@mapomodule/form 2.0.0-beta.0 → 2.0.0-beta.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/dist/__tests__/__mocks__/nuxt-imports.d.ts +4 -0
- package/dist/__tests__/__mocks__/nuxt-imports.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 +167 -13
- package/dist/runtime/components/MapoFocusPortal.vue +113 -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 +108 -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 +86 -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 +157 -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/MapoFileField.vue +97 -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 +118 -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 +97 -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/MapoRepeater.vue +449 -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 +341 -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 +118 -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 +227 -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 +142 -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 +323 -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 +27 -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 +87 -0
- package/dist/runtime/types/descriptor.d.ts +359 -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 +11 -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/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 +4 -4
- package/dist/index.d.cts +0 -1
- package/dist/module.d.cts +0 -2
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { watch, onBeforeUnmount } from "vue";
|
|
3
|
+
import { useEditor, EditorContent } from "@tiptap/vue-3";
|
|
4
|
+
import StarterKit from "@tiptap/starter-kit";
|
|
5
|
+
import Link from "@tiptap/extension-link";
|
|
6
|
+
import Underline from "@tiptap/extension-underline";
|
|
7
|
+
const props = defineProps({
|
|
8
|
+
modelValue: { type: null, required: true },
|
|
9
|
+
descriptor: { type: Object, required: true },
|
|
10
|
+
errors: { type: Array, required: false },
|
|
11
|
+
readonly: { type: Boolean, required: false },
|
|
12
|
+
disabled: { type: Boolean, required: false }
|
|
13
|
+
});
|
|
14
|
+
const emit = defineEmits(["update:modelValue"]);
|
|
15
|
+
const extraExtensions = props.descriptor.attrs?.extensions ?? [];
|
|
16
|
+
const ALLOWED_LINK_PROTOCOLS = ["http", "https", "mailto", "tel"];
|
|
17
|
+
function isSafeUrl(url) {
|
|
18
|
+
try {
|
|
19
|
+
if (!/^[a-z][a-z0-9+.-]*:/i.test(url)) return true;
|
|
20
|
+
const proto = new URL(url, "https://placeholder.local").protocol.replace(":", "").toLowerCase();
|
|
21
|
+
return ALLOWED_LINK_PROTOCOLS.includes(proto);
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function sanitizeHtml(html) {
|
|
27
|
+
if (typeof window === "undefined" || !html) return html;
|
|
28
|
+
const tpl = document.createElement("template");
|
|
29
|
+
tpl.innerHTML = html;
|
|
30
|
+
const walker = document.createTreeWalker(
|
|
31
|
+
tpl.content,
|
|
32
|
+
NodeFilter.SHOW_ELEMENT
|
|
33
|
+
);
|
|
34
|
+
const toRemove = [];
|
|
35
|
+
let node = walker.nextNode();
|
|
36
|
+
while (node) {
|
|
37
|
+
if (node.tagName === "SCRIPT" || node.tagName === "STYLE") {
|
|
38
|
+
toRemove.push(node);
|
|
39
|
+
} else {
|
|
40
|
+
for (const attr of Array.from(node.attributes)) {
|
|
41
|
+
const name = attr.name.toLowerCase();
|
|
42
|
+
if (name.startsWith("on")) node.removeAttribute(attr.name);
|
|
43
|
+
if ((name === "href" || name === "src" || name === "xlink:href") && !isSafeUrl(attr.value)) {
|
|
44
|
+
node.removeAttribute(attr.name);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
node = walker.nextNode();
|
|
49
|
+
}
|
|
50
|
+
toRemove.forEach((el) => el.remove());
|
|
51
|
+
return tpl.innerHTML;
|
|
52
|
+
}
|
|
53
|
+
const editor = useEditor({
|
|
54
|
+
content: sanitizeHtml(props.modelValue ?? ""),
|
|
55
|
+
editable: !props.readonly && !props.disabled,
|
|
56
|
+
extensions: [
|
|
57
|
+
StarterKit,
|
|
58
|
+
Link.configure({
|
|
59
|
+
openOnClick: false,
|
|
60
|
+
protocols: ALLOWED_LINK_PROTOCOLS,
|
|
61
|
+
validate: (href) => isSafeUrl(href)
|
|
62
|
+
}),
|
|
63
|
+
Underline,
|
|
64
|
+
...extraExtensions
|
|
65
|
+
],
|
|
66
|
+
onUpdate: ({ editor: e }) => {
|
|
67
|
+
emit("update:modelValue", e.getHTML());
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
watch(
|
|
71
|
+
() => [props.readonly, props.disabled],
|
|
72
|
+
([ro, dis]) => editor.value?.setEditable(!ro && !dis)
|
|
73
|
+
);
|
|
74
|
+
watch(
|
|
75
|
+
() => props.modelValue,
|
|
76
|
+
(val) => {
|
|
77
|
+
if (editor.value && val !== editor.value.getHTML()) {
|
|
78
|
+
editor.value.commands.setContent(
|
|
79
|
+
sanitizeHtml(val ?? ""),
|
|
80
|
+
false
|
|
81
|
+
);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
);
|
|
85
|
+
onBeforeUnmount(() => editor.value?.destroy());
|
|
86
|
+
</script>
|
|
87
|
+
|
|
88
|
+
<template>
|
|
89
|
+
<div
|
|
90
|
+
class="mapo-wyg-editor rounded border"
|
|
91
|
+
:class="[
|
|
92
|
+
errors?.length ? 'border-red-300' : 'border-gray-200',
|
|
93
|
+
readonly || disabled ? 'opacity-60' : ''
|
|
94
|
+
]"
|
|
95
|
+
>
|
|
96
|
+
<!-- Toolbar -->
|
|
97
|
+
<div
|
|
98
|
+
v-if="editor"
|
|
99
|
+
class="flex flex-wrap gap-1 border-b border-gray-200 bg-gray-50 px-2 py-1.5"
|
|
100
|
+
>
|
|
101
|
+
<UButton
|
|
102
|
+
size="xs"
|
|
103
|
+
variant="ghost"
|
|
104
|
+
color="neutral"
|
|
105
|
+
:disabled="readonly || disabled"
|
|
106
|
+
:class="{ 'bg-gray-200': editor.isActive('bold') }"
|
|
107
|
+
@click="editor.chain().focus().toggleBold().run()"
|
|
108
|
+
>
|
|
109
|
+
<strong>B</strong>
|
|
110
|
+
</UButton>
|
|
111
|
+
<UButton
|
|
112
|
+
size="xs"
|
|
113
|
+
variant="ghost"
|
|
114
|
+
color="neutral"
|
|
115
|
+
:disabled="readonly || disabled"
|
|
116
|
+
:class="{ 'bg-gray-200': editor.isActive('italic') }"
|
|
117
|
+
@click="editor.chain().focus().toggleItalic().run()"
|
|
118
|
+
>
|
|
119
|
+
<em>I</em>
|
|
120
|
+
</UButton>
|
|
121
|
+
<UButton
|
|
122
|
+
size="xs"
|
|
123
|
+
variant="ghost"
|
|
124
|
+
color="neutral"
|
|
125
|
+
:disabled="readonly || disabled"
|
|
126
|
+
:class="{ 'bg-gray-200': editor.isActive('underline') }"
|
|
127
|
+
@click="editor.chain().focus().toggleUnderline().run()"
|
|
128
|
+
>
|
|
129
|
+
<span class="underline">U</span>
|
|
130
|
+
</UButton>
|
|
131
|
+
|
|
132
|
+
<USeparator orientation="vertical" class="mx-1 h-5" />
|
|
133
|
+
|
|
134
|
+
<UButton
|
|
135
|
+
size="xs"
|
|
136
|
+
variant="ghost"
|
|
137
|
+
color="neutral"
|
|
138
|
+
:disabled="readonly || disabled"
|
|
139
|
+
:class="{ 'bg-gray-200': editor.isActive('heading', { level: 2 }) }"
|
|
140
|
+
@click="editor.chain().focus().toggleHeading({ level: 2 }).run()"
|
|
141
|
+
>
|
|
142
|
+
H2
|
|
143
|
+
</UButton>
|
|
144
|
+
<UButton
|
|
145
|
+
size="xs"
|
|
146
|
+
variant="ghost"
|
|
147
|
+
color="neutral"
|
|
148
|
+
:disabled="readonly || disabled"
|
|
149
|
+
:class="{ 'bg-gray-200': editor.isActive('heading', { level: 3 }) }"
|
|
150
|
+
@click="editor.chain().focus().toggleHeading({ level: 3 }).run()"
|
|
151
|
+
>
|
|
152
|
+
H3
|
|
153
|
+
</UButton>
|
|
154
|
+
|
|
155
|
+
<USeparator orientation="vertical" class="mx-1 h-5" />
|
|
156
|
+
|
|
157
|
+
<UButton
|
|
158
|
+
size="xs"
|
|
159
|
+
variant="ghost"
|
|
160
|
+
color="neutral"
|
|
161
|
+
:disabled="readonly || disabled"
|
|
162
|
+
:class="{ 'bg-gray-200': editor.isActive('bulletList') }"
|
|
163
|
+
icon="i-lucide-list"
|
|
164
|
+
@click="editor.chain().focus().toggleBulletList().run()"
|
|
165
|
+
/>
|
|
166
|
+
<UButton
|
|
167
|
+
size="xs"
|
|
168
|
+
variant="ghost"
|
|
169
|
+
color="neutral"
|
|
170
|
+
:disabled="readonly || disabled"
|
|
171
|
+
:class="{ 'bg-gray-200': editor.isActive('orderedList') }"
|
|
172
|
+
icon="i-lucide-list-ordered"
|
|
173
|
+
@click="editor.chain().focus().toggleOrderedList().run()"
|
|
174
|
+
/>
|
|
175
|
+
|
|
176
|
+
<USeparator orientation="vertical" class="mx-1 h-5" />
|
|
177
|
+
|
|
178
|
+
<UButton
|
|
179
|
+
size="xs"
|
|
180
|
+
variant="ghost"
|
|
181
|
+
color="neutral"
|
|
182
|
+
:disabled="readonly || disabled"
|
|
183
|
+
icon="i-lucide-undo"
|
|
184
|
+
@click="editor.chain().focus().undo().run()"
|
|
185
|
+
/>
|
|
186
|
+
<UButton
|
|
187
|
+
size="xs"
|
|
188
|
+
variant="ghost"
|
|
189
|
+
color="neutral"
|
|
190
|
+
:disabled="readonly || disabled"
|
|
191
|
+
icon="i-lucide-redo"
|
|
192
|
+
@click="editor.chain().focus().redo().run()"
|
|
193
|
+
/>
|
|
194
|
+
|
|
195
|
+
<USeparator orientation="vertical" class="mx-1 h-5" />
|
|
196
|
+
|
|
197
|
+
<!-- Insert Image — enabled in Phase 6 when Media Manager is available -->
|
|
198
|
+
<UTooltip
|
|
199
|
+
text="Insert image (requires Media Manager — Phase 6)"
|
|
200
|
+
:delay-open="300"
|
|
201
|
+
>
|
|
202
|
+
<UButton
|
|
203
|
+
size="xs"
|
|
204
|
+
variant="ghost"
|
|
205
|
+
color="neutral"
|
|
206
|
+
icon="i-lucide-image"
|
|
207
|
+
disabled
|
|
208
|
+
/>
|
|
209
|
+
</UTooltip>
|
|
210
|
+
</div>
|
|
211
|
+
|
|
212
|
+
<!-- Contenuto editor -->
|
|
213
|
+
<EditorContent
|
|
214
|
+
:editor="editor"
|
|
215
|
+
class="prose prose-sm max-w-none px-3 py-2 focus-within:outline-none"
|
|
216
|
+
/>
|
|
217
|
+
|
|
218
|
+
<p
|
|
219
|
+
v-for="err in errors"
|
|
220
|
+
:key="err"
|
|
221
|
+
class="px-3 pb-2 text-sm text-red-500"
|
|
222
|
+
role="alert"
|
|
223
|
+
>
|
|
224
|
+
{{ err }}
|
|
225
|
+
</p>
|
|
226
|
+
</div>
|
|
227
|
+
</template>
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { EditorDescriptor } from "../../types/index.js";
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
modelValue: unknown;
|
|
4
|
+
descriptor: EditorDescriptor;
|
|
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: string) => any;
|
|
11
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
12
|
+
"onUpdate:modelValue"?: ((value: string) => any) | undefined;
|
|
13
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
|
+
declare const _default: typeof __VLS_export;
|
|
15
|
+
export default _default;
|
|
16
|
+
//# sourceMappingURL=MapoWygEditor.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MapoWygEditor.vue.d.ts","sourceRoot":"","sources":["../../../../src/runtime/components/fields/MapoWygEditor.vue"],"names":[],"mappings":"AAyQA,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;AAilBF,QAAA,MAAM,YAAY;;;;kFAGhB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
4
|
+
//# sourceMappingURL=NuiCheckbox.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NuiCheckbox.vue.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/components/fields/nui/NuiCheckbox.vue"],"names":[],"mappings":"AA6CA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
4
|
+
//# sourceMappingURL=NuiInput.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NuiInput.vue.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/components/fields/nui/NuiInput.vue"],"names":[],"mappings":"AA6CA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { useNuiFieldAttrs } from "./useNuiFieldAttrs";
|
|
4
|
+
defineOptions({ inheritAttrs: false });
|
|
5
|
+
const rawAttrs = useNuiFieldAttrs();
|
|
6
|
+
const attrs = computed(() => {
|
|
7
|
+
const { options, items, ...rest } = rawAttrs.value;
|
|
8
|
+
const list = items ?? options;
|
|
9
|
+
const normalised = list?.map(
|
|
10
|
+
(it) => typeof it === "object" && it !== null ? { ...it, text: it.text ?? it.label ?? String(it.value) } : it
|
|
11
|
+
);
|
|
12
|
+
return { ...rest, items: normalised };
|
|
13
|
+
});
|
|
14
|
+
</script>
|
|
15
|
+
|
|
16
|
+
<template>
|
|
17
|
+
<USelectMenu v-bind="attrs" />
|
|
18
|
+
</template>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
4
|
+
//# sourceMappingURL=NuiSelectMenu.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NuiSelectMenu.vue.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/components/fields/nui/NuiSelectMenu.vue"],"names":[],"mappings":"AAmFA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
4
|
+
//# sourceMappingURL=NuiSlider.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NuiSlider.vue.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/components/fields/nui/NuiSlider.vue"],"names":[],"mappings":"AA6CA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
4
|
+
//# sourceMappingURL=NuiSwitch.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NuiSwitch.vue.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/components/fields/nui/NuiSwitch.vue"],"names":[],"mappings":"AA6CA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
declare const __VLS_export: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
2
|
+
declare const _default: typeof __VLS_export;
|
|
3
|
+
export default _default;
|
|
4
|
+
//# sourceMappingURL=NuiTextarea.vue.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NuiTextarea.vue.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/components/fields/nui/NuiTextarea.vue"],"names":[],"mappings":"AA6CA,QAAA,MAAM,YAAY,+QAChB,CAAC;wBACkB,OAAO,YAAY;AAAxC,wBAAyC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type ComputedRef } from "vue";
|
|
2
|
+
/**
|
|
3
|
+
* Shared logic for NUI wrappers: strips internal props (`descriptor`, `errors`)
|
|
4
|
+
* from the binding passed to the underlying NUI component and derives visual
|
|
5
|
+
* error flags (`color: 'error'` + `aria-invalid`).
|
|
6
|
+
*
|
|
7
|
+
* Note: NUI v3 form components accept `color="error"` for the red border.
|
|
8
|
+
* We apply it here as a fallback when the caller has not set it already,
|
|
9
|
+
* so consumers that do not go through `MapoFormField` still get the correct
|
|
10
|
+
* color when `errors` is non-empty.
|
|
11
|
+
*/
|
|
12
|
+
export declare function useNuiFieldAttrs(): ComputedRef<Record<string, unknown>>;
|
|
13
|
+
//# sourceMappingURL=useNuiFieldAttrs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useNuiFieldAttrs.d.ts","sourceRoot":"","sources":["../../../../../src/runtime/components/fields/nui/useNuiFieldAttrs.ts"],"names":[],"mappings":"AAAA,OAAO,EAAsB,KAAK,WAAW,EAAE,MAAM,KAAK,CAAC;AAE3D;;;;;;;;;GASG;AACH,wBAAgB,gBAAgB,IAAI,WAAW,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAiBvE"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { computed, useAttrs } from "vue";
|
|
2
|
+
export function useNuiFieldAttrs() {
|
|
3
|
+
const rawAttrs = useAttrs();
|
|
4
|
+
return computed(() => {
|
|
5
|
+
const {
|
|
6
|
+
descriptor: _d,
|
|
7
|
+
errors,
|
|
8
|
+
color,
|
|
9
|
+
...rest
|
|
10
|
+
} = rawAttrs;
|
|
11
|
+
const errs = errors ?? [];
|
|
12
|
+
const hasError = errs.length > 0;
|
|
13
|
+
return {
|
|
14
|
+
...rest,
|
|
15
|
+
color: color ?? (hasError ? "error" : void 0),
|
|
16
|
+
"aria-invalid": hasError ? "true" : void 0
|
|
17
|
+
};
|
|
18
|
+
});
|
|
19
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FieldComponentEntry, FieldAccessor } from "../types/index.js";
|
|
2
|
+
/** Options for registering or overriding a custom field type. */
|
|
3
|
+
export interface DefineFormFieldOptions {
|
|
4
|
+
/** Default attrs applied to all descriptors of this `type`. */
|
|
5
|
+
attrs?: Record<string, unknown>;
|
|
6
|
+
/** Default get/set accessor for this `type`. */
|
|
7
|
+
accessor?: FieldAccessor;
|
|
8
|
+
/** Replaces an existing registration without warning. */
|
|
9
|
+
override?: boolean;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Typed API for registering a custom field component.
|
|
13
|
+
* Must be called from a Nuxt plugin (the load order guarantees that `$mapoFormRegistry`
|
|
14
|
+
* is already present — the `@mapomodule/form` plugin is loaded first).
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* // app/plugins/my-fields.ts
|
|
18
|
+
* export default defineNuxtPlugin(() => {
|
|
19
|
+
* defineFormField('rich-text', () => import('~/components/RichText.vue'), {
|
|
20
|
+
* attrs: { rows: 6 },
|
|
21
|
+
* })
|
|
22
|
+
* })
|
|
23
|
+
*/
|
|
24
|
+
export declare function defineFormField(type: string, entry: FieldComponentEntry, opts?: DefineFormFieldOptions): void;
|
|
25
|
+
//# sourceMappingURL=defineFormField.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defineFormField.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/defineFormField.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,mBAAmB,EACnB,aAAa,EAEd,MAAM,mBAAmB,CAAC;AAE3B,iEAAiE;AACjE,MAAM,WAAW,sBAAsB;IACrC,+DAA+D;IAC/D,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAChC,gDAAgD;IAChD,QAAQ,CAAC,EAAE,aAAa,CAAC;IACzB,yDAAyD;IACzD,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,eAAe,CAC7B,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,mBAAmB,EAC1B,IAAI,GAAE,sBAA2B,GAChC,IAAI,CA2BN"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { useNuxtApp } from "#app";
|
|
2
|
+
export function defineFormField(type, entry, opts = {}) {
|
|
3
|
+
const nuxt = useNuxtApp();
|
|
4
|
+
const registry = nuxt.$mapoFormRegistry;
|
|
5
|
+
if (!registry) {
|
|
6
|
+
if (import.meta.dev) {
|
|
7
|
+
console.warn(
|
|
8
|
+
`[Mapo] defineFormField('${type}') called before $mapoFormRegistry is available. Make sure the plugin is loaded after @mapomodule/form.`
|
|
9
|
+
);
|
|
10
|
+
}
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
if (registry.mapping[type] && !opts.override) {
|
|
14
|
+
if (import.meta.dev) {
|
|
15
|
+
console.warn(
|
|
16
|
+
`[Mapo] defineFormField: type "${type}" already registered. Pass { override: true } to replace it intentionally.`
|
|
17
|
+
);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
registry.mapping[type] = entry;
|
|
21
|
+
if (opts.attrs) {
|
|
22
|
+
registry.attrs[type] = { ...registry.attrs[type] ?? {}, ...opts.attrs };
|
|
23
|
+
}
|
|
24
|
+
if (opts.accessor) {
|
|
25
|
+
registry.accessor[type] = opts.accessor;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type Ref } from "vue";
|
|
2
|
+
/** Provides the current form language to descendant components. */
|
|
3
|
+
export declare function provideCurrentLang(lang: Ref<string>): void;
|
|
4
|
+
/** Returns the current form language, falling back to the provided ref when needed. */
|
|
5
|
+
export declare function useCurrentLang(fallback?: Ref<string>): Ref<string>;
|
|
6
|
+
//# sourceMappingURL=useCurrentLang.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useCurrentLang.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useCurrentLang.ts"],"names":[],"mappings":"AAAA,OAAO,EAA4C,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAIzE,mEAAmE;AACnE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,GAAG,CAAC,MAAM,CAAC,QAEnD;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,CAKlE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { getCurrentInstance, inject, provide, ref } from "vue";
|
|
2
|
+
const LANG_KEY = Symbol("mapoCurrentLang");
|
|
3
|
+
export function provideCurrentLang(lang) {
|
|
4
|
+
provide(LANG_KEY, lang);
|
|
5
|
+
}
|
|
6
|
+
export function useCurrentLang(fallback) {
|
|
7
|
+
if (!getCurrentInstance()) return fallback ?? ref("");
|
|
8
|
+
return inject(LANG_KEY, fallback ?? ref(""));
|
|
9
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type Ref, type DeepReadonly, type ShallowRef } from "vue";
|
|
2
|
+
import type { AnyFieldDescriptor, FieldRegistry } from "../types/index.js";
|
|
3
|
+
/** Describes the currently focused repeater item in focus mode. */
|
|
4
|
+
export interface FocusTarget {
|
|
5
|
+
/** Descriptor of the repeater field that contains the focused item. */
|
|
6
|
+
descriptor: AnyFieldDescriptor;
|
|
7
|
+
/** Fields for the focused item, resolved from the template when needed. */
|
|
8
|
+
fields: AnyFieldDescriptor[];
|
|
9
|
+
/**
|
|
10
|
+
* Initial snapshot of the item model at the time the portal was opened.
|
|
11
|
+
* Stored as a plain object (not a Ref) to avoid Vue's auto-unwrap behaviour
|
|
12
|
+
* when placed inside Nuxt's useState reactive container.
|
|
13
|
+
*/
|
|
14
|
+
model: Record<string, unknown>;
|
|
15
|
+
/** Errors for this item (already filtered). */
|
|
16
|
+
errors: Ref<Record<string, string[]>>;
|
|
17
|
+
/** Callback invoked when the item model is updated. */
|
|
18
|
+
onUpdate: (val: Record<string, unknown>) => void;
|
|
19
|
+
/** Field component registry passed to the sub-form. */
|
|
20
|
+
registry: FieldRegistry;
|
|
21
|
+
/** Available language codes. */
|
|
22
|
+
languages: string[];
|
|
23
|
+
/** Currently active language code. */
|
|
24
|
+
currentLang: string;
|
|
25
|
+
/** Visual breadcrumb trail: ['Article', 'Blocks', 'Block 3'] */
|
|
26
|
+
breadcrumb: string[];
|
|
27
|
+
}
|
|
28
|
+
/** Shared focus-mode API used by nested repeater editors. */
|
|
29
|
+
export interface FocusModeReturn {
|
|
30
|
+
focusTarget: DeepReadonly<ShallowRef<FocusTarget | null>>;
|
|
31
|
+
isActive: Ref<boolean>;
|
|
32
|
+
enter: (target: FocusTarget) => void;
|
|
33
|
+
exit: () => void;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Exposes a shared focus-mode state for nested repeater items.
|
|
37
|
+
* In Nuxt it uses `useState()` for SSR-safe request isolation.
|
|
38
|
+
*/
|
|
39
|
+
export declare function useFocusMode(): FocusModeReturn;
|
|
40
|
+
//# sourceMappingURL=useFocusMode.d.ts.map
|
|
@@ -0,0 +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,EAAE,kBAAkB,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAE3E,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,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"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import {
|
|
2
|
+
computed,
|
|
3
|
+
readonly,
|
|
4
|
+
shallowRef
|
|
5
|
+
} from "vue";
|
|
6
|
+
const _clientFallback = shallowRef(null);
|
|
7
|
+
function getStateRef() {
|
|
8
|
+
const nuxtUseState = globalThis.useState;
|
|
9
|
+
if (typeof nuxtUseState === "function") {
|
|
10
|
+
return nuxtUseState(
|
|
11
|
+
"mapo:form:focusTarget",
|
|
12
|
+
() => null
|
|
13
|
+
);
|
|
14
|
+
}
|
|
15
|
+
return _clientFallback;
|
|
16
|
+
}
|
|
17
|
+
export function useFocusMode() {
|
|
18
|
+
const state = getStateRef();
|
|
19
|
+
function enter(target) {
|
|
20
|
+
state.value = target;
|
|
21
|
+
}
|
|
22
|
+
function exit() {
|
|
23
|
+
state.value = null;
|
|
24
|
+
}
|
|
25
|
+
return {
|
|
26
|
+
focusTarget: readonly(state),
|
|
27
|
+
isActive: computed(() => state.value !== null),
|
|
28
|
+
enter,
|
|
29
|
+
exit
|
|
30
|
+
};
|
|
31
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { type Ref } from "vue";
|
|
2
|
+
interface DraftEntry<T> {
|
|
3
|
+
model: T;
|
|
4
|
+
savedAt: number;
|
|
5
|
+
}
|
|
6
|
+
/** Options for draft persistence and restoration. */
|
|
7
|
+
export interface UseFormDraftOptions<T> {
|
|
8
|
+
model: Ref<T>;
|
|
9
|
+
isDirty: Ref<boolean>;
|
|
10
|
+
/**
|
|
11
|
+
* Unique draft key. It is prefixed with `mapo:draft:{userId}:` when `userId` is provided,
|
|
12
|
+
* otherwise `mapo:draft:`. Example: `article:42` → `mapo:draft:1:article:42`.
|
|
13
|
+
*/
|
|
14
|
+
key: string;
|
|
15
|
+
/**
|
|
16
|
+
* User identifier used to scope the draft so it is never shared across accounts.
|
|
17
|
+
* Without this, a draft survives logout and may be seen by the next user on the same browser.
|
|
18
|
+
* Pass `useAuthStore().user?.id` (or equivalent) from the calling composable.
|
|
19
|
+
*/
|
|
20
|
+
userId?: string | number;
|
|
21
|
+
/** Milliseconds between debounced writes to localStorage. Default: `2000`. */
|
|
22
|
+
debounce?: number;
|
|
23
|
+
/** TTL in milliseconds before the draft is discarded. Default: `86_400_000` (24h). */
|
|
24
|
+
ttl?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Called on mount when a valid, non-expired draft exists.
|
|
27
|
+
* Show a notification here and decide whether to restore it.
|
|
28
|
+
*/
|
|
29
|
+
onRestore?: (draft: T, savedAt: Date) => void;
|
|
30
|
+
/** Called after each successful write to localStorage. */
|
|
31
|
+
onSave?: (savedAt: Date) => void;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Persists form drafts to `localStorage` and restores them on mount when available.
|
|
35
|
+
*
|
|
36
|
+
* The draft is written debounced while `isDirty` is `true`. On mount, if a valid
|
|
37
|
+
* non-expired draft is found, `onRestore` is called so the caller can decide
|
|
38
|
+
* whether to apply it (e.g. show a snack notification first).
|
|
39
|
+
*
|
|
40
|
+
* @param options - Configuration for key, TTL, debounce interval and lifecycle callbacks.
|
|
41
|
+
* @returns An object with `{ clearDraft, getDraft, hasDraft }` for manual control.
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* useFormDraft({
|
|
45
|
+
* model,
|
|
46
|
+
* isDirty,
|
|
47
|
+
* key: `article:${route.params.id}`,
|
|
48
|
+
* onRestore: (draft, savedAt) => {
|
|
49
|
+
* snack.show(`Draft from ${savedAt.toLocaleString()} restored`)
|
|
50
|
+
* Object.assign(model.value, draft)
|
|
51
|
+
* },
|
|
52
|
+
* })
|
|
53
|
+
*/
|
|
54
|
+
export declare function useFormDraft<T>(options: UseFormDraftOptions<T>): {
|
|
55
|
+
clearDraft: () => void;
|
|
56
|
+
getDraft: () => DraftEntry<T> | null;
|
|
57
|
+
hasDraft: () => boolean;
|
|
58
|
+
};
|
|
59
|
+
export {};
|
|
60
|
+
//# sourceMappingURL=useFormDraft.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useFormDraft.d.ts","sourceRoot":"","sources":["../../../src/runtime/composables/useFormDraft.ts"],"names":[],"mappings":"AAAA,OAAO,EAAiC,KAAK,GAAG,EAAE,MAAM,KAAK,CAAC;AAG9D,UAAU,UAAU,CAAC,CAAC;IACpB,KAAK,EAAE,CAAC,CAAC;IACT,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,qDAAqD;AACrD,MAAM,WAAW,mBAAmB,CAAC,CAAC;IACpC,KAAK,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC;IACd,OAAO,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;IACtB;;;OAGG;IACH,GAAG,EAAE,MAAM,CAAC;IACZ;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,8EAA8E;IAC9E,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,sFAAsF;IACtF,GAAG,CAAC,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,SAAS,CAAC,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,KAAK,IAAI,CAAC;IAC9C,0DAA0D;IAC1D,MAAM,CAAC,EAAE,CAAC,OAAO,EAAE,IAAI,KAAK,IAAI,CAAC;CAClC;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,mBAAmB,CAAC,CAAC,CAAC;;oBAmCxC,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI;oBAqBpB,OAAO;EAK7B"}
|