@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/utils/dom.d.ts
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const updateExplicitBooleanAttribute: ($element: Element, attrName: string, attrValue: boolean | null | undefined) => void;
|
|
2
|
+
export declare const isAttrTrue: (attrValue: string | null) => boolean;
|
|
3
|
+
export declare const getBooleanAttribute: ($element: Element, attrName: string) => boolean;
|
|
4
|
+
export declare const updateBooleanAttribute: ($element: Element, attrName: string, attrValue: boolean | null | undefined) => void;
|
|
5
|
+
export declare const updateAttribute: ($element: Element, attrName: string, attrValue: string | number | boolean | null | undefined) => void;
|
|
6
|
+
export declare function getAttribute($element: Element, attrName: string): string | null;
|
|
7
|
+
export declare function getAttribute($element: Element, attrName: string, defaultValue: string): string;
|
|
8
|
+
export declare const isLiteralValue: <T extends readonly string[]>(literals: T, value: string | null | undefined) => value is T[number];
|
|
9
|
+
export declare const updateLiteralAttribute: <T extends readonly string[]>($element: Element, literals: T, attrName: string, attrValue: string | null | undefined) => void;
|
|
10
|
+
export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string): T[number];
|
|
11
|
+
export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: null): T[number] | null;
|
|
12
|
+
export declare function getLiteralAttribute<T extends readonly string[]>($element: Element, literals: T, attrName: string, defaultValue: T[number]): T[number];
|
|
13
|
+
export declare const clampNumber: (value: number, min: number, max: number) => number;
|
|
14
|
+
type IntegerOptions = {
|
|
15
|
+
min?: number;
|
|
16
|
+
max?: number;
|
|
17
|
+
defaultValue?: number | null;
|
|
18
|
+
itemSizeMultiplier?: number;
|
|
19
|
+
itemSpaceBetween?: number;
|
|
20
|
+
};
|
|
21
|
+
export declare const attrValueToInteger: (value: string | null, options?: IntegerOptions) => number | null;
|
|
22
|
+
export declare const attrValueToPixels: (value: string | null, options?: IntegerOptions) => string;
|
|
23
|
+
export declare const updateIntegerAttribute: ($element: Element, attrName: string, attrValue: string | number | null | undefined, options?: IntegerOptions) => void;
|
|
24
|
+
export declare function getIntegerAttribute($element: Element, attrName: string): number | undefined;
|
|
25
|
+
export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: null): number | null;
|
|
26
|
+
export declare function getIntegerAttribute($element: Element, attrName: string, defaultValue: number): number;
|
|
27
|
+
export declare const setClass: (elem: Element, name: string, isSet: boolean) => void;
|
|
28
|
+
export declare const hasClass: (elem: Element, name: string) => boolean;
|
|
29
|
+
export declare const getCssVar: (element: Element, variableName: string) => string | null;
|
|
30
|
+
export declare const getCssVars: (element: Element, variableNames: string[]) => (string | null)[];
|
|
31
|
+
export declare const cloneNode: (el: Element, deep: boolean) => Element;
|
|
32
|
+
export declare const shouldReduceMotion: () => boolean;
|
|
33
|
+
export declare const isAttrEqual: (oldVal: string | null, newVal: string | null) => boolean;
|
|
34
|
+
export {};
|
package/utils/dom.js
ADDED
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
export const updateExplicitBooleanAttribute = ($element, attrName, attrValue) => {
|
|
2
|
+
$element.setAttribute(attrName, attrValue === true ? 'true' : 'false');
|
|
3
|
+
};
|
|
4
|
+
export const isAttrTrue = attrValue => {
|
|
5
|
+
return attrValue !== null && attrValue !== 'false';
|
|
6
|
+
};
|
|
7
|
+
export const getBooleanAttribute = ($element, attrName) => {
|
|
8
|
+
return isAttrTrue($element.getAttribute(attrName));
|
|
9
|
+
};
|
|
10
|
+
export const updateBooleanAttribute = ($element, attrName, attrValue) => {
|
|
11
|
+
const currentAttrValue = $element.getAttribute(attrName);
|
|
12
|
+
if (attrValue === true) {
|
|
13
|
+
if (!isAttrTrue(currentAttrValue)) {
|
|
14
|
+
$element.setAttribute(attrName, '');
|
|
15
|
+
}
|
|
16
|
+
} else if (currentAttrValue !== null) {
|
|
17
|
+
$element.removeAttribute(attrName);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
export const updateAttribute = ($element, attrName, attrValue) => {
|
|
21
|
+
if (attrValue != null) {
|
|
22
|
+
$element.setAttribute(attrName, String(attrValue));
|
|
23
|
+
} else {
|
|
24
|
+
$element.removeAttribute(attrName);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
export function getAttribute($element, attrName) {
|
|
28
|
+
let defaultValue = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
|
|
29
|
+
return $element.getAttribute(attrName) ?? defaultValue;
|
|
30
|
+
}
|
|
31
|
+
export const isLiteralValue = (literals, value) => {
|
|
32
|
+
return value != null && literals.includes(value);
|
|
33
|
+
};
|
|
34
|
+
export const updateLiteralAttribute = ($element, literals, attrName, attrValue) => {
|
|
35
|
+
if (isLiteralValue(literals, attrValue)) {
|
|
36
|
+
$element.setAttribute(attrName, attrValue);
|
|
37
|
+
} else {
|
|
38
|
+
$element.removeAttribute(attrName);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
export function getLiteralAttribute($element, literals, attrName, defaultValue) {
|
|
42
|
+
const attrValue = $element.getAttribute(attrName);
|
|
43
|
+
if (isLiteralValue(literals, attrValue)) {
|
|
44
|
+
return attrValue;
|
|
45
|
+
}
|
|
46
|
+
return defaultValue;
|
|
47
|
+
}
|
|
48
|
+
export const clampNumber = (value, min, max) => {
|
|
49
|
+
return Math.min(max, Math.max(min, value));
|
|
50
|
+
};
|
|
51
|
+
const DEFAULT_INTEGER_OPTIONS = {
|
|
52
|
+
itemSizeMultiplier: 1,
|
|
53
|
+
itemSpaceBetween: 0,
|
|
54
|
+
defaultValue: null
|
|
55
|
+
};
|
|
56
|
+
const applyRange = (value, _ref) => {
|
|
57
|
+
let {
|
|
58
|
+
min,
|
|
59
|
+
max
|
|
60
|
+
} = _ref;
|
|
61
|
+
let result = value;
|
|
62
|
+
if (min != null) {
|
|
63
|
+
result = Math.max(min, result);
|
|
64
|
+
}
|
|
65
|
+
if (max != null) {
|
|
66
|
+
result = Math.min(max, result);
|
|
67
|
+
}
|
|
68
|
+
return result;
|
|
69
|
+
};
|
|
70
|
+
export const attrValueToInteger = function (value) {
|
|
71
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
|
|
72
|
+
const {
|
|
73
|
+
defaultValue = null,
|
|
74
|
+
itemSizeMultiplier = 1,
|
|
75
|
+
itemSpaceBetween = 0
|
|
76
|
+
} = options;
|
|
77
|
+
let intValue = defaultValue;
|
|
78
|
+
if (value !== null) {
|
|
79
|
+
const int = parseInt(value);
|
|
80
|
+
if (Number.isInteger(int)) {
|
|
81
|
+
intValue = applyRange(int, options);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
if (intValue !== null) {
|
|
85
|
+
return intValue * itemSizeMultiplier + Math.max(intValue - 1, 0) * itemSpaceBetween;
|
|
86
|
+
}
|
|
87
|
+
return null;
|
|
88
|
+
};
|
|
89
|
+
export const attrValueToPixels = function (value) {
|
|
90
|
+
let options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : DEFAULT_INTEGER_OPTIONS;
|
|
91
|
+
const int = attrValueToInteger(value, options);
|
|
92
|
+
return int === null ? 'unset' : `${int}px`;
|
|
93
|
+
};
|
|
94
|
+
export const updateIntegerAttribute = function ($element, attrName, attrValue) {
|
|
95
|
+
let options = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEFAULT_INTEGER_OPTIONS;
|
|
96
|
+
const {
|
|
97
|
+
defaultValue = null,
|
|
98
|
+
itemSizeMultiplier: multiplier = 1
|
|
99
|
+
} = options;
|
|
100
|
+
let intValue = null;
|
|
101
|
+
if (typeof attrValue === 'string') {
|
|
102
|
+
intValue = attrValueToInteger(attrValue, options);
|
|
103
|
+
} else if (typeof attrValue === 'number') {
|
|
104
|
+
intValue = applyRange(attrValue, options) * multiplier;
|
|
105
|
+
} else {
|
|
106
|
+
intValue = defaultValue;
|
|
107
|
+
}
|
|
108
|
+
if (intValue === null) {
|
|
109
|
+
$element.removeAttribute(attrName);
|
|
110
|
+
} else {
|
|
111
|
+
$element.setAttribute(attrName, intValue.toFixed(0));
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
export function getIntegerAttribute($element, attrName, defaultValue) {
|
|
115
|
+
return attrValueToInteger($element.getAttribute(attrName)) ?? defaultValue;
|
|
116
|
+
}
|
|
117
|
+
export const setClass = (elem, name, isSet) => {
|
|
118
|
+
isSet ? elem.classList.add(name) : elem.classList.remove(name);
|
|
119
|
+
};
|
|
120
|
+
export const hasClass = (elem, name) => {
|
|
121
|
+
return elem.classList.contains(name);
|
|
122
|
+
};
|
|
123
|
+
export const getCssVar = (element, variableName) => {
|
|
124
|
+
const result = getComputedStyle(element).getPropertyValue(variableName).trim();
|
|
125
|
+
return result === '' ? null : result;
|
|
126
|
+
};
|
|
127
|
+
export const getCssVars = (element, variableNames) => {
|
|
128
|
+
const style = getComputedStyle(element);
|
|
129
|
+
return variableNames.map(name => {
|
|
130
|
+
const result = style.getPropertyValue(name).trim();
|
|
131
|
+
return result === '' ? null : result;
|
|
132
|
+
});
|
|
133
|
+
};
|
|
134
|
+
export const cloneNode = (el, deep) => {
|
|
135
|
+
const root = el.getRootNode();
|
|
136
|
+
if (root !== document && Reflect.has(root, 'createElement')) {
|
|
137
|
+
const cloned = root.createElement(el.tagName.toLowerCase());
|
|
138
|
+
for (const attr of el.getAttributeNames()) {
|
|
139
|
+
cloned.setAttribute(attr, el.getAttribute(attr));
|
|
140
|
+
}
|
|
141
|
+
if (deep) {
|
|
142
|
+
for (let i = 0; i < el.children.length; i++) {
|
|
143
|
+
const clonedChild = cloneNode(el.children[i], deep);
|
|
144
|
+
cloned.appendChild(clonedChild);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return cloned;
|
|
148
|
+
}
|
|
149
|
+
return el.cloneNode(deep);
|
|
150
|
+
};
|
|
151
|
+
export const shouldReduceMotion = () => window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
|
152
|
+
export const isAttrEqual = (oldVal, newVal) => {
|
|
153
|
+
return oldVal === newVal || newVal === null && oldVal === 'false' || newVal === '' && oldVal === 'true';
|
|
154
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export declare const defineCustomElement: (name: string, constructor: CustomElementConstructor) => void;
|
|
2
|
+
export declare const setNectaryRegistry: (registry: CustomElementRegistry) => void;
|
|
3
|
+
declare global {
|
|
4
|
+
interface ShadowRootInit {
|
|
5
|
+
customElements?: CustomElementRegistry;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
export declare class NectaryElement extends HTMLElement {
|
|
9
|
+
#private;
|
|
10
|
+
attachShadow(options?: Partial<ShadowRootInit>): ShadowRoot;
|
|
11
|
+
version: string;
|
|
12
|
+
get focusable(): boolean;
|
|
13
|
+
connectedCallback(): void;
|
|
14
|
+
disconnectedCallback(): void;
|
|
15
|
+
get isDomConnected(): boolean;
|
|
16
|
+
}
|
package/utils/element.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import pkg from '../package.json';
|
|
2
|
+
const nectaryDefinitions = new Map();
|
|
3
|
+
let nectaryRegistry = null;
|
|
4
|
+
export const defineCustomElement = (name, constructor) => {
|
|
5
|
+
if (nectaryRegistry !== null) {
|
|
6
|
+
if (nectaryRegistry.get(name) == null) {
|
|
7
|
+
nectaryRegistry.define(name, constructor);
|
|
8
|
+
}
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
nectaryDefinitions.set(name, constructor);
|
|
12
|
+
};
|
|
13
|
+
export const setNectaryRegistry = registry => {
|
|
14
|
+
if (nectaryRegistry !== null) {
|
|
15
|
+
throw new Error('Nectary registry already set');
|
|
16
|
+
}
|
|
17
|
+
nectaryRegistry = registry;
|
|
18
|
+
for (const [name, ctor] of nectaryDefinitions.entries()) {
|
|
19
|
+
if (nectaryRegistry.get(name) == null) {
|
|
20
|
+
nectaryRegistry.define(name, ctor);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
nectaryDefinitions.clear();
|
|
24
|
+
};
|
|
25
|
+
export class NectaryElement extends HTMLElement {
|
|
26
|
+
attachShadow(options) {
|
|
27
|
+
return super.attachShadow({
|
|
28
|
+
mode: 'open',
|
|
29
|
+
delegatesFocus: false,
|
|
30
|
+
customElements: nectaryRegistry,
|
|
31
|
+
...options
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
version = pkg.version;
|
|
35
|
+
get focusable() {
|
|
36
|
+
return false;
|
|
37
|
+
}
|
|
38
|
+
#isDomConnected = false;
|
|
39
|
+
connectedCallback() {
|
|
40
|
+
this.#isDomConnected = true;
|
|
41
|
+
}
|
|
42
|
+
disconnectedCallback() {
|
|
43
|
+
this.#isDomConnected = false;
|
|
44
|
+
}
|
|
45
|
+
get isDomConnected() {
|
|
46
|
+
return this.#isDomConnected;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const isTargetEqual: (e: Event, $elem: HTMLElement) => boolean;
|
|
2
|
+
export declare const getTargetByAttribute: (e: Event, attr: string) => HTMLElement | null;
|
|
3
|
+
export declare const getTargetAttribute: (e: Event, attr: string) => string | null;
|
|
4
|
+
export declare const getTargetIndexInParent: (e: Event, parent: Element) => number;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
export const isTargetEqual = (e, $elem) => {
|
|
2
|
+
return e.target === $elem || e.originalTarget === $elem;
|
|
3
|
+
};
|
|
4
|
+
export const getTargetByAttribute = (e, attr) => {
|
|
5
|
+
if (e.target.hasAttribute(attr)) {
|
|
6
|
+
return e.target;
|
|
7
|
+
}
|
|
8
|
+
if (e.originalTarget?.hasAttribute(attr) === true) {
|
|
9
|
+
return e.originalTarget;
|
|
10
|
+
}
|
|
11
|
+
return null;
|
|
12
|
+
};
|
|
13
|
+
export const getTargetAttribute = (e, attr) => {
|
|
14
|
+
return e.target.getAttribute(attr) ?? e.originalTarget?.getAttribute(attr) ?? null;
|
|
15
|
+
};
|
|
16
|
+
export const getTargetIndexInParent = (e, parent) => {
|
|
17
|
+
const indexOf = Array.prototype.indexOf.call(parent.children, e.target);
|
|
18
|
+
if (indexOf >= 0) {
|
|
19
|
+
return indexOf;
|
|
20
|
+
}
|
|
21
|
+
const origTgt = e.originalTarget;
|
|
22
|
+
if (origTgt != null) {
|
|
23
|
+
return Array.prototype.indexOf.call(parent.children, origTgt);
|
|
24
|
+
}
|
|
25
|
+
return -1;
|
|
26
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getReactEventHandler: ($element: HTMLElement, handlerName: string) => ((arg?: any) => void) | null;
|
package/utils/index.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './context';
|
|
2
|
+
export * from './csv';
|
|
3
|
+
export * from './dom';
|
|
4
|
+
export * from './element';
|
|
5
|
+
export * from './rect';
|
|
6
|
+
export * from './slot';
|
|
7
|
+
export * from './throttle';
|
|
8
|
+
export * from './debounce';
|
|
9
|
+
export * from './get-react-event-handler';
|
|
10
|
+
export * from './markdown';
|
|
11
|
+
export * from './event-target';
|
|
12
|
+
export * from './uid';
|
package/utils/index.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export * from './context';
|
|
2
|
+
export * from './csv';
|
|
3
|
+
export * from './dom';
|
|
4
|
+
export * from './element';
|
|
5
|
+
export * from './rect';
|
|
6
|
+
export * from './slot';
|
|
7
|
+
export * from './throttle';
|
|
8
|
+
export * from './debounce';
|
|
9
|
+
export * from './get-react-event-handler';
|
|
10
|
+
export * from './markdown';
|
|
11
|
+
export * from './event-target';
|
|
12
|
+
export * from './uid';
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export type TMarkdownInlineParams = {
|
|
2
|
+
isBold?: boolean;
|
|
3
|
+
isItalic?: boolean;
|
|
4
|
+
isStrikethrough?: boolean;
|
|
5
|
+
};
|
|
6
|
+
export type TMarkdownParseVisitor = {
|
|
7
|
+
link(text: string, href: string, attributes?: string[]): void;
|
|
8
|
+
emoji(emojiChar: string): void;
|
|
9
|
+
codetag(text: string): void;
|
|
10
|
+
inline(text: string, params: TMarkdownInlineParams): void;
|
|
11
|
+
linebreak(): void;
|
|
12
|
+
paragraph(): void;
|
|
13
|
+
list(isOrdered: boolean): void;
|
|
14
|
+
endList(): void;
|
|
15
|
+
listItem(): void;
|
|
16
|
+
end(): Node;
|
|
17
|
+
};
|
|
18
|
+
export declare const isEmojiString: (data: string) => boolean;
|
|
19
|
+
export declare const parseMarkdown: (md: string, visitor: TMarkdownParseVisitor) => Node;
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const regLinebreak = /(?:<br>\n|<br>|\n)/;
|
|
2
|
+
const regParagraph = /\n{2,}/;
|
|
3
|
+
const regEm3Star = /\*\*\*(?<em3>.+?)\*\*\*/;
|
|
4
|
+
const regEm2Star = /\*\*(?<em2>.+?)\*\*/;
|
|
5
|
+
const regEm1Star = /\*(?<em1>.+?)\*/;
|
|
6
|
+
const regEm3Underscore = /___(?<em3>.+?)___/;
|
|
7
|
+
const regEm2Underscore = /__(?<em2>.+?)__/;
|
|
8
|
+
const regEm1Underscore = /_(?<em1>.+?)_/;
|
|
9
|
+
const regCodeTag = /`(?<code>.+?)`/;
|
|
10
|
+
const regStrikethrough = /~~(?<strike>.+?)~~/;
|
|
11
|
+
const regLink = /!?\[(?<linktext>[^\]]*?)\]\((?<linkhref>[^)]+?)\)(\{(?<linkattrs>[^)]+?)\})?/;
|
|
12
|
+
const regEmoji = /(?<emoji>(?![0-9*#])\p{Emoji})/u;
|
|
13
|
+
const regUList = /^(?<indent>[\t ]*?)[*+-][\t ]+(?<ultext>.*?)[\t ]*?$/;
|
|
14
|
+
const regOList = /^(?<indent>[\t ]*?)\d+\.[\t ]+(?<oltext>.*?)[\t ]*?$/;
|
|
15
|
+
const allRegs = [regCodeTag, regLink, regEm3Star, regEm2Star, regEm1Star, regEm3Underscore, regEm2Underscore, regEm1Underscore, regStrikethrough, regEmoji];
|
|
16
|
+
export const isEmojiString = data => regEmoji.test(data);
|
|
17
|
+
const excludeRegs = function (regs) {
|
|
18
|
+
for (var _len = arguments.length, excluding = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
19
|
+
excluding[_key - 1] = arguments[_key];
|
|
20
|
+
}
|
|
21
|
+
return regs.filter(r => !excluding.includes(r));
|
|
22
|
+
};
|
|
23
|
+
const matchClosest = (regs, line) => {
|
|
24
|
+
return regs.map(reg => reg.exec(line)).reduce((res, match) => {
|
|
25
|
+
if (match === null) {
|
|
26
|
+
return res;
|
|
27
|
+
}
|
|
28
|
+
if (res === null || res.index > match.index) {
|
|
29
|
+
return match;
|
|
30
|
+
}
|
|
31
|
+
return res;
|
|
32
|
+
}, null);
|
|
33
|
+
};
|
|
34
|
+
const INITIAL_CONTEXT = {
|
|
35
|
+
isBold: false,
|
|
36
|
+
isItalic: false,
|
|
37
|
+
isStrikethrough: false
|
|
38
|
+
};
|
|
39
|
+
const createLineParser = visitor => function parseLine(regs, md) {
|
|
40
|
+
let context = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : INITIAL_CONTEXT;
|
|
41
|
+
let line = md;
|
|
42
|
+
let match = null;
|
|
43
|
+
while ((match = matchClosest(regs, line)) !== null) {
|
|
44
|
+
const groups = match.groups;
|
|
45
|
+
const matchedStr = match[0];
|
|
46
|
+
if (match.index > 0) {
|
|
47
|
+
visitor.inline(line.substring(0, match.index), context);
|
|
48
|
+
}
|
|
49
|
+
line = line.substring(match.index + matchedStr.length);
|
|
50
|
+
if (groups?.linkhref != null) {
|
|
51
|
+
visitor.link(groups.linktext, groups.linkhref, groups.linkattrs?.split(' '));
|
|
52
|
+
}
|
|
53
|
+
if (groups?.code != null) {
|
|
54
|
+
visitor.codetag(groups.code);
|
|
55
|
+
}
|
|
56
|
+
if (groups?.emoji != null) {
|
|
57
|
+
visitor.emoji(groups.emoji);
|
|
58
|
+
}
|
|
59
|
+
if (groups?.em1 != null) {
|
|
60
|
+
parseLine(excludeRegs(regs, regEm1Star, regEm1Underscore), groups.em1, {
|
|
61
|
+
...context,
|
|
62
|
+
isItalic: true
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
if (groups?.em2 != null) {
|
|
66
|
+
parseLine(excludeRegs(regs, regEm2Star, regEm2Underscore), groups.em2, {
|
|
67
|
+
...context,
|
|
68
|
+
isBold: true
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
if (groups?.em3 != null) {
|
|
72
|
+
parseLine(excludeRegs(regs, regEm3Star, regEm3Underscore, regEm2Star, regEm2Underscore, regEm1Star, regEm1Underscore), groups.em3, {
|
|
73
|
+
...context,
|
|
74
|
+
isBold: true,
|
|
75
|
+
isItalic: true
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
if (groups?.strike != null) {
|
|
79
|
+
parseLine(excludeRegs(regs, regStrikethrough), groups.strike, {
|
|
80
|
+
...context,
|
|
81
|
+
isStrikethrough: true
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
if (line.length > 0) {
|
|
86
|
+
visitor.inline(line, context);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
const createBlockParser = visitor => {
|
|
90
|
+
const parseLine = createLineParser(visitor);
|
|
91
|
+
const listRegs = [regUList, regOList];
|
|
92
|
+
const getListItemText = match => {
|
|
93
|
+
return match.groups.ultext ?? match.groups.oltext;
|
|
94
|
+
};
|
|
95
|
+
const BLOCK_MODE_PARAGRAPH = 1;
|
|
96
|
+
const BLOCK_MODE_ULIST = 2;
|
|
97
|
+
const BLOCK_MODE_OLIST = 2;
|
|
98
|
+
return function parseBlock(lines) {
|
|
99
|
+
let mode = 0;
|
|
100
|
+
for (let i = 0; i < lines.length; ++i) {
|
|
101
|
+
const listMatch = matchClosest(listRegs, lines[i]);
|
|
102
|
+
const isListLine = listMatch !== null;
|
|
103
|
+
if (isListLine) {
|
|
104
|
+
const groups = listMatch.groups;
|
|
105
|
+
const isOrderedList = groups.oltext != null;
|
|
106
|
+
mode = isOrderedList ? BLOCK_MODE_OLIST : BLOCK_MODE_ULIST;
|
|
107
|
+
visitor.list(isOrderedList);
|
|
108
|
+
const listItemInitialIndent = groups.indent;
|
|
109
|
+
let listItemLines = [getListItemText(listMatch)];
|
|
110
|
+
visitor.listItem();
|
|
111
|
+
for (++i; i < lines.length; ++i) {
|
|
112
|
+
const listItemMatch = isOrderedList ? regOList.exec(lines[i]) : regUList.exec(lines[i]);
|
|
113
|
+
if (listItemMatch !== null && listItemMatch.groups.indent === listItemInitialIndent) {
|
|
114
|
+
parseBlock(listItemLines);
|
|
115
|
+
listItemLines = [getListItemText(listItemMatch)];
|
|
116
|
+
visitor.listItem();
|
|
117
|
+
} else {
|
|
118
|
+
listItemLines.push(lines[i]);
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
parseBlock(listItemLines);
|
|
122
|
+
visitor.endList();
|
|
123
|
+
mode = 0;
|
|
124
|
+
} else {
|
|
125
|
+
if (mode === BLOCK_MODE_PARAGRAPH) {
|
|
126
|
+
visitor.linebreak();
|
|
127
|
+
}
|
|
128
|
+
if (mode !== BLOCK_MODE_PARAGRAPH) {
|
|
129
|
+
mode = BLOCK_MODE_PARAGRAPH;
|
|
130
|
+
visitor.paragraph();
|
|
131
|
+
}
|
|
132
|
+
parseLine(allRegs, lines[i]);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
};
|
|
137
|
+
export const parseMarkdown = (md, visitor) => {
|
|
138
|
+
const parseBlock = createBlockParser(visitor);
|
|
139
|
+
for (const block of md.trim().split(regParagraph)) {
|
|
140
|
+
parseBlock(block.trim().split(regLinebreak));
|
|
141
|
+
}
|
|
142
|
+
return visitor.end();
|
|
143
|
+
};
|
package/utils/rect.d.ts
ADDED
package/utils/rect.js
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { getFirstSlotElement } from './slot';
|
|
2
|
+
export const getRect = el => {
|
|
3
|
+
const {
|
|
4
|
+
x,
|
|
5
|
+
y,
|
|
6
|
+
width,
|
|
7
|
+
height
|
|
8
|
+
} = el.getBoundingClientRect();
|
|
9
|
+
return {
|
|
10
|
+
x,
|
|
11
|
+
y,
|
|
12
|
+
width,
|
|
13
|
+
height
|
|
14
|
+
};
|
|
15
|
+
};
|
|
16
|
+
export const rectOverlap = (targetRect, contentRect) => {
|
|
17
|
+
return targetRect.x < contentRect.x + contentRect.width && targetRect.x + targetRect.width > contentRect.x && targetRect.y < contentRect.y + contentRect.height && targetRect.y + targetRect.height > contentRect.y;
|
|
18
|
+
};
|
|
19
|
+
export const getTargetRect = slot => {
|
|
20
|
+
const item = getFirstSlotElement(slot, true);
|
|
21
|
+
if (item === null) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
if (Reflect.has(item, 'footprintRect')) {
|
|
25
|
+
return item.footprintRect;
|
|
26
|
+
}
|
|
27
|
+
return getRect(item);
|
|
28
|
+
};
|
package/utils/size.d.ts
ADDED
package/utils/size.js
ADDED
package/utils/slot.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { NectaryElement } from './element';
|
|
2
|
+
export declare const getFirstSlotElement: (root: HTMLSlotElement, isDeep?: boolean) => HTMLElement | null;
|
|
3
|
+
export declare const getFirstFocusableElement: (root: Element) => NectaryElement | null;
|
|
4
|
+
export declare const isElementFocused: ($el: Element | null) => boolean;
|
package/utils/slot.js
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
const isSlotElement = el => {
|
|
2
|
+
return el.tagName === 'SLOT';
|
|
3
|
+
};
|
|
4
|
+
export const getFirstSlotElement = function (root) {
|
|
5
|
+
let isDeep = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
6
|
+
const el = root.assignedElements()[0];
|
|
7
|
+
if (el == null) {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
if (isDeep && isSlotElement(el)) {
|
|
11
|
+
return getFirstSlotElement(el, isDeep);
|
|
12
|
+
}
|
|
13
|
+
return el;
|
|
14
|
+
};
|
|
15
|
+
const getChildren = root => {
|
|
16
|
+
if (isSlotElement(root)) {
|
|
17
|
+
return root.assignedElements();
|
|
18
|
+
}
|
|
19
|
+
return Array.from(root.children);
|
|
20
|
+
};
|
|
21
|
+
const isFocusable = el => {
|
|
22
|
+
return el.focusable === true;
|
|
23
|
+
};
|
|
24
|
+
export const getFirstFocusableElement = root => {
|
|
25
|
+
for (const child of getChildren(root)) {
|
|
26
|
+
if (isFocusable(child)) {
|
|
27
|
+
return child;
|
|
28
|
+
}
|
|
29
|
+
const resultEl = getFirstFocusableElement(child);
|
|
30
|
+
if (resultEl !== null) {
|
|
31
|
+
return resultEl;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
};
|
|
36
|
+
export const isElementFocused = $el => {
|
|
37
|
+
return $el !== null && $el === $el.getRootNode().activeElement;
|
|
38
|
+
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const createThrottle = (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
|
+
id = delayFn(delayCallback);
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
cancel: () => {
|
|
14
|
+
if (id !== null) {
|
|
15
|
+
cancelFn(id);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
export const throttleAnimationFrame = createThrottle(globalThis.requestAnimationFrame, globalThis.cancelAnimationFrame);
|
package/utils/uid.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const getUid: () => string;
|
package/utils/uid.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export const getUid = () => crypto.getRandomValues(new Uint8Array(21)).reduce((id, byte) => {
|
|
2
|
+
const nextByte = byte & 63;
|
|
3
|
+
if (nextByte < 36) {
|
|
4
|
+
return id + nextByte.toString(36);
|
|
5
|
+
}
|
|
6
|
+
if (nextByte < 62) {
|
|
7
|
+
return id + (nextByte - 26).toString(36).toUpperCase();
|
|
8
|
+
}
|
|
9
|
+
if (nextByte > 62) {
|
|
10
|
+
return `${id}-`;
|
|
11
|
+
}
|
|
12
|
+
return `${id}_`;
|
|
13
|
+
}, '');
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { TSinchVerticalStepperElement, TSinchVerticalStepperReact } from './types';
|
|
2
|
+
declare global {
|
|
3
|
+
namespace JSX {
|
|
4
|
+
interface IntrinsicElements {
|
|
5
|
+
'sinch-vertical-stepper': TSinchVerticalStepperReact;
|
|
6
|
+
}
|
|
7
|
+
}
|
|
8
|
+
interface HTMLElementTagNameMap {
|
|
9
|
+
'sinch-vertical-stepper': TSinchVerticalStepperElement;
|
|
10
|
+
}
|
|
11
|
+
}
|