Skip to content

Commit 1513957

Browse files
authoredJun 12, 2024··
chore(preview): remove tokens support (#174)
1 parent 26e7e3d commit 1513957

File tree

5 files changed

+16
-146
lines changed

5 files changed

+16
-146
lines changed
 

Diff for: ‎src/runtime/components/ContentPreviewMode.vue

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ onMounted(async () => {
144144
145145
socket.on('draft:unauthorized', () => {
146146
clearSyncTimeout()
147-
error.value = 'Unauthorized preview token'
147+
error.value = 'Unauthorized preview'
148148
previewReady.value = false
149149
})
150150
socket.on('disconnect', () => {

Diff for: ‎src/runtime/composables/useStudio.ts

+2-48
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,9 @@ export const useStudio = () => {
2929

3030
// App config (required)
3131
const initialAppConfig = useDefaultAppConfig()
32-
let initialTokensConfig: object
33-
3432
const storage = useState<Storage | null>('studio-client-db', () => null)
3533

3634
if (!storage.value) {
37-
// @ts-expect-error custom hook
3835
nuxtApp.hook('content:storage', (_storage: Storage) => {
3936
storage.value = _storage
4037
})
@@ -81,33 +78,6 @@ export const useStudio = () => {
8178
}
8279
}
8380

84-
const syncPreviewTokensConfig = (tokensConfig?: ParsedContent) => {
85-
// Tokens config (optional; depends on the presence of pinceauTheme provide)
86-
// TODO: Improve typings
87-
// TODO: Use `inject()` but wrong context seem to be resolved; while $pinceauTheme global property is present in `app` context
88-
const themeSheet = nuxtApp?.vueApp?._context?.config?.globalProperties?.$pinceauTheme as Record<string, unknown>
89-
90-
// Pinceau might be not present, or not booted yet
91-
if (!themeSheet || !themeSheet?.updateTheme) return
92-
93-
// Set initial tokens config on first call
94-
if (!initialTokensConfig) {
95-
initialTokensConfig = JSON.parse(JSON.stringify((themeSheet?.theme as Record<string, unknown>).value || {}))
96-
}
97-
98-
// Call updateTheme with new config
99-
callWithNuxt(
100-
nuxtApp,
101-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
102-
themeSheet.updateTheme as any,
103-
[
104-
// Using `defu` to merge with initial tokens
105-
// This is important to revert to default values for missing properties
106-
defu(tokensConfig as ParsedContent, initialTokensConfig),
107-
],
108-
)
109-
}
110-
11181
const syncPreview = async (data: PreviewResponse) => {
11282
// Preserve db files in case storage is not ready yet (see check below)
11383
dbFiles = data.files = data.files || dbFiles || []
@@ -117,21 +87,18 @@ export const useStudio = () => {
11787
return false
11888
}
11989

120-
// Empty dbFiles array once storage is ready
90+
// Empty dbFiles array once storage is ready to clear memory
12191
dbFiles = []
12292

12393
const mergedFiles = mergeDraft(data.files, data.additions, data.deletions)
12494

12595
// Handle content files
126-
const contentFiles = mergedFiles.filter(item => !([StudioConfigFiles.appConfig, StudioConfigFiles.nuxtConfig, StudioConfigFiles.tokensConfig].includes(item.path)))
96+
const contentFiles = mergedFiles.filter(item => !([StudioConfigFiles.appConfig, StudioConfigFiles.nuxtConfig].includes(item.path)))
12797
await syncPreviewFiles(storage.value, contentFiles)
12898

12999
const appConfig = mergedFiles.find(item => item.path === StudioConfigFiles.appConfig)
130100
syncPreviewAppConfig(appConfig?.parsed as ParsedContent)
131101

132-
const tokensConfig = mergedFiles.find(item => item.path === StudioConfigFiles.tokensConfig)
133-
syncPreviewTokensConfig(tokensConfig?.parsed as ParsedContent)
134-
135102
requestRerender()
136103

137104
return true
@@ -211,7 +178,6 @@ export const useStudio = () => {
211178

212179
const requestRerender = async () => {
213180
if (contentConfig?.documentDriven) {
214-
// @ts-expect-error Update all cached pages
215181
const { pages } = callWithNuxt(nuxtApp, useContentState)
216182

217183
const contents = await Promise.all(Object.keys(pages.value).map(async (key) => {
@@ -235,7 +201,6 @@ export const useStudio = () => {
235201

236202
syncPreviewFiles,
237203
syncPreviewAppConfig,
238-
syncPreviewTokensConfig,
239204
requestPreviewSynchronization,
240205

241206
findContentWithId,
@@ -334,16 +299,6 @@ export const useStudio = () => {
334299
if (shouldRemoveAppConfig) {
335300
syncPreviewAppConfig(undefined)
336301
}
337-
338-
const tokensConfig = additions.find(item => item.path === StudioConfigFiles.tokensConfig)
339-
if (tokensConfig) {
340-
syncPreviewTokensConfig(tokensConfig?.parsed)
341-
}
342-
const shouldRemoveTokensConfig = deletions.find(item => item.path === StudioConfigFiles.tokensConfig)
343-
if (shouldRemoveTokensConfig) {
344-
syncPreviewTokensConfig(undefined)
345-
}
346-
break
347302
}
348303
}
349304
})
@@ -361,7 +316,6 @@ export const useStudio = () => {
361316
route.meta.studio_page_contentId = page?._id
362317
})
363318

364-
// @ts-expect-error custom hook
365319
nuxtApp.hook('nuxt-studio:preview:ready', () => {
366320
window.parent.postMessage({
367321
type: 'nuxt-studio:preview:ready',

Diff for: ‎src/runtime/server/routes/studio.ts

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import type { ComponentMeta } from 'vue-component-meta'
22
import { eventHandler } from 'h3'
3-
import { joinURL } from 'ufo'
43
import { useRuntimeConfig, useAppConfig } from '#imports'
54
// @ts-expect-error import does exist
65
import components from '#nuxt-component-meta/nitro'
@@ -30,7 +29,7 @@ export default eventHandler(async () => {
3029

3130
const appConfig = useAppConfig()
3231
const runtimeConfig = useRuntimeConfig()
33-
const { app, contentSchema, appConfigSchema, studio, content } = runtimeConfig
32+
const { contentSchema, appConfigSchema, studio, content } = runtimeConfig
3433
const { sources, ignores, locales, defaultLocale, highlight, navigation, documentDriven, experimental } = content as Record<string, unknown>
3534

3635
// Delete GitHub tokens for multiple source to avoid exposing them
@@ -46,15 +45,6 @@ export default eventHandler(async () => {
4645
dir,
4746
}
4847
})
49-
const hasPinceau = (runtimeConfig?.pinceau as Record<string, unknown>)?.studio
50-
let tokensConfig
51-
let tokensConfigSchema
52-
if (hasPinceau) {
53-
// @ts-expect-error Support for __pinceau_tokens_{schema|config}.json
54-
tokensConfig = await $fetch.native(joinURL(app.baseURL, '/__pinceau_tokens_config.json')).then(r => r.json())
55-
// @ts-expect-error Support for __pinceau_tokens_{schema|config}.json
56-
tokensConfigSchema = await $fetch.native(joinURL(app.baseURL, '/__pinceau_tokens_schema.json')).then(r => r.json())
57-
}
5848

5949
return {
6050
// Studio version
@@ -66,9 +56,6 @@ export default eventHandler(async () => {
6656
// app.config
6757
appConfigSchema: appConfigSchema || {},
6858
appConfig,
69-
// tokens.config
70-
tokensConfigSchema,
71-
tokensConfig,
7259
// @nuxt/content
7360
content: { sources: safeSources, ignores, locales, defaultLocale, highlight, navigation, documentDriven, experimental },
7461
// nuxt-component-meta

Diff for: ‎src/runtime/utils/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ export * from './files'
33
export const StudioConfigFiles = {
44
appConfig: 'app.config.ts',
55
nuxtConfig: 'nuxt.config.ts',
6-
tokensConfig: 'tokens.config.ts',
76
}
87

98
export const createSingleton = <T, Params extends Array<unknown>>(fn: () => T) => {

Diff for: ‎src/theme.ts

+12-82
Original file line numberDiff line numberDiff line change
@@ -3,146 +3,76 @@ import type { JSType, Schema, InputValue } from 'untyped'
33

44
export type ConfigInputsTypes =
55
| Exclude<JSType, 'symbol' | 'function' | 'any' | 'bigint'>
6-
| 'default' | 'icon' | 'file' | 'media' | 'component' | 'design-token'
7-
8-
export type DesignTokensInputsTypes = 'color' | 'size' | 'shadow' | 'size' | 'opacity' | 'font' | 'font-weight' | 'font-size' | 'letter-spacing'
6+
| 'default' | 'icon' | 'file' | 'media' | 'component'
97

108
export type PickerTypes = 'media-picker' | 'icon-picker'
119

12-
export type InputsTypes = DesignTokensInputsTypes | ConfigInputsTypes
13-
1410
export type PartialSchema = Pick<Schema, 'title' | 'description' | 'default' | 'required'> & { [key: string]: unknown }
1511

16-
const supportedFields: { [key in InputsTypes]: Schema } = {
12+
const supportedFields: { [key in ConfigInputsTypes]: Schema } = {
1713
/**
1814
* Raw types
1915
*/
20-
'default': {
16+
default: {
2117
type: 'string',
2218
tags: [
2319
'@studioInput string',
2420
],
2521
},
26-
'string': {
22+
string: {
2723
type: 'string',
2824
tags: [
2925
'@studioInput string',
3026
],
3127
},
32-
'number': {
28+
number: {
3329
type: 'number',
3430
tags: [
3531
'@studioInput number',
3632
],
3733
},
38-
'boolean': {
34+
boolean: {
3935
type: 'boolean',
4036
tags: [
4137
'@studioInput boolean',
4238
],
4339
},
44-
'array': {
40+
array: {
4541
type: 'array',
4642
tags: [
4743
'@studioInput array',
4844
],
4945
},
50-
'design-token': {
51-
type: 'string',
52-
tags: [
53-
'@studioInput design-token',
54-
],
55-
},
56-
'object': {
46+
object: {
5747
type: 'object',
5848
tags: [
5949
'@studioInput object',
6050
],
6151
},
62-
'file': {
52+
file: {
6353
type: 'string',
6454
tags: [
6555
'@studioInput file',
6656
],
6757
},
68-
'media': {
58+
media: {
6959
type: 'string',
7060
tags: [
7161
'@studioInput media',
7262
],
7363
},
74-
'component': {
64+
component: {
7565
type: 'string',
7666
tags: [
7767
'@studioInput component',
7868
],
7969
},
80-
'icon': {
70+
icon: {
8171
type: 'string',
8272
tags: [
8373
'@studioInput icon',
8474
],
8575
},
86-
87-
/**
88-
* Design Tokens
89-
*/
90-
'color': {
91-
type: 'string',
92-
tags: [
93-
'@studioInput design-token',
94-
'@studioInputTokenType color',
95-
],
96-
},
97-
'size': {
98-
type: 'string',
99-
tags: [
100-
'@studioInput design-token',
101-
'@studioInputTokenType size',
102-
],
103-
},
104-
'shadow': {
105-
type: 'string',
106-
tags: [
107-
'@studioInput design-token',
108-
'@studioInputTokenType shadow',
109-
],
110-
},
111-
'opacity': {
112-
type: 'string',
113-
tags: [
114-
'@studioInput design-token',
115-
'@studioInputTokenType opacity',
116-
],
117-
},
118-
'font': {
119-
type: 'string',
120-
tags: [
121-
'@studioInput design-token',
122-
'@studioInputTokenType font',
123-
],
124-
},
125-
'font-weight': {
126-
type: 'string',
127-
tags: [
128-
'@studioInput design-token',
129-
'@studioInputTokenType font-weight',
130-
],
131-
},
132-
'font-size': {
133-
type: 'string',
134-
tags: [
135-
'@studioInput design-token',
136-
'@studioInputTokenType size',
137-
],
138-
},
139-
'letter-spacing': {
140-
type: 'string',
141-
tags: [
142-
'@studioInput design-token',
143-
'@studioInputTokenType size',
144-
],
145-
},
14676
}
14777

14878
export type StudioFieldData =

0 commit comments

Comments
 (0)
Please sign in to comment.