Debian Codegraph @

extensions/VisualEditor/lib/ve/src/ui/ve.ui.NodeWindow.js

raw symbols SCIP
1 /*!
2 * VisualEditor user interface NodeWindow class.
3 *
4 * @copyright See AUTHORS.txt
5 */
6
7 /**
8 * Mixin for window for working with a node.
9 *
10 * Conceptually this extends a FragmentWindow, but as this and FragmentWindow
11 * are both are mixins, we don't need to set up actual inheritance here,
12 * that is handled by the concrete classes NodeDialog & NodeInspector. T264690
13 *
14 * @class
15 * @abstract
16 *
17 * @constructor
18 * @param {Object} [config] Configuration options
19 */
20 ve.ui.NodeWindow = function VeUiNodeWindow() {
21 // Properties
22 this.selectedNode = null;
23 };
24
25 /* Inheritance */
26
27 OO.initClass( ve.ui.NodeWindow );
28
29 /* Static Properties */
30
31 /**
32 * Node classes compatible with this dialog.
33 *
34 * @static
35 * @property {Function}
36 * @inheritable
37 */
38 ve.ui.NodeWindow.static.modelClasses = [];
39
40 /* Methods */
41
42 /**
43 * Check if the current node is editable by this window.
44 *
45 * @localdoc Returns true if the node being edited selects at least one model,
46 *
47 * @return {boolean} Node is editable by this window
48 */
49 ve.ui.NodeWindow.prototype.isEditing = function () {
50 return !!this.getSelectedNode();
51 };
52
53 /**
54 * Get the selected node.
55 *
56 * Should only be called after setup and before teardown.
57 * If no node is selected or the selected node is incompatible, null will be returned.
58 *
59 * @param {Object} [data] Window opening data
60 * @return {ve.dm.Node|null} Selected node
61 */
62 ve.ui.NodeWindow.prototype.getSelectedNode = function () {
63 const modelClasses = this.constructor.static.modelClasses,
64 selectedNode = this.getFragment().getSelectedNode();
65
66 if (
67 selectedNode &&
68 modelClasses.some( ( modelClass ) => selectedNode instanceof modelClass )
69 ) {
70 return selectedNode;
71 }
72 return null;
73 };
74
75 ve.ui.NodeWindow.prototype.getSetupProcess = function ( data, process ) {
76 data = data || {};
77 return process.next( () => {
78 this.selectedNode = this.getSelectedNode( data );
79 } );
80 };
81
82 ve.ui.NodeWindow.prototype.getTeardownProcess = function ( data, process ) {
83 data = data || {};
84 return process.next( () => {
85 this.selectedNode = null;
86 } );
87 };