Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ce/ve.ce.Node.js

raw symbols SCIP
1 /*!
2 * VisualEditor ContentEditable Node class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Generic ContentEditable node.
9 *
10 * @abstract
11 * @extends ve.ce.View
12 * @mixes ve.Node
13 *
14 * @constructor
15 * @param {ve.dm.Node} model Model to observe
16 * @param {Object} [config] Configuration options
17 */
18 ve.ce.Node = function VeCeNode() {
19 // Parent constructor
20 ve.ce.Node.super.apply( this, arguments );
21
22 // Mixin constructor
23 ve.Node.call( this );
24 };
25
26 /* Inheritance */
27
28 OO.inheritClass( ve.ce.Node, ve.ce.View );
29
30 OO.mixinClass( ve.ce.Node, ve.Node );
31
32 /* Static Members */
33
34 /**
35 * Whether Enter splits this node type.
36 *
37 * When the user presses Enter, we split the node they're in (if splittable), then split its parent
38 * if splittable, and continue traversing up the tree and stop at the first non-splittable node.
39 *
40 * @static
41 * @property {boolean}
42 * @inheritable
43 */
44 ve.ce.Node.static.splitOnEnter = false;
45
46 /**
47 * Whether Enter removes the empty last child of this node.
48 *
49 * Set true on the parent of a splitOnEnter node (e.g. a ListNode) to ensure that the last splittable
50 * child (e.g a ListItemNode) is removed when empty and enter is pressed.
51 *
52 * @static
53 * @property {boolean}
54 * @inheritable
55 */
56 ve.ce.Node.static.removeEmptyLastChildOnEnter = false;
57
58 /**
59 * Whether a node supports multiline input at all.
60 *
61 * If set to false, pressing Enter will not perform any splitting at all. If set to null, traverse
62 * up the tree until a boolean value is found.
63 *
64 * @static
65 * @property {boolean|null}
66 * @inheritable
67 */
68 ve.ce.Node.static.isMultiline = null;
69
70 /**
71 * Whether a node can take the cursor when its surface is focused
72 *
73 * When set to false, this will prevent the selection from being placed in
74 * any of the node's descendant ContentBranchNodes.
75 *
76 * @static
77 * @property {boolean}
78 * @inheritable
79 */
80 ve.ce.Node.static.autoFocus = true;
81
82 /**
83 * Whether a node traps the cursor when active, e.g. in table cells
84 *
85 * @static
86 * @property {boolean}
87 * @inheritable
88 */
89 ve.ce.Node.static.trapsCursor = false;
90
91 /* Static Methods */
92
93 /**
94 * Get a plain text description.
95 *
96 * @static
97 * @inheritable
98 * @param {ve.dm.Node} node Node model
99 * @return {string} Description of node
100 */
101 ve.ce.Node.static.getDescription = function () {
102 return '';
103 };
104
105 /* Methods */
106
107 // eslint-disable-next-line jsdoc/require-returns
108 /**
109 * @see ve.Node
110 */
111 ve.ce.Node.prototype.getChildNodeTypes = function () {
112 return this.model.getChildNodeTypes();
113 };
114
115 // eslint-disable-next-line jsdoc/require-returns
116 /**
117 * @see ve.Node
118 */
119 ve.ce.Node.prototype.getParentNodeTypes = function () {
120 return this.model.getParentNodeTypes();
121 };
122
123 // eslint-disable-next-line jsdoc/require-returns
124 /**
125 * @see ve.Node
126 */
127 ve.ce.Node.prototype.getSuggestedParentNodeTypes = function () {
128 return this.model.getSuggestedParentNodeTypes();
129 };
130
131 // eslint-disable-next-line jsdoc/require-returns
132 /**
133 * @see ve.Node
134 */
135 ve.ce.Node.prototype.canHaveChildren = function () {
136 return this.model.canHaveChildren();
137 };
138
139 // eslint-disable-next-line jsdoc/require-returns
140 /**
141 * @see ve.Node
142 */
143 ve.ce.Node.prototype.canHaveChildrenNotContent = function () {
144 return this.model.canHaveChildrenNotContent();
145 };
146
147 // eslint-disable-next-line jsdoc/require-returns
148 /**
149 * @see ve.Node
150 */
151 ve.ce.Node.prototype.isInternal = function () {
152 return this.model.isInternal();
153 };
154
155 // eslint-disable-next-line jsdoc/require-returns
156 /**
157 * @see ve.Node
158 */
159 ve.ce.Node.prototype.isMetaData = function () {
160 return this.model.isMetaData();
161 };
162
163 // eslint-disable-next-line jsdoc/require-returns
164 /**
165 * @see ve.Node
166 */
167 ve.ce.Node.prototype.isWrapped = function () {
168 return this.model.isWrapped();
169 };
170
171 // eslint-disable-next-line jsdoc/require-returns
172 /**
173 * @see ve.Node
174 */
175 ve.ce.Node.prototype.isUnwrappable = function () {
176 return this.model.isUnwrappable();
177 };
178
179 // eslint-disable-next-line jsdoc/require-returns
180 /**
181 * @see ve.Node
182 */
183 ve.ce.Node.prototype.canContainContent = function () {
184 return this.model.canContainContent();
185 };
186
187 // eslint-disable-next-line jsdoc/require-returns
188 /**
189 * @see ve.Node
190 */
191 ve.ce.Node.prototype.isContent = function () {
192 return this.model.isContent();
193 };
194
195 // eslint-disable-next-line jsdoc/require-returns
196 /**
197 * If this is set to true it should implement:
198 *
199 * setFocused( boolean val )
200 * boolean isFocused()
201 *
202 * @see ve.Node
203 */
204 ve.ce.Node.prototype.isFocusable = function () {
205 return this.model.isFocusable();
206 };
207
208 // eslint-disable-next-line jsdoc/require-returns
209 /**
210 * @see ve.Node
211 */
212 ve.ce.Node.prototype.isAlignable = function () {
213 return this.model.isAlignable();
214 };
215
216 // eslint-disable-next-line jsdoc/require-returns
217 /**
218 * @see ve.Node
219 */
220 ve.ce.Node.prototype.isCellable = function () {
221 return this.model.isCellable();
222 };
223
224 // eslint-disable-next-line jsdoc/require-returns
225 /**
226 * @see ve.Node
227 */
228 ve.ce.Node.prototype.isCellEditable = function () {
229 return this.model.isCellEditable();
230 };
231
232 // eslint-disable-next-line jsdoc/require-returns
233 /**
234 * @see ve.Node
235 */
236 ve.ce.Node.prototype.hasSignificantWhitespace = function () {
237 return this.model.hasSignificantWhitespace();
238 };
239
240 // eslint-disable-next-line jsdoc/require-returns
241 /**
242 * @see ve.Node
243 */
244 ve.ce.Node.prototype.handlesOwnChildren = function () {
245 return this.model.handlesOwnChildren();
246 };
247
248 // eslint-disable-next-line jsdoc/require-returns
249 /**
250 * @see ve.Node
251 */
252 ve.ce.Node.prototype.shouldIgnoreChildren = function () {
253 return this.model.shouldIgnoreChildren();
254 };
255
256 // eslint-disable-next-line jsdoc/require-returns
257 /**
258 * @see ve.Node
259 */
260 ve.ce.Node.prototype.getLength = function () {
261 return this.model.getLength();
262 };
263
264 // eslint-disable-next-line jsdoc/require-returns
265 /**
266 * @see ve.Node
267 */
268 ve.ce.Node.prototype.getOuterLength = function () {
269 return this.model.getOuterLength();
270 };
271
272 // eslint-disable-next-line jsdoc/require-returns
273 /**
274 * @see ve.Node
275 */
276 ve.ce.Node.prototype.getOffset = function () {
277 return this.model.getOffset();
278 };
279
280 /**
281 * Check if the node can be split.
282 *
283 * @return {boolean} Node can be split
284 */
285 ve.ce.Node.prototype.splitOnEnter = function () {
286 return this.constructor.static.splitOnEnter;
287 };
288
289 /**
290 * Check if the node removes its empty last child on 'enter'.
291 *
292 * @return {boolean} Node removes empty last child on 'enter'
293 */
294 ve.ce.Node.prototype.removeEmptyLastChildOnEnter = function () {
295 return this.constructor.static.removeEmptyLastChildOnEnter;
296 };
297
298 /**
299 * Check if the node is supports multiline input.
300 *
301 * Traverses upstream until a boolean value is found. If no value
302 * is found, reads the default from the surface.
303 *
304 * @return {boolean} Node supports multiline input
305 */
306 ve.ce.Node.prototype.isMultiline = function () {
307 const booleanNode = this.traverseUpstream( ( node ) => node.constructor.static.isMultiline === null );
308 if ( booleanNode ) {
309 return booleanNode.constructor.static.isMultiline;
310 } else {
311 return !this.root || this.getRoot().getSurface().getSurface().isMultiline();
312 }
313 };
314
315 /**
316 * Check if the node can take the cursor when its surface is focused
317 *
318 * @return {boolean} Node can be take the cursor
319 */
320 ve.ce.Node.prototype.autoFocus = function () {
321 return this.constructor.static.autoFocus;
322 };
323
324 /**
325 * Check if the node traps cursor when active
326 *
327 * @return {boolean} Node traps cursor
328 */
329 ve.ce.Node.prototype.trapsCursor = function () {
330 return this.constructor.static.trapsCursor;
331 };
332
333 /**
334 * Release all memory.
335 */
336 ve.ce.Node.prototype.destroy = function () {
337 this.parent = null;
338 this.root = null;
339 this.doc = null;
340
341 // Parent method
342 ve.ce.Node.super.prototype.destroy.call( this );
343 };
344
345 /**
346 * Get the model's HTML document
347 *
348 * @return {HTMLDocument} Model document
349 */
350 ve.ce.Node.prototype.getModelHtmlDocument = function () {
351 return this.model.getDocument() && this.model.getDocument().getHtmlDocument();
352 };