wiki-plugin-mech 0.1.29 → 0.1.31
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/.editorconfig +10 -0
- package/LICENSE +21 -0
- package/ReadMe.md +5 -2
- package/client/mech.js +20 -1286
- package/client/mech.js.map +7 -0
- package/gruntfile.js +27 -0
- package/package.json +22 -11
- package/server/server.js +136 -144
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../src/client/library.js", "../node_modules/universal-ticker/index.js", "../src/client/blocks.js", "../src/client/interpreter.js", "../src/client/mech.js"],
|
|
4
|
+
"sourcesContent": ["import { uniq, delay, asSlug } from './mech.js'\n\n// L I B R A R Y\n\n// adapted from wiki-plugin-frame/client/frame.js\nexport function requestSourceData(item, topic) {\n let sources = []\n for (let div of document.querySelectorAll(`.item`)) {\n if (div.classList.contains(`${topic}-source`)) {\n sources.unshift(div)\n }\n if (div === item) {\n break\n }\n }\n\n return sources.map(div => {\n let getData = div[`${topic}Data`]\n let result = getData ? getData() : null\n return { div, result }\n })\n}\n\n// adapted from super-collaborator/dotify.js\nexport function dotify(graph) {\n const tip = props =>\n Object.entries(props)\n .filter(e => e[1])\n .map(e => `${e[0]}: ${e[1]}`)\n .join('\\\\n')\n const nodes = graph.nodes.map((node, id) => {\n const label = node.type ? `${node.type}\\\\n${node.props.name}` : node.props.name\n return `${id} [label=\"${label}\" ${node.props.url || node.props.tick ? `URL=\"${node.props.url || '#'}\" target=\"_blank\"` : ''} tooltip=\"${tip(node.props)}\"]`\n })\n const edges = graph.rels.map(rel => {\n return `${rel.from}->${rel.to} [label=\"${rel.type}\" labeltooltip=\"${tip(rel.props)}\"]`\n })\n return ['digraph {', 'rankdir=LR', 'node [shape=box style=filled fillcolor=palegreen]', ...nodes, ...edges, '}'].join(\n '\\n',\n )\n}\n\n// inspired by aspects-of-recent-changes/roster-graphs.html\nexport function walks(count, way = 'steps', neighborhood, scope = {}) {\n const find = (slug, site) => neighborhood.find(info => info.slug == slug && (!site || info.domain == site))\n const finds = slugs => (slugs ? slugs.map(slug => find(slug)) : null)\n const prob = n => Math.floor(n * Math.abs(Math.random() - Math.random()))\n const rand = a => a[prob(a.length)]\n const good = info => info.links && Object.keys(info.links).length < 10\n const back = slug => neighborhood.filter(info => good(info) && slug in info.links)\n // const uniq = (value, index, self) => self.indexOf(value) === index\n const dedup = (value, index, self) => self.findIndex(info => info.slug == value.slug) === index\n const newr = infos =>\n infos\n .toSorted((a, b) => b.date - a.date)\n .filter(dedup)\n .slice(0, 3)\n const domains = neighborhood.map(info => info.domain).filter(uniq)\n\n function blanket(info) {\n // hub[0] => slug\n // find(slug) => info\n // node(info) => nid\n // back(slug) => infos\n // newr(infos) => infos\n\n const graph = new Graph()\n const node = info => {\n return graph.addUniqNode('', {\n name: info.title.replaceAll(/ /g, '\\n'),\n title: info.title,\n site: info.domain,\n })\n }\n const up = info => finds(info?.patterns?.up) ?? newr(back(info.slug))\n const down = info => info?.patterns?.down ?? Object.keys(info.links || {})\n\n // hub\n const nid = node(info)\n\n // parents of hub\n for (const parent of up(info)) {\n graph.addRel('', node(parent), nid)\n }\n\n // children of hub\n for (const link of down(info)) {\n const child = find(link)\n if (child) {\n const cid = node(child)\n graph.addRel('', nid, cid)\n\n // parents of children of hub\n for (const parent of up(child)) {\n graph.addRel('', node(parent), cid)\n }\n }\n }\n return graph\n }\n\n switch (way) {\n case 'steps':\n return steps(count)\n case 'days':\n return periods(way, 1, count)\n case 'weeks':\n return periods(way, 7, count)\n case 'months':\n return periods(way, 30, count)\n case 'hubs':\n return hubs(count)\n case 'references':\n return references()\n case 'lineup':\n return lineup()\n }\n\n function steps(count = 5) {\n return domains.map(domain => {\n const name = domain.split('.').slice(0, 3).join('.')\n const done = new Set()\n const graph = new Graph()\n let nid = 0\n const here = neighborhood.filter(info => info.domain == domain && 'links' in info)\n if (!here.length) return { name, graph: null }\n const node = info => {\n nid = graph.addNode('', {\n name: info.title.replaceAll(/ /g, '\\n'),\n title: info.title,\n site: domain,\n links: Object.keys(info.links || {}).filter(slug => find(slug)),\n })\n return nid\n }\n const rel = (here, there) => graph.addRel('', here, there)\n const links = nid => graph.nodes[nid].props.links.filter(slug => !done.has(slug))\n const start = rand(here)\n // const start = find('welcome-visitors')\n done.add(start.slug)\n node(start)\n for (let n = 5; n > 0; n--) {\n try {\n const slugs = links(nid)\n const slug = rand(slugs)\n done.add(slug)\n const info = find(slug)\n rel(nid, node(info))\n } catch (e) {}\n }\n return { name, graph }\n })\n }\n\n function periods(way, days, count = 12) {\n const interval = days * 24 * 60 * 60 * 1000\n const iota = [...Array(Number(count)).keys()]\n const dates = iota.map(n => Date.now() - n * interval)\n const aspects = []\n for (const stop of dates) {\n const start = stop - interval\n const name = `${way.replace(/s$/, '')} ${new Date(start).toLocaleDateString()}`\n const here = neighborhood\n .filter(info => info.date < stop && info.date >= start)\n .filter(info => !(info.links && Object.keys(info.links).length > 5))\n if (here.length) {\n const domains = here.reduce((set, info) => {\n set.add(info.domain)\n return set\n }, new Set())\n for (const domain of domains) {\n const graph = new Graph()\n const node = info => {\n return graph.addUniqNode('', {\n name: info.title.replaceAll(/ /g, '\\n'),\n title: info.title,\n site: info.domain,\n date: info.date,\n })\n }\n const author = domain.split(/\\.|\\:/)[0]\n for (const info of here.filter(info => info.domain == domain)) {\n const nid = node(info)\n for (const link in info.links || {}) {\n const linked = find(link)\n if (linked) graph.addRel('', nid, node(linked))\n }\n }\n aspects.push({ name: `${name} ${author}`, graph })\n }\n }\n }\n return aspects\n }\n\n function hubs(count = 12) {\n const aspects = []\n const ignored = new Set()\n const hits = {}\n for (const info of neighborhood)\n if (info.links)\n if (Object.keys(info.links).length <= 15) {\n for (const link in info.links) if (find(link)) hits[link] = (hits[link] || 0) + 1\n } else {\n ignored.add(info.slug)\n }\n if (ignored.size > 0) console.log('hub links ignored for large pages:', [...ignored])\n const hubs = Object.entries(hits)\n .sort((a, b) => b[1] - a[1])\n .slice(0, count)\n console.log({ hits, hubs })\n\n for (const hub of hubs) {\n const name = `hub ${hub[1]} ${hub[0]}`\n const graph = blanket(find(hub[0]))\n aspects.push({ name, graph })\n }\n return aspects\n }\n\n function lineup() {\n const aspects = []\n const lineup = scope.lineup()\n console.log({ lineup })\n for (const div of lineup) {\n const pageObject = wiki.lineup.atKey(div.dataset.key)\n const slug = pageObject.getSlug()\n const site = pageObject.getRemoteSite(location.host)\n const info = find(slug, site)\n console.log({ div, pageObject, site, slug, info })\n aspects.push({ name: pageObject.getTitle(), graph: blanket(info) })\n }\n return aspects\n }\n\n function references() {\n const aspects = []\n const items = scope.references()\n console.log({ items })\n for (const item of items) {\n const { title, site, slug } = item\n const info = find(slug, site)\n console.log({ site, slug, info })\n aspects.push({ name: title, graph: blanket(info) })\n }\n console.log({ aspects })\n return aspects\n }\n}\n\n// adapted from testing-file-mech/testing-kwic.html\nexport function kwic(prefix, lines, stop) {\n const quotes = lines\n .filter(line => line.match(/\\t/))\n .map(quote)\n .flat()\n .sort((a, b) => (a.word < b.word ? -1 : 1))\n let current = 'zzz'.slice(0, prefix)\n const groups = []\n for (const quote of quotes) {\n const group = quote.word.toLowerCase().slice(0, prefix)\n if (group != current) {\n groups.push({ group, quotes: [] })\n current = group\n }\n groups[groups.length - 1].quotes.push(quote)\n }\n return groups\n\n function quote(line) {\n const [key, text] = line.split(/\\t/)\n const words = text\n .replaceAll(/'t\\b/g, 't')\n .replaceAll(/'s\\b/g, 's')\n .split(/[^a-zA-Z]+/)\n .filter(word => word.length > 3 && !stop.has(word.toLowerCase()))\n return words.map(word => ({ word, line, key }))\n }\n}\n\n// adapted from graph/src/graph.js\nexport class Graph {\n constructor(nodes = [], rels = []) {\n this.nodes = nodes\n this.rels = rels\n }\n\n addNode(type, props = {}) {\n const obj = { type, in: [], out: [], props }\n this.nodes.push(obj)\n return this.nodes.length - 1\n }\n\n addUniqNode(type, props = {}) {\n const nid = this.nodes.findIndex(node => node.type == type && node.props?.name == props?.name)\n return nid >= 0 ? nid : this.addNode(type, props)\n }\n\n addRel(type, from, to, props = {}) {\n const obj = { type, from, to, props }\n this.rels.push(obj)\n const rid = this.rels.length - 1\n this.nodes[from].out.push(rid)\n this.nodes[to].in.push(rid)\n return rid\n }\n\n stringify(...args) {\n const obj = { nodes: this.nodes, rels: this.rels }\n return JSON.stringify(obj, ...args)\n }\n}\n\n// adapted from wiki-client/lib/revision.coffee\n\n// This module interprets journal actions in order to update\n// a story or even regenerate a complete story from some or\n// all of a journal.\n\nexport function apply(page, action) {\n const order = () => {\n return (page.story || []).map(item => item?.id)\n }\n\n const add = (after, item) => {\n const index = order().indexOf(after) + 1\n page.story.splice(index, 0, item)\n }\n\n const remove = () => {\n const index = order().indexOf(action.id)\n if (index !== -1) {\n page.story.splice(index, 1)\n }\n }\n\n page.story = page.story || []\n\n switch (action.type) {\n case 'create':\n if (action.item) {\n if (action.item.title != null) {\n page.title = action.item.title\n }\n if (action.item.story != null) {\n page.story = action.item.story.slice()\n }\n }\n break\n case 'add':\n add(action.after, action.item)\n break\n case 'edit':\n const index = order().indexOf(action.id)\n if (index !== -1) {\n page.story.splice(index, 1, action.item)\n } else {\n page.story.push(action.item)\n }\n break\n case 'move':\n // construct relative addresses from absolute order\n const moveIndex = action.order.indexOf(action.id)\n const after = action.order[moveIndex - 1]\n const item = page.story[order().indexOf(action.id)]\n remove()\n add(after, item)\n break\n case 'remove':\n remove()\n break\n }\n\n page.journal = page.journal || []\n if (action.fork) {\n // implicit fork\n page.journal.push({ type: 'fork', site: action.fork, date: action.date - 1 })\n }\n page.journal.push(action)\n}\n\n// adapted from Solo client\n\nexport function soloListener(event) {\n if (!event.data) return\n const { data } = event\n if (data?.action == 'publishSourceData' && data?.name == 'aspect') {\n if (wiki.debug) console.log('soloListener - source update', { event, data })\n return\n }\n\n // only continue if event is from a solo popup.\n // events from a popup window will have an opener\n // ensure that the popup window is one of ours\n\n if (!event.source.opener || event.source.location.pathname !== '/plugins/solo/dialog/') {\n if (wiki.debug) {\n console.log('soloListener - not for us', { event })\n }\n return\n }\n if (wiki.debug) {\n console.log('soloListener - ours', { event })\n }\n\n const { action, keepLineup = false, pageKey = null, title = null, context = null, page = null } = data\n\n let $page = null\n if (pageKey != null) {\n $page = keepLineup ? null : $('.page').filter((i, el) => $(el).data('key') == pageKey)\n }\n\n switch (action) {\n case 'doInternalLink':\n wiki.pageHandler.context = context\n wiki.doInternalLink(title, $page)\n break\n case 'showResult':\n const options = keepLineup ? {} : { $page }\n wiki.showResult(wiki.newPage(page), options)\n break\n default:\n console.error({ where: 'soloListener', message: 'unknown action', data })\n }\n}\n\nexport function create(revIndex, data) {\n revIndex = +revIndex\n const revJournal = data.journal.slice(0, revIndex + 1)\n const revPage = { title: data.title, story: [] }\n for (const action of revJournal) {\n apply(revPage, action || {})\n }\n return revPage\n}\n", "let max = Number.MAX_SAFE_INTEGER\n\nexport default function makeTicker (fn, minMS=1000, remainingTicks=max) {\n let hardstop = false\n let lastTickTime = Date.now()\n let api = {\n stop,\n remainingTicks,\n minMS,\n ticksSoFar: 0,\n timeSinceLastTick: 0\n }\n let r = run()\n r.api = api\n return r\n\n function stop () {\n hardstop = true\n }\n\n async function run () {\n if (hardstop || api.remainingTicks < 1) return\n api.remainingTicks -= 1\n api.ticksSoFar += 1\n api.timeSinceLastTick = Date.now() - lastTickTime\n lastTickTime = Date.now()\n\n const minTickBuffer = new Promise((resolve) => setTimeout(resolve, api.minMS))\n\n await fn(api)\n\n await minTickBuffer\n\n return run()\n }\n}", "import { soloListener, apply, requestSourceData, dotify, walks, kwic } from './library.js'\nimport { uniq, delay, asSlug } from './mech.js'\nimport ticker from 'universal-ticker'\n\nexport const api = {\n trouble,\n inspect,\n response,\n button,\n element,\n jfetch,\n status,\n sourceData,\n showResult,\n neighborhood,\n publishSourceData,\n newSVG,\n SVGline,\n ticker,\n}\n\nexport function trouble(elem, message) {\n if (elem.innerText.match(/\u2716\uFE0E/)) return\n elem.innerHTML += `<button style=\"border-width:0;color:red;\">\u2716\uFE0E</button>`\n elem.querySelector('button').addEventListener('click', event => {\n elem.outerHTML += `<span style=\"width:80%;color:gray;\">${message}</span>`\n })\n}\n\nexport function inspect(elem, key, state) {\n const tap = elem.previousElementSibling\n if (state.debug) {\n const value = state[key]\n tap.innerHTML = `${key} \u21D2 `\n tap.addEventListener('click', event => {\n console.log({ key, value })\n let look = tap.previousElementSibling\n if (!look?.classList.contains('look')) {\n const div = document.createElement('div')\n div.classList.add('look')\n tap.insertAdjacentElement('beforebegin', div)\n look = tap.previousElementSibling\n }\n let text = JSON.stringify(value, null, 1)\n if (text.length > 300) text = text.substring(0, 400) + '...'\n const css = `border:1px solid black; background-color:#f8f8f8; padding:8px; color:gray; word-break: break-all;`\n look.innerHTML = `<div style=\"${css}\">${text}</div>`\n })\n } else {\n tap.innerHTML = ''\n }\n}\n\nexport function response(elem, html) {\n elem.innerHTML += html\n}\n\nexport function button(elem, label, handler) {\n if (!elem.innerHTML.match(/button/)) {\n response(elem, `<button style=\"border-width:0;\">${label}</button>`)\n elem.querySelector('button').addEventListener('click', handler)\n }\n}\n\nexport function element(key) {\n return document.getElementById(key)\n}\n\nexport async function jfetch(url) {\n return fetch(url).then(res => (res.ok ? res.json() : null))\n}\n\nexport function status(elem, command, text) {\n elem.innerHTML = command + text\n}\n\nexport function sourceData(elem, topic) {\n const item = elem.closest('.item')\n const sources = requestSourceData(item, topic).map(({ div, result }) => ({\n classList: [...div.classList],\n id: div.dataset.id,\n result,\n }))\n if (sources.length) return sources\n trouble(elem, `Expected source for \"${topic}\" in the lineup.`)\n return null\n}\n\nexport function publishSourceData(elem, topic, data) {\n const item = elem.closest('.item')\n item.classList.add(`${topic}-source`)\n item[`${topic}Data`] = () => data\n}\n\nexport function showResult(elem, page) {\n const options = { $page: $(elem.closest('.page')) }\n wiki.showResult(wiki.newPage(page), options)\n}\n\nexport function neighborhood(want) {\n return Object.entries(wiki.neighborhoodObject.sites)\n .filter(([domain, site]) => !site.sitemapRequestInflight && (!want || domain.includes(want)))\n .map(([domain, site]) => (site.sitemap || []).map(info => Object.assign({ domain }, info)))\n}\n\nexport function newSVG(elem) {\n const div = document.createElement('div')\n elem.closest('.item').firstElementChild.prepend(div)\n div.outerHTML = `\n <div style=\"border:1px solid black; background-color:#f8f8f8; margin-bottom:16px;\">\n <svg viewBox=\"0 0 400 400\" width=100% height=400>\n <circle id=dot r=5 cx=200 cy=200 stroke=\"#ccc\"></circle>\n </svg>\n </div>`\n const svg = elem.closest('.item').getElementsByTagName('svg')[0]\n return svg\n}\n\nexport function SVGline(svg, [x1, y1], [x2, y2]) {\n const line = document.createElementNS('http://www.w3.org/2000/svg', 'line')\n const set = (k, v) => line.setAttribute(k, Math.round(v))\n set('x1', x1)\n set('y1', 400 - y1)\n set('x2', x2)\n set('y2', 400 - y2)\n line.style.stroke = 'black'\n line.style.strokeWidth = '2px'\n svg.appendChild(line)\n const dot = svg.getElementById('dot')\n dot.setAttribute('cx', Math.round(x2))\n dot.setAttribute('cy', Math.round(400 - y2))\n}\n\n// export function ticker(handler) {\n// const interval = setInterval(handler, 1000)\n// const stop = () => clearInterval(interval)\n// return { stop }\n// }\n\nexport async function run(nest, state) {\n const scope = nest.slice()\n while (scope.length) {\n const code = scope.shift()\n if ('command' in code) {\n const command = code.command\n const elem = state.api ? state.api.element(code.key) : document.getElementById(code.key)\n const [op, ...args] = code.command.split(/ +/)\n const next = scope[0]\n const body = next && 'command' in next ? null : scope.shift()\n const stuff = { command, op, args, body, elem, state }\n if (state.debug) console.log(stuff)\n if (blocks[op]) await blocks[op].emit.apply(null, [stuff])\n else if (op.match(/^[A-Z]+$/)) state.api.trouble(elem, `${op} doesn't name a block we know.`)\n else if (code.command.match(/\\S/)) state.api.trouble(elem, `Expected line to begin with all-caps keyword.`)\n }\n }\n}\n\n// B L O C K S\n\nfunction click_emit({ elem, body, state }) {\n if (!body?.length) return state.api.trouble(elem, `CLICK expects indented blocks to follow.`)\n state.api.button(elem, '\u25B6', event => {\n state.debug = event.shiftKey\n run(body, state)\n })\n}\n\nfunction hello_emit({ elem, args, state }) {\n const world = args[0] == 'world' ? ' \uD83C\uDF0E' : ' \uD83D\uDE00'\n for (const key of Object.keys(state)) state.api.inspect(elem, key, state)\n state.api.response(elem, world)\n}\n\nasync function from_emit({ elem, args, body, state }) {\n if (!body?.length) return state.api.trouble(elem, `FROM expects indented blocks to follow.`)\n const url = args[0]\n state.api.response(elem, ' \u23F3')\n state.page = await state.api.jfetch(`//${url}.json`)\n state.api.response(elem, ' \u231B')\n run(body, state)\n}\n\nfunction sensor_emit({ elem, command, args, body, state }) {\n state.api.status(elem, command, '')\n if (!('page' in state)) return state.api.trouble(elem, `Expect \"page\" as with FROM.`)\n state.api.inspect(elem, 'page', state)\n const datalog = state.page.story.find(item => item.type == 'datalog')\n if (!datalog) return state.api.trouble(elem, `Expect Datalog plugin in the page.`)\n const device = args[0]\n if (!device) return state.api.trouble(elem, `SENSOR needs a sensor name.`)\n const sensor = datalog.text\n .split(/\\n/)\n .map(line => line.split(/ +/))\n .filter(fields => fields[0] == 'SENSOR')\n .find(fields => fields[1] == device)\n if (!sensor) return state.api.trouble(elem, `Expect to find \"${device}\" in Datalog.`)\n const url = sensor[2]\n\n const f = c => (9 / 5) * (c / 16) + 32\n const avg = a => a.reduce((s, e) => s + e, 0) / a.length\n state.api.status(elem, command, ' \u23F3')\n state.api.jfetch(url).then(data => {\n if (state.debug) console.log({ sensor, data })\n state.api.status(elem, command, ' \u231B')\n const value = f(avg(Object.values(data)))\n state.temperature = `${value.toFixed(2)}\u00B0F`\n run(body, state)\n })\n}\n\nfunction report_emit({ elem, command, state }) {\n const value = state?.temperature\n if (!value) return state.api.trouble(elem, `Expect data, as from SENSOR.`)\n state.api.inspect(elem, 'temperature', state)\n state.api.response(elem, `<br><font face=Arial size=32>${value}</font>`)\n}\n\nfunction source_emit({ elem, command, args, body, state }) {\n if (!(args && args.length)) return state.api.trouble(elem, `Expected Source topic, like \"markers\" for Map markers.`)\n const topic = args[0]\n const sources = state.api.sourceData(elem, topic)\n if (!sources) return\n if (state.debug) console.log({ topic, sources })\n const count = type => {\n const count = sources.filter(source => source.classList.includes(type)).length\n return count ? `${count} ${type}` : null\n }\n const counts = [count('map'), count('image'), count('frame'), count('assets')].filter(count => count).join(', ')\n state.api.status(elem, command, ' \u21D2 ' + counts)\n state[topic] = sources.map(({ id, result }) => ({ id, result }))\n if (body) run(body, state)\n}\n\nfunction preview_emit({ elem, command, args, state }) {\n const round = digits => (+digits).toFixed(7)\n const story = []\n const types = args\n for (const type of types) {\n switch (type) {\n case 'map':\n if (!('marker' in state))\n return state.api.trouble(elem, `\"map\" preview expects \"marker\" state, like from \"SOURCE marker\".`)\n state.api.inspect(elem, 'marker', state)\n const text = state.marker\n .map(marker => [marker.result])\n .flat(2)\n .map(latlon => `${round(latlon.lat)}, ${round(latlon.lon)} ${latlon.label || ''}`)\n .filter(uniq)\n .join('\\n')\n story.push({ type: 'map', text })\n break\n case 'graph':\n if (!('aspect' in state))\n return state.api.trouble(elem, `\"graph\" preview expects \"aspect\" state, like from \"SOURCE aspect\".`)\n state.api.inspect(elem, 'aspect', state)\n for (const { div, result } of state.aspect) {\n for (const { name, graph } of result) {\n if (state.debug) console.log({ div, result, name, graph })\n story.push({ type: 'paragraph', text: name })\n story.push({ type: 'graphviz', text: dotify(graph) })\n }\n story.push({ type: 'pagefold', text: '.' })\n }\n break\n case 'items':\n if (!('items' in state))\n return state.api.trouble(elem, `\"graph\" preview expects \"items\" state, like from \"KWIC\".`)\n state.api.inspect(elem, 'items', state)\n story.push(...state.items)\n break\n case 'page':\n if (!('page' in state)) return state.api.trouble(elem, `\"page\" preview expects \"page\" state, like from \"FROM\".`)\n state.api.inspect(elem, 'page', state)\n story.push(...state.page.story)\n break\n case 'synopsis':\n const text2 = `This page created with Mech command: \"${command}\". See [[${state.context.title}]].`\n story.push({ type: 'paragraph', text: text2, id: state.context.itemId })\n break\n default:\n return state.api.trouble(elem, `\"${type}\" doesn't name an item we can preview`)\n }\n }\n const title = 'Mech Preview' + (state.tick ? ` ${state.tick}` : '')\n const page = { title, story }\n for (const item of page.story) item.id ||= (Math.random() * 10 ** 20).toFixed(0)\n const item = JSON.parse(JSON.stringify(page))\n const date = Date.now()\n page.journal = [{ type: 'create', date, item }]\n state.api.showResult(elem, page)\n}\n\nasync function neighbors_emit({ elem, command, args, body, state }) {\n const belem = probe => state.api.element(probe.key)\n const want = args[0]\n const have = state.api.neighborhood(want)\n for (const probe of body || []) {\n if (!probe.command.endsWith(' Survey')) {\n state.api.trouble(belem(probe), `NEIGHBORS expects a Site Survey title, like Pattern Link Survey`)\n continue\n }\n const todos = have.filter(sitemap => sitemap.find(info => info.title == probe.command))\n state.api.status(belem(probe), probe.command, `\u21D2 ${todos.length} sites`)\n for (const todo of todos) {\n const url = `//${todo[0].domain}/${asSlug(probe.command)}.json`\n const page = await state.api.jfetch(url)\n if (!page) continue\n const survey = page.story.find(item => item.type == 'frame')?.survey\n if (!survey) continue\n for (const info of todo) {\n const extra = Object.assign(\n {},\n survey.find(inf => inf.slug == info.slug),\n info,\n )\n Object.assign(info, extra)\n }\n console.log({ url, page, survey, todo })\n }\n }\n state.neighborhood = have.flat().sort((a, b) => b.date - a.date)\n state.api.status(elem, command, `\u21D2 ${state.neighborhood.length} pages, ${have.length} sites`)\n}\n\nfunction walk_emit({ elem, command, args, state }) {\n if (!('neighborhood' in state))\n return state.api.trouble(elem, `WALK expects state.neighborhood, like from NEIGHBORS.`)\n state.api.inspect(elem, 'neighborhood', state)\n const [, count, way] = command.match(/\\b(\\d+)? *(steps|days|weeks|months|hubs|lineup|references)\\b/) || []\n if (!way && command != 'WALK') return tate.api.trouble(elem, `WALK can't understand rest of this block.`)\n const scope = {\n lineup() {\n const items = [...document.querySelectorAll('.page')]\n const index = items.indexOf(elem.closest('.page'))\n return items.slice(0, index)\n },\n references() {\n const div = elem.closest('.page')\n const pageObject = wiki.lineup.atKey(div.dataset.key)\n const story = pageObject.getRawPage().story\n console.log({ div, pageObject, story })\n return story.filter(item => item.type == 'reference')\n },\n }\n const steps = walks(count, way, state.neighborhood, scope)\n const aspects = steps.filter(({ graph }) => graph)\n if (state.debug) console.log({ steps })\n const nodes = aspects.map(({ graph }) => graph.nodes).flat()\n state.api.status(elem, command, ` \u21D2 ${aspects.length} aspects, ${nodes.length} nodes`)\n if (steps.find(({ graph }) => !graph)) state.api.trouble(elem, `WALK skipped sites with no links in sitemaps`)\n if (aspects.length) {\n state.aspect = state.aspect || []\n const obj = state.aspect.find(obj => obj.id == elem.id)\n if (obj) obj.result = aspects\n else state.aspect.push({ id: elem.id, result: aspects, source: command })\n // const item = elem.closest('.item')\n // item.classList.add('aspect-source')\n // item.aspectData = () => state.aspect.map(obj => obj.result).flat()\n state.api.publishSourceData(elem, 'aspect', state.aspect.map(obj => obj.result).flat())\n if (state.debug) console.log({ command, state: state.aspect, item: item.aspectData() })\n }\n}\n\nfunction tick_emit({ elem, command, args, body, state }) {\n console.log({ command, args, body, state })\n if (!body?.length) return state.api.trouble(elem, `TICK expects indented blocks to follow.`)\n const count = args[0] || '1'\n if (!count.match(/^[1-9][0-9]?$/)) return state.api.trouble(elem, `TICK expects a count from 1 to 99`)\n let clock, outertick\n if (state.tick != null) {\n outertick = state.tick\n start({ shiftKey: state.debug })\n return clock\n } else ready()\n\n function ready() {\n state.api.button(elem, '\u25B6', start)\n }\n function status(ticks) {\n state.api.status(elem, command, ` \u21D2 ${ticks} remaining`)\n }\n\n function start(event) {\n state.debug = event.shiftKey\n state.tick = +count\n status(state.tick)\n clock = state.api.ticker(async () => {\n if (state.debug) console.log({ tick: state.tick, count })\n if ('tick' in state && --state.tick >= 0) {\n status(state.tick)\n await run(body, state)\n } else {\n clock = clock.api.stop()\n state.tick = outertick\n state.api.status(elem, command, '')\n ready()\n }\n })\n }\n}\n\nfunction until_emit({ elem, command, args, body, state }) {\n if (!args.length) return trouble(elem, `UNTIL expects an argument, a word to stop running.`)\n if (!state.tick) return trouble(elem, `UNTIL expects to indented below an iterator, like TICKS.`)\n if (!state.aspect) return trouble(elem, `UNTIL expects \"aspect\", like from WALK.`)\n inspect(elem, 'aspect', state)\n elem.innerHTML = command + ` \u21D2 ${state.tick}`\n const word = args[0]\n for (const { div, result } of state.aspect)\n for (const { name, graph } of result)\n for (const node of graph.nodes)\n if (node.type.includes(word) || node.props.name.includes(word)) {\n if (state.debug) console.log({ div, result, name, graph, node })\n delete state.tick\n elem.innerHTML += ' done'\n if (body) run(body, state)\n return\n }\n}\n\nfunction forward_emit({ elem, command, args, state }) {\n if (args.length < 1)\n return state.api.trouble(elem, `FORWARD expects an argument, the number of steps to move a \"turtle\".`)\n state.turtle ??= { svg: state.api.newSVG(elem), position: [200, 200], direction: 0 }\n const steps = args[0]\n const theta = (state.turtle.direction * 2 * Math.PI) / 360\n const [x1, y1] = state.turtle.position\n state.turtle.position = [x1 + steps * Math.sin(theta), y1 + steps * Math.cos(theta)]\n state.api.SVGline(state.turtle.svg, [x1, y1], state.turtle.position)\n state.api.status(elem, command, ` \u21D2 ${state.turtle.position.map(n => (n - 200).toFixed(1)).join(', ')}`)\n}\n\nfunction turn_emit({ elem, command, args, state }) {\n if (args.length < 1)\n return state.api.trouble(elem, `TURN expects an argument, the number of degrees to turn a \"turtle\".`)\n state.turtle ??= { svg: state.api.newSVG(elem), position: [200, 200], direction: 0 }\n const degrees = +args[0]\n state.turtle.direction += degrees\n state.api.status(elem, command, ` \u21D2 ${state.turtle.direction}\u00B0`)\n}\n\nfunction file_emit({ elem, command, args, body, state }) {\n if (!('assets' in state)) return trouble(elem, `FILE expects state.assets, like from SOURCE assets.`)\n inspect(elem, 'assets', state)\n\n // [ { \"id\": \"b2d5831168b4706b\", \"result\":\n // { \"pages/testing-file-mech\":\n // { \"//ward.dojo.fed.wiki/assets\":\n // [ \"KWIC-list+axe-files.txt\", \"KWIC-list-axe-files.tsv\" ] } } } ]\n\n const origin = '//' + window.location.host\n const assets = state.assets\n .map(({ id, result }) =>\n Object.entries(result).map(([dir, paths]) =>\n Object.entries(paths).map(([path, files]) =>\n files.map(file => {\n const assets = path.startsWith('//') ? path : `${origin}${path}`\n const host = assets.replace(/\\/assets$/, '')\n const url = `${assets}/${dir}/${file}`\n return { id, dir, path, host, file, url }\n }),\n ),\n ),\n )\n .flat(3)\n if (state.debug) console.log({ assets })\n\n if (args.length < 1) return trouble(elem, `FILE expects an argument, the dot suffix for desired files.`)\n if (!body?.length) return trouble(elem, 'FILE expects indented blocks to follow.')\n const suffix = args[0]\n const choices = assets.filter(asset => asset.file.endsWith(suffix))\n const flag = choice => `<img width=12 src=${choices[choice].host + '/favicon.png'}>`\n if (!choices) return trouble(elem, `FILE expects to find an asset with \"${suffix}\" suffix.`)\n elem.innerHTML =\n command +\n `<br><div class=choices style=\"border:1px solid black; background-color:#f8f8f8; padding:8px;\" >${choices\n .map(\n (choice, i) =>\n `<span data-choice=${i} style=\"cursor:pointer;\">\n ${flag(i)}\n ${choice.file} \u25B6\n </span>`,\n )\n .join('<br>\\n')}</div>`\n elem.querySelector('.choices').addEventListener('click', event => {\n if (!('choice' in event.target.dataset)) return\n const url = choices[event.target.dataset.choice].url\n // console.log(event.target)\n // console.log(event.target.dataset.file)\n // const url = 'http://ward.dojo.fed.wiki/assets/pages/testing-file-mech/KWIC-list-axe-files.tsv'\n fetch(url)\n .then(res => res.text())\n .then(text => {\n elem.innerHTML = command + ` \u21D2 ${text.length} bytes`\n state.tsv = text\n console.log({ text })\n run(body, state)\n })\n })\n}\n\nfunction kwic_emit({ elem, command, args, body, state }) {\n const template = body && body[0]?.command\n if (template && !template.match(/\\$[KW]/)) return trouble(elem, `KWIK expects $K or $W in link prototype.`)\n if (!('tsv' in state)) return trouble(elem, `KWIC expects a .tsv file, like from ASSETS .tsv.`)\n inspect(elem, 'tsv', state)\n const prefix = args[0] || 1\n const lines = state.tsv.trim().split(/\\n/)\n\n const stop = new Set(['of', 'and', 'in', 'at'])\n const page = $(elem.closest('.page')).data('data')\n const start = page.story.findIndex(item => item.type == 'pagefold' && item.text == 'stop')\n if (start >= 0) {\n const finish = page.story.findIndex((item, i) => i > start && item.type == 'pagefold')\n page.story\n .slice(start + 1, finish)\n .map(item => item.text.trim().split(/\\s+/))\n .flat()\n .forEach(word => stop.add(word))\n }\n\n const groups = kwic(prefix, lines, stop)\n elem.innerHTML = command + ` \u21D2 ${lines.length} lines, ${groups.length} groups`\n const link = quote => {\n let line = quote.line\n if (template) {\n const substitute = template\n .replaceAll(/\\$K\\+/g, quote.key.replaceAll(/ /g, '+'))\n .replaceAll(/\\$K/g, quote.key)\n .replaceAll(/\\$W/g, quote.word)\n const target = template.match(/\\$W/) ? quote.word : quote.key\n line = line.replace(target, substitute)\n }\n return line\n }\n\n state.items = groups.map(group => {\n const text = `# ${group.group}\\n\\n${group.quotes.map(quote => link(quote)).join('\\n')}`\n return { type: 'markdown', text }\n })\n}\n\nfunction show_emit({ elem, command, args, state }) {\n elem.innerHTML = command\n let site, slug\n if (args.length < 1) {\n if (state.info) {\n inspect(elem, 'info', state)\n site = state.info.domain\n slug = state.info.slug\n elem.innerHTML = command + ` \u21D2 ${state.info.title}`\n } else {\n return trouble(elem, `SHOW expects a slug or site/slug to open in the lineup.`)\n }\n } else {\n const info = args[0]\n ;[site, slug] = info.includes('/') ? info.split(/\\//) : [null, info]\n }\n const lineup = [...document.querySelectorAll('.page')].map(e => e.id)\n if (lineup.includes(slug)) return trouble(elem, `SHOW expects a page not already in the lineup.`)\n const page = elem.closest('.page')\n wiki.doInternalLink(slug, page, site)\n}\n\nfunction random_emit({ elem, command, state }) {\n if (!state.neighborhood) return trouble(elem, `RANDOM expected a neighborhood, like from NEIGHBORS.`)\n inspect(elem, 'neighborhood', state)\n const infos = state.neighborhood\n const many = infos.length\n const one = Math.floor(Math.random() * many)\n elem.innerHTML = command + ` \u21D2 ${one} of ${many}`\n state.info = infos[one]\n}\n\nfunction sleep_emit({ elem, command, args, body, state }) {\n let count = args[0] || '1'\n if (!count.match(/^[1-9][0-9]?$/)) return trouble(elem, `SLEEP expects seconds from 1 to 99`)\n return new Promise(resolve => {\n if (body)\n run(body, state).then(result => {\n if (state.debug) console.log(command, 'children', result)\n })\n elem.innerHTML = command + ` \u21D2 ${count} remain`\n let clock = setInterval(() => {\n if (--count > 0) elem.innerHTML = command + ` \u21D2 ${count} remain`\n else {\n clearInterval(clock)\n elem.innerHTML = command + ` \u21D2 done`\n if (state.debug) console.log(command, 'done')\n resolve()\n }\n }, 1000)\n })\n}\n\nfunction together_emit({ elem, command, args, body, state }) {\n if (!body) return trouble(elem, `TOGETHER expects indented commands to run together.`)\n const children = body.map(child => run([child], state))\n return Promise.all(children)\n}\n\n// http://localhost:3000/plugin/mech/run/testing-mechs-synchronization/5e269010fc81aebe?args=WyJoZWxsbyIsIndvcmxkIl0\nasync function get_emit({ elem, command, args, body, state }) {\n if (!body) return trouble(elem, `GET expects indented commands to run on the server.`)\n let share = {}\n let where = state.context.site\n if (args.length) {\n for (const arg of args) {\n if (arg in state) {\n inspect(elem, arg, state)\n share[arg] = state[arg]\n } else if (arg.match(/\\./)) where = arg\n else {\n return trouble(elem, `GET expected \"${arg}\" to name state or site.`)\n }\n }\n }\n // const site = state.context.site\n const slug = state.context.slug\n const itemId = state.context.itemId\n const query = `mech=${btoa(JSON.stringify(body))}&state=${btoa(JSON.stringify(share))}`\n const url = `//${where}/plugin/mech/run/${slug}/${itemId}?${query}`\n elem.innerHTML = command + ` \u21D2 in progress`\n const start = Date.now()\n let result\n try {\n result = await fetch(url).then(res => (res.ok ? res.json() : res.status))\n if ('err' in result) return trouble(elem, `RUN received error \"${result.err}\"`)\n } catch (err) {\n return trouble(elem, `RUN failed with \"${err.message}\"`)\n }\n state.result = result\n for (const arg of result.mech.flat(9)) {\n const elem = document.getElementById(arg.key)\n if ('status' in arg) elem.innerHTML = arg.command + ` \u21D2 ${arg.status}`\n if ('trouble' in arg) trouble(elem, arg.trouble)\n }\n if ('debug' in result.state) delete result.state.debug\n Object.assign(state, result.state)\n const elapsed = ((Date.now() - start) / 1000).toFixed(3)\n elem.innerHTML = command + ` \u21D2 ${elapsed} seconds`\n}\n\nfunction delta_emit({ elem, command, args, body, state }) {\n const copy = obj => JSON.parse(JSON.stringify(obj))\n const size = obj => JSON.stringify(obj).length\n if (args.length < 1) return trouble(elem, `DELTA expects argument, \"have\" or \"apply\" on client.`)\n if (body) return trouble(elem, `DELTA doesn't expect indented input.`)\n switch (args[0]) {\n case 'have':\n const edits = state.context.page.journal.filter(item => item.type != 'fork')\n state.recent = edits[edits.length - 1].date\n elem.innerHTML = command + ` \u21D2 ${new Date(state.recent).toLocaleString()}`\n break\n case 'apply':\n if (!('actions' in state)) return trouble(elem, `DELTA apply expect \"actions\" as input.`)\n inspect(elem, 'actions', state)\n const page = copy(state.context.page)\n const before = size(page)\n for (const action of state.actions) apply(page, action)\n state.page = page\n const after = size(page)\n elem.innerHTML = command + ` \u21D2 \u2206 ${(((after - before) / before) * 100).toFixed(1)}%`\n break\n default:\n trouble(elem, `DELTA doesn't know \"${args[0]}\".`)\n }\n}\n\nfunction roster_emit({ elem, command, state }) {\n if (!state.neighborhood) return trouble(elem, `ROSTER expected a neighborhood, like from NEIGHBORS.`)\n inspect(elem, 'neighborhood', state)\n const infos = state.neighborhood\n const sites = infos.map(info => info.domain).filter(uniq)\n const any = array => array[Math.floor(Math.random() * array.length)]\n if (state.debug) console.log(infos)\n const items = [\n { type: 'roster', text: 'Mech\\n' + sites.join('\\n') },\n { type: 'activity', text: `ROSTER Mech\\nSINCE 30 days` },\n ]\n elem.innerHTML = command + ` \u21D2 ${sites.length} sites`\n state.items = items\n}\n\nfunction lineup_emit({ elem, command, state }) {\n const items = [...document.querySelectorAll('.page')].map(div => {\n const $page = $(div)\n const page = $page.data('data')\n const site = $page.data('site') || location.host\n const slug = $page.attr('id').split('_')[0]\n const title = page.title || 'Empty'\n const text = page.story[0]?.text || 'empty'\n return { type: 'reference', site, slug, title, text }\n })\n elem.innerHTML = command + ` \u21D2 ${items.length} pages`\n state.items = items\n}\n\nfunction listen_emit({ elem, command, args, state }) {\n if (args.length < 1) return trouble(elem, `LISTEN expects argument, an action.`)\n const topic = args[0]\n let recent = Date.now()\n let count = 0\n const handler = listen\n handler.action = 'publishSourceData'\n handler.id = elem.id\n window.addEventListener('message', listen)\n $('.main').on('thumb', (evt, thumb) => console.log('jquery', { evt, thumb }))\n elem.innerHTML = command + ` \u21D2 ready`\n\n // window.listeners = (action=null) => {\n // return getEventListeners(window).message\n // .map(t => t.listener)\n // .filter(f => f.name == 'listen')\n // .map(f => ({action:f.action,elem:document.getElementById(f.id),count:f.count}))\n // }\n\n function listen(event) {\n console.log({ event })\n const { data } = event\n if (data.action == 'publishSourceData' && (data.name == topic || data.topic == topic)) {\n count++\n handler.count = count\n if (state.debug) console.log({ count, data })\n if (count <= 100) {\n const now = Date.now()\n const elapsed = now - recent\n recent = now\n elem.innerHTML = command + ` \u21D2 ${count} events, ${elapsed} ms`\n } else {\n window.removeEventListener('message', listen)\n }\n }\n }\n}\n\nfunction message_emit({ elem, command, args, state }) {\n if (args.length < 1) return trouble(elem, `MESSAGE expects argument, an action.`)\n const topic = args[0]\n const message = {\n action: 'publishSourceData',\n topic,\n name: topic,\n }\n window.postMessage(message, '*')\n elem.innerHTML = command + ` \u21D2 sent`\n}\n\nasync function solo_emit({ elem, command, state }) {\n if (!('aspect' in state)) return trouble(elem, `\"SOLO\" expects \"aspect\" state, like from \"WALK\".`)\n inspect(elem, 'aspect', state)\n elem.innerHTML = command\n const todo = state.aspect.map(each => ({\n source: each.source || each.id,\n aspects: each.result,\n }))\n const aspects = todo.reduce((sum, each) => sum + each.aspects.length, 0)\n elem.innerHTML += ` \u21D2 ${todo.length} sources, ${aspects} aspects`\n\n // from Solo plugin, client/solo.js\n const pageKey = elem.closest('.page').dataset.key\n const doing = { type: 'batch', sources: todo, pageKey }\n console.log({ pageKey, doing })\n\n if (typeof window.soloListener == 'undefined' || window.soloListener == null) {\n console.log('**** Adding solo listener')\n window.soloListener = soloListener\n window.addEventListener('message', soloListener)\n }\n\n await delay(750)\n const popup = window.open('/plugins/solo/dialog/#', 'solo', 'popup,height=720,width=1280')\n if (popup.location.pathname != '/plugins/solo/dialog/') {\n console.log('launching new dialog')\n popup.addEventListener('load', event => {\n console.log('launched and loaded')\n popup.postMessage(doing, window.origin)\n })\n } else {\n console.log('reusing existing dialog')\n popup.postMessage(doing, window.origin)\n }\n}\n\n// C A T A L O G\n\nexport const blocks = {\n CLICK: { emit: click_emit },\n HELLO: { emit: hello_emit },\n FROM: { emit: from_emit },\n SENSOR: { emit: sensor_emit },\n REPORT: { emit: report_emit },\n SOURCE: { emit: source_emit },\n PREVIEW: { emit: preview_emit },\n NEIGHBORS: { emit: neighbors_emit },\n WALK: { emit: walk_emit },\n TICK: { emit: tick_emit },\n UNTIL: { emit: until_emit },\n FORWARD: { emit: forward_emit },\n TURN: { emit: turn_emit },\n FILE: { emit: file_emit },\n KWIC: { emit: kwic_emit },\n SHOW: { emit: show_emit },\n RANDOM: { emit: random_emit },\n SLEEP: { emit: sleep_emit },\n TOGETHER: { emit: together_emit },\n GET: { emit: get_emit },\n DELTA: { emit: delta_emit },\n ROSTER: { emit: roster_emit },\n LINEUP: { emit: lineup_emit },\n LISTEN: { emit: listen_emit },\n MESSAGE: { emit: message_emit },\n SOLO: { emit: solo_emit },\n}\n", "import { blocks, trouble, inspect, run } from './blocks.js'\n\nfunction expand(text) {\n return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')\n}\n\n// I N T E R P R E T E R\n\n// https://github.com/dobbs/wiki-plugin-graphviz/blob/main/client/graphviz.js#L86-L103\nexport function tree(lines, here, indent) {\n while (lines.length) {\n let m = lines[0].match(/( *)(.*)/)\n let spaces = m[1].length\n let command = m[2]\n if (spaces == indent) {\n here.push({ command })\n lines.shift()\n } else if (spaces > indent) {\n var more = []\n here.push(more)\n tree(lines, more, spaces)\n } else {\n return here\n }\n }\n return here\n}\n\nexport function format(nest) {\n const unique = Math.floor(Math.random() * 1000000)\n const block = (more, path) => {\n const html = []\n for (const part of more) {\n const key = `${unique}.${path.join('.')}`\n part.key = key\n if ('command' in part)\n html.push(\n `<font color=gray size=small></font><span style=\"display: block;\" id=${key}>${expand(part.command)}</span>`,\n )\n else html.push(`<div id=${key} style=\"padding-left:15px\">${block(part, [...path, 0])}</div>`)\n path[path.length - 1]++\n }\n return html.join('\\n')\n }\n return block(nest, [0])\n}\n", "import { tree, format } from './interpreter.js'\nimport { api, run } from './blocks.js'\n;('use strict')\nexport const uniq = (value, index, self) => self.indexOf(value) === index\nexport const delay = time => new Promise(res => setTimeout(res, time))\nexport const asSlug = title =>\n title\n .replace(/\\s/g, '-')\n .replace(/[^A-Za-z0-9-]/g, '')\n .toLowerCase()\n\nfunction expand(text) {\n return text.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>')\n}\n\n// P L U G I N\n\nfunction emit($item, item) {\n const lines = item.text.split(/\\n/)\n const nest = tree(lines, [], 0)\n const html = format(nest)\n const $page = $item.parents('.page')\n const pageKey = $page.data('key')\n const context = {\n item,\n itemId: item.id,\n pageKey,\n page: wiki.lineup.atKey(pageKey).getRawPage(),\n origin: window.origin,\n site: $page.data('site') || window.location.host,\n slug: $page.attr('id'),\n title: $page.data('data').title,\n }\n const state = { context, api }\n $item.append(`<div style=\"background-color:#eee;padding:15px;border-top:8px;\">${html}</div>`)\n run(nest, state)\n}\n\nfunction bind($item, item) {\n return $item.dblclick(() => {\n return wiki.textEditor($item, item)\n })\n}\n\nif (typeof window !== 'undefined' && window !== null) {\n window.plugins.mech = { emit, bind }\n}\n\nexport { expand, tree, format, run }\nexport { emit, bind }\n"],
|
|
5
|
+
"mappings": ";MAKO,SAASA,EAAkBC,EAAMC,EAAO,CAC7C,IAAIC,EAAU,CAAC,EACf,QAASC,KAAO,SAAS,iBAAiB,OAAO,EAI/C,GAHIA,EAAI,UAAU,SAAS,GAAGF,CAAK,SAAS,GAC1CC,EAAQ,QAAQC,CAAG,EAEjBA,IAA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AK,IAAMC,EACvDE,GAAQC,GAAQ,IAAI,QAAQC,GAAO,WAAWA,EAAKD,CAAI,CAAC,EACxDE,GAASC,GACpBA,EACG,QAAQ,MAAO,GAAG,EAClB,QAAQ,iBAAkB,EAAE,EAC5B,YAAY,EAEjB,SAASC,GAAOC,EAAM,CACpB,OAAOA,EAAK,QAAQ,KAAM,OAAO,EAAE,QAAQ,KAAM,MAAM,EAAE,QAAQ,KAAM,MAAM,CAC/E,CAIA,SAASC,GAAKC,EAAOC,EAAM,CACzB,IAAMC,EAAQD,EAAK,KAAK,MAAM,IAAI,EAC5BE,EAAOC,EAAKF,EAAO,CAAC,EAAG,CAAC,EACxBG,EAAOC,GAAOH,CAAI,EAClBI,EAAQP,EAAM,QAAQ,OAAO,EAC7BQ,EAAUD,EAAM,KAAK,KAAK,EAW1BE,EAAQ,CAAE,QAVA,CACd,KAAAR,EACA,OAAQA,EAAK,GACb,QAAAO,EACA,KAAM,KAAK,OAAO,MAAMA,CAAO,EAAE,WAAW,EAC5C,OAAQ,OAAO,OACf,KAAMD,EAAM,KAAK,MAAM,GAAK,OAAO,SAAS,KAC5C,KAAMA,EAAM,KAAK,IAAI,EACrB,MAAOA,EAAM,KAAK,MAAM,EAAE,KAC5B,EACyB,IAAAG,CAAI,EAC7BV,EAAM,OAAO,mEAAmEK,CAAI,QAAQ,EAC5FM,EAAIR,EAAMM,CAAK,CACjB,CAEA,SAASG,GAAKZ,EAAOC,EAAM,CACzB,OAAOD,EAAM,SAAS,IACb,KAAK,WAAWA,EAAOC,CAAI,CACnC,CACH,CAEI,OAAO,OAAW,KAAe,SAAW,OAC9C,OAAO,QAAQ,KAAO,CAAE,KAAAF,GAAM,KAAAa,EAAK",
|
|
6
|
+
"names": ["requestSourceData", "item", "topic", "sources", "div", "getData", "result", "dotify", "graph", "tip", "props", "e", "nodes", "node", "id", "label", "edges", "rel", "walks", "count", "way", "neighborhood", "scope", "find", "slug", "site", "info", "finds", "slugs", "prob", "n", "rand", "a", "good", "back", "dedup", "value", "index", "self", "newr", "infos", "b", "domains", "uniq", "blanket", "Graph", "up", "down", "nid", "parent", "link", "child", "cid", "steps", "periods", "hubs", "references", "lineup", "domain", "name", "done", "here", "there", "links", "start", "days", "interval", "dates", "aspects", "stop", "set", "author", "linked", "ignored", "hits", "hub", "pageObject", "items", "title", "kwic", "prefix", "lines", "quotes", "line", "quote", "current", "groups", "group", "key", "text", "word", "rels", "type", "obj", "from", "to", "rid", "args", "apply", "page", "action", "order", "add", "after", "remove", "moveIndex", "soloListener", "event", "data", "keepLineup", "pageKey", "context", "$page", "i", "el", "options", "max", "makeTicker", "fn", "minMS", "remainingTicks", "hardstop", "lastTickTime", "api", "stop", "run", "minTickBuffer", "resolve", "api", "trouble", "inspect", "response", "button", "element", "jfetch", "status", "sourceData", "showResult", "neighborhood", "publishSourceData", "newSVG", "SVGline", "makeTicker", "elem", "message", "event", "key", "state", "tap", "value", "look", "div", "text", "css", "html", "label", "handler", "url", "res", "command", "topic", "item", "sources", "requestSourceData", "result", "data", "page", "options", "want", "domain", "site", "info", "svg", "x1", "y1", "x2", "y2", "line", "set", "k", "v", "dot", "run", "nest", "scope", "code", "op", "args", "next", "body", "stuff", "blocks", "click_emit", "hello_emit", "world", "from_emit", "sensor_emit", "datalog", "device", "sensor", "fields", "f", "c", "avg", "a", "s", "e", "report_emit", "source_emit", "count", "type", "source", "counts", "id", "preview_emit", "round", "digits", "story", "types", "marker", "latlon", "uniq", "name", "graph", "dotify", "text2", "date", "neighbors_emit", "belem", "probe", "have", "todos", "sitemap", "todo", "asSlug", "survey", "extra", "inf", "b", "walk_emit", "way", "items", "index", "pageObject", "steps", "walks", "aspects", "nodes", "obj", "tick_emit", "clock", "outertick", "start", "ready", "ticks", "until_emit", "word", "node", "forward_emit", "theta", "n", "turn_emit", "degrees", "file_emit", "origin", "assets", "dir", "paths", "path", "files", "file", "host", "suffix", "choices", "asset", "flag", "choice", "i", "kwic_emit", "template", "prefix", "lines", "stop", "finish", "groups", "kwic", "link", "quote", "substitute", "target", "group", "show_emit", "slug", "random_emit", "infos", "many", "one", "sleep_emit", "resolve", "together_emit", "children", "child", "get_emit", "share", "where", "arg", "itemId", "query", "err", "elapsed", "delta_emit", "copy", "size", "edits", "before", "action", "apply", "after", "roster_emit", "sites", "any", "array", "lineup_emit", "$page", "title", "listen_emit", "recent", "listen", "evt", "thumb", "now", "message_emit", "solo_emit", "each", "sum", "pageKey", "doing", "soloListener", "delay", "popup", "expand", "text", "tree", "lines", "here", "indent", "m", "spaces", "command", "more", "format", "nest", "unique", "block", "path", "html", "part", "key", "uniq", "value", "index", "self", "delay", "time", "res", "asSlug", "title", "expand", "text", "emit", "$item", "item", "lines", "nest", "tree", "html", "format", "$page", "pageKey", "state", "api", "run", "bind"]
|
|
7
|
+
}
|
package/gruntfile.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
module.exports = function (grunt) {
|
|
2
|
+
grunt.loadNpmTasks('grunt-contrib-coffee')
|
|
3
|
+
grunt.loadNpmTasks('grunt-contrib-watch')
|
|
4
|
+
grunt.loadNpmTasks('grunt-mocha-test')
|
|
5
|
+
grunt.loadNpmTasks('grunt-git-authors')
|
|
6
|
+
|
|
7
|
+
grunt.initConfig({
|
|
8
|
+
mochaTest: {
|
|
9
|
+
test: {
|
|
10
|
+
options: {
|
|
11
|
+
reporter: 'spec',
|
|
12
|
+
},
|
|
13
|
+
src: ['test/**/*.js'],
|
|
14
|
+
},
|
|
15
|
+
},
|
|
16
|
+
|
|
17
|
+
watch: {
|
|
18
|
+
all: {
|
|
19
|
+
files: ['client/*.js', 'test/*.js', 'server/*.js'],
|
|
20
|
+
tasks: ['mochaTest'],
|
|
21
|
+
},
|
|
22
|
+
},
|
|
23
|
+
})
|
|
24
|
+
|
|
25
|
+
grunt.registerTask('build', ['mochaTest'])
|
|
26
|
+
grunt.registerTask('default', ['build'])
|
|
27
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wiki-plugin-mech",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.1.31",
|
|
4
5
|
"description": "Federated Wiki - Mechanism Scripting Plugin",
|
|
5
6
|
"keywords": [
|
|
6
7
|
"mech",
|
|
@@ -10,23 +11,28 @@
|
|
|
10
11
|
"federated wiki",
|
|
11
12
|
"plugin"
|
|
12
13
|
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "npm run clean; npm run check; npm run test; node --no-warnings scripts/build-client.js",
|
|
16
|
+
"clean": "rm client/mech.js client/mech.js.map",
|
|
17
|
+
"format": "prettier --write './**/*.js'",
|
|
18
|
+
"check": "prettier --check ./**/*.js",
|
|
19
|
+
"prettier:format": "prettier --write './**/*.js'",
|
|
20
|
+
"prettier:check": "prettier --check ./**/*.js",
|
|
21
|
+
"test": "c8 -r 'lcov' node --test"
|
|
22
|
+
},
|
|
13
23
|
"author": {
|
|
14
24
|
"name": "Ward Cunningham",
|
|
15
25
|
"email": "ward@c2.com",
|
|
16
26
|
"url": "https://c2.com/ward"
|
|
17
27
|
},
|
|
18
28
|
"contributors": [],
|
|
19
|
-
"scripts": {
|
|
20
|
-
"test": "mocha"
|
|
21
|
-
},
|
|
22
29
|
"devDependencies": {
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"mocha": "^5.2.0"
|
|
30
|
+
"@eslint/js": "^9.22.0",
|
|
31
|
+
"c8": "^10.1.3",
|
|
32
|
+
"esbuild": "^0.25.1",
|
|
33
|
+
"eslint": "^9.22.0",
|
|
34
|
+
"globals": "^16.0.0",
|
|
35
|
+
"prettier": "^3.5.3"
|
|
30
36
|
},
|
|
31
37
|
"license": "MIT",
|
|
32
38
|
"repository": {
|
|
@@ -38,5 +44,10 @@
|
|
|
38
44
|
},
|
|
39
45
|
"engines": {
|
|
40
46
|
"node": ">=0.10"
|
|
47
|
+
},
|
|
48
|
+
"dependencies": {
|
|
49
|
+
"expect.js": "^0.3.1",
|
|
50
|
+
"universal-thing": "^1.0.0",
|
|
51
|
+
"universal-ticker": "^0.1.1"
|
|
41
52
|
}
|
|
42
53
|
}
|
package/server/server.js
CHANGED
|
@@ -1,152 +1,144 @@
|
|
|
1
1
|
// mech plugin, server-side component
|
|
2
2
|
// These handlers are launched with the wiki server.
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
run(code,state) // when does this even happen?
|
|
73
|
-
}
|
|
4
|
+
import * as fs from 'node:fs'
|
|
5
|
+
import * as path from 'node:path'
|
|
6
|
+
import * as process from 'node:process'
|
|
7
|
+
|
|
8
|
+
function cors(req, res, next) {
|
|
9
|
+
res.header('Access-Control-Allow-Origin', '*')
|
|
10
|
+
next()
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
function startServer(params) {
|
|
14
|
+
var app = params.app,
|
|
15
|
+
argv = params.argv
|
|
16
|
+
|
|
17
|
+
return app.get('/plugin/mech/run/:slug/:itemId', cors, (req, res, next) => {
|
|
18
|
+
console.log(req.params)
|
|
19
|
+
try {
|
|
20
|
+
const slug = req.params.slug
|
|
21
|
+
if(!slug.match(/^[a-z-]+$/)) return next()
|
|
22
|
+
const itemId = req.params.itemId
|
|
23
|
+
const mech = JSON.parse(atob(req.query.mech || 'W10='))
|
|
24
|
+
const share = JSON.parse(atob(req.query.state || 'W10='))
|
|
25
|
+
const context = { argv, slug }
|
|
26
|
+
const state = Object.assign(share, { context })
|
|
27
|
+
run(mech, state)
|
|
28
|
+
.then(() => {
|
|
29
|
+
delete state.context
|
|
30
|
+
return res.json({ mech, state })
|
|
31
|
+
})
|
|
32
|
+
.catch(err => {
|
|
33
|
+
console.log(err)
|
|
34
|
+
return res.json({ err: err.message + ' from promise' })
|
|
35
|
+
})
|
|
36
|
+
} catch (err) {
|
|
37
|
+
return res.json({ err: err.message + ' from try' })
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// I N T E R P R E T E R
|
|
43
|
+
|
|
44
|
+
function status(elem, message) {
|
|
45
|
+
elem.status = message
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function trouble(elem, message) {
|
|
49
|
+
elem.trouble = message
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
async function run(nest, state = {}, mock) {
|
|
53
|
+
// const scope = nest.slice()
|
|
54
|
+
// while (scope.length) {
|
|
55
|
+
for (let here = 0; here < nest.length; here++) {
|
|
56
|
+
// const code = scope.shift()
|
|
57
|
+
const code = nest[here]
|
|
58
|
+
if ('command' in code) {
|
|
59
|
+
const command = code.command
|
|
60
|
+
const elem = code
|
|
61
|
+
const [op, ...args] = code.command.split(/ +/)
|
|
62
|
+
const next = nest[here + 1]
|
|
63
|
+
const body = next && 'command' in next ? null : nest[++here]
|
|
64
|
+
const stuff = { command, op, args, body, elem, state }
|
|
65
|
+
if (state.debug) console.log(stuff)
|
|
66
|
+
if (blocks[op]) await blocks[op].emit.apply(null, [stuff])
|
|
67
|
+
else if (op.match(/^[A-Z]+$/)) trouble(elem, `${op} doesn't name a block we know.`)
|
|
68
|
+
else if (code.command.match(/\S/)) trouble(elem, `Expected line to begin with all-caps keyword.`)
|
|
69
|
+
} else if (Array.isArray(code)) {
|
|
70
|
+
console.warn(`this can't happen.`)
|
|
71
|
+
run(code, state) // when does this even happen?
|
|
74
72
|
}
|
|
75
73
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
// B L O C K S
|
|
77
|
+
|
|
78
|
+
function hello_emit({ elem, args, state }) {
|
|
79
|
+
const world = args[0] == 'world' ? ' 🌎' : ' 😀'
|
|
80
|
+
status(elem, world)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function uptime_emit({ elem, args, state }) {
|
|
84
|
+
const uptime = process.uptime()
|
|
85
|
+
status(elem, uptime)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function sleep_emit({ elem, command, args, body, state }) {
|
|
89
|
+
let count = args[0] || '1'
|
|
90
|
+
if (!count.match(/^[1-9][0-9]?$/)) return trouble(elem, `SLEEP expects seconds from 1 to 99`)
|
|
91
|
+
return new Promise(resolve => {
|
|
92
|
+
if (body)
|
|
93
|
+
run(body, state).then(result => {
|
|
94
|
+
if (state.debug) console.log(command, 'children', result)
|
|
95
|
+
})
|
|
96
|
+
setTimeout(() => {
|
|
97
|
+
resolve()
|
|
98
|
+
}, 1000 * count)
|
|
99
|
+
})
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
async function commons_emit({ elem, args, state }) {
|
|
103
|
+
const readdir = dir => new Promise((res, rej) => fs.readdir(dir, (e, v) => (e ? rej(e) : res(v))))
|
|
104
|
+
const stat = file => new Promise((res, rej) => fs.stat(file, (e, v) => (e ? rej(e) : res(v))))
|
|
105
|
+
const tally = async dir => {
|
|
106
|
+
const count = { files: 0, bytes: 0 }
|
|
107
|
+
const items = await readdir(dir)
|
|
108
|
+
for (const item of items) {
|
|
109
|
+
const itemPath = path.join(dir, item)
|
|
110
|
+
const stats = await stat(itemPath)
|
|
111
|
+
if (state.debug) console.log({ itemPath, stats })
|
|
112
|
+
if (stats.isFile()) {
|
|
113
|
+
count.files++
|
|
114
|
+
count.bytes += stats.size
|
|
118
115
|
}
|
|
119
|
-
return count
|
|
120
116
|
}
|
|
121
|
-
|
|
122
|
-
const here = await tally(path.join(state.context.argv.data,'assets','plugins','image'))
|
|
123
|
-
state.commons = {all,here}
|
|
124
|
-
status(elem,`${(all.bytes/1000000).toFixed(3)} mb in ${all.files} files`)
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
async function delta_emit ({elem,args,state}) {
|
|
128
|
-
const readFile = path => new Promise((res,rej) =>
|
|
129
|
-
fs.readFile(path,(e,v) => e ? rej(e) : res(v)));
|
|
130
|
-
if(!state.recent) return trouble(elem,`DELTA expects "recent" update time in state.`)
|
|
131
|
-
const file = path.join(state.context.argv.db,state.context.slug)
|
|
132
|
-
const page = JSON.parse(await readFile(file))
|
|
133
|
-
state.actions = page.journal
|
|
134
|
-
.filter(action => action.date > state.recent)
|
|
135
|
-
status(elem,`${state.actions.length} recent actions`)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// C A T A L O G
|
|
140
|
-
|
|
141
|
-
const blocks = {
|
|
142
|
-
HELLO: {emit:hello_emit},
|
|
143
|
-
UPTIME: {emit:uptime_emit},
|
|
144
|
-
SLEEP: {emit:sleep_emit},
|
|
145
|
-
COMMONS: {emit:commons_emit},
|
|
146
|
-
DELTA: {emit:delta_emit}
|
|
117
|
+
return count
|
|
147
118
|
}
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
}
|
|
119
|
+
const all = await tally(state.context.argv.commons)
|
|
120
|
+
const here = await tally(path.join(state.context.argv.data, 'assets', 'plugins', 'image'))
|
|
121
|
+
state.commons = { all, here }
|
|
122
|
+
status(elem, `${(all.bytes / 1000000).toFixed(3)} mb in ${all.files} files`)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function delta_emit({ elem, args, state }) {
|
|
126
|
+
const readFile = path => new Promise((res, rej) => fs.readFile(path, (e, v) => (e ? rej(e) : res(v))))
|
|
127
|
+
if (!state.recent) return trouble(elem, `DELTA expects "recent" update time in state.`)
|
|
128
|
+
const file = path.join(state.context.argv.db, state.context.slug)
|
|
129
|
+
const page = JSON.parse(await readFile(file))
|
|
130
|
+
state.actions = page.journal.filter(action => action.date > state.recent)
|
|
131
|
+
status(elem, `${state.actions.length} recent actions`)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// C A T A L O G
|
|
135
|
+
|
|
136
|
+
const blocks = {
|
|
137
|
+
HELLO: { emit: hello_emit },
|
|
138
|
+
UPTIME: { emit: uptime_emit },
|
|
139
|
+
SLEEP: { emit: sleep_emit },
|
|
140
|
+
COMMONS: { emit: commons_emit },
|
|
141
|
+
DELTA: { emit: delta_emit },
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
export { startServer }
|