wiki-plugin-rcnmap 0.3.0 → 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.
package/README.md CHANGED
@@ -53,9 +53,15 @@ A map can carry walks, written in the RCN Map (🚶 Walk, then ✎ Edit) and cop
53
53
  - Same bar, keys and voice settings (localStorage `rcnWalkPrefs` / `rcnWalkVoice`) as the rcngraph and rcntimeline walks, and one walk speaks at a time on the page.
54
54
  - A `LINEUP` or frozen map plays none: its ids are gathered from other pages, not the ones the walk names.
55
55
 
56
+ ## Open in RCN Map — write walks, save them back
57
+
58
+ **🗺 Open in RCN Map** under the map opens the full RCN Map in its own window with this item's points, ties and walks (passed as `#rcnmap=<base64 JSON>&page=<base64 title>`; nothing is uploaded). A blue banner there says which page the map came from. Write or change walks with 🚶 Walk → ✎ Edit, then **⬆ Save to wiki**: the map posts `{toolType:'rcnmap', action:'saveMap', walks}` back to this page, which saves them into `item.map.walks` as an ordinary edit and answers `{action:'saved'}`. Only walks come back — the full map does not edit points or ties yet. An item drawn from its text alone gets a `map` of its own on its first save.
59
+
60
+ Which copy of the map opens: the working copy on `localhost:8765` from a local wiki; otherwise the site's own `/assets/NDC/rcn_map.html` if it has one; otherwise the live copy on ndcgroup, which has the map's base data beside it. An item's `tool` field overrides all three.
61
+
56
62
  ## Status
57
63
 
58
- Version 0.3: draws points, ties and a legend; a point opens its page; lineup merging with ties, ❄ freeze, ↻ refresh; walks play. Planned next, in `docs/rcn-map-plugin-plan.md`: "Open in RCN Map" with save-back, and shared layers.
64
+ Version 0.4: draws points, ties and a legend; a point opens its page; lineup merging with ties, ❄ freeze, ↻ refresh; walks play; Open in RCN Map writes walks and saves them back. Planned next, in `docs/rcn-map-plugin-plan.md`: editing points and ties in the full map (so they save back too), and shared layers.
59
65
 
60
66
  Part of the [RCN toolset](https://github.com/marpie1/rcn), MIT.
61
67
 
package/client/rcnmap.js CHANGED
@@ -359,12 +359,73 @@
359
359
  if (wk.w !== null) end()
360
360
  }
361
361
 
362
+ // ── Open in RCN Map: write walks in the full map and save them back ────────
363
+ // A local wiki opens the working copy on :8765. Anywhere else: the site's own
364
+ // copy in its NDC assets folder if it has one, otherwise the live copy on
365
+ // ndcgroup, where the map's 5 MB of base data sits beside it (one shared copy
366
+ // serves every site). An item may name its own with a `tool` field. The map
367
+ // opens the item's map passed as #rcnmap=<base64 JSON>&page=<base64 title>,
368
+ // and its Save to wiki posts back {toolType:'rcnmap', action:'saveMap', walks}.
369
+ // Only walks come back: the full map does not edit points or ties yet.
370
+ const HERE = typeof window !== 'undefined' ? window.location : { hostname: '', origin: '' }
371
+ const LOCAL = /(^|\.)localhost$/.test(HERE.hostname)
372
+ const LOCAL_URL = 'http://localhost:8765/maps/rcn_map.html'
373
+ const SITE_URL = HERE.origin + '/assets/NDC/rcn_map.html'
374
+ const SHARED_URL = 'https://ndcgroup.relocalizecreativity.net/assets/NDC/rcn_map.html'
375
+ function toolUrl (item) {
376
+ if (item.tool) return Promise.resolve(item.tool)
377
+ if (LOCAL) return Promise.resolve(LOCAL_URL)
378
+ return fetch(SITE_URL, { method: 'HEAD', cache: 'no-store' })
379
+ .then(r => (r.ok ? SITE_URL : SHARED_URL), () => SHARED_URL)
380
+ }
381
+ const b64 = str => btoa(unescape(encodeURIComponent(str)))
382
+ const canOpen = item => !lineupOn(item) && !item.frozen
383
+
384
+ let pending = null // {item, $item, win} — the item the map will save into
385
+ function openTool ($item, item) {
386
+ const m = model(item)
387
+ const page = ($item.parents('.page:first').data('data') || {}).title || ''
388
+ const hand = { caption: caption(item), types: m.types, linkKinds: m.linkKinds, parcels: m.parcels, links: m.links, walks: m.walks || [] }
389
+ const hash = '#rcnmap=' + encodeURIComponent(b64(JSON.stringify(hand))) + '&page=' + encodeURIComponent(b64(page))
390
+ // Open the window now, while the click still counts, and point it at the
391
+ // map once we know which copy to use; otherwise popup blockers stop it.
392
+ const win = window.open('', 'rcnmap')
393
+ pending = { item, $item, win }
394
+ toolUrl(item).then(url => {
395
+ if (win) { win.location.href = url + hash; win.focus() } else window.open(url + hash, 'rcnmap')
396
+ })
397
+ }
398
+
399
+ // Save-back from the full map. Only the window this page opened is heard,
400
+ // and it saves into the item opened last. An item drawn from its text alone
401
+ // gets a map of its own, so the walks have somewhere to live.
402
+ function toolListener (event) {
403
+ if (!pending || !event.data || event.data.toolType !== 'rcnmap') return
404
+ if (pending.win && event.source !== pending.win) return
405
+ if (event.data.action !== 'saveMap' || !Array.isArray(event.data.walks)) return
406
+ const { item, $item } = pending
407
+ if (!item.map) item.map = model(item)
408
+ if (event.data.walks.length) item.map.walks = event.data.walks
409
+ else delete item.map.walks
410
+ save($item, item)
411
+ try { event.source.postMessage({ toolType: 'rcnmap', action: 'saved', page: ($item.parents('.page:first').data('data') || {}).title }, '*') } catch (e) {}
412
+ }
413
+
362
414
  function loadLeaflet (done) {
363
415
  if (!document.querySelector(`link[href='${LEAFLET_CSS}']`)) {
364
416
  $(`<link rel="stylesheet" href="${LEAFLET_CSS}">`).appendTo('head')
365
417
  }
366
418
  if (window.L && window.L.map) return done()
367
- wiki.getScript(LEAFLET_JS, done)
419
+ // A plain script tag, not wiki.getScript: newer wiki-clients load through
420
+ // import(), and Leaflet's UMD wrapper then never sets window.L.
421
+ let s = document.querySelector(`script[src='${LEAFLET_JS}']`)
422
+ if (!s) {
423
+ s = document.createElement('script')
424
+ s.src = LEAFLET_JS
425
+ document.head.appendChild(s)
426
+ }
427
+ s.addEventListener('load', () => done())
428
+ s.addEventListener('error', () => console.log('rcnmap: could not load Leaflet from', LEAFLET_JS))
368
429
  }
369
430
 
370
431
  function legendHTML (m) {
@@ -410,6 +471,7 @@
410
471
  <p class="caption" style="margin:4px 0 0;">${wiki.resolveLinks ? wiki.resolveLinks(esc(caption(item))) : esc(caption(item))}</p>
411
472
  ${controls}
412
473
  ${walkBar(item)}
474
+ ${canOpen(item) ? `<div style="text-align:center;padding-top:6px"><button class="rcnm-open" style="cursor:pointer;font-size:12px;padding:2px 8px" title="Open this map in the full RCN Map to write or change its walks; Save to wiki there brings them back here">🗺 Open in RCN Map</button></div>` : ''}
413
475
  </div>
414
476
  <style>
415
477
  .rcnm-label{background:none;border:0}
@@ -487,6 +549,8 @@
487
549
  }
488
550
 
489
551
  function save ($item, item) {
552
+ const wk = $item.get(0).rcnmWalk
553
+ if (wk && wk.w !== null && wk.end) wk.end() // the walk being played may have just changed
490
554
  wiki.pageHandler.put($item.parents('.page:first'), { type: 'edit', id: item.id, item })
491
555
  emit($item, item)
492
556
  }
@@ -523,6 +587,7 @@
523
587
  function bind ($item, item) {
524
588
  aboutMark($item, 'rcnmap')
525
589
  bindWalk($item, item)
590
+ $item.on('click', '.rcnm-open', e => { e.stopPropagation(); openTool($item, item) })
526
591
  $item.dblclick(e => { if (!$(e.target).closest('button, .walk-bar').length) wiki.textEditor($item, item) })
527
592
  $item.on('click', '.rcnm-refresh', e => { e.stopPropagation(); emit($item, item) })
528
593
  $item.on('click', '.rcnm-freeze', e => {
@@ -537,9 +602,13 @@
537
602
 
538
603
  if (typeof window !== 'undefined') {
539
604
  window.plugins.rcnmap = { emit, bind }
605
+ if (!window.rcnmapListener) {
606
+ window.rcnmapListener = toolListener
607
+ window.addEventListener('message', toolListener)
608
+ }
540
609
  }
541
610
  if (typeof module !== 'undefined') {
542
- module.exports = { model, caption, merge, lineupOn, walkList, stepLit }
611
+ module.exports = { model, caption, merge, lineupOn, walkList, stepLit, toolUrl }
543
612
  }
544
613
 
545
614
  })()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-rcnmap",
3
- "version": "0.3.0",
3
+ "version": "0.4.1",
4
4
  "description": "Federated Wiki plugin: a small RCN map on a page that draws points and the ties between them; each point opens its page",
5
5
  "keywords": ["wiki", "federated wiki", "plugin", "rcn", "map"],
6
6
  "author": "RCN Network <rcn@relocalizecreativity.net>",
@@ -130,13 +130,13 @@
130
130
  },
131
131
  {
132
132
  "type": "paragraph",
133
- "text": "Walks. A map made from an RCN Map issue can carry walks: a reading of the map, one step at a time. Press \u25b6 Walk under the map. Each step flies the map to the points and ties it is about, names those points, fades the rest (the ones already visited stay half lit) and reads one or two sentences aloud, shown as a caption too. Space plays or pauses, \u2190 and \u2192 step, Esc stops. Voice on or off and the choice of voice are kept in this browser and shared with the Graph Tool and Timeline walks. Walks are written in the RCN Map (\ud83d\udeb6 Walk, then \u270e Edit) and copied into the item's map; a LINEUP or frozen map plays none, because its points are gathered from other pages.",
133
+ "text": "Walks. A map made from an RCN Map issue can carry walks: a reading of the map, one step at a time. Press \u25b6 Walk under the map. Each step flies the map to the points and ties it is about, names those points, fades the rest (the ones already visited stay half lit) and reads one or two sentences aloud, shown as a caption too. Space plays or pauses, \u2190 and \u2192 step, Esc stops. Voice on or off and the choice of voice are kept in this browser and shared with the Graph Tool and Timeline walks. To write or change them, press \ud83d\uddfa Open in RCN Map: the full map opens with this map in it, a blue banner names this page, and after \ud83d\udeb6 Walk \u2192 \u270e Edit, \u2b06 Save to wiki brings the walks back into the item as an ordinary edit. Only walks come back; points and ties are edited in the item's text for now. a LINEUP or frozen map plays none, because its points are gathered from other pages.",
134
134
  "id": "acad2aaf540683fe"
135
135
  },
136
136
  {
137
137
  "type": "paragraph",
138
138
  "id": "22dca488818d034f",
139
- "text": "Coming next: an Open in RCN Map button that saves back into the item, and shared layers referenced by address. Plan: docs/rcn-map-plugin-plan.md in the rcn repository."
139
+ "text": "Coming next: editing points and ties in the full RCN Map so they save back too, and shared layers referenced by address. Plan: docs/rcn-map-plugin-plan.md in the rcn repository."
140
140
  },
141
141
  {
142
142
  "type": "markdown",
@@ -311,7 +311,7 @@
311
311
  "id": "acad2aaf540683fe",
312
312
  "item": {
313
313
  "type": "paragraph",
314
- "text": "Walks. A map made from an RCN Map issue can carry walks: a reading of the map, one step at a time. Press \u25b6 Walk under the map. Each step flies the map to the points and ties it is about, names those points, fades the rest (the ones already visited stay half lit) and reads one or two sentences aloud, shown as a caption too. Space plays or pauses, \u2190 and \u2192 step, Esc stops. Voice on or off and the choice of voice are kept in this browser and shared with the Graph Tool and Timeline walks. Walks are written in the RCN Map (\ud83d\udeb6 Walk, then \u270e Edit) and copied into the item's map; a LINEUP or frozen map plays none, because its points are gathered from other pages.",
314
+ "text": "Walks. A map made from an RCN Map issue can carry walks: a reading of the map, one step at a time. Press \u25b6 Walk under the map. Each step flies the map to the points and ties it is about, names those points, fades the rest (the ones already visited stay half lit) and reads one or two sentences aloud, shown as a caption too. Space plays or pauses, \u2190 and \u2192 step, Esc stops. Voice on or off and the choice of voice are kept in this browser and shared with the Graph Tool and Timeline walks. To write or change them, press \ud83d\uddfa Open in RCN Map: the full map opens with this map in it, a blue banner names this page, and after \ud83d\udeb6 Walk \u2192 \u270e Edit, \u2b06 Save to wiki brings the walks back into the item as an ordinary edit. Only walks come back; points and ties are edited in the item's text for now. a LINEUP or frozen map plays none, because its points are gathered from other pages.",
315
315
  "id": "acad2aaf540683fe"
316
316
  },
317
317
  "date": 1790643282159,
@@ -346,7 +346,7 @@
346
346
  "item": {
347
347
  "type": "paragraph",
348
348
  "id": "22dca488818d034f",
349
- "text": "Coming next: an Open in RCN Map button that saves back into the item, and shared layers referenced by address. Plan: docs/rcn-map-plugin-plan.md in the rcn repository."
349
+ "text": "Coming next: editing points and ties in the full RCN Map so they save back too, and shared layers referenced by address. Plan: docs/rcn-map-plugin-plan.md in the rcn repository."
350
350
  },
351
351
  "after": "acad2aaf540683fe",
352
352
  "date": 1792642784633