@atscript/ui 0.1.164 → 0.1.165
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/client-factory.d.cts +6 -1
- package/dist/client-factory.d.mts +6 -1
- package/dist/form/create-form-def.cjs +28 -6
- package/dist/form/create-form-def.mjs +29 -7
- package/dist/form/labels.cjs +7 -4
- package/dist/form/labels.d.cts +6 -2
- package/dist/form/labels.d.mts +6 -2
- package/dist/form/labels.mjs +7 -4
- package/dist/form/types.d.cts +14 -0
- package/dist/form/types.d.mts +14 -0
- package/dist/form/validate.cjs +59 -23
- package/dist/form/validate.d.cts +37 -6
- package/dist/form/validate.d.mts +37 -6
- package/dist/form/validate.mjs +58 -23
- package/dist/i18n/ui-texts.cjs +135 -0
- package/dist/i18n/ui-texts.d.cts +81 -0
- package/dist/i18n/ui-texts.d.mts +81 -0
- package/dist/i18n/ui-texts.mjs +132 -0
- package/dist/index.cjs +6 -0
- package/dist/index.d.cts +7 -6
- package/dist/index.d.mts +7 -6
- package/dist/index.mjs +3 -2
- package/dist/messages.cjs +301 -0
- package/dist/messages.d.cts +302 -0
- package/dist/messages.d.mts +302 -0
- package/dist/messages.mjs +300 -0
- package/dist/plugin/annotations.cjs +30 -15
- package/dist/plugin/annotations.mjs +30 -15
- package/dist/plugin/value-help-validation.cjs +17 -7
- package/dist/plugin/value-help-validation.mjs +17 -7
- package/dist/shared/meta-cache.cjs +75 -37
- package/dist/shared/meta-cache.d.cts +40 -20
- package/dist/shared/meta-cache.d.mts +40 -20
- package/dist/shared/meta-cache.mjs +75 -37
- package/dist/table/create-table-def.cjs +17 -8
- package/dist/table/create-table-def.d.cts +5 -1
- package/dist/table/create-table-def.d.mts +5 -1
- package/dist/table/create-table-def.mjs +18 -9
- package/dist/table/types.d.cts +5 -2
- package/dist/table/types.d.mts +5 -2
- package/dist/table/value-kind.cjs +6 -6
- package/dist/table/value-kind.d.cts +8 -7
- package/dist/table/value-kind.d.mts +8 -7
- package/dist/table/value-kind.mjs +6 -6
- package/dist/value-help/extract-literals.cjs +61 -22
- package/dist/value-help/extract-literals.d.cts +20 -8
- package/dist/value-help/extract-literals.d.mts +20 -8
- package/dist/value-help/extract-literals.mjs +60 -23
- package/dist/value-help/index.d.mts +1 -1
- package/dist/value-help/resolve-options.cjs +8 -4
- package/dist/value-help/resolve-options.d.cts +8 -3
- package/dist/value-help/resolve-options.d.mts +8 -3
- package/dist/value-help/resolve-options.mjs +9 -5
- package/dist/value-help/resolve.cjs +7 -3
- package/dist/value-help/resolve.d.cts +7 -2
- package/dist/value-help/resolve.d.mts +7 -2
- package/dist/value-help/resolve.mjs +7 -3
- package/dist/value-help/types.d.cts +5 -0
- package/dist/value-help/types.d.mts +5 -0
- package/package.json +15 -10
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { getUiTexts } from "../i18n/ui-texts.mjs";
|
|
1
2
|
import { invalidateValueHelpCache } from "../value-help/value-help-client.mjs";
|
|
2
3
|
import { getDefaultClientFactory } from "../client-factory.mjs";
|
|
3
4
|
import { createTableDef } from "../table/create-table-def.mjs";
|
|
@@ -13,7 +14,7 @@ import { clearMetaStore, defaultMetaStore } from "@atscript/db-client";
|
|
|
13
14
|
*/
|
|
14
15
|
const DEFAULT_MAX_ENTRIES = 100;
|
|
15
16
|
let maxEntries = DEFAULT_MAX_ENTRIES;
|
|
16
|
-
/**
|
|
17
|
+
/** Entries by {@link cacheKey}, least recently used first. Browser only. */
|
|
17
18
|
const cache = /* @__PURE__ */ new Map();
|
|
18
19
|
const slots = /* @__PURE__ */ new WeakMap();
|
|
19
20
|
/** Derived shapes per `ETag`, counted by the cached entries that use them. Browser only. */
|
|
@@ -23,28 +24,37 @@ const customStores = /* @__PURE__ */ new Map();
|
|
|
23
24
|
/** `undefined` until the first `setMetaCacheIdentity` call; `null` = anonymous. */
|
|
24
25
|
let identity;
|
|
25
26
|
const resetListeners = /* @__PURE__ */ new Set();
|
|
27
|
+
/** The cache key of `url` in `locale`. */
|
|
28
|
+
function cacheKey(url, locale) {
|
|
29
|
+
return locale === void 0 ? url : `${url}\n${locale}`;
|
|
30
|
+
}
|
|
26
31
|
/**
|
|
27
|
-
* Get or create the cache entry for `url
|
|
28
|
-
* `options.
|
|
29
|
-
* `meta` rejection, the entry is
|
|
30
|
-
*
|
|
31
|
-
* {@link retainMetaEntry}. Without a browser
|
|
32
|
-
* the client is asked for `metaStore: false`.
|
|
32
|
+
* Get or create the cache entry for `url` in the UI locale of
|
|
33
|
+
* `options.texts`. First caller's `factory` (and `options.metaKey`) seeds the
|
|
34
|
+
* `Client`; subsequent callers reuse it. On `meta` rejection, the entry is
|
|
35
|
+
* evicted so the next call retries. A hit marks the entry most recently used;
|
|
36
|
+
* hold an entry you keep using with {@link retainMetaEntry}. Without a browser
|
|
37
|
+
* `window` nothing is cached and the client is asked for `metaStore: false`.
|
|
33
38
|
*/
|
|
34
39
|
function getMetaEntry(url, factory, options) {
|
|
40
|
+
const texts = options?.texts ?? getUiTexts();
|
|
41
|
+
const locale = texts.locale();
|
|
42
|
+
const key = cacheKey(url, locale);
|
|
35
43
|
const browser = typeof window !== "undefined";
|
|
36
|
-
const existing = browser ? cache.get(
|
|
44
|
+
const existing = browser ? cache.get(key) : void 0;
|
|
37
45
|
if (existing) {
|
|
38
|
-
touch(
|
|
46
|
+
touch(key, existing);
|
|
47
|
+
mergeServedTexts(existing, texts, locale);
|
|
39
48
|
return existing;
|
|
40
49
|
}
|
|
50
|
+
const clientOptions = {};
|
|
51
|
+
if (!browser) clientOptions.metaStore = false;
|
|
52
|
+
else if (options?.metaKey) clientOptions.metaKey = options.metaKey;
|
|
53
|
+
if (locale !== void 0) clientOptions.locale = locale;
|
|
41
54
|
const f = factory ?? getDefaultClientFactory();
|
|
42
|
-
|
|
43
|
-
if (!browser) client = f(url, { metaStore: false });
|
|
44
|
-
else if (options?.metaKey) client = f(url, { metaKey: options.metaKey });
|
|
45
|
-
else client = f(url);
|
|
55
|
+
const client = Object.keys(clientOptions).length > 0 ? f(url, clientOptions) : f(url);
|
|
46
56
|
const meta = client.meta().catch((err) => {
|
|
47
|
-
if (cache.get(
|
|
57
|
+
if (cache.get(key) === entry) evict(key, entry);
|
|
48
58
|
throw err;
|
|
49
59
|
});
|
|
50
60
|
const derived = meta.then((m) => derive(entry, client, m));
|
|
@@ -56,20 +66,33 @@ function getMetaEntry(url, factory, options) {
|
|
|
56
66
|
type
|
|
57
67
|
};
|
|
58
68
|
const slot = {
|
|
59
|
-
|
|
69
|
+
key,
|
|
60
70
|
derived,
|
|
61
|
-
holds: 0
|
|
71
|
+
holds: 0,
|
|
72
|
+
tableDefs: /* @__PURE__ */ new Map(),
|
|
73
|
+
mergedInto: /* @__PURE__ */ new WeakSet()
|
|
62
74
|
};
|
|
63
75
|
slots.set(entry, slot);
|
|
64
76
|
if (browser) {
|
|
65
77
|
slot.store = customStoreOf(client);
|
|
66
78
|
if (slot.store) customStores.set(slot.store, (customStores.get(slot.store) ?? 0) + 1);
|
|
67
|
-
cache.set(
|
|
79
|
+
cache.set(key, entry);
|
|
68
80
|
trim(entry);
|
|
69
81
|
}
|
|
82
|
+
mergeServedTexts(entry, texts, locale);
|
|
70
83
|
return entry;
|
|
71
84
|
}
|
|
72
85
|
/**
|
|
86
|
+
* Merges the texts `entry`'s `/meta` serves (`type.$i18n`) into `texts` for
|
|
87
|
+
* `locale` — once per entry and texts, when `/meta` arrives.
|
|
88
|
+
*/
|
|
89
|
+
function mergeServedTexts(entry, texts, locale) {
|
|
90
|
+
const slot = slots.get(entry);
|
|
91
|
+
if (slot.mergedInto.has(texts)) return;
|
|
92
|
+
slot.mergedInto.add(texts);
|
|
93
|
+
entry.meta.then((m) => texts.merge(locale, m.type?.$i18n)).catch(() => {});
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
73
96
|
* Keep `entry` in the cache while it is in use: a held entry is never
|
|
74
97
|
* evicted by the size limit ({@link setMetaCacheMaxEntries}), so later
|
|
75
98
|
* `getMetaEntry` / `resolveValueHelp` calls for its URL keep returning it.
|
|
@@ -86,16 +109,17 @@ function retainMetaEntry(entry) {
|
|
|
86
109
|
if (released) return;
|
|
87
110
|
released = true;
|
|
88
111
|
slot.holds--;
|
|
89
|
-
if (slot.holds === 0 && cache.get(slot.
|
|
90
|
-
touch(slot.
|
|
112
|
+
if (slot.holds === 0 && cache.get(slot.key) === entry) {
|
|
113
|
+
touch(slot.key, entry);
|
|
91
114
|
trim();
|
|
92
115
|
}
|
|
93
116
|
};
|
|
94
117
|
}
|
|
95
118
|
/**
|
|
96
|
-
* How many
|
|
97
|
-
* entries beyond it are dropped — entries held
|
|
98
|
-
* (every mounted table and form value-help)
|
|
119
|
+
* How many entries (one per URL and UI locale) the meta cache keeps (default
|
|
120
|
+
* `100`). Least recently used entries beyond it are dropped — entries held
|
|
121
|
+
* with {@link retainMetaEntry} (every mounted table and form value-help)
|
|
122
|
+
* never are, and may exceed it.
|
|
99
123
|
* At least `1`; `Infinity` turns the limit off; no argument restores the
|
|
100
124
|
* default. Since 0.1.154.
|
|
101
125
|
*/
|
|
@@ -103,9 +127,9 @@ function setMetaCacheMaxEntries(max) {
|
|
|
103
127
|
maxEntries = max === void 0 ? DEFAULT_MAX_ENTRIES : max >= 1 ? max : 1;
|
|
104
128
|
trim();
|
|
105
129
|
}
|
|
106
|
-
function touch(
|
|
107
|
-
cache.delete(
|
|
108
|
-
cache.set(
|
|
130
|
+
function touch(key, entry) {
|
|
131
|
+
cache.delete(key);
|
|
132
|
+
cache.set(key, entry);
|
|
109
133
|
}
|
|
110
134
|
/**
|
|
111
135
|
* Drop least recently used entries nothing holds until the cache fits.
|
|
@@ -113,8 +137,8 @@ function touch(url, entry) {
|
|
|
113
137
|
*/
|
|
114
138
|
function trim(spare) {
|
|
115
139
|
if (cache.size <= maxEntries) return;
|
|
116
|
-
for (const [
|
|
117
|
-
if (entry !== spare && slots.get(entry).holds === 0) evict(
|
|
140
|
+
for (const [key, entry] of cache) {
|
|
141
|
+
if (entry !== spare && slots.get(entry).holds === 0) evict(key, entry);
|
|
118
142
|
if (cache.size <= maxEntries) return;
|
|
119
143
|
}
|
|
120
144
|
}
|
|
@@ -124,8 +148,8 @@ function trim(spare) {
|
|
|
124
148
|
* `/meta` goes now — a factory that reuses clients per URL would otherwise
|
|
125
149
|
* hand it to the next viewer.
|
|
126
150
|
*/
|
|
127
|
-
function evict(
|
|
128
|
-
cache.delete(
|
|
151
|
+
function evict(key, entry) {
|
|
152
|
+
cache.delete(key);
|
|
129
153
|
entry.client.invalidateMeta?.();
|
|
130
154
|
const slot = slots.get(entry);
|
|
131
155
|
if (slot.etag !== void 0 && --derivedByEtag.get(slot.etag).refs === 0) derivedByEtag.delete(slot.etag);
|
|
@@ -139,15 +163,29 @@ function evict(url, entry) {
|
|
|
139
163
|
}
|
|
140
164
|
}
|
|
141
165
|
/**
|
|
142
|
-
* The `TableDef` for a cache entry, built once per entry
|
|
143
|
-
* `/meta` `ETag` across entries.
|
|
166
|
+
* The `TableDef` for a cache entry in a UI locale, built once per entry and
|
|
167
|
+
* locale — and once per `/meta` `ETag` and locale across entries. Its labels
|
|
168
|
+
* (boolean `Yes` / `No`) are worded with `texts`: the active UI texts by
|
|
169
|
+
* default; a component passes its app's, so a server render and a remount
|
|
170
|
+
* in another locale get their own. Since 0.1.153; per locale since 0.1.165.
|
|
144
171
|
*/
|
|
145
|
-
function getMetaTableDef(entry) {
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
172
|
+
function getMetaTableDef(entry, texts = getUiTexts()) {
|
|
173
|
+
const slot = slots.get(entry);
|
|
174
|
+
const key = texts.locale() ?? "";
|
|
175
|
+
let def = slot?.tableDefs.get(key);
|
|
176
|
+
if (!def) {
|
|
177
|
+
def = Promise.all([entry.meta, slot?.derived ?? entry.type.then((type) => ({ type }))]).then(([meta, d]) => {
|
|
178
|
+
const defs = d.tableDefs ??= /* @__PURE__ */ new Map();
|
|
179
|
+
let tableDef = defs.get(key);
|
|
180
|
+
if (!tableDef) {
|
|
181
|
+
tableDef = createTableDef(meta, d.type, texts.t);
|
|
182
|
+
defs.set(key, tableDef);
|
|
183
|
+
}
|
|
184
|
+
return tableDef;
|
|
185
|
+
});
|
|
186
|
+
slot?.tableDefs.set(key, def);
|
|
149
187
|
}
|
|
150
|
-
return
|
|
188
|
+
return def;
|
|
151
189
|
}
|
|
152
190
|
/**
|
|
153
191
|
* Shares the `Derived` of one `ETag` among the cached entries that loaded it;
|
|
@@ -155,7 +193,7 @@ function getMetaTableDef(entry) {
|
|
|
155
193
|
*/
|
|
156
194
|
function derive(entry, client, meta) {
|
|
157
195
|
const slot = slots.get(entry);
|
|
158
|
-
const etag = cache.get(slot.
|
|
196
|
+
const etag = cache.get(slot.key) === entry ? client.metaEtag?.() : void 0;
|
|
159
197
|
if (etag === void 0) return { type: deserializeAnnotatedType(meta.type) };
|
|
160
198
|
let shared = derivedByEtag.get(etag);
|
|
161
199
|
if (shared) shared.refs++;
|
|
@@ -13,8 +13,11 @@ let _atscript_typescript_utils = require("@atscript/typescript/utils");
|
|
|
13
13
|
* 2. Flattens to discover all field paths
|
|
14
14
|
* 3. Builds ColumnDef per field using annotations + meta.fields capabilities
|
|
15
15
|
* 4. Sorts by @ui.table.order
|
|
16
|
+
*
|
|
17
|
+
* `t` words the default boolean option labels (`UI_YES` / `UI_NO`); the
|
|
18
|
+
* active UI texts when omitted.
|
|
16
19
|
*/
|
|
17
|
-
function createTableDef(meta, preDeserializedType) {
|
|
20
|
+
function createTableDef(meta, preDeserializedType, t) {
|
|
18
21
|
const type = preDeserializedType ?? (0, _atscript_typescript_utils.deserializeAnnotatedType)(meta.type);
|
|
19
22
|
const flatMap = type.type.kind === "object" ? (0, _atscript_typescript_utils.flattenAnnotatedType)(type, { excludePhantomTypes: true }) : /* @__PURE__ */ new Map();
|
|
20
23
|
const columns = [];
|
|
@@ -24,7 +27,7 @@ function createTableDef(meta, preDeserializedType) {
|
|
|
24
27
|
const fieldMeta = meta.fields[path];
|
|
25
28
|
if (!isReadable(fieldMeta)) continue;
|
|
26
29
|
if (require_field_resolver.getFieldMeta(prop, "ui.table.exclude") !== void 0) continue;
|
|
27
|
-
const options = require_extract_literals.extractFieldLiteralOptions(prop);
|
|
30
|
+
const options = require_extract_literals.extractFieldLiteralOptions(prop, t);
|
|
28
31
|
const valueHelpInfo = require_extract_ref.extractValueHelp(prop);
|
|
29
32
|
let distinct;
|
|
30
33
|
if (!valueHelpInfo && !options && fieldMeta.groupable && fieldMeta.filterable) {
|
|
@@ -47,7 +50,7 @@ function createTableDef(meta, preDeserializedType) {
|
|
|
47
50
|
if (!fieldMeta?.decoration || flatMap.has(path)) continue;
|
|
48
51
|
if (require_field_resolver.getFieldMeta(prop, "ui.table.exclude") !== void 0) continue;
|
|
49
52
|
flatMap.set(path, prop);
|
|
50
|
-
columns.push(buildColumn(path, prop, fieldMeta, { options: require_extract_literals.extractFieldLiteralOptions(prop) }));
|
|
53
|
+
columns.push(buildColumn(path, prop, fieldMeta, { options: require_extract_literals.extractFieldLiteralOptions(prop, t) }));
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
columns.sort((a, b) => a.order - b.order);
|
|
@@ -95,7 +98,7 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
95
98
|
sortable: !decoration && (fieldMeta.sortable ?? false),
|
|
96
99
|
filterable: !decoration && (fieldMeta.filterable ?? false),
|
|
97
100
|
...filterOps && { filterOps: [...filterOps] },
|
|
98
|
-
nullable: decoration || prop.optional === true,
|
|
101
|
+
nullable: decoration || prop.optional === true || hasEmptyMember(prop),
|
|
99
102
|
width: require_field_resolver.getFieldMeta(prop, require_annotation_keys.UI_TABLE_WIDTH),
|
|
100
103
|
maxLen: maxLengthMeta?.length,
|
|
101
104
|
order: require_field_resolver.getFieldMeta(prop, "ui.table.order") ?? Infinity,
|
|
@@ -160,7 +163,10 @@ function inferDisplayType(prop, literalOpts) {
|
|
|
160
163
|
const kind = prop.type.kind;
|
|
161
164
|
if (kind === "array") return "array";
|
|
162
165
|
if (kind === "object") return "object";
|
|
163
|
-
if (kind === "union")
|
|
166
|
+
if (kind === "union") {
|
|
167
|
+
if (literalOpts === void 0) return "union";
|
|
168
|
+
return literalOpts.every((o) => typeof o.value === "boolean") ? "boolean" : "enum";
|
|
169
|
+
}
|
|
164
170
|
if (kind === "") {
|
|
165
171
|
const final = prop.type;
|
|
166
172
|
const dt = final.designType;
|
|
@@ -197,6 +203,11 @@ function scalarValueKind(prop) {
|
|
|
197
203
|
default: return;
|
|
198
204
|
}
|
|
199
205
|
}
|
|
206
|
+
/** Whether a union has a `null` / `undefined` member (`T | null`): its value can be empty. */
|
|
207
|
+
function hasEmptyMember(prop) {
|
|
208
|
+
if (prop.type.kind !== "union") return false;
|
|
209
|
+
return prop.type.items.some((item) => require_extract_literals.isEmptyMember(item) || hasEmptyMember(item));
|
|
210
|
+
}
|
|
200
211
|
/** Kinds of every non-null leaf of a (possibly nested) union; `null` when one is not a scalar. */
|
|
201
212
|
function collectUnionKinds(items, out) {
|
|
202
213
|
for (const item of items) {
|
|
@@ -205,9 +216,7 @@ function collectUnionKinds(items, out) {
|
|
|
205
216
|
continue;
|
|
206
217
|
}
|
|
207
218
|
if (item.type.kind === "") {
|
|
208
|
-
|
|
209
|
-
if (dt === "null" || dt === "undefined") continue;
|
|
210
|
-
out.add(scalarValueKind(item));
|
|
219
|
+
if (!require_extract_literals.isEmptyMember(item)) out.add(scalarValueKind(item));
|
|
211
220
|
continue;
|
|
212
221
|
}
|
|
213
222
|
out.add(void 0);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MetaResponse, TableDef } from "./types.cjs";
|
|
2
|
+
import { UiT } from "../i18n/ui-texts.cjs";
|
|
2
3
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
3
4
|
|
|
4
5
|
//#region src/table/create-table-def.d.ts
|
|
@@ -9,7 +10,10 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
|
9
10
|
* 2. Flattens to discover all field paths
|
|
10
11
|
* 3. Builds ColumnDef per field using annotations + meta.fields capabilities
|
|
11
12
|
* 4. Sorts by @ui.table.order
|
|
13
|
+
*
|
|
14
|
+
* `t` words the default boolean option labels (`UI_YES` / `UI_NO`); the
|
|
15
|
+
* active UI texts when omitted.
|
|
12
16
|
*/
|
|
13
|
-
declare function createTableDef(meta: MetaResponse, preDeserializedType?: TAtscriptAnnotatedType): TableDef;
|
|
17
|
+
declare function createTableDef(meta: MetaResponse, preDeserializedType?: TAtscriptAnnotatedType, t?: UiT): TableDef;
|
|
14
18
|
//#endregion
|
|
15
19
|
export { createTableDef };
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { MetaResponse, TableDef } from "./types.mjs";
|
|
2
|
+
import { UiT } from "../i18n/ui-texts.mjs";
|
|
2
3
|
import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
3
4
|
|
|
4
5
|
//#region src/table/create-table-def.d.ts
|
|
@@ -9,7 +10,10 @@ import { TAtscriptAnnotatedType } from "@atscript/typescript/utils";
|
|
|
9
10
|
* 2. Flattens to discover all field paths
|
|
10
11
|
* 3. Builds ColumnDef per field using annotations + meta.fields capabilities
|
|
11
12
|
* 4. Sorts by @ui.table.order
|
|
13
|
+
*
|
|
14
|
+
* `t` words the default boolean option labels (`UI_YES` / `UI_NO`); the
|
|
15
|
+
* active UI texts when omitted.
|
|
12
16
|
*/
|
|
13
|
-
declare function createTableDef(meta: MetaResponse, preDeserializedType?: TAtscriptAnnotatedType): TableDef;
|
|
17
|
+
declare function createTableDef(meta: MetaResponse, preDeserializedType?: TAtscriptAnnotatedType, t?: UiT): TableDef;
|
|
14
18
|
//#endregion
|
|
15
19
|
export { createTableDef };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DB_HTTP_PATH, EXPECT_MAX_LENGTH, UI_TABLE_COMPONENT, UI_TABLE_SELECT_WITH, UI_TABLE_TYPE, UI_TABLE_WIDTH, UI_TYPE } from "../shared/annotation-keys.mjs";
|
|
2
2
|
import { getFieldMeta } from "../shared/field-resolver.mjs";
|
|
3
|
-
import { extractFieldLiteralOptions } from "../value-help/extract-literals.mjs";
|
|
3
|
+
import { extractFieldLiteralOptions, isEmptyMember } from "../value-help/extract-literals.mjs";
|
|
4
4
|
import { extractValueHelp } from "../value-help/extract-ref.mjs";
|
|
5
5
|
import { humanizePath } from "../shared/str.mjs";
|
|
6
6
|
import { extractMeasurement } from "../form/measurement.mjs";
|
|
@@ -13,8 +13,11 @@ import { deserializeAnnotatedType, flattenAnnotatedType } from "@atscript/typesc
|
|
|
13
13
|
* 2. Flattens to discover all field paths
|
|
14
14
|
* 3. Builds ColumnDef per field using annotations + meta.fields capabilities
|
|
15
15
|
* 4. Sorts by @ui.table.order
|
|
16
|
+
*
|
|
17
|
+
* `t` words the default boolean option labels (`UI_YES` / `UI_NO`); the
|
|
18
|
+
* active UI texts when omitted.
|
|
16
19
|
*/
|
|
17
|
-
function createTableDef(meta, preDeserializedType) {
|
|
20
|
+
function createTableDef(meta, preDeserializedType, t) {
|
|
18
21
|
const type = preDeserializedType ?? deserializeAnnotatedType(meta.type);
|
|
19
22
|
const flatMap = type.type.kind === "object" ? flattenAnnotatedType(type, { excludePhantomTypes: true }) : /* @__PURE__ */ new Map();
|
|
20
23
|
const columns = [];
|
|
@@ -24,7 +27,7 @@ function createTableDef(meta, preDeserializedType) {
|
|
|
24
27
|
const fieldMeta = meta.fields[path];
|
|
25
28
|
if (!isReadable(fieldMeta)) continue;
|
|
26
29
|
if (getFieldMeta(prop, "ui.table.exclude") !== void 0) continue;
|
|
27
|
-
const options = extractFieldLiteralOptions(prop);
|
|
30
|
+
const options = extractFieldLiteralOptions(prop, t);
|
|
28
31
|
const valueHelpInfo = extractValueHelp(prop);
|
|
29
32
|
let distinct;
|
|
30
33
|
if (!valueHelpInfo && !options && fieldMeta.groupable && fieldMeta.filterable) {
|
|
@@ -47,7 +50,7 @@ function createTableDef(meta, preDeserializedType) {
|
|
|
47
50
|
if (!fieldMeta?.decoration || flatMap.has(path)) continue;
|
|
48
51
|
if (getFieldMeta(prop, "ui.table.exclude") !== void 0) continue;
|
|
49
52
|
flatMap.set(path, prop);
|
|
50
|
-
columns.push(buildColumn(path, prop, fieldMeta, { options: extractFieldLiteralOptions(prop) }));
|
|
53
|
+
columns.push(buildColumn(path, prop, fieldMeta, { options: extractFieldLiteralOptions(prop, t) }));
|
|
51
54
|
}
|
|
52
55
|
}
|
|
53
56
|
columns.sort((a, b) => a.order - b.order);
|
|
@@ -95,7 +98,7 @@ function buildColumn(path, prop, fieldMeta, resolved) {
|
|
|
95
98
|
sortable: !decoration && (fieldMeta.sortable ?? false),
|
|
96
99
|
filterable: !decoration && (fieldMeta.filterable ?? false),
|
|
97
100
|
...filterOps && { filterOps: [...filterOps] },
|
|
98
|
-
nullable: decoration || prop.optional === true,
|
|
101
|
+
nullable: decoration || prop.optional === true || hasEmptyMember(prop),
|
|
99
102
|
width: getFieldMeta(prop, UI_TABLE_WIDTH),
|
|
100
103
|
maxLen: maxLengthMeta?.length,
|
|
101
104
|
order: getFieldMeta(prop, "ui.table.order") ?? Infinity,
|
|
@@ -160,7 +163,10 @@ function inferDisplayType(prop, literalOpts) {
|
|
|
160
163
|
const kind = prop.type.kind;
|
|
161
164
|
if (kind === "array") return "array";
|
|
162
165
|
if (kind === "object") return "object";
|
|
163
|
-
if (kind === "union")
|
|
166
|
+
if (kind === "union") {
|
|
167
|
+
if (literalOpts === void 0) return "union";
|
|
168
|
+
return literalOpts.every((o) => typeof o.value === "boolean") ? "boolean" : "enum";
|
|
169
|
+
}
|
|
164
170
|
if (kind === "") {
|
|
165
171
|
const final = prop.type;
|
|
166
172
|
const dt = final.designType;
|
|
@@ -197,6 +203,11 @@ function scalarValueKind(prop) {
|
|
|
197
203
|
default: return;
|
|
198
204
|
}
|
|
199
205
|
}
|
|
206
|
+
/** Whether a union has a `null` / `undefined` member (`T | null`): its value can be empty. */
|
|
207
|
+
function hasEmptyMember(prop) {
|
|
208
|
+
if (prop.type.kind !== "union") return false;
|
|
209
|
+
return prop.type.items.some((item) => isEmptyMember(item) || hasEmptyMember(item));
|
|
210
|
+
}
|
|
200
211
|
/** Kinds of every non-null leaf of a (possibly nested) union; `null` when one is not a scalar. */
|
|
201
212
|
function collectUnionKinds(items, out) {
|
|
202
213
|
for (const item of items) {
|
|
@@ -205,9 +216,7 @@ function collectUnionKinds(items, out) {
|
|
|
205
216
|
continue;
|
|
206
217
|
}
|
|
207
218
|
if (item.type.kind === "") {
|
|
208
|
-
|
|
209
|
-
if (dt === "null" || dt === "undefined") continue;
|
|
210
|
-
out.add(scalarValueKind(item));
|
|
219
|
+
if (!isEmptyMember(item)) out.add(scalarValueKind(item));
|
|
211
220
|
continue;
|
|
212
221
|
}
|
|
213
222
|
out.add(void 0);
|
package/dist/table/types.d.cts
CHANGED
|
@@ -205,7 +205,8 @@ interface ColumnDef {
|
|
|
205
205
|
*/
|
|
206
206
|
filterOps?: string[];
|
|
207
207
|
/**
|
|
208
|
-
* Whether the column accepts `null` values (atscript prop is `optional
|
|
208
|
+
* Whether the column accepts `null` values (atscript prop is `optional`, or —
|
|
209
|
+
* since 0.1.165 — its type has a `null` member: `T | null`).
|
|
209
210
|
* Drives operator-picker availability — `null` / `notNull` are dropped
|
|
210
211
|
* for non-nullable columns since they can never match.
|
|
211
212
|
*/
|
|
@@ -217,7 +218,9 @@ interface ColumnDef {
|
|
|
217
218
|
/** Initial column ordering from @ui.table.order (lower = first). */
|
|
218
219
|
order: number;
|
|
219
220
|
/**
|
|
220
|
-
* Enumerated options for union literal types (e.g. 'a' | 'b' | 'c')
|
|
221
|
+
* Enumerated options for union literal types (e.g. 'a' | 'b' | 'c') and — since
|
|
222
|
+
* 0.1.165 — booleans (`true` / `false`, labelled Yes / No unless
|
|
223
|
+
* `@ui.literalLabel` says otherwise). `value` is
|
|
221
224
|
* the typed literal (`true`, `3`) — what a filter sends to the server; the
|
|
222
225
|
* `key` is its string form. `createTableDef` always sets it (since 0.1.148);
|
|
223
226
|
* a hand-built column may omit it, and the string `key` is used.
|
package/dist/table/types.d.mts
CHANGED
|
@@ -205,7 +205,8 @@ interface ColumnDef {
|
|
|
205
205
|
*/
|
|
206
206
|
filterOps?: string[];
|
|
207
207
|
/**
|
|
208
|
-
* Whether the column accepts `null` values (atscript prop is `optional
|
|
208
|
+
* Whether the column accepts `null` values (atscript prop is `optional`, or —
|
|
209
|
+
* since 0.1.165 — its type has a `null` member: `T | null`).
|
|
209
210
|
* Drives operator-picker availability — `null` / `notNull` are dropped
|
|
210
211
|
* for non-nullable columns since they can never match.
|
|
211
212
|
*/
|
|
@@ -217,7 +218,9 @@ interface ColumnDef {
|
|
|
217
218
|
/** Initial column ordering from @ui.table.order (lower = first). */
|
|
218
219
|
order: number;
|
|
219
220
|
/**
|
|
220
|
-
* Enumerated options for union literal types (e.g. 'a' | 'b' | 'c')
|
|
221
|
+
* Enumerated options for union literal types (e.g. 'a' | 'b' | 'c') and — since
|
|
222
|
+
* 0.1.165 — booleans (`true` / `false`, labelled Yes / No unless
|
|
223
|
+
* `@ui.literalLabel` says otherwise). `value` is
|
|
221
224
|
* the typed literal (`true`, `3`) — what a filter sends to the server; the
|
|
222
225
|
* `key` is its string form. `createTableDef` always sets it (since 0.1.148);
|
|
223
226
|
* a hand-built column may omit it, and the string `key` is used.
|
|
@@ -6,14 +6,14 @@ const NUMERIC_VALUE_KINDS = new Set([
|
|
|
6
6
|
"decimal"
|
|
7
7
|
]);
|
|
8
8
|
/**
|
|
9
|
-
* The typed value of
|
|
10
|
-
* (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* The typed value of an option — a column's or a form field's — the literal
|
|
10
|
+
* itself (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
|
|
11
|
+
* option that has no `value`; a plain string option is itself. What a filter
|
|
12
|
+
* sends and what a select / radio / multiselect writes into the model.
|
|
13
|
+
* Since 0.1.148; form options (`TFormEntryOptions`) since 0.1.165.
|
|
14
14
|
*/
|
|
15
15
|
function optionValue(option) {
|
|
16
|
-
return option.value ?? option.key;
|
|
16
|
+
return typeof option === "string" ? option : option.value ?? option.key;
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
exports.NUMERIC_VALUE_KINDS = NUMERIC_VALUE_KINDS;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TFormEntryOptions } from "../value-help/types.cjs";
|
|
2
|
+
import { ColumnValueKind } from "./types.cjs";
|
|
2
3
|
|
|
3
4
|
//#region src/table/value-kind.d.ts
|
|
4
5
|
/** Storage kinds that hold plain numbers (a `timestamp` is epoch ms, but filters treat it as a date). */
|
|
5
6
|
declare const NUMERIC_VALUE_KINDS: ReadonlySet<ColumnValueKind>;
|
|
6
7
|
/**
|
|
7
|
-
* The typed value of
|
|
8
|
-
* (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* The typed value of an option — a column's or a form field's — the literal
|
|
9
|
+
* itself (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
|
|
10
|
+
* option that has no `value`; a plain string option is itself. What a filter
|
|
11
|
+
* sends and what a select / radio / multiselect writes into the model.
|
|
12
|
+
* Since 0.1.148; form options (`TFormEntryOptions`) since 0.1.165.
|
|
12
13
|
*/
|
|
13
|
-
declare function optionValue(option:
|
|
14
|
+
declare function optionValue(option: TFormEntryOptions): string | number | boolean;
|
|
14
15
|
//#endregion
|
|
15
16
|
export { NUMERIC_VALUE_KINDS, optionValue };
|
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { TFormEntryOptions } from "../value-help/types.mjs";
|
|
2
|
+
import { ColumnValueKind } from "./types.mjs";
|
|
2
3
|
|
|
3
4
|
//#region src/table/value-kind.d.ts
|
|
4
5
|
/** Storage kinds that hold plain numbers (a `timestamp` is epoch ms, but filters treat it as a date). */
|
|
5
6
|
declare const NUMERIC_VALUE_KINDS: ReadonlySet<ColumnValueKind>;
|
|
6
7
|
/**
|
|
7
|
-
* The typed value of
|
|
8
|
-
* (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
8
|
+
* The typed value of an option — a column's or a form field's — the literal
|
|
9
|
+
* itself (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
|
|
10
|
+
* option that has no `value`; a plain string option is itself. What a filter
|
|
11
|
+
* sends and what a select / radio / multiselect writes into the model.
|
|
12
|
+
* Since 0.1.148; form options (`TFormEntryOptions`) since 0.1.165.
|
|
12
13
|
*/
|
|
13
|
-
declare function optionValue(option:
|
|
14
|
+
declare function optionValue(option: TFormEntryOptions): string | number | boolean;
|
|
14
15
|
//#endregion
|
|
15
16
|
export { NUMERIC_VALUE_KINDS, optionValue };
|
|
@@ -6,14 +6,14 @@ const NUMERIC_VALUE_KINDS = new Set([
|
|
|
6
6
|
"decimal"
|
|
7
7
|
]);
|
|
8
8
|
/**
|
|
9
|
-
* The typed value of
|
|
10
|
-
* (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
-
*
|
|
9
|
+
* The typed value of an option — a column's or a form field's — the literal
|
|
10
|
+
* itself (`true`, `3`, `'a'`), falling back to the string `key` for a hand-built
|
|
11
|
+
* option that has no `value`; a plain string option is itself. What a filter
|
|
12
|
+
* sends and what a select / radio / multiselect writes into the model.
|
|
13
|
+
* Since 0.1.148; form options (`TFormEntryOptions`) since 0.1.165.
|
|
14
14
|
*/
|
|
15
15
|
function optionValue(option) {
|
|
16
|
-
return option.value ?? option.key;
|
|
16
|
+
return typeof option === "string" ? option : option.value ?? option.key;
|
|
17
17
|
}
|
|
18
18
|
//#endregion
|
|
19
19
|
export { NUMERIC_VALUE_KINDS, optionValue };
|