diff --git a/theatre/core/src/propTypes/index.ts b/theatre/core/src/propTypes/index.ts index dfa8c46..d5b220f 100644 --- a/theatre/core/src/propTypes/index.ts +++ b/theatre/core/src/propTypes/index.ts @@ -84,7 +84,6 @@ export const compound = ( label: opts?.label, sanitize: opts?.sanitize, interpolate: opts?.interpolate, - isScalar: false, } } @@ -258,7 +257,6 @@ export const boolean = ( valueType: null as $IntentionalAny, [propTypeSymbol]: 'TheatrePropType', label: opts?.label, - isScalar: false, sanitize(value: unknown) { if (opts?.sanitize) return opts.sanitize(value) return typeof value === 'boolean' ? value : undefined @@ -311,7 +309,6 @@ export const string = ( valueType: null as $IntentionalAny, [propTypeSymbol]: 'TheatrePropType', label: opts?.label, - isScalar: false, sanitize(value: unknown) { if (opts?.sanitize) return opts.sanitize(value) return typeof value === 'string' ? value : undefined @@ -366,7 +363,6 @@ export function stringLiteral( valueType: null as $IntentionalAny, as: opts?.as ?? 'menu', label: opts?.label, - isScalar: false, sanitize(value: unknown) { if (opts?.sanitize) return opts.sanitize(value) return typeof value === 'string' && Object.keys(options).includes(value) @@ -387,7 +383,7 @@ interface IBasePropType { valueType: ValueType [propTypeSymbol]: 'TheatrePropType' label: string | undefined - isScalar: boolean + isScalar?: true sanitize?: Sanitizer interpolate?: Interpolator } diff --git a/theatre/core/src/sheetObjects/SheetObjectTemplate.ts b/theatre/core/src/sheetObjects/SheetObjectTemplate.ts index 10e28e5..92d5cd8 100644 --- a/theatre/core/src/sheetObjects/SheetObjectTemplate.ts +++ b/theatre/core/src/sheetObjects/SheetObjectTemplate.ts @@ -19,15 +19,12 @@ import type { } from '@theatre/shared/utils/types' import type {IDerivation, Pointer} from '@theatre/dataverse' import {Atom, getPointerParts, prism, val} from '@theatre/dataverse' -import get from 'lodash-es/get' import set from 'lodash-es/set' import getPropDefaultsOfSheetObject from './getPropDefaultsOfSheetObject' import SheetObject from './SheetObject' import logger from '@theatre/shared/logger' -import type { - PropTypeConfig, - PropTypeConfig_Compound, -} from '@theatre/core/propTypes' +import type {PropTypeConfig_Compound} from '@theatre/core/propTypes' +import {getPropConfigByPath} from '@theatre/shared/propTypes/utils' export type IPropPathToTrackIdTree = { [key in string]?: SequenceTrackId | IPropPathToTrackIdTree @@ -116,8 +113,6 @@ export default class SheetObjectTemplate { > { return this._cache.get('getArrayOfValidSequenceTracks', () => prism((): Array<{pathToProp: PathToProp; trackId: SequenceTrackId}> => { - const defaults = val(this.getDefaultValues()) - const pointerToSheetState = this.project.pointers.historic.sheetsById[this.address.sheetId] @@ -131,39 +126,19 @@ export default class SheetObjectTemplate { trackId: SequenceTrackId }> = [] - if (trackIdByPropPath) { - for (const [pathToPropInString, trackId] of Object.entries( - trackIdByPropPath, - )) { - let pathToProp - try { - pathToProp = JSON.parse(pathToPropInString) - } catch (e) { - logger.warn( - `property ${JSON.stringify( - pathToPropInString, - )} cannot be parsed. Skipping.`, - ) - continue - } + if (!trackIdByPropPath) return emptyArray as $IntentionalAny - const propConfig = get(this.config.props, pathToProp) as - | PropTypeConfig - | undefined - const defaultValue = get(defaults, pathToProp) + const _entries = Object.entries(trackIdByPropPath) + for (const [pathToPropInString, trackId] of _entries) { + const pathToProp = parsePathToProp(pathToPropInString) + if (!pathToProp) continue - if ( - typeof defaultValue !== 'number' && - (!propConfig?.sanitize || !propConfig.interpolate) - ) { - //@checking defaultValue because tests don't provide prop config, and fail if this is omitted. - continue - } + const propConfig = getPropConfigByPath(this.config, pathToProp) - arrayOfIds.push({pathToProp, trackId: trackId!}) - } - } else { - return emptyArray as $IntentionalAny + if (!propConfig || !propConfig?.sanitize || !propConfig.interpolate) + continue + + arrayOfIds.push({pathToProp, trackId: trackId!}) } if (arrayOfIds.length === 0) { @@ -207,3 +182,19 @@ export default class SheetObjectTemplate { return defaultsAtPath as $FixMe } } + +function parsePathToProp( + pathToPropInString: string, +): undefined | Array { + try { + const pathToProp = JSON.parse(pathToPropInString) + return pathToProp + } catch (e) { + logger.warn( + `property ${JSON.stringify( + pathToPropInString, + )} cannot be parsed. Skipping.`, + ) + return undefined + } +} diff --git a/theatre/shared/src/propTypes/utils.ts b/theatre/shared/src/propTypes/utils.ts index ac7a0e7..8423ce2 100644 --- a/theatre/shared/src/propTypes/utils.ts +++ b/theatre/shared/src/propTypes/utils.ts @@ -1,5 +1,30 @@ -import type {PropTypeConfig} from '@theatre/core/propTypes' +import type { + PropTypeConfig, + PropTypeConfig_Compound, + PropTypeConfig_Enum, +} from '@theatre/core/propTypes' +import type {PathToProp} from '@theatre/shared/utils/addresses' +import type {$IntentionalAny} from '@theatre/shared/utils/types' -export function isPropConfigComposite(c: PropTypeConfig): boolean { +export function isPropConfigComposite( + c: PropTypeConfig, +): c is PropTypeConfig_Compound<{}> | PropTypeConfig_Enum { return c.type === 'compound' || c.type === 'enum' } + +export function getPropConfigByPath( + parentConf: PropTypeConfig | undefined, + path: PathToProp, +): undefined | PropTypeConfig { + if (!parentConf) return undefined + const [key, ...rest] = path + if (typeof key === 'undefined') return parentConf + if (!isPropConfigComposite(parentConf)) return undefined + + const sub = + parentConf.type === 'enum' + ? parentConf.cases[key] + : (parentConf as $IntentionalAny).props[key] + + return getPropConfigByPath(sub, rest) +}