@ramathibodi/nuxt-commons 4.0.27 → 4.0.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (118) hide show
  1. package/dist/module.json +2 -2
  2. package/dist/runtime/components/Calendar.d.vue.ts +12 -10
  3. package/dist/runtime/components/Calendar.vue.d.ts +12 -10
  4. package/dist/runtime/components/ExportCSV.d.vue.ts +3 -3
  5. package/dist/runtime/components/ExportCSV.vue.d.ts +3 -3
  6. package/dist/runtime/components/FileBtn.d.vue.ts +3 -3
  7. package/dist/runtime/components/FileBtn.vue.d.ts +3 -3
  8. package/dist/runtime/components/ImportCSV.d.vue.ts +3 -3
  9. package/dist/runtime/components/ImportCSV.vue.d.ts +3 -3
  10. package/dist/runtime/components/SplitterPanel.d.vue.ts +7 -5
  11. package/dist/runtime/components/SplitterPanel.vue.d.ts +7 -5
  12. package/dist/runtime/components/TabsGroup.d.vue.ts +7 -5
  13. package/dist/runtime/components/TabsGroup.vue.d.ts +7 -5
  14. package/dist/runtime/components/device/IdCardButton.d.vue.ts +3 -3
  15. package/dist/runtime/components/device/IdCardButton.vue.d.ts +3 -3
  16. package/dist/runtime/components/device/Scanner.d.vue.ts +31 -29
  17. package/dist/runtime/components/device/Scanner.vue.d.ts +31 -29
  18. package/dist/runtime/components/dialog/Confirm.d.vue.ts +7 -5
  19. package/dist/runtime/components/dialog/Confirm.vue.d.ts +7 -5
  20. package/dist/runtime/components/dialog/ImportProgress.d.vue.ts +5 -3
  21. package/dist/runtime/components/dialog/ImportProgress.vue.d.ts +5 -3
  22. package/dist/runtime/components/dialog/Index.d.vue.ts +5 -3
  23. package/dist/runtime/components/dialog/Index.vue.d.ts +5 -3
  24. package/dist/runtime/components/dialog/Loading.d.vue.ts +5 -3
  25. package/dist/runtime/components/dialog/Loading.vue.d.ts +5 -3
  26. package/dist/runtime/components/dialog/default/Confirm.d.vue.ts +7 -5
  27. package/dist/runtime/components/dialog/default/Confirm.vue.d.ts +7 -5
  28. package/dist/runtime/components/dialog/default/Loading.d.vue.ts +7 -5
  29. package/dist/runtime/components/dialog/default/Loading.vue.d.ts +7 -5
  30. package/dist/runtime/components/dialog/default/Printing.d.vue.ts +5 -3
  31. package/dist/runtime/components/dialog/default/Printing.vue.d.ts +5 -3
  32. package/dist/runtime/components/document/TemplateBuilderLiveView.d.vue.ts +71 -69
  33. package/dist/runtime/components/document/TemplateBuilderLiveView.vue.d.ts +71 -69
  34. package/dist/runtime/components/document/TemplateInputAttributesHelper.d.vue.ts +14 -0
  35. package/dist/runtime/components/document/TemplateInputAttributesHelper.vue +154 -0
  36. package/dist/runtime/components/document/TemplateInputAttributesHelper.vue.d.ts +14 -0
  37. package/dist/runtime/components/document/TemplateItemForm.vue +46 -1
  38. package/dist/runtime/components/document/TemplatePalette.d.vue.ts +8 -6
  39. package/dist/runtime/components/document/TemplatePalette.vue +16 -0
  40. package/dist/runtime/components/document/TemplatePalette.vue.d.ts +8 -6
  41. package/dist/runtime/components/form/ActionPad.d.vue.ts +34 -32
  42. package/dist/runtime/components/form/ActionPad.vue.d.ts +34 -32
  43. package/dist/runtime/components/form/Date.d.vue.ts +20 -18
  44. package/dist/runtime/components/form/Date.vue.d.ts +20 -18
  45. package/dist/runtime/components/form/Dialog.d.vue.ts +24 -22
  46. package/dist/runtime/components/form/Dialog.vue.d.ts +24 -22
  47. package/dist/runtime/components/form/EditPad.d.vue.ts +34 -32
  48. package/dist/runtime/components/form/EditPad.vue.d.ts +34 -32
  49. package/dist/runtime/components/form/File.d.vue.ts +12 -10
  50. package/dist/runtime/components/form/File.vue.d.ts +12 -10
  51. package/dist/runtime/components/form/Iterator.d.vue.ts +121 -134
  52. package/dist/runtime/components/form/Iterator.vue.d.ts +121 -134
  53. package/dist/runtime/components/form/Login.d.vue.ts +5 -3
  54. package/dist/runtime/components/form/Login.vue.d.ts +5 -3
  55. package/dist/runtime/components/form/Pad.d.vue.ts +652 -650
  56. package/dist/runtime/components/form/Pad.vue +3 -0
  57. package/dist/runtime/components/form/Pad.vue.d.ts +652 -650
  58. package/dist/runtime/components/form/Table.d.vue.ts +69 -82
  59. package/dist/runtime/components/form/Table.vue.d.ts +69 -82
  60. package/dist/runtime/components/form/TableData.d.vue.ts +18 -24
  61. package/dist/runtime/components/form/TableData.vue.d.ts +18 -24
  62. package/dist/runtime/components/form/images/Capture.d.vue.ts +15 -13
  63. package/dist/runtime/components/form/images/Capture.vue.d.ts +15 -13
  64. package/dist/runtime/components/label/Field.d.vue.ts +16 -14
  65. package/dist/runtime/components/label/Field.vue.d.ts +16 -14
  66. package/dist/runtime/components/label/FormatMoney.d.vue.ts +1 -1
  67. package/dist/runtime/components/label/FormatMoney.vue.d.ts +1 -1
  68. package/dist/runtime/components/master/Autocomplete.d.vue.ts +3 -5
  69. package/dist/runtime/components/master/Autocomplete.vue.d.ts +3 -5
  70. package/dist/runtime/components/master/Combobox.d.vue.ts +3 -5
  71. package/dist/runtime/components/master/Combobox.vue.d.ts +3 -5
  72. package/dist/runtime/components/master/RadioGroup.d.vue.ts +3 -3
  73. package/dist/runtime/components/master/RadioGroup.vue.d.ts +3 -3
  74. package/dist/runtime/components/master/Select.d.vue.ts +3 -5
  75. package/dist/runtime/components/master/Select.vue.d.ts +3 -5
  76. package/dist/runtime/components/master/label.d.vue.ts +7 -3
  77. package/dist/runtime/components/master/label.vue +33 -15
  78. package/dist/runtime/components/master/label.vue.d.ts +7 -3
  79. package/dist/runtime/components/model/Autocomplete.d.vue.ts +3 -3
  80. package/dist/runtime/components/model/Autocomplete.vue.d.ts +3 -3
  81. package/dist/runtime/components/model/Combobox.d.vue.ts +3 -3
  82. package/dist/runtime/components/model/Combobox.vue.d.ts +3 -3
  83. package/dist/runtime/components/model/Pad.d.vue.ts +17 -15
  84. package/dist/runtime/components/model/Pad.vue.d.ts +17 -15
  85. package/dist/runtime/components/model/Select.d.vue.ts +3 -3
  86. package/dist/runtime/components/model/Select.vue.d.ts +3 -3
  87. package/dist/runtime/components/model/Table.d.vue.ts +102 -166
  88. package/dist/runtime/components/model/Table.vue.d.ts +102 -166
  89. package/dist/runtime/components/model/iterator.d.vue.ts +188 -240
  90. package/dist/runtime/components/model/iterator.vue.d.ts +188 -240
  91. package/dist/runtime/components/model/label.d.vue.ts +11 -5
  92. package/dist/runtime/components/model/label.vue +54 -4
  93. package/dist/runtime/components/model/label.vue.d.ts +11 -5
  94. package/dist/runtime/composables/batchLookup.d.ts +39 -0
  95. package/dist/runtime/composables/batchLookup.js +144 -0
  96. package/dist/runtime/composables/document/inputAttributeCatalog.generated.json +95 -0
  97. package/dist/runtime/composables/document/inputAttributes.d.ts +46 -0
  98. package/dist/runtime/composables/document/inputAttributes.js +196 -0
  99. package/dist/runtime/composables/document/template.js +4 -0
  100. package/dist/runtime/composables/document/templateInputTypes.d.ts +36 -0
  101. package/dist/runtime/composables/document/templateInputTypes.js +86 -17
  102. package/dist/runtime/composables/document/templateMasterLabel.d.ts +32 -0
  103. package/dist/runtime/composables/document/templateMasterLabel.js +30 -0
  104. package/dist/runtime/composables/document/validateTemplate.js +11 -1
  105. package/dist/runtime/composables/masterItemBatch.d.ts +7 -0
  106. package/dist/runtime/composables/masterItemBatch.js +12 -0
  107. package/dist/runtime/composables/modelBatch.d.ts +61 -0
  108. package/dist/runtime/composables/modelBatch.js +192 -0
  109. package/dist/runtime/labs/form/EditMobile.d.vue.ts +1 -1
  110. package/dist/runtime/labs/form/EditMobile.vue.d.ts +1 -1
  111. package/dist/runtime/labs/form/TextFieldMask.d.vue.ts +3 -3
  112. package/dist/runtime/labs/form/TextFieldMask.vue.d.ts +3 -3
  113. package/dist/runtime/plugins/clientConfig.d.ts +1 -1
  114. package/dist/runtime/plugins/default.d.ts +1 -1
  115. package/dist/runtime/plugins/dialogManager.d.ts +1 -1
  116. package/dist/runtime/plugins/permission.d.ts +1 -1
  117. package/package.json +2 -2
  118. package/scripts/build-input-attribute-catalog.mjs +133 -0
@@ -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 var __VLS_12: never, __VLS_13: {};
6
- type __VLS_Slots = {} & {
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 var __VLS_12: never, __VLS_13: {};
6
- type __VLS_Slots = {} & {
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("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
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("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
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("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
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("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
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.27",
3
+ "version": "4.0.29",
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
+ }