tldraw 5.6.0 → 5.6.2
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/DOCS.md +21 -9
- package/RELEASE_NOTES.md +161 -3
- package/dist-cjs/index.d.ts +31 -1
- package/dist-cjs/index.js +4 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +11 -4
- package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js.map +2 -2
- package/dist-cjs/lib/shapes/bookmark/bookmarks.js +25 -4
- package/dist-cjs/lib/shapes/bookmark/bookmarks.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/HyperlinkButton.js +4 -0
- package/dist-cjs/lib/shapes/shared/HyperlinkButton.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js +13 -1
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/useOpenLinkHandler.js +38 -0
- package/dist-cjs/lib/shapes/shared/useOpenLinkHandler.js.map +7 -0
- package/dist-cjs/lib/ui/components/ConfirmOpenLinkDialog.js +57 -0
- package/dist-cjs/lib/ui/components/ConfirmOpenLinkDialog.js.map +7 -0
- package/dist-cjs/lib/ui/components/EditLinkDialog.js +15 -17
- package/dist-cjs/lib/ui/components/EditLinkDialog.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +47 -19
- package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +3 -3
- package/dist-cjs/lib/ui/context/actions.js +2 -1
- package/dist-cjs/lib/ui/context/actions.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useEditorEvents.js +12 -1
- package/dist-cjs/lib/ui/hooks/useEditorEvents.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
- package/dist-cjs/lib/ui/version.js +2 -2
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-cjs/lib/utils/linkUrl.js +39 -0
- package/dist-cjs/lib/utils/linkUrl.js.map +7 -0
- package/dist-cjs/lib/utils/openLink.js +68 -0
- package/dist-cjs/lib/utils/openLink.js.map +7 -0
- package/dist-cjs/lib/utils/text/richText.js +4 -1
- package/dist-cjs/lib/utils/text/richText.js.map +2 -2
- package/dist-esm/index.d.mts +31 -1
- package/dist-esm/index.mjs +4 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +12 -4
- package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs.map +2 -2
- package/dist-esm/lib/shapes/bookmark/bookmarks.mjs +25 -4
- package/dist-esm/lib/shapes/bookmark/bookmarks.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs +4 -0
- package/dist-esm/lib/shapes/shared/HyperlinkButton.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +13 -2
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/useOpenLinkHandler.mjs +18 -0
- package/dist-esm/lib/shapes/shared/useOpenLinkHandler.mjs.map +7 -0
- package/dist-esm/lib/ui/components/ConfirmOpenLinkDialog.mjs +43 -0
- package/dist-esm/lib/ui/components/ConfirmOpenLinkDialog.mjs.map +7 -0
- package/dist-esm/lib/ui/components/EditLinkDialog.mjs +16 -18
- package/dist-esm/lib/ui/components/EditLinkDialog.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +38 -20
- package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
- package/dist-esm/lib/ui/context/actions.mjs +2 -1
- package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useEditorEvents.mjs +13 -2
- package/dist-esm/lib/ui/hooks/useEditorEvents.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +2 -2
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/dist-esm/lib/utils/linkUrl.mjs +19 -0
- package/dist-esm/lib/utils/linkUrl.mjs.map +7 -0
- package/dist-esm/lib/utils/openLink.mjs +48 -0
- package/dist-esm/lib/utils/openLink.mjs.map +7 -0
- package/dist-esm/lib/utils/text/richText.mjs +5 -1
- package/dist-esm/lib/utils/text/richText.mjs.map +2 -2
- package/package.json +6 -6
- package/src/index.ts +1 -0
- package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +12 -6
- package/src/lib/shapes/bookmark/bookmarks.ts +38 -5
- package/src/lib/shapes/shared/HyperlinkButton.tsx +4 -0
- package/src/lib/shapes/shared/RichTextLabel.tsx +18 -2
- package/src/lib/shapes/shared/useOpenLinkHandler.ts +20 -0
- package/src/lib/ui/components/ConfirmOpenLinkDialog.tsx +53 -0
- package/src/lib/ui/components/EditLinkDialog.tsx +22 -26
- package/src/lib/ui/components/Toolbar/LinkEditor.tsx +40 -21
- package/src/lib/ui/context/actions.tsx +2 -1
- package/src/lib/ui/hooks/useEditorEvents.ts +14 -2
- package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +4 -0
- package/src/lib/ui/version.ts +2 -2
- package/src/lib/ui.css +19 -2
- package/src/lib/utils/linkUrl.test.ts +33 -0
- package/src/lib/utils/linkUrl.ts +30 -0
- package/src/lib/utils/openLink.test.ts +83 -0
- package/src/lib/utils/openLink.ts +75 -0
- package/src/lib/utils/text/richText.ts +4 -0
- package/src/test/bookmark-shapes.test.ts +62 -2
- package/src/test/ui/ConfirmOpenLinkDialog.test.tsx +128 -0
- package/src/test/ui/EditLinkDialog.test.tsx +53 -2
- package/src/test/ui/LinkEditor.test.tsx +71 -0
- package/tldraw.css +19 -2
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import { useEditor } from "@tldraw/editor";
|
|
2
|
-
import { useEffect } from "react";
|
|
2
|
+
import { createElement, useEffect } from "react";
|
|
3
|
+
import { ConfirmOpenLinkDialog } from "../components/ConfirmOpenLinkDialog.mjs";
|
|
4
|
+
import { useDialogs } from "../context/dialogs.mjs";
|
|
3
5
|
import { useToasts } from "../context/toasts.mjs";
|
|
4
6
|
function useEditorEvents() {
|
|
5
7
|
const editor = useEditor();
|
|
6
8
|
const { addToast } = useToasts();
|
|
9
|
+
const { addDialog } = useDialogs();
|
|
7
10
|
useEffect(() => {
|
|
8
11
|
function handleMaxShapes({ name, count }) {
|
|
9
12
|
addToast({
|
|
@@ -12,11 +15,19 @@ function useEditorEvents() {
|
|
|
12
15
|
severity: "warning"
|
|
13
16
|
});
|
|
14
17
|
}
|
|
18
|
+
function handleConfirmOpenLink({ url }) {
|
|
19
|
+
addDialog({
|
|
20
|
+
id: "confirm-open-link",
|
|
21
|
+
component: ({ onClose }) => createElement(ConfirmOpenLinkDialog, { url, onClose })
|
|
22
|
+
});
|
|
23
|
+
}
|
|
15
24
|
editor.addListener("max-shapes", handleMaxShapes);
|
|
25
|
+
editor.addListener("confirm-open-link", handleConfirmOpenLink);
|
|
16
26
|
return () => {
|
|
17
27
|
editor.removeListener("max-shapes", handleMaxShapes);
|
|
28
|
+
editor.removeListener("confirm-open-link", handleConfirmOpenLink);
|
|
18
29
|
};
|
|
19
|
-
}, [editor, addToast]);
|
|
30
|
+
}, [editor, addToast, addDialog]);
|
|
20
31
|
}
|
|
21
32
|
export {
|
|
22
33
|
useEditorEvents
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/ui/hooks/useEditorEvents.ts"],
|
|
4
|
-
"sourcesContent": ["import { useEditor } from '@tldraw/editor'\nimport { useEffect } from 'react'\nimport { useToasts } from '../context/toasts'\n\n/** @internal */\nexport function useEditorEvents() {\n\tconst editor = useEditor()\n\tconst { addToast } = useToasts()\n\n\tuseEffect(() => {\n\t\tfunction handleMaxShapes({ name, count }: { name: string; pageId: string; count: number }) {\n\t\t\taddToast({\n\t\t\t\ttitle: 'Maximum shapes reached',\n\t\t\t\tdescription: `You've reached the maximum number of shapes allowed on ${name} (${count}). Please delete some shapes or move to a different page to continue.`,\n\t\t\t\tseverity: 'warning',\n\t\t\t})\n\t\t}\n\n\t\teditor.addListener('max-shapes', handleMaxShapes)\n\t\treturn () => {\n\t\t\teditor.removeListener('max-shapes', handleMaxShapes)\n\t\t}\n\t}, [editor, addToast])\n}\n"],
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import { useEditor } from '@tldraw/editor'\nimport { createElement, useEffect } from 'react'\nimport { ConfirmOpenLinkDialog } from '../components/ConfirmOpenLinkDialog'\nimport { useDialogs } from '../context/dialogs'\nimport { useToasts } from '../context/toasts'\n\n/** @internal */\nexport function useEditorEvents() {\n\tconst editor = useEditor()\n\tconst { addToast } = useToasts()\n\tconst { addDialog } = useDialogs()\n\n\tuseEffect(() => {\n\t\tfunction handleMaxShapes({ name, count }: { name: string; pageId: string; count: number }) {\n\t\t\taddToast({\n\t\t\t\ttitle: 'Maximum shapes reached',\n\t\t\t\tdescription: `You've reached the maximum number of shapes allowed on ${name} (${count}). Please delete some shapes or move to a different page to continue.`,\n\t\t\t\tseverity: 'warning',\n\t\t\t})\n\t\t}\n\n\t\tfunction handleConfirmOpenLink({ url }: { url: string }) {\n\t\t\taddDialog({\n\t\t\t\tid: 'confirm-open-link',\n\t\t\t\tcomponent: ({ onClose }) => createElement(ConfirmOpenLinkDialog, { url, onClose }),\n\t\t\t})\n\t\t}\n\n\t\teditor.addListener('max-shapes', handleMaxShapes)\n\t\teditor.addListener('confirm-open-link', handleConfirmOpenLink)\n\t\treturn () => {\n\t\t\teditor.removeListener('max-shapes', handleMaxShapes)\n\t\t\teditor.removeListener('confirm-open-link', handleConfirmOpenLink)\n\t\t}\n\t}, [editor, addToast, addDialog])\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,eAAe,iBAAiB;AACzC,SAAS,6BAA6B;AACtC,SAAS,kBAAkB;AAC3B,SAAS,iBAAiB;AAGnB,SAAS,kBAAkB;AACjC,QAAM,SAAS,UAAU;AACzB,QAAM,EAAE,SAAS,IAAI,UAAU;AAC/B,QAAM,EAAE,UAAU,IAAI,WAAW;AAEjC,YAAU,MAAM;AACf,aAAS,gBAAgB,EAAE,MAAM,MAAM,GAAoD;AAC1F,eAAS;AAAA,QACR,OAAO;AAAA,QACP,aAAa,0DAA0D,IAAI,KAAK,KAAK;AAAA,QACrF,UAAU;AAAA,MACX,CAAC;AAAA,IACF;AAEA,aAAS,sBAAsB,EAAE,IAAI,GAAoB;AACxD,gBAAU;AAAA,QACT,IAAI;AAAA,QACJ,WAAW,CAAC,EAAE,QAAQ,MAAM,cAAc,uBAAuB,EAAE,KAAK,QAAQ,CAAC;AAAA,MAClF,CAAC;AAAA,IACF;AAEA,WAAO,YAAY,cAAc,eAAe;AAChD,WAAO,YAAY,qBAAqB,qBAAqB;AAC7D,WAAO,MAAM;AACZ,aAAO,eAAe,cAAc,eAAe;AACnD,aAAO,eAAe,qBAAqB,qBAAqB;AAAA,IACjE;AAAA,EACD,GAAG,CAAC,QAAQ,UAAU,SAAS,CAAC;AACjC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/ui/version.ts"],
|
|
4
|
-
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.6.
|
|
4
|
+
"sourcesContent": ["// This file is automatically generated by internal/scripts/refresh-assets.ts.\n// Do not edit manually. Or do, I'm a comment, not a cop.\n\nexport const version = '5.6.2'\nexport const publishDates = {\n\tmajor: '2026-05-06T16:28:18.473Z',\n\tminor: '2026-10-28T14:20:57.238Z',\n\tpatch: '2026-11-20T13:16:37.205Z',\n}\n"],
|
|
5
5
|
"mappings": "AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { T } from "@tldraw/editor";
|
|
2
|
+
const emailRegex = /^[^\s@/:]+@[^\s@/:]+\.[^\s@/:]+$/;
|
|
3
|
+
function normalizeLinkUrl(input) {
|
|
4
|
+
const url = input.trim().replace(/^https?:\/\/(https?:\/\/)/i, "$1");
|
|
5
|
+
if (T.linkUrl.isValid(url)) return url;
|
|
6
|
+
if (emailRegex.test(url)) return `mailto:${url}`;
|
|
7
|
+
const withProtocol = `https://${url}`;
|
|
8
|
+
if (!T.linkUrl.isValid(withProtocol)) return null;
|
|
9
|
+
const { hostname, username } = new URL(withProtocol);
|
|
10
|
+
if (username) return null;
|
|
11
|
+
if (hostname === "localhost" || hostname.startsWith("[") || /[^.]\.[^.]+$/.test(hostname)) {
|
|
12
|
+
return withProtocol;
|
|
13
|
+
}
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
normalizeLinkUrl
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=linkUrl.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/utils/linkUrl.ts"],
|
|
4
|
+
"sourcesContent": ["import { T } from '@tldraw/editor'\n\nconst emailRegex = /^[^\\s@/:]+@[^\\s@/:]+\\.[^\\s@/:]+$/\n\n/**\n * Turn what a user typed into a link field into the url to store, or null if it isn't a link.\n *\n * - Anything `T.linkUrl` accepts is kept as typed, so `mailto:` and app links (`vscode://\u2026`)\n * are never rewritten.\n * - An email address becomes a `mailto:` link.\n * - A bare host (`example.com`, `localhost:3000`) gets `https://`. A word with no dot, like\n * `hello`, is not treated as a host, or every typo would become a dead `https://hello` link.\n * - The empty string means \"no link\".\n */\nexport function normalizeLinkUrl(input: string): string | null {\n\t// Pasting a url into a field that already holds `https://` doubles the protocol.\n\tconst url = input.trim().replace(/^https?:\\/\\/(https?:\\/\\/)/i, '$1')\n\n\tif (T.linkUrl.isValid(url)) return url\n\tif (emailRegex.test(url)) return `mailto:${url}`\n\n\tconst withProtocol = `https://${url}`\n\tif (!T.linkUrl.isValid(withProtocol)) return null\n\tconst { hostname, username } = new URL(withProtocol)\n\tif (username) return null\n\tif (hostname === 'localhost' || hostname.startsWith('[') || /[^.]\\.[^.]+$/.test(hostname)) {\n\t\treturn withProtocol\n\t}\n\treturn null\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,SAAS;AAElB,MAAM,aAAa;AAYZ,SAAS,iBAAiB,OAA8B;AAE9D,QAAM,MAAM,MAAM,KAAK,EAAE,QAAQ,8BAA8B,IAAI;AAEnE,MAAI,EAAE,QAAQ,QAAQ,GAAG,EAAG,QAAO;AACnC,MAAI,WAAW,KAAK,GAAG,EAAG,QAAO,UAAU,GAAG;AAE9C,QAAM,eAAe,WAAW,GAAG;AACnC,MAAI,CAAC,EAAE,QAAQ,QAAQ,YAAY,EAAG,QAAO;AAC7C,QAAM,EAAE,UAAU,SAAS,IAAI,IAAI,IAAI,YAAY;AACnD,MAAI,SAAU,QAAO;AACrB,MAAI,aAAa,eAAe,SAAS,WAAW,GAAG,KAAK,eAAe,KAAK,QAAQ,GAAG;AAC1F,WAAO;AAAA,EACR;AACA,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { openWindow, T } from "@tldraw/editor";
|
|
2
|
+
const trustedLinkProtocols = /* @__PURE__ */ new Set([
|
|
3
|
+
"http:",
|
|
4
|
+
"https:",
|
|
5
|
+
"mailto:",
|
|
6
|
+
"claude:",
|
|
7
|
+
"codex:",
|
|
8
|
+
"cursor:",
|
|
9
|
+
"discord:",
|
|
10
|
+
"figma:",
|
|
11
|
+
"jetbrains:",
|
|
12
|
+
"linear:",
|
|
13
|
+
"notion:",
|
|
14
|
+
"obsidian:",
|
|
15
|
+
"slack:",
|
|
16
|
+
"spotify:",
|
|
17
|
+
"vscode:",
|
|
18
|
+
"windsurf:",
|
|
19
|
+
"zed:"
|
|
20
|
+
]);
|
|
21
|
+
function getLinkOpenPolicy(url) {
|
|
22
|
+
if (!url || !T.linkUrl.isValid(url)) return "block";
|
|
23
|
+
if (url.startsWith("/") || url.startsWith("./")) return "open";
|
|
24
|
+
return trustedLinkProtocols.has(new URL(url).protocol) ? "open" : "confirm";
|
|
25
|
+
}
|
|
26
|
+
function openLink(editor, url) {
|
|
27
|
+
switch (getLinkOpenPolicy(url)) {
|
|
28
|
+
case "open":
|
|
29
|
+
openWindow(url, "_blank");
|
|
30
|
+
return;
|
|
31
|
+
case "confirm":
|
|
32
|
+
if (editor.listenerCount("confirm-open-link") > 0) {
|
|
33
|
+
editor.emit("confirm-open-link", { url });
|
|
34
|
+
} else {
|
|
35
|
+
console.warn(
|
|
36
|
+
`Not opening ${url}: links into unknown apps need confirming, and nothing is listening for the editor's confirm-open-link event. Add a listener with editor.on('confirm-open-link', ({ url }) => ...) to ask the user, or render the default tldraw UI.`
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
return;
|
|
40
|
+
case "block":
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
export {
|
|
45
|
+
getLinkOpenPolicy,
|
|
46
|
+
openLink
|
|
47
|
+
};
|
|
48
|
+
//# sourceMappingURL=openLink.mjs.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/lib/utils/openLink.ts"],
|
|
4
|
+
"sourcesContent": ["import { Editor, openWindow, T } from '@tldraw/editor'\n\n/**\n * How {@link openLink} treats a link. See {@link getLinkOpenPolicy}.\n *\n * @public\n */\nexport type TLLinkOpenPolicy = 'open' | 'confirm' | 'block'\n\n// This list only decides whether we ask before opening, so it can change in any release. Don't move\n// it into `T.linkUrl`: every client and the sync server validate stored urls with that, so changing\n// what it accepts breaks shared boards between versions.\nconst trustedLinkProtocols = new Set([\n\t'http:',\n\t'https:',\n\t'mailto:',\n\t'claude:',\n\t'codex:',\n\t'cursor:',\n\t'discord:',\n\t'figma:',\n\t'jetbrains:',\n\t'linear:',\n\t'notion:',\n\t'obsidian:',\n\t'slack:',\n\t'spotify:',\n\t'vscode:',\n\t'windsurf:',\n\t'zed:',\n])\n\n/**\n * Decide how a link from a shape or rich text should be opened.\n *\n * - `open`: a web link, mailto link, relative link, or a link into a well-known app.\n * - `confirm`: any other link that `T.linkUrl` accepts, such as an app we don't know. Ask the\n * user before opening it.\n * - `block`: anything `T.linkUrl` rejects. Stored records are validated, but a link can also\n * come from rendered rich text or a custom shape, so check again here.\n *\n * @public\n */\nexport function getLinkOpenPolicy(url: string): TLLinkOpenPolicy {\n\tif (!url || !T.linkUrl.isValid(url)) return 'block'\n\tif (url.startsWith('/') || url.startsWith('./')) return 'open'\n\treturn trustedLinkProtocols.has(new URL(url).protocol) ? 'open' : 'confirm'\n}\n\n/**\n * Open a user-provided link in a new window, following {@link getLinkOpenPolicy}. Links that need\n * confirming emit a `confirm-open-link` event, which the default UI answers with a dialog. With no\n * listener for that event (for example with `hideUi`), those links are not opened. To handle them\n * yourself, add a listener that asks the user and calls `openWindow(url, '_blank')` if they agree.\n *\n * @public\n */\nexport function openLink(editor: Editor, url: string) {\n\tswitch (getLinkOpenPolicy(url)) {\n\t\tcase 'open':\n\t\t\topenWindow(url, '_blank')\n\t\t\treturn\n\t\tcase 'confirm':\n\t\t\tif (editor.listenerCount('confirm-open-link') > 0) {\n\t\t\t\teditor.emit('confirm-open-link', { url })\n\t\t\t} else {\n\t\t\t\tconsole.warn(\n\t\t\t\t\t`Not opening ${url}: links into unknown apps need confirming, and nothing is listening for the editor's confirm-open-link event. Add a listener with editor.on('confirm-open-link', ({ url }) => ...) to ask the user, or render the default tldraw UI.`\n\t\t\t\t)\n\t\t\t}\n\t\t\treturn\n\t\tcase 'block':\n\t\t\treturn\n\t}\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAiB,YAAY,SAAS;AAYtC,MAAM,uBAAuB,oBAAI,IAAI;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACD,CAAC;AAaM,SAAS,kBAAkB,KAA+B;AAChE,MAAI,CAAC,OAAO,CAAC,EAAE,QAAQ,QAAQ,GAAG,EAAG,QAAO;AAC5C,MAAI,IAAI,WAAW,GAAG,KAAK,IAAI,WAAW,IAAI,EAAG,QAAO;AACxD,SAAO,qBAAqB,IAAI,IAAI,IAAI,GAAG,EAAE,QAAQ,IAAI,SAAS;AACnE;AAUO,SAAS,SAAS,QAAgB,KAAa;AACrD,UAAQ,kBAAkB,GAAG,GAAG;AAAA,IAC/B,KAAK;AACJ,iBAAW,KAAK,QAAQ;AACxB;AAAA,IACD,KAAK;AACJ,UAAI,OAAO,cAAc,mBAAmB,IAAI,GAAG;AAClD,eAAO,KAAK,qBAAqB,EAAE,IAAI,CAAC;AAAA,MACzC,OAAO;AACN,gBAAQ;AAAA,UACP,eAAe,GAAG;AAAA,QACnB;AAAA,MACD;AACA;AAAA,IACD,KAAK;AACJ;AAAA,EACF;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -11,6 +11,7 @@ import { Typography } from "@tiptap/extension-typography";
|
|
|
11
11
|
import { StarterKit } from "@tiptap/starter-kit";
|
|
12
12
|
import {
|
|
13
13
|
getOwnProperty,
|
|
14
|
+
T,
|
|
14
15
|
WeakCache
|
|
15
16
|
} from "@tldraw/editor";
|
|
16
17
|
import { DefaultFontFaces } from "../../shapes/shared/defaultFonts.mjs";
|
|
@@ -35,7 +36,10 @@ function getTipTapDefaultExtensions(starterKitOptions) {
|
|
|
35
36
|
horizontalRule: false,
|
|
36
37
|
link: {
|
|
37
38
|
openOnClick: false,
|
|
38
|
-
autolink: true
|
|
39
|
+
autolink: true,
|
|
40
|
+
// TipTap strips hrefs outside its own protocol list, which would drop app links
|
|
41
|
+
// (`vscode://…`) that shape links accept.
|
|
42
|
+
isAllowedUri: (url, { defaultValidate }) => defaultValidate(url) || T.linkUrl.isValid(url)
|
|
39
43
|
},
|
|
40
44
|
// List every enabled block type: a missing one gets an empty paragraph appended after it
|
|
41
45
|
// that the user can't delete (#7641 for lists, #11113 for headings).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/utils/text/richText.ts"],
|
|
4
|
-
"sourcesContent": ["import {\n\tExtension,\n\tExtensions,\n\textensions,\n\tgenerateHTML,\n\tgenerateJSON,\n\tgenerateText,\n\tJSONContent,\n} from '@tiptap/core'\nimport { Code } from '@tiptap/extension-code'\nimport { Highlight } from '@tiptap/extension-highlight'\nimport { Typography } from '@tiptap/extension-typography'\nimport { Node } from '@tiptap/pm/model'\nimport { StarterKit, type StarterKitOptions } from '@tiptap/starter-kit'\nimport {\n\tEditor,\n\tgetOwnProperty,\n\tRichTextFontVisitorState,\n\tTLFontFace,\n\tTLRichText,\n\tWeakCache,\n} from '@tldraw/editor'\nimport { DefaultFontFaces } from '../../shapes/shared/defaultFonts'\nimport { LiteralTypingExtension } from './literalTyping'\nimport { WrapSelectionExtension } from './wrapSelection'\n\n/** @public */\nexport const KeyboardShiftEnterTweakExtension = Extension.create({\n\tname: 'keyboardShiftEnterHandler',\n\taddKeyboardShortcuts() {\n\t\treturn {\n\t\t\t// We don't support soft breaks, so we just use the default enter command.\n\t\t\t'Shift-Enter': ({ editor }) => editor.commands.enter(),\n\t\t}\n\t},\n})\n\n// We change the default Code to override what's in the StarterKit.\n// It allows for other attributes/extensions.\n// @ts-ignore this is fine.\nCode.config.excludes = undefined\n\n// We want the highlighting to take precedence over bolding/italics/links\n// as far as rendering is concerned. Otherwise, the highlighting\n// looks broken up.\nHighlight.config.priority = 1100\n\n/**\n * Build tldraw's default TipTap extension set, optionally overriding the bundled `StarterKit`\n * options. The one lever most consumers want is turning individual nodes off (e.g. comments use a\n * headingless set via `getTipTapDefaultExtensions({ heading: false })`); because `StarterKit` is a\n * single umbrella extension, its sub-extensions can only be disabled through its config, not by\n * filtering the returned array.\n *\n * @public\n */\nexport function getTipTapDefaultExtensions(\n\tstarterKitOptions?: Partial<StarterKitOptions>\n): Extensions {\n\treturn [\n\t\tStarterKit.configure({\n\t\t\tblockquote: false,\n\t\t\tcodeBlock: false,\n\t\t\thorizontalRule: false,\n\t\t\tlink: {\n\t\t\t\topenOnClick: false,\n\t\t\t\tautolink: true,\n\t\t\t},\n\t\t\t// List every enabled block type: a missing one gets an empty paragraph appended after it\n\t\t\t// that the user can't delete (#7641 for lists, #11113 for headings).\n\t\t\ttrailingNode: {\n\t\t\t\tnotAfter: ['paragraph', 'heading', 'bulletList', 'orderedList', 'listItem'],\n\t\t\t},\n\t\t\t...starterKitOptions,\n\t\t}),\n\t\tHighlight,\n\t\tTypography,\n\t\tLiteralTypingExtension,\n\t\tWrapSelectionExtension,\n\t\tKeyboardShiftEnterTweakExtension,\n\n\t\t// N.B. We disable the text direction core extension in RichTextArea,\n\t\t// but we add it back in again here in our own extensions list so that\n\t\t// people can omit/override it if they want to.\n\t\textensions.TextDirection.configure({ direction: 'auto' }),\n\t]\n}\n\n/**\n * Default extensions for the TipTap editor.\n *\n * @public\n */\nexport const tipTapDefaultExtensions: Extensions = getTipTapDefaultExtensions()\n\n// todo: bust this if the editor changes, too\nconst htmlCache = new WeakCache<TLRichText, string>()\n\n/**\n * Renders HTML from a rich text string using an explicit set of TipTap extensions, rather than the\n * ones configured on an editor. Use this when rendering rich text outside of a shape's editor\n * config (e.g. comments, which render through their own headingless extension set).\n *\n * @param richText - The rich text content.\n * @param extensions - The TipTap extensions to render with.\n *\n * @public\n */\nexport function renderHtmlFromRichTextWithExtensions(\n\trichText: TLRichText,\n\textensions: Extensions\n): string {\n\tconst html = generateHTML(richText as JSONContent, extensions)\n\t// We replace empty paragraphs with a single line break to prevent the browser from collapsing\n\t// them. The paragraph's attributes are kept: paragraphs render with a `dir` attribute, usually\n\t// `auto` but `ltr` or `rtl` when the direction was set explicitly or parsed from pasted HTML.\n\treturn html.replace(/<p([^>]*)><\\/p>/g, '<p$1><br /></p>')\n}\n\n/**\n * Renders HTML from a rich text string.\n *\n * @param editor - The editor instance.\n * @param richText - The rich text content.\n *\n * @public\n */\nexport function renderHtmlFromRichText(editor: Editor, richText: TLRichText) {\n\treturn htmlCache.get(richText, () => {\n\t\tconst tipTapExtensions =\n\t\t\teditor.getTextOptions().tipTapConfig?.extensions ?? tipTapDefaultExtensions\n\t\treturn renderHtmlFromRichTextWithExtensions(richText, tipTapExtensions)\n\t})\n}\n\n/**\n * Renders HTML from a rich text string for measurement.\n * @param editor - The editor instance.\n * @param richText - The rich text content.\n *\n * @public\n */\nexport function renderHtmlFromRichTextForMeasurement(editor: Editor, richText: TLRichText) {\n\tconst html = renderHtmlFromRichText(editor, richText)\n\treturn `<div class=\"tl-rich-text\">${html}</div>`\n}\n\n// A weak cache used to store plaintext that's been extracted from rich text.\nconst plainTextFromRichTextCache = new WeakCache<TLRichText, string>()\n\nexport function isEmptyRichText(richText: TLRichText) {\n\t// An empty document has no text. It can be encoded several equally-valid ways:\n\t// an empty `content` array at the doc level, or a single paragraph whose own\n\t// `content` is missing or an empty array. The interactive editor emits the\n\t// single-paragraph / missing-`content` form; programmatic authoring (snapshot\n\t// loads, and agents/importers emitting tldraw JSON) commonly emits the\n\t// empty-array forms. Treat them all as empty.\n\tif (richText.content.length === 0) return true\n\tif (richText.content.length === 1) {\n\t\tconst node = richText.content[0] as any\n\t\tif (!node.content || node.content.length === 0) return true\n\t}\n\treturn false\n}\n\n/**\n * Whether the editor's active rich text selection is inside a list.\n *\n * `taskList` isn't in the default extension set, but when it is added its list items bind Tab and\n * Shift-Tab themselves. Leaving it out here lets our own Tab handling run alongside TipTap's, so a\n * single keypress both indents the text and nests the item.\n *\n * @internal\n */\nexport function isEditingRichTextList(editor: Editor) {\n\tconst textEditor = editor.getRichTextEditor()\n\treturn !!(\n\t\ttextEditor?.isActive('bulletList') ||\n\t\ttextEditor?.isActive('orderedList') ||\n\t\ttextEditor?.isActive('taskList')\n\t)\n}\n\n/**\n * Renders plaintext from a rich text string.\n * @param editor - The editor instance.\n * @param richText - The rich text content.\n *\n * @public\n */\nexport function renderPlaintextFromRichText(editor: Editor, richText: TLRichText) {\n\tif (isEmptyRichText(richText)) return ''\n\n\treturn plainTextFromRichTextCache.get(richText, () => {\n\t\tconst tipTapExtensions =\n\t\t\teditor.getTextOptions().tipTapConfig?.extensions ?? tipTapDefaultExtensions\n\t\treturn generateText(richText as JSONContent, tipTapExtensions, {\n\t\t\tblockSeparator: '\\n',\n\t\t})\n\t})\n}\n\n/**\n * Renders JSONContent from html.\n * @param editor - The editor instance.\n * @param richText - The rich text content.\n *\n * @public\n */\nexport function renderRichTextFromHTML(editor: Editor, html: string): TLRichText {\n\tconst tipTapExtensions =\n\t\teditor.getTextOptions().tipTapConfig?.extensions ?? tipTapDefaultExtensions\n\treturn generateJSON(html, tipTapExtensions) as TLRichText\n}\n\n/** @public */\nexport function defaultAddFontsFromNode(\n\tnode: Node,\n\tstate: RichTextFontVisitorState,\n\taddFont: (font: TLFontFace) => void\n) {\n\tfor (const mark of node.marks) {\n\t\tif (mark.type.name === 'bold' && state.weight !== 'bold') {\n\t\t\tstate = { ...state, weight: 'bold' }\n\t\t}\n\t\tif (mark.type.name === 'italic' && state.style !== 'italic') {\n\t\t\tstate = { ...state, style: 'italic' }\n\t\t}\n\t\tif (mark.type.name === 'code' && state.family !== 'tldraw_mono') {\n\t\t\tstate = { ...state, family: 'tldraw_mono' }\n\t\t}\n\t}\n\n\tconst fontsForFamily = getOwnProperty(DefaultFontFaces, state.family)\n\tif (!fontsForFamily) return state\n\n\tconst fontsForStyle = getOwnProperty(fontsForFamily, state.style)\n\tif (!fontsForStyle) return state\n\n\tconst fontsForWeight = getOwnProperty(fontsForStyle, state.weight)\n\tif (!fontsForWeight) return state\n\n\taddFont(fontsForWeight)\n\n\treturn state\n}\n"],
|
|
5
|
-
"mappings": "AAAA;AAAA,EACC;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,SAAS,YAAY;AACrB,SAAS,iBAAiB;AAC1B,SAAS,kBAAkB;AAE3B,SAAS,kBAA0C;AACnD;AAAA,EAEC;AAAA,
|
|
4
|
+
"sourcesContent": ["import {\n\tExtension,\n\tExtensions,\n\textensions,\n\tgenerateHTML,\n\tgenerateJSON,\n\tgenerateText,\n\tJSONContent,\n} from '@tiptap/core'\nimport { Code } from '@tiptap/extension-code'\nimport { Highlight } from '@tiptap/extension-highlight'\nimport { Typography } from '@tiptap/extension-typography'\nimport { Node } from '@tiptap/pm/model'\nimport { StarterKit, type StarterKitOptions } from '@tiptap/starter-kit'\nimport {\n\tEditor,\n\tgetOwnProperty,\n\tRichTextFontVisitorState,\n\tT,\n\tTLFontFace,\n\tTLRichText,\n\tWeakCache,\n} from '@tldraw/editor'\nimport { DefaultFontFaces } from '../../shapes/shared/defaultFonts'\nimport { LiteralTypingExtension } from './literalTyping'\nimport { WrapSelectionExtension } from './wrapSelection'\n\n/** @public */\nexport const KeyboardShiftEnterTweakExtension = Extension.create({\n\tname: 'keyboardShiftEnterHandler',\n\taddKeyboardShortcuts() {\n\t\treturn {\n\t\t\t// We don't support soft breaks, so we just use the default enter command.\n\t\t\t'Shift-Enter': ({ editor }) => editor.commands.enter(),\n\t\t}\n\t},\n})\n\n// We change the default Code to override what's in the StarterKit.\n// It allows for other attributes/extensions.\n// @ts-ignore this is fine.\nCode.config.excludes = undefined\n\n// We want the highlighting to take precedence over bolding/italics/links\n// as far as rendering is concerned. Otherwise, the highlighting\n// looks broken up.\nHighlight.config.priority = 1100\n\n/**\n * Build tldraw's default TipTap extension set, optionally overriding the bundled `StarterKit`\n * options. The one lever most consumers want is turning individual nodes off (e.g. comments use a\n * headingless set via `getTipTapDefaultExtensions({ heading: false })`); because `StarterKit` is a\n * single umbrella extension, its sub-extensions can only be disabled through its config, not by\n * filtering the returned array.\n *\n * @public\n */\nexport function getTipTapDefaultExtensions(\n\tstarterKitOptions?: Partial<StarterKitOptions>\n): Extensions {\n\treturn [\n\t\tStarterKit.configure({\n\t\t\tblockquote: false,\n\t\t\tcodeBlock: false,\n\t\t\thorizontalRule: false,\n\t\t\tlink: {\n\t\t\t\topenOnClick: false,\n\t\t\t\tautolink: true,\n\t\t\t\t// TipTap strips hrefs outside its own protocol list, which would drop app links\n\t\t\t\t// (`vscode://\u2026`) that shape links accept.\n\t\t\t\tisAllowedUri: (url, { defaultValidate }) => defaultValidate(url) || T.linkUrl.isValid(url),\n\t\t\t},\n\t\t\t// List every enabled block type: a missing one gets an empty paragraph appended after it\n\t\t\t// that the user can't delete (#7641 for lists, #11113 for headings).\n\t\t\ttrailingNode: {\n\t\t\t\tnotAfter: ['paragraph', 'heading', 'bulletList', 'orderedList', 'listItem'],\n\t\t\t},\n\t\t\t...starterKitOptions,\n\t\t}),\n\t\tHighlight,\n\t\tTypography,\n\t\tLiteralTypingExtension,\n\t\tWrapSelectionExtension,\n\t\tKeyboardShiftEnterTweakExtension,\n\n\t\t// N.B. We disable the text direction core extension in RichTextArea,\n\t\t// but we add it back in again here in our own extensions list so that\n\t\t// people can omit/override it if they want to.\n\t\textensions.TextDirection.configure({ direction: 'auto' }),\n\t]\n}\n\n/**\n * Default extensions for the TipTap editor.\n *\n * @public\n */\nexport const tipTapDefaultExtensions: Extensions = getTipTapDefaultExtensions()\n\n// todo: bust this if the editor changes, too\nconst htmlCache = new WeakCache<TLRichText, string>()\n\n/**\n * Renders HTML from a rich text string using an explicit set of TipTap extensions, rather than the\n * ones configured on an editor. Use this when rendering rich text outside of a shape's editor\n * config (e.g. comments, which render through their own headingless extension set).\n *\n * @param richText - The rich text content.\n * @param extensions - The TipTap extensions to render with.\n *\n * @public\n */\nexport function renderHtmlFromRichTextWithExtensions(\n\trichText: TLRichText,\n\textensions: Extensions\n): string {\n\tconst html = generateHTML(richText as JSONContent, extensions)\n\t// We replace empty paragraphs with a single line break to prevent the browser from collapsing\n\t// them. The paragraph's attributes are kept: paragraphs render with a `dir` attribute, usually\n\t// `auto` but `ltr` or `rtl` when the direction was set explicitly or parsed from pasted HTML.\n\treturn html.replace(/<p([^>]*)><\\/p>/g, '<p$1><br /></p>')\n}\n\n/**\n * Renders HTML from a rich text string.\n *\n * @param editor - The editor instance.\n * @param richText - The rich text content.\n *\n * @public\n */\nexport function renderHtmlFromRichText(editor: Editor, richText: TLRichText) {\n\treturn htmlCache.get(richText, () => {\n\t\tconst tipTapExtensions =\n\t\t\teditor.getTextOptions().tipTapConfig?.extensions ?? tipTapDefaultExtensions\n\t\treturn renderHtmlFromRichTextWithExtensions(richText, tipTapExtensions)\n\t})\n}\n\n/**\n * Renders HTML from a rich text string for measurement.\n * @param editor - The editor instance.\n * @param richText - The rich text content.\n *\n * @public\n */\nexport function renderHtmlFromRichTextForMeasurement(editor: Editor, richText: TLRichText) {\n\tconst html = renderHtmlFromRichText(editor, richText)\n\treturn `<div class=\"tl-rich-text\">${html}</div>`\n}\n\n// A weak cache used to store plaintext that's been extracted from rich text.\nconst plainTextFromRichTextCache = new WeakCache<TLRichText, string>()\n\nexport function isEmptyRichText(richText: TLRichText) {\n\t// An empty document has no text. It can be encoded several equally-valid ways:\n\t// an empty `content` array at the doc level, or a single paragraph whose own\n\t// `content` is missing or an empty array. The interactive editor emits the\n\t// single-paragraph / missing-`content` form; programmatic authoring (snapshot\n\t// loads, and agents/importers emitting tldraw JSON) commonly emits the\n\t// empty-array forms. Treat them all as empty.\n\tif (richText.content.length === 0) return true\n\tif (richText.content.length === 1) {\n\t\tconst node = richText.content[0] as any\n\t\tif (!node.content || node.content.length === 0) return true\n\t}\n\treturn false\n}\n\n/**\n * Whether the editor's active rich text selection is inside a list.\n *\n * `taskList` isn't in the default extension set, but when it is added its list items bind Tab and\n * Shift-Tab themselves. Leaving it out here lets our own Tab handling run alongside TipTap's, so a\n * single keypress both indents the text and nests the item.\n *\n * @internal\n */\nexport function isEditingRichTextList(editor: Editor) {\n\tconst textEditor = editor.getRichTextEditor()\n\treturn !!(\n\t\ttextEditor?.isActive('bulletList') ||\n\t\ttextEditor?.isActive('orderedList') ||\n\t\ttextEditor?.isActive('taskList')\n\t)\n}\n\n/**\n * Renders plaintext from a rich text string.\n * @param editor - The editor instance.\n * @param richText - The rich text content.\n *\n * @public\n */\nexport function renderPlaintextFromRichText(editor: Editor, richText: TLRichText) {\n\tif (isEmptyRichText(richText)) return ''\n\n\treturn plainTextFromRichTextCache.get(richText, () => {\n\t\tconst tipTapExtensions =\n\t\t\teditor.getTextOptions().tipTapConfig?.extensions ?? tipTapDefaultExtensions\n\t\treturn generateText(richText as JSONContent, tipTapExtensions, {\n\t\t\tblockSeparator: '\\n',\n\t\t})\n\t})\n}\n\n/**\n * Renders JSONContent from html.\n * @param editor - The editor instance.\n * @param richText - The rich text content.\n *\n * @public\n */\nexport function renderRichTextFromHTML(editor: Editor, html: string): TLRichText {\n\tconst tipTapExtensions =\n\t\teditor.getTextOptions().tipTapConfig?.extensions ?? tipTapDefaultExtensions\n\treturn generateJSON(html, tipTapExtensions) as TLRichText\n}\n\n/** @public */\nexport function defaultAddFontsFromNode(\n\tnode: Node,\n\tstate: RichTextFontVisitorState,\n\taddFont: (font: TLFontFace) => void\n) {\n\tfor (const mark of node.marks) {\n\t\tif (mark.type.name === 'bold' && state.weight !== 'bold') {\n\t\t\tstate = { ...state, weight: 'bold' }\n\t\t}\n\t\tif (mark.type.name === 'italic' && state.style !== 'italic') {\n\t\t\tstate = { ...state, style: 'italic' }\n\t\t}\n\t\tif (mark.type.name === 'code' && state.family !== 'tldraw_mono') {\n\t\t\tstate = { ...state, family: 'tldraw_mono' }\n\t\t}\n\t}\n\n\tconst fontsForFamily = getOwnProperty(DefaultFontFaces, state.family)\n\tif (!fontsForFamily) return state\n\n\tconst fontsForStyle = getOwnProperty(fontsForFamily, state.style)\n\tif (!fontsForStyle) return state\n\n\tconst fontsForWeight = getOwnProperty(fontsForStyle, state.weight)\n\tif (!fontsForWeight) return state\n\n\taddFont(fontsForWeight)\n\n\treturn state\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": ["extensions"]
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "tldraw",
|
|
3
3
|
"description": "A tiny little drawing editor.",
|
|
4
|
-
"version": "5.6.
|
|
4
|
+
"version": "5.6.2",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -56,11 +56,11 @@
|
|
|
56
56
|
"@tiptap/pm": "^3.12.1",
|
|
57
57
|
"@tiptap/react": "^3.12.1",
|
|
58
58
|
"@tiptap/starter-kit": "^3.12.1",
|
|
59
|
-
"@tldraw/driver": "5.6.
|
|
60
|
-
"@tldraw/editor": "5.6.
|
|
61
|
-
"@tldraw/state": "5.6.
|
|
62
|
-
"@tldraw/store": "5.6.
|
|
63
|
-
"@tldraw/tlschema": "5.6.
|
|
59
|
+
"@tldraw/driver": "5.6.2",
|
|
60
|
+
"@tldraw/editor": "5.6.2",
|
|
61
|
+
"@tldraw/state": "5.6.2",
|
|
62
|
+
"@tldraw/store": "5.6.2",
|
|
63
|
+
"@tldraw/tlschema": "5.6.2",
|
|
64
64
|
"classnames": "^2.5.1",
|
|
65
65
|
"idb": "^7.1.1",
|
|
66
66
|
"lz-string": "^1.5.0",
|
package/src/index.ts
CHANGED
|
@@ -844,6 +844,7 @@ export {
|
|
|
844
844
|
setDefaultEditorAssetUrls,
|
|
845
845
|
type TLEditorAssetUrls,
|
|
846
846
|
} from './lib/utils/static-assets/assetUrls'
|
|
847
|
+
export { getLinkOpenPolicy, openLink, type TLLinkOpenPolicy } from './lib/utils/openLink'
|
|
847
848
|
export { sanitizeSvg } from './lib/utils/svg/sanitizeSvg'
|
|
848
849
|
export {
|
|
849
850
|
defaultAddFontsFromNode,
|
|
@@ -24,12 +24,14 @@ import type { ShapeOptionsWithDisplayValues } from '../shared/getDisplayValues'
|
|
|
24
24
|
import { HyperlinkButton } from '../shared/HyperlinkButton'
|
|
25
25
|
import { LINK_ICON } from '../shared/icons-editor'
|
|
26
26
|
import { getRotatedBoxShadow } from '../shared/rotated-box-shadow'
|
|
27
|
+
import { useOpenLinkHandler } from '../shared/useOpenLinkHandler'
|
|
27
28
|
import {
|
|
28
29
|
BOOKMARK_HEIGHT,
|
|
29
30
|
BOOKMARK_WIDTH,
|
|
30
31
|
getBookmarkShapeHeight,
|
|
31
32
|
getHumanReadableAddress,
|
|
32
33
|
getResolvedBookmarkAssetId,
|
|
34
|
+
isUrlOnlyBookmarkUrl,
|
|
33
35
|
setBookmarkHeight,
|
|
34
36
|
resolveBookmarkAssetForUrlChange,
|
|
35
37
|
} from './bookmarks'
|
|
@@ -135,7 +137,7 @@ export class BookmarkShapeUtil extends BaseBoxShapeUtil<TLBookmarkShape> {
|
|
|
135
137
|
next = resolveBookmarkAssetForUrlChange(this.editor, shape)
|
|
136
138
|
}
|
|
137
139
|
|
|
138
|
-
if (prev.props.assetId !== next.props.assetId) {
|
|
140
|
+
if (prev.props.assetId !== next.props.assetId || prev.props.url !== next.props.url) {
|
|
139
141
|
return setBookmarkHeight(this.editor, next)
|
|
140
142
|
}
|
|
141
143
|
|
|
@@ -175,10 +177,12 @@ export function BookmarkShapeComponent({
|
|
|
175
177
|
const isSafariExport = !!useSvgExportContext() && tlenv.isSafari
|
|
176
178
|
|
|
177
179
|
const address = getHumanReadableAddress(url)
|
|
180
|
+
const title = asset ? asset.props.title : isUrlOnlyBookmarkUrl(url) ? url : ''
|
|
178
181
|
|
|
179
182
|
const [isFaviconValid, setIsFaviconValid] = useState(true)
|
|
180
183
|
const onFaviconError = () => setIsFaviconValid(false)
|
|
181
184
|
|
|
185
|
+
const handleOpenLink = useOpenLinkHandler(url)
|
|
182
186
|
const markAsHandledOnShiftKey = useCallback<PointerEventHandler>(
|
|
183
187
|
(e) => {
|
|
184
188
|
if (!editor.inputs.getShiftKey()) editor.markEventAsHandled(e)
|
|
@@ -198,7 +202,7 @@ export function BookmarkShapeComponent({
|
|
|
198
202
|
maxHeight: h,
|
|
199
203
|
}}
|
|
200
204
|
>
|
|
201
|
-
{showImageContainer && (
|
|
205
|
+
{showImageContainer && (asset ? asset.props.image : !isUrlOnlyBookmarkUrl(url)) && (
|
|
202
206
|
<div className="tl-bookmark__image_container">
|
|
203
207
|
{asset ? (
|
|
204
208
|
<img
|
|
@@ -215,7 +219,7 @@ export function BookmarkShapeComponent({
|
|
|
215
219
|
</div>
|
|
216
220
|
)}
|
|
217
221
|
<div className="tl-bookmark__copy_container">
|
|
218
|
-
{
|
|
222
|
+
{title ? (
|
|
219
223
|
<a
|
|
220
224
|
className="tl-bookmark__link"
|
|
221
225
|
href={url || ''}
|
|
@@ -224,10 +228,10 @@ export function BookmarkShapeComponent({
|
|
|
224
228
|
draggable={false}
|
|
225
229
|
onPointerDown={markAsHandledOnShiftKey}
|
|
226
230
|
onPointerUp={markAsHandledOnShiftKey}
|
|
231
|
+
onClick={handleOpenLink}
|
|
232
|
+
onAuxClick={handleOpenLink}
|
|
227
233
|
>
|
|
228
|
-
<h2 className="tl-bookmark__heading">
|
|
229
|
-
{convertCommonTitleHTMLEntities(asset.props.title)}
|
|
230
|
-
</h2>
|
|
234
|
+
<h2 className="tl-bookmark__heading">{convertCommonTitleHTMLEntities(title)}</h2>
|
|
231
235
|
</a>
|
|
232
236
|
) : null}
|
|
233
237
|
{asset?.props.description && asset?.props.image ? (
|
|
@@ -241,6 +245,8 @@ export function BookmarkShapeComponent({
|
|
|
241
245
|
draggable={false}
|
|
242
246
|
onPointerDown={markAsHandledOnShiftKey}
|
|
243
247
|
onPointerUp={markAsHandledOnShiftKey}
|
|
248
|
+
onClick={handleOpenLink}
|
|
249
|
+
onAuxClick={handleOpenLink}
|
|
244
250
|
>
|
|
245
251
|
{isFaviconValid && asset?.props.favicon ? (
|
|
246
252
|
<img
|
|
@@ -15,9 +15,32 @@ import {
|
|
|
15
15
|
export const BOOKMARK_WIDTH = 300
|
|
16
16
|
export const BOOKMARK_HEIGHT = 320
|
|
17
17
|
export const BOOKMARK_JUST_URL_HEIGHT = 46
|
|
18
|
-
const SHORT_BOOKMARK_HEIGHT = 101
|
|
18
|
+
export const SHORT_BOOKMARK_HEIGHT = 101
|
|
19
19
|
|
|
20
|
-
|
|
20
|
+
// A bookmark asset's `src` is a `T.srcUrl`, which rejects app links and `mailto:`. Not
|
|
21
|
+
// `T.httpUrl`: it accepts `''` and relative paths, so clearing a bookmark's url would unfurl.
|
|
22
|
+
function canUnfurlUrl(url: string) {
|
|
23
|
+
try {
|
|
24
|
+
const { protocol } = new URL(url)
|
|
25
|
+
return protocol === 'http:' || protocol === 'https:'
|
|
26
|
+
} catch {
|
|
27
|
+
return false
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Whether a bookmark without an asset will never get one, rather than still loading. Without
|
|
33
|
+
* this, an app link bookmark shows the loading placeholder forever.
|
|
34
|
+
*/
|
|
35
|
+
export function isUrlOnlyBookmarkUrl(url: string) {
|
|
36
|
+
return url !== '' && !canUnfurlUrl(url)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function getBookmarkHeight(
|
|
40
|
+
editor: Editor,
|
|
41
|
+
assetId: TLAssetId | null | undefined,
|
|
42
|
+
url: string
|
|
43
|
+
) {
|
|
21
44
|
const asset = (assetId ? editor.getAsset(assetId) : null) as TLBookmarkAsset | null
|
|
22
45
|
|
|
23
46
|
if (asset) {
|
|
@@ -28,6 +51,8 @@ export function getBookmarkHeight(editor: Editor, assetId?: TLAssetId | null) {
|
|
|
28
51
|
return SHORT_BOOKMARK_HEIGHT
|
|
29
52
|
}
|
|
30
53
|
}
|
|
54
|
+
} else if (isUrlOnlyBookmarkUrl(url)) {
|
|
55
|
+
return SHORT_BOOKMARK_HEIGHT
|
|
31
56
|
}
|
|
32
57
|
|
|
33
58
|
return BOOKMARK_HEIGHT
|
|
@@ -36,7 +61,10 @@ export function getBookmarkHeight(editor: Editor, assetId?: TLAssetId | null) {
|
|
|
36
61
|
export function setBookmarkHeight(editor: Editor, shape: TLBookmarkShape) {
|
|
37
62
|
return {
|
|
38
63
|
...shape,
|
|
39
|
-
props: {
|
|
64
|
+
props: {
|
|
65
|
+
...shape.props,
|
|
66
|
+
h: getBookmarkHeight(editor, shape.props.assetId, shape.props.url),
|
|
67
|
+
},
|
|
40
68
|
}
|
|
41
69
|
}
|
|
42
70
|
|
|
@@ -44,6 +72,8 @@ export function setBookmarkHeight(editor: Editor, shape: TLBookmarkShape) {
|
|
|
44
72
|
export function getHumanReadableAddress(url: string) {
|
|
45
73
|
try {
|
|
46
74
|
const objUrl = new URL(url)
|
|
75
|
+
// An app link's host (`file` in `vscode://file/…`) doesn't say where it goes, but its app does.
|
|
76
|
+
if (isUrlOnlyBookmarkUrl(url)) return objUrl.protocol.slice(0, -1)
|
|
47
77
|
// we want the hostname without any www
|
|
48
78
|
return objUrl.hostname.replace(/^www\./, '')
|
|
49
79
|
} catch {
|
|
@@ -113,13 +143,14 @@ export function getResolvedBookmarkAssetId(
|
|
|
113
143
|
export function getBookmarkShapeHeight(editor: Editor, shape: TLBookmarkShape): number {
|
|
114
144
|
const resolvedAssetId = getResolvedBookmarkAssetId(editor, shape.props.assetId, shape.props.url)
|
|
115
145
|
if (resolvedAssetId === shape.props.assetId) return shape.props.h
|
|
116
|
-
return getBookmarkHeight(editor, resolvedAssetId)
|
|
146
|
+
return getBookmarkHeight(editor, resolvedAssetId, shape.props.url)
|
|
117
147
|
}
|
|
118
148
|
|
|
119
149
|
async function _createBookmarkAssetOnUrlChange(editor: Editor, shape: TLBookmarkShape) {
|
|
120
150
|
if (editor.isDisposed) return
|
|
121
151
|
|
|
122
152
|
const { url } = shape.props
|
|
153
|
+
if (!canUnfurlUrl(url)) return
|
|
123
154
|
|
|
124
155
|
// Create the asset using the external content manager's createAssetFromUrl method.
|
|
125
156
|
// This may be overwritten by the user (for example, we overwrite it on tldraw.com)
|
|
@@ -200,7 +231,7 @@ export async function createBookmarkFromUrl(
|
|
|
200
231
|
url,
|
|
201
232
|
assetId: existingAsset?.id ?? null,
|
|
202
233
|
w: BOOKMARK_WIDTH,
|
|
203
|
-
h: getBookmarkHeight(editor, existingAsset?.id),
|
|
234
|
+
h: getBookmarkHeight(editor, existingAsset?.id, url),
|
|
204
235
|
},
|
|
205
236
|
}
|
|
206
237
|
|
|
@@ -230,6 +261,8 @@ export async function createBookmarkFromUrl(
|
|
|
230
261
|
}
|
|
231
262
|
|
|
232
263
|
async function hydrateBookmarkShape(editor: Editor, shapeId: TLShapeId, url: string) {
|
|
264
|
+
if (!canUnfurlUrl(url)) return
|
|
265
|
+
|
|
233
266
|
let asset
|
|
234
267
|
try {
|
|
235
268
|
asset = await editor.getAssetForExternalContent({ type: 'url', url })
|
|
@@ -2,6 +2,7 @@ import { useEditor } from '@tldraw/editor'
|
|
|
2
2
|
import classNames from 'classnames'
|
|
3
3
|
import { PointerEventHandler, useCallback } from 'react'
|
|
4
4
|
import { useEfficientZoomThreshold } from './useEfficientZoomThreshold'
|
|
5
|
+
import { useOpenLinkHandler } from './useOpenLinkHandler'
|
|
5
6
|
|
|
6
7
|
const LINK_ICON =
|
|
7
8
|
"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='30' height='30' fill='none'%3E%3Cpath stroke='%23000' stroke-linecap='round' stroke-linejoin='round' stroke-width='2' d='M13 5H7a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h16a2 2 0 0 0 2-2v-6M19 5h6m0 0v6m0-6L13 17'/%3E%3C/svg%3E"
|
|
@@ -9,6 +10,7 @@ const LINK_ICON =
|
|
|
9
10
|
export function HyperlinkButton({ url }: { url: string }) {
|
|
10
11
|
const editor = useEditor()
|
|
11
12
|
const hideButton = useEfficientZoomThreshold()
|
|
13
|
+
const handleOpenLink = useOpenLinkHandler(url)
|
|
12
14
|
const markAsHandledOnShiftKey = useCallback<PointerEventHandler>(
|
|
13
15
|
(e) => {
|
|
14
16
|
if (!editor.inputs.getShiftKey()) editor.markEventAsHandled(e)
|
|
@@ -25,6 +27,8 @@ export function HyperlinkButton({ url }: { url: string }) {
|
|
|
25
27
|
rel="noopener noreferrer"
|
|
26
28
|
onPointerDown={markAsHandledOnShiftKey}
|
|
27
29
|
onPointerUp={markAsHandledOnShiftKey}
|
|
30
|
+
onClick={handleOpenLink}
|
|
31
|
+
onAuxClick={handleOpenLink}
|
|
28
32
|
title={url}
|
|
29
33
|
draggable={false}
|
|
30
34
|
>
|
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
TLEventInfo,
|
|
5
5
|
TLRichText,
|
|
6
6
|
TLShapeId,
|
|
7
|
-
openWindow,
|
|
8
7
|
preventDefault,
|
|
9
8
|
resolveLineHeightPx,
|
|
10
9
|
useEditor,
|
|
@@ -13,6 +12,7 @@ import {
|
|
|
13
12
|
} from '@tldraw/editor'
|
|
14
13
|
import classNames from 'classnames'
|
|
15
14
|
import React, { useMemo } from 'react'
|
|
15
|
+
import { openLink } from '../../utils/openLink'
|
|
16
16
|
import { renderHtmlFromRichText } from '../../utils/text/richText'
|
|
17
17
|
import { RichTextArea } from '../text/RichTextArea'
|
|
18
18
|
import { isLegacyAlign } from './legacyProps'
|
|
@@ -115,7 +115,7 @@ export const RichTextLabel = React.memo(function RichTextLabel({
|
|
|
115
115
|
if (e.name !== 'pointer_up' || !link) return
|
|
116
116
|
|
|
117
117
|
if (!isDragging.current) {
|
|
118
|
-
|
|
118
|
+
openLink(editor, link)
|
|
119
119
|
}
|
|
120
120
|
editor.off('event', handlePointerUp)
|
|
121
121
|
}
|
|
@@ -123,6 +123,20 @@ export const RichTextLabel = React.memo(function RichTextLabel({
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
// Mouse presses on a link are handled in handlePointerDown, since the canvas captures the pointer
|
|
127
|
+
// and the anchor never gets their click. A click that does reach it (Enter on a focused link)
|
|
128
|
+
// would follow the href and skip openLink's check, so route it through openLink here.
|
|
129
|
+
const handleLinkClick = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
130
|
+
if (e.type === 'auxclick' && e.button !== 1) return
|
|
131
|
+
const HTMLElementCtor = editor.getContainerWindow().HTMLElement
|
|
132
|
+
if (!(e.target instanceof HTMLElementCtor)) return
|
|
133
|
+
const anchor = e.target.closest('a')
|
|
134
|
+
if (!anchor) return
|
|
135
|
+
preventDefault(e)
|
|
136
|
+
// A mouse click that gets here was already opened on pointer up; only open keyboard clicks.
|
|
137
|
+
if (e.detail === 0) openLink(editor, anchor.getAttribute('href') ?? '')
|
|
138
|
+
}
|
|
139
|
+
|
|
126
140
|
// Should be guarded higher up so that this doesn't render... but repeated here. This should never be true.
|
|
127
141
|
if (!isEditing && isEmpty) return null
|
|
128
142
|
|
|
@@ -182,6 +196,8 @@ export const RichTextLabel = React.memo(function RichTextLabel({
|
|
|
182
196
|
// todo: see if I can abuse this
|
|
183
197
|
dangerouslySetInnerHTML={{ __html: html || '' }}
|
|
184
198
|
onPointerDown={handlePointerDown}
|
|
199
|
+
onClick={handleLinkClick}
|
|
200
|
+
onAuxClick={handleLinkClick}
|
|
185
201
|
data-is-ready-for-editing={isReadyForEditing}
|
|
186
202
|
/>
|
|
187
203
|
)}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useEditor } from '@tldraw/editor'
|
|
2
|
+
import { MouseEventHandler, useCallback } from 'react'
|
|
3
|
+
import { openLink } from '../../utils/openLink'
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Click handler for an `<a href>` that holds a user-provided link. Letting the browser follow the
|
|
7
|
+
* href would skip {@link openLink}'s check, so a modified or middle click on an unknown app link
|
|
8
|
+
* would open it without asking. Use it for both `onClick` and `onAuxClick`.
|
|
9
|
+
*/
|
|
10
|
+
export function useOpenLinkHandler(url: string) {
|
|
11
|
+
const editor = useEditor()
|
|
12
|
+
return useCallback<MouseEventHandler>(
|
|
13
|
+
(e) => {
|
|
14
|
+
if (e.type === 'auxclick' && e.button !== 1) return
|
|
15
|
+
e.preventDefault()
|
|
16
|
+
openLink(editor, url)
|
|
17
|
+
},
|
|
18
|
+
[editor, url]
|
|
19
|
+
)
|
|
20
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { openWindow } from '@tldraw/editor'
|
|
2
|
+
import { useCallback } from 'react'
|
|
3
|
+
import { TLUiDialogProps } from '../context/dialogs'
|
|
4
|
+
import { F } from '../context/i18n'
|
|
5
|
+
import { TldrawUiButton } from './primitives/Button/TldrawUiButton'
|
|
6
|
+
import { TldrawUiButtonLabel } from './primitives/Button/TldrawUiButtonLabel'
|
|
7
|
+
import {
|
|
8
|
+
TldrawUiDialogBody,
|
|
9
|
+
TldrawUiDialogCloseButton,
|
|
10
|
+
TldrawUiDialogFooter,
|
|
11
|
+
TldrawUiDialogHeader,
|
|
12
|
+
TldrawUiDialogTitle,
|
|
13
|
+
} from './primitives/TldrawUiDialog'
|
|
14
|
+
|
|
15
|
+
/** @internal */
|
|
16
|
+
export function ConfirmOpenLinkDialog({ url, onClose }: TLUiDialogProps & { url: string }) {
|
|
17
|
+
const handleOpen = useCallback(() => {
|
|
18
|
+
openWindow(url, '_blank')
|
|
19
|
+
onClose()
|
|
20
|
+
}, [url, onClose])
|
|
21
|
+
|
|
22
|
+
return (
|
|
23
|
+
<>
|
|
24
|
+
<TldrawUiDialogHeader>
|
|
25
|
+
<TldrawUiDialogTitle>
|
|
26
|
+
<F defaultMessage="Open external link?" id="confirm-open-link-dialog.title" />
|
|
27
|
+
</TldrawUiDialogTitle>
|
|
28
|
+
<TldrawUiDialogCloseButton />
|
|
29
|
+
</TldrawUiDialogHeader>
|
|
30
|
+
<TldrawUiDialogBody style={{ maxWidth: 350 }}>
|
|
31
|
+
<p>
|
|
32
|
+
<F
|
|
33
|
+
defaultMessage="This link opens another app on your device. Only continue if you trust where it came from."
|
|
34
|
+
id="confirm-open-link-dialog.detail"
|
|
35
|
+
/>
|
|
36
|
+
</p>
|
|
37
|
+
<p className="tlui-confirm-open-link-dialog__url">{url}</p>
|
|
38
|
+
</TldrawUiDialogBody>
|
|
39
|
+
<TldrawUiDialogFooter className="tlui-dialog__footer__actions">
|
|
40
|
+
<TldrawUiButton type="normal" onClick={onClose}>
|
|
41
|
+
<TldrawUiButtonLabel>
|
|
42
|
+
<F defaultMessage="Cancel" id="confirm-open-link-dialog.cancel" />
|
|
43
|
+
</TldrawUiButtonLabel>
|
|
44
|
+
</TldrawUiButton>
|
|
45
|
+
<TldrawUiButton type="primary" onClick={handleOpen}>
|
|
46
|
+
<TldrawUiButtonLabel>
|
|
47
|
+
<F defaultMessage="Open link" id="confirm-open-link-dialog.open" />
|
|
48
|
+
</TldrawUiButtonLabel>
|
|
49
|
+
</TldrawUiButton>
|
|
50
|
+
</TldrawUiDialogFooter>
|
|
51
|
+
</>
|
|
52
|
+
)
|
|
53
|
+
}
|