@molecule/app-ui-react-native 1.0.10 → 2.1.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.
- package/README.md +211 -331
- package/dist/components/Button.d.ts +2 -2
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js +2 -2
- package/dist/components/Card.d.ts +3 -2
- package/dist/components/Card.d.ts.map +1 -1
- package/dist/components/Card.js +11 -3
- package/dist/components/Checkbox.d.ts +2 -2
- package/dist/components/Checkbox.d.ts.map +1 -1
- package/dist/components/Checkbox.js +4 -7
- package/dist/components/Input.d.ts +13 -2
- package/dist/components/Input.d.ts.map +1 -1
- package/dist/components/Input.js +5 -11
- package/dist/components/Layout.d.ts +3 -2
- package/dist/components/Layout.d.ts.map +1 -1
- package/dist/components/Layout.js +2 -2
- package/dist/components/Select.d.ts +2 -2
- package/dist/components/Select.d.ts.map +1 -1
- package/dist/components/Select.js +4 -6
- package/dist/components/Switch.d.ts +2 -2
- package/dist/components/Switch.d.ts.map +1 -1
- package/dist/components/Switch.js +3 -7
- package/dist/components/Textarea.d.ts +13 -2
- package/dist/components/Textarea.d.ts.map +1 -1
- package/dist/components/Textarea.js +2 -6
- package/dist/elements/Anchor.d.ts +15 -0
- package/dist/elements/Anchor.d.ts.map +1 -0
- package/dist/elements/Anchor.js +57 -0
- package/dist/elements/Box.d.ts +19 -0
- package/dist/elements/Box.d.ts.map +1 -0
- package/dist/elements/Box.js +150 -0
- package/dist/elements/CheckField.d.ts +18 -0
- package/dist/elements/CheckField.d.ts.map +1 -0
- package/dist/elements/CheckField.js +103 -0
- package/dist/elements/Disclosure.d.ts +11 -0
- package/dist/elements/Disclosure.d.ts.map +1 -0
- package/dist/elements/Disclosure.js +67 -0
- package/dist/elements/Fieldset.d.ts +16 -0
- package/dist/elements/Fieldset.d.ts.map +1 -0
- package/dist/elements/Fieldset.js +34 -0
- package/dist/elements/FileField.d.ts +12 -0
- package/dist/elements/FileField.d.ts.map +1 -0
- package/dist/elements/FileField.js +111 -0
- package/dist/elements/FormArea.d.ts +18 -0
- package/dist/elements/FormArea.d.ts.map +1 -0
- package/dist/elements/FormArea.js +42 -0
- package/dist/elements/GlyphIcon.d.ts +19 -0
- package/dist/elements/GlyphIcon.d.ts.map +1 -0
- package/dist/elements/GlyphIcon.js +43 -0
- package/dist/elements/Image.d.ts +17 -0
- package/dist/elements/Image.d.ts.map +1 -0
- package/dist/elements/Image.js +26 -0
- package/dist/elements/Link.d.ts +20 -0
- package/dist/elements/Link.d.ts.map +1 -0
- package/dist/elements/Link.js +53 -0
- package/dist/elements/Pressable.d.ts +18 -0
- package/dist/elements/Pressable.d.ts.map +1 -0
- package/dist/elements/Pressable.js +107 -0
- package/dist/elements/PulseDots.d.ts +15 -0
- package/dist/elements/PulseDots.d.ts.map +1 -0
- package/dist/elements/PulseDots.js +78 -0
- package/dist/elements/RangeField.d.ts +11 -0
- package/dist/elements/RangeField.d.ts.map +1 -0
- package/dist/elements/RangeField.js +259 -0
- package/dist/elements/RichText.d.ts +23 -0
- package/dist/elements/RichText.d.ts.map +1 -0
- package/dist/elements/RichText.js +55 -0
- package/dist/elements/Rule.d.ts +11 -0
- package/dist/elements/Rule.d.ts.map +1 -0
- package/dist/elements/Rule.js +19 -0
- package/dist/elements/ScrollArea.d.ts +21 -0
- package/dist/elements/ScrollArea.d.ts.map +1 -0
- package/dist/elements/ScrollArea.js +101 -0
- package/dist/elements/SelectAction.d.ts +20 -0
- package/dist/elements/SelectAction.d.ts.map +1 -0
- package/dist/elements/SelectAction.js +113 -0
- package/dist/elements/SelectField.d.ts +11 -0
- package/dist/elements/SelectField.d.ts.map +1 -0
- package/dist/elements/SelectField.js +220 -0
- package/dist/elements/SelectMenu.d.ts +19 -0
- package/dist/elements/SelectMenu.d.ts.map +1 -0
- package/dist/elements/SelectMenu.js +122 -0
- package/dist/elements/Svg.d.ts +155 -0
- package/dist/elements/Svg.d.ts.map +1 -0
- package/dist/elements/Svg.js +525 -0
- package/dist/elements/TableBox.d.ts +19 -0
- package/dist/elements/TableBox.d.ts.map +1 -0
- package/dist/elements/TableBox.js +87 -0
- package/dist/elements/TableCell.d.ts +16 -0
- package/dist/elements/TableCell.d.ts.map +1 -0
- package/dist/elements/TableCell.js +69 -0
- package/dist/elements/Text.d.ts +17 -0
- package/dist/elements/Text.d.ts.map +1 -0
- package/dist/elements/Text.js +96 -0
- package/dist/elements/TextField.d.ts +25 -0
- package/dist/elements/TextField.d.ts.map +1 -0
- package/dist/elements/TextField.js +257 -0
- package/dist/elements/accessibility.d.ts +36 -0
- package/dist/elements/accessibility.d.ts.map +1 -0
- package/dist/elements/accessibility.js +239 -0
- package/dist/elements/className.d.ts +45 -0
- package/dist/elements/className.d.ts.map +1 -0
- package/dist/elements/className.js +8 -0
- package/dist/elements/decimal.d.ts +5 -0
- package/dist/elements/decimal.d.ts.map +1 -0
- package/dist/elements/decimal.js +11 -0
- package/dist/elements/documentUrl.d.ts +35 -0
- package/dist/elements/documentUrl.d.ts.map +1 -0
- package/dist/elements/documentUrl.js +89 -0
- package/dist/elements/drag-drop.d.ts +11 -0
- package/dist/elements/drag-drop.d.ts.map +1 -0
- package/dist/elements/drag-drop.js +277 -0
- package/dist/elements/drag.d.ts +47 -0
- package/dist/elements/drag.d.ts.map +1 -0
- package/dist/elements/drag.js +362 -0
- package/dist/elements/events.d.ts +45 -0
- package/dist/elements/events.d.ts.map +1 -0
- package/dist/elements/events.js +101 -0
- package/dist/elements/fieldBounds.d.ts +5 -0
- package/dist/elements/fieldBounds.d.ts.map +1 -0
- package/dist/elements/fieldBounds.js +60 -0
- package/dist/elements/flow.d.ts +36 -0
- package/dist/elements/flow.d.ts.map +1 -0
- package/dist/elements/flow.js +47 -0
- package/dist/elements/form.d.ts +48 -0
- package/dist/elements/form.d.ts.map +1 -0
- package/dist/elements/form.js +112 -0
- package/dist/elements/grid.d.ts +96 -0
- package/dist/elements/grid.d.ts.map +1 -0
- package/dist/elements/grid.js +272 -0
- package/dist/elements/index.d.ts +36 -0
- package/dist/elements/index.d.ts.map +1 -0
- package/dist/elements/index.js +35 -0
- package/dist/elements/inherited.d.ts +181 -0
- package/dist/elements/inherited.d.ts.map +1 -0
- package/dist/elements/inherited.js +512 -0
- package/dist/elements/labels.d.ts +39 -0
- package/dist/elements/labels.d.ts.map +1 -0
- package/dist/elements/labels.js +163 -0
- package/dist/elements/measure.d.ts +27 -0
- package/dist/elements/measure.d.ts.map +1 -0
- package/dist/elements/measure.js +24 -0
- package/dist/elements/outsidePress.d.ts +31 -0
- package/dist/elements/outsidePress.d.ts.map +1 -0
- package/dist/elements/outsidePress.js +94 -0
- package/dist/elements/paste.d.ts +22 -0
- package/dist/elements/paste.d.ts.map +1 -0
- package/dist/elements/paste.js +49 -0
- package/dist/elements/press.d.ts +41 -0
- package/dist/elements/press.d.ts.map +1 -0
- package/dist/elements/press.js +131 -0
- package/dist/elements/rangeKeyboard.d.ts +41 -0
- package/dist/elements/rangeKeyboard.d.ts.map +1 -0
- package/dist/elements/rangeKeyboard.js +58 -0
- package/dist/elements/rangeValues.d.ts +20 -0
- package/dist/elements/rangeValues.d.ts.map +1 -0
- package/dist/elements/rangeValues.js +101 -0
- package/dist/elements/ref.d.ts +16 -0
- package/dist/elements/ref.d.ts.map +1 -0
- package/dist/elements/ref.js +22 -0
- package/dist/elements/reveal.d.ts +8 -0
- package/dist/elements/reveal.d.ts.map +1 -0
- package/dist/elements/reveal.js +10 -0
- package/dist/elements/scrollReveal.d.ts +19 -0
- package/dist/elements/scrollReveal.d.ts.map +1 -0
- package/dist/elements/scrollReveal.js +52 -0
- package/dist/elements/selectOptions.d.ts +25 -0
- package/dist/elements/selectOptions.d.ts.map +1 -0
- package/dist/elements/selectOptions.js +60 -0
- package/dist/elements/style.d.ts +30 -0
- package/dist/elements/style.d.ts.map +1 -0
- package/dist/elements/style.js +363 -0
- package/dist/elements/svgHover.d.ts +41 -0
- package/dist/elements/svgHover.d.ts.map +1 -0
- package/dist/elements/svgHover.js +152 -0
- package/dist/elements/table.d.ts +52 -0
- package/dist/elements/table.d.ts.map +1 -0
- package/dist/elements/table.js +104 -0
- package/dist/elements/types.d.ts +25 -0
- package/dist/elements/types.d.ts.map +1 -0
- package/dist/elements/types.js +8 -0
- package/dist/elements/viewport.d.ts +53 -0
- package/dist/elements/viewport.d.ts.map +1 -0
- package/dist/elements/viewport.js +62 -0
- package/dist/elements/wheelZoom.d.ts +11 -0
- package/dist/elements/wheelZoom.d.ts.map +1 -0
- package/dist/elements/wheelZoom.js +7 -0
- package/dist/index.d.ts +11 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -5
- package/dist/platform/focus.d.ts +31 -0
- package/dist/platform/focus.d.ts.map +1 -0
- package/dist/platform/focus.js +86 -0
- package/dist/platform/index.d.ts +31 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +179 -0
- package/dist/platform/layout.d.ts +13 -0
- package/dist/platform/layout.d.ts.map +1 -0
- package/dist/platform/layout.js +15 -0
- package/dist/platform/position.d.ts +5 -0
- package/dist/platform/position.d.ts.map +1 -0
- package/dist/platform/position.js +177 -0
- package/dist/platform/stack.d.ts +86 -0
- package/dist/platform/stack.d.ts.map +1 -0
- package/dist/platform/stack.js +318 -0
- package/dist/types.d.ts +25 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/package.json +66 -8
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Svg and its shapes.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { createContext, forwardRef, isValidElement, useCallback, useContext, useId, useLayoutEffect, useMemo, useState, } from 'react';
|
|
8
|
+
import { Platform, Pressable, processColor, View, } from 'react-native';
|
|
9
|
+
import { Circle as NativeCircle, ClipPath as NativeClipPath, Defs as NativeDefs, Ellipse as NativeEllipse, G as NativeG, Image as NativeImage, Line as NativeLine, LinearGradient as NativeLinearGradient, Path as NativePath, Pattern as NativePattern, Polygon as NativePolygon, Polyline as NativePolyline, Rect as NativeRect, Stop as NativeStop, Svg as NativeSvg, SvgXml, Text as NativeSvgText, } from 'react-native-svg';
|
|
10
|
+
import { getFont } from '@molecule/app-fonts';
|
|
11
|
+
import { getClassMap, } from '@molecule/app-ui';
|
|
12
|
+
import { nativeAccessibility } from './accessibility.js';
|
|
13
|
+
import { useImageSource } from './documentUrl.js';
|
|
14
|
+
import { SvgDragFrame, useNativeDrag } from './drag.js';
|
|
15
|
+
import { keyboardEvent, mouseEvent } from './events.js';
|
|
16
|
+
import { registerInline } from './flow.js';
|
|
17
|
+
import { useGridCell } from './grid.js';
|
|
18
|
+
import { dataAttributes, replacedFlow, splitClasses, useInheritedText, useTagClasses, } from './inherited.js';
|
|
19
|
+
import { useLabelText, useReferencedLabelText } from './labels.js';
|
|
20
|
+
import { useOutsideTouch } from './outsidePress.js';
|
|
21
|
+
import { getNativeKeyboardView, rangeKeyboardEvent } from './rangeKeyboard.js';
|
|
22
|
+
import { useNativeRef } from './ref.js';
|
|
23
|
+
import { nativeStyle } from './style.js';
|
|
24
|
+
import { SvgHoverScope, useRectHover, useSvgHover } from './svgHover.js';
|
|
25
|
+
/**
|
|
26
|
+
* An SVG canvas: react-native-svg's `Svg`. Its classes and the text classes its container hands
|
|
27
|
+
* down go to `className`, so a class-name runtime can resolve the text colour `currentColor` reads.
|
|
28
|
+
*
|
|
29
|
+
* @param props - See {@link SvgProps}.
|
|
30
|
+
* @param ref - The native canvas viewport.
|
|
31
|
+
* @returns The element.
|
|
32
|
+
*/
|
|
33
|
+
export const Svg = forwardRef(function Svg(props, ref) {
|
|
34
|
+
return _jsx(Canvas, { ...props, elementRef: ref });
|
|
35
|
+
});
|
|
36
|
+
/** Draws the canvas and hosts its focus layer in the same coordinate space. */
|
|
37
|
+
function Canvas(props) {
|
|
38
|
+
const canvas = useCanvasProps(props);
|
|
39
|
+
const forward = useNativeRef(props.elementRef);
|
|
40
|
+
const hover = useSvgHover(props);
|
|
41
|
+
const hoverHost = hover.host;
|
|
42
|
+
const responder = useNativeDrag(hoverHost, {
|
|
43
|
+
drag: props.style?.pointerEvents === 'none' ? undefined : props.drag,
|
|
44
|
+
press: { onPress: canvas.props.onPress },
|
|
45
|
+
});
|
|
46
|
+
const ref = useCallback((view) => {
|
|
47
|
+
hoverHost.current = view;
|
|
48
|
+
forward?.(view);
|
|
49
|
+
}, [forward, hoverHost]);
|
|
50
|
+
const [targets, setTargets] = useState(() => new Map());
|
|
51
|
+
const [register] = useState(() => (id, target) => {
|
|
52
|
+
setTargets((previous) => new Map(previous).set(id, target));
|
|
53
|
+
return () => {
|
|
54
|
+
setTargets((previous) => {
|
|
55
|
+
const next = new Map(previous);
|
|
56
|
+
next.delete(id);
|
|
57
|
+
return next;
|
|
58
|
+
});
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
const rootFocusable = needsFocusTarget(props);
|
|
62
|
+
const onTouchStart = useOutsideTouch(hoverHost);
|
|
63
|
+
const hidden = canvas.props['aria-hidden'];
|
|
64
|
+
const drawing = {
|
|
65
|
+
...canvas.props,
|
|
66
|
+
onPress: responder ? undefined : canvas.props.onPress,
|
|
67
|
+
focusable: false,
|
|
68
|
+
accessible: rootFocusable ? false : canvas.props.accessible,
|
|
69
|
+
};
|
|
70
|
+
const { markup, children } = props;
|
|
71
|
+
const renderDrawing = (color) => {
|
|
72
|
+
const ink = typeof color === 'string' && typeof processColor(color) === 'number' ? color : undefined;
|
|
73
|
+
return (_jsx(SvgInk.Provider, { value: ink, children: _jsx(NativeSvg, { ...drawing, color: ink, children: children }) }));
|
|
74
|
+
};
|
|
75
|
+
const textClasses = drawing.className;
|
|
76
|
+
const styledDrawing = markup === undefined && textClasses
|
|
77
|
+
? getClassMap().renderNativeTextColor?.(textClasses, renderDrawing)
|
|
78
|
+
: undefined;
|
|
79
|
+
const content = markup === undefined ? (isValidElement(styledDrawing) ? (styledDrawing) : (renderDrawing(undefined))) : (_jsx(SvgXml, { ...drawing, xml: `<svg>${markup}</svg>` }));
|
|
80
|
+
return (_jsxs(View, { ref: ref, collapsable: false, onTouchStart: onTouchStart, pointerEvents: responder ? 'auto' : 'box-none', ...hover.handlers, ...responder, accessibilityElementsHidden: hidden, importantForAccessibility: hidden ? 'no-hide-descendants' : undefined, style: canvas.frameStyle, className: canvas.frameClassName, children: [_jsx(SvgDragFrame.Provider, { value: hoverHost, children: _jsx(SvgFocusScope.Provider, { value: hidden ? null : register, children: _jsx(SvgHoverScope.Provider, { value: hover.register, children: content }) }) }), rootFocusable && _jsx(SvgFocusTarget, { target: focusTarget(props, canvas.accessibility), fill: true }), !hidden &&
|
|
81
|
+
Array.from(targets, ([id, target]) => _jsx(SvgFocusTarget, { target: target }, id))] }));
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* The react-native-svg props of a canvas: its size, view box and paint, its classes (the text
|
|
85
|
+
* classes in effect, so `currentColor` is the text colour), its style and its accessibility.
|
|
86
|
+
*
|
|
87
|
+
* @param props - The canvas's props.
|
|
88
|
+
* @returns The react-native-svg props.
|
|
89
|
+
*/
|
|
90
|
+
function useCanvasProps(props) {
|
|
91
|
+
const { viewBox, preserveAspectRatio, fill, fillOpacity, stroke, strokeWidth, strokeOpacity, strokeLinecap, strokeLinejoin, strokeDasharray, strokeDashoffset, opacity, transform, style, } = props;
|
|
92
|
+
const accessibility = useSvgAccessibility(props, props.metadata);
|
|
93
|
+
const split = splitClasses(useTagClasses(props.className, 'svg'), useInheritedText(), dataAttributes(props));
|
|
94
|
+
const { width, height, style: measuredStyle, } = canvasSize(props.width, props.height, split.sized, viewBox);
|
|
95
|
+
const cell = useGridCell();
|
|
96
|
+
const frameStyle = [
|
|
97
|
+
measuredStyle,
|
|
98
|
+
width === undefined ? undefined : { width },
|
|
99
|
+
height === undefined ? undefined : { height },
|
|
100
|
+
nativeStyle(undefined, props.webStyle),
|
|
101
|
+
cell,
|
|
102
|
+
];
|
|
103
|
+
// Percentage dimensions on a view-box-only drawing give its auto-sized frame a
|
|
104
|
+
// 300px intrinsic width on web, even in a flex slot that would shrink to zero.
|
|
105
|
+
const hasFrameDimension = split.sized?.width ||
|
|
106
|
+
split.sized?.height ||
|
|
107
|
+
frameStyle.some((style) => style?.width !== undefined || style?.height !== undefined);
|
|
108
|
+
return {
|
|
109
|
+
accessibility,
|
|
110
|
+
frameStyle,
|
|
111
|
+
frameClassName: split.view || undefined,
|
|
112
|
+
props: {
|
|
113
|
+
...accessibility,
|
|
114
|
+
...(hasFrameDimension ? { width: '100%', height: '100%' } : {}),
|
|
115
|
+
accessibilityLabel: accessibility['aria-label'],
|
|
116
|
+
accessible: !accessibility['aria-hidden'] &&
|
|
117
|
+
Boolean(accessibility['aria-label'] || accessibility.accessibilityHint || accessibility.role),
|
|
118
|
+
accessibilityRole: accessibility.role === 'img' ? 'image' : undefined,
|
|
119
|
+
className: split.text || undefined,
|
|
120
|
+
viewBox,
|
|
121
|
+
preserveAspectRatio,
|
|
122
|
+
fill,
|
|
123
|
+
fillOpacity,
|
|
124
|
+
stroke,
|
|
125
|
+
strokeWidth,
|
|
126
|
+
strokeOpacity,
|
|
127
|
+
strokeLinecap,
|
|
128
|
+
strokeLinejoin,
|
|
129
|
+
strokeDasharray,
|
|
130
|
+
strokeDashoffset,
|
|
131
|
+
opacity,
|
|
132
|
+
transform,
|
|
133
|
+
...style,
|
|
134
|
+
onPress: props.onClick && style?.pointerEvents !== 'none'
|
|
135
|
+
? (event) => props.onClick?.(mouseEvent(event))
|
|
136
|
+
: undefined,
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
registerInline(Svg, (props) => replacedFlow(props.className, 'svg'));
|
|
141
|
+
/** The size the web gives a drawing with no width, no height and no view box. */
|
|
142
|
+
const DEFAULT_CANVAS = { width: 300, height: 150 };
|
|
143
|
+
/**
|
|
144
|
+
* The width/height ratio of a view box (`0 0 24 12` is 2), or `null` without a usable one.
|
|
145
|
+
*
|
|
146
|
+
* @param viewBox - The view box.
|
|
147
|
+
* @returns The ratio.
|
|
148
|
+
*/
|
|
149
|
+
export function viewBoxRatio(viewBox) {
|
|
150
|
+
const parts = (viewBox ?? '')
|
|
151
|
+
.trim()
|
|
152
|
+
.split(/[\s,]+/)
|
|
153
|
+
.map(Number);
|
|
154
|
+
const [, , w, h] = parts;
|
|
155
|
+
return parts.length === 4 && w !== undefined && h !== undefined && w > 0 && h > 0 ? w / h : null;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* A drawing's size as the web sizes an `<svg>`: its classes take precedence over the width and
|
|
159
|
+
* height attributes. A view box gives auto-sized dimensions an aspect ratio, with the available
|
|
160
|
+
* space determined by layout. Without a view box, missing dimensions default to 300px by 150px.
|
|
161
|
+
*
|
|
162
|
+
* @param width - The `width` attribute.
|
|
163
|
+
* @param height - The `height` attribute.
|
|
164
|
+
* @param sized - Which sizes the classes set.
|
|
165
|
+
* @param viewBox - The view box.
|
|
166
|
+
* @returns The props' width and height, and the style that supplies the sizes neither sets.
|
|
167
|
+
*/
|
|
168
|
+
export function canvasSize(width, height, sized, viewBox) {
|
|
169
|
+
const ownWidth = sized?.width ? undefined : width;
|
|
170
|
+
const ownHeight = sized?.height ? undefined : height;
|
|
171
|
+
const hasWidth = ownWidth !== undefined || sized?.width === true;
|
|
172
|
+
const hasHeight = ownHeight !== undefined || sized?.height === true;
|
|
173
|
+
if (hasWidth && hasHeight)
|
|
174
|
+
return { width: ownWidth, height: ownHeight, style: undefined };
|
|
175
|
+
const ratio = viewBoxRatio(viewBox);
|
|
176
|
+
const style = ratio
|
|
177
|
+
? { aspectRatio: ratio }
|
|
178
|
+
: {
|
|
179
|
+
...(hasWidth ? {} : { width: DEFAULT_CANVAS.width }),
|
|
180
|
+
...(hasHeight ? {} : { height: DEFAULT_CANVAS.height }),
|
|
181
|
+
};
|
|
182
|
+
return { width: ownWidth, height: ownHeight, style };
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* A canvas drawn from inner SVG markup: react-native-svg's `SvgXml` with that markup, sized and
|
|
186
|
+
* painted as {@link Svg} is.
|
|
187
|
+
*
|
|
188
|
+
* @param props - See {@link SvgMarkupProps}.
|
|
189
|
+
* @param ref - The native canvas viewport.
|
|
190
|
+
* @returns The element.
|
|
191
|
+
*/
|
|
192
|
+
export const SvgMarkup = forwardRef(function SvgMarkup(props, ref) {
|
|
193
|
+
return _jsx(Canvas, { ...props, elementRef: ref });
|
|
194
|
+
});
|
|
195
|
+
registerInline(SvgMarkup, (props) => replacedFlow(props.className, 'svg'));
|
|
196
|
+
const SvgFocusScope = createContext(null);
|
|
197
|
+
/** Concrete ink used both by the native canvas and by its gradient stops. */
|
|
198
|
+
const SvgInk = createContext(undefined);
|
|
199
|
+
/** Structured metadata and ARIA relationships share the native kit's existing ID directory. */
|
|
200
|
+
function useSvgAccessibility(props, metadata, text) {
|
|
201
|
+
const description = metadata?.description;
|
|
202
|
+
const fallbackName = props['aria-label'] ?? metadata?.title ?? text;
|
|
203
|
+
useLabelText(props.id, fallbackName);
|
|
204
|
+
useLabelText(description?.id, description?.text);
|
|
205
|
+
const name = useReferencedLabelText(props['aria-labelledby']) ?? fallbackName;
|
|
206
|
+
const hint = useReferencedLabelText(props['aria-describedby']) ?? description?.text;
|
|
207
|
+
return useMemo(() => {
|
|
208
|
+
const accessibility = nativeAccessibility({ ...props, 'aria-label': name });
|
|
209
|
+
const hints = [hint, accessibility.accessibilityHint].filter(Boolean);
|
|
210
|
+
return { ...accessibility, accessibilityHint: hints.join(', ') || undefined };
|
|
211
|
+
}, [props, name, hint]);
|
|
212
|
+
}
|
|
213
|
+
/** The native SVG shapes omit roles and keyboard targets. The canvas publishes those separately. */
|
|
214
|
+
function needsFocusTarget(props, shape = false, metadata) {
|
|
215
|
+
const hidden = props['aria-hidden'];
|
|
216
|
+
return (hidden !== true &&
|
|
217
|
+
hidden !== 'true' &&
|
|
218
|
+
Boolean(props.onKeyDown ||
|
|
219
|
+
(props.tabIndex !== undefined && props.tabIndex >= 0) ||
|
|
220
|
+
(shape &&
|
|
221
|
+
(metadata ||
|
|
222
|
+
props['aria-labelledby'] ||
|
|
223
|
+
props['aria-describedby'] ||
|
|
224
|
+
(props.role && props.role !== 'none' && props.role !== 'presentation')))));
|
|
225
|
+
}
|
|
226
|
+
/** Focus properties for the canvas itself. */
|
|
227
|
+
function focusTarget(props, accessibility) {
|
|
228
|
+
return {
|
|
229
|
+
accessibility,
|
|
230
|
+
tabIndex: props.tabIndex,
|
|
231
|
+
onClick: props.onClick,
|
|
232
|
+
onKeyDown: props.onKeyDown,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
/** A focus and accessibility target that leaves touch hit-testing to the drawing. */
|
|
236
|
+
function SvgFocusTarget({ target, fill }) {
|
|
237
|
+
const { accessibility, tabIndex, onClick, onKeyDown, bounds } = target;
|
|
238
|
+
const KeyboardView = useMemo(getNativeKeyboardView, []);
|
|
239
|
+
const focusable = tabIndex !== undefined ? tabIndex >= 0 : Boolean(onKeyDown);
|
|
240
|
+
const style = bounds
|
|
241
|
+
? {
|
|
242
|
+
position: 'absolute',
|
|
243
|
+
left: bounds.x,
|
|
244
|
+
top: bounds.y,
|
|
245
|
+
width: bounds.width,
|
|
246
|
+
height: bounds.height,
|
|
247
|
+
}
|
|
248
|
+
: fill
|
|
249
|
+
? { position: 'absolute', top: 0, left: 0, bottom: 0, right: 0 }
|
|
250
|
+
: { position: 'absolute', top: 0, left: 0, width: 1, height: 1 };
|
|
251
|
+
const invoke = () => {
|
|
252
|
+
if (onClick)
|
|
253
|
+
onClick(mouseEvent(undefined));
|
|
254
|
+
else
|
|
255
|
+
onKeyDown?.(keyboardEvent('Enter'));
|
|
256
|
+
};
|
|
257
|
+
const control = {
|
|
258
|
+
...accessibility,
|
|
259
|
+
testID: accessibility.testID ? `${accessibility.testID}-focus` : undefined,
|
|
260
|
+
accessible: true,
|
|
261
|
+
focusable,
|
|
262
|
+
pointerEvents: 'box-none',
|
|
263
|
+
style,
|
|
264
|
+
onAccessibilityTap: onClick || onKeyDown ? invoke : undefined,
|
|
265
|
+
accessibilityActions: onClick || onKeyDown ? [{ name: 'activate' }] : undefined,
|
|
266
|
+
onAccessibilityAction: (event) => {
|
|
267
|
+
if (event.nativeEvent.actionName === 'activate')
|
|
268
|
+
invoke();
|
|
269
|
+
},
|
|
270
|
+
};
|
|
271
|
+
if (onKeyDown && KeyboardView) {
|
|
272
|
+
return (_jsx(KeyboardView, { ...control, canBeFocused: focusable, hasKeyDownPress: true, onKeyDownPress: (event) => {
|
|
273
|
+
const { keyCode } = event.nativeEvent;
|
|
274
|
+
const ios = Platform.OS === 'ios';
|
|
275
|
+
const enter = ios ? keyCode === 40 || keyCode === 88 : keyCode === 66 || keyCode === 160;
|
|
276
|
+
const space = keyCode === (ios ? 44 : 62);
|
|
277
|
+
const key = rangeKeyboardEvent(event);
|
|
278
|
+
if (enter)
|
|
279
|
+
Object.assign(key, { key: 'Enter', code: 'Enter' });
|
|
280
|
+
if (space)
|
|
281
|
+
Object.assign(key, { key: ' ', code: 'Space' });
|
|
282
|
+
onKeyDown(key);
|
|
283
|
+
} }));
|
|
284
|
+
}
|
|
285
|
+
return (_jsx(Pressable, { ...control, onPress: onKeyDown ? () => onKeyDown(keyboardEvent('Enter')) : undefined }));
|
|
286
|
+
}
|
|
287
|
+
/** Copies typed paint and adapts a shape's native touch and accessibility props. */
|
|
288
|
+
function useShape(props, options) {
|
|
289
|
+
const { className: _className, role: _role, webStyle: _webStyle, style, tabIndex, onClick, onKeyDown, ...paint } = props;
|
|
290
|
+
const register = useContext(SvgFocusScope);
|
|
291
|
+
const id = useId();
|
|
292
|
+
const [bounds, setBounds] = useState();
|
|
293
|
+
const proxy = register !== null && needsFocusTarget(props, true, options?.metadata);
|
|
294
|
+
const accessibility = useSvgAccessibility(props, options?.metadata, options?.label);
|
|
295
|
+
const pointerEvents = style?.pointerEvents ?? options?.pointerEvents;
|
|
296
|
+
const name = accessibility['aria-label'];
|
|
297
|
+
const { testID } = accessibility;
|
|
298
|
+
useLayoutEffect(() => {
|
|
299
|
+
if (!proxy || !register)
|
|
300
|
+
return;
|
|
301
|
+
return register(id, { accessibility, tabIndex, onClick, onKeyDown, bounds });
|
|
302
|
+
}, [proxy, register, id, accessibility, tabIndex, onClick, onKeyDown, bounds]);
|
|
303
|
+
return {
|
|
304
|
+
...paint,
|
|
305
|
+
...style,
|
|
306
|
+
pointerEvents,
|
|
307
|
+
accessible: proxy || accessibility['aria-hidden'] ? false : name ? true : undefined,
|
|
308
|
+
accessibilityLabel: accessibility['aria-hidden'] ? undefined : name,
|
|
309
|
+
testID,
|
|
310
|
+
onPress: onClick && pointerEvents !== 'none'
|
|
311
|
+
? (event) => onClick(mouseEvent(event))
|
|
312
|
+
: undefined,
|
|
313
|
+
onLayout: proxy
|
|
314
|
+
? ({ nativeEvent: { layout } }) => {
|
|
315
|
+
setBounds((previous) => previous?.x === layout.x &&
|
|
316
|
+
previous.y === layout.y &&
|
|
317
|
+
previous.width === layout.width &&
|
|
318
|
+
previous.height === layout.height
|
|
319
|
+
? previous
|
|
320
|
+
: layout);
|
|
321
|
+
}
|
|
322
|
+
: undefined,
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* An SVG path.
|
|
327
|
+
*
|
|
328
|
+
* @param props - See {@link SvgPathProps}.
|
|
329
|
+
* @returns The element.
|
|
330
|
+
*/
|
|
331
|
+
export function Path(props) {
|
|
332
|
+
return _jsx(NativePath, { ...useShape(props) });
|
|
333
|
+
}
|
|
334
|
+
/**
|
|
335
|
+
* An SVG rectangle.
|
|
336
|
+
*
|
|
337
|
+
* @param props - See {@link SvgRectProps}.
|
|
338
|
+
* @returns The element.
|
|
339
|
+
*/
|
|
340
|
+
export function Rect(props) {
|
|
341
|
+
const { metadata, onMouseEnter: _onMouseEnter, pointerEvents, ...paint } = props;
|
|
342
|
+
const ref = useRectHover(props);
|
|
343
|
+
return _jsx(NativeRect, { ...useShape(paint, { metadata, pointerEvents }), ref: ref });
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* An SVG circle.
|
|
347
|
+
*
|
|
348
|
+
* @param props - See {@link SvgCircleProps}.
|
|
349
|
+
* @returns The element.
|
|
350
|
+
*/
|
|
351
|
+
export function Circle(props) {
|
|
352
|
+
return _jsx(NativeCircle, { ...useShape(props) });
|
|
353
|
+
}
|
|
354
|
+
/**
|
|
355
|
+
* An SVG ellipse.
|
|
356
|
+
*
|
|
357
|
+
* @param props - See {@link SvgEllipseProps}.
|
|
358
|
+
* @returns The element.
|
|
359
|
+
*/
|
|
360
|
+
export function Ellipse(props) {
|
|
361
|
+
return _jsx(NativeEllipse, { ...useShape(props) });
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* An SVG line.
|
|
365
|
+
*
|
|
366
|
+
* @param props - See {@link SvgLineProps}.
|
|
367
|
+
* @returns The element.
|
|
368
|
+
*/
|
|
369
|
+
export function Line(props) {
|
|
370
|
+
return _jsx(NativeLine, { ...useShape(props) });
|
|
371
|
+
}
|
|
372
|
+
/**
|
|
373
|
+
* An SVG polyline.
|
|
374
|
+
*
|
|
375
|
+
* @param props - See {@link SvgPolyProps}.
|
|
376
|
+
* @returns The element.
|
|
377
|
+
*/
|
|
378
|
+
export function Polyline(props) {
|
|
379
|
+
return _jsx(NativePolyline, { ...useShape(props) });
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* An SVG polygon.
|
|
383
|
+
*
|
|
384
|
+
* @param props - See {@link SvgPolyProps}.
|
|
385
|
+
* @returns The element.
|
|
386
|
+
*/
|
|
387
|
+
export function Polygon(props) {
|
|
388
|
+
return _jsx(NativePolygon, { ...useShape(props) });
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* An SVG group.
|
|
392
|
+
*
|
|
393
|
+
* @param props - See {@link SvgGroupProps}.
|
|
394
|
+
* @returns The element.
|
|
395
|
+
*/
|
|
396
|
+
export function G({ drag, ...props }) {
|
|
397
|
+
const frame = useContext(SvgDragFrame);
|
|
398
|
+
const shape = useShape(props);
|
|
399
|
+
const responder = useNativeDrag(frame, {
|
|
400
|
+
drag: props.style?.pointerEvents === 'none' ? undefined : drag,
|
|
401
|
+
press: { onPress: shape.onPress },
|
|
402
|
+
});
|
|
403
|
+
return (_jsx(NativeG, { ...shape, ...responder, onPress: responder ? undefined : shape.onPress, onLayout: shape.onLayout || responder?.onLayout
|
|
404
|
+
? (event) => {
|
|
405
|
+
shape.onLayout?.(event);
|
|
406
|
+
responder?.onLayout?.(event);
|
|
407
|
+
}
|
|
408
|
+
: undefined }));
|
|
409
|
+
}
|
|
410
|
+
/**
|
|
411
|
+
* SVG text.
|
|
412
|
+
*
|
|
413
|
+
* @param props - See {@link SvgTextProps}.
|
|
414
|
+
* @returns The element.
|
|
415
|
+
*/
|
|
416
|
+
export function SvgText(props) {
|
|
417
|
+
const { children, fontFamily, ...text } = props;
|
|
418
|
+
const label = typeof children === 'string' || typeof children === 'number' ? String(children) : undefined;
|
|
419
|
+
const { dominantBaseline, ...shape } = useShape({ ...text, children }, { label });
|
|
420
|
+
return (_jsx(NativeSvgText, { ...shape, alignmentBaseline: dominantBaseline === 'auto' ? undefined : dominantBaseline, fontFamily: nativeFontFamily(fontFamily) }));
|
|
421
|
+
}
|
|
422
|
+
const FONT_ROLES = ['sans', 'serif', 'mono', 'icon'];
|
|
423
|
+
const IOS_FAMILIES = [
|
|
424
|
+
'Arial',
|
|
425
|
+
'Courier New',
|
|
426
|
+
'Georgia',
|
|
427
|
+
'Helvetica',
|
|
428
|
+
'Helvetica Neue',
|
|
429
|
+
'Menlo',
|
|
430
|
+
'Times New Roman',
|
|
431
|
+
];
|
|
432
|
+
const ANDROID_FAMILIES = [
|
|
433
|
+
'Roboto',
|
|
434
|
+
'Roboto Condensed',
|
|
435
|
+
'sans-serif',
|
|
436
|
+
'sans-serif-condensed',
|
|
437
|
+
'serif',
|
|
438
|
+
'monospace',
|
|
439
|
+
];
|
|
440
|
+
/** Finds the first registered or system family in CSS priority order. */
|
|
441
|
+
function nativeFontFamily(list) {
|
|
442
|
+
const entries = list?.matchAll(/(?:^|,)\s*(?:"([^"]*)"|'([^']*)'|([^,]+))/g);
|
|
443
|
+
if (!entries)
|
|
444
|
+
return undefined;
|
|
445
|
+
const fonts = FONT_ROLES.map(getFont);
|
|
446
|
+
const system = Platform.OS === 'android' ? ANDROID_FAMILIES : IOS_FAMILIES;
|
|
447
|
+
for (const [, doubleQuoted, singleQuoted, unquoted] of entries) {
|
|
448
|
+
const family = (doubleQuoted ?? singleQuoted ?? unquoted)?.trim();
|
|
449
|
+
if (!family)
|
|
450
|
+
continue;
|
|
451
|
+
const name = family.toLowerCase();
|
|
452
|
+
if (name === 'system-ui' || name === '-apple-system' || name === 'blinkmacsystemfont')
|
|
453
|
+
return undefined;
|
|
454
|
+
if (name === 'sans-serif')
|
|
455
|
+
return Platform.OS === 'android' ? 'sans-serif' : undefined;
|
|
456
|
+
if (name === 'monospace')
|
|
457
|
+
return Platform.OS === 'android' ? 'monospace' : 'Menlo';
|
|
458
|
+
if (name === 'serif')
|
|
459
|
+
return Platform.OS === 'android' ? 'serif' : 'Georgia';
|
|
460
|
+
const available = system.find((item) => item.toLowerCase() === name);
|
|
461
|
+
if (available)
|
|
462
|
+
return available;
|
|
463
|
+
for (const font of fonts) {
|
|
464
|
+
if (!font?.nativeFiles)
|
|
465
|
+
continue;
|
|
466
|
+
const loaded = Object.keys(font.nativeFiles).find((item) => item.toLowerCase() === name);
|
|
467
|
+
if (loaded)
|
|
468
|
+
return loaded;
|
|
469
|
+
if (font.family.toLowerCase() === name)
|
|
470
|
+
return font.family;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
return undefined;
|
|
474
|
+
}
|
|
475
|
+
/** Definitions draw geometry but don't register as canvas interaction targets. */
|
|
476
|
+
function DefinitionShapes({ children }) {
|
|
477
|
+
return (_jsx(SvgFocusScope.Provider, { value: null, children: _jsx(SvgHoverScope.Provider, { value: null, children: children }) }));
|
|
478
|
+
}
|
|
479
|
+
/**
|
|
480
|
+
* Native SVG definitions in the enclosing drawing's ID namespace.
|
|
481
|
+
*
|
|
482
|
+
* @param props - See {@link SvgDefsProps}.
|
|
483
|
+
* @returns The native definitions.
|
|
484
|
+
*/
|
|
485
|
+
export function SvgDefs({ children }) {
|
|
486
|
+
return (_jsx(NativeDefs, { children: _jsx(DefinitionShapes, { children: children }) }));
|
|
487
|
+
}
|
|
488
|
+
/**
|
|
489
|
+
* A native SVG clipping region.
|
|
490
|
+
*
|
|
491
|
+
* @param props - See {@link SvgClipPathProps}.
|
|
492
|
+
* @returns The native clipping region.
|
|
493
|
+
*/
|
|
494
|
+
export function SvgClipPath({ children, ...props }) {
|
|
495
|
+
return (_jsx(NativeClipPath, { ...props, children: _jsx(DefinitionShapes, { children: children }) }));
|
|
496
|
+
}
|
|
497
|
+
/**
|
|
498
|
+
* A native linear gradient with concrete colours and ordered stops.
|
|
499
|
+
*
|
|
500
|
+
* @param props - See {@link SvgLinearGradientProps}.
|
|
501
|
+
* @returns The native gradient.
|
|
502
|
+
*/
|
|
503
|
+
export function SvgLinearGradient({ stops, ...props }) {
|
|
504
|
+
const inherited = useContext(SvgInk);
|
|
505
|
+
const ink = inherited ?? (Platform.OS === 'web' ? 'currentColor' : '#000');
|
|
506
|
+
return (_jsx(NativeLinearGradient, { ...props, children: stops.map(({ offset, stopColor, stopOpacity }, index) => (_jsx(NativeStop, { offset: offset, stopColor: stopColor === 'currentColor' ? ink : stopColor, stopOpacity: stopOpacity }, index))) }));
|
|
507
|
+
}
|
|
508
|
+
/**
|
|
509
|
+
* A named SVG pattern, repeated by the device's SVG painter.
|
|
510
|
+
*
|
|
511
|
+
* @param props - See {@link SvgPatternProps}.
|
|
512
|
+
* @returns The native pattern.
|
|
513
|
+
*/
|
|
514
|
+
export function SvgPattern({ children, ...props }) {
|
|
515
|
+
return (_jsx(NativePattern, { ...props, children: _jsx(DefinitionShapes, { children: children }) }));
|
|
516
|
+
}
|
|
517
|
+
/**
|
|
518
|
+
* A native image positioned in SVG user space.
|
|
519
|
+
*
|
|
520
|
+
* @param props - See {@link SvgImageProps}.
|
|
521
|
+
* @returns The native image.
|
|
522
|
+
*/
|
|
523
|
+
export function SvgImage({ href, ...props }) {
|
|
524
|
+
return _jsx(NativeImage, { ...useShape(props), href: useImageSource(href, 'SVG image href') });
|
|
525
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TableBox: the table's scope, row groups and flex rows on native.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type ReactElement } from 'react';
|
|
7
|
+
import type { TableBoxProps } from '@molecule/app-ui';
|
|
8
|
+
import type { ElementNode, ElementRefProps } from './types.js';
|
|
9
|
+
type Props = TableBoxProps<ElementNode> & ElementRefProps;
|
|
10
|
+
/**
|
|
11
|
+
* Renders a native table, row group or row. A row measures its cells once before
|
|
12
|
+
* applying the column widths shared by the whole table.
|
|
13
|
+
*
|
|
14
|
+
* @param props - The table part's props and ref.
|
|
15
|
+
* @returns The table part.
|
|
16
|
+
*/
|
|
17
|
+
export declare function TableBox(props: Props): ReactElement;
|
|
18
|
+
export {};
|
|
19
|
+
//# sourceMappingURL=TableBox.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableBox.d.ts","sourceRoot":"","sources":["../../src/elements/TableBox.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAkB,KAAK,YAAY,EAAmC,MAAM,OAAO,CAAA;AAQ1F,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAyBrD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE9D,KAAK,KAAK,GAAG,aAAa,CAAC,WAAW,CAAC,GAAG,eAAe,CAAA;AAEzD;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,KAAK,EAAE,KAAK,GAAG,YAAY,CAiBnD"}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* TableBox: the table's scope, row groups and flex rows on native.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { isValidElement, useContext, useEffect, useState } from 'react';
|
|
8
|
+
import { Pressable as NativePressable, View, } from 'react-native';
|
|
9
|
+
import { nativeAccessibility } from './accessibility.js';
|
|
10
|
+
import { useGridCell } from './grid.js';
|
|
11
|
+
import { dataAttributes, ElementScope, flatten, splitClasses, useInheritedText, useTagClasses, } from './inherited.js';
|
|
12
|
+
import { isPressable, pressProps } from './press.js';
|
|
13
|
+
import { useNativeRef } from './ref.js';
|
|
14
|
+
import { HorizontalViewport } from './ScrollArea.js';
|
|
15
|
+
import { nativeStyle } from './style.js';
|
|
16
|
+
import { cellSpan, fixedLength, TableColumn, TableLayout, TableRowPosition, useTableLayout, widthIn, } from './table.js';
|
|
17
|
+
/**
|
|
18
|
+
* Renders a native table, row group or row. A row measures its cells once before
|
|
19
|
+
* applying the column widths shared by the whole table.
|
|
20
|
+
*
|
|
21
|
+
* @param props - The table part's props and ref.
|
|
22
|
+
* @returns The table part.
|
|
23
|
+
*/
|
|
24
|
+
export function TableBox(props) {
|
|
25
|
+
if (props.as === 'table')
|
|
26
|
+
return _jsx(TableRoot, { ...props });
|
|
27
|
+
if (props.as === 'tr')
|
|
28
|
+
return _jsx(TableRow, { ...props });
|
|
29
|
+
return (_jsx(TablePart, { ...props, children: flatten(props.children)
|
|
30
|
+
.filter(isValidElement)
|
|
31
|
+
.map((row, index, rows) => (_jsx(TableRowPosition.Provider, { value: { first: index === 0, last: index === rows.length - 1 }, children: row }, row.key))) }));
|
|
32
|
+
}
|
|
33
|
+
/** Measures the table's container and publishes one set of column widths to its rows. */
|
|
34
|
+
function TableRoot(props) {
|
|
35
|
+
const viewport = useContext(HorizontalViewport);
|
|
36
|
+
const [measured, setMeasured] = useState();
|
|
37
|
+
const paint = nativeStyle(props.style, props.webStyle);
|
|
38
|
+
const explicitWidth = fixedLength(paint?.width);
|
|
39
|
+
const available = viewport
|
|
40
|
+
? (widthIn(explicitWidth, viewport.width) ?? viewport.width)
|
|
41
|
+
: (measured ?? widthIn(explicitWidth, undefined));
|
|
42
|
+
const layout = useTableLayout(available);
|
|
43
|
+
const measuring = layout.widths === undefined;
|
|
44
|
+
const total = layout.widths?.reduce((sum, width) => sum + width, 0) ?? 0;
|
|
45
|
+
const scrollPaint = viewport
|
|
46
|
+
? {
|
|
47
|
+
flexShrink: 0,
|
|
48
|
+
width: measuring ? 'auto' : Math.max(available ?? 0, total),
|
|
49
|
+
}
|
|
50
|
+
: undefined;
|
|
51
|
+
return (_jsx(TableLayout.Provider, { value: layout, children: _jsx(TableRowPosition.Provider, { value: undefined, children: _jsx(TablePart, { ...props, measuring: measuring, extraStyle: scrollPaint, onLayout: viewport ? undefined : (event) => setMeasured(event.nativeEvent.layout.width) }) }) }));
|
|
52
|
+
}
|
|
53
|
+
/** Assigns a starting column to each cell, advancing past its colspan. */
|
|
54
|
+
function TableRow(props) {
|
|
55
|
+
const inside = useContext(TableLayout) !== null;
|
|
56
|
+
useEffect(() => {
|
|
57
|
+
if (!inside && typeof __DEV__ !== 'undefined' && __DEV__) {
|
|
58
|
+
console.error('TableBox as="tr" requires a TableBox as="table" ancestor.');
|
|
59
|
+
}
|
|
60
|
+
}, [inside]);
|
|
61
|
+
let column = 0;
|
|
62
|
+
return (_jsx(TablePart, { ...props, children: flatten(props.children).map((child) => {
|
|
63
|
+
if (!isValidElement(child))
|
|
64
|
+
return null;
|
|
65
|
+
const start = column;
|
|
66
|
+
column += cellSpan(child.props.colSpan);
|
|
67
|
+
return (_jsx(TableColumn.Provider, { value: start, children: child }, child.key));
|
|
68
|
+
}) }));
|
|
69
|
+
}
|
|
70
|
+
/** A flex row whose cells stretch to its tallest cell. */
|
|
71
|
+
const ROW = { flexDirection: 'row', alignItems: 'stretch' };
|
|
72
|
+
/** Draws the table part with its inherited classes and optional press handlers. */
|
|
73
|
+
function TablePart({ extraStyle, measuring, onLayout, ...props }) {
|
|
74
|
+
const { as, className, style, webStyle, ref, children } = props;
|
|
75
|
+
const position = useContext(TableRowPosition);
|
|
76
|
+
const split = splitClasses(useTagClasses(className, as, position), useInheritedText(), dataAttributes(props));
|
|
77
|
+
const nativeRef = useNativeRef(ref);
|
|
78
|
+
const hostStyle = [
|
|
79
|
+
nativeStyle(style, webStyle),
|
|
80
|
+
useGridCell(),
|
|
81
|
+
as === 'tr' && ROW,
|
|
82
|
+
extraStyle,
|
|
83
|
+
measuring && { opacity: 0 },
|
|
84
|
+
];
|
|
85
|
+
const Host = isPressable(props) ? NativePressable : View;
|
|
86
|
+
return (_jsx(ElementScope, { split: split, children: _jsx(Host, { ...nativeAccessibility({ ...props, 'aria-hidden': measuring || props['aria-hidden'] }, as), ...pressProps(props), ref: nativeRef, onLayout: onLayout, pointerEvents: measuring ? 'none' : undefined, className: split.view || undefined, style: hostStyle, children: children }) }));
|
|
87
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TableCell: a native cell that shares its column widths with the table.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { type ReactElement } from 'react';
|
|
7
|
+
import type { TableCellProps } from '@molecule/app-ui';
|
|
8
|
+
import type { ElementNode, ElementRefProps } from './types.js';
|
|
9
|
+
/**
|
|
10
|
+
* Lays out the cell at the sum of its spanned column widths, with its header or cell role.
|
|
11
|
+
*
|
|
12
|
+
* @param props - The cell's props and ref.
|
|
13
|
+
* @returns The table cell.
|
|
14
|
+
*/
|
|
15
|
+
export declare function TableCell(props: TableCellProps<ElementNode> & ElementRefProps): ReactElement;
|
|
16
|
+
//# sourceMappingURL=TableCell.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TableCell.d.ts","sourceRoot":"","sources":["../../src/elements/TableCell.tsx"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,KAAK,YAAY,EAOlB,MAAM,OAAO,CAAA;AAGd,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAetD,OAAO,KAAK,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,YAAY,CAAA;AAE9D;;;;;GAKG;AACH,wBAAgB,SAAS,CAAC,KAAK,EAAE,cAAc,CAAC,WAAW,CAAC,GAAG,eAAe,GAAG,YAAY,CA+E5F"}
|