Skip to content

Commit 393c418

Browse files
committed
#15: Starting to integrate luna-console
Modifying the vue-repl based on vuejs/repl#333
1 parent 61ebd39 commit 393c418

File tree

12 files changed

+235
-188
lines changed

12 files changed

+235
-188
lines changed

packages/vue-repl/package.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@
2626
"import": "./dist/codemirror-editor.js",
2727
"require": null
2828
},
29+
"./luna-console": {
30+
"types": "./dist/luna-console.d.ts",
31+
"import": "./dist/luna-console.js",
32+
"require": null
33+
},
2934
"./core": {
3035
"types": "./dist/core.d.ts",
3136
"import": "./dist/core.js",
@@ -117,6 +122,9 @@
117122
"volar-service-typescript": "0.0.65",
118123
"vscode-uri": "^3.1.0",
119124
"vue": "^3.5.18",
120-
"vue-tsc": "3.0.7-alpha.1"
125+
"vue-tsc": "3.0.7-alpha.1",
126+
"luna-console": "^1.3.5",
127+
"luna-data-grid": "^1.3.0",
128+
"luna-object-viewer": "^0.3.1"
121129
}
122130
}

packages/vue-repl/src/Repl.vue

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@ import Output from './output/Output.vue'
44
import { type Store, useStore } from './store'
55
import { computed, provide, toRefs, useTemplateRef } from 'vue'
66
import {
7+
type ConsoleComponentType,
8+
9+
710
type EditorComponentType,
811
injectKeyPreviewRef,
912
injectKeyProps,
@@ -15,13 +18,19 @@ export interface Props {
1518
theme?: 'dark' | 'light'
1619
previewTheme?: boolean
1720
editor: EditorComponentType
21+
console?: ConsoleComponentType
22+
23+
1824
store?: Store
1925
autoResize?: boolean
2026
showCompileOutput?: boolean
2127
showOpenSourceMap?: boolean
2228
showImportMap?: boolean
2329
showSsrOutput?: boolean
2430
showTsConfig?: boolean
31+
showConsole?: boolean
32+
33+
2534
clearConsole?: boolean
2635
layout?: 'horizontal' | 'vertical'
2736
layoutReverse?: boolean
@@ -59,6 +68,9 @@ const props = withDefaults(defineProps<Props>(), {
5968
showImportMap: true,
6069
showSsrOutput: false,
6170
showTsConfig: true,
71+
showConsole: false,
72+
73+
6274
clearConsole: true,
6375
layoutReverse: false,
6476
ssr: false,
@@ -72,6 +84,10 @@ if (!props.editor) {
7284
throw new Error('The "editor" prop is now required.')
7385
}
7486
87+
const consoleWrapper = computed<ConsoleComponentType>(
88+
() => props.console ?? (() => ({})),
89+
)
90+
7591
const outputRef = useTemplateRef('output')
7692
7793
props.store.init()
@@ -81,6 +97,9 @@ const outputSlotName = computed(() => (props.layoutReverse ? 'left' : 'right'))
8197
8298
provide(injectKeyProps, {
8399
...toRefs(props),
100+
console: consoleWrapper,
101+
102+
84103
autoSave,
85104
})
86105
provide(
@@ -108,6 +127,7 @@ defineExpose({ reload })
108127
<Output
109128
ref="output"
110129
:editor-component="editor"
130+
:console-component="consoleWrapper"
111131
:show-compile-output="props.showCompileOutput"
112132
:show-open-source-map="props.showOpenSourceMap"
113133
:show-ssr-output="props.showSsrOutput"

packages/vue-repl/src/output/Output.vue

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,25 @@
11
<script setup lang="ts">
22
import Preview from './Preview.vue'
3+
import SplitPane from '../SplitPane.vue'
34
import SsrOutput from './SsrOutput.vue'
45
import { computed, inject, useTemplateRef, watchEffect } from 'vue'
56
import {
7+
type ConsoleComponentType,
68
type EditorComponentType,
79
type OutputModes,
810
injectKeyProps,
911
} from '../types'
1012
1113
const props = defineProps<{
1214
editorComponent: EditorComponentType
15+
consoleComponent: ConsoleComponentType
1316
showCompileOutput?: boolean
1417
showOpenSourceMap?: boolean
1518
showSsrOutput?: boolean
1619
ssr: boolean
1720
}>()
1821
19-
const { store } = inject(injectKeyProps)!
22+
const { store, showConsole } = inject(injectKeyProps)!
2023
const previewRef = useTemplateRef('preview')
2124
const modes = computed(() => {
2225
const outputModes: OutputModes[] = ['preview']
@@ -51,6 +54,9 @@ function openSourceMap() {
5154
5255
function reload() {
5356
previewRef.value?.reload()
57+
store.value.clearConsole?.()
58+
59+
5460
}
5561
5662
defineExpose({ reload, previewRef })
@@ -69,6 +75,14 @@ defineExpose({ reload, previewRef })
6975
</div>
7076

7177
<div class="output-container">
78+
<SplitPane v-if="showConsole" layout="vertical">
79+
<template #left>
80+
<Preview ref="preview" :show="mode === 'preview'" :ssr="ssr" />
81+
</template>
82+
<template #right>
83+
<props.consoleComponent />
84+
</template>
85+
</SplitPane>
7286
<Preview ref="preview" :show="mode === 'preview'" :ssr="ssr" />
7387
<SsrOutput
7488
v-if="mode === 'ssr output'"

packages/vue-repl/src/output/Preview.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ defineExpose({
3030
:preview-options="previewOptions"
3131
:ssr="props.ssr"
3232
:clear-console="clearConsole"
33+
@log="store.executeLog"
3334
/>
3435
</template>

packages/vue-repl/src/output/Sandbox.vue

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import srcdoc from './srcdoc.html?raw'
1515
import { PreviewProxy } from './PreviewProxy'
1616
import { compileModulesForPreview } from './moduleCompiler'
1717
import type { Store } from '../store'
18-
import { injectKeyProps } from '../types'
18+
import { type LogLevel, type SandboxEmits, injectKeyProps } from '../types'
1919
import { getVersions, isVaporSupported } from '../import-map'
2020
2121
export interface SandboxProps {
@@ -47,6 +47,10 @@ const props = withDefaults(defineProps<SandboxProps>(), {
4747
previewOptions: () => ({}),
4848
autoStoreInit: true,
4949
})
50+
51+
const emit = defineEmits<SandboxEmits>()
52+
53+
5054
const { store, theme, clearConsole, previewOptions } = toRefs(props)
5155
5256
const keyProps = inject(injectKeyProps)
@@ -132,6 +136,9 @@ function createSandbox() {
132136
sandbox.srcdoc = sandboxSrc
133137
containerRef.value?.appendChild(sandbox)
134138
139+
const doLog = (logLevel: LogLevel, data?: any) =>
140+
emit('log', { logLevel, data })
141+
135142
proxy = new PreviewProxy(sandbox, {
136143
on_fetch_progress: (progress: any) => {
137144
// pending_imports = progress;
@@ -157,33 +164,33 @@ function createSandbox() {
157164
}
158165
runtimeError.value = 'Uncaught (in promise): ' + error.message
159166
},
160-
on_console: (log: any) => {
161-
if (log.duplicate) {
162-
return
163-
}
167+
on_console: (log: any) => {
168+
const maybeMsg = log.args[0]
164169
if (log.level === 'error') {
165-
if (log.args[0] instanceof Error) {
166-
runtimeError.value = log.args[0].message
167-
} else {
168-
runtimeError.value = log.args[0]
169-
}
170-
} else if (log.level === 'warn') {
171-
if (log.args[0].toString().includes('[Vue warn]')) {
172-
runtimeWarning.value = log.args
173-
.join('')
174-
.replace(/\[Vue warn\]:/, '')
175-
.trim()
170+
if (maybeMsg instanceof Error) {
171+
runtimeError.value = maybeMsg.message
172+
} else if (!maybeMsg?.startsWith('[vue-repl]')) {
173+
runtimeError.value = maybeMsg
176174
}
175+
} else if (
176+
log.level === 'warn' &&
177+
maybeMsg.toString().includes('[Vue warn]')
178+
) {
179+
runtimeWarning.value = log.args
180+
.join('')
181+
.replace(/\[Vue warn\]:/, '')
182+
.trim()
177183
}
184+
doLog(log.level || 'log', log.args)
178185
},
179186
on_console_group: (action: any) => {
180-
// group_logs(action.label, false);
187+
doLog('group', action.label)
181188
},
182189
on_console_group_end: () => {
183-
// ungroup_logs();
190+
doLog('groupEnd')
184191
},
185192
on_console_group_collapsed: (action: any) => {
186-
// group_logs(action.label, true);
193+
doLog('groupCollapsed', action.label)
187194
},
188195
})
189196
@@ -348,12 +355,7 @@ defineExpose({ reload, container: containerRef })
348355
</script>
349356

350357
<template>
351-
<div
352-
v-show="props.show"
353-
ref="container"
354-
class="iframe-container"
355-
:class="theme"
356-
/>
358+
<div v-show="show" ref="container" class="iframe-container" :class="theme" />
357359
<Message :err="(previewOptions?.showRuntimeError ?? true) && runtimeError" />
358360
<Message
359361
v-if="!runtimeError && (previewOptions?.showRuntimeWarning ?? true)"

0 commit comments

Comments
 (0)