diff --git a/tldraw/apps/tldraw-logseq/src/components/PrimaryTools/PrimaryTools.tsx b/tldraw/apps/tldraw-logseq/src/components/PrimaryTools/PrimaryTools.tsx index 4871a98692..e876e1b27e 100644 --- a/tldraw/apps/tldraw-logseq/src/components/PrimaryTools/PrimaryTools.tsx +++ b/tldraw/apps/tldraw-logseq/src/components/PrimaryTools/PrimaryTools.tsx @@ -15,16 +15,15 @@ export const PrimaryTools = observer(function PrimaryTools() { app.api.setColor(color) }, []) - const handleToolClick = React.useCallback( - (e: React.MouseEvent) => { - const tool = e.currentTarget.dataset.tool - if (tool) app.selectTool(tool) - }, - [] - ) + const handleToolClick = React.useCallback((e: React.MouseEvent) => { + const tool = e.currentTarget.dataset.tool + if (tool) app.selectTool(tool) + }, []) const [activeGeomId, setActiveGeomId] = React.useState( - () => (Object.values(Geometry).find((geo: string) => geo === app.selectedTool.id) ?? Object.values(Geometry)[0]) + () => + Object.values(Geometry).find((geo: string) => geo === app.selectedTool.id) ?? + Object.values(Geometry)[0] ) React.useEffect(() => { @@ -33,25 +32,59 @@ export const PrimaryTools = observer(function PrimaryTools() { }) }, [app.selectedTool.id]) - return (
- app.selectTool("select")} tooltip="Select" id="select" icon="select-cursor" /> app.selectTool("move")} + handleClick={() => app.selectTool('select')} + tooltip="Select" + id="select" + icon="select-cursor" + /> + app.selectTool('move')} tooltip="Pan" id="move" icon={app.isIn('move.panning') ? 'hand-grab' : 'hand-stop'} /> - app.selectTool("`logseq-portal")} tooltip="Add block or page" id="logseq-portal" icon="circle-plus" /> - app.selectTool("pencil")} tooltip="Draw" id="pencil" icon="ballpen" /> - app.selectTool("highlighter")} tooltip="Highlight" id="highlighter" icon="highlight" /> - app.selectTool("erase")} tooltip="Eraser" id="erase" icon="eraser" /> - app.selectTool("line")} tooltip="Connector" id="line" icon="connector" /> - app.selectTool("text")} tooltip="Text" id="text" icon="text" /> - + app.selectTool('`logseq-portal')} + tooltip="Add block or page" + id="logseq-portal" + icon="circle-plus" + /> + app.selectTool('pencil')} + tooltip="Draw" + id="pencil" + icon="ballpen" + /> + app.selectTool('highlighter')} + tooltip="Highlight" + id="highlighter" + icon="highlight" + /> + app.selectTool('erase')} + tooltip="Eraser" + id="erase" + icon="eraser" + /> + app.selectTool('line')} + tooltip="Connector" + id="line" + icon="connector" + /> + app.selectTool('text')} + tooltip="Text" + id="text" + icon="text" + /> + ) => void } -export const ToolButton = observer(({ id, icon, tooltip, tooltipSide = "left", handleClick, ...props }: ToolButtonProps) => { - const app = useApp() +export const ToolButton = observer( + ({ id, icon, tooltip, tooltipSide = 'left', handleClick, ...props }: ToolButtonProps) => { + const app = useApp() - // Tool must exist - const Tool = [...app.Tools, TLSelectTool, TLMoveTool]?.find(T => T.id === id) + // Tool must exist + const Tool = [...app.Tools, TLSelectTool, TLMoveTool]?.find(T => T.id === id) - const shortcuts = (Tool as any)?.['shortcut'] + const shortcuts = (Tool as any)?.['shortcut'] - const tooltipContent = shortcuts && tooltip ? ( -
- {tooltip} - -
- ) : ( - tooltip - ) + const tooltipContent = + shortcuts && tooltip ? ( +
+ {tooltip} + +
+ ) : ( + tooltip + ) - return ( - - ) -}) + return ( + + ) + } +) diff --git a/tldraw/apps/tldraw-logseq/src/components/ZoomMenu/ZoomMenu.tsx b/tldraw/apps/tldraw-logseq/src/components/ZoomMenu/ZoomMenu.tsx index ff9b7ab80a..527cabbca7 100644 --- a/tldraw/apps/tldraw-logseq/src/components/ZoomMenu/ZoomMenu.tsx +++ b/tldraw/apps/tldraw-logseq/src/components/ZoomMenu/ZoomMenu.tsx @@ -28,7 +28,7 @@ export const ZoomMenu = observer(function ZoomMenu(): JSX.Element { onClick={app.api.zoomToFit} > Zoom to drawing - + Zoom to fit selection - + Zoom in - + Zoom out - + Reset zoom - + diff --git a/tldraw/packages/core/src/lib/TLApi/TLApi.ts b/tldraw/packages/core/src/lib/TLApi/TLApi.ts index 0c875ac9a4..78ff6d6258 100644 --- a/tldraw/packages/core/src/lib/TLApi/TLApi.ts +++ b/tldraw/packages/core/src/lib/TLApi/TLApi.ts @@ -43,7 +43,9 @@ export class TLApi(...shapes: ({ id: string, type: string } & Partial)[]): this => { + updateShapes = ( + ...shapes: ({ id: string; type: string } & Partial)[] + ): this => { this.app.updateShapes(shapes) return this } @@ -435,8 +437,7 @@ export class TLApi { shapes.forEach(shape => { - if (shape.props.type === 'logseq-portal') - shape.setCollapsed(collapsed) + if (shape.props.type === 'logseq-portal') shape.setCollapsed(collapsed) }) this.app.persist() } diff --git a/tldraw/packages/core/src/lib/TLApp/TLApp.ts b/tldraw/packages/core/src/lib/TLApp/TLApp.ts index baf688b5db..b18251cc75 100644 --- a/tldraw/packages/core/src/lib/TLApp/TLApp.ts +++ b/tldraw/packages/core/src/lib/TLApp/TLApp.ts @@ -17,13 +17,7 @@ import type { TLSubscriptionEventName, } from '../../types' import { AlignType, DistributeType } from '../../types' -import { - BoundsUtils, - createNewLineBinding, - dedupe, - isNonNullable, - uniqueId, -} from '../../utils' +import { BoundsUtils, createNewLineBinding, dedupe, isNonNullable, uniqueId } from '../../utils' import type { TLShape, TLShapeConstructor, TLShapeModel } from '../shapes' import { TLApi } from '../TLApi' import { TLCursors } from '../TLCursors' @@ -194,14 +188,16 @@ export class TLApp< return this } - @action updateShapes = (shapes: ({ id: string, type: string } & Partial)[]): this => { + @action updateShapes = ( + shapes: ({ id: string; type: string } & Partial)[] + ): this => { if (this.readOnly) return this shapes.forEach(shape => { const oldShape = this.getShapeById(shape.id) oldShape?.update(shape) if (shape.type !== oldShape?.type) { - this.api.convertShapes(shape.type , [oldShape]) + this.api.convertShapes(shape.type, [oldShape]) } }) this.persist() diff --git a/tldraw/packages/core/src/types/types.ts b/tldraw/packages/core/src/types/types.ts index 599fcbf426..24d5f99002 100644 --- a/tldraw/packages/core/src/types/types.ts +++ b/tldraw/packages/core/src/types/types.ts @@ -15,9 +15,9 @@ export enum Color { } export enum Geometry { - Box = 'box', - Ellipse = 'ellipse', - Polygon = 'polygon', + Box = 'box', + Ellipse = 'ellipse', + Polygon = 'polygon', } export enum AlignType { diff --git a/tldraw/packages/core/src/utils/index.ts b/tldraw/packages/core/src/utils/index.ts index 3219a7a799..ff4137df66 100644 --- a/tldraw/packages/core/src/utils/index.ts +++ b/tldraw/packages/core/src/utils/index.ts @@ -80,13 +80,14 @@ export function isDarwin(): boolean { return /Mac|iPod|iPhone|iPad/.test(window.navigator.platform) } -export function isDev():boolean { - return window?.logseq?.api?.get_state_from_store?.('ui/developer-mode?') || process.env.NODE_ENV === 'development' +export function isDev(): boolean { + return ( + window?.logseq?.api?.get_state_from_store?.('ui/developer-mode?') || + process.env.NODE_ENV === 'development' + ) } -/** - * Migrated from frontend.util/safari? - */ +/** Migrated from frontend.util/safari? */ export function isSafari(): boolean { const ua = window.navigator.userAgent.toLowerCase() return ua.includes('webkit') && !ua.includes('chrome')