-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
81 lines (70 loc) · 3.31 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/**
* hive.js
* Copyright (C) 2013-2016 Marcel Klehr <[email protected]>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the Mozilla Public License version 2
* as published by the Mozilla Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the Mozilla Public License
* along with this program. If not, see <https://www.mozilla.org/en-US/MPL/2.0/>.
*/
var path = require('path')
, spreadsheetOT = require('ot-socialcalc')
module.exports = setup
module.exports.consumes = ['ui', 'ot', 'importexport', 'sync', 'orm']
function setup(plugin, imports, register) {
var ui = imports.ui
var ot = imports.ot
var importexport = imports.importexport
var sync = imports.sync
var orm = imports.orm
ui.registerModule(path.join(__dirname, 'client.js'))
ui.registerStaticDir(path.join(__dirname, 'lib')) // for jQuery
ui.registerStaticDir(path.join(__dirname, '..', 'socialcalc', 'images'))
ui.registerStylesheet(path.join(__dirname, '..', 'socialcalc', 'socialcalc.css'))
ui.externalizeModule('socialcalc')
ot.registerOTType('spreadsheet', spreadsheetOT)
/* importexport.registerExportProvider('spreadsheet', 'application/vnd.oasis.opendocument.spreadsheet'
, function*(document, snapshot) {
return vdomToHtml(JSON.parse(snapshot.contents))
})
importexport.registerImportProvider('spreadsheet', 'application/vnd.oasis.opendocument.spreadsheet'
, function*(document, user, data) {
var sanitizedSvg = sanitizeHtml(data, {
allowedTags: svgTags
, allowedAttributes: {
'*': svgAttributes
}
})
var importedTree = domOT.create(sanitizedSvg)
// get gulf doc and prepare changes
var gulfDoc = yield sync.getDocument(document.id)
if(!gulfDoc.initialized) {
yield function(cb) {
gulfDoc.once('init', cb)
}
}
var root = gulfDoc.content
, insertPath = [root.childNodes.length]
, changes = [new domOT.Move(null, insertPath, domOT.serialize(importedTree))]
var snapshot = yield orm.collections.snapshot
.findOne({id: document.latestSnapshot})
// commit changes
yield function(cb) {
gulfDoc.receiveEdit(JSON.stringify({
cs: JSON.stringify(changes)
, parent: snapshot.id
, user: user
}), null, cb)
}
})
*/
register()
}
var defaultInitialData = '<svg id="svgcontent" width="580" height="400" x="150.5" y="11.5" overflow="hidden" xmlns="http://www.w3.org/2000/svg" xmlns:se="http://svg-edit.googlecode.com" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 580 400"><g style="pointer-events:none"><title style="pointer-events:inherit">Drawing</title><rect x="-1" y="-1" width="582" height="402" id="canvas_background" fill="#fff" style="pointer-events:inherit"/><g id="canvasGrid" width="100%" height="100%" x="0" y="0" overflow="visible" display="none"><rect width="100%" height="100%" x="0" y="0" stroke-width="0" stroke="none" fill="url(#gridpattern)" style="pointer-events: none; display:visible;"/></g></g><defs></defs><g style="pointer-events:all"><title style="pointer-events:inherit">Layer 1</title></g></svg>'