@molecule/app-ui-react-native 2.0.1 → 2.2.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 (193) hide show
  1. package/README.md +81 -10
  2. package/dist/components/Alert.d.ts.map +1 -1
  3. package/dist/components/Alert.js +2 -3
  4. package/dist/components/Button.d.ts +3 -1
  5. package/dist/components/Button.d.ts.map +1 -1
  6. package/dist/components/Button.js +35 -3
  7. package/dist/components/Skeleton.d.ts.map +1 -1
  8. package/dist/components/Skeleton.js +13 -12
  9. package/dist/components/Spinner.js +2 -2
  10. package/dist/elements/Anchor.d.ts +15 -0
  11. package/dist/elements/Anchor.d.ts.map +1 -0
  12. package/dist/elements/Anchor.js +57 -0
  13. package/dist/elements/Box.d.ts +19 -0
  14. package/dist/elements/Box.d.ts.map +1 -0
  15. package/dist/elements/Box.js +157 -0
  16. package/dist/elements/CheckField.d.ts +18 -0
  17. package/dist/elements/CheckField.d.ts.map +1 -0
  18. package/dist/elements/CheckField.js +103 -0
  19. package/dist/elements/Disclosure.d.ts +11 -0
  20. package/dist/elements/Disclosure.d.ts.map +1 -0
  21. package/dist/elements/Disclosure.js +67 -0
  22. package/dist/elements/Fieldset.d.ts +16 -0
  23. package/dist/elements/Fieldset.d.ts.map +1 -0
  24. package/dist/elements/Fieldset.js +34 -0
  25. package/dist/elements/FileField.d.ts +12 -0
  26. package/dist/elements/FileField.d.ts.map +1 -0
  27. package/dist/elements/FileField.js +111 -0
  28. package/dist/elements/FormArea.d.ts +18 -0
  29. package/dist/elements/FormArea.d.ts.map +1 -0
  30. package/dist/elements/FormArea.js +42 -0
  31. package/dist/elements/GlyphIcon.d.ts +19 -0
  32. package/dist/elements/GlyphIcon.d.ts.map +1 -0
  33. package/dist/elements/GlyphIcon.js +43 -0
  34. package/dist/elements/Image.d.ts +17 -0
  35. package/dist/elements/Image.d.ts.map +1 -0
  36. package/dist/elements/Image.js +26 -0
  37. package/dist/elements/Link.d.ts +20 -0
  38. package/dist/elements/Link.d.ts.map +1 -0
  39. package/dist/elements/Link.js +53 -0
  40. package/dist/elements/Pressable.d.ts +18 -0
  41. package/dist/elements/Pressable.d.ts.map +1 -0
  42. package/dist/elements/Pressable.js +108 -0
  43. package/dist/elements/PulseDots.d.ts +15 -0
  44. package/dist/elements/PulseDots.d.ts.map +1 -0
  45. package/dist/elements/PulseDots.js +78 -0
  46. package/dist/elements/RangeField.d.ts +11 -0
  47. package/dist/elements/RangeField.d.ts.map +1 -0
  48. package/dist/elements/RangeField.js +266 -0
  49. package/dist/elements/RichText.d.ts +23 -0
  50. package/dist/elements/RichText.d.ts.map +1 -0
  51. package/dist/elements/RichText.js +55 -0
  52. package/dist/elements/Rule.d.ts +11 -0
  53. package/dist/elements/Rule.d.ts.map +1 -0
  54. package/dist/elements/Rule.js +19 -0
  55. package/dist/elements/ScrollArea.d.ts +21 -0
  56. package/dist/elements/ScrollArea.d.ts.map +1 -0
  57. package/dist/elements/ScrollArea.js +101 -0
  58. package/dist/elements/SelectAction.d.ts +20 -0
  59. package/dist/elements/SelectAction.d.ts.map +1 -0
  60. package/dist/elements/SelectAction.js +117 -0
  61. package/dist/elements/SelectField.d.ts +11 -0
  62. package/dist/elements/SelectField.d.ts.map +1 -0
  63. package/dist/elements/SelectField.js +220 -0
  64. package/dist/elements/SelectMenu.d.ts +19 -0
  65. package/dist/elements/SelectMenu.d.ts.map +1 -0
  66. package/dist/elements/SelectMenu.js +122 -0
  67. package/dist/elements/Svg.d.ts +155 -0
  68. package/dist/elements/Svg.d.ts.map +1 -0
  69. package/dist/elements/Svg.js +535 -0
  70. package/dist/elements/TableBox.d.ts +19 -0
  71. package/dist/elements/TableBox.d.ts.map +1 -0
  72. package/dist/elements/TableBox.js +87 -0
  73. package/dist/elements/TableCell.d.ts +16 -0
  74. package/dist/elements/TableCell.d.ts.map +1 -0
  75. package/dist/elements/TableCell.js +69 -0
  76. package/dist/elements/Text.d.ts +17 -0
  77. package/dist/elements/Text.d.ts.map +1 -0
  78. package/dist/elements/Text.js +96 -0
  79. package/dist/elements/TextField.d.ts +25 -0
  80. package/dist/elements/TextField.d.ts.map +1 -0
  81. package/dist/elements/TextField.js +257 -0
  82. package/dist/elements/accessibility.d.ts +36 -0
  83. package/dist/elements/accessibility.d.ts.map +1 -0
  84. package/dist/elements/accessibility.js +244 -0
  85. package/dist/elements/className.d.ts +45 -0
  86. package/dist/elements/className.d.ts.map +1 -0
  87. package/dist/elements/className.js +8 -0
  88. package/dist/elements/decimal.d.ts +5 -0
  89. package/dist/elements/decimal.d.ts.map +1 -0
  90. package/dist/elements/decimal.js +11 -0
  91. package/dist/elements/documentUrl.d.ts +35 -0
  92. package/dist/elements/documentUrl.d.ts.map +1 -0
  93. package/dist/elements/documentUrl.js +89 -0
  94. package/dist/elements/drag-drop.d.ts +11 -0
  95. package/dist/elements/drag-drop.d.ts.map +1 -0
  96. package/dist/elements/drag-drop.js +277 -0
  97. package/dist/elements/drag.d.ts +53 -0
  98. package/dist/elements/drag.d.ts.map +1 -0
  99. package/dist/elements/drag.js +520 -0
  100. package/dist/elements/dragModifiers.d.ts +22 -0
  101. package/dist/elements/dragModifiers.d.ts.map +1 -0
  102. package/dist/elements/dragModifiers.js +62 -0
  103. package/dist/elements/events.d.ts +45 -0
  104. package/dist/elements/events.d.ts.map +1 -0
  105. package/dist/elements/events.js +101 -0
  106. package/dist/elements/fieldBounds.d.ts +5 -0
  107. package/dist/elements/fieldBounds.d.ts.map +1 -0
  108. package/dist/elements/fieldBounds.js +60 -0
  109. package/dist/elements/flow.d.ts +36 -0
  110. package/dist/elements/flow.d.ts.map +1 -0
  111. package/dist/elements/flow.js +47 -0
  112. package/dist/elements/form.d.ts +48 -0
  113. package/dist/elements/form.d.ts.map +1 -0
  114. package/dist/elements/form.js +112 -0
  115. package/dist/elements/grid.d.ts +96 -0
  116. package/dist/elements/grid.d.ts.map +1 -0
  117. package/dist/elements/grid.js +272 -0
  118. package/dist/elements/index.d.ts +36 -0
  119. package/dist/elements/index.d.ts.map +1 -0
  120. package/dist/elements/index.js +35 -0
  121. package/dist/elements/inherited.d.ts +181 -0
  122. package/dist/elements/inherited.d.ts.map +1 -0
  123. package/dist/elements/inherited.js +512 -0
  124. package/dist/elements/labels.d.ts +39 -0
  125. package/dist/elements/labels.d.ts.map +1 -0
  126. package/dist/elements/labels.js +163 -0
  127. package/dist/elements/measure.d.ts +27 -0
  128. package/dist/elements/measure.d.ts.map +1 -0
  129. package/dist/elements/measure.js +24 -0
  130. package/dist/elements/outsidePress.d.ts +31 -0
  131. package/dist/elements/outsidePress.d.ts.map +1 -0
  132. package/dist/elements/outsidePress.js +94 -0
  133. package/dist/elements/paste.d.ts +22 -0
  134. package/dist/elements/paste.d.ts.map +1 -0
  135. package/dist/elements/paste.js +49 -0
  136. package/dist/elements/press.d.ts +41 -0
  137. package/dist/elements/press.d.ts.map +1 -0
  138. package/dist/elements/press.js +131 -0
  139. package/dist/elements/rangeKeyboard.d.ts +41 -0
  140. package/dist/elements/rangeKeyboard.d.ts.map +1 -0
  141. package/dist/elements/rangeKeyboard.js +58 -0
  142. package/dist/elements/rangeValues.d.ts +20 -0
  143. package/dist/elements/rangeValues.d.ts.map +1 -0
  144. package/dist/elements/rangeValues.js +101 -0
  145. package/dist/elements/ref.d.ts +16 -0
  146. package/dist/elements/ref.d.ts.map +1 -0
  147. package/dist/elements/ref.js +22 -0
  148. package/dist/elements/reveal.d.ts +8 -0
  149. package/dist/elements/reveal.d.ts.map +1 -0
  150. package/dist/elements/reveal.js +10 -0
  151. package/dist/elements/scrollReveal.d.ts +19 -0
  152. package/dist/elements/scrollReveal.d.ts.map +1 -0
  153. package/dist/elements/scrollReveal.js +52 -0
  154. package/dist/elements/selectOptions.d.ts +25 -0
  155. package/dist/elements/selectOptions.d.ts.map +1 -0
  156. package/dist/elements/selectOptions.js +60 -0
  157. package/dist/elements/style.d.ts +30 -0
  158. package/dist/elements/style.d.ts.map +1 -0
  159. package/dist/elements/style.js +368 -0
  160. package/dist/elements/svgHover.d.ts +41 -0
  161. package/dist/elements/svgHover.d.ts.map +1 -0
  162. package/dist/elements/svgHover.js +152 -0
  163. package/dist/elements/table.d.ts +52 -0
  164. package/dist/elements/table.d.ts.map +1 -0
  165. package/dist/elements/table.js +104 -0
  166. package/dist/elements/types.d.ts +25 -0
  167. package/dist/elements/types.d.ts.map +1 -0
  168. package/dist/elements/types.js +8 -0
  169. package/dist/elements/viewport.d.ts +53 -0
  170. package/dist/elements/viewport.d.ts.map +1 -0
  171. package/dist/elements/viewport.js +62 -0
  172. package/dist/elements/wheelZoom.d.ts +12 -0
  173. package/dist/elements/wheelZoom.d.ts.map +1 -0
  174. package/dist/elements/wheelZoom.js +8 -0
  175. package/dist/index.d.ts +9 -4
  176. package/dist/index.d.ts.map +1 -1
  177. package/dist/index.js +9 -4
  178. package/dist/platform/focus.d.ts +31 -0
  179. package/dist/platform/focus.d.ts.map +1 -0
  180. package/dist/platform/focus.js +93 -0
  181. package/dist/platform/index.d.ts +31 -0
  182. package/dist/platform/index.d.ts.map +1 -0
  183. package/dist/platform/index.js +179 -0
  184. package/dist/platform/layout.d.ts +13 -0
  185. package/dist/platform/layout.d.ts.map +1 -0
  186. package/dist/platform/layout.js +15 -0
  187. package/dist/platform/position.d.ts +5 -0
  188. package/dist/platform/position.d.ts.map +1 -0
  189. package/dist/platform/position.js +177 -0
  190. package/dist/platform/stack.d.ts +86 -0
  191. package/dist/platform/stack.d.ts.map +1 -0
  192. package/dist/platform/stack.js +318 -0
  193. package/package.json +67 -8
@@ -0,0 +1,18 @@
1
+ /**
2
+ * Pressable: an element the user activates.
3
+ *
4
+ * @module
5
+ */
6
+ import { type ReactElement } from 'react';
7
+ import type { PressableProps } from '@molecule/app-ui';
8
+ import type { ElementNode, ElementRefProps } from './types.js';
9
+ /**
10
+ * Something the user activates: a native `Pressable`. `onClick` fires on press, the mouse
11
+ * handlers on hover where the device has a pointer, and a string child is drawn in a `Text` with
12
+ * the pressable's text classes. Key handlers are web-only.
13
+ *
14
+ * @param props - See {@link PressableProps}.
15
+ * @returns The element.
16
+ */
17
+ export declare function Pressable(props: PressableProps<ElementNode> & ElementRefProps): ReactElement;
18
+ //# sourceMappingURL=Pressable.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Pressable.d.ts","sourceRoot":"","sources":["../../src/elements/Pressable.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAmC,MAAM,OAAO,CAAA;AAG1E,OAAO,KAAK,EAAc,cAAc,EAAE,MAAM,kBAAkB,CAAA;AA0BlE,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE9D;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG,eAAe,GAAG,YAAY,CA+G5F"}
@@ -0,0 +1,108 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Pressable: an element the user activates.
4
+ *
5
+ * @module
6
+ */
7
+ import { useCallback, useContext, useRef } from 'react';
8
+ import { Pressable as NativePressable, View } from 'react-native';
9
+ import { useOverlayTarget } from '../platform/focus.js';
10
+ import { nativeAccessibility } from './accessibility.js';
11
+ import { dragViewActions, useDragFrame, useNativeDrag } from './drag.js';
12
+ import { registerInline } from './flow.js';
13
+ import { DisabledScope, FormScope, useFormRegistration } from './form.js';
14
+ import { useGridCell } from './grid.js';
15
+ import { blockInInline, buttonText, dataAttributes, ElementScope, flowOf, isCssInline, layoutChildren, splitClasses, useInheritedText, useLineStart, useTagClasses, } from './inherited.js';
16
+ import { useLabelable, useReferencedLabelText } from './labels.js';
17
+ import { useOutsideTouch } from './outsidePress.js';
18
+ import { activatePress, AnchorPress, pressProps, useMousePress } from './press.js';
19
+ import { useNativeRef } from './ref.js';
20
+ import { nativeStyle } from './style.js';
21
+ /**
22
+ * Something the user activates: a native `Pressable`. `onClick` fires on press, the mouse
23
+ * handlers on hover where the device has a pointer, and a string child is drawn in a `Text` with
24
+ * the pressable's text classes. Key handlers are web-only.
25
+ *
26
+ * @param props - See {@link PressableProps}.
27
+ * @returns The element.
28
+ */
29
+ export function Pressable(props) {
30
+ const { as, type, title, className, style, webStyle, children, ref } = props;
31
+ const form = useContext(FormScope);
32
+ const fieldsetDisabled = useContext(DisabledScope);
33
+ const anchorPress = useContext(AnchorPress);
34
+ const disabled = props.disabled || (as === 'button' && fieldsetDisabled);
35
+ const owner = as === 'button' && !props.form ? form : null;
36
+ const activate = type === 'reset' ? owner?.reset : type === 'button' ? undefined : owner?.submit;
37
+ const click = () => {
38
+ if (!disabled)
39
+ activatePress(props.onClick, activate);
40
+ };
41
+ useFormRegistration(owner?.buttons, { type, disabled, activate: click });
42
+ const label = useLabelable(props.id, as === 'button' ? click : undefined);
43
+ const description = useReferencedLabelText(props['aria-describedby']);
44
+ const inherited = useInheritedText();
45
+ const split = splitClasses(useTagClasses(className, as), as === 'button' ? buttonText(inherited) : inherited, dataAttributes(props));
46
+ const text = split.text;
47
+ const accessibility = nativeAccessibility({ ...props, 'aria-label': props['aria-label'] ?? label ?? title }, as);
48
+ const interaction = useMousePress(props, pressProps(props, activate, anchorPress), undefined, !disabled);
49
+ const host = useRef(null);
50
+ const forward = useNativeRef(ref);
51
+ const setHost = useCallback((view) => {
52
+ host.current = view;
53
+ forward?.(view);
54
+ }, [forward]);
55
+ const target = useOverlayTarget(setHost, disabled || accessibility['aria-disabled'] ? undefined : 'control');
56
+ const onTouchStart = useOutsideTouch(host);
57
+ const [frame, dragRef] = useDragFrame(target.ref);
58
+ const press = {
59
+ ...interaction,
60
+ onFocus: (event) => {
61
+ if (!disabled)
62
+ target.remember();
63
+ interaction.onFocus?.(event);
64
+ },
65
+ onPress: disabled
66
+ ? undefined
67
+ : (event) => {
68
+ target.remember();
69
+ interaction.onPress?.(event);
70
+ },
71
+ };
72
+ const secondary = disabled ? undefined : props.secondaryAction;
73
+ const responder = useNativeDrag(frame, {
74
+ drag: disabled ? undefined : props.drag,
75
+ zoom: disabled ? undefined : props.zoom,
76
+ secondary,
77
+ press,
78
+ });
79
+ const view = {
80
+ ...accessibility,
81
+ onTouchStart: ref ? onTouchStart : undefined,
82
+ accessibilityHint: description ?? accessibility.accessibilityHint,
83
+ 'aria-disabled': disabled || accessibility['aria-disabled'],
84
+ className: split.view || undefined,
85
+ style: [nativeStyle(style, webStyle), useLineStart(pressableFlow(props)), useGridCell()],
86
+ };
87
+ const content = layoutChildren(children, split);
88
+ return (_jsx(ElementScope, { split: split, text: text, children: responder ? (_jsx(View, { ...view, ref: dragRef, collapsable: false, accessible: true, ...responder, ...dragViewActions(props, press, press.onPress
89
+ ? () => {
90
+ target.remember();
91
+ activatePress(props.onClick, activate, undefined, anchorPress);
92
+ }
93
+ : undefined, secondary), children: content })) : (_jsx(NativePressable, { ...view, ref: target.ref,
94
+ // A disabled button inside an anchor still consumes its tap without activating either.
95
+ disabled: disabled && anchorPress ? undefined : disabled, ...press, children: content })) }));
96
+ }
97
+ /**
98
+ * How a pressable flows: a button or a span is an inline box, a div or an li a block, unless its
99
+ * classes say otherwise.
100
+ *
101
+ * @param props - Its props.
102
+ * @returns Its inline kind.
103
+ */
104
+ function pressableFlow(props) {
105
+ const data = dataAttributes(props);
106
+ return blockInInline(flowOf(props.className, props.as === 'button' || props.as === 'span' ? 'box' : null, data), props.children, isCssInline(props.className, props.as === 'span', data));
107
+ }
108
+ registerInline(Pressable, pressableFlow);
@@ -0,0 +1,15 @@
1
+ /**
2
+ * PulseDots: decorative typing activity paint on React Native.
3
+ *
4
+ * @module
5
+ */
6
+ import { type ReactElement } from 'react';
7
+ import { type PulseDotsProps } from '@molecule/app-ui';
8
+ /**
9
+ * Draws three decorative dots with the ClassMap pulse and the OS reduced-motion preference.
10
+ *
11
+ * @param props - See {@link PulseDotsProps}.
12
+ * @returns Three animated views, with the caller providing their layout and status semantics.
13
+ */
14
+ export declare function PulseDots({ size, durationMs }: PulseDotsProps): ReactElement;
15
+ //# sourceMappingURL=PulseDots.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PulseDots.d.ts","sourceRoot":"","sources":["../../src/elements/PulseDots.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAiD,MAAM,OAAO,CAAA;AAGxF,OAAO,EAAqC,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAOzF;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,EAAE,IAAI,EAAE,UAAU,EAAE,EAAE,cAAc,GAAG,YAAY,CAoF5E"}
@@ -0,0 +1,78 @@
1
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
2
+ /**
3
+ * PulseDots: decorative typing activity paint on React Native.
4
+ *
5
+ * @module
6
+ */
7
+ import { useEffect, useLayoutEffect, useMemo, useState } from 'react';
8
+ import { AccessibilityInfo, Animated, Easing } from 'react-native';
9
+ import { DEFAULT_TYPING_PULSE, getClassMap } from '@molecule/app-ui';
10
+ import { registerInline } from './flow.js';
11
+ import { Circle, Svg } from './Svg.js';
12
+ const stationary = { opacity: 1, transform: [{ scale: 1 }] };
13
+ /**
14
+ * Draws three decorative dots with the ClassMap pulse and the OS reduced-motion preference.
15
+ *
16
+ * @param props - See {@link PulseDotsProps}.
17
+ * @returns Three animated views, with the caller providing their layout and status semantics.
18
+ */
19
+ export function PulseDots({ size, durationMs }) {
20
+ const { peakAt, restAt, stagger, dimOpacity, dimScale } = getClassMap().typingPulse ?? DEFAULT_TYPING_PULSE;
21
+ const [motionAllowed, setMotionAllowed] = useState(false);
22
+ const [dots] = useState(() => [0, 1, 2].map(() => new Animated.Value(1)));
23
+ const animate = motionAllowed && durationMs > 0 && Number.isFinite(durationMs);
24
+ const paint = useMemo(() => dots.map((dot) => ({
25
+ opacity: dot.interpolate({ inputRange: [0, 1], outputRange: [dimOpacity, 1] }),
26
+ transform: [{ scale: dot.interpolate({ inputRange: [0, 1], outputRange: [dimScale, 1] }) }],
27
+ })), [dots, dimOpacity, dimScale]);
28
+ useEffect(() => {
29
+ let useInitialPreference = true;
30
+ const subscription = AccessibilityInfo.addEventListener('reduceMotionChanged', (reduced) => {
31
+ useInitialPreference = false;
32
+ setMotionAllowed(!reduced);
33
+ });
34
+ void AccessibilityInfo.isReduceMotionEnabled().then((reduced) => {
35
+ if (useInitialPreference)
36
+ setMotionAllowed(!reduced);
37
+ }, (_error) => {
38
+ // Keep the stationary dots when the OS cannot supply its preference.
39
+ });
40
+ return () => {
41
+ useInitialPreference = false;
42
+ subscription.remove();
43
+ };
44
+ }, []);
45
+ useLayoutEffect(() => {
46
+ if (!animate)
47
+ return;
48
+ const easeInOut = Easing.bezier(0.42, 0, 0.58, 1);
49
+ // Timing goes from one to zero, leaving the dot fully lit during its initial delay.
50
+ // The easing encodes the complete cycle so the native driver can repeat it on its own.
51
+ const easing = (fraction) => {
52
+ if (fraction < peakAt)
53
+ return 1 - easeInOut(fraction / peakAt);
54
+ if (fraction < restAt)
55
+ return easeInOut((fraction - peakAt) / (restAt - peakAt));
56
+ return 1;
57
+ };
58
+ const loops = dots.map((dot, index) => {
59
+ dot.setValue(1);
60
+ const loop = Animated.loop(Animated.timing(dot, {
61
+ toValue: 0,
62
+ duration: durationMs,
63
+ delay: index * durationMs * stagger,
64
+ easing,
65
+ isInteraction: false,
66
+ useNativeDriver: true,
67
+ }));
68
+ loop.start();
69
+ return loop;
70
+ });
71
+ return () => {
72
+ for (const loop of loops)
73
+ loop.stop();
74
+ };
75
+ }, [animate, dots, durationMs, peakAt, restAt, stagger]);
76
+ return (_jsx(_Fragment, { children: dots.map((_, index) => (_jsx(Animated.View, { accessible: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", pointerEvents: "none", style: [{ width: size, height: size }, animate ? paint[index] : stationary], children: _jsx(Svg, { width: size, height: size, "aria-hidden": true, children: _jsx(Circle, { cx: size / 2, cy: size / 2, r: size / 2, fill: "currentColor" }) }) }, index))) }));
77
+ }
78
+ registerInline(PulseDots, () => 'box');
@@ -0,0 +1,11 @@
1
+ /**
2
+ * RangeField: a numeric platform slider with native forms and accessibility.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ElementHandle, RangeFieldProps } from '@molecule/app-ui';
7
+ /**
8
+ * Renders the platform's slider and exposes its logical value to the native form and keyboard.
9
+ */
10
+ export declare const RangeField: import("react").ForwardRefExoticComponent<RangeFieldProps & import("react").RefAttributes<ElementHandle>>;
11
+ //# sourceMappingURL=RangeField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RangeField.d.ts","sourceRoot":"","sources":["../../src/elements/RangeField.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAyBH,OAAO,KAAK,EAAE,aAAa,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAuDtE;;GAEG;AACH,eAAO,MAAM,UAAU,2GAgRtB,CAAA"}
@@ -0,0 +1,266 @@
1
+ import { createElement as _createElement } from "react";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ /**
4
+ * RangeField: a numeric platform slider with native forms and accessibility.
5
+ *
6
+ * @module
7
+ */
8
+ import sliderExport from '@react-native-community/slider';
9
+ import { forwardRef, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState, } from 'react';
10
+ import { AccessibilityInfo, findNodeHandle, Platform, UIManager, View, } from 'react-native';
11
+ import { nativeAccessibility } from './accessibility.js';
12
+ import { focusEvent, mouseEvent } from './events.js';
13
+ import { registerInline } from './flow.js';
14
+ import { DisabledScope, FormScope, useFieldValue, useFormRegistration } from './form.js';
15
+ import { useGridCell } from './grid.js';
16
+ import { dataAttributes, ElementScope, replacedFlow, splitClasses, useInheritedText, useLineStart, useTagClasses, } from './inherited.js';
17
+ import { useLabelable } from './labels.js';
18
+ import { getNativeKeyboardView, RANGE_DIRECTIONAL_KEYS, rangeKeyboardEvent, } from './rangeKeyboard.js';
19
+ import { finiteRangeNumber, rangeValues } from './rangeValues.js';
20
+ import { nativeStyle } from './style.js';
21
+ /** The slider component, also when Vite's ES module interop exposes its CommonJS exports object. */
22
+ function resolveSlider(exported) {
23
+ return 'default' in exported ? exported.default : exported;
24
+ }
25
+ const Slider = resolveSlider(sliderExport);
26
+ const ADJUST_ACTIONS = [{ name: 'increment' }, { name: 'decrement' }];
27
+ /** Gives the rotated track a vertical layout footprint. */
28
+ function verticalFrame(style) {
29
+ const { width, height, transform, ...rest } = style ?? {};
30
+ const steps = typeof transform === 'string' ? undefined : transform;
31
+ const quarterTurn = steps?.find((step) => 'rotate' in step && typeof step.rotate === 'string' && /^-?90deg$/.test(step.rotate));
32
+ return {
33
+ ...rest,
34
+ width: (quarterTurn ? height : width) ?? 40,
35
+ height: (quarterTurn ? width : height) ?? 160,
36
+ transform: quarterTurn ? steps?.filter((step) => step !== quarterTurn) : transform,
37
+ alignItems: 'center',
38
+ justifyContent: 'center',
39
+ };
40
+ }
41
+ /**
42
+ * Renders the platform's slider and exposes its logical value to the native form and keyboard.
43
+ */
44
+ export const RangeField = forwardRef(function RangeField(props, ref) {
45
+ const { min, max, step, value, defaultValue, name, onValueChange, style, webStyle } = props;
46
+ const base = finiteRangeNumber(min) ?? finiteRangeNumber(value) ?? finiteRangeNumber(defaultValue) ?? 0;
47
+ const range = useMemo(() => rangeValues(min, max, step, base), [min, max, step, base]);
48
+ const field = useFieldValue(value === undefined ? undefined : range.normalize(value), range.normalize(defaultValue));
49
+ const displayed = range.normalize(field.displayed);
50
+ const read = () => range.normalize(field.read());
51
+ useLayoutEffect(() => {
52
+ if (field.displayed !== displayed)
53
+ field.change(displayed, () => undefined);
54
+ }, [field, displayed]);
55
+ const form = useContext(FormScope);
56
+ const fieldsetDisabled = useContext(DisabledScope);
57
+ const disabled = fieldsetDisabled || props.disabled === true;
58
+ const accessibility = nativeAccessibility(props);
59
+ const hidden = accessibility['aria-hidden'] === true;
60
+ const canAdjust = !disabled && range.hasChoices;
61
+ const KeyboardView = useMemo(getNativeKeyboardView, []);
62
+ const keyboard = Boolean(KeyboardView);
63
+ const [focusRevision, setFocusRevision] = useState(0);
64
+ const [requestedFocus, requestFocus] = useState(false);
65
+ const focused = useRef(false);
66
+ const tabStop = (props.tabIndex ?? 0) >= 0;
67
+ const host = useRef(null);
68
+ const setHost = (view) => {
69
+ host.current = view;
70
+ };
71
+ const focusTarget = useCallback((target) => {
72
+ if (keyboard) {
73
+ const handle = findNodeHandle(target);
74
+ if (handle !== null)
75
+ UIManager.dispatchViewManagerCommand(handle, 'rnekKeyboardFocus', []);
76
+ }
77
+ else {
78
+ target.focus();
79
+ }
80
+ }, [keyboard]);
81
+ const focus = () => {
82
+ const target = host.current;
83
+ if (disabled || hidden || !target)
84
+ return;
85
+ if (keyboard && !tabStop && !requestedFocus)
86
+ requestFocus(true);
87
+ else
88
+ focusTarget(target);
89
+ };
90
+ useLayoutEffect(() => {
91
+ if (requestedFocus && host.current && !hidden && !disabled)
92
+ focusTarget(host.current);
93
+ }, [requestedFocus, hidden, disabled, focusTarget]);
94
+ const loseFocus = () => {
95
+ if (requestedFocus)
96
+ requestFocus(false);
97
+ if (!focused.current)
98
+ return;
99
+ focused.current = false;
100
+ props.onBlur?.(focusEvent());
101
+ };
102
+ const label = useLabelable(props.id, focus);
103
+ useFormRegistration(form?.fields, {
104
+ entries: () => (name && !disabled ? [[name, String(read())]] : []),
105
+ valid: () => true,
106
+ reset: field.reset,
107
+ focus,
108
+ });
109
+ const change = (next) => {
110
+ if (!canAdjust || next === read())
111
+ return false;
112
+ field.change(next, () => onValueChange?.(next));
113
+ return true;
114
+ };
115
+ const [trackLength, setTrackLength] = useState();
116
+ const [thumbRevision, setThumbRevision] = useState(0);
117
+ const [heldWrite, holdWrite] = useState();
118
+ const gesture = useRef(null);
119
+ useImperativeHandle(ref, () => ({
120
+ focus,
121
+ blur: () => {
122
+ if (!keyboard) {
123
+ host.current?.blur();
124
+ return;
125
+ }
126
+ // Removing the focused host releases hardware focus on both platforms.
127
+ gesture.current = null;
128
+ holdWrite(undefined);
129
+ loseFocus();
130
+ setFocusRevision((revision) => revision + 1);
131
+ },
132
+ }));
133
+ const trackKey = `${range.nativeMax}:${range.nativeStep}:${canAdjust}`;
134
+ useLayoutEffect(() => {
135
+ gesture.current = null;
136
+ holdWrite(undefined);
137
+ }, [trackKey]);
138
+ const write = range.toNative(displayed);
139
+ const trackChange = (position) => {
140
+ const active = gesture.current;
141
+ if (!active || !Number.isFinite(position))
142
+ return;
143
+ // Fabric may echo writes on Android. Only progress from an active gesture is an edit.
144
+ const next = range.fromNative(position);
145
+ if (active.last === next)
146
+ return;
147
+ active.last = next;
148
+ change(next);
149
+ };
150
+ const spoken = props['aria-valuetext'] ?? range.spoken(displayed);
151
+ const [announcement, setAnnouncement] = useState();
152
+ const lastAnnouncement = useRef(undefined);
153
+ useEffect(() => {
154
+ if (!announcement || announcement === lastAnnouncement.current)
155
+ return;
156
+ lastAnnouncement.current = announcement;
157
+ // React Native 0.79 skips TalkBack's selected event when accessibilityValue has text.
158
+ if (announcement.value === displayed)
159
+ AccessibilityInfo.announceForAccessibility(spoken);
160
+ }, [announcement, displayed, spoken]);
161
+ const vertical = props['aria-orientation'] === 'vertical';
162
+ const elementStyle = nativeStyle(style, webStyle);
163
+ const frame = vertical ? verticalFrame(elementStyle) : elementStyle;
164
+ const split = splitClasses(useTagClasses(props.className, 'input'), useInheritedText(), dataAttributes(props));
165
+ const line = useLineStart(replacedFlow(props.className, 'input'));
166
+ const grid = useGridCell();
167
+ const android = Platform.OS === 'android';
168
+ // Android's delegate truncates a numeric range to signed integers. TalkBack can suppress an
169
+ // action at the wrong bound unless fractional controls expose their value as text alone.
170
+ const exposeNumbers = !android || (props['aria-valuetext'] === undefined && range.hasIntegerAccessibilityValue);
171
+ const control = {
172
+ nativeID: props.id,
173
+ testID: accessibility.testID,
174
+ className: split.view || undefined,
175
+ style: [vertical ? frame : [{ minWidth: 40 }, frame], line, grid],
176
+ onLayout: vertical
177
+ ? ({ nativeEvent }) => setTrackLength(nativeEvent.layout.height)
178
+ : undefined,
179
+ accessible: !hidden,
180
+ focusable: !disabled && !hidden && (tabStop || requestedFocus),
181
+ accessibilityElementsHidden: hidden,
182
+ importantForAccessibility: hidden ? 'no-hide-descendants' : 'yes',
183
+ // `role` exposes an Android SeekBar and acknowledges the dispatched action. UIKit needs
184
+ // the legacy adjustable role to apply its adjustable accessibility trait.
185
+ role: android ? 'slider' : undefined,
186
+ accessibilityRole: android ? undefined : 'adjustable',
187
+ accessibilityLabel: props['aria-label'] ?? label,
188
+ accessibilityLanguage: accessibility.accessibilityLanguage,
189
+ lang: accessibility.lang,
190
+ accessibilityLabelledBy: props['aria-labelledby'],
191
+ accessibilityState: { disabled: disabled || accessibility['aria-disabled'] },
192
+ accessibilityValue: exposeNumbers
193
+ ? { min: range.low, max: range.high, now: displayed, text: spoken }
194
+ : { text: spoken },
195
+ accessibilityActions: canAdjust && !hidden
196
+ ? ADJUST_ACTIONS.filter(({ name }) => name === 'increment' ? displayed < range.high : displayed > range.low)
197
+ : [],
198
+ onAccessibilityAction: ({ nativeEvent }) => {
199
+ if (hidden ||
200
+ (nativeEvent.actionName !== 'increment' && nativeEvent.actionName !== 'decrement'))
201
+ return;
202
+ const next = range.nudge(read(), nativeEvent.actionName === 'increment' ? 1 : -1);
203
+ if (change(next) && android)
204
+ setAnnouncement({ value: next });
205
+ },
206
+ };
207
+ const slider = (_jsx(Slider, { minimumValue: 1, maximumValue: range.nativeMax, step: range.nativeStep, value: heldWrite ?? write, disabled: !canAdjust, tapToSeek: true, accessible: false, focusable: false, accessibilityElementsHidden: true, importantForAccessibility: "no-hide-descendants", style: vertical
208
+ ? {
209
+ width: trackLength ?? (typeof frame?.height === 'number' ? frame.height : 160),
210
+ transform: [{ rotate: '-90deg' }],
211
+ }
212
+ : { width: '100%' }, onSlidingStart: () => {
213
+ if (!canAdjust)
214
+ return;
215
+ gesture.current = { last: read() };
216
+ holdWrite(write);
217
+ }, onValueChange: trackChange, onSlidingComplete: (position) => {
218
+ if (!gesture.current)
219
+ return;
220
+ try {
221
+ trackChange(position);
222
+ // Resend the prop even when a rejecting parent leaves its value unchanged.
223
+ if (Number.isFinite(position) && range.fromNative(position) !== read()) {
224
+ setThumbRevision((revision) => revision + 1);
225
+ }
226
+ props.onClick?.(mouseEvent(undefined));
227
+ }
228
+ finally {
229
+ gesture.current = null;
230
+ holdWrite(undefined);
231
+ }
232
+ } }, `${trackKey}:${thumbRevision}`));
233
+ return (_jsx(ElementScope, { split: split, children: KeyboardView ? (_createElement(KeyboardView, { ...control, key: focusRevision, ref: setHost, canBeFocused: control.focusable === true, haloEffect: true, lockFocus: canAdjust ? RANGE_DIRECTIONAL_KEYS : 0, hasKeyDownPress: true, onKeyDownPress: (event) => {
234
+ if (disabled || hidden)
235
+ return;
236
+ const key = rangeKeyboardEvent(event);
237
+ props.onKeyDown?.(key);
238
+ if (key.defaultPrevented)
239
+ return;
240
+ switch (key.key) {
241
+ case 'ArrowUp':
242
+ case 'ArrowRight':
243
+ change(range.nudge(read(), 1));
244
+ break;
245
+ case 'ArrowDown':
246
+ case 'ArrowLeft':
247
+ change(range.nudge(read(), -1));
248
+ break;
249
+ case 'Home':
250
+ change(range.low);
251
+ break;
252
+ case 'End':
253
+ change(range.high);
254
+ break;
255
+ }
256
+ }, hasKeyUpPress: !!props.onKeyUp, onKeyUpPress: props.onKeyUp ? (event) => props.onKeyUp?.(rangeKeyboardEvent(event)) : undefined, hasOnFocusChanged: true, onFocusChange: ({ nativeEvent }) => {
257
+ if (nativeEvent.isFocused) {
258
+ focused.current = true;
259
+ props.onFocus?.(focusEvent());
260
+ }
261
+ else {
262
+ loseFocus();
263
+ }
264
+ } }, slider)) : (_jsx(View, { ...control, ref: setHost, children: slider })) }));
265
+ });
266
+ registerInline(RangeField, (props) => replacedFlow(props.className, 'input'));
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Rich catalog text on React Native.
3
+ *
4
+ * @module
5
+ */
6
+ import { type ReactElement } from 'react';
7
+ import type { RichNode } from '@molecule/app-i18n';
8
+ /** Props for {@link RichText}. */
9
+ export interface RichTextProps {
10
+ /** Result of a rich translation read. */
11
+ nodes: readonly RichNode[];
12
+ /** Classes on the surrounding container. */
13
+ className?: string;
14
+ }
15
+ /**
16
+ * Renders paragraphs, heading semantics, nested bullet lists and strong emphasis.
17
+ * A custom web catalog that needs unsupported markup logs a migration diagnostic.
18
+ *
19
+ * @param props - The rich translation and container classes.
20
+ * @returns The rich text inside its container.
21
+ */
22
+ export declare function RichText({ nodes, className }: RichTextProps): ReactElement;
23
+ //# sourceMappingURL=RichText.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RichText.d.ts","sourceRoot":"","sources":["../../src/elements/RichText.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,YAAY,EAA6B,MAAM,OAAO,CAAA;AAEpE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,oBAAoB,CAAA;AAOlD,kCAAkC;AAClC,MAAM,WAAW,aAAa;IAC5B,yCAAyC;IACzC,KAAK,EAAE,SAAS,QAAQ,EAAE,CAAA;IAC1B,4CAA4C;IAC5C,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,EAAE,aAAa,GAAG,YAAY,CAY1E"}
@@ -0,0 +1,55 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Rich catalog text on React Native.
4
+ *
5
+ * @module
6
+ */
7
+ import { useEffect } from 'react';
8
+ import { getLogger } from '@molecule/app-logger';
9
+ import { getClassMap } from '@molecule/app-ui';
10
+ import { Box } from './Box.js';
11
+ import { Text } from './Text.js';
12
+ /**
13
+ * Renders paragraphs, heading semantics, nested bullet lists and strong emphasis.
14
+ * A custom web catalog that needs unsupported markup logs a migration diagnostic.
15
+ *
16
+ * @param props - The rich translation and container classes.
17
+ * @returns The rich text inside its container.
18
+ */
19
+ export function RichText({ nodes, className }) {
20
+ const diagnostic = nodes.find((node) => node.kind === 'legacy-html')?.diagnostic;
21
+ useEffect(() => {
22
+ if (diagnostic)
23
+ getLogger('i18n').warn(diagnostic);
24
+ }, [diagnostic]);
25
+ const cm = getClassMap();
26
+ return (_jsx(Box, { as: "div", className: className, children: renderNodes(nodes, cm) }));
27
+ }
28
+ /**
29
+ * Renders the native equivalent of the portable tags. List markers are
30
+ * structural decoration, with the item content in its own wrapping column.
31
+ *
32
+ * @param nodes - The nodes at this level.
33
+ * @param cm - The active ClassMap for native layout and typography.
34
+ * @returns The native element children.
35
+ */
36
+ function renderNodes(nodes, cm) {
37
+ return nodes.map((node, index) => {
38
+ if (node.kind === 'text')
39
+ return node.text;
40
+ if (node.kind === 'legacy-html')
41
+ return null;
42
+ const children = renderNodes(node.children, cm);
43
+ if (node.tag === 'ul')
44
+ return (_jsx(Box, { as: "ul", children: children }, index));
45
+ if (node.tag === 'li') {
46
+ return (_jsxs(Box, { as: "li", className: cm.flex({ direction: 'row' }), children: [_jsx(Text, { as: "span", "aria-hidden": "true", children: '\u2022 ' }), _jsx(Box, { as: "div", className: cm.flex1, children: children })] }, index));
47
+ }
48
+ const className = node.tag === 'h2'
49
+ ? cm.cn(cm.textSize('xl'), cm.fontWeight('bold'), cm.sp('my', 2))
50
+ : node.tag === 'p'
51
+ ? cm.sp('mb', 2)
52
+ : undefined;
53
+ return (_jsx(Text, { as: node.tag, className: className, children: children }, index));
54
+ });
55
+ }
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Rule: a native horizontal thematic break.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ReactElement } from 'react';
7
+ import { type RuleProps } from '@molecule/app-ui';
8
+ import type { ElementRefProps } from './types.js';
9
+ /** Draws a theme-colored top border with the theme's vertical spacing. */
10
+ export declare function Rule(props: RuleProps & ElementRefProps): ReactElement;
11
+ //# sourceMappingURL=Rule.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Rule.d.ts","sourceRoot":"","sources":["../../src/elements/Rule.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAGzC,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,kBAAkB,CAAA;AAQ9D,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAEjD,0EAA0E;AAC1E,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,GAAG,eAAe,GAAG,YAAY,CAmBrE"}
@@ -0,0 +1,19 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { View } from 'react-native';
3
+ import { getClassMap } from '@molecule/app-ui';
4
+ import { nativeAccessibility } from './accessibility.js';
5
+ import { registerInline } from './flow.js';
6
+ import { useGridCell } from './grid.js';
7
+ import { dataAttributes, splitClasses, useTagClasses } from './inherited.js';
8
+ import { useNativeRef } from './ref.js';
9
+ import { nativeStyle } from './style.js';
10
+ /** Draws a theme-colored top border with the theme's vertical spacing. */
11
+ export function Rule(props) {
12
+ const cm = getClassMap();
13
+ const className = cm.cn(cm.borderT, cm.sp('my', 1), useTagClasses(props.className, props.as));
14
+ const { view } = splitClasses(className, '', dataAttributes(props));
15
+ const accessibility = nativeAccessibility(props);
16
+ const decorative = !!accessibility['aria-hidden'] || props.role === 'presentation' || props.role === 'none';
17
+ return (_jsx(View, { ...accessibility, ref: useNativeRef(props.ref), accessible: !decorative, accessibilityElementsHidden: decorative || undefined, importantForAccessibility: decorative ? 'no-hide-descendants' : undefined, role: decorative ? undefined : (accessibility.role ?? 'separator'), className: view || undefined, style: [{ alignSelf: 'stretch' }, nativeStyle(props.style, props.webStyle), useGridCell()] }));
18
+ }
19
+ registerInline(Rule, () => null);
@@ -0,0 +1,21 @@
1
+ /**
2
+ * ScrollArea: a container that scrolls.
3
+ *
4
+ * @module
5
+ */
6
+ import { type ReactElement } from 'react';
7
+ import type { ScrollAreaProps } from '@molecule/app-ui';
8
+ import type { ElementNode, ElementRefProps } from './types.js';
9
+ /** The viewport available to a horizontal scroll area's content, once measured. */
10
+ export declare const HorizontalViewport: import("react").Context<{
11
+ width?: number;
12
+ } | null>;
13
+ /**
14
+ * A scrolling container: a native `View` frame with the element's classes, role and ref, holding
15
+ * a `ScrollView` in `direction` that the frame's size bounds.
16
+ *
17
+ * @param props - See {@link ScrollAreaProps}.
18
+ * @returns The element.
19
+ */
20
+ export declare function ScrollArea(props: ScrollAreaProps<ElementNode> & ElementRefProps): ReactElement;
21
+ //# sourceMappingURL=ScrollArea.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ScrollArea.d.ts","sourceRoot":"","sources":["../../src/elements/ScrollArea.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAEL,KAAK,YAAY,EAMlB,MAAM,OAAO,CAAA;AAWd,OAAO,KAAK,EAAiB,eAAe,EAAgB,MAAM,kBAAkB,CAAA;AAiBpF,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAK9D,mFAAmF;AACnF,eAAO,MAAM,kBAAkB;YAA2B,MAAM;SAAgB,CAAA;AAEhF;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC,GAAG,eAAe,GAAG,YAAY,CAmH9F"}