@portabletext/editor 1.7.1 → 1.9.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.
package/lib/index.js CHANGED
@@ -296,6 +296,21 @@ const breakingBlockObject = {
296
296
  blockObjects: coreBlockObjectBehaviors,
297
297
  lists: coreListBehaviors
298
298
  };
299
+ function isPortableTextSpan(node) {
300
+ return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
301
+ }
302
+ function isPortableTextBlock(node) {
303
+ return (
304
+ // A block doesn't _have_ to be named 'block' - to differentiate between
305
+ // allowed child types and marks, one might name them differently
306
+ typeof node._type == "string" && // Toolkit-types like nested spans are @-prefixed
307
+ node._type[0] !== "@" && // `markDefs` isn't _required_ per say, but if it's there, it needs to be an array
308
+ (!("markDefs" in node) || !node.markDefs || Array.isArray(node.markDefs) && // Every mark definition needs to have an `_key` to be mappable in child spans
309
+ node.markDefs.every((def) => typeof def._key == "string")) && // `children` is required and needs to be an array
310
+ "children" in node && Array.isArray(node.children) && // All children are objects with `_type` (usually spans, but can contain other stuff)
311
+ node.children.every((child) => typeof child == "object" && "_type" in child)
312
+ );
313
+ }
299
314
  function createMarkdownBehaviors(config) {
300
315
  const automaticBlockquoteOnSpace = {
301
316
  on: "insert text",
@@ -308,7 +323,7 @@ function createMarkdownBehaviors(config) {
308
323
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
309
324
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
310
325
  return !1;
311
- const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle(context.schema);
326
+ const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle?.(context.schema);
312
327
  return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
313
328
  focusTextBlock,
314
329
  focusSpan,
@@ -343,6 +358,48 @@ function createMarkdownBehaviors(config) {
343
358
  }
344
359
  }
345
360
  }]]
361
+ }, automaticBreak = {
362
+ on: "insert text",
363
+ guard: ({
364
+ context,
365
+ event
366
+ }) => {
367
+ if (event.text !== "-")
368
+ return !1;
369
+ const breakObject = config.mapBreakObject?.(context.schema), focusBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context);
370
+ if (!breakObject || !focusBlock || !selectionCollapsed)
371
+ return !1;
372
+ const onlyText = focusBlock.node.children.every(isPortableTextSpan), blockText = focusBlock.node.children.map((child) => child.text ?? "").join("");
373
+ return onlyText && blockText === "--" ? {
374
+ breakObject,
375
+ focusBlock
376
+ } : !1;
377
+ },
378
+ actions: [() => [{
379
+ type: "insert text",
380
+ text: "-"
381
+ }], (_, {
382
+ breakObject,
383
+ focusBlock
384
+ }) => [{
385
+ type: "insert block object",
386
+ ...breakObject
387
+ }, {
388
+ type: "delete",
389
+ selection: {
390
+ anchor: {
391
+ path: focusBlock.path,
392
+ offset: 0
393
+ },
394
+ focus: {
395
+ path: focusBlock.path,
396
+ offset: 0
397
+ }
398
+ }
399
+ }, {
400
+ type: "insert text block",
401
+ decorators: []
402
+ }]]
346
403
  }, automaticHeadingOnSpace = {
347
404
  on: "insert text",
348
405
  guard: ({
@@ -357,7 +414,7 @@ function createMarkdownBehaviors(config) {
357
414
  const markdownHeadingSearch = /^#+/.exec(focusSpan.node.text), headingLevel = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
358
415
  if (context.selection.focus.offset !== headingLevel)
359
416
  return !1;
360
- const headingStyle = headingLevel !== void 0 ? config.mapHeadingStyle(context.schema, headingLevel) : void 0;
417
+ const headingStyle = headingLevel !== void 0 ? config.mapHeadingStyle?.(context.schema, headingLevel) : void 0;
361
418
  return headingLevel !== void 0 && headingStyle !== void 0 ? {
362
419
  focusTextBlock,
363
420
  focusSpan,
@@ -402,7 +459,7 @@ function createMarkdownBehaviors(config) {
402
459
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
403
460
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
404
461
  return !1;
405
- const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.mapDefaultStyle(context.schema);
462
+ const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.mapDefaultStyle?.(context.schema);
406
463
  return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
407
464
  defaultStyle,
408
465
  focusTextBlock
@@ -427,7 +484,7 @@ function createMarkdownBehaviors(config) {
427
484
  const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
428
485
  if (!selectionCollapsed || !focusTextBlock || !focusSpan)
429
486
  return !1;
430
- const defaultStyle = config.mapDefaultStyle(context.schema), looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle(context.schema), caretAtTheEndOfUnorderedList = context.selection.focus.offset === 1;
487
+ const defaultStyle = config.mapDefaultStyle?.(context.schema), looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle?.(context.schema), caretAtTheEndOfUnorderedList = context.selection.focus.offset === 1;
431
488
  if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
432
489
  return {
433
490
  focusTextBlock,
@@ -436,7 +493,7 @@ function createMarkdownBehaviors(config) {
436
493
  listItemLength: 1,
437
494
  style: defaultStyle
438
495
  };
439
- const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle(context.schema), caretAtTheEndOfOrderedList = context.selection.focus.offset === 2;
496
+ const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle?.(context.schema), caretAtTheEndOfOrderedList = context.selection.focus.offset === 2;
440
497
  return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
441
498
  focusTextBlock,
442
499
  focusSpan,
@@ -474,7 +531,66 @@ function createMarkdownBehaviors(config) {
474
531
  }
475
532
  }]]
476
533
  };
477
- return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, clearStyleOnBackspace, automaticListOnSpace];
534
+ return [automaticBlockquoteOnSpace, automaticBreak, automaticHeadingOnSpace, clearStyleOnBackspace, automaticListOnSpace];
535
+ }
536
+ function createLinkBehaviors(config) {
537
+ const pasteLinkOnSelection = {
538
+ on: "paste",
539
+ guard: ({
540
+ context,
541
+ event
542
+ }) => {
543
+ const selectionCollapsed = selectionIsCollapsed(context), text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.mapLinkAnnotation?.({
544
+ url,
545
+ schema: context.schema
546
+ }) : void 0;
547
+ return annotation && !selectionCollapsed ? {
548
+ annotation
549
+ } : !1;
550
+ },
551
+ actions: [(_, {
552
+ annotation
553
+ }) => [{
554
+ type: "annotation.add",
555
+ annotation
556
+ }]]
557
+ }, pasteLinkAtCaret = {
558
+ on: "paste",
559
+ guard: ({
560
+ context,
561
+ event
562
+ }) => {
563
+ const focusSpan = getFocusSpan(context), selectionCollapsed = selectionIsCollapsed(context);
564
+ if (!focusSpan || !selectionCollapsed)
565
+ return !1;
566
+ const text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.mapLinkAnnotation?.({
567
+ url,
568
+ schema: context.schema
569
+ }) : void 0;
570
+ return url && annotation && selectionCollapsed ? {
571
+ focusSpan,
572
+ annotation,
573
+ url
574
+ } : !1;
575
+ },
576
+ actions: [(_, {
577
+ annotation,
578
+ url
579
+ }) => [{
580
+ type: "insert span",
581
+ text: url,
582
+ annotations: [annotation]
583
+ }]]
584
+ };
585
+ return [pasteLinkOnSelection, pasteLinkAtCaret];
586
+ }
587
+ function looksLikeUrl(text) {
588
+ let looksLikeUrl2 = !1;
589
+ try {
590
+ new URL(text), looksLikeUrl2 = !0;
591
+ } catch {
592
+ }
593
+ return looksLikeUrl2;
478
594
  }
479
595
  function getPortableTextMemberSchemaTypes(portableTextType) {
480
596
  if (!portableTextType)
@@ -3904,21 +4020,6 @@ function createWithPortableTextLists(types2) {
3904
4020
  }, editor;
3905
4021
  };
3906
4022
  }
3907
- function isPortableTextSpan(node) {
3908
- return node._type === "span" && "text" in node && typeof node.text == "string" && (typeof node.marks > "u" || Array.isArray(node.marks) && node.marks.every((mark) => typeof mark == "string"));
3909
- }
3910
- function isPortableTextBlock(node) {
3911
- return (
3912
- // A block doesn't _have_ to be named 'block' - to differentiate between
3913
- // allowed child types and marks, one might name them differently
3914
- typeof node._type == "string" && // Toolkit-types like nested spans are @-prefixed
3915
- node._type[0] !== "@" && // `markDefs` isn't _required_ per say, but if it's there, it needs to be an array
3916
- (!("markDefs" in node) || !node.markDefs || Array.isArray(node.markDefs) && // Every mark definition needs to have an `_key` to be mappable in child spans
3917
- node.markDefs.every((def) => typeof def._key == "string")) && // `children` is required and needs to be an array
3918
- "children" in node && Array.isArray(node.children) && // All children are objects with `_type` (usually spans, but can contain other stuff)
3919
- node.children.every((child) => typeof child == "object" && "_type" in child)
3920
- );
3921
- }
3922
4023
  function getPreviousSpan({
3923
4024
  editor,
3924
4025
  blockPath,
@@ -4405,11 +4506,11 @@ function isDecoratorActive({
4405
4506
  }) {
4406
4507
  if (!editor.selection)
4407
4508
  return !1;
4408
- const selectedNodes = Array.from(slate.Editor.nodes(editor, {
4509
+ const selectedTextNodes = Array.from(slate.Editor.nodes(editor, {
4409
4510
  match: slate.Text.isText,
4410
4511
  at: editor.selection
4411
4512
  }));
4412
- return slate.Range.isExpanded(editor.selection) ? selectedNodes.every((n) => {
4513
+ return selectedTextNodes.length === 0 ? !1 : slate.Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
4413
4514
  const [node] = n;
4414
4515
  return node.marks?.includes(decorator);
4415
4516
  }) : ({
@@ -4731,32 +4832,18 @@ function createEditableAPI(editor, editorActor) {
4731
4832
  at: editor.selection
4732
4833
  }), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path || [];
4733
4834
  },
4734
- insertBlock: (type, value) => {
4735
- const block = toSlateValue([{
4736
- _key: editorActor.getSnapshot().context.keyGenerator(),
4737
- _type: type.name,
4738
- ...value || {}
4739
- }], {
4740
- schemaTypes: editorActor.getSnapshot().context.schema
4741
- })[0];
4742
- if (!editor.selection) {
4743
- const lastBlock = Array.from(slate.Editor.nodes(editor, {
4744
- match: (n) => !slate.Editor.isEditor(n),
4745
- at: [],
4746
- reverse: !0
4747
- }))[0];
4748
- return slate.Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], types2) && slate.Transforms.removeNodes(editor, {
4749
- at: lastBlock[1]
4750
- }), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path ?? [];
4835
+ insertBlock: (type, value) => insertBlockObjectActionImplementation({
4836
+ context: {
4837
+ keyGenerator: editorActor.getSnapshot().context.keyGenerator,
4838
+ schema: types2
4839
+ },
4840
+ action: {
4841
+ type: "insert block object",
4842
+ name: type.name,
4843
+ value,
4844
+ editor
4751
4845
  }
4752
- const focusBlock = Array.from(slate.Editor.nodes(editor, {
4753
- at: editor.selection.focus.path.slice(0, 1),
4754
- match: (n) => n._type === types2.block.name
4755
- }))[0];
4756
- return slate.Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock[0]], types2) && slate.Transforms.removeNodes(editor, {
4757
- at: focusBlock[1]
4758
- }), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path || [];
4759
- },
4846
+ }),
4760
4847
  hasBlockStyle: (style) => {
4761
4848
  try {
4762
4849
  return editor.pteHasBlockStyle(style);
@@ -4926,6 +5013,35 @@ function createEditableAPI(editor, editorActor) {
4926
5013
  }
4927
5014
  };
4928
5015
  }
5016
+ const insertBlockObjectActionImplementation = ({
5017
+ context,
5018
+ action
5019
+ }) => {
5020
+ const editor = action.editor, types2 = context.schema, block = toSlateValue([{
5021
+ _key: context.keyGenerator(),
5022
+ _type: action.name,
5023
+ ...action.value ? action.value : {}
5024
+ }], {
5025
+ schemaTypes: context.schema
5026
+ })[0];
5027
+ if (!editor.selection) {
5028
+ const lastBlock = Array.from(slate.Editor.nodes(editor, {
5029
+ match: (n) => !slate.Editor.isEditor(n),
5030
+ at: [],
5031
+ reverse: !0
5032
+ }))[0];
5033
+ return slate.Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], types2) && slate.Transforms.removeNodes(editor, {
5034
+ at: lastBlock[1]
5035
+ }), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path ?? [];
5036
+ }
5037
+ const focusBlock = Array.from(slate.Editor.nodes(editor, {
5038
+ at: editor.selection.focus.path.slice(0, 1),
5039
+ match: (n) => n._type === types2.block.name
5040
+ }))[0];
5041
+ return slate.Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock[0]], types2) && slate.Transforms.removeNodes(editor, {
5042
+ at: focusBlock[1]
5043
+ }), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types2.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types2)?.focus.path || [];
5044
+ };
4929
5045
  function isAnnotationActive({
4930
5046
  editor,
4931
5047
  annotation
@@ -5222,6 +5338,35 @@ const addAnnotationActionImplementation = ({
5222
5338
  type: "insert break"
5223
5339
  }
5224
5340
  });
5341
+ }, insertSpanActionImplementation = ({
5342
+ context,
5343
+ action
5344
+ }) => {
5345
+ if (!action.editor.selection) {
5346
+ console.error("Unable to perform action without selection", action);
5347
+ return;
5348
+ }
5349
+ const [focusBlock, focusBlockPath] = Array.from(slate.Editor.nodes(action.editor, {
5350
+ at: action.editor.selection.focus.path,
5351
+ match: (node) => action.editor.isTextBlock(node)
5352
+ }))[0] ?? [void 0, void 0];
5353
+ if (!focusBlock || !focusBlockPath) {
5354
+ console.error("Unable to perform action without focus block", action);
5355
+ return;
5356
+ }
5357
+ const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
5358
+ _type: annotation.name,
5359
+ _key: context.keyGenerator(),
5360
+ ...annotation.value
5361
+ })) : void 0;
5362
+ annotations && annotations.length > 0 && slate.Transforms.setNodes(action.editor, {
5363
+ markDefs: [...markDefs, ...annotations]
5364
+ }), slate.Transforms.insertNodes(action.editor, {
5365
+ _type: "span",
5366
+ _key: context.keyGenerator(),
5367
+ text: action.text,
5368
+ marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
5369
+ });
5225
5370
  }, behaviorActionImplementations = {
5226
5371
  "annotation.add": addAnnotationActionImplementation,
5227
5372
  "annotation.remove": removeAnnotationActionImplementation,
@@ -5306,8 +5451,10 @@ const addAnnotationActionImplementation = ({
5306
5451
  at: location
5307
5452
  });
5308
5453
  },
5454
+ "insert block object": insertBlockObjectActionImplementation,
5309
5455
  "insert break": insertBreakActionImplementation,
5310
5456
  "insert soft break": insertSoftBreakActionImplementation,
5457
+ "insert span": insertSpanActionImplementation,
5311
5458
  "insert text": ({
5312
5459
  action
5313
5460
  }) => {
@@ -5334,6 +5481,11 @@ const addAnnotationActionImplementation = ({
5334
5481
  }) => {
5335
5482
  action.effect();
5336
5483
  },
5484
+ paste: ({
5485
+ action
5486
+ }) => {
5487
+ action.editor.insertData(action.clipboardData);
5488
+ },
5337
5489
  select: ({
5338
5490
  action
5339
5491
  }) => {
@@ -5363,6 +5515,20 @@ function performAction({
5363
5515
  });
5364
5516
  break;
5365
5517
  }
5518
+ case "insert block object": {
5519
+ behaviorActionImplementations["insert block object"]({
5520
+ context,
5521
+ action
5522
+ });
5523
+ break;
5524
+ }
5525
+ case "insert span": {
5526
+ behaviorActionImplementations["insert span"]({
5527
+ context,
5528
+ action
5529
+ });
5530
+ break;
5531
+ }
5366
5532
  case "insert text block": {
5367
5533
  behaviorActionImplementations["insert text block"]({
5368
5534
  context,
@@ -5494,11 +5660,18 @@ function performDefaultAction({
5494
5660
  });
5495
5661
  break;
5496
5662
  }
5497
- default:
5663
+ case "insert text": {
5498
5664
  behaviorActionImplementations["insert text"]({
5499
5665
  context,
5500
5666
  action
5501
5667
  });
5668
+ break;
5669
+ }
5670
+ default:
5671
+ behaviorActionImplementations.paste({
5672
+ context,
5673
+ action
5674
+ });
5502
5675
  }
5503
5676
  }
5504
5677
  const networkLogic = xstate.fromCallback(({
@@ -6564,19 +6737,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6564
6737
  const handleCopy = react.useCallback((event) => {
6565
6738
  onCopy && onCopy(event) !== void 0 && event.preventDefault();
6566
6739
  }, [onCopy]), handlePaste = react.useCallback((event_0) => {
6567
- if (event_0.preventDefault(), !slateEditor.selection)
6568
- return;
6569
- if (!onPaste) {
6570
- debug("Pasting normally"), slateEditor.insertData(event_0.clipboardData);
6571
- return;
6572
- }
6573
- const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste({
6740
+ const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
6574
6741
  event: event_0,
6575
6742
  value: value_0,
6576
6743
  path,
6577
6744
  schemaTypes
6578
6745
  });
6579
- onPasteResult === void 0 ? (debug("No result from custom paste handler, pasting normally"), slateEditor.insertData(event_0.clipboardData)) : (editorActor.send({
6746
+ onPasteResult || !slateEditor.selection ? (event_0.preventDefault(), editorActor.send({
6580
6747
  type: "loading"
6581
6748
  }), Promise.resolve(onPasteResult).then((result_0) => {
6582
6749
  debug("Custom paste function from client resolved", result_0), !result_0 || !result_0.insert ? (debug("No result from custom paste handler, pasting normally"), slateEditor.insertData(event_0.clipboardData)) : result_0.insert ? slateEditor.insertFragment(toSlateValue(result_0.insert, {
@@ -6586,7 +6753,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6586
6753
  editorActor.send({
6587
6754
  type: "done loading"
6588
6755
  });
6589
- }));
6756
+ })) : event_0.nativeEvent.clipboardData && (event_0.preventDefault(), editorActor.send({
6757
+ type: "behavior event",
6758
+ behaviorEvent: {
6759
+ type: "paste",
6760
+ clipboardData: event_0.nativeEvent.clipboardData
6761
+ },
6762
+ editor: slateEditor
6763
+ })), debug("No result from custom paste handler, pasting normally");
6590
6764
  }, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = react.useCallback((event_1) => {
6591
6765
  if (onFocus && onFocus(event_1), !event_1.isDefaultPrevented()) {
6592
6766
  const selection = PortableTextEditor.getSelection(portableTextEditor);
@@ -6601,15 +6775,11 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6601
6775
  });
6602
6776
  }
6603
6777
  }, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = react.useCallback((event_2) => {
6604
- if (onClick && onClick(event_2), slateEditor.selection && event_2.target === event_2.currentTarget) {
6605
- const [lastBlock, path_0] = slate.Node.last(slateEditor, []), focusPath = slateEditor.selection.focus.path.slice(0, 1), lastPath = path_0.slice(0, 1);
6606
- if (slate.Path.equals(focusPath, lastPath)) {
6607
- const node = slate.Node.descendant(slateEditor, path_0.slice(0, 1));
6608
- lastBlock && slate.Editor.isVoid(slateEditor, node) && (slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
6609
- decorators: []
6610
- })), slateEditor.onChange());
6611
- }
6612
- }
6778
+ onClick && onClick(event_2);
6779
+ const focusBlockPath = slateEditor.selection ? slateEditor.selection.focus.path.slice(0, 1) : void 0, focusBlock = focusBlockPath ? slate.Node.descendant(slateEditor, focusBlockPath) : void 0, [_, lastNodePath] = slate.Node.last(slateEditor, []), lastBlockPath = lastNodePath.slice(0, 1), lastNodeFocused = focusBlockPath ? slate.Path.equals(lastBlockPath, focusBlockPath) : !1, lastBlockIsVoid = focusBlock ? !slateEditor.isTextBlock(focusBlock) : !1;
6780
+ slateEditor.selection && slate.Range.isCollapsed(slateEditor.selection) && lastNodeFocused && lastBlockIsVoid && (slate.Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
6781
+ decorators: []
6782
+ })), slateEditor.onChange());
6613
6783
  }, [onClick, slateEditor]), handleOnBlur = react.useCallback((event_3) => {
6614
6784
  onBlur && onBlur(event_3), event_3.isPropagationStopped() || editorActor.send({
6615
6785
  type: "blur",
@@ -6657,7 +6827,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6657
6827
  return scrollSelectionIntoView === null ? noop__default.default : (_editor, domRange) => {
6658
6828
  scrollSelectionIntoView(portableTextEditor, domRange);
6659
6829
  };
6660
- }, [portableTextEditor, scrollSelectionIntoView]), decorate = react.useCallback(([, path_1]) => {
6830
+ }, [portableTextEditor, scrollSelectionIntoView]), decorate = react.useCallback(([, path_0]) => {
6661
6831
  if (isEqualToEmptyEditor(slateEditor.children, schemaTypes))
6662
6832
  return [{
6663
6833
  anchor: {
@@ -6670,18 +6840,18 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
6670
6840
  },
6671
6841
  placeholder: !0
6672
6842
  }];
6673
- if (path_1.length === 0)
6843
+ if (path_0.length === 0)
6674
6844
  return [];
6675
- const result_1 = rangeDecorationState.filter((item) => slate.Range.isCollapsed(item) ? path_1.length !== 2 ? !1 : slate.Path.equals(item.focus.path, path_1) && slate.Path.equals(item.anchor.path, path_1) : slate.Range.intersection(item, {
6845
+ const result_1 = rangeDecorationState.filter((item) => slate.Range.isCollapsed(item) ? path_0.length !== 2 ? !1 : slate.Path.equals(item.focus.path, path_0) && slate.Path.equals(item.anchor.path, path_0) : slate.Range.intersection(item, {
6676
6846
  anchor: {
6677
- path: path_1,
6847
+ path: path_0,
6678
6848
  offset: 0
6679
6849
  },
6680
6850
  focus: {
6681
- path: path_1,
6851
+ path: path_0,
6682
6852
  offset: 0
6683
6853
  }
6684
- }) || slate.Range.includes(item, path_1));
6854
+ }) || slate.Range.includes(item, path_0));
6685
6855
  return result_1.length > 0 ? result_1 : [];
6686
6856
  }, [slateEditor, schemaTypes, rangeDecorationState]);
6687
6857
  return react.useEffect(() => {
@@ -6751,6 +6921,7 @@ exports.PortableTextEditable = PortableTextEditable;
6751
6921
  exports.PortableTextEditor = PortableTextEditor;
6752
6922
  exports.coreBehavior = coreBehavior;
6753
6923
  exports.coreBehaviors = coreBehaviors;
6924
+ exports.createLinkBehaviors = createLinkBehaviors;
6754
6925
  exports.createMarkdownBehaviors = createMarkdownBehaviors;
6755
6926
  exports.defineBehavior = defineBehavior;
6756
6927
  exports.defineSchema = defineSchema;