react-resize-demo 1.0.2 → 2.0.1

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.
Files changed (43) hide show
  1. package/CHANGELOG.md +93 -1
  2. package/README.md +203 -110
  3. package/dist/components/ResizeHandle/index.js +92 -0
  4. package/dist/components/ResizeHandle/index.js.map +1 -0
  5. package/dist/components/ResizePanel/index.js +33 -0
  6. package/dist/components/ResizePanel/index.js.map +1 -0
  7. package/dist/components/ResizePanelGroup/index.js +61 -0
  8. package/dist/components/ResizePanelGroup/index.js.map +1 -0
  9. package/dist/components/shared/context.js +35 -0
  10. package/dist/components/shared/context.js.map +1 -0
  11. package/dist/esm/components/ResizeHandle/index.js +90 -0
  12. package/dist/esm/components/ResizeHandle/index.js.map +1 -0
  13. package/dist/esm/components/ResizePanel/index.js +31 -0
  14. package/dist/esm/components/ResizePanel/index.js.map +1 -0
  15. package/dist/esm/components/ResizePanelGroup/index.js +59 -0
  16. package/dist/esm/components/ResizePanelGroup/index.js.map +1 -0
  17. package/dist/esm/components/shared/context.js +32 -0
  18. package/dist/esm/components/shared/context.js.map +1 -0
  19. package/dist/esm/index.js +6 -0
  20. package/dist/esm/index.js.map +1 -0
  21. package/dist/esm/utils/resizeAble.js +427 -0
  22. package/dist/esm/utils/resizeAble.js.map +1 -0
  23. package/dist/esm/utils/virtualNode.js +164 -0
  24. package/dist/esm/utils/virtualNode.js.map +1 -0
  25. package/dist/index.js +9 -721
  26. package/dist/index.js.map +1 -1
  27. package/dist/types/index.d.ts +68 -2
  28. package/dist/utils/resizeAble.js +431 -0
  29. package/dist/utils/resizeAble.js.map +1 -0
  30. package/dist/utils/virtualNode.js +168 -0
  31. package/dist/utils/virtualNode.js.map +1 -0
  32. package/package.json +30 -3
  33. package/dist/components/ResizeHandle/index.d.ts +0 -8
  34. package/dist/components/ResizeHandle/index.d.ts.map +0 -1
  35. package/dist/components/ResizePanel/index.d.ts +0 -19
  36. package/dist/components/ResizePanel/index.d.ts.map +0 -1
  37. package/dist/index.d.ts +0 -22
  38. package/dist/index.d.ts.map +0 -1
  39. package/dist/index.esm.js +0 -724
  40. package/dist/index.esm.js.map +0 -1
  41. package/dist/types/index.d.ts.map +0 -1
  42. package/dist/utils/index.d.ts +0 -5
  43. package/dist/utils/index.d.ts.map +0 -1
package/CHANGELOG.md CHANGED
@@ -5,6 +5,99 @@
5
5
  格式基于 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.0.0/),
6
6
  版本号遵循 [Semantic Versioning](https://semver.org/lang/zh-CN/)。
7
7
 
8
+ ## [2.0.0] - 2026-01-10
9
+
10
+ ### 🎉 重大版本更新
11
+
12
+ 这是一个重大版本更新,包含架构重构、组件拆分、命名修正和打包优化等多项重要改进。
13
+
14
+ ### ✨ 新增
15
+
16
+ - **模块化架构**
17
+ - 新增 `types/` 目录,集中管理所有 TypeScript 类型定义
18
+ - 新增 `utils/` 目录,统一管理工具函数和核心逻辑
19
+ - 新增 `components/shared/` 目录,存放共享的 Context 和 Hook
20
+
21
+ - **组件拆分**
22
+ - 将组件拆分为独立的功能模块:
23
+ - `ResizePanelGroup/` - 容器组件,管理布局
24
+ - `ResizePanel/` - 面板组件,展示内容
25
+ - `ResizeHandle/` - 拖拽手柄组件,处理交互
26
+ - `shared/context` - 共享状态管理
27
+
28
+ - **分层打包**
29
+ - 使用 `preserveModules` 保持源码目录结构
30
+ - 支持按需导入,更好的 Tree-shaking
31
+ - 提供 CJS 和 ESM 双格式支持
32
+ - 类型定义独立打包到 `dist/types/`
33
+
34
+ - **命名修正**
35
+ - 修正所有命名:`Resizeable` → `Resizable`(正确拼写)
36
+ - 保留向后兼容的旧命名导出
37
+
38
+ ### 🔄 变更
39
+
40
+ - **项目结构重构**
41
+ - `src/core/` → `src/utils/`(更语义化的命名)
42
+ - 组件从单一文件夹拆分为多个独立文件夹
43
+ - 所有 `.js` 文件转换为 `.ts`,完整的 TypeScript 支持
44
+
45
+ - **打包产物结构**
46
+ ```
47
+ dist/
48
+ ├── index.js # CJS 主入口
49
+ ├── esm/ # ESM 模块
50
+ │ ├── index.js
51
+ │ ├── components/
52
+ │ ├── utils/
53
+ │ └── types/
54
+ ├── components/ # CJS 组件
55
+ ├── utils/ # CJS 工具
56
+ └── types/ # 类型定义
57
+ ```
58
+
59
+ - **导入路径**
60
+ - 支持分层导入:
61
+ ```typescript
62
+ import { ResizablePanelGroup } from 'react-resize-demo';
63
+ import { ResizablePanel } from 'react-resize-demo/components/ResizePanel';
64
+ import { ResizeAbleCore } from 'react-resize-demo/utils';
65
+ import type { VirtualConfig } from 'react-resize-demo/types';
66
+ ```
67
+
68
+ ### 🔧 改进
69
+
70
+ - **代码质量**
71
+ - 完整的 TypeScript 类型支持
72
+ - 移除所有 `@ts-expect-error` 注释
73
+ - 优化导入路径,更清晰的模块依赖
74
+
75
+ - **开发体验**
76
+ - 更清晰的目录结构,便于维护
77
+ - 组件职责单一,易于扩展
78
+ - 统一的导出入口
79
+
80
+ - **性能优化**
81
+ - 支持 Tree-shaking,按需导入减少打包体积
82
+ - 保持模块结构,优化构建性能
83
+
84
+ ### 📝 向后兼容
85
+
86
+ - 保留了旧的导出名称(`ResizeablePanelGroup`、`ResizeablePanel` 等)
87
+ - 主入口导入方式保持不变
88
+ - 现有代码无需修改即可使用
89
+
90
+ ### 🚨 破坏性变更
91
+
92
+ - 如果直接导入子模块路径,需要更新导入路径
93
+ - 内部 API 结构发生变化,但公共 API 保持兼容
94
+
95
+ ### 📚 文档
96
+
97
+ - 更新 README,反映新的架构和使用方式
98
+ - 更新项目结构说明
99
+ - 添加分层导入示例
100
+
8
101
  ## [1.0.3] - 2026-01-09
9
102
 
10
103
  ### 新增
@@ -73,4 +166,3 @@
73
166
  - 支持设置面板最小尺寸
74
167
  - 支持拖拽调整相邻面板的宽度/高度
75
168
  - 实现了级联调整:当面板达到最小值时,自动从相邻面板获取空间
76
-
package/README.md CHANGED
@@ -1,42 +1,51 @@
1
1
  # react-resize-demo
2
2
 
3
- 一个 React 可调整大小面板组件库,支持水平和垂直方向的布局调整。
3
+ 一个现代化的 React 可调整大小面板组件库,支持水平和垂直方向的布局调整,具备完整的 TypeScript 支持和模块化架构。
4
4
 
5
- ## 特性
5
+ **源码地址**: [https://gitee.com/zugechen/react-resize-demo](https://gitee.com/zugechen/react-resize-demo)
6
6
 
7
- - 支持水平和垂直方向的布局
8
- - ✅ 可拖拽调整相邻面板的宽度/高度
9
- - ✅ 支持设置面板最小尺寸
10
- - ✅ 级联调整:当面板达到最小值时,自动从相邻面板获取空间
11
- - ✅ 拖拽器与面板完全解耦,灵活可扩展
7
+ ## 特性
8
+
9
+ - ✅ **双向布局**:支持水平和垂直方向的布局
10
+ - ✅ **拖拽调整**:可拖拽调整相邻面板的宽度/高度
11
+ - ✅ **最小尺寸**:支持设置面板最小尺寸限制
12
+ - ✅ **级联调整**:当面板达到最小值时,自动从相邻面板获取空间
12
13
  - ✅ **虚拟化拖拽**:支持虚拟节点模式,拖拽时创建虚拟框架,提升性能
13
- - ✅ TypeScript 支持
14
+ - ✅ **TypeScript**:完整的 TypeScript 类型支持
15
+ - ✅ **模块化架构**:清晰的目录结构,支持按需导入
16
+ - ✅ **Tree-shaking**:支持 Tree-shaking,减少打包体积
14
17
 
15
- ## 安装
18
+ ## 📦 安装
16
19
 
17
20
  ```bash
18
21
  npm install react-resize-demo
22
+ # 或
23
+ yarn add react-resize-demo
24
+ # 或
25
+ pnpm add react-resize-demo
19
26
  ```
20
27
 
21
- ## 使用
28
+ ## 🚀 快速开始
29
+
30
+ ### 基础用法
22
31
 
23
32
  ```tsx
24
- import { ResizeablePanelGroup, ResizeablePanel } from 'react-resize-demo';
33
+ import { ResizablePanelGroup, ResizablePanel } from 'react-resize-demo';
25
34
 
26
35
  function App() {
27
36
  return (
28
37
  <div style={{ width: '100%', height: '500px' }}>
29
- <ResizeablePanelGroup direction="horizontal">
30
- <ResizeablePanel minSize={100} onResize={(width) => console.log(width)}>
38
+ <ResizablePanelGroup direction="horizontal">
39
+ <ResizablePanel minSize={100}>
31
40
  <div>Panel 1</div>
32
- </ResizeablePanel>
33
- <ResizeablePanel minSize={200}>
41
+ </ResizablePanel>
42
+ <ResizablePanel minSize={200}>
34
43
  <div>Panel 2</div>
35
- </ResizeablePanel>
36
- <ResizeablePanel minSize={300}>
44
+ </ResizablePanel>
45
+ <ResizablePanel minSize={300}>
37
46
  <div>Panel 3</div>
38
- </ResizeablePanel>
39
- </ResizeablePanelGroup>
47
+ </ResizablePanel>
48
+ </ResizablePanelGroup>
40
49
  </div>
41
50
  );
42
51
  }
@@ -45,17 +54,17 @@ function App() {
45
54
  ### 垂直布局
46
55
 
47
56
  ```tsx
48
- <ResizeablePanelGroup direction="vertical" style={{ height: '500px' }}>
49
- <ResizeablePanel minSize={100}>
57
+ <ResizablePanelGroup direction="vertical" style={{ height: '500px' }}>
58
+ <ResizablePanel minSize={100}>
50
59
  <div>顶部面板</div>
51
- </ResizeablePanel>
52
- <ResizeablePanel minSize={200}>
60
+ </ResizablePanel>
61
+ <ResizablePanel minSize={200}>
53
62
  <div>中间面板</div>
54
- </ResizeablePanel>
55
- <ResizeablePanel minSize={100}>
63
+ </ResizablePanel>
64
+ <ResizablePanel minSize={100}>
56
65
  <div>底部面板</div>
57
- </ResizeablePanel>
58
- </ResizeablePanelGroup>
66
+ </ResizablePanel>
67
+ </ResizablePanelGroup>
59
68
  ```
60
69
 
61
70
  ### 虚拟化模式
@@ -64,17 +73,17 @@ function App() {
64
73
 
65
74
  ```tsx
66
75
  // 启用虚拟化(使用默认样式)
67
- <ResizeablePanelGroup virtual={true}>
68
- <ResizeablePanel minSize={100}>
76
+ <ResizablePanelGroup virtual={true}>
77
+ <ResizablePanel minSize={100}>
69
78
  <div>Panel 1</div>
70
- </ResizeablePanel>
71
- <ResizeablePanel minSize={200}>
79
+ </ResizablePanel>
80
+ <ResizablePanel minSize={200}>
72
81
  <div>Panel 2</div>
73
- </ResizeablePanel>
74
- </ResizeablePanelGroup>
82
+ </ResizablePanel>
83
+ </ResizablePanelGroup>
75
84
 
76
85
  // 启用虚拟化(自定义样式)
77
- <ResizeablePanelGroup
86
+ <ResizablePanelGroup
78
87
  virtual={true}
79
88
  virtualConfig={{
80
89
  style: {
@@ -85,20 +94,75 @@ function App() {
85
94
  className: 'custom-virtual-node'
86
95
  }}
87
96
  >
88
- <ResizeablePanel minSize={100}>
97
+ <ResizablePanel minSize={100}>
89
98
  <div>Panel 1</div>
90
- </ResizeablePanel>
91
- <ResizeablePanel minSize={200}>
99
+ </ResizablePanel>
100
+ <ResizablePanel minSize={200}>
92
101
  <div>Panel 2</div>
93
- </ResizeablePanel>
94
- </ResizeablePanelGroup>
102
+ </ResizablePanel>
103
+ </ResizablePanelGroup>
104
+ ```
105
+
106
+ ### 按需导入
107
+
108
+ 支持分层导入,实现更好的 Tree-shaking:
109
+
110
+ ```tsx
111
+ // 从主入口导入(推荐)
112
+ import { ResizablePanelGroup, ResizablePanel } from 'react-resize-demo';
113
+
114
+ // 按需导入组件
115
+ import { ResizablePanelGroup } from 'react-resize-demo/components/ResizePanelGroup';
116
+ import { ResizablePanel } from 'react-resize-demo/components/ResizePanel';
117
+
118
+ // 导入工具函数
119
+ import { ResizeAbleCore } from 'react-resize-demo/utils';
120
+
121
+ // 导入类型
122
+ import type { VirtualConfig, ResizeDirection } from 'react-resize-demo/types';
123
+ ```
124
+
125
+ ## 🎮 运行 Demo
126
+
127
+ 要查看和体验完整的 demo 示例(包括虚拟化模式、性能对比等),请从源码运行:
128
+
129
+ ### 步骤
130
+
131
+ 1. **Clone 源码仓库**
132
+
133
+ ```bash
134
+ git clone https://gitee.com/zugechen/react-resize-demo.git
135
+ cd react-resize-demo
95
136
  ```
96
137
 
97
- ## API
138
+ 2. **安装依赖**
98
139
 
99
- ### ResizeablePanelGroup
140
+ ```bash
141
+ npm install
142
+ # 或
143
+ pnpm install
144
+ ```
100
145
 
101
- 面板组容器组件,用于包裹多个 `ResizeablePanel`。
146
+ 3. **启动 Demo**
147
+
148
+ ```bash
149
+ npm run demo
150
+ ```
151
+
152
+ 这将启动一个开发服务器(默认端口 3000),你可以在浏览器中查看和测试所有功能示例。
153
+
154
+ ### Demo 包含的内容
155
+
156
+ - ✅ 基础用法示例(水平/垂直布局)
157
+ - ✅ 虚拟化模式演示
158
+ - ✅ 性能对比测试
159
+ - ✅ 复杂内容场景演示
160
+
161
+ ## 📖 API 文档
162
+
163
+ ### ResizablePanelGroup
164
+
165
+ 面板组容器组件,用于包裹多个 `ResizablePanel`。
102
166
 
103
167
  | 属性 | 类型 | 默认值 | 说明 |
104
168
  |------|------|--------|------|
@@ -106,6 +170,7 @@ function App() {
106
170
  | virtual | `boolean` | `false` | 是否启用虚拟化模式 |
107
171
  | virtualConfig | `VirtualConfig` | `{}` | 虚拟化配置(仅在 virtual=true 时生效) |
108
172
  | style | `React.CSSProperties` | - | 自定义样式 |
173
+ | children | `React.ReactNode` | - | 子元素(通常是多个 ResizablePanel) |
109
174
 
110
175
  #### VirtualConfig
111
176
 
@@ -117,7 +182,7 @@ function App() {
117
182
  | style | `React.CSSProperties` | - | 虚拟节点的自定义样式 |
118
183
  | className | `string` | - | 虚拟节点的自定义类名 |
119
184
 
120
- ### ResizeablePanel
185
+ ### ResizablePanel
121
186
 
122
187
  可调整大小的面板组件。
123
188
 
@@ -127,12 +192,65 @@ function App() {
127
192
  | onResize | `(width: number) => void` | - | 面板尺寸变化时的回调函数 |
128
193
  | children | `React.ReactNode` | - | 面板内容 |
129
194
 
130
- ## 开发
195
+ ### Context & Hooks
196
+
197
+ ```tsx
198
+ import { ResizableContext, useResizableContext } from 'react-resize-demo';
199
+
200
+ // 在组件内部使用
201
+ const {
202
+ panelCount,
203
+ registerPanel,
204
+ unregisterPanel,
205
+ getPanelInfo,
206
+ direction,
207
+ virtualConfig
208
+ } = useResizableContext();
209
+ ```
210
+
211
+ ## 🏗️ 项目结构
212
+
213
+ ```
214
+ react-resize-demo/
215
+ ├── src/ # 源代码目录
216
+ │ ├── components/ # 组件目录
217
+ │ │ ├── ResizePanelGroup/ # 容器组件
218
+ │ │ │ └── index.tsx
219
+ │ │ ├── ResizePanel/ # 面板组件
220
+ │ │ │ └── index.tsx
221
+ │ │ ├── ResizeHandle/ # 拖拽手柄组件
222
+ │ │ │ └── index.tsx
223
+ │ │ ├── shared/ # 共享资源
224
+ │ │ │ └── context.tsx # Context 定义
225
+ │ │ └── index.tsx # 组件统一导出
226
+ │ ├── utils/ # 工具函数
227
+ │ │ ├── resizeAble.ts # 拖拽调整核心类
228
+ │ │ ├── virtualNode.ts # 虚拟节点管理模块
229
+ │ │ └── index.ts # 工具函数导出
230
+ │ ├── types/ # 类型定义
231
+ │ │ └── index.ts # 所有类型定义
232
+ │ └── index.ts # 主入口文件
233
+ ├── demo/ # 本地测试Demo
234
+ │ ├── App.tsx # Demo应用
235
+ │ └── ...
236
+ ├── dist/ # 构建输出目录
237
+ │ ├── index.js # CJS 主入口
238
+ │ ├── esm/ # ESM 模块
239
+ │ ├── components/ # CJS 组件
240
+ │ ├── utils/ # CJS 工具
241
+ │ └── types/ # 类型定义
242
+ ├── rollup.config.mjs # Rollup构建配置
243
+ └── package.json # 项目配置
244
+ ```
245
+
246
+ ## 🔧 开发
131
247
 
132
248
  ### 安装依赖
133
249
 
134
250
  ```bash
135
251
  npm install
252
+ # 或
253
+ pnpm install
136
254
  ```
137
255
 
138
256
  ### 构建库
@@ -141,7 +259,7 @@ npm install
141
259
  npm run build
142
260
  ```
143
261
 
144
- ### 运行本地Demo
262
+ ### 运行 Demo(开发模式)
145
263
 
146
264
  ```bash
147
265
  npm run demo
@@ -149,13 +267,31 @@ npm run demo
149
267
 
150
268
  这将启动一个开发服务器,你可以在浏览器中查看和测试组件。
151
269
 
152
- ### 构建Demo
270
+ ### 构建 Demo(生产模式)
153
271
 
154
272
  ```bash
155
273
  npm run demo:build
156
274
  ```
157
275
 
158
- ## 工作原理
276
+ ### 类型检查
277
+
278
+ ```bash
279
+ npm run type-check
280
+ ```
281
+
282
+ ### 代码检查
283
+
284
+ ```bash
285
+ npm run lint
286
+ ```
287
+
288
+ ### 监听模式构建
289
+
290
+ ```bash
291
+ npm run build:watch
292
+ ```
293
+
294
+ ## 💡 工作原理
159
295
 
160
296
  组件通过拖拽器(ResizeHandle)来调整相邻面板的尺寸:
161
297
  - **向右拖拽**:扩大左侧面板,缩小右侧面板(如果右侧面板达到最小值,继续从后续面板获取空间)
@@ -175,83 +311,40 @@ npm run demo:build
175
311
  - 提供视觉反馈:虚拟节点可以有不同的样式(如半透明、虚线边框等)
176
312
  - 适用于复杂内容:当面板内容复杂时,虚拟化可以避免拖拽时的性能问题
177
313
 
178
- ## 项目结构
179
-
180
- ```
181
- react-resize-demo/
182
- ├── src/ # 源代码目录
183
- │ ├── components/ # 组件目录
184
- │ │ ├── ResizePanel/ # 可调整大小面板组件
185
- │ │ └── ExampleComponent/ # 示例组件
186
- │ ├── core/ # 核心逻辑
187
- │ │ ├── resizeAble.js # 拖拽调整核心类
188
- │ │ └── virtualNode.js # 虚拟节点管理模块
189
- │ ├── utils/ # 工具函数
190
- │ ├── types/ # 类型定义
191
- │ └── index.ts # 入口文件
192
- ├── demo/ # 本地测试Demo
193
- │ ├── App.tsx # Demo应用
194
- │ ├── main.tsx # Demo入口
195
- │ └── index.html # HTML模板
196
- ├── dist/ # 构建输出目录
197
- ├── rollup.config.mjs # Rollup构建配置
198
- ├── vite.config.ts # Vite库构建配置
199
- ├── vite.demo.config.ts # Vite Demo配置
200
- ├── CHANGELOG.md # 变更日志
201
- └── package.json # 项目配置
202
- ```
203
-
204
- ## 开发
205
-
206
- ### 安装依赖
207
-
208
- ```bash
209
- npm install
210
- ```
211
-
212
- ### 构建库
213
-
214
- ```bash
215
- npm run build
216
- ```
314
+ ## 🔄 迁移指南
217
315
 
218
- ### 运行本地Demo
219
-
220
- ```bash
221
- npm run demo
222
- ```
316
+ ### 从 1.x 升级到 2.0
223
317
 
224
- 这将启动一个开发服务器,你可以在浏览器中查看和测试组件。
318
+ 2.0 版本保持了向后兼容,现有代码无需修改即可使用:
225
319
 
226
- ### 构建Demo
320
+ ```tsx
321
+ // ✅ 仍然可用(向后兼容)
322
+ import { ResizeablePanelGroup, ResizeablePanel } from 'react-resize-demo';
227
323
 
228
- ```bash
229
- npm run demo:build
324
+ // ✅ 推荐使用新的正确拼写
325
+ import { ResizablePanelGroup, ResizablePanel } from 'react-resize-demo';
230
326
  ```
231
327
 
232
- ### 类型检查
233
-
234
- ```bash
235
- npm run type-check
236
- ```
328
+ ### 新功能
237
329
 
238
- ### 代码检查
330
+ 如果你想要使用新的分层导入功能:
239
331
 
240
- ```bash
241
- npm run lint
332
+ ```tsx
333
+ // 按需导入,更好的 Tree-shaking
334
+ import { ResizablePanelGroup } from 'react-resize-demo/components/ResizePanelGroup';
335
+ import { ResizablePanel } from 'react-resize-demo/components/ResizePanel';
242
336
  ```
243
337
 
244
- ## 版本历史
338
+ ## 📝 版本历史
245
339
 
246
340
  查看 [CHANGELOG.md](./CHANGELOG.md) 了解详细的版本变更历史。
247
341
 
248
- ## 发布到npm
342
+ ## 📄 License
249
343
 
250
- 1. 确保代码已构建:`npm run build`
251
- 2. 更新版本号:`npm version patch|minor|major`
252
- 3. 发布:`npm publish`
344
+ MIT
253
345
 
254
- ## License
346
+ ## 🤝 贡献
255
347
 
256
- MIT
348
+ 欢迎提交 Issue 和 Pull Request!
257
349
 
350
+ **源码仓库**: [https://gitee.com/zugechen/react-resize-demo](https://gitee.com/zugechen/react-resize-demo)
@@ -0,0 +1,92 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var React = require('react');
5
+ var resizeAble = require('../../utils/resizeAble.js');
6
+ var context = require('../shared/context.js');
7
+
8
+ const ResizeHandle = ({ prePanelIndex, nextPanelIndex, direction, }) => {
9
+ const handleRef = React.useRef(null);
10
+ const coreInstanceRef = React.useRef(null);
11
+ const { getPanelInfo, panelCount, virtualConfig } = context.useResizableContext();
12
+ React.useEffect(() => {
13
+ // 确保所需的面板索引都已注册
14
+ // 需要确保 nextPanelIndex 对应的面板已经注册(因为索引从0开始,所以需要 >= nextPanelIndex + 1)
15
+ if (panelCount <= nextPanelIndex || !handleRef.current) {
16
+ return;
17
+ }
18
+ const prePanelInfo = getPanelInfo(prePanelIndex);
19
+ const nextPanelInfo = getPanelInfo(nextPanelIndex);
20
+ if (!prePanelInfo || !nextPanelInfo)
21
+ return;
22
+ // 获取拖拽器的尺寸
23
+ const handleSize = handleRef.current
24
+ ? (direction === 'horizontal'
25
+ ? handleRef.current.offsetWidth
26
+ : handleRef.current.offsetHeight)
27
+ : (direction === 'horizontal' ? 10 : 10); // 默认10px
28
+ coreInstanceRef.current = new resizeAble.default({
29
+ prePanelEl: prePanelInfo.panelEl,
30
+ nextPanelEl: nextPanelInfo.panelEl,
31
+ getPanelInfo,
32
+ prePanelIndex,
33
+ nextPanelIndex,
34
+ direction,
35
+ virtualEnabled: virtualConfig.enabled || false,
36
+ virtualConfig: {
37
+ style: virtualConfig.style,
38
+ className: virtualConfig.className,
39
+ },
40
+ handleSize, // 传递拖拽器尺寸
41
+ });
42
+ // 将拖拽器的开始/移动/结束事件绑定至核心类
43
+ const handleEl = handleRef.current;
44
+ let isResizing = false;
45
+ let startPos = 0;
46
+ const startResize = (e) => {
47
+ e.preventDefault();
48
+ isResizing = true;
49
+ startPos = direction === 'horizontal' ? e.clientX : e.clientY;
50
+ if (coreInstanceRef.current) {
51
+ coreInstanceRef.current.startResize();
52
+ }
53
+ };
54
+ const onResizeMove = (e) => {
55
+ if (!isResizing || !coreInstanceRef.current)
56
+ return;
57
+ const currentPos = direction === 'horizontal' ? e.clientX : e.clientY;
58
+ const delta = currentPos - startPos;
59
+ coreInstanceRef.current.onResize(delta);
60
+ };
61
+ const endResize = () => {
62
+ if (isResizing && coreInstanceRef.current) {
63
+ isResizing = false;
64
+ coreInstanceRef.current.endResize();
65
+ }
66
+ };
67
+ handleEl.addEventListener('mousedown', startResize);
68
+ document.addEventListener('mousemove', onResizeMove);
69
+ document.addEventListener('mouseup', endResize);
70
+ return () => {
71
+ handleEl.removeEventListener('mousedown', startResize);
72
+ document.removeEventListener('mousemove', onResizeMove);
73
+ document.removeEventListener('mouseup', endResize);
74
+ if (coreInstanceRef.current) {
75
+ coreInstanceRef.current.destroy();
76
+ }
77
+ };
78
+ }, [prePanelIndex, nextPanelIndex, direction, getPanelInfo, panelCount, virtualConfig]);
79
+ const isHorizontal = direction === 'horizontal';
80
+ return (jsxRuntime.jsx("div", { ref: handleRef, style: {
81
+ position: 'relative',
82
+ width: isHorizontal ? '10px' : '100%',
83
+ height: isHorizontal ? '100%' : '10px',
84
+ backgroundColor: '#000',
85
+ cursor: isHorizontal ? 'ew-resize' : 'ns-resize',
86
+ zIndex: 1000,
87
+ flexShrink: 0,
88
+ } }));
89
+ };
90
+
91
+ exports.ResizeHandle = ResizeHandle;
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sources":["../../../src/components/ResizeHandle/index.tsx"],"sourcesContent":["/**\r\n * 拖拽手柄组件\r\n * 负责处理面板之间的拖拽调整功能\r\n */\r\nimport React, { useRef, useEffect } from 'react';\r\nimport ResizeAbleCore from '../../utils/resizeAble';\r\nimport { useResizableContext } from '../shared/context';\r\nimport { ResizeDirection } from '../../types';\r\n\r\nexport interface ResizeHandleProps {\r\n prePanelIndex: number;\r\n nextPanelIndex: number;\r\n direction: ResizeDirection;\r\n}\r\n\r\nexport const ResizeHandle: React.FC<ResizeHandleProps> = ({\r\n prePanelIndex,\r\n nextPanelIndex,\r\n direction,\r\n}) => {\r\n const handleRef = useRef<HTMLDivElement>(null);\r\n const coreInstanceRef = useRef<InstanceType<typeof ResizeAbleCore> | null>(null);\r\n const { getPanelInfo, panelCount, virtualConfig } = useResizableContext();\r\n\r\n useEffect(() => {\r\n // 确保所需的面板索引都已注册\r\n // 需要确保 nextPanelIndex 对应的面板已经注册(因为索引从0开始,所以需要 >= nextPanelIndex + 1)\r\n if (panelCount <= nextPanelIndex || !handleRef.current) {\r\n return;\r\n }\r\n \r\n const prePanelInfo = getPanelInfo(prePanelIndex);\r\n const nextPanelInfo = getPanelInfo(nextPanelIndex);\r\n if(!prePanelInfo || !nextPanelInfo) return;\r\n \r\n // 获取拖拽器的尺寸\r\n const handleSize = handleRef.current \r\n ? (direction === 'horizontal' \r\n ? handleRef.current.offsetWidth \r\n : handleRef.current.offsetHeight)\r\n : (direction === 'horizontal' ? 10 : 10); // 默认10px\r\n \r\n coreInstanceRef.current = new ResizeAbleCore({\r\n prePanelEl: prePanelInfo.panelEl,\r\n nextPanelEl: nextPanelInfo.panelEl,\r\n getPanelInfo,\r\n prePanelIndex,\r\n nextPanelIndex,\r\n direction,\r\n virtualEnabled: virtualConfig.enabled || false,\r\n virtualConfig: {\r\n style: virtualConfig.style,\r\n className: virtualConfig.className,\r\n },\r\n handleSize, // 传递拖拽器尺寸\r\n });\r\n\r\n // 将拖拽器的开始/移动/结束事件绑定至核心类\r\n const handleEl = handleRef.current;\r\n let isResizing = false;\r\n let startPos = 0;\r\n\r\n const startResize = (e: MouseEvent) => {\r\n e.preventDefault();\r\n isResizing = true;\r\n startPos = direction === 'horizontal' ? e.clientX : e.clientY;\r\n if (coreInstanceRef.current) {\r\n coreInstanceRef.current.startResize();\r\n }\r\n };\r\n \r\n const onResizeMove = (e: MouseEvent) => {\r\n if(!isResizing || !coreInstanceRef.current) return;\r\n const currentPos = direction === 'horizontal' ? e.clientX : e.clientY;\r\n const delta = currentPos - startPos;\r\n coreInstanceRef.current.onResize(delta);\r\n };\r\n \r\n const endResize = () => {\r\n if(isResizing && coreInstanceRef.current) {\r\n isResizing = false;\r\n coreInstanceRef.current.endResize();\r\n }\r\n }\r\n \r\n handleEl.addEventListener('mousedown', startResize);\r\n document.addEventListener('mousemove', onResizeMove);\r\n document.addEventListener('mouseup', endResize);\r\n \r\n return () => {\r\n handleEl.removeEventListener('mousedown', startResize);\r\n document.removeEventListener('mousemove', onResizeMove);\r\n document.removeEventListener('mouseup', endResize);\r\n if(coreInstanceRef.current) {\r\n coreInstanceRef.current.destroy();\r\n }\r\n }\r\n }, [prePanelIndex, nextPanelIndex, direction, getPanelInfo, panelCount, virtualConfig]);\r\n\r\n const isHorizontal = direction === 'horizontal';\r\n return (\r\n <div\r\n ref={handleRef}\r\n style={{\r\n position: 'relative',\r\n width: isHorizontal ? '10px' : '100%',\r\n height: isHorizontal ? '100%' : '10px',\r\n backgroundColor: '#000',\r\n cursor: isHorizontal ? 'ew-resize' : 'ns-resize',\r\n zIndex: 1000,\r\n flexShrink: 0,\r\n }}\r\n />\r\n )\r\n};\r\n\r\n"],"names":["useRef","useResizableContext","useEffect","ResizeAbleCore","_jsx"],"mappings":"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"}
@@ -0,0 +1,33 @@
1
+ 'use strict';
2
+
3
+ var jsxRuntime = require('react/jsx-runtime');
4
+ var React = require('react');
5
+ var context = require('../shared/context.js');
6
+
7
+ const ResizePanel = ({ children, minSize = 100,
8
+ // onResize, // 暂时未使用,保留以备将来使用
9
+ }) => {
10
+ const panelRef = React.useRef(null);
11
+ const panelIndexRef = React.useRef(-1);
12
+ const { registerPanel, unregisterPanel, direction } = context.useResizableContext();
13
+ React.useEffect(() => {
14
+ if (!panelRef.current)
15
+ return;
16
+ const panelEl = panelRef.current;
17
+ panelIndexRef.current = registerPanel(panelEl, minSize);
18
+ return () => {
19
+ unregisterPanel(panelEl);
20
+ };
21
+ }, [minSize, registerPanel, unregisterPanel]);
22
+ return (jsxRuntime.jsx("div", { ref: panelRef, style: {
23
+ flex: 1,
24
+ minWidth: direction === 'horizontal' ? minSize : undefined,
25
+ minHeight: direction === 'vertical' ? minSize : undefined,
26
+ width: 'auto',
27
+ overflow: 'hidden',
28
+ position: 'relative',
29
+ }, children: jsxRuntime.jsx("div", { style: { height: '100%', padding: 16 }, children: children }) }));
30
+ };
31
+
32
+ exports.ResizePanel = ResizePanel;
33
+ //# sourceMappingURL=index.js.map