@kurvball/rehearse 0.0.0-stage → 1.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 +107 -2
- package/dist/affected/affected.d.ts +22 -0
- package/dist/affected/affected.js +162 -0
- package/dist/affected/index.d.ts +1 -0
- package/dist/affected/index.js +1 -0
- package/dist/args.d.ts +12 -0
- package/dist/args.js +42 -0
- package/dist/cli.d.ts +4 -0
- package/dist/cli.js +100 -0
- package/dist/commands/check.d.ts +2 -0
- package/dist/commands/check.js +42 -0
- package/dist/commands/clean.d.ts +2 -0
- package/dist/commands/clean.js +37 -0
- package/dist/commands/command.d.ts +30 -0
- package/dist/commands/command.js +38 -0
- package/dist/commands/compare.d.ts +4 -0
- package/dist/commands/compare.js +89 -0
- package/dist/commands/drive.d.ts +2 -0
- package/dist/commands/drive.js +244 -0
- package/dist/commands/index.d.ts +3 -0
- package/dist/commands/index.js +32 -0
- package/dist/commands/init.d.ts +2 -0
- package/dist/commands/init.js +19 -0
- package/dist/commands/list.d.ts +2 -0
- package/dist/commands/list.js +69 -0
- package/dist/commands/open.d.ts +2 -0
- package/dist/commands/open.js +60 -0
- package/dist/commands/people.d.ts +2 -0
- package/dist/commands/people.js +49 -0
- package/dist/commands/run.d.ts +4 -0
- package/dist/commands/run.js +84 -0
- package/dist/commands/services.d.ts +28 -0
- package/dist/commands/services.js +51 -0
- package/dist/commands/stage.d.ts +7 -0
- package/dist/commands/stage.js +53 -0
- package/dist/commands/up.d.ts +3 -0
- package/dist/commands/up.js +77 -0
- package/dist/commands/validate.d.ts +2 -0
- package/dist/commands/validate.js +35 -0
- package/dist/commands/worlds.d.ts +2 -0
- package/dist/commands/worlds.js +15 -0
- package/dist/compare/announce.d.ts +6 -0
- package/dist/compare/announce.js +27 -0
- package/dist/compare/compare.d.ts +83 -0
- package/dist/compare/compare.js +335 -0
- package/dist/compare/diff.d.ts +15 -0
- package/dist/compare/diff.js +105 -0
- package/dist/compare/index.d.ts +5 -0
- package/dist/compare/index.js +5 -0
- package/dist/compare/setaside.d.ts +29 -0
- package/dist/compare/setaside.js +121 -0
- package/dist/compare/verdict.d.ts +21 -0
- package/dist/compare/verdict.js +30 -0
- package/dist/drive/aria.d.ts +8 -0
- package/dist/drive/aria.js +12 -0
- package/dist/drive/browser.d.ts +34 -0
- package/dist/drive/browser.js +216 -0
- package/dist/drive/daemon.d.ts +1 -0
- package/dist/drive/daemon.js +171 -0
- package/dist/drive/grammar.d.ts +93 -0
- package/dist/drive/grammar.js +303 -0
- package/dist/drive/index.d.ts +4 -0
- package/dist/drive/index.js +4 -0
- package/dist/drive/names.d.ts +24 -0
- package/dist/drive/names.js +97 -0
- package/dist/drive/state.d.ts +13 -0
- package/dist/drive/state.js +28 -0
- package/dist/errors.d.ts +26 -0
- package/dist/errors.js +32 -0
- package/dist/exec.d.ts +16 -0
- package/dist/exec.js +43 -0
- package/dist/git/checkout.d.ts +11 -0
- package/dist/git/checkout.js +90 -0
- package/dist/git/git.d.ts +7 -0
- package/dist/git/git.js +27 -0
- package/dist/git/index.d.ts +2 -0
- package/dist/git/index.js +2 -0
- package/dist/git/seed.d.ts +3 -0
- package/dist/git/seed.js +115 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.js +15 -0
- package/dist/kinds/all.d.ts +4 -0
- package/dist/kinds/all.js +4 -0
- package/dist/kinds/call/check.d.ts +29 -0
- package/dist/kinds/call/check.js +187 -0
- package/dist/kinds/call/definition.d.ts +16 -0
- package/dist/kinds/call/definition.js +33 -0
- package/dist/kinds/call/hurl.d.ts +65 -0
- package/dist/kinds/call/hurl.js +333 -0
- package/dist/kinds/call/kind.d.ts +8 -0
- package/dist/kinds/call/kind.js +122 -0
- package/dist/kinds/call/send.d.ts +32 -0
- package/dist/kinds/call/send.js +152 -0
- package/dist/kinds/call/words.d.ts +22 -0
- package/dist/kinds/call/words.js +24 -0
- package/dist/kinds/file/kind.d.ts +44 -0
- package/dist/kinds/file/kind.js +331 -0
- package/dist/kinds/file/layouts.d.ts +14 -0
- package/dist/kinds/file/layouts.js +103 -0
- package/dist/kinds/flow/kind.d.ts +21 -0
- package/dist/kinds/flow/kind.js +412 -0
- package/dist/kinds/flow/literal.d.ts +8 -0
- package/dist/kinds/flow/literal.js +148 -0
- package/dist/kinds/index.d.ts +10 -0
- package/dist/kinds/index.js +8 -0
- package/dist/kinds/kind.d.ts +63 -0
- package/dist/kinds/kind.js +21 -0
- package/dist/kinds/piece/canvas.d.ts +18 -0
- package/dist/kinds/piece/canvas.js +165 -0
- package/dist/kinds/piece/conventions.d.ts +12 -0
- package/dist/kinds/piece/conventions.js +101 -0
- package/dist/kinds/piece/csf.d.ts +10 -0
- package/dist/kinds/piece/csf.js +304 -0
- package/dist/kinds/piece/kind.d.ts +12 -0
- package/dist/kinds/piece/kind.js +297 -0
- package/dist/kinds/piece/server.d.ts +23 -0
- package/dist/kinds/piece/server.js +236 -0
- package/dist/manifest/fill.d.ts +4 -0
- package/dist/manifest/fill.js +7 -0
- package/dist/manifest/index.d.ts +5 -0
- package/dist/manifest/index.js +5 -0
- package/dist/manifest/init.d.ts +1 -0
- package/dist/manifest/init.js +47 -0
- package/dist/manifest/load.d.ts +7 -0
- package/dist/manifest/load.js +245 -0
- package/dist/manifest/types.d.ts +255 -0
- package/dist/manifest/types.js +7 -0
- package/dist/manifest/yaml.d.ts +5 -0
- package/dist/manifest/yaml.js +47 -0
- package/dist/people/index.d.ts +1 -0
- package/dist/people/index.js +1 -0
- package/dist/people/people.d.ts +39 -0
- package/dist/people/people.js +139 -0
- package/dist/run/cache.d.ts +20 -0
- package/dist/run/cache.js +98 -0
- package/dist/run/index.d.ts +5 -0
- package/dist/run/index.js +4 -0
- package/dist/run/observation.d.ts +27 -0
- package/dist/run/observation.js +1 -0
- package/dist/run/parallel.d.ts +28 -0
- package/dist/run/parallel.js +140 -0
- package/dist/run/session.d.ts +35 -0
- package/dist/run/session.js +399 -0
- package/dist/run/vars.d.ts +3 -0
- package/dist/run/vars.js +13 -0
- package/dist/scenarios/area.d.ts +6 -0
- package/dist/scenarios/area.js +37 -0
- package/dist/scenarios/files.d.ts +9 -0
- package/dist/scenarios/files.js +26 -0
- package/dist/scenarios/glob.d.ts +6 -0
- package/dist/scenarios/glob.js +106 -0
- package/dist/scenarios/index.d.ts +4 -0
- package/dist/scenarios/index.js +4 -0
- package/dist/scenarios/read.d.ts +18 -0
- package/dist/scenarios/read.js +54 -0
- package/dist/scenarios/scenario.d.ts +34 -0
- package/dist/scenarios/scenario.js +10 -0
- package/dist/schema.d.ts +14 -0
- package/dist/schema.js +122 -0
- package/dist/services/index.d.ts +2 -0
- package/dist/services/index.js +2 -0
- package/dist/services/registry.d.ts +23 -0
- package/dist/services/registry.js +49 -0
- package/dist/services/service.d.ts +23 -0
- package/dist/services/service.js +313 -0
- package/dist/stage/api.d.ts +30 -0
- package/dist/stage/api.js +206 -0
- package/dist/stage/client/client/api.js +11 -0
- package/dist/stage/client/client/index.js +1 -0
- package/dist/stage/client/features/canvas/call.js +65 -0
- package/dist/stage/client/features/canvas/context.js +1 -0
- package/dist/stage/client/features/canvas/file.js +36 -0
- package/dist/stage/client/features/canvas/flow.js +59 -0
- package/dist/stage/client/features/canvas/index.js +1 -0
- package/dist/stage/client/features/canvas/observed.js +8 -0
- package/dist/stage/client/features/canvas/parts.js +24 -0
- package/dist/stage/client/features/canvas/piece.js +31 -0
- package/dist/stage/client/features/canvas/reach.js +6 -0
- package/dist/stage/client/features/canvas/views.js +16 -0
- package/dist/stage/client/features/list/index.js +1 -0
- package/dist/stage/client/features/list/list.js +53 -0
- package/dist/stage/client/features/list/reach.js +10 -0
- package/dist/stage/client/features/scenario/heading.js +14 -0
- package/dist/stage/client/features/scenario/index.js +1 -0
- package/dist/stage/client/features/scenario/reach.js +9 -0
- package/dist/stage/client/features/scenario/scenario.js +145 -0
- package/dist/stage/client/features/try/index.js +1 -0
- package/dist/stage/client/features/try/reach.js +12 -0
- package/dist/stage/client/features/try/try.js +65 -0
- package/dist/stage/client/index.html +16 -0
- package/dist/stage/client/main.js +24 -0
- package/dist/stage/client/primitives/busy.js +6 -0
- package/dist/stage/client/primitives/focus.js +21 -0
- package/dist/stage/client/primitives/h.js +25 -0
- package/dist/stage/client/primitives/index.js +6 -0
- package/dist/stage/client/primitives/keyed.js +16 -0
- package/dist/stage/client/primitives/say.js +6 -0
- package/dist/stage/client/primitives/state.js +21 -0
- package/dist/stage/client/primitives/types.js +1 -0
- package/dist/stage/client/primitives/verdicts.js +8 -0
- package/dist/stage/client/stage.css +652 -0
- package/dist/stage/compared.d.ts +20 -0
- package/dist/stage/compared.js +58 -0
- package/dist/stage/files.d.ts +4 -0
- package/dist/stage/files.js +59 -0
- package/dist/stage/guard.d.ts +3 -0
- package/dist/stage/guard.js +20 -0
- package/dist/stage/http.d.ts +12 -0
- package/dist/stage/http.js +34 -0
- package/dist/stage/index.d.ts +1 -0
- package/dist/stage/index.js +1 -0
- package/dist/stage/sending.d.ts +18 -0
- package/dist/stage/sending.js +66 -0
- package/dist/stage/server.d.ts +33 -0
- package/dist/stage/server.js +253 -0
- package/dist/version.d.ts +2 -0
- package/dist/version.js +5 -0
- package/dist/worlds/define.d.ts +16 -0
- package/dist/worlds/define.js +45 -0
- package/dist/worlds/index.d.ts +2 -0
- package/dist/worlds/index.js +2 -0
- package/dist/worlds/worlds.d.ts +15 -0
- package/dist/worlds/worlds.js +46 -0
- package/llms.txt +46 -0
- package/package.json +84 -3
- package/schema/v1/announce.schema.json +28 -0
- package/schema/v1/check.schema.json +67 -0
- package/schema/v1/clean.schema.json +19 -0
- package/schema/v1/common.schema.json +210 -0
- package/schema/v1/comparison.schema.json +298 -0
- package/schema/v1/dependents.schema.json +30 -0
- package/schema/v1/drive.schema.json +112 -0
- package/schema/v1/error.schema.json +26 -0
- package/schema/v1/file-scenario.schema.json +175 -0
- package/schema/v1/flow.schema.json +216 -0
- package/schema/v1/init.schema.json +20 -0
- package/schema/v1/list.schema.json +70 -0
- package/schema/v1/manifest.schema.json +434 -0
- package/schema/v1/observation.schema.json +388 -0
- package/schema/v1/open.schema.json +14 -0
- package/schema/v1/people.schema.json +88 -0
- package/schema/v1/samples/announce.yaml +5 -0
- package/schema/v1/samples/check.json +13 -0
- package/schema/v1/samples/clean.json +1 -0
- package/schema/v1/samples/comparison.json +83 -0
- package/schema/v1/samples/dependents.json +7 -0
- package/schema/v1/samples/drive.json +10 -0
- package/schema/v1/samples/error.json +10 -0
- package/schema/v1/samples/file-scenario.yaml +13 -0
- package/schema/v1/samples/flow.yaml +13 -0
- package/schema/v1/samples/init.json +1 -0
- package/schema/v1/samples/list.json +24 -0
- package/schema/v1/samples/manifest.yaml +55 -0
- package/schema/v1/samples/observation.json +49 -0
- package/schema/v1/samples/open.json +6 -0
- package/schema/v1/samples/people.json +11 -0
- package/schema/v1/samples/services.json +27 -0
- package/schema/v1/samples/stage.json +6 -0
- package/schema/v1/samples/try.json +13 -0
- package/schema/v1/samples/up.json +16 -0
- package/schema/v1/samples/validate.json +7 -0
- package/schema/v1/samples/worlds.json +21 -0
- package/schema/v1/services.schema.json +72 -0
- package/schema/v1/stage.schema.json +14 -0
- package/schema/v1/try.schema.json +56 -0
- package/schema/v1/up.schema.json +55 -0
- package/schema/v1/validate.schema.json +40 -0
- package/schema/v1/worlds.schema.json +33 -0
- package/skill/rehearse/SKILL.md +148 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { api } from '../../client/index.js';
|
|
2
|
+
import { disableKeepingFocus, h, redrawKeepingFocus, rememberInUrl, say, state, verdictWords, } from '../../primitives/index.js';
|
|
3
|
+
import { viewOf } from '../canvas/index.js';
|
|
4
|
+
import { tryPanel } from '../try/index.js';
|
|
5
|
+
import { heading, problem } from './heading.js';
|
|
6
|
+
const whyNotCompared = (answer) => answer.notRun?.[0]?.says ?? answer.line;
|
|
7
|
+
const MODES = ['base', 'head', 'diff'];
|
|
8
|
+
const modeWords = (m) => (m === 'base' ? 'Base' : m === 'head' ? 'Head' : 'Diff');
|
|
9
|
+
function chooser(label, key, options, value, set) {
|
|
10
|
+
if (options.length === 0)
|
|
11
|
+
return null;
|
|
12
|
+
return h('label', {}, label, h('select', { 'data-key': key, onchange: (e) => set(e.target.value || null) }, [
|
|
13
|
+
h('option', { value: '' }, '(its own)'),
|
|
14
|
+
...options.map((o) => h('option', { value: o, selected: o === value }, o)),
|
|
15
|
+
]));
|
|
16
|
+
}
|
|
17
|
+
export function createScenario(hooks) {
|
|
18
|
+
const element = h('main', { class: 'stage', id: 'stage' }, h('p', { class: 'empty' }, 'Choose a scenario on the left.'));
|
|
19
|
+
let latestAsk = 0;
|
|
20
|
+
let modeShown = null;
|
|
21
|
+
const render = () => redrawKeepingFocus(element, draw, () => modeShown);
|
|
22
|
+
const notRunYet = (side) => h('p', { class: 'note' }, `Not run on the ${side} yet. `, h('button', { class: 'btn', type: 'button', 'data-key': `run ${side}`, onclick: () => void run(side) }, `Run on the ${side}`));
|
|
23
|
+
const notComparedYet = () => h('p', { class: 'note' }, 'Not compared yet. ', h('button', { class: 'btn', type: 'button', 'data-key': 'compare', onclick: () => void compare() }, 'Compare'));
|
|
24
|
+
function draw() {
|
|
25
|
+
modeShown = null;
|
|
26
|
+
const d = state.detail;
|
|
27
|
+
if (!d) {
|
|
28
|
+
element.replaceChildren(state.errorUntilNextAction
|
|
29
|
+
? problem(state.errorUntilNextAction)
|
|
30
|
+
: h('p', { class: 'empty' }, state.id ? 'Opening the scenario…' : 'Choose a scenario on the left.'));
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const mode = state.mode ?? (d.comparison ? 'diff' : 'head');
|
|
34
|
+
const doing = state.busyByScenario.get(d.scenario.id);
|
|
35
|
+
const modes = h('div', { class: 'modes', role: 'group', 'aria-label': 'What to show' }, MODES.map((m) => {
|
|
36
|
+
const button = h('button', {
|
|
37
|
+
type: 'button',
|
|
38
|
+
'aria-pressed': m === mode ? 'true' : 'false',
|
|
39
|
+
'data-key': `mode ${m}`,
|
|
40
|
+
onclick: () => {
|
|
41
|
+
state.mode = m;
|
|
42
|
+
state.errorUntilNextAction = null;
|
|
43
|
+
rememberInUrl();
|
|
44
|
+
render();
|
|
45
|
+
},
|
|
46
|
+
}, modeWords(m));
|
|
47
|
+
if (m === mode)
|
|
48
|
+
modeShown = button;
|
|
49
|
+
return button;
|
|
50
|
+
}));
|
|
51
|
+
const go = h('button', {
|
|
52
|
+
class: 'btn primary',
|
|
53
|
+
type: 'button',
|
|
54
|
+
'data-key': 'go',
|
|
55
|
+
onclick: () => void (mode === 'diff' ? compare() : run(mode)),
|
|
56
|
+
}, doing ?? (mode === 'diff' ? 'Compare' : `Run on the ${mode}`));
|
|
57
|
+
if (doing)
|
|
58
|
+
disableKeepingFocus(go);
|
|
59
|
+
const view = viewOf(d.scenario.kind)({ detail: d, mode, notRunYet, notComparedYet });
|
|
60
|
+
element.replaceChildren(heading(d), ...(state.errorUntilNextAction ? [problem(state.errorUntilNextAction)] : []), h('div', { class: 'bar' }, chooser('World', 'world', state.index?.worlds ?? [], state.world, (v) => (state.world = v)), chooser('As', 'as', state.index?.people ?? [], state.person, (v) => (state.person = v)), modes, h('span', { class: 'spacer' }), go), h('section', { class: 'canvas', 'aria-label': 'Canvas' }, view), tryPanel(d, mode));
|
|
61
|
+
}
|
|
62
|
+
async function select(id) {
|
|
63
|
+
const ask = ++latestAsk;
|
|
64
|
+
const stale = () => ask !== latestAsk;
|
|
65
|
+
if (state.id !== id) {
|
|
66
|
+
state.mode = null;
|
|
67
|
+
state.errorUntilNextAction = null;
|
|
68
|
+
}
|
|
69
|
+
const showsAnother = state.detail !== null && state.detail.scenario.id !== id;
|
|
70
|
+
if (showsAnother)
|
|
71
|
+
state.detail = null;
|
|
72
|
+
state.id = id;
|
|
73
|
+
rememberInUrl();
|
|
74
|
+
hooks.chosen();
|
|
75
|
+
if (!state.detail)
|
|
76
|
+
render();
|
|
77
|
+
try {
|
|
78
|
+
const d = await api(`/api/scenario?id=${encodeURIComponent(id)}`);
|
|
79
|
+
if (stale())
|
|
80
|
+
return;
|
|
81
|
+
state.detail = d;
|
|
82
|
+
state.errorUntilNextAction = null;
|
|
83
|
+
}
|
|
84
|
+
catch (e) {
|
|
85
|
+
if (stale())
|
|
86
|
+
return;
|
|
87
|
+
state.detail = null;
|
|
88
|
+
state.errorUntilNextAction = e.message;
|
|
89
|
+
}
|
|
90
|
+
render();
|
|
91
|
+
}
|
|
92
|
+
async function busyWithChosen(words, work) {
|
|
93
|
+
const id = state.id;
|
|
94
|
+
if (!id || state.busyByScenario.has(id))
|
|
95
|
+
return;
|
|
96
|
+
state.busyByScenario.set(id, words);
|
|
97
|
+
state.errorUntilNextAction = null;
|
|
98
|
+
say(words);
|
|
99
|
+
render();
|
|
100
|
+
try {
|
|
101
|
+
await work(id);
|
|
102
|
+
}
|
|
103
|
+
catch (e) {
|
|
104
|
+
if (state.id === id)
|
|
105
|
+
state.errorUntilNextAction = e.message;
|
|
106
|
+
}
|
|
107
|
+
finally {
|
|
108
|
+
state.busyByScenario.delete(id);
|
|
109
|
+
if (state.id === id)
|
|
110
|
+
render();
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
async function run(side) {
|
|
114
|
+
await busyWithChosen(`Running on the ${side}…`, async (id) => {
|
|
115
|
+
const o = await api('/api/run', { id, side, world: state.world, person: state.person });
|
|
116
|
+
if (state.id !== id || state.detail?.scenario.id !== id)
|
|
117
|
+
return;
|
|
118
|
+
state.detail[side] = o;
|
|
119
|
+
state.mode = side;
|
|
120
|
+
rememberInUrl();
|
|
121
|
+
say(`Ran on the ${side}.`);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
async function compare() {
|
|
125
|
+
await busyWithChosen('Comparing…', async (id) => {
|
|
126
|
+
const answer = await api('/api/compare', {
|
|
127
|
+
id,
|
|
128
|
+
world: state.world,
|
|
129
|
+
person: state.person,
|
|
130
|
+
});
|
|
131
|
+
if (!answer.entry)
|
|
132
|
+
throw new Error(whyNotCompared(answer));
|
|
133
|
+
if (state.id === id) {
|
|
134
|
+
state.mode = 'diff';
|
|
135
|
+
rememberInUrl();
|
|
136
|
+
await select(id);
|
|
137
|
+
}
|
|
138
|
+
await hooks.compared();
|
|
139
|
+
const c = state.id === id ? state.detail?.comparison : null;
|
|
140
|
+
if (c)
|
|
141
|
+
say(`Compared: ${verdictWords(c.verdict)}`);
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return { element, select };
|
|
145
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { tryPanel } from './try.js';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export default {
|
|
2
|
+
name: 'Try',
|
|
3
|
+
service: 'stage',
|
|
4
|
+
start: '/?s=packages%2Freport%2Fweekly.rehearse.yaml&m=diff',
|
|
5
|
+
steps: [
|
|
6
|
+
{ click: 'Works', role: 'button' },
|
|
7
|
+
{ click: 'A note', role: 'textbox' },
|
|
8
|
+
{ type: 'Two decimals read better.' },
|
|
9
|
+
{ click: 'Save', role: 'button' },
|
|
10
|
+
{ snapshot: 'Earlier tries', role: 'list' },
|
|
11
|
+
],
|
|
12
|
+
};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import { api } from '../../client/index.js';
|
|
2
|
+
import { disableKeepingFocus, enableAgain, h, say, state, } from '../../primitives/index.js';
|
|
3
|
+
const unsavedTriesKeptAcrossDraws = new Map();
|
|
4
|
+
const tryLine = (t) => h('li', {}, `${t.works ? '✓ Works' : '✗ Doesn’t'} · ${t.mode}${t.note ? ` · “${t.note}”` : ''} · ${new Date(t.at).toLocaleString()}`);
|
|
5
|
+
export function tryPanel(d, mode) {
|
|
6
|
+
const id = d.scenario.id;
|
|
7
|
+
const unsaved = unsavedTriesKeptAcrossDraws.get(id) ?? { works: null, note: '' };
|
|
8
|
+
unsavedTriesKeptAcrossDraws.set(id, unsaved);
|
|
9
|
+
let saving = false;
|
|
10
|
+
const note = h('textarea', {
|
|
11
|
+
'aria-label': 'A note',
|
|
12
|
+
placeholder: 'What you saw (optional)',
|
|
13
|
+
'data-key': 'note',
|
|
14
|
+
value: unsaved.note,
|
|
15
|
+
oninput: (e) => (unsaved.note = e.target.value),
|
|
16
|
+
});
|
|
17
|
+
const choice = (works, words) => h('button', {
|
|
18
|
+
class: `btn choice ${works ? 'works' : 'doesnt'}`,
|
|
19
|
+
type: 'button',
|
|
20
|
+
'aria-pressed': String(unsaved.works === works),
|
|
21
|
+
'data-key': works ? 'works' : 'doesnt',
|
|
22
|
+
}, words);
|
|
23
|
+
const yes = choice(true, 'Works');
|
|
24
|
+
const no = choice(false, 'Doesn’t');
|
|
25
|
+
const save = h('button', { class: 'btn primary', type: 'button', disabled: unsaved.works === null, 'data-key': 'save' }, 'Save');
|
|
26
|
+
const pick = (v) => {
|
|
27
|
+
unsaved.works = v;
|
|
28
|
+
yes.setAttribute('aria-pressed', String(v));
|
|
29
|
+
no.setAttribute('aria-pressed', String(!v));
|
|
30
|
+
save.disabled = false;
|
|
31
|
+
};
|
|
32
|
+
yes.addEventListener('click', () => pick(true));
|
|
33
|
+
no.addEventListener('click', () => pick(false));
|
|
34
|
+
const list = h('ul', { class: 'tries', 'aria-label': 'Earlier tries' }, d.tries.slice(0, 5).map(tryLine));
|
|
35
|
+
save.addEventListener('click', () => {
|
|
36
|
+
if (unsaved.works === null || saving)
|
|
37
|
+
return;
|
|
38
|
+
saving = true;
|
|
39
|
+
disableKeepingFocus(save);
|
|
40
|
+
api('/api/try', {
|
|
41
|
+
id,
|
|
42
|
+
works: unsaved.works,
|
|
43
|
+
note: unsaved.note,
|
|
44
|
+
mode,
|
|
45
|
+
world: state.world,
|
|
46
|
+
person: state.person,
|
|
47
|
+
})
|
|
48
|
+
.then((t) => {
|
|
49
|
+
d.tries.unshift(t);
|
|
50
|
+
list.prepend(tryLine(t));
|
|
51
|
+
unsaved.note = '';
|
|
52
|
+
note.value = '';
|
|
53
|
+
say('Saved.');
|
|
54
|
+
})
|
|
55
|
+
.catch((e) => {
|
|
56
|
+
list.prepend(h('li', { class: 'error' }, e.message));
|
|
57
|
+
say(e.message);
|
|
58
|
+
})
|
|
59
|
+
.finally(() => {
|
|
60
|
+
saving = false;
|
|
61
|
+
enableAgain(save);
|
|
62
|
+
});
|
|
63
|
+
});
|
|
64
|
+
return h('section', { class: 'try', 'aria-label': 'Your try' }, h('span', { class: 'q' }, 'Did it work?'), yes, no, note, save, list);
|
|
65
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<title>Rehearse · the stage</title>
|
|
7
|
+
<link rel="stylesheet" href="stage.css" />
|
|
8
|
+
<link
|
|
9
|
+
rel="icon"
|
|
10
|
+
href="data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3E%3Crect width='16' height='16' rx='4' fill='%233b6fd8'/%3E%3Cpath d='M4 11V5h4.5a2 2 0 0 1 0 4H4m4 0 3 2' stroke='white' stroke-width='1.6' fill='none'/%3E%3C/svg%3E"
|
|
11
|
+
/>
|
|
12
|
+
</head>
|
|
13
|
+
<body>
|
|
14
|
+
<script type="module" src="main.js"></script>
|
|
15
|
+
</body>
|
|
16
|
+
</html>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { api } from './client/index.js';
|
|
2
|
+
import { createList } from './features/list/index.js';
|
|
3
|
+
import { createScenario } from './features/scenario/index.js';
|
|
4
|
+
import { h, liveRegion, state } from './primitives/index.js';
|
|
5
|
+
const sides = h('span', { class: 'sides', id: 'sides' });
|
|
6
|
+
const line = h('span', { class: 'line', id: 'line' });
|
|
7
|
+
function renderTop() {
|
|
8
|
+
const i = state.index;
|
|
9
|
+
if (!i)
|
|
10
|
+
return;
|
|
11
|
+
sides.replaceChildren('base ', h('code', {}, `${i.base.ref}${i.base.commit ? `@${i.base.commit.slice(0, 8)}` : ''}`), ' · head ', h('code', {}, `${i.head.commit ? i.head.commit.slice(0, 8) : i.head.path}${i.head.dirty ? ' + changes' : ''}`));
|
|
12
|
+
line.textContent = i.line ?? 'Not compared yet: rehearse compare, or Compare on a scenario.';
|
|
13
|
+
}
|
|
14
|
+
async function loadIndex() {
|
|
15
|
+
state.index = await api('/api/index');
|
|
16
|
+
renderTop();
|
|
17
|
+
list.render();
|
|
18
|
+
}
|
|
19
|
+
const list = createList((id) => void scenario.select(id));
|
|
20
|
+
const scenario = createScenario({ chosen: () => list.render(), compared: loadIndex });
|
|
21
|
+
document.body.append(h('header', { class: 'top' }, h('span', { class: 'brand' }, 'Rehearse'), sides, line), h('div', { class: 'body' }, list.element, scenario.element), liveRegion);
|
|
22
|
+
await loadIndex().catch((e) => list.showError(e.message));
|
|
23
|
+
if (state.id)
|
|
24
|
+
await scenario.select(state.id);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { drawnByKey } from './keyed.js';
|
|
2
|
+
export function redrawKeepingFocus(root, draw, whenGone) {
|
|
3
|
+
const was = document.activeElement;
|
|
4
|
+
const inside = was instanceof HTMLElement && root.contains(was);
|
|
5
|
+
const key = inside ? was.dataset.key : undefined;
|
|
6
|
+
const caret = was instanceof HTMLTextAreaElement || was instanceof HTMLInputElement
|
|
7
|
+
? [was.selectionStart, was.selectionEnd]
|
|
8
|
+
: null;
|
|
9
|
+
const drawn = drawnByKey(draw);
|
|
10
|
+
if (!inside)
|
|
11
|
+
return;
|
|
12
|
+
const inRoot = (el) => (el && root.contains(el) ? el : null);
|
|
13
|
+
const again = (key ? drawn.get(key)?.find((el) => root.contains(el)) : undefined) ?? inRoot(whenGone?.());
|
|
14
|
+
if (!again)
|
|
15
|
+
return;
|
|
16
|
+
again.focus({ preventScroll: true });
|
|
17
|
+
if (caret &&
|
|
18
|
+
caret[0] !== null &&
|
|
19
|
+
(again instanceof HTMLTextAreaElement || again instanceof HTMLInputElement))
|
|
20
|
+
again.setSelectionRange(caret[0], caret[1]);
|
|
21
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { noteKeyed } from './keyed.js';
|
|
2
|
+
export function h(tag, attrs = {}, ...children) {
|
|
3
|
+
const el = document.createElement(tag);
|
|
4
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
5
|
+
if (v === null || v === undefined || v === false)
|
|
6
|
+
continue;
|
|
7
|
+
if (typeof v === 'function')
|
|
8
|
+
el.addEventListener(k.replace(/^on/, '').toLowerCase(), v);
|
|
9
|
+
else if (k === 'class')
|
|
10
|
+
el.className = String(v);
|
|
11
|
+
else if (k === 'value' && 'value' in el)
|
|
12
|
+
el.value = String(v);
|
|
13
|
+
else {
|
|
14
|
+
el.setAttribute(k, v === true ? '' : String(v));
|
|
15
|
+
if (k === 'data-key')
|
|
16
|
+
noteKeyed(String(v), el);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
for (const c of children.flat()) {
|
|
20
|
+
if (c === null || c === undefined || c === false)
|
|
21
|
+
continue;
|
|
22
|
+
el.append(typeof c === 'string' || typeof c === 'number' ? document.createTextNode(String(c)) : c);
|
|
23
|
+
}
|
|
24
|
+
return el;
|
|
25
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { disableKeepingFocus, enableAgain } from './busy.js';
|
|
2
|
+
export { redrawKeepingFocus } from './focus.js';
|
|
3
|
+
export { h } from './h.js';
|
|
4
|
+
export { liveRegion, say } from './say.js';
|
|
5
|
+
export { rememberInUrl, state } from './state.js';
|
|
6
|
+
export { verdictWords } from './verdicts.js';
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
const drawing = [];
|
|
2
|
+
export function noteKeyed(key, el) {
|
|
3
|
+
for (const drawn of drawing)
|
|
4
|
+
drawn.set(key, [...(drawn.get(key) ?? []), el]);
|
|
5
|
+
}
|
|
6
|
+
export function drawnByKey(draw) {
|
|
7
|
+
const drawn = new Map();
|
|
8
|
+
drawing.push(drawn);
|
|
9
|
+
try {
|
|
10
|
+
draw();
|
|
11
|
+
}
|
|
12
|
+
finally {
|
|
13
|
+
drawing.splice(drawing.indexOf(drawn), 1);
|
|
14
|
+
}
|
|
15
|
+
return drawn;
|
|
16
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { h } from './h.js';
|
|
2
|
+
export const liveRegion = h('p', { id: 'said', class: 'sr-only', role: 'status', 'aria-live': 'polite' });
|
|
3
|
+
const heardAgainIfSame = (text, last) => (last === text ? `${text} ` : text);
|
|
4
|
+
export function say(text) {
|
|
5
|
+
liveRegion.textContent = heardAgainIfSame(text, liveRegion.textContent);
|
|
6
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const MODES = ['base', 'head', 'diff'];
|
|
2
|
+
const modeOf = (m) => (m !== null && MODES.includes(m) ? m : null);
|
|
3
|
+
const params = new URLSearchParams(location.search);
|
|
4
|
+
export const state = {
|
|
5
|
+
index: null,
|
|
6
|
+
detail: null,
|
|
7
|
+
id: params.get('s'),
|
|
8
|
+
mode: modeOf(params.get('m')),
|
|
9
|
+
world: null,
|
|
10
|
+
person: null,
|
|
11
|
+
busyByScenario: new Map(),
|
|
12
|
+
errorUntilNextAction: null,
|
|
13
|
+
};
|
|
14
|
+
export function rememberInUrl() {
|
|
15
|
+
const p = new URLSearchParams();
|
|
16
|
+
if (state.id)
|
|
17
|
+
p.set('s', state.id);
|
|
18
|
+
if (state.mode)
|
|
19
|
+
p.set('m', state.mode);
|
|
20
|
+
history.replaceState(null, '', `?${p.toString()}`);
|
|
21
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|