@ramathibodi/nuxt-commons 4.0.22 → 4.0.23

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 CHANGED
@@ -4,7 +4,7 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^4.3.1"
6
6
  },
7
- "version": "4.0.22",
7
+ "version": "4.0.23",
8
8
  "builder": {
9
9
  "@nuxt/module-builder": "1.0.2",
10
10
  "unbuild": "3.6.1"
@@ -1,7 +1,7 @@
1
1
  import 'vue-json-pretty/lib/styles.css';
2
2
  interface Props {
3
3
  title?: string;
4
- customCode?: boolean;
4
+ roleCustomCode?: string | string[];
5
5
  disableAdvanceMode?: boolean;
6
6
  }
7
7
  /**
@@ -28,7 +28,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {},
28
28
  "onUpdate:modelValue"?: ((value: string | Record<string, any>[] | undefined) => any) | undefined;
29
29
  }>, {
30
30
  title: string;
31
- customCode: boolean;
31
+ roleCustomCode: string | string[];
32
32
  disableAdvanceMode: boolean;
33
33
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
34
34
  declare const _default: typeof __VLS_export;
@@ -1,21 +1,24 @@
1
1
  <script setup>
2
- import { ref } from "vue";
2
+ import { computed, ref } from "vue";
3
3
  import {
4
4
  printConfigToAttributes,
5
5
  rowsToPrintConfig
6
6
  } from "../../composables/document/template";
7
7
  import { useDocumentTemplateBuilderModel } from "../../composables/document/templateBuilderModel";
8
+ import { useUserPermission } from "../../composables/userPermission";
8
9
  import VueJsonPretty from "vue-json-pretty";
9
10
  import "vue-json-pretty/lib/styles.css";
10
11
  import { safeParseJSONDeep } from "../../utils/object";
11
12
  const props = defineProps({
12
13
  title: { type: String, required: false, default: "Document Template" },
13
- customCode: { type: Boolean, required: false, default: false },
14
+ roleCustomCode: { type: [String, Array], required: false, default: "superadmin" },
14
15
  disableAdvanceMode: { type: Boolean, required: false, default: false }
15
16
  });
16
17
  const emit = defineEmits(["update:modelValue"]);
17
18
  const modelValue = defineModel({ type: [String, Array] });
18
19
  const { templateItems, isAdvanceMode, advanceModeCode, convertToAdvanceMode } = useDocumentTemplateBuilderModel(modelValue);
20
+ const permission = useUserPermission();
21
+ const canCustomCode = computed(() => permission.check(props.roleCustomCode));
19
22
  const headers = ref([
20
23
  {
21
24
  title: "",
@@ -70,7 +73,7 @@ function printConfigPreview(printConfig) {
70
73
  color="primary"
71
74
  variant="flat"
72
75
  @click="convertToAdvanceMode()"
73
- v-if="customCode && !disableAdvanceMode"
76
+ v-if="canCustomCode && !disableAdvanceMode"
74
77
  >
75
78
  Convert To Advance
76
79
  </VBtn>
@@ -79,7 +82,7 @@ function printConfigPreview(printConfig) {
79
82
  {{ internalItem.index }}
80
83
  </template>
81
84
  <template #form="{ data, rules }">
82
- <document-template-item-form :data="data" :rules="rules" :custom-code="customCode" />
85
+ <document-template-item-form :data="data" :rules="rules" :role-custom-code="roleCustomCode" />
83
86
  </template>
84
87
  <template #item.configuration="props">
85
88
  <v-sheet
@@ -1,7 +1,7 @@
1
1
  import 'vue-json-pretty/lib/styles.css';
2
2
  interface Props {
3
3
  title?: string;
4
- customCode?: boolean;
4
+ roleCustomCode?: string | string[];
5
5
  disableAdvanceMode?: boolean;
6
6
  }
7
7
  /**
@@ -28,7 +28,7 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {},
28
28
  "onUpdate:modelValue"?: ((value: string | Record<string, any>[] | undefined) => any) | undefined;
29
29
  }>, {
30
30
  title: string;
31
- customCode: boolean;
31
+ roleCustomCode: string | string[];
32
32
  disableAdvanceMode: boolean;
33
33
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
34
34
  declare const _default: typeof __VLS_export;
@@ -1,11 +1,13 @@
1
1
  export type DocumentTemplateImportMode = 'ask' | 'append' | 'replace';
2
2
  interface Props {
3
3
  title?: string;
4
- customCode?: boolean;
4
+ roleCustomCode?: string | string[];
5
5
  disableAdvanceMode?: boolean;
6
6
  templateScript?: string;
7
7
  toolbarColor?: string;
8
8
  editorWidth?: number | string;
9
+ dialogMaxWidth?: number | string;
10
+ dialogFullscreen?: boolean;
9
11
  outline?: boolean;
10
12
  initialData?: Record<string, any>;
11
13
  importable?: boolean;
@@ -20,13 +22,17 @@ interface Props {
20
22
  * Public props accepted by DocumentTemplateBuilderLiveView.
21
23
  *
22
24
  * Two surface modes are available from the live view's own bar (above the preview):
23
- * - **Design** (default) — the preview is a click target: clicking any rendered
24
- * field opens that item in the side panel. Inputs are not interactive.
25
+ * - **Design** (default) — the preview is a click target: clicking a rendered
26
+ * field selects it and pins its **edit overlay** (edit · move · duplicate ·
27
+ * delete); hovering a field shows the same overlay. The overlay's edit
28
+ * button, or a double-click on the field, opens the item editor **dialog**.
29
+ * Inputs are not interactive.
25
30
  * - **Preview** — the preview is a live, fillable form so you can try the
26
31
  * validations; the data typed is shown in the "Preview data" panel.
27
32
  *
28
33
  * Items with no visual (`FormHidden`, `Separator`) are reachable from the
29
- * **Outline** list, which also offers reordering for every item.
34
+ * **Outline** list (a click opens the editor dialog), which also offers
35
+ * reordering for every item.
30
36
  *
31
37
  * In Design mode every rendered field is also a drag handle: drop it on the
32
38
  * left / top half of another field to insert before it, on the right / bottom
@@ -36,27 +42,39 @@ interface Props {
36
42
  * per input type. Drag a card into the live view to insert a new item of that
37
43
  * type where it lands (the same before / after halves apply; anywhere else in
38
44
  * the preview appends), or click a card to add one after the selected item.
39
- * The new item opens in the editor so its label / variable can be filled in.
45
+ * The new item's settings dialog opens at once; cancelling it removes the
46
+ * item again, saving keeps it.
40
47
  */
41
48
  type __VLS_Props = Props;
49
+ /** Select (highlight + pin the edit overlay on) the item at `index`, or clear the selection with `null`. */
50
+ declare function selectItem(index: number | null): void;
51
+ /** Open the item editor dialog blank; saving inserts after the selected item, or at the end. */
42
52
  declare function openCreate(): void;
53
+ /** Select the item at `index` and open it in the item editor dialog. */
43
54
  declare function openEdit(index: number): void;
55
+ /** Close the item editor dialog (the selection is kept). An unsaved palette insert is removed. */
44
56
  declare function closeEditor(): void;
57
+ /** Remove the item at `index` straight away (no confirmation). */
58
+ declare function deleteItem(index: number): void;
45
59
  declare function deleteSelected(): void;
46
60
  /**
47
61
  * Move the item at `from` so it lands at index `to` (its index *after* the
48
- * move). The editor selection follows the moved item; a selected neighbour
49
- * that got shifted by the move keeps pointing at the same item.
62
+ * move). The selection follows the moved item; a selected neighbour that got
63
+ * shifted by the move keeps pointing at the same item.
50
64
  */
51
65
  declare function moveItemTo(from: number, to: number): boolean;
52
66
  declare function moveSelected(delta: number): void;
67
+ /** Insert a copy of the item at `index` right after it and select the copy. */
68
+ declare function duplicateItem(index: number): void;
53
69
  declare function duplicateSelected(): void;
54
70
  /**
55
71
  * Insert a fresh item of `inputType` at `index` (clamped; defaults to the
56
- * end) and open it in the editor. The item is seeded from `initialData` plus
57
- * a unique `variableName` and a default `inputLabel` (when the type needs
72
+ * end) and open its settings dialog. The item is seeded from `initialData`
73
+ * plus a unique `variableName` and a default `inputLabel` (when the type needs
58
74
  * them) so it renders in the preview right away — an item with no variable
59
75
  * name would compile to `v-model="data."` and blank the whole preview.
76
+ * Cancelling that dialog removes the item again; saving it (or any other
77
+ * structural edit, including another insert) keeps it.
60
78
  * Returns the index it landed at.
61
79
  */
62
80
  declare function insertInputType(inputType: string, index?: number): number;
@@ -76,28 +94,52 @@ declare var __VLS_20: {}, __VLS_28: {
76
94
  openCreate: typeof openCreate;
77
95
  openEdit: typeof openEdit;
78
96
  closeEditor: typeof closeEditor;
97
+ selectItem: typeof selectItem;
98
+ deleteItem: typeof deleteItem;
79
99
  deleteSelected: typeof deleteSelected;
80
100
  moveSelected: typeof moveSelected;
81
101
  moveItemTo: typeof moveItemTo;
102
+ duplicateItem: typeof duplicateItem;
82
103
  duplicateSelected: typeof duplicateSelected;
83
104
  insertInputType: typeof insertInputType;
84
105
  importItems: typeof importItems;
85
106
  convertToAdvanceMode: () => Promise<void>;
86
107
  };
87
- }, __VLS_197: {
108
+ }, __VLS_203: {
88
109
  operation: {
89
110
  openCreate: typeof openCreate;
90
111
  openEdit: typeof openEdit;
91
112
  closeEditor: typeof closeEditor;
113
+ selectItem: typeof selectItem;
114
+ deleteItem: typeof deleteItem;
92
115
  deleteSelected: typeof deleteSelected;
93
116
  moveSelected: typeof moveSelected;
94
117
  moveItemTo: typeof moveItemTo;
118
+ duplicateItem: typeof duplicateItem;
95
119
  duplicateSelected: typeof duplicateSelected;
96
120
  insertInputType: typeof insertInputType;
97
121
  importItems: typeof importItems;
98
122
  convertToAdvanceMode: () => Promise<void>;
99
123
  };
100
- }, __VLS_248: {
124
+ }, __VLS_224: {
125
+ index: number;
126
+ item: Record<string, any>;
127
+ operation: {
128
+ openCreate: typeof openCreate;
129
+ openEdit: typeof openEdit;
130
+ closeEditor: typeof closeEditor;
131
+ selectItem: typeof selectItem;
132
+ deleteItem: typeof deleteItem;
133
+ deleteSelected: typeof deleteSelected;
134
+ moveSelected: typeof moveSelected;
135
+ moveItemTo: typeof moveItemTo;
136
+ duplicateItem: typeof duplicateItem;
137
+ duplicateSelected: typeof duplicateSelected;
138
+ insertInputType: typeof insertInputType;
139
+ importItems: typeof importItems;
140
+ convertToAdvanceMode: () => Promise<void>;
141
+ };
142
+ }, __VLS_291: {
101
143
  insert: typeof insertInputType;
102
144
  disabled: boolean;
103
145
  };
@@ -106,23 +148,30 @@ type __VLS_Slots = {} & {
106
148
  } & {
107
149
  toolbarItems?: (props: typeof __VLS_28) => any;
108
150
  } & {
109
- empty?: (props: typeof __VLS_197) => any;
151
+ empty?: (props: typeof __VLS_203) => any;
152
+ } & {
153
+ itemOverlay?: (props: typeof __VLS_224) => any;
110
154
  } & {
111
- palette?: (props: typeof __VLS_248) => any;
155
+ palette?: (props: typeof __VLS_291) => any;
112
156
  };
113
157
  declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
114
158
  templateItems: import("vue").Ref<Record<string, any>[], Record<string, any>[]>;
115
159
  previewData: import("vue").Ref<Record<string, any>, Record<string, any>>;
116
160
  selectedIndex: import("vue").Ref<number | null, number | null>;
161
+ editingIndex: import("vue").Ref<number | null, number | null>;
162
+ dialogOpen: import("vue").Ref<boolean, boolean>;
117
163
  dragIndex: import("vue").Ref<number | null, number | null>;
118
164
  mode: import("vue").Ref<"design" | "preview", "design" | "preview">;
119
165
  operation: import("vue").Ref<{
120
166
  openCreate: typeof openCreate;
121
167
  openEdit: typeof openEdit;
122
168
  closeEditor: typeof closeEditor;
169
+ selectItem: typeof selectItem;
170
+ deleteItem: typeof deleteItem;
123
171
  deleteSelected: typeof deleteSelected;
124
172
  moveSelected: typeof moveSelected;
125
173
  moveItemTo: typeof moveItemTo;
174
+ duplicateItem: typeof duplicateItem;
126
175
  duplicateSelected: typeof duplicateSelected;
127
176
  insertInputType: typeof insertInputType;
128
177
  importItems: typeof importItems;
@@ -131,9 +180,12 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
131
180
  openCreate: typeof openCreate;
132
181
  openEdit: typeof openEdit;
133
182
  closeEditor: typeof closeEditor;
183
+ selectItem: typeof selectItem;
184
+ deleteItem: typeof deleteItem;
134
185
  deleteSelected: typeof deleteSelected;
135
186
  moveSelected: typeof moveSelected;
136
187
  moveItemTo: typeof moveItemTo;
188
+ duplicateItem: typeof duplicateItem;
137
189
  duplicateSelected: typeof duplicateSelected;
138
190
  insertInputType: typeof insertInputType;
139
191
  importItems: typeof importItems;
@@ -142,9 +194,12 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
142
194
  openCreate: typeof openCreate;
143
195
  openEdit: typeof openEdit;
144
196
  closeEditor: typeof closeEditor;
197
+ selectItem: typeof selectItem;
198
+ deleteItem: typeof deleteItem;
145
199
  deleteSelected: typeof deleteSelected;
146
200
  moveSelected: typeof moveSelected;
147
201
  moveItemTo: typeof moveItemTo;
202
+ duplicateItem: typeof duplicateItem;
148
203
  duplicateSelected: typeof duplicateSelected;
149
204
  insertInputType: typeof insertInputType;
150
205
  importItems: typeof importItems;
@@ -153,6 +208,7 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
153
208
  openCreate: typeof openCreate;
154
209
  openEdit: typeof openEdit;
155
210
  closeEditor: typeof closeEditor;
211
+ selectItem: typeof selectItem;
156
212
  moveItemTo: typeof moveItemTo;
157
213
  insertInputType: typeof insertInputType;
158
214
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
@@ -163,10 +219,12 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
163
219
  title: string;
164
220
  stringFields: string[];
165
221
  initialData: Record<string, any>;
166
- customCode: boolean;
222
+ roleCustomCode: string | string[];
167
223
  disableAdvanceMode: boolean;
168
224
  toolbarColor: string;
169
225
  editorWidth: number | string;
226
+ dialogMaxWidth: number | string;
227
+ dialogFullscreen: boolean;
170
228
  outline: boolean;
171
229
  importable: boolean;
172
230
  exportable: boolean;
@@ -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
- customCode: { type: Boolean, required: false, default: false },
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: 5 },
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 editorRef = ref();
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
- selectedIndex.value = null;
63
- panelOpen.value = true;
64
- nextTick(() => editorRef.value?.setOriginalData(void 0));
65
- emit("select", null);
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
- selectedIndex.value = index;
70
- panelOpen.value = true;
71
- nextTick(() => editorRef.value?.setOriginalData(templateItems.value[index]));
72
- emit("select", index);
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
- panelOpen.value = false;
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.push(item);
104
+ const at = selectedIndex.value === null ? templateItems.value.length : selectedIndex.value + 1;
105
+ templateItems.value.splice(at, 0, item);
81
106
  callback?.done();
82
- openEdit(templateItems.value.length - 1);
107
+ selectItem(at);
83
108
  }
84
109
  function onUpdate(item, callback) {
85
- const index = selectedIndex.value;
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
- templateItems.value.splice(selectedIndex.value, 1);
97
- closeEditor();
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
- const selected = selectedIndex.value;
106
- if (selected !== null) {
107
- if (selected === from) openEdit(to);
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
- const copy = cloneDeep(templateItems.value[selectedIndex.value]);
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 paletteExclude = computed(() => props.customCode ? [] : ["CustomCode"]);
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
- closeEditor();
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 target = event.target;
178
- const host = target?.closest?.(`[${ITEM_INDEX_ATTRIBUTE}]`);
179
- if (!host || !previewRoot.value?.contains(host)) return;
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
- const index = Number(host.getAttribute(ITEM_INDEX_ATTRIBUTE));
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([selectedIndex, panelOpen], () => nextTick(applySelectedHighlight));
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) closeEditor();
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="customCode && !disableAdvanceMode && !isAdvanceMode"
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
- ref="previewRoot"
495
- class="doc-live-view__preview px-2 pb-2"
496
- :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 }"
497
- @click.capture="onPreviewClick"
498
- @dragstart="onPreviewDragStart"
499
- @dragover="onPreviewDragOver"
500
- @dragleave="onPreviewDragLeave"
501
- @drop="onPreviewDrop"
502
- @dragend="finishDrag"
503
- >
504
- <slot name="empty" v-if="!templateItems.length" :operation="operation">
505
- <v-sheet
506
- class="d-flex flex-column align-center justify-center text-medium-emphasis pa-8 ma-2"
507
- border
508
- rounded
509
- style="border-style: dashed !important; cursor: pointer"
510
- @click="openCreate()"
511
- >
512
- <v-icon size="40" class="mb-2">mdi:mdi-plus-box-outline</v-icon>
513
- <div class="text-body-2">No fields yet. Click <b>add</b> to create the first one.</div>
514
- </v-sheet>
515
- </slot>
516
- <form-pad
517
- v-else
518
- v-model="previewData"
519
- :template="previewTemplate"
520
- :template-script="templateScript"
521
- isolated
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-view__editor,.doc-live-view__palette{border-left:thin solid rgba(var(--v-border-color),var(--v-border-opacity))}.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))}
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>
@@ -1,11 +1,13 @@
1
1
  export type DocumentTemplateImportMode = 'ask' | 'append' | 'replace';
2
2
  interface Props {
3
3
  title?: string;
4
- customCode?: boolean;
4
+ roleCustomCode?: string | string[];
5
5
  disableAdvanceMode?: boolean;
6
6
  templateScript?: string;
7
7
  toolbarColor?: string;
8
8
  editorWidth?: number | string;
9
+ dialogMaxWidth?: number | string;
10
+ dialogFullscreen?: boolean;
9
11
  outline?: boolean;
10
12
  initialData?: Record<string, any>;
11
13
  importable?: boolean;
@@ -20,13 +22,17 @@ interface Props {
20
22
  * Public props accepted by DocumentTemplateBuilderLiveView.
21
23
  *
22
24
  * Two surface modes are available from the live view's own bar (above the preview):
23
- * - **Design** (default) — the preview is a click target: clicking any rendered
24
- * field opens that item in the side panel. Inputs are not interactive.
25
+ * - **Design** (default) — the preview is a click target: clicking a rendered
26
+ * field selects it and pins its **edit overlay** (edit · move · duplicate ·
27
+ * delete); hovering a field shows the same overlay. The overlay's edit
28
+ * button, or a double-click on the field, opens the item editor **dialog**.
29
+ * Inputs are not interactive.
25
30
  * - **Preview** — the preview is a live, fillable form so you can try the
26
31
  * validations; the data typed is shown in the "Preview data" panel.
27
32
  *
28
33
  * Items with no visual (`FormHidden`, `Separator`) are reachable from the
29
- * **Outline** list, which also offers reordering for every item.
34
+ * **Outline** list (a click opens the editor dialog), which also offers
35
+ * reordering for every item.
30
36
  *
31
37
  * In Design mode every rendered field is also a drag handle: drop it on the
32
38
  * left / top half of another field to insert before it, on the right / bottom
@@ -36,27 +42,39 @@ interface Props {
36
42
  * per input type. Drag a card into the live view to insert a new item of that
37
43
  * type where it lands (the same before / after halves apply; anywhere else in
38
44
  * the preview appends), or click a card to add one after the selected item.
39
- * The new item opens in the editor so its label / variable can be filled in.
45
+ * The new item's settings dialog opens at once; cancelling it removes the
46
+ * item again, saving keeps it.
40
47
  */
41
48
  type __VLS_Props = Props;
49
+ /** Select (highlight + pin the edit overlay on) the item at `index`, or clear the selection with `null`. */
50
+ declare function selectItem(index: number | null): void;
51
+ /** Open the item editor dialog blank; saving inserts after the selected item, or at the end. */
42
52
  declare function openCreate(): void;
53
+ /** Select the item at `index` and open it in the item editor dialog. */
43
54
  declare function openEdit(index: number): void;
55
+ /** Close the item editor dialog (the selection is kept). An unsaved palette insert is removed. */
44
56
  declare function closeEditor(): void;
57
+ /** Remove the item at `index` straight away (no confirmation). */
58
+ declare function deleteItem(index: number): void;
45
59
  declare function deleteSelected(): void;
46
60
  /**
47
61
  * Move the item at `from` so it lands at index `to` (its index *after* the
48
- * move). The editor selection follows the moved item; a selected neighbour
49
- * that got shifted by the move keeps pointing at the same item.
62
+ * move). The selection follows the moved item; a selected neighbour that got
63
+ * shifted by the move keeps pointing at the same item.
50
64
  */
51
65
  declare function moveItemTo(from: number, to: number): boolean;
52
66
  declare function moveSelected(delta: number): void;
67
+ /** Insert a copy of the item at `index` right after it and select the copy. */
68
+ declare function duplicateItem(index: number): void;
53
69
  declare function duplicateSelected(): void;
54
70
  /**
55
71
  * Insert a fresh item of `inputType` at `index` (clamped; defaults to the
56
- * end) and open it in the editor. The item is seeded from `initialData` plus
57
- * a unique `variableName` and a default `inputLabel` (when the type needs
72
+ * end) and open its settings dialog. The item is seeded from `initialData`
73
+ * plus a unique `variableName` and a default `inputLabel` (when the type needs
58
74
  * them) so it renders in the preview right away — an item with no variable
59
75
  * name would compile to `v-model="data."` and blank the whole preview.
76
+ * Cancelling that dialog removes the item again; saving it (or any other
77
+ * structural edit, including another insert) keeps it.
60
78
  * Returns the index it landed at.
61
79
  */
62
80
  declare function insertInputType(inputType: string, index?: number): number;
@@ -76,28 +94,52 @@ declare var __VLS_20: {}, __VLS_28: {
76
94
  openCreate: typeof openCreate;
77
95
  openEdit: typeof openEdit;
78
96
  closeEditor: typeof closeEditor;
97
+ selectItem: typeof selectItem;
98
+ deleteItem: typeof deleteItem;
79
99
  deleteSelected: typeof deleteSelected;
80
100
  moveSelected: typeof moveSelected;
81
101
  moveItemTo: typeof moveItemTo;
102
+ duplicateItem: typeof duplicateItem;
82
103
  duplicateSelected: typeof duplicateSelected;
83
104
  insertInputType: typeof insertInputType;
84
105
  importItems: typeof importItems;
85
106
  convertToAdvanceMode: () => Promise<void>;
86
107
  };
87
- }, __VLS_197: {
108
+ }, __VLS_203: {
88
109
  operation: {
89
110
  openCreate: typeof openCreate;
90
111
  openEdit: typeof openEdit;
91
112
  closeEditor: typeof closeEditor;
113
+ selectItem: typeof selectItem;
114
+ deleteItem: typeof deleteItem;
92
115
  deleteSelected: typeof deleteSelected;
93
116
  moveSelected: typeof moveSelected;
94
117
  moveItemTo: typeof moveItemTo;
118
+ duplicateItem: typeof duplicateItem;
95
119
  duplicateSelected: typeof duplicateSelected;
96
120
  insertInputType: typeof insertInputType;
97
121
  importItems: typeof importItems;
98
122
  convertToAdvanceMode: () => Promise<void>;
99
123
  };
100
- }, __VLS_248: {
124
+ }, __VLS_224: {
125
+ index: number;
126
+ item: Record<string, any>;
127
+ operation: {
128
+ openCreate: typeof openCreate;
129
+ openEdit: typeof openEdit;
130
+ closeEditor: typeof closeEditor;
131
+ selectItem: typeof selectItem;
132
+ deleteItem: typeof deleteItem;
133
+ deleteSelected: typeof deleteSelected;
134
+ moveSelected: typeof moveSelected;
135
+ moveItemTo: typeof moveItemTo;
136
+ duplicateItem: typeof duplicateItem;
137
+ duplicateSelected: typeof duplicateSelected;
138
+ insertInputType: typeof insertInputType;
139
+ importItems: typeof importItems;
140
+ convertToAdvanceMode: () => Promise<void>;
141
+ };
142
+ }, __VLS_291: {
101
143
  insert: typeof insertInputType;
102
144
  disabled: boolean;
103
145
  };
@@ -106,23 +148,30 @@ type __VLS_Slots = {} & {
106
148
  } & {
107
149
  toolbarItems?: (props: typeof __VLS_28) => any;
108
150
  } & {
109
- empty?: (props: typeof __VLS_197) => any;
151
+ empty?: (props: typeof __VLS_203) => any;
152
+ } & {
153
+ itemOverlay?: (props: typeof __VLS_224) => any;
110
154
  } & {
111
- palette?: (props: typeof __VLS_248) => any;
155
+ palette?: (props: typeof __VLS_291) => any;
112
156
  };
113
157
  declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
114
158
  templateItems: import("vue").Ref<Record<string, any>[], Record<string, any>[]>;
115
159
  previewData: import("vue").Ref<Record<string, any>, Record<string, any>>;
116
160
  selectedIndex: import("vue").Ref<number | null, number | null>;
161
+ editingIndex: import("vue").Ref<number | null, number | null>;
162
+ dialogOpen: import("vue").Ref<boolean, boolean>;
117
163
  dragIndex: import("vue").Ref<number | null, number | null>;
118
164
  mode: import("vue").Ref<"design" | "preview", "design" | "preview">;
119
165
  operation: import("vue").Ref<{
120
166
  openCreate: typeof openCreate;
121
167
  openEdit: typeof openEdit;
122
168
  closeEditor: typeof closeEditor;
169
+ selectItem: typeof selectItem;
170
+ deleteItem: typeof deleteItem;
123
171
  deleteSelected: typeof deleteSelected;
124
172
  moveSelected: typeof moveSelected;
125
173
  moveItemTo: typeof moveItemTo;
174
+ duplicateItem: typeof duplicateItem;
126
175
  duplicateSelected: typeof duplicateSelected;
127
176
  insertInputType: typeof insertInputType;
128
177
  importItems: typeof importItems;
@@ -131,9 +180,12 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
131
180
  openCreate: typeof openCreate;
132
181
  openEdit: typeof openEdit;
133
182
  closeEditor: typeof closeEditor;
183
+ selectItem: typeof selectItem;
184
+ deleteItem: typeof deleteItem;
134
185
  deleteSelected: typeof deleteSelected;
135
186
  moveSelected: typeof moveSelected;
136
187
  moveItemTo: typeof moveItemTo;
188
+ duplicateItem: typeof duplicateItem;
137
189
  duplicateSelected: typeof duplicateSelected;
138
190
  insertInputType: typeof insertInputType;
139
191
  importItems: typeof importItems;
@@ -142,9 +194,12 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
142
194
  openCreate: typeof openCreate;
143
195
  openEdit: typeof openEdit;
144
196
  closeEditor: typeof closeEditor;
197
+ selectItem: typeof selectItem;
198
+ deleteItem: typeof deleteItem;
145
199
  deleteSelected: typeof deleteSelected;
146
200
  moveSelected: typeof moveSelected;
147
201
  moveItemTo: typeof moveItemTo;
202
+ duplicateItem: typeof duplicateItem;
148
203
  duplicateSelected: typeof duplicateSelected;
149
204
  insertInputType: typeof insertInputType;
150
205
  importItems: typeof importItems;
@@ -153,6 +208,7 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
153
208
  openCreate: typeof openCreate;
154
209
  openEdit: typeof openEdit;
155
210
  closeEditor: typeof closeEditor;
211
+ selectItem: typeof selectItem;
156
212
  moveItemTo: typeof moveItemTo;
157
213
  insertInputType: typeof insertInputType;
158
214
  }, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
@@ -163,10 +219,12 @@ declare const __VLS_base: import("vue").DefineComponent<__VLS_PublicProps, {
163
219
  title: string;
164
220
  stringFields: string[];
165
221
  initialData: Record<string, any>;
166
- customCode: boolean;
222
+ roleCustomCode: string | string[];
167
223
  disableAdvanceMode: boolean;
168
224
  toolbarColor: string;
169
225
  editorWidth: number | string;
226
+ dialogMaxWidth: number | string;
227
+ dialogFullscreen: boolean;
170
228
  outline: boolean;
171
229
  importable: boolean;
172
230
  exportable: boolean;
@@ -1,11 +1,11 @@
1
1
  interface Props {
2
2
  data: Record<string, any>;
3
3
  rules?: Record<string, any>;
4
- customCode?: boolean;
4
+ roleCustomCode?: string | string[];
5
5
  }
6
6
  declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
7
7
  rules: Record<string, any>;
8
- customCode: boolean;
8
+ roleCustomCode: string | string[];
9
9
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
10
  declare const _default: typeof __VLS_export;
11
11
  export default _default;
@@ -14,10 +14,11 @@ import {
14
14
  } from "../../composables/document/templateInputTypes";
15
15
  import { autoActionHeader, templateToHeader } from "../../composables/document/templateFormTable";
16
16
  import { useRules } from "../../composables/utils/validation";
17
+ import { useUserPermission } from "../../composables/userPermission";
17
18
  const props = defineProps({
18
19
  data: { type: Object, required: true },
19
20
  rules: { type: Object, required: false, default: void 0 },
20
- customCode: { type: Boolean, required: false, default: false }
21
+ roleCustomCode: { type: [String, Array], required: false, default: "superadmin" }
21
22
  });
22
23
  const fallbackRules = useRules().rules;
23
24
  const rules = computed(() => props.rules ?? fallbackRules.value);
@@ -51,7 +52,9 @@ function printConfigPreview(printConfig) {
51
52
  return printConfigToAttributes(printConfig);
52
53
  }
53
54
  const inputTypes = computed(() => useDocumentTemplateInputTypes());
54
- const inputTypeChoice = computed(() => inputTypes.value.filter((t) => props.customCode || t.value !== "CustomCode").map((t) => ({ label: t.label, value: t.value })));
55
+ const permission = useUserPermission();
56
+ const canCustomCode = computed(() => permission.check(props.roleCustomCode));
57
+ const inputTypeChoice = computed(() => inputTypes.value.filter((t) => canCustomCode.value || t.value !== "CustomCode").map((t) => ({ label: t.label, value: t.value })));
55
58
  const requireOption = computed(() => inputTypes.value.filter((t) => t.requiresOptions).map((t) => t.value));
56
59
  const notRequireVariable = computed(() => inputTypes.value.filter((t) => t.needsVariableName === false).map((t) => t.value));
57
60
  const notRequireLabel = computed(() => inputTypes.value.filter((t) => t.needsLabel === false).map((t) => t.value));
@@ -139,7 +142,7 @@ const ruleOptions = (inputType) => (value) => {
139
142
  </form-table>
140
143
  </v-col>
141
144
  <v-col cols="12">
142
- <document-template-builder v-model="optionData.formTemplate" title="Form Template" :custom-code="customCode"></document-template-builder>
145
+ <document-template-builder v-model="optionData.formTemplate" title="Form Template" :role-custom-code="roleCustomCode"></document-template-builder>
143
146
  </v-col>
144
147
  </v-row>
145
148
  </template>
@@ -156,10 +159,10 @@ const ruleOptions = (inputType) => (value) => {
156
159
  </template>
157
160
  <template #items>
158
161
  <v-tabs-window-item value="itemTemplate">
159
- <document-template-builder v-model="optionData.itemTemplate" title="Item Template" :custom-code="customCode" disable-advance-mode></document-template-builder>
162
+ <document-template-builder v-model="optionData.itemTemplate" title="Item Template" :role-custom-code="roleCustomCode" disable-advance-mode></document-template-builder>
160
163
  </v-tabs-window-item>
161
164
  <v-tabs-window-item value="dataTemplate">
162
- <document-template-builder v-model="optionData.dataTemplate" title="Data Template" :custom-code="customCode" disable-advance-mode></document-template-builder>
165
+ <document-template-builder v-model="optionData.dataTemplate" title="Data Template" :role-custom-code="roleCustomCode" disable-advance-mode></document-template-builder>
163
166
  </v-tabs-window-item>
164
167
  <v-tabs-window-item value="header">
165
168
  <form-table v-model="optionData.headers" :headers="formTableHeaders" title="Headers">
@@ -1,11 +1,11 @@
1
1
  interface Props {
2
2
  data: Record<string, any>;
3
3
  rules?: Record<string, any>;
4
- customCode?: boolean;
4
+ roleCustomCode?: string | string[];
5
5
  }
6
6
  declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
7
7
  rules: Record<string, any>;
8
- customCode: boolean;
8
+ roleCustomCode: string | string[];
9
9
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
10
10
  declare const _default: typeof __VLS_export;
11
11
  export default _default;
@@ -34,12 +34,12 @@ const computedOther = computed(() => {
34
34
  const computeItems = computed(() => {
35
35
  return reject(props.items, { value: "other" });
36
36
  });
37
- watch(values, () => {
38
- emit("update:modelValue", [...values.value, valuesOther.value].filter(Boolean));
39
- }, { deep: true });
40
- watch(valuesOther, () => {
41
- emit("update:modelValue", [...values.value, valuesOther.value].filter(Boolean));
42
- });
37
+ function emitModelValue() {
38
+ const merged = valuesOther.value !== void 0 && valuesOther.value !== "" ? [...values.value, valuesOther.value] : [...values.value];
39
+ emit("update:modelValue", merged);
40
+ }
41
+ watch(values, emitModelValue, { deep: true });
42
+ watch(valuesOther, emitModelValue);
43
43
  watch(props.modelValue, () => {
44
44
  if (!props.modelValue) {
45
45
  values.value = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ramathibodi/nuxt-commons",
3
- "version": "4.0.22",
3
+ "version": "4.0.23",
4
4
  "description": "Ramathibodi Nuxt modules for common components",
5
5
  "repository": {
6
6
  "type": "git",