/
create-editor.ts
190 lines (185 loc) · 5.77 KB
/
create-editor.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import {
addMark,
deleteFragment,
Editor,
getDirtyPaths,
getFragment,
insertBreak,
insertFragment,
insertNode,
insertSoftBreak,
insertText,
normalizeNode,
removeMark,
shouldNormalize,
} from './'
import { apply } from './core'
import {
above,
after,
before,
deleteBackward,
deleteForward,
edges,
elementReadOnly,
end,
first,
fragment,
getVoid,
hasBlocks,
hasInlines,
hasPath,
hasTexts,
isBlock,
isEdge,
isEmpty,
isEnd,
isNormalizing,
isStart,
last,
leaf,
levels,
marks,
next,
node,
nodes,
normalize,
parent,
path,
pathRef,
pathRefs,
point,
pointRef,
pointRefs,
positions,
previous,
range,
rangeRef,
rangeRefs,
setNormalizing,
shouldMergeNodesRemovePrevNode,
start,
string,
unhangRange,
withoutNormalizing,
} from './editor'
import { deleteText } from './transforms-text'
import {
collapse,
deselect,
move,
select,
setPoint,
setSelection,
} from './transforms-selection'
import {
insertNodes,
liftNodes,
mergeNodes,
moveNodes,
removeNodes,
setNodes,
splitNodes,
unsetNodes,
unwrapNodes,
wrapNodes,
} from './transforms-node'
/**
* Create a new Slate `Editor` object.
*/
export const createEditor = (): Editor => {
const editor: Editor = {
children: [],
operations: [],
selection: null,
marks: null,
isElementReadOnly: () => false,
isInline: () => false,
isSelectable: () => true,
isVoid: () => false,
markableVoid: () => false,
onChange: () => {},
// Core
apply: (...args) => apply(editor, ...args),
// Editor
addMark: (...args) => addMark(editor, ...args),
deleteBackward: (...args) => deleteBackward(editor, ...args),
deleteForward: (...args) => deleteForward(editor, ...args),
deleteFragment: (...args) => deleteFragment(editor, ...args),
getFragment: (...args) => getFragment(editor, ...args),
insertBreak: (...args) => insertBreak(editor, ...args),
insertSoftBreak: (...args) => insertSoftBreak(editor, ...args),
insertFragment: (...args) => insertFragment(editor, ...args),
insertNode: (...args) => insertNode(editor, ...args),
insertText: (...args) => insertText(editor, ...args),
normalizeNode: (...args) => normalizeNode(editor, ...args),
removeMark: (...args) => removeMark(editor, ...args),
getDirtyPaths: (...args) => getDirtyPaths(editor, ...args),
shouldNormalize: (...args) => shouldNormalize(editor, ...args),
// Editor interface
above: (...args) => above(editor, ...args),
after: (...args) => after(editor, ...args),
before: (...args) => before(editor, ...args),
collapse: (...args) => collapse(editor, ...args),
delete: (...args) => deleteText(editor, ...args),
deselect: (...args) => deselect(editor, ...args),
edges: (...args) => edges(editor, ...args),
elementReadOnly: (...args) => elementReadOnly(editor, ...args),
end: (...args) => end(editor, ...args),
first: (...args) => first(editor, ...args),
fragment: (...args) => fragment(editor, ...args),
getMarks: (...args) => marks(editor, ...args),
hasBlocks: (...args) => hasBlocks(editor, ...args),
hasInlines: (...args) => hasInlines(editor, ...args),
hasPath: (...args) => hasPath(editor, ...args),
hasTexts: (...args) => hasTexts(editor, ...args),
insertNodes: (...args) => insertNodes(editor, ...args),
isBlock: (...args) => isBlock(editor, ...args),
isEdge: (...args) => isEdge(editor, ...args),
isEmpty: (...args) => isEmpty(editor, ...args),
isEnd: (...args) => isEnd(editor, ...args),
isNormalizing: (...args) => isNormalizing(editor, ...args),
isStart: (...args) => isStart(editor, ...args),
last: (...args) => last(editor, ...args),
leaf: (...args) => leaf(editor, ...args),
levels: (...args) => levels(editor, ...args),
liftNodes: (...args) => liftNodes(editor, ...args),
mergeNodes: (...args) => mergeNodes(editor, ...args),
move: (...args) => move(editor, ...args),
moveNodes: (...args) => moveNodes(editor, ...args),
next: (...args) => next(editor, ...args),
node: (...args) => node(editor, ...args),
nodes: (...args) => nodes(editor, ...args),
normalize: (...args) => normalize(editor, ...args),
parent: (...args) => parent(editor, ...args),
path: (...args) => path(editor, ...args),
pathRef: (...args) => pathRef(editor, ...args),
pathRefs: (...args) => pathRefs(editor, ...args),
point: (...args) => point(editor, ...args),
pointRef: (...args) => pointRef(editor, ...args),
pointRefs: (...args) => pointRefs(editor, ...args),
positions: (...args) => positions(editor, ...args),
previous: (...args) => previous(editor, ...args),
range: (...args) => range(editor, ...args),
rangeRef: (...args) => rangeRef(editor, ...args),
rangeRefs: (...args) => rangeRefs(editor, ...args),
removeNodes: (...args) => removeNodes(editor, ...args),
select: (...args) => select(editor, ...args),
setNodes: (...args) => setNodes(editor, ...args),
setNormalizing: (...args) => setNormalizing(editor, ...args),
setPoint: (...args) => setPoint(editor, ...args),
setSelection: (...args) => setSelection(editor, ...args),
splitNodes: (...args) => splitNodes(editor, ...args),
start: (...args) => start(editor, ...args),
string: (...args) => string(editor, ...args),
unhangRange: (...args) => unhangRange(editor, ...args),
unsetNodes: (...args) => unsetNodes(editor, ...args),
unwrapNodes: (...args) => unwrapNodes(editor, ...args),
void: (...args) => getVoid(editor, ...args),
withoutNormalizing: (...args) => withoutNormalizing(editor, ...args),
wrapNodes: (...args) => wrapNodes(editor, ...args),
shouldMergeNodesRemovePrevNode: (...args) =>
shouldMergeNodesRemovePrevNode(editor, ...args),
}
return editor
}