@use-kona/editor 0.1.24-dnd.4 → 0.1.24-dnd.6

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.
@@ -46,21 +46,23 @@ class DnDPlugin {
46
46
  const isReadOnly = useReadOnly();
47
47
  const [dropPosition, setDropPosition] = useState(null);
48
48
  const dropTargetRef = useRef(null);
49
- options.customTypes?.[props.element.type];
49
+ const customType = options.customTypes?.[props.element.type];
50
50
  const currentElement = props.element;
51
51
  const [, drag, preview] = useDrag({
52
- type: DnDPlugin.DND_BLOCK_ELEMENT,
52
+ type: customType?.type || DnDPlugin.DND_BLOCK_ELEMENT,
53
53
  item: ()=>{
54
54
  const selected = Array.from($store.selected.values());
55
55
  const nodes = selected.length > 0 && selected.includes(currentElement.nodeId) ? getNodesByNodeIds(editor, selected) : [
56
56
  structuredClone(props.element)
57
57
  ];
58
+ const item = this.options.customTypes?.[currentElement.type].getData?.(currentElement);
58
59
  const items = nodes.map((node)=>{
59
60
  if (this.options.customTypes?.[node.type]) return this.options.customTypes[node.type].getData?.(node);
60
61
  return null;
61
62
  }).filter(Boolean);
62
63
  const dragItem = {
63
64
  nodes,
65
+ item,
64
66
  items,
65
67
  source: {
66
68
  editorId: this.getEditorId(editor),
@@ -105,17 +107,11 @@ class DnDPlugin {
105
107
  const insertAt = getDropPath(editor, sourceTo, dropPosition || 'bottom');
106
108
  if (!insertAt) return;
107
109
  const customDropHandler = itemType && options.customDropHandlers?.[itemType];
108
- if (customDropHandler) {
109
- console.log('customDropHandler.onDrop', itemType);
110
- customDropHandler.onDrop({
111
- editor,
112
- item,
113
- insertAt
114
- });
115
- return;
116
- }
117
- console.log('customDropHandler not found', itemType);
118
- options.customDropHandlers && console.log('valid drop handlers are', Object.keys(options.customDropHandlers));
110
+ if (customDropHandler) return void customDropHandler.onDrop({
111
+ editor,
112
+ item,
113
+ insertAt
114
+ });
119
115
  switch(itemType){
120
116
  case NativeTypes.FILE:
121
117
  options.onDropFiles(editor, item.files, insertAt);
@@ -44,6 +44,7 @@ type DropResult = 'handled' | 'ignored';
44
44
  */
45
45
  export type EditorDragItem = {
46
46
  nodes: NodeWithId[];
47
+ item?: unknown;
47
48
  items?: unknown[];
48
49
  source: {
49
50
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@use-kona/editor",
3
- "version": "0.1.24-dnd.4",
3
+ "version": "0.1.24-dnd.6",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./src/index.ts"
@@ -76,7 +76,7 @@ export class DnDPlugin implements IPlugin {
76
76
  const currentElement = props.element as NodeWithId;
77
77
 
78
78
  const [, drag, preview] = useDrag({
79
- type: DnDPlugin.DND_BLOCK_ELEMENT,
79
+ type: customType?.type || DnDPlugin.DND_BLOCK_ELEMENT,
80
80
  item: () => {
81
81
  const selected = Array.from($store.selected.values());
82
82
 
@@ -90,6 +90,11 @@ export class DnDPlugin implements IPlugin {
90
90
  ? getNodesByNodeIds(editor, selected)
91
91
  : [structuredClone(props.element as NodeWithId)];
92
92
 
93
+ const item =
94
+ this.options.customTypes?.[currentElement.type].getData?.(
95
+ currentElement,
96
+ );
97
+
93
98
  const items = nodes
94
99
  .map((node) => {
95
100
  if (this.options.customTypes?.[node.type]) {
@@ -101,6 +106,7 @@ export class DnDPlugin implements IPlugin {
101
106
 
102
107
  const dragItem: EditorDragItem = {
103
108
  nodes,
109
+ item,
104
110
  items,
105
111
  source: {
106
112
  editorId: this.getEditorId(editor),
@@ -170,16 +176,8 @@ export class DnDPlugin implements IPlugin {
170
176
  itemType && options.customDropHandlers?.[itemType];
171
177
 
172
178
  if (customDropHandler) {
173
- console.log('customDropHandler.onDrop', itemType);
174
179
  customDropHandler.onDrop({ editor, item, insertAt });
175
180
  return;
176
- } else {
177
- console.log('customDropHandler not found', itemType);
178
- options.customDropHandlers &&
179
- console.log(
180
- 'valid drop handlers are',
181
- Object.keys(options.customDropHandlers),
182
- );
183
181
  }
184
182
 
185
183
  switch (itemType) {
@@ -59,6 +59,7 @@ type DropResult = 'handled' | 'ignored';
59
59
  */
60
60
  export type EditorDragItem = {
61
61
  nodes: NodeWithId[];
62
+ item?: unknown;
62
63
  items?: unknown[];
63
64
  source: {
64
65
  /**