From 4891670f3dec8dd0c9cec1529d780aff214aa367 Mon Sep 17 00:00:00 2001 From: Andreas Tzionis Date: Sun, 5 Nov 2023 21:07:41 +0200 Subject: [PATCH] worked on image dialog --- lib/client/vanilla/editor.tsx | 9 +++ lib/client/vanilla/image.tsx | 147 ++++++++++++++++++++++++++++++++++ 2 files changed, 156 insertions(+) create mode 100644 lib/client/vanilla/image.tsx diff --git a/lib/client/vanilla/editor.tsx b/lib/client/vanilla/editor.tsx index 03a7e88a..126b934a 100644 --- a/lib/client/vanilla/editor.tsx +++ b/lib/client/vanilla/editor.tsx @@ -15,6 +15,7 @@ import ComputerDesktopIcon from '@heroicons/react/24/outline/ComputerDesktopIcon import PencilIcon from '@heroicons/react/24/outline/PencilIcon' import Select from './select' +import ImageDialog from './image' const standaloneServerPort = 12785 @@ -109,6 +110,8 @@ function Editor({ standaloneServer = false }) { const [themeIndex, setThemeIndex] = useState(0) + const [openImage, setOpenImage] = useState(false) + const loadTheme = async (index: number) => { const baseUrl = getBaseUrl(standaloneServer) const url = `${baseUrl}/api/builder/handle?type=theme&name=${themes[index].folder}` @@ -228,6 +231,11 @@ function Editor({ standaloneServer = false }) { } const onCanvasClick = (e: React.MouseEvent) => { + const target = e.target as HTMLElement + if (target.tagName === 'IMG') { + setOpenImage(true) + } + if (isEventOnElement(deleteRef.current! as unknown as HTMLElement, e)) { const clickEvent = new MouseEvent('click', { bubbles: true }) deleteRef.current!.dispatchEvent(clickEvent) @@ -377,6 +385,7 @@ function Editor({ standaloneServer = false }) { )} +
) => void + onChange: Function +} + +const Content: React.FC = ({ url, text, setText, onUpload, onChange }) => { + const input = useRef(null) + + return ( +
+ {!url ? ( +
+
+ + +
+
OR
+
+ setText(e.target.value)} + /> + +
+
+ ) : ( + + )} +
+ ) +} + +interface DialogProps { + open: boolean + setOpen: (open: boolean) => void + standaloneServer: boolean +} + +const Dialog: React.FC = ({ open, setOpen, standaloneServer }) => { + const [url, setUrl] = useState('') + const [text, setText] = useState('') + + const onUpload = async (e: any) => { + e.preventDefault() + + console.log('upload') + } + + const onChange = async () => { + setUrl(text) + } + + return ( + + + + + + Upload Image + + + + +
+ + + { + setOpen(false) + }} + className={cx( + 'inline-flex select-none justify-center rounded-md px-4 py-2 text-sm font-medium', + `bg-blue-600 text-white border border-transparent ${ + url ? 'hover:bg-blue-700' : 'opacity-50 cursor-not-allowed' + }`, + )} + disabled={!url} + > + Save + +
+ + setOpen(false)} + className={cx('absolute top-3.5 right-3.5 inline-flex items-center justify-center rounded-full p-1')} + > + + +
+
+
+
+ ) +} + +export default Dialog