@xelqun/forms 0.1.0 → 0.2.0
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/README.md +46 -61
- package/package.json +32 -2
- package/resources/css/xelqun.css +121 -0
- package/resources/js/components/XqAction.vue +143 -0
- package/resources/js/components/XqFieldSlot.vue +20 -0
- package/resources/js/components/XqFieldWrapper.vue +74 -30
- package/resources/js/components/XqForm.vue +36 -9
- package/resources/js/components/XqNode.vue +8 -1
- package/resources/js/components/XqUnknownNode.vue +2 -1
- package/resources/js/components/defaults.ts +36 -0
- package/resources/js/components/fields/XqBlockPicker.vue +68 -0
- package/resources/js/components/fields/XqCheckboxField.vue +35 -9
- package/resources/js/components/fields/XqCheckboxListField.vue +115 -0
- package/resources/js/components/fields/XqCodeEditorField.vue +92 -0
- package/resources/js/components/fields/XqColorPickerField.vue +156 -0
- package/resources/js/components/fields/XqDatePickerField.vue +149 -53
- package/resources/js/components/fields/XqFileUploadField.vue +524 -165
- package/resources/js/components/fields/XqImageEditor.vue +165 -0
- package/resources/js/components/fields/XqKeyValueField.vue +168 -0
- package/resources/js/components/fields/XqMarkdownEditorField.vue +245 -0
- package/resources/js/components/fields/XqRadioField.vue +9 -5
- package/resources/js/components/fields/XqRepeaterField.vue +314 -79
- package/resources/js/components/fields/XqRepeaterRowActions.vue +101 -0
- package/resources/js/components/fields/XqRichEditorField.vue +280 -0
- package/resources/js/components/fields/XqSelectField.vue +29 -12
- package/resources/js/components/fields/XqSliderField.vue +47 -0
- package/resources/js/components/fields/XqTagsInputField.vue +127 -0
- package/resources/js/components/fields/XqTextInputField.vue +121 -12
- package/resources/js/components/fields/XqTextareaField.vue +39 -16
- package/resources/js/components/fields/XqToggleButtonsField.vue +75 -0
- package/resources/js/components/fields/XqToggleField.vue +33 -9
- package/resources/js/components/layouts/XqActions.vue +19 -0
- package/resources/js/components/layouts/XqBlock.vue +52 -0
- package/resources/js/components/layouts/XqCallout.vue +46 -0
- package/resources/js/components/layouts/XqEmptyState.vue +37 -0
- package/resources/js/components/layouts/XqFlex.vue +23 -0
- package/resources/js/components/layouts/XqFusedGroup.vue +48 -0
- package/resources/js/components/layouts/XqIconNode.vue +32 -0
- package/resources/js/components/layouts/XqImageNode.vue +30 -0
- package/resources/js/components/layouts/XqSection.vue +3 -1
- package/resources/js/components/layouts/XqTabsLayout.vue +3 -21
- package/resources/js/components/layouts/XqTextNode.vue +49 -0
- package/resources/js/components/layouts/XqUnorderedList.vue +18 -0
- package/resources/js/components/layouts/XqWizard.vue +168 -0
- package/resources/js/composables/context.ts +14 -0
- package/resources/js/composables/useField.ts +21 -3
- package/resources/js/composables/usePanelErrors.ts +37 -0
- package/resources/js/composables/useSortable.ts +70 -0
- package/resources/js/composables/useUnsavedChangesAlert.ts +48 -0
- package/resources/js/core/dates.ts +38 -0
- package/resources/js/core/images.ts +110 -0
- package/resources/js/core/log.ts +1 -1
- package/resources/js/core/markdown.ts +61 -0
- package/resources/js/core/mask.ts +42 -0
- package/resources/js/core/patch.ts +6 -3
- package/resources/js/core/paths.ts +11 -14
- package/resources/js/core/store.ts +515 -25
- package/resources/js/core/translate.ts +17 -0
- package/resources/js/core/validation.ts +126 -0
- package/resources/js/index.ts +4 -3
- package/resources/js/lib/utils.ts +15 -0
- package/resources/js/plugin.ts +103 -6
- package/resources/js/schema/types.ts +102 -0
- package/resources/js/testing.ts +50 -0
- package/resources/js/ui/XqCalendar.vue +4 -0
- package/resources/js/ui/XqCombobox.vue +89 -32
- package/resources/js/ui/XqConfirmDialog.vue +58 -0
- package/resources/js/ui/XqDialog.vue +46 -0
- package/resources/js/ui/XqIcon.vue +28 -0
- package/resources/js/ui/XqSelect.vue +38 -18
- package/resources/js/ui/XqTabs.vue +1 -1
- package/resources/js/ui/XqTimeField.vue +66 -0
- package/resources/js/ui/classes.ts +33 -0
- package/resources/js/ui/icons.ts +95 -0
- package/resources/js/ui/index.ts +5 -0
- package/resources/js/ui/options.ts +46 -0
|
@@ -1,22 +1,48 @@
|
|
|
1
1
|
<script setup lang="ts">
|
|
2
|
-
import {
|
|
3
|
-
import { computed, nextTick, ref } from 'vue';
|
|
2
|
+
import { GripVertical, Plus } from 'lucide-vue-next';
|
|
3
|
+
import { computed, nextTick, ref, watch } from 'vue';
|
|
4
4
|
import { gridStyle } from '../../composables/layout';
|
|
5
5
|
import { useField } from '../../composables/useField';
|
|
6
|
-
import
|
|
6
|
+
import { useSortable } from '../../composables/useSortable';
|
|
7
|
+
import { startsWithPath } from '../../core/paths';
|
|
8
|
+
import { cn, focusFirstEnabled } from '../../lib/utils';
|
|
9
|
+
import type { BlockOption, SchemaNode } from '../../schema/types';
|
|
7
10
|
import XqButton from '../../ui/XqButton.vue';
|
|
11
|
+
import XqConfirmDialog from '../../ui/XqConfirmDialog.vue';
|
|
8
12
|
import XqFieldWrapper from '../XqFieldWrapper.vue';
|
|
9
13
|
import XqNode from '../XqNode.vue';
|
|
14
|
+
import XqBlockPicker from './XqBlockPicker.vue';
|
|
15
|
+
import XqRepeaterRowActions from './XqRepeaterRowActions.vue';
|
|
16
|
+
import { useTranslator } from '../../composables/context';
|
|
10
17
|
|
|
18
|
+
const t = useTranslator();
|
|
11
19
|
const props = defineProps<{ node: SchemaNode }>();
|
|
12
|
-
const { store, error, required, disabled, id } = useField(props.node);
|
|
20
|
+
const { store, path, error, required, disabled, id } = useField(props.node);
|
|
13
21
|
const options = computed(() => props.node.props ?? {});
|
|
14
22
|
const keys = computed(() => store.rowKeys(props.node));
|
|
15
|
-
const
|
|
23
|
+
const allRows = computed<Record<string, SchemaNode[]>>(() => options.value.rows ?? {});
|
|
24
|
+
const rows = computed(() =>
|
|
25
|
+
Object.fromEntries(
|
|
26
|
+
Object.entries(allRows.value).map(([key, nodes]) => [
|
|
27
|
+
key,
|
|
28
|
+
nodes.filter((child) => child.slot !== 'itemAction'),
|
|
29
|
+
]),
|
|
30
|
+
),
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
function itemActions(key: string): SchemaNode[] {
|
|
34
|
+
return (allRows.value[key] ?? []).filter((child) => child.slot === 'itemAction');
|
|
35
|
+
}
|
|
36
|
+
|
|
16
37
|
const container = ref<HTMLElement | null>(null);
|
|
38
|
+
const rowList = ref<HTMLElement | null>(null);
|
|
39
|
+
const isTable = computed(() => !!options.value.table);
|
|
40
|
+
const isSimple = computed(() => !!options.value.simple);
|
|
41
|
+
|
|
17
42
|
const canAdd = computed(
|
|
18
43
|
() =>
|
|
19
44
|
!disabled.value &&
|
|
45
|
+
options.value.addable !== false &&
|
|
20
46
|
(options.value.maxItems === null ||
|
|
21
47
|
options.value.maxItems === undefined ||
|
|
22
48
|
keys.value.length < options.value.maxItems),
|
|
@@ -25,25 +51,56 @@ const canRemove = computed(
|
|
|
25
51
|
() => !disabled.value && keys.value.length > (options.value.minItems ?? 0),
|
|
26
52
|
);
|
|
27
53
|
|
|
28
|
-
/**
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
54
|
+
/** The attributes the action buttons need, the same in every layout. */
|
|
55
|
+
function actions(index: number) {
|
|
56
|
+
return {
|
|
57
|
+
label: options.value.itemLabel,
|
|
58
|
+
index,
|
|
59
|
+
count: keys.value.length,
|
|
60
|
+
disabled: disabled.value,
|
|
61
|
+
orderable: options.value.orderable,
|
|
62
|
+
showClone: !!options.value.cloneable,
|
|
63
|
+
canClone: canAdd.value,
|
|
64
|
+
showRemove: options.value.deletable !== false,
|
|
65
|
+
canRemove: canRemove.value,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const blocks = computed<BlockOption[] | null>(() => options.value.blocks ?? null);
|
|
34
70
|
|
|
35
|
-
|
|
36
|
-
|
|
71
|
+
const usedBlocks = computed(() => {
|
|
72
|
+
const counts: Record<string, number> = {};
|
|
37
73
|
|
|
38
|
-
|
|
39
|
-
}
|
|
74
|
+
for (const key of keys.value) {
|
|
75
|
+
const type = store.get(`${path}.${key}.type`);
|
|
76
|
+
|
|
77
|
+
counts[type] = (counts[type] ?? 0) + 1;
|
|
40
78
|
}
|
|
79
|
+
|
|
80
|
+
return counts;
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
function titleOf(index: number): string {
|
|
84
|
+
const type = store.get(`${path}.${keys.value[index]}.type`);
|
|
85
|
+
const title =
|
|
86
|
+
blocks.value?.find((block) => block.name === type)?.label ?? options.value.itemLabel;
|
|
87
|
+
|
|
88
|
+
return options.value.itemNumbers === false ? title : `${title} ${index + 1}`;
|
|
41
89
|
}
|
|
42
90
|
|
|
43
91
|
function rowSelector(key: string): string {
|
|
44
92
|
return `[data-xq-row="${CSS.escape(key)}"]`;
|
|
45
93
|
}
|
|
46
94
|
|
|
95
|
+
async function focusRow(key: string): Promise<void> {
|
|
96
|
+
await nextTick();
|
|
97
|
+
store.root.value
|
|
98
|
+
?.querySelector<HTMLElement>(
|
|
99
|
+
`${rowSelector(key)} input:not([type=hidden]), ${rowSelector(key)} button[role=combobox]`,
|
|
100
|
+
)
|
|
101
|
+
?.focus();
|
|
102
|
+
}
|
|
103
|
+
|
|
47
104
|
async function remove(key: string, index: number): Promise<void> {
|
|
48
105
|
store.removeRow(props.node, key);
|
|
49
106
|
|
|
@@ -51,12 +108,31 @@ async function remove(key: string, index: number): Promise<void> {
|
|
|
51
108
|
|
|
52
109
|
const next = keys.value[Math.min(index, keys.value.length - 1)];
|
|
53
110
|
|
|
54
|
-
focusFirstEnabled([
|
|
111
|
+
focusFirstEnabled(container.value, [
|
|
55
112
|
...(next ? [`${rowSelector(next)} [data-xq-remove]`] : []),
|
|
56
113
|
'[data-xq-add]',
|
|
57
114
|
]);
|
|
58
115
|
}
|
|
59
116
|
|
|
117
|
+
/** Kept when the dialog closes, because closing runs before the confirm click. */
|
|
118
|
+
const pendingRemoval = ref<{ key: string; index: number } | null>(null);
|
|
119
|
+
const isConfirming = ref(false);
|
|
120
|
+
|
|
121
|
+
function requestRemove(key: string, index: number): void {
|
|
122
|
+
if (options.value.deleteConfirmation) {
|
|
123
|
+
pendingRemoval.value = { key, index };
|
|
124
|
+
isConfirming.value = true;
|
|
125
|
+
} else {
|
|
126
|
+
void remove(key, index);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
function confirmRemove(): void {
|
|
131
|
+
if (pendingRemoval.value) {
|
|
132
|
+
void remove(pendingRemoval.value.key, pendingRemoval.value.index);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
60
136
|
async function move(key: string, direction: -1 | 1): Promise<void> {
|
|
61
137
|
store.moveRow(props.node, key, direction);
|
|
62
138
|
|
|
@@ -64,103 +140,262 @@ async function move(key: string, direction: -1 | 1): Promise<void> {
|
|
|
64
140
|
|
|
65
141
|
const row = rowSelector(key);
|
|
66
142
|
|
|
67
|
-
focusFirstEnabled([
|
|
143
|
+
focusFirstEnabled(container.value, [
|
|
68
144
|
`${row} [data-xq-move="${direction}"]`,
|
|
69
145
|
`${row} [data-xq-move="${-direction}"]`,
|
|
70
146
|
]);
|
|
71
147
|
}
|
|
72
148
|
|
|
73
|
-
|
|
74
|
-
|
|
149
|
+
function add(block?: string): void {
|
|
150
|
+
void focusRow(store.addRow(props.node, block));
|
|
151
|
+
}
|
|
75
152
|
|
|
76
|
-
|
|
77
|
-
store.
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
153
|
+
function clone(key: string): void {
|
|
154
|
+
void focusRow(store.cloneRow(props.node, key));
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
const collapsedRows = ref(new Set<string>(options.value.collapsed ? keys.value : []));
|
|
158
|
+
|
|
159
|
+
function hasError(key: string): boolean {
|
|
160
|
+
return Object.keys(store.errors).some((errorPath) =>
|
|
161
|
+
startsWithPath(errorPath, `${path}.${key}`),
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
// Opened for good: if this only lasted as long as the error, typing the fix would close the row.
|
|
166
|
+
watch(
|
|
167
|
+
() => keys.value.filter(hasError),
|
|
168
|
+
(rowsWithErrors) => rowsWithErrors.forEach((key) => collapsedRows.value.delete(key)),
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
function isCollapsed(key: string): boolean {
|
|
172
|
+
return collapsedRows.value.has(key);
|
|
82
173
|
}
|
|
174
|
+
|
|
175
|
+
function toggle(key: string): void {
|
|
176
|
+
if (!collapsedRows.value.delete(key)) {
|
|
177
|
+
collapsedRows.value.add(key);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
const canDrag = computed(
|
|
182
|
+
() => !!options.value.draggable && !disabled.value && keys.value.length > 1,
|
|
183
|
+
);
|
|
184
|
+
|
|
185
|
+
useSortable(rowList, {
|
|
186
|
+
draggable: '> [data-xq-row]',
|
|
187
|
+
handle: `[data-xq-drag="${path}"]`,
|
|
188
|
+
enabled: () => canDrag.value,
|
|
189
|
+
onMove: (from, to) => store.moveRow(props.node, keys.value[from], to - from),
|
|
190
|
+
});
|
|
83
191
|
</script>
|
|
84
192
|
|
|
85
193
|
<template>
|
|
86
194
|
<XqFieldWrapper :node="node" :id="id" :error="error" :required="required">
|
|
87
195
|
<div ref="container" class="gap-3 grid">
|
|
88
|
-
<div
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
196
|
+
<div v-if="isTable" class="overflow-x-auto rounded-xq-lg border border-xq-border">
|
|
197
|
+
<table class="text-sm w-full border-collapse">
|
|
198
|
+
<thead>
|
|
199
|
+
<tr class="border-b border-xq-border bg-xq-muted/50">
|
|
200
|
+
<th
|
|
201
|
+
v-for="column in options.table"
|
|
202
|
+
:key="column.label"
|
|
203
|
+
scope="col"
|
|
204
|
+
:style="column.width ? { width: column.width } : undefined"
|
|
205
|
+
class="px-3 py-2 font-medium text-left text-xq-muted-foreground"
|
|
206
|
+
>
|
|
207
|
+
<span :class="column.hiddenLabel ? 'sr-only' : undefined">
|
|
208
|
+
{{ column.label }}
|
|
209
|
+
</span>
|
|
210
|
+
<span
|
|
211
|
+
v-if="column.required"
|
|
212
|
+
class="text-xq-destructive"
|
|
213
|
+
aria-hidden="true"
|
|
214
|
+
>*</span
|
|
215
|
+
>
|
|
216
|
+
</th>
|
|
217
|
+
<th scope="col" class="w-px">
|
|
218
|
+
<span class="sr-only">{{ t('Actions') }}</span>
|
|
219
|
+
</th>
|
|
220
|
+
</tr>
|
|
221
|
+
</thead>
|
|
222
|
+
<tbody ref="rowList">
|
|
223
|
+
<tr
|
|
224
|
+
v-for="(key, index) in keys"
|
|
225
|
+
:key="key"
|
|
226
|
+
:data-xq-row="key"
|
|
227
|
+
:class="cn('border-b border-xq-border last:border-b-0')"
|
|
228
|
+
>
|
|
229
|
+
<td
|
|
230
|
+
v-for="child in rows[key] ?? []"
|
|
231
|
+
:key="child.key"
|
|
232
|
+
class="px-3 py-2 align-top [&_[data-slot=xq-label]]:sr-only"
|
|
233
|
+
>
|
|
234
|
+
<XqNode :node="child" />
|
|
235
|
+
</td>
|
|
236
|
+
<td class="px-2 py-2 align-top">
|
|
237
|
+
<div class="gap-1 flex items-center justify-end">
|
|
238
|
+
<span
|
|
239
|
+
v-if="canDrag"
|
|
240
|
+
aria-hidden="true"
|
|
241
|
+
class="cursor-grab touch-none text-xq-muted-foreground"
|
|
242
|
+
:data-xq-drag="path"
|
|
243
|
+
>
|
|
244
|
+
<GripVertical class="size-4" />
|
|
245
|
+
</span>
|
|
246
|
+
<XqRepeaterRowActions
|
|
247
|
+
v-bind="actions(index)"
|
|
248
|
+
@move="move(key, $event)"
|
|
249
|
+
@clone="clone(key)"
|
|
250
|
+
@remove="requestRemove(key, index)"
|
|
251
|
+
>
|
|
252
|
+
<XqNode
|
|
253
|
+
v-for="action in itemActions(key)"
|
|
254
|
+
:key="action.key"
|
|
255
|
+
:node="action"
|
|
256
|
+
/>
|
|
257
|
+
</XqRepeaterRowActions>
|
|
258
|
+
</div>
|
|
259
|
+
</td>
|
|
260
|
+
</tr>
|
|
261
|
+
</tbody>
|
|
262
|
+
</table>
|
|
263
|
+
</div>
|
|
264
|
+
<div v-else ref="rowList" class="xq-grid gap-3" :style="gridStyle(options.grid)">
|
|
96
265
|
<div
|
|
97
|
-
|
|
266
|
+
v-for="(key, index) in keys"
|
|
267
|
+
:key="key"
|
|
268
|
+
:data-xq-row="key"
|
|
269
|
+
role="group"
|
|
270
|
+
:aria-label="`${options.itemLabel} ${index + 1}`"
|
|
271
|
+
:class="
|
|
272
|
+
cn(
|
|
273
|
+
!isSimple &&
|
|
274
|
+
'shadow-xs rounded-xq-lg border border-xq-border bg-xq-card',
|
|
275
|
+
isSimple && 'gap-2 flex items-start',
|
|
276
|
+
)
|
|
277
|
+
"
|
|
98
278
|
>
|
|
99
|
-
<
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
279
|
+
<template v-if="isSimple">
|
|
280
|
+
<span
|
|
281
|
+
v-if="canDrag"
|
|
282
|
+
aria-hidden="true"
|
|
283
|
+
class="mt-2.5 cursor-grab touch-none text-xq-muted-foreground"
|
|
284
|
+
:data-xq-drag="path"
|
|
285
|
+
>
|
|
286
|
+
<GripVertical class="size-4" />
|
|
287
|
+
</span>
|
|
288
|
+
<div class="min-w-0 flex-1">
|
|
289
|
+
<XqNode
|
|
290
|
+
v-for="child in rows[key] ?? []"
|
|
291
|
+
:key="child.key"
|
|
292
|
+
:node="child"
|
|
293
|
+
/>
|
|
294
|
+
</div>
|
|
295
|
+
<XqRepeaterRowActions
|
|
296
|
+
v-bind="actions(index)"
|
|
297
|
+
class="mt-1"
|
|
298
|
+
@move="move(key, $event)"
|
|
299
|
+
@clone="clone(key)"
|
|
300
|
+
@remove="requestRemove(key, index)"
|
|
301
|
+
>
|
|
302
|
+
<XqNode
|
|
303
|
+
v-for="action in itemActions(key)"
|
|
304
|
+
:key="action.key"
|
|
305
|
+
:node="action"
|
|
306
|
+
/>
|
|
307
|
+
</XqRepeaterRowActions>
|
|
308
|
+
</template>
|
|
309
|
+
<template v-else>
|
|
310
|
+
<div
|
|
311
|
+
:class="
|
|
312
|
+
cn(
|
|
313
|
+
'gap-2 px-3 py-1.5 flex items-center justify-between',
|
|
314
|
+
!isCollapsed(key) && 'border-b border-xq-border',
|
|
315
|
+
)
|
|
316
|
+
"
|
|
317
|
+
>
|
|
318
|
+
<div class="gap-1.5 min-w-0 flex items-center">
|
|
319
|
+
<span
|
|
320
|
+
v-if="canDrag"
|
|
321
|
+
aria-hidden="true"
|
|
322
|
+
class="cursor-grab touch-none text-xq-muted-foreground"
|
|
323
|
+
:data-xq-drag="path"
|
|
324
|
+
>
|
|
325
|
+
<GripVertical class="size-4" />
|
|
326
|
+
</span>
|
|
327
|
+
<span class="text-sm font-medium truncate text-xq-muted-foreground">
|
|
328
|
+
{{ titleOf(index) }}
|
|
329
|
+
</span>
|
|
330
|
+
</div>
|
|
331
|
+
<XqRepeaterRowActions
|
|
332
|
+
v-bind="actions(index)"
|
|
333
|
+
:collapsible="options.collapsible"
|
|
334
|
+
:collapsed="isCollapsed(key)"
|
|
335
|
+
@move="move(key, $event)"
|
|
336
|
+
@clone="clone(key)"
|
|
337
|
+
@remove="requestRemove(key, index)"
|
|
338
|
+
@toggle="toggle(key)"
|
|
123
339
|
>
|
|
124
|
-
<
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
@click="remove(key, index)"
|
|
340
|
+
<XqNode
|
|
341
|
+
v-for="action in itemActions(key)"
|
|
342
|
+
:key="action.key"
|
|
343
|
+
:node="action"
|
|
344
|
+
/>
|
|
345
|
+
</XqRepeaterRowActions>
|
|
346
|
+
</div>
|
|
347
|
+
<div
|
|
348
|
+
v-show="!isCollapsed(key)"
|
|
349
|
+
class="xq-grid p-3"
|
|
350
|
+
:style="gridStyle(options.columns)"
|
|
136
351
|
>
|
|
137
|
-
<
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
352
|
+
<XqNode
|
|
353
|
+
v-for="child in rows[key] ?? []"
|
|
354
|
+
:key="child.key"
|
|
355
|
+
:node="child"
|
|
356
|
+
/>
|
|
357
|
+
</div>
|
|
358
|
+
</template>
|
|
143
359
|
</div>
|
|
144
360
|
</div>
|
|
145
361
|
<div
|
|
146
362
|
v-if="keys.length === 0"
|
|
147
363
|
class="px-4 py-6 text-sm rounded-xq-lg border border-dashed border-xq-border text-center text-xq-muted-foreground"
|
|
148
364
|
>
|
|
149
|
-
|
|
365
|
+
{{
|
|
366
|
+
t('No :items yet.', {
|
|
367
|
+
items: `${String(options.itemLabel ?? 'item').toLowerCase()}s`,
|
|
368
|
+
})
|
|
369
|
+
}}
|
|
150
370
|
</div>
|
|
151
|
-
<div>
|
|
371
|
+
<div v-if="options.addable !== false">
|
|
372
|
+
<XqBlockPicker
|
|
373
|
+
v-if="blocks"
|
|
374
|
+
:blocks="blocks"
|
|
375
|
+
:label="options.addLabel"
|
|
376
|
+
:disabled="!canAdd"
|
|
377
|
+
:used="usedBlocks"
|
|
378
|
+
@pick="add"
|
|
379
|
+
/>
|
|
152
380
|
<XqButton
|
|
381
|
+
v-else
|
|
153
382
|
type="button"
|
|
154
383
|
variant="outline"
|
|
155
384
|
size="sm"
|
|
156
385
|
:disabled="!canAdd"
|
|
157
386
|
data-xq-add
|
|
158
|
-
@click="add"
|
|
387
|
+
@click="add()"
|
|
159
388
|
>
|
|
160
389
|
<Plus />
|
|
161
390
|
{{ options.addLabel }}
|
|
162
391
|
</XqButton>
|
|
163
392
|
</div>
|
|
164
393
|
</div>
|
|
394
|
+
<XqConfirmDialog
|
|
395
|
+
v-model:open="isConfirming"
|
|
396
|
+
:title="t('Remove :item', { item: String(options.itemLabel).toLowerCase() })"
|
|
397
|
+
:message="options.deleteConfirmation ?? ''"
|
|
398
|
+
@confirm="confirmRemove"
|
|
399
|
+
/>
|
|
165
400
|
</XqFieldWrapper>
|
|
166
401
|
</template>
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ArrowDown, ArrowUp, ChevronDown, Copy, Trash2 } from 'lucide-vue-next';
|
|
3
|
+
import { cn } from '../../lib/utils';
|
|
4
|
+
import XqButton from '../../ui/XqButton.vue';
|
|
5
|
+
import { useTranslator } from '../../composables/context';
|
|
6
|
+
|
|
7
|
+
const t = useTranslator();
|
|
8
|
+
defineProps<{
|
|
9
|
+
label: string;
|
|
10
|
+
index: number;
|
|
11
|
+
count: number;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
orderable?: boolean;
|
|
14
|
+
canClone?: boolean;
|
|
15
|
+
showClone?: boolean;
|
|
16
|
+
canRemove?: boolean;
|
|
17
|
+
showRemove?: boolean;
|
|
18
|
+
collapsible?: boolean;
|
|
19
|
+
collapsed?: boolean;
|
|
20
|
+
}>();
|
|
21
|
+
defineEmits<{ move: [direction: -1 | 1]; clone: []; remove: []; toggle: [] }>();
|
|
22
|
+
</script>
|
|
23
|
+
|
|
24
|
+
<template>
|
|
25
|
+
<div class="gap-0.5 flex items-center">
|
|
26
|
+
<slot />
|
|
27
|
+
<template v-if="orderable && count > 1">
|
|
28
|
+
<XqButton
|
|
29
|
+
type="button"
|
|
30
|
+
variant="ghost"
|
|
31
|
+
size="icon-sm"
|
|
32
|
+
:disabled="disabled || index === 0"
|
|
33
|
+
:aria-label="t('Move :label :number up', { label, number: index + 1 })"
|
|
34
|
+
data-xq-move="-1"
|
|
35
|
+
@click="$emit('move', -1)"
|
|
36
|
+
>
|
|
37
|
+
<ArrowUp />
|
|
38
|
+
</XqButton>
|
|
39
|
+
<XqButton
|
|
40
|
+
type="button"
|
|
41
|
+
variant="ghost"
|
|
42
|
+
size="icon-sm"
|
|
43
|
+
:disabled="disabled || index === count - 1"
|
|
44
|
+
:aria-label="t('Move :label :number down', { label, number: index + 1 })"
|
|
45
|
+
data-xq-move="1"
|
|
46
|
+
@click="$emit('move', 1)"
|
|
47
|
+
>
|
|
48
|
+
<ArrowDown />
|
|
49
|
+
</XqButton>
|
|
50
|
+
</template>
|
|
51
|
+
<XqButton
|
|
52
|
+
v-if="showClone"
|
|
53
|
+
type="button"
|
|
54
|
+
variant="ghost"
|
|
55
|
+
size="icon-sm"
|
|
56
|
+
:disabled="!canClone"
|
|
57
|
+
:aria-label="t('Copy :label :number', { label, number: index + 1 })"
|
|
58
|
+
data-xq-clone
|
|
59
|
+
@click="$emit('clone')"
|
|
60
|
+
>
|
|
61
|
+
<Copy />
|
|
62
|
+
</XqButton>
|
|
63
|
+
<XqButton
|
|
64
|
+
v-if="showRemove"
|
|
65
|
+
type="button"
|
|
66
|
+
variant="ghost"
|
|
67
|
+
size="icon-sm"
|
|
68
|
+
class="text-xq-muted-foreground hover:text-xq-destructive"
|
|
69
|
+
:disabled="!canRemove"
|
|
70
|
+
:aria-label="t('Remove :label :number', { label, number: index + 1 })"
|
|
71
|
+
data-xq-remove
|
|
72
|
+
@click="$emit('remove')"
|
|
73
|
+
>
|
|
74
|
+
<Trash2 />
|
|
75
|
+
</XqButton>
|
|
76
|
+
<XqButton
|
|
77
|
+
v-if="collapsible"
|
|
78
|
+
type="button"
|
|
79
|
+
variant="ghost"
|
|
80
|
+
size="icon-sm"
|
|
81
|
+
:aria-expanded="!collapsed"
|
|
82
|
+
:aria-label="
|
|
83
|
+
t(collapsed ? 'Expand :label :number' : 'Collapse :label :number', {
|
|
84
|
+
label,
|
|
85
|
+
number: index + 1,
|
|
86
|
+
})
|
|
87
|
+
"
|
|
88
|
+
data-xq-collapse
|
|
89
|
+
@click="$emit('toggle')"
|
|
90
|
+
>
|
|
91
|
+
<ChevronDown
|
|
92
|
+
:class="
|
|
93
|
+
cn(
|
|
94
|
+
'transition-transform motion-reduce:transition-none',
|
|
95
|
+
collapsed && '-rotate-90',
|
|
96
|
+
)
|
|
97
|
+
"
|
|
98
|
+
/>
|
|
99
|
+
</XqButton>
|
|
100
|
+
</div>
|
|
101
|
+
</template>
|