@delurio/cli 0.8.0 → 0.10.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/CHANGELOG.md +51 -0
- package/README.md +37 -6
- package/SPEC.md +203 -34
- package/dist/anchors.d.ts +29 -0
- package/dist/anchors.js +160 -0
- package/dist/changes.d.ts +4 -2
- package/dist/changes.js +32 -10
- package/dist/check.d.ts +1 -1
- package/dist/check.js +288 -32
- package/dist/diff-nav.js +15 -5
- package/dist/domain-names.d.ts +18 -0
- package/dist/domain-names.js +124 -0
- package/dist/domain.js +1 -1
- package/dist/graph.d.ts +21 -2
- package/dist/graph.js +149 -30
- package/dist/html.d.ts +1 -1
- package/dist/html.js +1 -1
- package/dist/invokes.d.ts +10 -0
- package/dist/invokes.js +67 -0
- package/dist/kit.d.ts +2 -1
- package/dist/kit.js +3 -2
- package/dist/model.d.ts +9 -1
- package/dist/model.js +89 -33
- package/dist/nav-page.js +15 -3
- package/dist/nav.d.ts +20 -1
- package/dist/nav.js +37 -25
- package/dist/needs.d.ts +51 -0
- package/dist/needs.js +335 -0
- package/dist/schemas.d.ts +6 -1
- package/dist/schemas.js +54 -2
- package/dist/starts.js +8 -1
- package/dist/tutorial-check.d.ts +9 -0
- package/dist/tutorial-check.js +297 -0
- package/dist/ui-check.d.ts +1 -1
- package/dist/ui-check.js +64 -13
- package/dist/wireframe.d.ts +2 -0
- package/dist/wireframe.js +31 -4
- package/dist/yaml.d.ts +1 -0
- package/dist/yaml.js +36 -5
- package/package.json +5 -4
- package/schemas/domain.schema.json +10 -7
- package/schemas/gaps.schema.json +49 -0
- package/schemas/nav.schema.json +34 -3
- package/schemas/needs.schema.json +189 -0
- package/schemas/ui.schema.json +42 -9
|
@@ -0,0 +1,297 @@
|
|
|
1
|
+
// A flow's tutorial.yaml held to the flow and its ui (SPEC.md §7). First every name a tutorial uses: the flow it is
|
|
2
|
+
// written against, the variables and values of its `scenario` and of each step's `then`, the states of `show`, `cut`
|
|
3
|
+
// and `end`, the nodes of `press`, `reveal` and `focus`, the events of `after`, and each `{word}` its words fill. Then,
|
|
4
|
+
// when every name is one, its steps are replayed on the flow from the scenario as the video plays them, and the first
|
|
5
|
+
// step that no longer holds is where it stops: a tutorial that no longer matches the graph stops at that step.
|
|
6
|
+
import { kindOf } from './edges.js';
|
|
7
|
+
import { shownIn } from './graph.js';
|
|
8
|
+
import { readYaml } from './yaml.js';
|
|
9
|
+
const isMap = (v) => v !== null && typeof v === 'object' && !Array.isArray(v);
|
|
10
|
+
const names = (v) => (Array.isArray(v) ? v : v === undefined ? [] : [v]);
|
|
11
|
+
const shown = (v) => JSON.stringify(v);
|
|
12
|
+
class Stop extends Error {
|
|
13
|
+
path;
|
|
14
|
+
constructor(path, message) {
|
|
15
|
+
super(message);
|
|
16
|
+
this.path = path;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
export function checkTutorial(g, m, ex, text) {
|
|
20
|
+
let t;
|
|
21
|
+
try {
|
|
22
|
+
t = readYaml(text);
|
|
23
|
+
}
|
|
24
|
+
catch (err) {
|
|
25
|
+
const at = err.linePos?.[0];
|
|
26
|
+
return [{ path: [], line: at?.line ?? 1, column: at?.col ?? 1, message: `tutorial.yaml cannot be read: ${err.message.split('\n')[0]}` }];
|
|
27
|
+
}
|
|
28
|
+
if (!isMap(t) || t.kind !== 'tutorial')
|
|
29
|
+
return [{ path: isMap(t) ? ['kind'] : [], message: 'tutorial.yaml is not a tutorial: it says kind: tutorial (SPEC.md §1, §7)' }];
|
|
30
|
+
if (t.flow !== g.flow.id)
|
|
31
|
+
return [{ path: ['flow'], message: `the tutorial is written against ${String(t.flow)}, and the flow beside it is ${g.flow.id} (SPEC.md §7)` }];
|
|
32
|
+
const stage = t.stage ?? 'screen';
|
|
33
|
+
if (stage !== 'screen' && stage !== 'diagram')
|
|
34
|
+
return [{ path: ['stage'], message: `stage is screen or diagram, not ${String(stage)} (SPEC.md §7)` }];
|
|
35
|
+
const steps = Array.isArray(t.steps) ? t.steps : [];
|
|
36
|
+
const out = [];
|
|
37
|
+
const flow = g.flow;
|
|
38
|
+
const nodes = g.ui.nodes;
|
|
39
|
+
const events = new Set(Object.values(flow.states).flatMap((st) => Object.keys(st.on ?? {})));
|
|
40
|
+
const samples = new Set([...Object.keys(g.ui.samples), ...(isMap(t.samples) ? Object.keys(t.samples) : [])]);
|
|
41
|
+
const problem = (path, message) => {
|
|
42
|
+
out.push({ path, message });
|
|
43
|
+
};
|
|
44
|
+
const values = (where, given, what) => {
|
|
45
|
+
if (given === undefined)
|
|
46
|
+
return;
|
|
47
|
+
if (!isMap(given))
|
|
48
|
+
return problem(where, `${what} is a map of variables to values`);
|
|
49
|
+
for (const [name, v] of Object.entries(given)) {
|
|
50
|
+
const cv = flow.context[name];
|
|
51
|
+
if (cv === undefined)
|
|
52
|
+
problem([...where, name], `${what} names ${name}, which is not a variable of ${flow.id}`);
|
|
53
|
+
else if (!cv.values.includes(v))
|
|
54
|
+
problem([...where, name], `${what}: ${shown(v)} is not a value of ${name} (${cv.values.map(shown).join(', ')})`);
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
// the start: a value of the scenario's for each variable that starts from any value, and the fixed one of the others
|
|
58
|
+
values(['scenario'], t.scenario, 'scenario');
|
|
59
|
+
const scenario = isMap(t.scenario) ? t.scenario : {};
|
|
60
|
+
for (const v of m.vars) {
|
|
61
|
+
const cv = flow.context[v];
|
|
62
|
+
const given = scenario[v];
|
|
63
|
+
if (cv.initial === 'any' && given === undefined)
|
|
64
|
+
problem(['scenario'], `scenario gives no value for ${v}, and the flow starts from any value of it`);
|
|
65
|
+
else if (cv.initial !== 'any' && given !== undefined && given !== cv.initial)
|
|
66
|
+
problem(['scenario', v], `scenario gives ${v} = ${shown(given)}, and ${flow.id} always starts with ${v} = ${shown(cv.initial)}`);
|
|
67
|
+
}
|
|
68
|
+
const words = (where, s, step) => {
|
|
69
|
+
if (typeof s !== 'string')
|
|
70
|
+
return;
|
|
71
|
+
for (const [, name] of s.matchAll(/\{(\w+)\}/g)) {
|
|
72
|
+
if (samples.has(name))
|
|
73
|
+
continue;
|
|
74
|
+
const n = nodes[name];
|
|
75
|
+
if (n === undefined)
|
|
76
|
+
problem(where, `${step}{${name}} is neither a sample value nor a node of ui.yaml`);
|
|
77
|
+
else if (n.text === undefined)
|
|
78
|
+
problem(where, `${step}{${name}} names the node ${name}, which has no visible text to say`);
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
words(['title'], t.title, 'title: ');
|
|
82
|
+
steps.forEach((s0, i) => {
|
|
83
|
+
if (!isMap(s0))
|
|
84
|
+
return;
|
|
85
|
+
const s = s0;
|
|
86
|
+
const at = (...rest) => ['steps', String(i), ...rest];
|
|
87
|
+
const step = `step ${i + 1}`;
|
|
88
|
+
for (const key of ['show', 'cut', 'end']) {
|
|
89
|
+
const v = s[key];
|
|
90
|
+
if (typeof v === 'string' && flow.states[v] === undefined)
|
|
91
|
+
problem(at(key), `${step}: ${key} ${v}, which is not a state of ${flow.id}`);
|
|
92
|
+
}
|
|
93
|
+
for (const key of ['press', 'reveal', 'focus']) {
|
|
94
|
+
names(s[key]).forEach((id, j) => {
|
|
95
|
+
const where = Array.isArray(s[key]) ? at(key, String(j)) : at(key);
|
|
96
|
+
if (stage === 'diagram')
|
|
97
|
+
problem(where, `${step}: ${key} points at a node, and a tutorial on the diagram has none (SPEC.md §7)`);
|
|
98
|
+
else if (typeof id !== 'string' || nodes[id] === undefined)
|
|
99
|
+
problem(where, `${step}: ${key} ${String(id)}, which is not a node of ui.yaml`);
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
names(s.after).forEach((e, j) => {
|
|
103
|
+
if (typeof e !== 'string' || !events.has(e))
|
|
104
|
+
problem(Array.isArray(s.after) ? at('after', String(j)) : at('after'), `${step}: after ${String(e)}, which no state of ${flow.id} handles`);
|
|
105
|
+
});
|
|
106
|
+
values(at('then'), s.then, `${step}: then`);
|
|
107
|
+
words(at('say'), s.say, `${step}: `);
|
|
108
|
+
words(at('chapter'), s.chapter, `${step}: `);
|
|
109
|
+
if (isMap(s.card)) {
|
|
110
|
+
words(at('card', 'title'), s.card.title, `${step}: `);
|
|
111
|
+
words(at('card', 'body'), s.card.body, `${step}: `);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
if (out.length > 0)
|
|
115
|
+
return out;
|
|
116
|
+
try {
|
|
117
|
+
if (stage === 'diagram')
|
|
118
|
+
replayDiagram(g, m, ex, steps, scenario);
|
|
119
|
+
else
|
|
120
|
+
replayScreens(g, m, ex, steps, scenario);
|
|
121
|
+
}
|
|
122
|
+
catch (err) {
|
|
123
|
+
if (!(err instanceof Stop))
|
|
124
|
+
throw err;
|
|
125
|
+
return [{ path: err.path, message: err.message }];
|
|
126
|
+
}
|
|
127
|
+
return [];
|
|
128
|
+
}
|
|
129
|
+
function start(g, m, scenario) {
|
|
130
|
+
return { state: g.flow.initial, ctx: m.vars.map((v) => (g.flow.context[v].initial === 'any' ? scenario[v] : g.flow.context[v].initial)) };
|
|
131
|
+
}
|
|
132
|
+
// the step's `then`: of the cases its transitions can take, the one with these values; without it, the first
|
|
133
|
+
function thenOf(m, s) {
|
|
134
|
+
return isMap(s.then) ? Object.entries(s.then).map(([name, v]) => [m.vars.indexOf(name), v]) : [];
|
|
135
|
+
}
|
|
136
|
+
const pick = (cases, then) => cases.find((c) => then.every(([i, v]) => c.ctx[i] === v)) ?? cases[0];
|
|
137
|
+
function thenHolds(m, s, cur, path, step) {
|
|
138
|
+
for (const [i, v] of thenOf(m, s)) {
|
|
139
|
+
if (cur.ctx[i] !== v)
|
|
140
|
+
throw new Stop([...path, 'then', m.vars[i]], `${step}: no case of this step has ${m.vars[i]} = ${shown(v)}`);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
function replayScreens(g, m, ex, steps, scenario) {
|
|
144
|
+
const flow = g.flow;
|
|
145
|
+
const nodes = g.ui.nodes;
|
|
146
|
+
const hasScreen = (state) => Object.values(nodes).some((n) => shownIn(n, state));
|
|
147
|
+
let then = [];
|
|
148
|
+
const take = (cur, event, path, step) => {
|
|
149
|
+
const hit = pick(m.steps(cur.state, cur.ctx).filter((x) => x.event === event), then);
|
|
150
|
+
if (hit === undefined)
|
|
151
|
+
throw new Stop(path, `${step}: the flow is in ${cur.state}, which does not handle ${event}`);
|
|
152
|
+
return settle({ state: hit.target, ctx: hit.ctx }, path, step);
|
|
153
|
+
};
|
|
154
|
+
// a step with no screen passes on its own along its normal way (a transition with no event, then DONE); one with no
|
|
155
|
+
// such way waits for an event the tutorial gives with `after`
|
|
156
|
+
const settle = (cur, path, step) => {
|
|
157
|
+
let c = cur;
|
|
158
|
+
for (let hops = 0; hops < 50 && kindOf(g, c.state) === 'server'; hops++) {
|
|
159
|
+
const ways = m.steps(c.state, c.ctx);
|
|
160
|
+
const next = pick(ways.filter((x) => x.event === null || x.event === 'DONE'), then);
|
|
161
|
+
if (next === undefined && ways.length > 0)
|
|
162
|
+
return c;
|
|
163
|
+
if (next === undefined)
|
|
164
|
+
throw new Stop(path, `${step}: the flow stops in ${c.state}, which has no screen and no way on`);
|
|
165
|
+
c = { state: next.target, ctx: next.ctx };
|
|
166
|
+
}
|
|
167
|
+
return c;
|
|
168
|
+
};
|
|
169
|
+
let cur = settle(start(g, m, scenario), ['scenario'], 'the start');
|
|
170
|
+
steps.forEach((s0, i) => {
|
|
171
|
+
if (!isMap(s0))
|
|
172
|
+
return;
|
|
173
|
+
const s = s0;
|
|
174
|
+
const path = ['steps', String(i)];
|
|
175
|
+
const step = `step ${i + 1}`;
|
|
176
|
+
then = thenOf(m, s);
|
|
177
|
+
if (s.intro === true) {
|
|
178
|
+
names(s.after).forEach((e, j) => {
|
|
179
|
+
cur = take(cur, e, Array.isArray(s.after) ? [...path, 'after', String(j)] : [...path, 'after'], step);
|
|
180
|
+
});
|
|
181
|
+
thenHolds(m, s, cur, path, step);
|
|
182
|
+
return;
|
|
183
|
+
}
|
|
184
|
+
const reveal = [...names(s.reveal)];
|
|
185
|
+
if (typeof s.press === 'string' && nodes[s.press].when !== undefined && !reveal.includes(s.press))
|
|
186
|
+
reveal.push(s.press);
|
|
187
|
+
let state = cur.state; // the state whose screen the step shows; null for a card
|
|
188
|
+
if (typeof s.cut === 'string') {
|
|
189
|
+
const wanted = s.cut;
|
|
190
|
+
let hit;
|
|
191
|
+
try {
|
|
192
|
+
hit = ex.configs.find((c) => c.state === wanted && reveal.every((id) => nodes[id].when === undefined || m.test(nodes[id].when, c.state, c.ctx)));
|
|
193
|
+
}
|
|
194
|
+
catch (err) {
|
|
195
|
+
throw new Stop([...path, 'reveal'], `${step}: ${err.message}`);
|
|
196
|
+
}
|
|
197
|
+
if (hit === undefined)
|
|
198
|
+
throw new Stop([...path, 'cut'], `${step}: no situation the flow reaches is in ${wanted}${reveal.length > 0 ? ` and shows ${reveal.join(', ')}` : ''}`);
|
|
199
|
+
cur = { state: hit.state, ctx: hit.ctx };
|
|
200
|
+
state = cur.state;
|
|
201
|
+
}
|
|
202
|
+
else if (s.end !== undefined) {
|
|
203
|
+
if (typeof s.end === 'string' && s.end !== cur.state)
|
|
204
|
+
throw new Stop([...path, 'end'], `${step}: the tutorial ends in ${s.end}, and the flow is in ${cur.state} here`);
|
|
205
|
+
if (flow.states[cur.state].type === 'final')
|
|
206
|
+
state = null;
|
|
207
|
+
else if (typeof s.end !== 'string')
|
|
208
|
+
throw new Stop([...path, 'end'], `${step}: the flow is in ${cur.state} here, which is no exit`);
|
|
209
|
+
if (isMap(s.card))
|
|
210
|
+
state = null;
|
|
211
|
+
}
|
|
212
|
+
else if (typeof s.show === 'string') {
|
|
213
|
+
if (s.show !== cur.state)
|
|
214
|
+
throw new Stop([...path, 'show'], `${step}: shows ${s.show}, and the flow is in ${cur.state} here`);
|
|
215
|
+
}
|
|
216
|
+
else if (s.card !== undefined) {
|
|
217
|
+
state = null;
|
|
218
|
+
}
|
|
219
|
+
if (state !== null && !hasScreen(state))
|
|
220
|
+
throw new Stop([...path, typeof s.cut === 'string' ? 'cut' : typeof s.show === 'string' ? 'show' : 'end'], `${step}: ${state} has no screen to show`);
|
|
221
|
+
for (const key of ['reveal', 'focus']) {
|
|
222
|
+
names(s[key]).forEach((id, j) => {
|
|
223
|
+
const where = Array.isArray(s[key]) ? [...path, key, String(j)] : [...path, key];
|
|
224
|
+
const n = nodes[id];
|
|
225
|
+
if (state === null)
|
|
226
|
+
throw new Stop(where, `${step}: ${key} ${String(id)} on a card, which shows no node`);
|
|
227
|
+
if (!shownIn(n, state))
|
|
228
|
+
throw new Stop(where, `${step}: ${key} ${String(id)}, which ${state} does not show`);
|
|
229
|
+
if (key === 'focus' && n.when !== undefined && !reveal.includes(id))
|
|
230
|
+
throw new Stop(where, `${step}: ${String(id)} is shown only when ${n.when}: list it under reveal`);
|
|
231
|
+
});
|
|
232
|
+
}
|
|
233
|
+
if (typeof s.press === 'string') {
|
|
234
|
+
const n = nodes[s.press];
|
|
235
|
+
const where = [...path, 'press'];
|
|
236
|
+
if (!shownIn(n, cur.state))
|
|
237
|
+
throw new Stop(where, `${step}: press ${s.press}, which ${cur.state} does not show`);
|
|
238
|
+
if ((n.disabledIn ?? []).includes(cur.state))
|
|
239
|
+
throw new Stop(where, `${step}: press ${s.press}, which is disabled in ${cur.state}`);
|
|
240
|
+
if (n.emits === undefined)
|
|
241
|
+
throw new Stop(where, `${step}: press ${s.press}, which sends no event`);
|
|
242
|
+
cur = take(cur, n.emits, where, step);
|
|
243
|
+
}
|
|
244
|
+
names(s.after).forEach((e, j) => {
|
|
245
|
+
cur = take(cur, e, Array.isArray(s.after) ? [...path, 'after', String(j)] : [...path, 'after'], step);
|
|
246
|
+
});
|
|
247
|
+
thenHolds(m, s, cur, path, step);
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
// On the diagram no state passes on its own: `show` and `end` walk the flow to their state along its normal way (a
|
|
251
|
+
// transition with no event, then DONE), and every other event is given with `after`
|
|
252
|
+
function replayDiagram(g, m, ex, steps, scenario) {
|
|
253
|
+
let cur = start(g, m, scenario);
|
|
254
|
+
let then = [];
|
|
255
|
+
const walkTo = (wanted, path, step) => {
|
|
256
|
+
const from = cur.state;
|
|
257
|
+
for (let hops = 0; cur.state !== wanted; hops++) {
|
|
258
|
+
const next = hops < 50 ? pick(m.steps(cur.state, cur.ctx).filter((x) => x.event === null || x.event === 'DONE'), then) : undefined;
|
|
259
|
+
if (next === undefined)
|
|
260
|
+
throw new Stop(path, `${step}: ${wanted} is not reached from ${from} without an event${cur.state === from ? '' : ` (the way stops in ${cur.state})`}`);
|
|
261
|
+
cur = { state: next.target, ctx: next.ctx };
|
|
262
|
+
}
|
|
263
|
+
};
|
|
264
|
+
steps.forEach((s0, i) => {
|
|
265
|
+
if (!isMap(s0))
|
|
266
|
+
return;
|
|
267
|
+
const s = s0;
|
|
268
|
+
const path = ['steps', String(i)];
|
|
269
|
+
const step = `step ${i + 1}`;
|
|
270
|
+
then = thenOf(m, s);
|
|
271
|
+
if (s.intro === true)
|
|
272
|
+
return;
|
|
273
|
+
if (typeof s.cut === 'string') {
|
|
274
|
+
const wanted = s.cut;
|
|
275
|
+
const hit = ex.configs.find((c) => c.state === wanted);
|
|
276
|
+
if (hit === undefined)
|
|
277
|
+
throw new Stop([...path, 'cut'], `${step}: no situation the flow reaches is in ${wanted}`);
|
|
278
|
+
cur = { state: hit.state, ctx: hit.ctx };
|
|
279
|
+
}
|
|
280
|
+
else if (typeof s.end === 'string') {
|
|
281
|
+
walkTo(s.end, [...path, 'end'], step);
|
|
282
|
+
if (g.flow.states[s.end].type !== 'final')
|
|
283
|
+
throw new Stop([...path, 'end'], `${step}: ends in ${s.end}, which is no exit`);
|
|
284
|
+
}
|
|
285
|
+
else if (typeof s.show === 'string') {
|
|
286
|
+
walkTo(s.show, [...path, 'show'], step);
|
|
287
|
+
}
|
|
288
|
+
names(s.after).forEach((e, j) => {
|
|
289
|
+
const where = Array.isArray(s.after) ? [...path, 'after', String(j)] : [...path, 'after'];
|
|
290
|
+
const hit = pick(m.steps(cur.state, cur.ctx).filter((x) => x.event === e), then);
|
|
291
|
+
if (hit === undefined)
|
|
292
|
+
throw new Stop(where, `${step}: the flow is in ${cur.state}, which does not handle ${String(e)}`);
|
|
293
|
+
cur = { state: hit.target, ctx: hit.ctx };
|
|
294
|
+
});
|
|
295
|
+
thenHolds(m, s, cur, path, step);
|
|
296
|
+
});
|
|
297
|
+
}
|
package/dist/ui-check.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Graph } from './graph.ts';
|
|
2
2
|
export interface UiProblem {
|
|
3
|
-
rule: 'focus-not-shown' | 'returns-focus-not-dialog';
|
|
3
|
+
rule: 'focus-not-shown' | 'returns-focus-not-dialog' | 'task-locale' | 'role-missing';
|
|
4
4
|
path: string[];
|
|
5
5
|
message: string;
|
|
6
6
|
element: string;
|
package/dist/ui-check.js
CHANGED
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
// What `check` holds in ui.yaml beyond its schema (SPEC.md §4): `focus` and `returnsFocus` give the focus to a node
|
|
2
|
-
// that is shown where the focus goes, `returnsFocus` starts at a dialog,
|
|
3
|
-
//
|
|
2
|
+
// that is shown where the focus goes, `returnsFocus` starts at a dialog, the words a field's `value` takes from the
|
|
3
|
+
// catalog are there, as every other node's are, and the flow's name for its users (`task`) is in every locale. That `value`, `checked` and `script` sit only on the nodes they
|
|
4
4
|
// are for is the schema's; that a `focus` state exists and that `checked` reads the context is the loader's.
|
|
5
|
-
import {
|
|
5
|
+
import { readFileSync } from 'node:fs';
|
|
6
|
+
import { basename, dirname, join } from 'node:path';
|
|
7
|
+
import { alternatives, isDialog, OPENER, shownIn } from './graph.js';
|
|
6
8
|
const listed = (xs) => (xs.length <= 1 ? xs.join('') : `${xs.slice(0, -1).join(', ')} and ${xs[xs.length - 1]}`);
|
|
7
|
-
// the states the flow stops in after a transition out of `state
|
|
8
|
-
// targets of that state, as far as they go
|
|
9
|
-
function stopsAfter(g, state) {
|
|
9
|
+
// the states the flow stops in after a transition out of `state` (on `event` only, when it is given): its targets, and
|
|
10
|
+
// past a state with `always` the targets of that state, as far as they go
|
|
11
|
+
function stopsAfter(g, state, event) {
|
|
10
12
|
const out = [];
|
|
11
13
|
const seen = new Set();
|
|
12
14
|
const ways = (s) => {
|
|
13
15
|
const st = g.flow.states[s];
|
|
14
16
|
return [...(st.always ?? []).map((a) => a.target), ...Object.values(st.on ?? {}).flatMap((spec) => alternatives(spec).map((a) => a.target))];
|
|
15
17
|
};
|
|
16
|
-
const
|
|
18
|
+
const first = g.flow.states[state].on?.[event ?? ''];
|
|
19
|
+
const todo = event === undefined ? ways(state) : first === undefined ? [] : alternatives(first).map((a) => a.target);
|
|
17
20
|
while (todo.length > 0) {
|
|
18
21
|
const t = todo.shift();
|
|
19
22
|
if (seen.has(t))
|
|
@@ -39,6 +42,20 @@ function closesInto(g, dialog) {
|
|
|
39
42
|
}
|
|
40
43
|
return [...out];
|
|
41
44
|
}
|
|
45
|
+
// the nodes that open a dialog: each is shown in a state that does not show the dialog, and sends an event that leads
|
|
46
|
+
// from there to a state that shows it (SPEC.md §4, the node that opened a dialog)
|
|
47
|
+
function openersOf(g, dialog) {
|
|
48
|
+
const d = g.ui.nodes[dialog];
|
|
49
|
+
const out = [];
|
|
50
|
+
for (const [id, n] of Object.entries(g.ui.nodes)) {
|
|
51
|
+
if (n.emits === undefined)
|
|
52
|
+
continue;
|
|
53
|
+
const opens = Object.keys(g.flow.states).some((s) => shownIn(n, s) && !shownIn(d, s) && stopsAfter(g, s, n.emits).some((t) => shownIn(d, t)));
|
|
54
|
+
if (opens)
|
|
55
|
+
out.push(id);
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
42
59
|
export function checkUi(g, warn) {
|
|
43
60
|
const nodes = g.ui.nodes;
|
|
44
61
|
const out = [];
|
|
@@ -61,15 +78,26 @@ export function checkUi(g, warn) {
|
|
|
61
78
|
out.push({ rule: 'returns-focus-not-dialog', path, element, message: `returnsFocus starts at ${dialog}, which is ${what}: it starts at a page node whose role is dialog or alertdialog (SPEC.md §4)` });
|
|
62
79
|
return;
|
|
63
80
|
}
|
|
64
|
-
|
|
65
|
-
|
|
81
|
+
// one node, the nodes that open the dialog, or OPENER: whichever node opens it
|
|
82
|
+
const several = Array.isArray(node) || node === OPENER;
|
|
83
|
+
const targets = node === OPENER ? openersOf(g, dialog) : Array.isArray(node) ? node : [node];
|
|
84
|
+
if (node === OPENER && targets.length === 0) {
|
|
85
|
+
out.push({ rule: 'focus-not-shown', path, element, message: `returnsFocus gives the focus of ${dialog} back to the node that opened it, but no node opens it: none sends an event that leads from a state without the dialog to one that shows it (SPEC.md §4)` });
|
|
66
86
|
return;
|
|
67
87
|
}
|
|
68
88
|
const into = closesInto(g, dialog);
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
89
|
+
for (const t of targets) {
|
|
90
|
+
const at = several ? `${element}/${t}` : element;
|
|
91
|
+
if (nodes[t] === undefined) {
|
|
92
|
+
out.push({ rule: 'focus-not-shown', path, element: at, message: `returnsFocus gives the focus of ${dialog} to ${t}, which is no node of ui.yaml` });
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (into.some((s) => shownIn(nodes[t], s)))
|
|
96
|
+
continue;
|
|
97
|
+
const where = into.length === 0 ? `the dialog ${dialog} never closes into a state the flow stops in` : `no state ${dialog} closes into shows it (${listed(into)})`;
|
|
98
|
+
const who = node === OPENER ? `back to ${t}, which opens it,` : `to ${t},`;
|
|
99
|
+
out.push({ rule: 'focus-not-shown', path, element: at, message: `returnsFocus gives the focus of ${dialog} ${who} but ${where} (SPEC.md §4)` });
|
|
100
|
+
}
|
|
73
101
|
});
|
|
74
102
|
// a field's value in words of the catalog, held as every other node's words are
|
|
75
103
|
const words = (v) => {
|
|
@@ -87,5 +115,28 @@ export function checkUi(g, warn) {
|
|
|
87
115
|
for (const n of Object.values(nodes))
|
|
88
116
|
if (n.value !== undefined)
|
|
89
117
|
words(n.value);
|
|
118
|
+
// a control with no role: a screen reader, a replay and kit check find a field or an action by its WAI-ARIA role
|
|
119
|
+
for (const [id, n] of Object.entries(nodes)) {
|
|
120
|
+
if (n.role !== undefined || (n.type !== 'field' && n.type !== 'action'))
|
|
121
|
+
continue;
|
|
122
|
+
out.push({ rule: 'role-missing', path: ['nodes', id], element: `nodes/${id}`, message: `${id} is ${n.type === 'field' ? 'a field' : 'an action'} with no role: a screen reader, a replay and kit check find a control by its WAI-ARIA role (textbox, combobox, button, link, ...), and kit check holds only its name and state (SPEC.md §4)` });
|
|
123
|
+
}
|
|
124
|
+
// the flow's name for its users, in the catalog of every locale, as the changes note is
|
|
125
|
+
const task = g.ui.task?.key;
|
|
126
|
+
if (g.ui.absent !== true && typeof task === 'string') {
|
|
127
|
+
for (const locale of g.ui.locales ?? [basename(g.ui.catalog, '.json')]) {
|
|
128
|
+
let catalog = null;
|
|
129
|
+
try {
|
|
130
|
+
catalog = JSON.parse(readFileSync(join(g.dir, dirname(g.ui.catalog), `${locale}.json`), 'utf8'));
|
|
131
|
+
}
|
|
132
|
+
catch {
|
|
133
|
+
catalog = null;
|
|
134
|
+
}
|
|
135
|
+
const name = catalog?.[task];
|
|
136
|
+
if (typeof name === 'string' && name.trim() !== '')
|
|
137
|
+
continue;
|
|
138
|
+
out.push({ rule: 'task-locale', path: ['task'], element: `task/${locale}`, message: `the flow's name for its users, ${task}, is not in the ${locale} catalog (SPEC.md §4)` });
|
|
139
|
+
}
|
|
140
|
+
}
|
|
90
141
|
return out;
|
|
91
142
|
}
|
package/dist/wireframe.d.ts
CHANGED
|
@@ -8,6 +8,8 @@ export interface Expectation {
|
|
|
8
8
|
id: string;
|
|
9
9
|
index: number;
|
|
10
10
|
role: string;
|
|
11
|
+
/** False when ui.yaml gives a control (a field or an action) no role: `role` is then its type, which no element is. */
|
|
12
|
+
roleGiven: boolean;
|
|
11
13
|
name: string | undefined;
|
|
12
14
|
disabled: boolean;
|
|
13
15
|
}
|
package/dist/wireframe.js
CHANGED
|
@@ -40,8 +40,22 @@ function accessibleName(g, n, warn) {
|
|
|
40
40
|
}
|
|
41
41
|
if (n.role === 'button' || n.role === 'heading' || n.role === 'status' || n.role === 'alert')
|
|
42
42
|
return texts(g, n, warn)[0];
|
|
43
|
+
// a checkbox, a radio and a select are named by their label, the words beside them (SPEC.md §4)
|
|
44
|
+
if (LABELLED.has(n.component ?? ''))
|
|
45
|
+
return texts(g, n, warn)[0];
|
|
43
46
|
return undefined;
|
|
44
47
|
}
|
|
48
|
+
const LABELLED = new Set(['Checkbox', 'Radio', 'Select']);
|
|
49
|
+
// the words a field holds when it is shown (`value`), for a select the option it shows chosen
|
|
50
|
+
function valueWords(g, n, warn) {
|
|
51
|
+
const v = n.value;
|
|
52
|
+
if (v === undefined)
|
|
53
|
+
return '';
|
|
54
|
+
if (v.literal !== undefined)
|
|
55
|
+
return v.literal;
|
|
56
|
+
const key = v.key ?? v.oneOf?.[0];
|
|
57
|
+
return key === undefined ? '' : fill(g, key, warn);
|
|
58
|
+
}
|
|
45
59
|
function chips(it) {
|
|
46
60
|
const n = it.node;
|
|
47
61
|
const parts = [n.role ?? n.type];
|
|
@@ -49,6 +63,8 @@ function chips(it) {
|
|
|
49
63
|
parts.push(`emits ${n.emits}`);
|
|
50
64
|
if (it.disabled)
|
|
51
65
|
parts.push('disabled');
|
|
66
|
+
else if (n.disabledWhen !== undefined)
|
|
67
|
+
parts.push(`disabled when ${n.disabledWhen}`);
|
|
52
68
|
if (n.when !== undefined)
|
|
53
69
|
parts.push(`when ${n.when}`);
|
|
54
70
|
if (it.focus)
|
|
@@ -78,7 +94,7 @@ function renderWireframe(g, state, items, warn, clean = false, kit = null) {
|
|
|
78
94
|
const name = accessibleName(g, n, warn);
|
|
79
95
|
// the role the expected tree gives the node, which picks a template from the component's `roles`
|
|
80
96
|
const role = n.role ?? (n.type === 'text' ? undefined : n.type);
|
|
81
|
-
return { id: it.id, text, name: name ?? text, intent: n.intent, role, disabled: it.disabled, named: name !== undefined && name !== text, conditional: n.when !== undefined };
|
|
97
|
+
return { id: it.id, text, name: name ?? text, intent: n.intent, role, disabled: it.disabled, named: name !== undefined && name !== text, conditional: n.when !== undefined, checked: n.checked === true };
|
|
82
98
|
};
|
|
83
99
|
const drawKitList = (it, drawn) => {
|
|
84
100
|
const f = { ...fill(it, texts(g, it.node, warn)[0] ?? ''), children: drawn.map((d) => `\n${d}`).join('') + '\n' };
|
|
@@ -142,6 +158,14 @@ function renderWireframe(g, state, items, warn, clean = false, kit = null) {
|
|
|
142
158
|
// the visible text is the label; the input is named by it, as a <label> around it does
|
|
143
159
|
out.push(item(it, `<label class="wf-field"><span>${text}</span><input type="text" class="wf-input" tabindex="-1"${it.disabled ? ' disabled' : ''}></label>`));
|
|
144
160
|
break;
|
|
161
|
+
case 'Checkbox':
|
|
162
|
+
case 'Radio':
|
|
163
|
+
// the box beside its label, as a <label> around an <input> draws it
|
|
164
|
+
out.push(item(it, `<label class="wf-check"><input type="${n.component === 'Radio' ? 'radio' : 'checkbox'}" tabindex="-1"${n.checked === true ? ' checked' : ''}${it.disabled ? ' disabled' : ''}><span>${text}</span></label>`));
|
|
165
|
+
break;
|
|
166
|
+
case 'Select':
|
|
167
|
+
out.push(item(it, `<label class="wf-field"><span>${text}</span><select class="wf-input" tabindex="-1"${it.disabled ? ' disabled' : ''}><option>${esc(valueWords(g, n, warn))}</option></select></label>`));
|
|
168
|
+
break;
|
|
145
169
|
case 'List':
|
|
146
170
|
out.push(`<ul class="wf-list" data-node="${esc(it.id)}">`);
|
|
147
171
|
inList = true;
|
|
@@ -172,7 +196,7 @@ function renderTree(g, items, warn) {
|
|
|
172
196
|
for (const it of items) {
|
|
173
197
|
const n = it.node;
|
|
174
198
|
const depth = n.component === 'Page' ? 0 : n.component === 'ListItem' ? 2 : 1;
|
|
175
|
-
const flags = [it.disabled ? 'disabled' : '', n.when !== undefined ? `when ${n.when}` : '', it.focus ? 'first focus' : '', n.emits !== undefined ? `→ ${n.emits}` : '']
|
|
199
|
+
const flags = [it.disabled ? 'disabled' : n.disabledWhen !== undefined ? `disabled when ${n.disabledWhen}` : '', n.when !== undefined ? `when ${n.when}` : '', it.focus ? 'first focus' : '', n.emits !== undefined ? `→ ${n.emits}` : '']
|
|
176
200
|
.filter((f) => f !== '')
|
|
177
201
|
.join(', ');
|
|
178
202
|
const suffix = flags === '' ? '' : ` [${flags}]`;
|
|
@@ -218,6 +242,8 @@ export function renderStageScreen(g, state, reveal, warn, kit = null) {
|
|
|
218
242
|
const items = shown.map(([id, node]) => ({ id, node, disabled: (node.disabledIn ?? []).includes(state), focus: false }));
|
|
219
243
|
return `<div class="wf${kit === null ? '' : ' kit'}" role="group" aria-label="Screen: ${esc(titleOf(g.flow, state))}">${renderWireframe(g, state, items, warn, true, kit)}</div>`;
|
|
220
244
|
}
|
|
245
|
+
// a node's type that is no WAI-ARIA role: a field or an action with no `role` says nothing a screen reader can find
|
|
246
|
+
const NO_ARIA_TYPES = new Set(['field', 'action']);
|
|
221
247
|
// For `kit check`: every screen with all its nodes (flags revealed, no annotations), and what each node must expose.
|
|
222
248
|
export function renderCheckScreens(g, kit, warn) {
|
|
223
249
|
const html = [];
|
|
@@ -233,11 +259,12 @@ export function renderCheckScreens(g, kit, warn) {
|
|
|
233
259
|
if (n.component === 'Page')
|
|
234
260
|
continue; // the screen itself: nothing is drawn for it
|
|
235
261
|
if (n.component === 'ListItem') {
|
|
236
|
-
texts(g, n, warn).forEach((line, index) => expected.push({ state, id: it.id, index, role: n.role ?? 'listitem', name: line, disabled: it.disabled }));
|
|
262
|
+
texts(g, n, warn).forEach((line, index) => expected.push({ state, id: it.id, index, role: n.role ?? 'listitem', roleGiven: true, name: line, disabled: it.disabled }));
|
|
237
263
|
continue;
|
|
238
264
|
}
|
|
239
265
|
const role = n.role ?? (n.type === 'text' ? 'text' : n.type);
|
|
240
|
-
|
|
266
|
+
const roleGiven = n.role !== undefined || !NO_ARIA_TYPES.has(n.type);
|
|
267
|
+
expected.push({ state, id: it.id, index: 0, role, roleGiven, name: role === 'text' ? texts(g, n, warn)[0] : accessibleName(g, n, warn), disabled: it.disabled });
|
|
241
268
|
}
|
|
242
269
|
}
|
|
243
270
|
return { html: html.join('\n'), expected };
|
package/dist/yaml.d.ts
CHANGED
|
@@ -11,6 +11,7 @@ export declare function lineAndColumn(text: string, offset: number): {
|
|
|
11
11
|
column: number;
|
|
12
12
|
};
|
|
13
13
|
export declare function unsupported(text: string): Unsupported | null;
|
|
14
|
+
export declare function parsingOnce<T>(run: () => T): T;
|
|
14
15
|
export declare function readYaml(text: string): unknown;
|
|
15
16
|
export declare function keyAt(text: string, path: string[]): {
|
|
16
17
|
line: number;
|
package/dist/yaml.js
CHANGED
|
@@ -68,18 +68,49 @@ function refusal(u) {
|
|
|
68
68
|
err.linePos = [{ line: u.line, col: u.column }];
|
|
69
69
|
return err;
|
|
70
70
|
}
|
|
71
|
-
|
|
71
|
+
let read = null;
|
|
72
|
+
// `run`, with every text it reads through `readYaml` or `keyAt` parsed once; the same as `run` alone otherwise
|
|
73
|
+
export function parsingOnce(run) {
|
|
74
|
+
if (read !== null)
|
|
75
|
+
return run();
|
|
76
|
+
read = { values: new Map(), documents: new Map() };
|
|
77
|
+
try {
|
|
78
|
+
return run();
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
read = null;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// the value of a graph file's text: the yaml library's `parse`, once nothing unsupported is found. Inside
|
|
85
|
+
// `parsingOnce` each call gets its own copy, so a reader that changes the value changes no other reader's.
|
|
72
86
|
export function readYaml(text) {
|
|
87
|
+
const kept = read?.values.get(text);
|
|
88
|
+
if (kept !== undefined) {
|
|
89
|
+
if ('refused' in kept)
|
|
90
|
+
throw refusal(kept.refused);
|
|
91
|
+
return structuredClone(kept.value);
|
|
92
|
+
}
|
|
73
93
|
const u = unsupported(text);
|
|
74
|
-
if (u !== null)
|
|
94
|
+
if (u !== null) {
|
|
95
|
+
read?.values.set(text, { refused: u });
|
|
75
96
|
throw refusal(u);
|
|
76
|
-
|
|
97
|
+
}
|
|
98
|
+
const value = parse(text);
|
|
99
|
+
if (read === null)
|
|
100
|
+
return value;
|
|
101
|
+
read.values.set(text, { value });
|
|
102
|
+
return structuredClone(value);
|
|
77
103
|
}
|
|
78
104
|
// the 1-based line and column of the key at `path` in a YAML text (of the item, for a list index), else the file's
|
|
79
105
|
// start; for a text `readYaml` has read
|
|
80
106
|
export function keyAt(text, path) {
|
|
81
|
-
|
|
82
|
-
|
|
107
|
+
let parsed = read?.documents.get(text);
|
|
108
|
+
if (parsed === undefined) {
|
|
109
|
+
const counter = new LineCounter();
|
|
110
|
+
parsed = { doc: parseDocument(text, { lineCounter: counter, prettyErrors: false }), lineCounter: counter };
|
|
111
|
+
read?.documents.set(text, parsed);
|
|
112
|
+
}
|
|
113
|
+
const { doc, lineCounter } = parsed;
|
|
83
114
|
const keyOf = (pair) => String(pair.key?.value ?? pair.key);
|
|
84
115
|
let node = doc.contents;
|
|
85
116
|
let at;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@delurio/cli",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.10.0",
|
|
4
4
|
"description": "The open checker and page of delurio-graph/0: check every graph in a project's own CI, offline, with GNU error lines and SARIF.",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"type": "module",
|
|
@@ -17,10 +17,11 @@
|
|
|
17
17
|
"./expr": { "types": "./dist/expr.d.ts", "default": "./dist/expr.js" },
|
|
18
18
|
"./spine": { "types": "./dist/spine.d.ts", "default": "./dist/spine.js" },
|
|
19
19
|
"./yaml": { "types": "./dist/yaml.d.ts", "default": "./dist/yaml.js" },
|
|
20
|
+
"./needs": { "types": "./dist/needs.d.ts", "default": "./dist/needs.js" },
|
|
20
21
|
"./package.json": "./package.json"
|
|
21
22
|
},
|
|
22
23
|
"files": ["dist", "schemas", "SPEC.md", "NOTICE", "CHANGELOG.md"],
|
|
23
|
-
"engines": { "node": ">=
|
|
24
|
+
"engines": { "node": ">=26" },
|
|
24
25
|
"repository": { "type": "git", "url": "git+https://github.com/delurio-labs/delurio.git" },
|
|
25
26
|
"homepage": "https://delur.io",
|
|
26
27
|
"bugs": "https://github.com/delurio-labs/delurio/issues",
|
|
@@ -33,11 +34,11 @@
|
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"ajv": "8.20.0",
|
|
35
36
|
"ajv-formats": "3.0.1",
|
|
36
|
-
"elkjs": "0.12.
|
|
37
|
+
"elkjs": "0.12.1",
|
|
37
38
|
"yaml": "2.9.1"
|
|
38
39
|
},
|
|
39
40
|
"devDependencies": {
|
|
40
|
-
"@types/node": "
|
|
41
|
+
"@types/node": "26.6.6",
|
|
41
42
|
"typescript": "7.0.2"
|
|
42
43
|
}
|
|
43
44
|
}
|