rme 0.2.5-alpha.13 → 0.2.5-alpha.14
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/dist/index.mjs +193 -133
- package/dist/index.mjs.map +4 -4
- package/package.json +7 -7
package/dist/index.mjs
CHANGED
|
@@ -1908,7 +1908,7 @@ import {
|
|
|
1908
1908
|
nodeInputRule as nodeInputRule10,
|
|
1909
1909
|
setBlockType as setBlockType3
|
|
1910
1910
|
} from "@rme-sdk/core";
|
|
1911
|
-
import { TextSelection as
|
|
1911
|
+
import { TextSelection as TextSelection12 } from "@rme-sdk/pm/state";
|
|
1912
1912
|
import { Decoration as Decoration8, DecorationSet as DecorationSet5 } from "@rme-sdk/pm/view";
|
|
1913
1913
|
|
|
1914
1914
|
// src/editor/transform/parser.ts
|
|
@@ -9574,7 +9574,108 @@ MermaidBlockExtension = __decorateClass([
|
|
|
9574
9574
|
], MermaidBlockExtension);
|
|
9575
9575
|
|
|
9576
9576
|
// src/editor/extensions/NodeIndicator/node-indicator-extension.tsx
|
|
9577
|
+
import { isHTMLElement as isHTMLElement3 } from "@ocavue/utils";
|
|
9577
9578
|
import { PlainExtension as PlainExtension7 } from "@rme-sdk/core";
|
|
9579
|
+
import { NodeSelection as NodeSelection2, TextSelection as TextSelection11 } from "@rme-sdk/pm/state";
|
|
9580
|
+
|
|
9581
|
+
// src/editor/extensions/NodeIndicator/drop-target.ts
|
|
9582
|
+
import { isHTMLElement } from "@ocavue/utils";
|
|
9583
|
+
import { NodeSelection } from "@rme-sdk/pm/state";
|
|
9584
|
+
function getTargetsByView(view) {
|
|
9585
|
+
let stack = [[-1, view.state.doc]];
|
|
9586
|
+
let targets = [];
|
|
9587
|
+
while (stack.length > 0) {
|
|
9588
|
+
const [pos, node] = stack.pop();
|
|
9589
|
+
if (pos >= 0) {
|
|
9590
|
+
let dom = view.nodeDOM(pos);
|
|
9591
|
+
if (dom && isHTMLElement(dom)) {
|
|
9592
|
+
let rect = dom.getBoundingClientRect();
|
|
9593
|
+
let { top, bottom, left: x1, right: x2 } = rect;
|
|
9594
|
+
targets.push(
|
|
9595
|
+
[pos, [x1, top, x2, top]],
|
|
9596
|
+
[pos + node.nodeSize, [x1, bottom, x2, bottom]]
|
|
9597
|
+
);
|
|
9598
|
+
}
|
|
9599
|
+
}
|
|
9600
|
+
if (node.isBlock && !node.isTextblock) {
|
|
9601
|
+
let childPos = pos + 1;
|
|
9602
|
+
for (let child of node.children) {
|
|
9603
|
+
stack.push([childPos, child]);
|
|
9604
|
+
childPos += child.nodeSize;
|
|
9605
|
+
}
|
|
9606
|
+
}
|
|
9607
|
+
}
|
|
9608
|
+
return targets;
|
|
9609
|
+
}
|
|
9610
|
+
function buildGetTarget(view, onDrag) {
|
|
9611
|
+
let prevTargets = [];
|
|
9612
|
+
let prevDoc;
|
|
9613
|
+
let prevRect;
|
|
9614
|
+
const getTargets = () => {
|
|
9615
|
+
const rect = view.dom.getBoundingClientRect();
|
|
9616
|
+
const doc = view.state.doc;
|
|
9617
|
+
if (prevTargets && prevDoc && prevRect && rect.width === prevRect.width && rect.height === prevRect.height && rect.x === prevRect.x && rect.y === prevRect.y && prevDoc.eq(doc)) {
|
|
9618
|
+
return prevTargets;
|
|
9619
|
+
}
|
|
9620
|
+
prevRect = rect;
|
|
9621
|
+
prevDoc = doc;
|
|
9622
|
+
prevTargets = getTargetsByView(view);
|
|
9623
|
+
return prevTargets;
|
|
9624
|
+
};
|
|
9625
|
+
const getTargetImpl = (point, event2) => {
|
|
9626
|
+
if (!view.editable || view.isDestroyed) {
|
|
9627
|
+
return;
|
|
9628
|
+
}
|
|
9629
|
+
const compare = (p1, p2) => {
|
|
9630
|
+
const [pos1, line1] = p1;
|
|
9631
|
+
const [pos2, line2] = p2;
|
|
9632
|
+
const p1Distance = pointLineDistance(point, line1);
|
|
9633
|
+
const p2Distance = pointLineDistance(point, line2);
|
|
9634
|
+
return p1Distance - p2Distance || pos1 - pos2;
|
|
9635
|
+
};
|
|
9636
|
+
let targets = getTargets();
|
|
9637
|
+
targets.sort(compare);
|
|
9638
|
+
targets = targets.slice(0, 8);
|
|
9639
|
+
const target = targets.find((target2) => onDrag?.({ view, pos: target2[0], event: event2 }) !== false);
|
|
9640
|
+
if (target && isDraggingToItself(view, target[0])) {
|
|
9641
|
+
return void 0;
|
|
9642
|
+
}
|
|
9643
|
+
return target;
|
|
9644
|
+
};
|
|
9645
|
+
let prevPoint;
|
|
9646
|
+
let prevTarget;
|
|
9647
|
+
const getTargetCached = (point, event2) => {
|
|
9648
|
+
if (prevPoint && pointEqual(prevPoint, point)) {
|
|
9649
|
+
return prevTarget;
|
|
9650
|
+
}
|
|
9651
|
+
prevPoint = point;
|
|
9652
|
+
prevTarget = getTargetImpl(point, event2);
|
|
9653
|
+
return prevTarget;
|
|
9654
|
+
};
|
|
9655
|
+
return getTargetCached;
|
|
9656
|
+
}
|
|
9657
|
+
function pointEqual(a, b) {
|
|
9658
|
+
return a[0] === b[0] && a[1] === b[1];
|
|
9659
|
+
}
|
|
9660
|
+
function pointPointDistance(a, b) {
|
|
9661
|
+
return Math.abs(a[0] - b[0]) + Math.abs(a[1] - b[1]);
|
|
9662
|
+
}
|
|
9663
|
+
function pointLineDistance(point, line) {
|
|
9664
|
+
return Math.min(
|
|
9665
|
+
pointPointDistance(point, [line[0], line[1]]),
|
|
9666
|
+
pointPointDistance(point, [line[2], line[3]])
|
|
9667
|
+
);
|
|
9668
|
+
}
|
|
9669
|
+
function isDraggingToItself(view, pos) {
|
|
9670
|
+
const dragging = view.dragging;
|
|
9671
|
+
if (!dragging) return;
|
|
9672
|
+
const { move } = dragging;
|
|
9673
|
+
if (!move) return;
|
|
9674
|
+
const selection = view.state.selection;
|
|
9675
|
+
if (!(selection instanceof NodeSelection)) return;
|
|
9676
|
+
const { from, to } = selection;
|
|
9677
|
+
return from <= pos && pos <= to;
|
|
9678
|
+
}
|
|
9578
9679
|
|
|
9579
9680
|
// src/editor/extensions/NodeIndicator/node-indicator-plugin.ts
|
|
9580
9681
|
import { PluginKey } from "@rme-sdk/pm/state";
|
|
@@ -9735,28 +9836,25 @@ function findFirstLineRectInElement(element) {
|
|
|
9735
9836
|
const bottom = top + lineHeight;
|
|
9736
9837
|
return { top, bottom, left, right };
|
|
9737
9838
|
}
|
|
9738
|
-
var fallbackRect = Object.freeze({
|
|
9739
|
-
top: -9999,
|
|
9740
|
-
right: -9999,
|
|
9741
|
-
bottom: -9999,
|
|
9742
|
-
left: -9999,
|
|
9743
|
-
width: 0,
|
|
9744
|
-
height: 0,
|
|
9745
|
-
x: -9999,
|
|
9746
|
-
y: -9999
|
|
9747
|
-
});
|
|
9748
9839
|
|
|
9749
9840
|
// src/editor/extensions/NodeIndicator/node-indicator-extension.tsx
|
|
9750
|
-
import { isHTMLElement as isHTMLElement2 } from "@ocavue/utils";
|
|
9751
9841
|
var NodeIndicatorExtension = class extends PlainExtension7 {
|
|
9752
9842
|
get name() {
|
|
9753
9843
|
return "nodeIndicator";
|
|
9754
9844
|
}
|
|
9755
9845
|
createPlugin() {
|
|
9846
|
+
let getTarget;
|
|
9847
|
+
const initialState = {
|
|
9848
|
+
node: null,
|
|
9849
|
+
pos: null,
|
|
9850
|
+
isDragging: false,
|
|
9851
|
+
rect: null
|
|
9852
|
+
};
|
|
9756
9853
|
return {
|
|
9757
9854
|
key: pluginKey,
|
|
9855
|
+
initialState,
|
|
9758
9856
|
state: {
|
|
9759
|
-
init: () =>
|
|
9857
|
+
init: () => initialState,
|
|
9760
9858
|
apply: (tr, value) => {
|
|
9761
9859
|
const meta = tr.getMeta(pluginKey);
|
|
9762
9860
|
if (meta) {
|
|
@@ -9771,12 +9869,56 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
|
|
|
9771
9869
|
return value;
|
|
9772
9870
|
}
|
|
9773
9871
|
},
|
|
9872
|
+
view: (view) => {
|
|
9873
|
+
getTarget = buildGetTarget(view);
|
|
9874
|
+
return {};
|
|
9875
|
+
},
|
|
9774
9876
|
props: {
|
|
9877
|
+
handleDrop: (view, event2, slice, move) => {
|
|
9878
|
+
if (!getTarget) return false;
|
|
9879
|
+
const target = getTarget([event2.clientX, event2.clientY], event2);
|
|
9880
|
+
if (!target) return false;
|
|
9881
|
+
event2.preventDefault();
|
|
9882
|
+
let insertPos = target[0];
|
|
9883
|
+
let tr = view.state.tr;
|
|
9884
|
+
if (move) {
|
|
9885
|
+
const ext = view.state.plugins.find((plugin) => {
|
|
9886
|
+
return plugin.spec.initialState?.isDragging === false;
|
|
9887
|
+
});
|
|
9888
|
+
const state = ext?.getState(view.state) || {};
|
|
9889
|
+
const { node: draggingNode, pos: draggingPos } = state;
|
|
9890
|
+
if (!draggingNode || !draggingPos) return false;
|
|
9891
|
+
tr.delete(draggingPos, draggingPos + draggingNode.nodeSize);
|
|
9892
|
+
let { node } = view.dragging || {};
|
|
9893
|
+
if (node) node.replace(tr);
|
|
9894
|
+
else tr.deleteSelection();
|
|
9895
|
+
}
|
|
9896
|
+
let pos = tr.mapping.map(insertPos);
|
|
9897
|
+
let isNode = slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1;
|
|
9898
|
+
let beforeInsert = tr.doc;
|
|
9899
|
+
if (isNode) tr.replaceRangeWith(pos, pos, slice.content.firstChild);
|
|
9900
|
+
else tr.replaceRange(pos, pos, slice);
|
|
9901
|
+
if (tr.doc.eq(beforeInsert)) {
|
|
9902
|
+
return true;
|
|
9903
|
+
}
|
|
9904
|
+
let $pos = tr.doc.resolve(pos);
|
|
9905
|
+
if (isNode && NodeSelection2.isSelectable(slice.content.firstChild) && $pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice.content.firstChild)) {
|
|
9906
|
+
tr.setSelection(new NodeSelection2($pos));
|
|
9907
|
+
} else {
|
|
9908
|
+
let end = tr.mapping.map(insertPos);
|
|
9909
|
+
tr.mapping.maps[tr.mapping.maps.length - 1].forEach(
|
|
9910
|
+
(_from, _to, _newFrom, newTo) => end = newTo
|
|
9911
|
+
);
|
|
9912
|
+
tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end)));
|
|
9913
|
+
}
|
|
9914
|
+
view.focus();
|
|
9915
|
+
view.dispatch(tr.setMeta("uiEvent", "drop"));
|
|
9916
|
+
return true;
|
|
9917
|
+
},
|
|
9775
9918
|
handleDOMEvents: {
|
|
9776
9919
|
pointermove: (view, event2) => {
|
|
9777
9920
|
const { x, y } = event2;
|
|
9778
9921
|
const block = findBlockByCoords(view, x, y);
|
|
9779
|
-
console.log("block", block?.node.type);
|
|
9780
9922
|
if (!block) {
|
|
9781
9923
|
view.dispatch(
|
|
9782
9924
|
view.state.tr.setMeta(pluginKey, { node: null, pos: null, isDragging: false })
|
|
@@ -9785,7 +9927,7 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
|
|
|
9785
9927
|
}
|
|
9786
9928
|
const { node, pos } = block;
|
|
9787
9929
|
const element = view.nodeDOM(pos);
|
|
9788
|
-
if (!element || !
|
|
9930
|
+
if (!element || !isHTMLElement3(element)) {
|
|
9789
9931
|
view.dispatch(
|
|
9790
9932
|
view.state.tr.setMeta(pluginKey, { node: null, pos: null, isDragging: false })
|
|
9791
9933
|
);
|
|
@@ -9798,13 +9940,15 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
|
|
|
9798
9940
|
const parentElement = view.nodeDOM(parentPos);
|
|
9799
9941
|
const rect = findFirstLineRect(parentElement, element);
|
|
9800
9942
|
view.dispatch(
|
|
9801
|
-
view.state.tr.setMeta(pluginKey, {
|
|
9943
|
+
view.state.tr.setMeta(pluginKey, {
|
|
9944
|
+
node: parentNode,
|
|
9945
|
+
pos: parentPos,
|
|
9946
|
+
rect: rect || {}
|
|
9947
|
+
})
|
|
9802
9948
|
);
|
|
9803
9949
|
} else {
|
|
9804
9950
|
const rect = findFirstLineRect(void 0, element);
|
|
9805
|
-
view.dispatch(
|
|
9806
|
-
view.state.tr.setMeta(pluginKey, { node, pos, rect: rect || {} })
|
|
9807
|
-
);
|
|
9951
|
+
view.dispatch(view.state.tr.setMeta(pluginKey, { node, pos, rect: rect || {} }));
|
|
9808
9952
|
}
|
|
9809
9953
|
return false;
|
|
9810
9954
|
}
|
|
@@ -9813,6 +9957,9 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
|
|
|
9813
9957
|
};
|
|
9814
9958
|
}
|
|
9815
9959
|
};
|
|
9960
|
+
function selectionBetween(view, $anchor, $head, bias) {
|
|
9961
|
+
return view.someProp("createSelectionBetween", (f) => f(view, $anchor, $head)) || TextSelection11.between($anchor, $head, bias);
|
|
9962
|
+
}
|
|
9816
9963
|
|
|
9817
9964
|
// src/editor/extensions/Paragraph/paragraph-extension.ts
|
|
9818
9965
|
import { ParagraphExtension } from "@rme-sdk/main/extensions";
|
|
@@ -10537,7 +10684,7 @@ var LineCodeMirrorExtension = class extends NodeExtension12 {
|
|
|
10537
10684
|
const pos = tr.selection.$from.before();
|
|
10538
10685
|
const end = pos + nodeSize + 1;
|
|
10539
10686
|
tr.replaceWith(pos, end, this.type.create({ language }));
|
|
10540
|
-
tr.setSelection(
|
|
10687
|
+
tr.setSelection(TextSelection12.near(tr.doc.resolve(pos + 1)));
|
|
10541
10688
|
if (dispatch) {
|
|
10542
10689
|
dispatch(tr);
|
|
10543
10690
|
}
|
|
@@ -10652,7 +10799,7 @@ var LineCodeMirrorExtension = class extends NodeExtension12 {
|
|
|
10652
10799
|
type: this.type,
|
|
10653
10800
|
beforeDispatch: ({ tr, start }) => {
|
|
10654
10801
|
const $pos = tr.doc.resolve(start);
|
|
10655
|
-
tr.setSelection(
|
|
10802
|
+
tr.setSelection(TextSelection12.near($pos));
|
|
10656
10803
|
},
|
|
10657
10804
|
getAttributes
|
|
10658
10805
|
})
|
|
@@ -10866,16 +11013,31 @@ import { Remirror as Remirror2 } from "@rme-sdk/react";
|
|
|
10866
11013
|
import { memo as memo7, useCallback as useCallback19, useEffect as useEffect8, useMemo as useMemo5 } from "react";
|
|
10867
11014
|
|
|
10868
11015
|
// src/editor/toolbar/BlockHandler/index.tsx
|
|
10869
|
-
import { isHTMLElement as
|
|
10870
|
-
import { Selection as Selection4 } from "@rme-sdk/pm/state";
|
|
11016
|
+
import { isHTMLElement as isHTMLElement5 } from "@ocavue/utils";
|
|
10871
11017
|
import { useExtension, useRemirrorContext as useRemirrorContext3 } from "@rme-sdk/react-core";
|
|
10872
11018
|
import { useRef as useRef6 } from "react";
|
|
10873
11019
|
import styled10 from "styled-components";
|
|
10874
11020
|
|
|
10875
|
-
// src/editor/
|
|
10876
|
-
import { isHTMLElement as
|
|
11021
|
+
// src/editor/extensions/NodeIndicator/drag-preview.ts
|
|
11022
|
+
import { isHTMLElement as isHTMLElement4 } from "@ocavue/utils";
|
|
10877
11023
|
import { Fragment as Fragment6, Slice as Slice3 } from "@rme-sdk/pm";
|
|
10878
|
-
import { NodeSelection } from "@rme-sdk/pm/state";
|
|
11024
|
+
import { NodeSelection as NodeSelection3 } from "@rme-sdk/pm/state";
|
|
11025
|
+
|
|
11026
|
+
// src/editor/utils/get-box-element.ts
|
|
11027
|
+
function getBoxElement(element) {
|
|
11028
|
+
const window2 = element.ownerDocument.defaultView;
|
|
11029
|
+
if (!window2) {
|
|
11030
|
+
return;
|
|
11031
|
+
}
|
|
11032
|
+
const style = window2.getComputedStyle(element);
|
|
11033
|
+
const display = style.display;
|
|
11034
|
+
if (display === "contents" && element.childElementCount === 1) {
|
|
11035
|
+
return element.firstElementChild;
|
|
11036
|
+
} else if (display === "none") {
|
|
11037
|
+
return;
|
|
11038
|
+
}
|
|
11039
|
+
return element;
|
|
11040
|
+
}
|
|
10879
11041
|
|
|
10880
11042
|
// src/editor/extensions/NodeIndicator/set-drag-preview.ts
|
|
10881
11043
|
function setDragPreview(event2, element) {
|
|
@@ -10929,23 +11091,7 @@ function setDragPreview(event2, element) {
|
|
|
10929
11091
|
});
|
|
10930
11092
|
}
|
|
10931
11093
|
|
|
10932
|
-
// src/editor/
|
|
10933
|
-
function getBoxElement(element) {
|
|
10934
|
-
const window2 = element.ownerDocument.defaultView;
|
|
10935
|
-
if (!window2) {
|
|
10936
|
-
return;
|
|
10937
|
-
}
|
|
10938
|
-
const style = window2.getComputedStyle(element);
|
|
10939
|
-
const display = style.display;
|
|
10940
|
-
if (display === "contents" && element.childElementCount === 1) {
|
|
10941
|
-
return element.firstElementChild;
|
|
10942
|
-
} else if (display === "none") {
|
|
10943
|
-
return;
|
|
10944
|
-
}
|
|
10945
|
-
return element;
|
|
10946
|
-
}
|
|
10947
|
-
|
|
10948
|
-
// src/editor/toolbar/BlockHandler/drag-preview.ts
|
|
11094
|
+
// src/editor/extensions/NodeIndicator/drag-preview.ts
|
|
10949
11095
|
function createDraggingPreview(view, hoverState, event2) {
|
|
10950
11096
|
if (!event2.dataTransfer) {
|
|
10951
11097
|
return;
|
|
@@ -10955,11 +11101,11 @@ function createDraggingPreview(view, hoverState, event2) {
|
|
|
10955
11101
|
return;
|
|
10956
11102
|
}
|
|
10957
11103
|
const element = view.nodeDOM(pos);
|
|
10958
|
-
if (!element || !
|
|
11104
|
+
if (!element || !isHTMLElement4(element)) {
|
|
10959
11105
|
return;
|
|
10960
11106
|
}
|
|
10961
11107
|
const boxElement = getBoxElement(element);
|
|
10962
|
-
if (!boxElement || !
|
|
11108
|
+
if (!boxElement || !isHTMLElement4(boxElement)) {
|
|
10963
11109
|
return;
|
|
10964
11110
|
}
|
|
10965
11111
|
event2.dataTransfer.clearData();
|
|
@@ -10973,7 +11119,7 @@ function setViewDragging(view, hoverState) {
|
|
|
10973
11119
|
const dragging = {
|
|
10974
11120
|
slice: new Slice3(Fragment6.from(node), 0, 0),
|
|
10975
11121
|
move: true,
|
|
10976
|
-
node:
|
|
11122
|
+
node: NodeSelection3.create(view.state.doc, pos)
|
|
10977
11123
|
};
|
|
10978
11124
|
view.dragging = dragging;
|
|
10979
11125
|
}
|
|
@@ -10999,7 +11145,6 @@ var nodeTypeIconMap = {
|
|
|
10999
11145
|
var BlockHandler = () => {
|
|
11000
11146
|
const { view: editorView } = useRemirrorContext3({ autoUpdate: true });
|
|
11001
11147
|
const dragStartPos = useRef6(null);
|
|
11002
|
-
const isDragging = useRef6(false);
|
|
11003
11148
|
const nodeIndicatorExtension = useExtension(NodeIndicatorExtension);
|
|
11004
11149
|
const state = nodeIndicatorExtension.getPluginState();
|
|
11005
11150
|
const handleClick = () => {
|
|
@@ -11009,96 +11154,14 @@ var BlockHandler = () => {
|
|
|
11009
11154
|
const state2 = nodeIndicatorExtension.getPluginState();
|
|
11010
11155
|
if (state2 && state2.pos !== null && state2.node && state2.node.isBlock) {
|
|
11011
11156
|
dragStartPos.current = state2.pos;
|
|
11012
|
-
isDragging.current = true;
|
|
11013
11157
|
const dom = editorView.nodeDOM(state2.pos);
|
|
11014
|
-
if (dom &&
|
|
11158
|
+
if (dom && isHTMLElement5(dom)) {
|
|
11015
11159
|
createDraggingPreview(editorView, state2, event2);
|
|
11016
11160
|
setViewDragging(editorView, state2);
|
|
11017
11161
|
}
|
|
11018
|
-
editorView.dispatch(
|
|
11019
|
-
editorView.state.tr.setMeta(nodeIndicatorExtension.pluginKey, {
|
|
11020
|
-
isDragging: true,
|
|
11021
|
-
draggedNode: state2.node,
|
|
11022
|
-
draggedPos: state2.pos
|
|
11023
|
-
})
|
|
11024
|
-
);
|
|
11025
11162
|
}
|
|
11026
11163
|
}
|
|
11027
11164
|
};
|
|
11028
|
-
const handleDragEnd = () => {
|
|
11029
|
-
isDragging.current = false;
|
|
11030
|
-
const element = document.querySelector(".rme-block-handler");
|
|
11031
|
-
if (element) {
|
|
11032
|
-
element.style.opacity = "";
|
|
11033
|
-
element.style.transform = "";
|
|
11034
|
-
}
|
|
11035
|
-
if (editorView && nodeIndicatorExtension) {
|
|
11036
|
-
editorView.dispatch(
|
|
11037
|
-
editorView.state.tr.setMeta(nodeIndicatorExtension.pluginKey, {
|
|
11038
|
-
isDragging: false,
|
|
11039
|
-
draggedNode: null,
|
|
11040
|
-
draggedPos: null
|
|
11041
|
-
})
|
|
11042
|
-
);
|
|
11043
|
-
}
|
|
11044
|
-
};
|
|
11045
|
-
const handleDragOver = (event2) => {
|
|
11046
|
-
const hasProsemirrorData = event2.dataTransfer.types.includes(
|
|
11047
|
-
"application/x-prosemirror-node-pos"
|
|
11048
|
-
);
|
|
11049
|
-
if (hasProsemirrorData) {
|
|
11050
|
-
event2.preventDefault();
|
|
11051
|
-
event2.dataTransfer.dropEffect = "move";
|
|
11052
|
-
}
|
|
11053
|
-
};
|
|
11054
|
-
const handleDrop = (event2) => {
|
|
11055
|
-
console.log("handleDrop", editorView, nodeIndicatorExtension);
|
|
11056
|
-
if (!editorView || !nodeIndicatorExtension) return;
|
|
11057
|
-
const draggedPosStr = event2.dataTransfer.getData("application/x-prosemirror-node-pos");
|
|
11058
|
-
console.log("draggedPosStr", draggedPosStr);
|
|
11059
|
-
if (!draggedPosStr) return;
|
|
11060
|
-
const draggedPos = parseInt(draggedPosStr, 10);
|
|
11061
|
-
console.log("draggedPos", draggedPos);
|
|
11062
|
-
if (isNaN(draggedPos)) return;
|
|
11063
|
-
const draggedNode = editorView.state.doc.nodeAt(draggedPos);
|
|
11064
|
-
console.log("draggedNode", draggedNode);
|
|
11065
|
-
if (!draggedNode) return;
|
|
11066
|
-
const dropPosResult = editorView.posAtCoords({ left: event2.clientX, top: event2.clientY });
|
|
11067
|
-
console.log("dropPosResult", dropPosResult);
|
|
11068
|
-
if (!dropPosResult) return;
|
|
11069
|
-
const tr = editorView.state.tr;
|
|
11070
|
-
let dropPos = dropPosResult.pos;
|
|
11071
|
-
console.log("dropPos", dropPos);
|
|
11072
|
-
if (dropPos >= draggedPos && dropPos < draggedPos + draggedNode.nodeSize) {
|
|
11073
|
-
event2.preventDefault();
|
|
11074
|
-
return;
|
|
11075
|
-
}
|
|
11076
|
-
try {
|
|
11077
|
-
tr.delete(draggedPos, draggedPos + draggedNode.nodeSize);
|
|
11078
|
-
let insertPos = tr.mapping.map(dropPos);
|
|
11079
|
-
const $insertPos = tr.doc.resolve(insertPos);
|
|
11080
|
-
if ($insertPos.parent.type.spec.isTextblock) {
|
|
11081
|
-
if ($insertPos.depth > 0) {
|
|
11082
|
-
insertPos = $insertPos.before($insertPos.depth);
|
|
11083
|
-
}
|
|
11084
|
-
}
|
|
11085
|
-
tr.insert(insertPos, draggedNode);
|
|
11086
|
-
tr.setSelection(Selection4.near(tr.doc.resolve(insertPos + draggedNode.nodeSize)));
|
|
11087
|
-
editorView.dispatch(tr);
|
|
11088
|
-
} catch (error) {
|
|
11089
|
-
console.error("\u62D6\u62FD\u64CD\u4F5C\u5931\u8D25:", error);
|
|
11090
|
-
} finally {
|
|
11091
|
-
const dom = editorView.nodeDOM(draggedPos);
|
|
11092
|
-
if (dom && isHTMLElement4(dom)) {
|
|
11093
|
-
dom.classList.remove("node-indicator-dragging");
|
|
11094
|
-
}
|
|
11095
|
-
tr.setMeta(nodeIndicatorExtension.pluginKey, {
|
|
11096
|
-
isDragging: false
|
|
11097
|
-
});
|
|
11098
|
-
editorView.dispatch(tr);
|
|
11099
|
-
}
|
|
11100
|
-
event2.preventDefault();
|
|
11101
|
-
};
|
|
11102
11165
|
if (!editorView || !state?.node) {
|
|
11103
11166
|
return null;
|
|
11104
11167
|
}
|
|
@@ -11122,9 +11185,6 @@ var BlockHandler = () => {
|
|
|
11122
11185
|
draggable: "true",
|
|
11123
11186
|
onClick: handleClick,
|
|
11124
11187
|
onDragStart: handleDragStart,
|
|
11125
|
-
onDragOver: handleDragOver,
|
|
11126
|
-
onDrop: handleDrop,
|
|
11127
|
-
onDragEnd: handleDragEnd,
|
|
11128
11188
|
style: {
|
|
11129
11189
|
position: "fixed",
|
|
11130
11190
|
left: `${state?.rect?.left ? state.rect.left - 38 : 0}px`,
|