@keemakr/ui-sdk 1.2.0 → 1.3.0-dev-20261001185950

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/dist/index.d.ts CHANGED
@@ -2,5 +2,6 @@ export { UI_SCHEMA_VERSION, pressSchema, buttonSchema, cellSchema, nodeSchema, s
2
2
  export type { Press, ScreenNode, ScreenRootNode, ScreenTree, ActionResult, InterfaceFamily, SurfaceDefinition, Surface, ScreenRegistration, UiManifest, ScreenTreeInput, ActionResultInput, } from './schema.js';
3
3
  export { childNodesOf, KNOWN_CONTAINERS, KNOWN_NODE_TYPES } from './nodes.js';
4
4
  export type { ContainerChild, ContainerNodeType, KnownNodeType } from './nodes.js';
5
+ export { pageRangeLabel, pageWindow, pressWithValue } from './pager.js';
5
6
  export { defineScreen, defineSurface } from './define.js';
6
7
  export type { ScreenDefinition, ScreenParams, LoadHandler, ActionHandler } from './define.js';
package/dist/index.js CHANGED
@@ -8,4 +8,5 @@
8
8
  // Module code never ships to the browser. UI is data, not code.
9
9
  export { UI_SCHEMA_VERSION, pressSchema, buttonSchema, cellSchema, nodeSchema, screenTreeSchema, actionResultSchema, screenLoadRequestSchema, screenLoadResponseSchema, screenActionRequestSchema, interfaceFamilySchema, surfaceDefinitionSchema, surfaceSchema, screenRegistrationSchema, uiManifestSchema, } from './schema.js';
10
10
  export { childNodesOf, KNOWN_CONTAINERS, KNOWN_NODE_TYPES } from './nodes.js';
11
+ export { pageRangeLabel, pageWindow, pressWithValue } from './pager.js';
11
12
  export { defineScreen, defineSurface } from './define.js';
package/dist/nodes.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import type { ScreenRootNode } from './schema.js';
2
2
  /** Every node type the root union admits (KEE-574 item 3). */
3
- export declare const KNOWN_NODE_TYPES: readonly ["heading", "text", "markdown", "stat", "button", "form", "table", "timeline", "pending_request", "pending_requests", "choice_cards", "progress", "chart", "section", "tabs"];
3
+ export declare const KNOWN_NODE_TYPES: readonly ["heading", "text", "markdown", "stat", "button", "form", "table", "timeline", "pending_request", "pending_requests", "choice_cards", "progress", "chart", "pagination", "select", "section", "tabs"];
4
4
  export type KnownNodeType = (typeof KNOWN_NODE_TYPES)[number];
5
5
  /**
6
6
  * The node types that hold child nodes. `section` mounts its children
package/dist/nodes.js CHANGED
@@ -23,6 +23,8 @@ export const KNOWN_NODE_TYPES = [
23
23
  'choice_cards',
24
24
  'progress',
25
25
  'chart',
26
+ 'pagination',
27
+ 'select',
26
28
  'section',
27
29
  'tabs',
28
30
  ];
@@ -0,0 +1,23 @@
1
+ import type { Press } from './schema.js';
2
+ /**
3
+ * The press a pager or select fires once the user has chosen `value`: the
4
+ * declared press with the value merged in under `name` — into `params` for a
5
+ * navigate (params are strings; they become the next screen's query), into
6
+ * `input` for an action. The chosen value wins over a same-named key the
7
+ * author put there, since the author cannot know which page will be chosen.
8
+ */
9
+ export declare function pressWithValue(press: Press, name: string, value: string | number): Press;
10
+ /**
11
+ * The page numbers a compact pager draws, `null` marking an ellipsis:
12
+ * `pageWindow(5, 13)` → `[1, null, 4, 5, 6, null, 13]`. First and last pages
13
+ * always show, plus `siblings` either side of the current one. An ellipsis
14
+ * never stands in for a single page — `1 … 3` draws as `1 2 3`, since the
15
+ * ellipsis would take the same room and hide the number.
16
+ */
17
+ export declare function pageWindow(page: number, pageCount: number, siblings?: number): (number | null)[];
18
+ /**
19
+ * "Showing 31–40 of 124" — the pager's live summary. The end clamps to
20
+ * `total`, so a short last page reads truthfully; an empty result, or a page
21
+ * past the last result, says so instead of inventing a range.
22
+ */
23
+ export declare function pageRangeLabel(page: number, pageSize: number, total: number): string;
package/dist/pager.js ADDED
@@ -0,0 +1,60 @@
1
+ // Renderer-side helpers for the `pagination` and `select` nodes. They live in
2
+ // the SDK, not in a renderer, because core and every client render these nodes:
3
+ // how a chosen value reaches the press, and which page numbers a pager shows,
4
+ // must be one rule, or the same tree pages differently on web and mobile.
5
+ /**
6
+ * The press a pager or select fires once the user has chosen `value`: the
7
+ * declared press with the value merged in under `name` — into `params` for a
8
+ * navigate (params are strings; they become the next screen's query), into
9
+ * `input` for an action. The chosen value wins over a same-named key the
10
+ * author put there, since the author cannot know which page will be chosen.
11
+ */
12
+ export function pressWithValue(press, name, value) {
13
+ if (press.kind === 'navigate') {
14
+ return { ...press, params: { ...press.params, [name]: String(value) } };
15
+ }
16
+ return { ...press, input: { ...press.input, [name]: value } };
17
+ }
18
+ /**
19
+ * The page numbers a compact pager draws, `null` marking an ellipsis:
20
+ * `pageWindow(5, 13)` → `[1, null, 4, 5, 6, null, 13]`. First and last pages
21
+ * always show, plus `siblings` either side of the current one. An ellipsis
22
+ * never stands in for a single page — `1 … 3` draws as `1 2 3`, since the
23
+ * ellipsis would take the same room and hide the number.
24
+ */
25
+ export function pageWindow(page, pageCount, siblings = 1) {
26
+ const last = Math.max(1, Math.floor(pageCount));
27
+ const current = Math.min(Math.max(1, Math.floor(page)), last);
28
+ const shown = new Set([1, last]);
29
+ for (let p = current - siblings; p <= current + siblings; p += 1) {
30
+ if (p >= 1 && p <= last)
31
+ shown.add(p);
32
+ }
33
+ const sorted = [...shown].sort((a, b) => a - b);
34
+ const out = [];
35
+ for (const p of sorted) {
36
+ const prev = out.at(-1);
37
+ if (typeof prev === 'number' && p - prev === 2)
38
+ out.push(prev + 1);
39
+ else if (typeof prev === 'number' && p - prev > 2)
40
+ out.push(null);
41
+ out.push(p);
42
+ }
43
+ return out;
44
+ }
45
+ /**
46
+ * "Showing 31–40 of 124" — the pager's live summary. The end clamps to
47
+ * `total`, so a short last page reads truthfully; an empty result, or a page
48
+ * past the last result, says so instead of inventing a range.
49
+ */
50
+ export function pageRangeLabel(page, pageSize, total) {
51
+ if (total <= 0)
52
+ return 'No results';
53
+ const start = (page - 1) * pageSize + 1;
54
+ // pageCount is not cross-checked against total, so a page can sit past the
55
+ // last result; say it holds none rather than inventing a "50–50" range.
56
+ if (start > total)
57
+ return `Showing 0 of ${total.toLocaleString('en-US')}`;
58
+ const end = Math.min(page * pageSize, total);
59
+ return `Showing ${start.toLocaleString('en-US')}–${end.toLocaleString('en-US')} of ${total.toLocaleString('en-US')}`;
60
+ }
package/dist/schema.d.ts CHANGED
@@ -41,6 +41,7 @@ export declare const buttonSchema: z.ZodObject<{
41
41
  primary: "primary";
42
42
  secondary: "secondary";
43
43
  }>>;
44
+ disabled: z.ZodDefault<z.ZodBoolean>;
44
45
  }, z.core.$strip>;
45
46
  /** A table cell. Dates are ISO 8601; core formats them tenant-locale-aware. */
46
47
  export declare const cellSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
@@ -92,14 +93,15 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
92
93
  primary: "primary";
93
94
  secondary: "secondary";
94
95
  }>>;
96
+ disabled: z.ZodDefault<z.ZodBoolean>;
95
97
  }, z.core.$strip>, z.ZodObject<{
96
98
  type: z.ZodLiteral<"form">;
97
99
  key: z.ZodString;
98
100
  fields: z.ZodArray<z.ZodObject<{
99
101
  kind: z.ZodEnum<{
100
102
  text: "text";
101
- textarea: "textarea";
102
103
  select: "select";
104
+ textarea: "textarea";
103
105
  }>;
104
106
  name: z.ZodString;
105
107
  label: z.ZodString;
@@ -182,6 +184,7 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
182
184
  primary: "primary";
183
185
  secondary: "secondary";
184
186
  }>>;
187
+ disabled: z.ZodDefault<z.ZodBoolean>;
185
188
  }, z.core.$strip>], "type">>;
186
189
  }, z.core.$strip>>;
187
190
  }, z.core.$strip>>;
@@ -247,6 +250,43 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
247
250
  name: z.ZodString;
248
251
  values: z.ZodArray<z.ZodNumber>;
249
252
  }, z.core.$strip>>;
253
+ }, z.core.$strip>, z.ZodObject<{
254
+ type: z.ZodLiteral<"pagination">;
255
+ page: z.ZodNumber;
256
+ pageCount: z.ZodNumber;
257
+ pageSize: z.ZodNumber;
258
+ total: z.ZodNumber;
259
+ onPage: z.ZodDiscriminatedUnion<[z.ZodObject<{
260
+ kind: z.ZodLiteral<"action">;
261
+ action: z.ZodString;
262
+ input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
263
+ confirm: z.ZodOptional<z.ZodString>;
264
+ }, z.core.$strip>, z.ZodObject<{
265
+ kind: z.ZodLiteral<"navigate">;
266
+ screen: z.ZodString;
267
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
268
+ }, z.core.$strip>], "kind">;
269
+ param: z.ZodDefault<z.ZodString>;
270
+ }, z.core.$strip>, z.ZodObject<{
271
+ type: z.ZodLiteral<"select">;
272
+ name: z.ZodString;
273
+ label: z.ZodString;
274
+ value: z.ZodOptional<z.ZodString>;
275
+ options: z.ZodArray<z.ZodObject<{
276
+ value: z.ZodString;
277
+ label: z.ZodString;
278
+ }, z.core.$strip>>;
279
+ onChange: z.ZodDiscriminatedUnion<[z.ZodObject<{
280
+ kind: z.ZodLiteral<"action">;
281
+ action: z.ZodString;
282
+ input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
283
+ confirm: z.ZodOptional<z.ZodString>;
284
+ }, z.core.$strip>, z.ZodObject<{
285
+ kind: z.ZodLiteral<"navigate">;
286
+ screen: z.ZodString;
287
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
288
+ }, z.core.$strip>], "kind">;
289
+ disabled: z.ZodDefault<z.ZodBoolean>;
250
290
  }, z.core.$strip>], "type">;
251
291
  type LeafScreenNode = z.infer<typeof leafNodeSchema>;
252
292
  type LeafScreenNodeInput = z.input<typeof leafNodeSchema>;
@@ -326,6 +366,7 @@ export declare const screenTreeSchema: z.ZodObject<{
326
366
  primary: "primary";
327
367
  secondary: "secondary";
328
368
  }>>;
369
+ disabled: z.ZodDefault<z.ZodBoolean>;
329
370
  }, z.core.$strip>>>;
330
371
  children: z.ZodArray<z.ZodType<ScreenRootNode, ScreenRootNodeInput, z.core.$ZodTypeInternals<ScreenRootNode, ScreenRootNodeInput>>>;
331
372
  refreshSeconds: z.ZodOptional<z.ZodNumber>;
@@ -365,6 +406,7 @@ export declare const screenLoadResponseSchema: z.ZodObject<{
365
406
  primary: "primary";
366
407
  secondary: "secondary";
367
408
  }>>;
409
+ disabled: z.ZodDefault<z.ZodBoolean>;
368
410
  }, z.core.$strip>>>;
369
411
  children: z.ZodArray<z.ZodType<ScreenRootNode, ScreenRootNodeInput, z.core.$ZodTypeInternals<ScreenRootNode, ScreenRootNodeInput>>>;
370
412
  refreshSeconds: z.ZodOptional<z.ZodNumber>;
package/dist/schema.js CHANGED
@@ -39,6 +39,8 @@ export const buttonSchema = z.object({
39
39
  label: z.string().max(80),
40
40
  onPress: pressSchema,
41
41
  variant: z.enum(['primary', 'secondary', 'destructive']).default('secondary'),
42
+ /** Shown but not pressable — a Next button on the last page, an action not yet available. */
43
+ disabled: z.boolean().default(false),
42
44
  });
43
45
  /** A table cell. Dates are ISO 8601; core formats them tenant-locale-aware. */
44
46
  export const cellSchema = z.discriminatedUnion('kind', [
@@ -97,6 +99,81 @@ const chartSchema = z
97
99
  }
98
100
  }
99
101
  });
102
+ /**
103
+ * A compact pager: "‹ 1 … 4 5 6 … 13 ›" plus a live "Showing 31–40 of 124".
104
+ *
105
+ * Choosing a page fires `onPage` with the page number merged in under `param`
106
+ * — into `params` for a navigate, into `input` for an action (see
107
+ * `pressWithValue`). So the module declares its press once instead of one
108
+ * button per page, and the pager owns which pages it shows. Prev/next are
109
+ * disabled at the edges by the renderer, not by the author.
110
+ *
111
+ * Prefer a navigate `onPage`: the page lands in the screen's params, so the
112
+ * next load serves it and the URL (back button, a shared link) carries it. An
113
+ * action `onPage` receives the page in `input`, but the screen reloads with
114
+ * the params it was mounted with, so an action that only returns `refresh`
115
+ * serves the SAME page again and the pager appears to do nothing. Such an
116
+ * action must return `navigate: { screen, params: { page } }` (keeping any
117
+ * other params it needs), or persist the page server-side before refreshing.
118
+ *
119
+ * `page` past `pageCount` is rejected: it names a page the pager cannot draw.
120
+ * `total` and `pageSize` are NOT cross-checked against `pageCount` — a module
121
+ * that caps its page count, or counts approximately, still renders, and the
122
+ * range label clamps to `total`.
123
+ */
124
+ const paginationSchema = z
125
+ .object({
126
+ type: z.literal('pagination'),
127
+ page: z.number().int().min(1),
128
+ pageCount: z.number().int().min(1).max(1_000_000),
129
+ pageSize: z.number().int().min(1).max(10_000),
130
+ total: z.number().int().min(0),
131
+ onPage: pressSchema,
132
+ param: slug.default('page'),
133
+ })
134
+ .superRefine((node, ctx) => {
135
+ if (node.page > node.pageCount) {
136
+ ctx.addIssue({
137
+ code: 'custom',
138
+ path: ['page'],
139
+ message: `page ${node.page} is past pageCount ${node.pageCount}`,
140
+ });
141
+ }
142
+ });
143
+ /**
144
+ * A standalone select that acts the moment it changes — no separate Show
145
+ * button. The chosen value is merged into `onChange` under `name` (into
146
+ * `params` for a navigate, `input` for an action), the same rule the pager
147
+ * uses. A select inside a `form` is still a form field and still waits for
148
+ * the submit; this node is for filters and page sizes that should just apply.
149
+ * A mouse or touch pick applies at once; keyboard stepping through options
150
+ * applies on Enter or when focus leaves, so passing an option never applies it.
151
+ * As with the pager, an action `onChange` that only returns `refresh` reloads
152
+ * with the mounted params: return `navigate` with the value in `params`, or
153
+ * persist it server-side, for the change to show.
154
+ */
155
+ const selectSchema = z
156
+ .object({
157
+ type: z.literal('select'),
158
+ name: slug,
159
+ label: z.string().max(80),
160
+ value: z.string().max(200).optional(),
161
+ options: z
162
+ .array(z.object({ value: z.string().max(200), label: z.string().max(120) }))
163
+ .min(1)
164
+ .max(100),
165
+ onChange: pressSchema,
166
+ disabled: z.boolean().default(false),
167
+ })
168
+ .superRefine((node, ctx) => {
169
+ if (node.value !== undefined && !node.options.some((option) => option.value === node.value)) {
170
+ ctx.addIssue({
171
+ code: 'custom',
172
+ path: ['value'],
173
+ message: `value "${node.value}" is not one of the options`,
174
+ });
175
+ }
176
+ });
100
177
  const headingSchema = z.object({ type: z.literal('heading'), text: z.string().max(120) });
101
178
  const textSchema = z.object({
102
179
  type: z.literal('text'),
@@ -215,6 +292,8 @@ const leafNodeSchema = z.discriminatedUnion('type', [
215
292
  choiceCardsSchema,
216
293
  progressSchema,
217
294
  chartSchema,
295
+ paginationSchema,
296
+ selectSchema,
218
297
  ]);
219
298
  const MAX_SECTION_DEPTH = 8;
220
299
  const nodeSchemas = new Map();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/ui-sdk",
3
- "version": "1.2.0",
3
+ "version": "1.3.0-dev-20261001185950",
4
4
  "description": "Product screens for keemakr marketplace modules: a versioned, server-driven UI tree schema plus defineScreen() handlers. Module code never ships to the browser — keemakr-core validates the tree and renders it with platform components.",
5
5
  "license": "MIT",
6
6
  "type": "module",