@peers-app/peers-ui 0.34.11 → 0.34.13

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.
Files changed (37) hide show
  1. package/dist/components/markdown-editor/editor.d.ts +36 -0
  2. package/dist/components/markdown-editor/editor.js +16 -0
  3. package/dist/components/markdown-editor/format-bar.d.ts +16 -0
  4. package/dist/components/markdown-editor/format-bar.js +132 -0
  5. package/dist/components/markdown-editor/format-commands.d.ts +25 -0
  6. package/dist/components/markdown-editor/format-commands.js +140 -0
  7. package/dist/components/markdown-editor/format.d.ts +36 -0
  8. package/dist/components/markdown-editor/format.js +47 -0
  9. package/dist/components/markdown-editor/lexical-editor.d.ts +1 -0
  10. package/dist/components/markdown-editor/lexical-editor.js +5 -1
  11. package/dist/components/markdown-editor/link-plugin.d.ts +9 -5
  12. package/dist/components/markdown-editor/link-plugin.js +47 -22
  13. package/dist/components/markdown-editor/selection-effects-plugin.d.ts +8 -1
  14. package/dist/components/markdown-editor/selection-effects-plugin.js +25 -1
  15. package/dist/components/markdown-render.js +21 -8
  16. package/dist/components/markdown-with-mentions.d.ts +6 -4
  17. package/dist/components/markdown-with-mentions.js +6 -4
  18. package/dist/host-shell/host-shell-consumer.d.ts +13 -5
  19. package/dist/host-shell/host-shell-consumer.js +31 -16
  20. package/dist/index.d.ts +4 -2
  21. package/dist/index.js +5 -1
  22. package/dist/isolated-screens/frame-runtime.js +14 -15
  23. package/dist/links/app-link-prompt.d.ts +29 -0
  24. package/dist/links/app-link-prompt.js +102 -0
  25. package/dist/links/link-schemes.d.ts +30 -0
  26. package/dist/links/link-schemes.js +46 -0
  27. package/dist/links/peers-links.d.ts +33 -0
  28. package/dist/links/peers-links.js +124 -0
  29. package/dist/mentions/mention-chooser.d.ts +12 -0
  30. package/dist/mentions/mention-chooser.js +48 -13
  31. package/dist/root-layout/root-layout-host.js +10 -1
  32. package/dist/screens/invites/accept-invite.js +3 -4
  33. package/dist/screens/invites/invite-capture.d.ts +2 -7
  34. package/dist/screens/invites/invite-capture.js +8 -25
  35. package/dist/screens/settings/settings-page.js +3 -1
  36. package/dist/theme.css +83 -0
  37. package/package.json +3 -3
@@ -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
- // For when focus has left the chooser (a click on its text); keys inside it stop below.
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: "peers-mention-chooser", role: "dialog", "aria-modal": "true", "aria-label": "Which one?", onMouseDown: (e) => {
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, invite_capture_1.listenForOpenUrlInvites)();
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://` open-url event
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://` open-url event
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 = /^peers:\/\/i\/?$/.test(before) || /^https?:\/\/[^/]+\/i\/?$/.test(before);
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
- (0, exports.inviteCaptured)(token);
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 () => {