@contentful/field-editor-reference 5.3.2 → 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,18 @@
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
+
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)
13
+
14
+ ### Bug Fixes
15
+
16
+ - remove background override from xspace refs ([#1261](https://github.com/contentful/field-editors/issues/1261)) ([22004a9](https://github.com/contentful/field-editors/commit/22004a927b51bd7aebfc40449f11d48a3dcf9355))
17
+
6
18
  ## [5.3.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.3.1...@contentful/field-editor-reference@5.3.2) (2022-10-06)
7
19
 
8
20
  ### 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;
@@ -2953,9 +2953,6 @@ function WrappedEntryCard(props) {
2953
2953
  size: props.size,
2954
2954
  isSelected: props.isSelected,
2955
2955
  status: status,
2956
- style: props.spaceName ? {
2957
- backgroundColor: tokens.gray100
2958
- } : undefined,
2959
2956
  icon: props.spaceName ? React.createElement(SpaceName, {
2960
2957
  spaceName: props.spaceName
2961
2958
  }) : React.createElement(ScheduledIconWithTooltip, {
@@ -3188,7 +3185,8 @@ function FetchingWrappedEntryCard(props) {
3188
3185
  onEdit: onEdit,
3189
3186
  onRemove: onRemoveEntry,
3190
3187
  onMoveTop: props.onMoveTop,
3191
- onMoveBottom: props.onMoveBottom
3188
+ onMoveBottom: props.onMoveBottom,
3189
+ isBeingDragged: props.isBeingDragged
3192
3190
  };
3193
3191
  var hasCardEditActions = props.hasCardEditActions,
3194
3192
  hasCardMoveActions = props.hasCardMoveActions,
@@ -3277,7 +3275,8 @@ var nullableValue = {
3277
3275
 
3278
3276
  function Editor$1(props) {
3279
3277
  var setValue = props.setValue,
3280
- entityType = props.entityType;
3278
+ entityType = props.entityType,
3279
+ setIndexToUpdate = props.setIndexToUpdate;
3281
3280
  var editorPermissions = useEditorPermissions(props);
3282
3281
  var items = React.useMemo(function () {
3283
3282
  return (props.items || []). // If null values have found their way into the persisted
@@ -3289,14 +3288,20 @@ function Editor$1(props) {
3289
3288
  });
3290
3289
  }, [props.items]);
3291
3290
  var onSortStart = React.useCallback(function (_, event) {
3292
- return event.preventDefault();
3291
+ if (event instanceof MouseEvent) {
3292
+ document.body.classList.add('grabbing');
3293
+ }
3294
+
3295
+ event.preventDefault();
3293
3296
  }, []);
3294
3297
  var onSortEnd = React.useCallback(function (_ref) {
3295
3298
  var oldIndex = _ref.oldIndex,
3296
3299
  newIndex = _ref.newIndex;
3297
3300
  var newItems = arrayMove(items, oldIndex, newIndex);
3298
3301
  setValue(newItems);
3299
- }, [items, setValue]);
3302
+ setIndexToUpdate && setIndexToUpdate(undefined);
3303
+ document.body.classList.remove('grabbing');
3304
+ }, [items, setIndexToUpdate, setValue]);
3300
3305
  var onMove = React.useCallback(function (oldIndex, newIndex) {
3301
3306
  var newItems = arrayMove(items, oldIndex, newIndex);
3302
3307
  setValue(newItems);
@@ -3398,18 +3403,29 @@ function SortableLinkList(props) {
3398
3403
  }
3399
3404
 
3400
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
+
3401
3415
  return React.createElement(MultipleReferenceEditor, _extends({}, props, {
3402
- entityType: "Entry"
3416
+ entityType: "Entry",
3417
+ setIndexToUpdate: setIndexToUpdate
3403
3418
  }), function (childrenProps) {
3404
3419
  return React.createElement(SortableLinkList, _extends({}, childrenProps, {
3405
3420
  axis: "y",
3406
- useDragHandle: true
3407
- }), function (_ref) {
3408
- var items = _ref.items,
3409
- item = _ref.item,
3410
- index = _ref.index,
3411
- isDisabled = _ref.isDisabled,
3412
- 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;
3413
3429
  var lastIndex = items.length - 1;
3414
3430
  return React.createElement(FetchingWrappedEntryCard, _extends({}, childrenProps, {
3415
3431
  key: item.sys.id + "-" + index,
@@ -3428,7 +3444,8 @@ function MultipleEntryReferenceEditor(props) {
3428
3444
  onMoveBottom: index !== lastIndex ? function () {
3429
3445
  return childrenProps.onMove(index, lastIndex);
3430
3446
  } : undefined,
3431
- renderDragHandle: DragHandle
3447
+ renderDragHandle: DragHandle,
3448
+ isBeingDragged: index === indexToUpdate
3432
3449
  }));
3433
3450
  });
3434
3451
  });