Skip to content
Merged
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: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,5 +65,10 @@
"engines": {
"node": ">=14",
"pnpm": ">=7"
},
"pnpm": {
"patchedDependencies": {
"@vue/repl@2.9.0": "patches/@vue__repl@2.9.0.patch"
}
}
}
1 change: 1 addition & 0 deletions packages/design-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@
"assert": "^2.0.0",
"buffer": "^6.0.3",
"cross-env": "^7.0.3",
"esbuild-plugin-copy": "^2.1.1",
"eslint": "^8.38.0",
"eslint-plugin-vue": "^8.0.0",
"fs-extra": "^10.1.0",
Expand Down
4 changes: 4 additions & 0 deletions packages/design-core/src/preview/src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
</template>

<script>
import { useDebugSwitch } from './preview/debugSwitch'
import Preview from './preview/Preview.vue'
import Toolbar from './Toolbar.vue'
import '@opentiny/tiny-engine-theme'
Expand All @@ -18,6 +19,9 @@ export default {
type: Boolean,
default: true
}
},
setup() {
useDebugSwitch()
}
}
</script>
Expand Down
17 changes: 16 additions & 1 deletion packages/design-core/src/preview/src/Toolbar.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<component :is="ToolbarMedia" :isCanvas="false" @setViewPort="setViewPort"></component>
</div>
<div class="toolbar-right">
<span><tiny-switch v-model="debugSwitch"></tiny-switch><span class="toolbar-button-text">调试模式</span></span>
<component :is="ChangeLang" :langChannel="previewLangChannel"></component>
</div>
</div>
Expand All @@ -15,9 +16,11 @@
<script lang="jsx">
import { defineAsyncComponent } from 'vue'
import { useBreadcrumb } from '@opentiny/tiny-engine-controller'
import { Switch as TinySwitch } from '@opentiny/vue'
import { getSearchParams } from './preview/http'
import { BROADCAST_CHANNEL } from '../src/preview/srcFiles/constant'
import addons from '@opentiny/tiny-engine-app-addons'
import { injectDebugSwitch } from './preview/debugSwitch'

const getToolbars = (pluginId) => {
return defineAsyncComponent(() =>
Expand All @@ -26,7 +29,11 @@ const getToolbars = (pluginId) => {
}

export default {
components: {
TinySwitch
},
setup() {
const debugSwitch = injectDebugSwitch()
const tools = ['breadcrumb', 'lang', 'media']
const [Breadcrumb, ChangeLang, ToolbarMedia] = tools.map(getToolbars)

Expand All @@ -47,7 +54,8 @@ export default {
Breadcrumb,
ChangeLang,
ToolbarMedia,
setViewPort
setViewPort,
debugSwitch
}
}
}
Expand All @@ -71,6 +79,13 @@ export default {
.toolbar-left,
.toolbar-right {
margin: 0 12px;
display: flex;
gap: 12px;
}
.toolbar-button-text {
color: #191919;
margin-left: 4px;
font-size: 12px;
}
:deep(.top-panel-breadcrumb) {
width: auto;
Expand Down
53 changes: 40 additions & 13 deletions packages/design-core/src/preview/src/preview/Preview.vue
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
<template>
<Repl
:editor="Monaco"
:store="store"
:sfcOptions="sfcOptions"
:showCompileOutput="false"
:showImportMap="false"
:clearConsole="false"
:autoResize="false"
/>
<div :class="['vue-repl-container', debugSwitch ? 'preview-debug-mode' : '']">
<Repl
:editor="editorComponent"
:store="store"
:sfcOptions="sfcOptions"
:showCompileOutput="false"
:showTsConfig="false"
:showImportMap="true"
:clearConsole="false"
:autoResize="false"
/>
</div>
</template>

<script>
import { defineComponent, computed, defineAsyncComponent } from 'vue'
import { Repl, ReplStore } from '@vue/repl'
import Monaco from '@vue/repl/monaco-editor'
import vueJsx from '@vue/babel-plugin-jsx'
import { transformSync } from '@babel/core'
import { Notify } from '@opentiny/vue'
Expand All @@ -21,8 +24,17 @@ import srcFiles from './srcFiles'
import generateMetaFiles, { processAppJsCode } from './generate'
import { getSearchParams, fetchCode, fetchMetaData } from './http'
import { PanelType, PreviewTips } from '../constant'
import { injectDebugSwitch } from './debugSwitch'
import '@vue/repl/style.css'

const Monaco = defineAsyncComponent(() => import('@vue/repl/monaco-editor')) // 异步组件实现懒加载,打开debug后再加载

const EmptyEditor = defineComponent({
setup() {
return () => null
}
})

const importNames = [
'createVNode',
'Fragment',
Expand Down Expand Up @@ -51,6 +63,8 @@ export default {
Repl
},
setup() {
const debugSwitch = injectDebugSwitch()
const editorComponent = computed(() => (debugSwitch?.value ? Monaco : EmptyEditor))
const store = new ReplStore()

const compiler = store.compiler
Expand Down Expand Up @@ -96,6 +110,7 @@ export default {
await store.setFiles(newFiles, mainFileName)
// 强制更新 codeSandbox
store.state.resetFlip = !store.state.resetFlip
store['initTsConfig']() // 触发获取组件d.ts方便调试
}

const addUtilsImportMap = (utils = []) => {
Expand Down Expand Up @@ -173,16 +188,16 @@ export default {
return {
store,
sfcOptions,
Monaco
editorComponent,
debugSwitch
}
}
}
</script>

<style lang="less">
.vue-repl {
width: 100vw;
height: 100vh;
height: 100%;

.split-pane {
.left {
Expand All @@ -206,4 +221,16 @@ export default {
}
}
}
.vue-repl-container {
height: calc(100vh - 48px);
&.preview-debug-mode .vue-repl .split-pane {
.left,
.right .tab-buttons {
display: block;
}
.right .output-container {
height: calc(100% - 38px);
}
}
}
</style>
10 changes: 10 additions & 0 deletions packages/design-core/src/preview/src/preview/debugSwitch.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ref, provide, inject } from 'vue'
export const debuggerSwitchTokenKey = Symbol('tiny-engine-preview-debug-switch')
export function useDebugSwitch() {
const debugSwitch = ref(false)
provide(debuggerSwitchTokenKey, debugSwitch)
return debugSwitch
}
export function injectDebugSwitch() {
return inject(debuggerSwitchTokenKey)
}
12 changes: 11 additions & 1 deletion packages/design-core/vite.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import vueJsx from '@vitejs/plugin-vue-jsx'
import nodeGlobalsPolyfillPlugin from '@esbuild-plugins/node-globals-polyfill'
import nodeModulesPolyfillPlugin from '@esbuild-plugins/node-modules-polyfill'
import nodePolyfill from 'rollup-plugin-polyfill-node'
import esbuildCopy from 'esbuild-plugin-copy'
import lowcodeConfig from './config/lowcode.config'
import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import { importmapPlugin } from './scripts/externalDeps'
Expand Down Expand Up @@ -79,7 +80,16 @@ const config = {
process: true,
buffer: true
}),
nodeModulesPolyfillPlugin()
nodeModulesPolyfillPlugin(),
esbuildCopy({
//@vue/repl monaco编辑器需要
resolveFrom: 'cwd',
assets: {
from: ['./node_modules/@vue/repl/dist/assets/*'], // worker.js文件以url形式引用不会被esbuild拉起,需要手动复制
to: ['./node_modules/.vite/assets'] // 开发态,js文件被缓存在.vite/deps,请求相对路径为.vite/assets
},
watch: true
})
]
}
},
Expand Down
50 changes: 50 additions & 0 deletions patches/@vue__repl@2.9.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
diff --git a/dist/chunks/MonacoEditor-KSgTEMrh.js b/dist/chunks/MonacoEditor-KSgTEMrh.js
index c9668cbf8c44ba3c816246b746127204839f8349..e893c59a432e53372c18aa2e70d7b7bb9fd666ba 100644
--- a/dist/chunks/MonacoEditor-KSgTEMrh.js
+++ b/dist/chunks/MonacoEditor-KSgTEMrh.js
@@ -1,5 +1,13 @@
import { watchEffect, defineComponent, ref, shallowRef, inject, computed, onMounted, nextTick, watch, onBeforeUnmount, openBlock, createElementBlock, createBlock } from 'vue';
import { c as commonjsGlobal, a as getAugmentedNamespace } from './_commonjsHelpers-9Q-OoQuc.js';
+function getWorkerURL(url){
+ if (typeof document !== 'undefined' && document.location && document.location.origin !== url.origin) {
+ return URL.createObjectURL(new Blob([`import '${url.href}'`], {
+ type: 'application/javascript'
+ }))
+ }
+ return url.href;
+}

/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
@@ -170640,7 +170648,7 @@ var languages;

function WorkerWrapper$1(options) {
return new Worker(
- ""+new URL('../assets/editor.worker-FXpxnIqv.js', import.meta.url).href+"",
+ ""+getWorkerURL(new URL('../assets/editor.worker-FXpxnIqv.js', import.meta.url))+"",
{
type: "module",
name: options?.name
@@ -172020,7 +172028,7 @@ function getOrCreateModel(uri, lang, value) {

function WorkerWrapper(options) {
return new Worker(
- ""+new URL('../assets/vue.worker-eqEbSb3e.js', import.meta.url).href+"",
+ ""+getWorkerURL(new URL('../assets/vue.worker-eqEbSb3e.js', import.meta.url))+"",
{
type: "module",
name: options?.name
diff --git a/dist/vue-repl.js b/dist/vue-repl.js
index 43bfd22a1a7d6f831e3f85228d809750317c4bfb..d5f5cb335533295c63e4cfa8aaa02770d16babca 100644
--- a/dist/vue-repl.js
+++ b/dist/vue-repl.js
@@ -528,7 +528,8 @@ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
"allow-popups",
"allow-same-origin",
"allow-scripts",
- "allow-top-navigation-by-user-activation"
+ "allow-top-navigation-by-user-activation",
+ "allow-downloads"
].join(" ")
);
const importMap = store.getImportMap();