wiki-plugin-mech 0.1.12 → 0.1.13
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/client/mech.js +49 -9
- package/package.json +1 -1
package/client/mech.js
CHANGED
|
@@ -121,8 +121,10 @@
|
|
|
121
121
|
})
|
|
122
122
|
}
|
|
123
123
|
|
|
124
|
-
function hello_emit ({elem,args}) {
|
|
124
|
+
function hello_emit ({elem,args,state}) {
|
|
125
125
|
const want = args[0] == 'world' ? ' 🌎' : ' 😀'
|
|
126
|
+
for (const key of Object.keys(state))
|
|
127
|
+
inspect(elem,key,state)
|
|
126
128
|
elem.innerHTML += want
|
|
127
129
|
}
|
|
128
130
|
|
|
@@ -331,23 +333,61 @@
|
|
|
331
333
|
function file_emit ({elem,command,args,body,state}) {
|
|
332
334
|
if(!('assets' in state)) return trouble(elem,`FILE expects state.assets, like from SOURCE assets.`)
|
|
333
335
|
inspect(elem,'assets',state)
|
|
336
|
+
|
|
337
|
+
// [ { "id": "b2d5831168b4706b", "result":
|
|
338
|
+
// { "pages/testing-file-mech":
|
|
339
|
+
// { "//ward.dojo.fed.wiki/assets":
|
|
340
|
+
// [ "KWIC-list+axe-files.txt", "KWIC-list-axe-files.tsv" ] } } } ]
|
|
341
|
+
|
|
342
|
+
const origin = '//'+window.location.host
|
|
343
|
+
const assets = state.assets.map(({id,result}) =>
|
|
344
|
+
Object.entries(result).map(([dir,paths]) =>
|
|
345
|
+
Object.entries(paths).map(([path,files]) =>
|
|
346
|
+
files.map(file => {
|
|
347
|
+
const assets = path.startsWith("//") ? path : `${origin}${path}`
|
|
348
|
+
const host = assets.replace(/\/assets$/,'')
|
|
349
|
+
const url = `${assets}/${dir}/${file}`
|
|
350
|
+
return {id,dir,path,host,file,url}
|
|
351
|
+
})))).flat(3)
|
|
352
|
+
if(state.debug) console.log({assets})
|
|
353
|
+
|
|
334
354
|
if(args.length < 1) return trouble(elem,`FILE expects an argument, the dot suffix for desired files.`)
|
|
335
355
|
if (!body?.length) return trouble(elem,'FILE expects indented blocks to follow.')
|
|
336
356
|
const suffix = args[0]
|
|
337
|
-
const
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
357
|
+
const choices = assets.filter(asset => asset.file.endsWith(suffix))
|
|
358
|
+
const flag = choice => `<img width=12 src=${choices[choice].host+'/favicon.png'}>`
|
|
359
|
+
if(!choices) return trouble(elem,`FILE expects to find an asset with "${suffix}" suffix.`)
|
|
360
|
+
elem.innerHTML = command +
|
|
361
|
+
`<br><div class=choices style="border:1px solid black; background-color:#f8f8f8; padding:8px;" >${choices
|
|
362
|
+
.map((choice,i) =>
|
|
363
|
+
`<span data-choice=${i} style="cursor:pointer;">
|
|
364
|
+
${flag(i)}
|
|
365
|
+
${choice.file} ▶
|
|
366
|
+
</span>`)
|
|
367
|
+
.join("<br>\n")
|
|
368
|
+
}</div>`
|
|
369
|
+
elem.querySelector('.choices').addEventListener('click',event => {
|
|
370
|
+
if (!('choice' in event.target.dataset)) return
|
|
371
|
+
const url = choices[event.target.dataset.choice].url
|
|
372
|
+
// console.log(event.target)
|
|
373
|
+
// console.log(event.target.dataset.file)
|
|
374
|
+
// const url = 'http://ward.dojo.fed.wiki/assets/pages/testing-file-mech/KWIC-list-axe-files.tsv'
|
|
375
|
+
fetch(url)
|
|
376
|
+
.then(res => res.text())
|
|
377
|
+
.then(text => {
|
|
378
|
+
elem.innerHTML = command + ` ⇒ ${text.length} bytes`
|
|
379
|
+
state.tsv = text
|
|
380
|
+
console.log({text})
|
|
381
|
+
run(body,state)
|
|
382
|
+
})
|
|
383
|
+
})
|
|
345
384
|
}
|
|
346
385
|
|
|
347
386
|
function kwic_emit ({elem,command,args,body,state}) {
|
|
348
387
|
const template = body && body[0]?.command
|
|
349
388
|
if(template && !template.match(/\$[KW]/)) return trouble(elem,`KWIK expects $K or $W in link prototype.`)
|
|
350
389
|
if(!('tsv' in state)) return trouble(elem,`KWIC expects a .tsv file, like from ASSETS .tsv.`)
|
|
390
|
+
inspect(elem,'tsv',state)
|
|
351
391
|
const prefix = args[0] || 1
|
|
352
392
|
const lines = state.tsv.trim().split(/\n/)
|
|
353
393
|
|