@ramathibodi/nuxt-commons 4.0.26 → 4.0.28
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/module.json +2 -2
- package/dist/runtime/components/Calendar.d.vue.ts +12 -10
- package/dist/runtime/components/Calendar.vue.d.ts +12 -10
- package/dist/runtime/components/ExportCSV.d.vue.ts +3 -3
- package/dist/runtime/components/ExportCSV.vue.d.ts +3 -3
- package/dist/runtime/components/FileBtn.d.vue.ts +3 -3
- package/dist/runtime/components/FileBtn.vue.d.ts +3 -3
- package/dist/runtime/components/ImportCSV.d.vue.ts +3 -3
- package/dist/runtime/components/ImportCSV.vue.d.ts +3 -3
- package/dist/runtime/components/SplitterPanel.d.vue.ts +7 -5
- package/dist/runtime/components/SplitterPanel.vue.d.ts +7 -5
- package/dist/runtime/components/TabsGroup.d.vue.ts +7 -5
- package/dist/runtime/components/TabsGroup.vue.d.ts +7 -5
- package/dist/runtime/components/device/IdCardButton.d.vue.ts +3 -3
- package/dist/runtime/components/device/IdCardButton.vue.d.ts +3 -3
- package/dist/runtime/components/device/Scanner.d.vue.ts +31 -29
- package/dist/runtime/components/device/Scanner.vue.d.ts +31 -29
- package/dist/runtime/components/dialog/Confirm.d.vue.ts +7 -5
- package/dist/runtime/components/dialog/Confirm.vue.d.ts +7 -5
- package/dist/runtime/components/dialog/ImportProgress.d.vue.ts +5 -3
- package/dist/runtime/components/dialog/ImportProgress.vue.d.ts +5 -3
- package/dist/runtime/components/dialog/Index.d.vue.ts +5 -3
- package/dist/runtime/components/dialog/Index.vue.d.ts +5 -3
- package/dist/runtime/components/dialog/Loading.d.vue.ts +5 -3
- package/dist/runtime/components/dialog/Loading.vue.d.ts +5 -3
- package/dist/runtime/components/dialog/default/Confirm.d.vue.ts +7 -5
- package/dist/runtime/components/dialog/default/Confirm.vue.d.ts +7 -5
- package/dist/runtime/components/dialog/default/Loading.d.vue.ts +7 -5
- package/dist/runtime/components/dialog/default/Loading.vue.d.ts +7 -5
- package/dist/runtime/components/dialog/default/Printing.d.vue.ts +5 -3
- package/dist/runtime/components/dialog/default/Printing.vue.d.ts +5 -3
- package/dist/runtime/components/document/TemplateBuilderLiveView.d.vue.ts +88 -73
- package/dist/runtime/components/document/TemplateBuilderLiveView.vue +175 -68
- package/dist/runtime/components/document/TemplateBuilderLiveView.vue.d.ts +88 -73
- package/dist/runtime/components/document/TemplateInputAttributesHelper.d.vue.ts +14 -0
- package/dist/runtime/components/document/TemplateInputAttributesHelper.vue +154 -0
- package/dist/runtime/components/document/TemplateInputAttributesHelper.vue.d.ts +14 -0
- package/dist/runtime/components/document/TemplateItemForm.vue +46 -1
- package/dist/runtime/components/document/TemplatePalette.d.vue.ts +8 -6
- package/dist/runtime/components/document/TemplatePalette.vue +16 -0
- package/dist/runtime/components/document/TemplatePalette.vue.d.ts +8 -6
- package/dist/runtime/components/form/ActionPad.d.vue.ts +34 -32
- package/dist/runtime/components/form/ActionPad.vue.d.ts +34 -32
- package/dist/runtime/components/form/Date.d.vue.ts +20 -18
- package/dist/runtime/components/form/Date.vue.d.ts +20 -18
- package/dist/runtime/components/form/DateTime.d.vue.ts +1 -1
- package/dist/runtime/components/form/DateTime.vue.d.ts +1 -1
- package/dist/runtime/components/form/Dialog.d.vue.ts +24 -22
- package/dist/runtime/components/form/Dialog.vue.d.ts +24 -22
- package/dist/runtime/components/form/EditPad.d.vue.ts +34 -32
- package/dist/runtime/components/form/EditPad.vue.d.ts +34 -32
- package/dist/runtime/components/form/File.d.vue.ts +12 -10
- package/dist/runtime/components/form/File.vue.d.ts +12 -10
- package/dist/runtime/components/form/Iterator.d.vue.ts +121 -134
- package/dist/runtime/components/form/Iterator.vue.d.ts +121 -134
- package/dist/runtime/components/form/Login.d.vue.ts +5 -3
- package/dist/runtime/components/form/Login.vue.d.ts +5 -3
- package/dist/runtime/components/form/Pad.d.vue.ts +651 -649
- package/dist/runtime/components/form/Pad.vue.d.ts +651 -649
- package/dist/runtime/components/form/Table.d.vue.ts +69 -82
- package/dist/runtime/components/form/Table.vue.d.ts +69 -82
- package/dist/runtime/components/form/TableData.d.vue.ts +18 -24
- package/dist/runtime/components/form/TableData.vue.d.ts +18 -24
- package/dist/runtime/components/form/images/Capture.d.vue.ts +15 -13
- package/dist/runtime/components/form/images/Capture.vue.d.ts +15 -13
- package/dist/runtime/components/label/Date.d.vue.ts +1 -1
- package/dist/runtime/components/label/Date.vue.d.ts +1 -1
- package/dist/runtime/components/label/Field.d.vue.ts +16 -14
- package/dist/runtime/components/label/Field.vue.d.ts +16 -14
- package/dist/runtime/components/label/FormatMoney.d.vue.ts +1 -1
- package/dist/runtime/components/label/FormatMoney.vue.d.ts +1 -1
- package/dist/runtime/components/master/Autocomplete.d.vue.ts +3 -5
- package/dist/runtime/components/master/Autocomplete.vue.d.ts +3 -5
- package/dist/runtime/components/master/Combobox.d.vue.ts +3 -5
- package/dist/runtime/components/master/Combobox.vue.d.ts +3 -5
- package/dist/runtime/components/master/RadioGroup.d.vue.ts +3 -3
- package/dist/runtime/components/master/RadioGroup.vue.d.ts +3 -3
- package/dist/runtime/components/master/Select.d.vue.ts +3 -5
- package/dist/runtime/components/master/Select.vue.d.ts +3 -5
- package/dist/runtime/components/master/label.d.vue.ts +7 -3
- package/dist/runtime/components/master/label.vue +33 -15
- package/dist/runtime/components/master/label.vue.d.ts +7 -3
- package/dist/runtime/components/model/Autocomplete.d.vue.ts +3 -3
- package/dist/runtime/components/model/Autocomplete.vue.d.ts +3 -3
- package/dist/runtime/components/model/Combobox.d.vue.ts +3 -3
- package/dist/runtime/components/model/Combobox.vue.d.ts +3 -3
- package/dist/runtime/components/model/Pad.d.vue.ts +17 -15
- package/dist/runtime/components/model/Pad.vue.d.ts +17 -15
- package/dist/runtime/components/model/Select.d.vue.ts +3 -3
- package/dist/runtime/components/model/Select.vue.d.ts +3 -3
- package/dist/runtime/components/model/Table.d.vue.ts +102 -166
- package/dist/runtime/components/model/Table.vue.d.ts +102 -166
- package/dist/runtime/components/model/iterator.d.vue.ts +188 -240
- package/dist/runtime/components/model/iterator.vue.d.ts +188 -240
- package/dist/runtime/components/model/label.d.vue.ts +11 -5
- package/dist/runtime/components/model/label.vue +54 -4
- package/dist/runtime/components/model/label.vue.d.ts +11 -5
- package/dist/runtime/composables/batchLookup.d.ts +39 -0
- package/dist/runtime/composables/batchLookup.js +144 -0
- package/dist/runtime/composables/document/inputAttributeCatalog.generated.json +95 -0
- package/dist/runtime/composables/document/inputAttributes.d.ts +46 -0
- package/dist/runtime/composables/document/inputAttributes.js +196 -0
- package/dist/runtime/composables/document/template.d.ts +9 -1
- package/dist/runtime/composables/document/template.js +16 -3
- package/dist/runtime/composables/document/templateInputTypes.d.ts +36 -0
- package/dist/runtime/composables/document/templateInputTypes.js +86 -17
- package/dist/runtime/composables/document/templateMasterLabel.d.ts +32 -0
- package/dist/runtime/composables/document/templateMasterLabel.js +30 -0
- package/dist/runtime/composables/document/validateTemplate.js +11 -1
- package/dist/runtime/composables/masterItemBatch.d.ts +7 -0
- package/dist/runtime/composables/masterItemBatch.js +12 -0
- package/dist/runtime/composables/modelBatch.d.ts +61 -0
- package/dist/runtime/composables/modelBatch.js +192 -0
- package/dist/runtime/labs/form/EditMobile.d.vue.ts +1 -1
- package/dist/runtime/labs/form/EditMobile.vue.d.ts +1 -1
- package/dist/runtime/labs/form/TextFieldMask.d.vue.ts +3 -3
- package/dist/runtime/labs/form/TextFieldMask.vue.d.ts +3 -3
- package/dist/runtime/plugins/clientConfig.d.ts +1 -1
- package/dist/runtime/plugins/default.d.ts +1 -1
- package/dist/runtime/plugins/dialogManager.d.ts +1 -1
- package/dist/runtime/plugins/permission.d.ts +1 -1
- package/package.json +2 -2
- package/scripts/build-input-attribute-catalog.mjs +133 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { type CacheOption } from './api.js';
|
|
2
|
+
import { type BatchLookupEntry } from './batchLookup.js';
|
|
3
|
+
export type ModelBatchItem = Record<string, any>;
|
|
4
|
+
export interface ModelBatchSpec {
|
|
5
|
+
/** Single-record operation, used for the GraphQL fallback. */
|
|
6
|
+
modelName: string;
|
|
7
|
+
/** List operation that accepts many `batchKey` values at once. */
|
|
8
|
+
batchOperation: string;
|
|
9
|
+
/** Variable of the single read whose values are collected (e.g. `itemCode`). */
|
|
10
|
+
batchKey: string;
|
|
11
|
+
/** List variable of `batchOperation` (default `${batchKey}s`). */
|
|
12
|
+
batchVariable?: string;
|
|
13
|
+
/** Result field compared with the requested key (default `batchKey`). */
|
|
14
|
+
batchMatch?: string;
|
|
15
|
+
/** All read variables; the `batchKey` entry is ignored. */
|
|
16
|
+
modelBy?: Record<string, unknown>;
|
|
17
|
+
fields?: Array<string | object>;
|
|
18
|
+
api?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export interface ModelBatchClearFilter {
|
|
21
|
+
modelName?: string;
|
|
22
|
+
batchOperation?: string;
|
|
23
|
+
/** Clear only groups whose variables contain these values. */
|
|
24
|
+
modelBy?: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
export interface ModelBatchRequestOptions {
|
|
27
|
+
/** Persist the resolved item in localStorage for this TTL (same forms as `useApi`'s `cache`). */
|
|
28
|
+
cache?: CacheOption;
|
|
29
|
+
}
|
|
30
|
+
export interface ModelBatch {
|
|
31
|
+
/** Reactive entry for a key; `undefined` until requested (or after a clear). */
|
|
32
|
+
get: (spec: ModelBatchSpec, key: unknown) => BatchLookupEntry<ModelBatchItem> | undefined;
|
|
33
|
+
/** Load a key (batched). Resolves once settled; never rejects. */
|
|
34
|
+
request: (spec: ModelBatchSpec, key: unknown, options?: ModelBatchRequestOptions) => Promise<BatchLookupEntry<ModelBatchItem>>;
|
|
35
|
+
/** Drop cached items (memory + localStorage) matching the filter, or all of them. */
|
|
36
|
+
clear: (filter?: ModelBatchClearFilter) => void;
|
|
37
|
+
}
|
|
38
|
+
interface ModelOperation {
|
|
39
|
+
call?: (fields?: Array<string | object>, variables?: Record<string, unknown>) => Promise<unknown>;
|
|
40
|
+
}
|
|
41
|
+
export interface ModelBatchOptions {
|
|
42
|
+
/** GraphQL operations; defaults to the app's GraphQL bridge. */
|
|
43
|
+
operations?: () => Record<string, ModelOperation | undefined>;
|
|
44
|
+
/** REST POST used in API mode; defaults to `useApi().postPromise`. */
|
|
45
|
+
apiPost?: (url: string, body: Record<string, unknown>) => Promise<unknown>;
|
|
46
|
+
/** Wraps each fetch so composables relying on the Nuxt context keep working. */
|
|
47
|
+
runWithContext?: <T>(fn: () => T) => T;
|
|
48
|
+
maxBatchSize?: number;
|
|
49
|
+
maxAttempts?: number;
|
|
50
|
+
retryDelay?: (attempt: number) => number;
|
|
51
|
+
}
|
|
52
|
+
export declare class ModelBatchOperationMissingError extends Error {
|
|
53
|
+
constructor(spec: {
|
|
54
|
+
modelName: string;
|
|
55
|
+
batchOperation: string;
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
export declare function createModelBatch(options?: ModelBatchOptions): ModelBatch;
|
|
59
|
+
/** The app-wide batch shared by every batching `<ModelLabel>` (and so every `<MasterLabel>`). */
|
|
60
|
+
export declare function useModelBatch(): ModelBatch;
|
|
61
|
+
export {};
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
import ls from "localstorage-slim";
|
|
2
|
+
import { useNuxtApp } from "#imports";
|
|
3
|
+
import { useGraphqlBridge } from "../bridges/graphql.js";
|
|
4
|
+
import { stableStringify } from "../utils/object.js";
|
|
5
|
+
import { useGraphQlOperation } from "./graphqlOperation.js";
|
|
6
|
+
import { resolveCacheTtlSeconds, useApi } from "./api.js";
|
|
7
|
+
import { buildApiEndpoint } from "./apiModel.js";
|
|
8
|
+
import { createBatchLookup } from "./batchLookup.js";
|
|
9
|
+
const PERSIST_PREFIX = "api-cache-modelBatch|";
|
|
10
|
+
export class ModelBatchOperationMissingError extends Error {
|
|
11
|
+
constructor(spec) {
|
|
12
|
+
super(`Neither ${spec.batchOperation} nor ${spec.modelName} is registered in the GraphQL bridge`);
|
|
13
|
+
this.name = "ModelBatchOperationMissingError";
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function normalizeKey(key) {
|
|
17
|
+
return key === null || key === void 0 ? "" : String(key);
|
|
18
|
+
}
|
|
19
|
+
function normalizeSpec(spec) {
|
|
20
|
+
const modelBy = Object.fromEntries(Object.entries(spec.modelBy ?? {}).filter(([name]) => name !== spec.batchKey));
|
|
21
|
+
const batchMatch = spec.batchMatch || spec.batchKey;
|
|
22
|
+
let fields = spec.fields && spec.fields.length ? [...spec.fields] : void 0;
|
|
23
|
+
if (fields && !fields.includes(batchMatch) && !fields.includes("*")) fields = [...fields, batchMatch];
|
|
24
|
+
return {
|
|
25
|
+
modelName: spec.modelName,
|
|
26
|
+
batchOperation: spec.batchOperation,
|
|
27
|
+
batchKey: spec.batchKey,
|
|
28
|
+
batchVariable: spec.batchVariable || `${spec.batchKey}s`,
|
|
29
|
+
batchMatch,
|
|
30
|
+
modelBy,
|
|
31
|
+
fields,
|
|
32
|
+
api: !!spec.api
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function signatureOf(spec) {
|
|
36
|
+
return stableStringify([spec.modelName, spec.batchOperation, spec.batchKey, spec.batchVariable, spec.batchMatch, spec.modelBy, spec.fields ?? null, spec.api]);
|
|
37
|
+
}
|
|
38
|
+
function hash(value) {
|
|
39
|
+
let h = 5381;
|
|
40
|
+
for (let i = 0; i < value.length; i++) h = (h << 5) + h + value.charCodeAt(i) | 0;
|
|
41
|
+
return (h >>> 0).toString(36);
|
|
42
|
+
}
|
|
43
|
+
function matchesFilter(target, filter) {
|
|
44
|
+
if (!filter) return true;
|
|
45
|
+
if (filter.modelName && filter.modelName !== target.modelName) return false;
|
|
46
|
+
if (filter.batchOperation && filter.batchOperation !== target.batchOperation) return false;
|
|
47
|
+
return Object.entries(filter.modelBy ?? {}).every(([name, value]) => stableStringify(target.modelBy?.[name]) === stableStringify(value));
|
|
48
|
+
}
|
|
49
|
+
function persistKey(signature, key) {
|
|
50
|
+
return `${PERSIST_PREFIX}${hash(signature)}|${key}`;
|
|
51
|
+
}
|
|
52
|
+
function readPersisted(signature, key) {
|
|
53
|
+
try {
|
|
54
|
+
return ls.get(persistKey(signature, key))?.item ?? null;
|
|
55
|
+
} catch {
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
function writePersisted(signature, spec, key, item, ttl) {
|
|
60
|
+
const entry = { modelName: spec.modelName, batchOperation: spec.batchOperation, modelBy: spec.modelBy, key, item };
|
|
61
|
+
try {
|
|
62
|
+
ls.set(persistKey(signature, key), entry, { ttl });
|
|
63
|
+
} catch {
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
function removePersisted(filter) {
|
|
67
|
+
if (typeof window === "undefined" || !window.localStorage) return;
|
|
68
|
+
const keys = [];
|
|
69
|
+
for (let i = 0; i < window.localStorage.length; i++) {
|
|
70
|
+
const key = window.localStorage.key(i);
|
|
71
|
+
if (key?.startsWith(PERSIST_PREFIX)) keys.push(key);
|
|
72
|
+
}
|
|
73
|
+
for (const key of keys) {
|
|
74
|
+
try {
|
|
75
|
+
const entry = ls.get(key);
|
|
76
|
+
if (!entry || matchesFilter(entry, filter)) ls.remove(key);
|
|
77
|
+
} catch {
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
function toItems(result) {
|
|
82
|
+
if (Array.isArray(result)) return result;
|
|
83
|
+
return result ? [result] : [];
|
|
84
|
+
}
|
|
85
|
+
export function createModelBatch(options = {}) {
|
|
86
|
+
const operations = options.operations ?? (() => useGraphqlBridge().graphqlOperation);
|
|
87
|
+
const apiPost = options.apiPost ?? ((url, body) => useApi().postPromise(url, body));
|
|
88
|
+
const runWithContext = options.runWithContext ?? ((fn) => fn());
|
|
89
|
+
const specs = /* @__PURE__ */ new Map();
|
|
90
|
+
const rawKeys = /* @__PURE__ */ new Map();
|
|
91
|
+
const rawKey = (signature, id) => rawKeys.has(signature + "\0" + id) ? rawKeys.get(signature + "\0" + id) : id;
|
|
92
|
+
async function callOperation(name, fields, variables) {
|
|
93
|
+
const operation = operations()?.[name];
|
|
94
|
+
return toItems(typeof operation?.call === "function" ? await operation.call(fields, variables) : await useGraphQlOperation("Query", name, fields, variables));
|
|
95
|
+
}
|
|
96
|
+
function indexResult(spec, keys, items) {
|
|
97
|
+
const byKey = /* @__PURE__ */ new Map();
|
|
98
|
+
for (const item of items) {
|
|
99
|
+
const value = item?.[spec.batchMatch];
|
|
100
|
+
if (value !== null && value !== void 0 && !byKey.has(String(value))) byKey.set(String(value), item);
|
|
101
|
+
}
|
|
102
|
+
return new Map(keys.map((key) => [key, byKey.get(key) ?? null]));
|
|
103
|
+
}
|
|
104
|
+
const lookup = createBatchLookup({
|
|
105
|
+
maxBatchSize: (signature) => {
|
|
106
|
+
const spec = specs.get(signature);
|
|
107
|
+
const batched = !spec || spec.api || runWithContext(() => !!operations()?.[spec.batchOperation]);
|
|
108
|
+
return batched ? options.maxBatchSize ?? 100 : 1;
|
|
109
|
+
},
|
|
110
|
+
maxAttempts: options.maxAttempts ?? 3,
|
|
111
|
+
retryDelay: options.retryDelay,
|
|
112
|
+
isRetryable: (error) => !(error instanceof ModelBatchOperationMissingError),
|
|
113
|
+
onError: (signature, keys, error) => {
|
|
114
|
+
const spec = specs.get(signature);
|
|
115
|
+
console.warn(`[useModelBatch] could not load ${spec?.batchOperation ?? signature}: ${keys.join(", ")}`, error);
|
|
116
|
+
},
|
|
117
|
+
fetch: (signature, keys) => runWithContext(async () => {
|
|
118
|
+
const spec = specs.get(signature);
|
|
119
|
+
const listVariables = { ...spec.modelBy, [spec.batchVariable]: keys.map((key) => rawKey(signature, key)) };
|
|
120
|
+
if (spec.api) {
|
|
121
|
+
const result = await apiPost(buildApiEndpoint(spec.batchOperation), { fields: spec.fields ?? [], variables: listVariables });
|
|
122
|
+
return indexResult(spec, keys, toItems(result));
|
|
123
|
+
}
|
|
124
|
+
const ops = operations() ?? {};
|
|
125
|
+
if (ops[spec.batchOperation]) {
|
|
126
|
+
return indexResult(spec, keys, await callOperation(spec.batchOperation, spec.fields, listVariables));
|
|
127
|
+
}
|
|
128
|
+
if (ops[spec.modelName]) {
|
|
129
|
+
const results = await Promise.all(keys.map((key) => callOperation(spec.modelName, spec.fields, { ...spec.modelBy, [spec.batchKey]: rawKey(signature, key) })));
|
|
130
|
+
const items = results.flat();
|
|
131
|
+
if (keys.length === 1 && items.length === 1 && items[0]?.[spec.batchMatch] === void 0) return /* @__PURE__ */ new Map([[keys[0], items[0]]]);
|
|
132
|
+
return indexResult(spec, keys, items);
|
|
133
|
+
}
|
|
134
|
+
throw new ModelBatchOperationMissingError(spec);
|
|
135
|
+
})
|
|
136
|
+
});
|
|
137
|
+
function register(spec) {
|
|
138
|
+
const normalized = normalizeSpec(spec);
|
|
139
|
+
const signature = signatureOf(normalized);
|
|
140
|
+
if (!specs.has(signature)) specs.set(signature, normalized);
|
|
141
|
+
return { signature, spec: specs.get(signature) };
|
|
142
|
+
}
|
|
143
|
+
function request(spec, key, requestOptions = {}) {
|
|
144
|
+
const { signature, spec: normalized } = register(spec);
|
|
145
|
+
const id = normalizeKey(key);
|
|
146
|
+
if (!rawKeys.has(signature + "\0" + id)) rawKeys.set(signature + "\0" + id, key);
|
|
147
|
+
const existing = lookup.get(signature, id);
|
|
148
|
+
const ttl = resolveCacheTtlSeconds(requestOptions.cache);
|
|
149
|
+
if (ttl > 0 && (!existing || existing.status === "error")) {
|
|
150
|
+
const persisted = readPersisted(signature, id);
|
|
151
|
+
if (persisted) lookup.prime(signature, id, persisted);
|
|
152
|
+
}
|
|
153
|
+
const settled = lookup.request(signature, id);
|
|
154
|
+
if (ttl > 0) {
|
|
155
|
+
settled.then((entry) => {
|
|
156
|
+
if (entry.status === "loaded" && entry.attempts > 0 && entry.value) writePersisted(signature, normalized, id, entry.value, ttl);
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
return settled;
|
|
160
|
+
}
|
|
161
|
+
function clear(filter) {
|
|
162
|
+
for (const [signature, spec] of specs) {
|
|
163
|
+
if (matchesFilter(spec, filter)) lookup.clear(signature);
|
|
164
|
+
}
|
|
165
|
+
removePersisted(filter);
|
|
166
|
+
}
|
|
167
|
+
return {
|
|
168
|
+
get: (spec, key) => lookup.get(signatureOf(normalizeSpec(spec)), normalizeKey(key)),
|
|
169
|
+
request,
|
|
170
|
+
clear
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
const instances = /* @__PURE__ */ new WeakMap();
|
|
174
|
+
let fallbackInstance;
|
|
175
|
+
export function useModelBatch() {
|
|
176
|
+
let nuxtApp;
|
|
177
|
+
try {
|
|
178
|
+
nuxtApp = useNuxtApp();
|
|
179
|
+
} catch {
|
|
180
|
+
nuxtApp = void 0;
|
|
181
|
+
}
|
|
182
|
+
if (!nuxtApp || typeof nuxtApp !== "object") return fallbackInstance ??= createModelBatch();
|
|
183
|
+
let instance = instances.get(nuxtApp);
|
|
184
|
+
if (!instance) {
|
|
185
|
+
const app = nuxtApp;
|
|
186
|
+
instance = createModelBatch({
|
|
187
|
+
runWithContext: typeof app.runWithContext === "function" ? (fn) => app.runWithContext(fn) : void 0
|
|
188
|
+
});
|
|
189
|
+
instances.set(nuxtApp, instance);
|
|
190
|
+
}
|
|
191
|
+
return instance;
|
|
192
|
+
}
|
|
@@ -5,8 +5,8 @@ interface Props {
|
|
|
5
5
|
}
|
|
6
6
|
declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
7
7
|
modelValue: number;
|
|
8
|
-
decimal: number;
|
|
9
8
|
currency: string;
|
|
9
|
+
decimal: number;
|
|
10
10
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
11
11
|
declare const _default: typeof __VLS_export;
|
|
12
12
|
export default _default;
|
|
@@ -5,8 +5,8 @@ interface Props {
|
|
|
5
5
|
}
|
|
6
6
|
declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
7
7
|
modelValue: number;
|
|
8
|
-
decimal: number;
|
|
9
8
|
currency: string;
|
|
9
|
+
decimal: number;
|
|
10
10
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
11
11
|
declare const _default: typeof __VLS_export;
|
|
12
12
|
export default _default;
|
|
@@ -2,10 +2,10 @@ import { VTextField } from 'vuetify/components/VTextField';
|
|
|
2
2
|
export interface Props extends /* @vue-ignore */ InstanceType<typeof VTextField['$props']> {
|
|
3
3
|
type: 'eReceipt' | 'telephone';
|
|
4
4
|
}
|
|
5
|
-
declare
|
|
6
|
-
|
|
7
|
-
[K in NonNullable<typeof __VLS_12>]?: (props: typeof __VLS_13) => any;
|
|
5
|
+
declare const __VLS_template: () => {
|
|
6
|
+
__VLS_Slots: {};
|
|
8
7
|
};
|
|
8
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
9
9
|
declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
10
10
|
"update:modelValue": (value: string) => any;
|
|
11
11
|
}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
|
|
@@ -2,10 +2,10 @@ import { VTextField } from 'vuetify/components/VTextField';
|
|
|
2
2
|
export interface Props extends /* @vue-ignore */ InstanceType<typeof VTextField['$props']> {
|
|
3
3
|
type: 'eReceipt' | 'telephone';
|
|
4
4
|
}
|
|
5
|
-
declare
|
|
6
|
-
|
|
7
|
-
[K in NonNullable<typeof __VLS_12>]?: (props: typeof __VLS_13) => any;
|
|
5
|
+
declare const __VLS_template: () => {
|
|
6
|
+
__VLS_Slots: {};
|
|
8
7
|
};
|
|
8
|
+
type __VLS_Slots = ReturnType<typeof __VLS_template>['__VLS_Slots'];
|
|
9
9
|
declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
10
10
|
"update:modelValue": (value: string) => any;
|
|
11
11
|
}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
|
|
2
2
|
export default _default;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("
|
|
1
|
+
declare const _default: import("nuxt/app").Plugin<Record<string, unknown>> & import("nuxt/app").ObjectPlugin<Record<string, unknown>>;
|
|
2
2
|
export default _default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramathibodi/nuxt-commons",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.28",
|
|
4
4
|
"description": "Ramathibodi Nuxt modules for common components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -54,7 +54,7 @@
|
|
|
54
54
|
"docs:api:composables": "typedoc --options docs/typedoc.json",
|
|
55
55
|
"docs:api:composables:md": "npm run docs:ai:summary && node scripts/generate-composables-md.mjs",
|
|
56
56
|
"docs:api": "npm run docs:api:components && npm run docs:api:composables",
|
|
57
|
-
"docs:ai:summary": "node scripts/generate-ai-summary.mjs",
|
|
57
|
+
"docs:ai:summary": "node scripts/generate-ai-summary.mjs && node scripts/build-input-attribute-catalog.mjs",
|
|
58
58
|
"release": "npm run lint && npm run test && npm run prepack && node scripts/release.mjs",
|
|
59
59
|
"lint": "eslint .",
|
|
60
60
|
"lint:fix": "eslint . --fix",
|
|
@@ -0,0 +1,133 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Builds the prop catalog that `<DocumentTemplateInputAttributesHelper>` shows next to
|
|
4
|
+
* "Input Attributes" in the document template item form (#281).
|
|
5
|
+
*
|
|
6
|
+
* Sources:
|
|
7
|
+
* - `vuetify/dist/json/attributes.json` (keys `VTextField/variant` → `{ type, description }`),
|
|
8
|
+
* limited to the Vuetify tags listed in `VUETIFY_TAGS`.
|
|
9
|
+
* - `docs/ai-summary.json`: every component of this module, tagged by its path
|
|
10
|
+
* (`components/form/Date.vue` → `FormDate`).
|
|
11
|
+
*
|
|
12
|
+
* Output: `src/runtime/composables/document/inputAttributeCatalog.generated.json`
|
|
13
|
+
* { vuetify: "<version>", tags: { <Tag>: [[kebab-name, type, description, values?], …] } }
|
|
14
|
+
*
|
|
15
|
+
* The output is deterministic (sorted, no timestamp), so
|
|
16
|
+
* `test/runtime/composables/document/inputAttributeCatalog.test.ts` can fail when it is out of
|
|
17
|
+
* sync with its sources. Regenerate with `pnpm run docs:ai:summary` (runs this script last).
|
|
18
|
+
*/
|
|
19
|
+
import { readFileSync, writeFileSync } from 'node:fs'
|
|
20
|
+
import { dirname, resolve } from 'node:path'
|
|
21
|
+
import { fileURLToPath } from 'node:url'
|
|
22
|
+
import { createRequire } from 'node:module'
|
|
23
|
+
|
|
24
|
+
const ROOT = resolve(dirname(fileURLToPath(import.meta.url)), '..')
|
|
25
|
+
export const CATALOG_PATH = resolve(ROOT, 'src/runtime/composables/document/inputAttributeCatalog.generated.json')
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Vuetify tags in the catalog: every tag a built-in input type renders or forwards attributes
|
|
29
|
+
* to, plus the common form inputs an app-registered type is likely to wrap
|
|
30
|
+
* (`attributesFrom: ['VAutocomplete']`). Tags missing from the installed Vuetify are skipped.
|
|
31
|
+
*/
|
|
32
|
+
export const VUETIFY_TAGS = [
|
|
33
|
+
'VAutocomplete', 'VBtnToggle', 'VCard', 'VCheckbox', 'VCheckboxBtn', 'VChipGroup',
|
|
34
|
+
'VColorPicker', 'VCombobox', 'VDatePicker', 'VField', 'VFileInput', 'VInput',
|
|
35
|
+
'VNumberInput', 'VOtpInput', 'VRadio', 'VRadioGroup', 'VRangeSlider', 'VRating',
|
|
36
|
+
'VSelect', 'VSlider', 'VSwitch', 'VTextField', 'VTextarea', 'VTimePicker',
|
|
37
|
+
]
|
|
38
|
+
|
|
39
|
+
const MAX_TYPE_LENGTH = 120
|
|
40
|
+
|
|
41
|
+
export function toKebab(name) {
|
|
42
|
+
return String(name).replace(/([a-z0-9])([A-Z])/g, '$1-$2').toLowerCase()
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `components/form/images/Field.vue` → `FormImagesField` (module.ts path-based prefix). */
|
|
46
|
+
export function componentTagFromPath(path) {
|
|
47
|
+
const rel = String(path).replace(/\\/g, '/').replace(/^.*?src\/runtime\/components\//, '').replace(/\.vue$/, '')
|
|
48
|
+
return rel.split('/').map(seg => seg.charAt(0).toUpperCase() + seg.slice(1)).join('')
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
const PRIMITIVE_TYPES = new Set(['string', 'number', 'boolean', 'null', 'undefined'])
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Quoted string literals of a flat union type: `'a' | 'b' | string` → `['a', 'b']`.
|
|
55
|
+
* Returns `undefined` for anything else (arrays, generics, functions such as `('a' | 'b')[]`),
|
|
56
|
+
* so the helper never offers a value the prop would reject.
|
|
57
|
+
*/
|
|
58
|
+
export function parseEnumValues(type) {
|
|
59
|
+
if (!type) return undefined
|
|
60
|
+
const parts = String(type).split('|').map(part => part.trim()).filter(Boolean)
|
|
61
|
+
const isLiteral = part => /^'[^']*'$/.test(part)
|
|
62
|
+
if (!parts.every(part => isLiteral(part) || PRIMITIVE_TYPES.has(part))) return undefined
|
|
63
|
+
const values = parts.filter(isLiteral).map(part => part.slice(1, -1))
|
|
64
|
+
return values.length ? values : undefined
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function compactType(type) {
|
|
68
|
+
const flat = String(type ?? '').replace(/\s+/g, ' ').trim().replace(/^\|\s*/, '')
|
|
69
|
+
return flat.length > MAX_TYPE_LENGTH ? `${flat.slice(0, MAX_TYPE_LENGTH - 1)}…` : flat
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function compactDescription(description) {
|
|
73
|
+
return String(description ?? '')
|
|
74
|
+
.replace(/\[([^\]]+)\]\([^)]*\)/g, '$1')
|
|
75
|
+
.replace(/\*\*([^*]+)\*\*/g, '$1')
|
|
76
|
+
.replace(/`([^`]+)`/g, '$1')
|
|
77
|
+
.replace(/\s+/g, ' ')
|
|
78
|
+
.trim()
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function toRow(name, type, description) {
|
|
82
|
+
const row = [toKebab(name), compactType(type), compactDescription(description)]
|
|
83
|
+
const values = parseEnumValues(type)
|
|
84
|
+
if (values) row.push(values)
|
|
85
|
+
return row
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function sortRows(rows) {
|
|
89
|
+
const seen = new Set()
|
|
90
|
+
return rows
|
|
91
|
+
.filter(row => (seen.has(row[0]) ? false : (seen.add(row[0]), true)))
|
|
92
|
+
.sort((a, b) => a[0].localeCompare(b[0]))
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function buildCatalog({ vuetifyAttributes, aiSummary, vuetifyVersion }) {
|
|
96
|
+
const tags = {}
|
|
97
|
+
for (const tag of VUETIFY_TAGS) {
|
|
98
|
+
const prefix = `${tag}/`
|
|
99
|
+
const rows = Object.entries(vuetifyAttributes)
|
|
100
|
+
.filter(([key]) => key.startsWith(prefix))
|
|
101
|
+
.map(([key, meta]) => toRow(key.slice(prefix.length), meta?.type, meta?.description))
|
|
102
|
+
if (rows.length) tags[tag] = sortRows(rows)
|
|
103
|
+
}
|
|
104
|
+
for (const component of aiSummary?.components ?? []) {
|
|
105
|
+
if (!component?.path || !Array.isArray(component.props) || component.props.length === 0) continue
|
|
106
|
+
tags[componentTagFromPath(component.path)] = sortRows(
|
|
107
|
+
component.props.map(prop => toRow(prop.name, prop.type, prop.description)),
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
const sorted = Object.fromEntries(Object.keys(tags).sort().map(tag => [tag, tags[tag]]))
|
|
111
|
+
return { vuetify: vuetifyVersion, tags: sorted }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export function loadSources() {
|
|
115
|
+
const require = createRequire(import.meta.url)
|
|
116
|
+
return {
|
|
117
|
+
vuetifyAttributes: require('vuetify/dist/json/attributes.json'),
|
|
118
|
+
vuetifyVersion: require('vuetify/package.json').version,
|
|
119
|
+
aiSummary: JSON.parse(readFileSync(resolve(ROOT, 'docs/ai-summary.json'), 'utf8')),
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** Stable serialization: one tag per line keeps diffs readable. */
|
|
124
|
+
export function serializeCatalog(catalog) {
|
|
125
|
+
const lines = Object.entries(catalog.tags).map(([tag, rows]) => ` ${JSON.stringify(tag)}: ${JSON.stringify(rows)}`)
|
|
126
|
+
return `{\n "vuetify": ${JSON.stringify(catalog.vuetify)},\n "tags": {\n${lines.join(',\n')}\n }\n}\n`
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (process.argv[1] && resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
|
|
130
|
+
const catalog = buildCatalog(loadSources())
|
|
131
|
+
writeFileSync(CATALOG_PATH, serializeCatalog(catalog))
|
|
132
|
+
console.log(`Input attribute catalog: ${Object.keys(catalog.tags).length} tags → ${CATALOG_PATH}`)
|
|
133
|
+
}
|