Skip to content

Commit f035697

Browse files
committed
chore: edited playground to test highlighting
1 parent 710e4f3 commit f035697

File tree

6 files changed

+92
-67
lines changed

6 files changed

+92
-67
lines changed

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@
4444
"@codemirror/state": "6.5.2",
4545
"@codemirror/theme-one-dark": "^6.1.2",
4646
"@codemirror/view": "6.36.4",
47-
"@nuxt/kit": "^3.16.0"
47+
"@nuxt/kit": "^3.16.0",
48+
"codemirror": "^6.0.1"
4849
},
4950
"devDependencies": {
5051
"@nuxt/devtools": "^2.2.1",
@@ -65,5 +66,5 @@
6566
"codemirror",
6667
"vue"
6768
],
68-
"packageManager": "pnpm@10.6.3"
69+
"packageManager": "pnpm@10.6.5"
6970
}

playground/app.vue

Lines changed: 3 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,5 @@
1-
<script setup lang="ts">
2-
import { javascript } from '@codemirror/lang-javascript'
3-
import type { ViewUpdate } from '@codemirror/view'
4-
import { minimalSetup } from 'codemirror'
5-
import type { CodeMirrorRef, Statistics } from '../src/runtime/types/nuxt-codemirror'
6-
7-
const code = ref('console.log("Hello, CodeMirror!");')
8-
// const theme = ref<'light' | 'dark' | 'none'>('light')
9-
const codemirror = ref<CodeMirrorRef>()
10-
11-
const handleChange = (value: string, viewUpdate: ViewUpdate) => {
12-
console.log('Value changed:', value)
13-
console.log('View updated:', viewUpdate)
14-
}
15-
16-
const handleStatistics = (stats: Statistics) => {
17-
console.log('Editor statistics:', stats)
18-
}
19-
20-
const handleUpdate = (viewUpdate: ViewUpdate) => {
21-
console.log('Editor updated:', viewUpdate)
22-
}
23-
24-
onMounted(() => {
25-
if (codemirror.value) {
26-
console.log('Log editorRef', codemirror.value.editor)
27-
console.log('Log containerRef', codemirror.value.container)
28-
}
29-
30-
watchEffect(() => {
31-
if (codemirror.value) {
32-
console.log('Log StateRef', codemirror.value.state)
33-
console.log('Log viewRef', codemirror.value.view)
34-
}
35-
})
36-
})
37-
</script>
38-
39-
<!-- Adding minimalSetup in the extensions array makes highlighting work, while it should work with basicSetup == true -->
40-
411
<template>
42-
<NuxtCodeMirror
43-
ref="codemirror"
44-
v-model="code"
45-
style="width: 500px; height: 400px;"
46-
placeholder="Enter your code here..."
47-
:auto-focus="true"
48-
:editable="true"
49-
:extensions="[javascript()]"
50-
:basic-setup="true"
51-
:indent-with-tab="true"
52-
@on-change="handleChange"
53-
@statistics="handleStatistics"
54-
@on-update="handleUpdate"
55-
/>
56-
<div>{{ code }}</div>
57-
<input
58-
v-model="code"
59-
type="text"
60-
>
2+
<NuxtLayout>
3+
<NuxtPage />
4+
</NuxtLayout>
615
</template>

playground/nuxt.config.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
export default defineNuxtConfig({
22
modules: ['../src/module'],
3-
devtools: { enabled: true },
4-
compatibilityDate: '2024-07-24',
5-
nuxtCodemirror: {},
3+
devtools: { enabled: false },
64
devServer: {
75
port: 4000,
86
},
9-
})
7+
compatibilityDate: '2024-07-24',
8+
nuxtCodemirror: {},
9+
},
10+
)

playground/pages/index.vue

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<script setup lang="ts">
2+
import { javascript } from '@codemirror/lang-javascript'
3+
import type { ViewUpdate } from '@codemirror/view'
4+
// import { minimalSetup } from 'codemirror'
5+
6+
const code = ref('console.log("Hello, CodeMirror!");')
7+
// const theme = ref<'light' | 'dark' | 'none'>('light')
8+
const codemirror = ref()
9+
10+
const handleChange = (value: string, viewUpdate: ViewUpdate) => {
11+
console.log('Value changed:', value)
12+
console.log('View updated:', viewUpdate)
13+
}
14+
15+
const handleStatistics = (stats: any) => {
16+
console.log('Editor statistics:', stats)
17+
}
18+
19+
const handleUpdate = (viewUpdate: ViewUpdate) => {
20+
console.log('Editor updated:', viewUpdate)
21+
}
22+
23+
onMounted(() => {
24+
if (codemirror.value) {
25+
console.log('Log editorRef', codemirror.value.editor)
26+
console.log('Log containerRef', codemirror.value.container)
27+
}
28+
29+
watchEffect(() => {
30+
if (codemirror.value) {
31+
console.log('Log StateRef', codemirror.value.state)
32+
console.log('Log viewRef', codemirror.value.view)
33+
}
34+
})
35+
})
36+
</script>
37+
38+
<!-- Adding minimalSetup in the extensions array makes highlighting work, while it should work with basicSetup == true -->
39+
40+
<template>
41+
<div>
42+
<NuxtCodeMirror
43+
ref="codemirror"
44+
v-model="code"
45+
style="width: 500px; height: 400px;"
46+
placeholder="Enter your code here..."
47+
:auto-focus="true"
48+
:editable="true"
49+
:extensions="[javascript()]"
50+
:basic-setup="[true]"
51+
:indent-with-tab="true"
52+
@on-change="handleChange"
53+
@statistics="handleStatistics"
54+
@on-update="handleUpdate"
55+
/>
56+
<div>{{ code }}</div>
57+
<input
58+
v-model="code"
59+
type="text"
60+
>
61+
</div>
62+
</template>

pnpm-lock.yaml

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/runtime/getDefaultExtensions.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import {
3030
foldKeymap,
3131
} from '@codemirror/language'
3232
import { lintKeymap } from '@codemirror/lint'
33+
import { minimalSetup } from 'codemirror'
3334
import { defaultLightThemeOption } from './theme/light'
3435

3536
export * from '@codemirror/theme-one-dark'
@@ -73,7 +74,7 @@ export interface DefaultExtensionsOptions {
7374
editable?: boolean
7475
}
7576

76-
export const minimalSetup: Extension = (() => [
77+
export const minimalSetup2: Extension = (() => [
7778
highlightSpecialChars(),
7879
history(),
7980
drawSelection(),
@@ -154,7 +155,7 @@ export const getDefaultExtensions = (optios: DefaultExtensionsOptions = {}): Ext
154155
getExtensions.push(basicSetup())
155156
}
156157
else {
157-
getExtensions.unshift(minimalSetup)
158+
getExtensions.unshift(basicSetup(defaultBasicSetup))
158159
}
159160
}
160161
if (placeholderStr) {

0 commit comments

Comments
 (0)