@keemakr/ui-sdk 1.6.0-dev-20261027083052 → 1.6.0-dev-20261027084552

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.
@@ -67,8 +67,16 @@ import type { ChatPress, ScreenRootNode, ScreenTree } from './schema.js';
67
67
  * column of its own, and its `tag` drawn as a grey pill after the label (newer than any
68
68
  * published release; core's own renderer draws them). An older parse strips both without a
69
69
  * sign, so without it they are written into the label ("07:30 · Brief sent · brief").
70
+ * - `stat.bar`: a stat tile's `bar`, a small bar split into coloured parts (newer than any
71
+ * published release; core's own renderer draws it). An older parse strips it without a sign,
72
+ * so without it the bar's legend ("Red 8 · Amber 13 · Green 29") is written into the tile's
73
+ * `hint`, after any hint it had, and the bar is dropped.
74
+ * - `section.action`: a section's `action`, a press drawn at the right end of its title line
75
+ * (newer than any published release; core's own renderer draws it). An older parse strips it,
76
+ * so without it the action becomes a `button` with the same label and press, last in the
77
+ * section, and the reader can still go where it led. A full section drops it.
70
78
  */
71
- export type UiFeature = 'breadcrumbs' | 'button.disabled' | 'section.row' | 'form.field_kinds' | 'form.confirm' | 'press.chat' | 'form.radio' | 'table.cells' | 'header.meta' | 'tabs.many' | 'choice.action' | 'markdown.links' | 'form.disabled' | 'press.seek' | 'edit.inline' | 'timeline.time_tag';
79
+ export type UiFeature = 'breadcrumbs' | 'button.disabled' | 'section.row' | 'form.field_kinds' | 'form.confirm' | 'press.chat' | 'form.radio' | 'table.cells' | 'header.meta' | 'tabs.many' | 'choice.action' | 'markdown.links' | 'form.disabled' | 'press.seek' | 'edit.inline' | 'timeline.time_tag' | 'stat.bar' | 'section.action';
72
80
  /** The node types and features one ui-sdk release, or one client, draws. */
73
81
  export interface NodeSet {
74
82
  /** For messages: "ui-sdk 1.4.0", "mobile 0.2.5". */
@@ -105,7 +113,7 @@ export declare const UI_SDK_SNAPSHOTS: {
105
113
  readonly current: {
106
114
  readonly name: "ui-sdk (this package)";
107
115
  readonly nodes: readonly ["heading", "text", "markdown", "stat", "button", "form", "table", "timeline", "pending_request", "pending_requests", "choice_cards", "progress", "chart", "section", "tabs", "pagination", "select", "alert", "details", "timestamp", "divider", "board", "link", "tags", "toggle", "segmented", "progress_bar", "conversation", "composer", "calendar", "image", "video", "stacked_bar", "heatmap", "audio"];
108
- readonly features: readonly ["breadcrumbs", "button.disabled", "section.row", "form.field_kinds", "form.confirm", "press.chat", "form.radio", "table.cells", "header.meta", "tabs.many", "choice.action", "markdown.links", "form.disabled", "press.seek", "edit.inline", "timeline.time_tag"];
116
+ readonly features: readonly ["breadcrumbs", "button.disabled", "section.row", "form.field_kinds", "form.confirm", "press.chat", "form.radio", "table.cells", "header.meta", "tabs.many", "choice.action", "markdown.links", "form.disabled", "press.seek", "edit.inline", "timeline.time_tag", "stat.bar", "section.action"];
109
117
  };
110
118
  };
111
119
  export type UiSdkSnapshot = keyof typeof UI_SDK_SNAPSHOTS;
package/dist/negotiate.js CHANGED
@@ -50,6 +50,8 @@ const ALL_FEATURES = [
50
50
  'press.seek',
51
51
  'edit.inline',
52
52
  'timeline.time_tag',
53
+ 'stat.bar',
54
+ 'section.action',
53
55
  ];
54
56
  /** The nodes of ui-sdk 1.1.0 and 1.2.0 (one schema). */
55
57
  const NODES_1_1_0 = [
@@ -284,6 +286,7 @@ export function latestRelease(client) {
284
286
  const TEXT_MAX = 5000;
285
287
  const MARKDOWN_MAX = 20000;
286
288
  const CHILDREN_MAX = 100;
289
+ const STAT_HINT_MAX = 120;
287
290
  /** The fallback for a node type that has no specific one: a sign that something is there. */
288
291
  export const GENERIC_FALLBACK_TEXT = 'Open this in the web app to see this part of the screen.';
289
292
  /**
@@ -337,6 +340,9 @@ export function negotiateTree(tree, set) {
337
340
  fallbacks.push({ path, type: 'section', reason: 'section.row', as: 'folded' });
338
341
  next = { ...next, layout: 'stack' };
339
342
  }
343
+ if (next.action && !features.has('section.action')) {
344
+ next = foldSectionAction(next, path, fallbacks);
345
+ }
340
346
  return next;
341
347
  }
342
348
  case 'form': {
@@ -379,6 +385,17 @@ export function negotiateTree(tree, set) {
379
385
  });
380
386
  return changed ? { ...form, fields } : form;
381
387
  }
388
+ case 'stat': {
389
+ if (!node.bar || features.has('stat.bar'))
390
+ return node;
391
+ fallbacks.push({ path, type: 'stat', reason: 'stat.bar', as: 'folded' });
392
+ const { bar, ...tile } = node;
393
+ const { legend } = stackedBarParts({ label: node.label, ...bar });
394
+ return {
395
+ ...tile,
396
+ hint: clip(tile.hint ? `${tile.hint} · ${legend}` : legend, STAT_HINT_MAX),
397
+ };
398
+ }
382
399
  case 'choice_cards':
383
400
  return features.has('choice.action') ? node : foldChoiceActions(node, path, fallbacks);
384
401
  case 'timeline':
@@ -604,6 +621,38 @@ export function foldChoiceActions(node, path, fallbacks) {
604
621
  });
605
622
  return { ...node, choices };
606
623
  }
624
+ /**
625
+ * A section with its `action` moved into its body as a last `button`, for a client that does not
626
+ * draw the action on the title line (`section.action`). Dropped when the section is full.
627
+ */
628
+ function foldSectionAction(node, path, fallbacks) {
629
+ const { action, ...rest } = node;
630
+ if (!action)
631
+ return node;
632
+ if (rest.children.length >= CHILDREN_MAX) {
633
+ fallbacks.push({
634
+ path: `${path}.action`,
635
+ type: 'section',
636
+ reason: 'section.action',
637
+ as: 'dropped',
638
+ });
639
+ return rest;
640
+ }
641
+ fallbacks.push({
642
+ path: `${path}.action`,
643
+ type: 'section',
644
+ reason: 'section.action',
645
+ as: 'folded',
646
+ });
647
+ const button = {
648
+ type: 'button',
649
+ label: action.label,
650
+ onPress: action.onPress,
651
+ variant: 'secondary',
652
+ disabled: false,
653
+ };
654
+ return { ...rest, children: [...rest.children, button] };
655
+ }
607
656
  /**
608
657
  * The node as a client that draws no edit control should get it (`edit.inline`): the same block,
609
658
  * read-only. Drops `edit` from a `text`, `markdown` or `details` block and its items, and from each
@@ -674,6 +723,11 @@ function withoutPresses(node, path, fallbacks, matches, reason) {
674
723
  return node;
675
724
  dropped(`${path}.action`, 'button');
676
725
  return omit(node, 'action');
726
+ case 'section':
727
+ if (!node.action || !matches(node.action.onPress))
728
+ return node;
729
+ dropped(`${path}.action`, 'section');
730
+ return omit(node, 'action');
677
731
  case 'image':
678
732
  if (!matches(node.onPress))
679
733
  return node;
package/dist/schema.d.ts CHANGED
@@ -434,6 +434,21 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
434
434
  kind: z.ZodLiteral<"seek">;
435
435
  }, z.core.$strip>], "kind">>;
436
436
  selected: z.ZodOptional<z.ZodBoolean>;
437
+ bar: z.ZodOptional<z.ZodObject<{
438
+ segments: z.ZodArray<z.ZodObject<{
439
+ label: z.ZodString;
440
+ value: z.ZodNumber;
441
+ tone: z.ZodEnum<{
442
+ default: "default";
443
+ success: "success";
444
+ warning: "warning";
445
+ destructive: "destructive";
446
+ info: "info";
447
+ accent: "accent";
448
+ }>;
449
+ }, z.core.$strip>>;
450
+ max: z.ZodOptional<z.ZodNumber>;
451
+ }, z.core.$strip>>;
437
452
  }, z.core.$strip>, z.ZodObject<{
438
453
  type: z.ZodLiteral<"button">;
439
454
  label: z.ZodString;
@@ -804,6 +819,21 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
804
819
  kind: z.ZodLiteral<"seek">;
805
820
  }, z.core.$strip>], "kind">>;
806
821
  selected: z.ZodOptional<z.ZodBoolean>;
822
+ bar: z.ZodOptional<z.ZodObject<{
823
+ segments: z.ZodArray<z.ZodObject<{
824
+ label: z.ZodString;
825
+ value: z.ZodNumber;
826
+ tone: z.ZodEnum<{
827
+ default: "default";
828
+ success: "success";
829
+ warning: "warning";
830
+ destructive: "destructive";
831
+ info: "info";
832
+ accent: "accent";
833
+ }>;
834
+ }, z.core.$strip>>;
835
+ max: z.ZodOptional<z.ZodNumber>;
836
+ }, z.core.$strip>>;
807
837
  }, z.core.$strip>, z.ZodObject<{
808
838
  type: z.ZodLiteral<"button">;
809
839
  label: z.ZodString;
@@ -1889,6 +1919,10 @@ export type ScreenNode = LeafScreenNode | {
1889
1919
  badge?: string;
1890
1920
  badgeTone?: 'default' | 'success' | 'warning' | 'destructive' | 'info' | 'accent';
1891
1921
  icon?: UiIcon;
1922
+ action?: {
1923
+ label: string;
1924
+ onPress: Press;
1925
+ };
1892
1926
  children: ScreenNode[];
1893
1927
  };
1894
1928
  type ScreenNodeInput = LeafScreenNodeInput | {
@@ -1909,6 +1943,10 @@ type ScreenNodeInput = LeafScreenNodeInput | {
1909
1943
  badge?: string;
1910
1944
  badgeTone?: 'default' | 'success' | 'warning' | 'destructive' | 'info' | 'accent';
1911
1945
  icon?: UiIcon;
1946
+ action?: {
1947
+ label: string;
1948
+ onPress: z.input<typeof pressSchema>;
1949
+ };
1912
1950
  children: ScreenNodeInput[];
1913
1951
  };
1914
1952
  /**
package/dist/schema.js CHANGED
@@ -1293,6 +1293,41 @@ const heatmapSchema = z
1293
1293
  });
1294
1294
  }
1295
1295
  });
1296
+ /** One part of a bar split into coloured parts: a stacked bar's, or a stat tile's `bar`. */
1297
+ const barSegmentShape = z.object({
1298
+ label: z.string().min(1).max(40),
1299
+ value: z.number().finite().min(0),
1300
+ tone,
1301
+ });
1302
+ /** The rules between a split bar's segments and its `max`, at `path` in the node. */
1303
+ function checkBarSegments(bar, ctx, path) {
1304
+ const total = bar.segments.reduce((sum, segment) => sum + segment.value, 0);
1305
+ if (bar.max === undefined && total <= 0) {
1306
+ ctx.addIssue({
1307
+ code: 'custom',
1308
+ path: [...path, 'segments'],
1309
+ message: 'the segments add up to 0; set max to draw an empty bar',
1310
+ });
1311
+ }
1312
+ if (bar.max !== undefined && total > bar.max) {
1313
+ ctx.addIssue({
1314
+ code: 'custom',
1315
+ path: [...path, 'max'],
1316
+ message: `the segments add up to ${total}, more than max ${bar.max}`,
1317
+ });
1318
+ }
1319
+ const seen = new Set();
1320
+ bar.segments.forEach((segment, index) => {
1321
+ if (seen.has(segment.label)) {
1322
+ ctx.addIssue({
1323
+ code: 'custom',
1324
+ path: [...path, 'segments', index, 'label'],
1325
+ message: `two segments are labelled "${segment.label}"`,
1326
+ });
1327
+ }
1328
+ seen.add(segment.label);
1329
+ });
1330
+ }
1296
1331
  /**
1297
1332
  * One bar split into coloured parts: "12 red, 30 amber, 108 green accounts", "used, reserved,
1298
1333
  * free seats". Each segment is drawn in proportion to `max`, which defaults to the sum of the
@@ -1305,10 +1340,7 @@ const stackedBarSchema = z
1305
1340
  type: z.literal('stacked_bar'),
1306
1341
  label: z.string().min(1).max(80),
1307
1342
  segments: z
1308
- .array(z.object({
1309
- label: z.string().min(1).max(40),
1310
- value: z.number().finite().min(0),
1311
- tone,
1343
+ .array(barSegmentShape.extend({
1312
1344
  onPress: pressSchema.optional(),
1313
1345
  /** For segments that filter: true on the active one. Needs `onPress`. */
1314
1346
  selected: z.boolean().optional(),
@@ -1321,31 +1353,8 @@ const stackedBarSchema = z
1321
1353
  valueLabel: z.string().max(40).optional(),
1322
1354
  })
1323
1355
  .superRefine((node, ctx) => {
1324
- const total = node.segments.reduce((sum, segment) => sum + segment.value, 0);
1325
- if (node.max === undefined && total <= 0) {
1326
- ctx.addIssue({
1327
- code: 'custom',
1328
- path: ['segments'],
1329
- message: 'the segments add up to 0; set max to draw an empty bar',
1330
- });
1331
- }
1332
- if (node.max !== undefined && total > node.max) {
1333
- ctx.addIssue({
1334
- code: 'custom',
1335
- path: ['max'],
1336
- message: `the segments add up to ${total}, more than max ${node.max}`,
1337
- });
1338
- }
1339
- const seen = new Set();
1356
+ checkBarSegments(node, ctx, []);
1340
1357
  node.segments.forEach((segment, index) => {
1341
- if (seen.has(segment.label)) {
1342
- ctx.addIssue({
1343
- code: 'custom',
1344
- path: ['segments', index, 'label'],
1345
- message: `two segments are labelled "${segment.label}"`,
1346
- });
1347
- }
1348
- seen.add(segment.label);
1349
1358
  if (segment.selected !== undefined && !segment.onPress) {
1350
1359
  ctx.addIssue({
1351
1360
  code: 'custom',
@@ -1495,8 +1504,8 @@ const markdownSchema = z.object({
1495
1504
  edit: inlineEditSchema.optional(),
1496
1505
  });
1497
1506
  /**
1498
- * A number with its label: a KPI tile. All of `tone`, `trend`, `onPress` and
1499
- * `selected` are optional; a renderer that does not know them draws `label`,
1507
+ * A number with its label: a KPI tile. All of `tone`, `trend`, `onPress`,
1508
+ * `selected` and `bar` are optional; a renderer that does not know them draws `label`,
1500
1509
  * `value` and `hint` as before.
1501
1510
  *
1502
1511
  * - `tone` colours the tile for a red, amber or green count. The label must
@@ -1508,6 +1517,10 @@ const markdownSchema = z.object({
1508
1517
  * filter the list below it.
1509
1518
  * - `selected` is for a tile that filters: set it on every tile of the group,
1510
1519
  * true on the active one. It is drawn as pressed and said as pressed.
1520
+ * - `bar` is a small bar split into coloured parts under the value, the shape
1521
+ * of a `stacked_bar`'s segments: Book health 50, Red 8 · Amber 13 · Green 29.
1522
+ * The stat's `label` names it. A segment takes no press: the tile is one
1523
+ * control, and `onPress` is its press.
1511
1524
  */
1512
1525
  const statSchema = z
1513
1526
  .object({
@@ -1529,8 +1542,17 @@ const statSchema = z
1529
1542
  .optional(),
1530
1543
  onPress: pressSchema.optional(),
1531
1544
  selected: z.boolean().optional(),
1545
+ bar: z
1546
+ .object({
1547
+ segments: z.array(barSegmentShape).min(2).max(6),
1548
+ /** The whole the segments are parts of. Defaults to their sum. */
1549
+ max: z.number().finite().positive().optional(),
1550
+ })
1551
+ .optional(),
1532
1552
  })
1533
1553
  .superRefine((node, ctx) => {
1554
+ if (node.bar)
1555
+ checkBarSegments(node.bar, ctx, ['bar']);
1534
1556
  if (node.selected !== undefined && !node.onPress) {
1535
1557
  ctx.addIssue({
1536
1558
  code: 'custom',
@@ -2253,6 +2275,16 @@ const sectionShape = (children) => z.object({
2253
2275
  * apart at a glance. Decorative: the title says what the section is. Needs a `title`.
2254
2276
  */
2255
2277
  icon: z.enum(UI_ICONS).optional(),
2278
+ /**
2279
+ * A press at the right end of the title line: "All", "Open", "See all 13 amber". Drawn as a
2280
+ * quiet text button, so the label says where it goes. Needs a `title`.
2281
+ */
2282
+ action: z
2283
+ .object({
2284
+ label: z.string().min(1).max(40),
2285
+ onPress: pressSchema,
2286
+ })
2287
+ .optional(),
2256
2288
  children: z.array(children).max(100),
2257
2289
  });
2258
2290
  /** The rules between a section's fields, which a field's own schema cannot state. */
@@ -2322,6 +2354,13 @@ function checkSection(node, ctx) {
2322
2354
  message: 'a section icon sits before its title, so it needs a title',
2323
2355
  });
2324
2356
  }
2357
+ if (node.action !== undefined && !node.title) {
2358
+ ctx.addIssue({
2359
+ code: 'custom',
2360
+ path: ['action'],
2361
+ message: 'a section action sits on its title line, so it needs a title',
2362
+ });
2363
+ }
2325
2364
  }
2326
2365
  const sectionBranch = (children) => sectionShape(children).superRefine(checkSection);
2327
2366
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/ui-sdk",
3
- "version": "1.6.0-dev-20261027083052",
3
+ "version": "1.6.0-dev-20261027084552",
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",