@portabletext/editor 2.14.4 → 2.15.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/_chunks-cjs/{selector.is-active-style.cjs → selector.is-at-the-start-of-block.cjs} +90 -94
- package/lib/_chunks-cjs/selector.is-at-the-start-of-block.cjs.map +1 -0
- package/lib/_chunks-dts/behavior.types.action.d.cts +4 -0
- package/lib/_chunks-dts/behavior.types.action.d.ts +4 -0
- package/lib/_chunks-es/{selector.is-active-style.js → selector.is-at-the-start-of-block.js} +90 -94
- package/lib/_chunks-es/selector.is-at-the-start-of-block.js.map +1 -0
- package/lib/index.cjs +163 -81
- package/lib/index.cjs.map +1 -1
- package/lib/index.js +84 -2
- package/lib/index.js.map +1 -1
- package/lib/selectors/index.cjs +33 -33
- package/lib/selectors/index.cjs.map +1 -1
- package/lib/selectors/index.js +2 -2
- package/lib/utils/index.d.cts +2 -2
- package/package.json +3 -3
- package/src/editor/editor-dom.ts +99 -0
- package/src/internal-utils/operation-to-patches.ts +39 -0
- package/lib/_chunks-cjs/selector.is-active-style.cjs.map +0 -1
- package/lib/_chunks-es/selector.is-active-style.js.map +0 -1
package/lib/index.js
CHANGED
|
@@ -13,7 +13,7 @@ import { getBlockStartPoint, getBlockKeyFromSelectionPoint, getChildKeyFromSelec
|
|
|
13
13
|
import isEqual from "lodash/isEqual.js";
|
|
14
14
|
import { isTextBlock, isSpan, compileSchema } from "@portabletext/schema";
|
|
15
15
|
import { defineSchema } from "@portabletext/schema";
|
|
16
|
-
import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getActiveDecorators, getTrimmedSelection, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-
|
|
16
|
+
import { getFocusInlineObject, getSelectedBlocks, getSelectionStartBlock as getSelectionStartBlock$1, getSelectionEndBlock as getSelectionEndBlock$1, isOverlappingSelection, isSelectingEntireBlocks, getActiveDecorators, getTrimmedSelection, isActiveAnnotation, getCaretWordSelection, getFocusBlockObject, getPreviousBlock, getNextBlock, getMarkState, getActiveAnnotationsMarks, isAtTheEndOfBlock, isAtTheStartOfBlock, getFirstBlock as getFirstBlock$1, getLastBlock as getLastBlock$1, getFocusListBlock, getSelectionEndPoint as getSelectionEndPoint$1, isActiveDecorator, getActiveAnnotations, getSelectedTextBlocks, isActiveListItem, isActiveStyle } from "./_chunks-es/selector.is-at-the-start-of-block.js";
|
|
17
17
|
import { isSelectionCollapsed as isSelectionCollapsed$1, getFocusTextBlock, getFocusSpan as getFocusSpan$1, isSelectionExpanded, getFocusBlock as getFocusBlock$1, getSelectedValue, getSelectionStartPoint as getSelectionStartPoint$1, getFocusChild as getFocusChild$1 } from "./_chunks-es/selector.get-selection-text.js";
|
|
18
18
|
import { defineBehavior, forward, raise, effect } from "./behaviors/index.js";
|
|
19
19
|
import uniq from "lodash/uniq.js";
|
|
@@ -5961,7 +5961,24 @@ function setNodePatch(schema, children, operation) {
|
|
|
5961
5961
|
}, block)) {
|
|
5962
5962
|
const child = block.children[operation.path[1]];
|
|
5963
5963
|
if (child) {
|
|
5964
|
-
const blockKey = block._key, childKey = child._key, patches = []
|
|
5964
|
+
const blockKey = block._key, childKey = child._key, patches = [];
|
|
5965
|
+
if (Element$1.isElement(child)) {
|
|
5966
|
+
const _key = operation.newProperties._key;
|
|
5967
|
+
_key !== void 0 && patches.push(set(_key, [{
|
|
5968
|
+
_key: blockKey
|
|
5969
|
+
}, "children", block.children.indexOf(child), "_key"]));
|
|
5970
|
+
const properties = "value" in operation.newProperties && typeof operation.newProperties.value == "object" ? operation.newProperties.value : {}, keys2 = Object.keys(properties);
|
|
5971
|
+
for (const key of keys2) {
|
|
5972
|
+
const value = properties[key];
|
|
5973
|
+
patches.push(set(value, [{
|
|
5974
|
+
_key: blockKey
|
|
5975
|
+
}, "children", {
|
|
5976
|
+
_key: childKey
|
|
5977
|
+
}, key]));
|
|
5978
|
+
}
|
|
5979
|
+
return patches;
|
|
5980
|
+
}
|
|
5981
|
+
const keys = Object.keys(operation.newProperties);
|
|
5965
5982
|
return keys.forEach((keyName) => {
|
|
5966
5983
|
if (keys.length === 1 && keyName === "_key") {
|
|
5967
5984
|
const val = get(operation.newProperties, keyName);
|
|
@@ -6728,6 +6745,10 @@ function createEditorDom(sendBack, slateEditor) {
|
|
|
6728
6745
|
return {
|
|
6729
6746
|
getBlockNodes: (snapshot) => getBlockNodes(slateEditor, snapshot),
|
|
6730
6747
|
getChildNodes: (snapshot) => getChildNodes(slateEditor, snapshot),
|
|
6748
|
+
getEditorElement: () => getEditorElement(slateEditor),
|
|
6749
|
+
getSelectionRect: (snapshot) => getSelectionRect(snapshot),
|
|
6750
|
+
getStartBlockElement: (snapshot) => getStartBlockElement(slateEditor, snapshot),
|
|
6751
|
+
getEndBlockElement: (snapshot) => getEndBlockElement(slateEditor, snapshot),
|
|
6731
6752
|
setDragGhost: ({
|
|
6732
6753
|
event,
|
|
6733
6754
|
ghost
|
|
@@ -6770,6 +6791,67 @@ function getChildNodes(slateEditor, snapshot) {
|
|
|
6770
6791
|
return [];
|
|
6771
6792
|
}
|
|
6772
6793
|
}
|
|
6794
|
+
function getEditorElement(slateEditor) {
|
|
6795
|
+
try {
|
|
6796
|
+
return DOMEditor.toDOMNode(slateEditor, slateEditor);
|
|
6797
|
+
} catch {
|
|
6798
|
+
return;
|
|
6799
|
+
}
|
|
6800
|
+
}
|
|
6801
|
+
function getSelectionRect(snapshot) {
|
|
6802
|
+
if (!snapshot.context.selection)
|
|
6803
|
+
return null;
|
|
6804
|
+
try {
|
|
6805
|
+
const selection = window.getSelection();
|
|
6806
|
+
return selection ? selection.getRangeAt(0).getBoundingClientRect() : null;
|
|
6807
|
+
} catch {
|
|
6808
|
+
return null;
|
|
6809
|
+
}
|
|
6810
|
+
}
|
|
6811
|
+
function getStartBlockElement(slateEditor, snapshot) {
|
|
6812
|
+
const startBlock = getSelectionStartBlock$1(snapshot);
|
|
6813
|
+
if (!startBlock)
|
|
6814
|
+
return null;
|
|
6815
|
+
const startBlockNode = getBlockNodes(slateEditor, {
|
|
6816
|
+
...snapshot,
|
|
6817
|
+
context: {
|
|
6818
|
+
...snapshot.context,
|
|
6819
|
+
selection: {
|
|
6820
|
+
anchor: {
|
|
6821
|
+
path: startBlock.path,
|
|
6822
|
+
offset: 0
|
|
6823
|
+
},
|
|
6824
|
+
focus: {
|
|
6825
|
+
path: startBlock.path,
|
|
6826
|
+
offset: 0
|
|
6827
|
+
}
|
|
6828
|
+
}
|
|
6829
|
+
}
|
|
6830
|
+
})?.at(0);
|
|
6831
|
+
return startBlockNode && startBlockNode instanceof Element ? startBlockNode : null;
|
|
6832
|
+
}
|
|
6833
|
+
function getEndBlockElement(slateEditor, snapshot) {
|
|
6834
|
+
const endBlock = getSelectionEndBlock$1(snapshot);
|
|
6835
|
+
if (!endBlock)
|
|
6836
|
+
return null;
|
|
6837
|
+
const endBlockNode = getBlockNodes(slateEditor, {
|
|
6838
|
+
...snapshot,
|
|
6839
|
+
context: {
|
|
6840
|
+
...snapshot.context,
|
|
6841
|
+
selection: {
|
|
6842
|
+
anchor: {
|
|
6843
|
+
path: endBlock.path,
|
|
6844
|
+
offset: 0
|
|
6845
|
+
},
|
|
6846
|
+
focus: {
|
|
6847
|
+
path: endBlock.path,
|
|
6848
|
+
offset: 0
|
|
6849
|
+
}
|
|
6850
|
+
}
|
|
6851
|
+
}
|
|
6852
|
+
})?.at(0);
|
|
6853
|
+
return endBlockNode && endBlockNode instanceof Element ? endBlockNode : null;
|
|
6854
|
+
}
|
|
6773
6855
|
function setDragGhost({
|
|
6774
6856
|
sendBack,
|
|
6775
6857
|
event,
|