@bridgebrew/sessions 0.0.8 → 0.0.9
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/browser/decision-questions.tsx +3 -3
- package/browser/index.tsx +12 -3
- package/browser/mobile.tsx +8 -2
- package/package.json +1 -1
- package/server.ts +3 -1
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
// field where a free answer is allowed, and one Submit for the whole request (enabled once every required question has
|
|
4
4
|
// an answer, `checkAnswer`), beside Dismiss.
|
|
5
5
|
import * as React from 'react';
|
|
6
|
-
import { Button, Checkbox, Icon, Textarea, cn } from '@bridge/ui';
|
|
6
|
+
import { Button, Checkbox, Icon, Textarea, cn, isComposing } from '@bridge/ui';
|
|
7
7
|
import { checkAnswer, type Answers, type Question } from '../answers.ts';
|
|
8
8
|
|
|
9
9
|
export function DecisionQuestions({
|
|
@@ -161,8 +161,8 @@ export function DecisionQuestions({
|
|
|
161
161
|
setChosen((was) => ({ ...was, [question.id]: [] }));
|
|
162
162
|
}}
|
|
163
163
|
onKeyDown={(event) => {
|
|
164
|
-
// ⌘↵ submits the request; ↵ alone is a new line.
|
|
165
|
-
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
|
|
164
|
+
// ⌘↵ submits the request; ↵ alone is a new line; an input method's ↵ is its own.
|
|
165
|
+
if (event.key === 'Enter' && (event.metaKey || event.ctrlKey) && !isComposing(event)) {
|
|
166
166
|
event.preventDefault();
|
|
167
167
|
event.currentTarget.form?.requestSubmit();
|
|
168
168
|
}
|
package/browser/index.tsx
CHANGED
|
@@ -1398,6 +1398,12 @@ function Sessions({
|
|
|
1398
1398
|
if ((cause as Error)?.name !== 'AbortError')
|
|
1399
1399
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
1400
1400
|
};
|
|
1401
|
+
/** A queued message the queue started meanwhile (plugins#91): said so, and the queue shown as it is now. */
|
|
1402
|
+
const started = (cause: unknown) => {
|
|
1403
|
+
if ((cause as { code?: unknown })?.code !== 'not_found') return report(cause);
|
|
1404
|
+
setError('This message has already been sent');
|
|
1405
|
+
void load();
|
|
1406
|
+
};
|
|
1401
1407
|
// Stable: the views' fallback (`renderComponent`) takes it, and a new one would redraw every turn (bridge#193).
|
|
1402
1408
|
const post = React.useCallback(
|
|
1403
1409
|
(path: string, body: object) =>
|
|
@@ -2194,6 +2200,9 @@ function Sessions({
|
|
|
2194
2200
|
onKey.current = (event) => {
|
|
2195
2201
|
// Another window is the one the user works in, or a modal dialog is open over the page: the keys are its own.
|
|
2196
2202
|
if (focused === false || modalOpen()) return;
|
|
2203
|
+
// A key of an input method's composition (Japanese, Chinese, Korean…) is the composition's: the Escape that cancels
|
|
2204
|
+
// a conversion never counts toward stopping the turn (#90).
|
|
2205
|
+
if (isComposing(event)) return;
|
|
2197
2206
|
// Escape twice within a second stops the running turn (a dialog, a menu or a popup list open takes the first one;
|
|
2198
2207
|
// the session lists, always there, do not count).
|
|
2199
2208
|
if (
|
|
@@ -2529,12 +2538,12 @@ function Sessions({
|
|
|
2529
2538
|
prompt?.addText(id, item.text, back);
|
|
2530
2539
|
promptHandle.current?.focus();
|
|
2531
2540
|
return load();
|
|
2532
|
-
},
|
|
2541
|
+
}, started);
|
|
2533
2542
|
}}
|
|
2534
2543
|
onRemove={(item) =>
|
|
2535
2544
|
void post(`/queue/remove?id=${encodeURIComponent(session.id)}`, { item }).then(
|
|
2536
2545
|
load,
|
|
2537
|
-
|
|
2546
|
+
started,
|
|
2538
2547
|
)
|
|
2539
2548
|
}
|
|
2540
2549
|
/>
|
|
@@ -2903,7 +2912,7 @@ function Sessions({
|
|
|
2903
2912
|
onKeyDown={(event) => {
|
|
2904
2913
|
if (event.key === 'Enter' && !isComposing(event))
|
|
2905
2914
|
event.currentTarget.blur();
|
|
2906
|
-
else if (event.key === 'Escape') {
|
|
2915
|
+
else if (event.key === 'Escape' && !isComposing(event)) {
|
|
2907
2916
|
setDraft(undefined);
|
|
2908
2917
|
requestAnimationFrame(() => titleField.current?.blur());
|
|
2909
2918
|
}
|
package/browser/mobile.tsx
CHANGED
|
@@ -405,6 +405,12 @@ function MobileSession({
|
|
|
405
405
|
if ((cause as Error)?.name !== 'AbortError')
|
|
406
406
|
setError(cause instanceof Error ? cause.message : String(cause));
|
|
407
407
|
};
|
|
408
|
+
/** A queued message the queue started meanwhile (plugins#91): said so, and the queue shown as it is now. */
|
|
409
|
+
const started = (cause: unknown) => {
|
|
410
|
+
if ((cause as { code?: unknown })?.code !== 'not_found') return report(cause);
|
|
411
|
+
setError('This message has already been sent');
|
|
412
|
+
void load();
|
|
413
|
+
};
|
|
408
414
|
const post = (path: string, body: object) =>
|
|
409
415
|
workspace
|
|
410
416
|
.fetch(`${api}${path}`, {
|
|
@@ -626,12 +632,12 @@ function MobileSession({
|
|
|
626
632
|
prompt?.addText(id, queued.text, back);
|
|
627
633
|
promptHandle.current?.focus();
|
|
628
634
|
return load();
|
|
629
|
-
},
|
|
635
|
+
}, started);
|
|
630
636
|
}}
|
|
631
637
|
onRemove={(queued) =>
|
|
632
638
|
void post(`/queue/remove?id=${encodeURIComponent(id)}`, {
|
|
633
639
|
item: queued,
|
|
634
|
-
}).then(load,
|
|
640
|
+
}).then(load, started)
|
|
635
641
|
}
|
|
636
642
|
/>
|
|
637
643
|
)}
|
package/package.json
CHANGED
package/server.ts
CHANGED
|
@@ -5008,8 +5008,10 @@ export async function apply(ctx: Context, config?: unknown) {
|
|
|
5008
5008
|
handle: async ({ query, body }) => {
|
|
5009
5009
|
const found = await find(query);
|
|
5010
5010
|
const { item } = parse(queuedBody, body, 'POST /sessions/queue/remove takes { item }');
|
|
5011
|
+
// A message the queue has already started is refused, as Send now: Edit then does not copy it back (plugins#91).
|
|
5011
5012
|
await change(found.id, ({ queue, ...now }) => {
|
|
5012
|
-
|
|
5013
|
+
if (!queue?.some((each) => each.id === item)) throw refused('not_found', `no queued message ${item}`, 404);
|
|
5014
|
+
const rest = queue.filter((each) => each.id !== item);
|
|
5013
5015
|
return rest.length ? { ...now, queue: rest } : now;
|
|
5014
5016
|
});
|
|
5015
5017
|
emit(found.id, { type: 'queue' });
|