@acvl/frontend-components 0.0.13 → 0.0.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/cjs/index.js CHANGED
@@ -93,6 +93,7 @@ var RefreshIcon = require('@mui/icons-material/Refresh');
93
93
  var Pagination = require('@mui/material/Pagination');
94
94
  var sortable = require('@dnd-kit/sortable');
95
95
  var utilities = require('@dnd-kit/utilities');
96
+ var core$1 = require('@dnd-kit/core');
96
97
  var modifiers = require('@dnd-kit/modifiers');
97
98
  var CloseIcon = require('@mui/icons-material/Close');
98
99
  var ErrorOutlineIcon = require('@mui/icons-material/ErrorOutline');
@@ -7408,7 +7409,7 @@ function memoize(fn) {
7408
7409
  };
7409
7410
  }
7410
7411
 
7411
- const properties$1 = {
7412
+ const properties = {
7412
7413
  m: 'margin',
7413
7414
  p: 'padding'
7414
7415
  };
@@ -7440,7 +7441,7 @@ const getCssProperties = memoize(prop => {
7440
7441
  }
7441
7442
  }
7442
7443
  const [a, b] = prop.split('');
7443
- const property = properties$1[a];
7444
+ const property = properties[a];
7444
7445
  const direction = directions[b] || '';
7445
7446
  return Array.isArray(direction) ? direction.map(dir => property + dir) : [property + direction];
7446
7447
  });
@@ -9487,7 +9488,7 @@ const _excluded$C = ["enableAccessibleFieldDOMStructure"],
9487
9488
  _excluded6 = ["ownerState"],
9488
9489
  _excluded7 = ["ownerState"],
9489
9490
  _excluded8 = ["InputProps", "inputProps"];
9490
- const noop$3 = () => {};
9491
+ const noop$2 = () => {};
9491
9492
  const cleanFieldResponse = _ref => {
9492
9493
  let {
9493
9494
  enableAccessibleFieldDOMStructure
@@ -9504,7 +9505,7 @@ const cleanFieldResponse = _ref => {
9504
9505
  openPickerAriaLabel
9505
9506
  } = fieldResponse,
9506
9507
  other = _objectWithoutPropertiesLoose(fieldResponse, _excluded2$6);
9507
- const mergedInputProps = version.major >= 6 && other?.slotProps?.input ? mergeSlotProps(other?.slotProps?.input, InputProps) : noop$3;
9508
+ const mergedInputProps = version.major >= 6 && other?.slotProps?.input ? mergeSlotProps(other?.slotProps?.input, InputProps) : noop$2;
9508
9509
  return {
9509
9510
  clearable,
9510
9511
  onClear,
@@ -9539,8 +9540,8 @@ const cleanFieldResponse = _ref => {
9539
9540
  openPickerAriaLabel
9540
9541
  } = fieldResponse,
9541
9542
  other = _objectWithoutPropertiesLoose(fieldResponse, _excluded3$1);
9542
- const mergedInputProps = version.major >= 6 && other?.slotProps?.input ? mergeSlotProps(other?.slotProps?.input, InputProps) : noop$3;
9543
- const mergedHtmlInputProps = version.major >= 6 && other?.slotProps?.htmlInput ? mergeSlotProps(other?.slotProps?.htmlInput, inputProps) : noop$3;
9543
+ const mergedInputProps = version.major >= 6 && other?.slotProps?.input ? mergeSlotProps(other?.slotProps?.input, InputProps) : noop$2;
9544
+ const mergedHtmlInputProps = version.major >= 6 && other?.slotProps?.htmlInput ? mergeSlotProps(other?.slotProps?.htmlInput, inputProps) : noop$2;
9544
9545
  return {
9545
9546
  clearable,
9546
9547
  onClear,
@@ -11955,7 +11956,7 @@ Transition.propTypes = process.env.NODE_ENV !== "production" ? {
11955
11956
  onExited: PropTypes.func
11956
11957
  } : {}; // Name the function so it is clearer in the documentation
11957
11958
 
11958
- function noop$2() {}
11959
+ function noop$1() {}
11959
11960
 
11960
11961
  Transition.defaultProps = {
11961
11962
  in: false,
@@ -11964,12 +11965,12 @@ Transition.defaultProps = {
11964
11965
  appear: false,
11965
11966
  enter: true,
11966
11967
  exit: true,
11967
- onEnter: noop$2,
11968
- onEntering: noop$2,
11969
- onEntered: noop$2,
11970
- onExit: noop$2,
11971
- onExiting: noop$2,
11972
- onExited: noop$2
11968
+ onEnter: noop$1,
11969
+ onEntering: noop$1,
11970
+ onEntered: noop$1,
11971
+ onExit: noop$1,
11972
+ onExiting: noop$1,
11973
+ onExited: noop$1
11973
11974
  };
11974
11975
  Transition.UNMOUNTED = UNMOUNTED;
11975
11976
  Transition.EXITED = EXITED;
@@ -12904,7 +12905,7 @@ const PickersDayFiller = styles.styled('div', {
12904
12905
  opacity: 0,
12905
12906
  pointerEvents: 'none'
12906
12907
  }));
12907
- const noop$1 = () => {};
12908
+ const noop = () => {};
12908
12909
  const PickersDayRaw = /*#__PURE__*/React__namespace.forwardRef(function PickersDay(inProps, forwardedRef) {
12909
12910
  const props = styles.useThemeProps({
12910
12911
  props: inProps,
@@ -12917,11 +12918,11 @@ const PickersDayRaw = /*#__PURE__*/React__namespace.forwardRef(function PickersD
12917
12918
  isAnimating,
12918
12919
  onClick,
12919
12920
  onDaySelect,
12920
- onFocus = noop$1,
12921
- onBlur = noop$1,
12922
- onKeyDown = noop$1,
12923
- onMouseDown = noop$1,
12924
- onMouseEnter = noop$1,
12921
+ onFocus = noop,
12922
+ onBlur = noop,
12923
+ onKeyDown = noop,
12924
+ onMouseDown = noop,
12925
+ onMouseEnter = noop,
12925
12926
  children,
12926
12927
  day,
12927
12928
  selected,
@@ -26625,10 +26626,12 @@ const SaveCancelButton = (props) => {
26625
26626
  ...props.slotProps?.cancelBtn
26626
26627
  } }), jsxRuntime.jsx(NormalOrIcon, { buttonProps: {
26627
26628
  color: 'secondary',
26629
+ variant: 'contained',
26628
26630
  startIcon: jsxRuntime.jsx(SaveIcon, {}),
26629
26631
  type: 'submit',
26630
26632
  form: 'formulario',
26631
26633
  sx: { height: 1 },
26634
+ children: 'Guardar',
26632
26635
  ...props.slotProps?.saveBtn
26633
26636
  } })] }));
26634
26637
  };
@@ -27269,7 +27272,7 @@ function CustomPagination() {
27269
27272
  }
27270
27273
 
27271
27274
  const DraggableRow = (params) => {
27272
- const { attributes, listeners, setNodeRef, transform, transition, } = sortable.useSortable({ id: params.rowId });
27275
+ const { attributes, listeners, setNodeRef, transform, transition, } = sortable.useSortable({ id: params.rowId.toString() });
27273
27276
  const style = {
27274
27277
  transform: utilities.CSS.Transform.toString(transform),
27275
27278
  transition
@@ -27286,3458 +27289,179 @@ const DraggableRow = (params) => {
27286
27289
  } }), jsxRuntime.jsx(xDataGrid.GridRow, { ...params })] }));
27287
27290
  };
27288
27291
 
27289
- const hiddenStyles = {
27290
- display: 'none'
27292
+ const EditGridWrapper = (props) => {
27293
+ const notifications = core.useNotifications();
27294
+ // ======================|| EDIT ||====================== //
27295
+ const [edit, setEdit] = React.useState(false);
27296
+ const [editMutation, { isLoading: loadingMutation }] = props.mutation();
27297
+ const [errors, setErrors] = React.useState({});
27298
+ const [rowModesModel, setRowModesModel] = React.useState({});
27299
+ const handleCancelarEdit = () => {
27300
+ setRowModesModel({});
27301
+ };
27302
+ const handleClickEdit = () => {
27303
+ if (edit)
27304
+ handleCancelarEdit();
27305
+ setEdit(prevState => !prevState);
27306
+ };
27307
+ const processRowUpdate = async (newRow, originalRow) => {
27308
+ const original_data = jsonForm({ submitData: originalRow });
27309
+ const data = jsonForm({ submitData: newRow, ...(props.parser ? { props: props.parser } : []) });
27310
+ if (lodash.isEqual(data, original_data))
27311
+ return originalRow;
27312
+ try {
27313
+ const result = await editMutation(data).unwrap();
27314
+ setErrors(prevState => immer.produce(prevState, draft => {
27315
+ delete draft[newRow.id];
27316
+ }));
27317
+ if (props?.postAction)
27318
+ props.postAction(result);
27319
+ notifications.show(`Información actualizada!`, { severity: 'success' });
27320
+ return result.list;
27321
+ }
27322
+ catch (e) {
27323
+ setErrors(prevState => immer.produce(prevState, draft => {
27324
+ draft[newRow.id] = lodash.get(e, 'data');
27325
+ }));
27326
+ notifications.show('Error actualizando información!', { severity: 'error' });
27327
+ }
27328
+ };
27329
+ // ===== || KEYDOWN || ===== //
27330
+ const handleKeyPress = React.useCallback((event) => {
27331
+ if (props.permission) {
27332
+ if (event.ctrlKey && event.shiftKey && event.key === 'E') {
27333
+ event.preventDefault();
27334
+ setEdit(true);
27335
+ }
27336
+ else if (event.key === 'Escape' && event.shiftKey && edit) {
27337
+ event.preventDefault();
27338
+ handleCancelarEdit();
27339
+ setEdit(false);
27340
+ }
27341
+ }
27342
+ }, [edit, props.permission]);
27343
+ React.useEffect(() => {
27344
+ document.addEventListener('keydown', handleKeyPress);
27345
+ return () => {
27346
+ document.removeEventListener('keydown', handleKeyPress);
27347
+ };
27348
+ }, [handleKeyPress]);
27349
+ // ========================= || DRAG N DROP || ========================= //
27350
+ const rowsIterator = props.baseGridRef?.current?.getRowModels().values();
27351
+ const rows = React.useMemo(() => {
27352
+ return rowsIterator ? Array.from(rowsIterator) : [];
27353
+ }, [rowsIterator]);
27354
+ const sensors = core$1.useSensors(core$1.useSensor(core$1.PointerSensor));
27355
+ const handleDragEnd = React.useCallback((event) => {
27356
+ const field = props.dnd?.field;
27357
+ if (!field)
27358
+ return;
27359
+ const { active, over } = event;
27360
+ if (over) {
27361
+ const activeRow = rows.find((row) => row.id == active.id);
27362
+ const overRow = rows.find((row) => row.id == over.id);
27363
+ const mutationArgs = { ...props.dnd?.args, id: activeRow.id };
27364
+ mutationArgs[field] = lodash.get(overRow, field);
27365
+ editMutation(mutationArgs);
27366
+ }
27367
+ }, [editMutation, props.dnd, rows]);
27368
+ // ===== || GRID PROPS || ===== //
27369
+ const editGridProps = mergeSettings({
27370
+ columns: props.columns({
27371
+ displayEdit: edit && props.permission,
27372
+ rowModesModel: rowModesModel,
27373
+ setRowModesModel: setRowModesModel,
27374
+ mutationErrors: errors,
27375
+ options: props.options,
27376
+ }),
27377
+ ...(edit && props.dnd ? { slots: { row: DraggableRow } } : {}),
27378
+ slotProps: {
27379
+ toolbar: {
27380
+ extraButtons: [
27381
+ ...(props.permission && !props.disabled ? [{
27382
+ label: edit ? 'Cancelar' : 'Editar',
27383
+ icon: edit ? CancelIcon : EditIcon,
27384
+ onClick: handleClickEdit,
27385
+ }] : []),
27386
+ ]
27387
+ }
27388
+ },
27389
+ onRowEditStart: ({ reason, row }, event) => {
27390
+ if (!lodash.get(row, `obj_permissions.edit`) || (reason === xDataGrid.GridRowEditStartReasons.cellDoubleClick && !edit)) {
27391
+ event.defaultMuiPrevented = true;
27392
+ }
27393
+ },
27394
+ // edit
27395
+ checkboxSelection: !edit,
27396
+ ...(edit ? { onRowClick: undefined } : []),
27397
+ editMode: 'row',
27398
+ rowModesModel: rowModesModel,
27399
+ onRowModesModelChange: setRowModesModel,
27400
+ processRowUpdate: processRowUpdate,
27401
+ loadingParams: [loadingMutation],
27402
+ }, props.dataGridProps);
27403
+ const renderEditGrid = () => (jsxRuntime.jsx(core$1.DndContext, { sensors: sensors, collisionDetection: core$1.closestCenter, onDragEnd: handleDragEnd, modifiers: [
27404
+ modifiers.restrictToVerticalAxis,
27405
+ modifiers.restrictToWindowEdges,
27406
+ modifiers.restrictToParentElement
27407
+ ], autoScroll: false, children: jsxRuntime.jsx(sortable.SortableContext, { items: rows ? rows.map((row) => row.id.toString()) : [], strategy: sortable.verticalListSortingStrategy, children: props.renderFunction({ ...props.renderFunctionProps, dataGridProps: editGridProps }) }) }));
27408
+ return renderEditGrid();
27291
27409
  };
27292
- function HiddenText(_ref) {
27293
- let {
27294
- id,
27295
- value
27296
- } = _ref;
27297
- return React.createElement("div", {
27298
- id: id,
27299
- style: hiddenStyles
27300
- }, value);
27301
- }
27302
-
27303
- function LiveRegion(_ref) {
27304
- let {
27305
- id,
27306
- announcement,
27307
- ariaLiveType = "assertive"
27308
- } = _ref;
27309
- // Hide element visually but keep it readable by screen readers
27310
- const visuallyHidden = {
27311
- position: 'fixed',
27312
- top: 0,
27313
- left: 0,
27314
- width: 1,
27315
- height: 1,
27316
- margin: -1,
27317
- border: 0,
27318
- padding: 0,
27319
- overflow: 'hidden',
27320
- clip: 'rect(0 0 0 0)',
27321
- clipPath: 'inset(100%)',
27322
- whiteSpace: 'nowrap'
27323
- };
27324
- return React.createElement("div", {
27325
- id: id,
27326
- style: visuallyHidden,
27327
- role: "status",
27328
- "aria-live": ariaLiveType,
27329
- "aria-atomic": true
27330
- }, announcement);
27331
- }
27332
-
27333
- function useAnnouncement() {
27334
- const [announcement, setAnnouncement] = React.useState('');
27335
- const announce = React.useCallback(value => {
27336
- if (value != null) {
27337
- setAnnouncement(value);
27338
- }
27339
- }, []);
27340
- return {
27341
- announce,
27342
- announcement
27343
- };
27344
- }
27345
-
27346
- const DndMonitorContext = /*#__PURE__*/React.createContext(null);
27347
-
27348
- function useDndMonitor(listener) {
27349
- const registerListener = React.useContext(DndMonitorContext);
27350
- React.useEffect(() => {
27351
- if (!registerListener) {
27352
- throw new Error('useDndMonitor must be used within a children of <DndContext>');
27353
- }
27354
-
27355
- const unsubscribe = registerListener(listener);
27356
- return unsubscribe;
27357
- }, [listener, registerListener]);
27358
- }
27359
-
27360
- function useDndMonitorProvider() {
27361
- const [listeners] = React.useState(() => new Set());
27362
- const registerListener = React.useCallback(listener => {
27363
- listeners.add(listener);
27364
- return () => listeners.delete(listener);
27365
- }, [listeners]);
27366
- const dispatch = React.useCallback(_ref => {
27367
- let {
27368
- type,
27369
- event
27370
- } = _ref;
27371
- listeners.forEach(listener => {
27372
- var _listener$type;
27373
-
27374
- return (_listener$type = listener[type]) == null ? void 0 : _listener$type.call(listener, event);
27375
- });
27376
- }, [listeners]);
27377
- return [dispatch, registerListener];
27378
- }
27379
27410
 
27380
- const defaultScreenReaderInstructions = {
27381
- 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 "
27411
+ const editColumn = (props) => {
27412
+ if (!props)
27413
+ return [];
27414
+ if (!props.displayEdit)
27415
+ return [];
27416
+ const handleEditClick = (id) => () => {
27417
+ props.setRowModesModel({ ...props.rowModesModel, [id]: { mode: xDataGrid.GridRowModes.Edit } });
27418
+ };
27419
+ const handleSaveClick = (id) => () => {
27420
+ props.setRowModesModel({ ...props.rowModesModel, [id]: { mode: xDataGrid.GridRowModes.View } });
27421
+ };
27422
+ const handleCancelClick = (id) => () => {
27423
+ props.setRowModesModel({
27424
+ ...props.rowModesModel,
27425
+ [id]: { mode: xDataGrid.GridRowModes.View, ignoreModifications: true },
27426
+ });
27427
+ };
27428
+ return [{
27429
+ field: 'edit',
27430
+ headerName: 'Editar',
27431
+ type: 'actions',
27432
+ width: 80,
27433
+ cellClassName: 'actions',
27434
+ getActions: ({ id, row }) => {
27435
+ const canEdit = get(row, 'obj_permissions.edit');
27436
+ const isInEditMode = props.rowModesModel[id]?.mode === xDataGrid.GridRowModes.Edit;
27437
+ if (isInEditMode) {
27438
+ return [
27439
+ jsxRuntime.jsx(xDataGrid.GridActionsCellItem, { icon: jsxRuntime.jsx(SaveIcon, {}), label: 'Guardar', color: 'primary', onClick: handleSaveClick(id) }, 'save'),
27440
+ jsxRuntime.jsx(xDataGrid.GridActionsCellItem, { icon: jsxRuntime.jsx(CancelIcon, {}), label: 'Cancelar', className: 'textPrimary', onClick: handleCancelClick(id), color: 'inherit' }, 'cancel'),
27441
+ ];
27442
+ }
27443
+ return [
27444
+ jsxRuntime.jsx(xDataGrid.GridActionsCellItem, { icon: jsxRuntime.jsx(EditIcon, { sx: { color: canEdit ? 'black' : 'inherit' } }), label: 'Editar', className: 'textPrimary', onClick: handleEditClick(id), disabled: !canEdit }, 'edit'),
27445
+ ];
27446
+ }
27447
+ }];
27382
27448
  };
27383
- const defaultAnnouncements = {
27384
- onDragStart(_ref) {
27385
- let {
27386
- active
27387
- } = _ref;
27388
- return "Picked up draggable item " + active.id + ".";
27389
- },
27390
-
27391
- onDragOver(_ref2) {
27392
- let {
27393
- active,
27394
- over
27395
- } = _ref2;
27396
-
27397
- if (over) {
27398
- return "Draggable item " + active.id + " was moved over droppable area " + over.id + ".";
27399
- }
27400
-
27401
- return "Draggable item " + active.id + " is no longer over a droppable area.";
27402
- },
27403
-
27404
- onDragEnd(_ref3) {
27405
- let {
27406
- active,
27407
- over
27408
- } = _ref3;
27409
-
27410
- if (over) {
27411
- return "Draggable item " + active.id + " was dropped over droppable area " + over.id;
27412
- }
27413
-
27414
- return "Draggable item " + active.id + " was dropped.";
27415
- },
27416
-
27417
- onDragCancel(_ref4) {
27418
- let {
27419
- active
27420
- } = _ref4;
27421
- return "Dragging was cancelled. Draggable item " + active.id + " was dropped.";
27422
- }
27423
27449
 
27424
- };
27425
-
27426
- function Accessibility(_ref) {
27427
- let {
27428
- announcements = defaultAnnouncements,
27429
- container,
27430
- hiddenTextDescribedById,
27431
- screenReaderInstructions = defaultScreenReaderInstructions
27432
- } = _ref;
27433
- const {
27434
- announce,
27435
- announcement
27436
- } = useAnnouncement();
27437
- const liveRegionId = utilities.useUniqueId("DndLiveRegion");
27438
- const [mounted, setMounted] = React.useState(false);
27439
- React.useEffect(() => {
27440
- setMounted(true);
27441
- }, []);
27442
- useDndMonitor(React.useMemo(() => ({
27443
- onDragStart(_ref2) {
27444
- let {
27445
- active
27446
- } = _ref2;
27447
- announce(announcements.onDragStart({
27448
- active
27449
- }));
27450
- },
27451
-
27452
- onDragMove(_ref3) {
27453
- let {
27454
- active,
27455
- over
27456
- } = _ref3;
27457
-
27458
- if (announcements.onDragMove) {
27459
- announce(announcements.onDragMove({
27460
- active,
27461
- over
27462
- }));
27463
- }
27464
- },
27465
-
27466
- onDragOver(_ref4) {
27467
- let {
27468
- active,
27469
- over
27470
- } = _ref4;
27471
- announce(announcements.onDragOver({
27472
- active,
27473
- over
27474
- }));
27475
- },
27476
-
27477
- onDragEnd(_ref5) {
27478
- let {
27479
- active,
27480
- over
27481
- } = _ref5;
27482
- announce(announcements.onDragEnd({
27483
- active,
27484
- over
27485
- }));
27486
- },
27487
-
27488
- onDragCancel(_ref6) {
27489
- let {
27490
- active,
27491
- over
27492
- } = _ref6;
27493
- announce(announcements.onDragCancel({
27494
- active,
27495
- over
27496
- }));
27497
- }
27498
-
27499
- }), [announce, announcements]));
27500
-
27501
- if (!mounted) {
27502
- return null;
27503
- }
27504
-
27505
- const markup = React.createElement(React.Fragment, null, React.createElement(HiddenText, {
27506
- id: hiddenTextDescribedById,
27507
- value: screenReaderInstructions.draggable
27508
- }), React.createElement(LiveRegion, {
27509
- id: liveRegionId,
27510
- announcement: announcement
27511
- }));
27512
- return container ? ReactDOM.createPortal(markup, container) : markup;
27513
- }
27514
-
27515
- var Action;
27516
-
27517
- (function (Action) {
27518
- Action["DragStart"] = "dragStart";
27519
- Action["DragMove"] = "dragMove";
27520
- Action["DragEnd"] = "dragEnd";
27521
- Action["DragCancel"] = "dragCancel";
27522
- Action["DragOver"] = "dragOver";
27523
- Action["RegisterDroppable"] = "registerDroppable";
27524
- Action["SetDroppableDisabled"] = "setDroppableDisabled";
27525
- Action["UnregisterDroppable"] = "unregisterDroppable";
27526
- })(Action || (Action = {}));
27527
-
27528
- function noop() {}
27529
-
27530
- function useSensor(sensor, options) {
27531
- return React.useMemo(() => ({
27532
- sensor,
27533
- options: {}
27534
- }), // eslint-disable-next-line react-hooks/exhaustive-deps
27535
- [sensor, options]);
27536
- }
27537
-
27538
- function useSensors() {
27539
- for (var _len = arguments.length, sensors = new Array(_len), _key = 0; _key < _len; _key++) {
27540
- sensors[_key] = arguments[_key];
27541
- }
27542
-
27543
- return React.useMemo(() => [...sensors].filter(sensor => sensor != null), // eslint-disable-next-line react-hooks/exhaustive-deps
27544
- [...sensors]);
27545
- }
27546
-
27547
- const defaultCoordinates = /*#__PURE__*/Object.freeze({
27548
- x: 0,
27549
- y: 0
27550
- });
27551
-
27552
- /**
27553
- * Returns the distance between two points
27554
- */
27555
- function distanceBetween(p1, p2) {
27556
- return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
27557
- }
27558
-
27559
- /**
27560
- * Sort collisions from smallest to greatest value
27561
- */
27562
- function sortCollisionsAsc(_ref, _ref2) {
27563
- let {
27564
- data: {
27565
- value: a
27566
- }
27567
- } = _ref;
27568
- let {
27569
- data: {
27570
- value: b
27571
- }
27572
- } = _ref2;
27573
- return a - b;
27574
- }
27575
- /**
27576
- * Sort collisions from greatest to smallest value
27577
- */
27578
-
27579
- function sortCollisionsDesc(_ref3, _ref4) {
27580
- let {
27581
- data: {
27582
- value: a
27583
- }
27584
- } = _ref3;
27585
- let {
27586
- data: {
27587
- value: b
27588
- }
27589
- } = _ref4;
27590
- return b - a;
27591
- }
27592
- function getFirstCollision(collisions, property) {
27593
- if (!collisions || collisions.length === 0) {
27594
- return null;
27595
- }
27596
-
27597
- const [firstCollision] = collisions;
27598
- return firstCollision[property] ;
27599
- }
27600
-
27601
- /**
27602
- * Returns the coordinates of the center of a given ClientRect
27603
- */
27604
-
27605
- function centerOfRectangle(rect, left, top) {
27606
- if (left === void 0) {
27607
- left = rect.left;
27608
- }
27609
-
27610
- if (top === void 0) {
27611
- top = rect.top;
27612
- }
27613
-
27614
- return {
27615
- x: left + rect.width * 0.5,
27616
- y: top + rect.height * 0.5
27617
- };
27618
- }
27619
- /**
27620
- * Returns the closest rectangles from an array of rectangles to the center of a given
27621
- * rectangle.
27622
- */
27623
-
27624
-
27625
- const closestCenter = _ref => {
27626
- let {
27627
- collisionRect,
27628
- droppableRects,
27629
- droppableContainers
27630
- } = _ref;
27631
- const centerRect = centerOfRectangle(collisionRect, collisionRect.left, collisionRect.top);
27632
- const collisions = [];
27633
-
27634
- for (const droppableContainer of droppableContainers) {
27635
- const {
27636
- id
27637
- } = droppableContainer;
27638
- const rect = droppableRects.get(id);
27639
-
27640
- if (rect) {
27641
- const distBetween = distanceBetween(centerOfRectangle(rect), centerRect);
27642
- collisions.push({
27643
- id,
27644
- data: {
27645
- droppableContainer,
27646
- value: distBetween
27647
- }
27648
- });
27649
- }
27650
- }
27651
-
27652
- return collisions.sort(sortCollisionsAsc);
27653
- };
27654
-
27655
- /**
27656
- * Returns the intersecting rectangle area between two rectangles
27657
- */
27658
-
27659
- function getIntersectionRatio(entry, target) {
27660
- const top = Math.max(target.top, entry.top);
27661
- const left = Math.max(target.left, entry.left);
27662
- const right = Math.min(target.left + target.width, entry.left + entry.width);
27663
- const bottom = Math.min(target.top + target.height, entry.top + entry.height);
27664
- const width = right - left;
27665
- const height = bottom - top;
27666
-
27667
- if (left < right && top < bottom) {
27668
- const targetArea = target.width * target.height;
27669
- const entryArea = entry.width * entry.height;
27670
- const intersectionArea = width * height;
27671
- const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea);
27672
- return Number(intersectionRatio.toFixed(4));
27673
- } // Rectangles do not overlap, or overlap has an area of zero (edge/corner overlap)
27674
-
27675
-
27676
- return 0;
27677
- }
27678
- /**
27679
- * Returns the rectangles that has the greatest intersection area with a given
27680
- * rectangle in an array of rectangles.
27681
- */
27682
-
27683
- const rectIntersection = _ref => {
27684
- let {
27685
- collisionRect,
27686
- droppableRects,
27687
- droppableContainers
27688
- } = _ref;
27689
- const collisions = [];
27690
-
27691
- for (const droppableContainer of droppableContainers) {
27692
- const {
27693
- id
27694
- } = droppableContainer;
27695
- const rect = droppableRects.get(id);
27696
-
27697
- if (rect) {
27698
- const intersectionRatio = getIntersectionRatio(rect, collisionRect);
27699
-
27700
- if (intersectionRatio > 0) {
27701
- collisions.push({
27702
- id,
27703
- data: {
27704
- droppableContainer,
27705
- value: intersectionRatio
27706
- }
27707
- });
27708
- }
27709
- }
27710
- }
27711
-
27712
- return collisions.sort(sortCollisionsDesc);
27713
- };
27714
-
27715
- function adjustScale(transform, rect1, rect2) {
27716
- return { ...transform,
27717
- scaleX: rect1 && rect2 ? rect1.width / rect2.width : 1,
27718
- scaleY: rect1 && rect2 ? rect1.height / rect2.height : 1
27719
- };
27720
- }
27721
-
27722
- function getRectDelta(rect1, rect2) {
27723
- return rect1 && rect2 ? {
27724
- x: rect1.left - rect2.left,
27725
- y: rect1.top - rect2.top
27726
- } : defaultCoordinates;
27727
- }
27728
-
27729
- function createRectAdjustmentFn(modifier) {
27730
- return function adjustClientRect(rect) {
27731
- for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
27732
- adjustments[_key - 1] = arguments[_key];
27733
- }
27734
-
27735
- return adjustments.reduce((acc, adjustment) => ({ ...acc,
27736
- top: acc.top + modifier * adjustment.y,
27737
- bottom: acc.bottom + modifier * adjustment.y,
27738
- left: acc.left + modifier * adjustment.x,
27739
- right: acc.right + modifier * adjustment.x
27740
- }), { ...rect
27741
- });
27742
- };
27743
- }
27744
- const getAdjustedRect = /*#__PURE__*/createRectAdjustmentFn(1);
27745
-
27746
- function parseTransform(transform) {
27747
- if (transform.startsWith('matrix3d(')) {
27748
- const transformArray = transform.slice(9, -1).split(/, /);
27749
- return {
27750
- x: +transformArray[12],
27751
- y: +transformArray[13],
27752
- scaleX: +transformArray[0],
27753
- scaleY: +transformArray[5]
27754
- };
27755
- } else if (transform.startsWith('matrix(')) {
27756
- const transformArray = transform.slice(7, -1).split(/, /);
27757
- return {
27758
- x: +transformArray[4],
27759
- y: +transformArray[5],
27760
- scaleX: +transformArray[0],
27761
- scaleY: +transformArray[3]
27762
- };
27763
- }
27764
-
27765
- return null;
27766
- }
27767
-
27768
- function inverseTransform(rect, transform, transformOrigin) {
27769
- const parsedTransform = parseTransform(transform);
27770
-
27771
- if (!parsedTransform) {
27772
- return rect;
27773
- }
27774
-
27775
- const {
27776
- scaleX,
27777
- scaleY,
27778
- x: translateX,
27779
- y: translateY
27780
- } = parsedTransform;
27781
- const x = rect.left - translateX - (1 - scaleX) * parseFloat(transformOrigin);
27782
- const y = rect.top - translateY - (1 - scaleY) * parseFloat(transformOrigin.slice(transformOrigin.indexOf(' ') + 1));
27783
- const w = scaleX ? rect.width / scaleX : rect.width;
27784
- const h = scaleY ? rect.height / scaleY : rect.height;
27785
- return {
27786
- width: w,
27787
- height: h,
27788
- top: y,
27789
- right: x + w,
27790
- bottom: y + h,
27791
- left: x
27792
- };
27793
- }
27794
-
27795
- const defaultOptions = {
27796
- ignoreTransform: false
27797
- };
27798
- /**
27799
- * Returns the bounding client rect of an element relative to the viewport.
27800
- */
27801
-
27802
- function getClientRect(element, options) {
27803
- if (options === void 0) {
27804
- options = defaultOptions;
27805
- }
27806
-
27807
- let rect = element.getBoundingClientRect();
27808
-
27809
- if (options.ignoreTransform) {
27810
- const {
27811
- transform,
27812
- transformOrigin
27813
- } = utilities.getWindow(element).getComputedStyle(element);
27814
-
27815
- if (transform) {
27816
- rect = inverseTransform(rect, transform, transformOrigin);
27817
- }
27818
- }
27819
-
27820
- const {
27821
- top,
27822
- left,
27823
- width,
27824
- height,
27825
- bottom,
27826
- right
27827
- } = rect;
27828
- return {
27829
- top,
27830
- left,
27831
- width,
27832
- height,
27833
- bottom,
27834
- right
27835
- };
27836
- }
27837
- /**
27838
- * Returns the bounding client rect of an element relative to the viewport.
27839
- *
27840
- * @remarks
27841
- * The ClientRect returned by this method does not take into account transforms
27842
- * applied to the element it measures.
27843
- *
27844
- */
27845
-
27846
- function getTransformAgnosticClientRect(element) {
27847
- return getClientRect(element, {
27848
- ignoreTransform: true
27849
- });
27850
- }
27851
-
27852
- function getWindowClientRect(element) {
27853
- const width = element.innerWidth;
27854
- const height = element.innerHeight;
27855
- return {
27856
- top: 0,
27857
- left: 0,
27858
- right: width,
27859
- bottom: height,
27860
- width,
27861
- height
27862
- };
27863
- }
27864
-
27865
- function isFixed(node, computedStyle) {
27866
- if (computedStyle === void 0) {
27867
- computedStyle = utilities.getWindow(node).getComputedStyle(node);
27868
- }
27869
-
27870
- return computedStyle.position === 'fixed';
27871
- }
27872
-
27873
- function isScrollable(element, computedStyle) {
27874
- if (computedStyle === void 0) {
27875
- computedStyle = utilities.getWindow(element).getComputedStyle(element);
27876
- }
27877
-
27878
- const overflowRegex = /(auto|scroll|overlay)/;
27879
- const properties = ['overflow', 'overflowX', 'overflowY'];
27880
- return properties.some(property => {
27881
- const value = computedStyle[property];
27882
- return typeof value === 'string' ? overflowRegex.test(value) : false;
27883
- });
27884
- }
27885
-
27886
- function getScrollableAncestors(element, limit) {
27887
- const scrollParents = [];
27888
-
27889
- function findScrollableAncestors(node) {
27890
- if (limit != null && scrollParents.length >= limit) {
27891
- return scrollParents;
27892
- }
27893
-
27894
- if (!node) {
27895
- return scrollParents;
27896
- }
27897
-
27898
- if (utilities.isDocument(node) && node.scrollingElement != null && !scrollParents.includes(node.scrollingElement)) {
27899
- scrollParents.push(node.scrollingElement);
27900
- return scrollParents;
27901
- }
27902
-
27903
- if (!utilities.isHTMLElement(node) || utilities.isSVGElement(node)) {
27904
- return scrollParents;
27905
- }
27906
-
27907
- if (scrollParents.includes(node)) {
27908
- return scrollParents;
27909
- }
27910
-
27911
- const computedStyle = utilities.getWindow(element).getComputedStyle(node);
27912
-
27913
- if (node !== element) {
27914
- if (isScrollable(node, computedStyle)) {
27915
- scrollParents.push(node);
27916
- }
27917
- }
27918
-
27919
- if (isFixed(node, computedStyle)) {
27920
- return scrollParents;
27921
- }
27922
-
27923
- return findScrollableAncestors(node.parentNode);
27924
- }
27925
-
27926
- if (!element) {
27927
- return scrollParents;
27928
- }
27929
-
27930
- return findScrollableAncestors(element);
27931
- }
27932
- function getFirstScrollableAncestor(node) {
27933
- const [firstScrollableAncestor] = getScrollableAncestors(node, 1);
27934
- return firstScrollableAncestor != null ? firstScrollableAncestor : null;
27935
- }
27936
-
27937
- function getScrollableElement(element) {
27938
- if (!utilities.canUseDOM || !element) {
27939
- return null;
27940
- }
27941
-
27942
- if (utilities.isWindow(element)) {
27943
- return element;
27944
- }
27945
-
27946
- if (!utilities.isNode(element)) {
27947
- return null;
27948
- }
27949
-
27950
- if (utilities.isDocument(element) || element === utilities.getOwnerDocument(element).scrollingElement) {
27951
- return window;
27952
- }
27953
-
27954
- if (utilities.isHTMLElement(element)) {
27955
- return element;
27956
- }
27957
-
27958
- return null;
27959
- }
27960
-
27961
- function getScrollXCoordinate(element) {
27962
- if (utilities.isWindow(element)) {
27963
- return element.scrollX;
27964
- }
27965
-
27966
- return element.scrollLeft;
27967
- }
27968
- function getScrollYCoordinate(element) {
27969
- if (utilities.isWindow(element)) {
27970
- return element.scrollY;
27971
- }
27972
-
27973
- return element.scrollTop;
27974
- }
27975
- function getScrollCoordinates(element) {
27976
- return {
27977
- x: getScrollXCoordinate(element),
27978
- y: getScrollYCoordinate(element)
27979
- };
27980
- }
27981
-
27982
- var Direction;
27983
-
27984
- (function (Direction) {
27985
- Direction[Direction["Forward"] = 1] = "Forward";
27986
- Direction[Direction["Backward"] = -1] = "Backward";
27987
- })(Direction || (Direction = {}));
27988
-
27989
- function isDocumentScrollingElement(element) {
27990
- if (!utilities.canUseDOM || !element) {
27991
- return false;
27992
- }
27993
-
27994
- return element === document.scrollingElement;
27995
- }
27996
-
27997
- function getScrollPosition(scrollingContainer) {
27998
- const minScroll = {
27999
- x: 0,
28000
- y: 0
28001
- };
28002
- const dimensions = isDocumentScrollingElement(scrollingContainer) ? {
28003
- height: window.innerHeight,
28004
- width: window.innerWidth
28005
- } : {
28006
- height: scrollingContainer.clientHeight,
28007
- width: scrollingContainer.clientWidth
28008
- };
28009
- const maxScroll = {
28010
- x: scrollingContainer.scrollWidth - dimensions.width,
28011
- y: scrollingContainer.scrollHeight - dimensions.height
28012
- };
28013
- const isTop = scrollingContainer.scrollTop <= minScroll.y;
28014
- const isLeft = scrollingContainer.scrollLeft <= minScroll.x;
28015
- const isBottom = scrollingContainer.scrollTop >= maxScroll.y;
28016
- const isRight = scrollingContainer.scrollLeft >= maxScroll.x;
28017
- return {
28018
- isTop,
28019
- isLeft,
28020
- isBottom,
28021
- isRight,
28022
- maxScroll,
28023
- minScroll
28024
- };
28025
- }
28026
-
28027
- const defaultThreshold = {
28028
- x: 0.2,
28029
- y: 0.2
28030
- };
28031
- function getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, _ref, acceleration, thresholdPercentage) {
28032
- let {
28033
- top,
28034
- left,
28035
- right,
28036
- bottom
28037
- } = _ref;
28038
-
28039
- if (acceleration === void 0) {
28040
- acceleration = 10;
28041
- }
28042
-
28043
- if (thresholdPercentage === void 0) {
28044
- thresholdPercentage = defaultThreshold;
28045
- }
28046
-
28047
- const {
28048
- isTop,
28049
- isBottom,
28050
- isLeft,
28051
- isRight
28052
- } = getScrollPosition(scrollContainer);
28053
- const direction = {
28054
- x: 0,
28055
- y: 0
28056
- };
28057
- const speed = {
28058
- x: 0,
28059
- y: 0
28060
- };
28061
- const threshold = {
28062
- height: scrollContainerRect.height * thresholdPercentage.y,
28063
- width: scrollContainerRect.width * thresholdPercentage.x
28064
- };
28065
-
28066
- if (!isTop && top <= scrollContainerRect.top + threshold.height) {
28067
- // Scroll Up
28068
- direction.y = Direction.Backward;
28069
- speed.y = acceleration * Math.abs((scrollContainerRect.top + threshold.height - top) / threshold.height);
28070
- } else if (!isBottom && bottom >= scrollContainerRect.bottom - threshold.height) {
28071
- // Scroll Down
28072
- direction.y = Direction.Forward;
28073
- speed.y = acceleration * Math.abs((scrollContainerRect.bottom - threshold.height - bottom) / threshold.height);
28074
- }
28075
-
28076
- if (!isRight && right >= scrollContainerRect.right - threshold.width) {
28077
- // Scroll Right
28078
- direction.x = Direction.Forward;
28079
- speed.x = acceleration * Math.abs((scrollContainerRect.right - threshold.width - right) / threshold.width);
28080
- } else if (!isLeft && left <= scrollContainerRect.left + threshold.width) {
28081
- // Scroll Left
28082
- direction.x = Direction.Backward;
28083
- speed.x = acceleration * Math.abs((scrollContainerRect.left + threshold.width - left) / threshold.width);
28084
- }
28085
-
28086
- return {
28087
- direction,
28088
- speed
28089
- };
28090
- }
28091
-
28092
- function getScrollElementRect(element) {
28093
- if (element === document.scrollingElement) {
28094
- const {
28095
- innerWidth,
28096
- innerHeight
28097
- } = window;
28098
- return {
28099
- top: 0,
28100
- left: 0,
28101
- right: innerWidth,
28102
- bottom: innerHeight,
28103
- width: innerWidth,
28104
- height: innerHeight
28105
- };
28106
- }
28107
-
28108
- const {
28109
- top,
28110
- left,
28111
- right,
28112
- bottom
28113
- } = element.getBoundingClientRect();
28114
- return {
28115
- top,
28116
- left,
28117
- right,
28118
- bottom,
28119
- width: element.clientWidth,
28120
- height: element.clientHeight
28121
- };
28122
- }
28123
-
28124
- function getScrollOffsets(scrollableAncestors) {
28125
- return scrollableAncestors.reduce((acc, node) => {
28126
- return utilities.add(acc, getScrollCoordinates(node));
28127
- }, defaultCoordinates);
28128
- }
28129
- function getScrollXOffset(scrollableAncestors) {
28130
- return scrollableAncestors.reduce((acc, node) => {
28131
- return acc + getScrollXCoordinate(node);
28132
- }, 0);
28133
- }
28134
- function getScrollYOffset(scrollableAncestors) {
28135
- return scrollableAncestors.reduce((acc, node) => {
28136
- return acc + getScrollYCoordinate(node);
28137
- }, 0);
28138
- }
28139
-
28140
- function scrollIntoViewIfNeeded(element, measure) {
28141
- if (measure === void 0) {
28142
- measure = getClientRect;
28143
- }
28144
-
28145
- if (!element) {
28146
- return;
28147
- }
28148
-
28149
- const {
28150
- top,
28151
- left,
28152
- bottom,
28153
- right
28154
- } = measure(element);
28155
- const firstScrollableAncestor = getFirstScrollableAncestor(element);
28156
-
28157
- if (!firstScrollableAncestor) {
28158
- return;
28159
- }
28160
-
28161
- if (bottom <= 0 || right <= 0 || top >= window.innerHeight || left >= window.innerWidth) {
28162
- element.scrollIntoView({
28163
- block: 'center',
28164
- inline: 'center'
28165
- });
28166
- }
28167
- }
28168
-
28169
- const properties = [['x', ['left', 'right'], getScrollXOffset], ['y', ['top', 'bottom'], getScrollYOffset]];
28170
- class Rect {
28171
- constructor(rect, element) {
28172
- this.rect = void 0;
28173
- this.width = void 0;
28174
- this.height = void 0;
28175
- this.top = void 0;
28176
- this.bottom = void 0;
28177
- this.right = void 0;
28178
- this.left = void 0;
28179
- const scrollableAncestors = getScrollableAncestors(element);
28180
- const scrollOffsets = getScrollOffsets(scrollableAncestors);
28181
- this.rect = { ...rect
28182
- };
28183
- this.width = rect.width;
28184
- this.height = rect.height;
28185
-
28186
- for (const [axis, keys, getScrollOffset] of properties) {
28187
- for (const key of keys) {
28188
- Object.defineProperty(this, key, {
28189
- get: () => {
28190
- const currentOffsets = getScrollOffset(scrollableAncestors);
28191
- const scrollOffsetsDeltla = scrollOffsets[axis] - currentOffsets;
28192
- return this.rect[key] + scrollOffsetsDeltla;
28193
- },
28194
- enumerable: true
28195
- });
28196
- }
28197
- }
28198
-
28199
- Object.defineProperty(this, 'rect', {
28200
- enumerable: false
28201
- });
28202
- }
28203
-
28204
- }
28205
-
28206
- class Listeners {
28207
- constructor(target) {
28208
- this.target = void 0;
28209
- this.listeners = [];
28210
-
28211
- this.removeAll = () => {
28212
- this.listeners.forEach(listener => {
28213
- var _this$target;
28214
-
28215
- return (_this$target = this.target) == null ? void 0 : _this$target.removeEventListener(...listener);
28216
- });
28217
- };
28218
-
28219
- this.target = target;
28220
- }
28221
-
28222
- add(eventName, handler, options) {
28223
- var _this$target2;
28224
-
28225
- (_this$target2 = this.target) == null ? void 0 : _this$target2.addEventListener(eventName, handler, options);
28226
- this.listeners.push([eventName, handler, options]);
28227
- }
28228
-
28229
- }
28230
-
28231
- function getEventListenerTarget(target) {
28232
- // If the `event.target` element is removed from the document events will still be targeted
28233
- // at it, and hence won't always bubble up to the window or document anymore.
28234
- // If there is any risk of an element being removed while it is being dragged,
28235
- // the best practice is to attach the event listeners directly to the target.
28236
- // https://developer.mozilla.org/en-US/docs/Web/API/EventTarget
28237
- const {
28238
- EventTarget
28239
- } = utilities.getWindow(target);
28240
- return target instanceof EventTarget ? target : utilities.getOwnerDocument(target);
28241
- }
28242
-
28243
- function hasExceededDistance(delta, measurement) {
28244
- const dx = Math.abs(delta.x);
28245
- const dy = Math.abs(delta.y);
28246
-
28247
- if (typeof measurement === 'number') {
28248
- return Math.sqrt(dx ** 2 + dy ** 2) > measurement;
28249
- }
28250
-
28251
- if ('x' in measurement && 'y' in measurement) {
28252
- return dx > measurement.x && dy > measurement.y;
28253
- }
28254
-
28255
- if ('x' in measurement) {
28256
- return dx > measurement.x;
28257
- }
28258
-
28259
- if ('y' in measurement) {
28260
- return dy > measurement.y;
28261
- }
28262
-
28263
- return false;
28264
- }
28265
-
28266
- var EventName;
28267
-
28268
- (function (EventName) {
28269
- EventName["Click"] = "click";
28270
- EventName["DragStart"] = "dragstart";
28271
- EventName["Keydown"] = "keydown";
28272
- EventName["ContextMenu"] = "contextmenu";
28273
- EventName["Resize"] = "resize";
28274
- EventName["SelectionChange"] = "selectionchange";
28275
- EventName["VisibilityChange"] = "visibilitychange";
28276
- })(EventName || (EventName = {}));
28277
-
28278
- function preventDefault(event) {
28279
- event.preventDefault();
28280
- }
28281
- function stopPropagation(event) {
28282
- event.stopPropagation();
28283
- }
28284
-
28285
- var KeyboardCode;
28286
-
28287
- (function (KeyboardCode) {
28288
- KeyboardCode["Space"] = "Space";
28289
- KeyboardCode["Down"] = "ArrowDown";
28290
- KeyboardCode["Right"] = "ArrowRight";
28291
- KeyboardCode["Left"] = "ArrowLeft";
28292
- KeyboardCode["Up"] = "ArrowUp";
28293
- KeyboardCode["Esc"] = "Escape";
28294
- KeyboardCode["Enter"] = "Enter";
28295
- KeyboardCode["Tab"] = "Tab";
28296
- })(KeyboardCode || (KeyboardCode = {}));
28297
-
28298
- const defaultKeyboardCodes = {
28299
- start: [KeyboardCode.Space, KeyboardCode.Enter],
28300
- cancel: [KeyboardCode.Esc],
28301
- end: [KeyboardCode.Space, KeyboardCode.Enter, KeyboardCode.Tab]
28302
- };
28303
- const defaultKeyboardCoordinateGetter = (event, _ref) => {
28304
- let {
28305
- currentCoordinates
28306
- } = _ref;
28307
-
28308
- switch (event.code) {
28309
- case KeyboardCode.Right:
28310
- return { ...currentCoordinates,
28311
- x: currentCoordinates.x + 25
28312
- };
28313
-
28314
- case KeyboardCode.Left:
28315
- return { ...currentCoordinates,
28316
- x: currentCoordinates.x - 25
28317
- };
28318
-
28319
- case KeyboardCode.Down:
28320
- return { ...currentCoordinates,
28321
- y: currentCoordinates.y + 25
28322
- };
28323
-
28324
- case KeyboardCode.Up:
28325
- return { ...currentCoordinates,
28326
- y: currentCoordinates.y - 25
28327
- };
28328
- }
28329
-
28330
- return undefined;
28331
- };
28332
-
28333
- class KeyboardSensor {
28334
- constructor(props) {
28335
- this.props = void 0;
28336
- this.autoScrollEnabled = false;
28337
- this.referenceCoordinates = void 0;
28338
- this.listeners = void 0;
28339
- this.windowListeners = void 0;
28340
- this.props = props;
28341
- const {
28342
- event: {
28343
- target
28344
- }
28345
- } = props;
28346
- this.props = props;
28347
- this.listeners = new Listeners(utilities.getOwnerDocument(target));
28348
- this.windowListeners = new Listeners(utilities.getWindow(target));
28349
- this.handleKeyDown = this.handleKeyDown.bind(this);
28350
- this.handleCancel = this.handleCancel.bind(this);
28351
- this.attach();
28352
- }
28353
-
28354
- attach() {
28355
- this.handleStart();
28356
- this.windowListeners.add(EventName.Resize, this.handleCancel);
28357
- this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
28358
- setTimeout(() => this.listeners.add(EventName.Keydown, this.handleKeyDown));
28359
- }
28360
-
28361
- handleStart() {
28362
- const {
28363
- activeNode,
28364
- onStart
28365
- } = this.props;
28366
- const node = activeNode.node.current;
28367
-
28368
- if (node) {
28369
- scrollIntoViewIfNeeded(node);
28370
- }
28371
-
28372
- onStart(defaultCoordinates);
28373
- }
28374
-
28375
- handleKeyDown(event) {
28376
- if (utilities.isKeyboardEvent(event)) {
28377
- const {
28378
- active,
28379
- context,
28380
- options
28381
- } = this.props;
28382
- const {
28383
- keyboardCodes = defaultKeyboardCodes,
28384
- coordinateGetter = defaultKeyboardCoordinateGetter,
28385
- scrollBehavior = 'smooth'
28386
- } = options;
28387
- const {
28388
- code
28389
- } = event;
28390
-
28391
- if (keyboardCodes.end.includes(code)) {
28392
- this.handleEnd(event);
28393
- return;
28394
- }
28395
-
28396
- if (keyboardCodes.cancel.includes(code)) {
28397
- this.handleCancel(event);
28398
- return;
28399
- }
28400
-
28401
- const {
28402
- collisionRect
28403
- } = context.current;
28404
- const currentCoordinates = collisionRect ? {
28405
- x: collisionRect.left,
28406
- y: collisionRect.top
28407
- } : defaultCoordinates;
28408
-
28409
- if (!this.referenceCoordinates) {
28410
- this.referenceCoordinates = currentCoordinates;
28411
- }
28412
-
28413
- const newCoordinates = coordinateGetter(event, {
28414
- active,
28415
- context: context.current,
28416
- currentCoordinates
28417
- });
28418
-
28419
- if (newCoordinates) {
28420
- const coordinatesDelta = utilities.subtract(newCoordinates, currentCoordinates);
28421
- const scrollDelta = {
28422
- x: 0,
28423
- y: 0
28424
- };
28425
- const {
28426
- scrollableAncestors
28427
- } = context.current;
28428
-
28429
- for (const scrollContainer of scrollableAncestors) {
28430
- const direction = event.code;
28431
- const {
28432
- isTop,
28433
- isRight,
28434
- isLeft,
28435
- isBottom,
28436
- maxScroll,
28437
- minScroll
28438
- } = getScrollPosition(scrollContainer);
28439
- const scrollElementRect = getScrollElementRect(scrollContainer);
28440
- const clampedCoordinates = {
28441
- 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)),
28442
- 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))
28443
- };
28444
- const canScrollX = direction === KeyboardCode.Right && !isRight || direction === KeyboardCode.Left && !isLeft;
28445
- const canScrollY = direction === KeyboardCode.Down && !isBottom || direction === KeyboardCode.Up && !isTop;
28446
-
28447
- if (canScrollX && clampedCoordinates.x !== newCoordinates.x) {
28448
- const newScrollCoordinates = scrollContainer.scrollLeft + coordinatesDelta.x;
28449
- const canScrollToNewCoordinates = direction === KeyboardCode.Right && newScrollCoordinates <= maxScroll.x || direction === KeyboardCode.Left && newScrollCoordinates >= minScroll.x;
28450
-
28451
- if (canScrollToNewCoordinates && !coordinatesDelta.y) {
28452
- // We don't need to update coordinates, the scroll adjustment alone will trigger
28453
- // logic to auto-detect the new container we are over
28454
- scrollContainer.scrollTo({
28455
- left: newScrollCoordinates,
28456
- behavior: scrollBehavior
28457
- });
28458
- return;
28459
- }
28460
-
28461
- if (canScrollToNewCoordinates) {
28462
- scrollDelta.x = scrollContainer.scrollLeft - newScrollCoordinates;
28463
- } else {
28464
- scrollDelta.x = direction === KeyboardCode.Right ? scrollContainer.scrollLeft - maxScroll.x : scrollContainer.scrollLeft - minScroll.x;
28465
- }
28466
-
28467
- if (scrollDelta.x) {
28468
- scrollContainer.scrollBy({
28469
- left: -scrollDelta.x,
28470
- behavior: scrollBehavior
28471
- });
28472
- }
28473
-
28474
- break;
28475
- } else if (canScrollY && clampedCoordinates.y !== newCoordinates.y) {
28476
- const newScrollCoordinates = scrollContainer.scrollTop + coordinatesDelta.y;
28477
- const canScrollToNewCoordinates = direction === KeyboardCode.Down && newScrollCoordinates <= maxScroll.y || direction === KeyboardCode.Up && newScrollCoordinates >= minScroll.y;
28478
-
28479
- if (canScrollToNewCoordinates && !coordinatesDelta.x) {
28480
- // We don't need to update coordinates, the scroll adjustment alone will trigger
28481
- // logic to auto-detect the new container we are over
28482
- scrollContainer.scrollTo({
28483
- top: newScrollCoordinates,
28484
- behavior: scrollBehavior
28485
- });
28486
- return;
28487
- }
28488
-
28489
- if (canScrollToNewCoordinates) {
28490
- scrollDelta.y = scrollContainer.scrollTop - newScrollCoordinates;
28491
- } else {
28492
- scrollDelta.y = direction === KeyboardCode.Down ? scrollContainer.scrollTop - maxScroll.y : scrollContainer.scrollTop - minScroll.y;
28493
- }
28494
-
28495
- if (scrollDelta.y) {
28496
- scrollContainer.scrollBy({
28497
- top: -scrollDelta.y,
28498
- behavior: scrollBehavior
28499
- });
28500
- }
28501
-
28502
- break;
28503
- }
28504
- }
28505
-
28506
- this.handleMove(event, utilities.add(utilities.subtract(newCoordinates, this.referenceCoordinates), scrollDelta));
28507
- }
28508
- }
28509
- }
28510
-
28511
- handleMove(event, coordinates) {
28512
- const {
28513
- onMove
28514
- } = this.props;
28515
- event.preventDefault();
28516
- onMove(coordinates);
28517
- }
28518
-
28519
- handleEnd(event) {
28520
- const {
28521
- onEnd
28522
- } = this.props;
28523
- event.preventDefault();
28524
- this.detach();
28525
- onEnd();
28526
- }
28527
-
28528
- handleCancel(event) {
28529
- const {
28530
- onCancel
28531
- } = this.props;
28532
- event.preventDefault();
28533
- this.detach();
28534
- onCancel();
28535
- }
28536
-
28537
- detach() {
28538
- this.listeners.removeAll();
28539
- this.windowListeners.removeAll();
28540
- }
28541
-
28542
- }
28543
- KeyboardSensor.activators = [{
28544
- eventName: 'onKeyDown',
28545
- handler: (event, _ref, _ref2) => {
28546
- let {
28547
- keyboardCodes = defaultKeyboardCodes,
28548
- onActivation
28549
- } = _ref;
28550
- let {
28551
- active
28552
- } = _ref2;
28553
- const {
28554
- code
28555
- } = event.nativeEvent;
28556
-
28557
- if (keyboardCodes.start.includes(code)) {
28558
- const activator = active.activatorNode.current;
28559
-
28560
- if (activator && event.target !== activator) {
28561
- return false;
28562
- }
28563
-
28564
- event.preventDefault();
28565
- onActivation == null ? void 0 : onActivation({
28566
- event: event.nativeEvent
28567
- });
28568
- return true;
28569
- }
28570
-
28571
- return false;
28572
- }
28573
- }];
28574
-
28575
- function isDistanceConstraint(constraint) {
28576
- return Boolean(constraint && 'distance' in constraint);
28577
- }
28578
-
28579
- function isDelayConstraint(constraint) {
28580
- return Boolean(constraint && 'delay' in constraint);
28581
- }
28582
-
28583
- class AbstractPointerSensor {
28584
- constructor(props, events, listenerTarget) {
28585
- var _getEventCoordinates;
28586
-
28587
- if (listenerTarget === void 0) {
28588
- listenerTarget = getEventListenerTarget(props.event.target);
28589
- }
28590
-
28591
- this.props = void 0;
28592
- this.events = void 0;
28593
- this.autoScrollEnabled = true;
28594
- this.document = void 0;
28595
- this.activated = false;
28596
- this.initialCoordinates = void 0;
28597
- this.timeoutId = null;
28598
- this.listeners = void 0;
28599
- this.documentListeners = void 0;
28600
- this.windowListeners = void 0;
28601
- this.props = props;
28602
- this.events = events;
28603
- const {
28604
- event
28605
- } = props;
28606
- const {
28607
- target
28608
- } = event;
28609
- this.props = props;
28610
- this.events = events;
28611
- this.document = utilities.getOwnerDocument(target);
28612
- this.documentListeners = new Listeners(this.document);
28613
- this.listeners = new Listeners(listenerTarget);
28614
- this.windowListeners = new Listeners(utilities.getWindow(target));
28615
- this.initialCoordinates = (_getEventCoordinates = utilities.getEventCoordinates(event)) != null ? _getEventCoordinates : defaultCoordinates;
28616
- this.handleStart = this.handleStart.bind(this);
28617
- this.handleMove = this.handleMove.bind(this);
28618
- this.handleEnd = this.handleEnd.bind(this);
28619
- this.handleCancel = this.handleCancel.bind(this);
28620
- this.handleKeydown = this.handleKeydown.bind(this);
28621
- this.removeTextSelection = this.removeTextSelection.bind(this);
28622
- this.attach();
28623
- }
28624
-
28625
- attach() {
28626
- const {
28627
- events,
28628
- props: {
28629
- options: {
28630
- activationConstraint,
28631
- bypassActivationConstraint
28632
- }
28633
- }
28634
- } = this;
28635
- this.listeners.add(events.move.name, this.handleMove, {
28636
- passive: false
28637
- });
28638
- this.listeners.add(events.end.name, this.handleEnd);
28639
-
28640
- if (events.cancel) {
28641
- this.listeners.add(events.cancel.name, this.handleCancel);
28642
- }
28643
-
28644
- this.windowListeners.add(EventName.Resize, this.handleCancel);
28645
- this.windowListeners.add(EventName.DragStart, preventDefault);
28646
- this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
28647
- this.windowListeners.add(EventName.ContextMenu, preventDefault);
28648
- this.documentListeners.add(EventName.Keydown, this.handleKeydown);
28649
-
28650
- if (activationConstraint) {
28651
- if (bypassActivationConstraint != null && bypassActivationConstraint({
28652
- event: this.props.event,
28653
- activeNode: this.props.activeNode,
28654
- options: this.props.options
28655
- })) {
28656
- return this.handleStart();
28657
- }
28658
-
28659
- if (isDelayConstraint(activationConstraint)) {
28660
- this.timeoutId = setTimeout(this.handleStart, activationConstraint.delay);
28661
- this.handlePending(activationConstraint);
28662
- return;
28663
- }
28664
-
28665
- if (isDistanceConstraint(activationConstraint)) {
28666
- this.handlePending(activationConstraint);
28667
- return;
28668
- }
28669
- }
28670
-
28671
- this.handleStart();
28672
- }
28673
-
28674
- detach() {
28675
- this.listeners.removeAll();
28676
- this.windowListeners.removeAll(); // Wait until the next event loop before removing document listeners
28677
- // This is necessary because we listen for `click` and `selection` events on the document
28678
-
28679
- setTimeout(this.documentListeners.removeAll, 50);
28680
-
28681
- if (this.timeoutId !== null) {
28682
- clearTimeout(this.timeoutId);
28683
- this.timeoutId = null;
28684
- }
28685
- }
28686
-
28687
- handlePending(constraint, offset) {
28688
- const {
28689
- active,
28690
- onPending
28691
- } = this.props;
28692
- onPending(active, constraint, this.initialCoordinates, offset);
28693
- }
28694
-
28695
- handleStart() {
28696
- const {
28697
- initialCoordinates
28698
- } = this;
28699
- const {
28700
- onStart
28701
- } = this.props;
28702
-
28703
- if (initialCoordinates) {
28704
- this.activated = true; // Stop propagation of click events once activation constraints are met
28705
-
28706
- this.documentListeners.add(EventName.Click, stopPropagation, {
28707
- capture: true
28708
- }); // Remove any text selection from the document
28709
-
28710
- this.removeTextSelection(); // Prevent further text selection while dragging
28711
-
28712
- this.documentListeners.add(EventName.SelectionChange, this.removeTextSelection);
28713
- onStart(initialCoordinates);
28714
- }
28715
- }
28716
-
28717
- handleMove(event) {
28718
- var _getEventCoordinates2;
28719
-
28720
- const {
28721
- activated,
28722
- initialCoordinates,
28723
- props
28724
- } = this;
28725
- const {
28726
- onMove,
28727
- options: {
28728
- activationConstraint
28729
- }
28730
- } = props;
28731
-
28732
- if (!initialCoordinates) {
28733
- return;
28734
- }
28735
-
28736
- const coordinates = (_getEventCoordinates2 = utilities.getEventCoordinates(event)) != null ? _getEventCoordinates2 : defaultCoordinates;
28737
- const delta = utilities.subtract(initialCoordinates, coordinates); // Constraint validation
28738
-
28739
- if (!activated && activationConstraint) {
28740
- if (isDistanceConstraint(activationConstraint)) {
28741
- if (activationConstraint.tolerance != null && hasExceededDistance(delta, activationConstraint.tolerance)) {
28742
- return this.handleCancel();
28743
- }
28744
-
28745
- if (hasExceededDistance(delta, activationConstraint.distance)) {
28746
- return this.handleStart();
28747
- }
28748
- }
28749
-
28750
- if (isDelayConstraint(activationConstraint)) {
28751
- if (hasExceededDistance(delta, activationConstraint.tolerance)) {
28752
- return this.handleCancel();
28753
- }
28754
- }
28755
-
28756
- this.handlePending(activationConstraint, delta);
28757
- return;
28758
- }
28759
-
28760
- if (event.cancelable) {
28761
- event.preventDefault();
28762
- }
28763
-
28764
- onMove(coordinates);
28765
- }
28766
-
28767
- handleEnd() {
28768
- const {
28769
- onAbort,
28770
- onEnd
28771
- } = this.props;
28772
- this.detach();
28773
-
28774
- if (!this.activated) {
28775
- onAbort(this.props.active);
28776
- }
28777
-
28778
- onEnd();
28779
- }
28780
-
28781
- handleCancel() {
28782
- const {
28783
- onAbort,
28784
- onCancel
28785
- } = this.props;
28786
- this.detach();
28787
-
28788
- if (!this.activated) {
28789
- onAbort(this.props.active);
28790
- }
28791
-
28792
- onCancel();
28793
- }
28794
-
28795
- handleKeydown(event) {
28796
- if (event.code === KeyboardCode.Esc) {
28797
- this.handleCancel();
28798
- }
28799
- }
28800
-
28801
- removeTextSelection() {
28802
- var _this$document$getSel;
28803
-
28804
- (_this$document$getSel = this.document.getSelection()) == null ? void 0 : _this$document$getSel.removeAllRanges();
28805
- }
28806
-
28807
- }
28808
-
28809
- const events = {
28810
- cancel: {
28811
- name: 'pointercancel'
28812
- },
28813
- move: {
28814
- name: 'pointermove'
28815
- },
28816
- end: {
28817
- name: 'pointerup'
28818
- }
28819
- };
28820
- class PointerSensor extends AbstractPointerSensor {
28821
- constructor(props) {
28822
- const {
28823
- event
28824
- } = props; // Pointer events stop firing if the target is unmounted while dragging
28825
- // Therefore we attach listeners to the owner document instead
28826
-
28827
- const listenerTarget = utilities.getOwnerDocument(event.target);
28828
- super(props, events, listenerTarget);
28829
- }
28830
-
28831
- }
28832
- PointerSensor.activators = [{
28833
- eventName: 'onPointerDown',
28834
- handler: (_ref, _ref2) => {
28835
- let {
28836
- nativeEvent: event
28837
- } = _ref;
28838
- let {
28839
- onActivation
28840
- } = _ref2;
28841
-
28842
- if (!event.isPrimary || event.button !== 0) {
28843
- return false;
28844
- }
28845
-
28846
- onActivation == null ? void 0 : onActivation({
28847
- event
28848
- });
28849
- return true;
28850
- }
28851
- }];
28852
-
28853
- const events$1 = {
28854
- move: {
28855
- name: 'mousemove'
28856
- },
28857
- end: {
28858
- name: 'mouseup'
28859
- }
28860
- };
28861
- var MouseButton;
28862
-
28863
- (function (MouseButton) {
28864
- MouseButton[MouseButton["RightClick"] = 2] = "RightClick";
28865
- })(MouseButton || (MouseButton = {}));
28866
-
28867
- class MouseSensor extends AbstractPointerSensor {
28868
- constructor(props) {
28869
- super(props, events$1, utilities.getOwnerDocument(props.event.target));
28870
- }
28871
-
28872
- }
28873
- MouseSensor.activators = [{
28874
- eventName: 'onMouseDown',
28875
- handler: (_ref, _ref2) => {
28876
- let {
28877
- nativeEvent: event
28878
- } = _ref;
28879
- let {
28880
- onActivation
28881
- } = _ref2;
28882
-
28883
- if (event.button === MouseButton.RightClick) {
28884
- return false;
28885
- }
28886
-
28887
- onActivation == null ? void 0 : onActivation({
28888
- event
28889
- });
28890
- return true;
28891
- }
28892
- }];
28893
-
28894
- const events$2 = {
28895
- cancel: {
28896
- name: 'touchcancel'
28897
- },
28898
- move: {
28899
- name: 'touchmove'
28900
- },
28901
- end: {
28902
- name: 'touchend'
28903
- }
28904
- };
28905
- class TouchSensor extends AbstractPointerSensor {
28906
- constructor(props) {
28907
- super(props, events$2);
28908
- }
28909
-
28910
- static setup() {
28911
- // Adding a non-capture and non-passive `touchmove` listener in order
28912
- // to force `event.preventDefault()` calls to work in dynamically added
28913
- // touchmove event handlers. This is required for iOS Safari.
28914
- window.addEventListener(events$2.move.name, noop, {
28915
- capture: false,
28916
- passive: false
28917
- });
28918
- return function teardown() {
28919
- window.removeEventListener(events$2.move.name, noop);
28920
- }; // We create a new handler because the teardown function of another sensor
28921
- // could remove our event listener if we use a referentially equal listener.
28922
-
28923
- function noop() {}
28924
- }
28925
-
28926
- }
28927
- TouchSensor.activators = [{
28928
- eventName: 'onTouchStart',
28929
- handler: (_ref, _ref2) => {
28930
- let {
28931
- nativeEvent: event
28932
- } = _ref;
28933
- let {
28934
- onActivation
28935
- } = _ref2;
28936
- const {
28937
- touches
28938
- } = event;
28939
-
28940
- if (touches.length > 1) {
28941
- return false;
28942
- }
28943
-
28944
- onActivation == null ? void 0 : onActivation({
28945
- event
28946
- });
28947
- return true;
28948
- }
28949
- }];
28950
-
28951
- var AutoScrollActivator;
28952
-
28953
- (function (AutoScrollActivator) {
28954
- AutoScrollActivator[AutoScrollActivator["Pointer"] = 0] = "Pointer";
28955
- AutoScrollActivator[AutoScrollActivator["DraggableRect"] = 1] = "DraggableRect";
28956
- })(AutoScrollActivator || (AutoScrollActivator = {}));
28957
-
28958
- var TraversalOrder;
28959
-
28960
- (function (TraversalOrder) {
28961
- TraversalOrder[TraversalOrder["TreeOrder"] = 0] = "TreeOrder";
28962
- TraversalOrder[TraversalOrder["ReversedTreeOrder"] = 1] = "ReversedTreeOrder";
28963
- })(TraversalOrder || (TraversalOrder = {}));
28964
-
28965
- function useAutoScroller(_ref) {
28966
- let {
28967
- acceleration,
28968
- activator = AutoScrollActivator.Pointer,
28969
- canScroll,
28970
- draggingRect,
28971
- enabled,
28972
- interval = 5,
28973
- order = TraversalOrder.TreeOrder,
28974
- pointerCoordinates,
28975
- scrollableAncestors,
28976
- scrollableAncestorRects,
28977
- delta,
28978
- threshold
28979
- } = _ref;
28980
- const scrollIntent = useScrollIntent({
28981
- delta,
28982
- disabled: !enabled
28983
- });
28984
- const [setAutoScrollInterval, clearAutoScrollInterval] = utilities.useInterval();
28985
- const scrollSpeed = React.useRef({
28986
- x: 0,
28987
- y: 0
28988
- });
28989
- const scrollDirection = React.useRef({
28990
- x: 0,
28991
- y: 0
28992
- });
28993
- const rect = React.useMemo(() => {
28994
- switch (activator) {
28995
- case AutoScrollActivator.Pointer:
28996
- return pointerCoordinates ? {
28997
- top: pointerCoordinates.y,
28998
- bottom: pointerCoordinates.y,
28999
- left: pointerCoordinates.x,
29000
- right: pointerCoordinates.x
29001
- } : null;
29002
-
29003
- case AutoScrollActivator.DraggableRect:
29004
- return draggingRect;
29005
- }
29006
- }, [activator, draggingRect, pointerCoordinates]);
29007
- const scrollContainerRef = React.useRef(null);
29008
- const autoScroll = React.useCallback(() => {
29009
- const scrollContainer = scrollContainerRef.current;
29010
-
29011
- if (!scrollContainer) {
29012
- return;
29013
- }
29014
-
29015
- const scrollLeft = scrollSpeed.current.x * scrollDirection.current.x;
29016
- const scrollTop = scrollSpeed.current.y * scrollDirection.current.y;
29017
- scrollContainer.scrollBy(scrollLeft, scrollTop);
29018
- }, []);
29019
- const sortedScrollableAncestors = React.useMemo(() => order === TraversalOrder.TreeOrder ? [...scrollableAncestors].reverse() : scrollableAncestors, [order, scrollableAncestors]);
29020
- React.useEffect(() => {
29021
- if (!enabled || !scrollableAncestors.length || !rect) {
29022
- clearAutoScrollInterval();
29023
- return;
29024
- }
29025
-
29026
- for (const scrollContainer of sortedScrollableAncestors) {
29027
- if ((canScroll == null ? void 0 : canScroll(scrollContainer)) === false) {
29028
- continue;
29029
- }
29030
-
29031
- const index = scrollableAncestors.indexOf(scrollContainer);
29032
- const scrollContainerRect = scrollableAncestorRects[index];
29033
-
29034
- if (!scrollContainerRect) {
29035
- continue;
29036
- }
29037
-
29038
- const {
29039
- direction,
29040
- speed
29041
- } = getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, rect, acceleration, threshold);
29042
-
29043
- for (const axis of ['x', 'y']) {
29044
- if (!scrollIntent[axis][direction[axis]]) {
29045
- speed[axis] = 0;
29046
- direction[axis] = 0;
29047
- }
29048
- }
29049
-
29050
- if (speed.x > 0 || speed.y > 0) {
29051
- clearAutoScrollInterval();
29052
- scrollContainerRef.current = scrollContainer;
29053
- setAutoScrollInterval(autoScroll, interval);
29054
- scrollSpeed.current = speed;
29055
- scrollDirection.current = direction;
29056
- return;
29057
- }
29058
- }
29059
-
29060
- scrollSpeed.current = {
29061
- x: 0,
29062
- y: 0
29063
- };
29064
- scrollDirection.current = {
29065
- x: 0,
29066
- y: 0
29067
- };
29068
- clearAutoScrollInterval();
29069
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
29070
- [acceleration, autoScroll, canScroll, clearAutoScrollInterval, enabled, interval, // eslint-disable-next-line react-hooks/exhaustive-deps
29071
- JSON.stringify(rect), // eslint-disable-next-line react-hooks/exhaustive-deps
29072
- JSON.stringify(scrollIntent), setAutoScrollInterval, scrollableAncestors, sortedScrollableAncestors, scrollableAncestorRects, // eslint-disable-next-line react-hooks/exhaustive-deps
29073
- JSON.stringify(threshold)]);
29074
- }
29075
- const defaultScrollIntent = {
29076
- x: {
29077
- [Direction.Backward]: false,
29078
- [Direction.Forward]: false
29079
- },
29080
- y: {
29081
- [Direction.Backward]: false,
29082
- [Direction.Forward]: false
29083
- }
29084
- };
29085
-
29086
- function useScrollIntent(_ref2) {
29087
- let {
29088
- delta,
29089
- disabled
29090
- } = _ref2;
29091
- const previousDelta = utilities.usePrevious(delta);
29092
- return utilities.useLazyMemo(previousIntent => {
29093
- if (disabled || !previousDelta || !previousIntent) {
29094
- // Reset scroll intent tracking when auto-scrolling is disabled
29095
- return defaultScrollIntent;
29096
- }
29097
-
29098
- const direction = {
29099
- x: Math.sign(delta.x - previousDelta.x),
29100
- y: Math.sign(delta.y - previousDelta.y)
29101
- }; // Keep track of the user intent to scroll in each direction for both axis
29102
-
29103
- return {
29104
- x: {
29105
- [Direction.Backward]: previousIntent.x[Direction.Backward] || direction.x === -1,
29106
- [Direction.Forward]: previousIntent.x[Direction.Forward] || direction.x === 1
29107
- },
29108
- y: {
29109
- [Direction.Backward]: previousIntent.y[Direction.Backward] || direction.y === -1,
29110
- [Direction.Forward]: previousIntent.y[Direction.Forward] || direction.y === 1
29111
- }
29112
- };
29113
- }, [disabled, delta, previousDelta]);
29114
- }
29115
-
29116
- function useCachedNode(draggableNodes, id) {
29117
- const draggableNode = id != null ? draggableNodes.get(id) : undefined;
29118
- const node = draggableNode ? draggableNode.node.current : null;
29119
- return utilities.useLazyMemo(cachedNode => {
29120
- var _ref;
29121
-
29122
- if (id == null) {
29123
- return null;
29124
- } // In some cases, the draggable node can unmount while dragging
29125
- // This is the case for virtualized lists. In those situations,
29126
- // we fall back to the last known value for that node.
29127
-
29128
-
29129
- return (_ref = node != null ? node : cachedNode) != null ? _ref : null;
29130
- }, [node, id]);
29131
- }
29132
-
29133
- function useCombineActivators(sensors, getSyntheticHandler) {
29134
- return React.useMemo(() => sensors.reduce((accumulator, sensor) => {
29135
- const {
29136
- sensor: Sensor
29137
- } = sensor;
29138
- const sensorActivators = Sensor.activators.map(activator => ({
29139
- eventName: activator.eventName,
29140
- handler: getSyntheticHandler(activator.handler, sensor)
29141
- }));
29142
- return [...accumulator, ...sensorActivators];
29143
- }, []), [sensors, getSyntheticHandler]);
29144
- }
29145
-
29146
- var MeasuringStrategy;
29147
-
29148
- (function (MeasuringStrategy) {
29149
- MeasuringStrategy[MeasuringStrategy["Always"] = 0] = "Always";
29150
- MeasuringStrategy[MeasuringStrategy["BeforeDragging"] = 1] = "BeforeDragging";
29151
- MeasuringStrategy[MeasuringStrategy["WhileDragging"] = 2] = "WhileDragging";
29152
- })(MeasuringStrategy || (MeasuringStrategy = {}));
29153
-
29154
- var MeasuringFrequency;
29155
-
29156
- (function (MeasuringFrequency) {
29157
- MeasuringFrequency["Optimized"] = "optimized";
29158
- })(MeasuringFrequency || (MeasuringFrequency = {}));
29159
-
29160
- const defaultValue = /*#__PURE__*/new Map();
29161
- function useDroppableMeasuring(containers, _ref) {
29162
- let {
29163
- dragging,
29164
- dependencies,
29165
- config
29166
- } = _ref;
29167
- const [queue, setQueue] = React.useState(null);
29168
- const {
29169
- frequency,
29170
- measure,
29171
- strategy
29172
- } = config;
29173
- const containersRef = React.useRef(containers);
29174
- const disabled = isDisabled();
29175
- const disabledRef = utilities.useLatestValue(disabled);
29176
- const measureDroppableContainers = React.useCallback(function (ids) {
29177
- if (ids === void 0) {
29178
- ids = [];
29179
- }
29180
-
29181
- if (disabledRef.current) {
29182
- return;
29183
- }
29184
-
29185
- setQueue(value => {
29186
- if (value === null) {
29187
- return ids;
29188
- }
29189
-
29190
- return value.concat(ids.filter(id => !value.includes(id)));
29191
- });
29192
- }, [disabledRef]);
29193
- const timeoutId = React.useRef(null);
29194
- const droppableRects = utilities.useLazyMemo(previousValue => {
29195
- if (disabled && !dragging) {
29196
- return defaultValue;
29197
- }
29198
-
29199
- if (!previousValue || previousValue === defaultValue || containersRef.current !== containers || queue != null) {
29200
- const map = new Map();
29201
-
29202
- for (let container of containers) {
29203
- if (!container) {
29204
- continue;
29205
- }
29206
-
29207
- if (queue && queue.length > 0 && !queue.includes(container.id) && container.rect.current) {
29208
- // This container does not need to be re-measured
29209
- map.set(container.id, container.rect.current);
29210
- continue;
29211
- }
29212
-
29213
- const node = container.node.current;
29214
- const rect = node ? new Rect(measure(node), node) : null;
29215
- container.rect.current = rect;
29216
-
29217
- if (rect) {
29218
- map.set(container.id, rect);
29219
- }
29220
- }
29221
-
29222
- return map;
29223
- }
29224
-
29225
- return previousValue;
29226
- }, [containers, queue, dragging, disabled, measure]);
29227
- React.useEffect(() => {
29228
- containersRef.current = containers;
29229
- }, [containers]);
29230
- React.useEffect(() => {
29231
- if (disabled) {
29232
- return;
29233
- }
29234
-
29235
- measureDroppableContainers();
29236
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
29237
- [dragging, disabled]);
29238
- React.useEffect(() => {
29239
- if (queue && queue.length > 0) {
29240
- setQueue(null);
29241
- }
29242
- }, //eslint-disable-next-line react-hooks/exhaustive-deps
29243
- [JSON.stringify(queue)]);
29244
- React.useEffect(() => {
29245
- if (disabled || typeof frequency !== 'number' || timeoutId.current !== null) {
29246
- return;
29247
- }
29248
-
29249
- timeoutId.current = setTimeout(() => {
29250
- measureDroppableContainers();
29251
- timeoutId.current = null;
29252
- }, frequency);
29253
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
29254
- [frequency, disabled, measureDroppableContainers, ...dependencies]);
29255
- return {
29256
- droppableRects,
29257
- measureDroppableContainers,
29258
- measuringScheduled: queue != null
29259
- };
29260
-
29261
- function isDisabled() {
29262
- switch (strategy) {
29263
- case MeasuringStrategy.Always:
29264
- return false;
29265
-
29266
- case MeasuringStrategy.BeforeDragging:
29267
- return dragging;
29268
-
29269
- default:
29270
- return !dragging;
29271
- }
29272
- }
29273
- }
29274
-
29275
- function useInitialValue(value, computeFn) {
29276
- return utilities.useLazyMemo(previousValue => {
29277
- if (!value) {
29278
- return null;
29279
- }
29280
-
29281
- if (previousValue) {
29282
- return previousValue;
29283
- }
29284
-
29285
- return typeof computeFn === 'function' ? computeFn(value) : value;
29286
- }, [computeFn, value]);
29287
- }
29288
-
29289
- function useInitialRect(node, measure) {
29290
- return useInitialValue(node, measure);
29291
- }
29292
-
29293
- /**
29294
- * Returns a new MutationObserver instance.
29295
- * If `MutationObserver` is undefined in the execution environment, returns `undefined`.
29296
- */
29297
-
29298
- function useMutationObserver(_ref) {
29299
- let {
29300
- callback,
29301
- disabled
29302
- } = _ref;
29303
- const handleMutations = utilities.useEvent(callback);
29304
- const mutationObserver = React.useMemo(() => {
29305
- if (disabled || typeof window === 'undefined' || typeof window.MutationObserver === 'undefined') {
29306
- return undefined;
29307
- }
29308
-
29309
- const {
29310
- MutationObserver
29311
- } = window;
29312
- return new MutationObserver(handleMutations);
29313
- }, [handleMutations, disabled]);
29314
- React.useEffect(() => {
29315
- return () => mutationObserver == null ? void 0 : mutationObserver.disconnect();
29316
- }, [mutationObserver]);
29317
- return mutationObserver;
29318
- }
29319
-
29320
- /**
29321
- * Returns a new ResizeObserver instance bound to the `onResize` callback.
29322
- * If `ResizeObserver` is undefined in the execution environment, returns `undefined`.
29323
- */
29324
-
29325
- function useResizeObserver(_ref) {
29326
- let {
29327
- callback,
29328
- disabled
29329
- } = _ref;
29330
- const handleResize = utilities.useEvent(callback);
29331
- const resizeObserver = React.useMemo(() => {
29332
- if (disabled || typeof window === 'undefined' || typeof window.ResizeObserver === 'undefined') {
29333
- return undefined;
29334
- }
29335
-
29336
- const {
29337
- ResizeObserver
29338
- } = window;
29339
- return new ResizeObserver(handleResize);
29340
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
29341
- [disabled]);
29342
- React.useEffect(() => {
29343
- return () => resizeObserver == null ? void 0 : resizeObserver.disconnect();
29344
- }, [resizeObserver]);
29345
- return resizeObserver;
29346
- }
29347
-
29348
- function defaultMeasure(element) {
29349
- return new Rect(getClientRect(element), element);
29350
- }
29351
-
29352
- function useRect(element, measure, fallbackRect) {
29353
- if (measure === void 0) {
29354
- measure = defaultMeasure;
29355
- }
29356
-
29357
- const [rect, setRect] = React.useState(null);
29358
-
29359
- function measureRect() {
29360
- setRect(currentRect => {
29361
- if (!element) {
29362
- return null;
29363
- }
29364
-
29365
- if (element.isConnected === false) {
29366
- var _ref;
29367
-
29368
- // Fall back to last rect we measured if the element is
29369
- // no longer connected to the DOM.
29370
- return (_ref = currentRect != null ? currentRect : fallbackRect) != null ? _ref : null;
29371
- }
29372
-
29373
- const newRect = measure(element);
29374
-
29375
- if (JSON.stringify(currentRect) === JSON.stringify(newRect)) {
29376
- return currentRect;
29377
- }
29378
-
29379
- return newRect;
29380
- });
29381
- }
29382
-
29383
- const mutationObserver = useMutationObserver({
29384
- callback(records) {
29385
- if (!element) {
29386
- return;
29387
- }
29388
-
29389
- for (const record of records) {
29390
- const {
29391
- type,
29392
- target
29393
- } = record;
29394
-
29395
- if (type === 'childList' && target instanceof HTMLElement && target.contains(element)) {
29396
- measureRect();
29397
- break;
29398
- }
29399
- }
29400
- }
29401
-
29402
- });
29403
- const resizeObserver = useResizeObserver({
29404
- callback: measureRect
29405
- });
29406
- utilities.useIsomorphicLayoutEffect(() => {
29407
- measureRect();
29408
-
29409
- if (element) {
29410
- resizeObserver == null ? void 0 : resizeObserver.observe(element);
29411
- mutationObserver == null ? void 0 : mutationObserver.observe(document.body, {
29412
- childList: true,
29413
- subtree: true
29414
- });
29415
- } else {
29416
- resizeObserver == null ? void 0 : resizeObserver.disconnect();
29417
- mutationObserver == null ? void 0 : mutationObserver.disconnect();
29418
- }
29419
- }, [element]);
29420
- return rect;
29421
- }
29422
-
29423
- function useRectDelta(rect) {
29424
- const initialRect = useInitialValue(rect);
29425
- return getRectDelta(rect, initialRect);
29426
- }
29427
-
29428
- const defaultValue$1 = [];
29429
- function useScrollableAncestors(node) {
29430
- const previousNode = React.useRef(node);
29431
- const ancestors = utilities.useLazyMemo(previousValue => {
29432
- if (!node) {
29433
- return defaultValue$1;
29434
- }
29435
-
29436
- if (previousValue && previousValue !== defaultValue$1 && node && previousNode.current && node.parentNode === previousNode.current.parentNode) {
29437
- return previousValue;
29438
- }
29439
-
29440
- return getScrollableAncestors(node);
29441
- }, [node]);
29442
- React.useEffect(() => {
29443
- previousNode.current = node;
29444
- }, [node]);
29445
- return ancestors;
29446
- }
29447
-
29448
- function useScrollOffsets(elements) {
29449
- const [scrollCoordinates, setScrollCoordinates] = React.useState(null);
29450
- const prevElements = React.useRef(elements); // To-do: Throttle the handleScroll callback
29451
-
29452
- const handleScroll = React.useCallback(event => {
29453
- const scrollingElement = getScrollableElement(event.target);
29454
-
29455
- if (!scrollingElement) {
29456
- return;
29457
- }
29458
-
29459
- setScrollCoordinates(scrollCoordinates => {
29460
- if (!scrollCoordinates) {
29461
- return null;
29462
- }
29463
-
29464
- scrollCoordinates.set(scrollingElement, getScrollCoordinates(scrollingElement));
29465
- return new Map(scrollCoordinates);
29466
- });
29467
- }, []);
29468
- React.useEffect(() => {
29469
- const previousElements = prevElements.current;
29470
-
29471
- if (elements !== previousElements) {
29472
- cleanup(previousElements);
29473
- const entries = elements.map(element => {
29474
- const scrollableElement = getScrollableElement(element);
29475
-
29476
- if (scrollableElement) {
29477
- scrollableElement.addEventListener('scroll', handleScroll, {
29478
- passive: true
29479
- });
29480
- return [scrollableElement, getScrollCoordinates(scrollableElement)];
29481
- }
29482
-
29483
- return null;
29484
- }).filter(entry => entry != null);
29485
- setScrollCoordinates(entries.length ? new Map(entries) : null);
29486
- prevElements.current = elements;
29487
- }
29488
-
29489
- return () => {
29490
- cleanup(elements);
29491
- cleanup(previousElements);
29492
- };
29493
-
29494
- function cleanup(elements) {
29495
- elements.forEach(element => {
29496
- const scrollableElement = getScrollableElement(element);
29497
- scrollableElement == null ? void 0 : scrollableElement.removeEventListener('scroll', handleScroll);
29498
- });
29499
- }
29500
- }, [handleScroll, elements]);
29501
- return React.useMemo(() => {
29502
- if (elements.length) {
29503
- return scrollCoordinates ? Array.from(scrollCoordinates.values()).reduce((acc, coordinates) => utilities.add(acc, coordinates), defaultCoordinates) : getScrollOffsets(elements);
29504
- }
29505
-
29506
- return defaultCoordinates;
29507
- }, [elements, scrollCoordinates]);
29508
- }
29509
-
29510
- function useScrollOffsetsDelta(scrollOffsets, dependencies) {
29511
- if (dependencies === void 0) {
29512
- dependencies = [];
29513
- }
29514
-
29515
- const initialScrollOffsets = React.useRef(null);
29516
- React.useEffect(() => {
29517
- initialScrollOffsets.current = null;
29518
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
29519
- dependencies);
29520
- React.useEffect(() => {
29521
- const hasScrollOffsets = scrollOffsets !== defaultCoordinates;
29522
-
29523
- if (hasScrollOffsets && !initialScrollOffsets.current) {
29524
- initialScrollOffsets.current = scrollOffsets;
29525
- }
29526
-
29527
- if (!hasScrollOffsets && initialScrollOffsets.current) {
29528
- initialScrollOffsets.current = null;
29529
- }
29530
- }, [scrollOffsets]);
29531
- return initialScrollOffsets.current ? utilities.subtract(scrollOffsets, initialScrollOffsets.current) : defaultCoordinates;
29532
- }
29533
-
29534
- function useSensorSetup(sensors) {
29535
- React.useEffect(() => {
29536
- if (!utilities.canUseDOM) {
29537
- return;
29538
- }
29539
-
29540
- const teardownFns = sensors.map(_ref => {
29541
- let {
29542
- sensor
29543
- } = _ref;
29544
- return sensor.setup == null ? void 0 : sensor.setup();
29545
- });
29546
- return () => {
29547
- for (const teardown of teardownFns) {
29548
- teardown == null ? void 0 : teardown();
29549
- }
29550
- };
29551
- }, // TO-DO: Sensors length could theoretically change which would not be a valid dependency
29552
- // eslint-disable-next-line react-hooks/exhaustive-deps
29553
- sensors.map(_ref2 => {
29554
- let {
29555
- sensor
29556
- } = _ref2;
29557
- return sensor;
29558
- }));
29559
- }
29560
-
29561
- function useWindowRect(element) {
29562
- return React.useMemo(() => element ? getWindowClientRect(element) : null, [element]);
29563
- }
29564
-
29565
- const defaultValue$2 = [];
29566
- function useRects(elements, measure) {
29567
- if (measure === void 0) {
29568
- measure = getClientRect;
29569
- }
29570
-
29571
- const [firstElement] = elements;
29572
- const windowRect = useWindowRect(firstElement ? utilities.getWindow(firstElement) : null);
29573
- const [rects, setRects] = React.useState(defaultValue$2);
29574
-
29575
- function measureRects() {
29576
- setRects(() => {
29577
- if (!elements.length) {
29578
- return defaultValue$2;
29579
- }
29580
-
29581
- return elements.map(element => isDocumentScrollingElement(element) ? windowRect : new Rect(measure(element), element));
29582
- });
29583
- }
29584
-
29585
- const resizeObserver = useResizeObserver({
29586
- callback: measureRects
29587
- });
29588
- utilities.useIsomorphicLayoutEffect(() => {
29589
- resizeObserver == null ? void 0 : resizeObserver.disconnect();
29590
- measureRects();
29591
- elements.forEach(element => resizeObserver == null ? void 0 : resizeObserver.observe(element));
29592
- }, [elements]);
29593
- return rects;
29594
- }
29595
-
29596
- function getMeasurableNode(node) {
29597
- if (!node) {
29598
- return null;
29599
- }
29600
-
29601
- if (node.children.length > 1) {
29602
- return node;
29603
- }
29604
-
29605
- const firstChild = node.children[0];
29606
- return utilities.isHTMLElement(firstChild) ? firstChild : node;
29607
- }
29608
-
29609
- function useDragOverlayMeasuring(_ref) {
29610
- let {
29611
- measure
29612
- } = _ref;
29613
- const [rect, setRect] = React.useState(null);
29614
- const handleResize = React.useCallback(entries => {
29615
- for (const {
29616
- target
29617
- } of entries) {
29618
- if (utilities.isHTMLElement(target)) {
29619
- setRect(rect => {
29620
- const newRect = measure(target);
29621
- return rect ? { ...rect,
29622
- width: newRect.width,
29623
- height: newRect.height
29624
- } : newRect;
29625
- });
29626
- break;
29627
- }
29628
- }
29629
- }, [measure]);
29630
- const resizeObserver = useResizeObserver({
29631
- callback: handleResize
29632
- });
29633
- const handleNodeChange = React.useCallback(element => {
29634
- const node = getMeasurableNode(element);
29635
- resizeObserver == null ? void 0 : resizeObserver.disconnect();
29636
-
29637
- if (node) {
29638
- resizeObserver == null ? void 0 : resizeObserver.observe(node);
29639
- }
29640
-
29641
- setRect(node ? measure(node) : null);
29642
- }, [measure, resizeObserver]);
29643
- const [nodeRef, setRef] = utilities.useNodeRef(handleNodeChange);
29644
- return React.useMemo(() => ({
29645
- nodeRef,
29646
- rect,
29647
- setRef
29648
- }), [rect, nodeRef, setRef]);
29649
- }
29650
-
29651
- const defaultSensors = [{
29652
- sensor: PointerSensor,
29653
- options: {}
29654
- }, {
29655
- sensor: KeyboardSensor,
29656
- options: {}
29657
- }];
29658
- const defaultData = {
29659
- current: {}
29660
- };
29661
- const defaultMeasuringConfiguration = {
29662
- draggable: {
29663
- measure: getTransformAgnosticClientRect
29664
- },
29665
- droppable: {
29666
- measure: getTransformAgnosticClientRect,
29667
- strategy: MeasuringStrategy.WhileDragging,
29668
- frequency: MeasuringFrequency.Optimized
29669
- },
29670
- dragOverlay: {
29671
- measure: getClientRect
29672
- }
29673
- };
29674
-
29675
- class DroppableContainersMap extends Map {
29676
- get(id) {
29677
- var _super$get;
29678
-
29679
- return id != null ? (_super$get = super.get(id)) != null ? _super$get : undefined : undefined;
29680
- }
29681
-
29682
- toArray() {
29683
- return Array.from(this.values());
29684
- }
29685
-
29686
- getEnabled() {
29687
- return this.toArray().filter(_ref => {
29688
- let {
29689
- disabled
29690
- } = _ref;
29691
- return !disabled;
29692
- });
29693
- }
29694
-
29695
- getNodeFor(id) {
29696
- var _this$get$node$curren, _this$get;
29697
-
29698
- return (_this$get$node$curren = (_this$get = this.get(id)) == null ? void 0 : _this$get.node.current) != null ? _this$get$node$curren : undefined;
29699
- }
29700
-
29701
- }
29702
-
29703
- const defaultPublicContext = {
29704
- activatorEvent: null,
29705
- active: null,
29706
- activeNode: null,
29707
- activeNodeRect: null,
29708
- collisions: null,
29709
- containerNodeRect: null,
29710
- draggableNodes: /*#__PURE__*/new Map(),
29711
- droppableRects: /*#__PURE__*/new Map(),
29712
- droppableContainers: /*#__PURE__*/new DroppableContainersMap(),
29713
- over: null,
29714
- dragOverlay: {
29715
- nodeRef: {
29716
- current: null
29717
- },
29718
- rect: null,
29719
- setRef: noop
29720
- },
29721
- scrollableAncestors: [],
29722
- scrollableAncestorRects: [],
29723
- measuringConfiguration: defaultMeasuringConfiguration,
29724
- measureDroppableContainers: noop,
29725
- windowRect: null,
29726
- measuringScheduled: false
29727
- };
29728
- const defaultInternalContext = {
29729
- activatorEvent: null,
29730
- activators: [],
29731
- active: null,
29732
- activeNodeRect: null,
29733
- ariaDescribedById: {
29734
- draggable: ''
29735
- },
29736
- dispatch: noop,
29737
- draggableNodes: /*#__PURE__*/new Map(),
29738
- over: null,
29739
- measureDroppableContainers: noop
29740
- };
29741
- const InternalContext = /*#__PURE__*/React.createContext(defaultInternalContext);
29742
- const PublicContext = /*#__PURE__*/React.createContext(defaultPublicContext);
29743
-
29744
- function getInitialState() {
29745
- return {
29746
- draggable: {
29747
- active: null,
29748
- initialCoordinates: {
29749
- x: 0,
29750
- y: 0
29751
- },
29752
- nodes: new Map(),
29753
- translate: {
29754
- x: 0,
29755
- y: 0
29756
- }
29757
- },
29758
- droppable: {
29759
- containers: new DroppableContainersMap()
29760
- }
29761
- };
29762
- }
29763
- function reducer(state, action) {
29764
- switch (action.type) {
29765
- case Action.DragStart:
29766
- return { ...state,
29767
- draggable: { ...state.draggable,
29768
- initialCoordinates: action.initialCoordinates,
29769
- active: action.active
29770
- }
29771
- };
29772
-
29773
- case Action.DragMove:
29774
- if (state.draggable.active == null) {
29775
- return state;
29776
- }
29777
-
29778
- return { ...state,
29779
- draggable: { ...state.draggable,
29780
- translate: {
29781
- x: action.coordinates.x - state.draggable.initialCoordinates.x,
29782
- y: action.coordinates.y - state.draggable.initialCoordinates.y
29783
- }
29784
- }
29785
- };
29786
-
29787
- case Action.DragEnd:
29788
- case Action.DragCancel:
29789
- return { ...state,
29790
- draggable: { ...state.draggable,
29791
- active: null,
29792
- initialCoordinates: {
29793
- x: 0,
29794
- y: 0
29795
- },
29796
- translate: {
29797
- x: 0,
29798
- y: 0
29799
- }
29800
- }
29801
- };
29802
-
29803
- case Action.RegisterDroppable:
29804
- {
29805
- const {
29806
- element
29807
- } = action;
29808
- const {
29809
- id
29810
- } = element;
29811
- const containers = new DroppableContainersMap(state.droppable.containers);
29812
- containers.set(id, element);
29813
- return { ...state,
29814
- droppable: { ...state.droppable,
29815
- containers
29816
- }
29817
- };
29818
- }
29819
-
29820
- case Action.SetDroppableDisabled:
29821
- {
29822
- const {
29823
- id,
29824
- key,
29825
- disabled
29826
- } = action;
29827
- const element = state.droppable.containers.get(id);
29828
-
29829
- if (!element || key !== element.key) {
29830
- return state;
29831
- }
29832
-
29833
- const containers = new DroppableContainersMap(state.droppable.containers);
29834
- containers.set(id, { ...element,
29835
- disabled
29836
- });
29837
- return { ...state,
29838
- droppable: { ...state.droppable,
29839
- containers
29840
- }
29841
- };
29842
- }
29843
-
29844
- case Action.UnregisterDroppable:
29845
- {
29846
- const {
29847
- id,
29848
- key
29849
- } = action;
29850
- const element = state.droppable.containers.get(id);
29851
-
29852
- if (!element || key !== element.key) {
29853
- return state;
29854
- }
29855
-
29856
- const containers = new DroppableContainersMap(state.droppable.containers);
29857
- containers.delete(id);
29858
- return { ...state,
29859
- droppable: { ...state.droppable,
29860
- containers
29861
- }
29862
- };
29863
- }
29864
-
29865
- default:
29866
- {
29867
- return state;
29868
- }
29869
- }
29870
- }
29871
-
29872
- function RestoreFocus(_ref) {
29873
- let {
29874
- disabled
29875
- } = _ref;
29876
- const {
29877
- active,
29878
- activatorEvent,
29879
- draggableNodes
29880
- } = React.useContext(InternalContext);
29881
- const previousActivatorEvent = utilities.usePrevious(activatorEvent);
29882
- const previousActiveId = utilities.usePrevious(active == null ? void 0 : active.id); // Restore keyboard focus on the activator node
29883
-
29884
- React.useEffect(() => {
29885
- if (disabled) {
29886
- return;
29887
- }
29888
-
29889
- if (!activatorEvent && previousActivatorEvent && previousActiveId != null) {
29890
- if (!utilities.isKeyboardEvent(previousActivatorEvent)) {
29891
- return;
29892
- }
29893
-
29894
- if (document.activeElement === previousActivatorEvent.target) {
29895
- // No need to restore focus
29896
- return;
29897
- }
29898
-
29899
- const draggableNode = draggableNodes.get(previousActiveId);
29900
-
29901
- if (!draggableNode) {
29902
- return;
29903
- }
29904
-
29905
- const {
29906
- activatorNode,
29907
- node
29908
- } = draggableNode;
29909
-
29910
- if (!activatorNode.current && !node.current) {
29911
- return;
29912
- }
29913
-
29914
- requestAnimationFrame(() => {
29915
- for (const element of [activatorNode.current, node.current]) {
29916
- if (!element) {
29917
- continue;
29918
- }
29919
-
29920
- const focusableNode = utilities.findFirstFocusableNode(element);
29921
-
29922
- if (focusableNode) {
29923
- focusableNode.focus();
29924
- break;
29925
- }
29926
- }
29927
- });
29928
- }
29929
- }, [activatorEvent, disabled, draggableNodes, previousActiveId, previousActivatorEvent]);
29930
- return null;
29931
- }
29932
-
29933
- function applyModifiers(modifiers, _ref) {
29934
- let {
29935
- transform,
29936
- ...args
29937
- } = _ref;
29938
- return modifiers != null && modifiers.length ? modifiers.reduce((accumulator, modifier) => {
29939
- return modifier({
29940
- transform: accumulator,
29941
- ...args
29942
- });
29943
- }, transform) : transform;
29944
- }
29945
-
29946
- function useMeasuringConfiguration(config) {
29947
- return React.useMemo(() => ({
29948
- draggable: { ...defaultMeasuringConfiguration.draggable,
29949
- ...(config == null ? void 0 : config.draggable)
29950
- },
29951
- droppable: { ...defaultMeasuringConfiguration.droppable,
29952
- ...(config == null ? void 0 : config.droppable)
29953
- },
29954
- dragOverlay: { ...defaultMeasuringConfiguration.dragOverlay,
29955
- ...(config == null ? void 0 : config.dragOverlay)
29956
- }
29957
- }), // eslint-disable-next-line react-hooks/exhaustive-deps
29958
- [config == null ? void 0 : config.draggable, config == null ? void 0 : config.droppable, config == null ? void 0 : config.dragOverlay]);
29959
- }
29960
-
29961
- function useLayoutShiftScrollCompensation(_ref) {
29962
- let {
29963
- activeNode,
29964
- measure,
29965
- initialRect,
29966
- config = true
29967
- } = _ref;
29968
- const initialized = React.useRef(false);
29969
- const {
29970
- x,
29971
- y
29972
- } = typeof config === 'boolean' ? {
29973
- x: config,
29974
- y: config
29975
- } : config;
29976
- utilities.useIsomorphicLayoutEffect(() => {
29977
- const disabled = !x && !y;
29978
-
29979
- if (disabled || !activeNode) {
29980
- initialized.current = false;
29981
- return;
29982
- }
29983
-
29984
- if (initialized.current || !initialRect) {
29985
- // Return early if layout shift scroll compensation was already attempted
29986
- // or if there is no initialRect to compare to.
29987
- return;
29988
- } // Get the most up to date node ref for the active draggable
29989
-
29990
-
29991
- const node = activeNode == null ? void 0 : activeNode.node.current;
29992
-
29993
- if (!node || node.isConnected === false) {
29994
- // Return early if there is no attached node ref or if the node is
29995
- // disconnected from the document.
29996
- return;
29997
- }
29998
-
29999
- const rect = measure(node);
30000
- const rectDelta = getRectDelta(rect, initialRect);
30001
-
30002
- if (!x) {
30003
- rectDelta.x = 0;
30004
- }
30005
-
30006
- if (!y) {
30007
- rectDelta.y = 0;
30008
- } // Only perform layout shift scroll compensation once
30009
-
30010
-
30011
- initialized.current = true;
30012
-
30013
- if (Math.abs(rectDelta.x) > 0 || Math.abs(rectDelta.y) > 0) {
30014
- const firstScrollableAncestor = getFirstScrollableAncestor(node);
30015
-
30016
- if (firstScrollableAncestor) {
30017
- firstScrollableAncestor.scrollBy({
30018
- top: rectDelta.y,
30019
- left: rectDelta.x
30020
- });
30021
- }
30022
- }
30023
- }, [activeNode, x, y, initialRect, measure]);
30024
- }
30025
-
30026
- const ActiveDraggableContext = /*#__PURE__*/React.createContext({ ...defaultCoordinates,
30027
- scaleX: 1,
30028
- scaleY: 1
30029
- });
30030
- var Status;
30031
-
30032
- (function (Status) {
30033
- Status[Status["Uninitialized"] = 0] = "Uninitialized";
30034
- Status[Status["Initializing"] = 1] = "Initializing";
30035
- Status[Status["Initialized"] = 2] = "Initialized";
30036
- })(Status || (Status = {}));
30037
-
30038
- const DndContext = /*#__PURE__*/React.memo(function DndContext(_ref) {
30039
- var _sensorContext$curren, _dragOverlay$nodeRef$, _dragOverlay$rect, _over$rect;
30040
-
30041
- let {
30042
- id,
30043
- accessibility,
30044
- autoScroll = true,
30045
- children,
30046
- sensors = defaultSensors,
30047
- collisionDetection = rectIntersection,
30048
- measuring,
30049
- modifiers,
30050
- ...props
30051
- } = _ref;
30052
- const store = React.useReducer(reducer, undefined, getInitialState);
30053
- const [state, dispatch] = store;
30054
- const [dispatchMonitorEvent, registerMonitorListener] = useDndMonitorProvider();
30055
- const [status, setStatus] = React.useState(Status.Uninitialized);
30056
- const isInitialized = status === Status.Initialized;
30057
- const {
30058
- draggable: {
30059
- active: activeId,
30060
- nodes: draggableNodes,
30061
- translate
30062
- },
30063
- droppable: {
30064
- containers: droppableContainers
30065
- }
30066
- } = state;
30067
- const node = activeId != null ? draggableNodes.get(activeId) : null;
30068
- const activeRects = React.useRef({
30069
- initial: null,
30070
- translated: null
30071
- });
30072
- const active = React.useMemo(() => {
30073
- var _node$data;
30074
-
30075
- return activeId != null ? {
30076
- id: activeId,
30077
- // It's possible for the active node to unmount while dragging
30078
- data: (_node$data = node == null ? void 0 : node.data) != null ? _node$data : defaultData,
30079
- rect: activeRects
30080
- } : null;
30081
- }, [activeId, node]);
30082
- const activeRef = React.useRef(null);
30083
- const [activeSensor, setActiveSensor] = React.useState(null);
30084
- const [activatorEvent, setActivatorEvent] = React.useState(null);
30085
- const latestProps = utilities.useLatestValue(props, Object.values(props));
30086
- const draggableDescribedById = utilities.useUniqueId("DndDescribedBy", id);
30087
- const enabledDroppableContainers = React.useMemo(() => droppableContainers.getEnabled(), [droppableContainers]);
30088
- const measuringConfiguration = useMeasuringConfiguration(measuring);
30089
- const {
30090
- droppableRects,
30091
- measureDroppableContainers,
30092
- measuringScheduled
30093
- } = useDroppableMeasuring(enabledDroppableContainers, {
30094
- dragging: isInitialized,
30095
- dependencies: [translate.x, translate.y],
30096
- config: measuringConfiguration.droppable
30097
- });
30098
- const activeNode = useCachedNode(draggableNodes, activeId);
30099
- const activationCoordinates = React.useMemo(() => activatorEvent ? utilities.getEventCoordinates(activatorEvent) : null, [activatorEvent]);
30100
- const autoScrollOptions = getAutoScrollerOptions();
30101
- const initialActiveNodeRect = useInitialRect(activeNode, measuringConfiguration.draggable.measure);
30102
- useLayoutShiftScrollCompensation({
30103
- activeNode: activeId != null ? draggableNodes.get(activeId) : null,
30104
- config: autoScrollOptions.layoutShiftCompensation,
30105
- initialRect: initialActiveNodeRect,
30106
- measure: measuringConfiguration.draggable.measure
30107
- });
30108
- const activeNodeRect = useRect(activeNode, measuringConfiguration.draggable.measure, initialActiveNodeRect);
30109
- const containerNodeRect = useRect(activeNode ? activeNode.parentElement : null);
30110
- const sensorContext = React.useRef({
30111
- activatorEvent: null,
30112
- active: null,
30113
- activeNode,
30114
- collisionRect: null,
30115
- collisions: null,
30116
- droppableRects,
30117
- draggableNodes,
30118
- draggingNode: null,
30119
- draggingNodeRect: null,
30120
- droppableContainers,
30121
- over: null,
30122
- scrollableAncestors: [],
30123
- scrollAdjustedTranslate: null
30124
- });
30125
- const overNode = droppableContainers.getNodeFor((_sensorContext$curren = sensorContext.current.over) == null ? void 0 : _sensorContext$curren.id);
30126
- const dragOverlay = useDragOverlayMeasuring({
30127
- measure: measuringConfiguration.dragOverlay.measure
30128
- }); // Use the rect of the drag overlay if it is mounted
30129
-
30130
- const draggingNode = (_dragOverlay$nodeRef$ = dragOverlay.nodeRef.current) != null ? _dragOverlay$nodeRef$ : activeNode;
30131
- const draggingNodeRect = isInitialized ? (_dragOverlay$rect = dragOverlay.rect) != null ? _dragOverlay$rect : activeNodeRect : null;
30132
- const usesDragOverlay = Boolean(dragOverlay.nodeRef.current && dragOverlay.rect); // The delta between the previous and new position of the draggable node
30133
- // is only relevant when there is no drag overlay
30134
-
30135
- const nodeRectDelta = useRectDelta(usesDragOverlay ? null : activeNodeRect); // Get the window rect of the dragging node
30136
-
30137
- const windowRect = useWindowRect(draggingNode ? utilities.getWindow(draggingNode) : null); // Get scrollable ancestors of the dragging node
30138
-
30139
- const scrollableAncestors = useScrollableAncestors(isInitialized ? overNode != null ? overNode : activeNode : null);
30140
- const scrollableAncestorRects = useRects(scrollableAncestors); // Apply modifiers
30141
-
30142
- const modifiedTranslate = applyModifiers(modifiers, {
30143
- transform: {
30144
- x: translate.x - nodeRectDelta.x,
30145
- y: translate.y - nodeRectDelta.y,
30146
- scaleX: 1,
30147
- scaleY: 1
30148
- },
30149
- activatorEvent,
30150
- active,
30151
- activeNodeRect,
30152
- containerNodeRect,
30153
- draggingNodeRect,
30154
- over: sensorContext.current.over,
30155
- overlayNodeRect: dragOverlay.rect,
30156
- scrollableAncestors,
30157
- scrollableAncestorRects,
30158
- windowRect
30159
- });
30160
- const pointerCoordinates = activationCoordinates ? utilities.add(activationCoordinates, translate) : null;
30161
- const scrollOffsets = useScrollOffsets(scrollableAncestors); // Represents the scroll delta since dragging was initiated
30162
-
30163
- const scrollAdjustment = useScrollOffsetsDelta(scrollOffsets); // Represents the scroll delta since the last time the active node rect was measured
30164
-
30165
- const activeNodeScrollDelta = useScrollOffsetsDelta(scrollOffsets, [activeNodeRect]);
30166
- const scrollAdjustedTranslate = utilities.add(modifiedTranslate, scrollAdjustment);
30167
- const collisionRect = draggingNodeRect ? getAdjustedRect(draggingNodeRect, modifiedTranslate) : null;
30168
- const collisions = active && collisionRect ? collisionDetection({
30169
- active,
30170
- collisionRect,
30171
- droppableRects,
30172
- droppableContainers: enabledDroppableContainers,
30173
- pointerCoordinates
30174
- }) : null;
30175
- const overId = getFirstCollision(collisions, 'id');
30176
- const [over, setOver] = React.useState(null); // When there is no drag overlay used, we need to account for the
30177
- // window scroll delta
30178
-
30179
- const appliedTranslate = usesDragOverlay ? modifiedTranslate : utilities.add(modifiedTranslate, activeNodeScrollDelta);
30180
- const transform = adjustScale(appliedTranslate, (_over$rect = over == null ? void 0 : over.rect) != null ? _over$rect : null, activeNodeRect);
30181
- const activeSensorRef = React.useRef(null);
30182
- const instantiateSensor = React.useCallback((event, _ref2) => {
30183
- let {
30184
- sensor: Sensor,
30185
- options
30186
- } = _ref2;
30187
-
30188
- if (activeRef.current == null) {
30189
- return;
30190
- }
30191
-
30192
- const activeNode = draggableNodes.get(activeRef.current);
30193
-
30194
- if (!activeNode) {
30195
- return;
30196
- }
30197
-
30198
- const activatorEvent = event.nativeEvent;
30199
- const sensorInstance = new Sensor({
30200
- active: activeRef.current,
30201
- activeNode,
30202
- event: activatorEvent,
30203
- options,
30204
- // Sensors need to be instantiated with refs for arguments that change over time
30205
- // otherwise they are frozen in time with the stale arguments
30206
- context: sensorContext,
30207
-
30208
- onAbort(id) {
30209
- const draggableNode = draggableNodes.get(id);
30210
-
30211
- if (!draggableNode) {
30212
- return;
30213
- }
30214
-
30215
- const {
30216
- onDragAbort
30217
- } = latestProps.current;
30218
- const event = {
30219
- id
30220
- };
30221
- onDragAbort == null ? void 0 : onDragAbort(event);
30222
- dispatchMonitorEvent({
30223
- type: 'onDragAbort',
30224
- event
30225
- });
30226
- },
30227
-
30228
- onPending(id, constraint, initialCoordinates, offset) {
30229
- const draggableNode = draggableNodes.get(id);
30230
-
30231
- if (!draggableNode) {
30232
- return;
30233
- }
30234
-
30235
- const {
30236
- onDragPending
30237
- } = latestProps.current;
30238
- const event = {
30239
- id,
30240
- constraint,
30241
- initialCoordinates,
30242
- offset
30243
- };
30244
- onDragPending == null ? void 0 : onDragPending(event);
30245
- dispatchMonitorEvent({
30246
- type: 'onDragPending',
30247
- event
30248
- });
30249
- },
30250
-
30251
- onStart(initialCoordinates) {
30252
- const id = activeRef.current;
30253
-
30254
- if (id == null) {
30255
- return;
30256
- }
30257
-
30258
- const draggableNode = draggableNodes.get(id);
30259
-
30260
- if (!draggableNode) {
30261
- return;
30262
- }
30263
-
30264
- const {
30265
- onDragStart
30266
- } = latestProps.current;
30267
- const event = {
30268
- activatorEvent,
30269
- active: {
30270
- id,
30271
- data: draggableNode.data,
30272
- rect: activeRects
30273
- }
30274
- };
30275
- ReactDOM.unstable_batchedUpdates(() => {
30276
- onDragStart == null ? void 0 : onDragStart(event);
30277
- setStatus(Status.Initializing);
30278
- dispatch({
30279
- type: Action.DragStart,
30280
- initialCoordinates,
30281
- active: id
30282
- });
30283
- dispatchMonitorEvent({
30284
- type: 'onDragStart',
30285
- event
30286
- });
30287
- setActiveSensor(activeSensorRef.current);
30288
- setActivatorEvent(activatorEvent);
30289
- });
30290
- },
30291
-
30292
- onMove(coordinates) {
30293
- dispatch({
30294
- type: Action.DragMove,
30295
- coordinates
30296
- });
30297
- },
30298
-
30299
- onEnd: createHandler(Action.DragEnd),
30300
- onCancel: createHandler(Action.DragCancel)
30301
- });
30302
- activeSensorRef.current = sensorInstance;
30303
-
30304
- function createHandler(type) {
30305
- return async function handler() {
30306
- const {
30307
- active,
30308
- collisions,
30309
- over,
30310
- scrollAdjustedTranslate
30311
- } = sensorContext.current;
30312
- let event = null;
30313
-
30314
- if (active && scrollAdjustedTranslate) {
30315
- const {
30316
- cancelDrop
30317
- } = latestProps.current;
30318
- event = {
30319
- activatorEvent,
30320
- active: active,
30321
- collisions,
30322
- delta: scrollAdjustedTranslate,
30323
- over
30324
- };
30325
-
30326
- if (type === Action.DragEnd && typeof cancelDrop === 'function') {
30327
- const shouldCancel = await Promise.resolve(cancelDrop(event));
30328
-
30329
- if (shouldCancel) {
30330
- type = Action.DragCancel;
30331
- }
30332
- }
30333
- }
30334
-
30335
- activeRef.current = null;
30336
- ReactDOM.unstable_batchedUpdates(() => {
30337
- dispatch({
30338
- type
30339
- });
30340
- setStatus(Status.Uninitialized);
30341
- setOver(null);
30342
- setActiveSensor(null);
30343
- setActivatorEvent(null);
30344
- activeSensorRef.current = null;
30345
- const eventName = type === Action.DragEnd ? 'onDragEnd' : 'onDragCancel';
30346
-
30347
- if (event) {
30348
- const handler = latestProps.current[eventName];
30349
- handler == null ? void 0 : handler(event);
30350
- dispatchMonitorEvent({
30351
- type: eventName,
30352
- event
30353
- });
30354
- }
30355
- });
30356
- };
30357
- }
30358
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
30359
- [draggableNodes]);
30360
- const bindActivatorToSensorInstantiator = React.useCallback((handler, sensor) => {
30361
- return (event, active) => {
30362
- const nativeEvent = event.nativeEvent;
30363
- const activeDraggableNode = draggableNodes.get(active);
30364
-
30365
- if ( // Another sensor is already instantiating
30366
- activeRef.current !== null || // No active draggable
30367
- !activeDraggableNode || // Event has already been captured
30368
- nativeEvent.dndKit || nativeEvent.defaultPrevented) {
30369
- return;
30370
- }
30371
-
30372
- const activationContext = {
30373
- active: activeDraggableNode
30374
- };
30375
- const shouldActivate = handler(event, sensor.options, activationContext);
30376
-
30377
- if (shouldActivate === true) {
30378
- nativeEvent.dndKit = {
30379
- capturedBy: sensor.sensor
30380
- };
30381
- activeRef.current = active;
30382
- instantiateSensor(event, sensor);
30383
- }
30384
- };
30385
- }, [draggableNodes, instantiateSensor]);
30386
- const activators = useCombineActivators(sensors, bindActivatorToSensorInstantiator);
30387
- useSensorSetup(sensors);
30388
- utilities.useIsomorphicLayoutEffect(() => {
30389
- if (activeNodeRect && status === Status.Initializing) {
30390
- setStatus(Status.Initialized);
30391
- }
30392
- }, [activeNodeRect, status]);
30393
- React.useEffect(() => {
30394
- const {
30395
- onDragMove
30396
- } = latestProps.current;
30397
- const {
30398
- active,
30399
- activatorEvent,
30400
- collisions,
30401
- over
30402
- } = sensorContext.current;
30403
-
30404
- if (!active || !activatorEvent) {
30405
- return;
30406
- }
30407
-
30408
- const event = {
30409
- active,
30410
- activatorEvent,
30411
- collisions,
30412
- delta: {
30413
- x: scrollAdjustedTranslate.x,
30414
- y: scrollAdjustedTranslate.y
30415
- },
30416
- over
30417
- };
30418
- ReactDOM.unstable_batchedUpdates(() => {
30419
- onDragMove == null ? void 0 : onDragMove(event);
30420
- dispatchMonitorEvent({
30421
- type: 'onDragMove',
30422
- event
30423
- });
30424
- });
30425
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
30426
- [scrollAdjustedTranslate.x, scrollAdjustedTranslate.y]);
30427
- React.useEffect(() => {
30428
- const {
30429
- active,
30430
- activatorEvent,
30431
- collisions,
30432
- droppableContainers,
30433
- scrollAdjustedTranslate
30434
- } = sensorContext.current;
30435
-
30436
- if (!active || activeRef.current == null || !activatorEvent || !scrollAdjustedTranslate) {
30437
- return;
30438
- }
30439
-
30440
- const {
30441
- onDragOver
30442
- } = latestProps.current;
30443
- const overContainer = droppableContainers.get(overId);
30444
- const over = overContainer && overContainer.rect.current ? {
30445
- id: overContainer.id,
30446
- rect: overContainer.rect.current,
30447
- data: overContainer.data,
30448
- disabled: overContainer.disabled
30449
- } : null;
30450
- const event = {
30451
- active,
30452
- activatorEvent,
30453
- collisions,
30454
- delta: {
30455
- x: scrollAdjustedTranslate.x,
30456
- y: scrollAdjustedTranslate.y
30457
- },
30458
- over
30459
- };
30460
- ReactDOM.unstable_batchedUpdates(() => {
30461
- setOver(over);
30462
- onDragOver == null ? void 0 : onDragOver(event);
30463
- dispatchMonitorEvent({
30464
- type: 'onDragOver',
30465
- event
30466
- });
30467
- });
30468
- }, // eslint-disable-next-line react-hooks/exhaustive-deps
30469
- [overId]);
30470
- utilities.useIsomorphicLayoutEffect(() => {
30471
- sensorContext.current = {
30472
- activatorEvent,
30473
- active,
30474
- activeNode,
30475
- collisionRect,
30476
- collisions,
30477
- droppableRects,
30478
- draggableNodes,
30479
- draggingNode,
30480
- draggingNodeRect,
30481
- droppableContainers,
30482
- over,
30483
- scrollableAncestors,
30484
- scrollAdjustedTranslate
30485
- };
30486
- activeRects.current = {
30487
- initial: draggingNodeRect,
30488
- translated: collisionRect
30489
- };
30490
- }, [active, activeNode, collisions, collisionRect, draggableNodes, draggingNode, draggingNodeRect, droppableRects, droppableContainers, over, scrollableAncestors, scrollAdjustedTranslate]);
30491
- useAutoScroller({ ...autoScrollOptions,
30492
- delta: translate,
30493
- draggingRect: collisionRect,
30494
- pointerCoordinates,
30495
- scrollableAncestors,
30496
- scrollableAncestorRects
30497
- });
30498
- const publicContext = React.useMemo(() => {
30499
- const context = {
30500
- active,
30501
- activeNode,
30502
- activeNodeRect,
30503
- activatorEvent,
30504
- collisions,
30505
- containerNodeRect,
30506
- dragOverlay,
30507
- draggableNodes,
30508
- droppableContainers,
30509
- droppableRects,
30510
- over,
30511
- measureDroppableContainers,
30512
- scrollableAncestors,
30513
- scrollableAncestorRects,
30514
- measuringConfiguration,
30515
- measuringScheduled,
30516
- windowRect
30517
- };
30518
- return context;
30519
- }, [active, activeNode, activeNodeRect, activatorEvent, collisions, containerNodeRect, dragOverlay, draggableNodes, droppableContainers, droppableRects, over, measureDroppableContainers, scrollableAncestors, scrollableAncestorRects, measuringConfiguration, measuringScheduled, windowRect]);
30520
- const internalContext = React.useMemo(() => {
30521
- const context = {
30522
- activatorEvent,
30523
- activators,
30524
- active,
30525
- activeNodeRect,
30526
- ariaDescribedById: {
30527
- draggable: draggableDescribedById
30528
- },
30529
- dispatch,
30530
- draggableNodes,
30531
- over,
30532
- measureDroppableContainers
30533
- };
30534
- return context;
30535
- }, [activatorEvent, activators, active, activeNodeRect, dispatch, draggableDescribedById, draggableNodes, over, measureDroppableContainers]);
30536
- return React.createElement(DndMonitorContext.Provider, {
30537
- value: registerMonitorListener
30538
- }, React.createElement(InternalContext.Provider, {
30539
- value: internalContext
30540
- }, React.createElement(PublicContext.Provider, {
30541
- value: publicContext
30542
- }, React.createElement(ActiveDraggableContext.Provider, {
30543
- value: transform
30544
- }, children)), React.createElement(RestoreFocus, {
30545
- disabled: (accessibility == null ? void 0 : accessibility.restoreFocus) === false
30546
- })), React.createElement(Accessibility, { ...accessibility,
30547
- hiddenTextDescribedById: draggableDescribedById
30548
- }));
30549
-
30550
- function getAutoScrollerOptions() {
30551
- const activeSensorDisablesAutoscroll = (activeSensor == null ? void 0 : activeSensor.autoScrollEnabled) === false;
30552
- const autoScrollGloballyDisabled = typeof autoScroll === 'object' ? autoScroll.enabled === false : autoScroll === false;
30553
- const enabled = isInitialized && !activeSensorDisablesAutoscroll && !autoScrollGloballyDisabled;
30554
-
30555
- if (typeof autoScroll === 'object') {
30556
- return { ...autoScroll,
30557
- enabled
30558
- };
30559
- }
30560
-
30561
- return {
30562
- enabled
30563
- };
30564
- }
30565
- });
30566
-
30567
- const EditGridWrapper = (props) => {
30568
- const notifications = core.useNotifications();
30569
- const baseGridRef = React.useRef(null);
30570
- // ======================|| EDIT ||====================== //
30571
- const [edit, setEdit] = React.useState(false);
30572
- const [editMutation, { isLoading: loadingMutation }] = props.mutation();
30573
- const [errors, setErrors] = React.useState({});
30574
- const [rowModesModel, setRowModesModel] = React.useState({});
30575
- const handleCancelarEdit = () => {
30576
- setRowModesModel({});
30577
- };
30578
- const handleClickEdit = () => {
30579
- if (edit)
30580
- handleCancelarEdit();
30581
- setEdit(prevState => !prevState);
30582
- };
30583
- const processRowUpdate = async (newRow, originalRow) => {
30584
- const original_data = jsonForm({ submitData: originalRow });
30585
- const data = jsonForm({ submitData: newRow, ...(props.parser ? { props: props.parser } : []) });
30586
- if (lodash.isEqual(data, original_data))
30587
- return originalRow;
30588
- try {
30589
- const result = await editMutation(data).unwrap();
30590
- setErrors(prevState => immer.produce(prevState, draft => {
30591
- delete draft[newRow.id];
30592
- }));
30593
- if (props?.postAction)
30594
- props.postAction(result);
30595
- notifications.show(`Información actualizada!`, { severity: 'success' });
30596
- return result.list;
30597
- }
30598
- catch (e) {
30599
- setErrors(prevState => immer.produce(prevState, draft => {
30600
- draft[newRow.id] = lodash.get(e, 'data');
30601
- }));
30602
- notifications.show('Error actualizando información!', { severity: 'error' });
30603
- }
30604
- };
30605
- // ===== || KEYDOWN || ===== //
30606
- const handleKeyPress = React.useCallback((event) => {
30607
- if (props.permission) {
30608
- if (event.ctrlKey && event.shiftKey && event.key === 'E') {
30609
- event.preventDefault();
30610
- setEdit(true);
30611
- }
30612
- else if (event.key === 'Escape' && event.shiftKey && edit) {
30613
- event.preventDefault();
30614
- handleCancelarEdit();
30615
- setEdit(false);
30616
- }
30617
- }
30618
- }, [edit, props.permission]);
30619
- React.useEffect(() => {
30620
- document.addEventListener('keydown', handleKeyPress);
30621
- return () => {
30622
- document.removeEventListener('keydown', handleKeyPress);
30623
- };
30624
- }, [handleKeyPress]);
30625
- // ========================= || DRAG N DROP || ========================= //
30626
- const rowsIterator = baseGridRef?.current?.getApi()?.getRowModels()?.values();
30627
- const rows = React.useMemo(() => {
30628
- return rowsIterator ? Array.from(rowsIterator) : [];
30629
- }, [rowsIterator]);
30630
- const sensors = useSensors(useSensor(PointerSensor));
30631
- const handleDragEnd = React.useCallback((event) => {
30632
- const field = props.dnd?.field;
30633
- if (!field)
30634
- return;
30635
- const { active, over } = event;
30636
- if (over) {
30637
- const activeRow = rows.find((row) => row.id === active.id);
30638
- const overRow = rows.find((row) => row.id === over.id);
30639
- const mutationArgs = { ...props.dnd?.args, id: activeRow.id };
30640
- mutationArgs[field] = lodash.get(overRow, field);
30641
- editMutation(mutationArgs);
30642
- }
30643
- }, [editMutation, props.dnd, rows]);
30644
- // ===== || GRID PROPS || ===== //
30645
- const editGridProps = mergeSettings({
30646
- columns: props.columns({
30647
- displayEdit: edit && props.permission,
30648
- rowModesModel: rowModesModel,
30649
- setRowModesModel: setRowModesModel,
30650
- mutationErrors: errors,
30651
- options: props.options,
30652
- }),
30653
- ...(edit && props.dnd ? { slots: { row: DraggableRow } } : []),
30654
- slotProps: {
30655
- toolbar: {
30656
- extraButtons: [
30657
- ...(props.permission && !props.disabled ? [{
30658
- label: edit ? 'Cancelar' : 'Editar',
30659
- icon: edit ? CancelIcon : EditIcon,
30660
- onClick: handleClickEdit,
30661
- }] : []),
30662
- ]
30663
- }
30664
- },
30665
- onRowEditStart: ({ reason, row }, event) => {
30666
- if (!lodash.get(row, `obj_permissions.edit`) || (reason === xDataGrid.GridRowEditStartReasons.cellDoubleClick && !edit)) {
30667
- event.defaultMuiPrevented = true;
30668
- }
30669
- },
30670
- // edit
30671
- checkboxSelection: !edit,
30672
- ...(edit ? { onRowClick: undefined } : []),
30673
- editMode: 'row',
30674
- rowModesModel: rowModesModel,
30675
- onRowModesModelChange: setRowModesModel,
30676
- processRowUpdate: processRowUpdate,
30677
- loadingParams: [loadingMutation],
30678
- }, props.dataGridProps);
30679
- const renderEditGrid = () => (jsxRuntime.jsx(DndContext, { sensors: sensors, collisionDetection: closestCenter, onDragEnd: handleDragEnd, modifiers: [
30680
- modifiers.restrictToVerticalAxis,
30681
- modifiers.restrictToWindowEdges,
30682
- modifiers.restrictToParentElement
30683
- ], autoScroll: false, children: jsxRuntime.jsx(sortable.SortableContext, { items: rows ? rows.map((row) => row.id) : [], strategy: sortable.verticalListSortingStrategy, children: props.renderFunction({ ...props.renderFunctionProps, dataGridProps: editGridProps }) }) }));
30684
- return renderEditGrid();
30685
- };
30686
-
30687
- const editColumn = (props) => {
30688
- if (!props)
30689
- return [];
30690
- if (!props.displayEdit)
30691
- return [];
30692
- const handleEditClick = (id) => () => {
30693
- props.setRowModesModel({ ...props.rowModesModel, [id]: { mode: xDataGrid.GridRowModes.Edit } });
30694
- };
30695
- const handleSaveClick = (id) => () => {
30696
- props.setRowModesModel({ ...props.rowModesModel, [id]: { mode: xDataGrid.GridRowModes.View } });
30697
- };
30698
- const handleCancelClick = (id) => () => {
30699
- props.setRowModesModel({
30700
- ...props.rowModesModel,
30701
- [id]: { mode: xDataGrid.GridRowModes.View, ignoreModifications: true },
30702
- });
30703
- };
30704
- return [{
30705
- field: 'edit',
30706
- headerName: 'Editar',
30707
- type: 'actions',
30708
- width: 80,
30709
- cellClassName: 'actions',
30710
- getActions: ({ id, row }) => {
30711
- const canEdit = get(row, 'obj_permissions.edit');
30712
- const isInEditMode = props.rowModesModel[id]?.mode === xDataGrid.GridRowModes.Edit;
30713
- if (isInEditMode) {
30714
- return [
30715
- jsxRuntime.jsx(xDataGrid.GridActionsCellItem, { icon: jsxRuntime.jsx(SaveIcon, {}), label: 'Guardar', color: 'primary', onClick: handleSaveClick(id) }, 'save'),
30716
- jsxRuntime.jsx(xDataGrid.GridActionsCellItem, { icon: jsxRuntime.jsx(CancelIcon, {}), label: 'Cancelar', className: 'textPrimary', onClick: handleCancelClick(id), color: 'inherit' }, 'cancel'),
30717
- ];
30718
- }
30719
- return [
30720
- jsxRuntime.jsx(xDataGrid.GridActionsCellItem, { icon: jsxRuntime.jsx(EditIcon, { sx: { color: canEdit ? 'black' : 'inherit' } }), label: 'Editar', className: 'textPrimary', onClick: handleEditClick(id), disabled: !canEdit }, 'edit'),
30721
- ];
30722
- }
30723
- }];
30724
- };
30725
-
30726
- const deleteColumn = (props) => {
30727
- if (!props.displayDelete)
30728
- return [];
30729
- return [{
30730
- field: 'delete',
30731
- headerName: 'Eliminar',
30732
- width: 80,
30733
- cellClassName: 'actions',
30734
- renderCell: ({ id, row }) => {
30735
- const canDelete = get(row, `obj_permissions.delete`, false);
30736
- return [
30737
- jsxRuntime.jsx(xDataGrid.GridActionsCellItem, { icon: jsxRuntime.jsx(DeleteIcon, {}), label: 'Eliminar', className: 'textPrimary', onClick: props.handleOpen(id), color: 'primary', disabled: !canDelete }, 'delete')
30738
- ];
30739
- }
30740
- }];
27450
+ const deleteColumn = (props) => {
27451
+ if (!props.displayDelete)
27452
+ return [];
27453
+ return [{
27454
+ field: 'delete',
27455
+ headerName: 'Eliminar',
27456
+ width: 80,
27457
+ cellClassName: 'actions',
27458
+ renderCell: ({ id, row }) => {
27459
+ const canDelete = get(row, `obj_permissions.delete`, false);
27460
+ return [
27461
+ jsxRuntime.jsx(xDataGrid.GridActionsCellItem, { icon: jsxRuntime.jsx(DeleteIcon, {}), label: 'Eliminar', className: 'textPrimary', onClick: props.handleOpen(id), color: 'primary', disabled: !canDelete }, 'delete')
27462
+ ];
27463
+ }
27464
+ }];
30741
27465
  };
30742
27466
 
30743
27467
  const DeleteGridWrapper = (props) => {
@@ -30989,6 +27713,11 @@ const Base = (props) => {
30989
27713
  const dataGridProps = mergeSettings({
30990
27714
  columns: [],
30991
27715
  loadingParams: [isLoading, isFetching],
27716
+ slots: {
27717
+ toolbar: CustomToolbar,
27718
+ pagination: CustomPagination,
27719
+ noRowsOverlay: CustomNoRows,
27720
+ },
30992
27721
  slotProps: {
30993
27722
  baseCheckbox: {
30994
27723
  size: 'small'
@@ -31017,15 +27746,12 @@ const Base = (props) => {
31017
27746
  },
31018
27747
  }, props.dataGridProps);
31019
27748
  const renderDataGrid = ({ dataGridProps: renderDataGridProps }) => {
27749
+ // console.log(dataGridProps)
31020
27750
  return (jsxRuntime.jsx(material.Box, { width: 1, minHeight: 300, height: 1,
31021
27751
  // maxHeight={'calc(100% - 30px)'}
31022
- display: 'flex', flexDirection: 'column', pb: 0, children: jsxRuntime.jsx(material.NoSsr, { children: jsxRuntime.jsx(xDataGrid.DataGrid, { apiRef: apiRef, ref: props.ref, rows: data?.results || [], loading: lodash.some(lodash.get(renderDataGridProps, 'loadingParams', []), function (x) {
27752
+ display: 'flex', flexDirection: 'column', pb: 0, children: jsxRuntime.jsx(material.NoSsr, { children: jsxRuntime.jsx(xDataGrid.DataGrid, { apiRef: apiRef, rows: data?.results || [], loading: lodash.some(lodash.get(renderDataGridProps, 'loadingParams', []), function (x) {
31023
27753
  return x;
31024
- }), slots: {
31025
- toolbar: CustomToolbar,
31026
- pagination: CustomPagination,
31027
- noRowsOverlay: CustomNoRows,
31028
- },
27754
+ }),
31029
27755
  // paginado //
31030
27756
  pagination: true, paginationMode: 'server', paginationModel: paginationModel, onPaginationModelChange: setPaginationModel, pageSizeOptions: [50, 100, { value: -1, label: 'Todos' }],
31031
27757
  // ordenado
@@ -31049,7 +27775,7 @@ const Base = (props) => {
31049
27775
  // row count
31050
27776
  rowCount: rowCount,
31051
27777
  // settings
31052
- rowHeight: 42,
27778
+ density: 'compact',
31053
27779
  // striping
31054
27780
  getRowClassName: (params) => params.indexRelativeToCurrentPage % 2 === 0 ? 'even' : 'odd', localeText: {
31055
27781
  columnHeaderSortIconLabel: 'Ordenar',
@@ -31078,6 +27804,7 @@ const Base = (props) => {
31078
27804
  renderFunction: renderFunction,
31079
27805
  renderFunctionProps: renderProps,
31080
27806
  dataGridProps: dataGridProps,
27807
+ baseGridRef: apiRef,
31081
27808
  ...props.api.edit
31082
27809
  };
31083
27810
  renderFunction = EditGridWrapper;