viewkitjs 0.22.0 → 0.24.0-pr-755-9d44fcd

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 (244) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/fields/dist/creatable.d.ts +9 -5
  3. package/fields/dist/creatable.js +8 -1
  4. package/fields/dist/messages.d.ts +19 -1
  5. package/fields/dist/messages.js +75 -0
  6. package/fields/dist/registry.js +4 -7
  7. package/fields/dist/types.d.ts +4 -2
  8. package/fields/dist/zod.d.ts +58 -0
  9. package/fields/dist/zod.js +430 -2
  10. package/fields/docs/guides/checking-definitions.md +6 -1
  11. package/fields/docs/guides/field-types.md +5 -1
  12. package/fields/docs/reference/definitions.md +1 -2
  13. package/fields/docs/reference/types.md +2 -1
  14. package/fields/skills/viewkit/SKILL.md +2 -2
  15. package/package.json +2 -4
  16. package/views/dist/contract.d.ts +6 -289
  17. package/views/dist/contract.js +1 -96
  18. package/views/dist/controls/atoms.d.ts +8 -0
  19. package/views/dist/controls/atoms.js +8 -0
  20. package/views/dist/controls/button/tokens.d.ts +351 -0
  21. package/views/dist/controls/button/tokens.js +90 -0
  22. package/views/dist/controls/checkbox/checkbox.d.ts +28 -0
  23. package/views/dist/controls/checkbox/checkbox.js +15 -0
  24. package/views/dist/controls/checkbox/looks.d.ts +3 -0
  25. package/views/dist/controls/checkbox/looks.js +8 -0
  26. package/views/dist/controls/checkbox/map-checkbox.d.ts +2 -0
  27. package/views/dist/controls/checkbox/map-checkbox.js +5 -0
  28. package/views/dist/controls/checkbox/tokens.d.ts +131 -0
  29. package/views/dist/controls/checkbox/tokens.js +35 -0
  30. package/views/dist/controls/checkbox.css +133 -0
  31. package/views/dist/controls/controls.d.ts +12 -3
  32. package/views/dist/controls/controls.js +13 -1
  33. package/views/dist/controls/field/field.d.ts +94 -0
  34. package/views/dist/controls/field/field.js +46 -0
  35. package/views/dist/controls/field/looks.d.ts +13 -0
  36. package/views/dist/controls/field/looks.js +22 -0
  37. package/views/dist/controls/field/tokens.d.ts +75 -0
  38. package/views/dist/controls/field/tokens.js +21 -0
  39. package/views/dist/controls/field.css +98 -0
  40. package/views/dist/controls/glass-button/glass-button.d.ts +40 -0
  41. package/views/dist/controls/glass-button/glass-button.js +16 -0
  42. package/views/dist/controls/glass-button/looks.d.ts +4 -0
  43. package/views/dist/controls/glass-button/looks.js +4 -0
  44. package/views/dist/controls/glass-button/tokens.d.ts +127 -0
  45. package/views/dist/controls/glass-button/tokens.js +34 -0
  46. package/views/dist/controls/glass-button.css +111 -0
  47. package/views/dist/controls/grip/grip.d.ts +14 -0
  48. package/views/dist/controls/grip/grip.js +9 -0
  49. package/views/dist/controls/index.d.ts +32 -0
  50. package/views/dist/controls/index.js +31 -0
  51. package/views/dist/controls/inline-input/inline-input.d.ts +14 -0
  52. package/views/dist/controls/inline-input/inline-input.js +10 -0
  53. package/views/dist/controls/inline-input/looks.d.ts +3 -0
  54. package/views/dist/controls/inline-input/looks.js +16 -0
  55. package/views/dist/controls/inline-input/tokens.d.ts +79 -0
  56. package/views/dist/controls/inline-input/tokens.js +22 -0
  57. package/views/dist/controls/inline-input.css +78 -0
  58. package/views/dist/controls/input/autofill.d.ts +25 -0
  59. package/views/dist/controls/input/autofill.js +17 -0
  60. package/views/dist/controls/input/input.d.ts +119 -0
  61. package/views/dist/controls/input/input.js +127 -0
  62. package/views/dist/controls/input/looks.d.ts +41 -0
  63. package/views/dist/controls/input/looks.js +48 -0
  64. package/views/dist/controls/input/map-input.d.ts +2 -0
  65. package/views/dist/controls/input/map-input.js +5 -0
  66. package/views/dist/controls/input/tokens.d.ts +171 -0
  67. package/views/dist/controls/input/tokens.js +45 -0
  68. package/views/dist/controls/input.css +381 -0
  69. package/views/dist/controls/internal/anchor.d.ts +16 -0
  70. package/views/dist/controls/internal/anchor.js +8 -0
  71. package/views/dist/controls/internal/close-reason.d.ts +5 -0
  72. package/views/dist/controls/internal/close-reason.js +2 -0
  73. package/views/dist/controls/internal/hold.d.ts +25 -0
  74. package/views/dist/controls/internal/hold.js +81 -0
  75. package/views/dist/controls/internal/icons.d.ts +8 -0
  76. package/views/dist/controls/internal/icons.js +65 -0
  77. package/views/dist/controls/internal/popup-host.d.ts +7 -0
  78. package/views/dist/controls/internal/popup-host.js +10 -0
  79. package/views/dist/controls/internal/read-token.d.ts +6 -0
  80. package/views/dist/controls/internal/read-token.js +11 -0
  81. package/views/dist/controls/internal/reorder.d.ts +44 -0
  82. package/views/dist/controls/internal/reorder.js +83 -0
  83. package/views/dist/controls/internal/scroll.d.ts +11 -0
  84. package/views/dist/controls/internal/scroll.js +14 -0
  85. package/views/dist/controls/kbd/kbd.d.ts +13 -0
  86. package/views/dist/controls/kbd/kbd.js +10 -0
  87. package/views/dist/controls/kbd/looks.d.ts +4 -0
  88. package/views/dist/controls/kbd/looks.js +4 -0
  89. package/views/dist/controls/kbd/tokens.d.ts +47 -0
  90. package/views/dist/controls/kbd/tokens.js +14 -0
  91. package/views/dist/controls/kbd.css +46 -0
  92. package/views/dist/controls/list/tokens.d.ts +139 -0
  93. package/views/dist/controls/list/tokens.js +37 -0
  94. package/views/dist/controls/list.css +188 -0
  95. package/views/dist/controls/menu-list/keys.d.ts +7 -0
  96. package/views/dist/controls/menu-list/keys.js +29 -0
  97. package/views/dist/controls/menu-list/looks.d.ts +4 -0
  98. package/views/dist/controls/menu-list/looks.js +20 -0
  99. package/views/dist/controls/menu-list/menu-list.d.ts +196 -0
  100. package/views/dist/controls/menu-list/menu-list.js +346 -0
  101. package/views/dist/controls/menu-list/tokens.d.ts +187 -0
  102. package/views/dist/controls/menu-list/tokens.js +49 -0
  103. package/views/dist/controls/menu-list.css +259 -0
  104. package/views/dist/controls/number-field/number-field.d.ts +48 -0
  105. package/views/dist/controls/number-field/number-field.js +34 -0
  106. package/views/dist/controls/number-field/tokens.d.ts +47 -0
  107. package/views/dist/controls/number-field/tokens.js +14 -0
  108. package/views/dist/controls/number-field.css +54 -0
  109. package/views/dist/controls/option/atom-tag.d.ts +6 -0
  110. package/views/dist/controls/option/atom-tag.js +6 -0
  111. package/views/dist/controls/option/looks.d.ts +7 -0
  112. package/views/dist/controls/option/looks.js +21 -0
  113. package/views/dist/controls/option/option.d.ts +35 -0
  114. package/views/dist/controls/option/option.js +32 -0
  115. package/views/dist/controls/option/tokens.d.ts +223 -0
  116. package/views/dist/controls/option/tokens.js +58 -0
  117. package/views/dist/controls/option.css +92 -0
  118. package/views/dist/controls/phone-header/header-bar.d.ts +18 -0
  119. package/views/dist/controls/phone-header/header-bar.js +9 -0
  120. package/views/dist/controls/phone-header/looks.d.ts +4 -0
  121. package/views/dist/controls/phone-header/looks.js +4 -0
  122. package/views/dist/controls/phone-header/soft-edge.d.ts +5 -0
  123. package/views/dist/controls/phone-header/soft-edge.js +3 -0
  124. package/views/dist/controls/phone-header/tokens.d.ts +59 -0
  125. package/views/dist/controls/phone-header/tokens.js +17 -0
  126. package/views/dist/controls/phone-header.css +51 -0
  127. package/views/dist/controls/popover/looks.d.ts +4 -0
  128. package/views/dist/controls/popover/looks.js +10 -0
  129. package/views/dist/controls/popover/map-popover.d.ts +3 -0
  130. package/views/dist/controls/popover/map-popover.js +5 -0
  131. package/views/dist/controls/popover/popover.d.ts +74 -0
  132. package/views/dist/controls/popover/popover.js +106 -0
  133. package/views/dist/controls/popover/tokens.d.ts +83 -0
  134. package/views/dist/controls/popover/tokens.js +23 -0
  135. package/views/dist/controls/popover.css +94 -0
  136. package/views/dist/controls/scrollbar/scrollbar.d.ts +10 -0
  137. package/views/dist/controls/scrollbar/scrollbar.js +143 -0
  138. package/views/dist/controls/scrollbar/tokens.d.ts +43 -0
  139. package/views/dist/controls/scrollbar/tokens.js +13 -0
  140. package/views/dist/controls/scrollbar.css +47 -0
  141. package/views/dist/controls/sheet/bottom-sheet.d.ts +98 -0
  142. package/views/dist/controls/sheet/bottom-sheet.js +375 -0
  143. package/views/dist/controls/sheet/forms.d.ts +38 -0
  144. package/views/dist/controls/sheet/forms.js +26 -0
  145. package/views/dist/controls/sheet/looks.d.ts +4 -0
  146. package/views/dist/controls/sheet/looks.js +10 -0
  147. package/views/dist/controls/sheet/map-sheet.d.ts +3 -0
  148. package/views/dist/controls/sheet/map-sheet.js +12 -0
  149. package/views/dist/controls/sheet/spring.d.ts +22 -0
  150. package/views/dist/controls/sheet/spring.js +48 -0
  151. package/views/dist/controls/sheet/tokens.d.ts +143 -0
  152. package/views/dist/controls/sheet/tokens.js +38 -0
  153. package/views/dist/controls/sheet.css +223 -0
  154. package/views/dist/controls/spinner/tokens.d.ts +55 -0
  155. package/views/dist/controls/spinner/tokens.js +16 -0
  156. package/views/dist/controls/status/atom-status-badge.d.ts +10 -0
  157. package/views/dist/controls/status/atom-status-badge.js +13 -0
  158. package/views/dist/controls/status/looks.d.ts +4 -0
  159. package/views/dist/controls/status/looks.js +22 -0
  160. package/views/dist/controls/status/marks.d.ts +26 -0
  161. package/views/dist/controls/status/marks.js +73 -0
  162. package/views/dist/controls/status/status.d.ts +43 -0
  163. package/views/dist/controls/status/status.js +26 -0
  164. package/views/dist/controls/status/tokens.d.ts +407 -0
  165. package/views/dist/controls/status/tokens.js +104 -0
  166. package/views/dist/controls/status.css +164 -0
  167. package/views/dist/controls/switch/looks.d.ts +4 -0
  168. package/views/dist/controls/switch/looks.js +19 -0
  169. package/views/dist/controls/switch/switch.d.ts +15 -0
  170. package/views/dist/controls/switch/switch.js +11 -0
  171. package/views/dist/controls/switch/tokens.d.ts +139 -0
  172. package/views/dist/controls/switch/tokens.js +37 -0
  173. package/views/dist/controls/switch.css +169 -0
  174. package/views/dist/controls/tag/atom-cell-more.d.ts +3 -0
  175. package/views/dist/controls/tag/atom-cell-more.js +5 -0
  176. package/views/dist/controls/tag/looks.d.ts +4 -0
  177. package/views/dist/controls/tag/looks.js +4 -0
  178. package/views/dist/controls/tag/tag.d.ts +25 -0
  179. package/views/dist/controls/tag/tag.js +19 -0
  180. package/views/dist/controls/tag/tokens.d.ts +63 -0
  181. package/views/dist/controls/tag/tokens.js +18 -0
  182. package/views/dist/controls/tag.css +81 -0
  183. package/views/dist/controls/toggle/looks.d.ts +3 -0
  184. package/views/dist/controls/toggle/looks.js +12 -0
  185. package/views/dist/controls/toggle/toggle.d.ts +47 -0
  186. package/views/dist/controls/toggle/toggle.js +23 -0
  187. package/views/dist/controls/toggle/tokens.d.ts +55 -0
  188. package/views/dist/controls/toggle/tokens.js +16 -0
  189. package/views/dist/controls/toggle.css +67 -0
  190. package/views/dist/controls/tokens.d.ts +16 -0
  191. package/views/dist/controls/tokens.js +49 -0
  192. package/views/dist/controls/tooltip/looks.d.ts +4 -0
  193. package/views/dist/controls/tooltip/looks.js +4 -0
  194. package/views/dist/controls/tooltip/map-tooltip.d.ts +3 -0
  195. package/views/dist/controls/tooltip/map-tooltip.js +5 -0
  196. package/views/dist/controls/tooltip/tokens.d.ts +75 -0
  197. package/views/dist/controls/tooltip/tokens.js +21 -0
  198. package/views/dist/controls/tooltip/tooltip.d.ts +54 -0
  199. package/views/dist/controls/tooltip/tooltip.js +78 -0
  200. package/views/dist/controls/tooltip.css +94 -0
  201. package/views/dist/grid/chrome/GridTable.js +21 -19
  202. package/views/dist/grid/chrome/grid-caret-keys.d.ts +7 -0
  203. package/views/dist/grid/chrome/grid-caret-keys.js +22 -0
  204. package/views/dist/grid/chrome/grid-row-window.js +3 -0
  205. package/views/dist/grid/chrome/useGridColumnLayout.d.ts +4 -1
  206. package/views/dist/grid/chrome/useGridColumnLayout.js +17 -2
  207. package/views/dist/grid/chrome/useGridFittedWidths.d.ts +32 -0
  208. package/views/dist/grid/chrome/useGridFittedWidths.js +59 -0
  209. package/views/dist/grid/chrome/useGridKeyboard.js +3 -0
  210. package/views/dist/looks/index.d.ts +16 -0
  211. package/views/dist/looks/index.js +16 -0
  212. package/views/dist/looks/looks.d.ts +10 -9
  213. package/views/dist/looks/pieces.js +38 -2
  214. package/views/dist/model/column-schema.d.ts +3 -2
  215. package/views/dist/model/column-state.d.ts +11 -1
  216. package/views/dist/model/column-state.js +8 -2
  217. package/views/dist/styles.css +2362 -7
  218. package/views/dist/styles.unlayered.css +2362 -7
  219. package/views/docs/contract.md +5 -97
  220. package/views/docs/controls/button.md +93 -0
  221. package/views/docs/controls/checkbox.md +38 -0
  222. package/views/docs/controls/field.md +26 -0
  223. package/views/docs/controls/glass-button.md +37 -0
  224. package/views/docs/controls/inline-input.md +27 -0
  225. package/views/docs/controls/input.md +48 -0
  226. package/views/docs/controls/kbd.md +17 -0
  227. package/views/docs/controls/list.md +40 -0
  228. package/views/docs/controls/menu-list.md +52 -0
  229. package/views/docs/controls/number-field.md +17 -0
  230. package/views/docs/controls/option.md +61 -0
  231. package/views/docs/controls/phone-header.md +20 -0
  232. package/views/docs/controls/popover.md +26 -0
  233. package/views/docs/controls/scrollbar.md +16 -0
  234. package/views/docs/controls/sheet.md +41 -0
  235. package/views/docs/controls/spinner.md +19 -0
  236. package/views/docs/controls/status.md +107 -0
  237. package/views/docs/controls/switch.md +40 -0
  238. package/views/docs/controls/tag.md +21 -0
  239. package/views/docs/controls/toggle.md +19 -0
  240. package/views/docs/controls/tooltip.md +24 -0
  241. package/views/docs/getting-started.md +1 -1
  242. package/views/docs/reference/controls.md +213 -2
  243. package/views/docs/reference/looks.md +70 -3
  244. package/views/docs/reference/views.md +7 -2
package/CHANGELOG.md CHANGED
@@ -5,6 +5,33 @@ Until 0.19.0 ViewKit shipped as three packages; their changes are in [fields/CHA
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [0.23.0] — 2026-11-25
9
+
10
+ viewkitjs/views/controls: the Option, the Tag, the Status and the Switch, their looks in viewkitjs/views/looks; CONTROL_ATOMS draws ViewKit's Tag, StatusBadge and CellMore atoms with them for an app that spreads it into its atoms.
11
+
12
+ ### Added
13
+
14
+ - `viewkitjs/views/controls`: the bottom Sheet (`Sheet`, `SheetHead`, `SheetBody`, `SheetFoot`, `SheetStep`, `SheetButton`, `SheetClose`, `useSheetCloseAll`, `STOPS`), with its forms, its stops and its spring, and the phone's header bar (`HeaderBar`) with the soft edge it stands on (`SoftEdge`), join the default controls, on Base UI. `CONTROLS` now also holds `Sheet`. Their stylesheets are `viewkitjs/views/controls/sheet.css` and `phone-header.css`, and the ready stylesheet carries them.
15
+ - `viewkitjs/views/looks`: `SHEET_LOOKS` and `PHONE_HEADER_LOOKS`, by the Outright kit's names.
16
+ - `viewkitjs/views/controls`: the Popover, the Tooltip (with `TooltipGroup`, `TooltipShown` and `TOOLTIP_TIMING`), the Kbd, the Glass button (with `GlassButtonGroup`) and the Scrollbar join the default controls, on Base UI; `POPUP_HOST` and `popupHostOf` name where a popup stands. `CONTROLS` now also holds `Popover` and `Tooltip`. Each control's stylesheet is `viewkitjs/views/controls/<piece>.css` (`popover`, `tooltip`, `kbd`, `glass-button`, `scrollbar`), every name it reads listed on its page under `docs/controls/`, and the ready stylesheet carries them.
17
+ - `viewkitjs/views/looks`: `POPOVER_LOOKS`, `TOOLTIP_LOOKS`, `KBD_LOOKS` and `GLASS_BUTTON_LOOKS`, each control's options by the Outright kit's names.
18
+ - `viewkitjs/views/controls`: the Input (with its InputGroup, addons, buttons and segments, and a box's own look), the inline input, the Field (with FieldSet, FieldSeparator and Field rows), the Toggle and its group, the number field and the Checkbox (with its mark and list), on Base UI, as the Outright kit draws them; and `useAutofill`, which turns the browser's and the password managers' filling off on a box.
19
+ - `CONTROLS` draws the components map's `Input` and `Checkbox`.
20
+ - Their options and looks on `viewkitjs/views/looks`: `INPUT_LOOKS`, `INLINE_INPUT_LOOKS`, `FIELD_LOOKS`, `TOGGLE_LOOKS`, `CHECKBOX_LOOKS`; a box's own look beside the Input's (`InputOwnLook`, `inputAttrs`, `inputOwnAttrs`, `inputFrameAttrs`, `kindLook`, `attioBox`) and a Field rows card's (`fieldRowsAttrs`, `FieldRowsLook`).
21
+ - `VK_CONTROL_TOKENS_BY_PIECE` and `ControlToken`: each default control's own list of the names its stylesheet reads, with each name's kind and the Outright token it stands for (`outright`). `VK_CONTROL_TOKENS` gathers them, once each.
22
+ - Each control's names, kinds, Outright tokens and defaults are on its own page, `views/docs/controls/<piece>.md`.
23
+
24
+ ### Changed
25
+
26
+ - `viewkitjs/views`: a column's `width` is optional. A grid column with no width of its own, and none the person or the saved view set, starts as wide as the values it first draws and its header need: never narrower than its header, at most 320 px, within the column's own `grid.minWidth` and `grid.maxWidth`. It keeps that width as rows scroll, load or change; a resize still wins, and a double-click on the handle goes back to it. On a phone the pinned columns with no width start at 160 px, so the rest of the row stays in view. A column that names a width is unchanged.
27
+ - The Sheet settles on the quick spring, with the smooth corner and the light dim where nothing is picked: My preset's picks, the Outright look's defaults.
28
+ - Where nothing says otherwise, the phone header's surface is Glass and two Glass buttons stand together on the pill, as their options' defaults say; only `data-phone-header-surface="flat"` or `data-glass-button-pair="separate"` set them apart.
29
+ - The default Popover's shadow is `md` and two Glass buttons share the glass pill unless something round them says `separate`: My preset's picks, the Outright look's defaults.
30
+ - The inline input's default is the Outright look's: the line, `md` corners, on a 20% tint of the brand (it was the `attio` look: `sm` corners on the overlay's ground). An app that picks none of its options, or only some, draws the new defaults for the rest.
31
+ - Their stylesheets, `viewkitjs/views/controls/{input,inline-input,field,toggle,number-field,checkbox}.css`, in the ready stylesheet too, and each one's tokens page under `views/docs/controls/`. Their phone rules hold below 640px, by the Outright Showcase's hooks (`o-phone`, `data-computer-host`), named in the controls' reference page.
32
+ - The number field's stepper gap is named with the addon it stands in (`.o-input-addon.o-number-steps`), so it wins over the addon's own gap whatever order the stylesheets load in.
33
+ - The controls' stylesheet doors are one pattern, `viewkitjs/views/controls/<piece>.css` (the outline's `smooth.css`, the Button's `button.css`, the Spinner's `spinner.css`), the same paths as before.
34
+
8
35
  ## [0.22.0] — 2026-11-25
9
36
 
10
37
  ### Added
@@ -1,9 +1,8 @@
1
1
  import { type FieldConventions } from "./conventions.js";
2
2
  import type { CategoryColor } from "./design/category-colors.js";
3
3
  import type { StatusSlot } from "./design/status-slots.js";
4
- import type { FieldSpec, FieldType } from "./types.js";
5
- /** A type a person may create: every type but the one the system sets (actor) and those worked out from others. */
6
- export type CreatableFieldType = Exclude<FieldType, "actor" | "lookup" | "rollup" | "formula">;
4
+ import type { CreatableFieldType, FieldSpec } from "./types.js";
5
+ export type { CreatableFieldType } from "./types.js";
7
6
  /** A setting applies only while another word or switch setting holds `is`; absent, that setting reads as its
8
7
  * first word (a switch: off). When it stops holding, the setting is removed, and a block it leaves empty
9
8
  * (`validation`, `format`, `code`) is removed with it: `checkFieldSpec` refuses the leftovers. */
@@ -16,6 +15,8 @@ export type FieldSettingWhen = {
16
15
  type SettingBase = {
17
16
  /** Where it sits in a definition, dotted: "validation.maxLength", "code.fixed". */
18
17
  path: string;
18
+ /** Its name in the host's words, the message `setting.label`: "Decimals shown". */
19
+ label: string;
19
20
  /** It holds a value whenever it applies: the starting definition carries one, or (a relation's kind) the app
20
21
  * sets it before it saves. */
21
22
  required?: true;
@@ -26,14 +27,18 @@ type SettingBase = {
26
27
  /** One setting a definition of a type takes, with its kind and, for a word, its allowed words. */
27
28
  export type FieldTypeSetting = SettingBase & ({
28
29
  kind: "switch";
29
- } | {
30
+ }
31
+ /** `wordLabels` names each word in the host's words, the message `setting.word`: "Up is good". */
32
+ | {
30
33
  kind: "word";
31
34
  words: readonly string[];
35
+ wordLabels: Readonly<Record<string, string>>;
32
36
  }
33
37
  /** Several of `words`, each once, in the person's order. */
34
38
  | {
35
39
  kind: "words";
36
40
  words: readonly string[];
41
+ wordLabels: Readonly<Record<string, string>>;
37
42
  } | {
38
43
  kind: "number";
39
44
  min?: number;
@@ -82,4 +87,3 @@ export declare const CREATABLE_FIELD_TYPES: readonly CreatableFieldType[];
82
87
  * system sets, nor a lookup, rollup or formula, which are worked out from other fields.
83
88
  */
84
89
  export declare function creatableFieldTypes(cv?: FieldConventions): readonly FieldTypeEntry[];
85
- export {};
@@ -172,6 +172,13 @@ function deepFreeze(value) {
172
172
  }
173
173
  deepFreeze(ENTRIES);
174
174
  export const CREATABLE_FIELD_TYPES = Object.freeze(ENTRIES.map((e) => e.type));
175
+ function labelled(type, setting, cv) {
176
+ const label = cv.messages({ key: "setting.label", values: { type, path: setting.path } });
177
+ if (setting.kind !== "word" && setting.kind !== "words")
178
+ return Object.freeze({ ...setting, label });
179
+ const wordLabels = Object.freeze(Object.fromEntries(setting.words.map((word) => [word, cv.messages({ key: "setting.word", values: { type, path: setting.path, word } })])));
180
+ return Object.freeze({ ...setting, label, wordLabels });
181
+ }
175
182
  export function creatableFieldTypes(cv = DEFAULT_CONVENTIONS) {
176
183
  cv = conventionsOr(cv);
177
184
  return Object.freeze(ENTRIES.map(({ type, several, start, settings }) => {
@@ -181,7 +188,7 @@ export function creatableFieldTypes(cv = DEFAULT_CONVENTIONS) {
181
188
  label,
182
189
  icon: type,
183
190
  several,
184
- settings,
191
+ settings: Object.freeze(settings.map((setting) => labelled(type, setting, cv))),
185
192
  spec: deepFreeze(JSON.parse(JSON.stringify({ type, label, ...start }))),
186
193
  });
187
194
  }));
@@ -1,4 +1,4 @@
1
- import type { ActorType, FieldType, RollupFn } from "./types.js";
1
+ import type { ActorType, CreatableFieldType, FieldType, RollupFn } from "./types.js";
2
2
  /**
3
3
  * A typed message plus the values its host may interpolate. EVERY sentence the
4
4
  * library writes is one of these — a host that translates them translates the
@@ -69,6 +69,24 @@ export type FieldMessage = {
69
69
  values: {
70
70
  type: FieldType;
71
71
  };
72
+ }
73
+ /** A setting a New field dialog offers (`creatableFieldTypes`), by where it sits in the type's definition:
74
+ * "Decimals shown" for `format.decimals`. */
75
+ | {
76
+ key: "setting.label";
77
+ values: {
78
+ type: CreatableFieldType;
79
+ path: string;
80
+ };
81
+ }
82
+ /** One of the words a word or words setting offers: "Up is good" for `format.signedTone`'s `positive-good`. */
83
+ | {
84
+ key: "setting.word";
85
+ values: {
86
+ type: CreatableFieldType;
87
+ path: string;
88
+ word: string;
89
+ };
72
90
  } | {
73
91
  key: "field.cannot-empty";
74
92
  } | {
@@ -24,6 +24,75 @@ const TYPE_LABELS = {
24
24
  rollup: "Rollup",
25
25
  formula: "Formula",
26
26
  };
27
+ const SETTING_LABELS = {
28
+ default: "Default value",
29
+ "validation.minLength": "Fewest characters",
30
+ "validation.maxLength": "Most characters",
31
+ "validation.pattern": "Pattern it must match",
32
+ "format.long": "Written over several lines",
33
+ storage: "Stored as",
34
+ "validation.min": "Lowest value",
35
+ "validation.max": "Highest value",
36
+ "validation.integer": "Whole numbers only",
37
+ "validation.decimals": "Most decimals",
38
+ "format.style": "Shown as",
39
+ "format.decimals": "Decimals shown",
40
+ "format.suffix": "Unit after the number",
41
+ "format.signed": "Show + and −",
42
+ "format.signedTone": "A rise reads as",
43
+ "format.unit": "Stored in",
44
+ "format.durationStyle": "Duration style",
45
+ "format.display": "Shown as",
46
+ "code.fixed": "Currency",
47
+ of: "A range of",
48
+ period: "Per",
49
+ ahead: "A date to look forward to",
50
+ "format.dateStyle": "Date style",
51
+ "format.withTime": "Show the time",
52
+ options: "Options",
53
+ vocabulary: "Values allowed",
54
+ "validation.maxItems": "Most values",
55
+ normalize: "Tidy each value",
56
+ "relation.kind": "Links to",
57
+ cardinality: "How many",
58
+ multiple: "Holds several values",
59
+ parts: "Parts of the place",
60
+ };
61
+ const SETTING_LABEL_BY_TYPE = {
62
+ multiselect: { "validation.maxItems": "Most choices" },
63
+ name: { "validation.maxLength": "Most characters in each part" },
64
+ location: { "validation.maxLength": "Most characters in each part" },
65
+ };
66
+ const SETTING_WORDS = {
67
+ storage: { number: "Number", decimal: "Exact decimal" },
68
+ "format.style": {
69
+ plain: "Number",
70
+ duration: "Duration",
71
+ checkbox: "Checkbox",
72
+ icon: "Icon",
73
+ marker: "Marker",
74
+ text: "Words",
75
+ },
76
+ "format.signedTone": { "positive-good": "Up is good", neutral: "Neutral" },
77
+ "format.unit": { ms: "Milliseconds", s: "Seconds" },
78
+ "format.durationStyle": { adaptive: "Adaptive", clock: "Clock", units: "Units" },
79
+ "format.display": { text: "Number", bar: "Bar", ring: "Ring" },
80
+ of: { number: "Numbers", currency: "Amounts", percent: "Percents" },
81
+ period: { hour: "Hour", day: "Day", week: "Week", month: "Month", year: "Year" },
82
+ "format.dateStyle": { short: "Short", long: "Long", numeric: "Numbers only", relative: "Relative" },
83
+ vocabulary: { closed: "Only the listed options", "custom-values": "Any value typed in" },
84
+ normalize: { trim: "Trim spaces", lowercase: "Lowercase", hyphenate: "Spaces to hyphens" },
85
+ cardinality: { one: "One record", many: "Several records" },
86
+ parts: {
87
+ line1: "Address line 1",
88
+ line2: "Address line 2",
89
+ postalCode: "Postal code",
90
+ city: "City",
91
+ region: "Region",
92
+ regionCode: "Region code",
93
+ countryCode: "Country",
94
+ },
95
+ };
27
96
  const ROLLUP_VERB = {
28
97
  sum: "The sum of",
29
98
  avg: "The average",
@@ -114,6 +183,12 @@ export const resolveFieldMessage = (message) => {
114
183
  return message.values.provider;
115
184
  case "type.label":
116
185
  return TYPE_LABELS[message.values.type];
186
+ case "setting.label": {
187
+ const { type, path } = message.values;
188
+ return SETTING_LABEL_BY_TYPE[type]?.[path] ?? SETTING_LABELS[path] ?? path;
189
+ }
190
+ case "setting.word":
191
+ return SETTING_WORDS[message.values.path]?.[message.values.word] ?? message.values.word;
117
192
  case "field.cannot-empty":
118
193
  return "This field can't be emptied";
119
194
  case "field.cannot-edit":
@@ -8,7 +8,7 @@ import { NORMALIZE_STEPS } from "./normalize.js";
8
8
  import { isDecimalText } from "./parse-number.js";
9
9
  import { LOCATION_PARTS } from "./location.js";
10
10
  import { isMultipleType } from "./value-list.js";
11
- import { buildFieldSchema } from "./zod.js";
11
+ import { buildFieldSchema, readPattern } from "./zod.js";
12
12
  export const FIELD_TYPES = [
13
13
  "text",
14
14
  "number",
@@ -463,12 +463,9 @@ export function checkFieldSpec(key, spec, all = {}, context = {}) {
463
463
  if (f.emptiable && v?.minLength)
464
464
  fail("an emptiable field cannot state a minLength above 0");
465
465
  if (v?.pattern !== undefined) {
466
- try {
467
- new RegExp(v.pattern);
468
- }
469
- catch {
470
- fail("pattern is not a valid regular expression");
471
- }
466
+ const read = readPattern(v.pattern);
467
+ if (!read.ok)
468
+ fail(`pattern ${read.why}`);
472
469
  }
473
470
  }
474
471
  if (f.type === "location" && f.parts !== undefined) {
@@ -12,6 +12,8 @@ import type { ValueItem } from "./value-list.js";
12
12
  * `datetime` is an instant. `percent` is stored 0–100 — the value IS the
13
13
  * percent. `rollup` and `formula` carry a `result` that names what comes out. */
14
14
  export type FieldType = "text" | "number" | "percent" | "currency" | "date" | "datetime" | "boolean" | "select" | "status" | "multiselect" | "relation" | "user" | "url" | "domain" | "email" | "phone" | "location" | "name" | "actor" | "rich_text" | "range" | "lookup" | "rollup" | "formula";
15
+ /** A type a person may create: every type but the one the system sets (actor) and those worked out from others. */
16
+ export type CreatableFieldType = Exclude<FieldType, "actor" | "lookup" | "rollup" | "formula">;
15
17
  export type LocationValue = {
16
18
  /** The street and number. */
17
19
  line1?: string | null;
@@ -275,8 +277,8 @@ export type Breakdown = {
275
277
  export type Freshness = "live" | "minute" | "sync";
276
278
  /** The member shapes a rollup or formula may produce — declared once, used
277
279
  * by the def union (with base keys) and by `result` (without them). */
278
- /** What a text-like value may be held to. `pattern` is a regular expression
279
- * source; `checkFieldSpec` refuses one that does not compile. */
280
+ /** What a text-like value may be held to. `pattern` is a regular expression source in ViewKit's dialect, matched
281
+ * without backtracking; `checkFieldSpec` and `zodFor` refuse one outside it. */
280
282
  export type TextualValidation = {
281
283
  maxLength?: number;
282
284
  pattern?: string;
@@ -26,4 +26,62 @@ export declare function linkRoleKey(kind: string, id: string, role: string): str
26
26
  * is one once `https://` is put before it. What a kept url is held to (`accept.ts`). Text with a space or a control
27
27
  * character inside is none: a split `java\tscript:` would hide its scheme here and lose it in the address parser. */
28
28
  export declare function readsAsLink(value: unknown): boolean;
29
+ /** A pattern's source is at most this many characters. */
30
+ export declare const PATTERN_MAX_LENGTH = 500;
31
+ /** A pattern's program holds at most this many steps once its repeats are counted out (`a{3}` is three). */
32
+ export declare const PATTERN_MAX_STEPS = 1000;
33
+ /** What one value may cost against a pattern: its characters times the pattern's steps, at most this many, about a
34
+ * fifth of a second. A longer value is refused as too long before the pattern reads it (`BoundedPattern.maxValueLength`). */
35
+ export declare const PATTERN_MAX_WORK = 20000000;
36
+ /** A set of UTF-16 code units: sorted, merged, inclusive [low, high] pairs, read by binary search, so a class of any
37
+ * size costs one search per character. */
38
+ type Ranges = Int32Array;
39
+ type Assertion = "start" | "end" | "word" | "not-word";
40
+ declare const CHAR = 0;
41
+ declare const SPLIT = 1;
42
+ declare const JUMP = 2;
43
+ declare const ASSERT = 3;
44
+ declare const MATCH = 4;
45
+ type Step = {
46
+ op: typeof CHAR;
47
+ set: Ranges;
48
+ } | {
49
+ op: typeof SPLIT;
50
+ x: number;
51
+ y: number;
52
+ } | {
53
+ op: typeof JUMP;
54
+ x: number;
55
+ } | {
56
+ op: typeof ASSERT;
57
+ a: Assertion;
58
+ } | {
59
+ op: typeof MATCH;
60
+ };
61
+ type Program = readonly Step[];
62
+ /**
63
+ * A `RegExp` whose `test` runs ViewKit's matcher: what zod's `.regex()` calls, and the `source` a JSON Schema
64
+ * describes. Only `test` is bounded; `exec`, `match` and `replace` stay the engine's own, so nothing else should be
65
+ * handed one.
66
+ */
67
+ export declare class BoundedPattern extends RegExp {
68
+ #private;
69
+ /** The longest value this pattern reads within `PATTERN_MAX_WORK`; `test` answers false past it, unread. */
70
+ readonly maxValueLength: number;
71
+ constructor(source: string, program: Program);
72
+ /** Built-ins that make a new expression from this one (`split`, `matchAll`) make a plain one. */
73
+ static get [Symbol.species](): RegExpConstructor;
74
+ test(value: string): boolean;
75
+ }
76
+ /**
77
+ * The pattern read in ViewKit's dialect, or why it is refused: words that follow "pattern ", the same wherever a
78
+ * pattern is checked (`checkFieldSpec`, `zodFor`).
79
+ */
80
+ export declare function readPattern(source: string): {
81
+ ok: true;
82
+ pattern: BoundedPattern;
83
+ } | {
84
+ ok: false;
85
+ why: string;
86
+ };
29
87
  export {};