@keemakr/ui-sdk 1.6.0-dev-20261027082128 → 1.6.0-dev-20261027083656

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,12 @@ 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.
70
74
  */
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';
75
+ 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';
72
76
  /** The node types and features one ui-sdk release, or one client, draws. */
73
77
  export interface NodeSet {
74
78
  /** For messages: "ui-sdk 1.4.0", "mobile 0.2.5". */
@@ -105,7 +109,7 @@ export declare const UI_SDK_SNAPSHOTS: {
105
109
  readonly current: {
106
110
  readonly name: "ui-sdk (this package)";
107
111
  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"];
112
+ 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"];
109
113
  };
110
114
  };
111
115
  export type UiSdkSnapshot = keyof typeof UI_SDK_SNAPSHOTS;
package/dist/negotiate.js CHANGED
@@ -50,6 +50,7 @@ const ALL_FEATURES = [
50
50
  'press.seek',
51
51
  'edit.inline',
52
52
  'timeline.time_tag',
53
+ 'stat.bar',
53
54
  ];
54
55
  /** The nodes of ui-sdk 1.1.0 and 1.2.0 (one schema). */
55
56
  const NODES_1_1_0 = [
@@ -284,6 +285,7 @@ export function latestRelease(client) {
284
285
  const TEXT_MAX = 5000;
285
286
  const MARKDOWN_MAX = 20000;
286
287
  const CHILDREN_MAX = 100;
288
+ const STAT_HINT_MAX = 120;
287
289
  /** The fallback for a node type that has no specific one: a sign that something is there. */
288
290
  export const GENERIC_FALLBACK_TEXT = 'Open this in the web app to see this part of the screen.';
289
291
  /**
@@ -379,6 +381,17 @@ export function negotiateTree(tree, set) {
379
381
  });
380
382
  return changed ? { ...form, fields } : form;
381
383
  }
384
+ case 'stat': {
385
+ if (!node.bar || features.has('stat.bar'))
386
+ return node;
387
+ fallbacks.push({ path, type: 'stat', reason: 'stat.bar', as: 'folded' });
388
+ const { bar, ...tile } = node;
389
+ const { legend } = stackedBarParts({ label: node.label, ...bar });
390
+ return {
391
+ ...tile,
392
+ hint: clip(tile.hint ? `${tile.hint} · ${legend}` : legend, STAT_HINT_MAX),
393
+ };
394
+ }
382
395
  case 'choice_cards':
383
396
  return features.has('choice.action') ? node : foldChoiceActions(node, path, fallbacks);
384
397
  case 'timeline':
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;
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',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/ui-sdk",
3
- "version": "1.6.0-dev-20261027082128",
3
+ "version": "1.6.0-dev-20261027083656",
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",