@celljs/ta-web 4.11.0 → 4.13.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/README.en.md +1 -1
- package/README.md +1 -1
- package/esm/browser/assistant/assistant-extension.js +14 -0
- package/esm/browser/assistant/assistant-initiative.d.ts +27 -0
- package/esm/browser/assistant/assistant-initiative.js +76 -0
- package/esm/browser/assistant/assistant-task-source.d.ts +7 -0
- package/esm/browser/assistant/assistant-task-source.js +12 -2
- package/esm/browser/assistant/assistant-view.js +10 -6
- package/esm/browser/assistant/assistant.d.ts +5 -0
- package/esm/browser/assistant/assistant.js +25 -6
- package/esm/browser/chat/chat-view.js +6 -5
- package/esm/browser/components/app-nav.d.ts +3 -1
- package/esm/browser/components/app-nav.js +5 -2
- package/esm/browser/components/app-view.js +26 -13
- package/esm/browser/components/asks-badge.d.ts +5 -0
- package/esm/browser/components/asks-badge.js +8 -0
- package/esm/browser/components/chat-asks.d.ts +46 -0
- package/esm/browser/components/chat-asks.js +101 -0
- package/esm/browser/components/chat-list.d.ts +7 -1
- package/esm/browser/components/chat-list.js +46 -17
- package/esm/browser/components/composer-addon-util.d.ts +11 -0
- package/esm/browser/components/composer-addon-util.js +40 -0
- package/esm/browser/components/composer-addons.d.ts +1 -7
- package/esm/browser/components/composer-addons.js +1 -27
- package/esm/browser/components/composer-box.d.ts +1 -0
- package/esm/browser/components/composer-box.js +50 -28
- package/esm/browser/components/composer.d.ts +10 -1
- package/esm/browser/components/composer.js +61 -22
- package/esm/browser/components/connection-bar.js +31 -12
- package/esm/browser/components/conversation-scroll-hooks.d.ts +16 -0
- package/esm/browser/components/conversation-scroll-hooks.js +98 -0
- package/esm/browser/components/conversation-scroll-util.d.ts +35 -0
- package/esm/browser/components/conversation-scroll-util.js +74 -0
- package/esm/browser/components/conversation-scroll.d.ts +57 -33
- package/esm/browser/components/conversation-scroll.js +188 -123
- package/esm/browser/components/discover-view.js +5 -1
- package/esm/browser/components/earlier-messages.d.ts +10 -3
- package/esm/browser/components/earlier-messages.js +14 -8
- package/esm/browser/components/face.d.ts +24 -0
- package/esm/browser/components/face.js +42 -0
- package/esm/browser/components/folder-picker.d.ts +2 -0
- package/esm/browser/components/folder-picker.js +7 -0
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/markdown.js +4 -2
- package/esm/browser/components/media.js +25 -11
- package/esm/browser/components/mermaid-view.js +45 -3
- package/esm/browser/components/message-actions.js +1 -0
- package/esm/browser/components/message-footer.d.ts +4 -0
- package/esm/browser/components/message-footer.js +8 -1
- package/esm/browser/components/message-list.d.ts +15 -1
- package/esm/browser/components/message-list.js +204 -41
- package/esm/browser/components/phone-shell.d.ts +7 -2
- package/esm/browser/components/phone-shell.js +9 -3
- package/esm/browser/components/relay-services.d.ts +24 -0
- package/esm/browser/components/relay-services.js +249 -0
- package/esm/browser/components/relay-view.js +17 -1
- package/esm/browser/components/remote-hosts.js +1 -1
- package/esm/browser/components/session-view.d.ts +3 -1
- package/esm/browser/components/session-view.js +23 -7
- package/esm/browser/components/settings-controls.js +3 -3
- package/esm/browser/components/settings-parts.js +13 -1
- package/esm/browser/components/stop-times.d.ts +47 -0
- package/esm/browser/components/stop-times.js +81 -0
- package/esm/browser/components/ta-avatar.js +6 -0
- package/esm/browser/components/tool-result.d.ts +13 -0
- package/esm/browser/components/tool-result.js +138 -0
- package/esm/browser/components/tool-view.js +5 -15
- package/esm/browser/components/use-stop-times.d.ts +3 -0
- package/esm/browser/components/use-stop-times.js +17 -0
- package/esm/browser/components/web-composer.js +2 -1
- package/esm/browser/device/photo-picker.d.ts +14 -0
- package/esm/browser/device/photo-picker.js +48 -0
- package/esm/browser/device/row-swipe.d.ts +2 -0
- package/esm/browser/device/row-swipe.js +8 -2
- package/esm/browser/device/sheet-swipe.d.ts +1 -1
- package/esm/browser/device/sheet-swipe.js +17 -3
- package/esm/browser/extension/extension-view.d.ts +3 -1
- package/esm/browser/extension/extension-view.js +7 -0
- package/esm/browser/extension/icons.js +10 -1
- package/esm/browser/extension/web-api-components.d.ts +21 -3
- package/esm/browser/extension/web-api-contributions.d.ts +128 -0
- package/esm/browser/extension/web-extension-api.d.ts +45 -48
- package/esm/browser/extension/web-extension-context.d.ts +6 -1
- package/esm/browser/extension/web-extension-context.js +72 -7
- package/esm/browser/extension/web-extension-protocol.d.ts +18 -2
- package/esm/browser/extension/web-extension-protocol.js +2 -0
- package/esm/browser/extension/web-extension-run.d.ts +3 -2
- package/esm/browser/extension/web-extension-run.js +3 -0
- package/esm/browser/extension/web-extensions.d.ts +2 -8
- package/esm/browser/extension/web-extensions.js +12 -35
- package/esm/browser/extension/web-page-list.d.ts +25 -0
- package/esm/browser/extension/web-page-list.js +35 -0
- package/esm/browser/extension/web-session-notices.d.ts +6 -1
- package/esm/browser/extension/web-session-notices.js +30 -4
- package/esm/browser/extension/web-sharing.d.ts +5 -2
- package/esm/browser/extension/web-sharing.js +10 -1
- package/esm/browser/i18n/locales.d.ts +77 -1
- package/esm/browser/i18n/messages.d.ts +76 -0
- package/esm/browser/i18n/messages.js +154 -2
- package/esm/browser/links/links-protocol.d.ts +2 -0
- package/esm/browser/links/links.d.ts +7 -2
- package/esm/browser/links/links.js +16 -9
- package/esm/browser/markdown/code-renderers.d.ts +4 -0
- package/esm/browser/markdown/code-renderers.js +4 -0
- package/esm/browser/markdown/lazy.d.ts +8 -0
- package/esm/browser/markdown/lazy.js +35 -0
- package/esm/browser/markdown/mermaid.d.ts +15 -3
- package/esm/browser/markdown/mermaid.js +45 -6
- package/esm/browser/notices/notices-protocol.d.ts +5 -0
- package/esm/browser/notices/notices.d.ts +19 -0
- package/esm/browser/notices/notices.js +85 -2
- package/esm/browser/notices/session-notices.d.ts +5 -2
- package/esm/browser/notices/session-notices.js +10 -1
- package/esm/browser/style/base.d.ts +1 -1
- package/esm/browser/style/base.js +2 -1
- package/esm/browser/style/conversation.d.ts +1 -1
- package/esm/browser/style/conversation.js +53 -0
- package/esm/browser/style/device.js +3 -0
- package/esm/browser/style/layout.d.ts +1 -1
- package/esm/browser/style/layout.js +27 -9
- package/esm/browser/style/pages.d.ts +1 -1
- package/esm/browser/style/pages.js +5 -0
- package/esm/browser/style/phone.d.ts +1 -1
- package/esm/browser/style/phone.js +2 -0
- package/esm/browser/style/shell.d.ts +1 -1
- package/esm/browser/style/shell.js +16 -3
- package/esm/browser/style/surfaces.d.ts +1 -1
- package/esm/browser/style/surfaces.js +19 -0
- package/esm/browser/util/desktop.d.ts +18 -1
- package/esm/browser/util/desktop.js +13 -0
- package/esm/browser/util/frame.d.ts +2 -0
- package/esm/browser/util/frame.js +2 -0
- package/esm/browser/util/process.d.ts +69 -2
- package/esm/browser/util/process.js +163 -8
- package/esm/browser/util/progress.d.ts +6 -1
- package/esm/browser/util/progress.js +11 -2
- package/esm/browser/util/scroll-rest.d.ts +10 -0
- package/esm/browser/util/scroll-rest.js +44 -0
- package/esm/browser/util/tool-result.d.ts +32 -0
- package/esm/browser/util/tool-result.js +85 -0
- package/esm/browser/util/tool.js +7 -0
- package/lib/browser/assistant/assistant-extension.js +14 -0
- package/lib/browser/assistant/assistant-initiative.d.ts +28 -0
- package/lib/browser/assistant/assistant-initiative.js +80 -0
- package/lib/browser/assistant/assistant-task-source.d.ts +7 -0
- package/lib/browser/assistant/assistant-task-source.js +12 -2
- package/lib/browser/assistant/assistant-view.js +8 -4
- package/lib/browser/assistant/assistant.d.ts +5 -0
- package/lib/browser/assistant/assistant.js +24 -5
- package/lib/browser/chat/chat-view.js +6 -5
- package/lib/browser/components/app-nav.d.ts +3 -1
- package/lib/browser/components/app-nav.js +5 -2
- package/lib/browser/components/app-view.js +25 -12
- package/lib/browser/components/asks-badge.d.ts +6 -0
- package/lib/browser/components/asks-badge.js +44 -0
- package/lib/browser/components/chat-asks.d.ts +47 -0
- package/lib/browser/components/chat-asks.js +104 -0
- package/lib/browser/components/chat-list.d.ts +7 -1
- package/lib/browser/components/chat-list.js +46 -17
- package/lib/browser/components/composer-addon-util.d.ts +12 -0
- package/lib/browser/components/composer-addon-util.js +76 -0
- package/lib/browser/components/composer-addons.d.ts +1 -7
- package/lib/browser/components/composer-addons.js +2 -29
- package/lib/browser/components/composer-box.d.ts +1 -0
- package/lib/browser/components/composer-box.js +48 -26
- package/lib/browser/components/composer.d.ts +10 -1
- package/lib/browser/components/composer.js +61 -21
- package/lib/browser/components/connection-bar.js +30 -11
- package/lib/browser/components/conversation-scroll-hooks.d.ts +17 -0
- package/lib/browser/components/conversation-scroll-hooks.js +135 -0
- package/lib/browser/components/conversation-scroll-util.d.ts +36 -0
- package/lib/browser/components/conversation-scroll-util.js +78 -0
- package/lib/browser/components/conversation-scroll.d.ts +57 -33
- package/lib/browser/components/conversation-scroll.js +189 -158
- package/lib/browser/components/discover-view.js +5 -1
- package/lib/browser/components/earlier-messages.d.ts +10 -3
- package/lib/browser/components/earlier-messages.js +16 -9
- package/lib/browser/components/face.d.ts +25 -0
- package/lib/browser/components/face.js +79 -0
- package/lib/browser/components/folder-picker.d.ts +2 -0
- package/lib/browser/components/folder-picker.js +7 -0
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/markdown.js +3 -1
- package/lib/browser/components/media.js +24 -10
- package/lib/browser/components/mermaid-view.js +45 -3
- package/lib/browser/components/message-actions.js +1 -0
- package/lib/browser/components/message-footer.d.ts +4 -0
- package/lib/browser/components/message-footer.js +8 -0
- package/lib/browser/components/message-list.d.ts +15 -1
- package/lib/browser/components/message-list.js +200 -35
- package/lib/browser/components/phone-shell.d.ts +7 -2
- package/lib/browser/components/phone-shell.js +9 -3
- package/lib/browser/components/relay-services.d.ts +25 -0
- package/lib/browser/components/relay-services.js +286 -0
- package/lib/browser/components/relay-view.js +17 -1
- package/lib/browser/components/remote-hosts.js +1 -1
- package/lib/browser/components/session-view.d.ts +3 -1
- package/lib/browser/components/session-view.js +23 -7
- package/lib/browser/components/settings-controls.js +3 -3
- package/lib/browser/components/settings-parts.js +13 -1
- package/lib/browser/components/stop-times.d.ts +48 -0
- package/lib/browser/components/stop-times.js +85 -0
- package/lib/browser/components/ta-avatar.js +6 -0
- package/lib/browser/components/tool-result.d.ts +14 -0
- package/lib/browser/components/tool-result.js +175 -0
- package/lib/browser/components/tool-view.js +10 -20
- package/lib/browser/components/use-stop-times.d.ts +4 -0
- package/lib/browser/components/use-stop-times.js +53 -0
- package/lib/browser/components/web-composer.js +2 -1
- package/lib/browser/device/photo-picker.d.ts +15 -0
- package/lib/browser/device/photo-picker.js +51 -0
- package/lib/browser/device/row-swipe.d.ts +2 -0
- package/lib/browser/device/row-swipe.js +8 -2
- package/lib/browser/device/sheet-swipe.d.ts +1 -1
- package/lib/browser/device/sheet-swipe.js +17 -3
- package/lib/browser/extension/extension-view.d.ts +3 -1
- package/lib/browser/extension/extension-view.js +8 -1
- package/lib/browser/extension/icons.js +9 -0
- package/lib/browser/extension/web-api-components.d.ts +21 -3
- package/lib/browser/extension/web-api-contributions.d.ts +128 -0
- package/lib/browser/extension/web-extension-api.d.ts +45 -48
- package/lib/browser/extension/web-extension-context.d.ts +6 -1
- package/lib/browser/extension/web-extension-context.js +73 -8
- package/lib/browser/extension/web-extension-protocol.d.ts +18 -2
- package/lib/browser/extension/web-extension-protocol.js +2 -0
- package/lib/browser/extension/web-extension-run.d.ts +3 -2
- package/lib/browser/extension/web-extension-run.js +3 -0
- package/lib/browser/extension/web-extensions.d.ts +2 -8
- package/lib/browser/extension/web-extensions.js +12 -35
- package/lib/browser/extension/web-page-list.d.ts +26 -0
- package/lib/browser/extension/web-page-list.js +39 -0
- package/lib/browser/extension/web-session-notices.d.ts +6 -1
- package/lib/browser/extension/web-session-notices.js +30 -4
- package/lib/browser/extension/web-sharing.d.ts +5 -2
- package/lib/browser/extension/web-sharing.js +10 -1
- package/lib/browser/i18n/locales.d.ts +77 -1
- package/lib/browser/i18n/messages.d.ts +76 -0
- package/lib/browser/i18n/messages.js +154 -2
- package/lib/browser/links/links-protocol.d.ts +2 -0
- package/lib/browser/links/links.d.ts +7 -2
- package/lib/browser/links/links.js +16 -9
- package/lib/browser/markdown/code-renderers.d.ts +4 -0
- package/lib/browser/markdown/code-renderers.js +5 -1
- package/lib/browser/markdown/lazy.d.ts +8 -0
- package/lib/browser/markdown/lazy.js +37 -1
- package/lib/browser/markdown/mermaid.d.ts +15 -3
- package/lib/browser/markdown/mermaid.js +44 -5
- package/lib/browser/notices/notices-protocol.d.ts +5 -0
- package/lib/browser/notices/notices.d.ts +19 -0
- package/lib/browser/notices/notices.js +84 -1
- package/lib/browser/notices/session-notices.d.ts +5 -2
- package/lib/browser/notices/session-notices.js +10 -1
- package/lib/browser/style/base.d.ts +1 -1
- package/lib/browser/style/base.js +2 -1
- package/lib/browser/style/conversation.d.ts +1 -1
- package/lib/browser/style/conversation.js +53 -0
- package/lib/browser/style/device.js +3 -0
- package/lib/browser/style/layout.d.ts +1 -1
- package/lib/browser/style/layout.js +27 -9
- package/lib/browser/style/pages.d.ts +1 -1
- package/lib/browser/style/pages.js +5 -0
- package/lib/browser/style/phone.d.ts +1 -1
- package/lib/browser/style/phone.js +2 -0
- package/lib/browser/style/shell.d.ts +1 -1
- package/lib/browser/style/shell.js +16 -3
- package/lib/browser/style/surfaces.d.ts +1 -1
- package/lib/browser/style/surfaces.js +19 -0
- package/lib/browser/util/desktop.d.ts +18 -1
- package/lib/browser/util/desktop.js +13 -0
- package/lib/browser/util/frame.d.ts +2 -0
- package/lib/browser/util/frame.js +2 -0
- package/lib/browser/util/process.d.ts +69 -2
- package/lib/browser/util/process.js +165 -9
- package/lib/browser/util/progress.d.ts +6 -1
- package/lib/browser/util/progress.js +11 -2
- package/lib/browser/util/scroll-rest.d.ts +11 -0
- package/lib/browser/util/scroll-rest.js +47 -0
- package/lib/browser/util/tool-result.d.ts +33 -0
- package/lib/browser/util/tool-result.js +88 -0
- package/lib/browser/util/tool.js +7 -0
- package/package.json +7 -7
|
@@ -1,11 +1,12 @@
|
|
|
1
|
-
import { ArrowUp, AtSign, ImagePlus, Keyboard, Mic, Plus, Slash, Square, X } from 'lucide-react';
|
|
1
|
+
import { ArrowUp, AtSign, Camera, ImagePlus, Images, Keyboard, Mic, Plus, Slash, Square, X } from 'lucide-react';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useDevice } from '../device/device.js';
|
|
4
4
|
import { useHeld } from '../device/hold.js';
|
|
5
5
|
import { LongPressUtil } from '../device/long-press.js';
|
|
6
|
+
import { PhotoPicker } from '../device/photo-picker.js';
|
|
6
7
|
import { RecentShots } from '../device/recent-shots.js';
|
|
7
8
|
import { useT } from '../i18n/use-t.js';
|
|
8
|
-
import { ComposerUtil, IMAGE_TYPES } from '../util/composer.js';
|
|
9
|
+
import { ComposerUtil, IMAGE_TYPES, MAX_IMAGES } from '../util/composer.js';
|
|
9
10
|
import { FileDragUtil } from '../util/file-drag.js';
|
|
10
11
|
import { Voice } from '../util/voice.js';
|
|
11
12
|
import { ComposerMenu } from './composer-menu.js';
|
|
@@ -59,6 +60,20 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
59
60
|
const [dragging, setDragging] = React.useState(false);
|
|
60
61
|
const [menu, setMenu] = React.useState(false);
|
|
61
62
|
const [listening, setListening] = React.useState(false);
|
|
63
|
+
// Stop pressed: the run may take a moment to end (a tool winding down), and the press must show at once.
|
|
64
|
+
const [stopping, setStopping] = React.useState(false);
|
|
65
|
+
React.useEffect(() => {
|
|
66
|
+
if (!working) {
|
|
67
|
+
setStopping(false);
|
|
68
|
+
}
|
|
69
|
+
}, [working]);
|
|
70
|
+
const stop = () => {
|
|
71
|
+
if (!onStop || stopping) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
setStopping(true);
|
|
75
|
+
Promise.resolve(onStop()).catch(() => setStopping(false));
|
|
76
|
+
};
|
|
62
77
|
const touch = useDevice(device => device.touch);
|
|
63
78
|
// On a phone the + menu is a panel under the box, in place of the keyboard, as WeChat's.
|
|
64
79
|
const handheld = useDevice(device => device.handheld);
|
|
@@ -70,6 +85,7 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
70
85
|
const [focused, setFocused] = React.useState(false);
|
|
71
86
|
const input = React.useRef(null);
|
|
72
87
|
const picker = React.useRef(null);
|
|
88
|
+
const camera = React.useRef(null);
|
|
73
89
|
const plus = React.useRef(null);
|
|
74
90
|
const panel = React.useRef(null);
|
|
75
91
|
const menuId = React.useId();
|
|
@@ -364,6 +380,12 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
364
380
|
});
|
|
365
381
|
}
|
|
366
382
|
};
|
|
383
|
+
const onPicked = (event) => {
|
|
384
|
+
if (event.target.files) {
|
|
385
|
+
addFiles(event.target.files);
|
|
386
|
+
}
|
|
387
|
+
event.target.value = '';
|
|
388
|
+
};
|
|
367
389
|
const onKeyDown = (event) => {
|
|
368
390
|
var _a;
|
|
369
391
|
const composing = event.nativeEvent.isComposing || event.keyCode === 229;
|
|
@@ -385,7 +407,7 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
385
407
|
}
|
|
386
408
|
else if (event.key === 'Escape' && working && onStop) {
|
|
387
409
|
event.preventDefault();
|
|
388
|
-
|
|
410
|
+
stop();
|
|
389
411
|
}
|
|
390
412
|
};
|
|
391
413
|
const onPaste = (event) => {
|
|
@@ -409,20 +431,25 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
409
431
|
}
|
|
410
432
|
};
|
|
411
433
|
const own = [];
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
434
|
+
const pickImages = () => {
|
|
435
|
+
var _a, _b, _c;
|
|
436
|
+
// The Ta app on iOS opens its library at once (and asks for the photos, for the screenshots, once picked).
|
|
437
|
+
if (PhotoPicker.available()) {
|
|
438
|
+
void PhotoPicker.pick(MAX_IMAGES - attachments.length).then(files => files.length && addFiles(files));
|
|
439
|
+
return;
|
|
440
|
+
}
|
|
441
|
+
if (recentShots) {
|
|
442
|
+
(_b = (_a = RecentShots.source()) === null || _a === void 0 ? void 0 : _a.ask) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
443
|
+
}
|
|
444
|
+
(_c = picker.current) === null || _c === void 0 ? void 0 : _c.click();
|
|
445
|
+
};
|
|
446
|
+
if (takesImages && handheld && touch) {
|
|
447
|
+
// On a phone the album and the camera are two tiles, as WeChat's: each opens at once, without the menu of
|
|
448
|
+
// the system's file field (Photo Library, Take Photo, Choose File) in between.
|
|
449
|
+
own.push({ key: 'album', label: t('ta.composer.album'), icon: React.createElement(Icon, { icon: Images, size: 16 }), run: pickImages }, { key: 'camera', label: t('ta.composer.camera'), icon: React.createElement(Icon, { icon: Camera, size: 16 }), run: () => { var _a; return (_a = camera.current) === null || _a === void 0 ? void 0 : _a.click(); } });
|
|
450
|
+
}
|
|
451
|
+
else if (takesImages) {
|
|
452
|
+
own.push({ key: 'image', label: t('ta.composer.addImage'), icon: React.createElement(Icon, { icon: ImagePlus, size: 16 }), run: pickImages });
|
|
426
453
|
}
|
|
427
454
|
if (mentionLabel) {
|
|
428
455
|
own.push({ key: 'mention', label: mentionLabel, icon: React.createElement(Icon, { icon: AtSign, size: 16 }), run: () => edit(...ComposerUtil.insert(text, caret, '@')) });
|
|
@@ -461,12 +488,8 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
461
488
|
React.createElement(IconButton, { icon: Plus, label: t('ta.composer.more'), className: `ta-attach ta-plus-button ${menu ? 'ta-on' : ''}`, onClick: toggleMenu }),
|
|
462
489
|
menu && !handheld && React.createElement(PlusMenu, { sections: sections, onClose: closeMenu }),
|
|
463
490
|
takesImages && recentShots && (React.createElement(RecentShotOffer, { box: box, activity: `${text}|${attachments.length}|${menu}|${talkMode}`, onPick: file => addFiles([file]) })))),
|
|
464
|
-
takesImages &&
|
|
465
|
-
|
|
466
|
-
addFiles(event.target.files);
|
|
467
|
-
}
|
|
468
|
-
event.target.value = '';
|
|
469
|
-
} })),
|
|
491
|
+
takesImages && React.createElement("input", { ref: picker, type: "file", accept: IMAGE_TYPES.join(','), multiple: true, hidden: true, onChange: onPicked }),
|
|
492
|
+
takesImages && handheld && touch && React.createElement("input", { ref: camera, type: "file", accept: "image/*", capture: "environment", hidden: true, onChange: onPicked }),
|
|
470
493
|
talkMode && React.createElement(TalkBar, { talk: talk }),
|
|
471
494
|
React.createElement("textarea", { ref: input, hidden: talkMode, rows: 1, value: text, autoFocus: autoFocus, enterKeyHint: "send", "aria-label": t('ta.composer.label'), "aria-controls": items.length ? menuId : undefined, "aria-activedescendant": items.length ? `${menuId}-${selected}` : undefined, placeholder: listening ? t('ta.composer.listening') : placeholder, onChange: event => {
|
|
472
495
|
setText(event.target.value);
|
|
@@ -481,16 +504,15 @@ export const ComposerBox = React.forwardRef(function ComposerBox(props, ref) {
|
|
|
481
504
|
}, onBlur: () => setFocused(false) }),
|
|
482
505
|
after,
|
|
483
506
|
microphone,
|
|
484
|
-
React.createElement("button", { type: "button", className: `ta-send ${action === 'stop' ? 'ta-send-stop' : ''}`, disabled: action === 'send' && (!sendable || reading), title: action === 'stop'
|
|
485
|
-
? t('ta.composer.stopTitle')
|
|
507
|
+
React.createElement("button", { type: "button", className: `ta-send ${action === 'stop' ? 'ta-send-stop' : ''} ${action === 'stop' && stopping ? 'ta-send-stopping' : ''}`, disabled: action === 'send' && (!sendable || reading), title: action === 'stop'
|
|
508
|
+
? t(stopping ? 'ta.composer.stopping' : 'ta.composer.stopTitle')
|
|
486
509
|
: reading
|
|
487
510
|
? t('ta.composer.imageLoading')
|
|
488
511
|
: working
|
|
489
512
|
? t('ta.composer.steerTitle')
|
|
490
|
-
: t('ta.send'), "aria-label": action === 'stop' ? t('ta.stop') : t('ta.send'),
|
|
513
|
+
: t('ta.send'), "aria-label": action === 'stop' ? t(stopping ? 'ta.composer.stopping' : 'ta.stop') : t('ta.send'), "aria-busy": action === 'stop' && stopping,
|
|
491
514
|
// Pressed with the keyboard open, the box keeps the focus and the keyboard stays, as in WeChat.
|
|
492
|
-
onPointerDown: event => document.activeElement === input.current && event.preventDefault(), onClick: () => (action === 'stop' ?
|
|
493
|
-
React.createElement(Icon, { icon: action === 'stop' ? Square : ArrowUp, size: action === 'stop' ? 14 : 18 })))),
|
|
515
|
+
onPointerDown: event => document.activeElement === input.current && event.preventDefault(), onClick: () => (action === 'stop' ? stop() : send(false)) }, action === 'stop' && stopping ? (React.createElement("span", { className: "ta-spinner" })) : (React.createElement(Icon, { icon: action === 'stop' ? Square : ArrowUp, size: action === 'stop' ? 14 : 18 }))))),
|
|
494
516
|
handheld && (menu || closing) && sections.length > 0 && (React.createElement(PlusMenu, { ref: panel, sections: sections, docked: true, closing: !menu, onClosed: () => setClosing(false), onClose: closeMenu }))));
|
|
495
517
|
});
|
|
496
518
|
//# sourceMappingURL=composer-box.js.map
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { SessionStore } from '@celljs/ta-client';
|
|
2
2
|
import type { TaServer, TaSlashCommand, TaWorkspaceServer } from '@celljs/ta-protocol';
|
|
3
3
|
import * as React from 'react';
|
|
4
|
-
import { type ComposerImage } from '../util/composer.js';
|
|
4
|
+
import { type ComposerImage, type ComposerQueued } from '../util/composer.js';
|
|
5
5
|
import { type ComposerAction, type ComposerBoxHandle } from './composer-box.js';
|
|
6
6
|
import type { TalkPlace } from './held-talk.js';
|
|
7
|
+
import { type StopTiming } from './stop-times.js';
|
|
7
8
|
export interface ComposerProps {
|
|
8
9
|
/** The session it sends to; none for a new conversation, which sends with `onSubmit`. */
|
|
9
10
|
store?: SessionStore;
|
|
@@ -38,6 +39,8 @@ export interface ComposerProps {
|
|
|
38
39
|
onSending?(): void;
|
|
39
40
|
/** Stops the work with no session yet (a new conversation still opening). */
|
|
40
41
|
onStop?(): void;
|
|
42
|
+
/** A stop of the session's run pressed here ended (or failed): how long it took (useStopTimes). */
|
|
43
|
+
onStopTimed?(timing: StopTiming): void;
|
|
41
44
|
onError(error: unknown): void;
|
|
42
45
|
}
|
|
43
46
|
/**
|
|
@@ -45,3 +48,9 @@ export interface ComposerProps {
|
|
|
45
48
|
* and Alt+Enter queues a follow-up; Escape stops it.
|
|
46
49
|
*/
|
|
47
50
|
export declare const Composer: React.ForwardRefExoticComponent<ComposerProps & React.RefAttributes<ComposerBoxHandle>>;
|
|
51
|
+
/** What waits to be sent, tucked on top of the box: as the conversation will show it, the package that sent it apart. */
|
|
52
|
+
export declare function QueuedMessages({ waiting, onTakeBack, onRemove, }: {
|
|
53
|
+
waiting: ComposerQueued[];
|
|
54
|
+
onTakeBack(): void;
|
|
55
|
+
onRemove(entry: ComposerQueued, back: boolean): void;
|
|
56
|
+
}): React.JSX.Element;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Clock3, CornerDownRight,
|
|
1
|
+
import { Clock3, CornerDownRight, PenLine, X } from 'lucide-react';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { AssistantTaskUtil } from '../assistant/assistant-task-util.js';
|
|
4
4
|
import { useDevice } from '../device/device.js';
|
|
@@ -6,11 +6,16 @@ import { useLanguage, useT } from '../i18n/use-t.js';
|
|
|
6
6
|
import { ComposerUtil } from '../util/composer.js';
|
|
7
7
|
import { ComposerBox } from './composer-box.js';
|
|
8
8
|
import { Icon } from './icon.js';
|
|
9
|
+
import { MessageOrigin, userWords } from './message-list.js';
|
|
10
|
+
import { StopClock } from './stop-times.js';
|
|
9
11
|
const FILE_LIMIT = 20;
|
|
10
12
|
const FILE_DELAY_MS = 120;
|
|
11
13
|
const EMPTY_QUEUE = { steering: [], followUp: [] };
|
|
12
14
|
/** What the user said of what waited: not the notes of the tasks that ended, which they did not write. */
|
|
13
|
-
const said = (texts) => texts.filter(text => !AssistantTaskUtil.noteOf(text));
|
|
15
|
+
const said = (texts) => texts.filter(text => !AssistantTaskUtil.noteOf(text)).map(text => words(text).copied);
|
|
16
|
+
/** A waiting message as the user sees it in the conversation: without its context, the package it came from apart. */
|
|
17
|
+
const blocksOf = (text) => [{ type: 'text', text }];
|
|
18
|
+
const words = (text) => userWords(blocksOf(text));
|
|
14
19
|
/** The files for an `@` being typed; a server without file search answers with an error, and the menu says so. */
|
|
15
20
|
function useFiles(workspace, cwd, query) {
|
|
16
21
|
const t = useT();
|
|
@@ -57,7 +62,7 @@ function useQueue(store, working) {
|
|
|
57
62
|
* and Alt+Enter queues a follow-up; Escape stops it.
|
|
58
63
|
*/
|
|
59
64
|
export const Composer = React.forwardRef(function Composer(props, ref) {
|
|
60
|
-
const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onError, } = props;
|
|
65
|
+
const { store, onSubmit, head, after, voiceSends, recentShots, talkPlace, onTalkSent, onListening, server, workspace, working, commands, cwd, actions, placeholder, above, onSending, onStop, onStopTimed, onError, } = props;
|
|
61
66
|
// A finger: the keyboard opens on focus, over the conversation, and there are no keys to name.
|
|
62
67
|
const touch = useDevice(device => device.touch);
|
|
63
68
|
const t = useT();
|
|
@@ -68,7 +73,32 @@ export const Composer = React.forwardRef(function Composer(props, ref) {
|
|
|
68
73
|
const files = useFiles(workspace, cwd, query);
|
|
69
74
|
const box = React.useRef(null);
|
|
70
75
|
React.useImperativeHandle(ref, () => ({ text: () => { var _a; var _b; return (_b = (_a = box.current) === null || _a === void 0 ? void 0 : _a.text()) !== null && _b !== void 0 ? _b : ''; }, setText: text => { var _a; return (_a = box.current) === null || _a === void 0 ? void 0 : _a.setText(text); } }));
|
|
71
|
-
|
|
76
|
+
// The stop pressed, timed until the computer answered it and the run was seen ended.
|
|
77
|
+
const stopping = React.useRef(undefined);
|
|
78
|
+
const timed = (clock, timing) => {
|
|
79
|
+
if (timing) {
|
|
80
|
+
stopping.current = stopping.current === clock ? undefined : stopping.current;
|
|
81
|
+
onStopTimed === null || onStopTimed === void 0 ? void 0 : onStopTimed(timing);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
React.useEffect(() => {
|
|
85
|
+
const clock = stopping.current;
|
|
86
|
+
if (!working && clock) {
|
|
87
|
+
timed(clock, clock.ended(performance.now()));
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const stop = () => {
|
|
91
|
+
if (!store) {
|
|
92
|
+
return onStop === null || onStop === void 0 ? void 0 : onStop();
|
|
93
|
+
}
|
|
94
|
+
const clock = new StopClock(performance.now(), Date.now());
|
|
95
|
+
stopping.current = clock;
|
|
96
|
+
return server.abort(store.sessionId).then(() => timed(clock, clock.answered(performance.now())), error => {
|
|
97
|
+
timed(clock, clock.answered(performance.now(), true));
|
|
98
|
+
onError(error);
|
|
99
|
+
throw error;
|
|
100
|
+
});
|
|
101
|
+
};
|
|
72
102
|
const send = (message, images, followUp) => {
|
|
73
103
|
var _a;
|
|
74
104
|
onSending === null || onSending === void 0 ? void 0 : onSending();
|
|
@@ -102,29 +132,38 @@ export const Composer = React.forwardRef(function Composer(props, ref) {
|
|
|
102
132
|
server.removeQueued(store.sessionId, entry.kind, entry.index).then(removed => {
|
|
103
133
|
var _a;
|
|
104
134
|
if (removed && back) {
|
|
105
|
-
(_a = box.current) === null || _a === void 0 ? void 0 : _a.setText(ComposerUtil.restore({ steering: [entry.text], followUp: [] }, box.current.text()));
|
|
135
|
+
(_a = box.current) === null || _a === void 0 ? void 0 : _a.setText(ComposerUtil.restore({ steering: said([entry.text]), followUp: [] }, box.current.text()));
|
|
106
136
|
}
|
|
107
137
|
}, onError);
|
|
108
138
|
};
|
|
109
139
|
const waiting = ComposerUtil.queued(queue);
|
|
110
140
|
return (React.createElement(ComposerBox, { ref: box, placeholder: placeholder !== null && placeholder !== void 0 ? placeholder : t(ComposerUtil.placeholderKey(working, touch)), working: working, onStop: stop, onSend: send, commands: listed, onMentionQuery: setQuery, mentions: files, mentionLabel: t('ta.composer.mentionFile'), images: true, recentShots: recentShots, actions: actions, head: head, after: after, voiceSends: voiceSends, talkPlace: talkPlace, onTalkSent: onTalkSent, onListening: onListening, autoFocus: !touch, cwd: cwd, onError: onError, above: React.createElement(React.Fragment, null,
|
|
111
141
|
above,
|
|
112
|
-
waiting.length > 0 &&
|
|
113
|
-
React.createElement("div", { className: "ta-queue-head" },
|
|
114
|
-
React.createElement("span", null, t('ta.composer.queue.count', { count: waiting.length })),
|
|
115
|
-
React.createElement("button", { type: "button", className: "ta-queue-all", onClick: takeBack, title: t('ta.composer.queue.takeBackTitle') }, t('ta.composer.queue.takeBackAll'))),
|
|
116
|
-
waiting.map(entry => {
|
|
117
|
-
const note = AssistantTaskUtil.noteOf(entry.text);
|
|
118
|
-
const text = note ? t('ta.task.ended', { title: note.title, status: t(`ta.task.${note.status}`) }) : entry.text;
|
|
119
|
-
return (React.createElement("div", { key: `${entry.kind}-${entry.index}-${entry.text}`, className: "ta-queue-row" },
|
|
120
|
-
React.createElement("span", { className: "ta-queue-kind", title: t(entry.kind === 'steering' ? 'ta.composer.queue.steering' : 'ta.composer.queue.followUp') },
|
|
121
|
-
React.createElement(Icon, { icon: entry.kind === 'steering' ? CornerDownRight : Clock3, size: 13 })),
|
|
122
|
-
React.createElement("span", { className: "ta-ellipsis ta-queue-text", title: text }, text),
|
|
123
|
-
React.createElement("span", { className: "ta-queue-actions" },
|
|
124
|
-
!note && (React.createElement("button", { type: "button", className: "ta-icon-button", onClick: () => remove(entry, true), title: t('ta.composer.queue.editTitle'), "aria-label": t('ta.composer.queue.editTitle') },
|
|
125
|
-
React.createElement(Icon, { icon: Undo2, size: 13 }))),
|
|
126
|
-
React.createElement("button", { type: "button", className: "ta-icon-button", onClick: () => remove(entry, false), title: t('ta.composer.queue.remove'), "aria-label": t('ta.composer.queue.remove') },
|
|
127
|
-
React.createElement(Icon, { icon: X, size: 13 })))));
|
|
128
|
-
})))) }));
|
|
142
|
+
waiting.length > 0 && React.createElement(QueuedMessages, { waiting: waiting, onTakeBack: takeBack, onRemove: remove })) }));
|
|
129
143
|
});
|
|
144
|
+
/** What waits to be sent, tucked on top of the box: as the conversation will show it, the package that sent it apart. */
|
|
145
|
+
export function QueuedMessages({ waiting, onTakeBack, onRemove, }) {
|
|
146
|
+
const t = useT();
|
|
147
|
+
return (React.createElement("div", { className: "ta-queue", "aria-live": "polite" },
|
|
148
|
+
waiting.length > 1 && (React.createElement("div", { className: "ta-queue-head" },
|
|
149
|
+
React.createElement("span", null, t('ta.composer.queue.count', { count: waiting.length })),
|
|
150
|
+
React.createElement("button", { type: "button", className: "ta-queue-all", onClick: onTakeBack, title: t('ta.composer.queue.takeBackTitle') }, t('ta.composer.queue.takeBackAll')))),
|
|
151
|
+
waiting.map(entry => {
|
|
152
|
+
const note = AssistantTaskUtil.noteOf(entry.text);
|
|
153
|
+
const shown = words(entry.text);
|
|
154
|
+
const text = note ? t('ta.task.ended', { title: note.title, status: t(`ta.task.${note.status}`) }) : shown.text || shown.copied;
|
|
155
|
+
const kind = t(entry.kind === 'steering' ? 'ta.composer.queue.steering' : 'ta.composer.queue.followUp');
|
|
156
|
+
return (React.createElement("div", { key: `${entry.kind}-${entry.index}-${entry.text}`, className: "ta-queue-row" },
|
|
157
|
+
React.createElement("span", { className: "ta-queue-kind", title: kind },
|
|
158
|
+
React.createElement(Icon, { icon: entry.kind === 'steering' ? CornerDownRight : Clock3, size: 13 }),
|
|
159
|
+
React.createElement("span", null, kind)),
|
|
160
|
+
!note && React.createElement(MessageOrigin, { blocks: blocksOf(entry.text) }),
|
|
161
|
+
React.createElement("span", { className: "ta-ellipsis ta-queue-text", title: text }, text),
|
|
162
|
+
React.createElement("span", { className: "ta-queue-actions" },
|
|
163
|
+
!note && (React.createElement("button", { type: "button", className: "ta-icon-button", onClick: () => onRemove(entry, true), title: t('ta.composer.queue.editTitle'), "aria-label": t('ta.composer.queue.editTitle') },
|
|
164
|
+
React.createElement(Icon, { icon: PenLine, size: 13 }))),
|
|
165
|
+
React.createElement("button", { type: "button", className: "ta-icon-button", onClick: () => onRemove(entry, false), title: t('ta.composer.queue.remove'), "aria-label": t('ta.composer.queue.remove') },
|
|
166
|
+
React.createElement(Icon, { icon: X, size: 13 })))));
|
|
167
|
+
})));
|
|
168
|
+
}
|
|
130
169
|
//# sourceMappingURL=composer.js.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { CircleAlert, CircleCheck, RotateCw, WifiOff } from 'lucide-react';
|
|
1
|
+
import { CircleAlert, CircleArrowUp, CircleCheck, RotateCw, WifiOff } from 'lucide-react';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import { useDevice } from '../device/device.js';
|
|
4
4
|
import { useNotices, useWorkbench } from '../hooks.js';
|
|
@@ -79,7 +79,7 @@ function usePressed() {
|
|
|
79
79
|
function useConnectionNotice() {
|
|
80
80
|
const t = useT();
|
|
81
81
|
const [{ offlineShown, error, retryAt, status }, workbench] = useWorkbench();
|
|
82
|
-
const [{ notDoneAt }] = useNotices();
|
|
82
|
+
const [{ notDoneAt, outdated }] = useNotices();
|
|
83
83
|
// Something the user did did not happen: no notice over the page, this row says it. Offline, it shows at once.
|
|
84
84
|
const notDone = useRecent(notDoneAt, NOT_DONE_MS);
|
|
85
85
|
const online = status === 'online';
|
|
@@ -91,6 +91,8 @@ function useConnectionNotice() {
|
|
|
91
91
|
const brief = error === 'away' ? t('ta.connection.awayBrief') : error === 'unreachable' ? t('ta.connection.unreachableBrief') : t('ta.connection.lost');
|
|
92
92
|
return {
|
|
93
93
|
phase,
|
|
94
|
+
// Below what the connection says: an outdated page reloads once it can.
|
|
95
|
+
outdated: !!outdated && phase === 'none',
|
|
94
96
|
back: phase === 'back' || phase === 'leaving',
|
|
95
97
|
notDone: phase === 'notDone',
|
|
96
98
|
text,
|
|
@@ -130,18 +132,30 @@ function useWidth(body, content) {
|
|
|
130
132
|
*/
|
|
131
133
|
export function ConnectionBar() {
|
|
132
134
|
const t = useT();
|
|
133
|
-
const { phase, back, notDone, text, seconds, trying, retry } = useConnectionNotice();
|
|
135
|
+
const { phase, outdated, back, notDone, text, seconds, trying, retry } = useConnectionNotice();
|
|
134
136
|
const body = React.useRef(null);
|
|
135
|
-
const shown = phase === 'none' ? undefined : notDone ? 'notDone' : back ? 'back' : 'offline';
|
|
137
|
+
const shown = outdated ? 'outdated' : phase === 'none' ? undefined : notDone ? 'notDone' : back ? 'back' : 'offline';
|
|
136
138
|
const width = useWidth(body, shown);
|
|
137
|
-
if (
|
|
139
|
+
if (shown === undefined) {
|
|
138
140
|
return null;
|
|
139
141
|
}
|
|
140
|
-
const classes = [
|
|
142
|
+
const classes = [
|
|
143
|
+
'ta-connection',
|
|
144
|
+
back && 'ta-connection-back',
|
|
145
|
+
notDone && 'ta-connection-notdone',
|
|
146
|
+
outdated && 'ta-connection-outdated',
|
|
147
|
+
phase === 'leaving' && 'ta-connection-leaving',
|
|
148
|
+
];
|
|
141
149
|
// The border of the bar is around the body.
|
|
142
150
|
const style = width === undefined ? undefined : { width: width + 2 };
|
|
143
151
|
return (React.createElement("div", { className: classes.filter(Boolean).join(' '), role: "status", style: style },
|
|
144
|
-
React.createElement("div", { className: "ta-connection-body", ref: body, key: shown },
|
|
152
|
+
React.createElement("div", { className: "ta-connection-body", ref: body, key: shown }, outdated ? (React.createElement(React.Fragment, null,
|
|
153
|
+
React.createElement(Icon, { icon: CircleArrowUp, size: 15, className: "ta-level-icon" }),
|
|
154
|
+
React.createElement("span", { className: "ta-connection-text" }, t('ta.connection.outdated')),
|
|
155
|
+
React.createElement("button", { type: "button", className: "ta-connection-retry", onClick: () => location.reload() },
|
|
156
|
+
React.createElement(Icon, { icon: RotateCw, size: 13 }),
|
|
157
|
+
" ",
|
|
158
|
+
t('ta.connection.reload')))) : notDone ? (React.createElement(React.Fragment, null,
|
|
145
159
|
React.createElement(Icon, { icon: CircleAlert, size: 15, className: "ta-level-icon" }),
|
|
146
160
|
React.createElement("span", { className: "ta-connection-text" }, t('ta.connection.notDone')))) : back ? (React.createElement(React.Fragment, null,
|
|
147
161
|
React.createElement(Icon, { icon: CircleCheck, size: 15, className: "ta-level-icon" }),
|
|
@@ -162,20 +176,25 @@ export function ConnectionBar() {
|
|
|
162
176
|
export function ConnectionBanner() {
|
|
163
177
|
const t = useT();
|
|
164
178
|
const handheld = useDevice(device => device.handheld);
|
|
165
|
-
const { phase, back, notDone, text, brief, trying, retry } = useConnectionNotice();
|
|
179
|
+
const { phase, outdated, back, notDone, text, brief, trying, retry } = useConnectionNotice();
|
|
166
180
|
if (!handheld) {
|
|
167
181
|
return null;
|
|
168
182
|
}
|
|
169
|
-
const open = phase === 'offline' || phase === 'back' || notDone;
|
|
183
|
+
const open = phase === 'offline' || phase === 'back' || notDone || outdated;
|
|
170
184
|
const quiet = back || notDone;
|
|
171
|
-
const classes = ['ta-connection-banner', open && 'ta-open', back && 'ta-connection-back'];
|
|
185
|
+
const classes = ['ta-connection-banner', open && 'ta-open', back && 'ta-connection-back', outdated && 'ta-connection-outdated'];
|
|
172
186
|
// Always there, empty while closed, so that it opens with a transition.
|
|
173
187
|
return (React.createElement("div", { className: classes.filter(Boolean).join(' '), role: "status", "aria-hidden": !open },
|
|
174
|
-
React.createElement("div", { className: "ta-connection-banner-inner" },
|
|
188
|
+
React.createElement("div", { className: "ta-connection-banner-inner" }, outdated ? (React.createElement("button", { type: "button", className: "ta-connection-banner-row", onClick: () => location.reload() },
|
|
189
|
+
React.createElement(Icon, { icon: CircleArrowUp, size: 16, className: "ta-level-icon" }),
|
|
190
|
+
React.createElement("span", { className: "ta-connection-banner-text" }, t('ta.connection.outdated')),
|
|
191
|
+
React.createElement("span", { className: "ta-connection-banner-action" },
|
|
192
|
+
React.createElement(Icon, { icon: RotateCw, size: 14 }),
|
|
193
|
+
t('ta.connection.reload')))) : (phase !== 'none' && (React.createElement("button", { type: "button", className: "ta-connection-banner-row", disabled: quiet || trying, tabIndex: open ? undefined : -1, title: quiet ? undefined : text, onClick: retry },
|
|
175
194
|
React.createElement(Icon, { icon: notDone ? CircleAlert : back ? CircleCheck : WifiOff, size: 16, className: "ta-level-icon" }),
|
|
176
195
|
React.createElement("span", { className: "ta-connection-banner-text" }, notDone ? t('ta.connection.notDone') : back ? t('ta.connection.back') : brief),
|
|
177
196
|
!quiet && (React.createElement("span", { className: "ta-connection-banner-action" },
|
|
178
197
|
trying ? React.createElement("span", { className: "ta-spinner" }) : React.createElement(Icon, { icon: RotateCw, size: 14 }),
|
|
179
|
-
trying ? t('ta.connection.retrying') : t('ta.connection.retry'))))))));
|
|
198
|
+
trying ? t('ta.connection.retrying') : t('ta.connection.retry')))))))));
|
|
180
199
|
}
|
|
181
200
|
//# sourceMappingURL=connection-bar.js.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export interface ConversationScrollOptions {
|
|
3
|
+
/** Where a message sent goes: to the top of the view with its answer under it (a conversation), or to the bottom (a group chat). */
|
|
4
|
+
sentTo?: 'top' | 'bottom';
|
|
5
|
+
/** Another key (another chat in the same view) goes to the bottom. */
|
|
6
|
+
key?: string;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The scrolling of a conversation (ConversationScroller), whose thread is the first child of the element of the
|
|
10
|
+
* returned ref. Opened, and when messages of the user go (a rewind), the view goes to the bottom.
|
|
11
|
+
*
|
|
12
|
+
* `asked`: how many messages of the user there are; the thread marks them with ASK_CLASS.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useConversationScroll(asked: number, options?: ConversationScrollOptions): React.RefObject<HTMLDivElement | null>;
|
|
15
|
+
/** Whether the conversation of `ref` is scrolled up from its latest, and a way back to it. */
|
|
16
|
+
export declare function useAwayFromBottom(ref: React.RefObject<HTMLDivElement | null>): [boolean, () => void];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ASK_CLASS, ConversationScroller, calm } from './conversation-scroll.js';
|
|
3
|
+
/**
|
|
4
|
+
* The scrolling of a conversation (ConversationScroller), whose thread is the first child of the element of the
|
|
5
|
+
* returned ref. Opened, and when messages of the user go (a rewind), the view goes to the bottom.
|
|
6
|
+
*
|
|
7
|
+
* `asked`: how many messages of the user there are; the thread marks them with ASK_CLASS.
|
|
8
|
+
*/
|
|
9
|
+
export function useConversationScroll(asked, options = {}) {
|
|
10
|
+
const { sentTo = 'top', key } = options;
|
|
11
|
+
const ref = React.useRef(null);
|
|
12
|
+
const attached = React.useRef(undefined);
|
|
13
|
+
const before = React.useRef(undefined);
|
|
14
|
+
// After each render, the view may only now be there (a page that shows it once its data came).
|
|
15
|
+
React.useLayoutEffect(() => {
|
|
16
|
+
var _a, _b;
|
|
17
|
+
const view = ref.current;
|
|
18
|
+
const thread = view === null || view === void 0 ? void 0 : view.firstElementChild;
|
|
19
|
+
if (((_a = attached.current) === null || _a === void 0 ? void 0 : _a.view) === view) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
(_b = attached.current) === null || _b === void 0 ? void 0 : _b.detach();
|
|
23
|
+
attached.current = undefined;
|
|
24
|
+
if (view && thread instanceof HTMLElement) {
|
|
25
|
+
const scroller = new ConversationScroller(view, thread);
|
|
26
|
+
attached.current = { view, scroller, detach: scroller.attach(view, thread) };
|
|
27
|
+
}
|
|
28
|
+
});
|
|
29
|
+
React.useLayoutEffect(() => () => {
|
|
30
|
+
var _a;
|
|
31
|
+
(_a = attached.current) === null || _a === void 0 ? void 0 : _a.detach();
|
|
32
|
+
attached.current = undefined;
|
|
33
|
+
}, []);
|
|
34
|
+
React.useLayoutEffect(() => {
|
|
35
|
+
var _a, _b;
|
|
36
|
+
const previous = before.current;
|
|
37
|
+
before.current = { asked, key };
|
|
38
|
+
const current = (_a = attached.current) === null || _a === void 0 ? void 0 : _a.scroller;
|
|
39
|
+
const thread = (_b = ref.current) === null || _b === void 0 ? void 0 : _b.firstElementChild;
|
|
40
|
+
if (!current || !thread) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
// One more: sent now. More at once is the conversation loaded again, which opens at its bottom.
|
|
44
|
+
const sent = previous !== undefined && previous.key === key && asked === previous.asked + 1;
|
|
45
|
+
const asks = sent && sentTo === 'top' ? thread.getElementsByClassName(ASK_CLASS) : undefined;
|
|
46
|
+
const message = asks === null || asks === void 0 ? void 0 : asks[asks.length - 1];
|
|
47
|
+
if (message) {
|
|
48
|
+
current.send(message);
|
|
49
|
+
}
|
|
50
|
+
else {
|
|
51
|
+
current.reset();
|
|
52
|
+
}
|
|
53
|
+
}, [asked, key, sentTo]);
|
|
54
|
+
return ref;
|
|
55
|
+
}
|
|
56
|
+
/** Away from the bottom by more than half of the view: the button back to the latest shows. */
|
|
57
|
+
const AWAY_SHARE = 0.5;
|
|
58
|
+
/** Lower than this (a phone held sideways, its keyboard open) the view has no room for the button. */
|
|
59
|
+
const AWAY_MIN_PX = 240;
|
|
60
|
+
/** Whether the conversation of `ref` is scrolled up from its latest, and a way back to it. */
|
|
61
|
+
export function useAwayFromBottom(ref) {
|
|
62
|
+
const [away, setAway] = React.useState(false);
|
|
63
|
+
React.useEffect(() => {
|
|
64
|
+
const element = ref.current;
|
|
65
|
+
if (!element) {
|
|
66
|
+
return;
|
|
67
|
+
}
|
|
68
|
+
let frame = 0;
|
|
69
|
+
const measure = () => {
|
|
70
|
+
cancelAnimationFrame(frame);
|
|
71
|
+
frame = requestAnimationFrame(() => {
|
|
72
|
+
const { scrollHeight, scrollTop, clientHeight } = element;
|
|
73
|
+
setAway(clientHeight >= AWAY_MIN_PX && scrollHeight - scrollTop - clientHeight > clientHeight * AWAY_SHARE);
|
|
74
|
+
});
|
|
75
|
+
};
|
|
76
|
+
element.addEventListener('scroll', measure, { passive: true });
|
|
77
|
+
// The keyboard and a turn of the phone change the height of the view, not where it is.
|
|
78
|
+
const observer = typeof ResizeObserver !== 'undefined' ? new ResizeObserver(measure) : undefined;
|
|
79
|
+
observer === null || observer === void 0 ? void 0 : observer.observe(element);
|
|
80
|
+
return () => {
|
|
81
|
+
cancelAnimationFrame(frame);
|
|
82
|
+
observer === null || observer === void 0 ? void 0 : observer.disconnect();
|
|
83
|
+
element.removeEventListener('scroll', measure);
|
|
84
|
+
};
|
|
85
|
+
}, [ref]);
|
|
86
|
+
const back = React.useCallback(() => {
|
|
87
|
+
const element = ref.current;
|
|
88
|
+
const scroller = element ? ConversationScroller.of(element) : undefined;
|
|
89
|
+
if (scroller) {
|
|
90
|
+
scroller.toBottom();
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
element === null || element === void 0 ? void 0 : element.scrollTo({ top: element.scrollHeight, behavior: calm() ? 'auto' : 'smooth' });
|
|
94
|
+
}
|
|
95
|
+
}, [ref]);
|
|
96
|
+
return [away, back];
|
|
97
|
+
}
|
|
98
|
+
//# sourceMappingURL=conversation-scroll-hooks.js.map
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { FrameScheduler } from '../util/frame.js';
|
|
2
|
+
/** A row of the thread. */
|
|
3
|
+
export interface ScrollRow {
|
|
4
|
+
/** From the top of the thread. */
|
|
5
|
+
readonly offsetTop: number;
|
|
6
|
+
readonly offsetHeight: number;
|
|
7
|
+
readonly isConnected: boolean;
|
|
8
|
+
/** `scrollSkip`: SCROLL_SKIP. */
|
|
9
|
+
readonly dataset?: {
|
|
10
|
+
readonly scrollSkip?: string;
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
export declare namespace ScrollUtil {
|
|
14
|
+
/** The first of `rows` (in order, as laid out) in a view scrolled to `top`; past what says earlier rows load. */
|
|
15
|
+
function firstRow(rows: ArrayLike<ScrollRow>, top: number): ScrollRow | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* The row read in a view scrolled to `top`, `height` high: the first that starts in it, which keeps its place as
|
|
18
|
+
* the row above it (only partly in sight) grows or shrinks; else the one over all of the view (firstRow).
|
|
19
|
+
*/
|
|
20
|
+
function readRow(rows: ArrayLike<ScrollRow>, top: number, height: number): ScrollRow | undefined;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* A view gliding where it goes rather than jumping there: each frame it goes the share of the way left it would
|
|
24
|
+
* in that time by an exponential ease of GLIDE_MS, however often the end of the way moves (more coming in).
|
|
25
|
+
*/
|
|
26
|
+
export declare class ScrollGlide {
|
|
27
|
+
private readonly frames;
|
|
28
|
+
private readonly now;
|
|
29
|
+
static readonly GLIDE_MS = 70;
|
|
30
|
+
private frame;
|
|
31
|
+
constructor(frames: FrameScheduler, now: () => number);
|
|
32
|
+
/** Gliding: `step` moves the view by the share of the way left it is given, each frame, until it answers false. */
|
|
33
|
+
start(step: (share: number) => boolean): void;
|
|
34
|
+
stop(): void;
|
|
35
|
+
}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
export var ScrollUtil;
|
|
2
|
+
(function (ScrollUtil) {
|
|
3
|
+
/** The first of `rows` (in order, as laid out) in a view scrolled to `top`; past what says earlier rows load. */
|
|
4
|
+
function firstRow(rows, top) {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
let low = 0;
|
|
7
|
+
let high = rows.length - 1;
|
|
8
|
+
while (low < high) {
|
|
9
|
+
const middle = (low + high) >> 1;
|
|
10
|
+
const row = rows[middle];
|
|
11
|
+
if (row.offsetTop + row.offsetHeight > top) {
|
|
12
|
+
high = middle;
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
low = middle + 1;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
return ((_b = (_a = rows[low]) === null || _a === void 0 ? void 0 : _a.dataset) === null || _b === void 0 ? void 0 : _b.scrollSkip) !== undefined && low + 1 < rows.length ? rows[low + 1] : rows[low];
|
|
19
|
+
}
|
|
20
|
+
ScrollUtil.firstRow = firstRow;
|
|
21
|
+
/**
|
|
22
|
+
* The row read in a view scrolled to `top`, `height` high: the first that starts in it, which keeps its place as
|
|
23
|
+
* the row above it (only partly in sight) grows or shrinks; else the one over all of the view (firstRow).
|
|
24
|
+
*/
|
|
25
|
+
function readRow(rows, top, height) {
|
|
26
|
+
const first = firstRow(rows, top);
|
|
27
|
+
if (!first || first.offsetTop >= top) {
|
|
28
|
+
return first;
|
|
29
|
+
}
|
|
30
|
+
for (let index = 0; index < rows.length; index++) {
|
|
31
|
+
if (rows[index] === first) {
|
|
32
|
+
const next = rows[index + 1];
|
|
33
|
+
return next && next.offsetTop < top + height ? next : first;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return first;
|
|
37
|
+
}
|
|
38
|
+
ScrollUtil.readRow = readRow;
|
|
39
|
+
})(ScrollUtil || (ScrollUtil = {}));
|
|
40
|
+
/**
|
|
41
|
+
* A view gliding where it goes rather than jumping there: each frame it goes the share of the way left it would
|
|
42
|
+
* in that time by an exponential ease of GLIDE_MS, however often the end of the way moves (more coming in).
|
|
43
|
+
*/
|
|
44
|
+
export class ScrollGlide {
|
|
45
|
+
constructor(frames, now) {
|
|
46
|
+
this.frames = frames;
|
|
47
|
+
this.now = now;
|
|
48
|
+
}
|
|
49
|
+
/** Gliding: `step` moves the view by the share of the way left it is given, each frame, until it answers false. */
|
|
50
|
+
start(step) {
|
|
51
|
+
if (this.frame !== undefined) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
let last = this.now();
|
|
55
|
+
const next = () => {
|
|
56
|
+
this.frame = undefined;
|
|
57
|
+
const now = this.now();
|
|
58
|
+
const share = 1 - Math.exp(-Math.max(1, now - last) / ScrollGlide.GLIDE_MS);
|
|
59
|
+
last = now;
|
|
60
|
+
if (step(share)) {
|
|
61
|
+
this.frame = this.frames.request(next);
|
|
62
|
+
}
|
|
63
|
+
};
|
|
64
|
+
this.frame = this.frames.request(next);
|
|
65
|
+
}
|
|
66
|
+
stop() {
|
|
67
|
+
if (this.frame !== undefined) {
|
|
68
|
+
this.frames.cancel(this.frame);
|
|
69
|
+
this.frame = undefined;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
ScrollGlide.GLIDE_MS = 70;
|
|
74
|
+
//# sourceMappingURL=conversation-scroll-util.js.map
|