@contentful/field-editor-reference 5.23.0 → 5.25.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.
- package/dist/cjs/resources/Cards/ResourceCard.spec.js +1 -1
- package/dist/cjs/resources/ExternalResourceCard/ExternalResourceCard.js +44 -4
- package/dist/esm/resources/Cards/ResourceCard.spec.js +1 -1
- package/dist/esm/resources/ExternalResourceCard/ExternalResourceCard.js +40 -5
- package/dist/types/resources/ExternalResourceCard/ExternalResourceCard.d.ts +1 -1
- package/package.json +2 -2
|
@@ -224,6 +224,6 @@ describe('ResourceCard', ()=>{
|
|
|
224
224
|
});
|
|
225
225
|
await (0, _react1.waitFor)(()=>expect(getByTestId('cf-ui-entry-card')).toBeDefined());
|
|
226
226
|
expect(getByText(_resourcejson.default.fields.title)).toBeDefined();
|
|
227
|
-
expect(getByText(_resourcetypejson.default.name)).toBeDefined();
|
|
227
|
+
expect(getByText(`${_resourcetypejson.default.sys.resourceProvider.sys.id} ${_resourcetypejson.default.name}`)).toBeDefined();
|
|
228
228
|
});
|
|
229
229
|
});
|
|
@@ -10,6 +10,14 @@ Object.defineProperty(exports, "ExternalResourceCard", {
|
|
|
10
10
|
});
|
|
11
11
|
const _react = _interop_require_wildcard(require("react"));
|
|
12
12
|
const _f36components = require("@contentful/f36-components");
|
|
13
|
+
const _f36tokens = _interop_require_default(require("@contentful/f36-tokens"));
|
|
14
|
+
const _emotion = require("emotion");
|
|
15
|
+
const _truncate = _interop_require_default(require("truncate"));
|
|
16
|
+
function _interop_require_default(obj) {
|
|
17
|
+
return obj && obj.__esModule ? obj : {
|
|
18
|
+
default: obj
|
|
19
|
+
};
|
|
20
|
+
}
|
|
13
21
|
function _getRequireWildcardCache(nodeInterop) {
|
|
14
22
|
if (typeof WeakMap !== "function") return null;
|
|
15
23
|
var cacheBabelInterop = new WeakMap();
|
|
@@ -56,20 +64,48 @@ const defaultProps = {
|
|
|
56
64
|
hasCardMoveActions: true,
|
|
57
65
|
hasCardRemoveActions: true
|
|
58
66
|
};
|
|
67
|
+
const styles = {
|
|
68
|
+
subtitle: (0, _emotion.css)({
|
|
69
|
+
color: _f36tokens.default.gray600
|
|
70
|
+
}),
|
|
71
|
+
description: (0, _emotion.css)({
|
|
72
|
+
color: _f36tokens.default.gray900
|
|
73
|
+
})
|
|
74
|
+
};
|
|
59
75
|
function ExternalEntityBadge(badge) {
|
|
60
76
|
return badge ? _react.createElement(_f36components.Badge, {
|
|
61
77
|
variant: badge.variant
|
|
62
78
|
}, badge.label) : null;
|
|
63
79
|
}
|
|
64
|
-
function
|
|
80
|
+
function ExternalResourceCardDescription({ subtitle, description }) {
|
|
81
|
+
if (!subtitle) {
|
|
82
|
+
return null;
|
|
83
|
+
}
|
|
84
|
+
if (!description) {
|
|
85
|
+
return _react.createElement(_f36components.Paragraph, {
|
|
86
|
+
className: styles.description,
|
|
87
|
+
marginBottom: "none",
|
|
88
|
+
isWordBreak: true
|
|
89
|
+
}, subtitle);
|
|
90
|
+
}
|
|
91
|
+
const truncatedDescription = (0, _truncate.default)(description, 95, {});
|
|
92
|
+
return _react.createElement(_react.Fragment, null, _react.createElement(_f36components.Caption, {
|
|
93
|
+
className: styles.subtitle
|
|
94
|
+
}, subtitle), _react.createElement(_f36components.Paragraph, {
|
|
95
|
+
className: styles.description,
|
|
96
|
+
marginBottom: "none",
|
|
97
|
+
isWordBreak: true
|
|
98
|
+
}, truncatedDescription));
|
|
99
|
+
}
|
|
100
|
+
ExternalResourceCardDescription.displayName = 'ExternalResourceCardDescription';
|
|
101
|
+
function ExternalResourceCard({ info, isClickable, onEdit, onRemove, onMoveTop, onMoveBottom, hasCardEditActions, hasCardMoveActions, hasCardRemoveActions, renderDragHandle, onClick, isSelected }) {
|
|
65
102
|
const { resource: entity, resourceType } = info;
|
|
66
103
|
const badge = ExternalEntityBadge(entity.fields.badge);
|
|
67
104
|
return _react.createElement(_f36components.EntryCard, {
|
|
68
105
|
as: entity.fields.externalUrl ? 'a' : 'article',
|
|
69
106
|
href: entity.fields.externalUrl,
|
|
70
107
|
title: entity.fields.title,
|
|
71
|
-
|
|
72
|
-
contentType: resourceType.name,
|
|
108
|
+
contentType: `${resourceType.sys.resourceProvider.sys.id} ${resourceType.name}`,
|
|
73
109
|
size: 'auto',
|
|
74
110
|
thumbnailElement: entity.fields.image?.url ? _react.createElement("img", {
|
|
75
111
|
alt: entity.fields.image.altText,
|
|
@@ -78,6 +114,7 @@ function ExternalResourceCard({ info, isClickable, onEdit, onRemove, onMoveTop,
|
|
|
78
114
|
dragHandleRender: renderDragHandle,
|
|
79
115
|
withDragHandle: !!renderDragHandle,
|
|
80
116
|
badge: badge,
|
|
117
|
+
isSelected: isSelected,
|
|
81
118
|
actions: [
|
|
82
119
|
hasCardEditActions && onEdit ? _react.createElement(_f36components.MenuItem, {
|
|
83
120
|
key: "edit",
|
|
@@ -112,6 +149,9 @@ function ExternalResourceCard({ info, isClickable, onEdit, onRemove, onMoveTop,
|
|
|
112
149
|
if (onClick) return onClick(e);
|
|
113
150
|
onEdit && onEdit();
|
|
114
151
|
} : undefined
|
|
115
|
-
}
|
|
152
|
+
}, _react.createElement(ExternalResourceCardDescription, {
|
|
153
|
+
subtitle: entity.fields.subtitle,
|
|
154
|
+
description: entity.fields.description
|
|
155
|
+
}));
|
|
116
156
|
}
|
|
117
157
|
ExternalResourceCard.defaultProps = defaultProps;
|
|
@@ -174,6 +174,6 @@ describe('ResourceCard', ()=>{
|
|
|
174
174
|
});
|
|
175
175
|
await waitFor(()=>expect(getByTestId('cf-ui-entry-card')).toBeDefined());
|
|
176
176
|
expect(getByText(resource.fields.title)).toBeDefined();
|
|
177
|
-
expect(getByText(resourceType.name)).toBeDefined();
|
|
177
|
+
expect(getByText(`${resourceType.sys.resourceProvider.sys.id} ${resourceType.name}`)).toBeDefined();
|
|
178
178
|
});
|
|
179
179
|
});
|
|
@@ -1,24 +1,55 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { Badge, EntryCard, MenuItem, MenuDivider } from '@contentful/f36-components';
|
|
2
|
+
import { Badge, EntryCard, MenuItem, MenuDivider, Paragraph, Caption } from '@contentful/f36-components';
|
|
3
|
+
import tokens from '@contentful/f36-tokens';
|
|
4
|
+
import { css } from 'emotion';
|
|
5
|
+
import truncate from 'truncate';
|
|
3
6
|
const defaultProps = {
|
|
4
7
|
isClickable: true,
|
|
5
8
|
hasCardMoveActions: true,
|
|
6
9
|
hasCardRemoveActions: true
|
|
7
10
|
};
|
|
11
|
+
const styles = {
|
|
12
|
+
subtitle: css({
|
|
13
|
+
color: tokens.gray600
|
|
14
|
+
}),
|
|
15
|
+
description: css({
|
|
16
|
+
color: tokens.gray900
|
|
17
|
+
})
|
|
18
|
+
};
|
|
8
19
|
function ExternalEntityBadge(badge) {
|
|
9
20
|
return badge ? React.createElement(Badge, {
|
|
10
21
|
variant: badge.variant
|
|
11
22
|
}, badge.label) : null;
|
|
12
23
|
}
|
|
13
|
-
|
|
24
|
+
function ExternalResourceCardDescription({ subtitle, description }) {
|
|
25
|
+
if (!subtitle) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
if (!description) {
|
|
29
|
+
return React.createElement(Paragraph, {
|
|
30
|
+
className: styles.description,
|
|
31
|
+
marginBottom: "none",
|
|
32
|
+
isWordBreak: true
|
|
33
|
+
}, subtitle);
|
|
34
|
+
}
|
|
35
|
+
const truncatedDescription = truncate(description, 95, {});
|
|
36
|
+
return React.createElement(React.Fragment, null, React.createElement(Caption, {
|
|
37
|
+
className: styles.subtitle
|
|
38
|
+
}, subtitle), React.createElement(Paragraph, {
|
|
39
|
+
className: styles.description,
|
|
40
|
+
marginBottom: "none",
|
|
41
|
+
isWordBreak: true
|
|
42
|
+
}, truncatedDescription));
|
|
43
|
+
}
|
|
44
|
+
ExternalResourceCardDescription.displayName = 'ExternalResourceCardDescription';
|
|
45
|
+
export function ExternalResourceCard({ info, isClickable, onEdit, onRemove, onMoveTop, onMoveBottom, hasCardEditActions, hasCardMoveActions, hasCardRemoveActions, renderDragHandle, onClick, isSelected }) {
|
|
14
46
|
const { resource: entity, resourceType } = info;
|
|
15
47
|
const badge = ExternalEntityBadge(entity.fields.badge);
|
|
16
48
|
return React.createElement(EntryCard, {
|
|
17
49
|
as: entity.fields.externalUrl ? 'a' : 'article',
|
|
18
50
|
href: entity.fields.externalUrl,
|
|
19
51
|
title: entity.fields.title,
|
|
20
|
-
|
|
21
|
-
contentType: resourceType.name,
|
|
52
|
+
contentType: `${resourceType.sys.resourceProvider.sys.id} ${resourceType.name}`,
|
|
22
53
|
size: 'auto',
|
|
23
54
|
thumbnailElement: entity.fields.image?.url ? React.createElement("img", {
|
|
24
55
|
alt: entity.fields.image.altText,
|
|
@@ -27,6 +58,7 @@ export function ExternalResourceCard({ info, isClickable, onEdit, onRemove, onMo
|
|
|
27
58
|
dragHandleRender: renderDragHandle,
|
|
28
59
|
withDragHandle: !!renderDragHandle,
|
|
29
60
|
badge: badge,
|
|
61
|
+
isSelected: isSelected,
|
|
30
62
|
actions: [
|
|
31
63
|
hasCardEditActions && onEdit ? React.createElement(MenuItem, {
|
|
32
64
|
key: "edit",
|
|
@@ -61,6 +93,9 @@ export function ExternalResourceCard({ info, isClickable, onEdit, onRemove, onMo
|
|
|
61
93
|
if (onClick) return onClick(e);
|
|
62
94
|
onEdit && onEdit();
|
|
63
95
|
} : undefined
|
|
64
|
-
}
|
|
96
|
+
}, React.createElement(ExternalResourceCardDescription, {
|
|
97
|
+
subtitle: entity.fields.subtitle,
|
|
98
|
+
description: entity.fields.description
|
|
99
|
+
}));
|
|
65
100
|
}
|
|
66
101
|
ExternalResourceCard.defaultProps = defaultProps;
|
|
@@ -16,7 +16,7 @@ export interface ExternalResourceCardProps {
|
|
|
16
16
|
hasCardMoveActions?: boolean;
|
|
17
17
|
hasCardRemoveActions?: boolean;
|
|
18
18
|
}
|
|
19
|
-
export declare function ExternalResourceCard({ info, isClickable, onEdit, onRemove, onMoveTop, onMoveBottom, hasCardEditActions, hasCardMoveActions, hasCardRemoveActions, renderDragHandle, onClick, }: ExternalResourceCardProps): JSX.Element;
|
|
19
|
+
export declare function ExternalResourceCard({ info, isClickable, onEdit, onRemove, onMoveTop, onMoveBottom, hasCardEditActions, hasCardMoveActions, hasCardRemoveActions, renderDragHandle, onClick, isSelected, }: ExternalResourceCardProps): JSX.Element;
|
|
20
20
|
export declare namespace ExternalResourceCard {
|
|
21
21
|
var defaultProps: {
|
|
22
22
|
isClickable: boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@contentful/field-editor-reference",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.25.0",
|
|
4
4
|
"main": "dist/cjs/index.js",
|
|
5
5
|
"module": "dist/esm/index.js",
|
|
6
6
|
"types": "dist/types/index.d.ts",
|
|
@@ -67,5 +67,5 @@
|
|
|
67
67
|
"publishConfig": {
|
|
68
68
|
"registry": "https://npm.pkg.github.com/"
|
|
69
69
|
},
|
|
70
|
-
"gitHead": "
|
|
70
|
+
"gitHead": "1df39db2c93daecf0236570e3656a965eabc5ae0"
|
|
71
71
|
}
|