wiki-plugin-rcngraph 0.1.20 → 0.1.21

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,163 @@
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
+ return R
158
+ })()
159
+ // END rcn-lineup-follow
160
+
3
161
  // Farm sites are alice.localhost, scp-experiment.localhost, … so match the suffix,
4
162
  // not the bare hostname. Local wikis get the working copy off the sofi-proxy static
5
163
  // server; everything else gets the deployed asset.
@@ -335,6 +493,20 @@
335
493
  </div>`
336
494
  }
337
495
 
496
+ // Following another item in the lineup (see rcn-lineup-follow): the boxes it
497
+ // lights here at full strength, an arrow between two of them too, what it lit
498
+ // before at half, the rest faded; the drawing zooms towards the lit boxes.
499
+ function showFollow($item, g, f) {
500
+ const svg = $item.find('svg').get(0)
501
+ if (!svg) return
502
+ svg.querySelectorAll('.rcn-walk-ring').forEach(el => el.remove())
503
+ $item.find('.graph-box').css('max-height', 'none')
504
+ const op = id => RL.op(f, String(id))
505
+ g.nodes.forEach(n => { const el = groupFor(svg, 'node', n.id); if (el) el.style.opacity = String(op(n.id)) })
506
+ 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))) })
507
+ walkZoom(svg, [...f.lit].map(id => groupFor(svg, 'node', id)).filter(Boolean))
508
+ }
509
+
338
510
  function esc(s) { return String(s).replace(/[&<>"]/g, c => ({ '&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;' }[c])) }
339
511
 
340
512
  function renderContent($item, item) {
@@ -588,6 +760,7 @@
588
760
  // Walk playback. w === null: no walk open. token guards every voice callback,
589
761
  // so a step that was skipped or stopped can never move the walk on.
590
762
  const wk = { w: null, i: 0, playing: false, token: 0, heard: null }
763
+ const elG = $item.get(0)
591
764
  const curWalk = () => { const g = graphModel(item); return g && wk.w !== null ? walkList(g)[wk.w] : null }
592
765
  const stopVoice = () => { wk.token++; recHush(); try { if (window.speechSynthesis) speechSynthesis.cancel() } catch (e) {} }
593
766
  const walkUI = note => {
@@ -612,8 +785,10 @@
612
785
  if (!walk) return
613
786
  wk.i = Math.max(0, Math.min(walk.steps.length - 1, i))
614
787
  stopVoice()
788
+ elG.rcnFollow = null // leading now, not following
615
789
  showWalkStep($item, g, walk, wk.i)
616
790
  const st = walk.steps[wk.i]
791
+ if (RL) { const lit = stepLit(g, st); RL.step(elG, 'sketch', { eips: lit ? [...lit.nodes] : [], all: !lit, label: walk.name }) }
617
792
  $item.find('.walk-say').text(st.say || '').css({ color: st.ask ? '#7c2d12' : '#1e1b4b', fontStyle: st.ask ? 'italic' : 'normal' })
618
793
  walkUI()
619
794
  if (wk.playing) walkSpeak()
@@ -645,9 +820,43 @@
645
820
  if (g) showWalkStep($item, g, null, null)
646
821
  wk.w = null
647
822
  if (activeWalk === wk) activeWalk = null
823
+ if (RL) RL.end(elG, 'sketch')
648
824
  walkUI()
649
825
  }
650
826
  wk.end = walkEnd
827
+ // Follow the other timeline, map and drawing items in the lineup, and the full
828
+ // tools in other tabs. A walk played elsewhere stops this one (and a build);
829
+ // a click elsewhere is ignored while either is open. A box is lit by its own
830
+ // id, as a drawing node or as a place (a sketch area and its map area share one id).
831
+ if (RL) RL.join(elG, 'sketch', msg => {
832
+ const g = graphModel(item)
833
+ if (!g || !$item.find('svg').length) return false
834
+ const walkStep = msg.type === 'rcn-walk' && !msg.end
835
+ if (wk.w !== null) { if (!walkStep) return false; walkEnd() }
836
+ if (buildIdx !== null) { if (!walkStep) return false; buildIdx = null; showBuildStep($item, g, null) }
837
+ const have = new Set(g.nodes.map(n => String(n.id)))
838
+ const mine = [...new Set([...(msg.eips || []), ...(msg.places || [])])].map(String).filter(id => have.has(id))
839
+ const was = elG.rcnFollow || null, f = RL.update(was, msg, mine)
840
+ if (f === was) return false
841
+ elG.rcnFollow = f
842
+ if (f && f.lit) showFollow($item, g, f); else showWalkStep($item, g, null, null)
843
+ return !!(f && f.lit)
844
+ })
845
+ // A click on a box lights it in the items beside it. Its label still opens its
846
+ // page when nothing beside it lights up; shift-click always opens the page, at
847
+ // the end of the lineup. A click on the empty drawing lets go.
848
+ const nodeOf = t => { const n = t && t.closest && t.closest('g[id^="node-"]'); return n ? n.id.slice(5) : null }
849
+ const followNode = (id, label) => {
850
+ if (!RL || wk.w !== null || buildIdx !== null) return 0
851
+ if (elG.rcnFollow) { elG.rcnFollow = null; showWalkStep($item, graphModel(item), null, null) }
852
+ return RL.click(elG, 'sketch', { eip: id, label })
853
+ }
854
+ $item.off('click.rcnfollow').on('click.rcnfollow', '.graph-box svg', e => {
855
+ if ($(e.target).closest('a.internal').length) return
856
+ const id = nodeOf(e.target)
857
+ if (id) followNode(id)
858
+ else if (RL && elG.rcnClicked) RL.click(elG, 'sketch', { clear: true })
859
+ })
651
860
  $item.off('.rcnwalk')
652
861
  $item.on('click.rcnwalk', '.walk-start', () => {
653
862
  const g = graphModel(item)
@@ -713,8 +922,10 @@
713
922
  $item.off('click.rcnlink').on('click.rcnlink', 'svg a.internal', e => {
714
923
  e.preventDefault()
715
924
  e.stopPropagation()
716
- const title = e.currentTarget.getAttribute('data-title')
717
- if (title) wiki.doInternalLink(title, e.shiftKey ? null : $item.parents('.page:first'))
925
+ const title = e.currentTarget.getAttribute('data-title'), id = nodeOf(e.currentTarget)
926
+ if (!e.shiftKey && id && followNode(id, title)) return
927
+ // beside items that follow, open it at the end so they stay open
928
+ if (title) wiki.doInternalLink(title, e.shiftKey || (RL && RL.others(elG)) ? null : $item.parents('.page:first'))
718
929
  })
719
930
  }
720
931
 
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.21",
4
4
  "description": "Federated Wiki - RCN Graph Plug-in",
5
5
  "keywords": [
6
6
  "wiki",
@@ -31,6 +31,11 @@
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
+ },
34
39
  {
35
40
  "type": "rcngraph",
36
41
  "id": "8d4e2a7f1c9b3065",
@@ -186,6 +191,17 @@
186
191
  "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
192
  },
188
193
  "date": 1792602075758
194
+ },
195
+ {
196
+ "type": "add",
197
+ "id": "f2b474457cb3f7bd",
198
+ "item": {
199
+ "type": "paragraph",
200
+ "id": "f2b474457cb3f7bd",
201
+ "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."
202
+ },
203
+ "after": "8e7e435485d56e9e",
204
+ "date": 1794193621097
189
205
  }
190
206
  ]
191
207
  }