@mapomodule/form 2.0.0-beta.8 → 2.0.0-experimental.1
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 +38 -119
- package/dist/index.d.mts +2 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +1 -0
- package/dist/module.d.mts +1 -0
- package/dist/module.d.ts.map +1 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +9 -0
- package/dist/runtime/components/MapoFocusPortal.vue +9 -2
- package/dist/runtime/components/MapoFocusPortal.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoForm.vue +28 -6
- package/dist/runtime/components/MapoForm.vue.d.ts +13 -1
- package/dist/runtime/components/MapoForm.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoFormAnnotation.vue +79 -0
- package/dist/runtime/components/MapoFormAnnotation.vue.d.ts +27 -0
- package/dist/runtime/components/MapoFormAnnotation.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoFormAnnotationBadges.vue +28 -0
- package/dist/runtime/components/MapoFormAnnotationBadges.vue.d.ts +13 -0
- package/dist/runtime/components/MapoFormAnnotationBadges.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoFormField.vue +47 -11
- package/dist/runtime/components/MapoFormField.vue.d.ts +15 -9
- package/dist/runtime/components/MapoFormField.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoFormGroup.vue +18 -2
- package/dist/runtime/components/MapoFormGroup.vue.d.ts.map +1 -1
- package/dist/runtime/components/MapoFormTabs.vue +50 -8
- package/dist/runtime/components/MapoFormTabs.vue.d.ts.map +1 -1
- package/dist/runtime/components/fields/MapoMediaField.vue +5 -3
- package/dist/runtime/components/fields/MapoMediaField.vue.d.ts.map +1 -1
- package/dist/runtime/components/fields/MapoMediaM2mField.vue +3 -2
- package/dist/runtime/components/fields/MapoMediaM2mField.vue.d.ts.map +1 -1
- package/dist/runtime/components/fields/MapoRepeater.vue +73 -14
- package/dist/runtime/components/fields/MapoRepeater.vue.d.ts.map +1 -1
- package/dist/runtime/components/fields/MapoRepeaterBlockPicker.vue +167 -0
- package/dist/runtime/components/fields/MapoRepeaterBlockPicker.vue.d.ts +20 -0
- package/dist/runtime/components/fields/MapoRepeaterBlockPicker.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoRepeaterItem.vue +46 -10
- package/dist/runtime/components/fields/MapoRepeaterItem.vue.d.ts +6 -2
- package/dist/runtime/components/fields/MapoRepeaterItem.vue.d.ts.map +1 -1
- package/dist/runtime/components/fields/MapoWygEditor.vue +19 -13
- package/dist/runtime/components/fields/MapoWygEditor.vue.d.ts.map +1 -1
- package/dist/runtime/composables/useFieldAnnotation.d.ts +18 -0
- package/dist/runtime/composables/useFieldAnnotation.d.ts.map +1 -0
- package/dist/runtime/composables/useFieldAnnotation.js +16 -0
- package/dist/runtime/composables/useFocusMode.d.ts +3 -1
- package/dist/runtime/composables/useFocusMode.d.ts.map +1 -1
- package/dist/runtime/composables/useFormFromSchema.d.ts +23 -1
- package/dist/runtime/composables/useFormFromSchema.d.ts.map +1 -1
- package/dist/runtime/composables/useFormFromSchema.js +173 -32
- package/dist/runtime/composables/useMapoForm.d.ts +21 -3
- package/dist/runtime/composables/useMapoForm.d.ts.map +1 -1
- package/dist/runtime/composables/useMapoForm.js +49 -15
- package/dist/runtime/types/annotation.d.ts +43 -0
- package/dist/runtime/types/annotation.d.ts.map +1 -0
- package/dist/runtime/types/annotation.js +0 -0
- package/dist/runtime/types/descriptor.d.ts +81 -4
- package/dist/runtime/types/descriptor.d.ts.map +1 -1
- package/dist/runtime/types/index.d.ts +2 -1
- package/dist/runtime/types/index.d.ts.map +1 -1
- package/dist/runtime/utils/annotations.d.ts +40 -0
- package/dist/runtime/utils/annotations.d.ts.map +1 -0
- package/dist/runtime/utils/annotations.js +78 -0
- package/dist/runtime/utils/draft.d.ts +21 -0
- package/dist/runtime/utils/draft.d.ts.map +1 -0
- package/dist/runtime/utils/draft.js +108 -0
- package/dist/runtime/utils/fieldComponent.d.ts +9 -0
- package/dist/runtime/utils/fieldComponent.d.ts.map +1 -0
- package/dist/runtime/utils/fieldComponent.js +12 -0
- package/dist/runtime/utils/fieldFocus.d.ts +24 -0
- package/dist/runtime/utils/fieldFocus.d.ts.map +1 -0
- package/dist/runtime/utils/fieldFocus.js +41 -0
- package/dist/runtime/utils/fieldsToJsonSchema.d.ts +38 -0
- package/dist/runtime/utils/fieldsToJsonSchema.d.ts.map +1 -0
- package/dist/runtime/utils/fieldsToJsonSchema.js +248 -0
- package/dist/runtime/utils/repeaterTemplates.d.ts +26 -0
- package/dist/runtime/utils/repeaterTemplates.d.ts.map +1 -0
- package/dist/runtime/utils/repeaterTemplates.js +51 -0
- package/dist/runtime/utils/reveal.d.ts +34 -0
- package/dist/runtime/utils/reveal.d.ts.map +1 -0
- package/dist/runtime/utils/reveal.js +29 -0
- package/dist/runtime/utils/tabVisibility.d.ts +18 -0
- package/dist/runtime/utils/tabVisibility.d.ts.map +1 -0
- package/dist/runtime/utils/tabVisibility.js +18 -0
- package/package.json +5 -5
- package/src/__tests__/MapoFocusPortal.component.test.ts +97 -0
- package/src/__tests__/MapoForm.component.test.ts +79 -0
- package/src/__tests__/MapoFormAnnotation.component.test.ts +244 -0
- package/src/__tests__/MapoFormField.component.test.ts +508 -0
- package/src/__tests__/MapoFormGroup.component.test.ts +141 -0
- package/src/__tests__/MapoFormTabs.component.test.ts +254 -0
- package/src/__tests__/MapoRepeaterItem.component.test.ts +286 -0
- package/src/__tests__/MapoWygEditor.component.test.ts +95 -0
- package/src/__tests__/annotations.test.ts +227 -0
- package/src/__tests__/article.schema.json +193 -0
- package/src/__tests__/camomillaRoundTrip.test.ts +73 -0
- package/src/__tests__/draft.test.ts +221 -0
- package/src/__tests__/fieldComponent.test.ts +31 -0
- package/src/__tests__/fieldExtensions.test.ts +63 -0
- package/src/__tests__/fieldFocus.test.ts +178 -0
- package/src/__tests__/fieldsToJsonSchema.test.ts +630 -0
- package/src/__tests__/headlessRenderer.ts +85 -0
- package/src/__tests__/repeaterTemplates.test.ts +154 -0
- package/src/__tests__/reveal.test.ts +89 -0
- package/src/__tests__/schemaSources.test.ts +132 -0
- package/src/__tests__/tabVisibility.test.ts +102 -0
- package/src/__tests__/useFormFromSchema.test.ts +387 -0
- package/src/__tests__/useMapoForm.test.ts +213 -2
- package/src/index.ts +9 -0
- package/src/module.ts +9 -0
- package/src/runtime/components/MapoFocusPortal.vue +15 -2
- package/src/runtime/components/MapoForm.vue +47 -4
- package/src/runtime/components/MapoFormAnnotation.vue +113 -0
- package/src/runtime/components/MapoFormAnnotationBadges.vue +41 -0
- package/src/runtime/components/MapoFormField.vue +72 -11
- package/src/runtime/components/MapoFormGroup.vue +20 -2
- package/src/runtime/components/MapoFormTabs.vue +64 -8
- package/src/runtime/components/fields/MapoMediaField.vue +5 -3
- package/src/runtime/components/fields/MapoMediaM2mField.vue +3 -2
- package/src/runtime/components/fields/MapoRepeater.vue +82 -14
- package/src/runtime/components/fields/MapoRepeaterBlockPicker.vue +188 -0
- package/src/runtime/components/fields/MapoRepeaterItem.vue +56 -8
- package/src/runtime/components/fields/MapoWygEditor.vue +22 -14
- package/src/runtime/composables/useFieldAnnotation.ts +38 -0
- package/src/runtime/composables/useFocusMode.ts +7 -1
- package/src/runtime/composables/useFormFromSchema.ts +306 -42
- package/src/runtime/composables/useMapoForm.ts +103 -23
- package/src/runtime/types/annotation.ts +53 -0
- package/src/runtime/types/descriptor.ts +94 -4
- package/src/runtime/types/index.ts +10 -0
- package/src/runtime/utils/annotations.ts +169 -0
- package/src/runtime/utils/draft.ts +158 -0
- package/src/runtime/utils/fieldComponent.ts +34 -0
- package/src/runtime/utils/fieldFocus.ts +73 -0
- package/src/runtime/utils/fieldsToJsonSchema.ts +405 -0
- package/src/runtime/utils/repeaterTemplates.ts +103 -0
- package/src/runtime/utils/reveal.ts +68 -0
- package/src/runtime/utils/tabVisibility.ts +44 -0
- package/dist/__tests__/__mocks__/nuxt-imports.d.ts +0 -4
- package/dist/__tests__/__mocks__/nuxt-imports.d.ts.map +0 -1
- package/dist/__tests__/registry.test.d.ts +0 -2
- package/dist/__tests__/registry.test.d.ts.map +0 -1
- package/dist/__tests__/useFormFromSchema.test.d.ts +0 -2
- package/dist/__tests__/useFormFromSchema.test.d.ts.map +0 -1
- package/dist/__tests__/useMapoForm.test.d.ts +0 -2
- package/dist/__tests__/useMapoForm.test.d.ts.map +0 -1
|
@@ -4,8 +4,15 @@ import { useI18n } from "vue-i18n";
|
|
|
4
4
|
import { VueDraggable } from "vue-draggable-plus";
|
|
5
5
|
import { useConfirmStore } from "@mapomodule/store/runtime/stores/confirm";
|
|
6
6
|
import type { RepeaterDescriptor } from "../../types/index.js";
|
|
7
|
+
import {
|
|
8
|
+
normalizeTemplates,
|
|
9
|
+
reachesMax,
|
|
10
|
+
repeaterItemFields,
|
|
11
|
+
shouldUseModalPicker,
|
|
12
|
+
} from "../../utils/repeaterTemplates.js";
|
|
7
13
|
import { injectMapoForm } from "../../composables/useMapoForm.js";
|
|
8
14
|
import MapoRepeaterItem from "./MapoRepeaterItem.vue";
|
|
15
|
+
import MapoRepeaterBlockPicker from "./MapoRepeaterBlockPicker.vue";
|
|
9
16
|
|
|
10
17
|
const props = defineProps<{
|
|
11
18
|
modelValue: unknown;
|
|
@@ -67,12 +74,42 @@ function undo() {
|
|
|
67
74
|
// ─── Template selection ──────────────────────────────────────────────────────
|
|
68
75
|
|
|
69
76
|
const templates = computed(() => attrs.value.templates);
|
|
70
|
-
|
|
71
|
-
|
|
77
|
+
|
|
78
|
+
// Bare field arrays and RepeaterTemplate objects are both accepted.
|
|
79
|
+
const templateList = computed(() =>
|
|
80
|
+
normalizeTemplates(templates.value, attrs.value.templateImageFit),
|
|
81
|
+
);
|
|
82
|
+
const templateByKey = computed(
|
|
83
|
+
() => new Map(templateList.value.map((tpl) => [tpl.key, tpl])),
|
|
72
84
|
);
|
|
85
|
+
const templateKeys = computed(() => templateList.value.map((tpl) => tpl.key));
|
|
73
86
|
const hasTemplates = computed(() => templateKeys.value.length > 0);
|
|
74
87
|
const selectedTemplate = ref<string>("");
|
|
75
88
|
|
|
89
|
+
const useModalPicker = computed(() =>
|
|
90
|
+
shouldUseModalPicker(attrs.value.picker, templateKeys.value.length),
|
|
91
|
+
);
|
|
92
|
+
const pickerOpen = ref(false);
|
|
93
|
+
|
|
94
|
+
const selectItems = computed(() =>
|
|
95
|
+
templateList.value.map((tpl) => ({
|
|
96
|
+
label: tpl.label,
|
|
97
|
+
value: tpl.key,
|
|
98
|
+
description: tpl.description,
|
|
99
|
+
icon: tpl.icon,
|
|
100
|
+
})),
|
|
101
|
+
);
|
|
102
|
+
|
|
103
|
+
function templateLabelFor(item: Record<string, unknown>): string | undefined {
|
|
104
|
+
const key = item._template as string | undefined;
|
|
105
|
+
if (!key) return undefined;
|
|
106
|
+
return templateByKey.value.get(key)?.label ?? key;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function templateIconFor(item: Record<string, unknown>): string | undefined {
|
|
110
|
+
return templateByKey.value.get(item._template as string)?.icon;
|
|
111
|
+
}
|
|
112
|
+
|
|
76
113
|
// Async-safe: when templates load after mount, auto-pick the first one.
|
|
77
114
|
watchEffect(() => {
|
|
78
115
|
if (!selectedTemplate.value && templateKeys.value[0]) {
|
|
@@ -81,9 +118,12 @@ watchEffect(() => {
|
|
|
81
118
|
});
|
|
82
119
|
|
|
83
120
|
function fieldsForItem(item: Record<string, unknown>) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
121
|
+
return repeaterItemFields(
|
|
122
|
+
props.descriptor,
|
|
123
|
+
templateList.value,
|
|
124
|
+
item,
|
|
125
|
+
selectedTemplate.value,
|
|
126
|
+
);
|
|
87
127
|
}
|
|
88
128
|
|
|
89
129
|
// ─── Item CRUD ───────────────────────────────────────────────────────────────
|
|
@@ -122,15 +162,28 @@ async function askConfirm(message: string, title?: string): Promise<boolean> {
|
|
|
122
162
|
}
|
|
123
163
|
}
|
|
124
164
|
|
|
125
|
-
function addItem() {
|
|
165
|
+
function addItem(templateKey?: string) {
|
|
126
166
|
if (!canAdd.value) return;
|
|
127
167
|
pushUndo();
|
|
128
168
|
const newItem: Record<string, unknown> = hasTemplates.value
|
|
129
|
-
? { _template: selectedTemplate.value }
|
|
169
|
+
? { _template: templateKey ?? selectedTemplate.value }
|
|
130
170
|
: {};
|
|
131
171
|
emitItems([...items.value, newItem]);
|
|
132
172
|
}
|
|
133
173
|
|
|
174
|
+
function onAddClick() {
|
|
175
|
+
if (useModalPicker.value) pickerOpen.value = true;
|
|
176
|
+
else addItem();
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
function onPickTemplate(key: string, keepOpen: boolean) {
|
|
180
|
+
// `items` still holds the pre-add array here, so count the new item explicitly.
|
|
181
|
+
const full = reachesMax(items.value.length, attrs.value.maxItems);
|
|
182
|
+
selectedTemplate.value = key;
|
|
183
|
+
addItem(key);
|
|
184
|
+
if (!keepOpen || full) pickerOpen.value = false;
|
|
185
|
+
}
|
|
186
|
+
|
|
134
187
|
async function deleteItem(index: number) {
|
|
135
188
|
if (!canDelete.value) return;
|
|
136
189
|
if (attrs.value.confirmDelete !== false) {
|
|
@@ -372,27 +425,38 @@ const errorPrefix = (index: number) =>
|
|
|
372
425
|
@click="toggleSelectionMode"
|
|
373
426
|
/>
|
|
374
427
|
|
|
375
|
-
<!-- Template selector -->
|
|
428
|
+
<!-- Template selector (dropdown mode; the modal picker opens from "Add") -->
|
|
376
429
|
<USelectMenu
|
|
377
|
-
v-if="hasTemplates"
|
|
430
|
+
v-if="hasTemplates && !useModalPicker"
|
|
378
431
|
v-model="selectedTemplate"
|
|
379
|
-
:items="
|
|
432
|
+
:items="selectItems"
|
|
433
|
+
value-key="value"
|
|
434
|
+
:search-input="templateKeys.length > 6"
|
|
435
|
+
:aria-label="t('mapo.repeater.blockType')"
|
|
380
436
|
size="xs"
|
|
381
|
-
class="w-
|
|
437
|
+
class="w-48"
|
|
382
438
|
/>
|
|
383
439
|
|
|
384
440
|
<UButton
|
|
385
441
|
size="sm"
|
|
386
442
|
color="primary"
|
|
387
|
-
icon="i-lucide-plus"
|
|
443
|
+
:icon="useModalPicker ? 'i-lucide-layout-grid' : 'i-lucide-plus'"
|
|
388
444
|
:disabled="!canAdd"
|
|
389
|
-
@click="
|
|
445
|
+
@click="onAddClick"
|
|
390
446
|
>
|
|
391
|
-
{{ t("mapo.add") }}
|
|
447
|
+
{{ useModalPicker ? t("mapo.repeater.addBlock") : t("mapo.add") }}
|
|
392
448
|
</UButton>
|
|
393
449
|
</div>
|
|
394
450
|
</div>
|
|
395
451
|
|
|
452
|
+
<MapoRepeaterBlockPicker
|
|
453
|
+
v-if="useModalPicker"
|
|
454
|
+
v-model:open="pickerOpen"
|
|
455
|
+
:templates="templateList"
|
|
456
|
+
:disabled="!canAdd"
|
|
457
|
+
@select="onPickTemplate"
|
|
458
|
+
/>
|
|
459
|
+
|
|
396
460
|
<!-- ── Bulk actions bar (visible when there is a selection) ───────────── -->
|
|
397
461
|
<Transition name="slide-down">
|
|
398
462
|
<div
|
|
@@ -469,6 +533,8 @@ const errorPrefix = (index: number) =>
|
|
|
469
533
|
<MapoRepeaterItem
|
|
470
534
|
v-for="(item, index) in items"
|
|
471
535
|
:key="`${uidFor(item)}-${collapseVersion}`"
|
|
536
|
+
:template-label="templateLabelFor(item)"
|
|
537
|
+
:template-icon="templateIconFor(item)"
|
|
472
538
|
:uid="uidFor(item)"
|
|
473
539
|
:item="item"
|
|
474
540
|
:fields="fieldsForItem(item)"
|
|
@@ -501,6 +567,8 @@ const errorPrefix = (index: number) =>
|
|
|
501
567
|
<MapoRepeaterItem
|
|
502
568
|
v-for="(item, index) in items"
|
|
503
569
|
:key="`${uidFor(item)}-${collapseVersion}`"
|
|
570
|
+
:template-label="templateLabelFor(item)"
|
|
571
|
+
:template-icon="templateIconFor(item)"
|
|
504
572
|
:uid="uidFor(item)"
|
|
505
573
|
:item="item"
|
|
506
574
|
:fields="fieldsForItem(item)"
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { ref, computed, watch } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
import type {
|
|
5
|
+
NormalizedRepeaterTemplate,
|
|
6
|
+
RepeaterImageFit,
|
|
7
|
+
} from "../../types/descriptor.js";
|
|
8
|
+
import {
|
|
9
|
+
filterTemplates,
|
|
10
|
+
wireframeShapes,
|
|
11
|
+
} from "../../utils/repeaterTemplates.js";
|
|
12
|
+
|
|
13
|
+
const props = defineProps<{
|
|
14
|
+
templates: NormalizedRepeaterTemplate[];
|
|
15
|
+
/** Disables the cards (e.g. `maxItems` reached). */
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
}>();
|
|
18
|
+
|
|
19
|
+
const open = defineModel<boolean>("open", { default: false });
|
|
20
|
+
|
|
21
|
+
const emit = defineEmits<{
|
|
22
|
+
/** `keepOpen` is true when Shift was held, so the caller can add several blocks. */
|
|
23
|
+
select: [key: string, keepOpen: boolean];
|
|
24
|
+
}>();
|
|
25
|
+
|
|
26
|
+
const { t } = useI18n();
|
|
27
|
+
|
|
28
|
+
const query = ref("");
|
|
29
|
+
const category = ref("");
|
|
30
|
+
|
|
31
|
+
watch(open, (isOpen) => {
|
|
32
|
+
if (isOpen) {
|
|
33
|
+
query.value = "";
|
|
34
|
+
category.value = "";
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
const categories = computed(
|
|
39
|
+
() =>
|
|
40
|
+
[
|
|
41
|
+
...new Set(props.templates.map((tpl) => tpl.category).filter(Boolean)),
|
|
42
|
+
] as string[],
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
const filtered = computed(() =>
|
|
46
|
+
filterTemplates(props.templates, query.value, category.value),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
// Whole class names, so Tailwind finds them when it scans this file. An unknown
|
|
50
|
+
// value from untyped app code falls back to `contain`.
|
|
51
|
+
const IMAGE_FIT_CLASS: Record<RepeaterImageFit, string> = {
|
|
52
|
+
contain: "object-contain",
|
|
53
|
+
cover: "object-cover",
|
|
54
|
+
fill: "object-fill",
|
|
55
|
+
none: "object-none",
|
|
56
|
+
"scale-down": "object-scale-down",
|
|
57
|
+
};
|
|
58
|
+
function imageFitClass(fit: RepeaterImageFit): string {
|
|
59
|
+
return IMAGE_FIT_CLASS[fit] ?? IMAGE_FIT_CLASS.contain;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const shapesFor = wireframeShapes;
|
|
63
|
+
function pick(key: string, event: MouseEvent) {
|
|
64
|
+
if (props.disabled) return;
|
|
65
|
+
emit("select", key, event.shiftKey);
|
|
66
|
+
}
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<UModal v-model:open="open" :title="t('mapo.repeater.chooseBlock')">
|
|
71
|
+
<template #body>
|
|
72
|
+
<div class="space-y-4">
|
|
73
|
+
<UInput
|
|
74
|
+
v-model="query"
|
|
75
|
+
icon="i-lucide-search"
|
|
76
|
+
:placeholder="t('mapo.repeater.searchBlocks')"
|
|
77
|
+
class="w-full"
|
|
78
|
+
autofocus
|
|
79
|
+
/>
|
|
80
|
+
|
|
81
|
+
<div v-if="categories.length" class="flex flex-wrap gap-1.5">
|
|
82
|
+
<UButton
|
|
83
|
+
size="xs"
|
|
84
|
+
:variant="category === '' ? 'solid' : 'outline'"
|
|
85
|
+
color="neutral"
|
|
86
|
+
:label="t('mapo.repeater.allCategories')"
|
|
87
|
+
@click="category = ''"
|
|
88
|
+
/>
|
|
89
|
+
<UButton
|
|
90
|
+
v-for="cat in categories"
|
|
91
|
+
:key="cat"
|
|
92
|
+
size="xs"
|
|
93
|
+
:variant="category === cat ? 'solid' : 'outline'"
|
|
94
|
+
color="neutral"
|
|
95
|
+
:label="cat"
|
|
96
|
+
@click="category = cat"
|
|
97
|
+
/>
|
|
98
|
+
</div>
|
|
99
|
+
|
|
100
|
+
<div
|
|
101
|
+
v-if="filtered.length"
|
|
102
|
+
class="grid grid-cols-1 gap-3 sm:grid-cols-2"
|
|
103
|
+
>
|
|
104
|
+
<button
|
|
105
|
+
v-for="tpl in filtered"
|
|
106
|
+
:key="tpl.key"
|
|
107
|
+
type="button"
|
|
108
|
+
class="group flex flex-col overflow-hidden rounded-lg border border-default text-left transition hover:border-primary hover:shadow focus-visible:outline-2 focus-visible:outline-primary disabled:cursor-not-allowed disabled:opacity-50"
|
|
109
|
+
:disabled="disabled"
|
|
110
|
+
:data-template="tpl.key"
|
|
111
|
+
@click="pick(tpl.key, $event)"
|
|
112
|
+
>
|
|
113
|
+
<!-- Preview: image > wireframe > icon -->
|
|
114
|
+
<div
|
|
115
|
+
class="flex h-28 w-full items-center justify-center bg-elevated"
|
|
116
|
+
>
|
|
117
|
+
<img
|
|
118
|
+
v-if="tpl.image"
|
|
119
|
+
:src="tpl.image"
|
|
120
|
+
alt=""
|
|
121
|
+
class="h-full w-full"
|
|
122
|
+
:class="imageFitClass(tpl.imageFit)"
|
|
123
|
+
/>
|
|
124
|
+
<div
|
|
125
|
+
v-else-if="tpl.wireframe"
|
|
126
|
+
class="flex w-3/4 flex-col gap-1.5"
|
|
127
|
+
aria-hidden="true"
|
|
128
|
+
>
|
|
129
|
+
<template v-for="(shape, i) in shapesFor(tpl.fields)" :key="i">
|
|
130
|
+
<div
|
|
131
|
+
v-if="shape === 'line'"
|
|
132
|
+
class="h-2 w-full rounded bg-accented"
|
|
133
|
+
/>
|
|
134
|
+
<div v-else-if="shape === 'lines'" class="space-y-1">
|
|
135
|
+
<div class="h-1.5 w-full rounded bg-accented" />
|
|
136
|
+
<div class="h-1.5 w-5/6 rounded bg-accented" />
|
|
137
|
+
</div>
|
|
138
|
+
<div
|
|
139
|
+
v-else-if="shape === 'box'"
|
|
140
|
+
class="h-8 w-full rounded bg-accented"
|
|
141
|
+
/>
|
|
142
|
+
<div v-else class="h-2.5 w-2.5 rounded-sm bg-accented" />
|
|
143
|
+
</template>
|
|
144
|
+
</div>
|
|
145
|
+
<UIcon
|
|
146
|
+
v-else
|
|
147
|
+
:name="tpl.icon ?? 'i-lucide-layout-template'"
|
|
148
|
+
class="h-10 w-10 text-dimmed group-hover:text-primary"
|
|
149
|
+
/>
|
|
150
|
+
</div>
|
|
151
|
+
|
|
152
|
+
<div class="space-y-0.5 p-3">
|
|
153
|
+
<div class="flex items-center gap-1.5">
|
|
154
|
+
<UIcon
|
|
155
|
+
v-if="tpl.icon && (tpl.image || tpl.wireframe)"
|
|
156
|
+
:name="tpl.icon"
|
|
157
|
+
class="h-4 w-4 shrink-0 text-muted"
|
|
158
|
+
/>
|
|
159
|
+
<span class="truncate text-sm font-medium text-highlighted">
|
|
160
|
+
{{ tpl.label }}
|
|
161
|
+
</span>
|
|
162
|
+
<UBadge
|
|
163
|
+
v-if="tpl.category"
|
|
164
|
+
size="xs"
|
|
165
|
+
variant="subtle"
|
|
166
|
+
color="neutral"
|
|
167
|
+
class="ml-auto"
|
|
168
|
+
>
|
|
169
|
+
{{ tpl.category }}
|
|
170
|
+
</UBadge>
|
|
171
|
+
</div>
|
|
172
|
+
<p v-if="tpl.description" class="line-clamp-2 text-xs text-muted">
|
|
173
|
+
{{ tpl.description }}
|
|
174
|
+
</p>
|
|
175
|
+
</div>
|
|
176
|
+
</button>
|
|
177
|
+
</div>
|
|
178
|
+
<p v-else class="py-6 text-center text-sm text-dimmed">
|
|
179
|
+
{{ t("mapo.repeater.noBlocksFound") }}
|
|
180
|
+
</p>
|
|
181
|
+
|
|
182
|
+
<p class="text-xs text-dimmed">
|
|
183
|
+
{{ t("mapo.repeater.keepOpenHint") }}
|
|
184
|
+
</p>
|
|
185
|
+
</div>
|
|
186
|
+
</template>
|
|
187
|
+
</UModal>
|
|
188
|
+
</template>
|
|
@@ -3,11 +3,14 @@ import { ref, computed, watch, watchEffect } from "vue";
|
|
|
3
3
|
import { useI18n } from "vue-i18n";
|
|
4
4
|
import type {
|
|
5
5
|
AnyFieldDescriptor,
|
|
6
|
+
FieldAnnotations,
|
|
6
7
|
FieldRegistry,
|
|
7
8
|
RepeaterDescriptor,
|
|
8
9
|
} from "../../types/index.js";
|
|
9
10
|
import { useMapoForm, injectMapoForm } from "../../composables/useMapoForm.js";
|
|
10
11
|
import { useFocusMode } from "../../composables/useFocusMode.js";
|
|
12
|
+
import { annotationGroups, entriesUnder } from "../../utils/annotations.js";
|
|
13
|
+
import MapoFormAnnotationBadges from "../MapoFormAnnotationBadges.vue";
|
|
11
14
|
import MapoFormField from "../MapoFormField.vue";
|
|
12
15
|
|
|
13
16
|
const { t } = useI18n();
|
|
@@ -35,6 +38,10 @@ const props = defineProps<{
|
|
|
35
38
|
selected?: boolean;
|
|
36
39
|
/** true = bulk selection mode is active in the parent repeater. */
|
|
37
40
|
selectionMode?: boolean;
|
|
41
|
+
/** Display name of the item's template (repeaters with `attrs.templates`). */
|
|
42
|
+
templateLabel?: string;
|
|
43
|
+
/** Icon of the item's template. */
|
|
44
|
+
templateIcon?: string;
|
|
38
45
|
}>();
|
|
39
46
|
|
|
40
47
|
const emit = defineEmits<{
|
|
@@ -83,14 +90,9 @@ watch(
|
|
|
83
90
|
);
|
|
84
91
|
|
|
85
92
|
// Filter parent errors down to this item: "blocks.0.title" → "title".
|
|
86
|
-
const itemErrors = computed<Record<string, string[]>>(() =>
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
for (const [k, v] of Object.entries(props.parentErrors)) {
|
|
90
|
-
if (k.startsWith(prefix)) result[k.slice(prefix.length)] = v;
|
|
91
|
-
}
|
|
92
|
-
return result;
|
|
93
|
-
});
|
|
93
|
+
const itemErrors = computed<Record<string, string[]>>(() =>
|
|
94
|
+
entriesUnder(props.parentErrors, props.errorPrefix),
|
|
95
|
+
);
|
|
94
96
|
|
|
95
97
|
const hasErrors = computed(() => Object.keys(itemErrors.value).length > 0);
|
|
96
98
|
|
|
@@ -105,6 +107,11 @@ const readonly = computed(() => props.readonly);
|
|
|
105
107
|
// Capture the parent context BEFORE useMapoForm provides a new one for this subtree.
|
|
106
108
|
const parentCtx = injectMapoForm<Record<string, unknown>>();
|
|
107
109
|
|
|
110
|
+
// The parent's annotations under this item, keyed as the item's fields see them.
|
|
111
|
+
const itemAnnotations = computed<FieldAnnotations>(() =>
|
|
112
|
+
entriesUnder(parentCtx?.annotations?.value ?? {}, props.errorPrefix),
|
|
113
|
+
);
|
|
114
|
+
|
|
108
115
|
// `notifyErrors: false` so each item does not duplicate the root form's error toast.
|
|
109
116
|
const form = useMapoForm<Record<string, unknown>>({
|
|
110
117
|
model: localModel,
|
|
@@ -116,6 +123,7 @@ const form = useMapoForm<Record<string, unknown>>({
|
|
|
116
123
|
debounce: parentCtx?.debounce ?? 300,
|
|
117
124
|
notifyErrors: false,
|
|
118
125
|
registry: props.registry,
|
|
126
|
+
annotations: itemAnnotations,
|
|
119
127
|
});
|
|
120
128
|
|
|
121
129
|
// Inherit readonly + submitted from the root form so its submit() reveals item-level
|
|
@@ -125,6 +133,33 @@ watchEffect(() => {
|
|
|
125
133
|
if (parentCtx) form.ctx.submitted.value = parentCtx.submitted.value;
|
|
126
134
|
});
|
|
127
135
|
|
|
136
|
+
// `revealField()` of the parent form names a field of this item: the item
|
|
137
|
+
// opens, and its own form brings the field into view, as the parent asked
|
|
138
|
+
// it under the item's prefix (`blocks.2.title` → `title`).
|
|
139
|
+
watch(
|
|
140
|
+
() => parentCtx?.reveal?.value,
|
|
141
|
+
(request) => {
|
|
142
|
+
if (!request?.rest) return;
|
|
143
|
+
const start = `${props.errorPrefix}.`;
|
|
144
|
+
const inside = `${request.key}.${request.rest}`;
|
|
145
|
+
if (!inside.startsWith(start)) return;
|
|
146
|
+
expanded.value = true;
|
|
147
|
+
void form.revealField(inside.slice(start.length)).then(request.settle);
|
|
148
|
+
},
|
|
149
|
+
{ immediate: true },
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
// An item starts collapsed: the badges on its header and mini-card tell which
|
|
153
|
+
// item holds marks, as the error badge does for errors.
|
|
154
|
+
const itemAnnotationGroups = computed(() =>
|
|
155
|
+
annotationGroups(
|
|
156
|
+
props.fields,
|
|
157
|
+
itemAnnotations.value,
|
|
158
|
+
localModel.value,
|
|
159
|
+
props.currentLang,
|
|
160
|
+
),
|
|
161
|
+
);
|
|
162
|
+
|
|
128
163
|
// ─── Preview label ────────────────────────────────────────────────────────────
|
|
129
164
|
|
|
130
165
|
const label = computed(
|
|
@@ -169,6 +204,7 @@ function enterFocusMode() {
|
|
|
169
204
|
fields: props.fields,
|
|
170
205
|
model: { ...localModel.value },
|
|
171
206
|
errors: itemErrors,
|
|
207
|
+
annotations: itemAnnotations,
|
|
172
208
|
onUpdate: (val) => {
|
|
173
209
|
localModel.value = { ...val };
|
|
174
210
|
emit("update:item", localModel.value);
|
|
@@ -243,6 +279,7 @@ function enterFocusMode() {
|
|
|
243
279
|
<UBadge v-if="hasErrors" color="error" variant="soft" size="xs">
|
|
244
280
|
errors
|
|
245
281
|
</UBadge>
|
|
282
|
+
<MapoFormAnnotationBadges :groups="itemAnnotationGroups" size="xs" />
|
|
246
283
|
|
|
247
284
|
<!-- Quick actions (delete only in mini mode) -->
|
|
248
285
|
<div class="flex items-center gap-1">
|
|
@@ -291,10 +328,21 @@ function enterFocusMode() {
|
|
|
291
328
|
selectionMode ? toggleSelectFromEvent($event) : (expanded = !expanded)
|
|
292
329
|
"
|
|
293
330
|
>
|
|
331
|
+
<UBadge
|
|
332
|
+
v-if="templateLabel"
|
|
333
|
+
color="neutral"
|
|
334
|
+
variant="subtle"
|
|
335
|
+
size="xs"
|
|
336
|
+
:icon="templateIcon"
|
|
337
|
+
class="shrink-0"
|
|
338
|
+
>
|
|
339
|
+
{{ templateLabel }}
|
|
340
|
+
</UBadge>
|
|
294
341
|
<span class="truncate">{{ label }}</span>
|
|
295
342
|
<UBadge v-if="hasErrors" color="error" variant="soft" size="xs">
|
|
296
343
|
errors
|
|
297
344
|
</UBadge>
|
|
345
|
+
<MapoFormAnnotationBadges :groups="itemAnnotationGroups" size="xs" />
|
|
298
346
|
</button>
|
|
299
347
|
|
|
300
348
|
<!-- Action buttons. All buttons stop propagation so the row-click selection handler
|
|
@@ -97,10 +97,12 @@ const editor = useEditor({
|
|
|
97
97
|
},
|
|
98
98
|
});
|
|
99
99
|
|
|
100
|
-
// Sync readonly prop → editor editable
|
|
100
|
+
// Sync readonly prop → editor editable. Without an update: Tiptap's default
|
|
101
|
+
// would emit the editor's own HTML, and a value only made read-only, as while
|
|
102
|
+
// the record saves, would count as changed by the operator.
|
|
101
103
|
watch(
|
|
102
104
|
() => [props.readonly, props.disabled],
|
|
103
|
-
([ro, dis]) => editor.value?.setEditable(!ro && !dis),
|
|
105
|
+
([ro, dis]) => editor.value?.setEditable(!ro && !dis, false),
|
|
104
106
|
);
|
|
105
107
|
|
|
106
108
|
// Sync modelValue esterno → editor (es. reset dopo save)
|
|
@@ -142,10 +144,13 @@ function onImageConfirm(
|
|
|
142
144
|
</script>
|
|
143
145
|
|
|
144
146
|
<template>
|
|
147
|
+
<!-- An input surface of its own, like the Nuxt UI inputs next to it
|
|
148
|
+
(`bg-default`, `accented` border): without it the text area takes the
|
|
149
|
+
page background and disappears on a tinted page. -->
|
|
145
150
|
<div
|
|
146
|
-
class="mapo-wyg-editor rounded border"
|
|
151
|
+
class="mapo-wyg-editor rounded-md border bg-default"
|
|
147
152
|
:class="[
|
|
148
|
-
errors?.length ? 'border-red-300' : 'border-
|
|
153
|
+
errors?.length ? 'border-red-300' : 'border-accented',
|
|
149
154
|
readonly || disabled ? 'opacity-60' : '',
|
|
150
155
|
]"
|
|
151
156
|
>
|
|
@@ -284,15 +289,18 @@ function onImageConfirm(
|
|
|
284
289
|
>
|
|
285
290
|
{{ err }}
|
|
286
291
|
</p>
|
|
287
|
-
</div>
|
|
288
292
|
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
293
|
+
<!-- Image picker dialog — only rendered when MapoMediaManagerDialog is
|
|
294
|
+
globally available. Inside the root on purpose: a second root would
|
|
295
|
+
drop what MapoFormField passes down (`flex-1`, `id`, `style`), and the
|
|
296
|
+
editor would shrink to its toolbar. As a modal it renders in <body>. -->
|
|
297
|
+
<component
|
|
298
|
+
:is="MediaManagerDialog"
|
|
299
|
+
v-if="hasMediaManager"
|
|
300
|
+
v-model="imagePickerOpen"
|
|
301
|
+
selection-mode="single"
|
|
302
|
+
mime="image/*"
|
|
303
|
+
@confirm="onImageConfirm"
|
|
304
|
+
/>
|
|
305
|
+
</div>
|
|
298
306
|
</template>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { computed, toValue } from "vue";
|
|
2
|
+
import type { ComputedRef, MaybeRefOrGetter } from "vue";
|
|
3
|
+
import type { AnyFieldDescriptor, FieldAnnotation } from "../types/index.js";
|
|
4
|
+
import { annotationFor, valuePath } from "../utils/annotations.js";
|
|
5
|
+
import { injectMapoForm } from "./useMapoForm.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The annotation of a field, the one its mark shows: the entry at the path of
|
|
9
|
+
* its value, then, for a translatable field, the entry at its bare key.
|
|
10
|
+
*
|
|
11
|
+
* Call it in a custom field component, which receives its `descriptor` as a
|
|
12
|
+
* prop, to style the field or show the annotation in it. Inside a repeater item
|
|
13
|
+
* it reads the item's annotations; outside a form it is always `undefined`.
|
|
14
|
+
*
|
|
15
|
+
* @param descriptor The field's descriptor, or a getter of it.
|
|
16
|
+
* @returns A computed annotation, `undefined` when the field has none.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const annotation = useFieldAnnotation(() => props.descriptor);
|
|
20
|
+
*/
|
|
21
|
+
export function useFieldAnnotation(
|
|
22
|
+
// `any` accepts descriptors typed against any model; only `key` and
|
|
23
|
+
// `translatable` are read.
|
|
24
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
25
|
+
descriptor: MaybeRefOrGetter<AnyFieldDescriptor<any>>,
|
|
26
|
+
): ComputedRef<FieldAnnotation | undefined> {
|
|
27
|
+
const form = injectMapoForm<Record<string, unknown>>();
|
|
28
|
+
return computed(() => {
|
|
29
|
+
if (!form) return undefined;
|
|
30
|
+
const field = toValue(descriptor);
|
|
31
|
+
const path = valuePath(field, form.currentLang.value);
|
|
32
|
+
return annotationFor(
|
|
33
|
+
form.annotations?.value ?? {},
|
|
34
|
+
field.key as string,
|
|
35
|
+
path,
|
|
36
|
+
);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
@@ -6,7 +6,11 @@ import {
|
|
|
6
6
|
type DeepReadonly,
|
|
7
7
|
type ShallowRef,
|
|
8
8
|
} from "vue";
|
|
9
|
-
import type {
|
|
9
|
+
import type {
|
|
10
|
+
AnyFieldDescriptor,
|
|
11
|
+
FieldAnnotations,
|
|
12
|
+
FieldRegistry,
|
|
13
|
+
} from "../types/index.js";
|
|
10
14
|
|
|
11
15
|
/** Describes the currently focused repeater item in focus mode. */
|
|
12
16
|
export interface FocusTarget {
|
|
@@ -22,6 +26,8 @@ export interface FocusTarget {
|
|
|
22
26
|
model: Record<string, unknown>;
|
|
23
27
|
/** Errors for this item (already filtered). */
|
|
24
28
|
errors: Ref<Record<string, string[]>>;
|
|
29
|
+
/** Annotations for this item (already filtered), keyed by the item's paths. */
|
|
30
|
+
annotations?: Readonly<Ref<FieldAnnotations>>;
|
|
25
31
|
/** Callback invoked when the item model is updated. */
|
|
26
32
|
onUpdate: (val: Record<string, unknown>) => void;
|
|
27
33
|
/** Field component registry passed to the sub-form. */
|