@celljs/ta-feedback 0.0.0-stage → 4.17.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/web/index.js ADDED
@@ -0,0 +1,939 @@
1
+ // web-src/feedback-protocol.ts
2
+ var REVIEW_TYPE = "ta-feedback:review";
3
+ var BOARD_KEY = "feedback:";
4
+ var FeedbackKeys;
5
+ ((FeedbackKeys) => {
6
+ FeedbackKeys.SETTINGS = "settings";
7
+ FeedbackKeys.ITEMS = "items";
8
+ FeedbackKeys.READ = "read";
9
+ FeedbackKeys.SESSIONS = "sessions";
10
+ })(FeedbackKeys ||= {});
11
+ var MEMBER_CHOICES = [16, 50, 100];
12
+ var DEFAULT_MEMBERS = 50;
13
+ var INVITE_DAYS = 365;
14
+
15
+ // ../ta-protocol/esm/common/language.js
16
+ var TaLanguageUtil;
17
+ (function(TaLanguageUtil2) {
18
+ TaLanguageUtil2.ALL = ["zh-CN", "zh-TW", "en-US", "ja-JP"];
19
+ TaLanguageUtil2.NAMES = { "zh-CN": "简体中文", "zh-TW": "繁體中文", "en-US": "English", "ja-JP": "日本語" };
20
+ function of(tag) {
21
+ const said = (tag !== null && tag !== undefined ? tag : "").toLowerCase().replace(/_/g, "-");
22
+ if (/^zh(\b|-)/.test(said)) {
23
+ return /-hant\b/.test(said) || !/-hans\b/.test(said) && /-(tw|hk|mo)\b/.test(said) ? "zh-TW" : "zh-CN";
24
+ }
25
+ return /^ja(\b|-)/.test(said) ? "ja-JP" : "en-US";
26
+ }
27
+ TaLanguageUtil2.of = of;
28
+ function server(env = typeof process === "undefined" ? {} : process.env) {
29
+ return of(env.TA_LANGUAGE || env.LC_ALL || env.LC_MESSAGES || env.LANG);
30
+ }
31
+ TaLanguageUtil2.server = server;
32
+ function pick(language, words) {
33
+ return words[of(language)];
34
+ }
35
+ TaLanguageUtil2.pick = pick;
36
+ function say(words) {
37
+ return words[server()];
38
+ }
39
+ TaLanguageUtil2.say = say;
40
+ function chinese(language) {
41
+ return of(language).startsWith("zh");
42
+ }
43
+ TaLanguageUtil2.chinese = chinese;
44
+ function cjk(language) {
45
+ return of(language) !== "en-US";
46
+ }
47
+ TaLanguageUtil2.cjk = cjk;
48
+ function list(language, items) {
49
+ return items.join(cjk(language) ? "、" : ", ");
50
+ }
51
+ TaLanguageUtil2.list = list;
52
+ })(TaLanguageUtil || (TaLanguageUtil = {}));
53
+
54
+ // web-src/i18n.ts
55
+ var EN = {
56
+ feedback: "Feedback",
57
+ on: "On",
58
+ off: "Off",
59
+ intro: "People report problems here, even from a browser. Ta sorts them into reports, fixes each on a branch of its own, and you decide what goes out.",
60
+ project: "Project",
61
+ pick: "Choose",
62
+ notGit: "Not a git repository: {reason}",
63
+ speaker: "Replies",
64
+ double: "Your double",
65
+ guests: "Let in from a browser",
66
+ guestsHint: "Those asking from a browser join without asking you, and only chat.",
67
+ members: "Members",
68
+ membersValue: "Up to {n}",
69
+ release: "Goes out by",
70
+ releaseHint: "What Ta does once you approve a fix",
71
+ releaseDefault: "Merge into main and push",
72
+ turnOn: "Turn on feedback",
73
+ save: "Save",
74
+ cancel: "Cancel",
75
+ settings: "Settings",
76
+ turnOff: "Turn off feedback",
77
+ turnOffTitle: 'Turn off feedback in "{title}"?',
78
+ turnOffHint: "Reports are kept. Ta stops reading the room.",
79
+ link: "Link that invites",
80
+ linkValue: "For a year",
81
+ linkTitle: "Link that invites, for a year",
82
+ linkHint: "Anyone with it can join from a browser and report. Making it stops the links of before.",
83
+ linkMake: "Make the link",
84
+ copy: "Copy",
85
+ copied: "Copied",
86
+ review: "Waiting for you",
87
+ working: "In progress",
88
+ ended: "Done",
89
+ none: "No reports yet. Share the link: what people say here is sorted for you.",
90
+ memberNone: "Say what is wrong in the chat: it gets fixed",
91
+ approve: "Approve",
92
+ decline: "Not now",
93
+ retry: "Try again",
94
+ open: "See how",
95
+ changes: "See the changes",
96
+ from: "From {names}",
97
+ files: "{n} files",
98
+ reviewCount: "{n} waiting for you",
99
+ workingCount: "{n} in progress",
100
+ doneCount: "{n} fixed",
101
+ lineQuiet: "Feedback is on: say what is wrong here",
102
+ status_new: "Filed",
103
+ status_fixing: "Fixing",
104
+ status_review: "Waiting for you",
105
+ status_releasing: "Going out",
106
+ status_released: "Out",
107
+ status_declined: "Not now",
108
+ status_unchanged: "Nothing to change",
109
+ status_failed: "Failed",
110
+ approved: "Approved: it is going out",
111
+ reviewTitle: "Fix #{n} is ready"
112
+ };
113
+ var ZH = {
114
+ feedback: "反馈",
115
+ on: "已开启",
116
+ off: "未开启",
117
+ intro: "大家在这里说问题,浏览器也能进来。Ta 整理成反馈、每条在单独的分支上修好,由你决定上不上线。",
118
+ project: "项目",
119
+ pick: "选择",
120
+ notGit: "不是 git 仓库:{reason}",
121
+ speaker: "谁来回复",
122
+ double: "我的分身",
123
+ guests: "浏览器访客直接进",
124
+ guestsHint: "用浏览器申请的人不用你同意就能进来,只能聊天。",
125
+ members: "人数上限",
126
+ membersValue: "{n} 人",
127
+ release: "上线方式",
128
+ releaseHint: "你批准修复后 Ta 怎么上线",
129
+ releaseDefault: "合入 main 分支并推送",
130
+ turnOn: "开启反馈",
131
+ save: "保存",
132
+ cancel: "取消",
133
+ settings: "设置",
134
+ turnOff: "关闭反馈",
135
+ turnOffTitle: "关闭「{title}」的反馈?",
136
+ turnOffHint: "已有的反馈会保留,Ta 不再读这个房间。",
137
+ link: "邀请链接",
138
+ linkValue: "一年有效",
139
+ linkTitle: "邀请链接(一年有效)",
140
+ linkHint: "拿到链接的人都能用浏览器进来反馈。生成新链接后,旧链接失效。",
141
+ linkMake: "生成链接",
142
+ copy: "复制",
143
+ copied: "已复制",
144
+ review: "待你决定",
145
+ working: "处理中",
146
+ ended: "已结束",
147
+ none: "还没有反馈。把邀请链接发出去,大家在这里说的问题会整理好交给你。",
148
+ memberNone: "有问题直接在群里说,会有人修",
149
+ approve: "批准上线",
150
+ decline: "先不改",
151
+ retry: "再试一次",
152
+ open: "看过程",
153
+ changes: "看改动",
154
+ from: "来自 {names}",
155
+ files: "{n} 个文件",
156
+ reviewCount: "{n} 个待你决定",
157
+ workingCount: "{n} 个处理中",
158
+ doneCount: "{n} 个已修复",
159
+ lineQuiet: "反馈已开启:有问题直接在这里说",
160
+ status_new: "已记录",
161
+ status_fixing: "修复中",
162
+ status_review: "待你决定",
163
+ status_releasing: "上线中",
164
+ status_released: "已上线",
165
+ status_declined: "先不改",
166
+ status_unchanged: "无需改动",
167
+ status_failed: "失败",
168
+ approved: "已批准,正在上线",
169
+ reviewTitle: "#{n} 修好了"
170
+ };
171
+ var ZH_TW = {
172
+ feedback: "回饋",
173
+ on: "已開啟",
174
+ off: "未開啟",
175
+ intro: "大家在這裡說問題,瀏覽器也能進來。Ta 整理成回饋、每條在單獨的分支上修好,由你決定上不上線。",
176
+ project: "專案",
177
+ pick: "選擇",
178
+ notGit: "不是 git 儲存庫:{reason}",
179
+ speaker: "誰來回覆",
180
+ double: "我的分身",
181
+ guests: "瀏覽器訪客直接進",
182
+ guestsHint: "用瀏覽器申請的人不用你同意就能進來,只能聊天。",
183
+ members: "人數上限",
184
+ membersValue: "{n} 人",
185
+ release: "上線方式",
186
+ releaseHint: "你批準修復後 Ta 怎麼上線",
187
+ releaseDefault: "合入 main 分支並推送",
188
+ turnOn: "開啟回饋",
189
+ save: "儲存",
190
+ cancel: "取消",
191
+ settings: "設定",
192
+ turnOff: "關閉回饋",
193
+ turnOffTitle: "關閉「{title}」的回饋?",
194
+ turnOffHint: "已有的回饋會保留,Ta 不再讀這個房間。",
195
+ link: "邀請連結",
196
+ linkValue: "一年有效",
197
+ linkTitle: "邀請連結(一年有效)",
198
+ linkHint: "拿到連結的人都能用瀏覽器進來回饋。產生新連結後,舊連結失效。",
199
+ linkMake: "產生連結",
200
+ copy: "複製",
201
+ copied: "已複製",
202
+ review: "待你決定",
203
+ working: "處理中",
204
+ ended: "已結束",
205
+ none: "還沒有回饋。把邀請連結發出去,大家在這裡說的問題會整理好交給你。",
206
+ memberNone: "有問題直接在群裡說,會有人修",
207
+ approve: "批準上線",
208
+ decline: "先不改",
209
+ retry: "再試一次",
210
+ open: "看過程",
211
+ changes: "看改動",
212
+ from: "來自 {names}",
213
+ files: "{n} 個檔案",
214
+ reviewCount: "{n} 個待你決定",
215
+ workingCount: "{n} 個處理中",
216
+ doneCount: "{n} 個已修復",
217
+ lineQuiet: "回饋已開啟:有問題直接在這裡說",
218
+ status_new: "已記錄",
219
+ status_fixing: "修復中",
220
+ status_review: "待你決定",
221
+ status_releasing: "上線中",
222
+ status_released: "已上線",
223
+ status_declined: "先不改",
224
+ status_unchanged: "無需改動",
225
+ status_failed: "失敗",
226
+ approved: "已批準,正在上線",
227
+ reviewTitle: "#{n} 修好了"
228
+ };
229
+ var JA = {
230
+ feedback: "フィードバック",
231
+ on: "オン",
232
+ off: "オフ",
233
+ intro: "ここで問題を報告してもらえます(ブラウザからも参加可)。Ta が報告に整理し、それぞれ別のブランチで修正し、リリースするかはあなたが決めます。",
234
+ project: "プロジェクト",
235
+ pick: "選択",
236
+ notGit: "git リポジトリではありません:{reason}",
237
+ speaker: "返信する人",
238
+ double: "あなたの分身",
239
+ guests: "ブラウザから直接参加",
240
+ guestsHint: "ブラウザから申請した人は承認なしで参加でき、チャットのみできます。",
241
+ members: "人数上限",
242
+ membersValue: "{n} 人",
243
+ release: "リリース方法",
244
+ releaseHint: "修正を承認したあと Ta が行うこと",
245
+ releaseDefault: "main にマージしてプッシュ",
246
+ turnOn: "フィードバックをオン",
247
+ save: "保存",
248
+ cancel: "キャンセル",
249
+ settings: "設定",
250
+ turnOff: "フィードバックをオフ",
251
+ turnOffTitle: "「{title}」のフィードバックをオフにしますか?",
252
+ turnOffHint: "報告は残ります。Ta はこのルームを読まなくなります。",
253
+ link: "招待リンク",
254
+ linkValue: "1 年有効",
255
+ linkTitle: "招待リンク(1 年有効)",
256
+ linkHint: "リンクを持っている人は誰でもブラウザから参加して報告できます。新しいリンクを作ると以前のリンクは無効になります。",
257
+ linkMake: "リンクを作成",
258
+ copy: "コピー",
259
+ copied: "コピーしました",
260
+ review: "あなたの判断待ち",
261
+ working: "対応中",
262
+ ended: "完了",
263
+ none: "まだ報告はありません。招待リンクを共有すると、ここで話された問題が整理されます。",
264
+ memberNone: "問題があればチャットで教えてください",
265
+ approve: "承認してリリース",
266
+ decline: "今はしない",
267
+ retry: "もう一度",
268
+ open: "経過を見る",
269
+ changes: "変更を見る",
270
+ from: "{names} から",
271
+ files: "{n} ファイル",
272
+ reviewCount: "判断待ち {n}",
273
+ workingCount: "対応中 {n}",
274
+ doneCount: "修正済み {n}",
275
+ lineQuiet: "フィードバックはオン:問題はここで教えてください",
276
+ status_new: "受付済み",
277
+ status_fixing: "修正中",
278
+ status_review: "判断待ち",
279
+ status_releasing: "リリース中",
280
+ status_released: "リリース済み",
281
+ status_declined: "今はしない",
282
+ status_unchanged: "変更不要",
283
+ status_failed: "失敗",
284
+ approved: "承認しました。リリース中です",
285
+ reviewTitle: "#{n} を修正しました"
286
+ };
287
+ var WORDS = { "zh-CN": ZH, "zh-TW": ZH_TW, "en-US": EN, "ja-JP": JA };
288
+ var FeedbackWords;
289
+ ((FeedbackWords) => {
290
+ function of(language) {
291
+ return TaLanguageUtil.pick(language, WORDS);
292
+ }
293
+ FeedbackWords.of = of;
294
+ function format(text, values = {}) {
295
+ return text.replace(/\{(\w+)\}/g, (all, key) => (key in values) ? String(values[key]) : all);
296
+ }
297
+ FeedbackWords.format = format;
298
+ })(FeedbackWords ||= {});
299
+
300
+ // web-src/react.ts
301
+ var React;
302
+ function bind(react) {
303
+ React = react;
304
+ }
305
+
306
+ // web-src/page.tsx
307
+ var pi;
308
+ function bindPage(api) {
309
+ pi = api;
310
+ }
311
+ function t(key, values = {}) {
312
+ return FeedbackWords.format(FeedbackWords.of(pi.ui.language)[key], values);
313
+ }
314
+ function statusName(status) {
315
+ return t(`status_${status}`);
316
+ }
317
+ function icon(name) {
318
+ return pi.ui.icons[name] ?? pi.ui.icons.Sparkles;
319
+ }
320
+ function message(error) {
321
+ return error instanceof Error ? error.message : String(error);
322
+ }
323
+ function callFeedback(request) {
324
+ return pi.callHost("feedback", request);
325
+ }
326
+
327
+ class FeedbackStore {
328
+ state = { settings: {}, items: [], boards: {} };
329
+ listeners = new Set;
330
+ get() {
331
+ return this.state;
332
+ }
333
+ set(next) {
334
+ this.state = { ...this.state, ...next };
335
+ for (const listener of this.listeners) {
336
+ listener();
337
+ }
338
+ }
339
+ subscribe = (listener) => {
340
+ this.listeners.add(listener);
341
+ return () => this.listeners.delete(listener);
342
+ };
343
+ start() {
344
+ const stops = [];
345
+ if (pi.storage) {
346
+ stops.push(pi.storage.onChange((keys) => {
347
+ if (keys.includes(FeedbackKeys.SETTINGS) || keys.includes(FeedbackKeys.ITEMS)) {
348
+ this.read();
349
+ }
350
+ }));
351
+ this.read();
352
+ }
353
+ const stop = pi.onRoomEvent?.((event) => {
354
+ if (event.type === "state" && event.key.startsWith(BOARD_KEY)) {
355
+ this.heardBoard(event.room, event.key, event.value, event.by);
356
+ } else if (event.type === "rooms") {
357
+ this.readBoards();
358
+ }
359
+ }, { messages: false, state: [BOARD_KEY] });
360
+ if (stop) {
361
+ stops.push(stop);
362
+ }
363
+ this.readBoards();
364
+ return () => {
365
+ for (const each of stops) {
366
+ each();
367
+ }
368
+ };
369
+ }
370
+ async read() {
371
+ const [settings, items] = await Promise.all([
372
+ pi.storage.get(FeedbackKeys.SETTINGS).catch(() => {
373
+ return;
374
+ }),
375
+ pi.storage.get(FeedbackKeys.ITEMS).catch(() => {
376
+ return;
377
+ })
378
+ ]);
379
+ this.set({ settings: settings && typeof settings === "object" ? settings : {}, items: Array.isArray(items) ? items : [] });
380
+ }
381
+ async readBoards() {
382
+ const rooms = await pi.rooms?.listRooms().catch(() => []) ?? [];
383
+ const boards = {};
384
+ for (const room of rooms.filter((each) => each.status === "member" && !each.owner && !each.unlisted)) {
385
+ const owner = room.members.find((member) => member.owner);
386
+ if (!owner) {
387
+ continue;
388
+ }
389
+ const key = `${BOARD_KEY}${owner.member}`;
390
+ const value = (await pi.rooms.getState(room.id, key).catch(() => ({})))[key];
391
+ if (value && Array.isArray(value.value) && value.by === owner.member) {
392
+ boards[room.id] = value.value;
393
+ }
394
+ }
395
+ this.set({ boards });
396
+ }
397
+ heardBoard(room, key, value, by) {
398
+ const member = key.slice(BOARD_KEY.length);
399
+ const boards = { ...this.state.boards };
400
+ if (by === member && Array.isArray(value)) {
401
+ boards[room] = value;
402
+ } else {
403
+ delete boards[room];
404
+ }
405
+ this.set({ boards });
406
+ }
407
+ }
408
+ var store = new FeedbackStore;
409
+ function useFeedback() {
410
+ return React.useSyncExternalStore(store.subscribe, () => store.get());
411
+ }
412
+ async function copy(text) {
413
+ try {
414
+ await navigator.clipboard.writeText(text);
415
+ pi.ui.notify(t("copied"));
416
+ } catch (error) {
417
+ pi.ui.notify(message(error), "error");
418
+ }
419
+ }
420
+
421
+ // web-src/feedback-view.tsx
422
+ var OPEN = new Set(["new", "fixing", "releasing"]);
423
+ function Status({ status }) {
424
+ return /* @__PURE__ */ React.createElement("span", {
425
+ className: `tfb-status tfb-status-${status}`
426
+ }, statusName(status));
427
+ }
428
+ function useBusy() {
429
+ const [busy, setBusy] = React.useState(false);
430
+ return [
431
+ busy,
432
+ (run) => {
433
+ setBusy(true);
434
+ run().catch((error) => pi.ui.notify(message(error), "error")).finally(() => setBusy(false));
435
+ }
436
+ ];
437
+ }
438
+ function folderName(path) {
439
+ return path.replace(/\/+$/, "").split("/").pop() || path;
440
+ }
441
+ function Row({
442
+ label,
443
+ value,
444
+ title,
445
+ onClick,
446
+ children
447
+ }) {
448
+ const Chevron = icon("ChevronRight");
449
+ const inner = /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("span", {
450
+ className: "tfb-row-label"
451
+ }, label), value !== undefined && /* @__PURE__ */ React.createElement("span", {
452
+ className: "tfb-row-value tfb-ellipsis",
453
+ title
454
+ }, value), children, onClick && /* @__PURE__ */ React.createElement("span", {
455
+ className: "tfb-row-chevron"
456
+ }, /* @__PURE__ */ React.createElement(Chevron, {
457
+ size: 15
458
+ })));
459
+ return onClick ? /* @__PURE__ */ React.createElement("button", {
460
+ type: "button",
461
+ className: "tfb-row",
462
+ onClick
463
+ }, inner) : /* @__PURE__ */ React.createElement("div", {
464
+ className: "tfb-row"
465
+ }, inner);
466
+ }
467
+ function useOwnAgents(room) {
468
+ const [agents, setAgents] = React.useState([]);
469
+ React.useEffect(() => {
470
+ const self = room.members.find((member) => member.self)?.member;
471
+ if (!self) {
472
+ return;
473
+ }
474
+ const key = `agents:${self}`;
475
+ pi.rooms.getState(room.id, key).then((state) => {
476
+ const value = state[key];
477
+ const list = value?.by === self && Array.isArray(value.value) ? value.value : [];
478
+ setAgents(list.filter((agent) => agent && typeof agent.id === "string" && typeof agent.name === "string"));
479
+ }, () => {
480
+ return;
481
+ });
482
+ }, [room.id, room.members]);
483
+ return agents;
484
+ }
485
+ function Setup({ room, settings, onDone }) {
486
+ const [cwd, setCwd] = React.useState(settings?.cwd ?? "");
487
+ const [problem, setProblem] = React.useState("");
488
+ const [agent, setAgent] = React.useState(settings?.agent ?? "");
489
+ const [guests, setGuests] = React.useState(settings?.admitGuests ?? true);
490
+ const [members, setMembers] = React.useState(settings ? room.capacity ?? 16 : DEFAULT_MEMBERS);
491
+ const [release, setRelease] = React.useState(settings?.release ?? "");
492
+ const [picking, setPicking] = React.useState(false);
493
+ const [busy, act] = useBusy();
494
+ const [menu, openMenu] = pi.ui.useContextMenu();
495
+ const agents = useOwnAgents(room);
496
+ const Check = icon("Check");
497
+ const speakers = [{ id: "", name: t("double") }, ...agents];
498
+ const choose = (event, items, current, set) => openMenu(event, [
499
+ items.map((item) => ({ key: item.key, label: item.label, ...item.value === current ? { icon: Check } : {}, run: () => set(item.value) }))
500
+ ]);
501
+ const pick = async (path) => {
502
+ setPicking(false);
503
+ try {
504
+ const found = await callFeedback({ kind: "check", cwd: path });
505
+ setCwd(found.top);
506
+ setProblem("");
507
+ } catch (error) {
508
+ setCwd(path);
509
+ setProblem(t("notGit", { reason: message(error) }));
510
+ }
511
+ };
512
+ const save = () => act(async () => {
513
+ await callFeedback({ kind: "enable", room: room.id, cwd, agent: agent || undefined, release, admitGuests: guests, members });
514
+ onDone?.();
515
+ });
516
+ return /* @__PURE__ */ React.createElement("div", {
517
+ className: "tfb-setup"
518
+ }, !settings && /* @__PURE__ */ React.createElement("p", {
519
+ className: "tfb-intro"
520
+ }, t("intro")), /* @__PURE__ */ React.createElement("div", {
521
+ className: "tfb-group"
522
+ }, /* @__PURE__ */ React.createElement(Row, {
523
+ label: t("project"),
524
+ value: cwd ? folderName(cwd) : t("pick"),
525
+ title: cwd,
526
+ onClick: () => setPicking(true)
527
+ }), /* @__PURE__ */ React.createElement(Row, {
528
+ label: t("speaker"),
529
+ value: speakers.find((each) => each.id === agent)?.name ?? t("double"),
530
+ onClick: (event) => choose(event, speakers.map((each) => ({ key: each.id || "double", label: each.name, value: each.id })), agent, setAgent)
531
+ }), /* @__PURE__ */ React.createElement(Row, {
532
+ label: t("members"),
533
+ value: t("membersValue", { n: members }),
534
+ onClick: (event) => choose(event, MEMBER_CHOICES.map((n) => ({ key: String(n), label: t("membersValue", { n }), value: n })), members, setMembers)
535
+ }), /* @__PURE__ */ React.createElement(Row, {
536
+ label: t("release"),
537
+ value: release || t("releaseDefault"),
538
+ title: release,
539
+ onClick: () => void pi.ui.input(t("release"), t("releaseHint"), { value: release || t("releaseDefault") }).then((text) => text !== undefined && setRelease(text.trim()))
540
+ })), problem && /* @__PURE__ */ React.createElement("p", {
541
+ className: "tfb-foot-note tfb-error"
542
+ }, problem), /* @__PURE__ */ React.createElement("div", {
543
+ className: "tfb-group"
544
+ }, /* @__PURE__ */ React.createElement(Row, {
545
+ label: t("guests")
546
+ }, /* @__PURE__ */ React.createElement(pi.ui.Switch, {
547
+ checked: guests,
548
+ label: t("guests"),
549
+ onChange: setGuests
550
+ }))), /* @__PURE__ */ React.createElement("p", {
551
+ className: "tfb-foot-note"
552
+ }, t("guestsHint")), /* @__PURE__ */ React.createElement("div", {
553
+ className: "tfb-buttons"
554
+ }, settings && onDone && /* @__PURE__ */ React.createElement("button", {
555
+ type: "button",
556
+ className: "ta-button",
557
+ disabled: busy,
558
+ onClick: onDone
559
+ }, t("cancel")), /* @__PURE__ */ React.createElement("button", {
560
+ type: "button",
561
+ className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
562
+ disabled: busy || !cwd || !!problem,
563
+ onClick: save
564
+ }, settings ? t("save") : t("turnOn"))), menu, picking && /* @__PURE__ */ React.createElement(pi.ui.FolderPicker, {
565
+ initial: cwd,
566
+ onPick: pick,
567
+ onClose: () => setPicking(false)
568
+ }));
569
+ }
570
+ function LinkDialog({ room, close }) {
571
+ const [link, setLink] = React.useState("");
572
+ const [busy, act] = useBusy();
573
+ return /* @__PURE__ */ React.createElement(pi.ui.Dialog, {
574
+ title: t("linkTitle"),
575
+ onClose: close
576
+ }, /* @__PURE__ */ React.createElement("div", {
577
+ className: "tfb-dialog"
578
+ }, /* @__PURE__ */ React.createElement("p", {
579
+ className: "tfb-note"
580
+ }, t("linkHint")), link ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
581
+ className: "tfb-qr"
582
+ }, /* @__PURE__ */ React.createElement(pi.ui.QrCode, {
583
+ text: link
584
+ })), /* @__PURE__ */ React.createElement("code", {
585
+ className: "tfb-link"
586
+ }, link), /* @__PURE__ */ React.createElement("div", {
587
+ className: "tfb-actions"
588
+ }, /* @__PURE__ */ React.createElement("button", {
589
+ type: "button",
590
+ className: "ta-button ta-primary",
591
+ onClick: () => void copy(link)
592
+ }, t("copy")))) : /* @__PURE__ */ React.createElement("div", {
593
+ className: "tfb-actions"
594
+ }, /* @__PURE__ */ React.createElement("button", {
595
+ type: "button",
596
+ className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
597
+ disabled: busy,
598
+ onClick: () => act(async () => setLink((await pi.rooms.invite(room.id, { days: INVITE_DAYS, renew: true })).link))
599
+ }, t("linkMake")))));
600
+ }
601
+ function Decide({ item, here }) {
602
+ const [busy, act] = useBusy();
603
+ return /* @__PURE__ */ React.createElement("div", {
604
+ className: "tfb-decide"
605
+ }, item.fixSession && !here && /* @__PURE__ */ React.createElement("button", {
606
+ type: "button",
607
+ className: "ta-button",
608
+ onClick: () => void pi.openChat?.(item.fixSession)
609
+ }, t("changes")), /* @__PURE__ */ React.createElement("button", {
610
+ type: "button",
611
+ className: "ta-button",
612
+ disabled: busy,
613
+ onClick: () => act(() => callFeedback({ kind: "decline", id: item.id }))
614
+ }, t("decline")), /* @__PURE__ */ React.createElement("button", {
615
+ type: "button",
616
+ className: `ta-button ta-primary${busy ? " ta-busy" : ""}`,
617
+ disabled: busy,
618
+ onClick: () => act(() => callFeedback({ kind: "release", id: item.id }).then(() => pi.ui.notify(t("approved"))))
619
+ }, t("approve")));
620
+ }
621
+ function ItemRow({ item }) {
622
+ const [busy, act] = useBusy();
623
+ const files = item.files?.length ?? 0;
624
+ const session = item.releaseSession ?? item.fixSession;
625
+ const retry = item.status === "failed" || item.status === "unchanged" || item.status === "declined";
626
+ return /* @__PURE__ */ React.createElement("li", {
627
+ className: `tfb-item${item.status === "review" ? " tfb-item-review" : ""}`
628
+ }, /* @__PURE__ */ React.createElement("div", {
629
+ className: "tfb-item-head"
630
+ }, /* @__PURE__ */ React.createElement("span", {
631
+ className: "tfb-n"
632
+ }, "#", item.n), /* @__PURE__ */ React.createElement("span", {
633
+ className: "tfb-item-title tfb-ellipsis"
634
+ }, item.title), /* @__PURE__ */ React.createElement(Status, {
635
+ status: item.status
636
+ })), /* @__PURE__ */ React.createElement("div", {
637
+ className: "tfb-item-meta tfb-ellipsis"
638
+ }, t("from", { names: [...new Set(item.reporters.map((reporter) => reporter.name))].join("、") }), files ? ` · ${t("files", { n: files })}` : ""), item.detail && /* @__PURE__ */ React.createElement("div", {
639
+ className: "tfb-item-detail"
640
+ }, item.detail), item.status === "review" ? /* @__PURE__ */ React.createElement(Decide, {
641
+ item
642
+ }) : (session || retry) && /* @__PURE__ */ React.createElement("div", {
643
+ className: "tfb-decide"
644
+ }, session && /* @__PURE__ */ React.createElement("button", {
645
+ type: "button",
646
+ className: "tfb-link-button",
647
+ onClick: () => void pi.openChat?.(session)
648
+ }, t("open")), retry && /* @__PURE__ */ React.createElement("button", {
649
+ type: "button",
650
+ className: "tfb-link-button",
651
+ disabled: busy,
652
+ onClick: () => act(() => callFeedback({ kind: "retry", id: item.id }))
653
+ }, t("retry"))));
654
+ }
655
+ function Section({ title, items }) {
656
+ if (!items.length) {
657
+ return null;
658
+ }
659
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
660
+ className: "tfb-section"
661
+ }, title, " · ", items.length), /* @__PURE__ */ React.createElement("ul", {
662
+ className: "tfb-items"
663
+ }, [...items].reverse().map((item) => /* @__PURE__ */ React.createElement(ItemRow, {
664
+ key: item.id,
665
+ item
666
+ }))));
667
+ }
668
+ function OwnerBoard({ room, settings }) {
669
+ const { items } = useFeedback();
670
+ const [editing, setEditing] = React.useState(false);
671
+ const [linking, setLinking] = React.useState(false);
672
+ const mine = items.filter((item) => item.room === room.id);
673
+ if (editing) {
674
+ return /* @__PURE__ */ React.createElement(Setup, {
675
+ room,
676
+ settings,
677
+ onDone: () => setEditing(false)
678
+ });
679
+ }
680
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", {
681
+ className: "tfb-group"
682
+ }, /* @__PURE__ */ React.createElement(Row, {
683
+ label: t("link"),
684
+ value: t("linkValue"),
685
+ onClick: () => setLinking(true)
686
+ }), /* @__PURE__ */ React.createElement(Row, {
687
+ label: t("settings"),
688
+ value: folderName(settings.cwd),
689
+ title: settings.cwd,
690
+ onClick: () => setEditing(true)
691
+ })), mine.length ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Section, {
692
+ title: t("review"),
693
+ items: mine.filter((item) => item.status === "review")
694
+ }), /* @__PURE__ */ React.createElement(Section, {
695
+ title: t("working"),
696
+ items: mine.filter((item) => OPEN.has(item.status))
697
+ }), /* @__PURE__ */ React.createElement(Section, {
698
+ title: t("ended"),
699
+ items: mine.filter((item) => item.status !== "review" && !OPEN.has(item.status))
700
+ })) : /* @__PURE__ */ React.createElement("div", {
701
+ className: "tfb-empty"
702
+ }, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
703
+ title: t("none"),
704
+ compact: true
705
+ })), /* @__PURE__ */ React.createElement("div", {
706
+ className: "tfb-foot"
707
+ }, /* @__PURE__ */ React.createElement("button", {
708
+ type: "button",
709
+ className: "tfb-link-button tfb-danger",
710
+ onClick: () => void pi.ui.confirm(t("turnOffTitle", { title: room.title }), t("turnOffHint"), { confirmLabel: t("turnOff"), danger: true }).then((yes) => yes && callFeedback({ kind: "disable", room: room.id })).catch((error) => pi.ui.notify(message(error), "error"))
711
+ }, t("turnOff"))), linking && /* @__PURE__ */ React.createElement(LinkDialog, {
712
+ room,
713
+ close: () => setLinking(false)
714
+ }));
715
+ }
716
+ function MemberBoard({ board }) {
717
+ if (!board.length) {
718
+ return /* @__PURE__ */ React.createElement("div", {
719
+ className: "tfb-empty"
720
+ }, /* @__PURE__ */ React.createElement(pi.ui.Empty, {
721
+ title: t("memberNone"),
722
+ compact: true
723
+ }));
724
+ }
725
+ return /* @__PURE__ */ React.createElement("ul", {
726
+ className: "tfb-items tfb-items-top"
727
+ }, [...board].reverse().map((item) => /* @__PURE__ */ React.createElement("li", {
728
+ key: item.n,
729
+ className: "tfb-item"
730
+ }, /* @__PURE__ */ React.createElement("div", {
731
+ className: "tfb-item-head"
732
+ }, /* @__PURE__ */ React.createElement("span", {
733
+ className: "tfb-n"
734
+ }, "#", item.n), /* @__PURE__ */ React.createElement("span", {
735
+ className: "tfb-item-title tfb-ellipsis"
736
+ }, item.title), /* @__PURE__ */ React.createElement(Status, {
737
+ status: item.status === "review" ? "fixing" : item.status
738
+ })), item.reporters.length > 0 && /* @__PURE__ */ React.createElement("div", {
739
+ className: "tfb-item-meta tfb-ellipsis"
740
+ }, t("from", { names: item.reporters.join("、") })))));
741
+ }
742
+ function FeedbackPage({ room }) {
743
+ const { settings, boards } = useFeedback();
744
+ const own = settings[room.id];
745
+ return /* @__PURE__ */ React.createElement("div", {
746
+ className: "tfb-panel"
747
+ }, /* @__PURE__ */ React.createElement("div", {
748
+ className: "tfb-panel-scroll"
749
+ }, room.owner ? own ? /* @__PURE__ */ React.createElement(OwnerBoard, {
750
+ room,
751
+ settings: own
752
+ }) : /* @__PURE__ */ React.createElement(Setup, {
753
+ room
754
+ }) : /* @__PURE__ */ React.createElement(MemberBoard, {
755
+ board: boards[room.id] ?? []
756
+ })));
757
+ }
758
+ function ReviewMessage({ message: shown }) {
759
+ const { items } = useFeedback();
760
+ const id = shown.details?.id;
761
+ const item = items.find((each) => each.id === id);
762
+ if (!item) {
763
+ return null;
764
+ }
765
+ const Branch = icon("GitBranch");
766
+ return /* @__PURE__ */ React.createElement("div", {
767
+ className: "tfb-card"
768
+ }, /* @__PURE__ */ React.createElement("div", {
769
+ className: "tfb-card-head"
770
+ }, /* @__PURE__ */ React.createElement("span", {
771
+ className: "tfb-card-icon"
772
+ }, /* @__PURE__ */ React.createElement(Branch, {
773
+ size: 15
774
+ })), /* @__PURE__ */ React.createElement("span", {
775
+ className: "tfb-item-title tfb-ellipsis"
776
+ }, t("reviewTitle", { n: item.n })), /* @__PURE__ */ React.createElement(Status, {
777
+ status: item.status
778
+ })), /* @__PURE__ */ React.createElement("div", {
779
+ className: "tfb-card-title"
780
+ }, item.title), item.files && item.files.length > 0 && /* @__PURE__ */ React.createElement("ul", {
781
+ className: "tfb-files"
782
+ }, item.files.slice(0, 8).map((file) => /* @__PURE__ */ React.createElement("li", {
783
+ key: file.path
784
+ }, /* @__PURE__ */ React.createElement("code", {
785
+ className: "tfb-ellipsis"
786
+ }, file.path), file.add >= 0 && /* @__PURE__ */ React.createElement("span", {
787
+ className: "tfb-add"
788
+ }, "+", file.add), file.del >= 0 && /* @__PURE__ */ React.createElement("span", {
789
+ className: "tfb-del"
790
+ }, "−", file.del)))), item.status === "review" && /* @__PURE__ */ React.createElement(Decide, {
791
+ item,
792
+ here: true
793
+ }));
794
+ }
795
+
796
+ // web-src/style.ts
797
+ var STYLE = `
798
+ .tfb-ellipsis { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
799
+ .tfb-note { margin: 0; color: var(--ta-muted); font-size: calc(12.5px * var(--ta-font-scale)); line-height: 1.5; }
800
+ .tfb-error { color: var(--ta-red); }
801
+ .tfb-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; background: var(--ta-main); color: var(--ta-text); font-size: calc(13.5px * var(--ta-font-scale)); }
802
+ .tfb-panel-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: 12px 12px calc(20px + env(safe-area-inset-bottom)); }
803
+ /* Groups of rows, as the settings of a phone */
804
+ .tfb-setup { display: flex; flex-direction: column; }
805
+ .tfb-intro { margin: 2px 4px 14px; color: var(--ta-secondary); font-size: calc(13px * var(--ta-font-scale)); line-height: 1.6; }
806
+ .tfb-group { border-radius: 12px; background: var(--ta-side); overflow: hidden; }
807
+ .tfb-group + .tfb-group, .tfb-foot-note + .tfb-group { margin-top: 14px; }
808
+ .tfb-row { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 46px; padding: 0 12px 0 14px; box-sizing: border-box; border: 0; background: none; color: var(--ta-text); font: inherit; text-align: left; }
809
+ button.tfb-row { cursor: pointer; }
810
+ button.tfb-row:hover { background: var(--ta-hover); }
811
+ .tfb-row { position: relative; }
812
+ .tfb-row + .tfb-row::before { content: ''; position: absolute; top: 0; left: 14px; right: 0; height: 1px; background: var(--ta-border-muted); }
813
+ .tfb-row-label { flex: 1; min-width: 0; }
814
+ .tfb-row-value { flex: none; max-width: 58%; color: var(--ta-muted); text-align: right; }
815
+ .tfb-row-chevron { display: inline-flex; flex: none; margin-left: -4px; color: var(--ta-muted); }
816
+ .tfb-foot-note { margin: 6px 14px 0; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); line-height: 1.5; }
817
+ .tfb-buttons { display: flex; gap: 8px; margin-top: 20px; }
818
+ .tfb-buttons .ta-button { flex: 1; min-height: 40px; }
819
+ .tfb-section { padding: 18px 4px 8px; color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
820
+ .tfb-empty { padding: 20px 0 4px; }
821
+ /* Reports */
822
+ .tfb-items { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
823
+ .tfb-items-top { margin-top: 2px; }
824
+ .tfb-item { display: flex; flex-direction: column; gap: 4px; padding: 12px; border-radius: 12px; background: var(--ta-side); }
825
+ .tfb-item-review { box-shadow: inset 0 0 0 1px color-mix(in srgb, var(--ta-link) 45%, transparent); }
826
+ .tfb-item-head, .tfb-card-head { display: flex; align-items: center; gap: 8px; min-width: 0; }
827
+ .tfb-n { flex: none; color: var(--ta-muted); font-variant-numeric: tabular-nums; font-size: calc(12px * var(--ta-font-scale)); }
828
+ .tfb-item-title { flex: 1; font-weight: 500; }
829
+ .tfb-item-meta { color: var(--ta-muted); font-size: calc(12px * var(--ta-font-scale)); }
830
+ .tfb-item-detail { color: var(--ta-secondary); font-size: calc(12.5px * var(--ta-font-scale)); line-height: 1.5; overflow-wrap: anywhere; }
831
+ .tfb-status { flex: none; padding: 0 7px; border-radius: 6px; background: var(--ta-hover); color: var(--ta-secondary); font-size: calc(11px * var(--ta-font-scale)); line-height: calc(18px * var(--ta-font-scale)); }
832
+ .tfb-status-review { background: color-mix(in srgb, var(--ta-link) 14%, transparent); color: var(--ta-link); }
833
+ .tfb-status-fixing, .tfb-status-releasing { background: color-mix(in srgb, var(--ta-yellow) 16%, transparent); color: var(--ta-text); }
834
+ .tfb-status-released { background: color-mix(in srgb, var(--ta-green) 14%, transparent); color: var(--ta-green); }
835
+ .tfb-status-failed { color: var(--ta-red); }
836
+ .tfb-decide { display: flex; justify-content: flex-end; align-items: center; gap: 8px; flex-wrap: wrap; margin-top: 6px; }
837
+ .tfb-link-button { padding: 2px 4px; border: 0; background: none; color: var(--ta-link); font: inherit; font-size: calc(12.5px * var(--ta-font-scale)); cursor: pointer; }
838
+ .tfb-link-button:disabled { opacity: 0.5; }
839
+ .tfb-danger { color: var(--ta-red); }
840
+ .tfb-foot { display: flex; justify-content: center; padding: 24px 0 4px; }
841
+ .tfb-actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
842
+ .tfb-dialog { display: flex; flex-direction: column; gap: 12px; }
843
+ .tfb-qr { display: flex; justify-content: center; }
844
+ .tfb-link { display: block; padding: 8px 10px; border-radius: 8px; background: var(--ta-side); font-family: var(--ta-mono); font-size: calc(11.5px * var(--ta-font-scale)); overflow-wrap: anywhere; }
845
+ /* The card of a fix in its conversation */
846
+ .tfb-card { display: flex; flex-direction: column; gap: 8px; max-width: 520px; padding: 12px; border: 1px solid var(--ta-border-muted); border-radius: 14px; background: var(--ta-side); }
847
+ .tfb-card-title { font-weight: 500; }
848
+ .tfb-card-icon { display: grid; place-items: center; flex: none; width: 26px; height: 26px; border-radius: 8px; background: var(--ta-tint-3); color: var(--ta-tint-ink-3); }
849
+ .tfb-files { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 2px; }
850
+ .tfb-files li { display: flex; align-items: center; gap: 8px; min-width: 0; font-size: calc(12px * var(--ta-font-scale)); }
851
+ .tfb-files code { flex: 1; font-family: var(--ta-mono); color: var(--ta-secondary); }
852
+ .tfb-add { color: var(--ta-green); font-variant-numeric: tabular-nums; }
853
+ .tfb-del { color: var(--ta-red); font-variant-numeric: tabular-nums; }
854
+ `;
855
+ function injectStyle() {
856
+ const element = document.createElement("style");
857
+ element.dataset.taPackage = "ta-feedback";
858
+ element.textContent = STYLE;
859
+ document.head.appendChild(element);
860
+ return () => element.remove();
861
+ }
862
+
863
+ // web-src/index.tsx
864
+ var OPEN2 = new Set(["new", "fixing", "releasing"]);
865
+ function counts(parts) {
866
+ return parts.filter(([n]) => n > 0).map(([n, key]) => t(key, { n }));
867
+ }
868
+ function activate(pi2) {
869
+ bind(pi2.React);
870
+ bindPage(pi2);
871
+ const removeStyle = injectStyle();
872
+ const stopStore = pi2.rooms ? store.start() : () => {
873
+ return;
874
+ };
875
+ pi2.registerMessageRenderer(REVIEW_TYPE, ReviewMessage);
876
+ pi2.registerRoomAddon?.({
877
+ subscribe: store.subscribe,
878
+ page: FeedbackPage,
879
+ tile: (room) => {
880
+ const { settings, items, boards } = store.get();
881
+ if (room.owner) {
882
+ if (room.unlisted) {
883
+ return;
884
+ }
885
+ if (!settings[room.id]) {
886
+ return { label: t("feedback"), icon: "Bug", status: t("off") };
887
+ }
888
+ const mine = items.filter((item) => item.room === room.id);
889
+ const review = mine.filter((item) => item.status === "review").length;
890
+ const working = mine.filter((item) => OPEN2.has(item.status)).length;
891
+ return {
892
+ label: t("feedback"),
893
+ icon: "Bug",
894
+ status: counts([
895
+ [review, "reviewCount"],
896
+ [working, "workingCount"]
897
+ ])[0] ?? t("on"),
898
+ attention: review > 0
899
+ };
900
+ }
901
+ const board = boards[room.id];
902
+ if (!board) {
903
+ return;
904
+ }
905
+ const open = board.filter((item) => OPEN2.has(item.status) || item.status === "review").length;
906
+ return { label: t("feedback"), icon: "Bug", status: counts([[open, "workingCount"]])[0] ?? t("on") };
907
+ },
908
+ line: (room) => {
909
+ const { settings, items, boards } = store.get();
910
+ if (room.owner) {
911
+ if (!settings[room.id]) {
912
+ return;
913
+ }
914
+ const mine = items.filter((item) => item.room === room.id);
915
+ const parts2 = counts([
916
+ [mine.filter((item) => item.status === "review").length, "reviewCount"],
917
+ [mine.filter((item) => OPEN2.has(item.status)).length, "workingCount"]
918
+ ]);
919
+ return { text: parts2.length ? `${t("feedback")} · ${parts2.join(" · ")}` : t("lineQuiet"), icon: "Bug" };
920
+ }
921
+ const board = boards[room.id];
922
+ if (!board) {
923
+ return;
924
+ }
925
+ const parts = counts([
926
+ [board.filter((item) => OPEN2.has(item.status) || item.status === "review").length, "workingCount"],
927
+ [board.filter((item) => item.status === "released").length, "doneCount"]
928
+ ]);
929
+ return { text: parts.length ? `${t("feedback")} · ${parts.join(" · ")}` : t("lineQuiet"), icon: "Bug" };
930
+ }
931
+ });
932
+ return () => {
933
+ stopStore();
934
+ removeStyle();
935
+ };
936
+ }
937
+ export {
938
+ activate as default
939
+ };