@pnkx-lib/ui 1.9.4 → 1.9.5

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.
@@ -1,10 +1,10 @@
1
- import { j as jsxRuntimeExports, b as Icon, _ as _extends, c as _typeof, P as PnkxField, C as CheckboxField, u as useForm, d as classNames, e as _arrayLikeToArray, f as _unsupportedIterableToArray, w as warningOnce, h as _createClass, i as _classCallCheck, k as _defineProperty, l as _slicedToArray, m as warning$1, n as canUseDom, o as _objectSpread2, p as updateCSS, r as removeCSS, q as _arrayWithHoles, s as _nonIterableRest, t as resetWarned$1, F as FastColor, v as generate, x as presetPrimaryColors, y as presetPalettes, z as _inherits, A as _createSuper, B as _assertThisInitialized, G as _objectWithoutProperties, H as IconContext } from './Switch-za5Skgtp.js';
2
- import { Button as Button$1, Cascader, Space as Space$1, Card, Skeleton as Skeleton$1, Modal as Modal$1, Tooltip as Tooltip$1, Popconfirm as Popconfirm$1, Typography, Table as Table$1, Tabs as Tabs$1, Popover as Popover$1, Badge as Badge$1, Col as Col$1, Row as Row$1, Dropdown as Dropdown$1, Breadcrumb as Breadcrumb$1, Flex as Flex$1, Splitter as Splitter$1, Menu as Menu$1, Pagination as Pagination$1, Steps as Steps$1, Tag as Tag$1, Divider as Divider$2, Alert as Alert$1, Spin as Spin$1, Drawer as Drawer$1, QRCode as QRCode$1, Result as Result$1, Rate as Rate$1, Segmented as Segmented$1, Statistic as Statistic$1, Timeline as Timeline$1, Tour as Tour$1, Tree as Tree$1, Watermark as Watermark$1, Anchor as Anchor$1, Affix, AutoComplete as AutoComplete$1, Input, Collapse, ColorPicker, Empty as Empty$2, Image as Image$1 } from 'antd';
1
+ import { j as jsxRuntimeExports, b as Icon, _ as _extends, c as _typeof, u as useForm, P as PnkxField, I as Input, d as classNames, e as _arrayLikeToArray, f as _unsupportedIterableToArray, w as warningOnce, h as _createClass, i as _classCallCheck, k as _defineProperty, l as _slicedToArray, m as warning$1, n as canUseDom, o as _objectSpread2, p as updateCSS, r as removeCSS, q as _arrayWithHoles, s as _nonIterableRest, t as resetWarned$1, F as FastColor, v as generate, x as presetPrimaryColors, y as presetPalettes, z as _inherits, A as _createSuper, B as _assertThisInitialized, C as _objectWithoutProperties, G as IconContext } from './Switch-eMq9KkOy.js';
2
+ import { Button as Button$1, Cascader, Space as Space$1, Card, Skeleton as Skeleton$1, Tooltip as Tooltip$1, Popconfirm as Popconfirm$1, Typography, Table as Table$1, Modal as Modal$1, Tabs as Tabs$1, Popover as Popover$1, Badge as Badge$1, Col as Col$1, Row as Row$1, Dropdown as Dropdown$1, Breadcrumb as Breadcrumb$1, Flex as Flex$1, Splitter as Splitter$1, Menu as Menu$1, Pagination as Pagination$1, Steps as Steps$1, Tag as Tag$1, Divider as Divider$2, Alert as Alert$1, Spin as Spin$1, Drawer as Drawer$1, QRCode as QRCode$1, Result as Result$1, Rate as Rate$1, Segmented as Segmented$1, Statistic as Statistic$1, Timeline as Timeline$1, Tour as Tour$1, Tree as Tree$1, Watermark as Watermark$1, Anchor as Anchor$1, Affix, AutoComplete as AutoComplete$1, Input as Input$1, Collapse, ColorPicker, Empty as Empty$2, Image as Image$1 } from 'antd';
3
3
  import * as React from 'react';
4
- import React__default, { version as version$1, isValidElement, useLayoutEffect as useLayoutEffect$1, useEffect, useRef, useMemo as useMemo$1, useCallback, useState, createContext, memo, useReducer, useContext, Component } from 'react';
5
- import ReactDOM__default, { unstable_batchedUpdates, createPortal } from 'react-dom';
4
+ import React__default, { version as version$1, isValidElement, useState, useEffect, useContext, createContext, useRef, useLayoutEffect as useLayoutEffect$1, useMemo as useMemo$1, Component } from 'react';
6
5
  import { useNavigate, useLocation } from 'react-router';
7
6
  import { u as useToast } from './cloneDeep-BLYi2V0G.js';
7
+ import ReactDOM__default from 'react-dom';
8
8
 
9
9
  const Button = (props) => {
10
10
  return /* @__PURE__ */ jsxRuntimeExports.jsx(Button$1, { ...props });
@@ -1695,6 +1695,7 @@ var classnames = function classnames(args) {
1695
1695
  var _createEmotion = createEmotion({
1696
1696
  key: 'css'
1697
1697
  }),
1698
+ cx = _createEmotion.cx,
1698
1699
  css = _createEmotion.css;
1699
1700
 
1700
1701
  // This icon file is generated automatically.
@@ -2189,4387 +2190,6 @@ const styles$1 = {
2189
2190
  }
2190
2191
  };
2191
2192
 
2192
- const Modal = ({ children, onOk, onSubmit, ...rest }) => {
2193
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Modal$1, { onOk: onSubmit ? onSubmit : onOk, ...rest, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "max-h-[20rem] overflow-y-auto", children: onSubmit ? /* @__PURE__ */ jsxRuntimeExports.jsx("form", { onSubmit, children }) : children }) });
2194
- };
2195
-
2196
- const SettingColumnItem = ({ lable, name, control }) => {
2197
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "w-full pt-2 pb-2 inline-flex", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
2198
- PnkxField,
2199
- {
2200
- label: lable,
2201
- component: CheckboxField,
2202
- name,
2203
- control,
2204
- afterOnChange: () => {
2205
- }
2206
- }
2207
- ) }, name);
2208
- };
2209
-
2210
- function useCombinedRefs() {
2211
- for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
2212
- refs[_key] = arguments[_key];
2213
- }
2214
-
2215
- return useMemo$1(() => node => {
2216
- refs.forEach(ref => ref(node));
2217
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
2218
- refs);
2219
- }
2220
-
2221
- // https://github.com/facebook/react/blob/master/packages/shared/ExecutionEnvironment.js
2222
- const canUseDOM = typeof window !== 'undefined' && typeof window.document !== 'undefined' && typeof window.document.createElement !== 'undefined';
2223
-
2224
- function isWindow(element) {
2225
- const elementString = Object.prototype.toString.call(element);
2226
- return elementString === '[object Window]' || // In Electron context the Window object serializes to [object global]
2227
- elementString === '[object global]';
2228
- }
2229
-
2230
- function isNode(node) {
2231
- return 'nodeType' in node;
2232
- }
2233
-
2234
- function getWindow(target) {
2235
- var _target$ownerDocument, _target$ownerDocument2;
2236
-
2237
- if (!target) {
2238
- return window;
2239
- }
2240
-
2241
- if (isWindow(target)) {
2242
- return target;
2243
- }
2244
-
2245
- if (!isNode(target)) {
2246
- return window;
2247
- }
2248
-
2249
- return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
2250
- }
2251
-
2252
- function isDocument(node) {
2253
- const {
2254
- Document
2255
- } = getWindow(node);
2256
- return node instanceof Document;
2257
- }
2258
-
2259
- function isHTMLElement(node) {
2260
- if (isWindow(node)) {
2261
- return false;
2262
- }
2263
-
2264
- return node instanceof getWindow(node).HTMLElement;
2265
- }
2266
-
2267
- function isSVGElement(node) {
2268
- return node instanceof getWindow(node).SVGElement;
2269
- }
2270
-
2271
- function getOwnerDocument(target) {
2272
- if (!target) {
2273
- return document;
2274
- }
2275
-
2276
- if (isWindow(target)) {
2277
- return target.document;
2278
- }
2279
-
2280
- if (!isNode(target)) {
2281
- return document;
2282
- }
2283
-
2284
- if (isDocument(target)) {
2285
- return target;
2286
- }
2287
-
2288
- if (isHTMLElement(target) || isSVGElement(target)) {
2289
- return target.ownerDocument;
2290
- }
2291
-
2292
- return document;
2293
- }
2294
-
2295
- /**
2296
- * A hook that resolves to useEffect on the server and useLayoutEffect on the client
2297
- * @param callback {function} Callback function that is invoked when the dependencies of the hook change
2298
- */
2299
-
2300
- const useIsomorphicLayoutEffect$1 = canUseDOM ? useLayoutEffect$1 : useEffect;
2301
-
2302
- function useEvent$1(handler) {
2303
- const handlerRef = useRef(handler);
2304
- useIsomorphicLayoutEffect$1(() => {
2305
- handlerRef.current = handler;
2306
- });
2307
- return useCallback(function () {
2308
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
2309
- args[_key] = arguments[_key];
2310
- }
2311
-
2312
- return handlerRef.current == null ? void 0 : handlerRef.current(...args);
2313
- }, []);
2314
- }
2315
-
2316
- function useInterval() {
2317
- const intervalRef = useRef(null);
2318
- const set = useCallback((listener, duration) => {
2319
- intervalRef.current = setInterval(listener, duration);
2320
- }, []);
2321
- const clear = useCallback(() => {
2322
- if (intervalRef.current !== null) {
2323
- clearInterval(intervalRef.current);
2324
- intervalRef.current = null;
2325
- }
2326
- }, []);
2327
- return [set, clear];
2328
- }
2329
-
2330
- function useLatestValue(value, dependencies) {
2331
- if (dependencies === void 0) {
2332
- dependencies = [value];
2333
- }
2334
-
2335
- const valueRef = useRef(value);
2336
- useIsomorphicLayoutEffect$1(() => {
2337
- if (valueRef.current !== value) {
2338
- valueRef.current = value;
2339
- }
2340
- }, dependencies);
2341
- return valueRef;
2342
- }
2343
-
2344
- function useLazyMemo(callback, dependencies) {
2345
- const valueRef = useRef();
2346
- return useMemo$1(() => {
2347
- const newValue = callback(valueRef.current);
2348
- valueRef.current = newValue;
2349
- return newValue;
2350
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
2351
- [...dependencies]);
2352
- }
2353
-
2354
- function useNodeRef(onChange) {
2355
- const onChangeHandler = useEvent$1(onChange);
2356
- const node = useRef(null);
2357
- const setNodeRef = useCallback(element => {
2358
- if (element !== node.current) {
2359
- onChangeHandler == null ? void 0 : onChangeHandler(element, node.current);
2360
- }
2361
-
2362
- node.current = element;
2363
- }, //eslint-disable-next-line
2364
- []);
2365
- return [node, setNodeRef];
2366
- }
2367
-
2368
- function usePrevious(value) {
2369
- const ref = useRef();
2370
- useEffect(() => {
2371
- ref.current = value;
2372
- }, [value]);
2373
- return ref.current;
2374
- }
2375
-
2376
- let ids = {};
2377
- function useUniqueId(prefix, value) {
2378
- return useMemo$1(() => {
2379
- if (value) {
2380
- return value;
2381
- }
2382
-
2383
- const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
2384
- ids[prefix] = id;
2385
- return prefix + "-" + id;
2386
- }, [prefix, value]);
2387
- }
2388
-
2389
- function createAdjustmentFn(modifier) {
2390
- return function (object) {
2391
- for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2392
- adjustments[_key - 1] = arguments[_key];
2393
- }
2394
-
2395
- return adjustments.reduce((accumulator, adjustment) => {
2396
- const entries = Object.entries(adjustment);
2397
-
2398
- for (const [key, valueAdjustment] of entries) {
2399
- const value = accumulator[key];
2400
-
2401
- if (value != null) {
2402
- accumulator[key] = value + modifier * valueAdjustment;
2403
- }
2404
- }
2405
-
2406
- return accumulator;
2407
- }, { ...object
2408
- });
2409
- };
2410
- }
2411
-
2412
- const add = /*#__PURE__*/createAdjustmentFn(1);
2413
- const subtract = /*#__PURE__*/createAdjustmentFn(-1);
2414
-
2415
- function hasViewportRelativeCoordinates(event) {
2416
- return 'clientX' in event && 'clientY' in event;
2417
- }
2418
-
2419
- function isKeyboardEvent(event) {
2420
- if (!event) {
2421
- return false;
2422
- }
2423
-
2424
- const {
2425
- KeyboardEvent
2426
- } = getWindow(event.target);
2427
- return KeyboardEvent && event instanceof KeyboardEvent;
2428
- }
2429
-
2430
- function isTouchEvent(event) {
2431
- if (!event) {
2432
- return false;
2433
- }
2434
-
2435
- const {
2436
- TouchEvent
2437
- } = getWindow(event.target);
2438
- return TouchEvent && event instanceof TouchEvent;
2439
- }
2440
-
2441
- /**
2442
- * Returns the normalized x and y coordinates for mouse and touch events.
2443
- */
2444
-
2445
- function getEventCoordinates(event) {
2446
- if (isTouchEvent(event)) {
2447
- if (event.touches && event.touches.length) {
2448
- const {
2449
- clientX: x,
2450
- clientY: y
2451
- } = event.touches[0];
2452
- return {
2453
- x,
2454
- y
2455
- };
2456
- } else if (event.changedTouches && event.changedTouches.length) {
2457
- const {
2458
- clientX: x,
2459
- clientY: y
2460
- } = event.changedTouches[0];
2461
- return {
2462
- x,
2463
- y
2464
- };
2465
- }
2466
- }
2467
-
2468
- if (hasViewportRelativeCoordinates(event)) {
2469
- return {
2470
- x: event.clientX,
2471
- y: event.clientY
2472
- };
2473
- }
2474
-
2475
- return null;
2476
- }
2477
-
2478
- const CSS = /*#__PURE__*/Object.freeze({
2479
- Translate: {
2480
- toString(transform) {
2481
- if (!transform) {
2482
- return;
2483
- }
2484
-
2485
- const {
2486
- x,
2487
- y
2488
- } = transform;
2489
- return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
2490
- }
2491
-
2492
- },
2493
- Scale: {
2494
- toString(transform) {
2495
- if (!transform) {
2496
- return;
2497
- }
2498
-
2499
- const {
2500
- scaleX,
2501
- scaleY
2502
- } = transform;
2503
- return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
2504
- }
2505
-
2506
- },
2507
- Transform: {
2508
- toString(transform) {
2509
- if (!transform) {
2510
- return;
2511
- }
2512
-
2513
- return [CSS.Translate.toString(transform), CSS.Scale.toString(transform)].join(' ');
2514
- }
2515
-
2516
- },
2517
- Transition: {
2518
- toString(_ref) {
2519
- let {
2520
- property,
2521
- duration,
2522
- easing
2523
- } = _ref;
2524
- return property + " " + duration + "ms " + easing;
2525
- }
2526
-
2527
- }
2528
- });
2529
-
2530
- const SELECTOR = 'a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]';
2531
- function findFirstFocusableNode(element) {
2532
- if (element.matches(SELECTOR)) {
2533
- return element;
2534
- }
2535
-
2536
- return element.querySelector(SELECTOR);
2537
- }
2538
-
2539
- const hiddenStyles = {
2540
- display: 'none'
2541
- };
2542
- function HiddenText(_ref) {
2543
- let {
2544
- id,
2545
- value
2546
- } = _ref;
2547
- return React__default.createElement("div", {
2548
- id: id,
2549
- style: hiddenStyles
2550
- }, value);
2551
- }
2552
-
2553
- function LiveRegion(_ref) {
2554
- let {
2555
- id,
2556
- announcement,
2557
- ariaLiveType = "assertive"
2558
- } = _ref;
2559
- // Hide element visually but keep it readable by screen readers
2560
- const visuallyHidden = {
2561
- position: 'fixed',
2562
- top: 0,
2563
- left: 0,
2564
- width: 1,
2565
- height: 1,
2566
- margin: -1,
2567
- border: 0,
2568
- padding: 0,
2569
- overflow: 'hidden',
2570
- clip: 'rect(0 0 0 0)',
2571
- clipPath: 'inset(100%)',
2572
- whiteSpace: 'nowrap'
2573
- };
2574
- return React__default.createElement("div", {
2575
- id: id,
2576
- style: visuallyHidden,
2577
- role: "status",
2578
- "aria-live": ariaLiveType,
2579
- "aria-atomic": true
2580
- }, announcement);
2581
- }
2582
-
2583
- function useAnnouncement() {
2584
- const [announcement, setAnnouncement] = useState('');
2585
- const announce = useCallback(value => {
2586
- if (value != null) {
2587
- setAnnouncement(value);
2588
- }
2589
- }, []);
2590
- return {
2591
- announce,
2592
- announcement
2593
- };
2594
- }
2595
-
2596
- const DndMonitorContext = /*#__PURE__*/createContext(null);
2597
-
2598
- function useDndMonitor(listener) {
2599
- const registerListener = useContext(DndMonitorContext);
2600
- useEffect(() => {
2601
- if (!registerListener) {
2602
- throw new Error('useDndMonitor must be used within a children of <DndContext>');
2603
- }
2604
-
2605
- const unsubscribe = registerListener(listener);
2606
- return unsubscribe;
2607
- }, [listener, registerListener]);
2608
- }
2609
-
2610
- function useDndMonitorProvider() {
2611
- const [listeners] = useState(() => new Set());
2612
- const registerListener = useCallback(listener => {
2613
- listeners.add(listener);
2614
- return () => listeners.delete(listener);
2615
- }, [listeners]);
2616
- const dispatch = useCallback(_ref => {
2617
- let {
2618
- type,
2619
- event
2620
- } = _ref;
2621
- listeners.forEach(listener => {
2622
- var _listener$type;
2623
-
2624
- return (_listener$type = listener[type]) == null ? void 0 : _listener$type.call(listener, event);
2625
- });
2626
- }, [listeners]);
2627
- return [dispatch, registerListener];
2628
- }
2629
-
2630
- const defaultScreenReaderInstructions = {
2631
- draggable: "\n To pick up a draggable item, press the space bar.\n While dragging, use the arrow keys to move the item.\n Press space again to drop the item in its new position, or press escape to cancel.\n "
2632
- };
2633
- const defaultAnnouncements = {
2634
- onDragStart(_ref) {
2635
- let {
2636
- active
2637
- } = _ref;
2638
- return "Picked up draggable item " + active.id + ".";
2639
- },
2640
-
2641
- onDragOver(_ref2) {
2642
- let {
2643
- active,
2644
- over
2645
- } = _ref2;
2646
-
2647
- if (over) {
2648
- return "Draggable item " + active.id + " was moved over droppable area " + over.id + ".";
2649
- }
2650
-
2651
- return "Draggable item " + active.id + " is no longer over a droppable area.";
2652
- },
2653
-
2654
- onDragEnd(_ref3) {
2655
- let {
2656
- active,
2657
- over
2658
- } = _ref3;
2659
-
2660
- if (over) {
2661
- return "Draggable item " + active.id + " was dropped over droppable area " + over.id;
2662
- }
2663
-
2664
- return "Draggable item " + active.id + " was dropped.";
2665
- },
2666
-
2667
- onDragCancel(_ref4) {
2668
- let {
2669
- active
2670
- } = _ref4;
2671
- return "Dragging was cancelled. Draggable item " + active.id + " was dropped.";
2672
- }
2673
-
2674
- };
2675
-
2676
- function Accessibility(_ref) {
2677
- let {
2678
- announcements = defaultAnnouncements,
2679
- container,
2680
- hiddenTextDescribedById,
2681
- screenReaderInstructions = defaultScreenReaderInstructions
2682
- } = _ref;
2683
- const {
2684
- announce,
2685
- announcement
2686
- } = useAnnouncement();
2687
- const liveRegionId = useUniqueId("DndLiveRegion");
2688
- const [mounted, setMounted] = useState(false);
2689
- useEffect(() => {
2690
- setMounted(true);
2691
- }, []);
2692
- useDndMonitor(useMemo$1(() => ({
2693
- onDragStart(_ref2) {
2694
- let {
2695
- active
2696
- } = _ref2;
2697
- announce(announcements.onDragStart({
2698
- active
2699
- }));
2700
- },
2701
-
2702
- onDragMove(_ref3) {
2703
- let {
2704
- active,
2705
- over
2706
- } = _ref3;
2707
-
2708
- if (announcements.onDragMove) {
2709
- announce(announcements.onDragMove({
2710
- active,
2711
- over
2712
- }));
2713
- }
2714
- },
2715
-
2716
- onDragOver(_ref4) {
2717
- let {
2718
- active,
2719
- over
2720
- } = _ref4;
2721
- announce(announcements.onDragOver({
2722
- active,
2723
- over
2724
- }));
2725
- },
2726
-
2727
- onDragEnd(_ref5) {
2728
- let {
2729
- active,
2730
- over
2731
- } = _ref5;
2732
- announce(announcements.onDragEnd({
2733
- active,
2734
- over
2735
- }));
2736
- },
2737
-
2738
- onDragCancel(_ref6) {
2739
- let {
2740
- active,
2741
- over
2742
- } = _ref6;
2743
- announce(announcements.onDragCancel({
2744
- active,
2745
- over
2746
- }));
2747
- }
2748
-
2749
- }), [announce, announcements]));
2750
-
2751
- if (!mounted) {
2752
- return null;
2753
- }
2754
-
2755
- const markup = React__default.createElement(React__default.Fragment, null, React__default.createElement(HiddenText, {
2756
- id: hiddenTextDescribedById,
2757
- value: screenReaderInstructions.draggable
2758
- }), React__default.createElement(LiveRegion, {
2759
- id: liveRegionId,
2760
- announcement: announcement
2761
- }));
2762
- return container ? createPortal(markup, container) : markup;
2763
- }
2764
-
2765
- var Action;
2766
-
2767
- (function (Action) {
2768
- Action["DragStart"] = "dragStart";
2769
- Action["DragMove"] = "dragMove";
2770
- Action["DragEnd"] = "dragEnd";
2771
- Action["DragCancel"] = "dragCancel";
2772
- Action["DragOver"] = "dragOver";
2773
- Action["RegisterDroppable"] = "registerDroppable";
2774
- Action["SetDroppableDisabled"] = "setDroppableDisabled";
2775
- Action["UnregisterDroppable"] = "unregisterDroppable";
2776
- })(Action || (Action = {}));
2777
-
2778
- function noop$2() {}
2779
-
2780
- const defaultCoordinates = /*#__PURE__*/Object.freeze({
2781
- x: 0,
2782
- y: 0
2783
- });
2784
-
2785
- /**
2786
- * Returns the distance between two points
2787
- */
2788
- function distanceBetween(p1, p2) {
2789
- return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
2790
- }
2791
-
2792
- /**
2793
- * Sort collisions from smallest to greatest value
2794
- */
2795
- function sortCollisionsAsc(_ref, _ref2) {
2796
- let {
2797
- data: {
2798
- value: a
2799
- }
2800
- } = _ref;
2801
- let {
2802
- data: {
2803
- value: b
2804
- }
2805
- } = _ref2;
2806
- return a - b;
2807
- }
2808
- /**
2809
- * Sort collisions from greatest to smallest value
2810
- */
2811
-
2812
- function sortCollisionsDesc(_ref3, _ref4) {
2813
- let {
2814
- data: {
2815
- value: a
2816
- }
2817
- } = _ref3;
2818
- let {
2819
- data: {
2820
- value: b
2821
- }
2822
- } = _ref4;
2823
- return b - a;
2824
- }
2825
- function getFirstCollision(collisions, property) {
2826
- if (!collisions || collisions.length === 0) {
2827
- return null;
2828
- }
2829
-
2830
- const [firstCollision] = collisions;
2831
- return firstCollision[property] ;
2832
- }
2833
-
2834
- /**
2835
- * Returns the coordinates of the center of a given ClientRect
2836
- */
2837
-
2838
- function centerOfRectangle(rect, left, top) {
2839
- if (left === void 0) {
2840
- left = rect.left;
2841
- }
2842
-
2843
- if (top === void 0) {
2844
- top = rect.top;
2845
- }
2846
-
2847
- return {
2848
- x: left + rect.width * 0.5,
2849
- y: top + rect.height * 0.5
2850
- };
2851
- }
2852
- /**
2853
- * Returns the closest rectangles from an array of rectangles to the center of a given
2854
- * rectangle.
2855
- */
2856
-
2857
-
2858
- const closestCenter = _ref => {
2859
- let {
2860
- collisionRect,
2861
- droppableRects,
2862
- droppableContainers
2863
- } = _ref;
2864
- const centerRect = centerOfRectangle(collisionRect, collisionRect.left, collisionRect.top);
2865
- const collisions = [];
2866
-
2867
- for (const droppableContainer of droppableContainers) {
2868
- const {
2869
- id
2870
- } = droppableContainer;
2871
- const rect = droppableRects.get(id);
2872
-
2873
- if (rect) {
2874
- const distBetween = distanceBetween(centerOfRectangle(rect), centerRect);
2875
- collisions.push({
2876
- id,
2877
- data: {
2878
- droppableContainer,
2879
- value: distBetween
2880
- }
2881
- });
2882
- }
2883
- }
2884
-
2885
- return collisions.sort(sortCollisionsAsc);
2886
- };
2887
-
2888
- /**
2889
- * Returns the intersecting rectangle area between two rectangles
2890
- */
2891
-
2892
- function getIntersectionRatio(entry, target) {
2893
- const top = Math.max(target.top, entry.top);
2894
- const left = Math.max(target.left, entry.left);
2895
- const right = Math.min(target.left + target.width, entry.left + entry.width);
2896
- const bottom = Math.min(target.top + target.height, entry.top + entry.height);
2897
- const width = right - left;
2898
- const height = bottom - top;
2899
-
2900
- if (left < right && top < bottom) {
2901
- const targetArea = target.width * target.height;
2902
- const entryArea = entry.width * entry.height;
2903
- const intersectionArea = width * height;
2904
- const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea);
2905
- return Number(intersectionRatio.toFixed(4));
2906
- } // Rectangles do not overlap, or overlap has an area of zero (edge/corner overlap)
2907
-
2908
-
2909
- return 0;
2910
- }
2911
- /**
2912
- * Returns the rectangles that has the greatest intersection area with a given
2913
- * rectangle in an array of rectangles.
2914
- */
2915
-
2916
- const rectIntersection = _ref => {
2917
- let {
2918
- collisionRect,
2919
- droppableRects,
2920
- droppableContainers
2921
- } = _ref;
2922
- const collisions = [];
2923
-
2924
- for (const droppableContainer of droppableContainers) {
2925
- const {
2926
- id
2927
- } = droppableContainer;
2928
- const rect = droppableRects.get(id);
2929
-
2930
- if (rect) {
2931
- const intersectionRatio = getIntersectionRatio(rect, collisionRect);
2932
-
2933
- if (intersectionRatio > 0) {
2934
- collisions.push({
2935
- id,
2936
- data: {
2937
- droppableContainer,
2938
- value: intersectionRatio
2939
- }
2940
- });
2941
- }
2942
- }
2943
- }
2944
-
2945
- return collisions.sort(sortCollisionsDesc);
2946
- };
2947
-
2948
- function adjustScale(transform, rect1, rect2) {
2949
- return { ...transform,
2950
- scaleX: rect1 && rect2 ? rect1.width / rect2.width : 1,
2951
- scaleY: rect1 && rect2 ? rect1.height / rect2.height : 1
2952
- };
2953
- }
2954
-
2955
- function getRectDelta(rect1, rect2) {
2956
- return rect1 && rect2 ? {
2957
- x: rect1.left - rect2.left,
2958
- y: rect1.top - rect2.top
2959
- } : defaultCoordinates;
2960
- }
2961
-
2962
- function createRectAdjustmentFn(modifier) {
2963
- return function adjustClientRect(rect) {
2964
- for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
2965
- adjustments[_key - 1] = arguments[_key];
2966
- }
2967
-
2968
- return adjustments.reduce((acc, adjustment) => ({ ...acc,
2969
- top: acc.top + modifier * adjustment.y,
2970
- bottom: acc.bottom + modifier * adjustment.y,
2971
- left: acc.left + modifier * adjustment.x,
2972
- right: acc.right + modifier * adjustment.x
2973
- }), { ...rect
2974
- });
2975
- };
2976
- }
2977
- const getAdjustedRect = /*#__PURE__*/createRectAdjustmentFn(1);
2978
-
2979
- function parseTransform(transform) {
2980
- if (transform.startsWith('matrix3d(')) {
2981
- const transformArray = transform.slice(9, -1).split(/, /);
2982
- return {
2983
- x: +transformArray[12],
2984
- y: +transformArray[13],
2985
- scaleX: +transformArray[0],
2986
- scaleY: +transformArray[5]
2987
- };
2988
- } else if (transform.startsWith('matrix(')) {
2989
- const transformArray = transform.slice(7, -1).split(/, /);
2990
- return {
2991
- x: +transformArray[4],
2992
- y: +transformArray[5],
2993
- scaleX: +transformArray[0],
2994
- scaleY: +transformArray[3]
2995
- };
2996
- }
2997
-
2998
- return null;
2999
- }
3000
-
3001
- function inverseTransform(rect, transform, transformOrigin) {
3002
- const parsedTransform = parseTransform(transform);
3003
-
3004
- if (!parsedTransform) {
3005
- return rect;
3006
- }
3007
-
3008
- const {
3009
- scaleX,
3010
- scaleY,
3011
- x: translateX,
3012
- y: translateY
3013
- } = parsedTransform;
3014
- const x = rect.left - translateX - (1 - scaleX) * parseFloat(transformOrigin);
3015
- const y = rect.top - translateY - (1 - scaleY) * parseFloat(transformOrigin.slice(transformOrigin.indexOf(' ') + 1));
3016
- const w = scaleX ? rect.width / scaleX : rect.width;
3017
- const h = scaleY ? rect.height / scaleY : rect.height;
3018
- return {
3019
- width: w,
3020
- height: h,
3021
- top: y,
3022
- right: x + w,
3023
- bottom: y + h,
3024
- left: x
3025
- };
3026
- }
3027
-
3028
- const defaultOptions = {
3029
- ignoreTransform: false
3030
- };
3031
- /**
3032
- * Returns the bounding client rect of an element relative to the viewport.
3033
- */
3034
-
3035
- function getClientRect(element, options) {
3036
- if (options === void 0) {
3037
- options = defaultOptions;
3038
- }
3039
-
3040
- let rect = element.getBoundingClientRect();
3041
-
3042
- if (options.ignoreTransform) {
3043
- const {
3044
- transform,
3045
- transformOrigin
3046
- } = getWindow(element).getComputedStyle(element);
3047
-
3048
- if (transform) {
3049
- rect = inverseTransform(rect, transform, transformOrigin);
3050
- }
3051
- }
3052
-
3053
- const {
3054
- top,
3055
- left,
3056
- width,
3057
- height,
3058
- bottom,
3059
- right
3060
- } = rect;
3061
- return {
3062
- top,
3063
- left,
3064
- width,
3065
- height,
3066
- bottom,
3067
- right
3068
- };
3069
- }
3070
- /**
3071
- * Returns the bounding client rect of an element relative to the viewport.
3072
- *
3073
- * @remarks
3074
- * The ClientRect returned by this method does not take into account transforms
3075
- * applied to the element it measures.
3076
- *
3077
- */
3078
-
3079
- function getTransformAgnosticClientRect(element) {
3080
- return getClientRect(element, {
3081
- ignoreTransform: true
3082
- });
3083
- }
3084
-
3085
- function getWindowClientRect(element) {
3086
- const width = element.innerWidth;
3087
- const height = element.innerHeight;
3088
- return {
3089
- top: 0,
3090
- left: 0,
3091
- right: width,
3092
- bottom: height,
3093
- width,
3094
- height
3095
- };
3096
- }
3097
-
3098
- function isFixed(node, computedStyle) {
3099
- if (computedStyle === void 0) {
3100
- computedStyle = getWindow(node).getComputedStyle(node);
3101
- }
3102
-
3103
- return computedStyle.position === 'fixed';
3104
- }
3105
-
3106
- function isScrollable(element, computedStyle) {
3107
- if (computedStyle === void 0) {
3108
- computedStyle = getWindow(element).getComputedStyle(element);
3109
- }
3110
-
3111
- const overflowRegex = /(auto|scroll|overlay)/;
3112
- const properties = ['overflow', 'overflowX', 'overflowY'];
3113
- return properties.some(property => {
3114
- const value = computedStyle[property];
3115
- return typeof value === 'string' ? overflowRegex.test(value) : false;
3116
- });
3117
- }
3118
-
3119
- function getScrollableAncestors(element, limit) {
3120
- const scrollParents = [];
3121
-
3122
- function findScrollableAncestors(node) {
3123
- if (limit != null && scrollParents.length >= limit) {
3124
- return scrollParents;
3125
- }
3126
-
3127
- if (!node) {
3128
- return scrollParents;
3129
- }
3130
-
3131
- if (isDocument(node) && node.scrollingElement != null && !scrollParents.includes(node.scrollingElement)) {
3132
- scrollParents.push(node.scrollingElement);
3133
- return scrollParents;
3134
- }
3135
-
3136
- if (!isHTMLElement(node) || isSVGElement(node)) {
3137
- return scrollParents;
3138
- }
3139
-
3140
- if (scrollParents.includes(node)) {
3141
- return scrollParents;
3142
- }
3143
-
3144
- const computedStyle = getWindow(element).getComputedStyle(node);
3145
-
3146
- if (node !== element) {
3147
- if (isScrollable(node, computedStyle)) {
3148
- scrollParents.push(node);
3149
- }
3150
- }
3151
-
3152
- if (isFixed(node, computedStyle)) {
3153
- return scrollParents;
3154
- }
3155
-
3156
- return findScrollableAncestors(node.parentNode);
3157
- }
3158
-
3159
- if (!element) {
3160
- return scrollParents;
3161
- }
3162
-
3163
- return findScrollableAncestors(element);
3164
- }
3165
- function getFirstScrollableAncestor(node) {
3166
- const [firstScrollableAncestor] = getScrollableAncestors(node, 1);
3167
- return firstScrollableAncestor != null ? firstScrollableAncestor : null;
3168
- }
3169
-
3170
- function getScrollableElement(element) {
3171
- if (!canUseDOM || !element) {
3172
- return null;
3173
- }
3174
-
3175
- if (isWindow(element)) {
3176
- return element;
3177
- }
3178
-
3179
- if (!isNode(element)) {
3180
- return null;
3181
- }
3182
-
3183
- if (isDocument(element) || element === getOwnerDocument(element).scrollingElement) {
3184
- return window;
3185
- }
3186
-
3187
- if (isHTMLElement(element)) {
3188
- return element;
3189
- }
3190
-
3191
- return null;
3192
- }
3193
-
3194
- function getScrollXCoordinate(element) {
3195
- if (isWindow(element)) {
3196
- return element.scrollX;
3197
- }
3198
-
3199
- return element.scrollLeft;
3200
- }
3201
- function getScrollYCoordinate(element) {
3202
- if (isWindow(element)) {
3203
- return element.scrollY;
3204
- }
3205
-
3206
- return element.scrollTop;
3207
- }
3208
- function getScrollCoordinates(element) {
3209
- return {
3210
- x: getScrollXCoordinate(element),
3211
- y: getScrollYCoordinate(element)
3212
- };
3213
- }
3214
-
3215
- var Direction;
3216
-
3217
- (function (Direction) {
3218
- Direction[Direction["Forward"] = 1] = "Forward";
3219
- Direction[Direction["Backward"] = -1] = "Backward";
3220
- })(Direction || (Direction = {}));
3221
-
3222
- function isDocumentScrollingElement(element) {
3223
- if (!canUseDOM || !element) {
3224
- return false;
3225
- }
3226
-
3227
- return element === document.scrollingElement;
3228
- }
3229
-
3230
- function getScrollPosition(scrollingContainer) {
3231
- const minScroll = {
3232
- x: 0,
3233
- y: 0
3234
- };
3235
- const dimensions = isDocumentScrollingElement(scrollingContainer) ? {
3236
- height: window.innerHeight,
3237
- width: window.innerWidth
3238
- } : {
3239
- height: scrollingContainer.clientHeight,
3240
- width: scrollingContainer.clientWidth
3241
- };
3242
- const maxScroll = {
3243
- x: scrollingContainer.scrollWidth - dimensions.width,
3244
- y: scrollingContainer.scrollHeight - dimensions.height
3245
- };
3246
- const isTop = scrollingContainer.scrollTop <= minScroll.y;
3247
- const isLeft = scrollingContainer.scrollLeft <= minScroll.x;
3248
- const isBottom = scrollingContainer.scrollTop >= maxScroll.y;
3249
- const isRight = scrollingContainer.scrollLeft >= maxScroll.x;
3250
- return {
3251
- isTop,
3252
- isLeft,
3253
- isBottom,
3254
- isRight,
3255
- maxScroll,
3256
- minScroll
3257
- };
3258
- }
3259
-
3260
- const defaultThreshold = {
3261
- x: 0.2,
3262
- y: 0.2
3263
- };
3264
- function getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, _ref, acceleration, thresholdPercentage) {
3265
- let {
3266
- top,
3267
- left,
3268
- right,
3269
- bottom
3270
- } = _ref;
3271
-
3272
- if (acceleration === void 0) {
3273
- acceleration = 10;
3274
- }
3275
-
3276
- if (thresholdPercentage === void 0) {
3277
- thresholdPercentage = defaultThreshold;
3278
- }
3279
-
3280
- const {
3281
- isTop,
3282
- isBottom,
3283
- isLeft,
3284
- isRight
3285
- } = getScrollPosition(scrollContainer);
3286
- const direction = {
3287
- x: 0,
3288
- y: 0
3289
- };
3290
- const speed = {
3291
- x: 0,
3292
- y: 0
3293
- };
3294
- const threshold = {
3295
- height: scrollContainerRect.height * thresholdPercentage.y,
3296
- width: scrollContainerRect.width * thresholdPercentage.x
3297
- };
3298
-
3299
- if (!isTop && top <= scrollContainerRect.top + threshold.height) {
3300
- // Scroll Up
3301
- direction.y = Direction.Backward;
3302
- speed.y = acceleration * Math.abs((scrollContainerRect.top + threshold.height - top) / threshold.height);
3303
- } else if (!isBottom && bottom >= scrollContainerRect.bottom - threshold.height) {
3304
- // Scroll Down
3305
- direction.y = Direction.Forward;
3306
- speed.y = acceleration * Math.abs((scrollContainerRect.bottom - threshold.height - bottom) / threshold.height);
3307
- }
3308
-
3309
- if (!isRight && right >= scrollContainerRect.right - threshold.width) {
3310
- // Scroll Right
3311
- direction.x = Direction.Forward;
3312
- speed.x = acceleration * Math.abs((scrollContainerRect.right - threshold.width - right) / threshold.width);
3313
- } else if (!isLeft && left <= scrollContainerRect.left + threshold.width) {
3314
- // Scroll Left
3315
- direction.x = Direction.Backward;
3316
- speed.x = acceleration * Math.abs((scrollContainerRect.left + threshold.width - left) / threshold.width);
3317
- }
3318
-
3319
- return {
3320
- direction,
3321
- speed
3322
- };
3323
- }
3324
-
3325
- function getScrollElementRect(element) {
3326
- if (element === document.scrollingElement) {
3327
- const {
3328
- innerWidth,
3329
- innerHeight
3330
- } = window;
3331
- return {
3332
- top: 0,
3333
- left: 0,
3334
- right: innerWidth,
3335
- bottom: innerHeight,
3336
- width: innerWidth,
3337
- height: innerHeight
3338
- };
3339
- }
3340
-
3341
- const {
3342
- top,
3343
- left,
3344
- right,
3345
- bottom
3346
- } = element.getBoundingClientRect();
3347
- return {
3348
- top,
3349
- left,
3350
- right,
3351
- bottom,
3352
- width: element.clientWidth,
3353
- height: element.clientHeight
3354
- };
3355
- }
3356
-
3357
- function getScrollOffsets(scrollableAncestors) {
3358
- return scrollableAncestors.reduce((acc, node) => {
3359
- return add(acc, getScrollCoordinates(node));
3360
- }, defaultCoordinates);
3361
- }
3362
- function getScrollXOffset(scrollableAncestors) {
3363
- return scrollableAncestors.reduce((acc, node) => {
3364
- return acc + getScrollXCoordinate(node);
3365
- }, 0);
3366
- }
3367
- function getScrollYOffset(scrollableAncestors) {
3368
- return scrollableAncestors.reduce((acc, node) => {
3369
- return acc + getScrollYCoordinate(node);
3370
- }, 0);
3371
- }
3372
-
3373
- function scrollIntoViewIfNeeded(element, measure) {
3374
- if (measure === void 0) {
3375
- measure = getClientRect;
3376
- }
3377
-
3378
- if (!element) {
3379
- return;
3380
- }
3381
-
3382
- const {
3383
- top,
3384
- left,
3385
- bottom,
3386
- right
3387
- } = measure(element);
3388
- const firstScrollableAncestor = getFirstScrollableAncestor(element);
3389
-
3390
- if (!firstScrollableAncestor) {
3391
- return;
3392
- }
3393
-
3394
- if (bottom <= 0 || right <= 0 || top >= window.innerHeight || left >= window.innerWidth) {
3395
- element.scrollIntoView({
3396
- block: 'center',
3397
- inline: 'center'
3398
- });
3399
- }
3400
- }
3401
-
3402
- const properties = [['x', ['left', 'right'], getScrollXOffset], ['y', ['top', 'bottom'], getScrollYOffset]];
3403
- class Rect {
3404
- constructor(rect, element) {
3405
- this.rect = void 0;
3406
- this.width = void 0;
3407
- this.height = void 0;
3408
- this.top = void 0;
3409
- this.bottom = void 0;
3410
- this.right = void 0;
3411
- this.left = void 0;
3412
- const scrollableAncestors = getScrollableAncestors(element);
3413
- const scrollOffsets = getScrollOffsets(scrollableAncestors);
3414
- this.rect = { ...rect
3415
- };
3416
- this.width = rect.width;
3417
- this.height = rect.height;
3418
-
3419
- for (const [axis, keys, getScrollOffset] of properties) {
3420
- for (const key of keys) {
3421
- Object.defineProperty(this, key, {
3422
- get: () => {
3423
- const currentOffsets = getScrollOffset(scrollableAncestors);
3424
- const scrollOffsetsDeltla = scrollOffsets[axis] - currentOffsets;
3425
- return this.rect[key] + scrollOffsetsDeltla;
3426
- },
3427
- enumerable: true
3428
- });
3429
- }
3430
- }
3431
-
3432
- Object.defineProperty(this, 'rect', {
3433
- enumerable: false
3434
- });
3435
- }
3436
-
3437
- }
3438
-
3439
- class Listeners {
3440
- constructor(target) {
3441
- this.target = void 0;
3442
- this.listeners = [];
3443
-
3444
- this.removeAll = () => {
3445
- this.listeners.forEach(listener => {
3446
- var _this$target;
3447
-
3448
- return (_this$target = this.target) == null ? void 0 : _this$target.removeEventListener(...listener);
3449
- });
3450
- };
3451
-
3452
- this.target = target;
3453
- }
3454
-
3455
- add(eventName, handler, options) {
3456
- var _this$target2;
3457
-
3458
- (_this$target2 = this.target) == null ? void 0 : _this$target2.addEventListener(eventName, handler, options);
3459
- this.listeners.push([eventName, handler, options]);
3460
- }
3461
-
3462
- }
3463
-
3464
- function getEventListenerTarget(target) {
3465
- // If the `event.target` element is removed from the document events will still be targeted
3466
- // at it, and hence won't always bubble up to the window or document anymore.
3467
- // If there is any risk of an element being removed while it is being dragged,
3468
- // the best practice is to attach the event listeners directly to the target.
3469
- // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
3470
- const {
3471
- EventTarget
3472
- } = getWindow(target);
3473
- return target instanceof EventTarget ? target : getOwnerDocument(target);
3474
- }
3475
-
3476
- function hasExceededDistance(delta, measurement) {
3477
- const dx = Math.abs(delta.x);
3478
- const dy = Math.abs(delta.y);
3479
-
3480
- if (typeof measurement === 'number') {
3481
- return Math.sqrt(dx ** 2 + dy ** 2) > measurement;
3482
- }
3483
-
3484
- if ('x' in measurement && 'y' in measurement) {
3485
- return dx > measurement.x && dy > measurement.y;
3486
- }
3487
-
3488
- if ('x' in measurement) {
3489
- return dx > measurement.x;
3490
- }
3491
-
3492
- if ('y' in measurement) {
3493
- return dy > measurement.y;
3494
- }
3495
-
3496
- return false;
3497
- }
3498
-
3499
- var EventName;
3500
-
3501
- (function (EventName) {
3502
- EventName["Click"] = "click";
3503
- EventName["DragStart"] = "dragstart";
3504
- EventName["Keydown"] = "keydown";
3505
- EventName["ContextMenu"] = "contextmenu";
3506
- EventName["Resize"] = "resize";
3507
- EventName["SelectionChange"] = "selectionchange";
3508
- EventName["VisibilityChange"] = "visibilitychange";
3509
- })(EventName || (EventName = {}));
3510
-
3511
- function preventDefault(event) {
3512
- event.preventDefault();
3513
- }
3514
- function stopPropagation(event) {
3515
- event.stopPropagation();
3516
- }
3517
-
3518
- var KeyboardCode;
3519
-
3520
- (function (KeyboardCode) {
3521
- KeyboardCode["Space"] = "Space";
3522
- KeyboardCode["Down"] = "ArrowDown";
3523
- KeyboardCode["Right"] = "ArrowRight";
3524
- KeyboardCode["Left"] = "ArrowLeft";
3525
- KeyboardCode["Up"] = "ArrowUp";
3526
- KeyboardCode["Esc"] = "Escape";
3527
- KeyboardCode["Enter"] = "Enter";
3528
- KeyboardCode["Tab"] = "Tab";
3529
- })(KeyboardCode || (KeyboardCode = {}));
3530
-
3531
- const defaultKeyboardCodes = {
3532
- start: [KeyboardCode.Space, KeyboardCode.Enter],
3533
- cancel: [KeyboardCode.Esc],
3534
- end: [KeyboardCode.Space, KeyboardCode.Enter, KeyboardCode.Tab]
3535
- };
3536
- const defaultKeyboardCoordinateGetter = (event, _ref) => {
3537
- let {
3538
- currentCoordinates
3539
- } = _ref;
3540
-
3541
- switch (event.code) {
3542
- case KeyboardCode.Right:
3543
- return { ...currentCoordinates,
3544
- x: currentCoordinates.x + 25
3545
- };
3546
-
3547
- case KeyboardCode.Left:
3548
- return { ...currentCoordinates,
3549
- x: currentCoordinates.x - 25
3550
- };
3551
-
3552
- case KeyboardCode.Down:
3553
- return { ...currentCoordinates,
3554
- y: currentCoordinates.y + 25
3555
- };
3556
-
3557
- case KeyboardCode.Up:
3558
- return { ...currentCoordinates,
3559
- y: currentCoordinates.y - 25
3560
- };
3561
- }
3562
-
3563
- return undefined;
3564
- };
3565
-
3566
- class KeyboardSensor {
3567
- constructor(props) {
3568
- this.props = void 0;
3569
- this.autoScrollEnabled = false;
3570
- this.referenceCoordinates = void 0;
3571
- this.listeners = void 0;
3572
- this.windowListeners = void 0;
3573
- this.props = props;
3574
- const {
3575
- event: {
3576
- target
3577
- }
3578
- } = props;
3579
- this.props = props;
3580
- this.listeners = new Listeners(getOwnerDocument(target));
3581
- this.windowListeners = new Listeners(getWindow(target));
3582
- this.handleKeyDown = this.handleKeyDown.bind(this);
3583
- this.handleCancel = this.handleCancel.bind(this);
3584
- this.attach();
3585
- }
3586
-
3587
- attach() {
3588
- this.handleStart();
3589
- this.windowListeners.add(EventName.Resize, this.handleCancel);
3590
- this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
3591
- setTimeout(() => this.listeners.add(EventName.Keydown, this.handleKeyDown));
3592
- }
3593
-
3594
- handleStart() {
3595
- const {
3596
- activeNode,
3597
- onStart
3598
- } = this.props;
3599
- const node = activeNode.node.current;
3600
-
3601
- if (node) {
3602
- scrollIntoViewIfNeeded(node);
3603
- }
3604
-
3605
- onStart(defaultCoordinates);
3606
- }
3607
-
3608
- handleKeyDown(event) {
3609
- if (isKeyboardEvent(event)) {
3610
- const {
3611
- active,
3612
- context,
3613
- options
3614
- } = this.props;
3615
- const {
3616
- keyboardCodes = defaultKeyboardCodes,
3617
- coordinateGetter = defaultKeyboardCoordinateGetter,
3618
- scrollBehavior = 'smooth'
3619
- } = options;
3620
- const {
3621
- code
3622
- } = event;
3623
-
3624
- if (keyboardCodes.end.includes(code)) {
3625
- this.handleEnd(event);
3626
- return;
3627
- }
3628
-
3629
- if (keyboardCodes.cancel.includes(code)) {
3630
- this.handleCancel(event);
3631
- return;
3632
- }
3633
-
3634
- const {
3635
- collisionRect
3636
- } = context.current;
3637
- const currentCoordinates = collisionRect ? {
3638
- x: collisionRect.left,
3639
- y: collisionRect.top
3640
- } : defaultCoordinates;
3641
-
3642
- if (!this.referenceCoordinates) {
3643
- this.referenceCoordinates = currentCoordinates;
3644
- }
3645
-
3646
- const newCoordinates = coordinateGetter(event, {
3647
- active,
3648
- context: context.current,
3649
- currentCoordinates
3650
- });
3651
-
3652
- if (newCoordinates) {
3653
- const coordinatesDelta = subtract(newCoordinates, currentCoordinates);
3654
- const scrollDelta = {
3655
- x: 0,
3656
- y: 0
3657
- };
3658
- const {
3659
- scrollableAncestors
3660
- } = context.current;
3661
-
3662
- for (const scrollContainer of scrollableAncestors) {
3663
- const direction = event.code;
3664
- const {
3665
- isTop,
3666
- isRight,
3667
- isLeft,
3668
- isBottom,
3669
- maxScroll,
3670
- minScroll
3671
- } = getScrollPosition(scrollContainer);
3672
- const scrollElementRect = getScrollElementRect(scrollContainer);
3673
- const clampedCoordinates = {
3674
- x: Math.min(direction === KeyboardCode.Right ? scrollElementRect.right - scrollElementRect.width / 2 : scrollElementRect.right, Math.max(direction === KeyboardCode.Right ? scrollElementRect.left : scrollElementRect.left + scrollElementRect.width / 2, newCoordinates.x)),
3675
- y: Math.min(direction === KeyboardCode.Down ? scrollElementRect.bottom - scrollElementRect.height / 2 : scrollElementRect.bottom, Math.max(direction === KeyboardCode.Down ? scrollElementRect.top : scrollElementRect.top + scrollElementRect.height / 2, newCoordinates.y))
3676
- };
3677
- const canScrollX = direction === KeyboardCode.Right && !isRight || direction === KeyboardCode.Left && !isLeft;
3678
- const canScrollY = direction === KeyboardCode.Down && !isBottom || direction === KeyboardCode.Up && !isTop;
3679
-
3680
- if (canScrollX && clampedCoordinates.x !== newCoordinates.x) {
3681
- const newScrollCoordinates = scrollContainer.scrollLeft + coordinatesDelta.x;
3682
- const canScrollToNewCoordinates = direction === KeyboardCode.Right && newScrollCoordinates <= maxScroll.x || direction === KeyboardCode.Left && newScrollCoordinates >= minScroll.x;
3683
-
3684
- if (canScrollToNewCoordinates && !coordinatesDelta.y) {
3685
- // We don't need to update coordinates, the scroll adjustment alone will trigger
3686
- // logic to auto-detect the new container we are over
3687
- scrollContainer.scrollTo({
3688
- left: newScrollCoordinates,
3689
- behavior: scrollBehavior
3690
- });
3691
- return;
3692
- }
3693
-
3694
- if (canScrollToNewCoordinates) {
3695
- scrollDelta.x = scrollContainer.scrollLeft - newScrollCoordinates;
3696
- } else {
3697
- scrollDelta.x = direction === KeyboardCode.Right ? scrollContainer.scrollLeft - maxScroll.x : scrollContainer.scrollLeft - minScroll.x;
3698
- }
3699
-
3700
- if (scrollDelta.x) {
3701
- scrollContainer.scrollBy({
3702
- left: -scrollDelta.x,
3703
- behavior: scrollBehavior
3704
- });
3705
- }
3706
-
3707
- break;
3708
- } else if (canScrollY && clampedCoordinates.y !== newCoordinates.y) {
3709
- const newScrollCoordinates = scrollContainer.scrollTop + coordinatesDelta.y;
3710
- const canScrollToNewCoordinates = direction === KeyboardCode.Down && newScrollCoordinates <= maxScroll.y || direction === KeyboardCode.Up && newScrollCoordinates >= minScroll.y;
3711
-
3712
- if (canScrollToNewCoordinates && !coordinatesDelta.x) {
3713
- // We don't need to update coordinates, the scroll adjustment alone will trigger
3714
- // logic to auto-detect the new container we are over
3715
- scrollContainer.scrollTo({
3716
- top: newScrollCoordinates,
3717
- behavior: scrollBehavior
3718
- });
3719
- return;
3720
- }
3721
-
3722
- if (canScrollToNewCoordinates) {
3723
- scrollDelta.y = scrollContainer.scrollTop - newScrollCoordinates;
3724
- } else {
3725
- scrollDelta.y = direction === KeyboardCode.Down ? scrollContainer.scrollTop - maxScroll.y : scrollContainer.scrollTop - minScroll.y;
3726
- }
3727
-
3728
- if (scrollDelta.y) {
3729
- scrollContainer.scrollBy({
3730
- top: -scrollDelta.y,
3731
- behavior: scrollBehavior
3732
- });
3733
- }
3734
-
3735
- break;
3736
- }
3737
- }
3738
-
3739
- this.handleMove(event, add(subtract(newCoordinates, this.referenceCoordinates), scrollDelta));
3740
- }
3741
- }
3742
- }
3743
-
3744
- handleMove(event, coordinates) {
3745
- const {
3746
- onMove
3747
- } = this.props;
3748
- event.preventDefault();
3749
- onMove(coordinates);
3750
- }
3751
-
3752
- handleEnd(event) {
3753
- const {
3754
- onEnd
3755
- } = this.props;
3756
- event.preventDefault();
3757
- this.detach();
3758
- onEnd();
3759
- }
3760
-
3761
- handleCancel(event) {
3762
- const {
3763
- onCancel
3764
- } = this.props;
3765
- event.preventDefault();
3766
- this.detach();
3767
- onCancel();
3768
- }
3769
-
3770
- detach() {
3771
- this.listeners.removeAll();
3772
- this.windowListeners.removeAll();
3773
- }
3774
-
3775
- }
3776
- KeyboardSensor.activators = [{
3777
- eventName: 'onKeyDown',
3778
- handler: (event, _ref, _ref2) => {
3779
- let {
3780
- keyboardCodes = defaultKeyboardCodes,
3781
- onActivation
3782
- } = _ref;
3783
- let {
3784
- active
3785
- } = _ref2;
3786
- const {
3787
- code
3788
- } = event.nativeEvent;
3789
-
3790
- if (keyboardCodes.start.includes(code)) {
3791
- const activator = active.activatorNode.current;
3792
-
3793
- if (activator && event.target !== activator) {
3794
- return false;
3795
- }
3796
-
3797
- event.preventDefault();
3798
- onActivation == null ? void 0 : onActivation({
3799
- event: event.nativeEvent
3800
- });
3801
- return true;
3802
- }
3803
-
3804
- return false;
3805
- }
3806
- }];
3807
-
3808
- function isDistanceConstraint(constraint) {
3809
- return Boolean(constraint && 'distance' in constraint);
3810
- }
3811
-
3812
- function isDelayConstraint(constraint) {
3813
- return Boolean(constraint && 'delay' in constraint);
3814
- }
3815
-
3816
- class AbstractPointerSensor {
3817
- constructor(props, events, listenerTarget) {
3818
- var _getEventCoordinates;
3819
-
3820
- if (listenerTarget === void 0) {
3821
- listenerTarget = getEventListenerTarget(props.event.target);
3822
- }
3823
-
3824
- this.props = void 0;
3825
- this.events = void 0;
3826
- this.autoScrollEnabled = true;
3827
- this.document = void 0;
3828
- this.activated = false;
3829
- this.initialCoordinates = void 0;
3830
- this.timeoutId = null;
3831
- this.listeners = void 0;
3832
- this.documentListeners = void 0;
3833
- this.windowListeners = void 0;
3834
- this.props = props;
3835
- this.events = events;
3836
- const {
3837
- event
3838
- } = props;
3839
- const {
3840
- target
3841
- } = event;
3842
- this.props = props;
3843
- this.events = events;
3844
- this.document = getOwnerDocument(target);
3845
- this.documentListeners = new Listeners(this.document);
3846
- this.listeners = new Listeners(listenerTarget);
3847
- this.windowListeners = new Listeners(getWindow(target));
3848
- this.initialCoordinates = (_getEventCoordinates = getEventCoordinates(event)) != null ? _getEventCoordinates : defaultCoordinates;
3849
- this.handleStart = this.handleStart.bind(this);
3850
- this.handleMove = this.handleMove.bind(this);
3851
- this.handleEnd = this.handleEnd.bind(this);
3852
- this.handleCancel = this.handleCancel.bind(this);
3853
- this.handleKeydown = this.handleKeydown.bind(this);
3854
- this.removeTextSelection = this.removeTextSelection.bind(this);
3855
- this.attach();
3856
- }
3857
-
3858
- attach() {
3859
- const {
3860
- events,
3861
- props: {
3862
- options: {
3863
- activationConstraint,
3864
- bypassActivationConstraint
3865
- }
3866
- }
3867
- } = this;
3868
- this.listeners.add(events.move.name, this.handleMove, {
3869
- passive: false
3870
- });
3871
- this.listeners.add(events.end.name, this.handleEnd);
3872
-
3873
- if (events.cancel) {
3874
- this.listeners.add(events.cancel.name, this.handleCancel);
3875
- }
3876
-
3877
- this.windowListeners.add(EventName.Resize, this.handleCancel);
3878
- this.windowListeners.add(EventName.DragStart, preventDefault);
3879
- this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
3880
- this.windowListeners.add(EventName.ContextMenu, preventDefault);
3881
- this.documentListeners.add(EventName.Keydown, this.handleKeydown);
3882
-
3883
- if (activationConstraint) {
3884
- if (bypassActivationConstraint != null && bypassActivationConstraint({
3885
- event: this.props.event,
3886
- activeNode: this.props.activeNode,
3887
- options: this.props.options
3888
- })) {
3889
- return this.handleStart();
3890
- }
3891
-
3892
- if (isDelayConstraint(activationConstraint)) {
3893
- this.timeoutId = setTimeout(this.handleStart, activationConstraint.delay);
3894
- this.handlePending(activationConstraint);
3895
- return;
3896
- }
3897
-
3898
- if (isDistanceConstraint(activationConstraint)) {
3899
- this.handlePending(activationConstraint);
3900
- return;
3901
- }
3902
- }
3903
-
3904
- this.handleStart();
3905
- }
3906
-
3907
- detach() {
3908
- this.listeners.removeAll();
3909
- this.windowListeners.removeAll(); // Wait until the next event loop before removing document listeners
3910
- // This is necessary because we listen for `click` and `selection` events on the document
3911
-
3912
- setTimeout(this.documentListeners.removeAll, 50);
3913
-
3914
- if (this.timeoutId !== null) {
3915
- clearTimeout(this.timeoutId);
3916
- this.timeoutId = null;
3917
- }
3918
- }
3919
-
3920
- handlePending(constraint, offset) {
3921
- const {
3922
- active,
3923
- onPending
3924
- } = this.props;
3925
- onPending(active, constraint, this.initialCoordinates, offset);
3926
- }
3927
-
3928
- handleStart() {
3929
- const {
3930
- initialCoordinates
3931
- } = this;
3932
- const {
3933
- onStart
3934
- } = this.props;
3935
-
3936
- if (initialCoordinates) {
3937
- this.activated = true; // Stop propagation of click events once activation constraints are met
3938
-
3939
- this.documentListeners.add(EventName.Click, stopPropagation, {
3940
- capture: true
3941
- }); // Remove any text selection from the document
3942
-
3943
- this.removeTextSelection(); // Prevent further text selection while dragging
3944
-
3945
- this.documentListeners.add(EventName.SelectionChange, this.removeTextSelection);
3946
- onStart(initialCoordinates);
3947
- }
3948
- }
3949
-
3950
- handleMove(event) {
3951
- var _getEventCoordinates2;
3952
-
3953
- const {
3954
- activated,
3955
- initialCoordinates,
3956
- props
3957
- } = this;
3958
- const {
3959
- onMove,
3960
- options: {
3961
- activationConstraint
3962
- }
3963
- } = props;
3964
-
3965
- if (!initialCoordinates) {
3966
- return;
3967
- }
3968
-
3969
- const coordinates = (_getEventCoordinates2 = getEventCoordinates(event)) != null ? _getEventCoordinates2 : defaultCoordinates;
3970
- const delta = subtract(initialCoordinates, coordinates); // Constraint validation
3971
-
3972
- if (!activated && activationConstraint) {
3973
- if (isDistanceConstraint(activationConstraint)) {
3974
- if (activationConstraint.tolerance != null && hasExceededDistance(delta, activationConstraint.tolerance)) {
3975
- return this.handleCancel();
3976
- }
3977
-
3978
- if (hasExceededDistance(delta, activationConstraint.distance)) {
3979
- return this.handleStart();
3980
- }
3981
- }
3982
-
3983
- if (isDelayConstraint(activationConstraint)) {
3984
- if (hasExceededDistance(delta, activationConstraint.tolerance)) {
3985
- return this.handleCancel();
3986
- }
3987
- }
3988
-
3989
- this.handlePending(activationConstraint, delta);
3990
- return;
3991
- }
3992
-
3993
- if (event.cancelable) {
3994
- event.preventDefault();
3995
- }
3996
-
3997
- onMove(coordinates);
3998
- }
3999
-
4000
- handleEnd() {
4001
- const {
4002
- onAbort,
4003
- onEnd
4004
- } = this.props;
4005
- this.detach();
4006
-
4007
- if (!this.activated) {
4008
- onAbort(this.props.active);
4009
- }
4010
-
4011
- onEnd();
4012
- }
4013
-
4014
- handleCancel() {
4015
- const {
4016
- onAbort,
4017
- onCancel
4018
- } = this.props;
4019
- this.detach();
4020
-
4021
- if (!this.activated) {
4022
- onAbort(this.props.active);
4023
- }
4024
-
4025
- onCancel();
4026
- }
4027
-
4028
- handleKeydown(event) {
4029
- if (event.code === KeyboardCode.Esc) {
4030
- this.handleCancel();
4031
- }
4032
- }
4033
-
4034
- removeTextSelection() {
4035
- var _this$document$getSel;
4036
-
4037
- (_this$document$getSel = this.document.getSelection()) == null ? void 0 : _this$document$getSel.removeAllRanges();
4038
- }
4039
-
4040
- }
4041
-
4042
- const events = {
4043
- cancel: {
4044
- name: 'pointercancel'
4045
- },
4046
- move: {
4047
- name: 'pointermove'
4048
- },
4049
- end: {
4050
- name: 'pointerup'
4051
- }
4052
- };
4053
- class PointerSensor extends AbstractPointerSensor {
4054
- constructor(props) {
4055
- const {
4056
- event
4057
- } = props; // Pointer events stop firing if the target is unmounted while dragging
4058
- // Therefore we attach listeners to the owner document instead
4059
-
4060
- const listenerTarget = getOwnerDocument(event.target);
4061
- super(props, events, listenerTarget);
4062
- }
4063
-
4064
- }
4065
- PointerSensor.activators = [{
4066
- eventName: 'onPointerDown',
4067
- handler: (_ref, _ref2) => {
4068
- let {
4069
- nativeEvent: event
4070
- } = _ref;
4071
- let {
4072
- onActivation
4073
- } = _ref2;
4074
-
4075
- if (!event.isPrimary || event.button !== 0) {
4076
- return false;
4077
- }
4078
-
4079
- onActivation == null ? void 0 : onActivation({
4080
- event
4081
- });
4082
- return true;
4083
- }
4084
- }];
4085
-
4086
- const events$1 = {
4087
- move: {
4088
- name: 'mousemove'
4089
- },
4090
- end: {
4091
- name: 'mouseup'
4092
- }
4093
- };
4094
- var MouseButton;
4095
-
4096
- (function (MouseButton) {
4097
- MouseButton[MouseButton["RightClick"] = 2] = "RightClick";
4098
- })(MouseButton || (MouseButton = {}));
4099
-
4100
- class MouseSensor extends AbstractPointerSensor {
4101
- constructor(props) {
4102
- super(props, events$1, getOwnerDocument(props.event.target));
4103
- }
4104
-
4105
- }
4106
- MouseSensor.activators = [{
4107
- eventName: 'onMouseDown',
4108
- handler: (_ref, _ref2) => {
4109
- let {
4110
- nativeEvent: event
4111
- } = _ref;
4112
- let {
4113
- onActivation
4114
- } = _ref2;
4115
-
4116
- if (event.button === MouseButton.RightClick) {
4117
- return false;
4118
- }
4119
-
4120
- onActivation == null ? void 0 : onActivation({
4121
- event
4122
- });
4123
- return true;
4124
- }
4125
- }];
4126
-
4127
- const events$2 = {
4128
- cancel: {
4129
- name: 'touchcancel'
4130
- },
4131
- move: {
4132
- name: 'touchmove'
4133
- },
4134
- end: {
4135
- name: 'touchend'
4136
- }
4137
- };
4138
- class TouchSensor extends AbstractPointerSensor {
4139
- constructor(props) {
4140
- super(props, events$2);
4141
- }
4142
-
4143
- static setup() {
4144
- // Adding a non-capture and non-passive `touchmove` listener in order
4145
- // to force `event.preventDefault()` calls to work in dynamically added
4146
- // touchmove event handlers. This is required for iOS Safari.
4147
- window.addEventListener(events$2.move.name, noop, {
4148
- capture: false,
4149
- passive: false
4150
- });
4151
- return function teardown() {
4152
- window.removeEventListener(events$2.move.name, noop);
4153
- }; // We create a new handler because the teardown function of another sensor
4154
- // could remove our event listener if we use a referentially equal listener.
4155
-
4156
- function noop() {}
4157
- }
4158
-
4159
- }
4160
- TouchSensor.activators = [{
4161
- eventName: 'onTouchStart',
4162
- handler: (_ref, _ref2) => {
4163
- let {
4164
- nativeEvent: event
4165
- } = _ref;
4166
- let {
4167
- onActivation
4168
- } = _ref2;
4169
- const {
4170
- touches
4171
- } = event;
4172
-
4173
- if (touches.length > 1) {
4174
- return false;
4175
- }
4176
-
4177
- onActivation == null ? void 0 : onActivation({
4178
- event
4179
- });
4180
- return true;
4181
- }
4182
- }];
4183
-
4184
- var AutoScrollActivator;
4185
-
4186
- (function (AutoScrollActivator) {
4187
- AutoScrollActivator[AutoScrollActivator["Pointer"] = 0] = "Pointer";
4188
- AutoScrollActivator[AutoScrollActivator["DraggableRect"] = 1] = "DraggableRect";
4189
- })(AutoScrollActivator || (AutoScrollActivator = {}));
4190
-
4191
- var TraversalOrder;
4192
-
4193
- (function (TraversalOrder) {
4194
- TraversalOrder[TraversalOrder["TreeOrder"] = 0] = "TreeOrder";
4195
- TraversalOrder[TraversalOrder["ReversedTreeOrder"] = 1] = "ReversedTreeOrder";
4196
- })(TraversalOrder || (TraversalOrder = {}));
4197
-
4198
- function useAutoScroller(_ref) {
4199
- let {
4200
- acceleration,
4201
- activator = AutoScrollActivator.Pointer,
4202
- canScroll,
4203
- draggingRect,
4204
- enabled,
4205
- interval = 5,
4206
- order = TraversalOrder.TreeOrder,
4207
- pointerCoordinates,
4208
- scrollableAncestors,
4209
- scrollableAncestorRects,
4210
- delta,
4211
- threshold
4212
- } = _ref;
4213
- const scrollIntent = useScrollIntent({
4214
- delta,
4215
- disabled: !enabled
4216
- });
4217
- const [setAutoScrollInterval, clearAutoScrollInterval] = useInterval();
4218
- const scrollSpeed = useRef({
4219
- x: 0,
4220
- y: 0
4221
- });
4222
- const scrollDirection = useRef({
4223
- x: 0,
4224
- y: 0
4225
- });
4226
- const rect = useMemo$1(() => {
4227
- switch (activator) {
4228
- case AutoScrollActivator.Pointer:
4229
- return pointerCoordinates ? {
4230
- top: pointerCoordinates.y,
4231
- bottom: pointerCoordinates.y,
4232
- left: pointerCoordinates.x,
4233
- right: pointerCoordinates.x
4234
- } : null;
4235
-
4236
- case AutoScrollActivator.DraggableRect:
4237
- return draggingRect;
4238
- }
4239
- }, [activator, draggingRect, pointerCoordinates]);
4240
- const scrollContainerRef = useRef(null);
4241
- const autoScroll = useCallback(() => {
4242
- const scrollContainer = scrollContainerRef.current;
4243
-
4244
- if (!scrollContainer) {
4245
- return;
4246
- }
4247
-
4248
- const scrollLeft = scrollSpeed.current.x * scrollDirection.current.x;
4249
- const scrollTop = scrollSpeed.current.y * scrollDirection.current.y;
4250
- scrollContainer.scrollBy(scrollLeft, scrollTop);
4251
- }, []);
4252
- const sortedScrollableAncestors = useMemo$1(() => order === TraversalOrder.TreeOrder ? [...scrollableAncestors].reverse() : scrollableAncestors, [order, scrollableAncestors]);
4253
- useEffect(() => {
4254
- if (!enabled || !scrollableAncestors.length || !rect) {
4255
- clearAutoScrollInterval();
4256
- return;
4257
- }
4258
-
4259
- for (const scrollContainer of sortedScrollableAncestors) {
4260
- if ((canScroll == null ? void 0 : canScroll(scrollContainer)) === false) {
4261
- continue;
4262
- }
4263
-
4264
- const index = scrollableAncestors.indexOf(scrollContainer);
4265
- const scrollContainerRect = scrollableAncestorRects[index];
4266
-
4267
- if (!scrollContainerRect) {
4268
- continue;
4269
- }
4270
-
4271
- const {
4272
- direction,
4273
- speed
4274
- } = getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, rect, acceleration, threshold);
4275
-
4276
- for (const axis of ['x', 'y']) {
4277
- if (!scrollIntent[axis][direction[axis]]) {
4278
- speed[axis] = 0;
4279
- direction[axis] = 0;
4280
- }
4281
- }
4282
-
4283
- if (speed.x > 0 || speed.y > 0) {
4284
- clearAutoScrollInterval();
4285
- scrollContainerRef.current = scrollContainer;
4286
- setAutoScrollInterval(autoScroll, interval);
4287
- scrollSpeed.current = speed;
4288
- scrollDirection.current = direction;
4289
- return;
4290
- }
4291
- }
4292
-
4293
- scrollSpeed.current = {
4294
- x: 0,
4295
- y: 0
4296
- };
4297
- scrollDirection.current = {
4298
- x: 0,
4299
- y: 0
4300
- };
4301
- clearAutoScrollInterval();
4302
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
4303
- [acceleration, autoScroll, canScroll, clearAutoScrollInterval, enabled, interval, // eslint-disable-next-line react-hooks/exhaustive-deps
4304
- JSON.stringify(rect), // eslint-disable-next-line react-hooks/exhaustive-deps
4305
- JSON.stringify(scrollIntent), setAutoScrollInterval, scrollableAncestors, sortedScrollableAncestors, scrollableAncestorRects, // eslint-disable-next-line react-hooks/exhaustive-deps
4306
- JSON.stringify(threshold)]);
4307
- }
4308
- const defaultScrollIntent = {
4309
- x: {
4310
- [Direction.Backward]: false,
4311
- [Direction.Forward]: false
4312
- },
4313
- y: {
4314
- [Direction.Backward]: false,
4315
- [Direction.Forward]: false
4316
- }
4317
- };
4318
-
4319
- function useScrollIntent(_ref2) {
4320
- let {
4321
- delta,
4322
- disabled
4323
- } = _ref2;
4324
- const previousDelta = usePrevious(delta);
4325
- return useLazyMemo(previousIntent => {
4326
- if (disabled || !previousDelta || !previousIntent) {
4327
- // Reset scroll intent tracking when auto-scrolling is disabled
4328
- return defaultScrollIntent;
4329
- }
4330
-
4331
- const direction = {
4332
- x: Math.sign(delta.x - previousDelta.x),
4333
- y: Math.sign(delta.y - previousDelta.y)
4334
- }; // Keep track of the user intent to scroll in each direction for both axis
4335
-
4336
- return {
4337
- x: {
4338
- [Direction.Backward]: previousIntent.x[Direction.Backward] || direction.x === -1,
4339
- [Direction.Forward]: previousIntent.x[Direction.Forward] || direction.x === 1
4340
- },
4341
- y: {
4342
- [Direction.Backward]: previousIntent.y[Direction.Backward] || direction.y === -1,
4343
- [Direction.Forward]: previousIntent.y[Direction.Forward] || direction.y === 1
4344
- }
4345
- };
4346
- }, [disabled, delta, previousDelta]);
4347
- }
4348
-
4349
- function useCachedNode(draggableNodes, id) {
4350
- const draggableNode = id != null ? draggableNodes.get(id) : undefined;
4351
- const node = draggableNode ? draggableNode.node.current : null;
4352
- return useLazyMemo(cachedNode => {
4353
- var _ref;
4354
-
4355
- if (id == null) {
4356
- return null;
4357
- } // In some cases, the draggable node can unmount while dragging
4358
- // This is the case for virtualized lists. In those situations,
4359
- // we fall back to the last known value for that node.
4360
-
4361
-
4362
- return (_ref = node != null ? node : cachedNode) != null ? _ref : null;
4363
- }, [node, id]);
4364
- }
4365
-
4366
- function useCombineActivators(sensors, getSyntheticHandler) {
4367
- return useMemo$1(() => sensors.reduce((accumulator, sensor) => {
4368
- const {
4369
- sensor: Sensor
4370
- } = sensor;
4371
- const sensorActivators = Sensor.activators.map(activator => ({
4372
- eventName: activator.eventName,
4373
- handler: getSyntheticHandler(activator.handler, sensor)
4374
- }));
4375
- return [...accumulator, ...sensorActivators];
4376
- }, []), [sensors, getSyntheticHandler]);
4377
- }
4378
-
4379
- var MeasuringStrategy;
4380
-
4381
- (function (MeasuringStrategy) {
4382
- MeasuringStrategy[MeasuringStrategy["Always"] = 0] = "Always";
4383
- MeasuringStrategy[MeasuringStrategy["BeforeDragging"] = 1] = "BeforeDragging";
4384
- MeasuringStrategy[MeasuringStrategy["WhileDragging"] = 2] = "WhileDragging";
4385
- })(MeasuringStrategy || (MeasuringStrategy = {}));
4386
-
4387
- var MeasuringFrequency;
4388
-
4389
- (function (MeasuringFrequency) {
4390
- MeasuringFrequency["Optimized"] = "optimized";
4391
- })(MeasuringFrequency || (MeasuringFrequency = {}));
4392
-
4393
- const defaultValue = /*#__PURE__*/new Map();
4394
- function useDroppableMeasuring(containers, _ref) {
4395
- let {
4396
- dragging,
4397
- dependencies,
4398
- config
4399
- } = _ref;
4400
- const [queue, setQueue] = useState(null);
4401
- const {
4402
- frequency,
4403
- measure,
4404
- strategy
4405
- } = config;
4406
- const containersRef = useRef(containers);
4407
- const disabled = isDisabled();
4408
- const disabledRef = useLatestValue(disabled);
4409
- const measureDroppableContainers = useCallback(function (ids) {
4410
- if (ids === void 0) {
4411
- ids = [];
4412
- }
4413
-
4414
- if (disabledRef.current) {
4415
- return;
4416
- }
4417
-
4418
- setQueue(value => {
4419
- if (value === null) {
4420
- return ids;
4421
- }
4422
-
4423
- return value.concat(ids.filter(id => !value.includes(id)));
4424
- });
4425
- }, [disabledRef]);
4426
- const timeoutId = useRef(null);
4427
- const droppableRects = useLazyMemo(previousValue => {
4428
- if (disabled && !dragging) {
4429
- return defaultValue;
4430
- }
4431
-
4432
- if (!previousValue || previousValue === defaultValue || containersRef.current !== containers || queue != null) {
4433
- const map = new Map();
4434
-
4435
- for (let container of containers) {
4436
- if (!container) {
4437
- continue;
4438
- }
4439
-
4440
- if (queue && queue.length > 0 && !queue.includes(container.id) && container.rect.current) {
4441
- // This container does not need to be re-measured
4442
- map.set(container.id, container.rect.current);
4443
- continue;
4444
- }
4445
-
4446
- const node = container.node.current;
4447
- const rect = node ? new Rect(measure(node), node) : null;
4448
- container.rect.current = rect;
4449
-
4450
- if (rect) {
4451
- map.set(container.id, rect);
4452
- }
4453
- }
4454
-
4455
- return map;
4456
- }
4457
-
4458
- return previousValue;
4459
- }, [containers, queue, dragging, disabled, measure]);
4460
- useEffect(() => {
4461
- containersRef.current = containers;
4462
- }, [containers]);
4463
- useEffect(() => {
4464
- if (disabled) {
4465
- return;
4466
- }
4467
-
4468
- measureDroppableContainers();
4469
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
4470
- [dragging, disabled]);
4471
- useEffect(() => {
4472
- if (queue && queue.length > 0) {
4473
- setQueue(null);
4474
- }
4475
- }, //eslint-disable-next-line react-hooks/exhaustive-deps
4476
- [JSON.stringify(queue)]);
4477
- useEffect(() => {
4478
- if (disabled || typeof frequency !== 'number' || timeoutId.current !== null) {
4479
- return;
4480
- }
4481
-
4482
- timeoutId.current = setTimeout(() => {
4483
- measureDroppableContainers();
4484
- timeoutId.current = null;
4485
- }, frequency);
4486
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
4487
- [frequency, disabled, measureDroppableContainers, ...dependencies]);
4488
- return {
4489
- droppableRects,
4490
- measureDroppableContainers,
4491
- measuringScheduled: queue != null
4492
- };
4493
-
4494
- function isDisabled() {
4495
- switch (strategy) {
4496
- case MeasuringStrategy.Always:
4497
- return false;
4498
-
4499
- case MeasuringStrategy.BeforeDragging:
4500
- return dragging;
4501
-
4502
- default:
4503
- return !dragging;
4504
- }
4505
- }
4506
- }
4507
-
4508
- function useInitialValue(value, computeFn) {
4509
- return useLazyMemo(previousValue => {
4510
- if (!value) {
4511
- return null;
4512
- }
4513
-
4514
- if (previousValue) {
4515
- return previousValue;
4516
- }
4517
-
4518
- return typeof computeFn === 'function' ? computeFn(value) : value;
4519
- }, [computeFn, value]);
4520
- }
4521
-
4522
- function useInitialRect(node, measure) {
4523
- return useInitialValue(node, measure);
4524
- }
4525
-
4526
- /**
4527
- * Returns a new MutationObserver instance.
4528
- * If `MutationObserver` is undefined in the execution environment, returns `undefined`.
4529
- */
4530
-
4531
- function useMutationObserver(_ref) {
4532
- let {
4533
- callback,
4534
- disabled
4535
- } = _ref;
4536
- const handleMutations = useEvent$1(callback);
4537
- const mutationObserver = useMemo$1(() => {
4538
- if (disabled || typeof window === 'undefined' || typeof window.MutationObserver === 'undefined') {
4539
- return undefined;
4540
- }
4541
-
4542
- const {
4543
- MutationObserver
4544
- } = window;
4545
- return new MutationObserver(handleMutations);
4546
- }, [handleMutations, disabled]);
4547
- useEffect(() => {
4548
- return () => mutationObserver == null ? void 0 : mutationObserver.disconnect();
4549
- }, [mutationObserver]);
4550
- return mutationObserver;
4551
- }
4552
-
4553
- /**
4554
- * Returns a new ResizeObserver instance bound to the `onResize` callback.
4555
- * If `ResizeObserver` is undefined in the execution environment, returns `undefined`.
4556
- */
4557
-
4558
- function useResizeObserver(_ref) {
4559
- let {
4560
- callback,
4561
- disabled
4562
- } = _ref;
4563
- const handleResize = useEvent$1(callback);
4564
- const resizeObserver = useMemo$1(() => {
4565
- if (disabled || typeof window === 'undefined' || typeof window.ResizeObserver === 'undefined') {
4566
- return undefined;
4567
- }
4568
-
4569
- const {
4570
- ResizeObserver
4571
- } = window;
4572
- return new ResizeObserver(handleResize);
4573
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
4574
- [disabled]);
4575
- useEffect(() => {
4576
- return () => resizeObserver == null ? void 0 : resizeObserver.disconnect();
4577
- }, [resizeObserver]);
4578
- return resizeObserver;
4579
- }
4580
-
4581
- function defaultMeasure(element) {
4582
- return new Rect(getClientRect(element), element);
4583
- }
4584
-
4585
- function useRect(element, measure, fallbackRect) {
4586
- if (measure === void 0) {
4587
- measure = defaultMeasure;
4588
- }
4589
-
4590
- const [rect, setRect] = useState(null);
4591
-
4592
- function measureRect() {
4593
- setRect(currentRect => {
4594
- if (!element) {
4595
- return null;
4596
- }
4597
-
4598
- if (element.isConnected === false) {
4599
- var _ref;
4600
-
4601
- // Fall back to last rect we measured if the element is
4602
- // no longer connected to the DOM.
4603
- return (_ref = currentRect != null ? currentRect : fallbackRect) != null ? _ref : null;
4604
- }
4605
-
4606
- const newRect = measure(element);
4607
-
4608
- if (JSON.stringify(currentRect) === JSON.stringify(newRect)) {
4609
- return currentRect;
4610
- }
4611
-
4612
- return newRect;
4613
- });
4614
- }
4615
-
4616
- const mutationObserver = useMutationObserver({
4617
- callback(records) {
4618
- if (!element) {
4619
- return;
4620
- }
4621
-
4622
- for (const record of records) {
4623
- const {
4624
- type,
4625
- target
4626
- } = record;
4627
-
4628
- if (type === 'childList' && target instanceof HTMLElement && target.contains(element)) {
4629
- measureRect();
4630
- break;
4631
- }
4632
- }
4633
- }
4634
-
4635
- });
4636
- const resizeObserver = useResizeObserver({
4637
- callback: measureRect
4638
- });
4639
- useIsomorphicLayoutEffect$1(() => {
4640
- measureRect();
4641
-
4642
- if (element) {
4643
- resizeObserver == null ? void 0 : resizeObserver.observe(element);
4644
- mutationObserver == null ? void 0 : mutationObserver.observe(document.body, {
4645
- childList: true,
4646
- subtree: true
4647
- });
4648
- } else {
4649
- resizeObserver == null ? void 0 : resizeObserver.disconnect();
4650
- mutationObserver == null ? void 0 : mutationObserver.disconnect();
4651
- }
4652
- }, [element]);
4653
- return rect;
4654
- }
4655
-
4656
- function useRectDelta(rect) {
4657
- const initialRect = useInitialValue(rect);
4658
- return getRectDelta(rect, initialRect);
4659
- }
4660
-
4661
- const defaultValue$1 = [];
4662
- function useScrollableAncestors(node) {
4663
- const previousNode = useRef(node);
4664
- const ancestors = useLazyMemo(previousValue => {
4665
- if (!node) {
4666
- return defaultValue$1;
4667
- }
4668
-
4669
- if (previousValue && previousValue !== defaultValue$1 && node && previousNode.current && node.parentNode === previousNode.current.parentNode) {
4670
- return previousValue;
4671
- }
4672
-
4673
- return getScrollableAncestors(node);
4674
- }, [node]);
4675
- useEffect(() => {
4676
- previousNode.current = node;
4677
- }, [node]);
4678
- return ancestors;
4679
- }
4680
-
4681
- function useScrollOffsets(elements) {
4682
- const [scrollCoordinates, setScrollCoordinates] = useState(null);
4683
- const prevElements = useRef(elements); // To-do: Throttle the handleScroll callback
4684
-
4685
- const handleScroll = useCallback(event => {
4686
- const scrollingElement = getScrollableElement(event.target);
4687
-
4688
- if (!scrollingElement) {
4689
- return;
4690
- }
4691
-
4692
- setScrollCoordinates(scrollCoordinates => {
4693
- if (!scrollCoordinates) {
4694
- return null;
4695
- }
4696
-
4697
- scrollCoordinates.set(scrollingElement, getScrollCoordinates(scrollingElement));
4698
- return new Map(scrollCoordinates);
4699
- });
4700
- }, []);
4701
- useEffect(() => {
4702
- const previousElements = prevElements.current;
4703
-
4704
- if (elements !== previousElements) {
4705
- cleanup(previousElements);
4706
- const entries = elements.map(element => {
4707
- const scrollableElement = getScrollableElement(element);
4708
-
4709
- if (scrollableElement) {
4710
- scrollableElement.addEventListener('scroll', handleScroll, {
4711
- passive: true
4712
- });
4713
- return [scrollableElement, getScrollCoordinates(scrollableElement)];
4714
- }
4715
-
4716
- return null;
4717
- }).filter(entry => entry != null);
4718
- setScrollCoordinates(entries.length ? new Map(entries) : null);
4719
- prevElements.current = elements;
4720
- }
4721
-
4722
- return () => {
4723
- cleanup(elements);
4724
- cleanup(previousElements);
4725
- };
4726
-
4727
- function cleanup(elements) {
4728
- elements.forEach(element => {
4729
- const scrollableElement = getScrollableElement(element);
4730
- scrollableElement == null ? void 0 : scrollableElement.removeEventListener('scroll', handleScroll);
4731
- });
4732
- }
4733
- }, [handleScroll, elements]);
4734
- return useMemo$1(() => {
4735
- if (elements.length) {
4736
- return scrollCoordinates ? Array.from(scrollCoordinates.values()).reduce((acc, coordinates) => add(acc, coordinates), defaultCoordinates) : getScrollOffsets(elements);
4737
- }
4738
-
4739
- return defaultCoordinates;
4740
- }, [elements, scrollCoordinates]);
4741
- }
4742
-
4743
- function useScrollOffsetsDelta(scrollOffsets, dependencies) {
4744
- if (dependencies === void 0) {
4745
- dependencies = [];
4746
- }
4747
-
4748
- const initialScrollOffsets = useRef(null);
4749
- useEffect(() => {
4750
- initialScrollOffsets.current = null;
4751
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
4752
- dependencies);
4753
- useEffect(() => {
4754
- const hasScrollOffsets = scrollOffsets !== defaultCoordinates;
4755
-
4756
- if (hasScrollOffsets && !initialScrollOffsets.current) {
4757
- initialScrollOffsets.current = scrollOffsets;
4758
- }
4759
-
4760
- if (!hasScrollOffsets && initialScrollOffsets.current) {
4761
- initialScrollOffsets.current = null;
4762
- }
4763
- }, [scrollOffsets]);
4764
- return initialScrollOffsets.current ? subtract(scrollOffsets, initialScrollOffsets.current) : defaultCoordinates;
4765
- }
4766
-
4767
- function useSensorSetup(sensors) {
4768
- useEffect(() => {
4769
- if (!canUseDOM) {
4770
- return;
4771
- }
4772
-
4773
- const teardownFns = sensors.map(_ref => {
4774
- let {
4775
- sensor
4776
- } = _ref;
4777
- return sensor.setup == null ? void 0 : sensor.setup();
4778
- });
4779
- return () => {
4780
- for (const teardown of teardownFns) {
4781
- teardown == null ? void 0 : teardown();
4782
- }
4783
- };
4784
- }, // TO-DO: Sensors length could theoretically change which would not be a valid dependency
4785
- // eslint-disable-next-line react-hooks/exhaustive-deps
4786
- sensors.map(_ref2 => {
4787
- let {
4788
- sensor
4789
- } = _ref2;
4790
- return sensor;
4791
- }));
4792
- }
4793
-
4794
- function useSyntheticListeners(listeners, id) {
4795
- return useMemo$1(() => {
4796
- return listeners.reduce((acc, _ref) => {
4797
- let {
4798
- eventName,
4799
- handler
4800
- } = _ref;
4801
-
4802
- acc[eventName] = event => {
4803
- handler(event, id);
4804
- };
4805
-
4806
- return acc;
4807
- }, {});
4808
- }, [listeners, id]);
4809
- }
4810
-
4811
- function useWindowRect(element) {
4812
- return useMemo$1(() => element ? getWindowClientRect(element) : null, [element]);
4813
- }
4814
-
4815
- const defaultValue$2 = [];
4816
- function useRects(elements, measure) {
4817
- if (measure === void 0) {
4818
- measure = getClientRect;
4819
- }
4820
-
4821
- const [firstElement] = elements;
4822
- const windowRect = useWindowRect(firstElement ? getWindow(firstElement) : null);
4823
- const [rects, setRects] = useState(defaultValue$2);
4824
-
4825
- function measureRects() {
4826
- setRects(() => {
4827
- if (!elements.length) {
4828
- return defaultValue$2;
4829
- }
4830
-
4831
- return elements.map(element => isDocumentScrollingElement(element) ? windowRect : new Rect(measure(element), element));
4832
- });
4833
- }
4834
-
4835
- const resizeObserver = useResizeObserver({
4836
- callback: measureRects
4837
- });
4838
- useIsomorphicLayoutEffect$1(() => {
4839
- resizeObserver == null ? void 0 : resizeObserver.disconnect();
4840
- measureRects();
4841
- elements.forEach(element => resizeObserver == null ? void 0 : resizeObserver.observe(element));
4842
- }, [elements]);
4843
- return rects;
4844
- }
4845
-
4846
- function getMeasurableNode(node) {
4847
- if (!node) {
4848
- return null;
4849
- }
4850
-
4851
- if (node.children.length > 1) {
4852
- return node;
4853
- }
4854
-
4855
- const firstChild = node.children[0];
4856
- return isHTMLElement(firstChild) ? firstChild : node;
4857
- }
4858
-
4859
- function useDragOverlayMeasuring(_ref) {
4860
- let {
4861
- measure
4862
- } = _ref;
4863
- const [rect, setRect] = useState(null);
4864
- const handleResize = useCallback(entries => {
4865
- for (const {
4866
- target
4867
- } of entries) {
4868
- if (isHTMLElement(target)) {
4869
- setRect(rect => {
4870
- const newRect = measure(target);
4871
- return rect ? { ...rect,
4872
- width: newRect.width,
4873
- height: newRect.height
4874
- } : newRect;
4875
- });
4876
- break;
4877
- }
4878
- }
4879
- }, [measure]);
4880
- const resizeObserver = useResizeObserver({
4881
- callback: handleResize
4882
- });
4883
- const handleNodeChange = useCallback(element => {
4884
- const node = getMeasurableNode(element);
4885
- resizeObserver == null ? void 0 : resizeObserver.disconnect();
4886
-
4887
- if (node) {
4888
- resizeObserver == null ? void 0 : resizeObserver.observe(node);
4889
- }
4890
-
4891
- setRect(node ? measure(node) : null);
4892
- }, [measure, resizeObserver]);
4893
- const [nodeRef, setRef] = useNodeRef(handleNodeChange);
4894
- return useMemo$1(() => ({
4895
- nodeRef,
4896
- rect,
4897
- setRef
4898
- }), [rect, nodeRef, setRef]);
4899
- }
4900
-
4901
- const defaultSensors = [{
4902
- sensor: PointerSensor,
4903
- options: {}
4904
- }, {
4905
- sensor: KeyboardSensor,
4906
- options: {}
4907
- }];
4908
- const defaultData = {
4909
- current: {}
4910
- };
4911
- const defaultMeasuringConfiguration = {
4912
- draggable: {
4913
- measure: getTransformAgnosticClientRect
4914
- },
4915
- droppable: {
4916
- measure: getTransformAgnosticClientRect,
4917
- strategy: MeasuringStrategy.WhileDragging,
4918
- frequency: MeasuringFrequency.Optimized
4919
- },
4920
- dragOverlay: {
4921
- measure: getClientRect
4922
- }
4923
- };
4924
-
4925
- class DroppableContainersMap extends Map {
4926
- get(id) {
4927
- var _super$get;
4928
-
4929
- return id != null ? (_super$get = super.get(id)) != null ? _super$get : undefined : undefined;
4930
- }
4931
-
4932
- toArray() {
4933
- return Array.from(this.values());
4934
- }
4935
-
4936
- getEnabled() {
4937
- return this.toArray().filter(_ref => {
4938
- let {
4939
- disabled
4940
- } = _ref;
4941
- return !disabled;
4942
- });
4943
- }
4944
-
4945
- getNodeFor(id) {
4946
- var _this$get$node$curren, _this$get;
4947
-
4948
- return (_this$get$node$curren = (_this$get = this.get(id)) == null ? void 0 : _this$get.node.current) != null ? _this$get$node$curren : undefined;
4949
- }
4950
-
4951
- }
4952
-
4953
- const defaultPublicContext = {
4954
- activatorEvent: null,
4955
- active: null,
4956
- activeNode: null,
4957
- activeNodeRect: null,
4958
- collisions: null,
4959
- containerNodeRect: null,
4960
- draggableNodes: /*#__PURE__*/new Map(),
4961
- droppableRects: /*#__PURE__*/new Map(),
4962
- droppableContainers: /*#__PURE__*/new DroppableContainersMap(),
4963
- over: null,
4964
- dragOverlay: {
4965
- nodeRef: {
4966
- current: null
4967
- },
4968
- rect: null,
4969
- setRef: noop$2
4970
- },
4971
- scrollableAncestors: [],
4972
- scrollableAncestorRects: [],
4973
- measuringConfiguration: defaultMeasuringConfiguration,
4974
- measureDroppableContainers: noop$2,
4975
- windowRect: null,
4976
- measuringScheduled: false
4977
- };
4978
- const defaultInternalContext = {
4979
- activatorEvent: null,
4980
- activators: [],
4981
- active: null,
4982
- activeNodeRect: null,
4983
- ariaDescribedById: {
4984
- draggable: ''
4985
- },
4986
- dispatch: noop$2,
4987
- draggableNodes: /*#__PURE__*/new Map(),
4988
- over: null,
4989
- measureDroppableContainers: noop$2
4990
- };
4991
- const InternalContext = /*#__PURE__*/createContext(defaultInternalContext);
4992
- const PublicContext = /*#__PURE__*/createContext(defaultPublicContext);
4993
-
4994
- function getInitialState() {
4995
- return {
4996
- draggable: {
4997
- active: null,
4998
- initialCoordinates: {
4999
- x: 0,
5000
- y: 0
5001
- },
5002
- nodes: new Map(),
5003
- translate: {
5004
- x: 0,
5005
- y: 0
5006
- }
5007
- },
5008
- droppable: {
5009
- containers: new DroppableContainersMap()
5010
- }
5011
- };
5012
- }
5013
- function reducer(state, action) {
5014
- switch (action.type) {
5015
- case Action.DragStart:
5016
- return { ...state,
5017
- draggable: { ...state.draggable,
5018
- initialCoordinates: action.initialCoordinates,
5019
- active: action.active
5020
- }
5021
- };
5022
-
5023
- case Action.DragMove:
5024
- if (state.draggable.active == null) {
5025
- return state;
5026
- }
5027
-
5028
- return { ...state,
5029
- draggable: { ...state.draggable,
5030
- translate: {
5031
- x: action.coordinates.x - state.draggable.initialCoordinates.x,
5032
- y: action.coordinates.y - state.draggable.initialCoordinates.y
5033
- }
5034
- }
5035
- };
5036
-
5037
- case Action.DragEnd:
5038
- case Action.DragCancel:
5039
- return { ...state,
5040
- draggable: { ...state.draggable,
5041
- active: null,
5042
- initialCoordinates: {
5043
- x: 0,
5044
- y: 0
5045
- },
5046
- translate: {
5047
- x: 0,
5048
- y: 0
5049
- }
5050
- }
5051
- };
5052
-
5053
- case Action.RegisterDroppable:
5054
- {
5055
- const {
5056
- element
5057
- } = action;
5058
- const {
5059
- id
5060
- } = element;
5061
- const containers = new DroppableContainersMap(state.droppable.containers);
5062
- containers.set(id, element);
5063
- return { ...state,
5064
- droppable: { ...state.droppable,
5065
- containers
5066
- }
5067
- };
5068
- }
5069
-
5070
- case Action.SetDroppableDisabled:
5071
- {
5072
- const {
5073
- id,
5074
- key,
5075
- disabled
5076
- } = action;
5077
- const element = state.droppable.containers.get(id);
5078
-
5079
- if (!element || key !== element.key) {
5080
- return state;
5081
- }
5082
-
5083
- const containers = new DroppableContainersMap(state.droppable.containers);
5084
- containers.set(id, { ...element,
5085
- disabled
5086
- });
5087
- return { ...state,
5088
- droppable: { ...state.droppable,
5089
- containers
5090
- }
5091
- };
5092
- }
5093
-
5094
- case Action.UnregisterDroppable:
5095
- {
5096
- const {
5097
- id,
5098
- key
5099
- } = action;
5100
- const element = state.droppable.containers.get(id);
5101
-
5102
- if (!element || key !== element.key) {
5103
- return state;
5104
- }
5105
-
5106
- const containers = new DroppableContainersMap(state.droppable.containers);
5107
- containers.delete(id);
5108
- return { ...state,
5109
- droppable: { ...state.droppable,
5110
- containers
5111
- }
5112
- };
5113
- }
5114
-
5115
- default:
5116
- {
5117
- return state;
5118
- }
5119
- }
5120
- }
5121
-
5122
- function RestoreFocus(_ref) {
5123
- let {
5124
- disabled
5125
- } = _ref;
5126
- const {
5127
- active,
5128
- activatorEvent,
5129
- draggableNodes
5130
- } = useContext(InternalContext);
5131
- const previousActivatorEvent = usePrevious(activatorEvent);
5132
- const previousActiveId = usePrevious(active == null ? void 0 : active.id); // Restore keyboard focus on the activator node
5133
-
5134
- useEffect(() => {
5135
- if (disabled) {
5136
- return;
5137
- }
5138
-
5139
- if (!activatorEvent && previousActivatorEvent && previousActiveId != null) {
5140
- if (!isKeyboardEvent(previousActivatorEvent)) {
5141
- return;
5142
- }
5143
-
5144
- if (document.activeElement === previousActivatorEvent.target) {
5145
- // No need to restore focus
5146
- return;
5147
- }
5148
-
5149
- const draggableNode = draggableNodes.get(previousActiveId);
5150
-
5151
- if (!draggableNode) {
5152
- return;
5153
- }
5154
-
5155
- const {
5156
- activatorNode,
5157
- node
5158
- } = draggableNode;
5159
-
5160
- if (!activatorNode.current && !node.current) {
5161
- return;
5162
- }
5163
-
5164
- requestAnimationFrame(() => {
5165
- for (const element of [activatorNode.current, node.current]) {
5166
- if (!element) {
5167
- continue;
5168
- }
5169
-
5170
- const focusableNode = findFirstFocusableNode(element);
5171
-
5172
- if (focusableNode) {
5173
- focusableNode.focus();
5174
- break;
5175
- }
5176
- }
5177
- });
5178
- }
5179
- }, [activatorEvent, disabled, draggableNodes, previousActiveId, previousActivatorEvent]);
5180
- return null;
5181
- }
5182
-
5183
- function applyModifiers(modifiers, _ref) {
5184
- let {
5185
- transform,
5186
- ...args
5187
- } = _ref;
5188
- return modifiers != null && modifiers.length ? modifiers.reduce((accumulator, modifier) => {
5189
- return modifier({
5190
- transform: accumulator,
5191
- ...args
5192
- });
5193
- }, transform) : transform;
5194
- }
5195
-
5196
- function useMeasuringConfiguration(config) {
5197
- return useMemo$1(() => ({
5198
- draggable: { ...defaultMeasuringConfiguration.draggable,
5199
- ...(config == null ? void 0 : config.draggable)
5200
- },
5201
- droppable: { ...defaultMeasuringConfiguration.droppable,
5202
- ...(config == null ? void 0 : config.droppable)
5203
- },
5204
- dragOverlay: { ...defaultMeasuringConfiguration.dragOverlay,
5205
- ...(config == null ? void 0 : config.dragOverlay)
5206
- }
5207
- }), // eslint-disable-next-line react-hooks/exhaustive-deps
5208
- [config == null ? void 0 : config.draggable, config == null ? void 0 : config.droppable, config == null ? void 0 : config.dragOverlay]);
5209
- }
5210
-
5211
- function useLayoutShiftScrollCompensation(_ref) {
5212
- let {
5213
- activeNode,
5214
- measure,
5215
- initialRect,
5216
- config = true
5217
- } = _ref;
5218
- const initialized = useRef(false);
5219
- const {
5220
- x,
5221
- y
5222
- } = typeof config === 'boolean' ? {
5223
- x: config,
5224
- y: config
5225
- } : config;
5226
- useIsomorphicLayoutEffect$1(() => {
5227
- const disabled = !x && !y;
5228
-
5229
- if (disabled || !activeNode) {
5230
- initialized.current = false;
5231
- return;
5232
- }
5233
-
5234
- if (initialized.current || !initialRect) {
5235
- // Return early if layout shift scroll compensation was already attempted
5236
- // or if there is no initialRect to compare to.
5237
- return;
5238
- } // Get the most up to date node ref for the active draggable
5239
-
5240
-
5241
- const node = activeNode == null ? void 0 : activeNode.node.current;
5242
-
5243
- if (!node || node.isConnected === false) {
5244
- // Return early if there is no attached node ref or if the node is
5245
- // disconnected from the document.
5246
- return;
5247
- }
5248
-
5249
- const rect = measure(node);
5250
- const rectDelta = getRectDelta(rect, initialRect);
5251
-
5252
- if (!x) {
5253
- rectDelta.x = 0;
5254
- }
5255
-
5256
- if (!y) {
5257
- rectDelta.y = 0;
5258
- } // Only perform layout shift scroll compensation once
5259
-
5260
-
5261
- initialized.current = true;
5262
-
5263
- if (Math.abs(rectDelta.x) > 0 || Math.abs(rectDelta.y) > 0) {
5264
- const firstScrollableAncestor = getFirstScrollableAncestor(node);
5265
-
5266
- if (firstScrollableAncestor) {
5267
- firstScrollableAncestor.scrollBy({
5268
- top: rectDelta.y,
5269
- left: rectDelta.x
5270
- });
5271
- }
5272
- }
5273
- }, [activeNode, x, y, initialRect, measure]);
5274
- }
5275
-
5276
- const ActiveDraggableContext = /*#__PURE__*/createContext({ ...defaultCoordinates,
5277
- scaleX: 1,
5278
- scaleY: 1
5279
- });
5280
- var Status;
5281
-
5282
- (function (Status) {
5283
- Status[Status["Uninitialized"] = 0] = "Uninitialized";
5284
- Status[Status["Initializing"] = 1] = "Initializing";
5285
- Status[Status["Initialized"] = 2] = "Initialized";
5286
- })(Status || (Status = {}));
5287
-
5288
- const DndContext = /*#__PURE__*/memo(function DndContext(_ref) {
5289
- var _sensorContext$curren, _dragOverlay$nodeRef$, _dragOverlay$rect, _over$rect;
5290
-
5291
- let {
5292
- id,
5293
- accessibility,
5294
- autoScroll = true,
5295
- children,
5296
- sensors = defaultSensors,
5297
- collisionDetection = rectIntersection,
5298
- measuring,
5299
- modifiers,
5300
- ...props
5301
- } = _ref;
5302
- const store = useReducer(reducer, undefined, getInitialState);
5303
- const [state, dispatch] = store;
5304
- const [dispatchMonitorEvent, registerMonitorListener] = useDndMonitorProvider();
5305
- const [status, setStatus] = useState(Status.Uninitialized);
5306
- const isInitialized = status === Status.Initialized;
5307
- const {
5308
- draggable: {
5309
- active: activeId,
5310
- nodes: draggableNodes,
5311
- translate
5312
- },
5313
- droppable: {
5314
- containers: droppableContainers
5315
- }
5316
- } = state;
5317
- const node = activeId != null ? draggableNodes.get(activeId) : null;
5318
- const activeRects = useRef({
5319
- initial: null,
5320
- translated: null
5321
- });
5322
- const active = useMemo$1(() => {
5323
- var _node$data;
5324
-
5325
- return activeId != null ? {
5326
- id: activeId,
5327
- // It's possible for the active node to unmount while dragging
5328
- data: (_node$data = node == null ? void 0 : node.data) != null ? _node$data : defaultData,
5329
- rect: activeRects
5330
- } : null;
5331
- }, [activeId, node]);
5332
- const activeRef = useRef(null);
5333
- const [activeSensor, setActiveSensor] = useState(null);
5334
- const [activatorEvent, setActivatorEvent] = useState(null);
5335
- const latestProps = useLatestValue(props, Object.values(props));
5336
- const draggableDescribedById = useUniqueId("DndDescribedBy", id);
5337
- const enabledDroppableContainers = useMemo$1(() => droppableContainers.getEnabled(), [droppableContainers]);
5338
- const measuringConfiguration = useMeasuringConfiguration(measuring);
5339
- const {
5340
- droppableRects,
5341
- measureDroppableContainers,
5342
- measuringScheduled
5343
- } = useDroppableMeasuring(enabledDroppableContainers, {
5344
- dragging: isInitialized,
5345
- dependencies: [translate.x, translate.y],
5346
- config: measuringConfiguration.droppable
5347
- });
5348
- const activeNode = useCachedNode(draggableNodes, activeId);
5349
- const activationCoordinates = useMemo$1(() => activatorEvent ? getEventCoordinates(activatorEvent) : null, [activatorEvent]);
5350
- const autoScrollOptions = getAutoScrollerOptions();
5351
- const initialActiveNodeRect = useInitialRect(activeNode, measuringConfiguration.draggable.measure);
5352
- useLayoutShiftScrollCompensation({
5353
- activeNode: activeId != null ? draggableNodes.get(activeId) : null,
5354
- config: autoScrollOptions.layoutShiftCompensation,
5355
- initialRect: initialActiveNodeRect,
5356
- measure: measuringConfiguration.draggable.measure
5357
- });
5358
- const activeNodeRect = useRect(activeNode, measuringConfiguration.draggable.measure, initialActiveNodeRect);
5359
- const containerNodeRect = useRect(activeNode ? activeNode.parentElement : null);
5360
- const sensorContext = useRef({
5361
- activatorEvent: null,
5362
- active: null,
5363
- activeNode,
5364
- collisionRect: null,
5365
- collisions: null,
5366
- droppableRects,
5367
- draggableNodes,
5368
- draggingNode: null,
5369
- draggingNodeRect: null,
5370
- droppableContainers,
5371
- over: null,
5372
- scrollableAncestors: [],
5373
- scrollAdjustedTranslate: null
5374
- });
5375
- const overNode = droppableContainers.getNodeFor((_sensorContext$curren = sensorContext.current.over) == null ? void 0 : _sensorContext$curren.id);
5376
- const dragOverlay = useDragOverlayMeasuring({
5377
- measure: measuringConfiguration.dragOverlay.measure
5378
- }); // Use the rect of the drag overlay if it is mounted
5379
-
5380
- const draggingNode = (_dragOverlay$nodeRef$ = dragOverlay.nodeRef.current) != null ? _dragOverlay$nodeRef$ : activeNode;
5381
- const draggingNodeRect = isInitialized ? (_dragOverlay$rect = dragOverlay.rect) != null ? _dragOverlay$rect : activeNodeRect : null;
5382
- const usesDragOverlay = Boolean(dragOverlay.nodeRef.current && dragOverlay.rect); // The delta between the previous and new position of the draggable node
5383
- // is only relevant when there is no drag overlay
5384
-
5385
- const nodeRectDelta = useRectDelta(usesDragOverlay ? null : activeNodeRect); // Get the window rect of the dragging node
5386
-
5387
- const windowRect = useWindowRect(draggingNode ? getWindow(draggingNode) : null); // Get scrollable ancestors of the dragging node
5388
-
5389
- const scrollableAncestors = useScrollableAncestors(isInitialized ? overNode != null ? overNode : activeNode : null);
5390
- const scrollableAncestorRects = useRects(scrollableAncestors); // Apply modifiers
5391
-
5392
- const modifiedTranslate = applyModifiers(modifiers, {
5393
- transform: {
5394
- x: translate.x - nodeRectDelta.x,
5395
- y: translate.y - nodeRectDelta.y,
5396
- scaleX: 1,
5397
- scaleY: 1
5398
- },
5399
- activatorEvent,
5400
- active,
5401
- activeNodeRect,
5402
- containerNodeRect,
5403
- draggingNodeRect,
5404
- over: sensorContext.current.over,
5405
- overlayNodeRect: dragOverlay.rect,
5406
- scrollableAncestors,
5407
- scrollableAncestorRects,
5408
- windowRect
5409
- });
5410
- const pointerCoordinates = activationCoordinates ? add(activationCoordinates, translate) : null;
5411
- const scrollOffsets = useScrollOffsets(scrollableAncestors); // Represents the scroll delta since dragging was initiated
5412
-
5413
- const scrollAdjustment = useScrollOffsetsDelta(scrollOffsets); // Represents the scroll delta since the last time the active node rect was measured
5414
-
5415
- const activeNodeScrollDelta = useScrollOffsetsDelta(scrollOffsets, [activeNodeRect]);
5416
- const scrollAdjustedTranslate = add(modifiedTranslate, scrollAdjustment);
5417
- const collisionRect = draggingNodeRect ? getAdjustedRect(draggingNodeRect, modifiedTranslate) : null;
5418
- const collisions = active && collisionRect ? collisionDetection({
5419
- active,
5420
- collisionRect,
5421
- droppableRects,
5422
- droppableContainers: enabledDroppableContainers,
5423
- pointerCoordinates
5424
- }) : null;
5425
- const overId = getFirstCollision(collisions, 'id');
5426
- const [over, setOver] = useState(null); // When there is no drag overlay used, we need to account for the
5427
- // window scroll delta
5428
-
5429
- const appliedTranslate = usesDragOverlay ? modifiedTranslate : add(modifiedTranslate, activeNodeScrollDelta);
5430
- const transform = adjustScale(appliedTranslate, (_over$rect = over == null ? void 0 : over.rect) != null ? _over$rect : null, activeNodeRect);
5431
- const activeSensorRef = useRef(null);
5432
- const instantiateSensor = useCallback((event, _ref2) => {
5433
- let {
5434
- sensor: Sensor,
5435
- options
5436
- } = _ref2;
5437
-
5438
- if (activeRef.current == null) {
5439
- return;
5440
- }
5441
-
5442
- const activeNode = draggableNodes.get(activeRef.current);
5443
-
5444
- if (!activeNode) {
5445
- return;
5446
- }
5447
-
5448
- const activatorEvent = event.nativeEvent;
5449
- const sensorInstance = new Sensor({
5450
- active: activeRef.current,
5451
- activeNode,
5452
- event: activatorEvent,
5453
- options,
5454
- // Sensors need to be instantiated with refs for arguments that change over time
5455
- // otherwise they are frozen in time with the stale arguments
5456
- context: sensorContext,
5457
-
5458
- onAbort(id) {
5459
- const draggableNode = draggableNodes.get(id);
5460
-
5461
- if (!draggableNode) {
5462
- return;
5463
- }
5464
-
5465
- const {
5466
- onDragAbort
5467
- } = latestProps.current;
5468
- const event = {
5469
- id
5470
- };
5471
- onDragAbort == null ? void 0 : onDragAbort(event);
5472
- dispatchMonitorEvent({
5473
- type: 'onDragAbort',
5474
- event
5475
- });
5476
- },
5477
-
5478
- onPending(id, constraint, initialCoordinates, offset) {
5479
- const draggableNode = draggableNodes.get(id);
5480
-
5481
- if (!draggableNode) {
5482
- return;
5483
- }
5484
-
5485
- const {
5486
- onDragPending
5487
- } = latestProps.current;
5488
- const event = {
5489
- id,
5490
- constraint,
5491
- initialCoordinates,
5492
- offset
5493
- };
5494
- onDragPending == null ? void 0 : onDragPending(event);
5495
- dispatchMonitorEvent({
5496
- type: 'onDragPending',
5497
- event
5498
- });
5499
- },
5500
-
5501
- onStart(initialCoordinates) {
5502
- const id = activeRef.current;
5503
-
5504
- if (id == null) {
5505
- return;
5506
- }
5507
-
5508
- const draggableNode = draggableNodes.get(id);
5509
-
5510
- if (!draggableNode) {
5511
- return;
5512
- }
5513
-
5514
- const {
5515
- onDragStart
5516
- } = latestProps.current;
5517
- const event = {
5518
- activatorEvent,
5519
- active: {
5520
- id,
5521
- data: draggableNode.data,
5522
- rect: activeRects
5523
- }
5524
- };
5525
- unstable_batchedUpdates(() => {
5526
- onDragStart == null ? void 0 : onDragStart(event);
5527
- setStatus(Status.Initializing);
5528
- dispatch({
5529
- type: Action.DragStart,
5530
- initialCoordinates,
5531
- active: id
5532
- });
5533
- dispatchMonitorEvent({
5534
- type: 'onDragStart',
5535
- event
5536
- });
5537
- setActiveSensor(activeSensorRef.current);
5538
- setActivatorEvent(activatorEvent);
5539
- });
5540
- },
5541
-
5542
- onMove(coordinates) {
5543
- dispatch({
5544
- type: Action.DragMove,
5545
- coordinates
5546
- });
5547
- },
5548
-
5549
- onEnd: createHandler(Action.DragEnd),
5550
- onCancel: createHandler(Action.DragCancel)
5551
- });
5552
- activeSensorRef.current = sensorInstance;
5553
-
5554
- function createHandler(type) {
5555
- return async function handler() {
5556
- const {
5557
- active,
5558
- collisions,
5559
- over,
5560
- scrollAdjustedTranslate
5561
- } = sensorContext.current;
5562
- let event = null;
5563
-
5564
- if (active && scrollAdjustedTranslate) {
5565
- const {
5566
- cancelDrop
5567
- } = latestProps.current;
5568
- event = {
5569
- activatorEvent,
5570
- active: active,
5571
- collisions,
5572
- delta: scrollAdjustedTranslate,
5573
- over
5574
- };
5575
-
5576
- if (type === Action.DragEnd && typeof cancelDrop === 'function') {
5577
- const shouldCancel = await Promise.resolve(cancelDrop(event));
5578
-
5579
- if (shouldCancel) {
5580
- type = Action.DragCancel;
5581
- }
5582
- }
5583
- }
5584
-
5585
- activeRef.current = null;
5586
- unstable_batchedUpdates(() => {
5587
- dispatch({
5588
- type
5589
- });
5590
- setStatus(Status.Uninitialized);
5591
- setOver(null);
5592
- setActiveSensor(null);
5593
- setActivatorEvent(null);
5594
- activeSensorRef.current = null;
5595
- const eventName = type === Action.DragEnd ? 'onDragEnd' : 'onDragCancel';
5596
-
5597
- if (event) {
5598
- const handler = latestProps.current[eventName];
5599
- handler == null ? void 0 : handler(event);
5600
- dispatchMonitorEvent({
5601
- type: eventName,
5602
- event
5603
- });
5604
- }
5605
- });
5606
- };
5607
- }
5608
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
5609
- [draggableNodes]);
5610
- const bindActivatorToSensorInstantiator = useCallback((handler, sensor) => {
5611
- return (event, active) => {
5612
- const nativeEvent = event.nativeEvent;
5613
- const activeDraggableNode = draggableNodes.get(active);
5614
-
5615
- if ( // Another sensor is already instantiating
5616
- activeRef.current !== null || // No active draggable
5617
- !activeDraggableNode || // Event has already been captured
5618
- nativeEvent.dndKit || nativeEvent.defaultPrevented) {
5619
- return;
5620
- }
5621
-
5622
- const activationContext = {
5623
- active: activeDraggableNode
5624
- };
5625
- const shouldActivate = handler(event, sensor.options, activationContext);
5626
-
5627
- if (shouldActivate === true) {
5628
- nativeEvent.dndKit = {
5629
- capturedBy: sensor.sensor
5630
- };
5631
- activeRef.current = active;
5632
- instantiateSensor(event, sensor);
5633
- }
5634
- };
5635
- }, [draggableNodes, instantiateSensor]);
5636
- const activators = useCombineActivators(sensors, bindActivatorToSensorInstantiator);
5637
- useSensorSetup(sensors);
5638
- useIsomorphicLayoutEffect$1(() => {
5639
- if (activeNodeRect && status === Status.Initializing) {
5640
- setStatus(Status.Initialized);
5641
- }
5642
- }, [activeNodeRect, status]);
5643
- useEffect(() => {
5644
- const {
5645
- onDragMove
5646
- } = latestProps.current;
5647
- const {
5648
- active,
5649
- activatorEvent,
5650
- collisions,
5651
- over
5652
- } = sensorContext.current;
5653
-
5654
- if (!active || !activatorEvent) {
5655
- return;
5656
- }
5657
-
5658
- const event = {
5659
- active,
5660
- activatorEvent,
5661
- collisions,
5662
- delta: {
5663
- x: scrollAdjustedTranslate.x,
5664
- y: scrollAdjustedTranslate.y
5665
- },
5666
- over
5667
- };
5668
- unstable_batchedUpdates(() => {
5669
- onDragMove == null ? void 0 : onDragMove(event);
5670
- dispatchMonitorEvent({
5671
- type: 'onDragMove',
5672
- event
5673
- });
5674
- });
5675
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
5676
- [scrollAdjustedTranslate.x, scrollAdjustedTranslate.y]);
5677
- useEffect(() => {
5678
- const {
5679
- active,
5680
- activatorEvent,
5681
- collisions,
5682
- droppableContainers,
5683
- scrollAdjustedTranslate
5684
- } = sensorContext.current;
5685
-
5686
- if (!active || activeRef.current == null || !activatorEvent || !scrollAdjustedTranslate) {
5687
- return;
5688
- }
5689
-
5690
- const {
5691
- onDragOver
5692
- } = latestProps.current;
5693
- const overContainer = droppableContainers.get(overId);
5694
- const over = overContainer && overContainer.rect.current ? {
5695
- id: overContainer.id,
5696
- rect: overContainer.rect.current,
5697
- data: overContainer.data,
5698
- disabled: overContainer.disabled
5699
- } : null;
5700
- const event = {
5701
- active,
5702
- activatorEvent,
5703
- collisions,
5704
- delta: {
5705
- x: scrollAdjustedTranslate.x,
5706
- y: scrollAdjustedTranslate.y
5707
- },
5708
- over
5709
- };
5710
- unstable_batchedUpdates(() => {
5711
- setOver(over);
5712
- onDragOver == null ? void 0 : onDragOver(event);
5713
- dispatchMonitorEvent({
5714
- type: 'onDragOver',
5715
- event
5716
- });
5717
- });
5718
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
5719
- [overId]);
5720
- useIsomorphicLayoutEffect$1(() => {
5721
- sensorContext.current = {
5722
- activatorEvent,
5723
- active,
5724
- activeNode,
5725
- collisionRect,
5726
- collisions,
5727
- droppableRects,
5728
- draggableNodes,
5729
- draggingNode,
5730
- draggingNodeRect,
5731
- droppableContainers,
5732
- over,
5733
- scrollableAncestors,
5734
- scrollAdjustedTranslate
5735
- };
5736
- activeRects.current = {
5737
- initial: draggingNodeRect,
5738
- translated: collisionRect
5739
- };
5740
- }, [active, activeNode, collisions, collisionRect, draggableNodes, draggingNode, draggingNodeRect, droppableRects, droppableContainers, over, scrollableAncestors, scrollAdjustedTranslate]);
5741
- useAutoScroller({ ...autoScrollOptions,
5742
- delta: translate,
5743
- draggingRect: collisionRect,
5744
- pointerCoordinates,
5745
- scrollableAncestors,
5746
- scrollableAncestorRects
5747
- });
5748
- const publicContext = useMemo$1(() => {
5749
- const context = {
5750
- active,
5751
- activeNode,
5752
- activeNodeRect,
5753
- activatorEvent,
5754
- collisions,
5755
- containerNodeRect,
5756
- dragOverlay,
5757
- draggableNodes,
5758
- droppableContainers,
5759
- droppableRects,
5760
- over,
5761
- measureDroppableContainers,
5762
- scrollableAncestors,
5763
- scrollableAncestorRects,
5764
- measuringConfiguration,
5765
- measuringScheduled,
5766
- windowRect
5767
- };
5768
- return context;
5769
- }, [active, activeNode, activeNodeRect, activatorEvent, collisions, containerNodeRect, dragOverlay, draggableNodes, droppableContainers, droppableRects, over, measureDroppableContainers, scrollableAncestors, scrollableAncestorRects, measuringConfiguration, measuringScheduled, windowRect]);
5770
- const internalContext = useMemo$1(() => {
5771
- const context = {
5772
- activatorEvent,
5773
- activators,
5774
- active,
5775
- activeNodeRect,
5776
- ariaDescribedById: {
5777
- draggable: draggableDescribedById
5778
- },
5779
- dispatch,
5780
- draggableNodes,
5781
- over,
5782
- measureDroppableContainers
5783
- };
5784
- return context;
5785
- }, [activatorEvent, activators, active, activeNodeRect, dispatch, draggableDescribedById, draggableNodes, over, measureDroppableContainers]);
5786
- return React__default.createElement(DndMonitorContext.Provider, {
5787
- value: registerMonitorListener
5788
- }, React__default.createElement(InternalContext.Provider, {
5789
- value: internalContext
5790
- }, React__default.createElement(PublicContext.Provider, {
5791
- value: publicContext
5792
- }, React__default.createElement(ActiveDraggableContext.Provider, {
5793
- value: transform
5794
- }, children)), React__default.createElement(RestoreFocus, {
5795
- disabled: (accessibility == null ? void 0 : accessibility.restoreFocus) === false
5796
- })), React__default.createElement(Accessibility, { ...accessibility,
5797
- hiddenTextDescribedById: draggableDescribedById
5798
- }));
5799
-
5800
- function getAutoScrollerOptions() {
5801
- const activeSensorDisablesAutoscroll = (activeSensor == null ? void 0 : activeSensor.autoScrollEnabled) === false;
5802
- const autoScrollGloballyDisabled = typeof autoScroll === 'object' ? autoScroll.enabled === false : autoScroll === false;
5803
- const enabled = isInitialized && !activeSensorDisablesAutoscroll && !autoScrollGloballyDisabled;
5804
-
5805
- if (typeof autoScroll === 'object') {
5806
- return { ...autoScroll,
5807
- enabled
5808
- };
5809
- }
5810
-
5811
- return {
5812
- enabled
5813
- };
5814
- }
5815
- });
5816
-
5817
- const NullContext = /*#__PURE__*/createContext(null);
5818
- const defaultRole = 'button';
5819
- const ID_PREFIX$1 = 'Draggable';
5820
- function useDraggable(_ref) {
5821
- let {
5822
- id,
5823
- data,
5824
- disabled = false,
5825
- attributes
5826
- } = _ref;
5827
- const key = useUniqueId(ID_PREFIX$1);
5828
- const {
5829
- activators,
5830
- activatorEvent,
5831
- active,
5832
- activeNodeRect,
5833
- ariaDescribedById,
5834
- draggableNodes,
5835
- over
5836
- } = useContext(InternalContext);
5837
- const {
5838
- role = defaultRole,
5839
- roleDescription = 'draggable',
5840
- tabIndex = 0
5841
- } = attributes != null ? attributes : {};
5842
- const isDragging = (active == null ? void 0 : active.id) === id;
5843
- const transform = useContext(isDragging ? ActiveDraggableContext : NullContext);
5844
- const [node, setNodeRef] = useNodeRef();
5845
- const [activatorNode, setActivatorNodeRef] = useNodeRef();
5846
- const listeners = useSyntheticListeners(activators, id);
5847
- const dataRef = useLatestValue(data);
5848
- useIsomorphicLayoutEffect$1(() => {
5849
- draggableNodes.set(id, {
5850
- id,
5851
- key,
5852
- node,
5853
- activatorNode,
5854
- data: dataRef
5855
- });
5856
- return () => {
5857
- const node = draggableNodes.get(id);
5858
-
5859
- if (node && node.key === key) {
5860
- draggableNodes.delete(id);
5861
- }
5862
- };
5863
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
5864
- [draggableNodes, id]);
5865
- const memoizedAttributes = useMemo$1(() => ({
5866
- role,
5867
- tabIndex,
5868
- 'aria-disabled': disabled,
5869
- 'aria-pressed': isDragging && role === defaultRole ? true : undefined,
5870
- 'aria-roledescription': roleDescription,
5871
- 'aria-describedby': ariaDescribedById.draggable
5872
- }), [disabled, role, tabIndex, isDragging, roleDescription, ariaDescribedById.draggable]);
5873
- return {
5874
- active,
5875
- activatorEvent,
5876
- activeNodeRect,
5877
- attributes: memoizedAttributes,
5878
- isDragging,
5879
- listeners: disabled ? undefined : listeners,
5880
- node,
5881
- over,
5882
- setNodeRef,
5883
- setActivatorNodeRef,
5884
- transform
5885
- };
5886
- }
5887
-
5888
- function useDndContext() {
5889
- return useContext(PublicContext);
5890
- }
5891
-
5892
- const ID_PREFIX$1$1 = 'Droppable';
5893
- const defaultResizeObserverConfig = {
5894
- timeout: 25
5895
- };
5896
- function useDroppable(_ref) {
5897
- let {
5898
- data,
5899
- disabled = false,
5900
- id,
5901
- resizeObserverConfig
5902
- } = _ref;
5903
- const key = useUniqueId(ID_PREFIX$1$1);
5904
- const {
5905
- active,
5906
- dispatch,
5907
- over,
5908
- measureDroppableContainers
5909
- } = useContext(InternalContext);
5910
- const previous = useRef({
5911
- disabled
5912
- });
5913
- const resizeObserverConnected = useRef(false);
5914
- const rect = useRef(null);
5915
- const callbackId = useRef(null);
5916
- const {
5917
- disabled: resizeObserverDisabled,
5918
- updateMeasurementsFor,
5919
- timeout: resizeObserverTimeout
5920
- } = { ...defaultResizeObserverConfig,
5921
- ...resizeObserverConfig
5922
- };
5923
- const ids = useLatestValue(updateMeasurementsFor != null ? updateMeasurementsFor : id);
5924
- const handleResize = useCallback(() => {
5925
- if (!resizeObserverConnected.current) {
5926
- // ResizeObserver invokes the `handleResize` callback as soon as `observe` is called,
5927
- // assuming the element is rendered and displayed.
5928
- resizeObserverConnected.current = true;
5929
- return;
5930
- }
5931
-
5932
- if (callbackId.current != null) {
5933
- clearTimeout(callbackId.current);
5934
- }
5935
-
5936
- callbackId.current = setTimeout(() => {
5937
- measureDroppableContainers(Array.isArray(ids.current) ? ids.current : [ids.current]);
5938
- callbackId.current = null;
5939
- }, resizeObserverTimeout);
5940
- }, //eslint-disable-next-line react-hooks/exhaustive-deps
5941
- [resizeObserverTimeout]);
5942
- const resizeObserver = useResizeObserver({
5943
- callback: handleResize,
5944
- disabled: resizeObserverDisabled || !active
5945
- });
5946
- const handleNodeChange = useCallback((newElement, previousElement) => {
5947
- if (!resizeObserver) {
5948
- return;
5949
- }
5950
-
5951
- if (previousElement) {
5952
- resizeObserver.unobserve(previousElement);
5953
- resizeObserverConnected.current = false;
5954
- }
5955
-
5956
- if (newElement) {
5957
- resizeObserver.observe(newElement);
5958
- }
5959
- }, [resizeObserver]);
5960
- const [nodeRef, setNodeRef] = useNodeRef(handleNodeChange);
5961
- const dataRef = useLatestValue(data);
5962
- useEffect(() => {
5963
- if (!resizeObserver || !nodeRef.current) {
5964
- return;
5965
- }
5966
-
5967
- resizeObserver.disconnect();
5968
- resizeObserverConnected.current = false;
5969
- resizeObserver.observe(nodeRef.current);
5970
- }, [nodeRef, resizeObserver]);
5971
- useEffect(() => {
5972
- dispatch({
5973
- type: Action.RegisterDroppable,
5974
- element: {
5975
- id,
5976
- key,
5977
- disabled,
5978
- node: nodeRef,
5979
- rect,
5980
- data: dataRef
5981
- }
5982
- });
5983
- return () => dispatch({
5984
- type: Action.UnregisterDroppable,
5985
- key,
5986
- id
5987
- });
5988
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
5989
- [id]);
5990
- useEffect(() => {
5991
- if (disabled !== previous.current.disabled) {
5992
- dispatch({
5993
- type: Action.SetDroppableDisabled,
5994
- id,
5995
- key,
5996
- disabled
5997
- });
5998
- previous.current.disabled = disabled;
5999
- }
6000
- }, [id, key, disabled, dispatch]);
6001
- return {
6002
- active,
6003
- rect,
6004
- isOver: (over == null ? void 0 : over.id) === id,
6005
- node: nodeRef,
6006
- over,
6007
- setNodeRef
6008
- };
6009
- }
6010
-
6011
- /**
6012
- * Move an array item to a different position. Returns a new array with the item moved to the new position.
6013
- */
6014
- function arrayMove(array, from, to) {
6015
- const newArray = array.slice();
6016
- newArray.splice(to < 0 ? newArray.length + to : to, 0, newArray.splice(from, 1)[0]);
6017
- return newArray;
6018
- }
6019
-
6020
- function getSortedRects(items, rects) {
6021
- return items.reduce((accumulator, id, index) => {
6022
- const rect = rects.get(id);
6023
-
6024
- if (rect) {
6025
- accumulator[index] = rect;
6026
- }
6027
-
6028
- return accumulator;
6029
- }, Array(items.length));
6030
- }
6031
-
6032
- function isValidIndex(index) {
6033
- return index !== null && index >= 0;
6034
- }
6035
-
6036
- function itemsEqual(a, b) {
6037
- if (a === b) {
6038
- return true;
6039
- }
6040
-
6041
- if (a.length !== b.length) {
6042
- return false;
6043
- }
6044
-
6045
- for (let i = 0; i < a.length; i++) {
6046
- if (a[i] !== b[i]) {
6047
- return false;
6048
- }
6049
- }
6050
-
6051
- return true;
6052
- }
6053
-
6054
- function normalizeDisabled(disabled) {
6055
- if (typeof disabled === 'boolean') {
6056
- return {
6057
- draggable: disabled,
6058
- droppable: disabled
6059
- };
6060
- }
6061
-
6062
- return disabled;
6063
- }
6064
-
6065
- const rectSortingStrategy = _ref => {
6066
- let {
6067
- rects,
6068
- activeIndex,
6069
- overIndex,
6070
- index
6071
- } = _ref;
6072
- const newRects = arrayMove(rects, overIndex, activeIndex);
6073
- const oldRect = rects[index];
6074
- const newRect = newRects[index];
6075
-
6076
- if (!newRect || !oldRect) {
6077
- return null;
6078
- }
6079
-
6080
- return {
6081
- x: newRect.left - oldRect.left,
6082
- y: newRect.top - oldRect.top,
6083
- scaleX: newRect.width / oldRect.width,
6084
- scaleY: newRect.height / oldRect.height
6085
- };
6086
- };
6087
-
6088
- // To-do: We should be calculating scale transformation
6089
- const defaultScale$1 = {
6090
- scaleX: 1,
6091
- scaleY: 1
6092
- };
6093
- const verticalListSortingStrategy = _ref => {
6094
- var _rects$activeIndex;
6095
-
6096
- let {
6097
- activeIndex,
6098
- activeNodeRect: fallbackActiveRect,
6099
- index,
6100
- rects,
6101
- overIndex
6102
- } = _ref;
6103
- const activeNodeRect = (_rects$activeIndex = rects[activeIndex]) != null ? _rects$activeIndex : fallbackActiveRect;
6104
-
6105
- if (!activeNodeRect) {
6106
- return null;
6107
- }
6108
-
6109
- if (index === activeIndex) {
6110
- const overIndexRect = rects[overIndex];
6111
-
6112
- if (!overIndexRect) {
6113
- return null;
6114
- }
6115
-
6116
- return {
6117
- x: 0,
6118
- y: activeIndex < overIndex ? overIndexRect.top + overIndexRect.height - (activeNodeRect.top + activeNodeRect.height) : overIndexRect.top - activeNodeRect.top,
6119
- ...defaultScale$1
6120
- };
6121
- }
6122
-
6123
- const itemGap = getItemGap$1(rects, index, activeIndex);
6124
-
6125
- if (index > activeIndex && index <= overIndex) {
6126
- return {
6127
- x: 0,
6128
- y: -activeNodeRect.height - itemGap,
6129
- ...defaultScale$1
6130
- };
6131
- }
6132
-
6133
- if (index < activeIndex && index >= overIndex) {
6134
- return {
6135
- x: 0,
6136
- y: activeNodeRect.height + itemGap,
6137
- ...defaultScale$1
6138
- };
6139
- }
6140
-
6141
- return {
6142
- x: 0,
6143
- y: 0,
6144
- ...defaultScale$1
6145
- };
6146
- };
6147
-
6148
- function getItemGap$1(clientRects, index, activeIndex) {
6149
- const currentRect = clientRects[index];
6150
- const previousRect = clientRects[index - 1];
6151
- const nextRect = clientRects[index + 1];
6152
-
6153
- if (!currentRect) {
6154
- return 0;
6155
- }
6156
-
6157
- if (activeIndex < index) {
6158
- return previousRect ? currentRect.top - (previousRect.top + previousRect.height) : nextRect ? nextRect.top - (currentRect.top + currentRect.height) : 0;
6159
- }
6160
-
6161
- return nextRect ? nextRect.top - (currentRect.top + currentRect.height) : previousRect ? currentRect.top - (previousRect.top + previousRect.height) : 0;
6162
- }
6163
-
6164
- const ID_PREFIX = 'Sortable';
6165
- const Context$1 = /*#__PURE__*/React__default.createContext({
6166
- activeIndex: -1,
6167
- containerId: ID_PREFIX,
6168
- disableTransforms: false,
6169
- items: [],
6170
- overIndex: -1,
6171
- useDragOverlay: false,
6172
- sortedRects: [],
6173
- strategy: rectSortingStrategy,
6174
- disabled: {
6175
- draggable: false,
6176
- droppable: false
6177
- }
6178
- });
6179
- function SortableContext(_ref) {
6180
- let {
6181
- children,
6182
- id,
6183
- items: userDefinedItems,
6184
- strategy = rectSortingStrategy,
6185
- disabled: disabledProp = false
6186
- } = _ref;
6187
- const {
6188
- active,
6189
- dragOverlay,
6190
- droppableRects,
6191
- over,
6192
- measureDroppableContainers
6193
- } = useDndContext();
6194
- const containerId = useUniqueId(ID_PREFIX, id);
6195
- const useDragOverlay = Boolean(dragOverlay.rect !== null);
6196
- const items = useMemo$1(() => userDefinedItems.map(item => typeof item === 'object' && 'id' in item ? item.id : item), [userDefinedItems]);
6197
- const isDragging = active != null;
6198
- const activeIndex = active ? items.indexOf(active.id) : -1;
6199
- const overIndex = over ? items.indexOf(over.id) : -1;
6200
- const previousItemsRef = useRef(items);
6201
- const itemsHaveChanged = !itemsEqual(items, previousItemsRef.current);
6202
- const disableTransforms = overIndex !== -1 && activeIndex === -1 || itemsHaveChanged;
6203
- const disabled = normalizeDisabled(disabledProp);
6204
- useIsomorphicLayoutEffect$1(() => {
6205
- if (itemsHaveChanged && isDragging) {
6206
- measureDroppableContainers(items);
6207
- }
6208
- }, [itemsHaveChanged, items, isDragging, measureDroppableContainers]);
6209
- useEffect(() => {
6210
- previousItemsRef.current = items;
6211
- }, [items]);
6212
- const contextValue = useMemo$1(() => ({
6213
- activeIndex,
6214
- containerId,
6215
- disabled,
6216
- disableTransforms,
6217
- items,
6218
- overIndex,
6219
- useDragOverlay,
6220
- sortedRects: getSortedRects(items, droppableRects),
6221
- strategy
6222
- }), // eslint-disable-next-line react-hooks/exhaustive-deps
6223
- [activeIndex, containerId, disabled.draggable, disabled.droppable, disableTransforms, items, overIndex, droppableRects, useDragOverlay, strategy]);
6224
- return React__default.createElement(Context$1.Provider, {
6225
- value: contextValue
6226
- }, children);
6227
- }
6228
-
6229
- const defaultNewIndexGetter = _ref => {
6230
- let {
6231
- id,
6232
- items,
6233
- activeIndex,
6234
- overIndex
6235
- } = _ref;
6236
- return arrayMove(items, activeIndex, overIndex).indexOf(id);
6237
- };
6238
- const defaultAnimateLayoutChanges = _ref2 => {
6239
- let {
6240
- containerId,
6241
- isSorting,
6242
- wasDragging,
6243
- index,
6244
- items,
6245
- newIndex,
6246
- previousItems,
6247
- previousContainerId,
6248
- transition
6249
- } = _ref2;
6250
-
6251
- if (!transition || !wasDragging) {
6252
- return false;
6253
- }
6254
-
6255
- if (previousItems !== items && index === newIndex) {
6256
- return false;
6257
- }
6258
-
6259
- if (isSorting) {
6260
- return true;
6261
- }
6262
-
6263
- return newIndex !== index && containerId === previousContainerId;
6264
- };
6265
- const defaultTransition = {
6266
- duration: 200,
6267
- easing: 'ease'
6268
- };
6269
- const transitionProperty = 'transform';
6270
- const disabledTransition = /*#__PURE__*/CSS.Transition.toString({
6271
- property: transitionProperty,
6272
- duration: 0,
6273
- easing: 'linear'
6274
- });
6275
- const defaultAttributes = {
6276
- roleDescription: 'sortable'
6277
- };
6278
-
6279
- /*
6280
- * When the index of an item changes while sorting,
6281
- * we need to temporarily disable the transforms
6282
- */
6283
-
6284
- function useDerivedTransform(_ref) {
6285
- let {
6286
- disabled,
6287
- index,
6288
- node,
6289
- rect
6290
- } = _ref;
6291
- const [derivedTransform, setDerivedtransform] = useState(null);
6292
- const previousIndex = useRef(index);
6293
- useIsomorphicLayoutEffect$1(() => {
6294
- if (!disabled && index !== previousIndex.current && node.current) {
6295
- const initial = rect.current;
6296
-
6297
- if (initial) {
6298
- const current = getClientRect(node.current, {
6299
- ignoreTransform: true
6300
- });
6301
- const delta = {
6302
- x: initial.left - current.left,
6303
- y: initial.top - current.top,
6304
- scaleX: initial.width / current.width,
6305
- scaleY: initial.height / current.height
6306
- };
6307
-
6308
- if (delta.x || delta.y) {
6309
- setDerivedtransform(delta);
6310
- }
6311
- }
6312
- }
6313
-
6314
- if (index !== previousIndex.current) {
6315
- previousIndex.current = index;
6316
- }
6317
- }, [disabled, index, node, rect]);
6318
- useEffect(() => {
6319
- if (derivedTransform) {
6320
- setDerivedtransform(null);
6321
- }
6322
- }, [derivedTransform]);
6323
- return derivedTransform;
6324
- }
6325
-
6326
- function useSortable(_ref) {
6327
- let {
6328
- animateLayoutChanges = defaultAnimateLayoutChanges,
6329
- attributes: userDefinedAttributes,
6330
- disabled: localDisabled,
6331
- data: customData,
6332
- getNewIndex = defaultNewIndexGetter,
6333
- id,
6334
- strategy: localStrategy,
6335
- resizeObserverConfig,
6336
- transition = defaultTransition
6337
- } = _ref;
6338
- const {
6339
- items,
6340
- containerId,
6341
- activeIndex,
6342
- disabled: globalDisabled,
6343
- disableTransforms,
6344
- sortedRects,
6345
- overIndex,
6346
- useDragOverlay,
6347
- strategy: globalStrategy
6348
- } = useContext(Context$1);
6349
- const disabled = normalizeLocalDisabled(localDisabled, globalDisabled);
6350
- const index = items.indexOf(id);
6351
- const data = useMemo$1(() => ({
6352
- sortable: {
6353
- containerId,
6354
- index,
6355
- items
6356
- },
6357
- ...customData
6358
- }), [containerId, customData, index, items]);
6359
- const itemsAfterCurrentSortable = useMemo$1(() => items.slice(items.indexOf(id)), [items, id]);
6360
- const {
6361
- rect,
6362
- node,
6363
- isOver,
6364
- setNodeRef: setDroppableNodeRef
6365
- } = useDroppable({
6366
- id,
6367
- data,
6368
- disabled: disabled.droppable,
6369
- resizeObserverConfig: {
6370
- updateMeasurementsFor: itemsAfterCurrentSortable,
6371
- ...resizeObserverConfig
6372
- }
6373
- });
6374
- const {
6375
- active,
6376
- activatorEvent,
6377
- activeNodeRect,
6378
- attributes,
6379
- setNodeRef: setDraggableNodeRef,
6380
- listeners,
6381
- isDragging,
6382
- over,
6383
- setActivatorNodeRef,
6384
- transform
6385
- } = useDraggable({
6386
- id,
6387
- data,
6388
- attributes: { ...defaultAttributes,
6389
- ...userDefinedAttributes
6390
- },
6391
- disabled: disabled.draggable
6392
- });
6393
- const setNodeRef = useCombinedRefs(setDroppableNodeRef, setDraggableNodeRef);
6394
- const isSorting = Boolean(active);
6395
- const displaceItem = isSorting && !disableTransforms && isValidIndex(activeIndex) && isValidIndex(overIndex);
6396
- const shouldDisplaceDragSource = !useDragOverlay && isDragging;
6397
- const dragSourceDisplacement = shouldDisplaceDragSource && displaceItem ? transform : null;
6398
- const strategy = localStrategy != null ? localStrategy : globalStrategy;
6399
- const finalTransform = displaceItem ? dragSourceDisplacement != null ? dragSourceDisplacement : strategy({
6400
- rects: sortedRects,
6401
- activeNodeRect,
6402
- activeIndex,
6403
- overIndex,
6404
- index
6405
- }) : null;
6406
- const newIndex = isValidIndex(activeIndex) && isValidIndex(overIndex) ? getNewIndex({
6407
- id,
6408
- items,
6409
- activeIndex,
6410
- overIndex
6411
- }) : index;
6412
- const activeId = active == null ? void 0 : active.id;
6413
- const previous = useRef({
6414
- activeId,
6415
- items,
6416
- newIndex,
6417
- containerId
6418
- });
6419
- const itemsHaveChanged = items !== previous.current.items;
6420
- const shouldAnimateLayoutChanges = animateLayoutChanges({
6421
- active,
6422
- containerId,
6423
- isDragging,
6424
- isSorting,
6425
- id,
6426
- index,
6427
- items,
6428
- newIndex: previous.current.newIndex,
6429
- previousItems: previous.current.items,
6430
- previousContainerId: previous.current.containerId,
6431
- transition,
6432
- wasDragging: previous.current.activeId != null
6433
- });
6434
- const derivedTransform = useDerivedTransform({
6435
- disabled: !shouldAnimateLayoutChanges,
6436
- index,
6437
- node,
6438
- rect
6439
- });
6440
- useEffect(() => {
6441
- if (isSorting && previous.current.newIndex !== newIndex) {
6442
- previous.current.newIndex = newIndex;
6443
- }
6444
-
6445
- if (containerId !== previous.current.containerId) {
6446
- previous.current.containerId = containerId;
6447
- }
6448
-
6449
- if (items !== previous.current.items) {
6450
- previous.current.items = items;
6451
- }
6452
- }, [isSorting, newIndex, containerId, items]);
6453
- useEffect(() => {
6454
- if (activeId === previous.current.activeId) {
6455
- return;
6456
- }
6457
-
6458
- if (activeId != null && previous.current.activeId == null) {
6459
- previous.current.activeId = activeId;
6460
- return;
6461
- }
6462
-
6463
- const timeoutId = setTimeout(() => {
6464
- previous.current.activeId = activeId;
6465
- }, 50);
6466
- return () => clearTimeout(timeoutId);
6467
- }, [activeId]);
6468
- return {
6469
- active,
6470
- activeIndex,
6471
- attributes,
6472
- data,
6473
- rect,
6474
- index,
6475
- newIndex,
6476
- items,
6477
- isOver,
6478
- isSorting,
6479
- isDragging,
6480
- listeners,
6481
- node,
6482
- overIndex,
6483
- over,
6484
- setNodeRef,
6485
- setActivatorNodeRef,
6486
- setDroppableNodeRef,
6487
- setDraggableNodeRef,
6488
- transform: derivedTransform != null ? derivedTransform : finalTransform,
6489
- transition: getTransition()
6490
- };
6491
-
6492
- function getTransition() {
6493
- if ( // Temporarily disable transitions for a single frame to set up derived transforms
6494
- derivedTransform || // Or to prevent items jumping to back to their "new" position when items change
6495
- itemsHaveChanged && previous.current.newIndex === index) {
6496
- return disabledTransition;
6497
- }
6498
-
6499
- if (shouldDisplaceDragSource && !isKeyboardEvent(activatorEvent) || !transition) {
6500
- return undefined;
6501
- }
6502
-
6503
- if (isSorting || shouldAnimateLayoutChanges) {
6504
- return CSS.Transition.toString({ ...transition,
6505
- property: transitionProperty
6506
- });
6507
- }
6508
-
6509
- return undefined;
6510
- }
6511
- }
6512
-
6513
- function normalizeLocalDisabled(localDisabled, globalDisabled) {
6514
- var _localDisabled$dragga, _localDisabled$droppa;
6515
-
6516
- if (typeof localDisabled === 'boolean') {
6517
- return {
6518
- draggable: localDisabled,
6519
- // Backwards compatibility
6520
- droppable: false
6521
- };
6522
- }
6523
-
6524
- return {
6525
- draggable: (_localDisabled$dragga = localDisabled == null ? void 0 : localDisabled.draggable) != null ? _localDisabled$dragga : globalDisabled.draggable,
6526
- droppable: (_localDisabled$droppa = localDisabled == null ? void 0 : localDisabled.droppable) != null ? _localDisabled$droppa : globalDisabled.droppable
6527
- };
6528
- }
6529
-
6530
- [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];
6531
-
6532
- const SettingIcon = (props) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
6533
- "svg",
6534
- {
6535
- xmlns: "http://www.w3.org/2000/svg",
6536
- width: 30,
6537
- height: 30,
6538
- fill: "none",
6539
- ...props,
6540
- children: [
6541
- /* @__PURE__ */ jsxRuntimeExports.jsx("rect", { width: 29, height: 29, x: 0.5, y: 0.5, fill: "#fff", rx: 14.5 }),
6542
- /* @__PURE__ */ jsxRuntimeExports.jsx("rect", { width: 29, height: 29, x: 0.5, y: 0.5, stroke: "#D6E6FE", rx: 14.5 }),
6543
- /* @__PURE__ */ jsxRuntimeExports.jsx(
6544
- "path",
6545
- {
6546
- fill: "#116DFF",
6547
- d: "M16.085 11a1.5 1.5 0 0 1 2.83 0H21v1h-2.085a1.5 1.5 0 0 1-2.83 0H9v-1h5.987M17 11v1h1v-1h-1Zm.5 7a1.5 1.5 0 0 1 1.415 1H21v1h-2.085a1.5 1.5 0 0 1-2.83 0H9v-1h7.085a1.5 1.5 0 0 1 1.415-1Zm-.5 1v1h1v-1h-1Zm4-4v1h-7.085a1.5 1.5 0 0 1-2.83 0H9v-1h2.085a1.5 1.5 0 0 1 2.83 0H21Zm-9 0v1h1v-1h-1Z"
6548
- }
6549
- )
6550
- ]
6551
- }
6552
- );
6553
- const DragIcon = (props) => /* @__PURE__ */ jsxRuntimeExports.jsx(
6554
- "svg",
6555
- {
6556
- xmlns: "http://www.w3.org/2000/svg",
6557
- width: 18,
6558
- height: 24,
6559
- fill: "none",
6560
- ...props,
6561
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
6562
- "path",
6563
- {
6564
- fill: "#116DFF",
6565
- fillRule: "evenodd",
6566
- d: "M6 1h2v2H6V1Zm0 5h2v2H6V6Zm4-5h2v2h-2V1Zm0 5h2v2h-2V6Zm-4 5h2v2H6v-2Zm4 0h2v2h-2v-2Zm-4 5h2v2H6v-2Zm4 0h2v2h-2v-2Zm-4 5h2v2H6v-2Zm4 0h2v2h-2v-2Z",
6567
- clipRule: "evenodd"
6568
- }
6569
- )
6570
- }
6571
- );
6572
-
6573
2193
  const CLASS_PART_SEPARATOR = '-';
6574
2194
  const createClassGroupUtils = config => {
6575
2195
  const classMap = createClassMap(config);
@@ -9525,146 +5145,51 @@ const getDefaultConfig = () => {
9525
5145
  };
9526
5146
  const twMerge = /*#__PURE__*/createTailwindMerge(getDefaultConfig);
9527
5147
 
9528
- const SortableItem = ({
9529
- id,
9530
- children,
9531
- isLastIndex
9532
- }) => {
9533
- const { attributes, listeners, setNodeRef, transform, transition } = useSortable({ id });
9534
- const style = {
9535
- transform: CSS.Transform.toString(transform),
9536
- transition
9537
- };
9538
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(
9539
- "div",
9540
- {
9541
- ref: setNodeRef,
9542
- style,
9543
- className: twMerge(
9544
- "flex items-center border-t-1 !border-t-[#F0F0F0] ",
9545
- isLastIndex ? "!border-b-1 !border-b-[#F0F0F0]" : ""
9546
- ),
9547
- children: [
9548
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "pl-2 pr-3.5 cursor-grab", ...attributes, ...listeners, children: /* @__PURE__ */ jsxRuntimeExports.jsx(DragIcon, {}) }),
9549
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "flex-1", children })
9550
- ]
9551
- }
9552
- );
5148
+ const Tooltip = ({ children, ...props }) => {
5149
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip$1, { ...props, children });
9553
5150
  };
9554
5151
 
9555
- const SettingTable = (props) => {
9556
- const {
9557
- open,
9558
- setOpen,
9559
- title,
9560
- showSetting,
9561
- setDefaultSettingColumnItems,
9562
- defaultSettingColumnItems
9563
- } = props;
9564
- const { handleSubmit, control } = useForm();
9565
- const [columns, setColumns] = useState([]);
9566
- const handleCloseModal = () => {
9567
- setOpen(false);
9568
- };
9569
- const handleOkModal = () => {
9570
- setOpen(false);
9571
- };
9572
- const onSubmit = (data) => {
9573
- console.log("datasubmit", data);
9574
- };
9575
- const handleDragEnd = (event) => {
9576
- const { active, over } = event;
9577
- if (!over || active.id === over.id) return;
9578
- const oldIndex = columns.findIndex((col) => col.key === active.id);
9579
- const newIndex = columns.findIndex((col) => col.key === over.id);
9580
- const newColumns = arrayMove(columns, oldIndex, newIndex);
9581
- setColumns(newColumns);
9582
- };
9583
- useEffect(() => {
9584
- setColumns(defaultSettingColumnItems);
9585
- }, [defaultSettingColumnItems]);
9586
- const titleHeader = () => {
9587
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
9588
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { children: "Cài đặt hiển thị bảng" }),
9589
- /* @__PURE__ */ jsxRuntimeExports.jsx("p", { className: "text-[14px] text-[#5C657D] font-normal", children: "Chọn cột muốn hiển thị và kéo thả vị trí muốn hiển thị" })
9590
- ] });
9591
- };
9592
- const footer = () => {
9593
- const handleCancel = () => {
9594
- setDefaultSettingColumnItems && setDefaultSettingColumnItems(defaultSettingColumnItems);
9595
- setColumns(defaultSettingColumnItems);
9596
- setOpen(false);
9597
- };
9598
- const handleSubmit2 = () => {
9599
- setOpen(false);
9600
- setDefaultSettingColumnItems && setDefaultSettingColumnItems(columns);
9601
- };
9602
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
9603
- /* @__PURE__ */ jsxRuntimeExports.jsx(
9604
- Button,
9605
- {
9606
- className: " !rounded-3xl !text-[#007BE5] !border-[#BDE3FF]",
9607
- onClick: handleCancel,
9608
- children: "Về chế độ mặc định"
9609
- }
9610
- ),
5152
+ const SettingIcon = (props) => /* @__PURE__ */ jsxRuntimeExports.jsxs(
5153
+ "svg",
5154
+ {
5155
+ xmlns: "http://www.w3.org/2000/svg",
5156
+ width: 30,
5157
+ height: 30,
5158
+ fill: "none",
5159
+ ...props,
5160
+ children: [
5161
+ /* @__PURE__ */ jsxRuntimeExports.jsx("rect", { width: 29, height: 29, x: 0.5, y: 0.5, fill: "#fff", rx: 14.5 }),
5162
+ /* @__PURE__ */ jsxRuntimeExports.jsx("rect", { width: 29, height: 29, x: 0.5, y: 0.5, stroke: "#D6E6FE", rx: 14.5 }),
9611
5163
  /* @__PURE__ */ jsxRuntimeExports.jsx(
9612
- Button,
5164
+ "path",
9613
5165
  {
9614
- className: "ml-2 !rounded-3xl !bg-[#007BE5] !text-[white] !border-[#007BE5]",
9615
- onClick: handleSubmit2,
9616
- children: "Xác nhận"
5166
+ fill: "#116DFF",
5167
+ d: "M16.085 11a1.5 1.5 0 0 1 2.83 0H21v1h-2.085a1.5 1.5 0 0 1-2.83 0H9v-1h5.987M17 11v1h1v-1h-1Zm.5 7a1.5 1.5 0 0 1 1.415 1H21v1h-2.085a1.5 1.5 0 0 1-2.83 0H9v-1h7.085a1.5 1.5 0 0 1 1.415-1Zm-.5 1v1h1v-1h-1Zm4-4v1h-7.085a1.5 1.5 0 0 1-2.83 0H9v-1h2.085a1.5 1.5 0 0 1 2.83 0H21Zm-9 0v1h1v-1h-1Z"
9617
5168
  }
9618
5169
  )
9619
- ] });
9620
- };
9621
- if (!showSetting) return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {});
9622
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
9623
- Modal,
5170
+ ]
5171
+ }
5172
+ );
5173
+
5174
+ const EditableCell = ({
5175
+ editing,
5176
+ dataIndex,
5177
+ inputType,
5178
+ children,
5179
+ control,
5180
+ ...restProps
5181
+ }) => {
5182
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("td", { ...restProps, children: editing ? /* @__PURE__ */ jsxRuntimeExports.jsx(
5183
+ PnkxField,
9624
5184
  {
9625
- open,
9626
- title: title || titleHeader(),
9627
- closable: true,
9628
- onClose: handleCloseModal,
9629
- onOk: handleOkModal,
9630
- className: "setting-table-modal",
9631
- onSubmit: handleSubmit(onSubmit),
9632
- footer: footer(),
9633
- onCancel: handleCloseModal,
9634
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(DndContext, { collisionDetection: closestCenter, onDragEnd: handleDragEnd, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
9635
- SortableContext,
9636
- {
9637
- items: columns.map((item) => String(item.key)),
9638
- strategy: verticalListSortingStrategy,
9639
- children: columns.map((item, index) => {
9640
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
9641
- SortableItem,
9642
- {
9643
- id: String(item.key),
9644
- isLastIndex: index === columns.length - 1,
9645
- children: /* @__PURE__ */ jsxRuntimeExports.jsx(
9646
- SettingColumnItem,
9647
- {
9648
- lable: String(item.title),
9649
- control,
9650
- name: item.key
9651
- }
9652
- )
9653
- },
9654
- item.key
9655
- );
9656
- })
9657
- }
9658
- ) })
5185
+ name: dataIndex,
5186
+ control,
5187
+ component: Input,
5188
+ type: inputType
9659
5189
  }
9660
- );
9661
- };
9662
-
9663
- const Tooltip = ({ children, ...props }) => {
9664
- return /* @__PURE__ */ jsxRuntimeExports.jsx(Tooltip$1, { ...props, children });
5190
+ ) : children });
9665
5191
  };
9666
-
9667
- css`
5192
+ const tableCss = css`
9668
5193
  .ant-table-cell::before {
9669
5194
  display: none !important;
9670
5195
  }
@@ -9801,7 +5326,7 @@ const Table = ({
9801
5326
  }
9802
5327
  }
9803
5328
  ];
9804
- columnsEditable.map(
5329
+ const mergedColumns = columnsEditable.map(
9805
5330
  (col) => {
9806
5331
  if (!col.editable) return col;
9807
5332
  return {
@@ -9860,7 +5385,7 @@ const Table = ({
9860
5385
  {
9861
5386
  rowKey,
9862
5387
  dataSource: data,
9863
- columns,
5388
+ columns: mergedColumns,
9864
5389
  pagination: paginationConfig,
9865
5390
  loading,
9866
5391
  rowSelection,
@@ -9871,19 +5396,13 @@ const Table = ({
9871
5396
  locale: {
9872
5397
  emptyText: /* @__PURE__ */ jsxRuntimeExports.jsx(EmptyTable, {})
9873
5398
  },
5399
+ rowClassName: (_, index) => `table-row-${index % 2 === 0 ? "even" : "odd"}`,
5400
+ className: cx(tableCss, className),
5401
+ components: editable ? {
5402
+ body: { cell: EditableCell }
5403
+ } : void 0,
9874
5404
  ...rest
9875
5405
  }
9876
- ),
9877
- /* @__PURE__ */ jsxRuntimeExports.jsx(
9878
- SettingTable,
9879
- {
9880
- open: openSetting,
9881
- setOpen: setOpenStting,
9882
- title: titleSettingTableModal,
9883
- showSetting,
9884
- defaultSettingColumnItems: columns,
9885
- setDefaultSettingColumnItems: setColumns
9886
- }
9887
5406
  )
9888
5407
  ] });
9889
5408
  const renderTableContent = () => {
@@ -9897,6 +5416,10 @@ const Table = ({
9897
5416
  return renderTableContent();
9898
5417
  };
9899
5418
 
5419
+ const Modal = ({ children, onOk, onSubmit, ...rest }) => {
5420
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(Modal$1, { onOk: onSubmit ? onSubmit : onOk, ...rest, children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "max-h-[20rem] overflow-y-auto", children: onSubmit ? /* @__PURE__ */ jsxRuntimeExports.jsx("form", { onSubmit, children }) : children }) });
5421
+ };
5422
+
9900
5423
  const createStoreImpl = (createState) => {
9901
5424
  let state;
9902
5425
  const listeners = /* @__PURE__ */ new Set();
@@ -16748,7 +12271,7 @@ const Appfix = ({ children, ...rest }) => {
16748
12271
  };
16749
12272
 
16750
12273
  const AutoComplete = (props) => {
16751
- return /* @__PURE__ */ jsxRuntimeExports.jsx(AutoComplete$1, { ...props, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Input, {}) });
12274
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(AutoComplete$1, { ...props, children: /* @__PURE__ */ jsxRuntimeExports.jsx(Input$1, {}) });
16752
12275
  };
16753
12276
 
16754
12277
  const PnkxCollapse = (props) => {