diff --git a/theatre/studio/src/TheatreStudio.ts b/theatre/studio/src/TheatreStudio.ts index ade43428e..36372728c 100644 --- a/theatre/studio/src/TheatreStudio.ts +++ b/theatre/studio/src/TheatreStudio.ts @@ -19,6 +19,8 @@ import { __experimental_disblePlayPauseKeyboardShortcut, __experimental_enablePlayPauseKeyboardShortcut, } from './UIRoot/useKeyboardShortcuts' +import type TheatreSheetObject from '@theatre/core/sheetObjects/TheatreSheetObject' +import type TheatreSheet from '@theatre/core/sheets/TheatreSheet' export interface ITransactionAPI { /** @@ -60,6 +62,21 @@ export interface ITransactionAPI { * @param pointer - A pointer, like object.props */ unset(pointer: Pointer): void + + /** + * EXPERIMENTAL API - this api may be removed without notice. + * + * Makes Theatre forget about this object. This means all the prop overrides and sequenced props + * will be reset, and the object won't show up in the exported state. + */ + __experimental_forgetObject(object: TheatreSheetObject): void + + /** + * EXPERIMENTAL API - this api may be removed without notice. + * + * Makes Theatre forget about this sheet. + */ + __experimental_forgetSheet(sheet: TheatreSheet): void } /** * @@ -474,8 +491,37 @@ export default class TheatreStudio implements IStudio { } transaction(fn: (api: ITransactionAPI) => void): void { - return getStudio().transaction(({set, unset}) => { - return fn({set, unset}) + return getStudio().transaction(({set, unset, stateEditors}) => { + const __experimental_forgetObject = (object: TheatreSheetObject) => { + if (!isSheetObjectPublicAPI(object)) { + throw new Error( + `object in transactionApi.__experimental_forgetObject(object) must be the return type of sheet.object(...)`, + ) + } + + stateEditors.coreByProject.historic.sheetsById.forgetObject( + object.address, + ) + } + + const __experimental_forgetSheet = (sheet: TheatreSheet) => { + if (!isSheetPublicAPI(sheet)) { + throw new Error( + `sheet in transactionApi.__experimental_forgetSheet(sheet) must be the return type of project.sheet()`, + ) + } + + stateEditors.coreByProject.historic.sheetsById.forgetSheet( + sheet.address, + ) + } + + return fn({ + set, + unset, + __experimental_forgetObject, + __experimental_forgetSheet, + }) }) } diff --git a/theatre/studio/src/store/stateEditors.ts b/theatre/studio/src/store/stateEditors.ts index d14c6b744..528cf6648 100644 --- a/theatre/studio/src/store/stateEditors.ts +++ b/theatre/studio/src/store/stateEditors.ts @@ -622,6 +622,29 @@ namespace stateEditors { return sheetsById[p.sheetId]! } + export function forgetObject( + p: WithoutSheetInstance, + ) { + const sheetState = + drafts().historic.coreByProject[p.projectId].sheetsById[p.sheetId] + if (!sheetState) return + delete sheetState.staticOverrides.byObject[p.objectKey] + + const sequence = sheetState.sequence + if (!sequence) return + delete sequence.tracksByObject[p.objectKey] + } + + export function forgetSheet(p: WithoutSheetInstance) { + const sheetState = + drafts().historic.coreByProject[p.projectId].sheetsById[p.sheetId] + if (sheetState) { + delete drafts().historic.coreByProject[p.projectId].sheetsById[ + p.sheetId + ] + } + } + export namespace sequence { export function _ensure( p: WithoutSheetInstance,