Skip to content

Commit

Permalink
fix: ensure imported editor can be passed as prop without type error
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed Jun 22, 2023
1 parent 4b5ecc2 commit 414b0e6
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 23 deletions.
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,19 @@
"types": "dist/repl.d.ts",
"exports": {
".": {
"types": "./dist/repl.d.ts",
"import": "./dist/vue-repl.js",
"require": "./dist/ssr-stub.js",
"types": "./dist/repl.d.ts"
"require": "./dist/ssr-stub.js"
},
"./monaco-editor": {
"types": "./dist/editor-types.d.ts",
"import": "./dist/monaco-editor.js",
"require": null,
"types": "./dist/MonacoEditor.vue.d.ts"
"require": null
},
"./codemirror-editor": {
"types": "./dist/editor-types.d.ts",
"import": "./dist/codemirror-editor.js",
"require": null,
"types": "./dist/CodeMirrorEditor.vue.d.ts"
"require": null
},
"./style.css": "./dist/style.css",
"./dist/style.css": "./dist/style.css"
Expand Down
12 changes: 1 addition & 11 deletions scripts/cleanup.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
// This file is executed from npm script with project root as cwd.
import fs from 'node:fs'

fs.renameSync(
'dist/src/editor/CodeMirrorEditor.vue.d.ts',
'dist/CodeMirrorEditor.vue.d.ts'
)

fs.renameSync(
'dist/src/editor/MonacoEditor.vue.d.ts',
'dist/MonacoEditor.vue.d.ts'
)

fs.renameSync('dist/src/editor/types.d.ts', 'dist/types.d.ts')
fs.renameSync('dist/src/editor/types.d.ts', 'dist/editor-types.d.ts')

fs.rmSync('dist/src', { recursive: true })
2 changes: 1 addition & 1 deletion src/Repl.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import SplitPane from './SplitPane.vue'
import Output from './output/Output.vue'
import { Store, ReplStore, SFCOptions } from './store'
import { provide, toRef } from 'vue'
import { EditorComponentType } from './editor/types'
import type EditorComponentType from './editor/types'
import EditorContainer from './editor/EditorContainer.vue'
export interface Props {
Expand Down
2 changes: 1 addition & 1 deletion src/editor/EditorContainer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Message from '../Message.vue'
import { debounce } from '../utils'
import { inject } from 'vue'
import { Store } from '../store'
import { EditorComponentType } from './types'
import type EditorComponentType from './types'
const props = defineProps<{
editorComponent: EditorComponentType
Expand Down
4 changes: 3 additions & 1 deletion src/editor/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ interface EditorEmits {
(e: 'change', code: string): void
}

export type EditorComponentType = Component<EditorProps, EditorEmits> & {
type EditorComponentType = Component<EditorProps, EditorEmits> & {
editorType: 'monaco' | 'codemirror'
}

export default EditorComponentType
2 changes: 1 addition & 1 deletion src/output/Output.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import Preview from './Preview.vue'
import { Store } from '../store'
import { inject, ref, computed } from 'vue'
import type { OutputModes } from './types'
import { EditorComponentType } from '../editor/types'
import type EditorComponentType from '../editor/types'
const props = defineProps<{
editorComponent: EditorComponentType
Expand Down
4 changes: 2 additions & 2 deletions test/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { createApp, h, watchEffect } from 'vue'
import { Repl, ReplStore } from '../src'
import MonacoEditor from '../src/editor/MonacoEditor.vue'
// import CodeMirrorEditor from '../src/editor/CodeMirrorEditor.vue'
import EditorComponentType from '../src/editor/types'
;(window as any).process = { env: {} }

const App = {
Expand Down Expand Up @@ -37,10 +38,9 @@ const App = {
// store.setVueVersion('3.2.8')

return () =>
//@ts-ignore
h(Repl, {
store,
editor: MonacoEditor,
editor: MonacoEditor as any as EditorComponentType,
// layout: 'vertical',
ssr: true,
sfcOptions: {
Expand Down

0 comments on commit 414b0e6

Please sign in to comment.