wiki-plugin-rcngraph 0.1.1 → 0.1.3

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