Skip to content

Commit

Permalink
feat(packages): update outputs package; expose plugin-types
Browse files Browse the repository at this point in the history
  • Loading branch information
Tahul committed Oct 20, 2023
1 parent f7cd05b commit 9102810
Show file tree
Hide file tree
Showing 42 changed files with 1,801 additions and 348 deletions.
2 changes: 1 addition & 1 deletion integrations/nuxt/server/pinceau.server.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ export default async function (nitro) {
if ($pinceauSSR.options?.ssr?.runtime) { htmlContext.head.splice(2, 0, `<style id="pinceau-runtime">${$pinceauSSR?.css || ''}</style>`) }

// Theme sheet
if ($pinceauSSR.options?.ssr?.theme) { htmlContext.head.splice(2, 0, `<style id="pinceau-theme" ${$pinceauSSR.options?.dev ? 'data-vite-dev-id="pinceau.css"' : ''}>${theme || ''}</style>`) }
if ($pinceauSSR.options?.ssr?.theme) { htmlContext.head.splice(2, 0, `<style id="pinceau-theme" ${$pinceauSSR.options?.dev ? 'data-vite-dev-id="@pinceau/outputs/theme.css"' : ''}>${theme || ''}</style>`) }
})
}
12 changes: 2 additions & 10 deletions integrations/react/src/unplugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { createUnplugin } from 'unplugin'
import type { UnpluginInstance } from 'unplugin'
import { suite } from './transforms/suite'
import { registerVirtualOutputs } from './utils/virtual'
import { pluginTypes } from './utils/plugin-types'

export { registerVirtualOutputs }

Expand All @@ -21,16 +22,7 @@ export const PinceauReactPlugin: UnpluginInstance<undefined> = createUnplugin(()

registerVirtualOutputs(ctx)

ctx.addTypes({
imports: [
'import type { ReactStyledComponentFactory } from \'@pinceau/react\'',
],
global: [
'export const $styled: { [Type in SupportedHTMLElements]: ReactStyledComponentFactory<Type> }',
],
raw: [
],
})
ctx.addTypes(pluginTypes)
},
},

Expand Down
1 change: 1 addition & 0 deletions integrations/react/src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './utils/runtime-plugin'
export * from './utils/virtual'
export * from './utils/plugin-types'
10 changes: 10 additions & 0 deletions integrations/react/src/utils/plugin-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export const pluginTypes = {
imports: [
'import type { ReactStyledComponentFactory } from \'@pinceau/react\'',
],
global: [
'export const $styled: { [Type in SupportedHTMLElements]: ReactStyledComponentFactory<Type> }',
],
raw: [
],
}
21 changes: 4 additions & 17 deletions integrations/repl/public/react-plugin-proxy.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,7 @@
import { useRuntimeSheet, useThemeSheet } from '@pinceau/runtime'
const PinceauProvider = window.__modules__['@pinceau/outputs/react-plugin'].PinceauProvider

export const PinceauReactOptions = { dev: false, colorSchemeMode: 'media', computedStyles: true, variants: true, ssr: { theme: true, runtime: true }, appId: false }
const PinceauReactOptions = window.__modules__['@pinceau/outputs/react-plugin'].PinceauReactOptions

export const PinceauContext = React.createContext()
const usePinceauContext = window.__modules__['@pinceau/outputs/react-plugin'].usePinceauContext

export const usePinceauContext = () => React.useContext(PinceauContext)

export function PinceauProvider({ options, children, cb }) {
const userOptions = { ...PinceauReactOptions, ...options }

const themeSheet = useThemeSheet(userOptions)
const runtimeSheet = useRuntimeSheet({ themeSheet, ...userOptions })

const ssr = { toString: () => runtimeSheet.toString() }

if (cb) { cb(ssr) }

return React.createElement(PinceauContext.Provider, { value: { themeSheet, runtimeSheet, ssr }, children })
}
export { PinceauProvider, PinceauReactOptions, usePinceauContext }
21 changes: 6 additions & 15 deletions integrations/repl/public/svelte-plugin-proxy.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,11 @@
import { useRuntimeSheet, useThemeSheet } from '@pinceau/runtime'
const getThemeSheet = window.__modules__['@pinceau/outputs/svelte-plugin'].getThemeSheet

export const PinceauSvelteOptions = { dev: false, colorSchemeMode: 'media', computedStyles: true, variants: true, ssr: { theme: true, runtime: true }, appId: false }
const getRuntimeSheet = window.__modules__['@pinceau/outputs/svelte-plugin'].getRuntimeSheet

let userOptions
const PinceauSvelteOptions = window.__modules__['@pinceau/outputs/svelte-plugin'].PinceauSvelteOptions

let themeSheet
export const getRuntimeSheet = () => runtimeSheet
const pinceauPlugin = window.__modules__['@pinceau/outputs/svelte-plugin'].pinceauPlugin

let runtimeSheet
export const getThemeSheet = () => themeSheet
const ssr = window.__modules__['@pinceau/outputs/svelte-plugin'].ssr

export function pinceauPlugin(options) {
userOptions = { ...PinceauSvelteOptions, ...options }

themeSheet = useThemeSheet(userOptions)
runtimeSheet = useRuntimeSheet({ themeSheet, ...userOptions })
}

export const ssr = { toString: () => runtimeSheet.toString() }
export { getThemeSheet, getRuntimeSheet, PinceauSvelteOptions, pinceauPlugin, ssr }
18 changes: 3 additions & 15 deletions integrations/repl/public/vue-plugin-proxy.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,5 @@
import { useRuntimeSheet, useThemeSheet } from '@pinceau/runtime'
const PinceauVueOptions = window.__modules__['@pinceau/outputs/vue-plugin'].PinceauVueOptions

export const PinceauVueOptions = { dev: false, colorSchemeMode: 'media', computedStyles: true, variants: true, ssr: { theme: true, runtime: true }, appId: false }
const PinceauVue = window.__modules__['@pinceau/outputs/vue-plugin'].PinceauVue

export const PinceauVue = {
install(app, options = {}) {
const _options = { ...PinceauVueOptions, ...options }

const themeSheet = useThemeSheet(_options)
app.provide('pinceauThemeSheet', themeSheet)

const runtimeSheet = useRuntimeSheet({ themeSheet, ..._options })
app.provide('pinceauRuntimeSheet', runtimeSheet)

app.config.globalProperties.$pinceauSSR = { toString: () => runtimeSheet.toString() }
},
}
export { PinceauVueOptions, PinceauVue }
Loading

0 comments on commit 9102810

Please sign in to comment.