@contentful/field-editor-reference 4.5.0 → 4.5.1

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
+ ## [4.5.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@4.5.0...@contentful/field-editor-reference@4.5.1) (2022-07-12)
7
+
8
+ ### Bug Fixes
9
+
10
+ - generalise SortableLinkList into one component ([#1183](https://github.com/contentful/field-editors/issues/1183)) ([83117b0](https://github.com/contentful/field-editors/commit/83117b005ec93ef5481eb137a87733ae96c45d54))
11
+
6
12
  # [4.5.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@4.4.0...@contentful/field-editor-reference@4.5.0) (2022-07-11)
7
13
 
8
14
  ### Features
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { SortableContainerProps } from 'react-sortable-hoc';
3
+ import { ReferenceEditorProps } from './ReferenceEditor';
4
+ declare type SortableContainerChildProps<IType> = SortableLinkListProps<IType> & {
5
+ item: IType;
6
+ index: number;
7
+ DragHandle?: typeof DragHandle;
8
+ };
9
+ declare type SortableLinkListProps<T> = ReferenceEditorProps & {
10
+ items: T[];
11
+ isDisabled: boolean;
12
+ children: (props: SortableContainerChildProps<T>) => React.ReactElement;
13
+ className?: string;
14
+ };
15
+ declare const DragHandle: (props: {
16
+ drag: React.ReactElement;
17
+ }) => JSX.Element;
18
+ export declare function SortableLinkList<T>(props: SortableLinkListProps<T> & SortableContainerProps): JSX.Element;
19
+ export {};
@@ -3302,7 +3302,8 @@ var styles$3 = {
3302
3302
  position: 'relative'
3303
3303
  }),
3304
3304
  item: /*#__PURE__*/emotion.css({
3305
- marginBottom: tokens.spacingM
3305
+ marginBottom: tokens.spacingM,
3306
+ marginRight: tokens.spacingM
3306
3307
  })
3307
3308
  };
3308
3309
 
@@ -3318,45 +3319,56 @@ var SortableLink = /*#__PURE__*/reactSortableHoc.SortableElement(function (props
3318
3319
  className: styles$3.item
3319
3320
  }, props.children);
3320
3321
  });
3321
- var SortableLinkList = /*#__PURE__*/reactSortableHoc.SortableContainer(function (props) {
3322
- var lastIndex = props.items.length - 1;
3322
+ var SortableLinkListInternal = /*#__PURE__*/reactSortableHoc.SortableContainer(function (props) {
3323
3323
  return React__default.createElement("div", {
3324
- className: styles$3.container
3324
+ className: emotion.cx(styles$3.container, props.className)
3325
3325
  }, props.items.map(function (item, index) {
3326
+ var _item$sys$id;
3327
+
3326
3328
  return React__default.createElement(SortableLink, {
3327
3329
  disabled: props.isDisabled,
3328
- key: item.sys.id + "-" + index,
3330
+ key: ((_item$sys$id = item.sys.id) != null ? _item$sys$id : item.sys.urn) + "-" + index,
3329
3331
  index: index
3330
- }, React__default.createElement(FetchingWrappedEntryCard, Object.assign({}, props, {
3331
- key: item.sys.id + "-" + index,
3332
+ }, props.children(_extends({}, props, {
3333
+ item: item,
3332
3334
  index: index,
3333
- allContentTypes: props.allContentTypes,
3334
- isDisabled: props.isDisabled,
3335
- entryId: item.sys.id,
3336
- onRemove: function onRemove() {
3337
- props.setValue(props.items.filter(function (_value, i) {
3338
- return i !== index;
3339
- }));
3340
- },
3341
- onMoveTop: index !== 0 ? function () {
3342
- return props.onMove(index, 0);
3343
- } : undefined,
3344
- onMoveBottom: index !== lastIndex ? function () {
3345
- return props.onMove(index, lastIndex);
3346
- } : undefined,
3347
- renderDragHandle: props.isDisabled ? undefined : DragHandle
3335
+ DragHandle: props.isDisabled ? undefined : DragHandle
3348
3336
  })));
3349
3337
  }));
3350
- });
3338
+ }); // HOC does not support generics, so we mimic it via additional component
3339
+
3340
+ function SortableLinkList(props) {
3341
+ return React__default.createElement(SortableLinkListInternal, Object.assign({}, props, {
3342
+ children: props.children
3343
+ }));
3344
+ }
3351
3345
 
3352
3346
  function MultipleEntryReferenceEditor(props) {
3353
3347
  return React.createElement(MultipleReferenceEditor, Object.assign({}, props, {
3354
3348
  entityType: "Entry"
3355
3349
  }), function (childrenProps) {
3356
- return React.createElement(SortableLinkList, Object.assign({}, props, childrenProps, {
3357
- axis: "y",
3358
- useDragHandle: true
3359
- }));
3350
+ return React.createElement(SortableLinkList, Object.assign({}, childrenProps), function (props) {
3351
+ var lastIndex = props.items.length - 1;
3352
+ return React.createElement(FetchingWrappedEntryCard, Object.assign({}, props, {
3353
+ key: props.item.sys.id + "-" + props.index,
3354
+ index: props.index,
3355
+ allContentTypes: childrenProps.allContentTypes,
3356
+ isDisabled: props.isDisabled,
3357
+ entryId: props.item.sys.id,
3358
+ onRemove: function onRemove() {
3359
+ childrenProps.setValue(props.items.filter(function (_value, i) {
3360
+ return i !== props.index;
3361
+ }));
3362
+ },
3363
+ onMoveTop: props.index !== 0 ? function () {
3364
+ return childrenProps.onMove(props.index, 0);
3365
+ } : undefined,
3366
+ onMoveBottom: props.index !== lastIndex ? function () {
3367
+ return childrenProps.onMove(props.index, lastIndex);
3368
+ } : undefined,
3369
+ renderDragHandle: props.DragHandle
3370
+ }));
3371
+ });
3360
3372
  });
3361
3373
  }
3362
3374
 
@@ -3767,62 +3779,33 @@ SingleMediaEditor.defaultProps = {
3767
3779
  };
3768
3780
 
3769
3781
  var styles$6 = {
3770
- gridContainter: /*#__PURE__*/emotion.css({
3782
+ gridContainer: /*#__PURE__*/emotion.css({
3771
3783
  position: 'relative',
3772
3784
  display: 'flex',
3773
3785
  flexWrap: 'wrap'
3774
- }),
3775
- container: /*#__PURE__*/emotion.css({
3776
- position: 'relative'
3777
- }),
3778
- item: /*#__PURE__*/emotion.css({
3779
- marginBottom: tokens.spacingM,
3780
- marginRight: tokens.spacingM
3781
3786
  })
3782
3787
  };
3783
-
3784
- var DragHandle$1 = function DragHandle(props) {
3785
- var SortableDragHandle = reactSortableHoc.SortableHandle(function () {
3786
- return props.drag;
3787
- });
3788
- return React__default.createElement(SortableDragHandle, null);
3789
- };
3790
-
3791
- var SortableLink$1 = /*#__PURE__*/reactSortableHoc.SortableElement(function (props) {
3792
- return React__default.createElement("div", {
3793
- className: styles$6.item
3794
- }, props.children);
3795
- });
3796
- var SortableLinkList$1 = /*#__PURE__*/reactSortableHoc.SortableContainer(function (props) {
3797
- return React__default.createElement("div", {
3798
- className: props.viewType === 'card' ? styles$6.gridContainter : styles$6.container
3799
- }, props.items.map(function (item, index) {
3800
- return React__default.createElement(SortableLink$1, {
3801
- disabled: props.isDisabled,
3802
- key: item.sys.id + "-" + index,
3803
- index: index
3804
- }, React__default.createElement(FetchingWrappedAssetCard, Object.assign({}, props, {
3805
- sdk: props.sdk,
3806
- key: item.sys.id + "-" + index,
3807
- assetId: item.sys.id,
3808
- onRemove: function onRemove() {
3809
- props.setValue(props.items.filter(function (_value, i) {
3810
- return i !== index;
3811
- }));
3812
- },
3813
- renderDragHandle: props.isDisabled ? undefined : DragHandle$1
3814
- })));
3815
- }));
3816
- });
3817
-
3818
3788
  function MultipleMediaEditor(props) {
3819
3789
  return React.createElement(MultipleReferenceEditor, Object.assign({}, props, {
3820
3790
  entityType: "Asset"
3821
3791
  }), function (childrenProps) {
3822
- return React.createElement(SortableLinkList$1, Object.assign({}, props, childrenProps, {
3823
- axis: props.viewType === 'card' ? 'xy' : 'y',
3824
- useDragHandle: true
3825
- }));
3792
+ var _cx;
3793
+
3794
+ return React.createElement(SortableLinkList, Object.assign({}, childrenProps, {
3795
+ className: emotion.cx((_cx = {}, _cx[styles$6.gridContainer] = childrenProps.viewType === 'card', _cx)),
3796
+ axis: childrenProps.viewType === 'card' ? 'xy' : 'y'
3797
+ }), function (props) {
3798
+ return React.createElement(FetchingWrappedAssetCard, Object.assign({}, props, {
3799
+ key: props.item.sys.id + "-" + props.index,
3800
+ assetId: props.item.sys.id,
3801
+ onRemove: function onRemove() {
3802
+ childrenProps.setValue(props.items.filter(function (_value, i) {
3803
+ return i !== props.index;
3804
+ }));
3805
+ },
3806
+ renderDragHandle: props.DragHandle
3807
+ }));
3808
+ });
3826
3809
  });
3827
3810
  }
3828
3811
  MultipleMediaEditor.defaultProps = {
@@ -3840,6 +3823,7 @@ exports.MultipleMediaEditor = MultipleMediaEditor;
3840
3823
  exports.ScheduledIconWithTooltip = ScheduledIconWithTooltip;
3841
3824
  exports.SingleEntryReferenceEditor = SingleEntryReferenceEditor;
3842
3825
  exports.SingleMediaEditor = SingleMediaEditor;
3826
+ exports.SortableLinkList = SortableLinkList;
3843
3827
  exports.WrappedAssetCard = WrappedAssetCard;
3844
3828
  exports.WrappedEntryCard = WrappedEntryCard;
3845
3829
  exports.getScheduleTooltipContent = getScheduleTooltipContent;