@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.
Files changed (42) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/es/DeterministicIdContext/DeterministicIdContext.js +2 -38
  3. package/es/DeterministicIdContext/DeterministicIdContextProvider.js +7 -46
  4. package/es/DeterministicIdContext/index.js +1 -25
  5. package/es/DeterministicIdContext/useDeterministicId.js +3 -65
  6. package/es/DeterministicIdContext/withDeterministicId.js +21 -65
  7. package/es/callRenderProp.js +7 -45
  8. package/es/ensureSingleChild.js +13 -53
  9. package/es/getDisplayName.js +2 -36
  10. package/es/getElementType.js +18 -68
  11. package/es/getInteraction.js +10 -56
  12. package/es/index.js +1 -26
  13. package/es/matchComponentTypes.js +7 -43
  14. package/es/omitProps.js +15 -60
  15. package/es/passthroughProps.js +6 -42
  16. package/es/pickProps.js +14 -52
  17. package/es/safeCloneElement.js +40 -89
  18. package/es/windowMessageListener.js +52 -96
  19. package/package.json +10 -13
  20. package/src/getDisplayName.ts +1 -1
  21. package/src/omitProps.ts +1 -1
  22. package/tsconfig.build.json +0 -3
  23. package/tsconfig.build.tsbuildinfo +1 -1
  24. package/types/getDisplayName.d.ts +1 -1
  25. package/lib/DeterministicIdContext/DeterministicIdContext.js +0 -47
  26. package/lib/DeterministicIdContext/DeterministicIdContextProvider.js +0 -54
  27. package/lib/DeterministicIdContext/index.js +0 -33
  28. package/lib/DeterministicIdContext/useDeterministicId.js +0 -74
  29. package/lib/DeterministicIdContext/withDeterministicId.js +0 -80
  30. package/lib/callRenderProp.js +0 -57
  31. package/lib/ensureSingleChild.js +0 -62
  32. package/lib/getDisplayName.js +0 -45
  33. package/lib/getElementType.js +0 -77
  34. package/lib/getInteraction.js +0 -62
  35. package/lib/index.js +0 -107
  36. package/lib/matchComponentTypes.js +0 -53
  37. package/lib/omitProps.js +0 -72
  38. package/lib/package.json +0 -1
  39. package/lib/passthroughProps.js +0 -53
  40. package/lib/pickProps.js +0 -64
  41. package/lib/safeCloneElement.js +0 -105
  42. package/lib/windowMessageListener.js +0 -110
package/CHANGELOG.md CHANGED
@@ -3,6 +3,19 @@
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
+ ## [11.7.9-pr-snapshot-1792147648392](https://github.com/instructure/instructure-ui/compare/v11.7.8...v11.7.9-pr-snapshot-1792147648392) (2026-10-16)
7
+
8
+ ### Build System
9
+
10
+ * **many:** replace babel with swc ([7e36c54](https://github.com/instructure/instructure-ui/commit/7e36c54d240b4fa483801c03ab18e7f860f561e2))
11
+
12
+ ### BREAKING CHANGES
13
+
14
+ * **many:** `@instructure/ui-babel-preset` and
15
+ `@instructure/browserslist-config-instui` are removed and will no longer be
16
+ published. Packages depend on `@swc/helpers` instead of `@babel/runtime`.
17
+
18
+
6
19
  ## [11.7.8](https://github.com/instructure/instructure-ui/compare/v11.7.7...v11.7.8) (2026-10-02)
7
20
 
8
21
  **Note:** Version bump only for package @instructure/ui-react-utils
@@ -1,40 +1,4 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
1
  import React from 'react';
25
- /**
26
- * @deprecated Id generation no longer uses an instance counter map. Ids are now
27
- * generated with React's built-in `useId` (see `useDeterministicId` /
28
- * `withDeterministicId`), which is SSR-safe and hydration-stable without any
29
- * shared counter. This map is retained only for backwards compatibility and is
30
- * no longer read; it will be removed in the next major version.
31
- */
32
2
  const defaultDeterministicIDMap = new Map();
33
-
34
- /**
35
- * @deprecated This context is no longer consumed by the id generation utilities
36
- * and has no effect. It is retained only for backwards compatibility and will be
37
- * removed in the next major version.
38
- */
39
- const DeterministicIdContext = /*#__PURE__*/React.createContext(defaultDeterministicIDMap);
40
- export { DeterministicIdContext, defaultDeterministicIDMap };
3
+ const DeterministicIdContext = React.createContext(defaultDeterministicIDMap);
4
+ export { DeterministicIdContext, defaultDeterministicIDMap };
@@ -1,48 +1,9 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- import { DeterministicIdContext, defaultDeterministicIDMap } from './DeterministicIdContext.js';
26
1
  import { jsx as _jsx } from "@emotion/react/jsx-runtime";
27
- /**
28
- * ---
29
- * category: components/contexts
30
- * ---
31
- * WARNING: providing the `instanceCounterMap` prop will result in unexpected behaviour. DO NOT USE IT!
32
- *
33
- * DEPRECATED: the `instanceCounterMap` prop is deprecated. You don't need to supply the
34
- * `instanceCounterMap` to the component. It handles it internally.
35
- *
36
- * This utility component is for wrapping components with `DeterministicIdContext.Provider`
37
- * See detailed documentation about how to use it: [InstUISettingsProvider](/#InstUISettingsProvider)
38
- */
39
- const DeterministicIdContextProvider = ({
40
- children,
41
- instanceCounterMap = defaultDeterministicIDMap
42
- }) => {
43
- return _jsx(DeterministicIdContext.Provider, {
44
- value: instanceCounterMap,
45
- children: children
46
- });
2
+ import { DeterministicIdContext, defaultDeterministicIDMap } from './DeterministicIdContext.js';
3
+ const DeterministicIdContextProvider = ({ children, instanceCounterMap = defaultDeterministicIDMap })=>{
4
+ return /*#__PURE__*/ _jsx(DeterministicIdContext.Provider, {
5
+ value: instanceCounterMap,
6
+ children: children
7
+ });
47
8
  };
48
- export { DeterministicIdContextProvider };
9
+ export { DeterministicIdContextProvider };
@@ -1,28 +1,4 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
1
  export { DeterministicIdContextProvider } from './DeterministicIdContextProvider.js';
26
2
  export { DeterministicIdContext } from './DeterministicIdContext.js';
27
3
  export { withDeterministicId } from './withDeterministicId.js';
28
- export { useDeterministicId } from './useDeterministicId.js';
4
+ export { useDeterministicId } from './useDeterministicId.js';
@@ -1,69 +1,7 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
1
  import { useId } from 'react';
26
-
27
- /**
28
- * A React hook that provides SSR-safe, hydration-stable ID generation for
29
- * functional components.
30
- *
31
- * This hook is the functional component equivalent of the `withDeterministicId`
32
- * decorator. It is backed by React's built-in {@link https://react.dev/reference/react/useId `useId`},
33
- * which produces the same id on the server and the client for a given position
34
- * in the React tree.
35
- *
36
- * The returned function may be called multiple times with distinct
37
- * `instanceName` values to derive several unique, stable ids from the same
38
- * component instance (e.g. one for an input and one for its messages).
39
- *
40
- * Note: for apps that mount more than one independent React root on the same
41
- * page (including module federation), pass a distinct `identifierPrefix` to each
42
- * `createRoot`/`hydrateRoot` call so ids stay unique across roots.
43
- *
44
- * Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
45
- *
46
- * @param componentName - Component name used as a human-readable id prefix.
47
- * @returns A function that generates stable ids. It accepts an optional
48
- * `instanceName` used as the prefix for that specific id.
49
- *
50
- * @example
51
- * ```tsx
52
- * const MyComponent = () => {
53
- * const getId = useDeterministicId('MyComponent')
54
- * const id = getId()
55
- * const messagesId = getId('MyComponent-messages')
56
- * return <div id={id} aria-describedby={messagesId}>Content</div>
57
- * }
58
- * ```
59
- */
60
2
  function useDeterministicId(componentName) {
61
- // React wraps the value of `useId` in delimiters that are not valid in a CSS
62
- // selector (`:r0:` in React 18, `«r0»` in React 19), which would break any
63
- // `querySelector('#' + id)` call, so strip them. The `___` separator keeps the
64
- // historical `ComponentName___token` id shape.
65
- const base = useId().replace(/[^a-zA-Z0-9-]/g, '');
66
- return instanceName => `${instanceName ?? componentName}___${base}`;
3
+ const base = useId().replace(/[^a-zA-Z0-9-]/g, '');
4
+ return (instanceName)=>`${instanceName ?? componentName}___${base}`;
67
5
  }
68
6
  export default useDeterministicId;
69
- export { useDeterministicId };
7
+ export { useDeterministicId };
@@ -1,73 +1,29 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
1
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
24
2
  import { forwardRef } from 'react';
25
3
  import hoistNonReactStatics from 'hoist-non-react-statics';
26
4
  import { decorator } from '@instructure/ui-decorator';
27
5
  import { useDeterministicId } from './useDeterministicId.js';
28
6
  import { warn } from '@instructure/console';
29
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
30
- /**
31
- * This decorator injects a `deterministicId` prop into the decorated class,
32
- * used to generate SSR-safe, hydration-stable ids.
33
- *
34
- * It is backed by React's built-in {@link https://react.dev/reference/react/useId `useId`},
35
- * which produces the same id on the server and the client for a given position
36
- * in the React tree The injected `deterministicId(instanceName?)` function may
37
- * be called multiple times with distinct `instanceName` values to derive
38
- * several unique, stable ids from the same component instance.
39
- *
40
- * Note: for apps that mount more than one independent React root on the same
41
- * page (including module federation), pass a distinct `identifierPrefix` to each
42
- * `createRoot`/`hydrateRoot` call so ids stay unique across roots.
43
- * Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
44
- */
45
- const withDeterministicId = decorator(ComposedComponent => {
46
- const WithDeterministicId = /*#__PURE__*/forwardRef((props, ref) => {
47
- const componentName = ComposedComponent.componentId || ComposedComponent.displayName || ComposedComponent.name;
48
- const deterministicId = useDeterministicId(componentName);
49
- if (props.deterministicId) {
50
- warn(false, `Manually passing the "deterministicId" property is not allowed on the ${componentName} component.\n`, props.deterministicId);
51
- }
52
- return _jsx(ComposedComponent, {
53
- ref: ref,
54
- deterministicId: deterministicId,
55
- ...props
7
+ const withDeterministicId = decorator((ComposedComponent)=>{
8
+ const WithDeterministicId = /*#__PURE__*/ forwardRef((props, ref)=>{
9
+ const componentName = ComposedComponent.componentId || ComposedComponent.displayName || ComposedComponent.name;
10
+ const deterministicId = useDeterministicId(componentName);
11
+ if (props.deterministicId) {
12
+ warn(false, `Manually passing the "deterministicId" property is not allowed on the ${componentName} component.\n`, props.deterministicId);
13
+ }
14
+ return /*#__PURE__*/ _jsx(ComposedComponent, {
15
+ ref: ref,
16
+ deterministicId: deterministicId,
17
+ ...props
18
+ });
56
19
  });
57
- });
58
- hoistNonReactStatics(WithDeterministicId, ComposedComponent);
59
-
60
- // These static fields exist on InstUI components
61
- //@ts-expect-error fix this
62
- WithDeterministicId.allowedProps = ComposedComponent.allowedProps;
63
-
64
- // added so it can be tested with ReactTestUtils
65
- // more info: https://github.com/facebook/react/issues/13455
66
- WithDeterministicId.originalType = ComposedComponent.originalType || ComposedComponent;
67
- if (typeof process !== 'undefined' && process?.env?.NODE_ENV !== 'production') {
68
- WithDeterministicId.displayName = `WithDeterministicId(${ComposedComponent.displayName})`;
69
- }
70
- return WithDeterministicId;
20
+ hoistNonReactStatics(WithDeterministicId, ComposedComponent);
21
+ WithDeterministicId.allowedProps = ComposedComponent.allowedProps;
22
+ WithDeterministicId.originalType = ComposedComponent.originalType || ComposedComponent;
23
+ if (typeof process !== 'undefined' && process?.env?.NODE_ENV !== 'production') {
24
+ WithDeterministicId.displayName = `WithDeterministicId(${ComposedComponent.displayName})`;
25
+ }
26
+ return WithDeterministicId;
71
27
  });
72
28
  export default withDeterministicId;
73
- export { withDeterministicId };
29
+ export { withDeterministicId };
@@ -1,50 +1,12 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
1
  import React from 'react';
26
- /**
27
- * ---
28
- * category: utilities/react
29
- * ---
30
- * Evaluate a provided value to create a renderable React element.
31
- * @module callRenderProp
32
- * @param value
33
- * @param props
34
- */
35
2
  function callRenderProp(value, props = {}) {
36
- if (typeof value === 'function') {
37
- // In react 16, `createElement` accepts a function. In react 15 we get an
38
- // error on rendering the result. Evaluate the function here if it is not a
39
- // react component.
40
- // fat arrow functions don't have a prototype
41
- if (!(value.prototype && value.prototype.isReactComponent)) {
42
- return value(props);
3
+ if (typeof value === 'function') {
4
+ if (!(value.prototype && value.prototype.isReactComponent)) {
5
+ return value(props);
6
+ }
7
+ return React.createElement(value, props);
43
8
  }
44
- // TODO type 'value' properly
45
- return /*#__PURE__*/React.createElement(value, props);
46
- }
47
- return value;
9
+ return value;
48
10
  }
49
11
  export default callRenderProp;
50
- export { callRenderProp };
12
+ export { callRenderProp };
@@ -1,58 +1,18 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
1
+ import { jsx as _jsx } from "@emotion/react/jsx-runtime";
25
2
  import { Children } from 'react';
26
3
  import { safeCloneElement } from './safeCloneElement.js';
27
-
28
- /**
29
- * ---
30
- * category: utilities/react
31
- * ---
32
- *
33
- * Ensure a single child. If it is a child of length 1, return a
34
- * cloned instance of the child. If it is a child of length > 1,
35
- * wrap in a span and return the child. Return null if child has
36
- * no length.
37
- * @module ensureSingleChild
38
- * @param child
39
- * @param props props for child
40
- * @returns cloned instance for a single child, or children wrapped in a span
41
- */
42
- import { jsx as _jsx } from "@emotion/react/jsx-runtime";
43
4
  function ensureSingleChild(child, props = {}) {
44
- const childCount = Children.count(child);
45
- if (childCount === 0) {
46
- return null;
47
- } else if (typeof child === 'string' && child.length > 0 || childCount > 1) {
48
- return _jsx("span", {
49
- ...props,
50
- children: child
51
- });
52
- } else {
53
- // TODO: check that we can only end up here if child is ReactElement
54
- return safeCloneElement(Array.isArray(child) ? child[0] : child, props);
55
- }
5
+ const childCount = Children.count(child);
6
+ if (childCount === 0) {
7
+ return null;
8
+ } else if (typeof child === 'string' && child.length > 0 || childCount > 1) {
9
+ return /*#__PURE__*/ _jsx("span", {
10
+ ...props,
11
+ children: child
12
+ });
13
+ } else {
14
+ return safeCloneElement(Array.isArray(child) ? child[0] : child, props);
15
+ }
56
16
  }
57
17
  export default ensureSingleChild;
58
- export { ensureSingleChild };
18
+ export { ensureSingleChild };
@@ -1,39 +1,5 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- /**
26
- * ---
27
- * category: utilities/react
28
- * ---
29
- * Get the displayName of a React component.
30
- * needs a babel plugin to work https://github.com/facebook/react/issues/4915 !!
31
- * @module getDisplayName
32
- * @param ReactComponent
33
- * @returns the component displayName
34
- */
35
1
  function getDisplayName(ReactComponent) {
36
- return typeof ReactComponent === 'string' ? ReactComponent : ReactComponent.displayName || ReactComponent.name;
2
+ return typeof ReactComponent === 'string' ? ReactComponent : ReactComponent.displayName || ReactComponent.name;
37
3
  }
38
4
  export default getDisplayName;
39
- export { getDisplayName };
5
+ export { getDisplayName };
@@ -1,72 +1,22 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
1
  import { logWarn as warn } from '@instructure/console';
26
-
27
- /**
28
- * A props object that is searched for some fields to determine the
29
- * element's type.
30
- */
31
-
32
- /**
33
- * ---
34
- * category: utilities/react
35
- * ---
36
- * Get the React element type for a component. It uses the following logic:
37
- * 1. type defined by the `as` prop
38
- * 2. type returned by the `getDefault()` parameter
39
- * 3. `<a>` if it has a `href` or `to` prop
40
- * 4. `<button>` if it has an `onClick` prop
41
- * 5. the component's defaultProp's `as` field
42
- * 6. `<span>` if none of the above
43
- *
44
- * @module getElementType
45
- * @param Component
46
- * @param props
47
- * @param getDefault an optional function that returns the default element type
48
- * @returns the element type
49
- */
50
2
  function getElementType(Component, props, getDefault) {
51
- if (props.as && props.as !== Component.defaultProps?.as) {
52
- return props.as;
53
- }
54
- if (typeof getDefault === 'function') {
55
- return getDefault();
56
- }
57
- if (props.href) {
58
- return 'a';
59
- }
60
- if (props.to) {
61
- warn(
62
- // if to prop is used without as
63
- !props.as, `[${Component.displayName}] \`as\` prop should be provided when using \`to\``);
64
- return 'a';
65
- }
66
- if (typeof props.onClick === 'function') {
67
- return 'button';
68
- }
69
- return Component.defaultProps?.as || 'span';
3
+ if (props.as && props.as !== Component.defaultProps?.as) {
4
+ return props.as;
5
+ }
6
+ if (typeof getDefault === 'function') {
7
+ return getDefault();
8
+ }
9
+ if (props.href) {
10
+ return 'a';
11
+ }
12
+ if (props.to) {
13
+ warn(!props.as, `[${Component.displayName}] \`as\` prop should be provided when using \`to\``);
14
+ return 'a';
15
+ }
16
+ if (typeof props.onClick === 'function') {
17
+ return 'button';
18
+ }
19
+ return Component.defaultProps?.as || 'span';
70
20
  }
71
21
  export default getElementType;
72
- export { getElementType };
22
+ export { getElementType };
@@ -1,56 +1,10 @@
1
- /*
2
- * The MIT License (MIT)
3
- *
4
- * Copyright (c) 2015 - present Instructure, Inc.
5
- *
6
- * Permission is hereby granted, free of charge, to any person obtaining a copy
7
- * of this software and associated documentation files (the "Software"), to deal
8
- * in the Software without restriction, including without limitation the rights
9
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
- * copies of the Software, and to permit persons to whom the Software is
11
- * furnished to do so, subject to the following conditions:
12
- *
13
- * The above copyright notice and this permission notice shall be included in all
14
- * copies or substantial portions of the Software.
15
- *
16
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
- * SOFTWARE.
23
- */
24
-
25
- /**
26
- * ---
27
- * category: utilities/react
28
- * ---
29
- * Parse the component props for the interaction type. It will return one of 'enabled', 'disabled', or 'readonly'.
30
- * This is useful for form elements where consumers are able to either use the interaction prop as specified or the
31
- * native html disabled or readonly attributes
32
- * @module getInteraction
33
- * @param args extra arguments
34
- * @returns The calculated interaction type
35
- */
36
- export function getInteraction({
37
- props = {},
38
- interactionTypes = ['disabled', 'readonly']
39
- } = {}) {
40
- const {
41
- interaction,
42
- disabled,
43
- readOnly
44
- } = props;
45
-
46
- // interaction is the source of truth when it is provided
47
- if (interaction) return interaction;
48
-
49
- // if there's no interaction specified, use disabled or readOnly if they are defined as props (note, disabled will win
50
- // over readOnly if both are provided)
51
- if (interactionTypes.includes('disabled') && disabled) return 'disabled';
52
- if (interactionTypes.includes('readonly') && readOnly) return 'readonly';
53
-
54
- // We were provided with nothing, use enabled by default
55
- return 'enabled';
56
- }
1
+ export function getInteraction({ props = {}, interactionTypes = [
2
+ 'disabled',
3
+ 'readonly'
4
+ ] } = {}) {
5
+ const { interaction, disabled, readOnly } = props;
6
+ if (interaction) return interaction;
7
+ if (interactionTypes.includes('disabled') && disabled) return 'disabled';
8
+ if (interactionTypes.includes('readonly') && readOnly) return 'readonly';
9
+ return 'enabled';
10
+ }