@vonaffenfels/slate-editor 1.0.53 → 1.0.55
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/slate-editor",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.55",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"cssnano": "^5.0.1",
|
|
72
72
|
"escape-html": "^1.0.3"
|
|
73
73
|
},
|
|
74
|
-
"gitHead": "
|
|
74
|
+
"gitHead": "b5aaf96b81e9d38533cc632505e6c78553e55e22",
|
|
75
75
|
"publishConfig": {
|
|
76
76
|
"access": "public"
|
|
77
77
|
}
|
package/src/Nodes/Element.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {IconButton} from "../SidebarEditor";
|
|
2
2
|
import {swapArrayElements} from "../helper/array";
|
|
3
|
+
import {reduceContentfulResponse} from "../util/reduceContentfulResponse";
|
|
3
4
|
import {
|
|
4
5
|
Asset, AssetList,
|
|
5
6
|
} from "./AssetList";
|
|
@@ -248,7 +249,7 @@ export const SidebarEditorField = ({
|
|
|
248
249
|
className="button"
|
|
249
250
|
onClick={() => {
|
|
250
251
|
sdk.dialogs.selectSingleEntry({contentTypes: field.control.contentTypes}).then(content => {
|
|
251
|
-
onChange(fieldKey, content);
|
|
252
|
+
onChange(fieldKey, reduceContentfulResponse(content, field.control.paths));
|
|
252
253
|
});
|
|
253
254
|
}}
|
|
254
255
|
>Auswählen</button>
|
|
@@ -267,7 +268,7 @@ export const SidebarEditorField = ({
|
|
|
267
268
|
onChange={v => onChange(fieldKey, v)}
|
|
268
269
|
onAddClick={() => {
|
|
269
270
|
sdk.dialogs.selectMultipleEntries({contentTypes: field.control.contentTypes}).then(contents => {
|
|
270
|
-
onChange(fieldKey, [...value, ...contents]);
|
|
271
|
+
onChange(fieldKey, reduceContentfulResponse([...value, ...contents], field.control.paths));
|
|
271
272
|
});
|
|
272
273
|
}} />
|
|
273
274
|
</div>
|
|
@@ -277,7 +278,7 @@ export const SidebarEditorField = ({
|
|
|
277
278
|
className="button"
|
|
278
279
|
onClick={() => {
|
|
279
280
|
sdk.dialogs.selectMultipleEntries({contentTypes: field.control.contentTypes}).then(contents => {
|
|
280
|
-
onChange(fieldKey, contents);
|
|
281
|
+
onChange(fieldKey, reduceContentfulResponse(contents, field.control.paths));
|
|
281
282
|
});
|
|
282
283
|
}}
|
|
283
284
|
>Auswählen</button>
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
export const reduceContentfulResponse = (item, paths) => {
|
|
2
|
+
|
|
3
|
+
if (Array.isArray(item)) {
|
|
4
|
+
return item.map(v => reduceContentfulResponse(v, paths));
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
if (!paths?.length || !item) {
|
|
8
|
+
return item;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const defaultPaths = [
|
|
12
|
+
"__typename",
|
|
13
|
+
"sys.id",
|
|
14
|
+
"sys.contentType.sys.id",
|
|
15
|
+
];
|
|
16
|
+
const mergedPaths = [...defaultPaths, ...paths];
|
|
17
|
+
|
|
18
|
+
const result = {
|
|
19
|
+
sys: {
|
|
20
|
+
id: item?.sys?.id,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
for (let i = 0; i < mergedPaths.length; i++) {
|
|
25
|
+
const path = mergedPaths[i];
|
|
26
|
+
|
|
27
|
+
setByPath(result, path, getByPath(item, path));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export const getByPath = (obj, path) => {
|
|
34
|
+
if (!obj || !path) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const pathParts = path.split(".");
|
|
39
|
+
|
|
40
|
+
if (pathParts.length === 1) {
|
|
41
|
+
return obj?.[pathParts[0]];
|
|
42
|
+
} else {
|
|
43
|
+
const currPart = pathParts.shift();
|
|
44
|
+
return getByPath(obj?.[currPart], pathParts.join("."));
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const setByPath = (obj, path, value) => {
|
|
49
|
+
const pathParts = path.split(".");
|
|
50
|
+
let objPointer = obj;
|
|
51
|
+
|
|
52
|
+
for (let i = 0; i < pathParts.length; i++) {
|
|
53
|
+
const pathPart = pathParts[i];
|
|
54
|
+
|
|
55
|
+
if (i === pathParts.length - 1) {
|
|
56
|
+
objPointer[pathPart] = value;
|
|
57
|
+
} else if (objPointer[pathPart] === undefined) {
|
|
58
|
+
objPointer[pathPart] = {};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
objPointer = objPointer[pathPart];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return obj;
|
|
65
|
+
};
|