@squiz/formatted-text-editor 2.6.4 → 2.6.5
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 +6 -0
- package/demo/diff/AppContext.tsx +36 -2
- package/demo/diff/contentApi.json +21 -0
- package/demo/diff/index.scss +2 -0
- package/lib/ui/Fields/ResourceBrowserSelector/ResourceBrowserSelector.d.ts +3 -0
- package/lib/ui/Fields/ResourceBrowserSelector/ResourceBrowserSelector.js +8 -0
- package/lib/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.js +5 -1
- package/package.json +8 -8
- package/src/Editor/Editor.spec.tsx +1 -0
- package/src/ui/Fields/ResourceBrowserSelector/ResourceBrowserSelector.spec.tsx +71 -1
- package/src/ui/Fields/ResourceBrowserSelector/ResourceBrowserSelector.tsx +30 -16
- package/src/utils/converters/remirrorNodeToSquizNode/remirrorNodeToSquizNode.ts +6 -1
- package/tests/renderWithContext.tsx +2 -0
package/CHANGELOG.md
CHANGED
package/demo/diff/AppContext.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import DamResourceBrowserPlugin from '@squiz/dam-resource-browser-plugin';
|
1
|
+
import DamResourceBrowserPlugin, { DamResourceBrowserSource } from '@squiz/dam-resource-browser-plugin';
|
2
2
|
import { AiServiceProvider } from '@squiz/dxp-ai-client-react';
|
3
3
|
import MatrixResourceBrowserPlugin, {
|
4
4
|
Resource,
|
@@ -11,6 +11,7 @@ import { QueryClient, QueryClientProvider } from 'react-query';
|
|
11
11
|
import { EditorContext, ResolveNodeType } from '../../src';
|
12
12
|
import resources from './resources.json';
|
13
13
|
import sources from './sources.json';
|
14
|
+
import contentApi from './contentApi.json';
|
14
15
|
|
15
16
|
export type AppContextProps = PropsWithChildren;
|
16
17
|
|
@@ -38,9 +39,36 @@ export const AppContext = ({ children }: AppContextProps) => (
|
|
38
39
|
id: 'matrixIdentifier',
|
39
40
|
type: 'matrix',
|
40
41
|
},
|
42
|
+
{
|
43
|
+
name: 'Bynder',
|
44
|
+
id: 'bynder',
|
45
|
+
type: 'dam',
|
46
|
+
configuration: {
|
47
|
+
externalType: 'bynder',
|
48
|
+
externalRootUrl: 'https://squiz-sandbox.bynder.com',
|
49
|
+
authUrl: 'authUrl - See readme for local authToken instructions',
|
50
|
+
clientId: 'clientId - See readme for local authToken instructions',
|
51
|
+
redirectUrl: 'http://localhost:6006/',
|
52
|
+
},
|
53
|
+
} as DamResourceBrowserSource,
|
41
54
|
]),
|
42
55
|
plugins: [
|
43
|
-
DamResourceBrowserPlugin(
|
56
|
+
DamResourceBrowserPlugin({
|
57
|
+
onResourceRequestProxy: () => {
|
58
|
+
return Promise.resolve({
|
59
|
+
id: 'id1',
|
60
|
+
type: 'image',
|
61
|
+
fileSize: 300,
|
62
|
+
description: 'description1',
|
63
|
+
name: 'Bynder Image',
|
64
|
+
original: 'https://picsum.photos/300/250',
|
65
|
+
height: 100,
|
66
|
+
width: 200,
|
67
|
+
extension: ['jpeg'],
|
68
|
+
thumbnails: { thul: 'https://picsum.photos/300/250' },
|
69
|
+
});
|
70
|
+
},
|
71
|
+
}),
|
44
72
|
MatrixResourceBrowserPlugin({
|
45
73
|
onRequestSources: (): Promise<Source> => Promise.resolve(sources),
|
46
74
|
onRequestChildren: (source: Source, resource: Resource | null): Promise<Resource[]> =>
|
@@ -72,6 +100,12 @@ export const AppContext = ({ children }: AppContextProps) => (
|
|
72
100
|
nextStart: null,
|
73
101
|
},
|
74
102
|
}),
|
103
|
+
onRequestMatrixAsset: (assetId: string) => {
|
104
|
+
return Promise.resolve({
|
105
|
+
...contentApi,
|
106
|
+
id: assetId,
|
107
|
+
});
|
108
|
+
},
|
75
109
|
}),
|
76
110
|
],
|
77
111
|
}}
|
@@ -0,0 +1,21 @@
|
|
1
|
+
{
|
2
|
+
"id": "3",
|
3
|
+
"type": "image",
|
4
|
+
"type_name": "Image",
|
5
|
+
"name": "Image",
|
6
|
+
"short_name": "Image",
|
7
|
+
"urls": ["https://picsum.photos/300/250"],
|
8
|
+
"url": "https://picsum.photos/300/250",
|
9
|
+
"attributes": {
|
10
|
+
"name": "Image",
|
11
|
+
"title": "Image",
|
12
|
+
"width": 640,
|
13
|
+
"height": 438,
|
14
|
+
"size": 99384,
|
15
|
+
"variety_count": 5,
|
16
|
+
"allow_unrestricted": true,
|
17
|
+
"caption": "",
|
18
|
+
"alt": ""
|
19
|
+
},
|
20
|
+
"children": []
|
21
|
+
}
|
package/demo/diff/index.scss
CHANGED
@@ -1,5 +1,7 @@
|
|
1
|
+
@import '../../../../node_modules/@squiz/sds/lib/package.css';
|
1
2
|
@import '../../../../node_modules/@squiz/resource-browser/lib/index.css';
|
2
3
|
@import '../../../../node_modules/@squiz/matrix-resource-browser-plugin/lib/index.css';
|
4
|
+
@import '../../../../node_modules/@squiz/dam-resource-browser-plugin/lib/index.css';
|
3
5
|
|
4
6
|
body {
|
5
7
|
font-family: 'Open Sans';
|
@@ -40,6 +40,7 @@ const ResourceBrowserSelector = ({ modalTitle, allowedTypes, value, onChange, ..
|
|
40
40
|
return {
|
41
41
|
sourceId: value.damSystemIdentifier,
|
42
42
|
resourceId: value.damObjectId,
|
43
|
+
variant: value.damAdditional?.variant,
|
43
44
|
};
|
44
45
|
}
|
45
46
|
return null;
|
@@ -53,6 +54,7 @@ const ResourceBrowserSelector = ({ modalTitle, allowedTypes, value, onChange, ..
|
|
53
54
|
damSystemIdentifier: undefined,
|
54
55
|
damObjectId: undefined,
|
55
56
|
damSystemType: undefined,
|
57
|
+
damAdditional: undefined,
|
56
58
|
url: undefined,
|
57
59
|
};
|
58
60
|
if (resource?.source?.type === 'matrix') {
|
@@ -65,11 +67,17 @@ const ResourceBrowserSelector = ({ modalTitle, allowedTypes, value, onChange, ..
|
|
65
67
|
};
|
66
68
|
}
|
67
69
|
else if (resource?.source?.type === 'dam') {
|
70
|
+
const damResource = resource;
|
68
71
|
onChangeData = {
|
69
72
|
...value,
|
70
73
|
damSystemIdentifier: resource?.source?.id,
|
71
74
|
damObjectId: resource?.id,
|
72
75
|
damSystemType: (resource?.source).configuration.externalType,
|
76
|
+
damAdditional: damResource.variant
|
77
|
+
? {
|
78
|
+
variant: damResource.variant,
|
79
|
+
}
|
80
|
+
: undefined,
|
73
81
|
url: resource?.url,
|
74
82
|
nodeType: Extensions_1.NodeName.DAMImage,
|
75
83
|
};
|
@@ -115,12 +115,16 @@ const transformNode = (node) => {
|
|
115
115
|
};
|
116
116
|
}
|
117
117
|
if (node.type.name === Extensions_1.NodeName.DAMImage) {
|
118
|
+
let damAdditional = node.attrs.damAdditional;
|
119
|
+
if (damAdditional && typeof node.attrs.damAdditional === 'string') {
|
120
|
+
damAdditional = JSON.parse(node.attrs.damAdditional);
|
121
|
+
}
|
118
122
|
transformedNode = {
|
119
123
|
type: 'dam-image',
|
120
124
|
damObjectId: node.attrs.damObjectId,
|
121
125
|
damSystemIdentifier: node.attrs.damSystemIdentifier,
|
122
126
|
damSystemType: node.attrs.damSystemType,
|
123
|
-
damAdditional
|
127
|
+
damAdditional,
|
124
128
|
};
|
125
129
|
}
|
126
130
|
node.marks.forEach((mark) => {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@squiz/formatted-text-editor",
|
3
|
-
"version": "2.6.
|
3
|
+
"version": "2.6.5",
|
4
4
|
"main": "lib/index.js",
|
5
5
|
"types": "lib/index.d.ts",
|
6
6
|
"private": false,
|
@@ -33,16 +33,16 @@
|
|
33
33
|
"remirror": "2.0.39"
|
34
34
|
},
|
35
35
|
"devDependencies": {
|
36
|
-
"@squiz/dam-resource-browser-plugin": "^3.
|
36
|
+
"@squiz/dam-resource-browser-plugin": "^3.2.7",
|
37
37
|
"@squiz/dxp-ai-client-react": "^1.0.0",
|
38
|
-
"@squiz/matrix-resource-browser-plugin": "^3.1
|
39
|
-
"@squiz/resource-browser": "^3.
|
38
|
+
"@squiz/matrix-resource-browser-plugin": "^3.3.1",
|
39
|
+
"@squiz/resource-browser": "^3.2.2",
|
40
40
|
"@squiz/sds": "^1.5.0",
|
41
41
|
"@testing-library/cypress": "^10.0.2",
|
42
42
|
"@testing-library/jest-dom": "5.16.5",
|
43
43
|
"@testing-library/react": "14.0.0",
|
44
44
|
"@testing-library/user-event": "14.4.3",
|
45
|
-
"@types/node": "
|
45
|
+
"@types/node": "22.10.5",
|
46
46
|
"@types/react": "^18.2.45",
|
47
47
|
"@types/react-dom": "^18.2.18",
|
48
48
|
"@vitejs/plugin-react": "3.0.0",
|
@@ -70,10 +70,10 @@
|
|
70
70
|
"vite": "^4.5.3"
|
71
71
|
},
|
72
72
|
"peerDependencies": {
|
73
|
-
"@squiz/dam-resource-browser-plugin": "^3.1.0
|
73
|
+
"@squiz/dam-resource-browser-plugin": "^3.1.0",
|
74
74
|
"@squiz/dxp-ai-client-react": "^1.0.0",
|
75
|
-
"@squiz/matrix-resource-browser-plugin": "^3.1.0
|
76
|
-
"@squiz/resource-browser": "^3.1.0
|
75
|
+
"@squiz/matrix-resource-browser-plugin": "^3.1.0",
|
76
|
+
"@squiz/resource-browser": "^3.1.0",
|
77
77
|
"@squiz/sds": "^1.5.0",
|
78
78
|
"@types/react": "^16.14.0 || ^17 || ^18",
|
79
79
|
"@types/react-dom": "^16.9.0 || ^17 || ^18",
|
@@ -57,7 +57,6 @@ describe('ResourceBrowserSelector', () => {
|
|
57
57
|
value={{
|
58
58
|
damObjectId: '123-456-789',
|
59
59
|
damSystemIdentifier: 'zzz-xxx-ccc',
|
60
|
-
additional: 'addditional data',
|
61
60
|
}}
|
62
61
|
onChange={jest.fn()}
|
63
62
|
/>,
|
@@ -71,6 +70,30 @@ describe('ResourceBrowserSelector', () => {
|
|
71
70
|
},
|
72
71
|
}),
|
73
72
|
);
|
73
|
+
|
74
|
+
render(
|
75
|
+
<ResourceBrowserSelector
|
76
|
+
modalTitle="Insert asset"
|
77
|
+
value={{
|
78
|
+
damObjectId: '123-456-789',
|
79
|
+
damSystemIdentifier: 'zzz-xxx-ccc',
|
80
|
+
damAdditional: {
|
81
|
+
variant: 'v1',
|
82
|
+
},
|
83
|
+
}}
|
84
|
+
onChange={jest.fn()}
|
85
|
+
/>,
|
86
|
+
);
|
87
|
+
|
88
|
+
expect(resourceBrowserSpy).toHaveBeenCalledWith(
|
89
|
+
expect.objectContaining({
|
90
|
+
value: {
|
91
|
+
resourceId: '123-456-789',
|
92
|
+
sourceId: 'zzz-xxx-ccc',
|
93
|
+
variant: 'v1',
|
94
|
+
},
|
95
|
+
}),
|
96
|
+
);
|
74
97
|
});
|
75
98
|
|
76
99
|
it('AssetImage: Calls onChange with expected value when resources is selected', async () => {
|
@@ -155,6 +178,53 @@ describe('ResourceBrowserSelector', () => {
|
|
155
178
|
});
|
156
179
|
});
|
157
180
|
|
181
|
+
it('DAMImage: Calls onChange with expected value when variant resources is selected', async () => {
|
182
|
+
const handleChange = jest.fn();
|
183
|
+
setSelectedResource({
|
184
|
+
id: 'my-resource-id',
|
185
|
+
name: 'My resource',
|
186
|
+
url: 'myResourceUrl',
|
187
|
+
source: {
|
188
|
+
id: 'my-source-id',
|
189
|
+
type: 'dam',
|
190
|
+
configuration: {
|
191
|
+
externalType: 'bynder',
|
192
|
+
},
|
193
|
+
},
|
194
|
+
variant: 'v1',
|
195
|
+
} as unknown as ResourceBrowserResource);
|
196
|
+
|
197
|
+
render(
|
198
|
+
<ResourceBrowserSelector
|
199
|
+
modalTitle="Insert asset"
|
200
|
+
value={{ matrixIdentifier: undefined, matrixAssetId: undefined, additional: 'additional data' }}
|
201
|
+
onChange={handleChange}
|
202
|
+
/>,
|
203
|
+
);
|
204
|
+
|
205
|
+
// Trigger the onChange handler to be called
|
206
|
+
await waitFor(() => {
|
207
|
+
expect(screen.getByRole('button', { name: 'Select ResourceBrowser Resource' })).toBeInTheDocument();
|
208
|
+
});
|
209
|
+
fireEvent.click(await screen.findByRole('button', { name: 'Select ResourceBrowser Resource' }));
|
210
|
+
|
211
|
+
expect(handleChange).toHaveBeenCalledWith({
|
212
|
+
target: {
|
213
|
+
value: {
|
214
|
+
additional: 'additional data',
|
215
|
+
damObjectId: 'my-resource-id',
|
216
|
+
damSystemIdentifier: 'my-source-id',
|
217
|
+
damSystemType: 'bynder',
|
218
|
+
damAdditional: {
|
219
|
+
variant: 'v1',
|
220
|
+
},
|
221
|
+
url: 'myResourceUrl',
|
222
|
+
nodeType: 'DAMImage',
|
223
|
+
},
|
224
|
+
},
|
225
|
+
});
|
226
|
+
});
|
227
|
+
|
158
228
|
it('ImageAsset: Calls onChange with expected value when resources is cleared', async () => {
|
159
229
|
const handleChange = jest.fn();
|
160
230
|
setSelectedResource(null);
|
@@ -1,6 +1,6 @@
|
|
1
1
|
import React, { useCallback } from 'react';
|
2
|
-
import { ResourceBrowserResource, ResourceBrowser } from '@squiz/resource-browser';
|
3
|
-
import { DamResourceBrowserSource } from '@squiz/dam-resource-browser-plugin';
|
2
|
+
import { ResourceBrowserUnresolvedResource, ResourceBrowserResource, ResourceBrowser } from '@squiz/resource-browser';
|
3
|
+
import { DamResourceBrowserSource, DAMResource } from '@squiz/dam-resource-browser-plugin';
|
4
4
|
import { InputContainer, InputContainerProps } from '../InputContainer/InputContainer';
|
5
5
|
import { NodeName } from '../../../Extensions/Extensions';
|
6
6
|
|
@@ -12,6 +12,9 @@ type DAMAsset = {
|
|
12
12
|
damSystemIdentifier?: string;
|
13
13
|
damObjectId?: string;
|
14
14
|
damSystemType?: string;
|
15
|
+
damAdditional?: {
|
16
|
+
variant: string;
|
17
|
+
};
|
15
18
|
};
|
16
19
|
type ResourceBrowserSelectorValue = MatrixAsset &
|
17
20
|
DAMAsset & {
|
@@ -40,21 +43,25 @@ export const ResourceBrowserSelector = <T extends ResourceBrowserSelectorValue>(
|
|
40
43
|
onChange,
|
41
44
|
...props
|
42
45
|
}: ResourceBrowserSelectorProps<T>) => {
|
43
|
-
const convertFormDataToResourceBrowserValue = useCallback(
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
46
|
+
const convertFormDataToResourceBrowserValue = useCallback(
|
47
|
+
(value: T | null): ResourceBrowserUnresolvedResource | null => {
|
48
|
+
if (value?.matrixIdentifier && value?.matrixAssetId) {
|
49
|
+
return {
|
50
|
+
sourceId: value.matrixIdentifier,
|
51
|
+
resourceId: value.matrixAssetId,
|
52
|
+
};
|
53
|
+
} else if (value?.damSystemIdentifier && value?.damObjectId) {
|
54
|
+
return {
|
55
|
+
sourceId: value.damSystemIdentifier,
|
56
|
+
resourceId: value.damObjectId,
|
57
|
+
variant: value.damAdditional?.variant,
|
58
|
+
};
|
59
|
+
}
|
55
60
|
|
56
|
-
|
57
|
-
|
61
|
+
return null;
|
62
|
+
},
|
63
|
+
[],
|
64
|
+
);
|
58
65
|
|
59
66
|
const handleResourceChange = useCallback((resource: ResourceBrowserResource | null) => {
|
60
67
|
// Clear out any key properties for clear resource use case
|
@@ -65,6 +72,7 @@ export const ResourceBrowserSelector = <T extends ResourceBrowserSelectorValue>(
|
|
65
72
|
damSystemIdentifier: undefined,
|
66
73
|
damObjectId: undefined,
|
67
74
|
damSystemType: undefined,
|
75
|
+
damAdditional: undefined,
|
68
76
|
url: undefined,
|
69
77
|
};
|
70
78
|
|
@@ -77,11 +85,17 @@ export const ResourceBrowserSelector = <T extends ResourceBrowserSelectorValue>(
|
|
77
85
|
nodeType: NodeName.AssetImage,
|
78
86
|
};
|
79
87
|
} else if (resource?.source?.type === 'dam') {
|
88
|
+
const damResource = resource as DAMResource;
|
80
89
|
onChangeData = {
|
81
90
|
...value,
|
82
91
|
damSystemIdentifier: resource?.source?.id,
|
83
92
|
damObjectId: resource?.id,
|
84
93
|
damSystemType: (resource?.source as DamResourceBrowserSource).configuration.externalType,
|
94
|
+
damAdditional: damResource.variant
|
95
|
+
? {
|
96
|
+
variant: damResource.variant,
|
97
|
+
}
|
98
|
+
: undefined,
|
85
99
|
url: resource?.url,
|
86
100
|
nodeType: NodeName.DAMImage,
|
87
101
|
};
|
@@ -154,12 +154,17 @@ const transformNode = (node: ProsemirrorNode): FormattedNode => {
|
|
154
154
|
}
|
155
155
|
|
156
156
|
if (node.type.name === NodeName.DAMImage) {
|
157
|
+
let damAdditional = node.attrs.damAdditional;
|
158
|
+
if (damAdditional && typeof node.attrs.damAdditional === 'string') {
|
159
|
+
damAdditional = JSON.parse(node.attrs.damAdditional);
|
160
|
+
}
|
161
|
+
|
157
162
|
transformedNode = {
|
158
163
|
type: 'dam-image',
|
159
164
|
damObjectId: node.attrs.damObjectId,
|
160
165
|
damSystemIdentifier: node.attrs.damSystemIdentifier,
|
161
166
|
damSystemType: node.attrs.damSystemType,
|
162
|
-
damAdditional
|
167
|
+
damAdditional,
|
163
168
|
};
|
164
169
|
}
|
165
170
|
|
@@ -46,6 +46,7 @@ export const renderWithContext = (ui: ReactElement | null, options?: ContextRend
|
|
46
46
|
const onRequestChildren = jest.fn().mockResolvedValue(resources);
|
47
47
|
const onRequestResource = jest.fn(() => Promise.resolve(resources[0]));
|
48
48
|
const onSearchRequest = jest.fn();
|
49
|
+
const onRequestMatrixAsset = jest.fn();
|
49
50
|
editorContext.resolveNodeToUrl = jest.fn(() => Promise.resolve(resources[0].url));
|
50
51
|
|
51
52
|
return render(
|
@@ -67,6 +68,7 @@ export const renderWithContext = (ui: ReactElement | null, options?: ContextRend
|
|
67
68
|
onRequestChildren: onRequestChildren,
|
68
69
|
onRequestResource: onRequestResource,
|
69
70
|
onSearchRequest,
|
71
|
+
onRequestMatrixAsset,
|
70
72
|
}),
|
71
73
|
],
|
72
74
|
}}
|