nuxt-ui-tools 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +8 -1
  3. package/dist/runtime/form/components/actions/form-actions.vue +13 -127
  4. package/dist/runtime/form/components/page/form-page-actions.d.vue.ts +3 -0
  5. package/dist/runtime/form/components/page/form-page-actions.vue +40 -0
  6. package/dist/runtime/form/components/page/form-page-actions.vue.d.ts +3 -0
  7. package/dist/runtime/form/components/page/form-page-header.d.vue.ts +24 -0
  8. package/dist/runtime/form/components/page/form-page-header.vue +99 -0
  9. package/dist/runtime/form/components/page/form-page-header.vue.d.ts +24 -0
  10. package/dist/runtime/form/components/page/form-page-navigation.d.vue.ts +34 -0
  11. package/dist/runtime/form/components/page/form-page-navigation.vue +229 -0
  12. package/dist/runtime/form/components/page/form-page-navigation.vue.d.ts +34 -0
  13. package/dist/runtime/form/components/page/form-page-section.d.vue.ts +19 -0
  14. package/dist/runtime/form/components/page/form-page-section.vue +114 -0
  15. package/dist/runtime/form/components/page/form-page-section.vue.d.ts +19 -0
  16. package/dist/runtime/form/components/page/form-page-sections.d.vue.ts +21 -0
  17. package/dist/runtime/form/components/page/form-page-sections.vue +75 -0
  18. package/dist/runtime/form/components/page/form-page-sections.vue.d.ts +21 -0
  19. package/dist/runtime/form/components/page/form-page.d.vue.ts +80 -0
  20. package/dist/runtime/form/components/page/form-page.vue +91 -0
  21. package/dist/runtime/form/components/page/form-page.vue.d.ts +80 -0
  22. package/dist/runtime/form/components/renderer/form-field-shell.vue +7 -11
  23. package/dist/runtime/form/components/root/form.vue +25 -194
  24. package/dist/runtime/form/composables/use-form-action-buttons.d.ts +32 -0
  25. package/dist/runtime/form/composables/use-form-action-buttons.js +89 -0
  26. package/dist/runtime/form/composables/use-form-actions.d.ts +8 -5
  27. package/dist/runtime/form/composables/use-form-actions.js +1 -1
  28. package/dist/runtime/form/composables/use-form-page-scroll.d.ts +22 -0
  29. package/dist/runtime/form/composables/use-form-page-scroll.js +178 -0
  30. package/dist/runtime/form/composables/use-form-page.d.ts +114 -0
  31. package/dist/runtime/form/composables/use-form-page.js +83 -0
  32. package/dist/runtime/form/composables/use-form-root.d.ts +34 -0
  33. package/dist/runtime/form/composables/use-form-root.js +171 -0
  34. package/dist/runtime/form/composables/use-form-runtime.js +13 -4
  35. package/dist/runtime/form/composables/use-form.js +2 -22
  36. package/dist/runtime/form/fields/checkbox-card/component.vue +28 -19
  37. package/dist/runtime/form/fields/checkbox-card/types.d.ts +2 -5
  38. package/dist/runtime/form/fields/choice-card/choice-card-label.d.vue.ts +17 -0
  39. package/dist/runtime/form/fields/choice-card/choice-card-label.vue +50 -0
  40. package/dist/runtime/form/fields/choice-card/choice-card-label.vue.d.ts +17 -0
  41. package/dist/runtime/form/fields/choice-card/types.d.ts +31 -0
  42. package/dist/runtime/form/fields/choice-card/types.js +0 -0
  43. package/dist/runtime/form/fields/choice-card/use-choice-card.d.ts +22 -0
  44. package/dist/runtime/form/fields/choice-card/use-choice-card.js +52 -0
  45. package/dist/runtime/form/fields/radio-card/component.vue +17 -18
  46. package/dist/runtime/form/fields/radio-card/types.d.ts +2 -4
  47. package/dist/runtime/form/index.d.ts +1 -1
  48. package/dist/runtime/form/index.js +7 -1
  49. package/dist/runtime/form/schema/index.d.ts +1 -1
  50. package/dist/runtime/form/schema/index.js +1 -0
  51. package/dist/runtime/form/schema/page.d.ts +50 -0
  52. package/dist/runtime/form/schema/page.js +25 -0
  53. package/dist/runtime/form/types/index.d.ts +1 -0
  54. package/dist/runtime/form/types/page.d.ts +172 -0
  55. package/dist/runtime/form/types/page.js +0 -0
  56. package/dist/runtime/form/types/ui.d.ts +60 -0
  57. package/dist/runtime/form/utils/controls.d.ts +15 -0
  58. package/dist/runtime/form/utils/controls.js +38 -0
  59. package/dist/runtime/form/utils/layout.js +3 -1
  60. package/dist/runtime/form/utils/page.d.ts +20 -0
  61. package/dist/runtime/form/utils/page.js +107 -0
  62. package/dist/runtime/form/utils/state.d.ts +2 -0
  63. package/dist/runtime/form/utils/state.js +1 -1
  64. package/dist/runtime/form/utils/ui.js +1 -0
  65. package/dist/runtime/i18n/locales/en.js +18 -0
  66. package/dist/runtime/i18n/locales/fr.js +18 -0
  67. package/dist/runtime/i18n/types.d.ts +29 -0
  68. package/package.json +1 -1
@@ -0,0 +1,34 @@
1
+ import type { FormPageSectionState } from '../../types/index.js';
2
+ /**
3
+ * Navigation of a form page: one entry per visible section, following the section in view.
4
+ * An entry shows whether its section is complete, invalid, or still to fill, marks optional
5
+ * sections, and, with `controls.dirtyCheck`, a dot on modified sections. The footer sums up
6
+ * the sections left to complete, or the modified ones with dirty checking.
7
+ *
8
+ * From 768px of page width it is a pinned column; below, a row of chips that scrolls sideways.
9
+ */
10
+ type __VLS_Slots = {
11
+ /** Replaces the heading, which comes from the schema `navigation.title`. */
12
+ title?: () => unknown;
13
+ /** Replaces an entry. Call `select` to scroll to the section. */
14
+ item?: (props: {
15
+ section: FormPageSectionState;
16
+ active: boolean;
17
+ select: () => void;
18
+ }) => unknown;
19
+ /** Replaces the summary under the entries. */
20
+ footer?: (props: {
21
+ sections: readonly FormPageSectionState[];
22
+ remaining: number;
23
+ modified: number;
24
+ }) => unknown;
25
+ };
26
+ declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
27
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
28
+ declare const _default: typeof __VLS_export;
29
+ export default _default;
30
+ type __VLS_WithSlots<T, S> = T & {
31
+ new (): {
32
+ $slots: S;
33
+ };
34
+ };
@@ -0,0 +1,19 @@
1
+ import type { FormPageSectionEntry, FormPageSectionState } from '../../types/index.js';
2
+ type __VLS_Props = {
3
+ entry: FormPageSectionEntry;
4
+ section: FormPageSectionState;
5
+ };
6
+ type __VLS_Slots = {
7
+ actions?: (props: {
8
+ section: FormPageSectionState;
9
+ }) => unknown;
10
+ };
11
+ 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>;
12
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
13
+ declare const _default: typeof __VLS_export;
14
+ export default _default;
15
+ type __VLS_WithSlots<T, S> = T & {
16
+ new (): {
17
+ $slots: S;
18
+ };
19
+ };
@@ -0,0 +1,114 @@
1
+ <script setup>
2
+ import UBadge from "@nuxt/ui/components/Badge.vue";
3
+ import UButton from "@nuxt/ui/components/Button.vue";
4
+ import { computed, onBeforeUnmount, onMounted, useId, useTemplateRef } from "vue";
5
+ import { useUiToolsLocale } from "../../../i18n/use-locale";
6
+ import { useFormGridLayout } from "../../composables/use-form-layout";
7
+ import { useFormPageContext } from "../../composables/use-form-page";
8
+ import { provideFormRuntime } from "../../composables/use-form-runtime";
9
+ import { useFormUi } from "../../composables/use-form-ui";
10
+ import { resolveFormLayoutConfig } from "../../utils/layout";
11
+ import { mergeFormUiClass } from "../../utils/ui";
12
+ import FormFieldRenderer from "../renderer/form-field-renderer.vue";
13
+ const props = defineProps({
14
+ entry: { type: Object, required: true },
15
+ section: { type: Object, required: true }
16
+ });
17
+ defineSlots();
18
+ const page = useFormPageContext();
19
+ const formUi = useFormUi();
20
+ const { t } = useUiToolsLocale();
21
+ const { runtime } = page.root;
22
+ const pageUi = computed(() => formUi.ui.value.page?.ui);
23
+ const titleId = useId();
24
+ const dirty = computed(() => page.dirtyCheck.value && props.section.dirty);
25
+ const layout = computed(
26
+ () => resolveFormLayoutConfig(runtime.currentLayout.value, props.entry.section.layout)
27
+ );
28
+ provideFormRuntime({ ...runtime, currentLayout: layout });
29
+ const grid = useFormGridLayout({ layout });
30
+ const element = useTemplateRef("element");
31
+ let unregister;
32
+ onMounted(() => {
33
+ if (element.value) {
34
+ unregister = page.register(props.section.key, element.value);
35
+ }
36
+ });
37
+ onBeforeUnmount(() => unregister?.());
38
+ </script>
39
+
40
+ <template>
41
+ <section
42
+ :id="section.key"
43
+ ref="element"
44
+ :aria-labelledby="titleId"
45
+ :data-form-page-section="section.key"
46
+ :data-state="section.status"
47
+ :data-dirty="dirty || void 0"
48
+ :class="
49
+ mergeFormUiClass(
50
+ 'flex min-w-0 scroll-mt-[calc(var(--nut-form-page-header,0px)+var(--nut-form-page-gap,24px))] flex-col gap-[18px] rounded-xl border border-default bg-default px-5 pt-5 pb-6 transition-[border-color,box-shadow] duration-200 @3xl/form-page:px-6 @3xl/form-page:pt-[22px] data-[dirty]:border-primary data-[dirty]:ring-4 data-[dirty]:ring-primary/20',
51
+ pageUi?.section
52
+ )
53
+ "
54
+ >
55
+ <header
56
+ :class="
57
+ mergeFormUiClass('flex flex-wrap items-center gap-x-3 gap-y-1', pageUi?.sectionHeader)
58
+ "
59
+ >
60
+ <h2
61
+ :id="titleId"
62
+ tabindex="-1"
63
+ :class="
64
+ mergeFormUiClass(
65
+ 'm-0 text-lg font-semibold tracking-[-0.015em] text-highlighted focus:outline-none',
66
+ pageUi?.sectionTitle
67
+ )
68
+ "
69
+ data-form-page-section-title
70
+ >
71
+ {{ section.label }}
72
+ </h2>
73
+ <p
74
+ v-if="section.description"
75
+ :class="mergeFormUiClass('m-0 text-[13px] text-muted', pageUi?.sectionDescription)"
76
+ >
77
+ {{ section.description }}
78
+ </p>
79
+ <UBadge
80
+ v-if="section.optional"
81
+ color="neutral"
82
+ variant="soft"
83
+ :label="t('form.page.optional')"
84
+ :class="mergeFormUiClass('capitalize', pageUi?.sectionOptional)"
85
+ />
86
+ <div
87
+ v-if="dirty || $slots.actions"
88
+ :class="mergeFormUiClass('ms-auto flex items-center gap-2', pageUi?.sectionActions)"
89
+ >
90
+ <slot name="actions" :section />
91
+ <UButton
92
+ v-if="dirty"
93
+ type="button"
94
+ color="neutral"
95
+ variant="ghost"
96
+ size="sm"
97
+ icon="i-lucide-rotate-ccw"
98
+ :label="t('form.page.resetSection')"
99
+ :class="pageUi?.sectionReset"
100
+ data-form-page-reset
101
+ @click="page.resetSection(section.key)"
102
+ />
103
+ </div>
104
+ </header>
105
+ <div :class="mergeFormUiClass('min-w-0', pageUi?.sectionBody)" :style="grid.style.value">
106
+ <FormFieldRenderer
107
+ v-for="field in entry.section.fields"
108
+ :key="field.key"
109
+ :field="field"
110
+ :parent-path="[]"
111
+ />
112
+ </div>
113
+ </section>
114
+ </template>
@@ -0,0 +1,19 @@
1
+ import type { FormPageSectionEntry, FormPageSectionState } from '../../types/index.js';
2
+ type __VLS_Props = {
3
+ entry: FormPageSectionEntry;
4
+ section: FormPageSectionState;
5
+ };
6
+ type __VLS_Slots = {
7
+ actions?: (props: {
8
+ section: FormPageSectionState;
9
+ }) => unknown;
10
+ };
11
+ 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>;
12
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
13
+ declare const _default: typeof __VLS_export;
14
+ export default _default;
15
+ type __VLS_WithSlots<T, S> = T & {
16
+ new (): {
17
+ $slots: S;
18
+ };
19
+ };
@@ -0,0 +1,21 @@
1
+ import type { FormPageSectionState } from '../../types/index.js';
2
+ /**
3
+ * Cards of a form page, one per visible section, each with its title, description, fields, and,
4
+ * with `controls.dirtyCheck`, a ring and a reset button while it is modified. Skeleton cards
5
+ * stand in while the schema context loads.
6
+ */
7
+ type __VLS_Slots = {
8
+ /** Extra buttons in a section header, before its reset button. */
9
+ actions?: (props: {
10
+ section: FormPageSectionState;
11
+ }) => unknown;
12
+ };
13
+ declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
14
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;
17
+ type __VLS_WithSlots<T, S> = T & {
18
+ new (): {
19
+ $slots: S;
20
+ };
21
+ };
@@ -0,0 +1,75 @@
1
+ <script setup>
2
+ import UAlert from "@nuxt/ui/components/Alert.vue";
3
+ import UButton from "@nuxt/ui/components/Button.vue";
4
+ import USkeleton from "@nuxt/ui/components/Skeleton.vue";
5
+ import { computed } from "vue";
6
+ import { useUiToolsLocale } from "../../../i18n/use-locale";
7
+ import { useFormPageContext } from "../../composables/use-form-page";
8
+ import { useFormUi } from "../../composables/use-form-ui";
9
+ import { mergeFormUiClass } from "../../utils/ui";
10
+ import FormPageSection from "./form-page-section.vue";
11
+ defineSlots();
12
+ const page = useFormPageContext();
13
+ const formUi = useFormUi();
14
+ const { t } = useUiToolsLocale();
15
+ const pageUi = computed(() => formUi.ui.value.page?.ui);
16
+ const { contextError, contextLoading, contextPending, refreshContext } = page.root;
17
+ </script>
18
+
19
+ <template>
20
+ <div
21
+ :class="mergeFormUiClass('flex min-w-0 flex-col gap-[18px]', pageUi?.sections)"
22
+ data-form-page-sections
23
+ >
24
+ <UAlert
25
+ v-if="contextError"
26
+ color="error"
27
+ variant="soft"
28
+ icon="i-lucide-circle-alert"
29
+ :title="t('form.states.contextError.title')"
30
+ :description="contextError"
31
+ >
32
+ <template #actions>
33
+ <UButton
34
+ type="button"
35
+ color="error"
36
+ variant="outline"
37
+ size="xs"
38
+ :loading="contextLoading"
39
+ @click="refreshContext"
40
+ >
41
+ {{ t("form.states.contextError.action") }}
42
+ </UButton>
43
+ </template>
44
+ </UAlert>
45
+ <template v-if="contextPending">
46
+ <div
47
+ v-for="section in page.sections.value"
48
+ :key="section.key"
49
+ :class="
50
+ mergeFormUiClass(
51
+ 'grid gap-4 rounded-xl border border-default bg-default px-6 pt-[22px] pb-6',
52
+ pageUi?.sectionSkeleton
53
+ )
54
+ "
55
+ data-form-skeleton
56
+ >
57
+ <USkeleton class="h-5 w-40" />
58
+ <USkeleton class="h-9 w-full" />
59
+ <USkeleton class="h-9 w-2/3" />
60
+ </div>
61
+ </template>
62
+ <template v-else>
63
+ <FormPageSection
64
+ v-for="item in page.items.value"
65
+ :key="item.section.key"
66
+ :entry="item.entry"
67
+ :section="item.section"
68
+ >
69
+ <template v-if="$slots.actions" #actions="slotProps">
70
+ <slot name="actions" v-bind="slotProps" />
71
+ </template>
72
+ </FormPageSection>
73
+ </template>
74
+ </div>
75
+ </template>
@@ -0,0 +1,21 @@
1
+ import type { FormPageSectionState } from '../../types/index.js';
2
+ /**
3
+ * Cards of a form page, one per visible section, each with its title, description, fields, and,
4
+ * with `controls.dirtyCheck`, a ring and a reset button while it is modified. Skeleton cards
5
+ * stand in while the schema context loads.
6
+ */
7
+ type __VLS_Slots = {
8
+ /** Extra buttons in a section header, before its reset button. */
9
+ actions?: (props: {
10
+ section: FormPageSectionState;
11
+ }) => unknown;
12
+ };
13
+ declare const __VLS_base: import("vue").DefineComponent<{}, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<{}> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
14
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
15
+ declare const _default: typeof __VLS_export;
16
+ export default _default;
17
+ type __VLS_WithSlots<T, S> = T & {
18
+ new (): {
19
+ $slots: S;
20
+ };
21
+ };
@@ -0,0 +1,80 @@
1
+ import type { FormPageSectionState, FormRendererController, FormUiConfig, FormValue } from '../../types/index.js';
2
+ /**
3
+ * A form laid out as a page: a header with the title and the actions, a navigation that follows
4
+ * the section in view, and one card per section. Render a schema from `defineFormPageSchema`.
5
+ *
6
+ * The page scrolls on its own, so give it a height (`h-full` in a layout that sizes its main
7
+ * area). Put parts in the default slot to compose another layout: `FormPageHeader`,
8
+ * `FormPageNavigation`, `FormPageSections`, and `FormPageActions` read the page they render in.
9
+ *
10
+ * @example
11
+ * ```vue
12
+ * <!-- const form = useForm({ schema: accountFormSchema(), onSubmit: createAccount }) -->
13
+ * <UiFormPage :form />
14
+ *
15
+ * <UiFormPage :form>
16
+ * <UiFormPageHeader />
17
+ * <div class="grid grid-cols-[minmax(0,1fr)_240px] gap-6 p-6">
18
+ * <UiFormPageSections />
19
+ * <UiFormPageNavigation />
20
+ * </div>
21
+ * </UiFormPage>
22
+ * ```
23
+ */
24
+ type __VLS_Props = {
25
+ form: FormRendererController;
26
+ /**
27
+ * Records the section picked in the navigation in the URL hash (`#identity`), and opens the
28
+ * page on the section the hash names. Defaults to `true`.
29
+ */
30
+ hash?: boolean;
31
+ /** Presentation overrides, merged after the app config and the schema `ui`. */
32
+ ui?: FormUiConfig;
33
+ };
34
+ type __VLS_Slots = {
35
+ /** Replaces the whole layout with parts of the page. */
36
+ default?: () => unknown;
37
+ /** Slots of the default header: see `FormPageHeader`. */
38
+ 'header-leading'?: () => unknown;
39
+ 'header-eyebrow'?: () => unknown;
40
+ 'header-title'?: () => unknown;
41
+ 'header-description'?: () => unknown;
42
+ 'header-actions'?: () => unknown;
43
+ /** Slots of the default navigation: see `FormPageNavigation`. */
44
+ 'navigation-title'?: () => unknown;
45
+ 'navigation-item'?: (props: {
46
+ section: FormPageSectionState;
47
+ active: boolean;
48
+ select: () => void;
49
+ }) => unknown;
50
+ 'navigation-footer'?: (props: {
51
+ sections: readonly FormPageSectionState[];
52
+ remaining: number;
53
+ modified: number;
54
+ }) => unknown;
55
+ /** Extra buttons in a section header: see `FormPageSections`. */
56
+ 'section-actions'?: (props: {
57
+ section: FormPageSectionState;
58
+ }) => unknown;
59
+ };
60
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
61
+ submit: (value: import("../../../shared/index.js").GenericObject, result: {
62
+ success: boolean;
63
+ data?: FormValue;
64
+ }) => any;
65
+ cancel: (value: import("../../../shared/index.js").GenericObject) => any;
66
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
67
+ onSubmit?: ((value: import("../../../shared/index.js").GenericObject, result: {
68
+ success: boolean;
69
+ data?: FormValue;
70
+ }) => any) | undefined;
71
+ onCancel?: ((value: import("../../../shared/index.js").GenericObject) => any) | undefined;
72
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
73
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
74
+ declare const _default: typeof __VLS_export;
75
+ export default _default;
76
+ type __VLS_WithSlots<T, S> = T & {
77
+ new (): {
78
+ $slots: S;
79
+ };
80
+ };
@@ -0,0 +1,91 @@
1
+ <script setup>
2
+ import { computed, useTemplateRef } from "vue";
3
+ import { provideFormPage, useFormPage } from "../../composables/use-form-page";
4
+ import { useFormRoot } from "../../composables/use-form-root";
5
+ import { mergeFormUiClass } from "../../utils/ui";
6
+ import FormPageHeader from "./form-page-header.vue";
7
+ import FormPageNavigation from "./form-page-navigation.vue";
8
+ import FormPageSections from "./form-page-sections.vue";
9
+ const {
10
+ form,
11
+ hash = true,
12
+ ui = void 0
13
+ } = defineProps({
14
+ form: { type: Object, required: true },
15
+ hash: { type: Boolean, required: false },
16
+ ui: { type: Object, required: false }
17
+ });
18
+ const emit = defineEmits(["submit", "cancel"]);
19
+ defineSlots();
20
+ const element = useTemplateRef("element");
21
+ const root = useFormRoot({
22
+ form: () => form,
23
+ input: () => void 0,
24
+ onCancelled: (value) => emit("cancel", value),
25
+ onSubmitted: (value, result) => emit("submit", value, result),
26
+ schema: () => void 0,
27
+ syncInput: () => void 0,
28
+ ui: () => ui,
29
+ validate: () => void 0
30
+ });
31
+ const page = provideFormPage(useFormPage({ element: () => element.value, hash: () => hash, root }));
32
+ const pageUi = computed(() => root.formUi.ui.value.page?.ui);
33
+ </script>
34
+
35
+ <template>
36
+ <form
37
+ ref="element"
38
+ novalidate
39
+ :class="
40
+ mergeFormUiClass('@container/form-page h-full min-w-0 overflow-y-auto bg-muted', pageUi?.root)
41
+ "
42
+ :style="{ '--nut-form-page-header': `${page.stickyOffset.value}px` }"
43
+ data-form-page
44
+ @submit.prevent="root.submit"
45
+ >
46
+ <slot>
47
+ <FormPageHeader>
48
+ <template v-if="$slots['header-leading']" #leading>
49
+ <slot name="header-leading" />
50
+ </template>
51
+ <template v-if="$slots['header-eyebrow']" #eyebrow>
52
+ <slot name="header-eyebrow" />
53
+ </template>
54
+ <template v-if="$slots['header-title']" #title>
55
+ <slot name="header-title" />
56
+ </template>
57
+ <template v-if="$slots['header-description']" #description>
58
+ <slot name="header-description" />
59
+ </template>
60
+ <template v-if="$slots['header-actions']" #actions>
61
+ <slot name="header-actions" />
62
+ </template>
63
+ </FormPageHeader>
64
+ <div
65
+ :class="
66
+ mergeFormUiClass(
67
+ 'grid gap-4 px-4 pt-4 pb-16 @3xl/form-page:grid-cols-[200px_minmax(0,1fr)] @3xl/form-page:items-start @3xl/form-page:gap-7 @3xl/form-page:px-7 @3xl/form-page:pt-6 @3xl/form-page:pb-20 @5xl/form-page:grid-cols-[230px_minmax(0,760px)]',
68
+ pageUi?.body
69
+ )
70
+ "
71
+ >
72
+ <FormPageNavigation>
73
+ <template v-if="$slots['navigation-title']" #title>
74
+ <slot name="navigation-title" />
75
+ </template>
76
+ <template v-if="$slots['navigation-item']" #item="slotProps">
77
+ <slot name="navigation-item" v-bind="slotProps" />
78
+ </template>
79
+ <template v-if="$slots['navigation-footer']" #footer="slotProps">
80
+ <slot name="navigation-footer" v-bind="slotProps" />
81
+ </template>
82
+ </FormPageNavigation>
83
+ <FormPageSections>
84
+ <template v-if="$slots['section-actions']" #actions="slotProps">
85
+ <slot name="section-actions" v-bind="slotProps" />
86
+ </template>
87
+ </FormPageSections>
88
+ </div>
89
+ </slot>
90
+ </form>
91
+ </template>
@@ -0,0 +1,80 @@
1
+ import type { FormPageSectionState, FormRendererController, FormUiConfig, FormValue } from '../../types/index.js';
2
+ /**
3
+ * A form laid out as a page: a header with the title and the actions, a navigation that follows
4
+ * the section in view, and one card per section. Render a schema from `defineFormPageSchema`.
5
+ *
6
+ * The page scrolls on its own, so give it a height (`h-full` in a layout that sizes its main
7
+ * area). Put parts in the default slot to compose another layout: `FormPageHeader`,
8
+ * `FormPageNavigation`, `FormPageSections`, and `FormPageActions` read the page they render in.
9
+ *
10
+ * @example
11
+ * ```vue
12
+ * <!-- const form = useForm({ schema: accountFormSchema(), onSubmit: createAccount }) -->
13
+ * <UiFormPage :form />
14
+ *
15
+ * <UiFormPage :form>
16
+ * <UiFormPageHeader />
17
+ * <div class="grid grid-cols-[minmax(0,1fr)_240px] gap-6 p-6">
18
+ * <UiFormPageSections />
19
+ * <UiFormPageNavigation />
20
+ * </div>
21
+ * </UiFormPage>
22
+ * ```
23
+ */
24
+ type __VLS_Props = {
25
+ form: FormRendererController;
26
+ /**
27
+ * Records the section picked in the navigation in the URL hash (`#identity`), and opens the
28
+ * page on the section the hash names. Defaults to `true`.
29
+ */
30
+ hash?: boolean;
31
+ /** Presentation overrides, merged after the app config and the schema `ui`. */
32
+ ui?: FormUiConfig;
33
+ };
34
+ type __VLS_Slots = {
35
+ /** Replaces the whole layout with parts of the page. */
36
+ default?: () => unknown;
37
+ /** Slots of the default header: see `FormPageHeader`. */
38
+ 'header-leading'?: () => unknown;
39
+ 'header-eyebrow'?: () => unknown;
40
+ 'header-title'?: () => unknown;
41
+ 'header-description'?: () => unknown;
42
+ 'header-actions'?: () => unknown;
43
+ /** Slots of the default navigation: see `FormPageNavigation`. */
44
+ 'navigation-title'?: () => unknown;
45
+ 'navigation-item'?: (props: {
46
+ section: FormPageSectionState;
47
+ active: boolean;
48
+ select: () => void;
49
+ }) => unknown;
50
+ 'navigation-footer'?: (props: {
51
+ sections: readonly FormPageSectionState[];
52
+ remaining: number;
53
+ modified: number;
54
+ }) => unknown;
55
+ /** Extra buttons in a section header: see `FormPageSections`. */
56
+ 'section-actions'?: (props: {
57
+ section: FormPageSectionState;
58
+ }) => unknown;
59
+ };
60
+ declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
61
+ submit: (value: import("../../../shared/index.js").GenericObject, result: {
62
+ success: boolean;
63
+ data?: FormValue;
64
+ }) => any;
65
+ cancel: (value: import("../../../shared/index.js").GenericObject) => any;
66
+ }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
67
+ onSubmit?: ((value: import("../../../shared/index.js").GenericObject, result: {
68
+ success: boolean;
69
+ data?: FormValue;
70
+ }) => any) | undefined;
71
+ onCancel?: ((value: import("../../../shared/index.js").GenericObject) => any) | undefined;
72
+ }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
73
+ declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
74
+ declare const _default: typeof __VLS_export;
75
+ export default _default;
76
+ type __VLS_WithSlots<T, S> = T & {
77
+ new (): {
78
+ $slots: S;
79
+ };
80
+ };
@@ -10,8 +10,8 @@ import { useUiToolsLocale } from "../../../i18n/use-locale";
10
10
  import { useFormFieldBare } from "../../composables/use-form-field-chrome";
11
11
  import { useFormRuntimeContext } from "../../composables/use-form-runtime";
12
12
  import { useFormUi } from "../../composables/use-form-ui";
13
+ import { getSchemaDirtyCheck } from "../../utils/controls";
13
14
  import { createFormFieldInstance } from "../../utils/field-instance";
14
- import { isRecord } from "../../utils/path";
15
15
  import { isFunction, isNumber, isString } from "../../utils/predicate";
16
16
  import { resolveRequired } from "../../utils/state";
17
17
  import { resolveFieldDescription, resolveFormText } from "../../utils/text";
@@ -85,21 +85,17 @@ const help = computed(
85
85
  );
86
86
  const shellHelp = computed(() => props.inlineLabel ? void 0 : help.value);
87
87
  const dirty = computed(
88
- () => "dirtyCheck" in props.field && (props.field.dirtyCheck === true || schemaDirtyCheck()) && form.dirtyPaths.value.includes(props.path.join("."))
88
+ () => "dirtyCheck" in props.field && (props.field.dirtyCheck === true || getSchemaDirtyCheck(form.schema.value)) && form.dirtyPaths.value.includes(props.path.join("."))
89
89
  );
90
- function schemaDirtyCheck() {
91
- const schema = form.schema.value;
92
- if (!isRecord(schema) || !isRecord(schema.controls)) {
93
- return false;
94
- }
95
- return schema.controls.dirtyCheck === true;
96
- }
97
90
  const open = ref(!("collapsed" in props.field && props.field.collapsed === true));
98
91
  const collapsible = computed(() => "collapsible" in props.field && props.field.collapsible === true);
99
92
  const fieldUi = computed(() => formUi.ui.value.field?.ui);
93
+ const stacked = computed(
94
+ () => orientation.value === "vertical" && Boolean(shellLabel.value || shellDescription.value)
95
+ );
100
96
  const nuxtFieldUi = computed(() => ({
101
97
  container: mergeFormUiClass(
102
- orientation.value === "horizontal" ? "min-w-0 flex-1" : void 0,
98
+ orientation.value === "horizontal" ? "min-w-0 flex-1" : stacked.value ? "mt-0" : void 0,
103
99
  fieldUi.value?.container
104
100
  ),
105
101
  description: fieldUi.value?.description,
@@ -111,7 +107,7 @@ const nuxtFieldUi = computed(() => ({
111
107
  orientation.value === "horizontal" && labelWidth.value ? "w-(--nut-form-label-width) shrink-0" : void 0,
112
108
  fieldUi.value?.labelWrapper
113
109
  ),
114
- root: fieldUi.value?.root,
110
+ root: mergeFormUiClass(stacked.value ? "flex flex-col gap-1.5" : void 0, fieldUi.value?.root),
115
111
  wrapper: fieldUi.value?.wrapper
116
112
  }));
117
113
  function resetField() {