@portabletext/editor 2.8.1 → 2.8.2
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/behavior.types.action.d.cts +82 -86
- package/lib/_chunks-dts/behavior.types.action.d.ts +27 -31
- package/lib/index.cjs +28 -41
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +28 -41
- package/lib/index.js.map +1 -1
- package/lib/plugins/index.d.cts +3 -3
- package/lib/plugins/index.d.ts +3 -3
- package/package.json +3 -3
- package/src/editor/PortableTextEditor.tsx +1 -1
- package/src/editor/plugins/createWithEditableAPI.ts +70 -28
- package/src/index.ts +1 -1
- package/src/operations/behavior.operation.annotation.add.ts +1 -46
- package/src/operations/behavior.operations.ts +1 -2
- package/src/types/editor.ts +19 -3
package/lib/index.js
CHANGED
|
@@ -3991,8 +3991,7 @@ const addAnnotationOperationImplementation = ({
|
|
|
3991
3991
|
const editor = operation.editor;
|
|
3992
3992
|
if (!editor.selection || Range.isCollapsed(editor.selection))
|
|
3993
3993
|
return;
|
|
3994
|
-
|
|
3995
|
-
const markDefPaths = [], selectedBlocks = Editor.nodes(editor, {
|
|
3994
|
+
const selectedBlocks = Editor.nodes(editor, {
|
|
3996
3995
|
at: editor.selection,
|
|
3997
3996
|
match: (node) => editor.isTextBlock(node),
|
|
3998
3997
|
reverse: Range.isBackward(editor.selection)
|
|
@@ -4002,18 +4001,14 @@ const addAnnotationOperationImplementation = ({
|
|
|
4002
4001
|
if (block.children.length === 0 || block.children.length === 1 && block.children[0].text === "")
|
|
4003
4002
|
continue;
|
|
4004
4003
|
const annotationKey = blockIndex === 0 ? parsedAnnotation._key : context.keyGenerator(), markDefs = block.markDefs ?? [];
|
|
4005
|
-
markDefs.find((markDef) => markDef._type === parsedAnnotation._type && markDef._key === annotationKey) === void 0 &&
|
|
4004
|
+
markDefs.find((markDef) => markDef._type === parsedAnnotation._type && markDef._key === annotationKey) === void 0 && Transforms.setNodes(editor, {
|
|
4006
4005
|
markDefs: [...markDefs, {
|
|
4007
4006
|
...parsedAnnotation,
|
|
4008
4007
|
_key: annotationKey
|
|
4009
4008
|
}]
|
|
4010
4009
|
}, {
|
|
4011
4010
|
at: blockPath
|
|
4012
|
-
}),
|
|
4013
|
-
_key: block._key
|
|
4014
|
-
}, "markDefs", {
|
|
4015
|
-
_key: annotationKey
|
|
4016
|
-
}], Range.isBackward(editor.selection) ? markDefPaths.unshift(markDefPath) : markDefPaths.push(markDefPath)), Transforms.setNodes(editor, {}, {
|
|
4011
|
+
}), Transforms.setNodes(editor, {}, {
|
|
4017
4012
|
match: Text.isText,
|
|
4018
4013
|
split: !0
|
|
4019
4014
|
});
|
|
@@ -4026,19 +4021,10 @@ const addAnnotationOperationImplementation = ({
|
|
|
4026
4021
|
marks: [...marks, annotationKey]
|
|
4027
4022
|
}, {
|
|
4028
4023
|
at: path
|
|
4029
|
-
})
|
|
4030
|
-
_key: block._key
|
|
4031
|
-
}, "children", {
|
|
4032
|
-
_key: span._key
|
|
4033
|
-
}];
|
|
4024
|
+
});
|
|
4034
4025
|
}
|
|
4035
4026
|
blockIndex++;
|
|
4036
4027
|
}
|
|
4037
|
-
return markDefPath && spanPath && (paths = {
|
|
4038
|
-
markDefPath,
|
|
4039
|
-
markDefPaths,
|
|
4040
|
-
spanPath
|
|
4041
|
-
}), paths;
|
|
4042
4028
|
}, removeAnnotationOperationImplementation = ({
|
|
4043
4029
|
operation
|
|
4044
4030
|
}) => {
|
|
@@ -10317,37 +10303,38 @@ function createEditableAPI(editor, editorActor) {
|
|
|
10317
10303
|
return isActiveAnnotation(annotationType)(snapshot);
|
|
10318
10304
|
},
|
|
10319
10305
|
addAnnotation: (type, value) => {
|
|
10320
|
-
|
|
10321
|
-
const snapshot = getEditorSnapshot({
|
|
10306
|
+
const snapshotBefore = getEditorSnapshot({
|
|
10322
10307
|
editorActorSnapshot: editorActor.getSnapshot(),
|
|
10323
10308
|
slateEditorInstance: editor
|
|
10324
|
-
});
|
|
10325
|
-
|
|
10326
|
-
mode: "partial"
|
|
10327
|
-
})(snapshot) && editorActor.send({
|
|
10309
|
+
}), selectedValueBefore = getSelectedValue(snapshotBefore), focusSpanBefore = getFocusSpan$1(snapshotBefore), markDefsBefore = selectedValueBefore.flatMap((block) => isTextBlock(snapshotBefore.context, block) ? block.markDefs ?? [] : []);
|
|
10310
|
+
editorActor.send({
|
|
10328
10311
|
type: "behavior event",
|
|
10329
10312
|
behaviorEvent: {
|
|
10330
|
-
type: "annotation.
|
|
10313
|
+
type: "annotation.add",
|
|
10331
10314
|
annotation: {
|
|
10332
|
-
name: type.name
|
|
10315
|
+
name: type.name,
|
|
10316
|
+
value: value ?? {}
|
|
10333
10317
|
}
|
|
10334
10318
|
},
|
|
10335
10319
|
editor
|
|
10336
|
-
})
|
|
10337
|
-
|
|
10338
|
-
|
|
10339
|
-
|
|
10340
|
-
|
|
10341
|
-
|
|
10342
|
-
|
|
10343
|
-
|
|
10344
|
-
|
|
10345
|
-
|
|
10346
|
-
|
|
10347
|
-
|
|
10348
|
-
|
|
10349
|
-
|
|
10350
|
-
|
|
10320
|
+
});
|
|
10321
|
+
const snapshotAfter = getEditorSnapshot({
|
|
10322
|
+
editorActorSnapshot: editorActor.getSnapshot(),
|
|
10323
|
+
slateEditorInstance: editor
|
|
10324
|
+
}), selectedValueAfter = getSelectedValue(snapshotAfter), focusBlockAfter = getFocusBlock$1(snapshotAfter), focusSpanAfter = getFocusSpan$1(snapshotAfter), newMarkDefKeysOnFocusSpan = focusSpanAfter?.node.marks?.filter((mark) => !focusSpanBefore?.node.marks?.includes(mark) && !snapshotAfter.context.schema.decorators.map((decorator) => decorator.name).includes(mark)), markDefs = selectedValueAfter.flatMap((block) => isTextBlock(snapshotAfter.context, block) ? block.markDefs?.map((markDef2) => ({
|
|
10325
|
+
markDef: markDef2,
|
|
10326
|
+
path: [{
|
|
10327
|
+
_key: block._key
|
|
10328
|
+
}, "markDefs", {
|
|
10329
|
+
_key: markDef2._key
|
|
10330
|
+
}]
|
|
10331
|
+
})) ?? [] : []).filter((markDef2) => !markDefsBefore.some((markDefBefore) => markDefBefore._key === markDef2.markDef._key)), spanPath = focusSpanAfter?.path, markDef = markDefs.find((markDef2) => newMarkDefKeysOnFocusSpan?.some((mark) => mark === markDef2.markDef._key));
|
|
10332
|
+
if (focusBlockAfter && spanPath && markDef)
|
|
10333
|
+
return {
|
|
10334
|
+
markDefPath: markDef.path,
|
|
10335
|
+
markDefPaths: markDefs.map((markDef2) => markDef2.path),
|
|
10336
|
+
spanPath
|
|
10337
|
+
};
|
|
10351
10338
|
},
|
|
10352
10339
|
delete: (selection, options) => {
|
|
10353
10340
|
if (selection) {
|