@vonaffenfels/slate-editor 1.1.64 → 1.1.65
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 -47
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vonaffenfels/slate-editor",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.65",
|
|
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": "f14cc08783e4c357ee4c0887fa2965b3d020eda4",
|
|
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";
|
|
@@ -70,38 +70,11 @@ export function Serializer({
|
|
|
70
70
|
adDefinitionMobile = [],
|
|
71
71
|
}) {
|
|
72
72
|
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
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
|
-
|
|
73
|
+
const processedValue = useMemo(() => {
|
|
74
|
+
let val = addAdsToValue(value, adDefinitionDesktop, adDefinitionMobile);
|
|
75
|
+
val = addFixedPositionsToValue(val, fixedPositions, fixedPositionTypes);
|
|
76
|
+
return val;
|
|
77
|
+
}, [value, adDefinitionDesktop, adDefinitionMobile, fixedPositions, fixedPositionTypes]);
|
|
105
78
|
|
|
106
79
|
const getPropsForType = (type, isInSlot = false) => {
|
|
107
80
|
if (!elementPropsMap) {
|
|
@@ -243,6 +216,27 @@ export function Serializer({
|
|
|
243
216
|
node = modifyElementFunc(node);
|
|
244
217
|
}
|
|
245
218
|
|
|
219
|
+
if (node.type === "paragraph") {
|
|
220
|
+
if (!node.children || node.children.length === 0) {
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
let children = node.children.filter((v) => !isEmptyNode(v));
|
|
225
|
+
|
|
226
|
+
if (children.length === 0) {
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
try {
|
|
232
|
+
let filterCtx = {content: value};
|
|
233
|
+
if (filterContent && !filterContent(node, filterCtx)) {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
} catch (e) {
|
|
237
|
+
console.error(e)
|
|
238
|
+
}
|
|
239
|
+
|
|
246
240
|
if (!node.children || !node.children.length) {
|
|
247
241
|
return serializeLeaf(node);
|
|
248
242
|
}
|
|
@@ -267,22 +261,15 @@ export function Serializer({
|
|
|
267
261
|
return <Leaf leaf={props} isRenderer={true} typeProps={getPropsForType("leaf")}>{props.text || ""}</Leaf>;
|
|
268
262
|
}
|
|
269
263
|
|
|
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
|
-
</>;
|
|
264
|
+
if (!value) {
|
|
265
|
+
return null;
|
|
283
266
|
}
|
|
284
267
|
|
|
285
|
-
return
|
|
268
|
+
return <>
|
|
269
|
+
{!!processedValue && processedValue.map((v, i) => {
|
|
270
|
+
return <Fragment key={v.block + "-pos-" + i}>{serializeNode(v, i)}</Fragment>;
|
|
271
|
+
})}
|
|
272
|
+
</>;
|
|
286
273
|
}
|
|
287
274
|
|
|
288
275
|
function getFixedPosition(fixedPositions, i) {
|