@byeolnaerim/flex-layout 0.0.8 → 0.0.10
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/flex-layout/components/FlexLayout.cjs +1 -76
- package/dist/flex-layout/components/FlexLayout.js +1 -70
- package/dist/flex-layout/components/FlexLayoutContainer.cjs +1 -196
- package/dist/flex-layout/components/FlexLayoutContainer.js +1 -189
- package/dist/flex-layout/components/FlexLayoutIFramePane.cjs +1 -0
- package/dist/flex-layout/components/FlexLayoutIFramePane.d.ts +4 -0
- package/dist/flex-layout/components/FlexLayoutIFramePane.js +1 -0
- package/dist/flex-layout/components/FlexLayoutResizePanel.cjs +1 -192
- package/dist/flex-layout/components/FlexLayoutResizePanel.d.ts +1 -1
- package/dist/flex-layout/components/FlexLayoutResizePanel.js +1 -186
- package/dist/flex-layout/components/FlexLayoutSplitScreen.cjs +1 -1211
- package/dist/flex-layout/components/FlexLayoutSplitScreen.js +1 -1197
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBox.cjs +1 -339
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBox.d.ts +1 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBox.js +1 -333
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxContainer.cjs +1 -32
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxContainer.js +1 -25
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxItem.cjs +1 -40
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxItem.js +1 -34
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxTitleMore.cjs +1 -30
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxTitleMore.js +1 -24
- package/dist/flex-layout/components/FlexLayoutSplitScreenScrollBox.cjs +1 -109
- package/dist/flex-layout/components/FlexLayoutSplitScreenScrollBox.js +1 -103
- package/dist/flex-layout/components/FlexLayoutStickyBox.cjs +1 -226
- package/dist/flex-layout/components/FlexLayoutStickyBox.d.ts +1 -0
- package/dist/flex-layout/components/FlexLayoutStickyBox.js +1 -224
- package/dist/flex-layout/components/index.cjs +1 -52
- package/dist/flex-layout/components/index.js +1 -9
- package/dist/flex-layout/hooks/index.cjs +1 -21
- package/dist/flex-layout/hooks/index.js +1 -4
- package/dist/flex-layout/hooks/useDrag.cjs +1 -232
- package/dist/flex-layout/hooks/useDrag.d.ts +20 -0
- package/dist/flex-layout/hooks/useDrag.js +1 -219
- package/dist/flex-layout/hooks/useFlexLayoutSplitScreen.cjs +1 -118
- package/dist/flex-layout/hooks/useFlexLayoutSplitScreen.js +1 -116
- package/dist/flex-layout/hooks/useListPaging.cjs +1 -179
- package/dist/flex-layout/hooks/useListPaging.js +1 -175
- package/dist/flex-layout/hooks/useSizes.cjs +1 -104
- package/dist/flex-layout/hooks/useSizes.js +1 -101
- package/dist/flex-layout/index.cjs +1 -42
- package/dist/flex-layout/index.js +1 -7
- package/dist/flex-layout/providers/FlexLayoutContext.cjs +1 -26
- package/dist/flex-layout/providers/FlexLayoutContext.js +1 -23
- package/dist/flex-layout/providers/FlexLayoutHooks.cjs +1 -247
- package/dist/flex-layout/providers/FlexLayoutHooks.d.ts +5 -1
- package/dist/flex-layout/providers/FlexLayoutHooks.js +1 -238
- package/dist/flex-layout/providers/index.cjs +1 -14
- package/dist/flex-layout/providers/index.js +1 -3
- package/dist/flex-layout/store/FlexLayoutContainerStore.cjs +1 -203
- package/dist/flex-layout/store/FlexLayoutContainerStore.d.ts +1 -0
- package/dist/flex-layout/store/FlexLayoutContainerStore.js +1 -181
- package/dist/flex-layout/store/index.cjs +1 -14
- package/dist/flex-layout/store/index.js +1 -3
- package/dist/flex-layout/styles/FlexLayout.module.css +473 -416
- package/dist/flex-layout/types/FlexDirectionTypes.cjs +1 -4
- package/dist/flex-layout/types/FlexDirectionTypes.js +0 -3
- package/dist/flex-layout/types/FlexLayoutTypes.cjs +1 -4
- package/dist/flex-layout/types/FlexLayoutTypes.d.ts +1 -3
- package/dist/flex-layout/types/FlexLayoutTypes.js +0 -3
- package/dist/flex-layout/utils/FlexLayoutUtils.cjs +1 -208
- package/dist/flex-layout/utils/FlexLayoutUtils.d.ts +4 -4
- package/dist/flex-layout/utils/FlexLayoutUtils.js +1 -196
- package/dist/flex-layout/utils/index.cjs +1 -14
- package/dist/flex-layout/utils/index.js +1 -3
- package/dist/index.cjs +1 -14
- package/dist/index.js +1 -3
- package/dist/types/css.d.cjs +1 -4
- package/dist/types/css.d.js +0 -3
- package/package.json +116 -109
- package/dist/flex-layout/components/FlexLayout.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayout.js.map +0 -1
- package/dist/flex-layout/components/FlexLayoutContainer.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayoutContainer.js.map +0 -1
- package/dist/flex-layout/components/FlexLayoutResizePanel.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayoutResizePanel.js.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreen.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreen.js.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBox.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBox.js.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxContainer.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxContainer.js.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxItem.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxItem.js.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxTitleMore.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenDragBoxTitleMore.js.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenScrollBox.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayoutSplitScreenScrollBox.js.map +0 -1
- package/dist/flex-layout/components/FlexLayoutStickyBox.cjs.map +0 -1
- package/dist/flex-layout/components/FlexLayoutStickyBox.js.map +0 -1
- package/dist/flex-layout/components/index.cjs.map +0 -1
- package/dist/flex-layout/components/index.js.map +0 -1
- package/dist/flex-layout/hooks/index.cjs.map +0 -1
- package/dist/flex-layout/hooks/index.js.map +0 -1
- package/dist/flex-layout/hooks/useDrag.cjs.map +0 -1
- package/dist/flex-layout/hooks/useDrag.js.map +0 -1
- package/dist/flex-layout/hooks/useFlexLayoutSplitScreen.cjs.map +0 -1
- package/dist/flex-layout/hooks/useFlexLayoutSplitScreen.js.map +0 -1
- package/dist/flex-layout/hooks/useListPaging.cjs.map +0 -1
- package/dist/flex-layout/hooks/useListPaging.js.map +0 -1
- package/dist/flex-layout/hooks/useSizes.cjs.map +0 -1
- package/dist/flex-layout/hooks/useSizes.js.map +0 -1
- package/dist/flex-layout/index.cjs.map +0 -1
- package/dist/flex-layout/index.js.map +0 -1
- package/dist/flex-layout/providers/FlexLayoutContext.cjs.map +0 -1
- package/dist/flex-layout/providers/FlexLayoutContext.js.map +0 -1
- package/dist/flex-layout/providers/FlexLayoutHooks.cjs.map +0 -1
- package/dist/flex-layout/providers/FlexLayoutHooks.js.map +0 -1
- package/dist/flex-layout/providers/index.cjs.map +0 -1
- package/dist/flex-layout/providers/index.js.map +0 -1
- package/dist/flex-layout/store/FlexLayoutContainerStore.cjs.map +0 -1
- package/dist/flex-layout/store/FlexLayoutContainerStore.js.map +0 -1
- package/dist/flex-layout/store/index.cjs.map +0 -1
- package/dist/flex-layout/store/index.js.map +0 -1
- package/dist/flex-layout/types/FlexDirectionTypes.cjs.map +0 -1
- package/dist/flex-layout/types/FlexDirectionTypes.js.map +0 -1
- package/dist/flex-layout/types/FlexLayoutTypes.cjs.map +0 -1
- package/dist/flex-layout/types/FlexLayoutTypes.js.map +0 -1
- package/dist/flex-layout/utils/FlexLayoutUtils.cjs.map +0 -1
- package/dist/flex-layout/utils/FlexLayoutUtils.js.map +0 -1
- package/dist/flex-layout/utils/index.cjs.map +0 -1
- package/dist/flex-layout/utils/index.js.map +0 -1
- package/dist/index.cjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/types/css.d.cjs.map +0 -1
- package/dist/types/css.d.js.map +0 -1
|
@@ -1,192 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var react = require('react');
|
|
5
|
-
var FlexLayoutContainerStore = require('../store/FlexLayoutContainerStore');
|
|
6
|
-
var styles = require('../styles/FlexLayout.module.css');
|
|
7
|
-
var FlexLayoutUtils = require('../utils/FlexLayoutUtils');
|
|
8
|
-
|
|
9
|
-
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
|
-
|
|
11
|
-
var styles__default = /*#__PURE__*/_interopDefault(styles);
|
|
12
|
-
|
|
13
|
-
const flexDirectionModel = {
|
|
14
|
-
row: {
|
|
15
|
-
xy: "x",
|
|
16
|
-
targetDirection: "left",
|
|
17
|
-
nextDirection: "right",
|
|
18
|
-
sizeName: "width",
|
|
19
|
-
resizeCursor: "ew-resize"
|
|
20
|
-
},
|
|
21
|
-
column: {
|
|
22
|
-
xy: "y",
|
|
23
|
-
targetDirection: "top",
|
|
24
|
-
nextDirection: "bottom",
|
|
25
|
-
sizeName: "height",
|
|
26
|
-
resizeCursor: "ns-resize"
|
|
27
|
-
}
|
|
28
|
-
};
|
|
29
|
-
function FlexLayoutResizePanel({
|
|
30
|
-
direction,
|
|
31
|
-
containerCount,
|
|
32
|
-
panelMode = "default",
|
|
33
|
-
containerName,
|
|
34
|
-
layoutName,
|
|
35
|
-
panelClassName,
|
|
36
|
-
panelMovementMode
|
|
37
|
-
}) {
|
|
38
|
-
const directionRef = react.useRef(direction);
|
|
39
|
-
const movementModeRef = react.useRef(panelMovementMode);
|
|
40
|
-
react.useEffect(() => {
|
|
41
|
-
directionRef.current = direction;
|
|
42
|
-
}, [direction]);
|
|
43
|
-
react.useEffect(() => {
|
|
44
|
-
movementModeRef.current = panelMovementMode;
|
|
45
|
-
}, [panelMovementMode]);
|
|
46
|
-
const isResizePanelClickRef = react.useRef(false);
|
|
47
|
-
const prevTouchEventRef = react.useRef(null);
|
|
48
|
-
const parentSizeRef = react.useRef(0);
|
|
49
|
-
const totalMovementRef = react.useRef(0);
|
|
50
|
-
const containerCountRef = react.useRef(containerCount);
|
|
51
|
-
const panelRef = react.useRef(null);
|
|
52
|
-
react.useEffect(() => {
|
|
53
|
-
return () => {
|
|
54
|
-
document.body.style.cursor = "";
|
|
55
|
-
};
|
|
56
|
-
}, []);
|
|
57
|
-
react.useEffect(() => {
|
|
58
|
-
containerCountRef.current = containerCount;
|
|
59
|
-
}, [containerCount]);
|
|
60
|
-
const panelMouseDownEvent = (event) => {
|
|
61
|
-
if (!panelRef.current || !panelRef.current.parentElement) return;
|
|
62
|
-
isResizePanelClickRef.current = true;
|
|
63
|
-
containerCountRef.current = [
|
|
64
|
-
...panelRef.current.parentElement.children
|
|
65
|
-
].filter((e) => e.hasAttribute("data-container_name")).length;
|
|
66
|
-
const sizeName = flexDirectionModel[direction].sizeName;
|
|
67
|
-
parentSizeRef.current = panelRef.current.parentElement.getBoundingClientRect()[sizeName];
|
|
68
|
-
prevTouchEventRef.current = null;
|
|
69
|
-
totalMovementRef.current = 0;
|
|
70
|
-
if (!parentSizeRef.current) return;
|
|
71
|
-
document.body.style.cursor = flexDirectionModel[direction].resizeCursor;
|
|
72
|
-
};
|
|
73
|
-
const panelMouseUpEvent = () => {
|
|
74
|
-
isResizePanelClickRef.current = false;
|
|
75
|
-
parentSizeRef.current = 0;
|
|
76
|
-
totalMovementRef.current = 0;
|
|
77
|
-
prevTouchEventRef.current = null;
|
|
78
|
-
document.body.style.cursor = "";
|
|
79
|
-
};
|
|
80
|
-
function moveMouseFlex(originTarget, resizePanel, moveEvent, dir, mode) {
|
|
81
|
-
const model = flexDirectionModel[dir];
|
|
82
|
-
const movement = moveEvent["movement" + model.xy.toUpperCase()];
|
|
83
|
-
totalMovementRef.current += movement;
|
|
84
|
-
const minSizeName = "min-" + model.sizeName;
|
|
85
|
-
const maxSizeName = "max-" + model.sizeName;
|
|
86
|
-
let targetElement = FlexLayoutUtils.findNotCloseFlexContent(
|
|
87
|
-
originTarget,
|
|
88
|
-
"previousElementSibling"
|
|
89
|
-
);
|
|
90
|
-
if (panelMovementMode === "divorce" && totalMovementRef.current > 0 || panelMovementMode === "bulldozer" && movement > 0 || !targetElement)
|
|
91
|
-
targetElement = originTarget;
|
|
92
|
-
let nextElement = FlexLayoutUtils.findNotCloseFlexContent(
|
|
93
|
-
resizePanel.nextElementSibling,
|
|
94
|
-
"nextElementSibling"
|
|
95
|
-
);
|
|
96
|
-
if (panelMovementMode === "divorce" && totalMovementRef.current < 0 || panelMovementMode === "bulldozer" && movement < 0 || !nextElement)
|
|
97
|
-
nextElement = resizePanel.nextElementSibling;
|
|
98
|
-
if (!targetElement || !nextElement) return;
|
|
99
|
-
const targetRect = targetElement.getBoundingClientRect();
|
|
100
|
-
const targetStyle = window.getComputedStyle(targetElement);
|
|
101
|
-
const targetMinSize = parseFloat(targetStyle.getPropertyValue(minSizeName)) || 0;
|
|
102
|
-
const targetMaxSize = parseFloat(targetStyle.getPropertyValue(maxSizeName)) || 0;
|
|
103
|
-
const nextRect = nextElement.getBoundingClientRect();
|
|
104
|
-
const nextStyle = window.getComputedStyle(nextElement);
|
|
105
|
-
const nextMinSize = parseFloat(nextStyle.getPropertyValue(minSizeName)) || 0;
|
|
106
|
-
const nextMaxSize = parseFloat(nextStyle.getPropertyValue(maxSizeName)) || 0;
|
|
107
|
-
let targetSize = targetRect[model.sizeName] + movement;
|
|
108
|
-
let nextElementSize = nextRect[model.sizeName] - movement;
|
|
109
|
-
if (targetMaxSize > 0 && targetSize > targetMaxSize) {
|
|
110
|
-
return;
|
|
111
|
-
}
|
|
112
|
-
if (nextMaxSize > 0 && nextElementSize > nextMaxSize) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
if (FlexLayoutUtils.isOverMove(targetSize, targetMinSize)) {
|
|
116
|
-
targetSize = 0;
|
|
117
|
-
nextElementSize = nextRect[model.sizeName];
|
|
118
|
-
} else if (FlexLayoutUtils.isOverMove(nextElementSize, nextMinSize)) {
|
|
119
|
-
nextElementSize = 0;
|
|
120
|
-
targetSize = targetRect[model.sizeName];
|
|
121
|
-
}
|
|
122
|
-
const targetFlexGrow = targetSize / (parentSizeRef.current - 1) * containerCountRef.current;
|
|
123
|
-
const nextElementFlexGrow = nextElementSize / (parentSizeRef.current - 1) * containerCountRef.current;
|
|
124
|
-
if (!(targetElement instanceof HTMLElement)) return;
|
|
125
|
-
if (!(nextElement instanceof HTMLElement)) return;
|
|
126
|
-
targetElement.style.flex = `${targetFlexGrow} 1 0%`;
|
|
127
|
-
nextElement.style.flex = `${nextElementFlexGrow} 1 0%`;
|
|
128
|
-
}
|
|
129
|
-
react.useEffect(() => {
|
|
130
|
-
const addGlobalMoveEvent = (event) => {
|
|
131
|
-
if (!isResizePanelClickRef.current || !panelRef.current) {
|
|
132
|
-
return;
|
|
133
|
-
}
|
|
134
|
-
event.preventDefault();
|
|
135
|
-
const dir = directionRef.current;
|
|
136
|
-
movementModeRef.current;
|
|
137
|
-
const targetElement = panelRef.current.previousElementSibling;
|
|
138
|
-
const targetPanel = panelRef.current;
|
|
139
|
-
if (!targetElement || !targetPanel) return;
|
|
140
|
-
let move = { movementX: 0, movementY: 0 };
|
|
141
|
-
if (window.TouchEvent && event instanceof window.TouchEvent) {
|
|
142
|
-
const prev = prevTouchEventRef.current;
|
|
143
|
-
if (!prev) {
|
|
144
|
-
prevTouchEventRef.current = event;
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
move.movementX = (prev.touches[0].pageX - event.touches[0].pageX) * -1;
|
|
148
|
-
move.movementY = (prev.touches[0].pageY - event.touches[0].pageY) * -1;
|
|
149
|
-
prevTouchEventRef.current = event;
|
|
150
|
-
} else {
|
|
151
|
-
move.movementX = event.movementX;
|
|
152
|
-
move.movementY = event.movementY;
|
|
153
|
-
}
|
|
154
|
-
moveMouseFlex(targetElement, targetPanel, move, dir);
|
|
155
|
-
};
|
|
156
|
-
["mousemove", "touchmove"].forEach((eventName) => {
|
|
157
|
-
window.addEventListener(eventName, addGlobalMoveEvent, {
|
|
158
|
-
passive: false
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
["mouseup", "touchend"].forEach((eventName) => {
|
|
162
|
-
window.addEventListener(eventName, panelMouseUpEvent);
|
|
163
|
-
});
|
|
164
|
-
return () => {
|
|
165
|
-
["mousemove", "touchmove"].forEach((eventName) => {
|
|
166
|
-
window.removeEventListener(eventName, addGlobalMoveEvent);
|
|
167
|
-
});
|
|
168
|
-
["mouseup", "touchend"].forEach((eventName) => {
|
|
169
|
-
window.removeEventListener(eventName, panelMouseUpEvent);
|
|
170
|
-
});
|
|
171
|
-
};
|
|
172
|
-
}, []);
|
|
173
|
-
react.useEffect(() => {
|
|
174
|
-
if (!panelRef.current) return;
|
|
175
|
-
FlexLayoutContainerStore.setResizePanelRef(layoutName, containerName, panelRef);
|
|
176
|
-
}, [containerName, layoutName]);
|
|
177
|
-
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
178
|
-
"div",
|
|
179
|
-
{
|
|
180
|
-
id: containerName + "_resize_panel",
|
|
181
|
-
className: `${styles__default.default["flex-resize-panel"]} ${styles__default.default[panelMode]} ${panelClassName && panelClassName !== "" ? panelClassName : ""}`,
|
|
182
|
-
ref: panelRef,
|
|
183
|
-
onMouseDown: panelMouseDownEvent,
|
|
184
|
-
onTouchStart: panelMouseDownEvent,
|
|
185
|
-
children: /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles__default.default.hover })
|
|
186
|
-
}
|
|
187
|
-
);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
module.exports = FlexLayoutResizePanel;
|
|
191
|
-
//# sourceMappingURL=FlexLayoutResizePanel.cjs.map
|
|
192
|
-
//# sourceMappingURL=FlexLayoutResizePanel.cjs.map
|
|
1
|
+
"use strict";"use client";var fe=Object.create;var G=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var he=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var Ee=(e,t)=>{for(var n in t)G(e,n,{get:t[n],enumerable:!0})},te=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let c of pe(t))!ge.call(e,c)&&c!==n&&G(e,c,{get:()=>t[c],enumerable:!(r=de(t,c))||r.enumerable});return e};var ve=(e,t,n)=>(n=e!=null?fe(he(e)):{},te(t||!e||!e.__esModule?G(n,"default",{value:e,enumerable:!0}):n,e)),Me=e=>te(G({},"__esModule",{value:!0}),e);var xe={};Ee(xe,{default:()=>oe});module.exports=Me(xe);var J=require("react/jsx-runtime"),u=require("react"),T=require("../hooks"),K=require("../store/FlexLayoutContainerStore"),C=ve(require("../styles/FlexLayout.module.css"),1),L=require("../utils/FlexLayoutUtils");const j={row:{xy:"x",targetDirection:"left",nextDirection:"right",sizeName:"width",resizeCursor:"ew-resize"},column:{xy:"y",targetDirection:"top",nextDirection:"bottom",sizeName:"height",resizeCursor:"ns-resize"}},h=4,ne=(e,t,n,r)=>{const c=new Map,l=(a,g)=>{const s=document.elementsFromPoint(a,g);for(const m of s){const M=m.closest?.(`.${C.default["flex-resize-panel"]}`);if(!M)continue;const f=M.dataset.resize_panel_key;f&&(c.has(f)||c.set(f,{el:M,key:f,dir:M.dataset.direction}))}};if([[0,0],[-h,0],[h,0],[0,-h],[0,h],[-h,-h],[h,-h],[-h,h],[h,h]].forEach(([a,g])=>l(e+a,t+g)),n&&r){const a=n.getBoundingClientRect(),g=r==="row"?a.width:r==="column"?a.height:1,s=Math.max(1,Math.ceil(g/2)),m=Math.ceil(h+g*2),p=Math.max(h,Math.ceil(g*2)),M=Array.from(new Set([1,Math.floor(p/2),Math.max(1,p-1)]));if(r==="row")for(let f=-m;f<=m;f+=s)for(const b of M)l(a.left-b,t+f),l(a.right+b,t+f);else if(r==="column")for(let f=-m;f<=m;f+=s)for(const b of M)l(e+f,a.top-b),l(e+f,a.bottom+b)}if(r){const g=[...c.values()].filter(s=>s.dir&&s.dir!==r);for(const s of g){const m=s.el.getBoundingClientRect(),p=s.dir==="row"?m.width:s.dir==="column"?m.height:1,M=Math.max(1,Math.ceil(p/2)),f=Math.ceil(h+p*2),b=Math.max(h,Math.ceil(p*2)),F=Array.from(new Set([1,Math.floor(b/2),Math.max(1,b-1)]));if(r==="column"&&s.dir==="row")for(let y=-f;y<=f;y+=M)for(const o of F)l(m.left-o,t+y),l(m.right+o,t+y);else if(r==="row"&&s.dir==="column")for(let y=-f;y<=f;y+=M)for(const o of F)l(e+y,m.top-o),l(e+y,m.bottom+o)}}return[...c.values()]},D=(e,t)=>{if(!e||e==="auto")return null;if(e.endsWith("px")){const r=parseFloat(e);return Number.isFinite(r)?r:null}if(e.endsWith("%")){const r=parseFloat(e);return Number.isFinite(r)?t*r/100:null}const n=parseFloat(e);return Number.isFinite(n)?n:null},ye=(e,t,n)=>e>=n.left&&e<=n.right&&t>=n.top&&t<=n.bottom,be=e=>{const t=e.getBoundingClientRect(),n=getComputedStyle(e,"::after");if(!n||n.content==="none"||n.content==="normal"||n.display==="none"||n.visibility==="hidden")return null;const r=D(n.width,t.width),c=D(n.height,t.height);if(!r||!c)return null;const l=D(n.left,t.width),a=D(n.right,t.width),g=D(n.top,t.height),s=D(n.bottom,t.height);let m=t.left;l!==null?m=t.left+l:a!==null&&(m=t.right-a-r);let p=t.top;return g!==null?p=t.top+g:s!==null&&(p=t.bottom-s-c),{left:m,top:p,right:m+r,bottom:p+c}},re=(e,t,n,r,c)=>{const l=n.getBoundingClientRect(),a=be(n);if(a&&ye(e,t,a))return!1;const g=r==="row"?l.width:r==="column"?l.height:1,s=Math.max(c,Math.ceil(g));return r==="row"?e>=l.left-s&&e<=l.right+s:r==="column"?t>=l.top-s&&t<=l.bottom+s:!0};function oe({direction:e,containerCount:t,panelMode:n="default",containerName:r,layoutName:c,panelClassName:l,panelMovementMode:a,onResizingChange:g}){const s=(0,u.useRef)(e),m=(0,u.useRef)(a),p=(0,u.useMemo)(()=>`${c}::${r}`,[c,r]);(0,u.useEffect)(()=>{s.current=e},[e]),(0,u.useEffect)(()=>{m.current=a},[a]);const M=(0,u.useRef)(!1),f=(0,u.useRef)(null),b=(0,u.useRef)(0),F=(0,u.useRef)(0),y=(0,u.useRef)(t),o=(0,u.useRef)(null),B=(0,u.useRef)(null),k=(0,u.useRef)(null);(0,u.useEffect)(()=>()=>{T.isResizingSubject.next(!1),document.body.style.cursor="",k.current?.()},[]),(0,u.useEffect)(()=>{y.current=t},[t]);const se=()=>{if(!o.current||!o.current.parentElement)return;M.current=!0,g?.(!0),y.current=[...o.current.parentElement.children].filter(i=>i.hasAttribute("data-container_name")).length;const d=j[e].sizeName;b.current=o.current.parentElement.getBoundingClientRect()[d],f.current=null,F.current=0,T.isResizingSubject.next(!0)},ie=()=>{M.current=!1,g?.(!1),b.current=0,F.current=0,B.current=null,T.isResizingSubject.next(!1),document.body.style.cursor="",O()};function le(d,i,x,z,S){const E=j[z],H=x["movement"+E.xy.toUpperCase()];F.current+=H;const A="min-"+E.sizeName,X="max-"+E.sizeName;let R=(0,L.findNotCloseFlexContent)(d,"previousElementSibling");(S==="divorce"&&F.current>0||S==="bulldozer"&&H>0||!R)&&(R=d);let w=(0,L.findNotCloseFlexContent)(i.nextElementSibling,"nextElementSibling");if((S==="divorce"&&F.current<0||S==="bulldozer"&&H<0||!w)&&(w=i.nextElementSibling),!R||!w)return;const N=R.getBoundingClientRect(),$=window.getComputedStyle(R),Y=parseFloat($.getPropertyValue(A))||0,v=parseFloat($.getPropertyValue(X))||0,P=w.getBoundingClientRect(),I=window.getComputedStyle(w),W=parseFloat(I.getPropertyValue(A))||0,ee=parseFloat(I.getPropertyValue(X))||0;let _=N[E.sizeName]+H,V=P[E.sizeName]-H;if(v>0&&_>v||ee>0&&V>ee)return;(0,L.isOverMove)(_,Y)?(_=0,V=P[E.sizeName]):(0,L.isOverMove)(V,W)&&(V=0,_=N[E.sizeName]);const ae=_/(b.current-1)*y.current,me=V/(b.current-1)*y.current;R instanceof HTMLElement&&w instanceof HTMLElement&&(R.style.flex=`${ae} 1 0%`,w.style.flex=`${me} 1 0%`)}(0,u.useEffect)(()=>{const d=T.resizeDragSubject.subscribe(i=>{if(i.type==="START"){if(!i.targets.includes(p))return;B.current=i.sessionId,se(),i.cursor&&(document.body.style.cursor=i.cursor);return}if(i.type==="MOVE"){if(B.current!==i.sessionId||!M.current||!o.current)return;const x=s.current,z=m.current,S=o.current.previousElementSibling,E=o.current;if(!S||!E)return;le(S,E,{movementX:i.movementX,movementY:i.movementY},x,z);return}if(i.type==="END"){if(B.current!==i.sessionId)return;ie()}});return()=>d.unsubscribe()},[p]);const Q=d=>{if(!o.current)return;d.preventDefault?.();const i=d.nativeEvent,x=(0,L.getClientXy)(i);if(!x)return;const z=s.current,S=re(x.clientX,x.clientY,o.current,z,h),E=S?ne(x.clientX,x.clientY,o.current,z):[{el:o.current,key:p,dir:z}],H=new Set([p]);E.forEach(v=>H.add(v.key));const A=[...H],X=S&&A.length>=2?"move":j[z].resizeCursor,R=`${Date.now()}_${Math.random().toString(16).slice(2)}`;T.resizeDragSubject.next({type:"START",sessionId:R,targets:A,cursor:X}),k.current?.();let w=x.clientX,N=x.clientY;const $=v=>{v.preventDefault?.();const P=(0,L.getClientXy)(v);if(!P)return;const I=P.clientX-w,W=P.clientY-N;w=P.clientX,N=P.clientY,T.resizeDragSubject.next({type:"MOVE",sessionId:R,movementX:I,movementY:W})},Y=()=>{k.current?.(),k.current=null,T.resizeDragSubject.next({type:"END",sessionId:R})};["mousemove","touchmove"].forEach(v=>{window.addEventListener(v,$,{passive:!1})}),["mouseup","touchend","touchcancel","pointerup","pointercancel","blur"].forEach(v=>window.addEventListener(v,Y)),k.current=()=>{["mousemove","touchmove"].forEach(v=>window.removeEventListener(v,$)),["mouseup","touchend","touchcancel","pointerup","pointercancel","blur"].forEach(v=>window.removeEventListener(v,Y))}};(0,u.useEffect)(()=>{if(o.current)return(0,K.setResizePanelRef)(c,r,o),()=>{(0,K.setResizePanelRef)(c,r,null)}},[r,c]);const q=(0,u.useRef)([]),U=(0,u.useRef)(null),O=()=>{for(const d of q.current)d.querySelector(`.${C.default.hover}`)?.removeAttribute("data-is_hover");q.current=[]},ce=d=>{O();for(const i of d)i.querySelector(`.${C.default.hover}`)?.setAttribute("data-is_hover","");q.current=d},Z=d=>{o.current&&(U.current&&cancelAnimationFrame(U.current),U.current=requestAnimationFrame(()=>{const i=s.current;if(!re(d.clientX,d.clientY,o.current,i,h)){o.current.style.cursor="",O();return}const S=ne(d.clientX,d.clientY,o.current,i).filter(E=>E.dir&&E.dir!==i).map(E=>E.el);o.current.style.cursor=S.length>0?"move":"",ce(S)}))},ue=()=>{o.current&&(o.current.style.cursor="",O())};return(0,J.jsx)("div",{id:r+"_resize_panel","data-resize_panel_key":p,"data-direction":e,className:`${C.default["flex-resize-panel"]} ${C.default[n]} ${l&&l!==""?l:""}`,ref:o,onMouseDown:Q,onTouchStart:Q,onMouseMove:Z,onMouseEnter:Z,onMouseLeave:ue,children:(0,J.jsx)("div",{className:C.default.hover,"aria-hidden":!0})})}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { FlexLayoutResizePanelProps } from "../types/FlexLayoutTypes";
|
|
2
|
-
export default function FlexLayoutResizePanel({ direction, containerCount, panelMode, containerName, layoutName, panelClassName, panelMovementMode, }: FlexLayoutResizePanelProps): import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export default function FlexLayoutResizePanel({ direction, containerCount, panelMode, containerName, layoutName, panelClassName, panelMovementMode, onResizingChange, }: FlexLayoutResizePanelProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,186 +1 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useRef, useEffect } from 'react';
|
|
3
|
-
import { setResizePanelRef } from '../store/FlexLayoutContainerStore';
|
|
4
|
-
import styles from '../styles/FlexLayout.module.css';
|
|
5
|
-
import { findNotCloseFlexContent, isOverMove } from '../utils/FlexLayoutUtils';
|
|
6
|
-
|
|
7
|
-
const flexDirectionModel = {
|
|
8
|
-
row: {
|
|
9
|
-
xy: "x",
|
|
10
|
-
targetDirection: "left",
|
|
11
|
-
nextDirection: "right",
|
|
12
|
-
sizeName: "width",
|
|
13
|
-
resizeCursor: "ew-resize"
|
|
14
|
-
},
|
|
15
|
-
column: {
|
|
16
|
-
xy: "y",
|
|
17
|
-
targetDirection: "top",
|
|
18
|
-
nextDirection: "bottom",
|
|
19
|
-
sizeName: "height",
|
|
20
|
-
resizeCursor: "ns-resize"
|
|
21
|
-
}
|
|
22
|
-
};
|
|
23
|
-
function FlexLayoutResizePanel({
|
|
24
|
-
direction,
|
|
25
|
-
containerCount,
|
|
26
|
-
panelMode = "default",
|
|
27
|
-
containerName,
|
|
28
|
-
layoutName,
|
|
29
|
-
panelClassName,
|
|
30
|
-
panelMovementMode
|
|
31
|
-
}) {
|
|
32
|
-
const directionRef = useRef(direction);
|
|
33
|
-
const movementModeRef = useRef(panelMovementMode);
|
|
34
|
-
useEffect(() => {
|
|
35
|
-
directionRef.current = direction;
|
|
36
|
-
}, [direction]);
|
|
37
|
-
useEffect(() => {
|
|
38
|
-
movementModeRef.current = panelMovementMode;
|
|
39
|
-
}, [panelMovementMode]);
|
|
40
|
-
const isResizePanelClickRef = useRef(false);
|
|
41
|
-
const prevTouchEventRef = useRef(null);
|
|
42
|
-
const parentSizeRef = useRef(0);
|
|
43
|
-
const totalMovementRef = useRef(0);
|
|
44
|
-
const containerCountRef = useRef(containerCount);
|
|
45
|
-
const panelRef = useRef(null);
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
return () => {
|
|
48
|
-
document.body.style.cursor = "";
|
|
49
|
-
};
|
|
50
|
-
}, []);
|
|
51
|
-
useEffect(() => {
|
|
52
|
-
containerCountRef.current = containerCount;
|
|
53
|
-
}, [containerCount]);
|
|
54
|
-
const panelMouseDownEvent = (event) => {
|
|
55
|
-
if (!panelRef.current || !panelRef.current.parentElement) return;
|
|
56
|
-
isResizePanelClickRef.current = true;
|
|
57
|
-
containerCountRef.current = [
|
|
58
|
-
...panelRef.current.parentElement.children
|
|
59
|
-
].filter((e) => e.hasAttribute("data-container_name")).length;
|
|
60
|
-
const sizeName = flexDirectionModel[direction].sizeName;
|
|
61
|
-
parentSizeRef.current = panelRef.current.parentElement.getBoundingClientRect()[sizeName];
|
|
62
|
-
prevTouchEventRef.current = null;
|
|
63
|
-
totalMovementRef.current = 0;
|
|
64
|
-
if (!parentSizeRef.current) return;
|
|
65
|
-
document.body.style.cursor = flexDirectionModel[direction].resizeCursor;
|
|
66
|
-
};
|
|
67
|
-
const panelMouseUpEvent = () => {
|
|
68
|
-
isResizePanelClickRef.current = false;
|
|
69
|
-
parentSizeRef.current = 0;
|
|
70
|
-
totalMovementRef.current = 0;
|
|
71
|
-
prevTouchEventRef.current = null;
|
|
72
|
-
document.body.style.cursor = "";
|
|
73
|
-
};
|
|
74
|
-
function moveMouseFlex(originTarget, resizePanel, moveEvent, dir, mode) {
|
|
75
|
-
const model = flexDirectionModel[dir];
|
|
76
|
-
const movement = moveEvent["movement" + model.xy.toUpperCase()];
|
|
77
|
-
totalMovementRef.current += movement;
|
|
78
|
-
const minSizeName = "min-" + model.sizeName;
|
|
79
|
-
const maxSizeName = "max-" + model.sizeName;
|
|
80
|
-
let targetElement = findNotCloseFlexContent(
|
|
81
|
-
originTarget,
|
|
82
|
-
"previousElementSibling"
|
|
83
|
-
);
|
|
84
|
-
if (panelMovementMode === "divorce" && totalMovementRef.current > 0 || panelMovementMode === "bulldozer" && movement > 0 || !targetElement)
|
|
85
|
-
targetElement = originTarget;
|
|
86
|
-
let nextElement = findNotCloseFlexContent(
|
|
87
|
-
resizePanel.nextElementSibling,
|
|
88
|
-
"nextElementSibling"
|
|
89
|
-
);
|
|
90
|
-
if (panelMovementMode === "divorce" && totalMovementRef.current < 0 || panelMovementMode === "bulldozer" && movement < 0 || !nextElement)
|
|
91
|
-
nextElement = resizePanel.nextElementSibling;
|
|
92
|
-
if (!targetElement || !nextElement) return;
|
|
93
|
-
const targetRect = targetElement.getBoundingClientRect();
|
|
94
|
-
const targetStyle = window.getComputedStyle(targetElement);
|
|
95
|
-
const targetMinSize = parseFloat(targetStyle.getPropertyValue(minSizeName)) || 0;
|
|
96
|
-
const targetMaxSize = parseFloat(targetStyle.getPropertyValue(maxSizeName)) || 0;
|
|
97
|
-
const nextRect = nextElement.getBoundingClientRect();
|
|
98
|
-
const nextStyle = window.getComputedStyle(nextElement);
|
|
99
|
-
const nextMinSize = parseFloat(nextStyle.getPropertyValue(minSizeName)) || 0;
|
|
100
|
-
const nextMaxSize = parseFloat(nextStyle.getPropertyValue(maxSizeName)) || 0;
|
|
101
|
-
let targetSize = targetRect[model.sizeName] + movement;
|
|
102
|
-
let nextElementSize = nextRect[model.sizeName] - movement;
|
|
103
|
-
if (targetMaxSize > 0 && targetSize > targetMaxSize) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
if (nextMaxSize > 0 && nextElementSize > nextMaxSize) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (isOverMove(targetSize, targetMinSize)) {
|
|
110
|
-
targetSize = 0;
|
|
111
|
-
nextElementSize = nextRect[model.sizeName];
|
|
112
|
-
} else if (isOverMove(nextElementSize, nextMinSize)) {
|
|
113
|
-
nextElementSize = 0;
|
|
114
|
-
targetSize = targetRect[model.sizeName];
|
|
115
|
-
}
|
|
116
|
-
const targetFlexGrow = targetSize / (parentSizeRef.current - 1) * containerCountRef.current;
|
|
117
|
-
const nextElementFlexGrow = nextElementSize / (parentSizeRef.current - 1) * containerCountRef.current;
|
|
118
|
-
if (!(targetElement instanceof HTMLElement)) return;
|
|
119
|
-
if (!(nextElement instanceof HTMLElement)) return;
|
|
120
|
-
targetElement.style.flex = `${targetFlexGrow} 1 0%`;
|
|
121
|
-
nextElement.style.flex = `${nextElementFlexGrow} 1 0%`;
|
|
122
|
-
}
|
|
123
|
-
useEffect(() => {
|
|
124
|
-
const addGlobalMoveEvent = (event) => {
|
|
125
|
-
if (!isResizePanelClickRef.current || !panelRef.current) {
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
event.preventDefault();
|
|
129
|
-
const dir = directionRef.current;
|
|
130
|
-
movementModeRef.current;
|
|
131
|
-
const targetElement = panelRef.current.previousElementSibling;
|
|
132
|
-
const targetPanel = panelRef.current;
|
|
133
|
-
if (!targetElement || !targetPanel) return;
|
|
134
|
-
let move = { movementX: 0, movementY: 0 };
|
|
135
|
-
if (window.TouchEvent && event instanceof window.TouchEvent) {
|
|
136
|
-
const prev = prevTouchEventRef.current;
|
|
137
|
-
if (!prev) {
|
|
138
|
-
prevTouchEventRef.current = event;
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
move.movementX = (prev.touches[0].pageX - event.touches[0].pageX) * -1;
|
|
142
|
-
move.movementY = (prev.touches[0].pageY - event.touches[0].pageY) * -1;
|
|
143
|
-
prevTouchEventRef.current = event;
|
|
144
|
-
} else {
|
|
145
|
-
move.movementX = event.movementX;
|
|
146
|
-
move.movementY = event.movementY;
|
|
147
|
-
}
|
|
148
|
-
moveMouseFlex(targetElement, targetPanel, move, dir);
|
|
149
|
-
};
|
|
150
|
-
["mousemove", "touchmove"].forEach((eventName) => {
|
|
151
|
-
window.addEventListener(eventName, addGlobalMoveEvent, {
|
|
152
|
-
passive: false
|
|
153
|
-
});
|
|
154
|
-
});
|
|
155
|
-
["mouseup", "touchend"].forEach((eventName) => {
|
|
156
|
-
window.addEventListener(eventName, panelMouseUpEvent);
|
|
157
|
-
});
|
|
158
|
-
return () => {
|
|
159
|
-
["mousemove", "touchmove"].forEach((eventName) => {
|
|
160
|
-
window.removeEventListener(eventName, addGlobalMoveEvent);
|
|
161
|
-
});
|
|
162
|
-
["mouseup", "touchend"].forEach((eventName) => {
|
|
163
|
-
window.removeEventListener(eventName, panelMouseUpEvent);
|
|
164
|
-
});
|
|
165
|
-
};
|
|
166
|
-
}, []);
|
|
167
|
-
useEffect(() => {
|
|
168
|
-
if (!panelRef.current) return;
|
|
169
|
-
setResizePanelRef(layoutName, containerName, panelRef);
|
|
170
|
-
}, [containerName, layoutName]);
|
|
171
|
-
return /* @__PURE__ */ jsx(
|
|
172
|
-
"div",
|
|
173
|
-
{
|
|
174
|
-
id: containerName + "_resize_panel",
|
|
175
|
-
className: `${styles["flex-resize-panel"]} ${styles[panelMode]} ${panelClassName && panelClassName !== "" ? panelClassName : ""}`,
|
|
176
|
-
ref: panelRef,
|
|
177
|
-
onMouseDown: panelMouseDownEvent,
|
|
178
|
-
onTouchStart: panelMouseDownEvent,
|
|
179
|
-
children: /* @__PURE__ */ jsx("div", { className: styles.hover })
|
|
180
|
-
}
|
|
181
|
-
);
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
export { FlexLayoutResizePanel as default };
|
|
185
|
-
//# sourceMappingURL=FlexLayoutResizePanel.js.map
|
|
186
|
-
//# sourceMappingURL=FlexLayoutResizePanel.js.map
|
|
1
|
+
"use client";import{jsx as se}from"react/jsx-runtime";import{useEffect as H,useMemo as de,useRef as S}from"react";import{isResizingSubject as W,resizeDragSubject as I}from"../hooks";import{setResizePanelRef as Z}from"../store/FlexLayoutContainerStore";import P from"../styles/FlexLayout.module.css";import{findNotCloseFlexContent as ee,getClientXy as te,isOverMove as ne}from"../utils/FlexLayoutUtils";const j={row:{xy:"x",targetDirection:"left",nextDirection:"right",sizeName:"width",resizeCursor:"ew-resize"},column:{xy:"y",targetDirection:"top",nextDirection:"bottom",sizeName:"height",resizeCursor:"ns-resize"}},d=4,re=(n,e,r,t)=>{const g=new Map,l=(c,p)=>{const s=document.elementsFromPoint(c,p);for(const u of s){const v=u.closest?.(`.${P["flex-resize-panel"]}`);if(!v)continue;const a=v.dataset.resize_panel_key;a&&(g.has(a)||g.set(a,{el:v,key:a,dir:v.dataset.direction}))}};if([[0,0],[-d,0],[d,0],[0,-d],[0,d],[-d,-d],[d,-d],[-d,d],[d,d]].forEach(([c,p])=>l(n+c,e+p)),r&&t){const c=r.getBoundingClientRect(),p=t==="row"?c.width:t==="column"?c.height:1,s=Math.max(1,Math.ceil(p/2)),u=Math.ceil(d+p*2),f=Math.max(d,Math.ceil(p*2)),v=Array.from(new Set([1,Math.floor(f/2),Math.max(1,f-1)]));if(t==="row")for(let a=-u;a<=u;a+=s)for(const y of v)l(c.left-y,e+a),l(c.right+y,e+a);else if(t==="column")for(let a=-u;a<=u;a+=s)for(const y of v)l(n+a,c.top-y),l(n+a,c.bottom+y)}if(t){const p=[...g.values()].filter(s=>s.dir&&s.dir!==t);for(const s of p){const u=s.el.getBoundingClientRect(),f=s.dir==="row"?u.width:s.dir==="column"?u.height:1,v=Math.max(1,Math.ceil(f/2)),a=Math.ceil(d+f*2),y=Math.max(d,Math.ceil(f*2)),T=Array.from(new Set([1,Math.floor(y/2),Math.max(1,y-1)]));if(t==="column"&&s.dir==="row")for(let M=-a;M<=a;M+=v)for(const o of T)l(u.left-o,e+M),l(u.right+o,e+M);else if(t==="row"&&s.dir==="column")for(let M=-a;M<=a;M+=v)for(const o of T)l(n+M,u.top-o),l(n+M,u.bottom+o)}}return[...g.values()]},C=(n,e)=>{if(!n||n==="auto")return null;if(n.endsWith("px")){const t=parseFloat(n);return Number.isFinite(t)?t:null}if(n.endsWith("%")){const t=parseFloat(n);return Number.isFinite(t)?e*t/100:null}const r=parseFloat(n);return Number.isFinite(r)?r:null},pe=(n,e,r)=>n>=r.left&&n<=r.right&&e>=r.top&&e<=r.bottom,he=n=>{const e=n.getBoundingClientRect(),r=getComputedStyle(n,"::after");if(!r||r.content==="none"||r.content==="normal"||r.display==="none"||r.visibility==="hidden")return null;const t=C(r.width,e.width),g=C(r.height,e.height);if(!t||!g)return null;const l=C(r.left,e.width),c=C(r.right,e.width),p=C(r.top,e.height),s=C(r.bottom,e.height);let u=e.left;l!==null?u=e.left+l:c!==null&&(u=e.right-c-t);let f=e.top;return p!==null?f=e.top+p:s!==null&&(f=e.bottom-s-g),{left:u,top:f,right:u+t,bottom:f+g}},oe=(n,e,r,t,g)=>{const l=r.getBoundingClientRect(),c=he(r);if(c&&pe(n,e,c))return!1;const p=t==="row"?l.width:t==="column"?l.height:1,s=Math.max(g,Math.ceil(p));return t==="row"?n>=l.left-s&&n<=l.right+s:t==="column"?e>=l.top-s&&e<=l.bottom+s:!0};function ge({direction:n,containerCount:e,panelMode:r="default",containerName:t,layoutName:g,panelClassName:l,panelMovementMode:c,onResizingChange:p}){const s=S(n),u=S(c),f=de(()=>`${g}::${t}`,[g,t]);H(()=>{s.current=n},[n]),H(()=>{u.current=c},[c]);const v=S(!1),a=S(null),y=S(0),T=S(0),M=S(e),o=S(null),V=S(null),D=S(null);H(()=>()=>{W.next(!1),document.body.style.cursor="",D.current?.()},[]),H(()=>{M.current=e},[e]);const ie=()=>{if(!o.current||!o.current.parentElement)return;v.current=!0,p?.(!0),M.current=[...o.current.parentElement.children].filter(i=>i.hasAttribute("data-container_name")).length;const m=j[n].sizeName;y.current=o.current.parentElement.getBoundingClientRect()[m],a.current=null,T.current=0,W.next(!0)},le=()=>{v.current=!1,p?.(!1),y.current=0,T.current=0,V.current=null,W.next(!1),document.body.style.cursor="",B()};function ce(m,i,b,z,x){const h=j[z],L=b["movement"+h.xy.toUpperCase()];T.current+=L;const k="min-"+h.sizeName,O="max-"+h.sizeName;let R=ee(m,"previousElementSibling");(x==="divorce"&&T.current>0||x==="bulldozer"&&L>0||!R)&&(R=m);let w=ee(i.nextElementSibling,"nextElementSibling");if((x==="divorce"&&T.current<0||x==="bulldozer"&&L<0||!w)&&(w=i.nextElementSibling),!R||!w)return;const A=R.getBoundingClientRect(),N=window.getComputedStyle(R),X=parseFloat(N.getPropertyValue(k))||0,E=parseFloat(N.getPropertyValue(O))||0,F=w.getBoundingClientRect(),Y=window.getComputedStyle(w),U=parseFloat(Y.getPropertyValue(k))||0,Q=parseFloat(Y.getPropertyValue(O))||0;let $=A[h.sizeName]+L,_=F[h.sizeName]-L;if(E>0&&$>E||Q>0&&_>Q)return;ne($,X)?($=0,_=F[h.sizeName]):ne(_,U)&&(_=0,$=A[h.sizeName]);const me=$/(y.current-1)*M.current,fe=_/(y.current-1)*M.current;R instanceof HTMLElement&&w instanceof HTMLElement&&(R.style.flex=`${me} 1 0%`,w.style.flex=`${fe} 1 0%`)}H(()=>{const m=I.subscribe(i=>{if(i.type==="START"){if(!i.targets.includes(f))return;V.current=i.sessionId,ie(),i.cursor&&(document.body.style.cursor=i.cursor);return}if(i.type==="MOVE"){if(V.current!==i.sessionId||!v.current||!o.current)return;const b=s.current,z=u.current,x=o.current.previousElementSibling,h=o.current;if(!x||!h)return;ce(x,h,{movementX:i.movementX,movementY:i.movementY},b,z);return}if(i.type==="END"){if(V.current!==i.sessionId)return;le()}});return()=>m.unsubscribe()},[f]);const K=m=>{if(!o.current)return;m.preventDefault?.();const i=m.nativeEvent,b=te(i);if(!b)return;const z=s.current,x=oe(b.clientX,b.clientY,o.current,z,d),h=x?re(b.clientX,b.clientY,o.current,z):[{el:o.current,key:f,dir:z}],L=new Set([f]);h.forEach(E=>L.add(E.key));const k=[...L],O=x&&k.length>=2?"move":j[z].resizeCursor,R=`${Date.now()}_${Math.random().toString(16).slice(2)}`;I.next({type:"START",sessionId:R,targets:k,cursor:O}),D.current?.();let w=b.clientX,A=b.clientY;const N=E=>{E.preventDefault?.();const F=te(E);if(!F)return;const Y=F.clientX-w,U=F.clientY-A;w=F.clientX,A=F.clientY,I.next({type:"MOVE",sessionId:R,movementX:Y,movementY:U})},X=()=>{D.current?.(),D.current=null,I.next({type:"END",sessionId:R})};["mousemove","touchmove"].forEach(E=>{window.addEventListener(E,N,{passive:!1})}),["mouseup","touchend","touchcancel","pointerup","pointercancel","blur"].forEach(E=>window.addEventListener(E,X)),D.current=()=>{["mousemove","touchmove"].forEach(E=>window.removeEventListener(E,N)),["mouseup","touchend","touchcancel","pointerup","pointercancel","blur"].forEach(E=>window.removeEventListener(E,X))}};H(()=>{if(o.current)return Z(g,t,o),()=>{Z(g,t,null)}},[t,g]);const G=S([]),q=S(null),B=()=>{for(const m of G.current)m.querySelector(`.${P.hover}`)?.removeAttribute("data-is_hover");G.current=[]},ue=m=>{B();for(const i of m)i.querySelector(`.${P.hover}`)?.setAttribute("data-is_hover","");G.current=m},J=m=>{o.current&&(q.current&&cancelAnimationFrame(q.current),q.current=requestAnimationFrame(()=>{const i=s.current;if(!oe(m.clientX,m.clientY,o.current,i,d)){o.current.style.cursor="",B();return}const x=re(m.clientX,m.clientY,o.current,i).filter(h=>h.dir&&h.dir!==i).map(h=>h.el);o.current.style.cursor=x.length>0?"move":"",ue(x)}))},ae=()=>{o.current&&(o.current.style.cursor="",B())};return se("div",{id:t+"_resize_panel","data-resize_panel_key":f,"data-direction":n,className:`${P["flex-resize-panel"]} ${P[r]} ${l&&l!==""?l:""}`,ref:o,onMouseDown:K,onTouchStart:K,onMouseMove:J,onMouseEnter:J,onMouseLeave:ae,children:se("div",{className:P.hover,"aria-hidden":!0})})}export{ge as default};
|