lkb-fields-document 1.0.0 → 1.0.1

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