@contentful/field-editor-reference 5.5.0 → 5.5.2

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.5.2](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.5.1...@contentful/field-editor-reference@5.5.2) (2022-11-07)
7
+
8
+ ### Bug Fixes
9
+
10
+ - onSortEnd before array move ([#1276](https://github.com/contentful/field-editors/issues/1276)) ([16f0eb0](https://github.com/contentful/field-editors/commit/16f0eb0db3bdb89820bb969a54833be3d6fd4f16))
11
+
12
+ ## [5.5.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.5.0...@contentful/field-editor-reference@5.5.1) (2022-11-07)
13
+
14
+ ### Bug Fixes
15
+
16
+ - on sort end multiple reference field ([#1273](https://github.com/contentful/field-editors/issues/1273)) ([1f7788b](https://github.com/contentful/field-editors/commit/1f7788bfb4de6a83b14c75578a43fa036202491e))
17
+
6
18
  # [5.5.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@5.4.0...@contentful/field-editor-reference@5.5.0) (2022-11-04)
7
19
 
8
20
  ### Features
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { SortEndHandler } from 'react-sortable-hoc';
3
2
  import { FieldConnector } from '@contentful/field-editor-shared';
4
3
  import type { LinkActionsProps } from '../components';
5
4
  import { Action, ActionLabels, FieldExtensionSDK, ViewType } from '../types';
@@ -30,9 +29,10 @@ export interface ReferenceEditorProps {
30
29
  updateBeforeSortStart?: ({ index }: {
31
30
  index: number;
32
31
  }) => void;
33
- onSortingEnd?: (({ index }: {
34
- index: number;
35
- }) => void) & SortEndHandler;
32
+ onSortingEnd?: ({ oldIndex, newIndex }: {
33
+ oldIndex: number;
34
+ newIndex: number;
35
+ }) => void;
36
36
  }
37
37
  export declare type CustomActionProps = LinkActionsProps;
38
38
  export declare function ReferenceEditor<T>(props: ReferenceEditorProps & {
@@ -3297,11 +3297,17 @@ function Editor$1(props) {
3297
3297
  var onSortEnd = React.useCallback(function (_ref) {
3298
3298
  var oldIndex = _ref.oldIndex,
3299
3299
  newIndex = _ref.newIndex;
3300
+ // custom callback that is invoked *before* we sort the array
3301
+ // e.g. in Compose we want to sort the references in the referenceMap before re-rendering drag and drop
3302
+ props.onSortingEnd && props.onSortingEnd({
3303
+ oldIndex: oldIndex,
3304
+ newIndex: newIndex
3305
+ });
3300
3306
  var newItems = arrayMove(items, oldIndex, newIndex);
3301
3307
  setValue(newItems);
3302
3308
  setIndexToUpdate && setIndexToUpdate(undefined);
3303
3309
  document.body.classList.remove('grabbing');
3304
- }, [items, setIndexToUpdate, setValue]);
3310
+ }, [items, props, setIndexToUpdate, setValue]);
3305
3311
  var onMove = React.useCallback(function (oldIndex, newIndex) {
3306
3312
  var newItems = arrayMove(items, oldIndex, newIndex);
3307
3313
  setValue(newItems);
@@ -3419,8 +3425,7 @@ function MultipleEntryReferenceEditor(props) {
3419
3425
  return React.createElement(SortableLinkList, _extends({}, childrenProps, {
3420
3426
  axis: "y",
3421
3427
  useDragHandle: true,
3422
- updateBeforeSortStart: updateBeforeSortStart,
3423
- onSortEnd: props.onSortingEnd
3428
+ updateBeforeSortStart: updateBeforeSortStart
3424
3429
  }), function (_ref2) {
3425
3430
  var items = _ref2.items,
3426
3431
  item = _ref2.item,