@ramathibodi/nuxt-commons 4.0.19 → 4.0.21
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/device/IdCardButton.d.vue.ts +2 -2
- package/dist/runtime/components/device/IdCardButton.vue.d.ts +2 -2
- package/dist/runtime/components/dialog/Confirm.d.vue.ts +1 -1
- package/dist/runtime/components/dialog/Confirm.vue.d.ts +1 -1
- package/dist/runtime/components/dialog/ImportResult.d.vue.ts +2 -2
- package/dist/runtime/components/dialog/ImportResult.vue.d.ts +2 -2
- package/dist/runtime/components/dialog/default/Confirm.d.vue.ts +2 -2
- package/dist/runtime/components/dialog/default/Confirm.vue.d.ts +2 -2
- package/dist/runtime/components/dialog/default/Notify.d.vue.ts +3 -3
- package/dist/runtime/components/dialog/default/Notify.vue.d.ts +3 -3
- package/dist/runtime/components/dialog/default/VerifyUser.d.vue.ts +2 -2
- package/dist/runtime/components/dialog/default/VerifyUser.vue.d.ts +2 -2
- 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/DateTime.d.vue.ts +1 -1
- package/dist/runtime/components/form/DateTime.vue.d.ts +1 -1
- package/dist/runtime/components/form/Login.d.vue.ts +1 -1
- package/dist/runtime/components/form/Login.vue.d.ts +1 -1
- package/dist/runtime/components/form/Pad.d.vue.ts +1 -1
- package/dist/runtime/components/form/Pad.vue +1 -1
- package/dist/runtime/components/form/Pad.vue.d.ts +1 -1
- package/dist/runtime/components/form/Time.vue +1 -2
- package/dist/runtime/components/form/images/Capture.d.vue.ts +1 -1
- package/dist/runtime/components/form/images/Capture.vue.d.ts +1 -1
- package/dist/runtime/components/label/Field.d.vue.ts +2 -2
- package/dist/runtime/components/label/Field.vue.d.ts +2 -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/labs/Calendar.d.vue.ts +4 -4
- package/dist/runtime/labs/Calendar.vue.d.ts +4 -4
- package/package.json +1 -1
|
@@ -37,10 +37,81 @@ export interface PrintConfigRow {
|
|
|
37
37
|
export interface ChoiceItem {
|
|
38
38
|
label: string;
|
|
39
39
|
value: string;
|
|
40
|
+
/**
|
|
41
|
+
* `VRadio` / `VRadioInline` only. `true` renders a text field right after
|
|
42
|
+
* this option's label, bound to `data.{radioChoiceTextVariable(...)}`
|
|
43
|
+
* (radio `treatment` + value `t1` → `data.treatmentT1Text`). The field is
|
|
44
|
+
* disabled while another option is selected and cleared when the
|
|
45
|
+
* selection moves to another option. Ignored by the select /
|
|
46
|
+
* checkbox-group inputs.
|
|
47
|
+
*/
|
|
48
|
+
textField?: boolean;
|
|
49
|
+
/** Placeholder shown in the `textField` input while it is empty. Only used when `textField` is `true`. */
|
|
50
|
+
textFieldPlaceholder?: string;
|
|
51
|
+
/**
|
|
52
|
+
* Validation rules for the `textField` input, in the same comma-separated
|
|
53
|
+
* format as {@link DocumentTemplateItem.validationRules} (e.g.
|
|
54
|
+
* `"require,length(50)"`). They apply only while this option is selected,
|
|
55
|
+
* so an unselected (disabled) field never blocks the form. Only used when
|
|
56
|
+
* `textField` is `true`.
|
|
57
|
+
*/
|
|
58
|
+
textFieldRules?: string;
|
|
40
59
|
}
|
|
41
60
|
export declare const validationRulesRegex: RegExp;
|
|
42
|
-
export
|
|
61
|
+
export interface DocumentTemplateRenderOptions {
|
|
62
|
+
/**
|
|
63
|
+
* Builder-only. When set, every top-level item that renders inside a
|
|
64
|
+
* `<v-col>` gets `<attribute>="<index>"` on that column so a design
|
|
65
|
+
* surface (e.g. `<DocumentTemplateBuilderLiveView>`) can map a click back
|
|
66
|
+
* to the item it came from. `Separator` and `FormHidden` render no column
|
|
67
|
+
* and are not annotated. Nested templates (FormTable / FormTableData)
|
|
68
|
+
* are never annotated. Omit for production rendering — the output is then
|
|
69
|
+
* unchanged.
|
|
70
|
+
*/
|
|
71
|
+
itemIndexAttribute?: string;
|
|
72
|
+
}
|
|
73
|
+
export declare function useDocumentTemplate(items: string | object, parentTemplates?: string | string[], options?: DocumentTemplateRenderOptions): string;
|
|
43
74
|
export declare function templateItemToString(inputItem: DocumentTemplateItem, parentTemplates: string | string[], dataVariable?: string): string;
|
|
75
|
+
/**
|
|
76
|
+
* Name of the `data` property that holds the text typed beside a radio choice
|
|
77
|
+
* (see {@link ChoiceItem.textField}): the radio's own `variableName`, then the
|
|
78
|
+
* choice value in PascalCase with non-identifier characters dropped, then
|
|
79
|
+
* `Text`.
|
|
80
|
+
*
|
|
81
|
+
* radioChoiceTextVariable('treatment', 't1') → 'treatmentT1Text'
|
|
82
|
+
* radioChoiceTextVariable('reason', 'other-one') → 'reasonOtherOneText'
|
|
83
|
+
*
|
|
84
|
+
* Use ASCII choice values: a value made only of non-identifier characters
|
|
85
|
+
* collapses to `{variableName}Text` and would collide with a sibling.
|
|
86
|
+
*/
|
|
87
|
+
export declare function radioChoiceTextVariable(variableName: string | undefined, value: string | undefined): string;
|
|
88
|
+
export interface RadioChoiceContext {
|
|
89
|
+
/** The radio item's `variableName` (`data.{variableName}` holds the selection). */
|
|
90
|
+
variableName?: string;
|
|
91
|
+
/** Name of the data object in the emitted bindings (`data` at top level, a row alias inside tables). */
|
|
92
|
+
dataVariable?: string;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Emit one `<v-radio>` for a {@link ChoiceItem}. When the choice has
|
|
96
|
+
* `textField: true`, the label text and a `<v-text-field>` are rendered
|
|
97
|
+
* together in the radio's `#label` slot so the field sits right after the
|
|
98
|
+
* label (the `label` prop is kept for the accessible name). The field binds
|
|
99
|
+
* `{dataVariable}.{radioChoiceTextVariable(variableName, value)}` and is
|
|
100
|
+
* disabled while another option is selected.
|
|
101
|
+
*/
|
|
102
|
+
export declare function radioChoiceToString(choiceItem: ChoiceItem, inputAttributes?: string, context?: RadioChoiceContext): string;
|
|
103
|
+
/**
|
|
104
|
+
* Build the `@update:model-value` handler for a radio group whose choices
|
|
105
|
+
* have `textField: true`. Each such choice's text variable is cleared (set to
|
|
106
|
+
* `undefined`) whenever the group changes to a value other than that choice —
|
|
107
|
+
* so a note typed beside T1 does not survive a switch to T2. The newly
|
|
108
|
+
* selected choice's own field is left untouched.
|
|
109
|
+
*
|
|
110
|
+
* Returns `''` when no choice has a text field, or when `inputAttributes`
|
|
111
|
+
* already defines an `@update:model-value` listener (the author's handler
|
|
112
|
+
* wins; a duplicate attribute would be a compile error).
|
|
113
|
+
*/
|
|
114
|
+
export declare function radioTextFieldClearHandler(choice: ChoiceItem[], variableName: string | undefined, dataVariable?: string, inputAttributes?: string): string;
|
|
44
115
|
export declare function optionStringToChoiceObject(option: string | object): ChoiceItem[];
|
|
45
116
|
export declare function escapeObjectForInlineBinding(obj: object): string;
|
|
46
117
|
/**
|
|
@@ -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
|
}
|
|
@@ -18,18 +18,18 @@ interface CalendarProps {
|
|
|
18
18
|
mode: 'dayGridMonth' | 'timeGridDay';
|
|
19
19
|
}
|
|
20
20
|
declare const __VLS_export: import("vue").DefineComponent<CalendarProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
21
|
-
select: (...args: any[]) => void;
|
|
22
21
|
dialog: (...args: any[]) => void;
|
|
22
|
+
select: (...args: any[]) => void;
|
|
23
23
|
}, string, import("vue").PublicProps, Readonly<CalendarProps> & Readonly<{
|
|
24
|
-
onSelect?: ((...args: any[]) => any) | undefined;
|
|
25
24
|
onDialog?: ((...args: any[]) => any) | undefined;
|
|
25
|
+
onSelect?: ((...args: any[]) => any) | undefined;
|
|
26
26
|
}>, {
|
|
27
|
+
height: string | number;
|
|
28
|
+
mode: "dayGridMonth" | "timeGridDay";
|
|
27
29
|
locale: "th" | "en";
|
|
28
30
|
toolBarLeft: string;
|
|
29
31
|
toolBarCenter: string;
|
|
30
32
|
toolBarRight: string;
|
|
31
|
-
height: string | number;
|
|
32
|
-
mode: "dayGridMonth" | "timeGridDay";
|
|
33
33
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
34
34
|
declare const _default: typeof __VLS_export;
|
|
35
35
|
export default _default;
|
|
@@ -18,18 +18,18 @@ interface CalendarProps {
|
|
|
18
18
|
mode: 'dayGridMonth' | 'timeGridDay';
|
|
19
19
|
}
|
|
20
20
|
declare const __VLS_export: import("vue").DefineComponent<CalendarProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
21
|
-
select: (...args: any[]) => void;
|
|
22
21
|
dialog: (...args: any[]) => void;
|
|
22
|
+
select: (...args: any[]) => void;
|
|
23
23
|
}, string, import("vue").PublicProps, Readonly<CalendarProps> & Readonly<{
|
|
24
|
-
onSelect?: ((...args: any[]) => any) | undefined;
|
|
25
24
|
onDialog?: ((...args: any[]) => any) | undefined;
|
|
25
|
+
onSelect?: ((...args: any[]) => any) | undefined;
|
|
26
26
|
}>, {
|
|
27
|
+
height: string | number;
|
|
28
|
+
mode: "dayGridMonth" | "timeGridDay";
|
|
27
29
|
locale: "th" | "en";
|
|
28
30
|
toolBarLeft: string;
|
|
29
31
|
toolBarCenter: string;
|
|
30
32
|
toolBarRight: string;
|
|
31
|
-
height: string | number;
|
|
32
|
-
mode: "dayGridMonth" | "timeGridDay";
|
|
33
33
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
34
34
|
declare const _default: typeof __VLS_export;
|
|
35
35
|
export default _default;
|