@peers-app/peers-ui 0.34.11 → 0.34.12
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/dist/components/markdown-editor/link-plugin.d.ts +9 -5
- package/dist/components/markdown-editor/link-plugin.js +47 -22
- package/dist/components/markdown-render.js +21 -8
- package/dist/components/markdown-with-mentions.d.ts +6 -4
- package/dist/components/markdown-with-mentions.js +6 -4
- package/dist/host-shell/host-shell-consumer.d.ts +13 -5
- package/dist/host-shell/host-shell-consumer.js +31 -16
- package/dist/isolated-screens/frame-runtime.js +14 -15
- package/dist/links/app-link-prompt.d.ts +29 -0
- package/dist/links/app-link-prompt.js +102 -0
- package/dist/links/link-schemes.d.ts +30 -0
- package/dist/links/link-schemes.js +46 -0
- package/dist/links/peers-links.d.ts +33 -0
- package/dist/links/peers-links.js +124 -0
- package/dist/mentions/mention-chooser.d.ts +12 -0
- package/dist/mentions/mention-chooser.js +48 -13
- package/dist/root-layout/root-layout-host.js +10 -1
- package/dist/screens/invites/accept-invite.js +3 -4
- package/dist/screens/invites/invite-capture.d.ts +2 -7
- package/dist/screens/invites/invite-capture.js +8 -25
- package/dist/screens/settings/settings-page.js +3 -1
- package/package.json +3 -3
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { type LinkNode } from "@lexical/link";
|
|
2
2
|
import { type LexicalCommand, type RangeSelection } from "lexical";
|
|
3
3
|
/**
|
|
4
|
-
* Whether `url` is a link the editor keeps:
|
|
4
|
+
* Whether `url` is a link the editor keeps and opens: a web or mail link, another app's link
|
|
5
|
+
* (`obsidian://…`), or a `peers://` link. Script, data and file links (`javascript:`, `data:`,
|
|
6
|
+
* `file:`, and the others the host refuses) aren't.
|
|
5
7
|
*
|
|
6
8
|
* @param url - The text to check.
|
|
7
9
|
*/
|
|
8
10
|
export declare function isLinkUrl(url: string): boolean;
|
|
9
11
|
/**
|
|
10
12
|
* What a typed link becomes: the URL as given when it's a web or mail link, `https://` before a
|
|
11
|
-
* bare domain (`example.com/page`), `mailto:` before an email address,
|
|
12
|
-
* else (
|
|
13
|
+
* bare domain (`example.com/page`), `mailto:` before an email address, another app's or a
|
|
14
|
+
* `peers://` link as given, or undefined for anything else (a refused scheme, a host and port
|
|
15
|
+
* with no scheme, or text with spaces).
|
|
13
16
|
*
|
|
14
17
|
* @param text - What the user typed or pasted as the link.
|
|
15
18
|
*/
|
|
@@ -30,8 +33,9 @@ export declare const OPEN_LINK_EDITOR_COMMAND: LexicalCommand<void>;
|
|
|
30
33
|
export declare function $selectedLink(selection: RangeSelection): LinkNode | null;
|
|
31
34
|
/**
|
|
32
35
|
* Links in the editor:
|
|
33
|
-
* - Clicking a
|
|
34
|
-
*
|
|
36
|
+
* - Clicking a link opens it through `openLink`: a web or mail link in the browser, another
|
|
37
|
+
* app's link in that app after asking, a `peers://` link inside Peers. A click that selects
|
|
38
|
+
* text in a link doesn't.
|
|
35
39
|
* - ⌘⇧K (Ctrl+Shift+K) or the toolbar's link button links the selected text, or edits the link
|
|
36
40
|
* the caret is in.
|
|
37
41
|
* - Pasting a URL over selected text links it.
|
|
@@ -15,27 +15,49 @@ const lexical_1 = require("lexical");
|
|
|
15
15
|
const react_1 = require("react");
|
|
16
16
|
const react_dom_1 = require("react-dom");
|
|
17
17
|
const host_shell_consumer_1 = require("../../host-shell/host-shell-consumer");
|
|
18
|
-
|
|
19
|
-
const LINK_SCHEMES = new Set(["http:", "https:", "mailto:"]);
|
|
18
|
+
const link_schemes_1 = require("../../links/link-schemes");
|
|
20
19
|
/**
|
|
21
|
-
* Whether `url` is a link the editor keeps:
|
|
20
|
+
* Whether `url` is a link the editor keeps and opens: a web or mail link, another app's link
|
|
21
|
+
* (`obsidian://…`), or a `peers://` link. Script, data and file links (`javascript:`, `data:`,
|
|
22
|
+
* `file:`, and the others the host refuses) aren't.
|
|
22
23
|
*
|
|
23
24
|
* @param url - The text to check.
|
|
24
25
|
*/
|
|
25
26
|
function isLinkUrl(url) {
|
|
27
|
+
return (0, link_schemes_1.linkKind)(url) !== undefined;
|
|
28
|
+
}
|
|
29
|
+
function parsesAsUrl(value) {
|
|
26
30
|
try {
|
|
27
|
-
|
|
31
|
+
new URL(value);
|
|
32
|
+
return true;
|
|
28
33
|
}
|
|
29
34
|
catch {
|
|
30
35
|
return false;
|
|
31
36
|
}
|
|
32
37
|
}
|
|
38
|
+
/** Whether a pasted destination should link the selection while keeping its label. */
|
|
39
|
+
function isPastedLinkUrl(text) {
|
|
40
|
+
const value = text.trim();
|
|
41
|
+
const kind = (0, link_schemes_1.linkKind)(value);
|
|
42
|
+
// A web path or a mail subject can contain a space.
|
|
43
|
+
if (kind === "web")
|
|
44
|
+
return parsesAsUrl(value);
|
|
45
|
+
// A short phone number pasted with its scheme is a destination, even if it resembles a port.
|
|
46
|
+
if (kind === "app" && /^(?:tel|sms):\d{1,5}$/i.test(value))
|
|
47
|
+
return true;
|
|
48
|
+
return normalizeLinkUrl(value) === value;
|
|
49
|
+
}
|
|
33
50
|
const EMAIL = /^[^\s@<>()[\]\\,;:"]+@[^\s@<>()[\]\\,;:"]+\.[a-z]{2,}$/i;
|
|
34
51
|
const BARE_DOMAIN = /^[\w-]+(\.[\w-]+)+(:\d+)?([/?#]\S*)?$/i;
|
|
52
|
+
/** A bare host and port, optionally followed by a path. */
|
|
53
|
+
const HOST_AND_PORT = /^[\w.-]+:\d{1,5}(\/|$)/;
|
|
54
|
+
/** A query or fragment may follow the port directly on a localhost address. */
|
|
55
|
+
const LOCALHOST_WITH_PORT = /^localhost:\d+(?:[/?#]|$)/i;
|
|
35
56
|
/**
|
|
36
57
|
* What a typed link becomes: the URL as given when it's a web or mail link, `https://` before a
|
|
37
|
-
* bare domain (`example.com/page`), `mailto:` before an email address,
|
|
38
|
-
* else (
|
|
58
|
+
* bare domain (`example.com/page`), `mailto:` before an email address, another app's or a
|
|
59
|
+
* `peers://` link as given, or undefined for anything else (a refused scheme, a host and port
|
|
60
|
+
* with no scheme, or text with spaces).
|
|
39
61
|
*
|
|
40
62
|
* @param text - What the user typed or pasted as the link.
|
|
41
63
|
*/
|
|
@@ -43,14 +65,15 @@ function normalizeLinkUrl(text) {
|
|
|
43
65
|
const value = text.trim();
|
|
44
66
|
if (!value || /\s/.test(value))
|
|
45
67
|
return undefined;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return undefined;
|
|
68
|
+
const kind = (0, link_schemes_1.linkKind)(value);
|
|
69
|
+
if (kind === "web")
|
|
70
|
+
return parsesAsUrl(value) ? value : undefined;
|
|
50
71
|
if (EMAIL.test(value))
|
|
51
72
|
return `mailto:${value}`;
|
|
52
73
|
if (BARE_DOMAIN.test(value))
|
|
53
74
|
return `https://${value}`;
|
|
75
|
+
if (kind && !HOST_AND_PORT.test(value) && !LOCALHOST_WITH_PORT.test(value))
|
|
76
|
+
return value;
|
|
54
77
|
return undefined;
|
|
55
78
|
}
|
|
56
79
|
/**
|
|
@@ -108,8 +131,9 @@ function popupFor(editor, link) {
|
|
|
108
131
|
}
|
|
109
132
|
/**
|
|
110
133
|
* Links in the editor:
|
|
111
|
-
* - Clicking a
|
|
112
|
-
*
|
|
134
|
+
* - Clicking a link opens it through `openLink`: a web or mail link in the browser, another
|
|
135
|
+
* app's link in that app after asking, a `peers://` link inside Peers. A click that selects
|
|
136
|
+
* text in a link doesn't.
|
|
113
137
|
* - ⌘⇧K (Ctrl+Shift+K) or the toolbar's link button links the selected text, or edits the link
|
|
114
138
|
* the caret is in.
|
|
115
139
|
* - Pasting a URL over selected text links it.
|
|
@@ -168,9 +192,6 @@ function LinksPlugin() {
|
|
|
168
192
|
const target = event.target;
|
|
169
193
|
if (!(target instanceof Node) || event.button !== 0)
|
|
170
194
|
return;
|
|
171
|
-
// A click that ends a drag selecting text in the link doesn't open it.
|
|
172
|
-
if (window.getSelection()?.isCollapsed === false)
|
|
173
|
-
return;
|
|
174
195
|
let url;
|
|
175
196
|
editor.read(() => {
|
|
176
197
|
const node = (0, lexical_1.$getNearestNodeFromDOMNode)(target);
|
|
@@ -181,7 +202,8 @@ function LinksPlugin() {
|
|
|
181
202
|
if (!url)
|
|
182
203
|
return;
|
|
183
204
|
event.preventDefault();
|
|
184
|
-
|
|
205
|
+
// A click that ends a selection still cancels navigation in the frame around the editor.
|
|
206
|
+
if (window.getSelection()?.isCollapsed !== false && isLinkUrl(url))
|
|
185
207
|
void (0, host_shell_consumer_1.openLink)(url);
|
|
186
208
|
};
|
|
187
209
|
return (0, utils_1.mergeRegister)(editor.registerRootListener((root, previous) => {
|
|
@@ -269,7 +291,7 @@ function LinksPlugin() {
|
|
|
269
291
|
}, { discrete: true });
|
|
270
292
|
close(true);
|
|
271
293
|
}, [editor, popup?.linkKey, close]);
|
|
272
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(LexicalLinkPlugin_1.LinkPlugin, { validateUrl:
|
|
294
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(LexicalLinkPlugin_1.LinkPlugin, { validateUrl: isPastedLinkUrl }), popup ? ((0, jsx_runtime_1.jsx)(LinkPopup, { popup: popup, popupRef: popupRef, onEdit: () => {
|
|
273
295
|
editor.read(() => {
|
|
274
296
|
const selection = (0, lexical_1.$getSelection)();
|
|
275
297
|
savedSelection.current = (0, lexical_1.$isRangeSelection)(selection) ? selection.clone() : null;
|
|
@@ -315,6 +337,13 @@ function LinkPopup(props) {
|
|
|
315
337
|
const style = { top: popup.rect.bottom + 4, left, maxWidth: POPUP_WIDTH };
|
|
316
338
|
// Buttons keep the editor's focus and selection.
|
|
317
339
|
const keepFocus = (event) => event.preventDefault();
|
|
340
|
+
const follow = (event) => {
|
|
341
|
+
if (event.button > 1)
|
|
342
|
+
return;
|
|
343
|
+
event.preventDefault();
|
|
344
|
+
if (isLinkUrl(popup.url))
|
|
345
|
+
void (0, host_shell_consumer_1.openLink)(popup.url);
|
|
346
|
+
};
|
|
318
347
|
return (0, react_dom_1.createPortal)((0, jsx_runtime_1.jsx)("div", { ref: popupRef, className: "peers-link-popup", style: style, "data-testid": "link-popup", children: popup.editing ? ((0, jsx_runtime_1.jsxs)("form", { className: "d-flex gap-1 align-items-center", onSubmit: (event) => {
|
|
319
348
|
event.preventDefault();
|
|
320
349
|
submit();
|
|
@@ -326,9 +355,5 @@ function LinkPopup(props) {
|
|
|
326
355
|
event.preventDefault();
|
|
327
356
|
props.onCancel();
|
|
328
357
|
}
|
|
329
|
-
} }), (0, jsx_runtime_1.jsx)("button", { type: "submit", className: "btn btn-sm btn-primary", title: "Save link", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-lg" }) })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-1 align-items-center", children: [(0, jsx_runtime_1.jsx)("a", { href: popup.url, className: "peers-link-popup-url text-truncate", title: popup.url, onMouseDown: keepFocus, onClick: (
|
|
330
|
-
event.preventDefault();
|
|
331
|
-
if (isLinkUrl(popup.url))
|
|
332
|
-
void (0, host_shell_consumer_1.openLink)(popup.url);
|
|
333
|
-
}, children: popup.url.replace(/^mailto:/, "") }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-1", title: "Edit link", "aria-label": "Edit link", onMouseDown: keepFocus, onClick: props.onEdit, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-pencil" }) }), popup.auto ? null : ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-1", title: "Remove link", "aria-label": "Remove link", onMouseDown: keepFocus, onClick: props.onRemove, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-x-lg" }) }))] })) }), document.body);
|
|
358
|
+
} }), (0, jsx_runtime_1.jsx)("button", { type: "submit", className: "btn btn-sm btn-primary", title: "Save link", children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-check-lg" }) })] })) : ((0, jsx_runtime_1.jsxs)("div", { className: "d-flex gap-1 align-items-center", children: [(0, jsx_runtime_1.jsx)("a", { href: popup.url, className: "peers-link-popup-url text-truncate", title: popup.url, onMouseDown: keepFocus, onClick: follow, onAuxClick: follow, children: popup.url.replace(/^mailto:/, "") }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-1", title: "Edit link", "aria-label": "Edit link", onMouseDown: keepFocus, onClick: props.onEdit, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-pencil" }) }), popup.auto ? null : ((0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-link p-1", title: "Remove link", "aria-label": "Remove link", onMouseDown: keepFocus, onClick: props.onRemove, children: (0, jsx_runtime_1.jsx)("i", { className: "bi bi-x-lg" }) }))] })) }), document.body);
|
|
334
359
|
}
|
|
@@ -47,6 +47,7 @@ const react_1 = __importDefault(require("react"));
|
|
|
47
47
|
const react_markdown_1 = __importStar(require("react-markdown"));
|
|
48
48
|
const remark_gfm_1 = __importDefault(require("remark-gfm"));
|
|
49
49
|
const host_shell_consumer_1 = require("../host-shell/host-shell-consumer");
|
|
50
|
+
const link_schemes_1 = require("../links/link-schemes");
|
|
50
51
|
const mention_chip_1 = require("../mentions/mention-chip");
|
|
51
52
|
/** The text in some rendered markdown children. */
|
|
52
53
|
function textOf(children) {
|
|
@@ -61,18 +62,30 @@ function textOf(children) {
|
|
|
61
62
|
})
|
|
62
63
|
.join("");
|
|
63
64
|
}
|
|
64
|
-
/**
|
|
65
|
+
/**
|
|
66
|
+
* A link: a mention becomes a chip, and any other link Peers opens goes through `openLink` (the
|
|
67
|
+
* browser for a web link, another app's after asking, a `peers://` link inside Peers).
|
|
68
|
+
*/
|
|
65
69
|
const LinkRenderer = (props) => {
|
|
66
70
|
const { href } = props;
|
|
67
71
|
const mention = href ? (0, peers_sdk_1.parseMentionUrl)(href) : undefined;
|
|
68
72
|
if (mention)
|
|
69
73
|
return (0, jsx_runtime_1.jsx)(mention_chip_1.MentionChip, { ...mention, label: textOf(props.children) });
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
74
|
+
const follow = (event) => {
|
|
75
|
+
if (event.button > 1 || href?.startsWith("#"))
|
|
76
|
+
return;
|
|
77
|
+
if (href && (0, link_schemes_1.linkKind)(href)) {
|
|
78
|
+
event.preventDefault();
|
|
79
|
+
void (0, host_shell_consumer_1.openLink)(href);
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
// Relative web paths still navigate within the page. A blanked or refused URL
|
|
83
|
+
// must not fall through to the browser, including a relative path on a file: page.
|
|
84
|
+
if (!href || (0, link_schemes_1.linkScheme)(href) || !["http:", "https:"].includes(event.currentTarget.protocol)) {
|
|
85
|
+
event.preventDefault();
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
return ((0, jsx_runtime_1.jsx)("a", { href: href, onClick: follow, onAuxClick: follow, children: props.children }));
|
|
76
89
|
};
|
|
77
90
|
/**
|
|
78
91
|
* An image. `` is a mention typed right after a `!` ("Thanks"),
|
|
@@ -134,7 +147,7 @@ const components = {
|
|
|
134
147
|
};
|
|
135
148
|
/** {@link mentionUrlTransform}'s implementation. */
|
|
136
149
|
function mentionUrlTransform(url) {
|
|
137
|
-
return (0, peers_sdk_1.parseMentionUrl)(url) ? url : (0, react_markdown_1.defaultUrlTransform)(url);
|
|
150
|
+
return (0, peers_sdk_1.parseMentionUrl)(url) || (0, link_schemes_1.linkKind)(url) ? url : (0, react_markdown_1.defaultUrlTransform)(url);
|
|
138
151
|
}
|
|
139
152
|
/** {@link MarkdownWithMentions}'s implementation. */
|
|
140
153
|
const MarkdownRender = ({ content, groupId, }) => ((0, jsx_runtime_1.jsx)(mention_chip_1.MentionGroupContext.Provider, { value: groupId, children: (0, jsx_runtime_1.jsx)("div", { className: "markdown", children: (0, jsx_runtime_1.jsx)(react_markdown_1.default, { remarkPlugins: [remark_gfm_1.default], urlTransform: mentionUrlTransform,
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
2
|
/**
|
|
3
|
-
* Keep
|
|
4
|
-
*
|
|
3
|
+
* Keep the links Peers opens (mentions, web and mail links, `peers://` links, and other apps'
|
|
4
|
+
* links, which ask before opening); every other URL gets react-markdown's default treatment,
|
|
5
|
+
* which blanks `javascript:` and other unsafe schemes in text other members wrote.
|
|
5
6
|
*/
|
|
6
7
|
export declare function mentionUrlTransform(url: string): string;
|
|
7
8
|
/**
|
|
8
9
|
* Render markdown (GitHub-flavored) with mentions (`[label](peers://<kind>/<id>)`, and the
|
|
9
|
-
* older `<$kind:Name:id>`) as chips showing each record's live title.
|
|
10
|
-
*
|
|
10
|
+
* older `<$kind:Name:id>`) as chips showing each record's live title. Links open through
|
|
11
|
+
* `openLink` instead of navigating the app window: web links in the browser, another app's link
|
|
12
|
+
* in that app after asking, a `peers://` link inside Peers.
|
|
11
13
|
*
|
|
12
14
|
* @param props.content - The markdown.
|
|
13
15
|
* @param props.groupId - The group the text belongs to: mentions resolve there first.
|
|
@@ -10,16 +10,18 @@ const lazy_module_1 = require("../lazy-module");
|
|
|
10
10
|
*/
|
|
11
11
|
const markdownRender = (0, lazy_module_1.lazyModule)(() => require("./markdown-render"));
|
|
12
12
|
/**
|
|
13
|
-
* Keep
|
|
14
|
-
*
|
|
13
|
+
* Keep the links Peers opens (mentions, web and mail links, `peers://` links, and other apps'
|
|
14
|
+
* links, which ask before opening); every other URL gets react-markdown's default treatment,
|
|
15
|
+
* which blanks `javascript:` and other unsafe schemes in text other members wrote.
|
|
15
16
|
*/
|
|
16
17
|
function mentionUrlTransform(url) {
|
|
17
18
|
return markdownRender().mentionUrlTransform(url);
|
|
18
19
|
}
|
|
19
20
|
/**
|
|
20
21
|
* Render markdown (GitHub-flavored) with mentions (`[label](peers://<kind>/<id>)`, and the
|
|
21
|
-
* older `<$kind:Name:id>`) as chips showing each record's live title.
|
|
22
|
-
*
|
|
22
|
+
* older `<$kind:Name:id>`) as chips showing each record's live title. Links open through
|
|
23
|
+
* `openLink` instead of navigating the app window: web links in the browser, another app's link
|
|
24
|
+
* in that app after asking, a `peers://` link inside Peers.
|
|
23
25
|
*
|
|
24
26
|
* @param props.content - The markdown.
|
|
25
27
|
* @param props.groupId - The group the text belongs to: mentions resolve there first.
|
|
@@ -7,17 +7,25 @@ export declare const hostShellContract: import("@peers-app/peers-sdk").IHostCont
|
|
|
7
7
|
/** Return the System Host Shell tools of the local host. */
|
|
8
8
|
export declare function hostShellTools(): Promise<IHostShellConsumer["tools"]>;
|
|
9
9
|
/**
|
|
10
|
-
* Open a
|
|
11
|
-
* unsupported host, a refused link scheme, a missing folder) are logged and
|
|
10
|
+
* Open a link with the app the OS has for it, or a local file or folder with the OS, without
|
|
11
|
+
* asking. Failures (an unsupported host, a refused link scheme, a missing folder) are logged and
|
|
12
|
+
* shown. For a link a person clicked, use {@link openLink}.
|
|
12
13
|
*
|
|
13
14
|
* @param target - Link or local path (`~` allowed).
|
|
14
15
|
*/
|
|
15
16
|
export declare function openOnHost(target: string): Promise<void>;
|
|
16
17
|
/**
|
|
17
|
-
* Open a
|
|
18
|
-
*
|
|
18
|
+
* Open a link the way Peers opens every link a person clicks. Package UIs use this.
|
|
19
|
+
* - A web or mail link (`http:`, `https:`, `mailto:`) opens in the browser or the mail app.
|
|
20
|
+
* - Another app's link (`obsidian://…`, `vscode://…`) opens in that app, after the user says yes:
|
|
21
|
+
* once per scheme on this device with "Always", or every time.
|
|
22
|
+
* - A `peers://` link opens inside Peers: a record's link (`peers://note/<id>`) opens the record,
|
|
23
|
+
* as its mention chip does.
|
|
19
24
|
*
|
|
20
|
-
*
|
|
25
|
+
* Anything else (a local path, `javascript:`, `file:` and the other refused schemes) is refused.
|
|
26
|
+
* Failures are logged and shown.
|
|
27
|
+
*
|
|
28
|
+
* @param url - The link.
|
|
21
29
|
*/
|
|
22
30
|
export declare function openLink(url: string): Promise<void>;
|
|
23
31
|
/**
|
|
@@ -8,6 +8,9 @@ exports.openInEditorOnHost = openInEditorOnHost;
|
|
|
8
8
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
9
9
|
const frame_protocol_1 = require("../isolated-screens/frame-protocol");
|
|
10
10
|
const frame_realm_1 = require("../isolated-screens/frame-realm");
|
|
11
|
+
const app_link_prompt_1 = require("../links/app-link-prompt");
|
|
12
|
+
const link_schemes_1 = require("../links/link-schemes");
|
|
13
|
+
const peers_links_1 = require("../links/peers-links");
|
|
11
14
|
/**
|
|
12
15
|
* Shared handle for System Host Shell on the local host. Calls name no data context, so the
|
|
13
16
|
* host runs them in the personal context, where the signed-in user has Self access.
|
|
@@ -18,8 +21,9 @@ async function hostShellTools() {
|
|
|
18
21
|
return (await exports.hostShellContract.get()).tools;
|
|
19
22
|
}
|
|
20
23
|
/**
|
|
21
|
-
* Open a
|
|
22
|
-
* unsupported host, a refused link scheme, a missing folder) are logged and
|
|
24
|
+
* Open a link with the app the OS has for it, or a local file or folder with the OS, without
|
|
25
|
+
* asking. Failures (an unsupported host, a refused link scheme, a missing folder) are logged and
|
|
26
|
+
* shown. For a link a person clicked, use {@link openLink}.
|
|
23
27
|
*
|
|
24
28
|
* @param target - Link or local path (`~` allowed).
|
|
25
29
|
*/
|
|
@@ -31,13 +35,18 @@ async function openOnHost(target) {
|
|
|
31
35
|
reportHostShellError(`Could not open ${target}`, error);
|
|
32
36
|
}
|
|
33
37
|
}
|
|
34
|
-
/** Link schemes {@link openLink} opens. */
|
|
35
|
-
const LINK_SCHEMES = new Set(["http:", "https:", "mailto:"]);
|
|
36
38
|
/**
|
|
37
|
-
* Open a
|
|
38
|
-
*
|
|
39
|
+
* Open a link the way Peers opens every link a person clicks. Package UIs use this.
|
|
40
|
+
* - A web or mail link (`http:`, `https:`, `mailto:`) opens in the browser or the mail app.
|
|
41
|
+
* - Another app's link (`obsidian://…`, `vscode://…`) opens in that app, after the user says yes:
|
|
42
|
+
* once per scheme on this device with "Always", or every time.
|
|
43
|
+
* - A `peers://` link opens inside Peers: a record's link (`peers://note/<id>`) opens the record,
|
|
44
|
+
* as its mention chip does.
|
|
39
45
|
*
|
|
40
|
-
*
|
|
46
|
+
* Anything else (a local path, `javascript:`, `file:` and the other refused schemes) is refused.
|
|
47
|
+
* Failures are logged and shown.
|
|
48
|
+
*
|
|
49
|
+
* @param url - The link.
|
|
41
50
|
*/
|
|
42
51
|
async function openLink(url) {
|
|
43
52
|
// An isolated screen asks its host, which opens it the same way.
|
|
@@ -46,18 +55,24 @@ async function openLink(url) {
|
|
|
46
55
|
await host.request(frame_protocol_1.FrameRequest.openLink, { url });
|
|
47
56
|
return;
|
|
48
57
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
58
|
+
const kind = (0, link_schemes_1.linkKind)(url);
|
|
59
|
+
const scheme = (0, link_schemes_1.linkScheme)(url);
|
|
60
|
+
if (!kind || !scheme) {
|
|
61
|
+
reportHostShellError(`Could not open ${url}`, new Error("Peers doesn't open this kind of link"));
|
|
62
|
+
return;
|
|
52
63
|
}
|
|
53
|
-
|
|
54
|
-
|
|
64
|
+
try {
|
|
65
|
+
if (kind === "peers") {
|
|
66
|
+
await (0, peers_links_1.openPeersLink)(url);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
if (kind === "app" && !(await (0, app_link_prompt_1.confirmAppLink)(url.trim(), scheme)))
|
|
70
|
+
return;
|
|
71
|
+
await openOnHost(url.trim());
|
|
55
72
|
}
|
|
56
|
-
|
|
57
|
-
reportHostShellError(
|
|
58
|
-
return;
|
|
73
|
+
catch (error) {
|
|
74
|
+
reportHostShellError("Could not open link", error);
|
|
59
75
|
}
|
|
60
|
-
await openOnHost(url);
|
|
61
76
|
}
|
|
62
77
|
/**
|
|
63
78
|
* Open a folder in a code editor (VS Code when installed), else with the OS.
|
|
@@ -8,6 +8,7 @@ const client_1 = require("react-dom/client");
|
|
|
8
8
|
const frame_commands_1 = require("../command-palette/frame-commands");
|
|
9
9
|
const globals_1 = require("../globals");
|
|
10
10
|
const hooks_1 = require("../hooks");
|
|
11
|
+
const link_schemes_1 = require("../links/link-schemes");
|
|
11
12
|
const global_overlays_1 = require("../root-layout/global-overlays");
|
|
12
13
|
const implement_piece_1 = require("../ui-contracts/implement-piece");
|
|
13
14
|
const piece_height_1 = require("../ui-contracts/piece-height");
|
|
@@ -326,31 +327,29 @@ async function handleInit(host, init) {
|
|
|
326
327
|
}
|
|
327
328
|
show({ ui, props: init.props, ...(init.widget ? { widget: true } : {}) });
|
|
328
329
|
}
|
|
329
|
-
/**
|
|
330
|
+
/** Route anchor activations through the host and leave file downloads to the frame. */
|
|
330
331
|
function installLinkHandling(host) {
|
|
331
332
|
document.addEventListener("click", (event) => {
|
|
332
333
|
if (event.defaultPrevented || event.button !== 0)
|
|
333
334
|
return;
|
|
334
335
|
const anchor = event.target?.closest?.("a[href]");
|
|
335
|
-
if (!anchor
|
|
336
|
+
if (!anchor)
|
|
337
|
+
return;
|
|
338
|
+
// Browsers may ignore download for another app's URL. Only leave actual file sources to it.
|
|
339
|
+
if (anchor.hasAttribute("download") &&
|
|
340
|
+
["blob:", "data:", "http:", "https:"].includes(anchor.protocol))
|
|
341
|
+
return;
|
|
342
|
+
event.preventDefault();
|
|
343
|
+
const href = anchor.getAttribute("href")?.trim();
|
|
344
|
+
if (!href)
|
|
336
345
|
return;
|
|
337
|
-
const href = anchor.getAttribute("href") ?? "";
|
|
338
346
|
if (href.startsWith("#")) {
|
|
339
|
-
event.preventDefault();
|
|
340
347
|
void host.request(frame_protocol_1.FrameRequest.navigate, { path: href.slice(1) }).catch(() => undefined);
|
|
341
348
|
return;
|
|
342
349
|
}
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
catch {
|
|
348
|
-
return;
|
|
349
|
-
}
|
|
350
|
-
// Others (`tel:`, `sms:`) are left to the browser, as the host only opens these.
|
|
351
|
-
if (["http:", "https:", "mailto:"].includes(url.protocol)) {
|
|
352
|
-
event.preventDefault();
|
|
353
|
-
void host.request(frame_protocol_1.FrameRequest.openLink, { url: anchor.href }).catch(() => undefined);
|
|
350
|
+
const url = (0, link_schemes_1.linkScheme)(href) ? href : anchor.href;
|
|
351
|
+
if (typeof url === "string" && (0, link_schemes_1.linkKind)(url)) {
|
|
352
|
+
void host.request(frame_protocol_1.FrameRequest.openLink, { url }).catch(() => undefined);
|
|
354
353
|
}
|
|
355
354
|
});
|
|
356
355
|
// A screen that navigates by setting `location.hash` navigates its tab.
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The question Peers asks before handing a link to another app (`obsidian://…`): once per scheme
|
|
3
|
+
* on each device when the user ticks "Always", every time otherwise.
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* The schemes this device opens in another app without asking, lowercased (`obsidian`), as the
|
|
7
|
+
* user allowed them with "Always open … links on this device".
|
|
8
|
+
*/
|
|
9
|
+
export declare function alwaysOpenSchemes(): Promise<string[]>;
|
|
10
|
+
/**
|
|
11
|
+
* Stop opening a scheme's links without asking on this device.
|
|
12
|
+
*
|
|
13
|
+
* @param scheme - The scheme, without its colon (`obsidian`).
|
|
14
|
+
*/
|
|
15
|
+
export declare function forgetAlwaysOpenScheme(scheme: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Ask whether to open another app's link, unless the user already said to always open its
|
|
18
|
+
* scheme on this device. Ticking "Always" remembers the scheme.
|
|
19
|
+
*
|
|
20
|
+
* @param url - The link (`obsidian://open?vault=…`).
|
|
21
|
+
* @param scheme - Its scheme, lowercased and without the colon (`obsidian`).
|
|
22
|
+
* @returns whether to open it
|
|
23
|
+
*/
|
|
24
|
+
export declare function confirmAppLink(url: string, scheme: string): Promise<boolean>;
|
|
25
|
+
/**
|
|
26
|
+
* Settings' list of the schemes this device opens in another app without asking, each with Ask
|
|
27
|
+
* again. Shows nothing until the user has ticked "Always" for one.
|
|
28
|
+
*/
|
|
29
|
+
export declare function AlwaysOpenLinksSetting(): import("react/jsx-runtime").JSX.Element | null;
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.alwaysOpenSchemes = alwaysOpenSchemes;
|
|
4
|
+
exports.forgetAlwaysOpenScheme = forgetAlwaysOpenScheme;
|
|
5
|
+
exports.confirmAppLink = confirmAppLink;
|
|
6
|
+
exports.AlwaysOpenLinksSetting = AlwaysOpenLinksSetting;
|
|
7
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
8
|
+
/**
|
|
9
|
+
* The question Peers asks before handing a link to another app (`obsidian://…`): once per scheme
|
|
10
|
+
* on each device when the user ticks "Always", every time otherwise.
|
|
11
|
+
*/
|
|
12
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
13
|
+
const react_1 = require("react");
|
|
14
|
+
const client_1 = require("react-dom/client");
|
|
15
|
+
const hooks_1 = require("../hooks");
|
|
16
|
+
const mention_chooser_1 = require("../mentions/mention-chooser");
|
|
17
|
+
/** Made on first use, so screens that never open another app's link don't load it. */
|
|
18
|
+
let allowedVar;
|
|
19
|
+
function allowedSchemesVar() {
|
|
20
|
+
allowedVar ??= (0, peers_sdk_1.deviceVar)("links:alwaysOpenSchemes", { defaultValue: [] });
|
|
21
|
+
return allowedVar;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* The schemes this device opens in another app without asking, lowercased (`obsidian`), as the
|
|
25
|
+
* user allowed them with "Always open … links on this device".
|
|
26
|
+
*/
|
|
27
|
+
async function alwaysOpenSchemes() {
|
|
28
|
+
const stored = allowedSchemesVar();
|
|
29
|
+
await stored.loadingPromise;
|
|
30
|
+
return stored() ?? [];
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Stop opening a scheme's links without asking on this device.
|
|
34
|
+
*
|
|
35
|
+
* @param scheme - The scheme, without its colon (`obsidian`).
|
|
36
|
+
*/
|
|
37
|
+
async function forgetAlwaysOpenScheme(scheme) {
|
|
38
|
+
const current = await alwaysOpenSchemes();
|
|
39
|
+
const key = scheme.toLowerCase();
|
|
40
|
+
if (current.includes(key))
|
|
41
|
+
allowedSchemesVar()(current.filter((s) => s !== key));
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Ask whether to open another app's link, unless the user already said to always open its
|
|
45
|
+
* scheme on this device. Ticking "Always" remembers the scheme.
|
|
46
|
+
*
|
|
47
|
+
* @param url - The link (`obsidian://open?vault=…`).
|
|
48
|
+
* @param scheme - Its scheme, lowercased and without the colon (`obsidian`).
|
|
49
|
+
* @returns whether to open it
|
|
50
|
+
*/
|
|
51
|
+
async function confirmAppLink(url, scheme) {
|
|
52
|
+
if ((await alwaysOpenSchemes()).includes(scheme))
|
|
53
|
+
return true;
|
|
54
|
+
const answer = await new Promise((resolve) => {
|
|
55
|
+
const host = document.createElement("div");
|
|
56
|
+
document.body.appendChild(host);
|
|
57
|
+
const root = (0, client_1.createRoot)(host);
|
|
58
|
+
const close = (open, always = false) => {
|
|
59
|
+
root.unmount();
|
|
60
|
+
host.remove();
|
|
61
|
+
resolve({ open, always });
|
|
62
|
+
};
|
|
63
|
+
root.render((0, jsx_runtime_1.jsx)(AppLinkPrompt, { url: url, scheme: scheme, onClose: close }));
|
|
64
|
+
});
|
|
65
|
+
if (answer.open && answer.always) {
|
|
66
|
+
const current = await alwaysOpenSchemes();
|
|
67
|
+
if (!current.includes(scheme))
|
|
68
|
+
allowedSchemesVar()([...current, scheme]);
|
|
69
|
+
}
|
|
70
|
+
return answer.open;
|
|
71
|
+
}
|
|
72
|
+
function AppLinkPrompt(props) {
|
|
73
|
+
const { url, scheme, onClose } = props;
|
|
74
|
+
const [always, setAlways] = (0, react_1.useState)(false);
|
|
75
|
+
// Cancel takes the focus, so a key pressed as the prompt appears (a screen can raise it while
|
|
76
|
+
// the person is typing) doesn't open the link.
|
|
77
|
+
const cancelButton = (0, react_1.useRef)(null);
|
|
78
|
+
(0, react_1.useEffect)(() => {
|
|
79
|
+
cancelButton.current?.focus();
|
|
80
|
+
// Tab and Escape go to the front dialog even after a click on its text, so a mention
|
|
81
|
+
// chooser opened over this prompt by an incoming link keeps its own keys.
|
|
82
|
+
return (0, mention_chooser_1.handleFrontDialogKeys)(() => cancelButton.current, () => onClose(false));
|
|
83
|
+
}, [onClose]);
|
|
84
|
+
return (
|
|
85
|
+
// The mention chooser's overlay and card: one look for the shell's small questions.
|
|
86
|
+
(0, jsx_runtime_1.jsx)("div", { className: "peers-mention-chooser peers-link-prompt", role: "dialog", "aria-modal": "true", "aria-label": "Open in another app?", onMouseDown: (e) => {
|
|
87
|
+
if (e.target === e.currentTarget)
|
|
88
|
+
onClose(false);
|
|
89
|
+
},
|
|
90
|
+
// Keys pressed here stay here, so the screen behind doesn't act on them too.
|
|
91
|
+
onKeyDown: (e) => e.stopPropagation(), children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-card", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-head", children: [(0, jsx_runtime_1.jsx)("strong", { children: "Open in another app?" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: () => onClose(false) })] }), (0, jsx_runtime_1.jsxs)("div", { className: "px-3 pb-3", children: [(0, jsx_runtime_1.jsx)("div", { className: "peers-link-prompt-url font-monospace small text-break mb-2", children: url }), (0, jsx_runtime_1.jsxs)("div", { className: "small text-body-secondary mb-3", children: ["Peers hands it to the app this device has for ", scheme, ": links."] }), (0, jsx_runtime_1.jsx)("div", { className: "form-check mb-3", children: (0, jsx_runtime_1.jsxs)("label", { className: "form-check-label", children: [(0, jsx_runtime_1.jsx)("input", { className: "form-check-input", type: "checkbox", checked: always, onChange: (e) => setAlways(e.target.checked) }), "Always open ", scheme, ": links on this device"] }) }), (0, jsx_runtime_1.jsxs)("div", { className: "d-flex justify-content-end gap-2", children: [(0, jsx_runtime_1.jsx)("button", { ref: cancelButton, type: "button", className: "btn btn-secondary", onClick: () => onClose(false), children: "Cancel" }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-primary", onClick: () => onClose(true, always), children: "Open" })] })] })] }) }));
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Settings' list of the schemes this device opens in another app without asking, each with Ask
|
|
95
|
+
* again. Shows nothing until the user has ticked "Always" for one.
|
|
96
|
+
*/
|
|
97
|
+
function AlwaysOpenLinksSetting() {
|
|
98
|
+
const [schemes] = (0, hooks_1.useObservable)(allowedSchemesVar());
|
|
99
|
+
if (!schemes?.length)
|
|
100
|
+
return null;
|
|
101
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "mb-4", children: [(0, jsx_runtime_1.jsx)("h6", { className: "mb-2", children: "Other apps' links" }), (0, jsx_runtime_1.jsx)("div", { className: "small text-muted mb-2", children: "These open in their app on this device without asking first." }), (0, jsx_runtime_1.jsx)("ul", { className: "list-group", children: schemes.map((scheme) => ((0, jsx_runtime_1.jsxs)("li", { className: "list-group-item d-flex align-items-center", children: [(0, jsx_runtime_1.jsxs)("span", { className: "font-monospace me-auto", children: [scheme, ":"] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-sm btn-outline-secondary", onClick: () => void forgetAlwaysOpenScheme(scheme), children: "Ask again" })] }, scheme))) })] }));
|
|
102
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which links Peers opens, and how: the one rule the editor, rendered markdown, isolated screens
|
|
3
|
+
* and {@link openLink} share. It follows the host's own (`classifyHostOpenTarget` in the SDK), so
|
|
4
|
+
* a link the UI offers to open is one the host will open.
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* How Peers opens a link:
|
|
8
|
+
* - `web`: a web or mail link, opened in the browser or the mail app straight away;
|
|
9
|
+
* - `app`: another app's link (`obsidian://…`, `vscode://…`), opened in that app after the user
|
|
10
|
+
* says yes once for its scheme on this device;
|
|
11
|
+
* - `peers`: a `peers://` link, opened inside Peers.
|
|
12
|
+
*/
|
|
13
|
+
export type LinkKind = "web" | "app" | "peers";
|
|
14
|
+
/**
|
|
15
|
+
* The scheme of a link, lowercased and without its colon (`obsidian` for `obsidian://open`), or
|
|
16
|
+
* undefined when the text doesn't start with one.
|
|
17
|
+
*
|
|
18
|
+
* @param url - The link.
|
|
19
|
+
*/
|
|
20
|
+
export declare function linkScheme(url: string): string | undefined;
|
|
21
|
+
/**
|
|
22
|
+
* How Peers opens `url` (see {@link LinkKind}), or undefined when it doesn't: no scheme (a
|
|
23
|
+
* relative link or a path), a one-letter scheme (a Windows drive: `C:\…`, or `C:notes.txt`,
|
|
24
|
+
* which Windows opens as a file), a refused scheme (`javascript:`, `file:`, `data:`, and the
|
|
25
|
+
* others in the SDK's `HOST_OPEN_REFUSED_SCHEMES`), nothing after the scheme (except `mailto:`, a
|
|
26
|
+
* blank mail draft), or a control character.
|
|
27
|
+
*
|
|
28
|
+
* @param url - The link.
|
|
29
|
+
*/
|
|
30
|
+
export declare function linkKind(url: string): LinkKind | undefined;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Which links Peers opens, and how: the one rule the editor, rendered markdown, isolated screens
|
|
4
|
+
* and {@link openLink} share. It follows the host's own (`classifyHostOpenTarget` in the SDK), so
|
|
5
|
+
* a link the UI offers to open is one the host will open.
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
exports.linkScheme = linkScheme;
|
|
9
|
+
exports.linkKind = linkKind;
|
|
10
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
11
|
+
const SCHEME = /^([a-z][a-z\d+.-]*):/i;
|
|
12
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: control characters are what it refuses
|
|
13
|
+
const CONTROL = /[\u0000-\u001f\u007f]/;
|
|
14
|
+
/**
|
|
15
|
+
* The scheme of a link, lowercased and without its colon (`obsidian` for `obsidian://open`), or
|
|
16
|
+
* undefined when the text doesn't start with one.
|
|
17
|
+
*
|
|
18
|
+
* @param url - The link.
|
|
19
|
+
*/
|
|
20
|
+
function linkScheme(url) {
|
|
21
|
+
return SCHEME.exec(url.trim())?.[1]?.toLowerCase();
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* How Peers opens `url` (see {@link LinkKind}), or undefined when it doesn't: no scheme (a
|
|
25
|
+
* relative link or a path), a one-letter scheme (a Windows drive: `C:\…`, or `C:notes.txt`,
|
|
26
|
+
* which Windows opens as a file), a refused scheme (`javascript:`, `file:`, `data:`, and the
|
|
27
|
+
* others in the SDK's `HOST_OPEN_REFUSED_SCHEMES`), nothing after the scheme (except `mailto:`, a
|
|
28
|
+
* blank mail draft), or a control character.
|
|
29
|
+
*
|
|
30
|
+
* @param url - The link.
|
|
31
|
+
*/
|
|
32
|
+
function linkKind(url) {
|
|
33
|
+
const value = url.trim();
|
|
34
|
+
const scheme = linkScheme(value);
|
|
35
|
+
if (!scheme || scheme.length === 1 || CONTROL.test(value))
|
|
36
|
+
return undefined;
|
|
37
|
+
if (value.length === scheme.length + 1 && scheme !== "mailto")
|
|
38
|
+
return undefined;
|
|
39
|
+
if (scheme === "peers")
|
|
40
|
+
return "peers";
|
|
41
|
+
if (peers_sdk_1.HOST_OPEN_URL_SCHEMES.includes(scheme))
|
|
42
|
+
return "web";
|
|
43
|
+
if (peers_sdk_1.HOST_OPEN_REFUSED_SCHEMES.includes(scheme))
|
|
44
|
+
return undefined;
|
|
45
|
+
return "app";
|
|
46
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `peers://` links: opening one inside Peers, and taking the ones the OS hands the desktop app (a
|
|
3
|
+
* link clicked in a browser, an email or another app such as Obsidian).
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Open a `peers://` link inside Peers:
|
|
7
|
+
* - a record's link (`peers://note/<id>`, `peers://task/<id>`: anything a mention names) opens
|
|
8
|
+
* the record, as clicking its chip does, asking which when it's in more than one group;
|
|
9
|
+
* - an invite (`peers://i#<token>`) goes to the Accept screen.
|
|
10
|
+
*
|
|
11
|
+
* Any other `peers://` link is shown as one Peers can't open.
|
|
12
|
+
*
|
|
13
|
+
* @param url - The link.
|
|
14
|
+
*/
|
|
15
|
+
export declare function openPeersLink(url: string): Promise<void>;
|
|
16
|
+
/**
|
|
17
|
+
* Take the `peers://` links the desktop app's main process hands this window: those it held
|
|
18
|
+
* while the window loaded, then each as it comes. An invite is kept for the Accept screen at
|
|
19
|
+
* once, signed in or not; any other link waits for {@link openIncomingLinksWith}. No-op outside
|
|
20
|
+
* the desktop app.
|
|
21
|
+
*
|
|
22
|
+
* @returns a function that stops listening
|
|
23
|
+
*/
|
|
24
|
+
export declare function listenForIncomingLinks(): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Open incoming links with `open`: the ones waiting now (in this window, across reloads), and
|
|
27
|
+
* each one after. The signed-in app calls it once it has loaded, so a link that launched Peers,
|
|
28
|
+
* or came while signing in, opens then.
|
|
29
|
+
*
|
|
30
|
+
* @param open - Opens one link.
|
|
31
|
+
* @returns a function that stops; links wait again until the next call
|
|
32
|
+
*/
|
|
33
|
+
export declare function openIncomingLinksWith(open: (url: string) => void): () => void;
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* `peers://` links: opening one inside Peers, and taking the ones the OS hands the desktop app (a
|
|
4
|
+
* link clicked in a browser, an email or another app such as Obsidian).
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.openPeersLink = openPeersLink;
|
|
8
|
+
exports.listenForIncomingLinks = listenForIncomingLinks;
|
|
9
|
+
exports.openIncomingLinksWith = openIncomingLinksWith;
|
|
10
|
+
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
11
|
+
const mentions_client_1 = require("../mentions/mentions-client");
|
|
12
|
+
const invite_capture_1 = require("../screens/invites/invite-capture");
|
|
13
|
+
/**
|
|
14
|
+
* Open a `peers://` link inside Peers:
|
|
15
|
+
* - a record's link (`peers://note/<id>`, `peers://task/<id>`: anything a mention names) opens
|
|
16
|
+
* the record, as clicking its chip does, asking which when it's in more than one group;
|
|
17
|
+
* - an invite (`peers://i#<token>`) goes to the Accept screen.
|
|
18
|
+
*
|
|
19
|
+
* Any other `peers://` link is shown as one Peers can't open.
|
|
20
|
+
*
|
|
21
|
+
* @param url - The link.
|
|
22
|
+
*/
|
|
23
|
+
async function openPeersLink(url) {
|
|
24
|
+
const token = (0, invite_capture_1.inviteTokenFromUrl)(url);
|
|
25
|
+
if (token) {
|
|
26
|
+
(0, invite_capture_1.stashPendingInvite)(token);
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
const ref = (0, peers_sdk_1.parseMentionUrl)(url.trim().replace(/^peers:/i, "peers:"));
|
|
30
|
+
if (ref) {
|
|
31
|
+
await (0, mentions_client_1.openMention)(ref);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
console.warn("Peers can't open this link:", url);
|
|
35
|
+
if (typeof window !== "undefined" && typeof window.alert === "function") {
|
|
36
|
+
window.alert(`Peers can't open this link: ${url}`);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
/** The IPC channel the desktop app's main process sends `peers://` links on. */
|
|
40
|
+
const OPEN_URL_CHANNEL = "peers-open-url";
|
|
41
|
+
/** Sent once this window listens, so the main process sends the links it was holding. */
|
|
42
|
+
const OPEN_URL_READY_CHANNEL = "peers-open-url:ready";
|
|
43
|
+
/**
|
|
44
|
+
* Links that came before the signed-in app could open them, kept in sessionStorage as invites
|
|
45
|
+
* are, so the reload that signing in, creating an account or pairing does doesn't lose them.
|
|
46
|
+
*/
|
|
47
|
+
const WAITING_LINKS_KEY = "peers.waitingLinks";
|
|
48
|
+
/** The most links kept waiting; older ones go first. */
|
|
49
|
+
const MAX_WAITING = 20;
|
|
50
|
+
let opener;
|
|
51
|
+
function readWaiting(consume) {
|
|
52
|
+
try {
|
|
53
|
+
const raw = sessionStorage.getItem(WAITING_LINKS_KEY);
|
|
54
|
+
if (raw === null)
|
|
55
|
+
return [];
|
|
56
|
+
if (consume)
|
|
57
|
+
sessionStorage.removeItem(WAITING_LINKS_KEY);
|
|
58
|
+
const stored = JSON.parse(raw);
|
|
59
|
+
if (!Array.isArray(stored))
|
|
60
|
+
return [];
|
|
61
|
+
const links = stored.filter((url) => typeof url === "string" && /^peers:\/\//i.test(url));
|
|
62
|
+
return links.length > MAX_WAITING ? links.slice(-MAX_WAITING) : links;
|
|
63
|
+
}
|
|
64
|
+
catch {
|
|
65
|
+
return [];
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
function queueLink(url) {
|
|
69
|
+
try {
|
|
70
|
+
const urls = readWaiting(false);
|
|
71
|
+
urls.push(url);
|
|
72
|
+
sessionStorage.setItem(WAITING_LINKS_KEY, JSON.stringify(urls.slice(-MAX_WAITING)));
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// An unavailable store cannot hold a link across sign-in.
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Take the `peers://` links the desktop app's main process hands this window: those it held
|
|
80
|
+
* while the window loaded, then each as it comes. An invite is kept for the Accept screen at
|
|
81
|
+
* once, signed in or not; any other link waits for {@link openIncomingLinksWith}. No-op outside
|
|
82
|
+
* the desktop app.
|
|
83
|
+
*
|
|
84
|
+
* @returns a function that stops listening
|
|
85
|
+
*/
|
|
86
|
+
function listenForIncomingLinks() {
|
|
87
|
+
const ipc = window.ipcRenderer;
|
|
88
|
+
if (!ipc)
|
|
89
|
+
return () => { };
|
|
90
|
+
ipc.on(OPEN_URL_CHANNEL, (_event, url) => {
|
|
91
|
+
if (typeof url !== "string")
|
|
92
|
+
return;
|
|
93
|
+
const token = (0, invite_capture_1.inviteTokenFromUrl)(url);
|
|
94
|
+
if (token) {
|
|
95
|
+
(0, invite_capture_1.stashPendingInvite)(token);
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
if (opener)
|
|
99
|
+
opener(url);
|
|
100
|
+
else
|
|
101
|
+
queueLink(url);
|
|
102
|
+
});
|
|
103
|
+
ipc.send(OPEN_URL_READY_CHANNEL);
|
|
104
|
+
return () => ipc.removeAllListeners(OPEN_URL_CHANNEL);
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Open incoming links with `open`: the ones waiting now (in this window, across reloads), and
|
|
108
|
+
* each one after. The signed-in app calls it once it has loaded, so a link that launched Peers,
|
|
109
|
+
* or came while signing in, opens then.
|
|
110
|
+
*
|
|
111
|
+
* @param open - Opens one link.
|
|
112
|
+
* @returns a function that stops; links wait again until the next call
|
|
113
|
+
*/
|
|
114
|
+
function openIncomingLinksWith(open) {
|
|
115
|
+
if (!("ipcRenderer" in window))
|
|
116
|
+
return () => { };
|
|
117
|
+
opener = open;
|
|
118
|
+
for (const url of readWaiting(true))
|
|
119
|
+
open(url);
|
|
120
|
+
return () => {
|
|
121
|
+
if (opener === open)
|
|
122
|
+
opener = undefined;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
@@ -7,3 +7,15 @@ import type { IMentionPlace } from "@peers-app/peers-sdk";
|
|
|
7
7
|
* @returns the place picked, or `undefined` when the user closed the chooser
|
|
8
8
|
*/
|
|
9
9
|
export declare function chooseMentionPlace(places: IMentionPlace[]): Promise<IMentionPlace | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* Give Tab and Escape to the front one of the shell's small dialogs (this chooser, and the
|
|
12
|
+
* app-link prompt that shares its overlay), even after a click on its text has moved focus to
|
|
13
|
+
* the page. Tab and Shift+Tab go round its buttons and inputs, so they never reach a dialog it
|
|
14
|
+
* covers (whose button would act on a choice the person can't see) or the screen behind. Escape
|
|
15
|
+
* closes it alone.
|
|
16
|
+
*
|
|
17
|
+
* @param inside - An element of this dialog, so it can tell whether it is the front one.
|
|
18
|
+
* @param onEscape - Closes this dialog.
|
|
19
|
+
* @returns a function that stops listening
|
|
20
|
+
*/
|
|
21
|
+
export declare function handleFrontDialogKeys(inside: () => Element | null, onEscape: () => void): () => void;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.chooseMentionPlace = chooseMentionPlace;
|
|
4
|
+
exports.handleFrontDialogKeys = handleFrontDialogKeys;
|
|
4
5
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
6
|
const react_1 = require("react");
|
|
6
7
|
const client_1 = require("react-dom/client");
|
|
@@ -25,28 +26,62 @@ function chooseMentionPlace(places) {
|
|
|
25
26
|
root.render((0, jsx_runtime_1.jsx)(MentionChooser, { places: places, onClose: close }));
|
|
26
27
|
});
|
|
27
28
|
}
|
|
29
|
+
/** The overlay the chooser and the app-link prompt share; the newest open one is last. */
|
|
30
|
+
const DIALOG_CLASS = "peers-mention-chooser";
|
|
31
|
+
/**
|
|
32
|
+
* Give Tab and Escape to the front one of the shell's small dialogs (this chooser, and the
|
|
33
|
+
* app-link prompt that shares its overlay), even after a click on its text has moved focus to
|
|
34
|
+
* the page. Tab and Shift+Tab go round its buttons and inputs, so they never reach a dialog it
|
|
35
|
+
* covers (whose button would act on a choice the person can't see) or the screen behind. Escape
|
|
36
|
+
* closes it alone.
|
|
37
|
+
*
|
|
38
|
+
* @param inside - An element of this dialog, so it can tell whether it is the front one.
|
|
39
|
+
* @param onEscape - Closes this dialog.
|
|
40
|
+
* @returns a function that stops listening
|
|
41
|
+
*/
|
|
42
|
+
function handleFrontDialogKeys(inside, onEscape) {
|
|
43
|
+
const onKey = (e) => {
|
|
44
|
+
if (e.defaultPrevented || (e.key !== "Tab" && e.key !== "Escape"))
|
|
45
|
+
return;
|
|
46
|
+
if (e.key === "Tab" && (e.ctrlKey || e.metaKey))
|
|
47
|
+
return;
|
|
48
|
+
// Every open dialog listens; only the front one acts.
|
|
49
|
+
const dialogs = document.getElementsByClassName(DIALOG_CLASS);
|
|
50
|
+
const front = dialogs[dialogs.length - 1];
|
|
51
|
+
if (!front?.contains(inside()))
|
|
52
|
+
return;
|
|
53
|
+
if (e.key === "Escape") {
|
|
54
|
+
e.stopImmediatePropagation();
|
|
55
|
+
onEscape();
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const controls = Array.from(front.querySelectorAll("button, input"));
|
|
59
|
+
const active = document.activeElement;
|
|
60
|
+
const index = active instanceof HTMLElement ? controls.indexOf(active) : -1;
|
|
61
|
+
const next = e.shiftKey
|
|
62
|
+
? (controls[index - 1] ?? controls[controls.length - 1])
|
|
63
|
+
: (controls[index + 1] ?? controls[0]);
|
|
64
|
+
if (!next)
|
|
65
|
+
return;
|
|
66
|
+
e.preventDefault();
|
|
67
|
+
e.stopImmediatePropagation();
|
|
68
|
+
next.focus();
|
|
69
|
+
};
|
|
70
|
+
window.addEventListener("keydown", onKey, true);
|
|
71
|
+
return () => window.removeEventListener("keydown", onKey, true);
|
|
72
|
+
}
|
|
28
73
|
function MentionChooser(props) {
|
|
29
74
|
const { places, onClose } = props;
|
|
30
75
|
const first = (0, react_1.useRef)(null);
|
|
31
76
|
(0, react_1.useEffect)(() => {
|
|
32
77
|
first.current?.focus();
|
|
33
|
-
|
|
34
|
-
const onKey = (e) => {
|
|
35
|
-
if (e.key === "Escape")
|
|
36
|
-
onClose();
|
|
37
|
-
};
|
|
38
|
-
window.addEventListener("keydown", onKey);
|
|
39
|
-
return () => window.removeEventListener("keydown", onKey);
|
|
78
|
+
return handleFrontDialogKeys(() => first.current, () => onClose());
|
|
40
79
|
}, [onClose]);
|
|
41
|
-
return ((0, jsx_runtime_1.jsx)("div", { className:
|
|
80
|
+
return ((0, jsx_runtime_1.jsx)("div", { className: DIALOG_CLASS, role: "dialog", "aria-modal": "true", "aria-label": "Which one?", onMouseDown: (e) => {
|
|
42
81
|
if (e.target === e.currentTarget)
|
|
43
82
|
onClose();
|
|
44
83
|
},
|
|
45
84
|
// Keys pressed in the chooser stay in it, so the screen behind doesn't act on them too
|
|
46
85
|
// (Tasks moves its selection on the arrow keys and closes the open task on Escape).
|
|
47
|
-
onKeyDown: (e) => {
|
|
48
|
-
e.stopPropagation();
|
|
49
|
-
if (e.key === "Escape")
|
|
50
|
-
onClose();
|
|
51
|
-
}, children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-card", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-head", children: [(0, jsx_runtime_1.jsxs)("span", { children: ["This is in ", places.length, " places. Which one?"] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: () => onClose() })] }), (0, jsx_runtime_1.jsx)("div", { className: "list-group list-group-flush", children: places.map((place, index) => ((0, jsx_runtime_1.jsxs)("button", { ref: index === 0 ? first : undefined, type: "button", className: "list-group-item list-group-item-action", onClick: () => onClose(place), children: [(0, jsx_runtime_1.jsxs)("div", { className: place.done ? "peers-mention-done" : undefined, children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: place.iconClassName, fallback: "bi:link-45deg", className: "me-1" }), place.title || place.kindLabel] }), (0, jsx_runtime_1.jsx)("small", { className: "text-body-secondary", children: [place.groupName, place.packageName, place.status].filter(Boolean).join(" · ") })] }, `${place.groupId ?? ""}:${place.packageId ?? ""}`))) })] }) }));
|
|
86
|
+
onKeyDown: (e) => e.stopPropagation(), children: (0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-card", children: [(0, jsx_runtime_1.jsxs)("div", { className: "peers-mention-chooser-head", children: [(0, jsx_runtime_1.jsxs)("span", { children: ["This is in ", places.length, " places. Which one?"] }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn-close", "aria-label": "Close", onClick: () => onClose() })] }), (0, jsx_runtime_1.jsx)("div", { className: "list-group list-group-flush", children: places.map((place, index) => ((0, jsx_runtime_1.jsxs)("button", { ref: index === 0 ? first : undefined, type: "button", className: "list-group-item list-group-item-action", onClick: () => onClose(place), children: [(0, jsx_runtime_1.jsxs)("div", { className: place.done ? "peers-mention-done" : undefined, children: [(0, jsx_runtime_1.jsx)(icon_1.Icon, { icon: place.iconClassName, fallback: "bi:link-45deg", className: "me-1" }), place.title || place.kindLabel] }), (0, jsx_runtime_1.jsx)("small", { className: "text-body-secondary", children: [place.groupName, place.packageName, place.status].filter(Boolean).join(" · ") })] }, `${place.groupId ?? ""}:${place.packageId ?? ""}`))) })] }) }));
|
|
52
87
|
}
|
|
@@ -22,6 +22,7 @@ const globals_1 = require("../globals");
|
|
|
22
22
|
const hooks_1 = require("../hooks");
|
|
23
23
|
const config_1 = require("../isolated-screens/config");
|
|
24
24
|
const global_widgets_1 = require("../isolated-screens/global-widgets");
|
|
25
|
+
const peers_links_1 = require("../links/peers-links");
|
|
25
26
|
const identity_ipc_1 = require("../screens/device-pairing/identity-ipc");
|
|
26
27
|
const identity_routes_1 = require("../screens/identity/identity-routes");
|
|
27
28
|
const invite_capture_1 = require("../screens/invites/invite-capture");
|
|
@@ -56,7 +57,7 @@ function RootLayoutHost() {
|
|
|
56
57
|
// finishes; signed-in captures route straight to the Accept screen.
|
|
57
58
|
const onHashChange = () => (0, invite_capture_1.captureInviteFromLocation)();
|
|
58
59
|
window.addEventListener("hashchange", onHashChange);
|
|
59
|
-
const stopOpenUrl = (0,
|
|
60
|
+
const stopOpenUrl = (0, peers_links_1.listenForIncomingLinks)();
|
|
60
61
|
const sub = invite_capture_1.inviteCaptured.subscribe(() => {
|
|
61
62
|
if (userIdRef.current && (0, invite_capture_1.peekPendingInvite)()) {
|
|
62
63
|
(0, globals_1.mainContentPath)(identity_routes_1.IDENTITY_ACCEPT_PATH);
|
|
@@ -107,6 +108,14 @@ function RootLayoutBootstrap(props) {
|
|
|
107
108
|
const [_colorMode] = (0, hooks_1.useObservable)(color_mode_dropdown_1.colorMode);
|
|
108
109
|
const [layoutId] = (0, hooks_1.useObservable)(root_layout_state_1.selectedRootLayoutId);
|
|
109
110
|
const [overlays] = (0, hooks_1.useObservable)(global_overlays_1.globalOverlays);
|
|
111
|
+
// peers:// links the OS handed the desktop app (one that launched it, too) open once loaded.
|
|
112
|
+
(0, react_1.useEffect)(() => {
|
|
113
|
+
if (!loaded)
|
|
114
|
+
return;
|
|
115
|
+
return (0, peers_links_1.openIncomingLinksWith)((url) => {
|
|
116
|
+
(0, peers_links_1.openPeersLink)(url).catch((error) => console.warn("Could not open", url, error));
|
|
117
|
+
});
|
|
118
|
+
}, [loaded]);
|
|
110
119
|
// Check if we should show the welcome modal after loading
|
|
111
120
|
(0, react_1.useEffect)(() => {
|
|
112
121
|
if (loaded && !(0, peers_sdk_1.hasShownWelcomeModal)()) {
|
|
@@ -51,11 +51,13 @@ function AcceptInvite(props) {
|
|
|
51
51
|
const [busy, setBusy] = (0, react_1.useState)(false);
|
|
52
52
|
const [error, setError] = (0, react_1.useState)("");
|
|
53
53
|
const runPreview = (0, react_1.useCallback)(async (token) => {
|
|
54
|
+
setScanning(false);
|
|
54
55
|
setError("");
|
|
55
56
|
setBusy(true);
|
|
56
57
|
try {
|
|
57
58
|
const tools = await (0, invites_ipc_1.inviteTools)();
|
|
58
59
|
const response = await tools.previewInvite({ token });
|
|
60
|
+
setResult(undefined);
|
|
59
61
|
setTrustLevel(undefined);
|
|
60
62
|
setPreview(response.preview);
|
|
61
63
|
setText(token);
|
|
@@ -150,10 +152,7 @@ function AcceptInvite(props) {
|
|
|
150
152
|
return (0, jsx_runtime_1.jsx)(ResultPanel, { result: result, preview: preview, onDone: done });
|
|
151
153
|
}
|
|
152
154
|
if (scanning) {
|
|
153
|
-
return ((0, jsx_runtime_1.jsxs)("div", { className: "text-center", children: [(0, jsx_runtime_1.jsx)(qr_scanner_1.QrScanner, { onScan: (scanned) => {
|
|
154
|
-
setScanning(false);
|
|
155
|
-
void runPreview(scanned);
|
|
156
|
-
}, onError: (message) => {
|
|
155
|
+
return ((0, jsx_runtime_1.jsxs)("div", { className: "text-center", children: [(0, jsx_runtime_1.jsx)(qr_scanner_1.QrScanner, { onScan: (scanned) => void runPreview(scanned), onError: (message) => {
|
|
157
156
|
setScanning(false);
|
|
158
157
|
setError(message);
|
|
159
158
|
} }), (0, jsx_runtime_1.jsx)("button", { type: "button", className: "btn btn-outline-secondary mt-3", onClick: () => setScanning(false), children: "Cancel" })] }));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Captures an inbound invite token from the page URL or a desktop `peers://`
|
|
3
|
-
* and holds it (tab-scoped) until the signed-in UI can route to the Accept screen.
|
|
2
|
+
* Captures an inbound invite token from the page URL or a desktop `peers://` link (taken by
|
|
3
|
+
* `links/peers-links.ts`) and holds it (tab-scoped) until the signed-in UI can route to the Accept screen.
|
|
4
4
|
*
|
|
5
5
|
* Tokens travel only in URL fragments and are stripped from the address bar immediately so
|
|
6
6
|
* startup route restoration never persists them.
|
|
@@ -25,8 +25,3 @@ export declare function consumePendingInvite(storage?: Storage): string | undefi
|
|
|
25
25
|
* Safe to call repeatedly; returns the captured token when one was present.
|
|
26
26
|
*/
|
|
27
27
|
export declare function captureInviteFromLocation(locationLike?: Pick<Location, "href" | "pathname" | "search">, historyLike?: Pick<History, "replaceState" | "state">, storage?: Storage): string | undefined;
|
|
28
|
-
/**
|
|
29
|
-
* Listen for `peers://` links forwarded by the Electron main process (`peers-open-url`).
|
|
30
|
-
* No-op outside Electron. Returns an unsubscribe function.
|
|
31
|
-
*/
|
|
32
|
-
export declare function listenForOpenUrlInvites(): () => void;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
/**
|
|
3
|
-
* Captures an inbound invite token from the page URL or a desktop `peers://`
|
|
4
|
-
* and holds it (tab-scoped) until the signed-in UI can route to the Accept screen.
|
|
3
|
+
* Captures an inbound invite token from the page URL or a desktop `peers://` link (taken by
|
|
4
|
+
* `links/peers-links.ts`) and holds it (tab-scoped) until the signed-in UI can route to the Accept screen.
|
|
5
5
|
*
|
|
6
6
|
* Tokens travel only in URL fragments and are stripped from the address bar immediately so
|
|
7
7
|
* startup route restoration never persists them.
|
|
@@ -13,7 +13,6 @@ exports.stashPendingInvite = stashPendingInvite;
|
|
|
13
13
|
exports.peekPendingInvite = peekPendingInvite;
|
|
14
14
|
exports.consumePendingInvite = consumePendingInvite;
|
|
15
15
|
exports.captureInviteFromLocation = captureInviteFromLocation;
|
|
16
|
-
exports.listenForOpenUrlInvites = listenForOpenUrlInvites;
|
|
17
16
|
const peers_sdk_1 = require("@peers-app/peers-sdk");
|
|
18
17
|
/** sessionStorage key for a captured token awaiting the Accept screen. */
|
|
19
18
|
exports.PENDING_INVITE_STORAGE_KEY = "peers.pendingInviteToken";
|
|
@@ -31,7 +30,7 @@ function inviteTokenFromUrl(url) {
|
|
|
31
30
|
const before = url.slice(0, hash);
|
|
32
31
|
const fragment = url.slice(hash + 1);
|
|
33
32
|
const isInviteFragment = fragment.startsWith("invite=");
|
|
34
|
-
const isLandingPage =
|
|
33
|
+
const isLandingPage = /^\s*peers:\/\/i\/?$/i.test(before) || /^https?:\/\/[^/]+\/i\/?$/.test(before);
|
|
35
34
|
if (!isInviteFragment && !isLandingPage) {
|
|
36
35
|
return undefined;
|
|
37
36
|
}
|
|
@@ -45,7 +44,11 @@ function inviteTokenFromUrl(url) {
|
|
|
45
44
|
/** Store a token for the Accept screen and notify listeners. */
|
|
46
45
|
function stashPendingInvite(token, storage = sessionStorage) {
|
|
47
46
|
storage.setItem(exports.PENDING_INVITE_STORAGE_KEY, token);
|
|
48
|
-
|
|
47
|
+
// Reopening the same invitation is another request to show Accept.
|
|
48
|
+
if ((0, exports.inviteCaptured)() === token)
|
|
49
|
+
exports.inviteCaptured.notifySubscribers();
|
|
50
|
+
else
|
|
51
|
+
(0, exports.inviteCaptured)(token);
|
|
49
52
|
}
|
|
50
53
|
/** Read the stored token without consuming it. */
|
|
51
54
|
function peekPendingInvite(storage = sessionStorage) {
|
|
@@ -70,23 +73,3 @@ function captureInviteFromLocation(locationLike = window.location, historyLike =
|
|
|
70
73
|
stashPendingInvite(token, storage);
|
|
71
74
|
return token;
|
|
72
75
|
}
|
|
73
|
-
/**
|
|
74
|
-
* Listen for `peers://` links forwarded by the Electron main process (`peers-open-url`).
|
|
75
|
-
* No-op outside Electron. Returns an unsubscribe function.
|
|
76
|
-
*/
|
|
77
|
-
function listenForOpenUrlInvites() {
|
|
78
|
-
const ipc = window.ipcRenderer;
|
|
79
|
-
if (!ipc) {
|
|
80
|
-
return () => { };
|
|
81
|
-
}
|
|
82
|
-
ipc.on("peers-open-url", (_event, url) => {
|
|
83
|
-
if (typeof url !== "string") {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
const token = inviteTokenFromUrl(url);
|
|
87
|
-
if (token) {
|
|
88
|
-
stashPendingInvite(token);
|
|
89
|
-
}
|
|
90
|
-
});
|
|
91
|
-
return () => ipc.removeAllListeners("peers-open-url");
|
|
92
|
-
}
|
|
@@ -43,6 +43,7 @@ const tabs_1 = require("../../components/tabs");
|
|
|
43
43
|
const tooltip_1 = require("../../components/tooltip");
|
|
44
44
|
const globals = __importStar(require("../../globals"));
|
|
45
45
|
const hooks_1 = require("../../hooks");
|
|
46
|
+
const app_link_prompt_1 = require("../../links/app-link-prompt");
|
|
46
47
|
const layout_picker_1 = require("../../root-layout/layout-picker");
|
|
47
48
|
const identity_ipc_1 = require("../device-pairing/identity-ipc");
|
|
48
49
|
const context_files_1 = require("../files/context-files");
|
|
@@ -73,6 +74,7 @@ const SettingsPage = () => {
|
|
|
73
74
|
},
|
|
74
75
|
{
|
|
75
76
|
name: "Advanced",
|
|
77
|
+
lazy: true,
|
|
76
78
|
content: (0, jsx_runtime_1.jsx)(AdvancedSettingsTab, {}),
|
|
77
79
|
},
|
|
78
80
|
{
|
|
@@ -93,7 +95,7 @@ const AppearanceSettingsTab = () => {
|
|
|
93
95
|
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h5", { className: "mb-3", children: "Appearance" }), (0, jsx_runtime_1.jsx)("div", { className: "mb-3", children: (0, jsx_runtime_1.jsx)(color_mode_dropdown_1.ColorModeDropdown, {}) }), (0, jsx_runtime_1.jsx)("div", { className: "mb-3", children: (0, jsx_runtime_1.jsx)(layout_picker_1.LayoutPicker, {}) })] }));
|
|
94
96
|
};
|
|
95
97
|
const AdvancedSettingsTab = () => {
|
|
96
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h5", { className: "mb-3", children: "Advanced Settings" }), (0, jsx_runtime_1.jsx)(PackagesRootDirectory, {}), (0, jsx_runtime_1.jsx)(ReloadPackagesOnPageRefresh, {}), (0, jsx_runtime_1.jsx)(ResetDeviceSyncInfos, {}), (0, jsx_runtime_1.jsx)(DeleteLocalDatabase, {}), (0, jsx_runtime_1.jsx)(CleanupOldDataDir, {}), (0, jsx_runtime_1.jsx)(ResetChangeTracking, {})] }));
|
|
98
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("h5", { className: "mb-3", children: "Advanced Settings" }), (0, jsx_runtime_1.jsx)(app_link_prompt_1.AlwaysOpenLinksSetting, {}), (0, jsx_runtime_1.jsx)(PackagesRootDirectory, {}), (0, jsx_runtime_1.jsx)(ReloadPackagesOnPageRefresh, {}), (0, jsx_runtime_1.jsx)(ResetDeviceSyncInfos, {}), (0, jsx_runtime_1.jsx)(DeleteLocalDatabase, {}), (0, jsx_runtime_1.jsx)(CleanupOldDataDir, {}), (0, jsx_runtime_1.jsx)(ResetChangeTracking, {})] }));
|
|
97
99
|
};
|
|
98
100
|
const ProfileSection = () => {
|
|
99
101
|
const me = (0, hooks_1.usePromise)(async () => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peers-app/peers-ui",
|
|
3
|
-
"version": "0.34.
|
|
3
|
+
"version": "0.34.12",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/peers-app/peers-ui.git"
|
|
@@ -36,7 +36,7 @@
|
|
|
36
36
|
"lint:fix": "biome check --write ."
|
|
37
37
|
},
|
|
38
38
|
"peerDependencies": {
|
|
39
|
-
"@peers-app/peers-sdk": "^0.34.
|
|
39
|
+
"@peers-app/peers-sdk": "^0.34.12",
|
|
40
40
|
"bootstrap": "^5.3.3",
|
|
41
41
|
"react": "^18.0.0",
|
|
42
42
|
"react-dom": "^18.0.0"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"@babel/preset-react": "^7.24.1",
|
|
48
48
|
"@babel/preset-typescript": "^7.27.1",
|
|
49
49
|
"@biomejs/biome": "2.3.11",
|
|
50
|
-
"@peers-app/peers-sdk": "0.34.
|
|
50
|
+
"@peers-app/peers-sdk": "0.34.12",
|
|
51
51
|
"@testing-library/dom": "^10.4.0",
|
|
52
52
|
"@testing-library/jest-dom": "^6.6.3",
|
|
53
53
|
"@testing-library/react": "^16.3.0",
|