@nectary/components 2.9.0 → 2.10.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/accordion/index.d.ts +11 -0
- package/accordion/index.js +86 -0
- package/accordion/types.d.ts +21 -0
- package/accordion/types.js +1 -0
- package/accordion-item/index.d.ts +14 -0
- package/accordion-item/index.js +95 -0
- package/accordion-item/types.d.ts +36 -0
- package/accordion-item/types.js +1 -0
- package/accordion-item/utils.d.ts +2 -0
- package/accordion-item/utils.js +1 -0
- package/action-menu/index.d.ts +11 -0
- package/action-menu/index.js +195 -0
- package/action-menu/types.d.ts +13 -0
- package/action-menu/types.js +1 -0
- package/action-menu-option/index.d.ts +12 -0
- package/action-menu-option/index.js +82 -0
- package/action-menu-option/types.d.ts +23 -0
- package/action-menu-option/types.js +1 -0
- package/action-menu-option/utils.d.ts +2 -0
- package/action-menu-option/utils.js +3 -0
- package/alert/index.d.ts +14 -0
- package/alert/index.js +48 -0
- package/alert/types.d.ts +18 -0
- package/alert/types.js +1 -0
- package/alert/utils.d.ts +2 -0
- package/alert/utils.js +1 -0
- package/avatar/index.d.ts +11 -0
- package/avatar/index.js +94 -0
- package/avatar/types.d.ts +37 -0
- package/avatar/types.js +1 -0
- package/avatar/utils.d.ts +4 -0
- package/avatar/utils.js +7 -0
- package/badge/index.d.ts +11 -0
- package/badge/index.js +114 -0
- package/badge/types.d.ts +34 -0
- package/badge/types.js +1 -0
- package/badge/utils.d.ts +2 -0
- package/badge/utils.js +1 -0
- package/button/index.d.ts +11 -0
- package/button/index.js +182 -0
- package/button/types.d.ts +53 -0
- package/button/types.js +1 -0
- package/button/utils.d.ts +2 -0
- package/button/utils.js +1 -0
- package/card/index.d.ts +13 -0
- package/card/index.js +133 -0
- package/card/types.d.ts +28 -0
- package/card/types.js +1 -0
- package/card-container/index.d.ts +11 -0
- package/card-container/index.js +11 -0
- package/card-container/types.d.ts +3 -0
- package/card-container/types.js +1 -0
- package/chat/index.d.ts +11 -0
- package/chat/index.js +11 -0
- package/chat/types.d.ts +3 -0
- package/chat/types.js +1 -0
- package/chat-block/index.d.ts +11 -0
- package/chat-block/index.js +86 -0
- package/chat-block/types.d.ts +30 -0
- package/chat-block/types.js +1 -0
- package/chat-bubble/index.d.ts +11 -0
- package/chat-bubble/index.js +41 -0
- package/chat-bubble/types.d.ts +20 -0
- package/chat-bubble/types.js +1 -0
- package/chat-bubble/utils.d.ts +3 -0
- package/chat-bubble/utils.js +2 -0
- package/checkbox/index.d.ts +11 -0
- package/checkbox/index.js +126 -0
- package/checkbox/types.d.ts +49 -0
- package/checkbox/types.js +1 -0
- package/chip/index.d.ts +13 -0
- package/chip/index.js +144 -0
- package/chip/types.d.ts +37 -0
- package/chip/types.js +1 -0
- package/chip/utils.d.ts +2 -0
- package/chip/utils.js +6 -0
- package/code-tag/index.d.ts +11 -0
- package/code-tag/index.js +31 -0
- package/code-tag/types.d.ts +11 -0
- package/code-tag/types.js +1 -0
- package/color-menu/index.d.ts +11 -0
- package/color-menu/index.js +308 -0
- package/color-menu/types.d.ts +32 -0
- package/color-menu/types.js +1 -0
- package/color-menu/utils.d.ts +1 -0
- package/color-menu/utils.js +11 -0
- package/color-menu-option/index.d.ts +13 -0
- package/color-menu-option/index.js +48 -0
- package/color-menu-option/types.d.ts +11 -0
- package/color-menu-option/types.js +1 -0
- package/color-menu-option/utils.d.ts +1 -0
- package/color-menu-option/utils.js +11 -0
- package/color-swatch/index.d.ts +12 -0
- package/color-swatch/index.js +54 -0
- package/color-swatch/types.d.ts +11 -0
- package/color-swatch/types.js +1 -0
- package/color-swatch/utils.d.ts +2 -0
- package/color-swatch/utils.js +6 -0
- package/date-picker/index.d.ts +14 -0
- package/date-picker/index.js +381 -0
- package/date-picker/types.d.ts +70 -0
- package/date-picker/types.js +1 -0
- package/date-picker/utils.d.ts +28 -0
- package/date-picker/utils.js +142 -0
- package/dialog/index.d.ts +15 -0
- package/dialog/index.js +144 -0
- package/dialog/types.d.ts +28 -0
- package/dialog/types.js +1 -0
- package/dialog/utils.d.ts +2 -0
- package/dialog/utils.js +18 -0
- package/emoji/index.d.ts +11 -0
- package/emoji/index.js +46 -0
- package/emoji/types.d.ts +11 -0
- package/emoji/types.js +1 -0
- package/emoji/utils.d.ts +3 -0
- package/emoji/utils.js +47 -0
- package/emoji-picker/index.d.ts +22 -0
- package/emoji-picker/index.js +308 -0
- package/emoji-picker/types.d.ts +26 -0
- package/emoji-picker/types.js +1 -0
- package/field/index.d.ts +11 -0
- package/field/index.js +120 -0
- package/field/types.d.ts +35 -0
- package/field/types.js +1 -0
- package/file-drop/index.d.ts +13 -0
- package/file-drop/index.js +205 -0
- package/file-drop/types.d.ts +50 -0
- package/file-drop/types.js +1 -0
- package/file-drop/utils.d.ts +2 -0
- package/file-drop/utils.js +31 -0
- package/file-picker/index.d.ts +11 -0
- package/file-picker/index.js +103 -0
- package/file-picker/types.d.ts +32 -0
- package/file-picker/types.js +1 -0
- package/file-picker/utils.d.ts +1 -0
- package/file-picker/utils.js +8 -0
- package/file-status/index.d.ts +14 -0
- package/file-status/index.js +61 -0
- package/file-status/types.d.ts +18 -0
- package/file-status/types.js +1 -0
- package/file-status/utils.d.ts +2 -0
- package/file-status/utils.js +1 -0
- package/flag/index.d.ts +11 -0
- package/flag/index.js +46 -0
- package/flag/types.d.ts +11 -0
- package/flag/types.js +1 -0
- package/flag/utils.d.ts +1 -0
- package/flag/utils.js +17 -0
- package/grid/index.d.ts +11 -0
- package/grid/index.js +11 -0
- package/grid/types.d.ts +3 -0
- package/grid/types.js +1 -0
- package/grid-item/index.d.ts +11 -0
- package/grid-item/index.js +35 -0
- package/grid-item/types.d.ts +17 -0
- package/grid-item/types.js +1 -0
- package/help-tooltip/index.d.ts +13 -0
- package/help-tooltip/index.js +74 -0
- package/help-tooltip/types.d.ts +3 -0
- package/help-tooltip/types.js +1 -0
- package/horizontal-stepper/index.d.ts +11 -0
- package/horizontal-stepper/index.js +61 -0
- package/horizontal-stepper/types.d.ts +13 -0
- package/horizontal-stepper/types.js +1 -0
- package/horizontal-stepper-item/index.d.ts +14 -0
- package/horizontal-stepper-item/index.js +61 -0
- package/horizontal-stepper-item/types.d.ts +24 -0
- package/horizontal-stepper-item/types.js +1 -0
- package/horizontal-stepper-item/utils.d.ts +2 -0
- package/horizontal-stepper-item/utils.js +1 -0
- package/icon/index.d.ts +11 -0
- package/icon/index.js +32 -0
- package/icon/types.d.ts +11 -0
- package/icon/types.js +1 -0
- package/icon-button/index.d.ts +12 -0
- package/icon-button/index.js +175 -0
- package/icon-button/types.d.ts +44 -0
- package/icon-button/types.js +1 -0
- package/icon-button/utils.d.ts +2 -0
- package/icon-button/utils.js +1 -0
- package/inline-alert/index.d.ts +15 -0
- package/inline-alert/index.js +83 -0
- package/inline-alert/types.d.ts +15 -0
- package/inline-alert/types.js +1 -0
- package/inline-alert/utils.d.ts +2 -0
- package/inline-alert/utils.js +1 -0
- package/input/index.d.ts +11 -0
- package/input/index.js +642 -0
- package/input/types.d.ts +86 -0
- package/input/types.js +1 -0
- package/input/utils.d.ts +26 -0
- package/input/utils.js +302 -0
- package/link/index.d.ts +12 -0
- package/link/index.js +150 -0
- package/link/types.d.ts +59 -0
- package/link/types.js +1 -0
- package/list/index.d.ts +11 -0
- package/list/index.js +14 -0
- package/list/types.d.ts +3 -0
- package/list/types.js +1 -0
- package/list-item/index.d.ts +11 -0
- package/list-item/index.js +14 -0
- package/list-item/types.d.ts +3 -0
- package/list-item/types.js +1 -0
- package/package.json +1 -1
- package/pagination/index.d.ts +12 -0
- package/pagination/index.js +147 -0
- package/pagination/types.d.ts +16 -0
- package/pagination/types.js +1 -0
- package/pop/index.d.ts +11 -0
- package/pop/index.js +425 -0
- package/pop/types.d.ts +35 -0
- package/pop/types.js +1 -0
- package/pop/utils.d.ts +4 -0
- package/pop/utils.js +16 -0
- package/popover/index.d.ts +12 -0
- package/popover/index.js +146 -0
- package/popover/types.d.ts +38 -0
- package/popover/types.js +1 -0
- package/popover/utils.d.ts +4 -0
- package/popover/utils.js +10 -0
- package/progress/index.d.ts +12 -0
- package/progress/index.js +58 -0
- package/progress/types.d.ts +12 -0
- package/progress/types.js +1 -0
- package/progress-stepper/index.d.ts +11 -0
- package/progress-stepper/index.js +206 -0
- package/progress-stepper/types.d.ts +22 -0
- package/progress-stepper/types.js +1 -0
- package/progress-stepper-item/index.d.ts +12 -0
- package/progress-stepper-item/index.js +82 -0
- package/progress-stepper-item/types.d.ts +23 -0
- package/progress-stepper-item/types.js +1 -0
- package/progress-stepper-item/utils.d.ts +11 -0
- package/progress-stepper-item/utils.js +13 -0
- package/radio/index.d.ts +11 -0
- package/radio/index.js +154 -0
- package/radio/types.d.ts +14 -0
- package/radio/types.js +1 -0
- package/radio-option/index.d.ts +11 -0
- package/radio-option/index.js +79 -0
- package/radio-option/types.d.ts +18 -0
- package/radio-option/types.js +1 -0
- package/rich-text/index.d.ts +14 -0
- package/rich-text/index.js +75 -0
- package/rich-text/types.d.ts +12 -0
- package/rich-text/types.js +1 -0
- package/rich-text/utils.d.ts +7 -0
- package/rich-text/utils.js +107 -0
- package/rich-textarea/index.d.ts +11 -0
- package/rich-textarea/index.js +464 -0
- package/rich-textarea/types.d.ts +48 -0
- package/rich-textarea/types.js +1 -0
- package/rich-textarea/utils.d.ts +39 -0
- package/rich-textarea/utils.js +1730 -0
- package/segment/index.d.ts +12 -0
- package/segment/index.js +109 -0
- package/segment/types.d.ts +16 -0
- package/segment/types.js +1 -0
- package/segment/utils.d.ts +3 -0
- package/segment/utils.js +16 -0
- package/segment-collapse/index.d.ts +13 -0
- package/segment-collapse/index.js +60 -0
- package/segment-collapse/types.d.ts +11 -0
- package/segment-collapse/types.js +1 -0
- package/segmented-control/index.d.ts +11 -0
- package/segmented-control/index.js +85 -0
- package/segmented-control/types.d.ts +11 -0
- package/segmented-control/types.js +1 -0
- package/segmented-control-option/index.d.ts +11 -0
- package/segmented-control-option/index.js +95 -0
- package/segmented-control-option/types.d.ts +19 -0
- package/segmented-control-option/types.js +1 -0
- package/segmented-icon-control/index.d.ts +11 -0
- package/segmented-icon-control/index.js +101 -0
- package/segmented-icon-control/types.d.ts +14 -0
- package/segmented-icon-control/types.js +1 -0
- package/segmented-icon-control-option/index.d.ts +11 -0
- package/segmented-icon-control-option/index.js +82 -0
- package/segmented-icon-control-option/types.d.ts +16 -0
- package/segmented-icon-control-option/types.js +1 -0
- package/select-button/index.d.ts +13 -0
- package/select-button/index.js +202 -0
- package/select-button/types.d.ts +50 -0
- package/select-button/types.js +1 -0
- package/select-menu/index.d.ts +15 -0
- package/select-menu/index.js +339 -0
- package/select-menu/types.d.ts +41 -0
- package/select-menu/types.js +1 -0
- package/select-menu-option/index.d.ts +28 -0
- package/select-menu-option/index.js +65 -0
- package/select-menu-option/types.d.ts +26 -0
- package/select-menu-option/types.js +1 -0
- package/skeleton/index.d.ts +11 -0
- package/skeleton/index.js +108 -0
- package/skeleton/types.d.ts +9 -0
- package/skeleton/types.js +1 -0
- package/skeleton-item/index.d.ts +11 -0
- package/skeleton-item/index.js +11 -0
- package/skeleton-item/types.d.ts +13 -0
- package/skeleton-item/types.js +1 -0
- package/spinner/index.d.ts +11 -0
- package/spinner/index.js +58 -0
- package/spinner/types.d.ts +12 -0
- package/spinner/types.js +1 -0
- package/standalone.d.ts +85 -0
- package/standalone.js +87 -0
- package/stop-events/index.d.ts +1 -0
- package/stop-events/index.js +27 -0
- package/table/index.d.ts +11 -0
- package/table/index.js +14 -0
- package/table/types.d.ts +3 -0
- package/table/types.js +1 -0
- package/table-body/index.d.ts +11 -0
- package/table-body/index.js +14 -0
- package/table-body/types.d.ts +3 -0
- package/table-body/types.js +1 -0
- package/table-cell/index.d.ts +11 -0
- package/table-cell/index.js +21 -0
- package/table-cell/types.d.ts +9 -0
- package/table-cell/types.js +1 -0
- package/table-cell/utils.d.ts +2 -0
- package/table-cell/utils.js +1 -0
- package/table-head/index.d.ts +11 -0
- package/table-head/index.js +14 -0
- package/table-head/types.d.ts +3 -0
- package/table-head/types.js +1 -0
- package/table-head-cell/index.d.ts +12 -0
- package/table-head-cell/index.js +57 -0
- package/table-head-cell/types.d.ts +15 -0
- package/table-head-cell/types.js +1 -0
- package/table-row/index.d.ts +11 -0
- package/table-row/index.js +42 -0
- package/table-row/types.d.ts +11 -0
- package/table-row/types.js +1 -0
- package/tabs/index.d.ts +11 -0
- package/tabs/index.js +80 -0
- package/tabs/types.d.ts +18 -0
- package/tabs/types.js +1 -0
- package/tabs-icon-option/index.d.ts +11 -0
- package/tabs-icon-option/index.js +79 -0
- package/tabs-icon-option/types.d.ts +19 -0
- package/tabs-icon-option/types.js +1 -0
- package/tabs-option/index.d.ts +12 -0
- package/tabs-option/index.js +86 -0
- package/tabs-option/types.d.ts +25 -0
- package/tabs-option/types.js +1 -0
- package/tag/index.d.ts +12 -0
- package/tag/index.js +84 -0
- package/tag/types.d.ts +23 -0
- package/tag/types.js +1 -0
- package/tag/utils.d.ts +2 -0
- package/tag/utils.js +6 -0
- package/text/index.d.ts +11 -0
- package/text/index.js +64 -0
- package/text/types.d.ts +30 -0
- package/text/types.js +1 -0
- package/text/utils.d.ts +2 -0
- package/text/utils.js +1 -0
- package/textarea/index.d.ts +11 -0
- package/textarea/index.js +322 -0
- package/textarea/types.d.ts +60 -0
- package/textarea/types.js +1 -0
- package/tile-control/index.d.ts +11 -0
- package/tile-control/index.js +110 -0
- package/tile-control/types.d.ts +37 -0
- package/tile-control/types.js +1 -0
- package/tile-control-option/index.d.ts +11 -0
- package/tile-control-option/index.js +98 -0
- package/tile-control-option/types.d.ts +37 -0
- package/tile-control-option/types.js +1 -0
- package/time-picker/index.d.ts +15 -0
- package/time-picker/index.js +337 -0
- package/time-picker/types.d.ts +34 -0
- package/time-picker/types.js +1 -0
- package/time-picker/utils.d.ts +11 -0
- package/time-picker/utils.js +75 -0
- package/title/index.d.ts +11 -0
- package/title/index.js +60 -0
- package/title/types.d.ts +31 -0
- package/title/types.js +1 -0
- package/title/utils.d.ts +3 -0
- package/title/utils.js +17 -0
- package/toast/index.d.ts +13 -0
- package/toast/index.js +86 -0
- package/toast/types.d.ts +28 -0
- package/toast/types.js +1 -0
- package/toast/utils.d.ts +2 -0
- package/toast/utils.js +1 -0
- package/toast-manager/index.d.ts +13 -0
- package/toast-manager/index.js +170 -0
- package/toast-manager/types.d.ts +13 -0
- package/toast-manager/types.js +1 -0
- package/toast-manager/utils.d.ts +2 -0
- package/toast-manager/utils.js +1 -0
- package/toggle/index.d.ts +11 -0
- package/toggle/index.js +141 -0
- package/toggle/types.d.ts +23 -0
- package/toggle/types.js +1 -0
- package/tooltip/index.d.ts +13 -0
- package/tooltip/index.js +275 -0
- package/tooltip/tooltip-state.d.ts +19 -0
- package/tooltip/tooltip-state.js +126 -0
- package/tooltip/types.d.ts +42 -0
- package/tooltip/types.js +1 -0
- package/tooltip/utils.d.ts +6 -0
- package/tooltip/utils.js +18 -0
- package/utils/context.d.ts +20 -0
- package/utils/context.js +84 -0
- package/utils/countries.d.ts +6 -0
- package/utils/countries.js +2 -0
- package/utils/csv.d.ts +5 -0
- package/utils/csv.js +22 -0
- package/utils/debounce.d.ts +8 -0
- package/utils/debounce.js +22 -0
- package/utils/dom.d.ts +34 -0
- package/utils/dom.js +154 -0
- package/utils/element.d.ts +16 -0
- package/utils/element.js +48 -0
- package/utils/event-target.d.ts +4 -0
- package/utils/event-target.js +26 -0
- package/utils/get-react-event-handler.d.ts +1 -0
- package/utils/get-react-event-handler.js +8 -0
- package/utils/index.d.ts +12 -0
- package/utils/index.js +12 -0
- package/utils/markdown.d.ts +19 -0
- package/utils/markdown.js +143 -0
- package/utils/rect.d.ts +4 -0
- package/utils/rect.js +28 -0
- package/utils/size.d.ts +5 -0
- package/utils/size.js +3 -0
- package/utils/slot.d.ts +4 -0
- package/utils/slot.js +38 -0
- package/utils/throttle.d.ts +4 -0
- package/utils/throttle.js +20 -0
- package/utils/uid.d.ts +1 -0
- package/utils/uid.js +13 -0
- package/vertical-stepper/index.d.ts +11 -0
- package/vertical-stepper/index.js +57 -0
- package/vertical-stepper/types.d.ts +13 -0
- package/vertical-stepper/types.js +1 -0
- package/vertical-stepper-item/index.d.ts +14 -0
- package/vertical-stepper-item/index.js +61 -0
- package/vertical-stepper-item/types.d.ts +24 -0
- package/vertical-stepper-item/types.js +1 -0
- package/vertical-stepper-item/utils.d.ts +2 -0
- package/vertical-stepper-item/utils.js +1 -0
package/tooltip/index.js
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
import '../text';
|
|
2
|
+
import '../pop';
|
|
3
|
+
import { defineCustomElement, getAttribute, getLiteralAttribute, updateBooleanAttribute, updateAttribute, updateLiteralAttribute, NectaryElement, setClass, rectOverlap, getReactEventHandler, shouldReduceMotion } from '../utils';
|
|
4
|
+
const templateHTML = '<style>:host{display:contents}#content-wrapper{padding-bottom:8px;filter:drop-shadow(var(--sinch-comp-tooltip-shadow))}:host([orientation=left]) #content-wrapper{padding-bottom:0;padding-right:8px}:host([orientation=right]) #content-wrapper{padding-bottom:0;padding-left:8px}:host([orientation^=bottom]) #content-wrapper{padding-bottom:0;padding-top:8px}#content{position:relative;display:block;max-width:300px;padding:2px 6px;box-sizing:border-box;background-color:var(--sinch-local-color-background);border-radius:var(--sinch-comp-tooltip-shape-radius);pointer-events:none;opacity:0;--sinch-local-color-background:var(--sinch-comp-tooltip-color-background);--sinch-global-color-text:var(--sinch-comp-tooltip-color-text)}#text{word-break:break-word;pointer-events:none;--sinch-comp-text-font:var(--sinch-comp-tooltip-font-body)}#tip{position:absolute;left:50%;top:100%;transform:translateX(-50%) rotate(0);transform-origin:top center;fill:var(--sinch-local-color-background);pointer-events:none}#tip.hidden{display:none}:host([orientation=left]) #tip{transform:translateX(-50%) rotate(270deg);top:50%;left:100%}:host([orientation=right]) #tip{transform:translateX(-50%) rotate(90deg);top:50%;left:0}:host([orientation^=bottom]) #tip{transform:translateX(-50%) rotate(180deg);top:0}:host([text-align=right]) #text{--sinch-comp-text-align:right}:host([text-align=center]) #text{--sinch-comp-text-align:center}:host([text-align=left]) #text{--sinch-comp-text-align:left}</style><sinch-pop id="pop"><slot id="target" slot="target"></slot><div id="content-wrapper" slot="content"><div id="content"><sinch-text id="text" type="s"></sinch-text><svg id="tip" width="8" height="4" aria-hidden="true"><path d="m4 4 4-4h-8l4 4Z"/></svg></div></div></sinch-pop>';
|
|
5
|
+
import { TooltipState } from './tooltip-state';
|
|
6
|
+
import { getPopOrientation, orientationValues, textAlignValues, typeValues } from './utils';
|
|
7
|
+
const TIP_SIZE = 8;
|
|
8
|
+
const SHOW_DELAY_SLOW = 1000;
|
|
9
|
+
const SHOW_DELAY_FAST = 250;
|
|
10
|
+
const HIDE_DELAY = 0;
|
|
11
|
+
const ANIMATION_DURATION = 100;
|
|
12
|
+
const template = document.createElement('template');
|
|
13
|
+
template.innerHTML = templateHTML;
|
|
14
|
+
defineCustomElement('sinch-tooltip', class extends NectaryElement {
|
|
15
|
+
#$pop;
|
|
16
|
+
#$tooltipText;
|
|
17
|
+
#$content;
|
|
18
|
+
#$contentWrapper;
|
|
19
|
+
#$tip;
|
|
20
|
+
#$target;
|
|
21
|
+
#controller = null;
|
|
22
|
+
#tooltipState;
|
|
23
|
+
#animation = null;
|
|
24
|
+
#shouldReduceMotion = false;
|
|
25
|
+
#isSubscribed = false;
|
|
26
|
+
constructor() {
|
|
27
|
+
super();
|
|
28
|
+
const shadowRoot = this.attachShadow();
|
|
29
|
+
shadowRoot.appendChild(template.content.cloneNode(true));
|
|
30
|
+
this.#$pop = shadowRoot.querySelector('#pop');
|
|
31
|
+
this.#$tooltipText = shadowRoot.querySelector('#text');
|
|
32
|
+
this.#$content = shadowRoot.querySelector('#content');
|
|
33
|
+
this.#$contentWrapper = shadowRoot.querySelector('#content-wrapper');
|
|
34
|
+
this.#$tip = shadowRoot.querySelector('#tip');
|
|
35
|
+
this.#$target = shadowRoot.querySelector('#target');
|
|
36
|
+
this.#shouldReduceMotion = shouldReduceMotion();
|
|
37
|
+
this.#tooltipState = new TooltipState({
|
|
38
|
+
showDelay: SHOW_DELAY_SLOW,
|
|
39
|
+
hideDelay: this.#shouldReduceMotion ? HIDE_DELAY + ANIMATION_DURATION : HIDE_DELAY,
|
|
40
|
+
hideAnimationDuration: this.#shouldReduceMotion ? 0 : ANIMATION_DURATION,
|
|
41
|
+
onShowStart: this.#onStateShowStart,
|
|
42
|
+
onShowEnd: this.#onStateShowEnd,
|
|
43
|
+
onHideStart: this.#onStateHideStart,
|
|
44
|
+
onHideEnd: this.#onStateHideEnd
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
connectedCallback() {
|
|
48
|
+
super.connectedCallback();
|
|
49
|
+
this.#controller = new AbortController();
|
|
50
|
+
const options = {
|
|
51
|
+
signal: this.#controller.signal
|
|
52
|
+
};
|
|
53
|
+
this.#$pop.addEventListener('-close', this.#onPopClose, options);
|
|
54
|
+
this.addEventListener('-show', this.#onShowReactHandler, options);
|
|
55
|
+
this.addEventListener('-hide', this.#onHideReactHandler, options);
|
|
56
|
+
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
57
|
+
this.#updateText();
|
|
58
|
+
}
|
|
59
|
+
disconnectedCallback() {
|
|
60
|
+
super.disconnectedCallback();
|
|
61
|
+
this.#tooltipState.destroy();
|
|
62
|
+
this.#controller.abort();
|
|
63
|
+
this.#controller = null;
|
|
64
|
+
}
|
|
65
|
+
static get observedAttributes() {
|
|
66
|
+
return ['text', 'orientation', 'text-align', 'type', 'aria-label', 'aria-description'];
|
|
67
|
+
}
|
|
68
|
+
attributeChangedCallback(name, _, newVal) {
|
|
69
|
+
switch (name) {
|
|
70
|
+
case 'text':
|
|
71
|
+
{
|
|
72
|
+
this.#updateText();
|
|
73
|
+
break;
|
|
74
|
+
}
|
|
75
|
+
case 'orientation':
|
|
76
|
+
{
|
|
77
|
+
updateAttribute(this.#$pop, 'orientation', getPopOrientation(this.orientation));
|
|
78
|
+
if (this.#isOpen()) {
|
|
79
|
+
this.#resetTipOrientation();
|
|
80
|
+
this.#updateTipOrientation();
|
|
81
|
+
}
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
case 'text-align':
|
|
85
|
+
{
|
|
86
|
+
updateAttribute(this.#$pop, 'text-align', newVal);
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
case 'type':
|
|
90
|
+
{
|
|
91
|
+
this.#tooltipState.updateOptions({
|
|
92
|
+
showDelay: newVal === 'fast' ? SHOW_DELAY_FAST : SHOW_DELAY_SLOW
|
|
93
|
+
});
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
case 'aria-label':
|
|
97
|
+
case 'aria-description':
|
|
98
|
+
{
|
|
99
|
+
updateAttribute(this.#$pop, name, newVal);
|
|
100
|
+
break;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
get text() {
|
|
105
|
+
return getAttribute(this, 'text', '');
|
|
106
|
+
}
|
|
107
|
+
set text(value) {
|
|
108
|
+
updateAttribute(this, 'text', value);
|
|
109
|
+
}
|
|
110
|
+
get orientation() {
|
|
111
|
+
return getLiteralAttribute(this, orientationValues, 'orientation', 'top');
|
|
112
|
+
}
|
|
113
|
+
set orientation(value) {
|
|
114
|
+
updateLiteralAttribute(this, orientationValues, 'orientation', value);
|
|
115
|
+
}
|
|
116
|
+
get 'text-align'() {
|
|
117
|
+
return getLiteralAttribute(this, textAlignValues, 'text-align', 'left');
|
|
118
|
+
}
|
|
119
|
+
set 'text-align'(value) {
|
|
120
|
+
updateLiteralAttribute(this, textAlignValues, 'text-align', value);
|
|
121
|
+
}
|
|
122
|
+
get type() {
|
|
123
|
+
return getLiteralAttribute(this, typeValues, 'type', 'slow');
|
|
124
|
+
}
|
|
125
|
+
set type(value) {
|
|
126
|
+
updateLiteralAttribute(this, typeValues, 'type', value);
|
|
127
|
+
}
|
|
128
|
+
get footprintRect() {
|
|
129
|
+
return this.#$pop.footprintRect;
|
|
130
|
+
}
|
|
131
|
+
get tooltipRect() {
|
|
132
|
+
return this.#$pop.popoverRect;
|
|
133
|
+
}
|
|
134
|
+
#onMouseDown = () => {
|
|
135
|
+
this.#tooltipState.destroy();
|
|
136
|
+
};
|
|
137
|
+
#onPopClose = () => {
|
|
138
|
+
this.#tooltipState.destroy();
|
|
139
|
+
};
|
|
140
|
+
#onMouseEnter = () => {
|
|
141
|
+
this.#tooltipState.show();
|
|
142
|
+
};
|
|
143
|
+
#onMouseLeave = e => {
|
|
144
|
+
if (!this.#isOpen() || e.relatedTarget !== this.#$contentWrapper && e.relatedTarget !== this.#$target) {
|
|
145
|
+
this.#tooltipState.hide();
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
#onScroll = () => {
|
|
149
|
+
this.#tooltipState.destroy();
|
|
150
|
+
};
|
|
151
|
+
#onStateShowStart = () => {
|
|
152
|
+
this.#subscribeScroll();
|
|
153
|
+
this.#subscribeMouseLeaveEvents();
|
|
154
|
+
};
|
|
155
|
+
#onStateShowEnd = () => {
|
|
156
|
+
this.#dispatchShowEvent();
|
|
157
|
+
updateBooleanAttribute(this.#$pop, 'open', true);
|
|
158
|
+
requestAnimationFrame(this.#updateTipOrientation);
|
|
159
|
+
if (this.#animation !== null) {
|
|
160
|
+
this.#animation.updatePlaybackRate(1);
|
|
161
|
+
this.#animation.play();
|
|
162
|
+
} else {
|
|
163
|
+
this.#animation = this.#$content.animate({
|
|
164
|
+
opacity: [0, 1]
|
|
165
|
+
}, {
|
|
166
|
+
duration: this.#shouldReduceMotion ? 0 : ANIMATION_DURATION,
|
|
167
|
+
iterations: 1,
|
|
168
|
+
fill: 'forwards'
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
#onStateHideStart = () => {
|
|
173
|
+
this.#animation.updatePlaybackRate(-1);
|
|
174
|
+
this.#animation.play();
|
|
175
|
+
};
|
|
176
|
+
#onStateHideEnd = () => {
|
|
177
|
+
if (this.#isOpen()) {
|
|
178
|
+
this.#animation.finish();
|
|
179
|
+
this.#dispatchHideEvent();
|
|
180
|
+
updateBooleanAttribute(this.#$pop, 'open', false);
|
|
181
|
+
}
|
|
182
|
+
this.#resetTipOrientation();
|
|
183
|
+
this.#unsubscribeMouseLeaveEvents();
|
|
184
|
+
this.#unsubscribeScroll();
|
|
185
|
+
};
|
|
186
|
+
#resetTipOrientation() {
|
|
187
|
+
this.#$tip.style.top = '';
|
|
188
|
+
this.#$tip.style.left = '';
|
|
189
|
+
}
|
|
190
|
+
#updateTipOrientation = () => {
|
|
191
|
+
const orient = this.orientation;
|
|
192
|
+
const targetRect = this.#$pop.footprintRect;
|
|
193
|
+
const contentRect = this.#$content.getBoundingClientRect();
|
|
194
|
+
const diffX = targetRect.x - contentRect.x;
|
|
195
|
+
const diffY = targetRect.y - contentRect.y;
|
|
196
|
+
if (orient === 'left' || orient === 'right') {
|
|
197
|
+
const yPos = Math.max(TIP_SIZE, Math.min(diffY + targetRect.height / 2, contentRect.height - TIP_SIZE));
|
|
198
|
+
this.#$tip.style.top = `${yPos}px`;
|
|
199
|
+
} else {
|
|
200
|
+
let xPos = Math.max(TIP_SIZE, Math.min(diffX + targetRect.width / 2, contentRect.width - TIP_SIZE));
|
|
201
|
+
if (orient === 'bottom-left' || orient === 'top-left') {
|
|
202
|
+
xPos = Math.max(xPos, contentRect.width * 0.75);
|
|
203
|
+
}
|
|
204
|
+
if (orient === 'bottom-right' || orient === 'top-right') {
|
|
205
|
+
xPos = Math.min(xPos, contentRect.width * 0.25);
|
|
206
|
+
}
|
|
207
|
+
this.#$tip.style.left = `${xPos}px`;
|
|
208
|
+
}
|
|
209
|
+
setClass(this.#$tip, 'hidden', rectOverlap(targetRect, contentRect));
|
|
210
|
+
};
|
|
211
|
+
#updateText() {
|
|
212
|
+
if (!this.isDomConnected) {
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
const text = this.text;
|
|
216
|
+
this.#$tooltipText.textContent = text;
|
|
217
|
+
if (text.length === 0) {
|
|
218
|
+
if (this.#isSubscribed) {
|
|
219
|
+
this.#tooltipState.destroy();
|
|
220
|
+
this.#unsubscribeMouseEnterEvent();
|
|
221
|
+
}
|
|
222
|
+
} else {
|
|
223
|
+
this.#subscribeMouseEnterEvent();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
#subscribeMouseEnterEvent() {
|
|
227
|
+
if (!this.isDomConnected || this.#isSubscribed) {
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
this.#$target.addEventListener('mouseenter', this.#onMouseEnter, {
|
|
231
|
+
signal: this.#controller.signal
|
|
232
|
+
});
|
|
233
|
+
this.#isSubscribed = true;
|
|
234
|
+
}
|
|
235
|
+
#unsubscribeMouseEnterEvent() {
|
|
236
|
+
this.#$target.removeEventListener('mouseenter', this.#onMouseEnter);
|
|
237
|
+
this.#isSubscribed = false;
|
|
238
|
+
}
|
|
239
|
+
#subscribeMouseLeaveEvents() {
|
|
240
|
+
const options = {
|
|
241
|
+
signal: this.#controller.signal
|
|
242
|
+
};
|
|
243
|
+
this.#$target.addEventListener('mousedown', this.#onMouseDown, options);
|
|
244
|
+
this.#$target.addEventListener('mouseleave', this.#onMouseLeave, options);
|
|
245
|
+
this.#$contentWrapper.addEventListener('mouseenter', this.#onMouseEnter, options);
|
|
246
|
+
this.#$contentWrapper.addEventListener('mouseleave', this.#onMouseLeave, options);
|
|
247
|
+
}
|
|
248
|
+
#unsubscribeMouseLeaveEvents() {
|
|
249
|
+
this.#$target.removeEventListener('mousedown', this.#onMouseDown);
|
|
250
|
+
this.#$target.removeEventListener('mouseleave', this.#onMouseLeave);
|
|
251
|
+
this.#$contentWrapper.removeEventListener('mouseenter', this.#onMouseEnter);
|
|
252
|
+
this.#$contentWrapper.removeEventListener('mouseleave', this.#onMouseLeave);
|
|
253
|
+
}
|
|
254
|
+
#subscribeScroll() {
|
|
255
|
+
window.addEventListener('wheel', this.#onScroll, true);
|
|
256
|
+
}
|
|
257
|
+
#unsubscribeScroll() {
|
|
258
|
+
window.removeEventListener('wheel', this.#onScroll, true);
|
|
259
|
+
}
|
|
260
|
+
#isOpen() {
|
|
261
|
+
return this.#$pop.hasAttribute('open');
|
|
262
|
+
}
|
|
263
|
+
#dispatchShowEvent() {
|
|
264
|
+
this.dispatchEvent(new CustomEvent('-show'));
|
|
265
|
+
}
|
|
266
|
+
#dispatchHideEvent() {
|
|
267
|
+
this.dispatchEvent(new CustomEvent('-hide'));
|
|
268
|
+
}
|
|
269
|
+
#onShowReactHandler = () => {
|
|
270
|
+
getReactEventHandler(this, 'on-show')?.();
|
|
271
|
+
};
|
|
272
|
+
#onHideReactHandler = () => {
|
|
273
|
+
getReactEventHandler(this, 'on-hide')?.();
|
|
274
|
+
};
|
|
275
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
type TTooltipStateOptions = {
|
|
2
|
+
showDelay: number;
|
|
3
|
+
hideDelay: number;
|
|
4
|
+
hideAnimationDuration: number;
|
|
5
|
+
onShowStart(): void;
|
|
6
|
+
onShowEnd(): void;
|
|
7
|
+
onHideStart(): void;
|
|
8
|
+
onHideEnd(): void;
|
|
9
|
+
};
|
|
10
|
+
export declare class TooltipState {
|
|
11
|
+
#private;
|
|
12
|
+
constructor(options: TTooltipStateOptions);
|
|
13
|
+
updateOptions(options: Partial<TTooltipStateOptions>): void;
|
|
14
|
+
show(): void;
|
|
15
|
+
hide(): void;
|
|
16
|
+
interrupt(): void;
|
|
17
|
+
destroy(): void;
|
|
18
|
+
}
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
export class TooltipState {
|
|
2
|
+
#timerId = null;
|
|
3
|
+
#state = 'hide';
|
|
4
|
+
#options;
|
|
5
|
+
constructor(options) {
|
|
6
|
+
this.#options = options;
|
|
7
|
+
}
|
|
8
|
+
updateOptions(options) {
|
|
9
|
+
this.#options = {
|
|
10
|
+
...this.#options,
|
|
11
|
+
...options
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
show() {
|
|
15
|
+
switch (this.#state) {
|
|
16
|
+
case 'hide':
|
|
17
|
+
{
|
|
18
|
+
this.#switchToHideToShow();
|
|
19
|
+
break;
|
|
20
|
+
}
|
|
21
|
+
case 'show-to-hide':
|
|
22
|
+
{
|
|
23
|
+
this.#switchToState('show');
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
hide() {
|
|
29
|
+
switch (this.#state) {
|
|
30
|
+
case 'hide-to-show':
|
|
31
|
+
{
|
|
32
|
+
this.#onHideAnimationEnd();
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
case 'show':
|
|
36
|
+
{
|
|
37
|
+
this.#switchToShowToHide();
|
|
38
|
+
break;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
interrupt() {
|
|
43
|
+
switch (this.#state) {
|
|
44
|
+
case 'hide-to-show':
|
|
45
|
+
{
|
|
46
|
+
this.#onHideAnimationEnd();
|
|
47
|
+
break;
|
|
48
|
+
}
|
|
49
|
+
case 'show':
|
|
50
|
+
{
|
|
51
|
+
this.#switchToShowToHide(true, false);
|
|
52
|
+
break;
|
|
53
|
+
}
|
|
54
|
+
case 'show-to-hide':
|
|
55
|
+
{
|
|
56
|
+
this.#switchToShowToHide(true, false);
|
|
57
|
+
break;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
destroy() {
|
|
62
|
+
switch (this.#state) {
|
|
63
|
+
case 'hide-to-show':
|
|
64
|
+
{
|
|
65
|
+
this.#onHideAnimationEnd();
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
case 'show':
|
|
69
|
+
{
|
|
70
|
+
this.#switchToShowToHide(true, true);
|
|
71
|
+
break;
|
|
72
|
+
}
|
|
73
|
+
case 'show-to-hide':
|
|
74
|
+
{
|
|
75
|
+
this.#switchToShowToHide(true, true);
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
case 'hide':
|
|
79
|
+
{
|
|
80
|
+
this.#onHideAnimationEnd();
|
|
81
|
+
break;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
#switchToHideToShow() {
|
|
86
|
+
this.#switchToState('hide-to-show');
|
|
87
|
+
this.#options.onShowStart();
|
|
88
|
+
if (this.#options.showDelay === 0) {
|
|
89
|
+
this.#onSwitchToShow();
|
|
90
|
+
} else {
|
|
91
|
+
this.#timerId = window.setTimeout(this.#onSwitchToShow, this.#options.showDelay);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
#switchToShowToHide(skipDelay, skipHideAnimation) {
|
|
95
|
+
this.#switchToState('show-to-hide');
|
|
96
|
+
if (skipDelay === true || this.#options.hideDelay === 0) {
|
|
97
|
+
this.#onShowToHideEnd(skipHideAnimation);
|
|
98
|
+
} else {
|
|
99
|
+
this.#timerId = window.setTimeout(this.#onShowToHideEnd, this.#options.hideDelay);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
#onSwitchToShow = () => {
|
|
103
|
+
this.#switchToState('show');
|
|
104
|
+
this.#options.onShowEnd();
|
|
105
|
+
};
|
|
106
|
+
#onShowToHideEnd = skipHideAnimation => {
|
|
107
|
+
this.#switchToState('hide');
|
|
108
|
+
this.#options.onHideStart();
|
|
109
|
+
if (skipHideAnimation === true || this.#options.hideAnimationDuration === 0) {
|
|
110
|
+
this.#onHideAnimationEnd();
|
|
111
|
+
} else {
|
|
112
|
+
this.#timerId = window.setTimeout(this.#onHideAnimationEnd, this.#options.hideAnimationDuration);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
#onHideAnimationEnd = () => {
|
|
116
|
+
this.#switchToState('hide');
|
|
117
|
+
this.#options.onHideEnd();
|
|
118
|
+
};
|
|
119
|
+
#switchToState(nextState) {
|
|
120
|
+
this.#state = nextState;
|
|
121
|
+
if (this.#timerId !== null) {
|
|
122
|
+
clearTimeout(this.#timerId);
|
|
123
|
+
this.#timerId = null;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import type { TRect, TSinchElementReact } from '../types';
|
|
2
|
+
export type TSinchTooltipOrientation = 'top' | 'bottom' | 'left' | 'right' | 'top-left' | 'top-right' | 'bottom-left' | 'bottom-right';
|
|
3
|
+
export type TSinchTooltipTextAlign = 'center' | 'right' | 'left';
|
|
4
|
+
export type TSinchTooltipType = 'slow' | 'fast';
|
|
5
|
+
export type TSinchTooltipElement = HTMLElement & {
|
|
6
|
+
/** Text */
|
|
7
|
+
text: string;
|
|
8
|
+
/** Orientation, where it *points to* from origin */
|
|
9
|
+
orientation: TSinchTooltipOrientation;
|
|
10
|
+
/** Type */
|
|
11
|
+
type: TSinchTooltipType;
|
|
12
|
+
/** Text Align */
|
|
13
|
+
'text-align': TSinchTooltipTextAlign;
|
|
14
|
+
readonly footprintRect: TRect;
|
|
15
|
+
readonly tooltipRect: TRect;
|
|
16
|
+
/** Show event */
|
|
17
|
+
addEventListener(type: '-show', listener: (e: CustomEvent<void>) => void): void;
|
|
18
|
+
/** Hide event */
|
|
19
|
+
addEventListener(type: '-hide', listener: (e: CustomEvent<void>) => void): void;
|
|
20
|
+
/** Text */
|
|
21
|
+
setAttribute(name: 'text', value: string): void;
|
|
22
|
+
/** Orientation, where it *points to* from origin */
|
|
23
|
+
setAttribute(name: 'orientation', value: TSinchTooltipOrientation): void;
|
|
24
|
+
/** Type */
|
|
25
|
+
setAttribute(name: 'type', value: TSinchTooltipType): void;
|
|
26
|
+
/** Text Align */
|
|
27
|
+
setAttribute(name: 'text-align', value: TSinchTooltipTextAlign): void;
|
|
28
|
+
};
|
|
29
|
+
export type TSinchTooltipReact = TSinchElementReact<TSinchTooltipElement> & {
|
|
30
|
+
/** Text */
|
|
31
|
+
text: string;
|
|
32
|
+
/** Orientation, where it *points to* from origin */
|
|
33
|
+
orientation?: TSinchTooltipOrientation;
|
|
34
|
+
/** Type */
|
|
35
|
+
type?: TSinchTooltipType;
|
|
36
|
+
/** Text Align */
|
|
37
|
+
'text-align'?: TSinchTooltipTextAlign;
|
|
38
|
+
/** Show event handler */
|
|
39
|
+
'on-show'?: (e: CustomEvent<void>) => void;
|
|
40
|
+
/** Hide event handler */
|
|
41
|
+
'on-hide'?: (e: CustomEvent<void>) => void;
|
|
42
|
+
};
|
package/tooltip/types.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TSinchTooltipOrientation, TSinchTooltipType, TSinchTooltipTextAlign } from './types';
|
|
2
|
+
import type { TSinchPopOrientation } from '../pop/types';
|
|
3
|
+
export declare const typeValues: readonly TSinchTooltipType[];
|
|
4
|
+
export declare const orientationValues: readonly TSinchTooltipOrientation[];
|
|
5
|
+
export declare const textAlignValues: readonly TSinchTooltipTextAlign[];
|
|
6
|
+
export declare const getPopOrientation: (orientation: TSinchTooltipOrientation) => TSinchPopOrientation;
|
package/tooltip/utils.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export const typeValues = ['fast', 'slow'];
|
|
2
|
+
export const orientationValues = ['top', 'bottom', 'left', 'right', 'top-left', 'top-right', 'bottom-left', 'bottom-right'];
|
|
3
|
+
export const textAlignValues = ['right', 'center', 'left'];
|
|
4
|
+
export const getPopOrientation = orientation => {
|
|
5
|
+
if (orientation === 'top') {
|
|
6
|
+
return 'top-center';
|
|
7
|
+
}
|
|
8
|
+
if (orientation === 'bottom') {
|
|
9
|
+
return 'bottom-center';
|
|
10
|
+
}
|
|
11
|
+
if (orientation === 'left') {
|
|
12
|
+
return 'center-left';
|
|
13
|
+
}
|
|
14
|
+
if (orientation === 'right') {
|
|
15
|
+
return 'center-right';
|
|
16
|
+
}
|
|
17
|
+
return orientation;
|
|
18
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export type TContextName = 'visibility' | 'keydown' | 'size';
|
|
2
|
+
export type TContextKeydown = {
|
|
3
|
+
code: string;
|
|
4
|
+
preventDefault: () => void;
|
|
5
|
+
};
|
|
6
|
+
export type TContextVisibility = boolean;
|
|
7
|
+
export type TContextSize = string;
|
|
8
|
+
type TContextDataType = {
|
|
9
|
+
visibility: TContextVisibility;
|
|
10
|
+
keydown: TContextKeydown;
|
|
11
|
+
size: TContextSize;
|
|
12
|
+
};
|
|
13
|
+
export declare class Context<T extends TContextName> {
|
|
14
|
+
#private;
|
|
15
|
+
constructor($element: Element, name: T);
|
|
16
|
+
listen(signal: AbortSignal): void;
|
|
17
|
+
dispatch(contextValue: TContextDataType[T]): void;
|
|
18
|
+
}
|
|
19
|
+
export declare const subscribeContext: <T extends TContextName>($el: Element, name: T, cb: (e: CustomEvent<TContextDataType[T]>) => void, signal: AbortSignal) => void;
|
|
20
|
+
export {};
|
package/utils/context.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
const contextNameToEventMap = {
|
|
2
|
+
keydown: '-keydown',
|
|
3
|
+
visibility: '-visibility',
|
|
4
|
+
size: '-size'
|
|
5
|
+
};
|
|
6
|
+
const shouldPersistContextValue = {
|
|
7
|
+
keydown: false,
|
|
8
|
+
visibility: true,
|
|
9
|
+
size: true
|
|
10
|
+
};
|
|
11
|
+
export class Context {
|
|
12
|
+
#$root;
|
|
13
|
+
#listeners = new Set();
|
|
14
|
+
#name;
|
|
15
|
+
#isListening = false;
|
|
16
|
+
#lastContextValue = null;
|
|
17
|
+
constructor($element, name) {
|
|
18
|
+
this.#$root = $element;
|
|
19
|
+
this.#name = name;
|
|
20
|
+
}
|
|
21
|
+
listen(signal) {
|
|
22
|
+
if (this.#isListening) {
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
this.#$root.addEventListener(`-context-connect-${this.#name}`, this.#onListenerConnect, {
|
|
26
|
+
signal
|
|
27
|
+
});
|
|
28
|
+
this.#$root.addEventListener(`-context-disconnect-${this.#name}`, this.#onListenerDisconnect, {
|
|
29
|
+
signal
|
|
30
|
+
});
|
|
31
|
+
this.#isListening = true;
|
|
32
|
+
signal.addEventListener('abort', () => {
|
|
33
|
+
this.#listeners.clear();
|
|
34
|
+
this.#isListening = false;
|
|
35
|
+
this.#lastContextValue = null;
|
|
36
|
+
}, {
|
|
37
|
+
once: true
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
dispatch(contextValue) {
|
|
41
|
+
for (const el of this.#listeners) {
|
|
42
|
+
el.dispatchEvent(new CustomEvent(contextNameToEventMap[this.#name], {
|
|
43
|
+
detail: contextValue
|
|
44
|
+
}));
|
|
45
|
+
}
|
|
46
|
+
if (shouldPersistContextValue[this.#name]) {
|
|
47
|
+
this.#lastContextValue = contextValue;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
#onListenerConnect = e => {
|
|
51
|
+
e.stopPropagation();
|
|
52
|
+
this.#listeners.add(e.detail);
|
|
53
|
+
if (this.#lastContextValue !== null) {
|
|
54
|
+
e.detail.dispatchEvent(new CustomEvent(contextNameToEventMap[this.#name], {
|
|
55
|
+
detail: this.#lastContextValue
|
|
56
|
+
}));
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
#onListenerDisconnect = e => {
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
this.#listeners.delete(e.detail);
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
export const subscribeContext = ($el, name, cb, signal) => {
|
|
65
|
+
requestAnimationFrame(() => {
|
|
66
|
+
$el.dispatchEvent(new CustomEvent(`-context-connect-${name}`, {
|
|
67
|
+
bubbles: true,
|
|
68
|
+
composed: true,
|
|
69
|
+
detail: $el
|
|
70
|
+
}));
|
|
71
|
+
});
|
|
72
|
+
$el.addEventListener(contextNameToEventMap[name], cb, {
|
|
73
|
+
signal
|
|
74
|
+
});
|
|
75
|
+
signal.addEventListener('abort', () => {
|
|
76
|
+
$el.dispatchEvent(new CustomEvent(`-context-disconnect-${name}`, {
|
|
77
|
+
bubbles: true,
|
|
78
|
+
composed: true,
|
|
79
|
+
detail: $el
|
|
80
|
+
}));
|
|
81
|
+
}, {
|
|
82
|
+
once: true
|
|
83
|
+
});
|
|
84
|
+
};
|
package/utils/csv.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export declare const CSV_DELIMITER = ",";
|
|
2
|
+
export declare const packCsv: (values: string[]) => string;
|
|
3
|
+
export declare const unpackCsv: (csv: string) => string[];
|
|
4
|
+
export declare const updateCsv: (csv: string, value: string, setActive: boolean) => string;
|
|
5
|
+
export declare const getFirstCsvValue: (acc: string) => string | null;
|
package/utils/csv.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export const CSV_DELIMITER = ',';
|
|
2
|
+
export const packCsv = values => {
|
|
3
|
+
return values.join(CSV_DELIMITER);
|
|
4
|
+
};
|
|
5
|
+
export const unpackCsv = csv => {
|
|
6
|
+
return csv.length === 0 ? [] : csv.split(CSV_DELIMITER);
|
|
7
|
+
};
|
|
8
|
+
export const updateCsv = (csv, value, setActive) => {
|
|
9
|
+
const values = unpackCsv(csv);
|
|
10
|
+
const index = values.indexOf(value);
|
|
11
|
+
if (setActive) {
|
|
12
|
+
if (index < 0) {
|
|
13
|
+
values.push(value);
|
|
14
|
+
}
|
|
15
|
+
} else if (index >= 0) {
|
|
16
|
+
values.splice(index, 1);
|
|
17
|
+
}
|
|
18
|
+
return packCsv(values);
|
|
19
|
+
};
|
|
20
|
+
export const getFirstCsvValue = acc => {
|
|
21
|
+
return acc.length === 0 ? null : unpackCsv(acc)[0];
|
|
22
|
+
};
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const createDebounce = (delayFn, cancelFn) => cb => {
|
|
2
|
+
let id = null;
|
|
3
|
+
const delayCallback = () => {
|
|
4
|
+
id = null;
|
|
5
|
+
cb();
|
|
6
|
+
};
|
|
7
|
+
return {
|
|
8
|
+
fn: () => {
|
|
9
|
+
if (id !== null) {
|
|
10
|
+
cancelFn(id);
|
|
11
|
+
}
|
|
12
|
+
id = delayFn(delayCallback);
|
|
13
|
+
},
|
|
14
|
+
cancel: () => {
|
|
15
|
+
if (id !== null) {
|
|
16
|
+
cancelFn(id);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const debounceTimeout = ms => createDebounce(cb => globalThis.setTimeout(cb, ms), globalThis.clearTimeout);
|
|
22
|
+
export const debounceAnimationFrame = createDebounce(globalThis.requestAnimationFrame, globalThis.cancelAnimationFrame);
|