@nectary/components 2.4.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 +168 -0
- package/button/types.d.ts +45 -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/colors.json +88 -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 +1 -0
- package/emoji/utils.js +42 -0
- package/emoji-picker/data.json +1 -0
- package/emoji-picker/index.d.ts +22 -0
- package/emoji-picker/index.js +304 -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 +112 -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 +173 -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 +620 -0
- package/input/types.d.ts +80 -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 +132 -0
- package/link/types.d.ts +55 -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 +30 -0
- 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 +140 -0
- package/popover/types.d.ts +40 -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 +17 -0
- package/radio-option/types.js +1 -0
- package/readme.md +179 -0
- package/rich-text/index.d.ts +11 -0
- package/rich-text/index.js +48 -0
- package/rich-text/types.d.ts +12 -0
- package/rich-text/types.js +1 -0
- package/rich-text/utils.d.ts +2 -0
- package/rich-text/utils.js +1 -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 +200 -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 +307 -0
- package/select-menu/types.d.ts +29 -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/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 +228 -0
- package/textarea/types.d.ts +57 -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 +35 -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 +14 -0
- package/toast/index.js +87 -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 +163 -0
- package/toast-manager/types.d.ts +7 -0
- package/toast-manager/types.js +1 -0
- package/toggle/index.d.ts +11 -0
- package/toggle/index.js +126 -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 +258 -0
- package/tooltip/tooltip-state.d.ts +19 -0
- package/tooltip/tooltip-state.js +126 -0
- package/tooltip/types.d.ts +35 -0
- package/tooltip/types.js +1 -0
- package/tooltip/utils.d.ts +5 -0
- package/tooltip/utils.js +17 -0
- package/types.d.ts +14 -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/countries.json +1217 -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 +1 -0
- package/utils/markdown.js +128 -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/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 => global.setTimeout(cb, ms), global.clearTimeout);
|
|
22
|
+
export const debounceAnimationFrame = createDebounce(global.requestAnimationFrame, global.cancelAnimationFrame);
|
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 @@
|
|
|
1
|
+
export declare const parseMarkdown: (md: string) => string;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { filterXSS } from 'xss';
|
|
2
|
+
const contextTags = {
|
|
3
|
+
em1: ['<span class="em1">', '</span>'],
|
|
4
|
+
em2: ['<span class="em2">', '</span>'],
|
|
5
|
+
em3: ['<span class="em3">', '</span>'],
|
|
6
|
+
s: ['<span class="strikethrough">', '</span>'],
|
|
7
|
+
p: ['<p class="paragraph">', '</p>']
|
|
8
|
+
};
|
|
9
|
+
const getContextTags = token => {
|
|
10
|
+
switch (token) {
|
|
11
|
+
case '_':
|
|
12
|
+
case '*':
|
|
13
|
+
return contextTags.em1;
|
|
14
|
+
case '__':
|
|
15
|
+
case '**':
|
|
16
|
+
return contextTags.em2;
|
|
17
|
+
case '___':
|
|
18
|
+
case '***':
|
|
19
|
+
return contextTags.em3;
|
|
20
|
+
case '~~':
|
|
21
|
+
return contextTags.s;
|
|
22
|
+
case 'p':
|
|
23
|
+
return contextTags.p;
|
|
24
|
+
default:
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
const encodeAttr = str => {
|
|
29
|
+
return `${str}`.replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>');
|
|
30
|
+
};
|
|
31
|
+
const tokenizer = /(?<em>___|\*\*\*|__|\*\*|[_*]|~~)|(?:!?\[(?<linktext>[^\]]*?)\]\((?<linkhref>[^)]+?)\))|(?:`(?<code>[^`].*?)`)|(?<paragraph>\n{2,})|(?<newline>\n)/gm;
|
|
32
|
+
export const parseMarkdown = md => {
|
|
33
|
+
const context = [];
|
|
34
|
+
let out = '';
|
|
35
|
+
let lastIndex = 0;
|
|
36
|
+
const isContextEnd = token => {
|
|
37
|
+
return context.length > 0 && context.at(-1).token === token;
|
|
38
|
+
};
|
|
39
|
+
const pushContext = token => {
|
|
40
|
+
const desc = getContextTags(token);
|
|
41
|
+
if (desc === null) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
context.push({
|
|
45
|
+
token,
|
|
46
|
+
out: ''
|
|
47
|
+
});
|
|
48
|
+
};
|
|
49
|
+
const popContext = (token, prev) => {
|
|
50
|
+
const desc = getContextTags(token);
|
|
51
|
+
if (desc === null) {
|
|
52
|
+
return token;
|
|
53
|
+
}
|
|
54
|
+
const ctx = context.pop();
|
|
55
|
+
return `${desc[0]}${ctx.out}${prev}${desc[1]}`;
|
|
56
|
+
};
|
|
57
|
+
const flushContext = prev => {
|
|
58
|
+
let str = '';
|
|
59
|
+
while (context.length > 1) {
|
|
60
|
+
const ctx = context.pop();
|
|
61
|
+
str = `${ctx.token}${ctx.out}${str}`;
|
|
62
|
+
}
|
|
63
|
+
if (context.length === 0) {
|
|
64
|
+
pushContext('p');
|
|
65
|
+
}
|
|
66
|
+
return popContext(context.at(-1).token, str + prev);
|
|
67
|
+
};
|
|
68
|
+
md = md.trim();
|
|
69
|
+
while (true) {
|
|
70
|
+
const tokens = tokenizer.exec(md);
|
|
71
|
+
if (tokens === null) {
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
74
|
+
let prev = md.substring(lastIndex, tokens.index);
|
|
75
|
+
let chunk = tokens[0];
|
|
76
|
+
const groups = tokens.groups;
|
|
77
|
+
lastIndex = tokenizer.lastIndex;
|
|
78
|
+
if (context.length === 0) {
|
|
79
|
+
pushContext('p');
|
|
80
|
+
}
|
|
81
|
+
if (prev.match(/[^\\](\\\\)*\\$/) != null) {
|
|
82
|
+
prev = prev.substring(0, prev.length - 1);
|
|
83
|
+
context.at(-1).out += prev + chunk;
|
|
84
|
+
continue;
|
|
85
|
+
}
|
|
86
|
+
if (groups.em != null) {
|
|
87
|
+
const isCloseTag = isContextEnd(groups.em);
|
|
88
|
+
if (isCloseTag) {
|
|
89
|
+
chunk = popContext(groups.em, prev);
|
|
90
|
+
context.at(-1).out += chunk;
|
|
91
|
+
continue;
|
|
92
|
+
}
|
|
93
|
+
context.at(-1).out += prev;
|
|
94
|
+
pushContext(groups.em);
|
|
95
|
+
continue;
|
|
96
|
+
}
|
|
97
|
+
if (groups.linkhref != null) {
|
|
98
|
+
const href = groups.linkhref;
|
|
99
|
+
const text = groups.linktext.length > 0 ? groups.linktext : href;
|
|
100
|
+
chunk = `<a class="link" target="_blank" href="${encodeAttr(href)}">${encodeAttr(text)}</a>`;
|
|
101
|
+
context.at(-1).out += prev + chunk;
|
|
102
|
+
continue;
|
|
103
|
+
}
|
|
104
|
+
if (groups.code != null) {
|
|
105
|
+
chunk = `<span class="code">${encodeAttr(groups.code)}</span>`;
|
|
106
|
+
context.at(-1).out += prev + chunk;
|
|
107
|
+
continue;
|
|
108
|
+
}
|
|
109
|
+
if (groups.newline != null) {
|
|
110
|
+
chunk = '<br/>';
|
|
111
|
+
context.at(-1).out += prev + chunk;
|
|
112
|
+
continue;
|
|
113
|
+
}
|
|
114
|
+
if (groups.paragraph != null) {
|
|
115
|
+
out += flushContext(prev);
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
out = (out + flushContext(md.substring(lastIndex))).trim();
|
|
120
|
+
return filterXSS(out, {
|
|
121
|
+
whiteList: {
|
|
122
|
+
p: ['class'],
|
|
123
|
+
span: ['class'],
|
|
124
|
+
a: ['href', 'class', 'target'],
|
|
125
|
+
br: []
|
|
126
|
+
}
|
|
127
|
+
});
|
|
128
|
+
};
|
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(global.requestAnimationFrame, global.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
|
+
}
|