@enspirit/opspicy 0.0.0-stage → 0.3.0
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/LICENSE +21 -0
- package/README.md +325 -2
- package/bin/entry.js +48 -0
- package/bin/help.js +115 -0
- package/bin/opspicy +27 -0
- package/dist/addresses.js +27 -0
- package/dist/behind.js +64 -0
- package/dist/citizens.js +71 -0
- package/dist/configuration.d.ts +56 -0
- package/dist/configuration.js +66 -0
- package/dist/explorer/afresh.js +43 -0
- package/dist/explorer/api.js +101 -0
- package/dist/explorer/asking.js +59 -0
- package/dist/explorer/build.js +11 -0
- package/dist/explorer/calls.js +42 -0
- package/dist/explorer/document.js +117 -0
- package/dist/explorer/elo-refs.js +153 -0
- package/dist/explorer/elo.js +95 -0
- package/dist/explorer/fonts/OFL.txt +93 -0
- package/dist/explorer/fonts/dm-sans-latin.woff2 +0 -0
- package/dist/explorer/html.js +104 -0
- package/dist/explorer/index.js +62 -0
- package/dist/explorer/json.js +33 -0
- package/dist/explorer/machine.js +34 -0
- package/dist/explorer/masking.js +57 -0
- package/dist/explorer/operation.js +97 -0
- package/dist/explorer/pages.js +159 -0
- package/dist/explorer/script/base.js +103 -0
- package/dist/explorer/script/call.js +161 -0
- package/dist/explorer/script/calling.js +103 -0
- package/dist/explorer/script/connection.js +83 -0
- package/dist/explorer/script/copying.js +75 -0
- package/dist/explorer/script/filter.js +56 -0
- package/dist/explorer/script/formaldef.js +37 -0
- package/dist/explorer/script/main.js +82 -0
- package/dist/explorer/script/markdown.js +143 -0
- package/dist/explorer/script/notes.js +184 -0
- package/dist/explorer/script/noting.js +38 -0
- package/dist/explorer/script/peek.js +62 -0
- package/dist/explorer/script/peeking.js +19 -0
- package/dist/explorer/script/ranking.js +91 -0
- package/dist/explorer/script/review.js +126 -0
- package/dist/explorer/script/rows.js +58 -0
- package/dist/explorer/script/run.js +168 -0
- package/dist/explorer/script/running.js +66 -0
- package/dist/explorer/script/search.js +122 -0
- package/dist/explorer/script/sending.js +64 -0
- package/dist/explorer/script/served.js +51 -0
- package/dist/explorer/serve.js +41 -0
- package/dist/explorer/server.js +143 -0
- package/dist/explorer/site.js +78 -0
- package/dist/explorer/style.css +247 -0
- package/dist/explorer/telling.js +30 -0
- package/dist/explorer/tests.js +78 -0
- package/dist/explorer/wiki.js +90 -0
- package/dist/files.js +178 -0
- package/dist/finding.js +17 -0
- package/dist/judging.js +99 -0
- package/dist/lines.js +30 -0
- package/dist/main.js +128 -0
- package/dist/meaning.js +100 -0
- package/dist/modelling.js +173 -0
- package/dist/naming.js +84 -0
- package/dist/notation.js +119 -0
- package/dist/planning.js +41 -0
- package/dist/reach.js +177 -0
- package/dist/reading.js +135 -0
- package/dist/report-file.js +42 -0
- package/dist/report.js +63 -0
- package/dist/running.js +105 -0
- package/dist/selecting.js +71 -0
- package/dist/starting.js +41 -0
- package/dist/suite.js +32 -0
- package/dist/upgrade.js +27 -0
- package/dist/upgrading.js +76 -0
- package/dist/words.js +103 -0
- package/dist/world.js +129 -0
- package/package.json +57 -4
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// What a note is once the browser has kept it, and gives it back. Pure: what was kept is given,
|
|
2
|
+
// so a table of cases holds it outside a browser.
|
|
3
|
+
//
|
|
4
|
+
// The notes are kept by their anchor, each `{kind, text, item}`: its kind, its text as typed, and
|
|
5
|
+
// what its item was when it was written (markdown.js). The store they come back from was written
|
|
6
|
+
// by a page, and not always by this one: another version of the explorer, another document of
|
|
7
|
+
// the same origin. What is not a note is left out, so that it costs neither the page nor the others.
|
|
8
|
+
|
|
9
|
+
/** What an item says of itself, each a text. */
|
|
10
|
+
const ITEM_KEYS = ['ref', 'kind', 'where', 'title', 'operation', 'area', 'source', 'quote', 'formaldef'];
|
|
11
|
+
|
|
12
|
+
/** What an item was, read back: each of its keys a text, whatever was kept under it. */
|
|
13
|
+
const itemKept = (item) => Object.fromEntries(ITEM_KEYS.map((key) => [key, asText(item[key])]));
|
|
14
|
+
|
|
15
|
+
/** One note read back: a kind there is, a text that says something, and what its item was when one was kept; nothing when it is no note. */
|
|
16
|
+
function noteKept(value) {
|
|
17
|
+
if (!isRecord(value) || !asText(value.text).trim()) return null;
|
|
18
|
+
const kind = NOTE_KINDS.includes(value.kind) ? value.kind : NOTE_KINDS[0];
|
|
19
|
+
return { kind, text: value.text, ...(isRecord(value.item) ? { item: itemKept(value.item) } : {}) };
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The notes read back, by their anchor. */
|
|
23
|
+
const notesKept = (value) =>
|
|
24
|
+
Object.fromEntries(
|
|
25
|
+
Object.entries(isRecord(value) ? value : {})
|
|
26
|
+
.map(([ref, note]) => [ref, noteKept(note)])
|
|
27
|
+
.filter(([, note]) => note),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
/** What an item says, and a note is taken on: its sentence or its description, and its formaldef. Where it is written and what it is called are how it is found, not what it says. */
|
|
31
|
+
const SAYS = ['quote', 'formaldef'];
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* What of an item is no longer what it was when a note was taken on it, among `quote` and
|
|
35
|
+
* `formaldef`: none when it says the same, or when nothing was kept of what it was. An anchor
|
|
36
|
+
* says where an item stands: a clause added above it, and the note is under another sentence.
|
|
37
|
+
*/
|
|
38
|
+
const changedSince = (then, now) => (then && now ? SAYS.filter((key) => asText(then[key]) !== asText(now[key])) : []);
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
// See where a link leads: the card that a link to a citizen or a page shows, after a moment of
|
|
2
|
+
// the pointer or at once with the keyboard. What it says is the index, and the formaldef is the
|
|
3
|
+
// one of the target's own row. The card never takes the pointer.
|
|
4
|
+
|
|
5
|
+
const peek = document.createElement('div');
|
|
6
|
+
peek.id = 'peek';
|
|
7
|
+
peek.hidden = true;
|
|
8
|
+
document.body.append(peek);
|
|
9
|
+
|
|
10
|
+
const byAnchor = new Map(entries.map((entry) => [entry.h, entry]));
|
|
11
|
+
|
|
12
|
+
/** How long the pointer rests on a link before the card shows. */
|
|
13
|
+
const REST = 260;
|
|
14
|
+
/** Where a link already says what it leads to: no card for a page there. */
|
|
15
|
+
const SAYS_ITSELF = 'tr.citizen, .nav, .crumb, .tools, #results';
|
|
16
|
+
|
|
17
|
+
/** The entry a link leads to, and the formaldef of its row; nothing for a link that is not to be shown. */
|
|
18
|
+
function peekTarget(link) {
|
|
19
|
+
const element = elementAt(link.getAttribute('href'));
|
|
20
|
+
if (!element) return null;
|
|
21
|
+
if (element.matches('.page')) return link.closest(SAYS_ITSELF) ? null : { entry: byAnchor.get(element.id), formal: null };
|
|
22
|
+
if (!element.matches('tr.citizen')) return null;
|
|
23
|
+
const formal = formalOf(element);
|
|
24
|
+
return { entry: byAnchor.get(aboutOf(element)), formal: formal && $('pre.elo', formal) };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Shows the card of a link, beside it. */
|
|
28
|
+
function showPeek(link) {
|
|
29
|
+
const found = peekTarget(link);
|
|
30
|
+
if (!found || !found.entry || link.closest('#results')) return;
|
|
31
|
+
peek.innerHTML = peekHtml(found.entry, found.formal ? found.formal.innerHTML : '');
|
|
32
|
+
peek.hidden = false;
|
|
33
|
+
const at = peekPlace(link.getBoundingClientRect(), { width: peek.offsetWidth, height: peek.offsetHeight }, { width: innerWidth, height: innerHeight });
|
|
34
|
+
peek.style.left = `${at.left + scrollX}px`;
|
|
35
|
+
peek.style.top = `${at.top + scrollY}px`;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
let timer;
|
|
39
|
+
|
|
40
|
+
/** Closes the card, and the wait for one. */
|
|
41
|
+
function hidePeek() {
|
|
42
|
+
clearTimeout(timer);
|
|
43
|
+
peek.hidden = true;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const linkOf = (event) => (event.target.closest ? event.target.closest('main a[href^="#"]') : null);
|
|
47
|
+
|
|
48
|
+
document.addEventListener('mouseover', (event) => {
|
|
49
|
+
const link = linkOf(event);
|
|
50
|
+
if (!link) return;
|
|
51
|
+
clearTimeout(timer);
|
|
52
|
+
timer = setTimeout(() => showPeek(link), REST);
|
|
53
|
+
});
|
|
54
|
+
document.addEventListener('mouseout', (event) => {
|
|
55
|
+
if (linkOf(event)) hidePeek();
|
|
56
|
+
});
|
|
57
|
+
document.addEventListener('focusin', (event) => {
|
|
58
|
+
const link = linkOf(event);
|
|
59
|
+
if (link && link.matches(':focus-visible')) showPeek(link);
|
|
60
|
+
});
|
|
61
|
+
document.addEventListener('focusout', hidePeek);
|
|
62
|
+
addEventListener('scroll', hidePeek, { passive: true });
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// What the card of a link says and where it goes. Pure: the entry and the rectangles are given,
|
|
2
|
+
// nothing of the page is read, so a table of cases holds it outside a browser.
|
|
3
|
+
|
|
4
|
+
/** The card of an entry: its kind, its name, what it says, and its formaldef when it has one (already HTML, as its own row shows it: a formaldef holds no id, and nothing of it is rewritten here). */
|
|
5
|
+
function peekHtml(entry, formalHtml) {
|
|
6
|
+
const said = entry.x ? `<p>${esc(entry.x)}</p>` : '';
|
|
7
|
+
const formal = formalHtml ? `<pre class="elo">${formalHtml}</pre>` : '';
|
|
8
|
+
return `<span class="k">${esc(entry.k)}</span><b>${esc(entry.n)}</b>${said}${formal}`;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/** Where the card goes, from the rectangle of the link, the size of the card and of the window: under the link, over it when there is no room, never out of the window. */
|
|
12
|
+
function peekPlace(link, card, view) {
|
|
13
|
+
const gap = 8;
|
|
14
|
+
const under = link.bottom + gap;
|
|
15
|
+
const above = link.top - card.height - gap;
|
|
16
|
+
const top = under + card.height > view.height && above > 0 ? above : under;
|
|
17
|
+
const left = Math.max(gap, Math.min(link.left, view.width - card.width - 12));
|
|
18
|
+
return { left, top };
|
|
19
|
+
}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// What a search finds, and in what order. Pure: the index and the words are given, nothing of
|
|
2
|
+
// the page is read, so the same text is held by a table of cases outside a browser.
|
|
3
|
+
//
|
|
4
|
+
// An entry of the index is `{h, k, n, x, c, ctx}`: its anchor, its kind, its name or its sentence,
|
|
5
|
+
// what else it says, its formaldef as text, and the title of its page.
|
|
6
|
+
|
|
7
|
+
/** What a scope narrows the results to: kinds of entries. */
|
|
8
|
+
const SCOPES = {
|
|
9
|
+
All: null,
|
|
10
|
+
Operations: ['Operation', 'Observation'],
|
|
11
|
+
Types: ['Type'],
|
|
12
|
+
Definitions: ['Predicate', 'Function', 'Condition'],
|
|
13
|
+
Clauses: ['Clause'],
|
|
14
|
+
Cases: ['Case'],
|
|
15
|
+
State: ['State', 'Relation'],
|
|
16
|
+
Tests: ['Tests'],
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
/** The order the kinds are shown in; one that is not named here comes last. */
|
|
20
|
+
const ORDER = ['Operation', 'Observation', 'Area', 'Type', 'Predicate', 'Function', 'Condition', 'Clause', 'Case', 'State', 'Relation', 'Agent', 'Actor', 'Background', 'Tests'];
|
|
21
|
+
|
|
22
|
+
/** The words of what was typed: all of them must be found. */
|
|
23
|
+
const wordsOf = (text) => text.trim().toLowerCase().split(/\s+/).filter(Boolean);
|
|
24
|
+
|
|
25
|
+
/** Whether a text holds every one of the words, wherever: what a filter keeps. */
|
|
26
|
+
const holdsAll = (text, words) => {
|
|
27
|
+
const lower = text.toLowerCase();
|
|
28
|
+
return words.every((word) => lower.includes(word));
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/** The index, ready to be searched: each entry with its texts in lower case. */
|
|
32
|
+
const searchable = (index) =>
|
|
33
|
+
index.map((entry) => {
|
|
34
|
+
const { n, x = '', c = '', ctx = '' } = entry;
|
|
35
|
+
return { ...entry, x, c, ctx, ln: n.toLowerCase(), lx: x.toLowerCase(), lc: c.toLowerCase() };
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const IN_FORMALDEF = 4;
|
|
39
|
+
|
|
40
|
+
/** What one word is worth in one entry: its name said exactly, begun, held; then what else it says; then its formaldef. Nothing when it is nowhere. */
|
|
41
|
+
function worth(entry, word, inFormaldefs) {
|
|
42
|
+
if (entry.ln === word) return 100;
|
|
43
|
+
if (entry.ln.startsWith(word)) return 60;
|
|
44
|
+
if (entry.ln.includes(word)) return 40;
|
|
45
|
+
if (entry.lx.includes(word)) return 15;
|
|
46
|
+
return inFormaldefs && entry.lc.includes(word) ? IN_FORMALDEF : 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** The entries that hold every word, each with its score, and whether a word was found in its formaldef alone. */
|
|
50
|
+
function found(entries, words, inFormaldefs = true) {
|
|
51
|
+
if (!words.length) return [];
|
|
52
|
+
const hits = [];
|
|
53
|
+
for (const entry of entries) {
|
|
54
|
+
const each = words.map((word) => worth(entry, word, inFormaldefs));
|
|
55
|
+
if (each.every(Boolean)) hits.push({ entry, score: each.reduce((sum, one) => sum + one, 0), code: each.includes(IN_FORMALDEF) });
|
|
56
|
+
}
|
|
57
|
+
return hits;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The hits a scope keeps. */
|
|
61
|
+
const scoped = (hits, scope) => hits.filter((hit) => !SCOPES[scope] || SCOPES[scope].includes(hit.entry.k));
|
|
62
|
+
|
|
63
|
+
const place = (kind) => (ORDER.includes(kind) ? ORDER.indexOf(kind) : ORDER.length);
|
|
64
|
+
|
|
65
|
+
/** The hits by kind, the kinds in their order, and in each the best first. */
|
|
66
|
+
function grouped(hits) {
|
|
67
|
+
const kinds = [...new Set(hits.map((hit) => hit.entry.k))].sort((a, b) => place(a) - place(b));
|
|
68
|
+
return kinds.map((kind) => ({ kind, hits: hits.filter((hit) => hit.entry.k === kind).sort((a, b) => b.score - a.score) }));
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** A text made safe for the page, with every place a word is found marked. */
|
|
72
|
+
function marked(text, words) {
|
|
73
|
+
const lower = text.toLowerCase();
|
|
74
|
+
const places = [];
|
|
75
|
+
for (const word of words) for (let at = lower.indexOf(word); at >= 0; at = lower.indexOf(word, at + word.length)) places.push([at, at + word.length]);
|
|
76
|
+
places.sort((a, b) => a[0] - b[0]);
|
|
77
|
+
let out = '';
|
|
78
|
+
let done = 0;
|
|
79
|
+
for (const [from, to] of places) {
|
|
80
|
+
if (from < done) continue;
|
|
81
|
+
out += `${esc(text.slice(done, from))}<mark>${esc(text.slice(from, to))}</mark>`;
|
|
82
|
+
done = to;
|
|
83
|
+
}
|
|
84
|
+
return out + esc(text.slice(done));
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A long text, from a little before the first place a word is found. */
|
|
88
|
+
const around = (text, word) => {
|
|
89
|
+
const at = text.toLowerCase().indexOf(word);
|
|
90
|
+
return at > 60 ? `…${text.slice(at - 40)}` : text;
|
|
91
|
+
};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
// The Review page: the notes in the order of the specification, each still editable and leading
|
|
2
|
+
// to its item, then the review file made of them (markdown.js), to copy or to save. A note whose
|
|
3
|
+
// item the specification no longer has is listed last, as it was when the note was taken.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* One note, with the item it is told with: the item as the specification has it now, or as it
|
|
7
|
+
* was when the note was taken, when what stands at its anchor now says something else
|
|
8
|
+
* (`changed` names what) or when nothing stands there any more (`gone`).
|
|
9
|
+
*/
|
|
10
|
+
function noteTold(ref, note) {
|
|
11
|
+
const now = describe(ref);
|
|
12
|
+
const changed = changedSince(note.item, now);
|
|
13
|
+
const item = (changed.length ? note.item : now) || note.item || { ref, kind: 'item', title: ref };
|
|
14
|
+
return { ref, kind: note.kind, text: note.text, item, now, changed, gone: !now, element: document.getElementById(ref) };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/** The notes, in the order the specification shows their items; those whose item is gone, last. */
|
|
18
|
+
function notesInOrder() {
|
|
19
|
+
const all = Object.entries(notes).map(([ref, note]) => noteTold(ref, note));
|
|
20
|
+
const before = (a, b) => (a.element.compareDocumentPosition(b.element) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
|
|
21
|
+
return [...all.filter((note) => !note.gone).sort(before), ...all.filter((note) => note.gone)];
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** The review file, as it would be written now. */
|
|
25
|
+
const reviewText = () => reviewOf({ meta: META, exported: new Date(), notes: notesInOrder() });
|
|
26
|
+
|
|
27
|
+
/** What the Review page says of a note whose item changed: what stands there now, and the button that says the note is about that. */
|
|
28
|
+
function changedHtml(note) {
|
|
29
|
+
if (!note.changed.length) return '';
|
|
30
|
+
const says = note.changed.includes('quote') ? `The specification now says “${esc(note.now.quote)}” there.` : 'Its formaldef is no longer the one the note was taken on.';
|
|
31
|
+
return `<p class="now s">${says} <button type="button" class="tb sm" data-now>The note is about what it says now</button></p>`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function reviewItem(note) {
|
|
35
|
+
const { item } = note;
|
|
36
|
+
const element = document.createElement('div');
|
|
37
|
+
element.className = 'review-item';
|
|
38
|
+
const tag = note.gone ? 'no longer in the specification' : note.changed.length ? 'changed since the note was taken' : '';
|
|
39
|
+
const title = `${note.gone ? `<b>${esc(item.title)}</b>` : `<a href="#${esc(note.ref)}"><b>${esc(item.title)}</b></a>`}${tag ? ` <span class="tag">${tag}</span>` : ''}`;
|
|
40
|
+
const where = `<span class="m s">${esc(item.kind)}${item.source ? ` · <span class="mono">${esc(item.source)}</span>` : ''}</span>`;
|
|
41
|
+
element.innerHTML = `<div class="where">${title}${where}</div>${item.quote ? `<p class="quote">“${esc(item.quote)}”</p>` : ''}${changedHtml(note)}`;
|
|
42
|
+
element.append(noteBox(note.ref));
|
|
43
|
+
return element;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* The focus, when the Review page was written again from under it: on the note that now stands
|
|
48
|
+
* at that place, on the last one when none does, and on the title of the page when no note is
|
|
49
|
+
* left. What had it (a button of a note, "Delete every note") is no longer there to have it.
|
|
50
|
+
*/
|
|
51
|
+
function focusInReview(place) {
|
|
52
|
+
const fields = $$('#review-list textarea');
|
|
53
|
+
const to = fields[Math.min(place, fields.length - 1)] || $('#review h1');
|
|
54
|
+
if (!fields.length) to.tabIndex = -1;
|
|
55
|
+
to.focus();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/** Writes the Review page from the notes as they are now; `place` is given by who had the focus in it, and says where it goes. */
|
|
59
|
+
function renderReview(place = -1) {
|
|
60
|
+
const all = notesInOrder();
|
|
61
|
+
$('#review-empty').hidden = all.length > 0;
|
|
62
|
+
$('#review-export').hidden = all.length === 0;
|
|
63
|
+
$('#review-list').replaceChildren(...all.map(reviewItem));
|
|
64
|
+
$('#review-md').value = reviewText();
|
|
65
|
+
const clear = $('#clear-notes');
|
|
66
|
+
clear.textContent = 'Delete every note';
|
|
67
|
+
delete clear.dataset.sure;
|
|
68
|
+
if (place >= 0) focusInReview(place);
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/** Saves the review as a file the browser downloads. */
|
|
72
|
+
function downloadReview() {
|
|
73
|
+
try {
|
|
74
|
+
const link = document.createElement('a');
|
|
75
|
+
link.href = URL.createObjectURL(new Blob([reviewText()], { type: 'text/markdown' }));
|
|
76
|
+
link.download = 'review.md';
|
|
77
|
+
link.click();
|
|
78
|
+
URL.revokeObjectURL(link.href);
|
|
79
|
+
} catch {
|
|
80
|
+
toast('Saving was refused here: use Copy');
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/** Has the server write the review to its disk, and says where; false, after saying why, when it did not. */
|
|
85
|
+
async function writeReview() {
|
|
86
|
+
const answer = await serverFetch('/api/review', { method: 'PUT', headers: { 'content-type': 'text/markdown' }, body: reviewText() }, WAITS.review);
|
|
87
|
+
const data = answer && answer.data;
|
|
88
|
+
if (answer && answer.status === 200 && data && data.path) {
|
|
89
|
+
toast(`Review written to ${data.path}`);
|
|
90
|
+
return true;
|
|
91
|
+
}
|
|
92
|
+
toast(`${(data && data.refused) || 'The server did not answer'}: the review is downloaded instead`);
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Saves the review: on the server's disk when the page is served, and as a download when it is not or when the server did not. */
|
|
97
|
+
async function saveReview() {
|
|
98
|
+
if (!served() || !(await writeReview())) downloadReview();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Deletes every note, when asked twice. */
|
|
102
|
+
function clearNotes(button) {
|
|
103
|
+
if (!button.dataset.sure) {
|
|
104
|
+
button.dataset.sure = '1';
|
|
105
|
+
button.textContent = 'Delete every note: sure?';
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
notes = {};
|
|
109
|
+
keepNotes();
|
|
110
|
+
noteCount();
|
|
111
|
+
for (const row of $$('tr.note-row')) row.remove();
|
|
112
|
+
for (const box of $$('.pagenote')) box.remove();
|
|
113
|
+
for (const mark of $$('.rb.nt.on')) sayNoted(mark, false);
|
|
114
|
+
renderReview(0);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
$('#copy-md').addEventListener('click', () => copy(reviewText(), 'Review copied as Markdown'));
|
|
118
|
+
$('#save-md').addEventListener('click', saveReview);
|
|
119
|
+
$('#clear-notes').addEventListener('click', (event) => clearNotes(event.currentTarget));
|
|
120
|
+
$('#review-list').addEventListener('click', (event) => {
|
|
121
|
+
const button = event.target.closest('button[data-now]');
|
|
122
|
+
if (!button) return;
|
|
123
|
+
const item = button.closest('.review-item');
|
|
124
|
+
noteAboutNow($('.note', item).dataset.ref);
|
|
125
|
+
renderReview($$('#review-list .review-item').indexOf(item));
|
|
126
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
// The tools column of a table: a last cell on every row, which the script makes, so that a page
|
|
2
|
+
// read without it has no button that does nothing. What a row has to offer comes from ROW_TOOLS:
|
|
3
|
+
// each part that has a button for a row adds a function to it, and this part never names them.
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What the parts offer for a row, in the order of the buttons. Each is `(row, about) => html`,
|
|
7
|
+
* where `about` says what the row is about (see aboutOf), and gives '' for a row it has nothing for.
|
|
8
|
+
*/
|
|
9
|
+
const ROW_TOOLS = [];
|
|
10
|
+
|
|
11
|
+
/** What a row is about: the citizen it lists at home elsewhere, the case it tells the run of, or its own address. */
|
|
12
|
+
const aboutOf = (row) => row.dataset.home || row.dataset.case || row.id;
|
|
13
|
+
|
|
14
|
+
/** The rows that belong to another row: its formaldef, its note, its run. */
|
|
15
|
+
const SECONDARY = '.formal-row, .note-row, .run-row';
|
|
16
|
+
|
|
17
|
+
/** The ƒ of a row, when it has a formaldef to show. */
|
|
18
|
+
ROW_TOOLS.push((row) =>
|
|
19
|
+
formalOf(row)
|
|
20
|
+
? `<button type="button" class="rb fd" title="Show or hide its formaldef" aria-label="Show or hide its formaldef" aria-expanded="${row.classList.contains('fd-on')}">ƒ</button>`
|
|
21
|
+
: '',
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
/** The tools of one row, as the cell that ends it. */
|
|
25
|
+
const toolsCell = (row) => {
|
|
26
|
+
const cell = document.createElement('td');
|
|
27
|
+
cell.className = 'rt';
|
|
28
|
+
cell.innerHTML = ROW_TOOLS.map((tool) => tool(row, aboutOf(row))).join('');
|
|
29
|
+
return cell;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** A table made ready: its head and its rows each end with the cell of the tools, and what spans its columns spans one more. */
|
|
33
|
+
function prepareTable(table) {
|
|
34
|
+
for (const head of $$('thead tr', table)) {
|
|
35
|
+
const cell = document.createElement('th');
|
|
36
|
+
cell.className = 'rt';
|
|
37
|
+
head.append(cell);
|
|
38
|
+
}
|
|
39
|
+
for (const row of $$('tbody > tr', table)) {
|
|
40
|
+
if (row.matches('.formal-row')) row.cells[0].colSpan += 1;
|
|
41
|
+
else if (!row.matches(SECONDARY)) {
|
|
42
|
+
if (row.matches('.citizen') && formalOf(row)) row.classList.add('has-fd');
|
|
43
|
+
row.append(toolsCell(row));
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** A page made ready, once, the first time it is shown. */
|
|
49
|
+
function prepare(page) {
|
|
50
|
+
if (page.dataset.prepared) return;
|
|
51
|
+
page.dataset.prepared = '1';
|
|
52
|
+
for (const table of $$('table.t', page)) prepareTable(table);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
document.addEventListener('click', (event) => {
|
|
56
|
+
const button = event.target.closest('button.rb.fd');
|
|
57
|
+
if (button) toggleRow(button.closest('tr'));
|
|
58
|
+
});
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
// Running one case: a ▶ at the end of each row that is about a case (the examples and
|
|
2
|
+
// counterexamples of an operation's page, the rows of the tests), which opens a panel under it.
|
|
3
|
+
// Not served, the panel says the command that runs the case in a terminal, to copy. Served, it
|
|
4
|
+
// says which Background the run starts from, and what that does to the database, then runs the
|
|
5
|
+
// case on the server and tells the result, the answer, what did not hold and the whole log.
|
|
6
|
+
// What is decided (the command, the words) is in running.js.
|
|
7
|
+
|
|
8
|
+
/** The `#meta` of the document, read when it is asked for. */
|
|
9
|
+
const runMeta = () => JSON.parse($('#meta').textContent);
|
|
10
|
+
|
|
11
|
+
/** Whether a run is under way: the server runs one at a time, and so does the page. */
|
|
12
|
+
let running = false;
|
|
13
|
+
|
|
14
|
+
/** The ▶ of a row that is about a case, between ƒ and ✎ by the order of the parts. */
|
|
15
|
+
ROW_TOOLS.push((row, about) => (about && about.startsWith('case-') ? '<button type="button" class="rb run" title="Run this case" aria-label="Run this case" aria-expanded="false">▶</button>' : ''));
|
|
16
|
+
|
|
17
|
+
/** The row that holds the run panel of a case's row, among those that belong to it. */
|
|
18
|
+
const runRowOf = (row) => {
|
|
19
|
+
for (let next = row.nextElementSibling; next && next.matches(SECONDARY); next = next.nextElementSibling) if (next.classList.contains('run-row')) return next;
|
|
20
|
+
return null;
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/** A row for the panel, after the formaldef of the row and before its note. */
|
|
24
|
+
function addRunRow(row) {
|
|
25
|
+
const runRow = document.createElement('tr');
|
|
26
|
+
const cell = document.createElement('td');
|
|
27
|
+
runRow.className = 'run-row';
|
|
28
|
+
cell.colSpan = row.cells.length;
|
|
29
|
+
cell.innerHTML = '<div class="runbox"></div>';
|
|
30
|
+
runRow.append(cell);
|
|
31
|
+
let after = row;
|
|
32
|
+
while (after.nextElementSibling && after.nextElementSibling.matches(SECONDARY) && !after.nextElementSibling.matches('.note-row')) after = after.nextElementSibling;
|
|
33
|
+
after.after(runRow);
|
|
34
|
+
return runRow;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** What the panel says when nothing can be run from the page: why, and the command, with its button to copy. */
|
|
38
|
+
function commandHtml(ref, why) {
|
|
39
|
+
const entry = byAnchor.get(ref);
|
|
40
|
+
const { runner, run } = runMeta();
|
|
41
|
+
if (!entry) return '<p class="err">This case is not in the index of the document: nothing says how to run it.</p>';
|
|
42
|
+
return `<p>${esc(why)}</p><pre class="cmd">${esc(runCommand(entry, runner, run && run.mode))}</pre><div class="line"><button type="button" class="tb sm" data-copy-run>Copy</button></div>`;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Whether the system the suite runs against is on another machine, or cannot be told. */
|
|
46
|
+
const onOtherMachine = (target) => {
|
|
47
|
+
try {
|
|
48
|
+
return !isLocal(new URL(target).hostname);
|
|
49
|
+
} catch {
|
|
50
|
+
return true;
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
/** The Background the case starts from, as its own row says it. */
|
|
55
|
+
const backgroundOf = (ref) => {
|
|
56
|
+
const row = document.getElementById(ref);
|
|
57
|
+
try {
|
|
58
|
+
return JSON.parse(row.dataset.request).background || '';
|
|
59
|
+
} catch {
|
|
60
|
+
return '';
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** The mode of a run: said when the server has one, chosen when it has two. */
|
|
65
|
+
const modeHtml = (health) =>
|
|
66
|
+
health.modes && health.modes.length > 1
|
|
67
|
+
? `<label>Mode <select data-mode>${health.modes.map((mode) => `<option${mode === health.mode ? ' selected' : ''}>${esc(mode)}</option>`).join('')}</select></label>`
|
|
68
|
+
: `<span>It runs in the <b>${esc(health.mode)}</b> mode.</span>`;
|
|
69
|
+
|
|
70
|
+
/** What the panel says before a run: where it starts from, what it does to the database, the mode, and the button that runs it. */
|
|
71
|
+
function beforeHtml(ref, health) {
|
|
72
|
+
const background = backgroundOf(ref);
|
|
73
|
+
const from = background ? `the Background <b class="mono">${esc(background)}</b>` : 'its Background';
|
|
74
|
+
return `<p>It starts from ${from}: its seed replaces what the database of <b class="mono">${esc(servedHost())}</b> holds.</p>
|
|
75
|
+
<div class="line">${modeHtml(health)}<button type="button" class="tb primary" data-go>Run this case</button><span class="err s" role="alert"></span></div>
|
|
76
|
+
<div class="outcome" aria-live="polite"></div>`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/** A line for what did not hold: the clause it names, as a link to it, and what it says. */
|
|
80
|
+
function failedLine(one) {
|
|
81
|
+
const entry = one.ref && byAnchor.get(one.ref);
|
|
82
|
+
const label = entry ? `${entry.ctx} · ${entry.w}` : one.ref;
|
|
83
|
+
return `<li>${one.ref ? `<a href="#${esc(one.ref)}">${esc(label)}</a>: ` : ''}${esc(one.says)}</li>`;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** What the system answered to the case: its status, and its body as text. */
|
|
87
|
+
function systemSaid(answer) {
|
|
88
|
+
if (!answer) return '<p class="m">The system gave no answer.</p>';
|
|
89
|
+
const body = bodyText(answer.body);
|
|
90
|
+
return `<p><span class="status">${esc(answer.status)}</span></p>${body ? `<pre class="out">${esc(body)}</pre>` : '<p class="m">No body.</p>'}`;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** What a run answered, in words: its result and time, the mode, the answer of the system, what did not hold, the log. */
|
|
94
|
+
function ranHtml(done) {
|
|
95
|
+
const verdict = verdictOf(done.result);
|
|
96
|
+
const failed = (done.failed || []).length ? `<ul>${done.failed.map(failedLine).join('')}</ul>` : '';
|
|
97
|
+
const log = (done.log || []).join('\n');
|
|
98
|
+
return `<p><span class="res ${verdict.cls}">${verdict.glyph} ${verdict.word}</span> <span class="m">${esc(secondsText(done.seconds))} · ${esc(done.mode)} mode</span></p>${systemSaid(done.answer)}${failed}<details><summary>Full log</summary><pre>${esc(log)}</pre></details>`;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** What the page says of what the server answered to a run: a refusal's sentence, no answer at all, or the run. */
|
|
102
|
+
function answeredHtml(answer) {
|
|
103
|
+
if (!answer) return '<p class="err">No answer from the server: it may have stopped.</p>';
|
|
104
|
+
if (answer.status !== 200 || !answer.data) return `<p class="err">${esc((answer.data && answer.data.refused) || `The server answered ${answer.status}.`)}</p>`;
|
|
105
|
+
return ranHtml(answer.data);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** Sends the case to the server, and tells what comes back. Whatever comes back, or nothing, the run is over: another may start. */
|
|
109
|
+
async function sendRun(box, ref, health) {
|
|
110
|
+
const mode = $('[data-mode]', box) ? $('[data-mode]', box).value : health.mode;
|
|
111
|
+
const out = $('.outcome', box);
|
|
112
|
+
const button = $('[data-go]', box);
|
|
113
|
+
running = true;
|
|
114
|
+
button.disabled = true;
|
|
115
|
+
out.innerHTML = '<p class="m">Running…</p>';
|
|
116
|
+
try {
|
|
117
|
+
out.innerHTML = answeredHtml(await serverFetch('/api/run', { method: 'POST', headers: { 'content-type': 'application/json' }, body: JSON.stringify({ case: ref, mode: modeOfRun(health, mode) }) }, WAITS.run));
|
|
118
|
+
} catch {
|
|
119
|
+
out.innerHTML = '<p class="err">What the server answered is not the telling of a run.</p>';
|
|
120
|
+
} finally {
|
|
121
|
+
running = false;
|
|
122
|
+
button.disabled = false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The button of a served panel: refuses while another run is under way, asks again for a database on another machine, runs. */
|
|
127
|
+
function goRun(box, ref, health) {
|
|
128
|
+
const button = $('[data-go]', box);
|
|
129
|
+
const problem = $('.err', box);
|
|
130
|
+
problem.textContent = '';
|
|
131
|
+
if (running) problem.textContent = 'A run is under way: wait for it.';
|
|
132
|
+
else if (onOtherMachine(health.target) && !button.dataset.armed) {
|
|
133
|
+
button.dataset.armed = '1';
|
|
134
|
+
button.textContent = `It replaces what the database of ${servedHost()} holds: run anyway`;
|
|
135
|
+
} else {
|
|
136
|
+
delete button.dataset.armed;
|
|
137
|
+
button.textContent = 'Run this case';
|
|
138
|
+
sendRun(box, ref, health);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** Fills a panel once it is known whether the page is served, and says it is asking until then. */
|
|
143
|
+
async function fillRun(box, ref) {
|
|
144
|
+
box.innerHTML = '<p class="m">Asking whether this page is served by the explorer…</p>';
|
|
145
|
+
await servedKnown;
|
|
146
|
+
const health = served();
|
|
147
|
+
// A server whose database is somebody's refuses every run: the panel says so, rather than offer one to be refused.
|
|
148
|
+
if (!health) box.innerHTML = commandHtml(ref, whyNotServed(location.protocol));
|
|
149
|
+
else box.innerHTML = health.protected ? commandHtml(ref, whyNoRunHere(servedHost())) : beforeHtml(ref, health);
|
|
150
|
+
const go = $('[data-go]', box);
|
|
151
|
+
if (go) go.addEventListener('click', () => goRun(box, ref, health));
|
|
152
|
+
const copying = $('[data-copy-run]', box);
|
|
153
|
+
if (copying) copying.addEventListener('click', () => copy($('pre.cmd', box).textContent, 'Command copied'));
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** Opens the panel of a row, or closes it when it is open. */
|
|
157
|
+
function toggleRun(row) {
|
|
158
|
+
const button = $('.rb.run', row);
|
|
159
|
+
const open = runRowOf(row);
|
|
160
|
+
if (open) open.remove();
|
|
161
|
+
else fillRun($('.runbox', addRunRow(row)), aboutOf(row));
|
|
162
|
+
button.setAttribute('aria-expanded', String(!open));
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
document.addEventListener('click', (event) => {
|
|
166
|
+
const button = event.target.closest('button.rb.run');
|
|
167
|
+
if (button) toggleRun(button.closest('tr'));
|
|
168
|
+
});
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// What running one case is made of, apart from the page: the command that runs it in a terminal,
|
|
2
|
+
// and how the answer of a run is told in words. Pure: nothing of the page is read, so the same
|
|
3
|
+
// text is held by a table of cases outside a browser (it reads copying.js, for the shell).
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* What a server of the explorer says of itself, when an answer is that: a 200 whose record names
|
|
7
|
+
* this specification, the system as a text and the runs it makes as a list. Nothing otherwise:
|
|
8
|
+
* any host may answer 200 at `/api/health`, and a page published there is not served by the explorer.
|
|
9
|
+
*/
|
|
10
|
+
function healthOf(answer, name) {
|
|
11
|
+
const data = answer && answer.status === 200 ? answer.data : null;
|
|
12
|
+
const told = isRecord(data) && data.name === name && typeof data.target === 'string' && Array.isArray(data.modes) && data.modes.every((mode) => typeof mode === 'string');
|
|
13
|
+
return told ? data : null;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/** What a case is, as the runner is narrowed by `ROBUST=`: `no` for an example, `only` for a counterexample, `generated` for one a condition gives. */
|
|
17
|
+
function robustOf(entry) {
|
|
18
|
+
if (entry.w.startsWith('example')) return 'no';
|
|
19
|
+
return entry.w.includes('from a condition') ? 'generated' : 'only';
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The command that runs one case, from the entry of the index that tells it (`ctx` is its
|
|
24
|
+
* operation, `n` its `when`, `w` what it is), the `runner` of the document, and the mode of the
|
|
25
|
+
* last run: the fast one is asked when it was the last, or when there has been none. The name of
|
|
26
|
+
* an operation is a text of the specification as its `when` is, and is quoted as one.
|
|
27
|
+
*/
|
|
28
|
+
function runCommand(entry, runner, lastMode) {
|
|
29
|
+
const fast = lastMode === undefined || lastMode === null || lastMode === 'fast';
|
|
30
|
+
return [`O=${plainWord(entry.ctx)}`, `CASE=${plainWord(entry.n)}`, `ROBUST=${robustOf(entry)}`, ...(fast ? ['FAST=yes'] : []), runner].join(' ');
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** Why nothing can be run from this page, as one sentence: it was opened as a file, or it is not served. */
|
|
34
|
+
const whyNotServed = (protocol) => (protocol === 'file:' ? 'This page was opened as a file: nothing can be run from it. From a terminal:' : 'This page is not served by the explorer, so nothing can be run from it. From a terminal:');
|
|
35
|
+
|
|
36
|
+
/** Why a server of the explorer runs no case, as one sentence: nothing told it that the database of the system may be emptied, which a run begins by doing. */
|
|
37
|
+
const whyNoRunHere = (host) => `This server runs no case: its configuration does not say that the database of ${host} may be emptied, and a run begins by replacing what it holds. From a terminal, where it may be:`;
|
|
38
|
+
|
|
39
|
+
/** The result of a run, in a glyph and a word, so that colour is never the only thing that says it. */
|
|
40
|
+
function verdictOf(result) {
|
|
41
|
+
if (result === 'passed') return { glyph: '✓', word: 'passed', cls: 'ok' };
|
|
42
|
+
if (result === 'failed') return { glyph: '✗', word: 'failed', cls: 'ko' };
|
|
43
|
+
return { glyph: '✗', word: 'could not be run', cls: 'ko' };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** A time of a run, in seconds, as it reads: `0.04 s`, `1.2 s`, `38 s`. */
|
|
47
|
+
function secondsText(seconds) {
|
|
48
|
+
const value = Number(seconds);
|
|
49
|
+
if (!Number.isFinite(value)) return '';
|
|
50
|
+
if (value < 0.1) return `${Math.round(value * 100) / 100} s`;
|
|
51
|
+
return `${value < 10 ? Math.round(value * 10) / 10 : Math.round(value)} s`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** A body of an answer, as text to read: JSON indented, a text as it is, nothing as nothing. */
|
|
55
|
+
function bodyText(body) {
|
|
56
|
+
if (body === null || body === undefined || body === '') return '';
|
|
57
|
+
if (typeof body !== 'string') return JSON.stringify(body, null, 2);
|
|
58
|
+
try {
|
|
59
|
+
return JSON.stringify(JSON.parse(body), null, 2);
|
|
60
|
+
} catch {
|
|
61
|
+
return body;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The mode a run takes: the one asked when the server runs it, else the one it takes when none is asked. */
|
|
66
|
+
const modeOfRun = (health, asked) => (health.modes && health.modes.includes(asked) ? asked : health.mode);
|