@lucasols/dnd-kit-utilities 0.1.1

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.
Files changed (44) hide show
  1. package/CHANGELOG.md +142 -0
  2. package/LICENSE +21 -0
  3. package/README.md +5 -0
  4. package/dist/adjustment.d.ts +2 -0
  5. package/dist/coordinates/getEventCoordinates.d.ts +5 -0
  6. package/dist/coordinates/index.d.ts +2 -0
  7. package/dist/coordinates/types.d.ts +4 -0
  8. package/dist/css.d.ts +25 -0
  9. package/dist/dnd-kit-utilities.cjs.development.js +361 -0
  10. package/dist/dnd-kit-utilities.cjs.development.js.map +1 -0
  11. package/dist/dnd-kit-utilities.cjs.production.min.js +2 -0
  12. package/dist/dnd-kit-utilities.cjs.production.min.js.map +1 -0
  13. package/dist/dnd-kit-utilities.esm.js +333 -0
  14. package/dist/dnd-kit-utilities.esm.js.map +1 -0
  15. package/dist/event/hasViewportRelativeCoordinates.d.ts +1 -0
  16. package/dist/event/index.d.ts +3 -0
  17. package/dist/event/isKeyboardEvent.d.ts +1 -0
  18. package/dist/event/isTouchEvent.d.ts +1 -0
  19. package/dist/execution-context/canUseDOM.d.ts +1 -0
  20. package/dist/execution-context/getOwnerDocument.d.ts +1 -0
  21. package/dist/execution-context/getWindow.d.ts +1 -0
  22. package/dist/execution-context/index.d.ts +3 -0
  23. package/dist/focus/findFirstFocusableNode.d.ts +1 -0
  24. package/dist/focus/index.d.ts +1 -0
  25. package/dist/hooks/index.d.ts +9 -0
  26. package/dist/hooks/useCombinedRefs.d.ts +1 -0
  27. package/dist/hooks/useEvent.d.ts +1 -0
  28. package/dist/hooks/useInterval.d.ts +1 -0
  29. package/dist/hooks/useIsomorphicLayoutEffect.d.ts +6 -0
  30. package/dist/hooks/useLatestValue.d.ts +2 -0
  31. package/dist/hooks/useLazyMemo.d.ts +1 -0
  32. package/dist/hooks/useNodeRef.d.ts +2 -0
  33. package/dist/hooks/usePrevious.d.ts +1 -0
  34. package/dist/hooks/useUniqueId.d.ts +1 -0
  35. package/dist/index.d.ts +11 -0
  36. package/dist/index.js +8 -0
  37. package/dist/type-guards/index.d.ts +5 -0
  38. package/dist/type-guards/isDocument.d.ts +1 -0
  39. package/dist/type-guards/isHTMLElement.d.ts +1 -0
  40. package/dist/type-guards/isNode.d.ts +1 -0
  41. package/dist/type-guards/isSVGElement.d.ts +1 -0
  42. package/dist/type-guards/isWindow.d.ts +1 -0
  43. package/dist/types.d.ts +6 -0
  44. package/package.json +38 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,142 @@
1
+ # @dnd-kit/utilities
2
+
3
+ ## 3.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - [#948](https://github.com/clauderic/dnd-kit/pull/948) [`da7c60d`](https://github.com/clauderic/dnd-kit/commit/da7c60dcbb76d89cf1fcb421e69a4abcea2eeebe) Thanks [@Ayc0](https://github.com/Ayc0)! - Upgrade to TypeScript to 4.8
8
+
9
+ ## 3.2.0
10
+
11
+ ### Minor Changes
12
+
13
+ - [#748](https://github.com/clauderic/dnd-kit/pull/748) [`59ca82b`](https://github.com/clauderic/dnd-kit/commit/59ca82b9f228f34c7731ece87aef5d9633608b57) Thanks [@clauderic](https://github.com/clauderic)! - Introduced the `findFirstFocusableNode` utility function that returns the first focusable node within a given HTMLElement, or the element itself if it is focusable.
14
+
15
+ - [#733](https://github.com/clauderic/dnd-kit/pull/733) [`035021a`](https://github.com/clauderic/dnd-kit/commit/035021aac51161e2bf9715f087a6dd1b46647bfc) Thanks [@clauderic](https://github.com/clauderic)! - Introduced the `useEvent` hook based on [implementation breakdown in the RFC](https://github.com/reactjs/rfcs/blob/useevent/text/0000-useevent.md#internal-implementation). In the future, this hook will be used as a polyfill if the native React hook is unavailble.
16
+
17
+ ## 3.1.0
18
+
19
+ ### Minor Changes
20
+
21
+ - [#518](https://github.com/clauderic/dnd-kit/pull/518) [`6310227`](https://github.com/clauderic/dnd-kit/commit/63102272d0d63dae349e2e9f638277e16a7d5970) Thanks [@clauderic](https://github.com/clauderic)! - Major internal refactor of measuring and collision detection.
22
+
23
+ ### Summary of changes
24
+
25
+ Previously, all collision detection algorithms were relative to the top and left points of the document. While this approach worked in most situations, it broke down in a number of different use-cases, such as fixed position droppable containers and trying to drag between containers that had different scroll positions.
26
+
27
+ This new approach changes the frame of comparison to be relative to the viewport. This is a major breaking change, and will need to be released under a new major version bump.
28
+
29
+ ### Breaking changes:
30
+
31
+ - By default, `@dnd-kit` now ignores only the transforms applied to the draggable / droppable node itself, but considers all the transforms applied to its ancestors. This should provide the right balance of flexibility for most consumers.
32
+ - Transforms applied to the droppable and draggable nodes are ignored by default, because the recommended approach for moving items on the screen is to use the transform property, which can interfere with the calculation of collisions.
33
+ - Consumers can choose an alternate approach that does consider transforms for specific use-cases if needed by configuring the measuring prop of <DndContext>. Refer to the <Switch> example.
34
+ - Reduced the number of concepts related to measuring from `ViewRect`, `LayoutRect` to just a single concept of `ClientRect`.
35
+ - The `ClientRect` interface no longer holds the `offsetTop` and `offsetLeft` properties. For most use-cases, you can replace `offsetTop` with `top` and `offsetLeft` with `left`.
36
+ - Replaced the following exports from the `@dnd-kit/core` package with `getClientRect`:
37
+ - `getBoundingClientRect`
38
+ - `getViewRect`
39
+ - `getLayoutRect`
40
+ - `getViewportLayoutRect`
41
+ - Removed `translatedRect` from the `SensorContext` interface. Replace usage with `collisionRect`.
42
+ - Removed `activeNodeClientRect` on the `DndContext` interface. Replace with `activeNodeRect`.
43
+
44
+ - [`528c67e`](https://github.com/clauderic/dnd-kit/commit/528c67e4c617dfc0ce5221496aa8b222ffc82ddb) Thanks [@clauderic](https://github.com/clauderic)! - Introduced the `useLatestValue` hook, which returns a ref that holds the latest value of a given argument. Optionally, the second argument can be used to customize the dependencies passed to the effect.
45
+
46
+ ### Patch Changes
47
+
48
+ - [#561](https://github.com/clauderic/dnd-kit/pull/561) [`02edd26`](https://github.com/clauderic/dnd-kit/commit/02edd2691b24bb49f2e7c9f9a3f282031bf658b7) Thanks [@clauderic](https://github.com/clauderic)! - - The `useNodeRef` hook's `onChange` argument now receives both the current node and the previous node that were attached to the ref.
49
+ - The `onChange` argument is only called if the previous node differs from the current node
50
+
51
+ ## 3.0.2
52
+
53
+ ### Patch Changes
54
+
55
+ - [#532](https://github.com/clauderic/dnd-kit/pull/532) [`dfa8d69`](https://github.com/clauderic/dnd-kit/commit/dfa8d69d98e8f271b29fa516cc13b8cd0c01d371) Thanks [@Nauss](https://github.com/Nauss)! - fix: `isWindow` has been updated to support checking wether an element is a window object in Electron applications.
56
+
57
+ ## 3.0.1
58
+
59
+ ### Patch Changes
60
+
61
+ - [#509](https://github.com/clauderic/dnd-kit/pull/509) [`1c6369e`](https://github.com/clauderic/dnd-kit/commit/1c6369e24ff338760adfb806c3017c72f3194726) Thanks [@clauderic](https://github.com/clauderic)! - Helpers have been updated to support rendering in foreign `window` contexts (via `ReactDOM.render` or `ReactDOM.createPortal`).
62
+
63
+ For example, checking if an element is an instance of an `HTMLElement` is normally done like so:
64
+
65
+ ```ts
66
+ if (element instanceof HTMLElement)
67
+ ```
68
+
69
+ However, when rendering in a different window, this can return false even if the element is indeed an HTMLElement, because this code is equivalent to:
70
+
71
+ ```ts
72
+ if (element instanceof window.HTMLElement)
73
+ ```
74
+
75
+ And in this case, the `window` of the `element` is different from the main execution context `window`, because we are rendering via a portal into another window.
76
+
77
+ This can be solved by finding the local window of the element:
78
+
79
+ ```ts
80
+ const elementWindow = element.ownerDocument.defaultView;
81
+
82
+ if (element instanceof elementWindow.HTMLElement)
83
+ ```
84
+
85
+ ## 3.0.0
86
+
87
+ ### Major Changes
88
+
89
+ - [#373](https://github.com/clauderic/dnd-kit/pull/373) [`1f5ca27`](https://github.com/clauderic/dnd-kit/commit/1f5ca27b17879861c2c545160c2046a747544846) Thanks [@clauderic](https://github.com/clauderic)! - Added react to peerDependencies of @dnd-kit/utilities
90
+
91
+ ### Minor Changes
92
+
93
+ - [#334](https://github.com/clauderic/dnd-kit/pull/334) [`13be602`](https://github.com/clauderic/dnd-kit/commit/13be602229c6d5723b3ae98bca7b8f45f0773366) Thanks [@trentmwillis](https://github.com/trentmwillis)! - Move `Coordinates` interface along with `getEventCoordinates`, `isMouseEvent` and `isTouchEvent` helpers to @dnd-kit/utilities
94
+
95
+ ### Patch Changes
96
+
97
+ - [#437](https://github.com/clauderic/dnd-kit/pull/437) [`0e628bc`](https://github.com/clauderic/dnd-kit/commit/0e628bce53fb1a7223cdedd203cb07b6e62e5ec1) Thanks [@chestozo](https://github.com/chestozo)! - Added PointerEvent support to the `getEventCoordinates` method. This fixes testing the PointerSensor with Cypress (#436)
98
+
99
+ ## 2.0.0
100
+
101
+ ### Major Changes
102
+
103
+ - [`a9d92cf`](https://github.com/clauderic/dnd-kit/commit/a9d92cf1fa35dd957e6c5915a13dfd2af134c103) [#174](https://github.com/clauderic/dnd-kit/pull/174) Thanks [@clauderic](https://github.com/clauderic)! - Distributed assets now only target modern browsers. [Browserlist](https://github.com/browserslist/browserslist) config:
104
+
105
+ ```
106
+ defaults
107
+ last 2 version
108
+ not IE 11
109
+ not dead
110
+ ```
111
+
112
+ If you need to support older browsers, include the appropriate polyfills in your project's build process.
113
+
114
+ ## 1.0.3
115
+
116
+ ### Patch Changes
117
+
118
+ - [`6a5c8a1`](https://github.com/clauderic/dnd-kit/commit/6a5c8a13bf19742efa65b20f16666f00ffaae1b1) [#154](https://github.com/clauderic/dnd-kit/pull/154) Thanks [@clauderic](https://github.com/clauderic)! - Update implementation of FirstArgument
119
+
120
+ ## 1.0.2
121
+
122
+ ### Patch Changes
123
+
124
+ - [`423610c`](https://github.com/clauderic/dnd-kit/commit/423610ca48c5e5ca95545fdb5c5cfcfbd3d233ba) [#56](https://github.com/clauderic/dnd-kit/pull/56) Thanks [@clauderic](https://github.com/clauderic)! - Add MIT license to package.json and distributed files
125
+
126
+ ## 1.0.1
127
+
128
+ ### Patch Changes
129
+
130
+ - [`0b343c7`](https://github.com/clauderic/dnd-kit/commit/0b343c7e88a68351f8a39f643e9f26b8e046ef48) [#52](https://github.com/clauderic/dnd-kit/pull/52) Thanks [@clauderic](https://github.com/clauderic)! - Add repository entry to package.json files
131
+
132
+ ## 1.0.0
133
+
134
+ ### Major Changes
135
+
136
+ - [`2912350`](https://github.com/clauderic/dnd-kit/commit/2912350c5008c2b0edda3bae30b5075a852dea63) Thanks [@clauderic](https://github.com/clauderic)! - Initial public release.
137
+
138
+ ## 0.1.0
139
+
140
+ ### Minor Changes
141
+
142
+ - [`7bd4568`](https://github.com/clauderic/dnd-kit/commit/7bd4568e9f339552fd73a9a4c888460b11195a5e) [#30](https://github.com/clauderic/dnd-kit/pull/30) - Initial beta release, authored by [@clauderic](https://github.com/clauderic).
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021, Claudéric Demers
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,5 @@
1
+ # @dnd-kit/utilities
2
+
3
+ [![Stable release](https://img.shields.io/npm/v/@dnd-kit/utilities.svg)](https://npm.im/@dnd-kit/sortable)
4
+
5
+ Internal utilities to bee shared between `@dnd-kit` packages.
@@ -0,0 +1,2 @@
1
+ export declare const add: <T extends Record<U, number>, U extends string>(object: T, ...adjustments: Partial<T>[]) => T;
2
+ export declare const subtract: <T extends Record<U, number>, U extends string>(object: T, ...adjustments: Partial<T>[]) => T;
@@ -0,0 +1,5 @@
1
+ import type { Coordinates } from './types';
2
+ /**
3
+ * Returns the normalized x and y coordinates for mouse and touch events.
4
+ */
5
+ export declare function getEventCoordinates(event: Event): Coordinates | null;
@@ -0,0 +1,2 @@
1
+ export type { Coordinates } from './types';
2
+ export { getEventCoordinates } from './getEventCoordinates';
@@ -0,0 +1,4 @@
1
+ export declare type Coordinates = {
2
+ x: number;
3
+ y: number;
4
+ };
package/dist/css.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ export declare type Transform = {
2
+ x: number;
3
+ y: number;
4
+ scaleX: number;
5
+ scaleY: number;
6
+ };
7
+ export interface Transition {
8
+ property: string;
9
+ easing: string;
10
+ duration: number;
11
+ }
12
+ export declare const CSS: Readonly<{
13
+ Translate: {
14
+ toString(transform: Transform | null): string | undefined;
15
+ };
16
+ Scale: {
17
+ toString(transform: Transform | null): string | undefined;
18
+ };
19
+ Transform: {
20
+ toString(transform: Transform | null): string | undefined;
21
+ };
22
+ Transition: {
23
+ toString({ property, duration, easing }: Transition): string;
24
+ };
25
+ }>;
@@ -0,0 +1,361 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+
7
+ function useCombinedRefs() {
8
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
9
+ refs[_key] = arguments[_key];
10
+ }
11
+
12
+ return react.useMemo(() => node => {
13
+ refs.forEach(ref => ref(node));
14
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
15
+ refs);
16
+ }
17
+
18
+ // https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
19
+ const canUseDOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
20
+
21
+ function isWindow(element) {
22
+ const elementString = Object.prototype.toString.call(element);
23
+ return elementString === '[object Window]' || // In Electron context the Window object serializes to [object global]
24
+ elementString === '[object global]';
25
+ }
26
+
27
+ function isNode(node) {
28
+ return 'nodeType' in node;
29
+ }
30
+
31
+ function getWindow(target) {
32
+ var _target$ownerDocument, _target$ownerDocument2;
33
+
34
+ if (!target) {
35
+ return window;
36
+ }
37
+
38
+ if (isWindow(target)) {
39
+ return target;
40
+ }
41
+
42
+ if (!isNode(target)) {
43
+ return window;
44
+ }
45
+
46
+ return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
47
+ }
48
+
49
+ function isDocument(node) {
50
+ const {
51
+ Document
52
+ } = getWindow(node);
53
+ return node instanceof Document;
54
+ }
55
+
56
+ function isHTMLElement(node) {
57
+ if (isWindow(node)) {
58
+ return false;
59
+ }
60
+
61
+ return node instanceof getWindow(node).HTMLElement;
62
+ }
63
+
64
+ function isSVGElement(node) {
65
+ return node instanceof getWindow(node).SVGElement;
66
+ }
67
+
68
+ function getOwnerDocument(target) {
69
+ if (!target) {
70
+ return document;
71
+ }
72
+
73
+ if (isWindow(target)) {
74
+ return target.document;
75
+ }
76
+
77
+ if (!isNode(target)) {
78
+ return document;
79
+ }
80
+
81
+ if (isDocument(target)) {
82
+ return target;
83
+ }
84
+
85
+ if (isHTMLElement(target) || isSVGElement(target)) {
86
+ return target.ownerDocument;
87
+ }
88
+
89
+ return document;
90
+ }
91
+
92
+ /**
93
+ * A hook that resolves to useEffect on the server and useLayoutEffect on the client
94
+ * @param callback {function} Callback function that is invoked when the dependencies of the hook change
95
+ */
96
+
97
+ const useIsomorphicLayoutEffect = canUseDOM ? react.useLayoutEffect : react.useEffect;
98
+
99
+ function useEvent(handler) {
100
+ const handlerRef = react.useRef(handler);
101
+ useIsomorphicLayoutEffect(() => {
102
+ handlerRef.current = handler;
103
+ });
104
+ return react.useCallback(function () {
105
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
106
+ args[_key] = arguments[_key];
107
+ }
108
+
109
+ return handlerRef.current == null ? void 0 : handlerRef.current(...args);
110
+ }, []);
111
+ }
112
+
113
+ function useInterval() {
114
+ const intervalRef = react.useRef(null);
115
+ const set = react.useCallback((listener, duration) => {
116
+ intervalRef.current = setInterval(listener, duration);
117
+ }, []);
118
+ const clear = react.useCallback(() => {
119
+ if (intervalRef.current !== null) {
120
+ clearInterval(intervalRef.current);
121
+ intervalRef.current = null;
122
+ }
123
+ }, []);
124
+ return [set, clear];
125
+ }
126
+
127
+ function useLatestValue(value, dependencies) {
128
+ if (dependencies === void 0) {
129
+ dependencies = [value];
130
+ }
131
+
132
+ const valueRef = react.useRef(value);
133
+ useIsomorphicLayoutEffect(() => {
134
+ if (valueRef.current !== value) {
135
+ valueRef.current = value;
136
+ }
137
+ }, dependencies);
138
+ return valueRef;
139
+ }
140
+
141
+ function useLazyMemo(callback, dependencies) {
142
+ const valueRef = react.useRef();
143
+ return react.useMemo(() => {
144
+ const newValue = callback(valueRef.current);
145
+ valueRef.current = newValue;
146
+ return newValue;
147
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
148
+ [...dependencies]);
149
+ }
150
+
151
+ function useNodeRef(onChange) {
152
+ const onChangeHandler = useEvent(onChange);
153
+ const node = react.useRef(null);
154
+ const setNodeRef = react.useCallback(element => {
155
+ if (element !== node.current) {
156
+ onChangeHandler == null ? void 0 : onChangeHandler(element, node.current);
157
+ }
158
+
159
+ node.current = element;
160
+ }, //eslint-disable-next-line
161
+ []);
162
+ return [node, setNodeRef];
163
+ }
164
+
165
+ function usePrevious(value) {
166
+ const ref = react.useRef();
167
+ react.useEffect(() => {
168
+ ref.current = value;
169
+ }, [value]);
170
+ return ref.current;
171
+ }
172
+
173
+ let ids = {};
174
+ function useUniqueId(prefix, value) {
175
+ return react.useMemo(() => {
176
+ if (value) {
177
+ return value;
178
+ }
179
+
180
+ const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
181
+ ids[prefix] = id;
182
+ return prefix + "-" + id;
183
+ }, [prefix, value]);
184
+ }
185
+
186
+ function createAdjustmentFn(modifier) {
187
+ return function (object) {
188
+ for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
189
+ adjustments[_key - 1] = arguments[_key];
190
+ }
191
+
192
+ return adjustments.reduce((accumulator, adjustment) => {
193
+ const entries = Object.entries(adjustment);
194
+
195
+ for (const [key, valueAdjustment] of entries) {
196
+ const value = accumulator[key];
197
+
198
+ if (value != null) {
199
+ accumulator[key] = value + modifier * valueAdjustment;
200
+ }
201
+ }
202
+
203
+ return accumulator;
204
+ }, { ...object
205
+ });
206
+ };
207
+ }
208
+
209
+ const add = /*#__PURE__*/createAdjustmentFn(1);
210
+ const subtract = /*#__PURE__*/createAdjustmentFn(-1);
211
+
212
+ function hasViewportRelativeCoordinates(event) {
213
+ return 'clientX' in event && 'clientY' in event;
214
+ }
215
+
216
+ function isKeyboardEvent(event) {
217
+ if (!event) {
218
+ return false;
219
+ }
220
+
221
+ const {
222
+ KeyboardEvent
223
+ } = getWindow(event.target);
224
+ return KeyboardEvent && event instanceof KeyboardEvent;
225
+ }
226
+
227
+ function isTouchEvent(event) {
228
+ if (!event) {
229
+ return false;
230
+ }
231
+
232
+ const {
233
+ TouchEvent
234
+ } = getWindow(event.target);
235
+ return TouchEvent && event instanceof TouchEvent;
236
+ }
237
+
238
+ /**
239
+ * Returns the normalized x and y coordinates for mouse and touch events.
240
+ */
241
+
242
+ function getEventCoordinates(event) {
243
+ if (isTouchEvent(event)) {
244
+ if (event.touches && event.touches.length) {
245
+ const {
246
+ clientX: x,
247
+ clientY: y
248
+ } = event.touches[0];
249
+ return {
250
+ x,
251
+ y
252
+ };
253
+ } else if (event.changedTouches && event.changedTouches.length) {
254
+ const {
255
+ clientX: x,
256
+ clientY: y
257
+ } = event.changedTouches[0];
258
+ return {
259
+ x,
260
+ y
261
+ };
262
+ }
263
+ }
264
+
265
+ if (hasViewportRelativeCoordinates(event)) {
266
+ return {
267
+ x: event.clientX,
268
+ y: event.clientY
269
+ };
270
+ }
271
+
272
+ return null;
273
+ }
274
+
275
+ const CSS = /*#__PURE__*/Object.freeze({
276
+ Translate: {
277
+ toString(transform) {
278
+ if (!transform) {
279
+ return;
280
+ }
281
+
282
+ const {
283
+ x,
284
+ y
285
+ } = transform;
286
+ return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
287
+ }
288
+
289
+ },
290
+ Scale: {
291
+ toString(transform) {
292
+ if (!transform) {
293
+ return;
294
+ }
295
+
296
+ const {
297
+ scaleX,
298
+ scaleY
299
+ } = transform;
300
+ return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
301
+ }
302
+
303
+ },
304
+ Transform: {
305
+ toString(transform) {
306
+ if (!transform) {
307
+ return;
308
+ }
309
+
310
+ return [CSS.Translate.toString(transform), CSS.Scale.toString(transform)].join(' ');
311
+ }
312
+
313
+ },
314
+ Transition: {
315
+ toString(_ref) {
316
+ let {
317
+ property,
318
+ duration,
319
+ easing
320
+ } = _ref;
321
+ return property + " " + duration + "ms " + easing;
322
+ }
323
+
324
+ }
325
+ });
326
+
327
+ const SELECTOR = 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';
328
+ function findFirstFocusableNode(element) {
329
+ if (element.matches(SELECTOR)) {
330
+ return element;
331
+ }
332
+
333
+ return element.querySelector(SELECTOR);
334
+ }
335
+
336
+ exports.CSS = CSS;
337
+ exports.add = add;
338
+ exports.canUseDOM = canUseDOM;
339
+ exports.findFirstFocusableNode = findFirstFocusableNode;
340
+ exports.getEventCoordinates = getEventCoordinates;
341
+ exports.getOwnerDocument = getOwnerDocument;
342
+ exports.getWindow = getWindow;
343
+ exports.hasViewportRelativeCoordinates = hasViewportRelativeCoordinates;
344
+ exports.isDocument = isDocument;
345
+ exports.isHTMLElement = isHTMLElement;
346
+ exports.isKeyboardEvent = isKeyboardEvent;
347
+ exports.isNode = isNode;
348
+ exports.isSVGElement = isSVGElement;
349
+ exports.isTouchEvent = isTouchEvent;
350
+ exports.isWindow = isWindow;
351
+ exports.subtract = subtract;
352
+ exports.useCombinedRefs = useCombinedRefs;
353
+ exports.useEvent = useEvent;
354
+ exports.useInterval = useInterval;
355
+ exports.useIsomorphicLayoutEffect = useIsomorphicLayoutEffect;
356
+ exports.useLatestValue = useLatestValue;
357
+ exports.useLazyMemo = useLazyMemo;
358
+ exports.useNodeRef = useNodeRef;
359
+ exports.usePrevious = usePrevious;
360
+ exports.useUniqueId = useUniqueId;
361
+ //# sourceMappingURL=dnd-kit-utilities.cjs.development.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dnd-kit-utilities.cjs.development.js","sources":["../src/hooks/useCombinedRefs.ts","../src/execution-context/canUseDOM.ts","../src/type-guards/isWindow.ts","../src/type-guards/isNode.ts","../src/execution-context/getWindow.ts","../src/type-guards/isDocument.ts","../src/type-guards/isHTMLElement.ts","../src/type-guards/isSVGElement.ts","../src/execution-context/getOwnerDocument.ts","../src/hooks/useIsomorphicLayoutEffect.ts","../src/hooks/useEvent.ts","../src/hooks/useInterval.ts","../src/hooks/useLatestValue.ts","../src/hooks/useLazyMemo.ts","../src/hooks/useNodeRef.ts","../src/hooks/usePrevious.ts","../src/hooks/useUniqueId.ts","../src/adjustment.ts","../src/event/hasViewportRelativeCoordinates.ts","../src/event/isKeyboardEvent.ts","../src/event/isTouchEvent.ts","../src/coordinates/getEventCoordinates.ts","../src/css.ts","../src/focus/findFirstFocusableNode.ts"],"sourcesContent":["import {useMemo} from 'react';\n\nexport function useCombinedRefs<T>(\n ...refs: ((node: T) => void)[]\n): (node: T) => void {\n return useMemo(\n () => (node: T) => {\n refs.forEach((ref) => ref(node));\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n refs\n );\n}\n","// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js\nexport const canUseDOM =\n typeof window !== 'undefined' &&\n typeof window.document !== 'undefined' &&\n typeof window.document.createElement !== 'undefined';\n","export function isWindow(element: Object): element is typeof window {\n const elementString = Object.prototype.toString.call(element);\n return (\n elementString === '[object Window]' ||\n // In Electron context the Window object serializes to [object global]\n elementString === '[object global]'\n );\n}\n","export function isNode(node: Object): node is Node {\n return 'nodeType' in node;\n}\n","import {isWindow} from '../type-guards/isWindow';\nimport {isNode} from '../type-guards/isNode';\n\nexport function getWindow(target: Event['target']): typeof window {\n if (!target) {\n return window;\n }\n\n if (isWindow(target)) {\n return target;\n }\n\n if (!isNode(target)) {\n return window;\n }\n\n return target.ownerDocument?.defaultView ?? window;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isDocument(node: Node): node is Document {\n const {Document} = getWindow(node);\n\n return node instanceof Document;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nimport {isWindow} from './isWindow';\n\nexport function isHTMLElement(node: Node | Window): node is HTMLElement {\n if (isWindow(node)) {\n return false;\n }\n\n return node instanceof getWindow(node).HTMLElement;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isSVGElement(node: Node): node is SVGElement {\n return node instanceof getWindow(node).SVGElement;\n}\n","import {\n isWindow,\n isHTMLElement,\n isDocument,\n isNode,\n isSVGElement,\n} from '../type-guards';\n\nexport function getOwnerDocument(target: Event['target']): Document {\n if (!target) {\n return document;\n }\n\n if (isWindow(target)) {\n return target.document;\n }\n\n if (!isNode(target)) {\n return document;\n }\n\n if (isDocument(target)) {\n return target;\n }\n\n if (isHTMLElement(target) || isSVGElement(target)) {\n return target.ownerDocument;\n }\n\n return document;\n}\n","import {useEffect, useLayoutEffect} from 'react';\n\nimport {canUseDOM} from '../execution-context';\n\n/**\n * A hook that resolves to useEffect on the server and useLayoutEffect on the client\n * @param callback {function} Callback function that is invoked when the dependencies of the hook change\n */\nexport const useIsomorphicLayoutEffect = canUseDOM\n ? useLayoutEffect\n : useEffect;\n","import {useCallback, useRef} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useEvent<T extends Function>(handler: T | undefined) {\n const handlerRef = useRef<T | undefined>(handler);\n\n useIsomorphicLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback(function (...args: any) {\n return handlerRef.current?.(...args);\n }, []);\n}\n","import {useCallback, useRef} from 'react';\n\nexport function useInterval() {\n const intervalRef = useRef<number | null>(null);\n\n const set = useCallback((listener: Function, duration: number) => {\n intervalRef.current = setInterval(listener, duration);\n }, []);\n\n const clear = useCallback(() => {\n if (intervalRef.current !== null) {\n clearInterval(intervalRef.current);\n intervalRef.current = null;\n }\n }, []);\n\n return [set, clear] as const;\n}\n","import {useRef} from 'react';\nimport type {DependencyList} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useLatestValue<T extends any>(\n value: T,\n dependencies: DependencyList = [value]\n) {\n const valueRef = useRef<T>(value);\n\n useIsomorphicLayoutEffect(() => {\n if (valueRef.current !== value) {\n valueRef.current = value;\n }\n }, dependencies);\n\n return valueRef;\n}\n","import {useMemo, useRef} from 'react';\n\nexport function useLazyMemo<T>(\n callback: (prevValue: T | undefined) => T,\n dependencies: any[]\n) {\n const valueRef = useRef<T>();\n\n return useMemo(\n () => {\n const newValue = callback(valueRef.current);\n valueRef.current = newValue;\n\n return newValue;\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...dependencies]\n );\n}\n","import {useRef, useCallback} from 'react';\n\nimport {useEvent} from './useEvent';\n\nexport function useNodeRef(\n onChange?: (\n newElement: HTMLElement | null,\n previousElement: HTMLElement | null\n ) => void\n) {\n const onChangeHandler = useEvent(onChange);\n const node = useRef<HTMLElement | null>(null);\n const setNodeRef = useCallback(\n (element: HTMLElement | null) => {\n if (element !== node.current) {\n onChangeHandler?.(element, node.current);\n }\n\n node.current = element;\n },\n //eslint-disable-next-line\n []\n );\n\n return [node, setNodeRef] as const;\n}\n","import {useRef, useEffect} from 'react';\n\nexport function usePrevious<T>(value: T) {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n","import {useMemo} from 'react';\n\nlet ids: Record<string, number> = {};\n\nexport function useUniqueId(prefix: string, value?: string) {\n return useMemo(() => {\n if (value) {\n return value;\n }\n\n const id = ids[prefix] == null ? 0 : ids[prefix] + 1;\n ids[prefix] = id;\n\n return `${prefix}-${id}`;\n }, [prefix, value]);\n}\n","function createAdjustmentFn(modifier: number) {\n return <T extends Record<U, number>, U extends string>(\n object: T,\n ...adjustments: Partial<T>[]\n ): T => {\n return adjustments.reduce<T>(\n (accumulator, adjustment) => {\n const entries = Object.entries(adjustment) as [U, number][];\n\n for (const [key, valueAdjustment] of entries) {\n const value = accumulator[key];\n\n if (value != null) {\n accumulator[key] = (value + modifier * valueAdjustment) as T[U];\n }\n }\n\n return accumulator;\n },\n {\n ...object,\n }\n );\n };\n}\n\nexport const add = createAdjustmentFn(1);\nexport const subtract = createAdjustmentFn(-1);\n","export function hasViewportRelativeCoordinates(\n event: Event\n): event is Event & Pick<PointerEvent, 'clientX' | 'clientY'> {\n return 'clientX' in event && 'clientY' in event;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isKeyboardEvent(\n event: Event | undefined | null\n): event is KeyboardEvent {\n if (!event) {\n return false;\n }\n\n const {KeyboardEvent} = getWindow(event.target);\n\n return KeyboardEvent && event instanceof KeyboardEvent;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isTouchEvent(\n event: Event | undefined | null\n): event is TouchEvent {\n if (!event) {\n return false;\n }\n\n const {TouchEvent} = getWindow(event.target);\n\n return TouchEvent && event instanceof TouchEvent;\n}\n","import type {Coordinates} from './types';\nimport {isTouchEvent, hasViewportRelativeCoordinates} from '../event';\n\n/**\n * Returns the normalized x and y coordinates for mouse and touch events.\n */\nexport function getEventCoordinates(event: Event): Coordinates | null {\n if (isTouchEvent(event)) {\n if (event.touches && event.touches.length) {\n const {clientX: x, clientY: y} = event.touches[0];\n\n return {\n x,\n y,\n };\n } else if (event.changedTouches && event.changedTouches.length) {\n const {clientX: x, clientY: y} = event.changedTouches[0];\n\n return {\n x,\n y,\n };\n }\n }\n\n if (hasViewportRelativeCoordinates(event)) {\n return {\n x: event.clientX,\n y: event.clientY,\n };\n }\n\n return null;\n}\n","export type Transform = {\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n};\n\nexport interface Transition {\n property: string;\n easing: string;\n duration: number;\n}\n\nexport const CSS = Object.freeze({\n Translate: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {x, y} = transform;\n\n return `translate3d(${x ? Math.round(x) : 0}px, ${\n y ? Math.round(y) : 0\n }px, 0)`;\n },\n },\n Scale: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {scaleX, scaleY} = transform;\n\n return `scaleX(${scaleX}) scaleY(${scaleY})`;\n },\n },\n Transform: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n return [\n CSS.Translate.toString(transform),\n CSS.Scale.toString(transform),\n ].join(' ');\n },\n },\n Transition: {\n toString({property, duration, easing}: Transition) {\n return `${property} ${duration}ms ${easing}`;\n },\n },\n});\n","const SELECTOR =\n 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';\n\nexport function findFirstFocusableNode(\n element: HTMLElement\n): HTMLElement | null {\n if (element.matches(SELECTOR)) {\n return element;\n }\n\n return element.querySelector(SELECTOR);\n}\n"],"names":["useCombinedRefs","refs","useMemo","node","forEach","ref","canUseDOM","window","document","createElement","isWindow","element","elementString","Object","prototype","toString","call","isNode","getWindow","target","ownerDocument","defaultView","isDocument","Document","isHTMLElement","HTMLElement","isSVGElement","SVGElement","getOwnerDocument","useIsomorphicLayoutEffect","useLayoutEffect","useEffect","useEvent","handler","handlerRef","useRef","current","useCallback","args","useInterval","intervalRef","set","listener","duration","setInterval","clear","clearInterval","useLatestValue","value","dependencies","valueRef","useLazyMemo","callback","newValue","useNodeRef","onChange","onChangeHandler","setNodeRef","usePrevious","ids","useUniqueId","prefix","id","createAdjustmentFn","modifier","object","adjustments","reduce","accumulator","adjustment","entries","key","valueAdjustment","add","subtract","hasViewportRelativeCoordinates","event","isKeyboardEvent","KeyboardEvent","isTouchEvent","TouchEvent","getEventCoordinates","touches","length","clientX","x","clientY","y","changedTouches","CSS","freeze","Translate","transform","Math","round","Scale","scaleX","scaleY","Transform","join","Transition","property","easing","SELECTOR","findFirstFocusableNode","matches","querySelector"],"mappings":";;;;;;SAEgBA;oCACXC;IAAAA;;;EAEH,OAAOC,aAAO,CACZ,MAAOC,IAAD;IACJF,IAAI,CAACG,OAAL,CAAcC,GAAD,IAASA,GAAG,CAACF,IAAD,CAAzB;GAFU;EAKZF,IALY,CAAd;AAOD;;ACZD;AACA,MAAaK,SAAS,GACpB,OAAOC,MAAP,KAAkB,WAAlB,IACA,OAAOA,MAAM,CAACC,QAAd,KAA2B,WAD3B,IAEA,OAAOD,MAAM,CAACC,QAAP,CAAgBC,aAAvB,KAAyC,WAHpC;;SCDSC,SAASC;EACvB,MAAMC,aAAa,GAAGC,MAAM,CAACC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BL,OAA/B,CAAtB;EACA,OACEC,aAAa,KAAK,iBAAlB;EAEAA,aAAa,KAAK,iBAHpB;AAKD;;SCPeK,OAAOd;EACrB,OAAO,cAAcA,IAArB;AACD;;SCCee,UAAUC;;;EACxB,IAAI,CAACA,MAAL,EAAa;IACX,OAAOZ,MAAP;;;EAGF,IAAIG,QAAQ,CAACS,MAAD,CAAZ,EAAsB;IACpB,OAAOA,MAAP;;;EAG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7F;EAEA,IAAIA,OAAO,CAAC8F,OAAR,CAAgBF,QAAhB,CAAJ,EAA+B;IAC7B,OAAO5F,OAAP;;;EAGF,OAAOA,OAAO,CAAC+F,aAAR,CAAsBH,QAAtB,CAAP;AACD;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react");const t="undefined"!=typeof window&&void 0!==window.document&&void 0!==window.document.createElement;function n(e){const t=Object.prototype.toString.call(e);return"[object Window]"===t||"[object global]"===t}function r(e){return"nodeType"in e}function o(e){var t,o;return e?n(e)?e:r(e)&&null!=(t=null==(o=e.ownerDocument)?void 0:o.defaultView)?t:window:window}function u(e){const{Document:t}=o(e);return e instanceof t}function c(e){return!n(e)&&e instanceof o(e).HTMLElement}function s(e){return e instanceof o(e).SVGElement}const i=t?e.useLayoutEffect:e.useEffect;function a(t){const n=e.useRef(t);return i(()=>{n.current=t}),e.useCallback((function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return null==n.current?void 0:n.current(...t)}),[])}let l={};function f(e){return function(t){for(var n=arguments.length,r=new Array(n>1?n-1:0),o=1;o<n;o++)r[o-1]=arguments[o];return r.reduce((t,n)=>{const r=Object.entries(n);for(const[n,o]of r){const r=t[n];null!=r&&(t[n]=r+e*o)}return t},{...t})}}const d=f(1),p=f(-1);function x(e){return"clientX"in e&&"clientY"in e}function m(e){if(!e)return!1;const{TouchEvent:t}=o(e.target);return t&&e instanceof t}const h=Object.freeze({Translate:{toString(e){if(!e)return;const{x:t,y:n}=e;return"translate3d("+(t?Math.round(t):0)+"px, "+(n?Math.round(n):0)+"px, 0)"}},Scale:{toString(e){if(!e)return;const{scaleX:t,scaleY:n}=e;return"scaleX("+t+") scaleY("+n+")"}},Transform:{toString(e){if(e)return[h.Translate.toString(e),h.Scale.toString(e)].join(" ")}},Transition:{toString(e){let{property:t,duration:n,easing:r}=e;return t+" "+n+"ms "+r}}}),b="a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";exports.CSS=h,exports.add=d,exports.canUseDOM=t,exports.findFirstFocusableNode=function(e){return e.matches(b)?e:e.querySelector(b)},exports.getEventCoordinates=function(e){if(m(e)){if(e.touches&&e.touches.length){const{clientX:t,clientY:n}=e.touches[0];return{x:t,y:n}}if(e.changedTouches&&e.changedTouches.length){const{clientX:t,clientY:n}=e.changedTouches[0];return{x:t,y:n}}}return x(e)?{x:e.clientX,y:e.clientY}:null},exports.getOwnerDocument=function(e){return e?n(e)?e.document:r(e)?u(e)?e:c(e)||s(e)?e.ownerDocument:document:document:document},exports.getWindow=o,exports.hasViewportRelativeCoordinates=x,exports.isDocument=u,exports.isHTMLElement=c,exports.isKeyboardEvent=function(e){if(!e)return!1;const{KeyboardEvent:t}=o(e.target);return t&&e instanceof t},exports.isNode=r,exports.isSVGElement=s,exports.isTouchEvent=m,exports.isWindow=n,exports.subtract=p,exports.useCombinedRefs=function(){for(var t=arguments.length,n=new Array(t),r=0;r<t;r++)n[r]=arguments[r];return e.useMemo(()=>e=>{n.forEach(t=>t(e))},n)},exports.useEvent=a,exports.useInterval=function(){const t=e.useRef(null);return[e.useCallback((e,n)=>{t.current=setInterval(e,n)},[]),e.useCallback(()=>{null!==t.current&&(clearInterval(t.current),t.current=null)},[])]},exports.useIsomorphicLayoutEffect=i,exports.useLatestValue=function(t,n){void 0===n&&(n=[t]);const r=e.useRef(t);return i(()=>{r.current!==t&&(r.current=t)},n),r},exports.useLazyMemo=function(t,n){const r=e.useRef();return e.useMemo(()=>{const e=t(r.current);return r.current=e,e},[...n])},exports.useNodeRef=function(t){const n=a(t),r=e.useRef(null),o=e.useCallback(e=>{e!==r.current&&(null==n||n(e,r.current)),r.current=e},[]);return[r,o]},exports.usePrevious=function(t){const n=e.useRef();return e.useEffect(()=>{n.current=t},[t]),n.current},exports.useUniqueId=function(t,n){return e.useMemo(()=>{if(n)return n;const e=null==l[t]?0:l[t]+1;return l[t]=e,t+"-"+e},[t,n])};
2
+ //# sourceMappingURL=dnd-kit-utilities.cjs.production.min.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dnd-kit-utilities.cjs.production.min.js","sources":["../src/execution-context/canUseDOM.ts","../src/type-guards/isWindow.ts","../src/type-guards/isNode.ts","../src/execution-context/getWindow.ts","../src/type-guards/isDocument.ts","../src/type-guards/isHTMLElement.ts","../src/type-guards/isSVGElement.ts","../src/hooks/useIsomorphicLayoutEffect.ts","../src/hooks/useEvent.ts","../src/hooks/useUniqueId.ts","../src/adjustment.ts","../src/event/hasViewportRelativeCoordinates.ts","../src/event/isTouchEvent.ts","../src/css.ts","../src/focus/findFirstFocusableNode.ts","../src/coordinates/getEventCoordinates.ts","../src/execution-context/getOwnerDocument.ts","../src/event/isKeyboardEvent.ts","../src/hooks/useCombinedRefs.ts","../src/hooks/useInterval.ts","../src/hooks/useLatestValue.ts","../src/hooks/useLazyMemo.ts","../src/hooks/useNodeRef.ts","../src/hooks/usePrevious.ts"],"sourcesContent":["// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js\nexport const canUseDOM =\n typeof window !== 'undefined' &&\n typeof window.document !== 'undefined' &&\n typeof window.document.createElement !== 'undefined';\n","export function isWindow(element: Object): element is typeof window {\n const elementString = Object.prototype.toString.call(element);\n return (\n elementString === '[object Window]' ||\n // In Electron context the Window object serializes to [object global]\n elementString === '[object global]'\n );\n}\n","export function isNode(node: Object): node is Node {\n return 'nodeType' in node;\n}\n","import {isWindow} from '../type-guards/isWindow';\nimport {isNode} from '../type-guards/isNode';\n\nexport function getWindow(target: Event['target']): typeof window {\n if (!target) {\n return window;\n }\n\n if (isWindow(target)) {\n return target;\n }\n\n if (!isNode(target)) {\n return window;\n }\n\n return target.ownerDocument?.defaultView ?? window;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isDocument(node: Node): node is Document {\n const {Document} = getWindow(node);\n\n return node instanceof Document;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nimport {isWindow} from './isWindow';\n\nexport function isHTMLElement(node: Node | Window): node is HTMLElement {\n if (isWindow(node)) {\n return false;\n }\n\n return node instanceof getWindow(node).HTMLElement;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isSVGElement(node: Node): node is SVGElement {\n return node instanceof getWindow(node).SVGElement;\n}\n","import {useEffect, useLayoutEffect} from 'react';\n\nimport {canUseDOM} from '../execution-context';\n\n/**\n * A hook that resolves to useEffect on the server and useLayoutEffect on the client\n * @param callback {function} Callback function that is invoked when the dependencies of the hook change\n */\nexport const useIsomorphicLayoutEffect = canUseDOM\n ? useLayoutEffect\n : useEffect;\n","import {useCallback, useRef} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useEvent<T extends Function>(handler: T | undefined) {\n const handlerRef = useRef<T | undefined>(handler);\n\n useIsomorphicLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback(function (...args: any) {\n return handlerRef.current?.(...args);\n }, []);\n}\n","import {useMemo} from 'react';\n\nlet ids: Record<string, number> = {};\n\nexport function useUniqueId(prefix: string, value?: string) {\n return useMemo(() => {\n if (value) {\n return value;\n }\n\n const id = ids[prefix] == null ? 0 : ids[prefix] + 1;\n ids[prefix] = id;\n\n return `${prefix}-${id}`;\n }, [prefix, value]);\n}\n","function createAdjustmentFn(modifier: number) {\n return <T extends Record<U, number>, U extends string>(\n object: T,\n ...adjustments: Partial<T>[]\n ): T => {\n return adjustments.reduce<T>(\n (accumulator, adjustment) => {\n const entries = Object.entries(adjustment) as [U, number][];\n\n for (const [key, valueAdjustment] of entries) {\n const value = accumulator[key];\n\n if (value != null) {\n accumulator[key] = (value + modifier * valueAdjustment) as T[U];\n }\n }\n\n return accumulator;\n },\n {\n ...object,\n }\n );\n };\n}\n\nexport const add = createAdjustmentFn(1);\nexport const subtract = createAdjustmentFn(-1);\n","export function hasViewportRelativeCoordinates(\n event: Event\n): event is Event & Pick<PointerEvent, 'clientX' | 'clientY'> {\n return 'clientX' in event && 'clientY' in event;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isTouchEvent(\n event: Event | undefined | null\n): event is TouchEvent {\n if (!event) {\n return false;\n }\n\n const {TouchEvent} = getWindow(event.target);\n\n return TouchEvent && event instanceof TouchEvent;\n}\n","export type Transform = {\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n};\n\nexport interface Transition {\n property: string;\n easing: string;\n duration: number;\n}\n\nexport const CSS = Object.freeze({\n Translate: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {x, y} = transform;\n\n return `translate3d(${x ? Math.round(x) : 0}px, ${\n y ? Math.round(y) : 0\n }px, 0)`;\n },\n },\n Scale: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {scaleX, scaleY} = transform;\n\n return `scaleX(${scaleX}) scaleY(${scaleY})`;\n },\n },\n Transform: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n return [\n CSS.Translate.toString(transform),\n CSS.Scale.toString(transform),\n ].join(' ');\n },\n },\n Transition: {\n toString({property, duration, easing}: Transition) {\n return `${property} ${duration}ms ${easing}`;\n },\n },\n});\n","const SELECTOR =\n 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';\n\nexport function findFirstFocusableNode(\n element: HTMLElement\n): HTMLElement | null {\n if (element.matches(SELECTOR)) {\n return element;\n }\n\n return element.querySelector(SELECTOR);\n}\n","import type {Coordinates} from './types';\nimport {isTouchEvent, hasViewportRelativeCoordinates} from '../event';\n\n/**\n * Returns the normalized x and y coordinates for mouse and touch events.\n */\nexport function getEventCoordinates(event: Event): Coordinates | null {\n if (isTouchEvent(event)) {\n if (event.touches && event.touches.length) {\n const {clientX: x, clientY: y} = event.touches[0];\n\n return {\n x,\n y,\n };\n } else if (event.changedTouches && event.changedTouches.length) {\n const {clientX: x, clientY: y} = event.changedTouches[0];\n\n return {\n x,\n y,\n };\n }\n }\n\n if (hasViewportRelativeCoordinates(event)) {\n return {\n x: event.clientX,\n y: event.clientY,\n };\n }\n\n return null;\n}\n","import {\n isWindow,\n isHTMLElement,\n isDocument,\n isNode,\n isSVGElement,\n} from '../type-guards';\n\nexport function getOwnerDocument(target: Event['target']): Document {\n if (!target) {\n return document;\n }\n\n if (isWindow(target)) {\n return target.document;\n }\n\n if (!isNode(target)) {\n return document;\n }\n\n if (isDocument(target)) {\n return target;\n }\n\n if (isHTMLElement(target) || isSVGElement(target)) {\n return target.ownerDocument;\n }\n\n return document;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isKeyboardEvent(\n event: Event | undefined | null\n): event is KeyboardEvent {\n if (!event) {\n return false;\n }\n\n const {KeyboardEvent} = getWindow(event.target);\n\n return KeyboardEvent && event instanceof KeyboardEvent;\n}\n","import {useMemo} from 'react';\n\nexport function useCombinedRefs<T>(\n ...refs: ((node: T) => void)[]\n): (node: T) => void {\n return useMemo(\n () => (node: T) => {\n refs.forEach((ref) => ref(node));\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n refs\n );\n}\n","import {useCallback, useRef} from 'react';\n\nexport function useInterval() {\n const intervalRef = useRef<number | null>(null);\n\n const set = useCallback((listener: Function, duration: number) => {\n intervalRef.current = setInterval(listener, duration);\n }, []);\n\n const clear = useCallback(() => {\n if (intervalRef.current !== null) {\n clearInterval(intervalRef.current);\n intervalRef.current = null;\n }\n }, []);\n\n return [set, clear] as const;\n}\n","import {useRef} from 'react';\nimport type {DependencyList} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useLatestValue<T extends any>(\n value: T,\n dependencies: DependencyList = [value]\n) {\n const valueRef = useRef<T>(value);\n\n useIsomorphicLayoutEffect(() => {\n if (valueRef.current !== value) {\n valueRef.current = value;\n }\n }, dependencies);\n\n return valueRef;\n}\n","import {useMemo, useRef} from 'react';\n\nexport function useLazyMemo<T>(\n callback: (prevValue: T | undefined) => T,\n dependencies: any[]\n) {\n const valueRef = useRef<T>();\n\n return useMemo(\n () => {\n const newValue = callback(valueRef.current);\n valueRef.current = newValue;\n\n return newValue;\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...dependencies]\n );\n}\n","import {useRef, useCallback} from 'react';\n\nimport {useEvent} from './useEvent';\n\nexport function useNodeRef(\n onChange?: (\n newElement: HTMLElement | null,\n previousElement: HTMLElement | null\n ) => void\n) {\n const onChangeHandler = useEvent(onChange);\n const node = useRef<HTMLElement | null>(null);\n const setNodeRef = useCallback(\n (element: HTMLElement | null) => {\n if (element !== node.current) {\n onChangeHandler?.(element, node.current);\n }\n\n node.current = element;\n },\n //eslint-disable-next-line\n []\n );\n\n return [node, setNodeRef] as const;\n}\n","import {useRef, useEffect} from 'react';\n\nexport function usePrevious<T>(value: T) {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n"],"names":["canUseDOM","window","document","createElement","isWindow","element","elementString","Object","prototype","toString","call","isNode","node","getWindow","target","ownerDocument","_target$ownerDocument2","defaultView","isDocument","Document","isHTMLElement","HTMLElement","isSVGElement","SVGElement","useIsomorphicLayoutEffect","useLayoutEffect","useEffect","useEvent","handler","handlerRef","useRef","current","useCallback","args","ids","createAdjustmentFn","modifier","object","adjustments","reduce","accumulator","adjustment","entries","key","valueAdjustment","value","add","subtract","hasViewportRelativeCoordinates","event","isTouchEvent","TouchEvent","CSS","freeze","Translate","transform","x","y","Math","round","Scale","scaleX","scaleY","Transform","join","Transition","property","duration","easing","SELECTOR","matches","querySelector","touches","length","clientX","clientY","changedTouches","KeyboardEvent","refs","useMemo","forEach","ref","intervalRef","listener","setInterval","clearInterval","dependencies","valueRef","callback","newValue","onChange","onChangeHandler","setNodeRef","prefix","id"],"mappings":"2FACA,MAAaA,EACO,oBAAXC,aACoB,IAApBA,OAAOC,eAC2B,IAAlCD,OAAOC,SAASC,u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C,2BAAAA,kBAEH,OAAOC,UACL,IAAOnE,IACLkE,EAAKE,QAASC,GAAQA,EAAIrE,KAG5BkE,sDCPF,MAAMI,EAAcpD,SAAsB,MAa1C,MAAO,CAXKE,cAAY,CAACmD,EAAoBhB,KAC3Ce,EAAYnD,QAAUqD,YAAYD,EAAUhB,IAC3C,IAEWnC,cAAY,KACI,OAAxBkD,EAAYnD,UACdsD,cAAcH,EAAYnD,SAC1BmD,EAAYnD,QAAU,OAEvB,0ECRHc,EACAyC,YAAAA,IAAAA,EAA+B,CAACzC,IAEhC,MAAM0C,EAAWzD,SAAUe,GAQ3B,OANArB,EAA0B,KACpB+D,EAASxD,UAAYc,IACvB0C,EAASxD,QAAUc,IAEpByC,GAEIC,gCCdPC,EACAF,GAEA,MAAMC,EAAWzD,WAEjB,OAAOiD,UACL,KACE,MAAMU,EAAWD,EAASD,EAASxD,SAGnC,OAFAwD,EAASxD,QAAU0D,EAEZA,GAGT,IAAIH,iCCXNI,GAKA,MAAMC,EAAkBhE,EAAS+D,GAC3B9E,EAAOkB,SAA2B,MAClC8D,EAAa5D,cAChB3B,IACKA,IAAYO,EAAKmB,gBACnB4D,GAAAA,EAAkBtF,EAASO,EAAKmB,UAGlCnB,EAAKmB,QAAU1B,GAGjB,IAGF,MAAO,CAACO,EAAMgF,iCCtBe/C,GAC7B,MAAMoC,EAAMnD,WAMZ,OAJAJ,YAAU,KACRuD,EAAIlD,QAAUc,GACb,CAACA,IAEGoC,EAAIlD,sCdLe8D,EAAgBhD,GAC1C,OAAOkC,UAAQ,KACb,GAAIlC,EACF,OAAOA,EAGT,MAAMiD,EAAoB,MAAf5D,EAAI2D,GAAkB,EAAI3D,EAAI2D,GAAU,EAGnD,OAFA3D,EAAI2D,GAAUC,EAEJD,MAAUC,GACnB,CAACD,EAAQhD"}
@@ -0,0 +1,333 @@
1
+ import { useMemo, useLayoutEffect, useEffect, useRef, useCallback } from 'react';
2
+
3
+ function useCombinedRefs() {
4
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
5
+ refs[_key] = arguments[_key];
6
+ }
7
+
8
+ return useMemo(() => node => {
9
+ refs.forEach(ref => ref(node));
10
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
11
+ refs);
12
+ }
13
+
14
+ // https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
15
+ const canUseDOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
16
+
17
+ function isWindow(element) {
18
+ const elementString = Object.prototype.toString.call(element);
19
+ return elementString === '[object Window]' || // In Electron context the Window object serializes to [object global]
20
+ elementString === '[object global]';
21
+ }
22
+
23
+ function isNode(node) {
24
+ return 'nodeType' in node;
25
+ }
26
+
27
+ function getWindow(target) {
28
+ var _target$ownerDocument, _target$ownerDocument2;
29
+
30
+ if (!target) {
31
+ return window;
32
+ }
33
+
34
+ if (isWindow(target)) {
35
+ return target;
36
+ }
37
+
38
+ if (!isNode(target)) {
39
+ return window;
40
+ }
41
+
42
+ return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
43
+ }
44
+
45
+ function isDocument(node) {
46
+ const {
47
+ Document
48
+ } = getWindow(node);
49
+ return node instanceof Document;
50
+ }
51
+
52
+ function isHTMLElement(node) {
53
+ if (isWindow(node)) {
54
+ return false;
55
+ }
56
+
57
+ return node instanceof getWindow(node).HTMLElement;
58
+ }
59
+
60
+ function isSVGElement(node) {
61
+ return node instanceof getWindow(node).SVGElement;
62
+ }
63
+
64
+ function getOwnerDocument(target) {
65
+ if (!target) {
66
+ return document;
67
+ }
68
+
69
+ if (isWindow(target)) {
70
+ return target.document;
71
+ }
72
+
73
+ if (!isNode(target)) {
74
+ return document;
75
+ }
76
+
77
+ if (isDocument(target)) {
78
+ return target;
79
+ }
80
+
81
+ if (isHTMLElement(target) || isSVGElement(target)) {
82
+ return target.ownerDocument;
83
+ }
84
+
85
+ return document;
86
+ }
87
+
88
+ /**
89
+ * A hook that resolves to useEffect on the server and useLayoutEffect on the client
90
+ * @param callback {function} Callback function that is invoked when the dependencies of the hook change
91
+ */
92
+
93
+ const useIsomorphicLayoutEffect = canUseDOM ? useLayoutEffect : useEffect;
94
+
95
+ function useEvent(handler) {
96
+ const handlerRef = useRef(handler);
97
+ useIsomorphicLayoutEffect(() => {
98
+ handlerRef.current = handler;
99
+ });
100
+ return useCallback(function () {
101
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
102
+ args[_key] = arguments[_key];
103
+ }
104
+
105
+ return handlerRef.current == null ? void 0 : handlerRef.current(...args);
106
+ }, []);
107
+ }
108
+
109
+ function useInterval() {
110
+ const intervalRef = useRef(null);
111
+ const set = useCallback((listener, duration) => {
112
+ intervalRef.current = setInterval(listener, duration);
113
+ }, []);
114
+ const clear = useCallback(() => {
115
+ if (intervalRef.current !== null) {
116
+ clearInterval(intervalRef.current);
117
+ intervalRef.current = null;
118
+ }
119
+ }, []);
120
+ return [set, clear];
121
+ }
122
+
123
+ function useLatestValue(value, dependencies) {
124
+ if (dependencies === void 0) {
125
+ dependencies = [value];
126
+ }
127
+
128
+ const valueRef = useRef(value);
129
+ useIsomorphicLayoutEffect(() => {
130
+ if (valueRef.current !== value) {
131
+ valueRef.current = value;
132
+ }
133
+ }, dependencies);
134
+ return valueRef;
135
+ }
136
+
137
+ function useLazyMemo(callback, dependencies) {
138
+ const valueRef = useRef();
139
+ return useMemo(() => {
140
+ const newValue = callback(valueRef.current);
141
+ valueRef.current = newValue;
142
+ return newValue;
143
+ }, // eslint-disable-next-line react-hooks/exhaustive-deps
144
+ [...dependencies]);
145
+ }
146
+
147
+ function useNodeRef(onChange) {
148
+ const onChangeHandler = useEvent(onChange);
149
+ const node = useRef(null);
150
+ const setNodeRef = useCallback(element => {
151
+ if (element !== node.current) {
152
+ onChangeHandler == null ? void 0 : onChangeHandler(element, node.current);
153
+ }
154
+
155
+ node.current = element;
156
+ }, //eslint-disable-next-line
157
+ []);
158
+ return [node, setNodeRef];
159
+ }
160
+
161
+ function usePrevious(value) {
162
+ const ref = useRef();
163
+ useEffect(() => {
164
+ ref.current = value;
165
+ }, [value]);
166
+ return ref.current;
167
+ }
168
+
169
+ let ids = {};
170
+ function useUniqueId(prefix, value) {
171
+ return useMemo(() => {
172
+ if (value) {
173
+ return value;
174
+ }
175
+
176
+ const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
177
+ ids[prefix] = id;
178
+ return prefix + "-" + id;
179
+ }, [prefix, value]);
180
+ }
181
+
182
+ function createAdjustmentFn(modifier) {
183
+ return function (object) {
184
+ for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
185
+ adjustments[_key - 1] = arguments[_key];
186
+ }
187
+
188
+ return adjustments.reduce((accumulator, adjustment) => {
189
+ const entries = Object.entries(adjustment);
190
+
191
+ for (const [key, valueAdjustment] of entries) {
192
+ const value = accumulator[key];
193
+
194
+ if (value != null) {
195
+ accumulator[key] = value + modifier * valueAdjustment;
196
+ }
197
+ }
198
+
199
+ return accumulator;
200
+ }, { ...object
201
+ });
202
+ };
203
+ }
204
+
205
+ const add = /*#__PURE__*/createAdjustmentFn(1);
206
+ const subtract = /*#__PURE__*/createAdjustmentFn(-1);
207
+
208
+ function hasViewportRelativeCoordinates(event) {
209
+ return 'clientX' in event && 'clientY' in event;
210
+ }
211
+
212
+ function isKeyboardEvent(event) {
213
+ if (!event) {
214
+ return false;
215
+ }
216
+
217
+ const {
218
+ KeyboardEvent
219
+ } = getWindow(event.target);
220
+ return KeyboardEvent && event instanceof KeyboardEvent;
221
+ }
222
+
223
+ function isTouchEvent(event) {
224
+ if (!event) {
225
+ return false;
226
+ }
227
+
228
+ const {
229
+ TouchEvent
230
+ } = getWindow(event.target);
231
+ return TouchEvent && event instanceof TouchEvent;
232
+ }
233
+
234
+ /**
235
+ * Returns the normalized x and y coordinates for mouse and touch events.
236
+ */
237
+
238
+ function getEventCoordinates(event) {
239
+ if (isTouchEvent(event)) {
240
+ if (event.touches && event.touches.length) {
241
+ const {
242
+ clientX: x,
243
+ clientY: y
244
+ } = event.touches[0];
245
+ return {
246
+ x,
247
+ y
248
+ };
249
+ } else if (event.changedTouches && event.changedTouches.length) {
250
+ const {
251
+ clientX: x,
252
+ clientY: y
253
+ } = event.changedTouches[0];
254
+ return {
255
+ x,
256
+ y
257
+ };
258
+ }
259
+ }
260
+
261
+ if (hasViewportRelativeCoordinates(event)) {
262
+ return {
263
+ x: event.clientX,
264
+ y: event.clientY
265
+ };
266
+ }
267
+
268
+ return null;
269
+ }
270
+
271
+ const CSS = /*#__PURE__*/Object.freeze({
272
+ Translate: {
273
+ toString(transform) {
274
+ if (!transform) {
275
+ return;
276
+ }
277
+
278
+ const {
279
+ x,
280
+ y
281
+ } = transform;
282
+ return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
283
+ }
284
+
285
+ },
286
+ Scale: {
287
+ toString(transform) {
288
+ if (!transform) {
289
+ return;
290
+ }
291
+
292
+ const {
293
+ scaleX,
294
+ scaleY
295
+ } = transform;
296
+ return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
297
+ }
298
+
299
+ },
300
+ Transform: {
301
+ toString(transform) {
302
+ if (!transform) {
303
+ return;
304
+ }
305
+
306
+ return [CSS.Translate.toString(transform), CSS.Scale.toString(transform)].join(' ');
307
+ }
308
+
309
+ },
310
+ Transition: {
311
+ toString(_ref) {
312
+ let {
313
+ property,
314
+ duration,
315
+ easing
316
+ } = _ref;
317
+ return property + " " + duration + "ms " + easing;
318
+ }
319
+
320
+ }
321
+ });
322
+
323
+ const SELECTOR = 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';
324
+ function findFirstFocusableNode(element) {
325
+ if (element.matches(SELECTOR)) {
326
+ return element;
327
+ }
328
+
329
+ return element.querySelector(SELECTOR);
330
+ }
331
+
332
+ export { CSS, add, canUseDOM, findFirstFocusableNode, getEventCoordinates, getOwnerDocument, getWindow, hasViewportRelativeCoordinates, isDocument, isHTMLElement, isKeyboardEvent, isNode, isSVGElement, isTouchEvent, isWindow, subtract, useCombinedRefs, useEvent, useInterval, useIsomorphicLayoutEffect, useLatestValue, useLazyMemo, useNodeRef, usePrevious, useUniqueId };
333
+ //# sourceMappingURL=dnd-kit-utilities.esm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dnd-kit-utilities.esm.js","sources":["../src/hooks/useCombinedRefs.ts","../src/execution-context/canUseDOM.ts","../src/type-guards/isWindow.ts","../src/type-guards/isNode.ts","../src/execution-context/getWindow.ts","../src/type-guards/isDocument.ts","../src/type-guards/isHTMLElement.ts","../src/type-guards/isSVGElement.ts","../src/execution-context/getOwnerDocument.ts","../src/hooks/useIsomorphicLayoutEffect.ts","../src/hooks/useEvent.ts","../src/hooks/useInterval.ts","../src/hooks/useLatestValue.ts","../src/hooks/useLazyMemo.ts","../src/hooks/useNodeRef.ts","../src/hooks/usePrevious.ts","../src/hooks/useUniqueId.ts","../src/adjustment.ts","../src/event/hasViewportRelativeCoordinates.ts","../src/event/isKeyboardEvent.ts","../src/event/isTouchEvent.ts","../src/coordinates/getEventCoordinates.ts","../src/css.ts","../src/focus/findFirstFocusableNode.ts"],"sourcesContent":["import {useMemo} from 'react';\n\nexport function useCombinedRefs<T>(\n ...refs: ((node: T) => void)[]\n): (node: T) => void {\n return useMemo(\n () => (node: T) => {\n refs.forEach((ref) => ref(node));\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n refs\n );\n}\n","// https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js\nexport const canUseDOM =\n typeof window !== 'undefined' &&\n typeof window.document !== 'undefined' &&\n typeof window.document.createElement !== 'undefined';\n","export function isWindow(element: Object): element is typeof window {\n const elementString = Object.prototype.toString.call(element);\n return (\n elementString === '[object Window]' ||\n // In Electron context the Window object serializes to [object global]\n elementString === '[object global]'\n );\n}\n","export function isNode(node: Object): node is Node {\n return 'nodeType' in node;\n}\n","import {isWindow} from '../type-guards/isWindow';\nimport {isNode} from '../type-guards/isNode';\n\nexport function getWindow(target: Event['target']): typeof window {\n if (!target) {\n return window;\n }\n\n if (isWindow(target)) {\n return target;\n }\n\n if (!isNode(target)) {\n return window;\n }\n\n return target.ownerDocument?.defaultView ?? window;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isDocument(node: Node): node is Document {\n const {Document} = getWindow(node);\n\n return node instanceof Document;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nimport {isWindow} from './isWindow';\n\nexport function isHTMLElement(node: Node | Window): node is HTMLElement {\n if (isWindow(node)) {\n return false;\n }\n\n return node instanceof getWindow(node).HTMLElement;\n}\n","import {getWindow} from '../execution-context/getWindow';\n\nexport function isSVGElement(node: Node): node is SVGElement {\n return node instanceof getWindow(node).SVGElement;\n}\n","import {\n isWindow,\n isHTMLElement,\n isDocument,\n isNode,\n isSVGElement,\n} from '../type-guards';\n\nexport function getOwnerDocument(target: Event['target']): Document {\n if (!target) {\n return document;\n }\n\n if (isWindow(target)) {\n return target.document;\n }\n\n if (!isNode(target)) {\n return document;\n }\n\n if (isDocument(target)) {\n return target;\n }\n\n if (isHTMLElement(target) || isSVGElement(target)) {\n return target.ownerDocument;\n }\n\n return document;\n}\n","import {useEffect, useLayoutEffect} from 'react';\n\nimport {canUseDOM} from '../execution-context';\n\n/**\n * A hook that resolves to useEffect on the server and useLayoutEffect on the client\n * @param callback {function} Callback function that is invoked when the dependencies of the hook change\n */\nexport const useIsomorphicLayoutEffect = canUseDOM\n ? useLayoutEffect\n : useEffect;\n","import {useCallback, useRef} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useEvent<T extends Function>(handler: T | undefined) {\n const handlerRef = useRef<T | undefined>(handler);\n\n useIsomorphicLayoutEffect(() => {\n handlerRef.current = handler;\n });\n\n return useCallback(function (...args: any) {\n return handlerRef.current?.(...args);\n }, []);\n}\n","import {useCallback, useRef} from 'react';\n\nexport function useInterval() {\n const intervalRef = useRef<number | null>(null);\n\n const set = useCallback((listener: Function, duration: number) => {\n intervalRef.current = setInterval(listener, duration);\n }, []);\n\n const clear = useCallback(() => {\n if (intervalRef.current !== null) {\n clearInterval(intervalRef.current);\n intervalRef.current = null;\n }\n }, []);\n\n return [set, clear] as const;\n}\n","import {useRef} from 'react';\nimport type {DependencyList} from 'react';\n\nimport {useIsomorphicLayoutEffect} from './useIsomorphicLayoutEffect';\n\nexport function useLatestValue<T extends any>(\n value: T,\n dependencies: DependencyList = [value]\n) {\n const valueRef = useRef<T>(value);\n\n useIsomorphicLayoutEffect(() => {\n if (valueRef.current !== value) {\n valueRef.current = value;\n }\n }, dependencies);\n\n return valueRef;\n}\n","import {useMemo, useRef} from 'react';\n\nexport function useLazyMemo<T>(\n callback: (prevValue: T | undefined) => T,\n dependencies: any[]\n) {\n const valueRef = useRef<T>();\n\n return useMemo(\n () => {\n const newValue = callback(valueRef.current);\n valueRef.current = newValue;\n\n return newValue;\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [...dependencies]\n );\n}\n","import {useRef, useCallback} from 'react';\n\nimport {useEvent} from './useEvent';\n\nexport function useNodeRef(\n onChange?: (\n newElement: HTMLElement | null,\n previousElement: HTMLElement | null\n ) => void\n) {\n const onChangeHandler = useEvent(onChange);\n const node = useRef<HTMLElement | null>(null);\n const setNodeRef = useCallback(\n (element: HTMLElement | null) => {\n if (element !== node.current) {\n onChangeHandler?.(element, node.current);\n }\n\n node.current = element;\n },\n //eslint-disable-next-line\n []\n );\n\n return [node, setNodeRef] as const;\n}\n","import {useRef, useEffect} from 'react';\n\nexport function usePrevious<T>(value: T) {\n const ref = useRef<T>();\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n","import {useMemo} from 'react';\n\nlet ids: Record<string, number> = {};\n\nexport function useUniqueId(prefix: string, value?: string) {\n return useMemo(() => {\n if (value) {\n return value;\n }\n\n const id = ids[prefix] == null ? 0 : ids[prefix] + 1;\n ids[prefix] = id;\n\n return `${prefix}-${id}`;\n }, [prefix, value]);\n}\n","function createAdjustmentFn(modifier: number) {\n return <T extends Record<U, number>, U extends string>(\n object: T,\n ...adjustments: Partial<T>[]\n ): T => {\n return adjustments.reduce<T>(\n (accumulator, adjustment) => {\n const entries = Object.entries(adjustment) as [U, number][];\n\n for (const [key, valueAdjustment] of entries) {\n const value = accumulator[key];\n\n if (value != null) {\n accumulator[key] = (value + modifier * valueAdjustment) as T[U];\n }\n }\n\n return accumulator;\n },\n {\n ...object,\n }\n );\n };\n}\n\nexport const add = createAdjustmentFn(1);\nexport const subtract = createAdjustmentFn(-1);\n","export function hasViewportRelativeCoordinates(\n event: Event\n): event is Event & Pick<PointerEvent, 'clientX' | 'clientY'> {\n return 'clientX' in event && 'clientY' in event;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isKeyboardEvent(\n event: Event | undefined | null\n): event is KeyboardEvent {\n if (!event) {\n return false;\n }\n\n const {KeyboardEvent} = getWindow(event.target);\n\n return KeyboardEvent && event instanceof KeyboardEvent;\n}\n","import {getWindow} from '../execution-context';\n\nexport function isTouchEvent(\n event: Event | undefined | null\n): event is TouchEvent {\n if (!event) {\n return false;\n }\n\n const {TouchEvent} = getWindow(event.target);\n\n return TouchEvent && event instanceof TouchEvent;\n}\n","import type {Coordinates} from './types';\nimport {isTouchEvent, hasViewportRelativeCoordinates} from '../event';\n\n/**\n * Returns the normalized x and y coordinates for mouse and touch events.\n */\nexport function getEventCoordinates(event: Event): Coordinates | null {\n if (isTouchEvent(event)) {\n if (event.touches && event.touches.length) {\n const {clientX: x, clientY: y} = event.touches[0];\n\n return {\n x,\n y,\n };\n } else if (event.changedTouches && event.changedTouches.length) {\n const {clientX: x, clientY: y} = event.changedTouches[0];\n\n return {\n x,\n y,\n };\n }\n }\n\n if (hasViewportRelativeCoordinates(event)) {\n return {\n x: event.clientX,\n y: event.clientY,\n };\n }\n\n return null;\n}\n","export type Transform = {\n x: number;\n y: number;\n scaleX: number;\n scaleY: number;\n};\n\nexport interface Transition {\n property: string;\n easing: string;\n duration: number;\n}\n\nexport const CSS = Object.freeze({\n Translate: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {x, y} = transform;\n\n return `translate3d(${x ? Math.round(x) : 0}px, ${\n y ? Math.round(y) : 0\n }px, 0)`;\n },\n },\n Scale: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n const {scaleX, scaleY} = transform;\n\n return `scaleX(${scaleX}) scaleY(${scaleY})`;\n },\n },\n Transform: {\n toString(transform: Transform | null) {\n if (!transform) {\n return;\n }\n\n return [\n CSS.Translate.toString(transform),\n CSS.Scale.toString(transform),\n ].join(' ');\n },\n },\n Transition: {\n toString({property, duration, easing}: Transition) {\n return `${property} ${duration}ms ${easing}`;\n },\n },\n});\n","const SELECTOR =\n 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';\n\nexport function findFirstFocusableNode(\n element: HTMLElement\n): HTMLElement | null {\n if (element.matches(SELECTOR)) {\n return element;\n }\n\n return element.querySelector(SELECTOR);\n}\n"],"names":["useCombinedRefs","refs","useMemo","node","forEach","ref","canUseDOM","window","document","createElement","isWindow","element","elementString","Object","prototype","toString","call","isNode","getWindow","target","ownerDocument","defaultView","isDocument","Document","isHTMLElement","HTMLElement","isSVGElement","SVGElement","getOwnerDocument","useIsomorphicLayoutEffect","useLayoutEffect","useEffect","useEvent","handler","handlerRef","useRef","current","useCallback","args","useInterval","intervalRef","set","listener","duration","setInterval","clear","clearInterval","useLatestValue","value","dependencies","valueRef","useLazyMemo","callback","newValue","useNodeRef","onChange","onChangeHandler","setNodeRef","usePrevious","ids","useUniqueId","prefix","id","createAdjustmentFn","modifier","object","adjustments","reduce","accumulator","adjustment","entries","key","valueAdjustment","add","subtract","hasViewportRelativeCoordinates","event","isKeyboardEvent","KeyboardEvent","isTouchEvent","TouchEvent","getEventCoordinates","touches","length","clientX","x","clientY","y","changedTouches","CSS","freeze","Translate","transform","Math","round","Scale","scaleX","scaleY","Transform","join","Transition","property","easing","SELECTOR","findFirstFocusableNode","matches","querySelector"],"mappings":";;SAEgBA;oCACXC;IAAAA;;;EAEH,OAAOC,OAAO,CACZ,MAAOC,IAAD;IACJF,IAAI,CAACG,OAAL,CAAcC,GAAD,IAASA,GAAG,CAACF,IAAD,CAAzB;GAFU;EAKZF,IALY,CAAd;AAOD;;ACZD;AACA,MAAaK,SAAS,GACpB,OAAOC,MAAP,KAAkB,WAAlB,IACA,OAAOA,MAAM,CAACC,QAAd,KAA2B,WAD3B,IAEA,OAAOD,MAAM,CAACC,QAAP,CAAgBC,aAAvB,KAAyC,WAHpC;;SCDSC,SAASC;EACvB,MAAMC,aAAa,GAAGC,MAAM,CAACC,SAAP,CAAiBC,QAAjB,CAA0BC,IAA1B,CAA+BL,OAA/B,CAAtB;EACA,OACEC,aAAa,KAAK,iBAAlB;EAEAA,aAAa,KAAK,iBAHpB;AAKD;;SCPeK,OAAOd;EACrB,OAAO,cAAcA,IAArB;AACD;;SCCee,UAAUC;;;EACxB,IAAI,CAACA,MAAL,EAAa;IACX,OAAOZ,MAAP;;;EAGF,IAAIG,QAAQ,CAACS,MAAD,CAAZ,EAAsB;IACpB,OAAOA,MAAP;;;EAGF,IAAI,CAACF,MAAM,CAACE,MAAD,CAAX,EAAqB;IACnB,OAAOZ,MAAP;;;EAGF,0DAAOY,MAAM,CAACC,aAAd,qBAAO,uBAAsBC,WAA7B,oCAA4Cd,MAA5C;AACD;;SCfee,WAAWnB;EACzB,MAAM;IAACoB;MAAYL,SAAS,CAACf,IAAD,CAA5B;EAEA,OAAOA,IAAI,YAAYoB,QAAvB;AACD;;SCFeC,cAAcrB;EAC5B,IAAIO,QAAQ,CAACP,IAAD,CAAZ,EAAoB;IAClB,OAAO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N,IAAI,CAACA,SAAL,EAAgB;QACd;;;MAGF,MAAM;QAACP,CAAD;QAAIE;UAAKK,SAAf;MAEA,yBAAsBP,CAAC,GAAGQ,IAAI,CAACC,KAAL,CAAWT,CAAX,CAAH,GAAmB,CAA1C,cACEE,CAAC,GAAGM,IAAI,CAACC,KAAL,CAAWP,CAAX,CAAH,GAAmB,CADtB;;;GAT2B;EAc/BQ,KAAK,EAAE;IACLhF,QAAQ,CAAC6E,SAAD;MACN,IAAI,CAACA,SAAL,EAAgB;QACd;;;MAGF,MAAM;QAACI,MAAD;QAASC;UAAUL,SAAzB;MAEA,mBAAiBI,MAAjB,iBAAmCC,MAAnC;;;GAtB2B;EAyB/BC,SAAS,EAAE;IACTnF,QAAQ,CAAC6E,SAAD;MACN,IAAI,CAACA,SAAL,EAAgB;QACd;;;MAGF,OAAO,CACLH,GAAG,CAACE,SAAJ,CAAc5E,QAAd,CAAuB6E,SAAvB,CADK,EAELH,GAAG,CAACM,KAAJ,CAAUhF,QAAV,CAAmB6E,SAAnB,CAFK,EAGLO,IAHK,CAGA,GAHA,CAAP;;;GA/B2B;EAqC/BC,UAAU,EAAE;IACVrF,QAAQ;UAAC;QAACsF,QAAD;QAAW1D,QAAX;QAAqB2D;;MAC5B,OAAUD,QAAV,SAAsB1D,QAAtB,WAAoC2D,MAApC;;;;AAvC2B,CAAd,CAAZ;;ACbP,MAAMC,QAAQ,GACZ,wIADF;AAGA,SAAgBC,uBACd7F;EAEA,IAAIA,OAAO,CAAC8F,OAAR,CAAgBF,QAAhB,CAAJ,EAA+B;IAC7B,OAAO5F,OAAP;;;EAGF,OAAOA,OAAO,CAAC+F,aAAR,CAAsBH,QAAtB,CAAP;AACD;;;;"}
@@ -0,0 +1 @@
1
+ export declare function hasViewportRelativeCoordinates(event: Event): event is Event & Pick<PointerEvent, 'clientX' | 'clientY'>;
@@ -0,0 +1,3 @@
1
+ export { hasViewportRelativeCoordinates } from './hasViewportRelativeCoordinates';
2
+ export { isKeyboardEvent } from './isKeyboardEvent';
3
+ export { isTouchEvent } from './isTouchEvent';
@@ -0,0 +1 @@
1
+ export declare function isKeyboardEvent(event: Event | undefined | null): event is KeyboardEvent;
@@ -0,0 +1 @@
1
+ export declare function isTouchEvent(event: Event | undefined | null): event is TouchEvent;
@@ -0,0 +1 @@
1
+ export declare const canUseDOM: boolean;
@@ -0,0 +1 @@
1
+ export declare function getOwnerDocument(target: Event['target']): Document;
@@ -0,0 +1 @@
1
+ export declare function getWindow(target: Event['target']): typeof window;
@@ -0,0 +1,3 @@
1
+ export { canUseDOM } from './canUseDOM';
2
+ export { getOwnerDocument } from './getOwnerDocument';
3
+ export { getWindow } from './getWindow';
@@ -0,0 +1 @@
1
+ export declare function findFirstFocusableNode(element: HTMLElement): HTMLElement | null;
@@ -0,0 +1 @@
1
+ export { findFirstFocusableNode } from './findFirstFocusableNode';
@@ -0,0 +1,9 @@
1
+ export { useCombinedRefs } from './useCombinedRefs';
2
+ export { useEvent } from './useEvent';
3
+ export { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect';
4
+ export { useInterval } from './useInterval';
5
+ export { useLatestValue } from './useLatestValue';
6
+ export { useLazyMemo } from './useLazyMemo';
7
+ export { useNodeRef } from './useNodeRef';
8
+ export { usePrevious } from './usePrevious';
9
+ export { useUniqueId } from './useUniqueId';
@@ -0,0 +1 @@
1
+ export declare function useCombinedRefs<T>(...refs: ((node: T) => void)[]): (node: T) => void;
@@ -0,0 +1 @@
1
+ export declare function useEvent<T extends Function>(handler: T | undefined): (...args: any) => any;
@@ -0,0 +1 @@
1
+ export declare function useInterval(): readonly [(listener: Function, duration: number) => void, () => void];
@@ -0,0 +1,6 @@
1
+ import { useLayoutEffect } from 'react';
2
+ /**
3
+ * A hook that resolves to useEffect on the server and useLayoutEffect on the client
4
+ * @param callback {function} Callback function that is invoked when the dependencies of the hook change
5
+ */
6
+ export declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
@@ -0,0 +1,2 @@
1
+ import type { DependencyList } from 'react';
2
+ export declare function useLatestValue<T extends any>(value: T, dependencies?: DependencyList): import("react").MutableRefObject<T>;
@@ -0,0 +1 @@
1
+ export declare function useLazyMemo<T>(callback: (prevValue: T | undefined) => T, dependencies: any[]): T;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export declare function useNodeRef(onChange?: (newElement: HTMLElement | null, previousElement: HTMLElement | null) => void): readonly [import("react").MutableRefObject<HTMLElement | null>, (element: HTMLElement | null) => void];
@@ -0,0 +1 @@
1
+ export declare function usePrevious<T>(value: T): T | undefined;
@@ -0,0 +1 @@
1
+ export declare function useUniqueId(prefix: string, value?: string): string;
@@ -0,0 +1,11 @@
1
+ export { useCombinedRefs, useEvent, useIsomorphicLayoutEffect, useInterval, useLatestValue, useLazyMemo, useNodeRef, usePrevious, useUniqueId, } from './hooks';
2
+ export { add, subtract } from './adjustment';
3
+ export type { Coordinates } from './coordinates';
4
+ export { getEventCoordinates } from './coordinates';
5
+ export { CSS } from './css';
6
+ export type { Transform, Transition } from './css';
7
+ export { hasViewportRelativeCoordinates, isKeyboardEvent, isTouchEvent, } from './event';
8
+ export { canUseDOM, getOwnerDocument, getWindow } from './execution-context';
9
+ export { findFirstFocusableNode } from './focus';
10
+ export { isDocument, isHTMLElement, isNode, isSVGElement, isWindow, } from './type-guards';
11
+ export type { Arguments, DeepRequired, FirstArgument, Without } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,8 @@
1
+
2
+ 'use strict'
3
+
4
+ if (process.env.NODE_ENV === 'production') {
5
+ module.exports = require('./dnd-kit-utilities.cjs.production.min.js')
6
+ } else {
7
+ module.exports = require('./dnd-kit-utilities.cjs.development.js')
8
+ }
@@ -0,0 +1,5 @@
1
+ export { isDocument } from './isDocument';
2
+ export { isHTMLElement } from './isHTMLElement';
3
+ export { isNode } from './isNode';
4
+ export { isSVGElement } from './isSVGElement';
5
+ export { isWindow } from './isWindow';
@@ -0,0 +1 @@
1
+ export declare function isDocument(node: Node): node is Document;
@@ -0,0 +1 @@
1
+ export declare function isHTMLElement(node: Node | Window): node is HTMLElement;
@@ -0,0 +1 @@
1
+ export declare function isNode(node: Object): node is Node;
@@ -0,0 +1 @@
1
+ export declare function isSVGElement(node: Node): node is SVGElement;
@@ -0,0 +1 @@
1
+ export declare function isWindow(element: Object): element is typeof window;
@@ -0,0 +1,6 @@
1
+ export declare type Arguments<T> = T extends (...args: infer U) => any ? U : never;
2
+ export declare type DeepRequired<T> = {
3
+ [K in keyof T]-?: Required<T[K]>;
4
+ };
5
+ export declare type FirstArgument<T> = T extends (firstArg: infer U, ...args: Array<any>) => any ? U : never;
6
+ export declare type Without<T, K extends keyof T> = Pick<T, Exclude<keyof T, K>>;
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "@lucasols/dnd-kit-utilities",
3
+ "version": "0.1.1",
4
+ "description": "Internal utilities to bee shared between `@dnd-kit` packages",
5
+ "author": "Claudéric Demers",
6
+ "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/clauderic/dnd-kit.git",
10
+ "directory": "packages/utilities"
11
+ },
12
+ "scripts": {
13
+ "start": "tsdx watch --tsconfig tsconfig.build.json --verbose --noClean",
14
+ "build": "tsdx build --tsconfig tsconfig.build.json",
15
+ "test": "tsdx test",
16
+ "lint": "tsdx lint",
17
+ "prepublish": "npm run build"
18
+ },
19
+ "main": "dist/index.js",
20
+ "module": "dist/utilities.esm.js",
21
+ "typings": "dist/index.d.ts",
22
+ "files": [
23
+ "README.md",
24
+ "CHANGELOG.md",
25
+ "LICENSE",
26
+ "dist"
27
+ ],
28
+ "dependencies": {
29
+ "tslib": "^2.0.0"
30
+ },
31
+ "peerDependencies": {
32
+ "react": ">=16.8.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "gitHead": "d4c160d488c7d4e49dba5aee2bbb3ac7a8acc71b"
38
+ }