alchemy-widget 0.2.5 → 0.2.7
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/CHANGELOG.md +12 -0
- package/assets/stylesheets/alchemy_widgets.scss +88 -0
- package/element/30-base_toolbar_element.js +226 -0
- package/element/editor_toolbar_element.js +30 -0
- package/element/user_avatar_element.js +137 -0
- package/element/user_avatar_group_element.js +131 -0
- package/element/widget_toolbar_element.js +40 -20
- package/helper/document_watcher.js +284 -0
- package/helper/editor_toolbar_manager.js +296 -0
- package/helper/widgets/00-widget.js +50 -5
- package/helper/widgets/markdown.js +90 -15
- package/helper_field/widget.js +53 -2
- package/helper_field/widgets.js +24 -0
- package/lib/conduit_extras.js +65 -0
- package/package.json +2 -2
- package/view/widget/elements/al_editor_toolbar.hwk +3 -0
- package/view/widget/elements/al_user_avatar.hwk +5 -0
- package/view/widget/elements/al_widget_toolbar.hwk +7 -1
|
@@ -0,0 +1,284 @@
|
|
|
1
|
+
const DOC_MAP = new Classes.WeakValueMap();
|
|
2
|
+
|
|
3
|
+
// A list of vibrant colours to choose from
|
|
4
|
+
const COLOURS = [
|
|
5
|
+
'#0095e8', // Blue
|
|
6
|
+
'#47be7d', // Green
|
|
7
|
+
'#5014d0', // Purple
|
|
8
|
+
'#f1bc00', // Yellow
|
|
9
|
+
'#d9214e', // Red
|
|
10
|
+
'#00a6a6', // Cyan
|
|
11
|
+
'#ff7f00', // Orange
|
|
12
|
+
'#20c997', // Teal
|
|
13
|
+
'#6610f2', // Indigo
|
|
14
|
+
'#e83e8c', // Pink
|
|
15
|
+
'#6f42c1', // Violet
|
|
16
|
+
'#9c27b0', // Periwinkle
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The syncable DocumentWatcher class:
|
|
21
|
+
* keeps track of how many people are viewing a document
|
|
22
|
+
*
|
|
23
|
+
* @constructor
|
|
24
|
+
*
|
|
25
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
26
|
+
* @since 0.2.7
|
|
27
|
+
* @version 0.2.7
|
|
28
|
+
*/
|
|
29
|
+
const DocumentWatcher = Function.inherits('Alchemy.Syncable', 'Alchemy.Widget', function DocumentWatcher() {
|
|
30
|
+
DocumentWatcher.super.call(this, 'document_watcher');
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create a watcher for the given document
|
|
35
|
+
*
|
|
36
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
37
|
+
* @since 0.2.7
|
|
38
|
+
* @version 0.2.7
|
|
39
|
+
*
|
|
40
|
+
* @param {String} model
|
|
41
|
+
* @param {*} pk
|
|
42
|
+
*/
|
|
43
|
+
DocumentWatcher.setStatic(function create(model, pk) {
|
|
44
|
+
|
|
45
|
+
if (typeof model != 'string') {
|
|
46
|
+
model = model.model_name;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let id = model + ':' + pk,
|
|
50
|
+
watcher = DOC_MAP.get(id);
|
|
51
|
+
|
|
52
|
+
if (!watcher) {
|
|
53
|
+
watcher = new DocumentWatcher();
|
|
54
|
+
watcher.setDocument(model, pk);
|
|
55
|
+
DOC_MAP.set(id, watcher);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return watcher;
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
if (Blast.isNode) {
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Add a viewer based on the conduit
|
|
65
|
+
*
|
|
66
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
67
|
+
* @since 0.2.7
|
|
68
|
+
* @version 0.2.7
|
|
69
|
+
*
|
|
70
|
+
* @param {Alchemy.Conduit} conduit
|
|
71
|
+
*/
|
|
72
|
+
DocumentWatcher.setTypedMethod([Types.Alchemy.Conduit], function addWatcher(conduit) {
|
|
73
|
+
|
|
74
|
+
let user_id = '' + conduit.getUserId(),
|
|
75
|
+
scene_id = conduit.scene_id;
|
|
76
|
+
|
|
77
|
+
this.addWatcher(user_id, scene_id);
|
|
78
|
+
|
|
79
|
+
// Watchers should also be registered as a client
|
|
80
|
+
this.registerClient(conduit);
|
|
81
|
+
|
|
82
|
+
let scene = conduit.scene;
|
|
83
|
+
|
|
84
|
+
if (scene) {
|
|
85
|
+
scene.on('destroyed', () => {
|
|
86
|
+
this.removeWatcher(user_id, scene_id);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* Remove a viewer based on the conduit
|
|
93
|
+
*
|
|
94
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
95
|
+
* @since 0.2.7
|
|
96
|
+
* @version 0.2.7
|
|
97
|
+
*
|
|
98
|
+
* @param {Alchemy.Conduit} conduit
|
|
99
|
+
*/
|
|
100
|
+
DocumentWatcher.setTypedMethod([Types.Alchemy.Conduit], function removeWatcher(conduit) {
|
|
101
|
+
let user_id = '' + conduit.getUserId(),
|
|
102
|
+
scene_id = conduit.scene_id;
|
|
103
|
+
|
|
104
|
+
this.removeWatcher(user_id, scene_id);
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Add the model property
|
|
110
|
+
*
|
|
111
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
112
|
+
* @since 0.2.7
|
|
113
|
+
* @version 0.2.7
|
|
114
|
+
*/
|
|
115
|
+
DocumentWatcher.setStateProperty('model', {allow_client_set: false});
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Add the pk property
|
|
119
|
+
*
|
|
120
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
121
|
+
* @since 0.2.7
|
|
122
|
+
* @version 0.2.7
|
|
123
|
+
*/
|
|
124
|
+
DocumentWatcher.setStateProperty('pk', {allow_client_set: false});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Add the title property
|
|
128
|
+
*
|
|
129
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
130
|
+
* @since 0.2.7
|
|
131
|
+
* @version 0.2.7
|
|
132
|
+
*/
|
|
133
|
+
DocumentWatcher.setStateProperty('title', {allow_client_set: false});
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Add the viewers property
|
|
137
|
+
*
|
|
138
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
139
|
+
* @since 0.2.7
|
|
140
|
+
* @version 0.2.7
|
|
141
|
+
*/
|
|
142
|
+
DocumentWatcher.setStateProperty('viewers', {
|
|
143
|
+
allow_client_set: false,
|
|
144
|
+
default: () => [],
|
|
145
|
+
});
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* Set the model and primary key
|
|
149
|
+
*
|
|
150
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
151
|
+
* @since 0.2.7
|
|
152
|
+
* @version 0.2.7
|
|
153
|
+
*
|
|
154
|
+
* @param {String} model
|
|
155
|
+
* @param {*} pk
|
|
156
|
+
*/
|
|
157
|
+
DocumentWatcher.setMethod(function setDocument(model, pk) {
|
|
158
|
+
this.state.model = model;
|
|
159
|
+
this.state.pk = pk;
|
|
160
|
+
|
|
161
|
+
if (model && pk) {
|
|
162
|
+
this.id = model + ':' + pk;
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Add a viewer
|
|
168
|
+
*
|
|
169
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
170
|
+
* @since 0.2.7
|
|
171
|
+
* @version 0.2.7
|
|
172
|
+
*
|
|
173
|
+
* @param {user_id} user_id
|
|
174
|
+
*/
|
|
175
|
+
DocumentWatcher.setSyncMethod([Types.String, Types.String], async function addWatcher(user_id, scene_id) {
|
|
176
|
+
|
|
177
|
+
let viewers = this.viewers,
|
|
178
|
+
entry;
|
|
179
|
+
|
|
180
|
+
for (entry of viewers) {
|
|
181
|
+
if (entry.user_id == user_id) {
|
|
182
|
+
entry.scenes.push(scene_id);
|
|
183
|
+
this.emitViewers();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
entry = {
|
|
189
|
+
user_id : user_id,
|
|
190
|
+
scenes : [scene_id],
|
|
191
|
+
info : null,
|
|
192
|
+
};
|
|
193
|
+
|
|
194
|
+
viewers.push(entry);
|
|
195
|
+
|
|
196
|
+
let info = await this.getUserInfo(user_id);
|
|
197
|
+
entry.info = info || false;
|
|
198
|
+
|
|
199
|
+
this.emitViewers();
|
|
200
|
+
});
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Emit the viewers property change, if they're all ready
|
|
204
|
+
*
|
|
205
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
206
|
+
* @since 0.2.7
|
|
207
|
+
* @version 0.2.7
|
|
208
|
+
*/
|
|
209
|
+
DocumentWatcher.setMethod(function emitViewers() {
|
|
210
|
+
this.emitPropertyChange('viewers');
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Remove a viewer
|
|
215
|
+
*
|
|
216
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
217
|
+
* @since 0.2.7
|
|
218
|
+
* @version 0.2.7
|
|
219
|
+
*
|
|
220
|
+
* @param {user_id} user_id
|
|
221
|
+
*/
|
|
222
|
+
DocumentWatcher.setSyncMethod([Types.String, Types.String], async function removeWatcher(user_id, scene_id) {
|
|
223
|
+
|
|
224
|
+
let viewers = this.viewers,
|
|
225
|
+
entry;
|
|
226
|
+
|
|
227
|
+
let user_to_remove;
|
|
228
|
+
|
|
229
|
+
for (entry of viewers) {
|
|
230
|
+
if (entry.user_id == user_id) {
|
|
231
|
+
|
|
232
|
+
let index = entry.scenes.indexOf(scene_id);
|
|
233
|
+
|
|
234
|
+
if (index > -1) {
|
|
235
|
+
entry.scenes.splice(index, 1);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
if (entry.scenes.length == 0) {
|
|
239
|
+
user_to_remove = entry;
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (user_to_remove) {
|
|
245
|
+
let index = viewers.indexOf(user_to_remove);
|
|
246
|
+
viewers.splice(index, 1);
|
|
247
|
+
this.emitViewers();
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Get information about an author
|
|
253
|
+
*
|
|
254
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
255
|
+
* @since 0.2.7
|
|
256
|
+
* @version 0.2.7
|
|
257
|
+
*
|
|
258
|
+
* @param {String} user_id
|
|
259
|
+
*/
|
|
260
|
+
DocumentWatcher.setUpstreamMethod(async function getUserInfo(user_id) {
|
|
261
|
+
|
|
262
|
+
if (!user_id) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
let document = await Model.get('User').findByPk(user_id);
|
|
267
|
+
|
|
268
|
+
if (!document) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
// Get a colour from the COLOURS array based on the user's id
|
|
273
|
+
let color = COLOURS[parseInt(user_id.slice(-4), 16) % COLOURS.length];
|
|
274
|
+
|
|
275
|
+
let result = {
|
|
276
|
+
pk : document.$pk,
|
|
277
|
+
first_name : document.first_name || document.firstname,
|
|
278
|
+
last_name : document.last_name || document.lastname,
|
|
279
|
+
username : document.username,
|
|
280
|
+
color : color,
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
return result;
|
|
284
|
+
});
|
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
const SCENE_MAP = new Map(),
|
|
2
|
+
CLEAR_DOC_ID = Symbol('clear_doc_id');
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* The syncable EditorToolbarManager class:
|
|
6
|
+
* handles a user's toolbar
|
|
7
|
+
*
|
|
8
|
+
* @constructor
|
|
9
|
+
*
|
|
10
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
11
|
+
* @since 0.2.7
|
|
12
|
+
* @version 0.2.7
|
|
13
|
+
*/
|
|
14
|
+
const EditorToolbarManager = Function.inherits('Alchemy.Syncable', 'Alchemy.Widget', function EditorToolbarManager() {
|
|
15
|
+
EditorToolbarManager.super.call(this, 'editor_toolbar_manager');
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
if (Blast.isNode) {
|
|
19
|
+
/**
|
|
20
|
+
* Create a manager for the given conduit
|
|
21
|
+
* (It should be linked to a user's tab/scene)
|
|
22
|
+
*
|
|
23
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
24
|
+
* @since 0.2.7
|
|
25
|
+
* @version 0.2.7
|
|
26
|
+
*
|
|
27
|
+
* @param {Conduit} conduit
|
|
28
|
+
*
|
|
29
|
+
* @return {EditorToolbarManager}
|
|
30
|
+
*/
|
|
31
|
+
EditorToolbarManager.setStatic(function create(conduit) {
|
|
32
|
+
|
|
33
|
+
if (!conduit?.scene_id) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
let id = conduit.scene_id,
|
|
38
|
+
ref = SCENE_MAP.get(id),
|
|
39
|
+
manager;
|
|
40
|
+
|
|
41
|
+
if (ref) {
|
|
42
|
+
manager = ref.deref();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (!manager) {
|
|
46
|
+
manager = new EditorToolbarManager();
|
|
47
|
+
manager.id = id;
|
|
48
|
+
manager.registerClient(conduit);
|
|
49
|
+
manager.conduit = conduit;
|
|
50
|
+
|
|
51
|
+
ref = new WeakRef(manager);
|
|
52
|
+
SCENE_MAP.set(id, ref);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (manager.conduit != conduit) {
|
|
56
|
+
// Don't create a shim like this,
|
|
57
|
+
// all the other important properties will be "frozen"
|
|
58
|
+
//manager = Object.create(manager);
|
|
59
|
+
manager.conduit = conduit;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
return manager;
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Add the document_watcher property
|
|
68
|
+
*
|
|
69
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
70
|
+
* @since 0.2.7
|
|
71
|
+
* @version 0.2.7
|
|
72
|
+
*/
|
|
73
|
+
EditorToolbarManager.setStateProperty('document_watcher', {allow_client_set: false});
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Add the model_name property
|
|
77
|
+
*
|
|
78
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
79
|
+
* @since 0.2.7
|
|
80
|
+
* @version 0.2.7
|
|
81
|
+
*/
|
|
82
|
+
EditorToolbarManager.setStateProperty('model_name', {allow_client_set: false});
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Add the title property
|
|
86
|
+
*
|
|
87
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
88
|
+
* @since 0.2.7
|
|
89
|
+
* @version 0.2.7
|
|
90
|
+
*/
|
|
91
|
+
EditorToolbarManager.setStateProperty('title', {allow_client_set: false});
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Add the scenario property
|
|
95
|
+
*
|
|
96
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
97
|
+
* @since 0.2.7
|
|
98
|
+
* @version 0.2.7
|
|
99
|
+
*/
|
|
100
|
+
EditorToolbarManager.setStateProperty('scenario');
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Clear the model fallback
|
|
104
|
+
*
|
|
105
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
106
|
+
* @since 0.2.7
|
|
107
|
+
* @version 0.2.7
|
|
108
|
+
*
|
|
109
|
+
* @param {String} model_name
|
|
110
|
+
*/
|
|
111
|
+
EditorToolbarManager.setMethod(function clearModelFallback() {
|
|
112
|
+
|
|
113
|
+
if (!this.fallback_id) {
|
|
114
|
+
this.fallback_id = 0;
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
this.fallback_id++;
|
|
118
|
+
|
|
119
|
+
return this.fallback_id;
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
/**
|
|
123
|
+
* If a response is sent through the conduit, and no model & document is set,
|
|
124
|
+
* make it clear those values.
|
|
125
|
+
*
|
|
126
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
127
|
+
* @since 0.2.7
|
|
128
|
+
* @version 0.2.7
|
|
129
|
+
*
|
|
130
|
+
* @param {String} model_name
|
|
131
|
+
*/
|
|
132
|
+
EditorToolbarManager.setMethod(function queueModelFallback(model_name) {
|
|
133
|
+
|
|
134
|
+
let current_id = this.clearModelFallback();
|
|
135
|
+
|
|
136
|
+
this.conduit.on('ending', () => {
|
|
137
|
+
if (this.fallback_id == current_id) {
|
|
138
|
+
this.setDocument(null);
|
|
139
|
+
this.setModel(model_name);
|
|
140
|
+
}
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Set the current model
|
|
146
|
+
*
|
|
147
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
148
|
+
* @since 0.2.7
|
|
149
|
+
* @version 0.2.7
|
|
150
|
+
*
|
|
151
|
+
* @param {String} model_name
|
|
152
|
+
*/
|
|
153
|
+
EditorToolbarManager.setTypedMethod([Types.String.optional().nullable()], function setModel(model_name) {
|
|
154
|
+
|
|
155
|
+
this.clearModelFallback();
|
|
156
|
+
|
|
157
|
+
let old_model = this.state.model_name;
|
|
158
|
+
|
|
159
|
+
this.state.model_name = model_name;
|
|
160
|
+
|
|
161
|
+
if (old_model != model_name) {
|
|
162
|
+
this.emitPropertyChange('model_name');
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
if (Blast.isNode && model_name) {
|
|
166
|
+
this.addTemplateToRender('buttons', 'chimera/toolbar/create_button', {
|
|
167
|
+
model_name: model_name.underscore(),
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* Set the document
|
|
174
|
+
*
|
|
175
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
176
|
+
* @since 0.2.7
|
|
177
|
+
* @version 0.2.7
|
|
178
|
+
*
|
|
179
|
+
* @param {Alchemy.Document} doc
|
|
180
|
+
*
|
|
181
|
+
* @return {DocumentWatcher}
|
|
182
|
+
*/
|
|
183
|
+
EditorToolbarManager.setMethod(function setDocument(doc) {
|
|
184
|
+
|
|
185
|
+
this.clearModelFallback();
|
|
186
|
+
|
|
187
|
+
this.clearArea('buttons');
|
|
188
|
+
|
|
189
|
+
if (!doc) {
|
|
190
|
+
this.setDocumentWatcher(null);
|
|
191
|
+
return;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
let model = doc.$model,
|
|
195
|
+
model_name = doc.$model_name,
|
|
196
|
+
pk_val = doc.$pk;
|
|
197
|
+
|
|
198
|
+
let document_watcher = Classes.Alchemy.Widget.DocumentWatcher.create(model_name, pk_val);
|
|
199
|
+
document_watcher.setProperty('title', ''+pk_val);
|
|
200
|
+
|
|
201
|
+
this.setDocumentWatcher(document_watcher);
|
|
202
|
+
|
|
203
|
+
if (this.scenario != 'chimera') {
|
|
204
|
+
this.addTemplateToRender('buttons', 'chimera/toolbar/edit_in_chimera_button', {
|
|
205
|
+
model_name: model_name.underscore(),
|
|
206
|
+
record_pk: pk_val,
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
if (model.chimera.record_preview) {
|
|
211
|
+
if (this.scenario == 'chimera') {
|
|
212
|
+
this.addTemplateToRender('buttons', 'chimera/toolbar/preview_button', {
|
|
213
|
+
model_name: model_name.underscore(),
|
|
214
|
+
record_pk: pk_val,
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
return document_watcher;
|
|
220
|
+
});
|
|
221
|
+
|
|
222
|
+
/**
|
|
223
|
+
* Clear an area
|
|
224
|
+
*
|
|
225
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
226
|
+
* @since 0.2.7
|
|
227
|
+
* @version 0.2.7
|
|
228
|
+
*/
|
|
229
|
+
EditorToolbarManager.setMethod(function clearArea(area) {
|
|
230
|
+
this.clearQueue('render_template');
|
|
231
|
+
this.pushQueue('clear_area', area);
|
|
232
|
+
});
|
|
233
|
+
|
|
234
|
+
/**
|
|
235
|
+
* Add a template to the toolbar
|
|
236
|
+
*
|
|
237
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
238
|
+
* @since 0.2.7
|
|
239
|
+
* @version 0.2.7
|
|
240
|
+
*/
|
|
241
|
+
EditorToolbarManager.setMethod(function addTemplateToRender(area, template, variables) {
|
|
242
|
+
this.pushQueue('render_template', area, template, variables);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* Set the document watcher to use
|
|
247
|
+
*
|
|
248
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
249
|
+
* @since 0.2.7
|
|
250
|
+
* @version 0.2.7
|
|
251
|
+
*
|
|
252
|
+
* @param {Alchemy.Widget.DocumentWatcher} watcher
|
|
253
|
+
*/
|
|
254
|
+
EditorToolbarManager.setSyncMethod(function setDocumentWatcher(watcher) {
|
|
255
|
+
|
|
256
|
+
if (this[CLEAR_DOC_ID]) {
|
|
257
|
+
clearTimeout(this[CLEAR_DOC_ID]);
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
let old_watcher = this.state.document_watcher;
|
|
261
|
+
|
|
262
|
+
this.state.document_watcher = watcher;
|
|
263
|
+
|
|
264
|
+
if (Blast.isNode) {
|
|
265
|
+
|
|
266
|
+
if (old_watcher) {
|
|
267
|
+
old_watcher.removeWatcher(this.conduit);
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (watcher) {
|
|
271
|
+
watcher.registerClient(this.conduit);
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
this.emitPropertyChange('document_watcher');
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
/**
|
|
279
|
+
* Queue clearing the document watcher
|
|
280
|
+
*
|
|
281
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
282
|
+
* @since 0.2.7
|
|
283
|
+
* @version 0.2.7
|
|
284
|
+
*/
|
|
285
|
+
EditorToolbarManager.setMethod(function queueClearDocumentWatcher(timeout = 500) {
|
|
286
|
+
|
|
287
|
+
if (this[CLEAR_DOC_ID]) {
|
|
288
|
+
clearTimeout(this[CLEAR_DOC_ID]);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
this[CLEAR_DOC_ID] = setTimeout(() => {
|
|
292
|
+
if (this.state.document_watcher) {
|
|
293
|
+
this.setDocumentWatcher(null);
|
|
294
|
+
}
|
|
295
|
+
}, timeout);
|
|
296
|
+
});
|
|
@@ -528,7 +528,7 @@ Widget.setStatic(function unDry(obj, custom_method, whenDone) {
|
|
|
528
528
|
*
|
|
529
529
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
530
530
|
* @since 0.1.0
|
|
531
|
-
* @version 0.
|
|
531
|
+
* @version 0.2.6
|
|
532
532
|
*
|
|
533
533
|
* @param {String} type The typeof widget to create
|
|
534
534
|
* @param {Object} config The optional config object
|
|
@@ -546,6 +546,10 @@ Widget.setMethod(function createChildWidget(type, config) {
|
|
|
546
546
|
// Create the instance
|
|
547
547
|
let instance = new WidgetClass(config);
|
|
548
548
|
|
|
549
|
+
if (this.conduit) {
|
|
550
|
+
instance.conduit = this.conduit;
|
|
551
|
+
}
|
|
552
|
+
|
|
549
553
|
// Set the parent instance!
|
|
550
554
|
instance.parent_instance = this;
|
|
551
555
|
|
|
@@ -582,12 +586,16 @@ Widget.setMethod(function toDry() {
|
|
|
582
586
|
*
|
|
583
587
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
584
588
|
* @since 0.1.0
|
|
585
|
-
* @version 0.2.
|
|
589
|
+
* @version 0.2.6
|
|
586
590
|
*
|
|
587
591
|
* @return {Array}
|
|
588
592
|
*/
|
|
589
593
|
Widget.setMethod(async function getActionbarActions() {
|
|
590
594
|
|
|
595
|
+
if (!this.constructor.actions) {
|
|
596
|
+
return [];
|
|
597
|
+
}
|
|
598
|
+
|
|
591
599
|
let sorted = this.constructor.actions.getSorted(),
|
|
592
600
|
result = [],
|
|
593
601
|
action;
|
|
@@ -810,16 +818,16 @@ Widget.setMethod(function queueVisibilityUpdate() {
|
|
|
810
818
|
*
|
|
811
819
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
812
820
|
* @since 0.2.1
|
|
813
|
-
* @version 0.2.
|
|
821
|
+
* @version 0.2.7
|
|
814
822
|
*/
|
|
815
823
|
Widget.setMethod(function checkVisibility() {
|
|
816
824
|
|
|
817
825
|
let should_be_hidden = this.is_hidden;
|
|
818
826
|
|
|
819
827
|
if (this.editing) {
|
|
820
|
-
this.widget.
|
|
828
|
+
this.widget.hideForEveryone(false);
|
|
821
829
|
} else {
|
|
822
|
-
this.widget.
|
|
830
|
+
this.widget.hideForEveryone(should_be_hidden);
|
|
823
831
|
}
|
|
824
832
|
|
|
825
833
|
if (should_be_hidden) {
|
|
@@ -1008,4 +1016,41 @@ Widget.setMethod(function getHandle() {
|
|
|
1008
1016
|
}
|
|
1009
1017
|
|
|
1010
1018
|
return element;
|
|
1019
|
+
});
|
|
1020
|
+
|
|
1021
|
+
/**
|
|
1022
|
+
* See if the given value is considered not-empty for this widget
|
|
1023
|
+
*
|
|
1024
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
1025
|
+
* @since 0.2.6
|
|
1026
|
+
* @version 0.2.6
|
|
1027
|
+
*
|
|
1028
|
+
* @return {Boolean}
|
|
1029
|
+
*/
|
|
1030
|
+
Widget.setMethod(function valueHasContent(value) {
|
|
1031
|
+
|
|
1032
|
+
if (!value || typeof value != 'object') {
|
|
1033
|
+
return false;
|
|
1034
|
+
}
|
|
1035
|
+
|
|
1036
|
+
let entry,
|
|
1037
|
+
key;
|
|
1038
|
+
|
|
1039
|
+
for (key in value) {
|
|
1040
|
+
entry = value[key];
|
|
1041
|
+
|
|
1042
|
+
if (entry) {
|
|
1043
|
+
if (Array.isArray(entry) && entry.length) {
|
|
1044
|
+
return true;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
if (entry === '') {
|
|
1048
|
+
continue;
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
return true;
|
|
1052
|
+
}
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
return false;
|
|
1011
1056
|
});
|