@vvedantb/native-ui 0.25.3 → 0.26.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/ai/prompt-input.jsx +76 -38
- package/dist/entries/paste-input.js +4 -0
- package/dist/primitives/paste-input.jsx +63 -0
- package/dist/primitives/paste-parts.jsx +18 -0
- package/package.json +10 -1
- package/src/ai/prompt-input.tsx +89 -50
- package/src/entries/paste-input.ts +4 -0
- package/src/primitives/paste-input.tsx +29 -0
- package/src/primitives/paste-parts.tsx +27 -0
package/dist/ai/prompt-input.jsx
CHANGED
|
@@ -9,6 +9,7 @@ import { withAlpha } from "../palette";
|
|
|
9
9
|
import { tokens } from "../tokens";
|
|
10
10
|
import { Input as FieldInput } from "../primitives/input";
|
|
11
11
|
import { COMPOSER_INPUT_ID, KeyboardAvoidingView, KeyboardLiftContext } from "../primitives/keyboard-parts";
|
|
12
|
+
import { usePasteParts } from "../primitives/paste-parts";
|
|
12
13
|
import { usePressFeedback } from "../motion";
|
|
13
14
|
import { useControllableState } from "../primitives/use-controllable-state";
|
|
14
15
|
import { useLargerText } from "../theme";
|
|
@@ -381,7 +382,7 @@ const ONE_ROW = Platform.OS === "web" ? 1 : undefined;
|
|
|
381
382
|
* with `KeyboardControllerProvider`, `ChatThread`) it adds no lift of its own.
|
|
382
383
|
*/
|
|
383
384
|
export function PromptInput(t0) {
|
|
384
|
-
const $ = _c(
|
|
385
|
+
const $ = _c(67);
|
|
385
386
|
const {
|
|
386
387
|
value,
|
|
387
388
|
defaultValue: t1,
|
|
@@ -396,6 +397,7 @@ export function PromptInput(t0) {
|
|
|
396
397
|
toolbar,
|
|
397
398
|
footer,
|
|
398
399
|
menu,
|
|
400
|
+
onPasteImages,
|
|
399
401
|
layout: t4,
|
|
400
402
|
shape: t5,
|
|
401
403
|
leading,
|
|
@@ -417,6 +419,8 @@ export function PromptInput(t0) {
|
|
|
417
419
|
const largerText = useLargerText();
|
|
418
420
|
const insets = useSafeAreaInsets();
|
|
419
421
|
const lifted = useContext(KeyboardLiftContext);
|
|
422
|
+
const paste = usePasteParts();
|
|
423
|
+
const pasteTarget = paste && onPasteImages ? paste.Target : null;
|
|
420
424
|
let t9;
|
|
421
425
|
if ($[0] !== defaultValue || $[1] !== onChangeText || $[2] !== value) {
|
|
422
426
|
t9 = {
|
|
@@ -550,7 +554,7 @@ export function PromptInput(t0) {
|
|
|
550
554
|
t21 = $[31];
|
|
551
555
|
}
|
|
552
556
|
let t22;
|
|
553
|
-
if ($[32] !== accessibilityLabel || $[33] !== canSubmit || $[34] !== changeText || $[35] !== disabled || $[36] !== fieldText || $[37] !== growStyle || $[38] !== header || $[39] !== largerText || $[40] !== layout || $[41] !== leading || $[42] !== maxHeight || $[43] !==
|
|
557
|
+
if ($[32] !== accessibilityLabel || $[33] !== canSubmit || $[34] !== changeText || $[35] !== disabled || $[36] !== fieldText || $[37] !== growStyle || $[38] !== header || $[39] !== largerText || $[40] !== layout || $[41] !== leading || $[42] !== maxHeight || $[43] !== onPasteImages || $[44] !== onStop || $[45] !== pasteTarget || $[46] !== pill || $[47] !== placeholder || $[48] !== replyTo || $[49] !== scheme || $[50] !== scrollEnabled || $[51] !== status || $[52] !== submit || $[53] !== testID || $[54] !== text || $[55] !== toolbar) {
|
|
554
558
|
t22 = layout === "inline" ? <View className="border" style={[fieldStyle(scheme), {
|
|
555
559
|
borderRadius: pill ? PILL.radius : INLINE_RADIUS
|
|
556
560
|
}]}>{replyTo ? <View className="px-1.5 pt-1.5">{replyTo}</View> : null}{header ? <View className="flex-row flex-wrap gap-1 px-1.5 pt-1.5">{header}</View> : null}<View className={cn("flex-row items-end gap-1", !pill && "p-1.5")} style={pill ? {
|
|
@@ -558,17 +562,17 @@ export function PromptInput(t0) {
|
|
|
558
562
|
paddingHorizontal: PILL.paddingX
|
|
559
563
|
} : null}>{leading ? <View className="shrink-0 flex-row items-center gap-1" style={pill ? {
|
|
560
564
|
minHeight: PILL.lineHeight
|
|
561
|
-
} : null}>{leading}</View> : null}<FieldInput testID={testID ? `${testID}-input` : undefined} nativeID={COMPOSER_INPUT_ID} multiline={true} numberOfLines={ONE_ROW} value={text} onChangeText={changeText} placeholder={placeholder} placeholderTextColor={pill ? withAlpha(tokens.color.muted[scheme], PILL.placeholderAlpha) : undefined} accessibilityLabel={accessibilityLabel} editable={!disabled} textAlignVertical="center" scrollEnabled={scrollEnabled} onContentSizeChange={e => setContentHeight(e.nativeEvent.contentSize.height)} className={cn("flex-1 border-0 text-sm font-instrument-sans", pill ? "min-h-9 px-1 py-2" : "min-h-8 px-2 py-1", largerText && "min-h-11 py-2 text-xl font-instrument-sans-medium")} style={[fieldTextStyle(scheme), fieldText, largerText ? typeStyle("medium") : null, {
|
|
565
|
+
} : null}>{leading}</View> : null}<PasteTarget target={pasteTarget} onPasteImages={onPasteImages} style={PASTE_TARGET_INLINE}><FieldInput testID={testID ? `${testID}-input` : undefined} nativeID={COMPOSER_INPUT_ID} multiline={true} numberOfLines={ONE_ROW} value={text} onChangeText={changeText} placeholder={placeholder} placeholderTextColor={pill ? withAlpha(tokens.color.muted[scheme], PILL.placeholderAlpha) : undefined} accessibilityLabel={accessibilityLabel} editable={!disabled} textAlignVertical="center" scrollEnabled={scrollEnabled} onContentSizeChange={e => setContentHeight(e.nativeEvent.contentSize.height)} className={cn(pasteTarget ? "border-0 text-sm font-instrument-sans" : "flex-1 border-0 text-sm font-instrument-sans", pill ? "min-h-9 px-1 py-2" : "min-h-8 px-2 py-1", largerText && "min-h-11 py-2 text-xl font-instrument-sans-medium")} style={[fieldTextStyle(scheme), fieldText, largerText ? typeStyle("medium") : null, {
|
|
566
|
+
backgroundColor: "transparent",
|
|
567
|
+
maxHeight,
|
|
568
|
+
...growStyle
|
|
569
|
+
}]} /></PasteTarget><View className="shrink-0 flex-row items-center gap-1" style={pill ? {
|
|
570
|
+
minHeight: PILL.lineHeight
|
|
571
|
+
} : null}>{toolbar}<PromptInputSubmit status={status} onSubmit={submit} onStop={onStop} canSubmit={canSubmit} size={pill ? "md" : undefined} /></View></View></View> : <View className="border" style={fieldStyle(scheme)}>{replyTo ? <View className="px-2 pt-2">{replyTo}</View> : null}{header ? <View className="flex-row flex-wrap gap-1 px-2 pt-2">{header}</View> : null}<PasteTarget target={pasteTarget} onPasteImages={onPasteImages}><FieldInput testID={testID ? `${testID}-input` : undefined} nativeID={COMPOSER_INPUT_ID} multiline={true} numberOfLines={ONE_ROW} value={text} onChangeText={changeText} placeholder={placeholder} accessibilityLabel={accessibilityLabel} editable={!disabled} textAlignVertical="top" scrollEnabled={scrollEnabled} onContentSizeChange={e_0 => setContentHeight(e_0.nativeEvent.contentSize.height)} className={cn("min-h-11 border-0 px-3.5 py-2.5 text-base font-instrument-sans", largerText && "min-h-14 px-4 py-3 text-xl font-instrument-sans-medium")} style={[fieldTextStyle(scheme), fieldText, largerText ? typeStyle("medium") : null, {
|
|
562
572
|
backgroundColor: "transparent",
|
|
563
573
|
maxHeight,
|
|
564
574
|
...growStyle
|
|
565
|
-
}]}
|
|
566
|
-
minHeight: PILL.lineHeight
|
|
567
|
-
} : null}>{toolbar}<PromptInputSubmit status={status} onSubmit={submit} onStop={onStop} canSubmit={canSubmit} size={pill ? "md" : undefined} /></View></View></View> : <View className="border" style={fieldStyle(scheme)}>{replyTo ? <View className="px-2 pt-2">{replyTo}</View> : null}{header ? <View className="flex-row flex-wrap gap-1 px-2 pt-2">{header}</View> : null}<FieldInput testID={testID ? `${testID}-input` : undefined} nativeID={COMPOSER_INPUT_ID} multiline={true} numberOfLines={ONE_ROW} value={text} onChangeText={changeText} placeholder={placeholder} accessibilityLabel={accessibilityLabel} editable={!disabled} textAlignVertical="top" scrollEnabled={scrollEnabled} onContentSizeChange={e_0 => setContentHeight(e_0.nativeEvent.contentSize.height)} className={cn("min-h-11 border-0 px-3.5 py-2.5 text-base font-instrument-sans", largerText && "min-h-14 px-4 py-3 text-xl font-instrument-sans-medium")} style={[fieldTextStyle(scheme), fieldText, largerText ? typeStyle("medium") : null, {
|
|
568
|
-
backgroundColor: "transparent",
|
|
569
|
-
maxHeight,
|
|
570
|
-
...growStyle
|
|
571
|
-
}]} /><View className="flex-row items-center justify-between gap-1 px-2 pb-2"><View className="min-w-0 shrink flex-row items-center gap-1">{toolbar}</View><PromptInputSubmit status={status} onSubmit={submit} onStop={onStop} canSubmit={canSubmit} /></View></View>;
|
|
575
|
+
}]} /></PasteTarget><View className="flex-row items-center justify-between gap-1 px-2 pb-2"><View className="min-w-0 shrink flex-row items-center gap-1">{toolbar}</View><PromptInputSubmit status={status} onSubmit={submit} onStop={onStop} canSubmit={canSubmit} /></View></View>;
|
|
572
576
|
$[32] = accessibilityLabel;
|
|
573
577
|
$[33] = canSubmit;
|
|
574
578
|
$[34] = changeText;
|
|
@@ -580,33 +584,35 @@ export function PromptInput(t0) {
|
|
|
580
584
|
$[40] = layout;
|
|
581
585
|
$[41] = leading;
|
|
582
586
|
$[42] = maxHeight;
|
|
583
|
-
$[43] =
|
|
584
|
-
$[44] =
|
|
585
|
-
$[45] =
|
|
586
|
-
$[46] =
|
|
587
|
-
$[47] =
|
|
588
|
-
$[48] =
|
|
589
|
-
$[49] =
|
|
590
|
-
$[50] =
|
|
591
|
-
$[51] =
|
|
592
|
-
$[52] =
|
|
593
|
-
$[53] =
|
|
594
|
-
$[54] =
|
|
595
|
-
|
|
596
|
-
|
|
587
|
+
$[43] = onPasteImages;
|
|
588
|
+
$[44] = onStop;
|
|
589
|
+
$[45] = pasteTarget;
|
|
590
|
+
$[46] = pill;
|
|
591
|
+
$[47] = placeholder;
|
|
592
|
+
$[48] = replyTo;
|
|
593
|
+
$[49] = scheme;
|
|
594
|
+
$[50] = scrollEnabled;
|
|
595
|
+
$[51] = status;
|
|
596
|
+
$[52] = submit;
|
|
597
|
+
$[53] = testID;
|
|
598
|
+
$[54] = text;
|
|
599
|
+
$[55] = toolbar;
|
|
600
|
+
$[56] = t22;
|
|
601
|
+
} else {
|
|
602
|
+
t22 = $[56];
|
|
597
603
|
}
|
|
598
604
|
let t23;
|
|
599
|
-
if ($[
|
|
605
|
+
if ($[57] !== footer || $[58] !== t16 || $[59] !== t20 || $[60] !== t21 || $[61] !== t22 || $[62] !== testID) {
|
|
600
606
|
t23 = <View testID={testID} className={t16} style={t20}>{t21}{t22}{footer}</View>;
|
|
601
|
-
$[
|
|
602
|
-
$[
|
|
603
|
-
$[
|
|
604
|
-
$[
|
|
605
|
-
$[
|
|
606
|
-
$[
|
|
607
|
-
$[
|
|
607
|
+
$[57] = footer;
|
|
608
|
+
$[58] = t16;
|
|
609
|
+
$[59] = t20;
|
|
610
|
+
$[60] = t21;
|
|
611
|
+
$[61] = t22;
|
|
612
|
+
$[62] = testID;
|
|
613
|
+
$[63] = t23;
|
|
608
614
|
} else {
|
|
609
|
-
t23 = $[
|
|
615
|
+
t23 = $[63];
|
|
610
616
|
}
|
|
611
617
|
const composer = t23;
|
|
612
618
|
if (lifted) {
|
|
@@ -614,13 +620,45 @@ export function PromptInput(t0) {
|
|
|
614
620
|
}
|
|
615
621
|
const t24 = keyboardVerticalOffset - bottom;
|
|
616
622
|
let t25;
|
|
617
|
-
if ($[
|
|
623
|
+
if ($[64] !== composer || $[65] !== t24) {
|
|
618
624
|
t25 = <KeyboardAvoidingView keyboardVerticalOffset={t24}>{composer}</KeyboardAvoidingView>;
|
|
619
|
-
$[
|
|
620
|
-
$[
|
|
621
|
-
$[
|
|
625
|
+
$[64] = composer;
|
|
626
|
+
$[65] = t24;
|
|
627
|
+
$[66] = t25;
|
|
622
628
|
} else {
|
|
623
|
-
t25 = $[
|
|
629
|
+
t25 = $[66];
|
|
624
630
|
}
|
|
625
631
|
return t25;
|
|
626
632
|
}
|
|
633
|
+
|
|
634
|
+
/** In the inline row the paste target takes the field's place: it grows across, and the field fills it. */
|
|
635
|
+
const PASTE_TARGET_INLINE = {
|
|
636
|
+
flex: 1,
|
|
637
|
+
minWidth: 0
|
|
638
|
+
};
|
|
639
|
+
|
|
640
|
+
/** The field inside the app's paste target (`PasteInputProvider`), or the field alone. */
|
|
641
|
+
function PasteTarget(t0) {
|
|
642
|
+
const $ = _c(5);
|
|
643
|
+
const {
|
|
644
|
+
target: Target,
|
|
645
|
+
onPasteImages,
|
|
646
|
+
style,
|
|
647
|
+
children
|
|
648
|
+
} = t0;
|
|
649
|
+
if (!Target || !onPasteImages) {
|
|
650
|
+
return children;
|
|
651
|
+
}
|
|
652
|
+
let t1;
|
|
653
|
+
if ($[0] !== Target || $[1] !== children || $[2] !== onPasteImages || $[3] !== style) {
|
|
654
|
+
t1 = <Target onPasteImages={onPasteImages} style={style}>{children}</Target>;
|
|
655
|
+
$[0] = Target;
|
|
656
|
+
$[1] = children;
|
|
657
|
+
$[2] = onPasteImages;
|
|
658
|
+
$[3] = style;
|
|
659
|
+
$[4] = t1;
|
|
660
|
+
} else {
|
|
661
|
+
t1 = $[4];
|
|
662
|
+
}
|
|
663
|
+
return t1;
|
|
664
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { c as _c } from "react/compiler-runtime";
|
|
2
|
+
import { TextInputWrapper } from "expo-paste-input";
|
|
3
|
+
import { PastePartsContext } from "./paste-parts";
|
|
4
|
+
|
|
5
|
+
// The image paste on `expo-paste-input`: on Android an `OnReceiveContentListener`
|
|
6
|
+
// on the wrapped field (Paste, and the keyboard's image insert), on iOS the
|
|
7
|
+
// field's `paste(_:)` and keyboard stickers. Text paste stays the field's own.
|
|
8
|
+
|
|
9
|
+
const Target = t0 => {
|
|
10
|
+
const $ = _c(6);
|
|
11
|
+
const {
|
|
12
|
+
onPasteImages,
|
|
13
|
+
style,
|
|
14
|
+
children
|
|
15
|
+
} = t0;
|
|
16
|
+
let t1;
|
|
17
|
+
if ($[0] !== onPasteImages) {
|
|
18
|
+
t1 = payload => {
|
|
19
|
+
if (payload.type === "images" && payload.uris.length > 0) {
|
|
20
|
+
onPasteImages(payload.uris);
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
$[0] = onPasteImages;
|
|
24
|
+
$[1] = t1;
|
|
25
|
+
} else {
|
|
26
|
+
t1 = $[1];
|
|
27
|
+
}
|
|
28
|
+
let t2;
|
|
29
|
+
if ($[2] !== children || $[3] !== style || $[4] !== t1) {
|
|
30
|
+
t2 = <TextInputWrapper style={style} onPaste={t1}>{children}</TextInputWrapper>;
|
|
31
|
+
$[2] = children;
|
|
32
|
+
$[3] = style;
|
|
33
|
+
$[4] = t1;
|
|
34
|
+
$[5] = t2;
|
|
35
|
+
} else {
|
|
36
|
+
t2 = $[5];
|
|
37
|
+
}
|
|
38
|
+
return t2;
|
|
39
|
+
};
|
|
40
|
+
const PARTS = {
|
|
41
|
+
Target
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Image paste for the kit's text fields (`PromptInput` `onPasteImages`). Wrap
|
|
46
|
+
* the app once, under `ThemeProvider`. Needs `expo-paste-input` and a native
|
|
47
|
+
* build (not Expo Go); on the web it does nothing.
|
|
48
|
+
*/
|
|
49
|
+
export function PasteInputProvider(t0) {
|
|
50
|
+
const $ = _c(2);
|
|
51
|
+
const {
|
|
52
|
+
children
|
|
53
|
+
} = t0;
|
|
54
|
+
let t1;
|
|
55
|
+
if ($[0] !== children) {
|
|
56
|
+
t1 = <PastePartsContext.Provider value={PARTS}>{children}</PastePartsContext.Provider>;
|
|
57
|
+
$[0] = children;
|
|
58
|
+
$[1] = t1;
|
|
59
|
+
} else {
|
|
60
|
+
t1 = $[1];
|
|
61
|
+
}
|
|
62
|
+
return t1;
|
|
63
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { createContext, useContext } from "react";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The `expo-paste-input` build of a text field's image paste, from
|
|
5
|
+
* `@vvedantb/native-ui/paste-input`. React Native's `TextInput` takes no
|
|
6
|
+
* pasted image: the long-press Paste and the keyboard's image insert (Gboard's
|
|
7
|
+
* clipboard, stickers) do nothing. `Target` wraps a field so they hand the
|
|
8
|
+
* images over as local file URIs. Without it (the peer is optional, and needs
|
|
9
|
+
* a native build) a field keeps text paste only. A context, so only that entry
|
|
10
|
+
* imports the peer and an app without it bundles as before.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
export const PastePartsContext = createContext(null);
|
|
14
|
+
|
|
15
|
+
/** The image paste parts from `PasteInputProvider`, or null without it. */
|
|
16
|
+
export function usePasteParts() {
|
|
17
|
+
return useContext(PastePartsContext);
|
|
18
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vvedantb/native-ui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Shared React Native / Expo UI primitives. Floating surfaces, forms, overlays, toasts, settings chrome, tab bar, AI chat parts, the family app marks, a NativeWind preset, the Expo web root and Clerk + Convex auth screens.",
|
|
6
6
|
"type": "module",
|
|
@@ -99,6 +99,11 @@
|
|
|
99
99
|
"source": "./src/entries/keyboard-controller.ts",
|
|
100
100
|
"default": "./dist/entries/keyboard-controller.js"
|
|
101
101
|
},
|
|
102
|
+
"./paste-input": {
|
|
103
|
+
"types": "./src/entries/paste-input.ts",
|
|
104
|
+
"source": "./src/entries/paste-input.ts",
|
|
105
|
+
"default": "./dist/entries/paste-input.js"
|
|
106
|
+
},
|
|
102
107
|
"./video": {
|
|
103
108
|
"types": "./src/entries/video.ts",
|
|
104
109
|
"source": "./src/entries/video.ts",
|
|
@@ -184,6 +189,7 @@
|
|
|
184
189
|
],
|
|
185
190
|
"sideEffects": false,
|
|
186
191
|
"peerDependencies": {
|
|
192
|
+
"expo-paste-input": ">=0.2.0",
|
|
187
193
|
"@clerk/clerk-expo": "*",
|
|
188
194
|
"@expo/vector-icons": "*",
|
|
189
195
|
"@json-render/core": ">=0.21.0",
|
|
@@ -225,6 +231,9 @@
|
|
|
225
231
|
"tailwind-merge": ">=2.0.0"
|
|
226
232
|
},
|
|
227
233
|
"peerDependenciesMeta": {
|
|
234
|
+
"expo-paste-input": {
|
|
235
|
+
"optional": true
|
|
236
|
+
},
|
|
228
237
|
"@clerk/clerk-expo": {
|
|
229
238
|
"optional": true
|
|
230
239
|
},
|
package/src/ai/prompt-input.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import { withAlpha } from "../palette";
|
|
|
8
8
|
import { tokens } from "../tokens";
|
|
9
9
|
import { Input as FieldInput } from "../primitives/input";
|
|
10
10
|
import { COMPOSER_INPUT_ID, KeyboardAvoidingView, KeyboardLiftContext } from "../primitives/keyboard-parts";
|
|
11
|
+
import { usePasteParts, type PasteParts } from "../primitives/paste-parts";
|
|
11
12
|
import { usePressFeedback } from "../motion";
|
|
12
13
|
import { useControllableState } from "../primitives/use-controllable-state";
|
|
13
14
|
import { useLargerText } from "../theme";
|
|
@@ -254,6 +255,12 @@ export type PromptInputProps = {
|
|
|
254
255
|
* while the picker is open.
|
|
255
256
|
*/
|
|
256
257
|
menu?: ReactNode;
|
|
258
|
+
/**
|
|
259
|
+
* Images pasted into the field (long-press Paste, or the keyboard's image
|
|
260
|
+
* insert), as `file://` URIs. Needs `PasteInputProvider` from
|
|
261
|
+
* `@vvedantb/native-ui/paste-input`; without it a field takes text only.
|
|
262
|
+
*/
|
|
263
|
+
onPasteImages?: (uris: string[]) => void;
|
|
257
264
|
/**
|
|
258
265
|
* `stacked` (default): the field over a footer of tools and send, the web
|
|
259
266
|
* `PromptInput`. `inline`: one row, as the web `Composer layout="inline"`
|
|
@@ -324,6 +331,7 @@ export function PromptInput({
|
|
|
324
331
|
toolbar,
|
|
325
332
|
footer,
|
|
326
333
|
menu,
|
|
334
|
+
onPasteImages,
|
|
327
335
|
layout = "stacked",
|
|
328
336
|
shape = "rounded",
|
|
329
337
|
leading,
|
|
@@ -337,6 +345,9 @@ export function PromptInput({
|
|
|
337
345
|
const largerText = useLargerText();
|
|
338
346
|
const insets = useSafeAreaInsets();
|
|
339
347
|
const lifted = useContext(KeyboardLiftContext);
|
|
348
|
+
const paste = usePasteParts();
|
|
349
|
+
// The field inside the paste target when an app takes pasted images; it then fills the target.
|
|
350
|
+
const pasteTarget = paste && onPasteImages ? paste.Target : null;
|
|
340
351
|
const [text, setText] = useControllableState({ value, defaultValue, onChange: onChangeText });
|
|
341
352
|
const message = text.trim();
|
|
342
353
|
const canSubmit = message.length > 0 && !disabled && !isGenerating(status);
|
|
@@ -393,6 +404,57 @@ export function PromptInput({
|
|
|
393
404
|
{leading}
|
|
394
405
|
</View>
|
|
395
406
|
) : null}
|
|
407
|
+
<PasteTarget target={pasteTarget} onPasteImages={onPasteImages} style={PASTE_TARGET_INLINE}>
|
|
408
|
+
<FieldInput
|
|
409
|
+
testID={testID ? `${testID}-input` : undefined}
|
|
410
|
+
nativeID={COMPOSER_INPUT_ID}
|
|
411
|
+
multiline
|
|
412
|
+
numberOfLines={ONE_ROW}
|
|
413
|
+
value={text}
|
|
414
|
+
onChangeText={changeText}
|
|
415
|
+
placeholder={placeholder}
|
|
416
|
+
placeholderTextColor={pill ? withAlpha(tokens.color.muted[scheme], PILL.placeholderAlpha) : undefined}
|
|
417
|
+
accessibilityLabel={accessibilityLabel}
|
|
418
|
+
editable={!disabled}
|
|
419
|
+
textAlignVertical="center"
|
|
420
|
+
scrollEnabled={scrollEnabled}
|
|
421
|
+
onContentSizeChange={(e) => setContentHeight(e.nativeEvent.contentSize.height)}
|
|
422
|
+
className={cn(
|
|
423
|
+
// In the row the field grows across; in a paste target, the target does and the field fills it.
|
|
424
|
+
pasteTarget ? "border-0 text-sm font-instrument-sans" : "flex-1 border-0 text-sm font-instrument-sans",
|
|
425
|
+
pill ? "min-h-9 px-1 py-2" : "min-h-8 px-2 py-1",
|
|
426
|
+
largerText && "min-h-11 py-2 text-xl font-instrument-sans-medium",
|
|
427
|
+
)}
|
|
428
|
+
style={[
|
|
429
|
+
fieldTextStyle(scheme),
|
|
430
|
+
fieldText,
|
|
431
|
+
largerText ? typeStyle("medium") : null,
|
|
432
|
+
{
|
|
433
|
+
backgroundColor: "transparent",
|
|
434
|
+
maxHeight,
|
|
435
|
+
...growStyle,
|
|
436
|
+
},
|
|
437
|
+
]}
|
|
438
|
+
/>
|
|
439
|
+
</PasteTarget>
|
|
440
|
+
<View className="shrink-0 flex-row items-center gap-1" style={pill ? { minHeight: PILL.lineHeight } : null}>
|
|
441
|
+
{toolbar}
|
|
442
|
+
<PromptInputSubmit
|
|
443
|
+
status={status}
|
|
444
|
+
onSubmit={submit}
|
|
445
|
+
onStop={onStop}
|
|
446
|
+
canSubmit={canSubmit}
|
|
447
|
+
size={pill ? "md" : undefined}
|
|
448
|
+
/>
|
|
449
|
+
</View>
|
|
450
|
+
</View>
|
|
451
|
+
</View>
|
|
452
|
+
) : (
|
|
453
|
+
<View className="border" style={fieldStyle(scheme)}>
|
|
454
|
+
{replyTo ? <View className="px-2 pt-2">{replyTo}</View> : null}
|
|
455
|
+
{header ? <View className="flex-row flex-wrap gap-1 px-2 pt-2">{header}</View> : null}
|
|
456
|
+
{/* The `Textarea` field without its `numberOfLines` (default 4), which on Android sets the line count: this one starts at one line and grows. */}
|
|
457
|
+
<PasteTarget target={pasteTarget} onPasteImages={onPasteImages}>
|
|
396
458
|
<FieldInput
|
|
397
459
|
testID={testID ? `${testID}-input` : undefined}
|
|
398
460
|
nativeID={COMPOSER_INPUT_ID}
|
|
@@ -401,16 +463,14 @@ export function PromptInput({
|
|
|
401
463
|
value={text}
|
|
402
464
|
onChangeText={changeText}
|
|
403
465
|
placeholder={placeholder}
|
|
404
|
-
placeholderTextColor={pill ? withAlpha(tokens.color.muted[scheme], PILL.placeholderAlpha) : undefined}
|
|
405
466
|
accessibilityLabel={accessibilityLabel}
|
|
406
467
|
editable={!disabled}
|
|
407
|
-
textAlignVertical="
|
|
468
|
+
textAlignVertical="top"
|
|
408
469
|
scrollEnabled={scrollEnabled}
|
|
409
470
|
onContentSizeChange={(e) => setContentHeight(e.nativeEvent.contentSize.height)}
|
|
410
471
|
className={cn(
|
|
411
|
-
"
|
|
412
|
-
|
|
413
|
-
largerText && "min-h-11 py-2 text-xl font-instrument-sans-medium",
|
|
472
|
+
"min-h-11 border-0 px-3.5 py-2.5 text-base font-instrument-sans",
|
|
473
|
+
largerText && "min-h-14 px-4 py-3 text-xl font-instrument-sans-medium",
|
|
414
474
|
)}
|
|
415
475
|
style={[
|
|
416
476
|
fieldTextStyle(scheme),
|
|
@@ -423,51 +483,7 @@ export function PromptInput({
|
|
|
423
483
|
},
|
|
424
484
|
]}
|
|
425
485
|
/>
|
|
426
|
-
|
|
427
|
-
{toolbar}
|
|
428
|
-
<PromptInputSubmit
|
|
429
|
-
status={status}
|
|
430
|
-
onSubmit={submit}
|
|
431
|
-
onStop={onStop}
|
|
432
|
-
canSubmit={canSubmit}
|
|
433
|
-
size={pill ? "md" : undefined}
|
|
434
|
-
/>
|
|
435
|
-
</View>
|
|
436
|
-
</View>
|
|
437
|
-
</View>
|
|
438
|
-
) : (
|
|
439
|
-
<View className="border" style={fieldStyle(scheme)}>
|
|
440
|
-
{replyTo ? <View className="px-2 pt-2">{replyTo}</View> : null}
|
|
441
|
-
{header ? <View className="flex-row flex-wrap gap-1 px-2 pt-2">{header}</View> : null}
|
|
442
|
-
{/* The `Textarea` field without its `numberOfLines` (default 4), which on Android sets the line count: this one starts at one line and grows. */}
|
|
443
|
-
<FieldInput
|
|
444
|
-
testID={testID ? `${testID}-input` : undefined}
|
|
445
|
-
nativeID={COMPOSER_INPUT_ID}
|
|
446
|
-
multiline
|
|
447
|
-
numberOfLines={ONE_ROW}
|
|
448
|
-
value={text}
|
|
449
|
-
onChangeText={changeText}
|
|
450
|
-
placeholder={placeholder}
|
|
451
|
-
accessibilityLabel={accessibilityLabel}
|
|
452
|
-
editable={!disabled}
|
|
453
|
-
textAlignVertical="top"
|
|
454
|
-
scrollEnabled={scrollEnabled}
|
|
455
|
-
onContentSizeChange={(e) => setContentHeight(e.nativeEvent.contentSize.height)}
|
|
456
|
-
className={cn(
|
|
457
|
-
"min-h-11 border-0 px-3.5 py-2.5 text-base font-instrument-sans",
|
|
458
|
-
largerText && "min-h-14 px-4 py-3 text-xl font-instrument-sans-medium",
|
|
459
|
-
)}
|
|
460
|
-
style={[
|
|
461
|
-
fieldTextStyle(scheme),
|
|
462
|
-
fieldText,
|
|
463
|
-
largerText ? typeStyle("medium") : null,
|
|
464
|
-
{
|
|
465
|
-
backgroundColor: "transparent",
|
|
466
|
-
maxHeight,
|
|
467
|
-
...growStyle,
|
|
468
|
-
},
|
|
469
|
-
]}
|
|
470
|
-
/>
|
|
486
|
+
</PasteTarget>
|
|
471
487
|
<View className="flex-row items-center justify-between gap-1 px-2 pb-2">
|
|
472
488
|
<View className="min-w-0 shrink flex-row items-center gap-1">{toolbar}</View>
|
|
473
489
|
<PromptInputSubmit status={status} onSubmit={submit} onStop={onStop} canSubmit={canSubmit} />
|
|
@@ -488,3 +504,26 @@ export function PromptInput({
|
|
|
488
504
|
</KeyboardAvoidingView>
|
|
489
505
|
);
|
|
490
506
|
}
|
|
507
|
+
|
|
508
|
+
/** In the inline row the paste target takes the field's place: it grows across, and the field fills it. */
|
|
509
|
+
const PASTE_TARGET_INLINE = { flex: 1, minWidth: 0 };
|
|
510
|
+
|
|
511
|
+
/** The field inside the app's paste target (`PasteInputProvider`), or the field alone. */
|
|
512
|
+
function PasteTarget({
|
|
513
|
+
target: Target,
|
|
514
|
+
onPasteImages,
|
|
515
|
+
style,
|
|
516
|
+
children,
|
|
517
|
+
}: {
|
|
518
|
+
target: PasteParts["Target"] | null;
|
|
519
|
+
onPasteImages: ((uris: string[]) => void) | undefined;
|
|
520
|
+
style?: { flex: number; minWidth: number };
|
|
521
|
+
children: ReactNode;
|
|
522
|
+
}) {
|
|
523
|
+
if (!Target || !onPasteImages) return children;
|
|
524
|
+
return (
|
|
525
|
+
<Target onPasteImages={onPasteImages} style={style}>
|
|
526
|
+
{children}
|
|
527
|
+
</Target>
|
|
528
|
+
);
|
|
529
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { TextInputWrapper, type PasteEventPayload } from "expo-paste-input";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import { PastePartsContext, type PasteParts } from "./paste-parts";
|
|
4
|
+
|
|
5
|
+
// The image paste on `expo-paste-input`: on Android an `OnReceiveContentListener`
|
|
6
|
+
// on the wrapped field (Paste, and the keyboard's image insert), on iOS the
|
|
7
|
+
// field's `paste(_:)` and keyboard stickers. Text paste stays the field's own.
|
|
8
|
+
|
|
9
|
+
const Target: PasteParts["Target"] = ({ onPasteImages, style, children }) => (
|
|
10
|
+
<TextInputWrapper
|
|
11
|
+
style={style}
|
|
12
|
+
onPaste={(payload: PasteEventPayload) => {
|
|
13
|
+
if (payload.type === "images" && payload.uris.length > 0) onPasteImages(payload.uris);
|
|
14
|
+
}}
|
|
15
|
+
>
|
|
16
|
+
{children}
|
|
17
|
+
</TextInputWrapper>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
const PARTS: PasteParts = { Target };
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Image paste for the kit's text fields (`PromptInput` `onPasteImages`). Wrap
|
|
24
|
+
* the app once, under `ThemeProvider`. Needs `expo-paste-input` and a native
|
|
25
|
+
* build (not Expo Go); on the web it does nothing.
|
|
26
|
+
*/
|
|
27
|
+
export function PasteInputProvider({ children }: { children: ReactNode }) {
|
|
28
|
+
return <PastePartsContext.Provider value={PARTS}>{children}</PastePartsContext.Provider>;
|
|
29
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createContext, useContext, type ComponentType, type ReactNode } from "react";
|
|
2
|
+
import type { StyleProp, ViewStyle } from "react-native";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The `expo-paste-input` build of a text field's image paste, from
|
|
6
|
+
* `@vvedantb/native-ui/paste-input`. React Native's `TextInput` takes no
|
|
7
|
+
* pasted image: the long-press Paste and the keyboard's image insert (Gboard's
|
|
8
|
+
* clipboard, stickers) do nothing. `Target` wraps a field so they hand the
|
|
9
|
+
* images over as local file URIs. Without it (the peer is optional, and needs
|
|
10
|
+
* a native build) a field keeps text paste only. A context, so only that entry
|
|
11
|
+
* imports the peer and an app without it bundles as before.
|
|
12
|
+
*/
|
|
13
|
+
export type PasteParts = {
|
|
14
|
+
Target: ComponentType<{
|
|
15
|
+
/** The pasted images, as `file://` URIs in the app's cache. */
|
|
16
|
+
onPasteImages: (uris: string[]) => void;
|
|
17
|
+
style?: StyleProp<ViewStyle>;
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}>;
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
export const PastePartsContext = createContext<PasteParts | null>(null);
|
|
23
|
+
|
|
24
|
+
/** The image paste parts from `PasteInputProvider`, or null without it. */
|
|
25
|
+
export function usePasteParts(): PasteParts | null {
|
|
26
|
+
return useContext(PastePartsContext);
|
|
27
|
+
}
|