expensify-common 1.0.1 → 2.0.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/README.md +15 -6
- package/dist/API.d.ts +11 -0
- package/{lib/API.jsx → dist/API.js} +230 -165
- package/dist/APIDeferred.d.ts +7 -0
- package/{lib/APIDeferred.jsx → dist/APIDeferred.js} +35 -53
- package/dist/BrowserDetect.d.ts +19 -0
- package/dist/BrowserDetect.js +107 -0
- package/dist/CONST.d.ts +813 -0
- package/{lib/CONST.jsx → dist/CONST.js} +245 -167
- package/dist/Cookie.d.ts +68 -0
- package/{lib/Cookie.jsx → dist/Cookie.js} +23 -36
- package/dist/CredentialsWrapper.d.ts +32 -0
- package/dist/CredentialsWrapper.js +52 -0
- package/dist/Device.d.ts +8 -0
- package/dist/Device.js +15 -0
- package/dist/ExpenseRule.d.ts +39 -0
- package/{lib/ExpenseRule.jsx → dist/ExpenseRule.js} +12 -14
- package/dist/ExpensiMark.d.ts +142 -0
- package/dist/ExpensiMark.js +1026 -0
- package/dist/Func.d.ts +40 -0
- package/{lib/Func.jsx → dist/Func.js} +19 -25
- package/dist/Log.d.ts +3 -0
- package/dist/Log.js +41 -0
- package/dist/Logger.d.ts +77 -0
- package/dist/Logger.js +126 -0
- package/dist/Network.d.ts +6 -0
- package/{lib/Network.jsx → dist/Network.js} +48 -45
- package/dist/Num.d.ts +95 -0
- package/{lib/Num.jsx → dist/Num.js} +20 -40
- package/dist/PageEvent.d.ts +25 -0
- package/dist/PageEvent.js +28 -0
- package/dist/PubSub.d.ts +2 -0
- package/{lib/PubSub.jsx → dist/PubSub.js} +27 -39
- package/dist/ReportHistoryStore.d.ts +64 -0
- package/dist/ReportHistoryStore.js +261 -0
- package/dist/Templates.d.ts +2 -0
- package/{lib/Templates.jsx → dist/Templates.js} +33 -48
- package/dist/Url.d.ts +22 -0
- package/dist/Url.js +30 -0
- package/dist/components/CopyText.d.ts +45 -0
- package/{lib/components/CopyText.jsx → dist/components/CopyText.js} +16 -23
- package/dist/components/StepProgressBar.d.ts +22 -0
- package/dist/components/StepProgressBar.js +68 -0
- package/dist/components/form/element/combobox.d.ts +237 -0
- package/{lib → dist}/components/form/element/combobox.js +361 -516
- package/dist/components/form/element/dropdown.d.ts +35 -0
- package/dist/components/form/element/dropdown.js +66 -0
- package/dist/components/form/element/dropdownItem.d.ts +55 -0
- package/dist/components/form/element/dropdownItem.js +118 -0
- package/dist/components/form/element/onOffSwitch.d.ts +94 -0
- package/dist/components/form/element/onOffSwitch.js +195 -0
- package/dist/components/form/element/switch.d.ts +58 -0
- package/{lib → dist}/components/form/element/switch.js +29 -66
- package/dist/fastMerge.d.ts +9 -0
- package/dist/fastMerge.js +77 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.js +71 -0
- package/dist/jquery.expensifyIframify.d.ts +10 -0
- package/{lib → dist}/jquery.expensifyIframify.js +52 -93
- package/dist/mixins/PubSub.d.ts +20 -0
- package/{lib/mixins/PubSub.jsx → dist/mixins/PubSub.js} +12 -11
- package/dist/mixins/extraClasses.d.ts +8 -0
- package/{lib → dist}/mixins/extraClasses.js +8 -12
- package/dist/mixins/validationClasses.d.ts +12 -0
- package/dist/mixins/validationClasses.js +58 -0
- package/dist/str.d.ts +613 -0
- package/{lib → dist}/str.js +176 -160
- package/dist/tlds.d.ts +2 -0
- package/dist/tlds.js +4 -0
- package/dist/utils.d.ts +5 -0
- package/dist/utils.js +13 -0
- package/package.json +47 -18
- package/.editorconfig +0 -34
- package/.eslintrc.js +0 -11
- package/.github/CODEOWNERS +0 -2
- package/.github/CONTRIBUTING.md +0 -163
- package/.github/ISSUE_TEMPLATE.md +0 -3
- package/.github/PULL_REQUEST_TEMPLATE.md +0 -14
- package/.github/workflows/cla.yml +0 -39
- package/.github/workflows/lint.yml +0 -29
- package/.github/workflows/test.yml +0 -29
- package/CLA.md +0 -20
- package/Gruntfile.js +0 -13
- package/__tests__/ExpensiMark-test.js +0 -340
- package/__tests__/Logger-test.js +0 -55
- package/__tests__/Str-test.js +0 -53
- package/babel.config.js +0 -12
- package/grunt/configloader.js +0 -17
- package/grunt/configs/chokidar.js +0 -23
- package/grunt/configs/eslint.js +0 -15
- package/grunt/task/watch.js +0 -3
- package/grunt/taskloader.js +0 -25
- package/lib/BrowserDetect.jsx +0 -91
- package/lib/ExpensiMark.js +0 -253
- package/lib/Log.jsx +0 -36
- package/lib/Logger.jsx +0 -154
- package/lib/PageEvent.jsx +0 -23
- package/lib/ReportHistoryStore.jsx +0 -194
- package/lib/components/StepProgressBar.js +0 -49
- package/lib/components/form/element/dropdown.js +0 -90
- package/lib/components/form/element/dropdownItem.js +0 -178
- package/lib/components/form/element/onOffSwitch.jsx +0 -229
- package/lib/mixins/validationClasses.js +0 -23
- package/lib/tlds.jsx +0 -3
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/**
|
|
2
3
|
* This is a jQuery plugin that provides some iFrame functionality like
|
|
3
4
|
* posting messages to the parent window.
|
|
@@ -15,8 +16,8 @@
|
|
|
15
16
|
* alert( data.msg );
|
|
16
17
|
* });
|
|
17
18
|
*/
|
|
18
|
-
|
|
19
|
-
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
exports.default = {
|
|
20
21
|
/**
|
|
21
22
|
* Loads the widget into jQuery
|
|
22
23
|
*
|
|
@@ -38,7 +39,6 @@ export default {
|
|
|
38
39
|
* @type {String} jQuery Element
|
|
39
40
|
*/
|
|
40
41
|
const defaultOrigin = `${window.location.protocol}//${window.location.hostname}`;
|
|
41
|
-
|
|
42
42
|
/**
|
|
43
43
|
* This indicates from and to which domains we need to send the messages.
|
|
44
44
|
* @type {Object}
|
|
@@ -54,40 +54,34 @@ export default {
|
|
|
54
54
|
'https://www.google.com': ['https://secure.expensify.com.dev', 'https://secure.expensify.com'],
|
|
55
55
|
'https://cdn.plaid.com': ['https://secure.expensify.com'],
|
|
56
56
|
};
|
|
57
|
-
|
|
58
57
|
/**
|
|
59
58
|
* Holds a reference to the jQuery iFrame object
|
|
60
59
|
*
|
|
61
60
|
* @type {Object} jQuery Element
|
|
62
61
|
*/
|
|
63
|
-
let
|
|
64
|
-
|
|
62
|
+
let iframeElement = null; // eslint-disable-line consistent-this
|
|
65
63
|
/**
|
|
66
64
|
* Whether or not the parent window is listening to the message event
|
|
67
65
|
*
|
|
68
66
|
* @type {Boolean}
|
|
69
67
|
*/
|
|
70
68
|
let parentIsListening = false;
|
|
71
|
-
|
|
72
69
|
/**
|
|
73
70
|
* Whether or not the plugin has been initialized
|
|
74
71
|
* @type {Boolean}
|
|
75
72
|
*/
|
|
76
73
|
let wasInitalized = false;
|
|
77
|
-
|
|
78
74
|
/**
|
|
79
75
|
* Whether or not the iframe is listening to the message event
|
|
80
76
|
*
|
|
81
77
|
* @type {Boolean}
|
|
82
78
|
*/
|
|
83
79
|
let iframeIsListening = false;
|
|
84
|
-
|
|
85
80
|
/**
|
|
86
81
|
* Keeps a record of if this script is running from the "parent" or the "iframe"
|
|
87
82
|
* so that we only have to do this logic once.
|
|
88
83
|
*/
|
|
89
84
|
let whatIAm;
|
|
90
|
-
|
|
91
85
|
/**
|
|
92
86
|
* Default settings for our plugin
|
|
93
87
|
*
|
|
@@ -95,30 +89,28 @@ export default {
|
|
|
95
89
|
*/
|
|
96
90
|
let settings = {
|
|
97
91
|
origin: defaultOrigin,
|
|
98
|
-
debug: false
|
|
92
|
+
debug: false,
|
|
99
93
|
};
|
|
100
|
-
|
|
101
94
|
/**
|
|
102
95
|
* Holds all of our registered event handlers
|
|
103
96
|
*
|
|
104
97
|
* @type {Object}
|
|
105
98
|
*/
|
|
106
99
|
let eventHandlers = {};
|
|
107
|
-
|
|
108
100
|
/**
|
|
109
101
|
* A method for logging things to the console for debugging
|
|
110
102
|
*/
|
|
111
103
|
function log(...args) {
|
|
112
|
-
if (settings.debug) {
|
|
113
|
-
|
|
114
|
-
const mainArguments = Array.prototype.slice.call(args);
|
|
115
|
-
const source = whatIAm === 'parent' ? 'Parent' : 'Iframe';
|
|
116
|
-
mainArguments.unshift(`${source}:`);
|
|
117
|
-
mainArguments.unshift('[EXPENSIFYIFRAMEIFY]');
|
|
118
|
-
console.log(...mainArguments);
|
|
104
|
+
if (!settings.debug) {
|
|
105
|
+
return;
|
|
119
106
|
}
|
|
107
|
+
// Make an array out of our arguments
|
|
108
|
+
const mainArguments = Array.prototype.slice.call(args);
|
|
109
|
+
const source = whatIAm === 'parent' ? 'Parent' : 'Iframe';
|
|
110
|
+
mainArguments.unshift(`${source}:`);
|
|
111
|
+
mainArguments.unshift('[EXPENSIFYIFRAMEIFY]');
|
|
112
|
+
console.log(...mainArguments); // eslint-disable-line no-console
|
|
120
113
|
}
|
|
121
|
-
|
|
122
114
|
/**
|
|
123
115
|
* Forms the message to send to our parent. The message structure is like:
|
|
124
116
|
*
|
|
@@ -141,25 +133,19 @@ export default {
|
|
|
141
133
|
*/
|
|
142
134
|
function postMessage(name, data, postToIframe) {
|
|
143
135
|
let msg = 'iframeify';
|
|
144
|
-
if (
|
|
145
|
-
msg += `:${
|
|
136
|
+
if (iframeElement.iframeId) {
|
|
137
|
+
msg += `:${iframeElement.iframeId}`;
|
|
146
138
|
}
|
|
147
|
-
|
|
148
139
|
msg += `:${name}`;
|
|
149
|
-
|
|
150
140
|
if (data) {
|
|
151
141
|
msg += '☢';
|
|
152
142
|
msg += JSON.stringify(data);
|
|
153
143
|
}
|
|
154
|
-
|
|
155
144
|
const isCommunicationAllowed = allowedCommunications[settings.origin];
|
|
156
|
-
|
|
157
145
|
if (!isCommunicationAllowed) {
|
|
158
146
|
log('not posting message, communication from this domain is not allowed', settings.origin, name, data);
|
|
159
147
|
}
|
|
160
|
-
|
|
161
148
|
let targetOrigin;
|
|
162
|
-
|
|
163
149
|
// Sending message from the iFrame to the parent
|
|
164
150
|
// Only post a message if this is in an iFrame
|
|
165
151
|
if (!postToIframe && window.parent !== window) {
|
|
@@ -167,15 +153,13 @@ export default {
|
|
|
167
153
|
log('posting message to parent', targetOrigin, msg);
|
|
168
154
|
window.parent.postMessage(msg, targetOrigin);
|
|
169
155
|
}
|
|
170
|
-
|
|
171
156
|
// Sending message from the parent to the iFrame
|
|
172
|
-
if (postToIframe &&
|
|
173
|
-
targetOrigin = `${
|
|
157
|
+
if (postToIframe && iframeElement[0].contentWindow) {
|
|
158
|
+
targetOrigin = `${iframeElement[0].contentWindow.location.protocol}//${iframeElement[0].contentWindow.location.hostname}`;
|
|
174
159
|
log('posting message to iframe', targetOrigin, msg);
|
|
175
|
-
|
|
160
|
+
iframeElement[0].contentWindow.postMessage(msg, targetOrigin);
|
|
176
161
|
}
|
|
177
162
|
}
|
|
178
|
-
|
|
179
163
|
/**
|
|
180
164
|
* Calls all the methods associated with the event name
|
|
181
165
|
* and passes it the given data
|
|
@@ -186,7 +170,7 @@ export default {
|
|
|
186
170
|
*/
|
|
187
171
|
function trigger(name, data, iframeId) {
|
|
188
172
|
log(`heard event "${name}"`, data);
|
|
189
|
-
const id = iframeId ||
|
|
173
|
+
const id = iframeId || iframeElement.iframeId;
|
|
190
174
|
if (eventHandlers[id] && eventHandlers[id][name] && eventHandlers[id][name].length) {
|
|
191
175
|
const listeners = eventHandlers[id][name];
|
|
192
176
|
for (let i = 0; i < listeners.length; i += 1) {
|
|
@@ -194,7 +178,6 @@ export default {
|
|
|
194
178
|
}
|
|
195
179
|
}
|
|
196
180
|
}
|
|
197
|
-
|
|
198
181
|
/**
|
|
199
182
|
* Handles the window message by parsing the data
|
|
200
183
|
* and relaying it to our event listeners
|
|
@@ -207,60 +190,51 @@ export default {
|
|
|
207
190
|
if (!event.origin || !event.target) {
|
|
208
191
|
return;
|
|
209
192
|
}
|
|
210
|
-
if (allowedCommunications[event.origin]
|
|
211
|
-
|
|
212
|
-
|
|
193
|
+
if (allowedCommunications[event.origin] &&
|
|
194
|
+
allowedCommunications[event.origin].indexOf('*') === -1 &&
|
|
195
|
+
allowedCommunications[event.origin].indexOf(`${event.target.location.protocol}//${event.target.location.hostname}`) === -1) {
|
|
213
196
|
log('not handling message, communication from this domain is not allowed', settings.origin);
|
|
214
197
|
return;
|
|
215
198
|
}
|
|
216
|
-
|
|
217
199
|
if (!event.data || !_.isString(event.data)) {
|
|
218
200
|
return;
|
|
219
201
|
}
|
|
220
|
-
|
|
221
202
|
// Get the pieces of our message (should be two)
|
|
222
203
|
const msgParts = event.data.split('☢');
|
|
223
|
-
|
|
224
204
|
if (!msgParts.length) {
|
|
225
205
|
return;
|
|
226
206
|
}
|
|
227
|
-
|
|
228
207
|
// Get the pieces of our name (should be two or three)
|
|
229
208
|
// and extract the event name and the iframe ID
|
|
230
209
|
const nameParts = msgParts[0].split(':');
|
|
231
|
-
|
|
232
210
|
if (!nameParts.length || nameParts.length > 3) {
|
|
233
211
|
return;
|
|
234
212
|
}
|
|
235
|
-
|
|
236
213
|
let iframeId = null;
|
|
237
214
|
let eventName = null;
|
|
238
215
|
let data = null;
|
|
239
216
|
if (nameParts.length === 3) {
|
|
240
217
|
iframeId = nameParts[1];
|
|
241
218
|
eventName = nameParts[2];
|
|
242
|
-
}
|
|
219
|
+
}
|
|
220
|
+
else if (nameParts.length === 2) {
|
|
243
221
|
eventName = nameParts[1];
|
|
244
222
|
}
|
|
245
|
-
|
|
246
223
|
// Get the data
|
|
247
224
|
if (msgParts.length > 1) {
|
|
248
225
|
try {
|
|
249
226
|
data = JSON.parse(msgParts[1]);
|
|
250
|
-
}
|
|
227
|
+
}
|
|
228
|
+
catch (exception) {
|
|
251
229
|
// This should only happen if someone didn't code something right
|
|
252
230
|
console.error('Could not parse JSON response for some reason', event.data);
|
|
253
231
|
}
|
|
254
232
|
}
|
|
255
|
-
|
|
256
233
|
// Trigger any listeners for this event
|
|
257
234
|
trigger(eventName, data, iframeId);
|
|
258
235
|
}
|
|
259
|
-
|
|
260
236
|
const actions = {
|
|
261
|
-
|
|
262
237
|
// Add actions here
|
|
263
|
-
|
|
264
238
|
/**
|
|
265
239
|
* Tells the parent to dynamically resize the iFrame
|
|
266
240
|
*
|
|
@@ -271,18 +245,14 @@ export default {
|
|
|
271
245
|
*/
|
|
272
246
|
resize(args) {
|
|
273
247
|
const size = {};
|
|
274
|
-
|
|
275
248
|
if (args.height !== undefined) {
|
|
276
249
|
size.height = args.height;
|
|
277
250
|
}
|
|
278
|
-
|
|
279
251
|
if (args.width !== undefined) {
|
|
280
252
|
size.width = args.width;
|
|
281
253
|
}
|
|
282
|
-
|
|
283
254
|
postMessage('resize', size);
|
|
284
255
|
},
|
|
285
|
-
|
|
286
256
|
/**
|
|
287
257
|
* Tell our parent a generic message
|
|
288
258
|
*
|
|
@@ -293,7 +263,6 @@ export default {
|
|
|
293
263
|
tellParent(args) {
|
|
294
264
|
postMessage(args.name, args.data);
|
|
295
265
|
},
|
|
296
|
-
|
|
297
266
|
/**
|
|
298
267
|
* Tell our iFrame a generic message
|
|
299
268
|
*
|
|
@@ -304,7 +273,6 @@ export default {
|
|
|
304
273
|
tellIframe(args) {
|
|
305
274
|
postMessage(args.name, args.data, true);
|
|
306
275
|
},
|
|
307
|
-
|
|
308
276
|
/**
|
|
309
277
|
* Register an event handler. The callback will be stored
|
|
310
278
|
* for the particular iFrame ID so that you can listen to
|
|
@@ -315,17 +283,14 @@ export default {
|
|
|
315
283
|
*/
|
|
316
284
|
on(name, callback) {
|
|
317
285
|
log(`listening to event "${name}"`);
|
|
318
|
-
if (!eventHandlers[
|
|
319
|
-
eventHandlers[
|
|
286
|
+
if (!eventHandlers[iframeElement.iframeId]) {
|
|
287
|
+
eventHandlers[iframeElement.iframeId] = {};
|
|
320
288
|
}
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
eventHandlers[self.iframeId][name] = [];
|
|
289
|
+
if (!eventHandlers[iframeElement.iframeId][name]) {
|
|
290
|
+
eventHandlers[iframeElement.iframeId][name] = [];
|
|
324
291
|
}
|
|
325
|
-
|
|
326
|
-
eventHandlers[self.iframeId][name].push(callback);
|
|
292
|
+
eventHandlers[iframeElement.iframeId][name].push(callback);
|
|
327
293
|
},
|
|
328
|
-
|
|
329
294
|
/**
|
|
330
295
|
* Unregister all handlers for an event. If name is null
|
|
331
296
|
* then all handlers will be removed
|
|
@@ -334,24 +299,27 @@ export default {
|
|
|
334
299
|
*/
|
|
335
300
|
off(name) {
|
|
336
301
|
log(`stop listening to event "${name}"`);
|
|
337
|
-
if (
|
|
338
|
-
if (eventHandlers[
|
|
302
|
+
if (iframeElement.iframeId) {
|
|
303
|
+
if (eventHandlers[iframeElement.iframeId]) {
|
|
339
304
|
if (!name) {
|
|
340
|
-
eventHandlers[
|
|
341
|
-
}
|
|
342
|
-
|
|
305
|
+
eventHandlers[iframeElement.iframeId] = {};
|
|
306
|
+
}
|
|
307
|
+
else {
|
|
308
|
+
delete eventHandlers[iframeElement.iframeId][name];
|
|
343
309
|
}
|
|
344
310
|
}
|
|
345
|
-
}
|
|
311
|
+
}
|
|
312
|
+
else if (!name) {
|
|
346
313
|
eventHandlers = {};
|
|
347
|
-
}
|
|
348
|
-
|
|
314
|
+
}
|
|
315
|
+
else {
|
|
316
|
+
const removeEventHandler = (obj) => {
|
|
349
317
|
const object = obj;
|
|
350
318
|
delete object[name];
|
|
351
|
-
}
|
|
319
|
+
};
|
|
320
|
+
_.each(eventHandlers, removeEventHandler);
|
|
352
321
|
}
|
|
353
322
|
},
|
|
354
|
-
|
|
355
323
|
/**
|
|
356
324
|
* Tears down the plugin by
|
|
357
325
|
* - removing all event handlers
|
|
@@ -361,10 +329,9 @@ export default {
|
|
|
361
329
|
$(window).off('message', handleWindowMessage);
|
|
362
330
|
parentIsListening = false;
|
|
363
331
|
iframeIsListening = false;
|
|
364
|
-
|
|
365
|
-
}
|
|
332
|
+
iframeElement = null;
|
|
333
|
+
},
|
|
366
334
|
};
|
|
367
|
-
|
|
368
335
|
/* eslint-disable no-param-reassign */
|
|
369
336
|
/**
|
|
370
337
|
* The method that we expose to jQuery. Is used to set options
|
|
@@ -383,23 +350,18 @@ export default {
|
|
|
383
350
|
const domainArray = urlArray[1].split('.');
|
|
384
351
|
const subdomain = domainArray.shift();
|
|
385
352
|
const domainWithoutSubdomain = domainArray.join('.');
|
|
386
|
-
|
|
387
353
|
// There are some browsers that don't support document.domain so we have to manually create it
|
|
388
354
|
document.domain = domainWithoutSubdomain;
|
|
389
|
-
|
|
390
|
-
|
|
355
|
+
iframeElement = this; // eslint-disable-line consistent-this
|
|
391
356
|
if (!wasInitalized) {
|
|
392
357
|
// Determine if this is the parent, or the iframe
|
|
393
358
|
// Because our site runs inside of an iframe in salesforce, the parent
|
|
394
359
|
// will actually think it's an iframe too. So here, we detect that we're on
|
|
395
360
|
// the salesforce subdomain and we know that we should be the parent
|
|
396
|
-
whatIAm =
|
|
397
|
-
? 'parent'
|
|
398
|
-
: 'iframe';
|
|
361
|
+
whatIAm = window.parent === window || subdomain === 'salesforce' ? 'parent' : 'iframe';
|
|
399
362
|
log('I am the:', whatIAm);
|
|
400
363
|
wasInitalized = true;
|
|
401
364
|
}
|
|
402
|
-
|
|
403
365
|
// The iframeId is pulled from the frameElement (if this is inside an iFrame)
|
|
404
366
|
// or it's pulled from the element that this plugin was called from.
|
|
405
367
|
//
|
|
@@ -407,18 +369,17 @@ export default {
|
|
|
407
369
|
// $( '#myIframe' ).expensifyIframeify();
|
|
408
370
|
//
|
|
409
371
|
// 'myIframe' would be the frameId
|
|
410
|
-
|
|
411
|
-
|
|
372
|
+
iframeElement.iframeId = whatIAm === 'iframe' ? $(window.frameElement).attr('id') : iframeElement.attr('id');
|
|
412
373
|
// Figure out if we are doing an action or setting options
|
|
413
374
|
if (typeof actionOrOptions === 'string') {
|
|
414
375
|
if (typeof actions[actionOrOptions] !== 'undefined') {
|
|
415
376
|
actions[actionOrOptions](args, callback);
|
|
416
377
|
}
|
|
417
|
-
}
|
|
378
|
+
}
|
|
379
|
+
else {
|
|
418
380
|
// Extend our default settings
|
|
419
381
|
settings = $.extend(settings, actionOrOptions);
|
|
420
382
|
}
|
|
421
|
-
|
|
422
383
|
// If this is the parent page, then we can start listening to messages
|
|
423
384
|
// from the iFrame
|
|
424
385
|
if (whatIAm === 'parent' && !parentIsListening) {
|
|
@@ -426,7 +387,6 @@ export default {
|
|
|
426
387
|
parentIsListening = true;
|
|
427
388
|
log('parent is listening for messages');
|
|
428
389
|
}
|
|
429
|
-
|
|
430
390
|
// If this is the iFrame, then we can start listening to messages
|
|
431
391
|
// from the iFrame
|
|
432
392
|
if (whatIAm === 'iframe' && !iframeIsListening) {
|
|
@@ -434,9 +394,8 @@ export default {
|
|
|
434
394
|
iframeIsListening = true;
|
|
435
395
|
log('iframe is listening for messages');
|
|
436
396
|
}
|
|
437
|
-
|
|
438
397
|
// make this plugin chainable
|
|
439
398
|
return this;
|
|
440
399
|
};
|
|
441
|
-
}
|
|
400
|
+
},
|
|
442
401
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
function UNSAFE_componentWillMount(): void;
|
|
3
|
+
/**
|
|
4
|
+
* Registers an event listener for a PubSub event and keeps track of the event ID
|
|
5
|
+
* @param {String} name
|
|
6
|
+
* @param {Function} callback
|
|
7
|
+
*/
|
|
8
|
+
function subscribe(name: string, callback: Function): void;
|
|
9
|
+
/**
|
|
10
|
+
* Publish an event
|
|
11
|
+
* @param {String} name
|
|
12
|
+
* @param {Object} [data]
|
|
13
|
+
*/
|
|
14
|
+
function publish(name: string, data?: Object | undefined): void;
|
|
15
|
+
/**
|
|
16
|
+
* When the component is unmounted, we want to subscribe from all of our event IDs
|
|
17
|
+
*/
|
|
18
|
+
function componentWillUnmount(): void;
|
|
19
|
+
}
|
|
20
|
+
export default _default;
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const underscore_1 = __importDefault(require("underscore"));
|
|
7
|
+
const PubSub_1 = __importDefault(require("../PubSub"));
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const PubSub = ((0, utils_1.isWindowAvailable)() && window.PubSub) || PubSub_1.default;
|
|
6
10
|
/**
|
|
7
11
|
* This mixin sets up automatic PubSub bindings which will be removed when
|
|
8
12
|
* the component is unmounted.
|
|
@@ -17,11 +21,10 @@ const PubSub = window.PubSub || PubSubModule;
|
|
|
17
21
|
* }
|
|
18
22
|
* });
|
|
19
23
|
*/
|
|
20
|
-
|
|
24
|
+
exports.default = {
|
|
21
25
|
UNSAFE_componentWillMount() {
|
|
22
26
|
this.eventIds = [];
|
|
23
27
|
},
|
|
24
|
-
|
|
25
28
|
/**
|
|
26
29
|
* Registers an event listener for a PubSub event and keeps track of the event ID
|
|
27
30
|
* @param {String} name
|
|
@@ -30,7 +33,6 @@ export default {
|
|
|
30
33
|
subscribe(name, callback) {
|
|
31
34
|
this.eventIds.push(PubSub.subscribe(name, callback, this));
|
|
32
35
|
},
|
|
33
|
-
|
|
34
36
|
/**
|
|
35
37
|
* Publish an event
|
|
36
38
|
* @param {String} name
|
|
@@ -39,11 +41,10 @@ export default {
|
|
|
39
41
|
publish(name, data) {
|
|
40
42
|
PubSub.publish(name, data || {});
|
|
41
43
|
},
|
|
42
|
-
|
|
43
44
|
/**
|
|
44
45
|
* When the component is unmounted, we want to subscribe from all of our event IDs
|
|
45
46
|
*/
|
|
46
47
|
componentWillUnmount() {
|
|
47
|
-
|
|
48
|
-
}
|
|
48
|
+
underscore_1.default.each(this.eventIds, underscore_1.default.bind(PubSub.unsubscribe, PubSub));
|
|
49
|
+
},
|
|
49
50
|
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/* global React */
|
|
2
|
-
|
|
3
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
4
|
/**
|
|
4
5
|
* This mixin adds the ability to specify an `extraClasses` property
|
|
5
6
|
* on a component that is added to any default classes that the component uses.
|
|
@@ -22,22 +23,17 @@
|
|
|
22
23
|
* return <Div extraClasses={['large', 'primary']} />;
|
|
23
24
|
* }
|
|
24
25
|
*/
|
|
25
|
-
|
|
26
|
+
const utils_1 = require("../utils");
|
|
27
|
+
exports.default = {
|
|
26
28
|
propTypes: {
|
|
27
|
-
extraClasses: window.PropTypes.oneOfType([
|
|
28
|
-
window.PropTypes.string,
|
|
29
|
-
window.PropTypes.array,
|
|
30
|
-
window.PropTypes.object,
|
|
31
|
-
]),
|
|
29
|
+
extraClasses: (0, utils_1.isWindowAvailable)() && window.PropTypes.oneOfType([window.PropTypes.string, window.PropTypes.array, window.PropTypes.object]),
|
|
32
30
|
},
|
|
33
|
-
|
|
34
31
|
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
35
|
-
this.setState({classes: React.classNames(this.defaultClasses || [], nextProps.extraClasses)});
|
|
32
|
+
this.setState({ classes: React.classNames(this.defaultClasses || [], nextProps.extraClasses) });
|
|
36
33
|
},
|
|
37
|
-
|
|
38
34
|
getInitialState() {
|
|
39
35
|
return {
|
|
40
|
-
classes: React.classNames(this.defaultClasses || [], this.props.extraClasses)
|
|
36
|
+
classes: React.classNames(this.defaultClasses || [], this.props.extraClasses),
|
|
41
37
|
};
|
|
42
|
-
}
|
|
38
|
+
},
|
|
43
39
|
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
declare namespace _default {
|
|
2
|
+
/**
|
|
3
|
+
* Clear the error state of this element
|
|
4
|
+
*/
|
|
5
|
+
function clearError(): void;
|
|
6
|
+
function handleErrorStateUpdate(state: object): object;
|
|
7
|
+
/**
|
|
8
|
+
* Display the error state of this element
|
|
9
|
+
*/
|
|
10
|
+
function showError(): void;
|
|
11
|
+
}
|
|
12
|
+
export default _default;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
|
+
};
|
|
28
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const classnames_1 = __importDefault(require("classnames"));
|
|
30
|
+
const CONST = __importStar(require("../CONST"));
|
|
31
|
+
/**
|
|
32
|
+
* This mixin will add two methods to a component which are uses to add
|
|
33
|
+
* and remove the error class from the component. Used great with refs and
|
|
34
|
+
* form elements. You can see how it is used in component/list/item/formelement.jsx
|
|
35
|
+
*/
|
|
36
|
+
exports.default = {
|
|
37
|
+
/**
|
|
38
|
+
* Clear the error state of this element
|
|
39
|
+
*/
|
|
40
|
+
clearError() {
|
|
41
|
+
this.setState(this.getInitialState());
|
|
42
|
+
},
|
|
43
|
+
/**
|
|
44
|
+
* Update the error state of this element
|
|
45
|
+
*
|
|
46
|
+
* @param {object} state - The current state of the component.
|
|
47
|
+
* @returns {object} The updated state with modified classes.
|
|
48
|
+
*/
|
|
49
|
+
handleErrorStateUpdate: (state) => ({
|
|
50
|
+
classes: (0, classnames_1.default)(state.classes, CONST.UI.ERROR),
|
|
51
|
+
}),
|
|
52
|
+
/**
|
|
53
|
+
* Display the error state of this element
|
|
54
|
+
*/
|
|
55
|
+
showError() {
|
|
56
|
+
this.setState(this.handleErrorStateUpdate);
|
|
57
|
+
},
|
|
58
|
+
};
|