mtrl-addons 0.1.2 → 0.2.2
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/AI.md +28 -230
- package/CLAUDE.md +882 -0
- package/build.js +253 -24
- package/package.json +14 -4
- package/scripts/debug/vlist-selection.ts +121 -0
- package/src/components/index.ts +5 -41
- package/src/components/{list → vlist}/config.ts +66 -95
- package/src/components/vlist/constants.ts +23 -0
- package/src/components/vlist/features/api.ts +626 -0
- package/src/components/vlist/features/index.ts +10 -0
- package/src/components/vlist/features/selection.ts +436 -0
- package/src/components/vlist/features/viewport.ts +59 -0
- package/src/components/vlist/index.ts +17 -0
- package/src/components/{list → vlist}/types.ts +242 -32
- package/src/components/vlist/vlist.ts +92 -0
- package/src/core/compose/features/gestures/index.ts +227 -0
- package/src/core/compose/features/gestures/longpress.ts +383 -0
- package/src/core/compose/features/gestures/pan.ts +424 -0
- package/src/core/compose/features/gestures/pinch.ts +475 -0
- package/src/core/compose/features/gestures/rotate.ts +485 -0
- package/src/core/compose/features/gestures/swipe.ts +492 -0
- package/src/core/compose/features/gestures/tap.ts +334 -0
- package/src/core/compose/features/index.ts +2 -38
- package/src/core/compose/index.ts +13 -29
- package/src/core/gestures/index.ts +31 -0
- package/src/core/gestures/longpress.ts +68 -0
- package/src/core/gestures/manager.ts +418 -0
- package/src/core/gestures/pan.ts +48 -0
- package/src/core/gestures/pinch.ts +58 -0
- package/src/core/gestures/rotate.ts +58 -0
- package/src/core/gestures/swipe.ts +66 -0
- package/src/core/gestures/tap.ts +45 -0
- package/src/core/gestures/types.ts +387 -0
- package/src/core/gestures/utils.ts +128 -0
- package/src/core/index.ts +27 -151
- package/src/core/layout/schema.ts +153 -72
- package/src/core/layout/types.ts +5 -2
- package/src/core/viewport/constants.ts +145 -0
- package/src/core/viewport/features/base.ts +73 -0
- package/src/core/viewport/features/collection.ts +1182 -0
- package/src/core/viewport/features/events.ts +130 -0
- package/src/core/viewport/features/index.ts +20 -0
- package/src/core/{list-manager/features/viewport → viewport/features}/item-size.ts +31 -34
- package/src/core/{list-manager/features/viewport → viewport/features}/loading.ts +4 -4
- package/src/core/viewport/features/momentum.ts +269 -0
- package/src/core/viewport/features/placeholders.ts +335 -0
- package/src/core/viewport/features/rendering.ts +962 -0
- package/src/core/viewport/features/scrollbar.ts +434 -0
- package/src/core/viewport/features/scrolling.ts +634 -0
- package/src/core/viewport/features/utils.ts +94 -0
- package/src/core/viewport/features/virtual.ts +525 -0
- package/src/core/viewport/index.ts +31 -0
- package/src/core/viewport/types.ts +133 -0
- package/src/core/viewport/utils/speed-tracker.ts +79 -0
- package/src/core/viewport/viewport.ts +265 -0
- package/src/index.ts +0 -7
- package/src/styles/components/_vlist.scss +352 -0
- package/src/styles/index.scss +1 -1
- package/test/components/vlist-selection.test.ts +240 -0
- package/test/components/vlist.test.ts +63 -0
- package/test/core/collection/adapter.test.ts +161 -0
- package/bun.lock +0 -792
- package/src/components/list/api.ts +0 -314
- package/src/components/list/constants.ts +0 -56
- package/src/components/list/features/api.ts +0 -428
- package/src/components/list/features/index.ts +0 -31
- package/src/components/list/features/list-manager.ts +0 -502
- package/src/components/list/index.ts +0 -39
- package/src/components/list/list.ts +0 -234
- package/src/core/collection/base-collection.ts +0 -100
- package/src/core/collection/collection-composer.ts +0 -178
- package/src/core/collection/collection.ts +0 -745
- package/src/core/collection/constants.ts +0 -172
- package/src/core/collection/events.ts +0 -428
- package/src/core/collection/features/api/loading.ts +0 -279
- package/src/core/collection/features/operations/data-operations.ts +0 -147
- package/src/core/collection/index.ts +0 -104
- package/src/core/collection/state.ts +0 -497
- package/src/core/collection/types.ts +0 -404
- package/src/core/compose/features/collection.ts +0 -119
- package/src/core/compose/features/selection.ts +0 -213
- package/src/core/compose/features/styling.ts +0 -108
- package/src/core/list-manager/api.ts +0 -599
- package/src/core/list-manager/config.ts +0 -593
- package/src/core/list-manager/constants.ts +0 -268
- package/src/core/list-manager/features/api.ts +0 -58
- package/src/core/list-manager/features/collection/collection.ts +0 -705
- package/src/core/list-manager/features/collection/index.ts +0 -17
- package/src/core/list-manager/features/viewport/constants.ts +0 -42
- package/src/core/list-manager/features/viewport/index.ts +0 -16
- package/src/core/list-manager/features/viewport/placeholders.ts +0 -281
- package/src/core/list-manager/features/viewport/rendering.ts +0 -575
- package/src/core/list-manager/features/viewport/scrollbar.ts +0 -495
- package/src/core/list-manager/features/viewport/scrolling.ts +0 -795
- package/src/core/list-manager/features/viewport/template.ts +0 -220
- package/src/core/list-manager/features/viewport/viewport.ts +0 -654
- package/src/core/list-manager/features/viewport/virtual.ts +0 -309
- package/src/core/list-manager/index.ts +0 -279
- package/src/core/list-manager/list-manager.ts +0 -206
- package/src/core/list-manager/types.ts +0 -439
- package/src/core/list-manager/utils/calculations.ts +0 -290
- package/src/core/list-manager/utils/range-calculator.ts +0 -349
- package/src/core/list-manager/utils/speed-tracker.ts +0 -273
- package/src/styles/components/_list.scss +0 -244
- package/src/types/mtrl.d.ts +0 -6
- package/test/components/list.test.ts +0 -256
- package/test/core/collection/failed-ranges.test.ts +0 -270
- package/test/core/compose/features.test.ts +0 -183
- package/test/core/list-manager/features/collection.test.ts +0 -704
- package/test/core/list-manager/features/viewport.test.ts +0 -698
- package/test/core/list-manager/list-manager.test.ts +0 -593
- package/test/core/list-manager/utils/calculations.test.ts +0 -433
- package/test/core/list-manager/utils/range-calculator.test.ts +0 -569
- package/test/core/list-manager/utils/speed-tracker.test.ts +0 -530
- package/tsconfig.build.json +0 -23
- /package/src/components/{list → vlist}/features.ts +0 -0
- /package/src/core/{compose → viewport}/features/performance.ts +0 -0
|
@@ -1,220 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Viewport Template System
|
|
3
|
-
* Handles all template-related functionality for item rendering
|
|
4
|
-
* Part of the viewport feature as rendering is a display concern
|
|
5
|
-
*/
|
|
6
|
-
|
|
7
|
-
import { PLACEHOLDER } from "../../constants";
|
|
8
|
-
import { VIEWPORT_CONSTANTS } from "./constants";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Gets default item template if none provided
|
|
12
|
-
*/
|
|
13
|
-
export const getDefaultTemplate = <T = any>(): ((
|
|
14
|
-
item: T,
|
|
15
|
-
index: number
|
|
16
|
-
) => string) => {
|
|
17
|
-
return (item: T, index: number) => {
|
|
18
|
-
// Check if this is a placeholder item
|
|
19
|
-
const isPlaceholder =
|
|
20
|
-
item &&
|
|
21
|
-
typeof item === "object" &&
|
|
22
|
-
(item as any)[PLACEHOLDER.PLACEHOLDER_FLAG];
|
|
23
|
-
const placeholderClass = isPlaceholder
|
|
24
|
-
? ` ${VIEWPORT_CONSTANTS.PLACEHOLDER.CSS_CLASS}`
|
|
25
|
-
: "";
|
|
26
|
-
|
|
27
|
-
if (typeof item === "string") {
|
|
28
|
-
return `<div class="mtrl-list-item__content${placeholderClass}">${item}</div>`;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
if (typeof item === "object" && item !== null) {
|
|
32
|
-
// Try common properties
|
|
33
|
-
const obj = item as any;
|
|
34
|
-
const text =
|
|
35
|
-
obj.text || obj.title || obj.name || obj.label || String(item);
|
|
36
|
-
const subtitle = obj.subtitle || obj.description || obj.secondary;
|
|
37
|
-
|
|
38
|
-
return `
|
|
39
|
-
<div class="mtrl-list-item__content${placeholderClass}">
|
|
40
|
-
<div class="mtrl-list-item__primary">${text}</div>
|
|
41
|
-
${
|
|
42
|
-
subtitle
|
|
43
|
-
? `<div class="mtrl-list-item__secondary">${subtitle}</div>`
|
|
44
|
-
: ""
|
|
45
|
-
}
|
|
46
|
-
</div>
|
|
47
|
-
`;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
return `<div class="mtrl-list-item__content${placeholderClass}">${String(
|
|
51
|
-
item
|
|
52
|
-
)}</div>`;
|
|
53
|
-
};
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* Gets loading template
|
|
58
|
-
*/
|
|
59
|
-
export const getLoadingTemplate = (): string => {
|
|
60
|
-
return `
|
|
61
|
-
<div class="mtrl-list-item mtrl-list-item--loading">
|
|
62
|
-
<div class="mtrl-list-item__content">
|
|
63
|
-
<div class="mtrl-list-item__primary">Loading...</div>
|
|
64
|
-
</div>
|
|
65
|
-
</div>
|
|
66
|
-
`;
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Gets empty state template
|
|
71
|
-
*/
|
|
72
|
-
export const getEmptyTemplate = (): string => {
|
|
73
|
-
return `
|
|
74
|
-
<div class="mtrl-list-item mtrl-list-item--empty">
|
|
75
|
-
<div class="mtrl-list-item__content">
|
|
76
|
-
<div class="mtrl-list-item__primary">No items available</div>
|
|
77
|
-
</div>
|
|
78
|
-
</div>
|
|
79
|
-
`;
|
|
80
|
-
};
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* Gets error template
|
|
84
|
-
*/
|
|
85
|
-
export const getErrorTemplate = (error: Error): string => {
|
|
86
|
-
return `
|
|
87
|
-
<div class="mtrl-list-item mtrl-list-item--error">
|
|
88
|
-
<div class="mtrl-list-item__content">
|
|
89
|
-
<div class="mtrl-list-item__primary">Error: ${error.message}</div>
|
|
90
|
-
</div>
|
|
91
|
-
</div>
|
|
92
|
-
`;
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* Converts renderItem object structure to template function
|
|
97
|
-
* Handles object-based template definitions with variable substitution
|
|
98
|
-
*/
|
|
99
|
-
export const convertRenderItemToTemplate = (
|
|
100
|
-
renderItem: any
|
|
101
|
-
): ((item: any, index: number) => HTMLElement) => {
|
|
102
|
-
if (!renderItem || typeof renderItem !== "object") {
|
|
103
|
-
return getDefaultTemplate();
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
return (item: any, index: number): HTMLElement => {
|
|
107
|
-
return createElementFromTemplate(renderItem, item, index);
|
|
108
|
-
};
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
/**
|
|
112
|
-
* Creates DOM element from template object structure
|
|
113
|
-
*/
|
|
114
|
-
export const createElementFromTemplate = (
|
|
115
|
-
template: any,
|
|
116
|
-
item: any,
|
|
117
|
-
index: number
|
|
118
|
-
): HTMLElement => {
|
|
119
|
-
const {
|
|
120
|
-
tag = "div",
|
|
121
|
-
className,
|
|
122
|
-
attributes = {},
|
|
123
|
-
children = [],
|
|
124
|
-
textContent,
|
|
125
|
-
style,
|
|
126
|
-
} = template;
|
|
127
|
-
|
|
128
|
-
// Create the element
|
|
129
|
-
const element = document.createElement(tag);
|
|
130
|
-
|
|
131
|
-
// Apply className
|
|
132
|
-
if (className) {
|
|
133
|
-
element.className = substituteVariables(className, item, index);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
// Apply attributes
|
|
137
|
-
for (const [key, value] of Object.entries(attributes)) {
|
|
138
|
-
if (typeof value === "string") {
|
|
139
|
-
element.setAttribute(key, substituteVariables(value, item, index));
|
|
140
|
-
} else {
|
|
141
|
-
element.setAttribute(key, String(value));
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Apply textContent
|
|
146
|
-
if (textContent) {
|
|
147
|
-
element.textContent = substituteVariables(textContent, item, index);
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
// Apply inline styles
|
|
151
|
-
if (style && typeof style === "object") {
|
|
152
|
-
for (const [key, value] of Object.entries(style)) {
|
|
153
|
-
if (typeof value === "string") {
|
|
154
|
-
(element.style as any)[key] = substituteVariables(value, item, index);
|
|
155
|
-
} else {
|
|
156
|
-
(element.style as any)[key] = String(value);
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
// Process children recursively
|
|
162
|
-
if (Array.isArray(children)) {
|
|
163
|
-
children.forEach((child) => {
|
|
164
|
-
if (child && typeof child === "object") {
|
|
165
|
-
const childElement = createElementFromTemplate(child, item, index);
|
|
166
|
-
element.appendChild(childElement);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
return element;
|
|
172
|
-
};
|
|
173
|
-
|
|
174
|
-
/**
|
|
175
|
-
* Substitutes template variables like {{name}} with actual values
|
|
176
|
-
*/
|
|
177
|
-
export const substituteVariables = (
|
|
178
|
-
template: string,
|
|
179
|
-
item: any,
|
|
180
|
-
index: number
|
|
181
|
-
): string => {
|
|
182
|
-
if (!template || typeof template !== "string") {
|
|
183
|
-
return String(template || "");
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
return template.replace(/\{\{([^}]+)\}\}/g, (match, expression) => {
|
|
187
|
-
try {
|
|
188
|
-
// Create a simple context for evaluation
|
|
189
|
-
const context = { ...item, index, item };
|
|
190
|
-
|
|
191
|
-
// Handle simple property access (e.g., {{name}}, {{user.email}})
|
|
192
|
-
const value = expression.split(".").reduce((obj: any, prop: string) => {
|
|
193
|
-
return obj && obj[prop.trim()];
|
|
194
|
-
}, context);
|
|
195
|
-
|
|
196
|
-
// Handle fallback expressions (e.g., {{name || id}})
|
|
197
|
-
if (value === undefined && expression.includes("||")) {
|
|
198
|
-
const parts = expression.split("||").map((part) => part.trim());
|
|
199
|
-
for (const part of parts) {
|
|
200
|
-
const fallbackValue = part
|
|
201
|
-
.split(".")
|
|
202
|
-
.reduce((obj: any, prop: string) => {
|
|
203
|
-
return obj && obj[prop.trim()];
|
|
204
|
-
}, context);
|
|
205
|
-
if (fallbackValue !== undefined) {
|
|
206
|
-
return String(fallbackValue);
|
|
207
|
-
}
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
return value !== undefined ? String(value) : "";
|
|
212
|
-
} catch (error) {
|
|
213
|
-
console.warn(
|
|
214
|
-
`Template variable substitution failed for "${expression}":`,
|
|
215
|
-
error
|
|
216
|
-
);
|
|
217
|
-
return match; // Return original if substitution fails
|
|
218
|
-
}
|
|
219
|
-
});
|
|
220
|
-
};
|