@atscript/ui 0.1.206 → 0.1.207
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 +3 -6
- package/dist/form/create-form-def.mjs +1 -4
- 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/index.cjs +18 -3
- package/dist/index.d.cts +8 -5
- package/dist/index.d.mts +8 -5
- package/dist/index.mjs +11 -8
- 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.mjs +3 -1
- 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/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 +7 -1
- package/dist/table/create-table-def.mjs +7 -2
- package/dist/table/types.d.cts +1 -1
- package/dist/table/types.d.mts +1 -1
- 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/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 +49 -8
- package/dist/value-help/options.d.cts +41 -4
- package/dist/value-help/options.d.mts +41 -4
- package/dist/value-help/options.mjs +47 -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 +39 -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 +40 -9
- 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 +315 -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 +310 -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 +21 -19
- package/dist/value-help/value-help-client.d.cts +9 -5
- package/dist/value-help/value-help-client.d.mts +9 -5
- package/dist/value-help/value-help-client.mjs +19 -17
- package/package.json +10 -10
|
@@ -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 };
|
|
@@ -49,14 +49,17 @@ function bindingInfo(node) {
|
|
|
49
49
|
return info;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* Adds a link's `@ui.valueHelp.column` list and
|
|
53
|
-
* (`own`) — its `@ui.valueHelp.fill`
|
|
54
|
-
*
|
|
55
|
-
* stay there; its columns
|
|
52
|
+
* Adds a link's `@ui.valueHelp.column` list and `@ui.valueHelp.label` (since
|
|
53
|
+
* 0.1.207) and — on the prop itself only (`own`) — its `@ui.valueHelp.fill`
|
|
54
|
+
* list to `info` (since 0.1.190). A link reached through a reference names
|
|
55
|
+
* fields of ANOTHER interface, so its fills stay there; its columns and label
|
|
56
|
+
* name the target, so they come along.
|
|
56
57
|
*/
|
|
57
58
|
function withExtras(info, node, own) {
|
|
58
59
|
const columns = node.metadata.get(require_annotation_keys.UI_VALUE_HELP_COLUMN);
|
|
59
60
|
if (columns && columns.length > 0) info.columns = [...columns];
|
|
61
|
+
const label = node.metadata.get(require_annotation_keys.UI_VALUE_HELP_LABEL);
|
|
62
|
+
if (label?.field) info.label = { ...label };
|
|
60
63
|
const fills = own ? node.metadata.get(require_annotation_keys.UI_VALUE_HELP_FILL) : void 0;
|
|
61
64
|
if (fills && fills.length > 0) info.fill = fills.map((f) => ({
|
|
62
65
|
local: f.local,
|
|
@@ -113,6 +116,13 @@ function extractValueHelp(prop) {
|
|
|
113
116
|
node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
|
|
114
117
|
}
|
|
115
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* The identity of a binding's dictionary and committed field (`url` and
|
|
121
|
+
* `targetField`) — what caches and per-binding state are keyed by. Since 0.1.207.
|
|
122
|
+
*/
|
|
123
|
+
function valueHelpKey(info) {
|
|
124
|
+
return `${info.url}\0${info.targetField}`;
|
|
125
|
+
}
|
|
116
126
|
/** Field types that still pick from the value help: the picker, a dropdown or radio group of the dictionary. */
|
|
117
127
|
const PICKER_TYPES = new Set([
|
|
118
128
|
"ref",
|
|
@@ -151,3 +161,4 @@ function isForeignKey(prop) {
|
|
|
151
161
|
exports.extractValueHelp = extractValueHelp;
|
|
152
162
|
exports.isForeignKey = isForeignKey;
|
|
153
163
|
exports.isValueHelpPicker = isValueHelpPicker;
|
|
164
|
+
exports.valueHelpKey = valueHelpKey;
|
|
@@ -33,5 +33,10 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
|
33
33
|
* resolved the chain).
|
|
34
34
|
*/
|
|
35
35
|
declare function extractValueHelp(prop: TAtscriptAnnotatedType): ValueHelpInfo | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The identity of a binding's dictionary and committed field (`url` and
|
|
38
|
+
* `targetField`) — what caches and per-binding state are keyed by. Since 0.1.207.
|
|
39
|
+
*/
|
|
40
|
+
declare function valueHelpKey(info: Pick<ValueHelpInfo, "url" | "targetField">): string;
|
|
36
41
|
//#endregion
|
|
37
|
-
export { extractValueHelp };
|
|
42
|
+
export { extractValueHelp, valueHelpKey };
|
|
@@ -33,5 +33,10 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
|
33
33
|
* resolved the chain).
|
|
34
34
|
*/
|
|
35
35
|
declare function extractValueHelp(prop: TAtscriptAnnotatedType): ValueHelpInfo | undefined;
|
|
36
|
+
/**
|
|
37
|
+
* The identity of a binding's dictionary and committed field (`url` and
|
|
38
|
+
* `targetField`) — what caches and per-binding state are keyed by. Since 0.1.207.
|
|
39
|
+
*/
|
|
40
|
+
declare function valueHelpKey(info: Pick<ValueHelpInfo, "url" | "targetField">): string;
|
|
36
41
|
//#endregion
|
|
37
|
-
export { extractValueHelp };
|
|
42
|
+
export { extractValueHelp, valueHelpKey };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { DB_HTTP_PATH, UI_VALUE_HELP, UI_VALUE_HELP_COLUMN, UI_VALUE_HELP_FILL } from "../shared/annotation-keys.mjs";
|
|
1
|
+
import { DB_HTTP_PATH, UI_VALUE_HELP, UI_VALUE_HELP_COLUMN, UI_VALUE_HELP_FILL, UI_VALUE_HELP_LABEL } from "../shared/annotation-keys.mjs";
|
|
2
2
|
import { valueHelpFilter } from "./filter-tree.mjs";
|
|
3
3
|
//#region src/value-help/extract-ref.ts
|
|
4
4
|
/**
|
|
@@ -49,14 +49,17 @@ function bindingInfo(node) {
|
|
|
49
49
|
return info;
|
|
50
50
|
}
|
|
51
51
|
/**
|
|
52
|
-
* Adds a link's `@ui.valueHelp.column` list and
|
|
53
|
-
* (`own`) — its `@ui.valueHelp.fill`
|
|
54
|
-
*
|
|
55
|
-
* stay there; its columns
|
|
52
|
+
* Adds a link's `@ui.valueHelp.column` list and `@ui.valueHelp.label` (since
|
|
53
|
+
* 0.1.207) and — on the prop itself only (`own`) — its `@ui.valueHelp.fill`
|
|
54
|
+
* list to `info` (since 0.1.190). A link reached through a reference names
|
|
55
|
+
* fields of ANOTHER interface, so its fills stay there; its columns and label
|
|
56
|
+
* name the target, so they come along.
|
|
56
57
|
*/
|
|
57
58
|
function withExtras(info, node, own) {
|
|
58
59
|
const columns = node.metadata.get(UI_VALUE_HELP_COLUMN);
|
|
59
60
|
if (columns && columns.length > 0) info.columns = [...columns];
|
|
61
|
+
const label = node.metadata.get(UI_VALUE_HELP_LABEL);
|
|
62
|
+
if (label?.field) info.label = { ...label };
|
|
60
63
|
const fills = own ? node.metadata.get(UI_VALUE_HELP_FILL) : void 0;
|
|
61
64
|
if (fills && fills.length > 0) info.fill = fills.map((f) => ({
|
|
62
65
|
local: f.local,
|
|
@@ -113,6 +116,13 @@ function extractValueHelp(prop) {
|
|
|
113
116
|
node = (target.type.kind === "object" ? target.type : void 0)?.props.get(ref.field);
|
|
114
117
|
}
|
|
115
118
|
}
|
|
119
|
+
/**
|
|
120
|
+
* The identity of a binding's dictionary and committed field (`url` and
|
|
121
|
+
* `targetField`) — what caches and per-binding state are keyed by. Since 0.1.207.
|
|
122
|
+
*/
|
|
123
|
+
function valueHelpKey(info) {
|
|
124
|
+
return `${info.url}\0${info.targetField}`;
|
|
125
|
+
}
|
|
116
126
|
/** Field types that still pick from the value help: the picker, a dropdown or radio group of the dictionary. */
|
|
117
127
|
const PICKER_TYPES = new Set([
|
|
118
128
|
"ref",
|
|
@@ -148,4 +158,4 @@ function isForeignKey(prop) {
|
|
|
148
158
|
return false;
|
|
149
159
|
}
|
|
150
160
|
//#endregion
|
|
151
|
-
export { extractValueHelp, isForeignKey, isValueHelpPicker };
|
|
161
|
+
export { extractValueHelp, isForeignKey, isValueHelpPicker, valueHelpKey };
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { TFormEntryOptions, ValueHelpInfo } from "./types.mjs";
|
|
2
|
+
import { ValueHelpSource, ValueHelpSourceOptions, valueHelpColumns, valueHelpSource } from "./source.mjs";
|
|
2
3
|
import { ResolvedValueHelp, resetValueHelpCache, resolveValueHelp } from "./resolve.mjs";
|
|
3
4
|
import { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl, valueHelpSelect } from "./value-help-client.mjs";
|
|
4
5
|
import { valueHelpDictPaths } from "./dict-paths.mjs";
|
|
5
6
|
import { DEFAULT_BOOLEAN_LABELS, extractFieldLiteralOptions, extractLiteralOptions, isPureLiteralUnion } from "./extract-literals.mjs";
|
|
6
|
-
import { extractValueHelp } from "./extract-ref.mjs";
|
|
7
|
+
import { extractValueHelp, valueHelpKey } from "./extract-ref.mjs";
|
|
7
8
|
import { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions } from "./resolve-options.mjs";
|
|
8
9
|
import { ValueHelpFillWrite, ValueHelpScope, valueHelpFills, valueHelpScope } from "./scope.mjs";
|
|
9
|
-
import { VALUE_HELP_OPTIONS_CAP, valueHelpOptions } from "./options.mjs";
|
|
10
|
-
import { fetchDistinctValues, isPickerDeclined } from "./distinct-client.mjs";
|
|
10
|
+
import { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText } from "./options.mjs";
|
|
11
|
+
import { fetchDistinctValues, isPickerDeclined } from "./distinct-client.mjs";
|
|
12
|
+
import { ValueHelpTextOptions, loadValueHelpTexts, onValueHelpTexts, valueHelpText } from "./texts.mjs";
|
|
13
|
+
import { DisplayValueOptions, displayValue } from "./display-value.mjs";
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
require("../shared/annotation-keys.cjs");
|
|
2
|
+
const require_field_resolver = require("../shared/field-resolver.cjs");
|
|
3
|
+
const require_extract_literals = require("./extract-literals.cjs");
|
|
4
|
+
const require_value_label = require("../shared/value-label.cjs");
|
|
1
5
|
//#region src/value-help/options.ts
|
|
2
6
|
/**
|
|
3
7
|
* Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
|
|
@@ -7,24 +11,61 @@
|
|
|
7
11
|
*/
|
|
8
12
|
const VALUE_HELP_OPTIONS_CAP = 200;
|
|
9
13
|
/**
|
|
14
|
+
* A dictionary row's text as a picker shows it (since 0.1.207): its label
|
|
15
|
+
* field's (`ResolvedValueHelp.labelField`) and its description, each a
|
|
16
|
+
* non-empty text or `undefined`. The one reader of a row's text — the
|
|
17
|
+
* reference field's list, the dropdown options and the texts of codes.
|
|
18
|
+
*/
|
|
19
|
+
function valueHelpRowText(resolved, row) {
|
|
20
|
+
return {
|
|
21
|
+
label: require_value_label.codeOf(row[resolved.labelField]),
|
|
22
|
+
descr: resolved.descrField ? require_value_label.codeOf(row[resolved.descrField]) : void 0
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
10
26
|
* Dictionary rows as dropdown options (since 0.1.190): the committed
|
|
11
|
-
* `targetField` value as the option's value, the
|
|
12
|
-
* when it has none) and the description after a
|
|
27
|
+
* `targetField` value as the option's value, the row's text
|
|
28
|
+
* (`valueHelpRowText`; the key when it has none) and the description after a
|
|
29
|
+
* dash.
|
|
13
30
|
*/
|
|
14
31
|
function valueHelpOptions(rows, resolved, info) {
|
|
15
32
|
return rows.map((row) => {
|
|
16
33
|
const value = row[info.targetField];
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const descr = resolved.descrField ? row[resolved.descrField] : void 0;
|
|
20
|
-
const text = label === void 0 || label === null || label === "" ? key : String(label);
|
|
34
|
+
const { label, descr } = valueHelpRowText(resolved, row);
|
|
35
|
+
const text = label ?? String(value);
|
|
21
36
|
return {
|
|
22
|
-
key,
|
|
23
|
-
label: descr ? `${text} — ${
|
|
37
|
+
key: String(value),
|
|
38
|
+
label: descr ? `${text} — ${descr}` : text,
|
|
24
39
|
value
|
|
25
40
|
};
|
|
26
41
|
});
|
|
27
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The options of a dropdown that lists its dictionary (`listsDictionary`;
|
|
45
|
+
* since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
|
|
46
|
+
* binding's scope (`ValueHelpSource.search`, in a form with the host values):
|
|
47
|
+
* the rows as options (`valueHelpOptions`), or `undefined` when there are more
|
|
48
|
+
* than the cap — the field then keeps its search picker.
|
|
49
|
+
*/
|
|
50
|
+
function valueHelpDropdown(rows, resolved, info) {
|
|
51
|
+
return rows.length > 200 ? void 0 : valueHelpOptions(rows, resolved, info);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Whether a form field or a column lists its dictionary's values as its
|
|
55
|
+
* options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
|
|
56
|
+
* `select` or `radio`, and with no options of its own — a form field none
|
|
57
|
+
* declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
|
|
58
|
+
* literal union), a column none in `options`.
|
|
59
|
+
*/
|
|
60
|
+
function listsDictionary(holder) {
|
|
61
|
+
if (!holder.valueHelpInfo || holder.type !== "select" && holder.type !== "radio") return false;
|
|
62
|
+
const prop = holder.prop;
|
|
63
|
+
if (!prop) return !holder.options?.length;
|
|
64
|
+
return !require_field_resolver.hasFieldMeta(prop, "ui.form.options") && !require_field_resolver.hasFieldMeta(prop, "ui.form.fn.options") && require_extract_literals.extractFieldLiteralOptions(prop) === void 0;
|
|
65
|
+
}
|
|
28
66
|
//#endregion
|
|
29
67
|
exports.VALUE_HELP_OPTIONS_CAP = VALUE_HELP_OPTIONS_CAP;
|
|
68
|
+
exports.listsDictionary = listsDictionary;
|
|
69
|
+
exports.valueHelpDropdown = valueHelpDropdown;
|
|
30
70
|
exports.valueHelpOptions = valueHelpOptions;
|
|
71
|
+
exports.valueHelpRowText = valueHelpRowText;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { TFormEntryOptions, ValueHelpInfo } from "./types.cjs";
|
|
2
2
|
import { ResolvedValueHelp } from "./resolve.cjs";
|
|
3
|
+
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
3
4
|
|
|
4
5
|
//#region src/value-help/options.d.ts
|
|
6
|
+
type Row = Record<string, unknown>;
|
|
5
7
|
/**
|
|
6
8
|
* Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
|
|
7
9
|
* `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
|
|
@@ -9,11 +11,46 @@ import { ResolvedValueHelp } from "./resolve.cjs";
|
|
|
9
11
|
* keeps its search picker.
|
|
10
12
|
*/
|
|
11
13
|
declare const VALUE_HELP_OPTIONS_CAP = 200;
|
|
14
|
+
/**
|
|
15
|
+
* A dictionary row's text as a picker shows it (since 0.1.207): its label
|
|
16
|
+
* field's (`ResolvedValueHelp.labelField`) and its description, each a
|
|
17
|
+
* non-empty text or `undefined`. The one reader of a row's text — the
|
|
18
|
+
* reference field's list, the dropdown options and the texts of codes.
|
|
19
|
+
*/
|
|
20
|
+
declare function valueHelpRowText(resolved: {
|
|
21
|
+
labelField: string;
|
|
22
|
+
descrField?: string;
|
|
23
|
+
}, row: Row): {
|
|
24
|
+
label?: string;
|
|
25
|
+
descr?: string;
|
|
26
|
+
};
|
|
12
27
|
/**
|
|
13
28
|
* Dictionary rows as dropdown options (since 0.1.190): the committed
|
|
14
|
-
* `targetField` value as the option's value, the
|
|
15
|
-
* when it has none) and the description after a
|
|
29
|
+
* `targetField` value as the option's value, the row's text
|
|
30
|
+
* (`valueHelpRowText`; the key when it has none) and the description after a
|
|
31
|
+
* dash.
|
|
32
|
+
*/
|
|
33
|
+
declare function valueHelpOptions(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
|
|
34
|
+
/**
|
|
35
|
+
* The options of a dropdown that lists its dictionary (`listsDictionary`;
|
|
36
|
+
* since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
|
|
37
|
+
* binding's scope (`ValueHelpSource.search`, in a form with the host values):
|
|
38
|
+
* the rows as options (`valueHelpOptions`), or `undefined` when there are more
|
|
39
|
+
* than the cap — the field then keeps its search picker.
|
|
40
|
+
*/
|
|
41
|
+
declare function valueHelpDropdown(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[] | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Whether a form field or a column lists its dictionary's values as its
|
|
44
|
+
* options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
|
|
45
|
+
* `select` or `radio`, and with no options of its own — a form field none
|
|
46
|
+
* declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
|
|
47
|
+
* literal union), a column none in `options`.
|
|
16
48
|
*/
|
|
17
|
-
declare function
|
|
49
|
+
declare function listsDictionary(holder: {
|
|
50
|
+
valueHelpInfo?: ValueHelpInfo;
|
|
51
|
+
type: string;
|
|
52
|
+
prop?: TAtscriptAnnotatedType;
|
|
53
|
+
options?: readonly unknown[];
|
|
54
|
+
}): boolean;
|
|
18
55
|
//#endregion
|
|
19
|
-
export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
|
|
56
|
+
export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText };
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { TFormEntryOptions, ValueHelpInfo } from "./types.mjs";
|
|
2
2
|
import { ResolvedValueHelp } from "./resolve.mjs";
|
|
3
|
+
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
3
4
|
|
|
4
5
|
//#region src/value-help/options.d.ts
|
|
6
|
+
type Row = Record<string, unknown>;
|
|
5
7
|
/**
|
|
6
8
|
* Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
|
|
7
9
|
* `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
|
|
@@ -9,11 +11,46 @@ import { ResolvedValueHelp } from "./resolve.mjs";
|
|
|
9
11
|
* keeps its search picker.
|
|
10
12
|
*/
|
|
11
13
|
declare const VALUE_HELP_OPTIONS_CAP = 200;
|
|
14
|
+
/**
|
|
15
|
+
* A dictionary row's text as a picker shows it (since 0.1.207): its label
|
|
16
|
+
* field's (`ResolvedValueHelp.labelField`) and its description, each a
|
|
17
|
+
* non-empty text or `undefined`. The one reader of a row's text — the
|
|
18
|
+
* reference field's list, the dropdown options and the texts of codes.
|
|
19
|
+
*/
|
|
20
|
+
declare function valueHelpRowText(resolved: {
|
|
21
|
+
labelField: string;
|
|
22
|
+
descrField?: string;
|
|
23
|
+
}, row: Row): {
|
|
24
|
+
label?: string;
|
|
25
|
+
descr?: string;
|
|
26
|
+
};
|
|
12
27
|
/**
|
|
13
28
|
* Dictionary rows as dropdown options (since 0.1.190): the committed
|
|
14
|
-
* `targetField` value as the option's value, the
|
|
15
|
-
* when it has none) and the description after a
|
|
29
|
+
* `targetField` value as the option's value, the row's text
|
|
30
|
+
* (`valueHelpRowText`; the key when it has none) and the description after a
|
|
31
|
+
* dash.
|
|
32
|
+
*/
|
|
33
|
+
declare function valueHelpOptions(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
|
|
34
|
+
/**
|
|
35
|
+
* The options of a dropdown that lists its dictionary (`listsDictionary`;
|
|
36
|
+
* since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
|
|
37
|
+
* binding's scope (`ValueHelpSource.search`, in a form with the host values):
|
|
38
|
+
* the rows as options (`valueHelpOptions`), or `undefined` when there are more
|
|
39
|
+
* than the cap — the field then keeps its search picker.
|
|
40
|
+
*/
|
|
41
|
+
declare function valueHelpDropdown(rows: Row[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[] | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Whether a form field or a column lists its dictionary's values as its
|
|
44
|
+
* options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
|
|
45
|
+
* `select` or `radio`, and with no options of its own — a form field none
|
|
46
|
+
* declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
|
|
47
|
+
* literal union), a column none in `options`.
|
|
16
48
|
*/
|
|
17
|
-
declare function
|
|
49
|
+
declare function listsDictionary(holder: {
|
|
50
|
+
valueHelpInfo?: ValueHelpInfo;
|
|
51
|
+
type: string;
|
|
52
|
+
prop?: TAtscriptAnnotatedType;
|
|
53
|
+
options?: readonly unknown[];
|
|
54
|
+
}): boolean;
|
|
18
55
|
//#endregion
|
|
19
|
-
export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
|
|
56
|
+
export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText };
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
import "../shared/annotation-keys.mjs";
|
|
2
|
+
import { hasFieldMeta } from "../shared/field-resolver.mjs";
|
|
3
|
+
import { extractFieldLiteralOptions } from "./extract-literals.mjs";
|
|
4
|
+
import { codeOf } from "../shared/value-label.mjs";
|
|
1
5
|
//#region src/value-help/options.ts
|
|
2
6
|
/**
|
|
3
7
|
* Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
|
|
@@ -7,23 +11,57 @@
|
|
|
7
11
|
*/
|
|
8
12
|
const VALUE_HELP_OPTIONS_CAP = 200;
|
|
9
13
|
/**
|
|
14
|
+
* A dictionary row's text as a picker shows it (since 0.1.207): its label
|
|
15
|
+
* field's (`ResolvedValueHelp.labelField`) and its description, each a
|
|
16
|
+
* non-empty text or `undefined`. The one reader of a row's text — the
|
|
17
|
+
* reference field's list, the dropdown options and the texts of codes.
|
|
18
|
+
*/
|
|
19
|
+
function valueHelpRowText(resolved, row) {
|
|
20
|
+
return {
|
|
21
|
+
label: codeOf(row[resolved.labelField]),
|
|
22
|
+
descr: resolved.descrField ? codeOf(row[resolved.descrField]) : void 0
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
10
26
|
* Dictionary rows as dropdown options (since 0.1.190): the committed
|
|
11
|
-
* `targetField` value as the option's value, the
|
|
12
|
-
* when it has none) and the description after a
|
|
27
|
+
* `targetField` value as the option's value, the row's text
|
|
28
|
+
* (`valueHelpRowText`; the key when it has none) and the description after a
|
|
29
|
+
* dash.
|
|
13
30
|
*/
|
|
14
31
|
function valueHelpOptions(rows, resolved, info) {
|
|
15
32
|
return rows.map((row) => {
|
|
16
33
|
const value = row[info.targetField];
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
const descr = resolved.descrField ? row[resolved.descrField] : void 0;
|
|
20
|
-
const text = label === void 0 || label === null || label === "" ? key : String(label);
|
|
34
|
+
const { label, descr } = valueHelpRowText(resolved, row);
|
|
35
|
+
const text = label ?? String(value);
|
|
21
36
|
return {
|
|
22
|
-
key,
|
|
23
|
-
label: descr ? `${text} — ${
|
|
37
|
+
key: String(value),
|
|
38
|
+
label: descr ? `${text} — ${descr}` : text,
|
|
24
39
|
value
|
|
25
40
|
};
|
|
26
41
|
});
|
|
27
42
|
}
|
|
43
|
+
/**
|
|
44
|
+
* The options of a dropdown that lists its dictionary (`listsDictionary`;
|
|
45
|
+
* since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
|
|
46
|
+
* binding's scope (`ValueHelpSource.search`, in a form with the host values):
|
|
47
|
+
* the rows as options (`valueHelpOptions`), or `undefined` when there are more
|
|
48
|
+
* than the cap — the field then keeps its search picker.
|
|
49
|
+
*/
|
|
50
|
+
function valueHelpDropdown(rows, resolved, info) {
|
|
51
|
+
return rows.length > 200 ? void 0 : valueHelpOptions(rows, resolved, info);
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Whether a form field or a column lists its dictionary's values as its
|
|
55
|
+
* options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
|
|
56
|
+
* `select` or `radio`, and with no options of its own — a form field none
|
|
57
|
+
* declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
|
|
58
|
+
* literal union), a column none in `options`.
|
|
59
|
+
*/
|
|
60
|
+
function listsDictionary(holder) {
|
|
61
|
+
if (!holder.valueHelpInfo || holder.type !== "select" && holder.type !== "radio") return false;
|
|
62
|
+
const prop = holder.prop;
|
|
63
|
+
if (!prop) return !holder.options?.length;
|
|
64
|
+
return !hasFieldMeta(prop, "ui.form.options") && !hasFieldMeta(prop, "ui.form.fn.options") && extractFieldLiteralOptions(prop) === void 0;
|
|
65
|
+
}
|
|
28
66
|
//#endregion
|
|
29
|
-
export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
|
|
67
|
+
export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText };
|
|
@@ -13,19 +13,21 @@ function optLabel(opt) {
|
|
|
13
13
|
}
|
|
14
14
|
const labelMaps = /* @__PURE__ */ new WeakMap();
|
|
15
15
|
/**
|
|
16
|
-
* The display label of
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* The display label of the option holding `value` (`@ui.literalLabel`) — of a
|
|
17
|
+
* literal-union (or boolean) column, or of a form field's options (since
|
|
18
|
+
* 0.1.207; a plain string option is its own label). `undefined` when there
|
|
19
|
+
* are no options or none matches. Map-backed per options array, so rendering
|
|
20
|
+
* a table does not scan the options per cell. The one lookup behind the table
|
|
21
|
+
* cell, the filter chips, export, read-only form fields and a custom cell.
|
|
20
22
|
* Since 0.1.148.
|
|
21
23
|
*/
|
|
22
|
-
function optionLabel(
|
|
23
|
-
const options =
|
|
24
|
+
function optionLabel(holder, value) {
|
|
25
|
+
const options = holder.options;
|
|
24
26
|
if (!options?.length) return void 0;
|
|
25
27
|
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return;
|
|
26
28
|
let labels = labelMaps.get(options);
|
|
27
29
|
if (!labels) {
|
|
28
|
-
labels = new Map(options.map((o) => [o
|
|
30
|
+
labels = new Map(options.map((o) => [optKey(o), optLabel(o)]));
|
|
29
31
|
labelMaps.set(options, labels);
|
|
30
32
|
}
|
|
31
33
|
return labels.get(String(value));
|
|
@@ -9,17 +9,16 @@ declare function optKey(opt: TFormEntryOptions): string;
|
|
|
9
9
|
/** Extracts the display label from an option entry. */
|
|
10
10
|
declare function optLabel(opt: TFormEntryOptions): string;
|
|
11
11
|
/**
|
|
12
|
-
* The display label of
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* The display label of the option holding `value` (`@ui.literalLabel`) — of a
|
|
13
|
+
* literal-union (or boolean) column, or of a form field's options (since
|
|
14
|
+
* 0.1.207; a plain string option is its own label). `undefined` when there
|
|
15
|
+
* are no options or none matches. Map-backed per options array, so rendering
|
|
16
|
+
* a table does not scan the options per cell. The one lookup behind the table
|
|
17
|
+
* cell, the filter chips, export, read-only form fields and a custom cell.
|
|
16
18
|
* Since 0.1.148.
|
|
17
19
|
*/
|
|
18
|
-
declare function optionLabel(
|
|
19
|
-
options?:
|
|
20
|
-
key: string;
|
|
21
|
-
label: string;
|
|
22
|
-
}[];
|
|
20
|
+
declare function optionLabel(holder: {
|
|
21
|
+
options?: readonly TFormEntryOptions[];
|
|
23
22
|
}, value: unknown): string | undefined;
|
|
24
23
|
/**
|
|
25
24
|
* Converts raw option annotation value to a normalized array. `t` translates
|
|
@@ -9,17 +9,16 @@ declare function optKey(opt: TFormEntryOptions): string;
|
|
|
9
9
|
/** Extracts the display label from an option entry. */
|
|
10
10
|
declare function optLabel(opt: TFormEntryOptions): string;
|
|
11
11
|
/**
|
|
12
|
-
* The display label of
|
|
13
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
12
|
+
* The display label of the option holding `value` (`@ui.literalLabel`) — of a
|
|
13
|
+
* literal-union (or boolean) column, or of a form field's options (since
|
|
14
|
+
* 0.1.207; a plain string option is its own label). `undefined` when there
|
|
15
|
+
* are no options or none matches. Map-backed per options array, so rendering
|
|
16
|
+
* a table does not scan the options per cell. The one lookup behind the table
|
|
17
|
+
* cell, the filter chips, export, read-only form fields and a custom cell.
|
|
16
18
|
* Since 0.1.148.
|
|
17
19
|
*/
|
|
18
|
-
declare function optionLabel(
|
|
19
|
-
options?:
|
|
20
|
-
key: string;
|
|
21
|
-
label: string;
|
|
22
|
-
}[];
|
|
20
|
+
declare function optionLabel(holder: {
|
|
21
|
+
options?: readonly TFormEntryOptions[];
|
|
23
22
|
}, value: unknown): string | undefined;
|
|
24
23
|
/**
|
|
25
24
|
* Converts raw option annotation value to a normalized array. `t` translates
|
|
@@ -13,19 +13,21 @@ function optLabel(opt) {
|
|
|
13
13
|
}
|
|
14
14
|
const labelMaps = /* @__PURE__ */ new WeakMap();
|
|
15
15
|
/**
|
|
16
|
-
* The display label of
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
16
|
+
* The display label of the option holding `value` (`@ui.literalLabel`) — of a
|
|
17
|
+
* literal-union (or boolean) column, or of a form field's options (since
|
|
18
|
+
* 0.1.207; a plain string option is its own label). `undefined` when there
|
|
19
|
+
* are no options or none matches. Map-backed per options array, so rendering
|
|
20
|
+
* a table does not scan the options per cell. The one lookup behind the table
|
|
21
|
+
* cell, the filter chips, export, read-only form fields and a custom cell.
|
|
20
22
|
* Since 0.1.148.
|
|
21
23
|
*/
|
|
22
|
-
function optionLabel(
|
|
23
|
-
const options =
|
|
24
|
+
function optionLabel(holder, value) {
|
|
25
|
+
const options = holder.options;
|
|
24
26
|
if (!options?.length) return void 0;
|
|
25
27
|
if (typeof value !== "string" && typeof value !== "number" && typeof value !== "boolean") return;
|
|
26
28
|
let labels = labelMaps.get(options);
|
|
27
29
|
if (!labels) {
|
|
28
|
-
labels = new Map(options.map((o) => [o
|
|
30
|
+
labels = new Map(options.map((o) => [optKey(o), optLabel(o)]));
|
|
29
31
|
labelMaps.set(options, labels);
|
|
30
32
|
}
|
|
31
33
|
return labels.get(String(value));
|