wiki-plugin-rcntimeline 0.3.10 → 0.4.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.
@@ -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
  // RCN Timeline — a small timeline on a wiki page: intervals as bars with their
4
162
  // fuzzy edges, the links between them, a date axis. The full RCN Timeline
5
163
  // (tools/rcn-timeline.html) solves and edits; this draws what the item holds.
@@ -351,6 +509,17 @@
351
509
  walkMark($item, lit)
352
510
  }
353
511
 
512
+ // Following another item in the lineup (see rcn-lineup-follow): what it lights
513
+ // here at full strength, what it lit before at half, the rest faded.
514
+ function followFade ($item, f) {
515
+ const op = id => RL.op(f, id)
516
+ $item.find('.rcnt-canvas [data-iv]').each(function () { this.style.opacity = op(this.getAttribute('data-iv')) })
517
+ $item.find('.rcnt-canvas [data-from]').each(function () {
518
+ this.style.opacity = Math.min(op(this.getAttribute('data-from')), op(this.getAttribute('data-to')))
519
+ })
520
+ walkMark($item, f.lit)
521
+ }
522
+
354
523
  // Each bar the step is about gets a pale ring. One pointer then moves to the bar the
355
524
  // words have reached: a ▼ over it, a line up to the date axis and its dates on the
356
525
  // axis, so it shows the thing and the time together; that bar's ring turns strong and
@@ -671,8 +840,10 @@
671
840
  if (!walk) return
672
841
  wk.i = Math.max(0, Math.min(walk.steps.length - 1, i))
673
842
  wk.token++; stopVoice(); ptrStop(wk)
843
+ el.rcntFollow = null // leading now, not following
674
844
  if (el.rcntPaint) el.rcntPaint()
675
845
  const st = walk.steps[wk.i]
846
+ if (RL) RL.step(el, 'timeline', { ids: st.all ? [] : (st.intervals || []).map(String), all: !!st.all, label: walk.name })
676
847
  ptrStart($item, el.rcntModel, st)
677
848
  $item.find('.walk-say').text(st.say || '').css({ color: st.ask ? '#7c2d12' : '#1e1b4b', fontStyle: st.ask ? 'italic' : 'normal' })
678
849
  ui()
@@ -693,10 +864,25 @@
693
864
  const end = () => {
694
865
  wk.playing = false; wk.token++; wk.w = null; wk.heard = null; ptrStop(wk)
695
866
  if (window.rcnActiveWalk === wk) { stopVoice(); window.rcnActiveWalk = null }
867
+ if (RL) RL.end(el, 'timeline')
696
868
  if (el.rcntPaint) el.rcntPaint()
697
869
  ui()
698
870
  }
699
871
  wk.end = end
872
+ // Follow the other timeline, map and drawing items in the lineup, and the full
873
+ // tools in other tabs. A walk played elsewhere stops this one; a click elsewhere
874
+ // is ignored while this item's own walk is open.
875
+ if (RL) RL.join(el, 'timeline', msg => {
876
+ if (wk.w !== null) { if (msg.type !== 'rcn-walk' || msg.end) return false; end() }
877
+ const have = new Set((el.rcntModel ? el.rcntModel.intervals : []).map(v => String(v.id)))
878
+ const mine = (msg.ids || []).map(String).filter(id => have.has(id))
879
+ const was = el.rcntFollow || null, f = RL.update(was, msg, mine)
880
+ if (f === was) return false
881
+ el.rcntFollow = f
882
+ $item.find('.rcnt-card').hide().data('iv', null)
883
+ if (el.rcntPaint) el.rcntPaint()
884
+ return !!(f && f.lit)
885
+ })
700
886
  $item.off('.rcntwalk')
701
887
  $item.on('click.rcntwalk', '.walk-start', () => {
702
888
  wk.w = +($item.find('.walk-pick').val() || 0)
@@ -793,8 +979,10 @@
793
979
  const paint = el.rcntPaint = () => {
794
980
  const wk = el.rcntWalk, walk = wk && wk.w !== null ? walkList(item)[wk.w] : null
795
981
  const st = walk && walk.steps[wk.i]
796
- $item.find('.rcnt-canvas').html(draw($item, item, m, st ? stepRange(m, st) : null))
982
+ const f = !st && el.rcntFollow && el.rcntFollow.lit ? el.rcntFollow : null
983
+ $item.find('.rcnt-canvas').html(draw($item, item, m, st ? stepRange(m, st) : f ? stepRange(m, { intervals: [...f.lit] }) : null))
797
984
  if (st) walkFade($item, m, walk, wk.i)
985
+ else if (f) followFade($item, f)
798
986
  }
799
987
  paint()
800
988
  setTimeout(paint, 0)
@@ -979,13 +1167,29 @@
979
1167
  item.frozen = item.frozen ? merge([item.frozen, got]) : got
980
1168
  save($item, item)
981
1169
  })
1170
+ // A bar click lights the bar's place and node in the items beside it. A bar
1171
+ // that names a page still opens it when nothing beside it lights up;
1172
+ // shift-click opens the page whatever happens, at the end of the lineup.
982
1173
  $item.on('click', '.rcnt-bar', function (e) {
983
- const page = this.getAttribute('data-page')
1174
+ const el = $item.get(0), page = this.getAttribute('data-page'), id = this.getAttribute('data-iv')
984
1175
  e.stopPropagation()
985
- if (page) { wiki.doInternalLink(page, e.shiftKey ? null : $item.parents('.page:first')); return }
986
- showCard($item, this.getAttribute('data-iv'))
1176
+ if (page && e.shiftKey) { wiki.doInternalLink(page, null); return }
1177
+ let lit = 0
1178
+ if (RL && !(el.rcntWalk && el.rcntWalk.w !== null)) {
1179
+ if (el.rcntFollow) { el.rcntFollow = null; if (el.rcntPaint) el.rcntPaint() }
1180
+ const v = el.rcntModel && el.rcntModel.intervals.find(w => String(w.id) === id)
1181
+ if (!page && $item.find('.rcnt-card').data('iv') === id) RL.click(el, 'timeline', { clear: true })
1182
+ else lit = RL.click(el, 'timeline', { id, label: v && v.label }) // the bar's own place and node, not everything else there
1183
+ }
1184
+ // beside items that follow, open it at the end so they stay open
1185
+ if (page && !lit) { wiki.doInternalLink(page, RL && RL.others(el) ? null : $item.parents('.page:first')); return }
1186
+ showCard($item, id)
1187
+ })
1188
+ $item.on('click', '.rcnt-card-x', e => {
1189
+ e.stopPropagation(); $item.find('.rcnt-card').hide().data('iv', null)
1190
+ const el = $item.get(0)
1191
+ if (RL && el.rcnClicked) RL.click(el, 'timeline', { clear: true })
987
1192
  })
988
- $item.on('click', '.rcnt-card-x', e => { e.stopPropagation(); $item.find('.rcnt-card').hide().data('iv', null) })
989
1193
  $item.on('dblclick', '.rcnt-card', e => e.stopPropagation())
990
1194
  }
991
1195
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcntimeline",
3
- "version": "0.3.10",
3
+ "version": "0.4.0",
4
4
  "description": "Federated Wiki plugin: a small RCN timeline on a page — intervals with fuzzy edges, the links between them, a date axis; each bar opens its page",
5
5
  "keywords": [
6
6
  "wiki",
@@ -26,6 +26,11 @@
26
26
  "id": "1caf7fe1c5cc610a",
27
27
  "text": "Walks. A timeline can carry walks, made in the full RCN Timeline tool: readings that explain it one stretch at a time. Press ▶ Walk under the timeline. Each step redraws the years it is about, fades the other bars, and says its words aloud with a caption. Space plays or pauses, the arrow keys step, Esc stops, and a walk stops at its questions so a group can talk. Voice on or off and the choice of voice are kept in the browser, shared with the drawing plugin's walks. Walks added October 2026 with Claude Opus 5.5."
28
28
  },
29
+ {
30
+ "type": "paragraph",
31
+ "id": "97f4075d8a08e9e9",
32
+ "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 bar and the map and the drawing light its place and its box. 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."
33
+ },
29
34
  {
30
35
  "type": "paragraph",
31
36
  "text": "Below: the Northwest Agriculture Business Center, from the Co-ops of Whatcom County pages. Its help to the meat co-op sits inside the co-op’s organising years, and the food hub it ran became a farmer-owned co-op.",
@@ -302,6 +307,17 @@
302
307
  },
303
308
  "after": "84d2ec6a4ab43717",
304
309
  "date": 1792629734413
310
+ },
311
+ {
312
+ "type": "add",
313
+ "id": "97f4075d8a08e9e9",
314
+ "item": {
315
+ "type": "paragraph",
316
+ "id": "97f4075d8a08e9e9",
317
+ "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 bar and the map and the drawing light its place and its box. 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."
318
+ },
319
+ "after": "1caf7fe1c5cc610a",
320
+ "date": 1794193621097
305
321
  }
306
322
  ]
307
323
  }