wiki-plugin-rcnsd 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -33,6 +33,19 @@ and restart the wiki. The Factory then offers **RCN System Dynamics**.
33
33
  - `text`: the first line is the caption. The rest names the stocks, flows and walks, for search and for a wiki without this plugin. The plugin rewrites it on every save and keeps your caption.
34
34
  - `tool` (optional): where Edit opens the full tool.
35
35
 
36
+ ## Writing walks on the page
37
+
38
+ The page's owner can write and change walks without opening the tool. **+ New walk** starts one. **✎ Edit walk** on an open walk turns the step's words into a box and adds buttons:
39
+
40
+ - **Light the names on the graph**: the step lights exactly the names graphed now. Click names in the drawing to choose them.
41
+ - **Light everything**: an overview step.
42
+ - **Keep these graphs**: the step puts these names on the graph.
43
+ - **Show this time**, **Play the run up to this time**: set from the slider.
44
+ - **A question for the group**: marks a closing question.
45
+ - **+ Step after this**, **↑ ↓**, **Delete this step**, the walk's name, and **Delete this walk** (a second click within 4 seconds).
46
+
47
+ **✓ Done** saves the walk to the page; closing the walk saves too. Steps that turn knobs (`set`, `final`) are written in the full tool; the page keeps them.
48
+
36
49
  ## Starting one
37
50
 
38
51
  Add **RCN System Dynamics** from the Factory, then drop a Vensim `.mdl` file on the empty item. Or press **Open RCN System Dynamics ↗**, open a model there and press **→ Save to wiki item**. Dropping a walks file (`.sdwalks.json`) on an item that holds a model adds its walks. Only the page's owner can drop.
package/client/rcnsd.js CHANGED
@@ -1214,7 +1214,33 @@
1214
1214
  dropped: name => 'Opened ' + name + ' into this item.',
1215
1215
  walksAdded: n => n + ' walk' + (n === 1 ? '' : 's') + ' added to this item.',
1216
1216
  notMdl: 'That isn\'t a Vensim .mdl file or a walks file.',
1217
- savedBack: 'Saved from RCN System Dynamics.'
1217
+ savedBack: 'Saved from RCN System Dynamics.',
1218
+ // writing walks on the page (the page's owner only)
1219
+ newWalk: '+ New walk',
1220
+ newWalkName: c => 'A walk through ' + c,
1221
+ editWalk: '✎ Edit walk',
1222
+ doneEdit: '✓ Done (save to page)',
1223
+ weSay: 'What to say at this step',
1224
+ weHow: 'Click names in the drawing to put them on the graph, then press "Light the names on the graph". Move the slider before "Show this time" or "Play the run up to this time".',
1225
+ weLight: 'Light the names on the graph',
1226
+ weAll: 'Light everything',
1227
+ weGraphs: 'Keep these graphs',
1228
+ weTime: 'Show this time',
1229
+ weRun: 'Play the run up to this time',
1230
+ weAsk: 'A question for the group',
1231
+ weAdd: '+ Step after this',
1232
+ weDel: 'Delete this step',
1233
+ weUp: '↑', weDown: '↓',
1234
+ weName: 'Walk name',
1235
+ weDelWalk: 'Delete this walk',
1236
+ weDelSure: 'Click "Delete this walk" again within 4 seconds to delete the whole walk.',
1237
+ weSaved: 'Saved to the page.',
1238
+ weSum: (lit, extra) => 'This step lights ' + lit + '.' + extra,
1239
+ weAllLit: 'everything',
1240
+ weNone: 'nothing yet',
1241
+ weTimeSum: t => ' Shows ' + t + '.',
1242
+ weRunSum: t => ' Plays the run to ' + t + '.',
1243
+ weGraphSum: g => ' Graphs ' + g + '.'
1218
1244
  }
1219
1245
 
1220
1246
  // ── math.js, once per page ──
@@ -1496,12 +1522,14 @@
1496
1522
  const voiceOn = () => { try { return localStorage.getItem('rcnSdWalkVoice') !== 'off' } catch (e) { return true } }
1497
1523
  function stopAll () { wk.token++; clearTimeout(wk.timer); cancelAnimationFrame(wk.anim); try { speechSynthesis.cancel() } catch (e) {} }
1498
1524
  function walkBar () {
1499
- const $b = $item.find('.rcnsd-walkbar'), ws = item.walks || []
1500
- if (!ws.length) { $b.empty(); return }
1525
+ const $b = $item.find('.rcnsd-walkbar'), ws = item.walks || [], owner = canEdit($item)
1501
1526
  const walk = curWalk(), btn = 'cursor:pointer;color:#2f6f5e'
1527
+ if (!ws.length && !owner) { $b.empty(); return }
1502
1528
  if (!walk) {
1503
1529
  $b.html(`<div style="padding:6px 0 0;display:flex;gap:6px;justify-content:center;flex-wrap:wrap">` +
1504
- ws.map((w, i) => `<button class="rcnsd-wstart" data-w="${i}" style="${btn}">${W.walk}: ${esc(w.name || 'Walk ' + (i + 1))}</button>`).join('') + `</div>`)
1530
+ ws.map((w, i) => `<button class="rcnsd-wstart" data-w="${i}" style="${btn}">${W.walk}: ${esc(w.name || 'Walk ' + (i + 1))}</button>`).join('') +
1531
+ (owner ? `<button class="rcnsd-wnew" style="cursor:pointer;color:#64748b">${W.newWalk}</button>` : '') + `</div>` +
1532
+ (wk.note ? `<div class="rcnsd-wnote" style="font-size:11px;color:#64748b;text-align:center;padding-top:2px">${esc(wk.note)}</div>` : ''))
1505
1533
  return
1506
1534
  }
1507
1535
  const s = walk.steps[wk.i] || {}
@@ -1511,12 +1539,55 @@
1511
1539
  <button class="rcnsd-wnext" style="${btn}" title="Next (→)">${W.next}</button>
1512
1540
  <span style="font-size:12px;color:#64748b;min-width:80px;text-align:center">${W.count(wk.i, walk.steps.length)}</span>
1513
1541
  <button class="rcnsd-wvoice" style="${btn}" title="Read aloud">${voiceOn() ? W.voiceOn : W.voiceOff}</button>
1542
+ ${owner ? `<button class="rcnsd-wedit" style="${btn}">${wk.edit ? W.doneEdit : W.editWalk}</button>` : ''}
1514
1543
  <button class="rcnsd-wclose" style="${btn}" title="Stop (Esc)">${W.close}</button>
1515
1544
  </div>
1516
- <div style="font-size:14px;line-height:1.5;padding:6px 4px 0;color:${s.ask ? '#7c2d12' : '#1e1b4b'};${s.ask ? 'font-style:italic' : ''}">
1545
+ ${wk.edit ? editPanel(walk, s) : `<div style="font-size:14px;line-height:1.5;padding:6px 4px 0;color:${s.ask ? '#7c2d12' : '#1e1b4b'};${s.ask ? 'font-style:italic' : ''}">
1517
1546
  ${s.ask ? `<span style="font-size:10px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;border:1px solid currentColor;border-radius:3px;padding:0 4px;margin-right:6px;font-style:normal">${W.ask}</span>` : ''}${esc(s.say || '')}
1518
- </div>
1519
- <div class="rcnsd-wnote" style="font-size:11px;color:#64748b;text-align:center;padding-top:2px">${wk.note || (wk.playing ? '' : W.keys)}</div>`)
1547
+ </div>`}
1548
+ <div class="rcnsd-wnote" style="font-size:11px;color:#64748b;text-align:center;padding-top:2px">${esc(wk.note || (wk.playing || wk.edit ? '' : W.keys))}</div>`)
1549
+ }
1550
+ function editPanel (walk, s) {
1551
+ const b = 'cursor:pointer;font-size:12px'
1552
+ const lit = s.all ? W.weAllLit : (s.names && s.names.length ? s.names.join(', ') : W.weNone)
1553
+ const extra = (s.run ? W.weRunSum(st.timeUnit + ' ' + num(s.run[1])) : s.time != null ? W.weTimeSum(st.timeUnit + ' ' + num(s.time)) : '') +
1554
+ (s.graph && s.graph.length ? W.weGraphSum(s.graph.join(', ')) : '')
1555
+ return `<div class="rcnsd-editor" style="display:grid;gap:5px;padding:6px 2px 0">
1556
+ <label style="font-size:12px;color:#475569;display:grid;gap:2px">${W.weSay}
1557
+ <textarea class="rcnsd-we-say" rows="3" style="width:100%;height:5.2em;min-height:0;font:inherit;font-size:14px;padding:4px 6px;box-sizing:border-box;resize:vertical">${esc(s.say || '')}</textarea></label>
1558
+ <div style="font-size:12px;color:#475569">${esc(W.weSum(lit, extra))}</div>
1559
+ <div style="display:flex;gap:4px;flex-wrap:wrap">
1560
+ <button class="rcnsd-we-light" style="${b}">${W.weLight}</button>
1561
+ <button class="rcnsd-we-all" style="${b}">${W.weAll}</button>
1562
+ <button class="rcnsd-we-graphs" style="${b}">${W.weGraphs}</button>
1563
+ <button class="rcnsd-we-time" style="${b}">${W.weTime}</button>
1564
+ <button class="rcnsd-we-run" style="${b}">${W.weRun}</button>
1565
+ <label style="font-size:12px;display:inline-flex;gap:3px;align-items:center"><input type="checkbox" class="rcnsd-we-ask" ${s.ask ? 'checked' : ''}> ${W.weAsk}</label>
1566
+ </div>
1567
+ <div style="display:flex;gap:4px;flex-wrap:wrap;align-items:center">
1568
+ <button class="rcnsd-we-add" style="${b}">${W.weAdd}</button>
1569
+ <button class="rcnsd-we-up" style="${b}" ${wk.i === 0 ? 'disabled' : ''}>${W.weUp}</button>
1570
+ <button class="rcnsd-we-down" style="${b}" ${wk.i >= walk.steps.length - 1 ? 'disabled' : ''}>${W.weDown}</button>
1571
+ <button class="rcnsd-we-del" style="${b}">${W.weDel}</button>
1572
+ <span style="flex:1"></span>
1573
+ <label style="font-size:12px;color:#475569">${W.weName} <input class="rcnsd-we-name" value="${esc(walk.name || '')}" style="width:12em;font-size:12px"></label>
1574
+ <button class="rcnsd-we-delwalk" style="${b};color:#9a3412">${W.weDelWalk}</button>
1575
+ </div>
1576
+ <div style="font-size:11px;color:#64748b">${W.weHow}</div>
1577
+ </div>`
1578
+ }
1579
+ // save the walks into the item, and the page; the walk stays open where it was
1580
+ function saveWalks (note) {
1581
+ item.text = describe(item)
1582
+ wiki.pageHandler.put($item.parents('.page:first'), { type: 'edit', id: item.id, item })
1583
+ wk.dirty = false
1584
+ if (note !== false) wk.note = W.weSaved
1585
+ }
1586
+ function edited (redraw) {
1587
+ wk.dirty = true
1588
+ const walk = curWalk()
1589
+ if (redraw && walk && st.sk) st.sk.paint(Sketch.litSets(walk, wk.i), wk.edit)
1590
+ walkBar()
1520
1591
  }
1521
1592
  function walkShow (i) {
1522
1593
  const walk = curWalk(); if (!walk) return
@@ -1528,7 +1599,7 @@
1528
1599
  st.final = s.final != null ? s.final : st.base.final
1529
1600
  run()
1530
1601
  if (s.graph) { st.selected = []; st.colorOf = {}; s.graph.forEach(n => pick(n, true)) }
1531
- if (st.sk) st.sk.paint(Sketch.litSets(walk, wk.i), false)
1602
+ if (st.sk) st.sk.paint(Sketch.litSets(walk, wk.i), !!wk.edit)
1532
1603
  const idx = t => { const r = st.result; if (!r) return 0; let b = 0; r.time.forEach((x, k) => { if (Math.abs(x - t) < Math.abs(r.time[b] - t)) b = k }); return b }
1533
1604
  let animDone = true, spoken = !wk.playing || !voiceOn() || !s.say
1534
1605
  if (s.run && st.result) {
@@ -1566,7 +1637,9 @@
1566
1637
  next()
1567
1638
  }
1568
1639
  function walkEnd () {
1569
- stopAll(); wk.w = null; wk.playing = false; wk.note = ''
1640
+ const was = wk.dirty
1641
+ stopAll(); wk.w = null; wk.playing = false; wk.note = ''; wk.edit = false
1642
+ if (was) saveWalks()
1570
1643
  st.over = Object.assign({}, st.base.overrides || {}); st.final = st.base.final
1571
1644
  run()
1572
1645
  st.selected = []; st.colorOf = {}
@@ -1594,8 +1667,52 @@
1594
1667
  if (!voiceOn()) try { speechSynthesis.cancel() } catch (err) {}
1595
1668
  walkBar()
1596
1669
  })
1670
+ // ── writing walks ──
1671
+ const cur = () => { const w = curWalk(); return w && w.steps[wk.i] }
1672
+ const timeAt = k => st.result ? st.result.time[k] : 0
1673
+ $item.on('click.rcnsd', '.rcnsd-wnew', e => {
1674
+ e.stopPropagation()
1675
+ if (!canEdit($item)) return
1676
+ item.walks = item.walks || []
1677
+ const caption = String(item.text || '').split('\n')[0].trim() || (item.fileName || 'this model').replace(/\.mdl$/i, '')
1678
+ item.walks.push({ name: W.newWalkName(caption), steps: [{ say: '', all: true }] })
1679
+ wk.w = item.walks.length - 1; wk.i = 0; wk.playing = false; wk.edit = true; wk.dirty = true
1680
+ walkShow(0)
1681
+ })
1682
+ $item.on('click.rcnsd', '.rcnsd-wedit', e => {
1683
+ e.stopPropagation()
1684
+ stopAll(); wk.playing = false
1685
+ if (wk.edit) { wk.edit = false; if (wk.dirty) saveWalks() } else { wk.edit = true; wk.note = '' }
1686
+ const walk = curWalk(); if (walk && st.sk) st.sk.paint(Sketch.litSets(walk, wk.i), wk.edit)
1687
+ walkBar()
1688
+ })
1689
+ $item.on('input.rcnsd', '.rcnsd-we-say', e => { const s = cur(); if (s) { s.say = e.target.value; wk.dirty = true } })
1690
+ $item.on('input.rcnsd', '.rcnsd-we-name', e => { const w = curWalk(); if (w) { w.name = e.target.value; wk.dirty = true } })
1691
+ $item.on('click.rcnsd', '.rcnsd-we-light', e => { e.stopPropagation(); const s = cur(); delete s.all; s.names = st.selected.slice(); edited(true) })
1692
+ $item.on('click.rcnsd', '.rcnsd-we-all', e => { e.stopPropagation(); const s = cur(); s.all = true; s.names = []; edited(true) })
1693
+ $item.on('click.rcnsd', '.rcnsd-we-graphs', e => { e.stopPropagation(); cur().graph = st.selected.slice(); edited() })
1694
+ $item.on('click.rcnsd', '.rcnsd-we-time', e => { e.stopPropagation(); const s = cur(); delete s.run; s.time = timeAt(st.k); edited() })
1695
+ $item.on('click.rcnsd', '.rcnsd-we-run', e => { e.stopPropagation(); const s = cur(); delete s.time; s.run = [timeAt(0), timeAt(st.k)]; edited() })
1696
+ $item.on('change.rcnsd', '.rcnsd-we-ask', e => { const s = cur(); if (e.target.checked) s.ask = true; else delete s.ask; edited() })
1697
+ $item.on('click.rcnsd', '.rcnsd-we-add', e => { e.stopPropagation(); const w = curWalk(); w.steps.splice(wk.i + 1, 0, { say: '', names: [] }); wk.dirty = true; walkShow(wk.i + 1) })
1698
+ $item.on('click.rcnsd', '.rcnsd-we-del', e => {
1699
+ e.stopPropagation(); const w = curWalk()
1700
+ if (w.steps.length <= 1) w.steps[0] = { say: '', names: [] }; else w.steps.splice(wk.i, 1)
1701
+ wk.dirty = true; walkShow(Math.min(wk.i, w.steps.length - 1))
1702
+ })
1703
+ $item.on('click.rcnsd', '.rcnsd-we-up', e => { e.stopPropagation(); const s2 = curWalk().steps; if (wk.i < 1) return; s2.splice(wk.i - 1, 0, s2.splice(wk.i, 1)[0]); wk.dirty = true; walkShow(wk.i - 1) })
1704
+ $item.on('click.rcnsd', '.rcnsd-we-down', e => { e.stopPropagation(); const s2 = curWalk().steps; if (wk.i >= s2.length - 1) return; s2.splice(wk.i + 1, 0, s2.splice(wk.i, 1)[0]); wk.dirty = true; walkShow(wk.i + 1) })
1705
+ $item.on('click.rcnsd', '.rcnsd-we-delwalk', e => {
1706
+ e.stopPropagation()
1707
+ if (!wk.delArmed || Date.now() - wk.delArmed > 4000) { wk.delArmed = Date.now(); wk.note = W.weDelSure; walkBar(); return }
1708
+ wk.delArmed = 0
1709
+ item.walks.splice(wk.w, 1)
1710
+ wk.dirty = false; walkEnd(); saveWalks(false); walkBar()
1711
+ })
1712
+
1597
1713
  $item.on('keydown.rcnsd', '.rcnsd-walkbar', e => {
1598
1714
  if (wk.w === null) return
1715
+ if (/^(INPUT|TEXTAREA|SELECT)$/.test(e.target.tagName)) { if (e.key === 'Escape') e.target.blur(); e.stopPropagation(); return }
1599
1716
  if (e.key === ' ') { e.preventDefault(); e.stopPropagation(); walkToggle() }
1600
1717
  else if (e.key === 'ArrowRight') { e.preventDefault(); e.stopPropagation(); walkShow(wk.i + 1) }
1601
1718
  else if (e.key === 'ArrowLeft') { e.preventDefault(); e.stopPropagation(); walkShow(wk.i - 1) }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcnsd",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Federated Wiki plugin: an RCN System Dynamics model on a page. The item holds the Vensim model; the page draws it, runs it and plays its walks; the full tool edits it and saves it back.",
5
5
  "keywords": [
6
6
  "wiki",
@@ -16,6 +16,11 @@
16
16
  "id": "a1b2c3d4e5f60003",
17
17
  "text": "A walk reads the model step by step, out loud if you like: it lights the names it talks about, can play the run forward and turn a knob to show what changes, and ends with a question for the group. Space plays, the arrows step, Esc stops."
18
18
  },
19
+ {
20
+ "type": "paragraph",
21
+ "id": "a1b2c3d4e5f6000a",
22
+ "text": "The page's owner can write walks right here, without the full tool. + New walk starts one; ✎ Edit walk on an open walk turns its words into a box. For each step: write what to say, click names in the drawing to put them on the graph and press Light the names on the graph (or Light everything), move the slider and press Show this time or Play the run up to this time, and tick A question for the group for a closing question. + Step after this, the arrows and Delete this step arrange the steps. ✓ Done saves the walk to the page."
23
+ },
19
24
  {
20
25
  "type": "paragraph",
21
26
  "id": "a1b2c3d4e5f60004",
@@ -234,4 +239,4 @@
234
239
  "date": 1795308624160
235
240
  }
236
241
  ]
237
- }
242
+ }