@tale-ui/utils 0.0.3
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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/detectBrowser.d.ts +8 -0
- package/detectBrowser.js +64 -0
- package/empty.d.ts +3 -0
- package/empty.js +10 -0
- package/error.d.ts +2 -0
- package/error.js +23 -0
- package/esm/detectBrowser.d.ts +8 -0
- package/esm/detectBrowser.js +58 -0
- package/esm/empty.d.ts +3 -0
- package/esm/empty.js +3 -0
- package/esm/error.d.ts +2 -0
- package/esm/error.js +16 -0
- package/esm/fastHooks.d.ts +14 -0
- package/esm/fastHooks.js +43 -0
- package/esm/fastObjectShallowCompare.d.ts +1 -0
- package/esm/fastObjectShallowCompare.js +29 -0
- package/esm/formatErrorMessage.d.ts +18 -0
- package/esm/formatErrorMessage.js +26 -0
- package/esm/generateId.d.ts +1 -0
- package/esm/generateId.js +5 -0
- package/esm/getReactElementRef.d.ts +5 -0
- package/esm/getReactElementRef.js +14 -0
- package/esm/inertValue.d.ts +1 -0
- package/esm/inertValue.js +8 -0
- package/esm/isElementDisabled.d.ts +1 -0
- package/esm/isElementDisabled.js +3 -0
- package/esm/isMouseWithinBounds.d.ts +1 -0
- package/esm/isMouseWithinBounds.js +10 -0
- package/esm/mergeObjects.d.ts +1 -0
- package/esm/mergeObjects.js +15 -0
- package/esm/owner.d.ts +2 -0
- package/esm/owner.js +4 -0
- package/esm/package.json +1 -0
- package/esm/reactVersion.d.ts +3 -0
- package/esm/reactVersion.js +5 -0
- package/esm/safeReact.d.ts +2 -0
- package/esm/safeReact.js +6 -0
- package/esm/store/ReactStore.d.ts +91 -0
- package/esm/store/ReactStore.js +199 -0
- package/esm/store/Store.d.ts +58 -0
- package/esm/store/Store.js +111 -0
- package/esm/store/StoreInspector.d.ts +41 -0
- package/esm/store/StoreInspector.js +537 -0
- package/esm/store/createSelector.d.ts +30 -0
- package/esm/store/createSelector.js +148 -0
- package/esm/store/index.d.ts +5 -0
- package/esm/store/index.js +5 -0
- package/esm/store/useStore.d.ts +22 -0
- package/esm/store/useStore.js +107 -0
- package/esm/testUtils.d.ts +17 -0
- package/esm/testUtils.js +19 -0
- package/esm/useAnimationFrame.d.ts +18 -0
- package/esm/useAnimationFrame.js +106 -0
- package/esm/useControlled.d.ts +24 -0
- package/esm/useControlled.js +40 -0
- package/esm/useEnhancedClickHandler.d.ts +13 -0
- package/esm/useEnhancedClickHandler.js +38 -0
- package/esm/useForcedRerendering.d.ts +4 -0
- package/esm/useForcedRerendering.js +13 -0
- package/esm/useId.d.ts +7 -0
- package/esm/useId.js +41 -0
- package/esm/useInterval.d.ts +13 -0
- package/esm/useInterval.js +36 -0
- package/esm/useIsoLayoutEffect.d.ts +2 -0
- package/esm/useIsoLayoutEffect.js +5 -0
- package/esm/useMergedRefs.d.ts +21 -0
- package/esm/useMergedRefs.js +108 -0
- package/esm/useOnFirstRender.d.ts +1 -0
- package/esm/useOnFirstRender.js +10 -0
- package/esm/useOnMount.d.ts +5 -0
- package/esm/useOnMount.js +14 -0
- package/esm/usePreviousValue.d.ts +6 -0
- package/esm/usePreviousValue.js +22 -0
- package/esm/useRefWithInit.d.ts +10 -0
- package/esm/useRefWithInit.js +20 -0
- package/esm/useScrollLock.d.ts +7 -0
- package/esm/useScrollLock.js +244 -0
- package/esm/useStableCallback.d.ts +13 -0
- package/esm/useStableCallback.js +44 -0
- package/esm/useTimeout.d.ts +17 -0
- package/esm/useTimeout.js +43 -0
- package/esm/useValueAsRef.d.ts +10 -0
- package/esm/useValueAsRef.js +28 -0
- package/esm/visuallyHidden.d.ts +3 -0
- package/esm/visuallyHidden.js +20 -0
- package/esm/warn.d.ts +1 -0
- package/esm/warn.js +13 -0
- package/fastHooks.d.ts +14 -0
- package/fastHooks.js +54 -0
- package/fastObjectShallowCompare.d.ts +1 -0
- package/fastObjectShallowCompare.js +35 -0
- package/formatErrorMessage.d.ts +18 -0
- package/formatErrorMessage.js +33 -0
- package/generateId.d.ts +1 -0
- package/generateId.js +11 -0
- package/getReactElementRef.d.ts +5 -0
- package/getReactElementRef.js +20 -0
- package/inertValue.d.ts +1 -0
- package/inertValue.js +14 -0
- package/isElementDisabled.d.ts +1 -0
- package/isElementDisabled.js +9 -0
- package/isMouseWithinBounds.d.ts +1 -0
- package/isMouseWithinBounds.js +16 -0
- package/mergeObjects.d.ts +1 -0
- package/mergeObjects.js +21 -0
- package/owner.d.ts +2 -0
- package/owner.js +16 -0
- package/package.json +64 -0
- package/reactVersion.d.ts +3 -0
- package/reactVersion.js +12 -0
- package/safeReact.d.ts +2 -0
- package/safeReact.js +12 -0
- package/store/ReactStore.d.ts +91 -0
- package/store/ReactStore.js +205 -0
- package/store/Store.d.ts +58 -0
- package/store/Store.js +118 -0
- package/store/StoreInspector.d.ts +41 -0
- package/store/StoreInspector.js +544 -0
- package/store/createSelector.d.ts +30 -0
- package/store/createSelector.js +154 -0
- package/store/index.d.ts +5 -0
- package/store/index.js +60 -0
- package/store/useStore.d.ts +22 -0
- package/store/useStore.js +115 -0
- package/testUtils.d.ts +17 -0
- package/testUtils.js +26 -0
- package/useAnimationFrame.d.ts +18 -0
- package/useAnimationFrame.js +113 -0
- package/useControlled.d.ts +24 -0
- package/useControlled.js +46 -0
- package/useEnhancedClickHandler.d.ts +13 -0
- package/useEnhancedClickHandler.js +44 -0
- package/useForcedRerendering.d.ts +4 -0
- package/useForcedRerendering.js +18 -0
- package/useId.d.ts +7 -0
- package/useId.js +47 -0
- package/useInterval.d.ts +13 -0
- package/useInterval.js +43 -0
- package/useIsoLayoutEffect.d.ts +2 -0
- package/useIsoLayoutEffect.js +11 -0
- package/useMergedRefs.d.ts +21 -0
- package/useMergedRefs.js +114 -0
- package/useOnFirstRender.d.ts +1 -0
- package/useOnFirstRender.js +16 -0
- package/useOnMount.d.ts +5 -0
- package/useOnMount.js +20 -0
- package/usePreviousValue.d.ts +6 -0
- package/usePreviousValue.js +27 -0
- package/useRefWithInit.d.ts +10 -0
- package/useRefWithInit.js +26 -0
- package/useScrollLock.d.ts +7 -0
- package/useScrollLock.js +249 -0
- package/useStableCallback.d.ts +13 -0
- package/useStableCallback.js +49 -0
- package/useTimeout.d.ts +17 -0
- package/useTimeout.js +50 -0
- package/useValueAsRef.d.ts +10 -0
- package/useValueAsRef.js +32 -0
- package/visuallyHidden.d.ts +3 -0
- package/visuallyHidden.js +26 -0
- package/warn.d.ts +1 -0
- package/warn.js +19 -0
|
@@ -0,0 +1,537 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
|
|
3
|
+
var _style, _FileJson, _SquareTerminal, _h, _h2, _h3, _CloseIcon, _div, _svg, _svg2, _svg3;
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import * as ReactDOM from 'react-dom';
|
|
6
|
+
import { useForcedRerendering } from "../useForcedRerendering.js";
|
|
7
|
+
import { useStableCallback } from "../useStableCallback.js";
|
|
8
|
+
import { useAnimationFrame } from "../useAnimationFrame.js";
|
|
9
|
+
import { useIsoLayoutEffect } from "../useIsoLayoutEffect.js";
|
|
10
|
+
import { useTimeout } from "../useTimeout.js";
|
|
11
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
12
|
+
const STYLES = `
|
|
13
|
+
.taleui-store-inspector-trigger {
|
|
14
|
+
all: unset;
|
|
15
|
+
width: 32px;
|
|
16
|
+
height: 32px;
|
|
17
|
+
display: inline-flex;
|
|
18
|
+
align-items: center;
|
|
19
|
+
justify-content: center;
|
|
20
|
+
color: oklch(0.651 0.078 264);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.taleui-store-inspector-trigger:hover,
|
|
24
|
+
.taleui-store-inspector-trigger:focus-visible {
|
|
25
|
+
opacity: 0.8;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.taleui-store-inspector-content {
|
|
29
|
+
background: #101010;
|
|
30
|
+
flex: 1 1 auto;
|
|
31
|
+
min-height: 0;
|
|
32
|
+
overflow: auto;
|
|
33
|
+
padding-bottom: 12px;
|
|
34
|
+
scrollbar-width: thin;
|
|
35
|
+
padding: 8px;
|
|
36
|
+
border-radius: 4px;
|
|
37
|
+
border: 1px solid rgba(255, 255, 255, 0.1);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.taleui-store-inspector-content h3 {
|
|
41
|
+
text-transform: uppercase;
|
|
42
|
+
font-weight: bold;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.taleui-store-inspector-content pre {
|
|
46
|
+
margin: 0 0 16px 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.taleui-store-inspector-content pre:last-child {
|
|
50
|
+
margin-bottom: 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
.taleui-store-inspector-root {
|
|
54
|
+
position: fixed;
|
|
55
|
+
background: oklch(0.34 0.036 264);
|
|
56
|
+
color: #fff;
|
|
57
|
+
z-index: 1000;
|
|
58
|
+
font-size: 12px;
|
|
59
|
+
padding: 8px;
|
|
60
|
+
border-radius: 8px;
|
|
61
|
+
display: flex;
|
|
62
|
+
flex-direction: column;
|
|
63
|
+
box-sizing: border-box;
|
|
64
|
+
max-width: 50vw;
|
|
65
|
+
color-scheme: dark;
|
|
66
|
+
overflow: clip;
|
|
67
|
+
box-shadow:
|
|
68
|
+
0 10px 15px -3px oklch(12% 9% 264deg / 8%),
|
|
69
|
+
0 4px 6px -4px oklch(12% 9% 264deg / 8%);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
.taleui-store-inspector-header {
|
|
73
|
+
display: flex;
|
|
74
|
+
align-items: center;
|
|
75
|
+
cursor: move;
|
|
76
|
+
user-select: none;
|
|
77
|
+
-webkit-user-select: none;
|
|
78
|
+
touch-action: none;
|
|
79
|
+
padding: 4px 8px 8px 8px;
|
|
80
|
+
gap: 8px;
|
|
81
|
+
|
|
82
|
+
h2 {
|
|
83
|
+
font-size: 16px;
|
|
84
|
+
flex-grow: 1;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
.taleui-store-inspector-header button {
|
|
89
|
+
all: unset;
|
|
90
|
+
width: 32px;
|
|
91
|
+
height: 32px;
|
|
92
|
+
display: flex;
|
|
93
|
+
align-items: center;
|
|
94
|
+
justify-content: center;
|
|
95
|
+
cursor: default;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
.taleui-store-inspector-header button:hover,
|
|
99
|
+
.taleui-store-inspector-header button:focus-visible {
|
|
100
|
+
opacity: 0.8;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
.taleui-store-inspector-resize-handle {
|
|
104
|
+
position: absolute;
|
|
105
|
+
width: 8px;
|
|
106
|
+
height: 8px;
|
|
107
|
+
right: -4px;
|
|
108
|
+
bottom: -4px;
|
|
109
|
+
cursor: se-resize;
|
|
110
|
+
background: linear-gradient(135deg, transparent 50%, rgba(255, 255, 255, 0.25) 50%);
|
|
111
|
+
border-radius: 2px;
|
|
112
|
+
}
|
|
113
|
+
`;
|
|
114
|
+
/**
|
|
115
|
+
* A tool to inspect the state of a Store in a floating panel.
|
|
116
|
+
* This is intended for development and debugging purposes.
|
|
117
|
+
*/
|
|
118
|
+
export function StoreInspector(props) {
|
|
119
|
+
const {
|
|
120
|
+
store,
|
|
121
|
+
title,
|
|
122
|
+
additionalData,
|
|
123
|
+
defaultOpen = false
|
|
124
|
+
} = props;
|
|
125
|
+
const [open, setOpen] = React.useState(defaultOpen);
|
|
126
|
+
return /*#__PURE__*/_jsxs(React.Fragment, {
|
|
127
|
+
children: [_style || (_style = /*#__PURE__*/_jsx("style", {
|
|
128
|
+
href: "taleui-store-inspector",
|
|
129
|
+
precedence: "default",
|
|
130
|
+
children: STYLES
|
|
131
|
+
})), /*#__PURE__*/_jsx("button", {
|
|
132
|
+
className: "taleui-store-inspector-trigger",
|
|
133
|
+
type: "button",
|
|
134
|
+
onClick: event => {
|
|
135
|
+
event.preventDefault();
|
|
136
|
+
event.stopPropagation();
|
|
137
|
+
setOpen(o => !o);
|
|
138
|
+
},
|
|
139
|
+
title: "Toggle store inspector",
|
|
140
|
+
"aria-hidden": true,
|
|
141
|
+
children: _FileJson || (_FileJson = /*#__PURE__*/_jsx(FileJson, {}))
|
|
142
|
+
}), /*#__PURE__*/_jsx(StoreInspectorPanel, {
|
|
143
|
+
open: open,
|
|
144
|
+
store: store,
|
|
145
|
+
title: title,
|
|
146
|
+
additionalData: additionalData,
|
|
147
|
+
onClose: () => setOpen(false)
|
|
148
|
+
})]
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
export function StoreInspectorPanel({
|
|
152
|
+
store,
|
|
153
|
+
title,
|
|
154
|
+
additionalData,
|
|
155
|
+
open,
|
|
156
|
+
onClose
|
|
157
|
+
}) {
|
|
158
|
+
const rerender = useForcedRerendering();
|
|
159
|
+
const rerenderTimeout = useTimeout();
|
|
160
|
+
|
|
161
|
+
// Update when state changes
|
|
162
|
+
useIsoLayoutEffect(() => {
|
|
163
|
+
const unsubscribe = store.subscribe(() => {
|
|
164
|
+
rerenderTimeout.start(1, () => rerender());
|
|
165
|
+
});
|
|
166
|
+
return unsubscribe;
|
|
167
|
+
}, [store, rerender, rerenderTimeout]);
|
|
168
|
+
const logToConsole = useStableCallback(() => {
|
|
169
|
+
const data = {
|
|
170
|
+
state: store.state
|
|
171
|
+
};
|
|
172
|
+
if (Object.keys(store.context ?? {}).length > 0) {
|
|
173
|
+
data.context = store.context;
|
|
174
|
+
}
|
|
175
|
+
if (additionalData !== undefined) {
|
|
176
|
+
data.additionalData = additionalData;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// eslint-disable-next-line no-console
|
|
180
|
+
console.log(data);
|
|
181
|
+
});
|
|
182
|
+
if (typeof document === 'undefined') {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
const content = /*#__PURE__*/_jsxs(Window, {
|
|
186
|
+
title: title ?? 'Store Inspector',
|
|
187
|
+
onClose: onClose,
|
|
188
|
+
headerActions: /*#__PURE__*/_jsx("button", {
|
|
189
|
+
type: "button",
|
|
190
|
+
onClick: logToConsole,
|
|
191
|
+
title: "Log to console",
|
|
192
|
+
children: _SquareTerminal || (_SquareTerminal = /*#__PURE__*/_jsx(SquareTerminal, {}))
|
|
193
|
+
}),
|
|
194
|
+
children: [_h || (_h = /*#__PURE__*/_jsx("h3", {
|
|
195
|
+
children: "State"
|
|
196
|
+
})), /*#__PURE__*/_jsx("pre", {
|
|
197
|
+
children: JSON.stringify(store.state, getStringifyReplacer(), 2)
|
|
198
|
+
}), Object.keys(store.context ?? {}).length > 0 && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
199
|
+
children: [_h2 || (_h2 = /*#__PURE__*/_jsx("h3", {
|
|
200
|
+
children: "Context"
|
|
201
|
+
})), /*#__PURE__*/_jsx("pre", {
|
|
202
|
+
children: JSON.stringify(store.context, getStringifyReplacer(), 2)
|
|
203
|
+
})]
|
|
204
|
+
}), additionalData !== undefined && /*#__PURE__*/_jsxs(React.Fragment, {
|
|
205
|
+
children: [_h3 || (_h3 = /*#__PURE__*/_jsx("h3", {
|
|
206
|
+
children: "Additional data"
|
|
207
|
+
})), /*#__PURE__*/_jsx("pre", {
|
|
208
|
+
children: JSON.stringify(additionalData, getStringifyReplacer(), 2)
|
|
209
|
+
})]
|
|
210
|
+
})]
|
|
211
|
+
});
|
|
212
|
+
return open ? /*#__PURE__*/ReactDOM.createPortal(content, document.body) : null;
|
|
213
|
+
}
|
|
214
|
+
function getStringifyReplacer() {
|
|
215
|
+
const ancestors = [];
|
|
216
|
+
return function replacer(_, value) {
|
|
217
|
+
if (value instanceof Element) {
|
|
218
|
+
return `Element(${value.tagName.toLowerCase()}${value.id ? `#${value.id}` : ''})`;
|
|
219
|
+
}
|
|
220
|
+
if (value === undefined) {
|
|
221
|
+
return '[undefined]';
|
|
222
|
+
}
|
|
223
|
+
if (value instanceof Map) {
|
|
224
|
+
return Array.from(value.entries());
|
|
225
|
+
}
|
|
226
|
+
if (value instanceof Set) {
|
|
227
|
+
return Array.from(value);
|
|
228
|
+
}
|
|
229
|
+
if (typeof value !== 'object' || value === null) {
|
|
230
|
+
return value;
|
|
231
|
+
}
|
|
232
|
+
// `this` is the object that value is contained in,
|
|
233
|
+
// i.e., its direct parent.
|
|
234
|
+
while (ancestors.length > 0 && ancestors.at(-1) !== this) {
|
|
235
|
+
ancestors.pop();
|
|
236
|
+
}
|
|
237
|
+
if (ancestors.includes(value)) {
|
|
238
|
+
return '[circular reference]';
|
|
239
|
+
}
|
|
240
|
+
ancestors.push(value);
|
|
241
|
+
return value;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* A reusable draggable and resizable window component.
|
|
246
|
+
* Handles all the pointer events for dragging and resizing internally.
|
|
247
|
+
*/
|
|
248
|
+
function Window({
|
|
249
|
+
title,
|
|
250
|
+
onClose,
|
|
251
|
+
children,
|
|
252
|
+
headerActions
|
|
253
|
+
}) {
|
|
254
|
+
const rootRef = React.useRef(null);
|
|
255
|
+
const headerRef = React.useRef(null);
|
|
256
|
+
const resizeHandleRef = React.useRef(null);
|
|
257
|
+
const raf = useAnimationFrame();
|
|
258
|
+
const minWidth = 160;
|
|
259
|
+
const minHeight = 52;
|
|
260
|
+
|
|
261
|
+
// Track position when user drags the window
|
|
262
|
+
const [position, setPosition] = React.useState(null);
|
|
263
|
+
const dragStateRef = React.useRef(null);
|
|
264
|
+
|
|
265
|
+
// Track size when user resizes the window
|
|
266
|
+
const [size, setSize] = React.useState(null);
|
|
267
|
+
const resizeStateRef = React.useRef(null);
|
|
268
|
+
useIsoLayoutEffect(() => {
|
|
269
|
+
if (position != null) {
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
const el = rootRef.current;
|
|
273
|
+
if (!el) {
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
setPosition({
|
|
277
|
+
left: 8,
|
|
278
|
+
top: 8
|
|
279
|
+
});
|
|
280
|
+
}, [position]);
|
|
281
|
+
const onPointerDown = useStableCallback(event => {
|
|
282
|
+
if (!headerRef.current || !rootRef.current) {
|
|
283
|
+
return;
|
|
284
|
+
}
|
|
285
|
+
const target = event.target;
|
|
286
|
+
if (target && target.closest('button')) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
const currentPos = position ?? {
|
|
290
|
+
left: 8,
|
|
291
|
+
top: 8
|
|
292
|
+
};
|
|
293
|
+
dragStateRef.current = {
|
|
294
|
+
dragging: true,
|
|
295
|
+
startX: event.clientX,
|
|
296
|
+
startY: event.clientY,
|
|
297
|
+
startLeft: currentPos.left,
|
|
298
|
+
startTop: currentPos.top
|
|
299
|
+
};
|
|
300
|
+
try {
|
|
301
|
+
headerRef.current.setPointerCapture(event.pointerId);
|
|
302
|
+
} catch {
|
|
303
|
+
void 0;
|
|
304
|
+
}
|
|
305
|
+
event.preventDefault();
|
|
306
|
+
});
|
|
307
|
+
const endDrag = useStableCallback(event => {
|
|
308
|
+
if (headerRef.current && event) {
|
|
309
|
+
try {
|
|
310
|
+
headerRef.current.releasePointerCapture(event.pointerId);
|
|
311
|
+
} catch {
|
|
312
|
+
void 0;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
if (dragStateRef.current) {
|
|
316
|
+
dragStateRef.current.dragging = false;
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
const onPointerMove = useStableCallback(event => {
|
|
320
|
+
const state = dragStateRef.current;
|
|
321
|
+
if (!state || !state.dragging) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
const nextLeft = state.startLeft + (event.clientX - state.startX);
|
|
325
|
+
const nextTop = Math.max(0, state.startTop + (event.clientY - state.startY));
|
|
326
|
+
raf.request(() => {
|
|
327
|
+
setPosition({
|
|
328
|
+
left: nextLeft,
|
|
329
|
+
top: nextTop
|
|
330
|
+
});
|
|
331
|
+
});
|
|
332
|
+
});
|
|
333
|
+
const onResizePointerDown = useStableCallback(event => {
|
|
334
|
+
if (!rootRef.current) {
|
|
335
|
+
return;
|
|
336
|
+
}
|
|
337
|
+
const rect = rootRef.current.getBoundingClientRect();
|
|
338
|
+
const currentSize = size ?? {
|
|
339
|
+
width: rect.width,
|
|
340
|
+
height: rect.height
|
|
341
|
+
};
|
|
342
|
+
const currentLeft = position?.left ?? rect.left;
|
|
343
|
+
const currentTop = position?.top ?? rect.top;
|
|
344
|
+
const maxWidth = Math.max(100, window.innerWidth - currentLeft);
|
|
345
|
+
const maxHeight = Math.max(80, window.innerHeight - currentTop);
|
|
346
|
+
resizeStateRef.current = {
|
|
347
|
+
resizing: true,
|
|
348
|
+
startX: event.clientX,
|
|
349
|
+
startY: event.clientY,
|
|
350
|
+
startWidth: currentSize.width,
|
|
351
|
+
startHeight: currentSize.height,
|
|
352
|
+
minWidth,
|
|
353
|
+
minHeight,
|
|
354
|
+
maxWidth,
|
|
355
|
+
maxHeight
|
|
356
|
+
};
|
|
357
|
+
try {
|
|
358
|
+
event.currentTarget?.setPointerCapture?.(event.pointerId);
|
|
359
|
+
} catch {
|
|
360
|
+
void 0;
|
|
361
|
+
}
|
|
362
|
+
event.preventDefault();
|
|
363
|
+
});
|
|
364
|
+
const onResizePointerMove = useStableCallback(event => {
|
|
365
|
+
const state = resizeStateRef.current;
|
|
366
|
+
if (!state || !state.resizing) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
const dx = event.clientX - state.startX;
|
|
370
|
+
const dy = event.clientY - state.startY;
|
|
371
|
+
const nextWidth = Math.min(state.maxWidth, Math.max(state.minWidth, state.startWidth + dx));
|
|
372
|
+
const nextHeight = Math.min(state.maxHeight, Math.max(state.minHeight, state.startHeight + dy));
|
|
373
|
+
raf.request(() => {
|
|
374
|
+
setSize({
|
|
375
|
+
width: nextWidth,
|
|
376
|
+
height: nextHeight
|
|
377
|
+
});
|
|
378
|
+
});
|
|
379
|
+
});
|
|
380
|
+
const endResize = useStableCallback(event => {
|
|
381
|
+
if (event) {
|
|
382
|
+
try {
|
|
383
|
+
event.target?.releasePointerCapture?.(event.pointerId);
|
|
384
|
+
} catch {
|
|
385
|
+
void 0;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
if (resizeStateRef.current) {
|
|
389
|
+
resizeStateRef.current.resizing = false;
|
|
390
|
+
}
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
// Bind/unbind global listeners for dragging and resizing
|
|
394
|
+
useIsoLayoutEffect(() => {
|
|
395
|
+
const move = event => {
|
|
396
|
+
onPointerMove(event);
|
|
397
|
+
onResizePointerMove(event);
|
|
398
|
+
};
|
|
399
|
+
const up = event => {
|
|
400
|
+
endDrag(event);
|
|
401
|
+
endResize(event);
|
|
402
|
+
};
|
|
403
|
+
window.addEventListener('pointermove', move);
|
|
404
|
+
window.addEventListener('pointerup', up);
|
|
405
|
+
window.addEventListener('pointercancel', up);
|
|
406
|
+
return () => {
|
|
407
|
+
window.removeEventListener('pointermove', move);
|
|
408
|
+
window.removeEventListener('pointerup', up);
|
|
409
|
+
window.removeEventListener('pointercancel', up);
|
|
410
|
+
};
|
|
411
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
412
|
+
}, []);
|
|
413
|
+
|
|
414
|
+
// Compute window style once per render
|
|
415
|
+
const style = {};
|
|
416
|
+
const viewportMax = typeof window !== 'undefined' ? Math.max(0, window.innerHeight - 16) : undefined;
|
|
417
|
+
if (position) {
|
|
418
|
+
style.top = position.top;
|
|
419
|
+
style.left = position.left;
|
|
420
|
+
style.right = 'auto';
|
|
421
|
+
style.position = 'fixed';
|
|
422
|
+
if (size?.width != null) {
|
|
423
|
+
style.width = size.width;
|
|
424
|
+
}
|
|
425
|
+
if (size?.height != null) {
|
|
426
|
+
style.height = size.height;
|
|
427
|
+
}
|
|
428
|
+
style.maxHeight = typeof window !== 'undefined' ? Math.max(0, window.innerHeight - position.top - 8) : undefined;
|
|
429
|
+
} else {
|
|
430
|
+
if (size?.width != null) {
|
|
431
|
+
style.width = size.width;
|
|
432
|
+
}
|
|
433
|
+
if (size?.height != null) {
|
|
434
|
+
style.height = size.height;
|
|
435
|
+
}
|
|
436
|
+
style.maxHeight = viewportMax;
|
|
437
|
+
}
|
|
438
|
+
return /*#__PURE__*/_jsxs("div", {
|
|
439
|
+
ref: rootRef,
|
|
440
|
+
className: "taleui-store-inspector-root",
|
|
441
|
+
style: style,
|
|
442
|
+
children: [/*#__PURE__*/_jsxs("div", {
|
|
443
|
+
ref: headerRef,
|
|
444
|
+
className: "taleui-store-inspector-header",
|
|
445
|
+
onPointerDown: onPointerDown,
|
|
446
|
+
children: [/*#__PURE__*/_jsx("h2", {
|
|
447
|
+
children: title
|
|
448
|
+
}), headerActions, /*#__PURE__*/_jsx("button", {
|
|
449
|
+
type: "button",
|
|
450
|
+
onClick: onClose,
|
|
451
|
+
title: "Close window",
|
|
452
|
+
children: _CloseIcon || (_CloseIcon = /*#__PURE__*/_jsx(CloseIcon, {}))
|
|
453
|
+
})]
|
|
454
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
455
|
+
className: "taleui-store-inspector-content",
|
|
456
|
+
children: children
|
|
457
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
458
|
+
ref: resizeHandleRef,
|
|
459
|
+
onPointerDown: onResizePointerDown,
|
|
460
|
+
style: {
|
|
461
|
+
position: 'relative'
|
|
462
|
+
},
|
|
463
|
+
children: _div || (_div = /*#__PURE__*/_jsx("div", {
|
|
464
|
+
className: "taleui-store-inspector-resize-handle"
|
|
465
|
+
}))
|
|
466
|
+
})]
|
|
467
|
+
});
|
|
468
|
+
}
|
|
469
|
+
function CloseIcon() {
|
|
470
|
+
return _svg || (_svg = /*#__PURE__*/_jsxs("svg", {
|
|
471
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
472
|
+
width: "24",
|
|
473
|
+
height: "24",
|
|
474
|
+
viewBox: "0 0 24 24",
|
|
475
|
+
fill: "none",
|
|
476
|
+
stroke: "currentColor",
|
|
477
|
+
strokeWidth: "2",
|
|
478
|
+
strokeLinecap: "round",
|
|
479
|
+
strokeLinejoin: "round",
|
|
480
|
+
children: [/*#__PURE__*/_jsx("circle", {
|
|
481
|
+
cx: "12",
|
|
482
|
+
cy: "12",
|
|
483
|
+
r: "10"
|
|
484
|
+
}), /*#__PURE__*/_jsx("path", {
|
|
485
|
+
d: "m15 9-6 6"
|
|
486
|
+
}), /*#__PURE__*/_jsx("path", {
|
|
487
|
+
d: "m9 9 6 6"
|
|
488
|
+
})]
|
|
489
|
+
}));
|
|
490
|
+
}
|
|
491
|
+
function FileJson() {
|
|
492
|
+
return _svg2 || (_svg2 = /*#__PURE__*/_jsxs("svg", {
|
|
493
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
494
|
+
width: "24",
|
|
495
|
+
height: "24",
|
|
496
|
+
viewBox: "0 0 24 24",
|
|
497
|
+
fill: "none",
|
|
498
|
+
stroke: "currentColor",
|
|
499
|
+
strokeWidth: "2",
|
|
500
|
+
strokeLinecap: "round",
|
|
501
|
+
strokeLinejoin: "round",
|
|
502
|
+
children: [/*#__PURE__*/_jsx("path", {
|
|
503
|
+
d: "M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z"
|
|
504
|
+
}), /*#__PURE__*/_jsx("path", {
|
|
505
|
+
d: "M14 2v4a2 2 0 0 0 2 2h4"
|
|
506
|
+
}), /*#__PURE__*/_jsx("path", {
|
|
507
|
+
d: "M10 12a1 1 0 0 0-1 1v1a1 1 0 0 1-1 1 1 1 0 0 1 1 1v1a1 1 0 0 0 1 1"
|
|
508
|
+
}), /*#__PURE__*/_jsx("path", {
|
|
509
|
+
d: "M14 18a1 1 0 0 0 1-1v-1a1 1 0 0 1 1-1 1 1 0 0 1-1-1v-1a1 1 0 0 0-1-1"
|
|
510
|
+
})]
|
|
511
|
+
}));
|
|
512
|
+
}
|
|
513
|
+
function SquareTerminal() {
|
|
514
|
+
return _svg3 || (_svg3 = /*#__PURE__*/_jsxs("svg", {
|
|
515
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
516
|
+
width: "24",
|
|
517
|
+
height: "24",
|
|
518
|
+
viewBox: "0 0 24 24",
|
|
519
|
+
fill: "none",
|
|
520
|
+
stroke: "currentColor",
|
|
521
|
+
strokeWidth: "2",
|
|
522
|
+
strokeLinecap: "round",
|
|
523
|
+
strokeLinejoin: "round",
|
|
524
|
+
children: [/*#__PURE__*/_jsx("path", {
|
|
525
|
+
d: "m7 11 2-2-2-2"
|
|
526
|
+
}), /*#__PURE__*/_jsx("path", {
|
|
527
|
+
d: "M11 13h4"
|
|
528
|
+
}), /*#__PURE__*/_jsx("rect", {
|
|
529
|
+
width: "18",
|
|
530
|
+
height: "18",
|
|
531
|
+
x: "3",
|
|
532
|
+
y: "3",
|
|
533
|
+
rx: "2",
|
|
534
|
+
ry: "2"
|
|
535
|
+
})]
|
|
536
|
+
}));
|
|
537
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { Selector } from 'reselect';
|
|
2
|
+
type Fn = (...args: any[]) => any;
|
|
3
|
+
type CreateSelectorFunction = <const Args extends any[], const Selectors extends ReadonlyArray<Selector<any>>, const Combiner extends (...args: readonly [...ReturnTypes<Selectors>, ...Args]) => any>(...items: [...Selectors, Combiner]) => (...args: Selectors['length'] extends 0 ? MergeParams<ReturnTypes<Selectors>, Parameters<Combiner>> : [StateFromSelectorList<Selectors>, ...MergeParams<ReturnTypes<Selectors>, Parameters<Combiner>>]) => ReturnType<Combiner>;
|
|
4
|
+
type StateFromSelectorList<Selectors extends readonly any[]> = Selectors extends [f: infer F, ...other: infer R] ? StateFromSelector<F> extends StateFromSelectorList<R> ? StateFromSelector<F> : StateFromSelectorList<R> : {};
|
|
5
|
+
type StateFromSelector<T> = T extends ((first: infer F, ...args: any[]) => any) ? F : never;
|
|
6
|
+
type DropFirst<T> = T extends [any, ...infer Xs] ? Xs : [];
|
|
7
|
+
type ReturnTypes<FunctionsArray extends readonly Fn[]> = { [Index in keyof FunctionsArray]: FunctionsArray[Index] extends FunctionsArray[number] ? ReturnType<FunctionsArray[Index]> : never };
|
|
8
|
+
type MergeParams<STypes extends readonly unknown[], CTypes extends readonly unknown[]> = STypes['length'] extends 0 ? CTypes : MergeParams<DropFirst<STypes>, DropFirst<CTypes>>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a selector function that can be used to derive values from the store's state.
|
|
11
|
+
* The selector can take up to three additional arguments that can be used in the selector logic.
|
|
12
|
+
* This function accepts up to six functions and combines them into a single selector function.
|
|
13
|
+
* The last parameter is the combiner function that combines the results of the previous selectors.
|
|
14
|
+
*
|
|
15
|
+
* @example
|
|
16
|
+
* const selector = createSelector(
|
|
17
|
+
* (state) => state.disabled
|
|
18
|
+
* );
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* const selector = createSelector(
|
|
22
|
+
* (state) => state.disabled,
|
|
23
|
+
* (state) => state.open,
|
|
24
|
+
* (disabled, open) => ({ disabled, open })
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
*/
|
|
28
|
+
export declare const createSelector: CreateSelectorFunction;
|
|
29
|
+
export declare const createSelectorMemoized: CreateSelectorFunction;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { lruMemoize, createSelectorCreator } from 'reselect';
|
|
2
|
+
|
|
3
|
+
/* eslint-disable no-underscore-dangle */ // __cacheKey__
|
|
4
|
+
|
|
5
|
+
const reselectCreateSelector = createSelectorCreator({
|
|
6
|
+
memoize: lruMemoize,
|
|
7
|
+
memoizeOptions: {
|
|
8
|
+
maxSize: 1,
|
|
9
|
+
equalityCheck: Object.is
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
/**
|
|
13
|
+
* Creates a selector function that can be used to derive values from the store's state.
|
|
14
|
+
* The selector can take up to three additional arguments that can be used in the selector logic.
|
|
15
|
+
* This function accepts up to six functions and combines them into a single selector function.
|
|
16
|
+
* The last parameter is the combiner function that combines the results of the previous selectors.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* const selector = createSelector(
|
|
20
|
+
* (state) => state.disabled
|
|
21
|
+
* );
|
|
22
|
+
*
|
|
23
|
+
* @example
|
|
24
|
+
* const selector = createSelector(
|
|
25
|
+
* (state) => state.disabled,
|
|
26
|
+
* (state) => state.open,
|
|
27
|
+
* (disabled, open) => ({ disabled, open })
|
|
28
|
+
* );
|
|
29
|
+
*
|
|
30
|
+
*/
|
|
31
|
+
/* eslint-disable id-denylist */
|
|
32
|
+
export const createSelector = (a, b, c, d, e, f, ...other) => {
|
|
33
|
+
if (other.length > 0) {
|
|
34
|
+
throw /* FIXME (minify-errors-in-prod): Unminified error message in production build! */new Error('Unsupported number of selectors');
|
|
35
|
+
}
|
|
36
|
+
let selector;
|
|
37
|
+
if (a && b && c && d && e && f) {
|
|
38
|
+
selector = (state, a1, a2, a3) => {
|
|
39
|
+
const va = a(state, a1, a2, a3);
|
|
40
|
+
const vb = b(state, a1, a2, a3);
|
|
41
|
+
const vc = c(state, a1, a2, a3);
|
|
42
|
+
const vd = d(state, a1, a2, a3);
|
|
43
|
+
const ve = e(state, a1, a2, a3);
|
|
44
|
+
return f(va, vb, vc, vd, ve, a1, a2, a3);
|
|
45
|
+
};
|
|
46
|
+
} else if (a && b && c && d && e) {
|
|
47
|
+
selector = (state, a1, a2, a3) => {
|
|
48
|
+
const va = a(state, a1, a2, a3);
|
|
49
|
+
const vb = b(state, a1, a2, a3);
|
|
50
|
+
const vc = c(state, a1, a2, a3);
|
|
51
|
+
const vd = d(state, a1, a2, a3);
|
|
52
|
+
return e(va, vb, vc, vd, a1, a2, a3);
|
|
53
|
+
};
|
|
54
|
+
} else if (a && b && c && d) {
|
|
55
|
+
selector = (state, a1, a2, a3) => {
|
|
56
|
+
const va = a(state, a1, a2, a3);
|
|
57
|
+
const vb = b(state, a1, a2, a3);
|
|
58
|
+
const vc = c(state, a1, a2, a3);
|
|
59
|
+
return d(va, vb, vc, a1, a2, a3);
|
|
60
|
+
};
|
|
61
|
+
} else if (a && b && c) {
|
|
62
|
+
selector = (state, a1, a2, a3) => {
|
|
63
|
+
const va = a(state, a1, a2, a3);
|
|
64
|
+
const vb = b(state, a1, a2, a3);
|
|
65
|
+
return c(va, vb, a1, a2, a3);
|
|
66
|
+
};
|
|
67
|
+
} else if (a && b) {
|
|
68
|
+
selector = (state, a1, a2, a3) => {
|
|
69
|
+
const va = a(state, a1, a2, a3);
|
|
70
|
+
return b(va, a1, a2, a3);
|
|
71
|
+
};
|
|
72
|
+
} else if (a) {
|
|
73
|
+
selector = a;
|
|
74
|
+
} else {
|
|
75
|
+
throw /* minify-error-disabled */new Error('Missing arguments');
|
|
76
|
+
}
|
|
77
|
+
return selector;
|
|
78
|
+
};
|
|
79
|
+
/* eslint-enable id-denylist */
|
|
80
|
+
|
|
81
|
+
export const createSelectorMemoized = (...selectors) => {
|
|
82
|
+
const cache = new WeakMap();
|
|
83
|
+
let nextCacheId = 1;
|
|
84
|
+
const combiner = selectors[selectors.length - 1];
|
|
85
|
+
const nSelectors = selectors.length - 1 || 1;
|
|
86
|
+
// (s1, s2, ..., sN, a1, a2, a3) => { ... }
|
|
87
|
+
const argsLength = combiner.length - nSelectors;
|
|
88
|
+
if (argsLength > 3) {
|
|
89
|
+
throw /* FIXME (minify-errors-in-prod): Unminified error message in production build! */new Error('Unsupported number of arguments');
|
|
90
|
+
}
|
|
91
|
+
const selector = (state, a1, a2, a3) => {
|
|
92
|
+
let cacheKey = state.__cacheKey__;
|
|
93
|
+
if (!cacheKey) {
|
|
94
|
+
cacheKey = {
|
|
95
|
+
id: nextCacheId
|
|
96
|
+
};
|
|
97
|
+
state.__cacheKey__ = cacheKey;
|
|
98
|
+
nextCacheId += 1;
|
|
99
|
+
}
|
|
100
|
+
let fn = cache.get(cacheKey);
|
|
101
|
+
if (!fn) {
|
|
102
|
+
let reselectArgs = selectors;
|
|
103
|
+
const selectorArgs = [undefined, undefined, undefined];
|
|
104
|
+
switch (argsLength) {
|
|
105
|
+
case 0:
|
|
106
|
+
break;
|
|
107
|
+
case 1:
|
|
108
|
+
{
|
|
109
|
+
reselectArgs = [...selectors.slice(0, -1), () => selectorArgs[0], combiner];
|
|
110
|
+
break;
|
|
111
|
+
}
|
|
112
|
+
case 2:
|
|
113
|
+
{
|
|
114
|
+
reselectArgs = [...selectors.slice(0, -1), () => selectorArgs[0], () => selectorArgs[1], combiner];
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
case 3:
|
|
118
|
+
{
|
|
119
|
+
reselectArgs = [...selectors.slice(0, -1), () => selectorArgs[0], () => selectorArgs[1], () => selectorArgs[2], combiner];
|
|
120
|
+
break;
|
|
121
|
+
}
|
|
122
|
+
default:
|
|
123
|
+
throw /* FIXME (minify-errors-in-prod): Unminified error message in production build! */new Error('Unsupported number of arguments');
|
|
124
|
+
}
|
|
125
|
+
fn = reselectCreateSelector(...reselectArgs);
|
|
126
|
+
fn.selectorArgs = selectorArgs;
|
|
127
|
+
cache.set(cacheKey, fn);
|
|
128
|
+
}
|
|
129
|
+
fn.selectorArgs[0] = a1;
|
|
130
|
+
fn.selectorArgs[1] = a2;
|
|
131
|
+
fn.selectorArgs[2] = a3;
|
|
132
|
+
|
|
133
|
+
// prettier-ignore
|
|
134
|
+
switch (argsLength) {
|
|
135
|
+
case 0:
|
|
136
|
+
return fn(state);
|
|
137
|
+
case 1:
|
|
138
|
+
return fn(state, a1);
|
|
139
|
+
case 2:
|
|
140
|
+
return fn(state, a1, a2);
|
|
141
|
+
case 3:
|
|
142
|
+
return fn(state, a1, a2, a3);
|
|
143
|
+
default:
|
|
144
|
+
throw /* minify-error-disabled */new Error('unreachable');
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
return selector;
|
|
148
|
+
};
|