wiki-plugin-rcntimeline 0.3.10 → 0.4.1

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
  // RCN Timeline — a small timeline on a wiki page: intervals as bars with their
4
177
  // fuzzy edges, the links between them, a date axis. The full RCN Timeline
5
178
  // (tools/rcn-timeline.html) solves and edits; this draws what the item holds.
@@ -351,6 +524,17 @@
351
524
  walkMark($item, lit)
352
525
  }
353
526
 
527
+ // Following another item in the lineup (see rcn-lineup-follow): what it lights
528
+ // here at full strength, what it lit before at half, the rest faded.
529
+ function followFade ($item, f) {
530
+ const op = id => RL.op(f, id)
531
+ $item.find('.rcnt-canvas [data-iv]').each(function () { this.style.opacity = op(this.getAttribute('data-iv')) })
532
+ $item.find('.rcnt-canvas [data-from]').each(function () {
533
+ this.style.opacity = Math.min(op(this.getAttribute('data-from')), op(this.getAttribute('data-to')))
534
+ })
535
+ walkMark($item, f.lit)
536
+ }
537
+
354
538
  // Each bar the step is about gets a pale ring. One pointer then moves to the bar the
355
539
  // words have reached: a ▼ over it, a line up to the date axis and its dates on the
356
540
  // axis, so it shows the thing and the time together; that bar's ring turns strong and
@@ -671,8 +855,10 @@
671
855
  if (!walk) return
672
856
  wk.i = Math.max(0, Math.min(walk.steps.length - 1, i))
673
857
  wk.token++; stopVoice(); ptrStop(wk)
858
+ el.rcntFollow = null // leading now, not following
674
859
  if (el.rcntPaint) el.rcntPaint()
675
860
  const st = walk.steps[wk.i]
861
+ if (RL) RL.step(el, 'timeline', { ids: st.all ? [] : (st.intervals || []).map(String), all: !!st.all, label: walk.name })
676
862
  ptrStart($item, el.rcntModel, st)
677
863
  $item.find('.walk-say').text(st.say || '').css({ color: st.ask ? '#7c2d12' : '#1e1b4b', fontStyle: st.ask ? 'italic' : 'normal' })
678
864
  ui()
@@ -693,10 +879,25 @@
693
879
  const end = () => {
694
880
  wk.playing = false; wk.token++; wk.w = null; wk.heard = null; ptrStop(wk)
695
881
  if (window.rcnActiveWalk === wk) { stopVoice(); window.rcnActiveWalk = null }
882
+ if (RL) RL.end(el, 'timeline')
696
883
  if (el.rcntPaint) el.rcntPaint()
697
884
  ui()
698
885
  }
699
886
  wk.end = end
887
+ // Follow the other timeline, map and drawing items in the lineup, and the full
888
+ // tools in other tabs. A walk played elsewhere stops this one; a click elsewhere
889
+ // is ignored while this item's own walk is open.
890
+ if (RL) RL.join(el, 'timeline', msg => {
891
+ if (wk.w !== null) { if (msg.type !== 'rcn-walk' || msg.end) return false; end() }
892
+ const have = new Set((el.rcntModel ? el.rcntModel.intervals : []).map(v => String(v.id)))
893
+ const mine = (msg.ids || []).map(String).filter(id => have.has(id))
894
+ const was = el.rcntFollow || null, f = RL.update(was, msg, mine)
895
+ if (f === was) return false
896
+ el.rcntFollow = f
897
+ $item.find('.rcnt-card').hide().data('iv', null)
898
+ if (el.rcntPaint) el.rcntPaint()
899
+ return !!(f && f.lit)
900
+ })
700
901
  $item.off('.rcntwalk')
701
902
  $item.on('click.rcntwalk', '.walk-start', () => {
702
903
  wk.w = +($item.find('.walk-pick').val() || 0)
@@ -785,7 +986,7 @@
785
986
  <div class="rcnt-card" style="display:none;margin:6px 0 0;padding:8px 26px 8px 10px;background:#fff;border:1px solid #c7d2fe;border-radius:6px;font-size:13px;line-height:1.45;position:relative"></div>
786
987
  ${rowsBar($item, item)}${walkBar(item)}
787
988
  <p class="caption" style="margin:4px 0 0;">${cap}</p>${note}
788
- <div style="padding:6px 0 0;text-align:center;">${controls}<button class="rcnt-open" style="cursor:pointer;">Open in RCN Timeline ↗</button></div></div>`)
989
+ <div style="padding:6px 0 0;text-align:center;">${controls}<button class="rcnt-open" style="cursor:pointer;">Open in RCN Timeline ↗</button> ${RL ? RL.togetherButton(item) : ''}</div></div>`)
789
990
  // Width is known only once the item is in the page. A walk step draws just
790
991
  // the years it is about and fades what it is not about.
791
992
  const el = $item.get(0)
@@ -793,8 +994,10 @@
793
994
  const paint = el.rcntPaint = () => {
794
995
  const wk = el.rcntWalk, walk = wk && wk.w !== null ? walkList(item)[wk.w] : null
795
996
  const st = walk && walk.steps[wk.i]
796
- $item.find('.rcnt-canvas').html(draw($item, item, m, st ? stepRange(m, st) : null))
997
+ const f = !st && el.rcntFollow && el.rcntFollow.lit ? el.rcntFollow : null
998
+ $item.find('.rcnt-canvas').html(draw($item, item, m, st ? stepRange(m, st) : f ? stepRange(m, { intervals: [...f.lit] }) : null))
797
999
  if (st) walkFade($item, m, walk, wk.i)
1000
+ else if (f) followFade($item, f)
798
1001
  }
799
1002
  paint()
800
1003
  setTimeout(paint, 0)
@@ -969,6 +1172,7 @@
969
1172
  $item.dblclick(e => { if (!$(e.target).closest('button, .walk-bar').length) wiki.textEditor($item, item) })
970
1173
  bindWalk($item, item)
971
1174
  $item.on('click', '.rcnt-open', e => { e.stopPropagation(); openTool($item, item) })
1175
+ $item.on('click', '.rcn-together', e => { e.stopPropagation(); RL.openTogether(item) })
972
1176
  $item.on('click', '.rcnt-refresh', e => { e.stopPropagation(); emit($item, item) })
973
1177
  $item.on('click', '.rcnt-rows', function (e) { e.stopPropagation(); $item.get(0).rcntRows = this.getAttribute('data-how'); emit($item, item) })
974
1178
  $item.on('click', '.rcnt-freeze', e => {
@@ -979,13 +1183,29 @@
979
1183
  item.frozen = item.frozen ? merge([item.frozen, got]) : got
980
1184
  save($item, item)
981
1185
  })
1186
+ // A bar click lights the bar's place and node in the items beside it. A bar
1187
+ // that names a page still opens it when nothing beside it lights up;
1188
+ // shift-click opens the page whatever happens, at the end of the lineup.
982
1189
  $item.on('click', '.rcnt-bar', function (e) {
983
- const page = this.getAttribute('data-page')
1190
+ const el = $item.get(0), page = this.getAttribute('data-page'), id = this.getAttribute('data-iv')
984
1191
  e.stopPropagation()
985
- if (page) { wiki.doInternalLink(page, e.shiftKey ? null : $item.parents('.page:first')); return }
986
- showCard($item, this.getAttribute('data-iv'))
1192
+ if (page && e.shiftKey) { wiki.doInternalLink(page, null); return }
1193
+ let lit = 0
1194
+ if (RL && !(el.rcntWalk && el.rcntWalk.w !== null)) {
1195
+ if (el.rcntFollow) { el.rcntFollow = null; if (el.rcntPaint) el.rcntPaint() }
1196
+ const v = el.rcntModel && el.rcntModel.intervals.find(w => String(w.id) === id)
1197
+ if (!page && $item.find('.rcnt-card').data('iv') === id) RL.click(el, 'timeline', { clear: true })
1198
+ else lit = RL.click(el, 'timeline', { id, label: v && v.label }) // the bar's own place and node, not everything else there
1199
+ }
1200
+ // beside items that follow, open it at the end so they stay open
1201
+ if (page && !lit) { wiki.doInternalLink(page, RL && RL.others(el) ? null : $item.parents('.page:first')); return }
1202
+ showCard($item, id)
1203
+ })
1204
+ $item.on('click', '.rcnt-card-x', e => {
1205
+ e.stopPropagation(); $item.find('.rcnt-card').hide().data('iv', null)
1206
+ const el = $item.get(0)
1207
+ if (RL && el.rcnClicked) RL.click(el, 'timeline', { clear: true })
987
1208
  })
988
- $item.on('click', '.rcnt-card-x', e => { e.stopPropagation(); $item.find('.rcnt-card').hide().data('iv', null) })
989
1209
  $item.on('dblclick', '.rcnt-card', e => e.stopPropagation())
990
1210
  }
991
1211
 
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.1",
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,16 @@
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
+ },
34
+ {
35
+ "type": "paragraph",
36
+ "id": "2f54ea236c26e0ff",
37
+ "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."
38
+ },
29
39
  {
30
40
  "type": "paragraph",
31
41
  "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 +312,28 @@
302
312
  },
303
313
  "after": "84d2ec6a4ab43717",
304
314
  "date": 1792629734413
315
+ },
316
+ {
317
+ "type": "add",
318
+ "id": "97f4075d8a08e9e9",
319
+ "item": {
320
+ "type": "paragraph",
321
+ "id": "97f4075d8a08e9e9",
322
+ "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."
323
+ },
324
+ "after": "1caf7fe1c5cc610a",
325
+ "date": 1794193621097
326
+ },
327
+ {
328
+ "type": "add",
329
+ "id": "2f54ea236c26e0ff",
330
+ "item": {
331
+ "type": "paragraph",
332
+ "id": "2f54ea236c26e0ff",
333
+ "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."
334
+ },
335
+ "after": "97f4075d8a08e9e9",
336
+ "date": 1794195627668
305
337
  }
306
338
  ]
307
339
  }