native-document 1.0.15 → 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 +8421 -1492
- 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 +181 -257
- 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 -502
- package/docs/contributing.md +300 -25
- package/docs/core-concepts.md +207 -366
- package/docs/elements.md +266 -254
- package/docs/extending-native-document-element.md +259 -0
- package/docs/filters.md +247 -0
- package/docs/getting-started.md +195 -257
- package/docs/i18n.md +241 -0
- package/docs/index.md +76 -0
- package/docs/lifecycle-events.md +146 -67
- package/docs/list-rendering.md +240 -460
- 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 -357
- 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 -91
- 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 -13
- package/package.json +59 -9
- package/readme.md +296 -93
- 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 +2 -3
- 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/{elements → core/elements}/control/for-each.js +42 -23
- 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 +4 -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 -55
- package/src/data/ObservableChecker.js +0 -39
- package/src/data/ObservableItem.js +0 -195
- package/src/data/Store.js +0 -74
- package/src/data/observable-helpers/array.js +0 -74
- package/src/data/observable-helpers/batch.js +0 -22
- package/src/data/observable-helpers/computed.js +0 -28
- package/src/data/observable-helpers/object.js +0 -111
- package/src/elements/anchor.js +0 -129
- package/src/elements/content-formatter.js +0 -32
- package/src/elements/control/for-each-array.js +0 -280
- 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 -10
- 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 -60
- package/src/utils/plugins-manager.js +0 -12
- package/src/utils/prototypes.js +0 -45
- package/src/wrappers/AttributesWrapper.js +0 -144
- package/src/wrappers/DocumentObserver.js +0 -80
- package/src/wrappers/ElementCreator.js +0 -114
- package/src/wrappers/HtmlElementEventsWrapper.js +0 -64
- package/src/wrappers/HtmlElementWrapper.js +0 -50
- package/src/wrappers/NdPrototype.js +0 -109
- package/src/wrappers/constants.js +0 -2
package/.npmrc.example
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//registry.npmjs.org/:_authToken=${NPM_TOKEN}
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
import { defineConfig } from 'vitepress'
|
|
2
|
+
|
|
3
|
+
export default defineConfig({
|
|
4
|
+
title: 'NativeDocument',
|
|
5
|
+
description: 'A reactive JavaScript framework that preserves native DOM simplicity without sacrificing modern features',
|
|
6
|
+
|
|
7
|
+
themeConfig: {
|
|
8
|
+
logo: '/logo.svg',
|
|
9
|
+
|
|
10
|
+
nav: [
|
|
11
|
+
{ text: 'Guide', link: '/getting-started' },
|
|
12
|
+
{ text: 'Components', link: '/components/' },
|
|
13
|
+
{ text: 'Utilities', link: '/utils/cache' },
|
|
14
|
+
{
|
|
15
|
+
text: 'v1.0.161',
|
|
16
|
+
items: [
|
|
17
|
+
{ text: 'Changelog', link: 'https://github.com/afrocodeur/native-document/releases' },
|
|
18
|
+
{ text: 'GitHub', link: 'https://github.com/afrocodeur/native-document' }
|
|
19
|
+
]
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
|
|
23
|
+
sidebar: {
|
|
24
|
+
'/components/': [
|
|
25
|
+
{
|
|
26
|
+
text: 'Components',
|
|
27
|
+
items: [
|
|
28
|
+
{ text: 'Overview', link: '/components/' },
|
|
29
|
+
{ text: 'Getting Started', link: '/components/getting-started' },
|
|
30
|
+
{ text: 'Traits', link: '/components/traits' },
|
|
31
|
+
]
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
text: 'Layout',
|
|
35
|
+
items: [
|
|
36
|
+
{ text: 'Layout', link: '/components/layout' },
|
|
37
|
+
{ text: 'Splitter', link: '/components/splitter' },
|
|
38
|
+
]
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
text: 'Display',
|
|
42
|
+
items: [
|
|
43
|
+
{ text: 'Alert & Feedback', link: '/components/alert' },
|
|
44
|
+
{ text: 'Avatar', link: '/components/avatar' },
|
|
45
|
+
{ text: 'Badge', link: '/components/alert' },
|
|
46
|
+
{ text: 'Breadcrumb', link: '/components/breadcrumb' },
|
|
47
|
+
{ text: 'Tooltip', link: '/components/tooltip' },
|
|
48
|
+
{ text: 'Toast', link: '/components/toast' },
|
|
49
|
+
]
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
text: 'Navigation',
|
|
53
|
+
items: [
|
|
54
|
+
{ text: 'Menu', link: '/components/menu' },
|
|
55
|
+
{ text: 'Tabs', link: '/components/tabs' },
|
|
56
|
+
{ text: 'Dropdown', link: '/components/dropdown' },
|
|
57
|
+
{ text: 'Context Menu', link: '/components/context-menu' },
|
|
58
|
+
{ text: 'Breadcrumb', link: '/components/breadcrumb' },
|
|
59
|
+
]
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
text: 'Overlay',
|
|
63
|
+
items: [
|
|
64
|
+
{ text: 'Modal & Popover', link: '/components/modal' },
|
|
65
|
+
]
|
|
66
|
+
},
|
|
67
|
+
{
|
|
68
|
+
text: 'Data',
|
|
69
|
+
items: [
|
|
70
|
+
{ text: 'Data Table', link: '/components/data-table' },
|
|
71
|
+
{ text: 'Accordion', link: '/components/accordion' },
|
|
72
|
+
]
|
|
73
|
+
},
|
|
74
|
+
{
|
|
75
|
+
text: 'Forms',
|
|
76
|
+
items: [
|
|
77
|
+
{ text: 'Button', link: '/components/button' },
|
|
78
|
+
{ text: 'Form Fields', link: '/components/form-fields' },
|
|
79
|
+
{ text: 'Checkbox & Radio', link: '/components/checkbox-radio' },
|
|
80
|
+
{ text: 'Select', link: '/components/select' },
|
|
81
|
+
{ text: 'File Upload', link: '/components/file' },
|
|
82
|
+
{ text: 'Slider & Stepper', link: '/components/slider-stepper' },
|
|
83
|
+
{ text: 'Switch', link: '/components/switch' },
|
|
84
|
+
]
|
|
85
|
+
}
|
|
86
|
+
],
|
|
87
|
+
|
|
88
|
+
'/utils/': [
|
|
89
|
+
{
|
|
90
|
+
text: 'Utilities',
|
|
91
|
+
items: [
|
|
92
|
+
{ text: 'Cache', link: '/utils/cache' },
|
|
93
|
+
{ text: 'NativeFetch', link: '/utils/native-fetch' },
|
|
94
|
+
{ text: 'Filters', link: '/utils/filters' },
|
|
95
|
+
]
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
|
|
99
|
+
'/': [
|
|
100
|
+
{
|
|
101
|
+
text: 'Introduction',
|
|
102
|
+
items: [
|
|
103
|
+
{ text: 'Getting Started', link: '/getting-started' },
|
|
104
|
+
{ text: 'CLI', link: '/cli' },
|
|
105
|
+
{ text: 'Core Concepts', link: '/core-concepts' },
|
|
106
|
+
]
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
text: 'Essentials',
|
|
110
|
+
items: [
|
|
111
|
+
{ text: 'Observables', link: '/observables' },
|
|
112
|
+
{ text: 'Observable Resource', link: '/observable-resource' },
|
|
113
|
+
{ text: 'Elements', link: '/elements' },
|
|
114
|
+
{ text: 'Conditional Rendering', link: '/conditional-rendering' },
|
|
115
|
+
{ text: 'List Rendering', link: '/list-rendering' },
|
|
116
|
+
{ text: 'Anchor', link: '/anchor' },
|
|
117
|
+
]
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
text: 'Application',
|
|
121
|
+
items: [
|
|
122
|
+
{ text: 'Routing', link: '/routing' },
|
|
123
|
+
{ text: 'State Management', link: '/state-management' },
|
|
124
|
+
{ text: 'i18n & Formatting', link: '/i18n' },
|
|
125
|
+
{ text: 'SVG Elements', link: '/svg-elements' },
|
|
126
|
+
]
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
text: 'NDElement',
|
|
130
|
+
items: [
|
|
131
|
+
{ text: 'NDElement', link: '/native-document-element' },
|
|
132
|
+
{ text: 'Extending NDElement', link: '/extending-native-document-element' },
|
|
133
|
+
{ text: 'Lifecycle Events', link: '/lifecycle-events' },
|
|
134
|
+
{ text: 'Advanced Components', link: '/advanced-components' },
|
|
135
|
+
]
|
|
136
|
+
},
|
|
137
|
+
{
|
|
138
|
+
text: 'Advanced',
|
|
139
|
+
items: [
|
|
140
|
+
{ text: 'Args Validation', link: '/validation' },
|
|
141
|
+
{ text: 'Memory Management', link: '/memory-management' },
|
|
142
|
+
]
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
text: 'Contributing',
|
|
146
|
+
items: [
|
|
147
|
+
{ text: 'Contributing', link: '/contributing' },
|
|
148
|
+
]
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
socialLinks: [
|
|
154
|
+
{ icon: 'github', link: 'https://github.com/afrocodeur/native-document' }
|
|
155
|
+
],
|
|
156
|
+
|
|
157
|
+
footer: {
|
|
158
|
+
message: 'Released under the MIT License.',
|
|
159
|
+
copyright: 'Copyright © 2024 AfroCodeur'
|
|
160
|
+
},
|
|
161
|
+
|
|
162
|
+
search: {
|
|
163
|
+
provider: 'local'
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
})
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to NativeDocument will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
## [Unreleased]
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `Card` - versatile content container with image, header, footer, actions, clickable and loading states (renderer implementation in progress)
|
|
15
|
+
- `List` - flexible list with single/multi selection, checkbox or click-to-select modes, dividers and keyboard navigation (renderer implementation in progress)
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## [1.0.166] - 2026-06-03
|
|
20
|
+
|
|
21
|
+
### Added
|
|
22
|
+
|
|
23
|
+
#### Core
|
|
24
|
+
- `Observable.resource()` - async data fetching with built-in state machine (`unresolved`, `pending`, `ready`, `refreshing`, `errored`), `AbortController` support, reactive dependencies, debounce, and optimistic `mutate()`
|
|
25
|
+
- `Observable.batch()` - batch multiple state changes into a single computed update, with async support
|
|
26
|
+
- `Observable.useValueProperty(name?)` - define a custom property alias for `$value`
|
|
27
|
+
- `Observable.autoCleanup(enable, options?)` - automatic periodic cleanup of orphaned observables via `WeakRef` and `FinalizationRegistry`
|
|
28
|
+
- `Observable.getById(id)` - retrieve a registered observable by its internal memory ID
|
|
29
|
+
- `observable.intercept(callback)` - transform or abort values before they are set
|
|
30
|
+
- `observable.interceptMutations(callback)` - intercept array and object mutations separately
|
|
31
|
+
- `observable.onCleanup(callback)` - register a callback that runs when the observable is cleaned up
|
|
32
|
+
- `observable.once(predicate, callback)` - single-fire listener triggered by value or condition
|
|
33
|
+
- `observable.deepSubscribe(callback)` - react to changes at any nesting depth
|
|
34
|
+
- `observable.persist(key, options?)` - two-way synchronization with `localStorage`
|
|
35
|
+
- `observable.clone()` - deep clone of the observable's current value
|
|
36
|
+
- `observable.resolve()` - recursively extract plain values from observables and proxies
|
|
37
|
+
- `observable.trigger()` - force notification without changing the value
|
|
38
|
+
- `observable.reset()` - reset to the initial value (requires `{ reset: true }` option)
|
|
39
|
+
- `Observable.computed()` - derived observable that recalculates when dependencies change
|
|
40
|
+
- `Observable.object()` / `Observable.json()` / `Observable.init()` - per-property reactive proxy
|
|
41
|
+
- `Observable.array()` - reactive array with mutating methods (`push`, `pop`, `splice`, `swap`, `merge`, `at`, `count`, `removeItem`, `insertAfter`)
|
|
42
|
+
- `ObservableArray.where()` / `whereSome()` / `whereEvery()` - live reactive filtering
|
|
43
|
+
- `observable.format(type, options?)` - locale-aware value formatting (`currency`, `number`, `percent`, `date`, `time`, `datetime`, `relative`, `plural`, custom)
|
|
44
|
+
- `Observable.setLocale(locale)` - set the reactive locale for all `.format()` calls
|
|
45
|
+
- `Formatters` - extensible formatter registry for custom format types
|
|
46
|
+
- Convenience checkers: `isTruthy()`, `isFalsy()`, `isEmpty()`, `isNotEmpty()`, `isEqualTo()`, `isGreaterThan()`, `isBetween()`, `isStartingWith()`, `isIncludedIn()`, `isHaving()`, and more
|
|
47
|
+
- Convenience transformers: `toUpperCase()`, `toLower()`, `toTrimmed()`, `toLength()`, `toClamped()`, `toPercent()`, `toLiteral()`, `toProperty()`
|
|
48
|
+
|
|
49
|
+
#### NDElement
|
|
50
|
+
- `.nd` proxy on every HTML element - fluent API for events, lifecycle, DOM utilities
|
|
51
|
+
- Auto-generated event methods for all standard DOM events in 4 variants: `onClick`, `onPreventClick`, `onStopClick`, `onPreventStopClick`
|
|
52
|
+
- `.on(name, callback, options)` - generic event with `AbortController` auto-cleanup on unmount
|
|
53
|
+
- `.off(name, callback)` - remove a specific listener
|
|
54
|
+
- `.once(name, callback)` - one-time listener
|
|
55
|
+
- `.emit(name, detail?)` - dispatch a custom event
|
|
56
|
+
- `.attr(name, value)` / `.attrs(attrs)` - reactive attribute binding
|
|
57
|
+
- `.class(map)` / `.style(map)` - reactive class and style binding
|
|
58
|
+
- `.ref(target, name)` - store the native `HTMLElement` reference
|
|
59
|
+
- `.refSelf(target, name)` - store the `NDElement` instance reference
|
|
60
|
+
- `.with(methods)` - add methods to a single element instance (component encapsulation pattern)
|
|
61
|
+
- `NDElement.extend(methods)` - add methods to all NDElement instances globally
|
|
62
|
+
- `.ghostDom(element)` - inject a companion element alongside the returned element
|
|
63
|
+
- `.attach(methodName, hydrator)` - template binding for `useCache` / `useSingleton`
|
|
64
|
+
- `.mounted(callback)` / `.unmounted(callback)` / `.lifecycle({ mounted, unmounted })` - DOM lifecycle hooks
|
|
65
|
+
- `.beforeUnmount(id, asyncCallback)` - async callback before element removal (exit animations)
|
|
66
|
+
- `.destroyOnUnmount()` - automatically call `destroy()` on unmount
|
|
67
|
+
- `.destroy()` - abort internal `AbortController`, clear lifecycle observers
|
|
68
|
+
- `.transition(name)` / `.transitionIn(name)` / `.transitionOut(name)` / `.animate(name)` - CSS transition helpers
|
|
69
|
+
- `.openShadow(css?)` / `.closedShadow(css?)` - Shadow DOM encapsulation
|
|
70
|
+
- `.unmountChildren()` - unmount all child elements
|
|
71
|
+
|
|
72
|
+
#### Elements
|
|
73
|
+
- Wrapper functions for all standard HTML elements (`Div`, `Button`, `Input`, `Form`, `Table`, etc.)
|
|
74
|
+
- `Fragment` - one-time static content grouping via `DocumentFragment`
|
|
75
|
+
- `Anchor` / `NativeDocumentFragment` - dynamic DOM zone delimited by comment markers
|
|
76
|
+
- `ShowIf` / `HideIf` / `HideIfNot` - conditional rendering with optional caching
|
|
77
|
+
- `ShowWhen` - show when an observable matches a specific value
|
|
78
|
+
- `Switch` - binary content toggle
|
|
79
|
+
- `Match` - multi-state rendering with `.nd.add()` / `.nd.remove()` for dynamic states
|
|
80
|
+
- `When` - fluent builder for conditional rendering
|
|
81
|
+
- `ForEach` - keyed list rendering for arrays and objects, with index observable
|
|
82
|
+
- `ForEachArray` - high-performance array rendering with `TemplateCloner`
|
|
83
|
+
- `useCache($binder)` - template cloning with data binding (value, class, style, attr, attach)
|
|
84
|
+
- `useSingleton(view)` - singleton view with named updatable sections
|
|
85
|
+
- Full SVG element set (`SvgSvg`, `SvgCircle`, `SvgRect`, `SvgPath`, etc.) with reactive attributes
|
|
86
|
+
- `classPropertyAccumulator` / `cssPropertyAccumulator` - programmatic class and style builders
|
|
87
|
+
|
|
88
|
+
#### Router
|
|
89
|
+
- `Router.create({ name, mode }, callback)` - multi-mode router (history, hash, memory)
|
|
90
|
+
- Route parameters with validation via `RouteParamPatterns` (built-in: `id`, `uuid`, `slug`, `locale`, `token`, and more)
|
|
91
|
+
- Named routes, route groups with shared middleware and layout, catch-all `{*}`
|
|
92
|
+
- `Router.push()` / `Router.replace()` / `Router.redirectTo()` / `Router.back()` / `Router.forward()`
|
|
93
|
+
- `Link` component with named route resolution and active state
|
|
94
|
+
- Middleware system with `context` and `next()`
|
|
95
|
+
- Multiple named routers with `Router.get(name)` / `Router.routers`
|
|
96
|
+
|
|
97
|
+
#### Store
|
|
98
|
+
- `Store.create()` / `createResettable()` / `createPersistent()` / `createPersistentResettable()` / `createComposed()`
|
|
99
|
+
- `Store.group(name, fn)` - isolated namespace with full Store API
|
|
100
|
+
- `Store.use(name)` - two-way reactive follower
|
|
101
|
+
- `Store.follow(name)` - read-only reactive follower (throws on mutation)
|
|
102
|
+
- `Store.get(name)` - raw observable access
|
|
103
|
+
- `Store.has(name)` / `Store.delete(name)` / `Store.reset(name)`
|
|
104
|
+
|
|
105
|
+
#### Utilities
|
|
106
|
+
- `NativeFetch` - HTTP client with request/response interceptors, automatic JSON, query string, FormData support
|
|
107
|
+
- `Cache.once(fn)` / `Cache.singleton(fn)` / `Cache.memoize(fn)` - lazy init, eager singleton, key-based memoization
|
|
108
|
+
- Filter helpers: `equals`, `greaterThan`, `between`, `includes`, `startsWith`, `match`, `inArray`, `and`, `or`, `not`, `custom`, `dateEquals`, `dateBetween`, `timeBetween`, `dateTimeBetween`, and more
|
|
109
|
+
- `ArgTypes` + `.args()` + `withValidation()` - runtime argument validation (development only)
|
|
110
|
+
- `PluginsManager` - internal event bus for DevTools integration
|
|
111
|
+
- `MemoryManager` - `WeakRef`-based observable registry with `FinalizationRegistry` auto-cleanup
|
|
112
|
+
- `ShortcutManager` - global and context-scoped keyboard shortcuts with OS-aware display
|
|
113
|
+
- `I18nService` - locale management backed by `i18next`, with `tr()` translation helper and `npm run i18n:scan`
|
|
114
|
+
|
|
115
|
+
#### Components (50+)
|
|
116
|
+
- **Layout**: `HStack`, `VStack`, `Row`, `Col`, `AbsoluteStack`, `FixedStack`, `RelativeStack`, `Divider`, `Spacer`, `Splitter` + `SplitterPanel`
|
|
117
|
+
- **Navigation**: `BreadCrumb`, `Menu` + `MenuItem` + `MenuGroup` + `MenuLink` + `MenuDivider`, `Tabs`, `Pagination`, `Stepper` + `StepperStep`
|
|
118
|
+
- **Overlay**: `Modal`, `Popover`, `Dropdown` + `DropdownItem` + `DropdownGroup` + `DropdownTrigger`, `Tooltip`, `ContextMenu`
|
|
119
|
+
- **Feedback**: `Alert`, `Badge`, `Progress`, `Skeleton`, `Spinner`, `Toast`
|
|
120
|
+
- **Data**: `DataTable` + `Column` + `ColumnGroup`, `SimpleTable`, `Accordion` + `AccordionItem`, `List`
|
|
121
|
+
- **Interaction**: `Button`, `Switch`, `Slider`
|
|
122
|
+
- **Media**: `Avatar`, `AvatarGroup`, `Card`
|
|
123
|
+
- **Forms**: `FormControl`, `FieldCollection`, `StringField`, `EmailField`, `PasswordField`, `TelField`, `UrlField`, `HiddenField`, `NumberField`, `RangeField`, `TextAreaField`, `CheckboxField`, `CheckboxGroupField`, `RadioField`, `SelectField`, `AutocompleteField`, `DateField`, `TimeField`, `ColorField`, `SliderField`, `ImageField`, `FileField` (with `FileNativeMode`, `FileDropzoneMode`, `FileUploadButtonMode`, `FileWallMode`, `FileAvatarMode`)
|
|
124
|
+
- **Traits**: `HasEventEmitter`, `HasDraggable`, `HasResizable`, `HasItems`, `HasPosition`, `HasFullPosition`, `HasValidation`
|
|
125
|
+
|
|
126
|
+
#### CLI (`@native-document/cli`)
|
|
127
|
+
- `nd create <name>` - scaffold a complete project with Vite, routing, i18n, and store pre-configured
|
|
128
|
+
- `nd create <name> --feature` - feature-based architecture
|
|
129
|
+
- `nd create:page` / `create:component` / `create:service` / `create:feature` - generators
|
|
130
|
+
- `npm run i18n:scan` - scan source for missing translation keys
|
|
131
|
+
|
|
132
|
+
#### Build
|
|
133
|
+
- Rollup 4 multi-output: CDN IIFE (dev + minified), ESM for bundlers, DevTools bundle
|
|
134
|
+
- `process.env.NODE_ENV` replacement for tree-shaking all debug code in production
|
|
135
|
+
- TypeScript `.d.ts` definitions for all public APIs
|
|
136
|
+
|
|
137
|
+
---
|
|
138
|
+
|
|
139
|
+
## How to Read This File
|
|
140
|
+
|
|
141
|
+
Entries use the following categories:
|
|
142
|
+
|
|
143
|
+
- **Added** - new features
|
|
144
|
+
- **Changed** - changes to existing functionality
|
|
145
|
+
- **Deprecated** - features that will be removed in a future release
|
|
146
|
+
- **Removed** - features removed in this release
|
|
147
|
+
- **Fixed** - bug fixes
|
|
148
|
+
- **Security** - vulnerability fixes
|
|
149
|
+
|
|
150
|
+
---
|
|
151
|
+
|
|
152
|
+
[Unreleased]: https://github.com/afrocodeur/native-document/compare/v1.0.166...HEAD
|
|
153
|
+
[1.0.166]: https://github.com/afrocodeur/native-document/releases/tag/v1.0.166
|
package/cdn.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { default as HtmlElementWrapper, createTextNode } from './src/core/wrappers/HtmlElementWrapper'
|
|
2
|
+
export { ElementCreator } from './src/core/wrappers/ElementCreator';
|
|
3
|
+
export { NDElement } from './src/core/wrappers/NDElement';
|
|
4
|
+
export { TemplateCloner, useCache } from './src/core/wrappers/template-cloner/TemplateCloner';
|
|
5
|
+
export { SingletonView, useSingleton } from './src/core/wrappers/SingletonView';
|
|
6
|
+
export { default as PluginsManager } from './src/core/utils/plugins-manager';
|
|
7
|
+
export { default as Validator } from './src/core/utils/validator';
|
|
8
|
+
|
|
9
|
+
export * from './src/core/utils/property-accumulator';
|
|
10
|
+
export * from './src/core/utils/args-types';
|
|
11
|
+
export * from './src/core/utils/memoize';
|
|
12
|
+
export * from './src/core/data/Observable';
|
|
13
|
+
export * from './src/core/data/Store';
|
|
14
|
+
|
|
15
|
+
import * as elements from './elements';
|
|
16
|
+
import * as router from './router';
|
|
17
|
+
import * as utils from './utils';
|
|
18
|
+
|
|
19
|
+
export { elements, router, utils };
|
package/components.d.ts
ADDED
package/components.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export * from './src/components/accordion/index';
|
|
2
|
+
export * from './src/components/alert/index';
|
|
3
|
+
export * from './src/components/avatar/index';
|
|
4
|
+
export * from './src/components/badge/index';
|
|
5
|
+
export * from './src/components/breadcrumb/index';
|
|
6
|
+
export * from './src/components/button/index';
|
|
7
|
+
export * from './src/components/card/index';
|
|
8
|
+
export * from './src/components/context-menu/index';
|
|
9
|
+
export * from './src/components/divider/index';
|
|
10
|
+
export * from './src/components/dropdown/index';
|
|
11
|
+
export * from './src/components/form/index';
|
|
12
|
+
export * from './src/components/list/index';
|
|
13
|
+
export * from './src/components/menu/index';
|
|
14
|
+
export * from './src/components/modal/index';
|
|
15
|
+
export * from './src/components/pagination/index';
|
|
16
|
+
export * from './src/components/popover/index';
|
|
17
|
+
export * from './src/components/progress/index';
|
|
18
|
+
export * from './src/components/skeleton/index';
|
|
19
|
+
export * from './src/components/slider/index';
|
|
20
|
+
export * from './src/components/spinner/index';
|
|
21
|
+
export * from './src/components/splitter/index';
|
|
22
|
+
export * from './src/components/stepper/index';
|
|
23
|
+
export * from './src/components/switch/index';
|
|
24
|
+
export * from './src/components/table/index';
|
|
25
|
+
|
|
26
|
+
export * from './src/components/tabs/index';
|
|
27
|
+
export * from './src/components/toast/index';
|
|
28
|
+
export * from './src/components/tooltip/index';
|
|
29
|
+
export * from './src/components/stacks/index';
|
|
30
|
+
export * from './src/components/spacer/index';
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import {Anchor} from "../elements";
|
|
2
|
+
import Validator from "../src/core/utils/validator";
|
|
3
|
+
import DebugManager from "../src/core/utils/debug-manager";
|
|
4
|
+
|
|
5
|
+
const ComponentRegistry = (function() {
|
|
6
|
+
const registry = new Map();
|
|
7
|
+
|
|
8
|
+
const attachLocalExtensions = (instance, factoryInstance) => {
|
|
9
|
+
if(!factoryInstance.$localExtensions) {
|
|
10
|
+
return;
|
|
11
|
+
}
|
|
12
|
+
const extensions = Object.fromEntries(factoryInstance.$localExtensions);
|
|
13
|
+
for(const name in extensions) {
|
|
14
|
+
instance.anchor[name] = function() {
|
|
15
|
+
const result = extensions[name](...arguments);
|
|
16
|
+
if(result === null || result === undefined) {
|
|
17
|
+
return instance.anchor;
|
|
18
|
+
}
|
|
19
|
+
if(Validator.isFragment(result) || Validator.isElement(result) || Validator.isNDElement(result)) {
|
|
20
|
+
instance.anchor.setContent(result);
|
|
21
|
+
return instance.anchor;
|
|
22
|
+
}
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
instance.anchor.$localExtensions = factoryInstance.$localExtensions;
|
|
27
|
+
instance.extensions = Object.keys(extensions);
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const wrapper = function(id, factory, metadata, registryItem) {
|
|
31
|
+
const factoryName = factory.name;
|
|
32
|
+
|
|
33
|
+
return function(...args) {
|
|
34
|
+
const firstParam = args[0];
|
|
35
|
+
if(firstParam?.__instance) {
|
|
36
|
+
const instance = firstParam.__instance;
|
|
37
|
+
const newFactoryInstance = factory(...instance.context.args, instance);
|
|
38
|
+
|
|
39
|
+
if(instance.extensions) {
|
|
40
|
+
instance.extensions.forEach((extensionName) => {
|
|
41
|
+
instance.anchor[extensionName] = undefined;
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
attachLocalExtensions(instance, newFactoryInstance);
|
|
45
|
+
instance.anchor.setContent(newFactoryInstance);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
const anchor = Anchor(factoryName);
|
|
49
|
+
const instance = {
|
|
50
|
+
anchor,
|
|
51
|
+
extensions: null,
|
|
52
|
+
context: {
|
|
53
|
+
args,
|
|
54
|
+
states: new Map()
|
|
55
|
+
}
|
|
56
|
+
};
|
|
57
|
+
const factoryInstance = factory(...args, instance);
|
|
58
|
+
anchor.setContent(factoryInstance);
|
|
59
|
+
registryItem.instances.add(instance);
|
|
60
|
+
|
|
61
|
+
attachLocalExtensions(instance, factoryInstance);
|
|
62
|
+
return anchor;
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return {
|
|
67
|
+
/**
|
|
68
|
+
* @param {string} id
|
|
69
|
+
* @param {Function} factory
|
|
70
|
+
* @param {Object} metadata
|
|
71
|
+
*/
|
|
72
|
+
register(id, factory, metadata = {}) {
|
|
73
|
+
if (!registry.has(id)) {
|
|
74
|
+
registry.set(id, {
|
|
75
|
+
factory,
|
|
76
|
+
instances: new Set(),
|
|
77
|
+
metadata,
|
|
78
|
+
states: {},
|
|
79
|
+
version: 0
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
return wrapper(id, factory, metadata, registry.get(id));
|
|
83
|
+
},
|
|
84
|
+
update(id, newFactory) {
|
|
85
|
+
const component = registry.get(id);
|
|
86
|
+
if(!component) {
|
|
87
|
+
DebugManager.warn(`[HMR] Component ${id} not found`);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
DebugManager.log(`[HMR] Updating ${component.instances.size} instance(s) of ${id}`);
|
|
91
|
+
const oldFactory = component.factory;
|
|
92
|
+
component.factory = newFactory;
|
|
93
|
+
component.version++;
|
|
94
|
+
const instances = Array.from(component.instances);
|
|
95
|
+
for (const instance of instances) {
|
|
96
|
+
try {
|
|
97
|
+
this.updateInstance(instance, newFactory);
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error('[HMR] Update failed:', error);
|
|
100
|
+
// Rollback
|
|
101
|
+
component.factory = oldFactory;
|
|
102
|
+
component.version--;
|
|
103
|
+
throw error;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
updateInstance(instance, newFactory) {
|
|
108
|
+
return newFactory({ __instance: instance });
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
}());
|
|
112
|
+
|
|
113
|
+
export default ComponentRegistry;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import {Observable} from "../../src/core/data/Observable";
|
|
2
|
+
|
|
3
|
+
export const DevToolService = {
|
|
4
|
+
createdObservable: Observable(0),
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
export const DevToolsPlugin = {
|
|
9
|
+
$name: 'DevTools',
|
|
10
|
+
name: 'DevTools',
|
|
11
|
+
onCreateObservable(observable) {
|
|
12
|
+
DevToolService.createdObservable.set((last) => ++last);
|
|
13
|
+
// console.log('Création Capturé', observable.$value);
|
|
14
|
+
}
|
|
15
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import transformComponentForHrm from "./src/transformComponentForHrm.js";
|
|
2
|
+
import {isFileMustBeModified} from "./src/utils.js";
|
|
3
|
+
import transformJsFile from "./src/transformJsFile.js";
|
|
4
|
+
|
|
5
|
+
export default function NdViteDevtools(options) {
|
|
6
|
+
const {
|
|
7
|
+
include = /\.nd\.js$/,
|
|
8
|
+
preserveState = true
|
|
9
|
+
} = options;
|
|
10
|
+
|
|
11
|
+
return {
|
|
12
|
+
name: 'nd-devtools',
|
|
13
|
+
apply: 'serve',
|
|
14
|
+
enforce: 'post',
|
|
15
|
+
|
|
16
|
+
handleHotUpdate({ file, server, modules }) {
|
|
17
|
+
if (!include.test(file)) {
|
|
18
|
+
if(isFileMustBeModified(file)) {
|
|
19
|
+
return modules.filter(Boolean);
|
|
20
|
+
}
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
// Notify the browser about the change
|
|
25
|
+
server.ws.send({
|
|
26
|
+
type: 'nd-hmr-file',
|
|
27
|
+
event: 'nd:update',
|
|
28
|
+
data: { file, msg: 'The content has changed' }
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
// We will manage all manually
|
|
32
|
+
return modules.filter(Boolean);
|
|
33
|
+
},
|
|
34
|
+
transform(code, id) {
|
|
35
|
+
if (!include.test(id)) {
|
|
36
|
+
if(isFileMustBeModified(id)) {
|
|
37
|
+
return transformJsFile(id, code, { preserveState });
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
if (id.includes('node_modules')) return null;
|
|
42
|
+
|
|
43
|
+
try {
|
|
44
|
+
return transformComponentForHrm(id, code, { preserveState });
|
|
45
|
+
} catch (error) {
|
|
46
|
+
console.error(`[NativeDocument] Transform error in ${id}:`, error);
|
|
47
|
+
return null;
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
|
|
51
|
+
configResolved() {
|
|
52
|
+
console.log('[NativeDocument] HMR Plugin loaded ✓');
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import MagicString from 'magic-string';
|
|
4
|
+
|
|
5
|
+
import { fileURLToPath } from 'node:url';
|
|
6
|
+
import { parse } from '@babel/parser';
|
|
7
|
+
import { default as traverse } from '@babel/traverse';
|
|
8
|
+
|
|
9
|
+
import { transformObservableImports, transformObservableDeclarations, template } from './utils.js';
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
13
|
+
const __dirname = path.dirname(__filename);
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export default function transformComponentForHrm(id, code, options) {
|
|
17
|
+
let hasDefaultExport = false;
|
|
18
|
+
let componentName = null;
|
|
19
|
+
let exportStart = 0;
|
|
20
|
+
let exportEnd = 0;
|
|
21
|
+
// TODO: move this line outside the function
|
|
22
|
+
const hrmHookTemplate = fs.readFileSync(__dirname + '/../templates/hrm.hook.template.js', 'utf8');
|
|
23
|
+
const formattedCode = transformObservableDeclarations(
|
|
24
|
+
transformObservableImports(code, { id, ...options }),
|
|
25
|
+
);
|
|
26
|
+
const s = new MagicString(formattedCode);
|
|
27
|
+
const codeParsed = parse(formattedCode, {
|
|
28
|
+
sourceType: 'module',
|
|
29
|
+
plugins: []
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
traverse.default(codeParsed, {
|
|
33
|
+
ExportDefaultDeclaration(path) {
|
|
34
|
+
hasDefaultExport = true;
|
|
35
|
+
const declaration = path.node.declaration;
|
|
36
|
+
|
|
37
|
+
if (declaration.id) {
|
|
38
|
+
componentName = declaration.id.name;
|
|
39
|
+
} else if (declaration.type === 'Identifier') {
|
|
40
|
+
componentName = declaration.name;
|
|
41
|
+
} else {
|
|
42
|
+
componentName = 'AnonymousComponent';
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
exportStart = path.node.start;
|
|
46
|
+
exportEnd = path.node.end;
|
|
47
|
+
},
|
|
48
|
+
});
|
|
49
|
+
if (!hasDefaultExport) {
|
|
50
|
+
return null;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
const originalExport = formattedCode.slice(exportStart, exportEnd);
|
|
54
|
+
const hrmComponentName = `__HRM_${componentName}__`;
|
|
55
|
+
const newExport = originalExport.replace(
|
|
56
|
+
'export default',
|
|
57
|
+
`const ${hrmComponentName} =`
|
|
58
|
+
);
|
|
59
|
+
s.overwrite(exportStart, exportEnd, newExport);
|
|
60
|
+
|
|
61
|
+
const hrmHookTemplateFormatted = template(hrmHookTemplate, {
|
|
62
|
+
id
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
s.prepend('import ComponentRegistry from "native-document/devtools/ComponentRegistry";');
|
|
66
|
+
s.append(`export default ComponentRegistry.register('${id}', ${hrmComponentName}, { preserveState: ${options.preserveState} });`);
|
|
67
|
+
s.append(hrmHookTemplateFormatted);
|
|
68
|
+
|
|
69
|
+
return {
|
|
70
|
+
code: s.toString(),
|
|
71
|
+
map: s.generateMap({ source: id, hires: true })
|
|
72
|
+
};
|
|
73
|
+
}
|