wiki-plugin-mech 0.1.21 → 0.1.23

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.
Files changed (2) hide show
  1. package/client/mech.js +72 -3
  2. package/package.json +1 -1
package/client/mech.js CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  (function() {
3
-
3
+ "use strict"
4
4
  const uniq = (value, index, self) => self.indexOf(value) === index
5
5
 
6
6
  function expand(text) {
@@ -37,7 +37,7 @@
37
37
  const unique = Math.floor(Math.random()*1000000)
38
38
  const block = (more,path) => {
39
39
  const html = []
40
- for (part of more) {
40
+ for (const part of more) {
41
41
  const key = `${unique}.${path.join('.')}`
42
42
  part.key = key
43
43
  if('command' in part)
@@ -600,6 +600,72 @@
600
600
  state.items = items
601
601
  }
602
602
 
603
+ function lineup_emit({elem,command,state}) {
604
+ const items = [...document.querySelectorAll('.page')]
605
+ .map(div => {
606
+ const $page = $(div)
607
+ const page = $page.data('data')
608
+ const site = $page.data('site') || location.host
609
+ const slug = $page.attr('id').split('_')[0]
610
+ const title = page.title || 'Empty'
611
+ const text = page.story[0]?.text||'empty'
612
+ return {type:'reference',site,slug,title,text}
613
+ })
614
+ elem.innerHTML = command + ` ⇒ ${items.length} pages`
615
+ state.items = items
616
+ }
617
+
618
+ function listen_emit({elem,command,args,state}) {
619
+ if (args.length < 1) return trouble(elem,`LISTEN expects argument, an action.`)
620
+ const topic = args[0]
621
+ let recent = Date.now()
622
+ let count = 0
623
+ const handler=listen
624
+ handler.action = 'publishSourceData'
625
+ handler.id = elem.id
626
+ window.addEventListener("message", listen)
627
+ $(".main").on('thumb', (evt, thumb) => console.log('jquery',{evt, thumb}))
628
+ elem.innerHTML = command + ` ⇒ ready`
629
+
630
+ // window.listeners = (action=null) => {
631
+ // return getEventListeners(window).message
632
+ // .map(t => t.listener)
633
+ // .filter(f => f.name == 'listen')
634
+ // .map(f => ({action:f.action,elem:document.getElementById(f.id),count:f.count}))
635
+ // }
636
+
637
+
638
+
639
+ function listen(event) {
640
+ console.log({event})
641
+ const {data} = event
642
+ if (data.action == 'publishSourceData' && (data.name == topic || data.topic == topic)) {
643
+ count++
644
+ handler.count = count
645
+ if(state.debug) console.log({count,data})
646
+ if(count<=100){
647
+ const now = Date.now()
648
+ const elapsed = now-recent
649
+ recent = now
650
+ elem.innerHTML = command + ` ⇒ ${count} events, ${elapsed} ms`
651
+ } else {
652
+ window.removeEventListener("message", listen)
653
+ }
654
+ }
655
+ }
656
+ }
657
+
658
+ function message_emit({elem,command,args,state}) {
659
+ if (args.length < 1) return trouble(elem,`MESSAGE expects argument, an action.`)
660
+ const topic = args[0]
661
+ const message = {
662
+ action: "publishSourceData",
663
+ topic,
664
+ name: topic,}
665
+ window.postMessage(message,"*")
666
+ elem.innerHTML = command + ` ⇒ sent`
667
+ }
668
+
603
669
 
604
670
  // C A T A L O G
605
671
 
@@ -625,7 +691,10 @@
625
691
  TOGETHER:{emit:together_emit},
626
692
  GET: {emit:get_emit},
627
693
  DELTA: {emit:delta_emit},
628
- ROSTER: {emit:roster_emit}
694
+ ROSTER: {emit:roster_emit},
695
+ LINEUP: {emit:lineup_emit},
696
+ LISTEN: {emit:listen_emit},
697
+ MESSAGE: {emit:message_emit}
629
698
  }
630
699
 
631
700
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-mech",
3
- "version": "0.1.21",
3
+ "version": "0.1.23",
4
4
  "description": "Federated Wiki - Mechanism Scripting Plugin",
5
5
  "keywords": [
6
6
  "mech",