wiki-plugin-rcntimeline 0.0.0-stage → 0.2.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.
package/README.md CHANGED
@@ -1,3 +1,49 @@
1
- # Temporary Holding Version
1
+ # wiki-plugin-rcntimeline
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A small RCN timeline on a Federated Wiki page: intervals as bars with their fuzzy edges, the links between them, and a date axis. Hover a bar for its dates, source, confidence and note; click it to open its page in the lineup.
4
+
5
+ The full RCN Timeline (`tools/rcn-timeline.html` in the rcn repository) solves and edits. This plugin draws what the item holds — dates as stored, no solving — and its **Open in RCN Timeline ↗** button opens the item's timeline in the full tool, in its own tab. On a localhost wiki that is the working copy on port 8765; elsewhere the site's own `/assets/rcn-timeline/rcn-timeline.html` if it has one, otherwise the shared copy at `https://marc.relocalizecreativity.net/assets/Drag/rcn-timeline.html`, beside the Graph Tool, so one upload serves every site; an item's `tool` field overrides all of them. A second Open reuses the same tab. Edits made there do not come back to the page yet.
6
+
7
+ Install on a wiki server:
8
+
9
+ ```
10
+ npm install -g wiki-plugin-rcntimeline
11
+ ```
12
+
13
+ and restart the wiki. The Factory then offers **RCN Timeline**.
14
+
15
+ ## The item
16
+
17
+ ```json
18
+ {
19
+ "type": "rcntimeline",
20
+ "text": "Caption on the first line\nthen the intervals and links in words",
21
+ "timeline": {
22
+ "intervals": [
23
+ {"id": "a1_pre", "label": "A-1 Builders (conventional firm)", "start": "Jul 1 1955", "end": "Jul 1 2017", "startFuzz": 0.5, "color": "#94a3b8", "row": 9, "page": "A1DesignBuild"},
24
+ {"id": "a1", "label": "A1DesignBuild — worker co-op", "start": "Jul 1 2017", "end": "Sep 28 2026", "color": "#c0392b", "row": 9, "page": "A1DesignBuild"}
25
+ ],
26
+ "links": [ {"from": "a1_pre", "to": "a1", "rel": "meets", "who": "a1designbuild.coop"} ]
27
+ }
28
+ }
29
+ ```
30
+
31
+ - `timeline` is the RCN Timeline's own export format, so a timeline saved from the tool drops straight in. Fields the plugin does not use (`coops`, say) are left alone.
32
+ - `page` names the wiki page a bar opens. A bar without one is not a link.
33
+ - `rel` may be one relation (`meets`) or a list (`["before", "meets"]`, "one of"), drawn dashed. Lists are not built in the tool yet; the plugin accepts them so it will not break when they are.
34
+ - `text`: the first line is the caption; the rest lists the intervals and links in words, for search and for a wiki without this plugin.
35
+ - An item with no `timeline` — a fresh one from the Factory — is drawn from its text in the tool's own sentence form: `Label = Jan 2020 .. Jun 2021`, or `Label = 1970 .. 2026`.
36
+
37
+ ## Status
38
+
39
+ Version 0.2: draws intervals, fuzz, links and an axis; bars open their pages; Open in RCN Timeline opens the item in the full tool, and the tool's **↩ Save to wiki** (shown only when a wiki opened it) saves the edited timeline back into the item — the item opened last — as an ordinary FedWiki edit.
40
+
41
+ ## Lineup merging
42
+
43
+ - Every timeline offers its intervals and links to items to its right (class `rcntimeline-source`, `timelineData()`).
44
+ - A timeline whose text has a `LINEUP` line collects from every timeline to its left and draws them together. Intervals merge by id (the first copy wins); each source's lanes stay together, so a firm and the co-op it became stay on one row; links merge on from + to + relation.
45
+ - **❄** freezes the collection into the item (`item.frozen`); shift-click unfreezes. **↻** collects again.
46
+
47
+ Part of the [RCN toolset](https://github.com/marpie1/rcn), MIT.
48
+
49
+ Marc Pierson and Claude Opus 5.5 · September 2026
@@ -0,0 +1,410 @@
1
+ (function () {
2
+
3
+ // RCN Timeline — a small timeline on a wiki page: intervals as bars with their
4
+ // fuzzy edges, the links between them, a date axis. The full RCN Timeline
5
+ // (tools/rcn-timeline.html) solves and edits; this draws what the item holds.
6
+ //
7
+ // item.timeline = { intervals:[{id,label,start,end,startFuzz,endFuzz,color,
8
+ // row,who,conf,note,page?,coops?}],
9
+ // links:[{from,to,rel,who,note}] }
10
+ // — the Timeline tool's own export format. Dates are drawn as stored; no
11
+ // solving happens here. `page` names the wiki page a bar opens.
12
+ // — `rel` may be one relation ("meets") or a list (["before","meets"]),
13
+ // so the tool's parked relation-sets work does not break this plugin.
14
+ // item.text = first line the caption; the rest the intervals and links in
15
+ // words, for search and for wikis without this plugin.
16
+ //
17
+ // An item with no `timeline` is drawn from its text, in the tool's own
18
+ // sentence form: "Label = Jan 2020 .. Jun 2021" (or "= 1970 .. 2026").
19
+
20
+ const MON = ['jan', 'feb', 'mar', 'apr', 'may', 'jun', 'jul', 'aug', 'sep', 'oct', 'nov', 'dec']
21
+ const MON_NAME = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
22
+ const PALETTE = ['#2563eb', '#c0392b', '#1a7a4a', '#8e5cc4', '#d4a017', '#d4549a', '#0d9488', '#64748b']
23
+ const ROW_H = 26, BAR_H = 14, AXIS_H = 22, PAD = 10
24
+ const LINK_COLOR = '#7c3aed'
25
+ const NS = 'http://www.w3.org/2000/svg'
26
+
27
+ // The full RCN Timeline. A local wiki opens the working copy served on :8765.
28
+ // Anywhere else: the site's own copy in its assets if it has one, otherwise
29
+ // the shared copy beside the Graph Tool on marc.relocalizecreativity.net, so
30
+ // one upload serves every site. An item may name its own with a `tool` field.
31
+ // The tool opens any timeline passed as #tl=<base64 JSON>, so opening needs
32
+ // nothing from the tool but that.
33
+ const HERE = typeof window !== 'undefined' ? window.location : { hostname: '', origin: '' }
34
+ const LOCAL = /(^|\.)localhost$/.test(HERE.hostname)
35
+ const LOCAL_URL = 'http://localhost:8765/tools/rcn-timeline.html'
36
+ const SITE_URL = HERE.origin + '/assets/rcn-timeline/rcn-timeline.html'
37
+ const SHARED_URL = 'https://marc.relocalizecreativity.net/assets/Drag/rcn-timeline.html'
38
+ function toolUrl (item) {
39
+ if (item.tool) return Promise.resolve(item.tool)
40
+ if (LOCAL) return Promise.resolve(LOCAL_URL)
41
+ return fetch(SITE_URL, { method: 'HEAD', cache: 'no-store' })
42
+ .then(r => (r.ok ? SITE_URL : SHARED_URL), () => SHARED_URL)
43
+ }
44
+ const b64 = str => btoa(unescape(encodeURIComponent(str)))
45
+
46
+ const esc = s => String(s == null ? '' : s)
47
+ .replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/"/g, '&quot;')
48
+
49
+ // "Jul 1 2019", "Jul 2019", "2019", "2019-07-01" -> fractional year.
50
+ function toYear (d) {
51
+ if (d == null || d === '') return null
52
+ if (typeof d === 'number') return d
53
+ const s = String(d).trim()
54
+ let m
55
+ if ((m = /^(-?\d{1,4})$/.exec(s))) return +m[1]
56
+ if ((m = /^(\d{4})-(\d{1,2})(?:-(\d{1,2}))?$/.exec(s))) return frac(+m[1], +m[2] - 1, +(m[3] || 1))
57
+ if ((m = /^([A-Za-z]{3})[a-z]*\.?\s+(?:(\d{1,2}),?\s+)?(\d{4})$/.exec(s))) {
58
+ const mo = MON.indexOf(m[1].toLowerCase())
59
+ if (mo >= 0) return frac(+m[3], mo, +(m[2] || 1))
60
+ }
61
+ const t = Date.parse(s)
62
+ return isNaN(t) ? null : frac(new Date(t).getUTCFullYear(), new Date(t).getUTCMonth(), new Date(t).getUTCDate())
63
+ }
64
+ function frac (y, mo, day) {
65
+ const a = Date.UTC(y, 0, 1), b = Date.UTC(y + 1, 0, 1)
66
+ return y + (Date.UTC(y, mo, day) - a) / (b - a)
67
+ }
68
+ function fmt (y) {
69
+ const yr = Math.floor(y), d = new Date(Date.UTC(yr, 0, 1) + (y - yr) * (Date.UTC(yr + 1, 0, 1) - Date.UTC(yr, 0, 1)))
70
+ return MON_NAME[d.getUTCMonth()] + ' ' + d.getUTCDate() + ' ' + d.getUTCFullYear()
71
+ }
72
+ const relWords = r => Array.isArray(r) ? 'one of ' + r.join(', ') : (r || 'before')
73
+
74
+ function caption (item) { return String(item.text || '').split('\n')[0] }
75
+
76
+ // The item's own intervals and links, as stored (or read from its text).
77
+ function rawOf (item) {
78
+ if (item.timeline && Array.isArray(item.timeline.intervals)) {
79
+ return { intervals: item.timeline.intervals, links: item.timeline.links || [] }
80
+ }
81
+ const ivs = []
82
+ String(item.text || '').split('\n').forEach((line, i) => {
83
+ const m = /^(.+?)\s*=\s*(.+?)\s*\.\.\s*(.+)$/.exec(line.trim())
84
+ if (m) ivs.push({ id: 't' + i, label: m[1], start: m[2], end: m[3] })
85
+ })
86
+ return { intervals: ivs, links: [] }
87
+ }
88
+
89
+ const lineupOn = item => /^LINEUP\s*$/m.test(String(item.text || ''))
90
+
91
+ // Merge timelines from several sources — this item's own, its frozen
92
+ // collection, the pages to its left. An interval is the same interval when
93
+ // its id is the same (the co-op timeline's ids are global), so the first copy
94
+ // wins. Lanes are kept per source: a source's row N stays one lane, placed
95
+ // after the lanes already taken, so a firm and the co-op it became stay side
96
+ // by side. Links merge on from + to + relation.
97
+ function merge (parts) {
98
+ const seen = new Set(), lanes = new Map(), intervals = [], links = [], seenL = new Set()
99
+ parts.forEach((part, pi) => {
100
+ (part.intervals || []).forEach(v => {
101
+ if (seen.has(v.id)) return
102
+ seen.add(v.id)
103
+ const key = pi + ':' + (v.row == null ? v.id : v.row)
104
+ if (!lanes.has(key)) lanes.set(key, lanes.size)
105
+ intervals.push(Object.assign({}, v, { row: lanes.get(key) }))
106
+ })
107
+ ;(part.links || []).forEach(l => {
108
+ const k = l.from + '|' + l.to + '|' + JSON.stringify(l.rel || 'before')
109
+ if (!seenL.has(k)) { seenL.add(k); links.push(l) }
110
+ })
111
+ })
112
+ return { intervals, links }
113
+ }
114
+
115
+ // What this item draws: its own, then (frozen ? the frozen collection :
116
+ // LINEUP ? what the pages to its left offer now : nothing).
117
+ function effective ($item, item) {
118
+ const parts = [rawOf(item)]
119
+ if (item.frozen) parts.push(item.frozen)
120
+ else if (lineupOn(item) && $item) parts.push(...collect($item))
121
+ return parts.length === 1 ? parts[0] : merge(parts)
122
+ }
123
+
124
+ // Every timeline to the left of this item in the lineup — earlier pages, and
125
+ // earlier items on this page — the way the native Map plugin's LINEUP reads
126
+ // marker sources. Browser-side only: pages open in this window, nothing fetched.
127
+ function collect ($item) {
128
+ const all = $('.item'), here = all.index($item)
129
+ const out = []
130
+ all.slice(0, here).filter('.rcntimeline-source').each(function () {
131
+ if (this.timelineData) out.push(this.timelineData())
132
+ })
133
+ return out
134
+ }
135
+
136
+ function model (item, $item) { return normalize(effective($item, item)) }
137
+
138
+ // Dates as fractional years, lanes packed top to bottom.
139
+ function normalize (raw) {
140
+ const ivs = raw.intervals, links = raw.links
141
+ const out = []
142
+ ivs.forEach((v, i) => {
143
+ const s = toYear(v.start != null ? v.start : v.s)
144
+ if (s == null) return
145
+ let e = toYear(v.end != null ? v.end : v.e)
146
+ if (e == null) e = s + 1
147
+ out.push(Object.assign({}, v, {
148
+ s, e, sf: +(v.startFuzz != null ? v.startFuzz : v.sf) || 0, ef: +(v.endFuzz != null ? v.endFuzz : v.ef) || 0,
149
+ color: v.color || PALETTE[i % PALETTE.length], row: v.row == null ? i : v.row
150
+ }))
151
+ })
152
+ // Lanes in use, packed top to bottom in their original order.
153
+ const lanes = Array.from(new Set(out.map(v => v.row))).sort((a, b) => a - b)
154
+ out.forEach(v => { v.lane = lanes.indexOf(v.row) })
155
+ return { intervals: out, links, lanes: lanes.length }
156
+ }
157
+
158
+ // A tick step that gives four to seven labels across the span.
159
+ function ticks (lo, hi) {
160
+ const span = hi - lo
161
+ const steps = [1 / 12, 0.25, 0.5, 1, 2, 5, 10, 20, 25, 50, 100]
162
+ const step = steps.find(s => span / s <= 7) || 100
163
+ const out = []
164
+ for (let t = Math.ceil(lo / step) * step; t <= hi + 1e-9; t += step) {
165
+ out.push({ t, label: step >= 1 ? String(Math.round(t)) : fmt(t).replace(/ \d+ /, ' ') })
166
+ }
167
+ return out
168
+ }
169
+
170
+ let measureCtx = null
171
+ function textWidth (s) {
172
+ measureCtx = measureCtx || document.createElement('canvas').getContext('2d')
173
+ measureCtx.font = '600 11px system-ui, -apple-system, sans-serif'
174
+ return measureCtx.measureText(s).width + 4
175
+ }
176
+ function fitText (s, w) {
177
+ if (textWidth(s) <= w) return s
178
+ if (w < textWidth(s.slice(0, 3) + '…')) return ''
179
+ let lo = 3, hi = s.length
180
+ while (lo < hi) { const m = Math.ceil((lo + hi) / 2); if (textWidth(s.slice(0, m).trimEnd() + '…') <= w) lo = m; else hi = m - 1 }
181
+ return s.slice(0, lo).trimEnd() + '…'
182
+ }
183
+
184
+ function draw ($item, item, m) {
185
+ const W = Math.max(280, ($item.width() || 420) - 18)
186
+ const H = AXIS_H + m.lanes * ROW_H + PAD
187
+ let lo = Math.min(...m.intervals.map(v => v.s - v.sf)), hi = Math.max(...m.intervals.map(v => v.e + v.ef))
188
+ const pad = Math.max((hi - lo) * 0.03, 0.25); lo -= pad; hi += pad
189
+ const x = t => PAD + (t - lo) / (hi - lo) * (W - 2 * PAD)
190
+ const yMid = lane => AXIS_H + lane * ROW_H + ROW_H / 2
191
+ const byId = {}; m.intervals.forEach(v => { byId[v.id] = v })
192
+
193
+ const parts = []
194
+ const defs = []
195
+ // axis
196
+ ticks(lo, hi).forEach(k => {
197
+ parts.push(`<line x1="${x(k.t)}" y1="${AXIS_H - 4}" x2="${x(k.t)}" y2="${H - PAD / 2}" stroke="#eef2f7"/>`)
198
+ parts.push(`<text x="${x(k.t) + 3}" y="${AXIS_H - 8}" font-size="10" fill="#94a3b8">${esc(k.label)}</text>`)
199
+ })
200
+ parts.push(`<line x1="0" y1="${AXIS_H - 4}" x2="${W}" y2="${AXIS_H - 4}" stroke="#e2e8f0"/>`)
201
+
202
+ // bars: the fuzz shoulders fade in and out, the core is solid
203
+ m.intervals.forEach((v, i) => {
204
+ const y = yMid(v.lane) - BAR_H / 2, gid = 'g' + Math.floor(Math.random() * 1e9) + i
205
+ defs.push(`<linearGradient id="${gid}L"><stop offset="0" stop-color="${esc(v.color)}" stop-opacity="0"/><stop offset="1" stop-color="${esc(v.color)}" stop-opacity=".75"/></linearGradient>`)
206
+ defs.push(`<linearGradient id="${gid}R"><stop offset="0" stop-color="${esc(v.color)}" stop-opacity=".75"/><stop offset="1" stop-color="${esc(v.color)}" stop-opacity="0"/></linearGradient>`)
207
+ const xs = x(v.s), xe = Math.max(x(v.e), xs + 2)
208
+ const tip = [v.label, fmt(v.s) + ' – ' + fmt(v.e),
209
+ (v.sf || v.ef) ? 'uncertain by ' + [v.sf ? v.sf + ' yr before' : '', v.ef ? v.ef + ' yr after' : ''].filter(Boolean).join(', ') : '',
210
+ v.who ? 'Source: ' + v.who : '', v.conf != null ? 'Confidence ' + Math.round(v.conf * 100) + '%' : '',
211
+ v.note || '', v.page ? '— click to open ' + v.page : ''].filter(Boolean).join('\n')
212
+ parts.push(`<g class="rcnt-bar" data-page="${esc(v.page || '')}" style="cursor:${v.page ? 'pointer' : 'default'}"><title>${esc(tip)}</title>`
213
+ + (v.sf ? `<rect x="${x(v.s - v.sf)}" y="${y}" width="${xs - x(v.s - v.sf)}" height="${BAR_H}" fill="url(#${gid}L)"/>` : '')
214
+ + (v.ef ? `<rect x="${xe}" y="${y}" width="${x(v.e + v.ef) - xe}" height="${BAR_H}" fill="url(#${gid}R)"/>` : '')
215
+ + `<rect x="${xs}" y="${y}" width="${xe - xs}" height="${BAR_H}" rx="3" fill="${esc(v.color)}" fill-opacity=".85"/></g>`)
216
+ })
217
+
218
+ // links, over the bars: from the end of one to the start of the other
219
+ m.links.forEach(l => {
220
+ const a = byId[l.from], b = byId[l.to]
221
+ if (!a || !b) return
222
+ const rel = Array.isArray(l.rel) ? null : (l.rel || 'before')
223
+ const x1 = rel === 'during' ? x((a.s + a.e) / 2) : x(a.e), y1 = yMid(a.lane)
224
+ const x2 = rel === 'during' ? x((a.s + a.e) / 2) : x(b.s), y2 = yMid(b.lane)
225
+ const dy = Math.max(12, Math.abs(y2 - y1) / 2)
226
+ parts.push(`<path d="M${x1},${y1} C${x1},${y1 + (y2 > y1 ? dy : -dy)} ${x2},${y2 - (y2 > y1 ? dy : -dy)} ${x2},${y2}" fill="none" stroke="${LINK_COLOR}" stroke-width="1.2" stroke-opacity=".7"${Array.isArray(l.rel) ? ' stroke-dasharray="3 3"' : ''}><title>${esc(a.label + ' ' + relWords(l.rel) + ' ' + b.label + (l.who ? '\nSource: ' + l.who : '') + (l.note ? '\n' + l.note : ''))}</title></path>`)
227
+ })
228
+
229
+ // labels last, on a white halo. At the bar's start when it fits there,
230
+ // stopped short of the next bar in the same lane. A late, short bar whose
231
+ // label runs off the right edge gets it just BEFORE the bar instead, ending
232
+ // where the bar begins — pushed back over empty years it would read as a
233
+ // bar that started decades early. Only when an earlier bar in the lane
234
+ // fills that space does the label fall back to hugging the right edge.
235
+ // Laid out right to left within each lane, so an earlier label stops where
236
+ // a later one begins — a firm's label gives way to the co-op it became.
237
+ const limit = {}
238
+ m.intervals.slice().sort((a, b) => a.lane - b.lane || b.s - a.s).forEach(v => {
239
+ let lx = Math.max(x(v.s) + 4, 4)
240
+ const next = m.intervals.filter(o => o !== v && o.lane === v.lane && o.s > v.s).reduce((a, o) => Math.min(a, o.s), Infinity)
241
+ const stop = Math.min(next < Infinity ? x(next) : W, limit[v.lane] != null ? limit[v.lane] : W)
242
+ let room = stop - lx - 4
243
+ const w = textWidth(v.label)
244
+ if (next === Infinity && w > room) {
245
+ const prevEnd = m.intervals.filter(o => o !== v && o.lane === v.lane && o.s < v.s)
246
+ .reduce((a, o) => Math.max(a, x(o.e + o.ef)), 0)
247
+ const before = x(v.s - v.sf) - 4 - w
248
+ if (before >= Math.max(4, prevEnd + 4)) { lx = before; room = w }
249
+ else { lx = Math.max(4, W - w - 4); room = W - lx - 4 }
250
+ }
251
+ const t = fitText(v.label, room)
252
+ if (t) limit[v.lane] = Math.min(limit[v.lane] != null ? limit[v.lane] : W, lx - 6)
253
+ if (t) parts.push(`<text x="${lx}" y="${yMid(v.lane) + 4}" font-size="11" font-weight="600" fill="#1e293b" paint-order="stroke" stroke="#fff" stroke-width="3" stroke-linejoin="round" pointer-events="none">${esc(t)}</text>`)
254
+ })
255
+
256
+ return `<svg xmlns="${NS}" width="${W}" height="${H}" viewBox="0 0 ${W} ${H}" style="display:block;font-family:system-ui,-apple-system,sans-serif"><defs>${defs.join('')}</defs>${parts.join('')}</svg>`
257
+ }
258
+
259
+ function emit ($item, item) {
260
+ $item.empty()
261
+ // Offer this item's timeline (its own, plus anything frozen into it) to any
262
+ // LINEUP timeline to its right. Set before drawing, so a timeline further
263
+ // right that renders first still finds it.
264
+ $item.addClass('rcntimeline-source')
265
+ const slug = $item.parents('.page:first').attr('id') || ''
266
+ $item.get(0).timelineData = () => {
267
+ const own = item.frozen ? merge([rawOf(item), item.frozen]) : rawOf(item)
268
+ return { intervals: own.intervals, links: own.links, source: slug }
269
+ }
270
+ const m = model(item, $item)
271
+ const cap = wiki.resolveLinks ? wiki.resolveLinks(esc(caption(item))) : esc(caption(item))
272
+ const lineup = lineupOn(item)
273
+ const controls = lineup
274
+ ? `<button class="rcnt-freeze" title="${item.frozen ? 'Frozen: shift-click to unfreeze' : 'Freeze what the lineup shows into this page'}" style="cursor:pointer;${item.frozen ? 'color:#2563eb;' : ''}">❄︎</button>
275
+ <button class="rcnt-refresh" title="Collect again from the pages to the left" style="cursor:pointer;"${item.frozen ? ' disabled' : ''}>↻</button> `
276
+ : ''
277
+ if (!m.intervals.length) {
278
+ $item.append(`<div style="background:#f5f5f5;padding:12px;color:#64748b">`
279
+ + (lineup ? `Nothing to collect yet. Open co-op pages to the left of this one, then press ↻. ${controls}`
280
+ : `No intervals yet. Double-click and add lines of the form <code>Label = Jan 2020 .. Jun 2021</code>.`)
281
+ + `</div>`)
282
+ return
283
+ }
284
+ const note = lineup ? `<p class="caption" style="margin:2px 0 0;color:#64748b">${item.frozen
285
+ ? 'Frozen: ' + m.intervals.length + ' intervals kept in this page.'
286
+ : 'Collected from ' + collect($item).length + ' timeline(s) to the left.'}</p>` : ''
287
+ $item.append(`<div style="background:#f5f5f5;padding:8px;">
288
+ <div class="rcnt-canvas" style="background:#fff;border:1px solid #ddd;overflow-x:auto"></div>
289
+ <p class="caption" style="margin:4px 0 0;">${cap}</p>${note}
290
+ <div style="padding:6px 0 0;text-align:center;">${controls}<button class="rcnt-open" style="cursor:pointer;">Open in RCN Timeline ↗</button></div></div>`)
291
+ // Width is known only once the item is in the page.
292
+ const paint = () => $item.find('.rcnt-canvas').html(draw($item, item, m))
293
+ paint()
294
+ setTimeout(paint, 0)
295
+ }
296
+
297
+ // Open this item's timeline (what it draws, lineup included) in the full
298
+ // tool, in its own window. The tool's "Save to wiki" posts the edited
299
+ // timeline back; it lands in the item opened last.
300
+ let pending = null // {item, $item, win} — the item the tool will save into
301
+ function openTool ($item, item) {
302
+ const raw = effective($item, item)
303
+ const tl = item.timeline && !item.frozen && !lineupOn(item) ? raw : {
304
+ intervals: raw.intervals.map(v => Object.assign({}, v, v.start == null ? { start: fmt(toYear(v.s)), end: fmt(toYear(v.e)) } : {})),
305
+ links: raw.links
306
+ }
307
+ const doc = Object.assign({ name: caption(item) || 'Timeline' }, tl)
308
+ const hash = '#tl=' + b64(JSON.stringify(doc))
309
+ // Open the window now, while the click still counts, and point it at the
310
+ // tool once we know which copy to use; otherwise popup blockers stop it.
311
+ const win = window.open('', 'rcntimeline')
312
+ pending = { item, $item, win }
313
+ toolUrl(item).then(url => {
314
+ if (win) { win.location.href = url + hash; win.focus() } else window.open(url + hash, 'rcntimeline')
315
+ })
316
+ }
317
+
318
+ // The text an item carries beside its timeline: caption, then the intervals
319
+ // and links in words (search reads it; a wiki without the plugin shows it).
320
+ function words (item, tl) {
321
+ const byId = {}; tl.intervals.forEach(v => { byId[v.id] = v })
322
+ const keep = String(item.text || '').split('\n').filter(l => /^LINEUP\s*$/.test(l))
323
+ return [caption(item)].concat(keep,
324
+ tl.intervals.map(v => v.label + ': ' + v.start + ' – ' + v.end),
325
+ tl.links.filter(l => byId[l.from] && byId[l.to])
326
+ .map(l => byId[l.from].label + ' ' + relWords(l.rel) + ' ' + byId[l.to].label)).join('\n')
327
+ }
328
+
329
+ function save ($item, item) {
330
+ wiki.pageHandler.put($item.parents('.page:first'), { type: 'edit', id: item.id, item })
331
+ emit($item, item)
332
+ }
333
+
334
+ // Save-back from the full tool. Only the window this page opened is heard,
335
+ // and it saves into the item opened last.
336
+ function toolListener (event) {
337
+ if (!pending || !event.data || event.data.toolType !== 'rcn-timeline') return
338
+ if (pending.win && event.source !== pending.win) return
339
+ if (event.data.action !== 'saveTimeline' || !event.data.timeline) return
340
+ const { item, $item } = pending
341
+ const tl = event.data.timeline
342
+ item.timeline = { intervals: tl.intervals || [], links: tl.links || [] }
343
+ delete item.frozen // what was frozen is now in the item's own timeline
344
+ item.text = words(item, item.timeline)
345
+ save($item, item)
346
+ try { event.source.postMessage({ toolType: 'rcn-timeline', action: 'saved', page: $item.parents('.page:first').data('data').title }, '*') } catch (e) {}
347
+ }
348
+
349
+
350
+ // ⓘ — this plugin's About page in one click. FedWiki opens it with Cmd/Ctrl-I,
351
+ // but only from the item's text editor, which people seldom open when the real
352
+ // work happens elsewhere. Redraws empty the item, so the mark puts itself back.
353
+ function aboutMark ($item, type) {
354
+ const el = $item.get(0)
355
+ if (!el || el.__aboutMark) return
356
+ el.__aboutMark = true
357
+ if (getComputedStyle(el).position === 'static') el.style.position = 'relative'
358
+ const add = () => {
359
+ if (el.querySelector(':scope > .rcn-about')) return
360
+ const a = document.createElement('a')
361
+ a.className = 'rcn-about'
362
+ a.href = '/view/about-' + type + '-plugin'
363
+ a.title = 'About this plugin'
364
+ a.textContent = 'ⓘ'
365
+ a.style.cssText = 'position:absolute;top:0;right:-18px;z-index:1000;font:15px/1 system-ui,sans-serif;color:#64748b;text-decoration:none;cursor:pointer;background:rgba(255,255,255,.75);border-radius:50%;padding:1px 2px'
366
+ a.addEventListener('click', e => {
367
+ e.preventDefault()
368
+ e.stopPropagation()
369
+ wiki.doInternalLink('about ' + type + ' plugin', $item.parents('.page:first'))
370
+ })
371
+ a.addEventListener('dblclick', e => e.stopPropagation())
372
+ el.appendChild(a)
373
+ }
374
+ add()
375
+ new MutationObserver(add).observe(el, { childList: true })
376
+ }
377
+
378
+ function bind ($item, item) {
379
+ aboutMark($item, 'rcntimeline')
380
+ $item.dblclick(e => { if (!$(e.target).closest('button').length) wiki.textEditor($item, item) })
381
+ $item.on('click', '.rcnt-open', e => { e.stopPropagation(); openTool($item, item) })
382
+ $item.on('click', '.rcnt-refresh', e => { e.stopPropagation(); emit($item, item) })
383
+ $item.on('click', '.rcnt-freeze', e => {
384
+ e.stopPropagation()
385
+ if (e.shiftKey) { if (item.frozen) { delete item.frozen; save($item, item) } return }
386
+ const got = merge(collect($item))
387
+ if (!got.intervals.length) return
388
+ item.frozen = item.frozen ? merge([item.frozen, got]) : got
389
+ save($item, item)
390
+ })
391
+ $item.on('click', '.rcnt-bar', function (e) {
392
+ const page = this.getAttribute('data-page')
393
+ if (!page) return
394
+ e.stopPropagation()
395
+ wiki.doInternalLink(page, e.shiftKey ? null : $item.parents('.page:first'))
396
+ })
397
+ }
398
+
399
+ if (typeof window !== 'undefined') {
400
+ window.plugins.rcntimeline = { emit, bind }
401
+ if (!window.rcnTimelineListener) {
402
+ window.rcnTimelineListener = toolListener
403
+ window.addEventListener('message', toolListener)
404
+ }
405
+ }
406
+ if (typeof module !== 'undefined') {
407
+ module.exports = { model, rawOf, merge, normalize, lineupOn, toYear, fmt, ticks, relWords, caption, toolUrl }
408
+ }
409
+
410
+ })()
package/factory.json ADDED
@@ -0,0 +1 @@
1
+ {"name":"Rcntimeline","title":"RCN Timeline","category":"visualization"}
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ // wiki-plugin-rcntimeline — server-side entry point
2
+ module.exports = { }
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcntimeline",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.2.2",
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
+ "keywords": ["wiki", "federated wiki", "plugin", "rcn", "timeline"],
6
+ "author": "RCN Network <rcn@relocalizecreativity.net>",
7
+ "license": "MIT",
8
+ "main": "index.js",
9
+ "files": ["client/rcntimeline.js", "factory.json", "index.js", "pages", "README.md"],
10
+ "repository": {"type": "git", "url": "git+https://github.com/marpie1/rcn.git"},
11
+ "homepage": "https://github.com/marpie1/rcn/tree/master/wiki-plugin-rcntimeline"
12
+ }
@@ -0,0 +1,291 @@
1
+ {
2
+ "title": "About Rcntimeline Plugin",
3
+ "story": [
4
+ {
5
+ "type": "paragraph",
6
+ "text": "The RCN Timeline plugin puts a small timeline on a wiki page: each interval a bar, its uncertain edges fading in and out, the links between intervals drawn as curves, and a date axis across the top. Hover a bar for its dates, who says so, how sure they are, and any note. Click a bar and its page opens in the lineup beside this one.",
7
+ "id": "f0a9a8322aafc9ab"
8
+ },
9
+ {
10
+ "type": "paragraph",
11
+ "id": "029356e7e8442a58",
12
+ "text": "See [https://github.com/marpie1/rcn/tree/master/wiki-plugin-rcntimeline GitHub] for plugin source."
13
+ },
14
+ {
15
+ "type": "paragraph",
16
+ "text": "The full RCN Timeline tool solves and edits: it moves floating intervals to satisfy their links and flags contradictions. This plugin only draws what the item holds, dates as stored.",
17
+ "id": "b1685103986c7744"
18
+ },
19
+ {
20
+ "type": "paragraph",
21
+ "text": "Editing the item. Double-click to open the text editor. The first line of the text is the caption; the rest lists the intervals and links in words, so wiki search finds them. The intervals themselves live in the item\u2019s timeline field, in the tool\u2019s own export format. A new item from the Factory has no timeline field yet: type lines such as Pilot = Jan 2020 .. Jun 2021 and each becomes a bar.",
22
+ "id": "84d2ec6a4ab43717"
23
+ },
24
+ {
25
+ "type": "paragraph",
26
+ "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\u2019s organising years, and the food hub it ran became a farmer-owned co-op.",
27
+ "id": "8bd7dff26d7d8c1e"
28
+ },
29
+ {
30
+ "type": "rcntimeline",
31
+ "id": "11dd477f3b62535a",
32
+ "text": "Northwest Agriculture Business Center over time. Click a shared bar for the other co-op\u2019s page.\nNABC co-op development help (USDA grant): Jul 1 2015 \u2013 Jul 1 2016\nPuget Sound Food Hub, run by NABC: Jul 1 2010 \u2013 Jul 1 2016\nNW Agriculture Business Center: Jul 1 2006 \u2013 Sep 28 2026\nNABC co-op development help (USDA grant) during NW Agriculture Business Center\nPuget Sound Food Hub, run by NABC during NW Agriculture Business Center",
33
+ "timeline": {
34
+ "intervals": [
35
+ {
36
+ "id": "nabc_ncm",
37
+ "label": "NABC co-op development help (USDA grant)",
38
+ "start": "Jul 1 2015",
39
+ "end": "Jul 1 2016",
40
+ "startFuzz": 1,
41
+ "endFuzz": 0,
42
+ "color": "#7c3aed",
43
+ "row": 21,
44
+ "who": "agbizcenter.org",
45
+ "conf": 0.55,
46
+ "note": "Technical assistance under a USDA Rural Cooperative Development Grant, including the securities exemptions that let the co-op sell shares. Year inferred from the launch; not published.",
47
+ "coops": [
48
+ "nabc",
49
+ "ncm"
50
+ ],
51
+ "page": "North Cascades Meat Producers Cooperative"
52
+ },
53
+ {
54
+ "id": "psfh_nabc",
55
+ "label": "Puget Sound Food Hub, run by NABC",
56
+ "start": "Jul 1 2010",
57
+ "end": "Jul 1 2016",
58
+ "startFuzz": 0.5,
59
+ "endFuzz": 0,
60
+ "color": "#64748b",
61
+ "row": 23,
62
+ "who": "WSU food hub case study",
63
+ "conf": 0.8,
64
+ "note": "The food hub began under NABC's governance.",
65
+ "coops": [
66
+ "psfh",
67
+ "nabc"
68
+ ],
69
+ "page": "Puget Sound Food Hub Cooperative"
70
+ },
71
+ {
72
+ "id": "nabc",
73
+ "label": "NW Agriculture Business Center",
74
+ "start": "Jul 1 2006",
75
+ "end": "Sep 28 2026",
76
+ "startFuzz": 0.5,
77
+ "endFuzz": 0,
78
+ "color": "#1a7a4a",
79
+ "row": 27,
80
+ "who": "agbizcenter.org",
81
+ "conf": 0.85,
82
+ "note": "Established 2006 in Mount Vernon (Skagit). USDA-funded rural co-op development centre.",
83
+ "coops": [
84
+ "nabc"
85
+ ],
86
+ "page": "Northwest Agriculture Business Center"
87
+ }
88
+ ],
89
+ "links": [
90
+ {
91
+ "from": "nabc_ncm",
92
+ "to": "nabc",
93
+ "rel": "during",
94
+ "who": "agbizcenter.org",
95
+ "note": "NABC's co-op development work."
96
+ },
97
+ {
98
+ "from": "psfh_nabc",
99
+ "to": "nabc",
100
+ "rel": "during",
101
+ "who": "WSU case study",
102
+ "note": "NABC ran the hub."
103
+ }
104
+ ]
105
+ }
106
+ },
107
+ {
108
+ "type": "paragraph",
109
+ "text": "Coming next: lineup merging, so a timeline collects the timelines of the pages to its left, and an Open in RCN Timeline button that saves back into the item.",
110
+ "id": "3b7a3ee27915f0e4"
111
+ },
112
+ {
113
+ "type": "markdown",
114
+ "id": "a5673a5be44d674a",
115
+ "text": "*Marc Pierson and Claude Opus 5.5 \u00b7 September 2026*",
116
+ "attribution": true
117
+ }
118
+ ],
119
+ "journal": [
120
+ {
121
+ "type": "create",
122
+ "item": {
123
+ "title": "About Rcntimeline Plugin",
124
+ "story": []
125
+ },
126
+ "date": 1790644321803,
127
+ "author": "Marc Pierson with Claude Opus 5.5"
128
+ },
129
+ {
130
+ "type": "add",
131
+ "id": "f0a9a8322aafc9ab",
132
+ "item": {
133
+ "type": "paragraph",
134
+ "text": "The RCN Timeline plugin puts a small timeline on a wiki page: each interval a bar, its uncertain edges fading in and out, the links between intervals drawn as curves, and a date axis across the top. Hover a bar for its dates, who says so, how sure they are, and any note. Click a bar and its page opens in the lineup beside this one.",
135
+ "id": "f0a9a8322aafc9ab"
136
+ },
137
+ "date": 1790644321804
138
+ },
139
+ {
140
+ "type": "add",
141
+ "id": "b1685103986c7744",
142
+ "item": {
143
+ "type": "paragraph",
144
+ "text": "The full RCN Timeline tool solves and edits: it moves floating intervals to satisfy their links and flags contradictions. This plugin only draws what the item holds, dates as stored.",
145
+ "id": "b1685103986c7744"
146
+ },
147
+ "date": 1790644321805,
148
+ "after": "f0a9a8322aafc9ab"
149
+ },
150
+ {
151
+ "type": "add",
152
+ "id": "84d2ec6a4ab43717",
153
+ "item": {
154
+ "type": "paragraph",
155
+ "text": "Editing the item. Double-click to open the text editor. The first line of the text is the caption; the rest lists the intervals and links in words, so wiki search finds them. The intervals themselves live in the item\u2019s timeline field, in the tool\u2019s own export format. A new item from the Factory has no timeline field yet: type lines such as Pilot = Jan 2020 .. Jun 2021 and each becomes a bar.",
156
+ "id": "84d2ec6a4ab43717"
157
+ },
158
+ "date": 1790644321806,
159
+ "after": "b1685103986c7744"
160
+ },
161
+ {
162
+ "type": "add",
163
+ "id": "8bd7dff26d7d8c1e",
164
+ "item": {
165
+ "type": "paragraph",
166
+ "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\u2019s organising years, and the food hub it ran became a farmer-owned co-op.",
167
+ "id": "8bd7dff26d7d8c1e"
168
+ },
169
+ "date": 1790644321807,
170
+ "after": "84d2ec6a4ab43717"
171
+ },
172
+ {
173
+ "type": "add",
174
+ "id": "11dd477f3b62535a",
175
+ "item": {
176
+ "type": "rcntimeline",
177
+ "id": "11dd477f3b62535a",
178
+ "text": "Northwest Agriculture Business Center over time. Click a shared bar for the other co-op\u2019s page.\nNABC co-op development help (USDA grant): Jul 1 2015 \u2013 Jul 1 2016\nPuget Sound Food Hub, run by NABC: Jul 1 2010 \u2013 Jul 1 2016\nNW Agriculture Business Center: Jul 1 2006 \u2013 Sep 28 2026\nNABC co-op development help (USDA grant) during NW Agriculture Business Center\nPuget Sound Food Hub, run by NABC during NW Agriculture Business Center",
179
+ "timeline": {
180
+ "intervals": [
181
+ {
182
+ "id": "nabc_ncm",
183
+ "label": "NABC co-op development help (USDA grant)",
184
+ "start": "Jul 1 2015",
185
+ "end": "Jul 1 2016",
186
+ "startFuzz": 1,
187
+ "endFuzz": 0,
188
+ "color": "#7c3aed",
189
+ "row": 21,
190
+ "who": "agbizcenter.org",
191
+ "conf": 0.55,
192
+ "note": "Technical assistance under a USDA Rural Cooperative Development Grant, including the securities exemptions that let the co-op sell shares. Year inferred from the launch; not published.",
193
+ "coops": [
194
+ "nabc",
195
+ "ncm"
196
+ ],
197
+ "page": "North Cascades Meat Producers Cooperative"
198
+ },
199
+ {
200
+ "id": "psfh_nabc",
201
+ "label": "Puget Sound Food Hub, run by NABC",
202
+ "start": "Jul 1 2010",
203
+ "end": "Jul 1 2016",
204
+ "startFuzz": 0.5,
205
+ "endFuzz": 0,
206
+ "color": "#64748b",
207
+ "row": 23,
208
+ "who": "WSU food hub case study",
209
+ "conf": 0.8,
210
+ "note": "The food hub began under NABC's governance.",
211
+ "coops": [
212
+ "psfh",
213
+ "nabc"
214
+ ],
215
+ "page": "Puget Sound Food Hub Cooperative"
216
+ },
217
+ {
218
+ "id": "nabc",
219
+ "label": "NW Agriculture Business Center",
220
+ "start": "Jul 1 2006",
221
+ "end": "Sep 28 2026",
222
+ "startFuzz": 0.5,
223
+ "endFuzz": 0,
224
+ "color": "#1a7a4a",
225
+ "row": 27,
226
+ "who": "agbizcenter.org",
227
+ "conf": 0.85,
228
+ "note": "Established 2006 in Mount Vernon (Skagit). USDA-funded rural co-op development centre.",
229
+ "coops": [
230
+ "nabc"
231
+ ],
232
+ "page": "Northwest Agriculture Business Center"
233
+ }
234
+ ],
235
+ "links": [
236
+ {
237
+ "from": "nabc_ncm",
238
+ "to": "nabc",
239
+ "rel": "during",
240
+ "who": "agbizcenter.org",
241
+ "note": "NABC's co-op development work."
242
+ },
243
+ {
244
+ "from": "psfh_nabc",
245
+ "to": "nabc",
246
+ "rel": "during",
247
+ "who": "WSU case study",
248
+ "note": "NABC ran the hub."
249
+ }
250
+ ]
251
+ }
252
+ },
253
+ "date": 1790644321808,
254
+ "after": "8bd7dff26d7d8c1e"
255
+ },
256
+ {
257
+ "type": "add",
258
+ "id": "3b7a3ee27915f0e4",
259
+ "item": {
260
+ "type": "paragraph",
261
+ "text": "Coming next: lineup merging, so a timeline collects the timelines of the pages to its left, and an Open in RCN Timeline button that saves back into the item.",
262
+ "id": "3b7a3ee27915f0e4"
263
+ },
264
+ "date": 1790644321809,
265
+ "after": "11dd477f3b62535a"
266
+ },
267
+ {
268
+ "type": "add",
269
+ "id": "a5673a5be44d674a",
270
+ "item": {
271
+ "type": "markdown",
272
+ "id": "a5673a5be44d674a",
273
+ "text": "*Marc Pierson and Claude Opus 5.5 \u00b7 September 2026*",
274
+ "attribution": true
275
+ },
276
+ "date": 1790644321962,
277
+ "after": "3b7a3ee27915f0e4"
278
+ },
279
+ {
280
+ "type": "add",
281
+ "id": "029356e7e8442a58",
282
+ "item": {
283
+ "type": "paragraph",
284
+ "id": "029356e7e8442a58",
285
+ "text": "See [https://github.com/marpie1/rcn/tree/master/wiki-plugin-rcntimeline GitHub] for plugin source."
286
+ },
287
+ "after": "f0a9a8322aafc9ab",
288
+ "date": 1791164815533
289
+ }
290
+ ]
291
+ }