@contentful/field-editor-reference 6.6.5 → 6.7.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.
@@ -130,25 +130,16 @@ function FetchingWrappedAssetCard(props) {
130
130
  localesStatusMap,
131
131
  activeLocales
132
132
  };
133
- if (props.viewType === 'link') {
134
- if (status === 'loading') {
135
- return _react.createElement(_f36components.EntryCard, {
136
- size: "small",
137
- isLoading: true
138
- });
139
- }
140
- return _react.createElement(_WrappedAssetLink.WrappedAssetLink, {
141
- ...commonProps,
142
- href: commonProps.entityUrl,
143
- getEntityScheduledActions: loadEntityScheduledActions
144
- });
145
- }
146
133
  if (status === 'loading') {
147
- return _react.createElement(_f36components.AssetCard, {
134
+ return props.viewType === 'link' ? _react.createElement(_f36components.EntryCard, {
135
+ size: "small",
136
+ isLoading: true
137
+ }) : _react.createElement(_f36components.AssetCard, {
148
138
  size: size,
149
139
  isLoading: true
150
140
  });
151
141
  }
142
+ const viewType = props.viewType;
152
143
  function renderDefaultCard(props) {
153
144
  const builtinCardProps = {
154
145
  ...commonProps,
@@ -157,6 +148,13 @@ function FetchingWrappedAssetCard(props) {
157
148
  asset: props?.entity || commonProps.asset,
158
149
  getAssetUrl: getEntityUrl
159
150
  };
151
+ if (viewType === 'link') {
152
+ return _react.createElement(_WrappedAssetLink.WrappedAssetLink, {
153
+ ...builtinCardProps,
154
+ href: commonProps.entityUrl,
155
+ getEntityScheduledActions: loadEntityScheduledActions
156
+ });
157
+ }
160
158
  return _react.createElement(_WrappedAssetCard.WrappedAssetCard, builtinCardProps);
161
159
  }
162
160
  if (props.renderCustomCard) {
@@ -104,12 +104,12 @@ const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLocaleCod
104
104
  const entityFile = asset.fields.file ? asset.fields.file[localeCode] || asset.fields.file[defaultLocaleCode] : undefined;
105
105
  const href = getAssetUrl ? getAssetUrl(asset.sys.id) : undefined;
106
106
  return _react.createElement(_f36components.AssetCard, {
107
- as: href ? 'a' : 'article',
107
+ as: isClickable && href ? 'a' : 'article',
108
108
  type: getFileType(entityFile),
109
109
  title: entityTitle,
110
110
  className: className,
111
111
  isSelected: isSelected,
112
- href: href,
112
+ href: isClickable ? href : undefined,
113
113
  badge: _react.createElement(_components.EntityStatusBadge, {
114
114
  getEntityScheduledActions: getEntityScheduledActions,
115
115
  entityType: "Asset",
@@ -55,7 +55,7 @@ function _interop_require_wildcard(obj, nodeInterop) {
55
55
  return newObj;
56
56
  }
57
57
  const WrappedAssetLink = (props)=>{
58
- const { className, href, onEdit, onRemove, isDisabled } = props;
58
+ const { className, href, onEdit, onRemove, isDisabled, isClickable = true } = props;
59
59
  const status = _fieldeditorshared.entityHelpers.getEntityStatus(props.asset.sys, props.useLocalizedEntityStatus ? props.localeCode : undefined);
60
60
  if (status === 'deleted') {
61
61
  return _react.createElement(_components.MissingAssetCard, {
@@ -71,11 +71,11 @@ const WrappedAssetLink = (props)=>{
71
71
  });
72
72
  const entityFile = props.asset.fields.file ? props.asset.fields.file[props.localeCode] || props.asset.fields.file[props.defaultLocaleCode] : undefined;
73
73
  return _react.createElement(_f36components.EntryCard, {
74
- as: href ? 'a' : 'article',
74
+ as: isClickable && href ? 'a' : 'article',
75
75
  contentType: "Asset",
76
76
  title: entityTitle,
77
77
  className: className,
78
- href: href,
78
+ href: isClickable ? href : undefined,
79
79
  size: "small",
80
80
  badge: _react.createElement(_components.EntityStatusBadge, {
81
81
  getEntityScheduledActions: props.getEntityScheduledActions,
@@ -89,16 +89,16 @@ const WrappedAssetLink = (props)=>{
89
89
  thumbnailElement: entityFile && (0, _fieldeditorshared.isValidImage)(entityFile) ? _react.createElement(_components.AssetThumbnail, {
90
90
  file: entityFile
91
91
  }) : undefined,
92
- onClick: (e)=>{
92
+ onClick: isClickable ? (e)=>{
93
93
  e.preventDefault();
94
- onEdit();
95
- },
96
- onKeyDown: (e)=>{
94
+ onEdit && onEdit();
95
+ } : undefined,
96
+ onKeyDown: isClickable ? (e)=>{
97
97
  if (e.key === 'Enter' && onEdit) {
98
98
  e.preventDefault();
99
99
  onEdit();
100
100
  }
101
- },
101
+ } : undefined,
102
102
  dragHandleRender: props.renderDragHandle,
103
103
  withDragHandle: !!props.renderDragHandle && !isDisabled,
104
104
  actions: [
@@ -221,7 +221,8 @@ async function fetchExternalResource({ urn, fetch, options, spaceId, environment
221
221
  spaceId,
222
222
  environmentId,
223
223
  resourceType,
224
- urn
224
+ urn,
225
+ locale
225
226
  ], ({ cmaClient })=>cmaClient.resource.getMany({
226
227
  spaceId,
227
228
  environmentId,
@@ -113,8 +113,8 @@ function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales, localeC
113
113
  defaultLocaleCode
114
114
  });
115
115
  return _react.createElement(_f36components.EntryCard, {
116
- as: entryUrl ? 'a' : 'article',
117
- href: entryUrl,
116
+ as: isClickable && entryUrl ? 'a' : 'article',
117
+ href: isClickable ? entryUrl : undefined,
118
118
  title: title,
119
119
  description: description,
120
120
  contentType: contentType?.name,
@@ -79,25 +79,16 @@ export function FetchingWrappedAssetCard(props) {
79
79
  localesStatusMap,
80
80
  activeLocales
81
81
  };
82
- if (props.viewType === 'link') {
83
- if (status === 'loading') {
84
- return React.createElement(EntryCard, {
85
- size: "small",
86
- isLoading: true
87
- });
88
- }
89
- return React.createElement(WrappedAssetLink, {
90
- ...commonProps,
91
- href: commonProps.entityUrl,
92
- getEntityScheduledActions: loadEntityScheduledActions
93
- });
94
- }
95
82
  if (status === 'loading') {
96
- return React.createElement(AssetCard, {
83
+ return props.viewType === 'link' ? React.createElement(EntryCard, {
84
+ size: "small",
85
+ isLoading: true
86
+ }) : React.createElement(AssetCard, {
97
87
  size: size,
98
88
  isLoading: true
99
89
  });
100
90
  }
91
+ const viewType = props.viewType;
101
92
  function renderDefaultCard(props) {
102
93
  const builtinCardProps = {
103
94
  ...commonProps,
@@ -106,6 +97,13 @@ export function FetchingWrappedAssetCard(props) {
106
97
  asset: props?.entity || commonProps.asset,
107
98
  getAssetUrl: getEntityUrl
108
99
  };
100
+ if (viewType === 'link') {
101
+ return React.createElement(WrappedAssetLink, {
102
+ ...builtinCardProps,
103
+ href: commonProps.entityUrl,
104
+ getEntityScheduledActions: loadEntityScheduledActions
105
+ });
106
+ }
109
107
  return React.createElement(WrappedAssetCard, builtinCardProps);
110
108
  }
111
109
  if (props.renderCustomCard) {
@@ -48,12 +48,12 @@ export const WrappedAssetCard = ({ asset, className, size, localeCode, defaultLo
48
48
  const entityFile = asset.fields.file ? asset.fields.file[localeCode] || asset.fields.file[defaultLocaleCode] : undefined;
49
49
  const href = getAssetUrl ? getAssetUrl(asset.sys.id) : undefined;
50
50
  return React.createElement(AssetCard, {
51
- as: href ? 'a' : 'article',
51
+ as: isClickable && href ? 'a' : 'article',
52
52
  type: getFileType(entityFile),
53
53
  title: entityTitle,
54
54
  className: className,
55
55
  isSelected: isSelected,
56
- href: href,
56
+ href: isClickable ? href : undefined,
57
57
  badge: React.createElement(EntityStatusBadge, {
58
58
  getEntityScheduledActions: getEntityScheduledActions,
59
59
  entityType: "Asset",
@@ -4,7 +4,7 @@ import { entityHelpers, isValidImage } from '@contentful/field-editor-shared';
4
4
  import { AssetThumbnail, EntityStatusBadge, MissingAssetCard } from '../../components';
5
5
  import { renderActions, renderAssetInfo } from './AssetCardActions';
6
6
  export const WrappedAssetLink = (props)=>{
7
- const { className, href, onEdit, onRemove, isDisabled } = props;
7
+ const { className, href, onEdit, onRemove, isDisabled, isClickable = true } = props;
8
8
  const status = entityHelpers.getEntityStatus(props.asset.sys, props.useLocalizedEntityStatus ? props.localeCode : undefined);
9
9
  if (status === 'deleted') {
10
10
  return React.createElement(MissingAssetCard, {
@@ -20,11 +20,11 @@ export const WrappedAssetLink = (props)=>{
20
20
  });
21
21
  const entityFile = props.asset.fields.file ? props.asset.fields.file[props.localeCode] || props.asset.fields.file[props.defaultLocaleCode] : undefined;
22
22
  return React.createElement(EntryCard, {
23
- as: href ? 'a' : 'article',
23
+ as: isClickable && href ? 'a' : 'article',
24
24
  contentType: "Asset",
25
25
  title: entityTitle,
26
26
  className: className,
27
- href: href,
27
+ href: isClickable ? href : undefined,
28
28
  size: "small",
29
29
  badge: React.createElement(EntityStatusBadge, {
30
30
  getEntityScheduledActions: props.getEntityScheduledActions,
@@ -38,16 +38,16 @@ export const WrappedAssetLink = (props)=>{
38
38
  thumbnailElement: entityFile && isValidImage(entityFile) ? React.createElement(AssetThumbnail, {
39
39
  file: entityFile
40
40
  }) : undefined,
41
- onClick: (e)=>{
41
+ onClick: isClickable ? (e)=>{
42
42
  e.preventDefault();
43
- onEdit();
44
- },
45
- onKeyDown: (e)=>{
43
+ onEdit && onEdit();
44
+ } : undefined,
45
+ onKeyDown: isClickable ? (e)=>{
46
46
  if (e.key === 'Enter' && onEdit) {
47
47
  e.preventDefault();
48
48
  onEdit();
49
49
  }
50
- },
50
+ } : undefined,
51
51
  dragHandleRender: props.renderDragHandle,
52
52
  withDragHandle: !!props.renderDragHandle && !isDisabled,
53
53
  actions: [
@@ -133,7 +133,8 @@ async function fetchExternalResource({ urn, fetch, options, spaceId, environment
133
133
  spaceId,
134
134
  environmentId,
135
135
  resourceType,
136
- urn
136
+ urn,
137
+ locale
137
138
  ], ({ cmaClient })=>cmaClient.resource.getMany({
138
139
  spaceId,
139
140
  environmentId,
@@ -62,8 +62,8 @@ export function WrappedEntryCard({ entry, entryUrl, contentType, activeLocales,
62
62
  defaultLocaleCode
63
63
  });
64
64
  return React.createElement(EntryCard, {
65
- as: entryUrl ? 'a' : 'article',
66
- href: entryUrl,
65
+ as: isClickable && entryUrl ? 'a' : 'article',
66
+ href: isClickable ? entryUrl : undefined,
67
67
  title: title,
68
68
  description: description,
69
69
  contentType: contentType?.name,
@@ -16,7 +16,7 @@ export interface WrappedAssetCardProps {
16
16
  onRemove?: () => void;
17
17
  size: 'default' | 'small';
18
18
  renderDragHandle?: RenderDragFn;
19
- isClickable: boolean;
19
+ isClickable?: boolean;
20
20
  useLocalizedEntityStatus?: boolean;
21
21
  localesStatusMap?: LocalePublishStatusMap;
22
22
  activeLocales?: Pick<LocaleProps, 'code'>[];
@@ -10,11 +10,12 @@ export interface WrappedAssetLinkProps {
10
10
  href?: string;
11
11
  className?: string;
12
12
  isDisabled: boolean;
13
- onEdit: () => void;
14
- onRemove: () => void;
13
+ onEdit?: () => void;
14
+ onRemove?: () => void;
15
15
  renderDragHandle?: RenderDragFn;
16
16
  useLocalizedEntityStatus?: boolean;
17
17
  localesStatusMap?: LocalePublishStatusMap;
18
18
  activeLocales?: Pick<LocaleProps, 'code'>[];
19
+ isClickable?: boolean;
19
20
  }
20
21
  export declare const WrappedAssetLink: (props: WrappedAssetLinkProps) => React.JSX.Element;
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { LocalePublishStatusMap } from '@contentful/field-editor-shared';
3
3
  import { LocaleProps } from 'contentful-management';
4
+ import { WrappedAssetCardProps } from '../assets/WrappedAssetCard/WrappedAssetCard';
4
5
  import { Asset, ContentType, Entry, RenderDragFn } from '../types';
5
6
  import { CustomActionProps } from './ReferenceEditor';
6
7
  export type MissingEntityCardProps = {
@@ -11,8 +12,8 @@ export type MissingEntityCardProps = {
11
12
  };
12
13
  };
13
14
  export type RenderCustomMissingEntityCard = ({ defaultCard, }: MissingEntityCardProps) => React.ReactElement;
14
- export type DefaultCardRenderer = (props?: CustomEntityCardProps) => React.ReactElement;
15
- export type CustomCardRenderer = (props: CustomEntityCardProps, linkActionsProps: CustomActionProps, renderDefaultCard: DefaultCardRenderer) => React.ReactElement | false;
15
+ export type DefaultCardRenderer = (props?: Partial<CustomEntityCardProps>) => React.ReactElement;
16
+ export type CustomCardRenderer = (props: CustomEntityCardProps, linkActionsProps: CustomActionProps, renderDefaultCard?: DefaultCardRenderer) => React.ReactElement | false;
16
17
  export type CustomEntityCardProps = {
17
18
  entity: Entry | Asset;
18
19
  entityUrl?: string;
@@ -31,4 +32,4 @@ export type CustomEntityCardProps = {
31
32
  useLocalizedEntityStatus?: boolean;
32
33
  localesStatusMap?: LocalePublishStatusMap;
33
34
  activeLocales?: Pick<LocaleProps, 'code'>[];
34
- };
35
+ } & Partial<WrappedAssetCardProps>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@contentful/field-editor-reference",
3
- "version": "6.6.5",
3
+ "version": "6.7.0",
4
4
  "main": "dist/cjs/index.js",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -64,5 +64,5 @@
64
64
  "publishConfig": {
65
65
  "registry": "https://npm.pkg.github.com/"
66
66
  },
67
- "gitHead": "eeb191f47b0820764640609ab4af6276689e0bfa"
67
+ "gitHead": "e9c9de2532a5812f7371dd59df96e7c5139b73c2"
68
68
  }