glacia-native 0.3.5 → 0.4.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/lib/module/Button.js +15 -2
- package/lib/module/Card.js +29 -14
- package/lib/module/Dialog.js +43 -32
- package/lib/module/Form.js +51 -12
- package/lib/module/Glass.js +11 -2
- package/lib/module/Input.js +19 -7
- package/lib/module/SegmentedControl.js +65 -21
- package/lib/module/Slider.js +121 -25
- package/lib/module/Switch.js +33 -15
- package/lib/module/TabBar.js +63 -25
- package/lib/module/Table.js +24 -6
- package/lib/module/Tabs.js +55 -33
- package/lib/module/ai.js +49 -20
- package/lib/module/charts/BarChart.js +4 -2
- package/lib/module/charts/FunnelChart.js +4 -2
- package/lib/module/charts/HeatmapChart.js +4 -2
- package/lib/module/charts/LineChart.js +4 -2
- package/lib/module/charts/PlotChart.js +11 -3
- package/lib/module/charts/RadarChart.js +4 -2
- package/lib/module/charts/RingChart.js +4 -2
- package/lib/module/charts/ScatterChart.js +20 -3
- package/lib/module/charts/WaterfallChart.js +12 -3
- package/lib/module/charts/advanced.js +12 -6
- package/lib/module/charts/extra.js +6 -3
- package/lib/module/internal/GlassView.js +17 -19
- package/lib/module/internal/fallback.js +14 -3
- package/lib/module/internal/glass-routing.js +56 -0
- package/lib/module/internal/motion.js +55 -0
- package/lib/module/internal/primitives.js +408 -0
- package/lib/typescript/Button.d.ts +11 -1
- package/lib/typescript/Card.d.ts +20 -8
- package/lib/typescript/Dialog.d.ts +19 -6
- package/lib/typescript/Form.d.ts +27 -11
- package/lib/typescript/Glass.d.ts +9 -0
- package/lib/typescript/Input.d.ts +11 -1
- package/lib/typescript/SegmentedControl.d.ts +11 -1
- package/lib/typescript/Slider.d.ts +13 -1
- package/lib/typescript/Switch.d.ts +12 -1
- package/lib/typescript/TabBar.d.ts +13 -1
- package/lib/typescript/Table.d.ts +14 -5
- package/lib/typescript/Tabs.d.ts +8 -5
- package/lib/typescript/ai.d.ts +12 -9
- package/lib/typescript/charts/BarChart.d.ts +1 -1
- package/lib/typescript/charts/FunnelChart.d.ts +1 -1
- package/lib/typescript/charts/HeatmapChart.d.ts +1 -1
- package/lib/typescript/charts/LineChart.d.ts +1 -1
- package/lib/typescript/charts/PlotChart.d.ts +1 -1
- package/lib/typescript/charts/RadarChart.d.ts +1 -1
- package/lib/typescript/charts/RingChart.d.ts +1 -1
- package/lib/typescript/charts/ScatterChart.d.ts +1 -1
- package/lib/typescript/charts/WaterfallChart.d.ts +1 -1
- package/lib/typescript/charts/advanced.d.ts +5 -5
- package/lib/typescript/charts/extra.d.ts +2 -2
- package/lib/typescript/internal/GlassView.d.ts +11 -3
- package/lib/typescript/internal/fallback.d.ts +10 -1
- package/lib/typescript/internal/glass-routing.d.ts +30 -0
- package/lib/typescript/internal/motion.d.ts +19 -0
- package/lib/typescript/internal/primitives.d.ts +41 -0
- package/package.json +2 -2
- package/src/Button.tsx +47 -22
- package/src/Card.tsx +52 -31
- package/src/Dialog.tsx +99 -64
- package/src/Form.tsx +90 -25
- package/src/Glass.tsx +24 -1
- package/src/Input.tsx +33 -12
- package/src/SegmentedControl.tsx +104 -32
- package/src/Slider.tsx +151 -47
- package/src/Switch.tsx +56 -32
- package/src/TabBar.tsx +100 -30
- package/src/Table.tsx +38 -14
- package/src/Tabs.tsx +85 -32
- package/src/ai.tsx +77 -31
- package/src/charts/BarChart.tsx +4 -2
- package/src/charts/FunnelChart.tsx +4 -2
- package/src/charts/HeatmapChart.tsx +4 -2
- package/src/charts/LineChart.tsx +4 -2
- package/src/charts/PlotChart.tsx +23 -3
- package/src/charts/RadarChart.tsx +4 -2
- package/src/charts/RingChart.tsx +4 -2
- package/src/charts/ScatterChart.tsx +24 -3
- package/src/charts/WaterfallChart.tsx +21 -3
- package/src/charts/advanced.tsx +12 -6
- package/src/charts/extra.tsx +6 -3
- package/src/internal/GlassView.tsx +31 -21
- package/src/internal/fallback.tsx +23 -8
- package/src/internal/glass-routing.ts +68 -0
- package/src/internal/motion.ts +60 -0
- package/src/internal/primitives.ts +477 -0
- package/lib/module/charts/primitives.js +0 -212
- package/lib/typescript/charts/primitives.d.ts +0 -23
- package/src/charts/primitives.ts +0 -262
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
/** Minimal shapes of the RN primitives the charts use. */
|
|
2
|
-
export interface RNPrimitives {
|
|
3
|
-
View: any;
|
|
4
|
-
Text: any;
|
|
5
|
-
Pressable: any;
|
|
6
|
-
Svg: any;
|
|
7
|
-
G: any;
|
|
8
|
-
Line: any;
|
|
9
|
-
Path: any;
|
|
10
|
-
Circle: any;
|
|
11
|
-
Rect: any;
|
|
12
|
-
Polygon: any;
|
|
13
|
-
SvgText: any;
|
|
14
|
-
TextInput: any;
|
|
15
|
-
Modal: any;
|
|
16
|
-
Image: any;
|
|
17
|
-
/** React Native's ScrollView, or null when it is unavailable. */
|
|
18
|
-
getScrollView: () => any;
|
|
19
|
-
/** React Native's BackHandler, or null outside a native runtime. */
|
|
20
|
-
getBackHandler: () => any;
|
|
21
|
-
}
|
|
22
|
-
/** The resolved primitives, computed once per process. */
|
|
23
|
-
export declare function primitives(): RNPrimitives;
|
package/src/charts/primitives.ts
DELETED
|
@@ -1,262 +0,0 @@
|
|
|
1
|
-
// React Native component resolution.
|
|
2
|
-
//
|
|
3
|
-
// The package never imports `react-native` or `react-native-svg` statically:
|
|
4
|
-
// both ship Flow-typed sources that a plain JS bundler (and the jsdom test
|
|
5
|
-
// environment) cannot parse. Resolving them at runtime keeps the package
|
|
6
|
-
// importable everywhere, matching how GlassView already locates the native
|
|
7
|
-
// liquid glass module.
|
|
8
|
-
|
|
9
|
-
declare const require: any;
|
|
10
|
-
|
|
11
|
-
/** Minimal shapes of the RN primitives the charts use. */
|
|
12
|
-
export interface RNPrimitives {
|
|
13
|
-
View: any;
|
|
14
|
-
Text: any;
|
|
15
|
-
Pressable: any;
|
|
16
|
-
Svg: any;
|
|
17
|
-
G: any;
|
|
18
|
-
Line: any;
|
|
19
|
-
Path: any;
|
|
20
|
-
Circle: any;
|
|
21
|
-
Rect: any;
|
|
22
|
-
Polygon: any;
|
|
23
|
-
SvgText: any;
|
|
24
|
-
TextInput: any;
|
|
25
|
-
Modal: any;
|
|
26
|
-
Image: any;
|
|
27
|
-
/** React Native's ScrollView, or null when it is unavailable. */
|
|
28
|
-
getScrollView: () => any;
|
|
29
|
-
/** React Native's BackHandler, or null outside a native runtime. */
|
|
30
|
-
getBackHandler: () => any;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* Resolves the primitives, falling back to pass-through DOM elements so the
|
|
35
|
-
* package can be rendered in a non-native environment (tests, web preview)
|
|
36
|
-
* without throwing.
|
|
37
|
-
*/
|
|
38
|
-
function resolve(): RNPrimitives {
|
|
39
|
-
let View: any;
|
|
40
|
-
let Text: any;
|
|
41
|
-
let Pressable: any;
|
|
42
|
-
let svg: any = null;
|
|
43
|
-
let rn: any = null;
|
|
44
|
-
|
|
45
|
-
try {
|
|
46
|
-
rn = require("react-native");
|
|
47
|
-
View = rn.View;
|
|
48
|
-
Text = rn.Text;
|
|
49
|
-
Pressable = rn.Pressable;
|
|
50
|
-
} catch {
|
|
51
|
-
// Non-native environment: render simple elements instead.
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
try {
|
|
55
|
-
svg = require("react-native-svg");
|
|
56
|
-
} catch {
|
|
57
|
-
svg = null;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Adapts React Native props to the DOM preview used when RN is absent.
|
|
62
|
-
* Without this, `accessibilityRole` and `onPress` reach the DOM untranslated
|
|
63
|
-
* and the element is neither reachable nor clickable in tests.
|
|
64
|
-
*/
|
|
65
|
-
const fallback = (tag: string) =>
|
|
66
|
-
function Primitive(props: any) {
|
|
67
|
-
const {
|
|
68
|
-
children,
|
|
69
|
-
style,
|
|
70
|
-
accessibilityRole,
|
|
71
|
-
accessibilityLabel,
|
|
72
|
-
accessibilityState,
|
|
73
|
-
onPress,
|
|
74
|
-
numberOfLines,
|
|
75
|
-
onChangeText,
|
|
76
|
-
value,
|
|
77
|
-
editable,
|
|
78
|
-
nativeID,
|
|
79
|
-
disabled,
|
|
80
|
-
keyboardType: _keyboardType,
|
|
81
|
-
returnKeyType: _returnKeyType,
|
|
82
|
-
onSubmitEditing: _onSubmitEditing,
|
|
83
|
-
secureTextEntry: _secureTextEntry,
|
|
84
|
-
autoCapitalize: _autoCapitalize,
|
|
85
|
-
autoCorrect: _autoCorrect,
|
|
86
|
-
multiline,
|
|
87
|
-
onFocus: _onFocus,
|
|
88
|
-
onBlur: _onBlur,
|
|
89
|
-
editable: _editable,
|
|
90
|
-
...rest
|
|
91
|
-
} = props ?? {};
|
|
92
|
-
const { createElement } = require("react");
|
|
93
|
-
|
|
94
|
-
// RN accepts unitless numbers where the DOM requires "px"; convert the
|
|
95
|
-
// length properties so the preview lays out instead of throwing.
|
|
96
|
-
const domProps: any = { style: toDomStyle(style), ...rest };
|
|
97
|
-
|
|
98
|
-
// RN roles that already exist in ARIA pass straight through.
|
|
99
|
-
const ROLE_MAP: Record<string, string> = {
|
|
100
|
-
button: "button",
|
|
101
|
-
checkbox: "checkbox",
|
|
102
|
-
radio: "radio",
|
|
103
|
-
radiogroup: "radiogroup",
|
|
104
|
-
alert: "alert",
|
|
105
|
-
text: "text",
|
|
106
|
-
link: "link",
|
|
107
|
-
image: "img",
|
|
108
|
-
tab: "tab",
|
|
109
|
-
progressbar: "progressbar",
|
|
110
|
-
tablist: "tablist",
|
|
111
|
-
switch: "switch",
|
|
112
|
-
slider: "slider",
|
|
113
|
-
heading: "heading",
|
|
114
|
-
};
|
|
115
|
-
// "none" means presentational: emit no role rather than a misleading one.
|
|
116
|
-
if (accessibilityRole && accessibilityRole !== "none") {
|
|
117
|
-
domProps.role = ROLE_MAP[accessibilityRole] ?? "text";
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
if (accessibilityLabel != null) domProps["aria-label"] = accessibilityLabel;
|
|
121
|
-
if (numberOfLines != null) domProps["data-lines"] = numberOfLines;
|
|
122
|
-
if (nativeID != null) domProps.id = nativeID;
|
|
123
|
-
|
|
124
|
-
if (accessibilityState) {
|
|
125
|
-
const state = accessibilityState;
|
|
126
|
-
if (state.checked !== undefined) domProps["aria-checked"] = state.checked;
|
|
127
|
-
if (state.selected !== undefined) domProps["aria-selected"] = state.selected;
|
|
128
|
-
if (state.expanded !== undefined) domProps["aria-expanded"] = state.expanded;
|
|
129
|
-
if (state.disabled !== undefined) domProps["aria-disabled"] = state.disabled;
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
// Inputs: bridge the RN controlled-value contract to the DOM one.
|
|
133
|
-
if (tag === "input") {
|
|
134
|
-
// A multiline field must be a real textarea: an <input> cannot wrap.
|
|
135
|
-
if (multiline) {
|
|
136
|
-
tag = "textarea";
|
|
137
|
-
if (typeof numberOfLines === "number") domProps.rows = numberOfLines;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
if (tag === "input" || tag === "textarea") {
|
|
142
|
-
if (value != null) domProps.value = value;
|
|
143
|
-
if (onChangeText) {
|
|
144
|
-
domProps.onChange = (event: any) => onChangeText(event.target.value);
|
|
145
|
-
}
|
|
146
|
-
if (editable === false || disabled) domProps.disabled = true;
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (onPress) {
|
|
150
|
-
if (tag === "button" || tag === "input") domProps.onClick = onPress;
|
|
151
|
-
else {
|
|
152
|
-
// A non-button element needs to be operable from the keyboard too.
|
|
153
|
-
domProps.onClick = onPress;
|
|
154
|
-
if (domProps.role === "button" || domProps.role === "checkbox" || domProps.role === "radio") {
|
|
155
|
-
domProps.tabIndex = 0;
|
|
156
|
-
}
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
if (disabled) domProps["aria-disabled"] = true;
|
|
160
|
-
|
|
161
|
-
return createElement(tag, domProps, children);
|
|
162
|
-
};
|
|
163
|
-
|
|
164
|
-
/** Resolves React Native's BackHandler, or null off-device. */
|
|
165
|
-
const getBackHandler = () => rn?.BackHandler ?? null;
|
|
166
|
-
|
|
167
|
-
/**
|
|
168
|
-
* A Modal that only mounts its children while visible.
|
|
169
|
-
*
|
|
170
|
-
* The generic fallback would render the content regardless of `visible`,
|
|
171
|
-
* which would surface every closed dialog in the DOM preview.
|
|
172
|
-
*/
|
|
173
|
-
const modalFallback = (tag: string) =>
|
|
174
|
-
function Primitive(props: any) {
|
|
175
|
-
const { children, visible, onRequestClose, ...rest } = props ?? {};
|
|
176
|
-
if (!visible) return null;
|
|
177
|
-
const { createElement } = require("react");
|
|
178
|
-
return createElement(tag, { style: toDomStyle(rest.style) }, children);
|
|
179
|
-
};
|
|
180
|
-
|
|
181
|
-
/** An image that reads its remote source in the DOM preview. */
|
|
182
|
-
function imageFallback(props: any) {
|
|
183
|
-
const { source, accessibilityLabel, style } = props ?? {};
|
|
184
|
-
const { createElement } = require("react");
|
|
185
|
-
return createElement("img", {
|
|
186
|
-
src: source?.uri,
|
|
187
|
-
alt: accessibilityLabel ?? "",
|
|
188
|
-
style: toDomStyle(style),
|
|
189
|
-
});
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
const SvgComponent = svg?.default ?? fallback("svg");
|
|
193
|
-
const SvgText = svg?.Text ?? fallback("text");
|
|
194
|
-
|
|
195
|
-
return {
|
|
196
|
-
View: View ?? fallback("div"),
|
|
197
|
-
Text: Text ?? fallback("span"),
|
|
198
|
-
Pressable: Pressable ?? fallback("button"),
|
|
199
|
-
Svg: SvgComponent,
|
|
200
|
-
G: svg?.G ?? fallback("g"),
|
|
201
|
-
Line: svg?.Line ?? fallback("line"),
|
|
202
|
-
Path: svg?.Path ?? fallback("path"),
|
|
203
|
-
Circle: svg?.Circle ?? fallback("circle"),
|
|
204
|
-
Rect: svg?.Rect ?? fallback("rect"),
|
|
205
|
-
Polygon: svg?.Polygon ?? fallback("polygon"),
|
|
206
|
-
// TextInput is not an SVG primitive, but resolving it here keeps every
|
|
207
|
-
// component on one runtime-resolution path instead of two.
|
|
208
|
-
TextInput: rn?.TextInput ?? fallback("input"),
|
|
209
|
-
// Modal is resolved the same way so dialogs degrade to a plain overlay
|
|
210
|
-
// outside a native runtime instead of failing to mount.
|
|
211
|
-
Modal: rn?.Modal ?? modalFallback("div"),
|
|
212
|
-
Image: rn?.Image ?? imageFallback,
|
|
213
|
-
getScrollView: () => rn?.ScrollView ?? null,
|
|
214
|
-
getBackHandler,
|
|
215
|
-
SvgText,
|
|
216
|
-
};
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
const LENGTH_PROPS = new Set([
|
|
220
|
-
"width",
|
|
221
|
-
"height",
|
|
222
|
-
"top",
|
|
223
|
-
"left",
|
|
224
|
-
"right",
|
|
225
|
-
"bottom",
|
|
226
|
-
"marginTop",
|
|
227
|
-
"marginBottom",
|
|
228
|
-
"marginLeft",
|
|
229
|
-
"marginRight",
|
|
230
|
-
"paddingTop",
|
|
231
|
-
"paddingBottom",
|
|
232
|
-
"paddingLeft",
|
|
233
|
-
"paddingRight",
|
|
234
|
-
"fontSize",
|
|
235
|
-
"borderRadius",
|
|
236
|
-
"gap",
|
|
237
|
-
]);
|
|
238
|
-
|
|
239
|
-
/** Converts an RN style object to DOM-compatible CSS. */
|
|
240
|
-
function toDomStyle(style: any): any {
|
|
241
|
-
if (!style) return style;
|
|
242
|
-
const list = Array.isArray(style) ? style : [style];
|
|
243
|
-
const merged: Record<string, any> = {};
|
|
244
|
-
|
|
245
|
-
for (const entry of list) {
|
|
246
|
-
if (!entry) continue;
|
|
247
|
-
for (const [key, value] of Object.entries(entry)) {
|
|
248
|
-
if (value == null) continue;
|
|
249
|
-
merged[key] =
|
|
250
|
-
typeof value === "number" && LENGTH_PROPS.has(key) ? `${value}px` : value;
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
return merged;
|
|
254
|
-
}
|
|
255
|
-
|
|
256
|
-
let cache: RNPrimitives | null = null;
|
|
257
|
-
|
|
258
|
-
/** The resolved primitives, computed once per process. */
|
|
259
|
-
export function primitives(): RNPrimitives {
|
|
260
|
-
if (!cache) cache = resolve();
|
|
261
|
-
return cache;
|
|
262
|
-
}
|