Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【wip】feat: update vue repl for site #2730

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions examples/sites/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
"@opentiny/vue-icon": "workspace:~",
"@opentiny/vue-icon-multicolor": "workspace:~",
"@opentiny/vue-icon-saas": "workspace:~",
"@opentiny/vue-repl": "^1.1.2",
"@opentiny/vue-theme": "workspace:~",
"@opentiny/vue-theme-mobile": "workspace:~",
"@opentiny/vue-theme-saas": "workspace:~",
Expand All @@ -45,15 +44,15 @@
"@opentiny/vue-flowchart": "workspace:~",
"@opentiny/vue-vite-import": "~1.2.0",
"@unocss/reset": "0.38.2",
"@vue/repl": "^2.5.5",
"@vue/repl": "^4.4.2",
"@vueuse/head": "0.7.13",
"github-markdown-css": "~5.1.0",
"highlight.js": "^11.5.1",
"marked": "^4.3.0",
"prismjs": "^1.28.0",
"sortablejs": "1.15.0",
"tailwindcss": "^3.2.4",
"vue": "^3.4.31",
"vue": "^3.5.13",
"vue-i18n": "^9.1.10",
"vue-router": "4.1.5"
},
Expand Down
70 changes: 46 additions & 24 deletions examples/sites/playground/App.vue
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<script setup lang="jsx">
import { onMounted, reactive, nextTick } from 'vue'
import { Repl, useStore, File } from '@opentiny/vue-repl'
import '@opentiny/vue-repl/dist/style.css'
<script setup lang="tsx">
import { onMounted, reactive, nextTick, computed } from 'vue'
import type { SFCOptions } from '@vue/repl'
import { Repl, useStore, useVueImportMap, File } from '@vue/repl'

import Editor from '@vue/repl/codemirror-editor'
import { TinyButtonGroup, TinyButton, TinySelect, TinyOption, TinySwitch, Notify } from '@opentiny/vue'
Expand Down Expand Up @@ -113,21 +113,38 @@ const getTinyTheme = (version) => {
return tinyThemeMap[theme]
}

const { productionMode, vueVersion, importMap } = useVueImportMap({})

// enable experimental features
const sfcOptions = computed(
(): SFCOptions => ({
script: {
inlineTemplate: true,
propsDestructure: true
},
style: {
isProd: productionMode.value
},
template: {
compilerOptions: {
isCustomElement: (tag: string) => tag.startsWith('custom-')
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ensure that the custom element check function in compilerOptions is correctly handling all necessary custom elements. This function should be comprehensive to avoid rendering issues with custom components.

}
})
)

// 如果hash有效,它格式为: 3.8.4|eNqIVV9p.............
const hash = location.hash.slice(1)
const shareData = hash.split('|')

// eslint-disable-next-line new-cap
const store = new useStore({
serializedState: shareData.length === 2 ? shareData[1] : '',
showOutput: true,
outputMode: 'preview',
versions: {
vue: '3.2.47',
opentiny: '3.9.1',
typescript: '5.1.3'
}
})
const store = useStore(
{
builtinImportMap: importMap,
vueVersion,
sfcOptions
},
hash
)

// repl 属性
const state = reactive({
Expand Down Expand Up @@ -182,7 +199,7 @@ function selectVersion(version) {

function versionChange(version) {
const importMap = createImportMap(version)
store.state.files['import-map.json'] = new File('', JSON.stringify(importMap))
store.files['import-map.json'] = new File('', JSON.stringify(importMap))
insertStyleDom(version)
}

Expand Down Expand Up @@ -236,8 +253,8 @@ const getDemoCode = async ({ cmpId, fileName, apiMode, mode }) => {

const loadFileCode = async ({ cmpId, fileName, apiMode, mode }) => {
const code = await getDemoCode({ cmpId, fileName, apiMode, mode })
store.state.mainFile = fileName
store.state.activeFile = fileName
store.mainFile = fileName
store.activeFilename = fileName
store.addFile(new File(fileName, code, false))
versionChange(latestVersion)
}
Expand All @@ -246,16 +263,16 @@ onMounted(() => {
setTinyDesign()
// 初始加载,有分享则加载分享,否则加载默认版本的默认文件
if (shareData.length === 2) {
const demoFile = Object.values(store.state.files).find(
const demoFile = Object.values(store.files.value).find(
(file) =>
file.filename.startsWith('src/') &&
file.filename.endsWith('.vue') &&
file.filename !== 'src/App.vue' &&
file.filename !== 'src/PlaygroundMain.vue'
)

store.state.mainFile = demoFile.filename
store.state.activeFile = demoFile
store.mainFile = demoFile.filename
store.activeFilename = demoFile.filename
versionChange(shareData[0])
} else {
const fileName = searchObj.get('fileName')
Expand Down Expand Up @@ -324,12 +341,17 @@ function share() {
</div>
<Repl
:editor="Editor"
@keydown.ctrl.s.prevent
@keydown.meta.s.prevent
:editorOptions="{ autoSaveText: false }"
:store="store"
:preview-options="state.previewOptions"
:clear-console="false"
:layout="state.layout"
:layout-reverse="state.layoutReverse"
></Repl>
:showCompileOutput="true"
:autoResize="true"
:clearConsole="false"
:preview-options="state.previewOptions"
/>
</template>

<style>
Expand Down
Loading
Loading