@trafica/editor 1.0.46 → 1.0.47

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.js CHANGED
@@ -8519,19 +8519,17 @@ function EditorCore({
8519
8519
  e.preventDefault();
8520
8520
  const path = JSON.parse(fig.dataset.imagePath);
8521
8521
  setSelectedImagePath(path);
8522
- if (path.length === 1) {
8523
- const imgEl = fig.querySelector("img");
8524
- const rect = imgEl == null ? void 0 : imgEl.getBoundingClientRect();
8525
- imageDragRef.current = {
8526
- imagePath: path,
8527
- startX: e.clientX,
8528
- startY: e.clientY,
8529
- active: false,
8530
- ghostW: Math.min((rect == null ? void 0 : rect.width) || 300, 320),
8531
- ghostH: Math.min((rect == null ? void 0 : rect.height) || 200, 200),
8532
- ghostSrc: (imgEl == null ? void 0 : imgEl.src) || ""
8533
- };
8534
- }
8522
+ const imgEl = fig.querySelector("img");
8523
+ const rect = imgEl == null ? void 0 : imgEl.getBoundingClientRect();
8524
+ imageDragRef.current = {
8525
+ imagePath: path,
8526
+ startX: e.clientX,
8527
+ startY: e.clientY,
8528
+ active: false,
8529
+ ghostW: Math.min((rect == null ? void 0 : rect.width) || 300, 320),
8530
+ ghostH: Math.min((rect == null ? void 0 : rect.height) || 200, 200),
8531
+ ghostSrc: (imgEl == null ? void 0 : imgEl.src) || ""
8532
+ };
8535
8533
  return;
8536
8534
  }
8537
8535
  setSelectedImagePath(null);
@@ -8921,14 +8919,19 @@ function moveImageInDoc(imagePath, targetIndex, engine) {
8921
8919
  const state = engine.getState();
8922
8920
  const imageNode = getNodeAtPath(state.doc, imagePath);
8923
8921
  if (!imageNode) return;
8924
- const oldIndex = imagePath[imagePath.length - 1];
8925
- const parentPath = imagePath.slice(0, -1);
8926
- let adj = targetIndex > oldIndex ? targetIndex - 1 : targetIndex;
8927
- adj = Math.max(0, Math.min(state.doc.children.length - 1, adj));
8928
- if (adj === oldIndex) return;
8922
+ const isTopLevel = imagePath.length === 1;
8923
+ const topLevelIndex = imagePath[0];
8924
+ let adj = targetIndex;
8925
+ if (isTopLevel) {
8926
+ if (targetIndex > topLevelIndex) adj = targetIndex - 1;
8927
+ adj = Math.max(0, Math.min(state.doc.children.length - 1, adj));
8928
+ if (adj === topLevelIndex) return;
8929
+ } else {
8930
+ adj = Math.max(0, Math.min(state.doc.children.length, adj));
8931
+ }
8929
8932
  const tr = createTransaction();
8930
8933
  tr.steps.push({ type: "delete_node", path: imagePath });
8931
- tr.steps.push({ type: "insert_node", parentPath, index: adj, node: imageNode });
8934
+ tr.steps.push({ type: "insert_node", parentPath: [], index: adj, node: imageNode });
8932
8935
  engine.dispatch(tr);
8933
8936
  }
8934
8937
  var BLOCK_TAGS = "p|h[1-6]|ul|ol|li|blockquote|pre|figure|table|thead|tbody|tr|th|td";