lkb-fields-document 1.0.0

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 (112) hide show
  1. package/component-blocks/dist/lkb-fields-document-component-blocks.cjs.d.ts +2 -0
  2. package/component-blocks/dist/lkb-fields-document-component-blocks.cjs.js +306 -0
  3. package/component-blocks/dist/lkb-fields-document-component-blocks.esm.js +300 -0
  4. package/component-blocks/dist/lkb-fields-document-component-blocks.node.cjs.js +306 -0
  5. package/component-blocks/dist/lkb-fields-document-component-blocks.node.esm.js +300 -0
  6. package/component-blocks/package.json +4 -0
  7. package/dist/Cell-0ac0ac66.node.cjs.js +21 -0
  8. package/dist/Cell-242f7404.esm.js +17 -0
  9. package/dist/Cell-3103f73d.node.esm.js +17 -0
  10. package/dist/Cell-bfb56d74.cjs.js +21 -0
  11. package/dist/Field-0e0f75ed.node.cjs.js +1628 -0
  12. package/dist/Field-28177061.cjs.js +1628 -0
  13. package/dist/Field-35b79e6b.node.esm.js +1619 -0
  14. package/dist/Field-92d13205.esm.js +1619 -0
  15. package/dist/api-2f524611.esm.js +502 -0
  16. package/dist/api-73636987.cjs.js +506 -0
  17. package/dist/api-8e2b20b8.node.cjs.js +506 -0
  18. package/dist/api-c32e360e.node.esm.js +502 -0
  19. package/dist/callout-ui-2aded278.cjs.js +131 -0
  20. package/dist/callout-ui-3e5ca544.node.esm.js +126 -0
  21. package/dist/callout-ui-8b5f2376.esm.js +126 -0
  22. package/dist/callout-ui-ad50f301.node.cjs.js +131 -0
  23. package/dist/declarations/src/component-blocks.d.ts +4 -0
  24. package/dist/declarations/src/component-blocks.d.ts.map +1 -0
  25. package/dist/declarations/src/document-editor/component-blocks/api.d.ts +120 -0
  26. package/dist/declarations/src/document-editor/component-blocks/api.d.ts.map +1 -0
  27. package/dist/declarations/src/document-editor/component-blocks/types.d.ts +241 -0
  28. package/dist/declarations/src/document-editor/component-blocks/types.d.ts.map +1 -0
  29. package/dist/declarations/src/document-editor/toolset/relationship/relationship-shared.d.ts +10 -0
  30. package/dist/declarations/src/document-editor/toolset/relationship/relationship-shared.d.ts.map +1 -0
  31. package/dist/declarations/src/index.d.ts +7 -0
  32. package/dist/declarations/src/index.d.ts.map +1 -0
  33. package/dist/declarations/src/my-component-blocks/index.d.ts +46 -0
  34. package/dist/declarations/src/my-component-blocks/index.d.ts.map +1 -0
  35. package/dist/declarations/src/structure/Cell.d.ts +5 -0
  36. package/dist/declarations/src/structure/Cell.d.ts.map +1 -0
  37. package/dist/declarations/src/structure/Field.d.ts +5 -0
  38. package/dist/declarations/src/structure/Field.d.ts.map +1 -0
  39. package/dist/declarations/src/structure/controller.d.ts +10 -0
  40. package/dist/declarations/src/structure/controller.d.ts.map +1 -0
  41. package/dist/declarations/src/structure/structure.d.ts +4 -0
  42. package/dist/declarations/src/structure/structure.d.ts.map +1 -0
  43. package/dist/declarations/src/structure-views.d.ts +5 -0
  44. package/dist/declarations/src/structure-views.d.ts.map +1 -0
  45. package/dist/declarations/src/types/DocumentFeatures.d.ts +33 -0
  46. package/dist/declarations/src/types/DocumentFeatures.d.ts.map +1 -0
  47. package/dist/declarations/src/types/DocumentFieldConfig.d.ts +18 -0
  48. package/dist/declarations/src/types/DocumentFieldConfig.d.ts.map +1 -0
  49. package/dist/declarations/src/types/FormattingConfig.d.ts +28 -0
  50. package/dist/declarations/src/types/FormattingConfig.d.ts.map +1 -0
  51. package/dist/declarations/src/types/RelationshipsConfig.d.ts +9 -0
  52. package/dist/declarations/src/types/RelationshipsConfig.d.ts.map +1 -0
  53. package/dist/declarations/src/types/StructureFieldConfig.d.ts +10 -0
  54. package/dist/declarations/src/types/StructureFieldConfig.d.ts.map +1 -0
  55. package/dist/declarations/src/validation/structure-validation.d.ts +218 -0
  56. package/dist/declarations/src/validation/structure-validation.d.ts.map +1 -0
  57. package/dist/declarations/src/views/Cell.d.ts +5 -0
  58. package/dist/declarations/src/views/Cell.d.ts.map +1 -0
  59. package/dist/declarations/src/views/Field.d.ts +5 -0
  60. package/dist/declarations/src/views/Field.d.ts.map +1 -0
  61. package/dist/declarations/src/views/controller.d.ts +15 -0
  62. package/dist/declarations/src/views/controller.d.ts.map +1 -0
  63. package/dist/declarations/src/views/document.d.ts +4 -0
  64. package/dist/declarations/src/views/document.d.ts.map +1 -0
  65. package/dist/declarations/src/views.d.ts +7 -0
  66. package/dist/declarations/src/views.d.ts.map +1 -0
  67. package/dist/editor-shared-a6e340e6.node.esm.js +1993 -0
  68. package/dist/editor-shared-a997ae98.node.cjs.js +2007 -0
  69. package/dist/editor-shared-cc1293ed.cjs.js +2007 -0
  70. package/dist/editor-shared-da518ba3.esm.js +1993 -0
  71. package/dist/form-from-preview-2042b9ef.cjs.js +512 -0
  72. package/dist/form-from-preview-5df6e492.node.esm.js +508 -0
  73. package/dist/form-from-preview-9e501058.node.cjs.js +512 -0
  74. package/dist/form-from-preview-b3a66f37.esm.js +508 -0
  75. package/dist/index-06c36775.cjs.js +14 -0
  76. package/dist/index-586adb8f.node.esm.js +11 -0
  77. package/dist/index-67d52357.esm.js +11 -0
  78. package/dist/index-c3223fdc.node.cjs.js +14 -0
  79. package/dist/layouts-6412fa2a.esm.js +189 -0
  80. package/dist/layouts-a4a3cf0b.node.cjs.js +196 -0
  81. package/dist/layouts-ba9a558b.cjs.js +196 -0
  82. package/dist/layouts-e653b908.node.esm.js +189 -0
  83. package/dist/lkb-fields-document.cjs.d.ts +2 -0
  84. package/dist/lkb-fields-document.cjs.js +1167 -0
  85. package/dist/lkb-fields-document.esm.js +1162 -0
  86. package/dist/lkb-fields-document.node.cjs.js +1167 -0
  87. package/dist/lkb-fields-document.node.esm.js +1162 -0
  88. package/dist/shared-0533009e.cjs.js +594 -0
  89. package/dist/shared-4684cc24.node.cjs.js +594 -0
  90. package/dist/shared-5e864055.node.esm.js +579 -0
  91. package/dist/shared-aaba5901.esm.js +579 -0
  92. package/dist/toolbar-state-3359e2f3.cjs.js +994 -0
  93. package/dist/toolbar-state-945823b8.node.esm.js +971 -0
  94. package/dist/toolbar-state-9611743f.node.cjs.js +994 -0
  95. package/dist/toolbar-state-bc8fe661.esm.js +971 -0
  96. package/dist/utils-06bcddc4.node.cjs.js +747 -0
  97. package/dist/utils-200ff260.node.esm.js +722 -0
  98. package/dist/utils-6409f730.cjs.js +747 -0
  99. package/dist/utils-bc6a0b82.esm.js +722 -0
  100. package/package.json +118 -0
  101. package/structure-views/dist/lkb-fields-document-structure-views.cjs.d.ts +2 -0
  102. package/structure-views/dist/lkb-fields-document-structure-views.cjs.js +138 -0
  103. package/structure-views/dist/lkb-fields-document-structure-views.esm.js +131 -0
  104. package/structure-views/dist/lkb-fields-document-structure-views.node.cjs.js +138 -0
  105. package/structure-views/dist/lkb-fields-document-structure-views.node.esm.js +131 -0
  106. package/structure-views/package.json +4 -0
  107. package/views/dist/lkb-fields-document-views.cjs.d.ts +2 -0
  108. package/views/dist/lkb-fields-document-views.cjs.js +114 -0
  109. package/views/dist/lkb-fields-document-views.esm.js +95 -0
  110. package/views/dist/lkb-fields-document-views.node.cjs.js +114 -0
  111. package/views/dist/lkb-fields-document-views.node.esm.js +95 -0
  112. package/views/package.json +4 -0
@@ -0,0 +1,722 @@
1
+ import { Editor, Node, Transforms, Text, Path, Element } from 'slate';
2
+
3
+ const allMarks = ['bold', 'italic', 'underline', 'strikethrough', 'code', 'superscript', 'subscript', 'keyboard'];
4
+ typeof window != 'undefined' && /Mac|iPod|iPhone|iPad/.test(window.navigator.platform);
5
+ function isElementActive(editor, format) {
6
+ const [match] = Editor.nodes(editor, {
7
+ match: n => n.type === format
8
+ });
9
+ return !!match;
10
+ }
11
+ function clearFormatting(editor) {
12
+ Transforms.unwrapNodes(editor, {
13
+ match: node => node.type === 'heading' || node.type === 'blockquote' || node.type === 'code'
14
+ });
15
+ Transforms.unsetNodes(editor, allMarks, {
16
+ match: Text.isText
17
+ });
18
+ }
19
+ function moveChildren(editor, parent, to, shouldMoveNode = () => true) {
20
+ const parentPath = Path.isPath(parent) ? parent : parent[1];
21
+ const parentNode = Path.isPath(parent) ? Node.get(editor, parentPath) : parent[0];
22
+ if (!(Element.isElement(parentNode) && Editor.isBlock(editor, parentNode))) return;
23
+ for (let i = parentNode.children.length - 1; i >= 0; i--) {
24
+ if (shouldMoveNode(parentNode.children[i])) {
25
+ const childPath = [...parentPath, i];
26
+ Transforms.moveNodes(editor, {
27
+ at: childPath,
28
+ to
29
+ });
30
+ }
31
+ }
32
+ }
33
+ function insertNodesButReplaceIfSelectionIsAtEmptyParagraphOrHeading(editor, nodes, slate) {
34
+ var _pathRefForEmptyNodeA;
35
+ let pathRefForEmptyNodeAtCursor;
36
+ const entry = Editor.above(editor, {
37
+ match: node => node.type === 'heading' || node.type === 'paragraph'
38
+ });
39
+ if (entry && Node.string(entry[0]) === '') {
40
+ pathRefForEmptyNodeAtCursor = Editor.pathRef(editor, entry[1]);
41
+ }
42
+ Transforms.insertNodes(editor, nodes);
43
+ const path = (_pathRefForEmptyNodeA = pathRefForEmptyNodeAtCursor) === null || _pathRefForEmptyNodeA === void 0 ? void 0 : _pathRefForEmptyNodeA.unref();
44
+ if (path) {
45
+ Transforms.removeNodes(editor, {
46
+ at: path
47
+ });
48
+ // even though the selection is in the right place after the removeNodes
49
+ // for some reason the editor blurs so we need to focus it again
50
+ slate === null || slate === void 0 || slate.ReactEditor.focus(editor);
51
+ }
52
+ }
53
+
54
+ /**
55
+ * This is equivalent to Editor.after except that it ignores points that have no content
56
+ * like the point in a void text node, an empty text node and the last point in a text node
57
+ */
58
+ // TODO: this would probably break if you were trying to get the last point in the editor?
59
+ function EditorAfterButIgnoringingPointsWithNoContent(editor, at, {
60
+ distance = 1
61
+ } = {}) {
62
+ const anchor = Editor.point(editor, at, {
63
+ edge: 'end'
64
+ });
65
+ const focus = Editor.end(editor, []);
66
+ const range = {
67
+ anchor,
68
+ focus
69
+ };
70
+ let d = 0;
71
+ let target;
72
+ for (const p of Editor.positions(editor, {
73
+ at: range
74
+ })) {
75
+ if (d > distance) break;
76
+
77
+ // this is the important change
78
+ const node = Node.get(editor, p.path);
79
+ if (node.text.length === p.offset) continue;
80
+ if (d !== 0) {
81
+ target = p;
82
+ }
83
+ d++;
84
+ }
85
+ return target;
86
+ }
87
+ function nodeTypeMatcher(...args) {
88
+ if (args.length === 1) {
89
+ const type = args[0];
90
+ return node => node.type === type;
91
+ }
92
+ const set = new Set(args);
93
+ return node => typeof node.type === 'string' && set.has(node.type);
94
+ }
95
+ function assert(condition) {
96
+ if (!condition) throw new Error('failed assert');
97
+ }
98
+
99
+ function getInitialValue(type, componentBlock) {
100
+ const props = getInitialPropsValue({
101
+ kind: 'object',
102
+ fields: componentBlock.schema
103
+ });
104
+ return {
105
+ type: 'component-block',
106
+ component: type,
107
+ props,
108
+ children: findChildPropPaths(props, componentBlock.schema).map(x => ({
109
+ type: `component-${x.options.kind}-prop`,
110
+ propPath: x.path,
111
+ children: [x.options.kind === 'block' ? {
112
+ type: 'paragraph',
113
+ children: [{
114
+ text: ''
115
+ }]
116
+ } : {
117
+ text: ''
118
+ }]
119
+ }))
120
+ };
121
+ }
122
+ function getInitialPropsValue(schema) {
123
+ switch (schema.kind) {
124
+ case 'form':
125
+ return schema.defaultValue;
126
+ case 'child':
127
+ return null;
128
+ case 'relationship':
129
+ return schema.many ? [] : null;
130
+ case 'conditional':
131
+ {
132
+ const defaultValue = schema.discriminant.defaultValue;
133
+ return {
134
+ discriminant: defaultValue,
135
+ value: getInitialPropsValue(schema.values[defaultValue.toString()])
136
+ };
137
+ }
138
+ case 'object':
139
+ {
140
+ const obj = {};
141
+ for (const key of Object.keys(schema.fields)) {
142
+ obj[key] = getInitialPropsValue(schema.fields[key]);
143
+ }
144
+ return obj;
145
+ }
146
+ case 'array':
147
+ return [];
148
+ }
149
+ assertNever(schema);
150
+ }
151
+ function getInitialPropsValueFromInitializer(schema, initializer) {
152
+ switch (schema.kind) {
153
+ case 'form':
154
+ return initializer === undefined ? schema.defaultValue : initializer;
155
+ case 'child':
156
+ return null;
157
+ case 'relationship':
158
+ return initializer === undefined ? schema.many ? [] : null : initializer;
159
+ case 'conditional':
160
+ {
161
+ const defaultValue = initializer === undefined ? schema.discriminant.defaultValue : initializer.discriminant;
162
+ return {
163
+ discriminant: defaultValue,
164
+ value: getInitialPropsValueFromInitializer(schema.values[defaultValue.toString()], initializer === undefined ? undefined : initializer.value)
165
+ };
166
+ }
167
+ case 'object':
168
+ {
169
+ const obj = {};
170
+ for (const key of Object.keys(schema.fields)) {
171
+ obj[key] = getInitialPropsValueFromInitializer(schema.fields[key], initializer === undefined ? undefined : initializer[key]);
172
+ }
173
+ return obj;
174
+ }
175
+ case 'array':
176
+ {
177
+ return (initializer !== null && initializer !== void 0 ? initializer : []).map(x => getInitialPropsValueFromInitializer(schema.element, x.value));
178
+ }
179
+ }
180
+ assertNever(schema);
181
+ }
182
+ function updateValue(schema, currentValue, updater) {
183
+ if (updater === undefined) return currentValue;
184
+ switch (schema.kind) {
185
+ case 'relationship':
186
+ return updater;
187
+ case 'form':
188
+ return updater;
189
+ case 'child':
190
+ return null;
191
+ case 'conditional':
192
+ {
193
+ return {
194
+ discriminant: updater.discriminant,
195
+ value: updater.discriminant === currentValue.discriminant ? updateValue(schema.values[updater.discriminant.toString()], currentValue.value, updater.value) : getInitialPropsValueFromInitializer(schema.values[updater.discriminant.toString()], updater.value)
196
+ };
197
+ }
198
+ case 'object':
199
+ {
200
+ const obj = {};
201
+ for (const key of Object.keys(schema.fields)) {
202
+ obj[key] = updateValue(schema.fields[key], currentValue[key], updater[key]);
203
+ }
204
+ return obj;
205
+ }
206
+ case 'array':
207
+ {
208
+ const currentArrVal = currentValue;
209
+ const newVal = updater;
210
+ const uniqueKeys = new Set();
211
+ for (const x of newVal) {
212
+ if (x.key !== undefined) {
213
+ if (uniqueKeys.has(x.key)) {
214
+ throw new Error('Array elements must have unique keys');
215
+ }
216
+ uniqueKeys.add(x.key);
217
+ }
218
+ }
219
+ const keys = newVal.map(x => {
220
+ if (x.key !== undefined) return x.key;
221
+ let elementKey = getNewArrayElementKey();
222
+ // just in case someone gives a key that is above our counter
223
+ while (uniqueKeys.has(elementKey)) {
224
+ elementKey = getNewArrayElementKey();
225
+ }
226
+ uniqueKeys.add(elementKey);
227
+ return elementKey;
228
+ });
229
+ const prevKeys = getKeysForArrayValue(currentArrVal);
230
+ const prevValuesByKey = new Map(currentArrVal.map((value, i) => {
231
+ return [prevKeys[i], value];
232
+ }));
233
+ const val = newVal.map((x, i) => {
234
+ const id = keys[i];
235
+ if (prevValuesByKey.has(id)) {
236
+ return updateValue(schema.element, prevValuesByKey.get(id), x.value);
237
+ }
238
+ return getInitialPropsValueFromInitializer(schema.element, x.value);
239
+ });
240
+ setKeysForArrayValue(val, keys);
241
+ return val;
242
+ }
243
+ }
244
+ assertNever(schema);
245
+ }
246
+
247
+ const arrayValuesToElementKeys = new WeakMap();
248
+ let counter = 0;
249
+ function getKeysForArrayValue(value) {
250
+ if (!arrayValuesToElementKeys.has(value)) {
251
+ arrayValuesToElementKeys.set(value, Array.from({
252
+ length: value.length
253
+ }, getNewArrayElementKey));
254
+ }
255
+ return arrayValuesToElementKeys.get(value);
256
+ }
257
+ function setKeysForArrayValue(value, elementIds) {
258
+ arrayValuesToElementKeys.set(value, elementIds);
259
+ }
260
+ function getNewArrayElementKey() {
261
+ return (counter++).toString();
262
+ }
263
+ function castToMemoizedInfoForSchema(val) {
264
+ return val;
265
+ }
266
+ function getOrInsert(map, key, val) {
267
+ if (!map.has(key)) map.set(key, val(key));
268
+ return map.get(key);
269
+ }
270
+ function createGetPreviewProps(rootSchema, rootOnChange, getChildFieldElement) {
271
+ const memoizedInfoForSchema = castToMemoizedInfoForSchema({
272
+ form(schema, onChange) {
273
+ return newVal => onChange(() => newVal);
274
+ },
275
+ array(schema, onChange) {
276
+ return {
277
+ rawOnChange: onChange,
278
+ inner: new Map(),
279
+ onChange(updater) {
280
+ onChange(value => updateValue(schema, value, updater));
281
+ }
282
+ };
283
+ },
284
+ child() {},
285
+ conditional(schema, onChange) {
286
+ return {
287
+ onChange: (discriminant, value) => onChange(v => updateValue(schema, v, {
288
+ discriminant,
289
+ value
290
+ })),
291
+ onChangeForValue: cb => onChange(v => ({
292
+ discriminant: v.discriminant,
293
+ value: cb(v.value)
294
+ }))
295
+ };
296
+ },
297
+ object(schema, onChange) {
298
+ return {
299
+ onChange: updater => {
300
+ onChange(value => updateValue(schema, value, updater));
301
+ },
302
+ innerOnChanges: Object.fromEntries(Object.keys(schema.fields).map(key => {
303
+ return [key, newVal => {
304
+ onChange(v => ({
305
+ ...v,
306
+ [key]: newVal(v[key])
307
+ }));
308
+ }];
309
+ }))
310
+ };
311
+ },
312
+ relationship(schema, onChange) {
313
+ return newVal => onChange(() => newVal);
314
+ }
315
+ });
316
+ const previewPropsFactories = {
317
+ form(schema, value, onChange) {
318
+ return {
319
+ value: value,
320
+ onChange,
321
+ options: schema.options,
322
+ schema: schema
323
+ };
324
+ },
325
+ child(schema, value, onChange, path) {
326
+ return {
327
+ element: getChildFieldElement(path),
328
+ schema: schema
329
+ };
330
+ },
331
+ object(schema, value, memoized, path, getInnerProp) {
332
+ const fields = {};
333
+ for (const key of Object.keys(schema.fields)) {
334
+ fields[key] = getInnerProp(schema.fields[key], value[key], memoized.innerOnChanges[key], key);
335
+ }
336
+ const previewProps = {
337
+ fields,
338
+ onChange: memoized.onChange,
339
+ schema: schema
340
+ };
341
+ return previewProps;
342
+ },
343
+ array(schema, value, memoized, path, getInnerProp) {
344
+ if (!Array.isArray(value)) throw new TypeError('Expected array');
345
+ const arrayValue = value;
346
+ const keys = getKeysForArrayValue(arrayValue);
347
+ const unusedKeys = new Set([...keys]);
348
+ const props = {
349
+ elements: arrayValue.map((val, i) => {
350
+ const key = keys[i];
351
+ unusedKeys.delete(key);
352
+ const element = getOrInsert(memoized.inner, key, () => {
353
+ const onChange = val => {
354
+ memoized.rawOnChange(prev => {
355
+ const keys = getKeysForArrayValue(prev);
356
+ const index = keys.indexOf(key);
357
+ const newValue = [...prev];
358
+ newValue[index] = val(newValue[index]);
359
+ setKeysForArrayValue(newValue, keys);
360
+ return newValue;
361
+ });
362
+ };
363
+ const element = getInnerProp(schema.element, val, onChange, key);
364
+ return {
365
+ element,
366
+ elementWithKey: {
367
+ ...element,
368
+ key
369
+ },
370
+ onChange
371
+ };
372
+ });
373
+ const currentInnerProp = getInnerProp(schema.element, val, element.onChange, key);
374
+ if (element.element !== currentInnerProp) {
375
+ element.element = currentInnerProp;
376
+ element.elementWithKey = {
377
+ ...currentInnerProp,
378
+ key
379
+ };
380
+ }
381
+ return element.elementWithKey;
382
+ }),
383
+ schema: schema,
384
+ onChange: memoized.onChange
385
+ };
386
+ for (const key of unusedKeys) {
387
+ memoized.inner.delete(key);
388
+ }
389
+ return props;
390
+ },
391
+ relationship(schema, value, onChange) {
392
+ const props = {
393
+ value: value,
394
+ onChange,
395
+ schema: schema
396
+ };
397
+ return props;
398
+ },
399
+ conditional(schema, value, memoized, path, getInnerProp) {
400
+ const props = {
401
+ discriminant: value.discriminant,
402
+ onChange: memoized.onChange,
403
+ options: schema.discriminant.options,
404
+ value: getInnerProp(schema.values[value.discriminant.toString()], value.value, memoized.onChangeForValue, 'value'),
405
+ schema: schema
406
+ };
407
+ return props;
408
+ }
409
+ };
410
+ function getPreviewPropsForProp(schema, value, memoedThing, path, getInnerProp) {
411
+ return previewPropsFactories[schema.kind](schema, value, memoedThing, path, getInnerProp);
412
+ }
413
+ function getInitialMemoState(schema, value, onChange, path) {
414
+ const innerState = new Map();
415
+ const memoizedInfo = memoizedInfoForSchema[schema.kind](schema, onChange);
416
+ const state = {
417
+ value,
418
+ inner: innerState,
419
+ props: getPreviewPropsForProp(schema, value, memoizedInfo, path, (schema, value, onChange, key) => {
420
+ const state = getInitialMemoState(schema, value, onChange, path.concat(key));
421
+ innerState.set(key, state);
422
+ return state.props;
423
+ }),
424
+ schema: schema,
425
+ cached: memoizedInfo
426
+ };
427
+ return state;
428
+ }
429
+ function getUpToDateProps(schema, value, onChange, memoState, path) {
430
+ if (memoState.schema !== schema) {
431
+ Object.assign(memoState, getInitialMemoState(schema, value, onChange, path));
432
+ return memoState.props;
433
+ }
434
+ if (memoState.value === value) {
435
+ return memoState.props;
436
+ }
437
+ memoState.value = value;
438
+ const unusedKeys = new Set(memoState.inner.keys());
439
+ memoState.props = getPreviewPropsForProp(schema, value, memoState.cached, path, (schema, value, onChange, innerMemoStateKey) => {
440
+ unusedKeys.delete(innerMemoStateKey);
441
+ if (!memoState.inner.has(innerMemoStateKey)) {
442
+ const innerState = getInitialMemoState(schema, value, onChange, path.concat(innerMemoStateKey));
443
+ memoState.inner.set(innerMemoStateKey, innerState);
444
+ return innerState.props;
445
+ }
446
+ return getUpToDateProps(schema, value, onChange, memoState.inner.get(innerMemoStateKey), path.concat(innerMemoStateKey));
447
+ });
448
+ for (const key of unusedKeys) {
449
+ memoState.inner.delete(key);
450
+ }
451
+ return memoState.props;
452
+ }
453
+ let memoState;
454
+ return value => {
455
+ if (memoState === undefined) {
456
+ memoState = getInitialMemoState(rootSchema, value, rootOnChange, []);
457
+ return memoState.props;
458
+ }
459
+ return getUpToDateProps(rootSchema, value, rootOnChange, memoState, []);
460
+ };
461
+ }
462
+
463
+ function findChildPropPathsForProp(value, schema, path) {
464
+ switch (schema.kind) {
465
+ case 'form':
466
+ case 'relationship':
467
+ return [];
468
+ case 'child':
469
+ return [{
470
+ path: path,
471
+ options: schema.options
472
+ }];
473
+ case 'conditional':
474
+ return findChildPropPathsForProp(value.value, schema.values[value.discriminant], path.concat('value'));
475
+ case 'object':
476
+ {
477
+ const paths = [];
478
+ Object.keys(schema.fields).forEach(key => {
479
+ paths.push(...findChildPropPathsForProp(value[key], schema.fields[key], path.concat(key)));
480
+ });
481
+ return paths;
482
+ }
483
+ case 'array':
484
+ {
485
+ const paths = [];
486
+ value.forEach((val, i) => {
487
+ paths.push(...findChildPropPathsForProp(val, schema.element, path.concat(i)));
488
+ });
489
+ return paths;
490
+ }
491
+ }
492
+ }
493
+ function findChildPropPaths(value, props) {
494
+ const propPaths = findChildPropPathsForProp(value, {
495
+ kind: 'object',
496
+ fields: props
497
+ }, []);
498
+ if (propPaths.length) return propPaths;
499
+ return [{
500
+ path: undefined,
501
+ options: {
502
+ kind: 'inline',
503
+ placeholder: ''
504
+ }
505
+ }];
506
+ }
507
+ function assertNever(arg) {
508
+ throw new Error('expected to never be called but received: ' + JSON.stringify(arg));
509
+ }
510
+ function getDocumentFeaturesForChildField(editorDocumentFeatures, options) {
511
+ var _options$formatting, _options$formatting3, _options$formatting4, _options$formatting5, _options$formatting6, _options$formatting7, _options$formatting8;
512
+ // an important note for this: normalization based on document features
513
+ // is done based on the document features returned here
514
+ // and the editor document features
515
+ // so the result for any given child prop will be the things that are
516
+ // allowed by both these document features
517
+ // AND the editor document features
518
+ const inlineMarksFromOptions = (_options$formatting = options.formatting) === null || _options$formatting === void 0 ? void 0 : _options$formatting.inlineMarks;
519
+ const inlineMarks = inlineMarksFromOptions === 'inherit' ? 'inherit' : Object.fromEntries(Object.keys(editorDocumentFeatures.formatting.inlineMarks).map(mark => {
520
+ return [mark, !!(inlineMarksFromOptions || {})[mark]];
521
+ }));
522
+ if (options.kind === 'inline') {
523
+ var _options$formatting2;
524
+ return {
525
+ kind: 'inline',
526
+ inlineMarks,
527
+ documentFeatures: {
528
+ links: options.links === 'inherit',
529
+ relationships: options.relationships === 'inherit'
530
+ },
531
+ softBreaks: ((_options$formatting2 = options.formatting) === null || _options$formatting2 === void 0 ? void 0 : _options$formatting2.softBreaks) === 'inherit'
532
+ };
533
+ }
534
+ return {
535
+ kind: 'block',
536
+ inlineMarks,
537
+ softBreaks: ((_options$formatting3 = options.formatting) === null || _options$formatting3 === void 0 ? void 0 : _options$formatting3.softBreaks) === 'inherit',
538
+ documentFeatures: {
539
+ layouts: [],
540
+ dividers: options.dividers === 'inherit' ? editorDocumentFeatures.dividers : false,
541
+ formatting: {
542
+ alignment: ((_options$formatting4 = options.formatting) === null || _options$formatting4 === void 0 ? void 0 : _options$formatting4.alignment) === 'inherit' ? editorDocumentFeatures.formatting.alignment : {
543
+ center: false,
544
+ end: false
545
+ },
546
+ blockTypes: ((_options$formatting5 = options.formatting) === null || _options$formatting5 === void 0 ? void 0 : _options$formatting5.blockTypes) === 'inherit' ? editorDocumentFeatures.formatting.blockTypes : {
547
+ blockquote: false,
548
+ code: false
549
+ },
550
+ headingLevels: ((_options$formatting6 = options.formatting) === null || _options$formatting6 === void 0 ? void 0 : _options$formatting6.headingLevels) === 'inherit' ? editorDocumentFeatures.formatting.headingLevels : ((_options$formatting7 = options.formatting) === null || _options$formatting7 === void 0 ? void 0 : _options$formatting7.headingLevels) || [],
551
+ listTypes: ((_options$formatting8 = options.formatting) === null || _options$formatting8 === void 0 ? void 0 : _options$formatting8.listTypes) === 'inherit' ? editorDocumentFeatures.formatting.listTypes : {
552
+ ordered: false,
553
+ unordered: false
554
+ }
555
+ },
556
+ links: options.links === 'inherit',
557
+ relationships: options.relationships === 'inherit'
558
+ },
559
+ componentBlocks: options.componentBlocks === 'inherit'
560
+ };
561
+ }
562
+ function getSchemaAtPropPathInner(path, value, schema) {
563
+ // because we're checking the length here
564
+ // the non-null asserts on shift below are fine
565
+ if (path.length === 0) return schema;
566
+ if (schema.kind === 'child' || schema.kind === 'form' || schema.kind === 'relationship') return;
567
+ if (schema.kind === 'conditional') {
568
+ const key = path.shift();
569
+ if (key === 'discriminant') return getSchemaAtPropPathInner(path, value.discriminant, schema.discriminant);
570
+ if (key === 'value') {
571
+ const propVal = schema.values[value.discriminant];
572
+ return getSchemaAtPropPathInner(path, value.value, propVal);
573
+ }
574
+ return;
575
+ }
576
+ if (schema.kind === 'object') {
577
+ const key = path.shift();
578
+ return getSchemaAtPropPathInner(path, value[key], schema.fields[key]);
579
+ }
580
+ if (schema.kind === 'array') {
581
+ const index = path.shift();
582
+ return getSchemaAtPropPathInner(path, value[index], schema.element);
583
+ }
584
+ assertNever(schema);
585
+ }
586
+ function getSchemaAtPropPath(path, value, props) {
587
+ return getSchemaAtPropPathInner([...path], value, {
588
+ kind: 'object',
589
+ fields: props
590
+ });
591
+ }
592
+ function clientSideValidateProp(schema, value) {
593
+ if (schema.kind === 'child') return true;
594
+ if (schema.kind === 'relationship') return true;
595
+ if (schema.kind === 'form') return schema.validate(value);
596
+ if (typeof value !== 'object') return false;
597
+ if (value === null) return false;
598
+ switch (schema.kind) {
599
+ case 'conditional':
600
+ {
601
+ if (!('discriminant' in value) || !('value' in value)) return false;
602
+ if (!schema.discriminant.validate(value.discriminant)) return false;
603
+ return clientSideValidateProp(schema.values[
604
+ // not actually gonna always be a string but just let property access do the coercion
605
+ value.discriminant], value.value);
606
+ }
607
+ case 'object':
608
+ {
609
+ for (const [key, childProp] of Object.entries(schema.fields)) {
610
+ if (!clientSideValidateProp(childProp, value[key])) return false;
611
+ }
612
+ return true;
613
+ }
614
+ case 'array':
615
+ {
616
+ if (!Array.isArray(value)) return false;
617
+ for (const innerVal of value) {
618
+ if (!clientSideValidateProp(schema.element, innerVal)) return false;
619
+ }
620
+ return true;
621
+ }
622
+ }
623
+ }
624
+ function getAncestorSchemas(rootSchema, path, value) {
625
+ const ancestors = [];
626
+ const currentPath = [...path];
627
+ let currentProp = rootSchema;
628
+ let currentValue = value;
629
+ while (currentPath.length) {
630
+ ancestors.push(currentProp);
631
+ const key = currentPath.shift(); // this code only runs when path.length is truthy so this non-null assertion is fine
632
+ if (currentProp.kind === 'array') {
633
+ currentProp = currentProp.element;
634
+ currentValue = currentValue[key];
635
+ } else if (currentProp.kind === 'conditional') {
636
+ currentProp = currentProp.values[value.discriminant];
637
+ currentValue = currentValue.value;
638
+ } else if (currentProp.kind === 'object') {
639
+ currentValue = currentValue[key];
640
+ currentProp = currentProp.fields[key];
641
+ } else if (currentProp.kind === 'child' || currentProp.kind === 'form' || currentProp.kind === 'relationship') {
642
+ throw new Error(`unexpected prop "${key}"`);
643
+ } else {
644
+ assertNever(currentProp);
645
+ }
646
+ }
647
+ return ancestors;
648
+ }
649
+ function getValueAtPropPath(value, inputPath) {
650
+ const path = [...inputPath];
651
+ while (path.length) {
652
+ const key = path.shift();
653
+ value = value[key];
654
+ }
655
+ return value;
656
+ }
657
+ function traverseProps(schema, value, visitor, path = []) {
658
+ if (schema.kind === 'form' || schema.kind === 'relationship' || schema.kind === 'child') {
659
+ visitor(schema, value, path);
660
+ return;
661
+ }
662
+ if (schema.kind === 'object') {
663
+ for (const [key, childProp] of Object.entries(schema.fields)) {
664
+ traverseProps(childProp, value[key], visitor, [...path, key]);
665
+ }
666
+ visitor(schema, value, path);
667
+ return;
668
+ }
669
+ if (schema.kind === 'array') {
670
+ for (const [idx, val] of value.entries()) {
671
+ traverseProps(schema.element, val, visitor, path.concat(idx));
672
+ }
673
+ return visitor(schema, value, path);
674
+ }
675
+ if (schema.kind === 'conditional') {
676
+ const discriminant = value.discriminant;
677
+ visitor(schema, discriminant, path.concat('discriminant'));
678
+ traverseProps(schema.values[discriminant.toString()], value.value, visitor, path.concat('value'));
679
+ visitor(schema, value, path);
680
+ return;
681
+ }
682
+ assertNever(schema);
683
+ }
684
+ function replaceValueAtPropPath(schema, value, newValue, path) {
685
+ if (path.length === 0) return newValue;
686
+ const [key, ...newPath] = path;
687
+ if (schema.kind === 'object') {
688
+ return {
689
+ ...value,
690
+ [key]: replaceValueAtPropPath(schema.fields[key], value[key], newValue, newPath)
691
+ };
692
+ }
693
+ if (schema.kind === 'conditional') {
694
+ const conditionalValue = value;
695
+ // replaceValueAtPropPath should not be used to only update the discriminant of a conditional field
696
+ // if you want to update the discriminant of a conditional field, replace the value of the whole conditional field
697
+ assert(key === 'value');
698
+ return {
699
+ discriminant: conditionalValue.discriminant,
700
+ value: replaceValueAtPropPath(schema.values[key], conditionalValue.value, newValue, newPath)
701
+ };
702
+ }
703
+ if (schema.kind === 'array') {
704
+ const prevVal = value;
705
+ const newVal = [...prevVal];
706
+ setKeysForArrayValue(newVal, getKeysForArrayValue(prevVal));
707
+ newVal[key] = replaceValueAtPropPath(schema.element, newVal[key], newValue, newPath);
708
+ return newVal;
709
+ }
710
+
711
+ // we should never reach here since form, relationship or child fields don't contain other fields
712
+ // so the only thing that can happen to them is to be replaced which happens at the start of this function when path.length === 0
713
+ assert(schema.kind !== 'form' && schema.kind !== 'relationship' && schema.kind !== 'child');
714
+ assertNever(schema);
715
+ }
716
+ function getPlaceholderTextForPropPath(propPath, fields, formProps) {
717
+ const field = getSchemaAtPropPath(propPath, formProps, fields);
718
+ if ((field === null || field === void 0 ? void 0 : field.kind) === 'child') return field.options.placeholder;
719
+ return '';
720
+ }
721
+
722
+ export { EditorAfterButIgnoringingPointsWithNoContent as E, assertNever as a, getDocumentFeaturesForChildField as b, getAncestorSchemas as c, assert as d, getValueAtPropPath as e, getKeysForArrayValue as f, getInitialPropsValue as g, findChildPropPaths as h, getNewArrayElementKey as i, isElementActive as j, insertNodesButReplaceIfSelectionIsAtEmptyParagraphOrHeading as k, getSchemaAtPropPath as l, moveChildren as m, nodeTypeMatcher as n, allMarks as o, clientSideValidateProp as p, createGetPreviewProps as q, replaceValueAtPropPath as r, setKeysForArrayValue as s, traverseProps as t, clearFormatting as u, getPlaceholderTextForPropPath as v, getInitialValue as w };