@portabletext/editor 1.40.3 → 1.40.4

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.
@@ -312,6 +312,65 @@ function fromSlateValue(value, textBlockType, keyMap = {}) {
312
312
  function isEqualToEmptyEditor(children, schemaTypes) {
313
313
  return children === void 0 || children && Array.isArray(children) && children.length === 0 || children && Array.isArray(children) && children.length === 1 && slate.Element.isElement(children[0]) && children[0]._type === schemaTypes.block.name && "style" in children[0] && children[0].style === schemaTypes.styles[0].value && !("listItem" in children[0]) && Array.isArray(children[0].children) && children[0].children.length === 1 && slate.Text.isText(children[0].children[0]) && children[0].children[0]._type === "span" && !children[0].children[0].marks?.join("") && children[0].children[0].text === "";
314
314
  }
315
+ function getFocusBlock({
316
+ editor
317
+ }) {
318
+ return editor.selection ? Array.from(slate.Editor.nodes(editor, {
319
+ at: editor.selection.focus.path.slice(0, 1),
320
+ match: (n) => !slate.Editor.isEditor(n)
321
+ })).at(0) ?? [void 0, void 0] : [void 0, void 0];
322
+ }
323
+ function getFocusChild({
324
+ editor
325
+ }) {
326
+ const [focusBlock, focusBlockPath] = getFocusBlock({
327
+ editor
328
+ }), childIndex = editor.selection?.focus.path.at(1);
329
+ if (!focusBlock || !focusBlockPath || childIndex === void 0)
330
+ return [void 0, void 0];
331
+ const focusChild = slate.Node.child(focusBlock, childIndex);
332
+ return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
333
+ }
334
+ function getLastBlock({
335
+ editor
336
+ }) {
337
+ return Array.from(slate.Editor.nodes(editor, {
338
+ match: (n) => !slate.Editor.isEditor(n),
339
+ at: [],
340
+ reverse: !0
341
+ })).at(0) ?? [void 0, void 0];
342
+ }
343
+ function getNodeBlock({
344
+ editor,
345
+ schema: schema2,
346
+ node
347
+ }) {
348
+ if (slate.Editor.isEditor(node))
349
+ return;
350
+ if (isBlockElement(schema2, node))
351
+ return elementToBlock({
352
+ schema: schema2,
353
+ element: node
354
+ });
355
+ const parent = Array.from(slate.Editor.nodes(editor, {
356
+ mode: "highest",
357
+ at: [],
358
+ match: (n) => isBlockElement(schema2, n) && n.children.some((child) => child._key === node._key)
359
+ })).at(0)?.at(0);
360
+ return slate.Element.isElement(parent) ? elementToBlock({
361
+ schema: schema2,
362
+ element: parent
363
+ }) : void 0;
364
+ }
365
+ function elementToBlock({
366
+ schema: schema2,
367
+ element
368
+ }) {
369
+ return fromSlateValue([element], schema2.block.name)?.at(0);
370
+ }
371
+ function isBlockElement(schema2, node) {
372
+ return slate.Element.isElement(node) && (schema2.block.name === node._type || schema2.blockObjects.some((blockObject) => blockObject.name === node._type));
373
+ }
315
374
  const IS_PROCESSING_REMOTE_CHANGES = /* @__PURE__ */ new WeakMap(), KEY_TO_SLATE_ELEMENT = /* @__PURE__ */ new WeakMap(), KEY_TO_VALUE_ELEMENT = /* @__PURE__ */ new WeakMap(), SLATE_TO_PORTABLE_TEXT_RANGE = /* @__PURE__ */ new WeakMap(), EditorActorContext = React.createContext({}), PortableTextEditorContext = React.createContext(null), usePortableTextEditor = () => {
316
375
  const editor = React.useContext(PortableTextEditorContext);
317
376
  if (!editor)
@@ -4271,36 +4330,7 @@ const addAnnotationActionImplementation = ({
4271
4330
  action
4272
4331
  }) => {
4273
4332
  console.warn(`Deserialization of ${action.mimeType} failed with reason "${action.reason}"`);
4274
- };
4275
- function getFocusBlock({
4276
- editor
4277
- }) {
4278
- return editor.selection ? Array.from(slate.Editor.nodes(editor, {
4279
- at: editor.selection.focus.path.slice(0, 1),
4280
- match: (n) => !slate.Editor.isEditor(n)
4281
- })).at(0) ?? [void 0, void 0] : [void 0, void 0];
4282
- }
4283
- function getFocusChild({
4284
- editor
4285
- }) {
4286
- const [focusBlock, focusBlockPath] = getFocusBlock({
4287
- editor
4288
- }), childIndex = editor.selection?.focus.path.at(1);
4289
- if (!focusBlock || !focusBlockPath || childIndex === void 0)
4290
- return [void 0, void 0];
4291
- const focusChild = slate.Node.child(focusBlock, childIndex);
4292
- return focusChild ? [focusChild, [...focusBlockPath, childIndex]] : [void 0, void 0];
4293
- }
4294
- function getLastBlock({
4295
- editor
4296
- }) {
4297
- return Array.from(slate.Editor.nodes(editor, {
4298
- match: (n) => !slate.Editor.isEditor(n),
4299
- at: [],
4300
- reverse: !0
4301
- })).at(0) ?? [void 0, void 0];
4302
- }
4303
- const insertBlockActionImplementation = ({
4333
+ }, insertBlockActionImplementation = ({
4304
4334
  context,
4305
4335
  action
4306
4336
  }) => {
@@ -4588,15 +4618,17 @@ const selectActionImplementation = ({
4588
4618
  editor: action.editor,
4589
4619
  schema: context.schema
4590
4620
  }), index++;
4591
- } else
4621
+ } else {
4622
+ let index = 0;
4592
4623
  for (const block of fragment)
4593
4624
  insertBlock({
4594
4625
  block,
4595
- placement: "auto",
4626
+ placement: index === 0 ? "auto" : "after",
4596
4627
  select: "end",
4597
4628
  editor: action.editor,
4598
4629
  schema: context.schema
4599
- });
4630
+ }), index++;
4631
+ }
4600
4632
  }, deserializationSuccessActionImplementation = ({
4601
4633
  context,
4602
4634
  action
@@ -7672,6 +7704,7 @@ exports.defaultKeyGenerator = defaultKeyGenerator;
7672
7704
  exports.defineSchema = defineSchema;
7673
7705
  exports.fromSlateValue = fromSlateValue;
7674
7706
  exports.getEditorSnapshot = getEditorSnapshot;
7707
+ exports.getNodeBlock = getNodeBlock;
7675
7708
  exports.isEqualToEmptyEditor = isEqualToEmptyEditor;
7676
7709
  exports.moveRangeByOperation = moveRangeByOperation;
7677
7710
  exports.toPortableTextRange = toPortableTextRange;