made-refine 0.2.18-beta.0 → 0.2.19

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.d.mts CHANGED
@@ -98,6 +98,7 @@ interface DirectEditActionsContextValue {
98
98
  startTextEditing: (element: HTMLElement) => void;
99
99
  commitTextEditing: () => void;
100
100
  groupSelection: () => void;
101
+ deleteSelection: () => void;
101
102
  insertElement: (kind: CanvasElementKind) => void;
102
103
  toggleCanvas: () => void;
103
104
  setCanvasZoom: (zoom: number) => void;
package/dist/index.d.ts CHANGED
@@ -98,6 +98,7 @@ interface DirectEditActionsContextValue {
98
98
  startTextEditing: (element: HTMLElement) => void;
99
99
  commitTextEditing: () => void;
100
100
  groupSelection: () => void;
101
+ deleteSelection: () => void;
101
102
  insertElement: (kind: CanvasElementKind) => void;
102
103
  toggleCanvas: () => void;
103
104
  setCanvasZoom: (zoom: number) => void;
package/dist/index.js CHANGED
@@ -4454,6 +4454,49 @@ function useSessionManager({
4454
4454
  pushUndo: false
4455
4455
  });
4456
4456
  }, [applySelection, buildSelectionSnapshot, getSanitizedSelection, pushUndo, saveCurrentToSession, stateRef]);
4457
+ const deleteSelection = React3.useCallback(() => {
4458
+ const selected = getSanitizedSelection(stateRef.current.selectedElements);
4459
+ if (selected.length === 0 || !stateRef.current.editModeActive) return;
4460
+ if (selected.some((el) => el === document.body || !el.parentElement)) return;
4461
+ saveCurrentToSession();
4462
+ const restoreSelection = buildSelectionSnapshot();
4463
+ const snapshots = selected.map((el) => ({
4464
+ element: el,
4465
+ parent: el.parentElement,
4466
+ nextSibling: el.nextSibling
4467
+ }));
4468
+ const sessionSnapshots = /* @__PURE__ */ new Map();
4469
+ for (const el of selected) {
4470
+ const edit = sessionEditsRef.current.get(el);
4471
+ if (edit) sessionSnapshots.set(el, edit);
4472
+ sessionEditsRef.current.delete(el);
4473
+ }
4474
+ syncSessionItemCount();
4475
+ for (const { element } of snapshots) {
4476
+ if (element.isConnected) element.remove();
4477
+ }
4478
+ pushUndo({
4479
+ type: "structure",
4480
+ restoreSelection,
4481
+ undo: () => {
4482
+ for (let i = snapshots.length - 1; i >= 0; i--) {
4483
+ const { element, parent, nextSibling } = snapshots[i];
4484
+ if (!element.isConnected && parent.isConnected) {
4485
+ if (nextSibling && nextSibling.parentNode === parent) {
4486
+ parent.insertBefore(element, nextSibling);
4487
+ } else {
4488
+ parent.appendChild(element);
4489
+ }
4490
+ }
4491
+ }
4492
+ for (const [el, edit] of sessionSnapshots) {
4493
+ sessionEditsRef.current.set(el, edit);
4494
+ }
4495
+ syncSessionItemCount();
4496
+ }
4497
+ });
4498
+ applySelection([], { primaryElement: null, pushUndo: false });
4499
+ }, [applySelection, buildSelectionSnapshot, getSanitizedSelection, pushUndo, saveCurrentToSession, stateRef, syncSessionItemCount]);
4457
4500
  const resetToOriginal = React3.useCallback(() => {
4458
4501
  const current = stateRef.current;
4459
4502
  const el = current.selectedElement;
@@ -4990,6 +5033,7 @@ ${exportMarkdown}`);
4990
5033
  selectChild,
4991
5034
  insertElement,
4992
5035
  groupSelection,
5036
+ deleteSelection,
4993
5037
  resetToOriginal,
4994
5038
  undo,
4995
5039
  handleMoveComplete,
@@ -5883,6 +5927,7 @@ function useKeyboardShortcuts({
5883
5927
  closePanel,
5884
5928
  clearSelection,
5885
5929
  groupSelection,
5930
+ deleteSelection,
5886
5931
  insertElement,
5887
5932
  setState,
5888
5933
  toggleCanvas,
@@ -5970,6 +6015,13 @@ function useKeyboardShortcuts({
5970
6015
  return;
5971
6016
  }
5972
6017
  }
6018
+ if ((e.key === "Backspace" || e.key === "Delete") && s.editModeActive && !s.textEditingElement) {
6019
+ if (!isInputFocused() && s.selectedElements.length > 0) {
6020
+ e.preventDefault();
6021
+ deleteSelection();
6022
+ return;
6023
+ }
6024
+ }
5973
6025
  if (e.key === "Enter" && s.editModeActive && !s.textEditingElement && s.selectedElement) {
5974
6026
  if (!isInputFocused() && isTextElement2(s.selectedElement)) {
5975
6027
  e.preventDefault();
@@ -6002,7 +6054,7 @@ function useKeyboardShortcuts({
6002
6054
  }
6003
6055
  window.addEventListener("keydown", handleKeyDown);
6004
6056
  return () => window.removeEventListener("keydown", handleKeyDown);
6005
- }, [clearSelection, closePanel, commitTextEditing, fitCanvasToViewport, groupSelection, insertElement, setCanvasZoom, setState, startTextEditing, toggleCanvas, toggleEditMode, toggleFlexLayout, undo, usesMetaForUndo, zoomCanvasTo100]);
6057
+ }, [clearSelection, closePanel, commitTextEditing, deleteSelection, fitCanvasToViewport, groupSelection, insertElement, setCanvasZoom, setState, startTextEditing, toggleCanvas, toggleEditMode, toggleFlexLayout, undo, usesMetaForUndo, zoomCanvasTo100]);
6006
6058
  }
6007
6059
 
6008
6060
  // src/use-canvas.ts
@@ -6652,6 +6704,7 @@ function DirectEditProvider({ children }) {
6652
6704
  removeSessionEdit,
6653
6705
  clearSessionEdits,
6654
6706
  groupSelection,
6707
+ deleteSelection,
6655
6708
  insertElement
6656
6709
  } = useSessionManager({
6657
6710
  stateRef,
@@ -6880,6 +6933,7 @@ function DirectEditProvider({ children }) {
6880
6933
  setState,
6881
6934
  clearSelection,
6882
6935
  groupSelection,
6936
+ deleteSelection,
6883
6937
  insertElement,
6884
6938
  toggleCanvas: toggleCanvasWithPreference,
6885
6939
  setCanvasZoom,
@@ -6947,6 +7001,7 @@ function DirectEditProvider({ children }) {
6947
7001
  startTextEditing,
6948
7002
  commitTextEditing,
6949
7003
  groupSelection,
7004
+ deleteSelection,
6950
7005
  insertElement,
6951
7006
  toggleCanvas: toggleCanvasWithPreference,
6952
7007
  setCanvasZoom,
@@ -6999,6 +7054,7 @@ function DirectEditProvider({ children }) {
6999
7054
  startTextEditing,
7000
7055
  commitTextEditing,
7001
7056
  groupSelection,
7057
+ deleteSelection,
7002
7058
  insertElement,
7003
7059
  toggleCanvasWithPreference,
7004
7060
  setCanvasZoom,
@@ -7622,6 +7678,8 @@ function useMove({ onMoveComplete }) {
7622
7678
  React12.useEffect(() => {
7623
7679
  if (!dragState.isDragging) return;
7624
7680
  function handlePointerMove(e) {
7681
+ e.stopPropagation();
7682
+ e.preventDefault();
7625
7683
  const current = dragStateRef.current;
7626
7684
  const { draggedElement, dragOffset, originalParent } = current;
7627
7685
  setDragState((prev) => ({
@@ -7709,12 +7767,17 @@ function useMove({ onMoveComplete }) {
7709
7767
  clearReorderPreview();
7710
7768
  }
7711
7769
  }
7712
- function handlePointerUp() {
7770
+ function handlePointerUp(e) {
7771
+ e.stopPropagation();
7713
7772
  completeDrag();
7714
7773
  }
7715
- function handlePointerCancel() {
7774
+ function handlePointerCancel(e) {
7775
+ e.stopPropagation();
7716
7776
  cancelDrag();
7717
7777
  }
7778
+ function blockMouseEvent(e) {
7779
+ e.stopPropagation();
7780
+ }
7718
7781
  function handleKeyDown(e) {
7719
7782
  if (e.key === "Escape") {
7720
7783
  cancelDrag();
@@ -7723,15 +7786,19 @@ function useMove({ onMoveComplete }) {
7723
7786
  function handleBlur() {
7724
7787
  cancelDrag();
7725
7788
  }
7726
- window.addEventListener("pointermove", handlePointerMove);
7727
- window.addEventListener("pointerup", handlePointerUp);
7728
- window.addEventListener("pointercancel", handlePointerCancel);
7789
+ window.addEventListener("pointermove", handlePointerMove, true);
7790
+ window.addEventListener("pointerup", handlePointerUp, true);
7791
+ window.addEventListener("pointercancel", handlePointerCancel, true);
7792
+ window.addEventListener("mousemove", blockMouseEvent, true);
7793
+ window.addEventListener("mouseup", blockMouseEvent, true);
7729
7794
  window.addEventListener("keydown", handleKeyDown);
7730
7795
  window.addEventListener("blur", handleBlur);
7731
7796
  return () => {
7732
- window.removeEventListener("pointermove", handlePointerMove);
7733
- window.removeEventListener("pointerup", handlePointerUp);
7734
- window.removeEventListener("pointercancel", handlePointerCancel);
7797
+ window.removeEventListener("pointermove", handlePointerMove, true);
7798
+ window.removeEventListener("pointerup", handlePointerUp, true);
7799
+ window.removeEventListener("pointercancel", handlePointerCancel, true);
7800
+ window.removeEventListener("mousemove", blockMouseEvent, true);
7801
+ window.removeEventListener("mouseup", blockMouseEvent, true);
7735
7802
  window.removeEventListener("keydown", handleKeyDown);
7736
7803
  window.removeEventListener("blur", handleBlur);
7737
7804
  };
@@ -8513,7 +8580,7 @@ function SelectedCommentComposer({
8513
8580
  React17.useLayoutEffect(() => {
8514
8581
  updatePosition();
8515
8582
  }, [text, updatePosition]);
8516
- React17.useEffect(() => {
8583
+ const handleComposerClick = React17.useCallback(() => {
8517
8584
  inputRef.current?.focus();
8518
8585
  }, []);
8519
8586
  React17.useEffect(() => {
@@ -8564,7 +8631,10 @@ function SelectedCommentComposer({
8564
8631
  width: position.width,
8565
8632
  pointerEvents: "auto"
8566
8633
  },
8567
- onClick: (e) => e.stopPropagation(),
8634
+ onClick: (e) => {
8635
+ e.stopPropagation();
8636
+ handleComposerClick();
8637
+ },
8568
8638
  children: [
8569
8639
  /* @__PURE__ */ (0, import_jsx_runtime7.jsx)(
8570
8640
  "textarea",
@@ -12811,7 +12881,8 @@ function DirectEditPanelContent() {
12811
12881
  sendCommentToAgent: sendCommentToAgent2,
12812
12882
  setActiveCommentId,
12813
12883
  startTextEditing,
12814
- toggleEditMode
12884
+ toggleEditMode,
12885
+ deleteSelection
12815
12886
  } = useDirectEditActions();
12816
12887
  const {
12817
12888
  position,