@atscript/ui 0.1.207 → 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.
- package/dist/form/create-form-def.cjs +13 -12
- package/dist/form/create-form-def.mjs +14 -13
- package/dist/form/decimal-format.cjs +8 -3
- package/dist/form/decimal-format.d.cts +8 -2
- package/dist/form/decimal-format.d.mts +8 -2
- package/dist/form/decimal-format.mjs +8 -3
- package/dist/form/form-actions.cjs +9 -0
- package/dist/form/form-actions.d.cts +7 -1
- package/dist/form/form-actions.d.mts +7 -1
- package/dist/form/form-actions.mjs +9 -1
- package/dist/form/measurement.cjs +58 -0
- package/dist/form/measurement.d.cts +36 -1
- package/dist/form/measurement.d.mts +36 -1
- package/dist/form/measurement.mjs +57 -2
- package/dist/form/omit-derived.cjs +11 -0
- package/dist/form/omit-derived.d.cts +8 -1
- package/dist/form/omit-derived.d.mts +8 -1
- package/dist/form/omit-derived.mjs +11 -1
- package/dist/form/optional-mode.cjs +7 -7
- package/dist/form/optional-mode.d.cts +2 -1
- package/dist/form/optional-mode.d.mts +2 -1
- package/dist/form/optional-mode.mjs +8 -8
- package/dist/form/types.cjs +5 -0
- package/dist/form/types.d.cts +14 -0
- package/dist/form/types.d.mts +14 -0
- package/dist/form/types.mjs +5 -1
- package/dist/form/validate.cjs +56 -5
- package/dist/form/validate.d.cts +30 -2
- package/dist/form/validate.d.mts +30 -2
- package/dist/form/validate.mjs +56 -6
- package/dist/index.cjs +24 -3
- package/dist/index.d.cts +14 -9
- package/dist/index.d.mts +14 -9
- package/dist/index.mjs +15 -10
- package/dist/plugin/annotations.cjs +1 -1
- package/dist/plugin/annotations.mjs +1 -1
- package/dist/shared/annotation-keys.d.cts +2 -1
- package/dist/shared/annotation-keys.d.mts +2 -1
- package/dist/shared/dev.cjs +22 -0
- package/dist/shared/dev.d.cts +4 -0
- package/dist/shared/dev.d.mts +4 -0
- package/dist/shared/dev.mjs +22 -0
- package/dist/shared/field-resolver.cjs +21 -1
- package/dist/shared/field-resolver.d.cts +15 -1
- package/dist/shared/field-resolver.d.mts +15 -1
- package/dist/shared/field-resolver.mjs +20 -2
- package/dist/shared/merge-filters.cjs +28 -0
- package/dist/shared/merge-filters.d.cts +13 -0
- package/dist/shared/merge-filters.d.mts +13 -0
- package/dist/shared/merge-filters.mjs +28 -0
- package/dist/shared/resolve-component.cjs +27 -0
- package/dist/shared/resolve-component.d.cts +22 -0
- package/dist/shared/resolve-component.d.mts +22 -0
- package/dist/shared/resolve-component.mjs +27 -0
- package/dist/shared/stable-key.cjs +28 -0
- package/dist/shared/stable-key.d.cts +13 -0
- package/dist/shared/stable-key.d.mts +13 -0
- package/dist/shared/stable-key.mjs +28 -0
- package/dist/shared/to-date.cjs +65 -0
- package/dist/shared/to-date.d.cts +35 -0
- package/dist/shared/to-date.d.mts +35 -0
- package/dist/shared/to-date.mjs +64 -0
- package/dist/table/create-table-def.cjs +49 -15
- package/dist/table/create-table-def.mjs +49 -16
- package/dist/table/types.d.cts +15 -13
- package/dist/table/types.d.mts +15 -13
- package/dist/value-help/distinct-client.cjs +80 -7
- package/dist/value-help/distinct-client.d.cts +31 -36
- package/dist/value-help/distinct-client.d.mts +31 -36
- package/dist/value-help/distinct-client.mjs +80 -7
- package/dist/value-help/index.d.mts +2 -2
- package/dist/value-help/options.cjs +21 -0
- package/dist/value-help/options.d.cts +17 -1
- package/dist/value-help/options.d.mts +17 -1
- package/dist/value-help/options.mjs +21 -1
- package/dist/value-help/resolve.cjs +2 -12
- package/dist/value-help/resolve.mjs +3 -13
- package/dist/value-help/scope.cjs +3 -7
- package/dist/value-help/scope.mjs +3 -7
- package/dist/value-help/texts.cjs +7 -4
- package/dist/value-help/texts.mjs +7 -4
- package/dist/value-help/value-help-client.cjs +5 -3
- package/dist/value-help/value-help-client.d.cts +3 -2
- package/dist/value-help/value-help-client.d.mts +3 -2
- package/dist/value-help/value-help-client.mjs +5 -3
- package/package.json +10 -10
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { FilterExpr } from "@atscript/db-client";
|
|
2
|
+
|
|
3
|
+
//#region src/shared/merge-filters.d.ts
|
|
4
|
+
/**
|
|
5
|
+
* AND-merge filter expressions (`undefined` ones skipped) — how the UI ANDs
|
|
6
|
+
* every filter it sends. A nested `$and` is flattened into the one, the
|
|
7
|
+
* fields next to it kept; a single expression is returned as is. Variadic
|
|
8
|
+
* since 0.1.140. In `@atscript/ui` since 0.1.208 (`@atscript/ui-table`
|
|
9
|
+
* re-exports it).
|
|
10
|
+
*/
|
|
11
|
+
declare function mergeFilters(...exprs: (FilterExpr | undefined)[]): FilterExpr | undefined;
|
|
12
|
+
//#endregion
|
|
13
|
+
export { mergeFilters };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
//#region src/shared/merge-filters.ts
|
|
2
|
+
/**
|
|
3
|
+
* AND-merge filter expressions (`undefined` ones skipped) — how the UI ANDs
|
|
4
|
+
* every filter it sends. A nested `$and` is flattened into the one, the
|
|
5
|
+
* fields next to it kept; a single expression is returned as is. Variadic
|
|
6
|
+
* since 0.1.140. In `@atscript/ui` since 0.1.208 (`@atscript/ui-table`
|
|
7
|
+
* re-exports it).
|
|
8
|
+
*/
|
|
9
|
+
function mergeFilters(...exprs) {
|
|
10
|
+
const list = exprs.filter((e) => !!e);
|
|
11
|
+
return list.length <= 1 ? list[0] : { $and: flattenAnd(list) };
|
|
12
|
+
}
|
|
13
|
+
/** The AND-ed clauses of `exprs`: each nested `$and` spread in, the keys next to it kept as one clause. */
|
|
14
|
+
function flattenAnd(exprs) {
|
|
15
|
+
const out = [];
|
|
16
|
+
for (const expr of exprs) {
|
|
17
|
+
const { $and, ...rest } = expr;
|
|
18
|
+
if (!Array.isArray($and)) {
|
|
19
|
+
out.push(expr);
|
|
20
|
+
continue;
|
|
21
|
+
}
|
|
22
|
+
out.push(...flattenAnd($and));
|
|
23
|
+
if (Object.keys(rest).length > 0) out.push(rest);
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
export { mergeFilters };
|
|
@@ -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 };
|
|
@@ -4,8 +4,9 @@ const require_field_resolver = require("../shared/field-resolver.cjs");
|
|
|
4
4
|
const require_extract_literals = require("../value-help/extract-literals.cjs");
|
|
5
5
|
const require_extract_ref = require("../value-help/extract-ref.cjs");
|
|
6
6
|
const require_exact_number = require("../shared/exact-number.cjs");
|
|
7
|
-
const
|
|
7
|
+
const require_path_utils = require("../form/path-utils.cjs");
|
|
8
8
|
const require_measurement = require("../form/measurement.cjs");
|
|
9
|
+
const require_str = require("../shared/str.cjs");
|
|
9
10
|
const require_value_label = require("../shared/value-label.cjs");
|
|
10
11
|
let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
11
12
|
//#region src/table/create-table-def.ts
|
|
@@ -59,6 +60,7 @@ function createTableDef(meta, preDeserializedType, t) {
|
|
|
59
60
|
preferredId,
|
|
60
61
|
identifierFields: identifierFieldsOf(preferredId, meta.actions ?? []),
|
|
61
62
|
versionColumn: meta.versionColumn,
|
|
63
|
+
label: dictLabelOf(meta, type),
|
|
62
64
|
crud,
|
|
63
65
|
canRemove: "remove" in crud,
|
|
64
66
|
actions,
|
|
@@ -80,17 +82,21 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
80
82
|
const sharedType = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TYPE);
|
|
81
83
|
const tableComponent = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_COMPONENT);
|
|
82
84
|
const filterOps = fieldMeta.filterOps;
|
|
83
|
-
|
|
85
|
+
const measurement = require_measurement.extractMeasurement(prop);
|
|
84
86
|
const label = require_value_label.valueLabelOf(prop);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
const siblings = require_path_utils.parentPrefix(path);
|
|
88
|
+
const valueLabel = label && {
|
|
89
|
+
path: siblings + label.field,
|
|
90
|
+
arrangement: label.arrangement
|
|
91
|
+
};
|
|
92
|
+
let selectWith = require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_SELECT_WITH);
|
|
93
|
+
for (const field of [
|
|
94
|
+
label?.field,
|
|
95
|
+
measurement.currencyRefField,
|
|
96
|
+
measurement.unitRefField
|
|
97
|
+
]) {
|
|
98
|
+
const sibling = field && siblings + field;
|
|
99
|
+
if (sibling && !selectWith?.includes(sibling)) selectWith = [...selectWith ?? [], sibling];
|
|
94
100
|
}
|
|
95
101
|
return {
|
|
96
102
|
path,
|
|
@@ -111,7 +117,7 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
111
117
|
valueHelpInfo,
|
|
112
118
|
...valueLabel && { valueLabel },
|
|
113
119
|
...distinct && { distinct },
|
|
114
|
-
...
|
|
120
|
+
...measurement
|
|
115
121
|
};
|
|
116
122
|
}
|
|
117
123
|
/**
|
|
@@ -132,12 +138,39 @@ function identifierFieldsOf(preferredId, actions) {
|
|
|
132
138
|
/**
|
|
133
139
|
* A field the caller may read: listed in `meta.fields` and not write-only —
|
|
134
140
|
* the one rule for a table's columns and a dictionary's label.
|
|
135
|
-
*
|
|
136
|
-
* @internal Shared with the value help.
|
|
137
141
|
*/
|
|
138
142
|
function isReadable(field) {
|
|
139
143
|
return field !== void 0 && field.writeOnly !== true;
|
|
140
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* The label a type's rows declare: the own field its `@ui.dict.label` marks
|
|
147
|
+
* (`@ui.dict.label 'keyText'` → that arrangement, default `textKey`), when
|
|
148
|
+
* the caller can read it. The one rule for a dictionary's label
|
|
149
|
+
* (`ResolvedValueHelp.label`) and a table's (`TableDef.label`).
|
|
150
|
+
*/
|
|
151
|
+
function dictLabelOf(meta, type) {
|
|
152
|
+
if (type.type.kind !== "object") return void 0;
|
|
153
|
+
let label;
|
|
154
|
+
for (const [field, prop] of type.type.props) {
|
|
155
|
+
const declared = prop.metadata.get(require_annotation_keys.UI_DICT_LABEL);
|
|
156
|
+
if (declared === void 0 || field === meta.versionColumn) continue;
|
|
157
|
+
label = readableLabel(meta, field, typeof declared === "string" ? declared : void 0);
|
|
158
|
+
}
|
|
159
|
+
return label;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* `field` of the served type as a label, when the caller may read it
|
|
163
|
+
* (`isReadable`); the arrangement defaults to `textKey`.
|
|
164
|
+
*
|
|
165
|
+
* @internal Shared with the value help.
|
|
166
|
+
*/
|
|
167
|
+
function readableLabel(meta, field, arrangement) {
|
|
168
|
+
if (!isReadable(meta.fields?.[field])) return void 0;
|
|
169
|
+
return {
|
|
170
|
+
field,
|
|
171
|
+
arrangement: arrangement ?? "textKey"
|
|
172
|
+
};
|
|
173
|
+
}
|
|
141
174
|
/** Sort by (order ?? 0). `toSorted` is stable per spec, so ties preserve declaration order. */
|
|
142
175
|
function byOrder(xs) {
|
|
143
176
|
return xs.toSorted((x, y) => (x.order ?? 0) - (y.order ?? 0));
|
|
@@ -252,5 +285,6 @@ function inferValueKind(prop) {
|
|
|
252
285
|
}
|
|
253
286
|
//#endregion
|
|
254
287
|
exports.createTableDef = createTableDef;
|
|
288
|
+
exports.dictLabelOf = dictLabelOf;
|
|
255
289
|
exports.inferValueKind = inferValueKind;
|
|
256
|
-
exports.
|
|
290
|
+
exports.readableLabel = readableLabel;
|
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { DB_HTTP_PATH, EXPECT_MAX_LENGTH, UI_TABLE_COMPONENT, UI_TABLE_SELECT_WITH, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE } from "../shared/annotation-keys.mjs";
|
|
1
|
+
import { DB_HTTP_PATH, EXPECT_MAX_LENGTH, UI_DICT_LABEL, UI_TABLE_COMPONENT, UI_TABLE_SELECT_WITH, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE } from "../shared/annotation-keys.mjs";
|
|
2
2
|
import { deserializeServedType } from "../i18n/model-texts.mjs";
|
|
3
3
|
import { getFieldMeta } from "../shared/field-resolver.mjs";
|
|
4
4
|
import { extractFieldLiteralOptions, isEmptyMember } from "../value-help/extract-literals.mjs";
|
|
5
5
|
import { extractValueHelp } from "../value-help/extract-ref.mjs";
|
|
6
6
|
import { isExactNumberText } from "../shared/exact-number.mjs";
|
|
7
|
-
import {
|
|
7
|
+
import { parentPrefix } from "../form/path-utils.mjs";
|
|
8
8
|
import { extractMeasurement } from "../form/measurement.mjs";
|
|
9
|
+
import { humanizePath } from "../shared/str.mjs";
|
|
9
10
|
import { valueLabelOf } from "../shared/value-label.mjs";
|
|
10
11
|
import { flattenAnnotatedType } from "@atscript/typescript/utils";
|
|
11
12
|
//#region src/table/create-table-def.ts
|
|
@@ -59,6 +60,7 @@ function createTableDef(meta, preDeserializedType, t) {
|
|
|
59
60
|
preferredId,
|
|
60
61
|
identifierFields: identifierFieldsOf(preferredId, meta.actions ?? []),
|
|
61
62
|
versionColumn: meta.versionColumn,
|
|
63
|
+
label: dictLabelOf(meta, type),
|
|
62
64
|
crud,
|
|
63
65
|
canRemove: "remove" in crud,
|
|
64
66
|
actions,
|
|
@@ -80,17 +82,21 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
80
82
|
const sharedType = getFieldMeta(prop, UI_TYPE);
|
|
81
83
|
const tableComponent = getFieldMeta(prop, UI_TABLE_COMPONENT);
|
|
82
84
|
const filterOps = fieldMeta.filterOps;
|
|
83
|
-
|
|
85
|
+
const measurement = extractMeasurement(prop);
|
|
84
86
|
const label = valueLabelOf(prop);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
const siblings = parentPrefix(path);
|
|
88
|
+
const valueLabel = label && {
|
|
89
|
+
path: siblings + label.field,
|
|
90
|
+
arrangement: label.arrangement
|
|
91
|
+
};
|
|
92
|
+
let selectWith = getFieldMeta(prop, UI_TABLE_SELECT_WITH);
|
|
93
|
+
for (const field of [
|
|
94
|
+
label?.field,
|
|
95
|
+
measurement.currencyRefField,
|
|
96
|
+
measurement.unitRefField
|
|
97
|
+
]) {
|
|
98
|
+
const sibling = field && siblings + field;
|
|
99
|
+
if (sibling && !selectWith?.includes(sibling)) selectWith = [...selectWith ?? [], sibling];
|
|
94
100
|
}
|
|
95
101
|
return {
|
|
96
102
|
path,
|
|
@@ -111,7 +117,7 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
111
117
|
valueHelpInfo,
|
|
112
118
|
...valueLabel && { valueLabel },
|
|
113
119
|
...distinct && { distinct },
|
|
114
|
-
...
|
|
120
|
+
...measurement
|
|
115
121
|
};
|
|
116
122
|
}
|
|
117
123
|
/**
|
|
@@ -132,12 +138,39 @@ function identifierFieldsOf(preferredId, actions) {
|
|
|
132
138
|
/**
|
|
133
139
|
* A field the caller may read: listed in `meta.fields` and not write-only —
|
|
134
140
|
* the one rule for a table's columns and a dictionary's label.
|
|
135
|
-
*
|
|
136
|
-
* @internal Shared with the value help.
|
|
137
141
|
*/
|
|
138
142
|
function isReadable(field) {
|
|
139
143
|
return field !== void 0 && field.writeOnly !== true;
|
|
140
144
|
}
|
|
145
|
+
/**
|
|
146
|
+
* The label a type's rows declare: the own field its `@ui.dict.label` marks
|
|
147
|
+
* (`@ui.dict.label 'keyText'` → that arrangement, default `textKey`), when
|
|
148
|
+
* the caller can read it. The one rule for a dictionary's label
|
|
149
|
+
* (`ResolvedValueHelp.label`) and a table's (`TableDef.label`).
|
|
150
|
+
*/
|
|
151
|
+
function dictLabelOf(meta, type) {
|
|
152
|
+
if (type.type.kind !== "object") return void 0;
|
|
153
|
+
let label;
|
|
154
|
+
for (const [field, prop] of type.type.props) {
|
|
155
|
+
const declared = prop.metadata.get(UI_DICT_LABEL);
|
|
156
|
+
if (declared === void 0 || field === meta.versionColumn) continue;
|
|
157
|
+
label = readableLabel(meta, field, typeof declared === "string" ? declared : void 0);
|
|
158
|
+
}
|
|
159
|
+
return label;
|
|
160
|
+
}
|
|
161
|
+
/**
|
|
162
|
+
* `field` of the served type as a label, when the caller may read it
|
|
163
|
+
* (`isReadable`); the arrangement defaults to `textKey`.
|
|
164
|
+
*
|
|
165
|
+
* @internal Shared with the value help.
|
|
166
|
+
*/
|
|
167
|
+
function readableLabel(meta, field, arrangement) {
|
|
168
|
+
if (!isReadable(meta.fields?.[field])) return void 0;
|
|
169
|
+
return {
|
|
170
|
+
field,
|
|
171
|
+
arrangement: arrangement ?? "textKey"
|
|
172
|
+
};
|
|
173
|
+
}
|
|
141
174
|
/** Sort by (order ?? 0). `toSorted` is stable per spec, so ties preserve declaration order. */
|
|
142
175
|
function byOrder(xs) {
|
|
143
176
|
return xs.toSorted((x, y) => (x.order ?? 0) - (y.order ?? 0));
|
|
@@ -251,4 +284,4 @@ function inferValueKind(prop) {
|
|
|
251
284
|
return [...kinds][0];
|
|
252
285
|
}
|
|
253
286
|
//#endregion
|
|
254
|
-
export { createTableDef, inferValueKind,
|
|
287
|
+
export { createTableDef, dictLabelOf, inferValueKind, readableLabel };
|