cmmn-js-properties-panel-flowable 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +112 -0
- package/dist/assets/cmmn-js-properties-panel.css +495 -0
- package/index.js +1 -0
- package/lib/PropertiesActivator.js +67 -0
- package/lib/PropertiesPanel.js +1264 -0
- package/lib/Utils.js +126 -0
- package/lib/cmd/MultiCommandHandler.js +32 -0
- package/lib/cmd/UpdateBusinessObjectHandler.js +100 -0
- package/lib/cmd/UpdateBusinessObjectListHandler.js +108 -0
- package/lib/cmd/index.js +25 -0
- package/lib/factory/CheckboxEntryFactory.js +68 -0
- package/lib/factory/EntryFactory.js +199 -0
- package/lib/factory/EntryFieldDescription.js +73 -0
- package/lib/factory/LabelFactory.js +38 -0
- package/lib/factory/SelectEntryFactory.js +75 -0
- package/lib/factory/TextBoxEntryFactory.js +42 -0
- package/lib/factory/TextInputEntryFactory.js +73 -0
- package/lib/factory/ValidationAwareTextInput.js +66 -0
- package/lib/helper/CmdHelper.js +76 -0
- package/lib/helper/CmmnElementHelper.js +232 -0
- package/lib/helper/ElementHelper.js +23 -0
- package/lib/helper/ExtensionElementsHelper.js +39 -0
- package/lib/helper/ListenerHelper.js +28 -0
- package/lib/index.js +13 -0
- package/lib/provider/cmmn/CmmnPropertiesProvider.js +183 -0
- package/lib/provider/cmmn/index.js +7 -0
- package/lib/provider/cmmn/parts/CallableProps.js +169 -0
- package/lib/provider/cmmn/parts/CaseProps.js +66 -0
- package/lib/provider/cmmn/parts/DefinitionDocumentationProps.js +24 -0
- package/lib/provider/cmmn/parts/DefinitionIdProps.js +22 -0
- package/lib/provider/cmmn/parts/DefinitionNameProps.js +43 -0
- package/lib/provider/cmmn/parts/DocumentationProps.js +21 -0
- package/lib/provider/cmmn/parts/IdProps.js +14 -0
- package/lib/provider/cmmn/parts/IfPartProps.js +110 -0
- package/lib/provider/cmmn/parts/NameProps.js +90 -0
- package/lib/provider/cmmn/parts/OnPartProps.js +61 -0
- package/lib/provider/cmmn/parts/PlanItemControlProps.js +214 -0
- package/lib/provider/cmmn/parts/implementation/ConditionProp.js +81 -0
- package/lib/provider/cmmn/parts/implementation/DocumentationProp.js +91 -0
- package/lib/provider/cmmn/parts/implementation/IdProp.js +42 -0
- package/lib/provider/cmmn/parts/implementation/NameProp.js +38 -0
- package/lib/provider/cmmn/parts/implementation/RuleProp.js +96 -0
- package/lib/provider/cmmn/parts/implementation/TransitionProp.js +81 -0
- package/lib/provider/flowable/FlowablePropertiesProvider.js +393 -0
- package/lib/provider/flowable/index.js +7 -0
- package/lib/provider/flowable/parts/CallableExtensionProps.js +250 -0
- package/lib/provider/flowable/parts/CaseExecutionListenerProps.js +31 -0
- package/lib/provider/flowable/parts/HistoryTimeToLiveProps.js +19 -0
- package/lib/provider/flowable/parts/HumanTaskProps.js +76 -0
- package/lib/provider/flowable/parts/ListenerDetailProps.js +32 -0
- package/lib/provider/flowable/parts/ListenerFieldInjectionProps.js +13 -0
- package/lib/provider/flowable/parts/RepeatOnStandardEventProps.js +144 -0
- package/lib/provider/flowable/parts/TaskListenerProps.js +27 -0
- package/lib/provider/flowable/parts/VariableListenerProps.js +27 -0
- package/lib/provider/flowable/parts/VariableMappingProps.js +361 -0
- package/lib/provider/flowable/parts/implementation/BusinessKeyProp.js +109 -0
- package/lib/provider/flowable/parts/implementation/ExtensionElements.js +248 -0
- package/lib/provider/flowable/parts/implementation/FieldInjection.js +281 -0
- package/lib/provider/flowable/parts/implementation/HistoryTimeToLiveProp.js +37 -0
- package/lib/provider/flowable/parts/implementation/ListenerDelegateProp.js +159 -0
- package/lib/provider/flowable/parts/implementation/ListenerElements.js +132 -0
- package/lib/provider/flowable/parts/implementation/ListenerEventTypeProp.js +118 -0
- package/lib/provider/flowable/parts/implementation/ScriptProp.js +161 -0
- package/package.json +72 -0
- package/styles/_mixins.less +79 -0
- package/styles/_variables.less +19 -0
- package/styles/config.json +46 -0
- package/styles/groups.less +71 -0
- package/styles/header.less +35 -0
- package/styles/properties.less +328 -0
- package/styles/tabs.less +90 -0
|
@@ -0,0 +1,1264 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var escapeHTML = require('./Utils').escapeHTML;
|
|
4
|
+
|
|
5
|
+
var domify = require('min-dom').domify,
|
|
6
|
+
domQuery = require('min-dom').query,
|
|
7
|
+
domQueryAll = require('min-dom').queryAll,
|
|
8
|
+
domRemove = require('min-dom').remove,
|
|
9
|
+
domClasses = require('min-dom').classes,
|
|
10
|
+
domClosest = require('min-dom').closest,
|
|
11
|
+
domAttr = require('min-dom').attr,
|
|
12
|
+
domDelegate = require('min-dom').delegate,
|
|
13
|
+
domMatches = require('min-dom').matches;
|
|
14
|
+
|
|
15
|
+
var forEach = require('lodash/forEach'),
|
|
16
|
+
filter = require('lodash/filter'),
|
|
17
|
+
get = require('lodash/get'),
|
|
18
|
+
keys = require('lodash/keys'),
|
|
19
|
+
isEmpty = require('lodash/isEmpty'),
|
|
20
|
+
isArray = require('lodash/isArray'),
|
|
21
|
+
xor = require('lodash/xor'),
|
|
22
|
+
debounce = require('lodash/debounce');
|
|
23
|
+
|
|
24
|
+
var updateSelection = require('selection-update');
|
|
25
|
+
|
|
26
|
+
var scrollTabs = require('scroll-tabs').default;
|
|
27
|
+
|
|
28
|
+
var HIDE_CLASS = 'cpp-hidden';
|
|
29
|
+
var DEBOUNCE_DELAY = 300;
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
function isToggle(node) {
|
|
33
|
+
return node.type === 'checkbox' || node.type === 'radio';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function isSelect(node) {
|
|
37
|
+
return node.type === 'select-one';
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function isContentEditable(node) {
|
|
41
|
+
return domAttr(node, 'contenteditable');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
function getPropertyPlaceholders(node) {
|
|
45
|
+
var selector = 'input[name], textarea[name], [data-value], [contenteditable]';
|
|
46
|
+
var placeholders = domQueryAll(selector, node);
|
|
47
|
+
if ((!placeholders || !placeholders.length) && domMatches(node, selector)) {
|
|
48
|
+
placeholders = [ node ];
|
|
49
|
+
}
|
|
50
|
+
return placeholders;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Return all active form controls.
|
|
55
|
+
* This excludes the invisible controls unless all is true
|
|
56
|
+
*
|
|
57
|
+
* @param {Element} node
|
|
58
|
+
* @param {Boolean} [all=false]
|
|
59
|
+
*/
|
|
60
|
+
function getFormControls(node, all) {
|
|
61
|
+
var controls = domQueryAll('input[name], textarea[name], select[name], [contenteditable]', node);
|
|
62
|
+
|
|
63
|
+
if (!controls || !controls.length) {
|
|
64
|
+
controls = domMatches(node, 'option') ? [ node ] : controls;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
if (!all) {
|
|
68
|
+
controls = filter(controls, function(node) {
|
|
69
|
+
return !domClosest(node, '.' + HIDE_CLASS);
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return controls;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function getFormControlValuesInScope(entryNode) {
|
|
77
|
+
var values = {};
|
|
78
|
+
|
|
79
|
+
var controlNodes = getFormControls(entryNode);
|
|
80
|
+
|
|
81
|
+
forEach(controlNodes, function(controlNode) {
|
|
82
|
+
var value = controlNode.value;
|
|
83
|
+
|
|
84
|
+
var name = domAttr(controlNode, 'name') || domAttr(controlNode, 'data-name');
|
|
85
|
+
|
|
86
|
+
// take toggle state into account for radio / checkboxes
|
|
87
|
+
if (isToggle(controlNode)) {
|
|
88
|
+
if (controlNode.checked) {
|
|
89
|
+
if (!domAttr(controlNode, 'value')) {
|
|
90
|
+
value = true;
|
|
91
|
+
} else {
|
|
92
|
+
value = controlNode.value;
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
value = null;
|
|
96
|
+
}
|
|
97
|
+
} else
|
|
98
|
+
if (isContentEditable(controlNode)) {
|
|
99
|
+
value = controlNode.innerText;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
if (value !== null) {
|
|
103
|
+
// return the actual value
|
|
104
|
+
// handle serialization in entry provider
|
|
105
|
+
// (ie. if empty string should be serialized or not)
|
|
106
|
+
values[name] = value;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
return values;
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Extract input values from entry node
|
|
116
|
+
*
|
|
117
|
+
* @param {DOMElement} entryNode
|
|
118
|
+
* @returns {Object}
|
|
119
|
+
*/
|
|
120
|
+
function getFormControlValues(entryNode) {
|
|
121
|
+
|
|
122
|
+
var values;
|
|
123
|
+
|
|
124
|
+
var listContainer = domQuery('[data-list-entry-container]', entryNode);
|
|
125
|
+
if (listContainer) {
|
|
126
|
+
values = [];
|
|
127
|
+
var listNodes = listContainer.children || [];
|
|
128
|
+
forEach(listNodes, function(listNode) {
|
|
129
|
+
values.push(getFormControlValuesInScope(listNode));
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
else {
|
|
133
|
+
values = getFormControlValuesInScope(entryNode);
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
return values;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* Return true if the given form extracted value equals
|
|
141
|
+
* to an old cached version.
|
|
142
|
+
*
|
|
143
|
+
* @param {Object} value
|
|
144
|
+
* @param {Object} oldValue
|
|
145
|
+
* @return {Boolean}
|
|
146
|
+
*/
|
|
147
|
+
function valueEqual(value, oldValue) {
|
|
148
|
+
|
|
149
|
+
if (value && !oldValue) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
var allKeys = keys(value).concat(keys(oldValue));
|
|
154
|
+
|
|
155
|
+
return allKeys.every(function(key) {
|
|
156
|
+
return value[key] === oldValue[key];
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Return true if the given form extracted value(s)
|
|
162
|
+
* equal an old cached version.
|
|
163
|
+
*
|
|
164
|
+
* @param {Array<Object>|Object} values
|
|
165
|
+
* @param {Array<Object>|Object} oldValues
|
|
166
|
+
* @return {Boolean}
|
|
167
|
+
*/
|
|
168
|
+
function valuesEqual(values, oldValues) {
|
|
169
|
+
|
|
170
|
+
if (isArray(values)) {
|
|
171
|
+
|
|
172
|
+
if (values.length !== oldValues.length) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
return values.every(function(v, idx) {
|
|
177
|
+
return valueEqual(v, oldValues[idx]);
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
return valueEqual(values, oldValues);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Return a mapping of { id: entry } for all entries in the given groups in the given tabs.
|
|
186
|
+
*
|
|
187
|
+
* @param {Object} tabs
|
|
188
|
+
* @return {Object}
|
|
189
|
+
*/
|
|
190
|
+
function extractEntries(tabs) {
|
|
191
|
+
return keyBy(flattenDeep(map(flattenDeep(map(tabs, 'groups')), 'entries')), 'id');
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Return a mapping of { id: group } for all groups in the given tabs.
|
|
196
|
+
*
|
|
197
|
+
* @param {Object} tabs
|
|
198
|
+
* @return {Object}
|
|
199
|
+
*/
|
|
200
|
+
function extractGroups(tabs) {
|
|
201
|
+
return keyBy(flattenDeep(map(tabs, 'groups')), 'id');
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
/**
|
|
205
|
+
* A properties panel implementation.
|
|
206
|
+
*
|
|
207
|
+
* To use it provide a `propertiesProvider` component that knows
|
|
208
|
+
* about which properties to display.
|
|
209
|
+
*
|
|
210
|
+
* Properties edit state / visibility can be intercepted
|
|
211
|
+
* via a custom {@link PropertiesActivator}.
|
|
212
|
+
*
|
|
213
|
+
* @class
|
|
214
|
+
* @constructor
|
|
215
|
+
*
|
|
216
|
+
* @param {Object} config
|
|
217
|
+
* @param {EventBus} eventBus
|
|
218
|
+
* @param {Modeling} modeling
|
|
219
|
+
* @param {PropertiesProvider} propertiesProvider
|
|
220
|
+
* @param {Canvas} canvas
|
|
221
|
+
* @param {CommandStack} commandStack
|
|
222
|
+
*/
|
|
223
|
+
function PropertiesPanel(config, eventBus, modeling, propertiesProvider, commandStack, canvas) {
|
|
224
|
+
|
|
225
|
+
this._eventBus = eventBus;
|
|
226
|
+
this._modeling = modeling;
|
|
227
|
+
this._commandStack = commandStack;
|
|
228
|
+
this._canvas = canvas;
|
|
229
|
+
this._propertiesProvider = propertiesProvider;
|
|
230
|
+
|
|
231
|
+
this._init(config);
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
PropertiesPanel.$inject = [
|
|
235
|
+
'config.propertiesPanel',
|
|
236
|
+
'eventBus',
|
|
237
|
+
'modeling',
|
|
238
|
+
'propertiesProvider',
|
|
239
|
+
'commandStack',
|
|
240
|
+
'canvas' ];
|
|
241
|
+
|
|
242
|
+
module.exports = PropertiesPanel;
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
PropertiesPanel.prototype._init = function(config) {
|
|
246
|
+
|
|
247
|
+
var eventBus = this._eventBus;
|
|
248
|
+
|
|
249
|
+
var self = this;
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Select the root element once it is added to the canvas
|
|
253
|
+
*/
|
|
254
|
+
eventBus.on('root.added', function(e) {
|
|
255
|
+
self.update(e.element);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
eventBus.on('selection.changed', function(e) {
|
|
259
|
+
var newElement = e.newSelection[0];
|
|
260
|
+
|
|
261
|
+
self.update(newElement);
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
// add / update tab-bar scrolling
|
|
265
|
+
eventBus.on([
|
|
266
|
+
'propertiesPanel.changed',
|
|
267
|
+
'propertiesPanel.resized'
|
|
268
|
+
], function(event) {
|
|
269
|
+
|
|
270
|
+
var tabBarNode = domQuery('.cpp-properties-tab-bar', self._container);
|
|
271
|
+
|
|
272
|
+
if (!tabBarNode) {
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
var scroller = scrollTabs.get(tabBarNode);
|
|
277
|
+
|
|
278
|
+
if (!scroller) {
|
|
279
|
+
|
|
280
|
+
// we did not initialize yet, do that
|
|
281
|
+
// now and make sure we select the active
|
|
282
|
+
// tab on scroll update
|
|
283
|
+
scroller = scrollTabs(tabBarNode, {
|
|
284
|
+
selectors: {
|
|
285
|
+
tabsContainer: '.cpp-properties-tabs-links',
|
|
286
|
+
tab: '.cpp-properties-tabs-links li',
|
|
287
|
+
ignore: '.cpp-hidden',
|
|
288
|
+
active: '.cpp-active'
|
|
289
|
+
}
|
|
290
|
+
});
|
|
291
|
+
|
|
292
|
+
|
|
293
|
+
scroller.on('scroll', function(newActiveNode, oldActiveNode, direction) {
|
|
294
|
+
|
|
295
|
+
var linkNode = domQuery('[data-tab-target]', newActiveNode);
|
|
296
|
+
|
|
297
|
+
var tabId = domAttr(linkNode, 'data-tab-target');
|
|
298
|
+
|
|
299
|
+
self.activateTab(tabId);
|
|
300
|
+
});
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// react on tab changes and or tabContainer resize
|
|
304
|
+
// and make sure the active tab is shown completely
|
|
305
|
+
scroller.update();
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
eventBus.on('elements.changed', function(e) {
|
|
309
|
+
|
|
310
|
+
var current = self._current;
|
|
311
|
+
var element = current && current.element;
|
|
312
|
+
|
|
313
|
+
if (element) {
|
|
314
|
+
if (e.elements.indexOf(element) !== -1) {
|
|
315
|
+
self.update(element);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
eventBus.on('diagram.destroy', function() {
|
|
321
|
+
self.detach();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
this._container = domify('<div class="cpp-properties-panel"></div>');
|
|
325
|
+
|
|
326
|
+
this._bindListeners(this._container);
|
|
327
|
+
|
|
328
|
+
if (config && config.parent) {
|
|
329
|
+
this.attachTo(config.parent);
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
PropertiesPanel.prototype.attachTo = function(parentNode) {
|
|
335
|
+
|
|
336
|
+
if (!parentNode) {
|
|
337
|
+
throw new Error('parentNode required');
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
// ensure we detach from the
|
|
341
|
+
// previous, old parent
|
|
342
|
+
this.detach();
|
|
343
|
+
|
|
344
|
+
// unwrap jQuery if provided
|
|
345
|
+
if (parentNode.get) {
|
|
346
|
+
parentNode = parentNode.get(0);
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
if (typeof parentNode === 'string') {
|
|
350
|
+
parentNode = domQuery(parentNode);
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
var container = this._container;
|
|
354
|
+
|
|
355
|
+
parentNode.appendChild(container);
|
|
356
|
+
|
|
357
|
+
this._emit('attach');
|
|
358
|
+
};
|
|
359
|
+
|
|
360
|
+
PropertiesPanel.prototype.detach = function() {
|
|
361
|
+
|
|
362
|
+
var container = this._container,
|
|
363
|
+
parentNode = container.parentNode;
|
|
364
|
+
|
|
365
|
+
if (!parentNode) {
|
|
366
|
+
return;
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
this._emit('detach');
|
|
370
|
+
|
|
371
|
+
parentNode.removeChild(container);
|
|
372
|
+
};
|
|
373
|
+
|
|
374
|
+
|
|
375
|
+
/**
|
|
376
|
+
* Select the given tab within the properties panel.
|
|
377
|
+
*
|
|
378
|
+
* @param {Object|String} tab
|
|
379
|
+
*/
|
|
380
|
+
PropertiesPanel.prototype.activateTab = function(tab) {
|
|
381
|
+
|
|
382
|
+
var tabId = typeof tab === 'string' ? tab : tab.id;
|
|
383
|
+
|
|
384
|
+
var current = this._current;
|
|
385
|
+
|
|
386
|
+
var panelNode = current.panel;
|
|
387
|
+
|
|
388
|
+
var allTabNodes = domQueryAll('.cpp-properties-tab', panelNode),
|
|
389
|
+
allTabLinkNodes = domQueryAll('.cpp-properties-tab-link', panelNode);
|
|
390
|
+
|
|
391
|
+
forEach(allTabNodes, function(tabNode) {
|
|
392
|
+
var currentTabId = domAttr(tabNode, 'data-tab');
|
|
393
|
+
|
|
394
|
+
domClasses(tabNode).toggle('cpp-active', tabId === currentTabId);
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
forEach(allTabLinkNodes, function(tabLinkNode) {
|
|
398
|
+
var tabLink = domQuery('[data-tab-target]', tabLinkNode),
|
|
399
|
+
currentTabId = domAttr(tabLink, 'data-tab-target');
|
|
400
|
+
|
|
401
|
+
domClasses(tabLinkNode).toggle('cpp-active', tabId === currentTabId);
|
|
402
|
+
});
|
|
403
|
+
};
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Update the DOM representation of the properties panel
|
|
407
|
+
*/
|
|
408
|
+
PropertiesPanel.prototype.update = function(element) {
|
|
409
|
+
var current = this._current;
|
|
410
|
+
|
|
411
|
+
// no actual selection change
|
|
412
|
+
var needsCreate = true;
|
|
413
|
+
|
|
414
|
+
if (typeof element === 'undefined') {
|
|
415
|
+
|
|
416
|
+
// use RootElement of BPMN diagram to generate properties panel if no element is selected
|
|
417
|
+
element = this._canvas.getRootElement();
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
var newTabs = this._propertiesProvider.getTabs(element);
|
|
421
|
+
|
|
422
|
+
if (current && current.element === element) {
|
|
423
|
+
// see if we can reuse the existing panel
|
|
424
|
+
|
|
425
|
+
needsCreate = this._entriesChanged(current, newTabs);
|
|
426
|
+
// needsCreate = false;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
if (needsCreate) {
|
|
430
|
+
|
|
431
|
+
if (current) {
|
|
432
|
+
|
|
433
|
+
// get active tab from the existing panel before remove it
|
|
434
|
+
var activeTabNode = domQuery('.cpp-properties-tab.cpp-active', current.panel);
|
|
435
|
+
|
|
436
|
+
var activeTabId;
|
|
437
|
+
if (activeTabNode) {
|
|
438
|
+
activeTabId = domAttr(activeTabNode, 'data-tab');
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
// remove old panel
|
|
442
|
+
domRemove(current.panel);
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
this._current = this._create(element, newTabs);
|
|
446
|
+
|
|
447
|
+
// activate the saved active tab from the remove panel or the first tab
|
|
448
|
+
(activeTabId) ? this.activateTab(activeTabId) : this.activateTab(this._current.tabs[0]);
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (this._current) {
|
|
452
|
+
// make sure correct tab contents are visible
|
|
453
|
+
this._updateActivation(this._current);
|
|
454
|
+
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
this._emit('changed');
|
|
458
|
+
};
|
|
459
|
+
|
|
460
|
+
|
|
461
|
+
/**
|
|
462
|
+
* Returns true if one of two groups has different entries than the other.
|
|
463
|
+
*
|
|
464
|
+
* @param {Object} current
|
|
465
|
+
* @param {Object} newTabs
|
|
466
|
+
* @return {Booelan}
|
|
467
|
+
*/
|
|
468
|
+
PropertiesPanel.prototype._entriesChanged = function(current, newTabs) {
|
|
469
|
+
|
|
470
|
+
var oldEntryIds = keys(current.entries),
|
|
471
|
+
newEntryIds = keys(extractEntries(newTabs));
|
|
472
|
+
|
|
473
|
+
return !isEmpty(xor(oldEntryIds, newEntryIds));
|
|
474
|
+
};
|
|
475
|
+
|
|
476
|
+
PropertiesPanel.prototype._emit = function(event) {
|
|
477
|
+
this._eventBus.fire('propertiesPanel.' + event, { panel: this, current: this._current });
|
|
478
|
+
};
|
|
479
|
+
|
|
480
|
+
PropertiesPanel.prototype._bindListeners = function(container) {
|
|
481
|
+
|
|
482
|
+
var self = this;
|
|
483
|
+
|
|
484
|
+
// handles a change for a given event
|
|
485
|
+
var handleChange = function handleChange(event) {
|
|
486
|
+
|
|
487
|
+
// see if we handle a change inside a [data-entry] element.
|
|
488
|
+
// if not, drop out
|
|
489
|
+
var node = domClosest(event.delegateTarget, '[data-entry]'),
|
|
490
|
+
entryId, entry;
|
|
491
|
+
|
|
492
|
+
// change from outside a [data-entry] element, simply ignore
|
|
493
|
+
if (!node) {
|
|
494
|
+
return;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
entryId = domAttr(node, 'data-entry');
|
|
498
|
+
entry = self.getEntry(entryId);
|
|
499
|
+
|
|
500
|
+
var values = getFormControlValues(node);
|
|
501
|
+
|
|
502
|
+
if (event.type === 'change') {
|
|
503
|
+
|
|
504
|
+
// - if the "data-on-change" attribute is present and a value is changed,
|
|
505
|
+
// then the associated action is performed.
|
|
506
|
+
// - if the associated action returns "true" then an update to the business
|
|
507
|
+
// object is done
|
|
508
|
+
// - if it does not return "true", then only the DOM content is updated
|
|
509
|
+
var onChangeAction = event.delegateTarget.getAttribute('data-on-change');
|
|
510
|
+
|
|
511
|
+
if (onChangeAction) {
|
|
512
|
+
var isEntryDirty = self.executeAction(entry, node, onChangeAction, event);
|
|
513
|
+
|
|
514
|
+
if (!isEntryDirty) {
|
|
515
|
+
return self.update(self._current.element);
|
|
516
|
+
}
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
self.applyChanges(entry, values, node);
|
|
520
|
+
self.updateState(entry, node);
|
|
521
|
+
};
|
|
522
|
+
|
|
523
|
+
// debounce update only elements that are target of key events,
|
|
524
|
+
// i.e. INPUT and TEXTAREA. SELECTs will trigger an immediate update anyway.
|
|
525
|
+
domDelegate.bind(container, 'input, textarea, [contenteditable]', 'input', debounce(handleChange, DEBOUNCE_DELAY));
|
|
526
|
+
domDelegate.bind(container, 'input, textarea, select, [contenteditable]', 'change', handleChange);
|
|
527
|
+
|
|
528
|
+
// paste as plain text only
|
|
529
|
+
domDelegate.bind(container, '[contenteditable]', 'paste', handlePaste);
|
|
530
|
+
|
|
531
|
+
function handlePaste(event) {
|
|
532
|
+
var text = (event.clipboardData || window.clipboardData).getData('text');
|
|
533
|
+
document.execCommand('insertText', false, text);
|
|
534
|
+
|
|
535
|
+
event.preventDefault();
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
domDelegate.bind(container, '[data-action]', 'click', function onClick(event) {
|
|
539
|
+
|
|
540
|
+
// triggers on all inputs
|
|
541
|
+
var inputNode = event.delegateTarget;
|
|
542
|
+
var entryNode = domClosest(inputNode, '[data-entry]');
|
|
543
|
+
|
|
544
|
+
var actionId = domAttr(inputNode, 'data-action'),
|
|
545
|
+
entryId = domAttr(entryNode, 'data-entry');
|
|
546
|
+
|
|
547
|
+
var entry = self.getEntry(entryId);
|
|
548
|
+
|
|
549
|
+
var isEntryDirty = self.executeAction(entry, entryNode, actionId, event);
|
|
550
|
+
|
|
551
|
+
if (isEntryDirty) {
|
|
552
|
+
var values = getFormControlValues(entryNode);
|
|
553
|
+
|
|
554
|
+
self.applyChanges(entry, values, entryNode, isEntryDirty.force);
|
|
555
|
+
}
|
|
556
|
+
|
|
557
|
+
self.updateState(entry, entryNode);
|
|
558
|
+
});
|
|
559
|
+
|
|
560
|
+
function handleInput(event, element) {
|
|
561
|
+
// triggers on all inputs
|
|
562
|
+
var inputNode = event.delegateTarget;
|
|
563
|
+
|
|
564
|
+
var entryNode = domClosest(inputNode, '[data-entry]');
|
|
565
|
+
|
|
566
|
+
// only work on data entries
|
|
567
|
+
if (!entryNode) {
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
var eventHandlerId = domAttr(inputNode, 'data-blur'),
|
|
572
|
+
entryId = domAttr(entryNode, 'data-entry');
|
|
573
|
+
|
|
574
|
+
var entry = self.getEntry(entryId);
|
|
575
|
+
|
|
576
|
+
var isEntryDirty = self.executeAction(entry, entryNode, eventHandlerId, event);
|
|
577
|
+
|
|
578
|
+
if (isEntryDirty) {
|
|
579
|
+
var values = getFormControlValues(entryNode);
|
|
580
|
+
|
|
581
|
+
self.applyChanges(entry, values, entryNode);
|
|
582
|
+
}
|
|
583
|
+
|
|
584
|
+
self.updateState(entry, entryNode);
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
domDelegate.bind(container, '[data-blur]', 'blur', handleInput, true);
|
|
588
|
+
|
|
589
|
+
// make tab links interactive
|
|
590
|
+
domDelegate.bind(container, '.cpp-properties-tabs-links [data-tab-target]', 'click', function(event) {
|
|
591
|
+
event.preventDefault();
|
|
592
|
+
|
|
593
|
+
var delegateTarget = event.delegateTarget;
|
|
594
|
+
|
|
595
|
+
var tabId = domAttr(delegateTarget, 'data-tab-target');
|
|
596
|
+
|
|
597
|
+
// activate tab on link click
|
|
598
|
+
self.activateTab(tabId);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
};
|
|
602
|
+
|
|
603
|
+
PropertiesPanel.prototype.updateState = function(entry, entryNode) {
|
|
604
|
+
this.updateShow(entry, entryNode);
|
|
605
|
+
this.updateDisable(entry, entryNode);
|
|
606
|
+
};
|
|
607
|
+
|
|
608
|
+
/**
|
|
609
|
+
* Update the visibility of the entry node in the DOM
|
|
610
|
+
*/
|
|
611
|
+
PropertiesPanel.prototype.updateShow = function(entry, node) {
|
|
612
|
+
|
|
613
|
+
var current = this._current;
|
|
614
|
+
|
|
615
|
+
if (!current) {
|
|
616
|
+
return;
|
|
617
|
+
}
|
|
618
|
+
|
|
619
|
+
domClasses(node).remove(HIDE_CLASS);
|
|
620
|
+
|
|
621
|
+
if (typeof entry.hideEntry === 'function') {
|
|
622
|
+
|
|
623
|
+
var shouldHideEntry = entry.hideEntry(current.element, node);
|
|
624
|
+
if (shouldHideEntry) {
|
|
625
|
+
domClasses(node).add(HIDE_CLASS);
|
|
626
|
+
}
|
|
627
|
+
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
var showNodes = domQueryAll('[data-show]', node) || [];
|
|
631
|
+
|
|
632
|
+
forEach(showNodes, function(showNode) {
|
|
633
|
+
|
|
634
|
+
var expr = domAttr(showNode, 'data-show');
|
|
635
|
+
var fn = get(entry, expr);
|
|
636
|
+
if (fn) {
|
|
637
|
+
var scope = domClosest(showNode, '[data-scope]') || node;
|
|
638
|
+
var shouldShow = fn(current.element, node, showNode, scope) || false;
|
|
639
|
+
var hasClass = domClasses(showNode).has(HIDE_CLASS);
|
|
640
|
+
if (shouldShow) {
|
|
641
|
+
if (hasClass) {
|
|
642
|
+
domClasses(showNode).remove(HIDE_CLASS);
|
|
643
|
+
}
|
|
644
|
+
} else {
|
|
645
|
+
domClasses(showNode).add(HIDE_CLASS);
|
|
646
|
+
}
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
};
|
|
650
|
+
|
|
651
|
+
/**
|
|
652
|
+
* Evaluates a given function. If it returns true, then the
|
|
653
|
+
* node is marked as "disabled".
|
|
654
|
+
*/
|
|
655
|
+
PropertiesPanel.prototype.updateDisable = function(entry, node) {
|
|
656
|
+
var current = this._current;
|
|
657
|
+
|
|
658
|
+
if (!current) {
|
|
659
|
+
return;
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
var nodes = domQueryAll('[data-disable]', node) || [];
|
|
663
|
+
|
|
664
|
+
forEach(nodes, function(currentNode) {
|
|
665
|
+
var expr = domAttr(currentNode, 'data-disable');
|
|
666
|
+
var fn = get(entry, expr);
|
|
667
|
+
if (fn) {
|
|
668
|
+
var scope = domClosest(currentNode, '[data-scope]') || node;
|
|
669
|
+
var shouldDisable = fn(current.element, node, currentNode, scope) || false;
|
|
670
|
+
domAttr(currentNode, 'disabled', shouldDisable ? '' : null);
|
|
671
|
+
}
|
|
672
|
+
});
|
|
673
|
+
};
|
|
674
|
+
|
|
675
|
+
PropertiesPanel.prototype.executeAction = function(entry, entryNode, actionId, event) {
|
|
676
|
+
var current = this._current;
|
|
677
|
+
|
|
678
|
+
if (!current) {
|
|
679
|
+
return;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
var fn = get(entry, actionId);
|
|
683
|
+
if (fn) {
|
|
684
|
+
var scopeNode = domClosest(event.target, '[data-scope]') || entryNode;
|
|
685
|
+
return fn.apply(entry, [ current.element, entryNode, event, scopeNode ]);
|
|
686
|
+
}
|
|
687
|
+
};
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Apply changes to the business object by executing a command
|
|
691
|
+
*/
|
|
692
|
+
PropertiesPanel.prototype.applyChanges = function(entry, values, containerElement, force) {
|
|
693
|
+
|
|
694
|
+
var element = this._current.element;
|
|
695
|
+
|
|
696
|
+
// ensure we only update the model if we got dirty changes
|
|
697
|
+
if (!force && valuesEqual(values, entry.oldValues)) {
|
|
698
|
+
return;
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
var command = entry.set(element, values, containerElement);
|
|
702
|
+
|
|
703
|
+
var commandToExecute;
|
|
704
|
+
|
|
705
|
+
if (isArray(command)) {
|
|
706
|
+
if (command.length) {
|
|
707
|
+
commandToExecute = {
|
|
708
|
+
cmd: 'properties-panel.multi-command-executor',
|
|
709
|
+
context: flattenDeep(command)
|
|
710
|
+
};
|
|
711
|
+
}
|
|
712
|
+
} else {
|
|
713
|
+
commandToExecute = command;
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
if (commandToExecute) {
|
|
717
|
+
this._commandStack.execute(commandToExecute.cmd, commandToExecute.context || { element : element });
|
|
718
|
+
} else {
|
|
719
|
+
this.update(element);
|
|
720
|
+
}
|
|
721
|
+
};
|
|
722
|
+
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* apply validation results in the DOM and show or remove a message near the entry node.
|
|
726
|
+
*/
|
|
727
|
+
PropertiesPanel.prototype.applyValidationResults = function(validationResults, entryNode) {
|
|
728
|
+
|
|
729
|
+
validationResults = validationResults || {};
|
|
730
|
+
|
|
731
|
+
var controlNodes = getFormControls(entryNode, true);
|
|
732
|
+
|
|
733
|
+
forEach(controlNodes, function(controlNode) {
|
|
734
|
+
|
|
735
|
+
var name = domAttr(controlNode, 'name') || domAttr(controlNode, 'data-name'),
|
|
736
|
+
message = validationResults[name],
|
|
737
|
+
messageNode = domQuery('.cpp-validation-message', controlNode.parentNode);
|
|
738
|
+
|
|
739
|
+
domClasses(controlNode).remove('invalid');
|
|
740
|
+
domClasses(controlNode).remove('warning');
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
if (messageNode) {
|
|
744
|
+
domClasses(messageNode).remove('cpp-error-message');
|
|
745
|
+
domClasses(messageNode).remove('cpp-warning-message');
|
|
746
|
+
|
|
747
|
+
if (!message) {
|
|
748
|
+
controlNode.parentNode.removeChild(messageNode);
|
|
749
|
+
}
|
|
750
|
+
}
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
if (message) {
|
|
754
|
+
|
|
755
|
+
if (!messageNode) {
|
|
756
|
+
messageNode = domify('<div></div>');
|
|
757
|
+
domClasses(messageNode).add('cpp-validation-message');
|
|
758
|
+
|
|
759
|
+
// insert messageNode after controlNode
|
|
760
|
+
controlNode.parentNode.insertBefore(messageNode, controlNode.nextSibling);
|
|
761
|
+
}
|
|
762
|
+
|
|
763
|
+
|
|
764
|
+
if (typeof message === 'string' || message.error) {
|
|
765
|
+
message = message.error || message;
|
|
766
|
+
|
|
767
|
+
domClasses(controlNode).add('invalid');
|
|
768
|
+
domClasses(messageNode).add('cpp-error-message');
|
|
769
|
+
}
|
|
770
|
+
else {
|
|
771
|
+
message = message.warning;
|
|
772
|
+
|
|
773
|
+
domClasses(controlNode).add('warning');
|
|
774
|
+
domClasses(messageNode).add('cpp-warning-message');
|
|
775
|
+
}
|
|
776
|
+
|
|
777
|
+
messageNode.textContent = message;
|
|
778
|
+
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
});
|
|
782
|
+
|
|
783
|
+
};
|
|
784
|
+
|
|
785
|
+
|
|
786
|
+
/**
|
|
787
|
+
* Check if the entry contains valid input
|
|
788
|
+
*/
|
|
789
|
+
PropertiesPanel.prototype.validate = function(entry, values, entryNode) {
|
|
790
|
+
var self = this;
|
|
791
|
+
|
|
792
|
+
var current = this._current;
|
|
793
|
+
|
|
794
|
+
entryNode = entryNode || domQuery('[data-entry="' + entry.id + '"]', current.panel);
|
|
795
|
+
|
|
796
|
+
if (values instanceof Array) {
|
|
797
|
+
var listContainer = domQuery('[data-list-entry-container]', entryNode),
|
|
798
|
+
listEntryNodes = listContainer.children || [];
|
|
799
|
+
|
|
800
|
+
// create new elements
|
|
801
|
+
for (var i = 0; i < values.length; i++) {
|
|
802
|
+
var listValue = values[i];
|
|
803
|
+
|
|
804
|
+
if (entry.validateListItem) {
|
|
805
|
+
|
|
806
|
+
var validationResults = entry.validateListItem(current.element, listValue, entryNode, i),
|
|
807
|
+
listEntryNode = listEntryNodes[i];
|
|
808
|
+
|
|
809
|
+
self.applyValidationResults(validationResults, listEntryNode);
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
else {
|
|
814
|
+
if (entry.validate) {
|
|
815
|
+
this.validationResults = entry.validate(current.element, values, entryNode);
|
|
816
|
+
|
|
817
|
+
self.applyValidationResults(this.validationResults, entryNode);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
|
|
821
|
+
};
|
|
822
|
+
|
|
823
|
+
PropertiesPanel.prototype.getEntry = function(id) {
|
|
824
|
+
return this._current && this._current.entries[id];
|
|
825
|
+
};
|
|
826
|
+
|
|
827
|
+
var flattenDeep = require('lodash/flattenDeep'),
|
|
828
|
+
keyBy = require('lodash/keyBy'),
|
|
829
|
+
map = require('lodash/map');
|
|
830
|
+
|
|
831
|
+
PropertiesPanel.prototype._create = function(element, tabs) {
|
|
832
|
+
|
|
833
|
+
if (!element) {
|
|
834
|
+
return null;
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
var containerNode = this._container;
|
|
838
|
+
|
|
839
|
+
var panelNode = this._createPanel(element, tabs);
|
|
840
|
+
|
|
841
|
+
containerNode.appendChild(panelNode);
|
|
842
|
+
|
|
843
|
+
var entries = extractEntries(tabs);
|
|
844
|
+
var groups = extractGroups(tabs);
|
|
845
|
+
|
|
846
|
+
return {
|
|
847
|
+
tabs: tabs,
|
|
848
|
+
groups: groups,
|
|
849
|
+
entries: entries,
|
|
850
|
+
element: element,
|
|
851
|
+
panel: panelNode
|
|
852
|
+
};
|
|
853
|
+
};
|
|
854
|
+
|
|
855
|
+
PropertiesPanel.prototype._bindTemplate = function(element, entry, values, entryNode, idx) {
|
|
856
|
+
|
|
857
|
+
var eventBus = this._eventBus;
|
|
858
|
+
|
|
859
|
+
function isPropertyEditable(entry, propertyName) {
|
|
860
|
+
return eventBus.fire('propertiesPanel.isPropertyEditable', {
|
|
861
|
+
entry: entry,
|
|
862
|
+
propertyName: propertyName,
|
|
863
|
+
element: element
|
|
864
|
+
});
|
|
865
|
+
}
|
|
866
|
+
|
|
867
|
+
var inputNodes = getPropertyPlaceholders(entryNode);
|
|
868
|
+
|
|
869
|
+
forEach(inputNodes, function(node) {
|
|
870
|
+
|
|
871
|
+
var name,
|
|
872
|
+
newValue,
|
|
873
|
+
editable;
|
|
874
|
+
|
|
875
|
+
// we deal with an input element
|
|
876
|
+
if ('value' in node || isContentEditable(node) === 'true') {
|
|
877
|
+
name = domAttr(node, 'name') || domAttr(node, 'data-name');
|
|
878
|
+
newValue = values[name];
|
|
879
|
+
|
|
880
|
+
editable = isPropertyEditable(entry, name);
|
|
881
|
+
if (editable && entry.editable) {
|
|
882
|
+
editable = entry.editable(element, entryNode, node, name, newValue, idx);
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
domAttr(node, 'readonly', editable ? null : '');
|
|
886
|
+
domAttr(node, 'disabled', editable ? null : '');
|
|
887
|
+
|
|
888
|
+
if (entry.setControlValue) {
|
|
889
|
+
entry.setControlValue(element, entryNode, node, name, newValue, idx);
|
|
890
|
+
} else if (isToggle(node)) {
|
|
891
|
+
setToggleValue(node, newValue);
|
|
892
|
+
} else if (isSelect(node)) {
|
|
893
|
+
setSelectValue(node, newValue);
|
|
894
|
+
} else {
|
|
895
|
+
setInputValue(node, newValue);
|
|
896
|
+
}
|
|
897
|
+
}
|
|
898
|
+
|
|
899
|
+
// we deal with some non-editable html element
|
|
900
|
+
else {
|
|
901
|
+
name = domAttr(node, 'data-value');
|
|
902
|
+
newValue = values[name];
|
|
903
|
+
if (entry.setControlValue) {
|
|
904
|
+
entry.setControlValue(element, entryNode, node, name, newValue, idx);
|
|
905
|
+
}
|
|
906
|
+
else {
|
|
907
|
+
setTextValue(node, newValue);
|
|
908
|
+
}
|
|
909
|
+
}
|
|
910
|
+
});
|
|
911
|
+
};
|
|
912
|
+
|
|
913
|
+
// TODO(nikku): WTF freaking name? Change / clarify.
|
|
914
|
+
PropertiesPanel.prototype._updateActivation = function(current) {
|
|
915
|
+
var self = this;
|
|
916
|
+
|
|
917
|
+
var eventBus = this._eventBus;
|
|
918
|
+
|
|
919
|
+
var element = current.element;
|
|
920
|
+
|
|
921
|
+
function isEntryVisible(entry) {
|
|
922
|
+
return eventBus.fire('propertiesPanel.isEntryVisible', {
|
|
923
|
+
entry: entry,
|
|
924
|
+
element: element
|
|
925
|
+
});
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
function isGroupVisible(group, element, groupNode) {
|
|
929
|
+
if (typeof group.enabled === 'function') {
|
|
930
|
+
return group.enabled(element, groupNode);
|
|
931
|
+
} else {
|
|
932
|
+
return true;
|
|
933
|
+
}
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
function isTabVisible(tab, element) {
|
|
937
|
+
if (typeof tab.enabled === 'function') {
|
|
938
|
+
return tab.enabled(element);
|
|
939
|
+
} else {
|
|
940
|
+
return true;
|
|
941
|
+
}
|
|
942
|
+
}
|
|
943
|
+
|
|
944
|
+
function toggleVisible(node, visible) {
|
|
945
|
+
domClasses(node).toggle(HIDE_CLASS, !visible);
|
|
946
|
+
}
|
|
947
|
+
|
|
948
|
+
// check whether the active tab is visible
|
|
949
|
+
// if not: set the first tab as active tab
|
|
950
|
+
function checkActiveTabVisibility(node, visible) {
|
|
951
|
+
var isActive = domClasses(node).has('cpp-active');
|
|
952
|
+
if (!visible && isActive) {
|
|
953
|
+
self.activateTab(current.tabs[0]);
|
|
954
|
+
}
|
|
955
|
+
}
|
|
956
|
+
|
|
957
|
+
function updateLabel(element, selector, text) {
|
|
958
|
+
var labelNode = domQuery(selector, element);
|
|
959
|
+
|
|
960
|
+
if (!labelNode) {
|
|
961
|
+
return;
|
|
962
|
+
}
|
|
963
|
+
|
|
964
|
+
labelNode.textContent = text;
|
|
965
|
+
}
|
|
966
|
+
|
|
967
|
+
var panelNode = current.panel;
|
|
968
|
+
|
|
969
|
+
forEach(current.tabs, function(tab) {
|
|
970
|
+
|
|
971
|
+
var tabNode = domQuery('[data-tab=' + tab.id + ']', panelNode);
|
|
972
|
+
var tabLinkNode = domQuery('[data-tab-target=' + tab.id + ']', panelNode).parentNode;
|
|
973
|
+
|
|
974
|
+
var tabVisible = false;
|
|
975
|
+
|
|
976
|
+
forEach(tab.groups, function(group) {
|
|
977
|
+
|
|
978
|
+
var groupVisible = false;
|
|
979
|
+
|
|
980
|
+
var groupNode = domQuery('[data-group=' + group.id + ']', tabNode);
|
|
981
|
+
|
|
982
|
+
forEach(group.entries, function(entry) {
|
|
983
|
+
|
|
984
|
+
var entryNode = domQuery('[data-entry="' + entry.id + '"]', groupNode);
|
|
985
|
+
|
|
986
|
+
var entryVisible = isEntryVisible(entry);
|
|
987
|
+
|
|
988
|
+
groupVisible = groupVisible || entryVisible;
|
|
989
|
+
|
|
990
|
+
toggleVisible(entryNode, entryVisible);
|
|
991
|
+
|
|
992
|
+
var values = 'get' in entry ? entry.get(element, entryNode) : {};
|
|
993
|
+
|
|
994
|
+
if (values instanceof Array) {
|
|
995
|
+
var listEntryContainer = domQuery('[data-list-entry-container]', entryNode);
|
|
996
|
+
var existingElements = listEntryContainer.children || [];
|
|
997
|
+
|
|
998
|
+
for (var i = 0; i < values.length; i++) {
|
|
999
|
+
var listValue = values[i];
|
|
1000
|
+
var listItemNode = existingElements[i];
|
|
1001
|
+
if (!listItemNode) {
|
|
1002
|
+
listItemNode = domify(entry.createListEntryTemplate(listValue, i, listEntryContainer));
|
|
1003
|
+
listEntryContainer.appendChild(listItemNode);
|
|
1004
|
+
}
|
|
1005
|
+
domAttr(listItemNode, 'data-index', i);
|
|
1006
|
+
|
|
1007
|
+
self._bindTemplate(element, entry, listValue, listItemNode, i);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
var entriesToRemove = existingElements.length - values.length;
|
|
1011
|
+
|
|
1012
|
+
for (var j = 0; j < entriesToRemove; j++) {
|
|
1013
|
+
// remove orphaned element
|
|
1014
|
+
listEntryContainer.removeChild(listEntryContainer.lastChild);
|
|
1015
|
+
}
|
|
1016
|
+
|
|
1017
|
+
} else {
|
|
1018
|
+
self._bindTemplate(element, entry, values, entryNode);
|
|
1019
|
+
}
|
|
1020
|
+
|
|
1021
|
+
// update conditionally visible elements
|
|
1022
|
+
self.updateState(entry, entryNode);
|
|
1023
|
+
self.validate(entry, values, entryNode);
|
|
1024
|
+
|
|
1025
|
+
// remember initial state for later dirty checking
|
|
1026
|
+
entry.oldValues = getFormControlValues(entryNode);
|
|
1027
|
+
});
|
|
1028
|
+
|
|
1029
|
+
if (typeof group.label === 'function') {
|
|
1030
|
+
updateLabel(groupNode, '.group-label', group.label(element, groupNode));
|
|
1031
|
+
}
|
|
1032
|
+
|
|
1033
|
+
groupVisible = groupVisible && isGroupVisible(group, element, groupNode);
|
|
1034
|
+
|
|
1035
|
+
tabVisible = tabVisible || groupVisible;
|
|
1036
|
+
|
|
1037
|
+
toggleVisible(groupNode, groupVisible);
|
|
1038
|
+
});
|
|
1039
|
+
|
|
1040
|
+
tabVisible = tabVisible && isTabVisible(tab, element);
|
|
1041
|
+
|
|
1042
|
+
toggleVisible(tabNode, tabVisible);
|
|
1043
|
+
toggleVisible(tabLinkNode, tabVisible);
|
|
1044
|
+
|
|
1045
|
+
checkActiveTabVisibility(tabNode, tabVisible);
|
|
1046
|
+
});
|
|
1047
|
+
|
|
1048
|
+
// inject elements id into header
|
|
1049
|
+
var propertiesProvider = self._propertiesProvider,
|
|
1050
|
+
labelId = element.id;
|
|
1051
|
+
|
|
1052
|
+
if (propertiesProvider.getHeaderLabel) {
|
|
1053
|
+
labelId = propertiesProvider.getHeaderLabel(element);
|
|
1054
|
+
}
|
|
1055
|
+
|
|
1056
|
+
updateLabel(panelNode, '[data-label-id]', labelId || '');
|
|
1057
|
+
};
|
|
1058
|
+
|
|
1059
|
+
PropertiesPanel.prototype._createPanel = function(element, tabs) {
|
|
1060
|
+
var self = this;
|
|
1061
|
+
|
|
1062
|
+
var panelNode = domify('<div class="cpp-properties"></div>'),
|
|
1063
|
+
headerNode = domify('<div class="cpp-properties-header">' +
|
|
1064
|
+
'<div class="label" data-label-id></div>' +
|
|
1065
|
+
'<div class="search">' +
|
|
1066
|
+
'<input type="search" placeholder="Search for property" />' +
|
|
1067
|
+
'<button><span>Search</span></button>' +
|
|
1068
|
+
'</div>' +
|
|
1069
|
+
'</div>'),
|
|
1070
|
+
tabBarNode = domify('<div class="cpp-properties-tab-bar"></div>'),
|
|
1071
|
+
tabLinksNode = domify('<ul class="cpp-properties-tabs-links"></ul>'),
|
|
1072
|
+
tabContainerNode = domify('<div class="cpp-properties-tabs-container"></div>');
|
|
1073
|
+
|
|
1074
|
+
panelNode.appendChild(headerNode);
|
|
1075
|
+
|
|
1076
|
+
forEach(tabs, function(tab, tabIndex) {
|
|
1077
|
+
|
|
1078
|
+
if (!tab.id) {
|
|
1079
|
+
throw new Error('tab must have an id');
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
var tabNode = domify('<div class="cpp-properties-tab" data-tab="' + escapeHTML(tab.id) + '"></div>'),
|
|
1083
|
+
tabLinkNode = domify('<li class="cpp-properties-tab-link">' +
|
|
1084
|
+
'<a href data-tab-target="' + escapeHTML(tab.id) + '">' + escapeHTML(tab.label) + '</a>' +
|
|
1085
|
+
'</li>');
|
|
1086
|
+
|
|
1087
|
+
var groups = tab.groups;
|
|
1088
|
+
|
|
1089
|
+
forEach(groups, function(group) {
|
|
1090
|
+
|
|
1091
|
+
if (!group.id) {
|
|
1092
|
+
throw new Error('group must have an id');
|
|
1093
|
+
}
|
|
1094
|
+
|
|
1095
|
+
var groupNode = domify('<div class="cpp-properties-group" data-group="' + escapeHTML(group.id) + '">' +
|
|
1096
|
+
'<span class="group-toggle"></span>' +
|
|
1097
|
+
'<span class="group-label">' + escapeHTML(group.label) + '</span>' +
|
|
1098
|
+
'</div>');
|
|
1099
|
+
|
|
1100
|
+
// TODO(nre): use event delegation to handle that...
|
|
1101
|
+
groupNode.querySelector('.group-toggle').addEventListener('click', function(evt) {
|
|
1102
|
+
domClasses(groupNode).toggle('group-closed');
|
|
1103
|
+
evt.preventDefault();
|
|
1104
|
+
evt.stopPropagation();
|
|
1105
|
+
});
|
|
1106
|
+
groupNode.addEventListener('click', function(evt) {
|
|
1107
|
+
if (!evt.defaultPrevented && domClasses(groupNode).has('group-closed')) {
|
|
1108
|
+
domClasses(groupNode).remove('group-closed');
|
|
1109
|
+
}
|
|
1110
|
+
});
|
|
1111
|
+
|
|
1112
|
+
forEach(group.entries, function(entry) {
|
|
1113
|
+
|
|
1114
|
+
if (!entry.id) {
|
|
1115
|
+
throw new Error('entry must have an id');
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
var html = entry.html;
|
|
1119
|
+
|
|
1120
|
+
if (typeof html === 'string') {
|
|
1121
|
+
html = domify(html);
|
|
1122
|
+
}
|
|
1123
|
+
|
|
1124
|
+
// unwrap jquery
|
|
1125
|
+
if (html.get) {
|
|
1126
|
+
html = html.get(0);
|
|
1127
|
+
}
|
|
1128
|
+
|
|
1129
|
+
var entryNode = domify('<div class="cpp-properties-entry" data-entry="' + escapeHTML(entry.id) + '"></div>');
|
|
1130
|
+
|
|
1131
|
+
forEach(entry.cssClasses || [], function(cssClass) {
|
|
1132
|
+
domClasses(entryNode).add(cssClass);
|
|
1133
|
+
});
|
|
1134
|
+
|
|
1135
|
+
entryNode.appendChild(html);
|
|
1136
|
+
|
|
1137
|
+
groupNode.appendChild(entryNode);
|
|
1138
|
+
|
|
1139
|
+
// update conditionally visible elements
|
|
1140
|
+
self.updateState(entry, entryNode);
|
|
1141
|
+
});
|
|
1142
|
+
|
|
1143
|
+
tabNode.appendChild(groupNode);
|
|
1144
|
+
});
|
|
1145
|
+
|
|
1146
|
+
tabLinksNode.appendChild(tabLinkNode);
|
|
1147
|
+
tabContainerNode.appendChild(tabNode);
|
|
1148
|
+
});
|
|
1149
|
+
|
|
1150
|
+
tabBarNode.appendChild(tabLinksNode);
|
|
1151
|
+
|
|
1152
|
+
panelNode.appendChild(tabBarNode);
|
|
1153
|
+
panelNode.appendChild(tabContainerNode);
|
|
1154
|
+
|
|
1155
|
+
return panelNode;
|
|
1156
|
+
};
|
|
1157
|
+
|
|
1158
|
+
|
|
1159
|
+
|
|
1160
|
+
function setInputValue(node, value) {
|
|
1161
|
+
|
|
1162
|
+
var contentEditable = isContentEditable(node);
|
|
1163
|
+
|
|
1164
|
+
var oldValue = contentEditable ? node.innerText : node.value;
|
|
1165
|
+
|
|
1166
|
+
var selection;
|
|
1167
|
+
|
|
1168
|
+
// prevents input fields from having the value 'undefined'
|
|
1169
|
+
if (value === undefined) {
|
|
1170
|
+
value = '';
|
|
1171
|
+
}
|
|
1172
|
+
|
|
1173
|
+
if (oldValue === value) {
|
|
1174
|
+
return;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
// update selection on undo/redo
|
|
1178
|
+
if (document.activeElement === node) {
|
|
1179
|
+
selection = updateSelection(getSelection(node), node.value, value);
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
if (contentEditable) {
|
|
1183
|
+
node.innerText = value;
|
|
1184
|
+
} else {
|
|
1185
|
+
node.value = value;
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
if (selection) {
|
|
1189
|
+
setSelection(node, selection);
|
|
1190
|
+
}
|
|
1191
|
+
}
|
|
1192
|
+
|
|
1193
|
+
function setSelectValue(node, value) {
|
|
1194
|
+
if (value !== undefined) {
|
|
1195
|
+
node.value = value;
|
|
1196
|
+
}
|
|
1197
|
+
}
|
|
1198
|
+
|
|
1199
|
+
function setToggleValue(node, value) {
|
|
1200
|
+
var nodeValue = node.value;
|
|
1201
|
+
|
|
1202
|
+
node.checked = (value === nodeValue) || (!domAttr(node, 'value') && value);
|
|
1203
|
+
}
|
|
1204
|
+
|
|
1205
|
+
function setTextValue(node, value) {
|
|
1206
|
+
node.textContent = value;
|
|
1207
|
+
}
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
function getSelection(node) {
|
|
1211
|
+
|
|
1212
|
+
return isContentEditable(node) ? getContentEditableSelection(node) : {
|
|
1213
|
+
start: node.selectionStart,
|
|
1214
|
+
end: node.selectionEnd
|
|
1215
|
+
};
|
|
1216
|
+
}
|
|
1217
|
+
|
|
1218
|
+
function getContentEditableSelection(node) {
|
|
1219
|
+
|
|
1220
|
+
var selection = window.getSelection();
|
|
1221
|
+
|
|
1222
|
+
var focusNode = selection.focusNode,
|
|
1223
|
+
focusOffset = selection.focusOffset,
|
|
1224
|
+
anchorOffset = selection.anchorOffset;
|
|
1225
|
+
|
|
1226
|
+
if (!focusNode) {
|
|
1227
|
+
throw new Error('not selected');
|
|
1228
|
+
}
|
|
1229
|
+
|
|
1230
|
+
// verify we have selection on the current element
|
|
1231
|
+
if (!node.contains(focusNode)) {
|
|
1232
|
+
throw new Error('not selected');
|
|
1233
|
+
}
|
|
1234
|
+
|
|
1235
|
+
return {
|
|
1236
|
+
start: Math.min(focusOffset, anchorOffset),
|
|
1237
|
+
end: Math.max(focusOffset, anchorOffset)
|
|
1238
|
+
};
|
|
1239
|
+
}
|
|
1240
|
+
|
|
1241
|
+
function setSelection(node, selection) {
|
|
1242
|
+
if (isContentEditable(node)) {
|
|
1243
|
+
setContentEditableSelection(node, selection);
|
|
1244
|
+
} else {
|
|
1245
|
+
node.selectionStart = selection.start;
|
|
1246
|
+
node.selectionEnd = selection.end;
|
|
1247
|
+
}
|
|
1248
|
+
}
|
|
1249
|
+
|
|
1250
|
+
function setContentEditableSelection(node, selection) {
|
|
1251
|
+
|
|
1252
|
+
var focusNode,
|
|
1253
|
+
domRange,
|
|
1254
|
+
domSelection;
|
|
1255
|
+
|
|
1256
|
+
focusNode = node.firstChild || node,
|
|
1257
|
+
domRange = document.createRange();
|
|
1258
|
+
domRange.setStart(focusNode, selection.start);
|
|
1259
|
+
domRange.setEnd(focusNode, selection.end);
|
|
1260
|
+
|
|
1261
|
+
domSelection = window.getSelection();
|
|
1262
|
+
domSelection.removeAllRanges();
|
|
1263
|
+
domSelection.addRange(domRange);
|
|
1264
|
+
}
|