@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.d.mts +97 -23
- package/lib/index.d.ts +97 -23
- package/lib/index.esm.js +244 -73
- package/lib/index.esm.js.map +1 -1
- package/lib/index.js +244 -73
- package/lib/index.js.map +1 -1
- package/lib/index.mjs +244 -73
- package/lib/index.mjs.map +1 -1
- package/package.json +10 -10
- package/src/editor/Editable.tsx +46 -31
- package/src/editor/behavior/behavior.action.insert-span.ts +48 -0
- package/src/editor/behavior/behavior.actions.ts +29 -1
- package/src/editor/behavior/behavior.links.ts +91 -0
- package/src/editor/behavior/behavior.markdown.ts +78 -11
- package/src/editor/behavior/behavior.types.ts +18 -0
- package/src/editor/plugins/createWithEditableAPI.ts +91 -71
- package/src/editor/plugins/createWithPortableTextMarkModel.ts +6 -2
- package/src/editor/plugins/with-plugins.ts +7 -2
- package/src/index.ts +5 -1
- package/src/types/options.ts +0 -9
- package/src/utils/__tests__/operationToPatches.test.ts +1 -1
- package/src/utils/__tests__/patchToOperations.test.ts +1 -1
package/lib/index.mjs
CHANGED
|
@@ -317,6 +317,21 @@ const breakingBlockObject = {
|
|
|
317
317
|
blockObjects: coreBlockObjectBehaviors,
|
|
318
318
|
lists: coreListBehaviors
|
|
319
319
|
};
|
|
320
|
+
function isPortableTextSpan(node) {
|
|
321
|
+
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"));
|
|
322
|
+
}
|
|
323
|
+
function isPortableTextBlock(node) {
|
|
324
|
+
return (
|
|
325
|
+
// A block doesn't _have_ to be named 'block' - to differentiate between
|
|
326
|
+
// allowed child types and marks, one might name them differently
|
|
327
|
+
typeof node._type == "string" && // Toolkit-types like nested spans are @-prefixed
|
|
328
|
+
node._type[0] !== "@" && // `markDefs` isn't _required_ per say, but if it's there, it needs to be an array
|
|
329
|
+
(!("markDefs" in node) || !node.markDefs || Array.isArray(node.markDefs) && // Every mark definition needs to have an `_key` to be mappable in child spans
|
|
330
|
+
node.markDefs.every((def) => typeof def._key == "string")) && // `children` is required and needs to be an array
|
|
331
|
+
"children" in node && Array.isArray(node.children) && // All children are objects with `_type` (usually spans, but can contain other stuff)
|
|
332
|
+
node.children.every((child) => typeof child == "object" && "_type" in child)
|
|
333
|
+
);
|
|
334
|
+
}
|
|
320
335
|
function createMarkdownBehaviors(config) {
|
|
321
336
|
const automaticBlockquoteOnSpace = {
|
|
322
337
|
on: "insert text",
|
|
@@ -329,7 +344,7 @@ function createMarkdownBehaviors(config) {
|
|
|
329
344
|
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
330
345
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
331
346
|
return !1;
|
|
332
|
-
const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle(context.schema);
|
|
347
|
+
const caretAtTheEndOfQuote = context.selection.focus.offset === 1, looksLikeMarkdownQuote = /^>/.test(focusSpan.node.text), blockquoteStyle = config.mapBlockquoteStyle?.(context.schema);
|
|
333
348
|
return caretAtTheEndOfQuote && looksLikeMarkdownQuote && blockquoteStyle !== void 0 ? {
|
|
334
349
|
focusTextBlock,
|
|
335
350
|
focusSpan,
|
|
@@ -364,6 +379,48 @@ function createMarkdownBehaviors(config) {
|
|
|
364
379
|
}
|
|
365
380
|
}
|
|
366
381
|
}]]
|
|
382
|
+
}, automaticBreak = {
|
|
383
|
+
on: "insert text",
|
|
384
|
+
guard: ({
|
|
385
|
+
context,
|
|
386
|
+
event
|
|
387
|
+
}) => {
|
|
388
|
+
if (event.text !== "-")
|
|
389
|
+
return !1;
|
|
390
|
+
const breakObject = config.mapBreakObject?.(context.schema), focusBlock = getFocusTextBlock(context), selectionCollapsed = selectionIsCollapsed(context);
|
|
391
|
+
if (!breakObject || !focusBlock || !selectionCollapsed)
|
|
392
|
+
return !1;
|
|
393
|
+
const onlyText = focusBlock.node.children.every(isPortableTextSpan), blockText = focusBlock.node.children.map((child) => child.text ?? "").join("");
|
|
394
|
+
return onlyText && blockText === "--" ? {
|
|
395
|
+
breakObject,
|
|
396
|
+
focusBlock
|
|
397
|
+
} : !1;
|
|
398
|
+
},
|
|
399
|
+
actions: [() => [{
|
|
400
|
+
type: "insert text",
|
|
401
|
+
text: "-"
|
|
402
|
+
}], (_, {
|
|
403
|
+
breakObject,
|
|
404
|
+
focusBlock
|
|
405
|
+
}) => [{
|
|
406
|
+
type: "insert block object",
|
|
407
|
+
...breakObject
|
|
408
|
+
}, {
|
|
409
|
+
type: "delete",
|
|
410
|
+
selection: {
|
|
411
|
+
anchor: {
|
|
412
|
+
path: focusBlock.path,
|
|
413
|
+
offset: 0
|
|
414
|
+
},
|
|
415
|
+
focus: {
|
|
416
|
+
path: focusBlock.path,
|
|
417
|
+
offset: 0
|
|
418
|
+
}
|
|
419
|
+
}
|
|
420
|
+
}, {
|
|
421
|
+
type: "insert text block",
|
|
422
|
+
decorators: []
|
|
423
|
+
}]]
|
|
367
424
|
}, automaticHeadingOnSpace = {
|
|
368
425
|
on: "insert text",
|
|
369
426
|
guard: ({
|
|
@@ -378,7 +435,7 @@ function createMarkdownBehaviors(config) {
|
|
|
378
435
|
const markdownHeadingSearch = /^#+/.exec(focusSpan.node.text), headingLevel = markdownHeadingSearch ? markdownHeadingSearch[0].length : void 0;
|
|
379
436
|
if (context.selection.focus.offset !== headingLevel)
|
|
380
437
|
return !1;
|
|
381
|
-
const headingStyle = headingLevel !== void 0 ? config.mapHeadingStyle(context.schema, headingLevel) : void 0;
|
|
438
|
+
const headingStyle = headingLevel !== void 0 ? config.mapHeadingStyle?.(context.schema, headingLevel) : void 0;
|
|
382
439
|
return headingLevel !== void 0 && headingStyle !== void 0 ? {
|
|
383
440
|
focusTextBlock,
|
|
384
441
|
focusSpan,
|
|
@@ -423,7 +480,7 @@ function createMarkdownBehaviors(config) {
|
|
|
423
480
|
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
424
481
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
425
482
|
return !1;
|
|
426
|
-
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.mapDefaultStyle(context.schema);
|
|
483
|
+
const atTheBeginningOfBLock = focusTextBlock.node.children[0]._key === focusSpan.node._key && context.selection.focus.offset === 0, defaultStyle = config.mapDefaultStyle?.(context.schema);
|
|
427
484
|
return atTheBeginningOfBLock && defaultStyle && focusTextBlock.node.style !== defaultStyle ? {
|
|
428
485
|
defaultStyle,
|
|
429
486
|
focusTextBlock
|
|
@@ -448,7 +505,7 @@ function createMarkdownBehaviors(config) {
|
|
|
448
505
|
const selectionCollapsed = selectionIsCollapsed(context), focusTextBlock = getFocusTextBlock(context), focusSpan = getFocusSpan(context);
|
|
449
506
|
if (!selectionCollapsed || !focusTextBlock || !focusSpan)
|
|
450
507
|
return !1;
|
|
451
|
-
const defaultStyle = config.mapDefaultStyle(context.schema), looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle(context.schema), caretAtTheEndOfUnorderedList = context.selection.focus.offset === 1;
|
|
508
|
+
const defaultStyle = config.mapDefaultStyle?.(context.schema), looksLikeUnorderedList = /^(-|\*)/.test(focusSpan.node.text), unorderedListStyle = config.mapUnorderedListStyle?.(context.schema), caretAtTheEndOfUnorderedList = context.selection.focus.offset === 1;
|
|
452
509
|
if (defaultStyle && caretAtTheEndOfUnorderedList && looksLikeUnorderedList && unorderedListStyle !== void 0)
|
|
453
510
|
return {
|
|
454
511
|
focusTextBlock,
|
|
@@ -457,7 +514,7 @@ function createMarkdownBehaviors(config) {
|
|
|
457
514
|
listItemLength: 1,
|
|
458
515
|
style: defaultStyle
|
|
459
516
|
};
|
|
460
|
-
const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle(context.schema), caretAtTheEndOfOrderedList = context.selection.focus.offset === 2;
|
|
517
|
+
const looksLikeOrderedList = /^1./.test(focusSpan.node.text), orderedListStyle = config.mapOrderedListStyle?.(context.schema), caretAtTheEndOfOrderedList = context.selection.focus.offset === 2;
|
|
461
518
|
return defaultStyle && caretAtTheEndOfOrderedList && looksLikeOrderedList && orderedListStyle !== void 0 ? {
|
|
462
519
|
focusTextBlock,
|
|
463
520
|
focusSpan,
|
|
@@ -495,7 +552,66 @@ function createMarkdownBehaviors(config) {
|
|
|
495
552
|
}
|
|
496
553
|
}]]
|
|
497
554
|
};
|
|
498
|
-
return [automaticBlockquoteOnSpace, automaticHeadingOnSpace, clearStyleOnBackspace, automaticListOnSpace];
|
|
555
|
+
return [automaticBlockquoteOnSpace, automaticBreak, automaticHeadingOnSpace, clearStyleOnBackspace, automaticListOnSpace];
|
|
556
|
+
}
|
|
557
|
+
function createLinkBehaviors(config) {
|
|
558
|
+
const pasteLinkOnSelection = {
|
|
559
|
+
on: "paste",
|
|
560
|
+
guard: ({
|
|
561
|
+
context,
|
|
562
|
+
event
|
|
563
|
+
}) => {
|
|
564
|
+
const selectionCollapsed = selectionIsCollapsed(context), text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.mapLinkAnnotation?.({
|
|
565
|
+
url,
|
|
566
|
+
schema: context.schema
|
|
567
|
+
}) : void 0;
|
|
568
|
+
return annotation && !selectionCollapsed ? {
|
|
569
|
+
annotation
|
|
570
|
+
} : !1;
|
|
571
|
+
},
|
|
572
|
+
actions: [(_, {
|
|
573
|
+
annotation
|
|
574
|
+
}) => [{
|
|
575
|
+
type: "annotation.add",
|
|
576
|
+
annotation
|
|
577
|
+
}]]
|
|
578
|
+
}, pasteLinkAtCaret = {
|
|
579
|
+
on: "paste",
|
|
580
|
+
guard: ({
|
|
581
|
+
context,
|
|
582
|
+
event
|
|
583
|
+
}) => {
|
|
584
|
+
const focusSpan = getFocusSpan(context), selectionCollapsed = selectionIsCollapsed(context);
|
|
585
|
+
if (!focusSpan || !selectionCollapsed)
|
|
586
|
+
return !1;
|
|
587
|
+
const text = event.clipboardData.getData("text/plain"), url = looksLikeUrl(text) ? text : void 0, annotation = url !== void 0 ? config.mapLinkAnnotation?.({
|
|
588
|
+
url,
|
|
589
|
+
schema: context.schema
|
|
590
|
+
}) : void 0;
|
|
591
|
+
return url && annotation && selectionCollapsed ? {
|
|
592
|
+
focusSpan,
|
|
593
|
+
annotation,
|
|
594
|
+
url
|
|
595
|
+
} : !1;
|
|
596
|
+
},
|
|
597
|
+
actions: [(_, {
|
|
598
|
+
annotation,
|
|
599
|
+
url
|
|
600
|
+
}) => [{
|
|
601
|
+
type: "insert span",
|
|
602
|
+
text: url,
|
|
603
|
+
annotations: [annotation]
|
|
604
|
+
}]]
|
|
605
|
+
};
|
|
606
|
+
return [pasteLinkOnSelection, pasteLinkAtCaret];
|
|
607
|
+
}
|
|
608
|
+
function looksLikeUrl(text) {
|
|
609
|
+
let looksLikeUrl2 = !1;
|
|
610
|
+
try {
|
|
611
|
+
new URL(text), looksLikeUrl2 = !0;
|
|
612
|
+
} catch {
|
|
613
|
+
}
|
|
614
|
+
return looksLikeUrl2;
|
|
499
615
|
}
|
|
500
616
|
function getPortableTextMemberSchemaTypes(portableTextType) {
|
|
501
617
|
if (!portableTextType)
|
|
@@ -3925,21 +4041,6 @@ function createWithPortableTextLists(types) {
|
|
|
3925
4041
|
}, editor;
|
|
3926
4042
|
};
|
|
3927
4043
|
}
|
|
3928
|
-
function isPortableTextSpan(node) {
|
|
3929
|
-
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"));
|
|
3930
|
-
}
|
|
3931
|
-
function isPortableTextBlock(node) {
|
|
3932
|
-
return (
|
|
3933
|
-
// A block doesn't _have_ to be named 'block' - to differentiate between
|
|
3934
|
-
// allowed child types and marks, one might name them differently
|
|
3935
|
-
typeof node._type == "string" && // Toolkit-types like nested spans are @-prefixed
|
|
3936
|
-
node._type[0] !== "@" && // `markDefs` isn't _required_ per say, but if it's there, it needs to be an array
|
|
3937
|
-
(!("markDefs" in node) || !node.markDefs || Array.isArray(node.markDefs) && // Every mark definition needs to have an `_key` to be mappable in child spans
|
|
3938
|
-
node.markDefs.every((def) => typeof def._key == "string")) && // `children` is required and needs to be an array
|
|
3939
|
-
"children" in node && Array.isArray(node.children) && // All children are objects with `_type` (usually spans, but can contain other stuff)
|
|
3940
|
-
node.children.every((child) => typeof child == "object" && "_type" in child)
|
|
3941
|
-
);
|
|
3942
|
-
}
|
|
3943
4044
|
function getPreviousSpan({
|
|
3944
4045
|
editor,
|
|
3945
4046
|
blockPath,
|
|
@@ -4426,11 +4527,11 @@ function isDecoratorActive({
|
|
|
4426
4527
|
}) {
|
|
4427
4528
|
if (!editor.selection)
|
|
4428
4529
|
return !1;
|
|
4429
|
-
const
|
|
4530
|
+
const selectedTextNodes = Array.from(Editor.nodes(editor, {
|
|
4430
4531
|
match: Text.isText,
|
|
4431
4532
|
at: editor.selection
|
|
4432
4533
|
}));
|
|
4433
|
-
return Range.isExpanded(editor.selection) ?
|
|
4534
|
+
return selectedTextNodes.length === 0 ? !1 : Range.isExpanded(editor.selection) ? selectedTextNodes.every((n) => {
|
|
4434
4535
|
const [node] = n;
|
|
4435
4536
|
return node.marks?.includes(decorator);
|
|
4436
4537
|
}) : ({
|
|
@@ -4752,32 +4853,18 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4752
4853
|
at: editor.selection
|
|
4753
4854
|
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path || [];
|
|
4754
4855
|
},
|
|
4755
|
-
insertBlock: (type, value) => {
|
|
4756
|
-
|
|
4757
|
-
|
|
4758
|
-
|
|
4759
|
-
|
|
4760
|
-
|
|
4761
|
-
|
|
4762
|
-
|
|
4763
|
-
|
|
4764
|
-
|
|
4765
|
-
match: (n) => !Editor.isEditor(n),
|
|
4766
|
-
at: [],
|
|
4767
|
-
reverse: !0
|
|
4768
|
-
}))[0];
|
|
4769
|
-
return Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], types) && Transforms.removeNodes(editor, {
|
|
4770
|
-
at: lastBlock[1]
|
|
4771
|
-
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path ?? [];
|
|
4856
|
+
insertBlock: (type, value) => insertBlockObjectActionImplementation({
|
|
4857
|
+
context: {
|
|
4858
|
+
keyGenerator: editorActor.getSnapshot().context.keyGenerator,
|
|
4859
|
+
schema: types
|
|
4860
|
+
},
|
|
4861
|
+
action: {
|
|
4862
|
+
type: "insert block object",
|
|
4863
|
+
name: type.name,
|
|
4864
|
+
value,
|
|
4865
|
+
editor
|
|
4772
4866
|
}
|
|
4773
|
-
|
|
4774
|
-
at: editor.selection.focus.path.slice(0, 1),
|
|
4775
|
-
match: (n) => n._type === types.block.name
|
|
4776
|
-
}))[0];
|
|
4777
|
-
return Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock[0]], types) && Transforms.removeNodes(editor, {
|
|
4778
|
-
at: focusBlock[1]
|
|
4779
|
-
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path || [];
|
|
4780
|
-
},
|
|
4867
|
+
}),
|
|
4781
4868
|
hasBlockStyle: (style) => {
|
|
4782
4869
|
try {
|
|
4783
4870
|
return editor.pteHasBlockStyle(style);
|
|
@@ -4947,6 +5034,35 @@ function createEditableAPI(editor, editorActor) {
|
|
|
4947
5034
|
}
|
|
4948
5035
|
};
|
|
4949
5036
|
}
|
|
5037
|
+
const insertBlockObjectActionImplementation = ({
|
|
5038
|
+
context,
|
|
5039
|
+
action
|
|
5040
|
+
}) => {
|
|
5041
|
+
const editor = action.editor, types = context.schema, block = toSlateValue([{
|
|
5042
|
+
_key: context.keyGenerator(),
|
|
5043
|
+
_type: action.name,
|
|
5044
|
+
...action.value ? action.value : {}
|
|
5045
|
+
}], {
|
|
5046
|
+
schemaTypes: context.schema
|
|
5047
|
+
})[0];
|
|
5048
|
+
if (!editor.selection) {
|
|
5049
|
+
const lastBlock = Array.from(Editor.nodes(editor, {
|
|
5050
|
+
match: (n) => !Editor.isEditor(n),
|
|
5051
|
+
at: [],
|
|
5052
|
+
reverse: !0
|
|
5053
|
+
}))[0];
|
|
5054
|
+
return Editor.insertNode(editor, block), lastBlock && isEqualToEmptyEditor([lastBlock[0]], types) && Transforms.removeNodes(editor, {
|
|
5055
|
+
at: lastBlock[1]
|
|
5056
|
+
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path ?? [];
|
|
5057
|
+
}
|
|
5058
|
+
const focusBlock = Array.from(Editor.nodes(editor, {
|
|
5059
|
+
at: editor.selection.focus.path.slice(0, 1),
|
|
5060
|
+
match: (n) => n._type === types.block.name
|
|
5061
|
+
}))[0];
|
|
5062
|
+
return Editor.insertNode(editor, block), focusBlock && isEqualToEmptyEditor([focusBlock[0]], types) && Transforms.removeNodes(editor, {
|
|
5063
|
+
at: focusBlock[1]
|
|
5064
|
+
}), editor.onChange(), toPortableTextRange(fromSlateValue(editor.children, types.block.name, KEY_TO_VALUE_ELEMENT.get(editor)), editor.selection, types)?.focus.path || [];
|
|
5065
|
+
};
|
|
4950
5066
|
function isAnnotationActive({
|
|
4951
5067
|
editor,
|
|
4952
5068
|
annotation
|
|
@@ -5243,6 +5359,35 @@ const addAnnotationActionImplementation = ({
|
|
|
5243
5359
|
type: "insert break"
|
|
5244
5360
|
}
|
|
5245
5361
|
});
|
|
5362
|
+
}, insertSpanActionImplementation = ({
|
|
5363
|
+
context,
|
|
5364
|
+
action
|
|
5365
|
+
}) => {
|
|
5366
|
+
if (!action.editor.selection) {
|
|
5367
|
+
console.error("Unable to perform action without selection", action);
|
|
5368
|
+
return;
|
|
5369
|
+
}
|
|
5370
|
+
const [focusBlock, focusBlockPath] = Array.from(Editor.nodes(action.editor, {
|
|
5371
|
+
at: action.editor.selection.focus.path,
|
|
5372
|
+
match: (node) => action.editor.isTextBlock(node)
|
|
5373
|
+
}))[0] ?? [void 0, void 0];
|
|
5374
|
+
if (!focusBlock || !focusBlockPath) {
|
|
5375
|
+
console.error("Unable to perform action without focus block", action);
|
|
5376
|
+
return;
|
|
5377
|
+
}
|
|
5378
|
+
const markDefs = focusBlock.markDefs ?? [], annotations = action.annotations ? action.annotations.map((annotation) => ({
|
|
5379
|
+
_type: annotation.name,
|
|
5380
|
+
_key: context.keyGenerator(),
|
|
5381
|
+
...annotation.value
|
|
5382
|
+
})) : void 0;
|
|
5383
|
+
annotations && annotations.length > 0 && Transforms.setNodes(action.editor, {
|
|
5384
|
+
markDefs: [...markDefs, ...annotations]
|
|
5385
|
+
}), Transforms.insertNodes(action.editor, {
|
|
5386
|
+
_type: "span",
|
|
5387
|
+
_key: context.keyGenerator(),
|
|
5388
|
+
text: action.text,
|
|
5389
|
+
marks: [...annotations?.map((annotation) => annotation._key) ?? [], ...action.decorators ?? []]
|
|
5390
|
+
});
|
|
5246
5391
|
}, behaviorActionImplementations = {
|
|
5247
5392
|
"annotation.add": addAnnotationActionImplementation,
|
|
5248
5393
|
"annotation.remove": removeAnnotationActionImplementation,
|
|
@@ -5327,8 +5472,10 @@ const addAnnotationActionImplementation = ({
|
|
|
5327
5472
|
at: location
|
|
5328
5473
|
});
|
|
5329
5474
|
},
|
|
5475
|
+
"insert block object": insertBlockObjectActionImplementation,
|
|
5330
5476
|
"insert break": insertBreakActionImplementation,
|
|
5331
5477
|
"insert soft break": insertSoftBreakActionImplementation,
|
|
5478
|
+
"insert span": insertSpanActionImplementation,
|
|
5332
5479
|
"insert text": ({
|
|
5333
5480
|
action
|
|
5334
5481
|
}) => {
|
|
@@ -5355,6 +5502,11 @@ const addAnnotationActionImplementation = ({
|
|
|
5355
5502
|
}) => {
|
|
5356
5503
|
action.effect();
|
|
5357
5504
|
},
|
|
5505
|
+
paste: ({
|
|
5506
|
+
action
|
|
5507
|
+
}) => {
|
|
5508
|
+
action.editor.insertData(action.clipboardData);
|
|
5509
|
+
},
|
|
5358
5510
|
select: ({
|
|
5359
5511
|
action
|
|
5360
5512
|
}) => {
|
|
@@ -5384,6 +5536,20 @@ function performAction({
|
|
|
5384
5536
|
});
|
|
5385
5537
|
break;
|
|
5386
5538
|
}
|
|
5539
|
+
case "insert block object": {
|
|
5540
|
+
behaviorActionImplementations["insert block object"]({
|
|
5541
|
+
context,
|
|
5542
|
+
action
|
|
5543
|
+
});
|
|
5544
|
+
break;
|
|
5545
|
+
}
|
|
5546
|
+
case "insert span": {
|
|
5547
|
+
behaviorActionImplementations["insert span"]({
|
|
5548
|
+
context,
|
|
5549
|
+
action
|
|
5550
|
+
});
|
|
5551
|
+
break;
|
|
5552
|
+
}
|
|
5387
5553
|
case "insert text block": {
|
|
5388
5554
|
behaviorActionImplementations["insert text block"]({
|
|
5389
5555
|
context,
|
|
@@ -5515,11 +5681,18 @@ function performDefaultAction({
|
|
|
5515
5681
|
});
|
|
5516
5682
|
break;
|
|
5517
5683
|
}
|
|
5518
|
-
|
|
5684
|
+
case "insert text": {
|
|
5519
5685
|
behaviorActionImplementations["insert text"]({
|
|
5520
5686
|
context,
|
|
5521
5687
|
action
|
|
5522
5688
|
});
|
|
5689
|
+
break;
|
|
5690
|
+
}
|
|
5691
|
+
default:
|
|
5692
|
+
behaviorActionImplementations.paste({
|
|
5693
|
+
context,
|
|
5694
|
+
action
|
|
5695
|
+
});
|
|
5523
5696
|
}
|
|
5524
5697
|
}
|
|
5525
5698
|
const networkLogic = fromCallback(({
|
|
@@ -6585,19 +6758,13 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6585
6758
|
const handleCopy = useCallback((event) => {
|
|
6586
6759
|
onCopy && onCopy(event) !== void 0 && event.preventDefault();
|
|
6587
6760
|
}, [onCopy]), handlePaste = useCallback((event_0) => {
|
|
6588
|
-
|
|
6589
|
-
return;
|
|
6590
|
-
if (!onPaste) {
|
|
6591
|
-
debug("Pasting normally"), slateEditor.insertData(event_0.clipboardData);
|
|
6592
|
-
return;
|
|
6593
|
-
}
|
|
6594
|
-
const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste({
|
|
6761
|
+
const value_0 = PortableTextEditor.getValue(portableTextEditor), path = toPortableTextRange(value_0, slateEditor.selection, schemaTypes)?.focus.path || [], onPasteResult = onPaste?.({
|
|
6595
6762
|
event: event_0,
|
|
6596
6763
|
value: value_0,
|
|
6597
6764
|
path,
|
|
6598
6765
|
schemaTypes
|
|
6599
6766
|
});
|
|
6600
|
-
onPasteResult
|
|
6767
|
+
onPasteResult || !slateEditor.selection ? (event_0.preventDefault(), editorActor.send({
|
|
6601
6768
|
type: "loading"
|
|
6602
6769
|
}), Promise.resolve(onPasteResult).then((result_0) => {
|
|
6603
6770
|
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, {
|
|
@@ -6607,7 +6774,14 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6607
6774
|
editorActor.send({
|
|
6608
6775
|
type: "done loading"
|
|
6609
6776
|
});
|
|
6610
|
-
}))
|
|
6777
|
+
})) : event_0.nativeEvent.clipboardData && (event_0.preventDefault(), editorActor.send({
|
|
6778
|
+
type: "behavior event",
|
|
6779
|
+
behaviorEvent: {
|
|
6780
|
+
type: "paste",
|
|
6781
|
+
clipboardData: event_0.nativeEvent.clipboardData
|
|
6782
|
+
},
|
|
6783
|
+
editor: slateEditor
|
|
6784
|
+
})), debug("No result from custom paste handler, pasting normally");
|
|
6611
6785
|
}, [editorActor, onPaste, portableTextEditor, schemaTypes, slateEditor]), handleOnFocus = useCallback((event_1) => {
|
|
6612
6786
|
if (onFocus && onFocus(event_1), !event_1.isDefaultPrevented()) {
|
|
6613
6787
|
const selection = PortableTextEditor.getSelection(portableTextEditor);
|
|
@@ -6622,15 +6796,11 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6622
6796
|
});
|
|
6623
6797
|
}
|
|
6624
6798
|
}, [editorActor, onFocus, portableTextEditor, slateEditor]), handleClick = useCallback((event_2) => {
|
|
6625
|
-
|
|
6626
|
-
|
|
6627
|
-
|
|
6628
|
-
|
|
6629
|
-
|
|
6630
|
-
decorators: []
|
|
6631
|
-
})), slateEditor.onChange());
|
|
6632
|
-
}
|
|
6633
|
-
}
|
|
6799
|
+
onClick && onClick(event_2);
|
|
6800
|
+
const focusBlockPath = slateEditor.selection ? slateEditor.selection.focus.path.slice(0, 1) : void 0, focusBlock = focusBlockPath ? Node.descendant(slateEditor, focusBlockPath) : void 0, [_, lastNodePath] = Node.last(slateEditor, []), lastBlockPath = lastNodePath.slice(0, 1), lastNodeFocused = focusBlockPath ? Path.equals(lastBlockPath, focusBlockPath) : !1, lastBlockIsVoid = focusBlock ? !slateEditor.isTextBlock(focusBlock) : !1;
|
|
6801
|
+
slateEditor.selection && Range.isCollapsed(slateEditor.selection) && lastNodeFocused && lastBlockIsVoid && (Transforms.insertNodes(slateEditor, slateEditor.pteCreateTextBlock({
|
|
6802
|
+
decorators: []
|
|
6803
|
+
})), slateEditor.onChange());
|
|
6634
6804
|
}, [onClick, slateEditor]), handleOnBlur = useCallback((event_3) => {
|
|
6635
6805
|
onBlur && onBlur(event_3), event_3.isPropagationStopped() || editorActor.send({
|
|
6636
6806
|
type: "blur",
|
|
@@ -6678,7 +6848,7 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6678
6848
|
return scrollSelectionIntoView === null ? noop : (_editor, domRange) => {
|
|
6679
6849
|
scrollSelectionIntoView(portableTextEditor, domRange);
|
|
6680
6850
|
};
|
|
6681
|
-
}, [portableTextEditor, scrollSelectionIntoView]), decorate = useCallback(([,
|
|
6851
|
+
}, [portableTextEditor, scrollSelectionIntoView]), decorate = useCallback(([, path_0]) => {
|
|
6682
6852
|
if (isEqualToEmptyEditor(slateEditor.children, schemaTypes))
|
|
6683
6853
|
return [{
|
|
6684
6854
|
anchor: {
|
|
@@ -6691,18 +6861,18 @@ const debug = debugWithName("component:Editable"), PLACEHOLDER_STYLE = {
|
|
|
6691
6861
|
},
|
|
6692
6862
|
placeholder: !0
|
|
6693
6863
|
}];
|
|
6694
|
-
if (
|
|
6864
|
+
if (path_0.length === 0)
|
|
6695
6865
|
return [];
|
|
6696
|
-
const result_1 = rangeDecorationState.filter((item) => Range.isCollapsed(item) ?
|
|
6866
|
+
const result_1 = rangeDecorationState.filter((item) => Range.isCollapsed(item) ? path_0.length !== 2 ? !1 : Path.equals(item.focus.path, path_0) && Path.equals(item.anchor.path, path_0) : Range.intersection(item, {
|
|
6697
6867
|
anchor: {
|
|
6698
|
-
path:
|
|
6868
|
+
path: path_0,
|
|
6699
6869
|
offset: 0
|
|
6700
6870
|
},
|
|
6701
6871
|
focus: {
|
|
6702
|
-
path:
|
|
6872
|
+
path: path_0,
|
|
6703
6873
|
offset: 0
|
|
6704
6874
|
}
|
|
6705
|
-
}) || Range.includes(item,
|
|
6875
|
+
}) || Range.includes(item, path_0));
|
|
6706
6876
|
return result_1.length > 0 ? result_1 : [];
|
|
6707
6877
|
}, [slateEditor, schemaTypes, rangeDecorationState]);
|
|
6708
6878
|
return useEffect(() => {
|
|
@@ -6773,6 +6943,7 @@ export {
|
|
|
6773
6943
|
PortableTextEditor,
|
|
6774
6944
|
coreBehavior,
|
|
6775
6945
|
coreBehaviors,
|
|
6946
|
+
createLinkBehaviors,
|
|
6776
6947
|
createMarkdownBehaviors,
|
|
6777
6948
|
defineBehavior,
|
|
6778
6949
|
defineSchema,
|