@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,54 @@
|
|
|
1
|
+
import { FormActions, FormBaseComponentType, FormFieldName, FormFieldSchema, FormFieldValue, FormResetOptions, FormResetState, FormValidationResult, FormValuePatch, FormValueSnapshot, FormValues, TamanFormProps } from "./form.types.js";
|
|
2
|
+
import { ComponentPublicInstance } from "vue";
|
|
3
|
+
import { StateHandler } from "@vinicunca/taman-core/utils";
|
|
4
|
+
import { Store } from "@vinicunca/taman-core/store";
|
|
5
|
+
//#region src/form/form.api.d.ts
|
|
6
|
+
type FormApiProps<TFormValues extends FormValues, T extends FormBaseComponentType, P extends Record<string, any>, TSubmitValues extends FormValues> = TamanFormProps<T, P, TFormValues, TSubmitValues>;
|
|
7
|
+
type FormApiFieldSchema<TValues extends FormValues, T extends FormBaseComponentType, P extends Record<string, any>> = FormFieldSchema<T, P, TValues>;
|
|
8
|
+
declare class FormApi<TFormValues extends FormValues = FormValues, T extends FormBaseComponentType = FormBaseComponentType, P extends Record<string, any> = Record<never, never>, TSubmitValues extends FormValues = TFormValues> {
|
|
9
|
+
form: FormActions<TFormValues>;
|
|
10
|
+
isMounted: boolean;
|
|
11
|
+
state: FormApiProps<TFormValues, T, P, TSubmitValues> | null;
|
|
12
|
+
stateHandler: StateHandler;
|
|
13
|
+
store: Store<FormApiProps<TFormValues, T, P, TSubmitValues>>;
|
|
14
|
+
private componentRefMap;
|
|
15
|
+
private latestSubmissionValues;
|
|
16
|
+
private prevState;
|
|
17
|
+
constructor(options?: FormApiProps<TFormValues, T, P, TSubmitValues>);
|
|
18
|
+
clearValidation(fieldNames?: FormFieldName<TFormValues> | Array<FormFieldName<TFormValues>>): Promise<void>;
|
|
19
|
+
formatValues(rawValues: Readonly<TFormValues>): TSubmitValues;
|
|
20
|
+
formatValues<TResult extends FormValues>(rawValues: Readonly<FormValues>): TResult;
|
|
21
|
+
getFieldComponentRef<T = ComponentPublicInstance>(fieldName: string): T | undefined;
|
|
22
|
+
getFocusedField(): string | undefined;
|
|
23
|
+
getLatestSubmissionValues(): {};
|
|
24
|
+
getRawValues(): Promise<TFormValues>;
|
|
25
|
+
getRawValues<TResult extends FormValues>(): Promise<TResult>;
|
|
26
|
+
getState(): FormApiProps<TFormValues, T, P, TSubmitValues> | null;
|
|
27
|
+
getValues(): Promise<TSubmitValues>;
|
|
28
|
+
getValues<TResult extends FormValues>(): Promise<TResult>;
|
|
29
|
+
getValueSnapshot(): Promise<FormValueSnapshot<TFormValues, TSubmitValues>>;
|
|
30
|
+
getValueSnapshot<TResult extends FormValues>(): Promise<FormValueSnapshot<TResult>>;
|
|
31
|
+
isFieldValid(fieldName: FormFieldName<TFormValues>): Promise<boolean>;
|
|
32
|
+
merge(formApi: FormApi<any, any, any, any>): any;
|
|
33
|
+
mount(formActions: FormActions<TFormValues>, componentRefMap?: Map<string, unknown>): void;
|
|
34
|
+
removeSchemaByFields(fields: Array<string>): Promise<void>;
|
|
35
|
+
reset(state?: FormResetState<TFormValues>, opts?: FormResetOptions): Promise<void>;
|
|
36
|
+
scrollToFirstError(errors: Record<string, any> | string): void;
|
|
37
|
+
setFieldError(fieldName: FormFieldName<TFormValues>, error?: string): Promise<void>;
|
|
38
|
+
setFieldValue<TFieldName extends FormFieldName<TFormValues>>(field: TFieldName, value: FormFieldValue<TFormValues, NoInfer<TFieldName>>, shouldValidate?: boolean): Promise<void>;
|
|
39
|
+
setLatestSubmissionValues(values: null | Partial<TSubmitValues>): void;
|
|
40
|
+
setState(stateOrFn: ((prev: FormApiProps<TFormValues, T, P, TSubmitValues>) => Partial<FormApiProps<TFormValues, T, P, TSubmitValues>>) | Partial<FormApiProps<TFormValues, T, P, TSubmitValues>>): void;
|
|
41
|
+
setSubmitValues(values: TSubmitValues, filterFields?: boolean, shouldValidate?: boolean): Promise<void>;
|
|
42
|
+
setValues(fields: FormValuePatch<TFormValues>, filterFields?: boolean, shouldValidate?: boolean): Promise<void>;
|
|
43
|
+
submit(e?: Event): Promise<TSubmitValues>;
|
|
44
|
+
unmount(): void;
|
|
45
|
+
updateSchema(schema: Array<Partial<FormApiFieldSchema<TFormValues, T, P>>>): void;
|
|
46
|
+
validate(): Promise<FormValidationResult>;
|
|
47
|
+
validateAndSubmit(): Promise<TSubmitValues | undefined>;
|
|
48
|
+
validateField(fieldName: FormFieldName<TFormValues>): Promise<FormValidationResult>;
|
|
49
|
+
private getForm;
|
|
50
|
+
private submitValues;
|
|
51
|
+
private updateState;
|
|
52
|
+
}
|
|
53
|
+
//#endregion
|
|
54
|
+
export { FormApi };
|
|
@@ -0,0 +1,324 @@
|
|
|
1
|
+
import { decodeFormValues, encodeFormValues } from "./form.codec.mjs";
|
|
2
|
+
import { resolveFieldNamePath } from "./form.field-name.mjs";
|
|
3
|
+
import { getFormFieldSchemas, removeFormSchemaByFields, updateFormSchemaList } from "./form-render/form-render.schema.mjs";
|
|
4
|
+
import { isRef, toRaw } from "vue";
|
|
5
|
+
import { StateHandler, bindMethods, clone, isFunction, isString, mergeWithArrayOverride } from "@vinicunca/taman-core/utils";
|
|
6
|
+
import { Store } from "@vinicunca/taman-core/store";
|
|
7
|
+
//#region src/form/form.api.ts
|
|
8
|
+
function cloneFormValues(value) {
|
|
9
|
+
if (Array.isArray(value)) return value.map((item) => cloneFormValues(item));
|
|
10
|
+
if (isPlainFormObject(value)) {
|
|
11
|
+
const next = {};
|
|
12
|
+
for (const [key, item] of Object.entries(value)) next[key] = cloneFormValues(item);
|
|
13
|
+
return next;
|
|
14
|
+
}
|
|
15
|
+
if (value instanceof Date) return new Date(value.getTime());
|
|
16
|
+
return value;
|
|
17
|
+
}
|
|
18
|
+
function isPlainFormObject(value) {
|
|
19
|
+
if (value === null || typeof value !== "object") return false;
|
|
20
|
+
const prototype = Object.getPrototypeOf(value);
|
|
21
|
+
return prototype === null || prototype === Object.prototype;
|
|
22
|
+
}
|
|
23
|
+
function mergeFormValuePatch(currentValue, nextValue, visited = /* @__PURE__ */ new WeakMap()) {
|
|
24
|
+
if (!isPlainFormObject(nextValue)) return cloneFormValues(nextValue);
|
|
25
|
+
const cached = visited.get(nextValue);
|
|
26
|
+
if (cached) return cached;
|
|
27
|
+
const result = isPlainFormObject(currentValue) ? clone(currentValue) : {};
|
|
28
|
+
visited.set(nextValue, result);
|
|
29
|
+
for (const [key, value] of Object.entries(nextValue)) result[key] = mergeFormValuePatch(result[key], value, visited);
|
|
30
|
+
return result;
|
|
31
|
+
}
|
|
32
|
+
function getDefaultState() {
|
|
33
|
+
return {
|
|
34
|
+
actionWrapperClass: "",
|
|
35
|
+
collapsed: false,
|
|
36
|
+
collapseTriggerResize: false,
|
|
37
|
+
commonConfig: {},
|
|
38
|
+
handleReset: void 0,
|
|
39
|
+
handleSubmit: void 0,
|
|
40
|
+
handleValuesChange: void 0,
|
|
41
|
+
handleCollapsedChange: void 0,
|
|
42
|
+
resetButtonOptions: {},
|
|
43
|
+
schema: [],
|
|
44
|
+
scrollToFirstError: false,
|
|
45
|
+
showDefaultActions: true,
|
|
46
|
+
submitButtonOptions: {},
|
|
47
|
+
submitOnChange: false,
|
|
48
|
+
submitOnEnter: false,
|
|
49
|
+
wrapperClass: "grid-cols-1"
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
var FormApi = class {
|
|
53
|
+
form = {};
|
|
54
|
+
isMounted = false;
|
|
55
|
+
state = null;
|
|
56
|
+
stateHandler;
|
|
57
|
+
store;
|
|
58
|
+
/**
|
|
59
|
+
* Component instance mapping
|
|
60
|
+
*/
|
|
61
|
+
componentRefMap = /* @__PURE__ */ new Map();
|
|
62
|
+
latestSubmissionValues = null;
|
|
63
|
+
prevState = null;
|
|
64
|
+
constructor(options = {}) {
|
|
65
|
+
const { ...storeState } = options;
|
|
66
|
+
const defaultState = getDefaultState();
|
|
67
|
+
this.store = new Store({
|
|
68
|
+
...defaultState,
|
|
69
|
+
...storeState
|
|
70
|
+
});
|
|
71
|
+
this.store.subscribe((state) => {
|
|
72
|
+
this.prevState = this.state;
|
|
73
|
+
this.state = state;
|
|
74
|
+
this.updateState();
|
|
75
|
+
});
|
|
76
|
+
this.state = this.store.state;
|
|
77
|
+
this.stateHandler = new StateHandler();
|
|
78
|
+
bindMethods(this);
|
|
79
|
+
}
|
|
80
|
+
async clearValidation(fieldNames) {
|
|
81
|
+
(await this.getForm()).clearValidation(fieldNames);
|
|
82
|
+
}
|
|
83
|
+
formatValues(rawValues) {
|
|
84
|
+
if (this.state?.codec) return clone(encodeFormValues(this.state.codec, toRaw(rawValues)));
|
|
85
|
+
return clone(toRaw(rawValues));
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get the field component instance
|
|
89
|
+
* @param fieldName Field name
|
|
90
|
+
* @returns Component instance
|
|
91
|
+
*/
|
|
92
|
+
getFieldComponentRef(fieldName) {
|
|
93
|
+
let target = this.componentRefMap.has(fieldName) ? this.componentRefMap.get(fieldName) : void 0;
|
|
94
|
+
if (target && target.$.type.name === "AsyncComponentWrapper" && target.$.subTree.ref) {
|
|
95
|
+
if (Array.isArray(target.$.subTree.ref)) {
|
|
96
|
+
if (target.$.subTree.ref.length > 0 && isRef(target.$.subTree.ref[0]?.r)) target = target.$.subTree.ref[0]?.r.value;
|
|
97
|
+
} else if (isRef(target.$.subTree.ref.r)) target = target.$.subTree.ref.r.value;
|
|
98
|
+
}
|
|
99
|
+
return target;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Get the currently focused field, if there is no focused field, return undefined
|
|
103
|
+
*/
|
|
104
|
+
getFocusedField() {
|
|
105
|
+
for (const fieldName of this.componentRefMap.keys()) {
|
|
106
|
+
const ref = this.getFieldComponentRef(fieldName);
|
|
107
|
+
if (ref) {
|
|
108
|
+
let el = null;
|
|
109
|
+
if (ref instanceof HTMLElement) el = ref;
|
|
110
|
+
else if (ref.$el instanceof HTMLElement) el = ref.$el;
|
|
111
|
+
if (!el) continue;
|
|
112
|
+
if (el === document.activeElement || el.contains(document.activeElement)) return fieldName;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
getLatestSubmissionValues() {
|
|
117
|
+
return this.latestSubmissionValues || {};
|
|
118
|
+
}
|
|
119
|
+
async getRawValues() {
|
|
120
|
+
const form = await this.getForm();
|
|
121
|
+
return cloneFormValues(toRaw(form.values ?? {}));
|
|
122
|
+
}
|
|
123
|
+
getState() {
|
|
124
|
+
return this.state;
|
|
125
|
+
}
|
|
126
|
+
async getValues() {
|
|
127
|
+
const form = await this.getForm();
|
|
128
|
+
return this.formatValues(toRaw(form.values ?? {}));
|
|
129
|
+
}
|
|
130
|
+
async getValueSnapshot() {
|
|
131
|
+
const rawValues = await this.getRawValues();
|
|
132
|
+
return {
|
|
133
|
+
rawValues,
|
|
134
|
+
values: this.formatValues(rawValues)
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
async isFieldValid(fieldName) {
|
|
138
|
+
return (await this.getForm()).isFieldValid(fieldName);
|
|
139
|
+
}
|
|
140
|
+
merge(formApi) {
|
|
141
|
+
const chain = [this, formApi];
|
|
142
|
+
const proxy = new Proxy(formApi, { get(target, prop) {
|
|
143
|
+
if (prop === "merge") return (nextFormApi) => {
|
|
144
|
+
chain.push(nextFormApi);
|
|
145
|
+
return proxy;
|
|
146
|
+
};
|
|
147
|
+
if (prop === "submitAllForm") return async (needMerge = true) => {
|
|
148
|
+
try {
|
|
149
|
+
const results = await Promise.all(chain.map(async (api) => {
|
|
150
|
+
if (!(await api.validate()).valid) return;
|
|
151
|
+
return toRaw(await api.getValues() || {});
|
|
152
|
+
}));
|
|
153
|
+
if (needMerge) return Object.assign({}, ...results);
|
|
154
|
+
return results;
|
|
155
|
+
} catch (error) {
|
|
156
|
+
console.error("Validation error:", error);
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
return target[prop];
|
|
160
|
+
} });
|
|
161
|
+
return proxy;
|
|
162
|
+
}
|
|
163
|
+
mount(formActions, componentRefMap) {
|
|
164
|
+
if (!this.isMounted) {
|
|
165
|
+
this.form = formActions;
|
|
166
|
+
this.stateHandler.setConditionTrue();
|
|
167
|
+
let initialValues = {};
|
|
168
|
+
if (this.form.values) {
|
|
169
|
+
const rawInitialValues = toRaw(this.form.values);
|
|
170
|
+
try {
|
|
171
|
+
initialValues = this.formatValues(rawInitialValues);
|
|
172
|
+
} catch (error) {
|
|
173
|
+
if (!this.state?.codec) throw error;
|
|
174
|
+
console.warn("[Taman Form] Failed to encode initial values. Falling back to raw form values.", error);
|
|
175
|
+
initialValues = cloneFormValues(rawInitialValues);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
this.setLatestSubmissionValues(initialValues);
|
|
179
|
+
this.componentRefMap = componentRefMap ?? this.componentRefMap ?? /* @__PURE__ */ new Map();
|
|
180
|
+
this.isMounted = true;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
* Remove form items by field name
|
|
185
|
+
* @param fields
|
|
186
|
+
*/
|
|
187
|
+
async removeSchemaByFields(fields) {
|
|
188
|
+
const schema = this.state?.schema ?? [];
|
|
189
|
+
this.setState({ schema: removeFormSchemaByFields(schema, fields) });
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Reset the form
|
|
193
|
+
*/
|
|
194
|
+
async reset(state, opts) {
|
|
195
|
+
return (await this.getForm()).reset(state, opts);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Scroll to the first error field
|
|
199
|
+
* @param errors Validation error object
|
|
200
|
+
*/
|
|
201
|
+
scrollToFirstError(errors) {
|
|
202
|
+
const firstErrorFieldName = isString(errors) ? errors : Object.keys(errors)[0];
|
|
203
|
+
if (!firstErrorFieldName) return;
|
|
204
|
+
let el = document.querySelector(`[name="${firstErrorFieldName}"]`);
|
|
205
|
+
if (!el) {
|
|
206
|
+
const componentRef = this.getFieldComponentRef(firstErrorFieldName);
|
|
207
|
+
if (componentRef && componentRef.$el instanceof HTMLElement) el = componentRef.$el;
|
|
208
|
+
}
|
|
209
|
+
if (el) el.scrollIntoView({
|
|
210
|
+
behavior: "smooth",
|
|
211
|
+
block: "center",
|
|
212
|
+
inline: "nearest"
|
|
213
|
+
});
|
|
214
|
+
}
|
|
215
|
+
async setFieldError(fieldName, error) {
|
|
216
|
+
(await this.getForm()).setFieldError(fieldName, error);
|
|
217
|
+
}
|
|
218
|
+
async setFieldValue(field, value, shouldValidate) {
|
|
219
|
+
await (await this.getForm()).setFieldValue(field, value, shouldValidate);
|
|
220
|
+
}
|
|
221
|
+
setLatestSubmissionValues(values) {
|
|
222
|
+
this.latestSubmissionValues = { ...toRaw(values) };
|
|
223
|
+
}
|
|
224
|
+
setState(stateOrFn) {
|
|
225
|
+
if (isFunction(stateOrFn)) this.store.setState((prev) => {
|
|
226
|
+
return mergeWithArrayOverride(stateOrFn(prev), prev);
|
|
227
|
+
});
|
|
228
|
+
else this.store.setState((prev) => mergeWithArrayOverride(stateOrFn, prev));
|
|
229
|
+
}
|
|
230
|
+
async setSubmitValues(values, filterFields = true, shouldValidate = false) {
|
|
231
|
+
const codec = this.state?.codec;
|
|
232
|
+
if (!codec) throw new Error("[Taman Form] `setSubmitValues()` requires a form `codec`.");
|
|
233
|
+
const formValues = decodeFormValues(codec, values);
|
|
234
|
+
await this.setValues(formValues, filterFields, shouldValidate);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Set the form values
|
|
238
|
+
* @param fields record
|
|
239
|
+
* @param filterFields Filter fields that are not defined in the schema, default is true
|
|
240
|
+
* @param shouldValidate
|
|
241
|
+
*/
|
|
242
|
+
async setValues(fields, filterFields = true, shouldValidate = false) {
|
|
243
|
+
const form = await this.getForm();
|
|
244
|
+
if (!filterFields) {
|
|
245
|
+
form.setValues(fields, shouldValidate);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
const currentValues = toRaw(form.values ?? {});
|
|
249
|
+
const mergedFields = Object.fromEntries(Object.entries(fields).map(([key, value]) => [key, mergeFormValuePatch(currentValues[key], value)]));
|
|
250
|
+
const schemaFieldPaths = getFormFieldSchemas(this.state?.schema ?? []).map((schema) => resolveFieldNamePath(schema.fieldName).pathSegments);
|
|
251
|
+
const filterValue = (value, parentPath = []) => {
|
|
252
|
+
if (!isPlainFormObject(value)) return value;
|
|
253
|
+
const result = {};
|
|
254
|
+
for (const [key, currentValue] of Object.entries(value)) {
|
|
255
|
+
const currentPath = [...parentPath, key];
|
|
256
|
+
const matchingPaths = schemaFieldPaths.filter((schemaPath) => schemaPath.length >= currentPath.length && currentPath.every((pathSegment, index) => schemaPath[index] === pathSegment));
|
|
257
|
+
if (matchingPaths.length === 0) continue;
|
|
258
|
+
result[key] = matchingPaths.some((schemaPath) => schemaPath.length === currentPath.length) ? currentValue : filterValue(currentValue, currentPath);
|
|
259
|
+
}
|
|
260
|
+
return result;
|
|
261
|
+
};
|
|
262
|
+
const filteredFields = filterValue(mergedFields);
|
|
263
|
+
form.setValues(filteredFields, shouldValidate);
|
|
264
|
+
}
|
|
265
|
+
async submit(e) {
|
|
266
|
+
e?.preventDefault();
|
|
267
|
+
e?.stopPropagation();
|
|
268
|
+
await (await this.getForm()).submit();
|
|
269
|
+
return this.submitValues();
|
|
270
|
+
}
|
|
271
|
+
unmount() {
|
|
272
|
+
this.form?.reset?.();
|
|
273
|
+
this.componentRefMap = /* @__PURE__ */ new Map();
|
|
274
|
+
this.latestSubmissionValues = null;
|
|
275
|
+
this.isMounted = false;
|
|
276
|
+
this.stateHandler.reset();
|
|
277
|
+
}
|
|
278
|
+
updateSchema(schema) {
|
|
279
|
+
const updated = [...schema];
|
|
280
|
+
if (!updated.every((item) => Reflect.has(item, "fieldName") && item.fieldName)) {
|
|
281
|
+
console.error("All items in the schema array must have a valid `fieldName` property to be updated");
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
const currentSchema = updateFormSchemaList([...this.state?.schema ?? []], updated);
|
|
285
|
+
this.setState({ schema: currentSchema });
|
|
286
|
+
}
|
|
287
|
+
async validate() {
|
|
288
|
+
const validateResult = await (await this.getForm()).validate();
|
|
289
|
+
if (Object.keys(validateResult?.errors ?? {}).length > 0 && this.state?.scrollToFirstError) this.scrollToFirstError(validateResult.errors);
|
|
290
|
+
return validateResult;
|
|
291
|
+
}
|
|
292
|
+
async validateAndSubmit() {
|
|
293
|
+
const { valid } = await this.validate();
|
|
294
|
+
if (!valid) return;
|
|
295
|
+
return this.submitValues();
|
|
296
|
+
}
|
|
297
|
+
async validateField(fieldName) {
|
|
298
|
+
const validateResult = await (await this.getForm()).validateField(fieldName);
|
|
299
|
+
if (Object.keys(validateResult?.errors ?? {}).length > 0 && this.state?.scrollToFirstError) this.scrollToFirstError(fieldName);
|
|
300
|
+
return validateResult;
|
|
301
|
+
}
|
|
302
|
+
async getForm() {
|
|
303
|
+
if (!this.isMounted) await this.stateHandler.waitForCondition();
|
|
304
|
+
if (!this.form?.meta) throw new Error("<TamanForm /> is not mounted");
|
|
305
|
+
return this.form;
|
|
306
|
+
}
|
|
307
|
+
async submitValues() {
|
|
308
|
+
const { rawValues, values } = await this.getValueSnapshot();
|
|
309
|
+
this.setLatestSubmissionValues(values);
|
|
310
|
+
await this.state?.handleSubmit?.(values, rawValues);
|
|
311
|
+
return values;
|
|
312
|
+
}
|
|
313
|
+
updateState() {
|
|
314
|
+
const currentSchema = getFormFieldSchemas(this.state?.schema ?? []);
|
|
315
|
+
const prevSchema = getFormFieldSchemas(this.prevState?.schema ?? []);
|
|
316
|
+
if (currentSchema.length < prevSchema.length) {
|
|
317
|
+
const currentFields = new Set(currentSchema.map((item) => item.fieldName));
|
|
318
|
+
const deletedSchema = prevSchema.filter((item) => !currentFields.has(item.fieldName));
|
|
319
|
+
for (const schema of deletedSchema) this.form?.setFieldValue?.(schema.fieldName, void 0);
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
};
|
|
323
|
+
//#endregion
|
|
324
|
+
export { FormApi };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { TamanFileUploadProps } from "../components/file-upload/taman-file-upload.types.js";
|
|
2
|
+
import { TamanInputCurrencyProps } from "../components/input/taman-input-currency.types.js";
|
|
3
|
+
import { TamanInputDateProps } from "../components/input-date/taman-input-date.types.js";
|
|
4
|
+
import "../index.js";
|
|
5
|
+
import { TamanFormFieldArrayProps } from "./components/form-field-array.types.js";
|
|
6
|
+
import { Component } from "vue";
|
|
7
|
+
import { CheckboxGroupProps, CheckboxProps, InputMenuProps, InputNumberProps, InputProps, InputRatingProps, InputTagsProps, InputTimeProps, PinInputProps, RadioGroupProps, SelectMenuProps, SelectProps, SeparatorProps, SliderProps, SwitchProps, TextareaProps } from "pohon-ui";
|
|
8
|
+
//#region src/form/form.built-ins.d.ts
|
|
9
|
+
interface BuiltInFormComponentPropsMap {
|
|
10
|
+
Checkbox: CheckboxProps;
|
|
11
|
+
CheckboxGroup: CheckboxGroupProps;
|
|
12
|
+
FileUpload: TamanFileUploadProps<false> | TamanFileUploadProps<true>;
|
|
13
|
+
Input: InputProps;
|
|
14
|
+
InputDate: TamanInputDateProps<false> | TamanInputDateProps<true>;
|
|
15
|
+
InputNumber: InputNumberProps;
|
|
16
|
+
InputCurrency: TamanInputCurrencyProps;
|
|
17
|
+
InputMenu: InputMenuProps;
|
|
18
|
+
InputPassword: InputProps & {
|
|
19
|
+
passwordStrength?: boolean;
|
|
20
|
+
};
|
|
21
|
+
InputRating: InputRatingProps;
|
|
22
|
+
InputTags: InputTagsProps;
|
|
23
|
+
InputTime: InputTimeProps;
|
|
24
|
+
PinInput: PinInputProps;
|
|
25
|
+
RadioGroup: RadioGroupProps;
|
|
26
|
+
Select: SelectProps;
|
|
27
|
+
SelectMenu: SelectMenuProps;
|
|
28
|
+
Slider: SliderProps;
|
|
29
|
+
Switch: SwitchProps;
|
|
30
|
+
Textarea: TextareaProps;
|
|
31
|
+
Separator: SeparatorProps;
|
|
32
|
+
TamanFormFieldArray: TamanFormFieldArrayProps;
|
|
33
|
+
}
|
|
34
|
+
type BuiltInFormComponentType = keyof BuiltInFormComponentPropsMap;
|
|
35
|
+
//#endregion
|
|
36
|
+
export { BuiltInFormComponentPropsMap, BuiltInFormComponentType };
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import _sfc_main from "../components/file-upload/taman-file-upload.mjs";
|
|
2
|
+
import _sfc_main$1 from "../components/input/taman-input-currency.mjs";
|
|
3
|
+
import _sfc_main$2 from "../components/input/taman-input-password.mjs";
|
|
4
|
+
import _sfc_main$3 from "../components/input-date/taman-input-date.mjs";
|
|
5
|
+
import "../index.mjs";
|
|
6
|
+
import _sfc_main$4 from "./components/form-field-array.mjs";
|
|
7
|
+
import PSeparator from "pohon-ui/components/Separator.vue";
|
|
8
|
+
import PInput from "pohon-ui/components/Input.vue";
|
|
9
|
+
import PCheckbox from "pohon-ui/components/Checkbox.vue";
|
|
10
|
+
import PCheckboxGroup from "pohon-ui/components/CheckboxGroup.vue";
|
|
11
|
+
import PInputMenu from "pohon-ui/components/InputMenu.vue";
|
|
12
|
+
import PInputNumber from "pohon-ui/components/InputNumber.vue";
|
|
13
|
+
import PInputRating from "pohon-ui/components/InputRating.vue";
|
|
14
|
+
import PInputTags from "pohon-ui/components/InputTags.vue";
|
|
15
|
+
import PInputTime from "pohon-ui/components/InputTime.vue";
|
|
16
|
+
import PPinInput from "pohon-ui/components/PinInput.vue";
|
|
17
|
+
import PRadioGroup from "pohon-ui/components/RadioGroup.vue";
|
|
18
|
+
import PSelect from "pohon-ui/components/Select.vue";
|
|
19
|
+
import PSelectMenu from "pohon-ui/components/SelectMenu.vue";
|
|
20
|
+
import PSlider from "pohon-ui/components/Slider.vue";
|
|
21
|
+
import PSwitch from "pohon-ui/components/Switch.vue";
|
|
22
|
+
import PTextarea from "pohon-ui/components/Textarea.vue";
|
|
23
|
+
//#region src/form/form.built-ins.ts
|
|
24
|
+
const BUILT_IN_COMPONENT_MAP = {
|
|
25
|
+
Checkbox: PCheckbox,
|
|
26
|
+
CheckboxGroup: PCheckboxGroup,
|
|
27
|
+
FileUpload: _sfc_main,
|
|
28
|
+
Input: PInput,
|
|
29
|
+
InputCurrency: _sfc_main$1,
|
|
30
|
+
InputDate: _sfc_main$3,
|
|
31
|
+
InputMenu: PInputMenu,
|
|
32
|
+
InputNumber: PInputNumber,
|
|
33
|
+
InputPassword: _sfc_main$2,
|
|
34
|
+
InputRating: PInputRating,
|
|
35
|
+
InputTags: PInputTags,
|
|
36
|
+
InputTime: PInputTime,
|
|
37
|
+
PinInput: PPinInput,
|
|
38
|
+
RadioGroup: PRadioGroup,
|
|
39
|
+
Select: PSelect,
|
|
40
|
+
SelectMenu: PSelectMenu,
|
|
41
|
+
Separator: PSeparator,
|
|
42
|
+
Slider: PSlider,
|
|
43
|
+
Switch: PSwitch,
|
|
44
|
+
TamanFormFieldArray: _sfc_main$4,
|
|
45
|
+
Textarea: PTextarea
|
|
46
|
+
};
|
|
47
|
+
//#endregion
|
|
48
|
+
export { BUILT_IN_COMPONENT_MAP };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { FormCodec } from "./form.types.js";
|
|
2
|
+
import { CalendarDateCodecOptions, CalendarDateCodecOptions as CalendarDateCodecOptions$1 } from "@vinicunca/taman-core/utils";
|
|
3
|
+
//#region src/form/form.codec.d.ts
|
|
4
|
+
type FormCodecPhase = 'decode' | 'encode';
|
|
5
|
+
declare class FormCodecError extends Error {
|
|
6
|
+
readonly cause: unknown;
|
|
7
|
+
readonly phase: FormCodecPhase;
|
|
8
|
+
constructor(phase: FormCodecPhase, cause: unknown);
|
|
9
|
+
}
|
|
10
|
+
declare function createCalendarDateCodec$1(options?: CalendarDateCodecOptions): FormCodec;
|
|
11
|
+
declare function createTimeCodec$1(): FormCodec;
|
|
12
|
+
declare function createCalendarDateTimeCodec(options?: CalendarDateCodecOptions): FormCodec;
|
|
13
|
+
declare const calendarDateCodec: FormCodec;
|
|
14
|
+
declare const timeCodec: FormCodec;
|
|
15
|
+
declare const calendarDateTimeCodec: FormCodec;
|
|
16
|
+
//#endregion
|
|
17
|
+
export { type CalendarDateCodecOptions$1 as CalendarDateCodecOptions, FormCodecError, FormCodecPhase, calendarDateCodec, calendarDateTimeCodec, createCalendarDateCodec$1 as createCalendarDateCodec, createCalendarDateTimeCodec, createTimeCodec$1 as createTimeCodec, timeCodec };
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { createCalendarDateCodec, createTimeCodec } from "@vinicunca/taman-core/utils";
|
|
2
|
+
//#region src/form/form.codec.ts
|
|
3
|
+
var FormCodecError = class extends Error {
|
|
4
|
+
cause;
|
|
5
|
+
phase;
|
|
6
|
+
constructor(phase, cause) {
|
|
7
|
+
super(`[Taman Form] Failed to ${phase} form values.`);
|
|
8
|
+
this.name = "FormCodecError";
|
|
9
|
+
this.cause = cause;
|
|
10
|
+
this.phase = phase;
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
function decodeFormValues(codec, values) {
|
|
14
|
+
try {
|
|
15
|
+
return codec.decode(values);
|
|
16
|
+
} catch (error) {
|
|
17
|
+
throw new FormCodecError("decode", error);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
function encodeFormValues(codec, values) {
|
|
21
|
+
try {
|
|
22
|
+
return codec.encode(values);
|
|
23
|
+
} catch (error) {
|
|
24
|
+
throw new FormCodecError("encode", error);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
function createCalendarDateCodec$1(options) {
|
|
28
|
+
return createCalendarDateCodec(options);
|
|
29
|
+
}
|
|
30
|
+
function createTimeCodec$1() {
|
|
31
|
+
return createTimeCodec();
|
|
32
|
+
}
|
|
33
|
+
function createCalendarDateTimeCodec(options) {
|
|
34
|
+
const calendarDate = createCalendarDateCodec$1(options);
|
|
35
|
+
const time = createTimeCodec$1();
|
|
36
|
+
return {
|
|
37
|
+
decode: (values) => time.decode(calendarDate.decode(values)),
|
|
38
|
+
encode: (values) => time.encode(calendarDate.encode(values))
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
const calendarDateCodec = createCalendarDateCodec$1();
|
|
42
|
+
const timeCodec = createTimeCodec$1();
|
|
43
|
+
const calendarDateTimeCodec = createCalendarDateTimeCodec();
|
|
44
|
+
//#endregion
|
|
45
|
+
export { FormCodecError, calendarDateCodec, calendarDateTimeCodec, createCalendarDateCodec$1 as createCalendarDateCodec, createCalendarDateTimeCodec, createTimeCodec$1 as createTimeCodec, decodeFormValues, encodeFormValues, timeCodec };
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { registerFormRules } from "./form.rule-registry.mjs";
|
|
2
|
+
import { BUILT_IN_COMPONENT_MAP } from "./form.built-ins.mjs";
|
|
3
|
+
import { globalShareState } from "@vinicunca/taman-core/global-state";
|
|
4
|
+
//#region src/form/form.config.ts
|
|
5
|
+
const DEFAULT_FORM_COMMON_CONFIG = {};
|
|
6
|
+
const COMPONENT_MAP = { ...BUILT_IN_COMPONENT_MAP };
|
|
7
|
+
function replaceRecord(target, source) {
|
|
8
|
+
for (const key of Object.keys(target)) Reflect.deleteProperty(target, key);
|
|
9
|
+
Object.assign(target, source);
|
|
10
|
+
}
|
|
11
|
+
let lastAdapterOptions;
|
|
12
|
+
/** Rebuild COMPONENT_MAP from globalShareState after this module is HMR'd. */
|
|
13
|
+
function rehydrateFormComponentMaps() {
|
|
14
|
+
const components = globalShareState.getComponents();
|
|
15
|
+
const nextComponentMap = {
|
|
16
|
+
...BUILT_IN_COMPONENT_MAP,
|
|
17
|
+
...components
|
|
18
|
+
};
|
|
19
|
+
replaceRecord(COMPONENT_MAP, nextComponentMap);
|
|
20
|
+
}
|
|
21
|
+
function getFormComponentMap() {
|
|
22
|
+
return {
|
|
23
|
+
...BUILT_IN_COMPONENT_MAP,
|
|
24
|
+
...globalShareState.getComponents()
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function setupTamanForm(options) {
|
|
28
|
+
lastAdapterOptions = options;
|
|
29
|
+
const { rules } = options;
|
|
30
|
+
if (rules) registerFormRules(rules);
|
|
31
|
+
rehydrateFormComponentMaps();
|
|
32
|
+
}
|
|
33
|
+
const hot = import.meta.hot;
|
|
34
|
+
if (hot) {
|
|
35
|
+
hot.dispose((data) => {
|
|
36
|
+
data.lastAdapterOptions = lastAdapterOptions;
|
|
37
|
+
});
|
|
38
|
+
const resumed = hot.data?.lastAdapterOptions;
|
|
39
|
+
if (resumed) setupTamanForm(resumed);
|
|
40
|
+
else rehydrateFormComponentMaps();
|
|
41
|
+
}
|
|
42
|
+
//#endregion
|
|
43
|
+
export { COMPONENT_MAP, DEFAULT_FORM_COMMON_CONFIG, getFormComponentMap, rehydrateFormComponentMaps, setupTamanForm };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { markRaw } from "vue";
|
|
2
|
+
//#region src/form/form.empty-value.ts
|
|
3
|
+
/**
|
|
4
|
+
* perkakas `isEmpty` treats a File as empty because `Object.keys(file)` is [].
|
|
5
|
+
* Form required/selectRequired rules must not use that for upload values.
|
|
6
|
+
*/
|
|
7
|
+
function isEmptyFormValue(value) {
|
|
8
|
+
if (value instanceof File || value instanceof Blob) return false;
|
|
9
|
+
if (value == null || value === "") return true;
|
|
10
|
+
if (Array.isArray(value)) return value.length === 0 || value.every((item) => isEmptyFormValue(item));
|
|
11
|
+
if (typeof value === "object") return Object.keys(value).length === 0;
|
|
12
|
+
return false;
|
|
13
|
+
}
|
|
14
|
+
function toFormFieldValue(value) {
|
|
15
|
+
if (value instanceof File || value instanceof Blob) return markRaw(value);
|
|
16
|
+
if (Array.isArray(value)) return value.map((item) => toFormFieldValue(item));
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
//#endregion
|
|
20
|
+
export { isEmptyFormValue, toFormFieldValue };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import "@vinicunca/taman-core/utils";
|
|
2
|
+
//#region src/form/form.field-name.ts
|
|
3
|
+
function resolveChildUpdateFieldName(parentFieldName, fieldName) {
|
|
4
|
+
if (fieldName.startsWith(`${parentFieldName}.`)) return fieldName.slice(parentFieldName.length + 1);
|
|
5
|
+
const indexedPrefix = `${parentFieldName}[`;
|
|
6
|
+
if (!fieldName.startsWith(indexedPrefix)) return;
|
|
7
|
+
const closeIndex = fieldName.indexOf("]", indexedPrefix.length);
|
|
8
|
+
if (closeIndex === -1 || fieldName[closeIndex + 1] !== ".") return;
|
|
9
|
+
return fieldName.slice(closeIndex + 2);
|
|
10
|
+
}
|
|
11
|
+
function resolveFieldNamePath(fieldName) {
|
|
12
|
+
if (fieldName.startsWith("[") && fieldName.endsWith("]")) {
|
|
13
|
+
const rawKey = fieldName.slice(1, -1);
|
|
14
|
+
return {
|
|
15
|
+
pathSegments: [rawKey],
|
|
16
|
+
rawKey
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
return {
|
|
20
|
+
pathSegments: fieldName.match(/[^.[\]]+/g) ?? [],
|
|
21
|
+
rawKey: void 0
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
//#endregion
|
|
25
|
+
export { resolveChildUpdateFieldName, resolveFieldNamePath };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
//#region src/form/form.rule-registry.ts
|
|
2
|
+
const FORM_RULES = /* @__PURE__ */ new Map();
|
|
3
|
+
function getFormRule(name) {
|
|
4
|
+
return FORM_RULES.get(name);
|
|
5
|
+
}
|
|
6
|
+
function registerFormRules(rules) {
|
|
7
|
+
for (const [name, validator] of Object.entries(rules)) if (validator) FORM_RULES.set(name, validator);
|
|
8
|
+
}
|
|
9
|
+
//#endregion
|
|
10
|
+
export { getFormRule, registerFormRules };
|