native-document 1.0.165 → 1.0.168
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/.vitepress/config.js +166 -0
- package/CHANGELOG.md +153 -0
- package/components.d.ts +2 -0
- package/components.js +2 -1
- package/devtools/widget.js +1 -1
- package/dist/native-document.components.min.js +11589 -2983
- package/dist/native-document.dev.js +2280 -396
- package/dist/native-document.dev.js.map +1 -1
- package/dist/native-document.min.js +1 -1
- package/docs/advanced-components.md +213 -608
- package/docs/anchor.md +173 -312
- package/docs/cache.md +95 -803
- 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 +170 -588
- package/docs/contributing.md +300 -25
- package/docs/core-concepts.md +205 -374
- package/docs/elements.md +251 -367
- package/docs/extending-native-document-element.md +192 -207
- package/docs/filters.md +153 -1122
- package/docs/getting-started.md +193 -267
- package/docs/i18n.md +241 -0
- package/docs/index.md +76 -0
- package/docs/lifecycle-events.md +143 -75
- package/docs/list-rendering.md +227 -852
- package/docs/memory-management.md +134 -47
- package/docs/native-document-element.md +337 -186
- package/docs/native-fetch.md +99 -630
- package/docs/observable-resource.md +364 -0
- package/docs/observables.md +592 -526
- package/docs/routing.md +244 -653
- package/docs/state-management.md +134 -241
- package/docs/svg-elements.md +231 -0
- package/docs/theming.md +409 -0
- package/docs/validation.md +95 -97
- package/docs/vitepress-conventions.md +219 -0
- package/eslint.config.js +28 -33
- package/i18n.js +1 -1
- package/i18n.ts +2 -0
- package/index.js +3 -0
- package/package.json +36 -14
- package/readme.md +269 -89
- 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 +204 -32
- package/src/components/card/index.js +4 -4
- 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/HasListItem.js +171 -0
- package/src/components/list/List.js +85 -67
- package/src/components/list/ListDivider.js +39 -0
- package/src/components/list/ListGroup.js +105 -38
- package/src/components/list/ListItem.js +158 -49
- package/src/components/list/index.js +8 -6
- 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 +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 +12 -3
- 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 +118 -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 +35 -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/card/CardRender.js +133 -0
- package/src/ui/components/card/card.css +169 -0
- package/src/ui/components/contextmenu/ContextmenuRender.js +6 -6
- 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/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 +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/spacer/SpacerRender.js +10 -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 +44 -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/SkeletonList.js +0 -0
- package/src/components/skeleton/SkeletonParagraph.js +0 -0
- package/src/components/skeleton/SkeletonTable.js +0 -0
- /package/{src/components/skeleton/SkeletonCard.js → docs/tutorials/.gitkeep} +0 -0
package/docs/anchor.md
CHANGED
|
@@ -1,438 +1,299 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: Anchor
|
|
3
|
+
description: Anchors enable dynamic DOM manipulation without wrapper elements using invisible comment node boundaries
|
|
4
|
+
---
|
|
5
|
+
|
|
1
6
|
# Anchor
|
|
2
7
|
|
|
3
8
|
Anchors enable dynamic DOM manipulation without wrapper elements. They use two invisible comment nodes as boundaries, allowing you to insert, remove, and replace content between them while keeping your DOM clean.
|
|
4
9
|
|
|
5
|
-
|
|
10
|
+
All conditional rendering and list rendering utilities in NativeDocument (`ShowIf`, `ForEach`, `Match`, etc.) are built on top of `Anchor`.
|
|
6
11
|
|
|
7
|
-
|
|
8
|
-
> **Important:** Anchors must be appended to a parent element to function. The comment markers only exist once the anchor is in the DOM.
|
|
12
|
+
## What is an Anchor?
|
|
9
13
|
|
|
10
|
-
|
|
14
|
+
An `Anchor` creates two invisible comment nodes as markers in the DOM:
|
|
11
15
|
|
|
12
16
|
```javascript
|
|
13
|
-
|
|
14
|
-
const anchor = Anchor("My Content");
|
|
15
|
-
// Or using the alias
|
|
16
|
-
const anchor = NativeDocumentFragment("My Content");
|
|
17
|
-
|
|
18
|
-
// In the DOM, this creates:
|
|
19
|
-
// <!-- Anchor Start : My Content -->
|
|
20
|
-
// <!-- / Anchor End My Content -->
|
|
21
|
-
|
|
22
|
-
// Content can be inserted between these markers
|
|
23
|
-
anchor.appendChild(Div("Dynamic content"));
|
|
24
|
-
// <!-- Anchor Start : My Content -->
|
|
25
|
-
// <div>Dynamic content</div>
|
|
26
|
-
// <!-- / Anchor End My Content -->
|
|
27
|
-
```
|
|
17
|
+
import { Anchor } from 'native-document/elements';
|
|
28
18
|
|
|
29
|
-
|
|
19
|
+
const anchor = Anchor('My Section');
|
|
30
20
|
|
|
31
|
-
|
|
21
|
+
// Once in the DOM, creates:
|
|
22
|
+
// <!-- Anchor Start : My Section -->
|
|
23
|
+
// <!-- / Anchor End My Section -->
|
|
32
24
|
|
|
33
|
-
|
|
34
|
-
//
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
Div("Standard fragment content"),
|
|
38
|
-
Div("Standard fragment content 2"),
|
|
39
|
-
]); // Returns document.createDocumentFragment() with children
|
|
25
|
+
anchor.appendChild(Div('Dynamic content'));
|
|
26
|
+
// <!-- Anchor Start : My Section -->
|
|
27
|
+
// <div>Dynamic content</div>
|
|
28
|
+
// <!-- / Anchor End My Section -->
|
|
40
29
|
```
|
|
41
30
|
|
|
42
|
-
|
|
31
|
+
> `NativeDocumentFragment` is a valid alias for `Anchor` - both create the same system.
|
|
43
32
|
|
|
44
|
-
|
|
45
|
-
// Anchor is a NativeDocument class
|
|
46
|
-
const anchor = Anchor("Dynamic Area");
|
|
47
|
-
anchor.appendChild(Div("Dynamic content")); // Uses comment markers system
|
|
48
|
-
```
|
|
33
|
+
> Anchors must be appended to a parent element before their methods work. The comment markers only exist once the anchor is in the DOM.
|
|
49
34
|
|
|
50
|
-
|
|
35
|
+
---
|
|
51
36
|
|
|
52
|
-
|
|
37
|
+
## Fragment vs Anchor
|
|
53
38
|
|
|
54
|
-
|
|
55
|
-
```javascript
|
|
56
|
-
const wrapper = Div({ class: 'wrapper' }); // Extra DOM node
|
|
39
|
+
**`Fragment`** wraps `document.createDocumentFragment()` - for one-time static content grouping:
|
|
57
40
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
41
|
+
```javascript
|
|
42
|
+
const fragment = Fragment(
|
|
43
|
+
H1('Static Title'),
|
|
44
|
+
P('Static content')
|
|
45
|
+
);
|
|
46
|
+
// Replaced entirely when appended to parent
|
|
62
47
|
```
|
|
63
48
|
|
|
64
|
-
|
|
65
|
-
```javascript
|
|
66
|
-
const anchor = Anchor("Content");
|
|
49
|
+
**`Anchor`** is for dynamic content that updates over time:
|
|
67
50
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
51
|
+
```javascript
|
|
52
|
+
const anchor = Anchor('Dynamic Area');
|
|
53
|
+
anchor.appendChild(Div('Initial content'));
|
|
54
|
+
anchor.replaceContent(Div('Updated content')); // markers stay, content swaps
|
|
72
55
|
```
|
|
73
56
|
|
|
74
|
-
|
|
75
|
-
- ✅ No extra DOM nodes
|
|
76
|
-
- ✅ Cleaner HTML structure
|
|
77
|
-
- ✅ Better semantic markup
|
|
78
|
-
- ✅ Easier CSS targeting (no wrapper interference)
|
|
57
|
+
---
|
|
79
58
|
|
|
80
|
-
##
|
|
59
|
+
## Why Use Anchors?
|
|
81
60
|
|
|
82
|
-
|
|
61
|
+
Without an anchor you need a wrapper element:
|
|
83
62
|
|
|
84
63
|
```javascript
|
|
85
|
-
//
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
// Anchor needs to be added to parent container
|
|
90
|
-
const container = Div();
|
|
91
|
-
container.appendChild(contentAnchor);
|
|
64
|
+
// Extra div in the DOM
|
|
65
|
+
const wrapper = Div({ class: 'wrapper' });
|
|
66
|
+
wrapper.appendChild(Div('Content'));
|
|
92
67
|
```
|
|
93
68
|
|
|
94
|
-
|
|
69
|
+
With an anchor, no wrapper is needed:
|
|
95
70
|
|
|
96
71
|
```javascript
|
|
97
|
-
const anchor = Anchor(
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
// Add content between the markers
|
|
102
|
-
anchor.appendChild(Div("Dynamic content 1"));
|
|
103
|
-
anchor.appendChild(Div("Dynamic content 2"));
|
|
104
|
-
|
|
105
|
-
// DOM structure:
|
|
106
|
-
// <div>
|
|
107
|
-
// <!-- Anchor Start : Dynamic Section -->
|
|
108
|
-
// <div>Dynamic content 1</div>
|
|
109
|
-
// <div>Dynamic content 2</div>
|
|
110
|
-
// <!-- / Anchor End Dynamic Section -->
|
|
111
|
-
// </div>
|
|
72
|
+
const anchor = Anchor('Content');
|
|
73
|
+
anchor.appendChild(Div('Content'));
|
|
74
|
+
// DOM: just the div between two comment nodes
|
|
112
75
|
```
|
|
113
76
|
|
|
114
|
-
|
|
115
|
-
```javascript
|
|
116
|
-
const anchor = Anchor("Multi Insert");
|
|
117
|
-
|
|
118
|
-
// Append multiple elements at once
|
|
119
|
-
anchor.appendChild([
|
|
120
|
-
Div("Element 1"),
|
|
121
|
-
Div("Element 2"),
|
|
122
|
-
Div("Element 3")
|
|
123
|
-
]);
|
|
124
|
-
|
|
125
|
-
// More efficient than multiple calls:
|
|
126
|
-
// anchor.appendChild(Div("Element 1"));
|
|
127
|
-
// anchor.appendChild(Div("Element 2"));
|
|
128
|
-
// anchor.appendChild(Div("Element 3"));
|
|
129
|
-
```
|
|
77
|
+
Benefits: no extra DOM nodes, cleaner HTML, no CSS interference from wrapper elements.
|
|
130
78
|
|
|
131
|
-
|
|
79
|
+
---
|
|
132
80
|
|
|
133
|
-
|
|
134
|
-
const anchor = Anchor("Ordered Content");
|
|
135
|
-
const element1 = Div("First");
|
|
136
|
-
const element2 = Div("Second");
|
|
81
|
+
## API Reference
|
|
137
82
|
|
|
138
|
-
|
|
139
|
-
anchor.insertBefore(element2, element1); // Inserts before element1
|
|
140
|
-
// Result: element2, element1
|
|
141
|
-
```
|
|
83
|
+
### `appendChild(child)` / `append(child)`
|
|
142
84
|
|
|
143
|
-
|
|
85
|
+
Inserts content before the end marker. Accepts an element, array, or any valid child:
|
|
144
86
|
|
|
145
87
|
```javascript
|
|
146
|
-
|
|
147
|
-
anchor.appendChild(
|
|
148
|
-
|
|
149
|
-
// Replace all content between markers with new content
|
|
150
|
-
anchor.replaceContent(Div("New content"));
|
|
88
|
+
anchor.appendChild(Div('Content'));
|
|
89
|
+
anchor.appendChild([H1('Title'), P('Body'), Button('Action')]);
|
|
90
|
+
anchor.append(Div('Same as appendChild'));
|
|
151
91
|
```
|
|
152
92
|
|
|
153
|
-
|
|
93
|
+
### `insertAtStart(child)`
|
|
154
94
|
|
|
155
|
-
|
|
95
|
+
Inserts content inside the anchor, immediately after the start marker - the opposite of `appendChild` which inserts before the end marker:
|
|
156
96
|
|
|
157
97
|
```javascript
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
//
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
// Alias for remove() - clears content but keeps anchor
|
|
165
|
-
anchor.clear();
|
|
98
|
+
anchor.insertAtStart(Div('Just before the anchor start'));
|
|
99
|
+
// DOM:
|
|
100
|
+
// <!-- Anchor Start : My Section -->
|
|
101
|
+
// <div>Just before the anchor start</div> <- inserted here
|
|
102
|
+
// ... anchor content ...
|
|
103
|
+
// <!-- / Anchor End My Section -->
|
|
166
104
|
```
|
|
167
105
|
|
|
168
|
-
###
|
|
169
|
-
|
|
106
|
+
### `replaceContent(child)` / `setContent(child)`
|
|
107
|
+
|
|
108
|
+
Removes all current content and inserts new content in one operation:
|
|
170
109
|
|
|
171
110
|
```javascript
|
|
172
|
-
|
|
173
|
-
anchor.
|
|
111
|
+
anchor.replaceContent(Div('New content'));
|
|
112
|
+
anchor.setContent(Div('Same as replaceContent'));
|
|
174
113
|
```
|
|
175
114
|
|
|
176
|
-
|
|
115
|
+
Prefer `replaceContent()` over `remove()` + `appendChild()` - it's a single DOM operation.
|
|
177
116
|
|
|
178
|
-
###
|
|
117
|
+
### `removeChildren()`
|
|
179
118
|
|
|
180
|
-
|
|
181
|
-
const anchor = Anchor("My Anchor");
|
|
182
|
-
|
|
183
|
-
// Get the start and end comment nodes
|
|
184
|
-
const start = anchor.startElement();
|
|
185
|
-
const end = anchor.endElement();
|
|
119
|
+
Removes all content between the markers. The markers stay in place and the anchor can be reused. Children are **destroyed**:
|
|
186
120
|
|
|
187
|
-
|
|
188
|
-
|
|
121
|
+
```javascript
|
|
122
|
+
anchor.removeChildren(); // content gone, markers remain
|
|
123
|
+
anchor.appendChild(Div('Fresh content')); // reuse the anchor
|
|
189
124
|
```
|
|
190
125
|
|
|
191
|
-
|
|
126
|
+
### `remove()`
|
|
192
127
|
|
|
193
|
-
|
|
128
|
+
Moves all content out of the DOM back into the internal fragment - content is **preserved** but detached. The markers stay in place:
|
|
194
129
|
|
|
195
130
|
```javascript
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
container.appendChild(anchor);
|
|
199
|
-
|
|
200
|
-
// Insert multiple elements without a containing wrapper
|
|
201
|
-
anchor.appendChild([
|
|
202
|
-
H1("Title"),
|
|
203
|
-
P("Paragraph"),
|
|
204
|
-
Button("Action")
|
|
205
|
-
]);
|
|
206
|
-
|
|
207
|
-
// DOM: No wrapper element, just the three elements between markers
|
|
131
|
+
anchor.remove(); // content detached but kept internally
|
|
132
|
+
anchor.appendChild(previousContent); // can be re-attached
|
|
208
133
|
```
|
|
209
134
|
|
|
210
|
-
|
|
135
|
+
> **Difference:** `removeChildren()` destroys children. `remove()` moves them back into the fragment, preserving them for potential re-use.
|
|
211
136
|
|
|
212
|
-
|
|
213
|
-
const contentAnchor = Anchor("Dynamic Updates");
|
|
214
|
-
const isLoading = Observable(true);
|
|
215
|
-
const data = Observable(null);
|
|
137
|
+
### `removeWithAnchors()` / `delete()`
|
|
216
138
|
|
|
217
|
-
|
|
218
|
-
contentAnchor.appendChild(Div("Loading..."));
|
|
139
|
+
Destroys the content **and** removes the comment markers from the DOM. The anchor becomes unusable:
|
|
219
140
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
contentAnchor.replaceContent(Div("Loading..."));
|
|
224
|
-
} else if (data.val()) {
|
|
225
|
-
contentAnchor.replaceContent(
|
|
226
|
-
Div(`Data: ${data.val()}`)
|
|
227
|
-
);
|
|
228
|
-
}
|
|
229
|
-
});
|
|
141
|
+
```javascript
|
|
142
|
+
anchor.removeWithAnchors(); // or anchor.delete()
|
|
143
|
+
// anchor is now permanently gone
|
|
230
144
|
```
|
|
231
145
|
|
|
232
|
-
|
|
146
|
+
### `getParent()`
|
|
233
147
|
|
|
234
|
-
|
|
148
|
+
Returns the current parent node:
|
|
235
149
|
|
|
236
150
|
```javascript
|
|
237
|
-
const
|
|
238
|
-
|
|
239
|
-
// ShowIf returns an anchor, not a wrapper element
|
|
240
|
-
const content = ShowIf(isVisible, () =>
|
|
241
|
-
Div("This content appears/disappears dynamically")
|
|
242
|
-
);
|
|
243
|
-
|
|
244
|
-
// No wrapper div created - content inserted directly between markers
|
|
245
|
-
isVisible.set(true); // Content appears between comment nodes
|
|
246
|
-
isVisible.set(false); // Content disappears, markers remain for reuse
|
|
151
|
+
const parent = anchor.getParent();
|
|
247
152
|
```
|
|
248
153
|
|
|
249
|
-
###
|
|
250
|
-
|
|
251
|
-
```javascript
|
|
252
|
-
const items = Observable.array(["Item 1", "Item 2"]);
|
|
253
|
-
|
|
254
|
-
// ForEach returns an anchor managing multiple elements
|
|
255
|
-
const list = ForEach(items, (item) =>
|
|
256
|
-
Div(item)
|
|
257
|
-
);
|
|
154
|
+
### `startElement()` / `endElement()`
|
|
258
155
|
|
|
259
|
-
|
|
260
|
-
items.push("Item 3"); // New div inserted at anchor position
|
|
261
|
-
items.splice(0, 1); // First div removed, others shift within markers
|
|
262
|
-
```
|
|
263
|
-
|
|
264
|
-
### Match/Switch Components
|
|
156
|
+
Returns the start or end comment node:
|
|
265
157
|
|
|
266
158
|
```javascript
|
|
267
|
-
const
|
|
268
|
-
|
|
269
|
-
// Match returns an anchor managing different content states
|
|
270
|
-
const content = Match(currentView, {
|
|
271
|
-
loading: () => Div("Loading..."),
|
|
272
|
-
success: () => Div("Data loaded!"),
|
|
273
|
-
error: () => Div("Error occurred")
|
|
274
|
-
});
|
|
159
|
+
const start = anchor.startElement();
|
|
160
|
+
const end = anchor.endElement();
|
|
275
161
|
|
|
276
|
-
|
|
162
|
+
console.log(start.textContent); // "Anchor Start : My Section"
|
|
163
|
+
console.log(end.textContent); // "/ Anchor End My Section"
|
|
277
164
|
```
|
|
278
165
|
|
|
279
|
-
|
|
166
|
+
---
|
|
280
167
|
|
|
281
|
-
|
|
282
|
-
- **One-time content creation** that won't change
|
|
283
|
-
- **Standard DOM operations** following web standards
|
|
284
|
-
- **Static content grouping** before insertion
|
|
168
|
+
## Method Aliases
|
|
285
169
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
);
|
|
292
|
-
// Gets replaced entirely when appended to parent
|
|
293
|
-
```
|
|
170
|
+
| Primary | Aliases |
|
|
171
|
+
|---|---|
|
|
172
|
+
| `appendChild(child)` | `append(child)` |
|
|
173
|
+
| `replaceContent(child)` | `setContent(child)` |
|
|
174
|
+
| `removeWithAnchors()` | `delete()` |
|
|
294
175
|
|
|
295
|
-
|
|
296
|
-
- **Dynamic content management** that updates frequently
|
|
297
|
-
- **Conditional rendering** systems
|
|
298
|
-
- **List management** with add/remove operations
|
|
299
|
-
- **Custom rendering patterns**
|
|
176
|
+
---
|
|
300
177
|
|
|
301
|
-
|
|
302
|
-
// Dynamic content area that can be updated multiple times
|
|
303
|
-
const anchor = Anchor("Updates");
|
|
304
|
-
anchor.appendChild(Div("Initial content"));
|
|
305
|
-
anchor.remove(); // Clear content
|
|
306
|
-
anchor.appendChild(Div("New content")); // Add different content - markers remain
|
|
307
|
-
```
|
|
178
|
+
## Practical Examples
|
|
308
179
|
|
|
309
|
-
|
|
180
|
+
### Dynamic content updates
|
|
310
181
|
|
|
311
|
-
### Memory Management
|
|
312
182
|
```javascript
|
|
313
|
-
|
|
314
|
-
const
|
|
183
|
+
const anchor = Anchor('Status');
|
|
184
|
+
const isLoading = Observable(true);
|
|
185
|
+
const data = Observable(null);
|
|
315
186
|
|
|
316
|
-
|
|
317
|
-
anchor.removeWithAnchors(); // Fully destroys anchor and frees memory
|
|
318
|
-
```
|
|
187
|
+
anchor.appendChild(Div('Loading...'));
|
|
319
188
|
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
189
|
+
isLoading.subscribe(loading => {
|
|
190
|
+
if (loading) {
|
|
191
|
+
anchor.replaceContent(Div('Loading...'));
|
|
192
|
+
} else {
|
|
193
|
+
anchor.replaceContent(
|
|
194
|
+
data.val()
|
|
195
|
+
? Div(['Data: ', data.select(d => d.name)])
|
|
196
|
+
: Div('No data')
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
});
|
|
331
200
|
```
|
|
332
201
|
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
### Creating Custom Anchor-Based Components
|
|
202
|
+
### Custom anchor-based component
|
|
336
203
|
|
|
337
204
|
```javascript
|
|
338
|
-
|
|
339
205
|
function ConditionalList(condition, items) {
|
|
340
|
-
const anchor = Anchor(
|
|
341
|
-
|
|
342
|
-
const
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
anchor.replaceContent(Ul(listItems));
|
|
206
|
+
const anchor = Anchor('ConditionalList');
|
|
207
|
+
|
|
208
|
+
const update = () => {
|
|
209
|
+
if (condition.val() && items.val().length) {
|
|
210
|
+
anchor.replaceContent(
|
|
211
|
+
Ul(items.val().map(item => Li(item)))
|
|
212
|
+
);
|
|
348
213
|
} else {
|
|
349
|
-
anchor.
|
|
214
|
+
anchor.removeChildren();
|
|
350
215
|
}
|
|
351
216
|
};
|
|
352
217
|
|
|
353
|
-
condition.subscribe(
|
|
354
|
-
items.subscribe(
|
|
355
|
-
|
|
218
|
+
condition.subscribe(update);
|
|
219
|
+
items.subscribe(update);
|
|
220
|
+
update();
|
|
356
221
|
|
|
357
222
|
return anchor;
|
|
358
223
|
}
|
|
359
224
|
|
|
360
|
-
// Usage example
|
|
361
225
|
const condition = Observable(true);
|
|
226
|
+
const items = Observable.array([]);
|
|
362
227
|
let id = 0;
|
|
363
|
-
const items = Observable.array([]);
|
|
364
228
|
|
|
365
229
|
document.body.appendChild(Div([
|
|
366
230
|
ConditionalList(condition, items),
|
|
367
|
-
Button(
|
|
368
|
-
Button(
|
|
231
|
+
Button('Toggle').nd.onClick(() => condition.toggle()),
|
|
232
|
+
Button('Add').nd.onClick(() => items.push('Item ' + (++id)))
|
|
369
233
|
]));
|
|
370
234
|
```
|
|
371
235
|
|
|
372
|
-
###
|
|
236
|
+
### Layout manager
|
|
373
237
|
|
|
374
238
|
```javascript
|
|
375
239
|
function LayoutManager() {
|
|
376
|
-
const header
|
|
377
|
-
const content = Anchor(
|
|
378
|
-
const footer
|
|
379
|
-
|
|
240
|
+
const header = Anchor('Header');
|
|
241
|
+
const content = Anchor('Content');
|
|
242
|
+
const footer = Anchor('Footer');
|
|
243
|
+
|
|
380
244
|
return {
|
|
381
|
-
setHeader:
|
|
382
|
-
setContent:
|
|
383
|
-
setFooter:
|
|
384
|
-
render:
|
|
245
|
+
setHeader: component => header.replaceContent(component),
|
|
246
|
+
setContent: component => content.replaceContent(component),
|
|
247
|
+
setFooter: component => footer.replaceContent(component),
|
|
248
|
+
render: () => Div([header, content, footer])
|
|
385
249
|
};
|
|
386
250
|
}
|
|
387
251
|
```
|
|
388
252
|
|
|
389
|
-
|
|
253
|
+
---
|
|
390
254
|
|
|
391
|
-
|
|
392
|
-
2. **Anchors are reusable** - Content can be added/removed multiple times
|
|
393
|
-
3. **Use `removeWithAnchors()` only when permanently destroying** the anchor
|
|
394
|
-
4. **Anchors are invisible** - They don't affect layout or styling
|
|
395
|
-
5. **Prefer `replaceContent()` over `remove()` + `appendChild()`** for better performance
|
|
396
|
-
6. **Create custom patterns** - Anchors enable custom rendering solutions
|
|
397
|
-
7. **Consider memory implications** when creating many anchors
|
|
398
|
-
8. **Use batch operations** for multiple content updates
|
|
255
|
+
## How Conditional Rendering Uses Anchors
|
|
399
256
|
|
|
400
|
-
|
|
257
|
+
Every conditional and list rendering utility returns an anchor:
|
|
401
258
|
|
|
402
|
-
❌ **Don't do this:**
|
|
403
259
|
```javascript
|
|
404
|
-
//
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
anchor
|
|
260
|
+
// ShowIf returns an anchor
|
|
261
|
+
const content = ShowIf(isVisible, () => Div('Hello'));
|
|
262
|
+
isVisible.toggle(); // anchor replaces content between its markers
|
|
263
|
+
|
|
264
|
+
// ForEach returns an anchor
|
|
265
|
+
const list = ForEach(items, item => Div(item));
|
|
266
|
+
items.push('New'); // anchor inserts new div before end marker
|
|
267
|
+
|
|
268
|
+
// Match returns an anchor
|
|
269
|
+
const view = Match(status, {
|
|
270
|
+
loading: Div('Loading...'),
|
|
271
|
+
success: Div('Done!')
|
|
272
|
+
});
|
|
273
|
+
status.set('success'); // anchor swaps content
|
|
409
274
|
```
|
|
410
275
|
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
276
|
+
---
|
|
277
|
+
|
|
278
|
+
## Best Practices
|
|
279
|
+
|
|
280
|
+
1. Use descriptive names - they appear in DOM comments and help debugging
|
|
281
|
+
2. Prefer `replaceContent()` over `remove()` + `appendChild()` - it's one DOM operation
|
|
282
|
+
3. Use `removeChildren()` when you want to clear and reuse the anchor
|
|
283
|
+
4. Use `removeWithAnchors()` / `delete()` only when permanently destroying the anchor
|
|
284
|
+
5. Anchors must be in the DOM before their methods work - always append to a parent first
|
|
285
|
+
|
|
286
|
+
---
|
|
417
287
|
|
|
418
288
|
## Next Steps
|
|
419
289
|
|
|
420
|
-
- **[
|
|
421
|
-
- **[
|
|
422
|
-
- **[
|
|
423
|
-
- **[
|
|
424
|
-
- **[Conditional Rendering](conditional-rendering.md)** - Dynamic content
|
|
425
|
-
- **[List Rendering](list-rendering.md)** - (ForEach | ForEachArray) and dynamic lists
|
|
426
|
-
- **[Routing](routing.md)** - Navigation and URL management
|
|
427
|
-
- **[State Management](state-management.md)** - Global state patterns
|
|
428
|
-
- **[NDElement](native-document-element.md)** - Native Document Element
|
|
429
|
-
- **[Extending NDElement](extending-native-document-element.md)** - Custom Methods Guide
|
|
430
|
-
- **[Advanced Components](advanced-components.md)** - Template caching and singleton views
|
|
431
|
-
- **[Args Validation](validation.md)** - Function Argument Validation
|
|
432
|
-
- **[Memory Management](memory-management.md)** - Memory management
|
|
290
|
+
- **[Conditional Rendering](./conditional-rendering.md)** - ShowIf, Match, Switch built on Anchor
|
|
291
|
+
- **[List Rendering](./list-rendering.md)** - ForEach and ForEachArray built on Anchor
|
|
292
|
+
- **[Elements](./elements.md)** - Creating and composing UI
|
|
293
|
+
- **[Memory Management](./memory-management.md)** - Cleanup and memory management
|
|
433
294
|
|
|
434
295
|
## Utilities
|
|
435
296
|
|
|
436
|
-
- **[Cache](
|
|
437
|
-
- **[NativeFetch](
|
|
438
|
-
- **[Filters](
|
|
297
|
+
- **[Cache](./cache.md)** - Lazy initialization and singleton patterns
|
|
298
|
+
- **[NativeFetch](./native-fetch.md)** - HTTP client with interceptors
|
|
299
|
+
- **[Filters](./filters.md)** - Data filtering helpers
|