@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,117 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { Children, useEffect, useRef, useState } from 'react';
3
+ import { PanResponder, ScrollView, Text, View } from 'react-native';
4
+ import { Button } from './button.js';
5
+ import { useControllableValue } from './internal/state.js';
6
+ import { Cluster } from './layout.js';
7
+ import { useTramaMessages } from './localization.js';
8
+ import { useTramaAppearance, useTramaTheme } from './theme.js';
9
+ export function Carousel({ index, defaultIndex, onIndexChange, loop, navigation, disabled, children, style, onLayout, ...props }) {
10
+ const { theme, direction, resolve } = useTramaAppearance();
11
+ const messages = useTramaMessages();
12
+ const slides = Children.toArray(children);
13
+ const total = slides.length;
14
+ const [owned, setIndex] = useControllableValue(index, defaultIndex ?? 0);
15
+ const current = Number.isFinite(owned) ? Math.min(Math.max(0, Math.round(owned)), Math.max(0, total - 1)) : 0;
16
+ const [width, setWidth] = useState(0);
17
+ const scroll = useRef(null);
18
+ const rtl = direction === 'rtl';
19
+ const controls = resolve(navigation, 'buttons');
20
+ const at = (rtl ? total - 1 - current : current) * width;
21
+ useEffect(() => {
22
+ if (width > 0 && total > 0)
23
+ scroll.current?.scrollTo({ x: at, animated: false });
24
+ }, [width, at, total]);
25
+ function choose(candidate, fromSwipe = false) {
26
+ if (disabled || total <= 1)
27
+ return;
28
+ const next = loop ? (candidate + total) % total : Math.max(0, Math.min(total - 1, candidate));
29
+ if (next === current)
30
+ return;
31
+ if (onIndexChange?.(next) !== false)
32
+ setIndex(next);
33
+ if (fromSwipe && index !== undefined)
34
+ scroll.current?.scrollTo({ x: at, animated: true });
35
+ }
36
+ const order = rtl ? [...slides].reverse() : slides;
37
+ return (_jsxs(View, { ...props, style: [{ gap: theme.space * 2, direction }, style], onLayout: (event) => {
38
+ setWidth(event.nativeEvent.layout.width);
39
+ onLayout?.(event);
40
+ }, children: [_jsx(ScrollView, { ref: scroll, horizontal: true, pagingEnabled: true, directionalLockEnabled: true, showsHorizontalScrollIndicator: false, scrollEnabled: !disabled && total > 1, style: { direction: 'ltr' }, onMomentumScrollEnd: (event) => {
41
+ if (!width)
42
+ return;
43
+ const physical = Math.round(event.nativeEvent.contentOffset.x / width);
44
+ choose(rtl ? total - 1 - physical : physical, true);
45
+ }, children: width > 0 &&
46
+ order.map((slide, position) => {
47
+ const logical = rtl ? total - 1 - position : position;
48
+ return (_jsx(View, { accessibilityElementsHidden: logical !== current, importantForAccessibility: logical === current ? 'auto' : 'no-hide-descendants', style: { width, direction }, children: slide }, position));
49
+ }) }), total > 1 && (controls === 'buttons' || controls === 'both') && (_jsxs(Cluster, { align: "center", children: [_jsx(Button, { variant: "outlined", disabled: disabled || (!loop && current === 0), onPress: () => choose(current - 1), children: messages.previous }), _jsx(Text, { accessibilityLiveRegion: "polite", style: { color: theme.colors.muted }, children: messages.pageOf(current + 1, total) }), _jsx(Button, { variant: "outlined", disabled: disabled || (!loop && current === total - 1), onPress: () => choose(current + 1), children: messages.next })] })), total > 1 && (controls === 'dots' || controls === 'both') && (_jsx(Cluster, { gap: "xs", align: "center", children: slides.map((_, slide) => (_jsx(Button, { size: "sm", variant: current === slide ? 'contained' : 'text', disabled: disabled, accessibilityLabel: messages.pageNumber(slide + 1), accessibilityState: { selected: current === slide }, onPress: () => choose(slide), children: "\u2022" }, slide))) }))] }));
50
+ }
51
+ export function CarouselItem(props) {
52
+ return _jsx(View, { ...props });
53
+ }
54
+ export function Splitter({ orientation, value, defaultValue = 50, min = 15, max = 85, step = 5, onValueChange, onValueCommit, disabled, handleLabel, children, style, onLayout, ...props }) {
55
+ const { theme, direction, resolve } = useTramaAppearance();
56
+ const messages = useTramaMessages();
57
+ const [owned, setValue] = useControllableValue(value, defaultValue);
58
+ const [extent, setExtent] = useState(0);
59
+ const [start, end, ...rest] = Children.toArray(children);
60
+ const vertical = resolve(orientation, 'horizontal') === 'vertical';
61
+ const low = Math.min(100, Math.max(0, min));
62
+ const high = Math.min(100, Math.max(low, max));
63
+ const limit = (next) => Math.min(high, Math.max(low, Math.round(next)));
64
+ const current = limit(Number.isFinite(owned) ? owned : 50);
65
+ const currentRef = useRef({ current, onValueCommit, extent, vertical, direction, disabled, change });
66
+ currentRef.current = { current, onValueCommit, extent, vertical, direction, disabled, change };
67
+ const movement = useRef({ start: current, last: current });
68
+ function change(candidate) {
69
+ const next = limit(candidate);
70
+ if (!disabled && current !== next && onValueChange?.(next) !== false) {
71
+ setValue(next);
72
+ return next;
73
+ }
74
+ return current;
75
+ }
76
+ const responder = useRef(PanResponder.create({
77
+ onMoveShouldSetPanResponder: (_event, gesture) => {
78
+ const state = currentRef.current;
79
+ return !state.disabled && state.extent > 44 && Math.abs(state.vertical ? gesture.dy : gesture.dx) > 3;
80
+ },
81
+ onPanResponderGrant: () => {
82
+ const { current } = currentRef.current;
83
+ movement.current = { start: current, last: current };
84
+ },
85
+ onPanResponderMove: (_event, gesture) => {
86
+ const { vertical, extent, direction, change } = currentRef.current;
87
+ const delta = vertical ? gesture.dy : gesture.dx * (direction === 'rtl' ? -1 : 1);
88
+ movement.current.last = change(movement.current.start + (delta / Math.max(1, extent - 44)) * 100);
89
+ },
90
+ onPanResponderRelease: () => currentRef.current.onValueCommit?.(movement.current.last),
91
+ })).current;
92
+ const available = Math.max(0, extent - 44);
93
+ const panes = rest.length ? (_jsxs(_Fragment, { children: [end, rest] })) : (end);
94
+ return (_jsxs(View, { ...props, onLayout: (event) => {
95
+ setExtent(vertical ? event.nativeEvent.layout.height : event.nativeEvent.layout.width);
96
+ onLayout?.(event);
97
+ }, style: [{ direction, flexDirection: vertical ? 'column' : 'row', minHeight: vertical ? 240 : undefined }, style], children: [_jsx(View, { style: [{ minWidth: 0, minHeight: 0 }, extent ? { flexBasis: (available * current) / 100 } : { flex: current }], children: start }), _jsx(View, { ...responder.panHandlers, accessible: true, accessibilityRole: "adjustable", accessibilityLabel: handleLabel ?? messages.resizePanels, accessibilityValue: { min: low, max: high, now: current }, accessibilityState: { disabled: Boolean(disabled) }, accessibilityActions: disabled ? undefined : [{ name: 'increment' }, { name: 'decrement' }], onAccessibilityAction: (event) => onValueCommit?.(change(current + Math.max(1, step) * (event.nativeEvent.actionName === 'increment' ? 1 : -1))), style: { flexBasis: 44, alignItems: 'center', justifyContent: 'center' }, children: _jsx(View, { style: {
98
+ width: vertical ? 32 : 3,
99
+ height: vertical ? 3 : 32,
100
+ backgroundColor: theme.colors.border,
101
+ borderRadius: 2,
102
+ } }) }), _jsx(View, { style: { flex: 1, minWidth: 0, minHeight: 0 }, children: panes })] }));
103
+ }
104
+ export function SplitterPane({ style, ...props }) {
105
+ const theme = useTramaTheme();
106
+ return (_jsx(View, { ...props, style: [
107
+ {
108
+ flex: 1,
109
+ minWidth: 0,
110
+ minHeight: 0,
111
+ backgroundColor: theme.colors.subtle,
112
+ borderRadius: theme.radius,
113
+ padding: theme.space * 3,
114
+ },
115
+ style,
116
+ ] }));
117
+ }
@@ -0,0 +1,17 @@
1
+ import { type ElementType, type ReactNode } from 'react';
2
+ import { type StyleProp, type TextStyle } from 'react-native';
3
+ import type { TramaTheme } from '../theme.js';
4
+ export declare function TextContent({ children, style }: {
5
+ children?: ReactNode;
6
+ style?: StyleProp<TextStyle>;
7
+ }): (bigint | Iterable<ReactNode> | Promise<string | number | bigint | boolean | import("react").ReactPortal | import("react").ReactElement<unknown, string | import("react").JSXElementConstructor<any>> | Iterable<ReactNode> | null | undefined> | import("react").JSX.Element)[] | null | undefined;
8
+ export declare function splitContent<Part extends string>(children: ReactNode, parts: Readonly<Record<Part, ElementType>>): {
9
+ body: ReactNode[];
10
+ named: Partial<Record<Part, ReactNode[]>>;
11
+ };
12
+ export declare function FieldMessage({ message, invalid, theme, nativeID, }: {
13
+ message: string;
14
+ invalid: boolean;
15
+ theme: Readonly<TramaTheme>;
16
+ nativeID?: string;
17
+ }): import("react").JSX.Element | null;
@@ -0,0 +1,24 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Children, isValidElement } from 'react';
3
+ import { Text } from 'react-native';
4
+ export function TextContent({ children, style }) {
5
+ return Children.map(children, (child) => typeof child === 'string' || typeof child === 'number' ? _jsx(Text, { style: style, children: child }) : child);
6
+ }
7
+ export function splitContent(children, parts) {
8
+ const entries = Object.entries(parts);
9
+ const named = {};
10
+ const body = [];
11
+ for (const child of Children.toArray(children)) {
12
+ const role = isValidElement(child) ? entries.find(([, component]) => child.type === component)?.[0] : undefined;
13
+ if (role === undefined)
14
+ body.push(child);
15
+ else
16
+ (named[role] ??= []).push(child);
17
+ }
18
+ return { body, named };
19
+ }
20
+ export function FieldMessage({ message, invalid, theme, nativeID, }) {
21
+ if (!message)
22
+ return null;
23
+ return (_jsx(Text, { nativeID: nativeID, accessibilityLiveRegion: invalid ? 'polite' : 'none', style: { color: invalid ? theme.colors.danger : theme.colors.muted, fontFamily: theme.fontFamily }, children: message }));
24
+ }
@@ -0,0 +1,16 @@
1
+ export type DragPoint = {
2
+ x: number;
3
+ y: number;
4
+ };
5
+ export type DragRectangle = DragPoint & {
6
+ width: number;
7
+ height: number;
8
+ };
9
+ export declare function withinDragRect(point: DragPoint, bounds: DragRectangle): boolean;
10
+ export declare function intersectDragRects(a: DragRectangle | undefined, b: DragRectangle | undefined): {
11
+ x: number;
12
+ y: number;
13
+ width: number;
14
+ height: number;
15
+ } | undefined;
16
+ export declare function edgeScrollSpeed(position: number, start: number, end: number, edgeSize?: number, speed?: number): number;
@@ -0,0 +1,25 @@
1
+ export function withinDragRect(point, bounds) {
2
+ return (point.x >= bounds.x &&
3
+ point.x < bounds.x + bounds.width &&
4
+ point.y >= bounds.y &&
5
+ point.y < bounds.y + bounds.height);
6
+ }
7
+ export function intersectDragRects(a, b) {
8
+ if (!a || !b)
9
+ return undefined;
10
+ const x = Math.max(a.x, b.x);
11
+ const y = Math.max(a.y, b.y);
12
+ const width = Math.min(a.x + a.width, b.x + b.width) - x;
13
+ const height = Math.min(a.y + a.height, b.y + b.height) - y;
14
+ return width > 0 && height > 0 ? { x, y, width, height } : undefined;
15
+ }
16
+ export function edgeScrollSpeed(position, start, end, edgeSize = 42, speed = 18) {
17
+ const edge = Math.min(edgeSize, (end - start) / 4);
18
+ if (edge < 1)
19
+ return 0;
20
+ if (position < start + edge)
21
+ return -Math.min(speed, (speed * (start + edge - position)) / edge);
22
+ if (position > end - edge)
23
+ return Math.min(speed, (speed * (position - end + edge)) / edge);
24
+ return 0;
25
+ }
@@ -0,0 +1,20 @@
1
+ export interface KeyboardCommandEvent {
2
+ key: string;
3
+ shiftKey?: boolean;
4
+ ctrlKey?: boolean;
5
+ metaKey?: boolean;
6
+ altKey?: boolean;
7
+ isComposing?: boolean;
8
+ repeat?: boolean;
9
+ }
10
+ export interface NativeKeyboardPayload {
11
+ keyCode: number;
12
+ unicodeChar?: string;
13
+ isAltPressed?: boolean;
14
+ isShiftPressed?: boolean;
15
+ isCtrlPressed?: boolean;
16
+ isMetaPressed?: boolean;
17
+ repeat?: boolean;
18
+ }
19
+ export declare function nativeKeyboardEvent(event: NativeKeyboardPayload, platform: 'ios' | 'android'): KeyboardCommandEvent | null;
20
+ export declare function matchesKeyboardShortcut(event: KeyboardCommandEvent, shortcut: string | undefined, apple: boolean): boolean;
@@ -0,0 +1,101 @@
1
+ const iosKeys = {
2
+ 40: 'Enter',
3
+ 41: 'Escape',
4
+ 43: 'Tab',
5
+ 44: ' ',
6
+ 74: 'Home',
7
+ 75: 'PageUp',
8
+ 77: 'End',
9
+ 78: 'PageDown',
10
+ 79: 'ArrowRight',
11
+ 80: 'ArrowLeft',
12
+ 81: 'ArrowDown',
13
+ 82: 'ArrowUp',
14
+ 88: 'Enter',
15
+ };
16
+ const androidKeys = {
17
+ 19: 'ArrowUp',
18
+ 20: 'ArrowDown',
19
+ 21: 'ArrowLeft',
20
+ 22: 'ArrowRight',
21
+ 23: 'Enter',
22
+ 61: 'Tab',
23
+ 62: ' ',
24
+ 66: 'Enter',
25
+ 92: 'PageUp',
26
+ 93: 'PageDown',
27
+ 111: 'Escape',
28
+ 122: 'Home',
29
+ 123: 'End',
30
+ 160: 'Enter',
31
+ };
32
+ export function nativeKeyboardEvent(event, platform) {
33
+ const ios = platform === 'ios';
34
+ const code = event.keyCode;
35
+ const keyIndex = code - (ios ? 4 : 29);
36
+ const letter = keyIndex >= 0 && keyIndex < 26 ? String.fromCharCode(97 + keyIndex) : undefined;
37
+ const digit = ios
38
+ ? code >= 30 && code <= 39
39
+ ? String((code - 29) % 10)
40
+ : undefined
41
+ : code >= 7 && code <= 16
42
+ ? String(code - 7)
43
+ : undefined;
44
+ const functionKey = ios && code >= 104 && code <= 115
45
+ ? `F${code - 91}`
46
+ : code >= (ios ? 58 : 131) && code <= (ios ? 69 : 142)
47
+ ? `F${code - (ios ? 57 : 130)}`
48
+ : undefined;
49
+ const printable = event.unicodeChar && event.unicodeChar.charCodeAt(0) >= 32 ? event.unicodeChar : undefined;
50
+ const key = (ios ? iosKeys : androidKeys)[code] ??
51
+ functionKey ??
52
+ (event.isCtrlPressed || event.isMetaPressed || event.isAltPressed
53
+ ? (letter ?? digit)
54
+ : (printable ?? letter ?? digit));
55
+ return key
56
+ ? {
57
+ key,
58
+ altKey: event.isAltPressed,
59
+ shiftKey: event.isShiftPressed,
60
+ ctrlKey: event.isCtrlPressed,
61
+ metaKey: event.isMetaPressed,
62
+ repeat: event.repeat,
63
+ }
64
+ : null;
65
+ }
66
+ export function matchesKeyboardShortcut(event, shortcut, apple) {
67
+ if (!shortcut || event.repeat || event.isComposing)
68
+ return false;
69
+ const tokens = shortcut
70
+ .toLowerCase()
71
+ .split('+')
72
+ .map((token) => token.trim());
73
+ const key = tokens.pop();
74
+ if (!key || !/^(?:[a-z0-9]|f(?:[1-9]|1\d|2[0-4])|enter|space|arrow(?:up|down|left|right))$/.test(key))
75
+ return false;
76
+ const flags = { ctrl: false, meta: false, alt: false, shift: false };
77
+ const names = {
78
+ mod: apple ? 'meta' : 'ctrl',
79
+ ctrl: 'ctrl',
80
+ control: 'ctrl',
81
+ cmd: 'meta',
82
+ meta: 'meta',
83
+ alt: 'alt',
84
+ option: 'alt',
85
+ shift: 'shift',
86
+ };
87
+ for (const token of tokens) {
88
+ if (!Object.hasOwn(names, token))
89
+ return false;
90
+ const modifier = names[token];
91
+ if (flags[modifier])
92
+ return false;
93
+ flags[modifier] = true;
94
+ }
95
+ return ((flags.ctrl || flags.meta || flags.alt || (key.startsWith('f') && key.length > 1)) &&
96
+ event.key.toLowerCase() === (key === 'space' ? ' ' : key) &&
97
+ flags.ctrl === Boolean(event.ctrlKey) &&
98
+ flags.meta === Boolean(event.metaKey) &&
99
+ flags.alt === Boolean(event.altKey) &&
100
+ flags.shift === Boolean(event.shiftKey));
101
+ }
@@ -0,0 +1 @@
1
+ export declare function useReducedMotion(): boolean;
@@ -0,0 +1,24 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { AccessibilityInfo } from 'react-native';
3
+ export function useReducedMotion() {
4
+ const [reduced, setReduced] = useState(true);
5
+ useEffect(() => {
6
+ let active = true;
7
+ let changed = false;
8
+ const subscription = AccessibilityInfo.addEventListener('reduceMotionChanged', (value) => {
9
+ changed = true;
10
+ setReduced(value);
11
+ });
12
+ void AccessibilityInfo.isReduceMotionEnabled()
13
+ .then((value) => {
14
+ if (active && !changed)
15
+ setReduced(value);
16
+ })
17
+ .catch(() => undefined);
18
+ return () => {
19
+ active = false;
20
+ subscription.remove();
21
+ };
22
+ }, []);
23
+ return reduced;
24
+ }
@@ -0,0 +1,4 @@
1
+ export declare function numberInputFormat(locale?: string): {
2
+ format: Intl.NumberFormat;
3
+ parse(text: string, exponent?: boolean): number | undefined;
4
+ };
@@ -0,0 +1,25 @@
1
+ export function numberInputFormat(locale) {
2
+ const format = new Intl.NumberFormat(locale, { useGrouping: false, maximumFractionDigits: 12 });
3
+ const decimal = format.formatToParts(1.1).find((part) => part.type === 'decimal')?.value ?? '.';
4
+ const minus = format.formatToParts(-1).find((part) => part.type === 'minusSign')?.value ?? '-';
5
+ const digits = Array.from({ length: 10 }, (_, digit) => format.format(digit));
6
+ return {
7
+ format,
8
+ parse(text, exponent = false) {
9
+ let normalized = text
10
+ .trim()
11
+ .replace(/[\u061c\u200e\u200f]/gu, '')
12
+ .replaceAll(decimal, '.')
13
+ .replaceAll(minus, '-');
14
+ digits.forEach((digit, index) => {
15
+ if (digit !== String(index))
16
+ normalized = normalized.replaceAll(digit, String(index));
17
+ });
18
+ const grammar = exponent ? /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)(?:e[+-]?\d+)?$/iu : /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/u;
19
+ if (!grammar.test(normalized))
20
+ return undefined;
21
+ const result = Number(normalized);
22
+ return Number.isFinite(result) ? result : undefined;
23
+ },
24
+ };
25
+ }
@@ -0,0 +1 @@
1
+ export declare function capturePointer(target: unknown, id: number): (() => void) | undefined;
@@ -0,0 +1,16 @@
1
+ export function capturePointer(target, id) {
2
+ if (!target || typeof target !== 'object' || !('setPointerCapture' in target))
3
+ return undefined;
4
+ const host = target;
5
+ try {
6
+ host.setPointerCapture(id);
7
+ }
8
+ catch {
9
+ // The pointer can end before the browser grants capture.
10
+ return undefined;
11
+ }
12
+ return () => {
13
+ if (host.hasPointerCapture(id))
14
+ host.releasePointerCapture(id);
15
+ };
16
+ }
@@ -0,0 +1,6 @@
1
+ export declare function useControllableValue<T>(value: T | undefined, initial: T, onChange?: (next: T) => void): readonly [T, (next: T) => void];
2
+ export declare function useFieldValidation(explicit: string, constraint: string, disabled: boolean): {
3
+ message: string;
4
+ checkValidity: () => boolean;
5
+ reportValidity(): boolean;
6
+ };
@@ -0,0 +1,28 @@
1
+ import { useState } from 'react';
2
+ export function useControllableValue(value, initial, onChange) {
3
+ const [uncontrolled, setUncontrolled] = useState(initial);
4
+ if (value !== undefined && !Object.is(value, uncontrolled))
5
+ setUncontrolled(value);
6
+ const current = value === undefined ? uncontrolled : value;
7
+ function request(next) {
8
+ if (Object.is(current, next))
9
+ return;
10
+ if (value === undefined)
11
+ setUncontrolled(next);
12
+ onChange?.(next);
13
+ }
14
+ return [current, request];
15
+ }
16
+ export function useFieldValidation(explicit, constraint, disabled) {
17
+ const [revealed, setRevealed] = useState(false);
18
+ const message = disabled ? '' : explicit || (revealed ? constraint : '');
19
+ const valid = disabled || !(explicit || constraint);
20
+ return {
21
+ message,
22
+ checkValidity: () => valid,
23
+ reportValidity() {
24
+ setRevealed(!valid);
25
+ return valid;
26
+ },
27
+ };
28
+ }
@@ -0,0 +1,48 @@
1
+ import type { ComponentRef, Ref } from 'react';
2
+ import type { NativeSyntheticEvent, View, ViewProps } from 'react-native';
3
+ export type SystemDropKind = 'text' | 'url' | 'files';
4
+ export interface SystemDragFile {
5
+ uri: string;
6
+ name?: string;
7
+ type?: string;
8
+ }
9
+ export type SystemDragContent = {
10
+ kind: 'text' | 'url';
11
+ value: string;
12
+ } | {
13
+ kind: 'files';
14
+ files: readonly SystemDragFile[];
15
+ };
16
+ export type SystemDropItem = {
17
+ kind: 'text' | 'url';
18
+ value: string;
19
+ } | {
20
+ kind: 'file';
21
+ uri: string;
22
+ name: string;
23
+ type?: string;
24
+ size: number;
25
+ };
26
+ export interface SystemDropDetail {
27
+ operation: 'copy';
28
+ items: readonly SystemDropItem[];
29
+ localItem?: {
30
+ id: string;
31
+ type?: string;
32
+ };
33
+ }
34
+ export type SystemDropError = 'unavailable' | 'limit';
35
+ export interface SystemDragSurfaceProps extends ViewProps {
36
+ ref?: Ref<ComponentRef<typeof View>>;
37
+ dragPayload?: string;
38
+ dropKinds?: string;
39
+ onTramaDragEvent?: (event: NativeSyntheticEvent<{
40
+ phase: string;
41
+ payload: string;
42
+ }>) => void;
43
+ }
44
+ export declare function encodeSystemDrag(content: SystemDragContent | undefined, item: {
45
+ id: string;
46
+ type?: string;
47
+ }): string | undefined;
48
+ export declare function readSystemDrop(payload: string, kinds: readonly SystemDropKind[]): SystemDropDetail | undefined;
@@ -0,0 +1,93 @@
1
+ const maxCount = 20;
2
+ const maxText = 65_536;
3
+ const maxURI = 8192;
4
+ const maxFile = 64 * 1024 * 1024;
5
+ const maxDrop = 2 * maxFile;
6
+ function value(input, length) {
7
+ return typeof input === 'string' && input.length > 0 && input.length <= length;
8
+ }
9
+ function record(input) {
10
+ return !!input && typeof input === 'object' && !Array.isArray(input);
11
+ }
12
+ function url(input) {
13
+ if (!value(input, maxURI) || !/^https?:\/\//iu.test(input))
14
+ return false;
15
+ try {
16
+ return !!new URL(input).hostname && !/[\u0000-\u0020\u007f]/u.test(input);
17
+ }
18
+ catch {
19
+ return false;
20
+ }
21
+ }
22
+ export function encodeSystemDrag(content, item) {
23
+ if (!content)
24
+ return undefined;
25
+ const localItem = value(item.id, 256)
26
+ ? { id: item.id, type: value(item.type, 256) ? item.type : undefined }
27
+ : undefined;
28
+ if (content.kind === 'text' && value(content.value, maxText))
29
+ return JSON.stringify({ kind: 'text', value: content.value, localItem });
30
+ if (content.kind === 'url' && url(content.value))
31
+ return JSON.stringify({ kind: 'url', value: content.value, localItem });
32
+ if (content.kind !== 'files' || !content.files.length || content.files.length > maxCount)
33
+ return undefined;
34
+ const files = [];
35
+ for (const { uri, name, type } of content.files) {
36
+ if (!value(uri, maxURI) || !/^(?:content|file):\/\/[^\s]/iu.test(uri))
37
+ return undefined;
38
+ files.push({ uri, name: value(name, 256) ? name : undefined, type: value(type, 256) ? type : undefined });
39
+ }
40
+ return JSON.stringify({ kind: 'files', files, localItem });
41
+ }
42
+ export function readSystemDrop(payload, kinds) {
43
+ if (payload.length > 9_000_000)
44
+ return undefined;
45
+ let event;
46
+ try {
47
+ event = JSON.parse(payload);
48
+ }
49
+ catch {
50
+ return undefined;
51
+ }
52
+ if (!record(event) || !Array.isArray(event.items) || !event.items.length || event.items.length > maxCount)
53
+ return undefined;
54
+ const items = [];
55
+ let total = 0;
56
+ for (const item of event.items) {
57
+ if (!record(item))
58
+ return undefined;
59
+ if (item.kind === 'text' && kinds.includes('text') && value(item.value, maxText)) {
60
+ items.push({ kind: 'text', value: item.value });
61
+ }
62
+ else if (item.kind === 'url' && kinds.includes('url') && url(item.value)) {
63
+ items.push({ kind: 'url', value: item.value });
64
+ }
65
+ else if (item.kind === 'file' &&
66
+ kinds.includes('files') &&
67
+ value(item.uri, maxURI) &&
68
+ item.uri.startsWith('file:///') &&
69
+ value(item.name, 256) &&
70
+ typeof item.size === 'number' &&
71
+ Number.isSafeInteger(item.size) &&
72
+ item.size >= 0 &&
73
+ item.size <= maxFile) {
74
+ total += item.size;
75
+ if (total > maxDrop)
76
+ return undefined;
77
+ items.push({
78
+ kind: 'file',
79
+ uri: item.uri,
80
+ name: item.name,
81
+ type: value(item.type, 256) ? item.type : undefined,
82
+ size: item.size,
83
+ });
84
+ }
85
+ else
86
+ return undefined;
87
+ }
88
+ const local = event.localItem;
89
+ const localItem = record(local) && value(local.id, 256)
90
+ ? { id: local.id, type: value(local.type, 256) ? local.type : undefined }
91
+ : undefined;
92
+ return { operation: 'copy', items, localItem };
93
+ }
@@ -0,0 +1,56 @@
1
+ import { type PointerEvent, type View, type GestureResponderEvent } from 'react-native';
2
+ import { type DragPoint as Point } from './drag-geometry.js';
3
+ import { type TableCellAddress, type TableCellRange } from './table-model.js';
4
+ interface Options {
5
+ enabled: boolean;
6
+ layout: object;
7
+ rtl: boolean;
8
+ offsets: readonly number[];
9
+ utility: number;
10
+ columns: number;
11
+ rowCount: number;
12
+ pinnedRowsStart: number;
13
+ pinnedRowsEnd: number;
14
+ pinnedColumnsStart: number;
15
+ pinnedColumnsEnd: number;
16
+ position: () => {
17
+ x: number;
18
+ y: number;
19
+ };
20
+ scroll: (delta: Point) => void;
21
+ cell: (row: number, column: number) => TableCellAddress;
22
+ onSelect: (range: TableCellRange) => void;
23
+ }
24
+ export declare function useTableDrag(options: Options): {
25
+ armed: boolean;
26
+ preview: TableCellRange | null;
27
+ viewportRef: import("react").RefObject<View | null>;
28
+ bodyRef: import("react").RefObject<View | null>;
29
+ row(index: number, view: View | null): void;
30
+ toggle(): void;
31
+ cancel(): boolean;
32
+ suppressPress: () => boolean;
33
+ events: import("react-native").GestureResponderHandlers | {
34
+ onPointerMove(event: PointerEvent): void;
35
+ onPointerUp(event: PointerEvent): void;
36
+ onPointerCancel: () => boolean;
37
+ onPointerLeave: () => void;
38
+ };
39
+ cellEvents(cell: TableCellAddress): {
40
+ onPointerDown?: undefined;
41
+ onTouchStart?: undefined;
42
+ onTouchEnd?: undefined;
43
+ onTouchCancel?: undefined;
44
+ } | {
45
+ onPointerDown({ nativeEvent }: PointerEvent): void;
46
+ onTouchStart?: undefined;
47
+ onTouchEnd?: undefined;
48
+ onTouchCancel?: undefined;
49
+ } | {
50
+ onTouchStart(event: GestureResponderEvent): void;
51
+ onTouchEnd: () => void;
52
+ onTouchCancel: () => boolean;
53
+ onPointerDown?: undefined;
54
+ };
55
+ };
56
+ export {};