@ramathibodi/nuxt-commons 4.0.20 → 4.0.22
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 +1 -1
- package/dist/runtime/components/document/TemplateBuilder.d.vue.ts +7 -1
- package/dist/runtime/components/document/TemplateBuilder.vue +7 -461
- package/dist/runtime/components/document/TemplateBuilder.vue.d.ts +7 -1
- package/dist/runtime/components/document/TemplateBuilderLiveView.d.vue.ts +185 -0
- package/dist/runtime/components/document/TemplateBuilderLiveView.vue +579 -0
- package/dist/runtime/components/document/TemplateBuilderLiveView.vue.d.ts +185 -0
- package/dist/runtime/components/document/TemplateItemForm.d.vue.ts +11 -0
- package/dist/runtime/components/document/TemplateItemForm.vue +437 -0
- package/dist/runtime/components/document/TemplateItemForm.vue.d.ts +11 -0
- package/dist/runtime/components/document/TemplatePalette.d.vue.ts +54 -0
- package/dist/runtime/components/document/TemplatePalette.vue +362 -0
- package/dist/runtime/components/document/TemplatePalette.vue.d.ts +54 -0
- package/dist/runtime/components/form/Pad.vue +1 -1
- package/dist/runtime/components/master/Autocomplete.vue +6 -2
- package/dist/runtime/components/master/Combobox.vue +6 -2
- package/dist/runtime/composables/document/template.d.ts +72 -1
- package/dist/runtime/composables/document/template.js +47 -8
- package/dist/runtime/composables/document/templateBuilderModel.d.ts +51 -0
- package/dist/runtime/composables/document/templateBuilderModel.js +62 -0
- package/dist/runtime/composables/document/templateFormHidden.js +3 -1
- package/dist/runtime/composables/document/templatePalette.d.ts +21 -0
- package/dist/runtime/composables/document/templatePalette.js +10 -0
- package/dist/runtime/composables/document/validateTemplate.js +61 -2
- package/dist/runtime/composables/lookupListMaster.d.ts +3 -1
- package/dist/runtime/composables/lookupListMaster.js +2 -2
- package/package.json +2 -2
|
@@ -5,7 +5,7 @@ import { some, includes, cloneDeep } from "lodash-es";
|
|
|
5
5
|
import { migrateInputAttributes, migrateTemplateString } from "./templateMigrate.js";
|
|
6
6
|
import { getDocumentTemplateInputTypeEntry } from "./templateInputTypes.js";
|
|
7
7
|
export const validationRulesRegex = /^(require(?:\([^)]*\))?|requireIf\([^)]*\)|requireTrue(?:\([^)]*\))?|requireTrueIf\([^)]*\)|requireNotEmpty(?:\([^)]*\))?|numeric(?:\([^)]*\))?|range\([^)]*\)|integer(?:\([^)]*\))?|unique\([^)]*\)|length(?:\([^)]*\))?|lengthGreater\([^)]*\)|lengthLess\([^)]*\)|telephone(?:\([^)]*\))?|email(?:\([^)]*\))?|regex\([^)]*\)|idcard(?:\([^)]*\))?|DateFuture(?:\([^)]*\))?|DatetimeFuture(?:\([^)]*\))?|DateHappen(?:\([^)]*\))?|DatetimeHappen(?:\([^)]*\))?|DateAfter\([^)]*\)|DateBefore\([^)]*\)|DateEqual\([^)]*\))(,(require(?:\([^)]*\))?|requireIf\([^)]*\)|requireTrue(?:\([^)]*\))?|requireTrueIf\([^)]*\)|requireNotEmpty(?:\([^)]*\))?|numeric(?:\([^)]*\))?|range\([^)]*\)|integer(?:\([^)]*\))?|unique\([^)]*\)|length(?:\([^)]*\))?|lengthGreater\([^)]*\)|lengthLess\([^)]*\)|telephone(?:\([^)]*\))?|email(?:\([^)]*\))?|regex\([^)]*\)|idcard(?:\([^)]*\))?|DateFuture(?:\([^)]*\))?|DatetimeFuture(?:\([^)]*\))?|DateHappen(?:\([^)]*\))?|DatetimeHappen(?:\([^)]*\))?|DateAfter\([^)]*\)|DateBefore\([^)]*\)|DateEqual\([^)]*\)))*$/;
|
|
8
|
-
export function useDocumentTemplate(items, parentTemplates) {
|
|
8
|
+
export function useDocumentTemplate(items, parentTemplates, options) {
|
|
9
9
|
if (!items) return "";
|
|
10
10
|
if (typeof items === "string") {
|
|
11
11
|
try {
|
|
@@ -17,7 +17,8 @@ export function useDocumentTemplate(items, parentTemplates) {
|
|
|
17
17
|
if (!Array.isArray(items) || !items.every((item) => typeof item === "object" && item !== null)) {
|
|
18
18
|
return "";
|
|
19
19
|
}
|
|
20
|
-
const
|
|
20
|
+
const indexAttribute = options?.itemIndexAttribute;
|
|
21
|
+
const templateString = items.map((item, index) => columnWrapTemplateItemString(item, parentTemplates || [], "data", indexAttribute ? ` ${indexAttribute}="${index}"` : "")).join("");
|
|
21
22
|
const wrapped = !parentTemplates || parentTemplates.length == 0 ? `<v-container fluid><v-row density='compact'>${templateString}</v-row></v-container>` : `<v-row density='compact'>${templateString}</v-row>`;
|
|
22
23
|
return migrateTemplateString(wrapped);
|
|
23
24
|
}
|
|
@@ -25,6 +26,7 @@ export function templateItemToString(inputItem, parentTemplates, dataVariable =
|
|
|
25
26
|
let item = cloneDeep(inputItem);
|
|
26
27
|
item.inputAttributes = migrateInputAttributes(item.inputAttributes?.trim() || "", item.inputType);
|
|
27
28
|
let optionString = "";
|
|
29
|
+
let radioClearHandler = "";
|
|
28
30
|
if (item.inputOptions) {
|
|
29
31
|
if (item.inputType === "MasterAutocomplete") {
|
|
30
32
|
optionString += `groupKey="${item.inputOptions}" `;
|
|
@@ -39,7 +41,9 @@ export function templateItemToString(inputItem, parentTemplates, dataVariable =
|
|
|
39
41
|
}
|
|
40
42
|
if (["VRadio", "VRadioInline"].includes(item.inputType)) {
|
|
41
43
|
const choice = optionStringToChoiceObject(item.inputOptions);
|
|
42
|
-
|
|
44
|
+
const radioContext = { variableName: item.variableName, dataVariable };
|
|
45
|
+
optionString = choice.map((choiceItem) => radioChoiceToString(choiceItem, item.inputAttributes, radioContext)).join("");
|
|
46
|
+
radioClearHandler = radioTextFieldClearHandler(choice, item.variableName, dataVariable, item.inputAttributes);
|
|
43
47
|
}
|
|
44
48
|
if (item.inputType === "Header") {
|
|
45
49
|
if (typeof item.inputOptions === "string") optionString = item.inputOptions.split(",").join(" ");
|
|
@@ -66,10 +70,10 @@ export function templateItemToString(inputItem, parentTemplates, dataVariable =
|
|
|
66
70
|
templateString = item.inputCustomCode || "";
|
|
67
71
|
break;
|
|
68
72
|
case "VRadio":
|
|
69
|
-
templateString = `${item.inputLabel ? `<p class="opacity-60">${item.inputLabel}</p>` : ""} <v-radio-group ${item.inputAttributes?.trim()} v-model="${dataVariable}.${item.variableName || ""}"${validationRules ? " " + validationRules.trim() : ""}>${optionString ? " " + optionString.trim() : ""}</v-radio-group>`;
|
|
73
|
+
templateString = `${item.inputLabel ? `<p class="opacity-60">${item.inputLabel}</p>` : ""} <v-radio-group ${item.inputAttributes?.trim()} v-model="${dataVariable}.${item.variableName || ""}"${radioClearHandler ? " " + radioClearHandler : ""}${validationRules ? " " + validationRules.trim() : ""}>${optionString ? " " + optionString.trim() : ""}</v-radio-group>`;
|
|
70
74
|
break;
|
|
71
75
|
case "VRadioInline":
|
|
72
|
-
templateString = `<v-radio-group ${item.inputAttributes?.trim()} v-model="${dataVariable}.${item.variableName || ""}" inline ${validationRules ? " " + validationRules.trim() : ""}>${item.inputLabel ? `<template #prepend><span class="opacity-60">${item.inputLabel}</span></template>` : ""}${optionString ? " " + optionString.trim() : ""}</v-radio-group>`;
|
|
76
|
+
templateString = `<v-radio-group ${item.inputAttributes?.trim()} v-model="${dataVariable}.${item.variableName || ""}"${radioClearHandler ? " " + radioClearHandler : ""} inline ${validationRules ? " " + validationRules.trim() : ""}>${item.inputLabel ? `<template #prepend><span class="opacity-60">${item.inputLabel}</span></template>` : ""}${optionString ? " " + optionString.trim() : ""}</v-radio-group>`;
|
|
73
77
|
break;
|
|
74
78
|
case "Separator":
|
|
75
79
|
templateString = `</v-row><v-row density='compact'${item.customClass ? ` class="${item.customClass}"` : ""}${item.customStyle ? ` class="${item.customStyle}"` : ""}>`;
|
|
@@ -98,12 +102,43 @@ export function templateItemToString(inputItem, parentTemplates, dataVariable =
|
|
|
98
102
|
}
|
|
99
103
|
return templateString || "";
|
|
100
104
|
}
|
|
101
|
-
function columnWrapTemplateItemString(item, parentTemplates, dataVariable = "data") {
|
|
105
|
+
function columnWrapTemplateItemString(item, parentTemplates, dataVariable = "data", extraColumnAttributes = "") {
|
|
102
106
|
let templateString = templateItemToString(item, parentTemplates, dataVariable);
|
|
103
|
-
if (!["Separator", "FormHidden"].includes(item.inputType)) templateString = `<v-col${item.width ? ` cols="${item.width}"` : ""}${item.columnAttributes ? " " + item.columnAttributes : ""} :class="(injectedClass) ? injectedClass['${item.variableName || ""}'] : undefined"${item.customClass ? ` class="${item.customClass}"` : ""}${item.customStyle ? ` class="${item.customStyle}"` : ""}>${templateString}</v-col>`;
|
|
107
|
+
if (!["Separator", "FormHidden"].includes(item.inputType)) templateString = `<v-col${extraColumnAttributes}${item.width ? ` cols="${item.width}"` : ""}${item.columnAttributes ? " " + item.columnAttributes : ""} :class="(injectedClass) ? injectedClass['${item.variableName || ""}'] : undefined"${item.customClass ? ` class="${item.customClass}"` : ""}${item.customStyle ? ` class="${item.customStyle}"` : ""}>${templateString}</v-col>`;
|
|
104
108
|
if (["Header", "DocumentForm"].includes(item.inputType)) templateString = `</v-row><v-row density='compact' ${item.customClass ? ` class="${item.customClass}"` : ""}${item.customStyle ? ` class="${item.customStyle}"` : ""}>${templateString}</v-row><v-row density='compact'>`;
|
|
105
109
|
return templateString || "";
|
|
106
110
|
}
|
|
111
|
+
export function radioChoiceTextVariable(variableName, value) {
|
|
112
|
+
const words = String(value ?? "").split(/[^A-Za-z0-9_$]+/).filter(Boolean);
|
|
113
|
+
const suffix = words.map((w) => w.charAt(0).toUpperCase() + w.slice(1)).join("");
|
|
114
|
+
return `${(variableName || "").trim()}${suffix}Text`;
|
|
115
|
+
}
|
|
116
|
+
function escapeChoiceValue(value) {
|
|
117
|
+
return String(value ?? "").replace(/\\/g, "\\\\").replace(/'/g, "\\'").replace(/"/g, """);
|
|
118
|
+
}
|
|
119
|
+
function hasUpdateListener(inputAttributes) {
|
|
120
|
+
return !!inputAttributes && /@update:model-?[vV]alue\b|v-on:update:model-?[vV]alue\b/.test(inputAttributes);
|
|
121
|
+
}
|
|
122
|
+
export function radioChoiceToString(choiceItem, inputAttributes, context = {}) {
|
|
123
|
+
const attrs = `label="${choiceItem.label || ""}" value="${choiceItem.value || ""}"${inputAttributes ? " " + inputAttributes : ""}`;
|
|
124
|
+
if (choiceItem.textField !== true) return `<v-radio ${attrs}></v-radio>`;
|
|
125
|
+
const dataVariable = context.dataVariable || "data";
|
|
126
|
+
const selection = `${dataVariable}.${context.variableName || ""}`;
|
|
127
|
+
const textVariable = `${dataVariable}.${radioChoiceTextVariable(context.variableName, choiceItem.value)}`;
|
|
128
|
+
const placeholder = typeof choiceItem.textFieldPlaceholder === "string" && choiceItem.textFieldPlaceholder.trim() ? ` placeholder="${choiceItem.textFieldPlaceholder.replace(/"/g, """)}"` : "";
|
|
129
|
+
const builtRules = typeof choiceItem.textFieldRules === "string" && choiceItem.textFieldRules.trim() ? buildValidationRules(choiceItem.textFieldRules) : "";
|
|
130
|
+
const rulesArray = builtRules.match(/^:rules="(\[.*\])"$/)?.[1];
|
|
131
|
+
const isSelected = `${selection} === '${escapeChoiceValue(choiceItem.value)}'`;
|
|
132
|
+
const rules = rulesArray ? ` hide-details="auto" :rules="${isSelected} ? ${rulesArray} : []" :key="${isSelected}"` : " hide-details";
|
|
133
|
+
const field = `<v-text-field v-model="${textVariable}" variant="underlined" density="compact"${rules}${placeholder} :disabled="${selection} !== '${escapeChoiceValue(choiceItem.value)}'" :readonly="isReadonly"></v-text-field>`;
|
|
134
|
+
return `<v-radio ${attrs}><template #label><span class="me-2">${choiceItem.label || ""}</span><span class="form-radio-text-field flex-grow-1 d-flex align-center">${field}</span></template></v-radio>`;
|
|
135
|
+
}
|
|
136
|
+
export function radioTextFieldClearHandler(choice, variableName, dataVariable = "data", inputAttributes) {
|
|
137
|
+
if (hasUpdateListener(inputAttributes)) return "";
|
|
138
|
+
const clauses = choice.filter((c) => c.textField === true).map((c) => `if ($v !== '${escapeChoiceValue(c.value)}') { ${dataVariable}.${radioChoiceTextVariable(variableName, c.value)} = undefined }`);
|
|
139
|
+
if (!clauses.length) return "";
|
|
140
|
+
return `@update:model-value="($v) => { ${clauses.join(" ")} }"`;
|
|
141
|
+
}
|
|
107
142
|
export function optionStringToChoiceObject(option) {
|
|
108
143
|
if (typeof option === "string") {
|
|
109
144
|
if (!/^[^'",]+(,[^'",]+)*$/.test(option.trim())) return [];
|
|
@@ -121,8 +156,12 @@ export function optionStringToChoiceObject(option) {
|
|
|
121
156
|
return option.sort((a, b) => (a.id ?? Infinity) - (b.id ?? Infinity)).map((item) => ({
|
|
122
157
|
label: item.label || item.value || "",
|
|
123
158
|
// Default to empty string if label is undefined
|
|
124
|
-
value: item.value || ""
|
|
159
|
+
value: item.value || "",
|
|
125
160
|
// Default to empty string if value is undefined
|
|
161
|
+
// Optional per-choice trailing text field (radio inputs only); kept only when true.
|
|
162
|
+
...item.textField === true ? { textField: true } : {},
|
|
163
|
+
...item.textField === true && typeof item.textFieldPlaceholder === "string" && item.textFieldPlaceholder.trim() ? { textFieldPlaceholder: item.textFieldPlaceholder } : {},
|
|
164
|
+
...item.textField === true && typeof item.textFieldRules === "string" && item.textFieldRules.trim() ? { textFieldRules: item.textFieldRules } : {}
|
|
126
165
|
}));
|
|
127
166
|
}
|
|
128
167
|
return [];
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared v-model plumbing for the document-template builders
|
|
3
|
+
* (`<DocumentTemplateBuilder>` and `<DocumentTemplateBuilderLiveView>`).
|
|
4
|
+
*
|
|
5
|
+
* The persisted `modelValue` is either
|
|
6
|
+
* - a stringified JSON array of {@link DocumentTemplateItem} (basic mode),
|
|
7
|
+
* - an array of items (basic mode, object form), or
|
|
8
|
+
* - a raw HTML template string (advance mode).
|
|
9
|
+
*
|
|
10
|
+
* This composable owns the translation between that persisted shape and the
|
|
11
|
+
* editable `templateItems` array (with `printConfig` exploded into key/value
|
|
12
|
+
* rows), plus the advance-mode code buffer and the one-way conversion into it.
|
|
13
|
+
* Both builders share it so the JSON they emit is byte-for-byte identical.
|
|
14
|
+
*
|
|
15
|
+
* This doc block is consumed by vue-docgen for generated API documentation.
|
|
16
|
+
*/
|
|
17
|
+
import { type Ref } from 'vue';
|
|
18
|
+
export type DocumentTemplateBuilderModelValue = string | Record<string, any>[] | undefined;
|
|
19
|
+
/** `true` when `str` parses to a JSON array whose entries are all plain objects. */
|
|
20
|
+
export declare function isValidJsonArrayOfObjects(str: string | undefined): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* `printConfig` is stored in the template JSON as an object map
|
|
23
|
+
* (`{ width: 2 }`) or a raw string, but the key/value editor works on an
|
|
24
|
+
* array of `{ key, value }` rows. These two helpers translate at the
|
|
25
|
+
* load/serialize boundary so the editor sees rows while the persisted JSON
|
|
26
|
+
* keeps the spec shape. Only the object-map form is exploded into rows; the
|
|
27
|
+
* raw-string form is edited as-is.
|
|
28
|
+
*/
|
|
29
|
+
export declare function templateItemsForEdit(items: Record<string, any>[]): Record<string, any>[];
|
|
30
|
+
export declare function templateItemsForStore(items: Record<string, any>[]): Record<string, any>[];
|
|
31
|
+
export interface DocumentTemplateBuilderModel {
|
|
32
|
+
/** Editable items (printConfig as rows). Mutate in place or replace; the model is re-serialised on change. */
|
|
33
|
+
templateItems: Ref<Record<string, any>[]>;
|
|
34
|
+
/** `true` when `modelValue` is a non-JSON string, i.e. a raw HTML template. */
|
|
35
|
+
isAdvanceMode: Ref<boolean>;
|
|
36
|
+
/** Raw HTML buffer bound to the code editor in advance mode. */
|
|
37
|
+
advanceModeCode: Ref<string | undefined>;
|
|
38
|
+
/** Items in the persisted shape (printConfig as a map), for previews. */
|
|
39
|
+
storedItems: Ref<Record<string, any>[]>;
|
|
40
|
+
/** Render the current items to HTML and replace `modelValue` with it (irreversible). */
|
|
41
|
+
convertToAdvanceMode: () => Promise<void>;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Bind a builder's `defineModel()` ref to an editable item list.
|
|
45
|
+
*
|
|
46
|
+
* ```ts
|
|
47
|
+
* const modelValue = defineModel<string | Record<string, any>[]>()
|
|
48
|
+
* const { templateItems, isAdvanceMode, advanceModeCode, convertToAdvanceMode } = useDocumentTemplateBuilderModel(modelValue)
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
export declare function useDocumentTemplateBuilderModel(modelValue: Ref<DocumentTemplateBuilderModelValue>): DocumentTemplateBuilderModel;
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { computed, ref, watch } from "vue";
|
|
2
|
+
import * as prettier from "prettier";
|
|
3
|
+
import prettierPluginHtml from "prettier/plugins/html";
|
|
4
|
+
import { cloneDeep, isPlainObject } from "lodash-es";
|
|
5
|
+
import {
|
|
6
|
+
printConfigToRows,
|
|
7
|
+
rowsToPrintConfig,
|
|
8
|
+
useDocumentTemplate
|
|
9
|
+
} from "./template.js";
|
|
10
|
+
export function isValidJsonArrayOfObjects(str) {
|
|
11
|
+
try {
|
|
12
|
+
const parsed = JSON.parse(str);
|
|
13
|
+
return Array.isArray(parsed) && parsed.every((item) => typeof item === "object" && item !== null && !Array.isArray(item));
|
|
14
|
+
} catch (_) {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export function templateItemsForEdit(items) {
|
|
19
|
+
return items.map((item) => isPlainObject(item.printConfig) ? { ...item, printConfig: printConfigToRows(item.printConfig) } : item);
|
|
20
|
+
}
|
|
21
|
+
export function templateItemsForStore(items) {
|
|
22
|
+
return items.map((item) => {
|
|
23
|
+
if (Array.isArray(item.printConfig)) {
|
|
24
|
+
const map = rowsToPrintConfig(item.printConfig);
|
|
25
|
+
const { printConfig, ...rest } = item;
|
|
26
|
+
return Object.keys(map).length ? { ...rest, printConfig: map } : rest;
|
|
27
|
+
}
|
|
28
|
+
if (typeof item.printConfig === "string" && item.printConfig.trim() === "") {
|
|
29
|
+
const { printConfig, ...rest } = item;
|
|
30
|
+
return rest;
|
|
31
|
+
}
|
|
32
|
+
return item;
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
export function useDocumentTemplateBuilderModel(modelValue) {
|
|
36
|
+
const advanceModeCode = ref();
|
|
37
|
+
const templateItems = ref([]);
|
|
38
|
+
const isAdvanceMode = computed(() => {
|
|
39
|
+
return !!modelValue.value && typeof modelValue.value === "string" && !isValidJsonArrayOfObjects(modelValue.value);
|
|
40
|
+
});
|
|
41
|
+
const storedItems = computed(() => templateItemsForStore(templateItems.value));
|
|
42
|
+
watch(templateItems, (newValue) => {
|
|
43
|
+
if (!isAdvanceMode.value) modelValue.value = JSON.stringify(templateItemsForStore(newValue));
|
|
44
|
+
}, { deep: true });
|
|
45
|
+
watch(modelValue, (newValue) => {
|
|
46
|
+
if (typeof newValue === "string" && isValidJsonArrayOfObjects(newValue)) templateItems.value = templateItemsForEdit(JSON.parse(newValue));
|
|
47
|
+
else if (typeof newValue === "string") advanceModeCode.value = newValue;
|
|
48
|
+
else if (newValue) templateItems.value = templateItemsForEdit(cloneDeep(newValue));
|
|
49
|
+
}, { deep: true, immediate: true });
|
|
50
|
+
watch(advanceModeCode, (newValue) => {
|
|
51
|
+
if (isAdvanceMode.value) modelValue.value = newValue;
|
|
52
|
+
});
|
|
53
|
+
async function convertToAdvanceMode() {
|
|
54
|
+
if (!isAdvanceMode.value) {
|
|
55
|
+
modelValue.value = await prettier.format(
|
|
56
|
+
useDocumentTemplate(templateItemsForStore(templateItems.value)).replaceAll(">", ">\n"),
|
|
57
|
+
{ parser: "html", plugins: [prettierPluginHtml] }
|
|
58
|
+
);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return { templateItems, isAdvanceMode, advanceModeCode, storedItems, convertToAdvanceMode };
|
|
62
|
+
}
|
|
@@ -9,5 +9,7 @@ export function processTemplateFormHidden(item, parentTemplates, dataVariable =
|
|
|
9
9
|
} else {
|
|
10
10
|
formHiddenOptions.hook = "";
|
|
11
11
|
}
|
|
12
|
-
|
|
12
|
+
const itemValue = formHiddenOptions.itemValue || (formHiddenOptions.hook ? "data" : "");
|
|
13
|
+
const itemValueAttribute = itemValue ? ` :item-value="${itemValue}"` : "";
|
|
14
|
+
return `<form-hidden v-model="${dataVariable}.${item.variableName || ""}"${itemValueAttribute}${formHiddenOptions.hook}></form-hidden>`;
|
|
13
15
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Drag-and-drop contract between `<DocumentTemplatePalette>` and the drop
|
|
3
|
+
* surfaces that accept a new document-template item (currently
|
|
4
|
+
* `<DocumentTemplateBuilderLiveView>`'s live view).
|
|
5
|
+
*
|
|
6
|
+
* The palette stamps the dragged `inputType` on the native `DataTransfer`
|
|
7
|
+
* under {@link DOCUMENT_TEMPLATE_PALETTE_MIME}. Browsers expose only the
|
|
8
|
+
* *types* (not the data) during `dragover`, so a drop surface uses
|
|
9
|
+
* {@link isDocumentTemplatePaletteDrag} to decide whether to accept the drag
|
|
10
|
+
* and {@link readDocumentTemplatePaletteDrag} on `drop` to get the value.
|
|
11
|
+
*
|
|
12
|
+
* Because the contract goes through the DataTransfer, a custom palette can
|
|
13
|
+
* feed the live view without sharing any state: set the same MIME type in
|
|
14
|
+
* its own `dragstart` handler.
|
|
15
|
+
*/
|
|
16
|
+
/** MIME type carrying the dragged `inputType`. Lower-case because Chrome lower-cases DataTransfer types. */
|
|
17
|
+
export declare const DOCUMENT_TEMPLATE_PALETTE_MIME = "application/x-document-template-input-type";
|
|
18
|
+
/** `true` when the in-flight drag carries a document-template input type (usable during `dragover`). */
|
|
19
|
+
export declare function isDocumentTemplatePaletteDrag(event: DragEvent): boolean;
|
|
20
|
+
/** The dragged `inputType`, or `null` when the drop is not a palette drag (only readable on `drop`). */
|
|
21
|
+
export declare function readDocumentTemplatePaletteDrag(event: DragEvent): string | null;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export const DOCUMENT_TEMPLATE_PALETTE_MIME = "application/x-document-template-input-type";
|
|
2
|
+
export function isDocumentTemplatePaletteDrag(event) {
|
|
3
|
+
const types = event.dataTransfer?.types;
|
|
4
|
+
if (!types) return false;
|
|
5
|
+
return Array.from(types).includes(DOCUMENT_TEMPLATE_PALETTE_MIME);
|
|
6
|
+
}
|
|
7
|
+
export function readDocumentTemplatePaletteDrag(event) {
|
|
8
|
+
const value = event.dataTransfer?.getData?.(DOCUMENT_TEMPLATE_PALETTE_MIME);
|
|
9
|
+
return value ? String(value) : null;
|
|
10
|
+
}
|
|
@@ -226,12 +226,13 @@ function validateInputOptions(item, path, ctx, push) {
|
|
|
226
226
|
return;
|
|
227
227
|
default:
|
|
228
228
|
if (optionsAsChoice && hasOptions) {
|
|
229
|
-
validateChoiceOptions(opts, optsPath, push);
|
|
229
|
+
validateChoiceOptions(opts, optsPath, push, RADIO_TYPES.includes(inputType));
|
|
230
230
|
}
|
|
231
231
|
return;
|
|
232
232
|
}
|
|
233
233
|
}
|
|
234
|
-
|
|
234
|
+
const RADIO_TYPES = ["VRadio", "VRadioInline"];
|
|
235
|
+
function validateChoiceOptions(opts, path, push, allowsTextField = false) {
|
|
235
236
|
if (typeof opts === "string") {
|
|
236
237
|
if (!CHOICE_STRING_REGEX.test(opts.trim())) {
|
|
237
238
|
push(
|
|
@@ -255,6 +256,64 @@ function validateChoiceOptions(opts, path, push) {
|
|
|
255
256
|
if (!hasLabel && !hasValue) {
|
|
256
257
|
push(`${path}[${i}]`, "CHOICE_ITEM_EMPTY", "Choice item has neither label nor value; it renders blank.", "info");
|
|
257
258
|
}
|
|
259
|
+
if (o.textField !== void 0 && o.textField !== null && o.textField !== "") {
|
|
260
|
+
if (typeof o.textField !== "boolean") {
|
|
261
|
+
push(
|
|
262
|
+
`${path}[${i}].textField`,
|
|
263
|
+
"CHOICE_TEXT_FIELD_INVALID",
|
|
264
|
+
"Choice textField must be a boolean; any other value is ignored (no text field is rendered).",
|
|
265
|
+
"warning"
|
|
266
|
+
);
|
|
267
|
+
} else if (o.textField && !allowsTextField) {
|
|
268
|
+
push(
|
|
269
|
+
`${path}[${i}].textField`,
|
|
270
|
+
"CHOICE_TEXT_FIELD_IGNORED",
|
|
271
|
+
"Choice textField is only rendered by VRadio / VRadioInline; other choice inputs ignore it.",
|
|
272
|
+
"info"
|
|
273
|
+
);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
if (o.textFieldPlaceholder !== void 0 && o.textFieldPlaceholder !== null && o.textFieldPlaceholder !== "") {
|
|
277
|
+
if (typeof o.textFieldPlaceholder !== "string") {
|
|
278
|
+
push(
|
|
279
|
+
`${path}[${i}].textFieldPlaceholder`,
|
|
280
|
+
"CHOICE_TEXT_FIELD_PLACEHOLDER_INVALID",
|
|
281
|
+
"Choice textFieldPlaceholder must be a string; any other value is ignored.",
|
|
282
|
+
"warning"
|
|
283
|
+
);
|
|
284
|
+
} else if (o.textField !== true) {
|
|
285
|
+
push(
|
|
286
|
+
`${path}[${i}].textFieldPlaceholder`,
|
|
287
|
+
"CHOICE_TEXT_FIELD_PLACEHOLDER_IGNORED",
|
|
288
|
+
"Choice textFieldPlaceholder only applies when textField is true.",
|
|
289
|
+
"info"
|
|
290
|
+
);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
if (o.textFieldRules !== void 0 && o.textFieldRules !== null && o.textFieldRules !== "") {
|
|
294
|
+
if (typeof o.textFieldRules !== "string") {
|
|
295
|
+
push(
|
|
296
|
+
`${path}[${i}].textFieldRules`,
|
|
297
|
+
"CHOICE_TEXT_FIELD_RULES_INVALID",
|
|
298
|
+
"Choice textFieldRules must be a string; any other value is ignored.",
|
|
299
|
+
"warning"
|
|
300
|
+
);
|
|
301
|
+
} else if (!validationRulesRegex.test(o.textFieldRules.trim())) {
|
|
302
|
+
push(
|
|
303
|
+
`${path}[${i}].textFieldRules`,
|
|
304
|
+
"CHOICE_TEXT_FIELD_RULES_INVALID",
|
|
305
|
+
"Choice textFieldRules does not match the supported rule syntax; the runtime drops the rules.",
|
|
306
|
+
"warning"
|
|
307
|
+
);
|
|
308
|
+
} else if (o.textField !== true) {
|
|
309
|
+
push(
|
|
310
|
+
`${path}[${i}].textFieldRules`,
|
|
311
|
+
"CHOICE_TEXT_FIELD_RULES_IGNORED",
|
|
312
|
+
"Choice textFieldRules only applies when textField is true.",
|
|
313
|
+
"info"
|
|
314
|
+
);
|
|
315
|
+
}
|
|
316
|
+
}
|
|
258
317
|
});
|
|
259
318
|
return;
|
|
260
319
|
}
|
|
@@ -30,5 +30,7 @@ export declare function useLookupListMaster(props: MasterLikeProps): {
|
|
|
30
30
|
itemTitleField: import("vue").ComputedRef<"itemValue" | "itemValueAlternative">;
|
|
31
31
|
computedNoDataText: import("vue").ComputedRef<string | undefined>;
|
|
32
32
|
computedSortBy: import("vue").ComputedRef<string[]>;
|
|
33
|
-
formatItemTitle: (item: any
|
|
33
|
+
formatItemTitle: (item: any, opts?: {
|
|
34
|
+
plain?: boolean;
|
|
35
|
+
}) => string;
|
|
34
36
|
};
|
|
@@ -30,10 +30,10 @@ export function useLookupListMaster(props) {
|
|
|
30
30
|
props.fields || []
|
|
31
31
|
);
|
|
32
32
|
});
|
|
33
|
-
const formatItemTitle = (item) => {
|
|
33
|
+
const formatItemTitle = (item, opts = {}) => {
|
|
34
34
|
const raw = item?.raw ?? item ?? {};
|
|
35
35
|
const resolvedTitle = item?.title || raw?.[itemTitleField.value] || raw?.itemValue || raw?.itemCode;
|
|
36
|
-
if (props.meilisearch) {
|
|
36
|
+
if (props.meilisearch && !opts.plain) {
|
|
37
37
|
const formatted = raw?._formatted ?? {};
|
|
38
38
|
const code = formatted?.itemCode ?? raw?.itemCode;
|
|
39
39
|
const title = formatted?.[itemTitleField.value] || formatted?.itemValue || formatted?.itemCode || resolvedTitle;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ramathibodi/nuxt-commons",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.22",
|
|
4
4
|
"description": "Ramathibodi Nuxt modules for common components",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -114,7 +114,7 @@
|
|
|
114
114
|
"vue-codemirror": "^6.1.1",
|
|
115
115
|
"vue-json-pretty": "^2.6.0",
|
|
116
116
|
"vue-signature-pad": "^3.0.2",
|
|
117
|
-
"vuetify": "^4.
|
|
117
|
+
"vuetify": "^4.2.2",
|
|
118
118
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.3/xlsx-0.20.3.tgz"
|
|
119
119
|
},
|
|
120
120
|
"devDependencies": {
|