@vvedantb/native-ui 0.24.1 → 0.25.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/dist/DropdownMenu.jsx +245 -116
- package/dist/MenuSheet.jsx +164 -0
- package/dist/ReactionRow.jsx +84 -0
- package/dist/ai/index.js +2 -0
- package/dist/ai/message-action-sheet.jsx +182 -202
- package/dist/ai/message-context-menu.jsx +386 -0
- package/dist/ai/message-menu-layout.js +46 -0
- package/dist/ai/message.jsx +113 -69
- package/dist/entries/primitives.js +2 -0
- package/dist/index.js +2 -0
- package/dist/motion.js +31 -0
- package/dist/primitives/overlay.jsx +162 -101
- package/package.json +1 -1
- package/src/DropdownMenu.tsx +71 -16
- package/src/MenuSheet.tsx +80 -0
- package/src/ReactionRow.tsx +70 -0
- package/src/ai/index.ts +3 -0
- package/src/ai/message-action-sheet.tsx +92 -97
- package/src/ai/message-context-menu.tsx +183 -0
- package/src/ai/message-menu-layout.ts +44 -0
- package/src/ai/message.tsx +52 -6
- package/src/entries/primitives.ts +4 -0
- package/src/index.ts +4 -0
- package/src/motion.ts +15 -0
- package/src/primitives/overlay.tsx +48 -8
package/dist/ai/message.jsx
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { c as _c } from "react/compiler-runtime";
|
|
2
|
-
import { createContext, useContext, useEffect, useState } from "react";
|
|
2
|
+
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
3
3
|
import { Pressable, StyleSheet, Text, View } from "react-native";
|
|
4
4
|
import Animated, { useAnimatedStyle, useSharedValue, withTiming } from "react-native-reanimated";
|
|
5
5
|
import { IconArrowBackUp, IconCopy, IconRefresh, IconThumbDown, IconThumbUp } from "@tabler/icons-react-native";
|
|
6
6
|
import { cn } from "../cn";
|
|
7
|
+
import { impactHaptic } from "../haptics";
|
|
7
8
|
import { sizeStyle, typeStyle } from "../controlStyles";
|
|
8
9
|
import { palette, withAlpha } from "../palette";
|
|
9
10
|
import { useLargerText } from "../theme";
|
|
@@ -13,6 +14,7 @@ import { useScheme } from "../useScheme";
|
|
|
13
14
|
import { META_TEXT_STYLE, chatTextSize } from "./chat-text";
|
|
14
15
|
import { ChatIconButton } from "./icon-button";
|
|
15
16
|
import { MESSAGE_ACTIONS_TITLE, MessageActionSheet } from "./message-action-sheet";
|
|
17
|
+
import { MessageContextMenu } from "./message-context-menu";
|
|
16
18
|
import { ChatTextColorContext, ResponseText } from "./response-text";
|
|
17
19
|
const MessageContext = createContext("assistant");
|
|
18
20
|
|
|
@@ -104,19 +106,30 @@ function MessageHighlight() {
|
|
|
104
106
|
* at the start, its parts full width.
|
|
105
107
|
*
|
|
106
108
|
* With `onLongPress` or `actions` the message is a `Pressable` (same layout,
|
|
107
|
-
* `className`, `style` and view props)
|
|
109
|
+
* `className`, `style` and view props): a 350 ms hold shrinks it a little,
|
|
110
|
+
* fires a medium haptic, runs `onLongPress` and opens the
|
|
108
111
|
* `MessageActionSheet`; TalkBack reaches it as the `longpress` action. It stays
|
|
109
112
|
* a non-accessible container so its buttons and links keep their own focus:
|
|
110
113
|
* also offer the actions in a `MessageActionsBar` for screen reader users. `highlighted` draws the quote-jump highlight.
|
|
111
114
|
*/
|
|
115
|
+
/** How long a hold takes, in ms: shorter than React Native's 500, as iMessage. */
|
|
116
|
+
const HOLD_DELAY_MS = 350;
|
|
117
|
+
/** A held message: a little smaller and dimmer. */
|
|
118
|
+
const HELD_STYLE = {
|
|
119
|
+
transform: [{
|
|
120
|
+
scale: 0.98
|
|
121
|
+
}],
|
|
122
|
+
opacity: 0.9
|
|
123
|
+
};
|
|
112
124
|
export function Message(t0) {
|
|
113
|
-
const $ = _c(
|
|
125
|
+
const $ = _c(52);
|
|
114
126
|
let actionSheetTitle;
|
|
115
127
|
let actions;
|
|
116
128
|
let bot;
|
|
117
129
|
let children;
|
|
118
130
|
let className;
|
|
119
131
|
let from;
|
|
132
|
+
let menu;
|
|
120
133
|
let onLongPress;
|
|
121
134
|
let props;
|
|
122
135
|
let style;
|
|
@@ -127,6 +140,7 @@ export function Message(t0) {
|
|
|
127
140
|
className,
|
|
128
141
|
style,
|
|
129
142
|
onLongPress,
|
|
143
|
+
menu,
|
|
130
144
|
actions,
|
|
131
145
|
actionSheetTitle,
|
|
132
146
|
highlighted: t1,
|
|
@@ -141,10 +155,11 @@ export function Message(t0) {
|
|
|
141
155
|
$[4] = children;
|
|
142
156
|
$[5] = className;
|
|
143
157
|
$[6] = from;
|
|
144
|
-
$[7] =
|
|
145
|
-
$[8] =
|
|
146
|
-
$[9] =
|
|
147
|
-
$[10] =
|
|
158
|
+
$[7] = menu;
|
|
159
|
+
$[8] = onLongPress;
|
|
160
|
+
$[9] = props;
|
|
161
|
+
$[10] = style;
|
|
162
|
+
$[11] = t1;
|
|
148
163
|
} else {
|
|
149
164
|
actionSheetTitle = $[1];
|
|
150
165
|
actions = $[2];
|
|
@@ -152,124 +167,153 @@ export function Message(t0) {
|
|
|
152
167
|
children = $[4];
|
|
153
168
|
className = $[5];
|
|
154
169
|
from = $[6];
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
170
|
+
menu = $[7];
|
|
171
|
+
onLongPress = $[8];
|
|
172
|
+
props = $[9];
|
|
173
|
+
style = $[10];
|
|
174
|
+
t1 = $[11];
|
|
159
175
|
}
|
|
160
176
|
const highlighted = t1 === undefined ? false : t1;
|
|
161
177
|
const user = from === "user";
|
|
162
178
|
const [sheetOpen, setSheetOpen] = useState(false);
|
|
179
|
+
const [pressing, setPressing] = useState(false);
|
|
180
|
+
const [held, setHeld] = useState(null);
|
|
181
|
+
const pressable = useRef(null);
|
|
163
182
|
const hasActions = actions != null && actions.length > 0;
|
|
164
|
-
const longPressable = onLongPress != null || hasActions;
|
|
183
|
+
const longPressable = onLongPress != null || hasActions || menu != null;
|
|
165
184
|
let t2;
|
|
166
|
-
if ($[
|
|
185
|
+
if ($[12] !== hasActions || $[13] !== menu || $[14] !== onLongPress) {
|
|
167
186
|
t2 = () => {
|
|
187
|
+
impactHaptic("medium");
|
|
168
188
|
onLongPress?.();
|
|
169
|
-
if (
|
|
170
|
-
|
|
189
|
+
if (menu) {
|
|
190
|
+
const built = menu();
|
|
191
|
+
pressable.current?.measureInWindow((x, y, width, height) => setHeld({
|
|
192
|
+
anchor: {
|
|
193
|
+
x,
|
|
194
|
+
y,
|
|
195
|
+
width,
|
|
196
|
+
height
|
|
197
|
+
},
|
|
198
|
+
menu: built
|
|
199
|
+
}));
|
|
200
|
+
} else {
|
|
201
|
+
if (hasActions) {
|
|
202
|
+
setSheetOpen(true);
|
|
203
|
+
}
|
|
171
204
|
}
|
|
172
205
|
};
|
|
173
|
-
$[
|
|
174
|
-
$[
|
|
175
|
-
$[
|
|
206
|
+
$[12] = hasActions;
|
|
207
|
+
$[13] = menu;
|
|
208
|
+
$[14] = onLongPress;
|
|
209
|
+
$[15] = t2;
|
|
176
210
|
} else {
|
|
177
|
-
t2 = $[
|
|
211
|
+
t2 = $[15];
|
|
178
212
|
}
|
|
179
213
|
const longPress = t2;
|
|
180
214
|
const t3 = user ? "flex-end" : "flex-start";
|
|
181
215
|
const t4 = user ? "flex-end" : "stretch";
|
|
182
216
|
let t5;
|
|
183
|
-
if ($[
|
|
217
|
+
if ($[16] !== t3 || $[17] !== t4) {
|
|
184
218
|
t5 = {
|
|
185
219
|
alignSelf: t3,
|
|
186
220
|
alignItems: t4
|
|
187
221
|
};
|
|
188
|
-
$[
|
|
189
|
-
$[
|
|
190
|
-
$[
|
|
222
|
+
$[16] = t3;
|
|
223
|
+
$[17] = t4;
|
|
224
|
+
$[18] = t5;
|
|
191
225
|
} else {
|
|
192
|
-
t5 = $[
|
|
226
|
+
t5 = $[18];
|
|
193
227
|
}
|
|
194
228
|
let t6;
|
|
195
|
-
if ($[
|
|
229
|
+
if ($[19] !== style || $[20] !== t5) {
|
|
196
230
|
t6 = [t5, style];
|
|
197
|
-
$[
|
|
198
|
-
$[
|
|
199
|
-
$[
|
|
231
|
+
$[19] = style;
|
|
232
|
+
$[20] = t5;
|
|
233
|
+
$[21] = t6;
|
|
200
234
|
} else {
|
|
201
|
-
t6 = $[
|
|
235
|
+
t6 = $[21];
|
|
202
236
|
}
|
|
203
237
|
const layout = t6;
|
|
204
238
|
let t7;
|
|
205
|
-
if ($[
|
|
239
|
+
if ($[22] !== className) {
|
|
206
240
|
t7 = cn("w-full max-w-[95%] gap-2", className);
|
|
207
|
-
$[
|
|
208
|
-
$[
|
|
241
|
+
$[22] = className;
|
|
242
|
+
$[23] = t7;
|
|
209
243
|
} else {
|
|
210
|
-
t7 = $[
|
|
244
|
+
t7 = $[23];
|
|
211
245
|
}
|
|
212
246
|
const merged = t7;
|
|
213
247
|
let t8;
|
|
214
|
-
if ($[
|
|
248
|
+
if ($[24] !== bot || $[25] !== user) {
|
|
215
249
|
t8 = bot && !user ? <MessageBotLabel name={bot.name} avatar={bot.avatar} /> : null;
|
|
216
|
-
$[
|
|
217
|
-
$[
|
|
218
|
-
$[
|
|
250
|
+
$[24] = bot;
|
|
251
|
+
$[25] = user;
|
|
252
|
+
$[26] = t8;
|
|
219
253
|
} else {
|
|
220
|
-
t8 = $[
|
|
254
|
+
t8 = $[26];
|
|
221
255
|
}
|
|
222
256
|
let t9;
|
|
223
|
-
if ($[
|
|
257
|
+
if ($[27] !== highlighted) {
|
|
224
258
|
t9 = highlighted ? <MessageHighlight /> : null;
|
|
225
|
-
$[
|
|
226
|
-
$[
|
|
259
|
+
$[27] = highlighted;
|
|
260
|
+
$[28] = t9;
|
|
227
261
|
} else {
|
|
228
|
-
t9 = $[
|
|
262
|
+
t9 = $[28];
|
|
229
263
|
}
|
|
230
264
|
let t10;
|
|
231
|
-
if ($[
|
|
265
|
+
if ($[29] !== children || $[30] !== t8 || $[31] !== t9) {
|
|
232
266
|
t10 = <>{t8}{children}{t9}</>;
|
|
233
|
-
$[
|
|
234
|
-
$[
|
|
235
|
-
$[
|
|
236
|
-
$[
|
|
267
|
+
$[29] = children;
|
|
268
|
+
$[30] = t8;
|
|
269
|
+
$[31] = t9;
|
|
270
|
+
$[32] = t10;
|
|
237
271
|
} else {
|
|
238
|
-
t10 = $[
|
|
272
|
+
t10 = $[32];
|
|
239
273
|
}
|
|
240
274
|
const parts = t10;
|
|
241
275
|
let t11;
|
|
242
|
-
if ($[
|
|
243
|
-
t11 = longPressable ? <><Pressable accessible={false} className={merged} style={layout} onLongPress={longPress} accessibilityActions={[{
|
|
276
|
+
if ($[33] !== actionSheetTitle || $[34] !== actions || $[35] !== from || $[36] !== hasActions || $[37] !== held || $[38] !== layout || $[39] !== longPress || $[40] !== longPressable || $[41] !== menu || $[42] !== merged || $[43] !== parts || $[44] !== pressing || $[45] !== props || $[46] !== sheetOpen || $[47] !== user) {
|
|
277
|
+
t11 = longPressable ? <><Pressable ref={pressable} accessible={false} className={merged} style={[layout, pressing ? HELD_STYLE : null]} onPressIn={() => setPressing(true)} onPressOut={() => setPressing(false)} onLongPress={longPress} delayLongPress={HOLD_DELAY_MS} accessibilityActions={[{
|
|
244
278
|
name: "longpress",
|
|
245
279
|
label: actionSheetTitle ?? MESSAGE_ACTIONS_TITLE
|
|
246
280
|
}]} onAccessibilityAction={event => {
|
|
247
281
|
if (event.nativeEvent.actionName === "longpress") {
|
|
248
282
|
longPress();
|
|
249
283
|
}
|
|
250
|
-
}} {...props}>{parts}</Pressable>{
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
$[
|
|
257
|
-
$[
|
|
258
|
-
$[
|
|
259
|
-
$[
|
|
260
|
-
$[
|
|
261
|
-
$[
|
|
262
|
-
|
|
263
|
-
|
|
284
|
+
}} {...props}>{parts}</Pressable>{menu ? <MessageContextMenu open={held !== null} onClose={() => setHeld(null)} anchor={held?.anchor ?? null} align={user ? "end" : "start"} preview={<MessageContext.Provider value={from}><View className={merged} style={[layout, {
|
|
285
|
+
maxWidth: "100%",
|
|
286
|
+
width: "100%"
|
|
287
|
+
}]}>{parts}</View></MessageContext.Provider>} menu={held?.menu ?? {
|
|
288
|
+
actions: []
|
|
289
|
+
}} /> : hasActions ? <MessageActionSheet open={sheetOpen} onClose={() => setSheetOpen(false)} actions={actions} title={actionSheetTitle} /> : null}</> : <View className={merged} style={layout} {...props}>{parts}</View>;
|
|
290
|
+
$[33] = actionSheetTitle;
|
|
291
|
+
$[34] = actions;
|
|
292
|
+
$[35] = from;
|
|
293
|
+
$[36] = hasActions;
|
|
294
|
+
$[37] = held;
|
|
295
|
+
$[38] = layout;
|
|
296
|
+
$[39] = longPress;
|
|
297
|
+
$[40] = longPressable;
|
|
298
|
+
$[41] = menu;
|
|
299
|
+
$[42] = merged;
|
|
300
|
+
$[43] = parts;
|
|
301
|
+
$[44] = pressing;
|
|
302
|
+
$[45] = props;
|
|
303
|
+
$[46] = sheetOpen;
|
|
304
|
+
$[47] = user;
|
|
305
|
+
$[48] = t11;
|
|
306
|
+
} else {
|
|
307
|
+
t11 = $[48];
|
|
264
308
|
}
|
|
265
309
|
let t12;
|
|
266
|
-
if ($[
|
|
310
|
+
if ($[49] !== from || $[50] !== t11) {
|
|
267
311
|
t12 = <MessageContext.Provider value={from}>{t11}</MessageContext.Provider>;
|
|
268
|
-
$[
|
|
269
|
-
$[
|
|
270
|
-
$[
|
|
312
|
+
$[49] = from;
|
|
313
|
+
$[50] = t11;
|
|
314
|
+
$[51] = t12;
|
|
271
315
|
} else {
|
|
272
|
-
t12 = $[
|
|
316
|
+
t12 = $[51];
|
|
273
317
|
}
|
|
274
318
|
return t12;
|
|
275
319
|
}
|
|
@@ -19,6 +19,8 @@ export { ColorSwatches } from "../ColorSwatches";
|
|
|
19
19
|
export { StatGrid } from "../StatGrid";
|
|
20
20
|
export { SectionLabel } from "../SectionLabel";
|
|
21
21
|
export { SheetRow } from "../SheetRow";
|
|
22
|
+
export { MenuSheet, SubmenuRow, MenuDivider } from "../MenuSheet";
|
|
23
|
+
export { ReactionRow } from "../ReactionRow";
|
|
22
24
|
export { PageIndicator } from "../PageIndicator";
|
|
23
25
|
export { IconButton } from "../IconButton";
|
|
24
26
|
export { Stepper } from "../Stepper";
|
package/dist/index.js
CHANGED
|
@@ -27,6 +27,8 @@ export { ColorSwatches } from "./ColorSwatches";
|
|
|
27
27
|
export { StatGrid } from "./StatGrid";
|
|
28
28
|
export { SectionLabel } from "./SectionLabel";
|
|
29
29
|
export { SheetRow } from "./SheetRow";
|
|
30
|
+
export { MenuSheet, SubmenuRow, MenuDivider } from "./MenuSheet";
|
|
31
|
+
export { ReactionRow } from "./ReactionRow";
|
|
30
32
|
export { PageIndicator } from "./PageIndicator";
|
|
31
33
|
export { IconButton } from "./IconButton";
|
|
32
34
|
export { Stepper } from "./Stepper";
|
package/dist/motion.js
CHANGED
|
@@ -31,3 +31,34 @@ export const SHEET_SNAP_SPRING = {
|
|
|
31
31
|
export function usePressFeedback() {
|
|
32
32
|
return useReduceMotion() ? "active:opacity-80" : "active:scale-[0.97]";
|
|
33
33
|
}
|
|
34
|
+
|
|
35
|
+
/** Start scale of a popover or dialog panel as it opens: never from 0, as the `animate-expo` rules say. */
|
|
36
|
+
export const PANEL_SCALE_FROM = 0.96;
|
|
37
|
+
|
|
38
|
+
/** A menu panel opening from its trigger: opacity and scale together. */
|
|
39
|
+
export const POPOVER_ENTER = {
|
|
40
|
+
duration: 150,
|
|
41
|
+
easing: EASE_OUT,
|
|
42
|
+
reduceMotion: ReduceMotion.System
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
/** A menu panel leaving: a quick fade only. */
|
|
46
|
+
export const POPOVER_EXIT = {
|
|
47
|
+
duration: 100,
|
|
48
|
+
easing: EASE_OUT,
|
|
49
|
+
reduceMotion: ReduceMotion.System
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/** A centred dialog opening: the backdrop fades while the panel scales and fades in. */
|
|
53
|
+
export const DIALOG_ENTER = {
|
|
54
|
+
duration: 200,
|
|
55
|
+
easing: EASE_OUT,
|
|
56
|
+
reduceMotion: ReduceMotion.System
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
/** A centred dialog closing. */
|
|
60
|
+
export const DIALOG_EXIT = {
|
|
61
|
+
duration: 150,
|
|
62
|
+
easing: EASE_OUT,
|
|
63
|
+
reduceMotion: ReduceMotion.System
|
|
64
|
+
};
|