Skip to content

Commit 06e8284

Browse files
committed
fix: excalidraw preview button logic in mobile
Signed-off-by: Innei <[email protected]>
1 parent 2504d2d commit 06e8284

File tree

2 files changed

+17
-41
lines changed

2 files changed

+17
-41
lines changed

next.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const isProd = process.env.NODE_ENV === 'production'
1212
// eslint-disable-next-line import/no-mutable-exports
1313
let nextConfig = {
1414
reactStrictMode: true,
15-
productionBrowserSourceMaps: true,
15+
productionBrowserSourceMaps: false,
1616
output: 'standalone',
1717
assetPrefix: isProd ? env.ASSETPREFIX || undefined : undefined,
1818
compiler: {

src/components/ui/excalidraw/Excalidraw.tsx

+16-40
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,8 @@ import type {
88
ExcalidrawImperativeAPI,
99
} from '@excalidraw/excalidraw/types/types'
1010
import type { Delta } from 'jsondiffpatch'
11-
import type { FC } from 'react'
1211

13-
import {
14-
Excalidraw as Board,
15-
exportToBlob,
16-
exportToSvg,
17-
} from '@excalidraw/excalidraw'
12+
import { Excalidraw as Board, exportToBlob } from '@excalidraw/excalidraw'
1813

1914
import { useIsMobile } from '~/atoms'
2015
import { API_URL } from '~/constants/env'
@@ -203,47 +198,40 @@ const ExcalidrawImpl = forwardRef<InternelExcalidrawRefObject, ExcalidrawProps>(
203198

204199
{viewModeEnabled && showExtendButton && (
205200
<MotionButtonBase
206-
onClick={async () => {
201+
onClick={() => {
207202
if (!excalidrawAPIRef.current) {
208203
toast.error('Excalidraw API not ready')
209204
return
210205
}
211206

212207
const elements = excalidrawAPIRef.current.getSceneElements()
213208
if (isMobile) {
214-
const blob = await exportToBlob({
209+
const win = window.open()
210+
const blob = exportToBlob({
215211
elements,
216212
files: null,
217213
})
218-
219-
window.open(window.URL.createObjectURL(blob))
220-
} else {
221-
const windowRect = {
222-
w: window.innerWidth,
223-
h: window.innerHeight,
224-
}
225-
226-
const $svg = await exportToSvg({
227-
elements,
228-
files: null,
229-
maxWidthOrHeight: Math.min(
230-
windowRect.h * 0.7,
231-
windowRect.w * 0.9,
232-
),
233-
appState: { theme: isDarkMode ? 'dark' : 'light' },
234-
exportPadding: 12,
214+
blob.then((blob) => {
215+
win?.location.replace(URL.createObjectURL(blob))
235216
})
236-
217+
} else {
237218
modal.present({
238219
title: 'Preview',
239-
content: () => <SvgPreview svgElement={$svg} />,
220+
content: () => (
221+
<ExcalidrawImpl
222+
data={data}
223+
className="h-full"
224+
showExtendButton={false}
225+
/>
226+
),
240227
clickOutsideToDismiss: true,
228+
max: true,
241229
})
242230
}
243231
}}
244232
className={clsxm(
245233
'absolute bottom-2 right-2 z-10 box-content flex h-5 w-5 rounded-md border p-2 center',
246-
'border-zinc-200 text-zinc-600',
234+
'border-zinc-200 bg-base-100 text-zinc-600',
247235
'dark:border-neutral-800 dark:text-zinc-500',
248236
)}
249237
>
@@ -255,15 +243,3 @@ const ExcalidrawImpl = forwardRef<InternelExcalidrawRefObject, ExcalidrawProps>(
255243
},
256244
)
257245
ExcalidrawImpl.displayName = 'ExcalidrawImpl'
258-
const SvgPreview: FC<{
259-
svgElement: SVGSVGElement
260-
}> = ({ svgElement }) => {
261-
return (
262-
<div
263-
className="relative w-full overflow-auto [&>svg]:!h-full [&>svg]:!w-full [&>svg]:max-w-full"
264-
dangerouslySetInnerHTML={{
265-
__html: svgElement.outerHTML,
266-
}}
267-
/>
268-
)
269-
}

0 commit comments

Comments
 (0)