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
|
@@ -0,0 +1,468 @@
|
|
|
1
|
+
import { default as React } from 'react';
|
|
2
|
+
import { WaterfallCoreProps } from '../core/WaterfallCore';
|
|
3
|
+
/**
|
|
4
|
+
* 瀑布流项的位置信息
|
|
5
|
+
*/
|
|
6
|
+
export interface ItemPosition {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
width: number;
|
|
10
|
+
height: number;
|
|
11
|
+
column: number;
|
|
12
|
+
row: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* 布局信息
|
|
16
|
+
*/
|
|
17
|
+
export interface LayoutInfo {
|
|
18
|
+
columns: number;
|
|
19
|
+
columnWidth: number;
|
|
20
|
+
gap: number;
|
|
21
|
+
columnHeights: number[];
|
|
22
|
+
totalHeight: number;
|
|
23
|
+
containerWidth: number;
|
|
24
|
+
containerHeight: number;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 视口信息
|
|
28
|
+
*/
|
|
29
|
+
export interface ViewportInfo {
|
|
30
|
+
scrollTop: number;
|
|
31
|
+
scrollLeft: number;
|
|
32
|
+
scrollHeight: number;
|
|
33
|
+
scrollWidth: number;
|
|
34
|
+
clientHeight: number;
|
|
35
|
+
clientWidth: number;
|
|
36
|
+
isScrolling: boolean;
|
|
37
|
+
direction: "up" | "down" | "left" | "right" | null;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 项可见性信息
|
|
41
|
+
*/
|
|
42
|
+
export interface ItemVisibility {
|
|
43
|
+
index: number;
|
|
44
|
+
isVisible: boolean;
|
|
45
|
+
visibleRatio: number;
|
|
46
|
+
isAboveViewport: boolean;
|
|
47
|
+
isBelowViewport: boolean;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 性能指标
|
|
51
|
+
*/
|
|
52
|
+
export interface PerformanceMetrics {
|
|
53
|
+
layoutStartTime: number;
|
|
54
|
+
layoutEndTime?: number;
|
|
55
|
+
layoutDuration?: number;
|
|
56
|
+
layoutCount: number;
|
|
57
|
+
renderStartTime?: number;
|
|
58
|
+
renderEndTime?: number;
|
|
59
|
+
renderDuration?: number;
|
|
60
|
+
renderedItemCount: number;
|
|
61
|
+
scrollStartTime?: number;
|
|
62
|
+
scrollEndTime?: number;
|
|
63
|
+
scrollDuration?: number;
|
|
64
|
+
scrollDistance?: number;
|
|
65
|
+
itemCount: number;
|
|
66
|
+
visibleItemCount: number;
|
|
67
|
+
memoryUsage?: number;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 设备信息
|
|
71
|
+
*/
|
|
72
|
+
export interface DeviceInfo {
|
|
73
|
+
type: "mobile" | "tablet" | "desktop";
|
|
74
|
+
os: string;
|
|
75
|
+
browser: string;
|
|
76
|
+
devicePixelRatio: number;
|
|
77
|
+
viewportWidth: number;
|
|
78
|
+
viewportHeight: number;
|
|
79
|
+
isTouchDevice: boolean;
|
|
80
|
+
isRetina: boolean;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* 网络信息
|
|
84
|
+
*/
|
|
85
|
+
export interface NetworkInfo {
|
|
86
|
+
effectiveType: "4g" | "3g" | "2g" | "slow-2g";
|
|
87
|
+
downlink: number;
|
|
88
|
+
rtt: number;
|
|
89
|
+
saveData: boolean;
|
|
90
|
+
online: boolean;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* 动画配置
|
|
94
|
+
*/
|
|
95
|
+
export interface AnimationConfig {
|
|
96
|
+
duration: number;
|
|
97
|
+
delay?: number;
|
|
98
|
+
easing?: string;
|
|
99
|
+
stagger?: number;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* 拖拽信息
|
|
103
|
+
*/
|
|
104
|
+
export interface DragInfo {
|
|
105
|
+
isDragging: boolean;
|
|
106
|
+
draggedIndex: number | null;
|
|
107
|
+
dragStartX: number;
|
|
108
|
+
dragStartY: number;
|
|
109
|
+
dragCurrentX: number;
|
|
110
|
+
dragCurrentY: number;
|
|
111
|
+
dropTargetIndex: number | null;
|
|
112
|
+
}
|
|
113
|
+
export interface PluginBus {
|
|
114
|
+
emit: <T = any>(event: string, data?: T) => void;
|
|
115
|
+
on: <T = any>(event: string, handler: (data: T) => void) => () => void;
|
|
116
|
+
once: <T = any>(event: string, handler: (data: T) => void) => () => void;
|
|
117
|
+
off: (event: string, handler?: (data: any) => void) => void;
|
|
118
|
+
getData: <T = any>(key: string) => T | undefined;
|
|
119
|
+
setData: <T = any>(key: string, value: T) => void;
|
|
120
|
+
deleteData: (key: string) => void;
|
|
121
|
+
hasData: (key: string) => boolean;
|
|
122
|
+
getAll: () => Record<string, any>;
|
|
123
|
+
clear: () => void;
|
|
124
|
+
}
|
|
125
|
+
export interface WaterfallPluginContext<T = any> {
|
|
126
|
+
items: T[];
|
|
127
|
+
itemCount: number;
|
|
128
|
+
containerRef: React.RefObject<HTMLDivElement | null>;
|
|
129
|
+
itemRefs: Map<number, HTMLElement>;
|
|
130
|
+
getItemRef: (index: number) => HTMLElement | null;
|
|
131
|
+
layout: LayoutInfo;
|
|
132
|
+
itemPositions: Map<number, ItemPosition>;
|
|
133
|
+
getItemPosition: (index: number) => ItemPosition | null;
|
|
134
|
+
viewport: ViewportInfo;
|
|
135
|
+
visibleItems: Set<number>;
|
|
136
|
+
visibleRange: {
|
|
137
|
+
start: number;
|
|
138
|
+
end: number;
|
|
139
|
+
};
|
|
140
|
+
isLayouting: boolean;
|
|
141
|
+
isScrolling: boolean;
|
|
142
|
+
isDragging: boolean;
|
|
143
|
+
isLoading: boolean;
|
|
144
|
+
hasMore: boolean;
|
|
145
|
+
error: Error | null;
|
|
146
|
+
props: WaterfallCoreProps<T>;
|
|
147
|
+
bus?: PluginBus;
|
|
148
|
+
sharedData?: Map<string, any>;
|
|
149
|
+
deviceInfo?: DeviceInfo;
|
|
150
|
+
networkInfo?: NetworkInfo;
|
|
151
|
+
performanceMetrics?: PerformanceMetrics;
|
|
152
|
+
dragInfo?: DragInfo;
|
|
153
|
+
relayout: () => void;
|
|
154
|
+
scrollToItem: (index: number, options?: ScrollToOptions) => void;
|
|
155
|
+
scrollToTop: (options?: ScrollToOptions) => void;
|
|
156
|
+
scrollToBottom: (options?: ScrollToOptions) => void;
|
|
157
|
+
measureItem: (index: number) => Promise<{
|
|
158
|
+
width: number;
|
|
159
|
+
height: number;
|
|
160
|
+
}>;
|
|
161
|
+
forceUpdate: () => void;
|
|
162
|
+
}
|
|
163
|
+
export interface ScrollToOptions {
|
|
164
|
+
behavior?: "auto" | "smooth";
|
|
165
|
+
block?: "start" | "center" | "end" | "nearest";
|
|
166
|
+
inline?: "start" | "center" | "end" | "nearest";
|
|
167
|
+
}
|
|
168
|
+
export interface WaterfallPluginHooks<T = any> {
|
|
169
|
+
/**
|
|
170
|
+
* 组件挂载时触发
|
|
171
|
+
* @returns 清理函数(可选)
|
|
172
|
+
*/
|
|
173
|
+
onMount?: (context: WaterfallPluginContext<T>) => void | (() => void);
|
|
174
|
+
/**
|
|
175
|
+
* 组件卸载时触发
|
|
176
|
+
*/
|
|
177
|
+
onUnmount?: (context: WaterfallPluginContext<T>) => void;
|
|
178
|
+
/**
|
|
179
|
+
* Props 变化时触发
|
|
180
|
+
*/
|
|
181
|
+
onPropsChange?: (context: WaterfallPluginContext<T>, prevProps: WaterfallCoreProps<T>, nextProps: WaterfallCoreProps<T>) => void;
|
|
182
|
+
/**
|
|
183
|
+
* 布局开始前触发
|
|
184
|
+
* @returns false 可以阻止布局
|
|
185
|
+
*/
|
|
186
|
+
onBeforeLayout?: (context: WaterfallPluginContext<T>) => boolean | Promise<boolean>;
|
|
187
|
+
/**
|
|
188
|
+
* 布局计算中触发(可以修改布局逻辑)
|
|
189
|
+
*/
|
|
190
|
+
onLayout?: (context: WaterfallPluginContext<T>) => void;
|
|
191
|
+
/**
|
|
192
|
+
* 布局完成后触发
|
|
193
|
+
*/
|
|
194
|
+
onLayoutComplete?: (context: WaterfallPluginContext<T>) => void;
|
|
195
|
+
/**
|
|
196
|
+
* 计算列数(响应式插件会实现此钩子)
|
|
197
|
+
* @returns 列数,undefined 表示使用默认值
|
|
198
|
+
*/
|
|
199
|
+
calculateColumns?: (context: WaterfallPluginContext<T>) => number | undefined;
|
|
200
|
+
/**
|
|
201
|
+
* 计算列宽(自定义列宽插件会实现)
|
|
202
|
+
*/
|
|
203
|
+
calculateColumnWidth?: (context: WaterfallPluginContext<T>, containerWidth: number, columns: number) => number | undefined;
|
|
204
|
+
/**
|
|
205
|
+
* 计算项位置(自定义布局算法插件会实现)
|
|
206
|
+
*/
|
|
207
|
+
calculateItemPosition?: (context: WaterfallPluginContext<T>, index: number, itemHeight: number) => ItemPosition | undefined;
|
|
208
|
+
/**
|
|
209
|
+
* 项挂载时触发
|
|
210
|
+
*/
|
|
211
|
+
onItemMount?: (context: WaterfallPluginContext<T>, index: number, element: HTMLElement) => void;
|
|
212
|
+
/**
|
|
213
|
+
* 项卸载时触发
|
|
214
|
+
*/
|
|
215
|
+
onItemUnmount?: (context: WaterfallPluginContext<T>, index: number) => void;
|
|
216
|
+
/**
|
|
217
|
+
* 项进入视口时触发
|
|
218
|
+
*/
|
|
219
|
+
onItemEnterViewport?: (context: WaterfallPluginContext<T>, index: number, visibility: ItemVisibility) => void;
|
|
220
|
+
/**
|
|
221
|
+
* 项离开视口时触发
|
|
222
|
+
*/
|
|
223
|
+
onItemLeaveViewport?: (context: WaterfallPluginContext<T>, index: number, visibility: ItemVisibility) => void;
|
|
224
|
+
/**
|
|
225
|
+
* 项可见性变化时触发
|
|
226
|
+
*/
|
|
227
|
+
onItemVisibilityChange?: (context: WaterfallPluginContext<T>, index: number, visibility: ItemVisibility) => void;
|
|
228
|
+
/**
|
|
229
|
+
* 项点击时触发
|
|
230
|
+
*/
|
|
231
|
+
onItemClick?: (context: WaterfallPluginContext<T>, index: number, item: T, event: React.MouseEvent) => void;
|
|
232
|
+
/**
|
|
233
|
+
* 滚动开始时触发
|
|
234
|
+
*/
|
|
235
|
+
onScrollStart?: (context: WaterfallPluginContext<T>) => void;
|
|
236
|
+
/**
|
|
237
|
+
* 滚动中触发
|
|
238
|
+
*/
|
|
239
|
+
onScroll?: (context: WaterfallPluginContext<T>, scrollTop: number, scrollLeft: number) => void;
|
|
240
|
+
/**
|
|
241
|
+
* 滚动结束时触发
|
|
242
|
+
*/
|
|
243
|
+
onScrollEnd?: (context: WaterfallPluginContext<T>) => void;
|
|
244
|
+
/**
|
|
245
|
+
* 滚动到底部时触发(用于无限滚动)
|
|
246
|
+
*/
|
|
247
|
+
onReachBottom?: (context: WaterfallPluginContext<T>, distance: number) => void | Promise<void>;
|
|
248
|
+
/**
|
|
249
|
+
* 滚动到顶部时触发
|
|
250
|
+
*/
|
|
251
|
+
onReachTop?: (context: WaterfallPluginContext<T>) => void;
|
|
252
|
+
/**
|
|
253
|
+
* 容器尺寸变化时触发
|
|
254
|
+
*/
|
|
255
|
+
onResize?: (context: WaterfallPluginContext<T>, width: number, height: number) => void;
|
|
256
|
+
/**
|
|
257
|
+
* 项尺寸变化时触发
|
|
258
|
+
*/
|
|
259
|
+
onItemResize?: (context: WaterfallPluginContext<T>, index: number, width: number, height: number) => void;
|
|
260
|
+
/**
|
|
261
|
+
* 数据变化前触发
|
|
262
|
+
* @returns false 可以阻止数据更新
|
|
263
|
+
*/
|
|
264
|
+
onBeforeItemsChange?: (context: WaterfallPluginContext<T>, oldItems: T[], newItems: T[]) => boolean | Promise<boolean>;
|
|
265
|
+
/**
|
|
266
|
+
* 数据变化后触发
|
|
267
|
+
*/
|
|
268
|
+
onItemsChange?: (context: WaterfallPluginContext<T>, oldItems: T[], newItems: T[]) => void;
|
|
269
|
+
/**
|
|
270
|
+
* 单个项数据变化时触发
|
|
271
|
+
*/
|
|
272
|
+
onItemChange?: (context: WaterfallPluginContext<T>, index: number, oldItem: T, newItem: T) => void;
|
|
273
|
+
/**
|
|
274
|
+
* 加载更多数据时触发(无限滚动插件会实现)
|
|
275
|
+
*/
|
|
276
|
+
onLoadMore?: (context: WaterfallPluginContext<T>, page: number) => Promise<T[]> | T[] | void;
|
|
277
|
+
/**
|
|
278
|
+
* 刷新数据时触发(下拉刷新插件会实现)
|
|
279
|
+
*/
|
|
280
|
+
onRefresh?: (context: WaterfallPluginContext<T>) => Promise<T[]> | T[] | void;
|
|
281
|
+
/**
|
|
282
|
+
* 拖拽开始时触发
|
|
283
|
+
*/
|
|
284
|
+
onDragStart?: (context: WaterfallPluginContext<T>, index: number, event: React.DragEvent) => void;
|
|
285
|
+
/**
|
|
286
|
+
* 拖拽中触发
|
|
287
|
+
*/
|
|
288
|
+
onDrag?: (context: WaterfallPluginContext<T>, index: number, event: React.DragEvent) => void;
|
|
289
|
+
/**
|
|
290
|
+
* 拖拽结束时触发
|
|
291
|
+
*/
|
|
292
|
+
onDragEnd?: (context: WaterfallPluginContext<T>, index: number, event: React.DragEvent) => void;
|
|
293
|
+
/**
|
|
294
|
+
* 项被拖放时触发
|
|
295
|
+
*/
|
|
296
|
+
onDrop?: (context: WaterfallPluginContext<T>, fromIndex: number, toIndex: number) => void;
|
|
297
|
+
/**
|
|
298
|
+
* 项被选中时触发
|
|
299
|
+
*/
|
|
300
|
+
onItemSelect?: (context: WaterfallPluginContext<T>, index: number, item: T, selected: boolean) => void;
|
|
301
|
+
/**
|
|
302
|
+
* 多选变化时触发
|
|
303
|
+
*/
|
|
304
|
+
onSelectionChange?: (context: WaterfallPluginContext<T>, selectedIndices: Set<number>) => void;
|
|
305
|
+
/**
|
|
306
|
+
* 筛选逻辑(筛选插件会实现)
|
|
307
|
+
*/
|
|
308
|
+
filterItem?: (context: WaterfallPluginContext<T>, item: T, index: number) => boolean;
|
|
309
|
+
/**
|
|
310
|
+
* 排序逻辑(排序插件会实现)
|
|
311
|
+
*/
|
|
312
|
+
sortItems?: (context: WaterfallPluginContext<T>, items: T[]) => T[];
|
|
313
|
+
/**
|
|
314
|
+
* 搜索逻辑(搜索插件会实现)
|
|
315
|
+
*/
|
|
316
|
+
searchItem?: (context: WaterfallPluginContext<T>, item: T, query: string) => boolean;
|
|
317
|
+
/**
|
|
318
|
+
* 性能指标收集
|
|
319
|
+
*/
|
|
320
|
+
onPerformanceMetric?: (context: WaterfallPluginContext<T>, metrics: PerformanceMetrics) => void;
|
|
321
|
+
/**
|
|
322
|
+
* 虚拟滚动范围计算(虚拟滚动插件会实现)
|
|
323
|
+
*/
|
|
324
|
+
calculateVisibleRange?: (context: WaterfallPluginContext<T>) => {
|
|
325
|
+
start: number;
|
|
326
|
+
end: number;
|
|
327
|
+
} | undefined;
|
|
328
|
+
/**
|
|
329
|
+
* 错误发生时触发
|
|
330
|
+
*/
|
|
331
|
+
onError?: (context: WaterfallPluginContext<T>, error: Error, errorInfo?: React.ErrorInfo) => void;
|
|
332
|
+
/**
|
|
333
|
+
* 项加载失败时触发
|
|
334
|
+
*/
|
|
335
|
+
onItemLoadError?: (context: WaterfallPluginContext<T>, index: number, error: Error) => void;
|
|
336
|
+
/**
|
|
337
|
+
* 自定义容器渲染
|
|
338
|
+
*/
|
|
339
|
+
renderContainer?: (context: WaterfallPluginContext<T>, children: React.ReactNode) => React.ReactNode;
|
|
340
|
+
/**
|
|
341
|
+
* 自定义项包装器渲染
|
|
342
|
+
*/
|
|
343
|
+
renderItemWrapper?: (context: WaterfallPluginContext<T>, index: number, item: T, children: React.ReactNode) => React.ReactNode;
|
|
344
|
+
/**
|
|
345
|
+
* 自定义覆盖层渲染(加载状态、空状态等)
|
|
346
|
+
*/
|
|
347
|
+
renderOverlay?: (context: WaterfallPluginContext<T>) => React.ReactNode;
|
|
348
|
+
/**
|
|
349
|
+
* 自定义加载更多指示器
|
|
350
|
+
*/
|
|
351
|
+
renderLoadingMore?: (context: WaterfallPluginContext<T>) => React.ReactNode;
|
|
352
|
+
/**
|
|
353
|
+
* 自定义空状态
|
|
354
|
+
*/
|
|
355
|
+
renderEmpty?: (context: WaterfallPluginContext<T>) => React.ReactNode;
|
|
356
|
+
/**
|
|
357
|
+
* 自定义错误状态
|
|
358
|
+
*/
|
|
359
|
+
renderError?: (context: WaterfallPluginContext<T>, error: Error) => React.ReactNode;
|
|
360
|
+
/**
|
|
361
|
+
* 转换 Props(可以在组件接收 props 前修改)
|
|
362
|
+
*/
|
|
363
|
+
transformProps?: (props: WaterfallCoreProps<T>) => WaterfallCoreProps<T>;
|
|
364
|
+
/**
|
|
365
|
+
* 转换项数据(可以在渲染前修改项数据)
|
|
366
|
+
*/
|
|
367
|
+
transformItem?: (context: WaterfallPluginContext<T>, item: T, index: number) => T;
|
|
368
|
+
}
|
|
369
|
+
export interface WaterfallPlugin<T = any> {
|
|
370
|
+
/**
|
|
371
|
+
* 插件名称(唯一标识)
|
|
372
|
+
*/
|
|
373
|
+
name: string;
|
|
374
|
+
/**
|
|
375
|
+
* 插件版本
|
|
376
|
+
*/
|
|
377
|
+
version?: string;
|
|
378
|
+
/**
|
|
379
|
+
* 插件描述
|
|
380
|
+
*/
|
|
381
|
+
description?: string;
|
|
382
|
+
/**
|
|
383
|
+
* 插件钩子
|
|
384
|
+
*/
|
|
385
|
+
hooks: WaterfallPluginHooks<T>;
|
|
386
|
+
/**
|
|
387
|
+
* 插件配置
|
|
388
|
+
*/
|
|
389
|
+
config?: Record<string, any>;
|
|
390
|
+
/**
|
|
391
|
+
* 插件依赖(需要先加载的插件名称)
|
|
392
|
+
*/
|
|
393
|
+
dependencies?: string[];
|
|
394
|
+
/**
|
|
395
|
+
* 插件优先级(数字越大优先级越高)
|
|
396
|
+
*/
|
|
397
|
+
priority?: number;
|
|
398
|
+
/**
|
|
399
|
+
* 插件初始化
|
|
400
|
+
*/
|
|
401
|
+
init?: () => void | Promise<void>;
|
|
402
|
+
/**
|
|
403
|
+
* 插件销毁
|
|
404
|
+
*/
|
|
405
|
+
destroy?: () => void | Promise<void>;
|
|
406
|
+
/**
|
|
407
|
+
* 插件是否启用
|
|
408
|
+
*/
|
|
409
|
+
enabled?: boolean;
|
|
410
|
+
}
|
|
411
|
+
export interface PluginManager<T = any> {
|
|
412
|
+
/**
|
|
413
|
+
* 注册插件
|
|
414
|
+
*/
|
|
415
|
+
register: (plugin: WaterfallPlugin<T>) => void;
|
|
416
|
+
/**
|
|
417
|
+
* 批量注册插件
|
|
418
|
+
*/
|
|
419
|
+
registerAll: (plugins: WaterfallPlugin<T>[]) => void;
|
|
420
|
+
/**
|
|
421
|
+
* 注销插件
|
|
422
|
+
*/
|
|
423
|
+
unregister: (pluginName: string) => void;
|
|
424
|
+
/**
|
|
425
|
+
* 获取插件
|
|
426
|
+
*/
|
|
427
|
+
getPlugin: (pluginName: string) => WaterfallPlugin<T> | undefined;
|
|
428
|
+
/**
|
|
429
|
+
* 获取所有插件
|
|
430
|
+
*/
|
|
431
|
+
getAllPlugins: () => WaterfallPlugin<T>[];
|
|
432
|
+
/**
|
|
433
|
+
* 获取启用的插件
|
|
434
|
+
*/
|
|
435
|
+
getEnabledPlugins: () => WaterfallPlugin<T>[];
|
|
436
|
+
/**
|
|
437
|
+
* 启用插件
|
|
438
|
+
*/
|
|
439
|
+
enablePlugin: (pluginName: string) => void;
|
|
440
|
+
/**
|
|
441
|
+
* 禁用插件
|
|
442
|
+
*/
|
|
443
|
+
disablePlugin: (pluginName: string) => void;
|
|
444
|
+
/**
|
|
445
|
+
* 检查插件是否已注册
|
|
446
|
+
*/
|
|
447
|
+
hasPlugin: (pluginName: string) => boolean;
|
|
448
|
+
/**
|
|
449
|
+
* 执行钩子
|
|
450
|
+
*/
|
|
451
|
+
executeHook: <K extends keyof WaterfallPluginHooks<T>>(hookName: K, context: WaterfallPluginContext<T>, ...args: any[]) => Promise<any>;
|
|
452
|
+
/**
|
|
453
|
+
* 清空所有插件
|
|
454
|
+
*/
|
|
455
|
+
clear: () => void;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
458
|
+
* 插件创建器类型
|
|
459
|
+
*/
|
|
460
|
+
export type PluginCreator<T = any, Config = any> = (config?: Config) => WaterfallPlugin<T>;
|
|
461
|
+
/**
|
|
462
|
+
* 项渲染函数类型
|
|
463
|
+
*/
|
|
464
|
+
export type ItemRenderer<T = any> = (item: T, index: number, context: WaterfallPluginContext<T>) => React.ReactNode;
|
|
465
|
+
/**
|
|
466
|
+
* 项键提取函数类型
|
|
467
|
+
*/
|
|
468
|
+
export type ItemKeyExtractor<T = any> = (item: T, index: number) => string | number;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { WaterfallPlugin } from './types';
|
|
2
|
+
import { default as React } from 'react';
|
|
3
|
+
import { WaterfallCoreProps, WaterfallCoreRef } from '../core/WaterfallCore';
|
|
4
|
+
export interface WithPluginsConfig<T = any> {
|
|
5
|
+
plugins: WaterfallPlugin<T>[];
|
|
6
|
+
enableDebug?: boolean;
|
|
7
|
+
}
|
|
8
|
+
export declare function withPlugins<T = any>(WrappedComponent: React.ForwardRefExoticComponent<React.PropsWithoutRef<WaterfallCoreProps<T>> & React.RefAttributes<WaterfallCoreRef>>, config: WithPluginsConfig<T> | WaterfallPlugin<T>[]): React.ForwardRefExoticComponent<WaterfallCoreProps<T> & React.RefAttributes<WaterfallCoreRef>>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* vane-waterfall 库入口文件
|
|
3
|
+
* 用于 npm 包发布时的导出
|
|
4
|
+
*/
|
|
5
|
+
export { WaterfallCore } from './components/WaterfallPlugin';
|
|
6
|
+
export type { WaterfallCoreProps, WaterfallCoreRef, ScrollToOptions, ScrollToItemOptions, } from './components/WaterfallPlugin';
|
|
7
|
+
export type { WaterfallPlugin, PluginManager, PluginBus, WaterfallPluginContext, WaterfallPluginHooks, PluginCreator, WithPluginsConfig, ItemPosition, LayoutInfo, ViewportInfo, ItemVisibility, PerformanceMetrics, DeviceInfo, NetworkInfo, AnimationConfig, DragInfo, ItemRenderer, ItemKeyExtractor, } from './components/WaterfallPlugin/plugins';
|
|
8
|
+
export { createPluginBus } from './components/WaterfallPlugin/plugins';
|
|
9
|
+
export { createPluginManager } from './components/WaterfallPlugin/plugins';
|
|
10
|
+
export { withPlugins } from './components/WaterfallPlugin/plugins';
|
|
11
|
+
export * from './components/WaterfallPlugin/custom-plugins';
|