@bolio-ui/core 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +71 -0
- package/dist/avatar/index.js +901 -0
- package/dist/badge/index.js +899 -0
- package/dist/bolio-ui-provider/index.js +1883 -0
- package/dist/breadcrumbs/index.js +985 -0
- package/dist/button/index.js +1358 -0
- package/dist/button-dropdown/index.js +1111 -0
- package/dist/button-group/index.js +782 -0
- package/dist/capacity/index.js +780 -0
- package/dist/card/index.js +1275 -0
- package/dist/checkbox/index.js +1042 -0
- package/dist/code/index.js +803 -0
- package/dist/col/index.js +90 -0
- package/dist/collapse/index.js +1158 -0
- package/dist/container/index.js +444 -0
- package/dist/css-baseline/index.js +348 -0
- package/dist/description/index.js +741 -0
- package/dist/display/index.js +745 -0
- package/dist/divider/index.js +767 -0
- package/dist/dot/index.js +755 -0
- package/dist/drawer/index.js +1513 -0
- package/dist/fieldset/index.js +1089 -0
- package/dist/grid/index.js +870 -0
- package/dist/image/index.js +1094 -0
- package/dist/index.js +9970 -0
- package/dist/input/index.js +1275 -0
- package/dist/keyboard/index.js +711 -0
- package/dist/link/index.js +863 -0
- package/dist/loading/index.js +765 -0
- package/dist/mdx-widgets/index.js +438 -0
- package/dist/modal/index.js +2220 -0
- package/dist/note/index.js +773 -0
- package/dist/page/index.js +928 -0
- package/dist/pagination/index.js +1201 -0
- package/dist/popover/index.js +1502 -0
- package/dist/progress/index.js +804 -0
- package/dist/radio/index.js +1028 -0
- package/dist/rating/index.js +912 -0
- package/dist/row/index.js +442 -0
- package/dist/section/index.js +733 -0
- package/dist/select/index.js +1865 -0
- package/dist/slider/index.js +1097 -0
- package/dist/snippet/index.js +1207 -0
- package/dist/spacer/index.js +692 -0
- package/dist/spinner/index.js +763 -0
- package/dist/styled-jsx.cjs.js +766 -0
- package/dist/tabs/index.js +1125 -0
- package/dist/tag/index.js +749 -0
- package/dist/text/index.js +830 -0
- package/dist/textarea/index.js +915 -0
- package/dist/themes/index.js +319 -0
- package/dist/toggle/index.js +852 -0
- package/dist/tooltip/index.js +1353 -0
- package/dist/use-all-themes/index.js +335 -0
- package/dist/use-body-scroll/index.js +173 -0
- package/dist/use-classes/index.js +55 -0
- package/dist/use-click-away/index.js +28 -0
- package/dist/use-clipboard/index.js +188 -0
- package/dist/use-current-state/index.js +90 -0
- package/dist/use-input/index.js +129 -0
- package/dist/use-keyboard/index.js +214 -0
- package/dist/use-media-query/index.js +495 -0
- package/dist/use-modal/index.js +114 -0
- package/dist/use-scale/index.js +673 -0
- package/dist/use-tabs/index.js +112 -0
- package/dist/use-theme/index.js +333 -0
- package/dist/use-toasts/index.js +236 -0
- package/esm/avatar/avatar-group.js +29 -0
- package/esm/avatar/avatar.js +107 -0
- package/esm/avatar/avatar.skeleton.js +21 -0
- package/esm/avatar/helpers.js +16 -0
- package/esm/avatar/index.js +4 -0
- package/esm/avatar/stories.js +113 -0
- package/esm/badge/badge-anchor.js +70 -0
- package/esm/badge/badge.js +58 -0
- package/esm/badge/index.js +4 -0
- package/esm/badge/stories.js +92 -0
- package/esm/bolio-ui-provider/bolio-ui-provider.js +62 -0
- package/esm/bolio-ui-provider/index.js +2 -0
- package/esm/bolio-ui-provider/theme-provider.js +47 -0
- package/esm/breadcrumbs/breadcrumbs-item.js +49 -0
- package/esm/breadcrumbs/breadcrumbs-separator.js +25 -0
- package/esm/breadcrumbs/breadcrumbs.js +47 -0
- package/esm/breadcrumbs/index.js +6 -0
- package/esm/breadcrumbs/stories.js +51 -0
- package/esm/button/button-icon.js +29 -0
- package/esm/button/button-loading.js +17 -0
- package/esm/button/button.drip.js +57 -0
- package/esm/button/button.js +146 -0
- package/esm/button/index.js +2 -0
- package/esm/button/stories.js +221 -0
- package/esm/button/styles.js +232 -0
- package/esm/button/utils.js +46 -0
- package/esm/button-dropdown/button-dropdown-context.js +11 -0
- package/esm/button-dropdown/button-dropdown-item.js +52 -0
- package/esm/button-dropdown/button-dropdown.js +111 -0
- package/esm/button-dropdown/icon.js +30 -0
- package/esm/button-dropdown/index.js +4 -0
- package/esm/button-dropdown/stories.js +92 -0
- package/esm/button-dropdown/styles.js +60 -0
- package/esm/button-group/button-group-context.js +9 -0
- package/esm/button-group/button-group.js +75 -0
- package/esm/button-group/index.js +2 -0
- package/esm/button-group/stories.js +66 -0
- package/esm/capacity/capacity.js +52 -0
- package/esm/capacity/index.js +2 -0
- package/esm/capacity/stories.js +55 -0
- package/esm/card/card-content.js +28 -0
- package/esm/card/card-footer.js +36 -0
- package/esm/card/card.js +68 -0
- package/esm/card/index.js +8 -0
- package/esm/card/stories.js +126 -0
- package/esm/card/styles.js +45 -0
- package/esm/checkbox/checkbox-context.js +10 -0
- package/esm/checkbox/checkbox-group.js +70 -0
- package/esm/checkbox/checkbox.icon.js +50 -0
- package/esm/checkbox/checkbox.js +114 -0
- package/esm/checkbox/index.js +4 -0
- package/esm/checkbox/stories.js +84 -0
- package/esm/checkbox/styles.js +34 -0
- package/esm/code/code.js +57 -0
- package/esm/code/index.js +2 -0
- package/esm/code/stories.js +53 -0
- package/esm/col/col.js +29 -0
- package/esm/col/index.js +2 -0
- package/esm/collapse/collapse-context.js +8 -0
- package/esm/collapse/collapse-group.js +75 -0
- package/esm/collapse/collapse-icon.js +28 -0
- package/esm/collapse/collapse.js +93 -0
- package/esm/collapse/index.js +4 -0
- package/esm/collapse/stories.js +48 -0
- package/esm/container/container.js +62 -0
- package/esm/container/index.js +2 -0
- package/esm/css-baseline/css-baseline.js +18 -0
- package/esm/css-baseline/index.js +1 -0
- package/esm/description/description.js +39 -0
- package/esm/description/index.js +2 -0
- package/esm/description/stories.js +23 -0
- package/esm/display/display.js +43 -0
- package/esm/display/index.js +2 -0
- package/esm/divider/divider.js +65 -0
- package/esm/divider/index.js +2 -0
- package/esm/divider/stories.js +41 -0
- package/esm/dot/dot.js +53 -0
- package/esm/dot/index.js +2 -0
- package/esm/dot/stories.js +40 -0
- package/esm/drawer/drawer-wrapper.js +86 -0
- package/esm/drawer/drawer.js +77 -0
- package/esm/drawer/helper.js +27 -0
- package/esm/drawer/index.js +8 -0
- package/esm/drawer/stories.js +79 -0
- package/esm/fieldset/fieldset-content.js +29 -0
- package/esm/fieldset/fieldset-context.js +9 -0
- package/esm/fieldset/fieldset-footer.js +30 -0
- package/esm/fieldset/fieldset-group.js +88 -0
- package/esm/fieldset/fieldset-subtitle.js +21 -0
- package/esm/fieldset/fieldset-title.js +23 -0
- package/esm/fieldset/fieldset.js +96 -0
- package/esm/fieldset/index.js +13 -0
- package/esm/fieldset/stories.js +72 -0
- package/esm/grid/basic-item.js +96 -0
- package/esm/grid/grid-container.js +46 -0
- package/esm/grid/grid-types.js +6 -0
- package/esm/grid/grid.js +37 -0
- package/esm/grid/index.js +4 -0
- package/esm/grid/stories.js +212 -0
- package/esm/icon/stories.js +36 -0
- package/esm/image/helpers.js +16 -0
- package/esm/image/image-browser-https-icon.js +23 -0
- package/esm/image/image-browser.js +86 -0
- package/esm/image/image.js +91 -0
- package/esm/image/image.skeleton.js +21 -0
- package/esm/image/index.js +4 -0
- package/esm/image/stories.js +73 -0
- package/esm/image/styles.js +15 -0
- package/esm/index.js +69 -0
- package/esm/input/index.js +6 -0
- package/esm/input/input-block-label.js +18 -0
- package/esm/input/input-icon-clear.js +47 -0
- package/esm/input/input-icon.js +19 -0
- package/esm/input/input-label.js +18 -0
- package/esm/input/input-props.js +12 -0
- package/esm/input/input.js +179 -0
- package/esm/input/password-icon.js +30 -0
- package/esm/input/password.js +66 -0
- package/esm/input/stories.js +113 -0
- package/esm/input/styles.js +41 -0
- package/esm/keyboard/index.js +2 -0
- package/esm/keyboard/keyboard.js +48 -0
- package/esm/keyboard/stories.js +43 -0
- package/esm/link/icon.js +30 -0
- package/esm/link/index.js +2 -0
- package/esm/link/link.js +50 -0
- package/esm/link/stories.js +59 -0
- package/esm/loading/index.js +2 -0
- package/esm/loading/loading.js +63 -0
- package/esm/loading/stories.js +75 -0
- package/esm/mdx-widgets/index.js +2 -0
- package/esm/mdx-widgets/mock-page.js +37 -0
- package/esm/mdx-widgets/parsed-codes/index.js +1 -0
- package/esm/mdx-widgets/parsed-codes/wait-time.js +13 -0
- package/esm/modal/index.js +10 -0
- package/esm/modal/modal-action.js +76 -0
- package/esm/modal/modal-actions.js +39 -0
- package/esm/modal/modal-content.js +28 -0
- package/esm/modal/modal-context.js +6 -0
- package/esm/modal/modal-subtitle.js +30 -0
- package/esm/modal/modal-title.js +30 -0
- package/esm/modal/modal-wrapper.js +80 -0
- package/esm/modal/modal.js +104 -0
- package/esm/modal/stories.js +165 -0
- package/esm/note/index.js +2 -0
- package/esm/note/note.js +71 -0
- package/esm/note/stories.js +68 -0
- package/esm/page/index.js +9 -0
- package/esm/page/page-content.js +26 -0
- package/esm/page/page-footer.js +25 -0
- package/esm/page/page-header.js +33 -0
- package/esm/page/page.js +88 -0
- package/esm/page/stories.js +54 -0
- package/esm/pagination/index.js +6 -0
- package/esm/pagination/pagination-context.js +8 -0
- package/esm/pagination/pagination-ellipsis.js +73 -0
- package/esm/pagination/pagination-item.js +50 -0
- package/esm/pagination/pagination-next.js +25 -0
- package/esm/pagination/pagination-pages.js +90 -0
- package/esm/pagination/pagination-previous.js +25 -0
- package/esm/pagination/pagination.js +105 -0
- package/esm/pagination/stories.js +49 -0
- package/esm/popover/index.js +5 -0
- package/esm/popover/popover-context.js +9 -0
- package/esm/popover/popover-item.js +65 -0
- package/esm/popover/popover.js +83 -0
- package/esm/popover/stories.js +84 -0
- package/esm/progress/index.js +2 -0
- package/esm/progress/progress.js +76 -0
- package/esm/progress/stories.js +114 -0
- package/esm/radio/index.js +7 -0
- package/esm/radio/radio-context.js +9 -0
- package/esm/radio/radio-description.js +30 -0
- package/esm/radio/radio-group.js +61 -0
- package/esm/radio/radio.js +123 -0
- package/esm/radio/stories.js +98 -0
- package/esm/radio/styles.js +41 -0
- package/esm/rating/index.js +2 -0
- package/esm/rating/rating-icon.js +20 -0
- package/esm/rating/rating.js +115 -0
- package/esm/rating/stories.js +72 -0
- package/esm/row/index.js +2 -0
- package/esm/row/row.js +60 -0
- package/esm/section/index.js +2 -0
- package/esm/section/section.js +30 -0
- package/esm/select/index.js +4 -0
- package/esm/select/select-context.js +9 -0
- package/esm/select/select-dropdown.js +41 -0
- package/esm/select/select-icon-clear.js +41 -0
- package/esm/select/select-icon.js +23 -0
- package/esm/select/select-input.js +34 -0
- package/esm/select/select-multiple-value.js +23 -0
- package/esm/select/select-option.js +100 -0
- package/esm/select/select.js +244 -0
- package/esm/select/stories.js +239 -0
- package/esm/select/styles.js +48 -0
- package/esm/shared/backdrop.js +77 -0
- package/esm/shared/css-transition.js +71 -0
- package/esm/shared/dropdown.js +109 -0
- package/esm/shared/ellipsis.js +15 -0
- package/esm/shared/expand.js +95 -0
- package/esm/shared/highlight.js +47 -0
- package/esm/slider/index.js +2 -0
- package/esm/slider/slider-dot.js +27 -0
- package/esm/slider/slider-mark.js +38 -0
- package/esm/slider/slider.js +163 -0
- package/esm/slider/stories.js +134 -0
- package/esm/slider/styles.js +27 -0
- package/esm/snippet/index.js +2 -0
- package/esm/snippet/snippet-icon.js +27 -0
- package/esm/snippet/snippet.js +100 -0
- package/esm/snippet/stories.js +133 -0
- package/esm/snippet/styles.js +58 -0
- package/esm/spacer/index.js +2 -0
- package/esm/spacer/spacer.js +28 -0
- package/esm/spacer/stories.js +54 -0
- package/esm/spinner/index.js +2 -0
- package/esm/spinner/spinner.js +46 -0
- package/esm/spinner/stories.js +13 -0
- package/esm/styled-jsx-server.es.js +5 -0
- package/esm/styled-jsx.es.js +757 -0
- package/esm/tabs/index.js +5 -0
- package/esm/tabs/stories.js +92 -0
- package/esm/tabs/tabs-context.js +8 -0
- package/esm/tabs/tabs-item.js +80 -0
- package/esm/tabs/tabs.js +151 -0
- package/esm/tag/index.js +2 -0
- package/esm/tag/stories.js +58 -0
- package/esm/tag/tag.js +86 -0
- package/esm/text/child.js +78 -0
- package/esm/text/index.js +2 -0
- package/esm/text/stories.js +104 -0
- package/esm/text/text.js +94 -0
- package/esm/textarea/index.js +2 -0
- package/esm/textarea/stories.js +104 -0
- package/esm/textarea/textarea.js +116 -0
- package/esm/themes/index.js +2 -0
- package/esm/themes/presets/dark.js +67 -0
- package/esm/themes/presets/default.js +67 -0
- package/esm/themes/presets/index.js +1 -0
- package/esm/themes/presets/shared.js +42 -0
- package/esm/themes/themes.js +89 -0
- package/esm/toggle/index.js +2 -0
- package/esm/toggle/stories.js +55 -0
- package/esm/toggle/styles.js +27 -0
- package/esm/toggle/toggle.js +82 -0
- package/esm/tooltip/helper.js +21 -0
- package/esm/tooltip/index.js +2 -0
- package/esm/tooltip/placement.js +160 -0
- package/esm/tooltip/stories.js +183 -0
- package/esm/tooltip/styles.js +18 -0
- package/esm/tooltip/tooltip-content.js +83 -0
- package/esm/tooltip/tooltip-icon.js +32 -0
- package/esm/tooltip/tooltip.js +132 -0
- package/esm/use-all-themes/all-themes-context.js +9 -0
- package/esm/use-all-themes/index.js +2 -0
- package/esm/use-body-scroll/index.js +2 -0
- package/esm/use-body-scroll/use-body-scroll.js +70 -0
- package/esm/use-classes/index.js +2 -0
- package/esm/use-classes/use-classes.js +41 -0
- package/esm/use-click-away/index.js +2 -0
- package/esm/use-click-away/use-click-away.js +22 -0
- package/esm/use-clipboard/index.js +2 -0
- package/esm/use-clipboard/use-clipboard.js +46 -0
- package/esm/use-current-state/index.js +2 -0
- package/esm/use-current-state/use-current-state.js +26 -0
- package/esm/use-input/index.js +2 -0
- package/esm/use-input/use-input.js +32 -0
- package/esm/use-keyboard/codes.js +97 -0
- package/esm/use-keyboard/helper.js +26 -0
- package/esm/use-keyboard/index.js +4 -0
- package/esm/use-keyboard/use-keyboard.js +79 -0
- package/esm/use-media-query/index.js +2 -0
- package/esm/use-media-query/use-media-query.js +90 -0
- package/esm/use-modal/index.js +2 -0
- package/esm/use-modal/use-modal.js +26 -0
- package/esm/use-scale/index.js +6 -0
- package/esm/use-scale/scale-context.js +37 -0
- package/esm/use-scale/utils.js +62 -0
- package/esm/use-scale/with-scale.js +114 -0
- package/esm/use-tabs/index.js +2 -0
- package/esm/use-tabs/use-tabs.js +24 -0
- package/esm/use-theme/index.js +2 -0
- package/esm/use-theme/theme-context.js +7 -0
- package/esm/use-toasts/helpers.js +72 -0
- package/esm/use-toasts/index.js +2 -0
- package/esm/use-toasts/toast-container.js +127 -0
- package/esm/use-toasts/toast-item.js +48 -0
- package/esm/use-toasts/use-toast.js +124 -0
- package/esm/utils/calculations.js +27 -0
- package/esm/utils/collections.js +138 -0
- package/esm/utils/color.js +43 -0
- package/esm/utils/layouts.js +82 -0
- package/esm/utils/prop-types.js +22 -0
- package/esm/utils/types.js +1 -0
- package/esm/utils/use-body-scroll.js +2 -0
- package/esm/utils/use-bolio-ui-context.js +27 -0
- package/esm/utils/use-click-anywhere.js +16 -0
- package/esm/utils/use-click-away.js +2 -0
- package/esm/utils/use-clipboard.js +2 -0
- package/esm/utils/use-context-state/create-bolio-ui-context.js +57 -0
- package/esm/utils/use-context-state/use-context-state.js +44 -0
- package/esm/utils/use-current-state.js +2 -0
- package/esm/utils/use-default-props.js +22 -0
- package/esm/utils/use-dom-observer.js +28 -0
- package/esm/utils/use-drag.js +75 -0
- package/esm/utils/use-portal.js +40 -0
- package/esm/utils/use-previous.js +11 -0
- package/esm/utils/use-real-shape.js +53 -0
- package/esm/utils/use-resize.js +21 -0
- package/esm/utils/use-ssr.js +20 -0
- package/esm/utils/use-warning.js +17 -0
- package/package.json +140 -0
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
function _slicedToArray(arr, i) {
|
|
8
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) {
|
|
12
|
+
if (Array.isArray(arr)) return arr;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function _iterableToArrayLimit(arr, i) {
|
|
16
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
17
|
+
|
|
18
|
+
if (_i == null) return;
|
|
19
|
+
var _arr = [];
|
|
20
|
+
var _n = true;
|
|
21
|
+
var _d = false;
|
|
22
|
+
|
|
23
|
+
var _s, _e;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
27
|
+
_arr.push(_s.value);
|
|
28
|
+
|
|
29
|
+
if (i && _arr.length === i) break;
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
_d = true;
|
|
33
|
+
_e = err;
|
|
34
|
+
} finally {
|
|
35
|
+
try {
|
|
36
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
37
|
+
} finally {
|
|
38
|
+
if (_d) throw _e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return _arr;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
46
|
+
if (!o) return;
|
|
47
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
48
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
49
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
50
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
51
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _arrayLikeToArray(arr, len) {
|
|
55
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
56
|
+
|
|
57
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
58
|
+
|
|
59
|
+
return arr2;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _nonIterableRest() {
|
|
63
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var getId = function getId() {
|
|
67
|
+
return Math.random().toString(32).slice(2, 10);
|
|
68
|
+
};
|
|
69
|
+
var isBrowser = function isBrowser() {
|
|
70
|
+
return Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
var useSSR = function useSSR() {
|
|
74
|
+
var _useState = React.useState(false),
|
|
75
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
76
|
+
browser = _useState2[0],
|
|
77
|
+
setBrowser = _useState2[1];
|
|
78
|
+
|
|
79
|
+
React.useEffect(function () {
|
|
80
|
+
setBrowser(isBrowser());
|
|
81
|
+
}, []);
|
|
82
|
+
return {
|
|
83
|
+
isBrowser: browser,
|
|
84
|
+
isServer: !browser
|
|
85
|
+
};
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
var useSSR$1 = useSSR;
|
|
89
|
+
|
|
90
|
+
var createElement = function createElement(id) {
|
|
91
|
+
var el = document.createElement('div');
|
|
92
|
+
el.setAttribute('id', id);
|
|
93
|
+
return el;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
var usePortal = function usePortal() {
|
|
97
|
+
var selectId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : getId();
|
|
98
|
+
var getContainer = arguments.length > 1 ? arguments[1] : undefined;
|
|
99
|
+
var id = "bolio-ui-".concat(selectId);
|
|
100
|
+
|
|
101
|
+
var _useSSR = useSSR$1(),
|
|
102
|
+
isBrowser = _useSSR.isBrowser;
|
|
103
|
+
|
|
104
|
+
var _useState = React.useState(isBrowser ? createElement(id) : null),
|
|
105
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
106
|
+
elSnapshot = _useState2[0],
|
|
107
|
+
setElSnapshot = _useState2[1];
|
|
108
|
+
|
|
109
|
+
React.useEffect(function () {
|
|
110
|
+
var customContainer = getContainer ? getContainer() : null;
|
|
111
|
+
var parentElement = customContainer || document.body;
|
|
112
|
+
var hasElement = parentElement.querySelector("#".concat(id));
|
|
113
|
+
var el = hasElement || createElement(id);
|
|
114
|
+
|
|
115
|
+
if (!hasElement) {
|
|
116
|
+
parentElement.appendChild(el);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
setElSnapshot(el);
|
|
120
|
+
}, []);
|
|
121
|
+
return elSnapshot;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
var usePortal$1 = usePortal;
|
|
125
|
+
|
|
126
|
+
var warningStack = {};
|
|
127
|
+
|
|
128
|
+
var useWarning = function useWarning(message, component) {
|
|
129
|
+
var tag = component ? " [".concat(component, "]") : ' ';
|
|
130
|
+
var log = "[Bolio UI]".concat(tag, ": ").concat(message);
|
|
131
|
+
if (typeof console === 'undefined') return;
|
|
132
|
+
if (warningStack[log]) return;
|
|
133
|
+
warningStack[log] = true;
|
|
134
|
+
|
|
135
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
136
|
+
return console.error(log);
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
console.warn(log);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
var useWarning$1 = useWarning;
|
|
143
|
+
|
|
144
|
+
var defaultOptions = {
|
|
145
|
+
onError: function onError() {
|
|
146
|
+
return useWarning$1('Failed to copy.', 'use-clipboard');
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
var useClipboard = function useClipboard() {
|
|
151
|
+
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : defaultOptions;
|
|
152
|
+
var el = usePortal$1('clipboard');
|
|
153
|
+
|
|
154
|
+
var copyText = function copyText(el, text) {
|
|
155
|
+
if (!el || !text) return;
|
|
156
|
+
var selection = window.getSelection();
|
|
157
|
+
if (!selection) return;
|
|
158
|
+
el.style.whiteSpace = 'pre';
|
|
159
|
+
el.textContent = text;
|
|
160
|
+
var range = window.document.createRange();
|
|
161
|
+
selection.removeAllRanges();
|
|
162
|
+
range.selectNode(el);
|
|
163
|
+
selection.addRange(range);
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
window.document.execCommand('copy');
|
|
167
|
+
} catch (e) {
|
|
168
|
+
options.onError && options.onError();
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
selection.removeAllRanges();
|
|
172
|
+
|
|
173
|
+
if (el) {
|
|
174
|
+
el.textContent = '';
|
|
175
|
+
}
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
var copy = React.useCallback(function (text) {
|
|
179
|
+
copyText(el, text);
|
|
180
|
+
}, [el]);
|
|
181
|
+
return {
|
|
182
|
+
copy: copy
|
|
183
|
+
};
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
var useClipboard$1 = useClipboard;
|
|
187
|
+
|
|
188
|
+
exports["default"] = useClipboard$1;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
function _slicedToArray(arr, i) {
|
|
8
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
function _arrayWithHoles(arr) {
|
|
12
|
+
if (Array.isArray(arr)) return arr;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
function _iterableToArrayLimit(arr, i) {
|
|
16
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
17
|
+
|
|
18
|
+
if (_i == null) return;
|
|
19
|
+
var _arr = [];
|
|
20
|
+
var _n = true;
|
|
21
|
+
var _d = false;
|
|
22
|
+
|
|
23
|
+
var _s, _e;
|
|
24
|
+
|
|
25
|
+
try {
|
|
26
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
27
|
+
_arr.push(_s.value);
|
|
28
|
+
|
|
29
|
+
if (i && _arr.length === i) break;
|
|
30
|
+
}
|
|
31
|
+
} catch (err) {
|
|
32
|
+
_d = true;
|
|
33
|
+
_e = err;
|
|
34
|
+
} finally {
|
|
35
|
+
try {
|
|
36
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
37
|
+
} finally {
|
|
38
|
+
if (_d) throw _e;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return _arr;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
46
|
+
if (!o) return;
|
|
47
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
48
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
49
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
50
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
51
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function _arrayLikeToArray(arr, len) {
|
|
55
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
56
|
+
|
|
57
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
58
|
+
|
|
59
|
+
return arr2;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function _nonIterableRest() {
|
|
63
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
var useCurrentState = function useCurrentState(initialState) {
|
|
67
|
+
var _useState = react.useState(function () {
|
|
68
|
+
return typeof initialState === 'function' ? initialState() : initialState;
|
|
69
|
+
}),
|
|
70
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
71
|
+
state = _useState2[0],
|
|
72
|
+
setState = _useState2[1];
|
|
73
|
+
|
|
74
|
+
var ref = react.useRef(initialState);
|
|
75
|
+
react.useEffect(function () {
|
|
76
|
+
ref.current = state;
|
|
77
|
+
}, [state]);
|
|
78
|
+
|
|
79
|
+
var setValue = function setValue(val) {
|
|
80
|
+
var result = typeof val === 'function' ? val(ref.current) : val;
|
|
81
|
+
ref.current = result;
|
|
82
|
+
setState(result);
|
|
83
|
+
};
|
|
84
|
+
|
|
85
|
+
return [state, setValue, ref];
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
var useCurrentState$1 = useCurrentState;
|
|
89
|
+
|
|
90
|
+
exports["default"] = useCurrentState$1;
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var react = require('react');
|
|
6
|
+
|
|
7
|
+
function _typeof(obj) {
|
|
8
|
+
"@babel/helpers - typeof";
|
|
9
|
+
|
|
10
|
+
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) {
|
|
11
|
+
return typeof obj;
|
|
12
|
+
} : function (obj) {
|
|
13
|
+
return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
|
|
14
|
+
}, _typeof(obj);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
function _slicedToArray(arr, i) {
|
|
18
|
+
return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function _arrayWithHoles(arr) {
|
|
22
|
+
if (Array.isArray(arr)) return arr;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
function _iterableToArrayLimit(arr, i) {
|
|
26
|
+
var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
|
|
27
|
+
|
|
28
|
+
if (_i == null) return;
|
|
29
|
+
var _arr = [];
|
|
30
|
+
var _n = true;
|
|
31
|
+
var _d = false;
|
|
32
|
+
|
|
33
|
+
var _s, _e;
|
|
34
|
+
|
|
35
|
+
try {
|
|
36
|
+
for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) {
|
|
37
|
+
_arr.push(_s.value);
|
|
38
|
+
|
|
39
|
+
if (i && _arr.length === i) break;
|
|
40
|
+
}
|
|
41
|
+
} catch (err) {
|
|
42
|
+
_d = true;
|
|
43
|
+
_e = err;
|
|
44
|
+
} finally {
|
|
45
|
+
try {
|
|
46
|
+
if (!_n && _i["return"] != null) _i["return"]();
|
|
47
|
+
} finally {
|
|
48
|
+
if (_d) throw _e;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
return _arr;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _unsupportedIterableToArray(o, minLen) {
|
|
56
|
+
if (!o) return;
|
|
57
|
+
if (typeof o === "string") return _arrayLikeToArray(o, minLen);
|
|
58
|
+
var n = Object.prototype.toString.call(o).slice(8, -1);
|
|
59
|
+
if (n === "Object" && o.constructor) n = o.constructor.name;
|
|
60
|
+
if (n === "Map" || n === "Set") return Array.from(o);
|
|
61
|
+
if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
function _arrayLikeToArray(arr, len) {
|
|
65
|
+
if (len == null || len > arr.length) len = arr.length;
|
|
66
|
+
|
|
67
|
+
for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i];
|
|
68
|
+
|
|
69
|
+
return arr2;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function _nonIterableRest() {
|
|
73
|
+
throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
var useCurrentState = function useCurrentState(initialState) {
|
|
77
|
+
var _useState = react.useState(function () {
|
|
78
|
+
return typeof initialState === 'function' ? initialState() : initialState;
|
|
79
|
+
}),
|
|
80
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
81
|
+
state = _useState2[0],
|
|
82
|
+
setState = _useState2[1];
|
|
83
|
+
|
|
84
|
+
var ref = react.useRef(initialState);
|
|
85
|
+
react.useEffect(function () {
|
|
86
|
+
ref.current = state;
|
|
87
|
+
}, [state]);
|
|
88
|
+
|
|
89
|
+
var setValue = function setValue(val) {
|
|
90
|
+
var result = typeof val === 'function' ? val(ref.current) : val;
|
|
91
|
+
ref.current = result;
|
|
92
|
+
setState(result);
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
return [state, setValue, ref];
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
var useCurrentState$1 = useCurrentState;
|
|
99
|
+
|
|
100
|
+
var useInput = function useInput(initialValue) {
|
|
101
|
+
var _useCurrentState = useCurrentState$1(initialValue),
|
|
102
|
+
_useCurrentState2 = _slicedToArray(_useCurrentState, 3),
|
|
103
|
+
state = _useCurrentState2[0],
|
|
104
|
+
setState = _useCurrentState2[1],
|
|
105
|
+
currentRef = _useCurrentState2[2];
|
|
106
|
+
|
|
107
|
+
return {
|
|
108
|
+
state: state,
|
|
109
|
+
setState: setState,
|
|
110
|
+
currentRef: currentRef,
|
|
111
|
+
reset: function reset() {
|
|
112
|
+
return setState(initialValue);
|
|
113
|
+
},
|
|
114
|
+
bindings: {
|
|
115
|
+
value: state,
|
|
116
|
+
onChange: function onChange(event) {
|
|
117
|
+
if (_typeof(event) === 'object' && event.target) {
|
|
118
|
+
setState(event.target.value);
|
|
119
|
+
} else {
|
|
120
|
+
setState(event);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
var useInput$1 = useInput;
|
|
128
|
+
|
|
129
|
+
exports["default"] = useInput$1;
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* KeyBinding Codes
|
|
9
|
+
* The content of this file is based on the design of the open source project "microsoft/vscode",
|
|
10
|
+
* Copyright (c) Microsoft Corporation. All rights reserved.
|
|
11
|
+
*
|
|
12
|
+
* We inherit the KeyMod values from "microsoft/vscode",
|
|
13
|
+
* but use the Browser's KeyboardEvent event implementation, and all values are used only as identification.
|
|
14
|
+
*/
|
|
15
|
+
exports.KeyCode = void 0;
|
|
16
|
+
|
|
17
|
+
(function (KeyCode) {
|
|
18
|
+
KeyCode[KeyCode["Unknown"] = 0] = "Unknown";
|
|
19
|
+
KeyCode[KeyCode["Backspace"] = 8] = "Backspace";
|
|
20
|
+
KeyCode[KeyCode["Tab"] = 9] = "Tab";
|
|
21
|
+
KeyCode[KeyCode["Enter"] = 13] = "Enter";
|
|
22
|
+
KeyCode[KeyCode["Shift"] = 16] = "Shift";
|
|
23
|
+
KeyCode[KeyCode["Ctrl"] = 17] = "Ctrl";
|
|
24
|
+
KeyCode[KeyCode["Alt"] = 18] = "Alt";
|
|
25
|
+
KeyCode[KeyCode["PauseBreak"] = 19] = "PauseBreak";
|
|
26
|
+
KeyCode[KeyCode["CapsLock"] = 20] = "CapsLock";
|
|
27
|
+
KeyCode[KeyCode["Escape"] = 27] = "Escape";
|
|
28
|
+
KeyCode[KeyCode["Space"] = 32] = "Space";
|
|
29
|
+
KeyCode[KeyCode["PageUp"] = 33] = "PageUp";
|
|
30
|
+
KeyCode[KeyCode["PageDown"] = 34] = "PageDown";
|
|
31
|
+
KeyCode[KeyCode["End"] = 35] = "End";
|
|
32
|
+
KeyCode[KeyCode["Home"] = 36] = "Home";
|
|
33
|
+
KeyCode[KeyCode["LeftArrow"] = 37] = "LeftArrow";
|
|
34
|
+
KeyCode[KeyCode["UpArrow"] = 38] = "UpArrow";
|
|
35
|
+
KeyCode[KeyCode["RightArrow"] = 39] = "RightArrow";
|
|
36
|
+
KeyCode[KeyCode["DownArrow"] = 40] = "DownArrow";
|
|
37
|
+
KeyCode[KeyCode["Insert"] = 45] = "Insert";
|
|
38
|
+
KeyCode[KeyCode["Delete"] = 46] = "Delete";
|
|
39
|
+
KeyCode[KeyCode["KEY_0"] = 48] = "KEY_0";
|
|
40
|
+
KeyCode[KeyCode["KEY_1"] = 49] = "KEY_1";
|
|
41
|
+
KeyCode[KeyCode["KEY_2"] = 50] = "KEY_2";
|
|
42
|
+
KeyCode[KeyCode["KEY_3"] = 51] = "KEY_3";
|
|
43
|
+
KeyCode[KeyCode["KEY_4"] = 52] = "KEY_4";
|
|
44
|
+
KeyCode[KeyCode["KEY_5"] = 53] = "KEY_5";
|
|
45
|
+
KeyCode[KeyCode["KEY_6"] = 54] = "KEY_6";
|
|
46
|
+
KeyCode[KeyCode["KEY_7"] = 55] = "KEY_7";
|
|
47
|
+
KeyCode[KeyCode["KEY_8"] = 56] = "KEY_8";
|
|
48
|
+
KeyCode[KeyCode["KEY_9"] = 57] = "KEY_9";
|
|
49
|
+
KeyCode[KeyCode["KEY_A"] = 65] = "KEY_A";
|
|
50
|
+
KeyCode[KeyCode["KEY_B"] = 66] = "KEY_B";
|
|
51
|
+
KeyCode[KeyCode["KEY_C"] = 67] = "KEY_C";
|
|
52
|
+
KeyCode[KeyCode["KEY_D"] = 68] = "KEY_D";
|
|
53
|
+
KeyCode[KeyCode["KEY_E"] = 69] = "KEY_E";
|
|
54
|
+
KeyCode[KeyCode["KEY_F"] = 70] = "KEY_F";
|
|
55
|
+
KeyCode[KeyCode["KEY_G"] = 71] = "KEY_G";
|
|
56
|
+
KeyCode[KeyCode["KEY_H"] = 72] = "KEY_H";
|
|
57
|
+
KeyCode[KeyCode["KEY_I"] = 73] = "KEY_I";
|
|
58
|
+
KeyCode[KeyCode["KEY_J"] = 74] = "KEY_J";
|
|
59
|
+
KeyCode[KeyCode["KEY_K"] = 75] = "KEY_K";
|
|
60
|
+
KeyCode[KeyCode["KEY_L"] = 76] = "KEY_L";
|
|
61
|
+
KeyCode[KeyCode["KEY_M"] = 77] = "KEY_M";
|
|
62
|
+
KeyCode[KeyCode["KEY_N"] = 78] = "KEY_N";
|
|
63
|
+
KeyCode[KeyCode["KEY_O"] = 79] = "KEY_O";
|
|
64
|
+
KeyCode[KeyCode["KEY_P"] = 80] = "KEY_P";
|
|
65
|
+
KeyCode[KeyCode["KEY_Q"] = 81] = "KEY_Q";
|
|
66
|
+
KeyCode[KeyCode["KEY_R"] = 82] = "KEY_R";
|
|
67
|
+
KeyCode[KeyCode["KEY_S"] = 83] = "KEY_S";
|
|
68
|
+
KeyCode[KeyCode["KEY_T"] = 84] = "KEY_T";
|
|
69
|
+
KeyCode[KeyCode["KEY_U"] = 85] = "KEY_U";
|
|
70
|
+
KeyCode[KeyCode["KEY_V"] = 86] = "KEY_V";
|
|
71
|
+
KeyCode[KeyCode["KEY_W"] = 87] = "KEY_W";
|
|
72
|
+
KeyCode[KeyCode["KEY_X"] = 88] = "KEY_X";
|
|
73
|
+
KeyCode[KeyCode["KEY_Y"] = 89] = "KEY_Y";
|
|
74
|
+
KeyCode[KeyCode["KEY_Z"] = 90] = "KEY_Z";
|
|
75
|
+
KeyCode[KeyCode["Meta"] = 91] = "Meta";
|
|
76
|
+
KeyCode[KeyCode["F1"] = 112] = "F1";
|
|
77
|
+
KeyCode[KeyCode["F2"] = 113] = "F2";
|
|
78
|
+
KeyCode[KeyCode["F3"] = 114] = "F3";
|
|
79
|
+
KeyCode[KeyCode["F4"] = 115] = "F4";
|
|
80
|
+
KeyCode[KeyCode["F5"] = 116] = "F5";
|
|
81
|
+
KeyCode[KeyCode["F6"] = 117] = "F6";
|
|
82
|
+
KeyCode[KeyCode["F7"] = 118] = "F7";
|
|
83
|
+
KeyCode[KeyCode["F8"] = 119] = "F8";
|
|
84
|
+
KeyCode[KeyCode["F9"] = 120] = "F9";
|
|
85
|
+
KeyCode[KeyCode["F10"] = 121] = "F10";
|
|
86
|
+
KeyCode[KeyCode["F11"] = 122] = "F11";
|
|
87
|
+
KeyCode[KeyCode["F12"] = 123] = "F12";
|
|
88
|
+
KeyCode[KeyCode["NumLock"] = 144] = "NumLock";
|
|
89
|
+
KeyCode[KeyCode["ScrollLock"] = 145] = "ScrollLock";
|
|
90
|
+
KeyCode[KeyCode["Equal"] = 187] = "Equal";
|
|
91
|
+
KeyCode[KeyCode["Minus"] = 189] = "Minus";
|
|
92
|
+
KeyCode[KeyCode["Backquote"] = 192] = "Backquote";
|
|
93
|
+
KeyCode[KeyCode["Backslash"] = 220] = "Backslash";
|
|
94
|
+
})(exports.KeyCode || (exports.KeyCode = {}));
|
|
95
|
+
|
|
96
|
+
exports.KeyMod = void 0;
|
|
97
|
+
|
|
98
|
+
(function (KeyMod) {
|
|
99
|
+
KeyMod[KeyMod["CtrlCmd"] = 2048] = "CtrlCmd";
|
|
100
|
+
KeyMod[KeyMod["Shift"] = 1024] = "Shift";
|
|
101
|
+
KeyMod[KeyMod["Alt"] = 512] = "Alt";
|
|
102
|
+
KeyMod[KeyMod["WinCtrl"] = 256] = "WinCtrl";
|
|
103
|
+
})(exports.KeyMod || (exports.KeyMod = {}));
|
|
104
|
+
|
|
105
|
+
var isBrowser = function isBrowser() {
|
|
106
|
+
return Boolean(typeof window !== 'undefined' && window.document && window.document.createElement);
|
|
107
|
+
};
|
|
108
|
+
var isMac = function isMac() {
|
|
109
|
+
if (!isBrowser()) return false;
|
|
110
|
+
return navigator.platform.toUpperCase().indexOf('MAC') >= 0;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
/* istanbul ignore next */
|
|
114
|
+
|
|
115
|
+
var getCtrlKeysByPlatform = function getCtrlKeysByPlatform() {
|
|
116
|
+
return {
|
|
117
|
+
CtrlCmd: isMac() ? 'metaKey' : 'ctrlKey',
|
|
118
|
+
WinCtrl: isMac() ? 'ctrlKey' : 'metaKey'
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
var getActiveModMap = function getActiveModMap(bindings) {
|
|
122
|
+
var modBindings = bindings.filter(function (item) {
|
|
123
|
+
return !!exports.KeyMod[item];
|
|
124
|
+
});
|
|
125
|
+
var activeModMap = {
|
|
126
|
+
CtrlCmd: false,
|
|
127
|
+
Shift: false,
|
|
128
|
+
Alt: false,
|
|
129
|
+
WinCtrl: false
|
|
130
|
+
};
|
|
131
|
+
modBindings.forEach(function (code) {
|
|
132
|
+
var modKey = exports.KeyMod[code];
|
|
133
|
+
activeModMap[modKey] = true;
|
|
134
|
+
});
|
|
135
|
+
return activeModMap;
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
var useKeyboard = function useKeyboard(handler, keyBindings) {
|
|
139
|
+
var options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
|
|
140
|
+
var bindings = Array.isArray(keyBindings) ? keyBindings : [keyBindings];
|
|
141
|
+
var _options$disableGloba = options.disableGlobalEvent,
|
|
142
|
+
disableGlobalEvent = _options$disableGloba === void 0 ? false : _options$disableGloba,
|
|
143
|
+
_options$capture = options.capture,
|
|
144
|
+
capture = _options$capture === void 0 ? false : _options$capture,
|
|
145
|
+
_options$stopPropagat = options.stopPropagation,
|
|
146
|
+
stopPropagation = _options$stopPropagat === void 0 ? false : _options$stopPropagat,
|
|
147
|
+
_options$preventDefau = options.preventDefault,
|
|
148
|
+
preventDefault = _options$preventDefau === void 0 ? true : _options$preventDefau,
|
|
149
|
+
_options$event = options.event,
|
|
150
|
+
event = _options$event === void 0 ? 'keydown' : _options$event;
|
|
151
|
+
var activeModMap = getActiveModMap(bindings);
|
|
152
|
+
var keyCode = bindings.filter(function (item) {
|
|
153
|
+
return !exports.KeyMod[item];
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
var _getCtrlKeysByPlatfor = getCtrlKeysByPlatform(),
|
|
157
|
+
CtrlCmd = _getCtrlKeysByPlatfor.CtrlCmd,
|
|
158
|
+
WinCtrl = _getCtrlKeysByPlatfor.WinCtrl;
|
|
159
|
+
|
|
160
|
+
var eventHandler = function eventHandler(event) {
|
|
161
|
+
if (activeModMap.Shift && !event.shiftKey) return;
|
|
162
|
+
if (activeModMap.Alt && !event.altKey) return;
|
|
163
|
+
if (activeModMap.CtrlCmd && !event[CtrlCmd]) return;
|
|
164
|
+
if (activeModMap.WinCtrl && !event[WinCtrl]) return;
|
|
165
|
+
var hitOne = keyCode.find(function (k) {
|
|
166
|
+
return k === event.keyCode;
|
|
167
|
+
});
|
|
168
|
+
if (keyCode && !hitOne) return;
|
|
169
|
+
|
|
170
|
+
if (stopPropagation) {
|
|
171
|
+
event.stopPropagation();
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
if (preventDefault) {
|
|
175
|
+
event.preventDefault();
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
handler && handler(event);
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
React.useEffect(function () {
|
|
182
|
+
if (!disableGlobalEvent) {
|
|
183
|
+
document.addEventListener(event, eventHandler);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
return function () {
|
|
187
|
+
document.removeEventListener(event, eventHandler);
|
|
188
|
+
};
|
|
189
|
+
}, [disableGlobalEvent]);
|
|
190
|
+
|
|
191
|
+
var elementBindingHandler = function elementBindingHandler(elementEventType) {
|
|
192
|
+
var isCapture = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
|
|
193
|
+
if (elementEventType !== event) return function () {};
|
|
194
|
+
if (isCapture !== capture) return function () {};
|
|
195
|
+
return function (e) {
|
|
196
|
+
return eventHandler(e);
|
|
197
|
+
};
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
bindings: {
|
|
202
|
+
onKeyDown: elementBindingHandler('keydown'),
|
|
203
|
+
onKeyDownCapture: elementBindingHandler('keydown', true),
|
|
204
|
+
onKeyPress: elementBindingHandler('keypress'),
|
|
205
|
+
onKeyPressCapture: elementBindingHandler('keypress', true),
|
|
206
|
+
onKeyUp: elementBindingHandler('keyup'),
|
|
207
|
+
onKeyUpCapture: elementBindingHandler('keyup', true)
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
};
|
|
211
|
+
|
|
212
|
+
var useKeyboard$1 = useKeyboard;
|
|
213
|
+
|
|
214
|
+
exports["default"] = useKeyboard$1;
|