@celljs/ta-web 4.30.0 → 4.31.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/account/account-side.js +1 -1
- package/esm/browser/account/device-account.d.ts +8 -0
- package/esm/browser/account/device-account.js +26 -0
- package/esm/browser/components/account-menu.d.ts +1 -1
- package/esm/browser/components/account-menu.js +8 -4
- package/esm/browser/components/account-view.d.ts +7 -0
- package/esm/browser/components/account-view.js +90 -10
- package/esm/browser/components/chat-tag.d.ts +13 -5
- package/esm/browser/components/chat-tag.js +23 -6
- package/esm/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/esm/browser/components/composer-box.js +6 -2
- package/esm/browser/components/host-view.d.ts +1 -1
- package/esm/browser/components/host-view.js +3 -3
- package/esm/browser/components/me-rows.d.ts +2 -0
- package/esm/browser/components/me-rows.js +1 -1
- package/esm/browser/components/scan-screen.js +10 -0
- package/esm/browser/components/session-view.js +1 -1
- package/esm/browser/components/tool-view.js +10 -4
- package/esm/browser/components/voice-button.d.ts +7 -0
- package/esm/browser/components/voice-button.js +25 -2
- package/esm/browser/components/voice-talk.js +1 -1
- package/esm/browser/components/workbench-view.js +2 -2
- package/esm/browser/device/back-stack.d.ts +7 -0
- package/esm/browser/device/back-stack.js +13 -1
- package/esm/browser/device/code-scan.d.ts +5 -2
- package/esm/browser/device/code-scan.js +22 -2
- package/esm/browser/device/mini-program.d.ts +69 -0
- package/esm/browser/device/mini-program.js +251 -0
- package/esm/browser/device/sheet-swipe.js +4 -1
- package/esm/browser/device/swipe-util.d.ts +2 -0
- package/esm/browser/device/swipe-util.js +5 -0
- package/esm/browser/extension/extension-view.d.ts +1 -1
- package/esm/browser/extension/icons.js +2 -1
- package/esm/browser/extension/web-api-chats.d.ts +2 -0
- package/esm/browser/extension/web-api-components.d.ts +10 -1
- package/esm/browser/extension/web-api-storage.d.ts +20 -0
- package/esm/browser/extension/web-api-storage.js +3 -0
- package/esm/browser/extension/web-extension-api.d.ts +3 -27
- package/esm/browser/extension/web-extension-context.js +1 -1
- package/esm/browser/extension/web-home.d.ts +1 -1
- package/esm/browser/extension/web-home.js +7 -2
- package/esm/browser/extension/web-pages.js +2 -2
- package/esm/browser/i18n/en/account.d.ts +3 -1
- package/esm/browser/i18n/en/account.js +3 -1
- package/esm/browser/i18n/en/chat.d.ts +2 -0
- package/esm/browser/i18n/en/chat.js +3 -1
- package/esm/browser/i18n/en/common.d.ts +1 -0
- package/esm/browser/i18n/en/common.js +1 -0
- package/esm/browser/i18n/ja/account.js +3 -1
- package/esm/browser/i18n/ja/chat.js +3 -1
- package/esm/browser/i18n/ja/common.js +1 -0
- package/esm/browser/i18n/locales.d.ts +7 -2
- package/esm/browser/i18n/messages.d.ts +6 -1
- package/esm/browser/i18n/zh/account.js +3 -1
- package/esm/browser/i18n/zh/chat.js +3 -1
- package/esm/browser/i18n/zh/common.js +1 -0
- package/esm/browser/i18n/zh-tw/account.js +3 -1
- package/esm/browser/i18n/zh-tw/chat.js +3 -1
- package/esm/browser/i18n/zh-tw/common.js +1 -0
- package/esm/browser/links/links.d.ts +4 -1
- package/esm/browser/links/links.js +10 -1
- package/esm/browser/settings/settings.js +3 -0
- package/esm/browser/style/chat-list.d.ts +1 -1
- package/esm/browser/style/chat-list.js +2 -0
- package/esm/browser/style/dialogs.d.ts +1 -1
- package/esm/browser/style/dialogs.js +0 -1
- package/esm/browser/util/tool.d.ts +6 -2
- package/esm/browser/util/tool.js +28 -5
- package/esm/browser/util/voice.d.ts +9 -0
- package/esm/browser/util/voice.js +20 -0
- package/esm/browser/workbench-util.d.ts +5 -0
- package/esm/browser/workbench-util.js +9 -0
- package/esm/browser/workbench.js +6 -1
- package/lib/browser/account/account-side.js +1 -1
- package/lib/browser/account/device-account.d.ts +8 -0
- package/lib/browser/account/device-account.js +26 -0
- package/lib/browser/components/account-menu.d.ts +1 -1
- package/lib/browser/components/account-menu.js +6 -2
- package/lib/browser/components/account-view.d.ts +7 -0
- package/lib/browser/components/account-view.js +91 -10
- package/lib/browser/components/chat-tag.d.ts +13 -5
- package/lib/browser/components/chat-tag.js +22 -5
- package/lib/browser/components/cloud-sign-in-view.d.ts +1 -1
- package/lib/browser/components/composer-box.js +5 -1
- package/lib/browser/components/host-view.d.ts +1 -1
- package/lib/browser/components/host-view.js +3 -3
- package/lib/browser/components/me-rows.d.ts +2 -0
- package/lib/browser/components/me-rows.js +1 -1
- package/lib/browser/components/scan-screen.js +10 -0
- package/lib/browser/components/session-view.js +1 -1
- package/lib/browser/components/tool-view.js +10 -4
- package/lib/browser/components/voice-button.d.ts +7 -0
- package/lib/browser/components/voice-button.js +26 -2
- package/lib/browser/components/voice-talk.js +1 -1
- package/lib/browser/components/workbench-view.js +2 -2
- package/lib/browser/device/back-stack.d.ts +7 -0
- package/lib/browser/device/back-stack.js +13 -1
- package/lib/browser/device/code-scan.d.ts +5 -2
- package/lib/browser/device/code-scan.js +22 -2
- package/lib/browser/device/mini-program.d.ts +70 -0
- package/lib/browser/device/mini-program.js +254 -0
- package/lib/browser/device/sheet-swipe.js +4 -1
- package/lib/browser/device/swipe-util.d.ts +2 -0
- package/lib/browser/device/swipe-util.js +5 -0
- package/lib/browser/extension/extension-view.d.ts +1 -1
- package/lib/browser/extension/icons.js +1 -0
- package/lib/browser/extension/web-api-chats.d.ts +2 -0
- package/lib/browser/extension/web-api-components.d.ts +10 -1
- package/lib/browser/extension/web-api-storage.d.ts +21 -0
- package/lib/browser/extension/web-api-storage.js +4 -0
- package/lib/browser/extension/web-extension-api.d.ts +3 -27
- package/lib/browser/extension/web-extension-context.js +1 -1
- package/lib/browser/extension/web-home.d.ts +1 -1
- package/lib/browser/extension/web-home.js +7 -2
- package/lib/browser/extension/web-pages.js +1 -1
- package/lib/browser/i18n/en/account.d.ts +3 -1
- package/lib/browser/i18n/en/account.js +3 -1
- package/lib/browser/i18n/en/chat.d.ts +2 -0
- package/lib/browser/i18n/en/chat.js +3 -1
- package/lib/browser/i18n/en/common.d.ts +1 -0
- package/lib/browser/i18n/en/common.js +1 -0
- package/lib/browser/i18n/ja/account.js +3 -1
- package/lib/browser/i18n/ja/chat.js +3 -1
- package/lib/browser/i18n/ja/common.js +1 -0
- package/lib/browser/i18n/locales.d.ts +7 -2
- package/lib/browser/i18n/messages.d.ts +6 -1
- package/lib/browser/i18n/zh/account.js +3 -1
- package/lib/browser/i18n/zh/chat.js +3 -1
- package/lib/browser/i18n/zh/common.js +1 -0
- package/lib/browser/i18n/zh-tw/account.js +3 -1
- package/lib/browser/i18n/zh-tw/chat.js +3 -1
- package/lib/browser/i18n/zh-tw/common.js +1 -0
- package/lib/browser/links/links.d.ts +4 -1
- package/lib/browser/links/links.js +10 -1
- package/lib/browser/settings/settings.js +3 -0
- package/lib/browser/style/chat-list.d.ts +1 -1
- package/lib/browser/style/chat-list.js +2 -0
- package/lib/browser/style/dialogs.d.ts +1 -1
- package/lib/browser/style/dialogs.js +0 -1
- package/lib/browser/util/tool.d.ts +6 -2
- package/lib/browser/util/tool.js +28 -5
- package/lib/browser/util/voice.d.ts +9 -0
- package/lib/browser/util/voice.js +20 -0
- package/lib/browser/workbench-util.d.ts +5 -0
- package/lib/browser/workbench-util.js +9 -0
- package/lib/browser/workbench.js +6 -1
- package/package.json +10 -10
|
@@ -5,6 +5,7 @@ import { useBackLayer } from '../device/back-stack.js';
|
|
|
5
5
|
import { ScanScreen } from '../device/code-scan.js';
|
|
6
6
|
import { CodeVision } from '../device/code-vision.js';
|
|
7
7
|
import { nativePlugin } from '../device/device.js';
|
|
8
|
+
import { MiniProgram } from '../device/mini-program.js';
|
|
8
9
|
import { useWorkbench } from '../hooks.js';
|
|
9
10
|
import { useT } from '../i18n/use-t.js';
|
|
10
11
|
import { Icon } from './icon.js';
|
|
@@ -30,6 +31,15 @@ const MISSED_MS = 2600;
|
|
|
30
31
|
/** The scan screen while it is open: the whole of Scan, or reading a code for whoever asked (ScanScreen.read). */
|
|
31
32
|
export function ScanHost(props) {
|
|
32
33
|
const open = React.useSyncExternalStore(ScanScreen.subscribe, ScanScreen.isOpen, ScanScreen.isOpen);
|
|
34
|
+
const [{ status }] = useWorkbench();
|
|
35
|
+
const { onCode } = props;
|
|
36
|
+
React.useEffect(() => {
|
|
37
|
+
// The code the scan page of Ta's mini program opened the page with, once connected.
|
|
38
|
+
const text = status === 'online' ? MiniProgram.take() : undefined;
|
|
39
|
+
if (text) {
|
|
40
|
+
onCode(text);
|
|
41
|
+
}
|
|
42
|
+
}, [status, onCode]);
|
|
33
43
|
if (!open) {
|
|
34
44
|
return React.createElement(ScanReader, null);
|
|
35
45
|
}
|
|
@@ -346,7 +346,7 @@ export function SessionView({ store, server, workspace, info, onClosed, onActivi
|
|
|
346
346
|
React.createElement("div", { className: "ta-session-title" },
|
|
347
347
|
chatTag ? (React.createElement("span", { className: "ta-title-line" },
|
|
348
348
|
React.createElement("span", { className: "ta-title" }, title),
|
|
349
|
-
React.createElement(ChatTagLabel, { tag: chatTag }))) : (React.createElement("span", { className: "ta-title" }, title)),
|
|
349
|
+
React.createElement(ChatTagLabel, { tag: chatTag, openable: true }))) : (React.createElement("span", { className: "ta-title" }, title)),
|
|
350
350
|
info && (React.createElement("span", { className: "ta-muted ta-path", title: info.cwd }, MessageUtil.shortPath(info.cwd)))),
|
|
351
351
|
React.createElement(PeopleFaces, { people: viewing, size: 24, label: t('ta.presence.viewing') }),
|
|
352
352
|
trailing)),
|
|
@@ -25,10 +25,10 @@ function StatusDot({ status }) {
|
|
|
25
25
|
return React.createElement("span", { className: `ta-status ta-status-${status}` });
|
|
26
26
|
}
|
|
27
27
|
/** One step in one line: a dot for its state and what it does; a click opens what it did. */
|
|
28
|
-
function ToolRow({ name, args, status, trailing, details, count = 0, times = 1 }) {
|
|
28
|
+
function ToolRow({ name, args, status, trailing, details, count = 0, times = 1, input }) {
|
|
29
29
|
const t = useT();
|
|
30
30
|
const [open, setOpen] = React.useState(false);
|
|
31
|
-
const summary = ToolUtil.summary(name, args, React.useContext(ToolRenderers));
|
|
31
|
+
const summary = ToolUtil.summary(name, args, React.useContext(ToolRenderers), input);
|
|
32
32
|
const ToolIcon = summary.icon;
|
|
33
33
|
const line = (React.createElement(React.Fragment, null,
|
|
34
34
|
React.createElement(StatusDot, { status: status }),
|
|
@@ -48,6 +48,12 @@ function ToolRow({ name, args, status, trailing, details, count = 0, times = 1 }
|
|
|
48
48
|
React.createElement("span", { className: "ta-tool-trailing" }, trailing)),
|
|
49
49
|
details && open && React.createElement("div", { className: "ta-tool-body" }, details)));
|
|
50
50
|
}
|
|
51
|
+
/** What another agent gave a call of its own, once it said. */
|
|
52
|
+
function agentInput(output) {
|
|
53
|
+
var _a;
|
|
54
|
+
const input = (_a = output === null || output === void 0 ? void 0 : output.details) === null || _a === void 0 ? void 0 : _a.input;
|
|
55
|
+
return input && typeof input === 'object' ? input : undefined;
|
|
56
|
+
}
|
|
51
57
|
/** What a call of a tool did, under its line once opened: the output, the diff, the file it wrote. */
|
|
52
58
|
function details(name, args, output, status) {
|
|
53
59
|
var _a;
|
|
@@ -132,7 +138,7 @@ function Act({ act, results, runs }) {
|
|
|
132
138
|
const body = thoughts || own || all.length ? (React.createElement(React.Fragment, null,
|
|
133
139
|
thoughts,
|
|
134
140
|
all.length > 1 ? (React.createElement("div", { className: "ta-tool-repeats" }, all.map(each => (React.createElement(React.Fragment, { key: each.key }, each.shown))))) : (own || ((_a = all[0]) === null || _a === void 0 ? void 0 : _a.shown)))) : undefined;
|
|
135
|
-
return React.createElement(ToolRow, { name: name, args: args, status: status, details: body, times: act.earlier.length + 1 });
|
|
141
|
+
return React.createElement(ToolRow, { name: name, args: args, status: status, details: body, times: act.earlier.length + 1, input: agentInput(output) });
|
|
136
142
|
}
|
|
137
143
|
// The script of another agent and the calls it made: one line, which opens to the calls, then the script.
|
|
138
144
|
const steps = act.nested.map(call => {
|
|
@@ -149,7 +155,7 @@ function Act({ act, results, runs }) {
|
|
|
149
155
|
var _a, _b, _c;
|
|
150
156
|
const nestedArgs = (_a = step.call.arguments) !== null && _a !== void 0 ? _a : {};
|
|
151
157
|
const shown = details((_b = step.call.name) !== null && _b !== void 0 ? _b : '', nestedArgs, step.output, step.status);
|
|
152
|
-
return React.createElement(ToolRow, { key: step.call.id, name: (_c = step.call.name) !== null && _c !== void 0 ? _c : '', args: nestedArgs, status: step.status, details: shown || undefined });
|
|
158
|
+
return (React.createElement(ToolRow, { key: step.call.id, name: (_c = step.call.name) !== null && _c !== void 0 ? _c : '', args: nestedArgs, status: step.status, details: shown || undefined, input: agentInput(step.output) }));
|
|
153
159
|
}),
|
|
154
160
|
script && React.createElement(ScriptLine, { script: script })) }));
|
|
155
161
|
}
|
|
@@ -11,6 +11,13 @@ export interface VoiceButtonProps {
|
|
|
11
11
|
}
|
|
12
12
|
/** The microphone of a message box with a mouse, where the browser can recognize speech: a click listens, a wave shows it, a click stops it. On a touch screen the box has a bar held to talk instead (TalkBar). */
|
|
13
13
|
export declare function VoiceButton(props: VoiceButtonProps): React.JSX.Element;
|
|
14
|
+
/**
|
|
15
|
+
* The microphone of a message box in WeChat's mini program, whose web-view cannot listen: its voice page listens,
|
|
16
|
+
* and what it heard goes into the box (MiniProgram.dictate), as WeChat's voice to text, to be read over and sent.
|
|
17
|
+
*/
|
|
18
|
+
export declare function DictateButton({ onHeard }: {
|
|
19
|
+
onHeard(text: string): void;
|
|
20
|
+
}): React.JSX.Element;
|
|
14
21
|
/** A reply being read aloud, on the right of the box: its wave, and a tap stops it. */
|
|
15
22
|
export declare function SpeakingButton({ onStop }: {
|
|
16
23
|
onStop(): void;
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { Mic } from 'lucide-react';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
+
import { MiniProgram } from '../device/mini-program.js';
|
|
3
4
|
import { useLanguage, useT } from '../i18n/use-t.js';
|
|
4
5
|
import { Voice } from '../util/voice.js';
|
|
6
|
+
import { useBusy } from './busy.js';
|
|
5
7
|
import { Icon } from './icon.js';
|
|
6
8
|
/** The microphone of a message box with a mouse, where the browser can recognize speech: a click listens, a wave shows it, a click stops it. On a touch screen the box has a bar held to talk instead (TalkBar). */
|
|
7
9
|
export function VoiceButton(props) {
|
|
@@ -40,8 +42,7 @@ export function VoiceButton(props) {
|
|
|
40
42
|
setListening(false);
|
|
41
43
|
(_b = (_a = latest.current).onListening) === null || _b === void 0 ? void 0 : _b.call(_a, false);
|
|
42
44
|
if (failure) {
|
|
43
|
-
|
|
44
|
-
latest.current.onError(new Error(denied ? t('ta.composer.voiceDenied') : t('ta.composer.voiceFailed', { error: failure })));
|
|
45
|
+
latest.current.onError(new Error(t(Voice.failure(failure), { error: failure })));
|
|
45
46
|
}
|
|
46
47
|
if (heard) {
|
|
47
48
|
latest.current.onHeard(heard);
|
|
@@ -62,6 +63,28 @@ export function VoiceButton(props) {
|
|
|
62
63
|
React.createElement("i", null),
|
|
63
64
|
React.createElement("i", null))) : (React.createElement(Icon, { icon: Mic, size: 17 }))));
|
|
64
65
|
}
|
|
66
|
+
/**
|
|
67
|
+
* The microphone of a message box in WeChat's mini program, whose web-view cannot listen: its voice page listens,
|
|
68
|
+
* and what it heard goes into the box (MiniProgram.dictate), as WeChat's voice to text, to be read over and sent.
|
|
69
|
+
*/
|
|
70
|
+
export function DictateButton({ onHeard }) {
|
|
71
|
+
const t = useT();
|
|
72
|
+
const language = useLanguage();
|
|
73
|
+
const latest = React.useRef(onHeard);
|
|
74
|
+
latest.current = onHeard;
|
|
75
|
+
// Words heard as the page loaded again (a web-view that reloads for a fragment).
|
|
76
|
+
React.useEffect(() => {
|
|
77
|
+
const said = MiniProgram.takeSaid();
|
|
78
|
+
if (said) {
|
|
79
|
+
latest.current(said);
|
|
80
|
+
}
|
|
81
|
+
}, []);
|
|
82
|
+
// Opening the voice page loads WeChat's JS-SDK the first time.
|
|
83
|
+
const [busy, run] = useBusy();
|
|
84
|
+
const label = t('ta.composer.voice');
|
|
85
|
+
return (React.createElement("button", { type: "button", className: busy ? 'ta-mic ta-busy' : 'ta-mic', title: label, "aria-label": label, onClick: () => void run(() => MiniProgram.dictate(language, words => latest.current(words))) },
|
|
86
|
+
React.createElement(Icon, { icon: Mic, size: 18 })));
|
|
87
|
+
}
|
|
65
88
|
/** A reply being read aloud, on the right of the box: its wave, and a tap stops it. */
|
|
66
89
|
export function SpeakingButton({ onStop }) {
|
|
67
90
|
const t = useT();
|
|
@@ -136,7 +136,7 @@ export function useVoiceTalk(onGive, onError, hints, calls = []) {
|
|
|
136
136
|
return;
|
|
137
137
|
}
|
|
138
138
|
if (failure) {
|
|
139
|
-
fail.current(new Error(t(Voice.
|
|
139
|
+
fail.current(new Error(t(Voice.failure(failure), { error: failure })));
|
|
140
140
|
leave();
|
|
141
141
|
}
|
|
142
142
|
else if (phase.current === 'released') {
|
|
@@ -63,7 +63,7 @@ export function SignIn(props) {
|
|
|
63
63
|
function RecentSignIns() {
|
|
64
64
|
const t = useT();
|
|
65
65
|
const [{ hosts }] = useWorkbench();
|
|
66
|
-
const accounts = WorkbenchUtil.
|
|
66
|
+
const accounts = WorkbenchUtil.ownDevice() ? DeviceAccount.recent().length : 0;
|
|
67
67
|
if (hosts.length === 0 && accounts === 0) {
|
|
68
68
|
return null;
|
|
69
69
|
}
|
|
@@ -79,7 +79,7 @@ function RecentSignIns() {
|
|
|
79
79
|
*/
|
|
80
80
|
function SignInPage({ error }) {
|
|
81
81
|
const t = useT();
|
|
82
|
-
const app = WorkbenchUtil.
|
|
82
|
+
const app = WorkbenchUtil.ownDevice();
|
|
83
83
|
const way = CodeScan.available() ? 'scan' : app ? 'pair' : 'serve';
|
|
84
84
|
// The ta serve of this page may take accounts (GitHub, Google, WeChat...); the app has none of its own.
|
|
85
85
|
const { providers, outcome, settled } = useSignInWays(!app);
|
|
@@ -94,6 +94,13 @@ export declare class BackLayers {
|
|
|
94
94
|
* on Android, whose back key slides nothing: there the layer slides away as when its button closes it.
|
|
95
95
|
*/
|
|
96
96
|
static browserSlides(): boolean;
|
|
97
|
+
/**
|
|
98
|
+
* Whether the web view goes back in its history by a swipe from the left edge of its own, which the page can
|
|
99
|
+
* neither stop nor hear of before it ends: WeChat's web-view of a mini program on iOS. While a layer is open, so
|
|
100
|
+
* that there is an entry to go back to, a swipe to the right from that edge is the web view's alone (a sheet of
|
|
101
|
+
* the page moving with it, the page would slide twice); it closes the top layer as Safari's does (browserSlides).
|
|
102
|
+
*/
|
|
103
|
+
static webViewSwipesBack(): boolean;
|
|
97
104
|
}
|
|
98
105
|
/** The layers of this page. */
|
|
99
106
|
export declare const Back: BackLayers;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
2
|
import { useDevice } from './device.js';
|
|
3
|
+
import { MiniProgram } from './mini-program.js';
|
|
3
4
|
/**
|
|
4
5
|
* The layers open as entries of the browser's history, so that its back closes the top one, as the back of an
|
|
5
6
|
* app does: the back button and gesture of Android, the swipe back of Safari, the back of a browser. Closed by
|
|
@@ -190,6 +191,15 @@ export class BackLayers {
|
|
|
190
191
|
const ios = /iPhone|iPad|iPod/.test(navigator.userAgent) || (/Macintosh/.test(navigator.userAgent) && navigator.maxTouchPoints > 1);
|
|
191
192
|
return ios && !app;
|
|
192
193
|
}
|
|
194
|
+
/**
|
|
195
|
+
* Whether the web view goes back in its history by a swipe from the left edge of its own, which the page can
|
|
196
|
+
* neither stop nor hear of before it ends: WeChat's web-view of a mini program on iOS. While a layer is open, so
|
|
197
|
+
* that there is an entry to go back to, a swipe to the right from that edge is the web view's alone (a sheet of
|
|
198
|
+
* the page moving with it, the page would slide twice); it closes the top layer as Safari's does (browserSlides).
|
|
199
|
+
*/
|
|
200
|
+
static webViewSwipesBack() {
|
|
201
|
+
return MiniProgram.inside() && BackLayers.browserSlides();
|
|
202
|
+
}
|
|
193
203
|
}
|
|
194
204
|
/** The layers of this page. */
|
|
195
205
|
export const Back = typeof window === 'undefined'
|
|
@@ -205,7 +215,9 @@ export const Back = typeof window === 'undefined'
|
|
|
205
215
|
requestAnimationFrame(() => requestAnimationFrame(() => delete root.dataset.sheetDrag));
|
|
206
216
|
}, BackLayers.browserSlides);
|
|
207
217
|
if (typeof window !== 'undefined') {
|
|
208
|
-
|
|
218
|
+
// Words the mini program's voice page gave back come as a move of the history, and are no back (MiniProgram.hears).
|
|
219
|
+
window.addEventListener('popstate', () => MiniProgram.hears() || Back.popped());
|
|
220
|
+
window.addEventListener('hashchange', () => MiniProgram.hears());
|
|
209
221
|
}
|
|
210
222
|
/** The layer the components under it are opened in. */
|
|
211
223
|
export const BackLayerContext = React.createContext(undefined);
|
|
@@ -52,12 +52,15 @@ export interface CodeScanHost {
|
|
|
52
52
|
export declare class CodeScan {
|
|
53
53
|
protected readonly host: CodeScanHost;
|
|
54
54
|
constructor(host: CodeScanHost);
|
|
55
|
-
/** Only the Ta app has a camera to scan with. */
|
|
55
|
+
/** Only the Ta app has a camera to scan with, and Ta's mini program of WeChat scans for its page (MiniProgram). */
|
|
56
56
|
static available(): boolean;
|
|
57
|
+
/** The page gets the code it scans back (the Ta app): not in the mini program, which opens the page again with it. */
|
|
58
|
+
static readable(): boolean;
|
|
57
59
|
/**
|
|
58
60
|
* Reads a code for the caller (`ui.scanCode`, adding a computer): the scan screen of the page, which picks from
|
|
59
61
|
* the album too, else the scanner of the app's plugin. Its text, or undefined when the user cancelled; rejects
|
|
60
|
-
* with a ScanError where the plugin could not.
|
|
62
|
+
* with a ScanError where the plugin could not. In the mini program, its scan page, which opens the page again
|
|
63
|
+
* with the code: undefined here.
|
|
61
64
|
*/
|
|
62
65
|
static read(instructions: string, cancelLabel: string): Promise<string | undefined>;
|
|
63
66
|
scan(): Promise<void>;
|
|
@@ -2,6 +2,7 @@ import { message } from '../i18n/messages.js';
|
|
|
2
2
|
import { ShareLinkUtil } from '../util/share-link.js';
|
|
3
3
|
import { WorkbenchUtil } from '../workbench-util.js';
|
|
4
4
|
import { CodeVision } from './code-vision.js';
|
|
5
|
+
import { MiniProgram } from './mini-program.js';
|
|
5
6
|
import { ScanError, Scanner } from './scanner.js';
|
|
6
7
|
/**
|
|
7
8
|
* Whether the scan screen of the page is open: ScanHost (components/scan-screen.tsx) draws it, CodeScan opens it;
|
|
@@ -85,16 +86,29 @@ export class CodeScan {
|
|
|
85
86
|
constructor(host) {
|
|
86
87
|
this.host = host;
|
|
87
88
|
}
|
|
88
|
-
/** Only the Ta app has a camera to scan with. */
|
|
89
|
+
/** Only the Ta app has a camera to scan with, and Ta's mini program of WeChat scans for its page (MiniProgram). */
|
|
89
90
|
static available() {
|
|
91
|
+
return CodeScan.readable() || MiniProgram.inside();
|
|
92
|
+
}
|
|
93
|
+
/** The page gets the code it scans back (the Ta app): not in the mini program, which opens the page again with it. */
|
|
94
|
+
static readable() {
|
|
90
95
|
return CodeVision.available() || Scanner.available();
|
|
91
96
|
}
|
|
92
97
|
/**
|
|
93
98
|
* Reads a code for the caller (`ui.scanCode`, adding a computer): the scan screen of the page, which picks from
|
|
94
99
|
* the album too, else the scanner of the app's plugin. Its text, or undefined when the user cancelled; rejects
|
|
95
|
-
* with a ScanError where the plugin could not.
|
|
100
|
+
* with a ScanError where the plugin could not. In the mini program, its scan page, which opens the page again
|
|
101
|
+
* with the code: undefined here.
|
|
96
102
|
*/
|
|
97
103
|
static read(instructions, cancelLabel) {
|
|
104
|
+
if (!CodeScan.readable() && MiniProgram.inside()) {
|
|
105
|
+
return MiniProgram.scan().then(went => {
|
|
106
|
+
if (!went) {
|
|
107
|
+
throw new ScanError('failed');
|
|
108
|
+
}
|
|
109
|
+
return undefined;
|
|
110
|
+
});
|
|
111
|
+
}
|
|
98
112
|
return CodeVision.available() ? ScanScreen.read(instructions) : Scanner.scan(instructions, cancelLabel);
|
|
99
113
|
}
|
|
100
114
|
async scan() {
|
|
@@ -102,6 +116,12 @@ export class CodeScan {
|
|
|
102
116
|
ScanScreen.show();
|
|
103
117
|
return;
|
|
104
118
|
}
|
|
119
|
+
if (!Scanner.available() && MiniProgram.inside()) {
|
|
120
|
+
if (!(await MiniProgram.scan())) {
|
|
121
|
+
this.host.notices.notify(this.say('ta.scan.failed'), { level: 'error' });
|
|
122
|
+
}
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
105
125
|
let text;
|
|
106
126
|
try {
|
|
107
127
|
text = await Scanner.scan(this.say('ta.scan.instructions'), this.say('ta.cancel'));
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ta's web page in the web-view of Ta's WeChat mini program (apps/ta-weapp, docs/design/ta-weapp.md). The web-view has no
|
|
3
|
+
* camera of its own and hears nothing of its mini program while open: Scan goes to the scan page of the mini program
|
|
4
|
+
* (`wx.scanCode`), which opens the page again with what it read, a computer to pair with as `#pair=`
|
|
5
|
+
* (WorkbenchUtil.fromFragment) and any other code as `#scan=`, opened as a code scanned in the Ta app (CodeScan.open)
|
|
6
|
+
* once the page is connected. Its bar (WeChat's, over the web-view: a web-view has no bar of its own) is coloured as
|
|
7
|
+
* Ta's theme by the look page of the mini program (`paint`). Speech is heard by the voice page of the mini program
|
|
8
|
+
* (WeChat's recognizer, the WechatSI plugin: the web-view's own always refuses), which gives the words back in the
|
|
9
|
+
* fragment of the page (`#say=`), changed alone so that the page stays as it is (`dictate`).
|
|
10
|
+
*/
|
|
11
|
+
export declare namespace MiniProgram {
|
|
12
|
+
/** WeChat's JS-SDK, loaded in the mini program alone: what lets the page go to a page of the mini program. */
|
|
13
|
+
const SDK = "https://res.wx.qq.com/open/js/jweixin-1.6.0.js";
|
|
14
|
+
/** The scan page of apps/ta-weapp. */
|
|
15
|
+
const SCAN_PAGE = "/pages/scan/scan";
|
|
16
|
+
/** The page of apps/ta-weapp that colours the bar of the mini program, keeps the colour and goes back at once. */
|
|
17
|
+
const LOOK_PAGE = "/pages/look/look";
|
|
18
|
+
/** The page of apps/ta-weapp that listens and gives the page what it heard. */
|
|
19
|
+
const VOICE_PAGE = "/pages/voice/voice";
|
|
20
|
+
/** What the mini program says it has (`#can=`), kept: its fragment is read once, and the page may load again without it. */
|
|
21
|
+
const CAN_KEY = "ta.miniProgram.can";
|
|
22
|
+
/** The theme is applied a few times as the page starts (its look of the last time, then the computer's): the bar waits for the last. */
|
|
23
|
+
const PAINT_MS = 400;
|
|
24
|
+
/** Pure: whether a user agent is that of the web-view of a mini program (WeChat says `miniProgram` there, since 7.0). */
|
|
25
|
+
function isAgent(agent: string): boolean;
|
|
26
|
+
/** Whether this page is in the web-view of a mini program. */
|
|
27
|
+
function inside(): boolean;
|
|
28
|
+
/** Pure: the code the scan page of the mini program read, from the fragment it opened the page with. */
|
|
29
|
+
function scanned(fragment: URLSearchParams): string | undefined;
|
|
30
|
+
/** Pure: the colour of the bar the mini program opened the page under (`bar=`, six hex digits), as `#rrggbb`. */
|
|
31
|
+
function barOf(fragment: URLSearchParams): string | undefined;
|
|
32
|
+
/** Pure: the look page that colours the bar `color` (`#rrggbb`), its title and the clock white over a dark one. */
|
|
33
|
+
function lookUrl(color: string, dark: boolean): string;
|
|
34
|
+
/** Pure: what the mini program says it has, from its fragment (`can=voice,…`); undefined when it says nothing. */
|
|
35
|
+
function canOf(fragment: URLSearchParams): string[] | undefined;
|
|
36
|
+
/** Pure: the words its voice page heard (`say=`). */
|
|
37
|
+
function saidOf(fragment: URLSearchParams): string | undefined;
|
|
38
|
+
/** Pure: the language WeChat's recognizer hears, for the page's (Mandarin unless English: it has no other of Ta's). */
|
|
39
|
+
function voiceLanguage(language: string): string;
|
|
40
|
+
/**
|
|
41
|
+
* Keeps the code the page was opened with, in the mini program alone (a link elsewhere opens nothing by itself);
|
|
42
|
+
* whether the fragment said anything to the mini program's page (a code, its bar), to take out of the address.
|
|
43
|
+
*/
|
|
44
|
+
function arrive(fragment: URLSearchParams): boolean;
|
|
45
|
+
/** Whether the mini program hears speech for the page (its voice page). */
|
|
46
|
+
function canDictate(): boolean;
|
|
47
|
+
/**
|
|
48
|
+
* Opens the voice page of the mini program, which listens in `language` (the page's) and gives `onWords` what it
|
|
49
|
+
* heard; nothing when the user cancels. False where it could not open.
|
|
50
|
+
*/
|
|
51
|
+
function dictate(language: string, onWords: (words: string) => void): Promise<boolean>;
|
|
52
|
+
/** What was said while the page loaded again, once: to put into the box. */
|
|
53
|
+
function takeSaid(): string | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* The history moved: whether to the words the voice page gave back (`#say=`), which go to what asked for them, the
|
|
56
|
+
* entry of the history they came in taken back (it is no layer of the page's, BackStack). The rest is the page's.
|
|
57
|
+
*/
|
|
58
|
+
function hears(): boolean;
|
|
59
|
+
/**
|
|
60
|
+
* The bar of the mini program in `color` (`#rrggbb`), the colour at the top of Ta's page: WeChat gives a web-view
|
|
61
|
+
* no way to colour it, so the look page does, pushed and gone at once, only when the colour changes (its last is
|
|
62
|
+
* kept by the mini program, which opens the page under it the next time).
|
|
63
|
+
*/
|
|
64
|
+
function paint(color: string, dark: boolean): void;
|
|
65
|
+
/** The code the page was opened with, once: to open once connected. */
|
|
66
|
+
function take(): string | undefined;
|
|
67
|
+
/** Goes to the scan page of the mini program, which opens this page again with the code; false where it could not. */
|
|
68
|
+
function scan(): Promise<boolean>;
|
|
69
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ta's web page in the web-view of Ta's WeChat mini program (apps/ta-weapp, docs/design/ta-weapp.md). The web-view has no
|
|
3
|
+
* camera of its own and hears nothing of its mini program while open: Scan goes to the scan page of the mini program
|
|
4
|
+
* (`wx.scanCode`), which opens the page again with what it read, a computer to pair with as `#pair=`
|
|
5
|
+
* (WorkbenchUtil.fromFragment) and any other code as `#scan=`, opened as a code scanned in the Ta app (CodeScan.open)
|
|
6
|
+
* once the page is connected. Its bar (WeChat's, over the web-view: a web-view has no bar of its own) is coloured as
|
|
7
|
+
* Ta's theme by the look page of the mini program (`paint`). Speech is heard by the voice page of the mini program
|
|
8
|
+
* (WeChat's recognizer, the WechatSI plugin: the web-view's own always refuses), which gives the words back in the
|
|
9
|
+
* fragment of the page (`#say=`), changed alone so that the page stays as it is (`dictate`).
|
|
10
|
+
*/
|
|
11
|
+
export var MiniProgram;
|
|
12
|
+
(function (MiniProgram) {
|
|
13
|
+
/** WeChat's JS-SDK, loaded in the mini program alone: what lets the page go to a page of the mini program. */
|
|
14
|
+
MiniProgram.SDK = 'https://res.wx.qq.com/open/js/jweixin-1.6.0.js';
|
|
15
|
+
/** The scan page of apps/ta-weapp. */
|
|
16
|
+
MiniProgram.SCAN_PAGE = '/pages/scan/scan';
|
|
17
|
+
/** The page of apps/ta-weapp that colours the bar of the mini program, keeps the colour and goes back at once. */
|
|
18
|
+
MiniProgram.LOOK_PAGE = '/pages/look/look';
|
|
19
|
+
/** The page of apps/ta-weapp that listens and gives the page what it heard. */
|
|
20
|
+
MiniProgram.VOICE_PAGE = '/pages/voice/voice';
|
|
21
|
+
/** What the mini program says it has (`#can=`), kept: its fragment is read once, and the page may load again without it. */
|
|
22
|
+
MiniProgram.CAN_KEY = 'ta.miniProgram.can';
|
|
23
|
+
/** The theme is applied a few times as the page starts (its look of the last time, then the computer's): the bar waits for the last. */
|
|
24
|
+
MiniProgram.PAINT_MS = 400;
|
|
25
|
+
/** Pure: whether a user agent is that of the web-view of a mini program (WeChat says `miniProgram` there, since 7.0). */
|
|
26
|
+
function isAgent(agent) {
|
|
27
|
+
return /miniProgram/i.test(agent);
|
|
28
|
+
}
|
|
29
|
+
MiniProgram.isAgent = isAgent;
|
|
30
|
+
/** Whether this page is in the web-view of a mini program. */
|
|
31
|
+
function inside() {
|
|
32
|
+
if (typeof navigator === 'undefined') {
|
|
33
|
+
return false;
|
|
34
|
+
}
|
|
35
|
+
return isAgent(navigator.userAgent) || globalThis.__wxjs_environment === 'miniprogram';
|
|
36
|
+
}
|
|
37
|
+
MiniProgram.inside = inside;
|
|
38
|
+
/** Pure: the code the scan page of the mini program read, from the fragment it opened the page with. */
|
|
39
|
+
function scanned(fragment) {
|
|
40
|
+
var _a;
|
|
41
|
+
return ((_a = fragment.get('scan')) === null || _a === void 0 ? void 0 : _a.trim()) || undefined;
|
|
42
|
+
}
|
|
43
|
+
MiniProgram.scanned = scanned;
|
|
44
|
+
/** Pure: the colour of the bar the mini program opened the page under (`bar=`, six hex digits), as `#rrggbb`. */
|
|
45
|
+
function barOf(fragment) {
|
|
46
|
+
var _a;
|
|
47
|
+
const bar = (_a = fragment.get('bar')) === null || _a === void 0 ? void 0 : _a.trim().toLowerCase();
|
|
48
|
+
return bar && /^[0-9a-f]{6}$/.test(bar) ? `#${bar}` : undefined;
|
|
49
|
+
}
|
|
50
|
+
MiniProgram.barOf = barOf;
|
|
51
|
+
/** Pure: the look page that colours the bar `color` (`#rrggbb`), its title and the clock white over a dark one. */
|
|
52
|
+
function lookUrl(color, dark) {
|
|
53
|
+
return `${MiniProgram.LOOK_PAGE}?bar=${color.slice(1)}&text=${dark ? 'white' : 'black'}`;
|
|
54
|
+
}
|
|
55
|
+
MiniProgram.lookUrl = lookUrl;
|
|
56
|
+
/** Pure: what the mini program says it has, from its fragment (`can=voice,…`); undefined when it says nothing. */
|
|
57
|
+
function canOf(fragment) {
|
|
58
|
+
const can = fragment.get('can');
|
|
59
|
+
return can === null ? undefined : can.split(',').filter(Boolean);
|
|
60
|
+
}
|
|
61
|
+
MiniProgram.canOf = canOf;
|
|
62
|
+
/** Pure: the words its voice page heard (`say=`). */
|
|
63
|
+
function saidOf(fragment) {
|
|
64
|
+
var _a;
|
|
65
|
+
return ((_a = fragment.get('say')) === null || _a === void 0 ? void 0 : _a.trim()) || undefined;
|
|
66
|
+
}
|
|
67
|
+
MiniProgram.saidOf = saidOf;
|
|
68
|
+
/** Pure: the language WeChat's recognizer hears, for the page's (Mandarin unless English: it has no other of Ta's). */
|
|
69
|
+
function voiceLanguage(language) {
|
|
70
|
+
return /^en\b/i.test(language) ? 'en_US' : 'zh_CN';
|
|
71
|
+
}
|
|
72
|
+
MiniProgram.voiceLanguage = voiceLanguage;
|
|
73
|
+
let arrived;
|
|
74
|
+
let said;
|
|
75
|
+
let hearing;
|
|
76
|
+
/** How long the history was when the voice page opened: the words given back push an entry of their own, or not. */
|
|
77
|
+
let lengthBefore = 0;
|
|
78
|
+
let heardHash;
|
|
79
|
+
/** The colour of the bar now: as the mini program opened the page, then as the page asked. */
|
|
80
|
+
let bar = typeof location === 'undefined' || !inside() ? undefined : barOf(new URLSearchParams(location.hash.slice(1)));
|
|
81
|
+
let painting;
|
|
82
|
+
/**
|
|
83
|
+
* Keeps the code the page was opened with, in the mini program alone (a link elsewhere opens nothing by itself);
|
|
84
|
+
* whether the fragment said anything to the mini program's page (a code, its bar), to take out of the address.
|
|
85
|
+
*/
|
|
86
|
+
function arrive(fragment) {
|
|
87
|
+
var _a;
|
|
88
|
+
if (!inside()) {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
const text = scanned(fragment);
|
|
92
|
+
arrived = text !== null && text !== void 0 ? text : arrived;
|
|
93
|
+
const can = canOf(fragment);
|
|
94
|
+
if (can) {
|
|
95
|
+
try {
|
|
96
|
+
localStorage.setItem(MiniProgram.CAN_KEY, can.join(','));
|
|
97
|
+
}
|
|
98
|
+
catch (_b) {
|
|
99
|
+
// Not kept: until the page loads again.
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
// The page loaded again with what was said (a web-view that reloads for a fragment): kept for the box.
|
|
103
|
+
said = (_a = saidOf(fragment)) !== null && _a !== void 0 ? _a : said;
|
|
104
|
+
return text !== undefined || barOf(fragment) !== undefined || can !== undefined || fragment.has('say');
|
|
105
|
+
}
|
|
106
|
+
MiniProgram.arrive = arrive;
|
|
107
|
+
/** Whether the mini program hears speech for the page (its voice page). */
|
|
108
|
+
function canDictate() {
|
|
109
|
+
var _a;
|
|
110
|
+
if (!inside()) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
return ((_a = localStorage.getItem(MiniProgram.CAN_KEY)) !== null && _a !== void 0 ? _a : '').split(',').includes('voice');
|
|
115
|
+
}
|
|
116
|
+
catch (_b) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
MiniProgram.canDictate = canDictate;
|
|
121
|
+
/**
|
|
122
|
+
* Opens the voice page of the mini program, which listens in `language` (the page's) and gives `onWords` what it
|
|
123
|
+
* heard; nothing when the user cancels. False where it could not open.
|
|
124
|
+
*/
|
|
125
|
+
async function dictate(language, onWords) {
|
|
126
|
+
const mini = await api();
|
|
127
|
+
if (!mini) {
|
|
128
|
+
return false;
|
|
129
|
+
}
|
|
130
|
+
hearing = onWords;
|
|
131
|
+
lengthBefore = history.length;
|
|
132
|
+
return new Promise(resolve => mini.navigateTo({ url: `${MiniProgram.VOICE_PAGE}?lang=${voiceLanguage(language)}`, success: () => resolve(true), fail: () => resolve(false) }));
|
|
133
|
+
}
|
|
134
|
+
MiniProgram.dictate = dictate;
|
|
135
|
+
/** What was said while the page loaded again, once: to put into the box. */
|
|
136
|
+
function takeSaid() {
|
|
137
|
+
const words = said;
|
|
138
|
+
said = undefined;
|
|
139
|
+
return words;
|
|
140
|
+
}
|
|
141
|
+
MiniProgram.takeSaid = takeSaid;
|
|
142
|
+
/**
|
|
143
|
+
* The history moved: whether to the words the voice page gave back (`#say=`), which go to what asked for them, the
|
|
144
|
+
* entry of the history they came in taken back (it is no layer of the page's, BackStack). The rest is the page's.
|
|
145
|
+
*/
|
|
146
|
+
function hears() {
|
|
147
|
+
if (!inside()) {
|
|
148
|
+
return false;
|
|
149
|
+
}
|
|
150
|
+
const words = saidOf(new URLSearchParams(location.hash.slice(1)));
|
|
151
|
+
if (words === undefined) {
|
|
152
|
+
return false;
|
|
153
|
+
}
|
|
154
|
+
// Heard once, by popstate or hashchange (both come, and the history goes back later).
|
|
155
|
+
if (location.hash === heardHash) {
|
|
156
|
+
return true;
|
|
157
|
+
}
|
|
158
|
+
heardHash = location.hash;
|
|
159
|
+
if (history.length > lengthBefore && lengthBefore > 0) {
|
|
160
|
+
history.back();
|
|
161
|
+
}
|
|
162
|
+
else {
|
|
163
|
+
history.replaceState(history.state, '', location.pathname + location.search);
|
|
164
|
+
}
|
|
165
|
+
lengthBefore = 0;
|
|
166
|
+
const to = hearing;
|
|
167
|
+
hearing = undefined;
|
|
168
|
+
if (to) {
|
|
169
|
+
to(words);
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
said = words;
|
|
173
|
+
}
|
|
174
|
+
return true;
|
|
175
|
+
}
|
|
176
|
+
MiniProgram.hears = hears;
|
|
177
|
+
/**
|
|
178
|
+
* The bar of the mini program in `color` (`#rrggbb`), the colour at the top of Ta's page: WeChat gives a web-view
|
|
179
|
+
* no way to colour it, so the look page does, pushed and gone at once, only when the colour changes (its last is
|
|
180
|
+
* kept by the mini program, which opens the page under it the next time).
|
|
181
|
+
*/
|
|
182
|
+
function paint(color, dark) {
|
|
183
|
+
if (!inside()) {
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
clearTimeout(painting);
|
|
187
|
+
painting = setTimeout(() => {
|
|
188
|
+
if (color === bar) {
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
// Behind the scan page, or WeChat in the background: once the page shows again.
|
|
192
|
+
if (document.visibilityState !== 'visible') {
|
|
193
|
+
document.addEventListener('visibilitychange', () => paint(color, dark), { once: true });
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const before = bar;
|
|
197
|
+
bar = color;
|
|
198
|
+
void api().then(mini => {
|
|
199
|
+
if (!mini) {
|
|
200
|
+
bar = before;
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
mini.navigateTo({
|
|
204
|
+
url: lookUrl(color, dark),
|
|
205
|
+
// A mini program of before the look page: as it was.
|
|
206
|
+
fail: () => {
|
|
207
|
+
bar = before;
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
});
|
|
211
|
+
}, MiniProgram.PAINT_MS);
|
|
212
|
+
}
|
|
213
|
+
MiniProgram.paint = paint;
|
|
214
|
+
/** The code the page was opened with, once: to open once connected. */
|
|
215
|
+
function take() {
|
|
216
|
+
const text = arrived;
|
|
217
|
+
arrived = undefined;
|
|
218
|
+
return text;
|
|
219
|
+
}
|
|
220
|
+
MiniProgram.take = take;
|
|
221
|
+
let sdk;
|
|
222
|
+
function api() {
|
|
223
|
+
const found = () => { var _a; return (_a = globalThis.wx) === null || _a === void 0 ? void 0 : _a.miniProgram; };
|
|
224
|
+
sdk !== null && sdk !== void 0 ? sdk : (sdk = new Promise(resolve => {
|
|
225
|
+
if (found()) {
|
|
226
|
+
resolve(found());
|
|
227
|
+
return;
|
|
228
|
+
}
|
|
229
|
+
const script = document.createElement('script');
|
|
230
|
+
script.src = MiniProgram.SDK;
|
|
231
|
+
script.onload = () => resolve(found());
|
|
232
|
+
script.onerror = () => {
|
|
233
|
+
// Tried again on the next scan: the network may be back.
|
|
234
|
+
sdk = undefined;
|
|
235
|
+
resolve(undefined);
|
|
236
|
+
};
|
|
237
|
+
document.head.append(script);
|
|
238
|
+
}));
|
|
239
|
+
return sdk;
|
|
240
|
+
}
|
|
241
|
+
/** Goes to the scan page of the mini program, which opens this page again with the code; false where it could not. */
|
|
242
|
+
async function scan() {
|
|
243
|
+
const mini = await api();
|
|
244
|
+
if (!mini) {
|
|
245
|
+
return false;
|
|
246
|
+
}
|
|
247
|
+
return new Promise(resolve => mini.navigateTo({ url: MiniProgram.SCAN_PAGE, success: () => resolve(true), fail: () => resolve(false) }));
|
|
248
|
+
}
|
|
249
|
+
MiniProgram.scan = scan;
|
|
250
|
+
})(MiniProgram || (MiniProgram = {}));
|
|
251
|
+
//# sourceMappingURL=mini-program.js.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { Back, BackLayers } from './back-stack.js';
|
|
2
3
|
import { OwnGestures } from './own-gestures.js';
|
|
3
4
|
import { SwipeFinger } from './swipe-finger.js';
|
|
4
5
|
import { afterLetGo, SwipeSettle, translated } from './swipe-settle.js';
|
|
@@ -221,7 +222,9 @@ export function useSheetSwipe(options) {
|
|
|
221
222
|
return;
|
|
222
223
|
}
|
|
223
224
|
const at = point(event, touch);
|
|
224
|
-
|
|
225
|
+
// The web view's own swipe back, which would move the page with the sheet: left to it (BackLayers.webViewSwipesBack).
|
|
226
|
+
const theirs = Back.size > 0 && SwipeUtil.fromBackEdge(sheet, at, current.open) && BackLayers.webViewSwipesBack();
|
|
227
|
+
if (!theirs && SwipeUtil.starts(sheet, at, current.open, window.innerWidth) && finger.follow(event, from.doc)) {
|
|
225
228
|
start = at;
|
|
226
229
|
velocity.start(at);
|
|
227
230
|
}
|
|
@@ -31,6 +31,8 @@ export declare namespace SwipeUtil {
|
|
|
31
31
|
const VELOCITY_MS = 80;
|
|
32
32
|
/** 1 when the finger moves right to bring the sheet out, -1 when left. */
|
|
33
33
|
function outward(sheet: SheetSwipe): 1 | -1;
|
|
34
|
+
/** Whether a touch at `start` moving the sheet would be a swipe to the right from the left edge: the back of iOS. */
|
|
35
|
+
function fromBackEdge(sheet: SheetSwipe, start: TouchPoint, open: boolean): boolean;
|
|
34
36
|
/** Whether a touch at `start` may move the sheet, on a screen `width` wide. */
|
|
35
37
|
function starts(sheet: SheetSwipe, start: TouchPoint, open: boolean, width: number): boolean;
|
|
36
38
|
/** Whether the move so far is the sheet's (more sideways than down, the right way); undefined until it is told. */
|