Skip to content

Commit

Permalink
downgrade tldraw
Browse files Browse the repository at this point in the history
  • Loading branch information
gempir committed Apr 14, 2024
1 parent 1060c6c commit 9ef7baf
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
1 change: 1 addition & 0 deletions web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"dependencies": {
"@heroicons/react": "^2.0.12",
"@tailwindcss/forms": "^0.5.7",
"@tldraw/tldraw": "^2.0.0-beta.2",
"@types/seedrandom": "^3.0.4",
"@y-sweet/react": "^0.1.0",
"@y-sweet/sdk": "^0.1.0",
Expand Down
39 changes: 11 additions & 28 deletions web/src/components/Overlay/Editor.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { AssetRecordType, Editor, MediaHelpers, TLAsset, TLAssetId, Tldraw, TldrawProps, getHashForString, isGifAnimated } from 'tldraw';
import 'tldraw/tldraw.css';
import { AssetRecordType, Editor, MediaHelpers, TLAsset, TLAssetId, Tldraw, TldrawProps, getHashForString } from '@tldraw/tldraw';
import '@tldraw/tldraw/tldraw.css';
import { useAssetUploader } from '../../hooks/useAssetUploader';
import { useYjsStore } from '../../hooks/useYjsStore';

Expand All @@ -21,41 +21,24 @@ export function CustomEditor(props: Partial<TldrawProps> & Props) {
} else {
editor.registerExternalAssetHandler('file', async ({ file }: { type: 'file'; file: File }) => {
const uploadedAsset = await upload(file);
//[b]
const assetId: TLAssetId = AssetRecordType.createId(getHashForString(uploadedAsset.url))

let size: {
w: number
h: number
}
let isAnimated: boolean
let shapeType: 'image' | 'video'

//[c]
if (['image/jpeg', 'image/png', 'image/gif', 'image/svg+xml'].includes(file.type)) {
shapeType = 'image'
size = await MediaHelpers.getImageSize(file)
isAnimated = file.type === 'image/gif' && (await isGifAnimated(file))
} else {
shapeType = 'video'
isAnimated = true
size = await MediaHelpers.getVideoSize(file)
}
//[d]
const assetId: TLAssetId = AssetRecordType.createId(getHashForString(uploadedAsset.id))

const size = uploadedAsset.isVideo ? await MediaHelpers.getVideoSizeFromSrc(uploadedAsset.url) : await MediaHelpers.getImageSizeFromSrc(uploadedAsset.url);

const asset: TLAsset = AssetRecordType.create({
id: assetId,
type: shapeType,
type: uploadedAsset.isVideo ? 'video' : 'image',
typeName: 'asset',
props: {
name: file.name,
name: uploadedAsset.id,
src: uploadedAsset.url,
w: size.w,
h: size.h,
mimeType: file.type,
isAnimated,
mimeType: uploadedAsset.mimeType,
isAnimated: uploadedAsset.isAnimated,
},
})

return asset
})
}
Expand Down
2 changes: 1 addition & 1 deletion web/src/hooks/useYjsStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
setUserPreferences,
react,
transact,
} from 'tldraw'
} from '@tldraw/tldraw'
import { useEffect, useMemo, useState } from 'react'
import { YKeyValue } from 'y-utility/y-keyvalue'
import * as Y from 'yjs'
Expand Down
9 changes: 8 additions & 1 deletion web/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,13 @@
lodash.isequal "^4.5.0"
nanoid "4.0.2"

"@tldraw/tldraw@^2.0.0-beta.2":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@tldraw/tldraw/-/tldraw-2.0.2.tgz#b53be55b0a8e727ccaaf0fa171d4b97f7dbdf179"
integrity sha512-34GK/SjYMyvPSrO7D0DR0sg3qi0XtFhyNKS4ls4PNGNa24Ov4Etm3MVEmbOe+stqAi8FC4hlfSDd7eE/vIsU5w==
dependencies:
tldraw "2.0.2"

"@tldraw/[email protected]":
version "2.0.2"
resolved "https://registry.yarnpkg.com/@tldraw/tlschema/-/tlschema-2.0.2.tgz#b4925a9155d74354b0b3608276f3fdf2e78d8b76"
Expand Down Expand Up @@ -3196,7 +3203,7 @@ throttle-debounce@^3.0.1:
resolved "https://registry.yarnpkg.com/throttle-debounce/-/throttle-debounce-3.0.1.tgz#32f94d84dfa894f786c9a1f290e7a645b6a19abb"
integrity sha512-dTEWWNu6JmeVXY0ZYoPuH5cRIwc0MeGbJwah9KUNYSJwommQpCzTySTpEe8Gs1J23aeWEuAobe4Ag7EHVt/LOg==

tldraw@^2.0.2:
tldraw@2.0.2, tldraw@^2.0.2:
version "2.0.2"
resolved "https://registry.yarnpkg.com/tldraw/-/tldraw-2.0.2.tgz#2d4efd6671c363ceec53d1ea57b872fbd90c1f1d"
integrity sha512-qWIbsZkbCVcexGHtUBBjT28+upgzwSu3yImtQXRbfwDj8wbVadxxczAK9Uh6gSsRqlEx8WaQRu3Nkv/3QJSTQQ==
Expand Down

0 comments on commit 9ef7baf

Please sign in to comment.