@vinicunca/taman-ui 0.1.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/README.md +95 -0
- package/dist/_virtual/_/plugin-vue/export-helper.mjs +8 -0
- package/dist/components/auth/index.d.ts +2 -0
- package/dist/components/auth/index.mjs +2 -0
- package/dist/components/auth/taman-auth-form.mjs +67 -0
- package/dist/components/auth/taman-auth-form.vue.d.ts +31 -0
- package/dist/components/back-to-top/index.mjs +2 -0
- package/dist/components/back-to-top/taman-back-to-top.mjs +70 -0
- package/dist/components/back-to-top/taman-back-to-top.vue.d.ts +18 -0
- package/dist/components/button/check-group-selection.mjs +17 -0
- package/dist/components/button/index.d.ts +4 -0
- package/dist/components/button/index.mjs +3 -0
- package/dist/components/button/taman-button-check-group.mjs +132 -0
- package/dist/components/button/taman-button-check-group.types.d.ts +22 -0
- package/dist/components/button/taman-button-check-group.vue.d.ts +41 -0
- package/dist/components/button/taman-button-icon.mjs +105 -0
- package/dist/components/button/taman-button-icon.vue.d.ts +17 -0
- package/dist/components/descriptions/index.d.ts +4 -0
- package/dist/components/descriptions/index.mjs +3 -0
- package/dist/components/descriptions/taman-description-cell.mjs +116 -0
- package/dist/components/descriptions/taman-description-item.mjs +10 -0
- package/dist/components/descriptions/taman-description-item.vue.d.ts +5 -0
- package/dist/components/descriptions/taman-description-row.mjs +131 -0
- package/dist/components/descriptions/taman-description.mjs +78 -0
- package/dist/components/descriptions/taman-description.types.d.ts +51 -0
- package/dist/components/descriptions/taman-description.vue.d.ts +23 -0
- package/dist/components/descriptions/use-taman-description.mjs +161 -0
- package/dist/components/file-upload/index.d.ts +3 -0
- package/dist/components/file-upload/index.mjs +2 -0
- package/dist/components/file-upload/taman-file-upload.mjs +88 -0
- package/dist/components/file-upload/taman-file-upload.types.d.ts +10 -0
- package/dist/components/file-upload/taman-file-upload.vue.d.ts +21 -0
- package/dist/components/full-screen/full-screen.mjs +27 -0
- package/dist/components/full-screen/full-screen.vue.d.ts +8 -0
- package/dist/components/full-screen/index.mjs +2 -0
- package/dist/components/icon/icon.mjs +27 -0
- package/dist/components/icon/icon.vue.d.ts +9 -0
- package/dist/components/icon/index.d.ts +2 -0
- package/dist/components/icon/index.mjs +2 -0
- package/dist/components/index.d.ts +34 -0
- package/dist/components/index.mjs +31 -0
- package/dist/components/input/index.d.ts +5 -0
- package/dist/components/input/index.mjs +4 -0
- package/dist/components/input/password-strength.d.ts +7 -0
- package/dist/components/input/password-strength.mjs +21 -0
- package/dist/components/input/taman-input-currency.mjs +76 -0
- package/dist/components/input/taman-input-currency.types.d.ts +8 -0
- package/dist/components/input/taman-input-currency.vue.d.ts +15 -0
- package/dist/components/input/taman-input-password.mjs +99 -0
- package/dist/components/input/taman-input-password.vue.d.ts +17 -0
- package/dist/components/input-date/format-calendar-input-value.mjs +26 -0
- package/dist/components/input-date/index.d.ts +3 -0
- package/dist/components/input-date/index.mjs +2 -0
- package/dist/components/input-date/taman-input-date.mjs +116 -0
- package/dist/components/input-date/taman-input-date.types.d.ts +14 -0
- package/dist/components/input-date/taman-input-date.vue.d.ts +21 -0
- package/dist/components/loading/index.d.ts +3 -0
- package/dist/components/loading/index.mjs +2 -0
- package/dist/components/loading/taman-loading.mjs +64 -0
- package/dist/components/loading/taman-loading.vue.d.ts +25 -0
- package/dist/components/loading/types.d.ts +13 -0
- package/dist/components/logo/index.mjs +2 -0
- package/dist/components/logo/taman-logo.mjs +60 -0
- package/dist/components/logo/taman-logo.vue.d.ts +32 -0
- package/dist/components/render-content/index.d.ts +2 -0
- package/dist/components/render-content/index.mjs +2 -0
- package/dist/components/render-content/render-content.mjs +42 -0
- package/dist/components/render-content/render-content.vue.d.ts +31 -0
- package/dist/components/scrollbar/index.d.ts +2 -0
- package/dist/components/scrollbar/index.mjs +2 -0
- package/dist/components/scrollbar/scrollbar.mjs +136 -0
- package/dist/components/scrollbar/scrollbar.vue.d.ts +50 -0
- package/dist/form/components/form-actions.mjs +151 -0
- package/dist/form/components/form-field-array.mjs +154 -0
- package/dist/form/components/form-field-array.types.d.ts +18 -0
- package/dist/form/form-render/form-render-field-collapsible.mjs +32 -0
- package/dist/form/form-render/form-render-field-control.mjs +44 -0
- package/dist/form/form-render/form-render-form-field.mjs +408 -0
- package/dist/form/form-render/form-render-form-label.mjs +46 -0
- package/dist/form/form-render/form-render-form.mjs +163 -0
- package/dist/form/form-render/form-render-group.mjs +89 -0
- package/dist/form/form-render/form-render.context.mjs +10 -0
- package/dist/form/form-render/form-render.dependencies.mjs +101 -0
- package/dist/form/form-render/form-render.helper.mjs +31 -0
- package/dist/form/form-render/form-render.schema.mjs +209 -0
- package/dist/form/form-render/index.mjs +4 -0
- package/dist/form/form.api.d.ts +54 -0
- package/dist/form/form.api.mjs +324 -0
- package/dist/form/form.built-ins.d.ts +36 -0
- package/dist/form/form.built-ins.mjs +48 -0
- package/dist/form/form.codec.d.ts +17 -0
- package/dist/form/form.codec.mjs +45 -0
- package/dist/form/form.config.d.ts +6 -0
- package/dist/form/form.config.mjs +43 -0
- package/dist/form/form.empty-value.d.ts +4 -0
- package/dist/form/form.empty-value.mjs +20 -0
- package/dist/form/form.field-name.mjs +25 -0
- package/dist/form/form.rule-registry.mjs +10 -0
- package/dist/form/form.runtime-field.mjs +56 -0
- package/dist/form/form.runtime.mjs +235 -0
- package/dist/form/form.schema-defaults.mjs +36 -0
- package/dist/form/form.types.d.ts +315 -0
- package/dist/form/form.use-delayed-flag.mjs +35 -0
- package/dist/form/form.use-form-context.mjs +44 -0
- package/dist/form/form.use-taman-form.d.ts +7 -0
- package/dist/form/form.use-taman-form.mjs +36 -0
- package/dist/form/index.d.ts +8 -0
- package/dist/form/index.mjs +6 -0
- package/dist/form/taman-use-form.mjs +146 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.mjs +56 -0
- package/dist/layout/components/index.mjs +6 -0
- package/dist/layout/components/taman-core-button-collapse.mjs +38 -0
- package/dist/layout/components/taman-core-button-fixed.mjs +29 -0
- package/dist/layout/components/taman-core-layout-content.mjs +50 -0
- package/dist/layout/components/taman-core-layout-footer.mjs +38 -0
- package/dist/layout/components/taman-core-layout-header.mjs +48 -0
- package/dist/layout/components/taman-core-layout-sidebar.mjs +319 -0
- package/dist/layout/components/taman-core-layout-tabbar.mjs +21 -0
- package/dist/layout/composables/use-layout.mjs +31 -0
- package/dist/layout/composables/use-sidebar-drag.mjs +103 -0
- package/dist/layout/header-scroll-state.mjs +9 -0
- package/dist/layout/index.d.ts +3 -0
- package/dist/layout/index.mjs +2 -0
- package/dist/layout/taman-core-layout.d.ts +41 -0
- package/dist/layout/taman-core-layout.mjs +603 -0
- package/dist/layout/taman-core-layout.vue.d.ts +99 -0
- package/dist/menu/components/collapse-transition.mjs +82 -0
- package/dist/menu/components/index.mjs +5 -0
- package/dist/menu/components/normal-menu/index.d.ts +3 -0
- package/dist/menu/components/normal-menu/index.mjs +2 -0
- package/dist/menu/components/normal-menu/normal-menu.d.ts +11 -0
- package/dist/menu/components/normal-menu/normal-menu.mjs +50 -0
- package/dist/menu/components/normal-menu/normal-menu.vue.d.ts +19 -0
- package/dist/menu/components/taman-menu-badge-dot.mjs +23 -0
- package/dist/menu/components/taman-menu-badge.mjs +49 -0
- package/dist/menu/components/taman-menu-badge.vue.d.ts +9 -0
- package/dist/menu/components/taman-menu-item.mjs +124 -0
- package/dist/menu/components/taman-menu-root.mjs +250 -0
- package/dist/menu/components/taman-menu-sub-menu-content.mjs +83 -0
- package/dist/menu/components/taman-menu-sub-menu.mjs +216 -0
- package/dist/menu/composables/index.mjs +3 -0
- package/dist/menu/composables/use-menu-context.mjs +36 -0
- package/dist/menu/composables/use-menu-scroll.mjs +23 -0
- package/dist/menu/composables/use-menu.mjs +33 -0
- package/dist/menu/index.d.ts +7 -0
- package/dist/menu/index.mjs +5 -0
- package/dist/menu/menu.constants.mjs +5 -0
- package/dist/menu/menu.types.d.ts +63 -0
- package/dist/menu/menu.utils.mjs +27 -0
- package/dist/menu/taman-menu.mjs +41 -0
- package/dist/menu/taman-menu.vue.d.ts +12 -0
- package/dist/menu/taman-sub-menu.mjs +75 -0
- package/dist/popup/alert/alert-builder.d.ts +8 -0
- package/dist/popup/alert/alert-builder.mjs +98 -0
- package/dist/popup/alert/alert-overlay.mjs +55 -0
- package/dist/popup/alert/alert.d.ts +43 -0
- package/dist/popup/alert/alert.mjs +10 -0
- package/dist/popup/alert/alert.vue.d.ts +26 -0
- package/dist/popup/alert/alert2.mjs +238 -0
- package/dist/popup/alert/index.d.ts +4 -0
- package/dist/popup/alert/index.mjs +4 -0
- package/dist/popup/dialog/dialog.api.d.ts +23 -0
- package/dist/popup/dialog/dialog.api.mjs +133 -0
- package/dist/popup/dialog/dialog.mjs +336 -0
- package/dist/popup/dialog/dialog.types.d.ts +60 -0
- package/dist/popup/dialog/dialog.vue.d.ts +46 -0
- package/dist/popup/dialog/index.d.ts +4 -0
- package/dist/popup/dialog/index.mjs +3 -0
- package/dist/popup/dialog/use-dialog-draggable.mjs +93 -0
- package/dist/popup/dialog/use-taman-dialog.d.ts +13 -0
- package/dist/popup/dialog/use-taman-dialog.mjs +106 -0
- package/dist/popup/drawer/drawer.api.d.ts +23 -0
- package/dist/popup/drawer/drawer.api.mjs +124 -0
- package/dist/popup/drawer/drawer.mjs +277 -0
- package/dist/popup/drawer/drawer.types.d.ts +56 -0
- package/dist/popup/drawer/drawer.vue.d.ts +47 -0
- package/dist/popup/drawer/index.d.ts +4 -0
- package/dist/popup/drawer/index.mjs +3 -0
- package/dist/popup/drawer/use-taman-drawer.d.ts +13 -0
- package/dist/popup/drawer/use-taman-drawer.mjs +109 -0
- package/dist/popup/index.d.ts +13 -0
- package/dist/popup/index.mjs +11 -0
- package/dist/tabs/components/index.mjs +2 -0
- package/dist/tabs/components/taman-tabs.mjs +158 -0
- package/dist/tabs/components/widgets/index.d.ts +4 -0
- package/dist/tabs/components/widgets/index.mjs +4 -0
- package/dist/tabs/components/widgets/tool-more.mjs +45 -0
- package/dist/tabs/components/widgets/tool-more.vue.d.ts +7 -0
- package/dist/tabs/components/widgets/tool-refresh.mjs +25 -0
- package/dist/tabs/components/widgets/tool-refresh.vue.d.ts +9 -0
- package/dist/tabs/components/widgets/tool-screen.mjs +29 -0
- package/dist/tabs/components/widgets/tool-screen.vue.d.ts +12 -0
- package/dist/tabs/index.d.ts +8 -0
- package/dist/tabs/index.mjs +6 -0
- package/dist/tabs/strict-context-menu.d.ts +10 -0
- package/dist/tabs/tabs.types.d.ts +30 -0
- package/dist/tabs/taman-tabs-view.mjs +101 -0
- package/dist/tabs/taman-tabs-view.vue.d.ts +18 -0
- package/dist/tabs/use-tabs-drag.mjs +69 -0
- package/dist/tabs/use-tabs-view-scroll.mjs +114 -0
- package/dist/ui/alert-dialog/alert-dialog-action.mjs +21 -0
- package/dist/ui/alert-dialog/alert-dialog-action.vue.d.ts +16 -0
- package/dist/ui/alert-dialog/alert-dialog-cancel.mjs +21 -0
- package/dist/ui/alert-dialog/alert-dialog-cancel.vue.d.ts +16 -0
- package/dist/ui/alert-dialog/alert-dialog-content.mjs +111 -0
- package/dist/ui/alert-dialog/alert-dialog-content.vue.d.ts +49 -0
- package/dist/ui/alert-dialog/alert-dialog-description.mjs +30 -0
- package/dist/ui/alert-dialog/alert-dialog-description.vue.d.ts +20 -0
- package/dist/ui/alert-dialog/alert-dialog-footer.mjs +14 -0
- package/dist/ui/alert-dialog/alert-dialog-footer.vue.d.ts +15 -0
- package/dist/ui/alert-dialog/alert-dialog-header.mjs +14 -0
- package/dist/ui/alert-dialog/alert-dialog-header.vue.d.ts +15 -0
- package/dist/ui/alert-dialog/alert-dialog-overlay.mjs +29 -0
- package/dist/ui/alert-dialog/alert-dialog-root.mjs +23 -0
- package/dist/ui/alert-dialog/alert-dialog-root.vue.d.ts +23 -0
- package/dist/ui/alert-dialog/alert-dialog-title.mjs +30 -0
- package/dist/ui/alert-dialog/alert-dialog-title.vue.d.ts +20 -0
- package/dist/ui/alert-dialog/alert-dialog-trigger.mjs +21 -0
- package/dist/ui/alert-dialog/alert-dialog-trigger.vue.d.ts +16 -0
- package/dist/ui/alert-dialog/index.d.ts +10 -0
- package/dist/ui/alert-dialog/index.mjs +10 -0
- package/dist/ui/dialog/dialog-close.mjs +21 -0
- package/dist/ui/dialog/dialog-close.vue.d.ts +16 -0
- package/dist/ui/dialog/dialog-content.mjs +111 -0
- package/dist/ui/dialog/dialog-content.vue.d.ts +51 -0
- package/dist/ui/dialog/dialog-description.mjs +31 -0
- package/dist/ui/dialog/dialog-description.vue.d.ts +20 -0
- package/dist/ui/dialog/dialog-footer.mjs +14 -0
- package/dist/ui/dialog/dialog-footer.vue.d.ts +15 -0
- package/dist/ui/dialog/dialog-header.mjs +14 -0
- package/dist/ui/dialog/dialog-header.vue.d.ts +15 -0
- package/dist/ui/dialog/dialog-overlay.mjs +34 -0
- package/dist/ui/dialog/dialog-overlay.vue.d.ts +14 -0
- package/dist/ui/dialog/dialog-root.mjs +24 -0
- package/dist/ui/dialog/dialog-root.vue.d.ts +23 -0
- package/dist/ui/dialog/dialog-title.mjs +31 -0
- package/dist/ui/dialog/dialog-title.vue.d.ts +20 -0
- package/dist/ui/dialog/dialog-trigger.mjs +21 -0
- package/dist/ui/dialog/dialog-trigger.vue.d.ts +16 -0
- package/dist/ui/dialog/index.d.ts +10 -0
- package/dist/ui/dialog/index.mjs +10 -0
- package/dist/ui/dialog/use-dialog-state-events.mjs +60 -0
- package/dist/ui/form/form-control.mjs +27 -0
- package/dist/ui/form/form-control.vue.d.ts +15 -0
- package/dist/ui/form/form-description.mjs +27 -0
- package/dist/ui/form/form-description.vue.d.ts +19 -0
- package/dist/ui/form/form-field.mjs +37 -0
- package/dist/ui/form/form-field.vue.d.ts +27 -0
- package/dist/ui/form/form-item.mjs +27 -0
- package/dist/ui/form/form-item.vue.d.ts +19 -0
- package/dist/ui/form/form-label.mjs +41 -0
- package/dist/ui/form/form-label.vue.d.ts +20 -0
- package/dist/ui/form/form-message.mjs +28 -0
- package/dist/ui/form/form-message.vue.d.ts +9 -0
- package/dist/ui/form/index.d.ts +8 -0
- package/dist/ui/form/index.mjs +8 -0
- package/dist/ui/form/injection-keys.d.ts +13 -0
- package/dist/ui/form/injection-keys.mjs +5 -0
- package/dist/ui/form/use-form-field.mjs +27 -0
- package/dist/ui/index.d.ts +42 -0
- package/dist/ui/index.mjs +42 -0
- package/dist/ui/label/index.d.ts +2 -0
- package/dist/ui/label/index.mjs +2 -0
- package/dist/ui/label/label.mjs +31 -0
- package/dist/ui/label/label.vue.d.ts +20 -0
- package/dist/ui/scroll-area/index.d.ts +3 -0
- package/dist/ui/scroll-area/index.mjs +3 -0
- package/dist/ui/scroll-area/scroll-area.mjs +47 -0
- package/dist/ui/scroll-area/scroll-area.vue.d.ts +21 -0
- package/dist/ui/scroll-area/scroll-bar.mjs +38 -0
- package/dist/ui/scroll-area/scroll-bar.vue.d.ts +12 -0
- package/dist/ui/sheet/index.d.ts +8 -0
- package/dist/ui/sheet/index.mjs +8 -0
- package/dist/ui/sheet/sheet-close.mjs +21 -0
- package/dist/ui/sheet/sheet-close.vue.d.ts +16 -0
- package/dist/ui/sheet/sheet-content.mjs +105 -0
- package/dist/ui/sheet/sheet-content.vue.d.ts +48 -0
- package/dist/ui/sheet/sheet-description.mjs +30 -0
- package/dist/ui/sheet/sheet-description.vue.d.ts +20 -0
- package/dist/ui/sheet/sheet-footer.mjs +14 -0
- package/dist/ui/sheet/sheet-footer.vue.d.ts +15 -0
- package/dist/ui/sheet/sheet-header.mjs +14 -0
- package/dist/ui/sheet/sheet-header.vue.d.ts +15 -0
- package/dist/ui/sheet/sheet-overlay.mjs +32 -0
- package/dist/ui/sheet/sheet-root.mjs +24 -0
- package/dist/ui/sheet/sheet-root.vue.d.ts +23 -0
- package/dist/ui/sheet/sheet-title.mjs +31 -0
- package/dist/ui/sheet/sheet-title.vue.d.ts +20 -0
- package/dist/ui/sheet/sheet.variants.d.ts +27 -0
- package/dist/ui/sheet/sheet.variants.mjs +12 -0
- package/dist/unocss/content.d.ts +4 -0
- package/dist/unocss/content.mjs +9 -0
- package/dist/unocss/index.d.ts +2 -0
- package/dist/unocss/index.mjs +2 -0
- package/package.json +78 -0
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { defineComponent, h, markRaw, onUnmounted } from "vue";
|
|
2
|
+
//#region src/form/form.runtime-field.ts
|
|
3
|
+
function isAsyncStandardSchemaValidator(validator) {
|
|
4
|
+
return Boolean(validator && typeof validator === "object" && "~standard" in validator);
|
|
5
|
+
}
|
|
6
|
+
const asyncValidatorKeys = [
|
|
7
|
+
"onBlurAsync",
|
|
8
|
+
"onChangeAsync",
|
|
9
|
+
"onDynamicAsync",
|
|
10
|
+
"onSubmitAsync"
|
|
11
|
+
];
|
|
12
|
+
function createRuntimeFieldComponent(fieldComponent, registerInvalidator, onValidatingChange) {
|
|
13
|
+
return markRaw(defineComponent({
|
|
14
|
+
inheritAttrs: false,
|
|
15
|
+
setup(_, { attrs, slots }) {
|
|
16
|
+
const fieldName = String(attrs.name ?? "");
|
|
17
|
+
let validationRunId = 0;
|
|
18
|
+
let cachedValidators;
|
|
19
|
+
let cachedWrappedValidators;
|
|
20
|
+
const unregisterInvalidator = registerInvalidator(fieldName, () => {
|
|
21
|
+
validationRunId += 1;
|
|
22
|
+
});
|
|
23
|
+
onUnmounted(unregisterInvalidator);
|
|
24
|
+
function wrapValidators(validators) {
|
|
25
|
+
if (validators === cachedValidators && cachedWrappedValidators) return cachedWrappedValidators;
|
|
26
|
+
const wrappedValidators = { ...validators };
|
|
27
|
+
for (const key of asyncValidatorKeys) {
|
|
28
|
+
const validator = validators[key];
|
|
29
|
+
if (typeof validator !== "function" && !isAsyncStandardSchemaValidator(validator)) continue;
|
|
30
|
+
wrappedValidators[key] = async (...args) => {
|
|
31
|
+
const currentValidationRunId = ++validationRunId;
|
|
32
|
+
onValidatingChange(fieldName, 1);
|
|
33
|
+
try {
|
|
34
|
+
const result = typeof validator === "function" ? await validator(...args) : (await validator["~standard"].validate(args[0]?.value)).issues;
|
|
35
|
+
return currentValidationRunId === validationRunId ? result : void 0;
|
|
36
|
+
} finally {
|
|
37
|
+
onValidatingChange(fieldName, -1);
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
cachedValidators = validators;
|
|
42
|
+
cachedWrappedValidators = wrappedValidators;
|
|
43
|
+
return wrappedValidators;
|
|
44
|
+
}
|
|
45
|
+
return () => {
|
|
46
|
+
const validators = attrs.validators;
|
|
47
|
+
return h(fieldComponent, {
|
|
48
|
+
...attrs,
|
|
49
|
+
...validators ? { validators: wrapValidators(validators) } : {}
|
|
50
|
+
}, slots);
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
}));
|
|
54
|
+
}
|
|
55
|
+
//#endregion
|
|
56
|
+
export { createRuntimeFieldComponent };
|
|
@@ -0,0 +1,235 @@
|
|
|
1
|
+
import { createRuntimeFieldComponent } from "./form.runtime-field.mjs";
|
|
2
|
+
import { computed, shallowRef } from "vue";
|
|
3
|
+
import { mergeWithArrayOverride } from "@vinicunca/taman-core/utils";
|
|
4
|
+
import { batch } from "@tanstack/store";
|
|
5
|
+
import { defaultValidationLogic, useForm } from "@tanstack/vue-form";
|
|
6
|
+
//#region src/form/form.runtime.ts
|
|
7
|
+
function normalizeError(error) {
|
|
8
|
+
if (typeof error === "string") return error;
|
|
9
|
+
if (error && typeof error === "object" && "message" in error) {
|
|
10
|
+
const message = Reflect.get(error, "message");
|
|
11
|
+
return typeof message === "string" ? message : void 0;
|
|
12
|
+
}
|
|
13
|
+
return error === void 0 || error === null ? void 0 : String(error);
|
|
14
|
+
}
|
|
15
|
+
function normalizeFieldMetaError(meta) {
|
|
16
|
+
if (!meta || typeof meta !== "object" || !("errors" in meta)) return;
|
|
17
|
+
const errors = Reflect.get(meta, "errors");
|
|
18
|
+
return normalizeError(Array.isArray(errors) ? errors[0] : void 0);
|
|
19
|
+
}
|
|
20
|
+
function createProgressiveValidationLogic(revealedFields) {
|
|
21
|
+
return (props) => {
|
|
22
|
+
let defaultValidators = [];
|
|
23
|
+
defaultValidationLogic({
|
|
24
|
+
...props,
|
|
25
|
+
runValidation: ({ validators }) => {
|
|
26
|
+
defaultValidators = validators;
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
const fieldName = props.event.fieldName;
|
|
30
|
+
const startsProgressiveValidation = props.event.type === "blur" || props.event.type === "submit";
|
|
31
|
+
if (fieldName && startsProgressiveValidation) revealedFields.add(fieldName);
|
|
32
|
+
const shouldRunProgressiveValidator = Boolean(fieldName && (startsProgressiveValidation || props.event.type === "change" && revealedFields.has(fieldName)));
|
|
33
|
+
const dynamicValidator = props.event.async ? props.validators?.onDynamicAsync : props.validators?.onDynamic;
|
|
34
|
+
return props.runValidation({
|
|
35
|
+
form: props.form,
|
|
36
|
+
validators: shouldRunProgressiveValidator && dynamicValidator ? [...defaultValidators, {
|
|
37
|
+
cause: "dynamic",
|
|
38
|
+
fn: dynamicValidator
|
|
39
|
+
}] : defaultValidators
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function useFormRuntime(defaultValues) {
|
|
44
|
+
const revealedFields = /* @__PURE__ */ new Set();
|
|
45
|
+
const rawForm = useForm({
|
|
46
|
+
defaultValues,
|
|
47
|
+
onSubmit: () => {},
|
|
48
|
+
validationLogic: createProgressiveValidationLogic(revealedFields)
|
|
49
|
+
});
|
|
50
|
+
const values = rawForm.useSelector((formState) => formState.values);
|
|
51
|
+
const fieldMeta = rawForm.useSelector((formState) => formState.fieldMeta);
|
|
52
|
+
const isDirty = rawForm.useSelector((formState) => formState.isDirty);
|
|
53
|
+
const isSubmitting = rawForm.useSelector((formState) => formState.isSubmitting);
|
|
54
|
+
const isValid = rawForm.useSelector((formState) => formState.isValid);
|
|
55
|
+
const isValidating = rawForm.useSelector((formState) => formState.isValidating);
|
|
56
|
+
const validationInvalidators = /* @__PURE__ */ new Map();
|
|
57
|
+
const pendingAsyncValidations = shallowRef(0);
|
|
58
|
+
const pendingFieldValidations = shallowRef(/* @__PURE__ */ new Map());
|
|
59
|
+
const isAnyFieldValidating = computed(() => pendingAsyncValidations.value > 0);
|
|
60
|
+
const isAnyNativeFieldValidating = computed(() => Object.values(fieldMeta.value).some((meta) => Boolean(meta.isValidating)));
|
|
61
|
+
function onFieldValidatingChange(fieldName, delta) {
|
|
62
|
+
pendingAsyncValidations.value += delta;
|
|
63
|
+
const nextPendingFieldValidations = new Map(pendingFieldValidations.value);
|
|
64
|
+
const nextCount = (nextPendingFieldValidations.get(fieldName) ?? 0) + delta;
|
|
65
|
+
if (nextCount > 0) nextPendingFieldValidations.set(fieldName, nextCount);
|
|
66
|
+
else nextPendingFieldValidations.delete(fieldName);
|
|
67
|
+
pendingFieldValidations.value = nextPendingFieldValidations;
|
|
68
|
+
}
|
|
69
|
+
function registerValidationInvalidator(fieldName, invalidator) {
|
|
70
|
+
let fieldInvalidators = validationInvalidators.get(fieldName);
|
|
71
|
+
if (!fieldInvalidators) {
|
|
72
|
+
fieldInvalidators = /* @__PURE__ */ new Set();
|
|
73
|
+
validationInvalidators.set(fieldName, fieldInvalidators);
|
|
74
|
+
}
|
|
75
|
+
fieldInvalidators.add(invalidator);
|
|
76
|
+
return () => {
|
|
77
|
+
invalidator();
|
|
78
|
+
fieldInvalidators.delete(invalidator);
|
|
79
|
+
if (fieldInvalidators.size === 0) {
|
|
80
|
+
validationInvalidators.delete(fieldName);
|
|
81
|
+
revealedFields.delete(fieldName);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
function invalidateFieldValidation(fieldName) {
|
|
86
|
+
for (const invalidator of validationInvalidators.get(fieldName) ?? []) invalidator();
|
|
87
|
+
}
|
|
88
|
+
const RuntimeField = createRuntimeFieldComponent(rawForm.Field, registerValidationInvalidator, onFieldValidatingChange);
|
|
89
|
+
function getErrors() {
|
|
90
|
+
const result = {};
|
|
91
|
+
for (const [fieldName, meta] of Object.entries(fieldMeta.value)) {
|
|
92
|
+
const error = normalizeFieldMetaError(meta);
|
|
93
|
+
if (error) result[fieldName] = error;
|
|
94
|
+
}
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
const errors = computed(getErrors);
|
|
98
|
+
const meta = computed(() => ({
|
|
99
|
+
dirty: isDirty.value,
|
|
100
|
+
submitting: isSubmitting.value,
|
|
101
|
+
valid: isValid.value,
|
|
102
|
+
validating: isValidating.value || isAnyFieldValidating.value || isAnyNativeFieldValidating.value
|
|
103
|
+
}));
|
|
104
|
+
const runtimeState = computed(() => ({
|
|
105
|
+
errors: errors.value,
|
|
106
|
+
meta: meta.value,
|
|
107
|
+
values: values.value
|
|
108
|
+
}));
|
|
109
|
+
function getFieldError(fieldName) {
|
|
110
|
+
return normalizeFieldMetaError(Reflect.get(fieldMeta.value, fieldName));
|
|
111
|
+
}
|
|
112
|
+
function useFieldError(fieldName) {
|
|
113
|
+
return rawForm.useSelector((formState) => normalizeFieldMetaError(Reflect.get(formState.fieldMeta, fieldName)));
|
|
114
|
+
}
|
|
115
|
+
function useFieldValidating(fieldName) {
|
|
116
|
+
return computed(() => Boolean(pendingFieldValidations.value.get(fieldName) || Reflect.get(fieldMeta.value, fieldName)?.isValidating));
|
|
117
|
+
}
|
|
118
|
+
function useFieldValue(fieldName) {
|
|
119
|
+
return rawForm.useSelector(() => rawForm.getFieldValue(fieldName));
|
|
120
|
+
}
|
|
121
|
+
function useFieldValues(fieldNames) {
|
|
122
|
+
const selectedValues = fieldNames.map((fieldName) => useFieldValue(fieldName));
|
|
123
|
+
return computed(() => selectedValues.map((value) => value.value));
|
|
124
|
+
}
|
|
125
|
+
async function validateField(fieldName) {
|
|
126
|
+
await rawForm.validateField(fieldName, "submit");
|
|
127
|
+
const error = getFieldError(fieldName);
|
|
128
|
+
return {
|
|
129
|
+
errors: error ? { [fieldName]: error } : {},
|
|
130
|
+
valid: !error
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
async function validate() {
|
|
134
|
+
await rawForm.validateAllFields("submit");
|
|
135
|
+
const errors = getErrors();
|
|
136
|
+
return {
|
|
137
|
+
errors,
|
|
138
|
+
valid: Object.keys(errors).length === 0
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
function setFieldError(fieldName, error) {
|
|
142
|
+
rawForm.setFieldMeta(fieldName, (meta) => ({
|
|
143
|
+
...meta,
|
|
144
|
+
errorMap: {
|
|
145
|
+
...meta?.errorMap,
|
|
146
|
+
onServer: error
|
|
147
|
+
}
|
|
148
|
+
}));
|
|
149
|
+
}
|
|
150
|
+
function clearValidation(fieldNames) {
|
|
151
|
+
let requestedFieldNames;
|
|
152
|
+
if (Array.isArray(fieldNames)) requestedFieldNames = fieldNames;
|
|
153
|
+
else if (fieldNames) requestedFieldNames = [fieldNames];
|
|
154
|
+
const targetFieldNames = requestedFieldNames ?? [.../* @__PURE__ */ new Set([...validationInvalidators.keys(), ...Object.keys(rawForm.getAllErrors().fields)])];
|
|
155
|
+
for (const fieldName of targetFieldNames) {
|
|
156
|
+
invalidateFieldValidation(fieldName);
|
|
157
|
+
revealedFields.delete(fieldName);
|
|
158
|
+
rawForm.setFieldMeta(fieldName, (meta) => ({
|
|
159
|
+
...meta,
|
|
160
|
+
errorMap: {}
|
|
161
|
+
}));
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
async function reset(resetState, options) {
|
|
165
|
+
for (const fieldName of validationInvalidators.keys()) invalidateFieldValidation(fieldName);
|
|
166
|
+
revealedFields.clear();
|
|
167
|
+
const partialValues = resetState?.values;
|
|
168
|
+
let resetValues;
|
|
169
|
+
if (partialValues) resetValues = options?.force ? partialValues : mergeWithArrayOverride(partialValues, rawForm.options.defaultValues ?? defaultValues);
|
|
170
|
+
rawForm.reset(resetValues, { keepDefaultValues: options?.keepDefaultValues });
|
|
171
|
+
}
|
|
172
|
+
async function submit() {
|
|
173
|
+
await rawForm.handleSubmit();
|
|
174
|
+
}
|
|
175
|
+
return {
|
|
176
|
+
clearValidation,
|
|
177
|
+
get errors() {
|
|
178
|
+
return errors.value;
|
|
179
|
+
},
|
|
180
|
+
fieldComponent: RuntimeField,
|
|
181
|
+
get meta() {
|
|
182
|
+
return meta.value;
|
|
183
|
+
},
|
|
184
|
+
get values() {
|
|
185
|
+
return values.value;
|
|
186
|
+
},
|
|
187
|
+
getFieldError,
|
|
188
|
+
getFieldValue(fieldName) {
|
|
189
|
+
return rawForm.getFieldValue(fieldName);
|
|
190
|
+
},
|
|
191
|
+
handleSubmit(callback) {
|
|
192
|
+
return async (event) => {
|
|
193
|
+
event?.preventDefault();
|
|
194
|
+
event?.stopPropagation();
|
|
195
|
+
if ((await validate()).valid) await callback?.(values.value);
|
|
196
|
+
};
|
|
197
|
+
},
|
|
198
|
+
isFieldValid(fieldName) {
|
|
199
|
+
return !getFieldError(fieldName);
|
|
200
|
+
},
|
|
201
|
+
pushFieldValue(fieldName, value) {
|
|
202
|
+
rawForm.pushFieldValue(fieldName, value);
|
|
203
|
+
},
|
|
204
|
+
async removeFieldValue(fieldName, index) {
|
|
205
|
+
await rawForm.removeFieldValue(fieldName, index);
|
|
206
|
+
},
|
|
207
|
+
reset,
|
|
208
|
+
setFieldError,
|
|
209
|
+
async setFieldValue(fieldName, value, shouldValidate) {
|
|
210
|
+
rawForm.setFieldValue(fieldName, value, { dontValidate: !shouldValidate });
|
|
211
|
+
if (shouldValidate) await validateField(fieldName);
|
|
212
|
+
},
|
|
213
|
+
async setValues(values, shouldValidate) {
|
|
214
|
+
batch(() => {
|
|
215
|
+
for (const [fieldName, value] of Object.entries(values)) rawForm.setFieldValue(fieldName, value, { dontValidate: !shouldValidate });
|
|
216
|
+
});
|
|
217
|
+
if (shouldValidate) await validate();
|
|
218
|
+
},
|
|
219
|
+
submit,
|
|
220
|
+
useSelector(selector) {
|
|
221
|
+
return computed(() => selector(runtimeState.value));
|
|
222
|
+
},
|
|
223
|
+
useFieldError,
|
|
224
|
+
useFieldValidating,
|
|
225
|
+
useFieldValue,
|
|
226
|
+
useFieldValues,
|
|
227
|
+
useValues() {
|
|
228
|
+
return values;
|
|
229
|
+
},
|
|
230
|
+
validate,
|
|
231
|
+
validateField
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
//#endregion
|
|
235
|
+
export { useFormRuntime };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { toRaw } from "vue";
|
|
2
|
+
import { ZodIntersection, ZodNumber, ZodObject, ZodString, ZodStringFormat, object, string } from "zod";
|
|
3
|
+
import { getDefaultsForSchema } from "zod-defaults";
|
|
4
|
+
//#region src/form/form.schema-defaults.ts
|
|
5
|
+
function getCustomDefaultValue(rule) {
|
|
6
|
+
rule = toRaw(rule);
|
|
7
|
+
if (rule instanceof ZodString || rule instanceof ZodStringFormat) return "";
|
|
8
|
+
else if (rule instanceof ZodNumber) return null;
|
|
9
|
+
else if (rule instanceof ZodObject) {
|
|
10
|
+
const defaultValues = {};
|
|
11
|
+
for (const [key, valueSchema] of Object.entries(rule.shape)) defaultValues[key] = getCustomDefaultValue(valueSchema);
|
|
12
|
+
return defaultValues;
|
|
13
|
+
} else if (rule instanceof ZodIntersection) return getDefaultsForSchema(normalizeSchemaForDefaults(rule));
|
|
14
|
+
else return;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Rebuild the schema used by zod-defaults, replacing native format nodes that
|
|
18
|
+
* zod-defaults does not recognise while retaining supported wrappers.
|
|
19
|
+
*/
|
|
20
|
+
function normalizeSchemaForDefaults(rule) {
|
|
21
|
+
const rawRule = toRaw(rule);
|
|
22
|
+
if (rawRule instanceof ZodStringFormat) return string();
|
|
23
|
+
if (rawRule instanceof ZodObject) {
|
|
24
|
+
const shape = Object.fromEntries(Object.entries(rawRule.shape).map(([key, value]) => [key, normalizeSchemaForDefaults(value)]));
|
|
25
|
+
return object(shape);
|
|
26
|
+
}
|
|
27
|
+
if (rawRule instanceof ZodIntersection) {
|
|
28
|
+
const { left, right } = rawRule.def;
|
|
29
|
+
return normalizeSchemaForDefaults(left).and(normalizeSchemaForDefaults(right));
|
|
30
|
+
}
|
|
31
|
+
if (rawRule.constructor.name === "ZodDefault") return normalizeSchemaForDefaults(rawRule.unwrap()).default(rawRule.def.defaultValue);
|
|
32
|
+
if (rawRule.constructor.name === "ZodPipe") return normalizeSchemaForDefaults(rawRule.in).pipe(rawRule.out);
|
|
33
|
+
return rawRule;
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { getCustomDefaultValue, normalizeSchemaForDefaults };
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
import { FormApi } from "./form.api.js";
|
|
2
|
+
import { BuiltInFormComponentPropsMap, BuiltInFormComponentType } from "./form.built-ins.js";
|
|
3
|
+
import { Component, HTMLAttributes, HtmlHTMLAttributes, Ref } from "vue";
|
|
4
|
+
import { ZodType } from "zod";
|
|
5
|
+
import { AnyFieldApi } from "@tanstack/vue-form";
|
|
6
|
+
import { MaybeComputedRef } from "@vinicunca/taman-core/typings";
|
|
7
|
+
import { ButtonProps } from "pohon-ui";
|
|
8
|
+
//#region src/form/form.types.d.ts
|
|
9
|
+
type FormValues = Record<string, any>;
|
|
10
|
+
type FormValuePatch<T> = T extends ((...args: Array<any>) => unknown) | Date | ReadonlyArray<unknown> ? T : T extends object ? { [K in keyof T]?: FormValuePatch<T[K]>; } : T;
|
|
11
|
+
interface FormCodec<TFormValues extends FormValues = FormValues, TSubmitValues extends FormValues = TFormValues> {
|
|
12
|
+
decode: (values: Readonly<TSubmitValues>) => TFormValues;
|
|
13
|
+
encode: (values: Readonly<TFormValues>) => TSubmitValues;
|
|
14
|
+
}
|
|
15
|
+
type FormFieldName<TValues extends FormValues = FormValues> = Extract<keyof TValues, string> | (Record<never, never> & string);
|
|
16
|
+
type FormFieldValue<TValues extends FormValues, TFieldName extends string> = TFieldName extends keyof TValues ? TValues[TFieldName] : unknown;
|
|
17
|
+
type FormBaseComponentType = BuiltInFormComponentType | (Record<never, never> & string);
|
|
18
|
+
type Breakpoints = '2xl:' | '3xl:' | '' | 'lg:' | 'md:' | 'sm:' | 'xl:';
|
|
19
|
+
type GridCols = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13;
|
|
20
|
+
type WrapperClassType = `${Breakpoints}grid-cols-${GridCols}` | (Record<never, never> & string);
|
|
21
|
+
type FormItemClassType = `${Breakpoints}cols-end-${'auto' | GridCols}` | `${Breakpoints}cols-span-${'auto' | 'full' | GridCols}` | `${Breakpoints}cols-start-${'auto' | GridCols}` | (Record<never, never> & string) | WrapperClassType;
|
|
22
|
+
interface FormFieldOptions {
|
|
23
|
+
asyncDebounceMs?: number;
|
|
24
|
+
validators?: NonNullable<AnyFieldApi['options']['validators']>;
|
|
25
|
+
validateOn?: ReadonlyArray<FormValidationTrigger>;
|
|
26
|
+
}
|
|
27
|
+
type FormValidationTrigger = 'blur' | 'change';
|
|
28
|
+
interface FormShape {
|
|
29
|
+
default?: any;
|
|
30
|
+
fieldName: string;
|
|
31
|
+
required?: boolean;
|
|
32
|
+
rules?: ZodType;
|
|
33
|
+
}
|
|
34
|
+
interface FormRuntimeField<TValue = unknown> {
|
|
35
|
+
handleBlur: () => void;
|
|
36
|
+
handleChange: (value: TValue) => void;
|
|
37
|
+
setErrorMap: (errorMap: Record<string, unknown>) => void;
|
|
38
|
+
state: {
|
|
39
|
+
meta: {
|
|
40
|
+
errors: Array<unknown>;
|
|
41
|
+
isDirty: boolean;
|
|
42
|
+
isTouched: boolean;
|
|
43
|
+
isValid: boolean;
|
|
44
|
+
isValidating: boolean;
|
|
45
|
+
};
|
|
46
|
+
value: TValue;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
interface FormComponentField<TValue = unknown, TFieldName extends string = string> {
|
|
50
|
+
'modelValue': TValue;
|
|
51
|
+
'name': TFieldName;
|
|
52
|
+
'onBlur': () => void;
|
|
53
|
+
'onChange': (value: TValue) => void;
|
|
54
|
+
'onInput': (value: TValue) => void;
|
|
55
|
+
'onUpdate:modelValue': (value: TValue) => void;
|
|
56
|
+
}
|
|
57
|
+
type MaybeComponentPropKey = 'options' | 'placeholder' | 'title' | keyof HtmlHTMLAttributes | (Record<never, never> & string);
|
|
58
|
+
type MaybeComponentProps = { [K in MaybeComponentPropKey]?: any; };
|
|
59
|
+
interface FormMeta {
|
|
60
|
+
dirty: boolean;
|
|
61
|
+
submitting: boolean;
|
|
62
|
+
valid: boolean;
|
|
63
|
+
validating: boolean;
|
|
64
|
+
}
|
|
65
|
+
interface FormRuntimeState<TValues extends FormValues = FormValues> {
|
|
66
|
+
errors: Record<string, string>;
|
|
67
|
+
meta: FormMeta;
|
|
68
|
+
values: TValues;
|
|
69
|
+
}
|
|
70
|
+
interface FormValidationResult {
|
|
71
|
+
errors: Record<string, string>;
|
|
72
|
+
valid: boolean;
|
|
73
|
+
}
|
|
74
|
+
interface FormValueSnapshot<TFormValues extends FormValues = FormValues, TSubmitValues extends FormValues = TFormValues> {
|
|
75
|
+
rawValues: Readonly<TFormValues>;
|
|
76
|
+
values: TSubmitValues;
|
|
77
|
+
}
|
|
78
|
+
interface FormResetState<TValues extends FormValues = FormValues> {
|
|
79
|
+
values?: Partial<TValues>;
|
|
80
|
+
}
|
|
81
|
+
interface FormResetOptions {
|
|
82
|
+
force?: boolean;
|
|
83
|
+
keepDefaultValues?: boolean;
|
|
84
|
+
}
|
|
85
|
+
interface FormActions<TValues extends FormValues = FormValues> {
|
|
86
|
+
clearValidation: (fieldNames?: FormFieldName<TValues> | Array<FormFieldName<TValues>>) => void;
|
|
87
|
+
readonly errors: Record<string, string>;
|
|
88
|
+
readonly fieldComponent: Component;
|
|
89
|
+
getFieldError: (fieldName: string) => string | undefined;
|
|
90
|
+
getFieldValue: <TFieldName extends FormFieldName<TValues>>(fieldName: TFieldName) => FormFieldValue<TValues, TFieldName>;
|
|
91
|
+
handleSubmit: (callback?: (values: TValues) => Promise<void> | void) => (event?: Event) => Promise<void>;
|
|
92
|
+
isFieldValid: (fieldName: string) => boolean;
|
|
93
|
+
readonly meta: FormMeta;
|
|
94
|
+
pushFieldValue: (fieldName: string, value: any) => void;
|
|
95
|
+
removeFieldValue: (fieldName: string, index: number) => Promise<void>;
|
|
96
|
+
reset: (state?: FormResetState<TValues>, options?: FormResetOptions) => Promise<void>;
|
|
97
|
+
setFieldError: (fieldName: string, error?: string) => void;
|
|
98
|
+
setFieldValue: <TFieldName extends FormFieldName<TValues>>(fieldName: TFieldName, value: FormFieldValue<TValues, NoInfer<TFieldName>>, shouldValidate?: boolean) => Promise<void>;
|
|
99
|
+
setValues: (values: Partial<TValues>, shouldValidate?: boolean) => Promise<void>;
|
|
100
|
+
submit: () => Promise<void>;
|
|
101
|
+
useFieldError: (fieldName: string) => Readonly<Ref<string | undefined>>;
|
|
102
|
+
useFieldValidating: (fieldName: string) => Readonly<Ref<boolean>>;
|
|
103
|
+
useFieldValue: <TFieldName extends FormFieldName<TValues>>(fieldName: TFieldName) => Readonly<Ref<FormFieldValue<TValues, TFieldName>>>;
|
|
104
|
+
useFieldValues: <TFieldName extends FormFieldName<TValues>>(fieldNames: ReadonlyArray<TFieldName>) => Readonly<Ref<Array<FormFieldValue<TValues, TFieldName>>>>;
|
|
105
|
+
useSelector: <T>(selector: (state: FormRuntimeState<TValues>) => T) => Readonly<Ref<T>>;
|
|
106
|
+
useValues: () => Readonly<Ref<TValues>>;
|
|
107
|
+
validate: () => Promise<FormValidationResult>;
|
|
108
|
+
validateField: (fieldName: string) => Promise<FormValidationResult>;
|
|
109
|
+
readonly values: TValues;
|
|
110
|
+
}
|
|
111
|
+
type ReservedFormSlotName = 'default' | 'expand-after' | 'expand-before' | 'reset-before' | 'submit-before';
|
|
112
|
+
type FormKnownFieldName<TValues extends FormValues> = string extends Extract<keyof TValues, string> ? never : Exclude<Extract<keyof TValues, string>, ReservedFormSlotName>;
|
|
113
|
+
interface TamanFormActionSlotProps<TValues extends FormValues = FormValues, T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TSubmitValues extends FormValues = TValues> {
|
|
114
|
+
formApi: ExtendedFormApi<TValues, T, P, TSubmitValues>;
|
|
115
|
+
values: TValues;
|
|
116
|
+
}
|
|
117
|
+
interface TamanFormDefaultSlotProps<TValues extends FormValues = FormValues, T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TSubmitValues extends FormValues = TValues> extends TamanFormActionSlotProps<TValues, T, P, TSubmitValues> {
|
|
118
|
+
shapes: Array<FormShape>;
|
|
119
|
+
}
|
|
120
|
+
interface TamanFormFieldSlotProps<TValues extends FormValues = FormValues, TFieldName extends FormFieldName<TValues> = FormFieldName<TValues>, T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TSubmitValues extends FormValues = TValues> extends TamanFormActionSlotProps<TValues, T, P, TSubmitValues> {
|
|
121
|
+
componentField: FormComponentField<FormFieldValue<TValues, TFieldName>, TFieldName>;
|
|
122
|
+
componentProps: TamanFormResolvedComponentProps<FormFieldValue<TValues, TFieldName>, TFieldName>;
|
|
123
|
+
disabled: boolean;
|
|
124
|
+
error: string | undefined;
|
|
125
|
+
field: FormRuntimeField<FormFieldValue<TValues, TFieldName>>;
|
|
126
|
+
isInValid: boolean;
|
|
127
|
+
issues: Array<{
|
|
128
|
+
message: string;
|
|
129
|
+
path: Array<PropertyKey>;
|
|
130
|
+
}>;
|
|
131
|
+
modelValue: FormFieldValue<TValues, TFieldName>;
|
|
132
|
+
name: TFieldName;
|
|
133
|
+
}
|
|
134
|
+
type TamanFormResolvedComponentProps<TValue = unknown, TFieldName extends string = string> = MaybeComponentProps & {
|
|
135
|
+
'disabled': boolean;
|
|
136
|
+
'modelValue'?: TValue;
|
|
137
|
+
'name': TFieldName;
|
|
138
|
+
'onUpdate:modelValue'?: (value: TValue) => void;
|
|
139
|
+
};
|
|
140
|
+
type TamanFormFieldSlots<TValues extends FormValues, T extends FormBaseComponentType, P extends Record<string, any>, TSubmitValues extends FormValues> = string extends Extract<keyof TValues, string> ? Record<string, ((props: TamanFormFieldSlotProps<TValues, FormFieldName<TValues>, T, P, TSubmitValues>) => any) | undefined> : { [TFieldName in FormKnownFieldName<TValues>]?: (props: TamanFormFieldSlotProps<TValues, TFieldName, T, P, TSubmitValues>) => any; };
|
|
141
|
+
type TamanFormSlots<TValues extends FormValues = FormValues, T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TSubmitValues extends FormValues = TValues> = TamanFormFieldSlots<TValues, T, P, TSubmitValues> & {
|
|
142
|
+
'default'?: (props: TamanFormDefaultSlotProps<TValues, T, P, TSubmitValues>) => any;
|
|
143
|
+
'expand-after'?: (props: TamanFormActionSlotProps<TValues, T, P, TSubmitValues>) => any;
|
|
144
|
+
'expand-before'?: (props: TamanFormActionSlotProps<TValues, T, P, TSubmitValues>) => any;
|
|
145
|
+
'reset-before'?: (props: TamanFormActionSlotProps<TValues, T, P, TSubmitValues>) => any;
|
|
146
|
+
'submit-before'?: (props: TamanFormActionSlotProps<TValues, T, P, TSubmitValues>) => any;
|
|
147
|
+
};
|
|
148
|
+
type TamanFormComponent<TValues extends FormValues = FormValues, T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TSubmitValues extends FormValues = TValues> = new () => {
|
|
149
|
+
$props: TamanFormProps<T, P, TValues, TSubmitValues>;
|
|
150
|
+
$slots: TamanFormSlots<TValues, T, P, TSubmitValues>;
|
|
151
|
+
};
|
|
152
|
+
interface FormSchemaContext<TValues extends FormValues = FormValues> {
|
|
153
|
+
arrayField?: string;
|
|
154
|
+
fieldName?: string;
|
|
155
|
+
originalFieldName?: string;
|
|
156
|
+
rootValues?: TValues;
|
|
157
|
+
row?: Record<string, any>;
|
|
158
|
+
rowIndex?: number;
|
|
159
|
+
rowPath?: string;
|
|
160
|
+
}
|
|
161
|
+
type FormCustomRenderType = (() => Component | string) | string;
|
|
162
|
+
type CustomParamsRenderType<TValues extends FormValues = FormValues> = ((ctx: FormSchemaContext<TValues>) => Component | string) | string;
|
|
163
|
+
type FormSchemaRuleType = 'required' | 'selectRequired' | null | (Record<never, never> & string) | ZodType;
|
|
164
|
+
interface FormItemDependenciesBase {
|
|
165
|
+
triggerFields: Array<string>;
|
|
166
|
+
}
|
|
167
|
+
interface FormDependenciesResolveContext<TValues extends FormValues = FormValues> {
|
|
168
|
+
actions: FormActions<TValues>;
|
|
169
|
+
controller: ExtendedFormApi<TValues>;
|
|
170
|
+
schema: FormSchemaContext<TValues>;
|
|
171
|
+
values: Readonly<TValues>;
|
|
172
|
+
}
|
|
173
|
+
interface FormDependenciesResolvedState {
|
|
174
|
+
componentProps?: MaybeComponentProps;
|
|
175
|
+
disabled?: boolean;
|
|
176
|
+
help?: FormCustomRenderType;
|
|
177
|
+
if?: boolean;
|
|
178
|
+
renderComponentContent?: Record<string, any>;
|
|
179
|
+
required?: boolean;
|
|
180
|
+
rules?: FormSchemaRuleType;
|
|
181
|
+
show?: boolean;
|
|
182
|
+
}
|
|
183
|
+
interface FormItemDependenciesResolve<TValues extends FormValues = FormValues> extends FormItemDependenciesBase {
|
|
184
|
+
resolve: (context: FormDependenciesResolveContext<TValues>) => FormDependenciesResolvedState | PromiseLike<FormDependenciesResolvedState | undefined> | undefined;
|
|
185
|
+
}
|
|
186
|
+
type FormItemDependencies<TValues extends FormValues = FormValues> = FormItemDependenciesResolve<TValues>;
|
|
187
|
+
type ComponentProps<TValues extends FormValues = FormValues> = ((ctx: FormSchemaContext<TValues>) => MaybeComponentProps) | MaybeComponentProps;
|
|
188
|
+
interface FormCommonConfig<TValues extends FormValues = FormValues> {
|
|
189
|
+
collapsible?: boolean;
|
|
190
|
+
componentProps?: ComponentProps<TValues>;
|
|
191
|
+
controlClass?: string;
|
|
192
|
+
defaultCollapsed?: boolean;
|
|
193
|
+
disabled?: boolean;
|
|
194
|
+
formFieldProps?: FormFieldOptions;
|
|
195
|
+
formItemClass?: (() => string) | string;
|
|
196
|
+
hideLabel?: boolean;
|
|
197
|
+
hideMessage?: boolean;
|
|
198
|
+
hideRequiredMark?: boolean;
|
|
199
|
+
labelClass?: string;
|
|
200
|
+
modelPropName?: string;
|
|
201
|
+
wrapperClass?: string;
|
|
202
|
+
}
|
|
203
|
+
type RenderComponentContentType<TValues extends FormValues = FormValues> = (ctx: FormSchemaContext<TValues>) => Record<string, any>;
|
|
204
|
+
type MappedComponentProps<P, TValues extends FormValues = FormValues> = ((ctx: FormSchemaContext<TValues>) => P & Record<string, any>) | (P & Record<string, any>);
|
|
205
|
+
interface FormSchemaBody<TValues extends FormValues = FormValues> extends Omit<FormCommonConfig<TValues>, 'componentProps'> {
|
|
206
|
+
collapsed?: boolean;
|
|
207
|
+
defaultValue?: any;
|
|
208
|
+
dependencies?: FormItemDependencies<TValues>;
|
|
209
|
+
description?: FormCustomRenderType;
|
|
210
|
+
fieldName: string;
|
|
211
|
+
help?: CustomParamsRenderType<TValues>;
|
|
212
|
+
hide?: boolean;
|
|
213
|
+
label?: FormCustomRenderType;
|
|
214
|
+
renderComponentContent?: RenderComponentContentType<TValues>;
|
|
215
|
+
rules?: FormSchemaRuleType;
|
|
216
|
+
suffix?: FormCustomRenderType;
|
|
217
|
+
}
|
|
218
|
+
type FormSchemaDiscriminated<T extends FormBaseComponentType, P extends Record<string, any>, TValues extends FormValues> = { [K in Extract<keyof P, T>]: {
|
|
219
|
+
component: K;
|
|
220
|
+
componentProps?: MappedComponentProps<P[K], TValues>;
|
|
221
|
+
} & FormSchemaBody<TValues>; }[Extract<keyof P, T>];
|
|
222
|
+
type FormSchemaFallback<T extends FormBaseComponentType, P extends Record<string, any>, TValues extends FormValues> = {
|
|
223
|
+
component: Component | (string extends keyof P ? T : Exclude<T, keyof P>);
|
|
224
|
+
componentProps?: ComponentProps<TValues>;
|
|
225
|
+
} & FormSchemaBody<TValues>;
|
|
226
|
+
type FormArraySchema<T extends FormBaseComponentType, P extends Record<string, any>, TValues extends FormValues> = {
|
|
227
|
+
arrayProps?: Omit<TamanFormFieldArrayProps<T, P, TValues>, 'disabled' | 'globalCommonConfig' | 'name' | 'schema'>;
|
|
228
|
+
children: Array<FormFieldSchema<T, P, TValues>>;
|
|
229
|
+
component?: Component | (string extends keyof P ? T : Exclude<T, keyof P>);
|
|
230
|
+
componentProps?: ComponentProps<TValues>;
|
|
231
|
+
type: 'array';
|
|
232
|
+
} & FormSchemaBody<TValues>;
|
|
233
|
+
interface FormGroupSchema<T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TValues extends FormValues = FormValues> {
|
|
234
|
+
children: Array<FormFieldSchema<T, P, TValues>>;
|
|
235
|
+
collapsed?: boolean;
|
|
236
|
+
collapsible?: boolean;
|
|
237
|
+
component?: never;
|
|
238
|
+
defaultCollapsed?: boolean;
|
|
239
|
+
extra?: FormCustomRenderType;
|
|
240
|
+
fieldName?: never;
|
|
241
|
+
formItemClass?: FormItemClassType;
|
|
242
|
+
hide?: boolean;
|
|
243
|
+
name?: string;
|
|
244
|
+
title?: FormCustomRenderType;
|
|
245
|
+
type: 'group';
|
|
246
|
+
wrapperClass?: WrapperClassType;
|
|
247
|
+
}
|
|
248
|
+
type FormFieldSchema<T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TValues extends FormValues = FormValues> = FormArraySchema<T, P, TValues> | FormSchemaDiscriminated<T, P, TValues> | FormSchemaFallback<T, P, TValues>;
|
|
249
|
+
type FormSchema<T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TValues extends FormValues = FormValues> = FormFieldSchema<T, P, TValues> | FormGroupSchema<T, P, TValues>;
|
|
250
|
+
interface TamanFormFieldArrayProps<T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TValues extends FormValues = FormValues> {
|
|
251
|
+
actionText?: string;
|
|
252
|
+
addButtonText?: string;
|
|
253
|
+
commonConfig?: FormCommonConfig<TValues>;
|
|
254
|
+
createRow?: () => Record<string, any>;
|
|
255
|
+
disabled?: boolean;
|
|
256
|
+
emptyText?: string;
|
|
257
|
+
globalCommonConfig?: FormCommonConfig<TValues>;
|
|
258
|
+
max?: number;
|
|
259
|
+
min?: number;
|
|
260
|
+
name?: string;
|
|
261
|
+
schema?: Array<FormFieldSchema<T, P, TValues>>;
|
|
262
|
+
showIndex?: boolean;
|
|
263
|
+
}
|
|
264
|
+
type FormHandleSubmitFn<TFormValues extends FormValues = FormValues, TSubmitValues extends FormValues = TFormValues> = (values: NoInfer<TSubmitValues>, rawValues: Readonly<TFormValues>) => Promise<void> | void;
|
|
265
|
+
type FormHandleResetFn<TSubmitValues extends FormValues = FormValues> = (values: TSubmitValues) => Promise<void> | void;
|
|
266
|
+
interface FormRenderProps<T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TValues extends FormValues = FormValues> {
|
|
267
|
+
collapsed?: boolean;
|
|
268
|
+
collapseTriggerResize?: boolean;
|
|
269
|
+
commonConfig?: FormCommonConfig<TValues>;
|
|
270
|
+
compact?: boolean;
|
|
271
|
+
componentMap: Record<FormBaseComponentType, Component>;
|
|
272
|
+
disabled?: boolean;
|
|
273
|
+
form?: FormActions<TValues>;
|
|
274
|
+
schema?: Array<FormSchema<T, P, TValues>>;
|
|
275
|
+
wrapperClass?: WrapperClassType;
|
|
276
|
+
}
|
|
277
|
+
interface ActionButtonOptions extends ButtonProps {
|
|
278
|
+
content?: MaybeComputedRef<string>;
|
|
279
|
+
show?: boolean;
|
|
280
|
+
}
|
|
281
|
+
interface TamanFormProps<T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TValues extends FormValues = FormValues, TSubmitValues extends FormValues = TValues> extends Omit<FormRenderProps<T, P, TValues>, 'componentMap' | 'form'> {
|
|
282
|
+
actionButtonsReverse?: boolean;
|
|
283
|
+
actionLayout?: 'inline' | 'newLine' | 'rowEnd';
|
|
284
|
+
actionPosition?: 'center' | 'left' | 'right';
|
|
285
|
+
actionWrapperClass?: HTMLAttributes['class'];
|
|
286
|
+
changeDebouncedTime?: number;
|
|
287
|
+
codec?: FormCodec<TValues, TSubmitValues>;
|
|
288
|
+
handleCollapsedChange?: (collapsed: boolean) => void;
|
|
289
|
+
handleReset?: FormHandleResetFn<NoInfer<TSubmitValues>>;
|
|
290
|
+
handleSubmit?: FormHandleSubmitFn<TValues, TSubmitValues>;
|
|
291
|
+
handleValuesChange?: (values: Readonly<TValues>, fieldsChanged: Array<string>, getFormattedValues: () => TSubmitValues) => void;
|
|
292
|
+
resetButtonOptions?: ActionButtonOptions;
|
|
293
|
+
scrollToFirstError?: boolean;
|
|
294
|
+
showDefaultActions?: boolean;
|
|
295
|
+
submitButtonOptions?: ActionButtonOptions;
|
|
296
|
+
submitOnChange?: boolean;
|
|
297
|
+
submitOnEnter?: boolean;
|
|
298
|
+
}
|
|
299
|
+
type ExtendedFormApi<TValues extends FormValues = FormValues, T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TSubmitValues extends FormValues = TValues> = FormApi<TValues, T, P, TSubmitValues> & {
|
|
300
|
+
useStore: <TResult = NoInfer<TamanFormProps<T, P, TValues, TSubmitValues>>>(selector?: (state: NoInfer<TamanFormProps<T, P, TValues, TSubmitValues>>) => TResult) => Readonly<Ref<TResult>>;
|
|
301
|
+
};
|
|
302
|
+
interface TamanFormAdapterOptions {
|
|
303
|
+
rules?: Partial<Record<string, FormRuleValidator>>;
|
|
304
|
+
}
|
|
305
|
+
interface FormRuleContext {
|
|
306
|
+
field: {
|
|
307
|
+
label?: string;
|
|
308
|
+
name: string;
|
|
309
|
+
};
|
|
310
|
+
label?: string;
|
|
311
|
+
name: string;
|
|
312
|
+
}
|
|
313
|
+
type FormRuleValidator = (value: any, params: any, context: FormRuleContext) => boolean | string;
|
|
314
|
+
//#endregion
|
|
315
|
+
export { type BuiltInFormComponentPropsMap, type BuiltInFormComponentType, ExtendedFormApi, FormActions, FormBaseComponentType, FormCodec, FormCommonConfig, FormComponentField, FormCustomRenderType, FormDependenciesResolveContext, FormDependenciesResolvedState, FormFieldName, FormFieldOptions, FormFieldSchema, FormFieldValue, FormGroupSchema, FormHandleResetFn, FormHandleSubmitFn, FormItemClassType, FormItemDependencies, FormItemDependenciesResolve, FormMeta, FormRenderProps, FormResetOptions, FormResetState, FormRuleContext, FormRuleValidator, FormRuntimeField, FormRuntimeState, FormSchema, FormSchemaContext, FormSchemaRuleType, FormShape, FormValidationResult, FormValidationTrigger, FormValuePatch, FormValueSnapshot, FormValues, MaybeComponentPropKey, MaybeComponentProps, TamanFormActionSlotProps, TamanFormAdapterOptions, TamanFormComponent, TamanFormDefaultSlotProps, TamanFormFieldArrayProps, TamanFormFieldSlotProps, TamanFormProps, TamanFormResolvedComponentProps, TamanFormSlots };
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { computed, onScopeDispose, ref, watch } from "vue";
|
|
2
|
+
//#region src/form/form.use-delayed-flag.ts
|
|
3
|
+
/**
|
|
4
|
+
* Mirrors `source`, but only flips to `true` once it has stayed truthy for
|
|
5
|
+
* `delayMs`. Falls back to `false` immediately.
|
|
6
|
+
*
|
|
7
|
+
* Used to keep fast async validators from flashing a spinner. Unlike the
|
|
8
|
+
* previous inline implementation this never mutates reactive state during
|
|
9
|
+
* render, so it is safe to read from a computed or a template.
|
|
10
|
+
*/
|
|
11
|
+
function useDelayedFlag(source, delayMs) {
|
|
12
|
+
const settled = ref(false);
|
|
13
|
+
let timer;
|
|
14
|
+
function clear() {
|
|
15
|
+
if (timer !== void 0) {
|
|
16
|
+
clearTimeout(timer);
|
|
17
|
+
timer = void 0;
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
watch(source, (active) => {
|
|
21
|
+
clear();
|
|
22
|
+
if (!active) {
|
|
23
|
+
settled.value = false;
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
timer = setTimeout(() => {
|
|
27
|
+
settled.value = true;
|
|
28
|
+
timer = void 0;
|
|
29
|
+
}, delayMs);
|
|
30
|
+
}, { immediate: true });
|
|
31
|
+
onScopeDispose(clear);
|
|
32
|
+
return computed(() => settled.value);
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
export { useDelayedFlag };
|