diff --git a/integrations/repl/src/components/Repl.vue b/integrations/repl/src/components/Repl.vue
index c50ae542..743f3e42 100644
--- a/integrations/repl/src/components/Repl.vue
+++ b/integrations/repl/src/components/Repl.vue
@@ -126,11 +126,13 @@ css({
'--bg-soft': '$color.gray.1',
'--border': '$color.gray.2',
'--text-light': '$color.gray.9',
+ '--font-base': '\'Onest\'',
'--font-code': '\'JetBrains Mono\', monospace',
'--color-branding': '$color.red.5',
'--color-branding-dark': '$color.blue.5',
'--header-height': '$space.12',
+ 'fontFamily': 'var(--font-base)',
'display': 'flex',
'flexDirection': 'column',
'height': '100%',
@@ -154,7 +156,6 @@ css({
'margin': '0',
'overflow': 'hidden',
'fontSize': '12px',
- 'fontFamily': '\'Onest\', sans-serif',
'backgroundColor': 'var(--bg-soft)',
'&.has-topbar': {
height: 'calc(100% - var(--header-height))',
diff --git a/integrations/repl/src/components/monaco/env.ts b/integrations/repl/src/components/monaco/env.ts
index 1e6d04dd..7cbb90b3 100644
--- a/integrations/repl/src/components/monaco/env.ts
+++ b/integrations/repl/src/components/monaco/env.ts
@@ -45,18 +45,27 @@ export function initMonaco(store: Store) {
const file = store.state.builtFiles[filename]
if (
- filename === '$pinceau/utils'
- || filename === '$pinceau/theme'
- || filename === 'pinceau.css'
- ) { continue }
+ [
+ '@pinceau/outputs/utils',
+ '@pinceau/outputs/theme',
+ '@pinceau/outputs/theme.css',
+ ].includes(filename)
+ ) {
+ continue
+ }
+
+ if (filename.includes('-ts')) {
+ filename = filename.slice(0, filename.indexOf('-ts'))
+ }
- if (filename.includes('-types')) {
- filename = filename.slice(0, filename.indexOf('-types'))
+ let uri: Uri = Uri.parse(`/npm/@pinceau/outputs@latest/${filename.replace('@pinceau/outputs/', '')}.d.ts`)
+ if (filename === '@pinceau/outputs') {
+ uri = Uri.parse('/npm/@pinceau/outputs@latest/index.d.ts')
}
getOrCreateModel(
- Uri.parse(filename),
- 'typescript',
+ uri,
+ undefined,
file.code,
)
}
diff --git a/integrations/repl/src/components/monaco/utils.ts b/integrations/repl/src/components/monaco/utils.ts
index a6234fc1..0398a639 100644
--- a/integrations/repl/src/components/monaco/utils.ts
+++ b/integrations/repl/src/components/monaco/utils.ts
@@ -6,11 +6,12 @@ export function getOrCreateModel(
lang: string | undefined,
value: string,
) {
+ console.log({ uri: uri.path, lang, value })
const model = editor.getModel(uri)
if (model) {
model.setValue(value)
return model
}
- console.log('creating', uri)
+ // console.log('creating', uri)
return editor.createModel(value, lang, uri)
}
diff --git a/integrations/repl/src/components/output/Preview.vue b/integrations/repl/src/components/output/Preview.vue
index aa873a9b..b285ef58 100644
--- a/integrations/repl/src/components/output/Preview.vue
+++ b/integrations/repl/src/components/output/Preview.vue
@@ -51,7 +51,7 @@ watch(
watch(store.resetFlip, createSandbox)
watch(
- () => store.state.files['src/theme.config.ts'],
+ () => store.state.builtFiles,
() => {
nextTick(() => createSandbox())
},
@@ -101,11 +101,11 @@ function createSandbox() {
//,
previewOptions?.placeholderHTML || ''
)
-
- if (store.state.builtFiles['pinceau.css']) {
+
+ if (store.state.builtFiles['@pinceau/outputs/theme.css']) {
sandboxSrc = sandboxSrc.replace(
//,
- ``
+ ``
)
}
@@ -204,6 +204,10 @@ css({
width: '100%',
height: '100%',
border: 'none',
+ position: 'relative'
+ },
+ '.msg': {
+ marginBottom: '$space.14'
}
})
diff --git a/integrations/repl/src/store/index.ts b/integrations/repl/src/store/index.ts
index 34c06da2..e67a959a 100644
--- a/integrations/repl/src/store/index.ts
+++ b/integrations/repl/src/store/index.ts
@@ -13,7 +13,7 @@ import { PinceauProvider } from './pinceau'
export const importMapFile = 'import-map.json'
export const tsconfigFile = 'tsconfig.json'
export const themeFile = 'theme.config.ts'
-export const pinceauVersion = '1.0.0-beta.16'
+export const pinceauVersion = '1.0.0-beta.21'
const supportedTransformers = {
vue: ReplVueTransformer,
@@ -224,10 +224,6 @@ export class ReplStore implements Store {
this.init()
this.forceSandboxReset()
- setTimeout(() => {
- window?.location?.reload()
- }, 1000)
-
return this
}
diff --git a/integrations/repl/src/store/pinceau.ts b/integrations/repl/src/store/pinceau.ts
index 571bfefa..bdc35a0d 100644
--- a/integrations/repl/src/store/pinceau.ts
+++ b/integrations/repl/src/store/pinceau.ts
@@ -8,6 +8,7 @@ import {
pinceauVariableTransformer,
resolveConfigContent,
resolveMediaQueriesKeys,
+ pluginTypes as themePluginTypes,
typescriptFormat,
utilsFormat,
utilsTypesFormat,
@@ -21,9 +22,12 @@ import { PinceauSvelteTransformer } from '@pinceau/svelte/utils'
import { findDefaultExport, parseAst, parsePinceauQuery, printAst, usePinceauContext, usePinceauTransformContext, visitAst } from '@pinceau/core/utils'
import { suite as styleSuite } from '@pinceau/style/transforms'
import { suite as themeSuite } from '@pinceau/theme/transforms'
+import { pluginTypes as stylePluginTypes } from '@pinceau/style/utils'
import type { PinceauContext } from '@pinceau/core'
import { File } from '..'
import type { ReplStore } from '..'
+import { processModule } from '../compiler'
+import { transformTS } from '../transforms/typescript'
import { themeFile } from '.'
export class PinceauProvider {
@@ -59,10 +63,14 @@ export class PinceauProvider {
'vue',
PinceauVueTransformer,
)
+
this.pinceauContext.registerTransformer(
'svelte',
PinceauSvelteTransformer,
)
+
+ this.pinceauContext.addTypes(themePluginTypes)
+ this.pinceauContext.addTypes(stylePluginTypes)
}
init() {
@@ -121,8 +129,32 @@ export class PinceauProvider {
this.pinceauContext,
)
- for (const [key, output] of Object.entries(builtTheme.outputs)) {
- builtFiles[key] = new File(key, output, true)
+ for (const [key, output] of Object.entries(builtTheme.outputs as { [key: string]: string })) {
+ if (key === '@pinceau/outputs' || key.includes('.css')) {
+ builtFiles[key] = new File(
+ key,
+ output,
+ true,
+ )
+ continue
+ }
+
+ let built: string = output
+ if (key.includes('-ts')) {
+ built = await transformTS(built)
+ }
+
+ const newFile = builtFiles[key] = new File(
+ key,
+ output,
+ true,
+ )
+
+ newFile.compiled.js = newFile.compiled.ssr = processModule(
+ this.store,
+ built,
+ key,
+ ).code
}
this.store.state.builtFiles = builtFiles
diff --git a/integrations/repl/src/store/react.ts b/integrations/repl/src/store/react.ts
index ed620527..1449432f 100644
--- a/integrations/repl/src/store/react.ts
+++ b/integrations/repl/src/store/react.ts
@@ -1,6 +1,7 @@
import type { Ref } from 'vue'
+import { createReactPlugin, pluginTypes } from '@pinceau/react/utils'
import { compileFile } from '../transforms'
-import { compileModulesForPreview } from '../compiler'
+import { compileModulesForPreview, processModule } from '../compiler'
import type { PreviewProxy } from '../components/output/PreviewProxy'
import type { ReplStore, ReplTransformer } from '.'
import { File, pinceauVersion } from '.'
@@ -30,7 +31,7 @@ const localImports = {
'@pinceau/core/runtime': () => `https://cdn.jsdelivr.net/npm/@pinceau/core@${pinceauVersion}/dist/runtime.mjs`,
'@pinceau/theme/runtime': () => `https://cdn.jsdelivr.net/npm/@pinceau/theme@${pinceauVersion}/dist/runtime.mjs`,
'@pinceau/react/runtime': () => `https://cdn.jsdelivr.net/npm/@pinceau/vue@${pinceauVersion}/dist/runtime.mjs`,
- '$pinceau/react-plugin': () => '/react-plugin-proxy.js',
+ '@pinceau/outputs/react-plugin': () => './react-plugin-proxy.js',
}
export class ReplReactTransformer implements ReplTransformer
{
@@ -83,6 +84,8 @@ declare global {
constructor({ store }: { store: ReplStore }) {
this.store = store
+
+ this.store.pinceauProvider.pinceauContext.addTypes(pluginTypes)
}
getTypescriptDependencies() {
@@ -147,6 +150,39 @@ declare global {
)
}
+ getBuiltFilesModules() {
+ const modules: string[] = []
+
+ for (const [key, code] of Object.entries(this.store.state.builtFiles)) {
+ if (
+ [
+ '@pinceau/outputs/theme',
+ '@pinceau/outputs/theme-ts',
+ '@pinceau/outputs/theme.css',
+ '@pinceau/outputs/utils-ts',
+ '@pinceau/outputs',
+ ].includes(key)
+ ) { continue }
+ modules.push(code.code)
+ }
+
+ let reactPlugin = createReactPlugin(this.store.pinceauProvider.pinceauContext)
+
+ reactPlugin = reactPlugin.replace(
+ 'import React, { createContext, useContext } from \'react\'',
+ 'const { createContext, useContext } = window.React',
+ )
+
+ return [
+ processModule(
+ this.store,
+ reactPlugin,
+ '@pinceau/outputs/react-plugin',
+ ).code,
+ ...modules,
+ ]
+ }
+
async compileFile(file: File): Promise<(string | Error)[]> {
return await compileFile(this.store, file)
}
@@ -175,16 +211,16 @@ declare global {
console.log(`[@pinceau/repl] Successfully compiled ${ssrModules.length} modules for SSR.`)
await proxy.eval([
+ 'import \'react\'\nimport \'react-dom\'\nimport \'react-dom/server\'\n',
'const __modules__ = {};',
- 'globalThis.require = (val) => { if (val === \'react-dom\') return ReactDOM }',
+ `globalThis.require = (val) => {
+ if (val === \'react\') return React
+ if (val === \'react-dom\') return ReactDOM
+ }`,
+ 'const ReactDOM = window.ReactDOM\nconst React = window.React',
+ ...this.getBuiltFilesModules(),
...ssrModules,
- `import 'react'
- import 'react-dom'
- import 'react-dom/server'
- import { PinceauProvider, PinceauContext } from '@pinceau/outputs/react-plugin'
-
- const ReactDOM = window.ReactDOM
- const React = window.React
+ `import { PinceauProvider } from "@pinceau/outputs/react-plugin"
const AppComponent = __modules__["${mainFile}"].default
@@ -228,15 +264,18 @@ declare global {
// compile code to simulated module system
const modules = compileModulesForPreview(this.store)
+
console.log(`[@pinceau/repl] Compiled ${modules.length} module${modules.length > 1 ? 's' : ''}.`)
const codeToEval = [
+ 'import \'react\'\nimport \'react-dom\'\nimport \'react-dom/server\'\n',
'window.__modules__ = {};window.__css__ = [];'
+ `if (window.__app__) window.__app__.unmount();${
isSSR
? ''
: `document.body.innerHTML = '' + \`${previewOptions?.bodyHTML || ''
}\``}`,
+ ...this.getBuiltFilesModules(),
...modules,
`setTimeout(()=> {
document.querySelectorAll('style[css]').forEach(el => el.remove())
@@ -247,11 +286,7 @@ declare global {
// if main file is a vue file, mount it.
if (mainFile.endsWith('.tsx')) {
codeToEval.push(
- `import 'react'
- import 'react-dom'
- import 'react-dom/server'
- import { PinceauProvider } from '@pinceau/outputs/react-plugin'
-
+ `import { PinceauProvider } from "@pinceau/outputs/react-plugin"
${previewOptions?.customCode?.importCode || ''}
const _mount = () => {
diff --git a/integrations/repl/src/store/svelte.ts b/integrations/repl/src/store/svelte.ts
index eb46bed4..19f2be2b 100644
--- a/integrations/repl/src/store/svelte.ts
+++ b/integrations/repl/src/store/svelte.ts
@@ -1,7 +1,8 @@
import type { Ref } from 'vue'
import * as defaultCompiler from 'svelte/compiler'
+import { createSveltePlugin, pluginTypes } from '@pinceau/svelte/utils'
import { compileFile } from '../transforms'
-import { compileModulesForPreview } from '../compiler'
+import { compileModulesForPreview, processModule } from '../compiler'
import type { PreviewProxy } from '../components/output/PreviewProxy'
import type { ReplStore, ReplTransformer } from '.'
import { File, pinceauVersion } from '.'
@@ -38,7 +39,7 @@ const localImports = {
'@pinceau/core/runtime': () => `https://cdn.jsdelivr.net/npm/@pinceau/core@${pinceauVersion}/dist/runtime.mjs`,
'@pinceau/theme/runtime': () => `https://cdn.jsdelivr.net/npm/@pinceau/theme@${pinceauVersion}/dist/runtime.mjs`,
'@pinceau/react/runtime': () => `https://cdn.jsdelivr.net/npm/@pinceau/react@${pinceauVersion}/dist/runtime.mjs`,
- '$pinceau/svelte-plugin': () => '/svelte-plugin-proxy.js',
+ '@pinceau/outputs/svelte-plugin': () => './svelte-plugin-proxy.js',
}
export class ReplSvelteTransformer implements ReplTransformer {
@@ -92,6 +93,8 @@ export class ReplSvelteTransformer implements ReplTransformer {
constructor({ store }: { store: ReplStore }) {
this.store = store
+
+ this.store.pinceauProvider.pinceauContext.addTypes(pluginTypes)
}
getTypescriptDependencies() {
@@ -157,6 +160,34 @@ export class ReplSvelteTransformer implements ReplTransformer {
)
}
+ getBuiltFilesModules() {
+ const modules: string[] = []
+
+ for (const [key, code] of Object.entries(this.store.state.builtFiles)) {
+ if (
+ [
+ '@pinceau/outputs/theme',
+ '@pinceau/outputs/theme-ts',
+ '@pinceau/outputs/theme.css',
+ '@pinceau/outputs/utils-ts',
+ '@pinceau/outputs',
+ ].includes(key)
+ ) { continue }
+ modules.push(code.code)
+ }
+
+ const sveltePlugin = createSveltePlugin(this.store.pinceauProvider.pinceauContext)
+
+ return [
+ processModule(
+ this.store,
+ sveltePlugin,
+ '@pinceau/outputs/svelte-plugin',
+ ).code,
+ ...modules,
+ ]
+ }
+
async compileFile(file: File): Promise<(string | Error)[]> {
return compileFile(this.store, file)
}
@@ -203,7 +234,8 @@ export class ReplSvelteTransformer implements ReplTransformer {
isSSR && false
? ''
: `document.body.innerHTML = '' + \`${previewOptions?.bodyHTML || ''
- }\``}`,
+ }\``}`,
+ ...this.getBuiltFilesModules(),
...modules,
`setTimeout(()=> {
document.querySelectorAll('style[css]').forEach(el => el.remove())
diff --git a/integrations/repl/src/store/vue.ts b/integrations/repl/src/store/vue.ts
index 08234646..d916a93f 100644
--- a/integrations/repl/src/store/vue.ts
+++ b/integrations/repl/src/store/vue.ts
@@ -6,11 +6,12 @@ import type {
SFCTemplateCompileOptions,
} from 'vue/compiler-sfc'
import type { Ref } from 'vue'
+import { createVuePlugin, pluginTypes } from '@pinceau/vue/utils'
import { compileFile } from '../transforms'
-import { compileModulesForPreview } from '../compiler'
+import { compileModulesForPreview, processModule } from '../compiler'
import type { PreviewProxy } from '../components/output/PreviewProxy'
-import type { ReplStore, ReplTransformer } from '.'
-import { File, pinceauVersion } from '.'
+import type { File, ReplStore, ReplTransformer } from '.'
+import { pinceauVersion } from '.'
const defaultMainFile = 'src/App.vue'
@@ -45,7 +46,7 @@ const localImports = {
'@pinceau/core/runtime': () => `https://cdn.jsdelivr.net/npm/@pinceau/core@${pinceauVersion}/dist/runtime.mjs`,
'@pinceau/theme/runtime': () => `https://cdn.jsdelivr.net/npm/@pinceau/theme@${pinceauVersion}/dist/runtime.mjs`,
'@pinceau/vue/runtime': () => `https://cdn.jsdelivr.net/npm/@pinceau/vue@${pinceauVersion}/dist/runtime.mjs`,
- '$pinceau/vue-plugin': () => '/vue-plugin-proxy.js',
+ '@pinceau/outputs/vue-plugin': () => './vue-plugin-proxy.js',
}
export class ReplVueTransformer implements ReplTransformer {
@@ -59,23 +60,7 @@ export class ReplVueTransformer implements ReplTransformer | null = null
imports: typeof localImports = localImports
- shims = {
- 'global.d.ts': new File('global.d.ts', `
- import type { VueStyledComponentFactory } from \'@pinceau/vue\'
- import type { PropType } from \'vue\'
- import type { StyledFunctionArg, SupportedHTMLElements, ResponsiveProp } from \'@pinceau/style\'
-
- declare global {
- export type ResponsiveProp = PropType>
- export type StyledProp = PropType
- export const $styled: { [Type in SupportedHTMLElements]: VueStyledComponentFactory }
- }
-
- declare module \'@vue/runtime-dom\' { interface HTMLAttributes { styled?: StyledFunctionArg } }
-
- export {}
- `),
- }
+ shims = {}
tsconfig: any = {
compilerOptions: {
@@ -86,6 +71,7 @@ export class ReplVueTransformer implements ReplTransformer {
return compileFile(this.store, file)
}
@@ -209,12 +222,20 @@ export class ReplVueTransformer implements ReplTransformer ' + \`${previewOptions?.bodyHTML || ''
- }\``}`,
+ }\``}`,
+ ...this.getBuiltFilesModules(),
...modules,
`setTimeout(()=> {
document.querySelectorAll('style[css]').forEach(el => el.remove())
@@ -259,7 +281,7 @@ export class ReplVueTransformer implements ReplTransformer