Fix: Moved privateAPI() to the core package
This commit is contained in:
parent
47f7da157a
commit
1ba89d76e1
13 changed files with 40 additions and 33 deletions
|
@ -1,8 +1,10 @@
|
|||
import type Studio from '@theatre/studio/Studio'
|
||||
import type {Studio} from '@theatre/studio/Studio'
|
||||
import projectsSingleton from './projects/projectsSingleton'
|
||||
import {privateAPI} from './privateAPIs'
|
||||
|
||||
export type CoreBits = {
|
||||
projectsP: typeof projectsSingleton.atom.pointer.projects
|
||||
privateAPI: typeof privateAPI
|
||||
}
|
||||
|
||||
export default class CoreBundle {
|
||||
|
@ -24,6 +26,7 @@ export default class CoreBundle {
|
|||
this._studio = studio
|
||||
const bits: CoreBits = {
|
||||
projectsP: projectsSingleton.atom.pointer.projects,
|
||||
privateAPI: privateAPI,
|
||||
}
|
||||
|
||||
callback(bits)
|
||||
|
|
|
@ -6,8 +6,6 @@ import type SheetObject from '@theatre/core/sheetObjects/SheetObject'
|
|||
import type {ISheetObject} from '@theatre/core/sheetObjects/TheatreSheetObject'
|
||||
import type Sheet from '@theatre/core/sheets/Sheet'
|
||||
import type {ISheet} from '@theatre/core/sheets/TheatreSheet'
|
||||
import type Studio from '@theatre/studio/Studio'
|
||||
import type {IStudio} from '@theatre/studio/TheatreStudio'
|
||||
import type {$IntentionalAny} from '@theatre/shared/utils/types'
|
||||
|
||||
const publicAPIToPrivateAPIMap = new WeakMap()
|
||||
|
@ -16,7 +14,6 @@ export function privateAPI(pub: IProject): Project
|
|||
export function privateAPI(pub: ISheet): Sheet
|
||||
export function privateAPI(pub: ISheetObject<$IntentionalAny>): SheetObject
|
||||
export function privateAPI(pub: ISequence): Sequence
|
||||
export function privateAPI(pub: IStudio | IStudio['ui']): Studio
|
||||
export function privateAPI(pub: {}): unknown {
|
||||
return publicAPIToPrivateAPIMap.get(pub)
|
||||
}
|
||||
|
@ -28,7 +25,6 @@ export function setPrivateAPI(
|
|||
pub: ISheetObject<$IntentionalAny>,
|
||||
priv: SheetObject,
|
||||
): void
|
||||
export function setPrivateAPI(pub: IStudio | IStudio['ui'], priv: Studio): void
|
||||
export function setPrivateAPI(pub: {}, priv: {}): void {
|
||||
publicAPIToPrivateAPIMap.set(pub, priv)
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
import {privateAPI, setPrivateAPI} from '@theatre/shared/privateAPIs'
|
||||
import {privateAPI, setPrivateAPI} from '@theatre/core/privateAPIs'
|
||||
import Project from '@theatre/core/projects/Project'
|
||||
import type {ISheet} from '@theatre/core/sheets/TheatreSheet'
|
||||
import type {ProjectAddress} from '@theatre/shared/utils/addresses'
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import logger from '@theatre/shared/logger'
|
||||
import {privateAPI, setPrivateAPI} from '@theatre/shared/privateAPIs'
|
||||
import {privateAPI, setPrivateAPI} from '@theatre/core/privateAPIs'
|
||||
import {defer} from '@theatre/shared/utils/defer'
|
||||
import type Sequence from './Sequence'
|
||||
import type {IPlaybackDirection, IPlaybackRange} from './Sequence'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {privateAPI, setPrivateAPI} from '@theatre/shared/privateAPIs'
|
||||
import {privateAPI, setPrivateAPI} from '@theatre/core/privateAPIs'
|
||||
import type {IProject} from '@theatre/core/projects/TheatreProject'
|
||||
import coreTicker from '@theatre/core/coreTicker'
|
||||
import type {ISheet} from '@theatre/core/sheets/TheatreSheet'
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import {privateAPI, setPrivateAPI} from '@theatre/shared/privateAPIs'
|
||||
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'
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* eslint-disable no-restricted-syntax */
|
||||
import '@theatre/studio'
|
||||
import {getProject} from '@theatre/core'
|
||||
import {privateAPI} from '@theatre/shared/privateAPIs'
|
||||
import {privateAPI} from '@theatre/core/privateAPIs'
|
||||
import type {ProjectState_Historic} from '@theatre/core/projects/store/storeTypes'
|
||||
import type {SheetState_Historic} from '@theatre/core/projects/store/types/SheetState_Historic'
|
||||
import * as t from '@theatre/shared/propTypes'
|
||||
|
|
|
@ -160,7 +160,7 @@ function useDerivation<T>(der: IDerivation<T>, debugLabel?: string): T {
|
|||
}, [der])
|
||||
|
||||
useLayoutEffect(() => {
|
||||
return () => {
|
||||
return function onUnmount() {
|
||||
refs.current.unmounted = true
|
||||
removeFromQueue(refs.current.queueItem)
|
||||
}
|
||||
|
|
|
@ -2,7 +2,7 @@ import forEachDeep from '@theatre/shared/utils/forEachDeep'
|
|||
import type {$FixMe} from '@theatre/shared/utils/types'
|
||||
import type {Pointer} from '@theatre/dataverse'
|
||||
import {getPointerParts} from '@theatre/dataverse'
|
||||
import type Studio from './Studio'
|
||||
import type {Studio} from './Studio'
|
||||
import type {CommitOrDiscard} from './StudioStore/StudioStore'
|
||||
import logger from '@theatre/shared/logger'
|
||||
import {isSheetObject} from '@theatre/shared/instanceTypes'
|
||||
|
|
|
@ -13,8 +13,10 @@ import type {IStudio} from './TheatreStudio'
|
|||
import TheatreStudio from './TheatreStudio'
|
||||
import {nanoid} from 'nanoid/non-secure'
|
||||
import type Project from '@theatre/core/projects/Project'
|
||||
import type {CoreBits} from '@theatre/core/CoreBundle'
|
||||
import type {privateAPI} from '@theatre/core/privateAPIs'
|
||||
|
||||
export default class Studio {
|
||||
export class Studio {
|
||||
readonly atomP: Pointer<FullStudioState>
|
||||
readonly ui!: UI
|
||||
readonly publicApi: IStudio
|
||||
|
@ -26,6 +28,7 @@ export default class Studio {
|
|||
this._projectsProxy.pointer
|
||||
|
||||
private readonly _store = new StudioStore()
|
||||
private _corePrivateApi: typeof privateAPI | undefined
|
||||
|
||||
constructor() {
|
||||
this.address = {studioId: nanoid(10)}
|
||||
|
@ -59,7 +62,12 @@ export default class Studio {
|
|||
attachToProjects(projectsD.getValue())
|
||||
}
|
||||
|
||||
setProjectsP(projectsP: Pointer<Record<string, Project>>) {
|
||||
setCoreBits(coreBits: CoreBits) {
|
||||
this._corePrivateApi = coreBits.privateAPI
|
||||
this._setProjectsP(coreBits.projectsP)
|
||||
}
|
||||
|
||||
private _setProjectsP(projectsP: Pointer<Record<string, Project>>) {
|
||||
this._projectsProxy.setPointer(projectsP)
|
||||
}
|
||||
|
||||
|
@ -78,4 +86,8 @@ export default class Studio {
|
|||
__dev_startHistoryFromScratch(newHistoricPart: StudioHistoricState) {
|
||||
return this._store.__dev_startHistoryFromScratch(newHistoricPart)
|
||||
}
|
||||
|
||||
get corePrivateAPI() {
|
||||
return this._corePrivateApi
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import type CoreBundle from '@theatre/core/CoreBundle'
|
||||
import type {CoreBits} from '@theatre/core/CoreBundle'
|
||||
import type Studio from './Studio'
|
||||
import type {Studio} from './Studio'
|
||||
|
||||
export default class StudioBundle {
|
||||
private _coreBundle: undefined | CoreBundle
|
||||
|
@ -22,6 +22,6 @@ export default class StudioBundle {
|
|||
coreBits = bits
|
||||
})
|
||||
|
||||
this._studio.setProjectsP(coreBits.projectsP)
|
||||
this._studio.setCoreBits(coreBits)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,15 +2,15 @@ import type {ISheetObject} from '@theatre/core'
|
|||
import studioTicker from '@theatre/studio/studioTicker'
|
||||
import type {IDerivation, Pointer} from '@theatre/dataverse'
|
||||
import {prism} from '@theatre/dataverse'
|
||||
import {privateAPI, setPrivateAPI} from '@theatre/shared/privateAPIs'
|
||||
import SimpleCache from '@theatre/shared/utils/SimpleCache'
|
||||
import type {VoidFn} from '@theatre/shared/utils/types'
|
||||
import type {IScrub} from '@theatre/studio/Scrub'
|
||||
|
||||
import type Studio from '@theatre/studio/Studio'
|
||||
import type {Studio} from '@theatre/studio/Studio'
|
||||
import {isSheetObjectPublicAPI} from '@theatre/shared/instanceTypes'
|
||||
import {getOutlineSelection} from './selectors'
|
||||
import type SheetObject from '@theatre/core/sheetObjects/SheetObject'
|
||||
import getStudio from './getStudio'
|
||||
|
||||
export interface ITransactionAPI {
|
||||
set<V>(pointer: Pointer<V>, value: V): void
|
||||
|
@ -39,19 +39,19 @@ export interface IStudio {
|
|||
export default class TheatreStudio implements IStudio {
|
||||
readonly ui = {
|
||||
show() {
|
||||
privateAPI(this).ui.show()
|
||||
getStudio().ui.show()
|
||||
},
|
||||
|
||||
hide() {
|
||||
privateAPI(this).ui.hide()
|
||||
getStudio().ui.hide()
|
||||
},
|
||||
|
||||
get showing(): boolean {
|
||||
return privateAPI(this).ui._showing
|
||||
return getStudio().ui._showing
|
||||
},
|
||||
|
||||
restore() {
|
||||
privateAPI(this).ui.restore()
|
||||
getStudio().ui.restore()
|
||||
},
|
||||
}
|
||||
|
||||
|
@ -60,13 +60,10 @@ export default class TheatreStudio implements IStudio {
|
|||
/**
|
||||
* @internal
|
||||
*/
|
||||
constructor(internals: Studio) {
|
||||
setPrivateAPI(this, internals)
|
||||
setPrivateAPI(this.ui, internals)
|
||||
}
|
||||
constructor(internals: Studio) {}
|
||||
|
||||
transaction(fn: (api: ITransactionAPI) => void): void {
|
||||
return privateAPI(this).transaction(({set, unset}) => {
|
||||
return getStudio().transaction(({set, unset}) => {
|
||||
return fn({set, unset})
|
||||
})
|
||||
}
|
||||
|
@ -88,9 +85,9 @@ export default class TheatreStudio implements IStudio {
|
|||
__experimental_setSelection(selection: Array<ISheetObject>): void {
|
||||
const sanitizedSelection = [...selection]
|
||||
.filter((s) => isSheetObjectPublicAPI(s))
|
||||
.map((s) => privateAPI(s))
|
||||
.map((s) => getStudio().corePrivateAPI!(s))
|
||||
|
||||
privateAPI(this).transaction(({stateEditors}) => {
|
||||
getStudio().transaction(({stateEditors}) => {
|
||||
stateEditors.studio.historic.panels.outline.selection.set(
|
||||
sanitizedSelection,
|
||||
)
|
||||
|
@ -106,6 +103,6 @@ export default class TheatreStudio implements IStudio {
|
|||
}
|
||||
|
||||
scrub(): IScrub {
|
||||
return privateAPI(this).scrub()
|
||||
return getStudio().scrub()
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
import {setStudio} from '@theatre/studio/getStudio'
|
||||
import Studio from '@theatre/studio/Studio'
|
||||
import {Studio} from '@theatre/studio/Studio'
|
||||
export type {IScrub} from '@theatre/studio/Scrub'
|
||||
export type {IStudio} from '@theatre/studio/TheatreStudio'
|
||||
import * as globalVariableNames from '@theatre/shared/globalVariableNames'
|
||||
|
@ -8,6 +8,7 @@ import StudioBundle from './StudioBundle'
|
|||
import type CoreBundle from '@theatre/core/CoreBundle'
|
||||
|
||||
const studioPrivateAPI = new Studio()
|
||||
setStudio(studioPrivateAPI)
|
||||
export const studio = studioPrivateAPI.publicApi
|
||||
export default studio
|
||||
|
||||
|
@ -15,8 +16,6 @@ if (process.env.NODE_ENV !== 'test') {
|
|||
studio.ui.show()
|
||||
}
|
||||
|
||||
setStudio(studioPrivateAPI)
|
||||
|
||||
registerStudioBundle()
|
||||
|
||||
function registerStudioBundle() {
|
||||
|
|
Loading…
Reference in a new issue