Experimental API for forgetting objects/sheet (#393)
This commit is contained in:
parent
583dd9d022
commit
7c410014e1
2 changed files with 71 additions and 2 deletions
|
@ -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<V>(pointer: Pointer<V>): 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,
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
@ -622,6 +622,29 @@ namespace stateEditors {
|
|||
return sheetsById[p.sheetId]!
|
||||
}
|
||||
|
||||
export function forgetObject(
|
||||
p: WithoutSheetInstance<SheetObjectAddress>,
|
||||
) {
|
||||
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<SheetAddress>) {
|
||||
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<SheetAddress>,
|
||||
|
|
Loading…
Reference in a new issue