@instructure/ui-react-utils 11.7.8 → 11.7.9-pr-snapshot-1792147648392
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 +13 -0
- package/es/DeterministicIdContext/DeterministicIdContext.js +2 -38
- package/es/DeterministicIdContext/DeterministicIdContextProvider.js +7 -46
- package/es/DeterministicIdContext/index.js +1 -25
- package/es/DeterministicIdContext/useDeterministicId.js +3 -65
- package/es/DeterministicIdContext/withDeterministicId.js +21 -65
- package/es/callRenderProp.js +7 -45
- package/es/ensureSingleChild.js +13 -53
- package/es/getDisplayName.js +2 -36
- package/es/getElementType.js +18 -68
- package/es/getInteraction.js +10 -56
- package/es/index.js +1 -26
- package/es/matchComponentTypes.js +7 -43
- package/es/omitProps.js +15 -60
- package/es/passthroughProps.js +6 -42
- package/es/pickProps.js +14 -52
- package/es/safeCloneElement.js +40 -89
- package/es/windowMessageListener.js +52 -96
- package/package.json +10 -13
- package/src/getDisplayName.ts +1 -1
- package/src/omitProps.ts +1 -1
- package/tsconfig.build.json +0 -3
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/getDisplayName.d.ts +1 -1
- package/lib/DeterministicIdContext/DeterministicIdContext.js +0 -47
- package/lib/DeterministicIdContext/DeterministicIdContextProvider.js +0 -54
- package/lib/DeterministicIdContext/index.js +0 -33
- package/lib/DeterministicIdContext/useDeterministicId.js +0 -74
- package/lib/DeterministicIdContext/withDeterministicId.js +0 -80
- package/lib/callRenderProp.js +0 -57
- package/lib/ensureSingleChild.js +0 -62
- package/lib/getDisplayName.js +0 -45
- package/lib/getElementType.js +0 -77
- package/lib/getInteraction.js +0 -62
- package/lib/index.js +0 -107
- package/lib/matchComponentTypes.js +0 -53
- package/lib/omitProps.js +0 -72
- package/lib/package.json +0 -1
- package/lib/passthroughProps.js +0 -53
- package/lib/pickProps.js +0 -64
- package/lib/safeCloneElement.js +0 -105
- package/lib/windowMessageListener.js +0 -110
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.withDeterministicId = exports.default = void 0;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
|
|
10
|
-
var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
|
|
11
|
-
var _useDeterministicId = require("./useDeterministicId.js");
|
|
12
|
-
var _console = require("@instructure/console");
|
|
13
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
14
|
-
/*
|
|
15
|
-
* The MIT License (MIT)
|
|
16
|
-
*
|
|
17
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
18
|
-
*
|
|
19
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
20
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
21
|
-
* in the Software without restriction, including without limitation the rights
|
|
22
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
23
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
24
|
-
* furnished to do so, subject to the following conditions:
|
|
25
|
-
*
|
|
26
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
27
|
-
* copies or substantial portions of the Software.
|
|
28
|
-
*
|
|
29
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
30
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
31
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
32
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
33
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
34
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
35
|
-
* SOFTWARE.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* This decorator injects a `deterministicId` prop into the decorated class,
|
|
40
|
-
* used to generate SSR-safe, hydration-stable ids.
|
|
41
|
-
*
|
|
42
|
-
* It is backed by React's built-in {@link https://react.dev/reference/react/useId `useId`},
|
|
43
|
-
* which produces the same id on the server and the client for a given position
|
|
44
|
-
* in the React tree The injected `deterministicId(instanceName?)` function may
|
|
45
|
-
* be called multiple times with distinct `instanceName` values to derive
|
|
46
|
-
* several unique, stable ids from the same component instance.
|
|
47
|
-
*
|
|
48
|
-
* Note: for apps that mount more than one independent React root on the same
|
|
49
|
-
* page (including module federation), pass a distinct `identifierPrefix` to each
|
|
50
|
-
* `createRoot`/`hydrateRoot` call so ids stay unique across roots.
|
|
51
|
-
* Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
|
|
52
|
-
*/
|
|
53
|
-
const withDeterministicId = exports.withDeterministicId = (0, _decorator.decorator)(ComposedComponent => {
|
|
54
|
-
const WithDeterministicId = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
55
|
-
const componentName = ComposedComponent.componentId || ComposedComponent.displayName || ComposedComponent.name;
|
|
56
|
-
const deterministicId = (0, _useDeterministicId.useDeterministicId)(componentName);
|
|
57
|
-
if (props.deterministicId) {
|
|
58
|
-
(0, _console.warn)(false, `Manually passing the "deterministicId" property is not allowed on the ${componentName} component.\n`, props.deterministicId);
|
|
59
|
-
}
|
|
60
|
-
return (0, _jsxRuntime.jsx)(ComposedComponent, {
|
|
61
|
-
ref: ref,
|
|
62
|
-
deterministicId: deterministicId,
|
|
63
|
-
...props
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
(0, _hoistNonReactStatics.default)(WithDeterministicId, ComposedComponent);
|
|
67
|
-
|
|
68
|
-
// These static fields exist on InstUI components
|
|
69
|
-
//@ts-expect-error fix this
|
|
70
|
-
WithDeterministicId.allowedProps = ComposedComponent.allowedProps;
|
|
71
|
-
|
|
72
|
-
// added so it can be tested with ReactTestUtils
|
|
73
|
-
// more info: https://github.com/facebook/react/issues/13455
|
|
74
|
-
WithDeterministicId.originalType = ComposedComponent.originalType || ComposedComponent;
|
|
75
|
-
if (typeof process !== 'undefined' && process?.env?.NODE_ENV !== 'production') {
|
|
76
|
-
WithDeterministicId.displayName = `WithDeterministicId(${ComposedComponent.displayName})`;
|
|
77
|
-
}
|
|
78
|
-
return WithDeterministicId;
|
|
79
|
-
});
|
|
80
|
-
var _default = exports.default = withDeterministicId;
|
package/lib/callRenderProp.js
DELETED
|
@@ -1,57 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.callRenderProp = callRenderProp;
|
|
8
|
-
exports.default = void 0;
|
|
9
|
-
var _react = _interopRequireDefault(require("react"));
|
|
10
|
-
/*
|
|
11
|
-
* The MIT License (MIT)
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
14
|
-
*
|
|
15
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
-
* in the Software without restriction, including without limitation the rights
|
|
18
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
-
* furnished to do so, subject to the following conditions:
|
|
21
|
-
*
|
|
22
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
-
* copies or substantial portions of the Software.
|
|
24
|
-
*
|
|
25
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
-
* SOFTWARE.
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* ---
|
|
36
|
-
* category: utilities/react
|
|
37
|
-
* ---
|
|
38
|
-
* Evaluate a provided value to create a renderable React element.
|
|
39
|
-
* @module callRenderProp
|
|
40
|
-
* @param value
|
|
41
|
-
* @param props
|
|
42
|
-
*/
|
|
43
|
-
function callRenderProp(value, props = {}) {
|
|
44
|
-
if (typeof value === 'function') {
|
|
45
|
-
// In react 16, `createElement` accepts a function. In react 15 we get an
|
|
46
|
-
// error on rendering the result. Evaluate the function here if it is not a
|
|
47
|
-
// react component.
|
|
48
|
-
// fat arrow functions don't have a prototype
|
|
49
|
-
if (!(value.prototype && value.prototype.isReactComponent)) {
|
|
50
|
-
return value(props);
|
|
51
|
-
}
|
|
52
|
-
// TODO type 'value' properly
|
|
53
|
-
return /*#__PURE__*/_react.default.createElement(value, props);
|
|
54
|
-
}
|
|
55
|
-
return value;
|
|
56
|
-
}
|
|
57
|
-
var _default = exports.default = callRenderProp;
|
package/lib/ensureSingleChild.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
exports.ensureSingleChild = ensureSingleChild;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _safeCloneElement = require("./safeCloneElement.js");
|
|
10
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
11
|
-
/*
|
|
12
|
-
* The MIT License (MIT)
|
|
13
|
-
*
|
|
14
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
15
|
-
*
|
|
16
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
17
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
18
|
-
* in the Software without restriction, including without limitation the rights
|
|
19
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
20
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
21
|
-
* furnished to do so, subject to the following conditions:
|
|
22
|
-
*
|
|
23
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
24
|
-
* copies or substantial portions of the Software.
|
|
25
|
-
*
|
|
26
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
27
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
28
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
29
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
30
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
31
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
32
|
-
* SOFTWARE.
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* ---
|
|
37
|
-
* category: utilities/react
|
|
38
|
-
* ---
|
|
39
|
-
*
|
|
40
|
-
* Ensure a single child. If it is a child of length 1, return a
|
|
41
|
-
* cloned instance of the child. If it is a child of length > 1,
|
|
42
|
-
* wrap in a span and return the child. Return null if child has
|
|
43
|
-
* no length.
|
|
44
|
-
* @module ensureSingleChild
|
|
45
|
-
* @param child
|
|
46
|
-
* @param props props for child
|
|
47
|
-
* @returns cloned instance for a single child, or children wrapped in a span
|
|
48
|
-
*/function ensureSingleChild(child, props = {}) {
|
|
49
|
-
const childCount = _react.Children.count(child);
|
|
50
|
-
if (childCount === 0) {
|
|
51
|
-
return null;
|
|
52
|
-
} else if (typeof child === 'string' && child.length > 0 || childCount > 1) {
|
|
53
|
-
return (0, _jsxRuntime.jsx)("span", {
|
|
54
|
-
...props,
|
|
55
|
-
children: child
|
|
56
|
-
});
|
|
57
|
-
} else {
|
|
58
|
-
// TODO: check that we can only end up here if child is ReactElement
|
|
59
|
-
return (0, _safeCloneElement.safeCloneElement)(Array.isArray(child) ? child[0] : child, props);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
var _default = exports.default = ensureSingleChild;
|
package/lib/getDisplayName.js
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
exports.getDisplayName = getDisplayName;
|
|
8
|
-
/*
|
|
9
|
-
* The MIT License (MIT)
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
-
* furnished to do so, subject to the following conditions:
|
|
19
|
-
*
|
|
20
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
-
* copies or substantial portions of the Software.
|
|
22
|
-
*
|
|
23
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
-
* SOFTWARE.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* ---
|
|
34
|
-
* category: utilities/react
|
|
35
|
-
* ---
|
|
36
|
-
* Get the displayName of a React component.
|
|
37
|
-
* needs a babel plugin to work https://github.com/facebook/react/issues/4915 !!
|
|
38
|
-
* @module getDisplayName
|
|
39
|
-
* @param ReactComponent
|
|
40
|
-
* @returns the component displayName
|
|
41
|
-
*/
|
|
42
|
-
function getDisplayName(ReactComponent) {
|
|
43
|
-
return typeof ReactComponent === 'string' ? ReactComponent : ReactComponent.displayName || ReactComponent.name;
|
|
44
|
-
}
|
|
45
|
-
var _default = exports.default = getDisplayName;
|
package/lib/getElementType.js
DELETED
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
exports.getElementType = getElementType;
|
|
8
|
-
var _console = require("@instructure/console");
|
|
9
|
-
/*
|
|
10
|
-
* The MIT License (MIT)
|
|
11
|
-
*
|
|
12
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
13
|
-
*
|
|
14
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
16
|
-
* in the Software without restriction, including without limitation the rights
|
|
17
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
19
|
-
* furnished to do so, subject to the following conditions:
|
|
20
|
-
*
|
|
21
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
22
|
-
* copies or substantial portions of the Software.
|
|
23
|
-
*
|
|
24
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
-
* SOFTWARE.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* A props object that is searched for some fields to determine the
|
|
35
|
-
* element's type.
|
|
36
|
-
*/
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* ---
|
|
40
|
-
* category: utilities/react
|
|
41
|
-
* ---
|
|
42
|
-
* Get the React element type for a component. It uses the following logic:
|
|
43
|
-
* 1. type defined by the `as` prop
|
|
44
|
-
* 2. type returned by the `getDefault()` parameter
|
|
45
|
-
* 3. `<a>` if it has a `href` or `to` prop
|
|
46
|
-
* 4. `<button>` if it has an `onClick` prop
|
|
47
|
-
* 5. the component's defaultProp's `as` field
|
|
48
|
-
* 6. `<span>` if none of the above
|
|
49
|
-
*
|
|
50
|
-
* @module getElementType
|
|
51
|
-
* @param Component
|
|
52
|
-
* @param props
|
|
53
|
-
* @param getDefault an optional function that returns the default element type
|
|
54
|
-
* @returns the element type
|
|
55
|
-
*/
|
|
56
|
-
function getElementType(Component, props, getDefault) {
|
|
57
|
-
if (props.as && props.as !== Component.defaultProps?.as) {
|
|
58
|
-
return props.as;
|
|
59
|
-
}
|
|
60
|
-
if (typeof getDefault === 'function') {
|
|
61
|
-
return getDefault();
|
|
62
|
-
}
|
|
63
|
-
if (props.href) {
|
|
64
|
-
return 'a';
|
|
65
|
-
}
|
|
66
|
-
if (props.to) {
|
|
67
|
-
(0, _console.logWarn)(
|
|
68
|
-
// if to prop is used without as
|
|
69
|
-
!props.as, `[${Component.displayName}] \`as\` prop should be provided when using \`to\``);
|
|
70
|
-
return 'a';
|
|
71
|
-
}
|
|
72
|
-
if (typeof props.onClick === 'function') {
|
|
73
|
-
return 'button';
|
|
74
|
-
}
|
|
75
|
-
return Component.defaultProps?.as || 'span';
|
|
76
|
-
}
|
|
77
|
-
var _default = exports.default = getElementType;
|
package/lib/getInteraction.js
DELETED
|
@@ -1,62 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getInteraction = getInteraction;
|
|
7
|
-
/*
|
|
8
|
-
* The MIT License (MIT)
|
|
9
|
-
*
|
|
10
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
11
|
-
*
|
|
12
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
13
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
14
|
-
* in the Software without restriction, including without limitation the rights
|
|
15
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
16
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
17
|
-
* furnished to do so, subject to the following conditions:
|
|
18
|
-
*
|
|
19
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
20
|
-
* copies or substantial portions of the Software.
|
|
21
|
-
*
|
|
22
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
23
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
24
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
25
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
26
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
27
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
28
|
-
* SOFTWARE.
|
|
29
|
-
*/
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* ---
|
|
33
|
-
* category: utilities/react
|
|
34
|
-
* ---
|
|
35
|
-
* Parse the component props for the interaction type. It will return one of 'enabled', 'disabled', or 'readonly'.
|
|
36
|
-
* This is useful for form elements where consumers are able to either use the interaction prop as specified or the
|
|
37
|
-
* native html disabled or readonly attributes
|
|
38
|
-
* @module getInteraction
|
|
39
|
-
* @param args extra arguments
|
|
40
|
-
* @returns The calculated interaction type
|
|
41
|
-
*/
|
|
42
|
-
function getInteraction({
|
|
43
|
-
props = {},
|
|
44
|
-
interactionTypes = ['disabled', 'readonly']
|
|
45
|
-
} = {}) {
|
|
46
|
-
const {
|
|
47
|
-
interaction,
|
|
48
|
-
disabled,
|
|
49
|
-
readOnly
|
|
50
|
-
} = props;
|
|
51
|
-
|
|
52
|
-
// interaction is the source of truth when it is provided
|
|
53
|
-
if (interaction) return interaction;
|
|
54
|
-
|
|
55
|
-
// if there's no interaction specified, use disabled or readOnly if they are defined as props (note, disabled will win
|
|
56
|
-
// over readOnly if both are provided)
|
|
57
|
-
if (interactionTypes.includes('disabled') && disabled) return 'disabled';
|
|
58
|
-
if (interactionTypes.includes('readonly') && readOnly) return 'readonly';
|
|
59
|
-
|
|
60
|
-
// We were provided with nothing, use enabled by default
|
|
61
|
-
return 'enabled';
|
|
62
|
-
}
|
package/lib/index.js
DELETED
|
@@ -1,107 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
Object.defineProperty(exports, "DeterministicIdContext", {
|
|
7
|
-
enumerable: true,
|
|
8
|
-
get: function () {
|
|
9
|
-
return _index.DeterministicIdContext;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "DeterministicIdContextProvider", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _index.DeterministicIdContextProvider;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "callRenderProp", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _callRenderProp.callRenderProp;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "ensureSingleChild", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _ensureSingleChild.ensureSingleChild;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
Object.defineProperty(exports, "getDisplayName", {
|
|
31
|
-
enumerable: true,
|
|
32
|
-
get: function () {
|
|
33
|
-
return _getDisplayName.getDisplayName;
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
|
-
Object.defineProperty(exports, "getElementType", {
|
|
37
|
-
enumerable: true,
|
|
38
|
-
get: function () {
|
|
39
|
-
return _getElementType.getElementType;
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
Object.defineProperty(exports, "getInteraction", {
|
|
43
|
-
enumerable: true,
|
|
44
|
-
get: function () {
|
|
45
|
-
return _getInteraction.getInteraction;
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
Object.defineProperty(exports, "matchComponentTypes", {
|
|
49
|
-
enumerable: true,
|
|
50
|
-
get: function () {
|
|
51
|
-
return _matchComponentTypes.matchComponentTypes;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
Object.defineProperty(exports, "omitProps", {
|
|
55
|
-
enumerable: true,
|
|
56
|
-
get: function () {
|
|
57
|
-
return _omitProps.omitProps;
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
Object.defineProperty(exports, "passthroughProps", {
|
|
61
|
-
enumerable: true,
|
|
62
|
-
get: function () {
|
|
63
|
-
return _passthroughProps.passthroughProps;
|
|
64
|
-
}
|
|
65
|
-
});
|
|
66
|
-
Object.defineProperty(exports, "pickProps", {
|
|
67
|
-
enumerable: true,
|
|
68
|
-
get: function () {
|
|
69
|
-
return _pickProps.pickProps;
|
|
70
|
-
}
|
|
71
|
-
});
|
|
72
|
-
Object.defineProperty(exports, "safeCloneElement", {
|
|
73
|
-
enumerable: true,
|
|
74
|
-
get: function () {
|
|
75
|
-
return _safeCloneElement.safeCloneElement;
|
|
76
|
-
}
|
|
77
|
-
});
|
|
78
|
-
Object.defineProperty(exports, "useDeterministicId", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function () {
|
|
81
|
-
return _index.useDeterministicId;
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
Object.defineProperty(exports, "windowMessageListener", {
|
|
85
|
-
enumerable: true,
|
|
86
|
-
get: function () {
|
|
87
|
-
return _windowMessageListener.windowMessageListener;
|
|
88
|
-
}
|
|
89
|
-
});
|
|
90
|
-
Object.defineProperty(exports, "withDeterministicId", {
|
|
91
|
-
enumerable: true,
|
|
92
|
-
get: function () {
|
|
93
|
-
return _index.withDeterministicId;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
var _callRenderProp = require("./callRenderProp.js");
|
|
97
|
-
var _ensureSingleChild = require("./ensureSingleChild.js");
|
|
98
|
-
var _getDisplayName = require("./getDisplayName.js");
|
|
99
|
-
var _getElementType = require("./getElementType.js");
|
|
100
|
-
var _getInteraction = require("./getInteraction.js");
|
|
101
|
-
var _matchComponentTypes = require("./matchComponentTypes.js");
|
|
102
|
-
var _omitProps = require("./omitProps.js");
|
|
103
|
-
var _passthroughProps = require("./passthroughProps.js");
|
|
104
|
-
var _pickProps = require("./pickProps.js");
|
|
105
|
-
var _safeCloneElement = require("./safeCloneElement.js");
|
|
106
|
-
var _windowMessageListener = require("./windowMessageListener.js");
|
|
107
|
-
var _index = require("./DeterministicIdContext/index.js");
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
exports.matchComponentTypes = matchComponentTypes;
|
|
8
|
-
var _getDisplayName = require("./getDisplayName.js");
|
|
9
|
-
/*
|
|
10
|
-
* The MIT License (MIT)
|
|
11
|
-
*
|
|
12
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
13
|
-
*
|
|
14
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
15
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
16
|
-
* in the Software without restriction, including without limitation the rights
|
|
17
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
18
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
19
|
-
* furnished to do so, subject to the following conditions:
|
|
20
|
-
*
|
|
21
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
22
|
-
* copies or substantial portions of the Software.
|
|
23
|
-
*
|
|
24
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
25
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
26
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
27
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
28
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
29
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
30
|
-
* SOFTWARE.
|
|
31
|
-
*/
|
|
32
|
-
|
|
33
|
-
/**
|
|
34
|
-
* ---
|
|
35
|
-
* category: utilities/react
|
|
36
|
-
* ---
|
|
37
|
-
* Check if a React component instance (React element) matches one of the
|
|
38
|
-
* specified types.
|
|
39
|
-
*
|
|
40
|
-
* @module matchComponentTypes
|
|
41
|
-
* @param componentInstance
|
|
42
|
-
* @param types an array of React components
|
|
43
|
-
* @returns true if the component matches at least one of the types
|
|
44
|
-
*/
|
|
45
|
-
function matchComponentTypes(componentInstance, types = []) {
|
|
46
|
-
if (componentInstance && componentInstance.type) {
|
|
47
|
-
const displayNames = types.map(type => (0, _getDisplayName.getDisplayName)(type));
|
|
48
|
-
return displayNames.indexOf((0, _getDisplayName.getDisplayName)(componentInstance.type)) >= 0;
|
|
49
|
-
} else {
|
|
50
|
-
return false;
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
var _default = exports.default = matchComponentTypes;
|
package/lib/omitProps.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
exports.omitProps = omitProps;
|
|
8
|
-
/*
|
|
9
|
-
* The MIT License (MIT)
|
|
10
|
-
*
|
|
11
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
12
|
-
*
|
|
13
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
14
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
15
|
-
* in the Software without restriction, including without limitation the rights
|
|
16
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
17
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
18
|
-
* furnished to do so, subject to the following conditions:
|
|
19
|
-
*
|
|
20
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
21
|
-
* copies or substantial portions of the Software.
|
|
22
|
-
*
|
|
23
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
24
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
25
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
26
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
27
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
28
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
29
|
-
* SOFTWARE.
|
|
30
|
-
*/
|
|
31
|
-
|
|
32
|
-
/**
|
|
33
|
-
* ---
|
|
34
|
-
* category: utilities/react
|
|
35
|
-
* ---
|
|
36
|
-
* Return an object with the remaining props after the given props are omitted.
|
|
37
|
-
*
|
|
38
|
-
* Automatically excludes the following props:
|
|
39
|
-
* `theme`, `children`, `className`, `style`, `styles`, `makeStyles`,
|
|
40
|
-
* `themeOverride`, `deterministicId`
|
|
41
|
-
* @module omitProps
|
|
42
|
-
* @param props The object to process
|
|
43
|
-
* @param propsToOmit list disallowed prop keys or an object whose
|
|
44
|
-
* keys will be omitted. If not specified the automatically excluded
|
|
45
|
-
* props will be removed.
|
|
46
|
-
* @param exclude an optional array of disallowed prop names to omit
|
|
47
|
-
* @returns props object without the excluded props
|
|
48
|
-
* @module omitProps
|
|
49
|
-
*/
|
|
50
|
-
function omitProps(props, propsToOmit, exclude) {
|
|
51
|
-
const propKeys = Array.isArray(propsToOmit) ? propsToOmit : Object.keys(propsToOmit || {});
|
|
52
|
-
const keysToOmit = exclude ? propKeys.concat(exclude) : propKeys;
|
|
53
|
-
return omit(props, keysToOmit);
|
|
54
|
-
}
|
|
55
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
56
|
-
const omit = (originalObject, keysToOmit) => {
|
|
57
|
-
// code based on babel's _objectWithoutProperties
|
|
58
|
-
const newObject = {};
|
|
59
|
-
for (const key in originalObject) {
|
|
60
|
-
// special case because we always want to omit these and === is faster than
|
|
61
|
-
// concat'ing them in
|
|
62
|
-
if (key === 'theme' || key === 'children' || key === 'className' || key === 'style' || key === 'styles' || key === 'makeStyles' || key === 'themeOverride' || key === 'deterministicId') {
|
|
63
|
-
continue;
|
|
64
|
-
}
|
|
65
|
-
if (keysToOmit.includes(key) || !hasOwnProperty.call(originalObject, key)) {
|
|
66
|
-
continue;
|
|
67
|
-
}
|
|
68
|
-
newObject[key] = originalObject[key];
|
|
69
|
-
}
|
|
70
|
-
return newObject;
|
|
71
|
-
};
|
|
72
|
-
var _default = exports.default = omitProps;
|
package/lib/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|
package/lib/passthroughProps.js
DELETED
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
|
|
4
|
-
Object.defineProperty(exports, "__esModule", {
|
|
5
|
-
value: true
|
|
6
|
-
});
|
|
7
|
-
exports.default = void 0;
|
|
8
|
-
exports.passthroughProps = passthroughProps;
|
|
9
|
-
var _isPropValid = _interopRequireDefault(require("@emotion/is-prop-valid"));
|
|
10
|
-
/*
|
|
11
|
-
* The MIT License (MIT)
|
|
12
|
-
*
|
|
13
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
14
|
-
*
|
|
15
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
16
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
17
|
-
* in the Software without restriction, including without limitation the rights
|
|
18
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
19
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
20
|
-
* furnished to do so, subject to the following conditions:
|
|
21
|
-
*
|
|
22
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
23
|
-
* copies or substantial portions of the Software.
|
|
24
|
-
*
|
|
25
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
26
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
27
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
28
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
29
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
30
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
31
|
-
* SOFTWARE.
|
|
32
|
-
*/
|
|
33
|
-
// list of "valid" props https://github.com/emotion-js/emotion/blob/master/packages/is-prop-valid/src/props.js
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Removes disallowed keys from the given object. Allowed keys: Valid props for
|
|
37
|
-
* HTML or SVG elements (see https://github.com/emotion-js/emotion/tree/main/packages/is-prop-valid)
|
|
38
|
-
*
|
|
39
|
-
* Disallowed is anything else and 'style', 'styles', 'className', 'children',
|
|
40
|
-
* 'makeStyles', 'deterministicId'
|
|
41
|
-
* @param props The props to process
|
|
42
|
-
*/
|
|
43
|
-
function passthroughProps(props) {
|
|
44
|
-
const validProps = {};
|
|
45
|
-
Object.keys(props)
|
|
46
|
-
// style and className need to be explicitly passed through
|
|
47
|
-
// styles and makeStyle can not pass through
|
|
48
|
-
.filter(propName => (0, _isPropValid.default)(propName) && propName !== 'style' && propName !== 'className' && propName !== 'children' && propName !== 'styles' && propName !== 'makeStyles' && propName !== 'deterministicId').forEach(propName => {
|
|
49
|
-
validProps[propName] = props[propName];
|
|
50
|
-
});
|
|
51
|
-
return validProps;
|
|
52
|
-
}
|
|
53
|
-
var _default = exports.default = passthroughProps;
|