@basic-ui/core 0.0.38 → 0.0.39
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/build/cjs/index.js.map +1 -1
- package/build/esm/Accordion/Accordion.d.ts +1 -1
- package/build/esm/Accordion/Accordion.js +23 -17
- package/build/esm/Accordion/Accordion.js.map +1 -1
- package/build/esm/Accordion/AccordionBody.d.ts +1 -1
- package/build/esm/Accordion/AccordionBody.js +24 -15
- package/build/esm/Accordion/AccordionBody.js.map +1 -1
- package/build/esm/Accordion/AccordionHeader.d.ts +1 -1
- package/build/esm/Accordion/AccordionHeader.js +46 -31
- package/build/esm/Accordion/AccordionHeader.js.map +1 -1
- package/build/esm/Accordion/AccordionItem.d.ts +1 -1
- package/build/esm/Accordion/AccordionItem.js +17 -16
- package/build/esm/Accordion/AccordionItem.js.map +1 -1
- package/build/esm/Accordion/context.d.ts +1 -1
- package/build/esm/Accordion/context.js +12 -10
- package/build/esm/Accordion/context.js.map +1 -1
- package/build/esm/CheckBox/CheckBox.d.ts +1 -1
- package/build/esm/CheckBox/CheckBox.js +20 -12
- package/build/esm/CheckBox/CheckBox.js.map +1 -1
- package/build/esm/ComboBox/Combobox.d.ts +1 -1
- package/build/esm/ComboBox/Combobox.js +53 -46
- package/build/esm/ComboBox/Combobox.js.map +1 -1
- package/build/esm/ComboBox/ComboboxButton.d.ts +1 -1
- package/build/esm/ComboBox/ComboboxButton.js +20 -20
- package/build/esm/ComboBox/ComboboxButton.js.map +1 -1
- package/build/esm/ComboBox/ComboboxInput.d.ts +1 -1
- package/build/esm/ComboBox/ComboboxInput.js +53 -50
- package/build/esm/ComboBox/ComboboxInput.js.map +1 -1
- package/build/esm/ComboBox/ComboboxLabel.d.ts +1 -1
- package/build/esm/ComboBox/ComboboxLabel.js +12 -12
- package/build/esm/ComboBox/ComboboxLabel.js.map +1 -1
- package/build/esm/ComboBox/ComboboxList.d.ts +1 -1
- package/build/esm/ComboBox/ComboboxList.js +16 -17
- package/build/esm/ComboBox/ComboboxList.js.map +1 -1
- package/build/esm/ComboBox/ComboboxOption.d.ts +1 -1
- package/build/esm/ComboBox/ComboboxOption.js +32 -34
- package/build/esm/ComboBox/ComboboxOption.js.map +1 -1
- package/build/esm/ComboBox/ComboboxPopover.d.ts +1 -1
- package/build/esm/ComboBox/ComboboxPopover.js +16 -17
- package/build/esm/ComboBox/ComboboxPopover.js.map +1 -1
- package/build/esm/ComboBox/context.d.ts +3 -3
- package/build/esm/ComboBox/context.js +6 -5
- package/build/esm/ComboBox/context.js.map +1 -1
- package/build/esm/ComboBox/hooks.d.ts +1 -1
- package/build/esm/ComboBox/hooks.js +82 -115
- package/build/esm/ComboBox/hooks.js.map +1 -1
- package/build/esm/ComboBox/makeHash.js +3 -3
- package/build/esm/ComboBox/makeHash.js.map +1 -1
- package/build/esm/FocusLock/FocusLock.d.ts +1 -1
- package/build/esm/FocusLock/FocusLock.js +18 -16
- package/build/esm/FocusLock/FocusLock.js.map +1 -1
- package/build/esm/FocusLock/tabUtils.js +4 -4
- package/build/esm/FocusLock/tabUtils.js.map +1 -1
- package/build/esm/FocusLock/useFocusLock.js +10 -11
- package/build/esm/FocusLock/useFocusLock.js.map +1 -1
- package/build/esm/List/List.d.ts +1 -1
- package/build/esm/List/List.js +6 -6
- package/build/esm/List/List.js.map +1 -1
- package/build/esm/List/ListItem.d.ts +1 -1
- package/build/esm/List/ListItem.js +6 -6
- package/build/esm/List/ListItem.js.map +1 -1
- package/build/esm/List/context.js +3 -3
- package/build/esm/List/context.js.map +1 -1
- package/build/esm/Menu/Menu.d.ts +1 -1
- package/build/esm/Menu/Menu.js +30 -21
- package/build/esm/Menu/Menu.js.map +1 -1
- package/build/esm/Menu/MenuButton.d.ts +1 -1
- package/build/esm/Menu/MenuButton.js +28 -24
- package/build/esm/Menu/MenuButton.js.map +1 -1
- package/build/esm/Menu/MenuItem.d.ts +1 -1
- package/build/esm/Menu/MenuItem.js +24 -24
- package/build/esm/Menu/MenuItem.js.map +1 -1
- package/build/esm/Menu/MenuList.d.ts +1 -1
- package/build/esm/Menu/MenuList.js +62 -45
- package/build/esm/Menu/MenuList.js.map +1 -1
- package/build/esm/Menu/MenuPopover.d.ts +2 -2
- package/build/esm/Menu/MenuPopover.js +9 -10
- package/build/esm/Menu/MenuPopover.js.map +1 -1
- package/build/esm/Menu/context.d.ts +1 -1
- package/build/esm/Menu/context.js +11 -8
- package/build/esm/Menu/context.js.map +1 -1
- package/build/esm/Modal/Modal.d.ts +2 -2
- package/build/esm/Modal/Modal.js +12 -10
- package/build/esm/Modal/Modal.js.map +1 -1
- package/build/esm/Modal/ModalBackdrop.d.ts +1 -1
- package/build/esm/Modal/ModalBackdrop.js +21 -19
- package/build/esm/Modal/ModalBackdrop.js.map +1 -1
- package/build/esm/Popper/Popper.d.ts +2 -2
- package/build/esm/Popper/Popper.js +47 -37
- package/build/esm/Popper/Popper.js.map +1 -1
- package/build/esm/Popper/PopperArrow.d.ts +1 -1
- package/build/esm/Popper/PopperArrow.js +9 -9
- package/build/esm/Popper/PopperArrow.js.map +1 -1
- package/build/esm/Popper/context.d.ts +1 -1
- package/build/esm/Popper/context.js +5 -3
- package/build/esm/Popper/context.js.map +1 -1
- package/build/esm/Portal/Portal.d.ts +1 -1
- package/build/esm/Portal/Portal.js +6 -5
- package/build/esm/Portal/Portal.js.map +1 -1
- package/build/esm/RadioButton/RadioButton.d.ts +2 -2
- package/build/esm/RadioButton/RadioButton.js +13 -13
- package/build/esm/RadioButton/RadioButton.js.map +1 -1
- package/build/esm/RadioButton/RadioGroup.d.ts +2 -2
- package/build/esm/RadioButton/RadioGroup.js +23 -16
- package/build/esm/RadioButton/RadioGroup.js.map +1 -1
- package/build/esm/RadioButton/context.js +6 -5
- package/build/esm/RadioButton/context.js.map +1 -1
- package/build/esm/SkipNav/SkipNav.d.ts +1 -1
- package/build/esm/SkipNav/SkipNav.js +6 -6
- package/build/esm/SkipNav/SkipNav.js.map +1 -1
- package/build/esm/Spinner/Spinner.d.ts +1 -1
- package/build/esm/Spinner/Spinner.js +42 -31
- package/build/esm/Spinner/Spinner.js.map +1 -1
- package/build/esm/Spinner/SpinnerButton.d.ts +1 -1
- package/build/esm/Spinner/SpinnerButton.js +12 -12
- package/build/esm/Spinner/SpinnerButton.js.map +1 -1
- package/build/esm/Spinner/context.js +6 -5
- package/build/esm/Spinner/context.js.map +1 -1
- package/build/esm/Tabs/Tab.d.ts +1 -1
- package/build/esm/Tabs/Tab.js +30 -29
- package/build/esm/Tabs/Tab.js.map +1 -1
- package/build/esm/Tabs/TabList.d.ts +1 -1
- package/build/esm/Tabs/TabList.js +25 -21
- package/build/esm/Tabs/TabList.js.map +1 -1
- package/build/esm/Tabs/TabPanel.d.ts +1 -1
- package/build/esm/Tabs/TabPanel.js +13 -12
- package/build/esm/Tabs/TabPanel.js.map +1 -1
- package/build/esm/Tabs/TabPanels.d.ts +1 -1
- package/build/esm/Tabs/TabPanels.js +14 -12
- package/build/esm/Tabs/TabPanels.js.map +1 -1
- package/build/esm/Tabs/Tabs.d.ts +1 -1
- package/build/esm/Tabs/Tabs.js +28 -14
- package/build/esm/Tabs/Tabs.js.map +1 -1
- package/build/esm/Tabs/context.d.ts +1 -1
- package/build/esm/Tabs/context.js +12 -10
- package/build/esm/Tabs/context.js.map +1 -1
- package/build/esm/Tooltip/Tooltip.d.ts +2 -1
- package/build/esm/Tooltip/Tooltip.js +17 -15
- package/build/esm/Tooltip/Tooltip.js.map +1 -1
- package/build/esm/Tooltip/stateMachine.js +56 -80
- package/build/esm/Tooltip/stateMachine.js.map +1 -1
- package/build/esm/Tooltip/useTooltip.d.ts +1 -1
- package/build/esm/Tooltip/useTooltip.js +31 -29
- package/build/esm/Tooltip/useTooltip.js.map +1 -1
- package/build/esm/hooks/useAutoFocus.js +1 -1
- package/build/esm/hooks/useAutoFocus.js.map +1 -1
- package/build/esm/hooks/useChildrenCounter.d.ts +1 -1
- package/build/esm/hooks/useChildrenCounter.js +6 -4
- package/build/esm/hooks/useChildrenCounter.js.map +1 -1
- package/build/esm/hooks/useControlledState.d.ts +1 -1
- package/build/esm/hooks/useControlledState.js +7 -2
- package/build/esm/hooks/useControlledState.js.map +1 -1
- package/build/esm/hooks/useFocusReturn.d.ts +1 -1
- package/build/esm/hooks/useFocusReturn.js +6 -6
- package/build/esm/hooks/useFocusReturn.js.map +1 -1
- package/build/esm/hooks/useFocusState.js +13 -9
- package/build/esm/hooks/useFocusState.js.map +1 -1
- package/build/esm/hooks/useGestureHandlers.js +59 -63
- package/build/esm/hooks/useGestureHandlers.js.map +1 -1
- package/build/esm/hooks/useMeasure.js +13 -7
- package/build/esm/hooks/useMeasure.js.map +1 -1
- package/build/esm/hooks/useOnClickOutside.js +5 -4
- package/build/esm/hooks/useOnClickOutside.js.map +1 -1
- package/build/esm/hooks/useOnKeyDown.js +4 -3
- package/build/esm/hooks/useOnKeyDown.js.map +1 -1
- package/build/esm/hooks/useReducerMachine.d.ts +1 -1
- package/build/esm/hooks/useReducerMachine.js +13 -10
- package/build/esm/hooks/useReducerMachine.js.map +1 -1
- package/build/esm/hooks/useRemoveBodyScroll.js +4 -4
- package/build/esm/hooks/useRemoveBodyScroll.js.map +1 -1
- package/build/esm/hooks/useScope.d.ts +1 -1
- package/build/esm/hooks/useScope.js +10 -12
- package/build/esm/hooks/useScope.js.map +1 -1
- package/build/esm/hooks/useThrottle.js +10 -5
- package/build/esm/hooks/useThrottle.js.map +1 -1
- package/build/esm/utils/assignRef.d.ts +1 -1
- package/build/esm/utils/assignRef.js +7 -3
- package/build/esm/utils/assignRef.js.map +1 -1
- package/build/esm/utils/createSubscription.js +7 -5
- package/build/esm/utils/createSubscription.js.map +1 -1
- package/build/esm/utils/rubberBandClamp.js +5 -2
- package/build/esm/utils/rubberBandClamp.js.map +1 -1
- package/build/esm/utils/wrapEvent.js +7 -3
- package/build/esm/utils/wrapEvent.js.map +1 -1
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
- package/src/Accordion/Accordion.story.tsx +1 -0
- package/src/Accordion/Accordion.tsx +4 -2
- package/src/Accordion/AccordionBody.tsx +4 -4
- package/src/Accordion/AccordionHeader.tsx +7 -8
- package/src/Accordion/AccordionItem.tsx +4 -2
- package/src/Accordion/context.ts +2 -1
- package/src/CheckBox/CheckBox.tsx +2 -1
- package/src/ComboBox/ComboBox.story.tsx +3 -3
- package/src/ComboBox/Combobox.tsx +8 -10
- package/src/ComboBox/ComboboxButton.tsx +4 -9
- package/src/ComboBox/ComboboxInput.tsx +2 -1
- package/src/ComboBox/ComboboxLabel.tsx +2 -1
- package/src/ComboBox/ComboboxList.tsx +2 -1
- package/src/ComboBox/ComboboxOption.tsx +1 -1
- package/src/ComboBox/ComboboxPopover.tsx +2 -1
- package/src/ComboBox/context.ts +4 -3
- package/src/ComboBox/hooks.tsx +6 -9
- package/src/FocusLock/FocusLock.tsx +2 -1
- package/src/FocusLock/useFocusLock.ts +1 -0
- package/src/List/List.tsx +1 -1
- package/src/List/ListItem.tsx +1 -1
- package/src/Menu/Menu.story.tsx +6 -5
- package/src/Menu/Menu.tsx +4 -2
- package/src/Menu/MenuButton.tsx +4 -8
- package/src/Menu/MenuItem.tsx +2 -1
- package/src/Menu/MenuList.tsx +4 -8
- package/src/Menu/MenuPopover.tsx +4 -2
- package/src/Menu/context.ts +2 -1
- package/src/Modal/Modal.story.tsx +1 -0
- package/src/Modal/Modal.tsx +4 -2
- package/src/Modal/ModalBackdrop.tsx +2 -1
- package/src/Modal/NavDrawer.story.tsx +3 -3
- package/src/Popper/Popper.story.tsx +3 -4
- package/src/Popper/Popper.tsx +8 -7
- package/src/Popper/PopperArrow.tsx +2 -1
- package/src/Popper/context.ts +2 -1
- package/src/Portal/Portal.tsx +1 -1
- package/src/RadioButton/RadioButton.story.tsx +1 -0
- package/src/RadioButton/RadioButton.tsx +4 -2
- package/src/RadioButton/RadioGroup.tsx +4 -2
- package/src/SkipNav/SkipNav.tsx +1 -1
- package/src/Spinner/Spinner.story.tsx +1 -0
- package/src/Spinner/Spinner.tsx +2 -1
- package/src/Spinner/SpinnerButton.tsx +2 -1
- package/src/Tabs/Tab.story.tsx +1 -0
- package/src/Tabs/Tab.tsx +4 -4
- package/src/Tabs/TabList.tsx +2 -1
- package/src/Tabs/TabPanel.tsx +2 -1
- package/src/Tabs/TabPanels.tsx +1 -1
- package/src/Tabs/Tabs.tsx +2 -1
- package/src/Tabs/context.ts +2 -1
- package/src/Tooltip/Tooltip.story.tsx +2 -1
- package/src/Tooltip/Tooltip.tsx +3 -7
- package/src/Tooltip/stateMachine.ts +1 -1
- package/src/Tooltip/useTooltip.ts +3 -1
- package/src/hooks/useAutoFocus.ts +1 -0
- package/src/hooks/useChildrenCounter.ts +2 -1
- package/src/hooks/useControlledState.ts +3 -1
- package/src/hooks/useFocusReturn.ts +2 -1
- package/src/hooks/useFocusState.ts +1 -0
- package/src/hooks/useReducerMachine.ts +2 -1
- package/src/hooks/useScope.ts +2 -1
- package/src/utils/assignRef.ts +1 -1
- package/build/esm/hooks/useId.d.ts +0 -3
- package/build/esm/hooks/useId.js +0 -16
- package/build/esm/hooks/useId.js.map +0 -1
|
@@ -1,14 +1,18 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
|
|
4
|
+
var _on, _on2, _on3, _on4, _on5, _states;
|
|
5
|
+
|
|
2
6
|
import { createSubscription } from '../utils/createSubscription';
|
|
3
7
|
////////////////////////////////////////////////////////////////////////////////
|
|
4
8
|
// Timeouts:
|
|
5
9
|
// Manages when the user "rests" on an element. Keeps the interface from being
|
|
6
10
|
// flashing tooltips all the time as the user moves the mouse around the screen.
|
|
7
|
-
|
|
11
|
+
var restTimeout;
|
|
8
12
|
|
|
9
13
|
function startRestTimer() {
|
|
10
14
|
window.clearTimeout(restTimeout);
|
|
11
|
-
restTimeout = window.setTimeout(()
|
|
15
|
+
restTimeout = window.setTimeout(function () {
|
|
12
16
|
send(Rest, undefined);
|
|
13
17
|
}, 200);
|
|
14
18
|
}
|
|
@@ -18,11 +22,13 @@ function clearRestTimer() {
|
|
|
18
22
|
} // Manages the delay to hide the tooltip after rest leaves.
|
|
19
23
|
|
|
20
24
|
|
|
21
|
-
|
|
25
|
+
var leavingVisibleTimer;
|
|
22
26
|
|
|
23
27
|
function startLeavingVisibleTimer() {
|
|
24
28
|
window.clearTimeout(leavingVisibleTimer);
|
|
25
|
-
leavingVisibleTimer = window.setTimeout(
|
|
29
|
+
leavingVisibleTimer = window.setTimeout(function () {
|
|
30
|
+
return send(TimeComplete, undefined);
|
|
31
|
+
}, 100);
|
|
26
32
|
}
|
|
27
33
|
|
|
28
34
|
function clearLeavingVisibleTimer() {
|
|
@@ -32,28 +38,28 @@ function clearLeavingVisibleTimer() {
|
|
|
32
38
|
|
|
33
39
|
|
|
34
40
|
// Nothing goin' on
|
|
35
|
-
export
|
|
41
|
+
export var Idle = 'IDLE'; // We're considering showing the tooltip, but we're gonna wait a sec
|
|
36
42
|
|
|
37
|
-
export
|
|
43
|
+
export var Focused = 'FOCUSED'; // It's on!
|
|
38
44
|
|
|
39
|
-
export
|
|
45
|
+
export var Visible = 'VISIBLE'; // Focus has left, but we want to keep it visible for a sec
|
|
40
46
|
|
|
41
|
-
export
|
|
47
|
+
export var LeavingVisible = 'LEAVING_VISIBLE'; // The user clicked the tool, so we want to hide the thing, we can't just use
|
|
42
48
|
// IDLE because we need to ignore mousemove, etc.
|
|
43
49
|
|
|
44
|
-
export
|
|
45
|
-
export
|
|
46
|
-
export
|
|
47
|
-
export
|
|
48
|
-
export
|
|
49
|
-
export
|
|
50
|
-
export
|
|
51
|
-
export
|
|
52
|
-
export
|
|
53
|
-
export
|
|
54
|
-
export
|
|
55
|
-
export
|
|
56
|
-
export
|
|
50
|
+
export var Dismissed = 'DISMISSED';
|
|
51
|
+
export var Blur = 'BLUR';
|
|
52
|
+
export var Focus = 'FOCUS';
|
|
53
|
+
export var GlobalMouseMove = 'GLOBAL_MOUSE_MOVE';
|
|
54
|
+
export var MouseDown = 'MOUSE_DOWN';
|
|
55
|
+
export var MouseEnter = 'MOUSE_ENTER';
|
|
56
|
+
export var MouseLeave = 'MOUSE_LEAVE';
|
|
57
|
+
export var MouseMove = 'MOUSE_MOVE';
|
|
58
|
+
export var Rest = 'REST';
|
|
59
|
+
export var SelectWithKeyboard = 'SELECT_WITH_KEYBOARD';
|
|
60
|
+
export var TimeComplete = 'TIME_COMPLETE';
|
|
61
|
+
export var subscription = createSubscription();
|
|
62
|
+
export var state = {
|
|
57
63
|
current: {
|
|
58
64
|
state: Idle,
|
|
59
65
|
id: ''
|
|
@@ -64,72 +70,42 @@ function clearContextId() {
|
|
|
64
70
|
state.current.id = '';
|
|
65
71
|
}
|
|
66
72
|
|
|
67
|
-
|
|
73
|
+
var chart = {
|
|
68
74
|
initial: Idle,
|
|
69
|
-
states: {
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
clearContextId();
|
|
73
|
-
},
|
|
74
|
-
on: {
|
|
75
|
-
[MouseEnter]: Focused,
|
|
76
|
-
[Focus]: Visible
|
|
77
|
-
}
|
|
75
|
+
states: (_states = {}, _defineProperty(_states, Idle, {
|
|
76
|
+
enter: function enter() {
|
|
77
|
+
clearContextId();
|
|
78
78
|
},
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
on: (_on = {}, _defineProperty(_on, MouseEnter, Focused), _defineProperty(_on, Focus, Visible), _on)
|
|
80
|
+
}), _defineProperty(_states, Focused, {
|
|
81
|
+
enter: startRestTimer,
|
|
82
|
+
leave: clearRestTimer,
|
|
83
|
+
on: (_on2 = {}, _defineProperty(_on2, MouseMove, Focused), _defineProperty(_on2, MouseLeave, Idle), _defineProperty(_on2, MouseDown, Dismissed), _defineProperty(_on2, Blur, Idle), _defineProperty(_on2, Rest, Visible), _on2)
|
|
84
|
+
}), _defineProperty(_states, Visible, {
|
|
85
|
+
on: (_on3 = {}, _defineProperty(_on3, Focus, Focused), _defineProperty(_on3, MouseEnter, Focused), _defineProperty(_on3, MouseLeave, LeavingVisible), _defineProperty(_on3, Blur, LeavingVisible), _defineProperty(_on3, MouseDown, Dismissed), _defineProperty(_on3, SelectWithKeyboard, Dismissed), _defineProperty(_on3, GlobalMouseMove, LeavingVisible), _on3)
|
|
86
|
+
}), _defineProperty(_states, LeavingVisible, {
|
|
87
|
+
enter: function enter() {
|
|
88
|
+
startLeavingVisibleTimer();
|
|
89
89
|
},
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
[MouseEnter]: Focused,
|
|
94
|
-
[MouseLeave]: LeavingVisible,
|
|
95
|
-
[Blur]: LeavingVisible,
|
|
96
|
-
[MouseDown]: Dismissed,
|
|
97
|
-
[SelectWithKeyboard]: Dismissed,
|
|
98
|
-
[GlobalMouseMove]: LeavingVisible
|
|
99
|
-
}
|
|
90
|
+
leave: function leave() {
|
|
91
|
+
clearLeavingVisibleTimer();
|
|
92
|
+
clearContextId();
|
|
100
93
|
},
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
leave: () => {
|
|
106
|
-
clearLeavingVisibleTimer();
|
|
107
|
-
clearContextId();
|
|
108
|
-
},
|
|
109
|
-
on: {
|
|
110
|
-
[MouseEnter]: Visible,
|
|
111
|
-
[Focus]: Visible,
|
|
112
|
-
[TimeComplete]: Idle
|
|
113
|
-
}
|
|
94
|
+
on: (_on4 = {}, _defineProperty(_on4, MouseEnter, Visible), _defineProperty(_on4, Focus, Visible), _defineProperty(_on4, TimeComplete, Idle), _on4)
|
|
95
|
+
}), _defineProperty(_states, Dismissed, {
|
|
96
|
+
leave: function leave() {
|
|
97
|
+
clearContextId();
|
|
114
98
|
},
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
clearContextId();
|
|
118
|
-
},
|
|
119
|
-
on: {
|
|
120
|
-
[MouseLeave]: Idle,
|
|
121
|
-
[Blur]: Idle
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
99
|
+
on: (_on5 = {}, _defineProperty(_on5, MouseLeave, Idle), _defineProperty(_on5, Blur, Idle), _on5)
|
|
100
|
+
}), _states)
|
|
125
101
|
};
|
|
126
102
|
|
|
127
103
|
function transition(currentState, event, payload) {
|
|
128
104
|
var _stateDef$on;
|
|
129
105
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
106
|
+
var currentStateValue = currentState.state;
|
|
107
|
+
var stateDef = chart.states[currentState.state];
|
|
108
|
+
var nextState = stateDef == null ? void 0 : (_stateDef$on = stateDef.on) == null ? void 0 : _stateDef$on[event]; // Really useful for debugging
|
|
133
109
|
// console.log({
|
|
134
110
|
// event,
|
|
135
111
|
// state: state.current.state,
|
|
@@ -145,8 +121,8 @@ function transition(currentState, event, payload) {
|
|
|
145
121
|
stateDef.leave(currentStateValue, payload);
|
|
146
122
|
}
|
|
147
123
|
|
|
148
|
-
|
|
149
|
-
|
|
124
|
+
var nextStateValue = nextState;
|
|
125
|
+
var nextDef = chart.states[nextStateValue];
|
|
150
126
|
|
|
151
127
|
if (nextDef && nextDef.enter) {
|
|
152
128
|
nextDef.enter(nextStateValue, payload);
|
|
@@ -158,7 +134,7 @@ function transition(currentState, event, payload) {
|
|
|
158
134
|
}
|
|
159
135
|
|
|
160
136
|
export function send(event, payload) {
|
|
161
|
-
|
|
137
|
+
var nextState = transition(state.current, event, payload);
|
|
162
138
|
|
|
163
139
|
if (state.current !== nextState) {
|
|
164
140
|
state.current = nextState;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Tooltip/stateMachine.ts"],"names":["createSubscription","restTimeout","startRestTimer","window","clearTimeout","setTimeout","send","Rest","undefined","clearRestTimer","leavingVisibleTimer","startLeavingVisibleTimer","TimeComplete","clearLeavingVisibleTimer","Idle","Focused","Visible","LeavingVisible","Dismissed","Blur","Focus","GlobalMouseMove","MouseDown","MouseEnter","MouseLeave","MouseMove","SelectWithKeyboard","subscription","state","current","id","clearContextId","chart","initial","states","enter","on","leave","transition","currentState","event","payload","currentStateValue","stateDef","nextState","nextStateValue","nextDef","notify"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/Tooltip/stateMachine.ts"],"names":["createSubscription","restTimeout","startRestTimer","window","clearTimeout","setTimeout","send","Rest","undefined","clearRestTimer","leavingVisibleTimer","startLeavingVisibleTimer","TimeComplete","clearLeavingVisibleTimer","Idle","Focused","Visible","LeavingVisible","Dismissed","Blur","Focus","GlobalMouseMove","MouseDown","MouseEnter","MouseLeave","MouseMove","SelectWithKeyboard","subscription","state","current","id","clearContextId","chart","initial","states","enter","on","leave","transition","currentState","event","payload","currentStateValue","stateDef","nextState","nextStateValue","nextDef","notify"],"mappings":";;;;;AAAA,SAASA,kBAAT,QAAmC,6BAAnC;AAGA;AACA;AAEA;AACA;AACA,IAAIC,WAAJ;;AACA,SAASC,cAAT,GAA0B;AACxBC,EAAAA,MAAM,CAACC,YAAP,CAAoBH,WAApB;AACAA,EAAAA,WAAW,GAAGE,MAAM,CAACE,UAAP,CAAkB,YAAM;AACpCC,IAAAA,IAAI,CAACC,IAAD,EAAOC,SAAP,CAAJ;AACD,GAFa,EAEX,GAFW,CAAd;AAGD;;AAED,SAASC,cAAT,GAA0B;AACxBN,EAAAA,MAAM,CAACC,YAAP,CAAoBH,WAApB;AACD,C,CAED;;;AACA,IAAIS,mBAAJ;;AAEA,SAASC,wBAAT,GAAoC;AAClCR,EAAAA,MAAM,CAACC,YAAP,CAAoBM,mBAApB;AACAA,EAAAA,mBAAmB,GAAGP,MAAM,CAACE,UAAP,CACpB;AAAA,WAAMC,IAAI,CAACM,YAAD,EAAeJ,SAAf,CAAV;AAAA,GADoB,EAEpB,GAFoB,CAAtB;AAID;;AAED,SAASK,wBAAT,GAAoC;AAClCV,EAAAA,MAAM,CAACC,YAAP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;AACA;AACA;AACA;;AAEA,MAAI,CAACI,SAAL,EAAgB;AACd,WAAOL,YAAP;AACD;;AAED,MAAII,QAAQ,IAAIA,QAAQ,CAACN,KAAzB,EAAgC;AAC9BM,IAAAA,QAAQ,CAACN,KAAT,CAAeK,iBAAf,EAAkCD,OAAlC;AACD;;AAED,MAAMI,cAAc,GAAGD,SAAvB;AACA,MAAME,OAAO,GAAGd,KAAK,CAACE,MAAN,CAAaW,cAAb,CAAhB;;AACA,MAAIC,OAAO,IAAIA,OAAO,CAACX,KAAvB,EAA8B;AAC5BW,IAAAA,OAAO,CAACX,KAAR,CAAcU,cAAd,EAA8BJ,OAA9B;AACD;;AAED,sBAAYF,YAAZ,EAA6BE,OAA7B;AAAsCb,IAAAA,KAAK,EAAEiB;AAA7C;AACD;;AAED,OAAO,SAASvC,IAAT,CACLkC,KADK,EAELC,OAFK,EAGL;AACA,MAAMG,SAAS,GAAGN,UAAU,CAACV,KAAK,CAACC,OAAP,EAAgBW,KAAhB,EAAuBC,OAAvB,CAA5B;;AACA,MAAIb,KAAK,CAACC,OAAN,KAAkBe,SAAtB,EAAiC;AAC/BhB,IAAAA,KAAK,CAACC,OAAN,GAAgBe,SAAhB;AACAjB,IAAAA,YAAY,CAACoB,MAAb;AACD;AACF","sourcesContent":["import { createSubscription } from '../utils/createSubscription';\nimport type { StateChart as GenericStateChart } from '../hooks/useReducerMachine';\n\n////////////////////////////////////////////////////////////////////////////////\n// Timeouts:\n\n// Manages when the user \"rests\" on an element. Keeps the interface from being\n// flashing tooltips all the time as the user moves the mouse around the screen.\nlet restTimeout: number;\nfunction startRestTimer() {\n window.clearTimeout(restTimeout);\n restTimeout = window.setTimeout(() => {\n send(Rest, undefined);\n }, 200);\n}\n\nfunction clearRestTimer() {\n window.clearTimeout(restTimeout);\n}\n\n// Manages the delay to hide the tooltip after rest leaves.\nlet leavingVisibleTimer: number;\n\nfunction startLeavingVisibleTimer() {\n window.clearTimeout(leavingVisibleTimer);\n leavingVisibleTimer = window.setTimeout(\n () => send(TimeComplete, undefined),\n 100\n );\n}\n\nfunction clearLeavingVisibleTimer() {\n window.clearTimeout(leavingVisibleTimer);\n}\n\n////////////////////////////////////////////////////////////////////////////////\n// State machine\n\nexport type TooltipStates =\n | 'IDLE'\n | 'FOCUSED'\n | 'VISIBLE'\n | 'LEAVING_VISIBLE'\n | 'DISMISSED';\n\n// Nothing goin' on\nexport const Idle = 'IDLE' as const;\n// We're considering showing the tooltip, but we're gonna wait a sec\nexport const Focused = 'FOCUSED' as const;\n// It's on!\nexport const Visible = 'VISIBLE' as const;\n// Focus has left, but we want to keep it visible for a sec\nexport const LeavingVisible = 'LEAVING_VISIBLE' as const;\n// The user clicked the tool, so we want to hide the thing, we can't just use\n// IDLE because we need to ignore mousemove, etc.\nexport const Dismissed = 'DISMISSED' as const;\n\nexport type TooltipEventTypes =\n | 'BLUR'\n | 'FOCUS'\n | 'GLOBAL_MOUSE_MOVE'\n | 'MOUSE_DOWN'\n | 'MOUSE_ENTER'\n | 'MOUSE_LEAVE'\n | 'MOUSE_MOVE'\n | 'REST'\n | 'SELECT_WITH_KEYBOARD'\n | 'TIME_COMPLETE';\n\nexport const Blur = 'BLUR' as const;\nexport const Focus = 'FOCUS' as const;\nexport const GlobalMouseMove = 'GLOBAL_MOUSE_MOVE' as const;\nexport const MouseDown = 'MOUSE_DOWN' as const;\nexport const MouseEnter = 'MOUSE_ENTER' as const;\nexport const MouseLeave = 'MOUSE_LEAVE' as const;\nexport const MouseMove = 'MOUSE_MOVE' as const;\nexport const Rest = 'REST' as const;\nexport const SelectWithKeyboard = 'SELECT_WITH_KEYBOARD' as const;\nexport const TimeComplete = 'TIME_COMPLETE' as const;\n\nexport const subscription = createSubscription();\nexport const state = {\n current: {\n state: Idle as TooltipStates,\n id: '',\n },\n};\n\nfunction clearContextId() {\n state.current.id = '';\n}\n\nconst chart: GenericStateChart<TooltipStates, TooltipEventTypes> = {\n initial: Idle,\n states: {\n [Idle]: {\n enter: () => {\n clearContextId();\n },\n on: {\n [MouseEnter]: Focused,\n [Focus]: Visible,\n },\n },\n [Focused]: {\n enter: startRestTimer,\n leave: clearRestTimer,\n on: {\n [MouseMove]: Focused,\n [MouseLeave]: Idle,\n [MouseDown]: Dismissed,\n [Blur]: Idle,\n [Rest]: Visible,\n },\n },\n [Visible]: {\n on: {\n [Focus]: Focused,\n [MouseEnter]: Focused,\n [MouseLeave]: LeavingVisible,\n [Blur]: LeavingVisible,\n [MouseDown]: Dismissed,\n [SelectWithKeyboard]: Dismissed,\n [GlobalMouseMove]: LeavingVisible,\n },\n },\n [LeavingVisible]: {\n enter: () => {\n startLeavingVisibleTimer();\n },\n leave: () => {\n clearLeavingVisibleTimer();\n clearContextId();\n },\n on: {\n [MouseEnter]: Visible,\n [Focus]: Visible,\n [TimeComplete]: Idle,\n },\n },\n [Dismissed]: {\n leave: () => {\n clearContextId();\n },\n on: {\n [MouseLeave]: Idle,\n [Blur]: Idle,\n },\n },\n },\n};\n\nfunction transition(\n currentState: typeof state['current'],\n event: TooltipEventTypes,\n payload?: Omit<typeof state['current'], 'state'>\n): typeof state['current'] {\n const currentStateValue = currentState.state;\n const stateDef = chart.states[currentState.state];\n const nextState = stateDef?.on?.[event];\n\n // Really useful for debugging\n // console.log({\n // event,\n // state: state.current.state,\n // id: state.current.id,\n // nextState,\n // });\n\n if (!nextState) {\n return currentState;\n }\n\n if (stateDef && stateDef.leave) {\n stateDef.leave(currentStateValue, payload);\n }\n\n const nextStateValue = nextState;\n const nextDef = chart.states[nextStateValue];\n if (nextDef && nextDef.enter) {\n nextDef.enter(nextStateValue, payload);\n }\n\n return { ...currentState, ...payload, state: nextStateValue };\n}\n\nexport function send<T extends TooltipEventTypes>(\n event: T,\n payload?: Omit<typeof state['current'], 'state'>\n) {\n const nextState = transition(state.current, event, payload);\n if (state.current !== nextState) {\n state.current = nextState;\n subscription.notify();\n }\n}\n"],"file":"stateMachine.js"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { RefAttributes } from 'react';
|
|
1
|
+
import type { RefAttributes } from 'react';
|
|
2
2
|
export declare type ChildProps = React.HTMLAttributes<HTMLElement> & RefAttributes<HTMLElement>;
|
|
3
3
|
export interface InjectedTooltipProps extends React.HTMLAttributes<HTMLElement> {
|
|
4
4
|
anchorEl: React.RefObject<HTMLElement>;
|
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
4
|
import { useRef, useEffect, useState, useId } from 'react';
|
|
4
5
|
import { assignMultipleRefs } from '../utils/assignRef';
|
|
5
6
|
import { wrapEvent } from '../utils/wrapEvent';
|
|
6
7
|
import { send, state, subscription, Blur, Focus, LeavingVisible, MouseDown, MouseEnter, MouseLeave, MouseMove, SelectWithKeyboard, Visible } from './stateMachine';
|
|
7
8
|
export function useTooltip(childProps, childRef, tooltipProps) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
9
|
+
var onMouseEnter = childProps.onMouseEnter,
|
|
10
|
+
onMouseLeave = childProps.onMouseLeave,
|
|
11
|
+
onMouseMove = childProps.onMouseMove,
|
|
12
|
+
onMouseDown = childProps.onMouseDown,
|
|
13
|
+
onKeyDown = childProps.onKeyDown,
|
|
14
|
+
onFocus = childProps.onFocus,
|
|
15
|
+
onBlur = childProps.onBlur;
|
|
16
|
+
var anchorEl = useRef(null);
|
|
17
|
+
|
|
18
|
+
var _useState = useState(false),
|
|
19
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
20
|
+
visible = _useState2[0],
|
|
21
|
+
setVisible = _useState2[1];
|
|
22
|
+
|
|
23
|
+
var id = useId();
|
|
24
|
+
useEffect(function () {
|
|
25
|
+
subscription.subscribe(function () {
|
|
22
26
|
setVisible((state.current.state === Visible || state.current.state === LeavingVisible) && state.current.id === id);
|
|
23
27
|
});
|
|
24
28
|
}, [id]);
|
|
25
29
|
|
|
26
30
|
function handleMouseEnter() {
|
|
27
31
|
send(MouseEnter, {
|
|
28
|
-
id
|
|
32
|
+
id: id
|
|
29
33
|
});
|
|
30
34
|
}
|
|
31
35
|
|
|
32
36
|
function handleMouseMove() {
|
|
33
37
|
send(MouseMove, {
|
|
34
|
-
id
|
|
38
|
+
id: id
|
|
35
39
|
});
|
|
36
40
|
}
|
|
37
41
|
|
|
@@ -48,7 +52,7 @@ export function useTooltip(childProps, childRef, tooltipProps) {
|
|
|
48
52
|
|
|
49
53
|
function handleFocus() {
|
|
50
54
|
send(Focus, {
|
|
51
|
-
id
|
|
55
|
+
id: id
|
|
52
56
|
});
|
|
53
57
|
}
|
|
54
58
|
|
|
@@ -65,15 +69,13 @@ export function useTooltip(childProps, childRef, tooltipProps) {
|
|
|
65
69
|
}
|
|
66
70
|
}
|
|
67
71
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
} = tooltipProps,
|
|
74
|
-
otherTooltipProps = _objectWithoutPropertiesLoose(tooltipProps, ["label", "onMouseEnter", "onMouseLeave", "onMouseMove"]);
|
|
72
|
+
var children = tooltipProps.label,
|
|
73
|
+
tooltipOnMouseEnter = tooltipProps.onMouseEnter,
|
|
74
|
+
tooltipOnMouseLeave = tooltipProps.onMouseLeave,
|
|
75
|
+
tooltipOnMouseMove = tooltipProps.onMouseMove,
|
|
76
|
+
otherTooltipProps = _objectWithoutProperties(tooltipProps, ["label", "onMouseEnter", "onMouseLeave", "onMouseMove"]);
|
|
75
77
|
|
|
76
|
-
|
|
78
|
+
var tooltipId = "tooltip-".concat(id);
|
|
77
79
|
return [_extends({}, childProps, {
|
|
78
80
|
ref: assignMultipleRefs(childRef, anchorEl)
|
|
79
81
|
}, visible && {
|
|
@@ -88,9 +90,9 @@ export function useTooltip(childProps, childRef, tooltipProps) {
|
|
|
88
90
|
onKeyDown: wrapEvent(onKeyDown, handleKeyDown)
|
|
89
91
|
}), _extends({
|
|
90
92
|
id: tooltipId,
|
|
91
|
-
anchorEl,
|
|
92
|
-
visible,
|
|
93
|
-
children,
|
|
93
|
+
anchorEl: anchorEl,
|
|
94
|
+
visible: visible,
|
|
95
|
+
children: children,
|
|
94
96
|
onMouseEnter: wrapEvent(tooltipOnMouseEnter, handleMouseEnter),
|
|
95
97
|
onMouseLeave: wrapEvent(tooltipOnMouseLeave, handleMouseLeave),
|
|
96
98
|
onMouseMove: wrapEvent(tooltipOnMouseMove, handleMouseMove),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/Tooltip/useTooltip.ts"],"names":["useRef","useEffect","useState","useId","assignMultipleRefs","wrapEvent","send","state","subscription","Blur","Focus","LeavingVisible","MouseDown","MouseEnter","MouseLeave","MouseMove","SelectWithKeyboard","Visible","useTooltip","childProps","childRef","tooltipProps","onMouseEnter","onMouseLeave","onMouseMove","onMouseDown","onKeyDown","onFocus","onBlur","anchorEl","visible","setVisible","id","subscribe","current","handleMouseEnter","handleMouseMove","handleMouseLeave","handleMouseDown","handleFocus","handleBlur","undefined","handleKeyDown","event","key","
|
|
1
|
+
{"version":3,"sources":["../../../src/Tooltip/useTooltip.ts"],"names":["useRef","useEffect","useState","useId","assignMultipleRefs","wrapEvent","send","state","subscription","Blur","Focus","LeavingVisible","MouseDown","MouseEnter","MouseLeave","MouseMove","SelectWithKeyboard","Visible","useTooltip","childProps","childRef","tooltipProps","onMouseEnter","onMouseLeave","onMouseMove","onMouseDown","onKeyDown","onFocus","onBlur","anchorEl","visible","setVisible","id","subscribe","current","handleMouseEnter","handleMouseMove","handleMouseLeave","handleMouseDown","handleFocus","handleBlur","undefined","handleKeyDown","event","key","children","label","tooltipOn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from 'react';\nimport { useRef, useEffect, useState, useId } from 'react';\n\nimport { assignMultipleRefs } from '../utils/assignRef';\nimport { wrapEvent } from '../utils/wrapEvent';\nimport {\n send,\n state,\n subscription,\n Blur,\n Focus,\n LeavingVisible,\n MouseDown,\n MouseEnter,\n MouseLeave,\n MouseMove,\n SelectWithKeyboard,\n Visible,\n} from './stateMachine';\n\nexport type ChildProps = React.HTMLAttributes<HTMLElement> &\n RefAttributes<HTMLElement>;\n\nexport interface InjectedTooltipProps\n extends React.HTMLAttributes<HTMLElement> {\n anchorEl: React.RefObject<HTMLElement>;\n visible: boolean;\n children?: React.ReactNode;\n}\n\nexport function useTooltip(\n childProps: ChildProps,\n childRef: React.Ref<HTMLElement> | undefined,\n tooltipProps: React.HTMLAttributes<HTMLElement> & { label?: React.ReactNode }\n): [ChildProps, InjectedTooltipProps] {\n const {\n onMouseEnter,\n onMouseLeave,\n onMouseMove,\n onMouseDown,\n onKeyDown,\n onFocus,\n onBlur,\n } = childProps;\n const anchorEl = useRef<HTMLElement>(null);\n const [visible, setVisible] = useState(false);\n const id = useId();\n\n useEffect(() => {\n subscription.subscribe(() => {\n setVisible(\n (state.current.state === Visible ||\n state.current.state === LeavingVisible) &&\n state.current.id === id\n );\n });\n }, [id]);\n\n function handleMouseEnter() {\n send(MouseEnter, { id });\n }\n\n function handleMouseMove() {\n send(MouseMove, { id });\n }\n\n function handleMouseLeave() {\n send(MouseLeave);\n }\n\n function handleMouseDown() {\n // Allow quick click from one tool to another\n if (state.current.id === id) {\n send(MouseDown);\n }\n }\n\n function handleFocus() {\n send(Focus, { id });\n }\n\n function handleBlur() {\n // Allow quick click from one tool to another\n if (state.current.id === id) {\n send(Blur, undefined);\n }\n }\n\n function handleKeyDown(event: React.KeyboardEvent<HTMLElement>) {\n if (event.key === 'Enter' || event.key === ' ') {\n send(SelectWithKeyboard);\n }\n }\n\n const {\n label: children,\n onMouseEnter: tooltipOnMouseEnter,\n onMouseLeave: tooltipOnMouseLeave,\n onMouseMove: tooltipOnMouseMove,\n ...otherTooltipProps\n } = tooltipProps;\n\n const tooltipId = `tooltip-${id}`;\n return [\n {\n ...childProps,\n ref: assignMultipleRefs(childRef, anchorEl),\n ...(visible && { 'aria-describedby': tooltipId }),\n onMouseEnter: wrapEvent(onMouseEnter, handleMouseEnter),\n onMouseLeave: wrapEvent(onMouseLeave, handleMouseLeave),\n onMouseMove: wrapEvent(onMouseMove, handleMouseMove),\n onMouseDown: wrapEvent(onMouseDown, handleMouseDown),\n onFocus: wrapEvent(onFocus, handleFocus),\n onBlur: wrapEvent(onBlur, handleBlur),\n onKeyDown: wrapEvent(onKeyDown, handleKeyDown),\n },\n {\n id: tooltipId,\n anchorEl,\n visible,\n children,\n onMouseEnter: wrapEvent(tooltipOnMouseEnter, handleMouseEnter),\n onMouseLeave: wrapEvent(tooltipOnMouseLeave, handleMouseLeave),\n onMouseMove: wrapEvent(tooltipOnMouseMove, handleMouseMove),\n role: 'tooltip',\n ...otherTooltipProps,\n },\n ];\n}\n"],"file":"useTooltip.js"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { focusOnChildNode } from '../FocusLock/tabUtils';
|
|
3
3
|
export function useAutoFocus(open, elementRef) {
|
|
4
|
-
useEffect(()
|
|
4
|
+
useEffect(function () {
|
|
5
5
|
if (open) {
|
|
6
6
|
// We will only autoFocus on the first child if the currently active element isn't already trapped inside the modal
|
|
7
7
|
if (elementRef.current && !elementRef.current.contains(document.activeElement)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/useAutoFocus.ts"],"names":["useEffect","focusOnChildNode","useAutoFocus","open","elementRef","current","contains","document","activeElement"],"mappings":"AAAA,SAASA,SAAT,QAA0B,OAA1B;
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useAutoFocus.ts"],"names":["useEffect","focusOnChildNode","useAutoFocus","open","elementRef","current","contains","document","activeElement"],"mappings":"AAAA,SAASA,SAAT,QAA0B,OAA1B;AAEA,SAASC,gBAAT,QAAiC,uBAAjC;AAEA,OAAO,SAASC,YAAT,CACLC,IADK,EAELC,UAFK,EAGL;AACAJ,EAAAA,SAAS,CAAC,YAAM;AACd,QAAIG,IAAJ,EAAU;AACR;AACA,UACEC,UAAU,CAACC,OAAX,IACA,CAACD,UAAU,CAACC,OAAX,CAAmBC,QAAnB,CAA4BC,QAAQ,CAACC,aAArC,CAFH,EAGE;AACAP,QAAAA,gBAAgB,CAACG,UAAU,CAACC,OAAZ,EAAqB,CAArB,CAAhB;AACD;AACF,KATa,CAUd;;AACD,GAXQ,EAWN,CAACF,IAAD,CAXM,CAAT;AAYD","sourcesContent":["import { useEffect } from 'react';\n\nimport { focusOnChildNode } from '../FocusLock/tabUtils';\n\nexport function useAutoFocus(\n open: boolean,\n elementRef: React.MutableRefObject<HTMLElement | null>\n) {\n useEffect(() => {\n if (open) {\n // We will only autoFocus on the first child if the currently active element isn't already trapped inside the modal\n if (\n elementRef.current &&\n !elementRef.current.contains(document.activeElement)\n ) {\n focusOnChildNode(elementRef.current, 0);\n }\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [open]);\n}\n"],"file":"useAutoFocus.js"}
|
|
@@ -6,21 +6,23 @@ export function useChildrenCounterParent(itemsRef) {
|
|
|
6
6
|
// the array
|
|
7
7
|
itemsRef.current = [];
|
|
8
8
|
itemsRef.current.isNewRender = true;
|
|
9
|
-
useEffect(()
|
|
9
|
+
useEffect(function () {
|
|
10
10
|
// Rendering is finished. Meaning any children can now rerender,
|
|
11
11
|
// and they should not push any new items to our array, because
|
|
12
12
|
// it is not a new render
|
|
13
13
|
itemsRef.current.isNewRender = false;
|
|
14
14
|
});
|
|
15
|
-
useEffect(()
|
|
15
|
+
useEffect(function () {
|
|
16
16
|
// When we are unmounting, it means there are no children anymore.
|
|
17
17
|
// Clear out our items array
|
|
18
|
-
return ()
|
|
18
|
+
return function () {
|
|
19
19
|
itemsRef.current = [];
|
|
20
20
|
};
|
|
21
21
|
}, [itemsRef]);
|
|
22
22
|
}
|
|
23
|
-
export function useChildrenCounterChild(itemsRef, itemIndexRef, obj
|
|
23
|
+
export function useChildrenCounterChild(itemsRef, itemIndexRef, obj) {
|
|
24
|
+
var disabled = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
|
|
25
|
+
|
|
24
26
|
if (itemsRef && itemsRef.current.isNewRender) {
|
|
25
27
|
if (disabled) {
|
|
26
28
|
itemIndexRef.current = -1;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/useChildrenCounter.ts"],"names":["useEffect","useChildrenCounterParent","itemsRef","current","isNewRender","useChildrenCounterChild","itemIndexRef","obj","disabled","length","Function","push"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useChildrenCounter.ts"],"names":["useEffect","useChildrenCounterParent","itemsRef","current","isNewRender","useChildrenCounterChild","itemIndexRef","obj","disabled","length","Function","push"],"mappings":"AACA,SAASA,SAAT,QAA0B,OAA1B;AAEA,OAAO,SAASC,wBAAT,CACLC,QADK,EAEL;AACA;AACA;AACA;AACA;AACAA,EAAAA,QAAQ,CAACC,OAAT,GAAmB,EAAnB;AACAD,EAAAA,QAAQ,CAACC,OAAT,CAAiBC,WAAjB,GAA+B,IAA/B;AAEAJ,EAAAA,SAAS,CAAC,YAAM;AACd;AACA;AACA;AACAE,IAAAA,QAAQ,CAACC,OAAT,CAAiBC,WAAjB,GAA+B,KAA/B;AACD,GALQ,CAAT;AAOAJ,EAAAA,SAAS,CAAC,YAAM;AACd;AACA;AACA,WAAO,YAAM;AACXE,MAAAA,QAAQ,CAACC,OAAT,GAAmB,EAAnB;AACD,KAFD;AAGD,GANQ,EAMN,CAACD,QAAD,CANM,CAAT;AAOD;AAED,OAAO,SAASG,uBAAT,CACLH,QADK,EAELI,YAFK,EAGLC,GAHK,EAKL;AAAA,MADAC,QACA,uEADW,KACX;;AACA,MAAIN,QAAQ,IAAIA,QAAQ,CAACC,OAAT,CAAiBC,WAAjC,EAA8C;AAC5C,QAAII,QAAJ,EAAc;AACZF,MAAAA,YAAY,CAACH,OAAb,GAAuB,CAAC,CAAxB;AACA;AACD,KAJ2C,CAM5C;;;AACAG,IAAAA,YAAY,CAACH,OAAb,GAAuBD,QAAQ,CAACC,OAAT,CAAiBM,MAAxC;;AAEA,QAAIF,GAAG,YAAYG,QAAnB,EAA6B;AAC3BR,MAAAA,QAAQ,CAACC,OAAT,CAAiBQ,IAAjB,CAAsBJ,GAAG,CAACD,YAAY,CAACH,OAAd,CAAzB;AACD,KAFD,MAEO;AACLD,MAAAA,QAAQ,CAACC,OAAT,CAAiBQ,IAAjB,CAAsBJ,GAAtB;AACD;AACF;AACF","sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect } from 'react';\n\nexport function useChildrenCounterParent<T>(\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }>\n) {\n // Reset the options ref every render so that they are always\n // accurate and ready for keyboard navigation handlers. Using layout\n // effect to schedule this effect before the ComboboxOptions push into\n // the array\n itemsRef.current = [];\n itemsRef.current.isNewRender = true;\n\n useEffect(() => {\n // Rendering is finished. Meaning any children can now rerender,\n // and they should not push any new items to our array, because\n // it is not a new render\n itemsRef.current.isNewRender = false;\n });\n\n useEffect(() => {\n // When we are unmounting, it means there are no children anymore.\n // Clear out our items array\n return () => {\n itemsRef.current = [];\n };\n }, [itemsRef]);\n}\n\nexport function useChildrenCounterChild<T>(\n itemsRef: MutableRefObject<T[] & { isNewRender?: boolean }> | undefined,\n itemIndexRef: MutableRefObject<number>,\n obj: T | ((idx: number) => T),\n disabled = false\n) {\n if (itemsRef && itemsRef.current.isNewRender) {\n if (disabled) {\n itemIndexRef.current = -1;\n return;\n }\n\n // push this option to the optionsRef array\n itemIndexRef.current = itemsRef.current.length;\n\n if (obj instanceof Function) {\n itemsRef.current.push(obj(itemIndexRef.current));\n } else {\n itemsRef.current.push(obj);\n }\n }\n}\n"],"file":"useChildrenCounter.js"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import { CustomEventHandler } from '../utils';
|
|
2
|
+
import type { CustomEventHandler } from '../utils';
|
|
3
3
|
export declare function useControlledState<V, E extends React.SyntheticEvent<any>, H extends unknown[]>(valueProp: V | undefined, onChangeProp: CustomEventHandler<E, H> | undefined, defaultValue: V, defaultOnChange: (setValue: React.Dispatch<React.SetStateAction<V>>) => CustomEventHandler<E, H>): [
|
|
4
4
|
V,
|
|
5
5
|
CustomEventHandler<E, H> | undefined,
|
|
@@ -1,8 +1,13 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import { useRef, useState } from 'react';
|
|
2
3
|
import { wrapEvent } from '../utils';
|
|
3
4
|
export function useControlledState(valueProp, onChangeProp, defaultValue, defaultOnChange) {
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
var isControlled = useRef(valueProp !== undefined);
|
|
6
|
+
|
|
7
|
+
var _useState = useState(defaultValue),
|
|
8
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
9
|
+
valueState = _useState2[0],
|
|
10
|
+
setValueState = _useState2[1];
|
|
6
11
|
|
|
7
12
|
if (isControlled.current) {
|
|
8
13
|
if (valueProp === undefined) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/useControlledState.ts"],"names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","valueState","setValueState","current","console","warn"],"mappings":"AAAA,SAASA,MAAT,EAAiBC,QAAjB,QAAiC,OAAjC;
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useControlledState.ts"],"names":["useRef","useState","wrapEvent","useControlledState","valueProp","onChangeProp","defaultValue","defaultOnChange","isControlled","undefined","valueState","setValueState","current","console","warn"],"mappings":";AAAA,SAASA,MAAT,EAAiBC,QAAjB,QAAiC,OAAjC;AAGA,SAASC,SAAT,QAA0B,UAA1B;AAEA,OAAO,SAASC,kBAAT,CAKLC,SALK,EAMLC,YANK,EAOLC,YAPK,EAQLC,eARK,EAeL;AACA,MAAMC,YAAY,GAAGR,MAAM,CAACI,SAAS,KAAKK,SAAf,CAA3B;;AADA,kBAEoCR,QAAQ,CAAIK,YAAJ,CAF5C;AAAA;AAAA,MAEOI,UAFP;AAAA,MAEmBC,aAFnB;;AAIA,MAAIH,YAAY,CAACI,OAAjB,EAA0B;AACxB,QAAIR,SAAS,KAAKK,SAAlB,EAA6B;AAC3BI,MAAAA,OAAO,CAACC,IAAR,CAAa,mDAAb;AACD,KAHuB,CAIxB;;;AACA,WAAO,CAACV,SAAD,EAAaC,YAAb,EAA2BM,aAA3B,CAAP;AACD;;AAED,SAAO,CACL;AACAD,EAAAA,UAFK,EAGLR,SAAS,CAACG,YAAD,EAAeE,eAAe,CAACI,aAAD,CAA9B,CAHJ,EAILA,aAJK,CAAP;AAMD","sourcesContent":["import { useRef, useState } from 'react';\n\nimport type { CustomEventHandler } from '../utils';\nimport { wrapEvent } from '../utils';\n\nexport function useControlledState<\n V,\n E extends React.SyntheticEvent<any>,\n H extends unknown[]\n>(\n valueProp: V | undefined,\n onChangeProp: CustomEventHandler<E, H> | undefined,\n defaultValue: V,\n defaultOnChange: (\n setValue: React.Dispatch<React.SetStateAction<V>>\n ) => CustomEventHandler<E, H>\n): [\n V,\n CustomEventHandler<E, H> | undefined,\n React.Dispatch<React.SetStateAction<V>>\n] {\n const isControlled = useRef(valueProp !== undefined);\n const [valueState, setValueState] = useState<V>(defaultValue);\n\n if (isControlled.current) {\n if (valueProp === undefined) {\n console.warn('Trying to change from controlled to uncontrolled.');\n }\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n return [valueProp!, onChangeProp, setValueState];\n }\n\n return [\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n valueState!,\n wrapEvent(onChangeProp, defaultOnChange(setValueState)),\n setValueState,\n ];\n}\n"],"file":"useControlledState.js"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { MutableRefObject } from 'react';
|
|
1
|
+
import type { MutableRefObject } from 'react';
|
|
2
2
|
export declare function useFocusReturn(open: boolean, rootEl: MutableRefObject<HTMLElement | null>): void;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { useEffect, useRef } from 'react';
|
|
2
2
|
export function useFocusReturn(open, rootEl) {
|
|
3
|
-
|
|
3
|
+
var previousFocusRef = useRef(function () {
|
|
4
4
|
if (open && typeof document !== 'undefined' && document.activeElement instanceof HTMLElement) {
|
|
5
5
|
return document.activeElement;
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
return null;
|
|
9
|
-
}
|
|
10
|
-
useEffect(()
|
|
9
|
+
}());
|
|
10
|
+
useEffect(function () {
|
|
11
11
|
if (open) {
|
|
12
12
|
var _rootEl$current;
|
|
13
13
|
|
|
@@ -17,9 +17,9 @@ export function useFocusReturn(open, rootEl) {
|
|
|
17
17
|
previousFocusRef.current = document.activeElement;
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
return ()
|
|
20
|
+
var rootElement = rootEl.current;
|
|
21
|
+
var previousElement = previousFocusRef.current;
|
|
22
|
+
return function () {
|
|
23
23
|
// on unmount, return focus to that element
|
|
24
24
|
if (previousElement && !(rootElement != null && rootElement.contains(document.activeElement))) {
|
|
25
25
|
previousElement.focus({
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../src/hooks/useFocusReturn.ts"],"names":["useEffect","useRef","useFocusReturn","open","rootEl","previousFocusRef","document","activeElement","HTMLElement","current","contains","rootElement","previousElement","focus","preventScroll"],"mappings":"
|
|
1
|
+
{"version":3,"sources":["../../../src/hooks/useFocusReturn.ts"],"names":["useEffect","useRef","useFocusReturn","open","rootEl","previousFocusRef","document","activeElement","HTMLElement","current","contains","rootElement","previousElement","focus","preventScroll"],"mappings":"AACA,SAASA,SAAT,EAAoBC,MAApB,QAAkC,OAAlC;AAEA,OAAO,SAASC,cAAT,CACLC,IADK,EAELC,MAFK,EAGL;AACA,MAAMC,gBAAgB,GAAGJ,MAAM,CAC5B,YAAM;AACL,QACEE,IAAI,IACJ,OAAOG,QAAP,KAAoB,WADpB,IAEAA,QAAQ,CAACC,aAAT,YAAkCC,WAHpC,EAIE;AACA,aAAOF,QAAQ,CAACC,aAAhB;AACD;;AACD,WAAO,IAAP;AACD,GATD,EAD6B,CAA/B;AAaAP,EAAAA,SAAS,CAAC,YAAM;AACd,QAAIG,IAAJ,EAAU;AAAA;;AACR;AACA;AACA,UACE,CAACE,gBAAgB,CAACI,OAAlB,IACAH,QAAQ,CAACC,aAAT,YAAkCC,WADlC,IAEA,qBAACJ,MAAM,CAACK,OAAR,aAAC,gBAAgBC,QAAhB,CAAyBJ,QAAQ,CAACC,aAAlC,CAAD,CAHF,EAIE;AACAF,QAAAA,gBAAgB,CAACI,OAAjB,GAA2BH,QAAQ,CAACC,aAApC;AACD;;AAED,UAAMI,WAAW,GAAGP,MAAM,CAACK,OAA3B;AACA,UAAMG,eAAe,GAAGP,gBAAgB,CAACI,OAAzC;AACA,aAAO,YAAM;AACX;AACA,YAAIG,eAAe,IAAI,EAACD,WAAD,YAACA,WAAW,CAAED,QAAb,CAAsBJ,QAAQ,CAACC,aAA/B,CAAD,CAAvB,EAAuE;AACrEK,UAAAA,eAAe,CAACC,KAAhB,CAAsB;AAAEC,YAAAA,aAAa,EAAE;AAAjB,WAAtB;AACD;AACF,OALD;AAMD;AACF,GArBQ,EAqBN,CAACX,IAAD,EAAOC,MAAP,CArBM,CAAT;AAsBD","sourcesContent":["import type { MutableRefObject } from 'react';\nimport { useEffect, useRef } from 'react';\n\nexport function useFocusReturn(\n open: boolean,\n rootEl: MutableRefObject<HTMLElement | null>\n) {\n const previousFocusRef = useRef<HTMLElement | null>(\n (() => {\n if (\n open &&\n typeof document !== 'undefined' &&\n document.activeElement instanceof HTMLElement\n ) {\n return document.activeElement;\n }\n return null;\n })()\n );\n\n useEffect(() => {\n if (open) {\n // once opened, keep track of the element that triggered\n // the Modal opening\n if (\n !previousFocusRef.current &&\n document.activeElement instanceof HTMLElement &&\n !rootEl.current?.contains(document.activeElement)\n ) {\n previousFocusRef.current = document.activeElement;\n }\n\n const rootElement = rootEl.current;\n const previousElement = previousFocusRef.current;\n return () => {\n // on unmount, return focus to that element\n if (previousElement && !rootElement?.contains(document.activeElement)) {\n previousElement.focus({ preventScroll: true });\n }\n };\n }\n }, [open, rootEl]);\n}\n"],"file":"useFocusReturn.js"}
|
|
@@ -1,17 +1,21 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
1
2
|
import { useState } from 'react';
|
|
2
3
|
import { wrapEvent } from '../utils/wrapEvent';
|
|
3
|
-
export function useFocusState(
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
} = props;
|
|
8
|
-
const [hasFocus, setHasFocus] = useState(false);
|
|
4
|
+
export function useFocusState() {
|
|
5
|
+
var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
6
|
+
var onFocus = props.onFocus,
|
|
7
|
+
onBlur = props.onBlur;
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
var _useState = useState(false),
|
|
10
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
11
|
+
hasFocus = _useState2[0],
|
|
12
|
+
setHasFocus = _useState2[1];
|
|
13
|
+
|
|
14
|
+
var handleFocus = function handleFocus() {
|
|
11
15
|
setHasFocus(true);
|
|
12
16
|
};
|
|
13
17
|
|
|
14
|
-
|
|
18
|
+
var handleBlur = function handleBlur() {
|
|
15
19
|
setHasFocus(false);
|
|
16
20
|
};
|
|
17
21
|
|
|
@@ -20,7 +24,7 @@ export function useFocusState(props = {}) {
|
|
|
20
24
|
onFocus: wrapEvent(onFocus, handleFocus),
|
|
21
25
|
onBlur: wrapEvent(onBlur, handleBlur)
|
|
22
26
|
},
|
|
23
|
-
hasFocus
|
|
27
|
+
hasFocus: hasFocus
|
|
24
28
|
};
|
|
25
29
|
}
|
|
26
30
|
//# sourceMappingURL=useFocusState.js.map
|