@homebound/beam 3.107.0 → 3.108.0
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.cjs +42 -24
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +72 -54
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -21774,7 +21774,8 @@ function DnDGrid(props) {
|
|
|
21774
21774
|
children,
|
|
21775
21775
|
gridStyles,
|
|
21776
21776
|
onReorder,
|
|
21777
|
-
activeItemStyles
|
|
21777
|
+
activeItemStyles,
|
|
21778
|
+
lockAxis
|
|
21778
21779
|
} = props;
|
|
21779
21780
|
const gridEl = (0, import_react107.useRef)(null);
|
|
21780
21781
|
const dragEl = (0, import_react107.useRef)();
|
|
@@ -21841,15 +21842,15 @@ function DnDGrid(props) {
|
|
|
21841
21842
|
const clientY = "clientY" in e ? e.clientY : e.touches[0].clientY;
|
|
21842
21843
|
const left = dragEl.current.style.left ? parseInt(dragEl.current.style.left) : 0;
|
|
21843
21844
|
const top = dragEl.current.style.top ? parseInt(dragEl.current.style.top) : 0;
|
|
21844
|
-
const x = clientX - transformFrom.current.x - left;
|
|
21845
|
-
const y = clientY - transformFrom.current.y - top;
|
|
21845
|
+
const x = lockAxis === "y" ? 0 : clientX - transformFrom.current.x - left;
|
|
21846
|
+
const y = lockAxis === "x" ? 0 : clientY - transformFrom.current.y - top;
|
|
21846
21847
|
dragEl.current.style.transform = `translate(${x}px, ${y}px)`;
|
|
21847
21848
|
const maybeTarget = "touches" in e ? document.elementFromPoint(clientX, clientY) : e.target;
|
|
21848
21849
|
const target = maybeTarget instanceof HTMLElement ? maybeTarget?.closest(`[${gridItemIdKey}]`) : void 0;
|
|
21849
21850
|
if (target instanceof HTMLElement && target !== cloneEl.current && target !== dragEl.current) {
|
|
21850
21851
|
const targetPos = target.getBoundingClientRect();
|
|
21851
21852
|
const clonePos = cloneEl.current.getBoundingClientRect();
|
|
21852
|
-
const useYAxis = Math.abs(targetPos.top - clonePos.top) >= Math.abs(targetPos.left - clonePos.left);
|
|
21853
|
+
const useYAxis = lockAxis === "y" ? true : lockAxis === "x" ? false : Math.abs(targetPos.top - clonePos.top) >= Math.abs(targetPos.left - clonePos.left);
|
|
21853
21854
|
const isHalfwayPassedTarget = useYAxis ? (clientY - targetPos.top) / (targetPos.bottom - targetPos.top) > 0.5 : (clientX - targetPos.left) / (targetPos.right - targetPos.left) > 0.5;
|
|
21854
21855
|
const shouldInsert = isHalfwayPassedTarget && target.nextSibling !== cloneEl.current || !isHalfwayPassedTarget && target.previousSibling !== cloneEl.current;
|
|
21855
21856
|
if (shouldInsert) {
|
|
@@ -21857,7 +21858,18 @@ function DnDGrid(props) {
|
|
|
21857
21858
|
}
|
|
21858
21859
|
}
|
|
21859
21860
|
}
|
|
21860
|
-
}, []);
|
|
21861
|
+
}, [lockAxis]);
|
|
21862
|
+
const onDragEnd = (0, import_react107.useCallback)((e) => {
|
|
21863
|
+
if (!reorderViaKeyboard.current && dragEl.current && cloneEl.current && gridEl.current) {
|
|
21864
|
+
e.preventDefault();
|
|
21865
|
+
cloneEl.current.replaceWith(dragEl.current);
|
|
21866
|
+
gridEl.current.querySelectorAll(`[${gridCloneKey}]`).forEach((el) => el.remove());
|
|
21867
|
+
gridEl.current.style.cursor = "auto";
|
|
21868
|
+
cloneEl.current = void 0;
|
|
21869
|
+
commitReorder();
|
|
21870
|
+
removePointerDragListeners(onMove, onDragEnd);
|
|
21871
|
+
}
|
|
21872
|
+
}, [commitReorder, onMove]);
|
|
21861
21873
|
const onDragStart = (0, import_react107.useCallback)((e) => {
|
|
21862
21874
|
if (!reorderViaKeyboard.current && dragEl.current && gridEl.current) {
|
|
21863
21875
|
const rect = dragEl.current.getBoundingClientRect();
|
|
@@ -21883,22 +21895,12 @@ function DnDGrid(props) {
|
|
|
21883
21895
|
dragEl.current.style.width = `${rect.width}px`;
|
|
21884
21896
|
dragEl.current.style.height = `${rect.height}px`;
|
|
21885
21897
|
gridEl.current.style.cursor = "grabbing";
|
|
21886
|
-
|
|
21887
|
-
gridEl.current.addEventListener("touchmove", onMove);
|
|
21898
|
+
addPointerDragListeners(onMove, onDragEnd);
|
|
21888
21899
|
}
|
|
21889
|
-
}, [initReorder, onMove]);
|
|
21890
|
-
|
|
21891
|
-
|
|
21892
|
-
|
|
21893
|
-
cloneEl.current.replaceWith(dragEl.current);
|
|
21894
|
-
gridEl.current.querySelectorAll(`[${gridCloneKey}]`).forEach((el) => el.remove());
|
|
21895
|
-
gridEl.current.style.cursor = "auto";
|
|
21896
|
-
cloneEl.current = void 0;
|
|
21897
|
-
commitReorder();
|
|
21898
|
-
gridEl.current.removeEventListener("mousemove", onMove);
|
|
21899
|
-
gridEl.current.removeEventListener("touchmove", onMove);
|
|
21900
|
-
}
|
|
21901
|
-
}, [commitReorder, onMove]);
|
|
21900
|
+
}, [initReorder, onMove, onDragEnd]);
|
|
21901
|
+
(0, import_react107.useEffect)(() => {
|
|
21902
|
+
return () => removePointerDragListeners(onMove, onDragEnd);
|
|
21903
|
+
}, [onMove, onDragEnd]);
|
|
21902
21904
|
const onDragHandleKeyDown = (0, import_react107.useCallback)((e) => {
|
|
21903
21905
|
const moveHandle = e.target;
|
|
21904
21906
|
if (dragEl.current instanceof HTMLElement && moveHandle instanceof HTMLElement && gridEl.current) {
|
|
@@ -21932,8 +21934,8 @@ function DnDGrid(props) {
|
|
|
21932
21934
|
document.removeEventListener("pointerdown", cancelReorder);
|
|
21933
21935
|
return;
|
|
21934
21936
|
}
|
|
21935
|
-
const movingLeft =
|
|
21936
|
-
const movingRight =
|
|
21937
|
+
const movingLeft = lockAxis !== "x" && e.key === "ArrowUp" || lockAxis !== "y" && e.key === "ArrowLeft";
|
|
21938
|
+
const movingRight = lockAxis !== "x" && e.key === "ArrowDown" || lockAxis !== "y" && e.key === "ArrowRight";
|
|
21937
21939
|
if (movingLeft || movingRight) {
|
|
21938
21940
|
e.preventDefault();
|
|
21939
21941
|
const gridItems = getGridItems();
|
|
@@ -21946,7 +21948,7 @@ function DnDGrid(props) {
|
|
|
21946
21948
|
moveHandle.focus();
|
|
21947
21949
|
}
|
|
21948
21950
|
}
|
|
21949
|
-
}, [cancelReorder, commitReorder, initReorder, getGridItems]);
|
|
21951
|
+
}, [cancelReorder, commitReorder, initReorder, getGridItems, lockAxis]);
|
|
21950
21952
|
return /* @__PURE__ */ (0, import_jsx_runtime147.jsx)(DnDGridContext.Provider, { value: {
|
|
21951
21953
|
dragEl,
|
|
21952
21954
|
onDragHandleKeyDown
|
|
@@ -21960,6 +21962,22 @@ function DnDGrid(props) {
|
|
|
21960
21962
|
}
|
|
21961
21963
|
var gridItemIdKey = "dndgrid-itemid";
|
|
21962
21964
|
var gridCloneKey = "dndgrid-clone";
|
|
21965
|
+
function addPointerDragListeners(onMove, onEnd) {
|
|
21966
|
+
document.addEventListener("mousemove", onMove);
|
|
21967
|
+
document.addEventListener("touchmove", onMove);
|
|
21968
|
+
document.addEventListener("mouseup", onEnd);
|
|
21969
|
+
document.addEventListener("touchend", onEnd);
|
|
21970
|
+
document.addEventListener("pointercancel", onEnd);
|
|
21971
|
+
document.addEventListener("touchcancel", onEnd);
|
|
21972
|
+
}
|
|
21973
|
+
function removePointerDragListeners(onMove, onEnd) {
|
|
21974
|
+
document.removeEventListener("mousemove", onMove);
|
|
21975
|
+
document.removeEventListener("touchmove", onMove);
|
|
21976
|
+
document.removeEventListener("mouseup", onEnd);
|
|
21977
|
+
document.removeEventListener("touchend", onEnd);
|
|
21978
|
+
document.removeEventListener("pointercancel", onEnd);
|
|
21979
|
+
document.removeEventListener("touchcancel", onEnd);
|
|
21980
|
+
}
|
|
21963
21981
|
function applyActiveStyles(el, activeStyles3) {
|
|
21964
21982
|
const {
|
|
21965
21983
|
className,
|
|
@@ -22348,7 +22366,7 @@ function DraggableChildren(props) {
|
|
|
22348
22366
|
}
|
|
22349
22367
|
});
|
|
22350
22368
|
};
|
|
22351
|
-
return /* @__PURE__ */ (0, import_jsx_runtime153.jsx)(DnDGrid, { onReorder: handleReorder, gridStyles: {
|
|
22369
|
+
return /* @__PURE__ */ (0, import_jsx_runtime153.jsx)(DnDGrid, { onReorder: handleReorder, lockAxis: "y", gridStyles: {
|
|
22352
22370
|
gridTemplateColumns: "gtc_minmax_0_1fr",
|
|
22353
22371
|
gap: "gap3"
|
|
22354
22372
|
}, children: sorted.map((child) => /* @__PURE__ */ (0, import_jsx_runtime153.jsx)(FormSectionChild, { ...child, ...tid }, child.id)) });
|