From 63414b72218e72df4e8231c0a21e724d03a40797 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mitja=20Bezen=C5=A1ek?= Date: Mon, 20 Nov 2023 18:10:47 +0100 Subject: [PATCH 01/30] Add monaco editor and show it on click. --- app/PreviewShape/PreviewShape.tsx | 183 ++++++++++++++++++++++-------- package-lock.json | 36 ++++++ package.json | 1 + 3 files changed, 175 insertions(+), 45 deletions(-) diff --git a/app/PreviewShape/PreviewShape.tsx b/app/PreviewShape/PreviewShape.tsx index a8626607..e2de5367 100644 --- a/app/PreviewShape/PreviewShape.tsx +++ b/app/PreviewShape/PreviewShape.tsx @@ -1,16 +1,20 @@ /* eslint-disable react-hooks/rules-of-hooks */ +import { Editor as MonacoEditor, OnChange } from '@monaco-editor/react' import { - TLBaseShape, BaseBoxShapeUtil, - useIsEditing, + DefaultSpinner, + Editor, HTMLContainer, - toDomPrecision, Icon, - useToasts, - DefaultSpinner, - stopEventPropagation, + TLBaseShape, Vec2d, + stopEventPropagation, + toDomPrecision, + useIsDarkMode, + useIsEditing, + useToasts, } from '@tldraw/tldraw' +import { useCallback, useState } from 'react' export type PreviewShape = TLBaseShape< 'preview', @@ -22,6 +26,74 @@ export type PreviewShape = TLBaseShape< } > +export function ShowResult({ + boxShadow, + editor, + html, + isEditing, + isShowingEditor, + shape, +}: { + boxShadow: string + editor: Editor + html: string + isEditing: boolean + isShowingEditor: boolean + shape: PreviewShape +}) { + const dark = useIsDarkMode() + + const handleOnChange: OnChange = useCallback( + (value, _event) => { + editor.updateShape({ + id: shape.id, + type: shape.type, + props: { + html: value, + }, + }) + }, + [editor, shape.id, shape.type] + ) + + return ( + <> + {isShowingEditor && ( +
+ +
+ )} +