Newer
Older
this._promise = new Promise(function (resolve, reject) {
that._callbacks = {
reject: reject,
resolve: resolve
that._proceed()
})
return this._promise
}
PromisePool.prototype._fireEvent = function (type, data) {
this.dispatchEvent(new PromisePoolEvent(this, type, data))
}
PromisePool.prototype._settle = function (error) {
if (error) {
this._callbacks.reject(error)
this._callbacks.resolve()
this._promise = null
this._callbacks = null
}
PromisePool.prototype._onPooledPromiseFulfilled = function (promise, result) {
this._size--
if (this.active()) {
this._fireEvent('fulfilled', {
promise: promise,
result: result
})
this._proceed()
}
}
PromisePool.prototype._onPooledPromiseRejected = function (promise, error) {
this._size--
if (this.active()) {
this._fireEvent('rejected', {
promise: promise,
error: error
})
this._settle(error || new Error('Unknown error'))
PromisePool.prototype._trackPromise = function (promise) {
var that = this
promise
.then(function (result) {
that._onPooledPromiseFulfilled(promise, result)
}, function (error) {
that._onPooledPromiseRejected(promise, error)
})['catch'](function (err) {
that._settle(new Error('Promise processing failed: ' + err))
})
}
PromisePool.prototype._proceed = function () {
if (!this._done) {
var result = { done: false }
while (this._size < this._concurrency &&
!(result = this._iterator.next()).done) {
this._size++
this._trackPromise(result.value)
this._done = (result === null || !!result.done)
if (this._done && this._size === 0) {
this._settle()
PromisePool.PromisePoolEvent = PromisePoolEvent
// Legacy API
PromisePool.PromisePool = PromisePool
return PromisePool
})
/***/ }),
/* 1592 */
/***/ (function(module, exports, __webpack_require__) {
const get = __webpack_require__(1564)
const flatten = __webpack_require__(1520)
const Contact = __webpack_require__(1593)
const Document = __webpack_require__(1393)
204092
204093
204094
204095
204096
204097
204098
204099
204100
204101
204102
204103
204104
204105
204106
204107
204108
204109
204110
204111
204112
204113
204114
204115
204116
class AdministrativeProcedure extends Document {
/**
* Returns personal data for the contact
*
* @param {Contact} contact - A contact
* @param {Array} fields - The list of fields to retrieve
* @return {Object} - the personal data
**/
static getPersonalData(contact, fields) {
const mapping = {
firstname: {
path: 'name.givenName'
},
lastname: {
path: 'name.familyName'
},
address: {
getter: Contact.getPrimaryAddress
},
email: {
getter: Contact.getPrimaryEmail
},
phone: {
getter: Contact.getPrimaryPhone
}
let personalData = {}
fields.forEach(field => {
const contactField = get(mapping, field, field)
let value
if (contactField.getter) {
value = contactField.getter(contact)
} else {
const path = get(contactField, 'path', field)
value = get(contact, path)
}
if (value !== undefined) {
personalData[field] = value
}
})
204134
204135
204136
204137
204138
204139
204140
204141
204142
204143
204144
204145
204146
204147
204148
204149
204150
204151
204152
204153
204154
204155
204156
204157
204158
204159
204160
204161
204162
204163
204164
204165
204166
204167
return personalData
}
/**
* Method to generate a query based on a few rules given by the template
* @param {Object} docRules
* @param {Object} docRules.rules
* @param {int} docRules.count
*/
static async getFilesByRules(docRules) {
const { rules, count } = docRules
const cozyRules = {
trashed: false,
type: 'file',
...rules
}
// Create an index in order to query and sort
await this.cozyClient
.collection('io.cozy.files')
.createIndex(['metadata.datetime', 'metadata.qualification'])
// Use the index
const files = await this.cozyClient
.collection('io.cozy.files')
.find(cozyRules, {
indexedFields: ['metadata.datetime', 'metadata.qualification'],
sort: [
{
'metadata.datetime': 'desc'
},
{
'metadata.qualification': 'desc'
}
],
limit: count ? count : 1
})
204172
204173
204174
204175
204176
204177
204178
204179
204180
204181
204182
204183
204184
204185
204186
204187
204188
204189
204190
204191
204192
204193
204194
204195
204196
204197
204198
204199
204200
204201
/**
* Returns a io.cozy.procedures.administratives object
*
* @param {object} data - The data we need for this type of procedure
* @param {ProcedureTemplate} template - The procedure's template
* @return {AdministrativeProcedure} the administrative procedure
*/
static create(data, template) {
const { documentsData, personalData, procedureData } = data
const files = Object.keys(documentsData).map(identifier => {
return documentsData[identifier].files.map(file => {
// TODO Remove this check. it has to be done before
if (file)
return {
_id: file.id,
_type: 'io.cozy.files',
templateDocumentId: identifier
}
})
})
return {
personalData,
procedureData,
submissionDate: new Date(),
templateId: template.type,
templateVersion: template.version,
relationships: {
files: {
data: flatten(files)
}
/**
* Returns json that represents the administative procedure
*
* @param {AdministrativeProcedure}
* @return {string} - the json that represents this procedure
*
*/
static createJson(administrativeProcedure) {
return JSON.stringify(administrativeProcedure)
}
}
AdministrativeProcedure.doctype = 'io.cozy.procedures.administratives'
module.exports = AdministrativeProcedure
/***/ }),
/* 1593 */
/***/ (function(module, exports, __webpack_require__) {
const PropTypes = __webpack_require__(1594)
const get = __webpack_require__(1564)
const log = __webpack_require__(1601)
const Document = __webpack_require__(1393)
const getPrimaryOrFirst = property => obj => {
if (!obj[property] || obj[property].length === 0) return ''
return obj[property].find(property => property.primary) || obj[property][0]
}
const logDeprecated = methodName =>
log(
'warn',
`${methodName} from cozy-doctypes contact is deprecated, use cozy-client/models/contacts/${methodName} instead`
)
/**
* Class representing the contact model.
* @extends Document
*/
class Contact extends Document {
/**
* Returns true if candidate is a contact
*
* @param {Object} candidate
* @return {boolean} - whether the candidate is a contact
*/
static isContact(candidate) {
return candidate._type === Contact.doctype
}
/**
* Returns the initials of the contact.
*
* @param {Contact|string} contact - A contact or a string
* @return {string} - the contact's initials
*/
static getInitials(contact) {
logDeprecated('getInitials')
if (typeof contact === 'string') {
log(
'warn',
'Passing a string to Contact.getInitials will be deprecated soon.'
)
return contact[0].toUpperCase()
if (contact.name) {
return ['givenName', 'familyName']
.map(part => get(contact, ['name', part, 0], ''))
.join('')
.toUpperCase()
}
const email = Contact.getPrimaryEmail(contact)
if (email) {
return email[0].toUpperCase()
log('warn', 'Contact has no name and no email.')
return ''
}
/**
* Returns the contact's main email
*
* @param {Contact} contact - A contact
* @return {string} - The contact's main email
*/
// TODO: sadly we have different versions of contacts' doctype to handle...
// A migration tool on the stack side is needed here
static getPrimaryEmail(contact) {
logDeprecated('getPrimaryEmail')
return Array.isArray(contact.email)
? getPrimaryOrFirst('email')(contact).address
: contact.email
}
/**
* Returns the contact's main cozy
*
* @param {Contact} contact - A contact
* @return {string} - The contact's main cozy
*/
static getPrimaryCozy(contact) {
logDeprecated('getPrimaryCozy')
return Array.isArray(contact.cozy)
? getPrimaryOrFirst('cozy')(contact).url
: contact.url
}
/**
* Returns the contact's main phone number
*
* @param {Contact} contact - A contact
* @return {string} - The contact's main phone number
*/
static getPrimaryPhone(contact) {
logDeprecated('getPrimaryPhone')
return getPrimaryOrFirst('phone')(contact).number
}
/**
* Returns the contact's main address
* @param {Contact} contact - A contact
* @return {string} - The contact's main address
static getPrimaryAddress(contact) {
logDeprecated('getPrimaryAddress')
return getPrimaryOrFirst('address')(contact).formattedAddress
}
/**
* Returns the contact's fullname
* @param {Contact} contact - A contact
* @return {string} - The contact's fullname
204347
204348
204349
204350
204351
204352
204353
204354
204355
204356
204357
204358
204359
204360
204361
204362
204363
static getFullname(contact) {
logDeprecated('getFullname')
if (contact.fullname) {
return contact.fullname
} else if (contact.name) {
return [
'namePrefix',
'givenName',
'additionalName',
'familyName',
'nameSuffix'
]
.map(part => contact.name[part])
.filter(part => part !== undefined)
.join(' ')
.trim()
}
return undefined
}
204368
204369
204370
204371
204372
204373
204374
204375
204376
204377
204378
204379
204380
204381
204382
204383
204384
204385
204386
204387
204388
204389
204390
204391
204392
204393
204394
204395
204396
204397
204398
204399
204400
204401
204402
204403
204404
204405
204406
204407
204408
204409
204410
204411
204412
204413
204414
204415
204416
204417
204418
204419
204420
204421
204422
204423
204424
204425
204426
204427
204428
204429
204430
204431
204432
204433
204434
204435
204436
204437
204438
204439
204440
204441
204442
204443
204444
204445
204446
204447
204448
204449
204450
204451
204452
/**
* Returns a display name for the contact
*
* @param {Contact} contact - A contact
* @return {string} - the contact's display name
**/
static getDisplayName(contact) {
logDeprecated('getDisplayName')
return Contact.getFullname(contact) || Contact.getPrimaryEmail(contact)
}
}
const ContactShape = PropTypes.shape({
_id: PropTypes.string.isRequired,
_type: PropTypes.string.isRequired,
fullname: PropTypes.string,
name: PropTypes.shape({
givenName: PropTypes.string,
familyName: PropTypes.string,
additionalName: PropTypes.string,
namePrefix: PropTypes.string,
nameSuffix: PropTypes.string
}),
birthday: PropTypes.string,
note: PropTypes.string,
email: PropTypes.arrayOf(
PropTypes.shape({
address: PropTypes.string.isRequired,
label: PropTypes.string,
type: PropTypes.string,
primary: PropTypes.bool
})
),
address: PropTypes.arrayOf(
PropTypes.shape({
street: PropTypes.string,
pobox: PropTypes.string,
city: PropTypes.string,
region: PropTypes.string,
postcode: PropTypes.string,
country: PropTypes.string,
type: PropTypes.string,
primary: PropTypes.bool,
label: PropTypes.string,
formattedAddress: PropTypes.string
})
),
phone: PropTypes.arrayOf(
PropTypes.shape({
number: PropTypes.string.isRequired,
type: PropTypes.string,
label: PropTypes.string,
primary: PropTypes.bool
})
),
cozy: PropTypes.arrayOf(
PropTypes.shape({
url: PropTypes.string.isRequired,
label: PropTypes.string,
primary: PropTypes.bool
})
),
company: PropTypes.string,
jobTitle: PropTypes.string,
trashed: PropTypes.bool,
me: PropTypes.bool,
relationships: PropTypes.shape({
accounts: PropTypes.shape({
data: PropTypes.arrayOf(
PropTypes.shape({
_id: PropTypes.string.isRequired,
_type: PropTypes.string.isRequired
})
)
}),
groups: PropTypes.shape({
data: PropTypes.arrayOf(
PropTypes.shape({
_id: PropTypes.string.isRequired,
_type: PropTypes.string.isRequired
})
)
})
})
})
Contact.doctype = 'io.cozy.contacts'
Contact.propType = ContactShape
/***/ }),
/* 1594 */
/***/ (function(module, exports, __webpack_require__) {
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
if (true) {
var ReactIs = __webpack_require__(1595);
// By explicitly using `prop-types` you are opting into new development behavior.
// http://fb.me/prop-types-in-prod
var throwOnDirectAccess = true;
module.exports = __webpack_require__(1597)(ReactIs.isElement, throwOnDirectAccess);
} else {}
/***/ }),
/* 1595 */
/***/ (function(module, exports, __webpack_require__) {
if (false) {} else {
module.exports = __webpack_require__(1596);
}
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/** @license React v16.8.4
* react-is.development.js
*
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
if (true) {
(function() {
'use strict';
204515
204516
204517
204518
204519
204520
204521
204522
204523
204524
204525
204526
204527
204528
204529
204530
204531
204532
204533
204534
204535
204536
204537
204538
Object.defineProperty(exports, '__esModule', { value: true });
// The Symbol used to tag the ReactElement-like types. If there is no native Symbol
// nor polyfill, then a plain number is used for performance.
var hasSymbol = typeof Symbol === 'function' && Symbol.for;
var REACT_ELEMENT_TYPE = hasSymbol ? Symbol.for('react.element') : 0xeac7;
var REACT_PORTAL_TYPE = hasSymbol ? Symbol.for('react.portal') : 0xeaca;
var REACT_FRAGMENT_TYPE = hasSymbol ? Symbol.for('react.fragment') : 0xeacb;
var REACT_STRICT_MODE_TYPE = hasSymbol ? Symbol.for('react.strict_mode') : 0xeacc;
var REACT_PROFILER_TYPE = hasSymbol ? Symbol.for('react.profiler') : 0xead2;
var REACT_PROVIDER_TYPE = hasSymbol ? Symbol.for('react.provider') : 0xeacd;
var REACT_CONTEXT_TYPE = hasSymbol ? Symbol.for('react.context') : 0xeace;
var REACT_ASYNC_MODE_TYPE = hasSymbol ? Symbol.for('react.async_mode') : 0xeacf;
var REACT_CONCURRENT_MODE_TYPE = hasSymbol ? Symbol.for('react.concurrent_mode') : 0xeacf;
var REACT_FORWARD_REF_TYPE = hasSymbol ? Symbol.for('react.forward_ref') : 0xead0;
var REACT_SUSPENSE_TYPE = hasSymbol ? Symbol.for('react.suspense') : 0xead1;
var REACT_MEMO_TYPE = hasSymbol ? Symbol.for('react.memo') : 0xead3;
var REACT_LAZY_TYPE = hasSymbol ? Symbol.for('react.lazy') : 0xead4;
function isValidElementType(type) {
return typeof type === 'string' || typeof type === 'function' ||
// Note: its typeof might be other than 'symbol' or 'number' if it's a polyfill.
type === REACT_FRAGMENT_TYPE || type === REACT_CONCURRENT_MODE_TYPE || type === REACT_PROFILER_TYPE || type === REACT_STRICT_MODE_TYPE || type === REACT_SUSPENSE_TYPE || typeof type === 'object' && type !== null && (type.$$typeof === REACT_LAZY_TYPE || type.$$typeof === REACT_MEMO_TYPE || type.$$typeof === REACT_PROVIDER_TYPE || type.$$typeof === REACT_CONTEXT_TYPE || type.$$typeof === REACT_FORWARD_REF_TYPE);
204541
204542
204543
204544
204545
204546
204547
204548
204549
204550
204551
204552
204553
204554
204555
204556
204557
204558
204559
204560
204561
204562
204563
204564
204565
204566
204567
204568
204569
204570
204571
204572
204573
204574
204575
/**
* Forked from fbjs/warning:
* https://github.com/facebook/fbjs/blob/e66ba20ad5be433eb54423f2b097d829324d9de6/packages/fbjs/src/__forks__/warning.js
*
* Only change is we use console.warn instead of console.error,
* and do nothing when 'console' is not supported.
* This really simplifies the code.
* ---
* Similar to invariant but only logs a warning if the condition is not met.
* This can be used to log issues in development environments in critical
* paths. Removing the logging code for production environments will keep the
* same logic and follow the same code paths.
*/
var lowPriorityWarning = function () {};
{
var printWarning = function (format) {
for (var _len = arguments.length, args = Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
var argIndex = 0;
var message = 'Warning: ' + format.replace(/%s/g, function () {
return args[argIndex++];
});
if (typeof console !== 'undefined') {
console.warn(message);
}
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
lowPriorityWarning = function (condition, format) {
if (format === undefined) {
throw new Error('`lowPriorityWarning(condition, format, ...args)` requires a warning ' + 'message argument');
if (!condition) {
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) {
args[_key2 - 2] = arguments[_key2];
}
printWarning.apply(undefined, [format].concat(args));
}
};
var lowPriorityWarning$1 = lowPriorityWarning;
function typeOf(object) {
if (typeof object === 'object' && object !== null) {
var $$typeof = object.$$typeof;
switch ($$typeof) {
case REACT_ELEMENT_TYPE:
var type = object.type;
switch (type) {
case REACT_ASYNC_MODE_TYPE:
case REACT_CONCURRENT_MODE_TYPE:
case REACT_FRAGMENT_TYPE:
case REACT_PROFILER_TYPE:
case REACT_STRICT_MODE_TYPE:
case REACT_SUSPENSE_TYPE:
return type;
default:
var $$typeofType = type && type.$$typeof;
switch ($$typeofType) {
case REACT_CONTEXT_TYPE:
case REACT_FORWARD_REF_TYPE:
case REACT_PROVIDER_TYPE:
return $$typeofType;
default:
return $$typeof;
}
}
case REACT_LAZY_TYPE:
case REACT_MEMO_TYPE:
case REACT_PORTAL_TYPE:
return $$typeof;
204628
204629
204630
204631
204632
204633
204634
204635
204636
204637
204638
204639
204640
204641
204642
204643
204644
204645
204646
204647
204648
204649
204650
204651
204652
204653
204654
204655
204656
204657
204658
204659
204660
204661
204662
204663
204664
204665
204666
204667
204668
204669
204670
204671
204672
204673
204674
204675
204676
204677
204678
204679
204680
204681
204682
204683
204684
204685
204686
204687
204688
204689
204690
204691
204692
204693
204694
204695
204696
204697
204698
204699
204700
204701
204702
204703
204704
204705
204706
204707
204708
204709
204710
204711
204712
204713
204714
204715
204716
204717
204718
204719
204720
204721
204722
204723
return undefined;
}
// AsyncMode is deprecated along with isAsyncMode
var AsyncMode = REACT_ASYNC_MODE_TYPE;
var ConcurrentMode = REACT_CONCURRENT_MODE_TYPE;
var ContextConsumer = REACT_CONTEXT_TYPE;
var ContextProvider = REACT_PROVIDER_TYPE;
var Element = REACT_ELEMENT_TYPE;
var ForwardRef = REACT_FORWARD_REF_TYPE;
var Fragment = REACT_FRAGMENT_TYPE;
var Lazy = REACT_LAZY_TYPE;
var Memo = REACT_MEMO_TYPE;
var Portal = REACT_PORTAL_TYPE;
var Profiler = REACT_PROFILER_TYPE;
var StrictMode = REACT_STRICT_MODE_TYPE;
var Suspense = REACT_SUSPENSE_TYPE;
var hasWarnedAboutDeprecatedIsAsyncMode = false;
// AsyncMode should be deprecated
function isAsyncMode(object) {
{
if (!hasWarnedAboutDeprecatedIsAsyncMode) {
hasWarnedAboutDeprecatedIsAsyncMode = true;
lowPriorityWarning$1(false, 'The ReactIs.isAsyncMode() alias has been deprecated, ' + 'and will be removed in React 17+. Update your code to use ' + 'ReactIs.isConcurrentMode() instead. It has the exact same API.');
}
}
return isConcurrentMode(object) || typeOf(object) === REACT_ASYNC_MODE_TYPE;
}
function isConcurrentMode(object) {
return typeOf(object) === REACT_CONCURRENT_MODE_TYPE;
}
function isContextConsumer(object) {
return typeOf(object) === REACT_CONTEXT_TYPE;
}
function isContextProvider(object) {
return typeOf(object) === REACT_PROVIDER_TYPE;
}
function isElement(object) {
return typeof object === 'object' && object !== null && object.$$typeof === REACT_ELEMENT_TYPE;
}
function isForwardRef(object) {
return typeOf(object) === REACT_FORWARD_REF_TYPE;
}
function isFragment(object) {
return typeOf(object) === REACT_FRAGMENT_TYPE;
}
function isLazy(object) {
return typeOf(object) === REACT_LAZY_TYPE;
}
function isMemo(object) {
return typeOf(object) === REACT_MEMO_TYPE;
}
function isPortal(object) {
return typeOf(object) === REACT_PORTAL_TYPE;
}
function isProfiler(object) {
return typeOf(object) === REACT_PROFILER_TYPE;
}
function isStrictMode(object) {
return typeOf(object) === REACT_STRICT_MODE_TYPE;
}
function isSuspense(object) {
return typeOf(object) === REACT_SUSPENSE_TYPE;
}
exports.typeOf = typeOf;
exports.AsyncMode = AsyncMode;
exports.ConcurrentMode = ConcurrentMode;
exports.ContextConsumer = ContextConsumer;
exports.ContextProvider = ContextProvider;
exports.Element = Element;
exports.ForwardRef = ForwardRef;
exports.Fragment = Fragment;
exports.Lazy = Lazy;
exports.Memo = Memo;
exports.Portal = Portal;
exports.Profiler = Profiler;
exports.StrictMode = StrictMode;
exports.Suspense = Suspense;
exports.isValidElementType = isValidElementType;
exports.isAsyncMode = isAsyncMode;
exports.isConcurrentMode = isConcurrentMode;
exports.isContextConsumer = isContextConsumer;
exports.isContextProvider = isContextProvider;
exports.isElement = isElement;
exports.isForwardRef = isForwardRef;
exports.isFragment = isFragment;
exports.isLazy = isLazy;
exports.isMemo = isMemo;
exports.isPortal = isPortal;
exports.isProfiler = isProfiler;
exports.isStrictMode = isStrictMode;
exports.isSuspense = isSuspense;
})();
/***/ (function(module, exports, __webpack_require__) {
"use strict";
/**
* Copyright (c) 2013-present, Facebook, Inc.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
var ReactIs = __webpack_require__(1595);
var assign = __webpack_require__(1598);
var ReactPropTypesSecret = __webpack_require__(1599);
var checkPropTypes = __webpack_require__(1600);
var has = Function.call.bind(Object.prototype.hasOwnProperty);
var printWarning = function() {};
if (true) {
printWarning = function(text) {
var message = 'Warning: ' + text;
if (typeof console !== 'undefined') {
console.error(message);
try {
// --- Welcome to debugging React ---
// This error was thrown as a convenience so that you can use this stack
// to find the callsite that caused this warning to fire.
throw new Error(message);
} catch (x) {}
};
}
function emptyFunctionThatReturnsNull() {
return null;
}
204769
204770
204771
204772
204773
204774
204775
204776
204777
204778
204779
204780
204781
204782
204783
204784
204785
204786
204787
204788
204789
204790
204791
module.exports = function(isValidElement, throwOnDirectAccess) {
/* global Symbol */
var ITERATOR_SYMBOL = typeof Symbol === 'function' && Symbol.iterator;
var FAUX_ITERATOR_SYMBOL = '@@iterator'; // Before Symbol spec.
/**
* Returns the iterator method function contained on the iterable object.
*
* Be sure to invoke the function with the iterable as context:
*
* var iteratorFn = getIteratorFn(myIterable);
* if (iteratorFn) {
* var iterator = iteratorFn.call(myIterable);
* ...
* }
*
* @param {?object} maybeIterable
* @return {?function}
*/
function getIteratorFn(maybeIterable) {
var iteratorFn = maybeIterable && (ITERATOR_SYMBOL && maybeIterable[ITERATOR_SYMBOL] || maybeIterable[FAUX_ITERATOR_SYMBOL]);
if (typeof iteratorFn === 'function') {
return iteratorFn;
204795
204796
204797
204798
204799
204800
204801
204802
204803
204804
204805
204806
204807
204808
204809
204810
204811
204812
204813
204814
204815
204816
204817
204818
204819
204820
204821
204822
204823
204824
204825
204826
204827
204828
204829
204830
204831
204832
204833
204834
204835
204836
204837
204838
204839
204840
/**
* Collection of methods that allow declaration and validation of props that are
* supplied to React components. Example usage:
*
* var Props = require('ReactPropTypes');
* var MyArticle = React.createClass({
* propTypes: {
* // An optional string prop named "description".
* description: Props.string,
*
* // A required enum prop named "category".
* category: Props.oneOf(['News','Photos']).isRequired,
*
* // A prop named "dialog" that requires an instance of Dialog.
* dialog: Props.instanceOf(Dialog).isRequired
* },
* render: function() { ... }
* });
*
* A more formal specification of how these methods are used:
*
* type := array|bool|func|object|number|string|oneOf([...])|instanceOf(...)
* decl := ReactPropTypes.{type}(.isRequired)?
*
* Each and every declaration produces a function with the same signature. This
* allows the creation of custom validation functions. For example:
*
* var MyLink = React.createClass({
* propTypes: {
* // An optional string or URI prop named "href".
* href: function(props, propName, componentName) {
* var propValue = props[propName];
* if (propValue != null && typeof propValue !== 'string' &&
* !(propValue instanceof URI)) {
* return new Error(
* 'Expected a string or an URI for ' + propName + ' in ' +
* componentName
* );
* }
* }
* },
* render: function() {...}
* });
*
* @internal
*/
204842
204843
204844
204845
204846
204847
204848
204849
204850
204851
204852
204853
204854
204855
204856
204857
204858
204859
204860
204861
204862
204863
204864
204865
204866
var ANONYMOUS = '<<anonymous>>';
// Important!
// Keep this list in sync with production version in `./factoryWithThrowingShims.js`.
var ReactPropTypes = {
array: createPrimitiveTypeChecker('array'),
bool: createPrimitiveTypeChecker('boolean'),
func: createPrimitiveTypeChecker('function'),
number: createPrimitiveTypeChecker('number'),
object: createPrimitiveTypeChecker('object'),
string: createPrimitiveTypeChecker('string'),
symbol: createPrimitiveTypeChecker('symbol'),
any: createAnyTypeChecker(),
arrayOf: createArrayOfTypeChecker,
element: createElementTypeChecker(),
elementType: createElementTypeTypeChecker(),
instanceOf: createInstanceTypeChecker,
node: createNodeChecker(),
objectOf: createObjectOfTypeChecker,
oneOf: createEnumTypeChecker,
oneOfType: createUnionTypeChecker,
shape: createShapeTypeChecker,
exact: createStrictShapeTypeChecker,
};
204868
204869
204870
204871
204872
204873
204874
204875
204876
204877
204878
204879
204880
204881
204882
204883
204884
/**
* inlined Object.is polyfill to avoid requiring consumers ship their own
* https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/is
*/
/*eslint-disable no-self-compare*/
function is(x, y) {
// SameValue algorithm
if (x === y) {
// Steps 1-5, 7-10
// Steps 6.b-6.e: +0 != -0
return x !== 0 || 1 / x === 1 / y;
} else {
// Step 6.a: NaN == NaN
return x !== x && y !== y;
}
}
/*eslint-enable no-self-compare*/
/**
* We use an Error-like object for backward compatibility as people may call
* PropTypes directly and inspect their output. However, we don't use real
* Errors anymore. We don't inspect their stack anyway, and creating them
* is prohibitively expensive if they are created too often, such as what
* happens in oneOfType() for any type before the one that matched.
*/
function PropTypeError(message) {
this.message = message;
this.stack = '';
}
// Make `instanceof Error` still work for returned errors.
PropTypeError.prototype = Error.prototype;
204900
204901
204902
204903
204904
204905
204906
204907
204908
204909
204910
204911
204912
204913
204914
204915
204916
204917
204918
204919
204920
204921
204922
204923
204924
204925
204926
204927
204928
204929
204930
204931
204932
204933
204934
204935
204936
204937
204938
204939
204940
204941
204942
204943
204944
204945
204946
204947
204948
204949
204950
function createChainableTypeChecker(validate) {
if (true) {
var manualPropTypeCallCache = {};
var manualPropTypeWarningCount = 0;
}
function checkType(isRequired, props, propName, componentName, location, propFullName, secret) {
componentName = componentName || ANONYMOUS;
propFullName = propFullName || propName;
if (secret !== ReactPropTypesSecret) {
if (throwOnDirectAccess) {
// New behavior only for users of `prop-types` package
var err = new Error(
'Calling PropTypes validators directly is not supported by the `prop-types` package. ' +
'Use `PropTypes.checkPropTypes()` to call them. ' +
'Read more at http://fb.me/use-check-prop-types'
);
err.name = 'Invariant Violation';
throw err;
} else if ( true && typeof console !== 'undefined') {
// Old behavior for people using React.PropTypes
var cacheKey = componentName + ':' + propName;
if (
!manualPropTypeCallCache[cacheKey] &&
// Avoid spamming the console because they are often not actionable except for lib authors
manualPropTypeWarningCount < 3
) {
printWarning(
'You are manually calling a React.PropTypes validation ' +
'function for the `' + propFullName + '` prop on `' + componentName + '`. This is deprecated ' +
'and will throw in the standalone `prop-types` package. ' +
'You may be seeing this warning due to a third-party PropTypes ' +
'library. See https://fb.me/react-warning-dont-call-proptypes ' + 'for details.'
);
manualPropTypeCallCache[cacheKey] = true;
manualPropTypeWarningCount++;
}
}
}
if (props[propName] == null) {
if (isRequired) {
if (props[propName] === null) {
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required ' + ('in `' + componentName + '`, but its value is `null`.'));
}
return new PropTypeError('The ' + location + ' `' + propFullName + '` is marked as required in ' + ('`' + componentName + '`, but its value is `undefined`.'));
}
return null;
} else {
return validate(props, propName, componentName, location, propFullName);
}
}
var chainedCheckType = checkType.bind(null, false);
chainedCheckType.isRequired = checkType.bind(null, true);
return chainedCheckType;
}
function createPrimitiveTypeChecker(expectedType) {
function validate(props, propName, componentName, location, propFullName, secret) {
var propValue = props[propName];
var propType = getPropType(propValue);
if (propType !== expectedType) {
// `propValue` being instance of, say, date/regexp, pass the 'object'
// check, but we can offer a more precise error message here rather than
// 'of type `object`'.
var preciseType = getPreciseType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + preciseType + '` supplied to `' + componentName + '`, expected ') + ('`' + expectedType + '`.'));
}
return null;
}
return createChainableTypeChecker(validate);
}
function createAnyTypeChecker() {
return createChainableTypeChecker(emptyFunctionThatReturnsNull);
}
204979
204980
204981
204982
204983
204984
204985
204986
204987
204988
204989
204990
204991
204992
204993
204994
204995
function createArrayOfTypeChecker(typeChecker) {
function validate(props, propName, componentName, location, propFullName) {
if (typeof typeChecker !== 'function') {
return new PropTypeError('Property `' + propFullName + '` of component `' + componentName + '` has invalid PropType notation inside arrayOf.');
}
var propValue = props[propName];
if (!Array.isArray(propValue)) {
var propType = getPropType(propValue);
return new PropTypeError('Invalid ' + location + ' `' + propFullName + '` of type ' + ('`' + propType + '` supplied to `' + componentName + '`, expected an array.'));
}
for (var i = 0; i < propValue.length; i++) {
var error = typeChecker(propValue, i, componentName, location, propFullName + '[' + i + ']', ReactPropTypesSecret);
if (error instanceof Error) {
return error;
}
}
return null;
return createChainableTypeChecker(validate);
function createElementTypeChecker() {