react-public-components 0.1.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/README.md +178 -0
- package/dist/index.cjs +600 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.css +100 -0
- package/dist/index.css.map +1 -0
- package/dist/index.d.cts +46 -0
- package/dist/index.d.ts +46 -0
- package/dist/index.js +562 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,600 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
|
|
30
|
+
// src/index.ts
|
|
31
|
+
var index_exports = {};
|
|
32
|
+
__export(index_exports, {
|
|
33
|
+
CollapseBox: () => CollapseBox_default,
|
|
34
|
+
Splitter: () => Splitter_default
|
|
35
|
+
});
|
|
36
|
+
module.exports = __toCommonJS(index_exports);
|
|
37
|
+
|
|
38
|
+
// CollapseBox/index.tsx
|
|
39
|
+
var import_react = require("react");
|
|
40
|
+
|
|
41
|
+
// src/icons.tsx
|
|
42
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
43
|
+
var baseStyle = {
|
|
44
|
+
display: "inline-block",
|
|
45
|
+
width: "1em",
|
|
46
|
+
height: "1em",
|
|
47
|
+
verticalAlign: "-0.125em"
|
|
48
|
+
};
|
|
49
|
+
var LeftOutlined = ({ style, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
50
|
+
"svg",
|
|
51
|
+
{
|
|
52
|
+
viewBox: "0 0 1024 1024",
|
|
53
|
+
focusable: "false",
|
|
54
|
+
"data-icon": "left",
|
|
55
|
+
width: "1em",
|
|
56
|
+
height: "1em",
|
|
57
|
+
fill: "currentColor",
|
|
58
|
+
"aria-hidden": "true",
|
|
59
|
+
style: { ...baseStyle, ...style },
|
|
60
|
+
className,
|
|
61
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M724 218.3V141c0-6.7-7.7-10.4-12.9-6.3L260.3 486.8a31.86 31.86 0 000 50.3l450.8 352.1c5.3 4.1 12.9.4 12.9-6.3v-77.3c0-4.9-2.3-9.6-6.1-12.6l-360-281 360-281.1c3.8-3 6.1-7.7 6.1-12.6z" })
|
|
62
|
+
}
|
|
63
|
+
);
|
|
64
|
+
var RightOutlined = ({ style, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
65
|
+
"svg",
|
|
66
|
+
{
|
|
67
|
+
viewBox: "0 0 1024 1024",
|
|
68
|
+
focusable: "false",
|
|
69
|
+
"data-icon": "right",
|
|
70
|
+
width: "1em",
|
|
71
|
+
height: "1em",
|
|
72
|
+
fill: "currentColor",
|
|
73
|
+
"aria-hidden": "true",
|
|
74
|
+
style: { ...baseStyle, ...style },
|
|
75
|
+
className,
|
|
76
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M765.7 486.8L314.9 134.7A7.97 7.97 0 00302 141v77.3c0 4.9 2.3 9.6 6.1 12.6l360 281.1-360 281.1c-3.9 3-6.1 7.7-6.1 12.6V883c0 6.7 7.7 10.4 12.9 6.3l450.8-352.1a31.96 31.96 0 000-50.4z" })
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
var UpOutlined = ({ style, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
80
|
+
"svg",
|
|
81
|
+
{
|
|
82
|
+
viewBox: "0 0 1024 1024",
|
|
83
|
+
focusable: "false",
|
|
84
|
+
"data-icon": "up",
|
|
85
|
+
width: "1em",
|
|
86
|
+
height: "1em",
|
|
87
|
+
fill: "currentColor",
|
|
88
|
+
"aria-hidden": "true",
|
|
89
|
+
style: { ...baseStyle, ...style },
|
|
90
|
+
className,
|
|
91
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M890.5 755.3L537.4 268a31.96 31.96 0 00-50.8 0L133.5 755.3a7.95 7.95 0 006.3 12.7h75.5c4.9 0 9.6-2.3 12.6-6.1l281-360 281 360c3 3.8 7.7 6.1 12.6 6.1h75.5c6.7 0 10.4-7.6 6.1-12.7z" })
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
var DownOutlined = ({ style, className }) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
95
|
+
"svg",
|
|
96
|
+
{
|
|
97
|
+
viewBox: "0 0 1024 1024",
|
|
98
|
+
focusable: "false",
|
|
99
|
+
"data-icon": "down",
|
|
100
|
+
width: "1em",
|
|
101
|
+
height: "1em",
|
|
102
|
+
fill: "currentColor",
|
|
103
|
+
"aria-hidden": "true",
|
|
104
|
+
style: { ...baseStyle, ...style },
|
|
105
|
+
className,
|
|
106
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("path", { d: "M884 256h-75c-5.1 0-9.9 2.5-12.9 6.6L512 654.2 227.9 262.6c-3-4.1-7.8-6.6-12.9-6.6h-75c-6.5 0-10.3 7.4-6.5 12.7l352.6 486.1c12.8 17.6 37 17.6 49.8 0l352.6-486.1c3.9-5.3.1-12.7-6.4-12.7z" })
|
|
107
|
+
}
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
// CollapseBox/index.tsx
|
|
111
|
+
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
112
|
+
var isNumber = (value) => typeof value === "number" && !Number.isNaN(value);
|
|
113
|
+
var ChevronLeft = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(LeftOutlined, {});
|
|
114
|
+
var ChevronRight = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(RightOutlined, {});
|
|
115
|
+
var ChevronUp = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(UpOutlined, {});
|
|
116
|
+
var ChevronDown = () => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(DownOutlined, {});
|
|
117
|
+
var CollapsibleBox = ({
|
|
118
|
+
children,
|
|
119
|
+
title = "\u5185\u5BB9\u533A\u57DF",
|
|
120
|
+
direction = "horizontal",
|
|
121
|
+
buttonPosition = "right",
|
|
122
|
+
defaultWidth = 600,
|
|
123
|
+
defaultHeight = 300,
|
|
124
|
+
contentPadding = "16px",
|
|
125
|
+
headerHeight = 16
|
|
126
|
+
}) => {
|
|
127
|
+
const [isExpanded, setIsExpanded] = (0, import_react.useState)(true);
|
|
128
|
+
const contentMaxHeight = isNumber(defaultHeight) ? defaultHeight - headerHeight : "100%";
|
|
129
|
+
const getIcon = () => {
|
|
130
|
+
if (direction === "horizontal") {
|
|
131
|
+
if (buttonPosition === "right") {
|
|
132
|
+
return isExpanded ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChevronRight, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChevronLeft, {});
|
|
133
|
+
} else {
|
|
134
|
+
return isExpanded ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChevronLeft, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChevronRight, {});
|
|
135
|
+
}
|
|
136
|
+
} else {
|
|
137
|
+
if (buttonPosition === "bottom") {
|
|
138
|
+
return isExpanded ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChevronUp, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChevronDown, {});
|
|
139
|
+
} else {
|
|
140
|
+
return isExpanded ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChevronDown, {}) : /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(ChevronUp, {});
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
};
|
|
144
|
+
const getButtonClass = () => {
|
|
145
|
+
if (direction === "horizontal") {
|
|
146
|
+
return buttonPosition === "right" ? "button-right" : "button-left";
|
|
147
|
+
} else {
|
|
148
|
+
return buttonPosition === "bottom" ? "button-bottom" : "button-top";
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
const getContainerStyle = () => {
|
|
152
|
+
const resolvedHeight = isNumber(defaultHeight) ? `${defaultHeight}px` : defaultHeight;
|
|
153
|
+
if (direction === "horizontal") {
|
|
154
|
+
return {
|
|
155
|
+
width: isExpanded ? defaultWidth : "0px",
|
|
156
|
+
height: resolvedHeight,
|
|
157
|
+
minWidth: 0
|
|
158
|
+
};
|
|
159
|
+
} else {
|
|
160
|
+
return {
|
|
161
|
+
height: isExpanded ? resolvedHeight : "0px",
|
|
162
|
+
width: defaultWidth,
|
|
163
|
+
minHeight: 0
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
};
|
|
167
|
+
const wrapperClass = direction === "horizontal" ? "collapsible-wrapper horizontal" : "collapsible-wrapper vertical";
|
|
168
|
+
const containerClass = direction === "horizontal" && buttonPosition === "right" ? "collapsible-container align-right" : "collapsible-container";
|
|
169
|
+
const height = isNumber(contentMaxHeight) ? contentMaxHeight + "px" : "100%";
|
|
170
|
+
const contentStyle = {
|
|
171
|
+
maxHeight: direction === "vertical" ? isExpanded ? `${height}` : "0px" : `${height}`,
|
|
172
|
+
overflowY: "auto",
|
|
173
|
+
padding: direction === "vertical" && !isExpanded ? "0px" : contentPadding,
|
|
174
|
+
boxSizing: "border-box"
|
|
175
|
+
};
|
|
176
|
+
const buttonStyle = direction === "vertical" && buttonPosition === "bottom" && !isExpanded ? { top: "0px", bottom: "auto" } : {};
|
|
177
|
+
const wrapperStyle = direction === "vertical" ? isExpanded ? {
|
|
178
|
+
height: isNumber(defaultHeight) ? `${defaultHeight}px` : void 0,
|
|
179
|
+
width: defaultWidth
|
|
180
|
+
} : { height: 0, width: defaultWidth } : void 0;
|
|
181
|
+
return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: wrapperClass, style: wrapperStyle, children: [
|
|
182
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { style: getContainerStyle(), className: containerClass, children: [
|
|
183
|
+
title && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "collapsible-header", style: { display: "none" }, children: /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { children: title }) }),
|
|
184
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "collapsible-content", style: contentStyle, children })
|
|
185
|
+
] }),
|
|
186
|
+
/* @__PURE__ */ (0, import_jsx_runtime2.jsx)(
|
|
187
|
+
"div",
|
|
188
|
+
{
|
|
189
|
+
onClick: () => setIsExpanded(!isExpanded),
|
|
190
|
+
className: `toggle-button ${getButtonClass()}`,
|
|
191
|
+
style: buttonStyle,
|
|
192
|
+
title: isExpanded ? "\u9690\u85CF" : "\u5C55\u5F00",
|
|
193
|
+
children: getIcon()
|
|
194
|
+
}
|
|
195
|
+
)
|
|
196
|
+
] });
|
|
197
|
+
};
|
|
198
|
+
var CollapseBox_default = CollapsibleBox;
|
|
199
|
+
|
|
200
|
+
// Splitter/index.tsx
|
|
201
|
+
var import_react2 = __toESM(require("react"), 1);
|
|
202
|
+
var import_jsx_runtime3 = require("react/jsx-runtime");
|
|
203
|
+
var DRAGGER_SIZE = 8;
|
|
204
|
+
var MIN_PANEL_SIZE = 0;
|
|
205
|
+
var SplitterPanel = ({ children }) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_jsx_runtime3.Fragment, { children });
|
|
206
|
+
var isPercentSize = (value) => typeof value === "string" && value.endsWith("%");
|
|
207
|
+
var parseSize = (value, total, fallback) => {
|
|
208
|
+
if (value === void 0) {
|
|
209
|
+
return fallback;
|
|
210
|
+
}
|
|
211
|
+
if (isPercentSize(value)) {
|
|
212
|
+
return Number.parseFloat(value) / 100 * total;
|
|
213
|
+
}
|
|
214
|
+
return Number(value);
|
|
215
|
+
};
|
|
216
|
+
var roundSizes = (sizes) => sizes.map((size) => Math.round(size));
|
|
217
|
+
var getPointerPosition = (event, orientation) => orientation === "horizontal" ? event.clientX : event.clientY;
|
|
218
|
+
var clamp = (value, min, max) => Math.min(Math.max(value, min), max);
|
|
219
|
+
var CustomSplitter = ({
|
|
220
|
+
children,
|
|
221
|
+
className,
|
|
222
|
+
lazy = false,
|
|
223
|
+
onResize,
|
|
224
|
+
onResizeEnd,
|
|
225
|
+
onResizeStart,
|
|
226
|
+
orientation,
|
|
227
|
+
style,
|
|
228
|
+
vertical = false
|
|
229
|
+
}) => {
|
|
230
|
+
const resolvedOrientation = orientation != null ? orientation : vertical ? "vertical" : "horizontal";
|
|
231
|
+
const rootRef = (0, import_react2.useRef)(null);
|
|
232
|
+
const sizesRef = (0, import_react2.useRef)([]);
|
|
233
|
+
const lastNonZeroSizesRef = (0, import_react2.useRef)([]);
|
|
234
|
+
const [containerSize, setContainerSize] = (0, import_react2.useState)(0);
|
|
235
|
+
const [draggingIndex, setDraggingIndex] = (0, import_react2.useState)(null);
|
|
236
|
+
const [hoveredIndex, setHoveredIndex] = (0, import_react2.useState)(null);
|
|
237
|
+
const [sizes, setSizes] = (0, import_react2.useState)([]);
|
|
238
|
+
const panels = (0, import_react2.useMemo)(
|
|
239
|
+
() => import_react2.default.Children.toArray(children).filter(
|
|
240
|
+
import_react2.default.isValidElement
|
|
241
|
+
),
|
|
242
|
+
[children]
|
|
243
|
+
);
|
|
244
|
+
const trackSize = Math.max(0, containerSize - Math.max(0, panels.length - 1) * DRAGGER_SIZE);
|
|
245
|
+
const getPanelMin = (0, import_react2.useCallback)(
|
|
246
|
+
(index) => {
|
|
247
|
+
var _a;
|
|
248
|
+
return parseSize((_a = panels[index]) == null ? void 0 : _a.props.min, trackSize, MIN_PANEL_SIZE);
|
|
249
|
+
},
|
|
250
|
+
[panels, trackSize]
|
|
251
|
+
);
|
|
252
|
+
const getPanelMax = (0, import_react2.useCallback)(
|
|
253
|
+
(index) => {
|
|
254
|
+
var _a;
|
|
255
|
+
return parseSize((_a = panels[index]) == null ? void 0 : _a.props.max, trackSize, trackSize);
|
|
256
|
+
},
|
|
257
|
+
[panels, trackSize]
|
|
258
|
+
);
|
|
259
|
+
const normalizeToTrack = (0, import_react2.useCallback)(
|
|
260
|
+
(nextSizes) => {
|
|
261
|
+
if (!trackSize || !nextSizes.length) {
|
|
262
|
+
return nextSizes;
|
|
263
|
+
}
|
|
264
|
+
const normalized = [...nextSizes];
|
|
265
|
+
const diff = trackSize - normalized.reduce((sum, size) => sum + size, 0);
|
|
266
|
+
const flexibleIndex = normalized.findIndex((size) => size > 0);
|
|
267
|
+
normalized[flexibleIndex === -1 ? 0 : flexibleIndex] += diff;
|
|
268
|
+
return normalized.map((size, index) => clamp(size, 0, getPanelMax(index)));
|
|
269
|
+
},
|
|
270
|
+
[getPanelMax, trackSize]
|
|
271
|
+
);
|
|
272
|
+
const buildInitialSizes = (0, import_react2.useCallback)(
|
|
273
|
+
(previous) => {
|
|
274
|
+
if (!trackSize || !panels.length) {
|
|
275
|
+
return [];
|
|
276
|
+
}
|
|
277
|
+
if ((previous == null ? void 0 : previous.length) === panels.length) {
|
|
278
|
+
const previousTotal = previous.reduce((sum, size) => sum + size, 0);
|
|
279
|
+
if (previousTotal > 0) {
|
|
280
|
+
return normalizeToTrack(previous.map((size) => size / previousTotal * trackSize));
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
const explicitSizes = panels.map(
|
|
284
|
+
(panel) => {
|
|
285
|
+
var _a;
|
|
286
|
+
return parseSize((_a = panel.props.size) != null ? _a : panel.props.defaultSize, trackSize, -1);
|
|
287
|
+
}
|
|
288
|
+
);
|
|
289
|
+
const usedSize = explicitSizes.filter((size) => size >= 0).reduce((sum, size) => sum + size, 0);
|
|
290
|
+
const unsetCount = explicitSizes.filter((size) => size < 0).length;
|
|
291
|
+
const fallbackSize = unsetCount ? Math.max(0, (trackSize - usedSize) / unsetCount) : 0;
|
|
292
|
+
return normalizeToTrack(
|
|
293
|
+
explicitSizes.map(
|
|
294
|
+
(size, index) => clamp(size >= 0 ? size : fallbackSize, getPanelMin(index), getPanelMax(index))
|
|
295
|
+
)
|
|
296
|
+
);
|
|
297
|
+
},
|
|
298
|
+
[getPanelMax, getPanelMin, normalizeToTrack, panels, trackSize]
|
|
299
|
+
);
|
|
300
|
+
const updateSizes = (0, import_react2.useCallback)(
|
|
301
|
+
(nextSizes, notify = true) => {
|
|
302
|
+
const normalized = normalizeToTrack(nextSizes);
|
|
303
|
+
setSizes(normalized);
|
|
304
|
+
sizesRef.current = normalized;
|
|
305
|
+
normalized.forEach((size, index) => {
|
|
306
|
+
if (size > 1) {
|
|
307
|
+
lastNonZeroSizesRef.current[index] = size;
|
|
308
|
+
}
|
|
309
|
+
});
|
|
310
|
+
if (notify) {
|
|
311
|
+
onResize == null ? void 0 : onResize(roundSizes(normalized));
|
|
312
|
+
}
|
|
313
|
+
},
|
|
314
|
+
[normalizeToTrack, onResize]
|
|
315
|
+
);
|
|
316
|
+
(0, import_react2.useEffect)(() => {
|
|
317
|
+
const node = rootRef.current;
|
|
318
|
+
if (!node) {
|
|
319
|
+
return void 0;
|
|
320
|
+
}
|
|
321
|
+
const syncSize = () => {
|
|
322
|
+
const rect = node.getBoundingClientRect();
|
|
323
|
+
setContainerSize(resolvedOrientation === "horizontal" ? rect.width : rect.height);
|
|
324
|
+
};
|
|
325
|
+
syncSize();
|
|
326
|
+
const observer = new ResizeObserver(syncSize);
|
|
327
|
+
observer.observe(node);
|
|
328
|
+
return () => observer.disconnect();
|
|
329
|
+
}, [resolvedOrientation]);
|
|
330
|
+
(0, import_react2.useEffect)(() => {
|
|
331
|
+
setSizes((previous) => {
|
|
332
|
+
const nextSizes = buildInitialSizes(previous);
|
|
333
|
+
sizesRef.current = nextSizes;
|
|
334
|
+
lastNonZeroSizesRef.current = nextSizes.map(
|
|
335
|
+
(size) => Math.max(size, trackSize / Math.max(panels.length, 1))
|
|
336
|
+
);
|
|
337
|
+
return nextSizes;
|
|
338
|
+
});
|
|
339
|
+
}, [buildInitialSizes, panels.length, trackSize]);
|
|
340
|
+
const getResizedPair = (0, import_react2.useCallback)(
|
|
341
|
+
(sourceSizes, index, delta) => {
|
|
342
|
+
const nextSizes = [...sourceSizes];
|
|
343
|
+
const leftSize = nextSizes[index];
|
|
344
|
+
const rightSize = nextSizes[index + 1];
|
|
345
|
+
const leftMin = getPanelMin(index);
|
|
346
|
+
const rightMin = getPanelMin(index + 1);
|
|
347
|
+
const leftMax = getPanelMax(index);
|
|
348
|
+
const rightMax = getPanelMax(index + 1);
|
|
349
|
+
const minDelta = Math.max(leftMin - leftSize, rightSize - rightMax);
|
|
350
|
+
const maxDelta = Math.min(leftMax - leftSize, rightSize - rightMin);
|
|
351
|
+
const safeDelta = clamp(delta, minDelta, maxDelta);
|
|
352
|
+
nextSizes[index] = leftSize + safeDelta;
|
|
353
|
+
nextSizes[index + 1] = rightSize - safeDelta;
|
|
354
|
+
return normalizeToTrack(nextSizes);
|
|
355
|
+
},
|
|
356
|
+
[getPanelMax, getPanelMin, normalizeToTrack]
|
|
357
|
+
);
|
|
358
|
+
const resizePair = (0, import_react2.useCallback)(
|
|
359
|
+
(index, delta, notify = true) => {
|
|
360
|
+
updateSizes(getResizedPair(sizesRef.current, index, delta), notify);
|
|
361
|
+
},
|
|
362
|
+
[getResizedPair, updateSizes]
|
|
363
|
+
);
|
|
364
|
+
const startResize = (index, event) => {
|
|
365
|
+
if (panels[index].props.resizable === false || panels[index + 1].props.resizable === false) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
event.preventDefault();
|
|
369
|
+
const startPosition = getPointerPosition(event, resolvedOrientation);
|
|
370
|
+
const startSizes = [...sizesRef.current];
|
|
371
|
+
let latestSizes = startSizes;
|
|
372
|
+
setDraggingIndex(index);
|
|
373
|
+
onResizeStart == null ? void 0 : onResizeStart(roundSizes(startSizes));
|
|
374
|
+
const handlePointerMove = (moveEvent) => {
|
|
375
|
+
const delta = getPointerPosition(moveEvent, resolvedOrientation) - startPosition;
|
|
376
|
+
latestSizes = getResizedPair(startSizes, index, delta);
|
|
377
|
+
if (!lazy) {
|
|
378
|
+
updateSizes(latestSizes, true);
|
|
379
|
+
}
|
|
380
|
+
};
|
|
381
|
+
const handlePointerUp = () => {
|
|
382
|
+
document.removeEventListener("pointermove", handlePointerMove);
|
|
383
|
+
document.removeEventListener("pointerup", handlePointerUp);
|
|
384
|
+
setDraggingIndex(null);
|
|
385
|
+
if (lazy) {
|
|
386
|
+
updateSizes(latestSizes, true);
|
|
387
|
+
}
|
|
388
|
+
onResizeEnd == null ? void 0 : onResizeEnd(roundSizes(sizesRef.current));
|
|
389
|
+
};
|
|
390
|
+
document.addEventListener("pointermove", handlePointerMove);
|
|
391
|
+
document.addEventListener("pointerup", handlePointerUp);
|
|
392
|
+
};
|
|
393
|
+
const toggleCollapse = (index, neighborIndex) => {
|
|
394
|
+
const nextSizes = [...sizesRef.current];
|
|
395
|
+
if (nextSizes[index] > 1) {
|
|
396
|
+
lastNonZeroSizesRef.current[index] = nextSizes[index];
|
|
397
|
+
nextSizes[neighborIndex] += nextSizes[index];
|
|
398
|
+
nextSizes[index] = 0;
|
|
399
|
+
} else {
|
|
400
|
+
const restoredSize = lastNonZeroSizesRef.current[index] || parseSize(panels[index].props.defaultSize, trackSize, trackSize / panels.length);
|
|
401
|
+
nextSizes[index] = clamp(restoredSize, getPanelMin(index), getPanelMax(index));
|
|
402
|
+
nextSizes[neighborIndex] = Math.max(0, nextSizes[neighborIndex] - nextSizes[index]);
|
|
403
|
+
}
|
|
404
|
+
updateSizes(nextSizes);
|
|
405
|
+
onResizeEnd == null ? void 0 : onResizeEnd(roundSizes(sizesRef.current));
|
|
406
|
+
};
|
|
407
|
+
const resetSizes = () => {
|
|
408
|
+
const nextSizes = buildInitialSizes();
|
|
409
|
+
updateSizes(nextSizes);
|
|
410
|
+
onResizeEnd == null ? void 0 : onResizeEnd(roundSizes(nextSizes));
|
|
411
|
+
};
|
|
412
|
+
const rootStyle = {
|
|
413
|
+
border: "1px solid #f0f0f0",
|
|
414
|
+
borderRadius: 8,
|
|
415
|
+
display: "flex",
|
|
416
|
+
flexDirection: resolvedOrientation === "horizontal" ? "row" : "column",
|
|
417
|
+
height: 360,
|
|
418
|
+
minHeight: 0,
|
|
419
|
+
overflow: "hidden",
|
|
420
|
+
width: "100%",
|
|
421
|
+
...style
|
|
422
|
+
};
|
|
423
|
+
const renderCollapseButton = (draggerIndex, panelIndex, direction) => {
|
|
424
|
+
var _a, _b;
|
|
425
|
+
const panel = panels[panelIndex];
|
|
426
|
+
if (!(panel == null ? void 0 : panel.props.collapsible)) {
|
|
427
|
+
return null;
|
|
428
|
+
}
|
|
429
|
+
const neighborIndex = direction === "start" ? panelIndex + 1 : panelIndex - 1;
|
|
430
|
+
const isCollapsed = ((_a = sizes[panelIndex]) != null ? _a : 0) <= 1;
|
|
431
|
+
const isNeighborCollapsed = ((_b = sizes[neighborIndex]) != null ? _b : 0) <= 1;
|
|
432
|
+
if (isCollapsed || isNeighborCollapsed) {
|
|
433
|
+
return null;
|
|
434
|
+
}
|
|
435
|
+
const Icon = resolvedOrientation === "horizontal" ? direction === "start" ? LeftOutlined : RightOutlined : direction === "start" ? UpOutlined : DownOutlined;
|
|
436
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
437
|
+
"button",
|
|
438
|
+
{
|
|
439
|
+
"aria-label": "\u6298\u53E0\u9762\u677F",
|
|
440
|
+
title: "\u6298\u53E0\u9762\u677F",
|
|
441
|
+
onClick: (event) => {
|
|
442
|
+
event.stopPropagation();
|
|
443
|
+
toggleCollapse(panelIndex, neighborIndex);
|
|
444
|
+
},
|
|
445
|
+
style: {
|
|
446
|
+
alignItems: "center",
|
|
447
|
+
background: "#fff",
|
|
448
|
+
border: "1px solid #d9d9d9",
|
|
449
|
+
borderRadius: 4,
|
|
450
|
+
color: "#595959",
|
|
451
|
+
cursor: "pointer",
|
|
452
|
+
display: "flex",
|
|
453
|
+
height: 20,
|
|
454
|
+
justifyContent: "center",
|
|
455
|
+
padding: 0,
|
|
456
|
+
width: 20,
|
|
457
|
+
fontSize: 12
|
|
458
|
+
},
|
|
459
|
+
type: "button",
|
|
460
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, {})
|
|
461
|
+
}
|
|
462
|
+
);
|
|
463
|
+
};
|
|
464
|
+
const renderExpandButton = (panelIndex, direction) => {
|
|
465
|
+
var _a;
|
|
466
|
+
const panel = panels[panelIndex];
|
|
467
|
+
if (!(panel == null ? void 0 : panel.props.collapsible)) {
|
|
468
|
+
return null;
|
|
469
|
+
}
|
|
470
|
+
const isCollapsed = ((_a = sizes[panelIndex]) != null ? _a : 0) <= 1;
|
|
471
|
+
if (!isCollapsed) {
|
|
472
|
+
return null;
|
|
473
|
+
}
|
|
474
|
+
const neighborIndex = direction === "start" ? panelIndex + 1 : panelIndex - 1;
|
|
475
|
+
const Icon = resolvedOrientation === "horizontal" ? direction === "start" ? RightOutlined : LeftOutlined : direction === "start" ? DownOutlined : UpOutlined;
|
|
476
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
477
|
+
"button",
|
|
478
|
+
{
|
|
479
|
+
"aria-label": "\u5C55\u5F00\u9762\u677F",
|
|
480
|
+
title: "\u5C55\u5F00\u9762\u677F",
|
|
481
|
+
onClick: (event) => {
|
|
482
|
+
event.stopPropagation();
|
|
483
|
+
toggleCollapse(panelIndex, neighborIndex);
|
|
484
|
+
},
|
|
485
|
+
style: {
|
|
486
|
+
alignItems: "center",
|
|
487
|
+
background: "#fff",
|
|
488
|
+
border: "1px solid #d9d9d9",
|
|
489
|
+
borderRadius: 4,
|
|
490
|
+
color: "#595959",
|
|
491
|
+
cursor: "pointer",
|
|
492
|
+
display: "flex",
|
|
493
|
+
height: 20,
|
|
494
|
+
justifyContent: "center",
|
|
495
|
+
padding: 0,
|
|
496
|
+
width: 20,
|
|
497
|
+
fontSize: 12
|
|
498
|
+
},
|
|
499
|
+
type: "button",
|
|
500
|
+
children: /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(Icon, {})
|
|
501
|
+
}
|
|
502
|
+
);
|
|
503
|
+
};
|
|
504
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className, ref: rootRef, style: rootStyle, children: panels.map((panel, index) => {
|
|
505
|
+
var _a, _b, _c, _d, _e;
|
|
506
|
+
const isHidden = sizes[index] <= 1;
|
|
507
|
+
return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(import_react2.default.Fragment, { children: [
|
|
508
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
509
|
+
"div",
|
|
510
|
+
{
|
|
511
|
+
style: {
|
|
512
|
+
background: index % 2 ? "#fff" : "#fafafa",
|
|
513
|
+
flex: `0 0 ${(_a = sizes[index]) != null ? _a : 0}px`,
|
|
514
|
+
minHeight: 0,
|
|
515
|
+
minWidth: 0,
|
|
516
|
+
overflow: "auto",
|
|
517
|
+
padding: isHidden ? 0 : 16,
|
|
518
|
+
transition: draggingIndex === null ? "flex-basis 0.2s ease" : void 0,
|
|
519
|
+
...panel.props.style
|
|
520
|
+
},
|
|
521
|
+
children: !isHidden && panel.props.children
|
|
522
|
+
}
|
|
523
|
+
),
|
|
524
|
+
index < panels.length - 1 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
525
|
+
"div",
|
|
526
|
+
{
|
|
527
|
+
"aria-orientation": resolvedOrientation,
|
|
528
|
+
onDoubleClick: resetSizes,
|
|
529
|
+
onKeyDown: (event) => {
|
|
530
|
+
const step = event.shiftKey ? 40 : 10;
|
|
531
|
+
const directionMap = resolvedOrientation === "horizontal" ? { ArrowLeft: -step, ArrowRight: step } : { ArrowUp: -step, ArrowDown: step };
|
|
532
|
+
const delta = directionMap[event.key];
|
|
533
|
+
if (delta !== void 0) {
|
|
534
|
+
event.preventDefault();
|
|
535
|
+
resizePair(index, delta);
|
|
536
|
+
}
|
|
537
|
+
},
|
|
538
|
+
onPointerDown: (event) => startResize(index, event),
|
|
539
|
+
onPointerEnter: () => setHoveredIndex(index),
|
|
540
|
+
onPointerLeave: () => setHoveredIndex(null),
|
|
541
|
+
role: "separator",
|
|
542
|
+
style: {
|
|
543
|
+
alignItems: "center",
|
|
544
|
+
background: hoveredIndex === index || draggingIndex === index ? "#e6f4ff" : "#f5f5f5",
|
|
545
|
+
cursor: resolvedOrientation === "horizontal" ? "col-resize" : "row-resize",
|
|
546
|
+
display: "flex",
|
|
547
|
+
flex: `0 0 ${DRAGGER_SIZE}px`,
|
|
548
|
+
justifyContent: "center",
|
|
549
|
+
outline: "none",
|
|
550
|
+
position: "relative",
|
|
551
|
+
userSelect: "none",
|
|
552
|
+
zIndex: 1
|
|
553
|
+
},
|
|
554
|
+
tabIndex: 0,
|
|
555
|
+
children: [
|
|
556
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
557
|
+
"div",
|
|
558
|
+
{
|
|
559
|
+
style: {
|
|
560
|
+
background: hoveredIndex === index || draggingIndex === index ? "#1677ff" : "#d9d9d9",
|
|
561
|
+
borderRadius: 2,
|
|
562
|
+
height: resolvedOrientation === "horizontal" ? 48 : 2,
|
|
563
|
+
width: resolvedOrientation === "horizontal" ? 2 : 48
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
),
|
|
567
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsxs)(
|
|
568
|
+
"div",
|
|
569
|
+
{
|
|
570
|
+
style: {
|
|
571
|
+
position: "absolute",
|
|
572
|
+
display: "flex",
|
|
573
|
+
flexDirection: resolvedOrientation === "horizontal" ? "column" : "row",
|
|
574
|
+
gap: 2,
|
|
575
|
+
opacity: hoveredIndex === index || ((_b = sizes[index]) != null ? _b : 0) <= 1 || ((_c = sizes[index + 1]) != null ? _c : 0) <= 1 ? 1 : 0,
|
|
576
|
+
transition: "opacity 0.15s ease",
|
|
577
|
+
pointerEvents: hoveredIndex === index || ((_d = sizes[index]) != null ? _d : 0) <= 1 || ((_e = sizes[index + 1]) != null ? _e : 0) <= 1 ? "auto" : "none"
|
|
578
|
+
},
|
|
579
|
+
children: [
|
|
580
|
+
renderCollapseButton(index, index, "start"),
|
|
581
|
+
renderCollapseButton(index, index + 1, "end"),
|
|
582
|
+
renderExpandButton(index, "start"),
|
|
583
|
+
renderExpandButton(index + 1, "end")
|
|
584
|
+
]
|
|
585
|
+
}
|
|
586
|
+
)
|
|
587
|
+
]
|
|
588
|
+
}
|
|
589
|
+
)
|
|
590
|
+
] }, index);
|
|
591
|
+
}) });
|
|
592
|
+
};
|
|
593
|
+
CustomSplitter.Panel = SplitterPanel;
|
|
594
|
+
var Splitter_default = CustomSplitter;
|
|
595
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
596
|
+
0 && (module.exports = {
|
|
597
|
+
CollapseBox,
|
|
598
|
+
Splitter
|
|
599
|
+
});
|
|
600
|
+
//# sourceMappingURL=index.cjs.map
|