@contentful/field-editor-reference 5.5.1 → 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,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.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
+
6
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)
7
13
 
8
14
  ### Bug Fixes
@@ -1,5 +1,4 @@
1
1
  import * as React from 'react';
2
- import { Offset, 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,11 +29,10 @@ export interface ReferenceEditorProps {
30
29
  updateBeforeSortStart?: ({ index }: {
31
30
  index: number;
32
31
  }) => void;
33
- onSortingEnd?: (({ oldIndex, newIndex, }: {
32
+ onSortingEnd?: ({ oldIndex, newIndex }: {
34
33
  oldIndex: number;
35
34
  newIndex: number;
36
- collection: Offset;
37
- }) => void) & SortEndHandler;
35
+ }) => void;
38
36
  }
39
37
  export declare type CustomActionProps = LinkActionsProps;
40
38
  export declare function ReferenceEditor<T>(props: ReferenceEditorProps & {
@@ -3296,17 +3296,17 @@ function Editor$1(props) {
3296
3296
  }, []);
3297
3297
  var onSortEnd = React.useCallback(function (_ref) {
3298
3298
  var oldIndex = _ref.oldIndex,
3299
- newIndex = _ref.newIndex,
3300
- collection = _ref.collection;
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
+ });
3301
3306
  var newItems = arrayMove(items, oldIndex, newIndex);
3302
3307
  setValue(newItems);
3303
3308
  setIndexToUpdate && setIndexToUpdate(undefined);
3304
3309
  document.body.classList.remove('grabbing');
3305
- props.onSortingEnd && props.onSortingEnd({
3306
- oldIndex: oldIndex,
3307
- newIndex: newIndex,
3308
- collection: collection
3309
- });
3310
3310
  }, [items, props, setIndexToUpdate, setValue]);
3311
3311
  var onMove = React.useCallback(function (oldIndex, newIndex) {
3312
3312
  var newItems = arrayMove(items, oldIndex, newIndex);