@trama-ui/react-native 0.0.0-stage → 0.7.0

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 (111) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +198 -2
  3. package/dist/accordion.d.ts +29 -0
  4. package/dist/accordion.js +137 -0
  5. package/dist/alert.d.ts +30 -0
  6. package/dist/alert.js +95 -0
  7. package/dist/avatar.d.ts +36 -0
  8. package/dist/avatar.js +91 -0
  9. package/dist/bars.d.ts +44 -0
  10. package/dist/bars.js +74 -0
  11. package/dist/button.d.ts +30 -0
  12. package/dist/button.js +90 -0
  13. package/dist/calendar.d.ts +71 -0
  14. package/dist/calendar.js +276 -0
  15. package/dist/card.d.ts +41 -0
  16. package/dist/card.js +139 -0
  17. package/dist/choices.d.ts +87 -0
  18. package/dist/choices.js +228 -0
  19. package/dist/collections.d.ts +131 -0
  20. package/dist/collections.js +230 -0
  21. package/dist/color-code.d.ts +37 -0
  22. package/dist/color-code.js +158 -0
  23. package/dist/compositions.d.ts +110 -0
  24. package/dist/compositions.js +190 -0
  25. package/dist/controls.d.ts +85 -0
  26. package/dist/controls.js +221 -0
  27. package/dist/drag-drop.d.ts +65 -0
  28. package/dist/drag-drop.js +482 -0
  29. package/dist/feedback.d.ts +30 -0
  30. package/dist/feedback.js +81 -0
  31. package/dist/file-upload.d.ts +67 -0
  32. package/dist/file-upload.js +251 -0
  33. package/dist/generated/icons.d.ts +1037 -0
  34. package/dist/generated/icons.js +3 -0
  35. package/dist/generated/tokens.d.ts +64 -0
  36. package/dist/generated/tokens.js +65 -0
  37. package/dist/icon.d.ts +31 -0
  38. package/dist/icon.js +28 -0
  39. package/dist/index.d.ts +43 -0
  40. package/dist/index.js +43 -0
  41. package/dist/input.d.ts +43 -0
  42. package/dist/input.js +115 -0
  43. package/dist/interactive-layout.d.ts +26 -0
  44. package/dist/interactive-layout.js +117 -0
  45. package/dist/internal/content.d.ts +17 -0
  46. package/dist/internal/content.js +24 -0
  47. package/dist/internal/drag-geometry.d.ts +16 -0
  48. package/dist/internal/drag-geometry.js +25 -0
  49. package/dist/internal/keyboard.d.ts +20 -0
  50. package/dist/internal/keyboard.js +101 -0
  51. package/dist/internal/motion.d.ts +1 -0
  52. package/dist/internal/motion.js +24 -0
  53. package/dist/internal/number-format.d.ts +4 -0
  54. package/dist/internal/number-format.js +25 -0
  55. package/dist/internal/pointer-capture.d.ts +1 -0
  56. package/dist/internal/pointer-capture.js +16 -0
  57. package/dist/internal/state.d.ts +6 -0
  58. package/dist/internal/state.js +28 -0
  59. package/dist/internal/system-drag.d.ts +48 -0
  60. package/dist/internal/system-drag.js +93 -0
  61. package/dist/internal/table-drag.d.ts +56 -0
  62. package/dist/internal/table-drag.js +237 -0
  63. package/dist/internal/table-editing.d.ts +49 -0
  64. package/dist/internal/table-editing.js +278 -0
  65. package/dist/internal/table-editor.d.ts +11 -0
  66. package/dist/internal/table-editor.js +31 -0
  67. package/dist/internal/table-grid.d.ts +44 -0
  68. package/dist/internal/table-grid.js +153 -0
  69. package/dist/internal/table-model.d.ts +132 -0
  70. package/dist/internal/table-model.js +231 -0
  71. package/dist/internal/table-source.d.ts +9 -0
  72. package/dist/internal/table-source.js +80 -0
  73. package/dist/internal/tour-target.d.ts +23 -0
  74. package/dist/internal/tour-target.js +81 -0
  75. package/dist/keyboard.d.ts +14 -0
  76. package/dist/keyboard.js +27 -0
  77. package/dist/layout.d.ts +35 -0
  78. package/dist/layout.js +77 -0
  79. package/dist/loader.d.ts +18 -0
  80. package/dist/loader.js +79 -0
  81. package/dist/localization.d.ts +106 -0
  82. package/dist/localization.js +310 -0
  83. package/dist/media.d.ts +35 -0
  84. package/dist/media.js +96 -0
  85. package/dist/menus.d.ts +103 -0
  86. package/dist/menus.js +422 -0
  87. package/dist/navigation.d.ts +111 -0
  88. package/dist/navigation.js +255 -0
  89. package/dist/overlays.d.ts +97 -0
  90. package/dist/overlays.js +364 -0
  91. package/dist/pill.d.ts +33 -0
  92. package/dist/pill.js +90 -0
  93. package/dist/progress.d.ts +27 -0
  94. package/dist/progress.js +154 -0
  95. package/dist/responsive.d.ts +15 -0
  96. package/dist/responsive.js +27 -0
  97. package/dist/select.d.ts +74 -0
  98. package/dist/select.js +181 -0
  99. package/dist/separator.d.ts +13 -0
  100. package/dist/separator.js +34 -0
  101. package/dist/switch.d.ts +26 -0
  102. package/dist/switch.js +69 -0
  103. package/dist/table.d.ts +122 -0
  104. package/dist/table.js +928 -0
  105. package/dist/text-fields.d.ts +39 -0
  106. package/dist/text-fields.js +134 -0
  107. package/dist/theme.d.ts +47 -0
  108. package/dist/theme.js +71 -0
  109. package/dist/transient.d.ts +80 -0
  110. package/dist/transient.js +273 -0
  111. package/package.json +50 -4
@@ -0,0 +1,482 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useMemo, useRef, useState, } from 'react';
3
+ import { PanResponder, Platform, Pressable, ScrollView, View, } from 'react-native';
4
+ import { TextContent } from './internal/content.js';
5
+ import { edgeScrollSpeed, intersectDragRects, withinDragRect, } from './internal/drag-geometry.js';
6
+ import { capturePointer } from './internal/pointer-capture.js';
7
+ import { encodeSystemDrag, readSystemDrop, } from './internal/system-drag.js';
8
+ import { useTramaMessages } from './localization.js';
9
+ import { DropdownMenu, DropdownMenuItem } from './menus.js';
10
+ import { useTramaTheme } from './theme.js';
11
+ const DragStateContext = createContext(null);
12
+ const DragAreaContext = createContext(null);
13
+ const SystemDragContext = createContext(undefined);
14
+ const SystemHoverContext = createContext(undefined);
15
+ const DragApiContext = createContext(null);
16
+ function measure(view) {
17
+ return new Promise((resolve) => {
18
+ if (!view) {
19
+ resolve(undefined);
20
+ return;
21
+ }
22
+ const timer = setTimeout(() => resolve(undefined), 160);
23
+ try {
24
+ view.measureInWindow((x, y, width, height) => {
25
+ clearTimeout(timer);
26
+ resolve(width > 0 && height > 0 ? { x, y, width, height } : undefined);
27
+ });
28
+ }
29
+ catch {
30
+ clearTimeout(timer);
31
+ resolve(undefined);
32
+ }
33
+ });
34
+ }
35
+ function locate(targets, point, item) {
36
+ for (let index = targets.length - 1; index >= 0; index--) {
37
+ const { target, bounds } = targets[index];
38
+ if (bounds && withinDragRect(point, bounds) && target.accepts(item))
39
+ return target;
40
+ }
41
+ return undefined;
42
+ }
43
+ export function DragDropProvider({ onDragStart, onDrop, onDragEnd, systemSurface, onSystemDrop, children, ...props }) {
44
+ const [state, setState] = useState(null);
45
+ const active = useRef(null);
46
+ const area = useRef(null);
47
+ const mounted = useRef(false);
48
+ const origin = useRef({ x: 0, y: 0 });
49
+ const targets = useRef(new Set());
50
+ const areas = useRef(new Set());
51
+ const snapshot = useRef({ targets: [], areas: [] });
52
+ const scrollFrame = useRef(null);
53
+ const callbacks = useRef({ onDragStart, onDrop, onDragEnd, onSystemDrop });
54
+ callbacks.current = { onDragStart, onDrop, onDragEnd, onSystemDrop };
55
+ useEffect(() => {
56
+ mounted.current = true;
57
+ return () => {
58
+ mounted.current = false;
59
+ active.current = null;
60
+ if (scrollFrame.current !== null)
61
+ cancelAnimationFrame(scrollFrame.current);
62
+ };
63
+ }, []);
64
+ const api = useMemo(() => {
65
+ async function scan() {
66
+ const [measuredAreas, measuredTargets] = await Promise.all([
67
+ Promise.all([...areas.current].map(async (area) => ({ area, bounds: await area.measure() }))),
68
+ Promise.all([...targets.current].map(async (target) => ({ target, bounds: await target.measure() }))),
69
+ ]);
70
+ const boundsByArea = new Map(measuredAreas.map(({ area, bounds }) => [area, bounds]));
71
+ function clip(bounds, area) {
72
+ for (let ancestor = area; bounds && ancestor; ancestor = ancestor.parent)
73
+ bounds = intersectDragRects(bounds, boundsByArea.get(ancestor));
74
+ return bounds;
75
+ }
76
+ return {
77
+ targets: measuredTargets.map(({ target, bounds }) => ({ target, bounds: clip(bounds, target.area) })),
78
+ areas: measuredAreas
79
+ .sort((a, b) => b.area.depth - a.area.depth)
80
+ .map(({ area, bounds }) => ({ area, bounds: clip(bounds, area.parent) })),
81
+ };
82
+ }
83
+ function expose(next) {
84
+ active.current = next;
85
+ setState(next && { ...next, point: { x: next.point.x - origin.current.x, y: next.point.y - origin.current.y } });
86
+ }
87
+ let gesture = 0;
88
+ let lastScan = -Infinity;
89
+ let scanning = false;
90
+ function stopScroll() {
91
+ if (scrollFrame.current !== null)
92
+ cancelAnimationFrame(scrollFrame.current);
93
+ scrollFrame.current = null;
94
+ }
95
+ function tick(now) {
96
+ const current = active.current;
97
+ if (!current || !areas.current.size) {
98
+ scrollFrame.current = null;
99
+ return;
100
+ }
101
+ for (const { area, bounds } of snapshot.current.areas) {
102
+ if (bounds &&
103
+ areas.current.has(area) &&
104
+ withinDragRect(current.point, bounds) &&
105
+ area.scroll(current.point, bounds))
106
+ break;
107
+ }
108
+ if (!scanning && now - lastScan >= 55) {
109
+ lastScan = now;
110
+ scanning = true;
111
+ const generation = gesture;
112
+ void scan()
113
+ .then((zones) => {
114
+ if (gesture !== generation || !active.current || !mounted.current)
115
+ return;
116
+ snapshot.current = zones;
117
+ const current = active.current;
118
+ const target = locate(zones.targets, current.point, current.item)?.id;
119
+ if (target !== current.target)
120
+ expose({ ...current, target });
121
+ })
122
+ .finally(() => {
123
+ if (gesture === generation)
124
+ scanning = false;
125
+ });
126
+ }
127
+ scrollFrame.current = requestAnimationFrame(tick);
128
+ }
129
+ return {
130
+ systemDrop(detail, target) {
131
+ callbacks.current.onSystemDrop?.({ ...detail, target });
132
+ },
133
+ register(target) {
134
+ targets.current.add(target);
135
+ return () => {
136
+ targets.current.delete(target);
137
+ };
138
+ },
139
+ registerArea(area) {
140
+ areas.current.add(area);
141
+ if (active.current && scrollFrame.current === null)
142
+ scrollFrame.current = requestAnimationFrame(tick);
143
+ return () => {
144
+ areas.current.delete(area);
145
+ };
146
+ },
147
+ start(item, point, preview) {
148
+ if (!mounted.current || active.current || callbacks.current.onDragStart?.(item) === false)
149
+ return false;
150
+ const generation = ++gesture;
151
+ snapshot.current = { targets: [], areas: [] };
152
+ origin.current = { x: 0, y: 0 };
153
+ expose({ item, point, preview });
154
+ lastScan = -Infinity;
155
+ scanning = true;
156
+ if (areas.current.size)
157
+ scrollFrame.current = requestAnimationFrame(tick);
158
+ void Promise.all([measure(area.current), scan()])
159
+ .then(([bounds, zones]) => {
160
+ if (!mounted.current || gesture !== generation || !active.current)
161
+ return;
162
+ origin.current = bounds ?? { x: 0, y: 0 };
163
+ snapshot.current = zones;
164
+ const current = active.current;
165
+ expose({ ...current, target: locate(zones.targets, current.point, item)?.id });
166
+ })
167
+ .finally(() => {
168
+ if (gesture === generation)
169
+ scanning = false;
170
+ });
171
+ return true;
172
+ },
173
+ move(point) {
174
+ const current = active.current;
175
+ if (current)
176
+ expose({ ...current, point, target: locate(snapshot.current.targets, point, current.item)?.id });
177
+ },
178
+ end(point) {
179
+ const current = active.current;
180
+ if (!current)
181
+ return;
182
+ const generation = ++gesture;
183
+ stopScroll();
184
+ expose(null);
185
+ void scan().then((zones) => {
186
+ if (!mounted.current || generation !== gesture)
187
+ return;
188
+ const target = locate(zones.targets, point, current.item);
189
+ const accepted = target && targets.current.has(target) && target.drop(current.item) !== false;
190
+ if (accepted)
191
+ callbacks.current.onDrop?.({ item: current.item, target: target.id });
192
+ callbacks.current.onDragEnd?.(current.item, accepted ? target.id : undefined);
193
+ });
194
+ },
195
+ cancel() {
196
+ if (!mounted.current)
197
+ return;
198
+ const item = active.current?.item;
199
+ gesture++;
200
+ stopScroll();
201
+ expose(null);
202
+ if (item)
203
+ callbacks.current.onDragEnd?.(item);
204
+ },
205
+ };
206
+ }, []);
207
+ return (_jsx(SystemDragContext.Provider, { value: systemSurface, children: _jsx(DragApiContext.Provider, { value: api, children: _jsx(DragStateContext.Provider, { value: state, children: _jsx(DragAreaContext.Provider, { value: null, children: _jsx(View, { ...props, ref: area, collapsable: false, children: children }) }) }) }) }));
208
+ }
209
+ export function DragScrollArea({ edgeSize = 42, maxStep = 18, horizontal, style, scrollEnabled = true, onScroll, onLayout, onContentSizeChange, children, ...props }) {
210
+ const api = useContext(DragApiContext);
211
+ const parent = useContext(DragAreaContext);
212
+ const viewport = useRef(null);
213
+ const scroll = useRef(null);
214
+ const sizes = useRef({ position: 0, viewport: 0, content: 0 });
215
+ const options = useRef({ horizontal, scrollEnabled, edgeSize, maxStep });
216
+ options.current = { horizontal, scrollEnabled, edgeSize, maxStep };
217
+ const area = useMemo(() => ({
218
+ parent,
219
+ depth: parent ? parent.depth + 1 : 0,
220
+ measure: () => measure(viewport.current),
221
+ scroll(point, visible) {
222
+ if (!scroll.current || !options.current.scrollEnabled)
223
+ return false;
224
+ const { horizontal, edgeSize, maxStep } = options.current;
225
+ const start = horizontal ? visible.x : visible.y;
226
+ const end = start + (horizontal ? visible.width : visible.height);
227
+ const edge = Number.isFinite(edgeSize) ? Math.max(0, edgeSize) : 42;
228
+ const step = Number.isFinite(maxStep) ? Math.max(0, Math.min(80, maxStep)) : 18;
229
+ const delta = edgeScrollSpeed(horizontal ? point.x : point.y, start, end, edge, step);
230
+ const value = sizes.current;
231
+ const next = Math.max(0, Math.min(value.content - value.viewport, value.position + delta));
232
+ if (Math.abs(next - value.position) < 0.1)
233
+ return false;
234
+ scroll.current.scrollTo({ x: horizontal ? next : 0, y: horizontal ? 0 : next, animated: false });
235
+ value.position = next;
236
+ return true;
237
+ },
238
+ }), [parent]);
239
+ useEffect(() => api?.registerArea(area), [api, area]);
240
+ return (_jsx(DragAreaContext.Provider, { value: area, children: _jsx(View, { ref: viewport, collapsable: false, style: [{ flexShrink: 1 }, style], children: _jsx(ScrollView, { ...props, ref: scroll, horizontal: horizontal, scrollEnabled: scrollEnabled, scrollEventThrottle: props.scrollEventThrottle ?? 16, onLayout: (event) => {
241
+ sizes.current.viewport = horizontal ? event.nativeEvent.layout.width : event.nativeEvent.layout.height;
242
+ onLayout?.(event);
243
+ }, onContentSizeChange: (width, height) => {
244
+ sizes.current.content = horizontal ? width : height;
245
+ onContentSizeChange?.(width, height);
246
+ }, onScroll: (event) => {
247
+ sizes.current.position = horizontal ? event.nativeEvent.contentOffset.x : event.nativeEvent.contentOffset.y;
248
+ onScroll?.(event);
249
+ }, children: children }) }) }));
250
+ }
251
+ export function DragHandle({ item, label, children, preview, systemDrag, disabled, style, onPress, onPressIn, ...props }) {
252
+ const api = useContext(DragApiContext);
253
+ const NativeSurface = useContext(SystemDragContext);
254
+ const theme = useTramaTheme();
255
+ const messages = useTramaMessages();
256
+ const activation = Boolean(onPress || props.onLongPress);
257
+ const source = useRef({ api, item, disabled, preview, activation });
258
+ source.current = { api, item, disabled, preview, activation };
259
+ const dragged = useRef(false);
260
+ const ownsGesture = useRef(false);
261
+ const lastPoint = useRef({ x: 0, y: 0 });
262
+ const reset = useRef(undefined);
263
+ const pointer = useRef(null);
264
+ function finish() {
265
+ pointer.current?.release?.();
266
+ pointer.current = null;
267
+ ownsGesture.current = false;
268
+ clearTimeout(reset.current);
269
+ reset.current = setTimeout(() => {
270
+ dragged.current = false;
271
+ }, 0);
272
+ }
273
+ useEffect(() => () => {
274
+ clearTimeout(reset.current);
275
+ pointer.current?.release?.();
276
+ if (ownsGesture.current)
277
+ api?.cancel();
278
+ }, [api]);
279
+ const responder = useRef(PanResponder.create({
280
+ onStartShouldSetPanResponderCapture: () => Boolean(source.current.api && !source.current.disabled && !source.current.activation),
281
+ onMoveShouldSetPanResponderCapture: (_event, gesture) => Boolean(source.current.api && !source.current.disabled && Math.hypot(gesture.dx, gesture.dy) > 5),
282
+ onPanResponderGrant: (event) => {
283
+ if (source.current.activation) {
284
+ const { api, item, preview } = source.current;
285
+ dragged.current = true;
286
+ lastPoint.current = { x: event.nativeEvent.pageX, y: event.nativeEvent.pageY };
287
+ ownsGesture.current = api?.start(item, lastPoint.current, preview) ?? false;
288
+ }
289
+ },
290
+ onPanResponderMove: (event, gesture) => {
291
+ const { api, item, preview, disabled } = source.current;
292
+ const { pageX, pageY } = event.nativeEvent;
293
+ lastPoint.current =
294
+ Number.isFinite(pageX) && Number.isFinite(pageY)
295
+ ? { x: pageX, y: pageY }
296
+ : { x: gesture.moveX, y: gesture.moveY };
297
+ if (!disabled && !dragged.current && Math.hypot(gesture.dx, gesture.dy) > 5) {
298
+ dragged.current = true;
299
+ ownsGesture.current = api?.start(item, lastPoint.current, preview) ?? false;
300
+ }
301
+ if (!ownsGesture.current)
302
+ return;
303
+ api?.move(lastPoint.current);
304
+ },
305
+ onPanResponderTerminationRequest: () => !ownsGesture.current,
306
+ onPanResponderRelease: ({ nativeEvent }) => {
307
+ const { pageX, pageY } = nativeEvent;
308
+ if (ownsGesture.current)
309
+ source.current.api?.end(Number.isFinite(pageX) && Number.isFinite(pageY) ? { x: pageX, y: pageY } : lastPoint.current);
310
+ finish();
311
+ },
312
+ onPanResponderTerminate: () => {
313
+ if (ownsGesture.current)
314
+ source.current.api?.cancel();
315
+ finish();
316
+ },
317
+ })).current;
318
+ const pointerEvents = {
319
+ onPointerDown({ nativeEvent, target }) {
320
+ if (disabled || !api || nativeEvent.button !== 0 || pointer.current)
321
+ return;
322
+ clearTimeout(reset.current);
323
+ dragged.current = false;
324
+ pointer.current = {
325
+ id: nativeEvent.pointerId,
326
+ point: { x: nativeEvent.clientX, y: nativeEvent.clientY },
327
+ release: capturePointer(target, nativeEvent.pointerId),
328
+ };
329
+ },
330
+ onPointerMove(event) {
331
+ const current = pointer.current;
332
+ if (!current || current.id !== event.nativeEvent.pointerId)
333
+ return;
334
+ const point = { x: event.nativeEvent.clientX, y: event.nativeEvent.clientY };
335
+ if (!dragged.current && Math.hypot(point.x - current.point.x, point.y - current.point.y) >= 6) {
336
+ dragged.current = true;
337
+ ownsGesture.current = !disabled && (api?.start(item, point, preview) ?? false);
338
+ if (ownsGesture.current && !current.release)
339
+ current.release = capturePointer(event.currentTarget, current.id);
340
+ }
341
+ if (ownsGesture.current) {
342
+ api?.move(point);
343
+ event.preventDefault();
344
+ }
345
+ },
346
+ onPointerUp(event) {
347
+ if (pointer.current?.id !== event.nativeEvent.pointerId)
348
+ return;
349
+ if (ownsGesture.current) {
350
+ api?.end({ x: event.nativeEvent.clientX, y: event.nativeEvent.clientY });
351
+ event.preventDefault();
352
+ }
353
+ finish();
354
+ },
355
+ onPointerCancel() {
356
+ if (ownsGesture.current)
357
+ api?.cancel();
358
+ finish();
359
+ },
360
+ onPointerLeave() {
361
+ if (!ownsGesture.current && pointer.current)
362
+ finish();
363
+ },
364
+ };
365
+ const handle = (_jsx(Pressable, { ...props, disabled: disabled, accessibilityRole: props.accessibilityRole ?? (onPress ? 'button' : undefined), accessibilityLabel: props.accessibilityLabel ?? label ?? messages.moveItem, onPressIn: (event) => {
366
+ if (Platform.OS !== 'web' && !ownsGesture.current)
367
+ dragged.current = false;
368
+ onPressIn?.(event);
369
+ }, onPress: onPress
370
+ ? (event) => {
371
+ if (!dragged.current)
372
+ onPress(event);
373
+ }
374
+ : undefined, style: (state) => [
375
+ { minHeight: 44, minWidth: 44, justifyContent: 'center', alignItems: 'center', userSelect: 'none' },
376
+ typeof style === 'function' ? style(state) : style,
377
+ ], children: _jsx(TextContent, { style: { color: theme.colors.text, userSelect: 'none' }, children: children ?? '⠿' }) }));
378
+ const dragPayload = !disabled && NativeSurface ? encodeSystemDrag(systemDrag, item) : undefined;
379
+ if (NativeSurface && dragPayload) {
380
+ return (_jsx(NativeSurface, { dragPayload: dragPayload, style: { minWidth: 0 }, children: handle }));
381
+ }
382
+ return (_jsx(View, { ...(Platform.OS === 'web' ? pointerEvents : responder.panHandlers), style: { minWidth: 0, ...(Platform.OS === 'web' && !disabled && api ? { touchAction: 'none' } : {}) }, children: handle }));
383
+ }
384
+ export function DropZone({ id, accepts, onDrop, disabled, systemDrop, onSystemDrop, onSystemDropError, children, style, ...props }) {
385
+ const api = useContext(DragApiContext);
386
+ const area = useContext(DragAreaContext);
387
+ const NativeSurface = useContext(SystemDragContext);
388
+ const state = useContext(DragStateContext);
389
+ const theme = useTramaTheme();
390
+ const view = useRef(null);
391
+ const latest = useRef({ accepts, onDrop, disabled });
392
+ latest.current = { accepts, onDrop, disabled };
393
+ useEffect(() => api?.register({
394
+ id,
395
+ area,
396
+ measure: () => measure(view.current),
397
+ accepts: (item) => !latest.current.disabled && (latest.current.accepts?.(item) ?? true),
398
+ drop: (item) => latest.current.onDrop?.(item),
399
+ }), [api, area, id]);
400
+ const [systemHovered, setSystemHovered] = useState(false);
401
+ const hovered = !disabled && (state?.target === id || (systemDrop?.length && systemHovered));
402
+ const Surface = NativeSurface && systemDrop?.length ? NativeSurface : View;
403
+ const systemEvents = NativeSurface && systemDrop?.length
404
+ ? {
405
+ dropKinds: disabled ? '' : systemDrop.join(','),
406
+ onTramaDragEvent({ nativeEvent }) {
407
+ if (nativeEvent.phase === 'enter' || nativeEvent.phase === 'leave')
408
+ setSystemHovered(nativeEvent.phase === 'enter' && !disabled);
409
+ if (disabled)
410
+ return;
411
+ if (nativeEvent.phase === 'error')
412
+ onSystemDropError?.(nativeEvent.payload === 'limit' ? 'limit' : 'unavailable');
413
+ if (nativeEvent.phase !== 'drop')
414
+ return;
415
+ const detail = readSystemDrop(nativeEvent.payload, systemDrop);
416
+ if (!detail)
417
+ onSystemDropError?.('unavailable');
418
+ else if (onSystemDrop?.(detail) !== false)
419
+ api?.systemDrop(detail, id);
420
+ },
421
+ }
422
+ : {};
423
+ return (_jsx(Surface, { ...props, ...systemEvents, ref: view, collapsable: false, style: [
424
+ {
425
+ padding: theme.space * 2,
426
+ borderRadius: theme.radius,
427
+ borderStyle: 'dashed',
428
+ borderWidth: 1,
429
+ borderColor: hovered ? theme.colors.accent : theme.colors.border,
430
+ backgroundColor: hovered ? theme.colors.subtle : 'transparent',
431
+ },
432
+ style,
433
+ ], children: _jsx(SystemHoverContext.Provider, { value: !disabled && systemHovered ? id : undefined, children: children }) }));
434
+ }
435
+ export function DragPreview({ renderItem, children, style, ...props }) {
436
+ const state = useContext(DragStateContext);
437
+ const theme = useTramaTheme();
438
+ if (!state)
439
+ return null;
440
+ return (_jsx(View, { ...props, pointerEvents: "none", importantForAccessibility: "no-hide-descendants", accessibilityElementsHidden: true, style: [
441
+ {
442
+ position: 'absolute',
443
+ top: state.point.y + 12,
444
+ left: state.point.x + 12,
445
+ zIndex: 50,
446
+ elevation: 8,
447
+ backgroundColor: theme.colors.surface,
448
+ borderRadius: theme.radius,
449
+ borderWidth: 1,
450
+ borderColor: theme.colors.border,
451
+ paddingHorizontal: theme.space * 3,
452
+ paddingVertical: theme.space * 2,
453
+ maxWidth: 220,
454
+ },
455
+ style,
456
+ ], children: _jsx(TextContent, { style: { color: theme.colors.text }, children: renderItem?.(state.item) ?? state.preview ?? children ?? state.item.id }) }));
457
+ }
458
+ export function DropIndicator({ target, visible, orientation = 'horizontal', style, ...props }) {
459
+ const state = useContext(DragStateContext);
460
+ const systemTarget = useContext(SystemHoverContext);
461
+ const theme = useTramaTheme();
462
+ if (!(visible ?? Boolean(target && (target === state?.target || target === systemTarget))))
463
+ return null;
464
+ return (_jsx(View, { ...props, accessible: false, pointerEvents: "none", style: [
465
+ { backgroundColor: theme.colors.accent, borderRadius: 2 },
466
+ orientation === 'horizontal' ? { height: 3 } : { width: 3, alignSelf: 'stretch' },
467
+ style,
468
+ ] }));
469
+ }
470
+ const MoveContext = createContext(undefined);
471
+ export function MoveMenu({ children, onMove, label, ...props }) {
472
+ const messages = useTramaMessages();
473
+ return (_jsx(MoveContext.Provider, { value: onMove, children: _jsx(DropdownMenu, { ...props, label: label ?? messages.moveItem, children: children }) }));
474
+ }
475
+ export function MoveOption({ value, onSelect, ...props }) {
476
+ const move = useContext(MoveContext);
477
+ return (_jsx(DropdownMenuItem, { ...props, value: value, onSelect: (detail) => {
478
+ if (onSelect?.(detail) === false)
479
+ return false;
480
+ move?.(value);
481
+ } }));
482
+ }
@@ -0,0 +1,30 @@
1
+ import { type ViewProps } from 'react-native';
2
+ import type { TramaResponsive } from './responsive.js';
3
+ import { type TramaColor, type TramaShape, type TramaSize } from './theme.js';
4
+ export interface SkeletonProps extends ViewProps {
5
+ loading?: boolean;
6
+ animation?: 'pulse' | 'wave' | 'none';
7
+ shape?: TramaResponsive<'text' | 'rectangle' | 'rounded' | 'circle'>;
8
+ width?: TramaResponsive<number | `${number}%`>;
9
+ height?: TramaResponsive<number | `${number}%`>;
10
+ lines?: TramaResponsive<number>;
11
+ lastLineWidth?: TramaResponsive<number | `${number}%`>;
12
+ }
13
+ export declare function Skeleton({ loading, animation, shape, width, height, lines, lastLineWidth, children, style, ...props }: SkeletonProps): import("react").JSX.Element;
14
+ export interface MeterProps extends ViewProps {
15
+ min?: number;
16
+ max?: number;
17
+ value?: number;
18
+ low?: number;
19
+ high?: number;
20
+ optimum?: number;
21
+ label?: string;
22
+ description?: string;
23
+ valueLabel?: string;
24
+ showValue?: TramaResponsive<boolean>;
25
+ size?: TramaResponsive<TramaSize>;
26
+ color?: TramaResponsive<TramaColor | 'auto'>;
27
+ variant?: TramaResponsive<'soft' | 'solid'>;
28
+ shape?: TramaResponsive<TramaShape>;
29
+ }
30
+ export declare function Meter({ min, max, value, low, high, optimum, label, description, valueLabel, showValue, size, color, variant, shape, style, ...props }: MeterProps): import("react").JSX.Element;
@@ -0,0 +1,81 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useRef, useState } from 'react';
3
+ import { Animated, Easing, Text, View } from 'react-native';
4
+ import { useReducedMotion } from './internal/motion.js';
5
+ import { Stack } from './layout.js';
6
+ import { getTone, sizeStep, useTramaAppearance, shapeRadius, } from './theme.js';
7
+ export function Skeleton({ loading = true, animation = 'pulse', shape, width, height, lines, lastLineWidth, children, style, ...props }) {
8
+ const { theme, direction, resolve } = useTramaAppearance();
9
+ const reduced = useReducedMotion();
10
+ const phase = useRef(new Animated.Value(0)).current;
11
+ const [extent, setExtent] = useState(0);
12
+ useEffect(() => {
13
+ if (!loading || animation === 'none' || reduced)
14
+ return;
15
+ const loop = Animated.loop(Animated.timing(phase, { toValue: 1, duration: 1500, easing: Easing.linear, useNativeDriver: true }));
16
+ loop.start();
17
+ return () => {
18
+ loop.stop();
19
+ phase.setValue(0);
20
+ };
21
+ }, [animation, loading, phase, reduced]);
22
+ const treatment = resolve(shape, 'text');
23
+ const defaultHeight = treatment === 'text' ? theme.fontSize : theme.space * 12;
24
+ const inline = resolve(width, treatment === 'circle' ? defaultHeight : '100%');
25
+ const block = resolve(height, defaultHeight);
26
+ const resolvedLines = resolve(lines, 1);
27
+ const count = treatment === 'text' && Number.isFinite(resolvedLines) ? Math.max(1, Math.min(20, Math.floor(resolvedLines))) : 1;
28
+ const radius = treatment === 'circle'
29
+ ? 9999
30
+ : treatment === 'rectangle'
31
+ ? 0
32
+ : treatment === 'rounded'
33
+ ? theme.radius
34
+ : theme.radius / 2;
35
+ return (_jsxs(View, { ...props, style: [{ direction }, style], children: [_jsx(View, { accessibilityElementsHidden: loading, importantForAccessibility: loading ? 'no-hide-descendants' : 'auto', style: { display: loading ? 'none' : 'flex' }, children: children }), loading && (_jsx(Animated.View, { accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", pointerEvents: "none", onLayout: (event) => setExtent(event.nativeEvent.layout.width), style: {
36
+ opacity: animation === 'pulse' && !reduced
37
+ ? phase.interpolate({ inputRange: [0, 0.5, 1], outputRange: [1, 0.5, 1] })
38
+ : 1,
39
+ gap: theme.space * 2,
40
+ }, children: Array.from({ length: count }, (_, index) => (_jsx(View, { style: {
41
+ width: count > 1 && index === count - 1 ? resolve(lastLineWidth, '72%') : inline,
42
+ height: block,
43
+ borderRadius: radius,
44
+ backgroundColor: theme.colors.border,
45
+ overflow: 'hidden',
46
+ }, children: animation === 'wave' && !reduced && extent > 0 && (_jsx(Animated.View, { style: {
47
+ width: extent * 0.26,
48
+ height: '100%',
49
+ backgroundColor: theme.colors.surface,
50
+ opacity: 0.4,
51
+ transform: [
52
+ {
53
+ translateX: phase.interpolate({
54
+ inputRange: [0, 1],
55
+ outputRange: direction === 'rtl' ? [extent * 0.26, -extent] : [-extent * 0.26, extent],
56
+ }),
57
+ },
58
+ ],
59
+ } })) }, index))) }))] }));
60
+ }
61
+ export function Meter({ min = 0, max = 100, value = 0, low, high, optimum, label, description, valueLabel, showValue, size, color, variant, shape, style, ...props }) {
62
+ const { theme, direction, resolve } = useTramaAppearance();
63
+ const floor = Number.isFinite(min) ? min : 0;
64
+ const ceiling = Number.isFinite(max) && max > floor ? max : floor + 1;
65
+ const clamped = Math.min(ceiling, Math.max(floor, Number.isFinite(value) ? value : floor));
66
+ const fraction = (clamped - floor) / (ceiling - floor);
67
+ const preferred = optimum ?? (floor + ceiling) / 2;
68
+ const zone = (amount) => low !== undefined && amount < low ? 0 : high !== undefined && amount > high ? 2 : 1;
69
+ const distance = Math.abs(zone(clamped) - zone(preferred));
70
+ const chosen = resolve(color, 'auto');
71
+ const tone = getTone(theme, chosen === 'auto' ? (distance === 0 ? 'green' : distance === 1 ? 'yellow' : 'red') : chosen);
72
+ const text = valueLabel ?? `${Math.round(fraction * 100)}%`;
73
+ const font = { color: theme.colors.text, fontFamily: theme.fontFamily, fontSize: theme.fontSize };
74
+ const borderRadius = shapeRadius(theme, resolve(shape, 'pill'));
75
+ return (_jsxs(Stack, { ...props, gap: "xs", accessible: true, accessibilityLabel: props.accessibilityLabel ?? label, accessibilityHint: props.accessibilityHint ?? description, accessibilityValue: { text }, style: [{ direction }, style], children: [_jsxs(View, { style: { flexDirection: 'row', justifyContent: 'space-between', flexWrap: 'wrap' }, children: [label && _jsx(Text, { style: font, children: label }), resolve(showValue, true) && _jsx(Text, { style: font, children: text })] }), _jsx(View, { style: {
76
+ height: theme.space * (2 + sizeStep[resolve(size, 'md')] * 0.5),
77
+ borderRadius,
78
+ backgroundColor: resolve(variant, 'soft') === 'soft' ? tone.soft : theme.colors.border,
79
+ overflow: 'hidden',
80
+ }, children: _jsx(View, { style: { width: `${fraction * 100}%`, height: '100%', backgroundColor: tone.solid, borderRadius } }) }), description && _jsx(Text, { style: { ...font, color: theme.colors.muted }, children: description })] }));
81
+ }
@@ -0,0 +1,67 @@
1
+ import { type ReactNode } from 'react';
2
+ import { type ViewProps } from 'react-native';
3
+ import { type ButtonProps } from './button.js';
4
+ import { type SystemDropError } from './drag-drop.js';
5
+ import type { FieldHandle } from './input.js';
6
+ import type { TramaResponsive } from './responsive.js';
7
+ export interface UploadFile {
8
+ id?: string;
9
+ uri: string;
10
+ name: string;
11
+ type?: string;
12
+ size?: number;
13
+ previewUri?: string;
14
+ progress?: number;
15
+ status?: 'queued' | 'uploading' | 'complete' | 'error';
16
+ error?: string;
17
+ }
18
+ export interface FilePickerOptions {
19
+ multiple: boolean;
20
+ accept?: string;
21
+ signal: AbortSignal;
22
+ }
23
+ export interface FileRejection {
24
+ file: UploadFile;
25
+ reason: 'type' | 'size' | 'limit';
26
+ }
27
+ export interface FileUploadProps extends ViewProps {
28
+ label?: string;
29
+ description?: string;
30
+ files?: readonly UploadFile[];
31
+ defaultFiles?: readonly UploadFile[];
32
+ onFilesChange?: (files: readonly UploadFile[]) => void | false;
33
+ chooseFiles?: (options: FilePickerOptions) => Promise<readonly UploadFile[] | null>;
34
+ onPickerError?: (error: unknown) => void;
35
+ systemDrop?: boolean;
36
+ onSystemDropError?: (error: SystemDropError) => void;
37
+ onReject?: (rejected: readonly FileRejection[]) => void;
38
+ onPreview?: (file: UploadFile) => void;
39
+ onRetry?: (file: UploadFile) => void;
40
+ onCancelUpload?: (file: UploadFile) => void;
41
+ renderItemMedia?: (file: UploadFile) => ReactNode;
42
+ name?: string;
43
+ required?: boolean;
44
+ disabled?: boolean;
45
+ readOnly?: boolean;
46
+ invalid?: boolean;
47
+ error?: string;
48
+ multiple?: boolean;
49
+ accept?: string;
50
+ maxFiles?: number;
51
+ maxFileSize?: number;
52
+ listStyle?: TramaResponsive<'list' | 'thumbnail'>;
53
+ }
54
+ export interface FileUploadHandle extends FieldHandle {
55
+ browse(): Promise<void>;
56
+ cancelBrowse(): boolean;
57
+ append(files: readonly UploadFile[]): void;
58
+ clear(): void;
59
+ }
60
+ export declare const FileUpload: import("react").ForwardRefExoticComponent<FileUploadProps & import("react").RefAttributes<FileUploadHandle>>;
61
+ export interface FileUploadDropzoneProps extends ViewProps {
62
+ id?: string;
63
+ }
64
+ export declare function FileUploadDropzone({ id, style, children, ...props }: FileUploadDropzoneProps): import("react").JSX.Element;
65
+ export declare function FileUploadTrigger({ children, onPress, ...props }: ButtonProps): import("react").JSX.Element;
66
+ export declare function FileUploadActions(props: ViewProps): import("react").JSX.Element;
67
+ export declare function FileUploadItemMedia(props: ViewProps): import("react").JSX.Element;