@use-kona/editor 0.1.22 → 0.1.23
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.
|
@@ -3,7 +3,7 @@ import { map } from "nanostores";
|
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { useDrag, useDrop } from "react-dnd";
|
|
5
5
|
import { NativeTypes } from "react-dnd-html5-backend";
|
|
6
|
-
import { Editor, Transforms } from "slate";
|
|
6
|
+
import { Editor, Path, Transforms } from "slate";
|
|
7
7
|
import { ReactEditor, useReadOnly, useSlate } from "slate-react";
|
|
8
8
|
class DnDPlugin {
|
|
9
9
|
options;
|
|
@@ -78,7 +78,7 @@ class DnDPlugin {
|
|
|
78
78
|
const itemType = monitor.getItemType();
|
|
79
79
|
const sourceTo = ReactEditor.findPath(editor, props.element);
|
|
80
80
|
if (!sourceTo) return;
|
|
81
|
-
const dropPath = getDropPath(editor, sourceTo);
|
|
81
|
+
const dropPath = getDropPath(editor, sourceTo, dropPosition || 'bottom');
|
|
82
82
|
if (!dropPath) return;
|
|
83
83
|
switch(itemType){
|
|
84
84
|
case NativeTypes.FILE:
|
|
@@ -88,7 +88,7 @@ class DnDPlugin {
|
|
|
88
88
|
{
|
|
89
89
|
const dragItem = item;
|
|
90
90
|
if (!dropPosition || !dragItem.nodeIds?.length) return;
|
|
91
|
-
moveNode(editor, sourceTo, dragItem.nodeIds);
|
|
91
|
+
moveNode(editor, sourceTo, dragItem.nodeIds, dropPosition);
|
|
92
92
|
$store.selected.clear();
|
|
93
93
|
break;
|
|
94
94
|
}
|
|
@@ -120,12 +120,17 @@ class DnDPlugin {
|
|
|
120
120
|
});
|
|
121
121
|
};
|
|
122
122
|
}
|
|
123
|
-
const getDropPath = (editor, targetNodePath)=>{
|
|
123
|
+
const getDropPath = (editor, targetNodePath, position)=>{
|
|
124
124
|
const target = Editor.node(editor, targetNodePath);
|
|
125
|
-
|
|
125
|
+
switch(position){
|
|
126
|
+
case 'top':
|
|
127
|
+
return target[1];
|
|
128
|
+
case 'bottom':
|
|
129
|
+
return Path.next(target[1]);
|
|
130
|
+
}
|
|
126
131
|
};
|
|
127
|
-
const moveNode = (editor, targetNodePath, nodeIds)=>{
|
|
128
|
-
const dropPath = getDropPath(editor, targetNodePath);
|
|
132
|
+
const moveNode = (editor, targetNodePath, nodeIds, position)=>{
|
|
133
|
+
const dropPath = getDropPath(editor, targetNodePath, position);
|
|
129
134
|
if (!dropPath) return;
|
|
130
135
|
if (!Editor.hasPath(editor, dropPath)) return;
|
|
131
136
|
Editor.withoutNormalizing(editor, ()=>{
|
package/package.json
CHANGED
|
@@ -154,7 +154,7 @@ export class DnDPlugin implements IPlugin {
|
|
|
154
154
|
|
|
155
155
|
if (!sourceTo) return;
|
|
156
156
|
|
|
157
|
-
const dropPath = getDropPath(editor, sourceTo);
|
|
157
|
+
const dropPath = getDropPath(editor, sourceTo, dropPosition || 'bottom');
|
|
158
158
|
|
|
159
159
|
if (!dropPath) return;
|
|
160
160
|
|
|
@@ -173,7 +173,7 @@ export class DnDPlugin implements IPlugin {
|
|
|
173
173
|
return;
|
|
174
174
|
}
|
|
175
175
|
|
|
176
|
-
moveNode(editor, sourceTo, dragItem.nodeIds);
|
|
176
|
+
moveNode(editor, sourceTo, dragItem.nodeIds, dropPosition);
|
|
177
177
|
$store.selected.clear();
|
|
178
178
|
break;
|
|
179
179
|
}
|
|
@@ -223,18 +223,25 @@ export class DnDPlugin implements IPlugin {
|
|
|
223
223
|
const getDropPath = (
|
|
224
224
|
editor: Editor,
|
|
225
225
|
targetNodePath: Path,
|
|
226
|
+
position: 'top' | 'bottom',
|
|
226
227
|
) => {
|
|
227
228
|
const target = Editor.node(editor, targetNodePath);
|
|
228
229
|
|
|
229
|
-
|
|
230
|
+
switch (position) {
|
|
231
|
+
case 'top':
|
|
232
|
+
return target[1];
|
|
233
|
+
case 'bottom':
|
|
234
|
+
return Path.next(target[1]);
|
|
235
|
+
}
|
|
230
236
|
};
|
|
231
237
|
|
|
232
238
|
const moveNode = (
|
|
233
239
|
editor: Editor,
|
|
234
240
|
targetNodePath: Path,
|
|
235
241
|
nodeIds: string[],
|
|
242
|
+
position: 'top' | 'bottom',
|
|
236
243
|
) => {
|
|
237
|
-
const dropPath = getDropPath(editor, targetNodePath);
|
|
244
|
+
const dropPath = getDropPath(editor, targetNodePath, position);
|
|
238
245
|
|
|
239
246
|
if (!dropPath) return;
|
|
240
247
|
if (!Editor.hasPath(editor, dropPath)) {
|