@keemakr/ui-sdk 1.6.0-dev-20261103135437 → 1.6.0-dev-20261103154901

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 CHANGED
@@ -73,6 +73,25 @@ export declare function searchableOptions<T extends {
73
73
  value: string;
74
74
  label: string;
75
75
  }>(options: readonly T[], pinned: readonly string[], query: string): T[];
76
+ /** An option of a choice field: what it posts and what the reader sees. */
77
+ export interface FieldOption {
78
+ value: string;
79
+ label: string;
80
+ }
81
+ /**
82
+ * The option an `addsTo` combobox adds to its multiselect for the text in its box, or null when
83
+ * it adds nothing: the option whose value is the text, or whose label is (any case), or, with
84
+ * `allowNew`, a new option that is the trimmed text. Blank text adds nothing.
85
+ */
86
+ export declare function comboboxPick(combobox: {
87
+ options?: readonly FieldOption[];
88
+ allowNew?: boolean;
89
+ }, text: string): FieldOption | null;
90
+ /**
91
+ * The chips of a `mirror` list: the ticked options of its multiselect in the order they were
92
+ * ticked, each by its label. A ticked value with no option is shown as itself.
93
+ */
94
+ export declare function mirrorChips(options: readonly FieldOption[], ticked: readonly string[]): FieldOption[];
76
95
  /** One send button of a form: its `submit` or one of its `secondary`. */
77
96
  export interface FormSubmit {
78
97
  label: string;
package/dist/form.js CHANGED
@@ -111,6 +111,31 @@ export function searchableOptions(options, pinned, query) {
111
111
  const rest = options.filter((o) => !pinned.includes(o.value) && o.label.toLocaleLowerCase().includes(needle));
112
112
  return [...top, ...rest];
113
113
  }
114
+ /**
115
+ * The option an `addsTo` combobox adds to its multiselect for the text in its box, or null when
116
+ * it adds nothing: the option whose value is the text, or whose label is (any case), or, with
117
+ * `allowNew`, a new option that is the trimmed text. Blank text adds nothing.
118
+ */
119
+ export function comboboxPick(combobox, text) {
120
+ const typed = text.trim();
121
+ if (typed === '')
122
+ return null;
123
+ const needle = typed.toLocaleLowerCase();
124
+ const match = combobox.options?.find((o) => o.value === typed || o.label.toLocaleLowerCase() === needle);
125
+ if (match)
126
+ return { value: match.value, label: match.label };
127
+ return combobox.allowNew ? { value: typed, label: typed } : null;
128
+ }
129
+ /**
130
+ * The chips of a `mirror` list: the ticked options of its multiselect in the order they were
131
+ * ticked, each by its label. A ticked value with no option is shown as itself.
132
+ */
133
+ export function mirrorChips(options, ticked) {
134
+ return ticked.map((value) => ({
135
+ value,
136
+ label: options.find((o) => o.value === value)?.label ?? value,
137
+ }));
138
+ }
114
139
  /**
115
140
  * Every send button of a form in drawing order: `submit` first, then `secondary`. `valid` says
116
141
  * whether every shown required field is filled (`formState(...).missing` is empty); a send with
package/dist/index.d.ts CHANGED
@@ -25,8 +25,8 @@ export type { AppDestination } from './app-press.js';
25
25
  export type { FocusReference, FormFieldName } from './focus.js';
26
26
  export { heatmapCellText, heatmapIntensity, heatmapMixPercent, heatmapRange, heatmapStrong, } from './heatmap.js';
27
27
  export type { HeatmapLike, HeatmapRange } from './heatmap.js';
28
- export { checkFormInput, chosenSubmit, formPress, formState, formSubmits, initialDraft, isoToLocalInput, localInputToIso, postedValue, searchableOptions, } from './form.js';
29
- export type { FormDraft, FormFieldKind, FormFieldLike, FormFieldRule, FormInputCheck, FormState, FormSubmit, ShowWhen, } from './form.js';
28
+ export { checkFormInput, chosenSubmit, comboboxPick, formPress, formState, formSubmits, initialDraft, isoToLocalInput, localInputToIso, mirrorChips, postedValue, searchableOptions, } from './form.js';
29
+ export type { FieldOption, FormDraft, FormFieldKind, FormFieldLike, FormFieldRule, FormInputCheck, FormState, FormSubmit, ShowWhen, } from './form.js';
30
30
  export { stackedBarParts, stackedBarValue } from './stacked-bar.js';
31
31
  export type { StackedBarLike, StackedBarParts, StackedBarSegmentPart } from './stacked-bar.js';
32
32
  export { statTrend } from './stat.js';
package/dist/index.js CHANGED
@@ -23,7 +23,7 @@ export { PLAYBACK_RATES, SEEK_AT_MAX, formatPlayhead, isSeekPress, nextPlaybackR
23
23
  export { FOCUSABLE_FIELD_KINDS, focusIssue, focusesIn, isFocusPress } from './focus.js';
24
24
  export { APP_DESTINATIONS, APPOINTMENT_PARAM, appPressPath, isAppPress } from './app-press.js';
25
25
  export { heatmapCellText, heatmapIntensity, heatmapMixPercent, heatmapRange, heatmapStrong, } from './heatmap.js';
26
- export { checkFormInput, chosenSubmit, formPress, formState, formSubmits, initialDraft, isoToLocalInput, localInputToIso, postedValue, searchableOptions, } from './form.js';
26
+ export { checkFormInput, chosenSubmit, comboboxPick, formPress, formState, formSubmits, initialDraft, isoToLocalInput, localInputToIso, mirrorChips, postedValue, searchableOptions, } from './form.js';
27
27
  export { stackedBarParts, stackedBarValue } from './stacked-bar.js';
28
28
  export { statTrend } from './stat.js';
29
29
  export { createSectionMemory, sectionBadge, sectionCollapsible, sectionColumnWeights, sectionGridTemplate, sectionScrollHeight, } from './section.js';
package/dist/negotiate.js CHANGED
@@ -1003,7 +1003,7 @@ export function foldChoiceField(field) {
1003
1003
  * list -> textarea, one item per line
1004
1004
  */
1005
1005
  export function foldFormField(field) {
1006
- const { values, checked, min: _min, max: _max, step: _step, searchable: _searchable, ...rest } = field;
1006
+ const { values, checked, min: _min, max: _max, step: _step, searchable: _searchable, addsTo: _addsTo, allowNew: _allowNew, mirror: _mirror, removable: _removable, ...rest } = field;
1007
1007
  switch (field.kind) {
1008
1008
  case 'number':
1009
1009
  case 'date':
package/dist/schema.d.ts CHANGED
@@ -685,6 +685,10 @@ declare const leafNodeSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{
685
685
  description: z.ZodOptional<z.ZodString>;
686
686
  }, z.core.$strip>>>;
687
687
  searchable: z.ZodOptional<z.ZodBoolean>;
688
+ addsTo: z.ZodOptional<z.ZodString>;
689
+ allowNew: z.ZodOptional<z.ZodBoolean>;
690
+ mirror: z.ZodOptional<z.ZodString>;
691
+ removable: z.ZodOptional<z.ZodBoolean>;
688
692
  required: z.ZodDefault<z.ZodBoolean>;
689
693
  placeholder: z.ZodOptional<z.ZodString>;
690
694
  hint: z.ZodOptional<z.ZodString>;
package/dist/schema.js CHANGED
@@ -1693,6 +1693,44 @@ function showWhenIssue(name, when, fields) {
1693
1693
  }
1694
1694
  return null;
1695
1695
  }
1696
+ /**
1697
+ * What is wrong with a field's `addsTo`, `allowNew`, `mirror` or `removable`, each with the key it
1698
+ * is on: an `addsTo` combobox or a `mirror` list names a multiselect of the same form, and the two
1699
+ * flags come only with the link they modify.
1700
+ */
1701
+ function linkedFieldIssues(field, fields) {
1702
+ const issues = [];
1703
+ const names = (key, target) => {
1704
+ if (!fields.some((other) => other.name === target && other.kind === 'multiselect')) {
1705
+ issues.push({ key, message: `${key} names no multiselect "${target}" in this form` });
1706
+ }
1707
+ };
1708
+ if (field.addsTo !== undefined) {
1709
+ if (field.kind !== 'combobox') {
1710
+ issues.push({ key: 'addsTo', message: 'addsTo is for combobox fields' });
1711
+ }
1712
+ else {
1713
+ names('addsTo', field.addsTo);
1714
+ if (field.required) {
1715
+ // It empties after each pick, so a required one could never be sent.
1716
+ issues.push({ key: 'required', message: 'a combobox with addsTo cannot be required' });
1717
+ }
1718
+ }
1719
+ }
1720
+ if (field.allowNew !== undefined && (field.kind !== 'combobox' || field.addsTo === undefined)) {
1721
+ issues.push({ key: 'allowNew', message: 'allowNew is for a combobox with addsTo' });
1722
+ }
1723
+ if (field.mirror !== undefined) {
1724
+ if (field.kind !== 'list')
1725
+ issues.push({ key: 'mirror', message: 'mirror is for list fields' });
1726
+ else
1727
+ names('mirror', field.mirror);
1728
+ }
1729
+ if (field.removable !== undefined && (field.kind !== 'list' || field.mirror === undefined)) {
1730
+ issues.push({ key: 'removable', message: 'removable is for a list with mirror' });
1731
+ }
1732
+ return issues;
1733
+ }
1696
1734
  /** A real YYYY-MM-DD calendar day: `2026-02-30` is refused. */
1697
1735
  function isCalendarDate(text) {
1698
1736
  if (!/^\d{4}-\d{2}-\d{2}$/.test(text))
@@ -1790,6 +1828,35 @@ const leafNodeSchema = z.discriminatedUnion('type', [
1790
1828
  * posts what a multiselect posts. Default false.
1791
1829
  */
1792
1830
  searchable: z.boolean().optional(),
1831
+ /**
1832
+ * A combobox only: the `name` of a multiselect in this form, for "Add another
1833
+ * form". Picking an option (`comboboxPick`) adds it to that multiselect's
1834
+ * options when it is not there yet, ticks it, and empties the box. Typed text
1835
+ * that matches no option is refused unless `allowNew`. The combobox posts what
1836
+ * a combobox posts, so '' once the pick is made; the multiselect posts its
1837
+ * ticked values. A client without it draws a plain combobox, which posts the
1838
+ * typed text, so the action must take that too.
1839
+ */
1840
+ addsTo: slug.optional(),
1841
+ /**
1842
+ * An `addsTo` combobox only: typed text that matches no option is added as a
1843
+ * new option, its value and label the text. Default false.
1844
+ */
1845
+ allowNew: z.boolean().optional(),
1846
+ /**
1847
+ * A list only: the `name` of a multiselect in this form. The list shows the
1848
+ * labels of its ticked options as read-only chips, in the order they were
1849
+ * ticked (`mirrorChips`), and posts those labels, as a list posts its values.
1850
+ * Set `values` to the same labels: a client without it draws an editable list
1851
+ * starting from them.
1852
+ */
1853
+ mirror: slug.optional(),
1854
+ /**
1855
+ * A `mirror` list only: each chip has a cross that unticks its option. A
1856
+ * required multiselect is still checked on send, as when its box is unticked.
1857
+ * Default false.
1858
+ */
1859
+ removable: z.boolean().optional(),
1793
1860
  required: z.boolean().default(false),
1794
1861
  placeholder: z.string().max(120).optional(),
1795
1862
  /** Shown under the field. */
@@ -2011,6 +2078,9 @@ const leafNodeSchema = z.discriminatedUnion('type', [
2011
2078
  message: 'searchable is for multiselect fields',
2012
2079
  });
2013
2080
  }
2081
+ for (const issue of linkedFieldIssues(field, node.fields)) {
2082
+ ctx.addIssue({ code: 'custom', path: at(issue.key), message: issue.message });
2083
+ }
2014
2084
  if (field.checked !== undefined && field.kind !== 'checkbox') {
2015
2085
  ctx.addIssue({
2016
2086
  code: 'custom',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keemakr/ui-sdk",
3
- "version": "1.6.0-dev-20261103135437",
3
+ "version": "1.6.0-dev-20261103154901",
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",