2023-10-29 22:02:07 +03:00
|
|
|
import '@/assets/base.css'
|
|
|
|
import { provideGuiConfig } from '@/providers/guiConfig'
|
|
|
|
import { provideVisualizationConfig } from '@/providers/visualizationConfig'
|
2023-12-14 01:27:31 +03:00
|
|
|
import { Vec2 } from '@/util/data/vec2'
|
2023-10-29 22:02:07 +03:00
|
|
|
import { MockTransport } from '@/util/net'
|
|
|
|
import type { QualifiedName } from '@/util/qualifiedName'
|
|
|
|
import { defineSetupVue3 } from '@histoire/plugin-vue'
|
2023-11-27 18:48:37 +03:00
|
|
|
import * as random from 'lib0/random'
|
2023-10-29 22:02:07 +03:00
|
|
|
import { createPinia } from 'pinia'
|
|
|
|
import type { LibraryComponentGroup, Uuid, response } from 'shared/languageServerTypes'
|
2023-12-15 17:58:57 +03:00
|
|
|
import type {
|
|
|
|
SuggestionEntry,
|
|
|
|
SuggestionsDatabaseUpdate,
|
|
|
|
} from 'shared/languageServerTypes/suggestions'
|
2023-10-29 22:02:07 +03:00
|
|
|
import { ref } from 'vue'
|
|
|
|
import mockDb from './mockSuggestions.json' assert { type: 'json' }
|
|
|
|
import './story.css'
|
|
|
|
|
2023-11-27 18:48:37 +03:00
|
|
|
const mockProjectId = random.uuidv4() as Uuid
|
2023-10-29 22:02:07 +03:00
|
|
|
const standardBase = 'Standard.Base' as QualifiedName
|
|
|
|
|
|
|
|
export function placeholderGroups(): LibraryComponentGroup[] {
|
|
|
|
return [
|
|
|
|
{ color: '#4D9A29', name: 'Input', library: standardBase, exports: [] },
|
|
|
|
{ color: '#B37923', name: 'Web', library: standardBase, exports: [] },
|
|
|
|
{ color: '#9735B9', name: 'Parse', library: standardBase, exports: [] },
|
|
|
|
{ color: '#4D9A29', name: 'Select', library: standardBase, exports: [] },
|
|
|
|
{ color: '#B37923', name: 'Join', library: standardBase, exports: [] },
|
|
|
|
{ color: '#9735B9', name: 'Transform', library: standardBase, exports: [] },
|
|
|
|
{ color: '#4D9A29', name: 'Output', library: standardBase, exports: [] },
|
|
|
|
]
|
|
|
|
}
|
|
|
|
|
|
|
|
MockTransport.addMock('engine', async (method, data, transport) => {
|
|
|
|
switch (method) {
|
|
|
|
case 'session/initProtocolConnection':
|
|
|
|
return {
|
|
|
|
contentRoots: [{ type: 'Project', id: mockProjectId }],
|
|
|
|
} satisfies response.InitProtocolConnection
|
|
|
|
case 'executionContext/create':
|
|
|
|
setTimeout(
|
|
|
|
() => transport.emit('executionContext/executionComplete', { contextId: data.contextId }),
|
|
|
|
100,
|
|
|
|
)
|
|
|
|
return {
|
|
|
|
contextId: data.contextId,
|
|
|
|
}
|
|
|
|
case 'search/getSuggestionsDatabase':
|
2023-12-15 17:58:57 +03:00
|
|
|
// We first send the empty database, and then update it 200 ms later, mimicking the real LS.
|
|
|
|
setTimeout(() => {
|
|
|
|
const updates: SuggestionsDatabaseUpdate[] = mockDb.map((suggestion, id) => ({
|
|
|
|
type: 'Add',
|
2023-10-29 22:02:07 +03:00
|
|
|
id,
|
|
|
|
suggestion: suggestion as SuggestionEntry,
|
2023-12-15 17:58:57 +03:00
|
|
|
}))
|
|
|
|
transport.emit('search/suggestionsDatabaseUpdates', { updates, currentVersion: 2 })
|
|
|
|
}, 200)
|
|
|
|
return {
|
|
|
|
entries: [],
|
2023-10-29 22:02:07 +03:00
|
|
|
currentVersion: 1,
|
|
|
|
} satisfies response.GetSuggestionsDatabase
|
|
|
|
case 'runtime/getComponentGroups':
|
|
|
|
return { componentGroups: placeholderGroups() } satisfies response.GetComponentGroups
|
2023-11-03 23:09:45 +03:00
|
|
|
case 'file/list':
|
|
|
|
return { paths: [] } satisfies response.FileList
|
2023-10-29 22:02:07 +03:00
|
|
|
case 'executionContext/push':
|
|
|
|
case 'executionContext/pop':
|
|
|
|
case 'executionContext/recompute':
|
|
|
|
case 'capability/acquire':
|
|
|
|
return {}
|
|
|
|
default:
|
|
|
|
return Promise.reject(`Method not mocked: ${method}`)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
|
|
|
export const setupVue3 = defineSetupVue3(({ app }) => {
|
|
|
|
app.use(createPinia())
|
|
|
|
provideGuiConfig._mock(
|
|
|
|
ref({
|
|
|
|
startup: {
|
|
|
|
project: 'Mock Project',
|
|
|
|
displayedProjectName: 'Mock Project',
|
|
|
|
},
|
|
|
|
engine: { rpcUrl: 'mock://engine', dataUrl: 'mock://data' },
|
|
|
|
}),
|
|
|
|
app,
|
|
|
|
)
|
|
|
|
// Required for visualization stories.
|
|
|
|
provideVisualizationConfig._mock(
|
|
|
|
{
|
|
|
|
fullscreen: false,
|
2023-12-08 21:45:42 +03:00
|
|
|
scale: 1,
|
2023-10-29 22:02:07 +03:00
|
|
|
width: 200,
|
|
|
|
height: 150,
|
|
|
|
hide() {},
|
|
|
|
isCircularMenuVisible: false,
|
2023-12-08 21:45:42 +03:00
|
|
|
isBelowToolbar: false,
|
2023-10-29 22:02:07 +03:00
|
|
|
nodeSize: new Vec2(200, 150),
|
|
|
|
currentType: {
|
|
|
|
module: { kind: 'Builtin' },
|
|
|
|
name: 'Current Type',
|
|
|
|
},
|
2023-12-01 15:41:24 +03:00
|
|
|
icon: 'braces',
|
2023-10-29 22:02:07 +03:00
|
|
|
types: [
|
|
|
|
{
|
|
|
|
module: { kind: 'Builtin' },
|
|
|
|
name: 'Example',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
module: { kind: 'Builtin' },
|
|
|
|
name: 'Types',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
module: { kind: 'Builtin' },
|
|
|
|
name: 'Here',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
updateType() {},
|
|
|
|
},
|
|
|
|
app,
|
|
|
|
)
|
|
|
|
})
|