nodebb-plugin-composer-default 9.0.0 → 9.2.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nodebb-plugin-composer-default",
3
- "version": "9.0.0",
3
+ "version": "9.2.0",
4
4
  "description": "Default composer for NodeBB",
5
5
  "main": "library.js",
6
6
  "repository": {
@@ -29,6 +29,9 @@
29
29
  "compatibility": "^2.5.0"
30
30
  },
31
31
  "dependencies": {
32
+ "@textcomplete/contenteditable": "^0.1.12",
33
+ "@textcomplete/core": "^0.1.12",
34
+ "@textcomplete/textarea": "^0.1.12",
32
35
  "screenfull": "^5.0.2",
33
36
  "validator": "^13.7.0"
34
37
  },
@@ -570,3 +570,4 @@
570
570
 
571
571
  @import './zen-mode.less';
572
572
  @import './page-compose.less';
573
+ @import './textcomplete.less';
@@ -0,0 +1,24 @@
1
+ .textcomplete-dropdown {
2
+ border: 1px solid #ddd;
3
+ background-color: white;
4
+ list-style: none;
5
+ padding: 0;
6
+ margin: 0;
7
+
8
+ li {
9
+ margin: 0;
10
+ }
11
+
12
+ .textcomplete-footer, .textcomplete-item {
13
+ border-top: 1px solid #ddd;
14
+ }
15
+
16
+ .textcomplete-item {
17
+ padding: 2px 5px;
18
+ cursor: pointer;
19
+
20
+ &:hover, &.active {
21
+ background-color: rgb(110, 183, 219);
22
+ }
23
+ }
24
+ }
@@ -3,6 +3,7 @@
3
3
  $(document).ready(function () {
4
4
  $(window).on('action:app.load', function () {
5
5
  require(['composer/drafts'], function (drafts) {
6
+ drafts.migrateGuest();
6
7
  drafts.loadOpen();
7
8
  });
8
9
  });
@@ -65,23 +65,23 @@ define('composer/autocomplete', [
65
65
  };
66
66
 
67
67
  // This is a generic method that is also used by the chat
68
- autocomplete.setup = function (data) {
69
- var element = data.element.get(0);
70
- if (!element) {
68
+ autocomplete.setup = function ({ element, strategies, options }) {
69
+ const targetEl = element.get(0);
70
+ if (!targetEl) {
71
71
  return;
72
72
  }
73
73
  var editor;
74
- if (element.nodeName === 'TEXTAREA') {
75
- editor = new TextareaEditor(element);
76
- } else if (element.nodeName === 'DIV' && element.getAttribute('contenteditable') === 'true') {
77
- editor = new ContenteditableEditor(element);
74
+ if (targetEl.nodeName === 'TEXTAREA') {
75
+ editor = new TextareaEditor(targetEl);
76
+ } else if (targetEl.nodeName === 'DIV' && targetEl.getAttribute('contenteditable') === 'true') {
77
+ editor = new ContenteditableEditor(targetEl);
78
78
  }
79
79
 
80
80
  // yuku-t/textcomplete inherits directionality from target element itself
81
- element.setAttribute('dir', document.querySelector('html').getAttribute('data-dir'));
81
+ targetEl.setAttribute('dir', document.querySelector('html').getAttribute('data-dir'));
82
82
 
83
- var textcomplete = new Textcomplete(editor, data.strategies, {
84
- dropdown: data.options,
83
+ var textcomplete = new Textcomplete(editor, strategies, {
84
+ dropdown: options,
85
85
  });
86
86
  textcomplete.on('rendered', function () {
87
87
  if (textcomplete.dropdown.items.length) {
@@ -191,6 +191,10 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
191
191
  };
192
192
 
193
193
  drafts.migrateThumbs = function (postContainer, postData) {
194
+ if (!app.uid) {
195
+ return;
196
+ }
197
+
194
198
  // If any thumbs were uploaded, migrate them to this new composer's uuid
195
199
  const newUUID = postContainer.attr('data-uuid');
196
200
  const draft = drafts.get(postData.save_id);
@@ -224,7 +228,7 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
224
228
  open = [];
225
229
  }
226
230
 
227
- if (available.length && app.user && app.user.uid !== 0) {
231
+ if (available.length) {
228
232
  // Deconstruct each save_id and open up composer
229
233
  available.forEach(function (save_id) {
230
234
  if (!save_id) {
@@ -256,16 +260,17 @@ define('composer/drafts', ['api', 'alerts'], function (api, alerts) {
256
260
  if (type === 'cid') {
257
261
  composer.newTopic({
258
262
  cid: id,
259
- title: draft.title,
260
- body: draft.text,
261
- tags: [],
263
+ handle: app.user && app.user.uid ? undefined : utils.escapeHTML(draft.handle),
264
+ title: utils.escapeHTML(draft.title),
265
+ body: utils.escapeHTML(draft.text),
266
+ tags: String(draft.tags || '').split(','),
262
267
  });
263
268
  } else if (type === 'tid') {
264
269
  api.get('/topics/' + id, {}, function (err, topicObj) {
265
270
  if (err) {
266
271
  return alerts.error(err);
267
272
  }
268
- composer.newReply(id, undefined, topicObj.title, draft.text);
273
+ composer.newReply(id, undefined, topicObj.title, utils.escapeHTML(draft.text));
269
274
  });
270
275
  } else if (type === 'pid') {
271
276
  composer.editPost(id);
@@ -200,6 +200,7 @@ define('composer', [
200
200
  var pushData = {
201
201
  action: 'topics.post',
202
202
  cid: data.cid,
203
+ handle: data.handle,
203
204
  title: data.title || '',
204
205
  body: data.body || '',
205
206
  tags: data.tags || [],
@@ -317,9 +318,6 @@ define('composer', [
317
318
  postContainer.attr('data-uuid', post_uuid);
318
319
  }
319
320
 
320
- var titleEl = postContainer.find('input.title');
321
- var handleEl = postContainer.find('input.handle');
322
- var tagsEl = postContainer.find('input.tags');
323
321
  var bodyEl = postContainer.find('textarea');
324
322
  var submitBtn = postContainer.find('.composer-submit');
325
323
 
@@ -394,21 +392,7 @@ define('composer', [
394
392
  });
395
393
 
396
394
  drafts.init(postContainer, postData);
397
-
398
- var draft = drafts.get(postData.save_id);
399
- if (draft && draft.title) {
400
- titleEl.val(draft.title);
401
- }
402
- if (draft && draft.handle) {
403
- handleEl.val(draft.handle);
404
- }
405
- if (draft && draft.tags) {
406
- const tags = draft.tags.split(',');
407
- tags.forEach(function (tag) {
408
- tagsEl.tagsinput('add', tag);
409
- });
410
- }
411
- bodyEl.val(draft.text ? draft.text : postData.body);
395
+ const draft = drafts.get(postData.save_id);
412
396
 
413
397
  preview.render(postContainer, function () {
414
398
  preview.matchScroll(postContainer);
@@ -426,11 +410,7 @@ define('composer', [
426
410
  $('[data-format="zen"]').addClass('hidden');
427
411
  }
428
412
 
429
- hooks.fire('action:composer.enhanced', {
430
- postContainer: postContainer,
431
- postData: postData,
432
- draft: draft,
433
- });
413
+ hooks.fire('action:composer.enhanced', { postContainer, postData, draft });
434
414
  };
435
415
 
436
416
  async function getSelectedCategory(postData) {
@@ -463,6 +443,7 @@ define('composer', [
463
443
  var data = {
464
444
  title: title,
465
445
  titleLength: title.length,
446
+ body: postData.body,
466
447
  mobile: composer.bsEnvironment === 'xs' || composer.bsEnvironment === 'sm',
467
448
  resizable: true,
468
449
  thumb: postData.thumb,
@@ -101,7 +101,7 @@
101
101
  <span class="toggle-preview hide">[[modules:composer.show_preview]]</span>
102
102
  </div>
103
103
  <div class="pull-right draft-icon hidden-md hidden-lg"></div>
104
- <textarea class="write" tabindex="4" placeholder="[[modules:composer.textarea.placeholder]]"></textarea>
104
+ <textarea class="write" tabindex="4" placeholder="[[modules:composer.textarea.placeholder]]">{body}</textarea>
105
105
  </div>
106
106
  <div class="hidden-sm hidden-xs preview-container">
107
107
  <div class="help-text">