Files
windmill/frontend/src/lib/components/build_workers.ts
T
Faton RamadaniandRuben Fiszel c19757af1b feat(frontend): Global CSS editor (#2178)
* feat(frontend): add global css

* feat(frontend): working styling

* feat(frontend): Add default classes

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* wip

* feat(frontend): Add global css v0

* feat(frontend): Add global css v0

* add css workers

* fix(frontend): Fix overflow issue

* wip

* feat(frontend): check for EE before injecting global css

* wip

* wip

* wip

* fix(frontend): fix typing issues

* fix(frontend): fix typing issues

* fix(frontend): fix global css

* fix(frontend): add missing mapping

* fix(frontend): Fix how styles are loaded

* fix(frontend): fix preview

* feat(frontend): fix everything

* feat(frontend): fix class autocomplete

* feat(frontend): remove console.log

* feat(frontend): update tooltup

* feat(frontend): eval

* feat(frontend): eval

* feat(frontend): fix build

* feat(frontend): fix initial binding

* feat(frontend): wip

* wip

* feat(frontend): Finish theme v0

* feat(frontend): Fix resource page

* feat(frontend): fix build

* feat(frontend): theme UI

* feat(frontend): theme UI

* feat(frontend): theme UI

* feat(frontend): fix EE

* feat(frontend): add missing warning

* feat(frontend): fix preview

* feat(frontend): fix global css by component initialisation

* feat(frontend): remove unused libraries

* feat(frontend): fix EE check

* feat(frontend): fix EE check

* feat(frontend): fix preview

* feat(frontend): Fix migration

* feat(frontend): Fix issues

* feat(frontend): add missing disabled in migration modal

* feat(frontend): Fix preview

* feat(frontend): Fix preview

* all

* all

* all

* sqlx

---------

Co-authored-by: Ruben Fiszel <ruben@rubenfiszel.com>
2023-09-15 22:55:47 +02:00

91 lines
2.7 KiB
TypeScript

import type { Environment } from 'monaco-editor/esm/vs/editor/editor.api.js'
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker'
interface MonacoEnvironmentEnhanced extends Environment {
workerOverrideGlobals: WorkerOverrideGlobals
}
type WorkerOverrideGlobals = {
basePath: string
workerPath: string
workerOptions: WorkerOptions
}
export function buildWorkerDefinition(
workerPath: string,
basePath: string,
useModuleWorker: boolean
) {
const monWin = self as Window
const workerOverrideGlobals: WorkerOverrideGlobals = {
basePath: basePath,
workerPath: workerPath,
workerOptions: {
type: useModuleWorker ? 'module' : 'classic'
}
}
if (!monWin.MonacoEnvironment) {
monWin.MonacoEnvironment = {
workerOverrideGlobals: workerOverrideGlobals,
createTrustedTypesPolicy: (_policyName: string) => {
return undefined
}
} as MonacoEnvironmentEnhanced
}
const monEnv = monWin.MonacoEnvironment as MonacoEnvironmentEnhanced
monEnv.workerOverrideGlobals = workerOverrideGlobals
const getWorker = (_: string, label: string) => {
console.log('getWorker: workerId: ' + _ + ' label: ' + label)
const buildWorker = (
globals: WorkerOverrideGlobals,
label: string,
workerName: string,
editorType: string
) => {
globals.workerOptions.name = label
const workerFilename =
globals.workerOptions.type === 'module' ? `${workerName}-es.js` : `${workerName}-iife.js`
const workerPathLocal = `${globals.workerPath}/${workerFilename}`
const workerUrl = new URL(workerPathLocal, globals.basePath)
console.log(
`${editorType}: url: ${workerUrl.href} created from basePath: ${globals.basePath} and file: ${workerPathLocal}`
)
return new Worker(workerUrl.href, globals.workerOptions)
}
switch (label) {
case 'template':
case 'typescript':
case 'javascript':
return buildWorker(workerOverrideGlobals, label, 'tsWorker', 'TS Worker')
case 'html':
case 'handlebars':
case 'razor':
return buildWorker(workerOverrideGlobals, label, 'htmlWorker', 'HTML Worker')
case 'css':
return new cssWorker()
case 'scss':
case 'less':
return buildWorker(workerOverrideGlobals, label, 'cssWorker', 'CSS Worker')
case 'json':
return buildWorker(workerOverrideGlobals, label, 'jsonWorker', 'JSON Worker')
case 'graphql':
const workerFilename = `graphql.worker.bundle.js`
const workerPathLocal = `${workerOverrideGlobals.workerPath}/${workerFilename}`
const workerUrl = new URL(workerPathLocal, workerOverrideGlobals.basePath)
return new Worker(workerUrl.href, {
name: label
})
default:
return buildWorker(workerOverrideGlobals, label, 'editorWorker', 'Editor Worker')
}
}
monWin.MonacoEnvironment.getWorker = getWorker
}