@mapomodule/form 2.0.0-beta.9 → 2.0.0-experimental.2
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 +171 -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__/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 +303 -41
- 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__/camomillaRoundTrip.test.d.ts +0 -2
- package/dist/__tests__/camomillaRoundTrip.test.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
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref, computed, watch } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
import {
|
|
5
|
+
filterTemplates,
|
|
6
|
+
wireframeShapes
|
|
7
|
+
} from "../../utils/repeaterTemplates.js";
|
|
8
|
+
const props = defineProps({
|
|
9
|
+
templates: { type: Array, required: true },
|
|
10
|
+
disabled: { type: Boolean, required: false }
|
|
11
|
+
});
|
|
12
|
+
const open = defineModel("open", { type: Boolean, ...{ default: false } });
|
|
13
|
+
const emit = defineEmits(["select"]);
|
|
14
|
+
const { t } = useI18n();
|
|
15
|
+
const query = ref("");
|
|
16
|
+
const category = ref("");
|
|
17
|
+
watch(open, (isOpen) => {
|
|
18
|
+
if (isOpen) {
|
|
19
|
+
query.value = "";
|
|
20
|
+
category.value = "";
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
const categories = computed(
|
|
24
|
+
() => [
|
|
25
|
+
...new Set(props.templates.map((tpl) => tpl.category).filter(Boolean))
|
|
26
|
+
]
|
|
27
|
+
);
|
|
28
|
+
const filtered = computed(
|
|
29
|
+
() => filterTemplates(props.templates, query.value, category.value)
|
|
30
|
+
);
|
|
31
|
+
const IMAGE_FIT_CLASS = {
|
|
32
|
+
contain: "object-contain",
|
|
33
|
+
cover: "object-cover",
|
|
34
|
+
fill: "object-fill",
|
|
35
|
+
none: "object-none",
|
|
36
|
+
"scale-down": "object-scale-down"
|
|
37
|
+
};
|
|
38
|
+
function imageFitClass(fit) {
|
|
39
|
+
return IMAGE_FIT_CLASS[fit] ?? IMAGE_FIT_CLASS.contain;
|
|
40
|
+
}
|
|
41
|
+
const shapesFor = wireframeShapes;
|
|
42
|
+
function pick(key, event) {
|
|
43
|
+
if (props.disabled) return;
|
|
44
|
+
emit("select", key, event.shiftKey);
|
|
45
|
+
}
|
|
46
|
+
</script>
|
|
47
|
+
|
|
48
|
+
<template>
|
|
49
|
+
<UModal v-model:open="open" :title="t('mapo.repeater.chooseBlock')">
|
|
50
|
+
<template #body>
|
|
51
|
+
<div class="space-y-4">
|
|
52
|
+
<UInput
|
|
53
|
+
v-model="query"
|
|
54
|
+
icon="i-lucide-search"
|
|
55
|
+
:placeholder="t('mapo.repeater.searchBlocks')"
|
|
56
|
+
class="w-full"
|
|
57
|
+
autofocus
|
|
58
|
+
/>
|
|
59
|
+
|
|
60
|
+
<div v-if="categories.length" class="flex flex-wrap gap-1.5">
|
|
61
|
+
<UButton
|
|
62
|
+
size="xs"
|
|
63
|
+
:variant="category === '' ? 'solid' : 'outline'"
|
|
64
|
+
color="neutral"
|
|
65
|
+
:label="t('mapo.repeater.allCategories')"
|
|
66
|
+
@click="category = ''"
|
|
67
|
+
/>
|
|
68
|
+
<UButton
|
|
69
|
+
v-for="cat in categories"
|
|
70
|
+
:key="cat"
|
|
71
|
+
size="xs"
|
|
72
|
+
:variant="category === cat ? 'solid' : 'outline'"
|
|
73
|
+
color="neutral"
|
|
74
|
+
:label="cat"
|
|
75
|
+
@click="category = cat"
|
|
76
|
+
/>
|
|
77
|
+
</div>
|
|
78
|
+
|
|
79
|
+
<div
|
|
80
|
+
v-if="filtered.length"
|
|
81
|
+
class="grid grid-cols-1 gap-3 sm:grid-cols-2"
|
|
82
|
+
>
|
|
83
|
+
<button
|
|
84
|
+
v-for="tpl in filtered"
|
|
85
|
+
:key="tpl.key"
|
|
86
|
+
type="button"
|
|
87
|
+
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"
|
|
88
|
+
:disabled="disabled"
|
|
89
|
+
:data-template="tpl.key"
|
|
90
|
+
@click="pick(tpl.key, $event)"
|
|
91
|
+
>
|
|
92
|
+
<!-- Preview: image > wireframe > icon -->
|
|
93
|
+
<div
|
|
94
|
+
class="flex h-28 w-full items-center justify-center bg-elevated"
|
|
95
|
+
>
|
|
96
|
+
<img
|
|
97
|
+
v-if="tpl.image"
|
|
98
|
+
:src="tpl.image"
|
|
99
|
+
alt=""
|
|
100
|
+
class="h-full w-full"
|
|
101
|
+
:class="imageFitClass(tpl.imageFit)"
|
|
102
|
+
/>
|
|
103
|
+
<div
|
|
104
|
+
v-else-if="tpl.wireframe"
|
|
105
|
+
class="flex w-3/4 flex-col gap-1.5"
|
|
106
|
+
aria-hidden="true"
|
|
107
|
+
>
|
|
108
|
+
<template v-for="(shape, i) in shapesFor(tpl.fields)" :key="i">
|
|
109
|
+
<div
|
|
110
|
+
v-if="shape === 'line'"
|
|
111
|
+
class="h-2 w-full rounded bg-accented"
|
|
112
|
+
/>
|
|
113
|
+
<div v-else-if="shape === 'lines'" class="space-y-1">
|
|
114
|
+
<div class="h-1.5 w-full rounded bg-accented" />
|
|
115
|
+
<div class="h-1.5 w-5/6 rounded bg-accented" />
|
|
116
|
+
</div>
|
|
117
|
+
<div
|
|
118
|
+
v-else-if="shape === 'box'"
|
|
119
|
+
class="h-8 w-full rounded bg-accented"
|
|
120
|
+
/>
|
|
121
|
+
<div v-else class="h-2.5 w-2.5 rounded-sm bg-accented" />
|
|
122
|
+
</template>
|
|
123
|
+
</div>
|
|
124
|
+
<UIcon
|
|
125
|
+
v-else
|
|
126
|
+
:name="tpl.icon ?? 'i-lucide-layout-template'"
|
|
127
|
+
class="h-10 w-10 text-dimmed group-hover:text-primary"
|
|
128
|
+
/>
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
<div class="space-y-0.5 p-3">
|
|
132
|
+
<div class="flex items-center gap-1.5">
|
|
133
|
+
<UIcon
|
|
134
|
+
v-if="tpl.icon && (tpl.image || tpl.wireframe)"
|
|
135
|
+
:name="tpl.icon"
|
|
136
|
+
class="h-4 w-4 shrink-0 text-muted"
|
|
137
|
+
/>
|
|
138
|
+
<span class="truncate text-sm font-medium text-highlighted">
|
|
139
|
+
{{ tpl.label }}
|
|
140
|
+
</span>
|
|
141
|
+
<UBadge
|
|
142
|
+
v-if="tpl.category"
|
|
143
|
+
size="xs"
|
|
144
|
+
variant="subtle"
|
|
145
|
+
color="neutral"
|
|
146
|
+
class="ml-auto"
|
|
147
|
+
>
|
|
148
|
+
{{ tpl.category }}
|
|
149
|
+
</UBadge>
|
|
150
|
+
</div>
|
|
151
|
+
<p v-if="tpl.description" class="line-clamp-2 text-xs text-muted">
|
|
152
|
+
{{ tpl.description }}
|
|
153
|
+
</p>
|
|
154
|
+
</div>
|
|
155
|
+
</button>
|
|
156
|
+
</div>
|
|
157
|
+
<p v-else class="py-6 text-center text-sm text-dimmed">
|
|
158
|
+
{{ t("mapo.repeater.noBlocksFound") }}
|
|
159
|
+
</p>
|
|
160
|
+
|
|
161
|
+
<p class="text-xs text-dimmed">
|
|
162
|
+
{{ t("mapo.repeater.keepOpenHint") }}
|
|
163
|
+
</p>
|
|
164
|
+
</div>
|
|
165
|
+
</template>
|
|
166
|
+
</UModal>
|
|
167
|
+
</template>
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { NormalizedRepeaterTemplate } from "../../types/descriptor.js";
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
templates: NormalizedRepeaterTemplate[];
|
|
4
|
+
/** Disables the cards (e.g. `maxItems` reached). */
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
};
|
|
7
|
+
type __VLS_ModelProps = {
|
|
8
|
+
"open"?: boolean;
|
|
9
|
+
};
|
|
10
|
+
type __VLS_PublicProps = __VLS_Props & __VLS_ModelProps;
|
|
11
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_PublicProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
12
|
+
select: (key: string, keepOpen: boolean) => any;
|
|
13
|
+
"update:open": (value: boolean) => any;
|
|
14
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_PublicProps> & Readonly<{
|
|
15
|
+
onSelect?: ((key: string, keepOpen: boolean) => any) | undefined;
|
|
16
|
+
"onUpdate:open"?: ((value: boolean) => any) | undefined;
|
|
17
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
18
|
+
declare const _default: typeof __VLS_export;
|
|
19
|
+
export default _default;
|
|
20
|
+
//# sourceMappingURL=MapoRepeaterBlockPicker.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapoRepeaterBlockPicker.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoRepeaterBlockPicker.vue"],"names":[],"mappings":"AAiMA,OAAO,KAAK,EACV,0BAA0B,EAE3B,MAAM,2BAA2B,CAAC;AAMnC,KAAK,WAAW,GAAG;IACjB,SAAS,EAAE,0BAA0B,EAAE,CAAC;IACxC,oDAAoD;IACpD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAyDF,KAAK,gBAAgB,GAAG;IACxB,MAAM,CAAC,EAAE,OAAO,CAAC;CAChB,CAAC;AAKF,KAAK,iBAAiB,GAAG,WAAW,GAAG,gBAAgB,CAAC;AAyXxD,QAAA,MAAM,YAAY;;;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -3,6 +3,8 @@ import { ref, computed, watch, watchEffect } from "vue";
|
|
|
3
3
|
import { useI18n } from "vue-i18n";
|
|
4
4
|
import { useMapoForm, injectMapoForm } from "../../composables/useMapoForm.js";
|
|
5
5
|
import { useFocusMode } from "../../composables/useFocusMode.js";
|
|
6
|
+
import { annotationGroups, entriesUnder } from "../../utils/annotations.js";
|
|
7
|
+
import MapoFormAnnotationBadges from "../MapoFormAnnotationBadges.vue";
|
|
6
8
|
import MapoFormField from "../MapoFormField.vue";
|
|
7
9
|
const { t } = useI18n();
|
|
8
10
|
const props = defineProps({
|
|
@@ -22,7 +24,9 @@ const props = defineProps({
|
|
|
22
24
|
repeaterDescriptor: { type: Object, required: false },
|
|
23
25
|
totalItems: { type: Number, required: false },
|
|
24
26
|
selected: { type: Boolean, required: false },
|
|
25
|
-
selectionMode: { type: Boolean, required: false }
|
|
27
|
+
selectionMode: { type: Boolean, required: false },
|
|
28
|
+
templateLabel: { type: String, required: false },
|
|
29
|
+
templateIcon: { type: String, required: false }
|
|
26
30
|
});
|
|
27
31
|
const emit = defineEmits(["update:item", "delete", "duplicate", "move-up", "move-down", "move-to", "toggle-select"]);
|
|
28
32
|
function toggleSelectFromEvent(e) {
|
|
@@ -44,18 +48,16 @@ watch(
|
|
|
44
48
|
},
|
|
45
49
|
{ deep: true }
|
|
46
50
|
);
|
|
47
|
-
const itemErrors = computed(
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
for (const [k, v] of Object.entries(props.parentErrors)) {
|
|
51
|
-
if (k.startsWith(prefix)) result[k.slice(prefix.length)] = v;
|
|
52
|
-
}
|
|
53
|
-
return result;
|
|
54
|
-
});
|
|
51
|
+
const itemErrors = computed(
|
|
52
|
+
() => entriesUnder(props.parentErrors, props.errorPrefix)
|
|
53
|
+
);
|
|
55
54
|
const hasErrors = computed(() => Object.keys(itemErrors.value).length > 0);
|
|
56
55
|
const currentLangRef = computed(() => props.currentLang);
|
|
57
56
|
const readonly = computed(() => props.readonly);
|
|
58
57
|
const parentCtx = injectMapoForm();
|
|
58
|
+
const itemAnnotations = computed(
|
|
59
|
+
() => entriesUnder(parentCtx?.annotations?.value ?? {}, props.errorPrefix)
|
|
60
|
+
);
|
|
59
61
|
const form = useMapoForm({
|
|
60
62
|
model: localModel,
|
|
61
63
|
fields: computed(() => props.fields),
|
|
@@ -65,12 +67,33 @@ const form = useMapoForm({
|
|
|
65
67
|
immediate: parentCtx?.immediate ?? false,
|
|
66
68
|
debounce: parentCtx?.debounce ?? 300,
|
|
67
69
|
notifyErrors: false,
|
|
68
|
-
registry: props.registry
|
|
70
|
+
registry: props.registry,
|
|
71
|
+
annotations: itemAnnotations
|
|
69
72
|
});
|
|
70
73
|
watchEffect(() => {
|
|
71
74
|
form.readonly.value = props.readonly;
|
|
72
75
|
if (parentCtx) form.ctx.submitted.value = parentCtx.submitted.value;
|
|
73
76
|
});
|
|
77
|
+
watch(
|
|
78
|
+
() => parentCtx?.reveal?.value,
|
|
79
|
+
(request) => {
|
|
80
|
+
if (!request?.rest) return;
|
|
81
|
+
const start = `${props.errorPrefix}.`;
|
|
82
|
+
const inside = `${request.key}.${request.rest}`;
|
|
83
|
+
if (!inside.startsWith(start)) return;
|
|
84
|
+
expanded.value = true;
|
|
85
|
+
void form.revealField(inside.slice(start.length)).then(request.settle);
|
|
86
|
+
},
|
|
87
|
+
{ immediate: true }
|
|
88
|
+
);
|
|
89
|
+
const itemAnnotationGroups = computed(
|
|
90
|
+
() => annotationGroups(
|
|
91
|
+
props.fields,
|
|
92
|
+
itemAnnotations.value,
|
|
93
|
+
localModel.value,
|
|
94
|
+
props.currentLang
|
|
95
|
+
)
|
|
96
|
+
);
|
|
74
97
|
const label = computed(
|
|
75
98
|
() => props.previewLabel?.(localModel.value, props.index) ?? `Item ${props.index + 1}`
|
|
76
99
|
);
|
|
@@ -100,6 +123,7 @@ function enterFocusMode() {
|
|
|
100
123
|
fields: props.fields,
|
|
101
124
|
model: { ...localModel.value },
|
|
102
125
|
errors: itemErrors,
|
|
126
|
+
annotations: itemAnnotations,
|
|
103
127
|
onUpdate: (val) => {
|
|
104
128
|
localModel.value = { ...val };
|
|
105
129
|
emit("update:item", localModel.value);
|
|
@@ -174,6 +198,7 @@ function enterFocusMode() {
|
|
|
174
198
|
<UBadge v-if="hasErrors" color="error" variant="soft" size="xs">
|
|
175
199
|
errors
|
|
176
200
|
</UBadge>
|
|
201
|
+
<MapoFormAnnotationBadges :groups="itemAnnotationGroups" size="xs" />
|
|
177
202
|
|
|
178
203
|
<!-- Quick actions (delete only in mini mode) -->
|
|
179
204
|
<div class="flex items-center gap-1">
|
|
@@ -222,10 +247,21 @@ function enterFocusMode() {
|
|
|
222
247
|
selectionMode ? toggleSelectFromEvent($event) : expanded = !expanded
|
|
223
248
|
"
|
|
224
249
|
>
|
|
250
|
+
<UBadge
|
|
251
|
+
v-if="templateLabel"
|
|
252
|
+
color="neutral"
|
|
253
|
+
variant="subtle"
|
|
254
|
+
size="xs"
|
|
255
|
+
:icon="templateIcon"
|
|
256
|
+
class="shrink-0"
|
|
257
|
+
>
|
|
258
|
+
{{ templateLabel }}
|
|
259
|
+
</UBadge>
|
|
225
260
|
<span class="truncate">{{ label }}</span>
|
|
226
261
|
<UBadge v-if="hasErrors" color="error" variant="soft" size="xs">
|
|
227
262
|
errors
|
|
228
263
|
</UBadge>
|
|
264
|
+
<MapoFormAnnotationBadges :groups="itemAnnotationGroups" size="xs" />
|
|
229
265
|
</button>
|
|
230
266
|
|
|
231
267
|
<!-- Action buttons. All buttons stop propagation so the row-click selection handler
|
|
@@ -22,10 +22,14 @@ type __VLS_Props = {
|
|
|
22
22
|
selected?: boolean;
|
|
23
23
|
/** true = bulk selection mode is active in the parent repeater. */
|
|
24
24
|
selectionMode?: boolean;
|
|
25
|
+
/** Display name of the item's template (repeaters with `attrs.templates`). */
|
|
26
|
+
templateLabel?: string;
|
|
27
|
+
/** Icon of the item's template. */
|
|
28
|
+
templateIcon?: string;
|
|
25
29
|
};
|
|
26
|
-
declare var
|
|
30
|
+
declare var __VLS_69: {};
|
|
27
31
|
type __VLS_Slots = {} & {
|
|
28
|
-
actions?: (props: typeof
|
|
32
|
+
actions?: (props: typeof __VLS_69) => any;
|
|
29
33
|
};
|
|
30
34
|
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
31
35
|
delete: () => any;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapoRepeaterItem.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoRepeaterItem.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MapoRepeaterItem.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoRepeaterItem.vue"],"names":[],"mappings":"AAodA,OAAO,KAAK,EACV,kBAAkB,EAElB,aAAa,EACb,kBAAkB,EACnB,MAAM,sBAAsB,CAAC;AAS9B,KAAK,WAAW,GAAG;IACjB,iEAAiE;IACjE,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC9B,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,CAAC;IACpB,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;IACvC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,QAAQ,EAAE,aAAa,CAAC;IACxB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IACxD,eAAe,EAAE,OAAO,CAAC;IACzB,cAAc,CAAC,EAAE,OAAO,CAAC;IACzB,wEAAwE;IACxE,kBAAkB,CAAC,EAAE,kBAAkB,CAAC;IACxC,kFAAkF;IAClF,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,iDAAiD;IACjD,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mEAAmE;IACnE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,8EAA8E;IAC9E,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,mCAAmC;IACnC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB,CAAC;AAk4BF,QAAA,IAAI,QAAQ,IAAY,CAAE;AAC1B,KAAK,WAAW,GAAG,EAAE,GACnB;IAAE,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG,CAAA;CAAE,CAAC;AAKhD,QAAA,MAAM,UAAU;;;;;;;;;;;;;;;;kFAGd,CAAC;AACH,QAAA,MAAM,YAAY,EAAS,eAAe,CAAC,OAAO,UAAU,EAAE,WAAW,CAAC,CAAC;wBACtD,OAAO,YAAY;AAAxC,wBAAyC;AACzC,KAAK,eAAe,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,GAAG;IAChC,QAAO;QACN,MAAM,EAAE,CAAC,CAAC;KACV,CAAA;CACD,CAAC"}
|
|
@@ -73,7 +73,7 @@ const editor = useEditor({
|
|
|
73
73
|
});
|
|
74
74
|
watch(
|
|
75
75
|
() => [props.readonly, props.disabled],
|
|
76
|
-
([ro, dis]) => editor.value?.setEditable(!ro && !dis)
|
|
76
|
+
([ro, dis]) => editor.value?.setEditable(!ro && !dis, false)
|
|
77
77
|
);
|
|
78
78
|
watch(
|
|
79
79
|
() => props.modelValue,
|
|
@@ -98,10 +98,13 @@ function onImageConfirm(selection) {
|
|
|
98
98
|
</script>
|
|
99
99
|
|
|
100
100
|
<template>
|
|
101
|
+
<!-- An input surface of its own, like the Nuxt UI inputs next to it
|
|
102
|
+
(`bg-default`, `accented` border): without it the text area takes the
|
|
103
|
+
page background and disappears on a tinted page. -->
|
|
101
104
|
<div
|
|
102
|
-
class="mapo-wyg-editor rounded border"
|
|
105
|
+
class="mapo-wyg-editor rounded-md border bg-default"
|
|
103
106
|
:class="[
|
|
104
|
-
errors?.length ? 'border-red-300' : 'border-
|
|
107
|
+
errors?.length ? 'border-red-300' : 'border-accented',
|
|
105
108
|
readonly || disabled ? 'opacity-60' : ''
|
|
106
109
|
]"
|
|
107
110
|
>
|
|
@@ -238,15 +241,18 @@ function onImageConfirm(selection) {
|
|
|
238
241
|
>
|
|
239
242
|
{{ err }}
|
|
240
243
|
</p>
|
|
241
|
-
</div>
|
|
242
244
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
245
|
+
<!-- Image picker dialog — only rendered when MapoMediaManagerDialog is
|
|
246
|
+
globally available. Inside the root on purpose: a second root would
|
|
247
|
+
drop what MapoFormField passes down (`flex-1`, `id`, `style`), and the
|
|
248
|
+
editor would shrink to its toolbar. As a modal it renders in <body>. -->
|
|
249
|
+
<component
|
|
250
|
+
:is="MediaManagerDialog"
|
|
251
|
+
v-if="hasMediaManager"
|
|
252
|
+
v-model="imagePickerOpen"
|
|
253
|
+
selection-mode="single"
|
|
254
|
+
mime="image/*"
|
|
255
|
+
@confirm="onImageConfirm"
|
|
256
|
+
/>
|
|
257
|
+
</div>
|
|
252
258
|
</template>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MapoWygEditor.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoWygEditor.vue"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MapoWygEditor.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoWygEditor.vue"],"names":[],"mappings":"AA6TA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAE7D,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,gBAAgB,CAAC;IAC7B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AA+pBF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { ComputedRef, MaybeRefOrGetter } from "vue";
|
|
2
|
+
import type { AnyFieldDescriptor, FieldAnnotation } from "../types/index.js";
|
|
3
|
+
/**
|
|
4
|
+
* The annotation of a field, the one its mark shows: the entry at the path of
|
|
5
|
+
* its value, then, for a translatable field, the entry at its bare key.
|
|
6
|
+
*
|
|
7
|
+
* Call it in a custom field component, which receives its `descriptor` as a
|
|
8
|
+
* prop, to style the field or show the annotation in it. Inside a repeater item
|
|
9
|
+
* it reads the item's annotations; outside a form it is always `undefined`.
|
|
10
|
+
*
|
|
11
|
+
* @param descriptor The field's descriptor, or a getter of it.
|
|
12
|
+
* @returns A computed annotation, `undefined` when the field has none.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* const annotation = useFieldAnnotation(() => props.descriptor);
|
|
16
|
+
*/
|
|
17
|
+
export declare function useFieldAnnotation(descriptor: MaybeRefOrGetter<AnyFieldDescriptor<any>>): ComputedRef<FieldAnnotation | undefined>;
|
|
18
|
+
//# sourceMappingURL=useFieldAnnotation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFieldAnnotation.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useFieldAnnotation.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,KAAK,CAAC;AACzD,OAAO,KAAK,EAAE,kBAAkB,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAI7E;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAIhC,UAAU,EAAE,gBAAgB,CAAC,kBAAkB,CAAC,GAAG,CAAC,CAAC,GACpD,WAAW,CAAC,eAAe,GAAG,SAAS,CAAC,CAY1C"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { computed, toValue } from "vue";
|
|
2
|
+
import { annotationFor, valuePath } from "../utils/annotations.js";
|
|
3
|
+
import { injectMapoForm } from "./useMapoForm.js";
|
|
4
|
+
export function useFieldAnnotation(descriptor) {
|
|
5
|
+
const form = injectMapoForm();
|
|
6
|
+
return computed(() => {
|
|
7
|
+
if (!form) return void 0;
|
|
8
|
+
const field = toValue(descriptor);
|
|
9
|
+
const path = valuePath(field, form.currentLang.value);
|
|
10
|
+
return annotationFor(
|
|
11
|
+
form.annotations?.value ?? {},
|
|
12
|
+
field.key,
|
|
13
|
+
path
|
|
14
|
+
);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { type Ref, type DeepReadonly, type ShallowRef } from "vue";
|
|
2
|
-
import type { AnyFieldDescriptor, FieldRegistry } from "../types/index.js";
|
|
2
|
+
import type { AnyFieldDescriptor, FieldAnnotations, FieldRegistry } from "../types/index.js";
|
|
3
3
|
/** Describes the currently focused repeater item in focus mode. */
|
|
4
4
|
export interface FocusTarget {
|
|
5
5
|
/** Descriptor of the repeater field that contains the focused item. */
|
|
@@ -14,6 +14,8 @@ export interface FocusTarget {
|
|
|
14
14
|
model: Record<string, unknown>;
|
|
15
15
|
/** Errors for this item (already filtered). */
|
|
16
16
|
errors: Ref<Record<string, string[]>>;
|
|
17
|
+
/** Annotations for this item (already filtered), keyed by the item's paths. */
|
|
18
|
+
annotations?: Readonly<Ref<FieldAnnotations>>;
|
|
17
19
|
/** Callback invoked when the item model is updated. */
|
|
18
20
|
onUpdate: (val: Record<string, unknown>) => void;
|
|
19
21
|
/** Field component registry passed to the sub-form. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFocusMode.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useFocusMode.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,GAAG,EACR,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,KAAK,CAAC;AACb,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"useFocusMode.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useFocusMode.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,GAAG,EACR,KAAK,YAAY,EACjB,KAAK,UAAU,EAChB,MAAM,KAAK,CAAC;AACb,OAAO,KAAK,EACV,kBAAkB,EAClB,gBAAgB,EAChB,aAAa,EACd,MAAM,mBAAmB,CAAC;AAE3B,mEAAmE;AACnE,MAAM,WAAW,WAAW;IAC1B,uEAAuE;IACvE,UAAU,EAAE,kBAAkB,CAAC;IAC/B,2EAA2E;IAC3E,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B;;;;OAIG;IACH,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,+CAA+C;IAC/C,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC;IACtC,+EAA+E;IAC/E,WAAW,CAAC,EAAE,QAAQ,CAAC,GAAG,CAAC,gBAAgB,CAAC,CAAC,CAAC;IAC9C,uDAAuD;IACvD,QAAQ,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,IAAI,CAAC;IACjD,uDAAuD;IACvD,QAAQ,EAAE,aAAa,CAAC;IACxB,gCAAgC;IAChC,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,sCAAsC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,gEAAgE;IAChE,UAAU,EAAE,MAAM,EAAE,CAAC;CACtB;AAED,6DAA6D;AAC7D,MAAM,WAAW,eAAe;IAC9B,WAAW,EAAE,YAAY,CAAC,UAAU,CAAC,WAAW,GAAG,IAAI,CAAC,CAAC,CAAC;IAC1D,QAAQ,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACvB,KAAK,EAAE,CAAC,MAAM,EAAE,WAAW,KAAK,IAAI,CAAC;IACrC,IAAI,EAAE,MAAM,IAAI,CAAC;CAClB;AAqBD;;;GAGG;AACH,wBAAgB,YAAY,IAAI,eAAe,CAkB9C"}
|
|
@@ -1,5 +1,26 @@
|
|
|
1
1
|
import type { JSONSchema } from "@mapomodule/utils";
|
|
2
|
-
import type { AnyFieldDescriptor } from "../types/index.js";
|
|
2
|
+
import type { AnyFieldDescriptor, FieldType } from "../types/index.js";
|
|
3
|
+
/** The property where a repeater item keeps its template key. @internal */
|
|
4
|
+
export declare const TEMPLATE_PROPERTY = "_template";
|
|
5
|
+
/**
|
|
6
|
+
* Attrs that a JSON Schema keyword with the same meaning expresses, by field
|
|
7
|
+
* type. The reader maps the keyword to the attr, and `fieldsToJsonSchema()`
|
|
8
|
+
* the attr to the keyword. @internal
|
|
9
|
+
*/
|
|
10
|
+
export declare const KEYWORD_ATTRS: Readonly<Record<string, Readonly<Record<string, string>>>>;
|
|
11
|
+
/**
|
|
12
|
+
* Attr names never read from a schema nor written to one. Attrs reach the
|
|
13
|
+
* field component through `v-bind`: an event handler (`onFocus`, `onclick`) or
|
|
14
|
+
* a DOM property such as `innerHTML` would let a schema run script.
|
|
15
|
+
* @internal
|
|
16
|
+
*/
|
|
17
|
+
export declare function isUnsafeAttr(name: string): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* The field type `useFormFromSchema()` gives a property. `fieldsToJsonSchema()`
|
|
20
|
+
* uses it to write `x-mapo-field` only when the other keywords are not enough.
|
|
21
|
+
* @internal
|
|
22
|
+
*/
|
|
23
|
+
export declare function schemaFieldType(schema: JSONSchema, key: string): FieldType;
|
|
3
24
|
/** Options for generating field descriptors from a JSON Schema document. */
|
|
4
25
|
export interface UseFormFromSchemaOptions {
|
|
5
26
|
/** Keys to exclude from generation, for example `id` or `created_at`. */
|
|
@@ -10,6 +31,7 @@ export interface UseFormFromSchemaOptions {
|
|
|
10
31
|
/**
|
|
11
32
|
* Builds a `AnyFieldDescriptor[]` array from a JSON Schema.
|
|
12
33
|
* Supports Pydantic v2 (`$defs`, nullable `anyOf`), DRF Spectacular, and `if/then/else` conditionals.
|
|
34
|
+
* Reads back the schemas `fieldsToJsonSchema()` writes.
|
|
13
35
|
*
|
|
14
36
|
* @example
|
|
15
37
|
* const fields = useFormFromSchema(myApiSchema, {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFormFromSchema.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useFormFromSchema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"useFormFromSchema.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useFormFromSchema.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,KAAK,EACV,kBAAkB,EAClB,SAAS,EAEV,MAAM,mBAAmB,CAAC;AAO3B,2EAA2E;AAC3E,eAAO,MAAM,iBAAiB,cAAc,CAAC;AAE7C;;;;GAIG;AACH,eAAO,MAAM,aAAa,EAAE,QAAQ,CAClC,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,CAUjD,CAAC;AAEF;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAOlD;AAiLD;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,MAAM,EAAE,UAAU,EAAE,GAAG,EAAE,MAAM,GAAG,SAAS,CAE1E;AA2ND,4EAA4E;AAC5E,MAAM,WAAW,wBAAwB;IACvC,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,EAAE,CAAC;IACnB,4EAA4E;IAC5E,SAAS,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC;CACzD;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,iBAAiB,CAC/B,MAAM,EAAE,UAAU,EAClB,OAAO,GAAE,wBAA6B,GACrC,kBAAkB,EAAE,CAsCtB"}
|