wiki-plugin-rcntimeline 0.4.1 → 0.4.2

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.
@@ -154,6 +154,80 @@
154
154
  if (f.seen.has(id)) return 0.42
155
155
  return f.click ? 0.3 : 0.13
156
156
  }
157
+ // Whole or Step, item by item (Nov 17 2026), the same choice as the explorer's
158
+ // panes (tools/rcn-together.html). Step: a walk — this item's or one it
159
+ // follows — zooms the item to each step. Whole: the item shows the whole
160
+ // timeline, map or drawing and stays where you put it; steps light things in
161
+ // place, and you pan and zoom by hand. A click elsewhere still brings the item
162
+ // to what was clicked. ⤢ shows the whole thing again. Each kind of item
163
+ // (timeline, map, sketch) remembers its last choice in this browser.
164
+ const FRAME_KEY = 'rcnLineupFrame'
165
+ const frameSaved = () => { try { return JSON.parse(localStorage.getItem(FRAME_KEY)) || {} } catch (e) { return {} } }
166
+ R.frame = el => el.rcnFrame || (el.rcnFrame = frameSaved()[el.rcnKind] === 'whole' ? 'whole' : 'step')
167
+ R.whole = el => R.frame(el) === 'whole'
168
+ const frameHTML = fr => {
169
+ const b = 'font:inherit;font-size:12px;border:0;padding:2px 8px;cursor:pointer;'
170
+ const on = 'background:#4f46e5;color:#fff;', off = 'background:#fff;color:#334155;'
171
+ return `<button data-fr="whole" style="${b}${fr === 'whole' ? on : off}" title="Show the whole thing; a walk lights things where they are and leaves the view to you. Drag to pan, pinch or ⌘-scroll to zoom.">Whole</button>` +
172
+ `<button data-fr="step" style="${b}border-left:1px solid #cbd5e1;${fr === 'step' ? on : off}" title="Zoom in on each step of a walk">Step</button>` +
173
+ (fr === 'whole' ? `<button data-fr="fit" style="${b}border-left:1px solid #cbd5e1;${off}" title="Show the whole thing again">⤢</button>` : '')
174
+ }
175
+ // The switch, for an item's button row. kind: 'timeline' | 'map' | 'sketch'.
176
+ R.frameSwitch = kind => `<span class="rcn-frame" data-kind="${kind}" style="display:inline-flex;vertical-align:middle;border:1px solid #cbd5e1;border-radius:6px;overflow:hidden" role="group" aria-label="During a walk"></span>`
177
+ // Wire an item's switch. fn(frame, fit) redraws the item for the new choice.
178
+ R.bindFrame = function (el, kind, fn) {
179
+ el.rcnKind = kind
180
+ const draw = () => el.querySelectorAll('.rcn-frame').forEach(s => { s.innerHTML = frameHTML(R.frame(el)) })
181
+ draw()
182
+ if (el.rcnFrameBound) { el.rcnFrameFn = fn; return }
183
+ el.rcnFrameBound = true; el.rcnFrameFn = fn
184
+ el.addEventListener('click', e => {
185
+ const b = e.target.closest && e.target.closest('.rcn-frame button')
186
+ if (!b) return
187
+ e.stopPropagation()
188
+ const v = b.dataset.fr, was = R.frame(el)
189
+ if (v !== 'fit') {
190
+ el.rcnFrame = v
191
+ const s = frameSaved(); s[kind] = v
192
+ try { localStorage.setItem(FRAME_KEY, JSON.stringify(s)) } catch (err) {}
193
+ }
194
+ el.querySelectorAll('.rcn-frame').forEach(s => { s.innerHTML = frameHTML(R.frame(el)) })
195
+ if (v === 'fit' || v !== was) try { el.rcnFrameFn(R.frame(el), v === 'fit') } catch (err) { console.warn('rcn-frame:', err) }
196
+ })
197
+ }
198
+ // Hand pan and zoom on an element, for items without their own (the timeline
199
+ // and the drawing; the map has Leaflet's). Only while on() says so. Drag pans,
200
+ // pinch or ⌘/Ctrl-scroll zooms about the pointer, double-click shows the whole.
201
+ // A drag swallows the click that ends it, so it never counts as a click on a box.
202
+ // h: {on(), pan(dxPx, dyPx), zoom(factor, xPx, yPx), reset()}; positions are
203
+ // relative to the element's top-left corner.
204
+ R.handView = function (box, h) {
205
+ if (box.rcnHand) { box.rcnHand = h; return }
206
+ box.rcnHand = h
207
+ let drag = null, moved = false
208
+ box.addEventListener('pointerdown', e => {
209
+ if (!box.rcnHand.on() || e.button !== 0) return
210
+ drag = { x: e.clientX, y: e.clientY, id: e.pointerId }; moved = false
211
+ })
212
+ box.addEventListener('pointermove', e => {
213
+ if (!drag || e.pointerId !== drag.id) return
214
+ const dx = e.clientX - drag.x, dy = e.clientY - drag.y
215
+ if (!moved && Math.hypot(dx, dy) < 4) return
216
+ if (!moved) { moved = true; try { box.setPointerCapture(e.pointerId) } catch (err) {} box.style.cursor = 'grabbing' }
217
+ drag.x = e.clientX; drag.y = e.clientY
218
+ box.rcnHand.pan(dx, dy)
219
+ })
220
+ const up = () => { if (drag) { drag = null; box.style.cursor = '' } }
221
+ box.addEventListener('pointerup', up); box.addEventListener('pointercancel', up)
222
+ box.addEventListener('click', e => { if (moved) { moved = false; e.stopPropagation(); e.preventDefault() } }, true)
223
+ box.addEventListener('wheel', e => {
224
+ if (!box.rcnHand.on() || !(e.ctrlKey || e.metaKey)) return // a plain scroll still scrolls the wiki page
225
+ e.preventDefault()
226
+ const r = box.getBoundingClientRect()
227
+ box.rcnHand.zoom(Math.exp(-e.deltaY * (e.deltaMode ? 0.05 : 0.002) * (e.ctrlKey ? 10 : 1)), e.clientX - r.left, e.clientY - r.top) // a pinch arrives as ctrl+wheel in small steps
228
+ }, { passive: false })
229
+ box.addEventListener('dblclick', e => { if (box.rcnHand.on()) { e.preventDefault(); e.stopPropagation(); box.rcnHand.reset() } }, true)
230
+ }
157
231
  // "⧉ Open together": the Time Place Causality Explorer on an item's set file
158
232
  // (item.set). A bare file name lives in the site's /assets/NDC/ folder beside
159
233
  // the explorer and the full tools; a full address may point anywhere, and the
@@ -986,19 +1060,53 @@
986
1060
  <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>
987
1061
  ${rowsBar($item, item)}${walkBar(item)}
988
1062
  <p class="caption" style="margin:4px 0 0;">${cap}</p>${note}
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>`)
1063
+ <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) : ''} ${RL && RL.frameSwitch ? RL.frameSwitch('timeline') : ''}</div></div>`)
990
1064
  // Width is known only once the item is in the page. A walk step draws just
991
1065
  // the years it is about and fades what it is not about.
992
1066
  const el = $item.get(0)
993
1067
  el.rcntModel = m
1068
+ // Whole (the Whole / Step switch, rcn-lineup-follow): the years shown are the
1069
+ // whole timeline, or wherever you have dragged and zoomed it (el.rcntUser), and a
1070
+ // walk lights its bars in place. A click elsewhere still slides the view to its bar.
1071
+ const whole = () => !!(RL && RL.whole && RL.whole(el))
994
1072
  const paint = el.rcntPaint = () => {
995
1073
  const wk = el.rcntWalk, walk = wk && wk.w !== null ? walkList(item)[wk.w] : null
996
1074
  const st = walk && walk.steps[wk.i]
997
1075
  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))
1076
+ let range
1077
+ if (whole()) {
1078
+ range = el.rcntUser || null
1079
+ const r = f && f.click && range && stepRange(m, { intervals: [...f.lit] })
1080
+ if (r && (r.lo < range.lo || r.hi > range.hi)) { // the clicked bar is out of view: slide to it, same zoom
1081
+ const span = range.hi - range.lo, mid = (r.lo + r.hi) / 2
1082
+ range = el.rcntUser = { lo: mid - span / 2, hi: mid + span / 2 }
1083
+ }
1084
+ } else range = st ? stepRange(m, st) : f ? stepRange(m, { intervals: [...f.lit] }) : null
1085
+ $item.find('.rcnt-canvas').html(draw($item, item, m, range))
999
1086
  if (st) walkFade($item, m, walk, wk.i)
1000
1087
  else if (f) followFade($item, f)
1001
1088
  }
1089
+ if (RL && RL.bindFrame) {
1090
+ RL.bindFrame(el, 'timeline', (fr, fit) => { if (fr === 'whole' || fit) el.rcntUser = null; paint() })
1091
+ // Hand pan and zoom, in Whole. The years on screen now, as draw() lays them out.
1092
+ const shown = () => {
1093
+ if (el.rcntUser) return el.rcntUser
1094
+ let lo = Math.min(...m.intervals.map(v => v.s - v.sf)), hi = Math.max(...m.intervals.map(v => v.e + v.ef))
1095
+ const pad = Math.max((hi - lo) * 0.03, 0.25)
1096
+ return { lo: lo - pad, hi: hi + pad }
1097
+ }
1098
+ const perPx = () => { const r = shown(), W = Math.max(280, ($item.width() || 420) - 18); return (r.hi - r.lo) / (W - 2 * PAD) }
1099
+ RL.handView($item.find('.rcnt-canvas').get(0), {
1100
+ on: whole,
1101
+ pan: dx => { const r = shown(), d = -dx * perPx(); el.rcntUser = { lo: r.lo + d, hi: r.hi + d }; paint() },
1102
+ zoom: (k, x) => {
1103
+ const r = shown(), at = r.lo + (x - PAD) * perPx(), span = Math.max(2 / 365.25, Math.min(1e4, (r.hi - r.lo) / k))
1104
+ const u = (at - r.lo) / (r.hi - r.lo)
1105
+ el.rcntUser = { lo: at - u * span, hi: at + (1 - u) * span }; paint()
1106
+ },
1107
+ reset: () => { el.rcntUser = null; paint() }
1108
+ })
1109
+ }
1002
1110
  paint()
1003
1111
  setTimeout(paint, 0)
1004
1112
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcntimeline",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
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",
@@ -36,6 +36,11 @@
36
36
  "id": "2f54ea236c26e0ff",
37
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
38
  },
39
+ {
40
+ "type": "paragraph",
41
+ "id": "b82e7351d3f6b429",
42
+ "text": "Whole or Step. Beside the item's buttons, Whole · Step says what this timeline does while a walk plays, its own or one it follows. Step draws just the years each step is about. Whole keeps the whole timeline, or wherever you have put it: each step lights its bars where they are. In Whole, drag the timeline to move through time, pinch or ⌘-scroll to zoom, and double-click (or ⤢) to see all of it again. A click on the map or the drawing beside it still slides the timeline to its bar. You can switch at any time, in the middle of a walk too, and the choice is remembered in your browser. The Time Place Causality Explorer has the same switch on each of its panes."
43
+ },
39
44
  {
40
45
  "type": "paragraph",
41
46
  "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.",
@@ -334,6 +339,17 @@
334
339
  },
335
340
  "after": "97f4075d8a08e9e9",
336
341
  "date": 1794195627668
342
+ },
343
+ {
344
+ "type": "add",
345
+ "id": "b82e7351d3f6b429",
346
+ "item": {
347
+ "type": "paragraph",
348
+ "id": "b82e7351d3f6b429",
349
+ "text": "Whole or Step. Beside the item's buttons, Whole · Step says what this timeline does while a walk plays, its own or one it follows. Step draws just the years each step is about. Whole keeps the whole timeline, or wherever you have put it: each step lights its bars where they are. In Whole, drag the timeline to move through time, pinch or ⌘-scroll to zoom, and double-click (or ⤢) to see all of it again. A click on the map or the drawing beside it still slides the timeline to its bar. You can switch at any time, in the middle of a walk too, and the choice is remembered in your browser. The Time Place Causality Explorer has the same switch on each of its panes."
350
+ },
351
+ "after": "2f54ea236c26e0ff",
352
+ "date": 1794945537902
337
353
  }
338
354
  ]
339
355
  }