@atscript/ui 0.1.207 → 0.1.208
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/form/create-form-def.cjs +13 -12
- package/dist/form/create-form-def.mjs +14 -13
- package/dist/form/decimal-format.cjs +8 -3
- package/dist/form/decimal-format.d.cts +8 -2
- package/dist/form/decimal-format.d.mts +8 -2
- package/dist/form/decimal-format.mjs +8 -3
- package/dist/form/form-actions.cjs +9 -0
- package/dist/form/form-actions.d.cts +7 -1
- package/dist/form/form-actions.d.mts +7 -1
- package/dist/form/form-actions.mjs +9 -1
- package/dist/form/measurement.cjs +58 -0
- package/dist/form/measurement.d.cts +36 -1
- package/dist/form/measurement.d.mts +36 -1
- package/dist/form/measurement.mjs +57 -2
- package/dist/form/omit-derived.cjs +11 -0
- package/dist/form/omit-derived.d.cts +8 -1
- package/dist/form/omit-derived.d.mts +8 -1
- package/dist/form/omit-derived.mjs +11 -1
- package/dist/form/optional-mode.cjs +7 -7
- package/dist/form/optional-mode.d.cts +2 -1
- package/dist/form/optional-mode.d.mts +2 -1
- package/dist/form/optional-mode.mjs +8 -8
- package/dist/form/types.cjs +5 -0
- package/dist/form/types.d.cts +14 -0
- package/dist/form/types.d.mts +14 -0
- package/dist/form/types.mjs +5 -1
- package/dist/form/validate.cjs +56 -5
- package/dist/form/validate.d.cts +30 -2
- package/dist/form/validate.d.mts +30 -2
- package/dist/form/validate.mjs +56 -6
- package/dist/index.cjs +24 -3
- package/dist/index.d.cts +14 -9
- package/dist/index.d.mts +14 -9
- package/dist/index.mjs +15 -10
- package/dist/plugin/annotations.cjs +1 -1
- package/dist/plugin/annotations.mjs +1 -1
- package/dist/shared/annotation-keys.d.cts +2 -1
- package/dist/shared/annotation-keys.d.mts +2 -1
- package/dist/shared/dev.cjs +22 -0
- package/dist/shared/dev.d.cts +4 -0
- package/dist/shared/dev.d.mts +4 -0
- package/dist/shared/dev.mjs +22 -0
- package/dist/shared/field-resolver.cjs +21 -1
- package/dist/shared/field-resolver.d.cts +15 -1
- package/dist/shared/field-resolver.d.mts +15 -1
- package/dist/shared/field-resolver.mjs +20 -2
- package/dist/shared/merge-filters.cjs +28 -0
- package/dist/shared/merge-filters.d.cts +13 -0
- package/dist/shared/merge-filters.d.mts +13 -0
- package/dist/shared/merge-filters.mjs +28 -0
- package/dist/shared/resolve-component.cjs +27 -0
- package/dist/shared/resolve-component.d.cts +22 -0
- package/dist/shared/resolve-component.d.mts +22 -0
- package/dist/shared/resolve-component.mjs +27 -0
- package/dist/shared/stable-key.cjs +28 -0
- package/dist/shared/stable-key.d.cts +13 -0
- package/dist/shared/stable-key.d.mts +13 -0
- package/dist/shared/stable-key.mjs +28 -0
- package/dist/shared/to-date.cjs +65 -0
- package/dist/shared/to-date.d.cts +35 -0
- package/dist/shared/to-date.d.mts +35 -0
- package/dist/shared/to-date.mjs +64 -0
- package/dist/table/create-table-def.cjs +49 -15
- package/dist/table/create-table-def.mjs +49 -16
- package/dist/table/types.d.cts +15 -13
- package/dist/table/types.d.mts +15 -13
- package/dist/value-help/distinct-client.cjs +80 -7
- package/dist/value-help/distinct-client.d.cts +31 -36
- package/dist/value-help/distinct-client.d.mts +31 -36
- package/dist/value-help/distinct-client.mjs +80 -7
- package/dist/value-help/index.d.mts +2 -2
- package/dist/value-help/options.cjs +21 -0
- package/dist/value-help/options.d.cts +17 -1
- package/dist/value-help/options.d.mts +17 -1
- package/dist/value-help/options.mjs +21 -1
- package/dist/value-help/resolve.cjs +2 -12
- package/dist/value-help/resolve.mjs +3 -13
- package/dist/value-help/scope.cjs +3 -7
- package/dist/value-help/scope.mjs +3 -7
- package/dist/value-help/texts.cjs +7 -4
- package/dist/value-help/texts.mjs +7 -4
- package/dist/value-help/value-help-client.cjs +5 -3
- package/dist/value-help/value-help-client.d.cts +3 -2
- package/dist/value-help/value-help-client.d.mts +3 -2
- package/dist/value-help/value-help-client.mjs +5 -3
- package/package.json +10 -10
package/dist/table/types.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ValueLabelArrangement } from "../shared/value-label.cjs";
|
|
1
|
+
import { ValueLabel, ValueLabelArrangement } from "../shared/value-label.cjs";
|
|
2
2
|
import { ValueHelpInfo } from "../value-help/types.cjs";
|
|
3
|
+
import { MeasurementInfo } from "../form/measurement.cjs";
|
|
3
4
|
import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
|
|
4
5
|
import { TCrudPermissions, TDbActionInfo } from "@atscript/db-client";
|
|
5
6
|
|
|
@@ -165,6 +166,13 @@ interface TableDef {
|
|
|
165
166
|
identifierFields?: string[];
|
|
166
167
|
/** Server-managed OCC column name — see `MetaResponse.versionColumn`. */
|
|
167
168
|
versionColumn?: string;
|
|
169
|
+
/**
|
|
170
|
+
* The label of the table's own rows: the field its type's `@ui.dict.label`
|
|
171
|
+
* marks — one the caller can read — with its arrangement (default
|
|
172
|
+
* `textKey`). `undefined` without one. An action dialog names a row by it
|
|
173
|
+
* (`Dune (3f2a…)`). Since 0.1.208.
|
|
174
|
+
*/
|
|
175
|
+
label?: ValueLabel;
|
|
168
176
|
/** Per-op CRUD permissions advertised in `/meta`. Key absent → denied. */
|
|
169
177
|
crud: TCrudPermissions;
|
|
170
178
|
canRemove: boolean;
|
|
@@ -183,8 +191,12 @@ interface TableDef {
|
|
|
183
191
|
* Since 0.1.148.
|
|
184
192
|
*/
|
|
185
193
|
type ColumnValueKind = "string" | "date" | "isoDate" | "number" | "integer" | "decimal" | "long" | "timestamp" | "boolean";
|
|
186
|
-
/**
|
|
187
|
-
|
|
194
|
+
/**
|
|
195
|
+
* A single column definition — built from field metadata + annotations; its
|
|
196
|
+
* currency / unit / precision fields are the `MeasurementInfo` of
|
|
197
|
+
* `extractMeasurement`.
|
|
198
|
+
*/
|
|
199
|
+
interface ColumnDef extends MeasurementInfo {
|
|
188
200
|
/** Field path in dot-notation (e.g. 'address.city'). */
|
|
189
201
|
path: string;
|
|
190
202
|
/** Display label — from @meta.label or humanized path. */
|
|
@@ -275,16 +287,6 @@ interface ColumnDef {
|
|
|
275
287
|
url: string;
|
|
276
288
|
field: string;
|
|
277
289
|
};
|
|
278
|
-
/** Literal currency code from `@db.amount.currency 'EUR'`. */
|
|
279
|
-
currencyCode?: string;
|
|
280
|
-
/** Sibling field path from `@db.amount.currency.ref 'fieldName'`. */
|
|
281
|
-
currencyRefField?: string;
|
|
282
|
-
/** Literal unit-of-measure from `@db.unit 'kg'`. */
|
|
283
|
-
unitCode?: string;
|
|
284
|
-
/** Sibling field path from `@db.unit.ref 'fieldName'`. */
|
|
285
|
-
unitRefField?: string;
|
|
286
|
-
/** Decimal scale (fraction digits) — second arg of `@db.column.precision precision, scale`. */
|
|
287
|
-
precisionScale?: number;
|
|
288
290
|
/**
|
|
289
291
|
* Synthesised, locked-chrome column. When `true`: header-cell column-menu
|
|
290
292
|
* skipped, resize handle skipped, drag-reorder excluded, NOT in the
|
package/dist/table/types.d.mts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { ValueLabelArrangement } from "../shared/value-label.mjs";
|
|
1
|
+
import { ValueLabel, ValueLabelArrangement } from "../shared/value-label.mjs";
|
|
2
2
|
import { ValueHelpInfo } from "../value-help/types.mjs";
|
|
3
|
+
import { MeasurementInfo } from "../form/measurement.mjs";
|
|
3
4
|
import { TAtscriptAnnotatedType, TSerializedAnnotatedType } from "@atscript/typescript/utils";
|
|
4
5
|
import { TCrudPermissions, TDbActionInfo } from "@atscript/db-client";
|
|
5
6
|
|
|
@@ -165,6 +166,13 @@ interface TableDef {
|
|
|
165
166
|
identifierFields?: string[];
|
|
166
167
|
/** Server-managed OCC column name — see `MetaResponse.versionColumn`. */
|
|
167
168
|
versionColumn?: string;
|
|
169
|
+
/**
|
|
170
|
+
* The label of the table's own rows: the field its type's `@ui.dict.label`
|
|
171
|
+
* marks — one the caller can read — with its arrangement (default
|
|
172
|
+
* `textKey`). `undefined` without one. An action dialog names a row by it
|
|
173
|
+
* (`Dune (3f2a…)`). Since 0.1.208.
|
|
174
|
+
*/
|
|
175
|
+
label?: ValueLabel;
|
|
168
176
|
/** Per-op CRUD permissions advertised in `/meta`. Key absent → denied. */
|
|
169
177
|
crud: TCrudPermissions;
|
|
170
178
|
canRemove: boolean;
|
|
@@ -183,8 +191,12 @@ interface TableDef {
|
|
|
183
191
|
* Since 0.1.148.
|
|
184
192
|
*/
|
|
185
193
|
type ColumnValueKind = "string" | "date" | "isoDate" | "number" | "integer" | "decimal" | "long" | "timestamp" | "boolean";
|
|
186
|
-
/**
|
|
187
|
-
|
|
194
|
+
/**
|
|
195
|
+
* A single column definition — built from field metadata + annotations; its
|
|
196
|
+
* currency / unit / precision fields are the `MeasurementInfo` of
|
|
197
|
+
* `extractMeasurement`.
|
|
198
|
+
*/
|
|
199
|
+
interface ColumnDef extends MeasurementInfo {
|
|
188
200
|
/** Field path in dot-notation (e.g. 'address.city'). */
|
|
189
201
|
path: string;
|
|
190
202
|
/** Display label — from @meta.label or humanized path. */
|
|
@@ -275,16 +287,6 @@ interface ColumnDef {
|
|
|
275
287
|
url: string;
|
|
276
288
|
field: string;
|
|
277
289
|
};
|
|
278
|
-
/** Literal currency code from `@db.amount.currency 'EUR'`. */
|
|
279
|
-
currencyCode?: string;
|
|
280
|
-
/** Sibling field path from `@db.amount.currency.ref 'fieldName'`. */
|
|
281
|
-
currencyRefField?: string;
|
|
282
|
-
/** Literal unit-of-measure from `@db.unit 'kg'`. */
|
|
283
|
-
unitCode?: string;
|
|
284
|
-
/** Sibling field path from `@db.unit.ref 'fieldName'`. */
|
|
285
|
-
unitRefField?: string;
|
|
286
|
-
/** Decimal scale (fraction digits) — second arg of `@db.column.precision precision, scale`. */
|
|
287
|
-
precisionScale?: number;
|
|
288
290
|
/**
|
|
289
291
|
* Synthesised, locked-chrome column. When `true`: header-cell column-menu
|
|
290
292
|
* skipped, resize handle skipped, drag-reorder excluded, NOT in the
|
|
@@ -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
|
|
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
|
-
|
|
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
|
-
|
|
34
|
-
} else
|
|
35
|
-
const filter =
|
|
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.
|
|
125
|
+
exports.createDistinctPager = createDistinctPager;
|
|
53
126
|
exports.isPickerDeclined = isPickerDeclined;
|
|
@@ -1,46 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
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 {
|
|
41
|
+
export { DistinctPager, DistinctPagerOptions, createDistinctPager, isPickerDeclined };
|
|
@@ -1,46 +1,41 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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
|
-
|
|
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
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
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 {
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
34
|
-
} else
|
|
35
|
-
const filter =
|
|
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 {
|
|
125
|
+
export { createDistinctPager, isPickerDeclined };
|
|
@@ -7,7 +7,7 @@ import { DEFAULT_BOOLEAN_LABELS, extractFieldLiteralOptions, extractLiteralOptio
|
|
|
7
7
|
import { extractValueHelp, valueHelpKey } from "./extract-ref.mjs";
|
|
8
8
|
import { optKey, optLabel, optionLabel, parseStaticOptions, resolveOptions } from "./resolve-options.mjs";
|
|
9
9
|
import { ValueHelpFillWrite, ValueHelpScope, valueHelpFills, valueHelpScope } from "./scope.mjs";
|
|
10
|
-
import { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText } from "./options.mjs";
|
|
11
|
-
import {
|
|
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
12
|
import { ValueHelpTextOptions, loadValueHelpTexts, onValueHelpTexts, valueHelpText } from "./texts.mjs";
|
|
13
13
|
import { DisplayValueOptions, displayValue } from "./display-value.mjs";
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require("../shared/annotation-keys.cjs");
|
|
2
2
|
const require_field_resolver = require("../shared/field-resolver.cjs");
|
|
3
3
|
const require_extract_literals = require("./extract-literals.cjs");
|
|
4
|
+
const require_extract_ref = require("./extract-ref.cjs");
|
|
4
5
|
const require_value_label = require("../shared/value-label.cjs");
|
|
5
6
|
//#region src/value-help/options.ts
|
|
6
7
|
/**
|
|
@@ -63,9 +64,29 @@ function listsDictionary(holder) {
|
|
|
63
64
|
if (!prop) return !holder.options?.length;
|
|
64
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;
|
|
65
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
|
+
}
|
|
66
86
|
//#endregion
|
|
67
87
|
exports.VALUE_HELP_OPTIONS_CAP = VALUE_HELP_OPTIONS_CAP;
|
|
68
88
|
exports.listsDictionary = listsDictionary;
|
|
69
89
|
exports.valueHelpDropdown = valueHelpDropdown;
|
|
70
90
|
exports.valueHelpOptions = valueHelpOptions;
|
|
71
91
|
exports.valueHelpRowText = valueHelpRowText;
|
|
92
|
+
exports.valuePickerMode = valuePickerMode;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TFormEntryOptions, ValueHelpInfo } from "./types.cjs";
|
|
2
|
+
import { ColumnDef } from "../table/types.cjs";
|
|
2
3
|
import { ResolvedValueHelp } from "./resolve.cjs";
|
|
3
4
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
4
5
|
|
|
@@ -52,5 +53,20 @@ declare function listsDictionary(holder: {
|
|
|
52
53
|
prop?: TAtscriptAnnotatedType;
|
|
53
54
|
options?: readonly unknown[];
|
|
54
55
|
}): boolean;
|
|
56
|
+
/** The picker a column's value filter offers — see {@link valuePickerMode}. */
|
|
57
|
+
type ValuePickerMode = "dictionary" | "options" | "distinct";
|
|
58
|
+
/**
|
|
59
|
+
* The picker a column's value filter offers (since 0.1.208) — the one rule of
|
|
60
|
+
* the inline filter field, the filter dialog and a custom filter:
|
|
61
|
+
* `"dictionary"` (a `@ui.valueHelp` binding or a foreign key, unless its
|
|
62
|
+
* {@link valueHelpKey} is in `declined` — the server answered 4xx), else
|
|
63
|
+
* `"options"` (a literal union, a boolean's Yes / No, a dictionary's values
|
|
64
|
+
* loaded as options), else `"distinct"` (`@ui.valueHelp.distinct`);
|
|
65
|
+
* `undefined` — no picker: the column takes typed conditions. Only a column
|
|
66
|
+
* the server filters by value with `$eq` (what a pick sends; several picks are
|
|
67
|
+
* an `$or` of them) has one: an existence-only (JSON-stored) column takes the
|
|
68
|
+
* empty / not-empty conditions instead.
|
|
69
|
+
*/
|
|
70
|
+
declare function valuePickerMode(column: Pick<ColumnDef, "filterable" | "filterOps" | "valueHelpInfo" | "options" | "distinct">, declined?: ReadonlySet<string>): ValuePickerMode | undefined;
|
|
55
71
|
//#endregion
|
|
56
|
-
export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText };
|
|
72
|
+
export { VALUE_HELP_OPTIONS_CAP, ValuePickerMode, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText, valuePickerMode };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { TFormEntryOptions, ValueHelpInfo } from "./types.mjs";
|
|
2
|
+
import { ColumnDef } from "../table/types.mjs";
|
|
2
3
|
import { ResolvedValueHelp } from "./resolve.mjs";
|
|
3
4
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
4
5
|
|
|
@@ -52,5 +53,20 @@ declare function listsDictionary(holder: {
|
|
|
52
53
|
prop?: TAtscriptAnnotatedType;
|
|
53
54
|
options?: readonly unknown[];
|
|
54
55
|
}): boolean;
|
|
56
|
+
/** The picker a column's value filter offers — see {@link valuePickerMode}. */
|
|
57
|
+
type ValuePickerMode = "dictionary" | "options" | "distinct";
|
|
58
|
+
/**
|
|
59
|
+
* The picker a column's value filter offers (since 0.1.208) — the one rule of
|
|
60
|
+
* the inline filter field, the filter dialog and a custom filter:
|
|
61
|
+
* `"dictionary"` (a `@ui.valueHelp` binding or a foreign key, unless its
|
|
62
|
+
* {@link valueHelpKey} is in `declined` — the server answered 4xx), else
|
|
63
|
+
* `"options"` (a literal union, a boolean's Yes / No, a dictionary's values
|
|
64
|
+
* loaded as options), else `"distinct"` (`@ui.valueHelp.distinct`);
|
|
65
|
+
* `undefined` — no picker: the column takes typed conditions. Only a column
|
|
66
|
+
* the server filters by value with `$eq` (what a pick sends; several picks are
|
|
67
|
+
* an `$or` of them) has one: an existence-only (JSON-stored) column takes the
|
|
68
|
+
* empty / not-empty conditions instead.
|
|
69
|
+
*/
|
|
70
|
+
declare function valuePickerMode(column: Pick<ColumnDef, "filterable" | "filterOps" | "valueHelpInfo" | "options" | "distinct">, declined?: ReadonlySet<string>): ValuePickerMode | undefined;
|
|
55
71
|
//#endregion
|
|
56
|
-
export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText };
|
|
72
|
+
export { VALUE_HELP_OPTIONS_CAP, ValuePickerMode, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText, valuePickerMode };
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import "../shared/annotation-keys.mjs";
|
|
2
2
|
import { hasFieldMeta } from "../shared/field-resolver.mjs";
|
|
3
3
|
import { extractFieldLiteralOptions } from "./extract-literals.mjs";
|
|
4
|
+
import { valueHelpKey } from "./extract-ref.mjs";
|
|
4
5
|
import { codeOf } from "../shared/value-label.mjs";
|
|
5
6
|
//#region src/value-help/options.ts
|
|
6
7
|
/**
|
|
@@ -63,5 +64,24 @@ function listsDictionary(holder) {
|
|
|
63
64
|
if (!prop) return !holder.options?.length;
|
|
64
65
|
return !hasFieldMeta(prop, "ui.form.options") && !hasFieldMeta(prop, "ui.form.fn.options") && extractFieldLiteralOptions(prop) === void 0;
|
|
65
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(valueHelpKey(info))) return "dictionary";
|
|
83
|
+
if (column.options?.length) return "options";
|
|
84
|
+
if (column.distinct) return "distinct";
|
|
85
|
+
}
|
|
66
86
|
//#endregion
|
|
67
|
-
export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText };
|
|
87
|
+
export { VALUE_HELP_OPTIONS_CAP, listsDictionary, valueHelpDropdown, valueHelpOptions, valueHelpRowText, valuePickerMode };
|