nuxt-ui-tools 1.2.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.
- package/dist/module.json +1 -1
- package/dist/module.mjs +18 -2
- package/dist/runtime/dashboard/components/block/dashboard-block-state.d.vue.ts +2 -0
- package/dist/runtime/dashboard/components/block/dashboard-block-state.vue +4 -1
- package/dist/runtime/dashboard/components/block/dashboard-block-state.vue.d.ts +2 -0
- package/dist/runtime/dashboard/components/block/dashboard-chips.d.vue.ts +20 -0
- package/dist/runtime/dashboard/components/block/dashboard-chips.vue +42 -0
- package/dist/runtime/dashboard/components/block/dashboard-chips.vue.d.ts +20 -0
- package/dist/runtime/dashboard/components/block/dashboard-series-picker.d.vue.ts +8 -0
- package/dist/runtime/dashboard/components/block/dashboard-series-picker.vue +29 -0
- package/dist/runtime/dashboard/components/block/dashboard-series-picker.vue.d.ts +8 -0
- package/dist/runtime/dashboard/components/block/dashboard-skeleton.d.vue.ts +1 -1
- package/dist/runtime/dashboard/components/block/dashboard-skeleton.vue.d.ts +1 -1
- package/dist/runtime/dashboard/components/block/dashboard-view-scope.d.vue.ts +21 -0
- package/dist/runtime/dashboard/components/block/dashboard-view-scope.vue +12 -0
- package/dist/runtime/dashboard/components/block/dashboard-view-scope.vue.d.ts +21 -0
- package/dist/runtime/dashboard/components/dashboard-alerts.vue +3 -3
- package/dist/runtime/dashboard/components/dashboard-bar-chart.d.vue.ts +14 -3
- package/dist/runtime/dashboard/components/dashboard-bar-chart.vue +30 -9
- package/dist/runtime/dashboard/components/dashboard-bar-chart.vue.d.ts +14 -3
- package/dist/runtime/dashboard/components/dashboard-bars.vue +4 -4
- package/dist/runtime/dashboard/components/dashboard-card.vue +28 -6
- package/dist/runtime/dashboard/components/dashboard-combo-chart.d.vue.ts +6 -1
- package/dist/runtime/dashboard/components/dashboard-combo-chart.vue +13 -3
- package/dist/runtime/dashboard/components/dashboard-combo-chart.vue.d.ts +6 -1
- package/dist/runtime/dashboard/components/dashboard-donut-chart.vue +5 -5
- package/dist/runtime/dashboard/components/dashboard-feed.vue +1 -1
- package/dist/runtime/dashboard/components/dashboard-filter.d.vue.ts +67 -0
- package/dist/runtime/dashboard/components/dashboard-filter.vue +134 -0
- package/dist/runtime/dashboard/components/dashboard-filter.vue.d.ts +67 -0
- package/dist/runtime/dashboard/components/dashboard-filters.d.vue.ts +49 -0
- package/dist/runtime/dashboard/components/dashboard-filters.vue +96 -0
- package/dist/runtime/dashboard/components/dashboard-filters.vue.d.ts +49 -0
- package/dist/runtime/dashboard/components/dashboard-funnel.vue +5 -5
- package/dist/runtime/dashboard/components/dashboard-gauge.vue +3 -3
- package/dist/runtime/dashboard/components/dashboard-grid.d.vue.ts +10 -3
- package/dist/runtime/dashboard/components/dashboard-grid.vue +24 -9
- package/dist/runtime/dashboard/components/dashboard-grid.vue.d.ts +10 -3
- package/dist/runtime/dashboard/components/dashboard-line-chart.d.vue.ts +14 -3
- package/dist/runtime/dashboard/components/dashboard-line-chart.vue +30 -9
- package/dist/runtime/dashboard/components/dashboard-line-chart.vue.d.ts +14 -3
- package/dist/runtime/dashboard/components/dashboard-list.d.vue.ts +3 -0
- package/dist/runtime/dashboard/components/dashboard-list.vue +18 -6
- package/dist/runtime/dashboard/components/dashboard-list.vue.d.ts +3 -0
- package/dist/runtime/dashboard/components/dashboard-page.d.vue.ts +53 -0
- package/dist/runtime/dashboard/components/dashboard-page.vue +156 -0
- package/dist/runtime/dashboard/components/dashboard-page.vue.d.ts +53 -0
- package/dist/runtime/dashboard/components/dashboard-paired-bars.vue +4 -4
- package/dist/runtime/dashboard/components/dashboard-refresh.d.vue.ts +1 -1
- package/dist/runtime/dashboard/components/dashboard-refresh.vue +1 -0
- package/dist/runtime/dashboard/components/dashboard-refresh.vue.d.ts +1 -1
- package/dist/runtime/dashboard/components/dashboard-stack-bar.vue +4 -4
- package/dist/runtime/dashboard/components/dashboard-stat.d.vue.ts +14 -2
- package/dist/runtime/dashboard/components/dashboard-stat.vue +28 -10
- package/dist/runtime/dashboard/components/dashboard-stat.vue.d.ts +14 -2
- package/dist/runtime/dashboard/components/dashboard-stats.vue +3 -3
- package/dist/runtime/dashboard/components/dashboard-table.d.vue.ts +1 -1
- package/dist/runtime/dashboard/components/dashboard-table.vue +3 -3
- package/dist/runtime/dashboard/components/dashboard-table.vue.d.ts +1 -1
- package/dist/runtime/dashboard/components/dashboard-tabs.d.vue.ts +1 -1
- package/dist/runtime/dashboard/components/dashboard-tabs.vue.d.ts +1 -1
- package/dist/runtime/dashboard/components/dashboard-total.d.vue.ts +7 -2
- package/dist/runtime/dashboard/components/dashboard-total.vue +10 -2
- package/dist/runtime/dashboard/components/dashboard-total.vue.d.ts +7 -2
- package/dist/runtime/dashboard/components/dashboard-view-tabs.d.vue.ts +33 -0
- package/dist/runtime/dashboard/components/dashboard-view-tabs.vue +66 -0
- package/dist/runtime/dashboard/components/dashboard-view-tabs.vue.d.ts +33 -0
- package/dist/runtime/dashboard/components/dashboard-widget.vue +1 -1
- package/dist/runtime/dashboard/components/filter/dashboard-filter-menu.d.vue.ts +44 -0
- package/dist/runtime/dashboard/components/filter/dashboard-filter-menu.vue +220 -0
- package/dist/runtime/dashboard/components/filter/dashboard-filter-menu.vue.d.ts +44 -0
- package/dist/runtime/dashboard/composables/use-dashboard-api.d.ts +6 -1
- package/dist/runtime/dashboard/composables/use-dashboard-api.js +29 -6
- package/dist/runtime/dashboard/composables/use-dashboard-block.d.ts +5 -4
- package/dist/runtime/dashboard/composables/use-dashboard-block.js +32 -15
- package/dist/runtime/dashboard/composables/use-dashboard-chart.d.ts +8 -1
- package/dist/runtime/dashboard/composables/use-dashboard-chart.js +16 -4
- package/dist/runtime/dashboard/composables/use-dashboard-context.d.ts +50 -0
- package/dist/runtime/dashboard/composables/use-dashboard-context.js +56 -0
- package/dist/runtime/dashboard/composables/use-dashboard-derived.js +6 -1
- package/dist/runtime/dashboard/composables/use-dashboard-filter-control.d.ts +16 -0
- package/dist/runtime/dashboard/composables/use-dashboard-filter-control.js +161 -0
- package/dist/runtime/dashboard/composables/use-dashboard-filter-scope.d.ts +37 -0
- package/dist/runtime/dashboard/composables/use-dashboard-filter-scope.js +107 -0
- package/dist/runtime/dashboard/composables/use-dashboard-format.d.ts +46 -6
- package/dist/runtime/dashboard/composables/use-dashboard-format.js +51 -8
- package/dist/runtime/dashboard/composables/use-dashboard-options.d.ts +11 -4
- package/dist/runtime/dashboard/composables/use-dashboard-options.js +33 -47
- package/dist/runtime/dashboard/composables/use-dashboard-remote-options.d.ts +8 -5
- package/dist/runtime/dashboard/composables/use-dashboard-remote-options.js +59 -70
- package/dist/runtime/dashboard/composables/use-dashboard-resource.d.ts +15 -4
- package/dist/runtime/dashboard/composables/use-dashboard-resource.js +52 -17
- package/dist/runtime/dashboard/composables/use-dashboard-scope.d.ts +10 -7
- package/dist/runtime/dashboard/composables/use-dashboard-scope.js +26 -16
- package/dist/runtime/dashboard/composables/use-dashboard-series-picker.d.ts +20 -0
- package/dist/runtime/dashboard/composables/use-dashboard-series-picker.js +30 -0
- package/dist/runtime/dashboard/composables/use-dashboard-time.d.ts +2 -0
- package/dist/runtime/dashboard/composables/use-dashboard-time.js +4 -1
- package/dist/runtime/dashboard/composables/use-dashboard-ui.d.ts +12 -2
- package/dist/runtime/dashboard/composables/use-dashboard-ui.js +3 -0
- package/dist/runtime/dashboard/composables/use-dashboard-views.d.ts +15 -3
- package/dist/runtime/dashboard/composables/use-dashboard-views.js +33 -10
- package/dist/runtime/dashboard/composables/use-dashboard.d.ts +18 -12
- package/dist/runtime/dashboard/composables/use-dashboard.js +98 -9
- package/dist/runtime/dashboard/index.d.ts +3 -1
- package/dist/runtime/dashboard/index.js +3 -1
- package/dist/runtime/dashboard/schema/index.d.ts +62 -30
- package/dist/runtime/dashboard/schema/index.js +3 -0
- package/dist/runtime/dashboard/types/blocks.d.ts +30 -4
- package/dist/runtime/dashboard/types/charts.d.ts +2 -2
- package/dist/runtime/dashboard/types/controls.d.ts +123 -0
- package/dist/runtime/dashboard/types/filters.d.ts +236 -0
- package/dist/runtime/dashboard/types/index.d.ts +3 -2
- package/dist/runtime/dashboard/types/page.d.ts +17 -0
- package/dist/runtime/dashboard/types/page.js +0 -0
- package/dist/runtime/dashboard/types/resource.d.ts +66 -28
- package/dist/runtime/dashboard/types/runtime.d.ts +39 -8
- package/dist/runtime/dashboard/types/schema.d.ts +94 -54
- package/dist/runtime/dashboard/types/ui.d.ts +78 -0
- package/dist/runtime/dashboard/utils/builders/dashboard-filters.d.ts +142 -0
- package/dist/runtime/dashboard/utils/builders/dashboard-filters.js +135 -0
- package/dist/runtime/dashboard/utils/charts.d.ts +4 -15
- package/dist/runtime/dashboard/utils/charts.js +26 -28
- package/dist/runtime/dashboard/utils/{params/codecs.d.ts → codecs.d.ts} +2 -2
- package/dist/runtime/dashboard/utils/{params/codecs.js → codecs.js} +1 -1
- package/dist/runtime/dashboard/utils/environment.d.ts +36 -0
- package/dist/runtime/dashboard/utils/environment.js +30 -0
- package/dist/runtime/dashboard/utils/filters.d.ts +44 -0
- package/dist/runtime/dashboard/utils/filters.js +62 -0
- package/dist/runtime/dashboard/utils/format.d.ts +25 -0
- package/dist/runtime/dashboard/utils/format.js +66 -0
- package/dist/runtime/dashboard/utils/grid.d.ts +17 -0
- package/dist/runtime/dashboard/utils/grid.js +14 -0
- package/dist/runtime/dashboard/utils/options.d.ts +3 -1
- package/dist/runtime/dashboard/utils/options.js +6 -0
- package/dist/runtime/dashboard/utils/remote.d.ts +7 -0
- package/dist/runtime/dashboard/utils/remote.js +14 -0
- package/dist/runtime/dashboard/utils/resource.d.ts +16 -7
- package/dist/runtime/dashboard/utils/resource.js +15 -9
- package/dist/runtime/dashboard/utils/schema.d.ts +8 -3
- package/dist/runtime/dashboard/utils/schema.js +9 -4
- package/dist/runtime/dashboard/utils/state.d.ts +11 -6
- package/dist/runtime/dashboard/utils/state.js +10 -5
- package/dist/runtime/dashboard/utils/time.d.ts +2 -0
- package/dist/runtime/dashboard/utils/time.js +11 -1
- package/dist/runtime/dashboard/utils/ui.d.ts +1 -1
- package/dist/runtime/dashboard/utils/ui.js +1 -1
- package/dist/runtime/form/components/actions/form-actions.vue +13 -127
- package/dist/runtime/form/components/page/form-page-actions.d.vue.ts +3 -0
- package/dist/runtime/form/components/page/form-page-actions.vue +40 -0
- package/dist/runtime/form/components/page/form-page-actions.vue.d.ts +3 -0
- package/dist/runtime/form/components/page/form-page-header.d.vue.ts +24 -0
- package/dist/runtime/form/components/page/form-page-header.vue +99 -0
- package/dist/runtime/form/components/page/form-page-header.vue.d.ts +24 -0
- package/dist/runtime/form/components/page/form-page-navigation.d.vue.ts +34 -0
- package/dist/runtime/form/components/page/form-page-navigation.vue +229 -0
- package/dist/runtime/form/components/page/form-page-navigation.vue.d.ts +34 -0
- package/dist/runtime/form/components/page/form-page-section.d.vue.ts +19 -0
- package/dist/runtime/form/components/page/form-page-section.vue +114 -0
- package/dist/runtime/form/components/page/form-page-section.vue.d.ts +19 -0
- package/dist/runtime/form/components/page/form-page-sections.d.vue.ts +21 -0
- package/dist/runtime/form/components/page/form-page-sections.vue +75 -0
- package/dist/runtime/form/components/page/form-page-sections.vue.d.ts +21 -0
- package/dist/runtime/form/components/page/form-page.d.vue.ts +80 -0
- package/dist/runtime/form/components/page/form-page.vue +91 -0
- package/dist/runtime/form/components/page/form-page.vue.d.ts +80 -0
- package/dist/runtime/form/components/renderer/form-field-shell.vue +7 -11
- package/dist/runtime/form/components/root/form.vue +26 -195
- package/dist/runtime/form/composables/use-form-action-buttons.d.ts +32 -0
- package/dist/runtime/form/composables/use-form-action-buttons.js +89 -0
- package/dist/runtime/form/composables/use-form-actions.d.ts +8 -5
- package/dist/runtime/form/composables/use-form-actions.js +1 -1
- package/dist/runtime/form/composables/use-form-page-scroll.d.ts +22 -0
- package/dist/runtime/form/composables/use-form-page-scroll.js +178 -0
- package/dist/runtime/form/composables/use-form-page.d.ts +114 -0
- package/dist/runtime/form/composables/use-form-page.js +83 -0
- package/dist/runtime/form/composables/use-form-root.d.ts +34 -0
- package/dist/runtime/form/composables/use-form-root.js +171 -0
- package/dist/runtime/form/composables/use-form-runtime.js +13 -4
- package/dist/runtime/form/composables/use-form.js +2 -22
- package/dist/runtime/form/fields/card-selection.d.ts +1 -0
- package/dist/runtime/form/fields/card-selection.js +1 -0
- package/dist/runtime/form/fields/checkbox-card/component.vue +28 -17
- package/dist/runtime/form/fields/checkbox-card/types.d.ts +2 -5
- package/dist/runtime/form/fields/checkbox-group/component.vue +5 -0
- package/dist/runtime/form/fields/choice-card/choice-card-label.d.vue.ts +17 -0
- package/dist/runtime/form/fields/choice-card/choice-card-label.vue +50 -0
- package/dist/runtime/form/fields/choice-card/choice-card-label.vue.d.ts +17 -0
- package/dist/runtime/form/fields/choice-card/types.d.ts +31 -0
- package/dist/runtime/form/fields/choice-card/types.js +0 -0
- package/dist/runtime/form/fields/choice-card/use-choice-card.d.ts +22 -0
- package/dist/runtime/form/fields/choice-card/use-choice-card.js +52 -0
- package/dist/runtime/form/fields/radio/component.vue +10 -0
- package/dist/runtime/form/fields/radio-card/component.vue +17 -16
- package/dist/runtime/form/fields/radio-card/types.d.ts +2 -4
- package/dist/runtime/form/index.d.ts +1 -1
- package/dist/runtime/form/index.js +7 -1
- package/dist/runtime/form/schema/index.d.ts +1 -1
- package/dist/runtime/form/schema/index.js +1 -0
- package/dist/runtime/form/schema/page.d.ts +50 -0
- package/dist/runtime/form/schema/page.js +25 -0
- package/dist/runtime/form/types/index.d.ts +1 -0
- package/dist/runtime/form/types/options.d.ts +1 -11
- package/dist/runtime/form/types/page.d.ts +172 -0
- package/dist/runtime/form/types/page.js +0 -0
- package/dist/runtime/form/types/ui.d.ts +60 -0
- package/dist/runtime/form/utils/controls.d.ts +15 -0
- package/dist/runtime/form/utils/controls.js +38 -0
- package/dist/runtime/form/utils/focus.js +1 -1
- package/dist/runtime/form/utils/layout.js +3 -1
- package/dist/runtime/form/utils/page.d.ts +20 -0
- package/dist/runtime/form/utils/page.js +107 -0
- package/dist/runtime/form/utils/state.d.ts +2 -0
- package/dist/runtime/form/utils/state.js +1 -1
- package/dist/runtime/form/utils/ui.js +1 -0
- package/dist/runtime/i18n/locales/en.js +47 -0
- package/dist/runtime/i18n/locales/fr.js +47 -0
- package/dist/runtime/i18n/types.d.ts +70 -0
- package/dist/runtime/shared/styles/tokens.css +1 -1
- package/dist/runtime/shared/types/query.d.ts +8 -0
- package/dist/runtime/table/types/index.d.ts +1 -0
- package/dist/runtime/table/types/remote-options.d.ts +64 -0
- package/dist/runtime/table/types/remote-options.js +0 -0
- package/dist/runtime/table/types/source.d.ts +10 -1
- package/dist/runtime/table/utils/builders/table-source.d.ts +2 -6
- package/dist/runtime/table/utils/index.d.ts +1 -0
- package/dist/runtime/table/utils/index.js +1 -0
- package/dist/runtime/table/utils/remote-table-options.d.ts +26 -0
- package/dist/runtime/table/utils/remote-table-options.js +88 -0
- package/package.json +4 -1
- package/dist/runtime/dashboard/composables/use-dashboard-param-scope.d.ts +0 -30
- package/dist/runtime/dashboard/composables/use-dashboard-param-scope.js +0 -71
- package/dist/runtime/dashboard/types/options.d.ts +0 -46
- package/dist/runtime/dashboard/types/params.d.ts +0 -115
- package/dist/runtime/dashboard/utils/builders/dashboard-params.d.ts +0 -85
- package/dist/runtime/dashboard/utils/builders/dashboard-params.js +0 -87
- /package/dist/runtime/dashboard/types/{options.js → controls.js} +0 -0
- /package/dist/runtime/dashboard/types/{params.js → filters.js} +0 -0
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { FormAction, FormRuntime } from '../types/index.js';
|
|
2
|
+
/**
|
|
3
|
+
* Turns form actions into Nuxt UI buttons: visibility, disabled and loading states, links, and
|
|
4
|
+
* what a click runs. The form footer and the form page actions render from it.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useFormActionButtons(params: {
|
|
7
|
+
runtime: FormRuntime;
|
|
8
|
+
actions: () => readonly FormAction[];
|
|
9
|
+
onCancel: () => void;
|
|
10
|
+
}): {
|
|
11
|
+
button: (action: FormAction) => {
|
|
12
|
+
readonly color: import("../types/index.js").FormActionColor | undefined;
|
|
13
|
+
readonly disabled: boolean;
|
|
14
|
+
readonly icon: string | undefined;
|
|
15
|
+
readonly label: string | undefined;
|
|
16
|
+
readonly loading: boolean;
|
|
17
|
+
readonly size: "xs" | "sm" | "md" | "lg" | "xl";
|
|
18
|
+
readonly to: string | undefined;
|
|
19
|
+
readonly trailingIcon: string | undefined;
|
|
20
|
+
readonly type: "button" | "submit";
|
|
21
|
+
readonly variant: import("../types/index.js").FormActionVariant | undefined;
|
|
22
|
+
};
|
|
23
|
+
fills: typeof fills;
|
|
24
|
+
run: (action: FormAction) => Promise<void>;
|
|
25
|
+
slot: typeof slot;
|
|
26
|
+
visible: import("vue").ComputedRef<FormAction[]>;
|
|
27
|
+
};
|
|
28
|
+
/** Footer group of an action at the current breakpoint. */
|
|
29
|
+
declare function slot(action: FormAction): "left" | "right";
|
|
30
|
+
/** True when an action fills its row at the current breakpoint. */
|
|
31
|
+
declare function fills(action: FormAction): boolean;
|
|
32
|
+
export {};
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
import { computed } from "vue";
|
|
2
|
+
import { getResponsiveValue } from "../../shared/composables/use-responsive-value.js";
|
|
3
|
+
import { createPublicFormApi } from "../utils/api.js";
|
|
4
|
+
import { invokeFormFunction, isString } from "../utils/predicate.js";
|
|
5
|
+
import { resolveFormText } from "../utils/text.js";
|
|
6
|
+
import { useFormUi } from "./use-form-ui.js";
|
|
7
|
+
export function useFormActionButtons(params) {
|
|
8
|
+
const formUi = useFormUi();
|
|
9
|
+
const context = computed(() => ({
|
|
10
|
+
actionPending: params.runtime.actionPending.value,
|
|
11
|
+
api: createPublicFormApi(params.runtime),
|
|
12
|
+
currentStep: params.runtime.currentStepIndex.value,
|
|
13
|
+
isFirstStep: params.runtime.isFirstStep.value,
|
|
14
|
+
isLastStep: params.runtime.isLastStep.value,
|
|
15
|
+
isMultiStep: params.runtime.isStepped.value
|
|
16
|
+
}));
|
|
17
|
+
const visible = computed(
|
|
18
|
+
() => params.actions().filter((action) => action.condition?.(context.value) ?? true)
|
|
19
|
+
);
|
|
20
|
+
async function run(action) {
|
|
21
|
+
if (action.key === "submit") {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
if (action.key === "next") {
|
|
25
|
+
await params.runtime.nextStep();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (action.key === "previous") {
|
|
29
|
+
await params.runtime.previousStep();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (action.key === "reset") {
|
|
33
|
+
await params.runtime.reset();
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
if (action.key === "cancel") {
|
|
37
|
+
params.onCancel();
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
if ("action" in action) {
|
|
41
|
+
await action.action?.(context.value);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
function link(action) {
|
|
45
|
+
if (!("link" in action)) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
if (isString(action.link)) {
|
|
49
|
+
return action.link;
|
|
50
|
+
}
|
|
51
|
+
const resolved = invokeFormFunction(action.link, [context.value]);
|
|
52
|
+
return isString(resolved) ? resolved : void 0;
|
|
53
|
+
}
|
|
54
|
+
function loading(action) {
|
|
55
|
+
const pending = params.runtime.actionPending.value;
|
|
56
|
+
return pending !== null && isBuiltInActionKey(action.key) && action.key === pending;
|
|
57
|
+
}
|
|
58
|
+
function disabled(action) {
|
|
59
|
+
if (action.disabled?.(context.value)) {
|
|
60
|
+
return true;
|
|
61
|
+
}
|
|
62
|
+
return params.runtime.actionPending.value !== null && !loading(action);
|
|
63
|
+
}
|
|
64
|
+
function button(action) {
|
|
65
|
+
const primary = action.type === "primary";
|
|
66
|
+
return {
|
|
67
|
+
color: action.color ?? (primary ? "primary" : void 0),
|
|
68
|
+
disabled: disabled(action),
|
|
69
|
+
icon: action.icon === false ? void 0 : action.icon,
|
|
70
|
+
label: resolveFormText(action.label),
|
|
71
|
+
loading: loading(action),
|
|
72
|
+
size: action.size ?? formUi.controlSize.value,
|
|
73
|
+
to: link(action),
|
|
74
|
+
trailingIcon: action.trailingIcon === false ? void 0 : action.trailingIcon,
|
|
75
|
+
type: action.key === "submit" ? "submit" : "button",
|
|
76
|
+
variant: action.variant ?? (primary ? "solid" : void 0)
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
return { button, fills, run, slot, visible };
|
|
80
|
+
}
|
|
81
|
+
function slot(action) {
|
|
82
|
+
return getResponsiveValue(action.slot ?? "right") === "left" ? "left" : "right";
|
|
83
|
+
}
|
|
84
|
+
function fills(action) {
|
|
85
|
+
return getResponsiveValue(action.width ?? "fit") === "fill";
|
|
86
|
+
}
|
|
87
|
+
function isBuiltInActionKey(value) {
|
|
88
|
+
return value === "reset" || value === "cancel" || value === "submit" || value === "previous" || value === "next";
|
|
89
|
+
}
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
export declare function useFormActions(params: {
|
|
1
|
+
import type { FormAction, FormActionSlot, FormRuntime } from '../types/index.js';
|
|
2
|
+
interface UseFormActionsParams {
|
|
4
3
|
runtime: FormRuntime;
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
/** Slot the built-in actions take unless an authored action sets its own. */
|
|
5
|
+
slot: () => FormActionSlot;
|
|
6
|
+
}
|
|
7
|
+
/** Resolves the actions of the current schema or step, completing built-in actions. */
|
|
8
|
+
export declare function useFormActions(params: UseFormActionsParams): import("vue").ComputedRef<readonly FormAction[]>;
|
|
9
|
+
export {};
|
|
@@ -28,7 +28,7 @@ function normalizeFormAction(action, params, t) {
|
|
|
28
28
|
};
|
|
29
29
|
}
|
|
30
30
|
function getBaseFormAction(key, params, t) {
|
|
31
|
-
const slot = params.
|
|
31
|
+
const slot = params.slot();
|
|
32
32
|
if (key === "submit") {
|
|
33
33
|
return {
|
|
34
34
|
condition: (context) => context.isMultiStep ? context.isLastStep : true,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ComputedRef } from 'vue';
|
|
2
|
+
import type { FormPageScrollOptions, FormPageSectionState } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* Scroll behavior of a form page: which section is in view (a scrollspy on the nearest scrolling
|
|
5
|
+
* ancestor), scrolling to a section, and the URL hash that records and restores it.
|
|
6
|
+
*
|
|
7
|
+
* A section counts as reached once its top passes the line its `scroll-margin-top` defines, the
|
|
8
|
+
* same offset `scrollIntoView` honors, so the pinned header and the scrollspy agree. The section
|
|
9
|
+
* of an entry clicked in the navigation, and the one holding the field that takes focus (such as
|
|
10
|
+
* the first invalid field on submit), stay current through the scroll they cause, until the page
|
|
11
|
+
* is scrolled again.
|
|
12
|
+
*/
|
|
13
|
+
export declare function useFormPageScroll(params: {
|
|
14
|
+
sections: ComputedRef<readonly FormPageSectionState[]>;
|
|
15
|
+
/** Element the scroll container is looked up from: the page itself, or an ancestor. */
|
|
16
|
+
root: () => HTMLElement | null;
|
|
17
|
+
hash: () => boolean;
|
|
18
|
+
}): {
|
|
19
|
+
active: import("vue").Ref<string | undefined, string | undefined>;
|
|
20
|
+
register: (key: string, element: HTMLElement) => () => void;
|
|
21
|
+
scrollTo: (key: string, options?: FormPageScrollOptions) => boolean;
|
|
22
|
+
};
|
|
@@ -0,0 +1,178 @@
|
|
|
1
|
+
import { nextTick, onBeforeUnmount, onMounted, ref } from "vue";
|
|
2
|
+
const SCROLL_SETTLE_MS = 120;
|
|
3
|
+
const ACTIVATION_SLACK = 8;
|
|
4
|
+
export function useFormPageScroll(params) {
|
|
5
|
+
const elements = /* @__PURE__ */ new Map();
|
|
6
|
+
const active = ref();
|
|
7
|
+
let scroller;
|
|
8
|
+
let focusRoot = null;
|
|
9
|
+
let target;
|
|
10
|
+
let pendingHash;
|
|
11
|
+
let settleTimer;
|
|
12
|
+
let holdFrame = 0;
|
|
13
|
+
let frame = 0;
|
|
14
|
+
function register(key, element) {
|
|
15
|
+
elements.set(key, element);
|
|
16
|
+
if (pendingHash === key) {
|
|
17
|
+
pendingHash = void 0;
|
|
18
|
+
void nextTick(() => scrollTo(key, { behavior: "instant", hash: false }));
|
|
19
|
+
} else {
|
|
20
|
+
schedule();
|
|
21
|
+
}
|
|
22
|
+
return () => {
|
|
23
|
+
if (elements.get(key) === element) {
|
|
24
|
+
elements.delete(key);
|
|
25
|
+
}
|
|
26
|
+
schedule();
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
function scrollTo(key, options = {}) {
|
|
30
|
+
const element = elements.get(key);
|
|
31
|
+
if (!element) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
hold(key);
|
|
35
|
+
element.scrollIntoView?.({
|
|
36
|
+
behavior: options.behavior ?? (prefersReducedMotion() ? "instant" : "smooth"),
|
|
37
|
+
block: "start"
|
|
38
|
+
});
|
|
39
|
+
if (options.focus) {
|
|
40
|
+
element.querySelector("[data-form-page-section-title]")?.focus({ preventScroll: true });
|
|
41
|
+
}
|
|
42
|
+
if (options.hash ?? params.hash()) {
|
|
43
|
+
writeHash(key);
|
|
44
|
+
}
|
|
45
|
+
return true;
|
|
46
|
+
}
|
|
47
|
+
function hold(key) {
|
|
48
|
+
target = key;
|
|
49
|
+
active.value = key;
|
|
50
|
+
clearTimeout(settleTimer);
|
|
51
|
+
cancelAnimationFrame(holdFrame);
|
|
52
|
+
holdFrame = requestAnimationFrame(() => {
|
|
53
|
+
holdFrame = requestAnimationFrame(() => {
|
|
54
|
+
holdFrame = 0;
|
|
55
|
+
settleSoon();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
function settleSoon() {
|
|
60
|
+
clearTimeout(settleTimer);
|
|
61
|
+
settleTimer = setTimeout(() => {
|
|
62
|
+
target = void 0;
|
|
63
|
+
}, SCROLL_SETTLE_MS);
|
|
64
|
+
}
|
|
65
|
+
function onScroll() {
|
|
66
|
+
if (target) {
|
|
67
|
+
settleSoon();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
schedule();
|
|
71
|
+
}
|
|
72
|
+
function onFocusIn(event) {
|
|
73
|
+
const section = event.target instanceof Element ? event.target.closest("[data-form-page-section]") : null;
|
|
74
|
+
const key = section?.dataset.formPageSection;
|
|
75
|
+
if (key && elements.get(key) === section) {
|
|
76
|
+
hold(key);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
function schedule() {
|
|
80
|
+
if (frame) {
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
frame = requestAnimationFrame(() => {
|
|
84
|
+
frame = 0;
|
|
85
|
+
update();
|
|
86
|
+
});
|
|
87
|
+
}
|
|
88
|
+
function update() {
|
|
89
|
+
if (target) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
const next = findActive();
|
|
93
|
+
if (next !== void 0) {
|
|
94
|
+
active.value = next;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
function findActive() {
|
|
98
|
+
const keys = params.sections.value.map((section) => section.key).filter((key) => elements.has(key));
|
|
99
|
+
if (!keys.length) {
|
|
100
|
+
return void 0;
|
|
101
|
+
}
|
|
102
|
+
if (isScrolledToEnd()) {
|
|
103
|
+
return keys.at(-1);
|
|
104
|
+
}
|
|
105
|
+
const line = scroller instanceof HTMLElement ? scroller.getBoundingClientRect().top : 0;
|
|
106
|
+
let current = keys[0];
|
|
107
|
+
for (const key of keys) {
|
|
108
|
+
const element = elements.get(key);
|
|
109
|
+
if (!element) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const margin = Number.parseFloat(getComputedStyle(element).scrollMarginTop) || 0;
|
|
113
|
+
if (element.getBoundingClientRect().top - margin > line + ACTIVATION_SLACK) {
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
current = key;
|
|
117
|
+
}
|
|
118
|
+
return current;
|
|
119
|
+
}
|
|
120
|
+
function isScrolledToEnd() {
|
|
121
|
+
const box = scroller instanceof HTMLElement ? scroller : document.scrollingElement;
|
|
122
|
+
if (!box || box.scrollHeight <= box.clientHeight) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
return box.scrollTop + box.clientHeight >= box.scrollHeight - 1;
|
|
126
|
+
}
|
|
127
|
+
function onHashChange() {
|
|
128
|
+
const key = readHash();
|
|
129
|
+
if (key && elements.has(key)) {
|
|
130
|
+
scrollTo(key, { hash: false });
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
onMounted(() => {
|
|
134
|
+
focusRoot = params.root();
|
|
135
|
+
focusRoot?.addEventListener("focusin", onFocusIn);
|
|
136
|
+
scroller = findScroller(focusRoot);
|
|
137
|
+
scroller.addEventListener("scroll", onScroll, { passive: true });
|
|
138
|
+
window.addEventListener("hashchange", onHashChange);
|
|
139
|
+
const key = params.hash() ? readHash() : void 0;
|
|
140
|
+
if (key && elements.has(key)) {
|
|
141
|
+
void nextTick(() => scrollTo(key, { behavior: "instant", hash: false }));
|
|
142
|
+
} else {
|
|
143
|
+
pendingHash = key;
|
|
144
|
+
schedule();
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
onBeforeUnmount(() => {
|
|
148
|
+
focusRoot?.removeEventListener("focusin", onFocusIn);
|
|
149
|
+
scroller?.removeEventListener("scroll", onScroll);
|
|
150
|
+
window.removeEventListener("hashchange", onHashChange);
|
|
151
|
+
clearTimeout(settleTimer);
|
|
152
|
+
cancelAnimationFrame(holdFrame);
|
|
153
|
+
if (frame) {
|
|
154
|
+
cancelAnimationFrame(frame);
|
|
155
|
+
}
|
|
156
|
+
});
|
|
157
|
+
return { active, register, scrollTo };
|
|
158
|
+
}
|
|
159
|
+
function findScroller(element) {
|
|
160
|
+
for (let node = element; node; node = node.parentElement) {
|
|
161
|
+
if (/auto|scroll/u.test(getComputedStyle(node).overflowY)) {
|
|
162
|
+
return node;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return window;
|
|
166
|
+
}
|
|
167
|
+
function prefersReducedMotion() {
|
|
168
|
+
return window.matchMedia?.("(prefers-reduced-motion: reduce)").matches === true;
|
|
169
|
+
}
|
|
170
|
+
function readHash() {
|
|
171
|
+
const hash = window.location.hash.slice(1);
|
|
172
|
+
return hash ? decodeURIComponent(hash) : void 0;
|
|
173
|
+
}
|
|
174
|
+
function writeHash(key) {
|
|
175
|
+
const url = new URL(window.location.href);
|
|
176
|
+
url.hash = key;
|
|
177
|
+
window.history.replaceState(window.history.state, "", url);
|
|
178
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import type { FormPageSectionState } from '../types/index.js';
|
|
2
|
+
import type { useFormRoot } from './use-form-root.js';
|
|
3
|
+
/**
|
|
4
|
+
* State shared by a form page and its parts: the visible sections and where each stands, the
|
|
5
|
+
* section in view, the navigation summary, and the actions a part can take on a section.
|
|
6
|
+
*/
|
|
7
|
+
export declare function useFormPage(params: {
|
|
8
|
+
root: ReturnType<typeof useFormRoot>;
|
|
9
|
+
/** The page element, where the lookup of the scroll container starts. */
|
|
10
|
+
element: () => HTMLElement | null;
|
|
11
|
+
hash: () => boolean;
|
|
12
|
+
}): {
|
|
13
|
+
active: import("vue").Ref<string | undefined, string | undefined>;
|
|
14
|
+
cancel: () => void;
|
|
15
|
+
dirtyCheck: import("vue").ComputedRef<boolean>;
|
|
16
|
+
items: import("vue").ComputedRef<{
|
|
17
|
+
entry: import("../types/index.js").FormPageSectionEntry;
|
|
18
|
+
section: FormPageSectionState;
|
|
19
|
+
}[]>;
|
|
20
|
+
modified: import("vue").ComputedRef<number>;
|
|
21
|
+
navigationTitle: import("vue").ComputedRef<string | undefined>;
|
|
22
|
+
register: (key: string, element: HTMLElement) => () => void;
|
|
23
|
+
remaining: import("vue").ComputedRef<number>;
|
|
24
|
+
resetSection: (key: string) => Promise<void>;
|
|
25
|
+
root: {
|
|
26
|
+
cancel: () => void;
|
|
27
|
+
contextError: import("vue").ComputedRef<string | undefined>;
|
|
28
|
+
contextLoading: import("vue").ComputedRef<boolean>;
|
|
29
|
+
contextPending: import("vue").ComputedRef<boolean>;
|
|
30
|
+
formUi: {
|
|
31
|
+
controlSize: import("vue").ComputedRef<import("../types/index.js").FormControlSize>;
|
|
32
|
+
density: import("vue").ComputedRef<import("../types/index.js").FormDensity>;
|
|
33
|
+
ui: import("vue").ComputedRef<import("../types/index.js").FormUiConfig>;
|
|
34
|
+
};
|
|
35
|
+
input: import("vue").ComputedRef<import("../../shared/index.js").GenericObject | undefined>;
|
|
36
|
+
refreshContext: () => Promise<void>;
|
|
37
|
+
runtime: import("../types/index.js").FormRuntime;
|
|
38
|
+
schema: import("vue").ComputedRef<{}>;
|
|
39
|
+
submit: () => Promise<void>;
|
|
40
|
+
validationMode: import("vue").ComputedRef<import("../types/index.js").FormValidationMode>;
|
|
41
|
+
};
|
|
42
|
+
scrollTo: (key: string, options?: import("../types/index.js").FormPageScrollOptions) => boolean;
|
|
43
|
+
sections: import("vue").ComputedRef<readonly FormPageSectionState[]>;
|
|
44
|
+
stickyOffset: import("vue").Ref<number, number>;
|
|
45
|
+
};
|
|
46
|
+
export declare function provideFormPage(page: ReturnType<typeof useFormPage>): {
|
|
47
|
+
active: import("vue").Ref<string | undefined, string | undefined>;
|
|
48
|
+
cancel: () => void;
|
|
49
|
+
dirtyCheck: import("vue").ComputedRef<boolean>;
|
|
50
|
+
items: import("vue").ComputedRef<{
|
|
51
|
+
entry: import("../types/index.js").FormPageSectionEntry;
|
|
52
|
+
section: FormPageSectionState;
|
|
53
|
+
}[]>;
|
|
54
|
+
modified: import("vue").ComputedRef<number>;
|
|
55
|
+
navigationTitle: import("vue").ComputedRef<string | undefined>;
|
|
56
|
+
register: (key: string, element: HTMLElement) => () => void;
|
|
57
|
+
remaining: import("vue").ComputedRef<number>;
|
|
58
|
+
resetSection: (key: string) => Promise<void>;
|
|
59
|
+
root: {
|
|
60
|
+
cancel: () => void;
|
|
61
|
+
contextError: import("vue").ComputedRef<string | undefined>;
|
|
62
|
+
contextLoading: import("vue").ComputedRef<boolean>;
|
|
63
|
+
contextPending: import("vue").ComputedRef<boolean>;
|
|
64
|
+
formUi: {
|
|
65
|
+
controlSize: import("vue").ComputedRef<import("../types/index.js").FormControlSize>;
|
|
66
|
+
density: import("vue").ComputedRef<import("../types/index.js").FormDensity>;
|
|
67
|
+
ui: import("vue").ComputedRef<import("../types/index.js").FormUiConfig>;
|
|
68
|
+
};
|
|
69
|
+
input: import("vue").ComputedRef<import("../../shared/index.js").GenericObject | undefined>;
|
|
70
|
+
refreshContext: () => Promise<void>;
|
|
71
|
+
runtime: import("../types/index.js").FormRuntime;
|
|
72
|
+
schema: import("vue").ComputedRef<{}>;
|
|
73
|
+
submit: () => Promise<void>;
|
|
74
|
+
validationMode: import("vue").ComputedRef<import("../types/index.js").FormValidationMode>;
|
|
75
|
+
};
|
|
76
|
+
scrollTo: (key: string, options?: import("../types/index.js").FormPageScrollOptions) => boolean;
|
|
77
|
+
sections: import("vue").ComputedRef<readonly FormPageSectionState[]>;
|
|
78
|
+
stickyOffset: import("vue").Ref<number, number>;
|
|
79
|
+
};
|
|
80
|
+
/** The page a part renders in. Parts only work inside `FormPage`. */
|
|
81
|
+
export declare function useFormPageContext(): {
|
|
82
|
+
active: import("vue").Ref<string | undefined, string | undefined>;
|
|
83
|
+
cancel: () => void;
|
|
84
|
+
dirtyCheck: import("vue").ComputedRef<boolean>;
|
|
85
|
+
items: import("vue").ComputedRef<{
|
|
86
|
+
entry: import("../types/index.js").FormPageSectionEntry;
|
|
87
|
+
section: FormPageSectionState;
|
|
88
|
+
}[]>;
|
|
89
|
+
modified: import("vue").ComputedRef<number>;
|
|
90
|
+
navigationTitle: import("vue").ComputedRef<string | undefined>;
|
|
91
|
+
register: (key: string, element: HTMLElement) => () => void;
|
|
92
|
+
remaining: import("vue").ComputedRef<number>;
|
|
93
|
+
resetSection: (key: string) => Promise<void>;
|
|
94
|
+
root: {
|
|
95
|
+
cancel: () => void;
|
|
96
|
+
contextError: import("vue").ComputedRef<string | undefined>;
|
|
97
|
+
contextLoading: import("vue").ComputedRef<boolean>;
|
|
98
|
+
contextPending: import("vue").ComputedRef<boolean>;
|
|
99
|
+
formUi: {
|
|
100
|
+
controlSize: import("vue").ComputedRef<import("../types/index.js").FormControlSize>;
|
|
101
|
+
density: import("vue").ComputedRef<import("../types/index.js").FormDensity>;
|
|
102
|
+
ui: import("vue").ComputedRef<import("../types/index.js").FormUiConfig>;
|
|
103
|
+
};
|
|
104
|
+
input: import("vue").ComputedRef<import("../../shared/index.js").GenericObject | undefined>;
|
|
105
|
+
refreshContext: () => Promise<void>;
|
|
106
|
+
runtime: import("../types/index.js").FormRuntime;
|
|
107
|
+
schema: import("vue").ComputedRef<{}>;
|
|
108
|
+
submit: () => Promise<void>;
|
|
109
|
+
validationMode: import("vue").ComputedRef<import("../types/index.js").FormValidationMode>;
|
|
110
|
+
};
|
|
111
|
+
scrollTo: (key: string, options?: import("../types/index.js").FormPageScrollOptions) => boolean;
|
|
112
|
+
sections: import("vue").ComputedRef<readonly FormPageSectionState[]>;
|
|
113
|
+
stickyOffset: import("vue").Ref<number, number>;
|
|
114
|
+
};
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
import { computed, inject, provide, ref } from "vue";
|
|
2
|
+
import { getSchemaDirtyCheck } from "../utils/controls.js";
|
|
3
|
+
import {
|
|
4
|
+
getFormPageNavigationTitle,
|
|
5
|
+
getFormPageSections,
|
|
6
|
+
isFormPageSectionVisible,
|
|
7
|
+
resolveFormPageSectionState
|
|
8
|
+
} from "../utils/page.js";
|
|
9
|
+
import { cloneFormValue } from "../utils/path.js";
|
|
10
|
+
import { useFormPageScroll } from "./use-form-page-scroll.js";
|
|
11
|
+
export function useFormPage(params) {
|
|
12
|
+
const { root } = params;
|
|
13
|
+
const { runtime } = root;
|
|
14
|
+
const entries = computed(
|
|
15
|
+
() => getFormPageSections(root.schema.value).filter(
|
|
16
|
+
(entry) => isFormPageSectionVisible(entry, runtime)
|
|
17
|
+
)
|
|
18
|
+
);
|
|
19
|
+
const requiredEnforced = computed(
|
|
20
|
+
() => root.validationMode.value === true || root.validationMode.value === "required"
|
|
21
|
+
);
|
|
22
|
+
const items = computed(
|
|
23
|
+
() => entries.value.map((entry, index) => ({
|
|
24
|
+
entry,
|
|
25
|
+
section: resolveFormPageSectionState({
|
|
26
|
+
entry,
|
|
27
|
+
index,
|
|
28
|
+
input: root.input.value,
|
|
29
|
+
requiredEnforced: requiredEnforced.value,
|
|
30
|
+
runtime
|
|
31
|
+
})
|
|
32
|
+
}))
|
|
33
|
+
);
|
|
34
|
+
const sections = computed(
|
|
35
|
+
() => items.value.map((item) => item.section)
|
|
36
|
+
);
|
|
37
|
+
const dirtyCheck = computed(() => getSchemaDirtyCheck(root.schema.value));
|
|
38
|
+
const navigationTitle = computed(() => getFormPageNavigationTitle(root.schema.value));
|
|
39
|
+
const remaining = computed(
|
|
40
|
+
() => sections.value.filter((section) => !section.optional && section.status !== "complete").length
|
|
41
|
+
);
|
|
42
|
+
const modified = computed(() => sections.value.filter((section) => section.dirty).length);
|
|
43
|
+
const stickyOffset = ref(0);
|
|
44
|
+
const scroll = useFormPageScroll({ hash: params.hash, root: params.element, sections });
|
|
45
|
+
async function resetSection(key) {
|
|
46
|
+
const section = sections.value.find((candidate) => candidate.key === key);
|
|
47
|
+
if (!section) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
for (const path of section.dirtyPaths) {
|
|
51
|
+
runtime.setValue(path, cloneFormValue(runtime.getInitialValue(path)));
|
|
52
|
+
runtime.clearError(path);
|
|
53
|
+
}
|
|
54
|
+
await runtime.settleEffects();
|
|
55
|
+
}
|
|
56
|
+
return {
|
|
57
|
+
active: scroll.active,
|
|
58
|
+
cancel: root.cancel,
|
|
59
|
+
dirtyCheck,
|
|
60
|
+
items,
|
|
61
|
+
modified,
|
|
62
|
+
navigationTitle,
|
|
63
|
+
register: scroll.register,
|
|
64
|
+
remaining,
|
|
65
|
+
resetSection,
|
|
66
|
+
root,
|
|
67
|
+
scrollTo: scroll.scrollTo,
|
|
68
|
+
sections,
|
|
69
|
+
stickyOffset
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
const formPageKey = Symbol("nuxt-ui-tools-form-page");
|
|
73
|
+
export function provideFormPage(page) {
|
|
74
|
+
provide(formPageKey, page);
|
|
75
|
+
return page;
|
|
76
|
+
}
|
|
77
|
+
export function useFormPageContext() {
|
|
78
|
+
const page = inject(formPageKey, null);
|
|
79
|
+
if (!page) {
|
|
80
|
+
throw new Error("Form page parts must be rendered inside <FormPage>.");
|
|
81
|
+
}
|
|
82
|
+
return page;
|
|
83
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type { FormObject, FormRendererController, FormSubmitHandlerResult, FormUiConfig, FormValidationMode, FormValue } from '../types/index.js';
|
|
2
|
+
export interface UseFormRootParams {
|
|
3
|
+
/** Controller from `useForm`. Its schema, input, and policies win over the direct ones. */
|
|
4
|
+
form: () => FormRendererController | undefined;
|
|
5
|
+
schema: () => FormValue;
|
|
6
|
+
input: () => FormObject | undefined;
|
|
7
|
+
syncInput: () => boolean | readonly string[] | undefined;
|
|
8
|
+
validate: () => FormValidationMode | undefined;
|
|
9
|
+
ui: () => FormUiConfig | undefined;
|
|
10
|
+
onSubmitted: (value: FormObject, result: FormSubmitHandlerResult<FormValue>) => void;
|
|
11
|
+
onCancelled: (value: FormObject) => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Root of a rendered form. It creates the runtime and binds it to the controller, provides the
|
|
15
|
+
* runtime and the presentation config to the fields, guards navigation away from a dirty form,
|
|
16
|
+
* and owns submit and cancel. `<NutForm>` and `FormPage` both render from it.
|
|
17
|
+
*/
|
|
18
|
+
export declare function useFormRoot(params: UseFormRootParams): {
|
|
19
|
+
cancel: () => void;
|
|
20
|
+
contextError: import("vue").ComputedRef<string | undefined>;
|
|
21
|
+
contextLoading: import("vue").ComputedRef<boolean>;
|
|
22
|
+
contextPending: import("vue").ComputedRef<boolean>;
|
|
23
|
+
formUi: {
|
|
24
|
+
controlSize: import("vue").ComputedRef<import("../types/index.js").FormControlSize>;
|
|
25
|
+
density: import("vue").ComputedRef<import("../types/index.js").FormDensity>;
|
|
26
|
+
ui: import("vue").ComputedRef<FormUiConfig>;
|
|
27
|
+
};
|
|
28
|
+
input: import("vue").ComputedRef<import("../../shared/index.js").GenericObject | undefined>;
|
|
29
|
+
refreshContext: () => Promise<void>;
|
|
30
|
+
runtime: import("../types/index.js").FormRuntime;
|
|
31
|
+
schema: import("vue").ComputedRef<{}>;
|
|
32
|
+
submit: () => Promise<void>;
|
|
33
|
+
validationMode: import("vue").ComputedRef<FormValidationMode>;
|
|
34
|
+
};
|