Chore: Moved propTypes to @theatre/core

This commit is contained in:
Aria Minaei 2021-07-02 11:44:07 +02:00
parent 64d955c464
commit 4ac12abb58
11 changed files with 12 additions and 12 deletions

View file

@ -6,7 +6,7 @@ import type {
} from '@theatre/core/projects/TheatreProject'
import TheatreProject from '@theatre/core/projects/TheatreProject'
import globals from '@theatre/shared/globals'
import * as types from '@theatre/shared/propTypes'
import * as types from '@theatre/core/propTypes'
import {InvalidArgumentError} from '@theatre/shared/utils/errors'
import {validateName} from '@theatre/shared/utils/sanitizers'
import userReadableTypeOfValue from '@theatre/shared/utils/userReadableTypeOfValue'

View file

@ -0,0 +1,100 @@
import type {$IntentionalAny} from '@theatre/shared/utils/types'
const s = Symbol('TheatrePropType_Basic')
type S = typeof s
interface IBasePropType<ValueType> {
valueType: ValueType
[s]: 'TheatrePropType'
}
export interface PropTypeConfig_Number extends IBasePropType<number> {
type: 'number'
default: number
min?: number
max?: number
step?: number
}
export const number = (
defaultValue: number,
opts?: Pick<PropTypeConfig_Number, 'min' | 'max' | 'step'>,
): PropTypeConfig_Number => {
return {
type: 'number',
valueType: 0,
default: defaultValue,
[s]: 'TheatrePropType',
...(opts ? opts : {}),
}
}
export interface PropTypeConfig_Boolean extends IBasePropType<boolean> {
type: 'boolean'
default: boolean
}
export const boolean = (defaultValue: boolean): PropTypeConfig_Boolean => {
return {
type: 'boolean',
default: defaultValue,
valueType: null as $IntentionalAny,
[s]: 'TheatrePropType',
}
}
export interface PropTypeConfig_String extends IBasePropType<string> {
type: 'string'
default: string
}
export const string = (defaultValue: string): PropTypeConfig_String => {
return {
type: 'string',
default: defaultValue,
valueType: null as $IntentionalAny,
[s]: 'TheatrePropType',
}
}
type IValidSheetountProps = {
[K in string]: PropTypeConfig
}
/**
* @todo Determine if 'compound' is a clear term for what this is.
* I didn't want to use 'object' as it could get confused with
* SheetObject.
*/
export interface PropTypeConfig_Compound<Props extends IValidSheetountProps>
extends IBasePropType<{[K in keyof Props]: Props[K]['valueType']}> {
type: 'compound'
props: Record<string, PropTypeConfig>
}
export const compound = <Props extends IValidSheetountProps>(
props: Props,
): PropTypeConfig_Compound<Props> => {
return {
type: 'compound',
props,
valueType: null as $IntentionalAny,
[s]: 'TheatrePropType',
}
}
export interface PropTypeConfig_Enum extends IBasePropType<{}> {
type: 'enum'
cases: Record<string, PropTypeConfig>
defaultCase: string
}
export type PropTypeConfig_AllPrimitives =
| PropTypeConfig_Number
| PropTypeConfig_Boolean
| PropTypeConfig_String
export type PropTypeConfig =
| PropTypeConfig_AllPrimitives
| PropTypeConfig_Compound<$IntentionalAny>
| PropTypeConfig_Enum

View file

@ -12,7 +12,7 @@ import type {
} from '@theatre/shared/utils/types'
import type {IDerivation, Pointer} from '@theatre/dataverse'
import {prism, val} from '@theatre/dataverse'
import type {PropTypeConfig_Compound} from '@theatre/shared/propTypes'
import type {PropTypeConfig_Compound} from '@theatre/core/propTypes'
import type SheetObject from './SheetObject'
export interface ISheetObject<

View file

@ -9,7 +9,7 @@ import type {
PropTypeConfig,
PropTypeConfig_Compound,
PropTypeConfig_Enum,
} from '@theatre/shared/propTypes'
} from '@theatre/core/propTypes'
const cachedDefaults = new WeakMap<PropTypeConfig, SerializableValue>()

View file

@ -2,7 +2,7 @@ import {privateAPI, setPrivateAPI} from '@theatre/core/privateAPIs'
import type {IProject} from '@theatre/core/projects/TheatreProject'
import type TheatreSequence from '@theatre/core/sequences/TheatreSequence'
import type {ISequence} from '@theatre/core/sequences/TheatreSequence'
import type {PropTypeConfig_Compound} from '@theatre/shared/propTypes'
import type {PropTypeConfig_Compound} from '@theatre/core/propTypes'
import type {ISheetObject} from '@theatre/core/sheetObjects/TheatreSheetObject'
import type Sheet from '@theatre/core/sheets/Sheet'
import type {SheetAddress} from '@theatre/shared/utils/addresses'