@keemakr/ui-sdk 1.7.0 → 1.8.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.
@@ -465,14 +465,14 @@ export declare const NODE_LIMITS: {
465
465
  readonly 'onPress@focus.field': 64;
466
466
  readonly 'onPress@navigate.screen': 64;
467
467
  readonly 'onPress@seek.player': 64;
468
- readonly src: 256;
468
+ readonly src: 2048;
469
469
  };
470
470
  readonly video: {
471
471
  readonly caption: 200;
472
472
  readonly captions: 256;
473
473
  readonly key: 64;
474
- readonly poster: 256;
475
- readonly src: 256;
474
+ readonly poster: 2048;
475
+ readonly src: 2048;
476
476
  readonly title: 120;
477
477
  };
478
478
  readonly audio: {
@@ -440,9 +440,9 @@ export const NODE_LIMITS = {
440
440
  'onPress@focus.field': 64,
441
441
  'onPress@navigate.screen': 64,
442
442
  'onPress@seek.player': 64,
443
- src: 256,
443
+ src: 2048,
444
444
  },
445
- video: { caption: 200, captions: 256, key: 64, poster: 256, src: 256, title: 120 },
445
+ video: { caption: 200, captions: 256, key: 64, poster: 2048, src: 2048, title: 120 },
446
446
  audio: { caption: 200, key: 64, src: 256, title: 120 },
447
447
  document: { caption: 200, src: 256, title: 120 },
448
448
  dataset: {
package/dist/page.d.ts ADDED
@@ -0,0 +1,307 @@
1
+ /**
2
+ * The page format (WS28-S13): the one shape a builder page has, wherever it is made or read. Kee's
3
+ * page skill, installed agents, the builder's editor, export and import all write exactly this, and
4
+ * core stores it as an operator artifact of the kind `page`.
5
+ *
6
+ * import { pageDocumentSchema, stampNodeIds } from '@keemakr/ui-sdk/page';
7
+ *
8
+ * A page is a thin envelope over a screen tree:
9
+ *
10
+ * { format: 'keemakr.page', formatVersion: 1, catalogId, kind: 'page' | 'template', title,
11
+ * tree, bindings }
12
+ *
13
+ * - `catalogId` names the catalog the page was built against (`catalog.json`'s `catalogId`). The
14
+ * checker flags a page built against another one.
15
+ * - `tree` is the screen tree, as `screenTreeSchema` defines it. The envelope does not parse it:
16
+ * a page that does not pass the schema yet is still a page, and saving it keeps the person's
17
+ * work. What is wrong with the tree is the checker's to say (`@keemakr/ui-sdk/check`), and only a
18
+ * push or a pack submission is refused for it.
19
+ * - `bindings` are what the page may read and call: an installed dataset by name, a declared
20
+ * action by its stable id. Empty until the builder slices that bind a page fill it.
21
+ *
22
+ * Node ids. Every node of a stored page carries a stable `id`, so an edit names the node it
23
+ * changes, never its position: a move or an insert above it does not send the edit to another
24
+ * node. `stampNodeIds` gives an id to each node that has none (or a duplicate, or one that is not
25
+ * an id), and leaves every other id as it is. The store stamps on every save. The screen tree's own
26
+ * node schemas do not list `id`: they keep unknown keys out of what a renderer is handed, so an id
27
+ * stays in the stored page and never reaches a client.
28
+ */
29
+ import { z } from 'zod';
30
+ export declare const PAGE_FORMAT = "keemakr.page";
31
+ export declare const PAGE_FORMAT_VERSION = 1;
32
+ export declare const PAGE_KINDS: readonly ["page", "template"];
33
+ export type PageKind = (typeof PAGE_KINDS)[number];
34
+ /** The caps on the envelope. The tree's own caps are NODE_LIMITS. */
35
+ export declare const PAGE_LIMITS: {
36
+ readonly titleLength: 120;
37
+ readonly catalogIdLength: 100;
38
+ readonly bindings: 50;
39
+ };
40
+ /** A node id: short, URL-safe, unique within its page. */
41
+ export declare const PAGE_NODE_ID: RegExp;
42
+ export declare const pageNodeIdSchema: z.ZodString;
43
+ /** One thing the page may read or call. */
44
+ export declare const pageBindingSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
45
+ kind: z.ZodLiteral<"dataset">;
46
+ dataset: z.ZodString;
47
+ }, z.core.$strict>, z.ZodObject<{
48
+ kind: z.ZodLiteral<"action">;
49
+ action: z.ZodString;
50
+ }, z.core.$strict>], "kind">;
51
+ export declare const pageDocumentSchema: z.ZodObject<{
52
+ format: z.ZodLiteral<"keemakr.page">;
53
+ formatVersion: z.ZodLiteral<1>;
54
+ catalogId: z.ZodString;
55
+ kind: z.ZodEnum<{
56
+ page: "page";
57
+ template: "template";
58
+ }>;
59
+ title: z.ZodString;
60
+ tree: z.ZodRecord<z.ZodString, z.ZodUnknown>;
61
+ bindings: z.ZodDefault<z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
62
+ kind: z.ZodLiteral<"dataset">;
63
+ dataset: z.ZodString;
64
+ }, z.core.$strict>, z.ZodObject<{
65
+ kind: z.ZodLiteral<"action">;
66
+ action: z.ZodString;
67
+ }, z.core.$strict>], "kind">>>;
68
+ }, z.core.$strict>;
69
+ export type PageDocument = z.infer<typeof pageDocumentSchema>;
70
+ export type PageDocumentInput = z.input<typeof pageDocumentSchema>;
71
+ export type PageBinding = z.infer<typeof pageBindingSchema>;
72
+ /**
73
+ * A copy of the document in which every node has a stable id: a node with none, with one that is
74
+ * not an id, or with one an earlier node already holds gets a new one from `newId`. Every other id
75
+ * is kept, so ids stay the same from one save to the next. The input is never changed. Anything
76
+ * that is not a page (no `tree` object) comes back as a copy, untouched.
77
+ *
78
+ * `newId` is the caller's (core passes a random one): this package reads no clock and no random
79
+ * source. An id it returns that is taken, or is not an id, is asked for again, a bounded number
80
+ * of times.
81
+ */
82
+ export declare function stampNodeIds(document: unknown, newId: () => string): {
83
+ document: unknown;
84
+ stamped: number;
85
+ };
86
+ /**
87
+ * An edit to a stored page is a list of patch ops, applied in order to the page's newest version.
88
+ * Kee, an installed agent and the editor all send these, and core applies them in one place
89
+ * (`applyPageEdit`). Every op names the node it changes by its stable id, never its position, so
90
+ * an edit made on top of a person's version changes only what it names.
91
+ *
92
+ * { op: 'add', node, at?: { parent?, tab?, index? } } a new block (it may hold children)
93
+ * { op: 'update', id, set } change a node's fields; `null` removes one
94
+ * { op: 'move', id, to: { parent?, tab?, index? } } the node and everything in it
95
+ * { op: 'remove', id } the node and everything in it
96
+ * { op: 'add_binding', binding } declare what the page may read or call
97
+ * { op: 'update_binding', binding, to } swap one declared binding for another
98
+ * { op: 'remove_binding', binding }
99
+ *
100
+ * There is no op that replaces the whole tree or the whole page: a list of ops that tries one
101
+ * (`replace`, `regenerate`, a `tree` or a page where an op belongs) is `regenerate_refused`. A
102
+ * changed page is made by naming each change, so the person's own work around it stays theirs.
103
+ *
104
+ * A place (`at`, `to`) is a container's list of children: the page's top level when `parent` is
105
+ * omitted, a `section` by its id, or one tab of a `tabs` node (`tab` is that tab's key). `index`
106
+ * is the position in that list, counted after a moved node has been taken out; omitted or past the
107
+ * end, the node goes last. A table row's `expand` holds nodes too: they can be updated, moved out
108
+ * and removed there, but nothing is added or moved into one.
109
+ *
110
+ * `update` changes a node's own fields. It never changes `id` or `type`, and it never adds, moves
111
+ * or drops a child node: a `section`'s `children` are only changed by add, move and remove, and a
112
+ * `tabs` node's `tabs` or a `table`'s `rows` may be set only when every node inside them stays the
113
+ * same node in the same place, unchanged field for field (a tab renamed, a row's values changed).
114
+ * A node inside is changed by an op on its own id.
115
+ *
116
+ * An added node keeps an `id` it brings when that id is free on the page, so a later op in the same
117
+ * edit can name it (add a section, then add into it); a node without one is given one. Ids are
118
+ * checked again when core stores the page.
119
+ *
120
+ * The edit is all or nothing: the first op that cannot apply refuses the whole edit, with its
121
+ * index and a stable code.
122
+ */
123
+ /** The caps on one edit. The page's own caps still apply to what it makes. */
124
+ export declare const PAGE_EDIT_LIMITS: {
125
+ readonly ops: 100;
126
+ };
127
+ /** The op names. */
128
+ export declare const PAGE_EDIT_OPS: readonly ["add", "update", "move", "remove", "add_binding", "update_binding", "remove_binding"];
129
+ export type PageEditOpName = (typeof PAGE_EDIT_OPS)[number];
130
+ /** Names of ops that would replace the tree or the page whole. Refused, never applied. */
131
+ export declare const REGENERATE_OPS: readonly ["replace", "replace_tree", "replace_page", "set_tree", "set_page", "regenerate"];
132
+ /** Where a node goes. */
133
+ export declare const pageEditPlaceSchema: z.ZodObject<{
134
+ parent: z.ZodOptional<z.ZodString>;
135
+ tab: z.ZodOptional<z.ZodString>;
136
+ index: z.ZodOptional<z.ZodNumber>;
137
+ }, z.core.$strict>;
138
+ export declare const pageEditOpSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
139
+ op: z.ZodLiteral<"add">;
140
+ node: z.ZodRecord<z.ZodString, z.ZodUnknown>;
141
+ at: z.ZodOptional<z.ZodObject<{
142
+ parent: z.ZodOptional<z.ZodString>;
143
+ tab: z.ZodOptional<z.ZodString>;
144
+ index: z.ZodOptional<z.ZodNumber>;
145
+ }, z.core.$strict>>;
146
+ }, z.core.$strict>, z.ZodObject<{
147
+ op: z.ZodLiteral<"update">;
148
+ id: z.ZodString;
149
+ set: z.ZodRecord<z.ZodString, z.ZodUnknown>;
150
+ }, z.core.$strict>, z.ZodObject<{
151
+ op: z.ZodLiteral<"move">;
152
+ id: z.ZodString;
153
+ to: z.ZodObject<{
154
+ parent: z.ZodOptional<z.ZodString>;
155
+ tab: z.ZodOptional<z.ZodString>;
156
+ index: z.ZodOptional<z.ZodNumber>;
157
+ }, z.core.$strict>;
158
+ }, z.core.$strict>, z.ZodObject<{
159
+ op: z.ZodLiteral<"remove">;
160
+ id: z.ZodString;
161
+ }, z.core.$strict>, z.ZodObject<{
162
+ op: z.ZodLiteral<"add_binding">;
163
+ binding: z.ZodDiscriminatedUnion<[z.ZodObject<{
164
+ kind: z.ZodLiteral<"dataset">;
165
+ dataset: z.ZodString;
166
+ }, z.core.$strict>, z.ZodObject<{
167
+ kind: z.ZodLiteral<"action">;
168
+ action: z.ZodString;
169
+ }, z.core.$strict>], "kind">;
170
+ }, z.core.$strict>, z.ZodObject<{
171
+ op: z.ZodLiteral<"update_binding">;
172
+ binding: z.ZodDiscriminatedUnion<[z.ZodObject<{
173
+ kind: z.ZodLiteral<"dataset">;
174
+ dataset: z.ZodString;
175
+ }, z.core.$strict>, z.ZodObject<{
176
+ kind: z.ZodLiteral<"action">;
177
+ action: z.ZodString;
178
+ }, z.core.$strict>], "kind">;
179
+ to: z.ZodDiscriminatedUnion<[z.ZodObject<{
180
+ kind: z.ZodLiteral<"dataset">;
181
+ dataset: z.ZodString;
182
+ }, z.core.$strict>, z.ZodObject<{
183
+ kind: z.ZodLiteral<"action">;
184
+ action: z.ZodString;
185
+ }, z.core.$strict>], "kind">;
186
+ }, z.core.$strict>, z.ZodObject<{
187
+ op: z.ZodLiteral<"remove_binding">;
188
+ binding: z.ZodDiscriminatedUnion<[z.ZodObject<{
189
+ kind: z.ZodLiteral<"dataset">;
190
+ dataset: z.ZodString;
191
+ }, z.core.$strict>, z.ZodObject<{
192
+ kind: z.ZodLiteral<"action">;
193
+ action: z.ZodString;
194
+ }, z.core.$strict>], "kind">;
195
+ }, z.core.$strict>], "op">;
196
+ export declare const pageEditOpsSchema: z.ZodArray<z.ZodDiscriminatedUnion<[z.ZodObject<{
197
+ op: z.ZodLiteral<"add">;
198
+ node: z.ZodRecord<z.ZodString, z.ZodUnknown>;
199
+ at: z.ZodOptional<z.ZodObject<{
200
+ parent: z.ZodOptional<z.ZodString>;
201
+ tab: z.ZodOptional<z.ZodString>;
202
+ index: z.ZodOptional<z.ZodNumber>;
203
+ }, z.core.$strict>>;
204
+ }, z.core.$strict>, z.ZodObject<{
205
+ op: z.ZodLiteral<"update">;
206
+ id: z.ZodString;
207
+ set: z.ZodRecord<z.ZodString, z.ZodUnknown>;
208
+ }, z.core.$strict>, z.ZodObject<{
209
+ op: z.ZodLiteral<"move">;
210
+ id: z.ZodString;
211
+ to: z.ZodObject<{
212
+ parent: z.ZodOptional<z.ZodString>;
213
+ tab: z.ZodOptional<z.ZodString>;
214
+ index: z.ZodOptional<z.ZodNumber>;
215
+ }, z.core.$strict>;
216
+ }, z.core.$strict>, z.ZodObject<{
217
+ op: z.ZodLiteral<"remove">;
218
+ id: z.ZodString;
219
+ }, z.core.$strict>, z.ZodObject<{
220
+ op: z.ZodLiteral<"add_binding">;
221
+ binding: z.ZodDiscriminatedUnion<[z.ZodObject<{
222
+ kind: z.ZodLiteral<"dataset">;
223
+ dataset: z.ZodString;
224
+ }, z.core.$strict>, z.ZodObject<{
225
+ kind: z.ZodLiteral<"action">;
226
+ action: z.ZodString;
227
+ }, z.core.$strict>], "kind">;
228
+ }, z.core.$strict>, z.ZodObject<{
229
+ op: z.ZodLiteral<"update_binding">;
230
+ binding: z.ZodDiscriminatedUnion<[z.ZodObject<{
231
+ kind: z.ZodLiteral<"dataset">;
232
+ dataset: z.ZodString;
233
+ }, z.core.$strict>, z.ZodObject<{
234
+ kind: z.ZodLiteral<"action">;
235
+ action: z.ZodString;
236
+ }, z.core.$strict>], "kind">;
237
+ to: z.ZodDiscriminatedUnion<[z.ZodObject<{
238
+ kind: z.ZodLiteral<"dataset">;
239
+ dataset: z.ZodString;
240
+ }, z.core.$strict>, z.ZodObject<{
241
+ kind: z.ZodLiteral<"action">;
242
+ action: z.ZodString;
243
+ }, z.core.$strict>], "kind">;
244
+ }, z.core.$strict>, z.ZodObject<{
245
+ op: z.ZodLiteral<"remove_binding">;
246
+ binding: z.ZodDiscriminatedUnion<[z.ZodObject<{
247
+ kind: z.ZodLiteral<"dataset">;
248
+ dataset: z.ZodString;
249
+ }, z.core.$strict>, z.ZodObject<{
250
+ kind: z.ZodLiteral<"action">;
251
+ action: z.ZodString;
252
+ }, z.core.$strict>], "kind">;
253
+ }, z.core.$strict>], "op">>;
254
+ export type PageEditOp = z.infer<typeof pageEditOpSchema>;
255
+ export type PageEditPlace = z.infer<typeof pageEditPlaceSchema>;
256
+ /** Why an edit was refused. Stable codes; callers show their own words. */
257
+ export type PageEditErrorCode =
258
+ /** The ops replace the tree or the page whole. */
259
+ 'regenerate_refused'
260
+ /** Not a list of ops in this shape. */
261
+ | 'invalid_ops'
262
+ /** No node (or parent) with that id on the page. */
263
+ | 'node_not_found'
264
+ /** The parent is not a `section` or a `tabs` node. */
265
+ | 'not_a_container'
266
+ /** A `tabs` parent without that tab, or a `tab` on a parent that has none. */
267
+ | 'tab_not_found'
268
+ /** A node moved into itself or into a node inside it. */
269
+ | 'move_into_itself'
270
+ /** An added node brings an id the page already has. */
271
+ | 'id_taken'
272
+ /** An update that would change `id`, `type` or the nodes inside the node. */
273
+ | 'structural_update'
274
+ /** The page already declares that binding. */
275
+ | 'binding_exists'
276
+ /** The page does not declare that binding. */
277
+ | 'binding_not_found';
278
+ export type PageEditRefusal = {
279
+ ok: false;
280
+ code: PageEditErrorCode;
281
+ /** The op that was refused, by its position in the list. Absent for the list as a whole. */
282
+ index?: number;
283
+ message: string;
284
+ };
285
+ export type ParsedPageEdit = {
286
+ ok: true;
287
+ ops: PageEditOp[];
288
+ } | PageEditRefusal;
289
+ /**
290
+ * Read an edit: a list of ops, or the refusal. Anything that would replace the tree or the page
291
+ * whole (a page or a tree in place of the list, an op named `replace` or `regenerate`, an op of no
292
+ * known name that carries a tree) is `regenerate_refused`, never `invalid_ops`, so the caller is
293
+ * told to name its changes rather than to fix a field.
294
+ */
295
+ export declare function parsePageEditOps(input: unknown): ParsedPageEdit;
296
+ /**
297
+ * Apply an edit to a page: a new document, the input unchanged. All or nothing: the first op that
298
+ * cannot apply refuses the edit with its index. `newId` gives ids to the nodes an `add` brings
299
+ * without one (core passes a random one; this package reads no random source).
300
+ *
301
+ * The result is not checked here. Core bounds it, stamps it and parses it as a page when it
302
+ * stores it, and runs the checker on it as on any save.
303
+ */
304
+ export declare function applyPageEditOps(document: PageDocumentInput, ops: readonly PageEditOp[], newId: () => string): {
305
+ ok: true;
306
+ document: PageDocumentInput;
307
+ } | PageEditRefusal;