@vonaffenfels/slate-editor 1.1.56 → 1.1.64

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.1.56",
3
+ "version": "1.1.64",
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": "6ec493b17d46bc029eefae0a83f08b1735f284e7",
75
+ "gitHead": "b36d33c384a5e3a5a40770030f147df9b599c5a1",
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  }
@@ -97,12 +97,6 @@ export default function BlockEditor({
97
97
  loadStories();
98
98
  }, []);
99
99
 
100
- const resetEditor = () => {
101
- if (confirm("This action will delete all data in the editor, are you sure?")) {
102
- onChange(emptyValue);
103
- }
104
- };
105
-
106
100
  const fixValue = (newValue) => {
107
101
  const fixedValue = [...(newValue || [])];
108
102
 
package/src/Renderer.js CHANGED
@@ -10,6 +10,7 @@ function Renderer({
10
10
  transformAttributes,
11
11
  storybookComponentLoader,
12
12
  storybookComponentDataLoader,
13
+ filterContent,
13
14
  fixedPositions,
14
15
  fixedPositionTypes,
15
16
  adDefinitionDesktop,
@@ -23,6 +24,7 @@ function Renderer({
23
24
  defaultComponentReplacement={defaultComponentReplacement}
24
25
  transformAttributes={transformAttributes}
25
26
  value={value}
27
+ filterContent={filterContent}
26
28
  modifyElementFunc={modifyElementFunc}
27
29
  storybookComponentLoader={storybookComponentLoader}
28
30
  storybookComponentDataLoader={storybookComponentDataLoader}
@@ -1,6 +1,6 @@
1
1
  import React, {
2
2
  isValidElement,
3
- Fragment,
3
+ Fragment, useMemo,
4
4
  } from "react";
5
5
  import {Default} from "../Nodes/Default";
6
6
  import {Leaf} from "../Nodes/Leaf";
@@ -62,33 +62,46 @@ export function Serializer({
62
62
  storybookComponentDataLoader,
63
63
  defaultComponentReplacement,
64
64
  modifyElementFunc,
65
+ filterContent = null,
65
66
  isRenderer = false,
66
67
  fixedPositions = {},
67
68
  fixedPositionTypes = {},
68
69
  adDefinitionDesktop = [],
69
70
  adDefinitionMobile = [],
70
71
  }) {
71
- if (value) {
72
- value = value.filter((node) => {
73
- if (!node) {
74
- return false;
75
- }
76
72
 
77
- if (node.type === "paragraph") {
78
- if (!node.children || node.children.length === 0) {
73
+ // memo the value only update if deps change
74
+ const filteredValue = useMemo(() => {
75
+ if (value) {
76
+ let filterCtx = {content: value};
77
+ return value.filter((node) => {
78
+ if (!node) {
79
79
  return false;
80
80
  }
81
81
 
82
- let children = node.children.filter((v) => !isEmptyNode(v));
82
+ if (node.type === "paragraph") {
83
+ if (!node.children || node.children.length === 0) {
84
+ return false;
85
+ }
83
86
 
84
- if (children.length === 0) {
85
- return false;
87
+ let children = node.children.filter((v) => !isEmptyNode(v));
88
+
89
+ if (children.length === 0) {
90
+ return false;
91
+ }
86
92
  }
87
- }
88
93
 
89
- return true;
90
- });
91
- }
94
+ if (!filterContent) {
95
+ return true;
96
+ }
97
+
98
+ return filterContent(node, filterCtx);
99
+ });
100
+ }
101
+
102
+ return [];
103
+ }, [value, filterContent])
104
+
92
105
 
93
106
  const getPropsForType = (type, isInSlot = false) => {
94
107
  if (!elementPropsMap) {
@@ -255,6 +268,10 @@ export function Serializer({
255
268
  }
256
269
 
257
270
  function renderValue(value) {
271
+ if (!value) {
272
+ return null;
273
+ }
274
+
258
275
  let processedValue = addAdsToValue(value, adDefinitionDesktop, adDefinitionMobile);
259
276
  processedValue = addFixedPositionsToValue(processedValue, fixedPositions, fixedPositionTypes);
260
277
 
@@ -265,7 +282,7 @@ export function Serializer({
265
282
  </>;
266
283
  }
267
284
 
268
- return renderValue(value);
285
+ return renderValue(filteredValue);
269
286
  }
270
287
 
271
288
  function getFixedPosition(fixedPositions, i) {