@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.
- package/dist/components/markdown-editor/editor.d.ts +36 -0
- package/dist/components/markdown-editor/editor.js +16 -0
- package/dist/components/markdown-editor/format-bar.d.ts +16 -0
- package/dist/components/markdown-editor/format-bar.js +132 -0
- package/dist/components/markdown-editor/format-commands.d.ts +25 -0
- package/dist/components/markdown-editor/format-commands.js +140 -0
- package/dist/components/markdown-editor/format.d.ts +36 -0
- package/dist/components/markdown-editor/format.js +47 -0
- package/dist/components/markdown-editor/lexical-editor.d.ts +1 -0
- package/dist/components/markdown-editor/lexical-editor.js +5 -1
- 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-editor/selection-effects-plugin.d.ts +8 -1
- package/dist/components/markdown-editor/selection-effects-plugin.js +25 -1
- 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/index.d.ts +4 -2
- package/dist/index.js +5 -1
- 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/dist/theme.css +83 -0
- package/package.json +3 -3
|
@@ -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
|
}
|
|
@@ -9,9 +9,16 @@ export declare function $selectedText(): string;
|
|
|
9
9
|
* @returns false, changing nothing, when nothing is selected.
|
|
10
10
|
*/
|
|
11
11
|
export declare function $replaceSelectionWithMention(link: IMentionLink): boolean;
|
|
12
|
+
/**
|
|
13
|
+
* Type `text` at the caret, or in place of the selection; at the end when the editor has no
|
|
14
|
+
* selection. Inside an editor update.
|
|
15
|
+
*/
|
|
16
|
+
export declare function $insertTextAtCaret(text: string): void;
|
|
12
17
|
/**
|
|
13
18
|
* Fills in the selection hooks of {@link IEditorEffects}, so a screen can turn selected text into
|
|
14
|
-
* a link to something it makes from it (Notes' Make note and Make task)
|
|
19
|
+
* a link to something it makes from it (Notes' Make note and Make task) or type into the editor
|
|
20
|
+
* from a button (an @ that opens the mention picker), and ties `effects` to this editor for
|
|
21
|
+
* `MarkdownFormatRow`.
|
|
15
22
|
*/
|
|
16
23
|
export declare function SelectionEffectsPlugin({ effects }: {
|
|
17
24
|
effects: IEditorEffects;
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.$selectedText = $selectedText;
|
|
4
4
|
exports.$replaceSelectionWithMention = $replaceSelectionWithMention;
|
|
5
|
+
exports.$insertTextAtCaret = $insertTextAtCaret;
|
|
5
6
|
exports.SelectionEffectsPlugin = SelectionEffectsPlugin;
|
|
6
7
|
const LexicalComposerContext_1 = require("@lexical/react/LexicalComposerContext");
|
|
7
8
|
const lexical_1 = require("lexical");
|
|
8
9
|
const react_1 = require("react");
|
|
10
|
+
const format_commands_1 = require("./format-commands");
|
|
9
11
|
const mention_node_1 = require("./mention-node");
|
|
10
12
|
/** The selected text as plain text, or empty when nothing is selected. Inside an editor read. */
|
|
11
13
|
function $selectedText() {
|
|
@@ -25,9 +27,24 @@ function $replaceSelectionWithMention(link) {
|
|
|
25
27
|
selection.insertNodes([(0, mention_node_1.$createMentionNode)(link)]);
|
|
26
28
|
return true;
|
|
27
29
|
}
|
|
30
|
+
/**
|
|
31
|
+
* Type `text` at the caret, or in place of the selection; at the end when the editor has no
|
|
32
|
+
* selection. Inside an editor update.
|
|
33
|
+
*/
|
|
34
|
+
function $insertTextAtCaret(text) {
|
|
35
|
+
const selection = (0, lexical_1.$getSelection)();
|
|
36
|
+
if ((0, lexical_1.$isRangeSelection)(selection))
|
|
37
|
+
selection.insertText(text);
|
|
38
|
+
else if ((0, lexical_1.$isNodeSelection)(selection))
|
|
39
|
+
selection.insertNodes([(0, lexical_1.$createTextNode)(text)]);
|
|
40
|
+
else
|
|
41
|
+
(0, lexical_1.$getRoot)().selectEnd().insertText(text);
|
|
42
|
+
}
|
|
28
43
|
/**
|
|
29
44
|
* Fills in the selection hooks of {@link IEditorEffects}, so a screen can turn selected text into
|
|
30
|
-
* a link to something it makes from it (Notes' Make note and Make task)
|
|
45
|
+
* a link to something it makes from it (Notes' Make note and Make task) or type into the editor
|
|
46
|
+
* from a button (an @ that opens the mention picker), and ties `effects` to this editor for
|
|
47
|
+
* `MarkdownFormatRow`.
|
|
31
48
|
*/
|
|
32
49
|
function SelectionEffectsPlugin({ effects }) {
|
|
33
50
|
const [editor] = (0, LexicalComposerContext_1.useLexicalComposerContext)();
|
|
@@ -40,9 +57,16 @@ function SelectionEffectsPlugin({ effects }) {
|
|
|
40
57
|
}, { discrete: true });
|
|
41
58
|
return replaced;
|
|
42
59
|
};
|
|
60
|
+
effects.insertText = (text) => {
|
|
61
|
+
editor.update(() => $insertTextAtCaret(text));
|
|
62
|
+
editor.focus();
|
|
63
|
+
};
|
|
64
|
+
(0, format_commands_1.attachEditor)(effects, editor);
|
|
43
65
|
return () => {
|
|
44
66
|
effects.getSelectedText = undefined;
|
|
45
67
|
effects.replaceSelectionWithMention = undefined;
|
|
68
|
+
effects.insertText = undefined;
|
|
69
|
+
(0, format_commands_1.attachEditor)(effects, undefined);
|
|
46
70
|
};
|
|
47
71
|
}, [editor, effects]);
|
|
48
72
|
return null;
|
|
@@ -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.
|
package/dist/index.d.ts
CHANGED
|
@@ -5,9 +5,11 @@ export * from "./components/icon";
|
|
|
5
5
|
export * from "./components/icon-picker";
|
|
6
6
|
export { configureIconSearchIndexes, type IconSearchIndexSource, type IIconSearchIndexSources, } from "./components/icon-search";
|
|
7
7
|
export * from "./components/inverse-lazy-list";
|
|
8
|
-
export type { IEditorEffects, IMarkdownEditorProps } from "./components/markdown-editor/editor";
|
|
9
|
-
export { MarkdownEditor } from "./components/markdown-editor/editor";
|
|
8
|
+
export type { IEditorEffects, IMarkdownEditorProps, IMarkdownFormatRowProps, } from "./components/markdown-editor/editor";
|
|
9
|
+
export { MarkdownEditor, MarkdownFormatRow } from "./components/markdown-editor/editor";
|
|
10
10
|
export * from "./components/markdown-editor/editor-inline";
|
|
11
|
+
export type { EditorFormat, IFormatState, ISelectionAction, } from "./components/markdown-editor/format";
|
|
12
|
+
export { ALL_FORMATS, INLINE_FORMATS } from "./components/markdown-editor/format";
|
|
11
13
|
export * from "./components/markdown-with-mentions";
|
|
12
14
|
export * from "./components/responsive-section-nav";
|
|
13
15
|
export * from "./components/sortable-list";
|
package/dist/index.js
CHANGED
|
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.inspectUI = exports.FRAME_SELECTOR_PREFIX = exports.actOnUI = exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openMention = exports.useMentionPlace = exports.MentionGroupContext = exports.MentionChip = exports.openLink = exports.windowWidth = exports.windowHeight = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.MarkdownEditor = exports.configureIconSearchIndexes = exports.unregisterCommand = exports.registerCommand = exports.executeCommand = void 0;
|
|
17
|
+
exports.inspectUI = exports.FRAME_SELECTOR_PREFIX = exports.actOnUI = exports.updateActiveTabTitle = exports.goToTabPath = exports.closeCurrentTab = exports.activeTabs = exports.activeTabId = exports.setRootLayout = exports.selectedRootLayoutId = exports.getRootLayouts = exports.getRootLayout = exports.DEFAULT_ROOT_LAYOUT_ID = exports.TabsLayoutApp = exports.RootLayoutHost = exports.LayoutPicker = exports.unregisterGlobalOverlay = exports.registerGlobalOverlay = exports.globalOverlays = exports.notificationHostControls = exports.openMention = exports.useMentionPlace = exports.MentionGroupContext = exports.MentionChip = exports.openLink = exports.windowWidth = exports.windowHeight = exports.mainContentPath = exports.isDesktop = exports.Typeahead = exports.INLINE_FORMATS = exports.ALL_FORMATS = exports.MarkdownFormatRow = exports.MarkdownEditor = exports.configureIconSearchIndexes = exports.unregisterCommand = exports.registerCommand = exports.executeCommand = void 0;
|
|
18
18
|
// Commands in the command palette, with optional shortcuts. From a package's frame they go to the
|
|
19
19
|
// host's palette, under the package's name.
|
|
20
20
|
var command_palette_1 = require("./command-palette/command-palette");
|
|
@@ -30,7 +30,11 @@ Object.defineProperty(exports, "configureIconSearchIndexes", { enumerable: true,
|
|
|
30
30
|
__exportStar(require("./components/inverse-lazy-list"), exports);
|
|
31
31
|
var editor_1 = require("./components/markdown-editor/editor");
|
|
32
32
|
Object.defineProperty(exports, "MarkdownEditor", { enumerable: true, get: function () { return editor_1.MarkdownEditor; } });
|
|
33
|
+
Object.defineProperty(exports, "MarkdownFormatRow", { enumerable: true, get: function () { return editor_1.MarkdownFormatRow; } });
|
|
33
34
|
__exportStar(require("./components/markdown-editor/editor-inline"), exports);
|
|
35
|
+
var format_1 = require("./components/markdown-editor/format");
|
|
36
|
+
Object.defineProperty(exports, "ALL_FORMATS", { enumerable: true, get: function () { return format_1.ALL_FORMATS; } });
|
|
37
|
+
Object.defineProperty(exports, "INLINE_FORMATS", { enumerable: true, get: function () { return format_1.INLINE_FORMATS; } });
|
|
34
38
|
__exportStar(require("./components/markdown-with-mentions"), exports);
|
|
35
39
|
__exportStar(require("./components/responsive-section-nav"), exports);
|
|
36
40
|
__exportStar(require("./components/sortable-list"), exports);
|
|
@@ -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;
|