@keemakr/ui-sdk 1.4.0-dev-20261012123722 → 1.4.0-dev-20261012124454

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/form.d.ts ADDED
@@ -0,0 +1,19 @@
1
+ export type FormFieldKind = 'text' | 'textarea' | 'select' | 'number' | 'date' | 'datetime' | 'checkbox' | 'multiselect' | 'combobox' | 'list';
2
+ export interface FormFieldLike {
3
+ kind: FormFieldKind;
4
+ value?: string;
5
+ values?: string[];
6
+ checked?: boolean;
7
+ }
8
+ /** What a renderer holds while the reader edits: text for the one-value kinds
9
+ * (a datetime as the local `YYYY-MM-DDTHH:mm` a datetime input shows), a
10
+ * boolean for a checkbox, a list for multiselect and list. */
11
+ export type FormDraft = string | boolean | string[];
12
+ /** The ISO moment as a datetime input's local `YYYY-MM-DDTHH:mm`, or ''. */
13
+ export declare function isoToLocalInput(iso: string | undefined): string;
14
+ /** A datetime input's local `YYYY-MM-DDTHH:mm` as ISO 8601 in UTC, or ''. */
15
+ export declare function localInputToIso(local: string): string;
16
+ /** The draft a field starts from. */
17
+ export declare function initialDraft(field: FormFieldLike): FormDraft;
18
+ /** What the module receives for a field. See the form schema for each kind. */
19
+ export declare function postedValue(field: Pick<FormFieldLike, 'kind'>, draft: FormDraft): string | number | boolean | string[] | null;
package/dist/form.js ADDED
@@ -0,0 +1,53 @@
1
+ // Renderer-side helpers for the `form` node. A form posts typed values (a
2
+ // number, a boolean, a list), so the rule for turning what the reader typed into
3
+ // what the module receives lives here, once, for core and every client.
4
+ /** The ISO moment as a datetime input's local `YYYY-MM-DDTHH:mm`, or ''. */
5
+ export function isoToLocalInput(iso) {
6
+ if (!iso)
7
+ return '';
8
+ const date = new Date(iso);
9
+ if (Number.isNaN(date.getTime()))
10
+ return '';
11
+ const pad = (n) => String(n).padStart(2, '0');
12
+ return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
13
+ }
14
+ /** A datetime input's local `YYYY-MM-DDTHH:mm` as ISO 8601 in UTC, or ''. */
15
+ export function localInputToIso(local) {
16
+ if (!local)
17
+ return '';
18
+ const date = new Date(local);
19
+ return Number.isNaN(date.getTime()) ? '' : date.toISOString();
20
+ }
21
+ /** The draft a field starts from. */
22
+ export function initialDraft(field) {
23
+ if (field.kind === 'checkbox')
24
+ return field.checked ?? false;
25
+ if (field.kind === 'multiselect' || field.kind === 'list')
26
+ return field.values ?? [];
27
+ if (field.kind === 'datetime')
28
+ return isoToLocalInput(field.value);
29
+ return field.value ?? '';
30
+ }
31
+ /** What the module receives for a field. See the form schema for each kind. */
32
+ export function postedValue(field, draft) {
33
+ switch (field.kind) {
34
+ case 'checkbox':
35
+ return draft === true;
36
+ case 'multiselect':
37
+ return Array.isArray(draft) ? draft : [];
38
+ case 'list':
39
+ // Blank rows are rows the reader added and left, not values.
40
+ return Array.isArray(draft) ? draft.map((v) => v.trim()).filter(Boolean) : [];
41
+ case 'number': {
42
+ const text = typeof draft === 'string' ? draft.trim() : '';
43
+ if (text === '')
44
+ return null;
45
+ const n = Number(text);
46
+ return Number.isFinite(n) ? n : null;
47
+ }
48
+ case 'datetime':
49
+ return localInputToIso(typeof draft === 'string' ? draft : '');
50
+ default:
51
+ return typeof draft === 'string' ? draft : '';
52
+ }
53
+ }
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ export type { Press, ScreenPresentation, ScreenNode, ScreenRootNode, ScreenTree,
3
3
  export { childNodesOf, KNOWN_CONTAINERS, KNOWN_NODE_TYPES } from './nodes.js';
4
4
  export type { ContainerChild, ContainerNodeType, KnownNodeType } from './nodes.js';
5
5
  export { pageRangeLabel, pageWindow, pressWithValue } from './pager.js';
6
+ export { initialDraft, isoToLocalInput, localInputToIso, postedValue } from './form.js';
7
+ export type { FormDraft, FormFieldKind, FormFieldLike } from './form.js';
6
8
  export { composerPress, composerShortcut } from './composer.js';
7
9
  export type { ComposerKey, ComposerShortcut } from './composer.js';
8
10
  export { addDays, calendarDays, dayStartMs, entriesOnDay, placeEntries, shiftCalendarDate, slotIsFree, slotTimes, todayIn, } from './calendar.js';
package/dist/index.js CHANGED
@@ -9,6 +9,7 @@
9
9
  export { UI_SCHEMA_VERSION, pressSchema, buttonSchema, cellSchema, nodeSchema, screenPresentationSchema, screenTreeSchema, actionResultSchema, screenLoadRequestSchema, screenLoadResponseSchema, screenActionRequestSchema, interfaceFamilySchema, surfaceDefinitionSchema, surfaceSchema, screenRegistrationSchema, uiManifestSchema, } from './schema.js';
10
10
  export { childNodesOf, KNOWN_CONTAINERS, KNOWN_NODE_TYPES } from './nodes.js';
11
11
  export { pageRangeLabel, pageWindow, pressWithValue } from './pager.js';
12
+ export { initialDraft, isoToLocalInput, localInputToIso, postedValue } from './form.js';
12
13
  export { composerPress, composerShortcut } from './composer.js';
13
14
  export { addDays, calendarDays, dayStartMs, entriesOnDay, placeEntries, shiftCalendarDate, slotIsFree, slotTimes, todayIn, } from './calendar.js';
14
15
  export { defineScreen, defineSurface } from './define.js';
package/dist/schema.d.ts CHANGED
@@ -103,22 +103,37 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
103
103
  key: z.ZodString;
104
104
  fields: z.ZodArray<z.ZodObject<{
105
105
  kind: z.ZodEnum<{
106
+ number: "number";
107
+ date: "date";
106
108
  text: "text";
107
109
  select: "select";
110
+ datetime: "datetime";
108
111
  textarea: "textarea";
112
+ checkbox: "checkbox";
113
+ multiselect: "multiselect";
114
+ combobox: "combobox";
115
+ list: "list";
109
116
  }>;
110
117
  name: z.ZodString;
111
118
  label: z.ZodString;
112
119
  value: z.ZodOptional<z.ZodString>;
120
+ values: z.ZodOptional<z.ZodArray<z.ZodString>>;
121
+ checked: z.ZodOptional<z.ZodBoolean>;
113
122
  options: z.ZodOptional<z.ZodArray<z.ZodObject<{
114
123
  value: z.ZodString;
115
124
  label: z.ZodString;
116
125
  }, z.core.$strip>>>;
117
126
  required: z.ZodDefault<z.ZodBoolean>;
127
+ placeholder: z.ZodOptional<z.ZodString>;
128
+ hint: z.ZodOptional<z.ZodString>;
129
+ min: z.ZodOptional<z.ZodNumber>;
130
+ max: z.ZodOptional<z.ZodNumber>;
131
+ step: z.ZodOptional<z.ZodNumber>;
118
132
  }, z.core.$strip>>;
119
133
  submit: z.ZodObject<{
120
134
  label: z.ZodString;
121
135
  action: z.ZodString;
136
+ confirm: z.ZodOptional<z.ZodString>;
122
137
  }, z.core.$strip>;
123
138
  }, z.core.$strip>, z.ZodObject<{
124
139
  type: z.ZodLiteral<"table">;
package/dist/schema.js CHANGED
@@ -746,21 +746,122 @@ const leafNodeSchema = z.discriminatedUnion('type', [
746
746
  markdownSchema,
747
747
  statSchema,
748
748
  buttonSchema,
749
- z.object({
749
+ z
750
+ .object({
750
751
  type: z.literal('form'),
751
752
  key: slug,
752
753
  fields: z
753
754
  .array(z.object({
754
- kind: z.enum(['text', 'textarea', 'select']),
755
+ /**
756
+ * What each kind posts under its name:
757
+ * - text, textarea, select, combobox: the string ('' when empty).
758
+ * - number: a number, or null when empty.
759
+ * - date: YYYY-MM-DD, or ''.
760
+ * - datetime: ISO 8601 in UTC, picked in the viewer's zone, or ''.
761
+ * - checkbox: true or false.
762
+ * - multiselect, list: an array of strings.
763
+ * A combobox suggests its options and also takes typed text.
764
+ */
765
+ kind: z.enum([
766
+ 'text',
767
+ 'textarea',
768
+ 'select',
769
+ 'number',
770
+ 'date',
771
+ 'datetime',
772
+ 'checkbox',
773
+ 'multiselect',
774
+ 'combobox',
775
+ 'list',
776
+ ]),
755
777
  name: slug,
756
778
  label: z.string().max(80),
779
+ /** The starting value for the single-value kinds. A datetime takes ISO 8601. */
757
780
  value: z.string().max(20000).optional(),
758
- options: z.array(z.object({ value: z.string(), label: z.string() })).optional(),
781
+ /** The starting values for multiselect and list. */
782
+ values: z.array(z.string().max(500)).max(100).optional(),
783
+ /** The starting state for a checkbox. */
784
+ checked: z.boolean().optional(),
785
+ options: z
786
+ .array(z.object({ value: z.string(), label: z.string() }))
787
+ .max(200)
788
+ .optional(),
759
789
  required: z.boolean().default(false),
790
+ placeholder: z.string().max(120).optional(),
791
+ /** Shown under the field. */
792
+ hint: z.string().max(200).optional(),
793
+ min: z.number().finite().optional(),
794
+ max: z.number().finite().optional(),
795
+ step: z.number().finite().positive().optional(),
760
796
  }))
761
797
  .max(30),
762
798
  /** Field values are posted as the action's `input`, keyed by field name. */
763
- submit: z.object({ label: z.string().max(80), action: slug }),
799
+ submit: z.object({
800
+ label: z.string().max(80),
801
+ action: slug,
802
+ /** Asked before the form posts, as a button's confirm is. */
803
+ confirm: z.string().max(500).optional(),
804
+ }),
805
+ })
806
+ .superRefine((node, ctx) => {
807
+ const names = new Set();
808
+ for (const [i, field] of node.fields.entries()) {
809
+ const at = (key) => ['fields', i, key];
810
+ if (names.has(field.name)) {
811
+ ctx.addIssue({
812
+ code: 'custom',
813
+ path: at('name'),
814
+ message: `duplicate field name "${field.name}"`,
815
+ });
816
+ }
817
+ names.add(field.name);
818
+ const needsOptions = ['select', 'multiselect', 'combobox'].includes(field.kind);
819
+ if (needsOptions && !field.options?.length) {
820
+ ctx.addIssue({
821
+ code: 'custom',
822
+ path: at('options'),
823
+ message: `a ${field.kind} field needs options`,
824
+ });
825
+ }
826
+ if (field.values !== undefined && field.kind !== 'multiselect' && field.kind !== 'list') {
827
+ ctx.addIssue({
828
+ code: 'custom',
829
+ path: at('values'),
830
+ message: 'values is for multiselect and list fields',
831
+ });
832
+ }
833
+ if (field.checked !== undefined && field.kind !== 'checkbox') {
834
+ ctx.addIssue({
835
+ code: 'custom',
836
+ path: at('checked'),
837
+ message: 'checked is for checkbox fields',
838
+ });
839
+ }
840
+ if (field.min !== undefined && field.max !== undefined && field.min > field.max) {
841
+ ctx.addIssue({ code: 'custom', path: at('max'), message: 'max is less than min' });
842
+ }
843
+ if (field.kind === 'number' && field.value && !Number.isFinite(Number(field.value))) {
844
+ ctx.addIssue({
845
+ code: 'custom',
846
+ path: at('value'),
847
+ message: 'a number field value must be a number',
848
+ });
849
+ }
850
+ if (field.kind === 'date' && field.value && !/^\d{4}-\d{2}-\d{2}$/.test(field.value)) {
851
+ ctx.addIssue({
852
+ code: 'custom',
853
+ path: at('value'),
854
+ message: 'a date field value is YYYY-MM-DD',
855
+ });
856
+ }
857
+ if (field.kind === 'datetime' && field.value && Number.isNaN(Date.parse(field.value))) {
858
+ ctx.addIssue({
859
+ code: 'custom',
860
+ path: at('value'),
861
+ message: 'a datetime field value is ISO 8601',
862
+ });
863
+ }
864
+ }
764
865
  }),
765
866
  z
766
867
  .object({
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/ui-sdk",
3
- "version": "1.4.0-dev-20261012123722",
3
+ "version": "1.4.0-dev-20261012124454",
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",