@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.
- package/inboxsdk.js +7 -34
- package/inboxsdk.js.map +1 -1
- package/package.json +1 -1
- package/pageWorld.js +1 -1
- package/pageWorld.js.map +1 -1
- package/src/common/version.d.ts.map +1 -1
- package/src/common/version.js +3 -1
- package/src/injected-js/main.js +0 -9
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/index.test.js +6 -2
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-app-sidebar-view/primary/index.js +4 -2
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-sidebar-view.js +4 -2
- package/src/platform-implementation-js/dom-driver/gmail/views/gmail-thread-sidebar-view.test.js +6 -2
- package/src/platform-implementation-js/driver-common/sidebar/ContentPanelViewDriver.js +2 -2
- package/src/platform-implementation-js/driver-common/sidebar/constants.d.ts +9 -0
- package/src/platform-implementation-js/driver-common/sidebar/constants.d.ts.map +1 -0
- package/src/platform-implementation-js/driver-common/sidebar/constants.js +26 -0
- package/src/platform-implementation-js/lib/idMap.d.ts +7 -0
- package/src/platform-implementation-js/lib/idMap.d.ts.map +1 -1
- package/src/platform-implementation-js/lib/idMap.js +35 -0
- package/src/platform-implementation-js/platform-implementation.d.ts +0 -3
- package/src/platform-implementation-js/platform-implementation.js +1 -9
- package/src/injected-js/inbox/setupAjaxInterceptor.js +0 -211
- package/src/injected-js/inbox/setupClickAndGetNewIframeSrc.js +0 -67
- package/src/injected-js/inbox/setupComposeViewDraftIDFinder.js +0 -35
- package/src/injected-js/inbox/setupInboxFakeWindowResizeListener.js +0 -29
- package/src/platform-implementation-js/dom-driver/inbox/__mocks__/getSidebarClassnames.js +0 -13
- package/src/platform-implementation-js/dom-driver/inbox/addNavItem.js +0 -38
- package/src/platform-implementation-js/dom-driver/inbox/addRecipientRow.js +0 -55
- package/src/platform-implementation-js/dom-driver/inbox/createLink.js +0 -19
- package/src/platform-implementation-js/dom-driver/inbox/createLink.test.js +0 -27
- package/src/platform-implementation-js/dom-driver/inbox/detection/appToolbarLocation/parser.js +0 -43
- package/src/platform-implementation-js/dom-driver/inbox/detection/attachmentCard/parser.js +0 -34
- package/src/platform-implementation-js/dom-driver/inbox/detection/attachmentOverlay/parser.js +0 -53
- package/src/platform-implementation-js/dom-driver/inbox/detection/chatSidebar/parser.js +0 -31
- package/src/platform-implementation-js/dom-driver/inbox/detection/compose/parser.js +0 -103
- package/src/platform-implementation-js/dom-driver/inbox/detection/message/parser.js +0 -69
- package/src/platform-implementation-js/dom-driver/inbox/detection/nativeDrawer/parser.js +0 -32
- package/src/platform-implementation-js/dom-driver/inbox/detection/searchBar/parser.js +0 -28
- package/src/platform-implementation-js/dom-driver/inbox/detection/thread/parser.js +0 -49
- package/src/platform-implementation-js/dom-driver/inbox/detection/thread-row/parser.js +0 -100
- package/src/platform-implementation-js/dom-driver/inbox/getComposeViewDriverLiveSet.js +0 -99
- package/src/platform-implementation-js/dom-driver/inbox/getInboxMessageIdForInboxThreadId.js +0 -36
- package/src/platform-implementation-js/dom-driver/inbox/getSidebarClassnames.js +0 -114
- package/src/platform-implementation-js/dom-driver/inbox/getSidebarClassnames.test.js +0 -73
- package/src/platform-implementation-js/dom-driver/inbox/gotoView.js +0 -39
- package/src/platform-implementation-js/dom-driver/inbox/gotoView.test.js +0 -28
- package/src/platform-implementation-js/dom-driver/inbox/inbox-butter-bar-driver.js +0 -148
- package/src/platform-implementation-js/dom-driver/inbox/inbox-driver.js +0 -863
- package/src/platform-implementation-js/dom-driver/inbox/inbox-page-communicator.js +0 -62
- package/src/platform-implementation-js/dom-driver/inbox/inboxResponseProcessor.js +0 -12
- package/src/platform-implementation-js/dom-driver/inbox/inboxResponseProcessor.test.js +0 -18
- package/src/platform-implementation-js/dom-driver/inbox/makePageParserTree.js +0 -33
- package/src/platform-implementation-js/dom-driver/inbox/pageParserOptions.js +0 -265
- package/src/platform-implementation-js/dom-driver/inbox/registerSearchSuggestionsProvider.js +0 -301
- package/src/platform-implementation-js/dom-driver/inbox/setupCustomAutocompleteSelectionHandling.js +0 -183
- package/src/platform-implementation-js/dom-driver/inbox/setupRouteViewDriverStream.js +0 -64
- package/src/platform-implementation-js/dom-driver/inbox/setupRouteViewDriverStream.test.js +0 -72
- package/src/platform-implementation-js/dom-driver/inbox/views/InboxLabelView.js +0 -78
- package/src/platform-implementation-js/dom-driver/inbox/views/InboxMoleViewDriver.js +0 -296
- package/src/platform-implementation-js/dom-driver/inbox/views/InboxToolbarButtonView.js +0 -91
- package/src/platform-implementation-js/dom-driver/inbox/views/InboxToolbarView.js +0 -53
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-sidebar-view.js +0 -271
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-toolbar-button-view.js +0 -160
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-app-toolbar-tooltip-view.js +0 -57
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-attachment-card-view.js +0 -197
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-attachment-overlay-view.js +0 -83
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-chat-sidebar-view.js +0 -45
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-compose-button-view.js +0 -116
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-compose-view.js +0 -842
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-custom-route-view.js +0 -75
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-dropdown-view.js +0 -25
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-dummy-route-view.js +0 -63
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-message-view.js +0 -274
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-modal-view.js +0 -112
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-route-view.js +0 -96
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-row-view.js +0 -315
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-view.js +0 -218
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-thread-view.test.js +0 -171
- package/src/platform-implementation-js/dom-driver/inbox/views/inbox-tooltip-view.js +0 -127
- package/src/platform-implementation-js/dom-driver/inbox/views/inboxNavItemView.js +0 -311
- package/src/platform-implementation-js/dom-driver/inbox/waitForAnimationClickBlockerGone.js +0 -26
|
@@ -1,100 +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 = parser;
|
|
8
|
-
var _ErrorCollector = _interopRequireDefault(require("../../../../lib/ErrorCollector"));
|
|
9
|
-
var _querySelectorOne = _interopRequireDefault(require("../../../../lib/dom/querySelectorOne"));
|
|
10
|
-
const RGB_REGEX = /^rgb\s*\(\s*(\d+),\s*(\d+),\s*(\d+)\s*\)/;
|
|
11
|
-
function parser(el) {
|
|
12
|
-
const ec = new _ErrorCollector.default('threadRow');
|
|
13
|
-
const inBundle = !el.hasAttribute('aria-multiselectable');
|
|
14
|
-
ec.run('tabindex', () => {
|
|
15
|
-
if (!el.hasAttribute('tabindex')) throw new Error('expected tabindex');
|
|
16
|
-
});
|
|
17
|
-
const subject = ec.run('subject', () => (0, _querySelectorOne.default)(el, 'div[jsaction][jslog] > div:not(:first-child):not(:last-child) > div > div[class]:not([style]):not(:first-child) > div:not(:first-child):not(:last-child) > div:not([style]):not(:first-child):not(:last-child):not([class*="inboxsdk"])'));
|
|
18
|
-
const checkbox = ec.run('checkbox', () => (0, _querySelectorOne.default)(el, 'div[jsaction] > div > div[jsaction] > div[role=checkbox]'));
|
|
19
|
-
const recipients = ec.run('recipients', () => el.querySelectorAll('div[jsaction] > div:not(:first-child):not(:last-child) > div > div > span[email]'));
|
|
20
|
-
const isOnlyDraft = ec.run('isOnlyDraft', () => !(recipients && recipients.length > 0));
|
|
21
|
-
const draftLabels = ec.run('draftLabels', () => {
|
|
22
|
-
const recipientCandidates = el.querySelectorAll('div[jsaction] > div:not(:first-child):not(:last-child) > div > div > span');
|
|
23
|
-
|
|
24
|
-
// We have to locate draft labels via text color because it's impossible
|
|
25
|
-
// to locate them with reliable CSS selectors
|
|
26
|
-
return Array.from(recipientCandidates).filter(candidate => {
|
|
27
|
-
const colorString = getComputedStyle(candidate).getPropertyValue('color');
|
|
28
|
-
const colorMatch = RGB_REGEX.exec(colorString);
|
|
29
|
-
if (!colorMatch) throw new Error('Failed to read color string');
|
|
30
|
-
const r = +colorMatch[1],
|
|
31
|
-
g = +colorMatch[2],
|
|
32
|
-
b = +colorMatch[3];
|
|
33
|
-
return r > 200 && g < 100 && b < 100; // Draft labels are red
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
const recipientParent = ec.run('recipientParent', () => {
|
|
38
|
-
if (recipients && recipients.length > 0) return recipients[0].parentElement;
|
|
39
|
-
|
|
40
|
-
// There are no recipient elements with an email attr, which means this
|
|
41
|
-
// thread only has drafts. In order to find the recipient parent we need
|
|
42
|
-
// to work from a draft label upwards.
|
|
43
|
-
if (!(draftLabels && draftLabels.length > 0)) throw new Error('Could not locate draft labels');
|
|
44
|
-
return draftLabels[0].parentElement;
|
|
45
|
-
});
|
|
46
|
-
const inboxThreadId = ec.run('thread id', () => {
|
|
47
|
-
const m = /thread-[^:]+:[^:\d]*(\d+)/.exec(el.getAttribute('data-item-id') || '');
|
|
48
|
-
if (!m) {
|
|
49
|
-
throw new Error('thread row id regex failed');
|
|
50
|
-
}
|
|
51
|
-
return m[0];
|
|
52
|
-
});
|
|
53
|
-
const messageCountParent = ec.run('messageCountParent', () => recipientParent && recipientParent.nextElementSibling);
|
|
54
|
-
const visibleMessageCount = ec.run('visibleMessageCount', () => {
|
|
55
|
-
const messageCountEl = messageCountParent && messageCountParent.querySelector('span');
|
|
56
|
-
const match = messageCountEl && /^\((\d+)\)$/.exec(messageCountEl.textContent);
|
|
57
|
-
if (!match) return 1;
|
|
58
|
-
return parseInt(match[1]);
|
|
59
|
-
});
|
|
60
|
-
const visibleDraftCount = ec.run('visibleDraftCount', () => {
|
|
61
|
-
if (isOnlyDraft && visibleMessageCount) return visibleMessageCount;
|
|
62
|
-
if (!draftLabels) throw new Error('Could not locate draft labels');
|
|
63
|
-
return draftLabels.length;
|
|
64
|
-
});
|
|
65
|
-
const contacts = ec.run('contacts', () => {
|
|
66
|
-
if (!recipients) return null;
|
|
67
|
-
return Array.from(recipients).map(recipientEl => {
|
|
68
|
-
const emailAddress = recipientEl.getAttribute('email');
|
|
69
|
-
if (!emailAddress) return null;
|
|
70
|
-
return {
|
|
71
|
-
name: null,
|
|
72
|
-
emailAddress
|
|
73
|
-
};
|
|
74
|
-
}).filter(Boolean);
|
|
75
|
-
});
|
|
76
|
-
const labelParent = ec.run('labelParent', () => (0, _querySelectorOne.default)(el, 'div[jsaction][jslog] > div:not(:first-child):not(:last-child) > div > div[class]:not([style]):not(:first-child) > div:not(:first-child):not(:last-child)'));
|
|
77
|
-
const toolbar = ec.run('toolbar', () => (0, _querySelectorOne.default)(el, 'div[jsaction] div[jsaction] > ul[aria-label]'));
|
|
78
|
-
const elements = {
|
|
79
|
-
subject,
|
|
80
|
-
checkbox,
|
|
81
|
-
labelParent,
|
|
82
|
-
toolbar,
|
|
83
|
-
recipientParent,
|
|
84
|
-
messageCountParent
|
|
85
|
-
};
|
|
86
|
-
const score = 1 - ec.errorCount() / ec.runCount();
|
|
87
|
-
return {
|
|
88
|
-
elements,
|
|
89
|
-
attributes: {
|
|
90
|
-
isOnlyDraft,
|
|
91
|
-
inBundle,
|
|
92
|
-
inboxThreadId,
|
|
93
|
-
visibleMessageCount,
|
|
94
|
-
visibleDraftCount,
|
|
95
|
-
contacts
|
|
96
|
-
},
|
|
97
|
-
score,
|
|
98
|
-
errors: ec.getErrorLogs()
|
|
99
|
-
};
|
|
100
|
-
}
|
|
@@ -1,99 +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 = getComposeViewDriverLiveSet;
|
|
8
|
-
var _kefir = _interopRequireDefault(require("kefir"));
|
|
9
|
-
var _liveSet = _interopRequireDefault(require("live-set"));
|
|
10
|
-
var _censorHTMLtree = _interopRequireDefault(require("../../../common/censorHTMLtree"));
|
|
11
|
-
var _inboxComposeView = _interopRequireDefault(require("./views/inbox-compose-view"));
|
|
12
|
-
var _toItemWithLifetimeStream = _interopRequireDefault(require("../../lib/toItemWithLifetimeStream"));
|
|
13
|
-
var _makeElementStreamMerger = _interopRequireDefault(require("../../lib/dom/make-element-stream-merger"));
|
|
14
|
-
var _parser = _interopRequireDefault(require("./detection/compose/parser"));
|
|
15
|
-
function getComposeViewDriverLiveSet(driver, tree) {
|
|
16
|
-
const denodeify = _ref => {
|
|
17
|
-
let {
|
|
18
|
-
el,
|
|
19
|
-
removalStream
|
|
20
|
-
} = _ref;
|
|
21
|
-
return {
|
|
22
|
-
el: el.getValue(),
|
|
23
|
-
removalStream
|
|
24
|
-
};
|
|
25
|
-
};
|
|
26
|
-
const inlineCompose = (0, _toItemWithLifetimeStream.default)(tree.getAllByTag('inlineCompose')).map(denodeify);
|
|
27
|
-
const regularCompose = (0, _toItemWithLifetimeStream.default)(tree.getAllByTag('regularCompose')).map(denodeify);
|
|
28
|
-
const fullscreenCompose = (0, _toItemWithLifetimeStream.default)(tree.getAllByTag('fullscreenCompose')).map(denodeify);
|
|
29
|
-
const compose = _kefir.default.merge([inlineCompose, regularCompose.merge(fullscreenCompose).flatMap((0, _makeElementStreamMerger.default)())]);
|
|
30
|
-
const composeViewDriverStream = compose.map(_ref2 => {
|
|
31
|
-
let {
|
|
32
|
-
el,
|
|
33
|
-
removalStream
|
|
34
|
-
} = _ref2;
|
|
35
|
-
const parsed = (0, _parser.default)(el);
|
|
36
|
-
if (parsed.errors.length) {
|
|
37
|
-
driver.getLogger().errorSite(new Error('parse errors (compose)'), {
|
|
38
|
-
score: parsed.score,
|
|
39
|
-
errors: parsed.errors,
|
|
40
|
-
html: (0, _censorHTMLtree.default)(el)
|
|
41
|
-
});
|
|
42
|
-
}
|
|
43
|
-
const view = new _inboxComposeView.default(driver, el, parsed);
|
|
44
|
-
removalStream.take(1).onValue(() => view.removedFromDOM());
|
|
45
|
-
return view;
|
|
46
|
-
});
|
|
47
|
-
return new _liveSet.default({
|
|
48
|
-
scheduler: tree.getAllByTag('inlineCompose').getScheduler(),
|
|
49
|
-
read() {
|
|
50
|
-
return new Set();
|
|
51
|
-
},
|
|
52
|
-
listen(setValues, controller) {
|
|
53
|
-
setValues(new Set());
|
|
54
|
-
const sub = composeViewDriverStream.observe({
|
|
55
|
-
value(composeViewDriver) {
|
|
56
|
-
controller.add(composeViewDriver);
|
|
57
|
-
composeViewDriver.getStopper().onValue(() => {
|
|
58
|
-
controller.remove(composeViewDriver);
|
|
59
|
-
});
|
|
60
|
-
},
|
|
61
|
-
error(err) {
|
|
62
|
-
// If we get here, it's probably because of a waitFor timeout caused by
|
|
63
|
-
// us failing to find the compose parent. Let's log the results of a few
|
|
64
|
-
// similar selectors to see if our selector was maybe slightly wrong.
|
|
65
|
-
function getStatus() {
|
|
66
|
-
return {
|
|
67
|
-
mainLength: document.querySelectorAll('[role=main]').length,
|
|
68
|
-
regularLength: document.querySelectorAll('body > div[id][jsaction] > div[id][class]:not([role]) > div[class] > div[id]').length,
|
|
69
|
-
noJsActionLength: document.querySelectorAll('body > div[id] > div[id][class]:not([role]) > div[class] > div[id]').length,
|
|
70
|
-
noNotLength: document.querySelectorAll('body > div[id][jsaction] > div[id][class] > div[class] > div[id]').length,
|
|
71
|
-
noBodyDirectChildLength: document.querySelectorAll('body div[id][jsaction] > div[id][class]:not([role]) > div[class] > div[id]').length,
|
|
72
|
-
noBodyLength: document.querySelectorAll('div[id][jsaction] > div[id][class]:not([role]) > div[class] > div[id]').length,
|
|
73
|
-
// We can use class names for logging heuristics. Don't want to use
|
|
74
|
-
// them anywhere else.
|
|
75
|
-
classLength: document.querySelectorAll('div.ek div.md > div').length,
|
|
76
|
-
classEkLength: document.querySelectorAll('.ek').length,
|
|
77
|
-
classMdLength: document.querySelectorAll('.md').length,
|
|
78
|
-
composeHtml: Array.from(document.querySelectorAll('body > div[id][jsaction] > div[id][class]:not([role]) > div[class] > div[id], div.ek div.md > div')).map(el => (0, _censorHTMLtree.default)(el))
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
const startStatus = getStatus();
|
|
82
|
-
const waitTime = 180 * 1000;
|
|
83
|
-
driver.getLogger().error(err, startStatus);
|
|
84
|
-
setTimeout(() => {
|
|
85
|
-
const laterStatus = getStatus();
|
|
86
|
-
driver.getLogger().eventSdkPassive('waitfor compose data', {
|
|
87
|
-
startStatus,
|
|
88
|
-
waitTime,
|
|
89
|
-
laterStatus
|
|
90
|
-
});
|
|
91
|
-
}, waitTime);
|
|
92
|
-
}
|
|
93
|
-
});
|
|
94
|
-
return () => {
|
|
95
|
-
sub.unsubscribe();
|
|
96
|
-
};
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
}
|
package/src/platform-implementation-js/dom-driver/inbox/getInboxMessageIdForInboxThreadId.js
DELETED
|
@@ -1,36 +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 _ud = require("ud");
|
|
9
|
-
var _inboxAjax = _interopRequireDefault(require("../../driver-common/inboxAjax"));
|
|
10
|
-
var _getAccountUrlPart = _interopRequireDefault(require("../../driver-common/getAccountUrlPart"));
|
|
11
|
-
var _inboxResponseProcessor = require("./inboxResponseProcessor");
|
|
12
|
-
async function getInboxMessageIdForInboxThreadId(driver, inboxThreadId) {
|
|
13
|
-
const {
|
|
14
|
-
text
|
|
15
|
-
} = await (0, _inboxAjax.default)({
|
|
16
|
-
method: 'POST',
|
|
17
|
-
url: `https://inbox.google.com/sync${(0, _getAccountUrlPart.default)()}/i/fd`,
|
|
18
|
-
headers: {
|
|
19
|
-
'Content-Type': 'application/json',
|
|
20
|
-
'X-Framework-Xsrf-Token': await driver.getPageCommunicator().getXsrfToken(),
|
|
21
|
-
'X-Gmail-BTAI': await driver.getPageCommunicator().getBtaiHeader(),
|
|
22
|
-
'X-Google-BTD': '1'
|
|
23
|
-
},
|
|
24
|
-
data: JSON.stringify({
|
|
25
|
-
'1': [{
|
|
26
|
-
'1': inboxThreadId,
|
|
27
|
-
'3': []
|
|
28
|
-
}]
|
|
29
|
-
})
|
|
30
|
-
});
|
|
31
|
-
const [firstMessageId] = (0, _inboxResponseProcessor.extractMessageIdsFromThreadResponse)(text);
|
|
32
|
-
if (!firstMessageId) throw new Error('Failed to find inbox message ID for thread');
|
|
33
|
-
return firstMessageId;
|
|
34
|
-
}
|
|
35
|
-
var _default = (0, _ud.defn)(module, getInboxMessageIdForInboxThreadId);
|
|
36
|
-
exports.default = _default;
|
|
@@ -1,114 +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 _difference = _interopRequireDefault(require("lodash/difference"));
|
|
9
|
-
var _once = _interopRequireDefault(require("lodash/once"));
|
|
10
|
-
var _flatMap = _interopRequireDefault(require("lodash/flatMap"));
|
|
11
|
-
var _last = _interopRequireDefault(require("lodash/last"));
|
|
12
|
-
var _transducers = _interopRequireDefault(require("transducers.js"));
|
|
13
|
-
var _postcssSelectorParser = _interopRequireDefault(require("postcss-selector-parser"));
|
|
14
|
-
var _logger = _interopRequireDefault(require("../../lib/logger"));
|
|
15
|
-
var _querySelectorOrFail = _interopRequireDefault(require("../../lib/dom/querySelectorOrFail"));
|
|
16
|
-
const cssProcessor = (0, _postcssSelectorParser.default)();
|
|
17
|
-
|
|
18
|
-
// There are specific classnames which are added when the chat or nav sidebars
|
|
19
|
-
// are open which affect the layout of the page. We need to be able to activate
|
|
20
|
-
// that chat sidebar layout ourselves, and we don't want to hardcode this
|
|
21
|
-
// classname because Inbox is prone to changing their classnames.
|
|
22
|
-
|
|
23
|
-
// We also get the classname for the center list element which has margins
|
|
24
|
-
// applied to it depending on the current page width and sidebar settings to
|
|
25
|
-
// keep it lined up with the search bar.
|
|
26
|
-
|
|
27
|
-
const getSidebarClassnames = (0, _once.default)(() => {
|
|
28
|
-
// We know that the page has a CSS rule which looks like
|
|
29
|
-
// .blah.chat .foo { margin-right: bigger number; margin-left: smaller number; }
|
|
30
|
-
// where .chat is the chat sidebar classname that we want to know, and .foo
|
|
31
|
-
// is one of the classnames that's on the [role=application] element.
|
|
32
|
-
|
|
33
|
-
// We could search the rules for this rule, but then we don't know which part
|
|
34
|
-
// of the selector string is the chat sidebar classname!
|
|
35
|
-
|
|
36
|
-
// There's also another similar rule for when only the nav sidebar is open:
|
|
37
|
-
// .blah.nav .foo { margin-right: smaller number; margin-left: bigger number; }
|
|
38
|
-
// If we find both of thse rules, then we can find the classname which is
|
|
39
|
-
// mentioned in the chat sidebar rule which is not mentioned in the nav
|
|
40
|
-
// sidebar rule.
|
|
41
|
-
|
|
42
|
-
// So first we find all the classnames on the [role=application] and make a
|
|
43
|
-
// regex for each one.
|
|
44
|
-
const classRegexes = Array.from((0, _querySelectorOrFail.default)(document, '[role=application]').classList).map(x => new RegExp('\\.' + x + '\\b'));
|
|
45
|
-
if (classRegexes.length === 0) throw new Error('no class names on element');
|
|
46
|
-
|
|
47
|
-
// rules will contain both the chat and nav sidebar rules.
|
|
48
|
-
const rules = _transducers.default.toArray(Array.prototype.slice.call(document.styleSheets), _transducers.default.compose(_transducers.default.filter(sheet => {
|
|
49
|
-
try {
|
|
50
|
-
return sheet.cssRules && sheet.cssRules.length;
|
|
51
|
-
} catch (err) {
|
|
52
|
-
// ignore. Sometimes pages have stylesheets that don't permit their
|
|
53
|
-
// rules to be enumerated. Possibly caused by other extensions including
|
|
54
|
-
// a css file from another domain?
|
|
55
|
-
return false;
|
|
56
|
-
}
|
|
57
|
-
}), _transducers.default.mapcat(sheet => Array.prototype.slice.call(sheet.cssRules || [])), _transducers.default.mapcat(rulesToStyleRules),
|
|
58
|
-
// We have all page rules. Filter it down to just rules mentioning one of
|
|
59
|
-
// [role=application]'s classnames.
|
|
60
|
-
_transducers.default.filter(rule => classRegexes.some(r => r.test(rule.selectorText))),
|
|
61
|
-
// Now just the rules that contain both margin-left and -right rules.
|
|
62
|
-
_transducers.default.filter(rule => rule.style['margin-left'] && rule.style['margin-right'])));
|
|
63
|
-
const onlyNavSidebarRule = _transducers.default.toArray(Array.prototype.slice.call(rules), _transducers.default.compose(_transducers.default.filter(rule => parseFloat(rule.style['margin-left']) > parseFloat(rule.style['margin-right'])), _transducers.default.take(1)))[0];
|
|
64
|
-
const onlyChatSidebarRule = _transducers.default.toArray(Array.prototype.slice.call(rules), _transducers.default.compose(_transducers.default.filter(rule => parseFloat(rule.style['margin-left']) < parseFloat(rule.style['margin-right'])), _transducers.default.take(1)))[0];
|
|
65
|
-
if (!onlyNavSidebarRule || !onlyChatSidebarRule) {
|
|
66
|
-
const err = new Error('Failed to parse element CSS rules');
|
|
67
|
-
_logger.default.error(err, {
|
|
68
|
-
rulesCount: rules.length,
|
|
69
|
-
hasOnlyNavSidebarRule: !!onlyNavSidebarRule,
|
|
70
|
-
hasOnlyChatSidebarRule: !!onlyChatSidebarRule
|
|
71
|
-
});
|
|
72
|
-
throw err;
|
|
73
|
-
}
|
|
74
|
-
function getMentionedClassNames(node) {
|
|
75
|
-
switch (node.type) {
|
|
76
|
-
case 'root':
|
|
77
|
-
case 'selector':
|
|
78
|
-
return (0, _flatMap.default)(node.nodes, getMentionedClassNames);
|
|
79
|
-
case 'class':
|
|
80
|
-
return [node.value];
|
|
81
|
-
default:
|
|
82
|
-
return [];
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
const onlyNavSidebarRuleClassNames = getMentionedClassNames(cssProcessor.process(onlyNavSidebarRule.selectorText).res);
|
|
86
|
-
const onlyChatSidebarRuleClassNames = getMentionedClassNames(cssProcessor.process(onlyChatSidebarRule.selectorText).res);
|
|
87
|
-
const chatSidebarClassNames = (0, _difference.default)(onlyChatSidebarRuleClassNames, onlyNavSidebarRuleClassNames);
|
|
88
|
-
const navSidebarClassNames = (0, _difference.default)(onlyNavSidebarRuleClassNames, onlyChatSidebarRuleClassNames);
|
|
89
|
-
const centerListClassName = (0, _last.default)(onlyNavSidebarRuleClassNames) === (0, _last.default)(onlyChatSidebarRuleClassNames) ? (0, _last.default)(onlyNavSidebarRuleClassNames) : null;
|
|
90
|
-
if (chatSidebarClassNames.length !== 1 || navSidebarClassNames.length !== 1 || !centerListClassName) {
|
|
91
|
-
_logger.default.error(new Error('Failed to find sidebar classnames'), {
|
|
92
|
-
onlyNavSidebarRuleClassNames,
|
|
93
|
-
onlyChatSidebarRuleClassNames,
|
|
94
|
-
chatSidebarClassNames,
|
|
95
|
-
navSidebarClassNames,
|
|
96
|
-
centerListClassName
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
return {
|
|
100
|
-
chat: chatSidebarClassNames[0],
|
|
101
|
-
nav: navSidebarClassNames[0],
|
|
102
|
-
centerList: centerListClassName
|
|
103
|
-
};
|
|
104
|
-
});
|
|
105
|
-
var _default = getSidebarClassnames;
|
|
106
|
-
exports.default = _default;
|
|
107
|
-
function rulesToStyleRules(rule) {
|
|
108
|
-
if (rule instanceof window.CSSMediaRule) {
|
|
109
|
-
return (0, _flatMap.default)(rule.cssRules, rulesToStyleRules);
|
|
110
|
-
} else if (rule instanceof window.CSSStyleRule) {
|
|
111
|
-
return [rule];
|
|
112
|
-
}
|
|
113
|
-
return [];
|
|
114
|
-
}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _getSidebarClassnames = _interopRequireDefault(require("./getSidebarClassnames"));
|
|
5
|
-
document.documentElement.innerHTML = `
|
|
6
|
-
<head>
|
|
7
|
-
<style type="text/css">
|
|
8
|
-
.blah {
|
|
9
|
-
color: red;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
.bz, .bS {
|
|
13
|
-
width: 1200px;
|
|
14
|
-
margin-left: auto;
|
|
15
|
-
margin-right: auto;
|
|
16
|
-
}
|
|
17
|
-
@media (max-width: 1800px) {
|
|
18
|
-
.bz, .bS {
|
|
19
|
-
width: 66.66%;
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
@media (max-width: 1260px) {
|
|
23
|
-
.bz, .bS {
|
|
24
|
-
width: 840px;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
.cM {
|
|
28
|
-
min-width: 512px;
|
|
29
|
-
padding: 56px 0 1px;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
/* chat sidebar open rules */
|
|
33
|
-
@media (max-width: 1632px) {
|
|
34
|
-
.m .bz {
|
|
35
|
-
width: auto;
|
|
36
|
-
margin-left: 50px;
|
|
37
|
-
margin-right: 272px;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
/* nav sidebar open rules */
|
|
42
|
-
@media (max-width: 1632px) {
|
|
43
|
-
.M .bz {
|
|
44
|
-
width: auto;
|
|
45
|
-
margin-left: 272px;
|
|
46
|
-
margin-right: 104px;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
/* both open */
|
|
51
|
-
@media (max-width: 1632px) {
|
|
52
|
-
.m.M .bz {
|
|
53
|
-
margin-left: 272px;
|
|
54
|
-
margin-right: 272px;
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
</style>
|
|
58
|
-
</head>
|
|
59
|
-
<body>
|
|
60
|
-
<div>
|
|
61
|
-
<div role="application" class="cM bz">
|
|
62
|
-
<p>foo
|
|
63
|
-
</div>
|
|
64
|
-
</div>
|
|
65
|
-
</body>
|
|
66
|
-
`;
|
|
67
|
-
test('works', () => {
|
|
68
|
-
expect((0, _getSidebarClassnames.default)()).toEqual({
|
|
69
|
-
chat: 'm',
|
|
70
|
-
nav: 'M',
|
|
71
|
-
centerList: 'bz'
|
|
72
|
-
});
|
|
73
|
-
});
|
|
@@ -1,39 +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 = gotoView;
|
|
8
|
-
var _includes = _interopRequireDefault(require("lodash/includes"));
|
|
9
|
-
var _populateRouteID = _interopRequireDefault(require("../../lib/populateRouteID"));
|
|
10
|
-
var _routeIDmatchesHash = _interopRequireDefault(require("../../lib/routeIDmatchesHash"));
|
|
11
|
-
var _router = require("../../constants/router");
|
|
12
|
-
function gotoView(driver, routeID, params) {
|
|
13
|
-
if ((0, _includes.default)(Object.values(_router.NATIVE_ROUTE_IDS), routeID)) {
|
|
14
|
-
throw new Error('NativeRouteIDs are not currently supported in Inbox');
|
|
15
|
-
}
|
|
16
|
-
if (!driver.getCustomRouteIDs().has(routeID)) {
|
|
17
|
-
const startedWithHash = routeID[0] === '#';
|
|
18
|
-
if (startedWithHash) {
|
|
19
|
-
routeID = routeID.slice(1);
|
|
20
|
-
}
|
|
21
|
-
let foundRouteID = false;
|
|
22
|
-
if (!params) {
|
|
23
|
-
// If params were given, then we don't assume it was a resolved/populated URL
|
|
24
|
-
for (let routeIDs of driver.getCustomRouteIDs()) {
|
|
25
|
-
if ((0, _routeIDmatchesHash.default)(routeIDs, routeID)) {
|
|
26
|
-
foundRouteID = true;
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
if (!foundRouteID) {
|
|
32
|
-
throw new Error(`Invalid routeID: ${routeID}`);
|
|
33
|
-
}
|
|
34
|
-
if (!startedWithHash) {
|
|
35
|
-
driver.getLogger().deprecationWarning('Router.goto resolved routeID without "#" prefix');
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
document.location.hash = (0, _populateRouteID.default)(routeID, params);
|
|
39
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
var _gotoView = _interopRequireDefault(require("./gotoView"));
|
|
5
|
-
function makeDriver() {
|
|
6
|
-
const customRouteIDs = new Set();
|
|
7
|
-
return {
|
|
8
|
-
getCustomRouteIDs: () => customRouteIDs
|
|
9
|
-
};
|
|
10
|
-
}
|
|
11
|
-
test('works for custom view', () => {
|
|
12
|
-
const driver = makeDriver();
|
|
13
|
-
driver.getCustomRouteIDs().add('example/:bar');
|
|
14
|
-
(0, _gotoView.default)(driver, 'example/:bar', {
|
|
15
|
-
bar: 'foo'
|
|
16
|
-
});
|
|
17
|
-
expect(document.location.hash).toBe('#example/foo');
|
|
18
|
-
});
|
|
19
|
-
test('fails for unknown route id', () => {
|
|
20
|
-
expect(() => (0, _gotoView.default)(makeDriver(), 'example/:bar', {
|
|
21
|
-
bar: 'foo'
|
|
22
|
-
})).toThrowError('Invalid routeID: example/:bar');
|
|
23
|
-
});
|
|
24
|
-
test('fails for native route ids', () => {
|
|
25
|
-
expect(() => (0, _gotoView.default)(makeDriver(), 'inbox/:threadID', {
|
|
26
|
-
threadID: 'abc'
|
|
27
|
-
})).toThrowError('NativeRouteIDs are not currently supported in Inbox');
|
|
28
|
-
});
|
|
@@ -1,148 +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 _kefir = _interopRequireDefault(require("kefir"));
|
|
9
|
-
var _streamWaitFor = _interopRequireDefault(require("../../lib/stream-wait-for"));
|
|
10
|
-
var _querySelectorOrFail = _interopRequireDefault(require("../../lib/dom/querySelectorOrFail"));
|
|
11
|
-
var _makeMutationObserverChunkedStream = _interopRequireDefault(require("../../lib/dom/make-mutation-observer-chunked-stream"));
|
|
12
|
-
const elements = (0, _streamWaitFor.default)(() => document.querySelector('body > div[id][jsaction] > div[id] > div[class][jsaction][aria-hidden]')).map(googleNotice => {
|
|
13
|
-
const noticeContainer = googleNotice.parentElement;
|
|
14
|
-
if (!noticeContainer) throw new Error('Should not happen');
|
|
15
|
-
let sdkNotice = noticeContainer.querySelector('.inboxsdk__butterbar');
|
|
16
|
-
if (!sdkNotice) {
|
|
17
|
-
sdkNotice = document.createElement('div');
|
|
18
|
-
sdkNotice.className = googleNotice.className + ' inboxsdk__butterbar';
|
|
19
|
-
sdkNotice.style.display = 'none';
|
|
20
|
-
noticeContainer.insertBefore(sdkNotice, googleNotice.nextSibling);
|
|
21
|
-
}
|
|
22
|
-
return {
|
|
23
|
-
noticeContainer,
|
|
24
|
-
googleNotice,
|
|
25
|
-
sdkNotice
|
|
26
|
-
};
|
|
27
|
-
}).toProperty();
|
|
28
|
-
|
|
29
|
-
// We queue our notices separately from the native ones in Inbox.
|
|
30
|
-
|
|
31
|
-
const sdkNoticeIdChanges = elements.flatMapLatest(_ref => {
|
|
32
|
-
let {
|
|
33
|
-
sdkNotice
|
|
34
|
-
} = _ref;
|
|
35
|
-
return (0, _makeMutationObserverChunkedStream.default)(sdkNotice, {
|
|
36
|
-
attributes: true,
|
|
37
|
-
attributeFilter: ['data-inboxsdk-id']
|
|
38
|
-
}).map(() => sdkNotice.getAttribute('data-inboxsdk-id'));
|
|
39
|
-
});
|
|
40
|
-
const sdkRemovedNotice = sdkNoticeIdChanges.filter(id => id == null);
|
|
41
|
-
const noticeAvailableStream = sdkRemovedNotice;
|
|
42
|
-
function hideMessage(noticeContainer, googleNotice, sdkNotice) {
|
|
43
|
-
Object.assign(sdkNotice.style, {
|
|
44
|
-
opacity: '0',
|
|
45
|
-
transform: '',
|
|
46
|
-
transition: 'opacity 100ms'
|
|
47
|
-
});
|
|
48
|
-
sdkNotice.removeAttribute('data-inboxsdk-id');
|
|
49
|
-
_kefir.default.fromEvents(sdkNotice, 'transitionend').merge(_kefir.default.later(200)) // transition might not finish if element is hidden
|
|
50
|
-
.takeUntilBy(sdkNoticeIdChanges.filter(id => id != null)).onValue(() => {
|
|
51
|
-
Object.assign(sdkNotice.style, {
|
|
52
|
-
display: 'none',
|
|
53
|
-
opacity: '',
|
|
54
|
-
transition: ''
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
class InboxButterBarDriver {
|
|
59
|
-
constructor() {
|
|
60
|
-
// Force stream to be in active state. sdkRemovedNotice is prone to missing
|
|
61
|
-
// events if it only becomes active once a message has started.
|
|
62
|
-
noticeAvailableStream.onValue(() => {});
|
|
63
|
-
}
|
|
64
|
-
getNoticeAvailableStream() {
|
|
65
|
-
return noticeAvailableStream;
|
|
66
|
-
}
|
|
67
|
-
getSharedMessageQueue() {
|
|
68
|
-
const attr = document.head.getAttribute('data-inboxsdk-butterbar-queue');
|
|
69
|
-
return attr ? JSON.parse(attr) : [];
|
|
70
|
-
}
|
|
71
|
-
setSharedMessageQueue(queue) {
|
|
72
|
-
const attr = JSON.stringify(queue);
|
|
73
|
-
document.head.setAttribute('data-inboxsdk-butterbar-queue', attr);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
// Immediately displays the message, overriding anything else on the screen.
|
|
77
|
-
// Priority and queuing logic is handled by butter-bar.js above this.
|
|
78
|
-
showMessage(rawOptions) {
|
|
79
|
-
const instanceId = Date.now() + '-' + Math.random();
|
|
80
|
-
elements.take(1).onValue(_ref2 => {
|
|
81
|
-
let {
|
|
82
|
-
noticeContainer,
|
|
83
|
-
googleNotice,
|
|
84
|
-
sdkNotice
|
|
85
|
-
} = _ref2;
|
|
86
|
-
sdkNotice.className = googleNotice.className;
|
|
87
|
-
sdkNotice.classList.add('inboxsdk__butterbar');
|
|
88
|
-
if (rawOptions.html) {
|
|
89
|
-
sdkNotice.innerHTML = rawOptions.html;
|
|
90
|
-
} else if (rawOptions.el) {
|
|
91
|
-
sdkNotice.innerHTML = '';
|
|
92
|
-
sdkNotice.appendChild(rawOptions.el);
|
|
93
|
-
} else {
|
|
94
|
-
sdkNotice.textContent = rawOptions.text;
|
|
95
|
-
}
|
|
96
|
-
if (rawOptions.className) {
|
|
97
|
-
sdkNotice.classList.add(rawOptions.className);
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
// If the sdkNotice is already up, just flash it out and in instead of
|
|
101
|
-
// animating it up into position.
|
|
102
|
-
if (sdkNotice.style.display === 'block' && getComputedStyle(sdkNotice).opacity === '1') {
|
|
103
|
-
Object.assign(sdkNotice.style, {
|
|
104
|
-
opacity: '0',
|
|
105
|
-
transform: 'none',
|
|
106
|
-
transition: 'none'
|
|
107
|
-
});
|
|
108
|
-
sdkNotice.offsetHeight; // force relayout
|
|
109
|
-
Object.assign(sdkNotice.style, {
|
|
110
|
-
opacity: '1',
|
|
111
|
-
transition: ''
|
|
112
|
-
});
|
|
113
|
-
} else {
|
|
114
|
-
Object.assign(sdkNotice.style, {
|
|
115
|
-
opacity: '0',
|
|
116
|
-
transform: '',
|
|
117
|
-
transition: '',
|
|
118
|
-
display: 'block'
|
|
119
|
-
});
|
|
120
|
-
sdkNotice.offsetHeight; // force relayout
|
|
121
|
-
Object.assign(sdkNotice.style, {
|
|
122
|
-
opacity: '1',
|
|
123
|
-
transform: 'none'
|
|
124
|
-
});
|
|
125
|
-
}
|
|
126
|
-
sdkNotice.setAttribute('data-inboxsdk-id', instanceId);
|
|
127
|
-
});
|
|
128
|
-
return {
|
|
129
|
-
destroy() {
|
|
130
|
-
elements.take(1).onValue(_ref3 => {
|
|
131
|
-
let {
|
|
132
|
-
noticeContainer,
|
|
133
|
-
googleNotice,
|
|
134
|
-
sdkNotice
|
|
135
|
-
} = _ref3;
|
|
136
|
-
if (sdkNotice.getAttribute('data-inboxsdk-id') === instanceId) {
|
|
137
|
-
if (rawOptions.className) sdkNotice.classList.remove(rawOptions.className);
|
|
138
|
-
hideMessage(noticeContainer, googleNotice, sdkNotice);
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
hideGmailMessage() {
|
|
145
|
-
// No-op in Inbox because we don't touch the native messages
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
|
-
exports.default = InboxButterBarDriver;
|