@atscript/ui 0.1.188 → 0.1.190

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/dist/client-factory.d.cts +9 -7
  2. package/dist/client-factory.d.mts +9 -7
  3. package/dist/form/create-form-def.cjs +38 -1
  4. package/dist/form/create-form-def.d.cts +1 -1
  5. package/dist/form/create-form-def.d.mts +1 -1
  6. package/dist/form/create-form-def.mjs +38 -1
  7. package/dist/form/diff.cjs +8 -1
  8. package/dist/form/diff.d.cts +5 -2
  9. package/dist/form/diff.d.mts +5 -2
  10. package/dist/form/diff.mjs +9 -2
  11. package/dist/form/skipped-nav.cjs +1 -1
  12. package/dist/form/skipped-nav.mjs +1 -1
  13. package/dist/index.cjs +11 -0
  14. package/dist/index.d.cts +7 -4
  15. package/dist/index.d.mts +7 -4
  16. package/dist/index.mjs +6 -3
  17. package/dist/messages.cjs +3 -0
  18. package/dist/messages.d.cts +3 -0
  19. package/dist/messages.d.mts +3 -0
  20. package/dist/messages.mjs +3 -0
  21. package/dist/plugin/annotations.cjs +57 -2
  22. package/dist/plugin/annotations.mjs +58 -3
  23. package/dist/plugin/value-help-validation.cjs +358 -24
  24. package/dist/plugin/value-help-validation.mjs +356 -26
  25. package/dist/shared/annotation-keys.cjs +11 -0
  26. package/dist/shared/annotation-keys.d.cts +3 -1
  27. package/dist/shared/annotation-keys.d.mts +3 -1
  28. package/dist/shared/annotation-keys.mjs +8 -1
  29. package/dist/shared/meta-cache.d.cts +3 -3
  30. package/dist/shared/meta-cache.d.mts +3 -3
  31. package/dist/shared/value-label.cjs +28 -0
  32. package/dist/shared/value-label.d.cts +25 -0
  33. package/dist/shared/value-label.d.mts +25 -0
  34. package/dist/shared/value-label.mjs +27 -0
  35. package/dist/table/create-table-def.cjs +15 -1
  36. package/dist/table/create-table-def.mjs +15 -1
  37. package/dist/table/types.d.cts +31 -9
  38. package/dist/table/types.d.mts +31 -9
  39. package/dist/value-help/distinct-client.d.cts +2 -2
  40. package/dist/value-help/distinct-client.d.mts +2 -2
  41. package/dist/value-help/extract-ref.cjs +22 -5
  42. package/dist/value-help/extract-ref.mjs +23 -6
  43. package/dist/value-help/filter-tree.cjs +39 -14
  44. package/dist/value-help/filter-tree.mjs +39 -14
  45. package/dist/value-help/index.d.mts +3 -1
  46. package/dist/value-help/options.cjs +30 -0
  47. package/dist/value-help/options.d.cts +19 -0
  48. package/dist/value-help/options.d.mts +19 -0
  49. package/dist/value-help/options.mjs +29 -0
  50. package/dist/value-help/scope.cjs +50 -0
  51. package/dist/value-help/scope.d.cts +32 -0
  52. package/dist/value-help/scope.d.mts +32 -0
  53. package/dist/value-help/scope.mjs +49 -0
  54. package/dist/value-help/types.d.cts +29 -1
  55. package/dist/value-help/types.d.mts +29 -1
  56. package/dist/value-help/value-help-client.cjs +23 -4
  57. package/dist/value-help/value-help-client.d.cts +27 -8
  58. package/dist/value-help/value-help-client.d.mts +27 -8
  59. package/dist/value-help/value-help-client.mjs +23 -5
  60. package/package.json +9 -9
@@ -0,0 +1,30 @@
1
+ //#region src/value-help/options.ts
2
+ /**
3
+ * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
4
+ * `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
5
+ * more: when it comes back the list is too long for a dropdown, and the field
6
+ * keeps its search picker.
7
+ */
8
+ const VALUE_HELP_OPTIONS_CAP = 200;
9
+ /**
10
+ * Dictionary rows as dropdown options (since 0.1.190): the committed
11
+ * `targetField` value as the option's value, the label field's text (the key
12
+ * when it has none) and the description after a dash.
13
+ */
14
+ function valueHelpOptions(rows, resolved, info) {
15
+ return rows.map((row) => {
16
+ const value = row[info.targetField];
17
+ const key = String(value);
18
+ const label = row[resolved.labelField];
19
+ const descr = resolved.descrField ? row[resolved.descrField] : void 0;
20
+ const text = label === void 0 || label === null || label === "" ? key : String(label);
21
+ return {
22
+ key,
23
+ label: descr ? `${text} — ${String(descr)}` : text,
24
+ value
25
+ };
26
+ });
27
+ }
28
+ //#endregion
29
+ exports.VALUE_HELP_OPTIONS_CAP = VALUE_HELP_OPTIONS_CAP;
30
+ exports.valueHelpOptions = valueHelpOptions;
@@ -0,0 +1,19 @@
1
+ import { TFormEntryOptions, ValueHelpInfo } from "./types.cjs";
2
+ import { ResolvedValueHelp } from "./resolve.cjs";
3
+
4
+ //#region src/value-help/options.d.ts
5
+ /**
6
+ * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
7
+ * `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
8
+ * more: when it comes back the list is too long for a dropdown, and the field
9
+ * keeps its search picker.
10
+ */
11
+ declare const VALUE_HELP_OPTIONS_CAP = 200;
12
+ /**
13
+ * Dictionary rows as dropdown options (since 0.1.190): the committed
14
+ * `targetField` value as the option's value, the label field's text (the key
15
+ * when it has none) and the description after a dash.
16
+ */
17
+ declare function valueHelpOptions(rows: Record<string, unknown>[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
18
+ //#endregion
19
+ export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
@@ -0,0 +1,19 @@
1
+ import { TFormEntryOptions, ValueHelpInfo } from "./types.mjs";
2
+ import { ResolvedValueHelp } from "./resolve.mjs";
3
+
4
+ //#region src/value-help/options.d.ts
5
+ /**
6
+ * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
7
+ * `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
8
+ * more: when it comes back the list is too long for a dropdown, and the field
9
+ * keeps its search picker.
10
+ */
11
+ declare const VALUE_HELP_OPTIONS_CAP = 200;
12
+ /**
13
+ * Dictionary rows as dropdown options (since 0.1.190): the committed
14
+ * `targetField` value as the option's value, the label field's text (the key
15
+ * when it has none) and the description after a dash.
16
+ */
17
+ declare function valueHelpOptions(rows: Record<string, unknown>[], resolved: ResolvedValueHelp, info: Pick<ValueHelpInfo, "targetField">): Exclude<TFormEntryOptions, string>[];
18
+ //#endregion
19
+ export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
@@ -0,0 +1,29 @@
1
+ //#region src/value-help/options.ts
2
+ /**
3
+ * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
4
+ * `@ui.type 'select'` on a bound field, since 0.1.190). A read asks for one
5
+ * more: when it comes back the list is too long for a dropdown, and the field
6
+ * keeps its search picker.
7
+ */
8
+ const VALUE_HELP_OPTIONS_CAP = 200;
9
+ /**
10
+ * Dictionary rows as dropdown options (since 0.1.190): the committed
11
+ * `targetField` value as the option's value, the label field's text (the key
12
+ * when it has none) and the description after a dash.
13
+ */
14
+ function valueHelpOptions(rows, resolved, info) {
15
+ return rows.map((row) => {
16
+ const value = row[info.targetField];
17
+ const key = String(value);
18
+ const label = row[resolved.labelField];
19
+ const descr = resolved.descrField ? row[resolved.descrField] : void 0;
20
+ const text = label === void 0 || label === null || label === "" ? key : String(label);
21
+ return {
22
+ key,
23
+ label: descr ? `${text} — ${String(descr)}` : text,
24
+ value
25
+ };
26
+ });
27
+ }
28
+ //#endregion
29
+ export { VALUE_HELP_OPTIONS_CAP, valueHelpOptions };
@@ -0,0 +1,50 @@
1
+ //#region src/value-help/scope.ts
2
+ /**
3
+ * A host value the picker can filter by: one scalar. Empty (`undefined`,
4
+ * `null`, `""`) or anything else (an array, an object) leaves the condition out.
5
+ */
6
+ function isHostValue(value) {
7
+ if (value === void 0 || value === null || value === "") return false;
8
+ return typeof value !== "object";
9
+ }
10
+ /**
11
+ * The scope of a form picker (since 0.1.190): the binding's literal `filter`
12
+ * with a `target = value` condition per host reference whose sibling field
13
+ * holds one value — read through `read(local)`, the form's sibling value —
14
+ * and the fields those values pin. A host field that is empty leaves its
15
+ * condition out (a wider picker); the value is sent as the form holds it.
16
+ * Without host references this is `{ filter: info.filter, pinned: info.pinned }`.
17
+ */
18
+ function valueHelpScope(info, read) {
19
+ const pinned = [...info.pinned ?? []];
20
+ const conditions = [];
21
+ for (const { target, local } of info.hostFilter ?? []) {
22
+ const value = read(local);
23
+ if (!isHostValue(value)) continue;
24
+ conditions.push({ [target]: value });
25
+ if (!pinned.includes(target)) pinned.push(target);
26
+ }
27
+ if (conditions.length === 0) return {
28
+ ...info.filter && { filter: info.filter },
29
+ pinned
30
+ };
31
+ const base = info.filter;
32
+ const all = base ? [...Array.isArray(base.$and) ? base.$and : [info.filter], ...conditions] : conditions;
33
+ return {
34
+ filter: all.length === 1 ? all[0] : { $and: all },
35
+ pinned
36
+ };
37
+ }
38
+ /**
39
+ * What a pick of `row` writes into sibling fields (`@ui.valueHelp.fill`,
40
+ * since 0.1.190): `row[target]` per fill, in declaration order.
41
+ */
42
+ function valueHelpFills(info, row) {
43
+ return (info.fill ?? []).map(({ local, target }) => ({
44
+ local,
45
+ value: row[target]
46
+ }));
47
+ }
48
+ //#endregion
49
+ exports.valueHelpFills = valueHelpFills;
50
+ exports.valueHelpScope = valueHelpScope;
@@ -0,0 +1,32 @@
1
+ import { ValueHelpInfo } from "./types.cjs";
2
+ import { FilterExpr } from "@atscript/db-client";
3
+
4
+ //#region src/value-help/scope.d.ts
5
+ /** The scope a picker of a form queries with: the binding's filter with its host values. */
6
+ interface ValueHelpScope {
7
+ /** `info.filter` AND'd with a `target = value` condition per host value; `undefined`: none. */
8
+ filter?: FilterExpr;
9
+ /** `info.pinned` plus the targets a host value pins — constant in the picker. */
10
+ pinned: string[];
11
+ }
12
+ /** One value a pick writes into a sibling field (`@ui.valueHelp.fill`). */
13
+ interface ValueHelpFillWrite {
14
+ local: string;
15
+ value: unknown;
16
+ }
17
+ /**
18
+ * The scope of a form picker (since 0.1.190): the binding's literal `filter`
19
+ * with a `target = value` condition per host reference whose sibling field
20
+ * holds one value — read through `read(local)`, the form's sibling value —
21
+ * and the fields those values pin. A host field that is empty leaves its
22
+ * condition out (a wider picker); the value is sent as the form holds it.
23
+ * Without host references this is `{ filter: info.filter, pinned: info.pinned }`.
24
+ */
25
+ declare function valueHelpScope(info: ValueHelpInfo, read: (local: string) => unknown): ValueHelpScope;
26
+ /**
27
+ * What a pick of `row` writes into sibling fields (`@ui.valueHelp.fill`,
28
+ * since 0.1.190): `row[target]` per fill, in declaration order.
29
+ */
30
+ declare function valueHelpFills(info: ValueHelpInfo, row: Record<string, unknown>): ValueHelpFillWrite[];
31
+ //#endregion
32
+ export { ValueHelpFillWrite, ValueHelpScope, valueHelpFills, valueHelpScope };
@@ -0,0 +1,32 @@
1
+ import { ValueHelpInfo } from "./types.mjs";
2
+ import { FilterExpr } from "@atscript/db-client";
3
+
4
+ //#region src/value-help/scope.d.ts
5
+ /** The scope a picker of a form queries with: the binding's filter with its host values. */
6
+ interface ValueHelpScope {
7
+ /** `info.filter` AND'd with a `target = value` condition per host value; `undefined`: none. */
8
+ filter?: FilterExpr;
9
+ /** `info.pinned` plus the targets a host value pins — constant in the picker. */
10
+ pinned: string[];
11
+ }
12
+ /** One value a pick writes into a sibling field (`@ui.valueHelp.fill`). */
13
+ interface ValueHelpFillWrite {
14
+ local: string;
15
+ value: unknown;
16
+ }
17
+ /**
18
+ * The scope of a form picker (since 0.1.190): the binding's literal `filter`
19
+ * with a `target = value` condition per host reference whose sibling field
20
+ * holds one value — read through `read(local)`, the form's sibling value —
21
+ * and the fields those values pin. A host field that is empty leaves its
22
+ * condition out (a wider picker); the value is sent as the form holds it.
23
+ * Without host references this is `{ filter: info.filter, pinned: info.pinned }`.
24
+ */
25
+ declare function valueHelpScope(info: ValueHelpInfo, read: (local: string) => unknown): ValueHelpScope;
26
+ /**
27
+ * What a pick of `row` writes into sibling fields (`@ui.valueHelp.fill`,
28
+ * since 0.1.190): `row[target]` per fill, in declaration order.
29
+ */
30
+ declare function valueHelpFills(info: ValueHelpInfo, row: Record<string, unknown>): ValueHelpFillWrite[];
31
+ //#endregion
32
+ export { ValueHelpFillWrite, ValueHelpScope, valueHelpFills, valueHelpScope };
@@ -0,0 +1,49 @@
1
+ //#region src/value-help/scope.ts
2
+ /**
3
+ * A host value the picker can filter by: one scalar. Empty (`undefined`,
4
+ * `null`, `""`) or anything else (an array, an object) leaves the condition out.
5
+ */
6
+ function isHostValue(value) {
7
+ if (value === void 0 || value === null || value === "") return false;
8
+ return typeof value !== "object";
9
+ }
10
+ /**
11
+ * The scope of a form picker (since 0.1.190): the binding's literal `filter`
12
+ * with a `target = value` condition per host reference whose sibling field
13
+ * holds one value — read through `read(local)`, the form's sibling value —
14
+ * and the fields those values pin. A host field that is empty leaves its
15
+ * condition out (a wider picker); the value is sent as the form holds it.
16
+ * Without host references this is `{ filter: info.filter, pinned: info.pinned }`.
17
+ */
18
+ function valueHelpScope(info, read) {
19
+ const pinned = [...info.pinned ?? []];
20
+ const conditions = [];
21
+ for (const { target, local } of info.hostFilter ?? []) {
22
+ const value = read(local);
23
+ if (!isHostValue(value)) continue;
24
+ conditions.push({ [target]: value });
25
+ if (!pinned.includes(target)) pinned.push(target);
26
+ }
27
+ if (conditions.length === 0) return {
28
+ ...info.filter && { filter: info.filter },
29
+ pinned
30
+ };
31
+ const base = info.filter;
32
+ const all = base ? [...Array.isArray(base.$and) ? base.$and : [info.filter], ...conditions] : conditions;
33
+ return {
34
+ filter: all.length === 1 ? all[0] : { $and: all },
35
+ pinned
36
+ };
37
+ }
38
+ /**
39
+ * What a pick of `row` writes into sibling fields (`@ui.valueHelp.fill`,
40
+ * since 0.1.190): `row[target]` per fill, in declaration order.
41
+ */
42
+ function valueHelpFills(info, row) {
43
+ return (info.fill ?? []).map(({ local, target }) => ({
44
+ local,
45
+ value: row[target]
46
+ }));
47
+ }
48
+ //#endregion
49
+ export { valueHelpFills, valueHelpScope };
@@ -28,7 +28,8 @@ interface ValueHelpInfo {
28
28
  targetField: string;
29
29
  /**
30
30
  * Static dictionary scope from `@ui.valueHelp`'s filter — AND'd into every
31
- * picker query. Since 0.1.148.
31
+ * picker query. Comparisons with literal values only: the filter's host
32
+ * references are in {@link hostFilter}. Since 0.1.148.
32
33
  */
33
34
  filter?: FilterExpr;
34
35
  /**
@@ -36,6 +37,33 @@ interface ValueHelpInfo {
36
37
  * from its columns. Since 0.1.148.
37
38
  */
38
39
  pinned?: string[];
40
+ /**
41
+ * The filter's host references (`targetField = Host.field`): in a form, the
42
+ * picker also filters `target` by the value of the sibling field `local`,
43
+ * left out while that field is empty (`valueHelpScope`). Table filters do
44
+ * not apply them. In a form def, `local` is the sibling's path in the def:
45
+ * for a field of a namespace object rendered inline it carries the parent
46
+ * (`shipping.country`). Since 0.1.190.
47
+ */
48
+ hostFilter?: {
49
+ target: string;
50
+ local: string;
51
+ }[];
52
+ /**
53
+ * `@ui.valueHelp.fill`: in a form, a pick also writes the row's `target`
54
+ * into the sibling field `local`. Only from the field's own binding or FK
55
+ * help; a form keeps the fills it can write, `local` scoped as in
56
+ * {@link hostFilter}. Since 0.1.190.
57
+ */
58
+ fill?: {
59
+ local: string;
60
+ target: string;
61
+ }[];
62
+ /**
63
+ * `@ui.valueHelp.column`: the target fields the picker dialogs show, in
64
+ * order, instead of the dictionary view. Since 0.1.190.
65
+ */
66
+ columns?: string[];
39
67
  }
40
68
  //#endregion
41
69
  export { TFormEntryOptions, ValueHelpInfo };
@@ -28,7 +28,8 @@ interface ValueHelpInfo {
28
28
  targetField: string;
29
29
  /**
30
30
  * Static dictionary scope from `@ui.valueHelp`'s filter — AND'd into every
31
- * picker query. Since 0.1.148.
31
+ * picker query. Comparisons with literal values only: the filter's host
32
+ * references are in {@link hostFilter}. Since 0.1.148.
32
33
  */
33
34
  filter?: FilterExpr;
34
35
  /**
@@ -36,6 +37,33 @@ interface ValueHelpInfo {
36
37
  * from its columns. Since 0.1.148.
37
38
  */
38
39
  pinned?: string[];
40
+ /**
41
+ * The filter's host references (`targetField = Host.field`): in a form, the
42
+ * picker also filters `target` by the value of the sibling field `local`,
43
+ * left out while that field is empty (`valueHelpScope`). Table filters do
44
+ * not apply them. In a form def, `local` is the sibling's path in the def:
45
+ * for a field of a namespace object rendered inline it carries the parent
46
+ * (`shipping.country`). Since 0.1.190.
47
+ */
48
+ hostFilter?: {
49
+ target: string;
50
+ local: string;
51
+ }[];
52
+ /**
53
+ * `@ui.valueHelp.fill`: in a form, a pick also writes the row's `target`
54
+ * into the sibling field `local`. Only from the field's own binding or FK
55
+ * help; a form keeps the fills it can write, `local` scoped as in
56
+ * {@link hostFilter}. Since 0.1.190.
57
+ */
58
+ fill?: {
59
+ local: string;
60
+ target: string;
61
+ }[];
62
+ /**
63
+ * `@ui.valueHelp.column`: the target fields the picker dialogs show, in
64
+ * order, instead of the dictionary view. Since 0.1.190.
65
+ */
66
+ columns?: string[];
39
67
  }
40
68
  //#endregion
41
69
  export { TFormEntryOptions, ValueHelpInfo };
@@ -85,10 +85,13 @@ var ValueHelpClient = class {
85
85
  async search(resolved, opts) {
86
86
  const mode = opts?.mode ?? "form";
87
87
  const limit = opts?.limit ?? 20;
88
- const valueField = opts?.valueField;
89
- const selectFields = opts?.select ?? computeSelectFields(resolved, mode, valueField);
88
+ const valueField = opts?.valueField ?? opts?.info?.targetField;
90
89
  const text = opts?.text;
91
90
  const scope = opts?.filter;
91
+ const selectFields = valueHelpSelect(resolved, opts?.info, mode, valueField);
92
+ if (opts?.select) {
93
+ for (const f of opts.select) if (!selectFields.includes(f)) selectFields.push(f);
94
+ }
92
95
  const controls = {
93
96
  $select: selectFields,
94
97
  $limit: limit
@@ -96,7 +99,8 @@ var ValueHelpClient = class {
96
99
  let filter = scope;
97
100
  if (text) if (resolved.searchable) controls.$search = text;
98
101
  else {
99
- const search = buildOrFilter(text, selectFields, valueField ?? resolved.primaryKeys[0] ?? resolved.labelField);
102
+ const keyField = valueField ?? resolved.primaryKeys[0] ?? resolved.labelField;
103
+ const search = buildOrFilter(text, computeSelectFields(resolved, mode, valueField), keyField);
100
104
  filter = scope ? { $and: [scope, search] } : search;
101
105
  }
102
106
  const items = await sharedQuery(this._client, {
@@ -107,7 +111,21 @@ var ValueHelpClient = class {
107
111
  }
108
112
  };
109
113
  /**
110
- * Compute the $select fields for a value-help query — always including the
114
+ * The fields every value-help read selects — the one rule for the form picker,
115
+ * the dropdown and the table's filter pickers (since 0.1.190): the dictionary's
116
+ * keys, label and description (and its `@ui.dict.attr` fields in `"filter"`
117
+ * mode), the committed `targetField` (`valueField` overrides it), the
118
+ * binding's `columns` and the target fields of its `fill`.
119
+ */
120
+ function valueHelpSelect(resolved, info, mode = "form", valueField = info?.targetField) {
121
+ const fields = computeSelectFields(resolved, mode, valueField);
122
+ if (info?.targetField) fields.push(info.targetField);
123
+ if (info?.columns) fields.push(...info.columns);
124
+ if (info?.fill) for (const f of info.fill) fields.push(f.target);
125
+ return [...new Set(fields)];
126
+ }
127
+ /**
128
+ * The dictionary's own fields of a value-help query — always including the
111
129
  * `valueField` the picker commits (a unique non-PK field is otherwise never fetched).
112
130
  */
113
131
  function computeSelectFields(resolved, mode, valueField) {
@@ -134,3 +152,4 @@ function buildOrFilter(text, fields, pkField) {
134
152
  exports.ValueHelpClient = ValueHelpClient;
135
153
  exports.invalidateValueHelpCache = invalidateValueHelpCache;
136
154
  exports.setValueHelpCacheTtl = setValueHelpCacheTtl;
155
+ exports.valueHelpSelect = valueHelpSelect;
@@ -1,5 +1,6 @@
1
+ import { ValueHelpInfo } from "./types.cjs";
1
2
  import { ResolvedValueHelp } from "./resolve.cjs";
2
- import { Client, FilterExpr } from "@atscript/db-client";
3
+ import { ClientLike, FilterExpr } from "@atscript/db-client";
3
4
 
4
5
  //#region src/value-help/value-help-client.d.ts
5
6
  interface ValueHelpSearchOptions {
@@ -9,20 +10,30 @@ interface ValueHelpSearchOptions {
9
10
  mode?: "form" | "filter";
10
11
  /** Max results. Default: 20. */
11
12
  limit?: number;
12
- /** Override the computed select fields. */
13
+ /**
14
+ * Fields added to the ones a value-help search always reads
15
+ * ({@link valueHelpSelect}). Since 0.1.190 it adds; before, it replaced them
16
+ * (and could leave out the committed field).
17
+ */
13
18
  select?: string[];
14
19
  /**
15
- * Static dictionary scope (`ValueHelpInfo.filter`) — AND'd with the search
16
- * filter and with `$search`. Since 0.1.148.
20
+ * Dictionary scope — AND'd with the search filter and with `$search`: the
21
+ * binding's `ValueHelpInfo.filter`, or in a form `valueHelpScope(info, …).filter`
22
+ * (the filter with the host values). Since 0.1.148.
17
23
  */
18
24
  filter?: FilterExpr;
19
25
  /**
20
26
  * The target field the picker commits (`ValueHelpInfo.targetField`). It is
21
27
  * selected, and it is the exact-match key of a non-searchable search — a
22
28
  * composite-key dictionary's `primaryKeys[0]` is not the value. Default:
23
- * `primaryKeys[0]`. Since 0.1.148.
29
+ * `primaryKeys[0]`, or `info.targetField`. Since 0.1.148.
24
30
  */
25
31
  valueField?: string;
32
+ /**
33
+ * The binding searched: its `targetField`, `columns` and the target fields
34
+ * of its `fill` are always selected ({@link valueHelpSelect}). Since 0.1.190.
35
+ */
36
+ info?: Pick<ValueHelpInfo, "targetField" | "columns" | "fill">;
26
37
  }
27
38
  interface ValueHelpResult {
28
39
  items: Record<string, unknown>[];
@@ -39,7 +50,7 @@ declare function setValueHelpCacheTtl(ms: number): void;
39
50
  * client when omitted. Call after writing to a dictionary outside the
40
51
  * built-in table actions to make pickers refetch at once.
41
52
  */
42
- declare function invalidateValueHelpCache(client?: Client): void;
53
+ declare function invalidateValueHelpCache(client?: ClientLike): void;
43
54
  /**
44
55
  * Value-help query client. Wraps a `Client` from `@atscript/db-client`
45
56
  * with FK-specific search logic (regex fallback for non-searchable tables,
@@ -54,7 +65,7 @@ declare function invalidateValueHelpCache(client?: Client): void;
54
65
  */
55
66
  declare class ValueHelpClient {
56
67
  private readonly _client;
57
- constructor(client: Client);
68
+ constructor(client: ClientLike);
58
69
  /**
59
70
  * Search the target with value-help semantics.
60
71
  *
@@ -63,5 +74,13 @@ declare class ValueHelpClient {
63
74
  */
64
75
  search(resolved: ResolvedValueHelp, opts?: ValueHelpSearchOptions): Promise<ValueHelpResult>;
65
76
  }
77
+ /**
78
+ * The fields every value-help read selects — the one rule for the form picker,
79
+ * the dropdown and the table's filter pickers (since 0.1.190): the dictionary's
80
+ * keys, label and description (and its `@ui.dict.attr` fields in `"filter"`
81
+ * mode), the committed `targetField` (`valueField` overrides it), the
82
+ * binding's `columns` and the target fields of its `fill`.
83
+ */
84
+ declare function valueHelpSelect(resolved: ResolvedValueHelp, info?: Pick<ValueHelpInfo, "targetField" | "columns" | "fill">, mode?: "form" | "filter", valueField?: string | undefined): string[];
66
85
  //#endregion
67
- export { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl };
86
+ export { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl, valueHelpSelect };
@@ -1,5 +1,6 @@
1
+ import { ValueHelpInfo } from "./types.mjs";
1
2
  import { ResolvedValueHelp } from "./resolve.mjs";
2
- import { Client, FilterExpr } from "@atscript/db-client";
3
+ import { ClientLike, FilterExpr } from "@atscript/db-client";
3
4
 
4
5
  //#region src/value-help/value-help-client.d.ts
5
6
  interface ValueHelpSearchOptions {
@@ -9,20 +10,30 @@ interface ValueHelpSearchOptions {
9
10
  mode?: "form" | "filter";
10
11
  /** Max results. Default: 20. */
11
12
  limit?: number;
12
- /** Override the computed select fields. */
13
+ /**
14
+ * Fields added to the ones a value-help search always reads
15
+ * ({@link valueHelpSelect}). Since 0.1.190 it adds; before, it replaced them
16
+ * (and could leave out the committed field).
17
+ */
13
18
  select?: string[];
14
19
  /**
15
- * Static dictionary scope (`ValueHelpInfo.filter`) — AND'd with the search
16
- * filter and with `$search`. Since 0.1.148.
20
+ * Dictionary scope — AND'd with the search filter and with `$search`: the
21
+ * binding's `ValueHelpInfo.filter`, or in a form `valueHelpScope(info, …).filter`
22
+ * (the filter with the host values). Since 0.1.148.
17
23
  */
18
24
  filter?: FilterExpr;
19
25
  /**
20
26
  * The target field the picker commits (`ValueHelpInfo.targetField`). It is
21
27
  * selected, and it is the exact-match key of a non-searchable search — a
22
28
  * composite-key dictionary's `primaryKeys[0]` is not the value. Default:
23
- * `primaryKeys[0]`. Since 0.1.148.
29
+ * `primaryKeys[0]`, or `info.targetField`. Since 0.1.148.
24
30
  */
25
31
  valueField?: string;
32
+ /**
33
+ * The binding searched: its `targetField`, `columns` and the target fields
34
+ * of its `fill` are always selected ({@link valueHelpSelect}). Since 0.1.190.
35
+ */
36
+ info?: Pick<ValueHelpInfo, "targetField" | "columns" | "fill">;
26
37
  }
27
38
  interface ValueHelpResult {
28
39
  items: Record<string, unknown>[];
@@ -39,7 +50,7 @@ declare function setValueHelpCacheTtl(ms: number): void;
39
50
  * client when omitted. Call after writing to a dictionary outside the
40
51
  * built-in table actions to make pickers refetch at once.
41
52
  */
42
- declare function invalidateValueHelpCache(client?: Client): void;
53
+ declare function invalidateValueHelpCache(client?: ClientLike): void;
43
54
  /**
44
55
  * Value-help query client. Wraps a `Client` from `@atscript/db-client`
45
56
  * with FK-specific search logic (regex fallback for non-searchable tables,
@@ -54,7 +65,7 @@ declare function invalidateValueHelpCache(client?: Client): void;
54
65
  */
55
66
  declare class ValueHelpClient {
56
67
  private readonly _client;
57
- constructor(client: Client);
68
+ constructor(client: ClientLike);
58
69
  /**
59
70
  * Search the target with value-help semantics.
60
71
  *
@@ -63,5 +74,13 @@ declare class ValueHelpClient {
63
74
  */
64
75
  search(resolved: ResolvedValueHelp, opts?: ValueHelpSearchOptions): Promise<ValueHelpResult>;
65
76
  }
77
+ /**
78
+ * The fields every value-help read selects — the one rule for the form picker,
79
+ * the dropdown and the table's filter pickers (since 0.1.190): the dictionary's
80
+ * keys, label and description (and its `@ui.dict.attr` fields in `"filter"`
81
+ * mode), the committed `targetField` (`valueField` overrides it), the
82
+ * binding's `columns` and the target fields of its `fill`.
83
+ */
84
+ declare function valueHelpSelect(resolved: ResolvedValueHelp, info?: Pick<ValueHelpInfo, "targetField" | "columns" | "fill">, mode?: "form" | "filter", valueField?: string | undefined): string[];
66
85
  //#endregion
67
- export { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl };
86
+ export { ValueHelpClient, ValueHelpResult, ValueHelpSearchOptions, invalidateValueHelpCache, setValueHelpCacheTtl, valueHelpSelect };
@@ -85,10 +85,13 @@ var ValueHelpClient = class {
85
85
  async search(resolved, opts) {
86
86
  const mode = opts?.mode ?? "form";
87
87
  const limit = opts?.limit ?? 20;
88
- const valueField = opts?.valueField;
89
- const selectFields = opts?.select ?? computeSelectFields(resolved, mode, valueField);
88
+ const valueField = opts?.valueField ?? opts?.info?.targetField;
90
89
  const text = opts?.text;
91
90
  const scope = opts?.filter;
91
+ const selectFields = valueHelpSelect(resolved, opts?.info, mode, valueField);
92
+ if (opts?.select) {
93
+ for (const f of opts.select) if (!selectFields.includes(f)) selectFields.push(f);
94
+ }
92
95
  const controls = {
93
96
  $select: selectFields,
94
97
  $limit: limit
@@ -96,7 +99,8 @@ var ValueHelpClient = class {
96
99
  let filter = scope;
97
100
  if (text) if (resolved.searchable) controls.$search = text;
98
101
  else {
99
- const search = buildOrFilter(text, selectFields, valueField ?? resolved.primaryKeys[0] ?? resolved.labelField);
102
+ const keyField = valueField ?? resolved.primaryKeys[0] ?? resolved.labelField;
103
+ const search = buildOrFilter(text, computeSelectFields(resolved, mode, valueField), keyField);
100
104
  filter = scope ? { $and: [scope, search] } : search;
101
105
  }
102
106
  const items = await sharedQuery(this._client, {
@@ -107,7 +111,21 @@ var ValueHelpClient = class {
107
111
  }
108
112
  };
109
113
  /**
110
- * Compute the $select fields for a value-help query — always including the
114
+ * The fields every value-help read selects — the one rule for the form picker,
115
+ * the dropdown and the table's filter pickers (since 0.1.190): the dictionary's
116
+ * keys, label and description (and its `@ui.dict.attr` fields in `"filter"`
117
+ * mode), the committed `targetField` (`valueField` overrides it), the
118
+ * binding's `columns` and the target fields of its `fill`.
119
+ */
120
+ function valueHelpSelect(resolved, info, mode = "form", valueField = info?.targetField) {
121
+ const fields = computeSelectFields(resolved, mode, valueField);
122
+ if (info?.targetField) fields.push(info.targetField);
123
+ if (info?.columns) fields.push(...info.columns);
124
+ if (info?.fill) for (const f of info.fill) fields.push(f.target);
125
+ return [...new Set(fields)];
126
+ }
127
+ /**
128
+ * The dictionary's own fields of a value-help query — always including the
111
129
  * `valueField` the picker commits (a unique non-PK field is otherwise never fetched).
112
130
  */
113
131
  function computeSelectFields(resolved, mode, valueField) {
@@ -131,4 +149,4 @@ function buildOrFilter(text, fields, pkField) {
131
149
  return { $or: conditions };
132
150
  }
133
151
  //#endregion
134
- export { ValueHelpClient, invalidateValueHelpCache, setValueHelpCacheTtl };
152
+ export { ValueHelpClient, invalidateValueHelpCache, setValueHelpCacheTtl, valueHelpSelect };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atscript/ui",
3
- "version": "0.1.188",
3
+ "version": "0.1.190",
4
4
  "description": "Framework-agnostic runtime for form and table definitions from atscript annotated types",
5
5
  "keywords": [
6
6
  "annotations",
@@ -52,20 +52,20 @@
52
52
  "access": "public"
53
53
  },
54
54
  "dependencies": {
55
- "@atscript/db-client": "^0.1.194"
55
+ "@atscript/db-client": "^0.1.196"
56
56
  },
57
57
  "devDependencies": {
58
- "@atscript/core": "^0.2.21",
59
- "@atscript/db": "^0.1.194",
60
- "@atscript/typescript": "^0.2.21",
58
+ "@atscript/core": "^0.2.23",
59
+ "@atscript/db": "^0.1.196",
60
+ "@atscript/typescript": "^0.2.23",
61
61
  "@uniqu/core": "^0.2.2",
62
- "unplugin-atscript": "^0.2.21",
62
+ "unplugin-atscript": "^0.2.23",
63
63
  "vitest": "npm:@voidzero-dev/vite-plus-test@0.1.14"
64
64
  },
65
65
  "peerDependencies": {
66
- "@atscript/core": "^0.2.21",
67
- "@atscript/db": "^0.1.194",
68
- "@atscript/typescript": "^0.2.21"
66
+ "@atscript/core": "^0.2.23",
67
+ "@atscript/db": "^0.1.196",
68
+ "@atscript/typescript": "^0.2.23"
69
69
  },
70
70
  "scripts": {
71
71
  "build": "vp pack",