@vonaffenfels/slate-editor 1.1.64 → 1.1.66
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/Renderer.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +2 -2
- package/src/Renderer.js +34 -3
- package/src/Serializer/Serializer.js +34 -48
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/slate-editor",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.66",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
"cssnano": "^5.0.1",
|
|
73
73
|
"escape-html": "^1.0.3"
|
|
74
74
|
},
|
|
75
|
-
"gitHead": "
|
|
75
|
+
"gitHead": "5941c51cc7d9f86dda5c8e76e3608098294a8740",
|
|
76
76
|
"publishConfig": {
|
|
77
77
|
"access": "public"
|
|
78
78
|
}
|
package/src/Renderer.js
CHANGED
|
@@ -2,7 +2,7 @@ import React, {memo} from 'react';
|
|
|
2
2
|
import {StorybookContext} from "./Context/StorybookContext";
|
|
3
3
|
import {Serializer} from "./Serializer";
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const Renderer = memo(function RendererInner({
|
|
6
6
|
value,
|
|
7
7
|
modifyElementFunc,
|
|
8
8
|
specialClassMap,
|
|
@@ -33,8 +33,39 @@ function Renderer({
|
|
|
33
33
|
adDefinitionDesktop={adDefinitionDesktop}
|
|
34
34
|
adDefinitionMobile={adDefinitionMobile}
|
|
35
35
|
isRenderer={true}
|
|
36
|
-
onStorybookElementClick={onStorybookElementClick}
|
|
37
|
-
}
|
|
36
|
+
onStorybookElementClick={onStorybookElementClick}/>
|
|
37
|
+
}, (prevProps, nextProps) => {
|
|
38
|
+
let allKeys = Array.from(new Set([...Object.keys(nextProps), ...Object.keys(prevProps)]));
|
|
39
|
+
|
|
40
|
+
for (let i = 0; i < allKeys.length; i++) {
|
|
41
|
+
const key = allKeys[i];
|
|
42
|
+
const oldValue = prevProps[key];
|
|
43
|
+
const newValue = nextProps[key];
|
|
44
|
+
|
|
45
|
+
if (oldValue === newValue) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
if (!oldValue && !newValue) {
|
|
50
|
+
console.warn(`Renderer :: ${key} :: Both empty but type changed?`, {oldValue, newValue});
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (typeof oldValue === "object" && typeof newValue === "object" && oldValue && newValue) {
|
|
55
|
+
try {
|
|
56
|
+
if (JSON.stringify(oldValue) === JSON.stringify(newValue)) {
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
} catch (e) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return true;
|
|
68
|
+
})
|
|
38
69
|
|
|
39
70
|
const RendererMemo = memo(Renderer);
|
|
40
71
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
isValidElement,
|
|
3
|
-
Fragment, useMemo,
|
|
3
|
+
Fragment, useMemo, useEffect,
|
|
4
4
|
} from "react";
|
|
5
5
|
import {Default} from "../Nodes/Default";
|
|
6
6
|
import {Leaf} from "../Nodes/Leaf";
|
|
@@ -69,39 +69,11 @@ export function Serializer({
|
|
|
69
69
|
adDefinitionDesktop = [],
|
|
70
70
|
adDefinitionMobile = [],
|
|
71
71
|
}) {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return value.filter((node) => {
|
|
78
|
-
if (!node) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
if (node.type === "paragraph") {
|
|
83
|
-
if (!node.children || node.children.length === 0) {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
let children = node.children.filter((v) => !isEmptyNode(v));
|
|
88
|
-
|
|
89
|
-
if (children.length === 0) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
if (!filterContent) {
|
|
95
|
-
return true;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
return filterContent(node, filterCtx);
|
|
99
|
-
});
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return [];
|
|
103
|
-
}, [value, filterContent])
|
|
104
|
-
|
|
72
|
+
const processedValue = useMemo(() => {
|
|
73
|
+
let val = addAdsToValue(value, adDefinitionDesktop, adDefinitionMobile);
|
|
74
|
+
val = addFixedPositionsToValue(val, fixedPositions, fixedPositionTypes);
|
|
75
|
+
return val;
|
|
76
|
+
}, [value, adDefinitionDesktop, adDefinitionMobile, fixedPositions, fixedPositionTypes]);
|
|
105
77
|
|
|
106
78
|
const getPropsForType = (type, isInSlot = false) => {
|
|
107
79
|
if (!elementPropsMap) {
|
|
@@ -243,6 +215,27 @@ export function Serializer({
|
|
|
243
215
|
node = modifyElementFunc(node);
|
|
244
216
|
}
|
|
245
217
|
|
|
218
|
+
if (node.type === "paragraph" && !node.text) {
|
|
219
|
+
if (!node.children || node.children.length === 0) {
|
|
220
|
+
return null;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
let children = node.children.filter((v) => !isEmptyNode(v));
|
|
224
|
+
|
|
225
|
+
if (children.length === 0) {
|
|
226
|
+
return null;
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
try {
|
|
231
|
+
let filterCtx = {content: value};
|
|
232
|
+
if (filterContent && !filterContent(node, filterCtx)) {
|
|
233
|
+
return null;
|
|
234
|
+
}
|
|
235
|
+
} catch (e) {
|
|
236
|
+
console.error(e);
|
|
237
|
+
}
|
|
238
|
+
|
|
246
239
|
if (!node.children || !node.children.length) {
|
|
247
240
|
return serializeLeaf(node);
|
|
248
241
|
}
|
|
@@ -267,22 +260,15 @@ export function Serializer({
|
|
|
267
260
|
return <Leaf leaf={props} isRenderer={true} typeProps={getPropsForType("leaf")}>{props.text || ""}</Leaf>;
|
|
268
261
|
}
|
|
269
262
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
return null;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
let processedValue = addAdsToValue(value, adDefinitionDesktop, adDefinitionMobile);
|
|
276
|
-
processedValue = addFixedPositionsToValue(processedValue, fixedPositions, fixedPositionTypes);
|
|
277
|
-
|
|
278
|
-
return <>
|
|
279
|
-
{!!processedValue && processedValue.map((v, i) => {
|
|
280
|
-
return <Fragment key={v.block + "-pos-" + i}>{serializeNode(v, i)}</Fragment>;
|
|
281
|
-
})}
|
|
282
|
-
</>;
|
|
263
|
+
if (!value) {
|
|
264
|
+
return null;
|
|
283
265
|
}
|
|
284
266
|
|
|
285
|
-
return
|
|
267
|
+
return <>
|
|
268
|
+
{!!processedValue && processedValue.map((v, i) => {
|
|
269
|
+
return <Fragment key={v.block + "-pos-" + i}>{serializeNode(v, i)}</Fragment>;
|
|
270
|
+
})}
|
|
271
|
+
</>;
|
|
286
272
|
}
|
|
287
273
|
|
|
288
274
|
function getFixedPosition(fixedPositions, i) {
|