better auto-generated docs for Tldraw and TldrawEditor (#4012)
Simplify the types used by the props of the `Tldraw` and `TldrawEditor` components. This doesn't make the docs perfect, but it makes them quite a bit better than they were.  ### Change Type - [x] `sdk` — Changes the tldraw SDK - [x] `docs` — Changes to the documentation, examples, or templates. - [x] `improvement` — Improving existing features
This commit is contained in:
parent
8ac48877de
commit
4ccac5da96
8 changed files with 147 additions and 108 deletions
|
@ -15,7 +15,6 @@ import { computed } from '@tldraw/state';
|
||||||
import { EmbedDefinition } from '@tldraw/tlschema';
|
import { EmbedDefinition } from '@tldraw/tlschema';
|
||||||
import { EMPTY_ARRAY } from '@tldraw/state';
|
import { EMPTY_ARRAY } from '@tldraw/state';
|
||||||
import EventEmitter from 'eventemitter3';
|
import EventEmitter from 'eventemitter3';
|
||||||
import { Expand } from '@tldraw/utils';
|
|
||||||
import { HistoryEntry } from '@tldraw/store';
|
import { HistoryEntry } from '@tldraw/store';
|
||||||
import { IndexKey } from '@tldraw/utils';
|
import { IndexKey } from '@tldraw/utils';
|
||||||
import { JsonObject } from '@tldraw/utils';
|
import { JsonObject } from '@tldraw/utils';
|
||||||
|
@ -67,7 +66,6 @@ import { TLParentId } from '@tldraw/tlschema';
|
||||||
import { TLPropsMigrations } from '@tldraw/tlschema';
|
import { TLPropsMigrations } from '@tldraw/tlschema';
|
||||||
import { TLRecord } from '@tldraw/tlschema';
|
import { TLRecord } from '@tldraw/tlschema';
|
||||||
import { TLScribble } from '@tldraw/tlschema';
|
import { TLScribble } from '@tldraw/tlschema';
|
||||||
import { TLSerializedStore } from '@tldraw/tlschema';
|
|
||||||
import { TLShape } from '@tldraw/tlschema';
|
import { TLShape } from '@tldraw/tlschema';
|
||||||
import { TLShapeId } from '@tldraw/tlschema';
|
import { TLShapeId } from '@tldraw/tlschema';
|
||||||
import { TLShapePartial } from '@tldraw/tlschema';
|
import { TLShapePartial } from '@tldraw/tlschema';
|
||||||
|
@ -2539,17 +2537,26 @@ export interface TldrawEditorBaseProps {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @public
|
// @public
|
||||||
export type TldrawEditorProps = Expand<TldrawEditorBaseProps & ({
|
export type TldrawEditorProps = TldrawEditorBaseProps & TldrawEditorStoreProps;
|
||||||
defaultName?: string;
|
|
||||||
initialData?: TLSerializedStore;
|
// @public (undocumented)
|
||||||
|
export type TldrawEditorStoreProps = TldrawEditorWithoutStoreProps | TldrawEditorWithStoreProps;
|
||||||
|
|
||||||
|
// @public
|
||||||
|
export interface TldrawEditorWithoutStoreProps extends TLStoreBaseOptions {
|
||||||
migrations?: readonly MigrationSequence[];
|
migrations?: readonly MigrationSequence[];
|
||||||
persistenceKey?: string;
|
persistenceKey?: string;
|
||||||
|
// (undocumented)
|
||||||
sessionId?: string;
|
sessionId?: string;
|
||||||
snapshot?: TLEditorSnapshot | TLStoreSnapshot;
|
snapshot?: TLEditorSnapshot | TLStoreSnapshot;
|
||||||
|
// (undocumented)
|
||||||
store?: undefined;
|
store?: undefined;
|
||||||
} | {
|
}
|
||||||
|
|
||||||
|
// @public
|
||||||
|
export interface TldrawEditorWithStoreProps {
|
||||||
store: TLStore | TLStoreWithStatus;
|
store: TLStore | TLStoreWithStatus;
|
||||||
})>;
|
}
|
||||||
|
|
||||||
// @public
|
// @public
|
||||||
export interface TldrawOptions {
|
export interface TldrawOptions {
|
||||||
|
@ -3256,19 +3263,23 @@ export interface TLStateNodeConstructor {
|
||||||
initial?: string;
|
initial?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// @public (undocumented)
|
||||||
|
export interface TLStoreBaseOptions {
|
||||||
|
defaultName?: string;
|
||||||
|
initialData?: SerializedStore<TLRecord>;
|
||||||
|
}
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export type TLStoreEventInfo = HistoryEntry<TLRecord>;
|
export type TLStoreEventInfo = HistoryEntry<TLRecord>;
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export type TLStoreOptions = {
|
export type TLStoreOptions = TLStoreBaseOptions & ({
|
||||||
defaultName?: string;
|
|
||||||
id?: string;
|
|
||||||
initialData?: SerializedStore<TLRecord>;
|
|
||||||
} & ({
|
|
||||||
bindingUtils?: readonly TLAnyBindingUtilConstructor[];
|
bindingUtils?: readonly TLAnyBindingUtilConstructor[];
|
||||||
|
id?: string;
|
||||||
migrations?: readonly MigrationSequence[];
|
migrations?: readonly MigrationSequence[];
|
||||||
shapeUtils?: readonly TLAnyShapeUtilConstructor[];
|
shapeUtils?: readonly TLAnyShapeUtilConstructor[];
|
||||||
} | {
|
} | {
|
||||||
|
id?: string;
|
||||||
schema?: StoreSchema<TLRecord, TLStoreProps>;
|
schema?: StoreSchema<TLRecord, TLStoreProps>;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -40,6 +40,9 @@ export {
|
||||||
type TLOnMountHandler,
|
type TLOnMountHandler,
|
||||||
type TldrawEditorBaseProps,
|
type TldrawEditorBaseProps,
|
||||||
type TldrawEditorProps,
|
type TldrawEditorProps,
|
||||||
|
type TldrawEditorStoreProps,
|
||||||
|
type TldrawEditorWithStoreProps,
|
||||||
|
type TldrawEditorWithoutStoreProps,
|
||||||
} from './lib/TldrawEditor'
|
} from './lib/TldrawEditor'
|
||||||
export {
|
export {
|
||||||
ErrorBoundary,
|
ErrorBoundary,
|
||||||
|
@ -117,6 +120,7 @@ export {
|
||||||
} from './lib/config/TLUserPreferences'
|
} from './lib/config/TLUserPreferences'
|
||||||
export {
|
export {
|
||||||
createTLStore,
|
createTLStore,
|
||||||
|
type TLStoreBaseOptions,
|
||||||
type TLStoreEventInfo,
|
type TLStoreEventInfo,
|
||||||
type TLStoreOptions,
|
type TLStoreOptions,
|
||||||
} from './lib/config/createTLStore'
|
} from './lib/config/createTLStore'
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import { MigrationSequence, Store } from '@tldraw/store'
|
import { MigrationSequence, Store } from '@tldraw/store'
|
||||||
import { TLSerializedStore, TLStore, TLStoreSnapshot } from '@tldraw/tlschema'
|
import { TLStore, TLStoreSnapshot } from '@tldraw/tlschema'
|
||||||
import { Expand, Required, annotateError } from '@tldraw/utils'
|
import { Required, annotateError } from '@tldraw/utils'
|
||||||
import React, {
|
import React, {
|
||||||
ReactNode,
|
ReactNode,
|
||||||
memo,
|
memo,
|
||||||
|
@ -16,6 +16,7 @@ import classNames from 'classnames'
|
||||||
import { OptionalErrorBoundary } from './components/ErrorBoundary'
|
import { OptionalErrorBoundary } from './components/ErrorBoundary'
|
||||||
import { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'
|
import { DefaultErrorFallback } from './components/default-components/DefaultErrorFallback'
|
||||||
import { TLEditorSnapshot } from './config/TLEditorSnapshot'
|
import { TLEditorSnapshot } from './config/TLEditorSnapshot'
|
||||||
|
import { TLStoreBaseOptions } from './config/createTLStore'
|
||||||
import { TLUser, createTLUser } from './config/createTLUser'
|
import { TLUser, createTLUser } from './config/createTLUser'
|
||||||
import { TLAnyBindingUtilConstructor } from './config/defaultBindings'
|
import { TLAnyBindingUtilConstructor } from './config/defaultBindings'
|
||||||
import { TLAnyShapeUtilConstructor } from './config/defaultShapes'
|
import { TLAnyShapeUtilConstructor } from './config/defaultShapes'
|
||||||
|
@ -39,28 +40,59 @@ import { TldrawOptions } from './options'
|
||||||
import { stopEventPropagation } from './utils/dom'
|
import { stopEventPropagation } from './utils/dom'
|
||||||
import { TLStoreWithStatus } from './utils/sync/StoreWithStatus'
|
import { TLStoreWithStatus } from './utils/sync/StoreWithStatus'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when passing in a
|
||||||
|
* {@link store#TLStore} directly. If you would like tldraw to create a store for you, use
|
||||||
|
* {@link TldrawEditorWithoutStoreProps}.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface TldrawEditorWithStoreProps {
|
||||||
|
/**
|
||||||
|
* The store to use in the editor.
|
||||||
|
*/
|
||||||
|
store: TLStore | TLStoreWithStatus
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components, when not passing in a
|
||||||
|
* {@link store#TLStore} directly. If you would like to pass in a store directly, use
|
||||||
|
* {@link TldrawEditorWithStoreProps}.
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface TldrawEditorWithoutStoreProps extends TLStoreBaseOptions {
|
||||||
|
store?: undefined
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Additional migrations to use in the store
|
||||||
|
*/
|
||||||
|
migrations?: readonly MigrationSequence[]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A starting snapshot of data to pre-populate the store. Do not supply both this and
|
||||||
|
* `initialData`.
|
||||||
|
*/
|
||||||
|
snapshot?: TLEditorSnapshot | TLStoreSnapshot
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If you would like to persist the store to the browser's local IndexedDB storage and sync it
|
||||||
|
* across tabs, provide a key here. Each key represents a single tldraw document.
|
||||||
|
*/
|
||||||
|
persistenceKey?: string
|
||||||
|
|
||||||
|
sessionId?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @public */
|
||||||
|
export type TldrawEditorStoreProps = TldrawEditorWithStoreProps | TldrawEditorWithoutStoreProps
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.
|
* Props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.
|
||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
**/
|
**/
|
||||||
export type TldrawEditorProps = Expand<
|
export type TldrawEditorProps = TldrawEditorBaseProps & TldrawEditorStoreProps
|
||||||
TldrawEditorBaseProps &
|
|
||||||
(
|
|
||||||
| {
|
|
||||||
store: TLStore | TLStoreWithStatus
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
store?: undefined
|
|
||||||
migrations?: readonly MigrationSequence[]
|
|
||||||
snapshot?: TLEditorSnapshot | TLStoreSnapshot
|
|
||||||
initialData?: TLSerializedStore
|
|
||||||
persistenceKey?: string
|
|
||||||
sessionId?: string
|
|
||||||
defaultName?: string
|
|
||||||
}
|
|
||||||
)
|
|
||||||
>
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.
|
* Base props for the {@link tldraw#Tldraw} and {@link TldrawEditor} components.
|
||||||
|
|
|
@ -4,18 +4,28 @@ import { TLAnyBindingUtilConstructor, checkBindings } from './defaultBindings'
|
||||||
import { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from './defaultShapes'
|
import { TLAnyShapeUtilConstructor, checkShapesAndAddCore } from './defaultShapes'
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export type TLStoreOptions = {
|
export interface TLStoreBaseOptions {
|
||||||
|
/** The initial data for the store. */
|
||||||
initialData?: SerializedStore<TLRecord>
|
initialData?: SerializedStore<TLRecord>
|
||||||
|
|
||||||
|
/** The default name for the store. */
|
||||||
defaultName?: string
|
defaultName?: string
|
||||||
id?: string
|
}
|
||||||
} & (
|
|
||||||
| {
|
/** @public */
|
||||||
shapeUtils?: readonly TLAnyShapeUtilConstructor[]
|
export type TLStoreOptions = TLStoreBaseOptions &
|
||||||
migrations?: readonly MigrationSequence[]
|
(
|
||||||
bindingUtils?: readonly TLAnyBindingUtilConstructor[]
|
| {
|
||||||
}
|
id?: string
|
||||||
| { schema?: StoreSchema<TLRecord, TLStoreProps> }
|
shapeUtils?: readonly TLAnyShapeUtilConstructor[]
|
||||||
)
|
migrations?: readonly MigrationSequence[]
|
||||||
|
bindingUtils?: readonly TLAnyBindingUtilConstructor[]
|
||||||
|
}
|
||||||
|
| {
|
||||||
|
id?: string
|
||||||
|
schema?: StoreSchema<TLRecord, TLStoreProps>
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export type TLStoreEventInfo = HistoryEntry<TLRecord>
|
export type TLStoreEventInfo = HistoryEntry<TLRecord>
|
||||||
|
|
|
@ -23,7 +23,6 @@ import { Editor } from '@tldraw/editor';
|
||||||
import { EMBED_DEFINITIONS } from '@tldraw/editor';
|
import { EMBED_DEFINITIONS } from '@tldraw/editor';
|
||||||
import { EmbedDefinition } from '@tldraw/editor';
|
import { EmbedDefinition } from '@tldraw/editor';
|
||||||
import { EnumStyleProp } from '@tldraw/editor';
|
import { EnumStyleProp } from '@tldraw/editor';
|
||||||
import { Expand } from '@tldraw/editor';
|
|
||||||
import { Geometry2d } from '@tldraw/editor';
|
import { Geometry2d } from '@tldraw/editor';
|
||||||
import { Group2d } from '@tldraw/editor';
|
import { Group2d } from '@tldraw/editor';
|
||||||
import { HandleSnapGeometry } from '@tldraw/editor';
|
import { HandleSnapGeometry } from '@tldraw/editor';
|
||||||
|
@ -71,6 +70,7 @@ import { TLDefaultHorizontalAlignStyle } from '@tldraw/editor';
|
||||||
import { TLDefaultSizeStyle } from '@tldraw/editor';
|
import { TLDefaultSizeStyle } from '@tldraw/editor';
|
||||||
import { TLDefaultVerticalAlignStyle } from '@tldraw/editor';
|
import { TLDefaultVerticalAlignStyle } from '@tldraw/editor';
|
||||||
import { TldrawEditorBaseProps } from '@tldraw/editor';
|
import { TldrawEditorBaseProps } from '@tldraw/editor';
|
||||||
|
import { TldrawEditorStoreProps } from '@tldraw/editor';
|
||||||
import { TLDrawShape } from '@tldraw/editor';
|
import { TLDrawShape } from '@tldraw/editor';
|
||||||
import { TLDrawShapeSegment } from '@tldraw/editor';
|
import { TLDrawShapeSegment } from '@tldraw/editor';
|
||||||
import { TLEditorComponents } from '@tldraw/editor';
|
import { TLEditorComponents } from '@tldraw/editor';
|
||||||
|
@ -110,7 +110,6 @@ import { TLShapeUtilFlag } from '@tldraw/editor';
|
||||||
import { TLStateNodeConstructor } from '@tldraw/editor';
|
import { TLStateNodeConstructor } from '@tldraw/editor';
|
||||||
import { TLStore } from '@tldraw/editor';
|
import { TLStore } from '@tldraw/editor';
|
||||||
import { TLStoreSnapshot } from '@tldraw/editor';
|
import { TLStoreSnapshot } from '@tldraw/editor';
|
||||||
import { TLStoreWithStatus } from '@tldraw/editor';
|
|
||||||
import { TLSvgOptions } from '@tldraw/editor';
|
import { TLSvgOptions } from '@tldraw/editor';
|
||||||
import { TLTextShape } from '@tldraw/editor';
|
import { TLTextShape } from '@tldraw/editor';
|
||||||
import { TLVideoShape } from '@tldraw/editor';
|
import { TLVideoShape } from '@tldraw/editor';
|
||||||
|
@ -1614,7 +1613,8 @@ export interface TLArrowPoint {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export type TLComponents = Expand<TLEditorComponents & TLUiComponents>;
|
export interface TLComponents extends TLEditorComponents, TLUiComponents {
|
||||||
|
}
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export type TLCopyType = 'jpeg' | 'json' | 'png' | 'svg';
|
export type TLCopyType = 'jpeg' | 'json' | 'png' | 'svg';
|
||||||
|
@ -1625,6 +1625,12 @@ export function Tldraw(props: TldrawProps): JSX_2.Element;
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export const TLDRAW_FILE_EXTENSION: ".tldr";
|
export const TLDRAW_FILE_EXTENSION: ".tldr";
|
||||||
|
|
||||||
|
// @public (undocumented)
|
||||||
|
export interface TldrawBaseProps extends TldrawUiProps, TldrawEditorBaseProps, TLExternalContentProps {
|
||||||
|
// (undocumented)
|
||||||
|
components?: TLComponents;
|
||||||
|
}
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export interface TldrawFile {
|
export interface TldrawFile {
|
||||||
// (undocumented)
|
// (undocumented)
|
||||||
|
@ -1669,18 +1675,7 @@ export interface TldrawImageProps extends TLSvgOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export type TldrawProps = Expand<(Omit<TldrawUiProps, 'components'> & Omit<TldrawEditorBaseProps, 'components'> & {
|
export type TldrawProps = TldrawBaseProps & TldrawEditorStoreProps;
|
||||||
components?: TLComponents;
|
|
||||||
}) & Partial<TLExternalContentProps> & ({
|
|
||||||
snapshot?: TLEditorSnapshot | TLStoreSnapshot;
|
|
||||||
defaultName?: string;
|
|
||||||
migrations?: readonly MigrationSequence[];
|
|
||||||
persistenceKey?: string;
|
|
||||||
sessionId?: string;
|
|
||||||
store?: undefined;
|
|
||||||
} | {
|
|
||||||
store: TLStore | TLStoreWithStatus;
|
|
||||||
})>;
|
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export function TldrawScribble({ scribble, zoom, color, opacity, className }: TLScribbleProps): JSX_2.Element | null;
|
export function TldrawScribble({ scribble, zoom, color, opacity, className }: TLScribbleProps): JSX_2.Element | null;
|
||||||
|
@ -1838,14 +1833,10 @@ export type TLExportType = 'jpeg' | 'json' | 'png' | 'svg' | 'webp';
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
export interface TLExternalContentProps {
|
export interface TLExternalContentProps {
|
||||||
// (undocumented)
|
acceptedImageMimeTypes?: readonly string[];
|
||||||
acceptedImageMimeTypes: readonly string[];
|
acceptedVideoMimeTypes?: readonly string[];
|
||||||
// (undocumented)
|
maxAssetSize?: number;
|
||||||
acceptedVideoMimeTypes: readonly string[];
|
maxImageDimension?: number;
|
||||||
// (undocumented)
|
|
||||||
maxAssetSize: number;
|
|
||||||
// (undocumented)
|
|
||||||
maxImageDimension: number;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// @public (undocumented)
|
// @public (undocumented)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// eslint-disable-next-line local/no-export-star
|
// eslint-disable-next-line local/no-export-star
|
||||||
export * from '@tldraw/editor'
|
export * from '@tldraw/editor'
|
||||||
export { getAssetFromIndexedDb, storeAssetInIndexedDb } from './lib/AssetBlobStore'
|
export { getAssetFromIndexedDb, storeAssetInIndexedDb } from './lib/AssetBlobStore'
|
||||||
export { Tldraw, type TLComponents, type TldrawProps } from './lib/Tldraw'
|
export { Tldraw, type TLComponents, type TldrawBaseProps, type TldrawProps } from './lib/Tldraw'
|
||||||
export { TldrawImage, type TldrawImageProps } from './lib/TldrawImage'
|
export { TldrawImage, type TldrawImageProps } from './lib/TldrawImage'
|
||||||
export { ArrowBindingUtil } from './lib/bindings/arrow/ArrowBindingUtil'
|
export { ArrowBindingUtil } from './lib/bindings/arrow/ArrowBindingUtil'
|
||||||
export { TldrawHandles } from './lib/canvas/TldrawHandles'
|
export { TldrawHandles } from './lib/canvas/TldrawHandles'
|
||||||
|
|
|
@ -4,17 +4,12 @@ import {
|
||||||
DefaultSpinner,
|
DefaultSpinner,
|
||||||
Editor,
|
Editor,
|
||||||
ErrorScreen,
|
ErrorScreen,
|
||||||
Expand,
|
|
||||||
LoadingScreen,
|
LoadingScreen,
|
||||||
MigrationSequence,
|
|
||||||
TLEditorComponents,
|
TLEditorComponents,
|
||||||
TLEditorSnapshot,
|
|
||||||
TLOnMountHandler,
|
TLOnMountHandler,
|
||||||
TLStore,
|
|
||||||
TLStoreSnapshot,
|
|
||||||
TLStoreWithStatus,
|
|
||||||
TldrawEditor,
|
TldrawEditor,
|
||||||
TldrawEditorBaseProps,
|
TldrawEditorBaseProps,
|
||||||
|
TldrawEditorStoreProps,
|
||||||
useEditor,
|
useEditor,
|
||||||
useEditorComponents,
|
useEditorComponents,
|
||||||
useEvent,
|
useEvent,
|
||||||
|
@ -43,35 +38,19 @@ import { usePreloadAssets } from './ui/hooks/usePreloadAssets'
|
||||||
import { useTranslation } from './ui/hooks/useTranslation/useTranslation'
|
import { useTranslation } from './ui/hooks/useTranslation/useTranslation'
|
||||||
import { useDefaultEditorAssetsWithOverrides } from './utils/static-assets/assetUrls'
|
import { useDefaultEditorAssetsWithOverrides } from './utils/static-assets/assetUrls'
|
||||||
|
|
||||||
/**@public */
|
/** @public */
|
||||||
export type TLComponents = Expand<TLEditorComponents & TLUiComponents>
|
export interface TLComponents extends TLEditorComponents, TLUiComponents {}
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export type TldrawProps = Expand<
|
export interface TldrawBaseProps
|
||||||
// combine components from base editor and ui
|
extends TldrawUiProps,
|
||||||
(Omit<TldrawUiProps, 'components'> &
|
TldrawEditorBaseProps,
|
||||||
Omit<TldrawEditorBaseProps, 'components'> & {
|
TLExternalContentProps {
|
||||||
components?: TLComponents
|
components?: TLComponents
|
||||||
}) &
|
}
|
||||||
// external content
|
|
||||||
Partial<TLExternalContentProps> &
|
/** @public */
|
||||||
// store stuff
|
export type TldrawProps = TldrawBaseProps & TldrawEditorStoreProps
|
||||||
(| {
|
|
||||||
store: TLStore | TLStoreWithStatus
|
|
||||||
}
|
|
||||||
| {
|
|
||||||
store?: undefined
|
|
||||||
migrations?: readonly MigrationSequence[]
|
|
||||||
persistenceKey?: string
|
|
||||||
sessionId?: string
|
|
||||||
defaultName?: string
|
|
||||||
/**
|
|
||||||
* A snapshot to load for the store's initial data / schema.
|
|
||||||
*/
|
|
||||||
snapshot?: TLEditorSnapshot | TLStoreSnapshot
|
|
||||||
}
|
|
||||||
)
|
|
||||||
>
|
|
||||||
|
|
||||||
/** @public @react */
|
/** @public @react */
|
||||||
export function Tldraw(props: TldrawProps) {
|
export function Tldraw(props: TldrawProps) {
|
||||||
|
@ -171,7 +150,7 @@ function InsideOfEditorAndUiContext({
|
||||||
acceptedVideoMimeTypes = DEFAULT_SUPPORT_VIDEO_TYPES,
|
acceptedVideoMimeTypes = DEFAULT_SUPPORT_VIDEO_TYPES,
|
||||||
onMount,
|
onMount,
|
||||||
persistenceKey,
|
persistenceKey,
|
||||||
}: Partial<TLExternalContentProps & { onMount: TLOnMountHandler; persistenceKey?: string }>) {
|
}: TLExternalContentProps & { onMount?: TLOnMountHandler; persistenceKey?: string }) {
|
||||||
const editor = useEditor()
|
const editor = useEditor()
|
||||||
const toasts = useToasts()
|
const toasts = useToasts()
|
||||||
const msg = useTranslation()
|
const msg = useTranslation()
|
||||||
|
|
|
@ -31,14 +31,26 @@ import { cleanupText, isRightToLeftLanguage } from './utils/text/text'
|
||||||
|
|
||||||
/** @public */
|
/** @public */
|
||||||
export interface TLExternalContentProps {
|
export interface TLExternalContentProps {
|
||||||
// The maximum dimension (width or height) of an image. Images larger than this will be rescaled to fit. Defaults to infinity.
|
/**
|
||||||
maxImageDimension: number
|
* The maximum dimension (width or height) of an image. Images larger than this will be rescaled
|
||||||
// The maximum size (in bytes) of an asset. Assets larger than this will be rejected. Defaults to 10mb (10 * 1024 * 1024).
|
* to fit. Defaults to infinity.
|
||||||
maxAssetSize: number
|
*/
|
||||||
// The mime types of images that are allowed to be handled. Defaults to DEFAULT_SUPPORTED_IMAGE_TYPES.
|
maxImageDimension?: number
|
||||||
acceptedImageMimeTypes: readonly string[]
|
/**
|
||||||
// The mime types of videos that are allowed to be handled. Defaults to DEFAULT_SUPPORT_VIDEO_TYPES.
|
* The maximum size (in bytes) of an asset. Assets larger than this will be rejected. Defaults
|
||||||
acceptedVideoMimeTypes: readonly string[]
|
* to 10mb (10 * 1024 * 1024).
|
||||||
|
*/
|
||||||
|
maxAssetSize?: number
|
||||||
|
/**
|
||||||
|
* The mime types of images that are allowed to be handled. Defaults to
|
||||||
|
* DEFAULT_SUPPORTED_IMAGE_TYPES.
|
||||||
|
*/
|
||||||
|
acceptedImageMimeTypes?: readonly string[]
|
||||||
|
/**
|
||||||
|
* The mime types of videos that are allowed to be handled. Defaults to
|
||||||
|
* DEFAULT_SUPPORT_VIDEO_TYPES.
|
||||||
|
*/
|
||||||
|
acceptedVideoMimeTypes?: readonly string[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export function registerDefaultExternalContentHandlers(
|
export function registerDefaultExternalContentHandlers(
|
||||||
|
@ -48,7 +60,7 @@ export function registerDefaultExternalContentHandlers(
|
||||||
maxAssetSize,
|
maxAssetSize,
|
||||||
acceptedImageMimeTypes,
|
acceptedImageMimeTypes,
|
||||||
acceptedVideoMimeTypes,
|
acceptedVideoMimeTypes,
|
||||||
}: TLExternalContentProps,
|
}: Required<TLExternalContentProps>,
|
||||||
{ toasts, msg }: { toasts: TLUiToastsContextType; msg: ReturnType<typeof useTranslation> },
|
{ toasts, msg }: { toasts: TLUiToastsContextType; msg: ReturnType<typeof useTranslation> },
|
||||||
persistenceKey?: string
|
persistenceKey?: string
|
||||||
) {
|
) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue