@keemakr/ui-sdk 1.5.0-dev-20261022120138 → 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/conform.js +13 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/negotiate.d.ts +1 -1
- package/dist/negotiate.js +10 -1
- package/dist/nodes.d.ts +1 -1
- package/dist/nodes.js +1 -0
- package/dist/schema.d.ts +35 -0
- package/dist/schema.js +81 -1
- package/dist/stacked-bar.d.ts +34 -0
- package/dist/stacked-bar.js +20 -0
- package/package.json +1 -1
package/dist/conform.js
CHANGED
|
@@ -5,6 +5,8 @@
|
|
|
5
5
|
//
|
|
6
6
|
// 1. A value or shape the app's parse REFUSES fails the whole screen. Known ones are folded to the
|
|
7
7
|
// nearest value the parse takes; anything else replaces the smallest node that holds it:
|
|
8
|
+
// - a chart's `chartType: 'area'` (after 1.4.0) -> 'line' (a chart's `stacked` and
|
|
9
|
+
// `legend` are stripped by such a parse, so its bars are drawn side by side)
|
|
8
10
|
// - `tone: 'info' | 'accent'` (badge cells, tags, board columns, calendar entries, progress
|
|
9
11
|
// bars; after 1.4.0) -> 'default', or the first tone that parse lists
|
|
10
12
|
// - a string `min`/`max` on a date or datetime field (after 1.4.0) -> dropped
|
|
@@ -198,6 +200,17 @@ export function conformTree(tree, parser, options) {
|
|
|
198
200
|
fallbacks.push({ path: pathText(path), type: 'tone', reason: 'parse', as: 'folded' });
|
|
199
201
|
return true;
|
|
200
202
|
}
|
|
203
|
+
if (key === 'chartType' &&
|
|
204
|
+
issue.code === 'invalid_value' &&
|
|
205
|
+
isObject(holder) &&
|
|
206
|
+
holder.type === 'chart' &&
|
|
207
|
+
holder.chartType === 'area' &&
|
|
208
|
+
(issue.values ?? []).includes('line')) {
|
|
209
|
+
// An area is a line with the room under it filled: the line keeps the trend.
|
|
210
|
+
holder.chartType = 'line';
|
|
211
|
+
fallbacks.push({ path: pathText(path), type: 'chartType', reason: 'parse', as: 'folded' });
|
|
212
|
+
return true;
|
|
213
|
+
}
|
|
201
214
|
if ((key === 'min' || key === 'max') && isObject(holder) && key in holder) {
|
|
202
215
|
delete holder[key];
|
|
203
216
|
fallbacks.push({ path: pathText(path), type: String(key), reason: 'parse', as: 'folded' });
|
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';
|
package/dist/negotiate.d.ts
CHANGED
|
@@ -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:
|
|
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
package/dist/schema.d.ts
CHANGED
|
@@ -565,8 +565,11 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
565
565
|
chartType: z.ZodEnum<{
|
|
566
566
|
bar: "bar";
|
|
567
567
|
line: "line";
|
|
568
|
+
area: "area";
|
|
568
569
|
}>;
|
|
569
570
|
title: z.ZodOptional<z.ZodString>;
|
|
571
|
+
stacked: z.ZodOptional<z.ZodBoolean>;
|
|
572
|
+
legend: z.ZodOptional<z.ZodBoolean>;
|
|
570
573
|
orientation: z.ZodDefault<z.ZodEnum<{
|
|
571
574
|
horizontal: "horizontal";
|
|
572
575
|
vertical: "vertical";
|
|
@@ -869,6 +872,38 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
|
|
|
869
872
|
accent: "accent";
|
|
870
873
|
}>>;
|
|
871
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>;
|
|
872
907
|
}, z.core.$strip>, z.ZodObject<{
|
|
873
908
|
type: z.ZodLiteral<"conversation">;
|
|
874
909
|
messages: z.ZodArray<z.ZodObject<{
|
package/dist/schema.js
CHANGED
|
@@ -191,8 +191,25 @@ const progressSchema = z.object({
|
|
|
191
191
|
const chartSchema = z
|
|
192
192
|
.object({
|
|
193
193
|
type: z.literal('chart'),
|
|
194
|
-
|
|
194
|
+
/**
|
|
195
|
+
* `area` is a line with the room under it filled: a trend whose size matters, such as usage
|
|
196
|
+
* over 30 days. An app whose parse knows only `bar` and `line` gets an area as a line.
|
|
197
|
+
*/
|
|
198
|
+
chartType: z.enum(['bar', 'line', 'area']),
|
|
195
199
|
title: z.string().max(120).optional(),
|
|
200
|
+
/**
|
|
201
|
+
* Bars or areas of every series stacked on each other in one column (or one row, for
|
|
202
|
+
* horizontal bars), so the stack shows the total and each part of it: a revenue mix.
|
|
203
|
+
* `showValues` then writes the total at the end of each stack. Lines ignore it. An app that
|
|
204
|
+
* does not know it draws the series side by side.
|
|
205
|
+
*/
|
|
206
|
+
stacked: z.boolean().optional(),
|
|
207
|
+
/**
|
|
208
|
+
* The key that names each series beside its colour. Shown by default. `false` hides it, but
|
|
209
|
+
* only on a one-series chart: with more series the key stays, so colour is never the only
|
|
210
|
+
* way to tell them apart.
|
|
211
|
+
*/
|
|
212
|
+
legend: z.boolean().optional(),
|
|
196
213
|
/**
|
|
197
214
|
* Bars run up from the bottom (`vertical`) or along from the left
|
|
198
215
|
* (`horizontal`). Horizontal bars put each category's name beside its bar,
|
|
@@ -932,6 +949,68 @@ const progressBarSchema = z
|
|
|
932
949
|
});
|
|
933
950
|
}
|
|
934
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
|
+
});
|
|
935
1014
|
/**
|
|
936
1015
|
* A file inside the module's own runtime: "patients/p-17/scan.jpg". Never a
|
|
937
1016
|
* URL. Core fetches it from the runtime's GET /screens/media/<path> with the
|
|
@@ -1569,6 +1648,7 @@ const leafNodeSchema = z.discriminatedUnion('type', [
|
|
|
1569
1648
|
toggleSchema,
|
|
1570
1649
|
segmentedSchema,
|
|
1571
1650
|
progressBarSchema,
|
|
1651
|
+
stackedBarSchema,
|
|
1572
1652
|
conversationSchema,
|
|
1573
1653
|
composerSchema,
|
|
1574
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-
|
|
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",
|