@getcliqio/hug-frontend 0.0.0-stage → 1.15.32
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/README.md +31 -2
- package/dist/base_css.d.ts +6 -0
- package/dist/base_css.d.ts.map +1 -0
- package/dist/base_css.js +28 -0
- package/dist/base_css.js.map +1 -0
- package/dist/build.d.ts +45 -0
- package/dist/build.d.ts.map +1 -0
- package/dist/build.js +44 -0
- package/dist/build.js.map +1 -0
- package/dist/current.d.ts +10 -0
- package/dist/current.d.ts.map +1 -0
- package/dist/current.js +14 -0
- package/dist/current.js.map +1 -0
- package/dist/define.d.ts +12 -0
- package/dist/define.d.ts.map +1 -0
- package/dist/define.js +9 -0
- package/dist/define.js.map +1 -0
- package/dist/errors.d.ts +15 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +25 -0
- package/dist/errors.js.map +1 -0
- package/dist/host.d.ts +137 -0
- package/dist/host.d.ts.map +1 -0
- package/dist/host.js +368 -0
- package/dist/host.js.map +1 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +16 -0
- package/dist/index.js.map +1 -0
- package/dist/mount.d.ts +64 -0
- package/dist/mount.d.ts.map +1 -0
- package/dist/mount.js +106 -0
- package/dist/mount.js.map +1 -0
- package/dist/paths.d.ts +12 -0
- package/dist/paths.d.ts.map +1 -0
- package/dist/paths.js +42 -0
- package/dist/paths.js.map +1 -0
- package/dist/react.d.ts +63 -0
- package/dist/react.d.ts.map +1 -0
- package/dist/react.js +149 -0
- package/dist/react.js.map +1 -0
- package/dist/runtime.d.ts +140 -0
- package/dist/runtime.d.ts.map +1 -0
- package/dist/runtime.js +284 -0
- package/dist/runtime.js.map +1 -0
- package/dist/shared/bridge/index.d.ts +16 -0
- package/dist/shared/bridge/index.d.ts.map +1 -0
- package/dist/shared/bridge/index.js +14 -0
- package/dist/shared/bridge/index.js.map +1 -0
- package/dist/shared/bridge/messages.d.ts +559 -0
- package/dist/shared/bridge/messages.d.ts.map +1 -0
- package/dist/shared/bridge/messages.js +166 -0
- package/dist/shared/bridge/messages.js.map +1 -0
- package/dist/shared/context.d.ts +54 -0
- package/dist/shared/context.d.ts.map +1 -0
- package/dist/shared/context.js +28 -0
- package/dist/shared/context.js.map +1 -0
- package/dist/shared/define.d.ts +116 -0
- package/dist/shared/define.d.ts.map +1 -0
- package/dist/shared/define.js +120 -0
- package/dist/shared/define.js.map +1 -0
- package/dist/shared/definitions/approval.d.ts +216 -0
- package/dist/shared/definitions/approval.d.ts.map +1 -0
- package/dist/shared/definitions/approval.js +51 -0
- package/dist/shared/definitions/approval.js.map +1 -0
- package/dist/shared/definitions/common.d.ts +122 -0
- package/dist/shared/definitions/common.d.ts.map +1 -0
- package/dist/shared/definitions/common.js +71 -0
- package/dist/shared/definitions/common.js.map +1 -0
- package/dist/shared/definitions/form.d.ts +197 -0
- package/dist/shared/definitions/form.d.ts.map +1 -0
- package/dist/shared/definitions/form.js +30 -0
- package/dist/shared/definitions/form.js.map +1 -0
- package/dist/shared/definitions/index.d.ts +10 -0
- package/dist/shared/definitions/index.d.ts.map +1 -0
- package/dist/shared/definitions/index.js +9 -0
- package/dist/shared/definitions/index.js.map +1 -0
- package/dist/shared/problems.d.ts +35 -0
- package/dist/shared/problems.d.ts.map +1 -0
- package/dist/shared/problems.js +54 -0
- package/dist/shared/problems.js.map +1 -0
- package/dist/shared/requested_inputs.d.ts +190 -0
- package/dist/shared/requested_inputs.d.ts.map +1 -0
- package/dist/shared/requested_inputs.js +221 -0
- package/dist/shared/requested_inputs.js.map +1 -0
- package/dist/shared/schema_for_inputs.d.ts +20 -0
- package/dist/shared/schema_for_inputs.d.ts.map +1 -0
- package/dist/shared/schema_for_inputs.js +96 -0
- package/dist/shared/schema_for_inputs.js.map +1 -0
- package/dist/state.d.ts +58 -0
- package/dist/state.d.ts.map +1 -0
- package/dist/state.js +124 -0
- package/dist/state.js.map +1 -0
- package/dist/testing.d.ts +96 -0
- package/dist/testing.d.ts.map +1 -0
- package/dist/testing.js +156 -0
- package/dist/testing.js.map +1 -0
- package/dist/theme.d.ts +15 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/theme.js +18 -0
- package/dist/theme.js.map +1 -0
- package/dist/transport.d.ts +19 -0
- package/dist/transport.d.ts.map +1 -0
- package/dist/transport.js +21 -0
- package/dist/transport.js.map +1 -0
- package/dist/ui/base.d.ts +33 -0
- package/dist/ui/base.d.ts.map +1 -0
- package/dist/ui/base.js +99 -0
- package/dist/ui/base.js.map +1 -0
- package/dist/ui/choices.d.ts +46 -0
- package/dist/ui/choices.d.ts.map +1 -0
- package/dist/ui/choices.js +121 -0
- package/dist/ui/choices.js.map +1 -0
- package/dist/ui/fields.d.ts +46 -0
- package/dist/ui/fields.d.ts.map +1 -0
- package/dist/ui/fields.js +169 -0
- package/dist/ui/fields.js.map +1 -0
- package/dist/ui/files.d.ts +80 -0
- package/dist/ui/files.d.ts.map +1 -0
- package/dist/ui/files.js +342 -0
- package/dist/ui/files.js.map +1 -0
- package/dist/ui/fonts.css +7 -0
- package/dist/ui/fonts_css.d.ts +3 -0
- package/dist/ui/fonts_css.d.ts.map +1 -0
- package/dist/ui/fonts_css.js +4 -0
- package/dist/ui/fonts_css.js.map +1 -0
- package/dist/ui/index.d.ts +24 -0
- package/dist/ui/index.d.ts.map +1 -0
- package/dist/ui/index.js +32 -0
- package/dist/ui/index.js.map +1 -0
- package/dist/ui/markdown.d.ts +46 -0
- package/dist/ui/markdown.d.ts.map +1 -0
- package/dist/ui/markdown.js +318 -0
- package/dist/ui/markdown.js.map +1 -0
- package/dist/view.d.ts +49 -0
- package/dist/view.d.ts.map +1 -0
- package/dist/view.js +136 -0
- package/dist/view.js.map +1 -0
- package/dist/zod_config.d.ts +2 -0
- package/dist/zod_config.d.ts.map +1 -0
- package/dist/zod_config.js +10 -0
- package/dist/zod_config.js.map +1 -0
- package/fonts/LICENSE.txt +92 -0
- package/package.json +82 -5
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@getcliqio/hug-frontend/testing` — a host for unit tests (PLAN-hug-widgets §9.2.9). It answers `ready` with an
|
|
3
|
+
* `init` built from the options, records what the frontend sends, and plays the host's part: Submit, "Change answer",
|
|
4
|
+
* closing, uploads and file reads. Like the real hosts it checks every message against the bridge (`issues` lists
|
|
5
|
+
* what a host would refuse, and those aren't acted on) and won't submit an answer the hug says isn't valid.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const host = mock_host({ definition: review_batch, params: { … } });
|
|
9
|
+
* await mount_hug(review_batch, { edit, connect: { transport: host.transport } });
|
|
10
|
+
* await host.flush();
|
|
11
|
+
* expect(host.last_values()?.valid).toBe(false);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import type { HugErrorCode } from './errors.js';
|
|
15
|
+
import type { Answer, FileRef, HugInfo, HugStatus, Mode, Transport, Values, Viewer } from './index.js';
|
|
16
|
+
import type { FileSlot, HugDefinition } from './shared/define.js';
|
|
17
|
+
import type { Problem } from './shared/problems.js';
|
|
18
|
+
/** What the host starts the hug with. */
|
|
19
|
+
export interface MockHostOptions<P = unknown, V extends Values = Values> {
|
|
20
|
+
/** Fills `hug.name`, `hug.title` and `files` (from `files(params)`). */
|
|
21
|
+
readonly definition?: HugDefinition<P, V>;
|
|
22
|
+
readonly params?: P;
|
|
23
|
+
readonly mode?: Mode;
|
|
24
|
+
readonly status?: HugStatus;
|
|
25
|
+
readonly mine?: Answer<V> | null;
|
|
26
|
+
readonly viewing?: Answer<V> | null;
|
|
27
|
+
readonly draft?: Partial<V> | null;
|
|
28
|
+
readonly files?: readonly FileSlot[];
|
|
29
|
+
readonly attachments?: readonly FileRef[];
|
|
30
|
+
readonly viewer?: Viewer;
|
|
31
|
+
readonly hug?: Partial<HugInfo>;
|
|
32
|
+
readonly progress?: string | null;
|
|
33
|
+
readonly theme?: {
|
|
34
|
+
scheme: 'light' | 'dark';
|
|
35
|
+
tokens: Record<string, string>;
|
|
36
|
+
};
|
|
37
|
+
readonly locale?: string;
|
|
38
|
+
readonly protocols?: readonly number[];
|
|
39
|
+
/** The person's pick for an upload slot: a file reference, or an error code (`upload_cancelled`, …). */
|
|
40
|
+
readonly upload?: (key: string) => FileRef | HugErrorCode | Promise<FileRef | HugErrorCode>;
|
|
41
|
+
/** A file's bytes, or an error code (`read_denied`, …). Default: a small text Blob. */
|
|
42
|
+
readonly read?: (ref: FileRef) => Blob | HugErrorCode | Promise<Blob | HugErrorCode>;
|
|
43
|
+
}
|
|
44
|
+
/** What the frontend last said about its answer. */
|
|
45
|
+
export interface SentValues<V extends Values = Values> {
|
|
46
|
+
readonly values: V;
|
|
47
|
+
readonly valid: boolean;
|
|
48
|
+
readonly problems?: readonly Problem[];
|
|
49
|
+
readonly submit?: {
|
|
50
|
+
readonly label: string;
|
|
51
|
+
readonly tone?: 'primary' | 'danger';
|
|
52
|
+
};
|
|
53
|
+
readonly summary?: string;
|
|
54
|
+
}
|
|
55
|
+
/** The test host. */
|
|
56
|
+
export interface MockHost<V extends Values = Values> {
|
|
57
|
+
/** Pass to `connect({ transport })` or `mount_hug(def, { connect: { transport } })`. */
|
|
58
|
+
readonly transport: Transport;
|
|
59
|
+
/** Every message the frontend sent that a host would take, in order. */
|
|
60
|
+
readonly sent: ReadonlyArray<Record<string, unknown> & {
|
|
61
|
+
type: string;
|
|
62
|
+
}>;
|
|
63
|
+
/** What a host would refuse (a message that breaks the bridge's rules), with why — empty when all is well. */
|
|
64
|
+
readonly issues: ReadonlyArray<{
|
|
65
|
+
readonly reason: string;
|
|
66
|
+
readonly message: unknown;
|
|
67
|
+
}>;
|
|
68
|
+
/** The frontend's latest answer state, or null. */
|
|
69
|
+
last_values(): SentValues<V> | null;
|
|
70
|
+
readonly downloads: readonly FileRef[];
|
|
71
|
+
readonly links: readonly string[];
|
|
72
|
+
/** The frame's latest height. */
|
|
73
|
+
height(): number | null;
|
|
74
|
+
/** Wait for throttled messages and pending replies. */
|
|
75
|
+
flush(): Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* Press Submit: the latest values are accepted (or `problems` are returned), then the answer is shown read-only.
|
|
78
|
+
* Refused, as by a real host, when there's nothing to submit or the hug said the answer isn't valid.
|
|
79
|
+
*/
|
|
80
|
+
submit(opts?: {
|
|
81
|
+
problems?: readonly Problem[];
|
|
82
|
+
responder?: Viewer;
|
|
83
|
+
}): Promise<void>;
|
|
84
|
+
/** Press "Change answer": back to answer mode, starting from this viewer's answer. */
|
|
85
|
+
change_answer(): Promise<void>;
|
|
86
|
+
/** The Hug closes (or expires, or is cancelled): view mode. */
|
|
87
|
+
close(status?: Exclude<HugStatus, 'open'>, viewing?: Answer<V> | null): Promise<void>;
|
|
88
|
+
/** The requester's progress or expiry changes. */
|
|
89
|
+
update(u: {
|
|
90
|
+
progress?: string | null;
|
|
91
|
+
expires_at?: string | null;
|
|
92
|
+
}): Promise<void>;
|
|
93
|
+
}
|
|
94
|
+
/** A host for unit tests. */
|
|
95
|
+
export declare function mock_host<P = unknown, V extends Values = Values>(opts?: MockHostOptions<P, V>): MockHost<V>;
|
|
96
|
+
//# sourceMappingURL=testing.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.d.ts","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAChD,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAEvG,OAAO,KAAK,EAAE,QAAQ,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAClE,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,sBAAsB,CAAC;AAEpD,yCAAyC;AACzC,MAAM,WAAW,eAAe,CAA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EAAE,CAAC;IAClC,iCAAiC;IACjC,MAAM,IAAI,MAAM,GAAG,IAAI,CAAC;IACxB,uDAAuD;IACvD,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IACvB;;;OAGG;IACH,MAAM,CAAC,IAAI,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,SAAS,OAAO,EAAE,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACpF,sFAAsF;IACtF,aAAa,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAC/B,+DAA+D;IAC/D,KAAK,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,SAAS,EAAE,MAAM,CAAC,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IACtF,kDAAkD;IAClD,MAAM,CAAC,CAAC,EAAE;QAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;KAAE,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACtF;AAgBD,6BAA6B;AAC7B,wBAAgB,SAAS,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,IAAI,GAAE,eAAe,CAAC,CAAC,EAAE,CAAC,CAAM,GAAG,QAAQ,CAAC,CAAC,CAAC,CAkH/G"}
|
package/dist/testing.js
ADDED
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@getcliqio/hug-frontend/testing` — a host for unit tests (PLAN-hug-widgets §9.2.9). It answers `ready` with an
|
|
3
|
+
* `init` built from the options, records what the frontend sends, and plays the host's part: Submit, "Change answer",
|
|
4
|
+
* closing, uploads and file reads. Like the real hosts it checks every message against the bridge (`issues` lists
|
|
5
|
+
* what a host would refuse, and those aren't acted on) and won't submit an answer the hug says isn't valid.
|
|
6
|
+
*
|
|
7
|
+
* ```ts
|
|
8
|
+
* const host = mock_host({ definition: review_batch, params: { … } });
|
|
9
|
+
* await mount_hug(review_batch, { edit, connect: { transport: host.transport } });
|
|
10
|
+
* await host.flush();
|
|
11
|
+
* expect(host.last_values()?.valid).toBe(false);
|
|
12
|
+
* ```
|
|
13
|
+
*/
|
|
14
|
+
import { BRIDGE_VERSION, MAX_VALUES_PER_SECOND, parse_frame_message } from './shared/bridge/messages.js';
|
|
15
|
+
function last_of(list, type) {
|
|
16
|
+
for (let i = list.length - 1; i >= 0; i--)
|
|
17
|
+
if (list[i].type === type)
|
|
18
|
+
return list[i];
|
|
19
|
+
return undefined;
|
|
20
|
+
}
|
|
21
|
+
const FLUSH_MS = Math.ceil(1000 / MAX_VALUES_PER_SECOND) + 10;
|
|
22
|
+
/** Why a Submit is refused: the problems the test gave, else nothing to submit, else the page's own problems. */
|
|
23
|
+
function refusal(given, state) {
|
|
24
|
+
if (given?.length)
|
|
25
|
+
return given;
|
|
26
|
+
if (!state)
|
|
27
|
+
return [{ message: 'nothing to submit' }];
|
|
28
|
+
return state.problems?.length ? state.problems : [{ message: 'the answer is not valid' }];
|
|
29
|
+
}
|
|
30
|
+
/** A host for unit tests. */
|
|
31
|
+
export function mock_host(opts = {}) {
|
|
32
|
+
const sent = [];
|
|
33
|
+
const issues = [];
|
|
34
|
+
const downloads = [];
|
|
35
|
+
const links = [];
|
|
36
|
+
const listeners = new Set();
|
|
37
|
+
const pending = [];
|
|
38
|
+
let mine = opts.mine ?? null;
|
|
39
|
+
const params = opts.params ?? {};
|
|
40
|
+
const deliver = (message) => {
|
|
41
|
+
const data = { v: BRIDGE_VERSION, ...message };
|
|
42
|
+
for (const fn of [...listeners])
|
|
43
|
+
fn(data);
|
|
44
|
+
};
|
|
45
|
+
const later = (work) => {
|
|
46
|
+
pending.push(Promise.resolve().then(work));
|
|
47
|
+
};
|
|
48
|
+
const checked = opts.definition?.check_params(params);
|
|
49
|
+
const files = opts.files ?? (checked?.ok ? opts.definition.files(checked.value) : []);
|
|
50
|
+
const init = () => ({
|
|
51
|
+
type: 'init', protocols: [...(opts.protocols ?? [BRIDGE_VERSION])],
|
|
52
|
+
hug: {
|
|
53
|
+
id: 'hug_test', name: opts.definition?.name ?? 'test', title: opts.definition?.title ?? 'Test',
|
|
54
|
+
status: opts.status ?? 'open', expires_at: null, requester: 'test-agent', run: null, ...opts.hug,
|
|
55
|
+
},
|
|
56
|
+
params, files: files.map((f) => ({ ...f, ...(f.accept ? { accept: [...f.accept] } : {}) })),
|
|
57
|
+
attachments: [...(opts.attachments ?? [])],
|
|
58
|
+
viewer: opts.viewer ?? { name: 'Tester', via: ['test'] },
|
|
59
|
+
mine, viewing: opts.viewing ?? null, draft: opts.draft ?? null,
|
|
60
|
+
progress: opts.progress ?? null,
|
|
61
|
+
theme: opts.theme ?? { scheme: 'light', tokens: {} },
|
|
62
|
+
locale: opts.locale ?? 'en-US',
|
|
63
|
+
mode: opts.mode ?? (opts.status && opts.status !== 'open' ? 'view' : 'answer'),
|
|
64
|
+
});
|
|
65
|
+
const answer_upload = (id, key) => later(async () => {
|
|
66
|
+
const picked = opts.upload ? await opts.upload(key) : 'upload_cancelled';
|
|
67
|
+
deliver(typeof picked === 'string'
|
|
68
|
+
? { type: 'upload_result', id, ok: false, error: picked }
|
|
69
|
+
: { type: 'upload_result', id, ok: true, ref: picked });
|
|
70
|
+
});
|
|
71
|
+
const answer_read = (id, ref) => later(async () => {
|
|
72
|
+
const got = opts.read ? await opts.read(ref) : new Blob([`contents of ${ref.name}`], { type: ref.content_type });
|
|
73
|
+
deliver(typeof got === 'string' ? { type: 'file', id, ok: false, error: got } : { type: 'file', id, ok: true, blob: got });
|
|
74
|
+
});
|
|
75
|
+
const transport = {
|
|
76
|
+
attached: true,
|
|
77
|
+
send(raw) {
|
|
78
|
+
// The bridge's own check, as a host makes it: a message it would refuse is recorded, not acted on.
|
|
79
|
+
const parsed = parse_frame_message(raw);
|
|
80
|
+
if (!parsed.ok) {
|
|
81
|
+
issues.push({ reason: parsed.reason, message: raw });
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
const message = raw;
|
|
85
|
+
sent.push(message);
|
|
86
|
+
switch (message.type) {
|
|
87
|
+
case 'ready':
|
|
88
|
+
later(() => deliver(init()));
|
|
89
|
+
break;
|
|
90
|
+
case 'upload':
|
|
91
|
+
answer_upload(message.id, message.key);
|
|
92
|
+
break;
|
|
93
|
+
case 'read_file':
|
|
94
|
+
answer_read(message.id, message.ref);
|
|
95
|
+
break;
|
|
96
|
+
case 'download':
|
|
97
|
+
downloads.push(message.ref);
|
|
98
|
+
break;
|
|
99
|
+
case 'open_link':
|
|
100
|
+
links.push(message.url);
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
},
|
|
104
|
+
listen(handler) {
|
|
105
|
+
listeners.add(handler);
|
|
106
|
+
return () => { listeners.delete(handler); };
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
const last_values = () => {
|
|
110
|
+
const m = last_of(sent, 'values');
|
|
111
|
+
if (!m)
|
|
112
|
+
return null;
|
|
113
|
+
const state = { ...m };
|
|
114
|
+
delete state.v;
|
|
115
|
+
delete state.type;
|
|
116
|
+
return state;
|
|
117
|
+
};
|
|
118
|
+
const flush = async () => {
|
|
119
|
+
await new Promise((r) => setTimeout(r, FLUSH_MS));
|
|
120
|
+
while (pending.length)
|
|
121
|
+
await Promise.all(pending.splice(0));
|
|
122
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
transport, sent, issues, downloads, links, last_values, flush,
|
|
126
|
+
height: () => last_of(sent, 'resize')?.height ?? null,
|
|
127
|
+
async submit(o = {}) {
|
|
128
|
+
await flush();
|
|
129
|
+
const state = last_values();
|
|
130
|
+
if (o.problems?.length || !state || !state.valid) {
|
|
131
|
+
deliver({ type: 'submit_result', ok: false, problems: [...refusal(o.problems, state)] });
|
|
132
|
+
return flush();
|
|
133
|
+
}
|
|
134
|
+
mine = {
|
|
135
|
+
values: state.values, ...(state.summary ? { summary: state.summary } : {}),
|
|
136
|
+
responder: o.responder ?? opts.viewer ?? { name: 'Tester', via: ['test'] }, responded_at: new Date().toISOString(),
|
|
137
|
+
};
|
|
138
|
+
deliver({ type: 'submit_result', ok: true, answer: mine });
|
|
139
|
+
deliver({ type: 'mode', mode: 'view', viewing: mine, mine, draft: null });
|
|
140
|
+
return flush();
|
|
141
|
+
},
|
|
142
|
+
async change_answer() {
|
|
143
|
+
deliver({ type: 'mode', mode: 'answer', viewing: null, mine, draft: null });
|
|
144
|
+
return flush();
|
|
145
|
+
},
|
|
146
|
+
async close(status = 'closed', viewing = mine) {
|
|
147
|
+
deliver({ type: 'status', status, mode: 'view', viewing });
|
|
148
|
+
return flush();
|
|
149
|
+
},
|
|
150
|
+
async update(u) {
|
|
151
|
+
deliver({ type: 'update', ...u });
|
|
152
|
+
return flush();
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sourceRoot":"","sources":["../src/testing.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAIH,OAAO,EAAE,cAAc,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAkEzG,SAAS,OAAO,CAA6B,IAAkB,EAAE,IAAY;IACzE,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE;QAAE,IAAI,IAAI,CAAC,CAAC,CAAE,CAAC,IAAI,KAAK,IAAI;YAAE,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC;IACtF,OAAO,SAAS,CAAC;AACrB,CAAC;AAED,MAAM,QAAQ,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,GAAG,qBA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EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC;YAC5E,OAAO,KAAK,EAAE,CAAC;QACnB,CAAC;QACD,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,QAAQ,EAAE,OAAO,GAAG,IAAI;YACzC,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;YAC3D,OAAO,KAAK,EAAE,CAAC;QACnB,CAAC;QACD,KAAK,CAAC,MAAM,CAAC,CAAC;YACV,OAAO,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,CAAC;YAClC,OAAO,KAAK,EAAE,CAAC;QACnB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Hub's theme in a frame (PLAN-hug-widgets §9.2.6): CSS variables matching the Hub's tokens (`--cliq-bg`,
|
|
3
|
+
* `--cliq-ink`, `--cliq-acc`, …) and the scheme (light or dark), as the host sends them in `init`.
|
|
4
|
+
*/
|
|
5
|
+
import type { BridgeTheme } from './shared/bridge/messages.js';
|
|
6
|
+
/** The theme, and a way to put it on an element. */
|
|
7
|
+
export interface Theme {
|
|
8
|
+
readonly scheme: 'light' | 'dark';
|
|
9
|
+
readonly tokens: Readonly<Record<string, string>>;
|
|
10
|
+
/** Set the tokens as CSS variables on `el` (default: the document element), and `data-cliq-scheme`. */
|
|
11
|
+
apply(el?: HTMLElement): void;
|
|
12
|
+
}
|
|
13
|
+
/** A theme from the host's `init`. */
|
|
14
|
+
export declare function make_theme(raw: BridgeTheme): Theme;
|
|
15
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAE/D,oDAAoD;AACpD,MAAM,WAAW,KAAK;IAClB,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,MAAM,CAAC;IAClC,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IAClD,uGAAuG;IACvG,KAAK,CAAC,EAAE,CAAC,EAAE,WAAW,GAAG,IAAI,CAAC;CACjC;AAED,sCAAsC;AACtC,wBAAgB,UAAU,CAAC,GAAG,EAAE,WAAW,GAAG,KAAK,CAUlD"}
|
package/dist/theme.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Hub's theme in a frame (PLAN-hug-widgets §9.2.6): CSS variables matching the Hub's tokens (`--cliq-bg`,
|
|
3
|
+
* `--cliq-ink`, `--cliq-acc`, …) and the scheme (light or dark), as the host sends them in `init`.
|
|
4
|
+
*/
|
|
5
|
+
/** A theme from the host's `init`. */
|
|
6
|
+
export function make_theme(raw) {
|
|
7
|
+
return {
|
|
8
|
+
scheme: raw.scheme,
|
|
9
|
+
tokens: { ...raw.tokens },
|
|
10
|
+
apply(el = document.documentElement) {
|
|
11
|
+
for (const [name, value] of Object.entries(raw.tokens))
|
|
12
|
+
el.style.setProperty(name, value);
|
|
13
|
+
el.dataset.cliqScheme = raw.scheme;
|
|
14
|
+
el.style.colorScheme = raw.scheme;
|
|
15
|
+
},
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=theme.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.js","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH,sCAAsC;AACtC,MAAM,UAAU,UAAU,CAAC,GAAgB;IACvC,OAAO;QACH,MAAM,EAAE,GAAG,CAAC,MAAM;QAClB,MAAM,EAAE,EAAE,GAAG,GAAG,CAAC,MAAM,EAAE;QACzB,KAAK,CAAC,EAAE,GAAG,QAAQ,CAAC,eAAe;YAC/B,KAAK,MAAM,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC;gBAAE,EAAE,CAAC,KAAK,CAAC,WAAW,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;YAC1F,EAAE,CAAC,OAAO,CAAC,UAAU,GAAG,GAAG,CAAC,MAAM,CAAC;YACnC,EAAE,CAAC,KAAK,CAAC,WAAW,GAAG,GAAG,CAAC,MAAM,CAAC;QACtC,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the runtime talks to its host. In a real page that's `postMessage` with the parent window — the Hub page, or
|
|
3
|
+
* cliqd's local page — and only messages from the parent are heard. Tests pass their own (the test host, §9.2.9).
|
|
4
|
+
*/
|
|
5
|
+
/** A two-way channel to the host. */
|
|
6
|
+
export interface Transport {
|
|
7
|
+
/** True when there is a host to talk to (the page is framed, or a test host is attached). */
|
|
8
|
+
readonly attached: boolean;
|
|
9
|
+
/** Send a message to the host (Blobs and other transferables go by structured clone). */
|
|
10
|
+
send(message: unknown): void;
|
|
11
|
+
/** Listen to the host's messages; returns a function that stops listening. */
|
|
12
|
+
listen(handler: (data: unknown) => void): () => void;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The transport of a framed page: messages go to `window.parent`; only messages whose source is the parent are heard.
|
|
16
|
+
* A frame's origin is opaque (`"null"`), so messages are addressed to `'*'`; the host checks they came from its frame.
|
|
17
|
+
*/
|
|
18
|
+
export declare function window_transport(win?: Window): Transport;
|
|
19
|
+
//# sourceMappingURL=transport.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.d.ts","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,qCAAqC;AACrC,MAAM,WAAW,SAAS;IACtB,6FAA6F;IAC7F,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;IAC3B,yFAAyF;IACzF,IAAI,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC;IAC7B,8EAA8E;IAC9E,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,EAAE,OAAO,KAAK,IAAI,GAAG,MAAM,IAAI,CAAC;CACxD;AAED;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,GAAG,GAAE,MAAe,GAAG,SAAS,CAUhE"}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How the runtime talks to its host. In a real page that's `postMessage` with the parent window — the Hub page, or
|
|
3
|
+
* cliqd's local page — and only messages from the parent are heard. Tests pass their own (the test host, §9.2.9).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The transport of a framed page: messages go to `window.parent`; only messages whose source is the parent are heard.
|
|
7
|
+
* A frame's origin is opaque (`"null"`), so messages are addressed to `'*'`; the host checks they came from its frame.
|
|
8
|
+
*/
|
|
9
|
+
export function window_transport(win = window) {
|
|
10
|
+
return {
|
|
11
|
+
attached: win.parent !== win,
|
|
12
|
+
send: (message) => win.parent.postMessage(message, '*'),
|
|
13
|
+
listen(handler) {
|
|
14
|
+
const on = (e) => { if (e.source === win.parent)
|
|
15
|
+
handler(e.data); };
|
|
16
|
+
win.addEventListener('message', on);
|
|
17
|
+
return () => win.removeEventListener('message', on);
|
|
18
|
+
},
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=transport.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transport.js","sourceRoot":"","sources":["../src/transport.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAYH;;;GAGG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAc,MAAM;IACjD,OAAO;QACH,QAAQ,EAAE,GAAG,CAAC,MAAM,KAAK,GAAG;QAC5B,IAAI,EAAE,CAAC,OAAO,EAAE,EAAE,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,EAAE,GAAG,CAAC;QACvD,MAAM,CAAC,OAAO;YACV,MAAM,EAAE,GAAG,CAAC,CAAe,EAAE,EAAE,GAAG,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,MAAM;gBAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;YAClF,GAAG,CAAC,gBAAgB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;YACpC,OAAO,GAAG,EAAE,CAAC,GAAG,CAAC,mBAAmB,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QACxD,CAAC;KACJ,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The UI kit's base element (PLAN-hug-widgets §9.2.5): a custom element that draws with lit-html into its shadow root,
|
|
3
|
+
* redraws when a property changes, and emits `change` events that cross shadow boundaries. Themed by the runtime's
|
|
4
|
+
* `--cliq-*` variables, which inherit into shadow roots.
|
|
5
|
+
*/
|
|
6
|
+
/** Styles every kit element shares: type, controls, labels, problems. */
|
|
7
|
+
export declare const KIT_CSS = "\n:host { display: block; font: 14px/1.5 Geist, system-ui, sans-serif; color: var(--cliq-ink, CanvasText); }\n:host([hidden]) { display: none; }\n* { box-sizing: border-box; }\n.label { display: block; font-weight: 500; margin-bottom: 4px; }\n.req { color: var(--cliq-bad, #c33); margin-left: 2px; }\n.help { color: var(--cliq-ink-2, GrayText); font-size: 13px; margin: 0 0 6px; }\n.problem { color: var(--cliq-bad, #c33); font-size: 13px; margin-top: 4px; }\ninput[type=text], input[type=number], textarea, select {\n width: 100%; font: inherit; color: inherit; background: var(--cliq-panel, Field);\n border: 1px solid var(--cliq-line, #ccc); border-radius: var(--cliq-radius, 6px); padding: 6px 8px; }\ntextarea { min-height: 80px; resize: vertical; }\n[aria-invalid=true] { border-color: var(--cliq-bad, #c33); }\n:focus-visible { outline: 2px solid var(--cliq-acc, Highlight); outline-offset: 1px; }\nbutton { font: inherit; color: inherit; background: var(--cliq-panel, ButtonFace); border: 1px solid var(--cliq-line, #ccc);\n border-radius: var(--cliq-radius, 6px); padding: 5px 10px; cursor: pointer; }\nbutton:disabled { opacity: .6; cursor: default; }\n.link { background: none; border: 0; padding: 0; color: var(--cliq-acc, LinkText); text-decoration: underline; }\n.muted { color: var(--cliq-ink-3, GrayText); }\n";
|
|
8
|
+
/** A kit element: lit-html into an open shadow root. */
|
|
9
|
+
export declare abstract class KitElement extends HTMLElement {
|
|
10
|
+
protected readonly root: ShadowRoot;
|
|
11
|
+
private readonly container;
|
|
12
|
+
private queued;
|
|
13
|
+
constructor(css?: string);
|
|
14
|
+
connectedCallback(): void;
|
|
15
|
+
/** What the element draws. */
|
|
16
|
+
protected abstract template(): unknown;
|
|
17
|
+
/** Redraw (batched to one per task). */
|
|
18
|
+
protected request_draw(): void;
|
|
19
|
+
/** Redraw now. */
|
|
20
|
+
draw(): void;
|
|
21
|
+
/** Emit `change` with a value. */
|
|
22
|
+
protected emit(detail: unknown): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Declares reactive properties: setting one redraws. `attrs` also read from attributes of the same name
|
|
26
|
+
* (`label="Why"`, `multiline`).
|
|
27
|
+
*/
|
|
28
|
+
export declare function reactive(cls: typeof KitElement, props: readonly string[], attrs?: readonly string[]): void;
|
|
29
|
+
/** Defines an element once (a page may import the kit twice). */
|
|
30
|
+
export declare function define_element(name: string, cls: CustomElementConstructor): void;
|
|
31
|
+
/** A page-unique id for label/control pairs inside a shadow root. */
|
|
32
|
+
export declare function uid(prefix: string): string;
|
|
33
|
+
//# sourceMappingURL=base.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/ui/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,yEAAyE;AACzE,eAAO,MAAM,OAAO,qzCAmBnB,CAAC;AAEF,wDAAwD;AACxD,8BAAsB,UAAW,SAAQ,WAAW;IAChD,SAAS,CAAC,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAc;IACxC,OAAO,CAAC,MAAM,CAAS;gBAEX,GAAG,SAAK;IAUpB,iBAAiB,IAAI,IAAI;IAIzB,8BAA8B;IAC9B,SAAS,CAAC,QAAQ,CAAC,QAAQ,IAAI,OAAO;IAEtC,wCAAwC;IACxC,SAAS,CAAC,YAAY,IAAI,IAAI;IAM9B,kBAAkB;IAClB,IAAI,IAAI,IAAI;IAIZ,kCAAkC;IAClC,SAAS,CAAC,IAAI,CAAC,MAAM,EAAE,OAAO,GAAG,IAAI;CAGxC;AAED;;;GAGG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,OAAO,UAAU,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,GAAE,SAAS,MAAM,EAAO,GAAG,IAAI,CAoB9G;AAED,iEAAiE;AACjE,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,EAAE,wBAAwB,GAAG,IAAI,CAEhF;AAGD,qEAAqE;AACrE,wBAAgB,GAAG,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG1C"}
|
package/dist/ui/base.js
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The UI kit's base element (PLAN-hug-widgets §9.2.5): a custom element that draws with lit-html into its shadow root,
|
|
3
|
+
* redraws when a property changes, and emits `change` events that cross shadow boundaries. Themed by the runtime's
|
|
4
|
+
* `--cliq-*` variables, which inherit into shadow roots.
|
|
5
|
+
*/
|
|
6
|
+
import { render } from 'lit-html';
|
|
7
|
+
/** Styles every kit element shares: type, controls, labels, problems. */
|
|
8
|
+
export const KIT_CSS = `
|
|
9
|
+
:host { display: block; font: 14px/1.5 Geist, system-ui, sans-serif; color: var(--cliq-ink, CanvasText); }
|
|
10
|
+
:host([hidden]) { display: none; }
|
|
11
|
+
* { box-sizing: border-box; }
|
|
12
|
+
.label { display: block; font-weight: 500; margin-bottom: 4px; }
|
|
13
|
+
.req { color: var(--cliq-bad, #c33); margin-left: 2px; }
|
|
14
|
+
.help { color: var(--cliq-ink-2, GrayText); font-size: 13px; margin: 0 0 6px; }
|
|
15
|
+
.problem { color: var(--cliq-bad, #c33); font-size: 13px; margin-top: 4px; }
|
|
16
|
+
input[type=text], input[type=number], textarea, select {
|
|
17
|
+
width: 100%; font: inherit; color: inherit; background: var(--cliq-panel, Field);
|
|
18
|
+
border: 1px solid var(--cliq-line, #ccc); border-radius: var(--cliq-radius, 6px); padding: 6px 8px; }
|
|
19
|
+
textarea { min-height: 80px; resize: vertical; }
|
|
20
|
+
[aria-invalid=true] { border-color: var(--cliq-bad, #c33); }
|
|
21
|
+
:focus-visible { outline: 2px solid var(--cliq-acc, Highlight); outline-offset: 1px; }
|
|
22
|
+
button { font: inherit; color: inherit; background: var(--cliq-panel, ButtonFace); border: 1px solid var(--cliq-line, #ccc);
|
|
23
|
+
border-radius: var(--cliq-radius, 6px); padding: 5px 10px; cursor: pointer; }
|
|
24
|
+
button:disabled { opacity: .6; cursor: default; }
|
|
25
|
+
.link { background: none; border: 0; padding: 0; color: var(--cliq-acc, LinkText); text-decoration: underline; }
|
|
26
|
+
.muted { color: var(--cliq-ink-3, GrayText); }
|
|
27
|
+
`;
|
|
28
|
+
/** A kit element: lit-html into an open shadow root. */
|
|
29
|
+
export class KitElement extends HTMLElement {
|
|
30
|
+
root;
|
|
31
|
+
container;
|
|
32
|
+
queued = false;
|
|
33
|
+
constructor(css = '') {
|
|
34
|
+
super();
|
|
35
|
+
this.root = this.attachShadow({ mode: 'open', delegatesFocus: true });
|
|
36
|
+
const style = document.createElement('style');
|
|
37
|
+
style.textContent = KIT_CSS + css;
|
|
38
|
+
this.container = document.createElement('div');
|
|
39
|
+
this.container.setAttribute('part', 'body');
|
|
40
|
+
this.root.append(style, this.container);
|
|
41
|
+
}
|
|
42
|
+
connectedCallback() {
|
|
43
|
+
this.draw();
|
|
44
|
+
}
|
|
45
|
+
/** Redraw (batched to one per task). */
|
|
46
|
+
request_draw() {
|
|
47
|
+
if (this.queued || !this.isConnected)
|
|
48
|
+
return;
|
|
49
|
+
this.queued = true;
|
|
50
|
+
queueMicrotask(() => { this.queued = false; this.draw(); });
|
|
51
|
+
}
|
|
52
|
+
/** Redraw now. */
|
|
53
|
+
draw() {
|
|
54
|
+
if (this.isConnected)
|
|
55
|
+
render(this.template(), this.container, { host: this });
|
|
56
|
+
}
|
|
57
|
+
/** Emit `change` with a value. */
|
|
58
|
+
emit(detail) {
|
|
59
|
+
this.dispatchEvent(new CustomEvent('change', { detail, bubbles: true, composed: true }));
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Declares reactive properties: setting one redraws. `attrs` also read from attributes of the same name
|
|
64
|
+
* (`label="Why"`, `multiline`).
|
|
65
|
+
*/
|
|
66
|
+
export function reactive(cls, props, attrs = []) {
|
|
67
|
+
for (const name of props) {
|
|
68
|
+
const store = Symbol(name);
|
|
69
|
+
Object.defineProperty(cls.prototype, name, {
|
|
70
|
+
configurable: true,
|
|
71
|
+
get() {
|
|
72
|
+
if (this[store] !== undefined || !attrs.includes(name))
|
|
73
|
+
return this[store];
|
|
74
|
+
const attr = this.getAttribute(name);
|
|
75
|
+
return attr === '' ? true : attr ?? undefined;
|
|
76
|
+
},
|
|
77
|
+
set(v) {
|
|
78
|
+
this[store] = v;
|
|
79
|
+
this.request_draw();
|
|
80
|
+
},
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
cls.observedAttributes = [...attrs];
|
|
84
|
+
cls.prototype.attributeChangedCallback = function () {
|
|
85
|
+
this.request_draw();
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
/** Defines an element once (a page may import the kit twice). */
|
|
89
|
+
export function define_element(name, cls) {
|
|
90
|
+
if (!customElements.get(name))
|
|
91
|
+
customElements.define(name, cls);
|
|
92
|
+
}
|
|
93
|
+
let next_id = 0;
|
|
94
|
+
/** A page-unique id for label/control pairs inside a shadow root. */
|
|
95
|
+
export function uid(prefix) {
|
|
96
|
+
next_id += 1;
|
|
97
|
+
return `${prefix}-${next_id}`;
|
|
98
|
+
}
|
|
99
|
+
//# sourceMappingURL=base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"base.js","sourceRoot":"","sources":["../../src/ui/base.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAC;AAElC,yEAAyE;AACzE,MAAM,CAAC,MAAM,OAAO,GAAG;;;;;;;;;;;;;;;;;;;CAmBtB,CAAC;AAEF,wDAAwD;AACxD,MAAM,OAAgB,UAAW,SAAQ,WAAW;IAC7B,IAAI,CAAa;IACnB,SAAS,CAAc;IAChC,MAAM,GAAG,KAAK,CAAC;IAEvB,YAAY,GAAG,GAAG,EAAE;QAChB,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,CAAC;QACtE,MAAM,KAAK,GAAG,QAAQ,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC9C,KAAK,CAAC,WAAW,GAAG,OAAO,GAAG,GAAG,CAAC;QAClC,IAAI,CAAC,SAAS,GAAG,QAAQ,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC5C,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC;IAC5C,CAAC;IAED,iBAAiB;QACb,IAAI,CAAC,IAAI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C,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,IAAI,SAAS,CAAC;YAClD,CAAC;YACD,GAAG,CAA2D,CAAU;gBACpE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;gBAChB,IAAI,CAAC,YAAY,EAAE,CAAC;YACxB,CAAC;SACJ,CAAC,CAAC;IACP,CAAC;IACA,GAAmD,CAAC,kBAAkB,GAAG,CAAC,GAAG,KAAK,CAAC,CAAC;IACpF,GAAG,CAAC,SAA6D,CAAC,wBAAwB,GAAG;QAC1F,IAAI,CAAC,YAAY,EAAE,CAAC;IACxB,CAAC,CAAC;AACN,CAAC;AAED,iEAAiE;AACjE,MAAM,UAAU,cAAc,CAAC,IAAY,EAAE,GAA6B;IACtE,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,IAAI,CAAC;QAAE,cAAc,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC;AACpE,CAAC;AAED,IAAI,OAAO,GAAG,CAAC,CAAC;AAChB,qEAAqE;AACrE,MAAM,UAAU,GAAG,CAAC,MAAc;IAC9B,OAAO,IAAI,CAAC,CAAC;IACb,OAAO,GAAG,MAAM,IAAI,OAAO,EAAE,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `<cliq-choice-group>` (Approve / Reject, reject choices), `<cliq-problems>` (problems linked to their fields) and
|
|
3
|
+
* `<cliq-context>` (context blocks: markdown, files, checks, a transcript).
|
|
4
|
+
*/
|
|
5
|
+
import type { ContextBlock } from '../shared/context.js';
|
|
6
|
+
import type { Problem } from '../shared/problems.js';
|
|
7
|
+
import { KitElement } from './base.js';
|
|
8
|
+
import './files.js';
|
|
9
|
+
import './markdown.js';
|
|
10
|
+
/** One choice. */
|
|
11
|
+
export interface Choice {
|
|
12
|
+
readonly value: string;
|
|
13
|
+
readonly label?: string;
|
|
14
|
+
/** `danger` draws it red when chosen (Reject). */
|
|
15
|
+
readonly tone?: 'primary' | 'danger';
|
|
16
|
+
}
|
|
17
|
+
/** `<cliq-choice-group label="Decision" .choices=${…} .value=${v}>` — a radio group as segmented buttons. Emits `change`. */
|
|
18
|
+
export declare class CliqChoiceGroup extends KitElement {
|
|
19
|
+
choices: readonly Choice[] | undefined;
|
|
20
|
+
value: string | undefined;
|
|
21
|
+
label: string | undefined;
|
|
22
|
+
private readonly field_id;
|
|
23
|
+
constructor();
|
|
24
|
+
protected template(): unknown;
|
|
25
|
+
private choose;
|
|
26
|
+
/** Arrow keys move and choose, as in a radio group. */
|
|
27
|
+
private readonly keys;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* `<cliq-problems .problems=${…}>` — the answer's problems. Each one with a path focuses its field: an element with a
|
|
31
|
+
* matching `path` attribute (`<cliq-field path="severity">`), searching the page and the kit's shadow roots.
|
|
32
|
+
*/
|
|
33
|
+
export declare class CliqProblems extends KitElement {
|
|
34
|
+
problems: readonly Problem[] | undefined;
|
|
35
|
+
protected template(): unknown;
|
|
36
|
+
}
|
|
37
|
+
/** Focuses the element whose `path` attribute matches, looking inside open shadow roots. */
|
|
38
|
+
export declare function focus_path(path: string, root?: ParentNode): boolean;
|
|
39
|
+
/** `<cliq-context .blocks=${params.context}>` — what the person reads beside the question. */
|
|
40
|
+
export declare class CliqContext extends KitElement {
|
|
41
|
+
blocks: readonly ContextBlock[] | undefined;
|
|
42
|
+
constructor();
|
|
43
|
+
protected template(): unknown;
|
|
44
|
+
private block;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=choices.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choices.d.ts","sourceRoot":"","sources":["../../src/ui/choices.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAC;AAErD,OAAO,EAAkB,UAAU,EA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