@monochange/feedback-react-native 0.0.0-stage → 0.2.1

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/LICENSE ADDED
@@ -0,0 +1,24 @@
1
+ This is free and unencumbered software released into the public domain.
2
+
3
+ Anyone is free to copy, modify, publish, use, compile, sell, or
4
+ distribute this software, either in source code form or as a compiled
5
+ binary, for any purpose, commercial or non-commercial, and by any
6
+ means.
7
+
8
+ In jurisdictions that recognize copyright laws, the author or authors
9
+ of this software dedicate any and all copyright interest in the
10
+ software to the public domain. We make this dedication for the benefit
11
+ of the public at large and to the detriment of our heirs and
12
+ successors. We intend this dedication to be an overt act of
13
+ relinquishment in perpetuity of all present and future rights to this
14
+ software under copyright law.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19
+ IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20
+ OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21
+ ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22
+ OTHER DEALINGS IN THE SOFTWARE.
23
+
24
+ For more information, please refer to <http://unlicense.org/>
package/README.md CHANGED
@@ -1,3 +1,9 @@
1
- # Temporary Holding Version
1
+ # React Native feedback
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Install `@monochange/feedback-react-native` with React 18+ and React Native 0.76+. It exports `FeedbackSheet` and `FeedbackClient`, with native controls for conversations, suggestions, votes, submissions, replies, and delivery status.
4
+
5
+ Read the [mobile integration guide](https://github.com/monochange/monochange/blob/main/docs/src/guide/feedback-widget.md#react-native).
6
+
7
+ `FeedbackSheet` requires a stable `client`, `visible`, `identityKey`, and `onClose`. Optional properties are `onSubmitted`, `theme`, and `labels`. Changing `identityKey` clears the prior account's draft and credentials. The component refreshes delivery status while visible and after resuming; the host owns the client's final `destroy()` call.
8
+
9
+ Use backend-issued **mobile** sessions. No backend credential or model key belongs in the app bundle, and no WebView is required. The example `App.tsx` shows host authentication, a custom launcher, and both mobile platform configurations.
@@ -0,0 +1,40 @@
1
+ import React from "react";
2
+ import { ClientToken, FeedbackClient, FeedbackClient as FeedbackClient$1, FeedbackContext, FeedbackOptions, Receipt } from "@monochange/feedback/client";
3
+
4
+ //#region packages/monochange__feedback-react-native/src/index.d.ts
5
+ interface FeedbackSheetProps {
6
+ client: FeedbackClient$1;
7
+ visible: boolean;
8
+ /** Change this on logout or account switches to erase the previous user's UI. */
9
+ identityKey: string;
10
+ onClose: () => void;
11
+ onSubmitted?: (receipt: Receipt) => void;
12
+ theme?: "light" | "dark";
13
+ labels?: Partial<typeof defaults>;
14
+ }
15
+ declare const defaults: {
16
+ title: string;
17
+ close: string;
18
+ feature: string;
19
+ bug: string;
20
+ send: string;
21
+ reply: string;
22
+ submit: string;
23
+ another: string;
24
+ upvote: string;
25
+ voted: string;
26
+ message: string;
27
+ working: string;
28
+ };
29
+ /** Native feedback UI. The host owns authentication, presentation, and translations. */
30
+ declare function FeedbackSheet({
31
+ client,
32
+ visible,
33
+ identityKey,
34
+ onClose,
35
+ onSubmitted,
36
+ theme,
37
+ labels: overrides
38
+ }: FeedbackSheetProps): React.JSX.Element;
39
+ //#endregion
40
+ export { type ClientToken, FeedbackClient, type FeedbackContext, type FeedbackOptions, FeedbackSheet, FeedbackSheetProps };
package/dist/index.js ADDED
@@ -0,0 +1,344 @@
1
+ import { useEffect, useRef, useState } from "react";
2
+ import { AppState, Button, KeyboardAvoidingView, Modal, Platform, Pressable, SafeAreaView, ScrollView, StyleSheet, Text, TextInput, View, useColorScheme } from "react-native";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { FeedbackClient } from "@monochange/feedback/client";
5
+ //#region packages/monochange__feedback-react-native/src/index.tsx
6
+ const defaults = {
7
+ title: "Feedback",
8
+ close: "Close",
9
+ feature: "Feature or change",
10
+ bug: "Bug report",
11
+ send: "Find similar requests",
12
+ reply: "Send reply",
13
+ submit: "Submit a new request",
14
+ another: "Start another request",
15
+ upvote: "Upvote",
16
+ voted: "Upvoted",
17
+ message: "Describe the outcome you want, or what went wrong…",
18
+ working: "Working…"
19
+ };
20
+ function useFeedback({ client, visible, identityKey, onSubmitted }) {
21
+ const [body, setBody] = useState("");
22
+ const [kind, setKind] = useState("feature_request");
23
+ const [conversation, setConversation] = useState();
24
+ const [suggestions, setSuggestions] = useState([]);
25
+ const [item, setItem] = useState();
26
+ const [busy, setBusy] = useState(false);
27
+ const [error, setError] = useState("");
28
+ const generation = useRef(0);
29
+ const running = useRef(false);
30
+ const current = useRef(item);
31
+ current.current = item;
32
+ function reset() {
33
+ generation.current += 1;
34
+ client.reset();
35
+ setBody("");
36
+ setConversation(void 0);
37
+ setSuggestions([]);
38
+ setItem(void 0);
39
+ setError("");
40
+ setBusy(false);
41
+ running.current = false;
42
+ }
43
+ useEffect(() => {
44
+ reset();
45
+ return () => {
46
+ generation.current += 1;
47
+ };
48
+ }, [client, identityKey]);
49
+ async function run(action) {
50
+ if (running.current) return;
51
+ running.current = true;
52
+ setBusy(true);
53
+ setError("");
54
+ const version = generation.current;
55
+ const active = () => generation.current === version;
56
+ try {
57
+ await action(active);
58
+ } catch (failure) {
59
+ if (active()) setError(failure instanceof Error ? failure.message : "Feedback request failed");
60
+ } finally {
61
+ if (active()) {
62
+ running.current = false;
63
+ setBusy(false);
64
+ }
65
+ }
66
+ }
67
+ useEffect(() => {
68
+ if (!visible) return;
69
+ const refresh = () => {
70
+ if (current.current) run(async (active) => {
71
+ const next = await client.getItem(current.current.id);
72
+ if (active()) setItem(next);
73
+ });
74
+ };
75
+ const timer = setInterval(refresh, 3e4);
76
+ const subscription = AppState.addEventListener("change", (state) => {
77
+ if (state === "active") refresh();
78
+ });
79
+ return () => {
80
+ clearInterval(timer);
81
+ subscription.remove();
82
+ };
83
+ }, [
84
+ client,
85
+ visible,
86
+ identityKey
87
+ ]);
88
+ const send = () => void run(async (active) => {
89
+ if (!body.trim()) return;
90
+ if (item) {
91
+ await client.reply(item.id, body);
92
+ const next = await client.getItem(item.id);
93
+ if (active()) setItem(next);
94
+ } else {
95
+ const result = conversation ? await client.sendMessage(conversation, body) : await client.startConversation(body, kind);
96
+ if (active()) {
97
+ setConversation(result.conversation);
98
+ setSuggestions(result.similar);
99
+ }
100
+ }
101
+ if (active()) setBody("");
102
+ });
103
+ const submit = () => void run(async (active) => {
104
+ if (!conversation) return;
105
+ const receipt = await client.submit(conversation.id, conversation.version);
106
+ const result = await client.getItem(receipt.id);
107
+ if (active()) {
108
+ setItem(result);
109
+ setSuggestions([]);
110
+ onSubmitted?.(receipt);
111
+ }
112
+ });
113
+ const vote = (suggestion) => void run(async (active) => {
114
+ const result = await client.vote(suggestion.id, !suggestion.voted);
115
+ if (active()) setSuggestions((previous) => previous.map((value) => value.id === suggestion.id ? {
116
+ ...value,
117
+ ...result
118
+ } : value));
119
+ });
120
+ return {
121
+ body,
122
+ setBody,
123
+ kind,
124
+ setKind,
125
+ conversation,
126
+ suggestions,
127
+ item,
128
+ busy,
129
+ error,
130
+ reset,
131
+ send,
132
+ submit,
133
+ vote
134
+ };
135
+ }
136
+ /** Native feedback UI. The host owns authentication, presentation, and translations. */
137
+ function FeedbackSheet({ client, visible, identityKey, onClose, onSubmitted, theme, labels: overrides }) {
138
+ const labels = {
139
+ ...defaults,
140
+ ...overrides
141
+ };
142
+ const system = useColorScheme();
143
+ const dark = (theme ?? system) === "dark";
144
+ const colors = {
145
+ backgroundColor: dark ? "#241f3b" : "#fff",
146
+ color: dark ? "#f5f3ff" : "#19152e"
147
+ };
148
+ const { body, setBody, kind, setKind, conversation, suggestions, item, busy, error, reset, send, submit, vote } = useFeedback({
149
+ client,
150
+ visible,
151
+ identityKey,
152
+ onSubmitted
153
+ });
154
+ return /* @__PURE__ */ jsx(Modal, {
155
+ visible,
156
+ animationType: "slide",
157
+ presentationStyle: "pageSheet",
158
+ onRequestClose: onClose,
159
+ children: /* @__PURE__ */ jsx(SafeAreaView, {
160
+ style: [styles.fill, colors],
161
+ children: /* @__PURE__ */ jsxs(KeyboardAvoidingView, {
162
+ style: styles.fill,
163
+ behavior: Platform.OS === "ios" ? "padding" : "height",
164
+ children: [/* @__PURE__ */ jsxs(View, {
165
+ style: styles.header,
166
+ children: [/* @__PURE__ */ jsx(Text, {
167
+ accessibilityRole: "header",
168
+ style: [styles.title, colors],
169
+ children: labels.title
170
+ }), /* @__PURE__ */ jsx(Button, {
171
+ title: labels.close,
172
+ onPress: onClose
173
+ })]
174
+ }), /* @__PURE__ */ jsxs(ScrollView, {
175
+ contentContainerStyle: styles.content,
176
+ keyboardShouldPersistTaps: "handled",
177
+ children: [
178
+ !!error && /* @__PURE__ */ jsx(Text, {
179
+ accessibilityRole: "alert",
180
+ style: styles.error,
181
+ children: error
182
+ }),
183
+ item && /* @__PURE__ */ jsxs(Text, {
184
+ accessibilityLiveRegion: "polite",
185
+ style: [styles.status, colors],
186
+ children: [
187
+ item.title,
188
+ " · ",
189
+ item.status
190
+ ]
191
+ }),
192
+ conversation && !item && conversation.messages.map((message, index) => /* @__PURE__ */ jsxs(Text, {
193
+ style: [styles.message, colors],
194
+ children: [message.role === "assistant" ? "Assistant: " : "You: ", message.body]
195
+ }, index)),
196
+ item?.messages.map((message, index) => /* @__PURE__ */ jsxs(Text, {
197
+ style: [styles.message, colors],
198
+ children: [
199
+ message.author,
200
+ ": ",
201
+ message.body
202
+ ]
203
+ }, index)),
204
+ suggestions.map((suggestion) => /* @__PURE__ */ jsxs(View, {
205
+ style: styles.card,
206
+ children: [
207
+ /* @__PURE__ */ jsx(Text, {
208
+ style: [styles.status, colors],
209
+ children: suggestion.title
210
+ }),
211
+ /* @__PURE__ */ jsxs(Text, {
212
+ style: colors,
213
+ children: [
214
+ suggestion.status,
215
+ " · ",
216
+ suggestion.votes
217
+ ]
218
+ }),
219
+ /* @__PURE__ */ jsx(Pressable, {
220
+ accessibilityRole: "button",
221
+ accessibilityState: {
222
+ selected: suggestion.voted,
223
+ disabled: busy
224
+ },
225
+ disabled: busy,
226
+ style: styles.vote,
227
+ onPress: () => vote(suggestion),
228
+ children: /* @__PURE__ */ jsx(Text, {
229
+ style: colors,
230
+ children: suggestion.voted ? labels.voted : labels.upvote
231
+ })
232
+ })
233
+ ]
234
+ }, suggestion.id)),
235
+ !conversation && !item && /* @__PURE__ */ jsx(View, {
236
+ style: styles.row,
237
+ children: ["feature_request", "bug_report"].map((value) => /* @__PURE__ */ jsx(Pressable, {
238
+ accessibilityRole: "radio",
239
+ accessibilityState: { checked: kind === value },
240
+ onPress: () => setKind(value),
241
+ style: [styles.choice, kind === value && styles.selected],
242
+ children: /* @__PURE__ */ jsx(Text, {
243
+ style: colors,
244
+ children: value === "bug_report" ? labels.bug : labels.feature
245
+ })
246
+ }, value))
247
+ }),
248
+ /* @__PURE__ */ jsx(TextInput, {
249
+ accessibilityLabel: labels.message,
250
+ placeholder: labels.message,
251
+ placeholderTextColor: dark ? "#c0b8d8" : "#5b5472",
252
+ multiline: true,
253
+ maxLength: 4e3,
254
+ value: body,
255
+ onChangeText: setBody,
256
+ editable: !busy,
257
+ style: [styles.input, colors]
258
+ }),
259
+ /* @__PURE__ */ jsx(Button, {
260
+ disabled: busy || !body.trim(),
261
+ title: busy ? labels.working : conversation || item ? labels.reply : labels.send,
262
+ onPress: send
263
+ }),
264
+ conversation && !item && /* @__PURE__ */ jsx(Button, {
265
+ disabled: busy,
266
+ title: labels.submit,
267
+ onPress: submit
268
+ }),
269
+ item && /* @__PURE__ */ jsx(Button, {
270
+ disabled: busy,
271
+ title: labels.another,
272
+ onPress: reset
273
+ })
274
+ ]
275
+ })]
276
+ })
277
+ })
278
+ });
279
+ }
280
+ const styles = StyleSheet.create({
281
+ fill: { flex: 1 },
282
+ header: {
283
+ padding: 16,
284
+ flexDirection: "row",
285
+ justifyContent: "space-between",
286
+ alignItems: "center"
287
+ },
288
+ title: {
289
+ fontSize: 24,
290
+ fontWeight: "700"
291
+ },
292
+ content: {
293
+ padding: 20,
294
+ gap: 12
295
+ },
296
+ row: {
297
+ flexDirection: "row",
298
+ gap: 8
299
+ },
300
+ input: {
301
+ minHeight: 120,
302
+ borderWidth: 1,
303
+ borderColor: "#aaa",
304
+ borderRadius: 12,
305
+ padding: 12,
306
+ textAlignVertical: "top"
307
+ },
308
+ message: {
309
+ padding: 12,
310
+ borderRadius: 12,
311
+ borderWidth: 1,
312
+ borderColor: "#8b5cf6"
313
+ },
314
+ card: {
315
+ padding: 14,
316
+ borderRadius: 12,
317
+ borderWidth: 1,
318
+ borderColor: "#aaa",
319
+ gap: 8
320
+ },
321
+ status: {
322
+ fontSize: 16,
323
+ fontWeight: "600"
324
+ },
325
+ vote: {
326
+ padding: 12,
327
+ borderRadius: 10,
328
+ borderWidth: 1,
329
+ borderColor: "#8b5cf6"
330
+ },
331
+ choice: {
332
+ padding: 10,
333
+ borderRadius: 10,
334
+ borderWidth: 1,
335
+ borderColor: "#aaa"
336
+ },
337
+ selected: {
338
+ borderColor: "#8b5cf6",
339
+ borderWidth: 2
340
+ },
341
+ error: { color: "#c23748" }
342
+ });
343
+ //#endregion
344
+ export { FeedbackClient, FeedbackSheet };
package/package.json CHANGED
@@ -1,6 +1,41 @@
1
1
  {
2
2
  "name": "@monochange/feedback-react-native",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
3
+ "version": "0.2.1",
4
+ "type": "module",
5
+ "description": "Native monochange feedback screens for React Native apps",
6
+ "license": "Unlicense",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/monochange/monochange"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "README.md"
14
+ ],
15
+ "exports": {
16
+ ".": {
17
+ "types": "./dist/index.d.ts",
18
+ "import": "./dist/index.js",
19
+ "react-native": "./dist/index.js"
20
+ }
21
+ },
22
+ "dependencies": {
23
+ "@monochange/feedback": "^0.3.0"
24
+ },
25
+ "peerDependencies": {
26
+ "react": ">=18",
27
+ "react-native": ">=0.76"
28
+ },
29
+ "devDependencies": {
30
+ "@types/react": "^19.1.0",
31
+ "@types/react-test-renderer": "^19.1.0",
32
+ "react-test-renderer": "^19.1.0"
33
+ },
34
+ "publishConfig": {
35
+ "access": "public",
36
+ "provenance": true
37
+ },
38
+ "scripts": {
39
+ "build": "pnpm --dir ../.. build:feedback"
40
+ }
6
41
  }