tldraw 4.2.0-next.d76c345101d5 → 4.2.0-next.dbecd76bfa98
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist-cjs/index.d.ts +20 -3
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js +1 -1
- package/dist-cjs/lib/shapes/shared/RichTextLabel.js.map +2 -2
- package/dist-cjs/lib/ui/components/DebugMenu/DefaultDebugMenuContent.js +10 -7
- package/dist-cjs/lib/ui/components/DebugMenu/DefaultDebugMenuContent.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/DefaultRichTextToolbar.js +6 -2
- package/dist-cjs/lib/ui/components/Toolbar/DefaultRichTextToolbar.js.map +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js +2 -2
- package/dist-cjs/lib/ui/components/Toolbar/LinkEditor.js.map +2 -2
- package/dist-cjs/lib/ui/getLocalFiles.js +18 -3
- package/dist-cjs/lib/ui/getLocalFiles.js.map +2 -2
- package/dist-cjs/lib/ui/version.js +3 -3
- package/dist-cjs/lib/ui/version.js.map +1 -1
- package/dist-cjs/lib/utils/text/richText.js +5 -6
- package/dist-cjs/lib/utils/text/richText.js.map +3 -3
- package/dist-esm/index.d.mts +20 -3
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs +2 -1
- package/dist-esm/lib/shapes/shared/RichTextLabel.mjs.map +2 -2
- package/dist-esm/lib/ui/components/DebugMenu/DefaultDebugMenuContent.mjs +10 -7
- package/dist-esm/lib/ui/components/DebugMenu/DefaultDebugMenuContent.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/DefaultRichTextToolbar.mjs +6 -2
- package/dist-esm/lib/ui/components/Toolbar/DefaultRichTextToolbar.mjs.map +2 -2
- package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs +3 -3
- package/dist-esm/lib/ui/components/Toolbar/LinkEditor.mjs.map +2 -2
- package/dist-esm/lib/ui/getLocalFiles.mjs +18 -3
- package/dist-esm/lib/ui/getLocalFiles.mjs.map +2 -2
- package/dist-esm/lib/ui/version.mjs +3 -3
- package/dist-esm/lib/ui/version.mjs.map +1 -1
- package/dist-esm/lib/utils/text/richText.mjs +5 -6
- package/dist-esm/lib/utils/text/richText.mjs.map +2 -2
- package/package.json +10 -10
- package/src/index.ts +3 -0
- package/src/lib/shapes/shared/RichTextLabel.tsx +2 -1
- package/src/lib/ui/components/DebugMenu/DefaultDebugMenuContent.tsx +27 -7
- package/src/lib/ui/components/Toolbar/DefaultRichTextToolbar.tsx +6 -2
- package/src/lib/ui/components/Toolbar/LinkEditor.tsx +3 -3
- package/src/lib/ui/getLocalFiles.ts +20 -3
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/utils/text/richText.ts +5 -5
|
@@ -79,7 +79,9 @@ function useEditingLinkBehavior(textEditor) {
|
|
|
79
79
|
};
|
|
80
80
|
textEditor.view.dom.addEventListener("click", handleClick);
|
|
81
81
|
return () => {
|
|
82
|
-
textEditor.
|
|
82
|
+
if (textEditor.isInitialized) {
|
|
83
|
+
textEditor.view.dom.removeEventListener("click", handleClick);
|
|
84
|
+
}
|
|
83
85
|
};
|
|
84
86
|
}, [textEditor, isEditingLink]);
|
|
85
87
|
useEffect(() => {
|
|
@@ -132,7 +134,9 @@ function useIsMousingDownOnTextEditor(textEditor) {
|
|
|
132
134
|
});
|
|
133
135
|
return () => {
|
|
134
136
|
touchDownEvents.forEach((eventName) => {
|
|
135
|
-
textEditor.
|
|
137
|
+
if (textEditor.isInitialized) {
|
|
138
|
+
textEditor.view.dom.removeEventListener(eventName, handlePointingDown);
|
|
139
|
+
}
|
|
136
140
|
});
|
|
137
141
|
touchUpEvents.forEach((eventName) => {
|
|
138
142
|
document.body.removeEventListener(eventName, handlePointingUp);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/ui/components/Toolbar/DefaultRichTextToolbar.tsx"],
|
|
4
|
-
"sourcesContent": ["import { getMarkRange, Range, EditorEvents as TextEditorEvents } from '@tiptap/core'\nimport { MarkType } from '@tiptap/pm/model'\nimport { Box, debounce, TiptapEditor, track, useEditor, useValue } from '@tldraw/editor'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { rectToBox, TldrawUiContextualToolbar } from '../primitives/TldrawUiContextualToolbar'\nimport { DefaultRichTextToolbarContent } from './DefaultRichTextToolbarContent'\nimport { LinkEditor } from './LinkEditor'\n\n/** @public */\nexport interface TLUiRichTextToolbarProps {\n\tchildren?: React.ReactNode\n}\n\n/**\n * The default rich text toolbar.\n *\n * @public @react\n */\nexport const DefaultRichTextToolbar = track(function DefaultRichTextToolbar({\n\tchildren,\n}: TLUiRichTextToolbarProps) {\n\tconst editor = useEditor()\n\n\tconst textEditor = useValue('textEditor', () => editor.getRichTextEditor(), [editor])\n\n\tif (editor.getInstanceState().isCoarsePointer || !textEditor) return null\n\n\treturn <ContextualToolbarInner textEditor={textEditor}>{children}</ContextualToolbarInner>\n})\n\nfunction ContextualToolbarInner({\n\ttextEditor,\n\tchildren,\n}: {\n\tchildren?: React.ReactNode\n\ttextEditor: TiptapEditor\n}) {\n\tconst { isEditingLink, onEditLinkStart, onEditLinkClose } = useEditingLinkBehavior(textEditor)\n\tconst [currentSelection, setCurrentSelection] = useState<Range | null>(null)\n\tconst previousSelectionBounds = useRef<Box | undefined>()\n\tconst isMousingDown = useIsMousingDownOnTextEditor(textEditor)\n\tconst msg = useTranslation()\n\n\tconst getSelectionBounds = useCallback(() => {\n\t\tif (isEditingLink) {\n\t\t\t// If we're editing a link we don't have selection bounds temporarily.\n\t\t\treturn previousSelectionBounds.current\n\t\t}\n\t\t// Get the text selection rects as a box. This will be undefined if there are no selections.\n\t\tconst selection = window.getSelection()\n\n\t\t// If there are no selections, don't return a box\n\t\tif (!currentSelection || !selection || selection.rangeCount === 0 || selection.isCollapsed)\n\t\t\treturn\n\n\t\t// Get a common box from all of the ranges' screen rects\n\t\tconst rangeBoxes: Box[] = []\n\t\tfor (let i = 0; i < selection.rangeCount; i++) {\n\t\t\tconst range = selection.getRangeAt(i)\n\t\t\trangeBoxes.push(rectToBox(range.getBoundingClientRect()))\n\t\t}\n\n\t\tconst bounds = Box.Common(rangeBoxes)\n\t\tpreviousSelectionBounds.current = bounds\n\t\treturn bounds\n\t}, [currentSelection, isEditingLink])\n\n\tuseEffect(() => {\n\t\tconst handleSelectionUpdate = ({ editor: textEditor }: TextEditorEvents['selectionUpdate']) =>\n\t\t\tsetCurrentSelection(textEditor.state.selection)\n\t\ttextEditor.on('selectionUpdate', handleSelectionUpdate)\n\t\t// Need to kick off the selection update manually to get the initial selection, esp. if select-all.\n\t\thandleSelectionUpdate({ editor: textEditor } as TextEditorEvents['selectionUpdate'])\n\t\treturn () => {\n\t\t\ttextEditor.off('selectionUpdate', handleSelectionUpdate)\n\t\t}\n\t}, [textEditor])\n\n\treturn (\n\t\t<TldrawUiContextualToolbar\n\t\t\tclassName=\"tlui-rich-text__toolbar\"\n\t\t\tgetSelectionBounds={getSelectionBounds}\n\t\t\tisMousingDown={isMousingDown}\n\t\t\tchangeOnlyWhenYChanges={true}\n\t\t\tlabel={msg('tool.rich-text-toolbar-title')}\n\t\t>\n\t\t\t{children ? (\n\t\t\t\tchildren\n\t\t\t) : isEditingLink ? (\n\t\t\t\t<LinkEditor\n\t\t\t\t\ttextEditor={textEditor}\n\t\t\t\t\tvalue={textEditor.isActive('link') ? textEditor.getAttributes('link').href : ''}\n\t\t\t\t\tonClose={onEditLinkClose}\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t<DefaultRichTextToolbarContent textEditor={textEditor} onEditLinkStart={onEditLinkStart} />\n\t\t\t)}\n\t\t</TldrawUiContextualToolbar>\n\t)\n}\n\nfunction useEditingLinkBehavior(textEditor?: TiptapEditor) {\n\tconst [isEditingLink, setIsEditingLink] = useState(false)\n\n\t// Set up text editor event listeners.\n\tuseEffect(() => {\n\t\tif (!textEditor) {\n\t\t\tsetIsEditingLink(false)\n\t\t\treturn\n\t\t}\n\n\t\tconst handleClick = () => {\n\t\t\tconst isLinkActive = textEditor.isActive('link')\n\t\t\tsetIsEditingLink(isLinkActive)\n\t\t}\n\n\t\ttextEditor.view.dom.addEventListener('click', handleClick)\n\t\treturn () => {\n\t\t\ttextEditor.view.dom.removeEventListener('click', handleClick)\n\t\t}\n\t}, [textEditor, isEditingLink])\n\n\t// If we're editing a link, select the entire link.\n\t// This can happen via a click or via keyboarding over to the link and then\n\t// clicking the toolbar button.\n\tuseEffect(() => {\n\t\tif (!textEditor) {\n\t\t\treturn\n\t\t}\n\n\t\t// N.B. This specifically isn't checking the isEditingLink state but\n\t\t// the current active state of the text editor. This is because there's\n\t\t// a subtelty where when going edit-to-edit, that is text editor-to-text editor\n\t\t// in different shapes, the isEditingLink state doesn't get reset quickly enough.\n\t\tif (textEditor.isActive('link')) {\n\t\t\ttry {\n\t\t\t\tconst { from, to } = getMarkRange(\n\t\t\t\t\ttextEditor.state.doc.resolve(textEditor.state.selection.from),\n\t\t\t\t\ttextEditor.schema.marks.link as MarkType\n\t\t\t\t) as Range\n\t\t\t\t// Select the entire link if we just clicked on it while in edit mode, but not if there's\n\t\t\t\t// a specific selection.\n\t\t\t\tif (textEditor.state.selection.empty) {\n\t\t\t\t\ttextEditor.commands.setTextSelection({ from, to })\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Sometimes getMarkRange throws an error when the selection is the entire document.\n\t\t\t\t// This is somewhat mysterious but it's harmless. We just need to ignore it.\n\t\t\t\t// Also, this seems to have recently broken with the React 19 preparation changes.\n\t\t\t}\n\t\t}\n\t}, [textEditor, isEditingLink])\n\n\tconst onEditLinkStart = useCallback(() => {\n\t\tsetIsEditingLink(true)\n\t}, [])\n\n\tconst onEditLinkCancel = useCallback(() => {\n\t\tsetIsEditingLink(false)\n\t}, [])\n\n\tconst onEditLinkClose = useCallback(() => {\n\t\tsetIsEditingLink(false)\n\t\tif (!textEditor) return\n\t\tconst from = textEditor.state.selection.from\n\t\ttextEditor.commands.setTextSelection({ from, to: from })\n\t}, [textEditor])\n\n\treturn { isEditingLink, onEditLinkStart, onEditLinkClose, onEditLinkCancel }\n}\n\nfunction useIsMousingDownOnTextEditor(textEditor: TiptapEditor) {\n\tconst [isMousingDown, setIsMousingDown] = useState(false)\n\n\t// Set up general event listeners for text selection.\n\tuseEffect(() => {\n\t\tif (!textEditor) return\n\n\t\tconst handlePointingStateChange = debounce(({ isPointing }: { isPointing: boolean }) => {\n\t\t\tsetIsMousingDown(isPointing)\n\t\t}, 16)\n\t\tconst handlePointingDown = () => handlePointingStateChange({ isPointing: true })\n\t\tconst handlePointingUp = () => handlePointingStateChange({ isPointing: false })\n\n\t\tconst touchDownEvents = ['touchstart', 'pointerdown', 'mousedown']\n\t\tconst touchUpEvents = ['touchend', 'pointerup', 'mouseup']\n\t\ttouchDownEvents.forEach((eventName: string) => {\n\t\t\ttextEditor.view.dom.addEventListener(eventName, handlePointingDown)\n\t\t})\n\t\ttouchUpEvents.forEach((eventName: string) => {\n\t\t\tdocument.body.addEventListener(eventName, handlePointingUp)\n\t\t})\n\t\treturn () => {\n\t\t\ttouchDownEvents.forEach((eventName: string) => {\n\t\t\t\ttextEditor.view.dom.removeEventListener(eventName, handlePointingDown)\n\t\t\t})\n\t\t\ttouchUpEvents.forEach((eventName: string) => {\n\t\t\t\tdocument.body.removeEventListener(eventName, handlePointingUp)\n\t\t\t})\n\t\t}\n\t}, [textEditor])\n\n\treturn isMousingDown\n}\n"],
|
|
5
|
-
"mappings": "AA4BQ;AA5BR,SAAS,oBAA6D;AAEtE,SAAS,KAAK,UAAwB,OAAO,WAAW,gBAAgB;AACxE,SAAgB,aAAa,WAAW,QAAQ,gBAAgB;A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AAqB;AAEtD,0BAAsB,EAAE,QAAQ,WAAW,CAAwC;AACnF,WAAO,MAAM;AACZ,iBAAW,IAAI,mBAAmB,qBAAqB;AAAA,IACxD;AAAA,EACD,GAAG,CAAC,UAAU,CAAC;AAEf,SACC;AAAA,IAAC;AAAA;AAAA,MACA,WAAU;AAAA,MACV;AAAA,MACA;AAAA,MACA,wBAAwB;AAAA,MACxB,OAAO,IAAI,8BAA8B;AAAA,MAExC,qBACA,WACG,gBACH;AAAA,QAAC;AAAA;AAAA,UACA;AAAA,UACA,OAAO,WAAW,SAAS,MAAM,IAAI,WAAW,cAAc,MAAM,EAAE,OAAO;AAAA,UAC7E,SAAS;AAAA;AAAA,MACV,IAEA,oBAAC,iCAA8B,YAAwB,iBAAkC;AAAA;AAAA,EAE3F;AAEF;AAEA,SAAS,uBAAuB,YAA2B;AAC1D,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAS,KAAK;AAGxD,YAAU,MAAM;AACf,QAAI,CAAC,YAAY;AAChB,uBAAiB,KAAK;AACtB;AAAA,IACD;AAEA,UAAM,cAAc,MAAM;AACzB,YAAM,eAAe,WAAW,SAAS,MAAM;AAC/C,uBAAiB,YAAY;AAAA,IAC9B;AAEA,eAAW,KAAK,IAAI,iBAAiB,SAAS,WAAW;AACzD,WAAO,MAAM;AACZ,
|
|
4
|
+
"sourcesContent": ["import { getMarkRange, Range, EditorEvents as TextEditorEvents } from '@tiptap/core'\nimport { MarkType } from '@tiptap/pm/model'\nimport { Box, debounce, TiptapEditor, track, useEditor, useValue } from '@tldraw/editor'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { useTranslation } from '../../hooks/useTranslation/useTranslation'\nimport { rectToBox, TldrawUiContextualToolbar } from '../primitives/TldrawUiContextualToolbar'\nimport { DefaultRichTextToolbarContent } from './DefaultRichTextToolbarContent'\nimport { LinkEditor } from './LinkEditor'\n\n/** @public */\nexport interface TLUiRichTextToolbarProps {\n\tchildren?: React.ReactNode\n}\n\n/**\n * The default rich text toolbar.\n *\n * @public @react\n */\nexport const DefaultRichTextToolbar = track(function DefaultRichTextToolbar({\n\tchildren,\n}: TLUiRichTextToolbarProps) {\n\tconst editor = useEditor()\n\n\tconst textEditor = useValue('textEditor', () => editor.getRichTextEditor(), [editor])\n\n\tif (editor.getInstanceState().isCoarsePointer || !textEditor) return null\n\n\treturn <ContextualToolbarInner textEditor={textEditor}>{children}</ContextualToolbarInner>\n})\n\nfunction ContextualToolbarInner({\n\ttextEditor,\n\tchildren,\n}: {\n\tchildren?: React.ReactNode\n\ttextEditor: TiptapEditor\n}) {\n\tconst { isEditingLink, onEditLinkStart, onEditLinkClose } = useEditingLinkBehavior(textEditor)\n\tconst [currentSelection, setCurrentSelection] = useState<Range | null>(null)\n\tconst previousSelectionBounds = useRef<Box | undefined>()\n\tconst isMousingDown = useIsMousingDownOnTextEditor(textEditor)\n\tconst msg = useTranslation()\n\n\tconst getSelectionBounds = useCallback(() => {\n\t\tif (isEditingLink) {\n\t\t\t// If we're editing a link we don't have selection bounds temporarily.\n\t\t\treturn previousSelectionBounds.current\n\t\t}\n\t\t// Get the text selection rects as a box. This will be undefined if there are no selections.\n\t\tconst selection = window.getSelection()\n\n\t\t// If there are no selections, don't return a box\n\t\tif (!currentSelection || !selection || selection.rangeCount === 0 || selection.isCollapsed)\n\t\t\treturn\n\n\t\t// Get a common box from all of the ranges' screen rects\n\t\tconst rangeBoxes: Box[] = []\n\t\tfor (let i = 0; i < selection.rangeCount; i++) {\n\t\t\tconst range = selection.getRangeAt(i)\n\t\t\trangeBoxes.push(rectToBox(range.getBoundingClientRect()))\n\t\t}\n\n\t\tconst bounds = Box.Common(rangeBoxes)\n\t\tpreviousSelectionBounds.current = bounds\n\t\treturn bounds\n\t}, [currentSelection, isEditingLink])\n\n\tuseEffect(() => {\n\t\tconst handleSelectionUpdate = ({ editor: textEditor }: TextEditorEvents['selectionUpdate']) =>\n\t\t\tsetCurrentSelection(textEditor.state.selection)\n\t\ttextEditor.on('selectionUpdate', handleSelectionUpdate)\n\t\t// Need to kick off the selection update manually to get the initial selection, esp. if select-all.\n\t\thandleSelectionUpdate({ editor: textEditor } as TextEditorEvents['selectionUpdate'])\n\t\treturn () => {\n\t\t\ttextEditor.off('selectionUpdate', handleSelectionUpdate)\n\t\t}\n\t}, [textEditor])\n\n\treturn (\n\t\t<TldrawUiContextualToolbar\n\t\t\tclassName=\"tlui-rich-text__toolbar\"\n\t\t\tgetSelectionBounds={getSelectionBounds}\n\t\t\tisMousingDown={isMousingDown}\n\t\t\tchangeOnlyWhenYChanges={true}\n\t\t\tlabel={msg('tool.rich-text-toolbar-title')}\n\t\t>\n\t\t\t{children ? (\n\t\t\t\tchildren\n\t\t\t) : isEditingLink ? (\n\t\t\t\t<LinkEditor\n\t\t\t\t\ttextEditor={textEditor}\n\t\t\t\t\tvalue={textEditor.isActive('link') ? textEditor.getAttributes('link').href : ''}\n\t\t\t\t\tonClose={onEditLinkClose}\n\t\t\t\t/>\n\t\t\t) : (\n\t\t\t\t<DefaultRichTextToolbarContent textEditor={textEditor} onEditLinkStart={onEditLinkStart} />\n\t\t\t)}\n\t\t</TldrawUiContextualToolbar>\n\t)\n}\n\nfunction useEditingLinkBehavior(textEditor?: TiptapEditor) {\n\tconst [isEditingLink, setIsEditingLink] = useState(false)\n\n\t// Set up text editor event listeners.\n\tuseEffect(() => {\n\t\tif (!textEditor) {\n\t\t\tsetIsEditingLink(false)\n\t\t\treturn\n\t\t}\n\n\t\tconst handleClick = () => {\n\t\t\tconst isLinkActive = textEditor.isActive('link')\n\t\t\tsetIsEditingLink(isLinkActive)\n\t\t}\n\n\t\ttextEditor.view.dom.addEventListener('click', handleClick)\n\t\treturn () => {\n\t\t\tif (textEditor.isInitialized) {\n\t\t\t\ttextEditor.view.dom.removeEventListener('click', handleClick)\n\t\t\t}\n\t\t}\n\t}, [textEditor, isEditingLink])\n\n\t// If we're editing a link, select the entire link.\n\t// This can happen via a click or via keyboarding over to the link and then\n\t// clicking the toolbar button.\n\tuseEffect(() => {\n\t\tif (!textEditor) {\n\t\t\treturn\n\t\t}\n\n\t\t// N.B. This specifically isn't checking the isEditingLink state but\n\t\t// the current active state of the text editor. This is because there's\n\t\t// a subtelty where when going edit-to-edit, that is text editor-to-text editor\n\t\t// in different shapes, the isEditingLink state doesn't get reset quickly enough.\n\t\tif (textEditor.isActive('link')) {\n\t\t\ttry {\n\t\t\t\tconst { from, to } = getMarkRange(\n\t\t\t\t\ttextEditor.state.doc.resolve(textEditor.state.selection.from),\n\t\t\t\t\ttextEditor.schema.marks.link as MarkType\n\t\t\t\t) as Range\n\t\t\t\t// Select the entire link if we just clicked on it while in edit mode, but not if there's\n\t\t\t\t// a specific selection.\n\t\t\t\tif (textEditor.state.selection.empty) {\n\t\t\t\t\ttextEditor.commands.setTextSelection({ from, to })\n\t\t\t\t}\n\t\t\t} catch {\n\t\t\t\t// Sometimes getMarkRange throws an error when the selection is the entire document.\n\t\t\t\t// This is somewhat mysterious but it's harmless. We just need to ignore it.\n\t\t\t\t// Also, this seems to have recently broken with the React 19 preparation changes.\n\t\t\t}\n\t\t}\n\t}, [textEditor, isEditingLink])\n\n\tconst onEditLinkStart = useCallback(() => {\n\t\tsetIsEditingLink(true)\n\t}, [])\n\n\tconst onEditLinkCancel = useCallback(() => {\n\t\tsetIsEditingLink(false)\n\t}, [])\n\n\tconst onEditLinkClose = useCallback(() => {\n\t\tsetIsEditingLink(false)\n\t\tif (!textEditor) return\n\t\tconst from = textEditor.state.selection.from\n\t\ttextEditor.commands.setTextSelection({ from, to: from })\n\t}, [textEditor])\n\n\treturn { isEditingLink, onEditLinkStart, onEditLinkClose, onEditLinkCancel }\n}\n\nfunction useIsMousingDownOnTextEditor(textEditor: TiptapEditor) {\n\tconst [isMousingDown, setIsMousingDown] = useState(false)\n\n\t// Set up general event listeners for text selection.\n\tuseEffect(() => {\n\t\tif (!textEditor) return\n\n\t\tconst handlePointingStateChange = debounce(({ isPointing }: { isPointing: boolean }) => {\n\t\t\tsetIsMousingDown(isPointing)\n\t\t}, 16)\n\t\tconst handlePointingDown = () => handlePointingStateChange({ isPointing: true })\n\t\tconst handlePointingUp = () => handlePointingStateChange({ isPointing: false })\n\n\t\tconst touchDownEvents = ['touchstart', 'pointerdown', 'mousedown']\n\t\tconst touchUpEvents = ['touchend', 'pointerup', 'mouseup']\n\t\ttouchDownEvents.forEach((eventName: string) => {\n\t\t\ttextEditor.view.dom.addEventListener(eventName, handlePointingDown)\n\t\t})\n\t\ttouchUpEvents.forEach((eventName: string) => {\n\t\t\tdocument.body.addEventListener(eventName, handlePointingUp)\n\t\t})\n\t\treturn () => {\n\t\t\ttouchDownEvents.forEach((eventName: string) => {\n\t\t\t\tif (textEditor.isInitialized) {\n\t\t\t\t\ttextEditor.view.dom.removeEventListener(eventName, handlePointingDown)\n\t\t\t\t}\n\t\t\t})\n\t\t\ttouchUpEvents.forEach((eventName: string) => {\n\t\t\t\tdocument.body.removeEventListener(eventName, handlePointingUp)\n\t\t\t})\n\t\t}\n\t}, [textEditor])\n\n\treturn isMousingDown\n}\n"],
|
|
5
|
+
"mappings": "AA4BQ;AA5BR,SAAS,oBAA6D;AAEtE,SAAS,KAAK,UAAwB,OAAO,WAAW,gBAAgB;AACxE,SAAgB,aAAa,WAAW,QAAQ,gBAAgB;AAChE,SAAS,sBAAsB;AAC/B,SAAS,WAAW,iCAAiC;AACrD,SAAS,qCAAqC;AAC9C,SAAS,kBAAkB;AAYpB,MAAM,yBAAyB,MAAM,SAASA,wBAAuB;AAAA,EAC3E;AACD,GAA6B;AAC5B,QAAM,SAAS,UAAU;AAEzB,QAAM,aAAa,SAAS,cAAc,MAAM,OAAO,kBAAkB,GAAG,CAAC,MAAM,CAAC;AAEpF,MAAI,OAAO,iBAAiB,EAAE,mBAAmB,CAAC,WAAY,QAAO;AAErE,SAAO,oBAAC,0BAAuB,YAAyB,UAAS;AAClE,CAAC;AAED,SAAS,uBAAuB;AAAA,EAC/B;AAAA,EACA;AACD,GAGG;AACF,QA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efault, useEditor } from "@tldraw/editor";
|
|
2
|
+
import { openWindow, preventDefault, useEditor } from "@tldraw/editor";
|
|
3
3
|
import { useEffect, useRef, useState } from "react";
|
|
4
4
|
import { useUiEvents } from "../../context/events.mjs";
|
|
5
5
|
import { useTranslation } from "../../hooks/useTranslation/useTranslation.mjs";
|
|
@@ -20,7 +20,7 @@ function LinkEditor({ textEditor, value: initialValue, onClose }) {
|
|
|
20
20
|
if (!link.startsWith("http://") && !link.startsWith("https://")) {
|
|
21
21
|
link = `https://${link}`;
|
|
22
22
|
}
|
|
23
|
-
textEditor.
|
|
23
|
+
textEditor.chain().setLink({ href: link }).run();
|
|
24
24
|
if (editor.getInstanceState().isCoarsePointer) {
|
|
25
25
|
textEditor.commands.blur();
|
|
26
26
|
} else {
|
|
@@ -30,7 +30,7 @@ function LinkEditor({ textEditor, value: initialValue, onClose }) {
|
|
|
30
30
|
};
|
|
31
31
|
const handleVisitLink = () => {
|
|
32
32
|
trackEvent("rich-text", { operation: "link-visit", source });
|
|
33
|
-
|
|
33
|
+
openWindow(linkifiedValue, "_blank");
|
|
34
34
|
onClose();
|
|
35
35
|
};
|
|
36
36
|
const handleRemoveLink = () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/lib/ui/components/Toolbar/LinkEditor.tsx"],
|
|
4
|
-
"sourcesContent": ["import { preventDefault, TiptapEditor, useEditor } from '@tldraw/editor'\nimport { 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\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 linkifiedValue = value.startsWith('http') ? value : `https://${value}`\n\n\tconst handleValueChange = (value: string) => setValue(value)\n\n\tconst handleLinkComplete = (link: string) => {\n\t\ttrackEvent('rich-text', { operation: 'link-edit', source })\n\t\tif (!link.startsWith('http://') && !link.startsWith('https://')) {\n\t\t\tlink = `https://${link}`\n\t\t}\n\n\t\ttextEditor.
|
|
5
|
-
"mappings": "AAmEE,mBACC,KADD;AAnEF,SAAS,gBAA8B,iBAAiB;
|
|
4
|
+
"sourcesContent": ["import { openWindow, preventDefault, TiptapEditor, useEditor } from '@tldraw/editor'\nimport { 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\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 linkifiedValue = value.startsWith('http') ? value : `https://${value}`\n\n\tconst handleValueChange = (value: string) => setValue(value)\n\n\tconst handleLinkComplete = (link: string) => {\n\t\ttrackEvent('rich-text', { operation: 'link-edit', source })\n\t\tif (!link.startsWith('http://') && !link.startsWith('https://')) {\n\t\t\tlink = `https://${link}`\n\t\t}\n\n\t\ttextEditor.chain().setLink({ href: link }).run()\n\t\t// N.B. We shouldn't focus() on mobile because it causes the\n\t\t// Return key to replace the link with a newline :facepalm:\n\t\tif (editor.getInstanceState().isCoarsePointer) {\n\t\t\ttextEditor.commands.blur()\n\t\t} else {\n\t\t\ttextEditor.commands.focus()\n\t\t}\n\t\tonClose()\n\t}\n\n\tconst handleVisitLink = () => {\n\t\ttrackEvent('rich-text', { operation: 'link-visit', source })\n\t\topenWindow(linkifiedValue, '_blank')\n\t\tonClose()\n\t}\n\n\tconst handleRemoveLink = () => {\n\t\ttrackEvent('rich-text', { operation: 'link-remove', source })\n\t\ttextEditor.chain().unsetLink().focus().run()\n\t\tonClose()\n\t}\n\n\tconst handleLinkCancel = () => onClose()\n\n\tuseEffect(() => {\n\t\tref.current?.focus()\n\t}, [value])\n\n\tuseEffect(() => {\n\t\tsetValue(initialValue)\n\t}, [initialValue])\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=\"tlui-rich-text__toolbar-link-input\"\n\t\t\t\tvalue={value}\n\t\t\t\tonValueChange={handleValueChange}\n\t\t\t\tonComplete={handleLinkComplete}\n\t\t\t\tonCancel={handleLinkCancel}\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('tool.rich-text-link-visit')}\n\t\t\t\ttype=\"icon\"\n\t\t\t\tonPointerDown={preventDefault}\n\t\t\t\tonClick={handleVisitLink}\n\t\t\t\tdisabled={!value}\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('tool.rich-text-link-remove')}\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": "AAmEE,mBACC,KADD;AAnEF,SAAS,YAAY,gBAA8B,iBAAiB;AACpE,SAAS,WAAW,QAAQ,gBAAgB;AAC5C,SAAS,mBAAmB;AAC5B,SAAS,sBAAsB;AAC/B,SAAS,sBAAsB;AAC/B,SAAS,0BAA0B;AACnC,SAAS,qBAAqB;AAUvB,SAAS,WAAW,EAAE,YAAY,OAAO,cAAc,QAAQ,GAAoB;AACzF,QAAM,SAAS,UAAU;AACzB,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,YAAY;AAC/C,QAAM,MAAM,eAAe;AAC3B,QAAM,MAAM,OAAyB,IAAI;AACzC,QAAM,aAAa,YAAY;AAC/B,QAAM,SAAS;AACf,QAAM,iBAAiB,MAAM,WAAW,MAAM,IAAI,QAAQ,WAAW,KAAK;AAE1E,QAAM,oBAAoB,CAACA,WAAkB,SAASA,MAAK;AAE3D,QAAM,qBAAqB,CAAC,SAAiB;AAC5C,eAAW,aAAa,EAAE,WAAW,aAAa,OAAO,CAAC;AAC1D,QAAI,CAAC,KAAK,WAAW,SAAS,KAAK,CAAC,KAAK,WAAW,UAAU,GAAG;AAChE,aAAO,WAAW,IAAI;AAAA,IACvB;AAEA,eAAW,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC,EAAE,IAAI;AAG/C,QAAI,OAAO,iBAAiB,EAAE,iBAAiB;AAC9C,iBAAW,SAAS,KAAK;AAAA,IAC1B,OAAO;AACN,iBAAW,SAAS,MAAM;AAAA,IAC3B;AACA,YAAQ;AAAA,EACT;AAEA,QAAM,kBAAkB,MAAM;AAC7B,eAAW,aAAa,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input.multiple = allowMultiple;
|
|
8
|
+
input.style.display = "none";
|
|
9
|
+
function dispose() {
|
|
10
|
+
input.removeEventListener("change", onchange);
|
|
11
|
+
input.removeEventListener("cancel", oncancel);
|
|
12
|
+
input.remove();
|
|
13
|
+
}
|
|
8
14
|
async function onchange(e) {
|
|
9
15
|
const fileList = e.target.files;
|
|
10
|
-
if (!fileList || fileList.length === 0)
|
|
16
|
+
if (!fileList || fileList.length === 0) {
|
|
17
|
+
resolve([]);
|
|
18
|
+
dispose();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
11
21
|
const files = Array.from(fileList);
|
|
12
22
|
input.value = "";
|
|
13
23
|
resolve(files);
|
|
14
|
-
|
|
15
|
-
|
|
24
|
+
dispose();
|
|
25
|
+
}
|
|
26
|
+
function oncancel() {
|
|
27
|
+
resolve([]);
|
|
28
|
+
dispose();
|
|
16
29
|
}
|
|
30
|
+
document.body.appendChild(input);
|
|
31
|
+
input.addEventListener("cancel", oncancel);
|
|
17
32
|
input.addEventListener("change", onchange);
|
|
18
33
|
input?.click();
|
|
19
34
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/lib/ui/getLocalFiles.ts"],
|
|
4
|
-
"sourcesContent": ["export function getLocalFiles(options?: {\n\tallowMultiple?: boolean\n\tmimeTypes?: string[] | readonly string[]\n}) {\n\treturn new Promise<File[]>((resolve) => {\n\t\tconst { allowMultiple = true, mimeTypes = [] } = options || {}\n\n\t\tconst input = document.createElement('input')\n\t\tinput.type = 'file'\n\t\tinput.accept = mimeTypes?.join(',')\n\t\tinput.multiple = allowMultiple\n\n\t\tasync function onchange(e: Event) {\n\t\t\tconst fileList = (e.target as HTMLInputElement).files\n\t\t\tif (!fileList || fileList.length === 0)
|
|
5
|
-
"mappings": "AAAO,SAAS,cAAc,SAG3B;AACF,SAAO,IAAI,QAAgB,CAAC,YAAY;AACvC,UAAM,EAAE,gBAAgB,MAAM,YAAY,CAAC,EAAE,IAAI,WAAW,CAAC;AAE7D,UAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,UAAM,OAAO;AACb,UAAM,SAAS,WAAW,KAAK,GAAG;AAClC,UAAM,WAAW;
|
|
4
|
+
"sourcesContent": ["export function getLocalFiles(options?: {\n\tallowMultiple?: boolean\n\tmimeTypes?: string[] | readonly string[]\n}) {\n\treturn new Promise<File[]>((resolve) => {\n\t\tconst { allowMultiple = true, mimeTypes = [] } = options || {}\n\n\t\tconst input = document.createElement('input')\n\t\tinput.type = 'file'\n\t\tinput.accept = mimeTypes?.join(',')\n\t\tinput.multiple = allowMultiple\n\t\tinput.style.display = 'none'\n\n\t\tfunction dispose() {\n\t\t\tinput.removeEventListener('change', onchange)\n\t\t\tinput.removeEventListener('cancel', oncancel)\n\t\t\tinput.remove()\n\t\t}\n\n\t\tasync function onchange(e: Event) {\n\t\t\tconst fileList = (e.target as HTMLInputElement).files\n\t\t\tif (!fileList || fileList.length === 0) {\n\t\t\t\tresolve([])\n\t\t\t\tdispose()\n\t\t\t\treturn\n\t\t\t}\n\t\t\tconst files = Array.from(fileList)\n\t\t\tinput.value = ''\n\t\t\tresolve(files)\n\t\t\tdispose()\n\t\t}\n\n\t\tfunction oncancel() {\n\t\t\tresolve([])\n\t\t\tdispose()\n\t\t}\n\n\t\tdocument.body.appendChild(input)\n\t\tinput.addEventListener('cancel', oncancel)\n\t\tinput.addEventListener('change', onchange)\n\t\tinput?.click()\n\t})\n}\n"],
|
|
5
|
+
"mappings": "AAAO,SAAS,cAAc,SAG3B;AACF,SAAO,IAAI,QAAgB,CAAC,YAAY;AACvC,UAAM,EAAE,gBAAgB,MAAM,YAAY,CAAC,EAAE,IAAI,WAAW,CAAC;AAE7D,UAAM,QAAQ,SAAS,cAAc,OAAO;AAC5C,UAAM,OAAO;AACb,UAAM,SAAS,WAAW,KAAK,GAAG;AAClC,UAAM,WAAW;AACjB,UAAM,MAAM,UAAU;AAEtB,aAAS,UAAU;AAClB,YAAM,oBAAoB,UAAU,QAAQ;AAC5C,YAAM,oBAAoB,UAAU,QAAQ;AAC5C,YAAM,OAAO;AAAA,IACd;AAEA,mBAAe,SAAS,GAAU;AACjC,YAAM,WAAY,EAAE,OAA4B;AAChD,UAAI,CAAC,YAAY,SAAS,WAAW,GAAG;AACvC,gBAAQ,CAAC,CAAC;AACV,gBAAQ;AACR;AAAA,MACD;AACA,YAAM,QAAQ,MAAM,KAAK,QAAQ;AACjC,YAAM,QAAQ;AACd,cAAQ,KAAK;AACb,cAAQ;AAAA,IACT;AAEA,aAAS,WAAW;AACnB,cAAQ,CAAC,CAAC;AACV,cAAQ;AAAA,IACT;AAEA,aAAS,KAAK,YAAY,KAAK;AAC/B,UAAM,iBAAiB,UAAU,QAAQ;AACzC,UAAM,iBAAiB,UAAU,QAAQ;AACzC,WAAO,MAAM;AAAA,EACd,CAAC;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const version = "4.2.0-next.
|
|
1
|
+
const version = "4.2.0-next.dbecd76bfa98";
|
|
2
2
|
const publishDates = {
|
|
3
3
|
major: "2025-09-18T14:39:22.803Z",
|
|
4
|
-
minor: "2025-10-
|
|
5
|
-
patch: "2025-10-
|
|
4
|
+
minor: "2025-10-30T12:57:32.699Z",
|
|
5
|
+
patch: "2025-10-30T12:57:32.699Z"
|
|
6
6
|
};
|
|
7
7
|
export {
|
|
8
8
|
publishDates,
|
|
@@ -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 = '4.2.0-next.
|
|
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 = '4.2.0-next.dbecd76bfa98'\nexport const publishDates = {\n\tmajor: '2025-09-18T14:39:22.803Z',\n\tminor: '2025-10-30T12:57:32.699Z',\n\tpatch: '2025-10-30T12:57:32.699Z',\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
|
}
|
|
@@ -6,7 +6,6 @@ import {
|
|
|
6
6
|
} from "@tiptap/core";
|
|
7
7
|
import Code from "@tiptap/extension-code";
|
|
8
8
|
import Highlight from "@tiptap/extension-highlight";
|
|
9
|
-
import Link from "@tiptap/extension-link";
|
|
10
9
|
import StarterKit from "@tiptap/starter-kit";
|
|
11
10
|
import {
|
|
12
11
|
getOwnProperty,
|
|
@@ -29,11 +28,11 @@ const tipTapDefaultExtensions = [
|
|
|
29
28
|
StarterKit.configure({
|
|
30
29
|
blockquote: false,
|
|
31
30
|
codeBlock: false,
|
|
32
|
-
horizontalRule: false
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
31
|
+
horizontalRule: false,
|
|
32
|
+
link: {
|
|
33
|
+
openOnClick: false,
|
|
34
|
+
autolink: true
|
|
35
|
+
}
|
|
37
36
|
}),
|
|
38
37
|
Highlight,
|
|
39
38
|
KeyboardShiftEnterTweakExtension,
|
|
@@ -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\tgenerateHTML,\n\tgenerateJSON,\n\tgenerateText,\n\tJSONContent,\n} from '@tiptap/core'\nimport Code from '@tiptap/extension-code'\nimport Highlight from '@tiptap/extension-highlight'\nimport
|
|
5
|
-
"mappings": "AAAA;AAAA,EACC;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OAEM;AACP,OAAO,UAAU;AACjB,OAAO,eAAe;
|
|
4
|
+
"sourcesContent": ["import {\n\tExtension,\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 { Node } from '@tiptap/pm/model'\nimport StarterKit 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 { TextDirection } from './textDirection'\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 * Default extensions for the TipTap editor.\n *\n * @public\n */\nexport const tipTapDefaultExtensions: Extensions = [\n\tStarterKit.configure({\n\t\tblockquote: false,\n\t\tcodeBlock: false,\n\t\thorizontalRule: false,\n\t\tlink: {\n\t\t\topenOnClick: false,\n\t\t\tautolink: true,\n\t\t},\n\t}),\n\tHighlight,\n\tKeyboardShiftEnterTweakExtension,\n\tTextDirection,\n]\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.\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\tconst html = generateHTML(richText as JSONContent, tipTapExtensions)\n\t\t// We replace empty paragraphs with a single line break to prevent the browser from collapsing them.\n\t\treturn html.replaceAll('<p dir=\"auto\"></p>', '<p><br /></p>') ?? ''\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 *\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\tif (richText.content.length === 1) {\n\t\tif (!(richText.content[0] as any).content) return true\n\t}\n\treturn false\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 *\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 *\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,OAEM;AACP,OAAO,UAAU;AACjB,OAAO,eAAe;AAEtB,OAAO,gBAAgB;AACvB;AAAA,EAEC;AAAA,EAIA;AAAA,OACM;AACP,SAAS,wBAAwB;AACjC,SAAS,qBAAqB;AAGvB,MAAM,mCAAmC,UAAU,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,KAAK,OAAO,WAAW;AAKvB,UAAU,OAAO,WAAW;AAOrB,MAAM,0BAAsC;AAAA,EAClD,WAAW,UAAU;AAAA,IACpB,YAAY;AAAA,IACZ,WAAW;AAAA,IACX,gBAAgB;AAAA,IAChB,MAAM;AAAA,MACL,aAAa;AAAA,MACb,UAAU;AAAA,IACX;AAAA,EACD,CAAC;AAAA,EACD;AAAA,EACA;AAAA,EACA;AACD;AAGA,MAAM,YAAY,IAAI,UA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,WAAW,eAAe;AAChE,cAAQ,EAAE,GAAG,OAAO,QAAQ,cAAc;AAAA,IAC3C;AAAA,EACD;AAEA,QAAM,iBAAiB,eAAe,kBAAkB,MAAM,MAAM;AACpE,MAAI,CAAC,eAAgB,QAAO;AAE5B,QAAM,gBAAgB,eAAe,gBAAgB,MAAM,KAAK;AAChE,MAAI,CAAC,cAAe,QAAO;AAE3B,QAAM,iBAAiB,eAAe,eAAe,MAAM,MAAM;AACjE,MAAI,CAAC,eAAgB,QAAO;AAE5B,UAAQ,cAAc;AAEtB,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
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": "4.2.0-next.
|
|
4
|
+
"version": "4.2.0-next.dbecd76bfa98",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "tldraw Inc.",
|
|
7
7
|
"email": "hello@tldraw.com"
|
|
@@ -55,15 +55,15 @@
|
|
|
55
55
|
"src"
|
|
56
56
|
],
|
|
57
57
|
"dependencies": {
|
|
58
|
-
"@tiptap/core": "
|
|
59
|
-
"@tiptap/extension-code": "
|
|
60
|
-
"@tiptap/extension-highlight": "
|
|
61
|
-
"@tiptap/extension-
|
|
62
|
-
"@tiptap/pm": "
|
|
63
|
-
"@tiptap/react": "
|
|
64
|
-
"@tiptap/starter-kit": "
|
|
65
|
-
"@tldraw/editor": "4.2.0-next.
|
|
66
|
-
"@tldraw/store": "4.2.0-next.
|
|
58
|
+
"@tiptap/core": "3.6.2",
|
|
59
|
+
"@tiptap/extension-code": "3.6.2",
|
|
60
|
+
"@tiptap/extension-highlight": "3.6.2",
|
|
61
|
+
"@tiptap/extension-list": "3.6.2",
|
|
62
|
+
"@tiptap/pm": "3.6.2",
|
|
63
|
+
"@tiptap/react": "3.6.2",
|
|
64
|
+
"@tiptap/starter-kit": "3.6.2",
|
|
65
|
+
"@tldraw/editor": "4.2.0-next.dbecd76bfa98",
|
|
66
|
+
"@tldraw/store": "4.2.0-next.dbecd76bfa98",
|
|
67
67
|
"classnames": "^2.5.1",
|
|
68
68
|
"hotkeys-js": "^3.13.9",
|
|
69
69
|
"idb": "^7.1.1",
|
package/src/index.ts
CHANGED
|
@@ -241,7 +241,10 @@ export {
|
|
|
241
241
|
DefaultDebugMenuContent,
|
|
242
242
|
ExampleDialog,
|
|
243
243
|
FeatureFlags,
|
|
244
|
+
type CustomDebugFlags,
|
|
245
|
+
type DebugFlagsProps,
|
|
244
246
|
type ExampleDialogProps,
|
|
247
|
+
type FeatureFlagsProps,
|
|
245
248
|
} from './lib/ui/components/DebugMenu/DefaultDebugMenuContent'
|
|
246
249
|
export { DefaultMenuPanel } from './lib/ui/components/DefaultMenuPanel'
|
|
247
250
|
export {
|
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
TLEventInfo,
|
|
9
9
|
TLRichText,
|
|
10
10
|
TLShapeId,
|
|
11
|
+
openWindow,
|
|
11
12
|
preventDefault,
|
|
12
13
|
useEditor,
|
|
13
14
|
useReactor,
|
|
@@ -112,7 +113,7 @@ export const RichTextLabel = React.memo(function RichTextLabel({
|
|
|
112
113
|
if (e.name !== 'pointer_up' || !link) return
|
|
113
114
|
|
|
114
115
|
if (!isDragging.current) {
|
|
115
|
-
|
|
116
|
+
openWindow(link, '_blank', false)
|
|
116
117
|
}
|
|
117
118
|
editor.off('event', handlePointerUp)
|
|
118
119
|
}
|
|
@@ -29,8 +29,17 @@ import { TldrawUiMenuGroup } from '../primitives/menus/TldrawUiMenuGroup'
|
|
|
29
29
|
import { TldrawUiMenuItem } from '../primitives/menus/TldrawUiMenuItem'
|
|
30
30
|
import { TldrawUiMenuSubmenu } from '../primitives/menus/TldrawUiMenuSubmenu'
|
|
31
31
|
|
|
32
|
+
/** @public */
|
|
33
|
+
export interface CustomDebugFlags {
|
|
34
|
+
customDebugFlags?: Record<string, DebugFlag<boolean>>
|
|
35
|
+
customFeatureFlags?: Record<string, DebugFlag<boolean>>
|
|
36
|
+
}
|
|
37
|
+
|
|
32
38
|
/** @public @react */
|
|
33
|
-
export function DefaultDebugMenuContent(
|
|
39
|
+
export function DefaultDebugMenuContent({
|
|
40
|
+
customDebugFlags,
|
|
41
|
+
customFeatureFlags,
|
|
42
|
+
}: CustomDebugFlags) {
|
|
34
43
|
const editor = useEditor()
|
|
35
44
|
const { addToast } = useToasts()
|
|
36
45
|
const { addDialog } = useDialogs()
|
|
@@ -161,15 +170,21 @@ export function DefaultDebugMenuContent() {
|
|
|
161
170
|
<TldrawUiMenuItem id="throw-error" onSelect={() => setError(true)} label={'Throw error'} />
|
|
162
171
|
</TldrawUiMenuGroup>
|
|
163
172
|
<TldrawUiMenuGroup id="flags">
|
|
164
|
-
<DebugFlags />
|
|
165
|
-
<FeatureFlags />
|
|
173
|
+
<DebugFlags customDebugFlags={customDebugFlags} />
|
|
174
|
+
<FeatureFlags customFeatureFlags={customFeatureFlags} />
|
|
166
175
|
</TldrawUiMenuGroup>
|
|
167
176
|
</>
|
|
168
177
|
)
|
|
169
178
|
}
|
|
179
|
+
|
|
180
|
+
/** @public */
|
|
181
|
+
export interface DebugFlagsProps {
|
|
182
|
+
customDebugFlags?: Record<string, DebugFlag<boolean>> | undefined
|
|
183
|
+
}
|
|
184
|
+
|
|
170
185
|
/** @public @react */
|
|
171
|
-
export function DebugFlags() {
|
|
172
|
-
const items = Object.values(debugFlags)
|
|
186
|
+
export function DebugFlags(props: DebugFlagsProps) {
|
|
187
|
+
const items = Object.values(props.customDebugFlags ?? debugFlags)
|
|
173
188
|
if (!items.length) return null
|
|
174
189
|
return (
|
|
175
190
|
<TldrawUiMenuSubmenu id="debug flags" label="Debug flags">
|
|
@@ -181,9 +196,14 @@ export function DebugFlags() {
|
|
|
181
196
|
</TldrawUiMenuSubmenu>
|
|
182
197
|
)
|
|
183
198
|
}
|
|
199
|
+
/** @public */
|
|
200
|
+
export interface FeatureFlagsProps {
|
|
201
|
+
customFeatureFlags?: Record<string, DebugFlag<boolean>> | undefined
|
|
202
|
+
}
|
|
203
|
+
|
|
184
204
|
/** @public @react */
|
|
185
|
-
export function FeatureFlags() {
|
|
186
|
-
const items = Object.values(featureFlags)
|
|
205
|
+
export function FeatureFlags(props: FeatureFlagsProps) {
|
|
206
|
+
const items = Object.values(props.customFeatureFlags ?? featureFlags)
|
|
187
207
|
if (!items.length) return null
|
|
188
208
|
return (
|
|
189
209
|
<TldrawUiMenuSubmenu id="feature flags" label="Feature flags">
|
|
@@ -117,7 +117,9 @@ function useEditingLinkBehavior(textEditor?: TiptapEditor) {
|
|
|
117
117
|
|
|
118
118
|
textEditor.view.dom.addEventListener('click', handleClick)
|
|
119
119
|
return () => {
|
|
120
|
-
textEditor.
|
|
120
|
+
if (textEditor.isInitialized) {
|
|
121
|
+
textEditor.view.dom.removeEventListener('click', handleClick)
|
|
122
|
+
}
|
|
121
123
|
}
|
|
122
124
|
}, [textEditor, isEditingLink])
|
|
123
125
|
|
|
@@ -193,7 +195,9 @@ function useIsMousingDownOnTextEditor(textEditor: TiptapEditor) {
|
|
|
193
195
|
})
|
|
194
196
|
return () => {
|
|
195
197
|
touchDownEvents.forEach((eventName: string) => {
|
|
196
|
-
textEditor.
|
|
198
|
+
if (textEditor.isInitialized) {
|
|
199
|
+
textEditor.view.dom.removeEventListener(eventName, handlePointingDown)
|
|
200
|
+
}
|
|
197
201
|
})
|
|
198
202
|
touchUpEvents.forEach((eventName: string) => {
|
|
199
203
|
document.body.removeEventListener(eventName, handlePointingUp)
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { preventDefault, TiptapEditor, useEditor } from '@tldraw/editor'
|
|
1
|
+
import { openWindow, preventDefault, TiptapEditor, useEditor } from '@tldraw/editor'
|
|
2
2
|
import { useEffect, useRef, useState } from 'react'
|
|
3
3
|
import { useUiEvents } from '../../context/events'
|
|
4
4
|
import { useTranslation } from '../../hooks/useTranslation/useTranslation'
|
|
@@ -31,7 +31,7 @@ export function LinkEditor({ textEditor, value: initialValue, onClose }: LinkEdi
|
|
|
31
31
|
link = `https://${link}`
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
textEditor.
|
|
34
|
+
textEditor.chain().setLink({ href: link }).run()
|
|
35
35
|
// N.B. We shouldn't focus() on mobile because it causes the
|
|
36
36
|
// Return key to replace the link with a newline :facepalm:
|
|
37
37
|
if (editor.getInstanceState().isCoarsePointer) {
|
|
@@ -44,7 +44,7 @@ export function LinkEditor({ textEditor, value: initialValue, onClose }: LinkEdi
|
|
|
44
44
|
|
|
45
45
|
const handleVisitLink = () => {
|
|
46
46
|
trackEvent('rich-text', { operation: 'link-visit', source })
|
|
47
|
-
|
|
47
|
+
openWindow(linkifiedValue, '_blank')
|
|
48
48
|
onClose()
|
|
49
49
|
}
|
|
50
50
|
|
|
@@ -9,17 +9,34 @@ export function getLocalFiles(options?: {
|
|
|
9
9
|
input.type = 'file'
|
|
10
10
|
input.accept = mimeTypes?.join(',')
|
|
11
11
|
input.multiple = allowMultiple
|
|
12
|
+
input.style.display = 'none'
|
|
13
|
+
|
|
14
|
+
function dispose() {
|
|
15
|
+
input.removeEventListener('change', onchange)
|
|
16
|
+
input.removeEventListener('cancel', oncancel)
|
|
17
|
+
input.remove()
|
|
18
|
+
}
|
|
12
19
|
|
|
13
20
|
async function onchange(e: Event) {
|
|
14
21
|
const fileList = (e.target as HTMLInputElement).files
|
|
15
|
-
if (!fileList || fileList.length === 0)
|
|
22
|
+
if (!fileList || fileList.length === 0) {
|
|
23
|
+
resolve([])
|
|
24
|
+
dispose()
|
|
25
|
+
return
|
|
26
|
+
}
|
|
16
27
|
const files = Array.from(fileList)
|
|
17
28
|
input.value = ''
|
|
18
29
|
resolve(files)
|
|
19
|
-
|
|
20
|
-
|
|
30
|
+
dispose()
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
function oncancel() {
|
|
34
|
+
resolve([])
|
|
35
|
+
dispose()
|
|
21
36
|
}
|
|
22
37
|
|
|
38
|
+
document.body.appendChild(input)
|
|
39
|
+
input.addEventListener('cancel', oncancel)
|
|
23
40
|
input.addEventListener('change', onchange)
|
|
24
41
|
input?.click()
|
|
25
42
|
})
|
package/src/lib/ui/version.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// This file is automatically generated by internal/scripts/refresh-assets.ts.
|
|
2
2
|
// Do not edit manually. Or do, I'm a comment, not a cop.
|
|
3
3
|
|
|
4
|
-
export const version = '4.2.0-next.
|
|
4
|
+
export const version = '4.2.0-next.dbecd76bfa98'
|
|
5
5
|
export const publishDates = {
|
|
6
6
|
major: '2025-09-18T14:39:22.803Z',
|
|
7
|
-
minor: '2025-10-
|
|
8
|
-
patch: '2025-10-
|
|
7
|
+
minor: '2025-10-30T12:57:32.699Z',
|
|
8
|
+
patch: '2025-10-30T12:57:32.699Z',
|
|
9
9
|
}
|
|
@@ -8,7 +8,6 @@ import {
|
|
|
8
8
|
} from '@tiptap/core'
|
|
9
9
|
import Code from '@tiptap/extension-code'
|
|
10
10
|
import Highlight from '@tiptap/extension-highlight'
|
|
11
|
-
import Link from '@tiptap/extension-link'
|
|
12
11
|
import { Node } from '@tiptap/pm/model'
|
|
13
12
|
import StarterKit from '@tiptap/starter-kit'
|
|
14
13
|
import {
|
|
@@ -35,6 +34,7 @@ export const KeyboardShiftEnterTweakExtension = Extension.create({
|
|
|
35
34
|
|
|
36
35
|
// We change the default Code to override what's in the StarterKit.
|
|
37
36
|
// It allows for other attributes/extensions.
|
|
37
|
+
// @ts-ignore this is fine.
|
|
38
38
|
Code.config.excludes = undefined
|
|
39
39
|
|
|
40
40
|
// We want the highlighting to take precedence over bolding/italics/links
|
|
@@ -52,10 +52,10 @@ export const tipTapDefaultExtensions: Extensions = [
|
|
|
52
52
|
blockquote: false,
|
|
53
53
|
codeBlock: false,
|
|
54
54
|
horizontalRule: false,
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
55
|
+
link: {
|
|
56
|
+
openOnClick: false,
|
|
57
|
+
autolink: true,
|
|
58
|
+
},
|
|
59
59
|
}),
|
|
60
60
|
Highlight,
|
|
61
61
|
KeyboardShiftEnterTweakExtension,
|