@instructure/ui-react-utils 8.33.1 → 8.33.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/CHANGELOG.md +4 -0
- package/es/ComponentIdentifier.js +5 -8
- package/es/DeterministicIdContext/DeterministicIdContextProvider.js +2 -2
- package/es/DeterministicIdContext/generateInstanceCounterMap.js +1 -1
- package/es/DeterministicIdContext/index.js +1 -0
- package/es/DeterministicIdContext/withDeterministicId.js +6 -10
- package/es/callRenderProp.js +3 -7
- package/es/deprecated.js +5 -30
- package/es/ensureSingleChild.js +2 -3
- package/es/experimental.js +0 -7
- package/es/getDisplayName.js +0 -1
- package/es/getElementType.js +3 -9
- package/es/getInteraction.js +12 -10
- package/es/hack.js +1 -7
- package/es/matchComponentTypes.js +1 -3
- package/es/omitProps.js +0 -7
- package/es/passthroughProps.js +3 -3
- package/es/pickProps.js +2 -6
- package/es/safeCloneElement.js +11 -15
- package/es/windowMessageListener.js +2 -13
- package/lib/ComponentIdentifier.js +2 -17
- package/lib/DeterministicIdContext/DeterministicIdContext.js +1 -5
- package/lib/DeterministicIdContext/DeterministicIdContextProvider.js +3 -7
- package/lib/DeterministicIdContext/generateInstanceCounterMap.js +1 -2
- package/lib/DeterministicIdContext/index.js +0 -4
- package/lib/DeterministicIdContext/withDeterministicId.js +6 -18
- package/lib/callRenderProp.js +2 -9
- package/lib/deprecated.js +6 -32
- package/lib/ensureSingleChild.js +0 -7
- package/lib/experimental.js +1 -10
- package/lib/getDisplayName.js +0 -2
- package/lib/getElementType.js +2 -10
- package/lib/getInteraction.js +12 -11
- package/lib/hack.js +0 -9
- package/lib/index.js +0 -16
- package/lib/matchComponentTypes.js +0 -4
- package/lib/omitProps.js +0 -8
- package/lib/passthroughProps.js +2 -5
- package/lib/pickProps.js +2 -7
- package/lib/safeCloneElement.js +10 -19
- package/lib/windowMessageListener.js +1 -16
- package/package.json +8 -8
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/getElementType.d.ts +1 -1
- package/types/getElementType.d.ts.map +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,10 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
## [8.33.2](https://github.com/instructure/instructure-ui/compare/v8.33.1...v8.33.2) (2023-01-25)
|
|
7
|
+
|
|
8
|
+
**Note:** Version bump only for package @instructure/ui-react-utils
|
|
9
|
+
|
|
6
10
|
## [8.33.1](https://github.com/instructure/instructure-ui/compare/v8.33.0...v8.33.1) (2023-01-06)
|
|
7
11
|
|
|
8
12
|
**Note:** Version bump only for package @instructure/ui-react-utils
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
2
2
|
const _excluded = ["children"];
|
|
3
|
-
|
|
4
3
|
var _dec, _class, _class2;
|
|
5
|
-
|
|
6
4
|
/*
|
|
7
5
|
* The MIT License (MIT)
|
|
8
6
|
*
|
|
@@ -26,12 +24,14 @@ var _dec, _class, _class2;
|
|
|
26
24
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
27
25
|
* SOFTWARE.
|
|
28
26
|
*/
|
|
27
|
+
|
|
29
28
|
import React, { Component } from 'react';
|
|
30
29
|
import PropTypes from 'prop-types';
|
|
31
30
|
import { matchComponentTypes } from './matchComponentTypes';
|
|
32
31
|
import { ensureSingleChild } from './ensureSingleChild';
|
|
33
|
-
import deprecated from './deprecated';
|
|
32
|
+
import deprecated from './deprecated';
|
|
34
33
|
|
|
34
|
+
// TODO delete this class, its not used anywhere, see livegrep
|
|
35
35
|
/**
|
|
36
36
|
---
|
|
37
37
|
category: utilities/react
|
|
@@ -68,16 +68,13 @@ Abstract component identifier. Helpful for picking out a specific child.
|
|
|
68
68
|
```
|
|
69
69
|
@module ComponentIdentifier
|
|
70
70
|
**/
|
|
71
|
-
|
|
72
71
|
let ComponentIdentifier = (_dec = deprecated('8.0.0', void 0, 'This component will be removed in InstUI 9.0 since its not used.'), _dec(_class = (_class2 = class ComponentIdentifier extends Component {
|
|
73
72
|
render() {
|
|
74
73
|
const _this$props = this.props,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
74
|
+
children = _this$props.children,
|
|
75
|
+
props = _objectWithoutProperties(_this$props, _excluded);
|
|
78
76
|
return ensureSingleChild(children, props);
|
|
79
77
|
}
|
|
80
|
-
|
|
81
78
|
}, _class2.displayName = "ComponentIdentifier", _class2.propTypes = {
|
|
82
79
|
children: PropTypes.node
|
|
83
80
|
}, _class2.defaultProps = {
|
|
@@ -25,6 +25,7 @@ import React from 'react';
|
|
|
25
25
|
import { generateInstanceCounterMap } from './generateInstanceCounterMap';
|
|
26
26
|
import { DeterministicIdContext } from './DeterministicIdContext';
|
|
27
27
|
const defaultContextValue = generateInstanceCounterMap();
|
|
28
|
+
|
|
28
29
|
/**
|
|
29
30
|
* ---
|
|
30
31
|
* category: components/utilities
|
|
@@ -35,12 +36,11 @@ const defaultContextValue = generateInstanceCounterMap();
|
|
|
35
36
|
|
|
36
37
|
const DeterministicIdContextProvider = _ref => {
|
|
37
38
|
let children = _ref.children,
|
|
38
|
-
|
|
39
|
+
instanceCounterMap = _ref.instanceCounterMap;
|
|
39
40
|
return /*#__PURE__*/React.createElement(DeterministicIdContext.Provider, {
|
|
40
41
|
value: instanceCounterMap
|
|
41
42
|
}, children);
|
|
42
43
|
};
|
|
43
|
-
|
|
44
44
|
DeterministicIdContextProvider.defaultProps = {
|
|
45
45
|
instanceCounterMap: defaultContextValue
|
|
46
46
|
};
|
|
@@ -21,9 +21,9 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
function generateInstanceCounterMap() {
|
|
25
26
|
return new Map();
|
|
26
27
|
}
|
|
27
|
-
|
|
28
28
|
export default generateInstanceCounterMap;
|
|
29
29
|
export { generateInstanceCounterMap };
|
|
@@ -21,6 +21,7 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
export { generateInstanceCounterMap } from './generateInstanceCounterMap';
|
|
25
26
|
export { DeterministicIdContextProvider } from './DeterministicIdContextProvider';
|
|
26
27
|
export { DeterministicIdContext } from './DeterministicIdContext';
|
|
@@ -27,7 +27,6 @@ import { DeterministicIdContext } from './DeterministicIdContext';
|
|
|
27
27
|
import { decorator } from '@instructure/ui-decorator';
|
|
28
28
|
import { generateId } from '@instructure/ui-utils';
|
|
29
29
|
import { warn } from '@instructure/console';
|
|
30
|
-
|
|
31
30
|
/**
|
|
32
31
|
* This decorator is used to enable the decorated class to use the `DeterministicIdContext` which is needed
|
|
33
32
|
* for deterministic id generation.
|
|
@@ -40,35 +39,32 @@ const withDeterministicId = decorator(ComposedComponent => {
|
|
|
40
39
|
const WithDeterministicId = /*#__PURE__*/forwardRef((props, ref) => {
|
|
41
40
|
const componentName = ComposedComponent.componentId || ComposedComponent.displayName || ComposedComponent.name;
|
|
42
41
|
const instanceCounterMap = useContext(DeterministicIdContext);
|
|
43
|
-
|
|
44
42
|
const deterministicId = function () {
|
|
45
43
|
let instanceName = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : componentName;
|
|
46
44
|
return generateId(instanceName, instanceCounterMap);
|
|
47
45
|
};
|
|
48
|
-
|
|
49
46
|
if (props.deterministicId) {
|
|
50
47
|
warn(false, `Manually passing the "deterministicId" property is not allowed on the ${componentName} component.\n`, props.deterministicId);
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
return /*#__PURE__*/React.createElement(ComposedComponent, Object.assign({
|
|
54
50
|
ref: ref,
|
|
55
51
|
deterministicId: deterministicId
|
|
56
52
|
}, props));
|
|
57
53
|
});
|
|
58
|
-
hoistNonReactStatics(WithDeterministicId, ComposedComponent);
|
|
54
|
+
hoistNonReactStatics(WithDeterministicId, ComposedComponent);
|
|
55
|
+
|
|
56
|
+
// we have to pass these on, because sometimes users
|
|
59
57
|
// access propTypes of the component in other components
|
|
60
58
|
// eslint-disable-next-line react/forbid-foreign-prop-types
|
|
61
|
-
|
|
62
59
|
WithDeterministicId.propTypes = ComposedComponent.propTypes;
|
|
63
|
-
WithDeterministicId.defaultProps = ComposedComponent.defaultProps;
|
|
64
|
-
//@ts-expect-error fix this
|
|
60
|
+
WithDeterministicId.defaultProps = ComposedComponent.defaultProps;
|
|
65
61
|
|
|
62
|
+
// These static fields exist on InstUI components
|
|
63
|
+
//@ts-expect-error fix this
|
|
66
64
|
WithDeterministicId.allowedProps = ComposedComponent.allowedProps;
|
|
67
|
-
|
|
68
65
|
if (process.env.NODE_ENV !== 'production') {
|
|
69
66
|
WithDeterministicId.displayName = `WithDeterministicId(${ComposedComponent.displayName})`;
|
|
70
67
|
}
|
|
71
|
-
|
|
72
68
|
return WithDeterministicId;
|
|
73
69
|
});
|
|
74
70
|
export default withDeterministicId;
|
package/es/callRenderProp.js
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import React from 'react';
|
|
25
24
|
|
|
25
|
+
import React from 'react';
|
|
26
26
|
/**
|
|
27
27
|
* ---
|
|
28
28
|
* category: utilities/react
|
|
@@ -34,7 +34,6 @@ import React from 'react';
|
|
|
34
34
|
*/
|
|
35
35
|
function callRenderProp(value) {
|
|
36
36
|
let props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
37
|
-
|
|
38
37
|
if (typeof value === 'function') {
|
|
39
38
|
// In react 16, `createElement` accepts a function. In react 15 we get an
|
|
40
39
|
// error on rendering the result. Evaluate the function here if it is not a
|
|
@@ -42,14 +41,11 @@ function callRenderProp(value) {
|
|
|
42
41
|
// fat arrow functions don't have a prototype
|
|
43
42
|
if (!(value.prototype && value.prototype.isReactComponent)) {
|
|
44
43
|
return value(props);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
}
|
|
45
|
+
// TODO type 'value' properly
|
|
48
46
|
return /*#__PURE__*/React.createElement(value, props);
|
|
49
47
|
}
|
|
50
|
-
|
|
51
48
|
return value;
|
|
52
49
|
}
|
|
53
|
-
|
|
54
50
|
export default callRenderProp;
|
|
55
51
|
export { callRenderProp };
|
package/es/deprecated.js
CHANGED
|
@@ -23,28 +23,20 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { decorator } from '@instructure/ui-decorator';
|
|
25
25
|
import { logWarnDeprecated as warnDeprecated } from '@instructure/console';
|
|
26
|
-
|
|
27
26
|
const deprecated = (() => {
|
|
28
27
|
if (process.env.NODE_ENV === 'production') {
|
|
29
28
|
const deprecated = function () {
|
|
30
29
|
return ComposedComponent => ComposedComponent;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
30
|
+
};
|
|
31
|
+
// eslint-disable-next-line react/display-name
|
|
34
32
|
deprecated.deprecatePropValues = () => () => null;
|
|
35
|
-
|
|
36
33
|
deprecated.warnDeprecatedProps = () => {};
|
|
37
|
-
|
|
38
34
|
deprecated.warnDeprecatedComponent = () => {};
|
|
39
|
-
|
|
40
35
|
deprecated.changedPackageWarning = () => '';
|
|
41
|
-
|
|
42
36
|
return deprecated;
|
|
43
37
|
}
|
|
44
|
-
|
|
45
38
|
const deprecated = decorator(function (ComposedComponent, version, oldProps) {
|
|
46
39
|
let message = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : '';
|
|
47
|
-
|
|
48
40
|
/**
|
|
49
41
|
* ---
|
|
50
42
|
* category: utilities/react
|
|
@@ -71,31 +63,26 @@ const deprecated = (() => {
|
|
|
71
63
|
* @module deprecated
|
|
72
64
|
*/
|
|
73
65
|
class DeprecatedComponent extends ComposedComponent {}
|
|
74
|
-
|
|
75
66
|
DeprecatedComponent.prototype.componentDidMount = function () {
|
|
76
67
|
if (oldProps) {
|
|
77
68
|
warnDeprecatedProps(ComposedComponent.name, version, this.props, oldProps, message);
|
|
78
69
|
} else {
|
|
79
70
|
warnDeprecatedComponent(version, ComposedComponent.name, message);
|
|
80
71
|
}
|
|
81
|
-
|
|
82
72
|
if (ComposedComponent.prototype.componentDidMount) {
|
|
83
73
|
ComposedComponent.prototype.componentDidMount.call(this);
|
|
84
74
|
}
|
|
85
75
|
};
|
|
86
|
-
|
|
87
76
|
DeprecatedComponent.prototype.componentDidUpdate = function (prevProps, prevState, prevContext) {
|
|
88
77
|
if (oldProps) {
|
|
89
78
|
warnDeprecatedProps(ComposedComponent.name, version, this.props, oldProps, message);
|
|
90
79
|
} else {
|
|
91
80
|
warnDeprecatedComponent(version, ComposedComponent.name, message);
|
|
92
81
|
}
|
|
93
|
-
|
|
94
82
|
if (ComposedComponent.prototype.componentDidUpdate) {
|
|
95
83
|
ComposedComponent.prototype.componentDidUpdate.call(this, prevProps, prevState, prevContext);
|
|
96
84
|
}
|
|
97
85
|
};
|
|
98
|
-
|
|
99
86
|
return DeprecatedComponent;
|
|
100
87
|
})
|
|
101
88
|
/**
|
|
@@ -107,9 +94,7 @@ const deprecated = (() => {
|
|
|
107
94
|
* @param {function} propType - validates the prop type. Returns null if valid, error otherwise
|
|
108
95
|
* @param {array} deprecated - an array of the deprecated variant names
|
|
109
96
|
* @param {string|function} message - a string with additional information (like the version the prop will be removed) or a function returning a string
|
|
110
|
-
|
|
111
|
-
;
|
|
112
|
-
|
|
97
|
+
*/;
|
|
113
98
|
deprecated.deprecatePropValues = function (propType) {
|
|
114
99
|
let deprecated = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
115
100
|
let message = arguments.length > 2 ? arguments[2] : void 0;
|
|
@@ -121,15 +106,12 @@ const deprecated = (() => {
|
|
|
121
106
|
propValue: props[propName]
|
|
122
107
|
}) : `The '${props[propName]}' value for the \`${propName}\` prop is deprecated. ${message || ''}`;
|
|
123
108
|
warnDeprecated(!isDeprecatedValue, `[${componentName}] ${warningMessage}`);
|
|
124
|
-
|
|
125
109
|
for (var _len = arguments.length, rest = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++) {
|
|
126
110
|
rest[_key - 3] = arguments[_key];
|
|
127
111
|
}
|
|
128
|
-
|
|
129
112
|
return isDeprecatedValue ? null : propType(props, propName, componentName, ...rest);
|
|
130
113
|
};
|
|
131
114
|
};
|
|
132
|
-
|
|
133
115
|
function warnDeprecatedProps(componentName, version, props, oldProps) {
|
|
134
116
|
let message = arguments.length > 4 && arguments[4] !== void 0 ? arguments[4] : '';
|
|
135
117
|
Object.keys(oldProps).forEach(oldProp => {
|
|
@@ -140,10 +122,8 @@ const deprecated = (() => {
|
|
|
140
122
|
}
|
|
141
123
|
});
|
|
142
124
|
}
|
|
143
|
-
|
|
144
125
|
;
|
|
145
126
|
deprecated.warnDeprecatedProps = warnDeprecatedProps;
|
|
146
|
-
|
|
147
127
|
function warnDeprecatedComponent(version, componentName, message) {
|
|
148
128
|
warnDeprecated(false, `[${componentName}] is deprecated and will be removed in version ${version}. ${message || ''}`);
|
|
149
129
|
}
|
|
@@ -155,10 +135,9 @@ const deprecated = (() => {
|
|
|
155
135
|
* @param {String} componentName the name of the component or Function.name of the utility function
|
|
156
136
|
* @param {String} message a message to display as a console error in DEV env when condition is false
|
|
157
137
|
*/
|
|
158
|
-
|
|
159
|
-
|
|
160
138
|
;
|
|
161
139
|
deprecated.warnDeprecatedComponent = warnDeprecatedComponent
|
|
140
|
+
|
|
162
141
|
/**
|
|
163
142
|
* ---
|
|
164
143
|
* category: utilities
|
|
@@ -166,15 +145,11 @@ const deprecated = (() => {
|
|
|
166
145
|
* @param {String} prevPackage the previous name of the package
|
|
167
146
|
* @param {String} newPackage the new version of the package
|
|
168
147
|
* @return {String} the formatted warning string
|
|
169
|
-
|
|
170
|
-
;
|
|
171
|
-
|
|
148
|
+
*/;
|
|
172
149
|
deprecated.changedPackageWarning = (prevPackage, newPackage) => {
|
|
173
150
|
return `It has been moved from @instructure/${prevPackage} to @instructure/${newPackage}.`;
|
|
174
151
|
};
|
|
175
|
-
|
|
176
152
|
return deprecated;
|
|
177
153
|
})();
|
|
178
|
-
|
|
179
154
|
export default deprecated;
|
|
180
155
|
export { deprecated };
|
package/es/ensureSingleChild.js
CHANGED
|
@@ -21,8 +21,10 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
+
|
|
24
25
|
import React, { Children } from 'react';
|
|
25
26
|
import { safeCloneElement } from './safeCloneElement';
|
|
27
|
+
|
|
26
28
|
/**
|
|
27
29
|
* ---
|
|
28
30
|
* category: utilities/react
|
|
@@ -37,11 +39,9 @@ import { safeCloneElement } from './safeCloneElement';
|
|
|
37
39
|
* @param {Object} props - props for child
|
|
38
40
|
* @returns {ReactElement|null} cloned instance for a single child, or children wrapped in a span
|
|
39
41
|
*/
|
|
40
|
-
|
|
41
42
|
function ensureSingleChild(child) {
|
|
42
43
|
let props = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : {};
|
|
43
44
|
const childCount = Children.count(child);
|
|
44
|
-
|
|
45
45
|
if (childCount === 0) {
|
|
46
46
|
return null;
|
|
47
47
|
} else if (typeof child === 'string' && child.length > 0 || childCount > 1) {
|
|
@@ -51,6 +51,5 @@ function ensureSingleChild(child) {
|
|
|
51
51
|
return safeCloneElement(Array.isArray(child) ? child[0] : child, props);
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
-
|
|
55
54
|
export default ensureSingleChild;
|
|
56
55
|
export { ensureSingleChild };
|
package/es/experimental.js
CHANGED
|
@@ -33,12 +33,10 @@ const experimental = process.env.NODE_ENV == 'production' ? () => ReactComponent
|
|
|
33
33
|
warnExperimentalComponent(ComposedComponent.name, message);
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
|
|
37
36
|
if (super.componentDidMount) {
|
|
38
37
|
super.componentDidMount();
|
|
39
38
|
}
|
|
40
39
|
}
|
|
41
|
-
|
|
42
40
|
componentDidUpdate(prevProps, prevState, prevContext) {
|
|
43
41
|
if (!this.props.__dangerouslyIgnoreExperimentalWarnings) {
|
|
44
42
|
if (experimentalProps) {
|
|
@@ -47,27 +45,22 @@ const experimental = process.env.NODE_ENV == 'production' ? () => ReactComponent
|
|
|
47
45
|
warnExperimentalComponent(ComposedComponent.name, message);
|
|
48
46
|
}
|
|
49
47
|
}
|
|
50
|
-
|
|
51
48
|
if (super.componentDidUpdate) {
|
|
52
49
|
super.componentDidUpdate(prevProps, prevState, prevContext);
|
|
53
50
|
}
|
|
54
51
|
}
|
|
55
|
-
|
|
56
52
|
};
|
|
57
53
|
});
|
|
58
|
-
|
|
59
54
|
function warnExperimentalProps(name, props, experimentalProps) {
|
|
60
55
|
let message = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : '';
|
|
61
56
|
experimentalProps.forEach(experimentalProp => {
|
|
62
57
|
warn(typeof props[experimentalProp] === 'undefined', `[${name}] The \`${experimentalProp}\` prop is experimental and its API could change significantly in a future release. ${message}`);
|
|
63
58
|
});
|
|
64
59
|
}
|
|
65
|
-
|
|
66
60
|
function warnExperimentalComponent(name) {
|
|
67
61
|
let message = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : '';
|
|
68
62
|
warn(false, `[${name}] is experimental and its API could change significantly in a future release. ${message}`);
|
|
69
63
|
}
|
|
70
|
-
|
|
71
64
|
export default experimental;
|
|
72
65
|
export {
|
|
73
66
|
/**
|
package/es/getDisplayName.js
CHANGED
package/es/getElementType.js
CHANGED
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import { logWarn as warn } from '@instructure/console';
|
|
25
24
|
|
|
25
|
+
import { logWarn as warn } from '@instructure/console';
|
|
26
26
|
/**
|
|
27
27
|
* ---
|
|
28
28
|
* category: utilities/react
|
|
@@ -37,31 +37,25 @@ import { logWarn as warn } from '@instructure/console';
|
|
|
37
37
|
*/
|
|
38
38
|
function getElementType(Component, props, getDefault) {
|
|
39
39
|
var _Component$defaultPro, _Component$defaultPro2;
|
|
40
|
-
|
|
41
40
|
if (props.as && props.as !== ((_Component$defaultPro = Component.defaultProps) === null || _Component$defaultPro === void 0 ? void 0 : _Component$defaultPro.as)) {
|
|
42
41
|
return props.as;
|
|
43
42
|
}
|
|
44
|
-
|
|
45
43
|
if (typeof getDefault === 'function') {
|
|
46
44
|
return getDefault();
|
|
47
45
|
}
|
|
48
|
-
|
|
49
46
|
if (props.href) {
|
|
50
47
|
return 'a';
|
|
51
48
|
}
|
|
52
|
-
|
|
53
49
|
if (props.to) {
|
|
54
|
-
warn(
|
|
50
|
+
warn(
|
|
51
|
+
// if to prop is used without as
|
|
55
52
|
!props.as, `[${Component.displayName}] \`as\` prop should be provided when using \`to\``);
|
|
56
53
|
return 'a';
|
|
57
54
|
}
|
|
58
|
-
|
|
59
55
|
if (typeof props.onClick === 'function') {
|
|
60
56
|
return 'button';
|
|
61
57
|
}
|
|
62
|
-
|
|
63
58
|
return ((_Component$defaultPro2 = Component.defaultProps) === null || _Component$defaultPro2 === void 0 ? void 0 : _Component$defaultPro2.as) || 'span';
|
|
64
59
|
}
|
|
65
|
-
|
|
66
60
|
export default getElementType;
|
|
67
61
|
export { getElementType };
|
package/es/getInteraction.js
CHANGED
|
@@ -40,20 +40,22 @@
|
|
|
40
40
|
*/
|
|
41
41
|
export function getInteraction() {
|
|
42
42
|
let _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {},
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
_ref$props = _ref.props,
|
|
44
|
+
props = _ref$props === void 0 ? {} : _ref$props,
|
|
45
|
+
_ref$interactionTypes = _ref.interactionTypes,
|
|
46
|
+
interactionTypes = _ref$interactionTypes === void 0 ? ['disabled', 'readonly'] : _ref$interactionTypes;
|
|
48
47
|
const interaction = props.interaction,
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
disabled = props.disabled,
|
|
49
|
+
readOnly = props.readOnly;
|
|
51
50
|
|
|
52
|
-
|
|
53
|
-
|
|
51
|
+
// interaction is the source of truth when it is provided
|
|
52
|
+
if (interaction) return interaction;
|
|
54
53
|
|
|
54
|
+
// if there's no interaction specified, use disabled or readOnly if they are defined as props (note, disabled will win
|
|
55
|
+
// over readOnly if both are provided)
|
|
55
56
|
if (interactionTypes.includes('disabled') && disabled) return 'disabled';
|
|
56
|
-
if (interactionTypes.includes('readonly') && readOnly) return 'readonly';
|
|
57
|
+
if (interactionTypes.includes('readonly') && readOnly) return 'readonly';
|
|
57
58
|
|
|
59
|
+
// We were provided with nothing, use enabled by default
|
|
58
60
|
return 'enabled';
|
|
59
61
|
}
|
package/es/hack.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
import { decorator } from '@instructure/ui-decorator';
|
|
25
25
|
import { logWarn as warn } from '@instructure/console';
|
|
26
|
+
|
|
26
27
|
/**
|
|
27
28
|
* ---
|
|
28
29
|
* category: utilities/react
|
|
@@ -44,39 +45,32 @@ import { logWarn as warn } from '@instructure/console';
|
|
|
44
45
|
* @param {string} message
|
|
45
46
|
* @return {function} React component flagged as having hack props
|
|
46
47
|
*/
|
|
47
|
-
|
|
48
48
|
const hack = process.env.NODE_ENV == 'production' ? () => Component => Component : decorator((ComposedComponent, hackProps, message) => {
|
|
49
49
|
return class HackComponent extends ComposedComponent {
|
|
50
50
|
componentDidMount() {
|
|
51
51
|
if (hackProps) {
|
|
52
52
|
warnHackProps(ComposedComponent.name, this.props, hackProps, message);
|
|
53
53
|
}
|
|
54
|
-
|
|
55
54
|
if (super.componentDidMount) {
|
|
56
55
|
super.componentDidMount();
|
|
57
56
|
}
|
|
58
57
|
}
|
|
59
|
-
|
|
60
58
|
componentDidUpdate(prevProps, prevState, prevContext) {
|
|
61
59
|
if (hackProps) {
|
|
62
60
|
warnHackProps(ComposedComponent.name, this.props, hackProps, message);
|
|
63
61
|
}
|
|
64
|
-
|
|
65
62
|
if (super.componentDidUpdate) {
|
|
66
63
|
super.componentDidUpdate(prevProps, prevState, prevContext);
|
|
67
64
|
}
|
|
68
65
|
}
|
|
69
|
-
|
|
70
66
|
};
|
|
71
67
|
});
|
|
72
|
-
|
|
73
68
|
function warnHackProps(name, props, hackProps) {
|
|
74
69
|
let message = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : '';
|
|
75
70
|
hackProps.forEach(hackProp => {
|
|
76
71
|
warn(typeof props[hackProp] === 'undefined', `[${name}] The \`${hackProp}\` prop is a temporary hack and will be removed in a future release. ${message}`);
|
|
77
72
|
});
|
|
78
73
|
}
|
|
79
|
-
|
|
80
74
|
export default hack;
|
|
81
75
|
export {
|
|
82
76
|
/**
|
|
@@ -21,8 +21,8 @@
|
|
|
21
21
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
22
|
* SOFTWARE.
|
|
23
23
|
*/
|
|
24
|
-
import { getDisplayName } from './getDisplayName';
|
|
25
24
|
|
|
25
|
+
import { getDisplayName } from './getDisplayName';
|
|
26
26
|
/**
|
|
27
27
|
* ---
|
|
28
28
|
* category: utilities/react
|
|
@@ -37,7 +37,6 @@ import { getDisplayName } from './getDisplayName';
|
|
|
37
37
|
*/
|
|
38
38
|
function matchComponentTypes(componentInstance) {
|
|
39
39
|
let types = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
|
|
40
|
-
|
|
41
40
|
if (componentInstance && componentInstance.type) {
|
|
42
41
|
const displayNames = types.map(type => getDisplayName(type));
|
|
43
42
|
return displayNames.indexOf(getDisplayName(componentInstance.type)) >= 0;
|
|
@@ -45,6 +44,5 @@ function matchComponentTypes(componentInstance) {
|
|
|
45
44
|
return false;
|
|
46
45
|
}
|
|
47
46
|
}
|
|
48
|
-
|
|
49
47
|
export default matchComponentTypes;
|
|
50
48
|
export { matchComponentTypes };
|
package/es/omitProps.js
CHANGED
|
@@ -44,29 +44,22 @@ function omitProps(props, propsToOmit, exclude) {
|
|
|
44
44
|
const keysToOmit = exclude ? propKeys.concat(exclude) : propKeys;
|
|
45
45
|
return omit(props, keysToOmit);
|
|
46
46
|
}
|
|
47
|
-
|
|
48
47
|
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
49
|
-
|
|
50
48
|
const omit = (originalObject, keysToOmit) => {
|
|
51
49
|
// code based on babel's _objectWithoutProperties
|
|
52
50
|
const newObject = {};
|
|
53
|
-
|
|
54
51
|
for (const key in originalObject) {
|
|
55
52
|
// special case because we always want to omit these and === is faster than
|
|
56
53
|
// concat'ing them in
|
|
57
54
|
if (key === 'theme' || key === 'children' || key === 'className' || key === 'style' || key === 'styles' || key === 'makeStyles' || key === 'themeOverride' || key === 'deterministicId') {
|
|
58
55
|
continue;
|
|
59
56
|
}
|
|
60
|
-
|
|
61
57
|
if (keysToOmit.includes(key) || !hasOwnProperty.call(originalObject, key)) {
|
|
62
58
|
continue;
|
|
63
59
|
}
|
|
64
|
-
|
|
65
60
|
newObject[key] = originalObject[key];
|
|
66
61
|
}
|
|
67
|
-
|
|
68
62
|
return newObject;
|
|
69
63
|
};
|
|
70
|
-
|
|
71
64
|
export default omitProps;
|
|
72
65
|
export { omitProps };
|
package/es/passthroughProps.js
CHANGED
|
@@ -23,6 +23,7 @@
|
|
|
23
23
|
*/
|
|
24
24
|
// list of "valid" props https://github.com/emotion-js/emotion/blob/master/packages/is-prop-valid/src/props.js
|
|
25
25
|
import isPropValid from '@emotion/is-prop-valid';
|
|
26
|
+
|
|
26
27
|
/**
|
|
27
28
|
* Removes disallowed keys from the given object. Allowed keys: Valid props for
|
|
28
29
|
* HTML or SVG elements (see https://github.com/emotion-js/emotion/tree/main/packages/is-prop-valid)
|
|
@@ -31,16 +32,15 @@ import isPropValid from '@emotion/is-prop-valid';
|
|
|
31
32
|
* 'makeStyles', 'deterministicId'
|
|
32
33
|
* @param props The props to process
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
35
|
function passthroughProps(props) {
|
|
36
36
|
const validProps = {};
|
|
37
|
-
Object.keys(props)
|
|
37
|
+
Object.keys(props)
|
|
38
|
+
// style and className need to be explicitly passed through
|
|
38
39
|
// styles and makeStyle can not pass through
|
|
39
40
|
.filter(propName => isPropValid(propName) && propName !== 'style' && propName !== 'className' && propName !== 'children' && propName !== 'styles' && propName !== 'makeStyles' && propName !== 'deterministicId').forEach(propName => {
|
|
40
41
|
validProps[propName] = props[propName];
|
|
41
42
|
});
|
|
42
43
|
return validProps;
|
|
43
44
|
}
|
|
44
|
-
|
|
45
45
|
export { passthroughProps };
|
|
46
46
|
export default passthroughProps;
|
package/es/pickProps.js
CHANGED
|
@@ -38,25 +38,21 @@ function pickProps(props, propTypesOrAllowedPropList, include) {
|
|
|
38
38
|
const propKeys = Array.isArray(propTypesOrAllowedPropList) ? propTypesOrAllowedPropList : Object.keys(propTypesOrAllowedPropList || {});
|
|
39
39
|
const combined = include ? propKeys.concat(include) : propKeys;
|
|
40
40
|
return pick(props, combined);
|
|
41
|
-
}
|
|
42
|
-
|
|
41
|
+
}
|
|
43
42
|
|
|
43
|
+
// this was the fastest implementation from testing: https://jsperf.com/pick-props
|
|
44
44
|
function pick(obj, keys) {
|
|
45
45
|
const res = {};
|
|
46
46
|
const len = keys.length;
|
|
47
47
|
let idx = -1;
|
|
48
48
|
let key;
|
|
49
|
-
|
|
50
49
|
while (++idx < len) {
|
|
51
50
|
key = keys[idx];
|
|
52
|
-
|
|
53
51
|
if (key in obj) {
|
|
54
52
|
res[key] = obj[key];
|
|
55
53
|
}
|
|
56
54
|
}
|
|
57
|
-
|
|
58
55
|
return res;
|
|
59
56
|
}
|
|
60
|
-
|
|
61
57
|
export default pickProps;
|
|
62
58
|
export { pickProps };
|