generated from qq15725/starter-ts
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathindex.html
More file actions
54 lines (48 loc) · 1.25 KB
/
index.html
File metadata and controls
54 lines (48 loc) · 1.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Playground</title>
<script src="https://unpkg.com/vue@3"></script>
</head>
<body>
<div id="app"></div>
<script type="module">
const { createApp, h, nextTick, ref } = window.Vue
import { DOMSelectionChange, EditorCore, render, selectionChange } from './src'
createApp({
setup() {
const editor = new EditorCore([
{
children: [
{ text: '' },
],
},
])
const hasSelection = ref(false)
const nodes = ref([])
editor.on('change', async () => {
nodes.value = [...editor.children]
await nextTick()
editor.run(() => selectionChange(editor))
hasSelection.value = Boolean(editor.selection)
})
document.addEventListener('selectionchange', () => {
editor.run(() => DOMSelectionChange(editor))
})
return () => {
return [
editor.run(() => render(
editor,
{ placeholder: '请输入', style: { width: '300px', minHeight: '100px' } },
hasSelection.value,
h,
)),
h('pre', JSON.stringify(nodes.value, null, 2)),
]
}
},
}).mount('#app')
</script>
</body>
</html>