mtrl-addons 0.2.1 → 0.2.3
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/{src/components/index.ts → dist/components/index.d.ts} +0 -2
- package/dist/components/vlist/config.d.ts +86 -0
- package/{src/components/vlist/constants.ts → dist/components/vlist/constants.d.ts} +10 -11
- package/dist/components/vlist/features/api.d.ts +7 -0
- package/{src/components/vlist/features/index.ts → dist/components/vlist/features/index.d.ts} +0 -2
- package/dist/components/vlist/features/selection.d.ts +6 -0
- package/dist/components/vlist/features/viewport.d.ts +9 -0
- package/dist/components/vlist/features.d.ts +31 -0
- package/{src/components/vlist/index.ts → dist/components/vlist/index.d.ts} +1 -9
- package/dist/components/vlist/types.d.ts +596 -0
- package/dist/components/vlist/vlist.d.ts +29 -0
- package/dist/core/compose/features/gestures/index.d.ts +86 -0
- package/dist/core/compose/features/gestures/longpress.d.ts +85 -0
- package/dist/core/compose/features/gestures/pan.d.ts +108 -0
- package/dist/core/compose/features/gestures/pinch.d.ts +111 -0
- package/dist/core/compose/features/gestures/rotate.d.ts +111 -0
- package/dist/core/compose/features/gestures/swipe.d.ts +149 -0
- package/dist/core/compose/features/gestures/tap.d.ts +79 -0
- package/{src/core/compose/features/index.ts → dist/core/compose/features/index.d.ts} +1 -2
- package/{src/core/compose/index.ts → dist/core/compose/index.d.ts} +2 -11
- package/{src/core/gestures/index.ts → dist/core/gestures/index.d.ts} +1 -20
- package/dist/core/gestures/longpress.d.ts +23 -0
- package/dist/core/gestures/manager.d.ts +14 -0
- package/dist/core/gestures/pan.d.ts +12 -0
- package/dist/core/gestures/pinch.d.ts +14 -0
- package/dist/core/gestures/rotate.d.ts +14 -0
- package/dist/core/gestures/swipe.d.ts +20 -0
- package/dist/core/gestures/tap.d.ts +12 -0
- package/dist/core/gestures/types.d.ts +320 -0
- package/dist/core/gestures/utils.d.ts +57 -0
- package/dist/core/index.d.ts +13 -0
- package/dist/core/layout/config.d.ts +33 -0
- package/dist/core/layout/index.d.ts +51 -0
- package/dist/core/layout/jsx.d.ts +65 -0
- package/dist/core/layout/schema.d.ts +112 -0
- package/dist/core/layout/types.d.ts +69 -0
- package/dist/core/viewport/constants.d.ts +105 -0
- package/dist/core/viewport/features/base.d.ts +14 -0
- package/dist/core/viewport/features/collection.d.ts +41 -0
- package/dist/core/viewport/features/events.d.ts +13 -0
- package/{src/core/viewport/features/index.ts → dist/core/viewport/features/index.d.ts} +0 -7
- package/dist/core/viewport/features/item-size.d.ts +30 -0
- package/dist/core/viewport/features/loading.d.ts +34 -0
- package/dist/core/viewport/features/momentum.d.ts +17 -0
- package/dist/core/viewport/features/performance.d.ts +53 -0
- package/dist/core/viewport/features/placeholders.d.ts +38 -0
- package/dist/core/viewport/features/rendering.d.ts +16 -0
- package/dist/core/viewport/features/scrollbar.d.ts +26 -0
- package/dist/core/viewport/features/scrolling.d.ts +16 -0
- package/dist/core/viewport/features/utils.d.ts +43 -0
- package/dist/core/viewport/features/virtual.d.ts +18 -0
- package/{src/core/viewport/index.ts → dist/core/viewport/index.d.ts} +1 -17
- package/dist/core/viewport/types.d.ts +96 -0
- package/dist/core/viewport/utils/speed-tracker.d.ts +22 -0
- package/dist/core/viewport/viewport.d.ts +11 -0
- package/{src/index.ts → dist/index.d.ts} +0 -4
- package/dist/index.js +5143 -0
- package/dist/index.mjs +5111 -0
- package/dist/styles.css +254 -0
- package/dist/styles.css.map +1 -0
- package/package.json +6 -1
- package/src/styles/components/_vlist.scss +234 -213
- package/.cursorrules +0 -117
- package/AI.md +0 -241
- package/build.js +0 -201
- package/scripts/analyze-orphaned-functions.ts +0 -387
- package/scripts/debug/vlist-selection.ts +0 -121
- package/src/components/vlist/config.ts +0 -323
- package/src/components/vlist/features/api.ts +0 -322
- package/src/components/vlist/features/selection.ts +0 -444
- package/src/components/vlist/features/viewport.ts +0 -65
- package/src/components/vlist/features.ts +0 -112
- package/src/components/vlist/types.ts +0 -591
- package/src/components/vlist/vlist.ts +0 -92
- package/src/core/compose/features/gestures/index.ts +0 -227
- package/src/core/compose/features/gestures/longpress.ts +0 -383
- package/src/core/compose/features/gestures/pan.ts +0 -424
- package/src/core/compose/features/gestures/pinch.ts +0 -475
- package/src/core/compose/features/gestures/rotate.ts +0 -485
- package/src/core/compose/features/gestures/swipe.ts +0 -492
- package/src/core/compose/features/gestures/tap.ts +0 -334
- package/src/core/gestures/longpress.ts +0 -68
- package/src/core/gestures/manager.ts +0 -418
- package/src/core/gestures/pan.ts +0 -48
- package/src/core/gestures/pinch.ts +0 -58
- package/src/core/gestures/rotate.ts +0 -58
- package/src/core/gestures/swipe.ts +0 -66
- package/src/core/gestures/tap.ts +0 -45
- package/src/core/gestures/types.ts +0 -387
- package/src/core/gestures/utils.ts +0 -128
- package/src/core/index.ts +0 -43
- package/src/core/layout/config.ts +0 -102
- package/src/core/layout/index.ts +0 -168
- package/src/core/layout/jsx.ts +0 -174
- package/src/core/layout/schema.ts +0 -1001
- package/src/core/layout/types.ts +0 -95
- package/src/core/viewport/constants.ts +0 -140
- package/src/core/viewport/features/base.ts +0 -73
- package/src/core/viewport/features/collection.ts +0 -882
- package/src/core/viewport/features/events.ts +0 -130
- package/src/core/viewport/features/item-size.ts +0 -271
- package/src/core/viewport/features/loading.ts +0 -263
- package/src/core/viewport/features/momentum.ts +0 -260
- package/src/core/viewport/features/performance.ts +0 -161
- package/src/core/viewport/features/placeholders.ts +0 -335
- package/src/core/viewport/features/rendering.ts +0 -568
- package/src/core/viewport/features/scrollbar.ts +0 -434
- package/src/core/viewport/features/scrolling.ts +0 -618
- package/src/core/viewport/features/utils.ts +0 -88
- package/src/core/viewport/features/virtual.ts +0 -384
- package/src/core/viewport/types.ts +0 -133
- package/src/core/viewport/utils/speed-tracker.ts +0 -79
- package/src/core/viewport/viewport.ts +0 -246
- package/test/benchmarks/layout/advanced.test.ts +0 -656
- package/test/benchmarks/layout/comparison.test.ts +0 -519
- package/test/benchmarks/layout/performance-comparison.test.ts +0 -274
- package/test/benchmarks/layout/real-components.test.ts +0 -733
- package/test/benchmarks/layout/simple.test.ts +0 -321
- package/test/benchmarks/layout/stress.test.ts +0 -990
- package/test/collection/basic.test.ts +0 -304
- package/test/components/vlist-selection.test.ts +0 -240
- package/test/components/vlist.test.ts +0 -63
- package/test/core/collection/adapter.test.ts +0 -161
- package/test/core/collection/collection.test.ts +0 -394
- package/test/core/layout/layout.test.ts +0 -201
- package/test/utils/dom-helpers.ts +0 -275
- package/test/utils/performance-helpers.ts +0 -392
- package/tsconfig.json +0 -20
|
@@ -1,246 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Viewport - Core virtual scrolling engine
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
import type {
|
|
6
|
-
ViewportConfig,
|
|
7
|
-
ViewportContext,
|
|
8
|
-
ViewportComponent,
|
|
9
|
-
ItemRange,
|
|
10
|
-
ViewportInfo,
|
|
11
|
-
} from "./types";
|
|
12
|
-
import { pipe } from "mtrl";
|
|
13
|
-
import { withBase } from "./features/base";
|
|
14
|
-
import { withVirtual } from "./features/virtual";
|
|
15
|
-
import { withScrolling } from "./features/scrolling";
|
|
16
|
-
import { withScrollbar } from "./features/scrollbar";
|
|
17
|
-
import { withCollection } from "./features/collection";
|
|
18
|
-
import { withPlaceholders } from "./features/placeholders";
|
|
19
|
-
import { withRendering } from "./features/rendering";
|
|
20
|
-
import { withEvents } from "./features/events";
|
|
21
|
-
|
|
22
|
-
// Internal viewport state
|
|
23
|
-
interface ViewportState {
|
|
24
|
-
scrollPosition: number;
|
|
25
|
-
totalItems: number;
|
|
26
|
-
itemSize: number;
|
|
27
|
-
containerSize: number;
|
|
28
|
-
virtualTotalSize: number;
|
|
29
|
-
visibleRange: ItemRange;
|
|
30
|
-
itemsContainer: HTMLElement | null;
|
|
31
|
-
velocity: number;
|
|
32
|
-
scrollDirection: "forward" | "backward";
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Creates a viewport-enhanced component using composition
|
|
37
|
-
*
|
|
38
|
-
* @param config - Viewport configuration
|
|
39
|
-
* @returns Function that enhances a component with viewport capabilities
|
|
40
|
-
*/
|
|
41
|
-
export const createViewport = (config: ViewportConfig = {}) => {
|
|
42
|
-
return <T extends ViewportContext>(component: T): T & ViewportComponent => {
|
|
43
|
-
// No normalization needed - we'll use the nested structure directly
|
|
44
|
-
|
|
45
|
-
// Create shared viewport state
|
|
46
|
-
const state: ViewportState = {
|
|
47
|
-
scrollPosition: 0,
|
|
48
|
-
totalItems: component.totalItems || 0,
|
|
49
|
-
itemSize: config.virtual?.itemSize || 50,
|
|
50
|
-
containerSize: 0,
|
|
51
|
-
virtualTotalSize: 0,
|
|
52
|
-
visibleRange: { start: 0, end: 0 },
|
|
53
|
-
itemsContainer: null,
|
|
54
|
-
velocity: 0,
|
|
55
|
-
scrollDirection: "forward",
|
|
56
|
-
};
|
|
57
|
-
|
|
58
|
-
// Create base viewport API
|
|
59
|
-
const viewportAPI = {
|
|
60
|
-
// Core API
|
|
61
|
-
initialize: () => {
|
|
62
|
-
// console.log("[Viewport] Initializing with state:", {
|
|
63
|
-
// element: !!component.element,
|
|
64
|
-
// totalItems: component.totalItems,
|
|
65
|
-
// itemSize: config.virtual?.itemSize,
|
|
66
|
-
// });
|
|
67
|
-
|
|
68
|
-
// Initialize container size
|
|
69
|
-
if (component.element) {
|
|
70
|
-
state.containerSize =
|
|
71
|
-
config.scrolling?.orientation === "horizontal"
|
|
72
|
-
? component.element.offsetWidth
|
|
73
|
-
: component.element.offsetHeight;
|
|
74
|
-
|
|
75
|
-
// console.log("[Viewport] Container size:", state.containerSize);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
// Calculate initial virtual size
|
|
79
|
-
state.virtualTotalSize = state.totalItems * state.itemSize;
|
|
80
|
-
|
|
81
|
-
// Calculate initial visible range
|
|
82
|
-
state.visibleRange = calculateVisibleRange(state.scrollPosition);
|
|
83
|
-
|
|
84
|
-
// console.log("[Viewport] Initial state:", {
|
|
85
|
-
// containerSize: state.containerSize,
|
|
86
|
-
// virtualTotalSize: state.virtualTotalSize,
|
|
87
|
-
// visibleRange: state.visibleRange,
|
|
88
|
-
// });
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
destroy: () => {
|
|
92
|
-
// Cleanup will be handled by features
|
|
93
|
-
},
|
|
94
|
-
|
|
95
|
-
updateViewport: () => {
|
|
96
|
-
// Will be implemented by rendering feature
|
|
97
|
-
},
|
|
98
|
-
|
|
99
|
-
// Scrolling API (will be overridden by scrolling feature)
|
|
100
|
-
scrollToIndex: (
|
|
101
|
-
index: number,
|
|
102
|
-
alignment?: "start" | "center" | "end"
|
|
103
|
-
) => {
|
|
104
|
-
// Will be implemented by scrolling feature
|
|
105
|
-
},
|
|
106
|
-
|
|
107
|
-
scrollToPosition: (position: number) => {
|
|
108
|
-
// Will be implemented by scrolling feature
|
|
109
|
-
},
|
|
110
|
-
|
|
111
|
-
getScrollPosition: () => state.scrollPosition,
|
|
112
|
-
|
|
113
|
-
// Info API
|
|
114
|
-
getVisibleRange: () => state.visibleRange,
|
|
115
|
-
|
|
116
|
-
getViewportInfo: (): ViewportInfo => ({
|
|
117
|
-
containerSize: state.containerSize,
|
|
118
|
-
totalVirtualSize: state.virtualTotalSize,
|
|
119
|
-
visibleRange: state.visibleRange,
|
|
120
|
-
virtualScrollPosition: state.scrollPosition,
|
|
121
|
-
}),
|
|
122
|
-
|
|
123
|
-
// Rendering API
|
|
124
|
-
renderItems: () => {
|
|
125
|
-
// Will be implemented by rendering feature
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
// Internal state (for features to access)
|
|
129
|
-
state,
|
|
130
|
-
};
|
|
131
|
-
|
|
132
|
-
// Helper function to calculate visible range
|
|
133
|
-
const calculateVisibleRange = (scrollPos: number): ItemRange => {
|
|
134
|
-
const itemSize = state.itemSize;
|
|
135
|
-
const start = Math.floor(scrollPos / itemSize);
|
|
136
|
-
const visibleCount = Math.ceil(state.containerSize / itemSize);
|
|
137
|
-
const end = Math.min(start + visibleCount, state.totalItems - 1);
|
|
138
|
-
|
|
139
|
-
return { start: Math.max(0, start), end: Math.max(0, end) };
|
|
140
|
-
};
|
|
141
|
-
|
|
142
|
-
// Add viewport API to component
|
|
143
|
-
const baseComponent = {
|
|
144
|
-
...component,
|
|
145
|
-
viewport: viewportAPI,
|
|
146
|
-
};
|
|
147
|
-
|
|
148
|
-
// Build the enhancement pipeline
|
|
149
|
-
const enhancers: Array<(c: any) => any> = [];
|
|
150
|
-
|
|
151
|
-
// Events system (always first - provides communication for other features)
|
|
152
|
-
enhancers.push(
|
|
153
|
-
withEvents({
|
|
154
|
-
debug: config.debug,
|
|
155
|
-
})
|
|
156
|
-
);
|
|
157
|
-
|
|
158
|
-
// Base setup (creates DOM structure)
|
|
159
|
-
enhancers.push(
|
|
160
|
-
withBase({
|
|
161
|
-
className: config.className,
|
|
162
|
-
orientation: config.scrolling?.orientation,
|
|
163
|
-
})
|
|
164
|
-
);
|
|
165
|
-
|
|
166
|
-
// Virtual scrolling (required for most features)
|
|
167
|
-
enhancers.push(
|
|
168
|
-
withVirtual({
|
|
169
|
-
itemSize: config.virtual?.itemSize,
|
|
170
|
-
overscan: config.virtual?.overscan,
|
|
171
|
-
orientation: config.scrolling?.orientation,
|
|
172
|
-
autoDetectItemSize: config.virtual?.autoDetectItemSize,
|
|
173
|
-
})
|
|
174
|
-
);
|
|
175
|
-
|
|
176
|
-
// Scrolling behavior
|
|
177
|
-
enhancers.push(
|
|
178
|
-
withScrolling({
|
|
179
|
-
orientation: config.scrolling?.orientation,
|
|
180
|
-
sensitivity: config.scrolling?.sensitivity,
|
|
181
|
-
smoothing: config.scrolling?.animation,
|
|
182
|
-
})
|
|
183
|
-
);
|
|
184
|
-
|
|
185
|
-
// Scrollbar (optional)
|
|
186
|
-
if (config.scrollbar?.enabled !== false) {
|
|
187
|
-
enhancers.push(
|
|
188
|
-
withScrollbar({
|
|
189
|
-
enabled: true,
|
|
190
|
-
autoHide: config.scrollbar?.autoHide,
|
|
191
|
-
})
|
|
192
|
-
);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
// Add collection if configured
|
|
196
|
-
if (config.collection?.adapter) {
|
|
197
|
-
enhancers.push(
|
|
198
|
-
withCollection({
|
|
199
|
-
collection: config.collection.adapter,
|
|
200
|
-
rangeSize: config.pagination?.limit,
|
|
201
|
-
strategy: config.pagination?.strategy as
|
|
202
|
-
| "offset"
|
|
203
|
-
| "page"
|
|
204
|
-
| "cursor"
|
|
205
|
-
| undefined,
|
|
206
|
-
transform: config.collection?.transform,
|
|
207
|
-
cancelLoadThreshold: config.performance?.cancelLoadThreshold,
|
|
208
|
-
maxConcurrentRequests: config.performance?.maxConcurrentRequests,
|
|
209
|
-
enableRequestQueue: config.performance?.enableRequestQueue !== false,
|
|
210
|
-
})
|
|
211
|
-
);
|
|
212
|
-
}
|
|
213
|
-
|
|
214
|
-
// Placeholders (optional, requires collection)
|
|
215
|
-
if (config.collection?.adapter && config.placeholders?.enabled !== false) {
|
|
216
|
-
enhancers.push(
|
|
217
|
-
withPlaceholders({
|
|
218
|
-
enabled: true,
|
|
219
|
-
analyzeFirstLoad: config.placeholders?.analyzeFirstLoad ?? true,
|
|
220
|
-
maskCharacter: config.placeholders?.maskCharacter,
|
|
221
|
-
})
|
|
222
|
-
);
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
// Rendering (always last to have access to all features)
|
|
226
|
-
enhancers.push(
|
|
227
|
-
withRendering({
|
|
228
|
-
template: config.template,
|
|
229
|
-
overscan: config.virtual?.overscan,
|
|
230
|
-
})
|
|
231
|
-
);
|
|
232
|
-
|
|
233
|
-
// Compose all enhancers
|
|
234
|
-
const enhance = pipe(...enhancers);
|
|
235
|
-
|
|
236
|
-
// Apply enhancements
|
|
237
|
-
const enhanced = enhance(baseComponent);
|
|
238
|
-
|
|
239
|
-
// Auto-initialize if element is provided
|
|
240
|
-
if (enhanced.element) {
|
|
241
|
-
enhanced.viewport.initialize();
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
return enhanced as T & ViewportComponent;
|
|
245
|
-
};
|
|
246
|
-
};
|