2023-12-21 18:04:30 +03:00
|
|
|
import { provideGuiConfig, type GuiConfig } from '@/providers/guiConfig'
|
2023-12-15 13:29:15 +03:00
|
|
|
import { provideWidgetRegistry } from '@/providers/widgetRegistry'
|
|
|
|
import { useGraphStore } from '@/stores/graph'
|
2024-03-25 12:14:41 +03:00
|
|
|
import { GraphDb } from '@/stores/graph/graphDatabase'
|
2023-12-15 13:29:15 +03:00
|
|
|
import { useProjectStore } from '@/stores/project'
|
|
|
|
import { ComputedValueRegistry } from '@/stores/project/computedValueRegistry'
|
2024-02-02 12:22:18 +03:00
|
|
|
import { Ast } from '@/util/ast'
|
2023-12-15 13:29:15 +03:00
|
|
|
import { MockTransport, MockWebSocket } from '@/util/net'
|
|
|
|
import { getActivePinia } from 'pinia'
|
|
|
|
import { ref, type App } from 'vue'
|
|
|
|
import { mockDataHandler, mockLSHandler } from './engine'
|
|
|
|
export * as vue from './vue'
|
|
|
|
|
|
|
|
export function languageServer() {
|
|
|
|
MockTransport.addMock('engine', mockLSHandler)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function dataServer() {
|
|
|
|
MockWebSocket.addMock('data', mockDataHandler)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function guiConfig(app: App) {
|
|
|
|
return provideGuiConfig._mock(
|
2023-12-21 18:04:30 +03:00
|
|
|
ref<GuiConfig>({
|
2023-12-15 13:29:15 +03:00
|
|
|
startup: {
|
|
|
|
project: 'Mock Project',
|
|
|
|
displayedProjectName: 'Mock Project',
|
|
|
|
},
|
2023-12-21 18:04:30 +03:00
|
|
|
engine: {
|
|
|
|
rpcUrl: 'mock://engine',
|
|
|
|
dataUrl: 'mock://data',
|
2024-05-02 09:28:57 +03:00
|
|
|
ydocUrl: '',
|
2023-12-21 18:04:30 +03:00
|
|
|
namespace: 'local',
|
|
|
|
projectManagerUrl: '',
|
|
|
|
},
|
|
|
|
window: {
|
|
|
|
topBarOffset: 96,
|
2024-02-28 16:01:03 +03:00
|
|
|
vibrancy: false,
|
2023-12-21 18:04:30 +03:00
|
|
|
},
|
|
|
|
authentication: {
|
|
|
|
enabled: true,
|
|
|
|
email: '',
|
|
|
|
},
|
2023-12-15 13:29:15 +03:00
|
|
|
}),
|
|
|
|
app,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export const computedValueRegistry = ComputedValueRegistry.Mock
|
|
|
|
export const graphDb = GraphDb.Mock
|
|
|
|
|
|
|
|
export function widgetRegistry(app: App) {
|
|
|
|
return widgetRegistry.withGraphDb(graphDb())(app)
|
|
|
|
}
|
|
|
|
|
|
|
|
widgetRegistry.withGraphDb = function widgetRegistryWithGraphDb(graphDb: GraphDb) {
|
|
|
|
return (app: App) => provideWidgetRegistry._mock([graphDb], app)
|
|
|
|
}
|
|
|
|
|
2024-03-14 20:05:26 +03:00
|
|
|
export function graphStore(): ReturnType<typeof useGraphStore> {
|
2023-12-15 13:29:15 +03:00
|
|
|
return useGraphStore(getActivePinia())
|
|
|
|
}
|
|
|
|
|
2024-03-14 20:05:26 +03:00
|
|
|
export function projectStore(): ReturnType<typeof useProjectStore> {
|
2023-12-15 13:29:15 +03:00
|
|
|
const projectStore = useProjectStore(getActivePinia())
|
|
|
|
const mod = projectStore.projectModel.createNewModule('Main.enso')
|
|
|
|
mod.doc.ydoc.emit('load', [])
|
2024-02-02 12:22:18 +03:00
|
|
|
const syncModule = new Ast.MutableModule(mod.doc.ydoc)
|
2024-02-20 02:57:42 +03:00
|
|
|
syncModule.transact(() => {
|
2024-02-02 12:22:18 +03:00
|
|
|
const root = Ast.parseBlock('main =\n', syncModule)
|
|
|
|
syncModule.replaceRoot(root)
|
|
|
|
})
|
2023-12-15 13:29:15 +03:00
|
|
|
return projectStore
|
|
|
|
}
|
|
|
|
|
|
|
|
/** The stores should be initialized in this order, as `graphStore` depends on `projectStore`. */
|
2024-03-14 20:05:26 +03:00
|
|
|
export function projectStoreAndGraphStore(): readonly [
|
|
|
|
ReturnType<typeof useProjectStore>,
|
|
|
|
ReturnType<typeof useGraphStore>,
|
|
|
|
] {
|
|
|
|
return [projectStore(), graphStore()] as const
|
2023-12-15 13:29:15 +03:00
|
|
|
}
|
|
|
|
|
2024-03-14 20:05:26 +03:00
|
|
|
export function waitForMainModule(projectStore?: ReturnType<typeof useProjectStore>) {
|
2023-12-15 13:29:15 +03:00
|
|
|
const definedProjectStore = projectStore ?? useProjectStore(getActivePinia())
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
const handle1 = window.setInterval(() => {
|
|
|
|
if (definedProjectStore.module != null) {
|
|
|
|
window.clearInterval(handle1)
|
|
|
|
window.clearTimeout(handle2)
|
|
|
|
resolve(definedProjectStore.module)
|
|
|
|
}
|
|
|
|
}, 10)
|
|
|
|
const handle2 = window.setTimeout(() => {
|
|
|
|
window.clearInterval(handle1)
|
|
|
|
reject()
|
|
|
|
}, 5_000)
|
|
|
|
})
|
|
|
|
}
|