tldraw 4.2.0-next.47462e908ff5 → 4.2.0-next.67908ea044c6
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 +23 -5
- package/dist-cjs/index.js +1 -1
- package/dist-cjs/index.js.map +2 -2
- package/dist-cjs/lib/shapes/frame/components/FrameLabelInput.js +63 -36
- package/dist-cjs/lib/shapes/frame/components/FrameLabelInput.js.map +2 -2
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.js +3 -3
- package/dist-cjs/lib/shapes/note/NoteShapeUtil.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/shapes/shared/ShapeFill.js +3 -0
- package/dist-cjs/lib/shapes/shared/ShapeFill.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js +14 -6
- package/dist-cjs/lib/tools/SelectTool/childStates/DraggingHandle.js.map +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.js +2 -2
- package/dist-cjs/lib/tools/SelectTool/childStates/Idle.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/Dialogs.js +2 -14
- package/dist-cjs/lib/ui/components/Dialogs.js.map +2 -2
- package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.js +5 -4
- package/dist-cjs/lib/ui/components/PageMenu/DefaultPageMenu.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/DefaultRichTextToolbarContent.js +2 -1
- package/dist-cjs/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.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/components/primitives/Button/TldrawUiButton.js +2 -2
- package/dist-cjs/lib/ui/components/primitives/Button/TldrawUiButton.js.map +2 -2
- package/dist-cjs/lib/ui/context/actions.js +16 -0
- package/dist-cjs/lib/ui/context/actions.js.map +2 -2
- package/dist-cjs/lib/ui/context/events.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/hooks/useClipboardEvents.js +18 -16
- package/dist-cjs/lib/ui/hooks/useClipboardEvents.js.map +3 -3
- package/dist-cjs/lib/ui/hooks/useTranslation/TLUiTranslationKey.js.map +1 -1
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js +1 -0
- package/dist-cjs/lib/ui/hooks/useTranslation/defaultTranslation.js.map +2 -2
- package/dist-cjs/lib/ui/hooks/useTranslation/useTranslation.js +1 -0
- package/dist-cjs/lib/ui/hooks/useTranslation/useTranslation.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 +23 -5
- package/dist-esm/index.mjs +1 -1
- package/dist-esm/index.mjs.map +2 -2
- package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs +65 -38
- package/dist-esm/lib/shapes/frame/components/FrameLabelInput.mjs.map +2 -2
- package/dist-esm/lib/shapes/note/NoteShapeUtil.mjs +5 -5
- package/dist-esm/lib/shapes/note/NoteShapeUtil.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/shapes/shared/ShapeFill.mjs +3 -0
- package/dist-esm/lib/shapes/shared/ShapeFill.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs +14 -6
- package/dist-esm/lib/tools/SelectTool/childStates/DraggingHandle.mjs.map +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.mjs +2 -2
- package/dist-esm/lib/tools/SelectTool/childStates/Idle.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/Dialogs.mjs +2 -14
- package/dist-esm/lib/ui/components/Dialogs.mjs.map +2 -2
- package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.mjs +5 -5
- package/dist-esm/lib/ui/components/PageMenu/DefaultPageMenu.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/DefaultRichTextToolbarContent.mjs +2 -1
- package/dist-esm/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.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/components/primitives/Button/TldrawUiButton.mjs +2 -2
- package/dist-esm/lib/ui/components/primitives/Button/TldrawUiButton.mjs.map +2 -2
- package/dist-esm/lib/ui/context/actions.mjs +16 -0
- package/dist-esm/lib/ui/context/actions.mjs.map +2 -2
- package/dist-esm/lib/ui/context/events.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/hooks/useClipboardEvents.mjs +18 -16
- package/dist-esm/lib/ui/hooks/useClipboardEvents.mjs.map +3 -3
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs +1 -0
- package/dist-esm/lib/ui/hooks/useTranslation/defaultTranslation.mjs.map +2 -2
- package/dist-esm/lib/ui/hooks/useTranslation/useTranslation.mjs +1 -0
- package/dist-esm/lib/ui/hooks/useTranslation/useTranslation.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/frame/components/FrameLabelInput.tsx +48 -24
- package/src/lib/shapes/note/NoteShapeUtil.tsx +6 -5
- package/src/lib/shapes/shared/RichTextLabel.tsx +2 -1
- package/src/lib/shapes/shared/ShapeFill.tsx +3 -0
- package/src/lib/tools/SelectTool/childStates/DraggingHandle.tsx +19 -8
- package/src/lib/tools/SelectTool/childStates/Idle.ts +2 -2
- package/src/lib/ui/components/DebugMenu/DefaultDebugMenuContent.tsx +27 -7
- package/src/lib/ui/components/Dialogs.tsx +2 -14
- package/src/lib/ui/components/PageMenu/DefaultPageMenu.tsx +6 -5
- package/src/lib/ui/components/Toolbar/DefaultRichTextToolbar.tsx +6 -2
- package/src/lib/ui/components/Toolbar/DefaultRichTextToolbarContent.tsx +4 -1
- package/src/lib/ui/components/Toolbar/LinkEditor.tsx +3 -3
- package/src/lib/ui/components/primitives/Button/TldrawUiButton.tsx +3 -2
- package/src/lib/ui/context/actions.tsx +16 -0
- package/src/lib/ui/context/events.tsx +1 -0
- package/src/lib/ui/getLocalFiles.ts +20 -3
- package/src/lib/ui/hooks/useClipboardEvents.ts +12 -9
- package/src/lib/ui/hooks/useTranslation/TLUiTranslationKey.ts +1 -0
- package/src/lib/ui/hooks/useTranslation/defaultTranslation.ts +1 -0
- package/src/lib/ui/hooks/useTranslation/useTranslation.tsx +2 -1
- package/src/lib/ui/version.ts +3 -3
- package/src/lib/utils/text/richText.ts +5 -5
- package/src/test/TldrawEditor.test.tsx +74 -29
- package/src/test/customSnapping.test.tsx +185 -0
|
@@ -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,UAA8B;AAU7C,SAAS,uBAAuB,QAAgB,UAAsB;AAC5E,SAAO,UAAU,IAAI,UAAU,MAAM;AACpC,UAAM,mBACL,OAAO,eAAe,EAAE,cAAc,cAAc;AACrD,UAAM,OAAO,aAAa,UAAyB,gBAAgB;AAEnE,WAAO,KAAK,WAAW,sBAAsB,eAAe,KAAK;AAAA,EAClE,CAAC;AACF;AAUO,SAAS,qCAAqC,QAAgB,UAAsB;AAC1F,QAAM,OAAO,uBAAuB,QAAQ,QAAQ;AACpD,SAAO,6BAA6B,IAAI;AACzC;AAGA,MAAM,6BAA6B,IAAI,UAA8B;AAE9D,SAAS,gBAAgB,UAAsB;AACrD,MAAI,SAAS,QAAQ,WAAW,GAAG;AAClC,QAAI,CAAE,SAAS,QAAQ,CAAC,EAAU,QAAS,QAAO;AAAA,EACnD;AACA,SAAO;AACR;AAUO,SAAS,4BAA4B,QAAgB,UAAsB;AACjF,MAAI,gBAAgB,QAAQ,EAAG,QAAO;AAEtC,SAAO,2BAA2B,IAAI,UAAU,MAAM;AACrD,UAAM,mBACL,OAAO,eAAe,EAAE,cAAc,cAAc;AACrD,WAAO,aAAa,UAAyB,kBAAkB;AAAA,MAC9D,gBAAgB;AAAA,IACjB,CAAC;AAAA,EACF,CAAC;AACF;AAUO,SAAS,uBAAuB,QAAgB,MAA0B;AAChF,QAAM,mBACL,OAAO,eAAe,EAAE,cAAc,cAAc;AACrD,SAAO,aAAa,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,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.67908ea044c6",
|
|
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.67908ea044c6",
|
|
66
|
+
"@tldraw/store": "4.2.0-next.67908ea044c6",
|
|
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 {
|
|
@@ -1,5 +1,8 @@
|
|
|
1
|
-
import { TLFrameShape, TLShapeId, useEditor } from '@tldraw/editor'
|
|
2
|
-
import { forwardRef, useCallback } from 'react'
|
|
1
|
+
import { TLFrameShape, TLShapeId, useEditor, useValue } from '@tldraw/editor'
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useRef } from 'react'
|
|
3
|
+
import { PORTRAIT_BREAKPOINT } from '../../../ui/constants'
|
|
4
|
+
import { useBreakpoint } from '../../../ui/context/breakpoints'
|
|
5
|
+
import { useTranslation } from '../../../ui/hooks/useTranslation/useTranslation'
|
|
3
6
|
import { defaultEmptyAs } from '../FrameShapeUtil'
|
|
4
7
|
|
|
5
8
|
export const FrameLabelInput = forwardRef<
|
|
@@ -7,6 +10,15 @@ export const FrameLabelInput = forwardRef<
|
|
|
7
10
|
{ id: TLShapeId; name: string; isEditing: boolean }
|
|
8
11
|
>(({ id, name, isEditing }, ref) => {
|
|
9
12
|
const editor = useEditor()
|
|
13
|
+
const breakpoint = useBreakpoint()
|
|
14
|
+
const isCoarsePointer = useValue(
|
|
15
|
+
'isCoarsePointer',
|
|
16
|
+
() => editor.getInstanceState().isCoarsePointer,
|
|
17
|
+
[editor]
|
|
18
|
+
)
|
|
19
|
+
const shouldUseWindowPrompt = breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM && isCoarsePointer
|
|
20
|
+
const promptOpen = useRef<boolean>(false)
|
|
21
|
+
const msg = useTranslation()
|
|
10
22
|
|
|
11
23
|
const handlePointerDown = useCallback(
|
|
12
24
|
(e: React.PointerEvent) => {
|
|
@@ -28,13 +40,12 @@ export const FrameLabelInput = forwardRef<
|
|
|
28
40
|
[editor]
|
|
29
41
|
)
|
|
30
42
|
|
|
31
|
-
const
|
|
32
|
-
(
|
|
43
|
+
const renameFrame = useCallback(
|
|
44
|
+
(value: string) => {
|
|
33
45
|
const shape = editor.getShape<TLFrameShape>(id)
|
|
34
46
|
if (!shape) return
|
|
35
47
|
|
|
36
48
|
const name = shape.props.name
|
|
37
|
-
const value = e.currentTarget.value.trim()
|
|
38
49
|
if (name === value) return
|
|
39
50
|
|
|
40
51
|
editor.updateShapes([
|
|
@@ -48,36 +59,49 @@ export const FrameLabelInput = forwardRef<
|
|
|
48
59
|
[id, editor]
|
|
49
60
|
)
|
|
50
61
|
|
|
62
|
+
const handleBlur = useCallback(
|
|
63
|
+
(e: React.FocusEvent<HTMLInputElement>) => {
|
|
64
|
+
renameFrame(e.currentTarget.value)
|
|
65
|
+
},
|
|
66
|
+
[renameFrame]
|
|
67
|
+
)
|
|
68
|
+
|
|
51
69
|
const handleChange = useCallback(
|
|
52
70
|
(e: React.ChangeEvent<HTMLInputElement>) => {
|
|
53
|
-
|
|
54
|
-
if (!shape) return
|
|
55
|
-
|
|
56
|
-
const name = shape.props.name
|
|
57
|
-
const value = e.currentTarget.value
|
|
58
|
-
if (name === value) return
|
|
59
|
-
|
|
60
|
-
editor.updateShapes([
|
|
61
|
-
{
|
|
62
|
-
id,
|
|
63
|
-
type: 'frame',
|
|
64
|
-
props: { name: value },
|
|
65
|
-
},
|
|
66
|
-
])
|
|
71
|
+
renameFrame(e.currentTarget.value)
|
|
67
72
|
},
|
|
68
|
-
[
|
|
73
|
+
[renameFrame]
|
|
69
74
|
)
|
|
70
75
|
|
|
76
|
+
/* Mobile rename uses window.prompt */
|
|
77
|
+
useEffect(() => {
|
|
78
|
+
if (!isEditing) {
|
|
79
|
+
promptOpen.current = false
|
|
80
|
+
return
|
|
81
|
+
}
|
|
82
|
+
if (isEditing && shouldUseWindowPrompt && !promptOpen.current) {
|
|
83
|
+
promptOpen.current = true
|
|
84
|
+
const shape = editor.getShape<TLFrameShape>(id)
|
|
85
|
+
const currentName = shape?.props.name ?? ''
|
|
86
|
+
const newName = window.prompt(msg('action.rename'), currentName)
|
|
87
|
+
promptOpen.current = false
|
|
88
|
+
if (newName !== null) renameFrame(newName)
|
|
89
|
+
editor.setEditingShape(null)
|
|
90
|
+
}
|
|
91
|
+
}, [isEditing, shouldUseWindowPrompt, id, msg, renameFrame, editor])
|
|
92
|
+
|
|
71
93
|
return (
|
|
72
|
-
<div
|
|
94
|
+
<div
|
|
95
|
+
className={`tl-frame-label ${isEditing && !shouldUseWindowPrompt ? 'tl-frame-label__editing' : ''}`}
|
|
96
|
+
>
|
|
73
97
|
<input
|
|
74
98
|
className="tl-frame-name-input"
|
|
75
99
|
ref={ref}
|
|
76
|
-
disabled={!isEditing}
|
|
77
|
-
readOnly={!isEditing}
|
|
100
|
+
disabled={!isEditing || shouldUseWindowPrompt}
|
|
101
|
+
readOnly={!isEditing || shouldUseWindowPrompt}
|
|
78
102
|
style={{ display: isEditing ? undefined : 'none' }}
|
|
79
103
|
value={name}
|
|
80
|
-
autoFocus
|
|
104
|
+
autoFocus={!shouldUseWindowPrompt}
|
|
81
105
|
onKeyDown={handleKeyDown}
|
|
82
106
|
onBlur={handleBlur}
|
|
83
107
|
onChange={handleChange}
|
|
@@ -31,9 +31,9 @@ import {
|
|
|
31
31
|
useEditor,
|
|
32
32
|
useValue,
|
|
33
33
|
} from '@tldraw/editor'
|
|
34
|
-
import { useCallback } from 'react'
|
|
34
|
+
import { useCallback, useContext } from 'react'
|
|
35
35
|
import { startEditingShapeWithLabel } from '../../tools/SelectTool/selectHelpers'
|
|
36
|
-
import {
|
|
36
|
+
import { TranslationsContext } from '../../ui/hooks/useTranslation/useTranslation'
|
|
37
37
|
import {
|
|
38
38
|
isEmptyRichText,
|
|
39
39
|
renderHtmlFromRichTextForMeasurement,
|
|
@@ -493,7 +493,8 @@ function getLabelSize(editor: Editor, shape: TLNoteShape) {
|
|
|
493
493
|
|
|
494
494
|
function useNoteKeydownHandler(id: TLShapeId) {
|
|
495
495
|
const editor = useEditor()
|
|
496
|
-
|
|
496
|
+
// Try to get the translation context, but fallback to ltr if it doesn't exist
|
|
497
|
+
const translation = useContext(TranslationsContext)
|
|
497
498
|
|
|
498
499
|
return useCallback(
|
|
499
500
|
(e: KeyboardEvent) => {
|
|
@@ -512,7 +513,7 @@ function useNoteKeydownHandler(id: TLShapeId) {
|
|
|
512
513
|
// tab controls x axis (shift inverts direction set by RTL)
|
|
513
514
|
// cmd enter is the y axis (shift inverts direction)
|
|
514
515
|
const isRTL = !!(
|
|
515
|
-
translation
|
|
516
|
+
translation?.dir === 'rtl' ||
|
|
516
517
|
// todo: can we check a partial of the text, so that we don't have to render the whole thing?
|
|
517
518
|
isRightToLeftLanguage(renderPlaintextFromRichText(editor, shape.props.richText))
|
|
518
519
|
)
|
|
@@ -540,7 +541,7 @@ function useNoteKeydownHandler(id: TLShapeId) {
|
|
|
540
541
|
}
|
|
541
542
|
}
|
|
542
543
|
},
|
|
543
|
-
[id, editor, translation
|
|
544
|
+
[id, editor, translation?.dir]
|
|
544
545
|
)
|
|
545
546
|
}
|
|
546
547
|
|
|
@@ -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
|
}
|
|
@@ -41,6 +41,9 @@ export const ShapeFill = React.memo(function ShapeFill({
|
|
|
41
41
|
case 'pattern': {
|
|
42
42
|
return <PatternFill theme={theme} color={color} fill={fill} d={d} scale={scale} />
|
|
43
43
|
}
|
|
44
|
+
case 'lined-fill': {
|
|
45
|
+
return <path fill={getColorValue(theme, color, 'linedFill')} d={d} />
|
|
46
|
+
}
|
|
44
47
|
}
|
|
45
48
|
})
|
|
46
49
|
|
|
@@ -83,24 +83,35 @@ export class DraggingHandle extends StateNode {
|
|
|
83
83
|
// Find the adjacent handle
|
|
84
84
|
this.initialAdjacentHandle = null
|
|
85
85
|
|
|
86
|
-
//
|
|
87
|
-
|
|
88
|
-
const
|
|
89
|
-
if (
|
|
90
|
-
this.initialAdjacentHandle =
|
|
91
|
-
break
|
|
86
|
+
// First, check if the handle specifies a custom reference handle
|
|
87
|
+
if (info.handle.snapReferenceHandleId) {
|
|
88
|
+
const customHandle = handles.find((h) => h.id === info.handle.snapReferenceHandleId)
|
|
89
|
+
if (customHandle) {
|
|
90
|
+
this.initialAdjacentHandle = customHandle
|
|
92
91
|
}
|
|
93
92
|
}
|
|
94
93
|
|
|
95
|
-
// If
|
|
94
|
+
// If no custom reference handle, use default behavior
|
|
96
95
|
if (!this.initialAdjacentHandle) {
|
|
97
|
-
|
|
96
|
+
// Start from the handle and work forward
|
|
97
|
+
for (let i = index + 1; i < handles.length; i++) {
|
|
98
98
|
const handle = handles[i]
|
|
99
99
|
if (handle.type === 'vertex' && handle.id !== 'middle' && handle.id !== info.handle.id) {
|
|
100
100
|
this.initialAdjacentHandle = handle
|
|
101
101
|
break
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
|
+
|
|
105
|
+
// If still no handle, start from the end and work backward
|
|
106
|
+
if (!this.initialAdjacentHandle) {
|
|
107
|
+
for (let i = handles.length - 1; i >= 0; i--) {
|
|
108
|
+
const handle = handles[i]
|
|
109
|
+
if (handle.type === 'vertex' && handle.id !== 'middle' && handle.id !== info.handle.id) {
|
|
110
|
+
this.initialAdjacentHandle = handle
|
|
111
|
+
break
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
104
115
|
}
|
|
105
116
|
|
|
106
117
|
// <!-- Only relevant to arrows
|
|
@@ -507,7 +507,7 @@ export class Idle extends StateNode {
|
|
|
507
507
|
}
|
|
508
508
|
case 'Tab': {
|
|
509
509
|
const selectedShapes = this.editor.getSelectedShapes()
|
|
510
|
-
if (selectedShapes.length) {
|
|
510
|
+
if (selectedShapes.length && !info.altKey) {
|
|
511
511
|
this.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')
|
|
512
512
|
}
|
|
513
513
|
break
|
|
@@ -557,7 +557,7 @@ export class Idle extends StateNode {
|
|
|
557
557
|
}
|
|
558
558
|
case 'Tab': {
|
|
559
559
|
const selectedShapes = this.editor.getSelectedShapes()
|
|
560
|
-
if (selectedShapes.length) {
|
|
560
|
+
if (selectedShapes.length && !info.altKey) {
|
|
561
561
|
this.editor.selectAdjacentShape(info.shiftKey ? 'prev' : 'next')
|
|
562
562
|
}
|
|
563
563
|
break
|
|
@@ -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">
|
|
@@ -4,12 +4,7 @@ import { memo, useCallback, useRef } from 'react'
|
|
|
4
4
|
import { TLUiDialog, useDialogs } from '../context/dialogs'
|
|
5
5
|
|
|
6
6
|
/** @internal */
|
|
7
|
-
const TldrawUiDialog = ({
|
|
8
|
-
id,
|
|
9
|
-
component: ModalContent,
|
|
10
|
-
onClose,
|
|
11
|
-
preventBackgroundClose,
|
|
12
|
-
}: TLUiDialog) => {
|
|
7
|
+
const TldrawUiDialog = ({ id, component: ModalContent, preventBackgroundClose }: TLUiDialog) => {
|
|
13
8
|
const { removeDialog } = useDialogs()
|
|
14
9
|
const mouseDownInsideContentRef = useRef(false)
|
|
15
10
|
|
|
@@ -18,17 +13,10 @@ const TldrawUiDialog = ({
|
|
|
18
13
|
const handleOpenChange = useCallback(
|
|
19
14
|
(isOpen: boolean) => {
|
|
20
15
|
if (!isOpen) {
|
|
21
|
-
if (onClose) {
|
|
22
|
-
try {
|
|
23
|
-
onClose()
|
|
24
|
-
} catch (err: any) {
|
|
25
|
-
console.warn(err)
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
16
|
removeDialog(id)
|
|
29
17
|
}
|
|
30
18
|
},
|
|
31
|
-
[id,
|
|
19
|
+
[id, removeDialog]
|
|
32
20
|
)
|
|
33
21
|
|
|
34
22
|
return (
|
|
@@ -3,7 +3,6 @@ import {
|
|
|
3
3
|
TLPageId,
|
|
4
4
|
releasePointerCapture,
|
|
5
5
|
setPointerCapture,
|
|
6
|
-
tlenv,
|
|
7
6
|
useEditor,
|
|
8
7
|
useValue,
|
|
9
8
|
} from '@tldraw/editor'
|
|
@@ -306,6 +305,8 @@ export const DefaultPageMenu = memo(function DefaultPageMenu() {
|
|
|
306
305
|
[editor, trackEvent]
|
|
307
306
|
)
|
|
308
307
|
|
|
308
|
+
const shouldUseWindowPrompt = breakpoint < PORTRAIT_BREAKPOINT.TABLET_SM && isCoarsePointer
|
|
309
|
+
|
|
309
310
|
return (
|
|
310
311
|
<TldrawUiPopover id="pages" onOpenChange={onOpenChange} open={isOpen}>
|
|
311
312
|
<TldrawUiPopoverTrigger data-testid="main.page-menu">
|
|
@@ -390,7 +391,7 @@ export const DefaultPageMenu = memo(function DefaultPageMenu() {
|
|
|
390
391
|
>
|
|
391
392
|
<TldrawUiButtonIcon icon="drag-handle-dots" />
|
|
392
393
|
</TldrawUiButton>
|
|
393
|
-
{
|
|
394
|
+
{shouldUseWindowPrompt ? (
|
|
394
395
|
// sigh, this is a workaround for iOS Safari
|
|
395
396
|
// because the device and the radix popover seem
|
|
396
397
|
// to be fighting over scroll position. Nothing
|
|
@@ -399,7 +400,7 @@ export const DefaultPageMenu = memo(function DefaultPageMenu() {
|
|
|
399
400
|
type="normal"
|
|
400
401
|
className="tlui-page-menu__item__button"
|
|
401
402
|
onClick={() => {
|
|
402
|
-
const name = window.prompt('
|
|
403
|
+
const name = window.prompt(msg('action.rename'), page.name)
|
|
403
404
|
if (name && name !== page.name) {
|
|
404
405
|
renamePage(page.id, name)
|
|
405
406
|
}
|
|
@@ -465,8 +466,8 @@ export const DefaultPageMenu = memo(function DefaultPageMenu() {
|
|
|
465
466
|
item={page}
|
|
466
467
|
listSize={pages.length}
|
|
467
468
|
onRename={() => {
|
|
468
|
-
if (
|
|
469
|
-
const name = window.prompt('
|
|
469
|
+
if (shouldUseWindowPrompt) {
|
|
470
|
+
const name = window.prompt(msg('action.rename'), page.name)
|
|
470
471
|
if (name && name !== page.name) {
|
|
471
472
|
renamePage(page.id, name)
|
|
472
473
|
}
|
|
@@ -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)
|
|
@@ -54,6 +54,9 @@ export function DefaultRichTextToolbarContent({
|
|
|
54
54
|
// todo: we could make this a prop
|
|
55
55
|
const actions = useMemo(() => {
|
|
56
56
|
function handleOp(name: string, op: string) {
|
|
57
|
+
// Check if the editor view is available before calling operations
|
|
58
|
+
if (!textEditor.view) return
|
|
59
|
+
|
|
57
60
|
trackEvent('rich-text', { operation: name as any, source })
|
|
58
61
|
// @ts-expect-error typing this is annoying at the moment.
|
|
59
62
|
textEditor.chain().focus()[op]().run()
|
|
@@ -109,7 +112,7 @@ export function DefaultRichTextToolbarContent({
|
|
|
109
112
|
}, [textEditor, trackEvent, onEditLinkStart])
|
|
110
113
|
|
|
111
114
|
return actions.map(({ name, attrs, onSelect }) => {
|
|
112
|
-
const isActive = textEditor.isActive(name, attrs)
|
|
115
|
+
const isActive = textEditor.view ? textEditor.isActive(name, attrs) : false
|
|
113
116
|
return (
|
|
114
117
|
<TldrawUiToolbarButton
|
|
115
118
|
key={name}
|
|
@@ -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
|
|
|
@@ -6,6 +6,7 @@ export interface TLUiButtonProps extends React.HTMLAttributes<HTMLButtonElement>
|
|
|
6
6
|
disabled?: boolean
|
|
7
7
|
isActive?: boolean
|
|
8
8
|
type: 'normal' | 'primary' | 'danger' | 'low' | 'icon' | 'tool' | 'menu' | 'help'
|
|
9
|
+
htmlButtonType?: 'button' | 'submit' | 'reset'
|
|
9
10
|
}
|
|
10
11
|
|
|
11
12
|
const namedClassNamesSoThatICanGrepForThis = {
|
|
@@ -21,11 +22,11 @@ const namedClassNamesSoThatICanGrepForThis = {
|
|
|
21
22
|
|
|
22
23
|
/** @public @react */
|
|
23
24
|
export const TldrawUiButton = React.forwardRef<HTMLButtonElement, TLUiButtonProps>(
|
|
24
|
-
function TldrawUiButton({ children, type, isActive, ...props }, ref) {
|
|
25
|
+
function TldrawUiButton({ children, type, htmlButtonType, isActive, ...props }, ref) {
|
|
25
26
|
return (
|
|
26
27
|
<button
|
|
27
28
|
ref={ref}
|
|
28
|
-
type=
|
|
29
|
+
type={htmlButtonType || 'button'}
|
|
29
30
|
draggable={false}
|
|
30
31
|
data-isactive={isActive}
|
|
31
32
|
{...props}
|
|
@@ -1495,6 +1495,22 @@ export function ActionsProvider({ overrides, children }: ActionsProviderProps) {
|
|
|
1495
1495
|
trackEvent('set-style', { source, id: style.id, value: 'fill' })
|
|
1496
1496
|
},
|
|
1497
1497
|
},
|
|
1498
|
+
{
|
|
1499
|
+
id: 'select-fill-lined-fill',
|
|
1500
|
+
label: 'fill-style.lined-fill',
|
|
1501
|
+
kbd: 'alt+shift+f',
|
|
1502
|
+
onSelect(source) {
|
|
1503
|
+
const style = DefaultFillStyle
|
|
1504
|
+
editor.run(() => {
|
|
1505
|
+
editor.markHistoryStoppingPoint('change-fill')
|
|
1506
|
+
if (editor.isIn('select')) {
|
|
1507
|
+
editor.setStyleForSelectedShapes(style, 'lined-fill')
|
|
1508
|
+
}
|
|
1509
|
+
editor.setStyleForNextShapes(style, 'lined-fill')
|
|
1510
|
+
})
|
|
1511
|
+
trackEvent('set-style', { source, id: style.id, value: 'lined-fill' })
|
|
1512
|
+
},
|
|
1513
|
+
},
|
|
1498
1514
|
{
|
|
1499
1515
|
id: 'flatten-to-image',
|
|
1500
1516
|
label: 'action.flatten-to-image',
|
|
@@ -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
|
})
|