vane-waterfall 1.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.
- package/README.md +370 -0
- package/dist/404.jpg +0 -0
- package/dist/components/WaterfallPlugin/core/WaterfallCore.d.ts +174 -0
- package/dist/components/WaterfallPlugin/custom-plugins/A11y/index.d.ts +16 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Alignment/index.d.ts +12 -0
- package/dist/components/WaterfallPlugin/custom-plugins/AutoColumn/index.d.ts +17 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Bookmark/index.d.ts +15 -0
- package/dist/components/WaterfallPlugin/custom-plugins/ClickAnalytics/index.d.ts +12 -0
- package/dist/components/WaterfallPlugin/custom-plugins/DebounceLayout/index.d.ts +10 -0
- package/dist/components/WaterfallPlugin/custom-plugins/DragReorder/index.d.ts +13 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Filter/index.d.ts +15 -0
- package/dist/components/WaterfallPlugin/custom-plugins/FixedHeight/index.d.ts +11 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Gap/index.d.ts +31 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Grouping/index.d.ts +12 -0
- package/dist/components/WaterfallPlugin/custom-plugins/HeatmapAnalytics/index.d.ts +14 -0
- package/dist/components/WaterfallPlugin/custom-plugins/InfiniteScroll/index.d.ts +13 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Pagination/index.d.ts +15 -0
- package/dist/components/WaterfallPlugin/custom-plugins/PinItem/index.d.ts +13 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Recycle/index.d.ts +12 -0
- package/dist/components/WaterfallPlugin/custom-plugins/ReducedMotion/index.d.ts +13 -0
- package/dist/components/WaterfallPlugin/custom-plugins/ResponsiveColumns/index.d.ts +10 -0
- package/dist/components/WaterfallPlugin/custom-plugins/ScrollAnchor/index.d.ts +12 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Search/index.d.ts +15 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Sort/index.d.ts +15 -0
- package/dist/components/WaterfallPlugin/custom-plugins/StatePersistence/index.d.ts +16 -0
- package/dist/components/WaterfallPlugin/custom-plugins/StickyHeader/index.d.ts +11 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Throttle/index.d.ts +12 -0
- package/dist/components/WaterfallPlugin/custom-plugins/Transition/index.d.ts +13 -0
- package/dist/components/WaterfallPlugin/custom-plugins/URLSync/index.d.ts +14 -0
- package/dist/components/WaterfallPlugin/custom-plugins/VirtualWaterfall/index.d.ts +12 -0
- package/dist/components/WaterfallPlugin/custom-plugins/index.d.ts +30 -0
- package/dist/components/WaterfallPlugin/index.d.ts +10 -0
- package/dist/components/WaterfallPlugin/plugins/PluginBus.d.ts +2 -0
- package/dist/components/WaterfallPlugin/plugins/PluginManager.d.ts +2 -0
- package/dist/components/WaterfallPlugin/plugins/index.d.ts +8 -0
- package/dist/components/WaterfallPlugin/plugins/types.d.ts +468 -0
- package/dist/components/WaterfallPlugin/plugins/withPlugins.d.ts +8 -0
- package/dist/index.d.ts +11 -0
- package/dist/index.es.js +2382 -0
- package/dist/index.umd.js +30 -0
- package/dist/vite.svg +1 -0
- package/package.json +82 -0
package/README.md
ADDED
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
# 🧱 Vane Waterfall
|
|
2
|
+
|
|
3
|
+
一个功能强大、高度可扩展的 React 瀑布流布局插件式组件库(WaterfallPlugin)
|
|
4
|
+
|
|
5
|
+
[](./LICENSE)
|
|
6
|
+
[](https://www.typescriptlang.org/)
|
|
7
|
+
[](https://reactjs.org/)
|
|
8
|
+
|
|
9
|
+
[在线演示](https://chinavane.netlify.app/) | [快速开始](#快速开始) | [插件列表](#插件列表) | [API 文档](#api-文档)
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## ✨ 核心特性
|
|
14
|
+
|
|
15
|
+
### 🔌 插件化架构
|
|
16
|
+
|
|
17
|
+
- 基于事件总线的插件系统,支持灵活组合
|
|
18
|
+
- 60+ 内置插件,覆盖各种使用场景
|
|
19
|
+
- 易于扩展,支持自定义插件开发(如 `calculateItemPosition` 覆盖布局)
|
|
20
|
+
|
|
21
|
+
### 🧱 布局与渲染
|
|
22
|
+
|
|
23
|
+
- 多种列分配策略:最矮列、平均列、固定列数、响应式列数
|
|
24
|
+
- 支持列间距 `gap` 与容器内边距 `padding`,保证两侧留白参与布局计算
|
|
25
|
+
- 过渡动画、固定高度、虚拟化渲染、工作线程布局等
|
|
26
|
+
|
|
27
|
+
### ⚡ 性能优化
|
|
28
|
+
|
|
29
|
+
- 布局防抖/节流
|
|
30
|
+
- 复用与回收(Recycle)
|
|
31
|
+
- 虚拟化(VirtualWaterfall)
|
|
32
|
+
|
|
33
|
+
### 🛡️ 稳健性
|
|
34
|
+
|
|
35
|
+
- 书签定位、滚动锚点、粘性头部
|
|
36
|
+
- 状态持久化与 URL 同步
|
|
37
|
+
|
|
38
|
+
### ♿ 可访问性与易用性
|
|
39
|
+
|
|
40
|
+
- A11y 增强、简洁 API、完善的示例
|
|
41
|
+
|
|
42
|
+
### 📊 监控与分析
|
|
43
|
+
|
|
44
|
+
- 热力图/交互分析、滚动性能采集(示例插件)
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## 📦 安装
|
|
49
|
+
|
|
50
|
+
### NPM / Yarn / PNPM(作为工程示例运行)
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
# 安装依赖
|
|
54
|
+
npm install
|
|
55
|
+
|
|
56
|
+
# 启动开发服务器
|
|
57
|
+
npm run dev
|
|
58
|
+
|
|
59
|
+
# 构建生产版本
|
|
60
|
+
npm run build
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
### 本地开发
|
|
64
|
+
|
|
65
|
+
启动后访问:`http://localhost:3000`。
|
|
66
|
+
|
|
67
|
+
---
|
|
68
|
+
|
|
69
|
+
## 📊 包大小与优化
|
|
70
|
+
|
|
71
|
+
### 模块大小(示意)
|
|
72
|
+
|
|
73
|
+
| 模块 | 原始大小 | Gzip 后 | 说明 |
|
|
74
|
+
| ---------- | -------- | ------- | ----------------------------------- |
|
|
75
|
+
| 核心组件 | ~10 KB | ~3 KB | `WaterfallCore` 仅包含基础布局逻辑 |
|
|
76
|
+
| 插件系统 | ~12 KB | ~4 KB | 插件管理器 + 事件总线 |
|
|
77
|
+
| 单个插件 | ~2-5 KB | ~1-2 KB | 每个插件平均大小 |
|
|
78
|
+
| 完整插件组 | ~80+ KB | ~25 KB | 包含常用插件的组合示例 |
|
|
79
|
+
|
|
80
|
+
> 💡 提示:使用按需导入与插件精简组合,可显著降低打包体积。
|
|
81
|
+
|
|
82
|
+
### Tree-Shaking 支持
|
|
83
|
+
|
|
84
|
+
本库完全支持 **Tree-Shaking**,未使用的插件不会被打包到最终产物中。
|
|
85
|
+
|
|
86
|
+
#### 为什么支持 Tree-Shaking?
|
|
87
|
+
|
|
88
|
+
1. ESM 模块发布,便于静态分析
|
|
89
|
+
2. 无副作用标记:`"sideEffects": false`
|
|
90
|
+
3. 命名导出,便于按需引用
|
|
91
|
+
4. 插件均为独立模块,可单独引入
|
|
92
|
+
|
|
93
|
+
```json
|
|
94
|
+
{
|
|
95
|
+
"sideEffects": false,
|
|
96
|
+
"module": "dist/index.es.js",
|
|
97
|
+
"exports": {
|
|
98
|
+
".": {
|
|
99
|
+
"import": "./dist/index.es.js",
|
|
100
|
+
"types": "./dist/index.d.ts"
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
#### ✅ 支持 Tree-Shaking 的导入方式
|
|
107
|
+
|
|
108
|
+
```tsx
|
|
109
|
+
import {
|
|
110
|
+
WaterfallCore,
|
|
111
|
+
withPlugins,
|
|
112
|
+
createAlignmentPlugin,
|
|
113
|
+
createTransitionPlugin,
|
|
114
|
+
} from "@/components/WaterfallPlugin";
|
|
115
|
+
|
|
116
|
+
const Waterfall = withPlugins(WaterfallCore, [
|
|
117
|
+
createAlignmentPlugin({ mode: "shortest" }),
|
|
118
|
+
createTransitionPlugin({ duration: 180 }),
|
|
119
|
+
]);
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
#### ⚠️ 不推荐的导入方式
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
// ❌ 不推荐:一次性导入所有插件(会失去 Tree-Shaking 优势)
|
|
126
|
+
import * as Waterfall from "@/components/WaterfallPlugin";
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
### 按需导入示例
|
|
130
|
+
|
|
131
|
+
#### 方式一:精确导入(最小体积)
|
|
132
|
+
|
|
133
|
+
```tsx
|
|
134
|
+
import { WaterfallCore } from "@/components/WaterfallPlugin";
|
|
135
|
+
import { withPlugins } from "@/components/WaterfallPlugin";
|
|
136
|
+
import { createAlignmentPlugin } from "@/components/WaterfallPlugin/custom-plugins/Alignment";
|
|
137
|
+
import { createTransitionPlugin } from "@/components/WaterfallPlugin/custom-plugins/Transition";
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
#### 方式二:分类导入(推荐)
|
|
141
|
+
|
|
142
|
+
```tsx
|
|
143
|
+
import {
|
|
144
|
+
WaterfallCore,
|
|
145
|
+
withPlugins,
|
|
146
|
+
createAutoColumnPlugin,
|
|
147
|
+
createResponsiveColumnsPlugin,
|
|
148
|
+
} from "@/components/WaterfallPlugin";
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### 方式三:分组导入
|
|
152
|
+
|
|
153
|
+
```tsx
|
|
154
|
+
import {
|
|
155
|
+
createAlignmentPlugin,
|
|
156
|
+
createFixedHeightPlugin,
|
|
157
|
+
createGapPlugin,
|
|
158
|
+
} from "@/components/WaterfallPlugin";
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
### 不同场景的包大小对比(示意)
|
|
162
|
+
|
|
163
|
+
| 使用场景 | 导入插件数 | 预估大小(Gzip) |
|
|
164
|
+
| -------------- | ---------- | ---------------- |
|
|
165
|
+
| 最小化(仅核心) | 0 | ~3 KB |
|
|
166
|
+
| 基础使用 | 2-3 个 | ~8-12 KB |
|
|
167
|
+
| 常规项目 | 5-8 个 | ~15-25 KB |
|
|
168
|
+
| 功能丰富 | 10-15 个 | ~30-45 KB |
|
|
169
|
+
|
|
170
|
+
### 打包优化建议
|
|
171
|
+
|
|
172
|
+
#### 1. 使用动态导入
|
|
173
|
+
|
|
174
|
+
```tsx
|
|
175
|
+
const Waterfall = withPlugins(WaterfallCore, [createTransitionPlugin()]);
|
|
176
|
+
|
|
177
|
+
async function loadAdvancedPlugins() {
|
|
178
|
+
const { createVirtualWaterfallPlugin } = await import(
|
|
179
|
+
"@/components/WaterfallPlugin/custom-plugins/VirtualWaterfall"
|
|
180
|
+
);
|
|
181
|
+
return [createVirtualWaterfallPlugin()];
|
|
182
|
+
}
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
#### 2. Vite 配置优化
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
// vite.config.ts(示例)
|
|
189
|
+
export default {
|
|
190
|
+
build: {
|
|
191
|
+
rollupOptions: {
|
|
192
|
+
output: {
|
|
193
|
+
manualChunks: {
|
|
194
|
+
waterfall: ["@/components/WaterfallPlugin"],
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
};
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
#### 3. Webpack 配置优化
|
|
203
|
+
|
|
204
|
+
```js
|
|
205
|
+
module.exports = {
|
|
206
|
+
optimization: {
|
|
207
|
+
usedExports: true,
|
|
208
|
+
sideEffects: false,
|
|
209
|
+
splitChunks: {
|
|
210
|
+
cacheGroups: {
|
|
211
|
+
waterfall: {
|
|
212
|
+
test: /WaterfallPlugin/,
|
|
213
|
+
name: "waterfall",
|
|
214
|
+
chunks: "all",
|
|
215
|
+
},
|
|
216
|
+
},
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
### 验证 Tree-Shaking 效果
|
|
223
|
+
|
|
224
|
+
同样可通过打包分析工具或比较测试文件大小的方式进行验证。
|
|
225
|
+
|
|
226
|
+
### 性能监控
|
|
227
|
+
|
|
228
|
+
可通过示例插件采集滚动与布局时序,或在页面中注入简单统计逻辑。
|
|
229
|
+
|
|
230
|
+
---
|
|
231
|
+
|
|
232
|
+
## 🚀 快速开始
|
|
233
|
+
|
|
234
|
+
### 基础使用
|
|
235
|
+
|
|
236
|
+
```tsx
|
|
237
|
+
import { WaterfallCore } from "@/components/WaterfallPlugin";
|
|
238
|
+
|
|
239
|
+
<WaterfallCore
|
|
240
|
+
items={items}
|
|
241
|
+
columns={4}
|
|
242
|
+
gap={12}
|
|
243
|
+
padding={12}
|
|
244
|
+
renderItem={(item) => <div style={{ height: item.height }} />}
|
|
245
|
+
/>;
|
|
246
|
+
```
|
|
247
|
+
|
|
248
|
+
### 使用插件
|
|
249
|
+
|
|
250
|
+
```tsx
|
|
251
|
+
import {
|
|
252
|
+
withPlugins,
|
|
253
|
+
createAlignmentPlugin,
|
|
254
|
+
createAutoColumnPlugin,
|
|
255
|
+
createResponsiveColumnsPlugin,
|
|
256
|
+
createTransitionPlugin,
|
|
257
|
+
} from "@/components/WaterfallPlugin";
|
|
258
|
+
|
|
259
|
+
const Waterfall = withPlugins(WaterfallCore, [
|
|
260
|
+
createAutoColumnPlugin({ minColumnWidth: 220 }),
|
|
261
|
+
createResponsiveColumnsPlugin({
|
|
262
|
+
breakpoints: {
|
|
263
|
+
xs: { width: 0, columns: 1 },
|
|
264
|
+
sm: { width: 640, columns: 2 },
|
|
265
|
+
md: { width: 768, columns: 3 },
|
|
266
|
+
lg: { width: 1024, columns: 4 },
|
|
267
|
+
xl: { width: 1280, columns: 5 },
|
|
268
|
+
},
|
|
269
|
+
}),
|
|
270
|
+
createAlignmentPlugin({ mode: "shortest" }),
|
|
271
|
+
createTransitionPlugin({ duration: 180, easing: "ease-out" }),
|
|
272
|
+
]);
|
|
273
|
+
```
|
|
274
|
+
|
|
275
|
+
### 组合示例:性能优化
|
|
276
|
+
|
|
277
|
+
```tsx
|
|
278
|
+
const WaterfallPerf = withPlugins(WaterfallCore, [
|
|
279
|
+
createTransitionPlugin({ duration: 150 }),
|
|
280
|
+
]);
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
---
|
|
284
|
+
|
|
285
|
+
## 📚 插件列表
|
|
286
|
+
|
|
287
|
+
本项目提供多个开箱即用的插件,按功能分类如下:
|
|
288
|
+
|
|
289
|
+
### 🎨 布局与效果
|
|
290
|
+
|
|
291
|
+
`Alignment`、`AutoColumn`、`ResponsiveColumns`、`FixedHeight`、`Gap`、`Transition`
|
|
292
|
+
|
|
293
|
+
### ⚡ 性能与渲染
|
|
294
|
+
|
|
295
|
+
`DebounceLayout`、`Recycle`、`VirtualWaterfall`、`WorkerLayout`、`Throttle`
|
|
296
|
+
|
|
297
|
+
### 🛡️ 稳健性与交互
|
|
298
|
+
|
|
299
|
+
`Bookmark`、`DragReorder`、`Grouping`、`ScrollAnchor`、`StickyHeader`
|
|
300
|
+
|
|
301
|
+
### 🔧 其他
|
|
302
|
+
|
|
303
|
+
`StatePersistence`、`PinItem`、`HeatmapAnalytics`、`A11y`
|
|
304
|
+
|
|
305
|
+
> 💡 提示:所有插件位于 `src/components/WaterfallPlugin/custom-plugins/` 目录,可直接查看实现与示例。
|
|
306
|
+
|
|
307
|
+
---
|
|
308
|
+
|
|
309
|
+
## 📂 项目结构
|
|
310
|
+
|
|
311
|
+
```
|
|
312
|
+
vane-waterfall/
|
|
313
|
+
├── src/
|
|
314
|
+
│ ├── components/
|
|
315
|
+
│ │ └── WaterfallPlugin/
|
|
316
|
+
│ │ ├── core/
|
|
317
|
+
│ │ │ └── WaterfallCore.tsx
|
|
318
|
+
│ │ ├── plugins/
|
|
319
|
+
│ │ │ ├── types.ts
|
|
320
|
+
│ │ │ ├── PluginBus.ts
|
|
321
|
+
│ │ │ ├── PluginManager.ts
|
|
322
|
+
│ │ │ └── withPlugins.tsx
|
|
323
|
+
│ │ ├── custom-plugins/
|
|
324
|
+
│ │ │ ├── Alignment/
|
|
325
|
+
│ │ │ ├── AutoColumn/
|
|
326
|
+
│ │ │ ├── InfiniteScroll/
|
|
327
|
+
│ │ │ └── ...
|
|
328
|
+
│ │ └── README.md
|
|
329
|
+
│ └── pages/
|
|
330
|
+
│ └── WaterfallPlugin/
|
|
331
|
+
│ └── LazyImageIntegrationDemo.tsx
|
|
332
|
+
└── README.md
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
---
|
|
336
|
+
|
|
337
|
+
## 🎯 API 文档
|
|
338
|
+
|
|
339
|
+
### 核心组件:`WaterfallCore`
|
|
340
|
+
|
|
341
|
+
#### Props(节选)
|
|
342
|
+
|
|
343
|
+
| 属性 | 类型 | 说明 |
|
|
344
|
+
| --------------- | ------------------- | --------------------------------- |
|
|
345
|
+
| `items` | `any[]` | 数据集合(含高度或可测量高度) |
|
|
346
|
+
| `renderItem` | `(item,i)=>ReactNode` | 渲染函数 |
|
|
347
|
+
| `columns` | `number` | 列数(可被插件覆盖) |
|
|
348
|
+
| `gap` | `number` | 列间距 |
|
|
349
|
+
| `padding` | `number` | 容器内边距(参与布局计算) |
|
|
350
|
+
| `alignmentMode` | `"shortest" | ...` | 列分配策略 |
|
|
351
|
+
| `onReachBottom` | `()=>void` | 触底回调 |
|
|
352
|
+
|
|
353
|
+
### 插件钩子(节选)
|
|
354
|
+
|
|
355
|
+
- `beforeLayout`、`afterLayout`
|
|
356
|
+
- `calculateItemPosition(item, index)`:返回值可覆盖默认位置
|
|
357
|
+
|
|
358
|
+
---
|
|
359
|
+
|
|
360
|
+
## 🛠️ 开发建议
|
|
361
|
+
|
|
362
|
+
- 优先使用 `padding` 控制容器留白,避免仅用 `containerStyle.padding`
|
|
363
|
+
- 通过插件扩展行为,保持核心组件简洁稳定
|
|
364
|
+
- 大型场景建议结合虚拟化与工作线程布局
|
|
365
|
+
|
|
366
|
+
---
|
|
367
|
+
|
|
368
|
+
## 📜 版权许可
|
|
369
|
+
|
|
370
|
+
本项目以 MIT 许可发布。
|
package/dist/404.jpg
ADDED
|
Binary file
|
|
@@ -0,0 +1,174 @@
|
|
|
1
|
+
import { ItemKeyExtractor, ItemPosition, LayoutInfo, ViewportInfo } from '../plugins/types';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
export interface WaterfallCoreProps<T = any> {
|
|
4
|
+
/**
|
|
5
|
+
* 数据源
|
|
6
|
+
*/
|
|
7
|
+
items: T[];
|
|
8
|
+
/**
|
|
9
|
+
* 渲染函数
|
|
10
|
+
*/
|
|
11
|
+
renderItem: (item: T, index: number) => React.ReactNode;
|
|
12
|
+
/**
|
|
13
|
+
* 键提取函数(用于 React key)
|
|
14
|
+
*/
|
|
15
|
+
keyExtractor?: ItemKeyExtractor<T>;
|
|
16
|
+
/**
|
|
17
|
+
* 列数(可由插件动态计算)
|
|
18
|
+
*/
|
|
19
|
+
columns?: number;
|
|
20
|
+
/**
|
|
21
|
+
* 列间距
|
|
22
|
+
*/
|
|
23
|
+
gap?: number;
|
|
24
|
+
/**
|
|
25
|
+
* 行间距(可选,默认等于 gap)
|
|
26
|
+
*/
|
|
27
|
+
rowGap?: number;
|
|
28
|
+
/**
|
|
29
|
+
* 列间距(可选,默认等于 gap)
|
|
30
|
+
*/
|
|
31
|
+
columnGap?: number;
|
|
32
|
+
/**
|
|
33
|
+
* 列分配策略(默认 shortest)
|
|
34
|
+
* - shortest:将下一项放入当前最矮列(默认)
|
|
35
|
+
* - sequential:按顺序轮转分配列(0,1,2...)
|
|
36
|
+
* - balanced:尽量使各列项数均衡(按项数最少列放置)
|
|
37
|
+
*/
|
|
38
|
+
alignmentMode?: "shortest" | "balanced" | "sequential";
|
|
39
|
+
/**
|
|
40
|
+
* 容器内边距
|
|
41
|
+
*/
|
|
42
|
+
padding?: number | {
|
|
43
|
+
top?: number;
|
|
44
|
+
right?: number;
|
|
45
|
+
bottom?: number;
|
|
46
|
+
left?: number;
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* 容器样式
|
|
50
|
+
*/
|
|
51
|
+
containerStyle?: React.CSSProperties;
|
|
52
|
+
/**
|
|
53
|
+
* 容器类名
|
|
54
|
+
*/
|
|
55
|
+
containerClassName?: string;
|
|
56
|
+
/**
|
|
57
|
+
* 项容器样式
|
|
58
|
+
*/
|
|
59
|
+
itemStyle?: React.CSSProperties;
|
|
60
|
+
/**
|
|
61
|
+
* 项容器类名
|
|
62
|
+
*/
|
|
63
|
+
itemClassName?: string;
|
|
64
|
+
/**
|
|
65
|
+
* 是否使用 transform 定位(性能更好)
|
|
66
|
+
*/
|
|
67
|
+
useTransform?: boolean;
|
|
68
|
+
/**
|
|
69
|
+
* 节流延迟(ms)
|
|
70
|
+
*/
|
|
71
|
+
throttleDelay?: number;
|
|
72
|
+
/**
|
|
73
|
+
* 防抖延迟(ms)
|
|
74
|
+
*/
|
|
75
|
+
debounceDelay?: number;
|
|
76
|
+
onMount?: () => void;
|
|
77
|
+
onUnmount?: () => void;
|
|
78
|
+
onBeforeLayout?: () => boolean | Promise<boolean>;
|
|
79
|
+
onLayout?: () => void;
|
|
80
|
+
onLayoutComplete?: () => void;
|
|
81
|
+
onItemMount?: (index: number, element: HTMLElement) => void;
|
|
82
|
+
onItemUnmount?: (index: number) => void;
|
|
83
|
+
onItemEnterViewport?: (index: number) => void;
|
|
84
|
+
onItemLeaveViewport?: (index: number) => void;
|
|
85
|
+
onScroll?: (scrollTop: number, scrollLeft: number) => void;
|
|
86
|
+
onResize?: (width: number, height: number) => void;
|
|
87
|
+
onReachBottom?: (distance: number) => void;
|
|
88
|
+
onItemClick?: (index: number, item: T, event: React.MouseEvent) => void;
|
|
89
|
+
/**
|
|
90
|
+
* 子元素(用于插件渲染覆盖层等)
|
|
91
|
+
*/
|
|
92
|
+
children?: React.ReactNode;
|
|
93
|
+
/**
|
|
94
|
+
* 外部容器引用(供 HOC 传入)
|
|
95
|
+
*/
|
|
96
|
+
containerRefExternal?: React.RefObject<HTMLDivElement | null>;
|
|
97
|
+
/**
|
|
98
|
+
* 外部项引用映射(供 HOC 传入)
|
|
99
|
+
*/
|
|
100
|
+
itemRefsExternal?: React.MutableRefObject<Map<number, HTMLElement>>;
|
|
101
|
+
/**
|
|
102
|
+
* 是否启用调试模式
|
|
103
|
+
*/
|
|
104
|
+
debug?: boolean;
|
|
105
|
+
}
|
|
106
|
+
export interface WaterfallCoreRef {
|
|
107
|
+
/**
|
|
108
|
+
* 重新布局
|
|
109
|
+
*/
|
|
110
|
+
relayout: () => void;
|
|
111
|
+
/**
|
|
112
|
+
* 滚动到指定项
|
|
113
|
+
*/
|
|
114
|
+
scrollToItem: (index: number, options?: ScrollToItemOptions) => void;
|
|
115
|
+
/**
|
|
116
|
+
* 滚动到顶部
|
|
117
|
+
*/
|
|
118
|
+
scrollToTop: (options?: ScrollToOptions) => void;
|
|
119
|
+
/**
|
|
120
|
+
* 滚动到底部
|
|
121
|
+
*/
|
|
122
|
+
scrollToBottom: (options?: ScrollToOptions) => void;
|
|
123
|
+
/**
|
|
124
|
+
* 获取项位置
|
|
125
|
+
*/
|
|
126
|
+
getItemPosition: (index: number) => ItemPosition | null;
|
|
127
|
+
/**
|
|
128
|
+
* 获取所有项位置
|
|
129
|
+
*/
|
|
130
|
+
getAllItemPositions: () => Map<number, ItemPosition>;
|
|
131
|
+
/**
|
|
132
|
+
* 获取列高度
|
|
133
|
+
*/
|
|
134
|
+
getColumnHeights: () => number[];
|
|
135
|
+
/**
|
|
136
|
+
* 获取布局信息
|
|
137
|
+
*/
|
|
138
|
+
getLayoutInfo: () => LayoutInfo;
|
|
139
|
+
/**
|
|
140
|
+
* 获取视口信息
|
|
141
|
+
*/
|
|
142
|
+
getViewportInfo: () => ViewportInfo;
|
|
143
|
+
/**
|
|
144
|
+
* 强制更新
|
|
145
|
+
*/
|
|
146
|
+
forceUpdate: () => void;
|
|
147
|
+
/**
|
|
148
|
+
* 获取容器 DOM
|
|
149
|
+
*/
|
|
150
|
+
getContainer: () => HTMLDivElement | null;
|
|
151
|
+
/**
|
|
152
|
+
* 获取项 DOM
|
|
153
|
+
*/
|
|
154
|
+
getItemElement: (index: number) => HTMLElement | null;
|
|
155
|
+
/**
|
|
156
|
+
* 测量项尺寸
|
|
157
|
+
*/
|
|
158
|
+
measureItem: (index: number) => Promise<{
|
|
159
|
+
width: number;
|
|
160
|
+
height: number;
|
|
161
|
+
}>;
|
|
162
|
+
}
|
|
163
|
+
export interface ScrollToItemOptions {
|
|
164
|
+
behavior?: "auto" | "smooth";
|
|
165
|
+
block?: "start" | "center" | "end" | "nearest";
|
|
166
|
+
inline?: "start" | "center" | "end" | "nearest";
|
|
167
|
+
offset?: number;
|
|
168
|
+
}
|
|
169
|
+
export interface ScrollToOptions {
|
|
170
|
+
behavior?: "auto" | "smooth";
|
|
171
|
+
offset?: number;
|
|
172
|
+
}
|
|
173
|
+
declare const WaterfallCore: React.ForwardRefExoticComponent<WaterfallCoreProps<any> & React.RefAttributes<WaterfallCoreRef>>;
|
|
174
|
+
export default WaterfallCore;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { WaterfallPlugin } from '../../plugins/types';
|
|
2
|
+
type A11yConfig = {
|
|
3
|
+
/** 为容器设置 ARIA role(默认 list) */
|
|
4
|
+
containerRole?: string;
|
|
5
|
+
/** 为项设置 ARIA role(默认 listitem) */
|
|
6
|
+
itemRole?: string;
|
|
7
|
+
/** 是否给项添加 tabindex 便于键盘焦点 */
|
|
8
|
+
enableTabIndex?: boolean;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* A11yPlugin - 可访问性增强
|
|
12
|
+
* - 为容器与项添加合理的 ARIA 角色与属性
|
|
13
|
+
* - 为项添加 tabindex,支持键盘导航与聚焦
|
|
14
|
+
*/
|
|
15
|
+
export declare function createA11yPlugin<T = any>(config?: A11yConfig): WaterfallPlugin<T>;
|
|
16
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WaterfallPlugin } from '../../plugins/types';
|
|
2
|
+
export type AlignmentMode = "shortest" | "balanced" | "sequential";
|
|
3
|
+
type AlignmentConfig = {
|
|
4
|
+
/** 列分配策略 */
|
|
5
|
+
mode: AlignmentMode;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* AlignmentPlugin - 控制瀑布流列分配策略
|
|
9
|
+
* 通过设置 props.alignmentMode 来影响核心布局算法的列选择逻辑
|
|
10
|
+
*/
|
|
11
|
+
export declare function createAlignmentPlugin<T = any>(config: AlignmentConfig): WaterfallPlugin<T>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { WaterfallPlugin } from '../../plugins/types';
|
|
2
|
+
type AutoColumnConfig = {
|
|
3
|
+
/** 每列最小宽度(含内容区,不含列间距) */
|
|
4
|
+
minColumnWidth: number;
|
|
5
|
+
/** 最大列数(可选) */
|
|
6
|
+
maxColumns?: number;
|
|
7
|
+
/** 最小列数(可选,默认 1) */
|
|
8
|
+
minColumns?: number;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* 根据视口宽度和最小列宽自动计算列数
|
|
12
|
+
* 公式(近似):columns = floor((availableWidth + columnGap) / (minColumnWidth + columnGap))
|
|
13
|
+
* - availableWidth 近似取 window.innerWidth,避免强依赖容器 ref
|
|
14
|
+
* - 考虑 padding 与 columnGap,提高真实布局的贴合度
|
|
15
|
+
*/
|
|
16
|
+
export declare function createAutoColumnPlugin<T = any>(config: AutoColumnConfig): WaterfallPlugin<T>;
|
|
17
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WaterfallPlugin } from '../../plugins/types';
|
|
2
|
+
type BookmarkConfig = {
|
|
3
|
+
/** localStorage 键名 */
|
|
4
|
+
storageKey?: string;
|
|
5
|
+
/** 滚动行为 */
|
|
6
|
+
scrollBehavior?: "auto" | "smooth";
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* BookmarkPlugin - 位置书签(键盘快捷键)
|
|
10
|
+
* - 按下 'b' 保存当前滚动位置到 localStorage
|
|
11
|
+
* - 按下 'r' 恢复到保存位置
|
|
12
|
+
* - 忽略输入框/可编辑元素中的按键
|
|
13
|
+
*/
|
|
14
|
+
export declare function createBookmarkPlugin<T = any>(config?: BookmarkConfig): WaterfallPlugin<T>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { WaterfallPlugin } from '../../plugins/types';
|
|
2
|
+
type ClickAnalyticsConfig = {
|
|
3
|
+
/** 是否在控制台输出点击日志 */
|
|
4
|
+
log?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* ClickAnalyticsPlugin - 点击分析(基础版)
|
|
8
|
+
* - 统计点击次数,向 bus 发送事件:analytics:click
|
|
9
|
+
* - 可选控制台输出日志
|
|
10
|
+
*/
|
|
11
|
+
export declare function createClickAnalyticsPlugin<T = any>(config?: ClickAnalyticsConfig): WaterfallPlugin<T>;
|
|
12
|
+
export {};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { WaterfallPlugin } from '../../plugins/types';
|
|
2
|
+
type DebounceConfig = {
|
|
3
|
+
/** 布局防抖延迟(ms) */
|
|
4
|
+
delay: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* DebounceLayoutPlugin - 调整核心布局的防抖延迟
|
|
8
|
+
*/
|
|
9
|
+
export declare function createDebounceLayoutPlugin<T = any>(config: DebounceConfig): WaterfallPlugin<T>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { WaterfallPlugin } from '../../plugins/types';
|
|
2
|
+
type DragReorderConfig = {
|
|
3
|
+
/** 是否启用(默认 true) */
|
|
4
|
+
enabled?: boolean;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* DragReorderPlugin - 拖拽重排
|
|
8
|
+
* - 为项包装器添加可拖拽样式与属性
|
|
9
|
+
* - 记录最后一次拖拽的 from/to 索引(sharedData)
|
|
10
|
+
* - 实际数据重排需外层配合(示例页提供)
|
|
11
|
+
*/
|
|
12
|
+
export declare function createDragReorderPlugin<T = any>(config?: DragReorderConfig): WaterfallPlugin<T>;
|
|
13
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { WaterfallPlugin } from '../../plugins/types';
|
|
2
|
+
type FilterConfig<T = any> = {
|
|
3
|
+
/** 初始筛选函数,可被 props.filterFn 覆盖 */
|
|
4
|
+
predicate?: (item: T, index: number) => boolean;
|
|
5
|
+
/** 条件变化后自动滚动到顶部 */
|
|
6
|
+
scrollToTop?: boolean;
|
|
7
|
+
/** 滚动行为(auto/smooth),仅在启用 scrollToTop 时生效 */
|
|
8
|
+
scrollBehavior?: "auto" | "smooth";
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* FilterPlugin - 基于筛选函数过滤 items
|
|
12
|
+
* 优先使用 props.filterFn,其次使用创建插件时传入的 predicate
|
|
13
|
+
*/
|
|
14
|
+
export declare function createFilterPlugin<T = any>(config?: FilterConfig<T>): WaterfallPlugin<T>;
|
|
15
|
+
export {};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { WaterfallPlugin } from '../../plugins/types';
|
|
2
|
+
type FixedHeightConfig = {
|
|
3
|
+
/** 固定项高度(像素) */
|
|
4
|
+
itemHeight: number;
|
|
5
|
+
};
|
|
6
|
+
/**
|
|
7
|
+
* FixedHeightPlugin - 将所有项的高度统一为固定值(Grid风格)
|
|
8
|
+
* 通过 transformProps 生成新的 items,使得 renderItem 使用统一高度
|
|
9
|
+
*/
|
|
10
|
+
export declare function createFixedHeightPlugin<T = any>(config: FixedHeightConfig): WaterfallPlugin<T>;
|
|
11
|
+
export {};
|