wiki-plugin-rcngraph 0.1.20 → 0.1.22

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.
@@ -1,5 +1,178 @@
1
1
  (function () {
2
2
 
3
+ // BEGIN rcn-lineup-follow — pasted from tools/rcn-lineup-follow.js by tools/paste-lineup-follow.js. Edit that file, never this block.
4
+ /* rcn-lineup-follow — the timeline, map and drawing items on a wiki page follow
5
+ * each other, across the whole lineup and into the full tools open in other tabs.
6
+ *
7
+ * ONE SOURCE. tools/paste-lineup-follow.js pastes this file into the three
8
+ * plugins (rcntimeline, rcnmap, rcngraph) between the BEGIN/END marker lines,
9
+ * so each plugin stays one file. Edit this file, then run
10
+ * node tools/paste-lineup-follow.js
11
+ *
12
+ * WHY IT IS EASY ON A WIKI. A FedWiki lineup is one browser document: every
13
+ * page beside the others is a .page inside .main, even pages from other sites.
14
+ * So items on different pages can call each other directly. The first plugin
15
+ * to load makes window.rcnLineup; the others use it.
16
+ *
17
+ * WHAT GOES OUT. The same two messages the full tools send (tools/rcn-switch.js):
18
+ * { type:'rcn-walk', src, lead, k, all, label, ids, places, eips } a walk step
19
+ * { type:'rcn-walk', src, lead, k, end:true } the walk stopped
20
+ * { type:'rcn-follow', src, k, click:true, id, place, eip, ids, places, eips, clear? }
21
+ * ids are timeline bars, places map points, eips drawing nodes. The sender
22
+ * widens what it lights one hop through every timeline in the lineup: each bar
23
+ * names a place and a node, so a map step on the Magma mine lights the Magma
24
+ * bars and the Magma Copper box. x:1 marks a message already widened.
25
+ *
26
+ * HOW IT TRAVELS. As a bubbling DOM event 'rcnwalkStream' from the item (the
27
+ * naming FedWiki's Frame plugin uses for its LINEUP topics), heard once at the
28
+ * document and handed to every joined item but the sender; and over the
29
+ * BroadcastChannel 'rcn-follow', where the full tools of the same site listen.
30
+ *
31
+ * Marc Pierson with Claude Opus 5.5, Nov 2026. MIT licence.
32
+ */
33
+ const RL = (function () {
34
+ if (typeof window === 'undefined' || typeof document === 'undefined') return null
35
+ if (window.rcnLineup) return window.rcnLineup
36
+ const R = window.rcnLineup = { v: 1, members: [], heard: {} }
37
+ const CH = ('BroadcastChannel' in window) ? new BroadcastChannel('rcn-follow') : null
38
+ const none = () => ({ ids: [], places: [], eips: [] })
39
+
40
+ // The bridges: every bar of every timeline item in the lineup.
41
+ R.bars = function () {
42
+ const out = []
43
+ document.querySelectorAll('.rcntimeline-source').forEach(el => {
44
+ if (!el.timelineData) return
45
+ try {
46
+ (el.timelineData().intervals || []).forEach(iv => {
47
+ const x = iv.extra || {}
48
+ out.push({ id: String(iv.id), place: iv.place || x.place || null, eip: iv.eip || x.eip || null })
49
+ })
50
+ } catch (e) {}
51
+ })
52
+ return out
53
+ }
54
+ // One hop: a bar named, or at a lit place, or about a lit node, adds its bar, place and node.
55
+ R.expand = function (o) {
56
+ const I = {}, P = {}, E = {}, i0 = {}, p0 = {}, e0 = {}
57
+ ;(o.ids || []).filter(Boolean).forEach(x => { I[x] = i0[x] = 1 })
58
+ ;(o.places || []).filter(Boolean).forEach(x => { P[x] = p0[x] = 1 })
59
+ ;(o.eips || []).filter(Boolean).forEach(x => { E[x] = e0[x] = 1 })
60
+ R.bars().forEach(b => {
61
+ if (i0[b.id] || (b.place && p0[b.place]) || (b.eip && e0[b.eip])) {
62
+ I[b.id] = 1; if (b.place) P[b.place] = 1; if (b.eip) E[b.eip] = 1
63
+ }
64
+ })
65
+ return { ids: Object.keys(I), places: Object.keys(P), eips: Object.keys(E) }
66
+ }
67
+
68
+ // An item joins: fn(m) hears the others and returns true when it lit something.
69
+ // Joining again (a redraw) replaces the item's old listener.
70
+ R.join = function (el, src, fn) {
71
+ R.members = R.members.filter(x => x.el !== el && document.contains(x.el))
72
+ R.members.push({ el, src, fn })
73
+ }
74
+ R.others = el => R.members.filter(x => x.el !== el && document.contains(x.el)).length
75
+
76
+ function deliver (m, fromEl) {
77
+ if (!m || !m.k || R.heard[m.k]) return 0
78
+ R.heard[m.k] = 1
79
+ R.members = R.members.filter(x => document.contains(x.el))
80
+ let n = 0
81
+ R.members.slice().forEach(x => {
82
+ if (x.el === fromEl) return
83
+ try { if (x.fn(m)) n++ } catch (e) { console.warn('rcn-lineup-follow:', e) }
84
+ })
85
+ return n
86
+ }
87
+ // Returns how many items in this lineup lit something.
88
+ function send (el, m) {
89
+ m.k = Date.now() + ':' + Math.random()
90
+ let n = 0
91
+ try {
92
+ const ev = new CustomEvent('rcnwalkStream', { bubbles: true, detail: m })
93
+ el.dispatchEvent(ev)
94
+ n = ev.rcnLit || 0
95
+ } catch (e) {}
96
+ try { if (CH) CH.postMessage(m) } catch (e) {}
97
+ return n
98
+ }
99
+ document.addEventListener('rcnwalkStream', e => { e.rcnLit = deliver(e.detail, e.target) })
100
+ // The full tools in other tabs: their walks come widened through their set;
101
+ // their clicks name one thing, so widen those here.
102
+ if (CH) CH.addEventListener('message', ev => {
103
+ const m = ev.data
104
+ if (!m || !m.k) return
105
+ if (m.type === 'rcn-walk') { deliver(m, null); return }
106
+ if (m.type !== 'rcn-follow' || !m.click) return
107
+ if (m.x) { deliver(m, null); return }
108
+ const x = m.id ? R.expand({ ids: m.src === 'timeline' ? [m.id] : [], places: [m.place], eips: [m.eip] }) : none()
109
+ deliver(Object.assign({}, m, x, { x: 1, clear: !m.id }), null)
110
+ })
111
+
112
+ // A step of this item's walk. o: {ids|places|eips: [...], all, label}
113
+ R.step = function (el, src, o) {
114
+ if (!el.rcnLead) el.rcnLead = src + ':' + Date.now().toString(36) + Math.random().toString(36).slice(2, 6)
115
+ const x = o.all ? none() : R.expand(o)
116
+ return send(el, Object.assign({ type: 'rcn-walk', src, lead: el.rcnLead, all: !!o.all, pointer: false, label: o.label || null, x: 1 }, x))
117
+ }
118
+ // This item's walk stopped. Sends nothing if it was not leading.
119
+ R.end = function (el, src) {
120
+ if (!el.rcnLead) return
121
+ const lead = el.rcnLead
122
+ el.rcnLead = null
123
+ send(el, { type: 'rcn-walk', src, lead, end: true })
124
+ }
125
+ // A click on one thing, or {clear:true} to let go. o: {id} for a bar (it
126
+ // lights the bar's own place and node), {place} for a map point (the bars there
127
+ // and their nodes), {eip} for a drawing box (the bars about it and their places).
128
+ // Returns how many items in this lineup lit something.
129
+ R.click = function (el, src, o) {
130
+ el.rcnClicked = !o.clear
131
+ const x = o.clear ? none() : R.expand({ ids: o.id ? [o.id] : [], places: [o.place], eips: [o.eip] })
132
+ const bar = o.id && R.bars().find(b => b.id === String(o.id))
133
+ return send(el, Object.assign({ type: 'rcn-follow', src, click: true, clear: !!o.clear,
134
+ id: o.clear ? null : (o.id || o.place || o.eip || null), label: o.label || null,
135
+ place: o.place || (bar && bar.place) || null, eip: o.eip || (bar && bar.eip) || null, x: 1 }, x))
136
+ }
137
+
138
+ // A follower's state after hearing m. f: {lead, lit:Set|null, seen:Set, click}
139
+ // or null. mine: the ids of this item that m names. Returns the new state; the
140
+ // same object means nothing changes (a step about nothing here leaves it be).
141
+ R.update = function (f, m, mine) {
142
+ if (m.type === 'rcn-walk' && m.end) return f && f.lead === m.lead ? null : f
143
+ if (m.type === 'rcn-follow' && m.clear) return f && f.click ? null : f
144
+ const same = f && m.lead && f.lead === m.lead
145
+ if (m.all) return { lead: m.lead || null, lit: null, seen: same ? f.seen : new Set(), click: false }
146
+ if (!mine.length) return f
147
+ const seen = same ? new Set([...f.seen, ...(f.lit || [])]) : new Set()
148
+ return { lead: m.lead || null, lit: new Set(mine), seen, click: m.type === 'rcn-follow' }
149
+ }
150
+ // How strongly to draw one thing: lit full, seen half, the rest faded
151
+ // (less faded after a click than in a walk).
152
+ R.op = function (f, id) {
153
+ if (!f || !f.lit || f.lit.has(id)) return 1
154
+ if (f.seen.has(id)) return 0.42
155
+ return f.click ? 0.3 : 0.13
156
+ }
157
+ // "⧉ Open together": the Time Place Causality Explorer on an item's set file
158
+ // (item.set). A bare file name lives in the site's /assets/NDC/ folder beside
159
+ // the explorer and the full tools; a full address may point anywhere, and the
160
+ // explorer is then looked for in that set's own folder. A local wiki opens the
161
+ // working copy on :8765.
162
+ R.together = function (set) {
163
+ const local = /(^|\.)localhost$/.test(location.hostname)
164
+ const s = new URL(set, location.origin + '/assets/NDC/')
165
+ const page = local ? 'http://localhost:8765/tools/rcn-together.html' : new URL('rcn-together.html', s).href
166
+ return page + '?set=' + encodeURIComponent(new URL(page).origin === s.origin ? s.pathname : s.href)
167
+ }
168
+ R.togetherButton = item => item && typeof item.set === 'string' && item.set.trim()
169
+ ? '<button class="rcn-together" style="cursor:pointer;font-size:12px;padding:2px 8px" title="Open this with its timeline, map and sketch side by side in the Time Place Causality Explorer">⧉ Open together ↗</button>'
170
+ : ''
171
+ R.openTogether = item => { const w = window.open(R.together(item.set.trim()), 'rcntogether'); if (w) try { w.focus() } catch (e) {} }
172
+ return R
173
+ })()
174
+ // END rcn-lineup-follow
175
+
3
176
  // Farm sites are alice.localhost, scp-experiment.localhost, … so match the suffix,
4
177
  // not the bare hostname. Local wikis get the working copy off the sofi-proxy static
5
178
  // server; everything else gets the deployed asset.
@@ -335,6 +508,20 @@
335
508
  </div>`
336
509
  }
337
510
 
511
+ // Following another item in the lineup (see rcn-lineup-follow): the boxes it
512
+ // lights here at full strength, an arrow between two of them too, what it lit
513
+ // before at half, the rest faded; the drawing zooms towards the lit boxes.
514
+ function showFollow($item, g, f) {
515
+ const svg = $item.find('svg').get(0)
516
+ if (!svg) return
517
+ svg.querySelectorAll('.rcn-walk-ring').forEach(el => el.remove())
518
+ $item.find('.graph-box').css('max-height', 'none')
519
+ const op = id => RL.op(f, String(id))
520
+ g.nodes.forEach(n => { const el = groupFor(svg, 'node', n.id); if (el) el.style.opacity = String(op(n.id)) })
521
+ g.edges.forEach(e => { const el = groupFor(svg, 'edge', e.id); if (el) el.style.opacity = String(Math.min(op(e.src), op(e.tgt))) })
522
+ walkZoom(svg, [...f.lit].map(id => groupFor(svg, 'node', id)).filter(Boolean))
523
+ }
524
+
338
525
  function esc(s) { return String(s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c])) }
339
526
 
340
527
  function renderContent($item, item) {
@@ -347,6 +534,7 @@
347
534
  </div>
348
535
  <div style="padding:6px 0 0;display:flex;gap:6px;justify-content:center;">
349
536
  <button class="edit-graph" style="cursor:pointer;">Edit in Graph Tool ↗</button>
537
+ ${RL ? RL.togetherButton(item) : ''}
350
538
  </div>
351
539
  ${buildBar(item)}
352
540
  ${walkBar(item)}
@@ -548,6 +736,7 @@
548
736
  function bind($item, item) {
549
737
  aboutMark($item, 'rcngraph')
550
738
  bindNotes($item, item)
739
+ $item.on('click', '.rcn-together', e => { e.stopPropagation(); RL.openTogether(item) })
551
740
  $item.on('click', '.open-graph, .edit-graph', () => {
552
741
  pendingItem = item
553
742
  pending$item = $item
@@ -588,6 +777,7 @@
588
777
  // Walk playback. w === null: no walk open. token guards every voice callback,
589
778
  // so a step that was skipped or stopped can never move the walk on.
590
779
  const wk = { w: null, i: 0, playing: false, token: 0, heard: null }
780
+ const elG = $item.get(0)
591
781
  const curWalk = () => { const g = graphModel(item); return g && wk.w !== null ? walkList(g)[wk.w] : null }
592
782
  const stopVoice = () => { wk.token++; recHush(); try { if (window.speechSynthesis) speechSynthesis.cancel() } catch (e) {} }
593
783
  const walkUI = note => {
@@ -612,8 +802,10 @@
612
802
  if (!walk) return
613
803
  wk.i = Math.max(0, Math.min(walk.steps.length - 1, i))
614
804
  stopVoice()
805
+ elG.rcnFollow = null // leading now, not following
615
806
  showWalkStep($item, g, walk, wk.i)
616
807
  const st = walk.steps[wk.i]
808
+ if (RL) { const lit = stepLit(g, st); RL.step(elG, 'sketch', { eips: lit ? [...lit.nodes] : [], all: !lit, label: walk.name }) }
617
809
  $item.find('.walk-say').text(st.say || '').css({ color: st.ask ? '#7c2d12' : '#1e1b4b', fontStyle: st.ask ? 'italic' : 'normal' })
618
810
  walkUI()
619
811
  if (wk.playing) walkSpeak()
@@ -645,9 +837,43 @@
645
837
  if (g) showWalkStep($item, g, null, null)
646
838
  wk.w = null
647
839
  if (activeWalk === wk) activeWalk = null
840
+ if (RL) RL.end(elG, 'sketch')
648
841
  walkUI()
649
842
  }
650
843
  wk.end = walkEnd
844
+ // Follow the other timeline, map and drawing items in the lineup, and the full
845
+ // tools in other tabs. A walk played elsewhere stops this one (and a build);
846
+ // a click elsewhere is ignored while either is open. A box is lit by its own
847
+ // id, as a drawing node or as a place (a sketch area and its map area share one id).
848
+ if (RL) RL.join(elG, 'sketch', msg => {
849
+ const g = graphModel(item)
850
+ if (!g || !$item.find('svg').length) return false
851
+ const walkStep = msg.type === 'rcn-walk' && !msg.end
852
+ if (wk.w !== null) { if (!walkStep) return false; walkEnd() }
853
+ if (buildIdx !== null) { if (!walkStep) return false; buildIdx = null; showBuildStep($item, g, null) }
854
+ const have = new Set(g.nodes.map(n => String(n.id)))
855
+ const mine = [...new Set([...(msg.eips || []), ...(msg.places || [])])].map(String).filter(id => have.has(id))
856
+ const was = elG.rcnFollow || null, f = RL.update(was, msg, mine)
857
+ if (f === was) return false
858
+ elG.rcnFollow = f
859
+ if (f && f.lit) showFollow($item, g, f); else showWalkStep($item, g, null, null)
860
+ return !!(f && f.lit)
861
+ })
862
+ // A click on a box lights it in the items beside it. Its label still opens its
863
+ // page when nothing beside it lights up; shift-click always opens the page, at
864
+ // the end of the lineup. A click on the empty drawing lets go.
865
+ const nodeOf = t => { const n = t && t.closest && t.closest('g[id^="node-"]'); return n ? n.id.slice(5) : null }
866
+ const followNode = (id, label) => {
867
+ if (!RL || wk.w !== null || buildIdx !== null) return 0
868
+ if (elG.rcnFollow) { elG.rcnFollow = null; showWalkStep($item, graphModel(item), null, null) }
869
+ return RL.click(elG, 'sketch', { eip: id, label })
870
+ }
871
+ $item.off('click.rcnfollow').on('click.rcnfollow', '.graph-box svg', e => {
872
+ if ($(e.target).closest('a.internal').length) return
873
+ const id = nodeOf(e.target)
874
+ if (id) followNode(id)
875
+ else if (RL && elG.rcnClicked) RL.click(elG, 'sketch', { clear: true })
876
+ })
651
877
  $item.off('.rcnwalk')
652
878
  $item.on('click.rcnwalk', '.walk-start', () => {
653
879
  const g = graphModel(item)
@@ -713,8 +939,10 @@
713
939
  $item.off('click.rcnlink').on('click.rcnlink', 'svg a.internal', e => {
714
940
  e.preventDefault()
715
941
  e.stopPropagation()
716
- const title = e.currentTarget.getAttribute('data-title')
717
- if (title) wiki.doInternalLink(title, e.shiftKey ? null : $item.parents('.page:first'))
942
+ const title = e.currentTarget.getAttribute('data-title'), id = nodeOf(e.currentTarget)
943
+ if (!e.shiftKey && id && followNode(id, title)) return
944
+ // beside items that follow, open it at the end so they stay open
945
+ if (title) wiki.doInternalLink(title, e.shiftKey || (RL && RL.others(elG)) ? null : $item.parents('.page:first'))
718
946
  })
719
947
  }
720
948
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcngraph",
3
- "version": "0.1.20",
3
+ "version": "0.1.22",
4
4
  "description": "Federated Wiki - RCN Graph Plug-in",
5
5
  "keywords": [
6
6
  "wiki",
@@ -31,6 +31,16 @@
31
31
  "id": "8e7e435485d56e9e",
32
32
  "text": "Walks: a diagram can also carry walks, written in the Graph Tool (press Walk there to play, edit or record one). A walk is a list of steps, each with a sentence or two and the part of the diagram it is about. The item shows a ▶ Walk button: each step lights its part, fades the rest, zooms in so a narrow column can read it, and says the words aloud with the browser’s own voice while showing them as a caption. Space pauses, ◀ ▶ or the arrow keys step, Esc stops, and clicking the drawing pauses so you can look. A walk stops at its questions so a group can talk. Voice off shows the words only. The voice and its speed are chosen in the Graph Tool and remembered by your browser."
33
33
  },
34
+ {
35
+ "type": "paragraph",
36
+ "id": "f2b474457cb3f7bd",
37
+ "text": "Following. Put this page in a lineup beside pages with an RCN timeline, map or drawing, and the items follow each other. Press ▶ Walk in any of them: each step lights what it is about there, and the others light what is related to it: full strength for this step, half for earlier steps, the rest faded. Click a box and the timeline lights the bars about it, and the map their places. The others light where it is for them. Click empty space to let go. The timeline's bars are the bridges: each bar names a place on the map (place) and a box in the drawing (eip). One walk plays at a time, and starting one stops the others. A click that lights nothing beside it opens its page as before; beside items that follow, the page opens at the end of the lineup so they stay open, and shift-click always opens it. The full Timeline, Map and Graph Tool, opened from this wiki's assets in another tab, follow too, and lead too."
38
+ },
39
+ {
40
+ "type": "paragraph",
41
+ "id": "eb1078f31385e806",
42
+ "text": "Opening the explorer. Give the item a set field naming a set file, for example \"set\": \"superior.set.json\", and it shows a ⧉ Open together button. The button opens the Time Place Causality Explorer, which puts the timeline, the map and the sketch side by side on one page. A bare file name means the site's /assets/NDC/ folder, where the explorer and the full tools sit; a full address can point to a set anywhere."
43
+ },
34
44
  {
35
45
  "type": "rcngraph",
36
46
  "id": "8d4e2a7f1c9b3065",
@@ -186,6 +196,28 @@
186
196
  "text": "Developed by Marc Pierson with Claude Sonnet 4.6 (Anthropic) for the ReLocalize Creativity Network. Build playback and walks added October 2026 with Claude Opus 5.5. Source: [https://github.com/marpie1/wiki-plugin-rcngraph GitHub]. Published on npm as wiki-plugin-rcngraph."
187
197
  },
188
198
  "date": 1792602075758
199
+ },
200
+ {
201
+ "type": "add",
202
+ "id": "f2b474457cb3f7bd",
203
+ "item": {
204
+ "type": "paragraph",
205
+ "id": "f2b474457cb3f7bd",
206
+ "text": "Following. Put this page in a lineup beside pages with an RCN timeline, map or drawing, and the items follow each other. Press ▶ Walk in any of them: each step lights what it is about there, and the others light what is related to it: full strength for this step, half for earlier steps, the rest faded. Click a box and the timeline lights the bars about it, and the map their places. The others light where it is for them. Click empty space to let go. The timeline's bars are the bridges: each bar names a place on the map (place) and a box in the drawing (eip). One walk plays at a time, and starting one stops the others. A click that lights nothing beside it opens its page as before; beside items that follow, the page opens at the end of the lineup so they stay open, and shift-click always opens it. The full Timeline, Map and Graph Tool, opened from this wiki's assets in another tab, follow too, and lead too."
207
+ },
208
+ "after": "8e7e435485d56e9e",
209
+ "date": 1794193621097
210
+ },
211
+ {
212
+ "type": "add",
213
+ "id": "eb1078f31385e806",
214
+ "item": {
215
+ "type": "paragraph",
216
+ "id": "eb1078f31385e806",
217
+ "text": "Opening the explorer. Give the item a set field naming a set file, for example \"set\": \"superior.set.json\", and it shows a ⧉ Open together button. The button opens the Time Place Causality Explorer, which puts the timeline, the map and the sketch side by side on one page. A bare file name means the site's /assets/NDC/ folder, where the explorer and the full tools sit; a full address can point to a set anywhere."
218
+ },
219
+ "after": "f2b474457cb3f7bd",
220
+ "date": 1794195627668
189
221
  }
190
222
  ]
191
223
  }