@ramathibodi/nuxt-commons 4.0.22 → 4.0.24
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/module.mjs +1 -1
- package/dist/runtime/calendar/mapping.d.ts +20 -0
- package/dist/runtime/calendar/mapping.js +51 -0
- package/dist/runtime/components/Calendar.d.vue.ts +109 -0
- package/dist/runtime/components/Calendar.vue +116 -0
- package/dist/runtime/components/Calendar.vue.d.ts +109 -0
- package/dist/runtime/components/document/TemplateBuilder.d.vue.ts +2 -2
- package/dist/runtime/components/document/TemplateBuilder.vue +7 -4
- package/dist/runtime/components/document/TemplateBuilder.vue.d.ts +2 -2
- package/dist/runtime/components/document/TemplateBuilderLiveView.d.vue.ts +72 -14
- package/dist/runtime/components/document/TemplateBuilderLiveView.vue +258 -107
- package/dist/runtime/components/document/TemplateBuilderLiveView.vue.d.ts +72 -14
- package/dist/runtime/components/document/TemplateItemForm.d.vue.ts +2 -2
- package/dist/runtime/components/document/TemplateItemForm.vue +8 -5
- package/dist/runtime/components/document/TemplateItemForm.vue.d.ts +2 -2
- package/dist/runtime/components/form/CheckboxGroup.vue +6 -6
- 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/types/calendar.d.ts +25 -0
- package/package.json +3 -9
- package/dist/runtime/labs/Calendar.d.vue.ts +0 -35
- package/dist/runtime/labs/Calendar.vue +0 -71
- package/dist/runtime/labs/Calendar.vue.d.ts +0 -35
|
@@ -1,19 +1,22 @@
|
|
|
1
1
|
<script setup>
|
|
2
2
|
import { computed, nextTick, onMounted, ref, watch } from "vue";
|
|
3
|
-
import { useMutationObserver } from "@vueuse/core";
|
|
3
|
+
import { useEventListener, useMutationObserver, useResizeObserver } from "@vueuse/core";
|
|
4
4
|
import { cloneDeep } from "lodash-es";
|
|
5
5
|
import { useDocumentTemplate } from "../../composables/document/template";
|
|
6
6
|
import { templateItemsForEdit, useDocumentTemplateBuilderModel } from "../../composables/document/templateBuilderModel";
|
|
7
7
|
import { getDocumentTemplateInputTypeEntry, useDocumentTemplateInputTypes } from "../../composables/document/templateInputTypes";
|
|
8
8
|
import { isDocumentTemplatePaletteDrag, readDocumentTemplatePaletteDrag } from "../../composables/document/templatePalette";
|
|
9
9
|
import { useDialog } from "../../composables/dialog";
|
|
10
|
+
import { useUserPermission } from "../../composables/userPermission";
|
|
10
11
|
const props = defineProps({
|
|
11
12
|
title: { type: String, required: false, default: "Document Template" },
|
|
12
|
-
|
|
13
|
+
roleCustomCode: { type: [String, Array], required: false, default: "superadmin" },
|
|
13
14
|
disableAdvanceMode: { type: Boolean, required: false, default: false },
|
|
14
15
|
templateScript: { type: String, required: false },
|
|
15
16
|
toolbarColor: { type: String, required: false, default: "primary" },
|
|
16
|
-
editorWidth: { type: [Number, String], required: false, default:
|
|
17
|
+
editorWidth: { type: [Number, String], required: false, default: void 0 },
|
|
18
|
+
dialogMaxWidth: { type: [Number, String], required: false, default: 960 },
|
|
19
|
+
dialogFullscreen: { type: Boolean, required: false, default: false },
|
|
17
20
|
outline: { type: Boolean, required: false, default: false },
|
|
18
21
|
initialData: { type: Object, required: false, default: () => ({}) },
|
|
19
22
|
importable: { type: Boolean, required: false, default: true },
|
|
@@ -32,9 +35,12 @@ const mode = ref("design");
|
|
|
32
35
|
const isDesignMode = computed(() => mode.value === "design" && !isAdvanceMode.value);
|
|
33
36
|
const outlineOpen = ref(props.outline);
|
|
34
37
|
const paletteOpen = ref(props.palette);
|
|
35
|
-
const panelOpen = ref(false);
|
|
36
38
|
const selectedIndex = ref(null);
|
|
37
|
-
const
|
|
39
|
+
const dialogOpen = ref(false);
|
|
40
|
+
const editingIndex = ref(null);
|
|
41
|
+
const editingItem = ref();
|
|
42
|
+
const pendingInsertIndex = ref(null);
|
|
43
|
+
const canvasRoot = ref();
|
|
38
44
|
const previewRoot = ref();
|
|
39
45
|
const previewData = ref({});
|
|
40
46
|
const showPreviewData = ref();
|
|
@@ -58,56 +64,101 @@ function itemTypeLabel(item) {
|
|
|
58
64
|
return inputTypeLabel.value[item.inputType] || item.inputType;
|
|
59
65
|
}
|
|
60
66
|
const hasNoVisual = (item) => ["Separator", "FormHidden"].includes(item?.inputType);
|
|
67
|
+
function selectItem(index) {
|
|
68
|
+
if (index !== null && (!Number.isInteger(index) || index < 0 || index >= templateItems.value.length)) return;
|
|
69
|
+
selectedIndex.value = index;
|
|
70
|
+
emit("select", index);
|
|
71
|
+
}
|
|
72
|
+
function commitPendingInsert() {
|
|
73
|
+
pendingInsertIndex.value = null;
|
|
74
|
+
}
|
|
61
75
|
function openCreate() {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
76
|
+
commitPendingInsert();
|
|
77
|
+
editingIndex.value = null;
|
|
78
|
+
editingItem.value = void 0;
|
|
79
|
+
dialogOpen.value = true;
|
|
66
80
|
}
|
|
67
81
|
function openEdit(index) {
|
|
68
|
-
if (index < 0 || index >= templateItems.value.length) return;
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
82
|
+
if (!Number.isInteger(index) || index < 0 || index >= templateItems.value.length) return;
|
|
83
|
+
if (pendingInsertIndex.value !== index) commitPendingInsert();
|
|
84
|
+
selectItem(index);
|
|
85
|
+
editingIndex.value = index;
|
|
86
|
+
editingItem.value = cloneDeep(templateItems.value[index]);
|
|
87
|
+
dialogOpen.value = true;
|
|
73
88
|
}
|
|
74
89
|
function closeEditor() {
|
|
75
|
-
|
|
76
|
-
selectedIndex.value = null;
|
|
77
|
-
emit("select", null);
|
|
90
|
+
dialogOpen.value = false;
|
|
78
91
|
}
|
|
92
|
+
function closeEditorNow() {
|
|
93
|
+
const pending = pendingInsertIndex.value;
|
|
94
|
+
pendingInsertIndex.value = null;
|
|
95
|
+
dialogOpen.value = false;
|
|
96
|
+
editingIndex.value = null;
|
|
97
|
+
editingItem.value = void 0;
|
|
98
|
+
if (pending !== null && pending < templateItems.value.length) removeItemAt(pending);
|
|
99
|
+
}
|
|
100
|
+
watch(dialogOpen, (open) => {
|
|
101
|
+
if (!open) closeEditorNow();
|
|
102
|
+
});
|
|
79
103
|
function onCreate(item, callback) {
|
|
80
|
-
templateItems.value.
|
|
104
|
+
const at = selectedIndex.value === null ? templateItems.value.length : selectedIndex.value + 1;
|
|
105
|
+
templateItems.value.splice(at, 0, item);
|
|
81
106
|
callback?.done();
|
|
82
|
-
|
|
107
|
+
selectItem(at);
|
|
83
108
|
}
|
|
84
109
|
function onUpdate(item, callback) {
|
|
85
|
-
const index =
|
|
110
|
+
const index = editingIndex.value;
|
|
86
111
|
if (index === null || index >= templateItems.value.length) {
|
|
87
112
|
callback?.error();
|
|
88
113
|
return;
|
|
89
114
|
}
|
|
115
|
+
commitPendingInsert();
|
|
90
116
|
templateItems.value.splice(index, 1, item);
|
|
91
|
-
editorRef.value?.setOriginalData(templateItems.value[index]);
|
|
92
117
|
callback?.done();
|
|
118
|
+
selectItem(index);
|
|
119
|
+
}
|
|
120
|
+
function shiftIndex(index, from, to) {
|
|
121
|
+
if (index === null) return null;
|
|
122
|
+
if (to === null) return index === from ? null : index > from ? index - 1 : index;
|
|
123
|
+
if (index === from) return to;
|
|
124
|
+
if (from < index && index <= to) return index - 1;
|
|
125
|
+
if (to <= index && index < from) return index + 1;
|
|
126
|
+
return index;
|
|
127
|
+
}
|
|
128
|
+
function removeItemAt(index) {
|
|
129
|
+
templateItems.value.splice(index, 1);
|
|
130
|
+
editingIndex.value = shiftIndex(editingIndex.value, index, null);
|
|
131
|
+
const selected = shiftIndex(selectedIndex.value, index, null);
|
|
132
|
+
if (selected !== selectedIndex.value) selectItem(selected);
|
|
133
|
+
}
|
|
134
|
+
function deleteItem(index) {
|
|
135
|
+
if (!Number.isInteger(index) || index < 0 || index >= templateItems.value.length) return;
|
|
136
|
+
commitPendingInsert();
|
|
137
|
+
if (editingIndex.value === index) closeEditor();
|
|
138
|
+
removeItemAt(index);
|
|
93
139
|
}
|
|
94
140
|
function deleteSelected() {
|
|
95
141
|
if (selectedIndex.value === null) return;
|
|
96
|
-
|
|
97
|
-
|
|
142
|
+
deleteItem(selectedIndex.value);
|
|
143
|
+
}
|
|
144
|
+
async function confirmDeleteItem(index) {
|
|
145
|
+
const item = templateItems.value[index];
|
|
146
|
+
if (!item) return;
|
|
147
|
+
const dialog = useDialog();
|
|
148
|
+
const label = describeItem(item) || itemTypeLabel(item);
|
|
149
|
+
const confirmed = dialog ? await dialog.confirm({ title: "Delete item", message: `Delete item ${index + 1} (${label})?` }) : true;
|
|
150
|
+
if (confirmed) deleteItem(index);
|
|
98
151
|
}
|
|
99
152
|
function moveItemTo(from, to) {
|
|
100
153
|
const length = templateItems.value.length;
|
|
101
154
|
if (!Number.isInteger(from) || !Number.isInteger(to)) return false;
|
|
102
155
|
if (from < 0 || from >= length || to < 0 || to >= length || from === to) return false;
|
|
156
|
+
commitPendingInsert();
|
|
103
157
|
const [moved] = templateItems.value.splice(from, 1);
|
|
104
158
|
templateItems.value.splice(to, 0, moved);
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
else if (from < selected && selected <= to) openEdit(selected - 1);
|
|
109
|
-
else if (to <= selected && selected < from) openEdit(selected + 1);
|
|
110
|
-
}
|
|
159
|
+
editingIndex.value = shiftIndex(editingIndex.value, from, to);
|
|
160
|
+
const selected = shiftIndex(selectedIndex.value, from, to);
|
|
161
|
+
if (selected !== selectedIndex.value) selectItem(selected);
|
|
111
162
|
emit("reorder", { from, to });
|
|
112
163
|
return true;
|
|
113
164
|
}
|
|
@@ -118,12 +169,18 @@ function moveSelected(delta) {
|
|
|
118
169
|
function moveItem(from, delta) {
|
|
119
170
|
moveItemTo(from, from + delta);
|
|
120
171
|
}
|
|
172
|
+
function duplicateItem(index) {
|
|
173
|
+
const source = templateItems.value[index];
|
|
174
|
+
if (!source) return;
|
|
175
|
+
commitPendingInsert();
|
|
176
|
+
const copy = cloneDeep(source);
|
|
177
|
+
delete copy.id;
|
|
178
|
+
templateItems.value.splice(index + 1, 0, copy);
|
|
179
|
+
selectItem(index + 1);
|
|
180
|
+
}
|
|
121
181
|
function duplicateSelected() {
|
|
122
182
|
if (selectedIndex.value === null) return;
|
|
123
|
-
|
|
124
|
-
delete copy.id;
|
|
125
|
-
templateItems.value.splice(selectedIndex.value + 1, 0, copy);
|
|
126
|
-
openEdit(selectedIndex.value + 1);
|
|
183
|
+
duplicateItem(selectedIndex.value);
|
|
127
184
|
}
|
|
128
185
|
function nextVariableName(inputType) {
|
|
129
186
|
const stem = inputType.replace(/^V(?=[A-Z])/, "").replace(/[^\w$]/g, "");
|
|
@@ -142,12 +199,16 @@ function insertInputType(inputType, index = templateItems.value.length) {
|
|
|
142
199
|
const item = { ...cloneDeep(props.initialData), inputType: type };
|
|
143
200
|
if (entry?.needsVariableName !== false && !item.variableName) item.variableName = nextVariableName(type);
|
|
144
201
|
if (entry?.needsLabel !== false && !item.inputLabel) item.inputLabel = (entry?.label || type).replace(/^\[[^\]]+\]/, "").trim();
|
|
202
|
+
commitPendingInsert();
|
|
145
203
|
templateItems.value.splice(at, 0, item);
|
|
146
204
|
emit("insert", { index: at, item });
|
|
147
205
|
openEdit(at);
|
|
206
|
+
pendingInsertIndex.value = at;
|
|
148
207
|
return at;
|
|
149
208
|
}
|
|
150
|
-
const
|
|
209
|
+
const permission = useUserPermission();
|
|
210
|
+
const canCustomCode = computed(() => permission.check(props.roleCustomCode));
|
|
211
|
+
const paletteExclude = computed(() => canCustomCode.value ? [] : ["CustomCode"]);
|
|
151
212
|
function onPaletteSelect(inputType) {
|
|
152
213
|
insertInputType(inputType, selectedIndex.value === null ? templateItems.value.length : selectedIndex.value + 1);
|
|
153
214
|
}
|
|
@@ -167,21 +228,62 @@ async function importItems(rows) {
|
|
|
167
228
|
buttonFalseText: "Append"
|
|
168
229
|
}) : false;
|
|
169
230
|
}
|
|
170
|
-
|
|
231
|
+
closeEditorNow();
|
|
232
|
+
selectItem(null);
|
|
171
233
|
if (replace) templateItems.value = incoming;
|
|
172
234
|
else templateItems.value.push(...incoming);
|
|
173
235
|
emit("import", { items: incoming, mode: replace ? "replace" : "append" });
|
|
174
236
|
}
|
|
175
237
|
function onPreviewClick(event) {
|
|
176
238
|
if (!isDesignMode.value) return;
|
|
177
|
-
const
|
|
178
|
-
const
|
|
179
|
-
if (
|
|
239
|
+
const host = itemHostFromEvent(event);
|
|
240
|
+
const index = host ? hostIndex(host) : null;
|
|
241
|
+
if (index === null) {
|
|
242
|
+
if (selectedIndex.value !== null) selectItem(null);
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
180
245
|
event.preventDefault();
|
|
181
246
|
event.stopPropagation();
|
|
182
|
-
|
|
183
|
-
if (Number.isInteger(index)) openEdit(index);
|
|
247
|
+
selectItem(index);
|
|
184
248
|
}
|
|
249
|
+
function onPreviewDblClick(event) {
|
|
250
|
+
if (!isDesignMode.value) return;
|
|
251
|
+
const host = itemHostFromEvent(event);
|
|
252
|
+
const index = host ? hostIndex(host) : null;
|
|
253
|
+
if (index === null) return;
|
|
254
|
+
event.preventDefault();
|
|
255
|
+
event.stopPropagation();
|
|
256
|
+
openEdit(index);
|
|
257
|
+
}
|
|
258
|
+
const hoveredIndex = ref(null);
|
|
259
|
+
function onPreviewHover(event) {
|
|
260
|
+
if (!isDesignMode.value) return;
|
|
261
|
+
const host = itemHostFromEvent(event);
|
|
262
|
+
hoveredIndex.value = host ? hostIndex(host) : null;
|
|
263
|
+
}
|
|
264
|
+
const overlayIndex = computed(() => {
|
|
265
|
+
if (!isDesignMode.value || dragIndex.value !== null || dialogOpen.value) return null;
|
|
266
|
+
const index = hoveredIndex.value ?? selectedIndex.value;
|
|
267
|
+
return index !== null && index < templateItems.value.length ? index : null;
|
|
268
|
+
});
|
|
269
|
+
const overlayRect = ref(null);
|
|
270
|
+
function updateOverlay() {
|
|
271
|
+
const index = overlayIndex.value;
|
|
272
|
+
const canvas = canvasRoot.value;
|
|
273
|
+
const host = index === null ? null : previewRoot.value?.querySelector(`[${ITEM_INDEX_ATTRIBUTE}="${index}"]`);
|
|
274
|
+
if (!host || !canvas) {
|
|
275
|
+
overlayRect.value = null;
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
const box = host.getBoundingClientRect();
|
|
279
|
+
const origin = canvas.getBoundingClientRect();
|
|
280
|
+
overlayRect.value = { top: box.top - origin.top, left: box.left - origin.left, width: box.width, height: box.height };
|
|
281
|
+
}
|
|
282
|
+
const overlayStyle = computed(() => {
|
|
283
|
+
const rect = overlayRect.value;
|
|
284
|
+
if (!rect) return {};
|
|
285
|
+
return { top: `${rect.top}px`, left: `${rect.left + rect.width}px` };
|
|
286
|
+
});
|
|
185
287
|
const DRAGGING_CLASS = "doc-live-view__item--dragging";
|
|
186
288
|
const DROP_CLASSES = {
|
|
187
289
|
before: "doc-live-view__item--drop-before",
|
|
@@ -307,27 +409,39 @@ function applySelectedHighlight() {
|
|
|
307
409
|
el.classList.toggle("doc-live-view__item--selected", isSelected);
|
|
308
410
|
});
|
|
309
411
|
}
|
|
310
|
-
watch(
|
|
412
|
+
watch(selectedIndex, () => nextTick(applySelectedHighlight));
|
|
311
413
|
onMounted(() => nextTick(applyDraggable));
|
|
312
414
|
watch([canSort, previewRoot], () => nextTick(applyDraggable));
|
|
313
415
|
useMutationObserver(previewRoot, () => {
|
|
314
416
|
applySelectedHighlight();
|
|
315
417
|
applyDraggable();
|
|
418
|
+
updateOverlay();
|
|
316
419
|
}, { childList: true, subtree: true });
|
|
420
|
+
watch(overlayIndex, () => nextTick(updateOverlay));
|
|
421
|
+
watch(isDesignMode, (design) => {
|
|
422
|
+
if (!design) hoveredIndex.value = null;
|
|
423
|
+
});
|
|
424
|
+
useResizeObserver(previewRoot, () => updateOverlay());
|
|
425
|
+
useEventListener(typeof window === "undefined" ? void 0 : window, "resize", () => updateOverlay());
|
|
317
426
|
watch(isAdvanceMode, (advance) => {
|
|
318
|
-
if (advance)
|
|
427
|
+
if (!advance) return;
|
|
428
|
+
closeEditorNow();
|
|
429
|
+
selectItem(null);
|
|
319
430
|
});
|
|
320
|
-
const operation = ref({ openCreate, openEdit, closeEditor, deleteSelected, moveSelected, moveItemTo, duplicateSelected, insertInputType, importItems, convertToAdvanceMode });
|
|
431
|
+
const operation = ref({ openCreate, openEdit, closeEditor, selectItem, deleteItem, deleteSelected, moveSelected, moveItemTo, duplicateItem, duplicateSelected, insertInputType, importItems, convertToAdvanceMode });
|
|
321
432
|
defineExpose({
|
|
322
433
|
templateItems,
|
|
323
434
|
previewData,
|
|
324
435
|
selectedIndex,
|
|
436
|
+
editingIndex,
|
|
437
|
+
dialogOpen,
|
|
325
438
|
dragIndex,
|
|
326
439
|
mode,
|
|
327
440
|
operation,
|
|
328
441
|
openCreate,
|
|
329
442
|
openEdit,
|
|
330
443
|
closeEditor,
|
|
444
|
+
selectItem,
|
|
331
445
|
moveItemTo,
|
|
332
446
|
insertInputType
|
|
333
447
|
});
|
|
@@ -384,7 +498,7 @@ defineExpose({
|
|
|
384
498
|
variant="flat"
|
|
385
499
|
:color="toolbarColor"
|
|
386
500
|
@click="convertToAdvanceMode()"
|
|
387
|
-
v-if="
|
|
501
|
+
v-if="canCustomCode && !disableAdvanceMode && !isAdvanceMode"
|
|
388
502
|
>
|
|
389
503
|
Convert To Advance
|
|
390
504
|
</v-btn>
|
|
@@ -482,7 +596,7 @@ defineExpose({
|
|
|
482
596
|
</button>
|
|
483
597
|
</div>
|
|
484
598
|
<span class="doc-live-view__hint text-caption text-medium-emphasis d-none d-sm-inline text-truncate" v-if="templateItems.length">
|
|
485
|
-
<template v-if="isDesignMode">Click a field to edit it<template v-if="sortable">, drag it to reorder</template><template v-if="paletteOpen">, drag a palette card to add one</template>. Switch to <b>Preview</b> to fill the form.</template>
|
|
599
|
+
<template v-if="isDesignMode">Click a field to select it, double-click or use its <v-icon size="13">mdi:mdi-pencil</v-icon> to edit it<template v-if="sortable">, drag it to reorder</template><template v-if="paletteOpen">, drag a palette card to add one</template>. Switch to <b>Preview</b> to fill the form.</template>
|
|
486
600
|
<template v-else>The form is live. Switch to <b>Design</b> to edit fields.</template>
|
|
487
601
|
</span>
|
|
488
602
|
<v-spacer />
|
|
@@ -490,36 +604,59 @@ defineExpose({
|
|
|
490
604
|
{{ templateItems.length }} {{ templateItems.length === 1 ? "field" : "fields" }}
|
|
491
605
|
</span>
|
|
492
606
|
</div>
|
|
493
|
-
<div
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
607
|
+
<div ref="canvasRoot" class="doc-live-view__canvas" @mouseleave="hoveredIndex = null">
|
|
608
|
+
<div
|
|
609
|
+
ref="previewRoot"
|
|
610
|
+
class="doc-live-view__preview px-2 pb-2"
|
|
611
|
+
:class="{ 'doc-live-view__preview--design': isDesignMode, 'doc-live-view__preview--sortable': canSort, 'doc-live-view__preview--dragging': dragIndex !== null, 'doc-live-view__preview--drop-end': dropAtEnd }"
|
|
612
|
+
@click.capture="onPreviewClick"
|
|
613
|
+
@dblclick.capture="onPreviewDblClick"
|
|
614
|
+
@mouseover="onPreviewHover"
|
|
615
|
+
@dragstart="onPreviewDragStart"
|
|
616
|
+
@dragover="onPreviewDragOver"
|
|
617
|
+
@dragleave="onPreviewDragLeave"
|
|
618
|
+
@drop="onPreviewDrop"
|
|
619
|
+
@dragend="finishDrag"
|
|
620
|
+
>
|
|
621
|
+
<slot name="empty" v-if="!templateItems.length" :operation="operation">
|
|
622
|
+
<v-sheet
|
|
623
|
+
class="d-flex flex-column align-center justify-center text-medium-emphasis pa-8 ma-2"
|
|
624
|
+
border
|
|
625
|
+
rounded
|
|
626
|
+
style="border-style: dashed !important; cursor: pointer"
|
|
627
|
+
@click="openCreate()"
|
|
628
|
+
>
|
|
629
|
+
<v-icon size="40" class="mb-2">mdi:mdi-plus-box-outline</v-icon>
|
|
630
|
+
<div class="text-body-2">No fields yet. Click <b>add</b> to create the first one.</div>
|
|
631
|
+
</v-sheet>
|
|
632
|
+
</slot>
|
|
633
|
+
<form-pad
|
|
634
|
+
v-else
|
|
635
|
+
v-model="previewData"
|
|
636
|
+
:template="previewTemplate"
|
|
637
|
+
:template-script="templateScript"
|
|
638
|
+
isolated
|
|
639
|
+
/>
|
|
640
|
+
</div>
|
|
641
|
+
<!-- Edit overlay: pinned to the hovered item, else the selected one -->
|
|
642
|
+
<div
|
|
643
|
+
v-if="overlayIndex !== null && overlayRect"
|
|
644
|
+
class="doc-live-view__overlay"
|
|
645
|
+
:style="overlayStyle"
|
|
646
|
+
role="toolbar"
|
|
647
|
+
:aria-label="`Item ${overlayIndex + 1} actions`"
|
|
648
|
+
@click.stop
|
|
649
|
+
@dblclick.stop
|
|
650
|
+
>
|
|
651
|
+
<slot name="itemOverlay" :index="overlayIndex" :item="templateItems[overlayIndex]" :operation="operation">
|
|
652
|
+
<span class="doc-live-view__overlay-label text-caption">{{ overlayIndex + 1 }} · {{ itemTypeLabel(templateItems[overlayIndex]) }}</span>
|
|
653
|
+
<v-btn class="doc-live-view__overlay-edit" icon="mdi:mdi-pencil" size="x-small" variant="flat" color="primary" density="comfortable" title="Edit" @click="openEdit(overlayIndex)" />
|
|
654
|
+
<v-btn icon="mdi:mdi-arrow-up-thick" size="x-small" variant="text" density="comfortable" title="Move up" :disabled="overlayIndex === 0" @click="moveItem(overlayIndex, -1)" />
|
|
655
|
+
<v-btn icon="mdi:mdi-arrow-down-thick" size="x-small" variant="text" density="comfortable" title="Move down" :disabled="overlayIndex === templateItems.length - 1" @click="moveItem(overlayIndex, 1)" />
|
|
656
|
+
<v-btn icon="mdi:mdi-content-copy" size="x-small" variant="text" density="comfortable" title="Duplicate" @click="duplicateItem(overlayIndex)" />
|
|
657
|
+
<v-btn class="doc-live-view__overlay-delete" icon="mdi:mdi-delete" size="x-small" variant="text" density="comfortable" color="error" title="Delete" @click="confirmDeleteItem(overlayIndex)" />
|
|
658
|
+
</slot>
|
|
659
|
+
</div>
|
|
523
660
|
</div>
|
|
524
661
|
<v-expansion-panels v-model="showPreviewData" variant="accordion" class="px-2 pb-2" v-if="mode === 'preview' && templateItems.length">
|
|
525
662
|
<v-expansion-panel :value="true">
|
|
@@ -539,41 +676,55 @@ defineExpose({
|
|
|
539
676
|
</slot>
|
|
540
677
|
</v-col>
|
|
541
678
|
|
|
542
|
-
<!-- Item editor side panel -->
|
|
543
|
-
<v-col cols="12" :md="editorWidth" v-if="panelOpen && !isAdvanceMode" class="doc-live-view__editor">
|
|
544
|
-
<v-toolbar density="compact" flat color="transparent">
|
|
545
|
-
<v-toolbar-title class="text-subtitle-1">
|
|
546
|
-
<template v-if="selectedIndex === null">New item</template>
|
|
547
|
-
<template v-else>
|
|
548
|
-
Item {{ selectedIndex + 1 }}
|
|
549
|
-
<span class="text-caption text-medium-emphasis" v-if="describeItem(templateItems[selectedIndex])"> · {{ describeItem(templateItems[selectedIndex]) }}</span>
|
|
550
|
-
</template>
|
|
551
|
-
</v-toolbar-title>
|
|
552
|
-
<template v-if="selectedIndex !== null">
|
|
553
|
-
<v-btn icon="mdi:mdi-arrow-up-thick" size="small" variant="text" :disabled="selectedIndex === 0" title="Move up" @click="moveSelected(-1)" />
|
|
554
|
-
<v-btn icon="mdi:mdi-arrow-down-thick" size="small" variant="text" :disabled="selectedIndex === templateItems.length - 1" title="Move down" @click="moveSelected(1)" />
|
|
555
|
-
<v-btn icon="mdi:mdi-content-copy" size="small" variant="text" title="Duplicate" @click="duplicateSelected()" />
|
|
556
|
-
<v-btn icon="mdi:mdi-delete" size="small" variant="text" color="error" title="Delete" @click="deleteSelected()" />
|
|
557
|
-
</template>
|
|
558
|
-
<v-btn icon="mdi:mdi-close" size="small" variant="text" title="Close" @click="closeEditor()" />
|
|
559
|
-
</v-toolbar>
|
|
560
|
-
<v-divider />
|
|
561
|
-
<form-action-pad
|
|
562
|
-
ref="editorRef"
|
|
563
|
-
title="Item"
|
|
564
|
-
:initial-data="initialData"
|
|
565
|
-
@create="onCreate"
|
|
566
|
-
@update="onUpdate"
|
|
567
|
-
>
|
|
568
|
-
<template #default="{ data, rules }">
|
|
569
|
-
<document-template-item-form :data="data" :rules="rules" :custom-code="customCode" />
|
|
570
|
-
</template>
|
|
571
|
-
</form-action-pad>
|
|
572
|
-
</v-col>
|
|
573
679
|
</v-row>
|
|
680
|
+
|
|
681
|
+
<!-- Item editor dialog: opens on a new item straight away, and from an item's edit overlay -->
|
|
682
|
+
<FormDialog
|
|
683
|
+
v-model="dialogOpen"
|
|
684
|
+
title="Item"
|
|
685
|
+
:form-data="editingItem"
|
|
686
|
+
:initial-data="initialData"
|
|
687
|
+
:fullscreen="dialogFullscreen"
|
|
688
|
+
:max-width="dialogMaxWidth"
|
|
689
|
+
@create="onCreate"
|
|
690
|
+
@update="onUpdate"
|
|
691
|
+
>
|
|
692
|
+
<template #title>
|
|
693
|
+
<template v-if="editingIndex === null">New item</template>
|
|
694
|
+
<template v-else>
|
|
695
|
+
<template v-if="pendingInsertIndex !== null">New {{ itemTypeLabel(templateItems[editingIndex]) }}</template>
|
|
696
|
+
<template v-else>Item {{ editingIndex + 1 }}</template>
|
|
697
|
+
<span class="text-body-2 text-medium-emphasis" v-if="pendingInsertIndex === null && describeItem(templateItems[editingIndex])"> · {{ describeItem(templateItems[editingIndex]) }}</span>
|
|
698
|
+
</template>
|
|
699
|
+
</template>
|
|
700
|
+
<template #default="{ data, rules }">
|
|
701
|
+
<document-template-item-form :data="data" :rules="rules" :role-custom-code="roleCustomCode" />
|
|
702
|
+
</template>
|
|
703
|
+
<template #action="{ operation: dialogOperation }">
|
|
704
|
+
<v-spacer />
|
|
705
|
+
<!-- A just-inserted item is saveable as seeded: cancelling would remove it. -->
|
|
706
|
+
<v-btn
|
|
707
|
+
color="primary"
|
|
708
|
+
variant="flat"
|
|
709
|
+
:loading="dialogOperation.isSaving"
|
|
710
|
+
:disabled="!dialogOperation.isDataChange && pendingInsertIndex === null"
|
|
711
|
+
@click="dialogOperation.save()"
|
|
712
|
+
>
|
|
713
|
+
{{ pendingInsertIndex !== null || editingIndex === null ? "Add" : "Save" }}
|
|
714
|
+
</v-btn>
|
|
715
|
+
<v-btn
|
|
716
|
+
color="error"
|
|
717
|
+
variant="flat"
|
|
718
|
+
:disabled="dialogOperation.isSaving"
|
|
719
|
+
@click="dialogOperation.cancel()"
|
|
720
|
+
>
|
|
721
|
+
{{ pendingInsertIndex !== null ? "Discard" : dialogOperation.isDataChange ? "Cancel" : "Close" }}
|
|
722
|
+
</v-btn>
|
|
723
|
+
</template>
|
|
724
|
+
</FormDialog>
|
|
574
725
|
</v-card>
|
|
575
726
|
</template>
|
|
576
727
|
|
|
577
728
|
<style scoped>
|
|
578
|
-
.doc-live-view__outline{border-right:thin solid rgba(var(--v-border-color),var(--v-border-opacity))}.doc-live-
|
|
729
|
+
.doc-live-view__outline{border-right:thin solid rgba(var(--v-border-color),var(--v-border-opacity))}.doc-live-view__palette{border-left:thin solid rgba(var(--v-border-color),var(--v-border-opacity))}.doc-live-view__canvas{position:relative}.doc-live-view__overlay{align-items:center;background:rgb(var(--v-theme-surface));border-radius:999px;box-shadow:0 1px 3px rgba(0,0,0,.18),0 0 0 1px rgba(var(--v-theme-primary),.35);display:inline-flex;gap:2px;padding:2px 4px 2px 8px;position:absolute;transform:translate(calc(-100% - 4px),-50%);white-space:nowrap;z-index:2}.doc-live-view__overlay-label{color:rgba(var(--v-theme-on-surface),var(--v-medium-emphasis-opacity));margin-right:4px;max-width:14em;overflow:hidden;text-overflow:ellipsis}.doc-live-view__preview--drop-end{background-color:rgba(var(--v-theme-primary),.03);border-radius:4px;outline:2px dashed rgba(var(--v-theme-primary),.7);outline-offset:-4px}.doc-live-view__preview-col{min-width:0}.doc-live-view__preview-bar{align-items:center;border-bottom:thin solid rgba(var(--v-border-color),var(--v-border-opacity));display:flex;gap:12px;min-height:44px;padding:4px 12px}.doc-live-view__bar-label{color:rgba(var(--v-theme-on-surface),var(--v-medium-emphasis-opacity));flex-shrink:0;letter-spacing:.12em;line-height:1}.doc-live-view__hint{min-width:0}.doc-live-view__count{font-variant-numeric:tabular-nums}.doc-live-view__mode-toggle{background:rgba(var(--v-theme-on-surface),.06);border-radius:999px;display:inline-flex;flex-shrink:0;gap:2px;padding:3px}.doc-live-view__mode{align-items:center;background:transparent;border:0;border-radius:999px;color:rgba(var(--v-theme-on-surface),var(--v-medium-emphasis-opacity));cursor:pointer;display:inline-flex;font:inherit;font-size:.8125rem;font-weight:500;gap:6px;height:28px;line-height:1;padding:0 12px 0 10px;transition:background-color .18s ease,color .18s ease,box-shadow .18s ease}.doc-live-view__mode:hover{color:rgba(var(--v-theme-on-surface),var(--v-high-emphasis-opacity))}.doc-live-view__mode:focus-visible{outline:2px solid rgba(var(--v-theme-primary),.5);outline-offset:1px}.doc-live-view__mode--active{background:rgb(var(--v-theme-surface));box-shadow:0 1px 2px rgba(0,0,0,.14),0 0 0 1px rgba(var(--v-theme-on-surface),.06);color:rgb(var(--v-theme-primary))}.doc-live-view__preview{padding-top:8px;transition:background-color .22s ease}.doc-live-view__preview--design{background-color:rgba(var(--v-theme-on-surface),.015);background-image:radial-gradient(rgba(var(--v-theme-on-surface),.14) 1px,transparent 1px);background-position:8px 8px;background-size:16px 16px}.doc-live-view__preview--design :deep([data-doc-item]){border-radius:4px;cursor:pointer;outline:1px dashed transparent;outline-offset:2px;transition:outline-color .12s ease,background-color .12s ease}.doc-live-view__preview--design :deep([data-doc-item]>*){pointer-events:none}.doc-live-view__preview--design :deep([data-doc-item]:hover){background-color:rgba(var(--v-theme-primary),.04);outline-color:rgba(var(--v-theme-primary),.6)}.doc-live-view__preview :deep([data-doc-item].doc-live-view__item--selected){background-color:rgba(var(--v-theme-primary),.06);border-radius:4px;outline:2px solid rgb(var(--v-theme-primary));outline-offset:2px}.doc-live-view__preview--sortable :deep([data-doc-item]){cursor:grab}.doc-live-view__preview--dragging :deep([data-doc-item]){cursor:grabbing}.doc-live-view__preview :deep([data-doc-item].doc-live-view__item--dragging){opacity:.4}.doc-live-view__preview :deep([data-doc-item].doc-live-view__item--drop-before){box-shadow:-4px 0 0 0 rgb(var(--v-theme-primary))}.doc-live-view__preview :deep([data-doc-item].doc-live-view__item--drop-after){box-shadow:4px 0 0 0 rgb(var(--v-theme-primary))}.doc-live-view__preview :deep([data-doc-item].doc-live-view__item--drop-above){box-shadow:0 -4px 0 0 rgb(var(--v-theme-primary))}.doc-live-view__preview :deep([data-doc-item].doc-live-view__item--drop-below){box-shadow:0 4px 0 0 rgb(var(--v-theme-primary))}
|
|
579
730
|
</style>
|