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
|
@ -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…
Add table
Add a link
Reference in a new issue