wiki-plugin-rcngraph 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/client/rcngraph.js +97 -0
- package/factory.json +1 -0
- package/index.js +2 -0
- package/package.json +10 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
|
|
3
|
+
const GRAPH_URL = 'https://marc.relocalizecreativity.net/assets/Drag/graph-tool-v22.html'
|
|
4
|
+
const WINDOW_NAME = 'rcngraph'
|
|
5
|
+
|
|
6
|
+
// Track which item/element opened the current popup
|
|
7
|
+
let pendingItem = null
|
|
8
|
+
let pending$item = null
|
|
9
|
+
|
|
10
|
+
function renderContent($item, item) {
|
|
11
|
+
$item.empty()
|
|
12
|
+
if (item.svgString) {
|
|
13
|
+
$item.append(`
|
|
14
|
+
<div style="background:#f5f5f5;padding:8px;">
|
|
15
|
+
<div style="overflow:auto;max-height:280px;border:1px solid #ddd;background:#fff;">
|
|
16
|
+
${item.svgString}
|
|
17
|
+
</div>
|
|
18
|
+
<div style="padding:6px 0 0;display:flex;gap:6px;justify-content:center;">
|
|
19
|
+
<button class="edit-graph" style="cursor:pointer;">Edit in Graph Tool ↗</button>
|
|
20
|
+
</div>
|
|
21
|
+
</div>
|
|
22
|
+
`)
|
|
23
|
+
} else {
|
|
24
|
+
$item.append(`
|
|
25
|
+
<div style="background-color:#eee;padding:15px;text-align:center;">
|
|
26
|
+
<p style="font-weight:bold;margin:0 0 6px;">RCN Graph Tool</p>
|
|
27
|
+
<p style="color:#666;font-size:0.85em;margin:0 0 12px;">CLD · EIP · OPM · VSM · NRM</p>
|
|
28
|
+
<button class="open-graph" style="cursor:pointer;">Open Graph Tool ↗</button>
|
|
29
|
+
</div>
|
|
30
|
+
`)
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function emit($item, item) {
|
|
35
|
+
renderContent($item, item)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function bind($item, item) {
|
|
39
|
+
$item.on('click', '.open-graph, .edit-graph', () => {
|
|
40
|
+
pendingItem = item
|
|
41
|
+
pending$item = $item
|
|
42
|
+
const popup = window.open(GRAPH_URL, WINDOW_NAME, 'popup,height=820,width=1440')
|
|
43
|
+
if (popup) popup.focus()
|
|
44
|
+
})
|
|
45
|
+
$item.on('dblclick', () => wiki.textEditor($item, item))
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function graphListener(event) {
|
|
49
|
+
if (!event.source || !event.source.opener) return
|
|
50
|
+
if (!event.data || event.data.toolType !== 'rcn-graph') return
|
|
51
|
+
|
|
52
|
+
const { data } = event
|
|
53
|
+
|
|
54
|
+
switch (data.action) {
|
|
55
|
+
case 'graphToolReady': {
|
|
56
|
+
if (pendingItem) {
|
|
57
|
+
const pageTitle = pending$item ? pending$item.parents('.page').data('title') : undefined
|
|
58
|
+
event.source.postMessage({ action: 'loadGraph', graphJSON: pendingItem.graphJSON || null, pageTitle }, '*')
|
|
59
|
+
}
|
|
60
|
+
break
|
|
61
|
+
}
|
|
62
|
+
case 'saveGraph': {
|
|
63
|
+
if (!pendingItem || !pending$item) break
|
|
64
|
+
pendingItem.graphJSON = data.graphJSON
|
|
65
|
+
pendingItem.svgString = data.svgString
|
|
66
|
+
const pageEl = pending$item.parents('.page')[0]
|
|
67
|
+
wiki.pageHandler.put(pageEl, { type: 'edit', id: pendingItem.id, item: pendingItem })
|
|
68
|
+
renderContent(pending$item, pendingItem)
|
|
69
|
+
bind(pending$item, pendingItem)
|
|
70
|
+
break
|
|
71
|
+
}
|
|
72
|
+
case 'doInternalLink': {
|
|
73
|
+
const { title, site, pageKey, keepLineup } = data
|
|
74
|
+
const $page = keepLineup
|
|
75
|
+
? null
|
|
76
|
+
: $('.page').filter((i, el) => $(el).data('key') == pageKey)
|
|
77
|
+
wiki.doInternalLink(title, $page, site)
|
|
78
|
+
break
|
|
79
|
+
}
|
|
80
|
+
case 'showResult': {
|
|
81
|
+
wiki.showResult(wiki.newPage(data.page), { $page: data.keepLineup ? null : undefined })
|
|
82
|
+
break
|
|
83
|
+
}
|
|
84
|
+
default:
|
|
85
|
+
if (wiki.debug) console.log('rcngraph listener — unknown action:', data)
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (typeof window !== 'undefined') {
|
|
90
|
+
window.plugins['rcngraph'] = { emit, bind }
|
|
91
|
+
if (!window.rcnGraphListener) {
|
|
92
|
+
window.rcnGraphListener = graphListener
|
|
93
|
+
window.addEventListener('message', graphListener)
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
})()
|
package/factory.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name":"Rcngraph","title":"RCN Graph Tool","category":"visualization"}
|
package/index.js
ADDED
package/package.json
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "wiki-plugin-rcngraph",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Federated Wiki - RCN Graph Plug-in",
|
|
5
|
+
"keywords": ["wiki", "federated wiki", "plugin", "rcn", "graph"],
|
|
6
|
+
"author": "RCN Network <rcn@relocalizecreativity.net>",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"main": "index.js",
|
|
9
|
+
"files": ["client/rcngraph.js", "factory.json", "index.js"]
|
|
10
|
+
}
|