@atscript/ui 0.1.206 → 0.1.208

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/dist/form/create-form-def.cjs +16 -18
  2. package/dist/form/create-form-def.mjs +15 -17
  3. package/dist/form/decimal-format.cjs +8 -3
  4. package/dist/form/decimal-format.d.cts +8 -2
  5. package/dist/form/decimal-format.d.mts +8 -2
  6. package/dist/form/decimal-format.mjs +8 -3
  7. package/dist/form/form-actions.cjs +9 -0
  8. package/dist/form/form-actions.d.cts +7 -1
  9. package/dist/form/form-actions.d.mts +7 -1
  10. package/dist/form/form-actions.mjs +9 -1
  11. package/dist/form/measurement.cjs +58 -0
  12. package/dist/form/measurement.d.cts +36 -1
  13. package/dist/form/measurement.d.mts +36 -1
  14. package/dist/form/measurement.mjs +57 -2
  15. package/dist/form/omit-derived.cjs +11 -0
  16. package/dist/form/omit-derived.d.cts +8 -1
  17. package/dist/form/omit-derived.d.mts +8 -1
  18. package/dist/form/omit-derived.mjs +11 -1
  19. package/dist/form/optional-mode.cjs +7 -7
  20. package/dist/form/optional-mode.d.cts +2 -1
  21. package/dist/form/optional-mode.d.mts +2 -1
  22. package/dist/form/optional-mode.mjs +8 -8
  23. package/dist/form/path-utils.cjs +10 -0
  24. package/dist/form/path-utils.d.cts +8 -1
  25. package/dist/form/path-utils.d.mts +8 -1
  26. package/dist/form/path-utils.mjs +10 -1
  27. package/dist/form/types.cjs +5 -0
  28. package/dist/form/types.d.cts +14 -0
  29. package/dist/form/types.d.mts +14 -0
  30. package/dist/form/types.mjs +5 -1
  31. package/dist/form/validate.cjs +56 -5
  32. package/dist/form/validate.d.cts +30 -2
  33. package/dist/form/validate.d.mts +30 -2
  34. package/dist/form/validate.mjs +56 -6
  35. package/dist/index.cjs +42 -6
  36. package/dist/index.d.cts +20 -12
  37. package/dist/index.d.mts +20 -12
  38. package/dist/index.mjs +23 -15
  39. package/dist/plugin/annotations.cjs +33 -14
  40. package/dist/plugin/annotations.mjs +34 -15
  41. package/dist/plugin/value-help-validation.cjs +26 -6
  42. package/dist/plugin/value-help-validation.mjs +26 -7
  43. package/dist/shared/annotation-keys.cjs +3 -0
  44. package/dist/shared/annotation-keys.d.cts +2 -1
  45. package/dist/shared/annotation-keys.d.mts +2 -1
  46. package/dist/shared/annotation-keys.mjs +3 -1
  47. package/dist/shared/dev.cjs +22 -0
  48. package/dist/shared/dev.d.cts +4 -0
  49. package/dist/shared/dev.d.mts +4 -0
  50. package/dist/shared/dev.mjs +22 -0
  51. package/dist/shared/field-resolver.cjs +21 -1
  52. package/dist/shared/field-resolver.d.cts +15 -1
  53. package/dist/shared/field-resolver.d.mts +15 -1
  54. package/dist/shared/field-resolver.mjs +20 -2
  55. package/dist/shared/merge-filters.cjs +28 -0
  56. package/dist/shared/merge-filters.d.cts +13 -0
  57. package/dist/shared/merge-filters.d.mts +13 -0
  58. package/dist/shared/merge-filters.mjs +28 -0
  59. package/dist/shared/meta-cache.cjs +5 -4
  60. package/dist/shared/meta-cache.d.cts +3 -2
  61. package/dist/shared/meta-cache.d.mts +3 -2
  62. package/dist/shared/meta-cache.mjs +5 -4
  63. package/dist/shared/resolve-component.cjs +27 -0
  64. package/dist/shared/resolve-component.d.cts +22 -0
  65. package/dist/shared/resolve-component.d.mts +22 -0
  66. package/dist/shared/resolve-component.mjs +27 -0
  67. package/dist/shared/stable-key.cjs +28 -0
  68. package/dist/shared/stable-key.d.cts +13 -0
  69. package/dist/shared/stable-key.d.mts +13 -0
  70. package/dist/shared/stable-key.mjs +28 -0
  71. package/dist/shared/to-date.cjs +65 -0
  72. package/dist/shared/to-date.d.cts +35 -0
  73. package/dist/shared/to-date.d.mts +35 -0
  74. package/dist/shared/to-date.mjs +64 -0
  75. package/dist/shared/value-label.cjs +14 -2
  76. package/dist/shared/value-label.d.cts +23 -6
  77. package/dist/shared/value-label.d.mts +23 -6
  78. package/dist/shared/value-label.mjs +14 -3
  79. package/dist/table/create-table-def.cjs +53 -13
  80. package/dist/table/create-table-def.mjs +53 -15
  81. package/dist/table/types.d.cts +15 -13
  82. package/dist/table/types.d.mts +15 -13
  83. package/dist/value-help/client-store.cjs +43 -0
  84. package/dist/value-help/client-store.d.mts +1 -0
  85. package/dist/value-help/client-store.mjs +40 -0
  86. package/dist/value-help/display-value.cjs +30 -0
  87. package/dist/value-help/display-value.d.cts +45 -0
  88. package/dist/value-help/display-value.d.mts +45 -0
  89. package/dist/value-help/display-value.mjs +30 -0
  90. package/dist/value-help/distinct-client.cjs +80 -7
  91. package/dist/value-help/distinct-client.d.cts +31 -36
  92. package/dist/value-help/distinct-client.d.mts +31 -36
  93. package/dist/value-help/distinct-client.mjs +80 -7
  94. package/dist/value-help/extract-ref.cjs +15 -4
  95. package/dist/value-help/extract-ref.d.cts +6 -1
  96. package/dist/value-help/extract-ref.d.mts +6 -1
  97. package/dist/value-help/extract-ref.mjs +16 -6
  98. package/dist/value-help/index.d.mts +6 -3
  99. package/dist/value-help/options.cjs +70 -8
  100. package/dist/value-help/options.d.cts +57 -4
  101. package/dist/value-help/options.d.mts +57 -4
  102. package/dist/value-help/options.mjs +67 -9
  103. package/dist/value-help/resolve-options.cjs +9 -7
  104. package/dist/value-help/resolve-options.d.cts +8 -9
  105. package/dist/value-help/resolve-options.d.mts +8 -9
  106. package/dist/value-help/resolve-options.mjs +9 -7
  107. package/dist/value-help/resolve.cjs +29 -8
  108. package/dist/value-help/resolve.d.cts +22 -5
  109. package/dist/value-help/resolve.d.mts +22 -5
  110. package/dist/value-help/resolve.mjs +29 -8
  111. package/dist/value-help/scope.cjs +3 -7
  112. package/dist/value-help/scope.mjs +3 -7
  113. package/dist/value-help/source.cjs +72 -0
  114. package/dist/value-help/source.d.cts +55 -0
  115. package/dist/value-help/source.d.mts +55 -0
  116. package/dist/value-help/source.mjs +71 -0
  117. package/dist/value-help/texts.cjs +318 -0
  118. package/dist/value-help/texts.d.cts +53 -0
  119. package/dist/value-help/texts.d.mts +53 -0
  120. package/dist/value-help/texts.mjs +313 -0
  121. package/dist/value-help/types.d.cts +10 -0
  122. package/dist/value-help/types.d.mts +10 -0
  123. package/dist/value-help/value-help-client.cjs +24 -20
  124. package/dist/value-help/value-help-client.d.cts +10 -5
  125. package/dist/value-help/value-help-client.d.mts +10 -5
  126. package/dist/value-help/value-help-client.mjs +22 -18
  127. package/package.json +10 -10
@@ -1,6 +1,10 @@
1
1
  const require_path_utils = require("../form/path-utils.cjs");
2
+ const require_merge_filters = require("../shared/merge-filters.cjs");
2
3
  const require_str = require("../shared/str.cjs");
3
4
  const require_value_kind = require("../table/value-kind.cjs");
5
+ const require_client_store = require("./client-store.cjs");
6
+ const require_meta_cache = require("../shared/meta-cache.cjs");
7
+ const require_stable_key = require("../shared/stable-key.cjs");
4
8
  //#region src/value-help/distinct-client.ts
5
9
  /**
6
10
  * `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
@@ -17,22 +21,21 @@ function isPickerDeclined(err) {
17
21
  * 4xx rejects with a `ClientError` — see {@link isPickerDeclined}.
18
22
  * `hasMore` tells whether another page follows.
19
23
  *
20
- * @internal Backs the distinct-values picker of `@atscript/vue-table`.
24
+ * @internal Backs {@link createDistinctPager}.
21
25
  */
22
26
  async function fetchDistinctValues(client, field, opts = {}) {
23
27
  const limit = opts.limit ?? 50;
24
28
  const text = opts.text?.trim();
25
- const conditions = [];
26
- if (opts.filter) conditions.push(opts.filter);
29
+ let search;
27
30
  if (text) if (opts.valueKind && require_value_kind.NUMERIC_VALUE_KINDS.has(opts.valueKind)) {
28
31
  const value = require_value_kind.coerceNumericText(text, opts.valueKind);
29
32
  if (value === void 0) return {
30
33
  items: [],
31
34
  hasMore: false
32
35
  };
33
- conditions.push({ [field]: value });
34
- } else conditions.push({ [field]: { $regex: `/^${require_str.escapeRegex(text)}/i` } });
35
- const filter = conditions.length > 1 ? { $and: conditions } : conditions[0];
36
+ search = { [field]: value };
37
+ } else search = { [field]: { $regex: `/^${require_str.escapeRegex(text)}/i` } };
38
+ const filter = require_merge_filters.mergeFilters(opts.filter, search);
36
39
  const rows = await client.aggregate({
37
40
  ...filter && { filter },
38
41
  controls: {
@@ -48,6 +51,76 @@ async function fetchDistinctValues(client, field, opts = {}) {
48
51
  hasMore: rows.length > limit
49
52
  };
50
53
  }
54
+ /** How long an unsearched first page is reused. */
55
+ const PAGE1_TTL_MS = 3e4;
56
+ /**
57
+ * The pager over the distinct values of `column.distinct`
58
+ * (`@ui.valueHelp.distinct`; since 0.1.208): each page is a
59
+ * {@link fetchDistinctValues} on the table's controller, in the current scope
60
+ * (`opts.scope`). Values are ordered, and so paged, only on a sortable column;
61
+ * otherwise the first `size` values are the whole list (a later page is
62
+ * empty) and a search narrows it. A 4xx rejects. The unsearched first page
63
+ * is reused for 30 s per page size and scope, so every picker sharing this
64
+ * pager asks once — until the data drops (`invalidateValueHelpCache`, which
65
+ * a table action or delete runs); a failure is not kept. Each request asks
66
+ * in the current locale of `opts.texts` through that locale's `/meta` entry,
67
+ * built with `opts.clientFactory` (the table's).
68
+ */
69
+ function createDistinctPager(column, opts = {}) {
70
+ const { url, field } = column.distinct;
71
+ const paged = column.sortable;
72
+ const page1 = /* @__PURE__ */ new Map();
73
+ return async (searchTerm, page, size) => {
74
+ const text = searchTerm.trim();
75
+ const skip = paged ? (page - 1) * size : 0;
76
+ const scope = opts.scope?.();
77
+ const client = require_meta_cache.getMetaEntry(url, opts.clientFactory, { texts: opts.texts }).client;
78
+ const load = () => fetchDistinctValues(client, field, {
79
+ text,
80
+ limit: size,
81
+ skip,
82
+ sortable: paged,
83
+ valueKind: column.valueKind,
84
+ filter: scope
85
+ });
86
+ let result;
87
+ if (!paged && page > 1) result = {
88
+ items: [],
89
+ hasMore: false
90
+ };
91
+ else if (text || page > 1) result = await load();
92
+ else {
93
+ const key = `${size}\0${scope ? require_stable_key.stableValueKey(scope) : ""}`;
94
+ const store = require_client_store.clientStore(client);
95
+ const at = Date.now();
96
+ for (const [k, old] of page1) if (at - old.at > PAGE1_TTL_MS) page1.delete(k);
97
+ let hit = page1.get(key);
98
+ if (hit?.store !== store) {
99
+ const entry = {
100
+ at,
101
+ store,
102
+ result: load()
103
+ };
104
+ entry.result.catch(() => page1.get(key) === entry && page1.delete(key));
105
+ page1.set(key, entry);
106
+ hit = entry;
107
+ }
108
+ result = await hit.result;
109
+ }
110
+ const hasMore = paged && result.hasMore;
111
+ const count = skip + result.items.length + (hasMore ? 1 : 0);
112
+ return {
113
+ data: result.items.map((v) => ({
114
+ __value: v,
115
+ __label: String(v)
116
+ })),
117
+ count,
118
+ page,
119
+ itemsPerPage: size,
120
+ pages: Math.max(1, Math.ceil(count / size))
121
+ };
122
+ };
123
+ }
51
124
  //#endregion
52
- exports.fetchDistinctValues = fetchDistinctValues;
125
+ exports.createDistinctPager = createDistinctPager;
53
126
  exports.isPickerDeclined = isPickerDeclined;
@@ -1,46 +1,41 @@
1
- import { ColumnValueKind } from "../table/types.cjs";
2
- import { ClientLike, FilterExpr } from "@atscript/db-client";
1
+ import { ColumnDef } from "../table/types.cjs";
2
+ import { ValueHelpSourceOptions } from "./source.cjs";
3
+ import { ClientLike, FilterExpr, PageResult } from "@atscript/db-client";
3
4
 
4
5
  //#region src/value-help/distinct-client.d.ts
5
- interface DistinctValuesOptions {
6
- /** Search text: a case-insensitive prefix match for strings, an exact match for numbers. */
7
- text?: string;
8
- /** Page size. Default: 50. */
9
- limit?: number;
10
- /**
11
- * Rows to skip (the next page of a scrolled picker). Distinct values are only
12
- * stable across pages when ordered, so a caller pages only with `sortable`.
13
- */
14
- skip?: number;
15
- /** Send `$sort` on the grouped field — only when the server lists it as sortable. */
16
- sortable?: boolean;
17
- /**
18
- * The field's storage kind. A numeric one ({@link NUMERIC_VALUE_KINDS}) is
19
- * searched by exact value — text that is no value of it finds nothing; a
20
- * `decimal` / `long` value is sent as text (since 0.1.205; before, a
21
- * `numeric` flag and a JS number).
22
- */
23
- valueKind?: ColumnValueKind;
24
- /** Extra scope AND'd into the query (e.g. the table's `forceFilters`). */
25
- filter?: FilterExpr;
26
- }
6
+ type Row = Record<string, unknown>;
27
7
  /**
28
8
  * `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
29
9
  * @internal Shared with `@atscript/vue-table`.
30
10
  */
31
11
  declare function isPickerDeclined(err: unknown): boolean;
32
12
  /**
33
- * Distinct values of one column of the table behind `client`, via
34
- * `/query?$groupBy=<field>`. All server gates (hidden field, ARBAC `$groupBy`
35
- * control, row scope, write-only, encrypted) apply as for any grouped read; a
36
- * 4xx rejects with a `ClientError` — see {@link isPickerDeclined}.
37
- * `hasMore` tells whether another page follows.
38
- *
39
- * @internal Backs the distinct-values picker of `@atscript/vue-table`.
13
+ * `(searchTerm, page, size)` → one page of a column's distinct values as
14
+ * picker rows — `__value` (the value) and `__label` (its text) — sized for a
15
+ * window: `count` is one past the values loaded so far while more follow
16
+ * (see {@link createDistinctPager}).
17
+ */
18
+ type DistinctPager = (searchTerm: string, page: number, size: number) => Promise<PageResult<Row>>;
19
+ interface DistinctPagerOptions extends ValueHelpSourceOptions {
20
+ /**
21
+ * The table's scope, read at every request (its `forceFilters`): the values
22
+ * narrow like the rows, so a picker never offers one the table cannot show.
23
+ */
24
+ scope?: () => FilterExpr | undefined;
25
+ }
26
+ /**
27
+ * The pager over the distinct values of `column.distinct`
28
+ * (`@ui.valueHelp.distinct`; since 0.1.208): each page is a
29
+ * {@link fetchDistinctValues} on the table's controller, in the current scope
30
+ * (`opts.scope`). Values are ordered, and so paged, only on a sortable column;
31
+ * otherwise the first `size` values are the whole list (a later page is
32
+ * empty) and a search narrows it. A 4xx rejects. The unsearched first page
33
+ * is reused for 30 s per page size and scope, so every picker sharing this
34
+ * pager asks once — until the data drops (`invalidateValueHelpCache`, which
35
+ * a table action or delete runs); a failure is not kept. Each request asks
36
+ * in the current locale of `opts.texts` through that locale's `/meta` entry,
37
+ * built with `opts.clientFactory` (the table's).
40
38
  */
41
- declare function fetchDistinctValues(client: Pick<ClientLike, "aggregate">, field: string, opts?: DistinctValuesOptions): Promise<{
42
- items: unknown[];
43
- hasMore: boolean;
44
- }>;
39
+ declare function createDistinctPager(column: Pick<ColumnDef, "distinct" | "sortable" | "valueKind">, opts?: DistinctPagerOptions): DistinctPager;
45
40
  //#endregion
46
- export { fetchDistinctValues, isPickerDeclined };
41
+ export { DistinctPager, DistinctPagerOptions, createDistinctPager, isPickerDeclined };
@@ -1,46 +1,41 @@
1
- import { ColumnValueKind } from "../table/types.mjs";
2
- import { ClientLike, FilterExpr } from "@atscript/db-client";
1
+ import { ColumnDef } from "../table/types.mjs";
2
+ import { ValueHelpSourceOptions } from "./source.mjs";
3
+ import { ClientLike, FilterExpr, PageResult } from "@atscript/db-client";
3
4
 
4
5
  //#region src/value-help/distinct-client.d.ts
5
- interface DistinctValuesOptions {
6
- /** Search text: a case-insensitive prefix match for strings, an exact match for numbers. */
7
- text?: string;
8
- /** Page size. Default: 50. */
9
- limit?: number;
10
- /**
11
- * Rows to skip (the next page of a scrolled picker). Distinct values are only
12
- * stable across pages when ordered, so a caller pages only with `sortable`.
13
- */
14
- skip?: number;
15
- /** Send `$sort` on the grouped field — only when the server lists it as sortable. */
16
- sortable?: boolean;
17
- /**
18
- * The field's storage kind. A numeric one ({@link NUMERIC_VALUE_KINDS}) is
19
- * searched by exact value — text that is no value of it finds nothing; a
20
- * `decimal` / `long` value is sent as text (since 0.1.205; before, a
21
- * `numeric` flag and a JS number).
22
- */
23
- valueKind?: ColumnValueKind;
24
- /** Extra scope AND'd into the query (e.g. the table's `forceFilters`). */
25
- filter?: FilterExpr;
26
- }
6
+ type Row = Record<string, unknown>;
27
7
  /**
28
8
  * `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
29
9
  * @internal Shared with `@atscript/vue-table`.
30
10
  */
31
11
  declare function isPickerDeclined(err: unknown): boolean;
32
12
  /**
33
- * Distinct values of one column of the table behind `client`, via
34
- * `/query?$groupBy=<field>`. All server gates (hidden field, ARBAC `$groupBy`
35
- * control, row scope, write-only, encrypted) apply as for any grouped read; a
36
- * 4xx rejects with a `ClientError` — see {@link isPickerDeclined}.
37
- * `hasMore` tells whether another page follows.
38
- *
39
- * @internal Backs the distinct-values picker of `@atscript/vue-table`.
13
+ * `(searchTerm, page, size)` → one page of a column's distinct values as
14
+ * picker rows — `__value` (the value) and `__label` (its text) — sized for a
15
+ * window: `count` is one past the values loaded so far while more follow
16
+ * (see {@link createDistinctPager}).
17
+ */
18
+ type DistinctPager = (searchTerm: string, page: number, size: number) => Promise<PageResult<Row>>;
19
+ interface DistinctPagerOptions extends ValueHelpSourceOptions {
20
+ /**
21
+ * The table's scope, read at every request (its `forceFilters`): the values
22
+ * narrow like the rows, so a picker never offers one the table cannot show.
23
+ */
24
+ scope?: () => FilterExpr | undefined;
25
+ }
26
+ /**
27
+ * The pager over the distinct values of `column.distinct`
28
+ * (`@ui.valueHelp.distinct`; since 0.1.208): each page is a
29
+ * {@link fetchDistinctValues} on the table's controller, in the current scope
30
+ * (`opts.scope`). Values are ordered, and so paged, only on a sortable column;
31
+ * otherwise the first `size` values are the whole list (a later page is
32
+ * empty) and a search narrows it. A 4xx rejects. The unsearched first page
33
+ * is reused for 30 s per page size and scope, so every picker sharing this
34
+ * pager asks once — until the data drops (`invalidateValueHelpCache`, which
35
+ * a table action or delete runs); a failure is not kept. Each request asks
36
+ * in the current locale of `opts.texts` through that locale's `/meta` entry,
37
+ * built with `opts.clientFactory` (the table's).
40
38
  */
41
- declare function fetchDistinctValues(client: Pick<ClientLike, "aggregate">, field: string, opts?: DistinctValuesOptions): Promise<{
42
- items: unknown[];
43
- hasMore: boolean;
44
- }>;
39
+ declare function createDistinctPager(column: Pick<ColumnDef, "distinct" | "sortable" | "valueKind">, opts?: DistinctPagerOptions): DistinctPager;
45
40
  //#endregion
46
- export { fetchDistinctValues, isPickerDeclined };
41
+ export { DistinctPager, DistinctPagerOptions, createDistinctPager, isPickerDeclined };
@@ -1,6 +1,10 @@
1
1
  import { getByPath } from "../form/path-utils.mjs";
2
+ import { mergeFilters } from "../shared/merge-filters.mjs";
2
3
  import { escapeRegex } from "../shared/str.mjs";
3
4
  import { NUMERIC_VALUE_KINDS, coerceNumericText } from "../table/value-kind.mjs";
5
+ import { clientStore } from "./client-store.mjs";
6
+ import { getMetaEntry } from "../shared/meta-cache.mjs";
7
+ import { stableValueKey } from "../shared/stable-key.mjs";
4
8
  //#region src/value-help/distinct-client.ts
5
9
  /**
6
10
  * `true` for a 4xx answer — the server declined this picker (gate, ARBAC, unknown field).
@@ -17,22 +21,21 @@ function isPickerDeclined(err) {
17
21
  * 4xx rejects with a `ClientError` — see {@link isPickerDeclined}.
18
22
  * `hasMore` tells whether another page follows.
19
23
  *
20
- * @internal Backs the distinct-values picker of `@atscript/vue-table`.
24
+ * @internal Backs {@link createDistinctPager}.
21
25
  */
22
26
  async function fetchDistinctValues(client, field, opts = {}) {
23
27
  const limit = opts.limit ?? 50;
24
28
  const text = opts.text?.trim();
25
- const conditions = [];
26
- if (opts.filter) conditions.push(opts.filter);
29
+ let search;
27
30
  if (text) if (opts.valueKind && NUMERIC_VALUE_KINDS.has(opts.valueKind)) {
28
31
  const value = coerceNumericText(text, opts.valueKind);
29
32
  if (value === void 0) return {
30
33
  items: [],
31
34
  hasMore: false
32
35
  };
33
- conditions.push({ [field]: value });
34
- } else conditions.push({ [field]: { $regex: `/^${escapeRegex(text)}/i` } });
35
- const filter = conditions.length > 1 ? { $and: conditions } : conditions[0];
36
+ search = { [field]: value };
37
+ } else search = { [field]: { $regex: `/^${escapeRegex(text)}/i` } };
38
+ const filter = mergeFilters(opts.filter, search);
36
39
  const rows = await client.aggregate({
37
40
  ...filter && { filter },
38
41
  controls: {
@@ -48,5 +51,75 @@ async function fetchDistinctValues(client, field, opts = {}) {
48
51
  hasMore: rows.length > limit
49
52
  };
50
53
  }
54
+ /** How long an unsearched first page is reused. */
55
+ const PAGE1_TTL_MS = 3e4;
56
+ /**
57
+ * The pager over the distinct values of `column.distinct`
58
+ * (`@ui.valueHelp.distinct`; since 0.1.208): each page is a
59
+ * {@link fetchDistinctValues} on the table's controller, in the current scope
60
+ * (`opts.scope`). Values are ordered, and so paged, only on a sortable column;
61
+ * otherwise the first `size` values are the whole list (a later page is
62
+ * empty) and a search narrows it. A 4xx rejects. The unsearched first page
63
+ * is reused for 30 s per page size and scope, so every picker sharing this
64
+ * pager asks once — until the data drops (`invalidateValueHelpCache`, which
65
+ * a table action or delete runs); a failure is not kept. Each request asks
66
+ * in the current locale of `opts.texts` through that locale's `/meta` entry,
67
+ * built with `opts.clientFactory` (the table's).
68
+ */
69
+ function createDistinctPager(column, opts = {}) {
70
+ const { url, field } = column.distinct;
71
+ const paged = column.sortable;
72
+ const page1 = /* @__PURE__ */ new Map();
73
+ return async (searchTerm, page, size) => {
74
+ const text = searchTerm.trim();
75
+ const skip = paged ? (page - 1) * size : 0;
76
+ const scope = opts.scope?.();
77
+ const client = getMetaEntry(url, opts.clientFactory, { texts: opts.texts }).client;
78
+ const load = () => fetchDistinctValues(client, field, {
79
+ text,
80
+ limit: size,
81
+ skip,
82
+ sortable: paged,
83
+ valueKind: column.valueKind,
84
+ filter: scope
85
+ });
86
+ let result;
87
+ if (!paged && page > 1) result = {
88
+ items: [],
89
+ hasMore: false
90
+ };
91
+ else if (text || page > 1) result = await load();
92
+ else {
93
+ const key = `${size}\0${scope ? stableValueKey(scope) : ""}`;
94
+ const store = clientStore(client);
95
+ const at = Date.now();
96
+ for (const [k, old] of page1) if (at - old.at > PAGE1_TTL_MS) page1.delete(k);
97
+ let hit = page1.get(key);
98
+ if (hit?.store !== store) {
99
+ const entry = {
100
+ at,
101
+ store,
102
+ result: load()
103
+ };
104
+ entry.result.catch(() => page1.get(key) === entry && page1.delete(key));
105
+ page1.set(key, entry);
106
+ hit = entry;
107
+ }
108
+ result = await hit.result;
109
+ }
110
+ const hasMore = paged && result.hasMore;
111
+ const count = skip + result.items.length + (hasMore ? 1 : 0);
112
+ return {
113
+ data: result.items.map((v) => ({
114
+ __value: v,
115
+ __label: String(v)
116
+ })),
117
+ count,
118
+ page,
119
+ itemsPerPage: size,
120
+ pages: Math.max(1, Math.ceil(count / size))
121
+ };
122
+ };
123
+ }
51
124
  //#endregion
52
- export { fetchDistinctValues, isPickerDeclined };
125
+ export { createDistinctPager, isPickerDeclined };
@@ -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 — on the prop itself only
53
- * (`own`) — its `@ui.valueHelp.fill` list to `info` (since 0.1.190). A link
54
- * reached through a reference names fields of ANOTHER interface, so its fills
55
- * stay there; its columns name the target, so they come along.
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 — on the prop itself only
53
- * (`own`) — its `@ui.valueHelp.fill` list to `info` (since 0.1.190). A link
54
- * reached through a reference names fields of ANOTHER interface, so its fills
55
- * stay there; its columns name the target, so they come along.
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, ValuePickerMode, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText, valuePickerMode } from "./options.mjs";
11
+ import { DistinctPager, DistinctPagerOptions, createDistinctPager, 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,8 @@
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_extract_ref = require("./extract-ref.cjs");
5
+ const require_value_label = require("../shared/value-label.cjs");
1
6
  //#region src/value-help/options.ts
2
7
  /**
3
8
  * Values a dropdown lists from a dictionary (`@ui.form.type 'select'` /
@@ -7,24 +12,81 @@
7
12
  */
8
13
  const VALUE_HELP_OPTIONS_CAP = 200;
9
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
+ function valueHelpRowText(resolved, row) {
21
+ return {
22
+ label: require_value_label.codeOf(row[resolved.labelField]),
23
+ descr: resolved.descrField ? require_value_label.codeOf(row[resolved.descrField]) : void 0
24
+ };
25
+ }
26
+ /**
10
27
  * 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.
28
+ * `targetField` value as the option's value, the row's text
29
+ * (`valueHelpRowText`; the key when it has none) and the description after a
30
+ * dash.
13
31
  */
14
32
  function valueHelpOptions(rows, resolved, info) {
15
33
  return rows.map((row) => {
16
34
  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);
35
+ const { label, descr } = valueHelpRowText(resolved, row);
36
+ const text = label ?? String(value);
21
37
  return {
22
- key,
23
- label: descr ? `${text} — ${String(descr)}` : text,
38
+ key: String(value),
39
+ label: descr ? `${text} — ${descr}` : text,
24
40
  value
25
41
  };
26
42
  });
27
43
  }
44
+ /**
45
+ * The options of a dropdown that lists its dictionary (`listsDictionary`;
46
+ * since 0.1.207) from a read of `VALUE_HELP_OPTIONS_CAP + 1` rows in the
47
+ * binding's scope (`ValueHelpSource.search`, in a form with the host values):
48
+ * the rows as options (`valueHelpOptions`), or `undefined` when there are more
49
+ * than the cap — the field then keeps its search picker.
50
+ */
51
+ function valueHelpDropdown(rows, resolved, info) {
52
+ return rows.length > 200 ? void 0 : valueHelpOptions(rows, resolved, info);
53
+ }
54
+ /**
55
+ * Whether a form field or a column lists its dictionary's values as its
56
+ * options (since 0.1.207): bound to a dictionary (`valueHelpInfo`), typed
57
+ * `select` or `radio`, and with no options of its own — a form field none
58
+ * declared on its `prop` (`@ui.form.options`, `@ui.form.fn.options`, a
59
+ * literal union), a column none in `options`.
60
+ */
61
+ function listsDictionary(holder) {
62
+ if (!holder.valueHelpInfo || holder.type !== "select" && holder.type !== "radio") return false;
63
+ const prop = holder.prop;
64
+ if (!prop) return !holder.options?.length;
65
+ 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;
66
+ }
67
+ /**
68
+ * The picker a column's value filter offers (since 0.1.208) — the one rule of
69
+ * the inline filter field, the filter dialog and a custom filter:
70
+ * `"dictionary"` (a `@ui.valueHelp` binding or a foreign key, unless its
71
+ * {@link valueHelpKey} is in `declined` — the server answered 4xx), else
72
+ * `"options"` (a literal union, a boolean's Yes / No, a dictionary's values
73
+ * loaded as options), else `"distinct"` (`@ui.valueHelp.distinct`);
74
+ * `undefined` — no picker: the column takes typed conditions. Only a column
75
+ * the server filters by value with `$eq` (what a pick sends; several picks are
76
+ * an `$or` of them) has one: an existence-only (JSON-stored) column takes the
77
+ * empty / not-empty conditions instead.
78
+ */
79
+ function valuePickerMode(column, declined) {
80
+ if (!column.filterable || column.filterOps && !column.filterOps.includes("$eq")) return;
81
+ const info = column.valueHelpInfo;
82
+ if (info && !declined?.has(require_extract_ref.valueHelpKey(info))) return "dictionary";
83
+ if (column.options?.length) return "options";
84
+ if (column.distinct) return "distinct";
85
+ }
28
86
  //#endregion
29
87
  exports.VALUE_HELP_OPTIONS_CAP = VALUE_HELP_OPTIONS_CAP;
88
+ exports.listsDictionary = listsDictionary;
89
+ exports.valueHelpDropdown = valueHelpDropdown;
30
90
  exports.valueHelpOptions = valueHelpOptions;
91
+ exports.valueHelpRowText = valueHelpRowText;
92
+ exports.valuePickerMode = valuePickerMode;