native-document 1.0.14 → 1.0.16-8.1
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/.npmrc.example +1 -0
- package/.vitepress/config.js +166 -0
- package/CHANGELOG.md +153 -0
- package/cdn.js +19 -0
- package/components.d.ts +2 -0
- package/components.js +30 -0
- package/devtools/ComponentRegistry.js +113 -0
- package/devtools/index.js +8 -0
- package/devtools/plugin/dev-tools-plugin.js +15 -0
- package/devtools/transformers/nd-vite-devtools.js +55 -0
- package/devtools/transformers/src/transformComponentForHrm.js +73 -0
- package/devtools/transformers/src/transformJsFile.js +9 -0
- package/devtools/transformers/src/utils.js +79 -0
- package/devtools/transformers/templates/hrm.hook.template.js +46 -0
- package/devtools/transformers/templates/hrm.orbservable.hook.template.js +76 -0
- package/devtools/widget/Widget.js +49 -0
- package/devtools/widget/widget.css +81 -0
- package/devtools/widget.js +23 -0
- package/dist/native-document.components.min.css +1 -0
- package/dist/native-document.components.min.js +23847 -0
- package/dist/native-document.dev.js +8665 -1313
- package/dist/native-document.dev.js.map +1 -0
- package/dist/native-document.devtools.min.js +1 -0
- package/dist/native-document.min.js +1 -1
- package/docs/advanced-components.md +419 -0
- package/docs/anchor.md +218 -131
- package/docs/cache.md +180 -0
- package/docs/cli.md +179 -0
- package/docs/components/accordion.md +172 -0
- package/docs/components/alert.md +99 -0
- package/docs/components/avatar.md +160 -0
- package/docs/components/badge.md +102 -0
- package/docs/components/breadcrumb.md +89 -0
- package/docs/components/button.md +183 -0
- package/docs/components/card.md +69 -0
- package/docs/components/context-menu.md +118 -0
- package/docs/components/data-table.md +345 -0
- package/docs/components/dropdown.md +214 -0
- package/docs/components/form/autocomplete-field.md +81 -0
- package/docs/components/form/checkbox-field.md +41 -0
- package/docs/components/form/checkbox-group-field.md +54 -0
- package/docs/components/form/color-field.md +64 -0
- package/docs/components/form/date-field.md +92 -0
- package/docs/components/form/field-collection.md +63 -0
- package/docs/components/form/file-field.md +203 -0
- package/docs/components/form/form-control.md +87 -0
- package/docs/components/form/image-field.md +90 -0
- package/docs/components/form/index.md +115 -0
- package/docs/components/form/number-field.md +65 -0
- package/docs/components/form/radio-field.md +51 -0
- package/docs/components/form/select-field.md +123 -0
- package/docs/components/form/slider.md +136 -0
- package/docs/components/form/string-field.md +134 -0
- package/docs/components/form/textarea-field.md +65 -0
- package/docs/components/form-fields.md +372 -0
- package/docs/components/getting-started.md +264 -0
- package/docs/components/index.md +337 -0
- package/docs/components/layout.md +279 -0
- package/docs/components/list.md +73 -0
- package/docs/components/menu.md +215 -0
- package/docs/components/modal.md +156 -0
- package/docs/components/pagination.md +95 -0
- package/docs/components/popover.md +131 -0
- package/docs/components/progress.md +111 -0
- package/docs/components/shortcut-manager.md +221 -0
- package/docs/components/simple-table.md +107 -0
- package/docs/components/skeleton.md +155 -0
- package/docs/components/spinner.md +100 -0
- package/docs/components/splitter.md +133 -0
- package/docs/components/stepper.md +163 -0
- package/docs/components/switch.md +113 -0
- package/docs/components/tabs.md +153 -0
- package/docs/components/toast.md +119 -0
- package/docs/components/tooltip.md +151 -0
- package/docs/components/traits.md +261 -0
- package/docs/conditional-rendering.md +177 -501
- package/docs/contributing.md +300 -25
- package/docs/core-concepts.md +209 -367
- package/docs/elements.md +268 -255
- package/docs/extending-native-document-element.md +259 -0
- package/docs/filters.md +247 -0
- package/docs/getting-started.md +199 -260
- package/docs/i18n.md +241 -0
- package/docs/index.md +76 -0
- package/docs/lifecycle-events.md +146 -67
- package/docs/list-rendering.md +387 -0
- package/docs/memory-management.md +135 -46
- package/docs/native-document-element.md +487 -0
- package/docs/native-fetch.md +213 -0
- package/docs/observable-resource.md +364 -0
- package/docs/observables.md +690 -356
- package/docs/routing.md +246 -646
- package/docs/state-management.md +213 -306
- package/docs/svg-elements.md +231 -0
- package/docs/theming.md +409 -0
- package/docs/tutorials/.gitkeep +0 -0
- package/docs/validation.md +98 -93
- package/docs/vitepress-conventions.md +219 -0
- package/elements.d.ts +7 -0
- package/elements.js +3 -4
- package/eslint.config.js +35 -0
- package/i18n.js +1 -0
- package/i18n.ts +2 -0
- package/index.d.ts +21 -0
- package/index.def.js +1086 -0
- package/index.js +19 -8
- package/package.json +59 -9
- package/readme.md +294 -90
- package/rollup.config.js +52 -3
- package/router.d.ts +7 -0
- package/router.js +0 -0
- package/src/components/$traits/has-draggable/HasDraggable.d.ts +4 -0
- package/src/components/$traits/has-draggable/HasDraggable.js +82 -0
- package/src/components/$traits/has-draggable/has-draggable.css +8 -0
- package/src/components/$traits/has-items/HasItems.d.ts +9 -0
- package/src/components/$traits/has-items/HasItems.js +64 -0
- package/src/components/$traits/has-position/HasFullPosition.d.ts +14 -0
- package/src/components/$traits/has-position/HasFullPosition.js +95 -0
- package/src/components/$traits/has-position/HasPosition.d.ts +7 -0
- package/src/components/$traits/has-position/HasPosition.js +45 -0
- package/src/components/$traits/has-resizable/HasResizable.d.ts +13 -0
- package/src/components/$traits/has-resizable/HasResizable.js +122 -0
- package/src/components/$traits/has-resizable/has-resizable.css +121 -0
- package/src/components/$traits/has-validation/HasValidation.d.ts +17 -0
- package/src/components/$traits/has-validation/HasValidation.js +133 -0
- package/src/components/BaseComponent.d.ts +32 -0
- package/src/components/BaseComponent.js +247 -0
- package/src/components/accordion/Accordion.js +268 -0
- package/src/components/accordion/AccordionItem.js +233 -0
- package/src/components/accordion/index.js +7 -0
- 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 +350 -0
- package/src/components/alert/index.js +6 -0
- package/src/components/alert/types/Alert.d.ts +62 -0
- package/src/components/avatar/Avatar.js +430 -0
- package/src/components/avatar/AvatarGroup.js +97 -0
- package/src/components/avatar/index.js +7 -0
- 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 +245 -0
- package/src/components/badge/index.js +6 -0
- package/src/components/badge/types/Badge.d.ts +51 -0
- package/src/components/base-component.css +0 -0
- package/src/components/breadcrumb/BreadCrumb.js +138 -0
- package/src/components/breadcrumb/index.js +5 -0
- package/src/components/breadcrumb/types/BreadCrumb.d.ts +42 -0
- package/src/components/button/Button.js +320 -0
- package/src/components/button/index.js +5 -0
- package/src/components/button/types/Button.d.ts +62 -0
- package/src/components/card/Card.js +282 -0
- package/src/components/card/index.js +5 -0
- package/src/components/card/types/Card.d.ts +42 -0
- package/src/components/context-menu/ContextMenu.js +127 -0
- package/src/components/context-menu/ContextMenuGroup.js +29 -0
- package/src/components/context-menu/ContextMenuItem.js +28 -0
- package/src/components/context-menu/index.js +10 -0
- 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 +256 -0
- package/src/components/divider/index.js +6 -0
- package/src/components/divider/types/Divider.d.ts +55 -0
- package/src/components/dropdown/Dropdown.js +531 -0
- package/src/components/dropdown/DropdownDivider.js +45 -0
- package/src/components/dropdown/DropdownGroup.js +83 -0
- package/src/components/dropdown/DropdownItem.js +150 -0
- package/src/components/dropdown/DropdownTrigger.js +93 -0
- package/src/components/dropdown/helpers.js +53 -0
- package/src/components/dropdown/index.js +13 -0
- 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 +498 -0
- package/src/components/form/field/Field.js +419 -0
- package/src/components/form/field/FieldCollection.js +292 -0
- package/src/components/form/field/types/AutocompleteField.js +168 -0
- package/src/components/form/field/types/CheckboxField.js +77 -0
- package/src/components/form/field/types/CheckboxGroupField.js +171 -0
- package/src/components/form/field/types/ColorField.js +102 -0
- package/src/components/form/field/types/DateField.js +315 -0
- package/src/components/form/field/types/EmailField.js +104 -0
- package/src/components/form/field/types/FileField.js +276 -0
- package/src/components/form/field/types/HiddenField.js +44 -0
- package/src/components/form/field/types/ImageField.js +138 -0
- package/src/components/form/field/types/NumberField.js +177 -0
- package/src/components/form/field/types/PasswordField.js +200 -0
- package/src/components/form/field/types/RadioField.js +145 -0
- package/src/components/form/field/types/RangeField.js +117 -0
- package/src/components/form/field/types/SearchField.js +66 -0
- package/src/components/form/field/types/SelectField.js +247 -0
- package/src/components/form/field/types/StringField.js +148 -0
- package/src/components/form/field/types/TelField.js +98 -0
- package/src/components/form/field/types/TextAreaField.js +142 -0
- package/src/components/form/field/types/TimeField.js +215 -0
- package/src/components/form/field/types/UrlField.js +115 -0
- package/src/components/form/field/types/file-field-mode/FileAvatarMode.js +183 -0
- package/src/components/form/field/types/file-field-mode/FileDropzoneMode.js +117 -0
- package/src/components/form/field/types/file-field-mode/FileItemPreview.js +150 -0
- package/src/components/form/field/types/file-field-mode/FileNativeMode.js +43 -0
- package/src/components/form/field/types/file-field-mode/FileUploadButtonMode.js +120 -0
- package/src/components/form/field/types/file-field-mode/FileWallMode.js +106 -0
- package/src/components/form/index.js +61 -0
- package/src/components/form/merge +0 -0
- 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/utils.js +17 -0
- package/src/components/form/validation/Validation.js +565 -0
- package/src/components/index.d.ts +160 -0
- package/src/components/list/HasListItem.js +171 -0
- package/src/components/list/List.js +125 -0
- package/src/components/list/ListDivider.js +39 -0
- package/src/components/list/ListGroup.js +135 -0
- package/src/components/list/ListItem.js +212 -0
- package/src/components/list/index.js +12 -0
- 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 +53 -0
- package/src/components/menu/HasMenuItem.js +182 -0
- package/src/components/menu/Menu.js +227 -0
- package/src/components/menu/MenuDivider.js +37 -0
- package/src/components/menu/MenuGroup.js +126 -0
- package/src/components/menu/MenuItem.js +190 -0
- package/src/components/menu/MenuLink.js +51 -0
- package/src/components/menu/index.js +14 -0
- 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 +524 -0
- package/src/components/modal/index.js +5 -0
- package/src/components/modal/types/Modal.d.ts +94 -0
- package/src/components/pagination/Pagination.js +411 -0
- package/src/components/pagination/index.js +5 -0
- package/src/components/pagination/types/Pagination.d.ts +68 -0
- package/src/components/popover/Popover.js +459 -0
- package/src/components/popover/PopoverFooter.js +61 -0
- package/src/components/popover/PopoverHeader.js +68 -0
- package/src/components/popover/index.js +10 -0
- 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 +401 -0
- package/src/components/progress/index.js +6 -0
- package/src/components/progress/types/Progress.d.ts +77 -0
- package/src/components/skeleton/Skeleton.js +228 -0
- package/src/components/skeleton/index.js +6 -0
- package/src/components/skeleton/types/Skeleton.d.ts +55 -0
- package/src/components/slider/Slider.js +406 -0
- package/src/components/slider/index.js +5 -0
- package/src/components/slider/types/Slider.d.ts +82 -0
- package/src/components/spacer/Spacer.js +27 -0
- package/src/components/spacer/index.js +5 -0
- package/src/components/spacer/types/Spacer.d.ts +19 -0
- package/src/components/spinner/Spinner.js +350 -0
- package/src/components/spinner/index.js +5 -0
- package/src/components/spinner/types/Spinner.d.ts +71 -0
- package/src/components/splitter/Splitter.js +164 -0
- package/src/components/splitter/SplitterGutter.js +140 -0
- package/src/components/splitter/SplitterPanel.js +143 -0
- package/src/components/splitter/index.js +10 -0
- 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 +53 -0
- package/src/components/stacks/FixedStack.js +53 -0
- package/src/components/stacks/HStack.js +54 -0
- package/src/components/stacks/PositionStack.js +254 -0
- package/src/components/stacks/RelativeStack.js +53 -0
- package/src/components/stacks/Stack.js +166 -0
- package/src/components/stacks/VStack.js +55 -0
- package/src/components/stacks/index.js +21 -0
- 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 +461 -0
- package/src/components/stepper/StepperStep.js +241 -0
- package/src/components/stepper/index.js +8 -0
- 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 +266 -0
- package/src/components/switch/index.js +6 -0
- package/src/components/switch/types/Switch.d.ts +55 -0
- package/src/components/table/Column.js +212 -0
- package/src/components/table/ColumnGroup.js +90 -0
- package/src/components/table/DataTable.js +720 -0
- package/src/components/table/SimpleTable.js +139 -0
- package/src/components/table/index.js +7 -0
- 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 +395 -0
- package/src/components/tabs/index.js +6 -0
- package/src/components/tabs/types/Tabs.d.ts +78 -0
- package/src/components/toast/Toast.js +262 -0
- package/src/components/toast/ToastError.js +0 -0
- package/src/components/toast/ToastInfo.js +0 -0
- package/src/components/toast/ToastSuccess.js +0 -0
- package/src/components/toast/ToastWarning.js +0 -0
- package/src/components/toast/index.js +5 -0
- 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 +359 -0
- package/src/components/tooltip/index.js +5 -0
- package/src/components/tooltip/prototypes.js +6 -0
- package/src/components/tooltip/types/Tooltip.d.ts +65 -0
- package/src/{data → core/data}/MemoryManager.js +9 -22
- package/src/core/data/Observable.js +227 -0
- package/src/core/data/ObservableArray.js +522 -0
- package/src/core/data/ObservableChecker.js +39 -0
- package/src/core/data/ObservableItem.js +611 -0
- package/src/core/data/ObservableObject.js +274 -0
- package/src/core/data/ObservableResource.js +315 -0
- package/src/core/data/ObservableWhen.js +54 -0
- package/src/core/data/Store.js +520 -0
- package/src/core/data/observable-helpers/observable.is-to.js +390 -0
- package/src/core/data/observable-helpers/observable.prototypes.js +145 -0
- package/src/core/elements/anchor/anchor-with-sentinel.js +66 -0
- package/src/core/elements/anchor/anchor.js +210 -0
- package/src/core/elements/anchor/one-child-anchor-overwriting.js +66 -0
- package/src/core/elements/content-formatter.js +169 -0
- package/src/core/elements/control/for-each-array.js +292 -0
- package/src/core/elements/control/for-each.js +170 -0
- package/src/core/elements/control/show-if.js +94 -0
- package/src/core/elements/control/show-when.js +54 -0
- package/src/core/elements/control/switch.js +141 -0
- package/src/core/elements/description-list.js +19 -0
- package/src/core/elements/form.js +255 -0
- package/src/core/elements/fragment.js +8 -0
- package/src/core/elements/html5-semantics.js +55 -0
- package/src/core/elements/img.js +59 -0
- package/src/{elements → core/elements}/index.js +5 -4
- package/src/core/elements/interactive.js +25 -0
- package/src/core/elements/list.js +37 -0
- package/src/core/elements/medias.js +37 -0
- package/src/core/elements/meta-data.js +43 -0
- package/src/core/elements/svg.js +61 -0
- package/src/core/elements/table.js +73 -0
- package/src/{errors → core/errors}/ArgTypesError.js +1 -1
- package/src/{errors → core/errors}/NativeDocumentError.js +0 -0
- package/src/core/utils/HasEventEmitter.js +85 -0
- package/src/core/utils/args-types.js +140 -0
- package/src/core/utils/cache.js +5 -0
- package/src/core/utils/callback-handler.js +50 -0
- package/src/core/utils/debug-manager.js +40 -0
- package/src/core/utils/events.js +148 -0
- package/src/core/utils/filters/date.js +178 -0
- package/src/core/utils/filters/index.js +4 -0
- package/src/core/utils/filters/standard.js +263 -0
- package/src/core/utils/filters/strings.js +67 -0
- package/src/core/utils/filters/utils.js +77 -0
- package/src/core/utils/formatters.js +90 -0
- package/src/core/utils/helpers.js +144 -0
- package/src/core/utils/localstorage.js +57 -0
- package/src/core/utils/memoize.js +115 -0
- package/src/core/utils/plugins-manager.js +81 -0
- package/src/core/utils/property-accumulator.js +72 -0
- package/src/core/utils/prototypes.js +44 -0
- package/src/core/utils/shortcut-manager.js +242 -0
- package/src/{utils → core/utils}/validator.js +58 -22
- package/src/core/wrappers/AttributesWrapper.js +181 -0
- package/src/core/wrappers/DocumentObserver.js +182 -0
- package/src/core/wrappers/ElementCreator.js +110 -0
- package/src/core/wrappers/HtmlElementWrapper.js +98 -0
- package/src/core/wrappers/NDElement.js +613 -0
- package/src/core/wrappers/NdPrototype.js +233 -0
- package/src/core/wrappers/SingletonView.js +99 -0
- package/src/core/wrappers/SvgElementWrapper.js +15 -0
- package/src/core/wrappers/TemplateBinding.js +7 -0
- package/src/core/wrappers/constants.js +66 -0
- package/src/core/wrappers/prototypes/attributes-extensions.js +24 -0
- package/src/core/wrappers/prototypes/bind-class-extensions.js +0 -0
- package/src/core/wrappers/prototypes/nd-element-extensions.js +149 -0
- package/src/core/wrappers/prototypes/nd-element.transition.extensions.js +127 -0
- package/src/core/wrappers/template-cloner/NodeCloner.js +209 -0
- package/src/core/wrappers/template-cloner/TemplateCloner.js +192 -0
- package/src/core/wrappers/template-cloner/attributes-hydrator.js +142 -0
- package/src/core/wrappers/template-cloner/utils.js +173 -0
- package/src/fetch/NativeFetch.js +89 -0
- package/src/i18n/bin/scan.js +132 -0
- package/src/i18n/index.d.ts +2 -0
- package/src/i18n/service/I18nService.d.ts +27 -0
- package/src/i18n/service/I18nService.js +46 -0
- package/src/i18n/service/functions.d.ts +22 -0
- package/src/i18n/service/functions.js +29 -0
- package/src/router/Route.js +33 -8
- package/src/router/RouteGroupHelper.js +10 -2
- package/src/router/Router.js +63 -22
- package/src/router/RouterComponent.js +114 -6
- package/src/{errors → router/errors}/RouterError.js +0 -1
- package/src/router/link.js +9 -10
- package/src/router/modes/HashRouter.js +2 -2
- package/src/router/modes/HistoryRouter.js +2 -3
- package/src/router/modes/MemoryRouter.js +1 -1
- package/src/ui/components/accordion/AccordionItemRender.js +63 -0
- package/src/ui/components/accordion/AccordionRender.js +35 -0
- package/src/ui/components/accordion/accordion.css +121 -0
- package/src/ui/components/alert/AlertRender.js +81 -0
- package/src/ui/components/alert/alert.css +163 -0
- package/src/ui/components/avatar/avata-group/AvatarGroupRender.js +50 -0
- package/src/ui/components/avatar/avata-group/avatar-group.css +38 -0
- package/src/ui/components/avatar/avatar/AvatarRender.js +87 -0
- package/src/ui/components/avatar/avatar/avatar.css +189 -0
- package/src/ui/components/badge/BadgeRender.js +25 -0
- package/src/ui/components/badge/badge.css +168 -0
- package/src/ui/components/breadcrumb/BreadcrumbRender.js +44 -0
- package/src/ui/components/breadcrumb/breadcrumb.css +55 -0
- package/src/ui/components/button/ButtonRender.js +65 -0
- package/src/ui/components/button/button.css +296 -0
- package/src/ui/components/card/CardRender.js +133 -0
- package/src/ui/components/card/card.css +169 -0
- package/src/ui/components/contextmenu/ContextmenuRender.js +68 -0
- package/src/ui/components/contextmenu/contextmenu.css +36 -0
- package/src/ui/components/divider/DividerRender.js +70 -0
- package/src/ui/components/divider/divider.css +70 -0
- package/src/ui/components/dropdown/DropdownRender.js +92 -0
- package/src/ui/components/dropdown/divider/DropdownDividerRender.js +9 -0
- package/src/ui/components/dropdown/divider/dropdown-divider.css +0 -0
- package/src/ui/components/dropdown/dropdown.css +179 -0
- package/src/ui/components/dropdown/group/DropdownGroupRender.js +23 -0
- package/src/ui/components/dropdown/group/dropdown-group.css +0 -0
- package/src/ui/components/dropdown/item/DropdownItemRender.js +29 -0
- package/src/ui/components/dropdown/item/dropdown-item.css +0 -0
- package/src/ui/components/form/FieldCollectionRender.js +110 -0
- package/src/ui/components/form/FormControlRender.js +85 -0
- package/src/ui/components/form/field-collection.css +55 -0
- package/src/ui/components/form/fields/AutocompleteFieldRender.js +143 -0
- package/src/ui/components/form/fields/CheckboxFieldRender.js +59 -0
- package/src/ui/components/form/fields/CheckboxGroupFieldRender.js +92 -0
- package/src/ui/components/form/fields/ColorFieldRender.js +30 -0
- package/src/ui/components/form/fields/DateFieldRender.js +155 -0
- package/src/ui/components/form/fields/EmailFieldRender.js +5 -0
- package/src/ui/components/form/fields/FieldRender.js +118 -0
- package/src/ui/components/form/fields/FileFieldRender.js +41 -0
- package/src/ui/components/form/fields/HiddenFieldRender.js +13 -0
- package/src/ui/components/form/fields/ImageFieldRender.js +0 -0
- package/src/ui/components/form/fields/NumberFieldRender.js +52 -0
- package/src/ui/components/form/fields/PasswordFieldRender.js +65 -0
- package/src/ui/components/form/fields/RadioFieldRender.js +77 -0
- package/src/ui/components/form/fields/RangeFieldRender.js +122 -0
- package/src/ui/components/form/fields/SelectFieldRender.js +248 -0
- package/src/ui/components/form/fields/SliderFieldRender.js +359 -0
- package/src/ui/components/form/fields/StringFieldRender.js +6 -0
- package/src/ui/components/form/fields/TelFieldRender.js +6 -0
- package/src/ui/components/form/fields/TextAreaFieldRender.js +96 -0
- package/src/ui/components/form/fields/TimeFieldRender.js +142 -0
- package/src/ui/components/form/fields/UrlFieldRender.js +6 -0
- package/src/ui/components/form/fields/date-field.css +32 -0
- package/src/ui/components/form/fields/field.css +402 -0
- package/src/ui/components/form/fields/file-field.css +79 -0
- package/src/ui/components/form/fields/password-field.css +50 -0
- package/src/ui/components/form/fields/range-field.css +120 -0
- package/src/ui/components/form/fields/slider.css +195 -0
- package/src/ui/components/form/file-upload-mode/FileAvatarModeRender.js +143 -0
- package/src/ui/components/form/file-upload-mode/FileDropzoneModeRender.js +108 -0
- package/src/ui/components/form/file-upload-mode/FileNativeModeRender.js +22 -0
- package/src/ui/components/form/file-upload-mode/FileUploadButtonModeRender.js +89 -0
- package/src/ui/components/form/file-upload-mode/FileWallModeRender.js +90 -0
- package/src/ui/components/form/file-upload-mode/file-avatar-mode.css +139 -0
- package/src/ui/components/form/file-upload-mode/file-dropzone-mode.css +88 -0
- package/src/ui/components/form/file-upload-mode/file-upload-button-mode.css +44 -0
- package/src/ui/components/form/file-upload-mode/file-wall-mode.css +88 -0
- package/src/ui/components/form/form-control.css +40 -0
- package/src/ui/components/form/helpers.js +111 -0
- package/src/ui/components/form/index.js +27 -0
- package/src/ui/components/list/ListRender.js +18 -0
- package/src/ui/components/list/divider/ListDividerRender.js +10 -0
- package/src/ui/components/list/divider/list-divider.css +12 -0
- package/src/ui/components/list/group/ListGroupRender.js +61 -0
- package/src/ui/components/list/group/list-group.css +62 -0
- package/src/ui/components/list/item/ListItemRender.js +238 -0
- package/src/ui/components/list/item/list-item.css +191 -0
- package/src/ui/components/list/list.css +24 -0
- package/src/ui/components/menu/MenuDividerRender.js +12 -0
- package/src/ui/components/menu/MenuGroupRender.js +59 -0
- package/src/ui/components/menu/MenuItemRender.js +57 -0
- package/src/ui/components/menu/MenuLinkRender.js +55 -0
- package/src/ui/components/menu/MenuRender.js +22 -0
- package/src/ui/components/menu/helpers.js +121 -0
- package/src/ui/components/menu/menu.css +308 -0
- package/src/ui/components/modal/ModalRender.js +118 -0
- package/src/ui/components/modal/modal.css +156 -0
- package/src/ui/components/pagination/PaginationRender.js +112 -0
- package/src/ui/components/pagination/pagination.css +63 -0
- package/src/ui/components/popover/PopoverRender.js +233 -0
- package/src/ui/components/popover/popover.css +139 -0
- package/src/ui/components/progress/ProgressRender.js +168 -0
- package/src/ui/components/progress/progress.css +197 -0
- package/src/ui/components/skeleton/SkeletonRender.js +136 -0
- package/src/ui/components/skeleton/skeleton.css +154 -0
- package/src/ui/components/spacer/SpacerRender.js +10 -0
- package/src/ui/components/spinner/SpinnerRender.js +47 -0
- package/src/ui/components/spinner/spinner.css +152 -0
- package/src/ui/components/splitter/SplitterGutterRender.js +94 -0
- package/src/ui/components/splitter/SplitterPanelRender.js +38 -0
- package/src/ui/components/splitter/SplitterRender.js +75 -0
- package/src/ui/components/splitter/splitter.css +128 -0
- package/src/ui/components/stacks/PositionStackRender.js +39 -0
- package/src/ui/components/stacks/StackRender.js +41 -0
- package/src/ui/components/stacks/absolute-stack/AbsoluteStackRender.js +5 -0
- package/src/ui/components/stacks/fixed-stack/FixedStackRender.js +5 -0
- package/src/ui/components/stacks/h-stack/HStackRender.js +7 -0
- package/src/ui/components/stacks/h-stack/h-stack.css +4 -0
- package/src/ui/components/stacks/index.js +5 -0
- package/src/ui/components/stacks/position-stack.css +62 -0
- package/src/ui/components/stacks/relative-stack/RelativeStackRender.js +7 -0
- package/src/ui/components/stacks/relative-stack/relative-stack.css +3 -0
- package/src/ui/components/stacks/stack.css +78 -0
- package/src/ui/components/stacks/v-stack/VStackRender.js +6 -0
- package/src/ui/components/stacks/v-stack/v-stack.css +4 -0
- package/src/ui/components/stepper/StepperRender.js +71 -0
- package/src/ui/components/stepper/StepperStepRender.js +67 -0
- package/src/ui/components/stepper/stepper.css +359 -0
- package/src/ui/components/switch/SwitchRender.js +83 -0
- package/src/ui/components/switch/switch.css +143 -0
- package/src/ui/components/table/data-table/DataTableRender.js +50 -0
- package/src/ui/components/table/data-table/bulk-actions.js +34 -0
- package/src/ui/components/table/data-table/data-table.css +246 -0
- package/src/ui/components/table/data-table/pagination.js +56 -0
- package/src/ui/components/table/data-table/tables.js +368 -0
- package/src/ui/components/table/data-table/toolbar.js +67 -0
- package/src/ui/components/table/simple-table/SimpleTableRender.js +203 -0
- package/src/ui/components/table/simple-table/simple-table.css +50 -0
- package/src/ui/components/tabs/TabsRender.js +226 -0
- package/src/ui/components/tabs/tabs.css +253 -0
- package/src/ui/components/toast/ToastRender.js +99 -0
- package/src/ui/components/toast/toast.css +201 -0
- package/src/ui/components/tooltip/TooltipRender.js +8 -0
- package/src/ui/components/tooltip/tooltip.css +113 -0
- package/src/ui/index.js +47 -0
- package/src/ui/theme.js +0 -0
- package/src/ui/theme.scss +1 -0
- package/src/ui/tokens/animation.scss +36 -0
- package/src/ui/tokens/colors-dark.scss +58 -0
- package/src/ui/tokens/colors.scss +54 -0
- package/src/ui/tokens/components.scss +32 -0
- package/src/ui/tokens/fonts.scss +57 -0
- package/src/ui/tokens/glass.scss +10 -0
- package/src/ui/tokens/index.scss +38 -0
- package/src/ui/tokens/layouts.scss +228 -0
- package/src/ui/tokens/opacity.scss +21 -0
- package/src/ui/tokens/others.scss +11 -0
- package/src/ui/tokens/radius.scss +6 -0
- package/src/ui/tokens/reset.scss +51 -0
- package/src/ui/tokens/shadows.scss +29 -0
- package/src/ui/tokens/spacings.scss +13 -0
- package/src/ui/tokens/vars.scss +35 -0
- package/src/ui/tokens/viewports.scss +30 -0
- package/types/args-types.d.ts +58 -0
- package/types/control-flow.d.ts +62 -0
- package/types/elements.d.ts +231 -0
- package/types/filters/dates.d.ts +43 -0
- package/types/filters/index.d.ts +4 -0
- package/types/filters/standard.d.ts +70 -0
- package/types/filters/strings.d.ts +21 -0
- package/types/filters/types.d.ts +20 -0
- package/types/forms.d.ts +84 -0
- package/types/globals.d.ts +543 -0
- package/types/images.d.ts +23 -0
- package/types/localStorage.ts +102 -0
- package/types/memoize.d.ts +26 -0
- package/types/native-fetch.d.ts +72 -0
- package/types/nd-element.d.ts +407 -0
- package/types/observable-resource.d.ts +3 -0
- package/types/observable.d.ts +227 -0
- package/types/plugins-manager.d.ts +65 -0
- package/types/polyfill.d.ts +18 -0
- package/types/property-accumulator.d.ts +33 -0
- package/types/router.d.ts +85 -0
- package/types/service.d.ts +23 -0
- package/types/singleton.d.ts +19 -0
- package/types/store.d.ts +63 -0
- package/types/template-cloner.ts +43 -0
- package/types/validator.ts +66 -0
- package/ui.js +1 -0
- package/utils.d.ts +4 -0
- package/utils.js +12 -0
- package/src/data/Observable.js +0 -233
- package/src/data/ObservableChecker.js +0 -38
- package/src/data/ObservableItem.js +0 -116
- package/src/data/Store.js +0 -74
- package/src/elements/anchor.js +0 -84
- package/src/elements/content-formatter.js +0 -32
- package/src/elements/control/for-each.js +0 -174
- package/src/elements/control/show-if.js +0 -79
- package/src/elements/control/switch.js +0 -98
- package/src/elements/description-list.js +0 -5
- package/src/elements/form.js +0 -71
- package/src/elements/html5-semantics.js +0 -12
- package/src/elements/img.js +0 -45
- package/src/elements/interactive.js +0 -7
- package/src/elements/list.js +0 -6
- package/src/elements/medias.js +0 -8
- package/src/elements/meta-data.js +0 -9
- package/src/elements/table.js +0 -14
- package/src/utils/args-types.js +0 -100
- package/src/utils/debug-manager.js +0 -31
- package/src/utils/helpers.js +0 -37
- package/src/utils/plugins-manager.js +0 -12
- package/src/utils/prototypes.js +0 -45
- package/src/wrappers/AttributesWrapper.js +0 -157
- package/src/wrappers/DocumentObserver.js +0 -51
- package/src/wrappers/HtmlElementEventsWrapper.js +0 -77
- package/src/wrappers/HtmlElementWrapper.js +0 -206
- package/src/wrappers/constants.js +0 -2
|
@@ -0,0 +1,611 @@
|
|
|
1
|
+
import DebugManager from '../../core/utils/debug-manager';
|
|
2
|
+
import MemoryManager from './MemoryManager';
|
|
3
|
+
import NativeDocumentError from '../../core/errors/NativeDocumentError';
|
|
4
|
+
import PluginsManager from '../../core/utils/plugins-manager';
|
|
5
|
+
import Validator from '../../core/utils/validator';
|
|
6
|
+
import {deepClone} from '../utils/helpers';
|
|
7
|
+
import {$getFromStorage, $saveToStorage} from '../utils/localstorage';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Reactive primitive value container.
|
|
11
|
+
* Notifies subscribers whenever its value changes.
|
|
12
|
+
* The core building block of NativeDocument's reactivity system.
|
|
13
|
+
*
|
|
14
|
+
* @constructor
|
|
15
|
+
* @param {*} value - Initial value of the observable
|
|
16
|
+
* @param {{ propagation?: boolean, reset?: boolean, deep?: boolean } | null} [configs=null] - Optional configuration
|
|
17
|
+
* @param {boolean} [configs.reset] - If true, stores the initial value for later reset via .reset()
|
|
18
|
+
* @param {boolean} [configs.propagation] - Controls whether changes propagate to parent observables
|
|
19
|
+
* @example
|
|
20
|
+
* const count = new ObservableItem(0);
|
|
21
|
+
* const name = new ObservableItem('John', { reset: true });
|
|
22
|
+
*/
|
|
23
|
+
export default function ObservableItem(value, configs = null) {
|
|
24
|
+
value = Validator.isObservable(value) ? value.val() : value;
|
|
25
|
+
|
|
26
|
+
this.$previousValue = null;
|
|
27
|
+
this.$currentValue = value;
|
|
28
|
+
if(process.env.NODE_ENV === 'development') {
|
|
29
|
+
this.$isCleanedUp = false;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
this.$firstListener = null;
|
|
33
|
+
this.$listeners = null;
|
|
34
|
+
this.$watchers = null;
|
|
35
|
+
|
|
36
|
+
this.$memoryId = null;
|
|
37
|
+
|
|
38
|
+
if(configs) {
|
|
39
|
+
this.configs = configs;
|
|
40
|
+
if(configs.reset) {
|
|
41
|
+
this.$initialValue = Validator.isObject(value) ? deepClone(value) : value;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
if(process.env.NODE_ENV === 'development') {
|
|
45
|
+
PluginsManager.emit('CreateObservable', this);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
Object.defineProperty(ObservableItem.prototype, '$value', {
|
|
50
|
+
get() {
|
|
51
|
+
return this.$currentValue;
|
|
52
|
+
},
|
|
53
|
+
set(value) {
|
|
54
|
+
this.set(value);
|
|
55
|
+
},
|
|
56
|
+
configurable: true,
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
ObservableItem.prototype.__$Observable = true;
|
|
60
|
+
ObservableItem.prototype.__$isObservable = true;
|
|
61
|
+
ObservableItem.computed = () => {};
|
|
62
|
+
|
|
63
|
+
const DEFAULT_OPERATIONS = {};
|
|
64
|
+
const noneTrigger = function() {};
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Intercepts and transforms values before they are set on the observable.
|
|
68
|
+
* The interceptor can modify the value or return undefined to use the original value.
|
|
69
|
+
*
|
|
70
|
+
* @param {(value) => any} callback - Interceptor function that receives (newValue, currentValue) and returns the transformed value or undefined
|
|
71
|
+
* @returns {ObservableItem} The observable instance for chaining
|
|
72
|
+
* @example
|
|
73
|
+
* const count = Observable(0);
|
|
74
|
+
* count.intercept((newVal, oldVal) => Math.max(0, newVal)); // Prevent negative values
|
|
75
|
+
*/
|
|
76
|
+
ObservableItem.prototype.intercept = function(callback) {
|
|
77
|
+
this.$interceptor = callback;
|
|
78
|
+
this.set = this.$setWithInterceptor;
|
|
79
|
+
return this;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Intercepts mutations of the array observable before they are applied.
|
|
84
|
+
* Allows transforming or cancelling array operations.
|
|
85
|
+
*
|
|
86
|
+
* @param {(operation: { action: string, args: any[] }) => void} callback - Called before each mutation with the operation details
|
|
87
|
+
* @returns {ObservableItem} this
|
|
88
|
+
*/
|
|
89
|
+
ObservableItem.prototype.interceptMutations = function(callback) {
|
|
90
|
+
this.$mutationInterceptor = callback;
|
|
91
|
+
return this;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
/**
|
|
95
|
+
* Calls the first registered subscriber directly (internal optimisation).
|
|
96
|
+
*
|
|
97
|
+
* @internal
|
|
98
|
+
* @param {{ action?: string, args?: any[], result?: any }} [operations] - Mutation metadata
|
|
99
|
+
*/
|
|
100
|
+
ObservableItem.prototype.triggerFirstListener = function(operations) {
|
|
101
|
+
this.$firstListener(this.$currentValue, this.$previousValue, operations);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Calls all registered subscribers (internal).
|
|
106
|
+
*
|
|
107
|
+
* @internal
|
|
108
|
+
* @param {{ action?: string, args?: any[], result?: any }} [operations] - Mutation metadata
|
|
109
|
+
*/
|
|
110
|
+
ObservableItem.prototype.triggerListeners = function(operations) {
|
|
111
|
+
const $listeners = this.$listeners;
|
|
112
|
+
const $previousValue = this.$previousValue;
|
|
113
|
+
const $currentValue = this.$currentValue;
|
|
114
|
+
|
|
115
|
+
for(let i = 0, length = $listeners.length; i < length; i++) {
|
|
116
|
+
$listeners[i]($currentValue, $previousValue, operations);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Triggers callbacks registered via .on() for the current and previous values (internal).
|
|
122
|
+
*
|
|
123
|
+
* @internal
|
|
124
|
+
* @param {{ action?: string, args?: any[], result?: any }} [operations] - Mutation metadata
|
|
125
|
+
*/
|
|
126
|
+
ObservableItem.prototype.triggerWatchers = function(operations) {
|
|
127
|
+
const $watchers = this.$watchers;
|
|
128
|
+
const $previousValue = this.$previousValue;
|
|
129
|
+
const $currentValue = this.$currentValue;
|
|
130
|
+
|
|
131
|
+
const $currentValueCallbacks = $watchers.get($currentValue);
|
|
132
|
+
const $previousValueCallbacks = $watchers.get($previousValue);
|
|
133
|
+
if($currentValueCallbacks) {
|
|
134
|
+
$currentValueCallbacks(true, $previousValue, operations);
|
|
135
|
+
}
|
|
136
|
+
if($previousValueCallbacks) {
|
|
137
|
+
$previousValueCallbacks(false, $currentValue, operations);
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Triggers both watchers and all subscribers (internal).
|
|
143
|
+
*
|
|
144
|
+
* @internal
|
|
145
|
+
* @param {{ action?: string, args?: any[], result?: any }} [operations] - Mutation metadata
|
|
146
|
+
*/
|
|
147
|
+
ObservableItem.prototype.triggerAll = function(operations) {
|
|
148
|
+
this.triggerWatchers(operations);
|
|
149
|
+
this.triggerListeners(operations);
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* Triggers both watchers and the first subscriber only (internal optimization).
|
|
154
|
+
*
|
|
155
|
+
* @internal
|
|
156
|
+
* @param {{ action?: string, args?: any[], result?: any }} [operations] - Mutation metadata
|
|
157
|
+
*/
|
|
158
|
+
ObservableItem.prototype.triggerWatchersAndFirstListener = function(operations) {
|
|
159
|
+
this.triggerWatchers(operations);
|
|
160
|
+
this.triggerFirstListener(operations);
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* Selects and assigns the optimal trigger strategy based on the current
|
|
165
|
+
* combination of listeners and watchers (internal).
|
|
166
|
+
* Called automatically after every subscribe / unsubscribe / on / off.
|
|
167
|
+
*
|
|
168
|
+
* @internal
|
|
169
|
+
*/
|
|
170
|
+
ObservableItem.prototype.assocTrigger = function() {
|
|
171
|
+
this.$firstListener = null;
|
|
172
|
+
if(this.$watchers?.size && this.$listeners?.length) {
|
|
173
|
+
this.$firstListener = this.$listeners[0];
|
|
174
|
+
this.trigger = this.$firstListener.length === 0 ? this.$firstListener : this.triggerFirstListener;
|
|
175
|
+
this.trigger = (this.$listeners.length === 1) ? this.triggerWatchersAndFirstListener : this.triggerAll;
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
if(this.$listeners?.length) {
|
|
179
|
+
if(this.$listeners.length === 1) {
|
|
180
|
+
this.$firstListener = this.$listeners[0];
|
|
181
|
+
this.trigger = this.$firstListener.length === 0 ? this.$firstListener : this.triggerFirstListener;
|
|
182
|
+
}
|
|
183
|
+
else {
|
|
184
|
+
this.trigger = this.triggerListeners;
|
|
185
|
+
}
|
|
186
|
+
return;
|
|
187
|
+
}
|
|
188
|
+
if(this.$watchers?.size) {
|
|
189
|
+
this.trigger = this.triggerWatchers;
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
this.trigger = noneTrigger;
|
|
193
|
+
};
|
|
194
|
+
ObservableItem.prototype.trigger = noneTrigger;
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
const $setOperation = { action: 'set' };
|
|
198
|
+
ObservableItem.prototype.$updateWithNewValue = function(newValue) {
|
|
199
|
+
newValue = newValue?.__$isObservable ? newValue.val() : newValue;
|
|
200
|
+
if(this.$currentValue === newValue) {
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
this.$previousValue = this.$currentValue;
|
|
204
|
+
this.$currentValue = newValue;
|
|
205
|
+
if(process.env.NODE_ENV === 'development') {
|
|
206
|
+
PluginsManager.emit('ObservableBeforeChange', this);
|
|
207
|
+
}
|
|
208
|
+
this.trigger($setOperation);
|
|
209
|
+
this.$previousValue = null;
|
|
210
|
+
if(process.env.NODE_ENV === 'development') {
|
|
211
|
+
PluginsManager.emit('ObservableAfterChange', this);
|
|
212
|
+
}
|
|
213
|
+
};
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* @param {*} data
|
|
217
|
+
*/
|
|
218
|
+
ObservableItem.prototype.$setWithInterceptor = function(data) {
|
|
219
|
+
let newValue = (typeof data === 'function') ? data(this.$currentValue) : data;
|
|
220
|
+
const result = this.$interceptor(newValue, this.$currentValue);
|
|
221
|
+
|
|
222
|
+
if (result !== undefined) {
|
|
223
|
+
newValue = result;
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
this.$updateWithNewValue(newValue);
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
/**
|
|
231
|
+
* @param {*} data
|
|
232
|
+
*/
|
|
233
|
+
ObservableItem.prototype.$basicSet = function(data) {
|
|
234
|
+
const newValue = (typeof data === 'function') ? data(this.$currentValue) : data;
|
|
235
|
+
this.$updateWithNewValue(newValue);
|
|
236
|
+
};
|
|
237
|
+
|
|
238
|
+
ObservableItem.prototype.set = ObservableItem.prototype.$basicSet;
|
|
239
|
+
|
|
240
|
+
/**
|
|
241
|
+
* Returns the current value of the observable.
|
|
242
|
+
*
|
|
243
|
+
* @returns {*} The current value
|
|
244
|
+
* @example
|
|
245
|
+
* const count = Observable(42);
|
|
246
|
+
* count.val(); // 42
|
|
247
|
+
*/
|
|
248
|
+
ObservableItem.prototype.val = function() {
|
|
249
|
+
return this.$currentValue;
|
|
250
|
+
};
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* Disconnects all listeners and watchers and nullifies internal state.
|
|
254
|
+
* Does not trigger cleanup callbacks. Prefer .cleanup() for full disposal.
|
|
255
|
+
*
|
|
256
|
+
* @returns {void}
|
|
257
|
+
*/
|
|
258
|
+
ObservableItem.prototype.disconnectAll = function() {
|
|
259
|
+
this.$previousValue = null;
|
|
260
|
+
this.$currentValue = null;
|
|
261
|
+
this.$listeners = null;
|
|
262
|
+
this.$watchers = null;
|
|
263
|
+
this.trigger = noneTrigger;
|
|
264
|
+
};
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Registers a cleanup callback that will be executed when the observable is cleaned up.
|
|
268
|
+
* Useful for disposing resources, removing event listeners, or other cleanup tasks.
|
|
269
|
+
*
|
|
270
|
+
* @param {Function} callback - Cleanup function to execute on observable disposal
|
|
271
|
+
* @example
|
|
272
|
+
* const obs = Observable(0);
|
|
273
|
+
* obs.onCleanup(() => console.log('Cleaned up!'));
|
|
274
|
+
* obs.cleanup(); // Logs: "Cleaned up!"
|
|
275
|
+
*/
|
|
276
|
+
ObservableItem.prototype.onCleanup = function(callback) {
|
|
277
|
+
this.$cleanupListeners = this.$cleanupListeners ?? [];
|
|
278
|
+
this.$cleanupListeners.push(callback);
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
/**
|
|
282
|
+
* Disposes the observable: runs cleanup callbacks, unregisters from MemoryManager,
|
|
283
|
+
* disconnects all listeners and removes the $value property.
|
|
284
|
+
*
|
|
285
|
+
* @returns {void}
|
|
286
|
+
* @example
|
|
287
|
+
* const obs = Observable(0);
|
|
288
|
+
* obs.onCleanup(() => console.log('disposed'));
|
|
289
|
+
* obs.cleanup(); // logs 'disposed', frees memory
|
|
290
|
+
*/
|
|
291
|
+
ObservableItem.prototype.cleanup = function() {
|
|
292
|
+
if (this.$cleanupListeners) {
|
|
293
|
+
for (let i = 0; i < this.$cleanupListeners.length; i++) {
|
|
294
|
+
this.$cleanupListeners[i]();
|
|
295
|
+
}
|
|
296
|
+
this.$cleanupListeners = null;
|
|
297
|
+
}
|
|
298
|
+
MemoryManager.unregister(this.$memoryId);
|
|
299
|
+
this.disconnectAll();
|
|
300
|
+
if(process.env.NODE_ENV === 'development') {
|
|
301
|
+
this.$isCleanedUp = true;
|
|
302
|
+
}
|
|
303
|
+
delete this.$value;
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* Subscribes to value changes. The callback is called every time the value changes.
|
|
309
|
+
* Returns nothing — use .unsubscribe(callback) to remove the listener.
|
|
310
|
+
*
|
|
311
|
+
* @param {(current: *, previous: *, operations?: { action?: string }) => void} callback - Called on each value change
|
|
312
|
+
* @example
|
|
313
|
+
* const count = Observable(0);
|
|
314
|
+
* count.subscribe((val) => console.log('New value:', val));
|
|
315
|
+
* count.$value++; // logs 'New value: 1'
|
|
316
|
+
*/
|
|
317
|
+
ObservableItem.prototype.subscribe = function(callback) {
|
|
318
|
+
if(process.env.NODE_ENV === 'development') {
|
|
319
|
+
if (this.$isCleanedUp) {
|
|
320
|
+
DebugManager.warn('Observable subscription', '⚠️ Attempted to subscribe to a cleaned up observable.');
|
|
321
|
+
return;
|
|
322
|
+
}
|
|
323
|
+
if (typeof callback !== 'function') {
|
|
324
|
+
throw new NativeDocumentError('Callback must be a function');
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
this.$listeners = this.$listeners ?? [];
|
|
328
|
+
|
|
329
|
+
this.$listeners.push(callback);
|
|
330
|
+
this.assocTrigger();
|
|
331
|
+
if(process.env.NODE_ENV === 'development') {
|
|
332
|
+
PluginsManager.emit('ObservableSubscribe', this);
|
|
333
|
+
}
|
|
334
|
+
};
|
|
335
|
+
|
|
336
|
+
/**
|
|
337
|
+
* Watches for a specific value and executes callback when the observable equals that value.
|
|
338
|
+
* Creates a watcher that only triggers when the observable changes to the specified value.
|
|
339
|
+
*
|
|
340
|
+
* @param {*} value - The value to watch for
|
|
341
|
+
* @param {(value) => void|ObservableItem} callback - Callback function or observable to set when value matches
|
|
342
|
+
* @example
|
|
343
|
+
* const status = Observable('idle');
|
|
344
|
+
* status.on('loading', () => console.log('Started loading'));
|
|
345
|
+
* status.on('error', isError); // Set another observable
|
|
346
|
+
*/
|
|
347
|
+
ObservableItem.prototype.on = function(value, callback) {
|
|
348
|
+
this.$watchers = this.$watchers ?? new Map();
|
|
349
|
+
|
|
350
|
+
let watchValueList = this.$watchers.get(value);
|
|
351
|
+
|
|
352
|
+
if(callback.__$isObservable) {
|
|
353
|
+
callback = callback.set.bind(callback);
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
if(!watchValueList) {
|
|
357
|
+
watchValueList = callback;
|
|
358
|
+
this.$watchers.set(value, callback);
|
|
359
|
+
} else if(!Validator.isArray(watchValueList.list)) {
|
|
360
|
+
watchValueList = [watchValueList, callback];
|
|
361
|
+
callback = (value) => {
|
|
362
|
+
for(let i = 0, length = watchValueList.length; i < length; i++) {
|
|
363
|
+
watchValueList[i](value);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
callback.list = watchValueList;
|
|
367
|
+
this.$watchers.set(value, callback);
|
|
368
|
+
} else {
|
|
369
|
+
watchValueList.list.push(callback);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
this.assocTrigger();
|
|
373
|
+
};
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Removes a watcher for a specific value. If no callback is provided, removes all watchers for that value.
|
|
377
|
+
*
|
|
378
|
+
* @param {*} value - The value to stop watching
|
|
379
|
+
* @param {Function} [callback] - Specific callback to remove. If omitted, removes all watchers for this value
|
|
380
|
+
* @example
|
|
381
|
+
* const status = Observable('idle');
|
|
382
|
+
* const handler = () => console.log('Loading');
|
|
383
|
+
* status.on('loading', handler);
|
|
384
|
+
* status.off('loading', handler); // Remove specific handler
|
|
385
|
+
* status.off('loading'); // Remove all handlers for 'loading'
|
|
386
|
+
*/
|
|
387
|
+
ObservableItem.prototype.off = function(value, callback) {
|
|
388
|
+
if(!this.$watchers) return;
|
|
389
|
+
|
|
390
|
+
const watchValueList = this.$watchers.get(value);
|
|
391
|
+
if(!watchValueList) return;
|
|
392
|
+
|
|
393
|
+
if(!callback || !Array.isArray(watchValueList.list)) {
|
|
394
|
+
this.$watchers?.delete(value);
|
|
395
|
+
this.assocTrigger();
|
|
396
|
+
return;
|
|
397
|
+
}
|
|
398
|
+
const index = watchValueList.indexOf(callback);
|
|
399
|
+
watchValueList?.splice(index, 1);
|
|
400
|
+
if(watchValueList.length === 1) {
|
|
401
|
+
this.$watchers.set(value, watchValueList[0]);
|
|
402
|
+
}
|
|
403
|
+
else if(watchValueList.length === 0) {
|
|
404
|
+
this.$watchers?.delete(value);
|
|
405
|
+
}
|
|
406
|
+
this.assocTrigger();
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Subscribes to the observable but automatically unsubscribes after the first time the predicate matches.
|
|
411
|
+
*
|
|
412
|
+
* @param {(value) => Boolean|any} predicate - Value to match or function that returns true when condition is met
|
|
413
|
+
* @param {(value) => void} callback - Callback to execute when predicate matches, receives the matched value
|
|
414
|
+
* @example
|
|
415
|
+
* const status = Observable('loading');
|
|
416
|
+
* status.once('ready', (val) => console.log('Ready!'));
|
|
417
|
+
* status.once(val => val === 'error', (val) => console.log('Error occurred'));
|
|
418
|
+
*/
|
|
419
|
+
ObservableItem.prototype.once = function(predicate, callback) {
|
|
420
|
+
const fn = typeof predicate === 'function' ? predicate : (v) => v === predicate;
|
|
421
|
+
|
|
422
|
+
const handler = (val) => {
|
|
423
|
+
if (fn(val)) {
|
|
424
|
+
this.unsubscribe(handler);
|
|
425
|
+
callback(val);
|
|
426
|
+
}
|
|
427
|
+
};
|
|
428
|
+
this.subscribe(handler);
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
/**
|
|
433
|
+
* Removes a previously registered subscriber.
|
|
434
|
+
*
|
|
435
|
+
* @param {Function} callback - The exact function reference passed to .subscribe()
|
|
436
|
+
* @returns {void}
|
|
437
|
+
* @example
|
|
438
|
+
* const handler = (val) => console.log(val);
|
|
439
|
+
* count.subscribe(handler);
|
|
440
|
+
* count.unsubscribe(handler);
|
|
441
|
+
*/
|
|
442
|
+
ObservableItem.prototype.unsubscribe = function(callback) {
|
|
443
|
+
if(!this.$listeners) return;
|
|
444
|
+
const index = this.$listeners.indexOf(callback);
|
|
445
|
+
if (index > -1) {
|
|
446
|
+
this.$listeners.splice(index, 1);
|
|
447
|
+
}
|
|
448
|
+
this.assocTrigger();
|
|
449
|
+
if(process.env.NODE_ENV === 'development') {
|
|
450
|
+
PluginsManager.emit('ObservableUnsubscribe', this);
|
|
451
|
+
}
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
|
|
457
|
+
/**
|
|
458
|
+
* Gets a property value from the observable's current value.
|
|
459
|
+
* If the property is an observable, returns its value.
|
|
460
|
+
*
|
|
461
|
+
* @param {string|number} key - Property key to retrieve
|
|
462
|
+
* @returns {*} The value of the property, unwrapped if it's an observable
|
|
463
|
+
* @example
|
|
464
|
+
* const user = Observable({ name: 'John', age: Observable(25) });
|
|
465
|
+
* user.get('name'); // 'John'
|
|
466
|
+
* user.get('age'); // 25 (unwrapped from observable)
|
|
467
|
+
*/
|
|
468
|
+
ObservableItem.prototype.get = function(key) {
|
|
469
|
+
const item = this.$currentValue[key];
|
|
470
|
+
return Validator.isObservable(item) ? item.val() : item;
|
|
471
|
+
};
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
/**
|
|
475
|
+
* Compares the observable's current value with another value or observable.
|
|
476
|
+
*
|
|
477
|
+
* @param {*|ObservableItem} other - Value or observable to compare against
|
|
478
|
+
* @returns {boolean} True if values are equal
|
|
479
|
+
* @example
|
|
480
|
+
* const a = Observable(5);
|
|
481
|
+
* const b = Observable(5);
|
|
482
|
+
* a.equals(5); // true
|
|
483
|
+
* a.equals(b); // true
|
|
484
|
+
* a.equals(10); // false
|
|
485
|
+
*/
|
|
486
|
+
ObservableItem.prototype.equals = function(other) {
|
|
487
|
+
if(Validator.isObservable(other)) {
|
|
488
|
+
return this.$currentValue === other.$currentValue;
|
|
489
|
+
}
|
|
490
|
+
return this.$currentValue === other;
|
|
491
|
+
};
|
|
492
|
+
|
|
493
|
+
/**
|
|
494
|
+
* Converts the observable's current value to a boolean.
|
|
495
|
+
*
|
|
496
|
+
* @returns {boolean} The boolean representation of the current value
|
|
497
|
+
* @example
|
|
498
|
+
* const count = Observable(0);
|
|
499
|
+
* count.toBool(); // false
|
|
500
|
+
* count.set(5);
|
|
501
|
+
* count.toBool(); // true
|
|
502
|
+
*/
|
|
503
|
+
ObservableItem.prototype.toBool = function() {
|
|
504
|
+
return !!this.$currentValue;
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
/**
|
|
508
|
+
* Toggles the boolean value of the observable (false becomes true, true becomes false).
|
|
509
|
+
*
|
|
510
|
+
* @example
|
|
511
|
+
* const isOpen = Observable(false);
|
|
512
|
+
* isOpen.toggle(); // Now true
|
|
513
|
+
* isOpen.toggle(); // Now false
|
|
514
|
+
*/
|
|
515
|
+
ObservableItem.prototype.toggle = function() {
|
|
516
|
+
this.set(!this.$currentValue);
|
|
517
|
+
};
|
|
518
|
+
|
|
519
|
+
/**
|
|
520
|
+
* Resets the observable to its initial value.
|
|
521
|
+
* Only works if the observable was created with { reset: true } config.
|
|
522
|
+
*
|
|
523
|
+
* @example
|
|
524
|
+
* const count = Observable(0, { reset: true });
|
|
525
|
+
* count.set(10);
|
|
526
|
+
* count.reset(); // Back to 0
|
|
527
|
+
*/
|
|
528
|
+
ObservableItem.prototype.reset = function() {
|
|
529
|
+
if(!this.configs?.reset) {
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
const resetValue = (Validator.isObject(this.$initialValue))
|
|
533
|
+
? deepClone(this.$initialValue, (observable) => {
|
|
534
|
+
observable.reset();
|
|
535
|
+
})
|
|
536
|
+
: this.$initialValue;
|
|
537
|
+
this.set(resetValue);
|
|
538
|
+
};
|
|
539
|
+
|
|
540
|
+
/**
|
|
541
|
+
* Returns a string representation of the observable's current value.
|
|
542
|
+
*
|
|
543
|
+
* @returns {string} String representation of the current value
|
|
544
|
+
*/
|
|
545
|
+
ObservableItem.prototype.toString = function() {
|
|
546
|
+
return String(this.$currentValue);
|
|
547
|
+
};
|
|
548
|
+
|
|
549
|
+
/**
|
|
550
|
+
* Returns the primitive value of the observable (its current value).
|
|
551
|
+
* Called automatically in type coercion contexts.
|
|
552
|
+
*
|
|
553
|
+
* @returns {*} The current value of the observable
|
|
554
|
+
*/
|
|
555
|
+
ObservableItem.prototype.valueOf = function() {
|
|
556
|
+
return this.$currentValue;
|
|
557
|
+
};
|
|
558
|
+
|
|
559
|
+
/**
|
|
560
|
+
* Syncs this observable's value to localStorage and restores it on load.
|
|
561
|
+
* Optionally transforms values on get and set.
|
|
562
|
+
*
|
|
563
|
+
* @param {string} key - localStorage key
|
|
564
|
+
* @param {{ get?: (stored: any) => T, set?: (value: T) => any }} [options={}] - Transform options
|
|
565
|
+
* @param {Function} [options.get] - Transform the stored value before applying it
|
|
566
|
+
* @param {Function} [options.set] - Transform the value before saving it
|
|
567
|
+
* @returns {ObservableItem} this — chainable
|
|
568
|
+
* @example
|
|
569
|
+
* const theme = Observable('light').persist('app-theme');
|
|
570
|
+
* const count = Observable(0).persist('count', {
|
|
571
|
+
* get: (v) => parseInt(v),
|
|
572
|
+
* set: (v) => String(v),
|
|
573
|
+
* });
|
|
574
|
+
*/
|
|
575
|
+
ObservableItem.prototype.persist = function(key, options = {}) {
|
|
576
|
+
let value = $getFromStorage(key, this.$currentValue);
|
|
577
|
+
if(options.get) {
|
|
578
|
+
value = options.get(value);
|
|
579
|
+
}
|
|
580
|
+
this.set(value);
|
|
581
|
+
const saver = $saveToStorage(this.$currentValue);
|
|
582
|
+
this.subscribe((newValue) => {
|
|
583
|
+
saver(key, options.set ? options.set(newValue) : newValue);
|
|
584
|
+
});
|
|
585
|
+
return this;
|
|
586
|
+
};
|
|
587
|
+
|
|
588
|
+
/**
|
|
589
|
+
* Creates a new ObservableItem with a deep clone of the current value.
|
|
590
|
+
* For objects implementing a .clone() method, delegates to that method.
|
|
591
|
+
*
|
|
592
|
+
* @returns {ObservableItem} A new independent observable with the cloned value
|
|
593
|
+
* @example
|
|
594
|
+
* const original = Observable({ x: 1 });
|
|
595
|
+
* const copy = original.clone();
|
|
596
|
+
* copy.set({ x: 99 });
|
|
597
|
+
* original.val(); // { x: 1 } — untouched
|
|
598
|
+
*/
|
|
599
|
+
ObservableItem.prototype.clone = function() {
|
|
600
|
+
let clonedValue = this.$currentValue;
|
|
601
|
+
|
|
602
|
+
if(clonedValue && typeof clonedValue === 'object') {
|
|
603
|
+
if(typeof clonedValue.clone === 'function') {
|
|
604
|
+
clonedValue = clonedValue.clone();
|
|
605
|
+
} else {
|
|
606
|
+
clonedValue = structuredClone(clonedValue);
|
|
607
|
+
}
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
return new ObservableItem(clonedValue);
|
|
611
|
+
};
|