@ramathibodi/nuxt-commons 4.0.27 → 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 +71 -69
- package/dist/runtime/components/document/TemplateBuilderLiveView.vue.d.ts +71 -69
- 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/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 +652 -650
- package/dist/runtime/components/form/Pad.vue.d.ts +652 -650
- 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/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.js +4 -0
- 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,46 @@
|
|
|
1
|
+
import type { MaybeRefOrGetter, Ref } from 'vue';
|
|
2
|
+
import { type DocumentTemplateInputAttribute, type DocumentTemplateInputType } from './templateInputTypes.js';
|
|
3
|
+
/** Row shape of the generated catalog: `[kebab-name, type, description, values?]`. */
|
|
4
|
+
export type InputAttributeCatalogRow = [string, string, string, string[]?];
|
|
5
|
+
export interface InputAttributeCatalog {
|
|
6
|
+
vuetify?: string;
|
|
7
|
+
tags: Record<string, InputAttributeCatalogRow[]>;
|
|
8
|
+
}
|
|
9
|
+
/** The generated catalog, imported on first use so it stays out of the main bundle. */
|
|
10
|
+
export declare function loadInputAttributeCatalog(): Promise<InputAttributeCatalog>;
|
|
11
|
+
/** Kebab-case prop names already present in an `Input Attributes` string. */
|
|
12
|
+
export declare function parseInputAttributeNames(attrs: string | undefined | null): string[];
|
|
13
|
+
/**
|
|
14
|
+
* Put `snippet` (e.g. `variant="outlined"`) into `attrs`: it replaces the first existing
|
|
15
|
+
* occurrence of the prop (plain or `:`-bound) and drops any others, or is appended.
|
|
16
|
+
*/
|
|
17
|
+
export declare function insertInputAttribute(attrs: string | undefined | null, name: string, snippet: string): string;
|
|
18
|
+
/**
|
|
19
|
+
* The text inserted for a prop: `name="value"` for a chosen enum value, a bare `name` for a
|
|
20
|
+
* boolean, `name=""` for strings / enums / unknown types, `:name=""` for anything else
|
|
21
|
+
* (numbers, arrays, objects) so the value is read as an expression.
|
|
22
|
+
*/
|
|
23
|
+
export declare function inputAttributeSnippet(attribute: Pick<DocumentTemplateInputAttribute, 'name' | 'type' | 'values'>, value?: string): string;
|
|
24
|
+
/** A component's `props` option (array or object form) as helper rows: names and types. */
|
|
25
|
+
export declare function normalizeRuntimeProps(props: unknown): DocumentTemplateInputAttribute[];
|
|
26
|
+
/** Tags the helper reads for an entry: `attributesFrom`, else the input type itself. */
|
|
27
|
+
export declare function inputAttributeSources(entry: Pick<DocumentTemplateInputType, 'value' | 'attributesFrom'>): string[];
|
|
28
|
+
/** Names the renderer sets for an entry: `managedAttributes`, else the default renderer's set. */
|
|
29
|
+
export declare function managedInputAttributeNames(entry: Pick<DocumentTemplateInputType, 'managedAttributes' | 'render'>): string[];
|
|
30
|
+
/**
|
|
31
|
+
* Merge the props of an entry's source tags. Pure: `runtime` holds the props read from
|
|
32
|
+
* registered components for tags missing from the catalog. Earlier tags win on a name
|
|
33
|
+
* collision (gaps are filled from later ones), `entry.attributes` override, managed props
|
|
34
|
+
* are flagged and listed last.
|
|
35
|
+
*/
|
|
36
|
+
export declare function resolveInputAttributes(entry: Pick<DocumentTemplateInputType, 'value' | 'attributesFrom' | 'managedAttributes' | 'attributes' | 'render'>, catalog: InputAttributeCatalog | undefined, runtime?: Record<string, DocumentTemplateInputAttribute[] | undefined>): DocumentTemplateInputAttribute[];
|
|
37
|
+
/**
|
|
38
|
+
* Reactive prop list for an input type, for the "Available props" helper. Re-resolves when
|
|
39
|
+
* `inputType` changes; the registry is read at that moment, so an entry registered later is
|
|
40
|
+
* picked up on the next change. Call it in a component `setup` so app-registered components
|
|
41
|
+
* can be looked up.
|
|
42
|
+
*/
|
|
43
|
+
export declare function useInputAttributeCatalog(inputType: MaybeRefOrGetter<string | undefined>): {
|
|
44
|
+
attributes: Ref<DocumentTemplateInputAttribute[]>;
|
|
45
|
+
isLoading: Ref<boolean>;
|
|
46
|
+
};
|
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
import { getCurrentInstance, ref, toValue, watch } from "vue";
|
|
2
|
+
import {
|
|
3
|
+
DEFAULT_MANAGED_INPUT_ATTRIBUTES,
|
|
4
|
+
getDocumentTemplateInputTypeEntry
|
|
5
|
+
} from "./templateInputTypes.js";
|
|
6
|
+
const kebab = (name) => String(name).replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
|
|
7
|
+
let catalogPromise;
|
|
8
|
+
export function loadInputAttributeCatalog() {
|
|
9
|
+
catalogPromise ??= import("./inputAttributeCatalog.generated.json").then((mod) => mod.default ?? mod).catch((error) => {
|
|
10
|
+
catalogPromise = void 0;
|
|
11
|
+
throw error;
|
|
12
|
+
});
|
|
13
|
+
return catalogPromise;
|
|
14
|
+
}
|
|
15
|
+
function tokenizeInputAttributes(attrs) {
|
|
16
|
+
const tokens = [];
|
|
17
|
+
const text = attrs ?? "";
|
|
18
|
+
let i = 0;
|
|
19
|
+
while (i < text.length) {
|
|
20
|
+
while (i < text.length && /\s/.test(text[i])) i++;
|
|
21
|
+
if (i >= text.length) break;
|
|
22
|
+
const start = i;
|
|
23
|
+
while (i < text.length && !/[\s=]/.test(text[i])) i++;
|
|
24
|
+
const rawName = text.slice(start, i);
|
|
25
|
+
let j = i;
|
|
26
|
+
while (j < text.length && /\s/.test(text[j])) j++;
|
|
27
|
+
if (text[j] === "=") {
|
|
28
|
+
j++;
|
|
29
|
+
while (j < text.length && /\s/.test(text[j])) j++;
|
|
30
|
+
const quote = text[j];
|
|
31
|
+
if (quote === '"' || quote === "'") {
|
|
32
|
+
const close = text.indexOf(quote, j + 1);
|
|
33
|
+
j = close === -1 ? text.length : close + 1;
|
|
34
|
+
} else {
|
|
35
|
+
while (j < text.length && !/\s/.test(text[j])) j++;
|
|
36
|
+
}
|
|
37
|
+
i = j;
|
|
38
|
+
}
|
|
39
|
+
const name = normalizeAttributeName(rawName);
|
|
40
|
+
if (name) tokens.push({ name, start, end: i });
|
|
41
|
+
}
|
|
42
|
+
return tokens;
|
|
43
|
+
}
|
|
44
|
+
function normalizeAttributeName(raw) {
|
|
45
|
+
if (!raw) return void 0;
|
|
46
|
+
let name = raw;
|
|
47
|
+
if (name.startsWith("v-bind:")) name = name.slice("v-bind:".length);
|
|
48
|
+
else if (name.startsWith(":")) name = name.slice(1);
|
|
49
|
+
else if (name.startsWith("@") || name.startsWith("#") || name.startsWith("v-")) return void 0;
|
|
50
|
+
name = name.replace(/\..*$/, "");
|
|
51
|
+
if (!name || name.startsWith("[")) return void 0;
|
|
52
|
+
return kebab(name);
|
|
53
|
+
}
|
|
54
|
+
export function parseInputAttributeNames(attrs) {
|
|
55
|
+
return [...new Set(tokenizeInputAttributes(attrs ?? "").map((token) => token.name))];
|
|
56
|
+
}
|
|
57
|
+
export function insertInputAttribute(attrs, name, snippet) {
|
|
58
|
+
const text = attrs ?? "";
|
|
59
|
+
const target = kebab(name);
|
|
60
|
+
const matches = tokenizeInputAttributes(text).filter((token) => token.name === target);
|
|
61
|
+
if (matches.length === 0) return `${text.trim()} ${snippet}`.trim();
|
|
62
|
+
let result = text;
|
|
63
|
+
for (let k = matches.length - 1; k >= 0; k--) {
|
|
64
|
+
const { end } = matches[k];
|
|
65
|
+
let { start } = matches[k];
|
|
66
|
+
if (k > 0) while (start > 0 && /\s/.test(result[start - 1])) start--;
|
|
67
|
+
result = result.slice(0, start) + (k === 0 ? snippet : "") + result.slice(end);
|
|
68
|
+
}
|
|
69
|
+
return result.trim();
|
|
70
|
+
}
|
|
71
|
+
export function inputAttributeSnippet(attribute, value) {
|
|
72
|
+
const name = kebab(attribute.name);
|
|
73
|
+
if (value !== void 0) return `${name}="${value}"`;
|
|
74
|
+
const type = (attribute.type ?? "").trim();
|
|
75
|
+
if (type === "boolean") return name;
|
|
76
|
+
if (!type || attribute.values?.length || /\bstring\b/.test(type)) return `${name}=""`;
|
|
77
|
+
return `:${name}=""`;
|
|
78
|
+
}
|
|
79
|
+
const CONSTRUCTOR_TYPES = {
|
|
80
|
+
String: "string",
|
|
81
|
+
Number: "number",
|
|
82
|
+
Boolean: "boolean",
|
|
83
|
+
Array: "array",
|
|
84
|
+
Object: "object",
|
|
85
|
+
Function: "function"
|
|
86
|
+
};
|
|
87
|
+
function runtimeTypeName(type) {
|
|
88
|
+
if (type == null || type === true) return void 0;
|
|
89
|
+
if (Array.isArray(type)) {
|
|
90
|
+
const names = type.map(runtimeTypeName).filter(Boolean);
|
|
91
|
+
return names.length ? [...new Set(names)].join(" | ") : void 0;
|
|
92
|
+
}
|
|
93
|
+
if (typeof type === "function") return CONSTRUCTOR_TYPES[type.name] ?? type.name ?? void 0;
|
|
94
|
+
if (typeof type === "object" && "type" in type) return runtimeTypeName(type.type);
|
|
95
|
+
return void 0;
|
|
96
|
+
}
|
|
97
|
+
export function normalizeRuntimeProps(props) {
|
|
98
|
+
if (!props) return [];
|
|
99
|
+
if (Array.isArray(props)) return props.filter((p) => typeof p === "string").map((name) => ({ name: kebab(name) }));
|
|
100
|
+
if (typeof props !== "object") return [];
|
|
101
|
+
return Object.entries(props).map(([name, definition]) => {
|
|
102
|
+
const type = runtimeTypeName(definition);
|
|
103
|
+
return type ? { name: kebab(name), type } : { name: kebab(name) };
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
function catalogAttributes(catalog, tag) {
|
|
107
|
+
const rows = catalog?.tags?.[tag];
|
|
108
|
+
if (!rows) return void 0;
|
|
109
|
+
return rows.map(([name, type, description, values]) => {
|
|
110
|
+
const attribute = { name, type, description };
|
|
111
|
+
if (values?.length) attribute.values = values;
|
|
112
|
+
return attribute;
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
export function inputAttributeSources(entry) {
|
|
116
|
+
return entry.attributesFrom ?? (entry.value ? [entry.value] : []);
|
|
117
|
+
}
|
|
118
|
+
export function managedInputAttributeNames(entry) {
|
|
119
|
+
if (entry.managedAttributes) return entry.managedAttributes.map(kebab);
|
|
120
|
+
return entry.render ? [] : [...DEFAULT_MANAGED_INPUT_ATTRIBUTES];
|
|
121
|
+
}
|
|
122
|
+
export function resolveInputAttributes(entry, catalog, runtime = {}) {
|
|
123
|
+
const byName = /* @__PURE__ */ new Map();
|
|
124
|
+
for (const tag of inputAttributeSources(entry)) {
|
|
125
|
+
for (const attribute of catalogAttributes(catalog, tag) ?? runtime[tag] ?? []) {
|
|
126
|
+
const name = kebab(attribute.name);
|
|
127
|
+
const existing = byName.get(name);
|
|
128
|
+
if (!existing) {
|
|
129
|
+
byName.set(name, { ...attribute, name, source: tag });
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
existing.type ||= attribute.type;
|
|
133
|
+
existing.description ||= attribute.description;
|
|
134
|
+
existing.values ??= attribute.values;
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
for (const override of entry.attributes ?? []) {
|
|
138
|
+
if (!override?.name) continue;
|
|
139
|
+
const name = kebab(override.name);
|
|
140
|
+
const existing = byName.get(name);
|
|
141
|
+
const defined = Object.fromEntries(Object.entries(override).filter(([, value]) => value !== void 0));
|
|
142
|
+
byName.set(name, { ...existing, ...defined, name, source: override.source ?? existing?.source ?? entry.value });
|
|
143
|
+
}
|
|
144
|
+
const managed = new Set(managedInputAttributeNames(entry));
|
|
145
|
+
const attributes = [...byName.values()].map(
|
|
146
|
+
(attribute) => managed.has(attribute.name) ? { ...attribute, managed: true } : { ...attribute, managed: false }
|
|
147
|
+
);
|
|
148
|
+
return [...attributes.filter((a) => !a.managed), ...attributes.filter((a) => a.managed)];
|
|
149
|
+
}
|
|
150
|
+
function camelize(value) {
|
|
151
|
+
return value.replace(/-(\w)/g, (_, c) => c.toUpperCase());
|
|
152
|
+
}
|
|
153
|
+
function lookupRegisteredComponent(components, tag) {
|
|
154
|
+
if (!components) return void 0;
|
|
155
|
+
const camel = camelize(tag);
|
|
156
|
+
return components[tag] ?? components[camel] ?? components[camel.charAt(0).toUpperCase() + camel.slice(1)] ?? components[kebab(tag)];
|
|
157
|
+
}
|
|
158
|
+
async function readRegisteredComponentProps(components, tag) {
|
|
159
|
+
let definition = lookupRegisteredComponent(components, tag);
|
|
160
|
+
if (!definition) return void 0;
|
|
161
|
+
if (typeof definition.__asyncLoader === "function") {
|
|
162
|
+
try {
|
|
163
|
+
await definition.__asyncLoader();
|
|
164
|
+
} catch {
|
|
165
|
+
return void 0;
|
|
166
|
+
}
|
|
167
|
+
definition = definition.__asyncResolved ?? definition;
|
|
168
|
+
}
|
|
169
|
+
return normalizeRuntimeProps(definition.props);
|
|
170
|
+
}
|
|
171
|
+
export function useInputAttributeCatalog(inputType) {
|
|
172
|
+
const attributes = ref([]);
|
|
173
|
+
const isLoading = ref(false);
|
|
174
|
+
const components = getCurrentInstance()?.appContext?.components;
|
|
175
|
+
let latest = 0;
|
|
176
|
+
watch(() => toValue(inputType), async (type) => {
|
|
177
|
+
const request = ++latest;
|
|
178
|
+
if (!type) {
|
|
179
|
+
attributes.value = [];
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const entry = getDocumentTemplateInputTypeEntry(type) ?? { label: type, value: type };
|
|
183
|
+
isLoading.value = true;
|
|
184
|
+
try {
|
|
185
|
+
const catalog = await loadInputAttributeCatalog().catch(() => void 0);
|
|
186
|
+
const runtime = {};
|
|
187
|
+
for (const tag of inputAttributeSources(entry)) {
|
|
188
|
+
if (!catalog?.tags?.[tag]) runtime[tag] = await readRegisteredComponentProps(components, tag);
|
|
189
|
+
}
|
|
190
|
+
if (request === latest) attributes.value = resolveInputAttributes(entry, catalog, runtime);
|
|
191
|
+
} finally {
|
|
192
|
+
if (request === latest) isLoading.value = false;
|
|
193
|
+
}
|
|
194
|
+
}, { immediate: true });
|
|
195
|
+
return { attributes, isLoading };
|
|
196
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { processTemplateFormTable } from "./templateFormTable.js";
|
|
2
2
|
import { processTemplateFormTableData } from "./templateFormTableData.js";
|
|
3
3
|
import { processTemplateFormHidden } from "./templateFormHidden.js";
|
|
4
|
+
import { processTemplateMasterLabel } from "./templateMasterLabel.js";
|
|
4
5
|
import { some, includes, cloneDeep } from "lodash-es";
|
|
5
6
|
import { migrateInputAttributes, migrateTemplateString } from "./templateMigrate.js";
|
|
6
7
|
import { getDocumentTemplateInputTypeEntry } from "./templateInputTypes.js";
|
|
@@ -89,6 +90,9 @@ export function templateItemToString(inputItem, parentTemplates, dataVariable =
|
|
|
89
90
|
case "LabelField":
|
|
90
91
|
templateString = `<LabelField v-model="${dataVariable}.${item.variableName || ""}" label="${item.inputLabel || item.variableName || ""}"${item.inputAttributes ? " " + item.inputAttributes : ""}/>`;
|
|
91
92
|
break;
|
|
93
|
+
case "MasterLabel":
|
|
94
|
+
templateString = processTemplateMasterLabel(item, dataVariable);
|
|
95
|
+
break;
|
|
92
96
|
case "Header":
|
|
93
97
|
templateString = `<div class="${optionString || "text-h4 font-weight-medium"}">${item.inputLabel || item.variableName || ""}</div>`;
|
|
94
98
|
break;
|
|
@@ -158,7 +158,43 @@ export interface DocumentTemplateInputType {
|
|
|
158
158
|
* the standard contract (different value prop, slot content, etc.).
|
|
159
159
|
*/
|
|
160
160
|
render?: DocumentTemplateInputTypeRenderer;
|
|
161
|
+
/**
|
|
162
|
+
* Tags whose props the "Available props" helper lists next to `Input Attributes`, in
|
|
163
|
+
* order (own component first). Default `[value]`. Name the inner component when this
|
|
164
|
+
* type forwards its attributes (e.g. a `.global` wrapper whose root is `<v-autocomplete>`
|
|
165
|
+
* → `['FormDepartment', 'VAutocomplete']`): forwarded props are not readable at runtime.
|
|
166
|
+
* `[]` lists nothing (the renderer drops `inputAttributes`).
|
|
167
|
+
*/
|
|
168
|
+
attributesFrom?: string[];
|
|
169
|
+
/**
|
|
170
|
+
* Props the renderer sets itself (kebab-case). The helper lists them greyed out and never
|
|
171
|
+
* inserts them. Default: {@link DEFAULT_MANAGED_INPUT_ATTRIBUTES} for an entry without
|
|
172
|
+
* `render` (the default `<Tag v-model label :rules :active/>` emission), none otherwise.
|
|
173
|
+
*/
|
|
174
|
+
managedAttributes?: string[];
|
|
175
|
+
/**
|
|
176
|
+
* Prop docs that win over the catalog / runtime lookup, matched by kebab-case `name`. Use
|
|
177
|
+
* it to describe an app component's own props: the runtime lookup only sees names and
|
|
178
|
+
* types, not descriptions.
|
|
179
|
+
*/
|
|
180
|
+
attributes?: DocumentTemplateInputAttribute[];
|
|
181
|
+
}
|
|
182
|
+
/** One prop the "Available props" helper lists for an input type. */
|
|
183
|
+
export interface DocumentTemplateInputAttribute {
|
|
184
|
+
/** Kebab-case prop name, as written in `Input Attributes` (e.g. `persistent-hint`). */
|
|
185
|
+
name: string;
|
|
186
|
+
/** Type as declared (`boolean`, `'outlined' | 'filled'`, …). */
|
|
187
|
+
type?: string;
|
|
188
|
+
description?: string;
|
|
189
|
+
/** Allowed literal values of an enum-like prop; the helper offers each as a choice. */
|
|
190
|
+
values?: string[];
|
|
191
|
+
/** Tag the prop was found on (e.g. `VTextField`). Filled in by the helper. */
|
|
192
|
+
source?: string;
|
|
193
|
+
/** Set by the renderer; shown but not insertable. Filled in by the helper. */
|
|
194
|
+
managed?: boolean;
|
|
161
195
|
}
|
|
196
|
+
/** What the default renderer (`processDefaultTemplate`) always sets. */
|
|
197
|
+
export declare const DEFAULT_MANAGED_INPUT_ATTRIBUTES: readonly string[];
|
|
162
198
|
/**
|
|
163
199
|
* Built-in registry. One entry per inputType that `TemplateBuilder.vue`
|
|
164
200
|
* historically hard-coded. Flag values mirror the previous arrays
|
|
@@ -1,27 +1,94 @@
|
|
|
1
1
|
import { getCurrentScope, onScopeDispose } from "vue";
|
|
2
|
+
export const DEFAULT_MANAGED_INPUT_ATTRIBUTES = Object.freeze(["model-value", "label", "rules", "active"]);
|
|
3
|
+
const CHOICE_MANAGED_ATTRIBUTES = [...DEFAULT_MANAGED_INPUT_ATTRIBUTES, "items", "item-title", "item-value"];
|
|
2
4
|
export const BUILT_IN_DOCUMENT_TEMPLATE_INPUT_TYPES = Object.freeze([
|
|
5
|
+
// `attributesFrom` follows where each component forwards its attributes (`v-bind="$attrs"` or
|
|
6
|
+
// fallthrough to its root), so the "Available props" helper lists what actually applies.
|
|
3
7
|
{ label: "Text Field", value: "VTextField" },
|
|
4
8
|
{ label: "Text Area", value: "VTextarea" },
|
|
5
|
-
{ label: "Text Date Picker", value: "FormDate" },
|
|
6
|
-
{ label: "Text Time Picker", value: "FormTime" },
|
|
7
|
-
{ label: "Text Date & Time Picker", value: "FormDateTime" },
|
|
8
|
-
{ label: "Select Dropdown", value: "VSelect", requiresOptions: true, optionsAsChoice: true },
|
|
9
|
-
{ label: "Select Combobox", value: "VCombobox", requiresOptions: true, optionsAsChoice: true },
|
|
10
|
-
{ label: "Autocomplete", value: "VAutocomplete", requiresOptions: true, optionsAsChoice: true },
|
|
11
|
-
{
|
|
12
|
-
|
|
13
|
-
|
|
9
|
+
{ label: "Text Date Picker", value: "FormDate", attributesFrom: ["FormDate", "VTextField"] },
|
|
10
|
+
{ label: "Text Time Picker", value: "FormTime", attributesFrom: ["FormTime", "VTextField"] },
|
|
11
|
+
{ label: "Text Date & Time Picker", value: "FormDateTime", attributesFrom: ["FormDateTime", "FormDate", "VTextField"] },
|
|
12
|
+
{ label: "Select Dropdown", value: "VSelect", requiresOptions: true, optionsAsChoice: true, managedAttributes: CHOICE_MANAGED_ATTRIBUTES },
|
|
13
|
+
{ label: "Select Combobox", value: "VCombobox", requiresOptions: true, optionsAsChoice: true, managedAttributes: CHOICE_MANAGED_ATTRIBUTES },
|
|
14
|
+
{ label: "Autocomplete", value: "VAutocomplete", requiresOptions: true, optionsAsChoice: true, managedAttributes: CHOICE_MANAGED_ATTRIBUTES },
|
|
15
|
+
{
|
|
16
|
+
label: "Autocomplete from Master",
|
|
17
|
+
value: "MasterAutocomplete",
|
|
18
|
+
requiresOptions: true,
|
|
19
|
+
optionsLabel: "Group Key",
|
|
20
|
+
attributesFrom: ["MasterAutocomplete", "VAutocomplete"],
|
|
21
|
+
managedAttributes: [...CHOICE_MANAGED_ATTRIBUTES, "group-key"]
|
|
22
|
+
},
|
|
23
|
+
// inputAttributes land on <v-radio-group> AND on every <v-radio> (`radioChoiceToString`).
|
|
24
|
+
{
|
|
25
|
+
label: "Radio Buttons",
|
|
26
|
+
value: "VRadio",
|
|
27
|
+
requiresOptions: true,
|
|
28
|
+
optionsAsChoice: true,
|
|
29
|
+
attributesFrom: ["VRadioGroup", "VRadio"],
|
|
30
|
+
managedAttributes: ["model-value", "label", "rules", "value"]
|
|
31
|
+
},
|
|
32
|
+
{
|
|
33
|
+
label: "Radio Buttons Inline",
|
|
34
|
+
value: "VRadioInline",
|
|
35
|
+
requiresOptions: true,
|
|
36
|
+
optionsAsChoice: true,
|
|
37
|
+
attributesFrom: ["VRadioGroup", "VRadio"],
|
|
38
|
+
managedAttributes: ["model-value", "label", "rules", "value", "inline"]
|
|
39
|
+
},
|
|
14
40
|
{ label: "Checkbox", value: "VCheckbox" },
|
|
15
|
-
{
|
|
41
|
+
{
|
|
42
|
+
label: "Checkbox Group",
|
|
43
|
+
value: "FormCheckboxGroup",
|
|
44
|
+
requiresOptions: true,
|
|
45
|
+
optionsAsChoice: true,
|
|
46
|
+
attributesFrom: ["FormCheckboxGroup", "VInput"],
|
|
47
|
+
managedAttributes: [...DEFAULT_MANAGED_INPUT_ATTRIBUTES, "items"]
|
|
48
|
+
},
|
|
16
49
|
{ label: "Switch", value: "VSwitch" },
|
|
17
|
-
{ label: "File Upload", value: "FormFile", needsLabel: false, showsOptions: false },
|
|
18
|
-
{ label: "Images Field", value: "FormImagesField", showsOptions: false },
|
|
19
|
-
{ label: "Signature Pad", value: "FormSignPad" },
|
|
20
|
-
{
|
|
21
|
-
|
|
50
|
+
{ label: "File Upload", value: "FormFile", needsLabel: false, showsOptions: false, attributesFrom: ["FormFile", "VTextField"] },
|
|
51
|
+
{ label: "Images Field", value: "FormImagesField", showsOptions: false, attributesFrom: ["FormImagesField", "VInput"] },
|
|
52
|
+
{ label: "Signature Pad", value: "FormSignPad", attributesFrom: ["FormSignPad", "VInput"] },
|
|
53
|
+
{
|
|
54
|
+
label: "Table",
|
|
55
|
+
value: "FormTable",
|
|
56
|
+
requiresOptions: true,
|
|
57
|
+
hasSpecificOptionEditor: true,
|
|
58
|
+
attributesFrom: ["FormTable", "VInput"],
|
|
59
|
+
managedAttributes: [...DEFAULT_MANAGED_INPUT_ATTRIBUTES, "title", "headers"]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
label: "Table Data",
|
|
63
|
+
value: "FormTableData",
|
|
64
|
+
requiresOptions: true,
|
|
65
|
+
hasSpecificOptionEditor: true,
|
|
66
|
+
attributesFrom: ["FormTableData", "VInput"],
|
|
67
|
+
managedAttributes: [...DEFAULT_MANAGED_INPUT_ATTRIBUTES, "title", "headers", "items-initial", "data-template"]
|
|
68
|
+
},
|
|
22
69
|
// Read-only display of a bound value. Rendered by a dedicated arm in
|
|
23
70
|
// `template.ts` so the default `variant` / `:active` never reach LabelField's card.
|
|
24
|
-
{
|
|
71
|
+
{
|
|
72
|
+
label: "Label Field",
|
|
73
|
+
value: "LabelField",
|
|
74
|
+
showsOptions: false,
|
|
75
|
+
hidesValidationRules: true,
|
|
76
|
+
attributesFrom: ["LabelField", "VCard"],
|
|
77
|
+
managedAttributes: ["model-value", "label"]
|
|
78
|
+
},
|
|
79
|
+
// Read-only master-data name. `inputOptions` is `GROUP_KEY` (code from data.<variableName>) or
|
|
80
|
+
// `GROUP_KEY|ITEM_CODE` (fixed code, variableName optional); see `templateMasterLabel.ts`.
|
|
81
|
+
// Its Group Key / Fixed Item Code fields are the specific option editor in TemplateItemForm.
|
|
82
|
+
// inputAttributes go on the wrapping <LabelField> (or a plain <div> when there is no label).
|
|
83
|
+
{
|
|
84
|
+
label: "Master Label",
|
|
85
|
+
value: "MasterLabel",
|
|
86
|
+
requiresOptions: true,
|
|
87
|
+
hasSpecificOptionEditor: true,
|
|
88
|
+
hidesValidationRules: true,
|
|
89
|
+
attributesFrom: ["LabelField", "VCard"],
|
|
90
|
+
managedAttributes: ["label"]
|
|
91
|
+
},
|
|
25
92
|
{
|
|
26
93
|
label: "[Decoration] Header",
|
|
27
94
|
value: "Header",
|
|
@@ -51,7 +118,9 @@ export const BUILT_IN_DOCUMENT_TEMPLATE_INPUT_TYPES = Object.freeze([
|
|
|
51
118
|
hasSpecificOptionEditor: true,
|
|
52
119
|
hidesValidationRules: true,
|
|
53
120
|
hidesColumnAttributes: true,
|
|
54
|
-
hidesClassAndStyle: true
|
|
121
|
+
hidesClassAndStyle: true,
|
|
122
|
+
// `processTemplateFormHidden` does not emit inputAttributes, so no prop would apply.
|
|
123
|
+
attributesFrom: []
|
|
55
124
|
},
|
|
56
125
|
{
|
|
57
126
|
label: "[Advanced] Inherit Form",
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MasterLabel template helpers: the `inputOptions` format of the `MasterLabel` input type and its renderer.
|
|
3
|
+
*
|
|
4
|
+
* `inputOptions` is a string holding either `GROUP_KEY` (bound mode: the item code is read from
|
|
5
|
+
* `data.<variableName>`) or `GROUP_KEY|ITEM_CODE` (fixed mode: a literal item code; `variableName`
|
|
6
|
+
* is not needed). A fixed code wins when both are set.
|
|
7
|
+
* This doc block is consumed by vue-docgen for generated API documentation.
|
|
8
|
+
*/
|
|
9
|
+
import type { DocumentTemplateItem } from './template.js';
|
|
10
|
+
export interface MasterLabelOptions {
|
|
11
|
+
groupKey: string;
|
|
12
|
+
itemCode: string;
|
|
13
|
+
}
|
|
14
|
+
/** Split `GROUP_KEY|ITEM_CODE` at the first `|`. A non-string gives empty parts. */
|
|
15
|
+
export declare function parseMasterLabelOptions(options: unknown): MasterLabelOptions;
|
|
16
|
+
/**
|
|
17
|
+
* Inverse of `parseMasterLabelOptions`: a bare group key when the fixed code is blank. Values are
|
|
18
|
+
* kept as typed (the editor writes on every keystroke; `parseMasterLabelOptions` trims on read).
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatMasterLabelOptions(groupKey: string | null | undefined, itemCode: string | null | undefined): string;
|
|
21
|
+
/** `true` for a `MasterLabel` item whose `inputOptions` carries a fixed item code. */
|
|
22
|
+
export declare function isMasterLabelFixed(item: {
|
|
23
|
+
inputType?: string;
|
|
24
|
+
inputOptions?: unknown;
|
|
25
|
+
}): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Render a `MasterLabel` item. With a caption (`inputLabel`, or `variableName` in bound mode) the
|
|
28
|
+
* name is shown in `<LabelField>`'s `#value` slot, so it lays out like a Label Field; without one,
|
|
29
|
+
* a plain `<div>` holds it. `inputAttributes` (with `conditionalDisplay` already folded in as
|
|
30
|
+
* `v-if`) go on that outer element.
|
|
31
|
+
*/
|
|
32
|
+
export declare function processTemplateMasterLabel(item: DocumentTemplateItem, dataVariable?: string): string;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export function parseMasterLabelOptions(options) {
|
|
2
|
+
if (typeof options !== "string") return { groupKey: "", itemCode: "" };
|
|
3
|
+
const pipe = options.indexOf("|");
|
|
4
|
+
if (pipe < 0) return { groupKey: options.trim(), itemCode: "" };
|
|
5
|
+
return { groupKey: options.slice(0, pipe).trim(), itemCode: options.slice(pipe + 1).trim() };
|
|
6
|
+
}
|
|
7
|
+
export function formatMasterLabelOptions(groupKey, itemCode) {
|
|
8
|
+
const key = groupKey ?? "";
|
|
9
|
+
const code = itemCode ?? "";
|
|
10
|
+
return code.trim() ? `${key}|${code}` : key;
|
|
11
|
+
}
|
|
12
|
+
export function isMasterLabelFixed(item) {
|
|
13
|
+
return item.inputType === "MasterLabel" && parseMasterLabelOptions(item.inputOptions).itemCode !== "";
|
|
14
|
+
}
|
|
15
|
+
function escapeAttribute(value) {
|
|
16
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
17
|
+
}
|
|
18
|
+
export function processTemplateMasterLabel(item, dataVariable = "data") {
|
|
19
|
+
const { groupKey, itemCode } = parseMasterLabelOptions(item.inputOptions);
|
|
20
|
+
const variableName = item.variableName?.trim() || "";
|
|
21
|
+
const fixed = itemCode !== "";
|
|
22
|
+
let codeBinding = "";
|
|
23
|
+
if (fixed) codeBinding = ` item-code="${escapeAttribute(itemCode)}"`;
|
|
24
|
+
else if (variableName) codeBinding = ` :item-code="${dataVariable}.${variableName}"`;
|
|
25
|
+
const master = `<MasterLabel group-key="${escapeAttribute(groupKey)}"${codeBinding}/>`;
|
|
26
|
+
const attributes = item.inputAttributes?.trim() ? ` ${item.inputAttributes.trim()}` : "";
|
|
27
|
+
const caption = item.inputLabel || (fixed ? "" : variableName);
|
|
28
|
+
if (!caption) return `<div${attributes}>${master}</div>`;
|
|
29
|
+
return `<LabelField label="${escapeAttribute(caption)}"${attributes}><template #value>${master}</template></LabelField>`;
|
|
30
|
+
}
|
|
@@ -4,6 +4,7 @@ import { validationRulesRegex } from "./template.js";
|
|
|
4
4
|
import {
|
|
5
5
|
getDocumentTemplateInputTypeEntry
|
|
6
6
|
} from "./templateInputTypes.js";
|
|
7
|
+
import { isMasterLabelFixed, parseMasterLabelOptions } from "./templateMasterLabel.js";
|
|
7
8
|
const CHOICE_STRING_REGEX = /^[^'",]+(,[^'",]+)*$/;
|
|
8
9
|
const VARIABLE_NAME_REGEX = /^[A-Za-z_$][\w$]*(\.[A-Za-z_$][\w$]*)*$/;
|
|
9
10
|
const KNOWN_ITEM_KEYS = /* @__PURE__ */ new Set([
|
|
@@ -85,7 +86,9 @@ function validateItem(item, path, siblingVarCounts, push) {
|
|
|
85
86
|
const variableName = typeof item.variableName === "string" ? item.variableName.trim() : "";
|
|
86
87
|
if (needsVariableName) {
|
|
87
88
|
if (!variableName) {
|
|
88
|
-
|
|
89
|
+
if (!isMasterLabelFixed(item)) {
|
|
90
|
+
push(`${path}.variableName`, "VARIABLE_NAME_REQUIRED", `${inputType} requires a variableName.`, "warning");
|
|
91
|
+
}
|
|
89
92
|
} else if (!VARIABLE_NAME_REGEX.test(variableName)) {
|
|
90
93
|
push(
|
|
91
94
|
`${path}.variableName`,
|
|
@@ -198,6 +201,13 @@ function validateInputOptions(item, path, ctx, push) {
|
|
|
198
201
|
push(optsPath, "OPTIONS_NOT_STRING", "MasterAutocomplete inputOptions must be a non-empty group-key string.", "warning");
|
|
199
202
|
}
|
|
200
203
|
return;
|
|
204
|
+
case "MasterLabel":
|
|
205
|
+
if (hasOptions && typeof opts !== "string") {
|
|
206
|
+
push(optsPath, "OPTIONS_NOT_STRING", 'MasterLabel inputOptions must be a "GROUP_KEY" or "GROUP_KEY|ITEM_CODE" string.', "warning");
|
|
207
|
+
} else if (parseMasterLabelOptions(opts).groupKey === "") {
|
|
208
|
+
push(optsPath, "OPTIONS_REQUIRED", 'MasterLabel requires a group key in inputOptions ("GROUP_KEY" or "GROUP_KEY|ITEM_CODE").', "warning");
|
|
209
|
+
}
|
|
210
|
+
return;
|
|
201
211
|
case "DocumentForm":
|
|
202
212
|
if (hasOptions && (typeof opts !== "string" || opts.trim() === "")) {
|
|
203
213
|
push(optsPath, "OPTIONS_NOT_STRING", "DocumentForm inputOptions must be the child template code (a non-empty string).", "warning");
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export declare const MASTER_ITEM_BATCH_OPERATION = "masterItemByGroupKeyAndItemCodeIn";
|
|
2
|
+
export declare const MASTER_ITEM_SINGLE_OPERATION = "masterItemByGroupKeyAndItemCode";
|
|
3
|
+
export interface MasterItemBatch {
|
|
4
|
+
/** Drop cached master items (memory + localStorage), for one group or all. */
|
|
5
|
+
clear: (groupKey?: string) => void;
|
|
6
|
+
}
|
|
7
|
+
export declare function useMasterItemBatch(): MasterItemBatch;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { useModelBatch } from "./modelBatch.js";
|
|
2
|
+
export const MASTER_ITEM_BATCH_OPERATION = "masterItemByGroupKeyAndItemCodeIn";
|
|
3
|
+
export const MASTER_ITEM_SINGLE_OPERATION = "masterItemByGroupKeyAndItemCode";
|
|
4
|
+
export function useMasterItemBatch() {
|
|
5
|
+
const batch = useModelBatch();
|
|
6
|
+
return {
|
|
7
|
+
clear: (groupKey) => batch.clear({
|
|
8
|
+
batchOperation: MASTER_ITEM_BATCH_OPERATION,
|
|
9
|
+
modelBy: groupKey === void 0 ? void 0 : { groupKey }
|
|
10
|
+
})
|
|
11
|
+
};
|
|
12
|
+
}
|
|
@@ -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 {};
|