@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.
Files changed (45) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +1 -0
  3. package/{lib/getDisplayName.js → babel.config.cjs} +11 -20
  4. package/es/DeterministicIdContext/DeterministicIdContext.js +0 -2
  5. package/es/DeterministicIdContext/DeterministicIdContextProvider.js +2 -1
  6. package/es/DeterministicIdContext/index.js +5 -4
  7. package/es/DeterministicIdContext/useDeterministicId.js +2 -1
  8. package/es/DeterministicIdContext/withDeterministicId.js +1 -1
  9. package/es/ensureSingleChild.js +2 -1
  10. package/es/getInteraction.js +0 -1
  11. package/es/index.js +13 -12
  12. package/es/matchComponentTypes.js +2 -1
  13. package/es/omitProps.js +0 -1
  14. package/package.json +9 -11
  15. package/src/DeterministicIdContext/DeterministicIdContext.ts +0 -1
  16. package/src/DeterministicIdContext/DeterministicIdContextProvider.tsx +1 -1
  17. package/src/DeterministicIdContext/index.ts +4 -4
  18. package/src/DeterministicIdContext/useDeterministicId.tsx +1 -1
  19. package/src/DeterministicIdContext/withDeterministicId.tsx +1 -1
  20. package/src/ensureSingleChild.tsx +1 -1
  21. package/src/index.ts +12 -12
  22. package/src/matchComponentTypes.ts +1 -1
  23. package/tsconfig.build.tsbuildinfo +1 -1
  24. package/types/DeterministicIdContext/DeterministicIdContext.d.ts.map +1 -1
  25. package/types/DeterministicIdContext/index.d.ts +4 -4
  26. package/types/DeterministicIdContext/index.d.ts.map +1 -1
  27. package/types/index.d.ts +12 -12
  28. package/types/index.d.ts.map +1 -1
  29. package/lib/DeterministicIdContext/DeterministicIdContext.js +0 -52
  30. package/lib/DeterministicIdContext/DeterministicIdContextProvider.js +0 -54
  31. package/lib/DeterministicIdContext/index.js +0 -33
  32. package/lib/DeterministicIdContext/useDeterministicId.js +0 -66
  33. package/lib/DeterministicIdContext/withDeterministicId.js +0 -75
  34. package/lib/callRenderProp.js +0 -57
  35. package/lib/ensureSingleChild.js +0 -62
  36. package/lib/getElementType.js +0 -77
  37. package/lib/getInteraction.js +0 -63
  38. package/lib/index.js +0 -107
  39. package/lib/matchComponentTypes.js +0 -53
  40. package/lib/omitProps.js +0 -73
  41. package/lib/package.json +0 -1
  42. package/lib/passthroughProps.js +0 -53
  43. package/lib/pickProps.js +0 -64
  44. package/lib/safeCloneElement.js +0 -105
  45. package/lib/windowMessageListener.js +0 -110
@@ -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;
package/lib/pickProps.js DELETED
@@ -1,64 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.pickProps = pickProps;
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 a props object with only specified propTypes.
37
- *
38
- * @param props React component props
39
- * @param propTypesOrAllowedPropList React component propTypes or the list of allowed prop keys
40
- * @param include an optional array of prop names to include
41
- * @returns props object with only the included props
42
- * @module pickProps
43
- */
44
- function pickProps(props, propTypesOrAllowedPropList, include) {
45
- const propKeys = Array.isArray(propTypesOrAllowedPropList) ? propTypesOrAllowedPropList : Object.keys(propTypesOrAllowedPropList || {});
46
- const combined = include ? propKeys.concat(include) : propKeys;
47
- return pick(props, combined);
48
- }
49
-
50
- // this was the fastest implementation from testing: https://jsperf.com/pick-props
51
- function pick(obj, keys) {
52
- const res = {};
53
- const len = keys.length;
54
- let idx = -1;
55
- let key;
56
- while (++idx < len) {
57
- key = keys[idx];
58
- if (key in obj) {
59
- res[key] = obj[key];
60
- }
61
- }
62
- return res;
63
- }
64
- var _default = exports.default = pickProps;
@@ -1,105 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.safeCloneElement = safeCloneElement;
8
- var _react = require("react");
9
- var _console = require("@instructure/console");
10
- var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
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
- * Clones a React element without overwriting refs.
40
- * @param element The element to clone
41
- * @param props Props of the element
42
- * @param children
43
- */
44
- function safeCloneElement(element, props, ...children) {
45
- const cloneRef = props.ref;
46
- // Support both React 18 (element.ref) and React 19+ (element.props.ref)
47
- // TypeScript's ReactElement type does not always include a 'ref' property,
48
- // so we use 'as any' to safely access it for React 18 compatibility.
49
- let isReact19OrNewer = true;
50
- const versArr = _react.version.split('.', 1);
51
- if (versArr.length > 0 && parseInt(versArr[0], 10) < 19) {
52
- isReact19OrNewer = false;
53
- }
54
- // this needs to happen in such tricky way because React 18 and earlier
55
- // throw warning when one tries to access element.props.ref, see
56
- // https://github.com/facebook/react/blob/18-3-1/packages/react/src/jsx/ReactJSXElement.js#L108
57
- const originalRef = isReact19OrNewer ? element.props.ref : element.ref;
58
- const originalRefIsAFunction = typeof originalRef === 'function';
59
- const cloneRefIsFunction = typeof cloneRef === 'function';
60
- const mergedProps = {
61
- ...props
62
- };
63
- if (element.props.style && props.style) {
64
- // merge with existing styles
65
- mergedProps.style = {
66
- ...element.props.style,
67
- ...props.style
68
- };
69
- }
70
-
71
- // prevent overriding existing keys
72
- mergedProps.key = element.key || props.key;
73
-
74
- // Add chained function to preserve existing event handlers
75
- Object.keys(props).forEach(prop => {
76
- // If prop looks like an event handler "on*" and either
77
- // props[props] or element.props[prop] is a function create a chained function.
78
- // If only one is a function it will just use that function with no extra overhead.
79
- // This is necessary in cases where props[prop] is `null` or `undefined` which would
80
- // otherwise unwantedly override element.props[prop].
81
- if (prop.indexOf('on') === 0 && (typeof props[prop] === 'function' || typeof element.props[prop] === 'function')) {
82
- ;
83
- mergedProps[prop] = (0, _createChainedFunction.createChainedFunction)(element.props[prop], props[prop]);
84
- }
85
- });
86
- if (originalRef == null || cloneRef == null) {
87
- return /*#__PURE__*/(0, _react.cloneElement)(element, mergedProps, ...children);
88
- }
89
- (0, _console.logWarn)(originalRefIsAFunction, `Cloning an element with a ref that will be overwritten because the ref \
90
- is not a function. Use a composable callback-style ref instead. \
91
- Ignoring ref: ${originalRef}`);
92
- return /*#__PURE__*/(0, _react.cloneElement)(element, {
93
- ...mergedProps,
94
- ref(component) {
95
- if (cloneRefIsFunction) {
96
- ;
97
- cloneRef(component);
98
- } else {
99
- cloneRef.current = component;
100
- }
101
- originalRefIsAFunction && originalRef(component);
102
- }
103
- }, ...children);
104
- }
105
- var _default = exports.default = safeCloneElement;
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
- exports.origin = origin;
8
- exports.windowMessageListener = void 0;
9
- var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
10
- var _ownerWindow = require("@instructure/ui-dom-utils/lib/ownerWindow.js");
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
- * A decorator or higher order component that provides methods
40
- * for cross-origin communication (between iframes/windows).
41
- *
42
- * see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
43
- * @module windowMessageListener
44
- * @param {Function} messageHandler a handler for messages receieved by the component
45
- * @param {Function} validSource an optional function that would restrict message handling to a specified source.
46
- * @returns {Function} a function that decorates a React component with the behavior
47
- */
48
- const windowMessageListener = exports.windowMessageListener = (0, _decorator.decorator)((ComposedComponent, messageHandler, validSource) => {
49
- return class extends ComposedComponent {
50
- static postMessage = function (target, message, origin) {
51
- target.postMessage(message, origin);
52
- };
53
- componentDidMount() {
54
- const win = (0, _ownerWindow.ownerWindow)(this);
55
- win.addEventListener('message', this.handleMessage, false);
56
- if (super.componentDidMount) {
57
- super.componentDidMount();
58
- }
59
- }
60
- componentWillUnmount() {
61
- const win = (0, _ownerWindow.ownerWindow)(this);
62
- win.removeEventListener('message', this.handleMessage, false);
63
- if (super.componentDidMount) {
64
- super.componentDidMount();
65
- }
66
- }
67
- sourceIsValid(eventSource) {
68
- const expectedSource = typeof validSource === 'function' ? validSource.call(this) : validSource;
69
- if (!expectedSource) {
70
- return true;
71
- } else if (eventSource) {
72
- const sourceFrame = eventSource.frameElement;
73
- const sourceName = sourceFrame ? sourceFrame.getAttribute('name') : null;
74
- return sourceName === expectedSource;
75
- } else {
76
- return false;
77
- }
78
- }
79
- handleMessage = e => {
80
- if (this.sourceIsValid(e.source) && e.origin === origin(this) && e.data) {
81
- messageHandler.call(this, e.data);
82
- }
83
- };
84
- };
85
- });
86
-
87
- /**
88
- * Return the origin of the owner window of the DOM element
89
- *
90
- * see https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage
91
- *
92
- * @param {DOMElement} node
93
- * @returns {String} the origin
94
- */
95
- function origin(node) {
96
- const ownWindow = (0, _ownerWindow.ownerWindow)(node);
97
- const {
98
- location
99
- } = ownWindow;
100
- if (location.protocol === 'file:') {
101
- return '*';
102
- } else if (location.origin) {
103
- return location.origin;
104
- } else if (location.port) {
105
- return `${location.protocol}//${location.hostname}:${location.port}`;
106
- } else {
107
- return `${location.protocol}//${location.hostname}`;
108
- }
109
- }
110
- var _default = exports.default = windowMessageListener;