decidim-core 0.31.4 → 0.31.6

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.
Files changed (140) hide show
  1. checksums.yaml +4 -4
  2. data/app/cells/decidim/amendable/amend_button_card/show.erb +2 -2
  3. data/app/cells/decidim/author_cell.rb +0 -4
  4. data/app/cells/decidim/content_blocks/cta_settings_form/show.erb +1 -1
  5. data/app/cells/decidim/content_blocks/hero_settings_form/show.erb +2 -2
  6. data/app/cells/decidim/content_blocks/highlighted_content_banner_cell.rb +1 -1
  7. data/app/cells/decidim/content_blocks/highlighted_content_banner_settings_form/show.erb +1 -1
  8. data/app/cells/decidim/content_blocks/highlighted_participatory_spaces_cell.rb +1 -1
  9. data/app/cells/decidim/content_blocks/html_cell.rb +1 -1
  10. data/app/cells/decidim/content_blocks/participatory_space_hero_settings_form/show.erb +1 -1
  11. data/app/cells/decidim/content_blocks/static_page/section_cell.rb +1 -1
  12. data/app/cells/decidim/content_blocks/static_page/section_settings_form/show.erb +3 -1
  13. data/app/cells/decidim/content_blocks/static_page/summary_cell.rb +1 -1
  14. data/app/cells/decidim/content_blocks/static_page/summary_settings_form/show.erb +3 -1
  15. data/app/cells/decidim/content_blocks/static_page/two_pane_section_cell.rb +2 -2
  16. data/app/cells/decidim/content_blocks/static_page/two_pane_section_settings_form/show.erb +4 -2
  17. data/app/cells/decidim/data_consent/category.erb +5 -5
  18. data/app/cells/decidim/resource_types_filter/show.erb +2 -2
  19. data/app/cells/decidim/upload_modal_cell.rb +5 -0
  20. data/app/commands/decidim/destroy_account.rb +12 -1
  21. data/app/commands/decidim/multiple_attachments_methods.rb +28 -27
  22. data/app/controllers/concerns/decidim/devise_controllers.rb +10 -0
  23. data/app/controllers/decidim/download_your_data_controller.rb +1 -1
  24. data/app/controllers/decidim/notifications_subscriptions_controller.rb +8 -0
  25. data/app/controllers/decidim/private_downloads_controller.rb +29 -0
  26. data/app/jobs/decidim/process_inactive_participant_job.rb +0 -7
  27. data/app/mailers/decidim/delete_user_mailer.rb +14 -0
  28. data/app/mailers/decidim/participants_account_mailer.rb +0 -16
  29. data/app/models/decidim/attachment.rb +20 -2
  30. data/app/models/decidim/authorization.rb +7 -0
  31. data/app/models/decidim/moderation.rb +1 -1
  32. data/app/models/decidim/participatory_space_private_user.rb +1 -1
  33. data/app/models/decidim/private_download.rb +61 -0
  34. data/app/models/decidim/private_export.rb +6 -0
  35. data/app/models/decidim/user_base_entity.rb +17 -2
  36. data/app/models/decidim/user_moderation.rb +1 -1
  37. data/app/packs/src/decidim/controllers/form_validator/form_validator.js +6 -6
  38. data/app/packs/src/decidim/controllers/form_validator/form_validator.test.js +23 -1
  39. data/app/packs/src/decidim/controllers/mention/controller.js +296 -140
  40. data/app/packs/src/decidim/controllers/mention/input_mentions.test.js +120 -457
  41. data/app/packs/src/decidim/controllers/multiple_mentions/controller.js +68 -32
  42. data/app/packs/src/decidim/controllers/multiple_mentions/input_multiple_mentions.test.js +30 -23
  43. data/app/packs/src/decidim/direct_uploads/upload_field.js +4 -4
  44. data/app/packs/src/decidim/direct_uploads/upload_modal.js +11 -7
  45. data/app/packs/src/decidim/geocoding/reverse_geocoding.js +15 -5
  46. data/app/packs/src/decidim/geocoding/reverse_geocoding.test.js +197 -0
  47. data/app/packs/src/decidim/index.js +4 -3
  48. data/app/packs/src/decidim/sw/push-permissions.js +48 -13
  49. data/app/packs/src/decidim/sw/sw.js +1 -1
  50. data/app/packs/src/decidim/utilities/text.js +6 -6
  51. data/app/packs/stylesheets/decidim/_conversations.scss +14 -0
  52. data/app/packs/stylesheets/decidim/_editor_suggestions.scss +49 -0
  53. data/app/packs/stylesheets/decidim/_floating_help.scss +1 -1
  54. data/app/packs/stylesheets/decidim/_tom_select.scss +23 -0
  55. data/app/packs/stylesheets/decidim/application.scss +2 -0
  56. data/app/packs/stylesheets/decidim/editor.scss +2 -33
  57. data/app/packs/stylesheets/decidim/geocoding_addons.scss +10 -2
  58. data/app/presenters/decidim/menu_item_presenter.rb +9 -3
  59. data/app/presenters/decidim/stats_presenter.rb +1 -1
  60. data/app/services/decidim/notifications_subscriptions_persistor.rb +6 -0
  61. data/app/services/decidim/push_subscription_endpoint_validator.rb +34 -0
  62. data/app/services/decidim/send_push_notification.rb +5 -1
  63. data/app/uploaders/decidim/image_uploader.rb +1 -1
  64. data/app/views/decidim/delete_user_mailer/delete.html.erb +6 -0
  65. data/app/views/decidim/gamification/badges/index.html.erb +1 -1
  66. data/app/views/decidim/homepage/show.html.erb +1 -1
  67. data/app/views/decidim/last_activities/index.html.erb +1 -1
  68. data/app/views/decidim/messaging/conversations/_error_modal.html.erb +11 -19
  69. data/app/views/decidim/messaging/conversations/error.js.erb +12 -7
  70. data/app/views/decidim/newsletters/unsubscribe.html.erb +1 -1
  71. data/app/views/decidim/notifications_settings/show.html.erb +5 -5
  72. data/app/views/decidim/offline/show.html.erb +1 -1
  73. data/app/views/decidim/pages/index.html.erb +1 -1
  74. data/app/views/decidim/profiles/show.html.erb +1 -1
  75. data/app/views/decidim/shared/_resource_actions.html.erb +4 -4
  76. data/app/views/decidim/user_activities/index.html.erb +1 -1
  77. data/app/views/layouts/decidim/_wrapper.html.erb +2 -2
  78. data/app/views/layouts/decidim/header/_menu_breadcrumb_mobile_tablet.html.erb +1 -1
  79. data/app/views/layouts/decidim/shared/_layout_center.html.erb +1 -1
  80. data/app/views/layouts/decidim/shared/_layout_item.html.erb +1 -1
  81. data/app/views/layouts/decidim/shared/_layout_two_col.html.erb +1 -1
  82. data/config/locales/ar.yml +0 -5
  83. data/config/locales/bg.yml +0 -6
  84. data/config/locales/ca-IT.yml +10 -10
  85. data/config/locales/ca.yml +10 -10
  86. data/config/locales/cs.yml +4 -13
  87. data/config/locales/de.yml +5 -17
  88. data/config/locales/el.yml +0 -4
  89. data/config/locales/en.yml +9 -9
  90. data/config/locales/es-MX.yml +9 -9
  91. data/config/locales/es-PY.yml +9 -9
  92. data/config/locales/es.yml +9 -9
  93. data/config/locales/eu.yml +49 -49
  94. data/config/locales/fi-plain.yml +9 -9
  95. data/config/locales/fi.yml +11 -11
  96. data/config/locales/fr-CA.yml +10 -9
  97. data/config/locales/fr.yml +10 -9
  98. data/config/locales/gl.yml +0 -3
  99. data/config/locales/hu.yml +0 -5
  100. data/config/locales/id-ID.yml +0 -3
  101. data/config/locales/it.yml +11 -3
  102. data/config/locales/ja.yml +24 -21
  103. data/config/locales/lb.yml +0 -5
  104. data/config/locales/lt.yml +0 -5
  105. data/config/locales/lv.yml +0 -3
  106. data/config/locales/nl.yml +0 -5
  107. data/config/locales/no.yml +0 -5
  108. data/config/locales/pl.yml +2 -8
  109. data/config/locales/pt-BR.yml +3 -16
  110. data/config/locales/pt.yml +0 -5
  111. data/config/locales/ro-RO.yml +1 -14
  112. data/config/locales/sk.yml +1408 -4
  113. data/config/locales/sv.yml +3 -11
  114. data/config/locales/tr-TR.yml +0 -6
  115. data/config/locales/zh-CN.yml +0 -5
  116. data/config/locales/zh-TW.yml +0 -5
  117. data/config/routes.rb +1 -0
  118. data/lib/decidim/api/functions/user_entity_list.rb +2 -0
  119. data/lib/decidim/attachment_attributes.rb +58 -9
  120. data/lib/decidim/command.rb +1 -1
  121. data/lib/decidim/content_renderers/base_renderer.rb +112 -0
  122. data/lib/decidim/content_renderers/blob_renderer.rb +4 -7
  123. data/lib/decidim/content_renderers/mention_resource_renderer.rb +10 -6
  124. data/lib/decidim/content_renderers/resource_renderer.rb +16 -7
  125. data/lib/decidim/content_renderers/user_renderer.rb +11 -9
  126. data/lib/decidim/core/content_blocks/registry_manager.rb +4 -4
  127. data/lib/decidim/core/engine.rb +8 -0
  128. data/lib/decidim/core/test/factories.rb +3 -0
  129. data/lib/decidim/core/test/shared_examples/admin_resource_gallery_examples.rb +10 -10
  130. data/lib/decidim/core/test/shared_examples/comments_examples.rb +6 -6
  131. data/lib/decidim/core/version.rb +1 -1
  132. data/lib/decidim/map/autocomplete.rb +4 -3
  133. data/lib/decidim/searchable.rb +5 -0
  134. data/lib/decidim/view_model.rb +1 -1
  135. data/lib/tasks/decidim_mailers_tasks.rake +31 -9
  136. metadata +14 -10
  137. data/app/commands/decidim/gallery_methods.rb +0 -107
  138. data/app/packs/src/decidim/vendor/tribute.js +0 -1890
  139. data/app/packs/stylesheets/decidim/_tribute.scss +0 -36
  140. data/app/views/decidim/participants_account_mailer/removal_notification.html.erb +0 -11
@@ -1,1890 +0,0 @@
1
- /* eslint-disable */
2
-
3
- /*
4
- Modified file from the original tribute.js
5
- Adding inside click event the conditional if the li element has no disabled-tribute-element class name. if true, then it must continue with normal behaviour.
6
- */
7
- (function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.Tribute = f()}})(function(){var define,module,exports;return (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){
8
- "use strict";
9
-
10
- Object.defineProperty(exports, "__esModule", {
11
- value: true
12
- });
13
- exports["default"] = void 0;
14
-
15
- require("./utils");
16
-
17
- var _TributeEvents = _interopRequireDefault(require("./TributeEvents"));
18
-
19
- var _TributeMenuEvents = _interopRequireDefault(require("./TributeMenuEvents"));
20
-
21
- var _TributeRange = _interopRequireDefault(require("./TributeRange"));
22
-
23
- var _TributeSearch = _interopRequireDefault(require("./TributeSearch"));
24
-
25
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
26
-
27
- function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
28
-
29
- function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
30
-
31
- function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
32
-
33
- function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
34
-
35
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
36
-
37
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
38
-
39
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
40
-
41
- var Tribute =
42
- /*#__PURE__*/
43
- function () {
44
- function Tribute(_ref) {
45
- var _this = this;
46
-
47
- var _ref$values = _ref.values,
48
- values = _ref$values === void 0 ? null : _ref$values,
49
- _ref$iframe = _ref.iframe,
50
- iframe = _ref$iframe === void 0 ? null : _ref$iframe,
51
- _ref$selectClass = _ref.selectClass,
52
- selectClass = _ref$selectClass === void 0 ? 'highlight' : _ref$selectClass,
53
- _ref$trigger = _ref.trigger,
54
- trigger = _ref$trigger === void 0 ? '@' : _ref$trigger,
55
- _ref$autocompleteMode = _ref.autocompleteMode,
56
- autocompleteMode = _ref$autocompleteMode === void 0 ? false : _ref$autocompleteMode,
57
- _ref$selectTemplate = _ref.selectTemplate,
58
- selectTemplate = _ref$selectTemplate === void 0 ? null : _ref$selectTemplate,
59
- _ref$menuItemTemplate = _ref.menuItemTemplate,
60
- menuItemTemplate = _ref$menuItemTemplate === void 0 ? null : _ref$menuItemTemplate,
61
- _ref$lookup = _ref.lookup,
62
- lookup = _ref$lookup === void 0 ? 'key' : _ref$lookup,
63
- _ref$fillAttr = _ref.fillAttr,
64
- fillAttr = _ref$fillAttr === void 0 ? 'value' : _ref$fillAttr,
65
- _ref$collection = _ref.collection,
66
- collection = _ref$collection === void 0 ? null : _ref$collection,
67
- _ref$menuContainer = _ref.menuContainer,
68
- menuContainer = _ref$menuContainer === void 0 ? null : _ref$menuContainer,
69
- _ref$noMatchTemplate = _ref.noMatchTemplate,
70
- noMatchTemplate = _ref$noMatchTemplate === void 0 ? null : _ref$noMatchTemplate,
71
- _ref$requireLeadingSp = _ref.requireLeadingSpace,
72
- requireLeadingSpace = _ref$requireLeadingSp === void 0 ? true : _ref$requireLeadingSp,
73
- _ref$allowSpaces = _ref.allowSpaces,
74
- allowSpaces = _ref$allowSpaces === void 0 ? false : _ref$allowSpaces,
75
- _ref$replaceTextSuffi = _ref.replaceTextSuffix,
76
- replaceTextSuffix = _ref$replaceTextSuffi === void 0 ? null : _ref$replaceTextSuffi,
77
- _ref$positionMenu = _ref.positionMenu,
78
- positionMenu = _ref$positionMenu === void 0 ? true : _ref$positionMenu,
79
- _ref$spaceSelectsMatc = _ref.spaceSelectsMatch,
80
- spaceSelectsMatch = _ref$spaceSelectsMatc === void 0 ? false : _ref$spaceSelectsMatc,
81
- _ref$searchOpts = _ref.searchOpts,
82
- searchOpts = _ref$searchOpts === void 0 ? {} : _ref$searchOpts,
83
- _ref$menuItemLimit = _ref.menuItemLimit,
84
- menuItemLimit = _ref$menuItemLimit === void 0 ? null : _ref$menuItemLimit;
85
-
86
- _classCallCheck(this, Tribute);
87
-
88
- this.autocompleteMode = autocompleteMode;
89
- this.menuSelected = 0;
90
- this.current = {};
91
- this.inputEvent = false;
92
- this.isActive = false;
93
- this.menuContainer = menuContainer;
94
- this.allowSpaces = allowSpaces;
95
- this.replaceTextSuffix = replaceTextSuffix;
96
- this.positionMenu = positionMenu;
97
- this.hasTrailingSpace = false;
98
- this.spaceSelectsMatch = spaceSelectsMatch;
99
-
100
- if (this.autocompleteMode) {
101
- trigger = '';
102
- allowSpaces = false;
103
- }
104
-
105
- if (values) {
106
- this.collection = [{
107
- // symbol that starts the lookup
108
- trigger: trigger,
109
- // is it wrapped in an iframe
110
- iframe: iframe,
111
- // class applied to selected item
112
- selectClass: selectClass,
113
- // function called on select that retuns the content to insert
114
- selectTemplate: (selectTemplate || Tribute.defaultSelectTemplate).bind(this),
115
- // function called that returns content for an item
116
- menuItemTemplate: (menuItemTemplate || Tribute.defaultMenuItemTemplate).bind(this),
117
- // function called when menu is empty, disables hiding of menu.
118
- noMatchTemplate: function (t) {
119
- if (typeof t === 'function') {
120
- return t.bind(_this);
121
- }
122
-
123
- return noMatchTemplate || function () {
124
- return '';
125
- }.bind(_this);
126
- }(noMatchTemplate),
127
- // column to search against in the object
128
- lookup: lookup,
129
- // column that contains the content to insert by default
130
- fillAttr: fillAttr,
131
- // array of objects or a function returning an array of objects
132
- values: values,
133
- requireLeadingSpace: requireLeadingSpace,
134
- searchOpts: searchOpts,
135
- menuItemLimit: menuItemLimit
136
- }];
137
- } else if (collection) {
138
- if (this.autocompleteMode) console.warn('Tribute in autocomplete mode does not work for collections');
139
- this.collection = collection.map(function (item) {
140
- return {
141
- trigger: item.trigger || trigger,
142
- iframe: item.iframe || iframe,
143
- selectClass: item.selectClass || selectClass,
144
- selectTemplate: (item.selectTemplate || Tribute.defaultSelectTemplate).bind(_this),
145
- menuItemTemplate: (item.menuItemTemplate || Tribute.defaultMenuItemTemplate).bind(_this),
146
- // function called when menu is empty, disables hiding of menu.
147
- noMatchTemplate: function (t) {
148
- if (typeof t === 'function') {
149
- return t.bind(_this);
150
- }
151
-
152
- return null;
153
- }(noMatchTemplate),
154
- lookup: item.lookup || lookup,
155
- fillAttr: item.fillAttr || fillAttr,
156
- values: item.values,
157
- requireLeadingSpace: item.requireLeadingSpace,
158
- searchOpts: item.searchOpts || searchOpts,
159
- menuItemLimit: item.menuItemLimit || menuItemLimit
160
- };
161
- });
162
- } else {
163
- throw new Error('[Tribute] No collection specified.');
164
- }
165
-
166
- new _TributeRange["default"](this);
167
- new _TributeEvents["default"](this);
168
- new _TributeMenuEvents["default"](this);
169
- new _TributeSearch["default"](this);
170
- }
171
-
172
- _createClass(Tribute, [{
173
- key: "triggers",
174
- value: function triggers() {
175
- return this.collection.map(function (config) {
176
- return config.trigger;
177
- });
178
- }
179
- }, {
180
- key: "attach",
181
- value: function attach(el) {
182
- if (!el) {
183
- throw new Error('[Tribute] Must pass in a DOM node or NodeList.');
184
- } // Check if it is a jQuery collection
185
-
186
-
187
- if (typeof jQuery !== 'undefined' && el instanceof jQuery) {
188
- el = el.get();
189
- } // Is el an Array/Array-like object?
190
-
191
-
192
- if (el.constructor === NodeList || el.constructor === HTMLCollection || el.constructor === Array) {
193
- var length = el.length;
194
-
195
- for (var i = 0; i < length; ++i) {
196
- this._attach(el[i]);
197
- }
198
- } else {
199
- this._attach(el);
200
- }
201
- }
202
- }, {
203
- key: "_attach",
204
- value: function _attach(el) {
205
- if (el.hasAttribute('data-tribute')) {
206
- console.warn('Tribute was already bound to ' + el.nodeName);
207
- }
208
-
209
- this.ensureEditable(el);
210
- this.events.bind(el);
211
- el.setAttribute('data-tribute', true);
212
- }
213
- }, {
214
- key: "ensureEditable",
215
- value: function ensureEditable(element) {
216
- if (Tribute.inputTypes().indexOf(element.nodeName) === -1) {
217
- if (element.contentEditable) {
218
- element.contentEditable = true;
219
- } else {
220
- throw new Error('[Tribute] Cannot bind to ' + element.nodeName);
221
- }
222
- }
223
- }
224
- }, {
225
- key: "createMenu",
226
- value: function createMenu() {
227
- var wrapper = this.range.getDocument().createElement('div'),
228
- ul = this.range.getDocument().createElement('ul');
229
- wrapper.className = 'tribute-container';
230
- wrapper.setAttribute('aria-expanded','true');
231
- ul.setAttribute('id','results');
232
- wrapper.appendChild(ul);
233
-
234
- if (this.menuContainer) {
235
- return this.menuContainer.appendChild(wrapper);
236
- }
237
-
238
- return this.range.getDocument().body.appendChild(wrapper);
239
- }
240
- }, {
241
- key: "showMenuFor",
242
- value: function showMenuFor(element, scrollTo) {
243
- var _this2 = this;
244
-
245
- // Only proceed if menu is not already shown for the current element & mentionText
246
- if (this.isActive && this.current.element === element && this.current.mentionText === this.currentMentionTextSnapshot) {
247
- return;
248
- }
249
-
250
- this.currentMentionTextSnapshot = this.current.mentionText; // create the menu if it does not exist.
251
-
252
- if (!this.menu) {
253
- this.menu = this.createMenu();
254
- element.tributeMenu = this.menu;
255
- this.menuEvents.bind(this.menu);
256
- }
257
-
258
- this.isActive = true;
259
- this.menuSelected = 0;
260
-
261
- if (!this.current.mentionText) {
262
- this.current.mentionText = '';
263
- }
264
-
265
- var processValues = function processValues(values) {
266
- // Tribute may not be active any more by the time the value callback returns
267
- if (!_this2.isActive) {
268
- return;
269
- }
270
-
271
- var items = _this2.search.filter(_this2.current.mentionText, values, {
272
- pre: _this2.current.collection.searchOpts.pre || '<span>',
273
- post: _this2.current.collection.searchOpts.post || '</span>',
274
- skip: _this2.current.collection.searchOpts.skip,
275
- extract: function extract(el) {
276
- if (typeof _this2.current.collection.lookup === 'string') {
277
- return el[_this2.current.collection.lookup];
278
- } else if (typeof _this2.current.collection.lookup === 'function') {
279
- return _this2.current.collection.lookup(el, _this2.current.mentionText);
280
- } else {
281
- throw new Error('Invalid lookup attribute, lookup must be string or function.');
282
- }
283
- }
284
- });
285
-
286
- if (_this2.current.collection.menuItemLimit) {
287
- items = items.slice(0, _this2.current.collection.menuItemLimit);
288
- }
289
-
290
- _this2.current.filteredItems = items;
291
-
292
- var ul = _this2.menu.querySelector('ul');
293
-
294
- _this2.range.positionMenuAtCaret(scrollTo);
295
-
296
- if (!items.length) {
297
- var noMatchEvent = new CustomEvent('tribute-no-match', {
298
- detail: _this2.menu
299
- });
300
-
301
- _this2.current.element.dispatchEvent(noMatchEvent);
302
-
303
- if (typeof _this2.current.collection.noMatchTemplate === 'function' && !_this2.current.collection.noMatchTemplate() || !_this2.current.collection.noMatchTemplate) {
304
- _this2.hideMenu();
305
- } else {
306
- typeof _this2.current.collection.noMatchTemplate === 'function' ? ul.innerHTML = _this2.current.collection.noMatchTemplate() : ul.innerHTML = _this2.current.collection.noMatchTemplate;
307
- }
308
-
309
- return;
310
- }
311
-
312
- ul.innerHTML = '';
313
-
314
- var fragment = _this2.range.getDocument().createDocumentFragment();
315
-
316
- items.forEach(function (item, index) {
317
- var li = _this2.range.getDocument().createElement('li');
318
- li.setAttribute('role', 'option');
319
- li.setAttribute('data-index', index);
320
- li.addEventListener('mousemove', function (e) {
321
- var _this2$_findLiTarget = _this2._findLiTarget(e.target),
322
- _this2$_findLiTarget2 = _slicedToArray(_this2$_findLiTarget, 2),
323
- li = _this2$_findLiTarget2[0],
324
- index = _this2$_findLiTarget2[1];
325
-
326
- if (e.movementY !== 0) {
327
- _this2.events.setActiveLi(index);
328
- }
329
- });
330
-
331
- if (_this2.menuSelected === index) {
332
- li.className = _this2.current.collection.selectClass;
333
- }
334
-
335
- li.innerHTML = _this2.current.collection.menuItemTemplate(item);
336
- fragment.appendChild(li);
337
- });
338
- ul.appendChild(fragment);
339
- };
340
-
341
- if (typeof this.current.collection.values === 'function') {
342
- this.current.collection.values(this.current.mentionText, processValues);
343
- } else {
344
- processValues(this.current.collection.values);
345
- }
346
- }
347
- }, {
348
- key: "_findLiTarget",
349
- value: function _findLiTarget(el) {
350
- if (!el) return [];
351
- var index = el.getAttribute('data-index');
352
- return !index ? this._findLiTarget(el.parentNode) : [el, index];
353
- }
354
- }, {
355
- key: "showMenuForCollection",
356
- value: function showMenuForCollection(element, collectionIndex) {
357
- if (element !== document.activeElement) {
358
- this.placeCaretAtEnd(element);
359
- }
360
-
361
- this.current.collection = this.collection[collectionIndex || 0];
362
- this.current.externalTrigger = true;
363
- this.current.element = element;
364
- if (element.isContentEditable) this.insertTextAtCursor(this.current.collection.trigger);else this.insertAtCaret(element, this.current.collection.trigger);
365
- this.showMenuFor(element);
366
- } // TODO: make sure this works for inputs/textareas
367
-
368
- }, {
369
- key: "placeCaretAtEnd",
370
- value: function placeCaretAtEnd(el) {
371
- el.focus();
372
-
373
- if (typeof window.getSelection != "undefined" && typeof document.createRange != "undefined") {
374
- var range = document.createRange();
375
- range.selectNodeContents(el);
376
- range.collapse(false);
377
- var sel = window.getSelection();
378
- sel.removeAllRanges();
379
- sel.addRange(range);
380
- } else if (typeof document.body.createTextRange != "undefined") {
381
- var textRange = document.body.createTextRange();
382
- textRange.moveToElementText(el);
383
- textRange.collapse(false);
384
- textRange.select();
385
- }
386
- } // for contenteditable
387
-
388
- }, {
389
- key: "insertTextAtCursor",
390
- value: function insertTextAtCursor(text) {
391
- var sel, range, html;
392
- sel = window.getSelection();
393
- range = sel.getRangeAt(0);
394
- range.deleteContents();
395
- var textNode = document.createTextNode(text);
396
- range.insertNode(textNode);
397
- range.selectNodeContents(textNode);
398
- range.collapse(false);
399
- sel.removeAllRanges();
400
- sel.addRange(range);
401
- } // for regular inputs
402
-
403
- }, {
404
- key: "insertAtCaret",
405
- value: function insertAtCaret(textarea, text) {
406
- var scrollPos = textarea.scrollTop;
407
- var caretPos = textarea.selectionStart;
408
- var front = textarea.value.substring(0, caretPos);
409
- var back = textarea.value.substring(textarea.selectionEnd, textarea.value.length);
410
- textarea.value = front + text + back;
411
- caretPos = caretPos + text.length;
412
- textarea.selectionStart = caretPos;
413
- textarea.selectionEnd = caretPos;
414
- textarea.focus();
415
- textarea.scrollTop = scrollPos;
416
- }
417
- }, {
418
- key: "hideMenu",
419
- value: function hideMenu() {
420
- if (this.menu) {
421
- this.menu.style.cssText = 'display: none;';
422
- this.isActive = false;
423
- this.menuSelected = 0;
424
- this.current = {};
425
- }
426
- }
427
- }, {
428
- key: "selectItemAtIndex",
429
- value: function selectItemAtIndex(index, originalEvent) {
430
- index = parseInt(index);
431
- if (typeof index !== 'number' || isNaN(index)) return;
432
- var item = this.current.filteredItems[index];
433
- var content = this.current.collection.selectTemplate(item);
434
- if (content !== null) this.replaceText(content, originalEvent, item);
435
- }
436
- }, {
437
- key: "replaceText",
438
- value: function replaceText(content, originalEvent, item) {
439
- this.range.replaceTriggerText(content, true, true, originalEvent, item);
440
- }
441
- }, {
442
- key: "_append",
443
- value: function _append(collection, newValues, replace) {
444
- if (typeof collection.values === 'function') {
445
- throw new Error('Unable to append to values, as it is a function.');
446
- } else if (!replace) {
447
- collection.values = collection.values.concat(newValues);
448
- } else {
449
- collection.values = newValues;
450
- }
451
- }
452
- }, {
453
- key: "append",
454
- value: function append(collectionIndex, newValues, replace) {
455
- var index = parseInt(collectionIndex);
456
- if (typeof index !== 'number') throw new Error('please provide an index for the collection to update.');
457
- var collection = this.collection[index];
458
-
459
- this._append(collection, newValues, replace);
460
- }
461
- }, {
462
- key: "appendCurrent",
463
- value: function appendCurrent(newValues, replace) {
464
- if (this.isActive) {
465
- this._append(this.current.collection, newValues, replace);
466
- } else {
467
- throw new Error('No active state. Please use append instead and pass an index.');
468
- }
469
- }
470
- }, {
471
- key: "detach",
472
- value: function detach(el) {
473
- if (!el) {
474
- throw new Error('[Tribute] Must pass in a DOM node or NodeList.');
475
- } // Check if it is a jQuery collection
476
-
477
-
478
- if (typeof jQuery !== 'undefined' && el instanceof jQuery) {
479
- el = el.get();
480
- } // Is el an Array/Array-like object?
481
-
482
-
483
- if (el.constructor === NodeList || el.constructor === HTMLCollection || el.constructor === Array) {
484
- var length = el.length;
485
-
486
- for (var i = 0; i < length; ++i) {
487
- this._detach(el[i]);
488
- }
489
- } else {
490
- this._detach(el);
491
- }
492
- }
493
- }, {
494
- key: "_detach",
495
- value: function _detach(el) {
496
- var _this3 = this;
497
-
498
- this.events.unbind(el);
499
-
500
- if (el.tributeMenu) {
501
- this.menuEvents.unbind(el.tributeMenu);
502
- }
503
-
504
- setTimeout(function () {
505
- el.removeAttribute('data-tribute');
506
- _this3.isActive = false;
507
-
508
- if (el.tributeMenu) {
509
- el.tributeMenu.remove();
510
- }
511
- });
512
- }
513
- }], [{
514
- key: "defaultSelectTemplate",
515
- value: function defaultSelectTemplate(item) {
516
- if (typeof item === 'undefined') return null;
517
-
518
- if (this.range.isContentEditable(this.current.element)) {
519
- return '<span class="tribute-mention">' + (this.current.collection.trigger + item.original[this.current.collection.fillAttr]) + '</span>';
520
- }
521
-
522
- return this.current.collection.trigger + item.original[this.current.collection.fillAttr];
523
- }
524
- }, {
525
- key: "defaultMenuItemTemplate",
526
- value: function defaultMenuItemTemplate(matchItem) {
527
- return matchItem.string;
528
- }
529
- }, {
530
- key: "inputTypes",
531
- value: function inputTypes() {
532
- return ['TEXTAREA', 'INPUT'];
533
- }
534
- }]);
535
-
536
- return Tribute;
537
- }();
538
-
539
- var _default = Tribute;
540
- exports["default"] = _default;
541
- module.exports = exports.default;
542
-
543
- },{"./TributeEvents":2,"./TributeMenuEvents":3,"./TributeRange":4,"./TributeSearch":5,"./utils":7}],2:[function(require,module,exports){
544
- "use strict";
545
-
546
- Object.defineProperty(exports, "__esModule", {
547
- value: true
548
- });
549
- exports["default"] = void 0;
550
-
551
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
552
-
553
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
554
-
555
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
556
-
557
- var TributeEvents =
558
- /*#__PURE__*/
559
- function () {
560
- function TributeEvents(tribute) {
561
- _classCallCheck(this, TributeEvents);
562
-
563
- this.tribute = tribute;
564
- this.tribute.events = this;
565
- }
566
-
567
- _createClass(TributeEvents, [{
568
- key: "bind",
569
- value: function bind(element) {
570
- element.boundKeydown = this.keydown.bind(element, this);
571
- element.boundKeyup = this.keyup.bind(element, this);
572
- element.boundInput = this.input.bind(element, this);
573
- element.addEventListener('keydown', element.boundKeydown, false);
574
- element.addEventListener('keyup', element.boundKeyup, false);
575
- element.addEventListener('input', element.boundInput, false);
576
- }
577
- }, {
578
- key: "unbind",
579
- value: function unbind(element) {
580
- element.removeEventListener('keydown', element.boundKeydown, false);
581
- element.removeEventListener('keyup', element.boundKeyup, false);
582
- element.removeEventListener('input', element.boundInput, false);
583
- delete element.boundKeydown;
584
- delete element.boundKeyup;
585
- delete element.boundInput;
586
- }
587
- }, {
588
- key: "keydown",
589
- value: function keydown(instance, event) {
590
- if (instance.shouldDeactivate(event)) {
591
- instance.tribute.isActive = false;
592
- instance.tribute.hideMenu();
593
- }
594
-
595
- var element = this;
596
- instance.commandEvent = false;
597
- TributeEvents.keys().forEach(function (o) {
598
- if (o.key === event.keyCode) {
599
- instance.commandEvent = true;
600
- instance.callbacks()[o.value.toLowerCase()](event, element);
601
- }
602
- });
603
- }
604
- }, {
605
- key: "input",
606
- value: function input(instance, event) {
607
- instance.inputEvent = true;
608
- instance.keyup.call(this, instance, event);
609
- }
610
- }, {
611
- key: "click",
612
- value: function click(instance, event) {
613
- var tribute = instance.tribute;
614
-
615
- if (tribute.menu && tribute.menu.contains(event.target)) {
616
- var li = event.target;
617
- event.preventDefault();
618
- event.stopPropagation();
619
-
620
- while (li.nodeName.toLowerCase() !== 'li') {
621
- li = li.parentNode;
622
-
623
- if (!li || li === tribute.menu) {
624
- throw new Error('cannot find the <li> container for the click');
625
- }
626
- }
627
-
628
- if (li.getElementsByClassName("disabled-tribute-element")[0]==undefined){
629
- tribute.selectItemAtIndex(li.getAttribute('data-index'), event);
630
- tribute.hideMenu(); // TODO: should fire with externalTrigger and target is outside of menu
631
- }
632
- } else if (tribute.current.element && !tribute.current.externalTrigger) {
633
- tribute.current.externalTrigger = false;
634
- setTimeout(function () {
635
- return tribute.hideMenu();
636
- });
637
- }
638
- }
639
- }, {
640
- key: "keyup",
641
- value: function keyup(instance, event) {
642
- if (instance.inputEvent) {
643
- instance.inputEvent = false;
644
- }
645
-
646
- instance.updateSelection(this);
647
- if (event.keyCode === 27) return;
648
-
649
- if (!instance.tribute.allowSpaces && instance.tribute.hasTrailingSpace) {
650
- instance.tribute.hasTrailingSpace = false;
651
- instance.commandEvent = true;
652
- instance.callbacks()["space"](event, this);
653
- return;
654
- }
655
-
656
- if (!instance.tribute.isActive) {
657
- if (instance.tribute.autocompleteMode) {
658
- instance.callbacks().triggerChar(event, this, '');
659
- } else {
660
- var keyCode = instance.getKeyCode(instance, this, event);
661
- if (isNaN(keyCode) || !keyCode) return;
662
- var trigger = instance.tribute.triggers().find(function (trigger) {
663
- return trigger.charCodeAt(0) === keyCode;
664
- });
665
-
666
- if (typeof trigger !== 'undefined') {
667
- instance.callbacks().triggerChar(event, this, trigger);
668
- }
669
- }
670
- }
671
-
672
- if ((instance.tribute.current.trigger || instance.tribute.autocompleteMode) && instance.commandEvent === false || instance.tribute.isActive && event.keyCode === 8) {
673
- instance.tribute.showMenuFor(this, true);
674
- }
675
- }
676
- }, {
677
- key: "shouldDeactivate",
678
- value: function shouldDeactivate(event) {
679
- if (!this.tribute.isActive) return false;
680
-
681
- if (this.tribute.current.mentionText.length === 0) {
682
- var eventKeyPressed = false;
683
- TributeEvents.keys().forEach(function (o) {
684
- if (event.keyCode === o.key) eventKeyPressed = true;
685
- });
686
- return !eventKeyPressed;
687
- }
688
-
689
- return false;
690
- }
691
- }, {
692
- key: "getKeyCode",
693
- value: function getKeyCode(instance, el, event) {
694
- var _char;
695
-
696
- var tribute = instance.tribute;
697
- var info = tribute.range.getTriggerInfo(false, tribute.hasTrailingSpace, true, tribute.allowSpaces, tribute.autocompleteMode);
698
-
699
- if (info) {
700
- return info.mentionTriggerChar.charCodeAt(0);
701
- } else {
702
- return false;
703
- }
704
- }
705
- }, {
706
- key: "updateSelection",
707
- value: function updateSelection(el) {
708
- this.tribute.current.element = el;
709
- var info = this.tribute.range.getTriggerInfo(false, this.tribute.hasTrailingSpace, true, this.tribute.allowSpaces, this.tribute.autocompleteMode);
710
-
711
- if (info) {
712
- this.tribute.current.selectedPath = info.mentionSelectedPath;
713
- this.tribute.current.mentionText = info.mentionText;
714
- this.tribute.current.selectedOffset = info.mentionSelectedOffset;
715
- }
716
- }
717
- }, {
718
- key: "callbacks",
719
- value: function callbacks() {
720
- var _this = this;
721
-
722
- return {
723
- triggerChar: function triggerChar(e, el, trigger) {
724
- var tribute = _this.tribute;
725
- tribute.current.trigger = trigger;
726
- var collectionItem = tribute.collection.find(function (item) {
727
- return item.trigger === trigger;
728
- });
729
- tribute.current.collection = collectionItem;
730
- if (tribute.inputEvent) tribute.showMenuFor(el, true);
731
- },
732
- enter: function enter(e, el) {
733
- // choose selection
734
- if (_this.tribute.isActive && _this.tribute.current.filteredItems) {
735
- e.preventDefault();
736
- e.stopPropagation();
737
- setTimeout(function () {
738
- _this.tribute.selectItemAtIndex(_this.tribute.menuSelected, e);
739
-
740
- _this.tribute.hideMenu();
741
- }, 0);
742
- }
743
- },
744
- escape: function escape(e, el) {
745
- if (_this.tribute.isActive) {
746
- e.preventDefault();
747
- e.stopPropagation();
748
- _this.tribute.isActive = false;
749
-
750
- _this.tribute.hideMenu();
751
- }
752
- },
753
- tab: function tab(e, el) {
754
- // choose first match
755
- _this.callbacks().enter(e, el);
756
- },
757
- space: function space(e, el) {
758
- if (_this.tribute.isActive) {
759
- if (_this.tribute.spaceSelectsMatch) {
760
- _this.callbacks().enter(e, el);
761
- } else if (!_this.tribute.allowSpaces) {
762
- e.stopPropagation();
763
- setTimeout(function () {
764
- _this.tribute.hideMenu();
765
-
766
- _this.tribute.isActive = false;
767
- }, 0);
768
- }
769
- }
770
- },
771
- up: function up(e, el) {
772
- // navigate up ul
773
- if (_this.tribute.isActive && _this.tribute.current.filteredItems) {
774
- e.preventDefault();
775
- e.stopPropagation();
776
- var count = _this.tribute.current.filteredItems.length,
777
- selected = _this.tribute.menuSelected;
778
-
779
- if (count > selected && selected > 0) {
780
- _this.tribute.menuSelected--;
781
-
782
- _this.setActiveLi();
783
- } else if (selected === 0) {
784
- _this.tribute.menuSelected = count - 1;
785
-
786
- _this.setActiveLi();
787
-
788
- _this.tribute.menu.scrollTop = _this.tribute.menu.scrollHeight;
789
- }
790
- }
791
- },
792
- down: function down(e, el) {
793
- // navigate down ul
794
- if (_this.tribute.isActive && _this.tribute.current.filteredItems) {
795
- e.preventDefault();
796
- e.stopPropagation();
797
- var count = _this.tribute.current.filteredItems.length - 1,
798
- selected = _this.tribute.menuSelected;
799
-
800
- if (count > selected) {
801
- _this.tribute.menuSelected++;
802
-
803
- _this.setActiveLi();
804
- } else if (count === selected) {
805
- _this.tribute.menuSelected = 0;
806
-
807
- _this.setActiveLi();
808
-
809
- _this.tribute.menu.scrollTop = 0;
810
- }
811
- }
812
- },
813
- "delete": function _delete(e, el) {
814
- if (_this.tribute.isActive && _this.tribute.current.mentionText.length < 1) {
815
- _this.tribute.hideMenu();
816
- } else if (_this.tribute.isActive) {
817
- _this.tribute.showMenuFor(el);
818
- }
819
- }
820
- };
821
- }
822
- }, {
823
- key: "setActiveLi",
824
- value: function setActiveLi(index) {
825
- var lis = this.tribute.menu.querySelectorAll('li'),
826
- length = lis.length >>> 0;
827
- if (index) this.tribute.menuSelected = parseInt(index);
828
-
829
- for (var i = 0; i < length; i++) {
830
- var li = lis[i];
831
-
832
- if (i === this.tribute.menuSelected) {
833
- li.classList.add(this.tribute.current.collection.selectClass);
834
- var liClientRect = li.getBoundingClientRect();
835
- var menuClientRect = this.tribute.menu.getBoundingClientRect();
836
-
837
- if (liClientRect.bottom > menuClientRect.bottom) {
838
- var scrollDistance = liClientRect.bottom - menuClientRect.bottom;
839
- this.tribute.menu.scrollTop += scrollDistance;
840
- } else if (liClientRect.top < menuClientRect.top) {
841
- var _scrollDistance = menuClientRect.top - liClientRect.top;
842
-
843
- this.tribute.menu.scrollTop -= _scrollDistance;
844
- }
845
- } else {
846
- li.classList.remove(this.tribute.current.collection.selectClass);
847
- }
848
- }
849
- }
850
- }, {
851
- key: "getFullHeight",
852
- value: function getFullHeight(elem, includeMargin) {
853
- var height = elem.getBoundingClientRect().height;
854
-
855
- if (includeMargin) {
856
- var style = elem.currentStyle || window.getComputedStyle(elem);
857
- return height + parseFloat(style.marginTop) + parseFloat(style.marginBottom);
858
- }
859
-
860
- return height;
861
- }
862
- }], [{
863
- key: "keys",
864
- value: function keys() {
865
- return [{
866
- key: 9,
867
- value: 'TAB'
868
- }, {
869
- key: 8,
870
- value: 'DELETE'
871
- }, {
872
- key: 13,
873
- value: 'ENTER'
874
- }, {
875
- key: 27,
876
- value: 'ESCAPE'
877
- }, {
878
- key: 32,
879
- value: 'SPACE'
880
- }, {
881
- key: 38,
882
- value: 'UP'
883
- }, {
884
- key: 40,
885
- value: 'DOWN'
886
- }];
887
- }
888
- }]);
889
-
890
- return TributeEvents;
891
- }();
892
-
893
- var _default = TributeEvents;
894
- exports["default"] = _default;
895
- module.exports = exports.default;
896
-
897
- },{}],3:[function(require,module,exports){
898
- "use strict";
899
-
900
- Object.defineProperty(exports, "__esModule", {
901
- value: true
902
- });
903
- exports["default"] = void 0;
904
-
905
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
906
-
907
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
908
-
909
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
910
-
911
- var TributeMenuEvents =
912
- /*#__PURE__*/
913
- function () {
914
- function TributeMenuEvents(tribute) {
915
- _classCallCheck(this, TributeMenuEvents);
916
-
917
- this.tribute = tribute;
918
- this.tribute.menuEvents = this;
919
- this.menu = this.tribute.menu;
920
- }
921
-
922
- _createClass(TributeMenuEvents, [{
923
- key: "bind",
924
- value: function bind(menu) {
925
- var _this = this;
926
-
927
- this.menuClickEvent = this.tribute.events.click.bind(null, this);
928
- this.menuContainerScrollEvent = this.debounce(function () {
929
- if (_this.tribute.isActive) {
930
- _this.tribute.showMenuFor(_this.tribute.current.element, false);
931
- }
932
- }, 300, false);
933
- this.windowResizeEvent = this.debounce(function () {
934
- if (_this.tribute.isActive) {
935
- _this.tribute.range.positionMenuAtCaret(true);
936
- }
937
- }, 300, false); // fixes IE11 issues with mousedown
938
-
939
- this.tribute.range.getDocument().addEventListener('MSPointerDown', this.menuClickEvent, false);
940
- this.tribute.range.getDocument().addEventListener('mousedown', this.menuClickEvent, false);
941
- window.addEventListener('resize', this.windowResizeEvent);
942
-
943
- if (this.menuContainer) {
944
- this.menuContainer.addEventListener('scroll', this.menuContainerScrollEvent, false);
945
- } else {
946
- window.addEventListener('scroll', this.menuContainerScrollEvent);
947
- }
948
- }
949
- }, {
950
- key: "unbind",
951
- value: function unbind(menu) {
952
- this.tribute.range.getDocument().removeEventListener('mousedown', this.menuClickEvent, false);
953
- this.tribute.range.getDocument().removeEventListener('MSPointerDown', this.menuClickEvent, false);
954
- window.removeEventListener('resize', this.windowResizeEvent);
955
-
956
- if (this.menuContainer) {
957
- this.menuContainer.removeEventListener('scroll', this.menuContainerScrollEvent, false);
958
- } else {
959
- window.removeEventListener('scroll', this.menuContainerScrollEvent);
960
- }
961
- }
962
- }, {
963
- key: "debounce",
964
- value: function debounce(func, wait, immediate) {
965
- var _this2 = this,
966
- _arguments = arguments;
967
-
968
- var timeout;
969
- return function () {
970
- var context = _this2,
971
- args = _arguments;
972
-
973
- var later = function later() {
974
- timeout = null;
975
- if (!immediate) func.apply(context, args);
976
- };
977
-
978
- var callNow = immediate && !timeout;
979
- clearTimeout(timeout);
980
- timeout = setTimeout(later, wait);
981
- if (callNow) func.apply(context, args);
982
- };
983
- }
984
- }]);
985
-
986
- return TributeMenuEvents;
987
- }();
988
-
989
- var _default = TributeMenuEvents;
990
- exports["default"] = _default;
991
- module.exports = exports.default;
992
-
993
- },{}],4:[function(require,module,exports){
994
- "use strict";
995
-
996
- Object.defineProperty(exports, "__esModule", {
997
- value: true
998
- });
999
- exports["default"] = void 0;
1000
-
1001
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1002
-
1003
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
1004
-
1005
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
1006
-
1007
- // Thanks to https://github.com/jeff-collins/ment.io
1008
- var TributeRange =
1009
- /*#__PURE__*/
1010
- function () {
1011
- function TributeRange(tribute) {
1012
- _classCallCheck(this, TributeRange);
1013
-
1014
- this.tribute = tribute;
1015
- this.tribute.range = this;
1016
- }
1017
-
1018
- _createClass(TributeRange, [{
1019
- key: "getDocument",
1020
- value: function getDocument() {
1021
- var iframe;
1022
-
1023
- if (this.tribute.current.collection) {
1024
- iframe = this.tribute.current.collection.iframe;
1025
- }
1026
-
1027
- if (!iframe) {
1028
- return document;
1029
- }
1030
-
1031
- return iframe.contentWindow.document;
1032
- }
1033
- }, {
1034
- key: "positionMenuAtCaret",
1035
- value: function positionMenuAtCaret(scrollTo) {
1036
- var _this = this;
1037
-
1038
- var context = this.tribute.current,
1039
- coordinates;
1040
- var info = this.getTriggerInfo(false, this.tribute.hasTrailingSpace, true, this.tribute.allowSpaces, this.tribute.autocompleteMode);
1041
-
1042
- if (typeof info !== 'undefined') {
1043
- if (!this.tribute.positionMenu) {
1044
- this.tribute.menu.style.cssText = "display: block;";
1045
- return;
1046
- }
1047
-
1048
- if (!this.isContentEditable(context.element)) {
1049
- coordinates = this.getTextAreaOrInputUnderlinePosition(this.tribute.current.element, info.mentionPosition);
1050
- } else {
1051
- coordinates = this.getContentEditableCaretPosition(info.mentionPosition);
1052
- }
1053
-
1054
- this.tribute.menu.style.cssText = "top: ".concat(coordinates.top, "px;\n left: ").concat(coordinates.left, "px;\n right: ").concat(coordinates.right, "px;\n bottom: ").concat(coordinates.bottom, "px;\n position: absolute;\n display: block;");
1055
-
1056
- if (coordinates.left === 'auto') {
1057
- this.tribute.menu.style.left = 'auto';
1058
- }
1059
-
1060
- if (coordinates.top === 'auto') {
1061
- this.tribute.menu.style.top = 'auto';
1062
- }
1063
-
1064
- if (scrollTo) this.scrollIntoView();
1065
- window.setTimeout(function () {
1066
- var menuDimensions = {
1067
- width: _this.tribute.menu.offsetWidth,
1068
- height: _this.tribute.menu.offsetHeight
1069
- };
1070
-
1071
- var menuIsOffScreen = _this.isMenuOffScreen(coordinates, menuDimensions);
1072
-
1073
- var menuIsOffScreenHorizontally = window.innerWidth > menuDimensions.width && (menuIsOffScreen.left || menuIsOffScreen.right);
1074
- var menuIsOffScreenVertically = window.innerHeight > menuDimensions.height && (menuIsOffScreen.top || menuIsOffScreen.bottom);
1075
-
1076
- if (menuIsOffScreenHorizontally || menuIsOffScreenVertically) {
1077
- _this.tribute.menu.style.cssText = 'display: none';
1078
-
1079
- _this.positionMenuAtCaret(scrollTo);
1080
- }
1081
- }, 0);
1082
- } else {
1083
- this.tribute.menu.style.cssText = 'display: none';
1084
- }
1085
- }
1086
- }, {
1087
- key: "selectElement",
1088
- value: function selectElement(targetElement, path, offset) {
1089
- var range;
1090
- var elem = targetElement;
1091
-
1092
- if (path) {
1093
- for (var i = 0; i < path.length; i++) {
1094
- elem = elem.childNodes[path[i]];
1095
-
1096
- if (elem === undefined) {
1097
- return;
1098
- }
1099
-
1100
- while (elem.length < offset) {
1101
- offset -= elem.length;
1102
- elem = elem.nextSibling;
1103
- }
1104
-
1105
- if (elem.childNodes.length === 0 && !elem.length) {
1106
- elem = elem.previousSibling;
1107
- }
1108
- }
1109
- }
1110
-
1111
- var sel = this.getWindowSelection();
1112
- range = this.getDocument().createRange();
1113
- range.setStart(elem, offset);
1114
- range.setEnd(elem, offset);
1115
- range.collapse(true);
1116
-
1117
- try {
1118
- sel.removeAllRanges();
1119
- } catch (error) {}
1120
-
1121
- sel.addRange(range);
1122
- targetElement.focus();
1123
- }
1124
- }, {
1125
- key: "replaceTriggerText",
1126
- value: function replaceTriggerText(text, requireLeadingSpace, hasTrailingSpace, originalEvent, item) {
1127
- var info = this.getTriggerInfo(true, hasTrailingSpace, requireLeadingSpace, this.tribute.allowSpaces, this.tribute.autocompleteMode);
1128
-
1129
- if (info !== undefined) {
1130
- var context = this.tribute.current;
1131
- var replaceEvent = new CustomEvent('tribute-replaced', {
1132
- detail: {
1133
- item: item,
1134
- instance: context,
1135
- context: info,
1136
- event: originalEvent
1137
- }
1138
- });
1139
-
1140
- if (!this.isContentEditable(context.element)) {
1141
- var myField = this.tribute.current.element;
1142
- var textSuffix = typeof this.tribute.replaceTextSuffix == 'string' ? this.tribute.replaceTextSuffix : ' ';
1143
- text += textSuffix;
1144
- var startPos = info.mentionPosition;
1145
- var endPos = info.mentionPosition + info.mentionText.length + textSuffix.length;
1146
- myField.value = myField.value.substring(0, startPos) + text + myField.value.substring(endPos, myField.value.length);
1147
- myField.selectionStart = startPos + text.length;
1148
- myField.selectionEnd = startPos + text.length;
1149
- } else {
1150
- // add a space to the end of the pasted text
1151
- var _textSuffix = typeof this.tribute.replaceTextSuffix == 'string' ? this.tribute.replaceTextSuffix : '\xA0';
1152
-
1153
- text += _textSuffix;
1154
- this.pasteHtml(text, info.mentionPosition, info.mentionPosition + info.mentionText.length + !this.tribute.autocompleteMode);
1155
- }
1156
-
1157
- context.element.dispatchEvent(replaceEvent);
1158
- }
1159
- }
1160
- }, {
1161
- key: "pasteHtml",
1162
- value: function pasteHtml(html, startPos, endPos) {
1163
- var range, sel;
1164
- sel = this.getWindowSelection();
1165
- range = this.getDocument().createRange();
1166
- range.setStart(sel.anchorNode, startPos);
1167
- range.setEnd(sel.anchorNode, endPos);
1168
- range.deleteContents();
1169
- var el = this.getDocument().createElement('div');
1170
- el.innerHTML = html;
1171
- var frag = this.getDocument().createDocumentFragment(),
1172
- node,
1173
- lastNode;
1174
-
1175
- while (node = el.firstChild) {
1176
- lastNode = frag.appendChild(node);
1177
- }
1178
-
1179
- range.insertNode(frag); // Preserve the selection
1180
-
1181
- if (lastNode) {
1182
- range = range.cloneRange();
1183
- range.setStartAfter(lastNode);
1184
- range.collapse(true);
1185
- sel.removeAllRanges();
1186
- sel.addRange(range);
1187
- }
1188
- }
1189
- }, {
1190
- key: "getWindowSelection",
1191
- value: function getWindowSelection() {
1192
- if (this.tribute.collection.iframe) {
1193
- return this.tribute.collection.iframe.contentWindow.getSelection();
1194
- }
1195
-
1196
- return window.getSelection();
1197
- }
1198
- }, {
1199
- key: "getNodePositionInParent",
1200
- value: function getNodePositionInParent(element) {
1201
- if (element.parentNode === null) {
1202
- return 0;
1203
- }
1204
-
1205
- for (var i = 0; i < element.parentNode.childNodes.length; i++) {
1206
- var node = element.parentNode.childNodes[i];
1207
-
1208
- if (node === element) {
1209
- return i;
1210
- }
1211
- }
1212
- }
1213
- }, {
1214
- key: "getContentEditableSelectedPath",
1215
- value: function getContentEditableSelectedPath(ctx) {
1216
- var sel = this.getWindowSelection();
1217
- var selected = sel.anchorNode;
1218
- var path = [];
1219
- var offset;
1220
-
1221
- if (selected != null) {
1222
- var i;
1223
- var ce = selected.contentEditable;
1224
-
1225
- while (selected !== null && ce !== 'true') {
1226
- i = this.getNodePositionInParent(selected);
1227
- path.push(i);
1228
- selected = selected.parentNode;
1229
-
1230
- if (selected !== null) {
1231
- ce = selected.contentEditable;
1232
- }
1233
- }
1234
-
1235
- path.reverse(); // getRangeAt may not exist, need alternative
1236
-
1237
- offset = sel.getRangeAt(0).startOffset;
1238
- return {
1239
- selected: selected,
1240
- path: path,
1241
- offset: offset
1242
- };
1243
- }
1244
- }
1245
- }, {
1246
- key: "getTextPrecedingCurrentSelection",
1247
- value: function getTextPrecedingCurrentSelection() {
1248
- var context = this.tribute.current,
1249
- text = '';
1250
-
1251
- if (!this.isContentEditable(context.element)) {
1252
- var textComponent = this.tribute.current.element;
1253
-
1254
- if (textComponent) {
1255
- var startPos = textComponent.selectionStart;
1256
-
1257
- if (textComponent.value && startPos >= 0) {
1258
- text = textComponent.value.substring(0, startPos);
1259
- }
1260
- }
1261
- } else {
1262
- var selectedElem = this.getWindowSelection().anchorNode;
1263
-
1264
- if (selectedElem != null) {
1265
- var workingNodeContent = selectedElem.textContent;
1266
- var selectStartOffset = this.getWindowSelection().getRangeAt(0).startOffset;
1267
-
1268
- if (workingNodeContent && selectStartOffset >= 0) {
1269
- text = workingNodeContent.substring(0, selectStartOffset);
1270
- }
1271
- }
1272
- }
1273
-
1274
- return text;
1275
- }
1276
- }, {
1277
- key: "getLastWordInText",
1278
- value: function getLastWordInText(text) {
1279
- text = text.replace(/\u00A0/g, ' '); // https://stackoverflow.com/questions/29850407/how-do-i-replace-unicode-character-u00a0-with-a-space-in-javascript
1280
-
1281
- var wordsArray = text.split(/\s+/);
1282
- var worldsCount = wordsArray.length - 1;
1283
- return wordsArray[worldsCount].trim();
1284
- }
1285
- }, {
1286
- key: "getTriggerInfo",
1287
- value: function getTriggerInfo(menuAlreadyActive, hasTrailingSpace, requireLeadingSpace, allowSpaces, isAutocomplete) {
1288
- var _this2 = this;
1289
-
1290
- var ctx = this.tribute.current;
1291
- var selected, path, offset;
1292
-
1293
- if (!this.isContentEditable(ctx.element)) {
1294
- selected = this.tribute.current.element;
1295
- } else {
1296
- var selectionInfo = this.getContentEditableSelectedPath(ctx);
1297
-
1298
- if (selectionInfo) {
1299
- selected = selectionInfo.selected;
1300
- path = selectionInfo.path;
1301
- offset = selectionInfo.offset;
1302
- }
1303
- }
1304
-
1305
- var effectiveRange = this.getTextPrecedingCurrentSelection();
1306
- var lastWordOfEffectiveRange = this.getLastWordInText(effectiveRange);
1307
-
1308
- if (isAutocomplete) {
1309
- return {
1310
- mentionPosition: effectiveRange.length - lastWordOfEffectiveRange.length,
1311
- mentionText: lastWordOfEffectiveRange,
1312
- mentionSelectedElement: selected,
1313
- mentionSelectedPath: path,
1314
- mentionSelectedOffset: offset
1315
- };
1316
- }
1317
-
1318
- if (effectiveRange !== undefined && effectiveRange !== null) {
1319
- var mostRecentTriggerCharPos = -1;
1320
- var triggerChar;
1321
- this.tribute.collection.forEach(function (config) {
1322
- var c = config.trigger;
1323
- var idx = config.requireLeadingSpace ? _this2.lastIndexWithLeadingSpace(effectiveRange, c) : effectiveRange.lastIndexOf(c);
1324
-
1325
- if (idx > mostRecentTriggerCharPos) {
1326
- mostRecentTriggerCharPos = idx;
1327
- triggerChar = c;
1328
- requireLeadingSpace = config.requireLeadingSpace;
1329
- }
1330
- });
1331
-
1332
- if (mostRecentTriggerCharPos >= 0 && (mostRecentTriggerCharPos === 0 || !requireLeadingSpace || /[\xA0\s]/g.test(effectiveRange.substring(mostRecentTriggerCharPos - 1, mostRecentTriggerCharPos)))) {
1333
- var currentTriggerSnippet = effectiveRange.substring(mostRecentTriggerCharPos + 1, effectiveRange.length);
1334
- triggerChar = effectiveRange.substring(mostRecentTriggerCharPos, mostRecentTriggerCharPos + 1);
1335
- var firstSnippetChar = currentTriggerSnippet.substring(0, 1);
1336
- var leadingSpace = currentTriggerSnippet.length > 0 && (firstSnippetChar === ' ' || firstSnippetChar === '\xA0');
1337
-
1338
- if (hasTrailingSpace) {
1339
- currentTriggerSnippet = currentTriggerSnippet.trim();
1340
- }
1341
-
1342
- var regex = allowSpaces ? /[^\S ]/g : /[\xA0\s]/g;
1343
- this.tribute.hasTrailingSpace = regex.test(currentTriggerSnippet);
1344
-
1345
- if (!leadingSpace && (menuAlreadyActive || !regex.test(currentTriggerSnippet))) {
1346
- return {
1347
- mentionPosition: mostRecentTriggerCharPos,
1348
- mentionText: currentTriggerSnippet,
1349
- mentionSelectedElement: selected,
1350
- mentionSelectedPath: path,
1351
- mentionSelectedOffset: offset,
1352
- mentionTriggerChar: triggerChar
1353
- };
1354
- }
1355
- }
1356
- }
1357
- }
1358
- }, {
1359
- key: "lastIndexWithLeadingSpace",
1360
- value: function lastIndexWithLeadingSpace(str, _char) {
1361
- var reversedStr = str.split('').reverse().join('');
1362
- var index = -1;
1363
-
1364
- for (var cidx = 0, len = str.length; cidx < len; cidx++) {
1365
- var firstChar = cidx === str.length - 1;
1366
- var leadingSpace = /\s/.test(reversedStr[cidx + 1]);
1367
- var match = _char === reversedStr[cidx];
1368
-
1369
- if (match && (firstChar || leadingSpace)) {
1370
- index = str.length - 1 - cidx;
1371
- break;
1372
- }
1373
- }
1374
-
1375
- return index;
1376
- }
1377
- }, {
1378
- key: "isContentEditable",
1379
- value: function isContentEditable(element) {
1380
- return element.nodeName !== 'INPUT' && element.nodeName !== 'TEXTAREA';
1381
- }
1382
- }, {
1383
- key: "isMenuOffScreen",
1384
- value: function isMenuOffScreen(coordinates, menuDimensions) {
1385
- var windowWidth = window.innerWidth;
1386
- var windowHeight = window.innerHeight;
1387
- var doc = document.documentElement;
1388
- var windowLeft = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
1389
- var windowTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
1390
- var menuTop = typeof coordinates.top === 'number' ? coordinates.top : windowTop + windowHeight - coordinates.bottom - menuDimensions.height;
1391
- var menuRight = typeof coordinates.right === 'number' ? coordinates.right : coordinates.left + menuDimensions.width;
1392
- var menuBottom = typeof coordinates.bottom === 'number' ? coordinates.bottom : coordinates.top + menuDimensions.height;
1393
- var menuLeft = typeof coordinates.left === 'number' ? coordinates.left : windowLeft + windowWidth - coordinates.right - menuDimensions.width;
1394
- return {
1395
- top: menuTop < Math.floor(windowTop),
1396
- right: menuRight > Math.ceil(windowLeft + windowWidth),
1397
- bottom: menuBottom > Math.ceil(windowTop + windowHeight),
1398
- left: menuLeft < Math.floor(windowLeft)
1399
- };
1400
- }
1401
- }, {
1402
- key: "getMenuDimensions",
1403
- value: function getMenuDimensions() {
1404
- // Width of the menu depends of its contents and position
1405
- // We must check what its width would be without any obstruction
1406
- // This way, we can achieve good positioning for flipping the menu
1407
- var dimensions = {
1408
- width: null,
1409
- height: null
1410
- };
1411
- this.tribute.menu.style.cssText = "top: 0px;\n left: 0px;\n position: fixed;\n display: block;\n visibility; hidden;";
1412
- dimensions.width = this.tribute.menu.offsetWidth;
1413
- dimensions.height = this.tribute.menu.offsetHeight;
1414
- this.tribute.menu.style.cssText = "display: none;";
1415
- return dimensions;
1416
- }
1417
- }, {
1418
- key: "getTextAreaOrInputUnderlinePosition",
1419
- value: function getTextAreaOrInputUnderlinePosition(element, position, flipped) {
1420
- var properties = ['direction', 'boxSizing', 'width', 'height', 'overflowX', 'overflowY', 'borderTopWidth', 'borderRightWidth', 'borderBottomWidth', 'borderLeftWidth', 'paddingTop', 'paddingRight', 'paddingBottom', 'paddingLeft', 'fontStyle', 'fontVariant', 'fontWeight', 'fontStretch', 'fontSize', 'fontSizeAdjust', 'lineHeight', 'fontFamily', 'textAlign', 'textTransform', 'textIndent', 'textDecoration', 'letterSpacing', 'wordSpacing'];
1421
- var isFirefox = window.mozInnerScreenX !== null;
1422
- var div = this.getDocument().createElement('div');
1423
- div.id = 'input-textarea-caret-position-mirror-div';
1424
- this.getDocument().body.appendChild(div);
1425
- var style = div.style;
1426
- var computed = window.getComputedStyle ? getComputedStyle(element) : element.currentStyle;
1427
- style.whiteSpace = 'pre-wrap';
1428
-
1429
- if (element.nodeName !== 'INPUT') {
1430
- style.wordWrap = 'break-word';
1431
- } // position off-screen
1432
-
1433
-
1434
- style.position = 'absolute';
1435
- style.visibility = 'hidden'; // transfer the element's properties to the div
1436
-
1437
- properties.forEach(function (prop) {
1438
- style[prop] = computed[prop];
1439
- });
1440
-
1441
- if (isFirefox) {
1442
- style.width = "".concat(parseInt(computed.width) - 2, "px");
1443
- if (element.scrollHeight > parseInt(computed.height)) style.overflowY = 'scroll';
1444
- } else {
1445
- style.overflow = 'hidden';
1446
- }
1447
-
1448
- div.textContent = element.value.substring(0, position);
1449
-
1450
- if (element.nodeName === 'INPUT') {
1451
- div.textContent = div.textContent.replace(/\s/g, ' ');
1452
- }
1453
-
1454
- var span = this.getDocument().createElement('span');
1455
- span.textContent = element.value.substring(position) || '.';
1456
- div.appendChild(span);
1457
- var rect = element.getBoundingClientRect();
1458
- var doc = document.documentElement;
1459
- var windowLeft = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
1460
- var windowTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
1461
- var top = 0;
1462
- var left = 0;
1463
-
1464
- if (this.menuContainerIsBody) {
1465
- top = rect.top;
1466
- left = rect.left;
1467
- }
1468
-
1469
- var coordinates = {
1470
- top: top + windowTop + span.offsetTop + parseInt(computed.borderTopWidth) + parseInt(computed.fontSize) - element.scrollTop,
1471
- left: left + windowLeft + span.offsetLeft + parseInt(computed.borderLeftWidth)
1472
- };
1473
- var windowWidth = window.innerWidth;
1474
- var windowHeight = window.innerHeight;
1475
- var menuDimensions = this.getMenuDimensions();
1476
- var menuIsOffScreen = this.isMenuOffScreen(coordinates, menuDimensions);
1477
-
1478
- if (menuIsOffScreen.right) {
1479
- coordinates.right = windowWidth - coordinates.left;
1480
- coordinates.left = 'auto';
1481
- }
1482
-
1483
- var parentHeight = this.tribute.menuContainer ? this.tribute.menuContainer.offsetHeight : this.getDocument().body.offsetHeight;
1484
-
1485
- if (menuIsOffScreen.bottom) {
1486
- var parentRect = this.tribute.menuContainer ? this.tribute.menuContainer.getBoundingClientRect() : this.getDocument().body.getBoundingClientRect();
1487
- var scrollStillAvailable = parentHeight - (windowHeight - parentRect.top);
1488
- coordinates.bottom = scrollStillAvailable + (windowHeight - rect.top - span.offsetTop);
1489
- coordinates.top = 'auto';
1490
- }
1491
-
1492
- menuIsOffScreen = this.isMenuOffScreen(coordinates, menuDimensions);
1493
-
1494
- if (menuIsOffScreen.left) {
1495
- coordinates.left = windowWidth > menuDimensions.width ? windowLeft + windowWidth - menuDimensions.width : windowLeft;
1496
- delete coordinates.right;
1497
- }
1498
-
1499
- if (menuIsOffScreen.top) {
1500
- coordinates.top = windowHeight > menuDimensions.height ? windowTop + windowHeight - menuDimensions.height : windowTop;
1501
- delete coordinates.bottom;
1502
- }
1503
-
1504
- this.getDocument().body.removeChild(div);
1505
- return coordinates;
1506
- }
1507
- }, {
1508
- key: "getContentEditableCaretPosition",
1509
- value: function getContentEditableCaretPosition(selectedNodePosition) {
1510
- var markerTextChar = '';
1511
- var markerEl,
1512
- markerId = "sel_".concat(new Date().getTime(), "_").concat(Math.random().toString().substr(2));
1513
- var range;
1514
- var sel = this.getWindowSelection();
1515
- var prevRange = sel.getRangeAt(0);
1516
- range = this.getDocument().createRange();
1517
- range.setStart(sel.anchorNode, selectedNodePosition);
1518
- range.setEnd(sel.anchorNode, selectedNodePosition);
1519
- range.collapse(false); // Create the marker element containing a single invisible character using DOM methods and insert it
1520
-
1521
- markerEl = this.getDocument().createElement('span');
1522
- markerEl.id = markerId;
1523
- markerEl.appendChild(this.getDocument().createTextNode(markerTextChar));
1524
- range.insertNode(markerEl);
1525
- sel.removeAllRanges();
1526
- sel.addRange(prevRange);
1527
- var rect = markerEl.getBoundingClientRect();
1528
- var doc = document.documentElement;
1529
- var windowLeft = (window.pageXOffset || doc.scrollLeft) - (doc.clientLeft || 0);
1530
- var windowTop = (window.pageYOffset || doc.scrollTop) - (doc.clientTop || 0);
1531
- var left = 0;
1532
- var top = 0;
1533
-
1534
- if (this.menuContainerIsBody) {
1535
- left = rect.left;
1536
- top = rect.top;
1537
- } else {
1538
- left = markerEl.offsetLeft;
1539
- top = markerEl.offsetTop;
1540
- }
1541
-
1542
- var coordinates = {
1543
- left: left + windowLeft,
1544
- top: top + markerEl.offsetHeight + windowTop
1545
- };
1546
- var windowWidth = window.innerWidth;
1547
- var windowHeight = window.innerHeight;
1548
- var menuDimensions = this.getMenuDimensions();
1549
- var menuIsOffScreen = this.isMenuOffScreen(coordinates, menuDimensions);
1550
-
1551
- if (menuIsOffScreen.right) {
1552
- coordinates.left = 'auto';
1553
- coordinates.right = windowWidth - rect.left - windowLeft;
1554
- }
1555
-
1556
- var parentHeight = this.tribute.menuContainer ? this.tribute.menuContainer.offsetHeight : this.getDocument().body.offsetHeight;
1557
-
1558
- if (menuIsOffScreen.bottom) {
1559
- var parentRect = this.tribute.menuContainer ? this.tribute.menuContainer.getBoundingClientRect() : this.getDocument().body.getBoundingClientRect();
1560
- var scrollStillAvailable = parentHeight - (windowHeight - parentRect.top);
1561
- coordinates.top = 'auto';
1562
- coordinates.bottom = scrollStillAvailable + (windowHeight - rect.top);
1563
- }
1564
-
1565
- menuIsOffScreen = this.isMenuOffScreen(coordinates, menuDimensions);
1566
-
1567
- if (menuIsOffScreen.left) {
1568
- coordinates.left = windowWidth > menuDimensions.width ? windowLeft + windowWidth - menuDimensions.width : windowLeft;
1569
- delete coordinates.right;
1570
- }
1571
-
1572
- if (menuIsOffScreen.top) {
1573
- coordinates.top = windowHeight > menuDimensions.height ? windowTop + windowHeight - menuDimensions.height : windowTop;
1574
- delete coordinates.bottom;
1575
- }
1576
-
1577
- markerEl.parentNode.removeChild(markerEl);
1578
- return coordinates;
1579
- }
1580
- }, {
1581
- key: "scrollIntoView",
1582
- value: function scrollIntoView(elem) {
1583
- var reasonableBuffer = 20,
1584
- clientRect;
1585
- var maxScrollDisplacement = 100;
1586
- var e = this.menu;
1587
- if (typeof e === 'undefined') return;
1588
-
1589
- while (clientRect === undefined || clientRect.height === 0) {
1590
- clientRect = e.getBoundingClientRect();
1591
-
1592
- if (clientRect.height === 0) {
1593
- e = e.childNodes[0];
1594
-
1595
- if (e === undefined || !e.getBoundingClientRect) {
1596
- return;
1597
- }
1598
- }
1599
- }
1600
-
1601
- var elemTop = clientRect.top;
1602
- var elemBottom = elemTop + clientRect.height;
1603
-
1604
- if (elemTop < 0) {
1605
- window.scrollTo(0, window.pageYOffset + clientRect.top - reasonableBuffer);
1606
- } else if (elemBottom > window.innerHeight) {
1607
- var maxY = window.pageYOffset + clientRect.top - reasonableBuffer;
1608
-
1609
- if (maxY - window.pageYOffset > maxScrollDisplacement) {
1610
- maxY = window.pageYOffset + maxScrollDisplacement;
1611
- }
1612
-
1613
- var targetY = window.pageYOffset - (window.innerHeight - elemBottom);
1614
-
1615
- if (targetY > maxY) {
1616
- targetY = maxY;
1617
- }
1618
-
1619
- window.scrollTo(0, targetY);
1620
- }
1621
- }
1622
- }, {
1623
- key: "menuContainerIsBody",
1624
- get: function get() {
1625
- return this.tribute.menuContainer === document.body || !this.tribute.menuContainer;
1626
- }
1627
- }]);
1628
-
1629
- return TributeRange;
1630
- }();
1631
-
1632
- var _default = TributeRange;
1633
- exports["default"] = _default;
1634
- module.exports = exports.default;
1635
-
1636
- },{}],5:[function(require,module,exports){
1637
- "use strict";
1638
-
1639
- Object.defineProperty(exports, "__esModule", {
1640
- value: true
1641
- });
1642
- exports["default"] = void 0;
1643
-
1644
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
1645
-
1646
- function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
1647
-
1648
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
1649
-
1650
- // Thanks to https://github.com/mattyork/fuzzy
1651
- var TributeSearch =
1652
- /*#__PURE__*/
1653
- function () {
1654
- function TributeSearch(tribute) {
1655
- _classCallCheck(this, TributeSearch);
1656
-
1657
- this.tribute = tribute;
1658
- this.tribute.search = this;
1659
- }
1660
-
1661
- _createClass(TributeSearch, [{
1662
- key: "simpleFilter",
1663
- value: function simpleFilter(pattern, array) {
1664
- var _this = this;
1665
-
1666
- return array.filter(function (string) {
1667
- return _this.test(pattern, string);
1668
- });
1669
- }
1670
- }, {
1671
- key: "test",
1672
- value: function test(pattern, string) {
1673
- return this.match(pattern, string) !== null;
1674
- }
1675
- }, {
1676
- key: "match",
1677
- value: function match(pattern, string, opts) {
1678
- opts = opts || {};
1679
- var patternIdx = 0,
1680
- result = [],
1681
- len = string.length,
1682
- totalScore = 0,
1683
- currScore = 0,
1684
- pre = opts.pre || '',
1685
- post = opts.post || '',
1686
- compareString = opts.caseSensitive && string || string.toLowerCase(),
1687
- ch,
1688
- compareChar;
1689
-
1690
- if (opts.skip) {
1691
- return {
1692
- rendered: string,
1693
- score: 0
1694
- };
1695
- }
1696
-
1697
- pattern = opts.caseSensitive && pattern || pattern.toLowerCase();
1698
- var patternCache = this.traverse(compareString, pattern, 0, 0, []);
1699
-
1700
- if (!patternCache) {
1701
- return null;
1702
- }
1703
-
1704
- return {
1705
- rendered: this.render(string, patternCache.cache, pre, post),
1706
- score: patternCache.score
1707
- };
1708
- }
1709
- }, {
1710
- key: "traverse",
1711
- value: function traverse(string, pattern, stringIndex, patternIndex, patternCache) {
1712
- // if the pattern search at end
1713
- if (pattern.length === patternIndex) {
1714
- // calculate score and copy the cache containing the indices where it is found
1715
- return {
1716
- score: this.calculateScore(patternCache),
1717
- cache: patternCache.slice()
1718
- };
1719
- } // if string at end or remaining pattern > remaining string
1720
-
1721
-
1722
- if (string.length === stringIndex || pattern.length - patternIndex > string.length - stringIndex) {
1723
- return undefined;
1724
- }
1725
-
1726
- var c = pattern[patternIndex];
1727
- var index = string.indexOf(c, stringIndex);
1728
- var best, temp;
1729
-
1730
- while (index > -1) {
1731
- patternCache.push(index);
1732
- temp = this.traverse(string, pattern, index + 1, patternIndex + 1, patternCache);
1733
- patternCache.pop(); // if downstream traversal failed, return best answer so far
1734
-
1735
- if (!temp) {
1736
- return best;
1737
- }
1738
-
1739
- if (!best || best.score < temp.score) {
1740
- best = temp;
1741
- }
1742
-
1743
- index = string.indexOf(c, index + 1);
1744
- }
1745
-
1746
- return best;
1747
- }
1748
- }, {
1749
- key: "calculateScore",
1750
- value: function calculateScore(patternCache) {
1751
- var score = 0;
1752
- var temp = 1;
1753
- patternCache.forEach(function (index, i) {
1754
- if (i > 0) {
1755
- if (patternCache[i - 1] + 1 === index) {
1756
- temp += temp + 1;
1757
- } else {
1758
- temp = 1;
1759
- }
1760
- }
1761
-
1762
- score += temp;
1763
- });
1764
- return score;
1765
- }
1766
- }, {
1767
- key: "render",
1768
- value: function render(string, indices, pre, post) {
1769
- var rendered = string.substring(0, indices[0]);
1770
- indices.forEach(function (index, i) {
1771
- rendered += pre + string[index] + post + string.substring(index + 1, indices[i + 1] ? indices[i + 1] : string.length);
1772
- });
1773
- return rendered;
1774
- }
1775
- }, {
1776
- key: "filter",
1777
- value: function filter(pattern, arr, opts) {
1778
- var _this2 = this;
1779
-
1780
- opts = opts || {};
1781
- return arr.reduce(function (prev, element, idx, arr) {
1782
- var str = element;
1783
-
1784
- if (opts.extract) {
1785
- str = opts.extract(element);
1786
-
1787
- if (!str) {
1788
- // take care of undefineds / nulls / etc.
1789
- str = '';
1790
- }
1791
- }
1792
-
1793
- var rendered = _this2.match(pattern, str, opts);
1794
-
1795
- if (rendered != null) {
1796
- prev[prev.length] = {
1797
- string: rendered.rendered,
1798
- score: rendered.score,
1799
- index: idx,
1800
- original: element
1801
- };
1802
- }
1803
-
1804
- return prev;
1805
- }, []).sort(function (a, b) {
1806
- var compare = b.score - a.score;
1807
- if (compare) return compare;
1808
- return a.index - b.index;
1809
- });
1810
- }
1811
- }]);
1812
-
1813
- return TributeSearch;
1814
- }();
1815
-
1816
- var _default = TributeSearch;
1817
- exports["default"] = _default;
1818
- module.exports = exports.default;
1819
-
1820
- },{}],6:[function(require,module,exports){
1821
- "use strict";
1822
-
1823
- Object.defineProperty(exports, "__esModule", {
1824
- value: true
1825
- });
1826
- exports["default"] = void 0;
1827
-
1828
- var _Tribute = _interopRequireDefault(require("./Tribute"));
1829
-
1830
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
1831
-
1832
- /**
1833
- * Tribute.js
1834
- * Native ES6 JavaScript @mention Plugin
1835
- **/
1836
- var _default = _Tribute["default"];
1837
- exports["default"] = _default;
1838
- module.exports = exports.default;
1839
-
1840
- },{"./Tribute":1}],7:[function(require,module,exports){
1841
- "use strict";
1842
-
1843
- if (!Array.prototype.find) {
1844
- Array.prototype.find = function (predicate) {
1845
- if (this === null) {
1846
- throw new TypeError('Array.prototype.find called on null or undefined');
1847
- }
1848
-
1849
- if (typeof predicate !== 'function') {
1850
- throw new TypeError('predicate must be a function');
1851
- }
1852
-
1853
- var list = Object(this);
1854
- var length = list.length >>> 0;
1855
- var thisArg = arguments[1];
1856
- var value;
1857
-
1858
- for (var i = 0; i < length; i++) {
1859
- value = list[i];
1860
-
1861
- if (predicate.call(thisArg, value, i, list)) {
1862
- return value;
1863
- }
1864
- }
1865
-
1866
- return undefined;
1867
- };
1868
- }
1869
-
1870
- if (window && typeof window.CustomEvent !== "function") {
1871
- var CustomEvent = function CustomEvent(event, params) {
1872
- params = params || {
1873
- bubbles: false,
1874
- cancelable: false,
1875
- detail: undefined
1876
- };
1877
- var evt = document.createEvent('CustomEvent');
1878
- evt.initCustomEvent(event, params.bubbles, params.cancelable, params.detail);
1879
- return evt;
1880
- };
1881
-
1882
- if (typeof window.Event !== 'undefined') {
1883
- CustomEvent.prototype = window.Event.prototype;
1884
- }
1885
-
1886
- window.CustomEvent = CustomEvent;
1887
- }
1888
-
1889
- },{}]},{},[6])(6)
1890
- });