@mapomodule/form 2.0.0-beta.1 → 2.0.0-beta.10
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 +2 -1
- package/dist/__tests__/__mocks__/nuxt-imports.d.ts +4 -0
- package/dist/__tests__/__mocks__/nuxt-imports.d.ts.map +1 -0
- package/dist/__tests__/camomillaRoundTrip.test.d.ts +2 -0
- package/dist/__tests__/camomillaRoundTrip.test.d.ts.map +1 -0
- package/dist/__tests__/registry.test.d.ts +2 -0
- package/dist/__tests__/registry.test.d.ts.map +1 -0
- package/dist/__tests__/useFormFromSchema.test.d.ts +2 -0
- package/dist/__tests__/useFormFromSchema.test.d.ts.map +1 -0
- package/dist/__tests__/useMapoForm.test.d.ts +2 -0
- package/dist/__tests__/useMapoForm.test.d.ts.map +1 -0
- package/dist/index.d.mts +9 -1
- package/dist/index.d.ts +15 -1
- package/dist/index.d.ts.map +1 -0
- package/dist/index.mjs +7 -34
- package/dist/module.d.mts +20 -2
- package/dist/module.d.ts +12 -2
- package/dist/module.d.ts.map +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +187 -13
- package/dist/runtime/components/MapoFocusPortal.vue +115 -0
- package/dist/runtime/components/MapoFocusPortal.vue.d.ts +4 -0
- package/dist/runtime/components/MapoFocusPortal.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoForm.vue +168 -0
- package/dist/runtime/components/MapoForm.vue.d.ts +47 -0
- package/dist/runtime/components/MapoForm.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoFormField.vue +269 -0
- package/dist/runtime/components/MapoFormField.vue.d.ts +46 -0
- package/dist/runtime/components/MapoFormField.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoFormFlatSection.vue +149 -0
- package/dist/runtime/components/MapoFormFlatSection.vue.d.ts +15 -0
- package/dist/runtime/components/MapoFormFlatSection.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoFormGroup.vue +247 -0
- package/dist/runtime/components/MapoFormGroup.vue.d.ts +44 -0
- package/dist/runtime/components/MapoFormGroup.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoFormTabs.vue +110 -0
- package/dist/runtime/components/MapoFormTabs.vue.d.ts +15 -0
- package/dist/runtime/components/MapoFormTabs.vue.d.ts.map +1 -0
- package/dist/runtime/components/MapoUnknownField.vue +62 -0
- package/dist/runtime/components/MapoUnknownField.vue.d.ts +16 -0
- package/dist/runtime/components/MapoUnknownField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoDateField.vue +88 -0
- package/dist/runtime/components/fields/MapoDateField.vue.d.ts +17 -0
- package/dist/runtime/components/fields/MapoDateField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoDateTimeField.vue +159 -0
- package/dist/runtime/components/fields/MapoDateTimeField.vue.d.ts +17 -0
- package/dist/runtime/components/fields/MapoDateTimeField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoEnhancedMediaField.vue +130 -0
- package/dist/runtime/components/fields/MapoEnhancedMediaField.vue.d.ts +16 -0
- package/dist/runtime/components/fields/MapoEnhancedMediaField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoFileField.vue +99 -0
- package/dist/runtime/components/fields/MapoFileField.vue.d.ts +16 -0
- package/dist/runtime/components/fields/MapoFileField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoFksField.vue +122 -0
- package/dist/runtime/components/fields/MapoFksField.vue.d.ts +16 -0
- package/dist/runtime/components/fields/MapoFksField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoMapField.vue +99 -0
- package/dist/runtime/components/fields/MapoMapField.vue.d.ts +22 -0
- package/dist/runtime/components/fields/MapoMapField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoMapFieldClient.vue +67 -0
- package/dist/runtime/components/fields/MapoMapFieldClient.vue.d.ts +20 -0
- package/dist/runtime/components/fields/MapoMapFieldClient.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoMediaField.vue +91 -0
- package/dist/runtime/components/fields/MapoMediaField.vue.d.ts +16 -0
- package/dist/runtime/components/fields/MapoMediaField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoMediaM2mField.vue +110 -0
- package/dist/runtime/components/fields/MapoMediaM2mField.vue.d.ts +16 -0
- package/dist/runtime/components/fields/MapoMediaM2mField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoMediaUnavailable.vue +15 -0
- package/dist/runtime/components/fields/MapoMediaUnavailable.vue.d.ts +4 -0
- package/dist/runtime/components/fields/MapoMediaUnavailable.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoRepeater.vue +459 -0
- package/dist/runtime/components/fields/MapoRepeater.vue.d.ts +16 -0
- package/dist/runtime/components/fields/MapoRepeater.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoRepeaterItem.vue +346 -0
- package/dist/runtime/components/fields/MapoRepeaterItem.vue.d.ts +55 -0
- package/dist/runtime/components/fields/MapoRepeaterItem.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoSeoPreview.vue +122 -0
- package/dist/runtime/components/fields/MapoSeoPreview.vue.d.ts +22 -0
- package/dist/runtime/components/fields/MapoSeoPreview.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoTimeField.vue +44 -0
- package/dist/runtime/components/fields/MapoTimeField.vue.d.ts +17 -0
- package/dist/runtime/components/fields/MapoTimeField.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/MapoWygEditor.vue +252 -0
- package/dist/runtime/components/fields/MapoWygEditor.vue.d.ts +16 -0
- package/dist/runtime/components/fields/MapoWygEditor.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/nui/NuiCheckbox.vue +9 -0
- package/dist/runtime/components/fields/nui/NuiCheckbox.vue.d.ts +4 -0
- package/dist/runtime/components/fields/nui/NuiCheckbox.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/nui/NuiInput.vue +9 -0
- package/dist/runtime/components/fields/nui/NuiInput.vue.d.ts +4 -0
- package/dist/runtime/components/fields/nui/NuiInput.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/nui/NuiSelectMenu.vue +18 -0
- package/dist/runtime/components/fields/nui/NuiSelectMenu.vue.d.ts +4 -0
- package/dist/runtime/components/fields/nui/NuiSelectMenu.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/nui/NuiSlider.vue +9 -0
- package/dist/runtime/components/fields/nui/NuiSlider.vue.d.ts +4 -0
- package/dist/runtime/components/fields/nui/NuiSlider.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/nui/NuiSwitch.vue +9 -0
- package/dist/runtime/components/fields/nui/NuiSwitch.vue.d.ts +4 -0
- package/dist/runtime/components/fields/nui/NuiSwitch.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/nui/NuiTextarea.vue +9 -0
- package/dist/runtime/components/fields/nui/NuiTextarea.vue.d.ts +4 -0
- package/dist/runtime/components/fields/nui/NuiTextarea.vue.d.ts.map +1 -0
- package/dist/runtime/components/fields/nui/useNuiFieldAttrs.d.ts +13 -0
- package/dist/runtime/components/fields/nui/useNuiFieldAttrs.d.ts.map +1 -0
- package/dist/runtime/components/fields/nui/useNuiFieldAttrs.js +19 -0
- package/dist/runtime/composables/defineFormField.d.ts +25 -0
- package/dist/runtime/composables/defineFormField.d.ts.map +1 -0
- package/dist/runtime/composables/defineFormField.js +27 -0
- package/dist/runtime/composables/useCurrentLang.d.ts +6 -0
- package/dist/runtime/composables/useCurrentLang.d.ts.map +1 -0
- package/dist/runtime/composables/useCurrentLang.js +9 -0
- package/dist/runtime/composables/useFocusMode.d.ts +40 -0
- package/dist/runtime/composables/useFocusMode.d.ts.map +1 -0
- package/dist/runtime/composables/useFocusMode.js +31 -0
- package/dist/runtime/composables/useFormDraft.d.ts +60 -0
- package/dist/runtime/composables/useFormDraft.d.ts.map +1 -0
- package/dist/runtime/composables/useFormDraft.js +52 -0
- package/dist/runtime/composables/useFormFromSchema.d.ts +21 -0
- package/dist/runtime/composables/useFormFromSchema.d.ts.map +1 -0
- package/dist/runtime/composables/useFormFromSchema.js +145 -0
- package/dist/runtime/composables/useMapoForm.d.ts +96 -0
- package/dist/runtime/composables/useMapoForm.d.ts.map +1 -0
- package/dist/runtime/composables/useMapoForm.js +325 -0
- package/dist/runtime/composables/useMediaManager.d.ts +17 -0
- package/dist/runtime/composables/useMediaManager.d.ts.map +1 -0
- package/dist/runtime/composables/useMediaManager.js +6 -0
- package/dist/runtime/composables/useProgressiveDisclosure.d.ts +44 -0
- package/dist/runtime/composables/useProgressiveDisclosure.d.ts.map +1 -0
- package/dist/runtime/composables/useProgressiveDisclosure.js +23 -0
- package/dist/runtime/composables/useUnsavedChangesGuard.d.ts +24 -0
- package/dist/runtime/composables/useUnsavedChangesGuard.d.ts.map +1 -0
- package/dist/runtime/composables/useUnsavedChangesGuard.js +28 -0
- package/dist/runtime/devtools/DevtoolsFormsPage.vue +235 -0
- package/dist/runtime/devtools/DevtoolsFormsPage.vue.d.ts +4 -0
- package/dist/runtime/devtools/DevtoolsFormsPage.vue.d.ts.map +1 -0
- package/dist/runtime/plugins/form-registry.d.ts +18 -0
- package/dist/runtime/plugins/form-registry.d.ts.map +1 -0
- package/dist/runtime/plugins/form-registry.js +19 -0
- package/dist/runtime/registry/defaults.d.ts +3 -0
- package/dist/runtime/registry/defaults.d.ts.map +1 -0
- package/dist/runtime/registry/defaults.js +93 -0
- package/dist/runtime/types/descriptor.d.ts +373 -0
- package/dist/runtime/types/descriptor.d.ts.map +1 -0
- package/dist/runtime/types/descriptor.js +26 -0
- package/dist/runtime/types/index.d.ts +12 -0
- package/dist/runtime/types/index.d.ts.map +1 -0
- package/dist/runtime/types/index.js +6 -0
- package/dist/runtime/types/layout.d.ts +21 -0
- package/dist/runtime/types/layout.d.ts.map +1 -0
- package/dist/runtime/types/layout.js +0 -0
- package/dist/runtime/types/media.d.ts +43 -0
- package/dist/runtime/types/media.d.ts.map +1 -0
- package/dist/runtime/types/media.js +0 -0
- package/dist/runtime/types/registry.d.ts +62 -0
- package/dist/runtime/types/registry.d.ts.map +1 -0
- package/dist/runtime/types/registry.js +19 -0
- package/dist/runtime/utils/flattenFieldGroups.d.ts +50 -0
- package/dist/runtime/utils/flattenFieldGroups.d.ts.map +1 -0
- package/dist/runtime/utils/flattenFieldGroups.js +24 -0
- package/dist/types.d.mts +6 -10
- package/package.json +10 -8
- package/src/__tests__/article.schema.json +193 -0
- package/src/__tests__/camomillaRoundTrip.test.ts +73 -0
- package/src/__tests__/useFormFromSchema.test.ts +24 -0
- package/src/__tests__/useMapoForm.test.ts +5 -0
- package/src/index.ts +5 -0
- package/src/module.ts +34 -0
- package/src/runtime/components/MapoFocusPortal.vue +3 -1
- package/src/runtime/components/MapoFormTabs.vue +4 -1
- package/src/runtime/components/fields/MapoDateField.vue +3 -1
- package/src/runtime/components/fields/MapoDateTimeField.vue +3 -1
- package/src/runtime/components/fields/MapoEnhancedMediaField.vue +153 -0
- package/src/runtime/components/fields/MapoFileField.vue +3 -1
- package/src/runtime/components/fields/MapoFksField.vue +7 -2
- package/src/runtime/components/fields/MapoMapField.vue +5 -2
- package/src/runtime/components/fields/MapoMediaField.vue +104 -0
- package/src/runtime/components/fields/MapoMediaM2mField.vue +130 -0
- package/src/runtime/components/fields/MapoMediaUnavailable.vue +19 -0
- package/src/runtime/components/fields/MapoRepeater.vue +33 -26
- package/src/runtime/components/fields/MapoRepeaterItem.vue +14 -8
- package/src/runtime/components/fields/MapoSeoPreview.vue +17 -13
- package/src/runtime/components/fields/MapoWygEditor.vue +47 -5
- package/src/runtime/composables/useFormFromSchema.ts +4 -1
- package/src/runtime/composables/useMapoForm.ts +4 -2
- package/src/runtime/composables/useMediaManager.ts +21 -0
- package/src/runtime/composables/useUnsavedChangesGuard.ts +3 -3
- package/src/runtime/registry/defaults.ts +9 -1
- package/src/runtime/types/descriptor.ts +22 -7
- package/src/runtime/types/index.ts +4 -0
- package/src/runtime/types/media.ts +44 -0
- package/dist/index.d.cts +0 -1
- package/dist/module.d.cts +0 -2
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { AnyFieldDescriptor } from "../types/index.js";
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
fields: AnyFieldDescriptor[];
|
|
4
|
+
};
|
|
5
|
+
type __VLS_Slots = Record<string, unknown>;
|
|
6
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
8
|
+
declare const _default: typeof __VLS_export;
|
|
9
|
+
export default _default;
|
|
10
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
11
|
+
new (): {
|
|
12
|
+
$slots: S;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=MapoFormFlatSection.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapoFormFlatSection.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFormFlatSection.vue"],"names":[],"mappings":"AAuKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAI5D,KAAK,WAAW,GAAG;IAAE,MAAM,EAAE,kBAAkB,EAAE,CAAA;CAAE,CAAC;AAGpD,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAmS3C,QAAA,MAAM,UAAU,kSAEd,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"}
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import {
|
|
3
|
+
ref,
|
|
4
|
+
computed,
|
|
5
|
+
provide,
|
|
6
|
+
watchEffect,
|
|
7
|
+
onMounted,
|
|
8
|
+
onUnmounted
|
|
9
|
+
} from "vue";
|
|
10
|
+
import { useRuntimeConfig } from "#app";
|
|
11
|
+
import { injectMapoForm } from "../composables/useMapoForm.js";
|
|
12
|
+
import MapoFormField from "./MapoFormField.vue";
|
|
13
|
+
const props = defineProps({
|
|
14
|
+
name: { type: String, required: true },
|
|
15
|
+
label: { type: String, required: false },
|
|
16
|
+
fields: { type: Array, required: true },
|
|
17
|
+
subtabs: { type: Map, required: false },
|
|
18
|
+
initialExpanded: { type: Boolean, required: false }
|
|
19
|
+
});
|
|
20
|
+
const globalExpanded = useRuntimeConfig().public.mapoForm?.groups?.expanded ?? true;
|
|
21
|
+
const expanded = ref(props.initialExpanded ?? globalExpanded);
|
|
22
|
+
const activeSubtab = ref("");
|
|
23
|
+
watchEffect(() => {
|
|
24
|
+
if (props.subtabs && props.subtabs.size > 0 && !activeSubtab.value) {
|
|
25
|
+
activeSubtab.value = [...props.subtabs.keys()][0] ?? "";
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
const expandedFieldKey = ref(null);
|
|
29
|
+
function expandField(key) {
|
|
30
|
+
expandedFieldKey.value = key;
|
|
31
|
+
document.body.style.overflow = "hidden";
|
|
32
|
+
}
|
|
33
|
+
function collapseField() {
|
|
34
|
+
expandedFieldKey.value = null;
|
|
35
|
+
document.body.style.overflow = "";
|
|
36
|
+
}
|
|
37
|
+
function onKeydown(e) {
|
|
38
|
+
if (e.key === "Escape" && expandedFieldKey.value) collapseField();
|
|
39
|
+
}
|
|
40
|
+
onMounted(() => document.addEventListener("keydown", onKeydown));
|
|
41
|
+
onUnmounted(() => {
|
|
42
|
+
document.removeEventListener("keydown", onKeydown);
|
|
43
|
+
document.body.style.overflow = "";
|
|
44
|
+
});
|
|
45
|
+
provide("mapoGroupExpand", { expandField, collapseField, expandedFieldKey });
|
|
46
|
+
const form = injectMapoForm();
|
|
47
|
+
const model = computed(() => form?.model.value);
|
|
48
|
+
const currentLang = computed(() => form?.currentLang.value ?? "");
|
|
49
|
+
const COL_SPAN = {
|
|
50
|
+
1: "col-span-1",
|
|
51
|
+
2: "col-span-2",
|
|
52
|
+
3: "col-span-3",
|
|
53
|
+
4: "col-span-4",
|
|
54
|
+
5: "col-span-5",
|
|
55
|
+
6: "col-span-6",
|
|
56
|
+
7: "col-span-7",
|
|
57
|
+
8: "col-span-8",
|
|
58
|
+
9: "col-span-9",
|
|
59
|
+
10: "col-span-10",
|
|
60
|
+
11: "col-span-11",
|
|
61
|
+
12: "col-span-12"
|
|
62
|
+
};
|
|
63
|
+
function colClass(cols) {
|
|
64
|
+
if (!cols || typeof cols !== "number") return "col-span-12";
|
|
65
|
+
return COL_SPAN[cols] ?? "col-span-12";
|
|
66
|
+
}
|
|
67
|
+
</script>
|
|
68
|
+
|
|
69
|
+
<template>
|
|
70
|
+
<!-- Expanded panel: teleported to body to avoid parent overflow/transform interference. -->
|
|
71
|
+
<Teleport to="body">
|
|
72
|
+
<Transition name="mapo-expand">
|
|
73
|
+
<div
|
|
74
|
+
v-if="expandedFieldKey"
|
|
75
|
+
class="fixed inset-0 z-50 flex flex-col"
|
|
76
|
+
style="padding: 1rem"
|
|
77
|
+
>
|
|
78
|
+
<!-- Clickable backdrop -->
|
|
79
|
+
<div
|
|
80
|
+
class="absolute inset-0 bg-black/50 backdrop-blur-sm"
|
|
81
|
+
@click="collapseField"
|
|
82
|
+
/>
|
|
83
|
+
|
|
84
|
+
<!-- Panel -->
|
|
85
|
+
<div
|
|
86
|
+
class="relative z-10 flex h-full flex-col overflow-hidden rounded-xl border border-gray-200 bg-white shadow-2xl"
|
|
87
|
+
>
|
|
88
|
+
<!-- Header -->
|
|
89
|
+
<div
|
|
90
|
+
class="flex shrink-0 items-center justify-between border-b border-gray-100 px-5 py-3.5"
|
|
91
|
+
>
|
|
92
|
+
<span class="text-sm font-semibold tracking-wide text-gray-700">{{
|
|
93
|
+
label ?? name
|
|
94
|
+
}}</span>
|
|
95
|
+
<button
|
|
96
|
+
type="button"
|
|
97
|
+
class="rounded p-1 text-gray-400 transition-colors hover:bg-gray-100 hover:text-gray-600"
|
|
98
|
+
@click="collapseField"
|
|
99
|
+
>
|
|
100
|
+
<UIcon name="i-lucide-minimize-2" class="h-4 w-4" />
|
|
101
|
+
</button>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<!-- Expanded field -->
|
|
105
|
+
<div
|
|
106
|
+
class="mapo-group-expand-body flex min-h-0 flex-1 flex-col p-5"
|
|
107
|
+
style="overflow: hidden"
|
|
108
|
+
>
|
|
109
|
+
<template v-for="field in fields" :key="field.key">
|
|
110
|
+
<div
|
|
111
|
+
v-if="expandedFieldKey === field.key"
|
|
112
|
+
style="
|
|
113
|
+
display: flex;
|
|
114
|
+
flex-direction: column;
|
|
115
|
+
flex: 1;
|
|
116
|
+
min-height: 0;
|
|
117
|
+
height: 100%;
|
|
118
|
+
"
|
|
119
|
+
>
|
|
120
|
+
<slot
|
|
121
|
+
:name="`field.${field.key}`"
|
|
122
|
+
:field="field"
|
|
123
|
+
:model="model"
|
|
124
|
+
:current-lang="currentLang"
|
|
125
|
+
>
|
|
126
|
+
<MapoFormField
|
|
127
|
+
:descriptor="field"
|
|
128
|
+
style="flex: 1; min-height: 0; height: 100%"
|
|
129
|
+
>
|
|
130
|
+
<template
|
|
131
|
+
v-for="(_, slotName) in $slots"
|
|
132
|
+
#[slotName]="slotProps"
|
|
133
|
+
>
|
|
134
|
+
<slot :name="slotName" v-bind="slotProps ?? {}" />
|
|
135
|
+
</template>
|
|
136
|
+
</MapoFormField>
|
|
137
|
+
</slot>
|
|
138
|
+
</div>
|
|
139
|
+
</template>
|
|
140
|
+
</div>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
</Transition>
|
|
144
|
+
</Teleport>
|
|
145
|
+
|
|
146
|
+
<!-- Regular group (kept in the DOM so the provide stays active) -->
|
|
147
|
+
<div
|
|
148
|
+
class="mapo-form-group relative overflow-hidden rounded-xl border border-gray-200 bg-white shadow-sm"
|
|
149
|
+
>
|
|
150
|
+
<!-- Collapsible heading -->
|
|
151
|
+
<button
|
|
152
|
+
type="button"
|
|
153
|
+
class="flex w-full items-center justify-between px-5 py-3.5 text-left transition-colors hover:bg-gray-50"
|
|
154
|
+
@click="expanded = !expanded"
|
|
155
|
+
>
|
|
156
|
+
<span class="text-sm font-semibold tracking-wide text-gray-700">{{
|
|
157
|
+
label ?? name
|
|
158
|
+
}}</span>
|
|
159
|
+
<UIcon
|
|
160
|
+
:name="expanded ? 'i-lucide-chevron-up' : 'i-lucide-chevron-down'"
|
|
161
|
+
class="h-4 w-4 shrink-0 text-gray-400"
|
|
162
|
+
/>
|
|
163
|
+
</button>
|
|
164
|
+
|
|
165
|
+
<!-- Body -->
|
|
166
|
+
<div v-if="expanded">
|
|
167
|
+
<!-- Flat fields (no subtab) -->
|
|
168
|
+
<div
|
|
169
|
+
v-if="fields.length"
|
|
170
|
+
class="grid grid-cols-12 gap-5 px-5 pb-5 pt-4"
|
|
171
|
+
:class="{ 'pb-0': subtabs && subtabs.size > 0 }"
|
|
172
|
+
>
|
|
173
|
+
<div
|
|
174
|
+
v-for="field in fields"
|
|
175
|
+
:key="field.key"
|
|
176
|
+
:class="colClass(field.cols)"
|
|
177
|
+
>
|
|
178
|
+
<slot
|
|
179
|
+
:name="`field.${field.key}`"
|
|
180
|
+
:field="field"
|
|
181
|
+
:model="model"
|
|
182
|
+
:current-lang="currentLang"
|
|
183
|
+
>
|
|
184
|
+
<MapoFormField :descriptor="field">
|
|
185
|
+
<template v-for="(_, slotName) in $slots" #[slotName]="slotProps">
|
|
186
|
+
<slot :name="slotName" v-bind="slotProps ?? {}" />
|
|
187
|
+
</template>
|
|
188
|
+
</MapoFormField>
|
|
189
|
+
</slot>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
|
|
193
|
+
<!-- Sub-tab bar + content (when subtabs are present) -->
|
|
194
|
+
<div v-if="subtabs && subtabs.size > 0" class="px-5 pb-5 pt-4">
|
|
195
|
+
<!-- Sub-tab bar -->
|
|
196
|
+
<div class="flex gap-1 border-b border-gray-200 mb-4">
|
|
197
|
+
<button
|
|
198
|
+
v-for="[subtabName] of subtabs"
|
|
199
|
+
:key="subtabName"
|
|
200
|
+
type="button"
|
|
201
|
+
class="relative px-3 py-1.5 text-sm font-medium transition-colors focus:outline-none"
|
|
202
|
+
:class="[
|
|
203
|
+
activeSubtab === subtabName ? 'text-primary-600 border-b-2 border-primary-600 -mb-px' : 'text-gray-500 hover:text-gray-700'
|
|
204
|
+
]"
|
|
205
|
+
@click="activeSubtab = subtabName"
|
|
206
|
+
>
|
|
207
|
+
{{ subtabName }}
|
|
208
|
+
</button>
|
|
209
|
+
</div>
|
|
210
|
+
|
|
211
|
+
<!-- Sub-tab fields -->
|
|
212
|
+
<div
|
|
213
|
+
v-for="[subtabName, subtabFields] of subtabs"
|
|
214
|
+
v-show="activeSubtab === subtabName"
|
|
215
|
+
:key="subtabName"
|
|
216
|
+
class="grid grid-cols-12 gap-5"
|
|
217
|
+
>
|
|
218
|
+
<div
|
|
219
|
+
v-for="field in subtabFields"
|
|
220
|
+
:key="field.key"
|
|
221
|
+
:class="colClass(field.cols)"
|
|
222
|
+
>
|
|
223
|
+
<slot
|
|
224
|
+
:name="`field.${field.key}`"
|
|
225
|
+
:field="field"
|
|
226
|
+
:model="model"
|
|
227
|
+
:current-lang="currentLang"
|
|
228
|
+
>
|
|
229
|
+
<MapoFormField :descriptor="field">
|
|
230
|
+
<template
|
|
231
|
+
v-for="(_, slotName) in $slots"
|
|
232
|
+
#[slotName]="slotProps"
|
|
233
|
+
>
|
|
234
|
+
<slot :name="slotName" v-bind="slotProps ?? {}" />
|
|
235
|
+
</template>
|
|
236
|
+
</MapoFormField>
|
|
237
|
+
</slot>
|
|
238
|
+
</div>
|
|
239
|
+
</div>
|
|
240
|
+
</div>
|
|
241
|
+
</div>
|
|
242
|
+
</div>
|
|
243
|
+
</template>
|
|
244
|
+
|
|
245
|
+
<style>
|
|
246
|
+
.mapo-expand-enter-active,.mapo-expand-leave-active{transition:opacity .2s ease,transform .2s ease}.mapo-expand-enter-from,.mapo-expand-leave-to{opacity:0;transform:scale(.97)}
|
|
247
|
+
</style>
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { AnyFieldDescriptor } from "../types/index.js";
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
name: string;
|
|
4
|
+
label?: string;
|
|
5
|
+
fields: AnyFieldDescriptor[];
|
|
6
|
+
subtabs?: Map<string, AnyFieldDescriptor[]>;
|
|
7
|
+
initialExpanded?: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare var __VLS_19: `field.${string}`, __VLS_20: {
|
|
10
|
+
field: AnyFieldDescriptor;
|
|
11
|
+
model: object | undefined;
|
|
12
|
+
currentLang: string;
|
|
13
|
+
}, __VLS_30: string, __VLS_31: any, __VLS_39: `field.${string}`, __VLS_40: {
|
|
14
|
+
field: AnyFieldDescriptor;
|
|
15
|
+
model: object | undefined;
|
|
16
|
+
currentLang: string;
|
|
17
|
+
}, __VLS_50: string, __VLS_51: any, __VLS_54: `field.${string}`, __VLS_55: {
|
|
18
|
+
field: AnyFieldDescriptor;
|
|
19
|
+
model: object | undefined;
|
|
20
|
+
currentLang: string;
|
|
21
|
+
}, __VLS_65: string, __VLS_66: any;
|
|
22
|
+
type __VLS_Slots = {} & {
|
|
23
|
+
[K in NonNullable<typeof __VLS_19>]?: (props: typeof __VLS_20) => any;
|
|
24
|
+
} & {
|
|
25
|
+
[K in NonNullable<typeof __VLS_30>]?: (props: typeof __VLS_31) => any;
|
|
26
|
+
} & {
|
|
27
|
+
[K in NonNullable<typeof __VLS_39>]?: (props: typeof __VLS_40) => any;
|
|
28
|
+
} & {
|
|
29
|
+
[K in NonNullable<typeof __VLS_50>]?: (props: typeof __VLS_51) => any;
|
|
30
|
+
} & {
|
|
31
|
+
[K in NonNullable<typeof __VLS_54>]?: (props: typeof __VLS_55) => any;
|
|
32
|
+
} & {
|
|
33
|
+
[K in NonNullable<typeof __VLS_65>]?: (props: typeof __VLS_66) => any;
|
|
34
|
+
};
|
|
35
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
36
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
37
|
+
declare const _default: typeof __VLS_export;
|
|
38
|
+
export default _default;
|
|
39
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
40
|
+
new (): {
|
|
41
|
+
$slots: S;
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=MapoFormGroup.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapoFormGroup.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFormGroup.vue"],"names":[],"mappings":"AAuSA,OAAO,KAAK,EACV,kBAAkB,EAEnB,MAAM,mBAAmB,CAAC;AAI3B,KAAK,WAAW,GAAG;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,kBAAkB,EAAE,CAAC;IAC7B,OAAO,CAAC,EAAE,GAAG,CAAC,MAAM,EAAE,kBAAkB,EAAE,CAAC,CAAC;IAC5C,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAidF,QAAA,IAAI,QAAQ,mBAAW,EAAE,QAAQ;;;;CAAW,EAAE,QAAQ,QAAW,EAAE,QAAQ,KAAW,EAAE,QAAQ,mBAAW,EAAE,QAAQ;;;;CAAW,EAAE,QAAQ,QAAW,EAAE,QAAQ,KAAW,EAAE,QAAQ,mBAAW,EAAE,QAAQ;;;;CAAW,EAAE,QAAQ,QAAW,EAAE,QAAQ,KAAY,CAAE;AACjQ,KAAK,WAAW,GAAG,EAAE,GACnB;KAAG,CAAC,IAAI,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG;CAAE,GACzE;KAAG,CAAC,IAAI,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG;CAAE,GACzE;KAAG,CAAC,IAAI,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG;CAAE,GACzE;KAAG,CAAC,IAAI,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG;CAAE,GACzE;KAAG,CAAC,IAAI,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG;CAAE,GACzE;KAAG,CAAC,IAAI,WAAW,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,QAAQ,KAAK,GAAG;CAAE,CAAC;AAG5E,QAAA,MAAM,UAAU,kSAEd,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"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { ref, computed } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
import { injectMapoForm } from "../composables/useMapoForm.js";
|
|
5
|
+
import MapoFormGroup from "./MapoFormGroup.vue";
|
|
6
|
+
import MapoFormFlatSection from "./MapoFormFlatSection.vue";
|
|
7
|
+
const { t } = useI18n();
|
|
8
|
+
const props = defineProps({
|
|
9
|
+
tabs: { type: Array, required: true }
|
|
10
|
+
});
|
|
11
|
+
defineSlots();
|
|
12
|
+
const activeTab = ref(props.tabs[0]?.name ?? "");
|
|
13
|
+
function tabHasErrors(tab, errorKeys) {
|
|
14
|
+
const directError = [...tab.groups.values()].some(
|
|
15
|
+
(g) => g.fields.some((f) => errorKeys.has(f.key))
|
|
16
|
+
);
|
|
17
|
+
if (directError) return true;
|
|
18
|
+
return [...tab.children.values()].some(
|
|
19
|
+
(child) => tabHasErrors(child, errorKeys)
|
|
20
|
+
);
|
|
21
|
+
}
|
|
22
|
+
const form = injectMapoForm();
|
|
23
|
+
const tabsWithErrors = computed(() => {
|
|
24
|
+
const errorKeys = new Set(Object.keys(form.errors.value));
|
|
25
|
+
return new Set(
|
|
26
|
+
props.tabs.filter((tab) => tabHasErrors(tab, errorKeys)).map((t2) => t2.name)
|
|
27
|
+
);
|
|
28
|
+
});
|
|
29
|
+
</script>
|
|
30
|
+
|
|
31
|
+
<template>
|
|
32
|
+
<div class="mapo-form-tabs">
|
|
33
|
+
<!-- Tab bar -->
|
|
34
|
+
<div class="flex gap-1 border-b border-gray-200 pb-px">
|
|
35
|
+
<button
|
|
36
|
+
v-for="tab in tabs"
|
|
37
|
+
:key="tab.name"
|
|
38
|
+
type="button"
|
|
39
|
+
class="relative flex items-center gap-1.5 rounded-t px-4 py-2 text-sm font-medium transition-colors"
|
|
40
|
+
:class="[
|
|
41
|
+
activeTab === tab.name ? 'border-b-2 border-primary-500 text-primary-600' : 'text-gray-500 hover:bg-gray-50 hover:text-gray-700'
|
|
42
|
+
]"
|
|
43
|
+
@click="activeTab = tab.name"
|
|
44
|
+
>
|
|
45
|
+
<slot :name="`tab.${tab.name}.label`" :tab="tab">
|
|
46
|
+
{{ tab.label ?? tab.name }}
|
|
47
|
+
</slot>
|
|
48
|
+
<span
|
|
49
|
+
v-if="tabsWithErrors.has(tab.name)"
|
|
50
|
+
class="inline-block h-1.5 w-1.5 rounded-full bg-red-500"
|
|
51
|
+
:aria-label="t('mapo.form.tabErrors')"
|
|
52
|
+
/>
|
|
53
|
+
</button>
|
|
54
|
+
<!-- Extra content appended to the tab bar (actions, badges, …). -->
|
|
55
|
+
<slot name="tab-bar-end" />
|
|
56
|
+
</div>
|
|
57
|
+
|
|
58
|
+
<!-- Tab content -->
|
|
59
|
+
<div
|
|
60
|
+
v-for="tab in tabs"
|
|
61
|
+
v-show="activeTab === tab.name"
|
|
62
|
+
:key="tab.name"
|
|
63
|
+
class="space-y-5 pt-5"
|
|
64
|
+
>
|
|
65
|
+
<!-- Full panel override: `tab.{name}` replaces this tab's content entirely. -->
|
|
66
|
+
<slot
|
|
67
|
+
v-if="$slots[`tab.${tab.name}`]"
|
|
68
|
+
:name="`tab.${tab.name}`"
|
|
69
|
+
:tab="tab"
|
|
70
|
+
/>
|
|
71
|
+
<template v-else>
|
|
72
|
+
<slot :name="`tab.${tab.name}.before`" :tab="tab" />
|
|
73
|
+
<!-- Direct groups at this level -->
|
|
74
|
+
<template v-for="[groupName, group] of tab.groups" :key="groupName">
|
|
75
|
+
<template v-if="groupName !== '__flat__'">
|
|
76
|
+
<slot :name="`group.${groupName}.before`" />
|
|
77
|
+
<MapoFormGroup
|
|
78
|
+
:name="groupName"
|
|
79
|
+
:label="group.label"
|
|
80
|
+
:fields="group.fields"
|
|
81
|
+
:subtabs="group.subtabs"
|
|
82
|
+
>
|
|
83
|
+
<template v-for="(_, slotName) in $slots" #[slotName]="slotProps">
|
|
84
|
+
<slot :name="slotName" v-bind="slotProps ?? {}" />
|
|
85
|
+
</template>
|
|
86
|
+
</MapoFormGroup>
|
|
87
|
+
<slot :name="`group.${groupName}.after`" />
|
|
88
|
+
</template>
|
|
89
|
+
|
|
90
|
+
<MapoFormFlatSection v-else :fields="group.fields">
|
|
91
|
+
<template v-for="(_, slotName) in $slots" #[slotName]="slotProps">
|
|
92
|
+
<slot :name="slotName" v-bind="slotProps ?? {}" />
|
|
93
|
+
</template>
|
|
94
|
+
</MapoFormFlatSection>
|
|
95
|
+
</template>
|
|
96
|
+
|
|
97
|
+
<!-- Nested sub-tabs (recursive) -->
|
|
98
|
+
<MapoFormTabs
|
|
99
|
+
v-if="tab.children.size > 0"
|
|
100
|
+
:tabs="[...tab.children.values()]"
|
|
101
|
+
>
|
|
102
|
+
<template v-for="(_, slotName) in $slots" #[slotName]="slotProps">
|
|
103
|
+
<slot :name="slotName" v-bind="slotProps ?? {}" />
|
|
104
|
+
</template>
|
|
105
|
+
</MapoFormTabs>
|
|
106
|
+
<slot :name="`tab.${tab.name}.after`" :tab="tab" />
|
|
107
|
+
</template>
|
|
108
|
+
</div>
|
|
109
|
+
</div>
|
|
110
|
+
</template>
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { TabEntry } from "../types/layout.js";
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
tabs: TabEntry[];
|
|
4
|
+
};
|
|
5
|
+
type __VLS_Slots = Record<string, unknown>;
|
|
6
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
7
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
8
|
+
declare const _default: typeof __VLS_export;
|
|
9
|
+
export default _default;
|
|
10
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
11
|
+
new (): {
|
|
12
|
+
$slots: S;
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=MapoFormTabs.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapoFormTabs.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoFormTabs.vue"],"names":[],"mappings":"AA4HA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAC;AAOnD,KAAK,WAAW,GAAG;IAAE,IAAI,EAAE,QAAQ,EAAE,CAAA;CAAE,CAAC;AAGxC,KAAK,WAAW,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;AAsO3C,QAAA,MAAM,UAAU,kSAEd,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"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref, watch } from "vue";
|
|
3
|
+
const props = defineProps({
|
|
4
|
+
modelValue: { type: null, required: true },
|
|
5
|
+
descriptor: { type: null, required: true },
|
|
6
|
+
errors: { type: Array, required: false },
|
|
7
|
+
readonly: { type: Boolean, required: false },
|
|
8
|
+
disabled: { type: Boolean, required: false }
|
|
9
|
+
});
|
|
10
|
+
const emit = defineEmits(["update:modelValue"]);
|
|
11
|
+
const jsonValue = computed(() => {
|
|
12
|
+
try {
|
|
13
|
+
return JSON.stringify(props.modelValue, null, 2);
|
|
14
|
+
} catch {
|
|
15
|
+
return String(props.modelValue);
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
const draft = ref(jsonValue.value);
|
|
19
|
+
const parseError = ref(null);
|
|
20
|
+
watch(jsonValue, (val) => {
|
|
21
|
+
draft.value = val;
|
|
22
|
+
parseError.value = null;
|
|
23
|
+
});
|
|
24
|
+
function onInput(val) {
|
|
25
|
+
draft.value = String(val);
|
|
26
|
+
try {
|
|
27
|
+
const parsed = JSON.parse(draft.value);
|
|
28
|
+
parseError.value = null;
|
|
29
|
+
emit("update:modelValue", parsed);
|
|
30
|
+
} catch (e) {
|
|
31
|
+
parseError.value = e.message;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
if (import.meta.dev) {
|
|
35
|
+
console.warn(
|
|
36
|
+
`[Mapo] Field type "${props.descriptor.type}" (key: "${props.descriptor.key}") is not in the registry. Rendered as MapoUnknownField.`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<div class="rounded border border-yellow-400 bg-yellow-50 p-3 text-sm">
|
|
43
|
+
<p class="font-mono font-semibold text-yellow-700">
|
|
44
|
+
Unknown field: <code>{{ descriptor.key }}</code>
|
|
45
|
+
<span class="ml-2 text-yellow-500">(type: {{ descriptor.type }})</span>
|
|
46
|
+
</p>
|
|
47
|
+
<UTextarea
|
|
48
|
+
class="mt-2 font-mono text-xs"
|
|
49
|
+
:model-value="draft"
|
|
50
|
+
:rows="4"
|
|
51
|
+
:readonly="readonly || disabled"
|
|
52
|
+
:disabled="disabled"
|
|
53
|
+
@update:model-value="onInput"
|
|
54
|
+
/>
|
|
55
|
+
<p v-if="parseError" class="mt-1 text-xs text-yellow-700">
|
|
56
|
+
Invalid JSON — changes are not applied until the value becomes parseable.
|
|
57
|
+
</p>
|
|
58
|
+
<p v-for="err in errors" :key="err" class="mt-1 text-red-500">
|
|
59
|
+
{{ err }}
|
|
60
|
+
</p>
|
|
61
|
+
</div>
|
|
62
|
+
</template>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AnyFieldDescriptor } from "../types/index.js";
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
modelValue: unknown;
|
|
4
|
+
descriptor: AnyFieldDescriptor;
|
|
5
|
+
errors?: string[];
|
|
6
|
+
readonly?: boolean;
|
|
7
|
+
disabled?: boolean;
|
|
8
|
+
};
|
|
9
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
10
|
+
"update:modelValue": (value: unknown) => any;
|
|
11
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
12
|
+
"onUpdate:modelValue"?: ((value: unknown) => any) | undefined;
|
|
13
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
|
+
declare const _default: typeof __VLS_export;
|
|
15
|
+
export default _default;
|
|
16
|
+
//# sourceMappingURL=MapoUnknownField.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapoUnknownField.vue.d.ts","sourceRoot":"","sources":["../../../src/runtime/components/MapoUnknownField.vue"],"names":[],"mappings":"AA8EA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAE5D,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,kBAAkB,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AA6IF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed, ref } from "vue";
|
|
3
|
+
import { useI18n } from "vue-i18n";
|
|
4
|
+
import { parseDate, CalendarDate } from "@internationalized/date";
|
|
5
|
+
const props = defineProps({
|
|
6
|
+
modelValue: { type: null, required: true },
|
|
7
|
+
descriptor: { type: Object, required: true },
|
|
8
|
+
errors: { type: Array, required: false },
|
|
9
|
+
readonly: { type: Boolean, required: false },
|
|
10
|
+
disabled: { type: Boolean, required: false }
|
|
11
|
+
});
|
|
12
|
+
const emit = defineEmits(["update:modelValue"]);
|
|
13
|
+
const { t } = useI18n();
|
|
14
|
+
const open = ref(false);
|
|
15
|
+
const calendarValue = computed(() => {
|
|
16
|
+
const v = props.modelValue;
|
|
17
|
+
if (!v) return void 0;
|
|
18
|
+
try {
|
|
19
|
+
return parseDate(String(v).split("T")[0]);
|
|
20
|
+
} catch {
|
|
21
|
+
return void 0;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
const displayLabel = computed(() => {
|
|
25
|
+
const v = calendarValue.value;
|
|
26
|
+
if (!v) return t("mapo.dateField.selectDate");
|
|
27
|
+
return `${String(v.day).padStart(2, "0")}/${String(v.month).padStart(2, "0")}/${v.year}`;
|
|
28
|
+
});
|
|
29
|
+
const attrs = computed(() => props.descriptor.attrs ?? {});
|
|
30
|
+
function onDateSelect(date) {
|
|
31
|
+
const d = date;
|
|
32
|
+
open.value = false;
|
|
33
|
+
emit("update:modelValue", d ? d.toString() : null);
|
|
34
|
+
}
|
|
35
|
+
function clear() {
|
|
36
|
+
emit("update:modelValue", null);
|
|
37
|
+
open.value = false;
|
|
38
|
+
}
|
|
39
|
+
</script>
|
|
40
|
+
|
|
41
|
+
<template>
|
|
42
|
+
<UPopover v-model:open="open" :disabled="readonly || disabled">
|
|
43
|
+
<UButton
|
|
44
|
+
variant="outline"
|
|
45
|
+
color="neutral"
|
|
46
|
+
icon="i-lucide-calendar"
|
|
47
|
+
trailing
|
|
48
|
+
class="w-full justify-between font-normal"
|
|
49
|
+
:class="{
|
|
50
|
+
'opacity-50 cursor-not-allowed': readonly || disabled,
|
|
51
|
+
'ring-2 ring-red-500': errors?.length
|
|
52
|
+
}"
|
|
53
|
+
:disabled="readonly || disabled"
|
|
54
|
+
>
|
|
55
|
+
<span
|
|
56
|
+
:class="
|
|
57
|
+
calendarValue ? 'text-gray-900 dark:text-white' : 'text-gray-400'
|
|
58
|
+
"
|
|
59
|
+
>
|
|
60
|
+
{{ displayLabel }}
|
|
61
|
+
</span>
|
|
62
|
+
</UButton>
|
|
63
|
+
|
|
64
|
+
<template #content>
|
|
65
|
+
<div class="p-3 space-y-2">
|
|
66
|
+
<UCalendar
|
|
67
|
+
:model-value="calendarValue"
|
|
68
|
+
:min-value="attrs.min ? parseDate(attrs.min) : void 0"
|
|
69
|
+
:max-value="attrs.max ? parseDate(attrs.max) : void 0"
|
|
70
|
+
@update:model-value="onDateSelect"
|
|
71
|
+
/>
|
|
72
|
+
<div
|
|
73
|
+
class="flex justify-end border-t border-gray-200 dark:border-gray-700 pt-2"
|
|
74
|
+
>
|
|
75
|
+
<UButton
|
|
76
|
+
variant="ghost"
|
|
77
|
+
color="neutral"
|
|
78
|
+
size="xs"
|
|
79
|
+
icon="i-lucide-x"
|
|
80
|
+
@click="clear"
|
|
81
|
+
>
|
|
82
|
+
Clear
|
|
83
|
+
</UButton>
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</template>
|
|
87
|
+
</UPopover>
|
|
88
|
+
</template>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { DateDescriptor } from "../../types/index.js";
|
|
2
|
+
/** Date-only field backed by `UCalendar` and serialised as `YYYY-MM-DD`. */
|
|
3
|
+
type __VLS_Props = {
|
|
4
|
+
modelValue: unknown;
|
|
5
|
+
descriptor: DateDescriptor;
|
|
6
|
+
errors?: string[];
|
|
7
|
+
readonly?: boolean;
|
|
8
|
+
disabled?: boolean;
|
|
9
|
+
};
|
|
10
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
11
|
+
"update:modelValue": (value: string | null) => any;
|
|
12
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
13
|
+
"onUpdate:modelValue"?: ((value: string | null) => any) | undefined;
|
|
14
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
15
|
+
declare const _default: typeof __VLS_export;
|
|
16
|
+
export default _default;
|
|
17
|
+
//# sourceMappingURL=MapoDateField.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapoDateField.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoDateField.vue"],"names":[],"mappings":"AA0GA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAE3D,4EAA4E;AAC5E,KAAK,WAAW,GAAG;IACjB,UAAU,EAAE,OAAO,CAAC;IACpB,UAAU,EAAE,cAAc,CAAC;IAC3B,MAAM,CAAC,EAAE,MAAM,EAAE,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAyMF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|