native-document 1.0.164 → 1.0.166
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/components.d.ts +2 -0
- package/devtools/widget.js +1 -1
- package/dist/native-document.components.min.js +11074 -2735
- package/dist/native-document.dev.js +2269 -392
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/eslint.config.js +28 -33
- package/i18n.js +1 -1
- package/i18n.ts +2 -0
- package/index.js +4 -1
- package/package.json +3 -2
- package/src/components/$traits/has-draggable/HasDraggable.d.ts +4 -0
- package/src/components/$traits/has-draggable/HasDraggable.js +13 -0
- package/src/components/$traits/has-items/HasItems.d.ts +9 -0
- package/src/components/$traits/has-items/HasItems.js +6 -6
- package/src/components/$traits/has-position/HasFullPosition.d.ts +14 -0
- package/src/components/$traits/has-position/HasFullPosition.js +44 -0
- package/src/components/$traits/has-position/HasPosition.d.ts +7 -0
- package/src/components/$traits/has-position/HasPosition.js +23 -1
- package/src/components/$traits/has-resizable/HasResizable.d.ts +13 -0
- package/src/components/$traits/has-resizable/HasResizable.js +9 -0
- package/src/components/$traits/has-validation/HasValidation.d.ts +17 -0
- package/src/components/$traits/has-validation/HasValidation.js +54 -7
- package/src/components/BaseComponent.d.ts +32 -0
- package/src/components/BaseComponent.js +65 -9
- package/src/components/accordion/Accordion.js +39 -14
- package/src/components/accordion/AccordionItem.js +45 -14
- package/src/components/accordion/index.js +2 -2
- package/src/components/accordion/types/Accordion.d.ts +47 -0
- package/src/components/accordion/types/AccordionItem.d.ts +48 -0
- package/src/components/alert/Alert.js +70 -38
- package/src/components/alert/index.js +2 -2
- package/src/components/alert/types/Alert.d.ts +62 -0
- package/src/components/avatar/Avatar.js +49 -12
- package/src/components/avatar/AvatarGroup.js +50 -2
- package/src/components/avatar/index.js +2 -2
- package/src/components/avatar/types/Avatar.d.ts +74 -0
- package/src/components/avatar/types/AvatarGroup.d.ts +32 -0
- package/src/components/badge/Badge.js +125 -5
- package/src/components/badge/index.js +2 -2
- package/src/components/badge/types/Badge.d.ts +51 -0
- package/src/components/breadcrumb/BreadCrumb.js +61 -5
- package/src/components/breadcrumb/index.js +2 -2
- package/src/components/breadcrumb/types/BreadCrumb.d.ts +42 -0
- package/src/components/button/Button.js +164 -9
- package/src/components/button/index.js +1 -1
- package/src/components/button/types/Button.d.ts +62 -0
- package/src/components/card/Card.js +128 -10
- package/src/components/card/index.js +3 -3
- package/src/components/card/types/Card.d.ts +42 -0
- package/src/components/context-menu/ContextMenu.js +49 -5
- package/src/components/context-menu/ContextMenuGroup.js +15 -2
- package/src/components/context-menu/ContextMenuItem.js +14 -2
- package/src/components/context-menu/index.js +5 -5
- package/src/components/context-menu/types/ContextMenu.d.ts +30 -0
- package/src/components/context-menu/types/ContextMenuGroup.d.ts +18 -0
- package/src/components/context-menu/types/ContextMenuItem.d.ts +18 -0
- package/src/components/divider/Divider.js +120 -4
- package/src/components/divider/index.js +3 -3
- package/src/components/divider/types/Divider.d.ts +55 -0
- package/src/components/dropdown/Dropdown.js +239 -16
- package/src/components/dropdown/DropdownDivider.js +22 -2
- package/src/components/dropdown/DropdownGroup.js +44 -5
- package/src/components/dropdown/DropdownItem.js +76 -3
- package/src/components/dropdown/DropdownTrigger.js +49 -20
- package/src/components/dropdown/helpers.js +1 -1
- package/src/components/dropdown/index.js +6 -6
- package/src/components/dropdown/types/Dropdown.d.ts +88 -0
- package/src/components/dropdown/types/DropdownDivider.d.ts +20 -0
- package/src/components/dropdown/types/DropdownGroup.d.ts +25 -0
- package/src/components/dropdown/types/DropdownItem.d.ts +41 -0
- package/src/components/dropdown/types/DropdownTrigger.d.ts +32 -0
- package/src/components/form/FormControl.js +156 -13
- package/src/components/form/field/Field.js +172 -9
- package/src/components/form/field/FieldCollection.js +116 -12
- package/src/components/form/field/types/AutocompleteField.js +92 -2
- package/src/components/form/field/types/CheckboxField.js +43 -2
- package/src/components/form/field/types/CheckboxGroupField.js +83 -6
- package/src/components/form/field/types/ColorField.js +56 -3
- package/src/components/form/field/types/DateField.js +155 -4
- package/src/components/form/field/types/EmailField.js +54 -4
- package/src/components/form/field/types/FileField.js +140 -6
- package/src/components/form/field/types/HiddenField.js +27 -1
- package/src/components/form/field/types/ImageField.js +82 -3
- package/src/components/form/field/types/NumberField.js +97 -4
- package/src/components/form/field/types/PasswordField.js +103 -7
- package/src/components/form/field/types/RadioField.js +75 -4
- package/src/components/form/field/types/RangeField.js +67 -1
- package/src/components/form/field/types/SearchField.js +41 -2
- package/src/components/form/field/types/SelectField.js +133 -4
- package/src/components/form/field/types/StringField.js +91 -2
- package/src/components/form/field/types/TelField.js +55 -4
- package/src/components/form/field/types/TextAreaField.js +76 -2
- package/src/components/form/field/types/TimeField.js +120 -5
- package/src/components/form/field/types/UrlField.js +59 -4
- package/src/components/form/field/types/file-field-mode/FileAvatarMode.js +83 -4
- package/src/components/form/field/types/file-field-mode/FileDropzoneMode.js +61 -3
- package/src/components/form/field/types/file-field-mode/FileItemPreview.js +79 -3
- package/src/components/form/field/types/file-field-mode/FileNativeMode.js +24 -2
- package/src/components/form/field/types/file-field-mode/FileUploadButtonMode.js +64 -3
- package/src/components/form/field/types/file-field-mode/FileWallMode.js +56 -3
- package/src/components/form/index.js +28 -28
- package/src/components/form/types/Field.d.ts +73 -0
- package/src/components/form/types/FieldCollection.d.ts +53 -0
- package/src/components/form/types/FormControl.d.ts +64 -0
- package/src/components/form/types/fields/AutocompleteField.d.ts +48 -0
- package/src/components/form/types/fields/CheckboxField.d.ts +33 -0
- package/src/components/form/types/fields/CheckboxGroupField.d.ts +49 -0
- package/src/components/form/types/fields/ColorField.d.ts +37 -0
- package/src/components/form/types/fields/DateField.d.ts +70 -0
- package/src/components/form/types/fields/EmailField.d.ts +35 -0
- package/src/components/form/types/fields/FileAvatarMode.d.ts +46 -0
- package/src/components/form/types/fields/FileDropzoneMode.d.ts +28 -0
- package/src/components/form/types/fields/FileField.d.ts +56 -0
- package/src/components/form/types/fields/FileItemPreview.d.ts +35 -0
- package/src/components/form/types/fields/FileNativeMode.d.ts +21 -0
- package/src/components/form/types/fields/FileUploadButtonMode.d.ts +34 -0
- package/src/components/form/types/fields/FileWallMode.d.ts +32 -0
- package/src/components/form/types/fields/HiddenField.d.ts +26 -0
- package/src/components/form/types/fields/ImageField.d.ts +45 -0
- package/src/components/form/types/fields/NumberField.d.ts +48 -0
- package/src/components/form/types/fields/PasswordField.d.ts +46 -0
- package/src/components/form/types/fields/RadioField.d.ts +48 -0
- package/src/components/form/types/fields/RangeField.d.ts +44 -0
- package/src/components/form/types/fields/SearchField.d.ts +34 -0
- package/src/components/form/types/fields/SelectField.d.ts +71 -0
- package/src/components/form/types/fields/StringField.d.ts +48 -0
- package/src/components/form/types/fields/TelField.d.ts +37 -0
- package/src/components/form/types/fields/TextAreaField.d.ts +44 -0
- package/src/components/form/types/fields/TimeField.d.ts +51 -0
- package/src/components/form/types/fields/UrlField.d.ts +35 -0
- package/src/components/form/validation/Validation.js +54 -54
- package/src/components/index.d.ts +160 -0
- package/src/components/list/List.js +99 -15
- package/src/components/list/ListGroup.js +58 -8
- package/src/components/list/ListItem.js +79 -18
- package/src/components/list/index.js +5 -5
- package/src/components/list/types/List.d.ts +43 -0
- package/src/components/list/types/ListGroup.d.ts +37 -0
- package/src/components/list/types/ListItem.d.ts +42 -0
- package/src/components/menu/HasMenuItem.js +55 -6
- package/src/components/menu/Menu.js +113 -22
- package/src/components/menu/MenuDivider.js +18 -2
- package/src/components/menu/MenuGroup.js +61 -6
- package/src/components/menu/MenuItem.js +95 -11
- package/src/components/menu/MenuLink.js +27 -2
- package/src/components/menu/index.js +6 -6
- package/src/components/menu/types/Menu.d.ts +60 -0
- package/src/components/menu/types/MenuDivider.d.ts +19 -0
- package/src/components/menu/types/MenuGroup.d.ts +44 -0
- package/src/components/menu/types/MenuItem.d.ts +46 -0
- package/src/components/menu/types/MenuLink.d.ts +16 -0
- package/src/components/modal/Modal.js +258 -17
- package/src/components/modal/index.js +3 -3
- package/src/components/modal/types/Modal.d.ts +94 -0
- package/src/components/pagination/Pagination.js +155 -7
- package/src/components/pagination/index.js +3 -3
- package/src/components/pagination/types/Pagination.d.ts +68 -0
- package/src/components/popover/Popover.js +198 -11
- package/src/components/popover/PopoverFooter.js +33 -9
- package/src/components/popover/PopoverHeader.js +33 -8
- package/src/components/popover/index.js +4 -4
- package/src/components/popover/types/Popover.d.ts +83 -0
- package/src/components/popover/types/PopoverFooter.d.ts +24 -0
- package/src/components/popover/types/PopoverHeader.d.ts +26 -0
- package/src/components/progress/Progress.js +182 -13
- package/src/components/progress/index.js +3 -3
- package/src/components/progress/types/Progress.d.ts +77 -0
- package/src/components/skeleton/Skeleton.js +117 -49
- package/src/components/skeleton/index.js +3 -3
- package/src/components/skeleton/types/Skeleton.d.ts +55 -0
- package/src/components/slider/Slider.js +207 -10
- package/src/components/slider/index.js +2 -2
- package/src/components/slider/types/Slider.d.ts +82 -0
- package/src/components/spacer/Spacer.js +11 -2
- package/src/components/spacer/index.js +2 -2
- package/src/components/spacer/types/Spacer.d.ts +19 -0
- package/src/components/spinner/Spinner.js +180 -9
- package/src/components/spinner/index.js +3 -3
- package/src/components/spinner/types/Spinner.d.ts +71 -0
- package/src/components/splitter/Splitter.js +76 -13
- package/src/components/splitter/SplitterGutter.js +67 -5
- package/src/components/splitter/SplitterPanel.js +69 -2
- package/src/components/splitter/index.js +5 -5
- package/src/components/splitter/types/Splitter.d.ts +38 -0
- package/src/components/splitter/types/SplitterGutter.d.ts +38 -0
- package/src/components/splitter/types/SplitterPanel.d.ts +41 -0
- package/src/components/stacks/AbsoluteStack.js +23 -3
- package/src/components/stacks/FixedStack.js +23 -3
- package/src/components/stacks/HStack.js +24 -3
- package/src/components/stacks/PositionStack.js +111 -3
- package/src/components/stacks/RelativeStack.js +23 -3
- package/src/components/stacks/Stack.js +73 -2
- package/src/components/stacks/VStack.js +24 -4
- package/src/components/stacks/index.js +7 -7
- package/src/components/stacks/types/AbsoluteStack.d.ts +16 -0
- package/src/components/stacks/types/FixedStack.d.ts +16 -0
- package/src/components/stacks/types/HStack.d.ts +16 -0
- package/src/components/stacks/types/PositionStack.d.ts +54 -0
- package/src/components/stacks/types/RelativeStack.d.ts +17 -0
- package/src/components/stacks/types/Stack.d.ts +39 -0
- package/src/components/stacks/types/VStack.d.ts +16 -0
- package/src/components/stepper/Stepper.js +152 -12
- package/src/components/stepper/StepperStep.js +104 -3
- package/src/components/stepper/index.js +4 -4
- package/src/components/stepper/types/Stepper.d.ts +68 -0
- package/src/components/stepper/types/StepperStep.d.ts +54 -0
- package/src/components/switch/Switch.js +143 -6
- package/src/components/switch/index.js +1 -1
- package/src/components/switch/types/Switch.d.ts +55 -0
- package/src/components/table/Column.js +105 -6
- package/src/components/table/ColumnGroup.js +48 -3
- package/src/components/table/DataTable.js +256 -19
- package/src/components/table/SimpleTable.js +58 -4
- package/src/components/table/index.js +2 -2
- package/src/components/table/types/Column.d.ts +49 -0
- package/src/components/table/types/ColumnGroup.d.ts +28 -0
- package/src/components/table/types/DataTable.d.ts +97 -0
- package/src/components/table/types/SimpleTable.d.ts +40 -0
- package/src/components/tabs/Tabs.js +192 -5
- package/src/components/tabs/index.js +3 -3
- package/src/components/tabs/types/Tabs.d.ts +78 -0
- package/src/components/toast/Toast.js +133 -5
- package/src/components/toast/index.js +3 -3
- package/src/components/toast/types/Toast.d.ts +57 -0
- package/src/components/toast/types/ToastError.d.ts +7 -0
- package/src/components/toast/types/ToastInfo.d.ts +7 -0
- package/src/components/toast/types/ToastSuccess.d.ts +7 -0
- package/src/components/toast/types/ToastWarning.d.ts +7 -0
- package/src/components/tooltip/Tooltip.js +157 -13
- package/src/components/tooltip/index.js +2 -2
- package/src/components/tooltip/prototypes.js +1 -1
- package/src/components/tooltip/types/Tooltip.d.ts +65 -0
- package/src/core/data/MemoryManager.js +2 -2
- package/src/core/data/Observable.js +15 -18
- package/src/core/data/ObservableArray.js +118 -46
- package/src/core/data/ObservableChecker.js +2 -2
- package/src/core/data/ObservableItem.js +135 -21
- package/src/core/data/ObservableObject.js +126 -35
- package/src/core/data/ObservableResource.js +113 -3
- package/src/core/data/Store.js +142 -26
- package/src/core/data/observable-helpers/observable.is-to.js +196 -1
- package/src/core/data/observable-helpers/observable.prototypes.js +33 -8
- package/src/core/elements/anchor/anchor-with-sentinel.js +23 -2
- package/src/core/elements/anchor/anchor.js +16 -7
- package/src/core/elements/anchor/one-child-anchor-overwriting.js +2 -2
- package/src/core/elements/content-formatter.js +1 -1
- package/src/core/elements/control/for-each-array.js +9 -9
- package/src/core/elements/control/for-each.js +14 -14
- package/src/core/elements/control/show-if.js +11 -11
- package/src/core/elements/control/show-when.js +5 -5
- package/src/core/elements/control/switch.js +14 -14
- package/src/core/elements/description-list.js +1 -1
- package/src/core/elements/form.js +2 -2
- package/src/core/elements/fragment.js +1 -1
- package/src/core/elements/html5-semantics.js +1 -1
- package/src/core/elements/img.js +3 -3
- package/src/core/elements/interactive.js +1 -1
- package/src/core/elements/list.js +1 -1
- package/src/core/elements/medias.js +1 -1
- package/src/core/elements/meta-data.js +1 -1
- package/src/core/elements/svg.js +1 -1
- package/src/core/elements/table.js +1 -1
- package/src/core/errors/ArgTypesError.js +1 -1
- package/src/core/utils/HasEventEmitter.js +36 -2
- package/src/core/utils/args-types.js +9 -9
- package/src/core/utils/cache.js +1 -1
- package/src/core/utils/callback-handler.js +29 -0
- package/src/core/utils/debug-manager.js +6 -6
- package/src/core/utils/events.js +139 -139
- package/src/core/utils/filters/date.js +84 -3
- package/src/core/utils/filters/standard.js +136 -11
- package/src/core/utils/filters/strings.js +34 -2
- package/src/core/utils/filters/utils.js +40 -4
- package/src/core/utils/formatters.js +4 -4
- package/src/core/utils/helpers.js +39 -7
- package/src/core/utils/localstorage.js +11 -11
- package/src/core/utils/memoize.js +56 -3
- package/src/core/utils/plugins-manager.js +3 -3
- package/src/core/utils/property-accumulator.js +6 -6
- package/src/core/utils/prototypes.js +26 -1
- package/src/core/utils/shortcut-manager.js +2 -2
- package/src/core/utils/validator.js +8 -8
- package/src/core/wrappers/AttributesWrapper.js +32 -22
- package/src/core/wrappers/DocumentObserver.js +3 -3
- package/src/core/wrappers/ElementCreator.js +5 -5
- package/src/core/wrappers/HtmlElementWrapper.js +38 -12
- package/src/core/wrappers/NDElement.js +328 -22
- package/src/core/wrappers/NdPrototype.js +60 -16
- package/src/core/wrappers/SingletonView.js +50 -2
- package/src/core/wrappers/SvgElementWrapper.js +1 -1
- package/src/core/wrappers/constants.js +35 -2
- package/src/core/wrappers/prototypes/attributes-extensions.js +7 -7
- package/src/core/wrappers/prototypes/nd-element-extensions.js +72 -6
- package/src/core/wrappers/prototypes/nd-element.transition.extensions.js +42 -2
- package/src/core/wrappers/template-cloner/NodeCloner.js +53 -8
- package/src/core/wrappers/template-cloner/TemplateCloner.js +75 -6
- package/src/core/wrappers/template-cloner/attributes-hydrator.js +58 -2
- package/src/core/wrappers/template-cloner/utils.js +42 -6
- package/src/fetch/NativeFetch.js +3 -3
- package/src/i18n/bin/scan.js +6 -6
- package/src/i18n/index.d.ts +2 -0
- package/src/i18n/service/I18nService.d.ts +27 -0
- package/src/i18n/service/I18nService.js +5 -5
- package/src/i18n/service/functions.d.ts +22 -0
- package/src/i18n/service/functions.js +2 -2
- package/src/router/Route.js +3 -3
- package/src/router/RouteGroupHelper.js +2 -2
- package/src/router/Router.js +15 -15
- package/src/router/RouterComponent.js +33 -7
- package/src/router/link.js +4 -4
- package/src/router/modes/HashRouter.js +2 -2
- package/src/router/modes/HistoryRouter.js +2 -2
- package/src/router/modes/MemoryRouter.js +1 -1
- package/src/ui/components/accordion/AccordionItemRender.js +3 -3
- package/src/ui/components/accordion/AccordionRender.js +1 -1
- package/src/ui/components/alert/AlertRender.js +10 -10
- package/src/ui/components/avatar/avata-group/AvatarGroupRender.js +1 -1
- package/src/ui/components/avatar/avatar/AvatarRender.js +1 -1
- package/src/ui/components/breadcrumb/BreadcrumbRender.js +2 -2
- package/src/ui/components/button/ButtonRender.js +1 -1
- package/src/ui/components/contextmenu/ContextmenuRender.js +5 -5
- package/src/ui/components/dropdown/DropdownRender.js +8 -8
- package/src/ui/components/dropdown/group/DropdownGroupRender.js +2 -2
- package/src/ui/components/dropdown/item/DropdownItemRender.js +1 -1
- package/src/ui/components/form/FieldCollectionRender.js +2 -2
- package/src/ui/components/form/FormControlRender.js +5 -5
- package/src/ui/components/form/fields/AutocompleteFieldRender.js +3 -3
- package/src/ui/components/form/fields/CheckboxFieldRender.js +1 -1
- package/src/ui/components/form/fields/CheckboxGroupFieldRender.js +1 -1
- package/src/ui/components/form/fields/DateFieldRender.js +7 -7
- package/src/ui/components/form/fields/EmailFieldRender.js +1 -1
- package/src/ui/components/form/fields/FieldRender.js +4 -4
- package/src/ui/components/form/fields/FileFieldRender.js +1 -1
- package/src/ui/components/form/fields/PasswordFieldRender.js +2 -2
- package/src/ui/components/form/fields/RadioFieldRender.js +1 -1
- package/src/ui/components/form/fields/RangeFieldRender.js +1 -1
- package/src/ui/components/form/fields/SelectFieldRender.js +2 -2
- package/src/ui/components/form/fields/SliderFieldRender.js +6 -6
- package/src/ui/components/form/fields/StringFieldRender.js +1 -1
- package/src/ui/components/form/fields/TelFieldRender.js +1 -1
- package/src/ui/components/form/fields/TextAreaFieldRender.js +1 -1
- package/src/ui/components/form/fields/TimeFieldRender.js +3 -3
- package/src/ui/components/form/fields/UrlFieldRender.js +1 -1
- package/src/ui/components/form/file-upload-mode/FileAvatarModeRender.js +1 -1
- package/src/ui/components/form/file-upload-mode/FileDropzoneModeRender.js +2 -2
- package/src/ui/components/form/file-upload-mode/FileUploadButtonModeRender.js +2 -2
- package/src/ui/components/form/file-upload-mode/FileWallModeRender.js +1 -1
- package/src/ui/components/form/helpers.js +8 -8
- package/src/ui/components/form/index.js +27 -27
- package/src/ui/components/menu/MenuDividerRender.js +1 -1
- package/src/ui/components/menu/MenuGroupRender.js +3 -3
- package/src/ui/components/menu/MenuItemRender.js +2 -2
- package/src/ui/components/menu/MenuLinkRender.js +3 -3
- package/src/ui/components/menu/helpers.js +4 -4
- package/src/ui/components/modal/ModalRender.js +4 -4
- package/src/ui/components/pagination/PaginationRender.js +9 -9
- package/src/ui/components/popover/PopoverRender.js +7 -7
- package/src/ui/components/progress/ProgressRender.js +12 -12
- package/src/ui/components/skeleton/SkeletonRender.js +56 -0
- package/src/ui/components/splitter/SplitterGutterRender.js +1 -1
- package/src/ui/components/splitter/SplitterPanelRender.js +2 -2
- package/src/ui/components/stacks/PositionStackRender.js +1 -1
- package/src/ui/components/stacks/StackRender.js +1 -1
- package/src/ui/components/stacks/absolute-stack/AbsoluteStackRender.js +1 -1
- package/src/ui/components/stacks/fixed-stack/FixedStackRender.js +1 -1
- package/src/ui/components/stacks/h-stack/HStackRender.js +1 -1
- package/src/ui/components/stacks/index.js +5 -5
- package/src/ui/components/stacks/relative-stack/RelativeStackRender.js +1 -1
- package/src/ui/components/stacks/v-stack/VStackRender.js +1 -1
- package/src/ui/components/stepper/StepperRender.js +2 -2
- package/src/ui/components/stepper/StepperStepRender.js +4 -4
- package/src/ui/components/switch/SwitchRender.js +4 -4
- package/src/ui/components/table/data-table/DataTableRender.js +5 -5
- package/src/ui/components/table/data-table/bulk-actions.js +7 -7
- package/src/ui/components/table/data-table/pagination.js +6 -6
- package/src/ui/components/table/data-table/tables.js +25 -25
- package/src/ui/components/table/data-table/toolbar.js +3 -3
- package/src/ui/components/table/simple-table/SimpleTableRender.js +8 -8
- package/src/ui/components/tabs/TabsRender.js +11 -11
- package/src/ui/components/toast/ToastRender.js +3 -3
- package/src/ui/components/tooltip/TooltipRender.js +1 -1
- package/src/ui/index.js +36 -36
- package/types/elements.d.ts +163 -1037
- package/types/forms.d.ts +16 -20
- package/types/globals.d.ts +543 -0
- package/types/images.d.ts +2 -2
- package/types/observable-resource.d.ts +3 -0
- package/types/property-accumulator.d.ts +4 -4
- package/types/store.d.ts +26 -2
- package/types/validator.ts +3 -3
- package/ui.js +1 -0
- package/src/components/form/field/DefaultRender.js +0 -77
- package/src/components/form/field/FieldFactory.js +0 -107
- package/src/components/skeleton/SkeletonCard.js +0 -0
- package/src/components/skeleton/SkeletonList.js +0 -0
- package/src/components/skeleton/SkeletonParagraph.js +0 -0
- package/src/components/skeleton/SkeletonTable.js +0 -0
|
@@ -1,10 +1,30 @@
|
|
|
1
|
-
import {debounce} from
|
|
2
|
-
import HasEventEmitter from
|
|
3
|
-
import { $ } from
|
|
4
|
-
import Validator from
|
|
5
|
-
import NativeDocumentError from
|
|
6
|
-
import BaseComponent from
|
|
7
|
-
|
|
1
|
+
import {debounce} from '../../core/utils/helpers';
|
|
2
|
+
import HasEventEmitter from '../../core/utils/HasEventEmitter';
|
|
3
|
+
import { $ } from '../../core/data/Observable';
|
|
4
|
+
import Validator from '../../core/utils/validator';
|
|
5
|
+
import NativeDocumentError from '../../../src/core/errors/NativeDocumentError';
|
|
6
|
+
import BaseComponent from '../BaseComponent';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Top-level form controller. Manages field registration, layout, validation, submission, error display, and reactive value tracking.
|
|
10
|
+
*
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const form = new FormControl()
|
|
14
|
+
* .fields((form) => {
|
|
15
|
+
* new StringField('email').label('Email').required().email();
|
|
16
|
+
* new PasswordField('password').label('Password').required().strong();
|
|
17
|
+
* })
|
|
18
|
+
* .layout((fields) => VStack(fields.email, fields.password))
|
|
19
|
+
* .onSubmit(async (values, form) => {
|
|
20
|
+
* await api.login(values);
|
|
21
|
+
* })
|
|
22
|
+
* .onError((errors) => console.log(errors))
|
|
23
|
+
* .errorsMode('inline');
|
|
24
|
+
*
|
|
25
|
+
* @constructor
|
|
26
|
+
* @param {GlobalAttributes} [props]
|
|
27
|
+
*/
|
|
8
28
|
export default function FormControl(props) {
|
|
9
29
|
if(!(this instanceof FormControl)) {
|
|
10
30
|
return new FormControl(props);
|
|
@@ -25,16 +45,37 @@ export default function FormControl(props) {
|
|
|
25
45
|
errors: $(null),
|
|
26
46
|
isDirty: $(false),
|
|
27
47
|
isValid: $(false),
|
|
28
|
-
props
|
|
48
|
+
props,
|
|
29
49
|
};
|
|
30
50
|
}
|
|
31
51
|
|
|
32
52
|
FormControl.defaultTemplate = null;
|
|
33
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Registers the render template for FormControl.
|
|
56
|
+
* @param {(description: {
|
|
57
|
+
* data: *|null,
|
|
58
|
+
* fieldBuilder: ((form: FormControl) => void)|null,
|
|
59
|
+
* layout: ((fields: Record<string, Field>) => NdChild)|null,
|
|
60
|
+
* errorsMode: 'dispatch'|'inline'|'summary'|'none',
|
|
61
|
+
* errorsPosition: 'top'|'bottom',
|
|
62
|
+
* errorsMapper: Record<string, string>|null,
|
|
63
|
+
* renderErrors: ((errors: Record<string, string[]>) => NdChild)|null,
|
|
64
|
+
* submitting: Observable<boolean>,
|
|
65
|
+
* errors: Observable<Record<string, string[]>|null>,
|
|
66
|
+
* isDirty: Observable<boolean>,
|
|
67
|
+
* isValid: Observable<boolean>,
|
|
68
|
+
* props: GlobalAttributes,
|
|
69
|
+
* }, instance: FormControl) => NdChild} template
|
|
70
|
+
*/
|
|
34
71
|
FormControl.use = function(template) {
|
|
35
72
|
FormControl.defaultTemplate = template;
|
|
36
73
|
};
|
|
37
74
|
|
|
75
|
+
/**
|
|
76
|
+
* @param {GlobalAttributes} [props]
|
|
77
|
+
* @returns {FormControl}
|
|
78
|
+
*/
|
|
38
79
|
FormControl.create = function(props) {
|
|
39
80
|
return new FormControl(props);
|
|
40
81
|
};
|
|
@@ -43,17 +84,21 @@ BaseComponent.extends(FormControl);
|
|
|
43
84
|
BaseComponent.use(FormControl, HasEventEmitter);
|
|
44
85
|
|
|
45
86
|
Object.defineProperty(FormControl.prototype, 'isDirty', {
|
|
46
|
-
get() { return this.$description.isDirty; }
|
|
87
|
+
get() { return this.$description.isDirty; },
|
|
47
88
|
});
|
|
48
89
|
|
|
49
90
|
Object.defineProperty(FormControl.prototype, 'isValid', {
|
|
50
|
-
get() { return this.$description.isValid; }
|
|
91
|
+
get() { return this.$description.isValid; },
|
|
51
92
|
});
|
|
52
93
|
|
|
53
94
|
Object.defineProperty(FormControl.prototype, 'submitting', {
|
|
54
|
-
get() { return this.$description.submitting; }
|
|
95
|
+
get() { return this.$description.submitting; },
|
|
55
96
|
});
|
|
56
97
|
|
|
98
|
+
/**
|
|
99
|
+
* @param {(form: FormControl) => void} fieldBuilder
|
|
100
|
+
* @returns {this}
|
|
101
|
+
*/
|
|
57
102
|
FormControl.prototype.fields = function(fieldBuilder) {
|
|
58
103
|
if(typeof fieldBuilder !== 'function') {
|
|
59
104
|
throw new NativeDocumentError('FormControl.fields() expects a function');
|
|
@@ -92,6 +137,10 @@ FormControl.prototype.$registerField = function(name, field) {
|
|
|
92
137
|
field.value(dataSource);
|
|
93
138
|
};
|
|
94
139
|
|
|
140
|
+
/**
|
|
141
|
+
* @param {string} fieldName
|
|
142
|
+
* @returns {Field|null}
|
|
143
|
+
*/
|
|
95
144
|
FormControl.prototype.get = function(fieldName) {
|
|
96
145
|
const field = this.$fields[fieldName];
|
|
97
146
|
if(!field) {
|
|
@@ -100,6 +149,10 @@ FormControl.prototype.get = function(fieldName) {
|
|
|
100
149
|
return field;
|
|
101
150
|
};
|
|
102
151
|
|
|
152
|
+
/**
|
|
153
|
+
* @param {(fields: Record<string, Field>) => NdChild} layoutCallback
|
|
154
|
+
* @returns {this}
|
|
155
|
+
*/
|
|
103
156
|
FormControl.prototype.layout = function(layoutCallback) {
|
|
104
157
|
if(typeof layoutCallback !== 'function') {
|
|
105
158
|
throw new NativeDocumentError('FormControl.layout() expects a function');
|
|
@@ -108,43 +161,72 @@ FormControl.prototype.layout = function(layoutCallback) {
|
|
|
108
161
|
return this;
|
|
109
162
|
};
|
|
110
163
|
|
|
164
|
+
/**
|
|
165
|
+
* @param {'inline'|'summary'|'none'} mode
|
|
166
|
+
* @returns {this}
|
|
167
|
+
*/
|
|
111
168
|
FormControl.prototype.errorsMode = function(mode) {
|
|
112
169
|
this.$description.errorsMode = mode;
|
|
113
170
|
return this;
|
|
114
171
|
};
|
|
115
172
|
|
|
173
|
+
/**
|
|
174
|
+
* @param {Record<string, string>|null} [mapper=null]
|
|
175
|
+
* @returns {this}
|
|
176
|
+
*/
|
|
116
177
|
FormControl.prototype.dispatchErrors = function(mapper = null) {
|
|
117
178
|
this.$description.errorsMode = this.$description.errorsMode === 'summary' ? 'both' : 'dispatch';
|
|
118
179
|
this.$description.errorsMapper = mapper;
|
|
119
180
|
return this;
|
|
120
181
|
};
|
|
121
182
|
|
|
183
|
+
/**
|
|
184
|
+
* @returns {Record<string, string[]>}
|
|
185
|
+
*/
|
|
122
186
|
FormControl.prototype.summarizeErrors = function() {
|
|
123
187
|
this.$description.errorsMode = this.$description.errorsMode === 'dispatch' ? 'both' : 'summary';
|
|
124
188
|
return this;
|
|
125
189
|
};
|
|
126
190
|
|
|
191
|
+
/**
|
|
192
|
+
* @param {Record<string, string>|null} [mapper=null]
|
|
193
|
+
* @returns {this}
|
|
194
|
+
*/
|
|
127
195
|
FormControl.prototype.dispatchAndSummarize = function(mapper = null) {
|
|
128
196
|
this.$description.errorsMode = 'both';
|
|
129
197
|
this.$description.errorsMapper = mapper;
|
|
130
198
|
return this;
|
|
131
199
|
};
|
|
132
200
|
|
|
201
|
+
/**
|
|
202
|
+
* @param {'top'|'bottom'} position
|
|
203
|
+
* @returns {this}
|
|
204
|
+
*/
|
|
133
205
|
FormControl.prototype.errorsPosition = function(position) {
|
|
134
206
|
this.$description.errorsPosition = position;
|
|
135
207
|
return this;
|
|
136
208
|
};
|
|
137
209
|
|
|
210
|
+
/**
|
|
211
|
+
* @returns {this}
|
|
212
|
+
*/
|
|
138
213
|
FormControl.prototype.errorsAtTop = function() {
|
|
139
214
|
this.$description.errorsPosition = 'top';
|
|
140
215
|
return this;
|
|
141
216
|
};
|
|
142
217
|
|
|
218
|
+
/**
|
|
219
|
+
* @returns {this}
|
|
220
|
+
*/
|
|
143
221
|
FormControl.prototype.errorsAtBottom = function() {
|
|
144
222
|
this.$description.errorsPosition = 'bottom';
|
|
145
223
|
return this;
|
|
146
224
|
};
|
|
147
225
|
|
|
226
|
+
/**
|
|
227
|
+
* @param {(errors: Record<string, string[]>) => NdChild} renderFn
|
|
228
|
+
* @returns {this}
|
|
229
|
+
*/
|
|
148
230
|
FormControl.prototype.renderErrors = function(renderFn) {
|
|
149
231
|
this.$description.renderErrors = renderFn;
|
|
150
232
|
return this;
|
|
@@ -169,6 +251,9 @@ FormControl.prototype.$dispatchServerErrors = function(error) {
|
|
|
169
251
|
}
|
|
170
252
|
};
|
|
171
253
|
|
|
254
|
+
/**
|
|
255
|
+
* @returns {this}
|
|
256
|
+
*/
|
|
172
257
|
FormControl.prototype.reset = function() {
|
|
173
258
|
this.$description.isDirty.set(false);
|
|
174
259
|
this.$description.isValid.set(false);
|
|
@@ -184,19 +269,31 @@ FormControl.prototype.reset = function() {
|
|
|
184
269
|
return this;
|
|
185
270
|
};
|
|
186
271
|
|
|
272
|
+
/**
|
|
273
|
+
* @param {string} name
|
|
274
|
+
* @returns {this}
|
|
275
|
+
*/
|
|
187
276
|
FormControl.prototype.resetField = function(name) {
|
|
188
277
|
const field = this.$fields[name];
|
|
189
278
|
if(!field) {
|
|
190
279
|
return this;
|
|
191
280
|
}
|
|
192
|
-
field.reset()
|
|
281
|
+
field.reset();
|
|
193
282
|
return this;
|
|
194
283
|
};
|
|
195
284
|
|
|
285
|
+
/**
|
|
286
|
+
* @param {string} event
|
|
287
|
+
* @returns {this}
|
|
288
|
+
*/
|
|
196
289
|
FormControl.prototype.submit = function(event) {
|
|
197
290
|
return this.$handleSubmit(event);
|
|
198
291
|
};
|
|
199
292
|
|
|
293
|
+
/**
|
|
294
|
+
* @param {...string} fieldNames
|
|
295
|
+
* @returns {this}
|
|
296
|
+
*/
|
|
200
297
|
FormControl.prototype.trigger = function(...fieldNames) {
|
|
201
298
|
const values = this.values();
|
|
202
299
|
fieldNames.forEach(name => {
|
|
@@ -205,6 +302,10 @@ FormControl.prototype.trigger = function(...fieldNames) {
|
|
|
205
302
|
return this;
|
|
206
303
|
};
|
|
207
304
|
|
|
305
|
+
/**
|
|
306
|
+
* @param {string|null} [fieldName=null]
|
|
307
|
+
* @returns {this}
|
|
308
|
+
*/
|
|
208
309
|
FormControl.prototype.disable = function(fieldName = null) {
|
|
209
310
|
if(fieldName) {
|
|
210
311
|
this.$fields[fieldName]?.disabled?.(true);
|
|
@@ -217,6 +318,10 @@ FormControl.prototype.disable = function(fieldName = null) {
|
|
|
217
318
|
return this;
|
|
218
319
|
};
|
|
219
320
|
|
|
321
|
+
/**
|
|
322
|
+
* @param {string|null} [fieldName=null]
|
|
323
|
+
* @returns {this}
|
|
324
|
+
*/
|
|
220
325
|
FormControl.prototype.enable = function(fieldName = null) {
|
|
221
326
|
if(fieldName) {
|
|
222
327
|
this.$fields[fieldName]?.disabled?.(false);
|
|
@@ -229,6 +334,9 @@ FormControl.prototype.enable = function(fieldName = null) {
|
|
|
229
334
|
return this;
|
|
230
335
|
};
|
|
231
336
|
|
|
337
|
+
/**
|
|
338
|
+
* @returns {Record<string, *>}
|
|
339
|
+
*/
|
|
232
340
|
FormControl.prototype.values = function() {
|
|
233
341
|
const values = {};
|
|
234
342
|
for(const [name, field] of Object.entries(this.$fields)) {
|
|
@@ -237,6 +345,11 @@ FormControl.prototype.values = function() {
|
|
|
237
345
|
return values;
|
|
238
346
|
};
|
|
239
347
|
|
|
348
|
+
/**
|
|
349
|
+
* @param {string} fieldName
|
|
350
|
+
* @param {(value: *, field: Field) => void} handler
|
|
351
|
+
* @returns {this}
|
|
352
|
+
*/
|
|
240
353
|
FormControl.prototype.watch = function(fieldName, handler) {
|
|
241
354
|
const field = this.$fields[fieldName];
|
|
242
355
|
if(!field) {
|
|
@@ -300,11 +413,19 @@ FormControl.prototype.$handleSubmit = async function(event) {
|
|
|
300
413
|
}
|
|
301
414
|
};
|
|
302
415
|
|
|
416
|
+
/**
|
|
417
|
+
* @param {(values: Record<string, *>, form: FormControl) => void|Promise<void>} callback
|
|
418
|
+
* @returns {this}
|
|
419
|
+
*/
|
|
303
420
|
FormControl.prototype.onSubmit = function(callback) {
|
|
304
421
|
this.on('submit', callback);
|
|
305
422
|
return this;
|
|
306
423
|
};
|
|
307
424
|
|
|
425
|
+
/**
|
|
426
|
+
* @param {Function} callback
|
|
427
|
+
* @returns {this}
|
|
428
|
+
*/
|
|
308
429
|
FormControl.prototype.onPreventSubmit = function(callback) {
|
|
309
430
|
this.on('submit', function(event) {
|
|
310
431
|
event.preventDefault();
|
|
@@ -313,25 +434,47 @@ FormControl.prototype.onPreventSubmit = function(callback) {
|
|
|
313
434
|
return this;
|
|
314
435
|
};
|
|
315
436
|
|
|
316
|
-
|
|
437
|
+
/**
|
|
438
|
+
* @param {(values: Record<string, *>) => void} callback
|
|
439
|
+
* @param {number} [delay=300]
|
|
440
|
+
* @returns {this}
|
|
441
|
+
*/
|
|
442
|
+
FormControl.prototype.onDebouncedSubmit = function(callback, delay = 300){
|
|
317
443
|
return this.onSubmit(debounce(callback.bind(this), delay));
|
|
318
444
|
};
|
|
319
445
|
|
|
446
|
+
/**
|
|
447
|
+
* @param {(values: Record<string, *>) => void} callback
|
|
448
|
+
* @returns {this}
|
|
449
|
+
*/
|
|
320
450
|
FormControl.prototype.onSuccess = function(callback) {
|
|
321
451
|
this.on('success', callback);
|
|
322
452
|
return this;
|
|
323
453
|
};
|
|
324
454
|
|
|
455
|
+
/**
|
|
456
|
+
* @param {(errors: Record<string, string[]>) => void} callback
|
|
457
|
+
* @returns {this}
|
|
458
|
+
*/
|
|
325
459
|
FormControl.prototype.onError = function(callback) {
|
|
326
460
|
this.on('error', callback);
|
|
327
461
|
return this;
|
|
328
462
|
};
|
|
329
463
|
|
|
464
|
+
|
|
465
|
+
/**
|
|
466
|
+
* @param {Function} callback
|
|
467
|
+
* @returns {this}
|
|
468
|
+
*/
|
|
330
469
|
FormControl.prototype.onChange = function(callback) {
|
|
331
470
|
this.on('change', callback);
|
|
332
471
|
return this;
|
|
333
472
|
};
|
|
334
473
|
|
|
474
|
+
/**
|
|
475
|
+
* @param {Function} callback
|
|
476
|
+
* @returns {this}
|
|
477
|
+
*/
|
|
335
478
|
FormControl.prototype.onReset = function(callback) {
|
|
336
479
|
this.on('reset', callback);
|
|
337
480
|
return this;
|
|
@@ -1,9 +1,27 @@
|
|
|
1
|
-
import { $ } from
|
|
2
|
-
import Validator from
|
|
3
|
-
import BaseComponent from
|
|
4
|
-
import HasEventEmitter from
|
|
5
|
-
import HasValidation from
|
|
6
|
-
|
|
1
|
+
import { $ } from '../../../core/data/Observable';
|
|
2
|
+
import Validator from '../../../core/utils/validator';
|
|
3
|
+
import BaseComponent from '../../BaseComponent';
|
|
4
|
+
import HasEventEmitter from '../../../core/utils/HasEventEmitter';
|
|
5
|
+
import HasValidation from '../../$traits/has-validation/HasValidation';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Base form field with label, hint, placeholder, validation rules, clearable state, and reactive value binding. Extended by all typed field variants.
|
|
9
|
+
*
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* const field = new Field('username', 'text')
|
|
13
|
+
* .label(Span('Username'))
|
|
14
|
+
* .placeholder('Enter your username')
|
|
15
|
+
* .required('Username is required')
|
|
16
|
+
* .minLength(3)
|
|
17
|
+
* .model(usernameObs)
|
|
18
|
+
* .clearable(true);
|
|
19
|
+
*
|
|
20
|
+
* @constructor
|
|
21
|
+
* @param {string} name
|
|
22
|
+
* @param {string} [type]
|
|
23
|
+
* @param {GlobalAttributes} [props]
|
|
24
|
+
*/
|
|
7
25
|
export default function Field(name, type, props) {
|
|
8
26
|
if(!(this instanceof Field)) {
|
|
9
27
|
return new Field(name, type, props);
|
|
@@ -36,7 +54,7 @@ export default function Field(name, type, props) {
|
|
|
36
54
|
label: null,
|
|
37
55
|
input: null,
|
|
38
56
|
error: null,
|
|
39
|
-
hint: null
|
|
57
|
+
hint: null,
|
|
40
58
|
},
|
|
41
59
|
render: null,
|
|
42
60
|
clearButtonIcon: null,
|
|
@@ -44,7 +62,7 @@ export default function Field(name, type, props) {
|
|
|
44
62
|
isDirty: $(false),
|
|
45
63
|
isTouched: $(false),
|
|
46
64
|
slots: {},
|
|
47
|
-
props
|
|
65
|
+
props,
|
|
48
66
|
};
|
|
49
67
|
|
|
50
68
|
this.$description.errors.intercept((nextValue) => nextValue === null ? [] : nextValue);
|
|
@@ -55,6 +73,32 @@ BaseComponent.extends(Field);
|
|
|
55
73
|
BaseComponent.use(Field, HasEventEmitter);
|
|
56
74
|
BaseComponent.use(Field, HasValidation);
|
|
57
75
|
|
|
76
|
+
/**
|
|
77
|
+
* Registers the render template for Field.
|
|
78
|
+
* @param {(description: {
|
|
79
|
+
* name: string,
|
|
80
|
+
* type: string,
|
|
81
|
+
* key: string,
|
|
82
|
+
* label: NdChild|null,
|
|
83
|
+
* placeholder: NdChild|null,
|
|
84
|
+
* help: NdChild|null,
|
|
85
|
+
* defaultValue: *,
|
|
86
|
+
* disabled: boolean|Observable<boolean>,
|
|
87
|
+
* readonly: boolean|Observable<boolean>,
|
|
88
|
+
* rules: Array<{ fn: Function, params: *, message: string }>,
|
|
89
|
+
* clearErrorOn: string,
|
|
90
|
+
* validateOn: string,
|
|
91
|
+
* value: Observable<*>|null,
|
|
92
|
+
* clearable: boolean|Observable<boolean>|null,
|
|
93
|
+
* hasErrors: Observable<boolean>,
|
|
94
|
+
* errors: Observable<string[]>,
|
|
95
|
+
* showErrors: Observable<boolean>,
|
|
96
|
+
* render: ((desc: *, instance: Field) => NdChild)|null,
|
|
97
|
+
* clearButtonIcon: NdChild|null,
|
|
98
|
+
* focus: Observable<boolean>,
|
|
99
|
+
* isDirty: Observable<boolean>,
|
|
100
|
+
* }, instance: Field) => NdChild} template
|
|
101
|
+
*/
|
|
58
102
|
Field.use = function(template) {
|
|
59
103
|
Field.defaultTemplate = template;
|
|
60
104
|
};
|
|
@@ -67,20 +111,35 @@ Field.prototype.$model = function() {
|
|
|
67
111
|
return this.$description.value || this.$description.checked;
|
|
68
112
|
};
|
|
69
113
|
|
|
114
|
+
/**
|
|
115
|
+
* @param {*} forceValue
|
|
116
|
+
* @returns {void}
|
|
117
|
+
*/
|
|
70
118
|
Field.prototype.forceShowErrors = function(forceValue) {
|
|
71
119
|
this.$description.showErrors.intercept(() => forceValue);
|
|
72
|
-
}
|
|
120
|
+
};
|
|
73
121
|
|
|
122
|
+
/**
|
|
123
|
+
* @param {string} key
|
|
124
|
+
* @returns {this}
|
|
125
|
+
*/
|
|
74
126
|
Field.prototype.key = function(key) {
|
|
75
127
|
this.$description.key = key;
|
|
76
128
|
return this;
|
|
77
129
|
};
|
|
78
130
|
|
|
131
|
+
/**
|
|
132
|
+
* @param {string} suffix
|
|
133
|
+
* @returns {this}
|
|
134
|
+
*/
|
|
79
135
|
Field.prototype.suffix = function(suffix) {
|
|
80
136
|
this.$description.suffix = suffix;
|
|
81
137
|
return this;
|
|
82
138
|
};
|
|
83
139
|
|
|
140
|
+
/**
|
|
141
|
+
* @returns {HTMLElement|DocumentFragment}
|
|
142
|
+
*/
|
|
84
143
|
Field.prototype.field = function() {
|
|
85
144
|
if(!this.$element) {
|
|
86
145
|
this.$element = this.toNdElement();
|
|
@@ -89,6 +148,10 @@ Field.prototype.field = function() {
|
|
|
89
148
|
};
|
|
90
149
|
Field.prototype.node = Field.prototype.field;
|
|
91
150
|
|
|
151
|
+
/**
|
|
152
|
+
* @param {Function} callback
|
|
153
|
+
* @returns {this}
|
|
154
|
+
*/
|
|
92
155
|
Field.prototype.input = function(callback) {
|
|
93
156
|
if(!this.$input) {
|
|
94
157
|
this.field();
|
|
@@ -97,6 +160,10 @@ Field.prototype.input = function(callback) {
|
|
|
97
160
|
return this;
|
|
98
161
|
};
|
|
99
162
|
|
|
163
|
+
/**
|
|
164
|
+
* @param {Observable<*>} observable
|
|
165
|
+
* @returns {this}
|
|
166
|
+
*/
|
|
100
167
|
Field.prototype.model = function(observable) {
|
|
101
168
|
this.$description.value = observable;
|
|
102
169
|
this.$description.initialValue = Validator.isObservable(observable)
|
|
@@ -107,6 +174,10 @@ Field.prototype.model = function(observable) {
|
|
|
107
174
|
|
|
108
175
|
Field.prototype.bind = Field.prototype.model;
|
|
109
176
|
|
|
177
|
+
/**
|
|
178
|
+
* @param {Observable<string[]>} errors
|
|
179
|
+
* @returns {this}
|
|
180
|
+
*/
|
|
110
181
|
Field.prototype.errors = function(errors) {
|
|
111
182
|
if(!Validator.isObservable(errors)) {
|
|
112
183
|
throw new Error('Errors must be an observable');
|
|
@@ -115,51 +186,90 @@ Field.prototype.errors = function(errors) {
|
|
|
115
186
|
return this;
|
|
116
187
|
};
|
|
117
188
|
|
|
189
|
+
/**
|
|
190
|
+
* @param {string} type
|
|
191
|
+
* @returns {this}
|
|
192
|
+
*/
|
|
118
193
|
Field.prototype.type = function(type) {
|
|
119
194
|
this.$description.type = type;
|
|
120
195
|
return this;
|
|
121
196
|
};
|
|
122
197
|
|
|
198
|
+
/**
|
|
199
|
+
* @param {*} defaultValue
|
|
200
|
+
* @returns {this}
|
|
201
|
+
*/
|
|
123
202
|
Field.prototype.default = function(defaultValue) {
|
|
124
203
|
this.$description.defaultValue = defaultValue;
|
|
125
204
|
return this;
|
|
126
205
|
};
|
|
127
206
|
|
|
207
|
+
/**
|
|
208
|
+
* @param {NdChild} text
|
|
209
|
+
* @returns {this}
|
|
210
|
+
*/
|
|
128
211
|
Field.prototype.label = function(text) {
|
|
129
212
|
this.$description.label = text;
|
|
130
213
|
return this;
|
|
131
214
|
};
|
|
132
215
|
|
|
216
|
+
/**
|
|
217
|
+
* @param {NdChild} text
|
|
218
|
+
* @returns {this}
|
|
219
|
+
*/
|
|
133
220
|
Field.prototype.help = function(text) {
|
|
134
221
|
this.$description.help = text;
|
|
135
222
|
return this;
|
|
136
223
|
};
|
|
137
224
|
|
|
225
|
+
/**
|
|
226
|
+
* @param {NdChild} text
|
|
227
|
+
* @returns {this}
|
|
228
|
+
*/
|
|
138
229
|
Field.prototype.hint = function(text) {
|
|
139
230
|
this.$description.help = text;
|
|
140
231
|
return this;
|
|
141
232
|
};
|
|
142
233
|
|
|
234
|
+
/**
|
|
235
|
+
* @param {NdChild} text
|
|
236
|
+
* @returns {this}
|
|
237
|
+
*/
|
|
143
238
|
Field.prototype.placeholder = function(text) {
|
|
144
239
|
this.$description.placeholder = text;
|
|
145
240
|
return this;
|
|
146
241
|
};
|
|
147
242
|
|
|
243
|
+
/**
|
|
244
|
+
* @param {boolean|Observable<boolean>} [disabled]
|
|
245
|
+
* @returns {this}
|
|
246
|
+
*/
|
|
148
247
|
Field.prototype.disabled = function(disabled) {
|
|
149
248
|
this.$description.disabled = BaseComponent.obs(disabled);
|
|
150
249
|
return this;
|
|
151
250
|
};
|
|
152
251
|
|
|
252
|
+
/**
|
|
253
|
+
* @param {boolean|Observable<boolean>} [readonly]
|
|
254
|
+
* @returns {this}
|
|
255
|
+
*/
|
|
153
256
|
Field.prototype.readonly = function(readonly) {
|
|
154
257
|
this.$description.readonly = BaseComponent.obs(readonly);
|
|
155
258
|
return this;
|
|
156
259
|
};
|
|
157
260
|
|
|
261
|
+
/**
|
|
262
|
+
* @returns {*}
|
|
263
|
+
*/
|
|
158
264
|
Field.prototype.value = function() {
|
|
159
265
|
const value = this.$model();
|
|
160
266
|
return Validator.isObservable(value) ? value.val() : value;
|
|
161
267
|
};
|
|
162
268
|
|
|
269
|
+
/**
|
|
270
|
+
* @param {*} newValue
|
|
271
|
+
* @returns {this}
|
|
272
|
+
*/
|
|
163
273
|
Field.prototype.setValue = function(newValue) {
|
|
164
274
|
const value = this.$model();
|
|
165
275
|
if(Validator.isObservable(value)) {
|
|
@@ -170,66 +280,115 @@ Field.prototype.setValue = function(newValue) {
|
|
|
170
280
|
return this;
|
|
171
281
|
};
|
|
172
282
|
|
|
283
|
+
/**
|
|
284
|
+
* @param {*} wrapperProps
|
|
285
|
+
* @returns {this}
|
|
286
|
+
*/
|
|
173
287
|
Field.prototype.wrapperProps = function(wrapperProps) {
|
|
174
288
|
this.$description.elementsProps.wrapper = wrapperProps;
|
|
175
289
|
return this;
|
|
176
290
|
};
|
|
177
291
|
|
|
292
|
+
/**
|
|
293
|
+
* @param {*} inputProps
|
|
294
|
+
* @returns {this}
|
|
295
|
+
*/
|
|
178
296
|
Field.prototype.inputProps = function(inputProps) {
|
|
179
297
|
this.$description.elementsProps.input = inputProps;
|
|
180
298
|
return this;
|
|
181
299
|
};
|
|
182
300
|
|
|
301
|
+
/**
|
|
302
|
+
* @param {*} labelProps
|
|
303
|
+
* @returns {this}
|
|
304
|
+
*/
|
|
183
305
|
Field.prototype.labelProps = function(labelProps) {
|
|
184
306
|
this.$description.elementsProps.label = labelProps;
|
|
185
307
|
return this;
|
|
186
308
|
};
|
|
187
309
|
|
|
310
|
+
/**
|
|
311
|
+
* @param {*} errorProps
|
|
312
|
+
* @returns {this}
|
|
313
|
+
*/
|
|
188
314
|
Field.prototype.errorProps = function(errorProps) {
|
|
189
315
|
this.$description.elementsProps.error = errorProps;
|
|
190
316
|
return this;
|
|
191
317
|
};
|
|
192
318
|
|
|
319
|
+
/**
|
|
320
|
+
* @param {*} hintProps
|
|
321
|
+
* @returns {this}
|
|
322
|
+
*/
|
|
193
323
|
Field.prototype.hintProps = function(hintProps) {
|
|
194
324
|
this.$description.elementsProps.hint = hintProps;
|
|
195
325
|
return this;
|
|
196
326
|
};
|
|
197
327
|
|
|
328
|
+
/**
|
|
329
|
+
* @returns {this}
|
|
330
|
+
*/
|
|
198
331
|
Field.prototype.focus = function() {
|
|
199
332
|
this.$description.focus.set(true);
|
|
200
333
|
return this;
|
|
201
334
|
};
|
|
202
335
|
|
|
336
|
+
/**
|
|
337
|
+
* @returns {this}
|
|
338
|
+
*/
|
|
203
339
|
Field.prototype.blur = function() {
|
|
204
340
|
this.$description.focus.set(false);
|
|
205
341
|
return this;
|
|
206
342
|
};
|
|
207
343
|
|
|
344
|
+
/**
|
|
345
|
+
* @param {NdChild} content
|
|
346
|
+
* @returns {this}
|
|
347
|
+
*/
|
|
208
348
|
Field.prototype.leading = function(content) {
|
|
209
349
|
this.$description.slots.leading = content;
|
|
210
350
|
return this;
|
|
211
351
|
};
|
|
212
352
|
|
|
353
|
+
/**
|
|
354
|
+
* @param {NdChild} content
|
|
355
|
+
* @returns {this}
|
|
356
|
+
*/
|
|
213
357
|
Field.prototype.trailing = function(content) {
|
|
214
358
|
this.$description.slots.trailing = content;
|
|
215
359
|
return this;
|
|
216
360
|
};
|
|
217
361
|
|
|
362
|
+
/**
|
|
363
|
+
* @param {NdChild} content
|
|
364
|
+
* @returns {this}
|
|
365
|
+
*/
|
|
218
366
|
Field.prototype.bottom = function(content) {
|
|
219
367
|
this.$description.slots.bottom = content;
|
|
220
368
|
return this;
|
|
221
369
|
};
|
|
222
370
|
|
|
371
|
+
/**
|
|
372
|
+
* @param {*} [mode]
|
|
373
|
+
* @returns {this}
|
|
374
|
+
*/
|
|
223
375
|
Field.prototype.clearable = function(mode = true) {
|
|
224
376
|
this.$description.clearable = BaseComponent.obs(mode);
|
|
225
377
|
return this;
|
|
226
378
|
};
|
|
227
379
|
|
|
380
|
+
/**
|
|
381
|
+
* @param {*} clearButtonIcon
|
|
382
|
+
* @returns {this}
|
|
383
|
+
*/
|
|
228
384
|
Field.prototype.clearButtonIcon = function(clearButtonIcon) {
|
|
229
385
|
this.$description.slots.clearButtonIcon = clearButtonIcon;
|
|
230
386
|
return this;
|
|
231
387
|
};
|
|
232
388
|
|
|
389
|
+
/**
|
|
390
|
+
* @returns {this}
|
|
391
|
+
*/
|
|
233
392
|
Field.prototype.reset = function() {
|
|
234
393
|
const value = this.$model();
|
|
235
394
|
if(Validator.isObservable(value)) {
|
|
@@ -248,6 +407,10 @@ Field.prototype.reset = function() {
|
|
|
248
407
|
return this;
|
|
249
408
|
};
|
|
250
409
|
|
|
410
|
+
/**
|
|
411
|
+
*
|
|
412
|
+
* @param {string|string[]} error
|
|
413
|
+
*/
|
|
251
414
|
Field.prototype.setError = function(error) {
|
|
252
415
|
const errs = Array.isArray(error) ? error : [error];
|
|
253
416
|
this.$description.errors.set(errs);
|