kopia lustrzana https://github.com/Tldraw/Tldraw
Move to a separate file.
rodzic
10314018aa
commit
4ec9af11d7
|
@ -120,6 +120,14 @@ import { getStraightArrowInfo } from './shapes/shared/arrow/straight-arrow'
|
|||
import { RootState } from './tools/RootState'
|
||||
import { StateNode, TLStateNodeConstructor } from './tools/StateNode'
|
||||
import { TLContent } from './types/clipboard-types'
|
||||
import {
|
||||
CreateShapeError,
|
||||
EditorResult,
|
||||
MAX_SHAPES_REACHED_ERROR_ERROR,
|
||||
NOT_ARRAY_OF_SHAPES_ERROR,
|
||||
NO_SHAPES_PROVIDED_ERROR,
|
||||
READONLY_ROOM_ERROR,
|
||||
} from './types/editor-result-types'
|
||||
import { TLEventMap } from './types/emit-types'
|
||||
import {
|
||||
TLEventInfo,
|
||||
|
@ -129,17 +137,7 @@ import {
|
|||
} from './types/event-types'
|
||||
import { TLExternalAssetContent, TLExternalContent } from './types/external-content'
|
||||
import { TLHistoryBatchOptions } from './types/history-types'
|
||||
import {
|
||||
CreateShapeError,
|
||||
EditorResult,
|
||||
MAX_SHAPES_REACHED_ERROR_ERROR,
|
||||
NOT_ARRAY_OF_SHAPES_ERROR,
|
||||
NO_SHAPES_PROVIDED_ERROR,
|
||||
OptionalKeys,
|
||||
READONLY_ROOM_ERROR,
|
||||
RequiredKeys,
|
||||
TLSvgOptions,
|
||||
} from './types/misc-types'
|
||||
import { OptionalKeys, RequiredKeys, TLSvgOptions } from './types/misc-types'
|
||||
import { TLResizeHandle } from './types/selection-types'
|
||||
|
||||
/** @public */
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
// Result types
|
||||
export type Ok = { readonly ok: true }
|
||||
export type OkWithValue<T> = { readonly ok: true; readonly value: T }
|
||||
export type Error<E> = { readonly ok: false; readonly error: E }
|
||||
|
||||
export type EditorResult<T, E> = Error<E> | Ok | OkWithValue<T>
|
||||
export const EditorResult = {
|
||||
ok(): Ok {
|
||||
return { ok: true }
|
||||
},
|
||||
okWithValue<T>(value: T): OkWithValue<T> {
|
||||
return { ok: true, value }
|
||||
},
|
||||
error<E>(error: E): Error<E> {
|
||||
return { ok: false, error }
|
||||
},
|
||||
}
|
||||
|
||||
// General errors
|
||||
export const READONLY_ROOM_ERROR = { type: 'readonly-room' as const, message: 'Room is readonly' }
|
||||
|
||||
// Create shape errors
|
||||
export const NOT_ARRAY_OF_SHAPES_ERROR = {
|
||||
type: 'not-array' as const,
|
||||
message: 'Expected an array',
|
||||
}
|
||||
export const NO_SHAPES_PROVIDED_ERROR = {
|
||||
type: 'no-shapes-provided' as const,
|
||||
message: 'No shapes provided',
|
||||
}
|
||||
export const MAX_SHAPES_REACHED_ERROR_ERROR = {
|
||||
type: 'max-shapes-reached' as const,
|
||||
message: 'Max shapes reached',
|
||||
}
|
||||
|
||||
export type CreateShapeErrorType =
|
||||
| (typeof READONLY_ROOM_ERROR)['type']
|
||||
| (typeof NOT_ARRAY_OF_SHAPES_ERROR)['type']
|
||||
| (typeof NO_SHAPES_PROVIDED_ERROR)['type']
|
||||
| (typeof MAX_SHAPES_REACHED_ERROR_ERROR)['type']
|
||||
export type CreateShapeError = { type: CreateShapeErrorType; message: string }
|
|
@ -14,44 +14,3 @@ export type TLSvgOptions = {
|
|||
darkMode?: boolean
|
||||
preserveAspectRatio: React.SVGAttributes<SVGSVGElement>['preserveAspectRatio']
|
||||
}
|
||||
|
||||
// General errors
|
||||
export const READONLY_ROOM_ERROR = { type: 'readonly-room' as const, message: 'Room is readonly' }
|
||||
|
||||
// Create shape errors
|
||||
export const NOT_ARRAY_OF_SHAPES_ERROR = {
|
||||
type: 'not-array' as const,
|
||||
message: 'Expected an array',
|
||||
}
|
||||
export const NO_SHAPES_PROVIDED_ERROR = {
|
||||
type: 'no-shapes-provided' as const,
|
||||
message: 'No shapes provided',
|
||||
}
|
||||
export const MAX_SHAPES_REACHED_ERROR_ERROR = {
|
||||
type: 'max-shapes-reached' as const,
|
||||
message: 'Max shapes reached',
|
||||
}
|
||||
|
||||
export type CreateShapeErrorType =
|
||||
| (typeof READONLY_ROOM_ERROR)['type']
|
||||
| (typeof NOT_ARRAY_OF_SHAPES_ERROR)['type']
|
||||
| (typeof NO_SHAPES_PROVIDED_ERROR)['type']
|
||||
| (typeof MAX_SHAPES_REACHED_ERROR_ERROR)['type']
|
||||
export type CreateShapeError = { type: CreateShapeErrorType; message: string }
|
||||
|
||||
export type Ok = { readonly ok: true }
|
||||
export type OkWithValue<T> = { readonly ok: true; readonly value: T }
|
||||
export type Error<E> = { readonly ok: false; readonly error: E }
|
||||
|
||||
export type EditorResult<T, E> = Error<E> | Ok | OkWithValue<T>
|
||||
export const EditorResult = {
|
||||
ok(): Ok {
|
||||
return { ok: true }
|
||||
},
|
||||
okWithValue<T>(value: T): OkWithValue<T> {
|
||||
return { ok: true, value }
|
||||
},
|
||||
error<E>(error: E): Error<E> {
|
||||
return { ok: false, error }
|
||||
},
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue