alchemy-widget 0.2.6 → 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 +6 -0
- package/assets/stylesheets/alchemy_widgets.scss +72 -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 +3 -3
- package/helper/widgets/markdown.js +65 -11
- package/lib/conduit_extras.js +65 -0
- package/package.json +1 -1
- 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
|
+
});
|
|
@@ -818,16 +818,16 @@ Widget.setMethod(function queueVisibilityUpdate() {
|
|
|
818
818
|
*
|
|
819
819
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
820
820
|
* @since 0.2.1
|
|
821
|
-
* @version 0.2.
|
|
821
|
+
* @version 0.2.7
|
|
822
822
|
*/
|
|
823
823
|
Widget.setMethod(function checkVisibility() {
|
|
824
824
|
|
|
825
825
|
let should_be_hidden = this.is_hidden;
|
|
826
826
|
|
|
827
827
|
if (this.editing) {
|
|
828
|
-
this.widget.
|
|
828
|
+
this.widget.hideForEveryone(false);
|
|
829
829
|
} else {
|
|
830
|
-
this.widget.
|
|
830
|
+
this.widget.hideForEveryone(should_be_hidden);
|
|
831
831
|
}
|
|
832
832
|
|
|
833
833
|
if (should_be_hidden) {
|
|
@@ -52,12 +52,68 @@ Markdown.setMethod(function populateWidget() {
|
|
|
52
52
|
*
|
|
53
53
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
54
54
|
* @since 0.1.0
|
|
55
|
-
* @version 0.2.
|
|
55
|
+
* @version 0.2.7
|
|
56
56
|
*/
|
|
57
57
|
Markdown.setMethod(async function _startEditor() {
|
|
58
58
|
|
|
59
59
|
Hawkejs.removeChildren(this.widget);
|
|
60
60
|
|
|
61
|
+
if (this.use_toast) {
|
|
62
|
+
this._startToastEditor();
|
|
63
|
+
} else {
|
|
64
|
+
this._startCodeEditor();
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Stop the editor
|
|
70
|
+
*
|
|
71
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
72
|
+
* @since 0.1.0
|
|
73
|
+
* @version 0.2.7
|
|
74
|
+
*/
|
|
75
|
+
Markdown.setMethod(function _stopEditor() {
|
|
76
|
+
|
|
77
|
+
Hawkejs.removeChildren(this.widget);
|
|
78
|
+
|
|
79
|
+
if (this.use_toast) {
|
|
80
|
+
this._startToastEditor();
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return this.loadWidget();
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Start the code editor
|
|
88
|
+
*
|
|
89
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
90
|
+
* @since 0.2.7
|
|
91
|
+
* @version 0.2.7
|
|
92
|
+
*/
|
|
93
|
+
Markdown.setMethod(async function _startCodeEditor() {
|
|
94
|
+
|
|
95
|
+
let element = this.createElement('div');
|
|
96
|
+
element.classList.add('markdown-editor-container');
|
|
97
|
+
this.widget.append(element);
|
|
98
|
+
|
|
99
|
+
let code_input = this.createElement('al-code-input');
|
|
100
|
+
code_input.show_line_numbers = false;
|
|
101
|
+
element.append(code_input);
|
|
102
|
+
|
|
103
|
+
code_input.value = this.config.markdown || '';
|
|
104
|
+
|
|
105
|
+
this.code_input = code_input;
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Start the toast editor
|
|
110
|
+
*
|
|
111
|
+
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
112
|
+
* @since 0.2.7
|
|
113
|
+
* @version 0.2.7
|
|
114
|
+
*/
|
|
115
|
+
Markdown.setMethod(async function _startToastEditor() {
|
|
116
|
+
|
|
61
117
|
hawkejs.scene.enableStyle('https://uicdn.toast.com/editor/latest/toastui-editor.min.css');
|
|
62
118
|
await hawkejs.require('https://uicdn.toast.com/editor/latest/toastui-editor-all.min.js');
|
|
63
119
|
|
|
@@ -69,7 +125,7 @@ Markdown.setMethod(async function _startEditor() {
|
|
|
69
125
|
|
|
70
126
|
const editor = new Editor({
|
|
71
127
|
el : element,
|
|
72
|
-
height : '
|
|
128
|
+
height : '600px',
|
|
73
129
|
initialEditType : 'markdown',
|
|
74
130
|
previewStyle : 'vertical',
|
|
75
131
|
usageStatistics : false,
|
|
@@ -84,15 +140,13 @@ Markdown.setMethod(async function _startEditor() {
|
|
|
84
140
|
});
|
|
85
141
|
|
|
86
142
|
/**
|
|
87
|
-
* Stop the editor
|
|
143
|
+
* Stop the toast editor
|
|
88
144
|
*
|
|
89
145
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
90
|
-
* @since 0.
|
|
91
|
-
* @version 0.2.
|
|
146
|
+
* @since 0.2.7
|
|
147
|
+
* @version 0.2.7
|
|
92
148
|
*/
|
|
93
|
-
Markdown.setMethod(function
|
|
94
|
-
|
|
95
|
-
Hawkejs.removeChildren(this.widget);
|
|
149
|
+
Markdown.setMethod(function _stopToastEditor() {
|
|
96
150
|
|
|
97
151
|
if (this.toast_editor) {
|
|
98
152
|
try {
|
|
@@ -101,8 +155,6 @@ Markdown.setMethod(function _stopEditor() {
|
|
|
101
155
|
}
|
|
102
156
|
|
|
103
157
|
this.toast_editor = null;
|
|
104
|
-
|
|
105
|
-
return this.loadWidget();
|
|
106
158
|
});
|
|
107
159
|
|
|
108
160
|
/**
|
|
@@ -110,7 +162,7 @@ Markdown.setMethod(function _stopEditor() {
|
|
|
110
162
|
*
|
|
111
163
|
* @author Jelle De Loecker <jelle@elevenways.be>
|
|
112
164
|
* @since 0.1.0
|
|
113
|
-
* @version 0.2.
|
|
165
|
+
* @version 0.2.7
|
|
114
166
|
*
|
|
115
167
|
* @return {Object}
|
|
116
168
|
*/
|
|
@@ -120,6 +172,8 @@ Markdown.setMethod(function syncConfig() {
|
|
|
120
172
|
|
|
121
173
|
if (this.toast_editor) {
|
|
122
174
|
value = this.toast_editor.getMarkdown();
|
|
175
|
+
} else if (this.code_input) {
|
|
176
|
+
value = this.code_input.value;
|
|
123
177
|
}
|
|
124
178
|
|
|
125
179
|
this.config.markdown = value;
|