-
Notifications
You must be signed in to change notification settings - Fork 0
/
WebGMEReactVizPanel.js
179 lines (151 loc) · 6.51 KB
/
WebGMEReactVizPanel.js
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
/*globals define, _, WebGMEGlobal*/
/**
* Generated by VisualizerGenerator 1.7.0 from webgme on Wed Apr 04 2018 16:27:16 GMT-0500 (Central Daylight Time).
*/
define([
'js/Constants',
'js/PanelBase/PanelBase',
'js/PanelManager/IActivePanel',
'common/util/guid',
'./reactViz.bundle',
'css!./reactViz.bundle.css'
], function (CONSTANTS,
PanelBase,
IActivePanel,
guid,
reactViz) {
'use strict';
const WebGMEReactPanels = {};
function WebGMEReactVizPanel(layoutManager, params) {
const options = {};
// set properties from options
options[PanelBase.OPTIONS.LOGGER_INSTANCE_NAME] = 'WebGMEReactVizPanel';
options[PanelBase.OPTIONS.FLOATING_TITLE] = true;
// call parent's constructor
PanelBase.apply(this, [options, layoutManager]);
WebGMEGlobal.WebGMEReactPanels = WebGMEReactPanels;
this.client = params.client;
this.activeNode = null;
this.appId = `react-viz-id-${guid()}`;
// initialize UI
this.initialize();
this.logger.debug('ctor finished');
}
// inherit from PanelBaseWithHeader
_.extend(WebGMEReactVizPanel.prototype, PanelBase.prototype);
_.extend(WebGMEReactVizPanel.prototype, IActivePanel.prototype);
WebGMEReactVizPanel.prototype.initialize = function initialize() {
this.$el.prop('id', this.appId);
this.$el.css({
width: '100%',
height: '100%',
});
this.activeNode = WebGMEGlobal.State.getActiveObject();
this.stateMediator = {
// Called by react component
setActiveNode: (activeNode) => {
if (typeof activeNode === 'string' && this.activeNode !== activeNode) {
this.activeNode = activeNode;
WebGMEGlobal.State.registerActiveObject(activeNode);
}
},
setActiveSelection: (activeSelection) => {
WebGMEGlobal.State.registerActiveSelection(activeSelection);
},
// Overwritten by the react-component
onActiveNodeChange: (activeNode) => {
console.warn('onActiveNodeChange not overwritten by react component..', activeNode);
},
onActiveSelectionChange: (activeSelection) => {
console.warn('onActiveSelectionChange not overwritten by react component..', activeSelection);
},
// Life-cycle placeholders.
onActivate: () => {
console.warn('onActivate not overwritten by react component');
},
onDeactivate: () => {
console.warn('onDeactivate not overwritten by react component');
},
onDestroy: () => {
console.warn('onDestroy not overwritten by react component');
},
onReadOnlyChanged: (isReadonly) => {
console.warn('onReadOnlyChanged not overwritten by react component', isReadonly);
},
onResize: (width, height) => {
console.warn('onResize not overwritten by react component', width, height);
},
};
const initialState = {
// The UI state, these can be modified by the react app as well.
activeNode: this.activeNode,
activeSelection: WebGMEGlobal.State.getActiveSelection(),
// activeTab: WebGMEGlobal.State.getActiveTab(),
// activeAspect: WebGMEGlobal.State.getActiveAspect(),
// Panel state (are passed in by the e.g. split-panel)
isActivePanel: false,
readOnly: false,
// size: {
// width: 0,
// height: 0,
// },
};
WebGMEReactPanels[this.appId] = {
client: this.client,
initialized: false,
initialState,
stateMediator: this.stateMediator,
};
};
WebGMEReactVizPanel.prototype.afterAppend = function afterAppend() {
reactViz(this.appId);
};
WebGMEReactVizPanel.prototype.onReadOnlyChanged = function onReadOnlyChanged(isReadOnly) {
// apply parent's onReadOnlyChanged
PanelBase.prototype.onReadOnlyChanged.call(this, isReadOnly);
this.stateMediator.onReadOnlyChanged(isReadOnly);
};
WebGMEReactVizPanel.prototype.onResize = function onResize(width, height) {
this.stateMediator.onResize(width, height);
};
WebGMEReactVizPanel.prototype.stateActiveObjectChanged = function stateActiveObjectChanged(model, activeNode) {
if (this.activeNode !== activeNode) {
this.activeNode = activeNode;
this.stateMediator.onActiveNodeChange(activeNode);
}
};
WebGMEReactVizPanel.prototype.stateActiveSelectionChanged = function stateActiveSelectionChanged(model, activeSelection) {
this.stateMediator.onActiveSelectionChange(activeSelection);
};
/* * * * * * * * Visualizer life cycle callbacks * * * * * * * */
WebGMEReactVizPanel.prototype.attachClientEventListeners = function attachClientEventListeners() {
this.detachClientEventListeners();
WebGMEGlobal.State.on(`change:${CONSTANTS.STATE_ACTIVE_OBJECT}`, this.stateActiveObjectChanged, this);
WebGMEGlobal.State.on(`change:${CONSTANTS.STATE_ACTIVE_SELECTION}`, this.stateActiveSelectionChanged, this);
};
WebGMEReactVizPanel.prototype.detachClientEventListeners = function detachClientEventListeners() {
WebGMEGlobal.State.off(`change:${CONSTANTS.STATE_ACTIVE_OBJECT}`, this.stateActiveObjectChanged);
WebGMEGlobal.State.off(`change:${CONSTANTS.STATE_ACTIVE_SELECTION}`, this.stateActiveSelectionChanged);
};
WebGMEReactVizPanel.prototype.destroy = function destroy() {
this.detachClientEventListeners();
this.stateMediator.onDestroy();
delete WebGMEReactPanels[this.appId];
PanelBase.prototype.destroy.call(this);
};
WebGMEReactVizPanel.prototype.onActivate = function onActivate() {
this.attachClientEventListeners();
this.stateMediator.onActivate();
if (typeof this.activeNode === 'string') {
WebGMEGlobal.State.registerActiveObject(
this.activeNode,
{suppressVisualizerFromNode: true},
);
}
};
WebGMEReactVizPanel.prototype.onDeactivate = function onDeactivate() {
this.detachClientEventListeners();
this.stateMediator.onDeactivate();
};
return WebGMEReactVizPanel;
});