rme 0.2.5-alpha.13 → 0.2.5-alpha.15
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 +195 -133
- package/dist/index.mjs.map +4 -4
- package/package.json +10 -10
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,58 @@ 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
|
+
console.log("handleDrop", view, event2, slice, move);
|
|
9879
|
+
if (!getTarget) return false;
|
|
9880
|
+
const target = getTarget([event2.clientX, event2.clientY], event2);
|
|
9881
|
+
if (!target) return false;
|
|
9882
|
+
event2.preventDefault();
|
|
9883
|
+
let insertPos = target[0];
|
|
9884
|
+
let tr = view.state.tr;
|
|
9885
|
+
if (move) {
|
|
9886
|
+
const ext = view.state.plugins.find((plugin) => {
|
|
9887
|
+
return plugin.spec.initialState?.isDragging === false;
|
|
9888
|
+
});
|
|
9889
|
+
const state = ext?.getState(view.state) || {};
|
|
9890
|
+
const { node: draggingNode, pos: draggingPos } = state;
|
|
9891
|
+
console.log("extstate", state);
|
|
9892
|
+
if (!draggingNode || !draggingPos) return false;
|
|
9893
|
+
tr = tr.delete(draggingPos, draggingPos + draggingNode.nodeSize);
|
|
9894
|
+
let { node } = view.dragging || {};
|
|
9895
|
+
if (node) node.replace(tr);
|
|
9896
|
+
else tr.deleteSelection();
|
|
9897
|
+
}
|
|
9898
|
+
let pos = tr.mapping.map(insertPos);
|
|
9899
|
+
let isNode = slice.openStart == 0 && slice.openEnd == 0 && slice.content.childCount == 1;
|
|
9900
|
+
let beforeInsert = tr.doc;
|
|
9901
|
+
if (isNode) tr.replaceRangeWith(pos, pos, slice.content.firstChild);
|
|
9902
|
+
else tr.replaceRange(pos, pos, slice);
|
|
9903
|
+
if (tr.doc.eq(beforeInsert)) {
|
|
9904
|
+
return true;
|
|
9905
|
+
}
|
|
9906
|
+
let $pos = tr.doc.resolve(pos);
|
|
9907
|
+
if (isNode && NodeSelection2.isSelectable(slice.content.firstChild) && $pos.nodeAfter && $pos.nodeAfter.sameMarkup(slice.content.firstChild)) {
|
|
9908
|
+
tr.setSelection(new NodeSelection2($pos));
|
|
9909
|
+
} else {
|
|
9910
|
+
let end = tr.mapping.map(insertPos);
|
|
9911
|
+
tr.mapping.maps[tr.mapping.maps.length - 1].forEach(
|
|
9912
|
+
(_from, _to, _newFrom, newTo) => end = newTo
|
|
9913
|
+
);
|
|
9914
|
+
tr.setSelection(selectionBetween(view, $pos, tr.doc.resolve(end)));
|
|
9915
|
+
}
|
|
9916
|
+
view.focus();
|
|
9917
|
+
view.dispatch(tr.setMeta("uiEvent", "drop"));
|
|
9918
|
+
return true;
|
|
9919
|
+
},
|
|
9775
9920
|
handleDOMEvents: {
|
|
9776
9921
|
pointermove: (view, event2) => {
|
|
9777
9922
|
const { x, y } = event2;
|
|
9778
9923
|
const block = findBlockByCoords(view, x, y);
|
|
9779
|
-
console.log("block", block?.node.type);
|
|
9780
9924
|
if (!block) {
|
|
9781
9925
|
view.dispatch(
|
|
9782
9926
|
view.state.tr.setMeta(pluginKey, { node: null, pos: null, isDragging: false })
|
|
@@ -9785,7 +9929,7 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
|
|
|
9785
9929
|
}
|
|
9786
9930
|
const { node, pos } = block;
|
|
9787
9931
|
const element = view.nodeDOM(pos);
|
|
9788
|
-
if (!element || !
|
|
9932
|
+
if (!element || !isHTMLElement3(element)) {
|
|
9789
9933
|
view.dispatch(
|
|
9790
9934
|
view.state.tr.setMeta(pluginKey, { node: null, pos: null, isDragging: false })
|
|
9791
9935
|
);
|
|
@@ -9798,13 +9942,15 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
|
|
|
9798
9942
|
const parentElement = view.nodeDOM(parentPos);
|
|
9799
9943
|
const rect = findFirstLineRect(parentElement, element);
|
|
9800
9944
|
view.dispatch(
|
|
9801
|
-
view.state.tr.setMeta(pluginKey, {
|
|
9945
|
+
view.state.tr.setMeta(pluginKey, {
|
|
9946
|
+
node: parentNode,
|
|
9947
|
+
pos: parentPos,
|
|
9948
|
+
rect: rect || {}
|
|
9949
|
+
})
|
|
9802
9950
|
);
|
|
9803
9951
|
} else {
|
|
9804
9952
|
const rect = findFirstLineRect(void 0, element);
|
|
9805
|
-
view.dispatch(
|
|
9806
|
-
view.state.tr.setMeta(pluginKey, { node, pos, rect: rect || {} })
|
|
9807
|
-
);
|
|
9953
|
+
view.dispatch(view.state.tr.setMeta(pluginKey, { node, pos, rect: rect || {} }));
|
|
9808
9954
|
}
|
|
9809
9955
|
return false;
|
|
9810
9956
|
}
|
|
@@ -9813,6 +9959,9 @@ var NodeIndicatorExtension = class extends PlainExtension7 {
|
|
|
9813
9959
|
};
|
|
9814
9960
|
}
|
|
9815
9961
|
};
|
|
9962
|
+
function selectionBetween(view, $anchor, $head, bias) {
|
|
9963
|
+
return view.someProp("createSelectionBetween", (f) => f(view, $anchor, $head)) || TextSelection11.between($anchor, $head, bias);
|
|
9964
|
+
}
|
|
9816
9965
|
|
|
9817
9966
|
// src/editor/extensions/Paragraph/paragraph-extension.ts
|
|
9818
9967
|
import { ParagraphExtension } from "@rme-sdk/main/extensions";
|
|
@@ -10537,7 +10686,7 @@ var LineCodeMirrorExtension = class extends NodeExtension12 {
|
|
|
10537
10686
|
const pos = tr.selection.$from.before();
|
|
10538
10687
|
const end = pos + nodeSize + 1;
|
|
10539
10688
|
tr.replaceWith(pos, end, this.type.create({ language }));
|
|
10540
|
-
tr.setSelection(
|
|
10689
|
+
tr.setSelection(TextSelection12.near(tr.doc.resolve(pos + 1)));
|
|
10541
10690
|
if (dispatch) {
|
|
10542
10691
|
dispatch(tr);
|
|
10543
10692
|
}
|
|
@@ -10652,7 +10801,7 @@ var LineCodeMirrorExtension = class extends NodeExtension12 {
|
|
|
10652
10801
|
type: this.type,
|
|
10653
10802
|
beforeDispatch: ({ tr, start }) => {
|
|
10654
10803
|
const $pos = tr.doc.resolve(start);
|
|
10655
|
-
tr.setSelection(
|
|
10804
|
+
tr.setSelection(TextSelection12.near($pos));
|
|
10656
10805
|
},
|
|
10657
10806
|
getAttributes
|
|
10658
10807
|
})
|
|
@@ -10866,16 +11015,31 @@ import { Remirror as Remirror2 } from "@rme-sdk/react";
|
|
|
10866
11015
|
import { memo as memo7, useCallback as useCallback19, useEffect as useEffect8, useMemo as useMemo5 } from "react";
|
|
10867
11016
|
|
|
10868
11017
|
// src/editor/toolbar/BlockHandler/index.tsx
|
|
10869
|
-
import { isHTMLElement as
|
|
10870
|
-
import { Selection as Selection4 } from "@rme-sdk/pm/state";
|
|
11018
|
+
import { isHTMLElement as isHTMLElement5 } from "@ocavue/utils";
|
|
10871
11019
|
import { useExtension, useRemirrorContext as useRemirrorContext3 } from "@rme-sdk/react-core";
|
|
10872
11020
|
import { useRef as useRef6 } from "react";
|
|
10873
11021
|
import styled10 from "styled-components";
|
|
10874
11022
|
|
|
10875
|
-
// src/editor/
|
|
10876
|
-
import { isHTMLElement as
|
|
11023
|
+
// src/editor/extensions/NodeIndicator/drag-preview.ts
|
|
11024
|
+
import { isHTMLElement as isHTMLElement4 } from "@ocavue/utils";
|
|
10877
11025
|
import { Fragment as Fragment6, Slice as Slice3 } from "@rme-sdk/pm";
|
|
10878
|
-
import { NodeSelection } from "@rme-sdk/pm/state";
|
|
11026
|
+
import { NodeSelection as NodeSelection3 } from "@rme-sdk/pm/state";
|
|
11027
|
+
|
|
11028
|
+
// src/editor/utils/get-box-element.ts
|
|
11029
|
+
function getBoxElement(element) {
|
|
11030
|
+
const window2 = element.ownerDocument.defaultView;
|
|
11031
|
+
if (!window2) {
|
|
11032
|
+
return;
|
|
11033
|
+
}
|
|
11034
|
+
const style = window2.getComputedStyle(element);
|
|
11035
|
+
const display = style.display;
|
|
11036
|
+
if (display === "contents" && element.childElementCount === 1) {
|
|
11037
|
+
return element.firstElementChild;
|
|
11038
|
+
} else if (display === "none") {
|
|
11039
|
+
return;
|
|
11040
|
+
}
|
|
11041
|
+
return element;
|
|
11042
|
+
}
|
|
10879
11043
|
|
|
10880
11044
|
// src/editor/extensions/NodeIndicator/set-drag-preview.ts
|
|
10881
11045
|
function setDragPreview(event2, element) {
|
|
@@ -10929,23 +11093,7 @@ function setDragPreview(event2, element) {
|
|
|
10929
11093
|
});
|
|
10930
11094
|
}
|
|
10931
11095
|
|
|
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
|
|
11096
|
+
// src/editor/extensions/NodeIndicator/drag-preview.ts
|
|
10949
11097
|
function createDraggingPreview(view, hoverState, event2) {
|
|
10950
11098
|
if (!event2.dataTransfer) {
|
|
10951
11099
|
return;
|
|
@@ -10955,11 +11103,11 @@ function createDraggingPreview(view, hoverState, event2) {
|
|
|
10955
11103
|
return;
|
|
10956
11104
|
}
|
|
10957
11105
|
const element = view.nodeDOM(pos);
|
|
10958
|
-
if (!element || !
|
|
11106
|
+
if (!element || !isHTMLElement4(element)) {
|
|
10959
11107
|
return;
|
|
10960
11108
|
}
|
|
10961
11109
|
const boxElement = getBoxElement(element);
|
|
10962
|
-
if (!boxElement || !
|
|
11110
|
+
if (!boxElement || !isHTMLElement4(boxElement)) {
|
|
10963
11111
|
return;
|
|
10964
11112
|
}
|
|
10965
11113
|
event2.dataTransfer.clearData();
|
|
@@ -10973,7 +11121,7 @@ function setViewDragging(view, hoverState) {
|
|
|
10973
11121
|
const dragging = {
|
|
10974
11122
|
slice: new Slice3(Fragment6.from(node), 0, 0),
|
|
10975
11123
|
move: true,
|
|
10976
|
-
node:
|
|
11124
|
+
node: NodeSelection3.create(view.state.doc, pos)
|
|
10977
11125
|
};
|
|
10978
11126
|
view.dragging = dragging;
|
|
10979
11127
|
}
|
|
@@ -10999,7 +11147,6 @@ var nodeTypeIconMap = {
|
|
|
10999
11147
|
var BlockHandler = () => {
|
|
11000
11148
|
const { view: editorView } = useRemirrorContext3({ autoUpdate: true });
|
|
11001
11149
|
const dragStartPos = useRef6(null);
|
|
11002
|
-
const isDragging = useRef6(false);
|
|
11003
11150
|
const nodeIndicatorExtension = useExtension(NodeIndicatorExtension);
|
|
11004
11151
|
const state = nodeIndicatorExtension.getPluginState();
|
|
11005
11152
|
const handleClick = () => {
|
|
@@ -11009,96 +11156,14 @@ var BlockHandler = () => {
|
|
|
11009
11156
|
const state2 = nodeIndicatorExtension.getPluginState();
|
|
11010
11157
|
if (state2 && state2.pos !== null && state2.node && state2.node.isBlock) {
|
|
11011
11158
|
dragStartPos.current = state2.pos;
|
|
11012
|
-
isDragging.current = true;
|
|
11013
11159
|
const dom = editorView.nodeDOM(state2.pos);
|
|
11014
|
-
if (dom &&
|
|
11160
|
+
if (dom && isHTMLElement5(dom)) {
|
|
11015
11161
|
createDraggingPreview(editorView, state2, event2);
|
|
11016
11162
|
setViewDragging(editorView, state2);
|
|
11017
11163
|
}
|
|
11018
|
-
editorView.dispatch(
|
|
11019
|
-
editorView.state.tr.setMeta(nodeIndicatorExtension.pluginKey, {
|
|
11020
|
-
isDragging: true,
|
|
11021
|
-
draggedNode: state2.node,
|
|
11022
|
-
draggedPos: state2.pos
|
|
11023
|
-
})
|
|
11024
|
-
);
|
|
11025
11164
|
}
|
|
11026
11165
|
}
|
|
11027
11166
|
};
|
|
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
11167
|
if (!editorView || !state?.node) {
|
|
11103
11168
|
return null;
|
|
11104
11169
|
}
|
|
@@ -11122,9 +11187,6 @@ var BlockHandler = () => {
|
|
|
11122
11187
|
draggable: "true",
|
|
11123
11188
|
onClick: handleClick,
|
|
11124
11189
|
onDragStart: handleDragStart,
|
|
11125
|
-
onDragOver: handleDragOver,
|
|
11126
|
-
onDrop: handleDrop,
|
|
11127
|
-
onDragEnd: handleDragEnd,
|
|
11128
11190
|
style: {
|
|
11129
11191
|
position: "fixed",
|
|
11130
11192
|
left: `${state?.rect?.left ? state.rect.left - 38 : 0}px`,
|