wiki-plugin-rcntimeline 0.4.0 → 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,95 @@
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
+ }
231
+ // "⧉ Open together": the Time Place Causality Explorer on an item's set file
232
+ // (item.set). A bare file name lives in the site's /assets/NDC/ folder beside
233
+ // the explorer and the full tools; a full address may point anywhere, and the
234
+ // explorer is then looked for in that set's own folder. A local wiki opens the
235
+ // working copy on :8765.
236
+ R.together = function (set) {
237
+ const local = /(^|\.)localhost$/.test(location.hostname)
238
+ const s = new URL(set, location.origin + '/assets/NDC/')
239
+ const page = local ? 'http://localhost:8765/tools/rcn-together.html' : new URL('rcn-together.html', s).href
240
+ return page + '?set=' + encodeURIComponent(new URL(page).origin === s.origin ? s.pathname : s.href)
241
+ }
242
+ R.togetherButton = item => item && typeof item.set === 'string' && item.set.trim()
243
+ ? '<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>'
244
+ : ''
245
+ R.openTogether = item => { const w = window.open(R.together(item.set.trim()), 'rcntogether'); if (w) try { w.focus() } catch (e) {} }
157
246
  return R
158
247
  })()
159
248
  // END rcn-lineup-follow
@@ -971,19 +1060,53 @@
971
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>
972
1061
  ${rowsBar($item, item)}${walkBar(item)}
973
1062
  <p class="caption" style="margin:4px 0 0;">${cap}</p>${note}
974
- <div style="padding:6px 0 0;text-align:center;">${controls}<button class="rcnt-open" style="cursor:pointer;">Open in RCN Timeline ↗</button></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>`)
975
1064
  // Width is known only once the item is in the page. A walk step draws just
976
1065
  // the years it is about and fades what it is not about.
977
1066
  const el = $item.get(0)
978
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))
979
1072
  const paint = el.rcntPaint = () => {
980
1073
  const wk = el.rcntWalk, walk = wk && wk.w !== null ? walkList(item)[wk.w] : null
981
1074
  const st = walk && walk.steps[wk.i]
982
1075
  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))
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))
984
1086
  if (st) walkFade($item, m, walk, wk.i)
985
1087
  else if (f) followFade($item, f)
986
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
+ }
987
1110
  paint()
988
1111
  setTimeout(paint, 0)
989
1112
  }
@@ -1157,6 +1280,7 @@
1157
1280
  $item.dblclick(e => { if (!$(e.target).closest('button, .walk-bar').length) wiki.textEditor($item, item) })
1158
1281
  bindWalk($item, item)
1159
1282
  $item.on('click', '.rcnt-open', e => { e.stopPropagation(); openTool($item, item) })
1283
+ $item.on('click', '.rcn-together', e => { e.stopPropagation(); RL.openTogether(item) })
1160
1284
  $item.on('click', '.rcnt-refresh', e => { e.stopPropagation(); emit($item, item) })
1161
1285
  $item.on('click', '.rcnt-rows', function (e) { e.stopPropagation(); $item.get(0).rcntRows = this.getAttribute('data-how'); emit($item, item) })
1162
1286
  $item.on('click', '.rcnt-freeze', e => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcntimeline",
3
- "version": "0.4.0",
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",
@@ -31,6 +31,16 @@
31
31
  "id": "97f4075d8a08e9e9",
32
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
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
+ },
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
+ },
34
44
  {
35
45
  "type": "paragraph",
36
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.",
@@ -318,6 +328,28 @@
318
328
  },
319
329
  "after": "1caf7fe1c5cc610a",
320
330
  "date": 1794193621097
331
+ },
332
+ {
333
+ "type": "add",
334
+ "id": "2f54ea236c26e0ff",
335
+ "item": {
336
+ "type": "paragraph",
337
+ "id": "2f54ea236c26e0ff",
338
+ "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."
339
+ },
340
+ "after": "97f4075d8a08e9e9",
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
321
353
  }
322
354
  ]
323
355
  }