@atscript/ui 0.1.205 → 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 +40 -58
- package/dist/form/create-form-def.d.cts +9 -0
- package/dist/form/create-form-def.d.mts +9 -0
- package/dist/form/create-form-def.mjs +39 -57
- package/dist/form/db-column.cjs +37 -0
- package/dist/form/db-column.mjs +35 -0
- package/dist/form/path-utils.cjs +20 -5
- package/dist/form/path-utils.d.cts +8 -1
- package/dist/form/path-utils.d.mts +8 -1
- package/dist/form/path-utils.mjs +20 -6
- package/dist/form/types.d.cts +1 -0
- package/dist/form/types.d.mts +1 -0
- 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
|
@@ -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));
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
const require_annotation_keys = require("../shared/annotation-keys.cjs");
|
|
2
|
+
const require_create_table_def = require("../table/create-table-def.cjs");
|
|
2
3
|
const require_meta_cache = require("../shared/meta-cache.cjs");
|
|
3
4
|
//#region src/value-help/resolve.ts
|
|
5
|
+
/** Per meta-cache entry: the dictionary resolved for each binding's label. */
|
|
6
|
+
const byBinding = /* @__PURE__ */ new WeakMap();
|
|
4
7
|
/**
|
|
5
8
|
* Lazily fetch and extract value-help metadata for the given URL.
|
|
6
9
|
*
|
|
@@ -14,13 +17,40 @@ const require_meta_cache = require("../shared/meta-cache.cjs");
|
|
|
14
17
|
* by default. `options.clientFactory` — the factory the host (a form's or a
|
|
15
18
|
* table's `clientFactory`) builds its clients with: it seeds the client when
|
|
16
19
|
* this call creates the entry for the URL and locale (default: the app-wide
|
|
17
|
-
* one). Since 0.1.168.
|
|
20
|
+
* one). Since 0.1.168. `options.info` — the binding resolved for: its
|
|
21
|
+
* `@ui.valueHelp.label` becomes the `label` and the `labelField`, resolved
|
|
22
|
+
* once per entry and label (since 0.1.207).
|
|
18
23
|
*/
|
|
19
24
|
function resolveValueHelp(url, options) {
|
|
20
25
|
const entry = require_meta_cache.getMetaEntry(url, options?.clientFactory, { texts: options?.texts });
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return entry.resolved;
|
|
26
|
+
entry.resolved ??= Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
|
|
27
|
+
const own = options?.info?.label;
|
|
28
|
+
if (!own) return entry.resolved;
|
|
29
|
+
let bindings = byBinding.get(entry);
|
|
30
|
+
if (!bindings) byBinding.set(entry, bindings = /* @__PURE__ */ new Map());
|
|
31
|
+
const id = `${own.field}\0${own.arrangement ?? ""}`;
|
|
32
|
+
let resolved = bindings.get(id);
|
|
33
|
+
if (!resolved) {
|
|
34
|
+
resolved = Promise.all([entry.meta, entry.resolved]).then(([meta, base]) => {
|
|
35
|
+
if (!base.targetType.type.props?.has(own.field)) return base;
|
|
36
|
+
const label = readableLabel(meta, own.field, own.arrangement ?? base.label?.arrangement);
|
|
37
|
+
return label ? {
|
|
38
|
+
...base,
|
|
39
|
+
label,
|
|
40
|
+
labelField: label.field
|
|
41
|
+
} : base;
|
|
42
|
+
});
|
|
43
|
+
bindings.set(id, resolved);
|
|
44
|
+
}
|
|
45
|
+
return resolved;
|
|
46
|
+
}
|
|
47
|
+
/** `field` of the served type as a label, when the caller may read it (`isReadable`). */
|
|
48
|
+
function readableLabel(meta, field, arrangement) {
|
|
49
|
+
if (!require_create_table_def.isReadable(meta.fields?.[field])) return void 0;
|
|
50
|
+
return {
|
|
51
|
+
field,
|
|
52
|
+
arrangement: arrangement ?? "textKey"
|
|
53
|
+
};
|
|
24
54
|
}
|
|
25
55
|
/** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
|
|
26
56
|
function resetValueHelpCache() {
|
|
@@ -30,7 +60,7 @@ function buildResolved(url, meta, targetType) {
|
|
|
30
60
|
const objectType = targetType.type.kind === "object" ? targetType.type : void 0;
|
|
31
61
|
const versionColumn = meta.versionColumn;
|
|
32
62
|
const primaryKeys = [];
|
|
33
|
-
let
|
|
63
|
+
let label;
|
|
34
64
|
let descrField;
|
|
35
65
|
const attrFields = [];
|
|
36
66
|
let firstStringField;
|
|
@@ -38,13 +68,13 @@ function buildResolved(url, meta, targetType) {
|
|
|
38
68
|
if (name === versionColumn) continue;
|
|
39
69
|
const isPK = fieldProp.metadata.has(require_annotation_keys.META_ID);
|
|
40
70
|
if (isPK) primaryKeys.push(name);
|
|
41
|
-
|
|
71
|
+
const dictLabel = fieldProp.metadata.get(require_annotation_keys.UI_DICT_LABEL);
|
|
72
|
+
if (dictLabel !== void 0) label = readableLabel(meta, name, typeof dictLabel === "string" ? dictLabel : void 0);
|
|
42
73
|
if (fieldProp.metadata.has("ui.dict.descr")) descrField = name;
|
|
43
74
|
if (fieldProp.metadata.has("ui.dict.attr")) attrFields.push(name);
|
|
44
75
|
if (!firstStringField && !isPK && fieldProp.type.kind === "" && fieldProp.type.designType === "string") firstStringField = name;
|
|
45
76
|
}
|
|
46
|
-
|
|
47
|
-
if (!labelField) labelField = primaryKeys[0] ?? "id";
|
|
77
|
+
const labelField = label?.field ?? firstStringField ?? primaryKeys[0] ?? "id";
|
|
48
78
|
const filterableFields = [];
|
|
49
79
|
const sortableFields = [];
|
|
50
80
|
if (meta.fields) for (const [name, fm] of Object.entries(meta.fields)) {
|
|
@@ -55,6 +85,7 @@ function buildResolved(url, meta, targetType) {
|
|
|
55
85
|
return {
|
|
56
86
|
url,
|
|
57
87
|
primaryKeys,
|
|
88
|
+
...label && { label },
|
|
58
89
|
labelField,
|
|
59
90
|
descrField,
|
|
60
91
|
attrFields,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ValueLabel } from "../shared/value-label.cjs";
|
|
2
|
+
import { ValueHelpInfo } from "./types.cjs";
|
|
3
|
+
import { ValueHelpSourceOptions } from "./source.cjs";
|
|
3
4
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
4
5
|
|
|
5
6
|
//#region src/value-help/resolve.d.ts
|
|
@@ -10,6 +11,20 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
|
10
11
|
interface ResolvedValueHelp {
|
|
11
12
|
url: string;
|
|
12
13
|
primaryKeys: string[];
|
|
14
|
+
/**
|
|
15
|
+
* The declared label of the codes bound to this dictionary: the binding's
|
|
16
|
+
* `@ui.valueHelp.label` (when resolved with its `info`), else the
|
|
17
|
+
* dictionary's `@ui.dict.label` — with its arrangement. A binding's label
|
|
18
|
+
* the caller cannot read (not in the served type, not listed in `/meta`
|
|
19
|
+
* `fields`, or write-only) counts as absent: the dictionary's applies.
|
|
20
|
+
* `undefined` when neither is declared and readable. Codes show its text
|
|
21
|
+
* only when it is set (`valueHelpText`). Since 0.1.207.
|
|
22
|
+
*/
|
|
23
|
+
label?: ValueLabel;
|
|
24
|
+
/**
|
|
25
|
+
* The field a picker shows as each row's text: `label.field`, else the
|
|
26
|
+
* first string field that is not a key, else the key.
|
|
27
|
+
*/
|
|
13
28
|
labelField: string;
|
|
14
29
|
descrField: string | undefined;
|
|
15
30
|
attrFields: string[];
|
|
@@ -31,10 +46,12 @@ interface ResolvedValueHelp {
|
|
|
31
46
|
* by default. `options.clientFactory` — the factory the host (a form's or a
|
|
32
47
|
* table's `clientFactory`) builds its clients with: it seeds the client when
|
|
33
48
|
* this call creates the entry for the URL and locale (default: the app-wide
|
|
34
|
-
* one). Since 0.1.168.
|
|
49
|
+
* one). Since 0.1.168. `options.info` — the binding resolved for: its
|
|
50
|
+
* `@ui.valueHelp.label` becomes the `label` and the `labelField`, resolved
|
|
51
|
+
* once per entry and label (since 0.1.207).
|
|
35
52
|
*/
|
|
36
|
-
declare function resolveValueHelp(url: string, options?:
|
|
37
|
-
|
|
53
|
+
declare function resolveValueHelp(url: string, options?: ValueHelpSourceOptions & {
|
|
54
|
+
info?: Pick<ValueHelpInfo, "label">;
|
|
38
55
|
}): Promise<ResolvedValueHelp>;
|
|
39
56
|
/** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
|
|
40
57
|
declare function resetValueHelpCache(): void;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { ValueLabel } from "../shared/value-label.mjs";
|
|
2
|
+
import { ValueHelpInfo } from "./types.mjs";
|
|
3
|
+
import { ValueHelpSourceOptions } from "./source.mjs";
|
|
3
4
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
4
5
|
|
|
5
6
|
//#region src/value-help/resolve.d.ts
|
|
@@ -10,6 +11,20 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
|
10
11
|
interface ResolvedValueHelp {
|
|
11
12
|
url: string;
|
|
12
13
|
primaryKeys: string[];
|
|
14
|
+
/**
|
|
15
|
+
* The declared label of the codes bound to this dictionary: the binding's
|
|
16
|
+
* `@ui.valueHelp.label` (when resolved with its `info`), else the
|
|
17
|
+
* dictionary's `@ui.dict.label` — with its arrangement. A binding's label
|
|
18
|
+
* the caller cannot read (not in the served type, not listed in `/meta`
|
|
19
|
+
* `fields`, or write-only) counts as absent: the dictionary's applies.
|
|
20
|
+
* `undefined` when neither is declared and readable. Codes show its text
|
|
21
|
+
* only when it is set (`valueHelpText`). Since 0.1.207.
|
|
22
|
+
*/
|
|
23
|
+
label?: ValueLabel;
|
|
24
|
+
/**
|
|
25
|
+
* The field a picker shows as each row's text: `label.field`, else the
|
|
26
|
+
* first string field that is not a key, else the key.
|
|
27
|
+
*/
|
|
13
28
|
labelField: string;
|
|
14
29
|
descrField: string | undefined;
|
|
15
30
|
attrFields: string[];
|
|
@@ -31,10 +46,12 @@ interface ResolvedValueHelp {
|
|
|
31
46
|
* by default. `options.clientFactory` — the factory the host (a form's or a
|
|
32
47
|
* table's `clientFactory`) builds its clients with: it seeds the client when
|
|
33
48
|
* this call creates the entry for the URL and locale (default: the app-wide
|
|
34
|
-
* one). Since 0.1.168.
|
|
49
|
+
* one). Since 0.1.168. `options.info` — the binding resolved for: its
|
|
50
|
+
* `@ui.valueHelp.label` becomes the `label` and the `labelField`, resolved
|
|
51
|
+
* once per entry and label (since 0.1.207).
|
|
35
52
|
*/
|
|
36
|
-
declare function resolveValueHelp(url: string, options?:
|
|
37
|
-
|
|
53
|
+
declare function resolveValueHelp(url: string, options?: ValueHelpSourceOptions & {
|
|
54
|
+
info?: Pick<ValueHelpInfo, "label">;
|
|
38
55
|
}): Promise<ResolvedValueHelp>;
|
|
39
56
|
/** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
|
|
40
57
|
declare function resetValueHelpCache(): void;
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import { META_ID } from "../shared/annotation-keys.mjs";
|
|
1
|
+
import { META_ID, UI_DICT_LABEL } from "../shared/annotation-keys.mjs";
|
|
2
|
+
import { isReadable } from "../table/create-table-def.mjs";
|
|
2
3
|
import { getMetaEntry, resetMetaCache } from "../shared/meta-cache.mjs";
|
|
3
4
|
//#region src/value-help/resolve.ts
|
|
5
|
+
/** Per meta-cache entry: the dictionary resolved for each binding's label. */
|
|
6
|
+
const byBinding = /* @__PURE__ */ new WeakMap();
|
|
4
7
|
/**
|
|
5
8
|
* Lazily fetch and extract value-help metadata for the given URL.
|
|
6
9
|
*
|
|
@@ -14,13 +17,40 @@ import { getMetaEntry, resetMetaCache } from "../shared/meta-cache.mjs";
|
|
|
14
17
|
* by default. `options.clientFactory` — the factory the host (a form's or a
|
|
15
18
|
* table's `clientFactory`) builds its clients with: it seeds the client when
|
|
16
19
|
* this call creates the entry for the URL and locale (default: the app-wide
|
|
17
|
-
* one). Since 0.1.168.
|
|
20
|
+
* one). Since 0.1.168. `options.info` — the binding resolved for: its
|
|
21
|
+
* `@ui.valueHelp.label` becomes the `label` and the `labelField`, resolved
|
|
22
|
+
* once per entry and label (since 0.1.207).
|
|
18
23
|
*/
|
|
19
24
|
function resolveValueHelp(url, options) {
|
|
20
25
|
const entry = getMetaEntry(url, options?.clientFactory, { texts: options?.texts });
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
return entry.resolved;
|
|
26
|
+
entry.resolved ??= Promise.all([entry.meta, entry.type]).then(([meta, type]) => buildResolved(url, meta, type));
|
|
27
|
+
const own = options?.info?.label;
|
|
28
|
+
if (!own) return entry.resolved;
|
|
29
|
+
let bindings = byBinding.get(entry);
|
|
30
|
+
if (!bindings) byBinding.set(entry, bindings = /* @__PURE__ */ new Map());
|
|
31
|
+
const id = `${own.field}\0${own.arrangement ?? ""}`;
|
|
32
|
+
let resolved = bindings.get(id);
|
|
33
|
+
if (!resolved) {
|
|
34
|
+
resolved = Promise.all([entry.meta, entry.resolved]).then(([meta, base]) => {
|
|
35
|
+
if (!base.targetType.type.props?.has(own.field)) return base;
|
|
36
|
+
const label = readableLabel(meta, own.field, own.arrangement ?? base.label?.arrangement);
|
|
37
|
+
return label ? {
|
|
38
|
+
...base,
|
|
39
|
+
label,
|
|
40
|
+
labelField: label.field
|
|
41
|
+
} : base;
|
|
42
|
+
});
|
|
43
|
+
bindings.set(id, resolved);
|
|
44
|
+
}
|
|
45
|
+
return resolved;
|
|
46
|
+
}
|
|
47
|
+
/** `field` of the served type as a label, when the caller may read it (`isReadable`). */
|
|
48
|
+
function readableLabel(meta, field, arrangement) {
|
|
49
|
+
if (!isReadable(meta.fields?.[field])) return void 0;
|
|
50
|
+
return {
|
|
51
|
+
field,
|
|
52
|
+
arrangement: arrangement ?? "textKey"
|
|
53
|
+
};
|
|
24
54
|
}
|
|
25
55
|
/** Thin alias over `resetMetaCache` — retained so existing test code keeps working. */
|
|
26
56
|
function resetValueHelpCache() {
|
|
@@ -30,7 +60,7 @@ function buildResolved(url, meta, targetType) {
|
|
|
30
60
|
const objectType = targetType.type.kind === "object" ? targetType.type : void 0;
|
|
31
61
|
const versionColumn = meta.versionColumn;
|
|
32
62
|
const primaryKeys = [];
|
|
33
|
-
let
|
|
63
|
+
let label;
|
|
34
64
|
let descrField;
|
|
35
65
|
const attrFields = [];
|
|
36
66
|
let firstStringField;
|
|
@@ -38,13 +68,13 @@ function buildResolved(url, meta, targetType) {
|
|
|
38
68
|
if (name === versionColumn) continue;
|
|
39
69
|
const isPK = fieldProp.metadata.has(META_ID);
|
|
40
70
|
if (isPK) primaryKeys.push(name);
|
|
41
|
-
|
|
71
|
+
const dictLabel = fieldProp.metadata.get(UI_DICT_LABEL);
|
|
72
|
+
if (dictLabel !== void 0) label = readableLabel(meta, name, typeof dictLabel === "string" ? dictLabel : void 0);
|
|
42
73
|
if (fieldProp.metadata.has("ui.dict.descr")) descrField = name;
|
|
43
74
|
if (fieldProp.metadata.has("ui.dict.attr")) attrFields.push(name);
|
|
44
75
|
if (!firstStringField && !isPK && fieldProp.type.kind === "" && fieldProp.type.designType === "string") firstStringField = name;
|
|
45
76
|
}
|
|
46
|
-
|
|
47
|
-
if (!labelField) labelField = primaryKeys[0] ?? "id";
|
|
77
|
+
const labelField = label?.field ?? firstStringField ?? primaryKeys[0] ?? "id";
|
|
48
78
|
const filterableFields = [];
|
|
49
79
|
const sortableFields = [];
|
|
50
80
|
if (meta.fields) for (const [name, fm] of Object.entries(meta.fields)) {
|
|
@@ -55,6 +85,7 @@ function buildResolved(url, meta, targetType) {
|
|
|
55
85
|
return {
|
|
56
86
|
url,
|
|
57
87
|
primaryKeys,
|
|
88
|
+
...label && { label },
|
|
58
89
|
labelField,
|
|
59
90
|
descrField,
|
|
60
91
|
attrFields,
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const require_dict_paths = require("./dict-paths.cjs");
|
|
2
|
+
const require_client_store = require("./client-store.cjs");
|
|
3
|
+
const require_meta_cache = require("../shared/meta-cache.cjs");
|
|
4
|
+
const require_resolve = require("./resolve.cjs");
|
|
5
|
+
const require_texts = require("./texts.cjs");
|
|
6
|
+
const require_value_help_client = require("./value-help-client.cjs");
|
|
7
|
+
//#region src/value-help/source.ts
|
|
8
|
+
/** Per meta-cache entry: the source of each binding object. */
|
|
9
|
+
const sources = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
/**
|
|
11
|
+
* The dictionary of the binding `info` (since 0.1.207): the meta-cache entry
|
|
12
|
+
* of its URL in the UI locale of `options.texts` (one `/meta` per session), a
|
|
13
|
+
* client over it, and the dictionary resolved for the binding. Call it in the
|
|
14
|
+
* browser only: a server render reads no dictionary.
|
|
15
|
+
*/
|
|
16
|
+
function valueHelpSource(info, options) {
|
|
17
|
+
const entry = require_meta_cache.getMetaEntry(info.url, options?.clientFactory, { texts: options?.texts });
|
|
18
|
+
let byInfo = sources.get(entry);
|
|
19
|
+
if (!byInfo) sources.set(entry, byInfo = /* @__PURE__ */ new WeakMap());
|
|
20
|
+
let source = byInfo.get(info);
|
|
21
|
+
if (!source) {
|
|
22
|
+
const client = new require_value_help_client.ValueHelpClient(entry.client);
|
|
23
|
+
/** Known once resolved: a search then goes out at once. */
|
|
24
|
+
let resolved;
|
|
25
|
+
const resolve = () => require_resolve.resolveValueHelp(info.url, {
|
|
26
|
+
...options,
|
|
27
|
+
info
|
|
28
|
+
}).then((r) => resolved = r);
|
|
29
|
+
source = {
|
|
30
|
+
entry,
|
|
31
|
+
resolve,
|
|
32
|
+
search: (opts) => {
|
|
33
|
+
const store = require_client_store.clientStore(entry.client);
|
|
34
|
+
const read = (r) => client.search(r, {
|
|
35
|
+
...opts,
|
|
36
|
+
info
|
|
37
|
+
}).then((result) => {
|
|
38
|
+
require_texts.feedValueHelpTexts(store, info, r, result.items);
|
|
39
|
+
return result;
|
|
40
|
+
});
|
|
41
|
+
return resolved ? read(resolved) : resolve().then(read);
|
|
42
|
+
},
|
|
43
|
+
pages: async (query, page, size) => {
|
|
44
|
+
const store = require_client_store.clientStore(entry.client);
|
|
45
|
+
const result = await entry.client.pages(query, page, size);
|
|
46
|
+
resolve().then((r) => require_texts.feedValueHelpTexts(store, info, r, result.data), () => {});
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
byInfo.set(info, source);
|
|
51
|
+
}
|
|
52
|
+
return source;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The fields a picker table lists, of the `available` ones, in their order
|
|
56
|
+
* (since 0.1.207) — the one rule of the table's filter dropdown, its dialog and
|
|
57
|
+
* the form's picker dialog: the binding's `@ui.valueHelp.column` fields, in
|
|
58
|
+
* the order it names them; else the dictionary view (`valueHelpDictPaths`)
|
|
59
|
+
* minus the fields the binding's scope pins with `=` (constant in the picker).
|
|
60
|
+
*/
|
|
61
|
+
function valueHelpColumns(resolved, info, available) {
|
|
62
|
+
if (info.columns) {
|
|
63
|
+
const byPath = new Map(available.map((c) => [c.path, c]));
|
|
64
|
+
return info.columns.flatMap((path) => byPath.get(path) ?? []);
|
|
65
|
+
}
|
|
66
|
+
const paths = require_dict_paths.valueHelpDictPaths(resolved);
|
|
67
|
+
const pinned = new Set(info.pinned);
|
|
68
|
+
return available.filter((c) => paths.has(c.path) && !pinned.has(c.path));
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
exports.valueHelpColumns = valueHelpColumns;
|
|
72
|
+
exports.valueHelpSource = valueHelpSource;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ValueHelpInfo } from "./types.cjs";
|
|
2
|
+
import { ClientFactory } from "../client-factory.cjs";
|
|
3
|
+
import { MetaCacheEntry, MetaEntryOptions } from "../shared/meta-cache.cjs";
|
|
4
|
+
import { ResolvedValueHelp } from "./resolve.cjs";
|
|
5
|
+
import { ValueHelpResult, ValueHelpSearchOptions } from "./value-help-client.cjs";
|
|
6
|
+
import { PageResult, Uniquery } from "@atscript/db-client";
|
|
7
|
+
|
|
8
|
+
//#region src/value-help/source.d.ts
|
|
9
|
+
type Row = Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Where a value help reads its dictionary (since 0.1.207): the app's UI texts
|
|
12
|
+
* (their locale picks the `/meta` entry) and the host's client factory (a
|
|
13
|
+
* form's or a table's `clientFactory`; default: the app-wide one).
|
|
14
|
+
*/
|
|
15
|
+
type ValueHelpSourceOptions = Pick<MetaEntryOptions, "texts"> & {
|
|
16
|
+
clientFactory?: ClientFactory;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A binding's dictionary (since 0.1.207) — the one entry point of every
|
|
20
|
+
* reader: the pickers (form and table), the dropdown options and the texts of
|
|
21
|
+
* codes. Rows read through it (`search`, `pages`) fill the texts of the
|
|
22
|
+
* dictionary's codes (`valueHelpText`).
|
|
23
|
+
*/
|
|
24
|
+
interface ValueHelpSource {
|
|
25
|
+
/** The dictionary's meta-cache entry: hold it while mounted (`retainMetaEntry`). */
|
|
26
|
+
readonly entry: MetaCacheEntry;
|
|
27
|
+
/**
|
|
28
|
+
* The dictionary resolved for the binding (`resolveValueHelp` with its
|
|
29
|
+
* `info`), once per entry and label. Rejects when its `/meta` fails.
|
|
30
|
+
*/
|
|
31
|
+
readonly resolve: () => Promise<ResolvedValueHelp>;
|
|
32
|
+
/** A value-help search of the dictionary for the binding (`ValueHelpClient.search`). */
|
|
33
|
+
readonly search: (opts?: Omit<ValueHelpSearchOptions, "info">) => Promise<ValueHelpResult>;
|
|
34
|
+
/** One page of the dictionary, for a picker table (`useTable`'s `queryFn`). */
|
|
35
|
+
readonly pages: (query: Uniquery, page: number, size: number) => Promise<PageResult<Row>>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The dictionary of the binding `info` (since 0.1.207): the meta-cache entry
|
|
39
|
+
* of its URL in the UI locale of `options.texts` (one `/meta` per session), a
|
|
40
|
+
* client over it, and the dictionary resolved for the binding. Call it in the
|
|
41
|
+
* browser only: a server render reads no dictionary.
|
|
42
|
+
*/
|
|
43
|
+
declare function valueHelpSource(info: ValueHelpInfo, options?: ValueHelpSourceOptions): ValueHelpSource;
|
|
44
|
+
/**
|
|
45
|
+
* The fields a picker table lists, of the `available` ones, in their order
|
|
46
|
+
* (since 0.1.207) — the one rule of the table's filter dropdown, its dialog and
|
|
47
|
+
* the form's picker dialog: the binding's `@ui.valueHelp.column` fields, in
|
|
48
|
+
* the order it names them; else the dictionary view (`valueHelpDictPaths`)
|
|
49
|
+
* minus the fields the binding's scope pins with `=` (constant in the picker).
|
|
50
|
+
*/
|
|
51
|
+
declare function valueHelpColumns<T extends {
|
|
52
|
+
path: string;
|
|
53
|
+
}>(resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "columns" | "pinned">, available: readonly T[]): T[];
|
|
54
|
+
//#endregion
|
|
55
|
+
export { ValueHelpSource, ValueHelpSourceOptions, valueHelpColumns, valueHelpSource };
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { ValueHelpInfo } from "./types.mjs";
|
|
2
|
+
import { ClientFactory } from "../client-factory.mjs";
|
|
3
|
+
import { MetaCacheEntry, MetaEntryOptions } from "../shared/meta-cache.mjs";
|
|
4
|
+
import { ResolvedValueHelp } from "./resolve.mjs";
|
|
5
|
+
import { ValueHelpResult, ValueHelpSearchOptions } from "./value-help-client.mjs";
|
|
6
|
+
import { PageResult, Uniquery } from "@atscript/db-client";
|
|
7
|
+
|
|
8
|
+
//#region src/value-help/source.d.ts
|
|
9
|
+
type Row = Record<string, unknown>;
|
|
10
|
+
/**
|
|
11
|
+
* Where a value help reads its dictionary (since 0.1.207): the app's UI texts
|
|
12
|
+
* (their locale picks the `/meta` entry) and the host's client factory (a
|
|
13
|
+
* form's or a table's `clientFactory`; default: the app-wide one).
|
|
14
|
+
*/
|
|
15
|
+
type ValueHelpSourceOptions = Pick<MetaEntryOptions, "texts"> & {
|
|
16
|
+
clientFactory?: ClientFactory;
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* A binding's dictionary (since 0.1.207) — the one entry point of every
|
|
20
|
+
* reader: the pickers (form and table), the dropdown options and the texts of
|
|
21
|
+
* codes. Rows read through it (`search`, `pages`) fill the texts of the
|
|
22
|
+
* dictionary's codes (`valueHelpText`).
|
|
23
|
+
*/
|
|
24
|
+
interface ValueHelpSource {
|
|
25
|
+
/** The dictionary's meta-cache entry: hold it while mounted (`retainMetaEntry`). */
|
|
26
|
+
readonly entry: MetaCacheEntry;
|
|
27
|
+
/**
|
|
28
|
+
* The dictionary resolved for the binding (`resolveValueHelp` with its
|
|
29
|
+
* `info`), once per entry and label. Rejects when its `/meta` fails.
|
|
30
|
+
*/
|
|
31
|
+
readonly resolve: () => Promise<ResolvedValueHelp>;
|
|
32
|
+
/** A value-help search of the dictionary for the binding (`ValueHelpClient.search`). */
|
|
33
|
+
readonly search: (opts?: Omit<ValueHelpSearchOptions, "info">) => Promise<ValueHelpResult>;
|
|
34
|
+
/** One page of the dictionary, for a picker table (`useTable`'s `queryFn`). */
|
|
35
|
+
readonly pages: (query: Uniquery, page: number, size: number) => Promise<PageResult<Row>>;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* The dictionary of the binding `info` (since 0.1.207): the meta-cache entry
|
|
39
|
+
* of its URL in the UI locale of `options.texts` (one `/meta` per session), a
|
|
40
|
+
* client over it, and the dictionary resolved for the binding. Call it in the
|
|
41
|
+
* browser only: a server render reads no dictionary.
|
|
42
|
+
*/
|
|
43
|
+
declare function valueHelpSource(info: ValueHelpInfo, options?: ValueHelpSourceOptions): ValueHelpSource;
|
|
44
|
+
/**
|
|
45
|
+
* The fields a picker table lists, of the `available` ones, in their order
|
|
46
|
+
* (since 0.1.207) — the one rule of the table's filter dropdown, its dialog and
|
|
47
|
+
* the form's picker dialog: the binding's `@ui.valueHelp.column` fields, in
|
|
48
|
+
* the order it names them; else the dictionary view (`valueHelpDictPaths`)
|
|
49
|
+
* minus the fields the binding's scope pins with `=` (constant in the picker).
|
|
50
|
+
*/
|
|
51
|
+
declare function valueHelpColumns<T extends {
|
|
52
|
+
path: string;
|
|
53
|
+
}>(resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "columns" | "pinned">, available: readonly T[]): T[];
|
|
54
|
+
//#endregion
|
|
55
|
+
export { ValueHelpSource, ValueHelpSourceOptions, valueHelpColumns, valueHelpSource };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { valueHelpDictPaths } from "./dict-paths.mjs";
|
|
2
|
+
import { clientStore } from "./client-store.mjs";
|
|
3
|
+
import { getMetaEntry } from "../shared/meta-cache.mjs";
|
|
4
|
+
import { resolveValueHelp } from "./resolve.mjs";
|
|
5
|
+
import { feedValueHelpTexts } from "./texts.mjs";
|
|
6
|
+
import { ValueHelpClient } from "./value-help-client.mjs";
|
|
7
|
+
//#region src/value-help/source.ts
|
|
8
|
+
/** Per meta-cache entry: the source of each binding object. */
|
|
9
|
+
const sources = /* @__PURE__ */ new WeakMap();
|
|
10
|
+
/**
|
|
11
|
+
* The dictionary of the binding `info` (since 0.1.207): the meta-cache entry
|
|
12
|
+
* of its URL in the UI locale of `options.texts` (one `/meta` per session), a
|
|
13
|
+
* client over it, and the dictionary resolved for the binding. Call it in the
|
|
14
|
+
* browser only: a server render reads no dictionary.
|
|
15
|
+
*/
|
|
16
|
+
function valueHelpSource(info, options) {
|
|
17
|
+
const entry = getMetaEntry(info.url, options?.clientFactory, { texts: options?.texts });
|
|
18
|
+
let byInfo = sources.get(entry);
|
|
19
|
+
if (!byInfo) sources.set(entry, byInfo = /* @__PURE__ */ new WeakMap());
|
|
20
|
+
let source = byInfo.get(info);
|
|
21
|
+
if (!source) {
|
|
22
|
+
const client = new ValueHelpClient(entry.client);
|
|
23
|
+
/** Known once resolved: a search then goes out at once. */
|
|
24
|
+
let resolved;
|
|
25
|
+
const resolve = () => resolveValueHelp(info.url, {
|
|
26
|
+
...options,
|
|
27
|
+
info
|
|
28
|
+
}).then((r) => resolved = r);
|
|
29
|
+
source = {
|
|
30
|
+
entry,
|
|
31
|
+
resolve,
|
|
32
|
+
search: (opts) => {
|
|
33
|
+
const store = clientStore(entry.client);
|
|
34
|
+
const read = (r) => client.search(r, {
|
|
35
|
+
...opts,
|
|
36
|
+
info
|
|
37
|
+
}).then((result) => {
|
|
38
|
+
feedValueHelpTexts(store, info, r, result.items);
|
|
39
|
+
return result;
|
|
40
|
+
});
|
|
41
|
+
return resolved ? read(resolved) : resolve().then(read);
|
|
42
|
+
},
|
|
43
|
+
pages: async (query, page, size) => {
|
|
44
|
+
const store = clientStore(entry.client);
|
|
45
|
+
const result = await entry.client.pages(query, page, size);
|
|
46
|
+
resolve().then((r) => feedValueHelpTexts(store, info, r, result.data), () => {});
|
|
47
|
+
return result;
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
byInfo.set(info, source);
|
|
51
|
+
}
|
|
52
|
+
return source;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* The fields a picker table lists, of the `available` ones, in their order
|
|
56
|
+
* (since 0.1.207) — the one rule of the table's filter dropdown, its dialog and
|
|
57
|
+
* the form's picker dialog: the binding's `@ui.valueHelp.column` fields, in
|
|
58
|
+
* the order it names them; else the dictionary view (`valueHelpDictPaths`)
|
|
59
|
+
* minus the fields the binding's scope pins with `=` (constant in the picker).
|
|
60
|
+
*/
|
|
61
|
+
function valueHelpColumns(resolved, info, available) {
|
|
62
|
+
if (info.columns) {
|
|
63
|
+
const byPath = new Map(available.map((c) => [c.path, c]));
|
|
64
|
+
return info.columns.flatMap((path) => byPath.get(path) ?? []);
|
|
65
|
+
}
|
|
66
|
+
const paths = valueHelpDictPaths(resolved);
|
|
67
|
+
const pinned = new Set(info.pinned);
|
|
68
|
+
return available.filter((c) => paths.has(c.path) && !pinned.has(c.path));
|
|
69
|
+
}
|
|
70
|
+
//#endregion
|
|
71
|
+
export { valueHelpColumns, valueHelpSource };
|