@instructure/ui-react-utils 8.33.1 → 8.33.2

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 +4 -0
  2. package/es/ComponentIdentifier.js +5 -8
  3. package/es/DeterministicIdContext/DeterministicIdContextProvider.js +2 -2
  4. package/es/DeterministicIdContext/generateInstanceCounterMap.js +1 -1
  5. package/es/DeterministicIdContext/index.js +1 -0
  6. package/es/DeterministicIdContext/withDeterministicId.js +6 -10
  7. package/es/callRenderProp.js +3 -7
  8. package/es/deprecated.js +5 -30
  9. package/es/ensureSingleChild.js +2 -3
  10. package/es/experimental.js +0 -7
  11. package/es/getDisplayName.js +0 -1
  12. package/es/getElementType.js +3 -9
  13. package/es/getInteraction.js +12 -10
  14. package/es/hack.js +1 -7
  15. package/es/matchComponentTypes.js +1 -3
  16. package/es/omitProps.js +0 -7
  17. package/es/passthroughProps.js +3 -3
  18. package/es/pickProps.js +2 -6
  19. package/es/safeCloneElement.js +11 -15
  20. package/es/windowMessageListener.js +2 -13
  21. package/lib/ComponentIdentifier.js +2 -17
  22. package/lib/DeterministicIdContext/DeterministicIdContext.js +1 -5
  23. package/lib/DeterministicIdContext/DeterministicIdContextProvider.js +3 -7
  24. package/lib/DeterministicIdContext/generateInstanceCounterMap.js +1 -2
  25. package/lib/DeterministicIdContext/index.js +0 -4
  26. package/lib/DeterministicIdContext/withDeterministicId.js +6 -18
  27. package/lib/callRenderProp.js +2 -9
  28. package/lib/deprecated.js +6 -32
  29. package/lib/ensureSingleChild.js +0 -7
  30. package/lib/experimental.js +1 -10
  31. package/lib/getDisplayName.js +0 -2
  32. package/lib/getElementType.js +2 -10
  33. package/lib/getInteraction.js +12 -11
  34. package/lib/hack.js +0 -9
  35. package/lib/index.js +0 -16
  36. package/lib/matchComponentTypes.js +0 -4
  37. package/lib/omitProps.js +0 -8
  38. package/lib/passthroughProps.js +2 -5
  39. package/lib/pickProps.js +2 -7
  40. package/lib/safeCloneElement.js +10 -19
  41. package/lib/windowMessageListener.js +1 -16
  42. package/package.json +8 -8
  43. package/tsconfig.build.tsbuildinfo +1 -1
  44. package/types/getElementType.d.ts +1 -1
  45. package/types/getElementType.d.ts.map +1 -1
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  exports.getElementType = getElementType;
8
-
9
8
  var _console = require("@instructure/console");
10
-
11
9
  /*
12
10
  * The MIT License (MIT)
13
11
  *
@@ -46,31 +44,25 @@ var _console = require("@instructure/console");
46
44
  */
47
45
  function getElementType(Component, props, getDefault) {
48
46
  var _Component$defaultPro, _Component$defaultPro2;
49
-
50
47
  if (props.as && props.as !== ((_Component$defaultPro = Component.defaultProps) === null || _Component$defaultPro === void 0 ? void 0 : _Component$defaultPro.as)) {
51
48
  return props.as;
52
49
  }
53
-
54
50
  if (typeof getDefault === 'function') {
55
51
  return getDefault();
56
52
  }
57
-
58
53
  if (props.href) {
59
54
  return 'a';
60
55
  }
61
-
62
56
  if (props.to) {
63
- (0, _console.logWarn)( // if to prop is used without as
57
+ (0, _console.logWarn)(
58
+ // if to prop is used without as
64
59
  !props.as, `[${Component.displayName}] \`as\` prop should be provided when using \`to\``);
65
60
  return 'a';
66
61
  }
67
-
68
62
  if (typeof props.onClick === 'function') {
69
63
  return 'button';
70
64
  }
71
-
72
65
  return ((_Component$defaultPro2 = Component.defaultProps) === null || _Component$defaultPro2 === void 0 ? void 0 : _Component$defaultPro2.as) || 'span';
73
66
  }
74
-
75
67
  var _default = getElementType;
76
68
  exports.default = _default;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.getInteraction = getInteraction;
7
-
8
7
  /*
9
8
  * The MIT License (MIT)
10
9
  *
@@ -47,20 +46,22 @@ exports.getInteraction = getInteraction;
47
46
  */
48
47
  function getInteraction() {
49
48
  let _ref = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : {},
50
- _ref$props = _ref.props,
51
- props = _ref$props === void 0 ? {} : _ref$props,
52
- _ref$interactionTypes = _ref.interactionTypes,
53
- interactionTypes = _ref$interactionTypes === void 0 ? ['disabled', 'readonly'] : _ref$interactionTypes;
54
-
49
+ _ref$props = _ref.props,
50
+ props = _ref$props === void 0 ? {} : _ref$props,
51
+ _ref$interactionTypes = _ref.interactionTypes,
52
+ interactionTypes = _ref$interactionTypes === void 0 ? ['disabled', 'readonly'] : _ref$interactionTypes;
55
53
  const interaction = props.interaction,
56
- disabled = props.disabled,
57
- readOnly = props.readOnly; // interaction is the source of truth when it is provided
54
+ disabled = props.disabled,
55
+ readOnly = props.readOnly;
58
56
 
59
- if (interaction) return interaction; // if there's no interaction specified, use disabled or readOnly if they are defined as props (note, disabled will win
60
- // over readOnly if both are provided)
57
+ // interaction is the source of truth when it is provided
58
+ if (interaction) return interaction;
61
59
 
60
+ // if there's no interaction specified, use disabled or readOnly if they are defined as props (note, disabled will win
61
+ // over readOnly if both are provided)
62
62
  if (interactionTypes.includes('disabled') && disabled) return 'disabled';
63
- if (interactionTypes.includes('readonly') && readOnly) return 'readonly'; // We were provided with nothing, use enabled by default
63
+ if (interactionTypes.includes('readonly') && readOnly) return 'readonly';
64
64
 
65
+ // We were provided with nothing, use enabled by default
65
66
  return 'enabled';
66
67
  }
package/lib/hack.js CHANGED
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.hack = exports.default = void 0;
7
-
8
7
  var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
9
-
10
8
  var _console = require("@instructure/console");
11
-
12
9
  /*
13
10
  * The MIT License (MIT)
14
11
  *
@@ -60,32 +57,26 @@ const hack = process.env.NODE_ENV == 'production' ? () => Component => Component
60
57
  if (hackProps) {
61
58
  warnHackProps(ComposedComponent.name, this.props, hackProps, message);
62
59
  }
63
-
64
60
  if (super.componentDidMount) {
65
61
  super.componentDidMount();
66
62
  }
67
63
  }
68
-
69
64
  componentDidUpdate(prevProps, prevState, prevContext) {
70
65
  if (hackProps) {
71
66
  warnHackProps(ComposedComponent.name, this.props, hackProps, message);
72
67
  }
73
-
74
68
  if (super.componentDidUpdate) {
75
69
  super.componentDidUpdate(prevProps, prevState, prevContext);
76
70
  }
77
71
  }
78
-
79
72
  };
80
73
  });
81
74
  exports.hack = hack;
82
-
83
75
  function warnHackProps(name, props, hackProps) {
84
76
  let message = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : '';
85
77
  hackProps.forEach(hackProp => {
86
78
  (0, _console.logWarn)(typeof props[hackProp] === 'undefined', `[${name}] The \`${hackProp}\` prop is a temporary hack and will be removed in a future release. ${message}`);
87
79
  });
88
80
  }
89
-
90
81
  var _default = hack;
91
82
  exports.default = _default;
package/lib/index.js CHANGED
@@ -117,35 +117,19 @@ Object.defineProperty(exports, "withDeterministicId", {
117
117
  return _DeterministicIdContext.withDeterministicId;
118
118
  }
119
119
  });
120
-
121
120
  var _callRenderProp = require("./callRenderProp");
122
-
123
121
  var _ComponentIdentifier = require("./ComponentIdentifier");
124
-
125
122
  var _deprecated = require("./deprecated");
126
-
127
123
  var _ensureSingleChild = require("./ensureSingleChild");
128
-
129
124
  var _experimental = require("./experimental");
130
-
131
125
  var _hack = require("./hack");
132
-
133
126
  var _getDisplayName = require("./getDisplayName");
134
-
135
127
  var _getElementType = require("./getElementType");
136
-
137
128
  var _getInteraction = require("./getInteraction");
138
-
139
129
  var _matchComponentTypes = require("./matchComponentTypes");
140
-
141
130
  var _omitProps = require("./omitProps");
142
-
143
131
  var _passthroughProps = require("./passthroughProps");
144
-
145
132
  var _pickProps = require("./pickProps");
146
-
147
133
  var _safeCloneElement = require("./safeCloneElement");
148
-
149
134
  var _windowMessageListener = require("./windowMessageListener");
150
-
151
135
  var _DeterministicIdContext = require("./DeterministicIdContext");
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  exports.matchComponentTypes = matchComponentTypes;
8
-
9
8
  var _getDisplayName = require("./getDisplayName");
10
-
11
9
  /*
12
10
  * The MIT License (MIT)
13
11
  *
@@ -46,7 +44,6 @@ var _getDisplayName = require("./getDisplayName");
46
44
  */
47
45
  function matchComponentTypes(componentInstance) {
48
46
  let types = arguments.length > 1 && arguments[1] !== void 0 ? arguments[1] : [];
49
-
50
47
  if (componentInstance && componentInstance.type) {
51
48
  const displayNames = types.map(type => (0, _getDisplayName.getDisplayName)(type));
52
49
  return displayNames.indexOf((0, _getDisplayName.getDisplayName)(componentInstance.type)) >= 0;
@@ -54,6 +51,5 @@ function matchComponentTypes(componentInstance) {
54
51
  return false;
55
52
  }
56
53
  }
57
-
58
54
  var _default = matchComponentTypes;
59
55
  exports.default = _default;
package/lib/omitProps.js CHANGED
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  exports.omitProps = omitProps;
8
-
9
8
  /*
10
9
  * The MIT License (MIT)
11
10
  *
@@ -52,29 +51,22 @@ function omitProps(props, propsToOmit, exclude) {
52
51
  const keysToOmit = exclude ? propKeys.concat(exclude) : propKeys;
53
52
  return omit(props, keysToOmit);
54
53
  }
55
-
56
54
  const hasOwnProperty = Object.prototype.hasOwnProperty;
57
-
58
55
  const omit = (originalObject, keysToOmit) => {
59
56
  // code based on babel's _objectWithoutProperties
60
57
  const newObject = {};
61
-
62
58
  for (const key in originalObject) {
63
59
  // special case because we always want to omit these and === is faster than
64
60
  // concat'ing them in
65
61
  if (key === 'theme' || key === 'children' || key === 'className' || key === 'style' || key === 'styles' || key === 'makeStyles' || key === 'themeOverride' || key === 'deterministicId') {
66
62
  continue;
67
63
  }
68
-
69
64
  if (keysToOmit.includes(key) || !hasOwnProperty.call(originalObject, key)) {
70
65
  continue;
71
66
  }
72
-
73
67
  newObject[key] = originalObject[key];
74
68
  }
75
-
76
69
  return newObject;
77
70
  };
78
-
79
71
  var _default = omitProps;
80
72
  exports.default = _default;
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
8
  exports.passthroughProps = passthroughProps;
10
-
11
9
  var _isPropValid = _interopRequireDefault(require("@emotion/is-prop-valid"));
12
-
13
10
  /*
14
11
  * The MIT License (MIT)
15
12
  *
@@ -45,13 +42,13 @@ var _isPropValid = _interopRequireDefault(require("@emotion/is-prop-valid"));
45
42
  */
46
43
  function passthroughProps(props) {
47
44
  const validProps = {};
48
- Object.keys(props) // style and className need to be explicitly passed through
45
+ Object.keys(props)
46
+ // style and className need to be explicitly passed through
49
47
  // styles and makeStyle can not pass through
50
48
  .filter(propName => (0, _isPropValid.default)(propName) && propName !== 'style' && propName !== 'className' && propName !== 'children' && propName !== 'styles' && propName !== 'makeStyles' && propName !== 'deterministicId').forEach(propName => {
51
49
  validProps[propName] = props[propName];
52
50
  });
53
51
  return validProps;
54
52
  }
55
-
56
53
  var _default = passthroughProps;
57
54
  exports.default = _default;
package/lib/pickProps.js CHANGED
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  exports.pickProps = pickProps;
8
-
9
8
  /*
10
9
  * The MIT License (MIT)
11
10
  *
@@ -46,25 +45,21 @@ function pickProps(props, propTypesOrAllowedPropList, include) {
46
45
  const propKeys = Array.isArray(propTypesOrAllowedPropList) ? propTypesOrAllowedPropList : Object.keys(propTypesOrAllowedPropList || {});
47
46
  const combined = include ? propKeys.concat(include) : propKeys;
48
47
  return pick(props, combined);
49
- } // this was the fastest implementation from testing: https://jsperf.com/pick-props
50
-
48
+ }
51
49
 
50
+ // this was the fastest implementation from testing: https://jsperf.com/pick-props
52
51
  function pick(obj, keys) {
53
52
  const res = {};
54
53
  const len = keys.length;
55
54
  let idx = -1;
56
55
  let key;
57
-
58
56
  while (++idx < len) {
59
57
  key = keys[idx];
60
-
61
58
  if (key in obj) {
62
59
  res[key] = obj[key];
63
60
  }
64
61
  }
65
-
66
62
  return res;
67
63
  }
68
-
69
64
  var _default = pickProps;
70
65
  exports.default = _default;
@@ -1,19 +1,14 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
8
  exports.safeCloneElement = safeCloneElement;
10
-
11
9
  var _react = _interopRequireDefault(require("react"));
12
-
13
10
  var _console = require("@instructure/console");
14
-
15
11
  var _createChainedFunction = require("@instructure/ui-utils/lib/createChainedFunction.js");
16
-
17
12
  /*
18
13
  * The MIT License (MIT)
19
14
  *
@@ -52,19 +47,21 @@ function safeCloneElement(element, props) {
52
47
  const originalRef = element.ref;
53
48
  const originalRefIsAFunction = typeof originalRef === 'function';
54
49
  const cloneRefIsFunction = typeof cloneRef === 'function';
55
- const mergedProps = { ...props
50
+ const mergedProps = {
51
+ ...props
56
52
  };
57
-
58
53
  if (element.props.style && props.style) {
59
54
  // merge with existing styles
60
- mergedProps.style = { ...element.props.style,
55
+ mergedProps.style = {
56
+ ...element.props.style,
61
57
  ...props.style
62
58
  };
63
- } // prevent overriding existing keys
64
-
59
+ }
65
60
 
66
- mergedProps.key = element.key || props.key; // Add chained function to preserve existing event handlers
61
+ // prevent overriding existing keys
62
+ mergedProps.key = element.key || props.key;
67
63
 
64
+ // Add chained function to preserve existing event handlers
68
65
  Object.keys(props).forEach(prop => {
69
66
  // If prop looks like an event handler "on*" and either
70
67
  // props[props] or element.props[prop] is a function create a chained function.
@@ -76,20 +73,17 @@ function safeCloneElement(element, props) {
76
73
  mergedProps[prop] = (0, _createChainedFunction.createChainedFunction)(element.props[prop], props[prop]);
77
74
  }
78
75
  });
79
-
80
76
  for (var _len = arguments.length, children = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
81
77
  children[_key - 2] = arguments[_key];
82
78
  }
83
-
84
79
  if (originalRef == null || cloneRef == null) {
85
80
  return /*#__PURE__*/_react.default.cloneElement(element, mergedProps, ...children);
86
81
  }
87
-
88
82
  (0, _console.logWarn)(originalRefIsAFunction, `Cloning an element with a ref that will be overwritten because the ref \
89
83
  is not a function. Use a composable callback-style ref instead. \
90
84
  Ignoring ref: ${originalRef}`);
91
- return /*#__PURE__*/_react.default.cloneElement(element, { ...mergedProps,
92
-
85
+ return /*#__PURE__*/_react.default.cloneElement(element, {
86
+ ...mergedProps,
93
87
  ref(component) {
94
88
  if (cloneRefIsFunction) {
95
89
  ;
@@ -97,12 +91,9 @@ Ignoring ref: ${originalRef}`);
97
91
  } else {
98
92
  cloneRef.current = component;
99
93
  }
100
-
101
94
  originalRef(component);
102
95
  }
103
-
104
96
  }, ...children);
105
97
  }
106
-
107
98
  var _default = safeCloneElement;
108
99
  exports.default = _default;
@@ -6,11 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  exports.origin = origin;
8
8
  exports.windowMessageListener = void 0;
9
-
10
9
  var _decorator = require("@instructure/ui-decorator/lib/decorator.js");
11
-
12
10
  var _ownerWindow = require("@instructure/ui-dom-utils/lib/ownerWindow.js");
13
-
14
11
  /*
15
12
  * The MIT License (MIT)
16
13
  *
@@ -50,39 +47,31 @@ var _ownerWindow = require("@instructure/ui-dom-utils/lib/ownerWindow.js");
50
47
  */
51
48
  const windowMessageListener = (0, _decorator.decorator)((ComposedComponent, messageHandler, validSource) => {
52
49
  var _class;
53
-
54
50
  return _class = class extends ComposedComponent {
55
51
  constructor() {
56
52
  super(...arguments);
57
-
58
53
  this.handleMessage = e => {
59
54
  if (this.sourceIsValid(e.source) && e.origin === origin(this) && e.data) {
60
55
  messageHandler.call(this, e.data);
61
56
  }
62
57
  };
63
58
  }
64
-
65
59
  componentDidMount() {
66
60
  const win = (0, _ownerWindow.ownerWindow)(this);
67
61
  win.addEventListener('message', this.handleMessage, false);
68
-
69
62
  if (super.componentDidMount) {
70
63
  super.componentDidMount();
71
64
  }
72
65
  }
73
-
74
66
  componentWillUnmount() {
75
67
  const win = (0, _ownerWindow.ownerWindow)(this);
76
68
  win.removeEventListener('message', this.handleMessage, false);
77
-
78
69
  if (super.componentDidMount) {
79
70
  super.componentDidMount();
80
71
  }
81
72
  }
82
-
83
73
  sourceIsValid(eventSource) {
84
74
  const expectedSource = typeof validSource === 'function' ? validSource.call(this) : validSource;
85
-
86
75
  if (!expectedSource) {
87
76
  return true;
88
77
  } else if (eventSource) {
@@ -93,11 +82,11 @@ const windowMessageListener = (0, _decorator.decorator)((ComposedComponent, mess
93
82
  return false;
94
83
  }
95
84
  }
96
-
97
85
  }, _class.postMessage = function (target, message, origin) {
98
86
  target.postMessage(message, origin);
99
87
  }, _class;
100
88
  });
89
+
101
90
  /**
102
91
  * Return the origin of the owner window of the DOM element
103
92
  *
@@ -106,13 +95,10 @@ const windowMessageListener = (0, _decorator.decorator)((ComposedComponent, mess
106
95
  * @param {DOMElement} node
107
96
  * @returns {String} the origin
108
97
  */
109
-
110
98
  exports.windowMessageListener = windowMessageListener;
111
-
112
99
  function origin(node) {
113
100
  const ownWindow = (0, _ownerWindow.ownerWindow)(node);
114
101
  const location = ownWindow.location;
115
-
116
102
  if (location.protocol === 'file:') {
117
103
  return '*';
118
104
  } else if (location.origin) {
@@ -123,6 +109,5 @@ function origin(node) {
123
109
  return `${location.protocol}//${location.hostname}`;
124
110
  }
125
111
  }
126
-
127
112
  var _default = windowMessageListener;
128
113
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-react-utils",
3
- "version": "8.33.1",
3
+ "version": "8.33.2",
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,17 @@
22
22
  },
23
23
  "license": "MIT",
24
24
  "devDependencies": {
25
- "@instructure/ui-babel-preset": "8.33.1",
26
- "@instructure/ui-test-utils": "8.33.1"
25
+ "@instructure/ui-babel-preset": "8.33.2",
26
+ "@instructure/ui-test-utils": "8.33.2"
27
27
  },
28
28
  "dependencies": {
29
29
  "@babel/runtime": "^7.13.10",
30
30
  "@emotion/is-prop-valid": "^1",
31
- "@instructure/console": "8.33.1",
32
- "@instructure/shared-types": "8.33.1",
33
- "@instructure/ui-decorator": "8.33.1",
34
- "@instructure/ui-dom-utils": "8.33.1",
35
- "@instructure/ui-utils": "8.33.1",
31
+ "@instructure/console": "8.33.2",
32
+ "@instructure/shared-types": "8.33.2",
33
+ "@instructure/ui-decorator": "8.33.2",
34
+ "@instructure/ui-dom-utils": "8.33.2",
35
+ "@instructure/ui-utils": "8.33.2",
36
36
  "hoist-non-react-statics": "^3.3.2",
37
37
  "prop-types": "^15"
38
38
  },