@instructure/ui-react-utils 8.17.1-snapshot.1 → 8.17.1-snapshot.14

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 (40) hide show
  1. package/es/DeterministicIdContext/DeterministicIdContext.js +27 -0
  2. package/es/DeterministicIdContext/DeterministicIdProvider.js +47 -0
  3. package/es/DeterministicIdContext/generateInstanceCounterMap.js +29 -0
  4. package/es/DeterministicIdContext/index.js +27 -0
  5. package/es/DeterministicIdContext/withDeterministicId.js +74 -0
  6. package/es/index.js +2 -1
  7. package/es/omitProps.js +1 -1
  8. package/es/passthroughProps.js +1 -1
  9. package/lib/DeterministicIdContext/DeterministicIdContext.js +39 -0
  10. package/lib/DeterministicIdContext/DeterministicIdProvider.js +59 -0
  11. package/lib/DeterministicIdContext/generateInstanceCounterMap.js +37 -0
  12. package/lib/DeterministicIdContext/index.js +37 -0
  13. package/lib/DeterministicIdContext/withDeterministicId.js +92 -0
  14. package/lib/index.js +27 -1
  15. package/lib/omitProps.js +1 -1
  16. package/lib/passthroughProps.js +1 -1
  17. package/package.json +10 -9
  18. package/src/DeterministicIdContext/DeterministicIdContext.ts +29 -0
  19. package/src/DeterministicIdContext/DeterministicIdProvider.tsx +58 -0
  20. package/src/DeterministicIdContext/generateInstanceCounterMap.ts +29 -0
  21. package/src/DeterministicIdContext/index.ts +30 -0
  22. package/src/DeterministicIdContext/withDeterministicId.tsx +101 -0
  23. package/src/index.ts +10 -0
  24. package/src/omitProps.ts +2 -1
  25. package/src/passthroughProps.ts +2 -1
  26. package/tsconfig.build.tsbuildinfo +1 -1
  27. package/types/DeterministicIdContext/DeterministicIdContext.d.ts +4 -0
  28. package/types/DeterministicIdContext/DeterministicIdContext.d.ts.map +1 -0
  29. package/types/DeterministicIdContext/DeterministicIdProvider.d.ts +21 -0
  30. package/types/DeterministicIdContext/DeterministicIdProvider.d.ts.map +1 -0
  31. package/types/DeterministicIdContext/generateInstanceCounterMap.d.ts +5 -0
  32. package/types/DeterministicIdContext/generateInstanceCounterMap.d.ts.map +1 -0
  33. package/types/DeterministicIdContext/index.d.ts +7 -0
  34. package/types/DeterministicIdContext/index.d.ts.map +1 -0
  35. package/types/DeterministicIdContext/withDeterministicId.d.ts +17 -0
  36. package/types/DeterministicIdContext/withDeterministicId.d.ts.map +1 -0
  37. package/types/index.d.ts +2 -0
  38. package/types/index.d.ts.map +1 -1
  39. package/types/omitProps.d.ts.map +1 -1
  40. package/types/passthroughProps.d.ts.map +1 -1
@@ -0,0 +1,27 @@
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
+ import React from 'react';
25
+ import { generateInstanceCounterMap } from './generateInstanceCounterMap';
26
+ const DeterministicIdContext = /*#__PURE__*/React.createContext(generateInstanceCounterMap());
27
+ export { DeterministicIdContext };
@@ -0,0 +1,47 @@
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
+ import React from 'react';
25
+ import { generateInstanceCounterMap } from './generateInstanceCounterMap';
26
+ import { DeterministicIdContext } from './DeterministicIdContext';
27
+ const defaultContextValue = generateInstanceCounterMap();
28
+ /**
29
+ * ---
30
+ * category: components/utilities
31
+ * ---
32
+ * This is utility component for wrapping components with `DeterministicIdContext.Provider`
33
+ * See detailed documentation about how to use it: [InstUISettingsProvider](/#InstUISettingsProvider)
34
+ */
35
+
36
+ const DeterministicIdContextProvider = _ref => {
37
+ let children = _ref.children,
38
+ instanceCounterMap = _ref.instanceCounterMap;
39
+ return /*#__PURE__*/React.createElement(DeterministicIdContext.Provider, {
40
+ value: instanceCounterMap
41
+ }, children);
42
+ };
43
+
44
+ DeterministicIdContextProvider.defaultProps = {
45
+ instanceCounterMap: defaultContextValue
46
+ };
47
+ export { DeterministicIdContextProvider };
@@ -0,0 +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
+ */
24
+ function generateInstanceCounterMap() {
25
+ return new Map();
26
+ }
27
+
28
+ export default generateInstanceCounterMap;
29
+ export { generateInstanceCounterMap };
@@ -0,0 +1,27 @@
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
+ export { generateInstanceCounterMap } from './generateInstanceCounterMap';
25
+ export { DeterministicIdContextProvider } from './DeterministicIdProvider';
26
+ export { DeterministicIdContext } from './DeterministicIdContext';
27
+ export { withDeterministicId } from './withDeterministicId';
@@ -0,0 +1,74 @@
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
+ import React, { forwardRef, useContext } from 'react';
25
+ import hoistNonReactStatics from 'hoist-non-react-statics';
26
+ import { DeterministicIdContext } from './DeterministicIdContext';
27
+ import { decorator } from '@instructure/ui-decorator';
28
+ import { generateId } from '@instructure/ui-utils';
29
+ import { warn } from '@instructure/console';
30
+
31
+ /**
32
+ * This decorator is used to enable the decorated class to use the `DeterministicIdContext` which is needed
33
+ * for deterministic id generation.
34
+ *
35
+ * The context is there for the users to pass an `instanceCounterMap` Map which is then used
36
+ * in the child components to deterministically create ids for them based on the `instanceCounterMap`.
37
+ * Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
38
+ */
39
+ const withDeterministicId = decorator(ComposedComponent => {
40
+ const WithDeterministicId = /*#__PURE__*/forwardRef((props, ref) => {
41
+ const componentName = ComposedComponent.componentId || ComposedComponent.displayName || ComposedComponent.name;
42
+ const instanceCounterMap = useContext(DeterministicIdContext);
43
+
44
+ const deterministicId = function () {
45
+ let instanceName = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : componentName;
46
+ return generateId(instanceName, instanceCounterMap);
47
+ };
48
+
49
+ if (props.deterministicId) {
50
+ warn(false, `Manually passing the "deterministicId" property is not allowed on the ${componentName} component.\n`, props.deterministicId);
51
+ }
52
+
53
+ return /*#__PURE__*/React.createElement(ComposedComponent, Object.assign({
54
+ ref: ref,
55
+ deterministicId: deterministicId
56
+ }, props));
57
+ });
58
+ hoistNonReactStatics(WithDeterministicId, ComposedComponent); // we have to pass these on, because sometimes users
59
+ // access propTypes of the component in other components
60
+ // eslint-disable-next-line react/forbid-foreign-prop-types
61
+
62
+ WithDeterministicId.propTypes = ComposedComponent.propTypes;
63
+ WithDeterministicId.defaultProps = ComposedComponent.defaultProps; // These static fields exist on InstUI components
64
+
65
+ WithDeterministicId.allowedProps = ComposedComponent.allowedProps;
66
+
67
+ if (process.env.NODE_ENV !== 'production') {
68
+ WithDeterministicId.displayName = `WithDeterministicId(${ComposedComponent.displayName})`;
69
+ }
70
+
71
+ return WithDeterministicId;
72
+ });
73
+ export default withDeterministicId;
74
+ export { withDeterministicId };
package/es/index.js CHANGED
@@ -37,4 +37,5 @@ export { omitProps } from './omitProps';
37
37
  export { passthroughProps } from './passthroughProps';
38
38
  export { pickProps } from './pickProps';
39
39
  export { safeCloneElement } from './safeCloneElement';
40
- export { windowMessageListener } from './windowMessageListener';
40
+ export { windowMessageListener } from './windowMessageListener';
41
+ export { DeterministicIdContext, generateInstanceCounterMap, DeterministicIdContextProvider, withDeterministicId } from './DeterministicIdContext';
package/es/omitProps.js CHANGED
@@ -54,7 +54,7 @@ const omit = (originalObject, keysToOmit) => {
54
54
  for (const key in originalObject) {
55
55
  // special case because we always want to omit these and === is faster than
56
56
  // concat'ing them in
57
- if (key === 'theme' || key === 'children' || key === 'className' || key === 'style' || key === 'styles' || key === 'makeStyles' || key === 'themeOverride') {
57
+ if (key === 'theme' || key === 'children' || key === 'className' || key === 'style' || key === 'styles' || key === 'makeStyles' || key === 'themeOverride' || key === 'instanceCounterMap') {
58
58
  continue;
59
59
  }
60
60
 
@@ -36,7 +36,7 @@ function passthroughProps(props) {
36
36
  const validProps = {};
37
37
  Object.keys(props) // style and className need to be explicitly passed through
38
38
  // styles and makeStyle can not pass through
39
- .filter(propName => isPropValid(propName) && propName !== 'style' && propName !== 'className' && propName !== 'children' && propName !== 'styles' && propName !== 'makeStyles').forEach(propName => {
39
+ .filter(propName => isPropValid(propName) && propName !== 'style' && propName !== 'className' && propName !== 'children' && propName !== 'styles' && propName !== 'makeStyles' && propName !== 'instanceCounterMap').forEach(propName => {
40
40
  validProps[propName] = props[propName];
41
41
  });
42
42
  return validProps;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.DeterministicIdContext = void 0;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _generateInstanceCounterMap = require("./generateInstanceCounterMap");
13
+
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
+ const DeterministicIdContext = /*#__PURE__*/_react.default.createContext((0, _generateInstanceCounterMap.generateInstanceCounterMap)());
38
+
39
+ exports.DeterministicIdContext = DeterministicIdContext;
@@ -0,0 +1,59 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.DeterministicIdContextProvider = void 0;
9
+
10
+ var _react = _interopRequireDefault(require("react"));
11
+
12
+ var _generateInstanceCounterMap = require("./generateInstanceCounterMap");
13
+
14
+ var _DeterministicIdContext = require("./DeterministicIdContext");
15
+
16
+ /*
17
+ * The MIT License (MIT)
18
+ *
19
+ * Copyright (c) 2015 - present Instructure, Inc.
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
22
+ * of this software and associated documentation files (the "Software"), to deal
23
+ * in the Software without restriction, including without limitation the rights
24
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
25
+ * copies of the Software, and to permit persons to whom the Software is
26
+ * furnished to do so, subject to the following conditions:
27
+ *
28
+ * The above copyright notice and this permission notice shall be included in all
29
+ * copies or substantial portions of the Software.
30
+ *
31
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
32
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
33
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
34
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
35
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
36
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
37
+ * SOFTWARE.
38
+ */
39
+ const defaultContextValue = (0, _generateInstanceCounterMap.generateInstanceCounterMap)();
40
+ /**
41
+ * ---
42
+ * category: components/utilities
43
+ * ---
44
+ * This is utility component for wrapping components with `DeterministicIdContext.Provider`
45
+ * See detailed documentation about how to use it: [InstUISettingsProvider](/#InstUISettingsProvider)
46
+ */
47
+
48
+ const DeterministicIdContextProvider = _ref => {
49
+ let children = _ref.children,
50
+ instanceCounterMap = _ref.instanceCounterMap;
51
+ return /*#__PURE__*/_react.default.createElement(_DeterministicIdContext.DeterministicIdContext.Provider, {
52
+ value: instanceCounterMap
53
+ }, children);
54
+ };
55
+
56
+ exports.DeterministicIdContextProvider = DeterministicIdContextProvider;
57
+ DeterministicIdContextProvider.defaultProps = {
58
+ instanceCounterMap: defaultContextValue
59
+ };
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ exports.generateInstanceCounterMap = generateInstanceCounterMap;
8
+
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
+ function generateInstanceCounterMap() {
33
+ return new Map();
34
+ }
35
+
36
+ var _default = generateInstanceCounterMap;
37
+ exports.default = _default;
@@ -0,0 +1,37 @@
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 _DeterministicIdProvider.DeterministicIdContextProvider;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "generateInstanceCounterMap", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _generateInstanceCounterMap.generateInstanceCounterMap;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "withDeterministicId", {
25
+ enumerable: true,
26
+ get: function () {
27
+ return _withDeterministicId.withDeterministicId;
28
+ }
29
+ });
30
+
31
+ var _generateInstanceCounterMap = require("./generateInstanceCounterMap");
32
+
33
+ var _DeterministicIdProvider = require("./DeterministicIdProvider");
34
+
35
+ var _DeterministicIdContext = require("./DeterministicIdContext");
36
+
37
+ var _withDeterministicId = require("./withDeterministicId");
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
+
5
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
6
+
7
+ Object.defineProperty(exports, "__esModule", {
8
+ value: true
9
+ });
10
+ exports.withDeterministicId = exports.default = void 0;
11
+
12
+ var _react = _interopRequireWildcard(require("react"));
13
+
14
+ var _hoistNonReactStatics = _interopRequireDefault(require("hoist-non-react-statics"));
15
+
16
+ var _DeterministicIdContext = require("./DeterministicIdContext");
17
+
18
+ var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
19
+
20
+ var _generateId = require("@instructure/ui-utils/lib/generateId.js");
21
+
22
+ var _console = require("@instructure/console");
23
+
24
+ /*
25
+ * The MIT License (MIT)
26
+ *
27
+ * Copyright (c) 2015 - present Instructure, Inc.
28
+ *
29
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
30
+ * of this software and associated documentation files (the "Software"), to deal
31
+ * in the Software without restriction, including without limitation the rights
32
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
33
+ * copies of the Software, and to permit persons to whom the Software is
34
+ * furnished to do so, subject to the following conditions:
35
+ *
36
+ * The above copyright notice and this permission notice shall be included in all
37
+ * copies or substantial portions of the Software.
38
+ *
39
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
40
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
41
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
42
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
43
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
44
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
45
+ * SOFTWARE.
46
+ */
47
+
48
+ /**
49
+ * This decorator is used to enable the decorated class to use the `DeterministicIdContext` which is needed
50
+ * for deterministic id generation.
51
+ *
52
+ * The context is there for the users to pass an `instanceCounterMap` Map which is then used
53
+ * in the child components to deterministically create ids for them based on the `instanceCounterMap`.
54
+ * Read more about it here: [SSR guide](https://instructure.design/#server-side-rendering)
55
+ */
56
+ const withDeterministicId = (0, _decorator.decorator)(ComposedComponent => {
57
+ const WithDeterministicId = /*#__PURE__*/(0, _react.forwardRef)((props, ref) => {
58
+ const componentName = ComposedComponent.componentId || ComposedComponent.displayName || ComposedComponent.name;
59
+ const instanceCounterMap = (0, _react.useContext)(_DeterministicIdContext.DeterministicIdContext);
60
+
61
+ const deterministicId = function () {
62
+ let instanceName = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : componentName;
63
+ return (0, _generateId.generateId)(instanceName, instanceCounterMap);
64
+ };
65
+
66
+ if (props.deterministicId) {
67
+ (0, _console.warn)(false, `Manually passing the "deterministicId" property is not allowed on the ${componentName} component.\n`, props.deterministicId);
68
+ }
69
+
70
+ return /*#__PURE__*/_react.default.createElement(ComposedComponent, Object.assign({
71
+ ref: ref,
72
+ deterministicId: deterministicId
73
+ }, props));
74
+ });
75
+ (0, _hoistNonReactStatics.default)(WithDeterministicId, ComposedComponent); // we have to pass these on, because sometimes users
76
+ // access propTypes of the component in other components
77
+ // eslint-disable-next-line react/forbid-foreign-prop-types
78
+
79
+ WithDeterministicId.propTypes = ComposedComponent.propTypes;
80
+ WithDeterministicId.defaultProps = ComposedComponent.defaultProps; // These static fields exist on InstUI components
81
+
82
+ WithDeterministicId.allowedProps = ComposedComponent.allowedProps;
83
+
84
+ if (process.env.NODE_ENV !== 'production') {
85
+ WithDeterministicId.displayName = `WithDeterministicId(${ComposedComponent.displayName})`;
86
+ }
87
+
88
+ return WithDeterministicId;
89
+ });
90
+ exports.withDeterministicId = withDeterministicId;
91
+ var _default = withDeterministicId;
92
+ exports.default = _default;
package/lib/index.js CHANGED
@@ -9,6 +9,18 @@ Object.defineProperty(exports, "ComponentIdentifier", {
9
9
  return _ComponentIdentifier.ComponentIdentifier;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "DeterministicIdContext", {
13
+ enumerable: true,
14
+ get: function () {
15
+ return _DeterministicIdContext.DeterministicIdContext;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "DeterministicIdContextProvider", {
19
+ enumerable: true,
20
+ get: function () {
21
+ return _DeterministicIdContext.DeterministicIdContextProvider;
22
+ }
23
+ });
12
24
  Object.defineProperty(exports, "callRenderProp", {
13
25
  enumerable: true,
14
26
  get: function () {
@@ -33,6 +45,12 @@ Object.defineProperty(exports, "experimental", {
33
45
  return _experimental.experimental;
34
46
  }
35
47
  });
48
+ Object.defineProperty(exports, "generateInstanceCounterMap", {
49
+ enumerable: true,
50
+ get: function () {
51
+ return _DeterministicIdContext.generateInstanceCounterMap;
52
+ }
53
+ });
36
54
  Object.defineProperty(exports, "getDisplayName", {
37
55
  enumerable: true,
38
56
  get: function () {
@@ -93,6 +111,12 @@ Object.defineProperty(exports, "windowMessageListener", {
93
111
  return _windowMessageListener.windowMessageListener;
94
112
  }
95
113
  });
114
+ Object.defineProperty(exports, "withDeterministicId", {
115
+ enumerable: true,
116
+ get: function () {
117
+ return _DeterministicIdContext.withDeterministicId;
118
+ }
119
+ });
96
120
 
97
121
  var _callRenderProp = require("./callRenderProp");
98
122
 
@@ -122,4 +146,6 @@ var _pickProps = require("./pickProps");
122
146
 
123
147
  var _safeCloneElement = require("./safeCloneElement");
124
148
 
125
- var _windowMessageListener = require("./windowMessageListener");
149
+ var _windowMessageListener = require("./windowMessageListener");
150
+
151
+ var _DeterministicIdContext = require("./DeterministicIdContext");
package/lib/omitProps.js CHANGED
@@ -62,7 +62,7 @@ const omit = (originalObject, keysToOmit) => {
62
62
  for (const key in originalObject) {
63
63
  // special case because we always want to omit these and === is faster than
64
64
  // concat'ing them in
65
- if (key === 'theme' || key === 'children' || key === 'className' || key === 'style' || key === 'styles' || key === 'makeStyles' || key === 'themeOverride') {
65
+ if (key === 'theme' || key === 'children' || key === 'className' || key === 'style' || key === 'styles' || key === 'makeStyles' || key === 'themeOverride' || key === 'instanceCounterMap') {
66
66
  continue;
67
67
  }
68
68
 
@@ -47,7 +47,7 @@ function passthroughProps(props) {
47
47
  const validProps = {};
48
48
  Object.keys(props) // style and className need to be explicitly passed through
49
49
  // styles and makeStyle can not pass through
50
- .filter(propName => (0, _isPropValid.default)(propName) && propName !== 'style' && propName !== 'className' && propName !== 'children' && propName !== 'styles' && propName !== 'makeStyles').forEach(propName => {
50
+ .filter(propName => (0, _isPropValid.default)(propName) && propName !== 'style' && propName !== 'className' && propName !== 'children' && propName !== 'styles' && propName !== 'makeStyles' && propName !== 'instanceCounterMap').forEach(propName => {
51
51
  validProps[propName] = props[propName];
52
52
  });
53
53
  return validProps;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-react-utils",
3
- "version": "8.17.1-snapshot.1+3eaf62445",
3
+ "version": "8.17.1-snapshot.14+f0b03679c",
4
4
  "description": "A React utility library made by Instructure Inc.",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -22,17 +22,18 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "devDependencies": {
25
- "@instructure/ui-babel-preset": "8.17.1-snapshot.1+3eaf62445",
26
- "@instructure/ui-test-utils": "8.17.1-snapshot.1+3eaf62445"
25
+ "@instructure/ui-babel-preset": "8.17.1-snapshot.14+f0b03679c",
26
+ "@instructure/ui-test-utils": "8.17.1-snapshot.14+f0b03679c"
27
27
  },
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.13.10",
30
30
  "@emotion/is-prop-valid": "^1",
31
- "@instructure/console": "8.17.1-snapshot.1+3eaf62445",
32
- "@instructure/shared-types": "8.17.1-snapshot.1+3eaf62445",
33
- "@instructure/ui-decorator": "8.17.1-snapshot.1+3eaf62445",
34
- "@instructure/ui-dom-utils": "8.17.1-snapshot.1+3eaf62445",
35
- "@instructure/ui-utils": "8.17.1-snapshot.1+3eaf62445",
31
+ "@instructure/console": "8.17.1-snapshot.14+f0b03679c",
32
+ "@instructure/shared-types": "8.17.1-snapshot.14+f0b03679c",
33
+ "@instructure/ui-decorator": "8.17.1-snapshot.14+f0b03679c",
34
+ "@instructure/ui-dom-utils": "8.17.1-snapshot.14+f0b03679c",
35
+ "@instructure/ui-utils": "8.17.1-snapshot.14+f0b03679c",
36
+ "hoist-non-react-statics": "^3.3.2",
36
37
  "prop-types": "^15"
37
38
  },
38
39
  "peerDependencies": {
@@ -43,5 +44,5 @@
43
44
  "access": "public"
44
45
  },
45
46
  "sideEffects": false,
46
- "gitHead": "3eaf62445635c7ef2927ddfcf610fb561a729fd1"
47
+ "gitHead": "f0b03679c4c4d05d4d650d22646ac1dc6791e935"
47
48
  }
@@ -0,0 +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
+ */
24
+ import React from 'react'
25
+ import { generateInstanceCounterMap } from './generateInstanceCounterMap'
26
+
27
+ const DeterministicIdContext = React.createContext(generateInstanceCounterMap())
28
+
29
+ export { DeterministicIdContext }