@keemakr/ui-sdk 1.0.0 → 1.1.0-dev-20260818164938

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
@@ -1,4 +1,4 @@
1
1
  export { UI_SCHEMA_VERSION, pressSchema, buttonSchema, cellSchema, nodeSchema, screenTreeSchema, actionResultSchema, screenLoadRequestSchema, screenLoadResponseSchema, screenActionRequestSchema, interfaceFamilySchema, surfaceDefinitionSchema, surfaceSchema, screenRegistrationSchema, uiManifestSchema, } from './schema.js';
2
- export type { Press, ScreenNode, ScreenTree, ActionResult, InterfaceFamily, SurfaceDefinition, Surface, ScreenRegistration, UiManifest, ScreenTreeInput, ActionResultInput, } from './schema.js';
2
+ export type { Press, ScreenNode, ScreenRootNode, ScreenTree, ActionResult, InterfaceFamily, SurfaceDefinition, Surface, ScreenRegistration, UiManifest, ScreenTreeInput, ActionResultInput, } from './schema.js';
3
3
  export { defineScreen, defineSurface } from './define.js';
4
4
  export type { ScreenDefinition, ScreenParams, LoadHandler, ActionHandler } from './define.js';
package/dist/schema.d.ts CHANGED
@@ -59,7 +59,7 @@ export declare const cellSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
59
59
  kind: z.ZodLiteral<"date">;
60
60
  value: z.ZodISODateTime;
61
61
  }, z.core.$strip>], "kind">;
62
- declare const leafNodeSchema: z.ZodUnion<readonly [z.ZodObject<{
62
+ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
63
63
  type: z.ZodLiteral<"heading">;
64
64
  text: z.ZodString;
65
65
  }, z.core.$strip>, z.ZodObject<{
@@ -211,7 +211,7 @@ declare const leafNodeSchema: z.ZodUnion<readonly [z.ZodObject<{
211
211
  name: z.ZodString;
212
212
  values: z.ZodArray<z.ZodNumber>;
213
213
  }, z.core.$strip>>;
214
- }, z.core.$strip>]>;
214
+ }, z.core.$strip>], "type">;
215
215
  type LeafScreenNode = z.infer<typeof leafNodeSchema>;
216
216
  type LeafScreenNodeInput = z.input<typeof leafNodeSchema>;
217
217
  export type ScreenNode = LeafScreenNode | {
@@ -230,7 +230,44 @@ type ScreenNodeInput = LeafScreenNodeInput | {
230
230
  columns: number;
231
231
  children: ScreenNodeInput[];
232
232
  };
233
- export declare const nodeSchema: z.ZodType<ScreenNode, ScreenNodeInput, z.core.$ZodTypeInternals<ScreenNode, ScreenNodeInput>>;
233
+ /**
234
+ * A tab strip. Unlike `section` this is NOT part of the recursive chain: it
235
+ * exists only in the composed root union below, and a tab's children descend
236
+ * into the chain — which carries no `tabs` branch. Nested tabs, and tabs inside
237
+ * a section, are therefore unrepresentable rather than merely rejected, and
238
+ * `tabs` serialises into the generated contract exactly once.
239
+ */
240
+ type TabsScreenNode = {
241
+ type: 'tabs';
242
+ key: string;
243
+ active?: string;
244
+ tabs: {
245
+ key: string;
246
+ label: string;
247
+ badge?: string;
248
+ children: ScreenNode[];
249
+ }[];
250
+ };
251
+ type TabsScreenNodeInput = {
252
+ type: 'tabs';
253
+ key: string;
254
+ active?: string;
255
+ tabs: {
256
+ key: string;
257
+ label: string;
258
+ badge?: string;
259
+ children: ScreenNodeInput[];
260
+ }[];
261
+ };
262
+ /** What a screen's top-level `children` may hold — the only place `tabs` appears. */
263
+ export type ScreenRootNode = ScreenNode | TabsScreenNode;
264
+ type ScreenRootNodeInput = ScreenNodeInput | TabsScreenNodeInput;
265
+ /**
266
+ * The root union: the chain's own membership plus `tabs`. Both container
267
+ * branches descend into the chain at depth 1, so nesting stays bounded by
268
+ * MAX_SECTION_DEPTH exactly as it was before `tabs` existed.
269
+ */
270
+ export declare const nodeSchema: z.ZodType<ScreenRootNode, ScreenRootNodeInput>;
234
271
  export declare const screenTreeSchema: z.ZodObject<{
235
272
  version: z.ZodLiteral<1>;
236
273
  title: z.ZodString;
@@ -254,7 +291,7 @@ export declare const screenTreeSchema: z.ZodObject<{
254
291
  secondary: "secondary";
255
292
  }>>;
256
293
  }, z.core.$strip>>>;
257
- children: z.ZodArray<z.ZodType<ScreenNode, ScreenNodeInput, z.core.$ZodTypeInternals<ScreenNode, ScreenNodeInput>>>;
294
+ children: z.ZodArray<z.ZodType<ScreenRootNode, ScreenRootNodeInput, z.core.$ZodTypeInternals<ScreenRootNode, ScreenRootNodeInput>>>;
258
295
  refreshSeconds: z.ZodOptional<z.ZodNumber>;
259
296
  }, z.core.$strip>;
260
297
  /** What an action handler returns. `refresh` re-runs `load` after the action. */
@@ -293,7 +330,7 @@ export declare const screenLoadResponseSchema: z.ZodObject<{
293
330
  secondary: "secondary";
294
331
  }>>;
295
332
  }, z.core.$strip>>>;
296
- children: z.ZodArray<z.ZodType<ScreenNode, ScreenNodeInput, z.core.$ZodTypeInternals<ScreenNode, ScreenNodeInput>>>;
333
+ children: z.ZodArray<z.ZodType<ScreenRootNode, ScreenRootNodeInput, z.core.$ZodTypeInternals<ScreenRootNode, ScreenRootNodeInput>>>;
297
334
  refreshSeconds: z.ZodOptional<z.ZodNumber>;
298
335
  }, z.core.$strip>;
299
336
  }, z.core.$strip>;
package/dist/schema.js CHANGED
@@ -97,7 +97,7 @@ const chartSchema = z
97
97
  }
98
98
  }
99
99
  });
100
- const leafNodeSchema = z.union([
100
+ const leafNodeSchema = z.discriminatedUnion('type', [
101
101
  z.object({ type: z.literal('heading'), text: z.string().max(120) }),
102
102
  z.object({
103
103
  type: z.literal('text'),
@@ -176,27 +176,77 @@ const leafNodeSchema = z.union([
176
176
  ]);
177
177
  const MAX_SECTION_DEPTH = 8;
178
178
  const nodeSchemas = new Map();
179
+ /** Shared by the chain and by the root union, so the two cannot drift apart. */
180
+ const sectionBranch = (children) => z.object({
181
+ type: z.literal('section'),
182
+ title: z.string().max(120).optional(),
183
+ description: z.string().max(300).optional(),
184
+ layout: z.enum(['stack', 'grid']),
185
+ columns: z.number().int().min(1).max(4),
186
+ children: z.array(children).max(100),
187
+ });
188
+ const tabsBranch = (children) => z
189
+ .object({
190
+ type: z.literal('tabs'),
191
+ key: slug,
192
+ /** A hint only — the renderer owns selection, and it survives no reload. */
193
+ active: slug.optional(),
194
+ // One tab is legitimate: a strip generated per live queue drops to one when
195
+ // only one queue exists, and rejecting that fails the WHOLE screen load.
196
+ tabs: z
197
+ .array(z.object({
198
+ key: slug,
199
+ label: z.string().min(1).max(40),
200
+ /** Sits beside the label — a count, not prose. */
201
+ badge: z.string().max(12).optional(),
202
+ children: z.array(children).max(100),
203
+ }))
204
+ .min(1)
205
+ .max(6),
206
+ })
207
+ .superRefine((node, ctx) => {
208
+ const keys = new Set();
209
+ for (const [index, tab] of node.tabs.entries()) {
210
+ if (keys.has(tab.key)) {
211
+ ctx.addIssue({
212
+ code: 'custom',
213
+ path: ['tabs', index, 'key'],
214
+ message: `duplicate tab key "${tab.key}"`,
215
+ });
216
+ }
217
+ keys.add(tab.key);
218
+ }
219
+ if (node.active !== undefined && !keys.has(node.active)) {
220
+ ctx.addIssue({
221
+ code: 'custom',
222
+ path: ['active'],
223
+ message: `active tab "${node.active}" is not one of the declared tabs`,
224
+ });
225
+ }
226
+ });
179
227
  function nodeSchemaAtDepth(depth) {
180
228
  const cached = nodeSchemas.get(depth);
181
229
  if (cached)
182
230
  return cached;
183
231
  if (depth === MAX_SECTION_DEPTH)
184
232
  return leafNodeSchema;
185
- const schema = z.union([
233
+ const schema = z.discriminatedUnion('type', [
186
234
  leafNodeSchema,
187
- z.object({
188
- type: z.literal('section'),
189
- title: z.string().max(120).optional(),
190
- description: z.string().max(300).optional(),
191
- layout: z.enum(['stack', 'grid']),
192
- columns: z.number().int().min(1).max(4),
193
- children: z.array(z.lazy(() => nodeSchemaAtDepth(depth + 1))).max(100),
194
- }),
235
+ sectionBranch(z.lazy(() => nodeSchemaAtDepth(depth + 1))),
195
236
  ]);
196
237
  nodeSchemas.set(depth, schema);
197
238
  return schema;
198
239
  }
199
- export const nodeSchema = nodeSchemaAtDepth(0);
240
+ /**
241
+ * The root union: the chain's own membership plus `tabs`. Both container
242
+ * branches descend into the chain at depth 1, so nesting stays bounded by
243
+ * MAX_SECTION_DEPTH exactly as it was before `tabs` existed.
244
+ */
245
+ export const nodeSchema = z.discriminatedUnion('type', [
246
+ leafNodeSchema,
247
+ sectionBranch(z.lazy(() => nodeSchemaAtDepth(1))),
248
+ tabsBranch(z.lazy(() => nodeSchemaAtDepth(1))),
249
+ ]);
200
250
  export const screenTreeSchema = z.object({
201
251
  version: z.literal(UI_SCHEMA_VERSION),
202
252
  title: z.string().max(120),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/ui-sdk",
3
- "version": "1.0.0",
3
+ "version": "1.1.0-dev-20260818164938",
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",