@keemakr/ui-sdk 1.5.0-dev-20261022123413 → 1.5.0-dev-20261022124244

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
@@ -12,6 +12,8 @@ export { PUBLISHED_PARSERS, type PublishedParser } from './published/index.js';
12
12
  export { MEDIA_CONTENT_TYPES, mediaContentType, mediaPathOf } from './media.js';
13
13
  export { formPress, formSubmits, initialDraft, isoToLocalInput, localInputToIso, postedValue, } from './form.js';
14
14
  export type { FormDraft, FormFieldKind, FormFieldLike, FormSubmit } from './form.js';
15
+ export { stackedBarParts, stackedBarValue } from './stacked-bar.js';
16
+ export type { StackedBarLike, StackedBarParts, StackedBarSegmentPart } from './stacked-bar.js';
15
17
  export { statTrend } from './stat.js';
16
18
  export type { StatTrend, StatTrendFeel, StatTrendLike } from './stat.js';
17
19
  export { composerPress, composerShortcut } from './composer.js';
package/dist/index.js CHANGED
@@ -15,6 +15,7 @@ export { CLIENT_RELEASES, CORE_DRAWN_NODE_TYPES, CURRENT_UI_SDK_SNAPSHOT, FLOOR_
15
15
  export { PUBLISHED_PARSERS } from './published/index.js';
16
16
  export { MEDIA_CONTENT_TYPES, mediaContentType, mediaPathOf } from './media.js';
17
17
  export { formPress, formSubmits, initialDraft, isoToLocalInput, localInputToIso, postedValue, } from './form.js';
18
+ export { stackedBarParts, stackedBarValue } from './stacked-bar.js';
18
19
  export { statTrend } from './stat.js';
19
20
  export { composerPress, composerShortcut } from './composer.js';
20
21
  export { addDays, calendarDays, dayStartMs, entriesOnDay, intlTimeZone, isTimeZone, placeEntries, shiftCalendarDate, slotIsFree, slotTimes, todayIn, } from './calendar.js';
@@ -57,7 +57,7 @@ export declare const UI_SDK_SNAPSHOTS: {
57
57
  };
58
58
  readonly current: {
59
59
  readonly name: "ui-sdk (this package)";
60
- 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"];
60
+ 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"];
61
61
  readonly features: readonly ["breadcrumbs", "button.disabled", "section.row", "form.field_kinds", "form.confirm", "press.chat", "form.radio"];
62
62
  };
63
63
  };
package/dist/negotiate.js CHANGED
@@ -22,6 +22,7 @@
22
22
  // parses with that row's published schema with no safety field lost.
23
23
  import { conformTree } from './conform.js';
24
24
  import { pageRangeLabel } from './pager.js';
25
+ import { stackedBarParts } from './stacked-bar.js';
25
26
  import { PUBLISHED_PARSERS } from './published/index.js';
26
27
  /** The features ui-sdk 1.4.0 draws: every one but those added after it. */
27
28
  const FEATURES_1_4_0 = [
@@ -76,6 +77,12 @@ const NODES_1_4_0 = [
76
77
  'image',
77
78
  'video',
78
79
  ];
80
+ /**
81
+ * The nodes of this package: every published 1.4.0 node, and the ones added since. A node added
82
+ * here reaches a client only once a row below says that client draws it; until then it gets its
83
+ * fallback (`fallbackNode`).
84
+ */
85
+ const NODES_CURRENT = [...NODES_1_4_0, 'stacked_bar'];
79
86
  /**
80
87
  * Nodes a module may send that core draws itself before any client sees the tree: a `dataset`
81
88
  * node becomes plain blocks from the module's rows (dataset-view.ts). No client parses them, so
@@ -89,7 +96,7 @@ export const CORE_DRAWN_NODE_TYPES = ['dataset'];
89
96
  export const UI_SDK_SNAPSHOTS = {
90
97
  '1.1.0': { name: 'ui-sdk 1.1.0', nodes: NODES_1_1_0, features: [] },
91
98
  '1.4.0': { name: 'ui-sdk 1.4.0', nodes: NODES_1_4_0, features: FEATURES_1_4_0 },
92
- current: { name: 'ui-sdk (this package)', nodes: NODES_1_4_0, features: ALL_FEATURES },
99
+ current: { name: 'ui-sdk (this package)', nodes: NODES_CURRENT, features: ALL_FEATURES },
93
100
  };
94
101
  /** The snapshot this package is. Core's own renderer draws all of it. */
95
102
  export const CURRENT_UI_SDK_SNAPSHOT = 'current';
@@ -638,6 +645,8 @@ export function fallbackNode(node, timeZone) {
638
645
  }
639
646
  case 'progress_bar':
640
647
  return text(`${n.label}: ${n.valueLabel ?? `${n.value} of ${n.max}`}`, false);
648
+ case 'stacked_bar':
649
+ return text(stackedBarParts(n).summary, false);
641
650
  case 'board': {
642
651
  const columns = n.columns.map((column) => {
643
652
  const cards = column.cards.map((card) => `- ${escapeMarkdown(card.title)}`);
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", "pagination", "select", "alert", "details", "timestamp", "divider", "board", "link", "tags", "toggle", "segmented", "progress_bar", "conversation", "composer", "calendar", "image", "video", "dataset", "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", "alert", "details", "timestamp", "divider", "board", "link", "tags", "toggle", "segmented", "progress_bar", "stacked_bar", "conversation", "composer", "calendar", "image", "video", "dataset", "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
@@ -35,6 +35,7 @@ export const KNOWN_NODE_TYPES = [
35
35
  'toggle',
36
36
  'segmented',
37
37
  'progress_bar',
38
+ 'stacked_bar',
38
39
  'conversation',
39
40
  'composer',
40
41
  'calendar',
package/dist/schema.d.ts CHANGED
@@ -872,6 +872,38 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
872
872
  accent: "accent";
873
873
  }>>;
874
874
  valueLabel: z.ZodOptional<z.ZodString>;
875
+ }, z.core.$strip>, z.ZodObject<{
876
+ type: z.ZodLiteral<"stacked_bar">;
877
+ label: z.ZodString;
878
+ segments: z.ZodArray<z.ZodObject<{
879
+ label: z.ZodString;
880
+ value: z.ZodNumber;
881
+ tone: z.ZodEnum<{
882
+ default: "default";
883
+ success: "success";
884
+ warning: "warning";
885
+ destructive: "destructive";
886
+ info: "info";
887
+ accent: "accent";
888
+ }>;
889
+ onPress: z.ZodOptional<z.ZodDiscriminatedUnion<[z.ZodObject<{
890
+ kind: z.ZodLiteral<"action">;
891
+ action: z.ZodString;
892
+ input: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
893
+ confirm: z.ZodOptional<z.ZodString>;
894
+ }, z.core.$strip>, z.ZodObject<{
895
+ kind: z.ZodLiteral<"navigate">;
896
+ screen: z.ZodString;
897
+ params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
898
+ }, z.core.$strip>, z.ZodObject<{
899
+ kind: z.ZodLiteral<"chat">;
900
+ prompt: z.ZodString;
901
+ agent: z.ZodOptional<z.ZodString>;
902
+ }, z.core.$strip>], "kind">>;
903
+ selected: z.ZodOptional<z.ZodBoolean>;
904
+ }, z.core.$strip>>;
905
+ max: z.ZodOptional<z.ZodNumber>;
906
+ valueLabel: z.ZodOptional<z.ZodString>;
875
907
  }, z.core.$strip>, z.ZodObject<{
876
908
  type: z.ZodLiteral<"conversation">;
877
909
  messages: z.ZodArray<z.ZodObject<{
package/dist/schema.js CHANGED
@@ -949,6 +949,68 @@ const progressBarSchema = z
949
949
  });
950
950
  }
951
951
  });
952
+ /**
953
+ * One bar split into coloured parts: "12 red, 30 amber, 108 green accounts", "used, reserved,
954
+ * free seats". Each segment is drawn in proportion to `max`, which defaults to the sum of the
955
+ * segments. A legend under the bar writes each segment's label and value ("Red 12 · Amber 30 ·
956
+ * Green 108"), so colour is never the only signal. A segment with `onPress` is a button in the
957
+ * legend (a red/amber/green bar that filters the list below); `selected` marks the active one.
958
+ */
959
+ const stackedBarSchema = z
960
+ .object({
961
+ type: z.literal('stacked_bar'),
962
+ label: z.string().min(1).max(80),
963
+ segments: z
964
+ .array(z.object({
965
+ label: z.string().min(1).max(40),
966
+ value: z.number().finite().min(0),
967
+ tone,
968
+ onPress: pressSchema.optional(),
969
+ /** For segments that filter: true on the active one. Needs `onPress`. */
970
+ selected: z.boolean().optional(),
971
+ }))
972
+ .min(2)
973
+ .max(6),
974
+ /** The whole the segments are parts of. Defaults to their sum; set it to leave room. */
975
+ max: z.number().finite().positive().optional(),
976
+ /** Shown after the label: "150 accounts". */
977
+ valueLabel: z.string().max(40).optional(),
978
+ })
979
+ .superRefine((node, ctx) => {
980
+ const total = node.segments.reduce((sum, segment) => sum + segment.value, 0);
981
+ if (node.max === undefined && total <= 0) {
982
+ ctx.addIssue({
983
+ code: 'custom',
984
+ path: ['segments'],
985
+ message: 'the segments add up to 0; set max to draw an empty bar',
986
+ });
987
+ }
988
+ if (node.max !== undefined && total > node.max) {
989
+ ctx.addIssue({
990
+ code: 'custom',
991
+ path: ['max'],
992
+ message: `the segments add up to ${total}, more than max ${node.max}`,
993
+ });
994
+ }
995
+ const seen = new Set();
996
+ node.segments.forEach((segment, index) => {
997
+ if (seen.has(segment.label)) {
998
+ ctx.addIssue({
999
+ code: 'custom',
1000
+ path: ['segments', index, 'label'],
1001
+ message: `two segments are labelled "${segment.label}"`,
1002
+ });
1003
+ }
1004
+ seen.add(segment.label);
1005
+ if (segment.selected !== undefined && !segment.onPress) {
1006
+ ctx.addIssue({
1007
+ code: 'custom',
1008
+ path: ['segments', index, 'selected'],
1009
+ message: 'selected needs onPress',
1010
+ });
1011
+ }
1012
+ });
1013
+ });
952
1014
  /**
953
1015
  * A file inside the module's own runtime: "patients/p-17/scan.jpg". Never a
954
1016
  * URL. Core fetches it from the runtime's GET /screens/media/<path> with the
@@ -1586,6 +1648,7 @@ const leafNodeSchema = z.discriminatedUnion('type', [
1586
1648
  toggleSchema,
1587
1649
  segmentedSchema,
1588
1650
  progressBarSchema,
1651
+ stackedBarSchema,
1589
1652
  conversationSchema,
1590
1653
  composerSchema,
1591
1654
  calendarSchema,
@@ -0,0 +1,34 @@
1
+ import type { ScreenRootNode } from './schema.js';
2
+ type StackedBarNode = Extract<ScreenRootNode, {
3
+ type: 'stacked_bar';
4
+ }>;
5
+ type Segment = StackedBarNode['segments'][number];
6
+ /** The fields `stackedBarParts` reads. A client on an older SDK type can pass its own shape. */
7
+ export interface StackedBarLike {
8
+ label: string;
9
+ segments: ReadonlyArray<Pick<Segment, 'label' | 'value'> & Partial<Segment>>;
10
+ max?: number;
11
+ valueLabel?: string;
12
+ }
13
+ export interface StackedBarSegmentPart<S> {
14
+ segment: S;
15
+ /** Width in percent of the whole bar, 0 to 100, not rounded: the parts add up exactly. */
16
+ percent: number;
17
+ /** "Red 12". */
18
+ text: string;
19
+ }
20
+ export interface StackedBarParts<S> {
21
+ /** The whole the widths are measured against: `max`, or the sum of the segments. */
22
+ max: number;
23
+ total: number;
24
+ segments: StackedBarSegmentPart<S>[];
25
+ /** "Red 12 · Amber 30 · Green 108". */
26
+ legend: string;
27
+ /** "Book health (150 accounts): Red 12 · Amber 30 · Green 108". */
28
+ summary: string;
29
+ }
30
+ /** A segment value as the legend writes it, the same in every runtime: 1,200 and 2.5. */
31
+ export declare function stackedBarValue(value: number): string;
32
+ /** Widths and words for a stacked bar. */
33
+ export declare function stackedBarParts<N extends StackedBarLike>(node: N): StackedBarParts<N['segments'][number]>;
34
+ export {};
@@ -0,0 +1,20 @@
1
+ // A stacked bar's geometry and words, shared by core's renderer, the clients and the fallback
2
+ // line an older app gets, so every surface draws the same widths and writes the same legend.
3
+ const NUMBER = new Intl.NumberFormat('en-US', { maximumFractionDigits: 2 });
4
+ /** A segment value as the legend writes it, the same in every runtime: 1,200 and 2.5. */
5
+ export function stackedBarValue(value) {
6
+ return NUMBER.format(value);
7
+ }
8
+ /** Widths and words for a stacked bar. */
9
+ export function stackedBarParts(node) {
10
+ const total = node.segments.reduce((sum, segment) => sum + segment.value, 0);
11
+ const max = node.max ?? total;
12
+ const segments = node.segments.map((segment) => ({
13
+ segment,
14
+ percent: max > 0 ? Math.min(100, (segment.value / max) * 100) : 0,
15
+ text: `${segment.label} ${stackedBarValue(segment.value)}`,
16
+ }));
17
+ const legend = segments.map((part) => part.text).join(' · ');
18
+ const head = node.valueLabel ? `${node.label} (${node.valueLabel})` : node.label;
19
+ return { max, total, segments, legend, summary: `${head}: ${legend}` };
20
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/ui-sdk",
3
- "version": "1.5.0-dev-20261022123413",
3
+ "version": "1.5.0-dev-20261022124244",
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",