@inboxsdk/core 1.1.0 → 1.1.2

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 (81) hide show
  1. package/inboxsdk.js +7 -34
  2. package/inboxsdk.js.map +1 -1
  3. package/package.json +1 -1
  4. package/pageWorld.js +1 -1
  5. package/pageWorld.js.map +1 -1
  6. package/src/common/version.d.ts.map +1 -1
  7. package/src/common/version.js +3 -1
  8. package/src/injected-js/main.js +0 -9
  9. package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/index.test.js +6 -2
  10. package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/primary/index.js +4 -2
  11. package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-sidebar-view.js +4 -2
  12. package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-sidebar-view.test.js +6 -2
  13. package/src/platform-implementation-js/driver-common/sidebar/ContentPanelViewDriver.js +2 -2
  14. package/src/platform-implementation-js/driver-common/sidebar/constants.d.ts +9 -0
  15. package/src/platform-implementation-js/driver-common/sidebar/constants.d.ts.map +1 -0
  16. package/src/platform-implementation-js/driver-common/sidebar/constants.js +26 -0
  17. package/src/platform-implementation-js/lib/idMap.d.ts +7 -0
  18. package/src/platform-implementation-js/lib/idMap.d.ts.map +1 -1
  19. package/src/platform-implementation-js/lib/idMap.js +35 -0
  20. package/src/platform-implementation-js/platform-implementation.d.ts +0 -3
  21. package/src/platform-implementation-js/platform-implementation.js +1 -9
  22. package/src/injected-js/inbox/setupAjaxInterceptor.js +0 -211
  23. package/src/injected-js/inbox/setupClickAndGetNewIframeSrc.js +0 -67
  24. package/src/injected-js/inbox/setupComposeViewDraftIDFinder.js +0 -35
  25. package/src/injected-js/inbox/setupInboxFakeWindowResizeListener.js +0 -29
  26. package/src/platform-implementation-js/dom-driver/inbox/__mocks__/getSidebarClassnames.js +0 -13
  27. package/src/platform-implementation-js/dom-driver/inbox/addNavItem.js +0 -38
  28. package/src/platform-implementation-js/dom-driver/inbox/addRecipientRow.js +0 -55
  29. package/src/platform-implementation-js/dom-driver/inbox/createLink.js +0 -19
  30. package/src/platform-implementation-js/dom-driver/inbox/createLink.test.js +0 -27
  31. package/src/platform-implementation-js/dom-driver/inbox/detection/appToolbarLocation/parser.js +0 -43
  32. package/src/platform-implementation-js/dom-driver/inbox/detection/attachmentCard/parser.js +0 -34
  33. package/src/platform-implementation-js/dom-driver/inbox/detection/attachmentOverlay/parser.js +0 -53
  34. package/src/platform-implementation-js/dom-driver/inbox/detection/chatSidebar/parser.js +0 -31
  35. package/src/platform-implementation-js/dom-driver/inbox/detection/compose/parser.js +0 -103
  36. package/src/platform-implementation-js/dom-driver/inbox/detection/message/parser.js +0 -69
  37. package/src/platform-implementation-js/dom-driver/inbox/detection/nativeDrawer/parser.js +0 -32
  38. package/src/platform-implementation-js/dom-driver/inbox/detection/searchBar/parser.js +0 -28
  39. package/src/platform-implementation-js/dom-driver/inbox/detection/thread/parser.js +0 -49
  40. package/src/platform-implementation-js/dom-driver/inbox/detection/thread-row/parser.js +0 -100
  41. package/src/platform-implementation-js/dom-driver/inbox/getComposeViewDriverLiveSet.js +0 -99
  42. package/src/platform-implementation-js/dom-driver/inbox/getInboxMessageIdForInboxThreadId.js +0 -36
  43. package/src/platform-implementation-js/dom-driver/inbox/getSidebarClassnames.js +0 -114
  44. package/src/platform-implementation-js/dom-driver/inbox/getSidebarClassnames.test.js +0 -73
  45. package/src/platform-implementation-js/dom-driver/inbox/gotoView.js +0 -39
  46. package/src/platform-implementation-js/dom-driver/inbox/gotoView.test.js +0 -28
  47. package/src/platform-implementation-js/dom-driver/inbox/inbox-butter-bar-driver.js +0 -148
  48. package/src/platform-implementation-js/dom-driver/inbox/inbox-driver.js +0 -863
  49. package/src/platform-implementation-js/dom-driver/inbox/inbox-page-communicator.js +0 -62
  50. package/src/platform-implementation-js/dom-driver/inbox/inboxResponseProcessor.js +0 -12
  51. package/src/platform-implementation-js/dom-driver/inbox/inboxResponseProcessor.test.js +0 -18
  52. package/src/platform-implementation-js/dom-driver/inbox/makePageParserTree.js +0 -33
  53. package/src/platform-implementation-js/dom-driver/inbox/pageParserOptions.js +0 -265
  54. package/src/platform-implementation-js/dom-driver/inbox/registerSearchSuggestionsProvider.js +0 -301
  55. package/src/platform-implementation-js/dom-driver/inbox/setupCustomAutocompleteSelectionHandling.js +0 -183
  56. package/src/platform-implementation-js/dom-driver/inbox/setupRouteViewDriverStream.js +0 -64
  57. package/src/platform-implementation-js/dom-driver/inbox/setupRouteViewDriverStream.test.js +0 -72
  58. package/src/platform-implementation-js/dom-driver/inbox/views/InboxLabelView.js +0 -78
  59. package/src/platform-implementation-js/dom-driver/inbox/views/InboxMoleViewDriver.js +0 -296
  60. package/src/platform-implementation-js/dom-driver/inbox/views/InboxToolbarButtonView.js +0 -91
  61. package/src/platform-implementation-js/dom-driver/inbox/views/InboxToolbarView.js +0 -53
  62. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-sidebar-view.js +0 -271
  63. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-toolbar-button-view.js +0 -160
  64. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-toolbar-tooltip-view.js +0 -57
  65. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-attachment-card-view.js +0 -197
  66. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-attachment-overlay-view.js +0 -83
  67. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-chat-sidebar-view.js +0 -45
  68. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-compose-button-view.js +0 -116
  69. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-compose-view.js +0 -842
  70. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-custom-route-view.js +0 -75
  71. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-dropdown-view.js +0 -25
  72. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-dummy-route-view.js +0 -63
  73. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-message-view.js +0 -274
  74. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-modal-view.js +0 -112
  75. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-route-view.js +0 -96
  76. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-row-view.js +0 -315
  77. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-view.js +0 -218
  78. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-view.test.js +0 -171
  79. package/src/platform-implementation-js/dom-driver/inbox/views/inbox-tooltip-view.js +0 -127
  80. package/src/platform-implementation-js/dom-driver/inbox/views/inboxNavItemView.js +0 -311
  81. package/src/platform-implementation-js/dom-driver/inbox/waitForAnimationClickBlockerGone.js +0 -26
@@ -1,842 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _escape = _interopRequireDefault(require("lodash/escape"));
9
- var _find = _interopRequireDefault(require("lodash/find"));
10
- var _ud = require("ud");
11
- var _closestNg = _interopRequireDefault(require("closest-ng"));
12
- var _kefir = _interopRequireDefault(require("kefir"));
13
- var _kefirStopper = _interopRequireDefault(require("kefir-stopper"));
14
- var _kefirBus = _interopRequireDefault(require("kefir-bus"));
15
- var _autoHtml = _interopRequireDefault(require("auto-html"));
16
- var _censorHTMLstring = _interopRequireDefault(require("../../../../common/censorHTMLstring"));
17
- var _delayAsap = _interopRequireDefault(require("../../../lib/delay-asap"));
18
- var _arrayToLifetimes = _interopRequireDefault(require("../../../lib/array-to-lifetimes"));
19
- var _querySelectorOrFail = _interopRequireDefault(require("../../../lib/dom/querySelectorOrFail"));
20
- var _makeMutationObserverChunkedStream = _interopRequireDefault(require("../../../lib/dom/make-mutation-observer-chunked-stream"));
21
- var _simulateMouseEvent = require("../../../lib/dom/simulate-mouse-event");
22
- var _simulateKey = _interopRequireDefault(require("../../../lib/dom/simulate-key"));
23
- var _insertHtmlAtCursor = _interopRequireDefault(require("../../../lib/dom/insert-html-at-cursor"));
24
- var _querySelectorOne = _interopRequireDefault(require("../../../lib/dom/querySelectorOne"));
25
- var _ErrorCollector = _interopRequireDefault(require("../../../lib/ErrorCollector"));
26
- var _handleComposeLinkChips = _interopRequireDefault(require("../../../lib/handle-compose-link-chips"));
27
- var _insertLinkChipIntoBody = _interopRequireDefault(require("../../../lib/insert-link-chip-into-body"));
28
- var _getPresendingStream = _interopRequireDefault(require("../../../driver-common/compose/getPresendingStream"));
29
- var _getDiscardStream = _interopRequireDefault(require("../../../driver-common/compose/getDiscardStream"));
30
- var _addRecipientRow = _interopRequireDefault(require("../addRecipientRow"));
31
- var _inboxComposeButtonView = _interopRequireDefault(require("./inbox-compose-button-view"));
32
- var _getSelection = require("../../../lib/dom/get-selection");
33
- var _getGmailThreadIdForRfcMessageId = _interopRequireDefault(require("../../../driver-common/getGmailThreadIdForRfcMessageId"));
34
- let cachedFromContacts = null;
35
- class InboxComposeView {
36
- _eventStream = (0, _kefirBus.default)();
37
- _stopper = (0, _kefirStopper.default)();
38
- _isMinimized = false;
39
- _isFullscreenMode = false;
40
- _isPresending = false;
41
- _closedProgrammatically = false;
42
- constructor(driver, el, parsed) {
43
- this;
44
- this._element = el;
45
- this._driver = driver;
46
- this._modifierButtonContainer = null;
47
- this._lastBodySelectionRange = null;
48
- this._p = parsed;
49
- this._els = parsed.elements;
50
- const bottomAreaElementCount = this._els.sendBtn && this._els.sendBtn.parentElement && this._els.sendBtn.parentElement.childElementCount;
51
- this._driver.getLogger().eventSite('compose open', {
52
- errorCount: this._p.errors.length,
53
- bottomAreaElementCount,
54
- isInline: this._p.attributes.isInline
55
- });
56
- const draftSaveTriggerer = (0, _kefirBus.default)();
57
- this._queueDraftSave = () => {
58
- draftSaveTriggerer.emit(null);
59
- };
60
- const bodyEl = this._els.body;
61
- if (bodyEl) {
62
- draftSaveTriggerer.bufferBy(draftSaveTriggerer.flatMap(() => (0, _delayAsap.default)(null))).filter(x => x.length > 0).takeUntilBy(this._stopper).onValue(() => {
63
- var unsilence = this._driver.getPageCommunicator().silenceGmailErrorsForAMoment();
64
- try {
65
- (0, _simulateKey.default)(bodyEl, 13, 0);
66
- } finally {
67
- unsilence();
68
- }
69
- });
70
- _kefir.default.merge([_kefir.default.fromEvents(document.body, 'mousedown'), _kefir.default.fromEvents(document.body, 'keydown')]).takeUntilBy(this.getStopper()).onValue(event => {
71
- const selection = document.getSelection();
72
- if (selection.rangeCount > 0 && bodyEl.contains(selection.anchorNode)) {
73
- this._lastBodySelectionRange = selection.getRangeAt(0);
74
- }
75
- });
76
- this._eventStream.plug((0, _makeMutationObserverChunkedStream.default)(bodyEl, {
77
- childList: true,
78
- subtree: true,
79
- characterData: true
80
- }).map(() => ({
81
- eventName: 'bodyChanged'
82
- })));
83
- }
84
- _kefir.default.fromEvents(this._element, 'closedProgrammatically').takeUntilBy(this._stopper).onValue(() => {
85
- this._closedProgrammatically = true;
86
- });
87
- this._draftID = this._driver.getPageCommunicator().getDraftIDForComposeView(this.getElement());
88
- this._ajaxInterceptStream = this._driver.getPageCommunicator().ajaxInterceptStream.takeUntilBy(this._stopper).filter(_ref => {
89
- let {
90
- draftID
91
- } = _ref;
92
- return draftID === this._draftID;
93
- });
94
- this._setupStreams();
95
- this.getEventStream().takeUntilBy(this._stopper).onValue(_ref2 => {
96
- let {
97
- eventName
98
- } = _ref2;
99
- if (eventName === 'presending') {
100
- this._isPresending = true;
101
- const sendCanceledStream = this.getEventStream().filter(_ref3 => {
102
- let {
103
- eventName
104
- } = _ref3;
105
- return eventName === 'sendCanceled';
106
- });
107
- this._sendingStream = _kefir.default.merge([_kefir.default.combine([this.getEventStream().filter(_ref4 => {
108
- let {
109
- eventName
110
- } = _ref4;
111
- return eventName === 'sending';
112
- }), this.getEventStream().filter(_ref5 => {
113
- let {
114
- eventName
115
- } = _ref5;
116
- return eventName === 'sent';
117
- })]), this._ajaxInterceptStream.filter(_ref6 => {
118
- let {
119
- type
120
- } = _ref6;
121
- return type === 'emailSendFailed';
122
- }), _kefir.default.later(60 * 1000).flatMap(() => _kefir.default.constantError(new Error('Timed out waiting for ComposeView send')))]).takeUntilBy(sendCanceledStream).takeUntilBy(this._stopper).take(1).takeErrors(1);
123
- this._sendingStream.onValue(() => {
124
- this._isPresending = false;
125
- }).onError(error => {
126
- this._driver.getLogger().error(error);
127
- });
128
- this._driver.getPageCommunicator().notifyEmailSending();
129
- if (!this._p.attributes.isInline) {
130
- // TODO make this code less fragile on slow machines/connections
131
- _kefir.default.later(5 * 1000).takeUntilBy(this.getEventStream().filter(_ref7 => {
132
- let {
133
- eventName
134
- } = _ref7;
135
- return ['sendCanceled', 'presending'].indexOf(eventName) !== -1;
136
- })).onValue(() => {
137
- // In cases where Inbox decides to cancel the send client-side,
138
- // we need to make sure we realize sending is not going to happen
139
- // and inform consumers who might be expecting a send.
140
- // The most common case for this is trying to send an email
141
- // with no recipients.
142
- if (document.contains(this._element)) {
143
- this._eventStream.emit({
144
- eventName: 'sendCanceled'
145
- });
146
- }
147
- });
148
- }
149
- } else if (eventName === 'sendCanceled') {
150
- this._isPresending = false;
151
- this._driver.getPageCommunicator().notifyEmailSendCanceled();
152
- }
153
- });
154
- (0, _handleComposeLinkChips.default)(this);
155
- const {
156
- fromPickerEmailSpan
157
- } = this._els;
158
- if (fromPickerEmailSpan) {
159
- this._eventStream.plug((0, _makeMutationObserverChunkedStream.default)(fromPickerEmailSpan, {
160
- childList: true,
161
- subtree: true,
162
- characterData: true
163
- }).map(() => ({
164
- eventName: 'fromContactChanged',
165
- data: {
166
- contact: this.getFromContact()
167
- }
168
- })));
169
- }
170
- const {
171
- minimizeBtnImage
172
- } = this._els;
173
- if (minimizeBtnImage) {
174
- const isMinimized = () => /_maximize_/.test(minimizeBtnImage.src);
175
- const minimizeButtonChanges = (0, _makeMutationObserverChunkedStream.default)(minimizeBtnImage, {
176
- attributes: true
177
- });
178
- minimizeButtonChanges.toProperty(() => null).takeUntilBy(this._stopper).onValue(() => {
179
- this._isMinimized = isMinimized();
180
- });
181
- this._eventStream.plug(minimizeButtonChanges.map(() => ({
182
- eventName: isMinimized() ? 'minimized' : 'restored'
183
- })));
184
- }
185
- const {
186
- toggleFullscreenButtonImage
187
- } = this._els;
188
- if (toggleFullscreenButtonImage) {
189
- const isFullscreenMode = () => !/_enter_full_screen/.test(toggleFullscreenButtonImage.src);
190
- const toggleButtonChanges = (0, _makeMutationObserverChunkedStream.default)(toggleFullscreenButtonImage, {
191
- attributes: true
192
- });
193
- toggleButtonChanges.toProperty(() => null).takeUntilBy(this._stopper).onValue(() => {
194
- this._isFullscreenMode = isFullscreenMode();
195
- });
196
- this._eventStream.plug(toggleButtonChanges.map(() => ({
197
- eventName: 'fullscreenChanged',
198
- data: {
199
- fullscreen: isFullscreenMode()
200
- }
201
- })));
202
- }
203
- }
204
- removedFromDOM() {
205
- // The element of an inline draft may be re-used with a new ID.
206
- this._element.removeAttribute('data-inboxsdk-draft-id');
207
- const cleanup = () => {
208
- this._eventStream.emit({
209
- eventName: 'destroy',
210
- data: {
211
- closedByInboxSDK: this._closedProgrammatically
212
- }
213
- });
214
- this._eventStream.end();
215
- this._stopper.destroy();
216
- };
217
- if (this._isPresending) {
218
- this._sendingStream && this._sendingStream.onEnd(cleanup);
219
- } else {
220
- cleanup();
221
- }
222
- }
223
- getEventStream() {
224
- return this._eventStream;
225
- }
226
- getStopper() {
227
- return this._stopper;
228
- }
229
- getElement() {
230
- return this._element;
231
- }
232
- // Call this whenever we change the body directly by mucking with the
233
- // elements.
234
- _informBodyChanged() {
235
- if (this._els.bodyPlaceholder) {
236
- if (this._els.body && this._els.body.textContent.length > 0) {
237
- this._els.bodyPlaceholder.style.display = 'none';
238
- } else {
239
- // To do this properly, we have to re-add whatever the visible class is.
240
- // It's a bit of work for a pretty minor detail (making the placeholder
241
- // re-appear immediately when SDK methods are used to clear a compose).
242
- //this._els.bodyPlaceholder.style.display = "";
243
- }
244
- }
245
- this._queueDraftSave();
246
- }
247
- _getAddressChangesStream() {
248
- const {
249
- toInput,
250
- ccInput,
251
- bccInput
252
- } = this._els;
253
- function makeChangesStream(prefix, input, cb) {
254
- if (!input) return _kefir.default.never();
255
- const contactArrayStream = (0, _makeMutationObserverChunkedStream.default)(input.parentElement, {
256
- childList: true,
257
- attributes: true,
258
- subtree: true
259
- }).merge(_kefir.default.later(0)).map(cb);
260
- return (0, _arrayToLifetimes.default)(contactArrayStream, c => c.emailAddress).flatMap(_ref8 => {
261
- let {
262
- el,
263
- removalStream
264
- } = _ref8;
265
- return _kefir.default.constant({
266
- eventName: prefix + 'ContactAdded',
267
- data: {
268
- contact: el
269
- }
270
- }).merge(removalStream.map(() => ({
271
- eventName: prefix + 'ContactRemoved',
272
- data: {
273
- contact: el
274
- }
275
- })));
276
- });
277
- }
278
- return _kefir.default.merge([makeChangesStream('to', toInput, () => this.getToRecipients()), makeChangesStream('cc', ccInput, () => this.getCcRecipients()), makeChangesStream('bcc', bccInput, () => this.getBccRecipients())]).takeUntilBy(this._stopper);
279
- }
280
- _setupStreams() {
281
- this._eventStream.plug(this._getAddressChangesStream());
282
- this._eventStream.plug((0, _getPresendingStream.default)({
283
- element: this.getElement(),
284
- sendButton: this.getSendButton()
285
- }));
286
- this._eventStream.plug((0, _getDiscardStream.default)({
287
- element: this.getElement(),
288
- discardButton: this.getDiscardButton()
289
- }));
290
- this._eventStream.plug(_kefir.default.fromEvents(this.getElement(), 'inboxSDKsendCanceled').map(() => ({
291
- eventName: 'sendCanceled'
292
- })));
293
- this._eventStream.plug(_kefir.default.fromEvents(this.getElement(), 'inboxSDKdiscardCanceled').map(() => ({
294
- eventName: 'discardCanceled'
295
- })));
296
- this._eventStream.plug(this._ajaxInterceptStream.filter(_ref9 => {
297
- let {
298
- type
299
- } = _ref9;
300
- return type === 'emailSending';
301
- }).map(() => ({
302
- eventName: 'sending'
303
- })));
304
- this._eventStream.plug(this._ajaxInterceptStream.filter(_ref10 => {
305
- let {
306
- type
307
- } = _ref10;
308
- return type === 'emailSent';
309
- }).map(event => {
310
- const data = {
311
- getThreadID: () => (0, _getGmailThreadIdForRfcMessageId.default)(this._driver, event.rfcID),
312
- getMessageID: () => this._driver.getGmailMessageIdForSyncMessageId(`msg-a:${event.draftID}`)
313
- };
314
- ['gmailThreadId', 'gmailMessageId', 'threadID', 'messageID'].forEach(name => {
315
- Object.defineProperty(data, name, {
316
- get: () => {
317
- this._driver.getLogger().deprecationWarning(`ComposeView sent event.${name}`, 'ComposeView sent event.getThreadID() or event.getMessageID()');
318
- throw new Error('Not supported');
319
- }
320
- });
321
- });
322
- return {
323
- eventName: 'sent',
324
- data
325
- };
326
- }));
327
- }
328
- getFromContact() {
329
- const {
330
- fromPickerEmailSpan
331
- } = this._els;
332
- if (!fromPickerEmailSpan) {
333
- return this._driver.getUserContact();
334
- }
335
- const email = fromPickerEmailSpan.textContent;
336
- const contact = (0, _find.default)(this.getFromContactChoices(), c => c.emailAddress === email);
337
- if (!contact) {
338
- throw new Error('Failed to find from contact');
339
- }
340
- return contact;
341
- }
342
- getFromContactChoices() {
343
- if (this._p.attributes.isInline) throw new Error("Can't get from values of inline compose");
344
- if (cachedFromContacts) {
345
- return cachedFromContacts;
346
- }
347
- const {
348
- fromPicker
349
- } = this._els;
350
- if (!fromPicker) {
351
- cachedFromContacts = [this._driver.getUserContact()];
352
- return cachedFromContacts;
353
- }
354
- const startActiveElement = document.activeElement;
355
- const grandUncle = this._element.parentElement.parentElement.firstElementChild;
356
- let fromOptionEls = grandUncle.querySelectorAll('li[role=menuitem][data-jsaction*=".switch_custom_from"]');
357
- const needToOpenMenu = fromOptionEls.length === 0;
358
- try {
359
- if (needToOpenMenu) {
360
- (0, _simulateMouseEvent.simulateClick)(fromPicker);
361
- fromOptionEls = grandUncle.querySelectorAll('li[role=menuitem][data-jsaction*=".switch_custom_from"]');
362
- }
363
- if (fromOptionEls.length === 0) {
364
- cachedFromContacts = [this._driver.getUserContact()];
365
- return cachedFromContacts;
366
- }
367
- cachedFromContacts = Array.from(fromOptionEls).map(el => ({
368
- name: (0, _querySelectorOrFail.default)(el, 'span[title]').title,
369
- emailAddress: (0, _querySelectorOrFail.default)(el, 'span:not([title])').textContent
370
- }));
371
- } finally {
372
- if (needToOpenMenu) {
373
- (0, _simulateMouseEvent.simulateClick)(document.body);
374
- }
375
- if (startActiveElement) {
376
- startActiveElement.focus();
377
- }
378
- }
379
- return cachedFromContacts;
380
- }
381
- setFromEmail(email) {
382
- if (this._p.attributes.isInline) throw new Error("Can't set from value of inline compose");
383
- if (this.getFromContact().emailAddress === email) return;
384
- const {
385
- fromPicker
386
- } = this._els;
387
- if (!fromPicker) throw new Error('from picker element not found');
388
- const startActiveElement = document.activeElement;
389
- const grandUncle = this._element.parentElement.parentElement.firstElementChild;
390
- let fromOptionEls = grandUncle.querySelectorAll('li[role=menuitem][data-jsaction*=".switch_custom_from"]');
391
- const needToOpenMenu = fromOptionEls.length === 0;
392
- try {
393
- if (needToOpenMenu) {
394
- (0, _simulateMouseEvent.simulateClick)(fromPicker);
395
- fromOptionEls = grandUncle.querySelectorAll('li[role=menuitem][data-jsaction*=".switch_custom_from"]');
396
- }
397
- const fromOptionEl = (0, _find.default)(fromOptionEls, el => el.querySelector('span:not([title])').textContent === email);
398
- if (!fromOptionEl) {
399
- throw new Error('Failed to find from contact to set');
400
- }
401
- (0, _simulateMouseEvent.simulateClick)(fromOptionEl);
402
- } finally {
403
- if (needToOpenMenu) {
404
- (0, _simulateMouseEvent.simulateClick)(fromPicker);
405
- }
406
- if (startActiveElement) {
407
- startActiveElement.focus();
408
- }
409
- }
410
- }
411
- focus() {
412
- if (!this._els.body) throw new Error('Compose View missing body element');
413
- this._els.body.focus();
414
- const selection = document.getSelection();
415
- const lastSelectionRange = this._lastBodySelectionRange;
416
- if (lastSelectionRange && selection) {
417
- selection.removeAllRanges();
418
- selection.addRange(lastSelectionRange);
419
- }
420
- }
421
- insertBodyTextAtCursor(text) {
422
- return this.insertBodyHTMLAtCursor((0, _escape.default)(text).replace(/\n/g, '<br>'));
423
- }
424
- insertBodyHTMLAtCursor(html) {
425
- var retVal = (0, _insertHtmlAtCursor.default)(this.getBodyElement(), html, this._lastBodySelectionRange);
426
- this._informBodyChanged();
427
- return retVal;
428
- }
429
- insertLinkIntoBody(text, href) {
430
- var html = (0, _autoHtml.default)`<a href="${href}">${text}</a>`;
431
- return this.insertBodyHTMLAtCursor(html);
432
- }
433
- insertLinkChipIntoBody(options) {
434
- var retval = (0, _insertLinkChipIntoBody.default)(this, options);
435
- this._informBodyChanged();
436
- return retval;
437
- }
438
- setBodyHTML(html) {
439
- if (!this._els.body) throw new Error('Compose View missing body element');
440
- this._els.body.innerHTML = html;
441
- this._informBodyChanged();
442
- }
443
- setBodyText(text) {
444
- if (!this._els.body) throw new Error('Compose View missing body element');
445
- this._els.body.textContent = text;
446
- this._informBodyChanged();
447
- }
448
- _setRecipients(inputElement, emails) {
449
- const chipContainer = inputElement.parentElement;
450
- if (!chipContainer) throw new Error('Should not happen');
451
- const startActiveElement = document.activeElement;
452
-
453
- // Inbox re-uses the chip elements as some are removed, so finding all the
454
- // button elements at once and then clicking on each of them wouldn't work.
455
- const removeButtonCount = chipContainer.querySelectorAll('[role=button][jsaction*="remove_chip"]').length;
456
- for (let i = 0; i < removeButtonCount; i++) {
457
- const removeButton = chipContainer.querySelector('[role=button][jsaction*="remove_chip"]');
458
- if (!removeButton) break;
459
- (0, _simulateMouseEvent.simulateClick)(removeButton);
460
- }
461
- emails.forEach(email => {
462
- inputElement.value = email;
463
- inputElement.dispatchEvent(new window.FocusEvent('blur'));
464
- });
465
- if (startActiveElement) {
466
- startActiveElement.focus();
467
- }
468
- }
469
- setToRecipients(emails) {
470
- if (this._p.attributes.isInline) throw new Error("Can't set recipients of inline compose");
471
- const {
472
- toInput
473
- } = this._els;
474
- if (!toInput) throw new Error('Compose View missing recipient input');
475
- this._setRecipients(toInput, emails);
476
- }
477
- setCcRecipients(emails) {
478
- if (this._p.attributes.isInline) throw new Error("Can't set recipients of inline compose");
479
- const {
480
- ccInput
481
- } = this._els;
482
- if (!ccInput) throw new Error('Compose View missing recipient input');
483
- this._setRecipients(ccInput, emails);
484
- const {
485
- toggleCcBccButton
486
- } = this._els;
487
- if (emails.length && toggleCcBccButton && toggleCcBccButton.style.display !== 'none') {
488
- (0, _simulateMouseEvent.simulateClick)(toggleCcBccButton);
489
- }
490
- }
491
- setBccRecipients(emails) {
492
- if (this._p.attributes.isInline) throw new Error("Can't set recipients of inline compose");
493
- const {
494
- bccInput
495
- } = this._els;
496
- if (!bccInput) throw new Error('Compose View missing recipient input');
497
- this._setRecipients(bccInput, emails);
498
- const {
499
- toggleCcBccButton
500
- } = this._els;
501
- if (emails.length && toggleCcBccButton && toggleCcBccButton.style.display !== 'none') {
502
- (0, _simulateMouseEvent.simulateClick)(toggleCcBccButton);
503
- }
504
- }
505
- replaceSendButton(el) {
506
- const {
507
- sendBtn
508
- } = this._p.elements;
509
- if (!sendBtn) throw new Error('Could not locate send button');
510
- sendBtn.style.display = 'none';
511
- const container = document.createElement('div');
512
- container.classList.add('inboxsdk__compose_customSendContainer');
513
- container.appendChild(el);
514
- this._element.setAttribute('data-inboxsdk-send-replaced', '');
515
- sendBtn.insertAdjacentElement('afterend', container);
516
- const removalStopper = (0, _kefirStopper.default)();
517
- return () => {
518
- removalStopper.destroy();
519
- container.remove();
520
- this._element.removeAttribute('data-inboxsdk-send-replaced');
521
- sendBtn.style.display = '';
522
- };
523
- }
524
- hideDiscardButton() {
525
- const {
526
- discardBtn
527
- } = this._p.elements;
528
- if (!discardBtn) throw new Error('Could not locate discard button');
529
- const discardDivider = discardBtn.previousElementSibling;
530
- if (!(discardDivider instanceof HTMLElement)) {
531
- throw new Error('Could not locate discard button divider');
532
- }
533
- discardBtn.style.display = 'none';
534
- discardDivider.style.display = 'none';
535
- return () => {
536
- discardBtn.style.display = '';
537
- discardDivider.style.display = '';
538
- };
539
- }
540
- close() {
541
- if (this._p.attributes.isInline) {
542
- throw new Error('Not implemented for inline compose');
543
- }
544
- const {
545
- closeBtn
546
- } = this._els;
547
- if (closeBtn) {
548
- this._element.dispatchEvent(new CustomEvent('closedProgrammatically', {
549
- bubbles: false,
550
- cancelable: false,
551
- detail: null
552
- }));
553
- (0, _simulateMouseEvent.simulateClick)(closeBtn);
554
- }
555
- }
556
- send(_ref11) {
557
- let {
558
- sendAndArchive
559
- } = _ref11;
560
- if (!this._els.sendBtn) throw new Error('Compose View missing send element');
561
- (0, _simulateMouseEvent.simulateClick)(this._els.sendBtn);
562
- }
563
- discard() {
564
- (0, _simulateMouseEvent.simulateClick)(this.getDiscardButton());
565
- }
566
- setMinimized(minimized) {
567
- if (minimized !== this.isMinimized()) {
568
- if (this._p.attributes.isInline) throw new Error('Not implemented for inline compose views');
569
- const {
570
- minimizeBtn
571
- } = this._els;
572
- if (!minimizeBtn) throw new Error('Could not find minimize button');
573
- minimizeBtn.click();
574
- }
575
- }
576
- setFullscreen(fullscreen) {
577
- if (fullscreen !== this.isFullscreen()) {
578
- if (this._p.attributes.isInline) throw new Error('Not implemented for inline compose views');
579
- const {
580
- toggleFullscreenButton
581
- } = this._els;
582
- if (!toggleFullscreenButton) throw new Error('Could not find fullscreen button');
583
- toggleFullscreenButton.click();
584
- }
585
- }
586
- setTitleBarColor(color) {
587
- const {
588
- isInline
589
- } = this._p.attributes;
590
- if (isInline) throw new Error('Cannot set title bar of inline compose');
591
- const {
592
- titleBar
593
- } = this._p.elements;
594
- if (!titleBar) throw new Error('Could not locate compose title bar');
595
- titleBar.style.backgroundColor = color;
596
- return () => {
597
- titleBar.style.backgroundColor = '';
598
- };
599
- }
600
- setTitleBarText(text) {
601
- throw new Error('Not supported in Inbox');
602
- }
603
- addButton(buttonDescriptor, groupOrderHint, extraOnClickOptions) {
604
- var buttonViewController = new _inboxComposeButtonView.default(this, buttonDescriptor, groupOrderHint, extraOnClickOptions);
605
- return Promise.resolve({
606
- buttonViewController,
607
- buttonDescriptor: {}
608
- });
609
- }
610
- getModifierButtonContainer() {
611
- if (this._modifierButtonContainer) {
612
- return this._modifierButtonContainer;
613
- }
614
- this._modifierButtonContainer = this._element.querySelector('.inboxsdk__compose_actionToolbar');
615
- if (this._modifierButtonContainer) {
616
- return this._modifierButtonContainer;
617
- }
618
- const div = document.createElement('div');
619
- div.className = 'inboxsdk__compose_actionToolbar';
620
- if (!this._p.attributes.isInline) {
621
- const hiddenAttachBtn = this._els.attachBtn ? this._els.attachBtn.nextSibling : null;
622
- if (hiddenAttachBtn instanceof HTMLElement && hiddenAttachBtn.style.position === 'absolute') {
623
- hiddenAttachBtn.style.display = 'none';
624
- } else {
625
- this._driver.getLogger().error(new Error("Didn't find hiddenAttachBtn"));
626
- }
627
- }
628
- const sendBtn = this._els.sendBtn;
629
- if (!sendBtn) throw new Error('Compose View missing send element');
630
- const sendParent = sendBtn.parentElement;
631
- if (!sendParent) throw new Error('Could not find send button parent');
632
- sendParent.insertBefore(div, sendBtn.nextSibling);
633
- this._modifierButtonContainer = div;
634
- return div;
635
- }
636
- addRecipientRow(options) {
637
- if (this._p.attributes.isInline) throw new Error('Cannot add recipient rows to inline compose views');
638
- return (0, _addRecipientRow.default)(this, options);
639
- }
640
- forceRecipientRowsOpen() {
641
- console.warn('ComposeView.forceRecipientRowsOpen() is a no-op in Inbox');
642
- return () => {};
643
- }
644
- hideNativeRecipientRows() {
645
- if (this._p.attributes.isInline) throw new Error('Cannot hide recipient rows on inline compose views');
646
- const rows = [this.getToRow(), this.getCCRow(), this.getBCCRow()];
647
- rows.forEach(row => {
648
- row.classList.add('inboxsdk__compose_forceRecipientRowHidden');
649
- });
650
- return () => {
651
- rows.forEach(row => {
652
- row.classList.remove('inboxsdk__compose_forceRecipientRowHidden');
653
- });
654
- };
655
- }
656
- hideRecipientArea() {
657
- throw new Error('Not implemented');
658
- }
659
- addOuterSidebar(options) {
660
- throw new Error('Not implemented');
661
- }
662
- addInnerSidebar(options) {
663
- throw new Error('Not implemented');
664
- }
665
- addComposeNotice(composeNoticeDescriptor) {
666
- throw new Error('Not implemented');
667
- }
668
- addStatusBar(options) {
669
- throw new Error('Not implemented');
670
- }
671
- hideNativeStatusBar() {
672
- throw new Error('Not Implemented');
673
- }
674
- isForward() {
675
- throw new Error('Not Implemented');
676
- }
677
- isReply() {
678
- if (this._p.attributes.isInline) return true;
679
- throw new Error('Not implemented');
680
- }
681
- isInlineReplyForm() {
682
- return this._p.attributes.isInline;
683
- }
684
- popOut() {
685
- if (!this._p.attributes.isInline) {
686
- throw new Error('Can only pop out inline reply compose views');
687
- }
688
- if (!this._els.popOutBtn) {
689
- throw new Error('Should not happen');
690
- }
691
- (0, _simulateMouseEvent.simulateClick)(this._els.popOutBtn);
692
- }
693
- registerRequestModifier(modifier) {
694
- throw new Error('Not implemented');
695
- }
696
- attachFiles(files) {
697
- throw new Error('Not implemented');
698
- }
699
- attachInlineFiles(files) {
700
- throw new Error('Not implemented');
701
- }
702
- isFullscreen() {
703
- return this._isFullscreenMode;
704
- }
705
- isMinimized() {
706
- return this._isMinimized;
707
- }
708
- getSubjectInput() {
709
- return this._els.subject;
710
- }
711
- getMetadataFormElement() {
712
- throw new Error('Not supported in Inbox.');
713
- }
714
- getToRow() {
715
- const {
716
- toRow
717
- } = this._els;
718
- if (!toRow) throw new Error('Could not locate To row');
719
- return toRow;
720
- }
721
- getCCRow() {
722
- const {
723
- ccRow
724
- } = this._els;
725
- if (!ccRow) throw new Error('Could not locate CC row');
726
- return ccRow;
727
- }
728
- getBCCRow() {
729
- const {
730
- bccRow
731
- } = this._els;
732
- if (!bccRow) throw new Error('Could not locate BCC row');
733
- return bccRow;
734
- }
735
- getBodyElement() {
736
- if (!this._els.body) throw new Error('Compose View missing body element');
737
- return this._els.body;
738
- }
739
- getHTMLContent() {
740
- return this.getBodyElement().innerHTML;
741
- }
742
- getTextContent() {
743
- return this.getBodyElement().textContent;
744
- }
745
- getSelectedBodyHTML() {
746
- return (0, _getSelection.getSelectedHTMLInElement)(this.getBodyElement(), this._lastBodySelectionRange);
747
- }
748
- getSelectedBodyText() {
749
- return (0, _getSelection.getSelectedTextInElement)(this.getBodyElement(), this._lastBodySelectionRange);
750
- }
751
- getSubject() {
752
- const {
753
- subject
754
- } = this._els;
755
- if (!subject) {
756
- throw new Error('InboxSDK: Could not locate subject field');
757
- }
758
- return subject.value;
759
- }
760
- setSubject(text) {
761
- if (this._p.attributes.isInline) {
762
- throw new Error('setSubject is not supported for inline compose views');
763
- }
764
- if (!this._els.subject) {
765
- throw new Error('InboxSDK: Could not locate subject field');
766
- }
767
- this._els.subject.value = text;
768
- }
769
- _getRecipients(inputElement) {
770
- const chipContainer = inputElement.parentElement;
771
- if (!chipContainer) throw new Error('Should not happen');
772
- return Array.from(chipContainer.children).filter(el => el.nodeName === 'DIV' && el.hasAttribute('email') && el.style.display !== 'none').map(chip => ({
773
- emailAddress: chip.getAttribute('email') || '',
774
- name: chip.textContent
775
- }));
776
- }
777
- getToRecipients() {
778
- if (this._p.attributes.isInline) throw new Error("Can't get recipients of inline compose");
779
- const {
780
- toInput
781
- } = this._els;
782
- if (!toInput) throw new Error('Compose View missing recipient input');
783
- return this._getRecipients(toInput);
784
- }
785
- getCcRecipients() {
786
- if (this._p.attributes.isInline) throw new Error("Can't get recipients of inline compose");
787
- const {
788
- ccInput
789
- } = this._els;
790
- if (!ccInput) throw new Error('Compose View missing recipient input');
791
- return this._getRecipients(ccInput);
792
- }
793
- getBccRecipients() {
794
- if (this._p.attributes.isInline) throw new Error("Can't get recipients of inline compose");
795
- const {
796
- bccInput
797
- } = this._els;
798
- if (!bccInput) throw new Error('Compose View missing recipient input');
799
- return this._getRecipients(bccInput);
800
- }
801
- getComposeID() {
802
- throw new Error('This method was discontinued');
803
- }
804
- getInitialMessageID() {
805
- throw new Error('composeView.getInitialMessageID is not implemented in Inbox');
806
- }
807
- getMessageID() {
808
- throw new Error('composeView.getMessageID is not implemented in Inbox');
809
- }
810
- getThreadID() {
811
- // TODO
812
- return null;
813
- }
814
- getCurrentDraftID() {
815
- return Promise.resolve(this._draftID);
816
- }
817
- getDraftID() {
818
- return Promise.resolve(this._draftID);
819
- }
820
- addTooltipToButton(buttonViewController, buttonDescriptor, tooltipDescriptor) {
821
- buttonViewController.showTooltip(tooltipDescriptor);
822
- }
823
- closeButtonTooltip(buttonViewController) {
824
- buttonViewController.closeTooltip();
825
- }
826
- getDiscardButton() {
827
- if (!this._els.discardBtn) throw new Error('Compose View missing discard button');
828
- return this._els.discardBtn;
829
- }
830
- getSendButton() {
831
- if (!this._els.sendBtn) throw new Error('Compose View missing send button');
832
- return this._els.sendBtn;
833
- }
834
- ensureAppButtonToolbarsAreClosed() {
835
- //TODO
836
- }
837
- ensureFormattingToolbarIsHidden() {
838
- //TODO
839
- }
840
- }
841
- var _default = (0, _ud.defn)(module, InboxComposeView);
842
- exports.default = _default;