@instructure/ui-react-utils 11.7.3 → 11.7.4-pr-snapshot-1781695314229
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 +8 -0
- package/LICENSE.md +1 -0
- package/{lib/getDisplayName.js → babel.config.cjs} +11 -20
- package/es/DeterministicIdContext/DeterministicIdContext.js +0 -2
- package/es/DeterministicIdContext/DeterministicIdContextProvider.js +2 -1
- package/es/DeterministicIdContext/index.js +5 -4
- package/es/DeterministicIdContext/useDeterministicId.js +2 -1
- package/es/DeterministicIdContext/withDeterministicId.js +1 -1
- package/es/ensureSingleChild.js +2 -1
- package/es/getInteraction.js +0 -1
- package/es/index.js +13 -12
- package/es/matchComponentTypes.js +2 -1
- package/es/omitProps.js +0 -1
- package/package.json +9 -11
- package/src/DeterministicIdContext/DeterministicIdContext.ts +0 -1
- package/src/DeterministicIdContext/DeterministicIdContextProvider.tsx +1 -1
- package/src/DeterministicIdContext/index.ts +4 -4
- package/src/DeterministicIdContext/useDeterministicId.tsx +1 -1
- package/src/DeterministicIdContext/withDeterministicId.tsx +1 -1
- package/src/ensureSingleChild.tsx +1 -1
- package/src/index.ts +12 -12
- package/src/matchComponentTypes.ts +1 -1
- package/tsconfig.build.tsbuildinfo +1 -1
- package/types/DeterministicIdContext/DeterministicIdContext.d.ts.map +1 -1
- package/types/DeterministicIdContext/index.d.ts +4 -4
- package/types/DeterministicIdContext/index.d.ts.map +1 -1
- package/types/index.d.ts +12 -12
- package/types/index.d.ts.map +1 -1
- package/lib/DeterministicIdContext/DeterministicIdContext.js +0 -52
- package/lib/DeterministicIdContext/DeterministicIdContextProvider.js +0 -54
- package/lib/DeterministicIdContext/index.js +0 -33
- package/lib/DeterministicIdContext/useDeterministicId.js +0 -66
- package/lib/DeterministicIdContext/withDeterministicId.js +0 -75
- package/lib/callRenderProp.js +0 -57
- package/lib/ensureSingleChild.js +0 -62
- package/lib/getElementType.js +0 -77
- package/lib/getInteraction.js +0 -63
- package/lib/index.js +0 -107
- package/lib/matchComponentTypes.js +0 -53
- package/lib/omitProps.js +0 -73
- 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,33 +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 _DeterministicIdContext.DeterministicIdContext;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "DeterministicIdContextProvider", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _DeterministicIdContextProvider.DeterministicIdContextProvider;
|
|
16
|
-
}
|
|
17
|
-
});
|
|
18
|
-
Object.defineProperty(exports, "useDeterministicId", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _useDeterministicId.useDeterministicId;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "withDeterministicId", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _withDeterministicId.withDeterministicId;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
|
-
var _DeterministicIdContextProvider = require("./DeterministicIdContextProvider");
|
|
31
|
-
var _DeterministicIdContext = require("./DeterministicIdContext");
|
|
32
|
-
var _withDeterministicId = require("./withDeterministicId");
|
|
33
|
-
var _useDeterministicId = require("./useDeterministicId");
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.default = void 0;
|
|
7
|
-
exports.useDeterministicId = useDeterministicId;
|
|
8
|
-
var _react = require("react");
|
|
9
|
-
var _generateId = require("@instructure/ui-utils/lib/generateId.js");
|
|
10
|
-
var _DeterministicIdContext = require("./DeterministicIdContext");
|
|
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
|
-
* A React hook that provides deterministic ID generation for functional components.
|
|
37
|
-
*
|
|
38
|
-
* This hook is the functional component equivalent of the `withDeterministicId` decorator.
|
|
39
|
-
* It uses the `DeterministicIdContext` which is needed for deterministic id generation.
|
|
40
|
-
*
|
|
41
|
-
* The context is there for the users to pass an `instanceCounterMap` Map which is then used
|
|
42
|
-
* in the child components to deterministically create ids for them based on the `instanceCounterMap`.
|
|
43
|
-
* Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
|
|
44
|
-
*
|
|
45
|
-
* @param componentName - Optional component name to use as the ID prefix.
|
|
46
|
-
* @returns A function that generates deterministic IDs. The function accepts an optional instanceName parameter.
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```tsx
|
|
50
|
-
* const MyComponent = () => {
|
|
51
|
-
* const [deterministicId, setDeterministicId] = useState()
|
|
52
|
-
* const getId = useDeterministicId('MyComponent')
|
|
53
|
-
* useEffect(() => {
|
|
54
|
-
* setDeterministicId(getId())
|
|
55
|
-
* }, [])
|
|
56
|
-
* return <div id={deterministicId}>Content</div>
|
|
57
|
-
* }
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
60
|
-
function useDeterministicId(componentName) {
|
|
61
|
-
const instanceCounterMap = (0, _react.useContext)(_DeterministicIdContext.DeterministicIdContext);
|
|
62
|
-
return (instanceName = componentName) => {
|
|
63
|
-
return (0, _generateId.generateId)(instanceName, instanceCounterMap);
|
|
64
|
-
};
|
|
65
|
-
}
|
|
66
|
-
var _default = exports.default = useDeterministicId;
|
|
@@ -1,75 +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 _DeterministicIdContext = require("./DeterministicIdContext");
|
|
11
|
-
var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
|
|
12
|
-
var _generateId = require("@instructure/ui-utils/lib/generateId.js");
|
|
13
|
-
var _console = require("@instructure/console");
|
|
14
|
-
var _jsxRuntime = require("@emotion/react/jsx-runtime");
|
|
15
|
-
/*
|
|
16
|
-
* The MIT License (MIT)
|
|
17
|
-
*
|
|
18
|
-
* Copyright (c) 2015 - present Instructure, Inc.
|
|
19
|
-
*
|
|
20
|
-
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
21
|
-
* of this software and associated documentation files (the "Software"), to deal
|
|
22
|
-
* in the Software without restriction, including without limitation the rights
|
|
23
|
-
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
24
|
-
* copies of the Software, and to permit persons to whom the Software is
|
|
25
|
-
* furnished to do so, subject to the following conditions:
|
|
26
|
-
*
|
|
27
|
-
* The above copyright notice and this permission notice shall be included in all
|
|
28
|
-
* copies or substantial portions of the Software.
|
|
29
|
-
*
|
|
30
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
31
|
-
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
32
|
-
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
33
|
-
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
34
|
-
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
35
|
-
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
36
|
-
* SOFTWARE.
|
|
37
|
-
*/
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* This decorator is used to enable the decorated class to use the `DeterministicIdContext` which is needed
|
|
41
|
-
* for deterministic id generation.
|
|
42
|
-
*
|
|
43
|
-
* The context is there for the users to pass an `instanceCounterMap` Map which is then used
|
|
44
|
-
* in the child components to deterministically create ids for them based on the `instanceCounterMap`.
|
|
45
|
-
* Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
|
|
46
|
-
*/
|
|
47
|
-
const withDeterministicId = exports.withDeterministicId = (0, _decorator.decorator)(ComposedComponent => {
|
|
48
|
-
const WithDeterministicId = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
|
|
49
|
-
const componentName = ComposedComponent.componentId || ComposedComponent.displayName || ComposedComponent.name;
|
|
50
|
-
const instanceCounterMap = (0, _react.useContext)(_DeterministicIdContext.DeterministicIdContext);
|
|
51
|
-
const deterministicId = (instanceName = componentName) => (0, _generateId.generateId)(instanceName, instanceCounterMap);
|
|
52
|
-
if (props.deterministicId) {
|
|
53
|
-
(0, _console.warn)(false, `Manually passing the "deterministicId" property is not allowed on the ${componentName} component.\n`, props.deterministicId);
|
|
54
|
-
}
|
|
55
|
-
return (0, _jsxRuntime.jsx)(ComposedComponent, {
|
|
56
|
-
ref: ref,
|
|
57
|
-
deterministicId: deterministicId,
|
|
58
|
-
...props
|
|
59
|
-
});
|
|
60
|
-
});
|
|
61
|
-
(0, _hoistNonReactStatics.default)(WithDeterministicId, ComposedComponent);
|
|
62
|
-
|
|
63
|
-
// These static fields exist on InstUI components
|
|
64
|
-
//@ts-expect-error fix this
|
|
65
|
-
WithDeterministicId.allowedProps = ComposedComponent.allowedProps;
|
|
66
|
-
|
|
67
|
-
// added so it can be tested with ReactTestUtils
|
|
68
|
-
// more info: https://github.com/facebook/react/issues/13455
|
|
69
|
-
WithDeterministicId.originalType = ComposedComponent.originalType || ComposedComponent;
|
|
70
|
-
if (typeof process !== 'undefined' && process?.env?.NODE_ENV !== 'production') {
|
|
71
|
-
WithDeterministicId.displayName = `WithDeterministicId(${ComposedComponent.displayName})`;
|
|
72
|
-
}
|
|
73
|
-
return WithDeterministicId;
|
|
74
|
-
});
|
|
75
|
-
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");
|
|
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/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,63 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.getInteraction = getInteraction;
|
|
7
|
-
require("core-js/modules/es.array.includes.js");
|
|
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
|
-
* Parse the component props for the interaction type. It will return one of 'enabled', 'disabled', or 'readonly'.
|
|
37
|
-
* This is useful for form elements where consumers are able to either use the interaction prop as specified or the
|
|
38
|
-
* native html disabled or readonly attributes
|
|
39
|
-
* @module getInteraction
|
|
40
|
-
* @param args extra arguments
|
|
41
|
-
* @returns The calculated interaction type
|
|
42
|
-
*/
|
|
43
|
-
function getInteraction({
|
|
44
|
-
props = {},
|
|
45
|
-
interactionTypes = ['disabled', 'readonly']
|
|
46
|
-
} = {}) {
|
|
47
|
-
const {
|
|
48
|
-
interaction,
|
|
49
|
-
disabled,
|
|
50
|
-
readOnly
|
|
51
|
-
} = props;
|
|
52
|
-
|
|
53
|
-
// interaction is the source of truth when it is provided
|
|
54
|
-
if (interaction) return interaction;
|
|
55
|
-
|
|
56
|
-
// if there's no interaction specified, use disabled or readOnly if they are defined as props (note, disabled will win
|
|
57
|
-
// over readOnly if both are provided)
|
|
58
|
-
if (interactionTypes.includes('disabled') && disabled) return 'disabled';
|
|
59
|
-
if (interactionTypes.includes('readonly') && readOnly) return 'readonly';
|
|
60
|
-
|
|
61
|
-
// We were provided with nothing, use enabled by default
|
|
62
|
-
return 'enabled';
|
|
63
|
-
}
|
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 _DeterministicIdContext.DeterministicIdContext;
|
|
10
|
-
}
|
|
11
|
-
});
|
|
12
|
-
Object.defineProperty(exports, "DeterministicIdContextProvider", {
|
|
13
|
-
enumerable: true,
|
|
14
|
-
get: function () {
|
|
15
|
-
return _DeterministicIdContext.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 _DeterministicIdContext.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 _DeterministicIdContext.withDeterministicId;
|
|
94
|
-
}
|
|
95
|
-
});
|
|
96
|
-
var _callRenderProp = require("./callRenderProp");
|
|
97
|
-
var _ensureSingleChild = require("./ensureSingleChild");
|
|
98
|
-
var _getDisplayName = require("./getDisplayName");
|
|
99
|
-
var _getElementType = require("./getElementType");
|
|
100
|
-
var _getInteraction = require("./getInteraction");
|
|
101
|
-
var _matchComponentTypes = require("./matchComponentTypes");
|
|
102
|
-
var _omitProps = require("./omitProps");
|
|
103
|
-
var _passthroughProps = require("./passthroughProps");
|
|
104
|
-
var _pickProps = require("./pickProps");
|
|
105
|
-
var _safeCloneElement = require("./safeCloneElement");
|
|
106
|
-
var _windowMessageListener = require("./windowMessageListener");
|
|
107
|
-
var _DeterministicIdContext = require("./DeterministicIdContext");
|
|
@@ -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");
|
|
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,73 +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
|
-
require("core-js/modules/es.array.includes.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
|
-
* Return an object with the remaining props after the given props are omitted.
|
|
38
|
-
*
|
|
39
|
-
* Automatically excludes the following props:
|
|
40
|
-
* `theme`, `children`, `className`, `style`, `styles`, `makeStyles`,
|
|
41
|
-
* `themeOverride`, `deterministicId`
|
|
42
|
-
* @module omitProps
|
|
43
|
-
* @param props The object to process
|
|
44
|
-
* @param propsToOmit list disallowed prop keys or an object whose
|
|
45
|
-
* keys will be omitted. If not specified the automatically excluded
|
|
46
|
-
* props will be removed.
|
|
47
|
-
* @param exclude an optional array of disallowed prop names to omit
|
|
48
|
-
* @returns props object without the excluded props
|
|
49
|
-
* @module omitProps
|
|
50
|
-
*/
|
|
51
|
-
function omitProps(props, propsToOmit, exclude) {
|
|
52
|
-
const propKeys = Array.isArray(propsToOmit) ? propsToOmit : Object.keys(propsToOmit || {});
|
|
53
|
-
const keysToOmit = exclude ? propKeys.concat(exclude) : propKeys;
|
|
54
|
-
return omit(props, keysToOmit);
|
|
55
|
-
}
|
|
56
|
-
const hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
57
|
-
const omit = (originalObject, keysToOmit) => {
|
|
58
|
-
// code based on babel's _objectWithoutProperties
|
|
59
|
-
const newObject = {};
|
|
60
|
-
for (const key in originalObject) {
|
|
61
|
-
// special case because we always want to omit these and === is faster than
|
|
62
|
-
// concat'ing them in
|
|
63
|
-
if (key === 'theme' || key === 'children' || key === 'className' || key === 'style' || key === 'styles' || key === 'makeStyles' || key === 'themeOverride' || key === 'deterministicId') {
|
|
64
|
-
continue;
|
|
65
|
-
}
|
|
66
|
-
if (keysToOmit.includes(key) || !hasOwnProperty.call(originalObject, key)) {
|
|
67
|
-
continue;
|
|
68
|
-
}
|
|
69
|
-
newObject[key] = originalObject[key];
|
|
70
|
-
}
|
|
71
|
-
return newObject;
|
|
72
|
-
};
|
|
73
|
-
var _default = exports.default = omitProps;
|
package/lib/package.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"type":"commonjs"}
|