@cmodjs/core 7.0.0 → 8.0.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/docs/commands.md +104 -70
- package/docs/dependencies.md +153 -23
- package/docs/index.md +54 -10
- package/docs/install-steps.md +20 -17
- package/docs/jobs.md +42 -17
- package/docs/mod.md +37 -30
- package/docs/options.md +2 -2
- package/docs/session.md +39 -29
- package/docs/testing.md +84 -23
- package/docs/ui.md +128 -58
- package/installer.d.ts +2 -2
- package/jobs/context.js +1 -1
- package/jobs/program.d.ts +2 -3
- package/jobs/program.d.ts.map +1 -1
- package/jobs/program.js +72 -23
- package/mod.d.ts +23 -8
- package/mod.d.ts.map +1 -1
- package/mod.js +3 -3
- package/package.json +1 -1
- package/records.d.ts +5 -3
- package/records.d.ts.map +1 -1
- package/records.js +18 -9
- package/register.d.ts.map +1 -1
- package/register.js +7 -15
- package/rpc.d.ts +7 -0
- package/rpc.d.ts.map +1 -0
- package/rpc.js +59 -0
- package/runtime/bound.d.ts +1 -0
- package/runtime/bound.d.ts.map +1 -1
- package/runtime/bound.js +10 -0
- package/runtime/bun.d.ts +20 -0
- package/runtime/bun.d.ts.map +1 -0
- package/runtime/bun.js +20 -0
- package/runtime/claude.d.ts +1 -0
- package/runtime/claude.d.ts.map +1 -1
- package/runtime/conversations.d.ts +9 -2
- package/runtime/conversations.d.ts.map +1 -1
- package/runtime/conversations.js +244 -185
- package/runtime/deadline.d.ts +4 -3
- package/runtime/deadline.d.ts.map +1 -1
- package/runtime/deadline.js +10 -4
- package/runtime/engine.d.ts +4 -4
- package/runtime/engine.d.ts.map +1 -1
- package/runtime/installer.d.ts +3 -3
- package/runtime/installer.d.ts.map +1 -1
- package/runtime/installer.js +10 -9
- package/runtime/interfaces.d.ts +108 -42
- package/runtime/interfaces.d.ts.map +1 -1
- package/runtime/interfaces.js +639 -143
- package/runtime/lifecycle.d.ts +3 -5
- package/runtime/lifecycle.d.ts.map +1 -1
- package/runtime/lifecycle.js +74 -63
- package/runtime/options.d.ts.map +1 -1
- package/runtime/options.js +2 -6
- package/runtime/parts.d.ts +64 -1
- package/runtime/parts.d.ts.map +1 -1
- package/runtime/parts.js +311 -4
- package/runtime/programs.d.ts +1 -0
- package/runtime/programs.d.ts.map +1 -1
- package/runtime/programs.js +5 -3
- package/runtime/rpc.d.ts +2 -0
- package/runtime/rpc.d.ts.map +1 -1
- package/runtime/rpc.js +30 -5
- package/runtime/sessions.d.ts +3 -3
- package/runtime/sessions.d.ts.map +1 -1
- package/runtime/sessions.js +38 -73
- package/runtime/toaster.js +1 -1
- package/runtime/ui.d.ts +19 -8
- package/runtime/ui.d.ts.map +1 -1
- package/runtime/ui.js +51 -47
- package/runtime/web.d.ts +0 -73
- package/runtime/web.d.ts.map +1 -1
- package/runtime/web.js +9 -5
- package/runtime/widgets.d.ts +4 -2
- package/runtime/widgets.d.ts.map +1 -1
- package/runtime/widgets.js +17 -16
- package/session/conversation.d.ts +6 -2
- package/session/conversation.d.ts.map +1 -1
- package/session/session.d.ts +22 -6
- package/session/session.d.ts.map +1 -1
- package/session/session.js +1 -0
- package/src/installer.ts +2 -2
- package/src/jobs/context.ts +1 -1
- package/src/jobs/program.ts +63 -23
- package/src/mod.ts +22 -11
- package/src/records.ts +21 -9
- package/src/register.ts +7 -15
- package/src/rpc.ts +67 -0
- package/src/runtime/bound.ts +10 -0
- package/src/runtime/bun.ts +40 -0
- package/src/runtime/claude.ts +1 -0
- package/src/runtime/conversations.ts +247 -182
- package/src/runtime/deadline.ts +13 -6
- package/src/runtime/engine.ts +4 -4
- package/src/runtime/installer.ts +13 -12
- package/src/runtime/interfaces.ts +753 -172
- package/src/runtime/lifecycle.ts +93 -67
- package/src/runtime/options.ts +2 -5
- package/src/runtime/parts.ts +364 -5
- package/src/runtime/programs.ts +6 -3
- package/src/runtime/rpc.ts +32 -5
- package/src/runtime/sessions.ts +39 -73
- package/src/runtime/toaster.ts +1 -1
- package/src/runtime/ui.ts +67 -55
- package/src/runtime/web.ts +10 -39
- package/src/runtime/widgets.ts +20 -18
- package/src/session/conversation.ts +7 -2
- package/src/session/session.ts +14 -6
- package/src/testing/fake-claude.ts +10 -4
- package/src/testing/fake-serve.ts +106 -6
- package/src/testing/fake-sessions.ts +6 -5
- package/src/testing.ts +149 -67
- package/src/ui/areas.ts +2 -2
- package/src/ui/elements.ts +21 -16
- package/src/ui/panes.ts +14 -7
- package/testing/fake-claude.d.ts +2 -0
- package/testing/fake-claude.d.ts.map +1 -1
- package/testing/fake-claude.js +10 -4
- package/testing/fake-serve.d.ts +32 -2
- package/testing/fake-serve.d.ts.map +1 -1
- package/testing/fake-serve.js +81 -6
- package/testing/fake-sessions.d.ts.map +1 -1
- package/testing/fake-sessions.js +6 -5
- package/testing.d.ts +21 -4
- package/testing.d.ts.map +1 -1
- package/testing.js +131 -55
- package/ui/areas.d.ts +3 -1
- package/ui/areas.d.ts.map +1 -1
- package/ui/elements.d.ts +18 -9
- package/ui/elements.d.ts.map +1 -1
- package/ui/elements.js +9 -8
- package/ui/panes.d.ts +10 -6
- package/ui/panes.d.ts.map +1 -1
- package/ui/panes.js +5 -3
- package/runtime/pages.d.ts +0 -34
- package/runtime/pages.d.ts.map +0 -1
- package/runtime/pages.js +0 -157
- package/src/runtime/pages.ts +0 -198
package/testing.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { hotkeyCommand, readSteps
|
|
1
|
+
import { hotkeyCommand, readSteps } from './records.js';
|
|
2
2
|
import { heldInput } from './runtime/claude.js';
|
|
3
3
|
import { answerCall, cmodPluginName, loadedMethod, notInstalled } from './runtime/dependencies.js';
|
|
4
4
|
import { closingContext, foldBefore, installBefore, withAnswer } from './runtime/before.js';
|
|
@@ -7,6 +7,7 @@ import { keepClaudeCode } from './testing/claude-code.js';
|
|
|
7
7
|
import { createRouter } from './runtime/router.js';
|
|
8
8
|
import { toolInputOf } from './runtime/tool-calls.js';
|
|
9
9
|
import { createLifecycle } from './runtime/lifecycle.js';
|
|
10
|
+
import { cmodStore } from './runtime/programs.js';
|
|
10
11
|
import { serveCmodPlugin } from './register.js';
|
|
11
12
|
import { MissingOptions } from './runtime/options.js';
|
|
12
13
|
import { conversationMethods, pickedColor } from './runtime/sessions.js';
|
|
@@ -26,12 +27,11 @@ import { fakeSessions } from './testing/fake-sessions.js';
|
|
|
26
27
|
import { listed, messageOf } from './utils/text.js';
|
|
27
28
|
import { componentOf } from './ui/styles.js';
|
|
28
29
|
import { AbovePrompt, areas, BelowPrompt, Dashboard, TurnEnd as TurnEndArea, Working } from './ui/areas.js';
|
|
29
|
-
import { drawWith, elementOf,
|
|
30
|
-
import { drawnParts } from './runtime/parts.js';
|
|
30
|
+
import { drawWith, elementOf, forClaudeCode } from './ui/elements.js';
|
|
31
|
+
import { drawnParts, pagesOf, providedBy, serveParts, viewsOf } from './runtime/parts.js';
|
|
31
32
|
import { serveWidgets } from './runtime/widgets.js';
|
|
32
33
|
import { engineOf } from './runtime/engine.js';
|
|
33
|
-
import {
|
|
34
|
-
import { interfaceMethods, styleInterface } from './runtime/interfaces.js';
|
|
34
|
+
import { createProviders, interfaceMethods, styleInterface } from './runtime/interfaces.js';
|
|
35
35
|
import { inheriting, openLink, partMethods } from './runtime/ui.js';
|
|
36
36
|
const defaultColumns = 80;
|
|
37
37
|
const defaultRows = 24;
|
|
@@ -50,6 +50,15 @@ function drawnByStyle(key) {
|
|
|
50
50
|
export function testMod(definition, options = {}) {
|
|
51
51
|
installJsx();
|
|
52
52
|
const name = definition.name;
|
|
53
|
+
const given = options.providers ?? [];
|
|
54
|
+
for (const each of given) {
|
|
55
|
+
if (each.program !== undefined)
|
|
56
|
+
continue;
|
|
57
|
+
if (each.mod === name)
|
|
58
|
+
throw new Error(`${name} is the tested mod, so its own provide answers ${each.name}. Fake another mod's provider, or a program's with program: '<executable>'.`);
|
|
59
|
+
if (each.device !== undefined)
|
|
60
|
+
throw new Error(`${each.mod}'s session code provides ${each.name} only in this session, on this computer, so it takes no device. Give the program that provides it on ${each.device.name}, with program: '<executable>'.`);
|
|
61
|
+
}
|
|
53
62
|
const isProjectPlugin = options.scope === 'project';
|
|
54
63
|
let projectRoot = options.projectRoot ?? (isProjectPlugin ? '/test/project' : `/test/plugins/${name}`);
|
|
55
64
|
const root = isProjectPlugin ? `${projectRoot}/.claude/skills/${name}` : `/test/plugins/${name}`;
|
|
@@ -88,6 +97,7 @@ export function testMod(definition, options = {}) {
|
|
|
88
97
|
if (held.color !== undefined)
|
|
89
98
|
await tellColor(held);
|
|
90
99
|
};
|
|
100
|
+
let declaredViews = [];
|
|
91
101
|
let declaredPages = [];
|
|
92
102
|
let openPages = [];
|
|
93
103
|
let shownPage;
|
|
@@ -99,10 +109,11 @@ export function testMod(definition, options = {}) {
|
|
|
99
109
|
return work;
|
|
100
110
|
};
|
|
101
111
|
const settle = async () => {
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
await fake.settle();
|
|
113
|
+
while (modeled.size > 0) {
|
|
104
114
|
await Promise.allSettled(modeled);
|
|
105
|
-
|
|
115
|
+
await fake.settle();
|
|
116
|
+
}
|
|
106
117
|
};
|
|
107
118
|
let focused;
|
|
108
119
|
const forgetFocus = (part) => {
|
|
@@ -114,7 +125,7 @@ export function testMod(definition, options = {}) {
|
|
|
114
125
|
const pane = isPane ? id : 'sidebar';
|
|
115
126
|
if (!(await holdsKeyboard(isPane, id)))
|
|
116
127
|
return `the pane "${pane}" does not hold the keyboard`;
|
|
117
|
-
const drawn = lifecycle.phase === 'active' ? (isPane ? await drawPane(id) : await
|
|
128
|
+
const drawn = lifecycle.phase === 'active' ? (isPane ? await drawPane(id) : await drawInSidebar(id)).drawing : undefined;
|
|
118
129
|
if (drawn === undefined || focusableKey(drawn, (props) => props['key'] === key) === undefined)
|
|
119
130
|
return `the pane "${pane}" draws no Button, Input, or Select with the key "${key}"`;
|
|
120
131
|
return undefined;
|
|
@@ -122,12 +133,12 @@ export function testMod(definition, options = {}) {
|
|
|
122
133
|
const applyRequests = async (requests) => {
|
|
123
134
|
for (const request of requests) {
|
|
124
135
|
if ('open' in request) {
|
|
125
|
-
const isSettings =
|
|
136
|
+
const isSettings = declaredViews.some((view) => view.id === request.open && view.place === 'settings');
|
|
126
137
|
if (!isSettings)
|
|
127
138
|
openPages = [...openPages.filter((page) => page.id !== request.open), { id: request.open, params: request.params ?? null }];
|
|
128
139
|
shownPage = { id: request.open, params: request.params ?? null, isFocused: request.focus === true };
|
|
129
140
|
if (request.focus === true)
|
|
130
|
-
forgetFocus(`
|
|
141
|
+
forgetFocus(`sidebar:${request.open}`);
|
|
131
142
|
}
|
|
132
143
|
else if ('close' in request) {
|
|
133
144
|
openPages = openPages.filter((page) => page.id !== request.close);
|
|
@@ -138,15 +149,15 @@ export function testMod(definition, options = {}) {
|
|
|
138
149
|
const key = `${name}/${request.focus}:${request.key}`;
|
|
139
150
|
const refused = await refusedFocus(false, request.focus, key);
|
|
140
151
|
if (refused === undefined)
|
|
141
|
-
focused = { part: `
|
|
152
|
+
focused = { part: `sidebar:${request.focus}`, key: request.key };
|
|
142
153
|
else
|
|
143
|
-
reportPart(`pages:${name}`, `Could not show the page ${name} asked for`, new Error(`cmod: Claude Code did not focus "${key}" in the Sidebar pane: ${refused}`));
|
|
154
|
+
reportPart(`pages:${name}`, `Could not show the view or page ${name} asked for`, new Error(`cmod: Claude Code did not focus "${key}" in the Sidebar pane: ${refused}`));
|
|
144
155
|
}
|
|
145
156
|
else if ('settings' in request) {
|
|
146
|
-
const first =
|
|
157
|
+
const first = declaredViews.find((view) => view.place === 'settings');
|
|
147
158
|
shownPage = first === undefined ? undefined : { id: first.id, params: null, isFocused: true };
|
|
148
159
|
if (first !== undefined)
|
|
149
|
-
forgetFocus(`
|
|
160
|
+
forgetFocus(`sidebar:${first.id}`);
|
|
150
161
|
}
|
|
151
162
|
}
|
|
152
163
|
await tellShown();
|
|
@@ -157,6 +168,7 @@ export function testMod(definition, options = {}) {
|
|
|
157
168
|
const missedMarkdown = new Map();
|
|
158
169
|
const updated = async ({ parts, redraw, requests }) => {
|
|
159
170
|
if (parts !== undefined) {
|
|
171
|
+
declaredViews = viewsOf(parts);
|
|
160
172
|
declaredPages = pagesOf(parts);
|
|
161
173
|
provides = providedBy(parts);
|
|
162
174
|
ownMarkdown.clear();
|
|
@@ -196,7 +208,7 @@ export function testMod(definition, options = {}) {
|
|
|
196
208
|
const openFromCmod = (href, press) => void openLink(fake.claude, href, press.surface).catch((error) => reportPart('open-link', 'Could not open the link', error));
|
|
197
209
|
const cmodClaude = {
|
|
198
210
|
...fake.claude,
|
|
199
|
-
ui: { ...fake.claude.ui, resolve: (e) =>
|
|
211
|
+
ui: { ...fake.claude.ui, resolve: (e) => forClaudeCode(fake.claude.ui.resolve(e), e.surface, openFromCmod) },
|
|
200
212
|
cmod: { call: async (input) => (input.to === name ? callMod(input.method, input.input) : fake.claude.cmod.call(input)) },
|
|
201
213
|
};
|
|
202
214
|
const tellRefusedPress = (_mod, error) => fake.claude.ui.log(`cmod: ${name} did not take the press: ${messageOf(error)}`, { to: 'debug' });
|
|
@@ -208,7 +220,7 @@ export function testMod(definition, options = {}) {
|
|
|
208
220
|
return serveWidgets({
|
|
209
221
|
claude: cmodClaude,
|
|
210
222
|
router: cmodPlugin,
|
|
211
|
-
store:
|
|
223
|
+
store: await cmodStore(fake.claude),
|
|
212
224
|
report: reportPart,
|
|
213
225
|
turnClosedBy: () => conversations.lastTurn(),
|
|
214
226
|
parts,
|
|
@@ -217,14 +229,62 @@ export function testMod(definition, options = {}) {
|
|
|
217
229
|
};
|
|
218
230
|
const widgetsOf = () => (widgets ??= servedWidgets());
|
|
219
231
|
const cmodBeneath = createRouter();
|
|
220
|
-
const
|
|
221
|
-
|
|
222
|
-
const
|
|
232
|
+
const servedParts = serveParts({ claude: cmodClaude, router: cmodBeneath, report: reportPart, tellRefusedPress, widgets: { update: (mod, update) => void widgetsOf().then((served) => served.update(mod, update)) }, parts, tellStylers: () => undefined, tellUi: () => undefined });
|
|
233
|
+
servedParts.apply((_mod, requests) => applyRequests(requests));
|
|
234
|
+
const after = (ms, run) => fake.claude.clock.after(ms, run);
|
|
235
|
+
const report = (error) => reportPart('interfaces', 'A provider listener failed', error);
|
|
236
|
+
const sessionMods = new Map();
|
|
237
|
+
const served = fake.serve.connect({
|
|
238
|
+
tell: (_caller, heard) => new Promise((resolve) => fake.claude.clock.after(0, () => resolve(callMod(interfaceMethods.heard, heard)))),
|
|
239
|
+
sessionCode: (named) => [...(provides.includes(named) ? [name] : []), ...[...sessionMods].filter(([, each]) => each.provided().includes(named)).map(([mod]) => mod)],
|
|
240
|
+
device: async () => {
|
|
241
|
+
const { id, name: deviceName } = await fake.claude.device.read();
|
|
242
|
+
return { id, name: deviceName };
|
|
243
|
+
},
|
|
244
|
+
after,
|
|
245
|
+
report,
|
|
246
|
+
});
|
|
247
|
+
const providedInSession = given.map(({ name: named, mod, program, methods }) => {
|
|
248
|
+
if (program !== undefined)
|
|
249
|
+
return undefined;
|
|
250
|
+
const made = sessionMods.get(mod) ?? createProviders({ name: mod, call: (_to, method, input) => served.answer(method, input, mod) ?? Promise.reject(new Error(`${mod} reaches no ${method} in the test kit.`)), changed: () => undefined, after, report });
|
|
251
|
+
sessionMods.set(mod, made);
|
|
252
|
+
return made.provide(named, methods);
|
|
253
|
+
});
|
|
254
|
+
let fakesReady;
|
|
255
|
+
const fakeProviders = () => (fakesReady ??= (async () => {
|
|
256
|
+
const programs = await fake.serve.provide(given.flatMap(({ name: named, mod, program, device, methods }) => (program === undefined ? [] : [{ name: named, mod, program, ...(device === undefined ? {} : { device }), methods }])), { after, report });
|
|
257
|
+
let next = 0;
|
|
258
|
+
return providedInSession.map((inSession) => inSession ?? programs[next++]);
|
|
259
|
+
})());
|
|
260
|
+
const fakeProvider = (index) => {
|
|
261
|
+
const reached = async () => {
|
|
262
|
+
const each = (await fakeProviders())[index];
|
|
263
|
+
await fake.settle();
|
|
264
|
+
return each;
|
|
265
|
+
};
|
|
266
|
+
return {
|
|
267
|
+
remove: () => void modeling(reached().then((each) => each.remove())),
|
|
268
|
+
tell: (event, payload) => void modeling(reached().then((each) => each.tell(event, payload))),
|
|
269
|
+
ask: (event, payload) => modeling(reached().then((each) => each.ask(event, payload))),
|
|
270
|
+
};
|
|
271
|
+
};
|
|
272
|
+
const fakedPrograms = new Set(given.flatMap(({ mod, program }) => (mod === name && program !== undefined ? [program] : [])));
|
|
273
|
+
const spawnUnlessFaked = fake.claude.process.spawn;
|
|
274
|
+
fake.claude.process.spawn = (request) => {
|
|
275
|
+
const [, command, mod] = request.argv;
|
|
276
|
+
const at = request.argv.indexOf('--');
|
|
277
|
+
const executable = at === -1 ? undefined : request.argv[at + 1]?.split('/').at(-1);
|
|
278
|
+
if (command !== 'program' || mod !== name || request.argv.includes('--remove-service') || executable === undefined || !fakedPrograms.has(executable))
|
|
279
|
+
return spawnUnlessFaked(request);
|
|
280
|
+
return { [Symbol.asyncIterator]: () => ({ next: () => new Promise(() => undefined) }) };
|
|
281
|
+
};
|
|
282
|
+
const dependencies = fakeDependencies(name, options.dependencies ?? {}, conversations, served, sessionMods);
|
|
223
283
|
fake.fakes.cmod.call = async (call) => {
|
|
224
284
|
if (call.to !== cmodPluginName || call.method !== partMethods.changed)
|
|
225
285
|
return dependencies(call);
|
|
226
286
|
const { requests, isAsked, ...listing } = call.input;
|
|
227
|
-
const isHeld = isAsked === true && requests !== undefined &&
|
|
287
|
+
const isHeld = isAsked === true && requests !== undefined && servedParts.update(name, { requests, isAsked });
|
|
228
288
|
await updated(isAsked === true ? listing : call.input);
|
|
229
289
|
return { isHeld };
|
|
230
290
|
};
|
|
@@ -269,7 +329,7 @@ export function testMod(definition, options = {}) {
|
|
|
269
329
|
const runProcess = fake.claude.process.run;
|
|
270
330
|
fake.claude.process.run = async (argv, init) => {
|
|
271
331
|
const [program, command, action, mod, key] = argv;
|
|
272
|
-
if (program?.split('/').at(-1) !== 'cmod' || command !== '
|
|
332
|
+
if (program?.split('/').at(-1) !== 'cmod' || command !== 'secrets' || mod !== name || key === undefined)
|
|
273
333
|
return runProcess(argv, init);
|
|
274
334
|
const answer = (stdout, stderr = '') => ({ exitCode: stderr === '' ? 0 : 1, stdout, stderr, isStdoutTruncated: false, isStderrTruncated: false });
|
|
275
335
|
if (action === 'get')
|
|
@@ -277,7 +337,7 @@ export function testMod(definition, options = {}) {
|
|
|
277
337
|
if (action === 'delete')
|
|
278
338
|
secrets.delete(key);
|
|
279
339
|
else if (init?.stdin === undefined || init.stdin === '')
|
|
280
|
-
return answer('', `cmod
|
|
340
|
+
return answer('', `cmod secrets: cmod secrets store read no value from stdin. cmod secrets delete ${name} ${key} deletes the secret.\n`);
|
|
281
341
|
else
|
|
282
342
|
secrets.set(key, init.stdin);
|
|
283
343
|
return answer('');
|
|
@@ -312,15 +372,15 @@ export function testMod(definition, options = {}) {
|
|
|
312
372
|
await fake.settle();
|
|
313
373
|
};
|
|
314
374
|
const start = async () => {
|
|
315
|
-
started ??= lifecycle.start(fake.claude, async (claude) => ({
|
|
375
|
+
started ??= fakeProviders().then(() => lifecycle.start(fake.claude, async (claude) => ({
|
|
316
376
|
name,
|
|
317
377
|
root,
|
|
318
378
|
version: '0.0.0',
|
|
319
|
-
store:
|
|
379
|
+
store: await cmodStore(claude),
|
|
320
380
|
isInstalled: true,
|
|
321
381
|
shouldRecord: false,
|
|
322
382
|
steps: await modSteps(),
|
|
323
|
-
}));
|
|
383
|
+
})));
|
|
324
384
|
await started;
|
|
325
385
|
await fake.settle();
|
|
326
386
|
const { failure } = lifecycle;
|
|
@@ -425,36 +485,39 @@ export function testMod(definition, options = {}) {
|
|
|
425
485
|
const drawing = await route('ui.render', { surface: 'terminal', component: 'Pane', requestId: paneId, props }, elements.Box({}));
|
|
426
486
|
return { drawing, columns };
|
|
427
487
|
};
|
|
428
|
-
const
|
|
488
|
+
const drawInSidebar = async (id, columns = defaultColumns) => {
|
|
429
489
|
await start();
|
|
430
|
-
const
|
|
431
|
-
if (
|
|
432
|
-
throw new Error(`The page "${
|
|
433
|
-
const drawn = (await callMod(partMethods.draw, { page:
|
|
490
|
+
const shown = shownPage;
|
|
491
|
+
if (shown?.id !== id)
|
|
492
|
+
throw new Error(`The view or page "${id}" of ${name} no longer shows, and a user sees one only while it shows.`);
|
|
493
|
+
const drawn = (await callMod(partMethods.draw, { page: id, params: shown.params, columns, isFocused: shown.isFocused, surface: 'terminal' }));
|
|
434
494
|
await fake.settle();
|
|
435
495
|
const tree = drawn?.tree ?? null;
|
|
436
|
-
const table =
|
|
437
|
-
const drawing = tree === null || drawn === null ? elements.Box({}) : await withOwnMarkdown(async () => drawWith(table, () => elementOf(tree, `${name}/${
|
|
496
|
+
const table = forClaudeCode(elements, 'terminal', openFromCmod);
|
|
497
|
+
const drawing = tree === null || drawn === null ? elements.Box({}) : await withOwnMarkdown(async () => drawWith(table, () => elementOf(tree, `${name}/${id}:`, (handler, args) => void modeling(pressPart({ draw: drawn.draw, handler, args }))), markdownIn(table, { surface: 'terminal', columns })));
|
|
438
498
|
checkKeys(drawing, cmodPluginName, 'Pane');
|
|
439
499
|
return { drawing, columns };
|
|
440
500
|
};
|
|
441
|
-
const shownNow = (
|
|
442
|
-
if (
|
|
501
|
+
const shownNow = (kind) => {
|
|
502
|
+
if (kind === 'pane') {
|
|
443
503
|
const id = [...fake.shown.openPanes].at(-1);
|
|
444
504
|
if (id === undefined)
|
|
445
505
|
throw new Error(`No pane of ${name} shows. Open one with pane.open(), from a slash command, a hotkey, or setup.`);
|
|
446
506
|
return { id, params: undefined };
|
|
447
507
|
}
|
|
448
|
-
|
|
449
|
-
|
|
508
|
+
const shownKind = shownPage === undefined ? undefined : declaredPages.some((page) => page.id === shownPage?.id) ? 'page' : 'view';
|
|
509
|
+
if (shownPage === undefined || shownKind !== kind) {
|
|
510
|
+
const opening = kind === 'view' ? 'view.open(), or Settings with mod.settings.open()' : 'page.open()';
|
|
511
|
+
throw new Error(`No ${kind} of ${name} shows in the Sidebar${shownPage === undefined ? '' : `, where its ${shownKind} "${shownPage.id}" shows`}. Open one with ${opening}.`);
|
|
512
|
+
}
|
|
450
513
|
return shownPage;
|
|
451
514
|
};
|
|
452
|
-
const shownPart = (
|
|
453
|
-
const
|
|
515
|
+
const shownPart = (kind) => {
|
|
516
|
+
const isPane = kind === 'pane';
|
|
454
517
|
const draw = async (columns) => {
|
|
455
518
|
await start();
|
|
456
|
-
const { id } = shownNow(
|
|
457
|
-
return { id, ...(isPane ? await drawPane(id, columns) : await
|
|
519
|
+
const { id } = shownNow(kind);
|
|
520
|
+
return { id, ...(isPane ? await drawPane(id, columns) : await drawInSidebar(id, columns)) };
|
|
458
521
|
};
|
|
459
522
|
const drawnElement = async (type, key) => {
|
|
460
523
|
const { id, drawing } = await draw();
|
|
@@ -467,10 +530,10 @@ export function testMod(definition, options = {}) {
|
|
|
467
530
|
const eventIn = (id, key) => ({ plugin: name, element: key, component: 'Pane', requestId: id, surface: 'terminal' });
|
|
468
531
|
return {
|
|
469
532
|
get id() {
|
|
470
|
-
return shownNow(
|
|
533
|
+
return shownNow(kind).id;
|
|
471
534
|
},
|
|
472
535
|
get params() {
|
|
473
|
-
return shownNow(
|
|
536
|
+
return shownNow(kind).params;
|
|
474
537
|
},
|
|
475
538
|
lines: async (lineOptions) => {
|
|
476
539
|
const { drawing, columns } = await draw(lineOptions?.columns);
|
|
@@ -512,10 +575,10 @@ export function testMod(definition, options = {}) {
|
|
|
512
575
|
},
|
|
513
576
|
async focusedKey() {
|
|
514
577
|
await start();
|
|
515
|
-
const { id } = shownNow(
|
|
578
|
+
const { id } = shownNow(kind);
|
|
516
579
|
if (!(await holdsKeyboard(isPane, id)))
|
|
517
580
|
return undefined;
|
|
518
|
-
if (focused?.part === `${
|
|
581
|
+
if (focused?.part === `${isPane ? 'pane' : 'sidebar'}:${id}`)
|
|
519
582
|
return focused.key;
|
|
520
583
|
const autoFocused = focusableKey((await draw()).drawing, (props) => props['autoFocus'] === true);
|
|
521
584
|
return isPane || autoFocused === undefined ? autoFocused : autoFocused.slice(`${name}/${id}:`.length);
|
|
@@ -544,6 +607,12 @@ export function testMod(definition, options = {}) {
|
|
|
544
607
|
checkKeys(drawing, name, component);
|
|
545
608
|
return { drawing, columns: defaultColumns };
|
|
546
609
|
};
|
|
610
|
+
const loadSettings = async (answer) => {
|
|
611
|
+
if (answer.block === undefined)
|
|
612
|
+
await lifecycle.settingsLoaded();
|
|
613
|
+
await fake.settle();
|
|
614
|
+
return answer;
|
|
615
|
+
};
|
|
547
616
|
const fire = ((event, input, below, signal) => {
|
|
548
617
|
if (event.includes('.'))
|
|
549
618
|
return route(event, input, below, signal);
|
|
@@ -570,6 +639,8 @@ export function testMod(definition, options = {}) {
|
|
|
570
639
|
const started = routed.then((answer) => ((answeredId = startedAs), answer));
|
|
571
640
|
return source === 'startup' || source === 'clear' ? started : started.then(async (answer) => (await tellHeldColor(), answer));
|
|
572
641
|
}
|
|
642
|
+
if (event === 'ConfigChange')
|
|
643
|
+
return route('classic.ConfigChange', filled, below, signal).then(loadSettings);
|
|
573
644
|
if (event !== 'PreToolUse')
|
|
574
645
|
return route(`classic.${event}`, filled, below, signal);
|
|
575
646
|
return firePreToolUse(filled, below);
|
|
@@ -673,7 +744,7 @@ export function testMod(definition, options = {}) {
|
|
|
673
744
|
}
|
|
674
745
|
const component = componentOf(target);
|
|
675
746
|
if (props === undefined || component === undefined)
|
|
676
|
-
throw new Error(`lines takes an area, such as AbovePrompt, or a row kind, such as ToolCall, with its props, and ${target} is neither. Read a pane with tested.shown.pane.lines() and a page with tested.shown.page.lines().`);
|
|
747
|
+
throw new Error(`lines takes an area, such as AbovePrompt, or a row kind, such as ToolCall, with its props, and ${target} is neither. Read a pane with tested.shown.pane.lines(), a view with tested.shown.view.lines(), and a page with tested.shown.page.lines().`);
|
|
677
748
|
const { drawing, columns } = await drawSlot(component, props, requestId);
|
|
678
749
|
return rowsOf(drawing, columns).map((row) => row.trimEnd());
|
|
679
750
|
},
|
|
@@ -750,27 +821,32 @@ export function testMod(definition, options = {}) {
|
|
|
750
821
|
return lifecycle.toasts;
|
|
751
822
|
},
|
|
752
823
|
sent: conversations.sent,
|
|
753
|
-
pane: shownPart(
|
|
754
|
-
|
|
824
|
+
pane: shownPart('pane'),
|
|
825
|
+
view: shownPart('view'),
|
|
826
|
+
page: shownPart('page'),
|
|
755
827
|
},
|
|
828
|
+
providers: given.map((_each, index) => fakeProvider(index)),
|
|
756
829
|
};
|
|
757
830
|
keepClaudeCode(tested, { fire });
|
|
758
831
|
return tested;
|
|
759
832
|
}
|
|
760
|
-
function fakeDependencies(caller, dependencies, conversations,
|
|
833
|
+
function fakeDependencies(caller, dependencies, conversations, served, sessionMods) {
|
|
761
834
|
const cmod = {
|
|
762
835
|
forkParent: () => null,
|
|
763
836
|
updateSettings: () => null,
|
|
764
|
-
[loadedMethod]: ({ name }) => name === caller || name === cmodPluginName || Object.hasOwn(dependencies, name),
|
|
765
|
-
[interfaceMethods.providers]: ({ name }) => ({ mods: provides().includes(name) ? [caller] : [], programs: [] }),
|
|
837
|
+
[loadedMethod]: ({ name }) => name === caller || name === cmodPluginName || Object.hasOwn(dependencies, name) || sessionMods.has(name),
|
|
766
838
|
};
|
|
767
839
|
const apis = { [cmodPluginName]: cmod, ...dependencies };
|
|
840
|
+
const provided = ({ to, method, input }) => (to === cmodPluginName ? served.answer(method, input, caller) : sessionMods.get(to)?.answer(method, input, caller, new AbortController().signal));
|
|
768
841
|
return async (call) => {
|
|
769
|
-
const
|
|
770
|
-
if (
|
|
771
|
-
return calledAnswer(caller,
|
|
842
|
+
const told = call.to === cmodPluginName ? conversations.answer(caller, call.method, call.input) : undefined;
|
|
843
|
+
if (told !== undefined)
|
|
844
|
+
return calledAnswer(caller, told);
|
|
845
|
+
const answered = provided(call);
|
|
846
|
+
if (answered !== undefined)
|
|
847
|
+
return calledAnswer(caller, await answered.then((value) => ({ value }), (error) => ({ deny: messageOf(error) })));
|
|
772
848
|
const api = apis[call.to];
|
|
773
|
-
return calledAnswer(caller, api === undefined ? { deny: notInstalled(call.to) } : await answerCall(call.to, api, call));
|
|
849
|
+
return calledAnswer(caller, api === undefined ? { deny: sessionMods.has(call.to) ? `${call.to} has no method ${call.method}.` : notInstalled(call.to) } : await answerCall(call.to, api, call));
|
|
774
850
|
};
|
|
775
851
|
}
|
|
776
852
|
function claudeCodeAnswer(event, e) {
|
package/ui/areas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Mod, Turn } from '../mod.js';
|
|
1
|
+
import type { Mod, Surface, Turn } from '../mod.js';
|
|
2
2
|
export declare const AbovePrompt = "abovePrompt";
|
|
3
3
|
export declare const BelowPrompt = "belowPrompt";
|
|
4
4
|
export declare const Working = "working";
|
|
@@ -9,10 +9,12 @@ export type Area = (typeof areas)[number];
|
|
|
9
9
|
export type WidgetContext = {
|
|
10
10
|
readonly area: typeof TurnEnd;
|
|
11
11
|
readonly columns: number;
|
|
12
|
+
readonly surface: Surface;
|
|
12
13
|
readonly turn: Turn;
|
|
13
14
|
} | {
|
|
14
15
|
readonly area: Exclude<Area, typeof TurnEnd>;
|
|
15
16
|
readonly columns: number;
|
|
17
|
+
readonly surface: Surface;
|
|
16
18
|
};
|
|
17
19
|
export type WidgetInit<State extends object = Record<never, never>> = {
|
|
18
20
|
readonly id: string;
|
package/ui/areas.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"areas.d.ts","sourceRoot":"","sources":["../src/ui/areas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;
|
|
1
|
+
{"version":3,"file":"areas.d.ts","sourceRoot":"","sources":["../src/ui/areas.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAEnD,eAAO,MAAM,WAAW,gBAAgB,CAAA;AACxC,eAAO,MAAM,WAAW,gBAAgB,CAAA;AACxC,eAAO,MAA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C,EAAE,EAAE,MAAM,CAAA;IACnB,QAAQ,CAAC,IAAI,EAAE,IAAI,GAAG,SAAS,CAAA;IAC/B,MAAM,IAAI,IAAI,CAAA;CACf,CAAA"}
|
package/ui/elements.d.ts
CHANGED
|
@@ -1,16 +1,25 @@
|
|
|
1
1
|
import type { BoxProps as ClaudeBoxProps, ButtonProps as ClaudeButtonProps, ClientProps as ClaudeClientProps, CodeProps as ClaudeCodeProps, Color as ClaudeColor, ElementConstructor, ElementTable, ImageProps as ClaudeImageProps, InputProps as ClaudeInputProps, MarkdownProps as ClaudeMarkdownProps, RasterProps as ClaudeRasterProps, RenderElement, RenderSurface, SelectProps as ClaudeSelectProps, SvgProps as ClaudeSvgProps, TextProps as ClaudeTextProps, UiPressArgument } from 'claude-code';
|
|
2
|
+
import type { Surface } from '../mod.js';
|
|
2
3
|
export type BoxProps = ClaudeBoxProps;
|
|
3
4
|
export type TextProps = ClaudeTextProps;
|
|
4
5
|
export type CodeProps = ClaudeCodeProps;
|
|
5
6
|
export type MarkdownProps = ClaudeMarkdownProps;
|
|
6
7
|
export type InputProps = ClaudeInputProps;
|
|
7
8
|
export type SelectProps = ClaudeSelectProps;
|
|
8
|
-
export type ImageProps = ClaudeImageProps
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
export type ImageProps = Omit<ClaudeImageProps, 'alt'> & {
|
|
10
|
+
readonly label: string;
|
|
11
|
+
};
|
|
12
|
+
export type SvgProps = Omit<ClaudeSvgProps, 'alt'> & {
|
|
13
|
+
readonly label: string;
|
|
14
|
+
};
|
|
15
|
+
export type RasterProps = ClaudeRasterProps & {
|
|
16
|
+
readonly label: string;
|
|
17
|
+
};
|
|
11
18
|
export type ClientProps = ClaudeClientProps;
|
|
12
19
|
export type Color = ClaudeColor;
|
|
13
|
-
export type Press = UiPressArgument
|
|
20
|
+
export type Press = Omit<UiPressArgument, 'surface'> & {
|
|
21
|
+
readonly surface: Surface;
|
|
22
|
+
};
|
|
14
23
|
export type ButtonProps = Omit<ClaudeButtonProps, 'onPress'> & ({
|
|
15
24
|
readonly onPress: (press: Press) => void;
|
|
16
25
|
readonly href?: never;
|
|
@@ -21,10 +30,10 @@ export type ButtonProps = Omit<ClaudeButtonProps, 'onPress'> & ({
|
|
|
21
30
|
export declare function drawWith<Drawn>(table: ElementTable, draw: () => Drawn, markdown?: (props: MarkdownProps) => RenderElement): Drawn;
|
|
22
31
|
export declare function drawKeyed<Drawn>(keyPrefix: string, draw: () => Drawn): Drawn;
|
|
23
32
|
export type Handler = (...args: unknown[]) => unknown;
|
|
24
|
-
export declare function elementData(value: unknown,
|
|
33
|
+
export declare function elementData(value: unknown, numberOf: (run: Handler) => number): unknown;
|
|
25
34
|
export declare function elementOf(data: unknown, keyPrefix: string, press: (handler: number, args: readonly unknown[]) => void): unknown;
|
|
26
35
|
export declare function drawsFocusable(data: unknown, key: string): boolean;
|
|
27
|
-
export declare function
|
|
36
|
+
export declare function forClaudeCode(table: ElementTable, surface: RenderSurface, open: (href: string, press: UiPressArgument) => void): ElementTable;
|
|
28
37
|
export declare const Box: ElementConstructor<ClaudeBoxProps>;
|
|
29
38
|
export declare const Text: ElementConstructor<ClaudeTextProps>;
|
|
30
39
|
export declare const Button: ElementConstructor<ButtonProps>;
|
|
@@ -32,8 +41,8 @@ export declare const Code: ElementConstructor<ClaudeCodeProps>;
|
|
|
32
41
|
export declare const Markdown: ElementConstructor<ClaudeMarkdownProps>;
|
|
33
42
|
export declare const Input: ElementConstructor<ClaudeInputProps>;
|
|
34
43
|
export declare const Select: ElementConstructor<ClaudeSelectProps>;
|
|
35
|
-
export declare const Image: ElementConstructor<
|
|
36
|
-
export declare const Svg: ElementConstructor<
|
|
37
|
-
export declare const Raster: ElementConstructor<
|
|
44
|
+
export declare const Image: ElementConstructor<ImageProps>;
|
|
45
|
+
export declare const Svg: ElementConstructor<SvgProps>;
|
|
46
|
+
export declare const Raster: ElementConstructor<RasterProps>;
|
|
38
47
|
export declare const Client: ElementConstructor<ClaudeClientProps>;
|
|
39
48
|
//# sourceMappingURL=elements.d.ts.map
|
package/ui/elements.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../src/ui/elements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,IAAI,cAAc,EAC1B,WAAW,IAAI,iBAAiB,EAChC,WAAW,IAAI,iBAAiB,EAChC,SAAS,IAAI,eAAe,EAC5B,KAAK,IAAI,WAAW,EACpB,kBAAkB,EAElB,YAAY,EAEZ,UAAU,IAAI,gBAAgB,EAC9B,UAAU,IAAI,gBAAgB,EAC9B,aAAa,IAAI,mBAAmB,EACpC,WAAW,IAAI,iBAAiB,EAChC,aAAa,EACb,aAAa,EACb,WAAW,IAAI,iBAAiB,EAChC,QAAQ,IAAI,cAAc,EAC1B,SAAS,IAAI,eAAe,EAC5B,eAAe,EAChB,MAAM,aAAa,CAAA;
|
|
1
|
+
{"version":3,"file":"elements.d.ts","sourceRoot":"","sources":["../src/ui/elements.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,QAAQ,IAAI,cAAc,EAC1B,WAAW,IAAI,iBAAiB,EAChC,WAAW,IAAI,iBAAiB,EAChC,SAAS,IAAI,eAAe,EAC5B,KAAK,IAAI,WAAW,EACpB,kBAAkB,EAElB,YAAY,EAEZ,UAAU,IAAI,gBAAgB,EAC9B,UAAU,IAAI,gBAAgB,EAC9B,aAAa,IAAI,mBAAmB,EACpC,WAAW,IAAI,iBAAiB,EAChC,aAAa,EACb,aAAa,EACb,WAAW,IAAI,iBAAiB,EAChC,QAAQ,IAAI,cAAc,EAC1B,SAAS,IAAI,eAAe,EAC5B,eAAe,EAChB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAExC,MAAM,MAAM,QAAQ,GAAG,cAAc,CAAA;AACrC,MAAM,MAAM,SAAS,GAAG,eAAe,CAAA;AACvC,MAAM,M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A;AACrF,eAAO,MAAM,MAAM,uCAAoB,CAAA"}
|
package/ui/elements.js
CHANGED
|
@@ -50,22 +50,22 @@ function keyed(value, keyPrefix) {
|
|
|
50
50
|
}
|
|
51
51
|
const elementKey = '$cmodElement';
|
|
52
52
|
const handlerKey = '$cmodHandler';
|
|
53
|
-
export function elementData(value,
|
|
53
|
+
export function elementData(value, numberOf) {
|
|
54
54
|
if (typeof value === 'function')
|
|
55
|
-
return { [handlerKey]:
|
|
55
|
+
return { [handlerKey]: numberOf(value) };
|
|
56
56
|
if (Array.isArray(value))
|
|
57
|
-
return value.map((each) => elementData(each,
|
|
57
|
+
return value.map((each) => elementData(each, numberOf));
|
|
58
58
|
if (typeof value !== 'object' || value === null)
|
|
59
59
|
return value;
|
|
60
60
|
if (unbuilt in value) {
|
|
61
61
|
const { name, props } = value[unbuilt];
|
|
62
62
|
if (name === 'Client')
|
|
63
63
|
throw new Error('Client draws only in panes and styles.');
|
|
64
|
-
return { [elementKey]: name, props: elementData(props,
|
|
64
|
+
return { [elementKey]: name, props: elementData(props, numberOf) };
|
|
65
65
|
}
|
|
66
66
|
if (Object.getPrototypeOf(value) !== Object.prototype)
|
|
67
67
|
throw new Error('a widget draws only the elements of ui/elements.js and ui/components.js, text, numbers, and plain objects.');
|
|
68
|
-
return Object.fromEntries(Object.entries(value).map(([key, each]) => [key, elementData(each,
|
|
68
|
+
return Object.fromEntries(Object.entries(value).map(([key, each]) => [key, elementData(each, numberOf)]));
|
|
69
69
|
}
|
|
70
70
|
export function elementOf(data, keyPrefix, press) {
|
|
71
71
|
if (Array.isArray(data))
|
|
@@ -97,8 +97,8 @@ export function drawsFocusable(data, key) {
|
|
|
97
97
|
return true;
|
|
98
98
|
return Object.values(fields).some((each) => drawsFocusable(each, key));
|
|
99
99
|
}
|
|
100
|
-
export function
|
|
101
|
-
const { Button: button, Link: link } = table;
|
|
100
|
+
export function forClaudeCode(table, surface, open) {
|
|
101
|
+
const { Button: button, Link: link, Image: image, Svg: svg, Raster: raster } = table;
|
|
102
102
|
const opening = (props) => {
|
|
103
103
|
const { href, ...rest } = props;
|
|
104
104
|
if (typeof href !== 'string')
|
|
@@ -109,7 +109,8 @@ export function withLinks(table, surface, open) {
|
|
|
109
109
|
return link({ href, ...(typeof label === 'string' ? { label } : {}), ...(hasChildren ? { children } : {}) });
|
|
110
110
|
return button({ ...rest, onPress: (press) => open(href, press) });
|
|
111
111
|
};
|
|
112
|
-
|
|
112
|
+
const named = (draw) => ({ label, ...rest }) => draw({ alt: label, ...rest });
|
|
113
|
+
return { ...table, Button: opening, Image: named(image), Svg: named(svg), Raster: ({ label, ...rest }) => raster(rest) };
|
|
113
114
|
}
|
|
114
115
|
export const Box = element('Box');
|
|
115
116
|
export const Text = element('Text');
|
package/ui/panes.d.ts
CHANGED
|
@@ -45,17 +45,18 @@ export type Pane<Params = undefined> = {
|
|
|
45
45
|
focus(key: string): Promise<void>;
|
|
46
46
|
remove(): void;
|
|
47
47
|
};
|
|
48
|
-
export type
|
|
48
|
+
export type ViewProps<Params> = {
|
|
49
49
|
readonly params: Params;
|
|
50
50
|
readonly isFocused: boolean;
|
|
51
51
|
readonly columns: number;
|
|
52
|
+
readonly surface: Surface;
|
|
52
53
|
};
|
|
53
|
-
export type
|
|
54
|
+
export type ViewInit<State extends object = Record<never, never>, Params = undefined> = {
|
|
54
55
|
readonly id: string;
|
|
55
56
|
readonly title: string;
|
|
56
|
-
render(mod: Mod<State>, props:
|
|
57
|
+
render(mod: Mod<State>, props: ViewProps<Params>): JSX.Element;
|
|
57
58
|
};
|
|
58
|
-
export type
|
|
59
|
+
export type View<Params = undefined> = {
|
|
59
60
|
readonly id: string;
|
|
60
61
|
readonly isOpen: boolean;
|
|
61
62
|
readonly isShown: boolean;
|
|
@@ -70,7 +71,10 @@ export type Page<Params = undefined> = {
|
|
|
70
71
|
focus(key: string): Promise<void>;
|
|
71
72
|
remove(): void;
|
|
72
73
|
};
|
|
74
|
+
export type PageProps<Params> = ViewProps<Params>;
|
|
75
|
+
export type PageInit<State extends object = Record<never, never>, Params = undefined> = ViewInit<State, Params>;
|
|
76
|
+
export type Page<Params = undefined> = View<Params>;
|
|
73
77
|
export declare const sizeKeys: readonly ['columns', 'rows'];
|
|
74
|
-
export declare function checkPart(name: string, kind: string, id: string, title: string): void;
|
|
75
|
-
export declare function checkPane<State extends object, Params>(name: string, pane: PaneInit<State, Params
|
|
78
|
+
export declare function checkPart(name: string, kind: string, id: string, title: string, takenBy: string | undefined): void;
|
|
79
|
+
export declare function checkPane<State extends object, Params>(name: string, pane: PaneInit<State, Params>, takenBy: string | undefined): void;
|
|
76
80
|
//# sourceMappingURL=panes.d.ts.map
|
package/ui/panes.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"panes.d.ts","sourceRoot":"","sources":["../src/ui/panes.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,cAAc,EAAE,aAAa,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AACvF,OAAO,KAAK,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AAE7C,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,aAAa,CAAC,CAAA;AAE9C,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC,CAAA;AAE9C,MAAM,MAAM,YAAY,GAAG,OAAO,GAAG,KAAK,GAAG;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;CAAE,CAAA;AAErE,MAAM,MAAM,aAAa,GAAG;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,GAAG,SAAS,CAAA;CAAE,CAAA;AAEvF,MAAM,MAAM,WAAW,CAAC,MAAM,IAAI;IAAE,QAAQ,CAAC,KAAK,CAAC,EAAE,IAAI,CAAA;CAAE,GAAG,CAAC,SAAS,SAAS,MAAM,GAAG;IAAE,QAAQ,CAAC,MAAM,CAAC,EAAE,MAA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@ -1,13 +1,15 @@
|
|
|
1
1
|
const partId = /^[A-Za-z0-9_-]{1,64}$/;
|
|
2
2
|
export const sizeKeys = ['columns', 'rows'];
|
|
3
|
-
export function checkPart(name, kind, id, title) {
|
|
3
|
+
export function checkPart(name, kind, id, title, takenBy) {
|
|
4
4
|
if (!partId.test(id))
|
|
5
5
|
throw new Error(`${name}: "${id}" is not a ${kind} id. Use 1 to 64 letters, digits, "_", or "-".`);
|
|
6
6
|
if (title.trim() === '')
|
|
7
7
|
throw new Error(`${name}: the ${kind} "${id}" needs a title, the label its tab shows.`);
|
|
8
|
+
if (takenBy !== undefined)
|
|
9
|
+
throw new Error(`${name}: the ${takenBy} "${id}" is already added. Give the ${kind} another id.`);
|
|
8
10
|
}
|
|
9
|
-
export function checkPane(name, pane) {
|
|
10
|
-
checkPart(name, 'pane', pane.id, pane.title);
|
|
11
|
+
export function checkPane(name, pane, takenBy) {
|
|
12
|
+
checkPart(name, 'pane', pane.id, pane.title, takenBy);
|
|
11
13
|
for (const key of sizeKeys) {
|
|
12
14
|
const size = pane[key];
|
|
13
15
|
if (typeof size !== 'function' && size !== undefined && (!Number.isInteger(size) || size <= 0))
|