@portabletext/editor 6.6.4 → 7.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 (43) hide show
  1. package/lib/_chunks-dts/behavior.types.action.d.ts +683 -512
  2. package/lib/_chunks-dts/behavior.types.action.d.ts.map +1 -1
  3. package/lib/_chunks-dts/resolve-containers.d.ts +688 -0
  4. package/lib/_chunks-dts/resolve-containers.d.ts.map +1 -0
  5. package/lib/_chunks-es/get-ancestor.js +192 -0
  6. package/lib/_chunks-es/get-ancestor.js.map +1 -0
  7. package/lib/_chunks-es/get-first-child.js +130 -0
  8. package/lib/_chunks-es/get-first-child.js.map +1 -0
  9. package/lib/_chunks-es/get-path-sub-schema.js +266 -0
  10. package/lib/_chunks-es/get-path-sub-schema.js.map +1 -0
  11. package/lib/_chunks-es/selector.is-at-the-start-of-block.js +1021 -0
  12. package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
  13. package/lib/_chunks-es/use-editor.js +4 -13
  14. package/lib/_chunks-es/use-editor.js.map +1 -1
  15. package/lib/_chunks-es/util.is-empty-text-block.js +15 -0
  16. package/lib/_chunks-es/util.is-empty-text-block.js.map +1 -0
  17. package/lib/_chunks-es/util.slice-blocks.js +347 -198
  18. package/lib/_chunks-es/util.slice-blocks.js.map +1 -1
  19. package/lib/behaviors/index.d.ts +2 -1
  20. package/lib/index.d.ts +3 -2
  21. package/lib/index.js +5442 -5604
  22. package/lib/index.js.map +1 -1
  23. package/lib/plugins/index.d.ts +18 -2
  24. package/lib/plugins/index.d.ts.map +1 -1
  25. package/lib/plugins/index.js +18 -2
  26. package/lib/plugins/index.js.map +1 -1
  27. package/lib/selectors/index.d.ts +220 -5
  28. package/lib/selectors/index.d.ts.map +1 -1
  29. package/lib/selectors/index.js +62 -71
  30. package/lib/selectors/index.js.map +1 -1
  31. package/lib/traversal/index.d.ts +235 -0
  32. package/lib/traversal/index.d.ts.map +1 -0
  33. package/lib/traversal/index.js +30 -0
  34. package/lib/traversal/index.js.map +1 -0
  35. package/lib/utils/index.d.ts +11 -57
  36. package/lib/utils/index.d.ts.map +1 -1
  37. package/lib/utils/index.js +36 -107
  38. package/lib/utils/index.js.map +1 -1
  39. package/package.json +19 -17
  40. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js +0 -806
  41. package/lib/_chunks-es/selector.is-selecting-entire-blocks.js.map +0 -1
  42. package/lib/_chunks-es/util.slice-text-block.js +0 -60
  43. package/lib/_chunks-es/util.slice-text-block.js.map +0 -1
@@ -1,12 +1,114 @@
1
- import { isTextBlock, isSpan } from "@portabletext/schema";
2
- function isTypedObject(object) {
3
- return isRecord(object) && typeof object._type == "string";
1
+ import { isTextBlock, isSpan, getSubSchema } from "@portabletext/schema";
2
+ import { getAncestor, getNode, isKeyedSegment, isTypedObject, isRecord } from "./get-ancestor.js";
3
+ function getAncestorTextBlock(snapshot, path) {
4
+ const result = getAncestor(snapshot, path, (node) => isTextBlock({
5
+ schema: snapshot.context.schema
6
+ }, node));
7
+ if (result && isTextBlock({
8
+ schema: snapshot.context.schema
9
+ }, result.node))
10
+ return {
11
+ node: result.node,
12
+ path: result.path
13
+ };
14
+ }
15
+ function blockOffsetToSpanSelectionPoint({
16
+ snapshot,
17
+ blockOffset,
18
+ direction
19
+ }) {
20
+ const blockEntry = getNode(snapshot, blockOffset.path);
21
+ if (!blockEntry || !isTextBlock(snapshot.context, blockEntry.node))
22
+ return;
23
+ const block = blockEntry.node, blockPath = blockEntry.path;
24
+ let offsetLeft = blockOffset.offset, selectionPoint, skippedInlineObject = !1;
25
+ for (const child of block.children) {
26
+ if (direction === "forward") {
27
+ if (!isSpan(snapshot.context, child))
28
+ continue;
29
+ if (offsetLeft <= child.text.length) {
30
+ selectionPoint = {
31
+ path: [...blockPath, "children", {
32
+ _key: child._key
33
+ }],
34
+ offset: offsetLeft
35
+ };
36
+ break;
37
+ }
38
+ offsetLeft -= child.text.length;
39
+ continue;
40
+ }
41
+ if (!isSpan(snapshot.context, child)) {
42
+ skippedInlineObject = !0;
43
+ continue;
44
+ }
45
+ if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {
46
+ skippedInlineObject && (selectionPoint = {
47
+ path: [...blockPath, "children", {
48
+ _key: child._key
49
+ }],
50
+ offset: 0
51
+ });
52
+ break;
53
+ }
54
+ if (offsetLeft > child.text.length) {
55
+ offsetLeft -= child.text.length;
56
+ continue;
57
+ }
58
+ if (offsetLeft <= child.text.length && (selectionPoint = {
59
+ path: [...blockPath, "children", {
60
+ _key: child._key
61
+ }],
62
+ offset: offsetLeft
63
+ }, offsetLeft -= child.text.length, offsetLeft !== 0))
64
+ break;
65
+ }
66
+ return selectionPoint;
67
+ }
68
+ function spanSelectionPointToBlockOffset({
69
+ snapshot,
70
+ selectionPoint
71
+ }) {
72
+ const spanSegment = selectionPoint.path.at(-1);
73
+ if (!isKeyedSegment(spanSegment))
74
+ return;
75
+ const textBlock = getAncestorTextBlock(snapshot, selectionPoint.path);
76
+ if (!textBlock)
77
+ return;
78
+ let offset = 0;
79
+ for (const child of textBlock.node.children)
80
+ if (isSpan(snapshot.context, child)) {
81
+ if (child._key === spanSegment._key)
82
+ return {
83
+ path: textBlock.path,
84
+ offset: offset + selectionPoint.offset
85
+ };
86
+ offset += child.text.length;
87
+ }
88
+ }
89
+ function isEqualPathSegments(segA, segB) {
90
+ return segA === segB ? !0 : segA === void 0 || segB === void 0 ? !1 : (typeof segA == "string" || typeof segA == "number") && (typeof segB == "string" || typeof segB == "number") ? segA === segB : isKeyedSegment(segA) && isKeyedSegment(segB) ? segA._key === segB._key : Array.isArray(segA) && Array.isArray(segB) ? segA[0] === segB[0] && segA[1] === segB[1] : !1;
91
+ }
92
+ function isEqualPaths(a, b) {
93
+ if (a.length !== b.length)
94
+ return !1;
95
+ for (let i = 0; i < a.length; i++)
96
+ if (!isEqualPathSegments(a[i], b[i]))
97
+ return !1;
98
+ return !0;
99
+ }
100
+ function isEqualSelectionPoints(a, b) {
101
+ return a.offset === b.offset && isEqualPaths(a.path, b.path);
4
102
  }
5
- function isRecord(value) {
6
- return !!value && (typeof value == "object" || typeof value == "function");
103
+ function getBlockKeyFromSelectionPoint(point) {
104
+ const blockPathSegment = point.path.at(0);
105
+ if (isKeyedSegment(blockPathSegment))
106
+ return blockPathSegment._key;
7
107
  }
8
- function isKeyedSegment(segment) {
9
- return typeof segment == "object" && segment !== null && "_key" in segment;
108
+ function getChildKeyFromSelectionPoint(point) {
109
+ const childPathSegment = point.path.at(2);
110
+ if (isKeyedSegment(childPathSegment))
111
+ return childPathSegment._key;
10
112
  }
11
113
  function getBlockEndPoint({
12
114
  context,
@@ -45,38 +147,25 @@ function getBlockStartPoint({
45
147
  offset: 0
46
148
  };
47
149
  }
48
- function isEqualPathSegments(segA, segB) {
49
- return segA === segB ? !0 : segA === void 0 || segB === void 0 ? !1 : (typeof segA == "string" || typeof segA == "number") && (typeof segB == "string" || typeof segB == "number") ? segA === segB : isKeyedSegment(segA) && isKeyedSegment(segB) ? segA._key === segB._key : Array.isArray(segA) && Array.isArray(segB) ? segA[0] === segB[0] && segA[1] === segB[1] : !1;
50
- }
51
- function isEqualPaths(a, b) {
52
- if (a.length !== b.length)
53
- return !1;
54
- for (let i = 0; i < a.length; i++)
55
- if (!isEqualPathSegments(a[i], b[i]))
56
- return !1;
57
- return !0;
58
- }
59
150
  function isSelectionCollapsed(selection) {
60
151
  return selection ? isEqualPaths(selection.anchor.path, selection.focus.path) && selection.anchor.offset === selection.focus.offset : !1;
61
152
  }
62
- function getBlockKeyFromSelectionPoint(point) {
63
- const blockPathSegment = point.path.at(0);
64
- if (isKeyedSegment(blockPathSegment))
65
- return blockPathSegment._key;
153
+ function getSelectionEndPoint(selection) {
154
+ return selection ? selection.backward ? selection.anchor : selection.focus : null;
66
155
  }
67
- function getChildKeyFromSelectionPoint(point) {
68
- const childPathSegment = point.path.at(2);
69
- if (isKeyedSegment(childPathSegment))
70
- return childPathSegment._key;
156
+ function getSelectionStartPoint(selection) {
157
+ return selection ? selection.backward ? selection.focus : selection.anchor : null;
71
158
  }
72
159
  function parseBlocks({
73
- context,
160
+ schema,
161
+ keyGenerator,
74
162
  blocks,
75
163
  options
76
164
  }) {
77
165
  return Array.isArray(blocks) ? blocks.flatMap((block) => {
78
- const parsedBlock = parseBlock({
79
- context,
166
+ const parsedBlock = parseBlockInternal({
167
+ schema,
168
+ keyGenerator,
80
169
  block,
81
170
  options
82
171
  });
@@ -84,37 +173,94 @@ function parseBlocks({
84
173
  }) : [];
85
174
  }
86
175
  function parseBlock({
87
- context,
176
+ schema,
177
+ keyGenerator,
178
+ block,
179
+ options
180
+ }) {
181
+ return parseBlockInternal({
182
+ schema,
183
+ keyGenerator,
184
+ block,
185
+ options
186
+ });
187
+ }
188
+ function parseSpan({
189
+ span,
190
+ schema,
191
+ keyGenerator,
192
+ markDefKeyMap,
193
+ options
194
+ }) {
195
+ return parseSpanInternal({
196
+ span,
197
+ schema,
198
+ keyGenerator,
199
+ markDefKeyMap,
200
+ options
201
+ });
202
+ }
203
+ function parseInlineObject({
204
+ inlineObject,
205
+ schema,
206
+ keyGenerator,
207
+ options
208
+ }) {
209
+ return parseInlineObjectInternal({
210
+ inlineObject,
211
+ schema,
212
+ keyGenerator,
213
+ options
214
+ });
215
+ }
216
+ function parseMarkDefs({
217
+ schema,
218
+ keyGenerator,
219
+ markDefs,
220
+ options
221
+ }) {
222
+ return parseMarkDefsInternal({
223
+ schema,
224
+ keyGenerator,
225
+ markDefs,
226
+ options
227
+ });
228
+ }
229
+ function parseBlockInternal({
230
+ schema,
231
+ keyGenerator,
88
232
  block,
89
233
  options
90
234
  }) {
91
235
  return parseTextBlock({
92
236
  block,
93
- context,
237
+ schema,
238
+ keyGenerator,
94
239
  options
95
240
  }) ?? parseBlockObject({
96
241
  blockObject: block,
97
- context,
242
+ schema,
243
+ keyGenerator,
98
244
  options
99
245
  });
100
246
  }
101
247
  function parseBlockObject({
102
248
  blockObject,
103
- context,
249
+ schema,
250
+ keyGenerator,
104
251
  options
105
252
  }) {
106
253
  if (!isTypedObject(blockObject))
107
254
  return;
108
- const schemaType = context.schema.blockObjects.find(({
255
+ const schemaType = schema.blockObjects.find(({
109
256
  name
110
257
  }) => name === blockObject._type);
111
258
  if (schemaType)
112
259
  return parseObject({
113
260
  object: blockObject,
114
- context: {
115
- keyGenerator: context.keyGenerator,
116
- schemaType
117
- },
261
+ schema,
262
+ keyGenerator,
263
+ schemaType,
118
264
  options
119
265
  });
120
266
  }
@@ -123,61 +269,67 @@ function isListBlock(context, block) {
123
269
  }
124
270
  function parseTextBlock({
125
271
  block,
126
- context,
272
+ schema,
273
+ keyGenerator,
127
274
  options
128
275
  }) {
129
- if (!isTypedObject(block))
276
+ if (!isTypedObject(block) || block._type !== schema.block.name)
130
277
  return;
131
278
  const customFields = {};
132
279
  for (const key of Object.keys(block))
133
- key === "_type" || key === "_key" || key === "children" || key === "markDefs" || key === "style" || key === "listItem" || key === "level" || (options.validateFields ? context.schema.block.fields?.some((field) => field.name === key) && (customFields[key] = block[key]) : customFields[key] = block[key]);
134
- if (block._type !== context.schema.block.name)
135
- return;
136
- const _key = typeof block._key == "string" ? block._key : context.keyGenerator(), {
280
+ key === "_type" || key === "_key" || key === "children" || key === "markDefs" || key === "style" || key === "listItem" || key === "level" || (options.validateFields ? (schema.block.fields ?? []).some((f) => f.name === key) && (customFields[key] = block[key]) : customFields[key] = block[key]);
281
+ const _key = typeof block._key == "string" ? block._key : keyGenerator(), {
137
282
  markDefs,
138
283
  markDefKeyMap
139
- } = parseMarkDefs({
140
- context,
284
+ } = parseMarkDefsInternal({
285
+ schema,
286
+ keyGenerator,
141
287
  markDefs: block.markDefs,
142
288
  options
143
- }), parsedChildren = (Array.isArray(block.children) ? block.children : []).map((child) => parseChild({
289
+ }), parsedChildren = (Array.isArray(block.children) ? block.children : []).map((child) => parseChildInternal({
144
290
  child,
145
- context,
291
+ schema,
292
+ keyGenerator,
146
293
  markDefKeyMap,
147
294
  options
148
295
  })).filter((child) => child !== void 0), marks = parsedChildren.flatMap((child) => child.marks ?? []), children = parsedChildren.length > 0 ? parsedChildren : [{
149
- _key: context.keyGenerator(),
150
- _type: context.schema.span.name,
296
+ _key: keyGenerator(),
297
+ _type: schema.span.name,
151
298
  text: "",
152
299
  marks: []
153
300
  }], normalizedChildren = options.normalize ? (
154
301
  // Ensure that inline objects re surrounded by spans
155
302
  children.reduce((normalizedChildren2, child, index) => {
156
- if (isSpan(context, child))
303
+ if (isSpan({
304
+ schema
305
+ }, child))
157
306
  return [...normalizedChildren2, child];
158
307
  const previousChild = normalizedChildren2.at(-1);
159
- return !previousChild || !isSpan(context, previousChild) ? [...normalizedChildren2, {
160
- _key: context.keyGenerator(),
161
- _type: context.schema.span.name,
308
+ return !previousChild || !isSpan({
309
+ schema
310
+ }, previousChild) ? [...normalizedChildren2, {
311
+ _key: keyGenerator(),
312
+ _type: schema.span.name,
162
313
  text: "",
163
314
  marks: []
164
315
  }, child, ...index === children.length - 1 ? [{
165
- _key: context.keyGenerator(),
166
- _type: context.schema.span.name,
316
+ _key: keyGenerator(),
317
+ _type: schema.span.name,
167
318
  text: "",
168
319
  marks: []
169
320
  }] : []] : [...normalizedChildren2, child];
170
321
  }, [])
171
322
  ) : children, parsedBlock = {
172
- _type: context.schema.block.name,
323
+ _type: schema.block.name,
173
324
  _key,
174
325
  children: normalizedChildren,
175
326
  ...customFields
176
327
  };
177
- return typeof block.markDefs == "object" && block.markDefs !== null && (parsedBlock.markDefs = options.removeUnusedMarkDefs ? markDefs.filter((markDef) => marks.includes(markDef._key)) : markDefs), typeof block.style == "string" && context.schema.styles.find((style) => style.name === block.style) && (parsedBlock.style = block.style), typeof block.listItem == "string" && context.schema.lists.find((list) => list.name === block.listItem) && (parsedBlock.listItem = block.listItem), typeof block.level == "number" && (parsedBlock.level = block.level), parsedBlock;
328
+ return typeof block.markDefs == "object" && block.markDefs !== null && (parsedBlock.markDefs = options.removeUnusedMarkDefs ? markDefs.filter((markDef) => marks.includes(markDef._key)) : markDefs), typeof block.style == "string" && schema.styles.find((style) => style.name === block.style) && (parsedBlock.style = block.style), typeof block.listItem == "string" && schema.lists.find((list) => list.name === block.listItem) && (parsedBlock.listItem = block.listItem), typeof block.level == "number" && (parsedBlock.level = block.level), parsedBlock;
178
329
  }
179
- function parseMarkDefs({
180
- context,
330
+ function parseMarkDefsInternal({
331
+ schema,
332
+ keyGenerator,
181
333
  markDefs,
182
334
  options
183
335
  }) {
@@ -186,7 +338,7 @@ function parseMarkDefs({
186
338
  markDefs: unparsedMarkDefs.flatMap((markDef) => {
187
339
  if (!isTypedObject(markDef))
188
340
  return [];
189
- const schemaType = context.schema.annotations.find(({
341
+ const schemaType = schema.annotations.find(({
190
342
  name
191
343
  }) => name === markDef._type);
192
344
  if (!schemaType)
@@ -195,10 +347,9 @@ function parseMarkDefs({
195
347
  return [];
196
348
  const parsedAnnotation = parseObject({
197
349
  object: markDef,
198
- context: {
199
- schemaType,
200
- keyGenerator: context.keyGenerator
201
- },
350
+ schema,
351
+ keyGenerator,
352
+ schemaType,
202
353
  options
203
354
  });
204
355
  return parsedAnnotation ? (markDefKeyMap.set(markDef._key, parsedAnnotation._key), [parsedAnnotation]) : [];
@@ -206,26 +357,30 @@ function parseMarkDefs({
206
357
  markDefKeyMap
207
358
  };
208
359
  }
209
- function parseChild({
360
+ function parseChildInternal({
210
361
  child,
211
- context,
362
+ schema,
363
+ keyGenerator,
212
364
  markDefKeyMap,
213
365
  options
214
366
  }) {
215
- return parseSpan({
367
+ return parseSpanInternal({
216
368
  span: child,
217
- context,
369
+ schema,
370
+ keyGenerator,
218
371
  markDefKeyMap,
219
372
  options
220
- }) ?? parseInlineObject({
373
+ }) ?? parseInlineObjectInternal({
221
374
  inlineObject: child,
222
- context,
375
+ schema,
376
+ keyGenerator,
223
377
  options
224
378
  });
225
379
  }
226
- function parseSpan({
380
+ function parseSpanInternal({
227
381
  span,
228
- context,
382
+ schema,
383
+ keyGenerator,
229
384
  markDefKeyMap,
230
385
  options
231
386
  }) {
@@ -238,164 +393,166 @@ function parseSpan({
238
393
  if (typeof mark != "string")
239
394
  return [];
240
395
  const markDefKey = markDefKeyMap.get(mark);
241
- return markDefKey !== void 0 ? [markDefKey] : context.schema.decorators.some((decorator) => decorator.name === mark) ? [mark] : [];
396
+ return markDefKey !== void 0 ? [markDefKey] : schema.decorators.some((decorator) => decorator.name === mark) ? [mark] : [];
242
397
  });
243
- if (!(typeof span._type == "string" && span._type !== context.schema.span.name))
398
+ if (!(typeof span._type == "string" && span._type !== schema.span.name))
244
399
  return typeof span._type != "string" ? typeof span.text == "string" ? {
245
- _type: context.schema.span.name,
246
- _key: typeof span._key == "string" ? span._key : context.keyGenerator(),
400
+ _type: schema.span.name,
401
+ _key: typeof span._key == "string" ? span._key : keyGenerator(),
247
402
  text: span.text,
248
403
  marks,
249
404
  ...options.validateFields ? {} : customFields
250
405
  } : void 0 : {
251
- _type: context.schema.span.name,
252
- _key: typeof span._key == "string" ? span._key : context.keyGenerator(),
406
+ _type: schema.span.name,
407
+ _key: typeof span._key == "string" ? span._key : keyGenerator(),
253
408
  text: typeof span.text == "string" ? span.text : "",
254
409
  marks,
255
410
  ...options.validateFields ? {} : customFields
256
411
  };
257
412
  }
258
- function parseInlineObject({
413
+ function parseInlineObjectInternal({
259
414
  inlineObject,
260
- context,
415
+ schema,
416
+ keyGenerator,
261
417
  options
262
418
  }) {
263
419
  if (!isTypedObject(inlineObject))
264
420
  return;
265
- const schemaType = context.schema.inlineObjects.find(({
421
+ const schemaType = schema.inlineObjects.find(({
266
422
  name
267
423
  }) => name === inlineObject._type);
268
424
  if (schemaType)
269
425
  return parseObject({
270
426
  object: inlineObject,
271
- context: {
272
- keyGenerator: context.keyGenerator,
273
- schemaType
274
- },
427
+ schema,
428
+ keyGenerator,
429
+ schemaType,
275
430
  options
276
431
  });
277
432
  }
278
433
  function parseAnnotation({
279
434
  annotation,
280
- context,
435
+ schema,
436
+ keyGenerator,
281
437
  options
282
438
  }) {
283
439
  if (!isTypedObject(annotation))
284
440
  return;
285
- const schemaType = context.schema.annotations.find(({
441
+ const schemaType = schema.annotations.find(({
286
442
  name
287
443
  }) => name === annotation._type);
288
444
  if (schemaType)
289
445
  return parseObject({
290
446
  object: annotation,
291
- context: {
292
- keyGenerator: context.keyGenerator,
293
- schemaType
294
- },
447
+ schema,
448
+ keyGenerator,
449
+ schemaType,
295
450
  options
296
451
  });
297
452
  }
453
+ function resolveOfMember(of, typeName, schema, ancestorFields) {
454
+ for (const member of of)
455
+ if (member.type !== "block") {
456
+ if (member.type === "object" && "name" in member && member.name) {
457
+ if (member.name === typeName && "fields" in member && member.fields)
458
+ return {
459
+ name: member.name,
460
+ fields: member.fields
461
+ };
462
+ continue;
463
+ }
464
+ if (member.type === typeName) {
465
+ const ancestorMatch = ancestorFields.get(typeName);
466
+ if (ancestorMatch)
467
+ return {
468
+ name: typeName,
469
+ fields: ancestorMatch
470
+ };
471
+ const rootMatch = schema.blockObjects.find((blockObject) => blockObject.name === typeName);
472
+ return rootMatch && "fields" in rootMatch && rootMatch.fields ? {
473
+ name: rootMatch.name,
474
+ fields: rootMatch.fields
475
+ } : void 0;
476
+ }
477
+ }
478
+ }
298
479
  function parseObject({
299
480
  object,
300
- context,
481
+ schema,
482
+ keyGenerator,
483
+ schemaType,
484
+ ancestorFields,
301
485
  options
302
486
  }) {
303
487
  const {
304
- _type,
305
488
  _key,
306
489
  ...customFields
307
- } = object, values = options.validateFields ? context.schemaType.fields.reduce((fieldValues, field) => {
308
- const fieldValue = object[field.name];
309
- return fieldValue !== void 0 && (fieldValues[field.name] = fieldValue), fieldValues;
310
- }, {}) : customFields;
490
+ } = object, fieldsByName = new Map(schemaType.fields.map((field) => [field.name, field])), nextAncestors = new Map(ancestorFields ?? []);
491
+ nextAncestors.set(schemaType.name, schemaType.fields);
492
+ const values = {};
493
+ for (const [key, value] of Object.entries(customFields)) {
494
+ if (key === "_type" || value === void 0)
495
+ continue;
496
+ const field = fieldsByName.get(key);
497
+ if (!(options.validateFields && !field)) {
498
+ if (field && field.type === "array" && field.of && Array.isArray(value)) {
499
+ values[key] = parseContainerFieldValue({
500
+ schema,
501
+ keyGenerator,
502
+ of: field.of,
503
+ value,
504
+ ancestorFields: nextAncestors,
505
+ options
506
+ });
507
+ continue;
508
+ }
509
+ values[key] = value;
510
+ }
511
+ }
311
512
  return {
312
- _type: context.schemaType.name,
313
- _key: typeof object._key == "string" ? object._key : context.keyGenerator(),
513
+ _type: schemaType.name,
514
+ _key: typeof _key == "string" ? _key : keyGenerator(),
314
515
  ...values
315
516
  };
316
517
  }
317
- function blockOffsetToSpanSelectionPoint({
318
- context,
319
- blockOffset,
320
- direction
518
+ function parseContainerFieldValue({
519
+ schema,
520
+ keyGenerator,
521
+ of,
522
+ value,
523
+ ancestorFields,
524
+ options
321
525
  }) {
322
- let offsetLeft = blockOffset.offset, selectionPoint, skippedInlineObject = !1;
323
- for (const block of context.value)
324
- if (block._key === blockOffset.path[0]._key && isTextBlock(context, block))
325
- for (const child of block.children) {
326
- if (direction === "forward") {
327
- if (!isSpan(context, child))
328
- continue;
329
- if (offsetLeft <= child.text.length) {
330
- selectionPoint = {
331
- path: [...blockOffset.path, "children", {
332
- _key: child._key
333
- }],
334
- offset: offsetLeft
335
- };
336
- break;
337
- }
338
- offsetLeft -= child.text.length;
339
- continue;
340
- }
341
- if (!isSpan(context, child)) {
342
- skippedInlineObject = !0;
343
- continue;
344
- }
345
- if (offsetLeft === 0 && selectionPoint && !skippedInlineObject) {
346
- skippedInlineObject && (selectionPoint = {
347
- path: [...blockOffset.path, "children", {
348
- _key: child._key
349
- }],
350
- offset: 0
351
- });
352
- break;
526
+ const childBlockSubSchema = of.some((member) => member.type === "block") ? getSubSchema(schema, of) : void 0;
527
+ return value.flatMap((item) => {
528
+ if (!isTypedObject(item))
529
+ return [item];
530
+ if (childBlockSubSchema && item._type === childBlockSubSchema.block.name) {
531
+ const parsed = parseTextBlock({
532
+ block: item,
533
+ schema: childBlockSubSchema,
534
+ keyGenerator,
535
+ options: {
536
+ normalize: !1,
537
+ removeUnusedMarkDefs: !1,
538
+ validateFields: options.validateFields
353
539
  }
354
- if (offsetLeft > child.text.length) {
355
- offsetLeft -= child.text.length;
356
- continue;
357
- }
358
- if (offsetLeft <= child.text.length && (selectionPoint = {
359
- path: [...blockOffset.path, "children", {
360
- _key: child._key
361
- }],
362
- offset: offsetLeft
363
- }, offsetLeft -= child.text.length, offsetLeft !== 0))
364
- break;
365
- }
366
- return selectionPoint;
367
- }
368
- function spanSelectionPointToBlockOffset({
369
- context,
370
- selectionPoint
371
- }) {
372
- let offset = 0;
373
- const blockKey = getBlockKeyFromSelectionPoint(selectionPoint), spanKey = getChildKeyFromSelectionPoint(selectionPoint);
374
- if (!(!blockKey || !spanKey)) {
375
- for (const block of context.value)
376
- if (block._key === blockKey && isTextBlock(context, block)) {
377
- for (const child of block.children)
378
- if (isSpan(context, child)) {
379
- if (child._key === spanKey)
380
- return {
381
- path: [{
382
- _key: block._key
383
- }],
384
- offset: offset + selectionPoint.offset
385
- };
386
- offset += child.text.length;
387
- }
388
- }
389
- }
390
- }
391
- function getSelectionEndPoint(selection) {
392
- return selection ? selection.backward ? selection.anchor : selection.focus : null;
393
- }
394
- function getSelectionStartPoint(selection) {
395
- return selection ? selection.backward ? selection.focus : selection.anchor : null;
396
- }
397
- function isEqualSelectionPoints(a, b) {
398
- return a.offset === b.offset && isEqualPaths(a.path, b.path);
540
+ });
541
+ return parsed ? [parsed] : [];
542
+ }
543
+ const schemaType = resolveOfMember(of, item._type, schema, ancestorFields);
544
+ return schemaType ? [parseObject({
545
+ object: item,
546
+ schema,
547
+ keyGenerator,
548
+ schemaType: {
549
+ name: schemaType.name,
550
+ fields: schemaType.fields
551
+ },
552
+ ancestorFields,
553
+ options
554
+ })] : [item];
555
+ });
399
556
  }
400
557
  const defaultKeyGenerator = () => randomKey(12), getByteHexTable = /* @__PURE__ */ (() => {
401
558
  let table;
@@ -501,59 +658,51 @@ function sliceBlocks({
501
658
  break;
502
659
  }
503
660
  startBlock && middleBlocks.push(parseBlock({
504
- context: {
505
- schema: context.schema,
506
- keyGenerator: context.keyGenerator ?? defaultKeyGenerator
507
- },
661
+ keyGenerator: context.keyGenerator ?? defaultKeyGenerator,
508
662
  block,
509
663
  options: {
510
664
  normalize: !1,
511
665
  removeUnusedMarkDefs: !0,
512
666
  validateFields: !1
513
- }
667
+ },
668
+ schema: context.schema
514
669
  }) ?? block);
515
670
  }
516
671
  const parsedStartBlock = startBlock ? parseBlock({
517
- context: {
518
- schema: context.schema,
519
- keyGenerator: context.keyGenerator ?? defaultKeyGenerator
520
- },
672
+ keyGenerator: context.keyGenerator ?? defaultKeyGenerator,
521
673
  block: startBlock,
522
674
  options: {
523
675
  normalize: !1,
524
676
  removeUnusedMarkDefs: !0,
525
677
  validateFields: !1
526
- }
527
- }) : void 0, parsedEndBlock = endBlock ? parseBlock({
528
- context: {
529
- schema: context.schema,
530
- keyGenerator: context.keyGenerator ?? defaultKeyGenerator
531
678
  },
679
+ schema: context.schema
680
+ }) : void 0, parsedEndBlock = endBlock ? parseBlock({
681
+ keyGenerator: context.keyGenerator ?? defaultKeyGenerator,
532
682
  block: endBlock,
533
683
  options: {
534
684
  normalize: !1,
535
685
  removeUnusedMarkDefs: !0,
536
686
  validateFields: !1
537
- }
687
+ },
688
+ schema: context.schema
538
689
  }) : void 0;
539
690
  return [...parsedStartBlock ? [parsedStartBlock] : [], ...middleBlocks, ...parsedEndBlock ? [parsedEndBlock] : []];
540
691
  }
541
692
  export {
542
693
  blockOffsetToSpanSelectionPoint,
543
694
  defaultKeyGenerator,
695
+ getAncestorTextBlock,
544
696
  getBlockEndPoint,
545
697
  getBlockKeyFromSelectionPoint,
546
698
  getBlockStartPoint,
547
- getChildKeyFromSelectionPoint,
548
699
  getSelectionEndPoint,
549
700
  getSelectionStartPoint,
550
701
  isEqualPathSegments,
551
702
  isEqualPaths,
552
703
  isEqualSelectionPoints,
553
- isKeyedSegment,
554
704
  isListBlock,
555
705
  isSelectionCollapsed,
556
- isTypedObject,
557
706
  parseAnnotation,
558
707
  parseBlock,
559
708
  parseBlocks,