diff --git a/packages/editor/api-report.md b/packages/editor/api-report.md index 3ef011918..118a68af2 100644 --- a/packages/editor/api-report.md +++ b/packages/editor/api-report.md @@ -1051,6 +1051,9 @@ export function getPointerInfo(e: PointerEvent | React.PointerEvent, container: // @public export function getResizedImageDataUrl(dataURLForImage: string, width: number, height: number): Promise; +// @public (undocumented) +export function getRotatedBoxShadow(rotation: number): string; + // @public (undocumented) export function getSplineForLineShape(shape: TLLineShape): NonNullable; @@ -1324,6 +1327,7 @@ export function matchEmbedUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1335,7 +1339,8 @@ export function matchEmbedUrl(url: string): { readonly width: 520; readonly height: 400; readonly doesResize: true; - readonly toEmbedUrl: (url: string) => string | undefined; /** @public */ + readonly canUnmount: false; + readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { readonly type: "codesandbox"; @@ -1346,6 +1351,7 @@ export function matchEmbedUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1355,6 +1361,7 @@ export function matchEmbedUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly isAspectRatioLocked: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; @@ -1365,6 +1372,7 @@ export function matchEmbedUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1374,6 +1382,7 @@ export function matchEmbedUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1383,6 +1392,7 @@ export function matchEmbedUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1394,6 +1404,7 @@ export function matchEmbedUrl(url: string): { readonly minWidth: 460; readonly minHeight: 360; readonly doesResize: true; + readonly canUnmount: false; readonly instructionLink: "https://support.google.com/calendar/answer/41207?hl=en"; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; @@ -1404,6 +1415,7 @@ export function matchEmbedUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1415,6 +1427,7 @@ export function matchEmbedUrl(url: string): { readonly minWidth: 460; readonly minHeight: 360; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1424,6 +1437,7 @@ export function matchEmbedUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly isAspectRatioLocked: false; readonly backgroundColor: "#fff"; readonly toEmbedUrl: (url: string) => string | undefined; @@ -1435,6 +1449,7 @@ export function matchEmbedUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1444,6 +1459,7 @@ export function matchEmbedUrl(url: string): { readonly width: 520; readonly height: 400; readonly doesResize: false; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1455,6 +1471,7 @@ export function matchEmbedUrl(url: string): { readonly minHeight: 500; readonly overrideOutlineRadius: 12; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1464,6 +1481,7 @@ export function matchEmbedUrl(url: string): { readonly width: 640; readonly height: 360; readonly doesResize: true; + readonly canUnmount: false; readonly isAspectRatioLocked: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; @@ -1474,6 +1492,7 @@ export function matchEmbedUrl(url: string): { readonly width: 800; readonly height: 450; readonly doesResize: true; + readonly canUnmount: false; readonly overridePermissions: { readonly 'allow-presentation': true; }; @@ -1496,6 +1515,7 @@ export function matchUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1507,7 +1527,8 @@ export function matchUrl(url: string): { readonly width: 520; readonly height: 400; readonly doesResize: true; - readonly toEmbedUrl: (url: string) => string | undefined; /** @public */ + readonly canUnmount: false; + readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { readonly type: "codesandbox"; @@ -1518,6 +1539,7 @@ export function matchUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1527,6 +1549,7 @@ export function matchUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly isAspectRatioLocked: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; @@ -1537,6 +1560,7 @@ export function matchUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1546,6 +1570,7 @@ export function matchUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1555,6 +1580,7 @@ export function matchUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1566,6 +1592,7 @@ export function matchUrl(url: string): { readonly minWidth: 460; readonly minHeight: 360; readonly doesResize: true; + readonly canUnmount: false; readonly instructionLink: "https://support.google.com/calendar/answer/41207?hl=en"; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; @@ -1576,6 +1603,7 @@ export function matchUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1587,6 +1615,7 @@ export function matchUrl(url: string): { readonly minWidth: 460; readonly minHeight: 360; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1596,6 +1625,7 @@ export function matchUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly isAspectRatioLocked: false; readonly backgroundColor: "#fff"; readonly toEmbedUrl: (url: string) => string | undefined; @@ -1607,6 +1637,7 @@ export function matchUrl(url: string): { readonly width: 720; readonly height: 500; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1616,6 +1647,7 @@ export function matchUrl(url: string): { readonly width: 520; readonly height: 400; readonly doesResize: false; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1627,6 +1659,7 @@ export function matchUrl(url: string): { readonly minHeight: 500; readonly overrideOutlineRadius: 12; readonly doesResize: true; + readonly canUnmount: false; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; } | { @@ -1636,6 +1669,7 @@ export function matchUrl(url: string): { readonly width: 640; readonly height: 360; readonly doesResize: true; + readonly canUnmount: false; readonly isAspectRatioLocked: true; readonly toEmbedUrl: (url: string) => string | undefined; readonly fromEmbedUrl: (url: string) => string | undefined; @@ -1646,6 +1680,7 @@ export function matchUrl(url: string): { readonly width: 800; readonly height: 450; readonly doesResize: true; + readonly canUnmount: false; readonly overridePermissions: { readonly 'allow-presentation': true; }; @@ -1826,24 +1861,6 @@ export type RequiredKeys = Pick & Partial; // @internal (undocumented) export const RICH_TYPES: Record; -// @public (undocumented) -export function rotateBoxShadow(rotation: number, shadows: { - offsetX: number; - offsetY: number; - blur: number; - spread: number; - color: string; -}[]): string; - -// @public (undocumented) -export const ROTATING_SHADOWS: { - offsetX: number; - offsetY: number; - blur: number; - spread: number; - color: string; -}[]; - // @public (undocumented) export const runtime: { openWindow: (url: string, target: string) => void; diff --git a/packages/editor/src/index.ts b/packages/editor/src/index.ts index 782a17b8b..87b20fd44 100644 --- a/packages/editor/src/index.ts +++ b/packages/editor/src/index.ts @@ -78,7 +78,6 @@ export { MULTI_CLICK_DURATION, REMOVE_SYMBOL, RICH_TYPES, - ROTATING_SHADOWS, STYLES, SVG_PADDING, TEXT_PROPS, @@ -226,10 +225,10 @@ export { } from './lib/utils/data' export { debugFlags, featureFlags, type DebugFlag } from './lib/utils/debug-flags' export { + getRotatedBoxShadow, loopToHtmlElement, preventDefault, releasePointerCapture, - rotateBoxShadow, setPointerCapture, truncateStringWithEllipsis, usePrefersReducedMotion, diff --git a/packages/editor/src/lib/constants.ts b/packages/editor/src/lib/constants.ts index 082df50a8..dfef18e5d 100644 --- a/packages/editor/src/lib/constants.ts +++ b/packages/editor/src/lib/constants.ts @@ -100,24 +100,6 @@ export const DEFAULT_BOOKMARK_WIDTH = 300 /** @internal */ export const DEFAULT_BOOKMARK_HEIGHT = 320 -/** @public */ -export const ROTATING_SHADOWS = [ - { - offsetX: 0, - offsetY: 2, - blur: 4, - spread: 0, - color: '#00000029', - }, - { - offsetX: 0, - offsetY: 3, - blur: 6, - spread: 0, - color: '#0000001f', - }, -] - /** @public */ export const GRID_STEPS = [ { min: -1, mid: 0.15, step: 100 }, diff --git a/packages/editor/src/lib/editor/shapes/bookmark/BookmarkShapeUtil.tsx b/packages/editor/src/lib/editor/shapes/bookmark/BookmarkShapeUtil.tsx index ffdcd54b6..04aa33b68 100644 --- a/packages/editor/src/lib/editor/shapes/bookmark/BookmarkShapeUtil.tsx +++ b/packages/editor/src/lib/editor/shapes/bookmark/BookmarkShapeUtil.tsx @@ -2,14 +2,13 @@ import { toDomPrecision } from '@tldraw/primitives' import { AssetRecordType, TLAssetId, TLBookmarkAsset, TLBookmarkShape } from '@tldraw/tlschema' import { debounce, getHashForString } from '@tldraw/utils' import { HTMLContainer } from '../../../components/HTMLContainer' -import { ROTATING_SHADOWS } from '../../../constants' const DEFAULT_BOOKMARK_WIDTH = 300 const DEFAULT_BOOKMARK_HEIGHT = 320 import { isValidUrl } from '../../../utils/data' import { - rotateBoxShadow, + getRotatedBoxShadow, stopEventPropagation, truncateStringWithEllipsis, } from '../../../utils/dom' @@ -50,7 +49,7 @@ export class BookmarkShapeUtil extends BaseBoxShapeUtil {
diff --git a/packages/editor/src/lib/editor/shapes/embed/EmbedShapeUtil.tsx b/packages/editor/src/lib/editor/shapes/embed/EmbedShapeUtil.tsx index 9d8b5914b..20d4b2222 100644 --- a/packages/editor/src/lib/editor/shapes/embed/EmbedShapeUtil.tsx +++ b/packages/editor/src/lib/editor/shapes/embed/EmbedShapeUtil.tsx @@ -10,9 +10,8 @@ import { useMemo } from 'react' import { useValue } from 'signia-react' import { DefaultSpinner } from '../../../components/DefaultSpinner' import { HTMLContainer } from '../../../components/HTMLContainer' -import { ROTATING_SHADOWS } from '../../../constants' import { useIsEditing } from '../../../hooks/useIsEditing' -import { rotateBoxShadow } from '../../../utils/dom' +import { getRotatedBoxShadow } from '../../../utils/dom' import { getEmbedInfo, getEmbedInfoUnsafely } from '../../../utils/embeds' import { BaseBoxShapeUtil } from '../BaseBoxShapeUtil' import { TLOnResizeHandler, TLShapeUtilFlag } from '../ShapeUtil' @@ -29,32 +28,30 @@ const getSandboxPermissions = (permissions: TLEmbedShapePermissions) => { export class EmbedShapeUtil extends BaseBoxShapeUtil { static override type = 'embed' as const - override canUnmount: TLShapeUtilFlag = () => false - override canResize = (shape: TLEmbedShape) => { - const result = getEmbedInfo(shape.props.url) - return !!result?.definition?.doesResize - } - override hideSelectionBoundsBg: TLShapeUtilFlag = (shape) => !this.canResize(shape) override hideSelectionBoundsFg: TLShapeUtilFlag = (shape) => !this.canResize(shape) - override canEdit: TLShapeUtilFlag = () => true + override canUnmount: TLShapeUtilFlag = (shape: TLEmbedShape) => { + return !!getEmbedInfo(shape.props.url)?.definition?.canUnmount + } + override canResize = (shape: TLEmbedShape) => { + return !!getEmbedInfo(shape.props.url)?.definition?.doesResize + } override defaultProps(): TLEmbedShape['props'] { return { w: 300, h: 300, url: '', - doesResize: true, } } - isAspectRatioLocked: TLShapeUtilFlag = (shape) => { + override isAspectRatioLocked: TLShapeUtilFlag = (shape) => { const embedInfo = getEmbedInfo(shape.props.url) return embedInfo?.definition.isAspectRatioLocked ?? false } - onResize: TLOnResizeHandler = (shape, info) => { + override onResize: TLOnResizeHandler = (shape, info) => { const isAspectRatioLocked = this.isAspectRatioLocked(shape) const embedInfo = getEmbedInfo(shape.props.url) let minWidth = embedInfo?.definition.minWidth ?? 200 @@ -75,7 +72,7 @@ export class EmbedShapeUtil extends BaseBoxShapeUtil { return resizeBox(shape, info, { minWidth, minHeight }) } - render(shape: TLEmbedShape) { + override render(shape: TLEmbedShape) { const { w, h, url } = shape.props const isEditing = useIsEditing(shape.id) const embedInfo = useMemo(() => getEmbedInfoUnsafely(url), [url]) @@ -91,6 +88,7 @@ export class EmbedShapeUtil extends BaseBoxShapeUtil { return true } } + return false }, [] @@ -102,19 +100,19 @@ export class EmbedShapeUtil extends BaseBoxShapeUtil { if (embedInfo?.definition.type === 'github_gist') { const idFromGistUrl = embedInfo.url.split('/').pop() - if (idFromGistUrl) { - return ( - - - - ) - } + if (!idFromGistUrl) throw Error('No gist id!') + + return ( + + + + ) } const sandbox = getSandboxPermissions({ @@ -139,7 +137,7 @@ export class EmbedShapeUtil extends BaseBoxShapeUtil { pointerEvents: isInteractive ? 'auto' : 'none', // Fix for safari zIndex: isInteractive ? '' : '-1', - boxShadow: rotateBoxShadow(pageRotation, ROTATING_SHADOWS), + boxShadow: getRotatedBoxShadow(pageRotation), borderRadius: embedInfo?.definition.overrideOutlineRadius ?? 8, background: embedInfo?.definition.backgroundColor, }} @@ -153,7 +151,7 @@ export class EmbedShapeUtil extends BaseBoxShapeUtil { ) } - indicator(shape: TLEmbedShape) { + override indicator(shape: TLEmbedShape) { const embedInfo = useMemo(() => getEmbedInfo(shape.props.url), [shape.props.url]) return ( (null) - - const fileArg = file ? `?file=${file}` : '' - const gistLink = `https://gist.github.com/${id}.js${fileArg}` - return (