@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,103 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * CheckField: a native checkbox or controlled radio.
4
+ *
5
+ * @module
6
+ */
7
+ import { useCallback, useContext, useImperativeHandle, useLayoutEffect, useRef, useState, } from 'react';
8
+ import { Pressable as NativePressable } from 'react-native';
9
+ import { getClassMap } from '@molecule/app-ui';
10
+ import { nativeAccessibility } from './accessibility.js';
11
+ import { fieldEvent } from './events.js';
12
+ import { registerInline } from './flow.js';
13
+ import { DisabledScope, FormScope, useFieldValue, useFormRegistration } from './form.js';
14
+ import { useGridCell } from './grid.js';
15
+ import { dataAttributes, ElementScope, replacedFlow, splitClasses, useInheritedText, useLineStart, useTagClasses, } from './inherited.js';
16
+ import { useLabelable } from './labels.js';
17
+ import { activatePress, pressProps } from './press.js';
18
+ import { nativeStyle } from './style.js';
19
+ import { Path, Svg } from './Svg.js';
20
+ /**
21
+ * Draws the check state, handles activation, and contributes a successful control to the form.
22
+ * An accessibility-hidden control retains its handle and registration without drawing a view.
23
+ *
24
+ * @param props - The checkbox or radio's props and ref.
25
+ * @returns The visible control, or null for a hidden one.
26
+ */
27
+ export function CheckField(props) {
28
+ const { as, type, name, checked, defaultChecked, indeterminate, className, style, webStyle, required, onChange, onClick, onCheckedChange, onFocus, onBlur, tabIndex, ref, } = props;
29
+ const value = props.value ?? 'on';
30
+ const form = useContext(FormScope);
31
+ const fieldsetDisabled = useContext(DisabledScope);
32
+ const disabled = props.disabled || fieldsetDisabled;
33
+ const hidden = props['aria-hidden'] === true || props['aria-hidden'] === 'true';
34
+ const field = useFieldValue(checked, defaultChecked ?? false);
35
+ const [mixed, setMixed] = useState(indeterminate ?? false);
36
+ useLayoutEffect(() => {
37
+ setMixed(indeterminate ?? false);
38
+ }, [indeterminate]);
39
+ const view = useRef(null);
40
+ const focus = useCallback(() => {
41
+ if (!disabled && !hidden)
42
+ view.current?.focus();
43
+ }, [disabled, hidden]);
44
+ const click = (event) => {
45
+ if (disabled)
46
+ return;
47
+ activatePress(onClick, () => {
48
+ const next = !field.read();
49
+ if (type === 'radio' && !next)
50
+ return;
51
+ setMixed(false);
52
+ field.change(next, () => {
53
+ onChange?.(fieldEvent({ checked: next, value, name: name ?? '', type }));
54
+ onCheckedChange?.(next);
55
+ });
56
+ }, event);
57
+ };
58
+ useImperativeHandle(ref, () => ({
59
+ focus,
60
+ blur: () => view.current?.blur(),
61
+ click: () => click(),
62
+ get checked() {
63
+ return field.read();
64
+ },
65
+ }));
66
+ const label = useLabelable(props.id, hidden ? undefined : () => click());
67
+ useFormRegistration(form?.fields, {
68
+ entries: () => (name && !disabled && field.read() ? [[name, value]] : []),
69
+ valid: () => disabled ||
70
+ !required ||
71
+ field.read() ||
72
+ (type === 'radio' && !!name && form?.hasCheckedRadio(name) === true),
73
+ checkedRadio: () => (type === 'radio' && field.read() ? name : undefined),
74
+ reset: field.reset,
75
+ focus,
76
+ });
77
+ // RN View.focus is available to focusable hosts, and hidden controls never acquire a host.
78
+ useLayoutEffect(() => {
79
+ if (props.autoFocus)
80
+ focus();
81
+ }, [props.autoFocus, focus]);
82
+ const classes = useTagClasses(className, as);
83
+ const marked = mixed || field.displayed;
84
+ const split = splitClasses(classes, useInheritedText(), {
85
+ ...dataAttributes(props),
86
+ state: marked ? 'checked' : 'unchecked',
87
+ });
88
+ const lineStyle = useLineStart(replacedFlow(className, as));
89
+ const gridStyle = useGridCell();
90
+ if (hidden)
91
+ return null;
92
+ const mark = marked
93
+ ? getClassMap().checkFieldMark?.(type === 'radio' ? 'radio' : mixed ? 'mixed' : 'checked', classes)
94
+ : undefined;
95
+ return (_jsx(ElementScope, { split: split, children: _jsx(NativePressable, { ...nativeAccessibility({
96
+ ...props,
97
+ role: props.role ?? type,
98
+ 'aria-checked': props['aria-checked'] ?? (mixed ? 'mixed' : field.displayed),
99
+ 'aria-disabled': disabled || props['aria-disabled'],
100
+ 'aria-label': props['aria-label'] ?? label,
101
+ }), ref: view, className: split.view || undefined, style: [nativeStyle(style, webStyle), lineStyle, gridStyle], disabled: disabled, ...pressProps({ onFocus, onBlur, tabIndex }), onPress: click, children: mark && (_jsx(Svg, { className: mark.className, width: "100%", height: "100%", viewBox: "0 0 16 16", "aria-hidden": true, children: _jsx(Path, { d: mark.path, fill: "currentColor" }) })) }) }));
102
+ }
103
+ registerInline(CheckField, (props) => replacedFlow(props.className, 'input'));
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Disclosure: a pressable summary and a mounted, collapsible body.
3
+ *
4
+ * @module
5
+ */
6
+ import { type ReactElement } from 'react';
7
+ import type { DisclosureProps } from '@molecule/app-ui';
8
+ import type { ElementNode, ElementRefProps } from './types.js';
9
+ /** Draws the summary as a button and keeps closed content mounted but inaccessible. */
10
+ export declare function Disclosure(props: DisclosureProps<ElementNode> & ElementRefProps): ReactElement;
11
+ //# sourceMappingURL=Disclosure.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Disclosure.d.ts","sourceRoot":"","sources":["../../src/elements/Disclosure.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAkD,MAAM,OAAO,CAAA;AAGzF,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAA;AAevD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAgD9D,uFAAuF;AACvF,wBAAgB,UAAU,CAAC,KAAK,EAAE,eAAe,CAAC,WAAW,CAAC,GAAG,eAAe,GAAG,YAAY,CA8C9F"}
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Disclosure: a pressable summary and a mounted, collapsible body.
4
+ *
5
+ * @module
6
+ */
7
+ import { useCallback, useLayoutEffect, useRef, useState } from 'react';
8
+ import { Pressable, View } from 'react-native';
9
+ import { nativeAccessibility } from './accessibility.js';
10
+ import { registerInline } from './flow.js';
11
+ import { useGridCell } from './grid.js';
12
+ import { dataAttributes, ElementScope, layoutChildren, splitClasses, useInheritedText, useTagClasses, } from './inherited.js';
13
+ import { useNativeRef } from './ref.js';
14
+ import { nativeStyle } from './style.js';
15
+ /** Tracks the applied open state and coalesces changes into one queued notification. */
16
+ function useExpanded(open, onToggle) {
17
+ const [expanded, setExpanded] = useState(open ?? false);
18
+ const current = useRef(false);
19
+ const callback = useRef(onToggle);
20
+ const pending = useRef(false);
21
+ const task = useRef(undefined);
22
+ const queue = useCallback(() => {
23
+ pending.current = true;
24
+ if (task.current !== undefined)
25
+ return;
26
+ task.current = setTimeout(() => {
27
+ task.current = undefined;
28
+ pending.current = false;
29
+ callback.current?.(current.current);
30
+ }, 0);
31
+ }, []);
32
+ const transition = useCallback((next) => {
33
+ if (current.current === next)
34
+ return;
35
+ current.current = next;
36
+ setExpanded(next);
37
+ queue();
38
+ }, [queue]);
39
+ useLayoutEffect(() => {
40
+ callback.current = onToggle;
41
+ }, [onToggle]);
42
+ // Reapply only when the parent changes the supplied value, as React does for the open attribute.
43
+ useLayoutEffect(() => transition(open ?? false), [open, transition]);
44
+ useLayoutEffect(() => {
45
+ // React can replay effect setup after cleanup while keeping state, e.g. in StrictMode.
46
+ if (pending.current)
47
+ queue();
48
+ return () => {
49
+ clearTimeout(task.current);
50
+ task.current = undefined;
51
+ };
52
+ }, [queue]);
53
+ return { expanded, toggle: () => transition(!current.current) };
54
+ }
55
+ /** Draws the summary as a button and keeps closed content mounted but inaccessible. */
56
+ export function Disclosure(props) {
57
+ const { as, open, summary, summaryProps, onToggle, style, webStyle, children, ref } = props;
58
+ const { expanded, toggle } = useExpanded(open, onToggle);
59
+ const split = splitClasses(useTagClasses(props.className, as), useInheritedText(), dataAttributes(props));
60
+ const summarySplit = splitClasses(useTagClasses(summaryProps?.className, 'summary', { first: true, last: children == null }), split.text, summaryProps && dataAttributes(summaryProps));
61
+ return (_jsx(View, { ...nativeAccessibility(props, as), ref: useNativeRef(ref), className: split.view || undefined, style: [nativeStyle(style, webStyle), useGridCell()], children: _jsxs(ElementScope, { split: split, children: [_jsx(Pressable, { ...nativeAccessibility({
62
+ ...summaryProps,
63
+ role: summaryProps?.role ?? 'button',
64
+ children: summary,
65
+ }), accessibilityState: { expanded }, "aria-expanded": expanded, className: summarySplit.view || undefined, onPress: toggle, style: nativeStyle(summaryProps?.style, summaryProps?.webStyle), children: _jsx(ElementScope, { split: summarySplit, children: layoutChildren(summary, summarySplit) }) }), _jsx(View, { accessibilityElementsHidden: expanded ? undefined : true, importantForAccessibility: expanded ? undefined : 'no-hide-descendants', pointerEvents: expanded ? undefined : 'none', style: expanded ? undefined : { display: 'none' }, children: layoutChildren(children, split) })] }) }));
66
+ }
67
+ registerInline(Disclosure, () => null);
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Fieldset: a native disabled scope with an optional layout box.
3
+ *
4
+ * @module
5
+ */
6
+ import { type ReactElement } from 'react';
7
+ import type { FieldsetProps } from '@molecule/app-ui';
8
+ import type { ElementNode, ElementRefProps } from './types.js';
9
+ /**
10
+ * Disables descendant controls, with no view when its classes set display contents.
11
+ *
12
+ * @param props - The fieldset's props and ref.
13
+ * @returns The fieldset and its content.
14
+ */
15
+ export declare function Fieldset(props: FieldsetProps<ElementNode> & ElementRefProps): ReactElement;
16
+ //# sourceMappingURL=Fieldset.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Fieldset.d.ts","sourceRoot":"","sources":["../../src/elements/Fieldset.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,KAAK,YAAY,EAAc,MAAM,OAAO,CAAA;AAGrD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAiBrD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE9D;;;;;GAKG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG,eAAe,GAAG,YAAY,CAiC1F"}
@@ -0,0 +1,34 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * Fieldset: a native disabled scope with an optional layout box.
4
+ *
5
+ * @module
6
+ */
7
+ import { useContext } from 'react';
8
+ import { View } from 'react-native';
9
+ import { nativeAccessibility } from './accessibility.js';
10
+ import { registerContents } from './flow.js';
11
+ import { DisabledScope } from './form.js';
12
+ import { useGridCell } from './grid.js';
13
+ import { dataAttributes, ElementScope, layoutChildren, splitClasses, useInheritedText, useTagClasses, wrapStrings, } from './inherited.js';
14
+ import { useNativeRef } from './ref.js';
15
+ import { nativeStyle } from './style.js';
16
+ /**
17
+ * Disables descendant controls, with no view when its classes set display contents.
18
+ *
19
+ * @param props - The fieldset's props and ref.
20
+ * @returns The fieldset and its content.
21
+ */
22
+ export function Fieldset(props) {
23
+ const { as, className, style, webStyle, children, ref } = props;
24
+ const parentDisabled = useContext(DisabledScope);
25
+ const disabled = parentDisabled || props.disabled === true;
26
+ const split = splitClasses(useTagClasses(className, as), useInheritedText(), dataAttributes(props));
27
+ const nativeRef = useNativeRef(ref);
28
+ const gridCell = useGridCell();
29
+ return (_jsx(DisabledScope.Provider, { value: disabled, children: _jsx(ElementScope, { split: split, children: split.display === 'contents' ? (wrapStrings(children, split.text)) : (_jsx(View, { ...nativeAccessibility({ ...props, 'aria-disabled': disabled || props['aria-disabled'] }, as), ref: nativeRef, className: split.view || undefined, style: [nativeStyle(style, webStyle), gridCell], children: layoutChildren(children, split) })) }) }));
30
+ }
31
+ registerContents(Fieldset, (props) => {
32
+ const className = typeof props.className === 'string' ? props.className : undefined;
33
+ return splitClasses(className, '', dataAttributes(props)).display === 'contents';
34
+ });
@@ -0,0 +1,12 @@
1
+ /**
2
+ * File chooser control for React Native.
3
+ *
4
+ * @module
5
+ */
6
+ import { type ReactNode } from 'react';
7
+ import type { FileFieldHandle, FileFieldProps } from '@molecule/app-ui';
8
+ /**
9
+ * Opens the bonded device picker from its browse target or the caller's `pick()` handle.
10
+ */
11
+ export declare const FileField: import("react").ForwardRefExoticComponent<FileFieldProps<ReactNode> & import("react").RefAttributes<FileFieldHandle>>;
12
+ //# sourceMappingURL=FileField.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FileField.d.ts","sourceRoot":"","sources":["../../src/elements/FileField.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAc,KAAK,SAAS,EAAgD,MAAM,OAAO,CAAA;AAKhG,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAgBvE;;GAEG;AACH,eAAO,MAAM,SAAS,uHAwHrB,CAAA"}
@@ -0,0 +1,111 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * File chooser control for React Native.
4
+ *
5
+ * @module
6
+ */
7
+ import { forwardRef, useImperativeHandle, useLayoutEffect, useRef } from 'react';
8
+ import { getProvider } from '@molecule/app-file-picker';
9
+ import { filterPickedFiles } from '@molecule/app-filesystem';
10
+ import { useT } from '@molecule/app-react';
11
+ import { registeredKind, registerInline } from './flow.js';
12
+ import { Pressable } from './Pressable.js';
13
+ /**
14
+ * Reports a picker failure the same way as the browser field.
15
+ *
16
+ * @param error - The underlying picker or selection error.
17
+ * @param onPickError - The current consumer error handler.
18
+ */
19
+ function reportPickError(error, onPickError) {
20
+ if (!onPickError)
21
+ throw error;
22
+ onPickError(error instanceof Error ? error : new Error(String(error), { cause: error }));
23
+ }
24
+ /**
25
+ * Opens the bonded device picker from its browse target or the caller's `pick()` handle.
26
+ */
27
+ export const FileField = forwardRef(function FileField(props, ref) {
28
+ const { accept, children, disabled, externalTrigger, maxSize, multiple, onPickError, onRejected, onValueChange, role = 'button', tabIndex, ...attrs } = props;
29
+ const t = useT();
30
+ const latest = useRef({
31
+ accept,
32
+ disabled,
33
+ maxSize,
34
+ multiple,
35
+ onPickError,
36
+ onRejected,
37
+ onValueChange,
38
+ });
39
+ const pending = useRef(null);
40
+ useLayoutEffect(() => {
41
+ latest.current = {
42
+ accept,
43
+ disabled,
44
+ maxSize,
45
+ multiple,
46
+ onPickError,
47
+ onRejected,
48
+ onValueChange,
49
+ };
50
+ if (disabled && pending.current)
51
+ pending.current.discard = true;
52
+ }, [accept, disabled, maxSize, multiple, onPickError, onRejected, onValueChange]);
53
+ useLayoutEffect(() => () => {
54
+ if (pending.current)
55
+ pending.current.discard = true;
56
+ }, []);
57
+ /** Starts at most one request for this pressable and delivers it to the current render. */
58
+ function open() {
59
+ const options = latest.current;
60
+ if (options.disabled || pending.current)
61
+ return;
62
+ const picker = getProvider();
63
+ if (!picker) {
64
+ const message = t('ui.fileField.error.missingProvider', { bond: '@molecule/app-file-picker-expo', core: '@molecule/app-file-picker' }, {
65
+ defaultValue: 'No file picker is bonded. Import `provider` from {{bond}} and call `setProvider(provider)` from {{core}} in `setupProviders()`.',
66
+ });
67
+ reportPickError(new Error(message), options.onPickError);
68
+ return;
69
+ }
70
+ const request = { discard: false };
71
+ pending.current = request;
72
+ const pick = async () => {
73
+ let selection;
74
+ try {
75
+ const files = await picker.pickFiles({
76
+ accept: options.accept,
77
+ multiple: options.multiple,
78
+ includeRejected: true,
79
+ });
80
+ if (request.discard)
81
+ return;
82
+ selection = filterPickedFiles(files, latest.current);
83
+ }
84
+ catch (error) {
85
+ if (!request.discard)
86
+ reportPickError(error, latest.current.onPickError);
87
+ return;
88
+ }
89
+ finally {
90
+ pending.current = null;
91
+ }
92
+ const { onValueChange, onRejected } = latest.current;
93
+ if (selection.accepted.length)
94
+ onValueChange(selection.accepted);
95
+ if (selection.rejected.length)
96
+ onRejected?.(selection.rejected);
97
+ };
98
+ void pick().catch((error) => {
99
+ // Pressable has a void event handler. Raise an exception on the host after the await.
100
+ queueMicrotask(() => {
101
+ throw error;
102
+ });
103
+ });
104
+ }
105
+ useImperativeHandle(ref, () => ({ pick: open }));
106
+ if (externalTrigger)
107
+ return null;
108
+ return (_jsx(Pressable, { as: "div", role: role, "data-mol-id": "file-field", ...attrs, "aria-label": attrs['aria-label'] ??
109
+ t('ui.fileField.browse', undefined, { defaultValue: 'Browse files' }), "aria-disabled": disabled, disabled: disabled, tabIndex: tabIndex ?? (disabled ? -1 : 0), onClick: open, children: children }));
110
+ });
111
+ registerInline(FileField, (props) => registeredKind(Pressable, { ...props, as: 'div' }) ?? null);
@@ -0,0 +1,18 @@
1
+ /**
2
+ * FormArea: a native scope for grouping, validating and submitting controls.
3
+ *
4
+ * @module
5
+ */
6
+ import { type ReactElement, type Ref } from 'react';
7
+ import type { FormAreaHandle, FormAreaProps } from '@molecule/app-ui';
8
+ import type { ElementNode } from './types.js';
9
+ /**
10
+ * Draws a form container and supplies its submit, reset and scoped label associations.
11
+ *
12
+ * @param props - The form's props and ref.
13
+ * @returns The form and its content.
14
+ */
15
+ export declare function FormArea(props: FormAreaProps<ElementNode> & {
16
+ ref?: Ref<FormAreaHandle>;
17
+ }): ReactElement;
18
+ //# sourceMappingURL=FormArea.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"FormArea.d.ts","sourceRoot":"","sources":["../../src/elements/FormArea.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,GAAG,EAMT,MAAM,OAAO,CAAA;AAGd,OAAO,KAAK,EAAE,cAAc,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAerE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA;AAE7C;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,aAAa,CAAC,WAAW,CAAC,GAAG;IAAE,GAAG,CAAC,EAAE,GAAG,CAAC,cAAc,CAAC,CAAA;CAAE,GAChE,YAAY,CA6Cd"}
@@ -0,0 +1,42 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ /**
3
+ * FormArea: a native scope for grouping, validating and submitting controls.
4
+ *
5
+ * @module
6
+ */
7
+ import { useEffect, useImperativeHandle, useLayoutEffect, useRef, useState, } from 'react';
8
+ import { View } from 'react-native';
9
+ import { nativeAccessibility } from './accessibility.js';
10
+ import { createFormScope, FormScope } from './form.js';
11
+ import { useGridCell } from './grid.js';
12
+ import { dataAttributes, ElementScope, layoutChildren, splitClasses, useInheritedText, useTagClasses, } from './inherited.js';
13
+ import { createLabelDirectory, FormLabels } from './labels.js';
14
+ import { nativeStyle } from './style.js';
15
+ /**
16
+ * Draws a form container and supplies its submit, reset and scoped label associations.
17
+ *
18
+ * @param props - The form's props and ref.
19
+ * @returns The form and its content.
20
+ */
21
+ export function FormArea(props) {
22
+ const { as, action, onSubmit, className, style, webStyle, children, ref } = props;
23
+ const latest = useRef(props);
24
+ useLayoutEffect(() => {
25
+ latest.current = props;
26
+ }, [props]);
27
+ const [form] = useState(() => createFormScope(() => latest.current));
28
+ const [labels] = useState(createLabelDirectory);
29
+ const view = useRef(null);
30
+ useImperativeHandle(ref, () => ({
31
+ focus: () => view.current?.focus(),
32
+ blur: () => view.current?.blur(),
33
+ requestSubmit: form.submit,
34
+ }), [form]);
35
+ useEffect(() => {
36
+ if (typeof __DEV__ !== 'undefined' && __DEV__ && action !== undefined && !onSubmit) {
37
+ console.error('FormArea requires onSubmit to handle an action on React Native.');
38
+ }
39
+ }, [action, onSubmit]);
40
+ const split = splitClasses(useTagClasses(className, as), useInheritedText(), dataAttributes(props));
41
+ return (_jsx(FormScope.Provider, { value: form, children: _jsx(FormLabels.Provider, { value: labels, children: _jsx(ElementScope, { split: split, children: _jsx(View, { ...nativeAccessibility(props, as), ref: view, className: split.view || undefined, style: [nativeStyle(style, webStyle), useGridCell()], children: layoutChildren(children, split) }) }) }) }));
42
+ }
@@ -0,0 +1,19 @@
1
+ /**
2
+ * GlyphIcon: a glyph of the icon font.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ReactElement } from 'react';
7
+ import { type GlyphIconProps } from '@molecule/app-ui';
8
+ import type { ElementRefProps } from './types.js';
9
+ /**
10
+ * A glyph of the icon font: a native `Text` drawing the glyph's codepoint in the icon font the app
11
+ * set (`setFont` with an `icon` font that has `glyphs`, such as
12
+ * `@molecule/app-fonts-material-symbols/native`), since a device draws neither ligatures nor
13
+ * variable axes. A name the font does not draw renders nothing.
14
+ *
15
+ * @param props - See {@link GlyphIconProps}.
16
+ * @returns The element, or `null`.
17
+ */
18
+ export declare function GlyphIcon(props: GlyphIconProps & ElementRefProps): ReactElement | null;
19
+ //# sourceMappingURL=GlyphIcon.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GlyphIcon.d.ts","sourceRoot":"","sources":["../../src/elements/GlyphIcon.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAIzC,OAAO,EAAe,KAAK,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAcnE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD;;;;;;;;GAQG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,GAAG,eAAe,GAAG,YAAY,GAAG,IAAI,CAmCtF"}
@@ -0,0 +1,43 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Text as NativeText } from 'react-native';
3
+ import { getFont } from '@molecule/app-fonts';
4
+ import { getClassMap } from '@molecule/app-ui';
5
+ import { nativeAccessibility } from './accessibility.js';
6
+ import { registerInline } from './flow.js';
7
+ import { useGridCell } from './grid.js';
8
+ import { dataAttributes, splitClasses, textElementClasses, useInheritedText, useTagClasses, } from './inherited.js';
9
+ import { useNativeRef } from './ref.js';
10
+ import { nativeStyle } from './style.js';
11
+ /** Glyph names already reported as missing from the icon font. */
12
+ const REPORTED = new Set();
13
+ /**
14
+ * A glyph of the icon font: a native `Text` drawing the glyph's codepoint in the icon font the app
15
+ * set (`setFont` with an `icon` font that has `glyphs`, such as
16
+ * `@molecule/app-fonts-material-symbols/native`), since a device draws neither ligatures nor
17
+ * variable axes. A name the font does not draw renders nothing.
18
+ *
19
+ * @param props - See {@link GlyphIconProps}.
20
+ * @returns The element, or `null`.
21
+ */
22
+ export function GlyphIcon(props) {
23
+ const { name, filled, className, style, webStyle, ref } = props;
24
+ const cm = getClassMap();
25
+ const split = splitClasses(cm.cn(cm.iconGlyphFont, useTagClasses(className, 'span')), useInheritedText(), dataAttributes(props));
26
+ const nativeRef = useNativeRef(ref);
27
+ const gridStyle = useGridCell();
28
+ const font = getFont('icon');
29
+ const codepoint = font?.glyphs?.codepoint(name);
30
+ if (!font || codepoint === undefined) {
31
+ if (typeof __DEV__ !== 'undefined' && __DEV__ && !REPORTED.has(name)) {
32
+ REPORTED.add(name);
33
+ console.error(font?.glyphs
34
+ ? `GlyphIcon: the icon font "${font.family}" has no glyph named "${name}".`
35
+ : `GlyphIcon "${name}": no icon font with glyphs is set. Call setFont() with one (nativeFont from @molecule/app-fonts-material-symbols/native) and load its nativeFiles with expo-font.`);
36
+ }
37
+ return null;
38
+ }
39
+ const family = filled ? (font.glyphs?.filledFamily ?? font.family) : font.family;
40
+ const own = nativeStyle(style, webStyle);
41
+ return (_jsx(NativeText, { ...nativeAccessibility(props, 'span'), ref: nativeRef, className: textElementClasses(split), style: [{ fontFamily: family }, own, gridStyle], children: String.fromCodePoint(codepoint) }));
42
+ }
43
+ registerInline(GlyphIcon, () => 'text');
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Image: a picture.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ReactElement } from 'react';
7
+ import type { ImageProps } from '@molecule/app-ui';
8
+ import type { ElementRefProps } from './types.js';
9
+ /**
10
+ * An image: a native `Image` with `alt` as its accessibility label; an empty `alt` hides a
11
+ * decorative image from assistive technology.
12
+ *
13
+ * @param props - See {@link ImageProps}.
14
+ * @returns The element.
15
+ */
16
+ export declare function Image(props: ImageProps & ElementRefProps): ReactElement;
17
+ //# sourceMappingURL=Image.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Image.d.ts","sourceRoot":"","sources":["../../src/elements/Image.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAGzC,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAOlD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAKjD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,UAAU,GAAG,eAAe,GAAG,YAAY,CAmBvE"}
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Image as NativeImage } from 'react-native';
3
+ import { nativeAccessibility } from './accessibility.js';
4
+ import { registerInline } from './flow.js';
5
+ import { useGridCell } from './grid.js';
6
+ import { replacedFlow } from './inherited.js';
7
+ import { useNativeRef } from './ref.js';
8
+ /** React Native's resize mode for a CSS `object-fit`. */
9
+ const RESIZE = { cover: 'cover', contain: 'contain', fill: 'stretch', none: 'center' };
10
+ /**
11
+ * An image: a native `Image` with `alt` as its accessibility label; an empty `alt` hides a
12
+ * decorative image from assistive technology.
13
+ *
14
+ * @param props - See {@link ImageProps}.
15
+ * @returns The element.
16
+ */
17
+ export function Image(props) {
18
+ const { src, alt, width, height, className, style, onLoad, onError, ref } = props;
19
+ const { objectFit, ...box } = style ?? {};
20
+ return (_jsx(NativeImage, { ...nativeAccessibility({
21
+ ...props,
22
+ 'aria-label': alt || props['aria-label'],
23
+ 'aria-hidden': alt === '' ? true : props['aria-hidden'],
24
+ }), ref: useNativeRef(ref), source: { uri: src }, className: className || undefined, style: [{ width, height }, box, useGridCell()], resizeMode: objectFit ? RESIZE[objectFit] : undefined, onLoad: onLoad ? () => onLoad() : undefined, onError: onError ? () => onError() : undefined }));
25
+ }
26
+ registerInline(Image, (props) => replacedFlow(props.className, 'img'));
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Link: an in-app or external link.
3
+ *
4
+ * @module
5
+ */
6
+ import type { ReactElement } from 'react';
7
+ import type { ElementLinkProps } from '@molecule/app-ui';
8
+ import type { ElementNode, ElementRefProps } from './types.js';
9
+ /**
10
+ * A link: a native `Pressable` with the link role. A press runs `onClick`, then (unless the
11
+ * handler called `preventDefault()`) navigates through the router for an app path, or opens a URL
12
+ * outside the app. A link to the location already shown replaces it, as on the web. A URL outside
13
+ * the app needs no router: it opens through the device's URL handler in an app with none mounted,
14
+ * while an app path without one fails with the binding's no-router error, as on the web.
15
+ *
16
+ * @param props - See {@link ElementLinkProps}.
17
+ * @returns The element.
18
+ */
19
+ export declare function Link(props: ElementLinkProps<ElementNode> & ElementRefProps): ReactElement;
20
+ //# sourceMappingURL=Link.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Link.d.ts","sourceRoot":"","sources":["../../src/elements/Link.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAA;AAKzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAA;AAmBxD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE9D;;;;;;;;;GASG;AACH,wBAAgB,IAAI,CAAC,KAAK,EAAE,gBAAgB,CAAC,WAAW,CAAC,GAAG,eAAe,GAAG,YAAY,CAiEzF"}
@@ -0,0 +1,53 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { Linking, Pressable } from 'react-native';
3
+ import { useLinkRouter } from '@molecule/app-react';
4
+ import { formatLocation, parseLocation, resolveLinkPath } from '@molecule/app-routing';
5
+ import { nativeAccessibility } from './accessibility.js';
6
+ import { focusEvent, mouseEvent } from './events.js';
7
+ import { registerInline } from './flow.js';
8
+ import { useGridCell } from './grid.js';
9
+ import { blockInInline, dataAttributes, ElementScope, flowOf, isCssInline, layoutChildren, splitClasses, useInheritedText, useTagClasses, } from './inherited.js';
10
+ import { useNativeRef } from './ref.js';
11
+ import { nativeStyle } from './style.js';
12
+ /**
13
+ * A link: a native `Pressable` with the link role. A press runs `onClick`, then (unless the
14
+ * handler called `preventDefault()`) navigates through the router for an app path, or opens a URL
15
+ * outside the app. A link to the location already shown replaces it, as on the web. A URL outside
16
+ * the app needs no router: it opens through the device's URL handler in an app with none mounted,
17
+ * while an app path without one fails with the binding's no-router error, as on the web.
18
+ *
19
+ * @param props - See {@link ElementLinkProps}.
20
+ * @returns The element.
21
+ */
22
+ export function Link(props) {
23
+ const { to, replace, state, title, className, style, webStyle, onClick, onMouseEnter, onMouseLeave, onFocus, onBlur, children, ref, } = props;
24
+ const router = useLinkRouter(to);
25
+ const split = splitClasses(useTagClasses(className, 'a'), useInheritedText(), dataAttributes(props));
26
+ const text = split.text;
27
+ const accessibility = nativeAccessibility({
28
+ ...props,
29
+ role: props.role ?? 'link',
30
+ 'aria-label': props['aria-label'] ?? title,
31
+ });
32
+ return (_jsx(ElementScope, { split: split, text: text, children: _jsx(Pressable, { ...accessibility, ref: useNativeRef(ref), className: split.view || undefined, style: [nativeStyle(style, webStyle), useGridCell()], onPress: (nativeEvent) => {
33
+ const event = mouseEvent(nativeEvent);
34
+ onClick?.(event);
35
+ if (event.defaultPrevented)
36
+ return;
37
+ const path = resolveLinkPath(to);
38
+ // `router` is null only for a URL outside the app with no router mounted, so that case
39
+ // opens the URL like every other one outside the app. An app path always has a router
40
+ // here: `useLinkRouter` threw the binding's no-router error without one.
41
+ if (router === null || path === null) {
42
+ void Linking.openURL(to);
43
+ return;
44
+ }
45
+ const navigation = {
46
+ replace: replace ??
47
+ formatLocation(router.getLocation()) === formatLocation(parseLocation(path)),
48
+ ...(state === undefined ? {} : { state }),
49
+ };
50
+ router.navigate(path, navigation);
51
+ }, onHoverIn: onMouseEnter ? () => onMouseEnter(mouseEvent(undefined)) : undefined, onHoverOut: onMouseLeave ? () => onMouseLeave(mouseEvent(undefined)) : undefined, onFocus: onFocus ? () => onFocus(focusEvent()) : undefined, onBlur: onBlur ? () => onBlur(focusEvent()) : undefined, children: layoutChildren(children, split) }) }));
52
+ }
53
+ registerInline(Link, (props) => blockInInline(flowOf(props.className, 'box', dataAttributes(props)), props.children, isCssInline(props.className, true, dataAttributes(props))));