@portabletext/editor 2.21.4 → 2.21.5
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/_chunks-dts/index.d.ts +1 -1
- package/lib/index.js +6 -6
- package/lib/index.js.map +1 -1
- package/package.json +6 -6
- package/src/internal-utils/apply-operation-to-portable-text.test.ts +91 -0
- package/src/internal-utils/apply-operation-to-portable-text.ts +6 -3
- package/src/internal-utils/portable-text-node.test.ts +132 -0
- package/src/internal-utils/portable-text-node.ts +18 -8
|
@@ -1697,7 +1697,7 @@ declare const editorMachine: xstate229.StateMachine<{
|
|
|
1697
1697
|
}, xstate229.AnyEventObject>;
|
|
1698
1698
|
}) => {
|
|
1699
1699
|
behaviors: Set<{
|
|
1700
|
-
behavior: Behavior<"*" | "split" | `custom.${string}` | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "drag.dragstart" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragover" | "drag.dragleave" | "drag.drop" | "input.*" | "keyboard.keydown" | "keyboard.keyup" | "mouse.click" | "history.*" | "split.*" | "delete.*" | "select.*" | "deserialize.*" | "serialize.*" | "annotation.*" | "block.*" | "child.*" | "decorator.*" | "insert.*" | "move.*" | "deserialization.*" | "list item.*" | "serialization.*" | "
|
|
1700
|
+
behavior: Behavior<"*" | "split" | `custom.${string}` | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle" | "clipboard.copy" | "clipboard.cut" | "clipboard.paste" | "drag.dragstart" | "drag.drag" | "drag.dragend" | "drag.dragenter" | "drag.dragover" | "drag.dragleave" | "drag.drop" | "input.*" | "keyboard.keydown" | "keyboard.keyup" | "mouse.click" | "style.*" | "history.*" | "split.*" | "delete.*" | "select.*" | "deserialize.*" | "serialize.*" | "annotation.*" | "block.*" | "child.*" | "decorator.*" | "insert.*" | "move.*" | "deserialization.*" | "list item.*" | "serialization.*" | "clipboard.*" | "drag.*" | "keyboard.*" | "mouse.*", true, {
|
|
1701
1701
|
type: StrictExtract<"split" | "annotation.add" | "annotation.remove" | "block.set" | "block.unset" | "child.set" | "child.unset" | "decorator.add" | "decorator.remove" | "delete" | "history.redo" | "history.undo" | "insert.block" | "insert.child" | "insert.text" | "move.backward" | "move.block" | "move.forward" | "select" | "annotation.set" | "annotation.toggle" | "decorator.toggle" | "delete.backward" | "delete.block" | "delete.child" | "delete.forward" | "delete.text" | "deserialize" | "deserialize.data" | "deserialization.success" | "deserialization.failure" | "insert.blocks" | "insert.break" | "insert.inline object" | "insert.soft break" | "insert.span" | "list item.add" | "list item.remove" | "list item.toggle" | "move.block down" | "move.block up" | "select.block" | "select.previous block" | "select.next block" | "serialize" | "serialize.data" | "serialization.success" | "serialization.failure" | "style.add" | "style.remove" | "style.toggle", "annotation.add">;
|
|
1702
1702
|
annotation: {
|
|
1703
1703
|
name: string;
|
package/lib/index.js
CHANGED
|
@@ -6480,11 +6480,11 @@ function isTextBlockNode(context, node) {
|
|
|
6480
6480
|
function isSpanNode(context, node) {
|
|
6481
6481
|
return typeof node != "object" || node === null || "children" in node ? !1 : "_type" in node ? node._type === context.schema.span.name : "text" in node;
|
|
6482
6482
|
}
|
|
6483
|
-
function isPartialSpanNode(node) {
|
|
6484
|
-
return typeof node
|
|
6483
|
+
function isPartialSpanNode(context, node) {
|
|
6484
|
+
return !(typeof node != "object" || node === null || !("text" in node) || typeof node.text != "string" || "_type" in node && node._type !== context.schema.span.name);
|
|
6485
6485
|
}
|
|
6486
6486
|
function isObjectNode(context, node) {
|
|
6487
|
-
return !isEditorNode(node) && !isTextBlockNode(context, node) && !isSpanNode(context, node) && !isPartialSpanNode(node);
|
|
6487
|
+
return !isEditorNode(node) && !isTextBlockNode(context, node) && !isSpanNode(context, node) && !isPartialSpanNode(context, node);
|
|
6488
6488
|
}
|
|
6489
6489
|
function getBlock(root, path) {
|
|
6490
6490
|
const index = path.at(0);
|
|
@@ -6563,7 +6563,7 @@ function applyOperationToPortableTextDraft(context, root, operation) {
|
|
|
6563
6563
|
if (path.length === 2) {
|
|
6564
6564
|
if (!isTextBlockNode(context, parent))
|
|
6565
6565
|
break;
|
|
6566
|
-
if (isPartialSpanNode(insertedNode)) {
|
|
6566
|
+
if (isPartialSpanNode(context, insertedNode)) {
|
|
6567
6567
|
parent.children.splice(index, 0, insertedNode);
|
|
6568
6568
|
break;
|
|
6569
6569
|
}
|
|
@@ -6599,7 +6599,7 @@ function applyOperationToPortableTextDraft(context, root, operation) {
|
|
|
6599
6599
|
if (!node || !prev || !parent)
|
|
6600
6600
|
break;
|
|
6601
6601
|
const index = path[path.length - 1];
|
|
6602
|
-
if (isPartialSpanNode(node) && isPartialSpanNode(prev))
|
|
6602
|
+
if (isPartialSpanNode(context, node) && isPartialSpanNode(context, prev))
|
|
6603
6603
|
prev.text += node.text;
|
|
6604
6604
|
else if (isTextBlockNode(context, node) && isTextBlockNode(context, prev))
|
|
6605
6605
|
prev.children.push(...node.children);
|
|
@@ -6684,7 +6684,7 @@ function applyOperationToPortableTextDraft(context, root, operation) {
|
|
|
6684
6684
|
newProperties.hasOwnProperty(key) || delete node[key];
|
|
6685
6685
|
break;
|
|
6686
6686
|
}
|
|
6687
|
-
if (isPartialSpanNode(node)) {
|
|
6687
|
+
if (isPartialSpanNode(context, node)) {
|
|
6688
6688
|
for (const key in newProperties) {
|
|
6689
6689
|
if (key === "text")
|
|
6690
6690
|
break;
|