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,4 +1,4 @@
|
|
|
1
|
-
import ObservableItem from
|
|
1
|
+
import ObservableItem from '../ObservableItem';
|
|
2
2
|
|
|
3
3
|
const $computed = (fn, dependencies) => ObservableItem.computed(fn, dependencies);
|
|
4
4
|
const $checker = (obs, fn) => obs.transform(fn);
|
|
@@ -7,6 +7,17 @@ const $checker = (obs, fn) => obs.transform(fn);
|
|
|
7
7
|
// is... -> ObservableChecker<boolean>
|
|
8
8
|
//
|
|
9
9
|
|
|
10
|
+
/**
|
|
11
|
+
* Returns a derived observable that emits true when the value strictly equals the given value.
|
|
12
|
+
* Supports reactive comparison when an ObservableItem is passed.
|
|
13
|
+
*
|
|
14
|
+
* @param {*|ObservableItem} value - Static value or observable to compare against
|
|
15
|
+
* @returns {ObservableChecker<boolean>}
|
|
16
|
+
* @example
|
|
17
|
+
* const age = Observable(25);
|
|
18
|
+
* age.isEqualTo(25).val(); // true
|
|
19
|
+
* age.isEqualTo(Observable(25)).val(); // true
|
|
20
|
+
*/
|
|
10
21
|
ObservableItem.prototype.isEqualTo = function (value) {
|
|
11
22
|
if (value?.__$Observable) {
|
|
12
23
|
return $computed((a, b) => a === b, [this, value]);
|
|
@@ -14,6 +25,12 @@ ObservableItem.prototype.isEqualTo = function (value) {
|
|
|
14
25
|
return $checker(this, x => x === value);
|
|
15
26
|
};
|
|
16
27
|
|
|
28
|
+
/**
|
|
29
|
+
* Returns a derived observable that emits true when the value does not strictly equal the given value.
|
|
30
|
+
*
|
|
31
|
+
* @param {*|ObservableItem} value - Static value or observable to compare against
|
|
32
|
+
* @returns {ObservableChecker<boolean>}
|
|
33
|
+
*/
|
|
17
34
|
ObservableItem.prototype.isNotEqualTo = function (value) {
|
|
18
35
|
if (value?.__$Observable) {
|
|
19
36
|
return $computed((a, b) => a !== b, [this, value]);
|
|
@@ -21,6 +38,12 @@ ObservableItem.prototype.isNotEqualTo = function (value) {
|
|
|
21
38
|
return $checker(this, x => x !== value);
|
|
22
39
|
};
|
|
23
40
|
|
|
41
|
+
/**
|
|
42
|
+
* Returns a derived observable that emits true when the value is greater than the given value.
|
|
43
|
+
*
|
|
44
|
+
* @param {number|ObservableItem<number>} value - Threshold value or observable
|
|
45
|
+
* @returns {ObservableChecker<boolean>}
|
|
46
|
+
*/
|
|
24
47
|
ObservableItem.prototype.isGreaterThan = function (value) {
|
|
25
48
|
if (value?.__$Observable) {
|
|
26
49
|
return $computed((a, b) => a > b, [this, value]);
|
|
@@ -28,6 +51,12 @@ ObservableItem.prototype.isGreaterThan = function (value) {
|
|
|
28
51
|
return $checker(this, x => x > value);
|
|
29
52
|
};
|
|
30
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Returns a derived observable that emits true when the value is greater than or equal to the given value.
|
|
56
|
+
*
|
|
57
|
+
* @param {number|ObservableItem<number>} value - Threshold value or observable
|
|
58
|
+
* @returns {ObservableChecker<boolean>}
|
|
59
|
+
*/
|
|
31
60
|
ObservableItem.prototype.isGreaterThanOrEqualTo = function (value) {
|
|
32
61
|
if (value?.__$Observable) {
|
|
33
62
|
return $computed((a, b) => a >= b, [this, value]);
|
|
@@ -35,6 +64,12 @@ ObservableItem.prototype.isGreaterThanOrEqualTo = function (value) {
|
|
|
35
64
|
return $checker(this, x => x >= value);
|
|
36
65
|
};
|
|
37
66
|
|
|
67
|
+
/**
|
|
68
|
+
* Returns a derived observable that emits true when the value is less than the given value.
|
|
69
|
+
*
|
|
70
|
+
* @param {number|ObservableItem<number>} value - Threshold value or observable
|
|
71
|
+
* @returns {ObservableChecker<boolean>}
|
|
72
|
+
*/
|
|
38
73
|
ObservableItem.prototype.isLessThan = function (value) {
|
|
39
74
|
if (value?.__$Observable) {
|
|
40
75
|
return $computed((a, b) => a < b, [this, value]);
|
|
@@ -42,6 +77,12 @@ ObservableItem.prototype.isLessThan = function (value) {
|
|
|
42
77
|
return $checker(this, x => x < value);
|
|
43
78
|
};
|
|
44
79
|
|
|
80
|
+
/**
|
|
81
|
+
* Returns a derived observable that emits true when the value is less than or equal to the given value.
|
|
82
|
+
*
|
|
83
|
+
* @param {number|ObservableItem<number>} value - Threshold value or observable
|
|
84
|
+
* @returns {ObservableChecker<boolean>}
|
|
85
|
+
*/
|
|
45
86
|
ObservableItem.prototype.isLessThanOrEqualTo = function (value) {
|
|
46
87
|
if (value?.__$Observable) {
|
|
47
88
|
return $computed((a, b) => a <= b, [this, value]);
|
|
@@ -49,6 +90,18 @@ ObservableItem.prototype.isLessThanOrEqualTo = function (value) {
|
|
|
49
90
|
return $checker(this, x => x <= value);
|
|
50
91
|
};
|
|
51
92
|
|
|
93
|
+
/**
|
|
94
|
+
* Returns a derived observable that emits true when the value is between min and max (inclusive).
|
|
95
|
+
* All combinations of static and observable min/max are supported.
|
|
96
|
+
*
|
|
97
|
+
* @param {number|ObservableItem<number>} min - Lower bound (inclusive)
|
|
98
|
+
* @param {number|ObservableItem<number>} max - Upper bound (inclusive)
|
|
99
|
+
* @returns {ObservableChecker<boolean>}
|
|
100
|
+
* @example
|
|
101
|
+
* const age = Observable(25);
|
|
102
|
+
* age.isBetween(18, 65).val(); // true
|
|
103
|
+
* age.isBetween(Observable(18), Observable(65)).val(); // true
|
|
104
|
+
*/
|
|
52
105
|
ObservableItem.prototype.isBetween = function (min, max) {
|
|
53
106
|
if (min.__$Observable && max.__$Observable) {
|
|
54
107
|
return $computed((x, a, b) => x >= a && x <= b, [this, min, max]);
|
|
@@ -62,18 +115,39 @@ ObservableItem.prototype.isBetween = function (min, max) {
|
|
|
62
115
|
return $checker(this, x => x >= min && x <= max);
|
|
63
116
|
};
|
|
64
117
|
|
|
118
|
+
/**
|
|
119
|
+
* Returns a derived observable that emits true when the value is null or undefined.
|
|
120
|
+
*
|
|
121
|
+
* @returns {ObservableChecker<boolean>}
|
|
122
|
+
*/
|
|
65
123
|
ObservableItem.prototype.isNull = function () {
|
|
66
124
|
return $checker(this, x => x == null);
|
|
67
125
|
};
|
|
68
126
|
|
|
127
|
+
/**
|
|
128
|
+
* Returns a derived observable that emits true when the value is truthy.
|
|
129
|
+
*
|
|
130
|
+
* @returns {ObservableChecker<boolean>}
|
|
131
|
+
*/
|
|
69
132
|
ObservableItem.prototype.isTruthy = function () {
|
|
70
133
|
return $checker(this, x => !!x);
|
|
71
134
|
};
|
|
72
135
|
|
|
136
|
+
/**
|
|
137
|
+
* Returns a derived observable that emits true when the value is falsy.
|
|
138
|
+
*
|
|
139
|
+
* @returns {ObservableChecker<boolean>}
|
|
140
|
+
*/
|
|
73
141
|
ObservableItem.prototype.isFalsy = function () {
|
|
74
142
|
return $checker(this, x => !x);
|
|
75
143
|
};
|
|
76
144
|
|
|
145
|
+
/**
|
|
146
|
+
* Returns a derived observable that emits true when the string value starts with the given string.
|
|
147
|
+
*
|
|
148
|
+
* @param {string|ObservableItem<string>} str - Prefix to check for
|
|
149
|
+
* @returns {ObservableChecker<boolean>}
|
|
150
|
+
*/
|
|
77
151
|
ObservableItem.prototype.isStartingWith = function (str) {
|
|
78
152
|
if (str?.__$Observable) {
|
|
79
153
|
return $computed((a, b) => String(a).startsWith(b), [this, str]);
|
|
@@ -81,6 +155,12 @@ ObservableItem.prototype.isStartingWith = function (str) {
|
|
|
81
155
|
return $checker(this, x => String(x).startsWith(str));
|
|
82
156
|
};
|
|
83
157
|
|
|
158
|
+
/**
|
|
159
|
+
* Returns a derived observable that emits true when the string value ends with the given string.
|
|
160
|
+
*
|
|
161
|
+
* @param {string|ObservableItem<string>} str - Suffix to check for
|
|
162
|
+
* @returns {ObservableChecker<boolean>}
|
|
163
|
+
*/
|
|
84
164
|
ObservableItem.prototype.isEndingWith = function (str) {
|
|
85
165
|
if (str?.__$Observable) {
|
|
86
166
|
return $computed((a, b) => String(a).endsWith(b), [this, str]);
|
|
@@ -88,6 +168,12 @@ ObservableItem.prototype.isEndingWith = function (str) {
|
|
|
88
168
|
return $checker(this, x => String(x).endsWith(str));
|
|
89
169
|
};
|
|
90
170
|
|
|
171
|
+
/**
|
|
172
|
+
* Returns a derived observable that emits true when the string value matches the given regex.
|
|
173
|
+
*
|
|
174
|
+
* @param {RegExp|ObservableItem<RegExp>} regex - Pattern to test against
|
|
175
|
+
* @returns {ObservableChecker<boolean>}
|
|
176
|
+
*/
|
|
91
177
|
ObservableItem.prototype.isMatchingPattern = function (regex) {
|
|
92
178
|
if (regex?.__$Observable) {
|
|
93
179
|
return $computed((a, b) => new RegExp(b).test(String(a)), [this, regex]);
|
|
@@ -95,14 +181,36 @@ ObservableItem.prototype.isMatchingPattern = function (regex) {
|
|
|
95
181
|
return $checker(this, x => regex.test(String(x)));
|
|
96
182
|
};
|
|
97
183
|
|
|
184
|
+
/**
|
|
185
|
+
* Returns a derived observable that emits true when the value is empty.
|
|
186
|
+
* Empty means: null, undefined, empty string, or empty array.
|
|
187
|
+
*
|
|
188
|
+
* @returns {ObservableChecker<boolean>}
|
|
189
|
+
*/
|
|
98
190
|
ObservableItem.prototype.isEmpty = function () {
|
|
99
191
|
return $checker(this, x => x == null || x === '' || (Array.isArray(x) && x.length === 0));
|
|
100
192
|
};
|
|
101
193
|
|
|
194
|
+
/**
|
|
195
|
+
* Returns a derived observable that emits true when the value is not empty.
|
|
196
|
+
* Not empty means: not null, not undefined, not empty string, not empty array.
|
|
197
|
+
*
|
|
198
|
+
* @returns {ObservableChecker<boolean>}
|
|
199
|
+
*/
|
|
102
200
|
ObservableItem.prototype.isNotEmpty = function () {
|
|
103
201
|
return $checker(this, x => x != null && x !== '' && !(Array.isArray(x) && x.length === 0));
|
|
104
202
|
};
|
|
105
203
|
|
|
204
|
+
/**
|
|
205
|
+
* Returns a derived observable that emits true when the value includes the given value.
|
|
206
|
+
* Works for both arrays (includes check) and strings (substring check).
|
|
207
|
+
*
|
|
208
|
+
* @param {*|ObservableItem} value - Value to search for
|
|
209
|
+
* @returns {ObservableChecker<boolean>}
|
|
210
|
+
* @example
|
|
211
|
+
* Observable([1, 2, 3]).isIncludes(2).val(); // true
|
|
212
|
+
* Observable('hello world').isIncludes('world').val(); // true
|
|
213
|
+
*/
|
|
106
214
|
ObservableItem.prototype.isIncludes = function (value) {
|
|
107
215
|
if (value?.__$Observable) {
|
|
108
216
|
return $computed((a, b) => {
|
|
@@ -116,6 +224,16 @@ ObservableItem.prototype.isIncludes = function (value) {
|
|
|
116
224
|
});
|
|
117
225
|
};
|
|
118
226
|
|
|
227
|
+
/**
|
|
228
|
+
* Returns a derived observable that emits true when the value is included in the given array.
|
|
229
|
+
* Alias: isOneOf
|
|
230
|
+
*
|
|
231
|
+
* @param {Array|ObservableItem<Array>} array - Array to check membership in
|
|
232
|
+
* @returns {ObservableChecker<boolean>}
|
|
233
|
+
* @example
|
|
234
|
+
* const role = Observable('admin');
|
|
235
|
+
* role.isIncludedIn(['admin', 'editor']).val(); // true
|
|
236
|
+
*/
|
|
119
237
|
ObservableItem.prototype.isIncludedIn = function (array) {
|
|
120
238
|
if (array?.__$Observable) {
|
|
121
239
|
return $computed((a, b) => b.includes(a), [this, array]);
|
|
@@ -125,6 +243,15 @@ ObservableItem.prototype.isIncludedIn = function (array) {
|
|
|
125
243
|
|
|
126
244
|
ObservableItem.prototype.isOneOf = ObservableItem.prototype.isIncludedIn;
|
|
127
245
|
|
|
246
|
+
/**
|
|
247
|
+
* Returns a derived observable that emits true when the given key exists in the value object.
|
|
248
|
+
*
|
|
249
|
+
* @param {string|ObservableItem<string>} key - Property key to check for
|
|
250
|
+
* @returns {ObservableChecker<boolean>}
|
|
251
|
+
* @example
|
|
252
|
+
* const user = Observable({ name: 'John' });
|
|
253
|
+
* user.isHaving('name').val(); // true
|
|
254
|
+
*/
|
|
128
255
|
ObservableItem.prototype.isHaving = function (key) {
|
|
129
256
|
if (key?.__$Observable) {
|
|
130
257
|
return $computed((a, b) => b in Object(a), [this, key]);
|
|
@@ -136,28 +263,68 @@ ObservableItem.prototype.isHaving = function (key) {
|
|
|
136
263
|
// to... -> ObservableChecker<any>
|
|
137
264
|
//
|
|
138
265
|
|
|
266
|
+
/**
|
|
267
|
+
* Returns a derived observable that emits the string value converted to uppercase.
|
|
268
|
+
*
|
|
269
|
+
* @returns {ObservableChecker<string>}
|
|
270
|
+
*/
|
|
139
271
|
ObservableItem.prototype.toUpperCase = function () {
|
|
140
272
|
return $checker(this, x => String(x).toUpperCase());
|
|
141
273
|
};
|
|
142
274
|
|
|
275
|
+
/**
|
|
276
|
+
* Returns a derived observable that emits the string value converted to lowercase.
|
|
277
|
+
*
|
|
278
|
+
* @returns {ObservableChecker<string>}
|
|
279
|
+
*/
|
|
143
280
|
ObservableItem.prototype.toLowerCase = function () {
|
|
144
281
|
return $checker(this, x => String(x).toLowerCase());
|
|
145
282
|
};
|
|
146
283
|
|
|
284
|
+
/**
|
|
285
|
+
* Returns a derived observable that emits the string value trimmed of whitespace.
|
|
286
|
+
*
|
|
287
|
+
* @returns {ObservableChecker<string>}
|
|
288
|
+
*/
|
|
147
289
|
ObservableItem.prototype.toTrimmed = function () {
|
|
148
290
|
return $checker(this, x => String(x).trim());
|
|
149
291
|
};
|
|
150
292
|
|
|
293
|
+
/**
|
|
294
|
+
* Returns a derived observable that emits the value coerced to boolean.
|
|
295
|
+
*
|
|
296
|
+
* @returns {ObservableChecker<boolean>}
|
|
297
|
+
*/
|
|
151
298
|
ObservableItem.prototype.toBoolean = function () {
|
|
152
299
|
return $checker(this, x => !!x);
|
|
153
300
|
};
|
|
154
301
|
|
|
302
|
+
/**
|
|
303
|
+
* Returns a derived observable that emits a string with the placeholder replaced by the current value.
|
|
304
|
+
* Alias: toFormatted
|
|
305
|
+
*
|
|
306
|
+
* @param {string} template - Template string containing the placeholder
|
|
307
|
+
* @param {string} [placeholder='${v}'] - Placeholder string to replace with the value
|
|
308
|
+
* @returns {ObservableChecker<string>}
|
|
309
|
+
* @example
|
|
310
|
+
* const count = Observable(5);
|
|
311
|
+
* count.toLiteral('You have ${v} items').val(); // 'You have 5 items'
|
|
312
|
+
*/
|
|
155
313
|
ObservableItem.prototype.toLiteral = function (template, placeholder = '${v}') {
|
|
156
314
|
return $checker(this, x => template.replace(placeholder, x));
|
|
157
315
|
};
|
|
158
316
|
|
|
159
317
|
ObservableItem.prototype.toFormatted = ObservableItem.prototype.toLiteral;
|
|
160
318
|
|
|
319
|
+
/**
|
|
320
|
+
* Returns a derived observable that emits a nested property value resolved via dot notation.
|
|
321
|
+
*
|
|
322
|
+
* @param {string} key - Dot-notation path to the property (e.g. 'user.address.city')
|
|
323
|
+
* @returns {ObservableChecker<*>}
|
|
324
|
+
* @example
|
|
325
|
+
* const state = Observable({ user: { name: 'John' } });
|
|
326
|
+
* state.toProperty('user.name').val(); // 'John'
|
|
327
|
+
*/
|
|
161
328
|
ObservableItem.prototype.toProperty = function (key) {
|
|
162
329
|
const keys = key.split('.');
|
|
163
330
|
return $checker(this, x => {
|
|
@@ -170,10 +337,27 @@ ObservableItem.prototype.toProperty = function (key) {
|
|
|
170
337
|
});
|
|
171
338
|
};
|
|
172
339
|
|
|
340
|
+
/**
|
|
341
|
+
* Returns a derived observable that emits the length of the current value.
|
|
342
|
+
* Returns 0 if the value is null or undefined.
|
|
343
|
+
*
|
|
344
|
+
* @returns {ObservableChecker<number>}
|
|
345
|
+
*/
|
|
173
346
|
ObservableItem.prototype.toLength = function () {
|
|
174
347
|
return $checker(this, x => (x == null ? 0 : x.length));
|
|
175
348
|
};
|
|
176
349
|
|
|
350
|
+
/**
|
|
351
|
+
* Returns a derived observable that emits the value clamped between min and max.
|
|
352
|
+
* All combinations of static and observable min/max are supported.
|
|
353
|
+
*
|
|
354
|
+
* @param {number|ObservableItem<number>} min - Minimum bound
|
|
355
|
+
* @param {number|ObservableItem<number>} max - Maximum bound
|
|
356
|
+
* @returns {ObservableChecker<number>}
|
|
357
|
+
* @example
|
|
358
|
+
* const volume = Observable(150);
|
|
359
|
+
* volume.toClamped(0, 100).val(); // 100
|
|
360
|
+
*/
|
|
177
361
|
ObservableItem.prototype.toClamped = function (min, max) {
|
|
178
362
|
if (min.__$Observable && max.__$Observable) {
|
|
179
363
|
return $computed((x, a, b) => Math.min(Math.max(x, a), b), [this, min, max]);
|
|
@@ -187,6 +371,17 @@ ObservableItem.prototype.toClamped = function (min, max) {
|
|
|
187
371
|
return $checker(this, x => Math.min(Math.max(x, min), max));
|
|
188
372
|
};
|
|
189
373
|
|
|
374
|
+
/**
|
|
375
|
+
* Returns a derived observable that emits the value expressed as a percentage of total.
|
|
376
|
+
* Returns 0 if total is 0.
|
|
377
|
+
*
|
|
378
|
+
* @param {number|ObservableItem<number>} total - The total value representing 100%
|
|
379
|
+
* @returns {ObservableChecker<number>}
|
|
380
|
+
* @example
|
|
381
|
+
* const score = Observable(75);
|
|
382
|
+
* score.toPercent(100).val(); // 75
|
|
383
|
+
* score.toPercent(200).val(); // 37.5
|
|
384
|
+
*/
|
|
190
385
|
ObservableItem.prototype.toPercent = function (total) {
|
|
191
386
|
if (total?.__$Observable) {
|
|
192
387
|
return $computed((a, b) => (b === 0 ? 0 : (a / b) * 100), [this, total]);
|
|
@@ -10,11 +10,11 @@
|
|
|
10
10
|
* isLoading.subscribe(active => console.log('Loading:', active));
|
|
11
11
|
* status.set('loading'); // Logs: "Loading: true"
|
|
12
12
|
*/
|
|
13
|
-
import {ObservableWhen} from
|
|
14
|
-
import ObservableItem from
|
|
15
|
-
import ObservableChecker from
|
|
16
|
-
import {Formatters} from
|
|
17
|
-
import NativeDocumentError from
|
|
13
|
+
import {ObservableWhen} from '../ObservableWhen';
|
|
14
|
+
import ObservableItem from '../ObservableItem';
|
|
15
|
+
import ObservableChecker from '../ObservableChecker';
|
|
16
|
+
import {Formatters} from '../../utils/formatters';
|
|
17
|
+
import NativeDocumentError from '../../errors/NativeDocumentError';
|
|
18
18
|
|
|
19
19
|
ObservableItem.prototype.when = function(value) {
|
|
20
20
|
return new ObservableWhen(this, value);
|
|
@@ -28,13 +28,38 @@ ObservableItem.prototype.when = function(value) {
|
|
|
28
28
|
* @returns {ObservableChecker}
|
|
29
29
|
*/
|
|
30
30
|
ObservableItem.prototype.check = function(callback) {
|
|
31
|
-
return new ObservableChecker(this, callback)
|
|
31
|
+
return new ObservableChecker(this, callback);
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
ObservableItem.prototype.transform = ObservableItem.prototype.check;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Returns a derived observable that emits the value of a nested property.
|
|
38
|
+
* Alias for .check(value => value[property]).
|
|
39
|
+
*
|
|
40
|
+
* @param {string} property - Property name to extract
|
|
41
|
+
* @returns {ObservableChecker<*>}
|
|
42
|
+
* @example
|
|
43
|
+
* const user = Observable({ name: 'John', age: 25 });
|
|
44
|
+
* user.pluck('name').val(); // 'John'
|
|
45
|
+
*/
|
|
35
46
|
ObservableItem.prototype.pluck = function(property) {
|
|
36
47
|
return new ObservableChecker(this, (value) => value[property]);
|
|
37
48
|
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Creates a derived observable using a callback or checks equality with a static value.
|
|
52
|
+
* - If callback is a function: equivalent to .check(callback)
|
|
53
|
+
* - If callback is a value: equivalent to .check(v => v === value)
|
|
54
|
+
* Alias: .select()
|
|
55
|
+
*
|
|
56
|
+
* @param {Function|*} callbackOrValue - Transform function or value to compare
|
|
57
|
+
* @returns {ObservableChecker<*>}
|
|
58
|
+
* @example
|
|
59
|
+
* const count = Observable(5);
|
|
60
|
+
* count.is(v => v > 3).val(); // true
|
|
61
|
+
* count.is(5).val(); // true
|
|
62
|
+
*/
|
|
38
63
|
ObservableItem.prototype.is = function(callbackOrValue) {
|
|
39
64
|
if(typeof callbackOrValue === 'function') {
|
|
40
65
|
return new ObservableChecker(this, callbackOrValue);
|
|
@@ -104,7 +129,7 @@ ObservableItem.prototype.format = function(type, options = {}) {
|
|
|
104
129
|
if (process.env.NODE_ENV === 'development') {
|
|
105
130
|
if (!Formatters[type]) {
|
|
106
131
|
throw new NativeDocumentError(
|
|
107
|
-
`Observable.format : unknown type '${type}'. Available : ${Object.keys(Formatters).join(', ')}
|
|
132
|
+
`Observable.format : unknown type '${type}'. Available : ${Object.keys(Formatters).join(', ')}.`,
|
|
108
133
|
);
|
|
109
134
|
}
|
|
110
135
|
}
|
|
@@ -113,6 +138,6 @@ ObservableItem.prototype.format = function(type, options = {}) {
|
|
|
113
138
|
const localeObservable = Formatters.locale;
|
|
114
139
|
|
|
115
140
|
return ObservableItem.computed(() => formatter(self.val(), localeObservable.val(), options),
|
|
116
|
-
[self, localeObservable]
|
|
141
|
+
[self, localeObservable],
|
|
117
142
|
);
|
|
118
143
|
};
|
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
/**
|
|
3
|
+
* Creates an augmented DocumentFragment with comment sentinel nodes and a MutationObserver
|
|
4
|
+
* that fires when the fragment is inserted into the live DOM.
|
|
5
|
+
* Used as the base for Anchor — not intended for direct use in application code.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
* @constructor
|
|
9
|
+
* @param {string} name - Debug label used in comment node text content
|
|
10
|
+
* @returns {AnchorWithSentinel} Augmented DocumentFragment instance
|
|
11
|
+
*/
|
|
4
12
|
export default function AnchorWithSentinel(name) {
|
|
5
13
|
const instance = Reflect.construct(DocumentFragment, [], AnchorWithSentinel);
|
|
6
14
|
const sentinel = document.createComment((name || '') + ' Anchor Sentinel');
|
|
@@ -31,11 +39,24 @@ export default function AnchorWithSentinel(name) {
|
|
|
31
39
|
AnchorWithSentinel.prototype = Object.create(DocumentFragment.prototype);
|
|
32
40
|
AnchorWithSentinel.prototype.constructor = AnchorWithSentinel;
|
|
33
41
|
|
|
42
|
+
/**
|
|
43
|
+
* Registers a callback to call every time the sentinel is connected to the live DOM.
|
|
44
|
+
* The callback receives the parent node as its argument.
|
|
45
|
+
*
|
|
46
|
+
* @param {(parent: Node) => void} callback - Called each time the fragment is inserted
|
|
47
|
+
* @returns {this}
|
|
48
|
+
*/
|
|
34
49
|
AnchorWithSentinel.prototype.onConnected = function(callback) {
|
|
35
50
|
this.$events.connected = callback;
|
|
36
51
|
return this;
|
|
37
52
|
};
|
|
38
53
|
|
|
54
|
+
/**
|
|
55
|
+
* Registers a callback to call the first time the sentinel is connected to the live DOM.
|
|
56
|
+
* After the first connection, the MutationObserver is disconnected automatically.
|
|
57
|
+
*
|
|
58
|
+
* @param {(parent: Node) => void} callback - Called once on first insertion
|
|
59
|
+
*/
|
|
39
60
|
AnchorWithSentinel.prototype.onConnectedOnce = function(callback) {
|
|
40
61
|
this.$events.connected = (parent) => {
|
|
41
62
|
callback(parent);
|
|
@@ -1,8 +1,17 @@
|
|
|
1
|
-
import Validator from
|
|
2
|
-
import {ElementCreator} from
|
|
3
|
-
import AnchorWithSentinel from
|
|
4
|
-
import oneChildAnchorOverwriting from
|
|
1
|
+
import Validator from '../../utils/validator';
|
|
2
|
+
import {ElementCreator} from '../../wrappers/ElementCreator';
|
|
3
|
+
import AnchorWithSentinel from './anchor-with-sentinel';
|
|
4
|
+
import oneChildAnchorOverwriting from './one-child-anchor-overwriting';
|
|
5
5
|
|
|
6
|
+
/**
|
|
7
|
+
* Creates an anchor fragment — a managed DocumentFragment delimited by comment sentinels.
|
|
8
|
+
* Used internally by ForEach, ShowIf, Switch, Match and other control-flow directives
|
|
9
|
+
* to manage dynamic DOM regions without a real container element.
|
|
10
|
+
*
|
|
11
|
+
* @param {string} name - Debug name for the anchor (visible as HTML comments in the DOM)
|
|
12
|
+
* @param {boolean} [isUniqueChild=false] - If true, optimises rendering when this anchor is the only child of its parent
|
|
13
|
+
* @returns {AnchorDocumentFragment} An augmented DocumentFragment with anchor management methods
|
|
14
|
+
*/
|
|
6
15
|
export default function Anchor(name, isUniqueChild = false) {
|
|
7
16
|
const anchorFragment = new AnchorWithSentinel(name);
|
|
8
17
|
|
|
@@ -22,7 +31,7 @@ export default function Anchor(name, isUniqueChild = false) {
|
|
|
22
31
|
anchorFragment.nativeAppend = anchorFragment.append;
|
|
23
32
|
|
|
24
33
|
const isParentUniqueChild = isUniqueChild
|
|
25
|
-
? () => true: (parent) => (parent.firstChild === anchorStart && parent.lastChild === anchorEnd)
|
|
34
|
+
? () => true: (parent) => (parent.firstChild === anchorStart && parent.lastChild === anchorEnd);
|
|
26
35
|
|
|
27
36
|
const insertBefore = (parent, child, target) => {
|
|
28
37
|
const childElement = Validator.isElement(child) ? child : ElementCreator.getChild(child);
|
|
@@ -85,7 +94,7 @@ export default function Anchor(name, isUniqueChild = false) {
|
|
|
85
94
|
parentNode.nativeInsertBefore(child, anchorStart);
|
|
86
95
|
return;
|
|
87
96
|
}
|
|
88
|
-
parentNode.insertBefore(child, anchorStart);
|
|
97
|
+
parentNode.insertBefore(child, anchorStart.nextSibling);
|
|
89
98
|
};
|
|
90
99
|
|
|
91
100
|
anchorFragment.removeChildren = function() {
|
|
@@ -198,4 +207,4 @@ export function createPortal(children, { parent, name = 'unnamed' } = {}) {
|
|
|
198
207
|
return anchor;
|
|
199
208
|
}
|
|
200
209
|
|
|
201
|
-
DocumentFragment.prototype.setAttribute = () => {}
|
|
210
|
+
DocumentFragment.prototype.setAttribute = () => {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import Validator from
|
|
2
|
-
import {ElementCreator} from
|
|
1
|
+
import Validator from '../../utils/validator';
|
|
2
|
+
import {ElementCreator} from '../../wrappers/ElementCreator';
|
|
3
3
|
|
|
4
4
|
|
|
5
5
|
export default function oneChildAnchorOverwriting(anchor, parent) {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import Anchor from
|
|
2
|
-
import { ElementCreator } from
|
|
3
|
-
import NativeDocumentError from
|
|
1
|
+
import Anchor from '../anchor/anchor';
|
|
2
|
+
import { ElementCreator } from '../../wrappers/ElementCreator';
|
|
3
|
+
import NativeDocumentError from '../../errors/NativeDocumentError';
|
|
4
4
|
|
|
5
5
|
|
|
6
6
|
const CREATE_AND_CACHE_ACTIONS = new Set(['clear', 'push', 'unshift', 'replace']);
|
|
@@ -30,7 +30,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
30
30
|
const element = Anchor('ForEach Array', configs.isParentUniqueChild);
|
|
31
31
|
const blockEnd = element.endElement();
|
|
32
32
|
|
|
33
|
-
|
|
33
|
+
const cache = new Map();
|
|
34
34
|
let lastNumberOfItems = 0;
|
|
35
35
|
const isIndexRequired = callback.length >= 2;
|
|
36
36
|
|
|
@@ -61,7 +61,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
61
61
|
const child = ElementCreator.getChild(callback(item, null));
|
|
62
62
|
if(process.env.NODE_ENV === 'development') {
|
|
63
63
|
if(!child) {
|
|
64
|
-
throw new NativeDocumentError(
|
|
64
|
+
throw new NativeDocumentError('ForEachArray child can\'t be null or undefined!');
|
|
65
65
|
}
|
|
66
66
|
}
|
|
67
67
|
cache.set(item, { child, indexObserver: null });
|
|
@@ -73,7 +73,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
73
73
|
const child = ElementCreator.getChild(callback(item, indexObserver));
|
|
74
74
|
if(process.env.NODE_ENV === 'development') {
|
|
75
75
|
if(!child) {
|
|
76
|
-
throw new NativeDocumentError(
|
|
76
|
+
throw new NativeDocumentError('ForEachArray child can\'t be null or undefined!');
|
|
77
77
|
}
|
|
78
78
|
}
|
|
79
79
|
cache.set(item, { child, indexObserver });
|
|
@@ -84,7 +84,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
84
84
|
const child = ElementCreator.getChild(callback(item, indexKey));
|
|
85
85
|
if(process.env.NODE_ENV === 'development') {
|
|
86
86
|
if(!child) {
|
|
87
|
-
throw new NativeDocumentError(
|
|
87
|
+
throw new NativeDocumentError('ForEachArray child can\'t be null or undefined!');
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
90
|
cache.set(item, { child, indexObserver: null });
|
|
@@ -214,7 +214,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
214
214
|
const garbageFragment = document.createDocumentFragment();
|
|
215
215
|
|
|
216
216
|
if(deleted.length > 0) {
|
|
217
|
-
|
|
217
|
+
const firstItem = deleted[0];
|
|
218
218
|
if(deleted.length === 1) {
|
|
219
219
|
removeByItem(firstItem, garbageFragment);
|
|
220
220
|
} else if(deleted.length > 1) {
|
|
@@ -266,7 +266,7 @@ export function ForEachArray(data, callback, configs = {}) {
|
|
|
266
266
|
parent.insertBefore(childA, childBNext);
|
|
267
267
|
childA = null;
|
|
268
268
|
childB = null;
|
|
269
|
-
}
|
|
269
|
+
},
|
|
270
270
|
};
|
|
271
271
|
Actions.merge = Actions.add;
|
|
272
272
|
Actions.push = Actions.add;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {Observable} from
|
|
2
|
-
import Validator from
|
|
3
|
-
import Anchor from
|
|
4
|
-
import DebugManager from
|
|
5
|
-
import {getKey} from
|
|
6
|
-
import { ElementCreator } from
|
|
7
|
-
import NativeDocumentError from
|
|
1
|
+
import {Observable} from '../../data/Observable';
|
|
2
|
+
import Validator from '../../utils/validator';
|
|
3
|
+
import Anchor from '../anchor/anchor';
|
|
4
|
+
import DebugManager from '../../utils/debug-manager';
|
|
5
|
+
import {getKey} from '../../utils/helpers';
|
|
6
|
+
import { ElementCreator } from '../../wrappers/ElementCreator';
|
|
7
|
+
import NativeDocumentError from '../../errors/NativeDocumentError';
|
|
8
8
|
|
|
9
9
|
const SELF_RENDER = (item) => item;
|
|
10
10
|
|
|
@@ -34,7 +34,7 @@ export function ForEach(data, callback, key, { shouldKeepItemsInCache = false }
|
|
|
34
34
|
const blockEnd = element.endElement();
|
|
35
35
|
const blockStart = element.startElement();
|
|
36
36
|
|
|
37
|
-
|
|
37
|
+
const cache = new Map();
|
|
38
38
|
let lastKeyOrder = null;
|
|
39
39
|
const keyIds = new Set();
|
|
40
40
|
|
|
@@ -78,9 +78,9 @@ export function ForEach(data, callback, key, { shouldKeepItemsInCache = false }
|
|
|
78
78
|
|
|
79
79
|
try {
|
|
80
80
|
const indexObserver = callback.length >= 2 ? Observable(indexKey) : null;
|
|
81
|
-
|
|
81
|
+
const child = ElementCreator.getChild(callback(item, indexObserver));
|
|
82
82
|
if(!child) {
|
|
83
|
-
throw new NativeDocumentError(
|
|
83
|
+
throw new NativeDocumentError('ForEach child can\'t be null or undefined!');
|
|
84
84
|
}
|
|
85
85
|
cache.set(keyId, { keyId, isNew: true, child: new WeakRef(child), indexObserver});
|
|
86
86
|
} catch (e) {
|
|
@@ -101,15 +101,15 @@ export function ForEach(data, callback, key, { shouldKeepItemsInCache = false }
|
|
|
101
101
|
child && fragment.appendChild(child);
|
|
102
102
|
}
|
|
103
103
|
parent.insertBefore(fragment, blockEnd);
|
|
104
|
-
}
|
|
104
|
+
};
|
|
105
105
|
|
|
106
106
|
const diffingDOMUpdates = (parent) => {
|
|
107
107
|
const operations = [];
|
|
108
|
-
|
|
108
|
+
const fragment = document.createDocumentFragment();
|
|
109
109
|
const newKeys = Array.from(keyIds);
|
|
110
110
|
const oldKeys = Array.from(lastKeyOrder);
|
|
111
111
|
|
|
112
|
-
|
|
112
|
+
const currentPosition = blockStart;
|
|
113
113
|
|
|
114
114
|
for(const index in newKeys) {
|
|
115
115
|
const itemKey = newKeys[index];
|
|
@@ -164,7 +164,7 @@ export function ForEach(data, callback, key, { shouldKeepItemsInCache = false }
|
|
|
164
164
|
|
|
165
165
|
buildContent();
|
|
166
166
|
if(Validator.isObservable(data)) {
|
|
167
|
-
data.subscribe(buildContent)
|
|
167
|
+
data.subscribe(buildContent);
|
|
168
168
|
}
|
|
169
169
|
return element;
|
|
170
170
|
}
|