@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.
- package/dist/form/create-form-def.cjs +16 -18
- package/dist/form/create-form-def.mjs +15 -17
- 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/path-utils.cjs +10 -0
- package/dist/form/path-utils.d.cts +8 -1
- package/dist/form/path-utils.d.mts +8 -1
- package/dist/form/path-utils.mjs +10 -1
- 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 +42 -6
- package/dist/index.d.cts +20 -12
- package/dist/index.d.mts +20 -12
- package/dist/index.mjs +23 -15
- package/dist/plugin/annotations.cjs +33 -14
- package/dist/plugin/annotations.mjs +34 -15
- package/dist/plugin/value-help-validation.cjs +26 -6
- package/dist/plugin/value-help-validation.mjs +26 -7
- package/dist/shared/annotation-keys.cjs +3 -0
- package/dist/shared/annotation-keys.d.cts +2 -1
- package/dist/shared/annotation-keys.d.mts +2 -1
- package/dist/shared/annotation-keys.mjs +3 -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/meta-cache.cjs +5 -4
- package/dist/shared/meta-cache.d.cts +3 -2
- package/dist/shared/meta-cache.d.mts +3 -2
- package/dist/shared/meta-cache.mjs +5 -4
- 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/shared/value-label.cjs +14 -2
- package/dist/shared/value-label.d.cts +23 -6
- package/dist/shared/value-label.d.mts +23 -6
- package/dist/shared/value-label.mjs +14 -3
- package/dist/table/create-table-def.cjs +53 -13
- package/dist/table/create-table-def.mjs +53 -15
- package/dist/table/types.d.cts +15 -13
- package/dist/table/types.d.mts +15 -13
- package/dist/value-help/client-store.cjs +43 -0
- package/dist/value-help/client-store.d.mts +1 -0
- package/dist/value-help/client-store.mjs +40 -0
- package/dist/value-help/display-value.cjs +30 -0
- package/dist/value-help/display-value.d.cts +45 -0
- package/dist/value-help/display-value.d.mts +45 -0
- package/dist/value-help/display-value.mjs +30 -0
- 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/extract-ref.cjs +15 -4
- package/dist/value-help/extract-ref.d.cts +6 -1
- package/dist/value-help/extract-ref.d.mts +6 -1
- package/dist/value-help/extract-ref.mjs +16 -6
- package/dist/value-help/index.d.mts +6 -3
- package/dist/value-help/options.cjs +70 -8
- package/dist/value-help/options.d.cts +57 -4
- package/dist/value-help/options.d.mts +57 -4
- package/dist/value-help/options.mjs +67 -9
- package/dist/value-help/resolve-options.cjs +9 -7
- package/dist/value-help/resolve-options.d.cts +8 -9
- package/dist/value-help/resolve-options.d.mts +8 -9
- package/dist/value-help/resolve-options.mjs +9 -7
- package/dist/value-help/resolve.cjs +29 -8
- package/dist/value-help/resolve.d.cts +22 -5
- package/dist/value-help/resolve.d.mts +22 -5
- package/dist/value-help/resolve.mjs +29 -8
- package/dist/value-help/scope.cjs +3 -7
- package/dist/value-help/scope.mjs +3 -7
- package/dist/value-help/source.cjs +72 -0
- package/dist/value-help/source.d.cts +55 -0
- package/dist/value-help/source.d.mts +55 -0
- package/dist/value-help/source.mjs +71 -0
- package/dist/value-help/texts.cjs +318 -0
- package/dist/value-help/texts.d.cts +53 -0
- package/dist/value-help/texts.d.mts +53 -0
- package/dist/value-help/texts.mjs +313 -0
- package/dist/value-help/types.d.cts +10 -0
- package/dist/value-help/types.d.mts +10 -0
- package/dist/value-help/value-help-client.cjs +24 -20
- package/dist/value-help/value-help-client.d.cts +10 -5
- package/dist/value-help/value-help-client.d.mts +10 -5
- package/dist/value-help/value-help-client.mjs +22 -18
- package/package.json +10 -10
|
@@ -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
|
/**
|
|
@@ -129,10 +135,42 @@ function identifierFieldsOf(preferredId, actions) {
|
|
|
129
135
|
}
|
|
130
136
|
return out ?? preferredId;
|
|
131
137
|
}
|
|
132
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* A field the caller may read: listed in `meta.fields` and not write-only —
|
|
140
|
+
* the one rule for a table's columns and a dictionary's label.
|
|
141
|
+
*/
|
|
133
142
|
function isReadable(field) {
|
|
134
143
|
return field !== void 0 && field.writeOnly !== true;
|
|
135
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
|
+
}
|
|
136
174
|
/** Sort by (order ?? 0). `toSorted` is stable per spec, so ties preserve declaration order. */
|
|
137
175
|
function byOrder(xs) {
|
|
138
176
|
return xs.toSorted((x, y) => (x.order ?? 0) - (y.order ?? 0));
|
|
@@ -247,4 +285,6 @@ function inferValueKind(prop) {
|
|
|
247
285
|
}
|
|
248
286
|
//#endregion
|
|
249
287
|
exports.createTableDef = createTableDef;
|
|
288
|
+
exports.dictLabelOf = dictLabelOf;
|
|
250
289
|
exports.inferValueKind = inferValueKind;
|
|
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
|
/**
|
|
@@ -129,10 +135,42 @@ function identifierFieldsOf(preferredId, actions) {
|
|
|
129
135
|
}
|
|
130
136
|
return out ?? preferredId;
|
|
131
137
|
}
|
|
132
|
-
/**
|
|
138
|
+
/**
|
|
139
|
+
* A field the caller may read: listed in `meta.fields` and not write-only —
|
|
140
|
+
* the one rule for a table's columns and a dictionary's label.
|
|
141
|
+
*/
|
|
133
142
|
function isReadable(field) {
|
|
134
143
|
return field !== void 0 && field.writeOnly !== true;
|
|
135
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
|
+
}
|
|
136
174
|
/** Sort by (order ?? 0). `toSorted` is stable per spec, so ties preserve declaration order. */
|
|
137
175
|
function byOrder(xs) {
|
|
138
176
|
return xs.toSorted((x, y) => (x.order ?? 0) - (y.order ?? 0));
|
|
@@ -246,4 +284,4 @@ function inferValueKind(prop) {
|
|
|
246
284
|
return [...kinds][0];
|
|
247
285
|
}
|
|
248
286
|
//#endregion
|
|
249
|
-
export { createTableDef, inferValueKind };
|
|
287
|
+
export { createTableDef, dictLabelOf, inferValueKind, readableLabel };
|
package/dist/table/types.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ValueLabel, ValueLabelArrangement } from "../shared/value-label.cjs";
|
|
1
2
|
import { ValueHelpInfo } from "../value-help/types.cjs";
|
|
2
|
-
import {
|
|
3
|
+
import { MeasurementInfo } from "../form/measurement.cjs";
|
|
3
4
|
import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
|
|
4
5
|
import { TCrudPermissions, TDbActionInfo } from "@atscript/db-client";
|
|
5
6
|
|
|
@@ -165,6 +166,13 @@ interface TableDef {
|
|
|
165
166
|
identifierFields?: string[];
|
|
166
167
|
/** Server-managed OCC column name — see `MetaResponse.versionColumn`. */
|
|
167
168
|
versionColumn?: string;
|
|
169
|
+
/**
|
|
170
|
+
* The label of the table's own rows: the field its type's `@ui.dict.label`
|
|
171
|
+
* marks — one the caller can read — with its arrangement (default
|
|
172
|
+
* `textKey`). `undefined` without one. An action dialog names a row by it
|
|
173
|
+
* (`Dune (3f2a…)`). Since 0.1.208.
|
|
174
|
+
*/
|
|
175
|
+
label?: ValueLabel;
|
|
168
176
|
/** Per-op CRUD permissions advertised in `/meta`. Key absent → denied. */
|
|
169
177
|
crud: TCrudPermissions;
|
|
170
178
|
canRemove: boolean;
|
|
@@ -183,8 +191,12 @@ interface TableDef {
|
|
|
183
191
|
* Since 0.1.148.
|
|
184
192
|
*/
|
|
185
193
|
type ColumnValueKind = "string" | "date" | "isoDate" | "number" | "integer" | "decimal" | "long" | "timestamp" | "boolean";
|
|
186
|
-
/**
|
|
187
|
-
|
|
194
|
+
/**
|
|
195
|
+
* A single column definition — built from field metadata + annotations; its
|
|
196
|
+
* currency / unit / precision fields are the `MeasurementInfo` of
|
|
197
|
+
* `extractMeasurement`.
|
|
198
|
+
*/
|
|
199
|
+
interface ColumnDef extends MeasurementInfo {
|
|
188
200
|
/** Field path in dot-notation (e.g. 'address.city'). */
|
|
189
201
|
path: string;
|
|
190
202
|
/** Display label — from @meta.label or humanized path. */
|
|
@@ -275,16 +287,6 @@ interface ColumnDef {
|
|
|
275
287
|
url: string;
|
|
276
288
|
field: string;
|
|
277
289
|
};
|
|
278
|
-
/** Literal currency code from `@db.amount.currency 'EUR'`. */
|
|
279
|
-
currencyCode?: string;
|
|
280
|
-
/** Sibling field path from `@db.amount.currency.ref 'fieldName'`. */
|
|
281
|
-
currencyRefField?: string;
|
|
282
|
-
/** Literal unit-of-measure from `@db.unit 'kg'`. */
|
|
283
|
-
unitCode?: string;
|
|
284
|
-
/** Sibling field path from `@db.unit.ref 'fieldName'`. */
|
|
285
|
-
unitRefField?: string;
|
|
286
|
-
/** Decimal scale (fraction digits) — second arg of `@db.column.precision precision, scale`. */
|
|
287
|
-
precisionScale?: number;
|
|
288
290
|
/**
|
|
289
291
|
* Synthesised, locked-chrome column. When `true`: header-cell column-menu
|
|
290
292
|
* skipped, resize handle skipped, drag-reorder excluded, NOT in the
|
package/dist/table/types.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { ValueLabel, ValueLabelArrangement } from "../shared/value-label.mjs";
|
|
1
2
|
import { ValueHelpInfo } from "../value-help/types.mjs";
|
|
2
|
-
import {
|
|
3
|
+
import { MeasurementInfo } from "../form/measurement.mjs";
|
|
3
4
|
import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
|
|
4
5
|
import { TCrudPermissions, TDbActionInfo } from "@atscript/db-client";
|
|
5
6
|
|
|
@@ -165,6 +166,13 @@ interface TableDef {
|
|
|
165
166
|
identifierFields?: string[];
|
|
166
167
|
/** Server-managed OCC column name — see `MetaResponse.versionColumn`. */
|
|
167
168
|
versionColumn?: string;
|
|
169
|
+
/**
|
|
170
|
+
* The label of the table's own rows: the field its type's `@ui.dict.label`
|
|
171
|
+
* marks — one the caller can read — with its arrangement (default
|
|
172
|
+
* `textKey`). `undefined` without one. An action dialog names a row by it
|
|
173
|
+
* (`Dune (3f2a…)`). Since 0.1.208.
|
|
174
|
+
*/
|
|
175
|
+
label?: ValueLabel;
|
|
168
176
|
/** Per-op CRUD permissions advertised in `/meta`. Key absent → denied. */
|
|
169
177
|
crud: TCrudPermissions;
|
|
170
178
|
canRemove: boolean;
|
|
@@ -183,8 +191,12 @@ interface TableDef {
|
|
|
183
191
|
* Since 0.1.148.
|
|
184
192
|
*/
|
|
185
193
|
type ColumnValueKind = "string" | "date" | "isoDate" | "number" | "integer" | "decimal" | "long" | "timestamp" | "boolean";
|
|
186
|
-
/**
|
|
187
|
-
|
|
194
|
+
/**
|
|
195
|
+
* A single column definition — built from field metadata + annotations; its
|
|
196
|
+
* currency / unit / precision fields are the `MeasurementInfo` of
|
|
197
|
+
* `extractMeasurement`.
|
|
198
|
+
*/
|
|
199
|
+
interface ColumnDef extends MeasurementInfo {
|
|
188
200
|
/** Field path in dot-notation (e.g. 'address.city'). */
|
|
189
201
|
path: string;
|
|
190
202
|
/** Display label — from @meta.label or humanized path. */
|
|
@@ -275,16 +287,6 @@ interface ColumnDef {
|
|
|
275
287
|
url: string;
|
|
276
288
|
field: string;
|
|
277
289
|
};
|
|
278
|
-
/** Literal currency code from `@db.amount.currency 'EUR'`. */
|
|
279
|
-
currencyCode?: string;
|
|
280
|
-
/** Sibling field path from `@db.amount.currency.ref 'fieldName'`. */
|
|
281
|
-
currencyRefField?: string;
|
|
282
|
-
/** Literal unit-of-measure from `@db.unit 'kg'`. */
|
|
283
|
-
unitCode?: string;
|
|
284
|
-
/** Sibling field path from `@db.unit.ref 'fieldName'`. */
|
|
285
|
-
unitRefField?: string;
|
|
286
|
-
/** Decimal scale (fraction digits) — second arg of `@db.column.precision precision, scale`. */
|
|
287
|
-
precisionScale?: number;
|
|
288
290
|
/**
|
|
289
291
|
* Synthesised, locked-chrome column. When `true`: header-cell column-menu
|
|
290
292
|
* skipped, resize handle skipped, drag-reorder excluded, NOT in the
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
//#region src/value-help/client-store.ts
|
|
2
|
+
let stores = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
/** Data drops of every client so far. */
|
|
4
|
+
let drops = 0;
|
|
5
|
+
/**
|
|
6
|
+
* The store of `client`, created on first use — and again after a data drop,
|
|
7
|
+
* keeping the texts of the store it replaces (one back) as `stale`.
|
|
8
|
+
*/
|
|
9
|
+
function clientStore(client) {
|
|
10
|
+
const prev = stores.get(client);
|
|
11
|
+
if (prev?.drop === drops) return prev;
|
|
12
|
+
for (const texts of prev?.texts.values() ?? []) texts.stale = void 0;
|
|
13
|
+
const store = {
|
|
14
|
+
client,
|
|
15
|
+
drop: drops,
|
|
16
|
+
searches: /* @__PURE__ */ new Map(),
|
|
17
|
+
texts: /* @__PURE__ */ new Map(),
|
|
18
|
+
stale: prev?.texts
|
|
19
|
+
};
|
|
20
|
+
stores.set(client, store);
|
|
21
|
+
return store;
|
|
22
|
+
}
|
|
23
|
+
/** The data of `client`, or of every client, changed: its store is replaced on its next use. */
|
|
24
|
+
function staleClientStores(client) {
|
|
25
|
+
if (!client) drops++;
|
|
26
|
+
else {
|
|
27
|
+
const store = stores.get(client);
|
|
28
|
+
if (store) store.drop = -1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Drop every client's store, stale texts too (`resetMetaCache`: another viewer). */
|
|
32
|
+
function dropClientStores() {
|
|
33
|
+
stores = /* @__PURE__ */ new WeakMap();
|
|
34
|
+
}
|
|
35
|
+
/** A monotonic clock (ms) where there is one. */
|
|
36
|
+
function now() {
|
|
37
|
+
return typeof performance === "undefined" ? Date.now() : performance.now();
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
exports.clientStore = clientStore;
|
|
41
|
+
exports.dropClientStores = dropClientStores;
|
|
42
|
+
exports.now = now;
|
|
43
|
+
exports.staleClientStores = staleClientStores;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { ClientLike } from "@atscript/db-client";
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
//#region src/value-help/client-store.ts
|
|
2
|
+
let stores = /* @__PURE__ */ new WeakMap();
|
|
3
|
+
/** Data drops of every client so far. */
|
|
4
|
+
let drops = 0;
|
|
5
|
+
/**
|
|
6
|
+
* The store of `client`, created on first use — and again after a data drop,
|
|
7
|
+
* keeping the texts of the store it replaces (one back) as `stale`.
|
|
8
|
+
*/
|
|
9
|
+
function clientStore(client) {
|
|
10
|
+
const prev = stores.get(client);
|
|
11
|
+
if (prev?.drop === drops) return prev;
|
|
12
|
+
for (const texts of prev?.texts.values() ?? []) texts.stale = void 0;
|
|
13
|
+
const store = {
|
|
14
|
+
client,
|
|
15
|
+
drop: drops,
|
|
16
|
+
searches: /* @__PURE__ */ new Map(),
|
|
17
|
+
texts: /* @__PURE__ */ new Map(),
|
|
18
|
+
stale: prev?.texts
|
|
19
|
+
};
|
|
20
|
+
stores.set(client, store);
|
|
21
|
+
return store;
|
|
22
|
+
}
|
|
23
|
+
/** The data of `client`, or of every client, changed: its store is replaced on its next use. */
|
|
24
|
+
function staleClientStores(client) {
|
|
25
|
+
if (!client) drops++;
|
|
26
|
+
else {
|
|
27
|
+
const store = stores.get(client);
|
|
28
|
+
if (store) store.drop = -1;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Drop every client's store, stale texts too (`resetMetaCache`: another viewer). */
|
|
32
|
+
function dropClientStores() {
|
|
33
|
+
stores = /* @__PURE__ */ new WeakMap();
|
|
34
|
+
}
|
|
35
|
+
/** A monotonic clock (ms) where there is one. */
|
|
36
|
+
function now() {
|
|
37
|
+
return typeof performance === "undefined" ? Date.now() : performance.now();
|
|
38
|
+
}
|
|
39
|
+
//#endregion
|
|
40
|
+
export { clientStore, dropClientStores, now, staleClientStores };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const require_ui_texts = require("../i18n/ui-texts.cjs");
|
|
2
|
+
const require_resolve_options = require("./resolve-options.cjs");
|
|
3
|
+
const require_value_label = require("../shared/value-label.cjs");
|
|
4
|
+
//#region src/value-help/display-value.ts
|
|
5
|
+
/**
|
|
6
|
+
* The words a value shows as (since 0.1.207) — the one rule behind the table
|
|
7
|
+
* cells, the filter chips, the export and the read-only form fields, in this
|
|
8
|
+
* order:
|
|
9
|
+
*
|
|
10
|
+
* 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
|
|
11
|
+
* field's own options);
|
|
12
|
+
* 2. `Yes` / `No` for a boolean;
|
|
13
|
+
* 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
|
|
14
|
+
* `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
|
|
15
|
+
* (`opts.valueText`).
|
|
16
|
+
*
|
|
17
|
+
* `undefined` when none applies: the value shows as itself.
|
|
18
|
+
*/
|
|
19
|
+
function displayValue(holder, value, opts = {}) {
|
|
20
|
+
if (value === null || value === void 0) return void 0;
|
|
21
|
+
const option = require_resolve_options.optionLabel(holder, value);
|
|
22
|
+
if (option !== void 0) return option;
|
|
23
|
+
if (typeof value === "boolean") return (opts.t ?? require_ui_texts.getUiTexts().t)(value ? "UI_YES" : "UI_NO");
|
|
24
|
+
const code = require_value_label.codeOf(value);
|
|
25
|
+
if (code === void 0) return void 0;
|
|
26
|
+
const found = opts.siblingText ?? opts.valueText?.();
|
|
27
|
+
return found && require_value_label.arrangeText(opts.keyText ?? code, found.text, found.arrangement);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
exports.displayValue = displayValue;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ValueLabelArrangement, ValueText } from "../shared/value-label.cjs";
|
|
2
|
+
import { TFormEntryOptions } from "./types.cjs";
|
|
3
|
+
import { UiT } from "../i18n/ui-texts.cjs";
|
|
4
|
+
|
|
5
|
+
//#region src/value-help/display-value.d.ts
|
|
6
|
+
/** What {@link displayValue} reads besides the value. Since 0.1.207. */
|
|
7
|
+
interface DisplayValueOptions {
|
|
8
|
+
/** The code as the caller writes it (a cell's number in its locale). Default: the code itself. */
|
|
9
|
+
keyText?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The text of the value's `@ui.valueLabel` sibling, read from its row, with
|
|
12
|
+
* the annotation's arrangement. Set for a field that declares one: it wins
|
|
13
|
+
* over the dictionary — also when empty, then the code shows alone.
|
|
14
|
+
*/
|
|
15
|
+
siblingText?: {
|
|
16
|
+
text: unknown;
|
|
17
|
+
arrangement: ValueLabelArrangement;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The dictionary text of the code (`valueHelpText`). Called only when
|
|
21
|
+
* nothing before it applies, so a value an option labels sends no lookup.
|
|
22
|
+
*/
|
|
23
|
+
valueText?: () => ValueText | undefined;
|
|
24
|
+
/** Words booleans (`UI_YES` / `UI_NO`). Default: the active UI texts. */
|
|
25
|
+
t?: UiT;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The words a value shows as (since 0.1.207) — the one rule behind the table
|
|
29
|
+
* cells, the filter chips, the export and the read-only form fields, in this
|
|
30
|
+
* order:
|
|
31
|
+
*
|
|
32
|
+
* 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
|
|
33
|
+
* field's own options);
|
|
34
|
+
* 2. `Yes` / `No` for a boolean;
|
|
35
|
+
* 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
|
|
36
|
+
* `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
|
|
37
|
+
* (`opts.valueText`).
|
|
38
|
+
*
|
|
39
|
+
* `undefined` when none applies: the value shows as itself.
|
|
40
|
+
*/
|
|
41
|
+
declare function displayValue(holder: {
|
|
42
|
+
options?: readonly TFormEntryOptions[];
|
|
43
|
+
}, value: unknown, opts?: DisplayValueOptions): string | undefined;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { DisplayValueOptions, displayValue };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { ValueLabelArrangement, ValueText } from "../shared/value-label.mjs";
|
|
2
|
+
import { TFormEntryOptions } from "./types.mjs";
|
|
3
|
+
import { UiT } from "../i18n/ui-texts.mjs";
|
|
4
|
+
|
|
5
|
+
//#region src/value-help/display-value.d.ts
|
|
6
|
+
/** What {@link displayValue} reads besides the value. Since 0.1.207. */
|
|
7
|
+
interface DisplayValueOptions {
|
|
8
|
+
/** The code as the caller writes it (a cell's number in its locale). Default: the code itself. */
|
|
9
|
+
keyText?: string;
|
|
10
|
+
/**
|
|
11
|
+
* The text of the value's `@ui.valueLabel` sibling, read from its row, with
|
|
12
|
+
* the annotation's arrangement. Set for a field that declares one: it wins
|
|
13
|
+
* over the dictionary — also when empty, then the code shows alone.
|
|
14
|
+
*/
|
|
15
|
+
siblingText?: {
|
|
16
|
+
text: unknown;
|
|
17
|
+
arrangement: ValueLabelArrangement;
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* The dictionary text of the code (`valueHelpText`). Called only when
|
|
21
|
+
* nothing before it applies, so a value an option labels sends no lookup.
|
|
22
|
+
*/
|
|
23
|
+
valueText?: () => ValueText | undefined;
|
|
24
|
+
/** Words booleans (`UI_YES` / `UI_NO`). Default: the active UI texts. */
|
|
25
|
+
t?: UiT;
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The words a value shows as (since 0.1.207) — the one rule behind the table
|
|
29
|
+
* cells, the filter chips, the export and the read-only form fields, in this
|
|
30
|
+
* order:
|
|
31
|
+
*
|
|
32
|
+
* 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
|
|
33
|
+
* field's own options);
|
|
34
|
+
* 2. `Yes` / `No` for a boolean;
|
|
35
|
+
* 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
|
|
36
|
+
* `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
|
|
37
|
+
* (`opts.valueText`).
|
|
38
|
+
*
|
|
39
|
+
* `undefined` when none applies: the value shows as itself.
|
|
40
|
+
*/
|
|
41
|
+
declare function displayValue(holder: {
|
|
42
|
+
options?: readonly TFormEntryOptions[];
|
|
43
|
+
}, value: unknown, opts?: DisplayValueOptions): string | undefined;
|
|
44
|
+
//#endregion
|
|
45
|
+
export { DisplayValueOptions, displayValue };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { getUiTexts } from "../i18n/ui-texts.mjs";
|
|
2
|
+
import { optionLabel } from "./resolve-options.mjs";
|
|
3
|
+
import { arrangeText, codeOf } from "../shared/value-label.mjs";
|
|
4
|
+
//#region src/value-help/display-value.ts
|
|
5
|
+
/**
|
|
6
|
+
* The words a value shows as (since 0.1.207) — the one rule behind the table
|
|
7
|
+
* cells, the filter chips, the export and the read-only form fields, in this
|
|
8
|
+
* order:
|
|
9
|
+
*
|
|
10
|
+
* 1. the label of its option (`optionLabel`: `@ui.literalLabel`, a form
|
|
11
|
+
* field's own options);
|
|
12
|
+
* 2. `Yes` / `No` for a boolean;
|
|
13
|
+
* 3. a code (`codeOf`) with its text, arranged (`arrangeText`): its
|
|
14
|
+
* `@ui.valueLabel` sibling's (`opts.siblingText`), else its dictionary's
|
|
15
|
+
* (`opts.valueText`).
|
|
16
|
+
*
|
|
17
|
+
* `undefined` when none applies: the value shows as itself.
|
|
18
|
+
*/
|
|
19
|
+
function displayValue(holder, value, opts = {}) {
|
|
20
|
+
if (value === null || value === void 0) return void 0;
|
|
21
|
+
const option = optionLabel(holder, value);
|
|
22
|
+
if (option !== void 0) return option;
|
|
23
|
+
if (typeof value === "boolean") return (opts.t ?? getUiTexts().t)(value ? "UI_YES" : "UI_NO");
|
|
24
|
+
const code = codeOf(value);
|
|
25
|
+
if (code === void 0) return void 0;
|
|
26
|
+
const found = opts.siblingText ?? opts.valueText?.();
|
|
27
|
+
return found && arrangeText(opts.keyText ?? code, found.text, found.arrangement);
|
|
28
|
+
}
|
|
29
|
+
//#endregion
|
|
30
|
+
export { displayValue };
|