wiki-plugin-mech 0.1.1 → 0.1.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.
Files changed (2) hide show
  1. package/client/mech.js +22 -19
  2. package/package.json +1 -1
package/client/mech.js CHANGED
@@ -29,17 +29,16 @@
29
29
  return here
30
30
  }
31
31
 
32
- function format(nest,index) {
32
+ function format(nest) {
33
33
  const unique = Math.floor(Math.random()*1000000)
34
34
  const block = (more,path) => {
35
35
  const html = []
36
36
  for (part of more) {
37
37
  const key = `${unique}.${path.join('.')}`
38
- index[key] = part
39
38
  part.key = key
40
39
  if(part.command)
41
40
  html.push(`<span id=${key}>${expand(part.command)}</span>`)
42
- else
41
+ else if(typeof part == 'array')
43
42
  html.push(`<div id=${key} style="padding-left:15px">${block(part,[...path,0])}</div> `)
44
43
  path[path.length-1]++
45
44
  }
@@ -48,17 +47,18 @@
48
47
  return block(nest,[0])
49
48
  }
50
49
 
50
+ function trouble(elem,message) {
51
+ elem.innerHTML += `<button style="border-width:0;color:red;">✖︎</button>`
52
+ elem.querySelector('button').addEventListener('click',event => {
53
+ elem.outerHTML += `<span style="width:80%;color:gray;">${message}</span>` })
54
+ }
55
+
51
56
  function click_emit (elem) {
57
+ if(elem.innerHTML.match(/button/)) return
52
58
  const body = this
53
- console.log({body,elem})
54
- if (!body.length && !elem.innerHTML.match(/button/)) {
55
- console.log('trouble')
56
- elem.innerHTML += '<button style="border-width:0;color:red;" title="nothing to run">✖︎</button>'
57
- } else
58
- if (!elem.innerHTML.match(/button/)) {
59
- elem.innerHTML += '<button style="border-width:0;">◉</button>'
60
- elem.querySelector('button').addEventListener('click',event => run(this))
61
- }
59
+ if (!body.length) return trouble(elem,'CLICK expects indented blocks to follow.')
60
+ elem.innerHTML += '<button style="border-width:0;">◉</button>'
61
+ elem.querySelector('button').addEventListener('click',event => run(this))
62
62
  }
63
63
 
64
64
  function click_bind (elem) {
@@ -78,7 +78,6 @@
78
78
  }
79
79
 
80
80
  function run (nest) {
81
- console.log({nest})
82
81
  const scope = nest.slice()
83
82
  while (scope.length) {
84
83
  const code = scope.shift()
@@ -86,9 +85,14 @@
86
85
  const elem = document.getElementById(code.key)
87
86
  const [op, ...args] = code.command.split(/ +/)
88
87
  const more = scope[0]?.command ? null : scope.shift()
89
- console.log({op,args,more})
90
- blocks[op].emit.apply(more||[],[elem,...args])
91
- } else {
88
+ if (blocks[op])
89
+ blocks[op].emit.apply(more||[],[elem,...args])
90
+ else
91
+ if (op.match(/^[A-Z]+$/))
92
+ trouble(elem,`${op} doesn't name a block we know.`)
93
+ else if (code.command.match(/\S/))
94
+ trouble(elem, `Expected line to begin with all-caps keyword.`)
95
+ } else if(typeof code == 'array') {
92
96
  run(code)
93
97
  }
94
98
  }
@@ -97,10 +101,9 @@
97
101
  function emit($item, item) {
98
102
  const lines = item.text.split(/\n/)
99
103
  const nest = tree(lines,[],0)
100
- const index = {}
101
- const html = format(nest,index)
104
+ const html = format(nest)
102
105
  $item.append(`<div style="background-color:#eee;padding:15px;border-top:8px;">${html}</div>`)
103
- run(nest,index)
106
+ run(nest)
104
107
  }
105
108
 
106
109
  function bind($item, item) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "wiki-plugin-mech",
3
- "version": "0.1.1",
3
+ "version": "0.1.2",
4
4
  "description": "Federated Wiki - Mechanism Scripting Plugin",
5
5
  "keywords": [
6
6
  "mech",