@contentful/field-editor-reference 5.3.3 → 5.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,12 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ # [5.4.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.3.3...@contentful/field-editor-reference@5.4.0) (2022-11-02)
7
+
8
+ ### Features
9
+
10
+ - isBeingDragged multiple reference field [TOL-361] ([#1271](https://github.com/contentful/field-editors/issues/1271)) ([0819192](https://github.com/contentful/field-editors/commit/08191922e44283697f6cf04f099e55f7269cfdeb))
11
+
6
12
  ## [5.3.3](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.3.2...@contentful/field-editor-reference@5.3.3) (2022-10-11)
7
13
 
8
14
  ### Bug Fixes
@@ -1,7 +1,7 @@
1
1
  import * as React from 'react';
2
+ import { SortEndHandler, SortStartHandler } from 'react-sortable-hoc';
2
3
  import { ReferenceValue, ContentEntityType, ContentType } from '../types';
3
4
  import { ReferenceEditorProps } from './ReferenceEditor';
4
- import { SortEndHandler, SortStartHandler } from 'react-sortable-hoc';
5
5
  declare type ChildProps = {
6
6
  entityType: ContentEntityType;
7
7
  items: ReferenceValue[];
@@ -15,6 +15,7 @@ declare type ChildProps = {
15
15
  export declare function MultipleReferenceEditor(props: ReferenceEditorProps & {
16
16
  entityType: ContentEntityType;
17
17
  children: (props: ReferenceEditorProps & ChildProps) => React.ReactElement;
18
+ setIndexToUpdate?: React.Dispatch<React.SetStateAction<number | undefined>>;
18
19
  }): JSX.Element;
19
20
  export declare namespace MultipleReferenceEditor {
20
21
  var defaultProps: {
@@ -26,6 +26,9 @@ export interface ReferenceEditorProps {
26
26
  bulkEditing?: boolean;
27
27
  };
28
28
  };
29
+ updateBeforeSortStart?: ({ index }: {
30
+ index: number;
31
+ }) => void;
29
32
  }
30
33
  export declare type CustomActionProps = LinkActionsProps;
31
34
  export declare function ReferenceEditor<T>(props: ReferenceEditorProps & {
@@ -1,5 +1,5 @@
1
- import { Asset, ContentType, Entry, RenderDragFn } from '../types';
2
1
  import * as React from 'react';
2
+ import { Asset, ContentType, Entry, RenderDragFn } from '../types';
3
3
  import { CustomActionProps } from './ReferenceEditor';
4
4
  export declare type MissingEntityCardProps = {
5
5
  defaultCard: React.ReactElement;
@@ -25,4 +25,5 @@ export declare type CustomEntityCardProps = {
25
25
  onRemove?: () => void;
26
26
  onMoveTop?: () => void;
27
27
  onMoveBottom?: () => void;
28
+ isBeingDragged?: boolean;
28
29
  };
@@ -13,5 +13,6 @@ export declare type EntryCardReferenceEditorProps = ReferenceEditorProps & {
13
13
  onMoveTop?: () => void;
14
14
  onMoveBottom?: () => void;
15
15
  renderCustomMissingEntityCard?: RenderCustomMissingEntityCard;
16
+ isBeingDragged?: boolean;
16
17
  };
17
18
  export declare function FetchingWrappedEntryCard(props: EntryCardReferenceEditorProps): JSX.Element;
@@ -3185,7 +3185,8 @@ function FetchingWrappedEntryCard(props) {
3185
3185
  onEdit: onEdit,
3186
3186
  onRemove: onRemoveEntry,
3187
3187
  onMoveTop: props.onMoveTop,
3188
- onMoveBottom: props.onMoveBottom
3188
+ onMoveBottom: props.onMoveBottom,
3189
+ isBeingDragged: props.isBeingDragged
3189
3190
  };
3190
3191
  var hasCardEditActions = props.hasCardEditActions,
3191
3192
  hasCardMoveActions = props.hasCardMoveActions,
@@ -3274,7 +3275,8 @@ var nullableValue = {
3274
3275
 
3275
3276
  function Editor$1(props) {
3276
3277
  var setValue = props.setValue,
3277
- entityType = props.entityType;
3278
+ entityType = props.entityType,
3279
+ setIndexToUpdate = props.setIndexToUpdate;
3278
3280
  var editorPermissions = useEditorPermissions(props);
3279
3281
  var items = React.useMemo(function () {
3280
3282
  return (props.items || []). // If null values have found their way into the persisted
@@ -3286,14 +3288,20 @@ function Editor$1(props) {
3286
3288
  });
3287
3289
  }, [props.items]);
3288
3290
  var onSortStart = React.useCallback(function (_, event) {
3289
- return event.preventDefault();
3291
+ if (event instanceof MouseEvent) {
3292
+ document.body.classList.add('grabbing');
3293
+ }
3294
+
3295
+ event.preventDefault();
3290
3296
  }, []);
3291
3297
  var onSortEnd = React.useCallback(function (_ref) {
3292
3298
  var oldIndex = _ref.oldIndex,
3293
3299
  newIndex = _ref.newIndex;
3294
3300
  var newItems = arrayMove(items, oldIndex, newIndex);
3295
3301
  setValue(newItems);
3296
- }, [items, setValue]);
3302
+ setIndexToUpdate && setIndexToUpdate(undefined);
3303
+ document.body.classList.remove('grabbing');
3304
+ }, [items, setIndexToUpdate, setValue]);
3297
3305
  var onMove = React.useCallback(function (oldIndex, newIndex) {
3298
3306
  var newItems = arrayMove(items, oldIndex, newIndex);
3299
3307
  setValue(newItems);
@@ -3395,18 +3403,29 @@ function SortableLinkList(props) {
3395
3403
  }
3396
3404
 
3397
3405
  function MultipleEntryReferenceEditor(props) {
3406
+ var _React$useState = React.useState(undefined),
3407
+ indexToUpdate = _React$useState[0],
3408
+ setIndexToUpdate = _React$useState[1];
3409
+
3410
+ var updateBeforeSortStart = function updateBeforeSortStart(_ref) {
3411
+ var index = _ref.index;
3412
+ setIndexToUpdate(index);
3413
+ };
3414
+
3398
3415
  return React.createElement(MultipleReferenceEditor, _extends({}, props, {
3399
- entityType: "Entry"
3416
+ entityType: "Entry",
3417
+ setIndexToUpdate: setIndexToUpdate
3400
3418
  }), function (childrenProps) {
3401
3419
  return React.createElement(SortableLinkList, _extends({}, childrenProps, {
3402
3420
  axis: "y",
3403
- useDragHandle: true
3404
- }), function (_ref) {
3405
- var items = _ref.items,
3406
- item = _ref.item,
3407
- index = _ref.index,
3408
- isDisabled = _ref.isDisabled,
3409
- DragHandle = _ref.DragHandle;
3421
+ useDragHandle: true,
3422
+ updateBeforeSortStart: updateBeforeSortStart
3423
+ }), function (_ref2) {
3424
+ var items = _ref2.items,
3425
+ item = _ref2.item,
3426
+ index = _ref2.index,
3427
+ isDisabled = _ref2.isDisabled,
3428
+ DragHandle = _ref2.DragHandle;
3410
3429
  var lastIndex = items.length - 1;
3411
3430
  return React.createElement(FetchingWrappedEntryCard, _extends({}, childrenProps, {
3412
3431
  key: item.sys.id + "-" + index,
@@ -3425,7 +3444,8 @@ function MultipleEntryReferenceEditor(props) {
3425
3444
  onMoveBottom: index !== lastIndex ? function () {
3426
3445
  return childrenProps.onMove(index, lastIndex);
3427
3446
  } : undefined,
3428
- renderDragHandle: DragHandle
3447
+ renderDragHandle: DragHandle,
3448
+ isBeingDragged: index === indexToUpdate
3429
3449
  }));
3430
3450
  });
3431
3451
  });