nexus-shared 3.2.0 → 4.0.0

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.
Files changed (187) hide show
  1. package/CHANGELOG.md +1564 -0
  2. package/README.md +1705 -1123
  3. package/dist/Client.Index.d.ts +14 -0
  4. package/dist/Client.Index.js +14 -0
  5. package/dist/Components/Documents/DocumentFrame.d.ts +50 -0
  6. package/dist/Components/Documents/DocumentFrame.js +83 -0
  7. package/dist/Components/Documents/Menu.d.ts +4 -0
  8. package/dist/Components/Documents/Menu.js +40 -24
  9. package/dist/Components/Documents/PrintDocument.d.ts +95 -0
  10. package/dist/Components/Documents/PrintDocument.js +62 -0
  11. package/dist/Components/Documents/Tabs.d.ts +59 -0
  12. package/dist/Components/Documents/Tabs.js +70 -0
  13. package/dist/Components/Forms/ApiForm.js +19 -2
  14. package/dist/Components/Forms/Crud.d.ts +2 -2
  15. package/dist/Components/Forms/Crud.js +576 -243
  16. package/dist/Components/Forms/CrudActions.d.ts +136 -0
  17. package/dist/Components/Forms/CrudActions.js +184 -0
  18. package/dist/Components/Forms/CrudNarrowPicker.d.ts +31 -0
  19. package/dist/Components/Forms/CrudNarrowPicker.js +180 -0
  20. package/dist/Components/Forms/CrudParts.d.ts +30 -2
  21. package/dist/Components/Forms/CrudParts.js +55 -5
  22. package/dist/Components/Forms/CrudRowForms.d.ts +26 -0
  23. package/dist/Components/Forms/CrudRowForms.js +114 -0
  24. package/dist/Components/Forms/CrudScopes.d.ts +28 -0
  25. package/dist/Components/Forms/CrudScopes.js +76 -0
  26. package/dist/Components/Forms/CrudTree.d.ts +90 -0
  27. package/dist/Components/Forms/CrudTree.js +363 -0
  28. package/dist/Components/Forms/CrudWorkspace.d.ts +63 -0
  29. package/dist/Components/Forms/CrudWorkspace.js +169 -0
  30. package/dist/Components/Forms/ExcelImport.js +3 -3
  31. package/dist/Components/Forms/Form.d.ts +4 -4
  32. package/dist/Components/Forms/Form.js +123 -17
  33. package/dist/Components/Forms/FormLeaveGuard.d.ts +44 -0
  34. package/dist/Components/Forms/FormLeaveGuard.js +65 -0
  35. package/dist/Components/Forms/RecordFlows.d.ts +50 -0
  36. package/dist/Components/Forms/RecordFlows.js +282 -0
  37. package/dist/Components/Forms/SubmitForm.d.ts +37 -2
  38. package/dist/Components/Forms/SubmitForm.js +195 -10
  39. package/dist/Components/Inputs/CheckBox.js +1 -1
  40. package/dist/Components/Inputs/ChoiceField.d.ts +21 -1
  41. package/dist/Components/Inputs/ChoiceField.js +28 -2
  42. package/dist/Components/Inputs/Dropdown.d.ts +13 -0
  43. package/dist/Components/Inputs/Dropdown.js +5 -5
  44. package/dist/Components/Inputs/DropdownParts.d.ts +3 -1
  45. package/dist/Components/Inputs/DropdownParts.js +16 -4
  46. package/dist/Components/Inputs/Field.d.ts +7 -1
  47. package/dist/Components/Inputs/Field.js +2 -2
  48. package/dist/Components/Inputs/GroupForm.d.ts +6 -6
  49. package/dist/Components/Inputs/GroupForm.js +10 -11
  50. package/dist/Components/Inputs/InputRenderer.d.ts +9 -6
  51. package/dist/Components/Inputs/InputRenderer.js +37 -32
  52. package/dist/Components/Inputs/PictureInput.d.ts +41 -0
  53. package/dist/Components/Inputs/PictureInput.js +70 -0
  54. package/dist/Components/Inputs/RadioGroup.d.ts +16 -3
  55. package/dist/Components/Inputs/RadioGroup.js +8 -3
  56. package/dist/Components/Inputs/RowsInput.d.ts +1 -1
  57. package/dist/Components/Inputs/RowsInput.js +18 -3
  58. package/dist/Components/Inputs/TabularForm.d.ts +5 -5
  59. package/dist/Components/Inputs/TabularForm.js +29 -29
  60. package/dist/Components/Inputs/TextArea.d.ts +6 -0
  61. package/dist/Components/Inputs/TextArea.js +11 -2
  62. package/dist/Components/Inputs/TextBoxTypes.d.ts +6 -0
  63. package/dist/Components/Inputs/TextBoxTypes.js +17 -0
  64. package/dist/Components/Inputs/TreeView.d.ts +53 -2
  65. package/dist/Components/Inputs/TreeView.js +147 -13
  66. package/dist/Components/Layouts/MessageBox.d.ts +15 -2
  67. package/dist/Components/Layouts/MessageBox.js +56 -7
  68. package/dist/Components/Layouts/Popup.d.ts +13 -6
  69. package/dist/Components/Layouts/Popup.js +37 -9
  70. package/dist/Components/Layouts/PopupDock.d.ts +3 -1
  71. package/dist/Components/Layouts/PopupDock.js +2 -1
  72. package/dist/Components/Layouts/PopupHost.js +5 -4
  73. package/dist/Components/Viewers/DataTable.js +150 -48
  74. package/dist/Components/Viewers/DataTableFilters.d.ts +1 -1
  75. package/dist/Components/Viewers/DataTableFilters.js +17 -2
  76. package/dist/Components/Viewers/DataTableParts.d.ts +21 -5
  77. package/dist/Components/Viewers/DataTableParts.js +26 -14
  78. package/dist/Components/Viewers/OwnerFiles.d.ts +175 -0
  79. package/dist/Components/Viewers/OwnerFiles.js +589 -0
  80. package/dist/Components/Viewers/QrCodeImage.d.ts +22 -0
  81. package/dist/Components/Viewers/QrCodeImage.js +15 -0
  82. package/dist/Components/Viewers/RecordCards.d.ts +16 -0
  83. package/dist/Components/Viewers/RecordCards.js +509 -0
  84. package/dist/Helpers/BusyHooks.d.ts +6 -0
  85. package/dist/Helpers/BusyHooks.js +39 -0
  86. package/dist/Helpers/CrudBackend.d.ts +20 -2
  87. package/dist/Helpers/CrudBackend.js +46 -2
  88. package/dist/Helpers/CrudColumns.d.ts +53 -6
  89. package/dist/Helpers/CrudColumns.js +98 -7
  90. package/dist/Helpers/CrudDetailsTabs.d.ts +58 -0
  91. package/dist/Helpers/CrudDetailsTabs.js +126 -0
  92. package/dist/Helpers/CrudHelpers.d.ts +81 -2
  93. package/dist/Helpers/CrudHelpers.js +195 -0
  94. package/dist/Helpers/CrudNarrowPick.d.ts +83 -0
  95. package/dist/Helpers/CrudNarrowPick.js +157 -0
  96. package/dist/Helpers/CrudRowForms.d.ts +15 -0
  97. package/dist/Helpers/CrudRowForms.js +43 -0
  98. package/dist/Helpers/CrudScopes.d.ts +32 -0
  99. package/dist/Helpers/CrudScopes.js +79 -0
  100. package/dist/Helpers/DropdownHelpers.d.ts +3 -1
  101. package/dist/Helpers/DropdownHelpers.js +6 -2
  102. package/dist/Helpers/ExcelHelpers.d.ts +1 -1
  103. package/dist/Helpers/ExcelHelpers.js +12 -11
  104. package/dist/Helpers/FileAdapter.d.ts +78 -0
  105. package/dist/Helpers/FileAdapter.js +102 -0
  106. package/dist/Helpers/FilePrimaries.d.ts +48 -0
  107. package/dist/Helpers/FilePrimaries.js +138 -0
  108. package/dist/Helpers/FormConfirm.d.ts +32 -0
  109. package/dist/Helpers/FormConfirm.js +40 -0
  110. package/dist/Helpers/FormStore.d.ts +90 -5
  111. package/dist/Helpers/FormStore.js +318 -22
  112. package/dist/Helpers/InputConditions.d.ts +50 -0
  113. package/dist/Helpers/InputConditions.js +168 -0
  114. package/dist/Helpers/InputMemory.d.ts +106 -0
  115. package/dist/Helpers/InputMemory.js +385 -0
  116. package/dist/Helpers/InputNarrowing.d.ts +18 -0
  117. package/dist/Helpers/InputNarrowing.js +67 -0
  118. package/dist/Helpers/InputParamsHelpers.d.ts +44 -1
  119. package/dist/Helpers/InputParamsHelpers.js +157 -74
  120. package/dist/Helpers/NexusDriveAdapter.d.ts +55 -0
  121. package/dist/Helpers/NexusDriveAdapter.js +207 -0
  122. package/dist/Helpers/NumberHelpers.d.ts +95 -0
  123. package/dist/Helpers/NumberHelpers.js +126 -0
  124. package/dist/Helpers/Permissions.js +2 -1
  125. package/dist/Helpers/QrCode.d.ts +26 -0
  126. package/dist/Helpers/QrCode.js +463 -0
  127. package/dist/Helpers/RecordCards.d.ts +205 -0
  128. package/dist/Helpers/RecordCards.js +378 -0
  129. package/dist/Helpers/RequestCache.d.ts +14 -2
  130. package/dist/Helpers/RequestCache.js +22 -3
  131. package/dist/Helpers/RowsStore.d.ts +37 -2
  132. package/dist/Helpers/RowsStore.js +128 -10
  133. package/dist/Helpers/ServerPreview.d.ts +69 -0
  134. package/dist/Helpers/ServerPreview.js +99 -0
  135. package/dist/Helpers/TableColumns.js +4 -3
  136. package/dist/Helpers/TableExport.d.ts +7 -1
  137. package/dist/Helpers/TableExport.js +9 -3
  138. package/dist/Helpers/TableFilters.d.ts +1 -1
  139. package/dist/Helpers/TableFilters.js +24 -23
  140. package/dist/Helpers/TableHelpers.d.ts +23 -2
  141. package/dist/Helpers/TableHelpers.js +51 -10
  142. package/dist/Helpers/TableJoins.d.ts +13 -0
  143. package/dist/Helpers/TableJoins.js +34 -0
  144. package/dist/Helpers/TableStore.d.ts +21 -1
  145. package/dist/Helpers/TableStore.js +64 -7
  146. package/dist/Helpers/TreeStore.d.ts +81 -0
  147. package/dist/Helpers/TreeStore.js +365 -0
  148. package/dist/Interfaces/CrudInterfaces.d.ts +465 -5
  149. package/dist/Interfaces/FileInterfaces.d.ts +162 -0
  150. package/dist/Interfaces/FileInterfaces.js +4 -0
  151. package/dist/Interfaces/FormInterfaces.d.ts +391 -30
  152. package/dist/Interfaces/FormInterfaces.js +79 -1
  153. package/dist/Interfaces/InputInterfaces.d.ts +15 -3
  154. package/dist/Interfaces/RecordInterfaces.d.ts +367 -0
  155. package/dist/Interfaces/RecordInterfaces.js +1 -0
  156. package/dist/Interfaces/TableInterfaces.d.ts +74 -1
  157. package/dist/Services/ExcelApi.js +5 -0
  158. package/dist/Services/FileApi.d.ts +13 -0
  159. package/dist/Services/FileApi.js +29 -0
  160. package/dist/Services/ImageEditorLoader.d.ts +14 -0
  161. package/dist/Services/ImageEditorLoader.js +51 -0
  162. package/dist/Services/JoinSources.d.ts +37 -5
  163. package/dist/Services/JoinSources.js +90 -14
  164. package/dist/Services/ModuleImport.d.ts +7 -0
  165. package/dist/Services/ModuleImport.js +22 -0
  166. package/dist/Shared.Index.d.ts +16 -0
  167. package/dist/Shared.Index.js +16 -0
  168. package/package.json +7 -2
  169. package/src/Styles/Nexus.Avatar.css +6 -5
  170. package/src/Styles/Nexus.Button.css +10 -4
  171. package/src/Styles/Nexus.Choice.css +16 -0
  172. package/src/Styles/Nexus.Crud.css +383 -9
  173. package/src/Styles/Nexus.Dropdown.css +8 -0
  174. package/src/Styles/Nexus.Files.css +410 -0
  175. package/src/Styles/Nexus.Form.css +5 -2
  176. package/src/Styles/Nexus.Index.css +4 -0
  177. package/src/Styles/Nexus.Input.css +42 -0
  178. package/src/Styles/Nexus.Menu.css +10 -1
  179. package/src/Styles/Nexus.Popup.css +77 -1
  180. package/src/Styles/Nexus.Print.css +288 -0
  181. package/src/Styles/Nexus.QrCode.css +12 -0
  182. package/src/Styles/Nexus.Record.css +430 -0
  183. package/src/Styles/Nexus.Tab.Buttons.css +87 -22
  184. package/src/Styles/Nexus.Table.css +67 -5
  185. package/src/Styles/Nexus.Themes.css +12 -6
  186. package/src/Styles/Nexus.Tokens.css +8 -3
  187. package/src/Styles/Nexus.Tree.css +31 -1
@@ -63,6 +63,24 @@ export interface ChoiceItemProps<T extends OptionValue> {
63
63
  }
64
64
  /** One option of a group: a native input and its label, icon, and description, all inside one clickable label. */
65
65
  export declare function ChoiceItem<T extends OptionValue>({ type, groupId, name, option, index, size, checked, defaultChecked, invalid, readOnly, onInvalid }: ChoiceItemProps<T>): import("react").JSX.Element;
66
+ /**
67
+ * One option of a group drawn as tabs (`design="tabs"`): the native input out of sight inside a tab of the `TabButtons`
68
+ * track. Its description is its tooltip, and the input's description for a screen reader: `descriptionId` names the
69
+ * group's note for this option (`ChoiceTabNotes`), which a hidden note still gives.
70
+ */
71
+ export declare function ChoiceTab<T extends OptionValue>({ type, groupId, name, option, index, checked, defaultChecked, invalid, readOnly, onInvalid }: Omit<ChoiceItemProps<T>, "size">): import("react").JSX.Element;
72
+ /**
73
+ * The descriptions of a group drawn as tabs, under the track: the chosen option's shows (a phone has no tooltip), the
74
+ * rest stay hidden but still describe their inputs. `chosen` is the option chosen when the group is drawn; after that
75
+ * `showChosenNote` follows the inputs, as the group's `sync` rule.
76
+ */
77
+ export declare function ChoiceTabNotes<T extends OptionValue>({ groupId, options, chosen }: {
78
+ groupId: string;
79
+ options: readonly ChoiceOption<T>[];
80
+ chosen: number;
81
+ }): (import("react").JSX.Element | null)[];
82
+ /** Shows the note of the option checked now and hides the others (a `useChoiceField` `sync` rule). */
83
+ export declare function showChosenNote(inputs: HTMLInputElement[]): void;
66
84
  /** The legend of a choice group, with the required mark and, when read-only, a lock. */
67
85
  export declare function ChoiceLegend({ label, required, lock }: {
68
86
  label: ReactNode;
@@ -108,7 +126,9 @@ type GroupStyle = CSSProperties & {
108
126
  "--nx-choices-columns"?: number;
109
127
  };
110
128
  /** Class names and inline style of a group's fieldset and options list. */
111
- export declare function groupLayout(props: ChoiceGroupProps<OptionValue>): {
129
+ export declare function groupLayout(props: Omit<ChoiceGroupProps<OptionValue>, "design"> & {
130
+ design?: ChoiceDesign | "tabs";
131
+ }): {
112
132
  className: string;
113
133
  optionsStyle: GroupStyle | undefined;
114
134
  };
@@ -123,7 +123,7 @@ export function preventChange(event) {
123
123
  * reaches the input too), or pressed with Space or an arrow key, which browsers turn into a click.
124
124
  */
125
125
  export function optionAnchor(target) {
126
- return target instanceof HTMLInputElement ? target.closest(".nx-choice") : null;
126
+ return target instanceof HTMLInputElement ? target.closest(".nx-choice, .nx-tabs__option") : null;
127
127
  }
128
128
  /** Hides a field's read-only note when focus leaves the field, not when it moves between its options. */
129
129
  export function leavesField(event) {
@@ -146,6 +146,32 @@ export function ChoiceItem({ type, groupId, name, option, index, size, checked,
146
146
  onChange: checked === undefined ? undefined : noop }), hasContent(option.icon) && (_jsx("span", { className: "nx-choice__icon", "aria-hidden": "true", children: option.icon })), _jsxs("span", { className: "nx-choice__text", children: [_jsx("span", { id: labelId, className: "nx-choice__label", children: option.label }), descriptionId && (_jsx("span", { id: descriptionId, className: "nx-choice__description", children: option.description }))] })] }));
147
147
  }
148
148
  function noop() { }
149
+ /**
150
+ * One option of a group drawn as tabs (`design="tabs"`): the native input out of sight inside a tab of the `TabButtons`
151
+ * track. Its description is its tooltip, and the input's description for a screen reader: `descriptionId` names the
152
+ * group's note for this option (`ChoiceTabNotes`), which a hidden note still gives.
153
+ */
154
+ export function ChoiceTab({ type, groupId, name, option, index, checked, defaultChecked, invalid, readOnly, onInvalid }) {
155
+ const descriptionId = hasContent(option.description) ? `${groupId}-${index}-description` : undefined;
156
+ return (_jsxs("label", { className: "nx-tabs__option", title: typeof option.description === "string" ? option.description : undefined, children: [_jsx("input", { id: `${groupId}-${index}`, type: type, name: name, value: String(option.value), [OPTION_ATTRIBUTE]: index, className: "nx-visually-hidden", checked: checked, defaultChecked: checked === undefined ? defaultChecked : undefined, disabled: option.disabled, "aria-invalid": invalid || undefined, "aria-describedby": descriptionId, onClick: readOnly ? preventChange : undefined, onInvalid: onInvalid, onChange: checked === undefined ? undefined : noop }), option.icon, _jsx("span", { className: "nx-tabs__label", children: _jsx("span", { className: "nx-tabs__text", children: option.label }) })] }));
157
+ }
158
+ /**
159
+ * The descriptions of a group drawn as tabs, under the track: the chosen option's shows (a phone has no tooltip), the
160
+ * rest stay hidden but still describe their inputs. `chosen` is the option chosen when the group is drawn; after that
161
+ * `showChosenNote` follows the inputs, as the group's `sync` rule.
162
+ */
163
+ export function ChoiceTabNotes({ groupId, options, chosen }) {
164
+ return options.map((option, index) => hasContent(option.description) ? (_jsx("p", { id: `${groupId}-${index}-description`, className: "nx-choices__note", "data-nx-note": index, hidden: index !== chosen, children: option.description }, String(option.value))) : null);
165
+ }
166
+ /** Shows the note of the option checked now and hides the others (a `useChoiceField` `sync` rule). */
167
+ export function showChosenNote(inputs) {
168
+ const group = inputs[0]?.closest(".nx-choices");
169
+ if (!group)
170
+ return;
171
+ const chosen = inputs.find(input => input.checked)?.getAttribute(OPTION_ATTRIBUTE) ?? null;
172
+ for (const note of Array.from(group.querySelectorAll("[data-nx-note]")))
173
+ note.hidden = note.dataset.nxNote !== chosen;
174
+ }
149
175
  /** The legend of a choice group, with the required mark and, when read-only, a lock. */
150
176
  export function ChoiceLegend({ label, required, lock }) {
151
177
  if (!hasContent(label))
@@ -156,7 +182,7 @@ export function ChoiceLegend({ label, required, lock }) {
156
182
  export function groupLayout(props) {
157
183
  const { size = "md", design = "default", orientation = "vertical", columns } = props;
158
184
  return {
159
- className: cx("nx-choices", `nx-choices--${size}`, design === "cards" && "nx-choices--cards", orientation === "horizontal" && "nx-choices--horizontal", props.className),
185
+ className: cx("nx-choices", `nx-choices--${size}`, design === "cards" && "nx-choices--cards", design === "tabs" && "nx-choices--tabs", orientation === "horizontal" && "nx-choices--horizontal", props.className),
160
186
  optionsStyle: (columns && columns > 1 ? { "--nx-choices-columns": columns } : undefined),
161
187
  };
162
188
  }
@@ -8,6 +8,11 @@ interface DropdownBaseProps<TItem extends DropdownItem, TValue extends OptionVal
8
8
  hint?: ReactNode;
9
9
  /** An error from outside, such as a server message. Shown before the field's own message. */
10
10
  error?: string | null;
11
+ /**
12
+ * Drawn as invalid with no message line, for a box whose reason the page says elsewhere (`Field` `invalid`); a screen
13
+ * reader hears that reason through `aria-describedby`. A CRUD's narrowing box is drawn so while it asks for a pick.
14
+ */
15
+ invalid?: boolean;
11
16
  /** Default `standard`. */
12
17
  design?: InputDesign;
13
18
  /** Default `md`. */
@@ -29,6 +34,14 @@ interface DropdownBaseProps<TItem extends DropdownItem, TValue extends OptionVal
29
34
  selectedOptions?: readonly TItem[];
30
35
  /** Loads the items of values that no list or `selectedOptions` has, e.g. by id. Values it does not return show as "Not found". */
31
36
  resolveOptions?: (values: TValue[]) => Promise<readonly TItem[]>;
37
+ /**
38
+ * The item of a value (as text) that the page already holds, at once and with no call: a list kept for the page, a
39
+ * record looked up before. Asked before `resolveOptions`, so a value it knows is named from the first draw - and a form
40
+ * can name the values it holds without a call (a CRUD's save does). It answers only what is fresh: a record marked old
41
+ * since may have changed, and the dropdown then asks `resolveOptions`. With `aged` it answers an old one too, which a
42
+ * CRUD's save takes over no name at all. `crudPicker` gives one.
43
+ */
44
+ peekOption?: (key: string, aged?: boolean) => TItem | null | undefined;
32
45
  /** The item field that holds the value. Default `value`. */
33
46
  valueKey?: string;
34
47
  /** The item field shown as its name, in the box and in the list. Default `label`. */
@@ -7,7 +7,7 @@ import { columnTrack, defaultSearchKeys, filterItems, foldSearchText, indexItems
7
7
  import { followAnchor, isPopoverOpen, placeListPanel } from "../../Helpers/PopoverHelpers.js";
8
8
  import { DEFAULT_FIELD_NAME, validateSelection } from "../../Helpers/ValidationHelpers.js";
9
9
  import { Button } from "../Documents/Button.js";
10
- import { DropdownChip, DropdownMedia, DropdownOption, DropdownTag, hasIcon } from "./DropdownParts.js";
10
+ import { columnAlignStyle, DropdownChip, DropdownMedia, DropdownOption, DropdownTag, hasIcon } from "./DropdownParts.js";
11
11
  import { Field } from "./Field.js";
12
12
  import { useInputField } from "./InputField.js";
13
13
  import { useReadOnlyNotice } from "./ReadOnlyNotice.js";
@@ -28,7 +28,7 @@ const NAMES_LISTED = 20;
28
28
  const SKELETON_WIDTHS = ["72%", "54%", "64%", "46%"];
29
29
  const IDLE_LIST = { search: "", loadKey: undefined, items: [], page: 0, hasMore: false, total: undefined, status: "idle", errorPage: 1, firstKeys: new Set() };
30
30
  export function Dropdown(props) {
31
- const { label, hint, error, design: ownDesign, size = "md", icon, options, loadOptions, loadKey, pageSize = 50, selectedOptions, resolveOptions, valueKey = "value", labelKey = "label", descriptionKey = "description", iconKey = "icon", columns, searchKeys, isOptionDisabled = isDisabledItem, isOptionInactive = isInactiveItem, searchable: searchableProp, clearable = true, loading = false, emptyMessage = "No options", renderValue, panelWidth, readOnlyMessage, fieldName, validateOn, className, inputClassName, style, required, validate, name, form, placeholder, disabled, readOnly, ref, onBlur, onFocus, onKeyDown, onClick, onInvalid, multiple: multipleProp, value: valueProp, defaultValue, onValueChange, min, max, selectAll = true, maxChips = 10, ...inputProps } = props;
31
+ const { label, hint, error, invalid = false, design: ownDesign, size = "md", icon, options, loadOptions, loadKey, pageSize = 50, selectedOptions, resolveOptions, peekOption, valueKey = "value", labelKey = "label", descriptionKey = "description", iconKey = "icon", columns, searchKeys, isOptionDisabled = isDisabledItem, isOptionInactive = isInactiveItem, searchable: searchableProp, clearable = true, loading = false, emptyMessage = "No options", renderValue, panelWidth, readOnlyMessage, fieldName, validateOn, className, inputClassName, style, required, validate, name, form, placeholder, disabled, readOnly, ref, onBlur, onFocus, onKeyDown, onClick, onInvalid, multiple: multipleProp, value: valueProp, defaultValue, onValueChange, min, max, selectAll = true, maxChips = 10, ...inputProps } = props;
32
32
  // The person's input design (the quick preferences) when this page and its form name none, for a labelled input.
33
33
  const design = useInputDesign(ownDesign, Boolean(label));
34
34
  const multiple = multipleProp === true;
@@ -48,7 +48,7 @@ export function Dropdown(props) {
48
48
  const optionIndex = useMemo(() => (options ? indexItems(options, valueKey) : null), [options, valueKey]);
49
49
  const selectedIndex = useMemo(() => (selectedOptions ? indexItems(selectedOptions, valueKey) : null), [selectedOptions, valueKey]);
50
50
  const knownRef = useRef(new Map());
51
- const findItem = (key) => optionIndex?.get(key) ?? knownRef.current.get(key) ?? selectedIndex?.get(key) ?? null;
51
+ const findItem = (key) => optionIndex?.get(key) ?? knownRef.current.get(key) ?? selectedIndex?.get(key) ?? peekOption?.(key) ?? null;
52
52
  const labelOf = (item) => itemLabel(item, labelKey, valueKey);
53
53
  const listId = `${useId()}-list`;
54
54
  const selectionId = `${listId}-selection`;
@@ -777,7 +777,7 @@ export function Dropdown(props) {
777
777
  const failed = Boolean(loadOptions) && server.status === "error";
778
778
  const empty = rows.length === 0 && !skeleton && !failed;
779
779
  const typed = deferredSearch.trim();
780
- listContent = (_jsxs(_Fragment, { children: [showHeader && (_jsxs("div", { className: "nx-dropdown-list__header", "aria-hidden": "true", children: [_jsx("span", {}), typedColumns.map((column, index) => (_jsx("span", { className: "nx-dropdown-list__heading", style: column.align && column.align !== "start" ? { justifySelf: column.align, textAlign: column.align } : undefined, children: column.header }, index)))] })), rows.map((row, index) => {
780
+ listContent = (_jsxs(_Fragment, { children: [showHeader && (_jsxs("div", { className: "nx-dropdown-list__header", "aria-hidden": "true", children: [_jsx("span", {}), typedColumns.map((column, index) => (_jsx("span", { className: "nx-dropdown-list__heading", style: columnAlignStyle(column), children: column.header }, index)))] })), rows.map((row, index) => {
781
781
  const labelField = row.item ? readField(row.item, labelKey) : undefined;
782
782
  const description = row.item && !typedColumns ? readField(row.item, descriptionKey) : undefined;
783
783
  const pending = isPending(row.key, row.item);
@@ -809,7 +809,7 @@ export function Dropdown(props) {
809
809
  // The check column, the columns, and an empty last track whose gap keeps text off the row's end.
810
810
  const gridColumns = columns ? `auto ${columns.map(column => columnTrack(column)).join(" ")} 0px` : undefined;
811
811
  const panelStyle = panelWidth === undefined ? undefined : { width: typeof panelWidth === "number" ? `${panelWidth}px` : panelWidth };
812
- return (_jsxs(_Fragment, { children: [_jsxs(Field, { controlId: field.controlId, messageId: field.messageId, label: label, required: required, design: design, size: size, hint: hint, error: field.error, icon: icon, actions: _jsxs(_Fragment, { children: [busy && (_jsx("span", { className: "nx-dropdown__spinner", title: "Loading", "aria-hidden": "true", children: _jsx(InlineIcon, { icon: iconLoader2, className: "nx-spin" }) })), showClear && (_jsx("button", { type: "button", className: "nx-field__action nx-dropdown__clear", tabIndex: -1, "aria-label": "Clear", title: "Clear", onMouseDown: event => event.preventDefault(), onClick: clear, children: _jsx(InlineIcon, { icon: iconX }) })), readOnlyNotice.lock, !readOnly && (_jsx("button", { type: "button", className: "nx-field__action nx-dropdown__toggle", tabIndex: -1, "aria-label": open ? "Close the list" : "Open the list", "aria-expanded": open, "aria-controls": open ? listId : undefined, disabled: disabled, onMouseDown: event => event.preventDefault(), onClick: () => (open ? closePanel() : openPanel()), children: _jsx(InlineIcon, { icon: iconChevronDown }) }))] }), disabled: disabled, readOnly: readOnly, raiseLabel: values.length > 0 || Boolean(placeholder), className: cx("nx-field--dropdown", className), style: style, children: [_jsxs("div", { className: cx("nx-dropdown__control", multiple ? "nx-dropdown__control--multiple" : "nx-dropdown__control--single"), "data-searchable": searchable || undefined, "data-has-value": values.length > 0 || undefined, onMouseDown: handleControlMouseDown, children: [boxContent, _jsx("input", { autoComplete: "off", spellCheck: false, ...inputProps, ...field.controlProps, type: "text", role: "combobox", "aria-expanded": open, "aria-haspopup": "listbox", "aria-controls": open ? listId : undefined, "aria-activedescendant": activeIndex >= 0 ? `${listId}-${activeIndex}` : undefined, "aria-autocomplete": searchable ? "list" : "none", inputMode: searchable ? inputProps.inputMode : "none", name: undefined, form: form, className: cx("nx-field__control", "nx-dropdown__input", inputClassName), placeholder: values.length > 0 ? " " : placeholder || " ", disabled: disabled, readOnly: readOnly, onBlur: handleBlur, onFocus: onFocus, onKeyDown: handleKeyDown, onClick: handleClick }), _jsx("span", { id: selectionId, className: "nx-visually-hidden", children: values.length > 0 ? `Selected: ${namesOf(values)}` : "" })] }), name &&
812
+ return (_jsxs(_Fragment, { children: [_jsxs(Field, { controlId: field.controlId, messageId: field.messageId, label: label, required: required, design: design, size: size, hint: hint, error: field.error, invalid: invalid, icon: icon, actions: _jsxs(_Fragment, { children: [busy && (_jsx("span", { className: "nx-dropdown__spinner", title: "Loading", "aria-hidden": "true", children: _jsx(InlineIcon, { icon: iconLoader2, className: "nx-spin" }) })), showClear && (_jsx("button", { type: "button", className: "nx-field__action nx-dropdown__clear", tabIndex: -1, "aria-label": "Clear", title: "Clear", onMouseDown: event => event.preventDefault(), onClick: clear, children: _jsx(InlineIcon, { icon: iconX }) })), readOnlyNotice.lock, !readOnly && (_jsx("button", { type: "button", className: "nx-field__action nx-dropdown__toggle", tabIndex: -1, "aria-label": open ? "Close the list" : "Open the list", "aria-expanded": open, "aria-controls": open ? listId : undefined, disabled: disabled, onMouseDown: event => event.preventDefault(), onClick: () => (open ? closePanel() : openPanel()), children: _jsx(InlineIcon, { icon: iconChevronDown }) }))] }), disabled: disabled, readOnly: readOnly, raiseLabel: values.length > 0 || Boolean(placeholder), className: cx("nx-field--dropdown", className), style: style, children: [_jsxs("div", { className: cx("nx-dropdown__control", multiple ? "nx-dropdown__control--multiple" : "nx-dropdown__control--single"), "data-searchable": searchable || undefined, "data-has-value": values.length > 0 || undefined, onMouseDown: handleControlMouseDown, children: [boxContent, _jsx("input", { autoComplete: "off", spellCheck: false, ...inputProps, ...field.controlProps, type: "text", role: "combobox", "aria-expanded": open, "aria-haspopup": "listbox", "aria-controls": open ? listId : undefined, "aria-activedescendant": activeIndex >= 0 ? `${listId}-${activeIndex}` : undefined, "aria-autocomplete": searchable ? "list" : "none", "aria-busy": busy || undefined, inputMode: searchable ? inputProps.inputMode : "none", name: undefined, form: form, className: cx("nx-field__control", "nx-dropdown__input", inputClassName), placeholder: values.length > 0 ? " " : placeholder || " ", disabled: disabled, readOnly: readOnly, onBlur: handleBlur, onFocus: onFocus, onKeyDown: handleKeyDown, onClick: handleClick }), _jsx("span", { id: selectionId, className: "nx-visually-hidden", children: values.length > 0 ? `Selected: ${namesOf(values)}` : busy ? "Loading" : "" })] }), name &&
813
813
  (multiple ? (values.map(value => _jsx("input", { type: "hidden", name: name, form: form, disabled: disabled, value: optionKey(value) }, optionKey(value)))) : (_jsx("input", { type: "hidden", name: name, form: form, disabled: disabled, value: optionKey(values[0]) })))] }), readOnlyNotice.notice, !readOnly && (_jsx("div", { ref: panelRef, popover: "manual", className: cx("nx-popover", "nx-dropdown-panel", `nx-dropdown-panel--${size}`), style: panelStyle, onKeyDown: handlePanelKeyDown, onBlur: handlePanelBlur,
814
814
  // The box keeps focus while rows and buttons are pressed. A press on the list itself is left alone, so its
815
815
  // scroll bar can be dragged.
@@ -1,4 +1,4 @@
1
- import { type ReactNode } from "react";
1
+ import { type CSSProperties, type ReactNode } from "react";
2
2
  import type { DropdownColumn, DropdownItem } from "../../Interfaces/InputInterfaces.ts";
3
3
  /**
4
4
  * Why a current value cannot be picked again:
@@ -24,6 +24,8 @@ export declare function DropdownImage({ src }: {
24
24
  export declare function iconNode(icon: unknown): ReactNode;
25
25
  /** Whether an icon field has something to draw. */
26
26
  export declare function hasIcon(icon: unknown): boolean;
27
+ /** A column's cells and heading where they sit (`dropdownColumnAlign`): nothing to say for `start`. */
28
+ export declare const columnAlignStyle: (column: Pick<AnyColumn, "type" | "align">) => CSSProperties | undefined;
27
29
  /** One cell of a row with columns. `label` names the avatar's initials; `tag` follows the text. */
28
30
  export declare function DropdownCell({ column, item, label, tag }: {
29
31
  column: AnyColumn;
@@ -3,7 +3,9 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
3
3
  import { Icon, iconCheck, iconX, InlineIcon } from "nexus-icons";
4
4
  import { isValidElement, memo, useState } from "react";
5
5
  import { cx } from "../../Helpers/ClassHelpers.js";
6
- import { isMediaColumn, readField } from "../../Helpers/DropdownHelpers.js";
6
+ import { dropdownColumnAlign, isMediaColumn, readField } from "../../Helpers/DropdownHelpers.js";
7
+ import { formatMoney } from "../../Helpers/NumberHelpers.js";
8
+ import { useNumberLocale } from "../../Helpers/UserPreferences.js";
7
9
  import { Avatar } from "../Viewers/Avatar.js";
8
10
  export const DROPDOWN_STATE_LABELS = {
9
11
  inactive: "Inactive",
@@ -38,11 +40,21 @@ export function iconNode(icon) {
38
40
  export function hasIcon(icon) {
39
41
  return (typeof icon === "string" && icon !== "") || isValidElement(icon);
40
42
  }
41
- const alignStyle = (align) => align && align !== "start" ? { justifySelf: align, textAlign: align } : undefined;
43
+ /** A column's cells and heading where they sit (`dropdownColumnAlign`): nothing to say for `start`. */
44
+ export const columnAlignStyle = (column) => {
45
+ const align = dropdownColumnAlign(column);
46
+ return align !== "start" ? { justifySelf: align, textAlign: align } : undefined;
47
+ };
48
+ /** A money column's figure: 2 places in the person's number format; nothing for a missing one or one that is no figure. */
49
+ function DropdownMoney({ value }) {
50
+ const locale = useNumberLocale();
51
+ const figure = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" ? Number(value) : Number.NaN;
52
+ return _jsx("span", { className: "nx-dropdown-cell__text", children: formatMoney(Number.isFinite(figure) ? figure : null, { locale }) });
53
+ }
42
54
  /** One cell of a row with columns. `label` names the avatar's initials; `tag` follows the text. */
43
55
  export function DropdownCell({ column, item, label, tag }) {
44
56
  const type = column.type ?? "text";
45
- const style = alignStyle(column.align);
57
+ const style = columnAlignStyle(column);
46
58
  if (column.render) {
47
59
  return (_jsxs("span", { className: cx("nx-dropdown-cell", `nx-dropdown-cell--${type}`), style: style, children: [column.render(item), tag] }));
48
60
  }
@@ -51,7 +63,7 @@ export function DropdownCell({ column, item, label, tag }) {
51
63
  return (_jsx("span", { className: "nx-dropdown-cell nx-dropdown-cell--media", style: style, "aria-hidden": "true", children: type === "avatar" ? _jsx(DropdownAvatar, { src: value, name: label }) : type === "image" ? _jsx(DropdownImage, { src: value }) : _jsx("span", { className: "nx-dropdown-icon", children: iconNode(value) }) }));
52
64
  }
53
65
  const text = value === null || value === undefined ? "" : String(value);
54
- return (_jsxs("span", { className: cx("nx-dropdown-cell", `nx-dropdown-cell--${type}`), style: style, children: [_jsx("span", { className: "nx-dropdown-cell__text", children: text }), tag] }));
66
+ return (_jsxs("span", { className: cx("nx-dropdown-cell", `nx-dropdown-cell--${type}`), style: style, children: [type === "money" ? _jsx(DropdownMoney, { value: value }) : _jsx("span", { className: "nx-dropdown-cell__text", children: text }), tag] }));
55
67
  }
56
68
  /** The picture that leads a value in the box or a chip: the first avatar, image, or icon column, or the icon field. */
57
69
  export function DropdownMedia({ item, label, columns, iconKey }) {
@@ -17,6 +17,12 @@ export interface FieldProps {
17
17
  hint?: ReactNode;
18
18
  /** Error message. Marks the field invalid and replaces the hint. */
19
19
  error?: ReactNode;
20
+ /**
21
+ * Draws the field as invalid, the look an error gives it, with no message line of its own: for a field the page says
22
+ * why about elsewhere, such as a CRUD's narrowing box while its list asks for a pick. Nothing is said to a screen
23
+ * reader by it: point the control's `aria-describedby` at the words that say why.
24
+ */
25
+ invalid?: boolean;
20
26
  /** Id of the hint or error line, for the control's `aria-describedby`. */
21
27
  messageId?: string;
22
28
  /** Decorative icon at the start of the box. */
@@ -48,6 +54,6 @@ export interface FieldProps {
48
54
  * The frame around every input: label, box, icons, and the hint or error line. It has no state, so it renders
49
55
  * anywhere; inputs such as `TextBox` build on it, and so can custom controls.
50
56
  */
51
- export declare function Field({ controlId, label, labelId, required, design, size, hint, error, messageId, icon, iconEnd, prefix, suffix, actionsStart, actions, aside, disabled, readOnly, raiseLabel, multiline, className, style, children, }: FieldProps): import("react").JSX.Element;
57
+ export declare function Field({ controlId, label, labelId, required, design, size, hint, error, invalid, messageId, icon, iconEnd, prefix, suffix, actionsStart, actions, aside, disabled, readOnly, raiseLabel, multiline, className, style, children, }: FieldProps): import("react").JSX.Element;
52
58
  /** Whether a node renders something: not `undefined`, `null`, `false`, or "". */
53
59
  export declare const hasContent: (node: ReactNode) => boolean;
@@ -5,12 +5,12 @@ import { cx } from "../../Helpers/ClassHelpers.js";
5
5
  * The frame around every input: label, box, icons, and the hint or error line. It has no state, so it renders
6
6
  * anywhere; inputs such as `TextBox` build on it, and so can custom controls.
7
7
  */
8
- export function Field({ controlId, label, labelId, required = false, design = "standard", size = "md", hint, error, messageId, icon, iconEnd, prefix, suffix, actionsStart, actions, aside, disabled = false, readOnly = false, raiseLabel = false, multiline = false, className, style, children, }) {
8
+ export function Field({ controlId, label, labelId, required = false, design = "standard", size = "md", hint, error, invalid = false, messageId, icon, iconEnd, prefix, suffix, actionsStart, actions, aside, disabled = false, readOnly = false, raiseLabel = false, multiline = false, className, style, children, }) {
9
9
  const hasLabel = hasContent(label);
10
10
  const hasError = hasContent(error);
11
11
  const message = hasError ? error : hint;
12
12
  const labelElement = hasLabel && (_jsxs("label", { id: labelId, className: "nx-field__label", htmlFor: controlId, children: [label, required && (_jsx("span", { className: "nx-field__required", "aria-hidden": "true", children: "*" }))] }));
13
- return (_jsxs("div", { className: cx("nx-field", `nx-field--${design}`, `nx-field--${size}`, multiline && "nx-field--multiline", className), "data-invalid": hasError || undefined, "data-disabled": disabled || undefined, "data-readonly": readOnly || undefined, "data-raised": raiseLabel || undefined, style: style, children: [design === "standard" && labelElement, _jsxs("div", { className: "nx-field__box", children: [actionsStart && _jsx("span", { className: "nx-field__actions nx-field__actions--start", children: actionsStart }), icon && (_jsx("span", { className: "nx-field__icon", "aria-hidden": "true", children: icon })), hasContent(prefix) && (_jsx("span", { id: `${controlId}-prefix`, className: "nx-field__affix", children: prefix })), children, design !== "standard" && labelElement, hasContent(suffix) && (_jsx("span", { id: `${controlId}-suffix`, className: "nx-field__affix nx-field__affix--end", children: suffix })), actions && _jsx("span", { className: "nx-field__actions", children: actions }), iconEnd && (_jsx("span", { className: "nx-field__icon nx-field__icon--end", "aria-hidden": "true", children: iconEnd }))] }), (message || aside) && (_jsxs("div", { className: "nx-field__footer", children: [message && (_jsxs("p", { id: messageId, className: cx("nx-field__message", hasError && "nx-field__message--error"), children: [hasError && _jsx(InlineIcon, { icon: iconAlertCircle }), _jsx("span", { children: message })] })), aside && _jsx("span", { className: "nx-field__aside", children: aside })] }))] }));
13
+ return (_jsxs("div", { className: cx("nx-field", `nx-field--${design}`, `nx-field--${size}`, multiline && "nx-field--multiline", className), "data-invalid": hasError || invalid || undefined, "data-disabled": disabled || undefined, "data-readonly": readOnly || undefined, "data-raised": raiseLabel || undefined, style: style, children: [design === "standard" && labelElement, _jsxs("div", { className: "nx-field__box", children: [actionsStart && _jsx("span", { className: "nx-field__actions nx-field__actions--start", children: actionsStart }), icon && (_jsx("span", { className: "nx-field__icon", "aria-hidden": "true", children: icon })), hasContent(prefix) && (_jsx("span", { id: `${controlId}-prefix`, className: "nx-field__affix", children: prefix })), children, design !== "standard" && labelElement, hasContent(suffix) && (_jsx("span", { id: `${controlId}-suffix`, className: "nx-field__affix nx-field__affix--end", children: suffix })), actions && _jsx("span", { className: "nx-field__actions", children: actions }), iconEnd && (_jsx("span", { className: "nx-field__icon nx-field__icon--end", "aria-hidden": "true", children: iconEnd }))] }), (message || aside) && (_jsxs("div", { className: "nx-field__footer", children: [message && (_jsxs("p", { id: messageId, className: cx("nx-field__message", hasError && "nx-field__message--error"), children: [hasError && _jsx(InlineIcon, { icon: iconAlertCircle }), _jsx("span", { children: message })] })), aside && _jsx("span", { className: "nx-field__aside", children: aside })] }))] }));
14
14
  }
15
15
  /** Whether a node renders something: not `undefined`, `null`, `false`, or "". */
16
16
  export const hasContent = (node) => node !== undefined && node !== null && node !== false && node !== "";
@@ -1,4 +1,4 @@
1
- import type { GroupFormProps, RowValue } from "../../Interfaces/FormInterfaces.ts";
1
+ import { type GroupFormProps, type RowValue } from "../../Interfaces/FormInterfaces.ts";
2
2
  /**
3
3
  * The rows of a `TabularForm` as sections: each row's inputs with their own labels, on a 12-column grid (`span` in
4
4
  * each input's params). The same params, value, rules, and form behavior as `TabularForm`; only the layout differs. It
@@ -10,11 +10,11 @@ import type { GroupFormProps, RowValue } from "../../Interfaces/FormInterfaces.t
10
10
  *
11
11
  * @example
12
12
  * <GroupForm name="addresses" label="Addresses" itemLabel="Address" max={5} inputs={[
13
- * { type: "dropdown", name: "country", label: "Country", required: true, options: countries, span: 6 },
14
- * { type: "text", name: "city", label: "City", required: true, span: 6 },
15
- * { type: "text", name: "zipCode", label: "Zip code", span: 4 },
16
- * { type: "dropdown", name: "type", label: "Type", options: ADDRESS_TYPES, span: 4 },
17
- * { type: "radio", name: "isPrimary", label: "Primary address", span: 4, required: true },
13
+ * { type: EInputTypes.Dropdown, name: "country", label: "Country", required: true, options: countries, span: 6 },
14
+ * { type: EInputTypes.Text, name: "city", label: "City", required: true, span: 6 },
15
+ * { type: EInputTypes.Text, name: "zipCode", label: "Zip code", span: 4 },
16
+ * { type: EInputTypes.Dropdown, name: "type", label: "Type", options: ADDRESS_TYPES, span: 4 },
17
+ * { type: EInputTypes.Radio, name: "isPrimary", label: "Primary address", span: 4, required: true },
18
18
  * ]} />
19
19
  */
20
20
  export declare function GroupForm<TRow extends RowValue = RowValue>(props: GroupFormProps<TRow>): import("react").JSX.Element;
@@ -4,13 +4,12 @@ import { iconAlertCircle, iconArrowDown, iconArrowUp, iconChevronDown, iconCopy,
4
4
  import { memo, useCallback, useLayoutEffect, useMemo, useRef, useState, useSyncExternalStore } from "react";
5
5
  import { cx } from "../../Helpers/ClassHelpers.js";
6
6
  import { useDatePreferences } from "../../Helpers/DatePreferences.js";
7
- import { formatInputValue } from "../../Helpers/InputParamsHelpers.js";
7
+ import { formatInputValue, isBooleanInput } from "../../Helpers/InputParamsHelpers.js";
8
+ import { EInputTypes } from "../../Interfaces/FormInterfaces.js";
8
9
  import { Button } from "../Documents/Button.js";
9
10
  import { firstFocusable, labelText, RowCell, RowsFooter, RowsLegend, useRowsFrame, useRowsInput, useRowVersion } from "./RowsInput.js";
10
11
  /** Inputs that read as a line of text in a collapsed section's summary. */
11
- const SUMMARY_SKIP = new Set(["checkbox", "switch", "radio", "tree", "tabular", "group", "markdown"]);
12
- /** Inputs without a box: they line up with the boxes beside them. */
13
- const CHOICE_TYPES = new Set(["checkbox", "switch", "radio"]);
12
+ const SUMMARY_SKIP = new Set([EInputTypes.CheckBox, EInputTypes.Switch, EInputTypes.Radio, EInputTypes.Tree, EInputTypes.Tabular, EInputTypes.Group, EInputTypes.Markdown, EInputTypes.Picture]);
14
13
  function defaultSummary(row, inputs, preferences) {
15
14
  const parts = [];
16
15
  for (const params of inputs) {
@@ -46,7 +45,7 @@ const GroupSection = memo(function GroupSection({ store, rowKey, index, count, i
46
45
  setCollapsed(false);
47
46
  }, [problems, collapsed]);
48
47
  // Radio columns this row has on show as tags: "Primary".
49
- const tags = inputs.filter(params => params.type === "radio" && !params.hidden && row[params.name] === true).map(labelText);
48
+ const tags = inputs.filter(params => params.type === EInputTypes.Radio && !params.hidden && row[params.name] === true).map(labelText);
50
49
  let summary = null;
51
50
  if (!open) {
52
51
  const { summary: pick } = context;
@@ -64,7 +63,7 @@ const GroupSection = memo(function GroupSection({ store, rowKey, index, count, i
64
63
  store.touch(rowKey, cell.dataset.nxCell ?? "");
65
64
  }
66
65
  const heading = (_jsxs(_Fragment, { children: [_jsx("span", { id: titleId, className: "nx-group-form__title", children: title }), tags.map(tag => (_jsx("span", { className: "nx-group-form__tag", children: tag }, tag))), summary && _jsx("span", { className: "nx-group-form__summary", children: summary }), problems > 0 && (_jsxs("span", { className: "nx-group-form__problems", children: [_jsx(InlineIcon, { icon: iconAlertCircle }), problems, " to fix"] }))] }));
67
- return (_jsxs("li", { className: "nx-group-form__section", "data-nx-row": rowKey, "data-open": open || undefined, "data-problem": problems > 0 || undefined, children: [_jsxs("div", { className: "nx-group-form__head", children: [context.collapsible ? (_jsxs("button", { type: "button", className: "nx-group-form__toggle", "aria-expanded": open, "aria-controls": open ? bodyId : undefined, "data-nx-row-actions": "", onClick: () => setCollapsed(open), children: [_jsx(InlineIcon, { icon: iconChevronDown, className: "nx-group-form__chevron" }), heading] })) : (_jsx("div", { className: "nx-group-form__heading", children: heading })), (context.sortable || context.canAdd || context.removable) && (_jsxs("div", { className: "nx-group-form__actions", children: [context.sortable && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", size: "sm", icon: _jsx(InlineIcon, { icon: iconArrowUp }), "aria-label": `Move ${name} up`, title: "Move up", disabled: index === 0, onClick: () => onAction("move-up", rowKey) }), _jsx(Button, { variant: "ghost", size: "sm", icon: _jsx(InlineIcon, { icon: iconArrowDown }), "aria-label": `Move ${name} down`, title: "Move down", disabled: index === count - 1, onClick: () => onAction("move-down", rowKey) })] })), context.canAdd && (_jsx(Button, { variant: "ghost", size: "sm", icon: _jsx(InlineIcon, { icon: iconCopy }), "aria-label": `Duplicate ${name}`, title: "Duplicate", onClick: () => onAction("duplicate", rowKey) })), context.removable && (_jsx(Button, { variant: "ghost", size: "sm", hoverTone: "danger", icon: _jsx(InlineIcon, { icon: iconTrash }), "aria-label": `Remove ${name}`, title: "Remove", onClick: () => onAction("remove", rowKey) }))] }))] }), open && (_jsx("div", { id: bodyId, role: "group", "aria-labelledby": titleId, className: "nx-group-form__body", onBlur: onBlur, children: inputs.map(params => params.hidden ? null : (_jsx("div", { className: cx("nx-group-form__cell", CHOICE_TYPES.has(params.type) && "nx-group-form__cell--choice"), style: { "--nx-span": Math.max(1, Math.min(12, params.span ?? 12)) }, "data-nx-cell": params.name, children: _jsx(RowCell, { store: store, rowKey: rowKey, params: context.cellParams(rowKey, params, index), index: index, error: store.shownError(rowKey, params.name), layout: "group", idPrefix: context.idPrefix, size: context.size, design: context.design, readOnly: context.readOnly, disabled: context.disabled, lock: context.cellLock(rowKey, params.name, index) }, store.revision(rowKey, params.name)) }, params.name))) }))] }));
66
+ return (_jsxs("li", { className: "nx-group-form__section", "data-nx-row": rowKey, "data-open": open || undefined, "data-problem": problems > 0 || undefined, children: [_jsxs("div", { className: "nx-group-form__head", children: [context.collapsible ? (_jsxs("button", { type: "button", className: "nx-group-form__toggle", "aria-expanded": open, "aria-controls": open ? bodyId : undefined, "data-nx-row-actions": "", onClick: () => setCollapsed(open), children: [_jsx(InlineIcon, { icon: iconChevronDown, className: "nx-group-form__chevron" }), heading] })) : (_jsx("div", { className: "nx-group-form__heading", children: heading })), (context.sortable || context.canAdd || context.removable) && (_jsxs("div", { className: "nx-group-form__actions", children: [context.sortable && (_jsxs(_Fragment, { children: [_jsx(Button, { variant: "ghost", size: "sm", icon: _jsx(InlineIcon, { icon: iconArrowUp }), "aria-label": `Move ${name} up`, title: "Move up", disabled: index === 0, onClick: () => onAction("move-up", rowKey) }), _jsx(Button, { variant: "ghost", size: "sm", icon: _jsx(InlineIcon, { icon: iconArrowDown }), "aria-label": `Move ${name} down`, title: "Move down", disabled: index === count - 1, onClick: () => onAction("move-down", rowKey) })] })), context.canAdd && (_jsx(Button, { variant: "ghost", size: "sm", icon: _jsx(InlineIcon, { icon: iconCopy }), "aria-label": `Duplicate ${name}`, title: "Duplicate", onClick: () => onAction("duplicate", rowKey) })), context.removable && (_jsx(Button, { variant: "ghost", size: "sm", hoverTone: "danger", icon: _jsx(InlineIcon, { icon: iconTrash }), "aria-label": `Remove ${name}`, title: "Remove", onClick: () => onAction("remove", rowKey) }))] }))] }), open && (_jsx("div", { id: bodyId, role: "group", "aria-labelledby": titleId, className: "nx-group-form__body", onBlur: onBlur, children: inputs.map(params => params.hidden ? null : (_jsx("div", { className: cx("nx-group-form__cell", isBooleanInput(params) && "nx-group-form__cell--choice"), style: { "--nx-span": Math.max(1, Math.min(12, params.span ?? 12)) }, "data-nx-cell": params.name, children: _jsx(RowCell, { store: store, rowKey: rowKey, params: context.cellParams(rowKey, params, index), index: index, error: store.shownError(rowKey, params.name), layout: "group", idPrefix: context.idPrefix, size: context.size, design: context.design, readOnly: context.readOnly, disabled: context.disabled, lock: context.cellLock(rowKey, params.name, index) }, store.revision(rowKey, params.name)) }, params.name))) }))] }));
68
67
  });
69
68
  /**
70
69
  * The rows of a `TabularForm` as sections: each row's inputs with their own labels, on a 12-column grid (`span` in
@@ -77,11 +76,11 @@ const GroupSection = memo(function GroupSection({ store, rowKey, index, count, i
77
76
  *
78
77
  * @example
79
78
  * <GroupForm name="addresses" label="Addresses" itemLabel="Address" max={5} inputs={[
80
- * { type: "dropdown", name: "country", label: "Country", required: true, options: countries, span: 6 },
81
- * { type: "text", name: "city", label: "City", required: true, span: 6 },
82
- * { type: "text", name: "zipCode", label: "Zip code", span: 4 },
83
- * { type: "dropdown", name: "type", label: "Type", options: ADDRESS_TYPES, span: 4 },
84
- * { type: "radio", name: "isPrimary", label: "Primary address", span: 4, required: true },
79
+ * { type: EInputTypes.Dropdown, name: "country", label: "Country", required: true, options: countries, span: 6 },
80
+ * { type: EInputTypes.Text, name: "city", label: "City", required: true, span: 6 },
81
+ * { type: EInputTypes.Text, name: "zipCode", label: "Zip code", span: 4 },
82
+ * { type: EInputTypes.Dropdown, name: "type", label: "Type", options: ADDRESS_TYPES, span: 4 },
83
+ * { type: EInputTypes.Radio, name: "isPrimary", label: "Primary address", span: 4, required: true },
85
84
  * ]} />
86
85
  */
87
86
  export function GroupForm(props) {
@@ -1,5 +1,5 @@
1
1
  import type { ReactNode } from "react";
2
- import type { InputParams } from "../../Interfaces/FormInterfaces.ts";
2
+ import { type InputParams } from "../../Interfaces/FormInterfaces.ts";
3
3
  import type { InputDesign } from "../../Interfaces/InputInterfaces.ts";
4
4
  import type { Size } from "../../Interfaces/TypeInterfaces.ts";
5
5
  /** What a form sets on an input it renders from params. Keys given here replace the params' own, even when `undefined`. */
@@ -10,8 +10,8 @@ export interface InputOverrides {
10
10
  form?: string;
11
11
  /** The value the input starts with: `defaultChecked` for a checkbox, switch, or radio, `defaultValue` for the rest. */
12
12
  defaultValue?: unknown;
13
- /** The new value after each change, before the params' own `onValueChange`. */
14
- onValueChange?: (value: unknown) => void;
13
+ /** The new value after each change, before the params' own `onValueChange`; a dropdown's item (items) with it. */
14
+ onValueChange?: (value: unknown, item?: unknown) => void;
15
15
  error?: string | null;
16
16
  /** Replaces the params' own, e.g. `false` for a radio in rows, where "required" means one row has it. */
17
17
  required?: boolean;
@@ -25,13 +25,16 @@ export interface InputOverrides {
25
25
  readOnlyMessage?: string;
26
26
  /** On top of the params, like `readOnly`. */
27
27
  disabled?: boolean;
28
+ /** A dropdown's value is on its way: its spinner shows, as a form's does while a picker is asked about a remembered value. */
29
+ loading?: boolean;
28
30
  fieldName?: string;
29
31
  className?: string;
30
32
  "aria-label"?: string;
31
33
  }
32
34
  /**
33
- * Renders an input from its params: `{ type: "email", name: "email", label: "Email", required: true }` gives a
34
- * `TextBox` of type email. Forms render their `inputs` with it, and tabular and group forms render each row's inputs.
35
- * Layout keys (`span`, `width`, `grow`) stay out of the component's props; `hidden` renders nothing.
35
+ * Renders an input from its params: `{ type: EInputTypes.Email, name: "email", label: "Email", required: true }` gives a
36
+ * `TextBox` of HTML type email. Forms render their `inputs` with it, and tabular and group forms render each row's inputs.
37
+ * Layout keys (`span`, `width`, `grow`, and the Form-only ones such as `showWhen` and `compute`) stay out of the
38
+ * component's props; `hidden` renders nothing.
36
39
  */
37
40
  export declare function renderInput(params: InputParams, overrides?: InputOverrides): ReactNode;
@@ -1,5 +1,6 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { isBooleanInput } from "../../Helpers/InputParamsHelpers.js";
3
+ import { EInputTypes } from "../../Interfaces/FormInterfaces.js";
3
4
  import { CheckBox, RadioButton, Switch } from "./CheckBox.js";
4
5
  import { CheckBoxGroup } from "./CheckBoxGroup.js";
5
6
  import { CodeBox } from "./CodeBox.js";
@@ -10,23 +11,26 @@ import { Dropdown } from "./Dropdown.js";
10
11
  import { GroupForm } from "./GroupForm.js";
11
12
  import { MarkdownEditor } from "./MarkdownEditor.js";
12
13
  import { NumberBox } from "./NumberBox.js";
14
+ import { PictureInput } from "./PictureInput.js";
13
15
  import { RadioGroup } from "./RadioGroup.js";
14
16
  import { RichTextEditor } from "./RichTextEditor.js";
15
17
  import { RangeSlider, Slider } from "./Slider.js";
16
18
  import { TabularForm } from "./TabularForm.js";
17
19
  import { TextArea } from "./TextArea.js";
18
20
  import { TextBox } from "./TextBox.js";
21
+ import { isTextInputType, TEXT_BOX_TYPES } from "./TextBoxTypes.js";
19
22
  import { TimePicker } from "./TimePicker.js";
20
23
  import { TreeView } from "./TreeView.js";
21
24
  /**
22
- * Renders an input from its params: `{ type: "email", name: "email", label: "Email", required: true }` gives a
23
- * `TextBox` of type email. Forms render their `inputs` with it, and tabular and group forms render each row's inputs.
24
- * Layout keys (`span`, `width`, `grow`) stay out of the component's props; `hidden` renders nothing.
25
+ * Renders an input from its params: `{ type: EInputTypes.Email, name: "email", label: "Email", required: true }` gives a
26
+ * `TextBox` of HTML type email. Forms render their `inputs` with it, and tabular and group forms render each row's inputs.
27
+ * Layout keys (`span`, `width`, `grow`, and the Form-only ones such as `showWhen` and `compute`) stay out of the
28
+ * component's props; `hidden` renders nothing.
25
29
  */
26
30
  export function renderInput(params, overrides = {}) {
27
31
  if (params.hidden)
28
32
  return null;
29
- const { type, section: _section, span: _span, width: _width, grow: _grow, hidden: _hidden, dependsOn: _dependsOn, onValueChange: ownChange, ...rest } = params;
33
+ const { type, section: _section, span: _span, width: _width, grow: _grow, hidden: _hidden, dependsOn: _dependsOn, narrowedBy: _narrowedBy, showWhen: _showWhen, readOnlyWhen: _readOnlyWhen, remember: _remember, labelWhen: _labelWhen, spanWhen: _spanWhen, compute: _compute, onValueChange: ownChange, ...rest } = params;
30
34
  const { defaultValue, onValueChange, readOnly, disabled, ...set } = overrides;
31
35
  const props = { ...rest, ...set };
32
36
  if (readOnly)
@@ -43,59 +47,60 @@ export function renderInput(params, overrides = {}) {
43
47
  }
44
48
  if (onValueChange || ownChange) {
45
49
  props.onValueChange = (value, ...more) => {
46
- onValueChange?.(value);
50
+ // A dropdown says which item it picked; the other inputs' second argument is their event.
51
+ onValueChange?.(value, type === EInputTypes.Dropdown ? more[0] : undefined);
47
52
  ownChange?.(value, ...more);
48
53
  };
49
54
  }
55
+ if (isTextInputType(type))
56
+ return _jsx(TextBox, { ...props, type: TEXT_BOX_TYPES[type] });
50
57
  switch (type) {
51
- case "text":
52
- case "email":
53
- case "password":
54
- case "search":
55
- case "tel":
56
- case "url":
57
- return _jsx(TextBox, { ...props, type: type });
58
- case "textarea":
58
+ case EInputTypes.TextArea:
59
59
  return _jsx(TextArea, { ...props });
60
- case "number":
60
+ case EInputTypes.Number:
61
61
  return _jsx(NumberBox, { ...props });
62
- case "code":
62
+ case EInputTypes.Code:
63
63
  return _jsx(CodeBox, { ...props });
64
- case "checkbox":
64
+ case EInputTypes.CheckBox:
65
65
  return _jsx(CheckBox, { ...props });
66
- case "switch":
66
+ case EInputTypes.Switch:
67
67
  return _jsx(Switch, { ...props });
68
- case "radio":
68
+ case EInputTypes.Radio:
69
69
  return _jsx(RadioButton, { ...props });
70
- case "checkbox-group":
70
+ case EInputTypes.CheckBoxGroup:
71
71
  return _jsx(CheckBoxGroup, { ...props });
72
- case "radio-group":
72
+ case EInputTypes.RadioGroup:
73
73
  return _jsx(RadioGroup, { ...props });
74
- case "dropdown":
74
+ case EInputTypes.Dropdown:
75
75
  // Either overload: `multiple` travels in the props.
76
76
  return _jsx(Dropdown, { ...props });
77
- case "date":
77
+ case EInputTypes.Date:
78
78
  return _jsx(DatePicker, { ...props });
79
- case "date-range":
79
+ case EInputTypes.DateRange:
80
80
  return _jsx(DateRangePicker, { ...props });
81
- case "time":
81
+ case EInputTypes.Time:
82
82
  return _jsx(TimePicker, { ...props });
83
- case "date-time":
83
+ case EInputTypes.DateTime:
84
84
  return _jsx(DateTimePicker, { ...props });
85
- case "slider":
85
+ case EInputTypes.Slider:
86
86
  return _jsx(Slider, { ...props });
87
- case "range-slider":
87
+ case EInputTypes.RangeSlider:
88
88
  return _jsx(RangeSlider, { ...props });
89
- case "markdown":
89
+ case EInputTypes.Markdown:
90
90
  return _jsx(MarkdownEditor, { ...props });
91
- case "rich-text":
91
+ case EInputTypes.RichText:
92
92
  return _jsx(RichTextEditor, { ...props });
93
- case "tree":
93
+ case EInputTypes.Tree:
94
94
  return _jsx(TreeView, { ...props });
95
- case "tabular":
95
+ case EInputTypes.Tabular:
96
96
  return _jsx(TabularForm, { ...props });
97
- case "group":
97
+ case EInputTypes.Group:
98
98
  return _jsx(GroupForm, { ...props });
99
+ case EInputTypes.Picture: {
100
+ // A picture is the owner's file, not a value: the form's value and field name stay out of it.
101
+ const { defaultValue: _value, name: _name, form: _form, ...picture } = props;
102
+ return _jsx(PictureInput, { ...picture });
103
+ }
99
104
  default:
100
105
  return null;
101
106
  }
@@ -0,0 +1,41 @@
1
+ import { type CSSProperties, type ReactNode } from "react";
2
+ import type { ApiModuleValue } from "../../Interfaces/ApiInterfaces.ts";
3
+ import type { Size } from "../../Interfaces/TypeInterfaces.ts";
4
+ import { type OwnerFilesParams } from "../Viewers/OwnerFiles.tsx";
5
+ export interface PictureInputProps extends Omit<OwnerFilesParams<ApiModuleValue>, "ownerId"> {
6
+ /**
7
+ * The owner's id: the record the form edits (`row?.id` in a CRUD's inputs). Null or missing for a record not saved
8
+ * yet, which has no pictures until it is: the input says so.
9
+ */
10
+ ownerId?: string | null;
11
+ label?: ReactNode;
12
+ /**
13
+ * Help text under the picture. Default: what the category takes, once it is known. There is no `required`: the
14
+ * picture is saved at once, apart from the form, so a form could not refuse a save without one.
15
+ */
16
+ hint?: ReactNode;
17
+ /** The preview's height: `sm` 72px, `md` 112px, `lg` 152px. Default `md`. */
18
+ size?: Size;
19
+ disabled?: boolean;
20
+ /** What the record is, for the note a new one shows: "branch". Default "record". */
21
+ subject?: string;
22
+ id?: string;
23
+ className?: string;
24
+ style?: CSSProperties;
25
+ "aria-label"?: string;
26
+ }
27
+ /**
28
+ * A record's picture in a form: the owner's main picture, with Upload (a new one, edited first, made the main picture),
29
+ * Edit (the main one, saved as a new picture), Remove (no main picture; the pictures stay) and, when the category keeps
30
+ * more than one, All pictures (the gallery). In a category that keeps one file, Upload is Replace and Remove deletes it.
31
+ * Clicking or pressing the picture opens the pictures window too, read only where the input is. The change is saved at
32
+ * once, not with the form: a picture is the owner's file, not one of the record's values, so the form keeps no field for
33
+ * it and sends nothing under its name.
34
+ *
35
+ * @example
36
+ * inputs: (action, row) => [
37
+ * { type: EInputTypes.Picture, name: "logo", label: "Logo", module: NexusModule.Enterprise, category: "company-logo", ownerId: row?.id, aspect: 1 },
38
+ * ...
39
+ * ]
40
+ */
41
+ export declare function PictureInput({ label, hint, size, disabled, readOnly, subject, id, className, style, "aria-label": ariaLabel, ...params }: PictureInputProps): import("react").JSX.Element;