-
-
Notifications
You must be signed in to change notification settings - Fork 16
/
state.ts
41 lines (38 loc) · 1.29 KB
/
state.ts
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
import { defaultKeymap, history, historyKeymap } from '@codemirror/commands'
import type { EditorSelection } from '@codemirror/state'
import { EditorState } from '@codemirror/state'
import { keymap } from '@codemirror/view'
import { buildVendors } from '/src/extensions'
import type * as Ink from '/types/ink'
import type InkInternal from '/types/internal'
import { toCodeMirror } from './adapters/selections'
import { blockquote } from './extensions/blockquote'
import { code } from './extensions/code'
import { ink } from './extensions/ink'
import { lineWrapping } from './extensions/line_wrapping'
import { theme } from './extensions/theme'
const toVendorSelection = (selections: Ink.Editor.Selection[]): EditorSelection | undefined => {
if (selections.length > 0) {
return toCodeMirror(selections)
}
}
export const createState = ([state, setState]: InkInternal.Store): InkInternal.Vendor.State => {
const { selections } = state().options
return EditorState.create({
doc: state().options.doc,
selection: toVendorSelection(selections),
extensions: [
keymap.of([
...defaultKeymap,
...historyKeymap,
]),
blockquote(),
code(),
history(),
ink(),
lineWrapping(),
theme(),
...buildVendors([state, setState]),
],
})
}