@elliemae/ds-props-helpers 2.3.0-alpha.6 → 2.3.0-next.0
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/cjs/defaultProps/index.js +9 -0
- package/cjs/defaultProps/useMemoMergePropsWithDefault.js +48 -0
- package/cjs/getProps/index.js +20 -0
- package/cjs/globalProps/constants.js +15 -0
- package/cjs/globalProps/globalAttributesPropTypes.js +382 -0
- package/cjs/globalProps/index.js +11 -0
- package/cjs/globalProps/useGetGlobalAttributes.js +36 -0
- package/cjs/index.js +28 -0
- package/cjs/propTypes/PropTypes.js +130 -0
- package/cjs/propTypes/customPropTypes.js +21 -0
- package/cjs/propTypes/describe.js +64 -0
- package/cjs/propTypes/describeConversions.js +104 -0
- package/cjs/propTypes/describeGuards.js +21 -0
- package/cjs/propTypes/index.js +11 -0
- package/cjs/propTypes/toTypescript.js +160 -0
- package/cjs/propTypes/types.js +2 -0
- package/cjs/validation/errorTemplates.js +16 -0
- package/cjs/validation/index.js +15 -0
- package/cjs/validation/typescriptGuards.js +36 -0
- package/cjs/validation/typescriptParsers.js +45 -0
- package/cjs/validation/typescriptValidator.js +208 -0
- package/cjs/validation/validator.js +36 -0
- package/esm/defaultProps/index.js +1 -0
- package/esm/defaultProps/useMemoMergePropsWithDefault.js +39 -0
- package/esm/getProps/index.js +15 -0
- package/esm/globalProps/constants.js +11 -0
- package/{dist/esm → esm}/globalProps/globalAttributesPropTypes.js +67 -58
- package/esm/globalProps/index.js +2 -0
- package/esm/globalProps/useGetGlobalAttributes.js +32 -0
- package/esm/index.js +9 -0
- package/esm/propTypes/PropTypes.js +124 -0
- package/esm/propTypes/customPropTypes.js +17 -0
- package/esm/propTypes/describe.js +62 -0
- package/esm/propTypes/describeConversions.js +96 -0
- package/esm/propTypes/describeGuards.js +10 -0
- package/esm/propTypes/index.js +2 -0
- package/esm/propTypes/toTypescript.js +154 -0
- package/esm/propTypes/types.js +1 -0
- package/esm/validation/errorTemplates.js +11 -0
- package/esm/validation/index.js +3 -0
- package/esm/validation/typescriptGuards.js +23 -0
- package/esm/validation/typescriptParsers.js +41 -0
- package/esm/validation/typescriptValidator.js +203 -0
- package/esm/validation/validator.js +32 -0
- package/package.json +63 -65
- package/types/defaultProps/index.d.ts +1 -0
- package/types/defaultProps/useMemoMergePropsWithDefault.d.ts +1 -0
- package/types/getProps/index.d.ts +2 -0
- package/types/globalProps/constants.d.ts +3 -0
- package/types/globalProps/globalAttributesPropTypes.d.ts +363 -0
- package/types/globalProps/index.d.ts +2 -0
- package/types/globalProps/useGetGlobalAttributes.d.ts +5 -0
- package/types/index.d.ts +5 -0
- package/types/propTypes/PropTypes.d.ts +3 -0
- package/types/propTypes/customPropTypes.d.ts +2 -0
- package/types/propTypes/describe.d.ts +3 -0
- package/types/propTypes/describeConversions.d.ts +3 -0
- package/types/propTypes/describeGuards.d.ts +9 -0
- package/types/propTypes/index.d.ts +3 -0
- package/types/propTypes/toTypescript.d.ts +3 -0
- package/types/propTypes/types.d.ts +96 -0
- package/types/tests/globalProps/TestComponent.d.ts +1 -0
- package/types/tests/globalProps/globalAttributes.test.d.ts +1 -0
- package/types/tests/validation/any.validation.test.d.ts +1 -0
- package/types/tests/validation/array.validation.test.d.ts +1 -0
- package/types/tests/validation/boolean.validation.test.d.ts +1 -0
- package/types/tests/validation/function.validation.test.d.ts +1 -0
- package/types/tests/validation/number.validation.test.d.ts +1 -0
- package/types/tests/validation/object.validation.test.d.ts +1 -0
- package/types/tests/validation/schema.validation.test.d.ts +1 -0
- package/types/tests/validation/string.validation.test.d.ts +1 -0
- package/types/tests/validation/test.schema.d.ts +1 -0
- package/types/tests/validation/union.validation.test.d.ts +1 -0
- package/types/validation/errorTemplates.d.ts +2 -0
- package/types/validation/index.d.ts +3 -0
- package/types/validation/typescriptGuards.d.ts +12 -0
- package/types/validation/typescriptParsers.d.ts +1 -0
- package/types/validation/typescriptValidator.d.ts +15 -0
- package/types/validation/validator.d.ts +1 -0
- package/dist/cjs/defaultProps/index.js +0 -28
- package/dist/cjs/defaultProps/index.js.map +0 -7
- package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js +0 -48
- package/dist/cjs/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
- package/dist/cjs/getProps/index.js +0 -37
- package/dist/cjs/getProps/index.js.map +0 -7
- package/dist/cjs/globalProps/constants.js +0 -398
- package/dist/cjs/globalProps/constants.js.map +0 -7
- package/dist/cjs/globalProps/globalAttributesPropTypes.js +0 -398
- package/dist/cjs/globalProps/globalAttributesPropTypes.js.map +0 -7
- package/dist/cjs/globalProps/index.js +0 -29
- package/dist/cjs/globalProps/index.js.map +0 -7
- package/dist/cjs/globalProps/useGetGlobalAttributes.js +0 -56
- package/dist/cjs/globalProps/useGetGlobalAttributes.js.map +0 -7
- package/dist/cjs/index.js +0 -32
- package/dist/cjs/index.js.map +0 -7
- package/dist/cjs/propTypes/PropTypes.js +0 -136
- package/dist/cjs/propTypes/PropTypes.js.map +0 -7
- package/dist/cjs/propTypes/customPropTypes.js +0 -38
- package/dist/cjs/propTypes/customPropTypes.js.map +0 -7
- package/dist/cjs/propTypes/describe.js +0 -81
- package/dist/cjs/propTypes/describe.js.map +0 -7
- package/dist/cjs/propTypes/describeConversions.js +0 -96
- package/dist/cjs/propTypes/describeConversions.js.map +0 -7
- package/dist/cjs/propTypes/describeGuards.js +0 -49
- package/dist/cjs/propTypes/describeGuards.js.map +0 -7
- package/dist/cjs/propTypes/index.js +0 -37
- package/dist/cjs/propTypes/index.js.map +0 -7
- package/dist/cjs/propTypes/toTypescript.js +0 -139
- package/dist/cjs/propTypes/toTypescript.js.map +0 -7
- package/dist/cjs/propTypes/types.js +0 -27
- package/dist/cjs/propTypes/types.js.map +0 -7
- package/dist/cjs/tests/globalProps/TestComponent.js +0 -42
- package/dist/cjs/tests/globalProps/TestComponent.js.map +0 -7
- package/dist/cjs/tests/validation/test.schema.js +0 -67
- package/dist/cjs/tests/validation/test.schema.js.map +0 -7
- package/dist/cjs/validation/errorTemplates.js +0 -48
- package/dist/cjs/validation/errorTemplates.js.map +0 -7
- package/dist/cjs/validation/index.js +0 -30
- package/dist/cjs/validation/index.js.map +0 -7
- package/dist/cjs/validation/typescriptGuards.js +0 -65
- package/dist/cjs/validation/typescriptGuards.js.map +0 -7
- package/dist/cjs/validation/typescriptParsers.js +0 -76
- package/dist/cjs/validation/typescriptParsers.js.map +0 -7
- package/dist/cjs/validation/typescriptValidator.js +0 -171
- package/dist/cjs/validation/typescriptValidator.js.map +0 -7
- package/dist/cjs/validation/validator.js +0 -55
- package/dist/cjs/validation/validator.js.map +0 -7
- package/dist/esm/defaultProps/index.js +0 -3
- package/dist/esm/defaultProps/index.js.map +0 -7
- package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js +0 -19
- package/dist/esm/defaultProps/useMemoMergePropsWithDefault.js.map +0 -7
- package/dist/esm/getProps/index.js +0 -8
- package/dist/esm/getProps/index.js.map +0 -7
- package/dist/esm/globalProps/constants.js +0 -369
- package/dist/esm/globalProps/constants.js.map +0 -7
- package/dist/esm/globalProps/globalAttributesPropTypes.js.map +0 -7
- package/dist/esm/globalProps/index.js +0 -4
- package/dist/esm/globalProps/index.js.map +0 -7
- package/dist/esm/globalProps/useGetGlobalAttributes.js +0 -27
- package/dist/esm/globalProps/useGetGlobalAttributes.js.map +0 -7
- package/dist/esm/index.js +0 -7
- package/dist/esm/index.js.map +0 -7
- package/dist/esm/propTypes/PropTypes.js +0 -107
- package/dist/esm/propTypes/PropTypes.js.map +0 -7
- package/dist/esm/propTypes/customPropTypes.js +0 -9
- package/dist/esm/propTypes/customPropTypes.js.map +0 -7
- package/dist/esm/propTypes/describe.js +0 -52
- package/dist/esm/propTypes/describe.js.map +0 -7
- package/dist/esm/propTypes/describeConversions.js +0 -76
- package/dist/esm/propTypes/describeConversions.js.map +0 -7
- package/dist/esm/propTypes/describeGuards.js +0 -20
- package/dist/esm/propTypes/describeGuards.js.map +0 -7
- package/dist/esm/propTypes/index.js +0 -8
- package/dist/esm/propTypes/index.js.map +0 -7
- package/dist/esm/propTypes/toTypescript.js +0 -110
- package/dist/esm/propTypes/toTypescript.js.map +0 -7
- package/dist/esm/propTypes/types.js +0 -2
- package/dist/esm/propTypes/types.js.map +0 -7
- package/dist/esm/tests/globalProps/TestComponent.js +0 -13
- package/dist/esm/tests/globalProps/TestComponent.js.map +0 -7
- package/dist/esm/tests/validation/test.schema.js +0 -38
- package/dist/esm/tests/validation/test.schema.js.map +0 -7
- package/dist/esm/validation/errorTemplates.js +0 -19
- package/dist/esm/validation/errorTemplates.js.map +0 -7
- package/dist/esm/validation/index.js +0 -5
- package/dist/esm/validation/index.js.map +0 -7
- package/dist/esm/validation/typescriptGuards.js +0 -36
- package/dist/esm/validation/typescriptGuards.js.map +0 -7
- package/dist/esm/validation/typescriptParsers.js +0 -47
- package/dist/esm/validation/typescriptParsers.js.map +0 -7
- package/dist/esm/validation/typescriptValidator.js +0 -153
- package/dist/esm/validation/typescriptValidator.js.map +0 -7
- package/dist/esm/validation/validator.js +0 -26
- package/dist/esm/validation/validator.js.map +0 -7
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
5
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
7
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
8
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
9
|
+
|
|
10
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
11
|
+
|
|
12
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
13
|
+
|
|
14
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
15
|
+
|
|
16
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
17
|
+
|
|
18
|
+
const addPropTypeDocumentationField = fieldName => function addFieldToReactDesc(value) {
|
|
19
|
+
if (!this.reactDesc) {
|
|
20
|
+
this.reactDesc = {};
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
let realValue = value;
|
|
24
|
+
if (fieldName === 'global' || fieldName === 'hidden') realValue = true;
|
|
25
|
+
this.reactDesc[fieldName] = realValue;
|
|
26
|
+
return this;
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const documentedPropType = {
|
|
30
|
+
defaultValue: addPropTypeDocumentationField('defaultValue'),
|
|
31
|
+
description: addPropTypeDocumentationField('description'),
|
|
32
|
+
deprecated: addPropTypeDocumentationField('deprecated'),
|
|
33
|
+
format: addPropTypeDocumentationField('format'),
|
|
34
|
+
global: addPropTypeDocumentationField('global'),
|
|
35
|
+
hidden: addPropTypeDocumentationField('hidden')
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const createPropType = type => {
|
|
39
|
+
const propTypeObj = _objectSpread({
|
|
40
|
+
type
|
|
41
|
+
}, documentedPropType);
|
|
42
|
+
|
|
43
|
+
Object.defineProperty(propTypeObj, 'isRequired', {
|
|
44
|
+
get: function getRequired() {
|
|
45
|
+
if (!this.reactDesc) {
|
|
46
|
+
this.reactDesc = {};
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.reactDesc.required = true;
|
|
50
|
+
return this;
|
|
51
|
+
},
|
|
52
|
+
enumerable: true,
|
|
53
|
+
configurable: true
|
|
54
|
+
});
|
|
55
|
+
return propTypeObj;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const createPropTypeWithArgs = type => args => {
|
|
59
|
+
const propTypeObj = _objectSpread({
|
|
60
|
+
args,
|
|
61
|
+
type
|
|
62
|
+
}, documentedPropType);
|
|
63
|
+
|
|
64
|
+
Object.defineProperty(propTypeObj, 'isRequired', {
|
|
65
|
+
get: function getRequired() {
|
|
66
|
+
if (!this.reactDesc) {
|
|
67
|
+
this.reactDesc = {};
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
this.reactDesc.required = true;
|
|
71
|
+
return this;
|
|
72
|
+
},
|
|
73
|
+
enumerable: true,
|
|
74
|
+
configurable: true
|
|
75
|
+
});
|
|
76
|
+
return propTypeObj;
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const PropTypes = {
|
|
80
|
+
custom: callback => {
|
|
81
|
+
const target = callback.bind(null);
|
|
82
|
+
target.type = 'func';
|
|
83
|
+
Object.keys(documentedPropType).forEach(fieldName => {
|
|
84
|
+
const fieldNameCasted = fieldName; // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion
|
|
85
|
+
|
|
86
|
+
target[fieldNameCasted] = documentedPropType[fieldNameCasted];
|
|
87
|
+
});
|
|
88
|
+
return target;
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
function definePropType(type) {
|
|
93
|
+
Object.defineProperty(PropTypes, type, {
|
|
94
|
+
get: function getPropType() {
|
|
95
|
+
return createPropType(type);
|
|
96
|
+
},
|
|
97
|
+
enumerable: true,
|
|
98
|
+
configurable: true
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
function definePropTypeWithArgs(type) {
|
|
103
|
+
Object.defineProperty(PropTypes, type, {
|
|
104
|
+
get: function getPropType() {
|
|
105
|
+
return createPropTypeWithArgs(type);
|
|
106
|
+
},
|
|
107
|
+
enumerable: true,
|
|
108
|
+
configurable: true
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
definePropType('any');
|
|
113
|
+
definePropType('array');
|
|
114
|
+
definePropType('bool');
|
|
115
|
+
definePropType('element');
|
|
116
|
+
definePropType('func');
|
|
117
|
+
definePropType('node');
|
|
118
|
+
definePropType('number');
|
|
119
|
+
definePropType('object');
|
|
120
|
+
definePropType('symbol');
|
|
121
|
+
definePropType('string');
|
|
122
|
+
definePropTypeWithArgs('arrayOf');
|
|
123
|
+
definePropTypeWithArgs('instanceOf');
|
|
124
|
+
definePropTypeWithArgs('objectOf');
|
|
125
|
+
definePropTypeWithArgs('oneOfType');
|
|
126
|
+
definePropTypeWithArgs('oneOf');
|
|
127
|
+
definePropTypeWithArgs('shape');
|
|
128
|
+
definePropTypeWithArgs('tuple');
|
|
129
|
+
|
|
130
|
+
module.exports = PropTypes;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
6
|
+
|
|
7
|
+
/* eslint-disable max-params */
|
|
8
|
+
const tupleValidator = tupleShape => {
|
|
9
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-call
|
|
10
|
+
const func = function (value, index) {
|
|
11
|
+
for (var _len = arguments.length, rest = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
|
|
12
|
+
rest[_key - 2] = arguments[_key];
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return tupleShape[index](value, index, ...rest);
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
return func;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
exports.tupleValidator = tupleValidator;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
4
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
5
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
6
|
+
var describeConversions = require('./describeConversions.js');
|
|
7
|
+
var toTypescript = require('./toTypescript.js');
|
|
8
|
+
|
|
9
|
+
function describe(ComponentInstance) {
|
|
10
|
+
if (!ComponentInstance) {
|
|
11
|
+
throw new Error('react-desc: component is required');
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const documentation = {
|
|
15
|
+
propTypes: {}
|
|
16
|
+
};
|
|
17
|
+
const DocumentedComponent = ComponentInstance;
|
|
18
|
+
|
|
19
|
+
const addDocumentationProp = propName => {
|
|
20
|
+
const func = value => {
|
|
21
|
+
documentation[propName] = value;
|
|
22
|
+
return DocumentedComponent;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
return func;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
DocumentedComponent.availableAt = addDocumentationProp('availableAt');
|
|
29
|
+
DocumentedComponent.description = addDocumentationProp('description');
|
|
30
|
+
DocumentedComponent.details = addDocumentationProp('details');
|
|
31
|
+
DocumentedComponent.deprecated = addDocumentationProp('deprecated');
|
|
32
|
+
DocumentedComponent.usage = addDocumentationProp('usage');
|
|
33
|
+
DocumentedComponent.intrinsicElement = addDocumentationProp('intrinsicElement');
|
|
34
|
+
|
|
35
|
+
DocumentedComponent.toTypescript = () => toTypescript(ComponentInstance, documentation);
|
|
36
|
+
|
|
37
|
+
Object.defineProperty(DocumentedComponent, 'propTypes', {
|
|
38
|
+
get: () => DocumentedComponent.propTypesValue,
|
|
39
|
+
set: value => {
|
|
40
|
+
if (!DocumentedComponent.propTypesValue) {
|
|
41
|
+
DocumentedComponent.propTypesValue = {};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
Object.keys(value).forEach(name => {
|
|
45
|
+
const propType = value[name];
|
|
46
|
+
let realPropType;
|
|
47
|
+
documentation.propTypes[name] = propType;
|
|
48
|
+
realPropType = describeConversions.convertPropType(propType);
|
|
49
|
+
|
|
50
|
+
if (value[name].reactDesc.required) {
|
|
51
|
+
realPropType = realPropType.isRequired;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
DocumentedComponent.propTypesValue[name] = realPropType;
|
|
55
|
+
return propType;
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
enumerable: true,
|
|
59
|
+
configurable: true
|
|
60
|
+
});
|
|
61
|
+
return DocumentedComponent;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
module.exports = describe;
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/web.dom-collections.iterator.js');
|
|
6
|
+
require('core-js/modules/esnext.async-iterator.map.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.map.js');
|
|
8
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
9
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
11
|
+
var PropTypes = require('prop-types');
|
|
12
|
+
var customPropTypes = require('./customPropTypes.js');
|
|
13
|
+
var describeGuards = require('./describeGuards.js');
|
|
14
|
+
|
|
15
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
16
|
+
|
|
17
|
+
var PropTypes__default = /*#__PURE__*/_interopDefaultLegacy(PropTypes);
|
|
18
|
+
|
|
19
|
+
const enrichPropType = (propType, reactDesc) => {
|
|
20
|
+
const func = function (props, propName, componentName) {
|
|
21
|
+
if (reactDesc && reactDesc.deprecated && propName in props && !reactDesc.warned) {
|
|
22
|
+
const {
|
|
23
|
+
version = '',
|
|
24
|
+
message = ''
|
|
25
|
+
} = reactDesc.deprecated;
|
|
26
|
+
const warning = "\"".concat(propName, "\" property of \"").concat(componentName, "\" will be deprecated on VERSION: ").concat(version, ".\n").concat(message);
|
|
27
|
+
console.warn(warning);
|
|
28
|
+
reactDesc.warned = true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (var _len = arguments.length, rest = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
32
|
+
rest[_key - 3] = arguments[_key];
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return propType(props, propName, componentName, ...rest);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
Object.defineProperty(func, 'isRequired', Object.getOwnPropertyDescriptor(propType, 'isRequired'));
|
|
39
|
+
return func;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const convertArray = array => array.map(type => convertPropType(type));
|
|
43
|
+
|
|
44
|
+
const convertShape = _shape => {
|
|
45
|
+
const result = {};
|
|
46
|
+
Object.keys(_shape).forEach(key => {
|
|
47
|
+
result[key] = convertPropType(_shape[key]);
|
|
48
|
+
});
|
|
49
|
+
return result;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const convertPropType = propType => {
|
|
53
|
+
if (!propType || !propType.type) {
|
|
54
|
+
throw new Error("react-desc: unknown error -- proptype is not well defined");
|
|
55
|
+
} // DimSum PropTypes conversion
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
if (propType.type === 'tuple') {
|
|
59
|
+
return enrichPropType(PropTypes__default["default"].arrayOf(customPropTypes.tupleValidator(convertArray(propType.args))), propType.reactDesc);
|
|
60
|
+
} // Default PropType conversion
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
const realPropType = PropTypes__default["default"][propType.type];
|
|
64
|
+
|
|
65
|
+
if (!realPropType) {
|
|
66
|
+
throw new Error("react-desc: unknown type ".concat(propType.type));
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (describeGuards.hasArguments(propType)) {
|
|
70
|
+
if (describeGuards.isOneOfType(propType)) {
|
|
71
|
+
return enrichPropType(realPropType(convertArray(propType.args)), propType.reactDesc);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
if (describeGuards.isArrayOf(propType)) {
|
|
75
|
+
return enrichPropType(realPropType(convertPropType(propType.args)), propType.reactDesc);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
if (describeGuards.isShape(propType)) {
|
|
79
|
+
return enrichPropType(realPropType(convertShape(propType.args)), propType.reactDesc);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (describeGuards.isInstanceOf(propType)) {
|
|
83
|
+
return enrichPropType(realPropType(propType.args), propType.reactDesc);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (describeGuards.isOneOf(propType)) {
|
|
87
|
+
return enrichPropType(realPropType(propType.args), propType.reactDesc);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (describeGuards.isObjectOf(propType)) {
|
|
91
|
+
return enrichPropType(realPropType(propType.args), propType.reactDesc);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (describeGuards.isExact(propType)) {
|
|
95
|
+
return enrichPropType(realPropType(propType.args), propType.reactDesc);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
throw new Error("react-desc: unknown error -- proptype with args is not matching");
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return enrichPropType(realPropType, propType.reactDesc);
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
exports.convertPropType = convertPropType;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
const hasArguments = (propType, realPropType) => !!propType.args;
|
|
6
|
+
const isOneOfType = (propType, realPropType) => propType.type === 'oneOfType';
|
|
7
|
+
const isArrayOf = (propType, realPropType) => propType.type === 'arrayOf';
|
|
8
|
+
const isShape = (propType, realPropType) => propType.type === 'shape';
|
|
9
|
+
const isInstanceOf = (propType, realPropType) => propType.type === 'instanceOf';
|
|
10
|
+
const isOneOf = (propType, realPropType) => propType.type === 'oneOf';
|
|
11
|
+
const isObjectOf = (propType, realPropType) => propType.type === 'objectOf';
|
|
12
|
+
const isExact = (propType, realPropType) => propType.type === 'exact';
|
|
13
|
+
|
|
14
|
+
exports.hasArguments = hasArguments;
|
|
15
|
+
exports.isArrayOf = isArrayOf;
|
|
16
|
+
exports.isExact = isExact;
|
|
17
|
+
exports.isInstanceOf = isInstanceOf;
|
|
18
|
+
exports.isObjectOf = isObjectOf;
|
|
19
|
+
exports.isOneOf = isOneOf;
|
|
20
|
+
exports.isOneOfType = isOneOfType;
|
|
21
|
+
exports.isShape = isShape;
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _defineProperty = require('@babel/runtime/helpers/defineProperty');
|
|
4
|
+
require('core-js/modules/esnext.async-iterator.map.js');
|
|
5
|
+
require('core-js/modules/esnext.iterator.map.js');
|
|
6
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
8
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
9
|
+
require('core-js/modules/esnext.async-iterator.filter.js');
|
|
10
|
+
require('core-js/modules/esnext.iterator.filter.js');
|
|
11
|
+
|
|
12
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
13
|
+
|
|
14
|
+
var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
|
|
15
|
+
|
|
16
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
17
|
+
|
|
18
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
19
|
+
|
|
20
|
+
/* eslint-disable @typescript-eslint/restrict-template-expressions */
|
|
21
|
+
|
|
22
|
+
/* eslint-disable @typescript-eslint/no-use-before-define */
|
|
23
|
+
|
|
24
|
+
/* eslint-disable complexity */
|
|
25
|
+
|
|
26
|
+
/* eslint-disable react/forbid-foreign-prop-types */
|
|
27
|
+
const arrayFormat = array => array.map(propType => propTypeFormat(propType));
|
|
28
|
+
|
|
29
|
+
const shapeFormat = shape => {
|
|
30
|
+
const props = Object.keys(shape).map(key => {
|
|
31
|
+
const value = shape[key];
|
|
32
|
+
let valueFormat;
|
|
33
|
+
|
|
34
|
+
if (value.type && (value.type === 'arrayOf' || value.type === 'oneOfType' || value.type === 'oneOf') && Array.isArray(value.args)) {
|
|
35
|
+
valueFormat = "".concat(propTypeFormat(value));
|
|
36
|
+
} else if (value.type === 'shape') {
|
|
37
|
+
valueFormat = "".concat(propTypeFormat(value));
|
|
38
|
+
} else {
|
|
39
|
+
valueFormat = propTypeFormat(value);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
return "".concat(key).concat(value.reactDesc && value.reactDesc.required ? '' : '?', ": ").concat(valueFormat);
|
|
43
|
+
});
|
|
44
|
+
return "{".concat(props.join(','), "}");
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const propTypeFormat = function (propType) {
|
|
48
|
+
let joinWith = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
49
|
+
let result;
|
|
50
|
+
|
|
51
|
+
if (Array.isArray(propType)) {
|
|
52
|
+
result = arrayFormat(propType).join(joinWith);
|
|
53
|
+
} else if (typeof propType !== 'function' && propType.type) {
|
|
54
|
+
switch (propType.type) {
|
|
55
|
+
case 'array':
|
|
56
|
+
result = 'any[]';
|
|
57
|
+
break;
|
|
58
|
+
|
|
59
|
+
case 'arrayOf':
|
|
60
|
+
if (propType.args.type === 'oneOfType') {
|
|
61
|
+
result = "(".concat(propTypeFormat(propType.args, ' | '), ")[]");
|
|
62
|
+
} else {
|
|
63
|
+
result = "".concat(propTypeFormat(propType.args, '\n'), "[]");
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
break;
|
|
67
|
+
|
|
68
|
+
case 'tuple':
|
|
69
|
+
result = "[".concat(propTypeFormat(propType.args, ', '), "]");
|
|
70
|
+
break;
|
|
71
|
+
|
|
72
|
+
case 'bool':
|
|
73
|
+
result = 'boolean';
|
|
74
|
+
break;
|
|
75
|
+
|
|
76
|
+
case 'func':
|
|
77
|
+
result = '((...args: any[]) => any)';
|
|
78
|
+
break;
|
|
79
|
+
|
|
80
|
+
case 'node':
|
|
81
|
+
result = 'React.ReactNode';
|
|
82
|
+
break;
|
|
83
|
+
|
|
84
|
+
case 'element':
|
|
85
|
+
result = 'JSX.Element';
|
|
86
|
+
break;
|
|
87
|
+
|
|
88
|
+
case 'instanceOf':
|
|
89
|
+
result = 'any';
|
|
90
|
+
break;
|
|
91
|
+
|
|
92
|
+
case 'symbol':
|
|
93
|
+
result = 'any';
|
|
94
|
+
break;
|
|
95
|
+
|
|
96
|
+
case 'objectOf':
|
|
97
|
+
result = "{ [key: string]: ".concat(propTypeFormat(propType.args), " }");
|
|
98
|
+
break;
|
|
99
|
+
|
|
100
|
+
case 'oneOf':
|
|
101
|
+
result = propType.args.map(a => "\"".concat(a, "\"")).join(' | ');
|
|
102
|
+
break;
|
|
103
|
+
|
|
104
|
+
case 'oneOfType':
|
|
105
|
+
result = "".concat(propTypeFormat(propType.args, ' | '));
|
|
106
|
+
break;
|
|
107
|
+
|
|
108
|
+
case 'shape':
|
|
109
|
+
result = "".concat(shapeFormat(propType.args));
|
|
110
|
+
break;
|
|
111
|
+
|
|
112
|
+
default:
|
|
113
|
+
result = "".concat(propType.type);
|
|
114
|
+
break;
|
|
115
|
+
}
|
|
116
|
+
} else {
|
|
117
|
+
result = 'any';
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
return result;
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const propTypeAsTypescript = (propType, propName) => {
|
|
124
|
+
const documentation = _objectSpread(_objectSpread({}, propType.reactDesc), {}, {
|
|
125
|
+
name: propName
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
documentation.format = propTypeFormat(propType);
|
|
129
|
+
return documentation;
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
function descToTypescript(component, reactDesc) {
|
|
133
|
+
if (!component) {
|
|
134
|
+
throw new Error('react-desc: component is required');
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
const documentation = _objectSpread({
|
|
138
|
+
name: component.displayName || component.name
|
|
139
|
+
}, reactDesc);
|
|
140
|
+
|
|
141
|
+
if (reactDesc) {
|
|
142
|
+
delete documentation.propTypes;
|
|
143
|
+
|
|
144
|
+
if (reactDesc.propTypes) {
|
|
145
|
+
const propTypes = [];
|
|
146
|
+
Object.keys(reactDesc.propTypes).forEach(propName => {
|
|
147
|
+
const propType = reactDesc.propTypes[propName];
|
|
148
|
+
propTypes.push(propTypeAsTypescript(propType, propName));
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
if (propTypes.length > 0) {
|
|
152
|
+
documentation.properties = propTypes;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
return documentation;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
module.exports = descToTypescript;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/es.string.replace.js');
|
|
6
|
+
|
|
7
|
+
/* eslint-disable max-params */
|
|
8
|
+
const throwTypeError = (componentName, validPropKey, invalidProp, validFormat) => {
|
|
9
|
+
throw new Error("".concat(componentName, ":: You are trying to pass a not valid \"").concat(validPropKey, "\" property, \n please provide a valid type.\n\n Received: ").concat(invalidProp, " (").concat(typeof invalidProp, ")\n Expected: (").concat(validFormat.replace('\n', ' or '), ")\n "));
|
|
10
|
+
};
|
|
11
|
+
const throwRequiredError = (componentName, validPropKey) => {
|
|
12
|
+
throw new Error("".concat(componentName, ":: Please provide a/an \"").concat(validPropKey, "\" property to use this component. \n This property is required.\n "));
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
exports.throwRequiredError = throwRequiredError;
|
|
16
|
+
exports.throwTypeError = throwTypeError;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var validator = require('./validator.js');
|
|
6
|
+
var errorTemplates = require('./errorTemplates.js');
|
|
7
|
+
var typescriptValidator = require('./typescriptValidator.js');
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
exports.useValidatePropTypes = validator.useValidatePropTypes;
|
|
12
|
+
exports.throwRequiredError = errorTemplates.throwRequiredError;
|
|
13
|
+
exports.throwTypeError = errorTemplates.throwTypeError;
|
|
14
|
+
exports.useValidateTypescriptPropTypes = typescriptValidator.useValidateTypescriptPropTypes;
|
|
15
|
+
exports.validateTypescriptPropTypesImplementation = typescriptValidator.validateTypescriptPropTypesImplementation;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
|
|
9
|
+
const isPrimitiveType = format => ['string', 'number', 'boolean'].includes(format);
|
|
10
|
+
const isUndefined = format => format === '"undefined"';
|
|
11
|
+
const isNull = format => format === '"null"';
|
|
12
|
+
const isUnion = format => {
|
|
13
|
+
let depth = 0;
|
|
14
|
+
let satisfies = false;
|
|
15
|
+
format.split('').forEach(char => {
|
|
16
|
+
if (['{', '('].includes(char)) depth += 1;else if (['}', ')'].includes(char)) depth -= 1;else if (char === '|' && depth === 0) satisfies = true;
|
|
17
|
+
});
|
|
18
|
+
return satisfies;
|
|
19
|
+
};
|
|
20
|
+
const isString = format => !isUnion(format) && format[0] === '"' && format.slice(-1) === '"';
|
|
21
|
+
const isArray = format => !isUnion(format) && format.slice(-2) === '[]';
|
|
22
|
+
const isObject = format => format === 'object' || !isUnion(format) && format[0] === '{' && format.slice(-1) === '}';
|
|
23
|
+
const isFunction = format => !isUnion(format) && format === '((...args: any[]) => any)';
|
|
24
|
+
const isJSXorNode = format => !isUnion(format) && ['React.ReactNode', 'JSX.Element'].includes(format);
|
|
25
|
+
const isSomethingWithParenthesis = format => !isUnion(format) && format[0] === '(' && format.slice(-1) === ')';
|
|
26
|
+
|
|
27
|
+
exports.isArray = isArray;
|
|
28
|
+
exports.isFunction = isFunction;
|
|
29
|
+
exports.isJSXorNode = isJSXorNode;
|
|
30
|
+
exports.isNull = isNull;
|
|
31
|
+
exports.isObject = isObject;
|
|
32
|
+
exports.isPrimitiveType = isPrimitiveType;
|
|
33
|
+
exports.isSomethingWithParenthesis = isSomethingWithParenthesis;
|
|
34
|
+
exports.isString = isString;
|
|
35
|
+
exports.isUndefined = isUndefined;
|
|
36
|
+
exports.isUnion = isUnion;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
require('core-js/modules/esnext.async-iterator.for-each.js');
|
|
6
|
+
require('core-js/modules/esnext.iterator.constructor.js');
|
|
7
|
+
require('core-js/modules/esnext.iterator.for-each.js');
|
|
8
|
+
|
|
9
|
+
/* eslint-disable complexity */
|
|
10
|
+
const typescriptObjectParser = format => {
|
|
11
|
+
const keyValuePairs = []; // State of the algorithm
|
|
12
|
+
|
|
13
|
+
let lastKey = '';
|
|
14
|
+
let lastValue = '';
|
|
15
|
+
let shouldAppendToKey = true;
|
|
16
|
+
|
|
17
|
+
const pushPair = () => {
|
|
18
|
+
if (lastKey) keyValuePairs.push([lastKey, lastValue]);
|
|
19
|
+
lastKey = '';
|
|
20
|
+
lastValue = '';
|
|
21
|
+
shouldAppendToKey = true;
|
|
22
|
+
}; // Complex -- but working -- logic
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
let depth = 0;
|
|
26
|
+
format.split('').forEach(char => {
|
|
27
|
+
if (char === '{') {
|
|
28
|
+
depth += 1;
|
|
29
|
+
if (depth > 1) lastValue += char;
|
|
30
|
+
} else if (char === '}') {
|
|
31
|
+
if (depth > 1) lastValue += char;
|
|
32
|
+
depth -= 1;
|
|
33
|
+
if (depth === 1) pushPair();
|
|
34
|
+
} else if (char === ':') {
|
|
35
|
+
shouldAppendToKey = false;
|
|
36
|
+
if (depth > 1) lastValue += char;
|
|
37
|
+
} else if (char === ',') {
|
|
38
|
+
if (depth === 1) pushPair();else lastValue += char;
|
|
39
|
+
} else if (char === ' ') ; else if (shouldAppendToKey) lastKey += char;else lastValue += char;
|
|
40
|
+
});
|
|
41
|
+
pushPair();
|
|
42
|
+
return keyValuePairs;
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
exports.typescriptObjectParser = typescriptObjectParser;
|