@kubex/zinc 0.0.2 → 1.0.0
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/.editorconfig +18 -0
- package/.eslintignore +8 -0
- package/.eslintrc.cjs +208 -0
- package/.github/workflows/eleventy_build.yml +42 -0
- package/.github/workflows/js_build_and_deploy.yaml +62 -0
- package/custom-elements-manifest.config.js +230 -0
- package/custom-elements.json +24227 -0
- package/docs/_includes/component.njk +340 -0
- package/docs/_includes/default.njk +137 -0
- package/docs/_includes/sidebar.njk +24 -0
- package/docs/_utilities/active-links.cjs +41 -0
- package/docs/_utilities/anchor-headings.cjs +74 -0
- package/docs/_utilities/cem.cjs +89 -0
- package/docs/_utilities/code-previews.cjs +98 -0
- package/docs/_utilities/copy-code-buttons.cjs +26 -0
- package/docs/_utilities/external-links.cjs +53 -0
- package/docs/_utilities/highlight-code.cjs +74 -0
- package/docs/_utilities/markdown.cjs +74 -0
- package/docs/_utilities/prettier.cjs +26 -0
- package/docs/_utilities/replacer.cjs +24 -0
- package/docs/_utilities/scrolling-tables.cjs +23 -0
- package/docs/_utilities/strings.cjs +16 -0
- package/docs/_utilities/table-of-contents.cjs +48 -0
- package/docs/_utilities/typography.cjs +24 -0
- package/docs/assets/icons.json +57989 -0
- package/docs/assets/images/chrome.png +0 -0
- package/docs/assets/images/edge.png +0 -0
- package/docs/assets/images/firefox.png +0 -0
- package/docs/assets/images/opera.png +0 -0
- package/docs/assets/images/safari.png +0 -0
- package/docs/assets/images/watermark.svg +1 -0
- package/docs/assets/rip.js +78 -0
- package/docs/assets/scripts/code-previews.js +250 -0
- package/docs/assets/scripts/docs.js +374 -0
- package/docs/assets/scripts/search.js +441 -0
- package/docs/assets/scripts/turbo.js +29 -0
- package/docs/assets/styles/code-previews.css +169 -0
- package/docs/assets/styles/docs.css +1168 -0
- package/docs/assets/styles/search.css +347 -0
- package/docs/eleventy.config.cjs +262 -0
- package/docs/pages/components/absolute-container.md +35 -0
- package/docs/pages/components/action-bar.md +58 -0
- package/docs/pages/components/alert.md +45 -0
- package/docs/pages/components/bulk-actions.md +26 -0
- package/docs/pages/components/button-group.md +78 -0
- package/docs/pages/components/button-menu.md +127 -0
- package/docs/pages/components/button.md +80 -0
- package/docs/pages/components/chart.md +27 -0
- package/docs/pages/components/checkbox-group.md +196 -0
- package/docs/pages/components/checkbox.md +157 -0
- package/docs/pages/components/chip.md +61 -0
- package/docs/pages/components/collapsible.md +52 -0
- package/docs/pages/components/cols.md +66 -0
- package/docs/pages/components/confirm.md +52 -0
- package/docs/pages/components/content-block.md +108 -0
- package/docs/pages/components/copy-button.md +22 -0
- package/docs/pages/components/data-select.md +54 -0
- package/docs/pages/components/data-table-filter.md +23 -0
- package/docs/pages/components/data-table-sort.md +20 -0
- package/docs/pages/components/data-table.md +74 -0
- package/docs/pages/components/datepicker.md +25 -0
- package/docs/pages/components/defined-label.md +26 -0
- package/docs/pages/components/dialog.md +145 -0
- package/docs/pages/components/dropdown.md +22 -0
- package/docs/pages/components/editor.md +26 -0
- package/docs/pages/components/empty-state.md +51 -0
- package/docs/pages/components/expanding-action.md +55 -0
- package/docs/pages/components/file.md +45 -0
- package/docs/pages/components/form-group.md +22 -0
- package/docs/pages/components/header.md +103 -0
- package/docs/pages/components/icon.md +322 -0
- package/docs/pages/components/inline-edit.md +41 -0
- package/docs/pages/components/input.md +261 -0
- package/docs/pages/components/item.md +78 -0
- package/docs/pages/components/linked-select.md +41 -0
- package/docs/pages/components/menu-item.md +22 -0
- package/docs/pages/components/menu.md +36 -0
- package/docs/pages/components/navbar.md +57 -0
- package/docs/pages/components/note.md +55 -0
- package/docs/pages/components/option.md +22 -0
- package/docs/pages/components/order-table.md +22 -0
- package/docs/pages/components/page-nav.md +23 -0
- package/docs/pages/components/pagination.md +22 -0
- package/docs/pages/components/pane.md +22 -0
- package/docs/pages/components/panel.md +124 -0
- package/docs/pages/components/popup.md +22 -0
- package/docs/pages/components/progress-bar.md +22 -0
- package/docs/pages/components/progress-tile.md +22 -0
- package/docs/pages/components/query-builder.md +148 -0
- package/docs/pages/components/radio-group.md +129 -0
- package/docs/pages/components/radio.md +20 -0
- package/docs/pages/components/rating.md +28 -0
- package/docs/pages/components/scroll-container.md +22 -0
- package/docs/pages/components/select.md +452 -0
- package/docs/pages/components/sidebar.md +28 -0
- package/docs/pages/components/simple-chart.md +23 -0
- package/docs/pages/components/skeleton.md +70 -0
- package/docs/pages/components/slideout.md +23 -0
- package/docs/pages/components/sp.md +87 -0
- package/docs/pages/components/split-button.md +32 -0
- package/docs/pages/components/split-pane.md +22 -0
- package/docs/pages/components/stat.md +24 -0
- package/docs/pages/components/status-indicator.md +13 -0
- package/docs/pages/components/stepper.md +20 -0
- package/docs/pages/components/style.md +106 -0
- package/docs/pages/components/table.md +22 -0
- package/docs/pages/components/tabs.md +57 -0
- package/docs/pages/components/textarea.md +120 -0
- package/docs/pages/components/tile-property.md +29 -0
- package/docs/pages/components/tile.md +51 -0
- package/docs/pages/components/timer.md +22 -0
- package/docs/pages/components/toggle.md +22 -0
- package/docs/pages/components/tooltip.md +242 -0
- package/docs/pages/components/vertical-stepper.md +22 -0
- package/docs/pages/components/well.md +13 -0
- package/docs/pages/getting-started/example-layout.md +143 -0
- package/docs/pages/getting-started/example-page.md +83 -0
- package/docs/pages/getting-started/form-controls.md +552 -0
- package/docs/pages/getting-started/form-examples.md +122 -0
- package/docs/pages/getting-started/table-examples.md +43 -0
- package/docs/pages/index.md +32 -0
- package/index.html +22 -0
- package/package.json +111 -11
- package/scripts/build.js +381 -0
- package/scripts/generator/generator.js +102 -0
- package/scripts/generator/index.js +17 -0
- package/scripts/generator/preprocess.js +20 -0
- package/scripts/generator/resolver.js +86 -0
- package/scripts/generator/tailwind.config.js +14 -0
- package/scripts/make-metadata.js +10 -0
- package/scripts/make-themes.js +27 -0
- package/scripts/plop/plopfile.js +63 -0
- package/scripts/plop/templates/component.hbs +43 -0
- package/scripts/plop/templates/define.hbs +12 -0
- package/scripts/plop/templates/docs.hbs +20 -0
- package/scripts/plop/templates/style.hbs +5 -0
- package/scripts/plop/templates/test.hbs +10 -0
- package/scss/_global-components.scss +4 -0
- package/scss/_global-spacing.scss +96 -0
- package/scss/_root.scss +202 -0
- package/scss/boot.scss +29 -0
- package/scss/mixins/_helper-mixins.scss +24 -0
- package/scss/mixins/_spacing-mixins.scss +84 -0
- package/scss/mixins/index.scss +2 -0
- package/scss/shared/_base.scss +138 -0
- package/scss/shared/_button.scss +27 -0
- package/scss/shared/_form-elements.scss +162 -0
- package/scss/shared/_opacity.scss +27 -0
- package/scss/shared/_reset.scss +288 -0
- package/scss/shared/_table.scss +73 -0
- package/scss/shared/divide.scss +41 -0
- package/scss/shared/index.scss +12 -0
- package/scss/shared/layout.scss +290 -0
- package/scss/shared/nav.scss +71 -0
- package/scss/themes/_dark.scss +277 -0
- package/scss/themes/_index.scss +3 -0
- package/scss/themes/_light.scss +540 -0
- package/scss/themes/_utility.scss +44 -0
- package/scss/variables/_spacing.scss +35 -0
- package/scss/variables/index.scss +1 -0
- package/src/components/absolute-container/absolute-container.component.ts +62 -0
- package/src/components/absolute-container/absolute-container.test.ts +10 -0
- package/src/components/absolute-container/index.ts +12 -0
- package/src/components/action-bar/action-bar.component.ts +41 -0
- package/src/components/action-bar/action-bar.scss +33 -0
- package/src/components/action-bar/action-bar.test.ts +10 -0
- package/src/components/action-bar/index.ts +12 -0
- package/src/components/alert/alert.component.ts +71 -0
- package/src/components/alert/alert.scss +170 -0
- package/src/components/alert/alert.test.ts +10 -0
- package/src/components/alert/index.ts +12 -0
- package/src/components/bulk-actions/bulk-actions.component.ts +229 -0
- package/src/components/bulk-actions/bulk-actions.scss +56 -0
- package/src/components/bulk-actions/bulk-actions.test.ts +10 -0
- package/src/components/bulk-actions/index.ts +12 -0
- package/src/components/button/button.component.ts +242 -0
- package/src/components/button/button.scss +346 -0
- package/src/components/button/button.test.ts +32 -0
- package/src/components/button/index.ts +12 -0
- package/src/components/button-group/button-group.component.ts +74 -0
- package/src/components/button-group/button-group.scss +39 -0
- package/src/components/button-group/button-group.test.ts +10 -0
- package/src/components/button-group/index.ts +12 -0
- package/src/components/button-menu/button-menu.component.ts +353 -0
- package/src/components/button-menu/button-menu.scss +41 -0
- package/src/components/button-menu/button-menu.test.ts +10 -0
- package/src/components/button-menu/index.ts +12 -0
- package/src/components/chart/chart.component.ts +206 -0
- package/src/components/chart/chart.scss +11 -0
- package/src/components/chart/chart.test.ts +10 -0
- package/src/components/chart/index.ts +12 -0
- package/src/components/checkbox/checkbox.component.ts +326 -0
- package/src/components/checkbox/checkbox.scss +202 -0
- package/src/components/checkbox/checkbox.test.ts +10 -0
- package/src/components/checkbox/index.ts +12 -0
- package/src/components/checkbox-group/checkbox-group.component.ts +351 -0
- package/src/components/checkbox-group/checkbox-group.scss +60 -0
- package/src/components/checkbox-group/checkbox-group.test.ts +10 -0
- package/src/components/checkbox-group/index.ts +12 -0
- package/src/components/chip/chip.component.ts +70 -0
- package/src/components/chip/chip.scss +101 -0
- package/src/components/chip/chip.test.ts +10 -0
- package/src/components/chip/index.ts +12 -0
- package/src/components/collapsible/collapsible.component.ts +86 -0
- package/src/components/collapsible/collapsible.scss +100 -0
- package/src/components/collapsible/collapsible.test.ts +10 -0
- package/src/components/collapsible/index.ts +12 -0
- package/src/components/cols/cols.component.ts +76 -0
- package/src/components/cols/cols.scss +99 -0
- package/src/components/cols/cols.test.ts +10 -0
- package/src/components/cols/index.ts +12 -0
- package/src/components/confirm/confirm.component.ts +181 -0
- package/src/components/confirm/confirm.scss +44 -0
- package/src/components/confirm/confirm.test.ts +10 -0
- package/src/components/confirm/index.ts +12 -0
- package/src/components/content-block/content-block.component.ts +225 -0
- package/src/components/content-block/content-block.scss +64 -0
- package/src/components/content-block/content-block.test.ts +10 -0
- package/src/components/content-block/index.ts +12 -0
- package/src/components/copy-button/copy-button.component.ts +163 -0
- package/src/components/copy-button/copy-button.scss +47 -0
- package/src/components/copy-button/copy-button.test.ts +10 -0
- package/src/components/copy-button/index.ts +12 -0
- package/src/components/data-select/data-select.component.ts +219 -0
- package/src/components/data-select/data-select.scss +43 -0
- package/src/components/data-select/data-select.test.ts +10 -0
- package/src/components/data-select/index.ts +12 -0
- package/src/components/data-select/providers/color-data-provider.ts +16 -0
- package/src/components/data-select/providers/country-code-data-provider.ts +517 -0
- package/src/components/data-select/providers/country-data-provider.ts +527 -0
- package/src/components/data-select/providers/currency-data-provider.ts +328 -0
- package/src/components/data-select/providers/provider.ts +32 -0
- package/src/components/data-table/data-table.component.ts +1093 -0
- package/src/components/data-table/data-table.scss +330 -0
- package/src/components/data-table/data-table.test.ts +10 -0
- package/src/components/data-table/index.ts +12 -0
- package/src/components/data-table-filter/data-table-filter.component.ts +126 -0
- package/src/components/data-table-filter/data-table-filter.scss +22 -0
- package/src/components/data-table-filter/data-table-filter.test.ts +10 -0
- package/src/components/data-table-filter/index.ts +12 -0
- package/src/components/data-table-sort/data-table-sort.component.ts +56 -0
- package/src/components/data-table-sort/data-table-sort.scss +37 -0
- package/src/components/data-table-sort/data-table-sort.test.ts +10 -0
- package/src/components/data-table-sort/index.ts +12 -0
- package/src/components/datepicker/datepicker.component.ts +315 -0
- package/src/components/datepicker/datepicker.scss +237 -0
- package/src/components/datepicker/datepicker.test.ts +10 -0
- package/src/components/datepicker/index.ts +12 -0
- package/src/components/defined-label/defined-label.component.ts +241 -0
- package/src/components/defined-label/defined-label.scss +43 -0
- package/src/components/defined-label/defined-label.test.ts +10 -0
- package/src/components/defined-label/index.ts +12 -0
- package/src/components/dialog/dialog.component.ts +237 -0
- package/src/components/dialog/dialog.scss +197 -0
- package/src/components/dialog/dialog.test.ts +10 -0
- package/src/components/dialog/index.ts +12 -0
- package/src/components/dropdown/dropdown.component.ts +380 -0
- package/src/components/dropdown/dropdown.scss +9 -0
- package/src/components/dropdown/dropdown.test.ts +10 -0
- package/src/components/dropdown/index.ts +12 -0
- package/src/components/editor/editor.component.ts +423 -0
- package/src/components/editor/editor.scss +131 -0
- package/src/components/editor/editor.test.ts +10 -0
- package/src/components/editor/index.ts +12 -0
- package/src/components/editor/modules/attachment-module.ts +195 -0
- package/src/components/editor/modules/dialog-module/dialog-module.component.ts +289 -0
- package/src/components/editor/modules/dialog-module/dialog-module.scss +115 -0
- package/src/components/editor/modules/dialog-module/dialog-module.ts +99 -0
- package/src/components/editor/modules/drag-drop-module.ts +125 -0
- package/src/components/editor/modules/events/zn-command-select.ts +7 -0
- package/src/components/editor/modules/events/zn-editor-update.ts +7 -0
- package/src/components/editor/modules/events/zn-show-canned-response-dialog.ts +15 -0
- package/src/components/editor/modules/image-resize-module/image-resize-module.ts +157 -0
- package/src/components/editor/modules/menu-module/menu-module.component.ts +149 -0
- package/src/components/editor/modules/menu-module/menu-module.scss +17 -0
- package/src/components/editor/modules/menu-module/menu-module.ts +203 -0
- package/src/components/editor/modules/time-tracking-module.ts +35 -0
- package/src/components/empty-state/empty-state.component.ts +63 -0
- package/src/components/empty-state/empty-state.scss +91 -0
- package/src/components/empty-state/empty-state.test.ts +10 -0
- package/src/components/empty-state/index.ts +12 -0
- package/src/components/expanding-action/expanding-action.component.ts +312 -0
- package/src/components/expanding-action/expanding-action.scss +87 -0
- package/src/components/expanding-action/expanding-action.test.ts +10 -0
- package/src/components/expanding-action/index.ts +12 -0
- package/src/components/file/file.component.ts +619 -0
- package/src/components/file/file.scss +200 -0
- package/src/components/file/file.test.ts +10 -0
- package/src/components/file/index.ts +12 -0
- package/src/components/form-group/form-group.component.ts +93 -0
- package/src/components/form-group/form-group.scss +84 -0
- package/src/components/form-group/form-group.test.ts +10 -0
- package/src/components/form-group/index.ts +12 -0
- package/src/components/header/header.component.ts +186 -0
- package/src/components/header/header.scss +244 -0
- package/src/components/header/header.test.ts +10 -0
- package/src/components/header/index.ts +12 -0
- package/src/components/hover-container/hover-container.component.ts +214 -0
- package/src/components/hover-container/hover-container.scss +59 -0
- package/src/components/hover-container/hover-container.ts +10 -0
- package/src/components/hover-container/index.ts +12 -0
- package/src/components/icon/icon.component.ts +251 -0
- package/src/components/icon/icon.scss +186 -0
- package/src/components/icon/icon.test.ts +10 -0
- package/src/components/icon/index.ts +13 -0
- package/src/components/icon/lni.scss +2492 -0
- package/src/components/inline-edit/index.ts +12 -0
- package/src/components/inline-edit/inline-edit.component.ts +289 -0
- package/src/components/inline-edit/inline-edit.scss +139 -0
- package/src/components/inline-edit/inline-edit.test.ts +10 -0
- package/src/components/input/index.ts +12 -0
- package/src/components/input/input.component.ts +614 -0
- package/src/components/input/input.scss +355 -0
- package/src/components/input/input.test.ts +10 -0
- package/src/components/item/index.ts +12 -0
- package/src/components/item/item.component.ts +102 -0
- package/src/components/item/item.scss +161 -0
- package/src/components/item/item.test.ts +10 -0
- package/src/components/linked-select/index.ts +12 -0
- package/src/components/linked-select/linked-select.component.ts +156 -0
- package/src/components/linked-select/linked-select.scss +9 -0
- package/src/components/linked-select/linked-select.test.ts +17 -0
- package/src/components/menu/index.ts +12 -0
- package/src/components/menu/menu.component.ts +243 -0
- package/src/components/menu/menu.scss +14 -0
- package/src/components/menu/menu.test.ts +10 -0
- package/src/components/menu-item/index.ts +12 -0
- package/src/components/menu-item/menu-item.component.ts +220 -0
- package/src/components/menu-item/menu-item.scss +157 -0
- package/src/components/menu-item/menu-item.test.ts +10 -0
- package/src/components/menu-item/submenu-controller.ts +291 -0
- package/src/components/navbar/index.ts +12 -0
- package/src/components/navbar/navbar.component.ts +240 -0
- package/src/components/navbar/navbar.scss +411 -0
- package/src/components/navbar/navbar.test.ts +10 -0
- package/src/components/note/index.ts +12 -0
- package/src/components/note/note.component.ts +60 -0
- package/src/components/note/note.scss +69 -0
- package/src/components/note/note.test.ts +10 -0
- package/src/components/option/index.ts +12 -0
- package/src/components/option/option.component.ts +152 -0
- package/src/components/option/option.scss +88 -0
- package/src/components/option/option.test.ts +10 -0
- package/src/components/order-table/index.ts +12 -0
- package/src/components/order-table/order-table.component.ts +323 -0
- package/src/components/order-table/order-table.scss +154 -0
- package/src/components/order-table/order-table.test.ts +10 -0
- package/src/components/page-nav/index.ts +12 -0
- package/src/components/page-nav/page-nav.component.ts +117 -0
- package/src/components/page-nav/page-nav.scss +155 -0
- package/src/components/page-nav/page-nav.test.ts +10 -0
- package/src/components/pagination/index.ts +12 -0
- package/src/components/pagination/pagination.component.ts +91 -0
- package/src/components/pagination/pagination.scss +76 -0
- package/src/components/pagination/pagination.test.ts +10 -0
- package/src/components/pane/index.ts +12 -0
- package/src/components/pane/pane.component.ts +52 -0
- package/src/components/pane/pane.scss +45 -0
- package/src/components/pane/pane.test.ts +10 -0
- package/src/components/panel/index.ts +12 -0
- package/src/components/panel/panel.component.ts +100 -0
- package/src/components/panel/panel.scss +129 -0
- package/src/components/panel/panel.test.ts +10 -0
- package/src/components/popup/index.ts +12 -0
- package/src/components/popup/popup.component.ts +543 -0
- package/src/components/popup/popup.scss +59 -0
- package/src/components/popup/popup.test.ts +10 -0
- package/src/components/progress-bar/index.ts +12 -0
- package/src/components/progress-bar/progress-bar.component.ts +80 -0
- package/src/components/progress-bar/progress-bar.scss +46 -0
- package/src/components/progress-bar/progress-bar.test.ts +10 -0
- package/src/components/progress-tile/index.ts +12 -0
- package/src/components/progress-tile/progress-tile.component.ts +127 -0
- package/src/components/progress-tile/progress-tile.scss +116 -0
- package/src/components/progress-tile/progress-tile.test.ts +10 -0
- package/src/components/query-builder/index.ts +12 -0
- package/src/components/query-builder/query-builder.component.ts +544 -0
- package/src/components/query-builder/query-builder.scss +53 -0
- package/src/components/query-builder/query-builder.test.ts +10 -0
- package/src/components/radio/index.ts +12 -0
- package/src/components/radio/radio.component.ts +305 -0
- package/src/components/radio/radio.scss +197 -0
- package/src/components/radio/radio.test.ts +10 -0
- package/src/components/radio-group/index.ts +12 -0
- package/src/components/radio-group/radio-group.component.ts +362 -0
- package/src/components/radio-group/radio-group.scss +60 -0
- package/src/components/radio-group/radio-group.test.ts +10 -0
- package/src/components/rating/index.ts +12 -0
- package/src/components/rating/rating.component.ts +235 -0
- package/src/components/rating/rating.scss +82 -0
- package/src/components/rating/rating.test.ts +10 -0
- package/src/components/scroll-container/index.ts +12 -0
- package/src/components/scroll-container/scroll-container.component.ts +41 -0
- package/src/components/scroll-container/scroll-container.scss +17 -0
- package/src/components/scroll-container/scroll-container.test.ts +10 -0
- package/src/components/select/index.ts +12 -0
- package/src/components/select/select.component.ts +984 -0
- package/src/components/select/select.scss +325 -0
- package/src/components/select/select.test.ts +10 -0
- package/src/components/sidebar/index.ts +12 -0
- package/src/components/sidebar/sidebar.component.ts +98 -0
- package/src/components/sidebar/sidebar.scss +294 -0
- package/src/components/sidebar/sidebar.test.ts +10 -0
- package/src/components/simple-chart/index.ts +12 -0
- package/src/components/simple-chart/simple-chart.component.ts +204 -0
- package/src/components/simple-chart/simple-chart.scss +9 -0
- package/src/components/simple-chart/simple-chart.test.ts +10 -0
- package/src/components/skeleton/index.ts +12 -0
- package/src/components/skeleton/skeleton.component.ts +34 -0
- package/src/components/skeleton/skeleton.scss +39 -0
- package/src/components/skeleton/skeleton.test.ts +10 -0
- package/src/components/slideout/index.ts +12 -0
- package/src/components/slideout/slideout.component.ts +223 -0
- package/src/components/slideout/slideout.scss +96 -0
- package/src/components/slideout/slideout.test.ts +10 -0
- package/src/components/sp/index.ts +12 -0
- package/src/components/sp/sp.component.ts +86 -0
- package/src/components/sp/sp.scss +88 -0
- package/src/components/sp/sp.test.ts +10 -0
- package/src/components/split-button/index.ts +12 -0
- package/src/components/split-button/split-button.component.ts +154 -0
- package/src/components/split-button/split-button.scss +9 -0
- package/src/components/split-button/split-button.test.ts +10 -0
- package/src/components/split-pane/index.ts +12 -0
- package/src/components/split-pane/split-pane.component.ts +195 -0
- package/src/components/split-pane/split-pane.scss +303 -0
- package/src/components/split-pane/split-pane.test.ts +10 -0
- package/src/components/stat/index.ts +12 -0
- package/src/components/stat/stat.component.ts +117 -0
- package/src/components/stat/stat.scss +92 -0
- package/src/components/stat/stat.test.ts +10 -0
- package/src/components/status-indicator/index.ts +12 -0
- package/src/components/status-indicator/status-indicator.component.ts +31 -0
- package/src/components/status-indicator/status-indicator.scss +32 -0
- package/src/components/status-indicator/status-indicator.test.ts +10 -0
- package/src/components/stepper/index.ts +12 -0
- package/src/components/stepper/stepper.component.ts +80 -0
- package/src/components/stepper/stepper.scss +88 -0
- package/src/components/stepper/stepper.test.ts +10 -0
- package/src/components/style/index.ts +12 -0
- package/src/components/style/style.component.ts +150 -0
- package/src/components/style/style.scss +1 -0
- package/src/components/style/style.test.ts +10 -0
- package/src/components/table/index.ts +12 -0
- package/src/components/table/table.component.ts +297 -0
- package/src/components/table/table.scss +209 -0
- package/src/components/table/table.test.ts +10 -0
- package/src/components/tabs/index.ts +12 -0
- package/src/components/tabs/tabs.component.ts +496 -0
- package/src/components/tabs/tabs.scss +147 -0
- package/src/components/tabs/tabs.test.ts +10 -0
- package/src/components/textarea/index.ts +12 -0
- package/src/components/textarea/textarea.component.ts +417 -0
- package/src/components/textarea/textarea.scss +152 -0
- package/src/components/textarea/textarea.test.ts +10 -0
- package/src/components/tile/index.ts +12 -0
- package/src/components/tile/tile.component.ts +105 -0
- package/src/components/tile/tile.scss +144 -0
- package/src/components/tile/tile.test.ts +10 -0
- package/src/components/tile-property/index.ts +12 -0
- package/src/components/tile-property/tile-property.component.ts +43 -0
- package/src/components/tile-property/tile-property.scss +43 -0
- package/src/components/tile-property/tile-property.test.ts +10 -0
- package/src/components/timer/index.ts +12 -0
- package/src/components/timer/timer.component.ts +88 -0
- package/src/components/timer/timer.scss +40 -0
- package/src/components/timer/timer.test.ts +10 -0
- package/src/components/toggle/index.ts +12 -0
- package/src/components/toggle/toggle.component.ts +203 -0
- package/src/components/toggle/toggle.scss +93 -0
- package/src/components/toggle/toggle.test.ts +10 -0
- package/src/components/tooltip/index.ts +12 -0
- package/src/components/tooltip/tooltip.component.ts +215 -0
- package/src/components/tooltip/tooltip.scss +43 -0
- package/src/components/tooltip/tooltip.test.ts +10 -0
- package/src/components/vertical-stepper/index.ts +12 -0
- package/src/components/vertical-stepper/vertical-stepper.component.ts +53 -0
- package/src/components/vertical-stepper/vertical-stepper.scss +84 -0
- package/src/components/vertical-stepper/vertical-stepper.test.ts +10 -0
- package/src/components/well/index.ts +12 -0
- package/src/components/well/well.component.ts +43 -0
- package/src/components/well/well.scss +19 -0
- package/src/components/well/well.test.ts +10 -0
- package/src/declaration.d.ts +39 -0
- package/src/events/events.ts +7 -0
- package/src/events/zn-after-collapse.ts +7 -0
- package/src/events/zn-after-expand.ts +7 -0
- package/src/events/zn-after-hide.ts +7 -0
- package/src/events/zn-after-show.ts +7 -0
- package/src/events/zn-blur.ts +7 -0
- package/src/events/zn-cancel.ts +7 -0
- package/src/events/zn-change.ts +7 -0
- package/src/events/zn-clear.ts +7 -0
- package/src/events/zn-close.ts +7 -0
- package/src/events/zn-collapse.ts +7 -0
- package/src/events/zn-copy.ts +7 -0
- package/src/events/zn-element-added.ts +7 -0
- package/src/events/zn-error.ts +7 -0
- package/src/events/zn-expand.ts +7 -0
- package/src/events/zn-filter-change.ts +7 -0
- package/src/events/zn-finish.ts +7 -0
- package/src/events/zn-focus.ts +7 -0
- package/src/events/zn-hide.ts +7 -0
- package/src/events/zn-hover.ts +10 -0
- package/src/events/zn-initial-focus.ts +7 -0
- package/src/events/zn-input.ts +7 -0
- package/src/events/zn-invalid.ts +7 -0
- package/src/events/zn-load.ts +7 -0
- package/src/events/zn-menu-ready.ts +9 -0
- package/src/events/zn-menu-select.ts +9 -0
- package/src/events/zn-open.ts +7 -0
- package/src/events/zn-remove.ts +7 -0
- package/src/events/zn-request-close.ts +7 -0
- package/src/events/zn-select.ts +9 -0
- package/src/events/zn-show.ts +7 -0
- package/src/events/zn-sort-change.ts +7 -0
- package/src/events/zn-submit.ts +7 -0
- package/src/form-control.scss +123 -0
- package/src/internal/animate.ts +64 -0
- package/src/internal/default-value.ts +49 -0
- package/src/internal/event.ts +75 -0
- package/src/internal/form.ts +527 -0
- package/src/internal/offset.ts +13 -0
- package/src/internal/scroll.ts +69 -0
- package/src/internal/slot.ts +110 -0
- package/src/internal/storage.ts +70 -0
- package/src/internal/tabbable.ts +198 -0
- package/src/internal/theme.ts +54 -0
- package/src/internal/watch.ts +63 -0
- package/src/internal/zinc-element.ts +113 -0
- package/src/translations/en.ts +30 -0
- package/src/utilities/animation-registry.ts +74 -0
- package/src/utilities/base-path.ts +46 -0
- package/src/utilities/lit-to-html.ts +7 -0
- package/src/utilities/localize.ts +37 -0
- package/src/utilities/md5.ts +216 -0
- package/src/utilities/on.ts +29 -0
- package/src/utilities/query.ts +36 -0
- package/src/wc.scss +33 -0
- package/src/zinc-autoloader.ts +58 -0
- package/src/zinc.ts +83 -0
- package/tsconfig.json +41 -0
- package/tsconfig.prod.json +12 -0
- package/vscode.html-custom-data.json +2804 -0
- package/web-test-runner.config.js +50 -0
- package/web-types.json +6420 -0
- package/zn.d.ts +6318 -0
- package/zn.min.css +1 -0
- package/zn.min.js +3701 -0
- package/.idea/.name +0 -1
- package/.idea/fusion.iml +0 -9
- package/.idea/modules.xml +0 -8
- package/.idea/php.xml +0 -4
- package/.idea/vcs.xml +0 -6
- package/.idea/watcherTasks.xml +0 -25
- package/components/Blank/demo/demo.html +0 -11
- package/components/Blank/dist/zn-blank.js +0 -39
- package/components/Blank/go/component.go +0 -18
- package/components/Blank/go/go.mod +0 -3
- package/components/Blank/package.json +0 -33
- package/components/Blank/php/composer.json +0 -25
- package/components/Blank/php/src/Blank.php +0 -15
- package/components/Blank/rollup.config.js +0 -32
- package/components/Blank/scss/Styles.scss +0 -6
- package/components/Blank/ts/Component.ts +0 -15
- package/components/Blank/tsconfig.json +0 -7
- package/components/Icon/demo/demo.html +0 -90
- package/components/Icon/dist/zn-icon.js +0 -55
- package/components/Icon/go/component.go +0 -56
- package/components/Icon/go/go.mod +0 -3
- package/components/Icon/package.json +0 -33
- package/components/Icon/php/composer.json +0 -26
- package/components/Icon/php/src/Icon.php +0 -38
- package/components/Icon/php/src/Library.php +0 -17
- package/components/Icon/php/src/Size.php +0 -42
- package/components/Icon/roadmap.md +0 -7
- package/components/Icon/rollup.config.js +0 -32
- package/components/Icon/scss/Styles.scss +0 -65
- package/components/Icon/ts/Component.ts +0 -108
- package/components/Icon/ts/md5.ts +0 -215
- package/components/Icon/tsconfig.json +0 -7
- package/components/MaxWidth/demo/demo.html +0 -11
- package/components/MaxWidth/dist/zn-max-width.js +0 -51
- package/components/MaxWidth/go/component.go +0 -24
- package/components/MaxWidth/go/go.mod +0 -3
- package/components/MaxWidth/package.json +0 -33
- package/components/MaxWidth/php/composer.json +0 -25
- package/components/MaxWidth/php/src/MaxWidth.php +0 -32
- package/components/MaxWidth/rollup.config.js +0 -32
- package/components/MaxWidth/scss/Styles.scss +0 -13
- package/components/MaxWidth/ts/Component.ts +0 -27
- package/components/MaxWidth/tsconfig.json +0 -7
- package/components/roadmap.md +0 -4
- package/layout/components/Columns/demo/demo.html +0 -16
- package/layout/components/Columns/ts/Component.ts +0 -59
- package/layout/demo/index.html +0 -24
- package/layout/dist/zn-layout.js +0 -87
- package/layout/package.json +0 -38
- package/layout/rollup.config.js +0 -38
- package/layout/scss/layout.scss +0 -24
- package/layout/tailwind.config.js +0 -42
- package/layout/ts/import.ts +0 -2
- package/layout/tsconfig.json +0 -7
- /package/{layout/components/Columns/scss/Styles.scss → src/internal/zinc-element.test.ts} +0 -0
|
@@ -0,0 +1,527 @@
|
|
|
1
|
+
import type {ReactiveController, ReactiveControllerHost} from "lit";
|
|
2
|
+
import type {ZincFormControl} from "./zinc-element";
|
|
3
|
+
import type Button from "../components/button";
|
|
4
|
+
|
|
5
|
+
//
|
|
6
|
+
// We store a WeakMap of forms + controls so we can keep references to all Zinc controls within a given form. As
|
|
7
|
+
// elements connect and disconnect to/from the DOM, their containing form is used as the key and the form control is
|
|
8
|
+
// added and removed from the form's set, respectively.
|
|
9
|
+
//
|
|
10
|
+
export const formCollections: WeakMap<HTMLFormElement, Set<ZincFormControl>> = new WeakMap();
|
|
11
|
+
|
|
12
|
+
//
|
|
13
|
+
// We store a WeakMap of reportValidity() overloads so we can override it when form controls connect to the DOM and
|
|
14
|
+
// restore the original behavior when they disconnect.
|
|
15
|
+
//
|
|
16
|
+
const reportValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();
|
|
17
|
+
const checkValidityOverloads: WeakMap<HTMLFormElement, () => boolean> = new WeakMap();
|
|
18
|
+
|
|
19
|
+
//
|
|
20
|
+
// We store a Set of controls that users have interacted with. This allows us to determine the interaction state
|
|
21
|
+
// without littering the DOM with additional data attributes.
|
|
22
|
+
//
|
|
23
|
+
const userInteractedControls: WeakSet<ZincFormControl> = new WeakSet();
|
|
24
|
+
|
|
25
|
+
//
|
|
26
|
+
// We store a WeakMap of interactions for each form control so we can track when all conditions are met for validation.
|
|
27
|
+
//
|
|
28
|
+
const interactions = new WeakMap<ZincFormControl, string[]>();
|
|
29
|
+
|
|
30
|
+
export interface FormControlControllerOptions {
|
|
31
|
+
/** A function that returns the form containing the form control. */
|
|
32
|
+
form: (input: ZincFormControl) => HTMLFormElement | null;
|
|
33
|
+
/** A function that returns the form control's name, which will be submitted with the form data. */
|
|
34
|
+
name: (input: ZincFormControl) => string;
|
|
35
|
+
/** A function that returns the form control's current value. */
|
|
36
|
+
value: (input: ZincFormControl) => unknown | unknown[];
|
|
37
|
+
/** A function that returns the form control's default value. */
|
|
38
|
+
defaultValue: (input: ZincFormControl) => unknown | unknown[];
|
|
39
|
+
/** A function that returns the form control's current disabled state. If disabled, the value won't be submitted. */
|
|
40
|
+
disabled: (input: ZincFormControl) => boolean;
|
|
41
|
+
/**
|
|
42
|
+
* A function that maps to the form control's reportValidity() function. When the control is invalid, this will
|
|
43
|
+
* prevent submission and trigger the browser's constraint violation warning.
|
|
44
|
+
*/
|
|
45
|
+
reportValidity: (input: ZincFormControl) => boolean;
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A function that maps to the form control's `checkValidity()` function. When the control is invalid, this will return false.
|
|
49
|
+
* this is helpful is you want to check validation without triggering the native browser constraint violation warning.
|
|
50
|
+
*/
|
|
51
|
+
checkValidity: (input: ZincFormControl) => boolean;
|
|
52
|
+
/** A function that sets the form control's value */
|
|
53
|
+
setValue: (input: ZincFormControl, value: unknown) => void;
|
|
54
|
+
/**
|
|
55
|
+
* An array of event names to listen to. When all events in the list are emitted, the control will receive validity
|
|
56
|
+
* states such as user-valid and user-invalid.user interacted validity states. */
|
|
57
|
+
assumeInteractionOn: string[];
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
export class FormControlController implements ReactiveController {
|
|
61
|
+
host: ZincFormControl & ReactiveControllerHost;
|
|
62
|
+
form?: HTMLFormElement | null;
|
|
63
|
+
options: FormControlControllerOptions;
|
|
64
|
+
|
|
65
|
+
constructor(host: ReactiveControllerHost & ZincFormControl, options?: Partial<FormControlControllerOptions>) {
|
|
66
|
+
(this.host = host).addController(this);
|
|
67
|
+
this.options = {
|
|
68
|
+
form: input => {
|
|
69
|
+
// If there's a form attribute, use it to find the target form by id
|
|
70
|
+
// Controls may not always reflect the 'form' property. For example, `<zn-button>` doesn't reflect.
|
|
71
|
+
const formId = input.form;
|
|
72
|
+
|
|
73
|
+
if (formId) {
|
|
74
|
+
const root = input.getRootNode() as Document | ShadowRoot | HTMLElement;
|
|
75
|
+
const form = root.querySelector(`#${formId}`);
|
|
76
|
+
|
|
77
|
+
if (form) {
|
|
78
|
+
return form as HTMLFormElement;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return input.closest('form');
|
|
83
|
+
},
|
|
84
|
+
name: input => input.name,
|
|
85
|
+
value: input => input.value,
|
|
86
|
+
defaultValue: input => input.defaultValue,
|
|
87
|
+
disabled: input => input.disabled ?? false,
|
|
88
|
+
reportValidity: input => (typeof input.reportValidity === 'function' ? input.reportValidity() : true),
|
|
89
|
+
checkValidity: input => (typeof input.checkValidity === 'function' ? input.checkValidity() : true),
|
|
90
|
+
setValue: (input, value: string) => (input.value = value),
|
|
91
|
+
assumeInteractionOn: ['zn-input'],
|
|
92
|
+
...options
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
async hostConnected() {
|
|
97
|
+
const form = this.options.form(this.host);
|
|
98
|
+
|
|
99
|
+
if (form) {
|
|
100
|
+
this.attachForm(form);
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
// Listen for interactions
|
|
104
|
+
interactions.set(this.host, []);
|
|
105
|
+
this.options.assumeInteractionOn.forEach(event => {
|
|
106
|
+
this.host.addEventListener(event, this.handleInteraction);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
await this.host.updateComplete;
|
|
110
|
+
if (form) {
|
|
111
|
+
this.checkFormValidity();
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
hostDisconnected() {
|
|
116
|
+
this.detachForm();
|
|
117
|
+
|
|
118
|
+
// Clean up interactions
|
|
119
|
+
interactions.delete(this.host);
|
|
120
|
+
this.options.assumeInteractionOn.forEach(event => {
|
|
121
|
+
this.host.removeEventListener(event, this.handleInteraction);
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
hostUpdated() {
|
|
126
|
+
const form = this.options.form(this.host);
|
|
127
|
+
|
|
128
|
+
// Detach if the form no longer exists
|
|
129
|
+
if (!form) {
|
|
130
|
+
this.detachForm();
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// If the form has changed, reattach it
|
|
134
|
+
if (form && this.form !== form) {
|
|
135
|
+
this.detachForm();
|
|
136
|
+
this.attachForm(form);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
if (this.host.hasUpdated) {
|
|
140
|
+
this.setValidity(this.host.validity?.valid);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
private attachForm(form?: HTMLFormElement) {
|
|
145
|
+
if (!form) {
|
|
146
|
+
this.form = undefined;
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
this.form = form;
|
|
151
|
+
|
|
152
|
+
// Add this element to the form's collection
|
|
153
|
+
if (formCollections.has(this.form)) {
|
|
154
|
+
formCollections.get(this.form)!.add(this.host);
|
|
155
|
+
} else {
|
|
156
|
+
formCollections.set(this.form, new Set<ZincFormControl>([this.host]));
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
this.form.addEventListener('formdata', this.handleFormData);
|
|
160
|
+
this.form.addEventListener('submit', this.handleFormSubmit);
|
|
161
|
+
this.form.addEventListener('reset', this.handleFormReset);
|
|
162
|
+
|
|
163
|
+
// Pagelet events to check form completion state
|
|
164
|
+
this.form.addEventListener('complete', this.enableSubmit);
|
|
165
|
+
this.form.addEventListener('cancelled', this.enableSubmit);
|
|
166
|
+
this.form.addEventListener('error', this.enableSubmit);
|
|
167
|
+
|
|
168
|
+
// Overload the form's reportValidity() method so it looks at Zinc form controls
|
|
169
|
+
if (!reportValidityOverloads.has(this.form)) {
|
|
170
|
+
reportValidityOverloads.set(this.form, this.form.reportValidity);
|
|
171
|
+
this.form.reportValidity = () => this.reportFormValidity();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// Overload the form's checkValidity() method so it looks at Zinc form controls
|
|
175
|
+
if (!checkValidityOverloads.has(this.form)) {
|
|
176
|
+
checkValidityOverloads.set(this.form, this.form.checkValidity);
|
|
177
|
+
this.form.checkValidity = () => this.checkFormValidity();
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
private detachForm() {
|
|
182
|
+
if (!this.form) return;
|
|
183
|
+
|
|
184
|
+
const formCollection = formCollections.get(this.form);
|
|
185
|
+
|
|
186
|
+
if (!formCollection) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
// Remove this host from the form's collection
|
|
191
|
+
formCollection.delete(this.host);
|
|
192
|
+
|
|
193
|
+
// Check to make sure there's no other form controls in the collection. If we do this
|
|
194
|
+
// without checking if any other controls are still in the collection, then we will wipe out the
|
|
195
|
+
// validity checks for all other elements.
|
|
196
|
+
if (formCollection.size <= 0) {
|
|
197
|
+
this.form.removeEventListener('formdata', this.handleFormData);
|
|
198
|
+
this.form.removeEventListener('submit', this.handleFormSubmit);
|
|
199
|
+
this.form.removeEventListener('reset', this.handleFormReset);
|
|
200
|
+
|
|
201
|
+
this.form.removeEventListener('complete', this.enableSubmit);
|
|
202
|
+
this.form.removeEventListener('cancelled', this.enableSubmit);
|
|
203
|
+
this.form.removeEventListener('error', this.enableSubmit);
|
|
204
|
+
|
|
205
|
+
if (reportValidityOverloads.has(this.form)) {
|
|
206
|
+
this.form.reportValidity = reportValidityOverloads.get(this.form)!;
|
|
207
|
+
reportValidityOverloads.delete(this.form);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (checkValidityOverloads.has(this.form)) {
|
|
211
|
+
this.form.checkValidity = checkValidityOverloads.get(this.form)!;
|
|
212
|
+
checkValidityOverloads.delete(this.form);
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// So it looks weird here to not always set the form to undefined. But I _think_ if we un-attach this.form here,
|
|
216
|
+
// we end up in this fun spot where future validity checks don't have a reference to the form validity handler.
|
|
217
|
+
// First form element in sets the validity handler. So we can't clean up `this.form` until there are no other form elements in the form.
|
|
218
|
+
this.form = undefined;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
private handleFormData = (event: FormDataEvent) => {
|
|
223
|
+
const disabled = this.options.disabled(this.host);
|
|
224
|
+
const name = this.options.name(this.host);
|
|
225
|
+
const value = this.options.value(this.host);
|
|
226
|
+
|
|
227
|
+
// For buttons, we only submit the value if they were the submitter. This is currently done in doAction() by
|
|
228
|
+
// injecting the name/value on a temporary button, so we can just skip them here.
|
|
229
|
+
const isButton = this.host.tagName.toLowerCase() === 'zn-button';
|
|
230
|
+
|
|
231
|
+
if (
|
|
232
|
+
this.host.isConnected &&
|
|
233
|
+
!disabled &&
|
|
234
|
+
!isButton &&
|
|
235
|
+
name.length > 0 &&
|
|
236
|
+
typeof value !== 'undefined'
|
|
237
|
+
) {
|
|
238
|
+
if (Array.isArray(value)) {
|
|
239
|
+
(value as unknown[]).forEach(val => {
|
|
240
|
+
event.formData.append(name, (val as string | number | boolean).toString());
|
|
241
|
+
});
|
|
242
|
+
} else {
|
|
243
|
+
event.formData.append(name, (value as string | number | boolean).toString());
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
this.host.dispatchEvent(new CustomEvent('zn-formdata', {bubbles: true, composed: true}));
|
|
247
|
+
}
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
private handleFormSubmit = (event: Event) => {
|
|
251
|
+
const disabled = this.options.disabled(this.host);
|
|
252
|
+
const reportValidity = this.options.reportValidity;
|
|
253
|
+
|
|
254
|
+
// Update the interacted state for all controls when the form is submitted
|
|
255
|
+
if (this.form && !this.form.noValidate) {
|
|
256
|
+
formCollections.get(this.form)?.forEach(control => {
|
|
257
|
+
this.setUserInteracted(control, true);
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
// get the submit button
|
|
262
|
+
const submitButton = this.form?.querySelector('[type="submit"]') as HTMLButtonElement | null;
|
|
263
|
+
const content = submitButton?.innerHTML ?? 'Submit';
|
|
264
|
+
if (submitButton) {
|
|
265
|
+
submitButton.setAttribute('data-original-text', content);
|
|
266
|
+
|
|
267
|
+
setTimeout(() => {
|
|
268
|
+
// disable duplicate submit
|
|
269
|
+
submitButton.disabled = true;
|
|
270
|
+
submitButton.innerHTML = this.form?.getAttribute('data-loading-text') || 'Processing...';
|
|
271
|
+
}, 20);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
if (this.form && !this.form.noValidate && !disabled && !reportValidity(this.host)) {
|
|
275
|
+
event.preventDefault();
|
|
276
|
+
event.stopImmediatePropagation();
|
|
277
|
+
|
|
278
|
+
// remove the disabled state from the submit button
|
|
279
|
+
if (submitButton) {
|
|
280
|
+
submitButton.disabled = false;
|
|
281
|
+
submitButton.innerHTML = content;
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
|
|
286
|
+
private enableSubmit = (e: Event) => {
|
|
287
|
+
const target = e.target;
|
|
288
|
+
|
|
289
|
+
// Make sure the event is coming from the attached form
|
|
290
|
+
if (target !== this.form) {
|
|
291
|
+
return;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
const submitButton = this.form?.querySelector('[type="submit"]') as HTMLButtonElement | null;
|
|
295
|
+
if (submitButton) {
|
|
296
|
+
const content = submitButton.getAttribute('data-original-text') ?? submitButton.innerHTML;
|
|
297
|
+
|
|
298
|
+
submitButton.disabled = false;
|
|
299
|
+
submitButton.innerHTML = content;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
private handleFormReset = () => {
|
|
304
|
+
this.options.setValue(this.host, this.options.defaultValue(this.host));
|
|
305
|
+
this.setUserInteracted(this.host, false);
|
|
306
|
+
interactions.set(this.host, []);
|
|
307
|
+
};
|
|
308
|
+
|
|
309
|
+
private handleInteraction = (event: Event) => {
|
|
310
|
+
const emittedEvents = interactions.get(this.host)!;
|
|
311
|
+
|
|
312
|
+
if (!emittedEvents.includes(event.type)) {
|
|
313
|
+
emittedEvents.push(event.type);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// Mark it as user-interacted as soon as all associated events have been emitted
|
|
317
|
+
if (emittedEvents.length === this.options.assumeInteractionOn.length) {
|
|
318
|
+
this.setUserInteracted(this.host, true);
|
|
319
|
+
}
|
|
320
|
+
this.checkFormValidity();
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
private checkFormValidity = () => {
|
|
324
|
+
//
|
|
325
|
+
// This is very similar to the `reportFormValidity` function, but it does not trigger native constraint validation
|
|
326
|
+
// Allow the user to simply check if the form is valid and handling validity in their own way.
|
|
327
|
+
//
|
|
328
|
+
// We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger
|
|
329
|
+
// validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't
|
|
330
|
+
// be necessary once we can use ElementInternals.
|
|
331
|
+
//
|
|
332
|
+
// Note that we're also honoring the form's novalidate attribute.
|
|
333
|
+
//
|
|
334
|
+
const submit = this.form?.querySelector('[type="submit"]') as HTMLButtonElement | null;
|
|
335
|
+
if (this.form && !this.form.noValidate) {
|
|
336
|
+
// This seems sloppy, but checking all elements will cover native inputs, Zinc inputs, and other custom
|
|
337
|
+
// elements that support the constraint validation API.
|
|
338
|
+
const elements: NodeListOf<HTMLInputElement> = this.form.querySelectorAll<HTMLInputElement>('*');
|
|
339
|
+
for (const element of elements) {
|
|
340
|
+
if (typeof element.checkValidity === 'function' && !element.checkValidity()) {
|
|
341
|
+
submit?.setAttribute('disabled', 'disabled');
|
|
342
|
+
return false;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
|
|
347
|
+
submit?.removeAttribute('disabled');
|
|
348
|
+
return true;
|
|
349
|
+
};
|
|
350
|
+
|
|
351
|
+
private reportFormValidity = () => {
|
|
352
|
+
//
|
|
353
|
+
// Zinc form controls work hard to act like regular form controls. They support the Constraint Validation API
|
|
354
|
+
// and its associated methods such as setCustomValidity() and reportValidity(). However, the HTMLFormElement also
|
|
355
|
+
// has a reportValidity() method that will trigger validation on all child controls. Since we're not yet using
|
|
356
|
+
// ElementInternals, we need to overload this method so it looks for any element with the reportValidity() method.
|
|
357
|
+
//
|
|
358
|
+
// We preserve the original method in a WeakMap, but we don't call it from the overload because that would trigger
|
|
359
|
+
// validations in an unexpected order. When the element disconnects, we revert to the original behavior. This won't
|
|
360
|
+
// be necessary once we can use ElementInternals.
|
|
361
|
+
//
|
|
362
|
+
// Note that we're also honoring the form's novalidate attribute.
|
|
363
|
+
//
|
|
364
|
+
if (this.form && !this.form.noValidate) {
|
|
365
|
+
// This seems sloppy, but checking all elements will cover native inputs, Zinc inputs, and other custom
|
|
366
|
+
// elements that support the constraint validation API.
|
|
367
|
+
const elements: NodeListOf<HTMLInputElement> = this.form.querySelectorAll<HTMLInputElement>('*');
|
|
368
|
+
for (const element of elements) {
|
|
369
|
+
if (typeof element.reportValidity === 'function' && !element.reportValidity()) {
|
|
370
|
+
return false;
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return true;
|
|
376
|
+
};
|
|
377
|
+
|
|
378
|
+
private setUserInteracted(el: ZincFormControl, hasInteracted: boolean) {
|
|
379
|
+
if (hasInteracted) {
|
|
380
|
+
userInteractedControls.add(el);
|
|
381
|
+
} else {
|
|
382
|
+
userInteractedControls.delete(el);
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
el.requestUpdate();
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
private doAction(type: 'submit' | 'reset', submitter?: HTMLInputElement | Button) {
|
|
389
|
+
if (this.form) {
|
|
390
|
+
const button = document.createElement('button');
|
|
391
|
+
button.type = type;
|
|
392
|
+
button.style.position = 'absolute';
|
|
393
|
+
button.style.width = '0';
|
|
394
|
+
button.style.height = '0';
|
|
395
|
+
button.style.clipPath = 'inset(50%)';
|
|
396
|
+
button.style.overflow = 'hidden';
|
|
397
|
+
button.style.whiteSpace = 'nowrap';
|
|
398
|
+
|
|
399
|
+
// Pass name, value, and form attributes through to the temporary button
|
|
400
|
+
if (submitter) {
|
|
401
|
+
button.name = submitter.name;
|
|
402
|
+
button.value = submitter.value;
|
|
403
|
+
|
|
404
|
+
['formaction', 'formenctype', 'formmethod', 'formnovalidate', 'formtarget'].forEach(attr => {
|
|
405
|
+
if (submitter.hasAttribute(attr)) {
|
|
406
|
+
button.setAttribute(attr, submitter.getAttribute(attr)!);
|
|
407
|
+
}
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
this.form.append(button);
|
|
412
|
+
|
|
413
|
+
// make sure this form is 'zn-register-element' event with the form
|
|
414
|
+
if (this.form instanceof HTMLFormElement) {
|
|
415
|
+
document.dispatchEvent(new CustomEvent('zn-register-element', {
|
|
416
|
+
detail: {element: this.form}
|
|
417
|
+
}));
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
button.click();
|
|
421
|
+
button.remove();
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
/** Returns the associated `<form>` element, if one exists. */
|
|
426
|
+
getForm() {
|
|
427
|
+
return this.form ?? null;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
/** Resets the form, restoring all the control to their default value */
|
|
431
|
+
reset(submitter?: HTMLInputElement | Button) {
|
|
432
|
+
this.doAction('reset', submitter);
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
/** Submits the form, triggering validation and form data injection. */
|
|
436
|
+
submit(submitter?: HTMLInputElement | Button) {
|
|
437
|
+
// Calling form.submit() bypasses the submit event and constraint validation. To prevent this, we can inject a
|
|
438
|
+
// native submit button into the form, "click" it, then remove it to simulate a standard form submission.
|
|
439
|
+
this.doAction('submit', submitter);
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
/**
|
|
443
|
+
* Synchronously sets the form control's validity. Call this when you know the future validity but need to update
|
|
444
|
+
* the host element immediately, i.e. before Lit updates the component in the next update.
|
|
445
|
+
*/
|
|
446
|
+
setValidity(isValid: boolean) {
|
|
447
|
+
const host = this.host;
|
|
448
|
+
const hasInteracted = Boolean(userInteractedControls.has(host));
|
|
449
|
+
const required = Boolean(host.required);
|
|
450
|
+
|
|
451
|
+
// We're mapping the following "states" to data attributes. In the future, we can use ElementInternals.states to
|
|
452
|
+
// create a similar mapping, but instead of [data-invalid] it will look like :--invalid.
|
|
453
|
+
host.toggleAttribute('data-required', required);
|
|
454
|
+
host.toggleAttribute('data-optional', !required);
|
|
455
|
+
host.toggleAttribute('data-invalid', !isValid);
|
|
456
|
+
host.toggleAttribute('data-valid', isValid);
|
|
457
|
+
host.toggleAttribute('data-user-invalid', !isValid && hasInteracted);
|
|
458
|
+
host.toggleAttribute('data-user-valid', isValid && hasInteracted);
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Updates the form control's validity based on the current value of `host.validity.valid`. Call this when anything
|
|
463
|
+
* that affects constraint validation changes so the component receives the correct validity states.
|
|
464
|
+
*/
|
|
465
|
+
updateValidity() {
|
|
466
|
+
const host = this.host;
|
|
467
|
+
this.setValidity(host.validity?.valid);
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
/**
|
|
471
|
+
* Dispatches a non-bubbling, cancelable custom event of type `zn-invalid`.
|
|
472
|
+
* If the `zm-invalid` event will be cancelled then the original `invalid`
|
|
473
|
+
* event (which may have been passed as argument) will also be cancelled.
|
|
474
|
+
* If no original `invalid` event has been passed then the `zn-invalid`
|
|
475
|
+
* event will be cancelled before being dispatched.
|
|
476
|
+
*/
|
|
477
|
+
emitInvalidEvent(originalInvalidEvent?: Event) {
|
|
478
|
+
const znInvalidEvent = new CustomEvent<Record<PropertyKey, never>>('zn-invalid', {
|
|
479
|
+
bubbles: false,
|
|
480
|
+
composed: false,
|
|
481
|
+
cancelable: true,
|
|
482
|
+
detail: {}
|
|
483
|
+
});
|
|
484
|
+
|
|
485
|
+
if (!originalInvalidEvent) {
|
|
486
|
+
znInvalidEvent.preventDefault();
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
if (!this.host.dispatchEvent(znInvalidEvent)) {
|
|
490
|
+
originalInvalidEvent?.preventDefault();
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/*
|
|
496
|
+
* Predefined common validity states.
|
|
497
|
+
* All of them are read-only.
|
|
498
|
+
*/
|
|
499
|
+
|
|
500
|
+
// A validity state object that represents `valid`
|
|
501
|
+
export const validValidityState: ValidityState = Object.freeze({
|
|
502
|
+
badInput: false,
|
|
503
|
+
customError: false,
|
|
504
|
+
patternMismatch: false,
|
|
505
|
+
rangeOverflow: false,
|
|
506
|
+
rangeUnderflow: false,
|
|
507
|
+
stepMismatch: false,
|
|
508
|
+
tooLong: false,
|
|
509
|
+
tooShort: false,
|
|
510
|
+
typeMismatch: false,
|
|
511
|
+
valid: true,
|
|
512
|
+
valueMissing: false
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
// A validity state object that represents `value missing`
|
|
516
|
+
export const customErrorValidityState: ValidityState = Object.freeze({
|
|
517
|
+
...validValidityState,
|
|
518
|
+
customError: true,
|
|
519
|
+
valid: false
|
|
520
|
+
});
|
|
521
|
+
|
|
522
|
+
// A validity state object that represents a custom error
|
|
523
|
+
export const valueMissingValidityState: ValidityState = Object.freeze({
|
|
524
|
+
...validValidityState,
|
|
525
|
+
valueMissing: true,
|
|
526
|
+
valid: false
|
|
527
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Returns an element's offset relative to its parent. Similar to element.offsetTop and element.offsetLeft, except the
|
|
3
|
+
* parent doesn't have to be positioned relative or absolute.
|
|
4
|
+
*
|
|
5
|
+
* NOTE: This was created to work around what appears to be a bug in Chrome where a slotted element's offsetParent seems
|
|
6
|
+
* to ignore elements inside the surrounding shadow DOM: https://bugs.chromium.org/p/chromium/issues/detail?id=920069
|
|
7
|
+
*/
|
|
8
|
+
export function getOffset(element: HTMLElement, parent: HTMLElement) {
|
|
9
|
+
return {
|
|
10
|
+
top: Math.round(element.getBoundingClientRect().top - parent.getBoundingClientRect().top),
|
|
11
|
+
left: Math.round(element.getBoundingClientRect().left - parent.getBoundingClientRect().left)
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { getOffset } from './offset.js';
|
|
2
|
+
|
|
3
|
+
const locks = new Set();
|
|
4
|
+
|
|
5
|
+
/** Returns the width of the document's scrollbar */
|
|
6
|
+
function getScrollbarWidth() {
|
|
7
|
+
const documentWidth = document.documentElement.clientWidth;
|
|
8
|
+
return Math.abs(window.innerWidth - documentWidth);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Prevents body scrolling. Keeps track of which elements requested a lock so multiple levels of locking are possible
|
|
13
|
+
* without premature unlocking.
|
|
14
|
+
*/
|
|
15
|
+
export function lockBodyScrolling(lockingEl: HTMLElement) {
|
|
16
|
+
locks.add(lockingEl);
|
|
17
|
+
|
|
18
|
+
// When the first lock is created, set the scroll lock size to match the scrollbar's width to prevent content from
|
|
19
|
+
// shifting. We only do this on the first lock because the scrollbar width will measure zero after overflow is hidden.
|
|
20
|
+
if (!document.body.classList.contains('zn-scroll-lock')) {
|
|
21
|
+
const scrollbarWidth = getScrollbarWidth(); // must be measured before the `zn-scroll-lock` class is applied
|
|
22
|
+
document.body.classList.add('zn-scroll-lock');
|
|
23
|
+
document.body.style.setProperty('--zn-scroll-lock-size', `${scrollbarWidth}px`);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Unlocks body scrolling. Scrolling will only be unlocked once all elements that requested a lock call this method.
|
|
29
|
+
*/
|
|
30
|
+
export function unlockBodyScrolling(lockingEl: HTMLElement) {
|
|
31
|
+
locks.delete(lockingEl);
|
|
32
|
+
|
|
33
|
+
if (locks.size === 0) {
|
|
34
|
+
document.body.classList.remove('zn-scroll-lock');
|
|
35
|
+
document.body.style.removeProperty('--zn-scroll-lock-size');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Scrolls an element into view of its container. If the element is already in view, nothing will happen. */
|
|
40
|
+
export function scrollIntoView(
|
|
41
|
+
element: HTMLElement,
|
|
42
|
+
container: HTMLElement,
|
|
43
|
+
direction: 'horizontal' | 'vertical' | 'both' = 'vertical',
|
|
44
|
+
behavior: 'smooth' | 'auto' = 'smooth'
|
|
45
|
+
) {
|
|
46
|
+
const offset = getOffset(element, container);
|
|
47
|
+
const offsetTop = offset.top + container.scrollTop;
|
|
48
|
+
const offsetLeft = offset.left + container.scrollLeft;
|
|
49
|
+
const minX = container.scrollLeft;
|
|
50
|
+
const maxX = container.scrollLeft + container.offsetWidth;
|
|
51
|
+
const minY = container.scrollTop;
|
|
52
|
+
const maxY = container.scrollTop + container.offsetHeight;
|
|
53
|
+
|
|
54
|
+
if (direction === 'horizontal' || direction === 'both') {
|
|
55
|
+
if (offsetLeft < minX) {
|
|
56
|
+
container.scrollTo({ left: offsetLeft, behavior });
|
|
57
|
+
} else if (offsetLeft + element.clientWidth > maxX) {
|
|
58
|
+
container.scrollTo({ left: offsetLeft - container.offsetWidth + element.clientWidth, behavior });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
if (direction === 'vertical' || direction === 'both') {
|
|
63
|
+
if (offsetTop < minY) {
|
|
64
|
+
container.scrollTo({ top: offsetTop, behavior });
|
|
65
|
+
} else if (offsetTop + element.clientHeight > maxY) {
|
|
66
|
+
container.scrollTo({ top: offsetTop - container.offsetHeight + element.clientHeight, behavior });
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|