@contentful/field-editor-reference 4.5.0 → 4.6.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,24 @@
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.6.1](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@4.6.0...@contentful/field-editor-reference@4.6.1) (2022-07-18)
7
+
8
+ ### Bug Fixes
9
+
10
+ - correctly pass props to children of SortableLinkList ([#1187](https://github.com/contentful/field-editors/issues/1187)) ([5f574b9](https://github.com/contentful/field-editors/commit/5f574b938670290e8e2bb8c0b9bcb67720a83da9))
11
+
12
+ # [4.6.0](https://github.com/contentful/field-editors/compare/@contentful/field-editor-reference@4.5.1...@contentful/field-editor-reference@4.6.0) (2022-07-15)
13
+
14
+ ### Features
15
+
16
+ - export resource info type ([#1186](https://github.com/contentful/field-editors/issues/1186)) ([209e523](https://github.com/contentful/field-editors/commit/209e5237c634b05f40ad7b878deb65d5ff977008))
17
+
18
+ ## [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)
19
+
20
+ ### Bug Fixes
21
+
22
+ - generalise SortableLinkList into one component ([#1183](https://github.com/contentful/field-editors/issues/1183)) ([83117b0](https://github.com/contentful/field-editors/commit/83117b005ec93ef5481eb137a87733ae96c45d54))
23
+
6
24
  # [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
25
 
8
26
  ### 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> = Pick<SortableLinkListProps<IType>, 'items' | 'isDisabled'> & {
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 {};
@@ -3318,36 +3318,29 @@ var SortableLink = /*#__PURE__*/reactSortableHoc.SortableElement(function (props
3318
3318
  className: styles$3.item
3319
3319
  }, props.children);
3320
3320
  });
3321
- var SortableLinkList = /*#__PURE__*/reactSortableHoc.SortableContainer(function (props) {
3322
- var lastIndex = props.items.length - 1;
3321
+ var SortableLinkListInternal = /*#__PURE__*/reactSortableHoc.SortableContainer(function (props) {
3323
3322
  return React__default.createElement("div", {
3324
- className: styles$3.container
3323
+ className: emotion.cx(styles$3.container, props.className)
3325
3324
  }, props.items.map(function (item, index) {
3325
+ var _item$sys$urn;
3326
+
3326
3327
  return React__default.createElement(SortableLink, {
3327
3328
  disabled: props.isDisabled,
3328
- key: item.sys.id + "-" + index,
3329
+ key: ((_item$sys$urn = item.sys.urn) != null ? _item$sys$urn : item.sys.id) + "-" + index,
3329
3330
  index: index
3330
- }, React__default.createElement(FetchingWrappedEntryCard, Object.assign({}, props, {
3331
- key: item.sys.id + "-" + index,
3332
- index: index,
3333
- allContentTypes: props.allContentTypes,
3331
+ }, props.children({
3332
+ items: props.items,
3334
3333
  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
3348
- })));
3334
+ item: item,
3335
+ index: index,
3336
+ DragHandle: props.isDisabled ? undefined : DragHandle
3337
+ }));
3349
3338
  }));
3350
- });
3339
+ }); // HOC does not support generics, so we mimic it via additional component
3340
+
3341
+ function SortableLinkList(props) {
3342
+ return React__default.createElement(SortableLinkListInternal, Object.assign({}, props), props.children);
3343
+ }
3351
3344
 
3352
3345
  function MultipleEntryReferenceEditor(props) {
3353
3346
  return React.createElement(MultipleReferenceEditor, Object.assign({}, props, {
@@ -3356,7 +3349,33 @@ function MultipleEntryReferenceEditor(props) {
3356
3349
  return React.createElement(SortableLinkList, Object.assign({}, props, childrenProps, {
3357
3350
  axis: "y",
3358
3351
  useDragHandle: true
3359
- }));
3352
+ }), function (_ref) {
3353
+ var items = _ref.items,
3354
+ item = _ref.item,
3355
+ index = _ref.index,
3356
+ isDisabled = _ref.isDisabled,
3357
+ DragHandle = _ref.DragHandle;
3358
+ var lastIndex = items.length - 1;
3359
+ return React.createElement(FetchingWrappedEntryCard, Object.assign({}, props, {
3360
+ key: item.sys.id + "-" + index,
3361
+ index: index,
3362
+ allContentTypes: childrenProps.allContentTypes,
3363
+ isDisabled: isDisabled,
3364
+ entryId: item.sys.id,
3365
+ onRemove: function onRemove() {
3366
+ childrenProps.setValue(items.filter(function (_value, i) {
3367
+ return i !== index;
3368
+ }));
3369
+ },
3370
+ onMoveTop: index !== 0 ? function () {
3371
+ return childrenProps.onMove(index, 0);
3372
+ } : undefined,
3373
+ onMoveBottom: index !== lastIndex ? function () {
3374
+ return childrenProps.onMove(index, lastIndex);
3375
+ } : undefined,
3376
+ renderDragHandle: DragHandle
3377
+ }));
3378
+ });
3360
3379
  });
3361
3380
  }
3362
3381
 
@@ -3767,62 +3786,40 @@ SingleMediaEditor.defaultProps = {
3767
3786
  };
3768
3787
 
3769
3788
  var styles$6 = {
3770
- gridContainter: /*#__PURE__*/emotion.css({
3789
+ gridContainer: /*#__PURE__*/emotion.css({
3771
3790
  position: 'relative',
3772
3791
  display: 'flex',
3773
3792
  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
3793
  })
3782
3794
  };
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
3795
  function MultipleMediaEditor(props) {
3819
3796
  return React.createElement(MultipleReferenceEditor, Object.assign({}, props, {
3820
3797
  entityType: "Asset"
3821
3798
  }), function (childrenProps) {
3822
- return React.createElement(SortableLinkList$1, Object.assign({}, props, childrenProps, {
3823
- axis: props.viewType === 'card' ? 'xy' : 'y',
3799
+ var _cx;
3800
+
3801
+ return React.createElement(SortableLinkList, Object.assign({}, childrenProps, {
3802
+ className: emotion.cx((_cx = {}, _cx[styles$6.gridContainer] = childrenProps.viewType === 'card', _cx)),
3803
+ axis: childrenProps.viewType === 'card' ? 'xy' : 'y',
3824
3804
  useDragHandle: true
3825
- }));
3805
+ }), function (_ref) {
3806
+ var items = _ref.items,
3807
+ item = _ref.item,
3808
+ index = _ref.index,
3809
+ isDisabled = _ref.isDisabled,
3810
+ DragHandle = _ref.DragHandle;
3811
+ return React.createElement(FetchingWrappedAssetCard, Object.assign({}, props, {
3812
+ isDisabled: isDisabled,
3813
+ key: item.sys.id + "-" + index,
3814
+ assetId: item.sys.id,
3815
+ onRemove: function onRemove() {
3816
+ childrenProps.setValue(items.filter(function (_value, i) {
3817
+ return i !== index;
3818
+ }));
3819
+ },
3820
+ renderDragHandle: DragHandle
3821
+ }));
3822
+ });
3826
3823
  });
3827
3824
  }
3828
3825
  MultipleMediaEditor.defaultProps = {
@@ -3840,6 +3837,7 @@ exports.MultipleMediaEditor = MultipleMediaEditor;
3840
3837
  exports.ScheduledIconWithTooltip = ScheduledIconWithTooltip;
3841
3838
  exports.SingleEntryReferenceEditor = SingleEntryReferenceEditor;
3842
3839
  exports.SingleMediaEditor = SingleMediaEditor;
3840
+ exports.SortableLinkList = SortableLinkList;
3843
3841
  exports.WrappedAssetCard = WrappedAssetCard;
3844
3842
  exports.WrappedEntryCard = WrappedEntryCard;
3845
3843
  exports.getScheduleTooltipContent = getScheduleTooltipContent;