Skip to content

Commit 196874b

Browse files
committed
Merge branch 'main' into chore/better-content-integration
2 parents 01cd2ab + a36ad89 commit 196874b

File tree

10 files changed

+81
-14
lines changed

10 files changed

+81
-14
lines changed

src/app/src/assets/css/main.css

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@import "@nuxt/ui";
33
@plugin "@tailwindcss/typography";
44

5-
@source "@farnabaz/mdc-editor";
65
@source "../../**";
76

87
@source inline('ring-orange-200 hover:ring-orange-300 hover:dark:ring-orange-700');

src/app/src/components/AppFooter.vue

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,14 @@ const { ui, host } = useStudio()
66
77
const uiConfig = ui.config
88
const user = host.user.get()
9+
10+
const showTechnicalMode = computed({
11+
get: () => uiConfig.value.showTechnicalMode,
12+
set: (value) => {
13+
uiConfig.value.showTechnicalMode = value
14+
},
15+
})
16+
917
const repositoryUrl = computed(() => {
1018
switch (host.repository.provider) {
1119
case 'github':
@@ -18,14 +26,17 @@ const repositoryUrl = computed(() => {
1826
})
1927
2028
const userMenuItems = computed(() => [
21-
repositoryUrl.value
22-
? [{
29+
[{
30+
slot: 'view-mode' as const,
31+
}, repositoryUrl.value
32+
? {
2333
label: `${host.repository.owner}/${host.repository.repo}`,
2434
icon: 'i-simple-icons:github',
2535
to: repositoryUrl.value,
2636
target: '_blank',
27-
}]
28-
: [],
37+
}
38+
: undefined
39+
].filter(Boolean),
2940
[{
3041
label: 'Sign out',
3142
icon: 'i-lucide-log-out',
@@ -35,7 +46,7 @@ const userMenuItems = computed(() => [
3546
})
3647
},
3748
}],
38-
].filter(group => group.length > 0))
49+
])
3950
</script>
4051

4152
<template>
@@ -47,6 +58,19 @@ const userMenuItems = computed(() => [
4758
:items="userMenuItems"
4859
:ui="{ content: 'w-full' }"
4960
>
61+
<template #view-mode>
62+
<div
63+
class="w-full"
64+
@click.stop
65+
>
66+
<USwitch
67+
v-model="showTechnicalMode"
68+
label="Technical view"
69+
size="xs"
70+
:ui="{ root: 'w-full flex-row-reverse justify-between', wrapper: 'ms-0' }"
71+
/>
72+
</div>
73+
</template>
5074
<UButton
5175
color="neutral"
5276
variant="ghost"

src/app/src/composables/useUI.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { createSharedComposable, useStorage } from '@vueuse/core'
22
import { ref, watch } from 'vue'
3-
import { type StudioHost, StudioFeature } from '../types'
3+
import { type StudioHost, StudioFeature, type UIConfig } from '../types'
44
import { useSidebar } from './useSidebar'
55

66
export const useUI = createSharedComposable((host: StudioHost) => {
7-
const config = useStorage('studio-ui-config', { syncEditorAndRoute: true })
7+
const config = useStorage<UIConfig>('studio-ui-config', { syncEditorAndRoute: true, showTechnicalMode: false })
88
const sidebar = useSidebar()
99
const isOpen = ref(false)
1010
const currentPanel = ref<StudioFeature | null>(null)

src/app/src/main.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import styles from './assets/css/main.css?inline'
77

88
import { createHead } from '@unhead/vue/client'
99
import { generateColors, tailwindColors } from './utils/colors'
10+
import { refineTailwindStyles } from './utils/styles.ts'
1011

1112
import App from './app.vue'
1213
import Content from './pages/content.vue'
@@ -53,9 +54,7 @@ if (typeof window !== 'undefined' && 'customElements' in window) {
5354
styles: [
5455
tailwindColors,
5556
generateColors(),
56-
styles.replace(/:root/g, ':host')
57-
.replace(/([^-])html/g, '$1:host')
58-
.replace(/([^-])body/g, '$1:host'),
57+
refineTailwindStyles(styles),
5958
],
6059
},
6160
) as VueElementConstructor

src/app/src/pages/content.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { computed } from 'vue'
33
import { useStudio } from '../composables/useStudio'
44
import { StudioItemActionId, TreeStatus } from '../types'
55
6-
const { documentTree, context } = useStudio()
6+
const { documentTree, context, ui } = useStudio()
77
88
const folderTree = computed(() => (documentTree.current.value || []).filter(f => f.type === 'directory'))
99
const fileTree = computed(() => (documentTree.current.value || []).filter(f => f.type === 'file'))
@@ -35,6 +35,12 @@ const showFileForm = computed(() => {
3535
:draft-item="documentTree.draft.current.value!"
3636
:read-only="documentTree.currentItem.value.status === TreeStatus.Deleted"
3737
/>
38+
<div
39+
v-else-if="ui.config.value.showTechnicalMode"
40+
class="flex flex-col p-4"
41+
>
42+
Developer tree
43+
</div>
3844
<div
3945
v-else
4046
class="flex flex-col p-4"

src/app/src/types/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export * from './git'
1515
export * from './context'
1616
export * from './content'
1717
export * from './component'
18+
export * from './ui'
1819

1920
export interface StudioHost {
2021
meta: {

src/app/src/types/ui.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export interface UIConfig {
2+
syncEditorAndRoute: boolean
3+
showTechnicalMode: boolean
4+
}

src/app/src/utils/styles.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
export function refineTailwindStyles(styles: string) {
2+
styles = convertPropertyToVar(styles)
3+
// Replace :root, html, and body with :host
4+
styles = styles.replace(/:root/g, ':host')
5+
.replace(/([^-])html/g, '$1:host')
6+
.replace(/([^-])body/g, '$1:host')
7+
8+
return styles
9+
}
10+
11+
export function convertPropertyToVar(cssText: string) {
12+
const propertyRegex = /@property\s+(--[\w-]+)\s*\{([^}]*)\}/g
13+
const cssVars: string[] = []
14+
15+
const result = cssText.replace(propertyRegex, (_, propertyName, propertyContent) => {
16+
const initialValueMatch = propertyContent.match(/initial-value\s*:([^;]+)(;|$)/)
17+
18+
if (initialValueMatch) {
19+
let initialValue = initialValueMatch[1].trim()
20+
21+
if (propertyContent.includes('<length>') && !initialValue.endsWith('px')) {
22+
initialValue = `${initialValue}px`
23+
}
24+
25+
cssVars.push(`${propertyName}: ${initialValue};`)
26+
}
27+
28+
return ''
29+
})
30+
31+
const cssVarsBlock = cssVars.length > 0 ? `:host {\n ${cssVars.join('\n ')}\n}` : ''
32+
33+
return cssVarsBlock + (cssVarsBlock && result.trim() ? '\n\n' : '') + result.trim()
34+
}

src/module/src/runtime/utils/content.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { parseMarkdown } from '@nuxtjs/mdc/runtime'
33
import { omit } from './object'
44
import type { DatabaseItem } from 'nuxt-studio/app'
55
import { compressTree } from '@nuxt/content/runtime'
6-
import { ContentFileExtension } from '../../../../app/src/types'
6+
import { ContentFileExtension } from 'nuxt-studio/app'
77
import { parseFrontMatter } from 'remark-mdc'
88
import { destr } from 'destr'
99
import { visit } from 'unist-util-visit'

src/module/src/runtime/utils/serialization.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const yamlToJson = (data: string) => {
66
new yaml.Type('tag:yaml.org,2002:timestamp', {
77
kind: 'scalar',
88
resolve: () => false,
9-
construct: data => data,
9+
construct: (data: unknown) => data,
1010
}),
1111
],
1212
})

0 commit comments

Comments
 (0)