@vonaffenfels/slate-editor 1.2.15 → 1.2.19

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.
Files changed (84) hide show
  1. package/.babelrc +43 -43
  2. package/README.md +5 -5
  3. package/componentLoader.js +93 -93
  4. package/dist/BlockEditor.js +1 -1
  5. package/dist/Renderer.js +1 -1
  6. package/dist/index.js +1 -1
  7. package/package.json +2 -2
  8. package/postcss.config.js +6 -6
  9. package/scss/demo.scss +148 -148
  10. package/scss/sidebarEditor.scss +185 -185
  11. package/scss/toolbar.scss +162 -162
  12. package/src/Blocks/EmptyBlock.js +11 -11
  13. package/src/Blocks/EmptyWrapper.js +4 -4
  14. package/src/Blocks/ErrorBoundary.js +40 -40
  15. package/src/Blocks/LayoutBlock.js +274 -274
  16. package/src/Blocks/LayoutSlot.js +90 -90
  17. package/src/CollapsableMenu/CollapsableMenu.js +48 -48
  18. package/src/Context/StorybookContext.js +6 -6
  19. package/src/ElementAutocomplete.js +134 -134
  20. package/src/Loader.js +137 -137
  21. package/src/Nodes/Default.js +162 -158
  22. package/src/Nodes/Leaf.js +54 -54
  23. package/src/Nodes/Text.js +97 -97
  24. package/src/ObjectId.js +3 -3
  25. package/src/Renderer.js +73 -73
  26. package/src/Serializer/Html.js +42 -42
  27. package/src/Serializer/Serializer.js +371 -371
  28. package/src/Serializer/Text.js +17 -17
  29. package/src/Serializer/ads.js +187 -187
  30. package/src/Serializer/index.js +3 -3
  31. package/src/SidebarEditor/AssetList.js +181 -181
  32. package/src/SidebarEditor/Fields/CloudinaryContentSelect.js +89 -89
  33. package/src/SidebarEditor/Fields/ColorPicker.js +89 -89
  34. package/src/SidebarEditor/Fields/ContentfulContentSelect.js +62 -62
  35. package/src/SidebarEditor/Fields/DateTime.js +55 -55
  36. package/src/SidebarEditor/Fields/MVP.js +66 -66
  37. package/src/SidebarEditor/Fields/MultiSelect.js +13 -13
  38. package/src/SidebarEditor/Fields/RemoteMultiSelect.js +40 -40
  39. package/src/SidebarEditor/Fields/RemoteSelect.js +39 -39
  40. package/src/SidebarEditor/Fields/Select.js +47 -47
  41. package/src/SidebarEditor/Fields/StreamSelect.js +15 -15
  42. package/src/SidebarEditor/Fields/Switch.js +34 -34
  43. package/src/SidebarEditor/Fields/Textarea.js +21 -21
  44. package/src/SidebarEditor/Resizable.js +85 -85
  45. package/src/Storybook.js +151 -151
  46. package/src/Toolbar/Align.js +64 -64
  47. package/src/Toolbar/Anchor.js +94 -94
  48. package/src/Toolbar/Block.js +135 -135
  49. package/src/Toolbar/Element.js +44 -44
  50. package/src/Toolbar/Formats.js +71 -71
  51. package/src/Toolbar/Insert.js +28 -28
  52. package/src/Toolbar/Layout.js +399 -399
  53. package/src/Toolbar/Link.js +164 -164
  54. package/src/Toolbar/Toolbar.js +235 -235
  55. package/src/Tools/Margin.js +51 -51
  56. package/src/Translation/TranslationToolbarButton.js +119 -119
  57. package/src/dev/draftToSlate.json +3147 -3147
  58. package/src/dev/index.css +2 -2
  59. package/src/dev/index.html +10 -10
  60. package/src/dev/index.js +4 -4
  61. package/src/dev/sampleValue1.json +4294 -4294
  62. package/src/dev/sampleValueValid.json +410 -410
  63. package/src/dev/testComponents/TestStory.js +74 -74
  64. package/src/dev/testComponents/TestStory.stories.js +216 -216
  65. package/src/dev/testComponents/TestStory2.js +74 -74
  66. package/src/dev/testComponents/TestStory2.stories.js +197 -197
  67. package/src/dev/testComponents/TestStory3.js +74 -74
  68. package/src/dev/testComponents/TestStory3.stories.js +197 -197
  69. package/src/dev/testSampleValue.json +746 -746
  70. package/src/fromHTML.js +4 -4
  71. package/src/helper/array.js +8 -8
  72. package/src/index.js +10 -10
  73. package/src/plugins/ListItem.js +48 -48
  74. package/src/plugins/SoftBreak.js +23 -23
  75. package/src/toHTML.js +6 -6
  76. package/src/toText.js +6 -6
  77. package/src/util/reduceContentfulResponse.js +64 -64
  78. package/src/util.js +19 -19
  79. package/storyLoader.js +47 -47
  80. package/tailwind.config.js +4 -4
  81. package/webpack.config.build.js +55 -55
  82. package/webpack.config.dev.js +60 -60
  83. package/webpack.config.js +130 -130
  84. package/webpack.config.watch.js +4 -4
@@ -1,372 +1,372 @@
1
- import React, {
2
- isValidElement,
3
- Fragment, useMemo, useEffect,
4
- } from "react";
5
- import {Default} from "../Nodes/Default";
6
- import {Leaf} from "../Nodes/Leaf";
7
- import {StorybookDisplay} from "../Nodes/StorybookDisplay";
8
- import classNames from "classnames";
9
- import {addAdsToValue} from "./ads";
10
- import ErrorBoundary from "../Blocks/ErrorBoundary";
11
-
12
- function isEmptyNode(node) {
13
- if (!node.type) {
14
- if (!String(node.text).trim()) {
15
- return true;
16
- }
17
- }
18
-
19
- return false;
20
- }
21
-
22
- function getTextContent(node, text = "") {
23
- if (!node) {
24
- return text;
25
- }
26
-
27
- if (!node.children || !node.children.length) {
28
- if (!node.text) {
29
- return text;
30
- } else {
31
- text += node.text;
32
- }
33
- } else {
34
- return node.children.map(v => getTextContent(v, text)).join("").trim();
35
- }
36
-
37
- return text;
38
- }
39
-
40
- function isValidNodeForPlacement(node) {
41
- return true;
42
- // this is disabled, elements should just clear, otherwise too many ads are missing because of short intro texts and such ...
43
- /*
44
- if (node && node.type === "paragraph") {
45
- const text = getTextContent(node);
46
-
47
- if (text.length < 200) {
48
- return false;
49
- }
50
- }
51
-
52
- return true;
53
- */
54
- }
55
-
56
- export function Serializer({
57
- value = [],
58
- elementPropsMap,
59
- specialClassMap,
60
- transformAttributes,
61
- storybookComponentLoader,
62
- storybookComponentDataLoader,
63
- defaultComponentReplacement,
64
- modifyElementFunc,
65
- filterContent = null,
66
- isRenderer = false,
67
- fixedPositions = {},
68
- fixedPositionTypes = {},
69
- adDefinitionDesktop = [],
70
- adDefinitionMobile = [],
71
- }) {
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]);
77
-
78
- const getPropsForType = (type, isInSlot = false) => {
79
- if (!elementPropsMap) {
80
- return {};
81
- }
82
-
83
- if (isInSlot) {
84
- if (elementPropsMap[type + "-in-slot"]) {
85
- return elementPropsMap[type + "-in-slot"];
86
- }
87
- }
88
-
89
- return elementPropsMap[type] || {};
90
- };
91
-
92
- const renderElement = (props, isInSlot = false) => {
93
- const typeProps = getPropsForType(props.type, isInSlot);
94
- const Wrapper = typeProps.wrapper || function ({children}) {
95
- return <ErrorBoundary>{children}</ErrorBoundary>;
96
- };
97
-
98
- switch (props.type) {
99
- case 'storybook': {
100
- const storyProps = {
101
- element: {
102
- ...props,
103
- attributes: {
104
- ...(props.attributes || {}),
105
- isInSlot: isInSlot,
106
- },
107
- },
108
- attributes: props.attributes,
109
- storybookComponentLoader: storybookComponentLoader,
110
- storybookComponentDataLoader: storybookComponentDataLoader,
111
- };
112
-
113
- return <ErrorBoundary><Wrapper
114
- type={props.type}
115
- block={props.block}><StorybookDisplay {...storyProps} /></Wrapper></ErrorBoundary>;
116
- }
117
- case 'layout': {
118
- let isGrid = true;
119
-
120
- if (Array.isArray(props.children)) {
121
- props.children.forEach(child => {
122
- if (child.type === "layout-slot" && ["grid-auto", "grid-fill"].includes(child.attributes.name)) {
123
- isGrid = false;
124
- }
125
- });
126
- }
127
-
128
- return <ErrorBoundary>
129
- <Wrapper type={props.type}>
130
- <div
131
- data-cols={props.children.length}
132
- className={classNames("block-editor-layout", {
133
- "block-editor-layout-grid": isGrid,
134
- "block-editor-layout-flex": !isGrid,
135
- "block-editor-table-border-wrapper": props?.attributes?.tableBorder,
136
- "md:grid-cols-1": props.children.length === 1,
137
- "md:grid-cols-2": props.children.length === 2,
138
- "md:grid-cols-3": props.children.length === 3,
139
- "md:grid-cols-4": props.children.length === 4,
140
- "md:grid-cols-5": props.children.length === 5,
141
- "grid-cols-1": props?.attributes?.mobileColumnSpan === 1,
142
- "grid-cols-2": props?.attributes?.mobileColumnSpan === 2,
143
- "md:space-x-4": props.attributes?.spacing,
144
- "mt-16": props?.attributes?.margin?.top,
145
- "mr-16": props?.attributes?.margin?.right,
146
- "mb-16": props?.attributes?.margin?.bottom,
147
- "ml-16": props?.attributes?.margin?.left,
148
- "justify-center": props?.attributes?.justifyCenter,
149
- [typeProps.classNameSite + " site-width"]: !isInSlot && (props.attributes?.width === "site" || props.attributes?.width === "full"),
150
- [typeProps.classNameArticle + " article-width"]: !isInSlot && (props.attributes?.width === "article" || !props.attributes?.width),
151
- })}
152
- >
153
- {props.children.map((v, i) => <Fragment
154
- key={"layout-pos-" + i}>{serializeNode(v, i, isInSlot)}</Fragment>)}
155
- </div>
156
- </Wrapper>
157
- </ErrorBoundary>;
158
- }
159
- case 'layout-slot':
160
- return <ErrorBoundary>
161
- <Wrapper type={props.type}>
162
- <div
163
- className={classNames({
164
- ["block-editor-layout-" + props.attributes.name]: true,
165
- "mt-4": props.attributes?.margin?.top,
166
- "md:mr-4": props.attributes?.margin?.right,
167
- "mb-4": props.attributes?.margin?.bottom,
168
- "md:ml-4": props.attributes?.margin?.left,
169
- })}
170
- >
171
- <div
172
- style={{top: props.attributes?.sticky && "80px"}}
173
- className={classNames({"sticky": props.attributes?.sticky})}>
174
- {props.children.map((v, i) => <div
175
- key={"layout-slot-" + i}
176
- >{serializeNode(v, i, props.attributes.name)}</div>)}
177
- </div>
178
- </div>
179
- </Wrapper>
180
- </ErrorBoundary>;
181
- default: {
182
- const defaultProps = {
183
- specialClassMap: specialClassMap,
184
- elementPropsMap: elementPropsMap,
185
- element: {
186
- attributes: props.attributes || {},
187
- align: props.align,
188
- type: props.type,
189
- },
190
- attributes: props.htmlAttributes || {},
191
- children: props.children.map((v, i) => <Fragment
192
- key={props.type + "-pos-item-" + i}>{serializeNode(v, i, isInSlot)}</Fragment>),
193
- };
194
-
195
- return <ErrorBoundary>
196
- <Default
197
- {...defaultProps}
198
- isInSlot={isInSlot}
199
- isRenderer={isRenderer}
200
- transformAttributes={transformAttributes}
201
- defaultComponentReplacement={defaultComponentReplacement}
202
- />
203
- </ErrorBoundary>;
204
- }
205
- }
206
- };
207
-
208
-
209
- function serializeNode(node, i, isInSlot = false) {
210
- if (isValidElement(node)) {
211
- return node;
212
- }
213
-
214
- if (typeof modifyElementFunc === "function") {
215
- node = modifyElementFunc(node);
216
- }
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
-
239
- if (!node.children || !node.children.length) {
240
- return serializeLeaf(node);
241
- }
242
-
243
- // unwrap elements that are inside of a paragraph (that has no text content) so they have been inserted "inline" by mistake
244
- // this helps preventing a lot of hydration errors!
245
- if (node?.type === "paragraph") {
246
- const textContent = node.children.find(v => !v?.type && v?.text);
247
- if (!textContent) {
248
- const storybookNodes = node.children.filter(v => v?.type === "storybook");
249
- if (storybookNodes.length === 1) {
250
- // only unwrap if we only have exactly 1 node
251
- return renderElement(storybookNodes.at(0), isInSlot);
252
- }
253
- }
254
- }
255
-
256
- return renderElement(node, isInSlot);
257
- }
258
-
259
- function serializeLeaf(props) {
260
- return <Leaf leaf={props} isRenderer={true} typeProps={getPropsForType("leaf")}>{props.text || ""}</Leaf>;
261
- }
262
-
263
- if (!value) {
264
- return null;
265
- }
266
-
267
- return <>
268
- {!!processedValue && processedValue.map((v, i) => {
269
- return <Fragment key={v.block + "-pos-" + i}>{serializeNode(v, i)}</Fragment>;
270
- })}
271
- </>;
272
- }
273
-
274
- function getFixedPosition(fixedPositions, i) {
275
- return fixedPositions?.[i] || null;
276
- }
277
-
278
- function isShortParagraph(node) {
279
- if (node?.type === "paragraph") {
280
- let textLength = node.children.map(v => v?.text?.length || 0).reduce((pv, cv) => pv + cv, 0) || 0;
281
- return textLength <= 60;
282
- }
283
-
284
- return false;
285
- }
286
-
287
- function getFixedPositionPlacement(node, prevNode, fixedPosType) {
288
- // inline has to be before
289
- if (fixedPosType === "inline") {
290
- return "before";
291
- }
292
-
293
- let placement = "before";
294
-
295
- if (node?.type === "paragraph" && prevNode?.type === "heading" || isShortParagraph(prevNode)) {
296
- placement = "after";
297
- }
298
-
299
- return placement;
300
- }
301
-
302
- function isNodeValidForCounter(node, counters = {}) {
303
- let isValid = true;
304
-
305
- if (node.type === "paragraph") {
306
- let lengthCounterId = `paragraph_textlength`;
307
-
308
- if (!counters[lengthCounterId]) {
309
- counters[lengthCounterId] = 0;
310
- }
311
-
312
- let textLength = node.children.map(v => v?.text?.length || 0).reduce((pv, cv) => pv + cv, 0) || 0;
313
- let isHeadline = textLength <= 60;
314
-
315
- counters[lengthCounterId] += textLength;
316
-
317
- isValid = !isHeadline && counters[lengthCounterId] >= 200;
318
-
319
- if (isValid) {
320
- counters[lengthCounterId] = 0;
321
- }
322
- }
323
-
324
- return isValid;
325
- }
326
-
327
- function addFixedPositionsToValue(
328
- value, fixedPositions, fixedPositionTypes, counters = {},
329
- ) {
330
- if (!Array.isArray(value)) {
331
- return value;
332
- }
333
-
334
- let processedValue = [];
335
-
336
- for (let i = 0; i < value.length; i++) {
337
- let node = value[i];
338
- let prevNode = value?.[i - 1];
339
-
340
- if (!node.type) {
341
- processedValue.push(node);
342
- continue;
343
- }
344
- if (!counters[node.type]) {
345
- counters[node.type] = 0;
346
- }
347
-
348
- let counterId = `${node.type}_${counters[node.type]}`;
349
-
350
- // only count this node if its valid to be counted (dont count strong headlines and so on)
351
- if (isNodeValidForCounter(node, counters)) {
352
- counters[node.type]++;
353
- let fixedPosType = fixedPositionTypes?.[counterId];
354
- let fixedPos = getFixedPosition(fixedPositions, counterId);
355
- let placement = getFixedPositionPlacement(node, prevNode, fixedPosType);
356
-
357
- if (fixedPos && placement === "before") {
358
- processedValue.push(fixedPos);
359
- }
360
-
361
- processedValue.push(node);
362
-
363
- if (fixedPos && placement === "after") {
364
- processedValue.push(fixedPos);
365
- }
366
- } else {
367
- processedValue.push(node);
368
- }
369
- }
370
-
371
- return processedValue;
1
+ import React, {
2
+ isValidElement,
3
+ Fragment, useMemo, useEffect,
4
+ } from "react";
5
+ import {Default} from "../Nodes/Default";
6
+ import {Leaf} from "../Nodes/Leaf";
7
+ import {StorybookDisplay} from "../Nodes/StorybookDisplay";
8
+ import classNames from "classnames";
9
+ import {addAdsToValue} from "./ads";
10
+ import ErrorBoundary from "../Blocks/ErrorBoundary";
11
+
12
+ function isEmptyNode(node) {
13
+ if (!node.type) {
14
+ if (!String(node.text).trim()) {
15
+ return true;
16
+ }
17
+ }
18
+
19
+ return false;
20
+ }
21
+
22
+ function getTextContent(node, text = "") {
23
+ if (!node) {
24
+ return text;
25
+ }
26
+
27
+ if (!node.children || !node.children.length) {
28
+ if (!node.text) {
29
+ return text;
30
+ } else {
31
+ text += node.text;
32
+ }
33
+ } else {
34
+ return node.children.map(v => getTextContent(v, text)).join("").trim();
35
+ }
36
+
37
+ return text;
38
+ }
39
+
40
+ function isValidNodeForPlacement(node) {
41
+ return true;
42
+ // this is disabled, elements should just clear, otherwise too many ads are missing because of short intro texts and such ...
43
+ /*
44
+ if (node && node.type === "paragraph") {
45
+ const text = getTextContent(node);
46
+
47
+ if (text.length < 200) {
48
+ return false;
49
+ }
50
+ }
51
+
52
+ return true;
53
+ */
54
+ }
55
+
56
+ export function Serializer({
57
+ value = [],
58
+ elementPropsMap,
59
+ specialClassMap,
60
+ transformAttributes,
61
+ storybookComponentLoader,
62
+ storybookComponentDataLoader,
63
+ defaultComponentReplacement,
64
+ modifyElementFunc,
65
+ filterContent = null,
66
+ isRenderer = false,
67
+ fixedPositions = {},
68
+ fixedPositionTypes = {},
69
+ adDefinitionDesktop = [],
70
+ adDefinitionMobile = [],
71
+ }) {
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]);
77
+
78
+ const getPropsForType = (type, isInSlot = false) => {
79
+ if (!elementPropsMap) {
80
+ return {};
81
+ }
82
+
83
+ if (isInSlot) {
84
+ if (elementPropsMap[type + "-in-slot"]) {
85
+ return elementPropsMap[type + "-in-slot"];
86
+ }
87
+ }
88
+
89
+ return elementPropsMap[type] || {};
90
+ };
91
+
92
+ const renderElement = (props, isInSlot = false) => {
93
+ const typeProps = getPropsForType(props.type, isInSlot);
94
+ const Wrapper = typeProps.wrapper || function ({children}) {
95
+ return <ErrorBoundary>{children}</ErrorBoundary>;
96
+ };
97
+
98
+ switch (props.type) {
99
+ case 'storybook': {
100
+ const storyProps = {
101
+ element: {
102
+ ...props,
103
+ attributes: {
104
+ ...(props.attributes || {}),
105
+ isInSlot: isInSlot,
106
+ },
107
+ },
108
+ attributes: props.attributes,
109
+ storybookComponentLoader: storybookComponentLoader,
110
+ storybookComponentDataLoader: storybookComponentDataLoader,
111
+ };
112
+
113
+ return <ErrorBoundary><Wrapper
114
+ type={props.type}
115
+ block={props.block}><StorybookDisplay {...storyProps} /></Wrapper></ErrorBoundary>;
116
+ }
117
+ case 'layout': {
118
+ let isGrid = true;
119
+
120
+ if (Array.isArray(props.children)) {
121
+ props.children.forEach(child => {
122
+ if (child.type === "layout-slot" && ["grid-auto", "grid-fill"].includes(child.attributes.name)) {
123
+ isGrid = false;
124
+ }
125
+ });
126
+ }
127
+
128
+ return <ErrorBoundary>
129
+ <Wrapper type={props.type}>
130
+ <div
131
+ data-cols={props.children.length}
132
+ className={classNames("block-editor-layout", {
133
+ "block-editor-layout-grid": isGrid,
134
+ "block-editor-layout-flex": !isGrid,
135
+ "block-editor-table-border-wrapper": props?.attributes?.tableBorder,
136
+ "md:grid-cols-1": props.children.length === 1,
137
+ "md:grid-cols-2": props.children.length === 2,
138
+ "md:grid-cols-3": props.children.length === 3,
139
+ "md:grid-cols-4": props.children.length === 4,
140
+ "md:grid-cols-5": props.children.length === 5,
141
+ "grid-cols-1": props?.attributes?.mobileColumnSpan === 1,
142
+ "grid-cols-2": props?.attributes?.mobileColumnSpan === 2,
143
+ "md:space-x-4": props.attributes?.spacing,
144
+ "mt-16": props?.attributes?.margin?.top,
145
+ "mr-16": props?.attributes?.margin?.right,
146
+ "mb-16": props?.attributes?.margin?.bottom,
147
+ "ml-16": props?.attributes?.margin?.left,
148
+ "justify-center": props?.attributes?.justifyCenter,
149
+ [typeProps.classNameSite + " site-width"]: !isInSlot && (props.attributes?.width === "site" || props.attributes?.width === "full"),
150
+ [typeProps.classNameArticle + " article-width"]: !isInSlot && (props.attributes?.width === "article" || !props.attributes?.width),
151
+ })}
152
+ >
153
+ {props.children.map((v, i) => <Fragment
154
+ key={"layout-pos-" + i}>{serializeNode(v, i, isInSlot)}</Fragment>)}
155
+ </div>
156
+ </Wrapper>
157
+ </ErrorBoundary>;
158
+ }
159
+ case 'layout-slot':
160
+ return <ErrorBoundary>
161
+ <Wrapper type={props.type}>
162
+ <div
163
+ className={classNames({
164
+ ["block-editor-layout-" + props.attributes.name]: true,
165
+ "mt-4": props.attributes?.margin?.top,
166
+ "md:mr-4": props.attributes?.margin?.right,
167
+ "mb-4": props.attributes?.margin?.bottom,
168
+ "md:ml-4": props.attributes?.margin?.left,
169
+ })}
170
+ >
171
+ <div
172
+ style={{top: props.attributes?.sticky && "80px"}}
173
+ className={classNames({"sticky": props.attributes?.sticky})}>
174
+ {props.children.map((v, i) => <div
175
+ key={"layout-slot-" + i}
176
+ >{serializeNode(v, i, props.attributes.name)}</div>)}
177
+ </div>
178
+ </div>
179
+ </Wrapper>
180
+ </ErrorBoundary>;
181
+ default: {
182
+ const defaultProps = {
183
+ specialClassMap: specialClassMap,
184
+ elementPropsMap: elementPropsMap,
185
+ element: {
186
+ attributes: props.attributes || {},
187
+ align: props.align,
188
+ type: props.type,
189
+ },
190
+ attributes: props.htmlAttributes || {},
191
+ children: props.children.map((v, i) => <Fragment
192
+ key={props.type + "-pos-item-" + i}>{serializeNode(v, i, isInSlot)}</Fragment>),
193
+ };
194
+
195
+ return <ErrorBoundary>
196
+ <Default
197
+ {...defaultProps}
198
+ isInSlot={isInSlot}
199
+ isRenderer={isRenderer}
200
+ transformAttributes={transformAttributes}
201
+ defaultComponentReplacement={defaultComponentReplacement}
202
+ />
203
+ </ErrorBoundary>;
204
+ }
205
+ }
206
+ };
207
+
208
+
209
+ function serializeNode(node, i, isInSlot = false) {
210
+ if (isValidElement(node)) {
211
+ return node;
212
+ }
213
+
214
+ if (typeof modifyElementFunc === "function") {
215
+ node = modifyElementFunc(node);
216
+ }
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
+
239
+ if (!node.children || !node.children.length) {
240
+ return serializeLeaf(node);
241
+ }
242
+
243
+ // unwrap elements that are inside of a paragraph (that has no text content) so they have been inserted "inline" by mistake
244
+ // this helps preventing a lot of hydration errors!
245
+ if (node?.type === "paragraph") {
246
+ const textContent = node.children.find(v => !v?.type && v?.text);
247
+ if (!textContent) {
248
+ const storybookNodes = node.children.filter(v => v?.type === "storybook");
249
+ if (storybookNodes.length === 1) {
250
+ // only unwrap if we only have exactly 1 node
251
+ return renderElement(storybookNodes.at(0), isInSlot);
252
+ }
253
+ }
254
+ }
255
+
256
+ return renderElement(node, isInSlot);
257
+ }
258
+
259
+ function serializeLeaf(props) {
260
+ return <Leaf leaf={props} isRenderer={true} typeProps={getPropsForType("leaf")}>{props.text || ""}</Leaf>;
261
+ }
262
+
263
+ if (!value) {
264
+ return null;
265
+ }
266
+
267
+ return <>
268
+ {!!processedValue && processedValue.map((v, i) => {
269
+ return <Fragment key={v.block + "-pos-" + i}>{serializeNode(v, i)}</Fragment>;
270
+ })}
271
+ </>;
272
+ }
273
+
274
+ function getFixedPosition(fixedPositions, i) {
275
+ return fixedPositions?.[i] || null;
276
+ }
277
+
278
+ function isShortParagraph(node) {
279
+ if (node?.type === "paragraph") {
280
+ let textLength = node.children.map(v => v?.text?.length || 0).reduce((pv, cv) => pv + cv, 0) || 0;
281
+ return textLength <= 60;
282
+ }
283
+
284
+ return false;
285
+ }
286
+
287
+ function getFixedPositionPlacement(node, prevNode, fixedPosType) {
288
+ // inline has to be before
289
+ if (fixedPosType === "inline") {
290
+ return "before";
291
+ }
292
+
293
+ let placement = "before";
294
+
295
+ if (node?.type === "paragraph" && prevNode?.type === "heading" || isShortParagraph(prevNode)) {
296
+ placement = "after";
297
+ }
298
+
299
+ return placement;
300
+ }
301
+
302
+ function isNodeValidForCounter(node, counters = {}) {
303
+ let isValid = true;
304
+
305
+ if (node.type === "paragraph") {
306
+ let lengthCounterId = `paragraph_textlength`;
307
+
308
+ if (!counters[lengthCounterId]) {
309
+ counters[lengthCounterId] = 0;
310
+ }
311
+
312
+ let textLength = node.children.map(v => v?.text?.length || 0).reduce((pv, cv) => pv + cv, 0) || 0;
313
+ let isHeadline = textLength <= 60;
314
+
315
+ counters[lengthCounterId] += textLength;
316
+
317
+ isValid = !isHeadline && counters[lengthCounterId] >= 200;
318
+
319
+ if (isValid) {
320
+ counters[lengthCounterId] = 0;
321
+ }
322
+ }
323
+
324
+ return isValid;
325
+ }
326
+
327
+ function addFixedPositionsToValue(
328
+ value, fixedPositions, fixedPositionTypes, counters = {},
329
+ ) {
330
+ if (!Array.isArray(value)) {
331
+ return value;
332
+ }
333
+
334
+ let processedValue = [];
335
+
336
+ for (let i = 0; i < value.length; i++) {
337
+ let node = value[i];
338
+ let prevNode = value?.[i - 1];
339
+
340
+ if (!node.type) {
341
+ processedValue.push(node);
342
+ continue;
343
+ }
344
+ if (!counters[node.type]) {
345
+ counters[node.type] = 0;
346
+ }
347
+
348
+ let counterId = `${node.type}_${counters[node.type]}`;
349
+
350
+ // only count this node if its valid to be counted (dont count strong headlines and so on)
351
+ if (isNodeValidForCounter(node, counters)) {
352
+ counters[node.type]++;
353
+ let fixedPosType = fixedPositionTypes?.[counterId];
354
+ let fixedPos = getFixedPosition(fixedPositions, counterId);
355
+ let placement = getFixedPositionPlacement(node, prevNode, fixedPosType);
356
+
357
+ if (fixedPos && placement === "before") {
358
+ processedValue.push(fixedPos);
359
+ }
360
+
361
+ processedValue.push(node);
362
+
363
+ if (fixedPos && placement === "after") {
364
+ processedValue.push(fixedPos);
365
+ }
366
+ } else {
367
+ processedValue.push(node);
368
+ }
369
+ }
370
+
371
+ return processedValue;
372
372
  }