tldraw 5.6.0 → 5.6.1
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 +2 -1
- package/RELEASE_NOTES.md +106 -3
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/lib/shapes/bookmark/BookmarkShapeUtil.js +5 -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/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 +46 -19
- package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +3 -3
- 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/text/richText.js +4 -1
- package/dist-cjs/lib/utils/text/richText.js.map +2 -2
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/lib/shapes/bookmark/BookmarkShapeUtil.mjs +6 -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/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 +36 -19
- package/dist-esm/lib/ui/components/Toolbar/LinkEditor.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/text/richText.mjs +5 -1
- package/dist-esm/lib/utils/text/richText.mjs.map +2 -2
- package/package.json +6 -6
- package/src/lib/shapes/bookmark/BookmarkShapeUtil.tsx +6 -6
- package/src/lib/shapes/bookmark/bookmarks.ts +38 -5
- package/src/lib/ui/components/EditLinkDialog.tsx +22 -26
- package/src/lib/ui/components/Toolbar/LinkEditor.tsx +38 -20
- package/src/lib/ui/version.ts +2 -2
- package/src/lib/ui.css +9 -2
- package/src/lib/utils/linkUrl.test.ts +33 -0
- package/src/lib/utils/linkUrl.ts +30 -0
- package/src/lib/utils/text/richText.ts +4 -0
- package/src/test/bookmark-shapes.test.ts +62 -2
- package/src/test/ui/EditLinkDialog.test.tsx +53 -2
- package/src/test/ui/LinkEditor.test.tsx +71 -0
- package/tldraw.css +9 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/ui/components/EditLinkDialog.tsx"],
|
|
4
|
-
"sourcesContent": ["import { defineMessages,
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;
|
|
4
|
+
"sourcesContent": ["import { defineMessages, TLShape, track, useEditor } from '@tldraw/editor'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { normalizeLinkUrl } from '../../utils/linkUrl'\nimport { isShapeWithLink, TLShapeWithLink } from '../../utils/shapes/shapes'\nimport { TLUiDialogProps } from '../context/dialogs'\nimport { F } from '../context/i18n'\nimport { TldrawUiButton } from './primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonLabel } from './primitives/Button/TldrawUiButtonLabel'\nimport {\n\tTldrawUiDialogBody,\n\tTldrawUiDialogCloseButton,\n\tTldrawUiDialogFooter,\n\tTldrawUiDialogHeader,\n\tTldrawUiDialogTitle,\n} from './primitives/TldrawUiDialog'\nimport { TldrawUiInput } from './primitives/TldrawUiInput'\n\nfunction getUrlInputState(url: string) {\n\tconst normalized = normalizeLinkUrl(url)\n\treturn { actual: url, safe: normalized ?? '', valid: normalized !== null }\n}\n\nfunction assertShapeWithLink(shape: TLShape | null | undefined): asserts shape is TLShapeWithLink {\n\tif (!isShapeWithLink(shape)) {\n\t\tthrow new Error('Shape is not a valid TLShapeWithLink')\n\t}\n}\n\nconst messages = defineMessages({\n\t// `TldrawUiInput` takes its label as data, not as an element, so this one can't be an `<F>`.\n\turl: { id: 'edit-link-dialog.url', defaultMessage: 'URL' },\n})\n\nexport const EditLinkDialog = track(function EditLinkDialog({ onClose }: TLUiDialogProps) {\n\tconst editor = useEditor()\n\n\tconst selectedShape = editor.getOnlySelectedShape()\n\tconst hasShapeWithLink = isShapeWithLink(selectedShape)\n\n\t// The shape can be deleted or deselected from under the open dialog (a collaborator, or a\n\t// keypress reaching the canvas). Returning null on its own would leave an empty dialog frame.\n\tuseEffect(() => {\n\t\tif (!hasShapeWithLink) onClose()\n\t}, [hasShapeWithLink, onClose])\n\n\tif (!hasShapeWithLink) {\n\t\treturn null\n\t}\n\n\treturn <EditLinkDialogInner onClose={onClose} selectedShape={selectedShape} />\n})\n\nexport const EditLinkDialogInner = track(function EditLinkDialogInner({\n\tonClose,\n\tselectedShape,\n}: TLUiDialogProps & { selectedShape: TLShapeWithLink }) {\n\tconst editor = useEditor()\n\n\tconst rInput = useRef<HTMLInputElement>(null)\n\n\tuseEffect(() => {\n\t\teditor.timers.requestAnimationFrame(() => rInput.current?.focus())\n\t}, [editor])\n\n\tconst rInitialValue = useRef(selectedShape.props.url)\n\n\tconst [urlInputState, setUrlInputState] = useState(() => {\n\t\tconst { safe } = getUrlInputState(selectedShape.props.url)\n\t\treturn { actual: safe, safe, valid: true }\n\t})\n\n\tconst [showInvalid, setShowInvalid] = useState(false)\n\n\tconst handleChange = useCallback((rawValue: string) => {\n\t\tsetUrlInputState(getUrlInputState(rawValue))\n\t\tsetShowInvalid(false)\n\t}, [])\n\n\tconst handleClear = useCallback(() => {\n\t\tconst onlySelectedShape = editor.getOnlySelectedShape()\n\t\tif (!onlySelectedShape) return\n\t\tassertShapeWithLink(onlySelectedShape)\n\t\teditor.updateShapes([\n\t\t\t{ id: onlySelectedShape.id, type: onlySelectedShape.type, props: { url: '' } },\n\t\t])\n\t\tonClose()\n\t}, [editor, onClose])\n\n\tconst handleComplete = useCallback(() => {\n\t\tconst onlySelectedShape = editor.getOnlySelectedShape()\n\n\t\tif (!onlySelectedShape) return\n\t\tassertShapeWithLink(onlySelectedShape)\n\n\t\t// Enter reaches here even while the save button is disabled.\n\t\tif (!urlInputState.valid) {\n\t\t\tsetShowInvalid(true)\n\t\t\trInput.current?.focus()\n\t\t\treturn\n\t\t}\n\n\t\tif (onlySelectedShape.props.url !== urlInputState.safe) {\n\t\t\teditor.updateShapes([\n\t\t\t\t{\n\t\t\t\t\tid: onlySelectedShape.id,\n\t\t\t\t\ttype: onlySelectedShape.type,\n\t\t\t\t\tprops: { url: urlInputState.safe },\n\t\t\t\t},\n\t\t\t])\n\t\t}\n\t\tonClose()\n\t}, [editor, onClose, urlInputState])\n\n\tconst handleCancel = useCallback(() => {\n\t\tonClose()\n\t}, [onClose])\n\n\tconst isEmpty = urlInputState.valid && urlInputState.safe === ''\n\t// Only an empty field clears a link, so a typo can't delete it.\n\tconst isRemoving = !!rInitialValue.current && isEmpty\n\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiDialogHeader>\n\t\t\t\t<TldrawUiDialogTitle>\n\t\t\t\t\t<F defaultMessage=\"Edit link\" id=\"edit-link-dialog.title\" />\n\t\t\t\t</TldrawUiDialogTitle>\n\t\t\t\t<TldrawUiDialogCloseButton />\n\t\t\t</TldrawUiDialogHeader>\n\t\t\t<TldrawUiDialogBody>\n\t\t\t\t<div className=\"tlui-edit-link-dialog\">\n\t\t\t\t\t<TldrawUiInput\n\t\t\t\t\t\tref={rInput}\n\t\t\t\t\t\tclassName=\"tlui-edit-link-dialog__input\"\n\t\t\t\t\t\tlabel={messages.url.id}\n\t\t\t\t\t\tautoFocus\n\t\t\t\t\t\tautoSelect\n\t\t\t\t\t\tplaceholder=\"https://example.com\"\n\t\t\t\t\t\tvalue={urlInputState.actual}\n\t\t\t\t\t\tonValueChange={handleChange}\n\t\t\t\t\t\tonComplete={handleComplete}\n\t\t\t\t\t\tonCancel={handleCancel}\n\t\t\t\t\t/>\n\t\t\t\t\t<div>\n\t\t\t\t\t\t{showInvalid ? (\n\t\t\t\t\t\t\t<F defaultMessage=\"A link must be a valid URL.\" id=\"edit-link-dialog.invalid-url\" />\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<F defaultMessage=\"Links will open in a new tab.\" id=\"edit-link-dialog.detail\" />\n\t\t\t\t\t\t)}\n\t\t\t\t\t</div>\n\t\t\t\t</div>\n\t\t\t</TldrawUiDialogBody>\n\t\t\t<TldrawUiDialogFooter className=\"tlui-dialog__footer__actions\">\n\t\t\t\t<TldrawUiButton type=\"normal\" onClick={handleCancel} onTouchEnd={handleCancel}>\n\t\t\t\t\t<TldrawUiButtonLabel>\n\t\t\t\t\t\t<F defaultMessage=\"Cancel\" id=\"edit-link-dialog.cancel\" />\n\t\t\t\t\t</TldrawUiButtonLabel>\n\t\t\t\t</TldrawUiButton>\n\t\t\t\t{isRemoving ? (\n\t\t\t\t\t<TldrawUiButton type=\"danger\" onTouchEnd={handleClear} onClick={handleClear}>\n\t\t\t\t\t\t<TldrawUiButtonLabel>\n\t\t\t\t\t\t\t<F defaultMessage=\"Clear\" id=\"edit-link-dialog.clear\" />\n\t\t\t\t\t\t</TldrawUiButtonLabel>\n\t\t\t\t\t</TldrawUiButton>\n\t\t\t\t) : (\n\t\t\t\t\t<TldrawUiButton\n\t\t\t\t\t\ttype=\"primary\"\n\t\t\t\t\t\tdisabled={!urlInputState.valid || isEmpty}\n\t\t\t\t\t\tonTouchEnd={handleComplete}\n\t\t\t\t\t\tonClick={handleComplete}\n\t\t\t\t\t>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UAClC,YAAY;AAAA,UACZ,SAAS;AAAA,UAET,sDAAC,kDACA,sDAAC,iBAAE,gBAAe,YAAW,IAAG,yBAAwB,GACzD;AAAA;AAAA,MACD;AAAA,OAEF;AAAA,KACD;AAEF,CAAC;",
|
|
6
6
|
"names": ["EditLinkDialog", "EditLinkDialogInner"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
var LinkEditor_exports = {};
|
|
20
30
|
__export(LinkEditor_exports, {
|
|
@@ -23,7 +33,9 @@ __export(LinkEditor_exports, {
|
|
|
23
33
|
module.exports = __toCommonJS(LinkEditor_exports);
|
|
24
34
|
var import_jsx_runtime = require("react/jsx-runtime");
|
|
25
35
|
var import_editor = require("@tldraw/editor");
|
|
36
|
+
var import_classnames = __toESM(require("classnames"), 1);
|
|
26
37
|
var import_react = require("react");
|
|
38
|
+
var import_linkUrl = require("../../../utils/linkUrl");
|
|
27
39
|
var import_events = require("../../context/events");
|
|
28
40
|
var import_useTranslation = require("../../hooks/useTranslation/useTranslation");
|
|
29
41
|
var import_TldrawUiButton = require("../primitives/Button/TldrawUiButton");
|
|
@@ -36,18 +48,31 @@ const messages = (0, import_editor.defineMessages)({
|
|
|
36
48
|
function LinkEditor({ textEditor, value: initialValue, onClose }) {
|
|
37
49
|
const editor = (0, import_editor.useEditor)();
|
|
38
50
|
const [value, setValue] = (0, import_react.useState)(initialValue);
|
|
51
|
+
const [isInvalid, setIsInvalid] = (0, import_react.useState)(false);
|
|
39
52
|
const msg = (0, import_useTranslation.useTranslation)();
|
|
40
53
|
const ref = (0, import_react.useRef)(null);
|
|
41
54
|
const trackEvent = (0, import_events.useUiEvents)();
|
|
42
55
|
const source = "rich-text-menu";
|
|
43
|
-
const
|
|
56
|
+
const normalizedValue = (0, import_linkUrl.normalizeLinkUrl)(value);
|
|
57
|
+
const handleRemoveLink = (0, import_react.useCallback)(() => {
|
|
58
|
+
trackEvent("rich-text", { operation: "link-remove", source });
|
|
59
|
+
textEditor.chain().unsetLink().focus().run();
|
|
60
|
+
onClose();
|
|
61
|
+
}, [trackEvent, source, textEditor, onClose]);
|
|
44
62
|
const handleLinkComplete = (0, import_react.useCallback)(
|
|
45
63
|
(link) => {
|
|
46
|
-
|
|
47
|
-
if (
|
|
48
|
-
|
|
64
|
+
const href = (0, import_linkUrl.normalizeLinkUrl)(link);
|
|
65
|
+
if (href === null) {
|
|
66
|
+
setIsInvalid(true);
|
|
67
|
+
ref.current?.focus();
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (href === "") {
|
|
71
|
+
handleRemoveLink();
|
|
72
|
+
return;
|
|
49
73
|
}
|
|
50
|
-
|
|
74
|
+
trackEvent("rich-text", { operation: "link-edit", source });
|
|
75
|
+
textEditor.chain().setLink({ href }).run();
|
|
51
76
|
if (editor.getInstanceState().isCoarsePointer) {
|
|
52
77
|
textEditor.commands.blur();
|
|
53
78
|
} else {
|
|
@@ -55,49 +80,51 @@ function LinkEditor({ textEditor, value: initialValue, onClose }) {
|
|
|
55
80
|
}
|
|
56
81
|
onClose();
|
|
57
82
|
},
|
|
58
|
-
[trackEvent, source, textEditor, editor, onClose]
|
|
83
|
+
[trackEvent, source, textEditor, editor, onClose, handleRemoveLink]
|
|
59
84
|
);
|
|
60
85
|
const handleVisitLink = () => {
|
|
61
86
|
trackEvent("rich-text", { operation: "link-visit", source });
|
|
62
|
-
(0, import_editor.openWindow)(
|
|
87
|
+
if (normalizedValue) (0, import_editor.openWindow)(normalizedValue, "_blank");
|
|
63
88
|
onClose();
|
|
64
89
|
};
|
|
65
|
-
const handleRemoveLink = (0, import_react.useCallback)(() => {
|
|
66
|
-
trackEvent("rich-text", { operation: "link-remove", source });
|
|
67
|
-
textEditor.chain().unsetLink().focus().run();
|
|
68
|
-
onClose();
|
|
69
|
-
}, [trackEvent, source, textEditor, onClose]);
|
|
70
90
|
(0, import_react.useEffect)(() => {
|
|
71
91
|
const doc = editor.getContainerDocument();
|
|
72
92
|
const handlePointerDown = (e) => {
|
|
73
93
|
const toolbar = doc.querySelector(".tlui-rich-text__toolbar");
|
|
74
94
|
if (toolbar?.contains(e.target)) return;
|
|
75
|
-
if (
|
|
76
|
-
|
|
95
|
+
if (normalizedValue === null) {
|
|
96
|
+
onClose();
|
|
77
97
|
} else {
|
|
78
|
-
|
|
98
|
+
handleLinkComplete(value);
|
|
79
99
|
}
|
|
80
100
|
};
|
|
81
101
|
doc.addEventListener("pointerdown", handlePointerDown, { capture: true });
|
|
82
102
|
return () => {
|
|
83
103
|
doc.removeEventListener("pointerdown", handlePointerDown, { capture: true });
|
|
84
104
|
};
|
|
85
|
-
}, [editor, handleLinkComplete,
|
|
105
|
+
}, [editor, handleLinkComplete, onClose, normalizedValue, value]);
|
|
86
106
|
(0, import_react.useEffect)(() => {
|
|
87
107
|
ref.current?.focus();
|
|
88
108
|
}, [value]);
|
|
89
109
|
(0, import_react.useEffect)(() => {
|
|
90
110
|
setValue(initialValue);
|
|
111
|
+
setIsInvalid(false);
|
|
91
112
|
}, [initialValue]);
|
|
113
|
+
const handleValueChange = (0, import_react.useCallback)((nextValue) => {
|
|
114
|
+
setValue(nextValue);
|
|
115
|
+
setIsInvalid(false);
|
|
116
|
+
}, []);
|
|
92
117
|
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
93
118
|
/* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
94
119
|
import_TldrawUiInput.TldrawUiInput,
|
|
95
120
|
{
|
|
96
121
|
ref,
|
|
97
122
|
"data-testid": "rich-text.link-input",
|
|
98
|
-
className: "tlui-rich-text__toolbar-link-input",
|
|
123
|
+
className: (0, import_classnames.default)("tlui-rich-text__toolbar-link-input", {
|
|
124
|
+
"tlui-rich-text__toolbar-link-input--invalid": isInvalid
|
|
125
|
+
}),
|
|
99
126
|
value,
|
|
100
|
-
onValueChange:
|
|
127
|
+
onValueChange: handleValueChange,
|
|
101
128
|
onComplete: handleLinkComplete,
|
|
102
129
|
onCancel: onClose,
|
|
103
130
|
placeholder: "example.com",
|
|
@@ -112,7 +139,7 @@ function LinkEditor({ textEditor, value: initialValue, onClose }) {
|
|
|
112
139
|
type: "icon",
|
|
113
140
|
onPointerDown: import_editor.preventDefault,
|
|
114
141
|
onClick: handleVisitLink,
|
|
115
|
-
disabled: !
|
|
142
|
+
disabled: !normalizedValue,
|
|
116
143
|
children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_TldrawUiButtonIcon.TldrawUiButtonIcon, { small: true, icon: "external-link" })
|
|
117
144
|
}
|
|
118
145
|
),
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/ui/components/Toolbar/LinkEditor.tsx"],
|
|
4
|
-
"sourcesContent": ["import { defineMessages, openWindow, preventDefault, TiptapEditor, useEditor } from '@tldraw/editor'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { useUiEvents } from '../../context/events'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButton } from '../primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport { TldrawUiInput } from '../primitives/TldrawUiInput'\n\nconst messages = defineMessages({\n\ttoolRichTextLinkRemove: { id: 'tool.rich-text-link-remove', defaultMessage: 'Remove link' },\n\ttoolRichTextLinkVisit: { id: 'tool.rich-text-link-visit', defaultMessage: 'Visit link' },\n})\n\n/** @public */\nexport interface LinkEditorProps {\n\ttextEditor: TiptapEditor\n\tvalue: string\n\tonClose(): void\n}\n\n/** @public @react */\nexport function LinkEditor({ textEditor, value: initialValue, onClose }: LinkEditorProps) {\n\tconst editor = useEditor()\n\tconst [value, setValue] = useState(initialValue)\n\tconst msg = useTranslation()\n\tconst ref = useRef<HTMLInputElement>(null)\n\tconst trackEvent = useUiEvents()\n\tconst source = 'rich-text-menu'\n\tconst
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": []
|
|
4
|
+
"sourcesContent": ["import { defineMessages, openWindow, preventDefault, TiptapEditor, useEditor } from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { useCallback, useEffect, useRef, useState } from 'react'\nimport { normalizeLinkUrl } from '../../../utils/linkUrl'\nimport { useUiEvents } from '../../context/events'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { TldrawUiButton } from '../primitives/Button/TldrawUiButton'\nimport { TldrawUiButtonIcon } from '../primitives/Button/TldrawUiButtonIcon'\nimport { TldrawUiInput } from '../primitives/TldrawUiInput'\n\nconst messages = defineMessages({\n\ttoolRichTextLinkRemove: { id: 'tool.rich-text-link-remove', defaultMessage: 'Remove link' },\n\ttoolRichTextLinkVisit: { id: 'tool.rich-text-link-visit', defaultMessage: 'Visit link' },\n})\n\n/** @public */\nexport interface LinkEditorProps {\n\ttextEditor: TiptapEditor\n\tvalue: string\n\tonClose(): void\n}\n\n/** @public @react */\nexport function LinkEditor({ textEditor, value: initialValue, onClose }: LinkEditorProps) {\n\tconst editor = useEditor()\n\tconst [value, setValue] = useState(initialValue)\n\tconst [isInvalid, setIsInvalid] = useState(false)\n\tconst msg = useTranslation()\n\tconst ref = useRef<HTMLInputElement>(null)\n\tconst trackEvent = useUiEvents()\n\tconst source = 'rich-text-menu'\n\tconst normalizedValue = normalizeLinkUrl(value)\n\n\tconst handleRemoveLink = useCallback(() => {\n\t\ttrackEvent('rich-text', { operation: 'link-remove', source })\n\t\ttextEditor.chain().unsetLink().focus().run()\n\t\tonClose()\n\t}, [trackEvent, source, textEditor, onClose])\n\n\tconst handleLinkComplete = useCallback(\n\t\t(link: string) => {\n\t\t\tconst href = normalizeLinkUrl(link)\n\t\t\tif (href === null) {\n\t\t\t\tsetIsInvalid(true)\n\t\t\t\tref.current?.focus()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tif (href === '') {\n\t\t\t\thandleRemoveLink()\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\ttrackEvent('rich-text', { operation: 'link-edit', source })\n\t\t\ttextEditor.chain().setLink({ href }).run()\n\t\t\t// N.B. We shouldn't focus() on mobile because it causes the\n\t\t\t// Return key to replace the link with a newline :facepalm:\n\t\t\tif (editor.getInstanceState().isCoarsePointer) {\n\t\t\t\ttextEditor.commands.blur()\n\t\t\t} else {\n\t\t\t\ttextEditor.commands.focus()\n\t\t\t}\n\t\t\tonClose()\n\t\t},\n\t\t[trackEvent, source, textEditor, editor, onClose, handleRemoveLink]\n\t)\n\n\tconst handleVisitLink = () => {\n\t\ttrackEvent('rich-text', { operation: 'link-visit', source })\n\t\tif (normalizedValue) openWindow(normalizedValue, '_blank')\n\t\tonClose()\n\t}\n\n\tuseEffect(() => {\n\t\tconst doc = editor.getContainerDocument()\n\t\tconst handlePointerDown = (e: PointerEvent) => {\n\t\t\tconst toolbar = doc.querySelector('.tlui-rich-text__toolbar')\n\t\t\tif (toolbar?.contains(e.target as Node)) return\n\t\t\t// If the pointer down is not in the toolbar, complete the link\n\t\t\tif (normalizedValue === null) {\n\t\t\t\tonClose()\n\t\t\t} else {\n\t\t\t\thandleLinkComplete(value)\n\t\t\t}\n\t\t}\n\t\tdoc.addEventListener('pointerdown', handlePointerDown, { capture: true })\n\t\treturn () => {\n\t\t\tdoc.removeEventListener('pointerdown', handlePointerDown, { capture: true })\n\t\t}\n\t}, [editor, handleLinkComplete, onClose, normalizedValue, value])\n\n\tuseEffect(() => {\n\t\tref.current?.focus()\n\t}, [value])\n\n\tuseEffect(() => {\n\t\tsetValue(initialValue)\n\t\tsetIsInvalid(false)\n\t}, [initialValue])\n\n\tconst handleValueChange = useCallback((nextValue: string) => {\n\t\tsetValue(nextValue)\n\t\tsetIsInvalid(false)\n\t}, [])\n\n\treturn (\n\t\t<>\n\t\t\t<TldrawUiInput\n\t\t\t\tref={ref}\n\t\t\t\tdata-testid=\"rich-text.link-input\"\n\t\t\t\tclassName={classNames('tlui-rich-text__toolbar-link-input', {\n\t\t\t\t\t'tlui-rich-text__toolbar-link-input--invalid': isInvalid,\n\t\t\t\t})}\n\t\t\t\tvalue={value}\n\t\t\t\tonValueChange={handleValueChange}\n\t\t\t\tonComplete={handleLinkComplete}\n\t\t\t\tonCancel={onClose}\n\t\t\t\tplaceholder=\"example.com\"\n\t\t\t\taria-label=\"example.com\"\n\t\t\t/>\n\t\t\t<TldrawUiButton\n\t\t\t\tclassName=\"tlui-rich-text__toolbar-link-visit\"\n\t\t\t\ttitle={msg(messages.toolRichTextLinkVisit)}\n\t\t\t\ttype=\"icon\"\n\t\t\t\tonPointerDown={preventDefault}\n\t\t\t\tonClick={handleVisitLink}\n\t\t\t\tdisabled={!normalizedValue}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon small icon=\"external-link\" />\n\t\t\t</TldrawUiButton>\n\t\t\t<TldrawUiButton\n\t\t\t\tclassName=\"tlui-rich-text__toolbar-link-remove\"\n\t\t\t\ttitle={msg(messages.toolRichTextLinkRemove)}\n\t\t\t\tdata-testid=\"rich-text.link-remove\"\n\t\t\t\ttype=\"icon\"\n\t\t\t\tonPointerDown={preventDefault}\n\t\t\t\tonClick={handleRemoveLink}\n\t\t\t>\n\t\t\t\t<TldrawUiButtonIcon small icon=\"trash\" />\n\t\t\t</TldrawUiButton>\n\t\t</>\n\t)\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAyGE;AAzGF,oBAAoF;AACpF,wBAAuB;AACvB,mBAAyD;AACzD,qBAAiC;AACjC,oBAA4B;AAC5B,4BAA+B;AAC/B,4BAA+B;AAC/B,gCAAmC;AACnC,2BAA8B;AAE9B,MAAM,eAAW,8BAAe;AAAA,EAC/B,wBAAwB,EAAE,IAAI,8BAA8B,gBAAgB,cAAc;AAAA,EAC1F,uBAAuB,EAAE,IAAI,6BAA6B,gBAAgB,aAAa;AACxF,CAAC;AAUM,SAAS,WAAW,EAAE,YAAY,OAAO,cAAc,QAAQ,GAAoB;AACzF,QAAM,aAAS,yBAAU;AACzB,QAAM,CAAC,OAAO,QAAQ,QAAI,uBAAS,YAAY;AAC/C,QAAM,CAAC,WAAW,YAAY,QAAI,uBAAS,KAAK;AAChD,QAAM,UAAM,sCAAe;AAC3B,QAAM,UAAM,qBAAyB,IAAI;AACzC,QAAM,iBAAa,2BAAY;AAC/B,QAAM,SAAS;AACf,QAAM,sBAAkB,iCAAiB,KAAK;AAE9C,QAAM,uBAAmB,0BAAY,MAAM;AAC1C,eAAW,aAAa,EAAE,WAAW,eAAe,OAAO,CAAC;AAC5D,eAAW,MAAM,EAAE,UAAU,EAAE,MAAM,EAAE,IAAI;AAC3C,YAAQ;AAAA,EACT,GAAG,C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;AACf,QAAI,SAAS,MAAM;AAAA,EACpB,GAAG,CAAC,KAAK,CAAC;AAEV,8BAAU,MAAM;AACf,aAAS,YAAY;AACrB,iBAAa,KAAK;AAAA,EACnB,GAAG,CAAC,YAAY,CAAC;AAEjB,QAAM,wBAAoB,0BAAY,CAAC,cAAsB;AAC5D,aAAS,SAAS;AAClB,iBAAa,KAAK;AAAA,EACnB,GAAG,CAAC,CAAC;AAEL,SACC,4EACC;AAAA;AAAA,MAAC;AAAA;AAAA,QACA;AAAA,QACA,eAAY;AAAA,QACZ,eAAW,kBAAAA,SAAW,sCAAsC;AAAA,UAC3D,+CAA+C;AAAA,QAChD,CAAC;AAAA,QACD;AAAA,QACA,eAAe;AAAA,QACf,YAAY;AAAA,QACZ,UAAU;AAAA,QACV,aAAY;AAAA,QACZ,cAAW;AAAA;AAAA,IACZ;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,OAAO,IAAI,SAAS,qBAAqB;AAAA,QACzC,MAAK;AAAA,QACL,eAAe;AAAA,QACf,SAAS;AAAA,QACT,UAAU,CAAC;AAAA,QAEX,sDAAC,gDAAmB,OAAK,MAAC,MAAK,iBAAgB;AAAA;AAAA,IAChD;AAAA,IACA;AAAA,MAAC;AAAA;AAAA,QACA,WAAU;AAAA,QACV,OAAO,IAAI,SAAS,sBAAsB;AAAA,QAC1C,eAAY;AAAA,QACZ,MAAK;AAAA,QACL,eAAe;AAAA,QACf,SAAS;AAAA,QAET,sDAAC,gDAAmB,OAAK,MAAC,MAAK,SAAQ;AAAA;AAAA,IACxC;AAAA,KACD;AAEF;",
|
|
6
|
+
"names": ["classNames"]
|
|
7
7
|
}
|
|
@@ -22,10 +22,10 @@ __export(version_exports, {
|
|
|
22
22
|
version: () => version
|
|
23
23
|
});
|
|
24
24
|
module.exports = __toCommonJS(version_exports);
|
|
25
|
-
const version = "5.6.
|
|
25
|
+
const version = "5.6.1";
|
|
26
26
|
const publishDates = {
|
|
27
27
|
major: "2026-05-06T16:28:18.473Z",
|
|
28
28
|
minor: "2026-10-28T14:20:57.238Z",
|
|
29
|
-
patch: "2026-
|
|
29
|
+
patch: "2026-11-16T18:57:15.106Z"
|
|
30
30
|
};
|
|
31
31
|
//# sourceMappingURL=version.js.map
|
|
@@ -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.1'\nexport const publishDates = {\n\tmajor: '2026-05-06T16:28:18.473Z',\n\tminor: '2026-10-28T14:20:57.238Z',\n\tpatch: '2026-11-16T18:57:15.106Z',\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGO,MAAM,UAAU;AAChB,MAAM,eAAe;AAAA,EAC3B,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
var linkUrl_exports = {};
|
|
20
|
+
__export(linkUrl_exports, {
|
|
21
|
+
normalizeLinkUrl: () => normalizeLinkUrl
|
|
22
|
+
});
|
|
23
|
+
module.exports = __toCommonJS(linkUrl_exports);
|
|
24
|
+
var import_editor = require("@tldraw/editor");
|
|
25
|
+
const emailRegex = /^[^\s@/:]+@[^\s@/:]+\.[^\s@/:]+$/;
|
|
26
|
+
function normalizeLinkUrl(input) {
|
|
27
|
+
const url = input.trim().replace(/^https?:\/\/(https?:\/\/)/i, "$1");
|
|
28
|
+
if (import_editor.T.linkUrl.isValid(url)) return url;
|
|
29
|
+
if (emailRegex.test(url)) return `mailto:${url}`;
|
|
30
|
+
const withProtocol = `https://${url}`;
|
|
31
|
+
if (!import_editor.T.linkUrl.isValid(withProtocol)) return null;
|
|
32
|
+
const { hostname, username } = new URL(withProtocol);
|
|
33
|
+
if (username) return null;
|
|
34
|
+
if (hostname === "localhost" || hostname.startsWith("[") || /[^.]\.[^.]+$/.test(hostname)) {
|
|
35
|
+
return withProtocol;
|
|
36
|
+
}
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=linkUrl.js.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;AAAA;AAAA;AAAA;AAAA;AAAA,oBAAkB;AAElB,MAAM,aAAa;AAYZ,SAAS,iBAAiB,OAA8B;AAE9D,QAAM,MAAM,MAAM,KAAK,EAAE,QAAQ,8BAA8B,IAAI;AAEnE,MAAI,gBAAE,QAAQ,QAAQ,GAAG,EAAG,QAAO;AACnC,MAAI,WAAW,KAAK,GAAG,EAAG,QAAO,UAAU,GAAG;AAE9C,QAAM,eAAe,WAAW,GAAG;AACnC,MAAI,CAAC,gBAAE,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
|
+
}
|
|
@@ -59,7 +59,10 @@ function getTipTapDefaultExtensions(starterKitOptions) {
|
|
|
59
59
|
horizontalRule: false,
|
|
60
60
|
link: {
|
|
61
61
|
openOnClick: false,
|
|
62
|
-
autolink: true
|
|
62
|
+
autolink: true,
|
|
63
|
+
// TipTap strips hrefs outside its own protocol list, which would drop app links
|
|
64
|
+
// (`vscode://…`) that shape links accept.
|
|
65
|
+
isAllowedUri: (url, { defaultValidate }) => defaultValidate(url) || import_editor.T.linkUrl.isValid(url)
|
|
63
66
|
},
|
|
64
67
|
// List every enabled block type: a missing one gets an empty paragraph appended after it
|
|
65
68
|
// 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;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQO;AACP,4BAAqB;AACrB,iCAA0B;AAC1B,kCAA2B;AAE3B,yBAAmD;AACnD,
|
|
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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAQO;AACP,4BAAqB;AACrB,iCAA0B;AAC1B,kCAA2B;AAE3B,yBAAmD;AACnD,oBAQO;AACP,0BAAiC;AACjC,2BAAuC;AACvC,2BAAuC;AAGhC,MAAM,mCAAmC,sBAAU,OAAO;AAAA,EAChE,MAAM;AAAA,EACN,uBAAuB;AACtB,WAAO;AAAA;AAAA,MAEN,eAAe,CAAC,EAAE,OAAO,MAAM,OAAO,SAAS,MAAM;AAAA,IACtD;AAAA,EACD;AACD,CAAC;AAKD,2BAAK,OAAO,WAAW;AAKvB,qCAAU,OAAO,WAAW;AAWrB,SAAS,2BACf,mBACa;AACb,SAAO;AAAA,IACN,8BAAW,UAAU;AAAA,MACpB,YAAY;AAAA,MACZ,WAAW;AAAA,MACX,gBAAgB;AAAA,MAChB,MAAM;AAAA,QACL,aAAa;AAAA,QACb,UAAU;AAAA;AAAA;AAAA,QAGV,cAAc,CAAC,KAAK,EAAE,gBAAgB,MAAM,gBAAgB,GAAG,KAAK,gBAAE,QAAQ,QAAQ,GAAG;AAAA,MAC1F;AAAA;AAAA;AAAA,MAGA,cAAc;AAAA,QACb,UAAU,CAAC,aAAa,WAAW,cAAc,eAAe,UAAU;AAAA,MAC3E;AAAA,MACA,GAAG;AAAA,IACJ,CAAC;AAAA,IACD;AAAA,IACA;AA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AAgB;AAAA,IACjB,CAAC;AAAA,EACF,CAAC;AACF;AASO,SAAS,uBAAuB,QAAgB,MAA0B;AAChF,QAAM,mBACL,OAAO,eAAe,EAAE,cAAc,cAAc;AACrD,aAAO,0BAAa,MAAM,gBAAgB;AAC3C;AAGO,SAAS,wBACf,MACA,OACA,SACC;AACD,aAAW,QAAQ,KAAK,OAAO;AAC9B,QAAI,KAAK,KAAK,SAAS,UAAU,MAAM,WAAW,QAAQ;AACzD,cAAQ,EAAE,GAAG,OAAO,QAAQ,OAAO;AAAA,IACpC;AACA,QAAI,KAAK,KAAK,SAAS,YAAY,MAAM,UAAU,UAAU;AAC5D,cAAQ,EAAE,GAAG,OAAO,OAAO,SAAS;AAAA,IACrC;AACA,QAAI,KAAK,KAAK,SAAS,UAAU,MAAM,WAAW,eAAe;AAChE,cAAQ,EAAE,GAAG,OAAO,QAAQ,cAAc;AAAA,IAC3C;AAAA,EACD;AAEA,QAAM,qBAAiB,8BAAe,sCAAkB,MAAM,MAAM;AACpE,MAAI,CAAC,eAAgB,QAAO;AAE5B,QAAM,oBAAgB,8BAAe,gBAAgB,MAAM,KAAK;AAChE,MAAI,CAAC,cAAe,QAAO;AAE3B,QAAM,qBAAiB,8BAAe,eAAe,MAAM,MAAM;AACjE,MAAI,CAAC,eAAgB,QAAO;AAE5B,UAAQ,cAAc;AAEtB,SAAO;AACR;",
|
|
6
6
|
"names": ["extensions"]
|
|
7
7
|
}
|
package/dist-esm/index.mjs
CHANGED
|
@@ -25,6 +25,7 @@ import {
|
|
|
25
25
|
getBookmarkShapeHeight,
|
|
26
26
|
getHumanReadableAddress,
|
|
27
27
|
getResolvedBookmarkAssetId,
|
|
28
|
+
isUrlOnlyBookmarkUrl,
|
|
28
29
|
setBookmarkHeight,
|
|
29
30
|
resolveBookmarkAssetForUrlChange
|
|
30
31
|
} from "./bookmarks.mjs";
|
|
@@ -97,7 +98,7 @@ class BookmarkShapeUtil extends BaseBoxShapeUtil {
|
|
|
97
98
|
}
|
|
98
99
|
next = resolveBookmarkAssetForUrlChange(this.editor, shape);
|
|
99
100
|
}
|
|
100
|
-
if (prev.props.assetId !== next.props.assetId) {
|
|
101
|
+
if (prev.props.assetId !== next.props.assetId || prev.props.url !== next.props.url) {
|
|
101
102
|
return setBookmarkHeight(this.editor, next);
|
|
102
103
|
}
|
|
103
104
|
return next === shape ? void 0 : next;
|
|
@@ -122,6 +123,7 @@ function BookmarkShapeComponent({
|
|
|
122
123
|
const asset = resolvedAssetId ? editor.getAsset(resolvedAssetId) : null;
|
|
123
124
|
const isSafariExport = !!useSvgExportContext() && tlenv.isSafari;
|
|
124
125
|
const address = getHumanReadableAddress(url);
|
|
126
|
+
const title = asset ? asset.props.title : isUrlOnlyBookmarkUrl(url) ? url : "";
|
|
125
127
|
const [isFaviconValid, setIsFaviconValid] = useState(true);
|
|
126
128
|
const onFaviconError = () => setIsFaviconValid(false);
|
|
127
129
|
const markAsHandledOnShiftKey = useCallback(
|
|
@@ -142,7 +144,7 @@ function BookmarkShapeComponent({
|
|
|
142
144
|
maxHeight: h
|
|
143
145
|
},
|
|
144
146
|
children: [
|
|
145
|
-
showImageContainer && (
|
|
147
|
+
showImageContainer && (asset ? asset.props.image : !isUrlOnlyBookmarkUrl(url)) && /* @__PURE__ */ jsxs("div", { className: "tl-bookmark__image_container", children: [
|
|
146
148
|
asset ? /* @__PURE__ */ jsx(
|
|
147
149
|
"img",
|
|
148
150
|
{
|
|
@@ -156,7 +158,7 @@ function BookmarkShapeComponent({
|
|
|
156
158
|
asset?.props.image && /* @__PURE__ */ jsx(HyperlinkButton, { url })
|
|
157
159
|
] }),
|
|
158
160
|
/* @__PURE__ */ jsxs("div", { className: "tl-bookmark__copy_container", children: [
|
|
159
|
-
|
|
161
|
+
title ? /* @__PURE__ */ jsx(
|
|
160
162
|
"a",
|
|
161
163
|
{
|
|
162
164
|
className: "tl-bookmark__link",
|
|
@@ -166,7 +168,7 @@ function BookmarkShapeComponent({
|
|
|
166
168
|
draggable: false,
|
|
167
169
|
onPointerDown: markAsHandledOnShiftKey,
|
|
168
170
|
onPointerUp: markAsHandledOnShiftKey,
|
|
169
|
-
children: /* @__PURE__ */ jsx("h2", { className: "tl-bookmark__heading", children: convertCommonTitleHTMLEntities(
|
|
171
|
+
children: /* @__PURE__ */ jsx("h2", { className: "tl-bookmark__heading", children: convertCommonTitleHTMLEntities(title) })
|
|
170
172
|
}
|
|
171
173
|
) : null,
|
|
172
174
|
asset?.props.description && asset?.props.image ? /* @__PURE__ */ jsx("p", { className: "tl-bookmark__description", children: asset.props.description }) : null,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/lib/shapes/bookmark/BookmarkShapeUtil.tsx"],
|
|
4
|
-
"sourcesContent": ["// oxlint-disable typescript/no-empty-object-type\nimport {\n\tBaseBoxShapeUtil,\n\tbookmarkShapeMigrations,\n\tbookmarkShapeProps,\n\tdefineMessages,\n\tHTMLContainer,\n\tlerp,\n\tRectangle2d,\n\tT,\n\tTLAssetId,\n\tTLBookmarkAsset,\n\tTLBookmarkShape,\n\tTLBookmarkShapeProps,\n\ttlenv,\n\ttranslateMessage,\n\tuseEditor,\n\tuseSvgExportContext,\n} from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { PointerEventHandler, useCallback, useState } from 'react'\nimport { convertCommonTitleHTMLEntities } from '../../utils/text/text'\nimport type { ShapeOptionsWithDisplayValues } from '../shared/getDisplayValues'\nimport { HyperlinkButton } from '../shared/HyperlinkButton'\nimport { LINK_ICON } from '../shared/icons-editor'\nimport { getRotatedBoxShadow } from '../shared/rotated-box-shadow'\nimport {\n\tBOOKMARK_HEIGHT,\n\tBOOKMARK_WIDTH,\n\tgetBookmarkShapeHeight,\n\tgetHumanReadableAddress,\n\tgetResolvedBookmarkAssetId,\n\tsetBookmarkHeight,\n\tresolveBookmarkAssetForUrlChange,\n} from './bookmarks'\n\n/** @public */\nexport type BookmarkShapeUtilDisplayValues = object\n\n/** @public */\nexport interface BookmarkShapeOptions extends ShapeOptionsWithDisplayValues<\n\tTLBookmarkShape,\n\tBookmarkShapeUtilDisplayValues\n> {}\n\nconst messages = defineMessages({\n\tname: { id: 'tool.bookmark', defaultMessage: 'Bookmark' },\n})\n\n/** @public */\nexport class BookmarkShapeUtil extends BaseBoxShapeUtil<TLBookmarkShape> {\n\tstatic override type = 'bookmark' as const\n\tstatic override props = bookmarkShapeProps\n\tstatic override migrations = bookmarkShapeMigrations\n\n\toverride options: BookmarkShapeOptions = {\n\t\tgetDefaultDisplayValues(): BookmarkShapeUtilDisplayValues {\n\t\t\treturn {}\n\t\t},\n\t\tgetCustomDisplayValues(): Partial<BookmarkShapeUtilDisplayValues> {\n\t\t\treturn {}\n\t\t},\n\t}\n\n\toverride getShapeName() {\n\t\treturn translateMessage(this.editor.i18n(), messages.name)\n\t}\n\n\toverride canResize(shape: TLBookmarkShape) {\n\t\treturn false\n\t}\n\n\toverride hideSelectionBoundsFg(shape: TLBookmarkShape) {\n\t\treturn true\n\t}\n\n\toverride getText(shape: TLBookmarkShape) {\n\t\treturn shape.props.url\n\t}\n\n\toverride getAriaDescriptor(shape: TLBookmarkShape) {\n\t\tconst asset = (\n\t\t\tshape.props.assetId ? this.editor.getAsset(shape.props.assetId) : null\n\t\t) as TLBookmarkAsset | null\n\n\t\tif (!asset?.props.title) return undefined\n\n\t\treturn (\n\t\t\tconvertCommonTitleHTMLEntities(asset.props.title) +\n\t\t\t(asset.props.description ? ', ' + asset.props.description : '')\n\t\t)\n\t}\n\n\toverride getDefaultProps(): TLBookmarkShape['props'] {\n\t\treturn {\n\t\t\turl: '',\n\t\t\tw: BOOKMARK_WIDTH,\n\t\t\th: BOOKMARK_HEIGHT,\n\t\t\tassetId: null,\n\t\t}\n\t}\n\n\toverride getGeometry(shape: TLBookmarkShape) {\n\t\treturn new Rectangle2d({\n\t\t\twidth: shape.props.w,\n\t\t\theight: getBookmarkShapeHeight(this.editor, shape),\n\t\t\tisFilled: true,\n\t\t})\n\t}\n\n\toverride component(shape: TLBookmarkShape) {\n\t\tconst { assetId, url } = shape.props\n\t\tconst h = getBookmarkShapeHeight(this.editor, shape)\n\t\tconst rotation = this.editor.getShapePageTransform(shape)!.rotation()\n\n\t\treturn <BookmarkShapeComponent assetId={assetId} url={url} h={h} rotation={rotation} />\n\t}\n\n\toverride getIndicatorPath(shape: TLBookmarkShape): Path2D {\n\t\tconst path = new Path2D()\n\t\tpath.rect(0, 0, shape.props.w, getBookmarkShapeHeight(this.editor, shape))\n\t\treturn path\n\t}\n\n\toverride onBeforeCreate(next: TLBookmarkShape) {\n\t\treturn setBookmarkHeight(this.editor, next)\n\t}\n\n\toverride onBeforeUpdate(prev: TLBookmarkShape, shape: TLBookmarkShape) {\n\t\tlet next = shape\n\t\tif (prev.props.url !== shape.props.url) {\n\t\t\tif (!T.linkUrl.isValid(shape.props.url)) {\n\t\t\t\treturn { ...shape, props: { ...shape.props, url: prev.props.url } }\n\t\t\t}\n\t\t\tnext = resolveBookmarkAssetForUrlChange(this.editor, shape)\n\t\t}\n\n\t\tif (prev.props.assetId !== next.props.assetId) {\n\t\t\treturn setBookmarkHeight(this.editor, next)\n\t\t}\n\n\t\treturn next === shape ? undefined : next\n\t}\n\toverride getInterpolatedProps(\n\t\tstartShape: TLBookmarkShape,\n\t\tendShape: TLBookmarkShape,\n\t\tt: number\n\t): TLBookmarkShapeProps {\n\t\treturn {\n\t\t\t...(t > 0.5 ? endShape.props : startShape.props),\n\t\t\tw: lerp(startShape.props.w, endShape.props.w, t),\n\t\t\th: lerp(startShape.props.h, endShape.props.h, t),\n\t\t}\n\t}\n}\n\nexport function BookmarkShapeComponent({\n\tassetId,\n\trotation,\n\turl,\n\th,\n\tshowImageContainer = true,\n}: {\n\tassetId: TLAssetId | null\n\trotation: number\n\th: number\n\turl: string\n\tshowImageContainer?: boolean\n}) {\n\tconst editor = useEditor()\n\n\tconst resolvedAssetId = getResolvedBookmarkAssetId(editor, assetId, url)\n\tconst asset = resolvedAssetId ? (editor.getAsset(resolvedAssetId) as TLBookmarkAsset) : null\n\n\tconst isSafariExport = !!useSvgExportContext() && tlenv.isSafari\n\n\tconst address = getHumanReadableAddress(url)\n\n\tconst [isFaviconValid, setIsFaviconValid] = useState(true)\n\tconst onFaviconError = () => setIsFaviconValid(false)\n\n\tconst markAsHandledOnShiftKey = useCallback<PointerEventHandler>(\n\t\t(e) => {\n\t\t\tif (!editor.inputs.getShiftKey()) editor.markEventAsHandled(e)\n\t\t},\n\t\t[editor]\n\t)\n\n\treturn (\n\t\t<HTMLContainer>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\n\t\t\t\t\t'tl-bookmark__container',\n\t\t\t\t\tisSafariExport && 'tl-bookmark__container--safariExport'\n\t\t\t\t)}\n\t\t\t\tstyle={{\n\t\t\t\t\tboxShadow: isSafariExport ? undefined : getRotatedBoxShadow(rotation),\n\t\t\t\t\tmaxHeight: h,\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{showImageContainer && (
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["// oxlint-disable typescript/no-empty-object-type\nimport {\n\tBaseBoxShapeUtil,\n\tbookmarkShapeMigrations,\n\tbookmarkShapeProps,\n\tdefineMessages,\n\tHTMLContainer,\n\tlerp,\n\tRectangle2d,\n\tT,\n\tTLAssetId,\n\tTLBookmarkAsset,\n\tTLBookmarkShape,\n\tTLBookmarkShapeProps,\n\ttlenv,\n\ttranslateMessage,\n\tuseEditor,\n\tuseSvgExportContext,\n} from '@tldraw/editor'\nimport classNames from 'classnames'\nimport { PointerEventHandler, useCallback, useState } from 'react'\nimport { convertCommonTitleHTMLEntities } from '../../utils/text/text'\nimport type { ShapeOptionsWithDisplayValues } from '../shared/getDisplayValues'\nimport { HyperlinkButton } from '../shared/HyperlinkButton'\nimport { LINK_ICON } from '../shared/icons-editor'\nimport { getRotatedBoxShadow } from '../shared/rotated-box-shadow'\nimport {\n\tBOOKMARK_HEIGHT,\n\tBOOKMARK_WIDTH,\n\tgetBookmarkShapeHeight,\n\tgetHumanReadableAddress,\n\tgetResolvedBookmarkAssetId,\n\tisUrlOnlyBookmarkUrl,\n\tsetBookmarkHeight,\n\tresolveBookmarkAssetForUrlChange,\n} from './bookmarks'\n\n/** @public */\nexport type BookmarkShapeUtilDisplayValues = object\n\n/** @public */\nexport interface BookmarkShapeOptions extends ShapeOptionsWithDisplayValues<\n\tTLBookmarkShape,\n\tBookmarkShapeUtilDisplayValues\n> {}\n\nconst messages = defineMessages({\n\tname: { id: 'tool.bookmark', defaultMessage: 'Bookmark' },\n})\n\n/** @public */\nexport class BookmarkShapeUtil extends BaseBoxShapeUtil<TLBookmarkShape> {\n\tstatic override type = 'bookmark' as const\n\tstatic override props = bookmarkShapeProps\n\tstatic override migrations = bookmarkShapeMigrations\n\n\toverride options: BookmarkShapeOptions = {\n\t\tgetDefaultDisplayValues(): BookmarkShapeUtilDisplayValues {\n\t\t\treturn {}\n\t\t},\n\t\tgetCustomDisplayValues(): Partial<BookmarkShapeUtilDisplayValues> {\n\t\t\treturn {}\n\t\t},\n\t}\n\n\toverride getShapeName() {\n\t\treturn translateMessage(this.editor.i18n(), messages.name)\n\t}\n\n\toverride canResize(shape: TLBookmarkShape) {\n\t\treturn false\n\t}\n\n\toverride hideSelectionBoundsFg(shape: TLBookmarkShape) {\n\t\treturn true\n\t}\n\n\toverride getText(shape: TLBookmarkShape) {\n\t\treturn shape.props.url\n\t}\n\n\toverride getAriaDescriptor(shape: TLBookmarkShape) {\n\t\tconst asset = (\n\t\t\tshape.props.assetId ? this.editor.getAsset(shape.props.assetId) : null\n\t\t) as TLBookmarkAsset | null\n\n\t\tif (!asset?.props.title) return undefined\n\n\t\treturn (\n\t\t\tconvertCommonTitleHTMLEntities(asset.props.title) +\n\t\t\t(asset.props.description ? ', ' + asset.props.description : '')\n\t\t)\n\t}\n\n\toverride getDefaultProps(): TLBookmarkShape['props'] {\n\t\treturn {\n\t\t\turl: '',\n\t\t\tw: BOOKMARK_WIDTH,\n\t\t\th: BOOKMARK_HEIGHT,\n\t\t\tassetId: null,\n\t\t}\n\t}\n\n\toverride getGeometry(shape: TLBookmarkShape) {\n\t\treturn new Rectangle2d({\n\t\t\twidth: shape.props.w,\n\t\t\theight: getBookmarkShapeHeight(this.editor, shape),\n\t\t\tisFilled: true,\n\t\t})\n\t}\n\n\toverride component(shape: TLBookmarkShape) {\n\t\tconst { assetId, url } = shape.props\n\t\tconst h = getBookmarkShapeHeight(this.editor, shape)\n\t\tconst rotation = this.editor.getShapePageTransform(shape)!.rotation()\n\n\t\treturn <BookmarkShapeComponent assetId={assetId} url={url} h={h} rotation={rotation} />\n\t}\n\n\toverride getIndicatorPath(shape: TLBookmarkShape): Path2D {\n\t\tconst path = new Path2D()\n\t\tpath.rect(0, 0, shape.props.w, getBookmarkShapeHeight(this.editor, shape))\n\t\treturn path\n\t}\n\n\toverride onBeforeCreate(next: TLBookmarkShape) {\n\t\treturn setBookmarkHeight(this.editor, next)\n\t}\n\n\toverride onBeforeUpdate(prev: TLBookmarkShape, shape: TLBookmarkShape) {\n\t\tlet next = shape\n\t\tif (prev.props.url !== shape.props.url) {\n\t\t\tif (!T.linkUrl.isValid(shape.props.url)) {\n\t\t\t\treturn { ...shape, props: { ...shape.props, url: prev.props.url } }\n\t\t\t}\n\t\t\tnext = resolveBookmarkAssetForUrlChange(this.editor, shape)\n\t\t}\n\n\t\tif (prev.props.assetId !== next.props.assetId || prev.props.url !== next.props.url) {\n\t\t\treturn setBookmarkHeight(this.editor, next)\n\t\t}\n\n\t\treturn next === shape ? undefined : next\n\t}\n\toverride getInterpolatedProps(\n\t\tstartShape: TLBookmarkShape,\n\t\tendShape: TLBookmarkShape,\n\t\tt: number\n\t): TLBookmarkShapeProps {\n\t\treturn {\n\t\t\t...(t > 0.5 ? endShape.props : startShape.props),\n\t\t\tw: lerp(startShape.props.w, endShape.props.w, t),\n\t\t\th: lerp(startShape.props.h, endShape.props.h, t),\n\t\t}\n\t}\n}\n\nexport function BookmarkShapeComponent({\n\tassetId,\n\trotation,\n\turl,\n\th,\n\tshowImageContainer = true,\n}: {\n\tassetId: TLAssetId | null\n\trotation: number\n\th: number\n\turl: string\n\tshowImageContainer?: boolean\n}) {\n\tconst editor = useEditor()\n\n\tconst resolvedAssetId = getResolvedBookmarkAssetId(editor, assetId, url)\n\tconst asset = resolvedAssetId ? (editor.getAsset(resolvedAssetId) as TLBookmarkAsset) : null\n\n\tconst isSafariExport = !!useSvgExportContext() && tlenv.isSafari\n\n\tconst address = getHumanReadableAddress(url)\n\tconst title = asset ? asset.props.title : isUrlOnlyBookmarkUrl(url) ? url : ''\n\n\tconst [isFaviconValid, setIsFaviconValid] = useState(true)\n\tconst onFaviconError = () => setIsFaviconValid(false)\n\n\tconst markAsHandledOnShiftKey = useCallback<PointerEventHandler>(\n\t\t(e) => {\n\t\t\tif (!editor.inputs.getShiftKey()) editor.markEventAsHandled(e)\n\t\t},\n\t\t[editor]\n\t)\n\n\treturn (\n\t\t<HTMLContainer>\n\t\t\t<div\n\t\t\t\tclassName={classNames(\n\t\t\t\t\t'tl-bookmark__container',\n\t\t\t\t\tisSafariExport && 'tl-bookmark__container--safariExport'\n\t\t\t\t)}\n\t\t\t\tstyle={{\n\t\t\t\t\tboxShadow: isSafariExport ? undefined : getRotatedBoxShadow(rotation),\n\t\t\t\t\tmaxHeight: h,\n\t\t\t\t}}\n\t\t\t>\n\t\t\t\t{showImageContainer && (asset ? asset.props.image : !isUrlOnlyBookmarkUrl(url)) && (\n\t\t\t\t\t<div className=\"tl-bookmark__image_container\">\n\t\t\t\t\t\t{asset ? (\n\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\tclassName=\"tl-bookmark__image\"\n\t\t\t\t\t\t\t\tdraggable={false}\n\t\t\t\t\t\t\t\treferrerPolicy=\"strict-origin-when-cross-origin\"\n\t\t\t\t\t\t\t\tsrc={asset?.props.image}\n\t\t\t\t\t\t\t\talt={asset?.props.title || ''}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<div className=\"tl-bookmark__placeholder\" />\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t{asset?.props.image && <HyperlinkButton url={url} />}\n\t\t\t\t\t</div>\n\t\t\t\t)}\n\t\t\t\t<div className=\"tl-bookmark__copy_container\">\n\t\t\t\t\t{title ? (\n\t\t\t\t\t\t<a\n\t\t\t\t\t\t\tclassName=\"tl-bookmark__link\"\n\t\t\t\t\t\t\thref={url || ''}\n\t\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\t\trel=\"noopener noreferrer\"\n\t\t\t\t\t\t\tdraggable={false}\n\t\t\t\t\t\t\tonPointerDown={markAsHandledOnShiftKey}\n\t\t\t\t\t\t\tonPointerUp={markAsHandledOnShiftKey}\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<h2 className=\"tl-bookmark__heading\">{convertCommonTitleHTMLEntities(title)}</h2>\n\t\t\t\t\t\t</a>\n\t\t\t\t\t) : null}\n\t\t\t\t\t{asset?.props.description && asset?.props.image ? (\n\t\t\t\t\t\t<p className=\"tl-bookmark__description\">{asset.props.description}</p>\n\t\t\t\t\t) : null}\n\t\t\t\t\t<a\n\t\t\t\t\t\tclassName=\"tl-bookmark__link\"\n\t\t\t\t\t\thref={url || ''}\n\t\t\t\t\t\ttarget=\"_blank\"\n\t\t\t\t\t\trel=\"noopener noreferrer\"\n\t\t\t\t\t\tdraggable={false}\n\t\t\t\t\t\tonPointerDown={markAsHandledOnShiftKey}\n\t\t\t\t\t\tonPointerUp={markAsHandledOnShiftKey}\n\t\t\t\t\t>\n\t\t\t\t\t\t{isFaviconValid && asset?.props.favicon ? (\n\t\t\t\t\t\t\t<img\n\t\t\t\t\t\t\t\tclassName=\"tl-bookmark__favicon\"\n\t\t\t\t\t\t\t\tsrc={asset?.props.favicon}\n\t\t\t\t\t\t\t\treferrerPolicy=\"strict-origin-when-cross-origin\"\n\t\t\t\t\t\t\t\tonError={onFaviconError}\n\t\t\t\t\t\t\t\talt={`favicon of ${address}`}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t) : (\n\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\tclassName=\"tl-hyperlink__icon\"\n\t\t\t\t\t\t\t\tstyle={{\n\t\t\t\t\t\t\t\t\tmask: `url(\"${LINK_ICON}\") center 100% / 100% no-repeat`,\n\t\t\t\t\t\t\t\t\tWebkitMask: `url(\"${LINK_ICON}\") center 100% / 100% no-repeat`,\n\t\t\t\t\t\t\t\t}}\n\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t)}\n\t\t\t\t\t\t<span>{address}</span>\n\t\t\t\t\t</a>\n\t\t\t\t</div>\n\t\t\t</div>\n\t\t</HTMLContainer>\n\t)\n}\n"],
|
|
5
|
+
"mappings": "AAoHS,cAuFJ,YAvFI;AAnHT;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAKA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AACP,OAAO,gBAAgB;AACvB,SAA8B,aAAa,gBAAgB;AAC3D,SAAS,sCAAsC;AAE/C,SAAS,uBAAuB;AAChC,SAAS,iBAAiB;AAC1B,SAAS,2BAA2B;AACpC;AAAA,EACC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OACM;AAWP,MAAM,WAAW,eAAe;AAAA,EAC/B,MAAM,EAAE,IAAI,iBAAiB,gBAAgB,WAAW;AACzD,CAAC;AAGM,MAAM,0BAA0B,iBAAkC;AAAA,EACxE,OAAgB,OAAO;AAAA,EACvB,OAAgB,QAAQ;AAAA,EACxB,OAAgB,aAAa;AAAA,EAEpB,UAAgC;AAAA,IACxC,0BAA0D;AACzD,aAAO,CAAC;AAAA,IACT;AAAA,IACA,yBAAkE;AACjE,aAAO,CAAC;AAAA,I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