@atscript/ui 0.1.206 → 0.1.208

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 (127) hide show
  1. package/dist/form/create-form-def.cjs +16 -18
  2. package/dist/form/create-form-def.mjs +15 -17
  3. package/dist/form/decimal-format.cjs +8 -3
  4. package/dist/form/decimal-format.d.cts +8 -2
  5. package/dist/form/decimal-format.d.mts +8 -2
  6. package/dist/form/decimal-format.mjs +8 -3
  7. package/dist/form/form-actions.cjs +9 -0
  8. package/dist/form/form-actions.d.cts +7 -1
  9. package/dist/form/form-actions.d.mts +7 -1
  10. package/dist/form/form-actions.mjs +9 -1
  11. package/dist/form/measurement.cjs +58 -0
  12. package/dist/form/measurement.d.cts +36 -1
  13. package/dist/form/measurement.d.mts +36 -1
  14. package/dist/form/measurement.mjs +57 -2
  15. package/dist/form/omit-derived.cjs +11 -0
  16. package/dist/form/omit-derived.d.cts +8 -1
  17. package/dist/form/omit-derived.d.mts +8 -1
  18. package/dist/form/omit-derived.mjs +11 -1
  19. package/dist/form/optional-mode.cjs +7 -7
  20. package/dist/form/optional-mode.d.cts +2 -1
  21. package/dist/form/optional-mode.d.mts +2 -1
  22. package/dist/form/optional-mode.mjs +8 -8
  23. package/dist/form/path-utils.cjs +10 -0
  24. package/dist/form/path-utils.d.cts +8 -1
  25. package/dist/form/path-utils.d.mts +8 -1
  26. package/dist/form/path-utils.mjs +10 -1
  27. package/dist/form/types.cjs +5 -0
  28. package/dist/form/types.d.cts +14 -0
  29. package/dist/form/types.d.mts +14 -0
  30. package/dist/form/types.mjs +5 -1
  31. package/dist/form/validate.cjs +56 -5
  32. package/dist/form/validate.d.cts +30 -2
  33. package/dist/form/validate.d.mts +30 -2
  34. package/dist/form/validate.mjs +56 -6
  35. package/dist/index.cjs +42 -6
  36. package/dist/index.d.cts +20 -12
  37. package/dist/index.d.mts +20 -12
  38. package/dist/index.mjs +23 -15
  39. package/dist/plugin/annotations.cjs +33 -14
  40. package/dist/plugin/annotations.mjs +34 -15
  41. package/dist/plugin/value-help-validation.cjs +26 -6
  42. package/dist/plugin/value-help-validation.mjs +26 -7
  43. package/dist/shared/annotation-keys.cjs +3 -0
  44. package/dist/shared/annotation-keys.d.cts +2 -1
  45. package/dist/shared/annotation-keys.d.mts +2 -1
  46. package/dist/shared/annotation-keys.mjs +3 -1
  47. package/dist/shared/dev.cjs +22 -0
  48. package/dist/shared/dev.d.cts +4 -0
  49. package/dist/shared/dev.d.mts +4 -0
  50. package/dist/shared/dev.mjs +22 -0
  51. package/dist/shared/field-resolver.cjs +21 -1
  52. package/dist/shared/field-resolver.d.cts +15 -1
  53. package/dist/shared/field-resolver.d.mts +15 -1
  54. package/dist/shared/field-resolver.mjs +20 -2
  55. package/dist/shared/merge-filters.cjs +28 -0
  56. package/dist/shared/merge-filters.d.cts +13 -0
  57. package/dist/shared/merge-filters.d.mts +13 -0
  58. package/dist/shared/merge-filters.mjs +28 -0
  59. package/dist/shared/meta-cache.cjs +5 -4
  60. package/dist/shared/meta-cache.d.cts +3 -2
  61. package/dist/shared/meta-cache.d.mts +3 -2
  62. package/dist/shared/meta-cache.mjs +5 -4
  63. package/dist/shared/resolve-component.cjs +27 -0
  64. package/dist/shared/resolve-component.d.cts +22 -0
  65. package/dist/shared/resolve-component.d.mts +22 -0
  66. package/dist/shared/resolve-component.mjs +27 -0
  67. package/dist/shared/stable-key.cjs +28 -0
  68. package/dist/shared/stable-key.d.cts +13 -0
  69. package/dist/shared/stable-key.d.mts +13 -0
  70. package/dist/shared/stable-key.mjs +28 -0
  71. package/dist/shared/to-date.cjs +65 -0
  72. package/dist/shared/to-date.d.cts +35 -0
  73. package/dist/shared/to-date.d.mts +35 -0
  74. package/dist/shared/to-date.mjs +64 -0
  75. package/dist/shared/value-label.cjs +14 -2
  76. package/dist/shared/value-label.d.cts +23 -6
  77. package/dist/shared/value-label.d.mts +23 -6
  78. package/dist/shared/value-label.mjs +14 -3
  79. package/dist/table/create-table-def.cjs +53 -13
  80. package/dist/table/create-table-def.mjs +53 -15
  81. package/dist/table/types.d.cts +15 -13
  82. package/dist/table/types.d.mts +15 -13
  83. package/dist/value-help/client-store.cjs +43 -0
  84. package/dist/value-help/client-store.d.mts +1 -0
  85. package/dist/value-help/client-store.mjs +40 -0
  86. package/dist/value-help/display-value.cjs +30 -0
  87. package/dist/value-help/display-value.d.cts +45 -0
  88. package/dist/value-help/display-value.d.mts +45 -0
  89. package/dist/value-help/display-value.mjs +30 -0
  90. package/dist/value-help/distinct-client.cjs +80 -7
  91. package/dist/value-help/distinct-client.d.cts +31 -36
  92. package/dist/value-help/distinct-client.d.mts +31 -36
  93. package/dist/value-help/distinct-client.mjs +80 -7
  94. package/dist/value-help/extract-ref.cjs +15 -4
  95. package/dist/value-help/extract-ref.d.cts +6 -1
  96. package/dist/value-help/extract-ref.d.mts +6 -1
  97. package/dist/value-help/extract-ref.mjs +16 -6
  98. package/dist/value-help/index.d.mts +6 -3
  99. package/dist/value-help/options.cjs +70 -8
  100. package/dist/value-help/options.d.cts +57 -4
  101. package/dist/value-help/options.d.mts +57 -4
  102. package/dist/value-help/options.mjs +67 -9
  103. package/dist/value-help/resolve-options.cjs +9 -7
  104. package/dist/value-help/resolve-options.d.cts +8 -9
  105. package/dist/value-help/resolve-options.d.mts +8 -9
  106. package/dist/value-help/resolve-options.mjs +9 -7
  107. package/dist/value-help/resolve.cjs +29 -8
  108. package/dist/value-help/resolve.d.cts +22 -5
  109. package/dist/value-help/resolve.d.mts +22 -5
  110. package/dist/value-help/resolve.mjs +29 -8
  111. package/dist/value-help/scope.cjs +3 -7
  112. package/dist/value-help/scope.mjs +3 -7
  113. package/dist/value-help/source.cjs +72 -0
  114. package/dist/value-help/source.d.cts +55 -0
  115. package/dist/value-help/source.d.mts +55 -0
  116. package/dist/value-help/source.mjs +71 -0
  117. package/dist/value-help/texts.cjs +318 -0
  118. package/dist/value-help/texts.d.cts +53 -0
  119. package/dist/value-help/texts.d.mts +53 -0
  120. package/dist/value-help/texts.mjs +313 -0
  121. package/dist/value-help/types.d.cts +10 -0
  122. package/dist/value-help/types.d.mts +10 -0
  123. package/dist/value-help/value-help-client.cjs +24 -20
  124. package/dist/value-help/value-help-client.d.cts +10 -5
  125. package/dist/value-help/value-help-client.d.mts +10 -5
  126. package/dist/value-help/value-help-client.mjs +22 -18
  127. package/package.json +10 -10
@@ -106,8 +106,9 @@ declare function getMetaTableDef(entry: MetaCacheEntry, texts?: Pick<UiTexts, "l
106
106
  * Drop every cached `/meta` — including the copy each cached `Client`
107
107
  * memoizes and the `@atscript/db-client` meta stores used to revalidate it
108
108
  * (the shared default one and any custom one a factory supplied) — the
109
- * value-help searches shared under them, and everything registered through
110
- * {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
109
+ * value-help searches shared under them, the texts of codes read from the
110
+ * dictionaries and the labels resolved for their bindings, and everything
111
+ * registered through {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
111
112
  * handed out keep working; the next `getMetaEntry` refetches.
112
113
  */
113
114
  declare function resetMetaCache(): void;
@@ -1,8 +1,8 @@
1
1
  import { deserializeServedType } from "../i18n/model-texts.mjs";
2
2
  import { getUiTexts } from "../i18n/ui-texts.mjs";
3
3
  import { createTableDef } from "../table/create-table-def.mjs";
4
- import { invalidateValueHelpCache } from "../value-help/value-help-client.mjs";
5
4
  import { getDefaultClientFactory } from "../client-factory.mjs";
5
+ import { resetValueHelpTexts } from "../value-help/texts.mjs";
6
6
  import { clearMetaStore, defaultMetaStore } from "@atscript/db-client";
7
7
  //#region src/shared/meta-cache.ts
8
8
  /**
@@ -231,8 +231,9 @@ function customStoreOf(client) {
231
231
  * Drop every cached `/meta` — including the copy each cached `Client`
232
232
  * memoizes and the `@atscript/db-client` meta stores used to revalidate it
233
233
  * (the shared default one and any custom one a factory supplied) — the
234
- * value-help searches shared under them, and everything registered through
235
- * {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
234
+ * value-help searches shared under them, the texts of codes read from the
235
+ * dictionaries and the labels resolved for their bindings, and everything
236
+ * registered through {@link onMetaCacheReset} (e.g. the table-presets cache). Entries already
236
237
  * handed out keep working; the next `getMetaEntry` refetches.
237
238
  */
238
239
  function resetMetaCache() {
@@ -243,7 +244,7 @@ function resetMetaCache() {
243
244
  clearMetaStore();
244
245
  for (const store of customStores.keys()) store.clear();
245
246
  customStores.clear();
246
- invalidateValueHelpCache();
247
+ resetValueHelpTexts();
247
248
  for (const listener of resetListeners) listener();
248
249
  }
249
250
  /**
@@ -0,0 +1,27 @@
1
+ const require_dev = require("./dev.cjs");
2
+ //#region src/shared/resolve-component.ts
3
+ /** The named components a development build warned about, once each. */
4
+ const warned = /* @__PURE__ */ new Set();
5
+ /**
6
+ * Which component renders a form field, a union variant or a table cell
7
+ * (since 0.1.208) — the one order of forms and tables. `entry` is the field's
8
+ * `FormFieldDef` or the column's `ColumnDef`: the component
9
+ * `entry.component` names (`@ui.form.component` / `@ui.table.component`) in
10
+ * `maps.components`, else `maps.types[entry.customType]` (a form's
11
+ * `@ui.form.type` on a structured field), else `maps.types[entry.type]`;
12
+ * `undefined` when none has one — the caller's default. A named component
13
+ * the map lacks falls through to the type's, with a warning in development
14
+ * (once per name).
15
+ */
16
+ function resolveComponent(entry, maps) {
17
+ const { components, types } = maps;
18
+ const name = entry.component;
19
+ const named = name ? components?.[name] : void 0;
20
+ if (require_dev.DEV && name && !named && !warned.has(name)) {
21
+ warned.add(name);
22
+ console.warn(`[ui] component "${name}" is not in the components map — rendering the type's component`);
23
+ }
24
+ return named ?? (entry.customType ? types?.[entry.customType] : void 0) ?? types?.[entry.type];
25
+ }
26
+ //#endregion
27
+ exports.resolveComponent = resolveComponent;
@@ -0,0 +1,22 @@
1
+ //#region src/shared/resolve-component.d.ts
2
+ /**
3
+ * Which component renders a form field, a union variant or a table cell
4
+ * (since 0.1.208) — the one order of forms and tables. `entry` is the field's
5
+ * `FormFieldDef` or the column's `ColumnDef`: the component
6
+ * `entry.component` names (`@ui.form.component` / `@ui.table.component`) in
7
+ * `maps.components`, else `maps.types[entry.customType]` (a form's
8
+ * `@ui.form.type` on a structured field), else `maps.types[entry.type]`;
9
+ * `undefined` when none has one — the caller's default. A named component
10
+ * the map lacks falls through to the type's, with a warning in development
11
+ * (once per name).
12
+ */
13
+ declare function resolveComponent<C>(entry: {
14
+ component?: string;
15
+ customType?: string;
16
+ type: string;
17
+ }, maps: {
18
+ components?: Record<string, C>;
19
+ types?: Record<string, C>;
20
+ }): C | undefined;
21
+ //#endregion
22
+ export { resolveComponent };
@@ -0,0 +1,22 @@
1
+ //#region src/shared/resolve-component.d.ts
2
+ /**
3
+ * Which component renders a form field, a union variant or a table cell
4
+ * (since 0.1.208) — the one order of forms and tables. `entry` is the field's
5
+ * `FormFieldDef` or the column's `ColumnDef`: the component
6
+ * `entry.component` names (`@ui.form.component` / `@ui.table.component`) in
7
+ * `maps.components`, else `maps.types[entry.customType]` (a form's
8
+ * `@ui.form.type` on a structured field), else `maps.types[entry.type]`;
9
+ * `undefined` when none has one — the caller's default. A named component
10
+ * the map lacks falls through to the type's, with a warning in development
11
+ * (once per name).
12
+ */
13
+ declare function resolveComponent<C>(entry: {
14
+ component?: string;
15
+ customType?: string;
16
+ type: string;
17
+ }, maps: {
18
+ components?: Record<string, C>;
19
+ types?: Record<string, C>;
20
+ }): C | undefined;
21
+ //#endregion
22
+ export { resolveComponent };
@@ -0,0 +1,27 @@
1
+ import { DEV } from "./dev.mjs";
2
+ //#region src/shared/resolve-component.ts
3
+ /** The named components a development build warned about, once each. */
4
+ const warned = /* @__PURE__ */ new Set();
5
+ /**
6
+ * Which component renders a form field, a union variant or a table cell
7
+ * (since 0.1.208) — the one order of forms and tables. `entry` is the field's
8
+ * `FormFieldDef` or the column's `ColumnDef`: the component
9
+ * `entry.component` names (`@ui.form.component` / `@ui.table.component`) in
10
+ * `maps.components`, else `maps.types[entry.customType]` (a form's
11
+ * `@ui.form.type` on a structured field), else `maps.types[entry.type]`;
12
+ * `undefined` when none has one — the caller's default. A named component
13
+ * the map lacks falls through to the type's, with a warning in development
14
+ * (once per name).
15
+ */
16
+ function resolveComponent(entry, maps) {
17
+ const { components, types } = maps;
18
+ const name = entry.component;
19
+ const named = name ? components?.[name] : void 0;
20
+ if (DEV && name && !named && !warned.has(name)) {
21
+ warned.add(name);
22
+ console.warn(`[ui] component "${name}" is not in the components map — rendering the type's component`);
23
+ }
24
+ return named ?? (entry.customType ? types?.[entry.customType] : void 0) ?? types?.[entry.type];
25
+ }
26
+ //#endregion
27
+ export { resolveComponent };
@@ -0,0 +1,28 @@
1
+ //#region src/shared/stable-key.ts
2
+ /**
3
+ * A stable string for any JSON-like value: object keys sorted at every depth,
4
+ * `RegExp` and `Date` values spelled out (plain `JSON.stringify` would
5
+ * collapse every regex to `{}`). Structurally equal values produce the same
6
+ * string whatever their key order, so a change of it means a real change.
7
+ * Reading it traverses reactive objects, so it also tracks in-place edits.
8
+ *
9
+ * @internal Shared with `@atscript/ui-table` and `@atscript/vue-table`.
10
+ */
11
+ function stableValueKey(value) {
12
+ return JSON.stringify(value, function(key, val) {
13
+ const raw = this[key];
14
+ if (raw instanceof RegExp) return {
15
+ $re: raw.source,
16
+ flags: raw.flags
17
+ };
18
+ if (raw instanceof Date) return { $date: raw.toISOString() };
19
+ if (val && typeof val === "object" && !Array.isArray(val)) {
20
+ const sorted = {};
21
+ for (const k of Object.keys(val).toSorted()) sorted[k] = val[k];
22
+ return sorted;
23
+ }
24
+ return val;
25
+ });
26
+ }
27
+ //#endregion
28
+ exports.stableValueKey = stableValueKey;
@@ -0,0 +1,13 @@
1
+ //#region src/shared/stable-key.d.ts
2
+ /**
3
+ * A stable string for any JSON-like value: object keys sorted at every depth,
4
+ * `RegExp` and `Date` values spelled out (plain `JSON.stringify` would
5
+ * collapse every regex to `{}`). Structurally equal values produce the same
6
+ * string whatever their key order, so a change of it means a real change.
7
+ * Reading it traverses reactive objects, so it also tracks in-place edits.
8
+ *
9
+ * @internal Shared with `@atscript/ui-table` and `@atscript/vue-table`.
10
+ */
11
+ declare function stableValueKey(value: unknown): string;
12
+ //#endregion
13
+ export { stableValueKey };
@@ -0,0 +1,13 @@
1
+ //#region src/shared/stable-key.d.ts
2
+ /**
3
+ * A stable string for any JSON-like value: object keys sorted at every depth,
4
+ * `RegExp` and `Date` values spelled out (plain `JSON.stringify` would
5
+ * collapse every regex to `{}`). Structurally equal values produce the same
6
+ * string whatever their key order, so a change of it means a real change.
7
+ * Reading it traverses reactive objects, so it also tracks in-place edits.
8
+ *
9
+ * @internal Shared with `@atscript/ui-table` and `@atscript/vue-table`.
10
+ */
11
+ declare function stableValueKey(value: unknown): string;
12
+ //#endregion
13
+ export { stableValueKey };
@@ -0,0 +1,28 @@
1
+ //#region src/shared/stable-key.ts
2
+ /**
3
+ * A stable string for any JSON-like value: object keys sorted at every depth,
4
+ * `RegExp` and `Date` values spelled out (plain `JSON.stringify` would
5
+ * collapse every regex to `{}`). Structurally equal values produce the same
6
+ * string whatever their key order, so a change of it means a real change.
7
+ * Reading it traverses reactive objects, so it also tracks in-place edits.
8
+ *
9
+ * @internal Shared with `@atscript/ui-table` and `@atscript/vue-table`.
10
+ */
11
+ function stableValueKey(value) {
12
+ return JSON.stringify(value, function(key, val) {
13
+ const raw = this[key];
14
+ if (raw instanceof RegExp) return {
15
+ $re: raw.source,
16
+ flags: raw.flags
17
+ };
18
+ if (raw instanceof Date) return { $date: raw.toISOString() };
19
+ if (val && typeof val === "object" && !Array.isArray(val)) {
20
+ const sorted = {};
21
+ for (const k of Object.keys(val).toSorted()) sorted[k] = val[k];
22
+ return sorted;
23
+ }
24
+ return val;
25
+ });
26
+ }
27
+ //#endregion
28
+ export { stableValueKey };
@@ -0,0 +1,65 @@
1
+ //#region src/shared/to-date.ts
2
+ /** The numeric date-only shapes of `string.date`. */
3
+ const DAY_SHAPES = [
4
+ /^(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})$/,
5
+ /^(?<m>\d{2})\/(?<d>\d{2})\/(?<y>\d{4})$/,
6
+ /^(?<d>\d{2})-(?<m>\d{2})-(?<y>\d{4})$/
7
+ ];
8
+ /** `D Month YYYY`: `Date` reads the month's name. */
9
+ const NAMED_DAY = /^(?<d>\d{1,2}) [A-Za-z]+ (?<y>\d{4})$/;
10
+ /**
11
+ * Midnight UTC of the day `y`-`m`-`d` (`m` 1–12); `undefined` when there is no
12
+ * such day (month 13, February 30). A year below 100 is that year, not 19xx.
13
+ *
14
+ * @internal Shared with `@atscript/ui-table` (its temporal filter values).
15
+ */
16
+ function utcDay(y, m, d) {
17
+ const date = /* @__PURE__ */ new Date(0);
18
+ date.setUTCFullYear(y, m - 1, d);
19
+ return date.getUTCFullYear() === y && date.getUTCMonth() === m - 1 && date.getUTCDate() === d ? date : void 0;
20
+ }
21
+ /**
22
+ * Midnight UTC of a date-only text's day: `null` when the text has a date-only
23
+ * shape but names no day (`2026-13-01`, `31 February 2026`); `undefined` for a
24
+ * text of any other shape.
25
+ */
26
+ function calendarDay(text) {
27
+ for (const shape of DAY_SHAPES) {
28
+ const g = shape.exec(text)?.groups;
29
+ if (g) return utcDay(+g.y, +g.m, +g.d) ?? null;
30
+ }
31
+ const g = NAMED_DAY.exec(text)?.groups;
32
+ if (!g) return void 0;
33
+ const named = new Date(text);
34
+ return named.getDate() === +g.d && utcDay(+g.y, named.getMonth() + 1, +g.d) || null;
35
+ }
36
+ /**
37
+ * A date value (since 0.1.208): a `Date`, epoch milliseconds, or a text `Date`
38
+ * reads (an ISO instant, …); `undefined` when it is empty, no valid date or
39
+ * the epoch instant — `0`, an unset numeric timestamp (the calendar date
40
+ * `1970-01-01` is a date). The one date reader of the form's date inputs and
41
+ * the table's date cells.
42
+ *
43
+ * The time-zone rule: a calendar date — a value with no time part, the
44
+ * `string.date` shapes `YYYY-MM-DD`, `MM/DD/YYYY`, `DD-MM-YYYY`, `D Month YYYY` —
45
+ * is the same day in every time zone (`dateOnly`). The zone applies only to a
46
+ * value that carries a time (a number, a `Date`, a text with a time): a form's
47
+ * date input shows it on the local clock (the clock a native date input edits),
48
+ * a table cell in the cell time zone (`provideCellLocale`, else the runtime's).
49
+ */
50
+ function toDate(value) {
51
+ const day = typeof value === "string" ? calendarDay(value) : void 0;
52
+ if (day !== void 0) return day ? {
53
+ date: day,
54
+ dateOnly: true
55
+ } : void 0;
56
+ const date = value instanceof Date ? value : typeof value === "number" || typeof value === "string" ? new Date(value) : void 0;
57
+ const time = date?.getTime() ?? 0;
58
+ return date && Number.isFinite(time) && time !== 0 ? {
59
+ date,
60
+ dateOnly: false
61
+ } : void 0;
62
+ }
63
+ //#endregion
64
+ exports.toDate = toDate;
65
+ exports.utcDay = utcDay;
@@ -0,0 +1,35 @@
1
+ //#region src/shared/to-date.d.ts
2
+ /** A date value read by {@link toDate}. Since 0.1.208. */
3
+ interface DateValue {
4
+ /** The instant; a date-only value's is midnight UTC of its day. */
5
+ date: Date;
6
+ /**
7
+ * A calendar date — a value with no time part (`2026-10-05`): write it in UTC
8
+ * (`timeZone: "UTC"`, the `getUTC*` getters), where `date` is its midnight.
9
+ */
10
+ dateOnly: boolean;
11
+ }
12
+ /**
13
+ * Midnight UTC of the day `y`-`m`-`d` (`m` 1–12); `undefined` when there is no
14
+ * such day (month 13, February 30). A year below 100 is that year, not 19xx.
15
+ *
16
+ * @internal Shared with `@atscript/ui-table` (its temporal filter values).
17
+ */
18
+ declare function utcDay(y: number, m: number, d: number): Date | undefined;
19
+ /**
20
+ * A date value (since 0.1.208): a `Date`, epoch milliseconds, or a text `Date`
21
+ * reads (an ISO instant, …); `undefined` when it is empty, no valid date or
22
+ * the epoch instant — `0`, an unset numeric timestamp (the calendar date
23
+ * `1970-01-01` is a date). The one date reader of the form's date inputs and
24
+ * the table's date cells.
25
+ *
26
+ * The time-zone rule: a calendar date — a value with no time part, the
27
+ * `string.date` shapes `YYYY-MM-DD`, `MM/DD/YYYY`, `DD-MM-YYYY`, `D Month YYYY` —
28
+ * is the same day in every time zone (`dateOnly`). The zone applies only to a
29
+ * value that carries a time (a number, a `Date`, a text with a time): a form's
30
+ * date input shows it on the local clock (the clock a native date input edits),
31
+ * a table cell in the cell time zone (`provideCellLocale`, else the runtime's).
32
+ */
33
+ declare function toDate(value: unknown): DateValue | undefined;
34
+ //#endregion
35
+ export { DateValue, toDate, utcDay };
@@ -0,0 +1,35 @@
1
+ //#region src/shared/to-date.d.ts
2
+ /** A date value read by {@link toDate}. Since 0.1.208. */
3
+ interface DateValue {
4
+ /** The instant; a date-only value's is midnight UTC of its day. */
5
+ date: Date;
6
+ /**
7
+ * A calendar date — a value with no time part (`2026-10-05`): write it in UTC
8
+ * (`timeZone: "UTC"`, the `getUTC*` getters), where `date` is its midnight.
9
+ */
10
+ dateOnly: boolean;
11
+ }
12
+ /**
13
+ * Midnight UTC of the day `y`-`m`-`d` (`m` 1–12); `undefined` when there is no
14
+ * such day (month 13, February 30). A year below 100 is that year, not 19xx.
15
+ *
16
+ * @internal Shared with `@atscript/ui-table` (its temporal filter values).
17
+ */
18
+ declare function utcDay(y: number, m: number, d: number): Date | undefined;
19
+ /**
20
+ * A date value (since 0.1.208): a `Date`, epoch milliseconds, or a text `Date`
21
+ * reads (an ISO instant, …); `undefined` when it is empty, no valid date or
22
+ * the epoch instant — `0`, an unset numeric timestamp (the calendar date
23
+ * `1970-01-01` is a date). The one date reader of the form's date inputs and
24
+ * the table's date cells.
25
+ *
26
+ * The time-zone rule: a calendar date — a value with no time part, the
27
+ * `string.date` shapes `YYYY-MM-DD`, `MM/DD/YYYY`, `DD-MM-YYYY`, `D Month YYYY` —
28
+ * is the same day in every time zone (`dateOnly`). The zone applies only to a
29
+ * value that carries a time (a number, a `Date`, a text with a time): a form's
30
+ * date input shows it on the local clock (the clock a native date input edits),
31
+ * a table cell in the cell time zone (`provideCellLocale`, else the runtime's).
32
+ */
33
+ declare function toDate(value: unknown): DateValue | undefined;
34
+ //#endregion
35
+ export { DateValue, toDate, utcDay };
@@ -0,0 +1,64 @@
1
+ //#region src/shared/to-date.ts
2
+ /** The numeric date-only shapes of `string.date`. */
3
+ const DAY_SHAPES = [
4
+ /^(?<y>\d{4})-(?<m>\d{2})-(?<d>\d{2})$/,
5
+ /^(?<m>\d{2})\/(?<d>\d{2})\/(?<y>\d{4})$/,
6
+ /^(?<d>\d{2})-(?<m>\d{2})-(?<y>\d{4})$/
7
+ ];
8
+ /** `D Month YYYY`: `Date` reads the month's name. */
9
+ const NAMED_DAY = /^(?<d>\d{1,2}) [A-Za-z]+ (?<y>\d{4})$/;
10
+ /**
11
+ * Midnight UTC of the day `y`-`m`-`d` (`m` 1–12); `undefined` when there is no
12
+ * such day (month 13, February 30). A year below 100 is that year, not 19xx.
13
+ *
14
+ * @internal Shared with `@atscript/ui-table` (its temporal filter values).
15
+ */
16
+ function utcDay(y, m, d) {
17
+ const date = /* @__PURE__ */ new Date(0);
18
+ date.setUTCFullYear(y, m - 1, d);
19
+ return date.getUTCFullYear() === y && date.getUTCMonth() === m - 1 && date.getUTCDate() === d ? date : void 0;
20
+ }
21
+ /**
22
+ * Midnight UTC of a date-only text's day: `null` when the text has a date-only
23
+ * shape but names no day (`2026-13-01`, `31 February 2026`); `undefined` for a
24
+ * text of any other shape.
25
+ */
26
+ function calendarDay(text) {
27
+ for (const shape of DAY_SHAPES) {
28
+ const g = shape.exec(text)?.groups;
29
+ if (g) return utcDay(+g.y, +g.m, +g.d) ?? null;
30
+ }
31
+ const g = NAMED_DAY.exec(text)?.groups;
32
+ if (!g) return void 0;
33
+ const named = new Date(text);
34
+ return named.getDate() === +g.d && utcDay(+g.y, named.getMonth() + 1, +g.d) || null;
35
+ }
36
+ /**
37
+ * A date value (since 0.1.208): a `Date`, epoch milliseconds, or a text `Date`
38
+ * reads (an ISO instant, …); `undefined` when it is empty, no valid date or
39
+ * the epoch instant — `0`, an unset numeric timestamp (the calendar date
40
+ * `1970-01-01` is a date). The one date reader of the form's date inputs and
41
+ * the table's date cells.
42
+ *
43
+ * The time-zone rule: a calendar date — a value with no time part, the
44
+ * `string.date` shapes `YYYY-MM-DD`, `MM/DD/YYYY`, `DD-MM-YYYY`, `D Month YYYY` —
45
+ * is the same day in every time zone (`dateOnly`). The zone applies only to a
46
+ * value that carries a time (a number, a `Date`, a text with a time): a form's
47
+ * date input shows it on the local clock (the clock a native date input edits),
48
+ * a table cell in the cell time zone (`provideCellLocale`, else the runtime's).
49
+ */
50
+ function toDate(value) {
51
+ const day = typeof value === "string" ? calendarDay(value) : void 0;
52
+ if (day !== void 0) return day ? {
53
+ date: day,
54
+ dateOnly: true
55
+ } : void 0;
56
+ const date = value instanceof Date ? value : typeof value === "number" || typeof value === "string" ? new Date(value) : void 0;
57
+ const time = date?.getTime() ?? 0;
58
+ return date && Number.isFinite(time) && time !== 0 ? {
59
+ date,
60
+ dateOnly: false
61
+ } : void 0;
62
+ }
63
+ //#endregion
64
+ export { toDate, utcDay };
@@ -11,18 +11,30 @@ function valueLabelOf(prop) {
11
11
  };
12
12
  }
13
13
  /**
14
- * The one rendering of a code with its text (`@ui.valueLabel`, since 0.1.190):
14
+ * The one rendering of a code with its text (since 0.1.190) — a sibling's
15
+ * (`@ui.valueLabel`) or a dictionary's (`valueHelpText`, since 0.1.207):
15
16
  * `textKey` (default) `text (key)`, `keyText` `key (text)`, `text` the text
16
17
  * alone. An empty text (`undefined`, `null`, `""`, or no scalar) yields the
17
18
  * key; an empty key yields `""` — a text without a code labels nothing.
18
19
  */
19
20
  function arrangeText(key, text, arrangement = "textKey") {
20
21
  if (key === "") return "";
21
- const label = typeof text === "string" ? text : typeof text === "number" ? String(text) : void 0;
22
+ const label = codeOf(text);
22
23
  if (!label) return key;
23
24
  if (arrangement === "text") return label;
24
25
  return arrangement === "keyText" ? `${key} (${label})` : `${label} (${key})`;
25
26
  }
27
+ /**
28
+ * A value as a code (since 0.1.207): a non-empty string, or a finite number
29
+ * written out; `undefined` for anything else. Only a code shows with a text
30
+ * (`displayValue`, `arrangeText`) or is looked up in a dictionary
31
+ * (`valueHelpText`).
32
+ */
33
+ function codeOf(value) {
34
+ if (typeof value === "string") return value === "" ? void 0 : value;
35
+ return typeof value === "number" && Number.isFinite(value) ? String(value) : void 0;
36
+ }
26
37
  //#endregion
27
38
  exports.arrangeText = arrangeText;
39
+ exports.codeOf = codeOf;
28
40
  exports.valueLabelOf = valueLabelOf;
@@ -2,24 +2,41 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
2
2
 
3
3
  //#region src/shared/value-label.d.ts
4
4
  /**
5
- * How `@ui.valueLabel` shows a code with its text (since 0.1.190):
6
- * `textKey` — `Berlin (BER)`, `keyText` — `BER (Berlin)`, `text` — `Berlin`.
5
+ * How a code shows with its text (since 0.1.190): `textKey` — `Berlin (BER)`,
6
+ * `keyText` — `BER (Berlin)`, `text` — `Berlin`.
7
7
  */
8
8
  type ValueLabelArrangement = "textKey" | "keyText" | "text";
9
- /** `@ui.valueLabel` of a field: the sibling holding the text, and the arrangement. Since 0.1.190. */
9
+ /**
10
+ * Where a code's text is, and how it shows: `@ui.valueLabel` of a field (the
11
+ * sibling holding the text, since 0.1.190), or the label of a dictionary
12
+ * (`ResolvedValueHelp.label`: a field of the dictionary, since 0.1.207).
13
+ */
10
14
  interface ValueLabel {
11
- /** The sibling field holding the text (a name, relative to the field's parent). */
15
+ /** The field holding the text: a sibling's name, or a field of the dictionary. */
12
16
  field: string;
13
17
  arrangement: ValueLabelArrangement;
14
18
  }
19
+ /** A code's text and the arrangement it shows in — what `arrangeText` renders. Since 0.1.207. */
20
+ interface ValueText {
21
+ text: string;
22
+ arrangement: ValueLabelArrangement;
23
+ }
15
24
  /** The field's `@ui.valueLabel`, the arrangement defaulted to `textKey`; `undefined` without one. */
16
25
  declare function valueLabelOf(prop: TAtscriptAnnotatedType): ValueLabel | undefined;
17
26
  /**
18
- * The one rendering of a code with its text (`@ui.valueLabel`, since 0.1.190):
27
+ * The one rendering of a code with its text (since 0.1.190) — a sibling's
28
+ * (`@ui.valueLabel`) or a dictionary's (`valueHelpText`, since 0.1.207):
19
29
  * `textKey` (default) `text (key)`, `keyText` `key (text)`, `text` the text
20
30
  * alone. An empty text (`undefined`, `null`, `""`, or no scalar) yields the
21
31
  * key; an empty key yields `""` — a text without a code labels nothing.
22
32
  */
23
33
  declare function arrangeText(key: string, text: unknown, arrangement?: ValueLabelArrangement): string;
34
+ /**
35
+ * A value as a code (since 0.1.207): a non-empty string, or a finite number
36
+ * written out; `undefined` for anything else. Only a code shows with a text
37
+ * (`displayValue`, `arrangeText`) or is looked up in a dictionary
38
+ * (`valueHelpText`).
39
+ */
40
+ declare function codeOf(value: unknown): string | undefined;
24
41
  //#endregion
25
- export { ValueLabel, ValueLabelArrangement, arrangeText, valueLabelOf };
42
+ export { ValueLabel, ValueLabelArrangement, ValueText, arrangeText, codeOf, valueLabelOf };
@@ -2,24 +2,41 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
2
2
 
3
3
  //#region src/shared/value-label.d.ts
4
4
  /**
5
- * How `@ui.valueLabel` shows a code with its text (since 0.1.190):
6
- * `textKey` — `Berlin (BER)`, `keyText` — `BER (Berlin)`, `text` — `Berlin`.
5
+ * How a code shows with its text (since 0.1.190): `textKey` — `Berlin (BER)`,
6
+ * `keyText` — `BER (Berlin)`, `text` — `Berlin`.
7
7
  */
8
8
  type ValueLabelArrangement = "textKey" | "keyText" | "text";
9
- /** `@ui.valueLabel` of a field: the sibling holding the text, and the arrangement. Since 0.1.190. */
9
+ /**
10
+ * Where a code's text is, and how it shows: `@ui.valueLabel` of a field (the
11
+ * sibling holding the text, since 0.1.190), or the label of a dictionary
12
+ * (`ResolvedValueHelp.label`: a field of the dictionary, since 0.1.207).
13
+ */
10
14
  interface ValueLabel {
11
- /** The sibling field holding the text (a name, relative to the field's parent). */
15
+ /** The field holding the text: a sibling's name, or a field of the dictionary. */
12
16
  field: string;
13
17
  arrangement: ValueLabelArrangement;
14
18
  }
19
+ /** A code's text and the arrangement it shows in — what `arrangeText` renders. Since 0.1.207. */
20
+ interface ValueText {
21
+ text: string;
22
+ arrangement: ValueLabelArrangement;
23
+ }
15
24
  /** The field's `@ui.valueLabel`, the arrangement defaulted to `textKey`; `undefined` without one. */
16
25
  declare function valueLabelOf(prop: TAtscriptAnnotatedType): ValueLabel | undefined;
17
26
  /**
18
- * The one rendering of a code with its text (`@ui.valueLabel`, since 0.1.190):
27
+ * The one rendering of a code with its text (since 0.1.190) — a sibling's
28
+ * (`@ui.valueLabel`) or a dictionary's (`valueHelpText`, since 0.1.207):
19
29
  * `textKey` (default) `text (key)`, `keyText` `key (text)`, `text` the text
20
30
  * alone. An empty text (`undefined`, `null`, `""`, or no scalar) yields the
21
31
  * key; an empty key yields `""` — a text without a code labels nothing.
22
32
  */
23
33
  declare function arrangeText(key: string, text: unknown, arrangement?: ValueLabelArrangement): string;
34
+ /**
35
+ * A value as a code (since 0.1.207): a non-empty string, or a finite number
36
+ * written out; `undefined` for anything else. Only a code shows with a text
37
+ * (`displayValue`, `arrangeText`) or is looked up in a dictionary
38
+ * (`valueHelpText`).
39
+ */
40
+ declare function codeOf(value: unknown): string | undefined;
24
41
  //#endregion
25
- export { ValueLabel, ValueLabelArrangement, arrangeText, valueLabelOf };
42
+ export { ValueLabel, ValueLabelArrangement, ValueText, arrangeText, codeOf, valueLabelOf };
@@ -11,17 +11,28 @@ function valueLabelOf(prop) {
11
11
  };
12
12
  }
13
13
  /**
14
- * The one rendering of a code with its text (`@ui.valueLabel`, since 0.1.190):
14
+ * The one rendering of a code with its text (since 0.1.190) — a sibling's
15
+ * (`@ui.valueLabel`) or a dictionary's (`valueHelpText`, since 0.1.207):
15
16
  * `textKey` (default) `text (key)`, `keyText` `key (text)`, `text` the text
16
17
  * alone. An empty text (`undefined`, `null`, `""`, or no scalar) yields the
17
18
  * key; an empty key yields `""` — a text without a code labels nothing.
18
19
  */
19
20
  function arrangeText(key, text, arrangement = "textKey") {
20
21
  if (key === "") return "";
21
- const label = typeof text === "string" ? text : typeof text === "number" ? String(text) : void 0;
22
+ const label = codeOf(text);
22
23
  if (!label) return key;
23
24
  if (arrangement === "text") return label;
24
25
  return arrangement === "keyText" ? `${key} (${label})` : `${label} (${key})`;
25
26
  }
27
+ /**
28
+ * A value as a code (since 0.1.207): a non-empty string, or a finite number
29
+ * written out; `undefined` for anything else. Only a code shows with a text
30
+ * (`displayValue`, `arrangeText`) or is looked up in a dictionary
31
+ * (`valueHelpText`).
32
+ */
33
+ function codeOf(value) {
34
+ if (typeof value === "string") return value === "" ? void 0 : value;
35
+ return typeof value === "number" && Number.isFinite(value) ? String(value) : void 0;
36
+ }
26
37
  //#endregion
27
- export { arrangeText, valueLabelOf };
38
+ export { arrangeText, codeOf, valueLabelOf };