@instructure/ui-responsive 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.
@@ -5,15 +5,10 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = exports.addElementQueryMatchListener = void 0;
7
7
  exports.updateElementMatches = updateElementMatches;
8
-
9
8
  var _parseQuery = require("./parseQuery");
10
-
11
9
  var _findDOMNode = require("@instructure/ui-dom-utils/lib/findDOMNode.js");
12
-
13
10
  var _getBoundingClientRect = require("@instructure/ui-dom-utils/lib/getBoundingClientRect.js");
14
-
15
11
  var _debounce = require("@instructure/debounce");
16
-
17
12
  /*
18
13
  * The MIT License (MIT)
19
14
  *
@@ -95,24 +90,18 @@ var _debounce = require("@instructure/debounce");
95
90
  */
96
91
  const addElementQueryMatchListener = (query, el, cb) => {
97
92
  const node = typeof el === 'function' ? el() : el;
98
-
99
93
  const _getBoundingClientRec = (0, _getBoundingClientRect.getBoundingClientRect)(node),
100
- width = _getBoundingClientRec.width,
101
- height = _getBoundingClientRec.height;
102
-
94
+ width = _getBoundingClientRec.width,
95
+ height = _getBoundingClientRec.height;
103
96
  let matches = [];
104
-
105
97
  const update = size => {
106
98
  const newMatches = updateElementMatches(query, node, matches, size);
107
-
108
99
  if (newMatches) {
109
100
  matches = newMatches;
110
101
  cb(matches);
111
102
  }
112
-
113
103
  return;
114
104
  };
115
-
116
105
  const debounced = (0, _debounce.debounce)(update, 100, {
117
106
  leading: false,
118
107
  trailing: true
@@ -120,9 +109,8 @@ const addElementQueryMatchListener = (query, el, cb) => {
120
109
  const elementResizeListener = new ResizeObserver(entries => {
121
110
  for (const entry of entries) {
122
111
  const _entry$contentRect = entry.contentRect,
123
- newWidth = _entry$contentRect.width,
124
- newHeight = _entry$contentRect.height;
125
-
112
+ newWidth = _entry$contentRect.width,
113
+ newHeight = _entry$contentRect.height;
126
114
  if (width !== newWidth) {
127
115
  debounced({
128
116
  width: newWidth,
@@ -141,42 +129,34 @@ const addElementQueryMatchListener = (query, el, cb) => {
141
129
  if (elementResizeListener) {
142
130
  elementResizeListener.disconnect();
143
131
  }
144
-
145
132
  if (debounced) {
146
133
  debounced.cancel();
147
134
  }
148
135
  }
149
-
150
136
  };
151
137
  };
152
-
153
138
  exports.addElementQueryMatchListener = addElementQueryMatchListener;
154
-
155
139
  function updateElementMatches(query, el) {
156
140
  let matches = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : [];
157
141
  let size = arguments.length > 3 ? arguments[3] : void 0;
158
142
  const node = (0, _findDOMNode.findDOMNode)(el);
159
-
160
143
  const _ref = size || (0, _getBoundingClientRect.getBoundingClientRect)(node),
161
- width = _ref.width,
162
- height = _ref.height;
163
-
144
+ width = _ref.width,
145
+ height = _ref.height;
164
146
  const matchingQueries = (0, _parseQuery.parseQuery)(query, node)({
165
147
  width,
166
148
  height
167
149
  });
168
- const newMatches = Object.keys(matchingQueries).filter(key => matchingQueries[key]).map(key => key); // only return matches if they have changed
150
+ const newMatches = Object.keys(matchingQueries).filter(key => matchingQueries[key]).map(key => key);
169
151
 
152
+ // only return matches if they have changed
170
153
  if (matches.length !== newMatches.length) {
171
154
  return newMatches;
172
155
  }
173
-
174
156
  if (matches.filter(match => newMatches.indexOf(match) === -1).length > 0) {
175
157
  return newMatches;
176
158
  }
177
-
178
159
  return null;
179
160
  }
180
-
181
161
  var _default = addElementQueryMatchListener;
182
162
  exports.default = _default;
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = exports.addMediaQueryMatchListener = void 0;
7
-
8
7
  var _matchMedia = require("@instructure/ui-dom-utils/lib/matchMedia.js");
9
-
10
8
  var _jsonToMediaQuery = require("./jsonToMediaQuery");
11
-
12
9
  /*
13
10
  * The MIT License (MIT)
14
11
  *
@@ -88,21 +85,16 @@ var _jsonToMediaQuery = require("./jsonToMediaQuery");
88
85
  const addMediaQueryMatchListener = function (query, el, cb) {
89
86
  let matchMedia = arguments.length > 3 && arguments[3] !== void 0 ? arguments[3] : _matchMedia.matchMedia;
90
87
  const node = typeof el === 'function' ? el() : el;
91
-
92
88
  const updateMediaMatches = mediaQueryLists => {
93
89
  const matches = Object.keys(mediaQueryLists).filter(key => mediaQueryLists[key].matches).map(key => key);
94
90
  cb(matches);
95
91
  };
96
-
97
92
  const mediaQueryLists = {};
98
-
99
93
  const listenerCallback = () => {
100
94
  updateMediaMatches(mediaQueryLists);
101
95
  };
102
-
103
96
  Object.keys(query).forEach(key => {
104
97
  const mediaQueryList = matchMedia((0, _jsonToMediaQuery.jsonToMediaQuery)(query[key], node), node);
105
-
106
98
  if (mediaQueryList) {
107
99
  mediaQueryList.addListener(listenerCallback);
108
100
  mediaQueryLists[key] = mediaQueryList;
@@ -117,10 +109,8 @@ const addMediaQueryMatchListener = function (query, el, cb) {
117
109
  });
118
110
  }
119
111
  }
120
-
121
112
  };
122
113
  };
123
-
124
114
  exports.addMediaQueryMatchListener = addMediaQueryMatchListener;
125
115
  var _default = addMediaQueryMatchListener;
126
116
  exports.default = _default;
package/lib/index.js CHANGED
@@ -39,15 +39,9 @@ Object.defineProperty(exports, "parseQuery", {
39
39
  return _parseQuery.parseQuery;
40
40
  }
41
41
  });
42
-
43
42
  var _Responsive = require("./Responsive");
44
-
45
43
  var _addElementQueryMatchListener = require("./addElementQueryMatchListener");
46
-
47
44
  var _addMediaQueryMatchListener = require("./addMediaQueryMatchListener");
48
-
49
45
  var _parseQuery = require("./parseQuery");
50
-
51
46
  var _jsonToMediaQuery = require("./jsonToMediaQuery");
52
-
53
47
  var _ResponsivePropTypes = require("./ResponsivePropTypes");
@@ -5,9 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  exports.jsonToMediaQuery = jsonToMediaQuery;
8
-
9
8
  var _px = require("@instructure/ui-utils/lib/px.js");
10
-
11
9
  /*
12
10
  * The MIT License (MIT)
13
11
  *
@@ -58,35 +56,28 @@ var _px = require("@instructure/ui-utils/lib/px.js");
58
56
  function jsonToMediaQuery(query, el) {
59
57
  // Ensure the query is of the correct form
60
58
  const keys = Object.keys(query);
61
-
62
59
  if (keys.length !== 1) {
63
60
  throw new Error('Expected exactly one key in query object.');
64
61
  }
65
-
66
62
  const key = keys[0];
67
63
  const validKeys = ['minHeight', 'maxHeight', 'minWidth', 'maxWidth'];
68
-
69
64
  if (validKeys.indexOf(key) === -1) {
70
65
  throw new Error(`Invalid key \`${key}\` in query object. Valid keys should consist of one of the following: ` + `${validKeys.join(', ')} (case sensitive)`);
71
66
  }
67
+ const value = query[key];
72
68
 
73
- const value = query[key]; // TS catches this, but we want to throw error in runtime too
74
-
69
+ // TS catches this, but we want to throw error in runtime too
75
70
  if (typeof value !== 'string' && typeof value !== 'number') {
76
71
  throw new Error('The value of the query object must be a string or number.');
77
72
  }
78
-
79
73
  if (!value) {
80
74
  throw new Error('No value supplied for query object');
81
75
  }
82
-
83
76
  return `(${hyphenateQueryKey(key)}: ${(0, _px.px)(value, el)}px)`;
84
77
  }
85
-
86
78
  function hyphenateQueryKey(key) {
87
79
  const lowerCaseKey = key.toLowerCase();
88
80
  return lowerCaseKey.slice(0, 3) + '-' + lowerCaseKey.slice(3);
89
81
  }
90
-
91
82
  var _default = jsonToMediaQuery;
92
83
  exports.default = _default;
package/lib/parseQuery.js CHANGED
@@ -1,17 +1,13 @@
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.parseQuery = parseQuery;
10
-
11
9
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
-
13
10
  var _px = require("@instructure/ui-utils/lib/px.js");
14
-
15
11
  /*
16
12
  * The MIT License (MIT)
17
13
  *
@@ -53,14 +49,15 @@ var _px = require("@instructure/ui-utils/lib/px.js");
53
49
  * true false if it matches
54
50
  */
55
51
  function parseQuery(query, el) {
56
- const rules = {}; // converting values to numerical values and adding initial values to all query keys
52
+ const rules = {};
57
53
 
54
+ // converting values to numerical values and adding initial values to all query keys
58
55
  Object.keys(query).forEach(selectorName => {
59
56
  const _query$selectorName = query[selectorName],
60
- minWidth = _query$selectorName.minWidth,
61
- maxWidth = _query$selectorName.maxWidth,
62
- minHeight = _query$selectorName.minHeight,
63
- maxHeight = _query$selectorName.maxHeight;
57
+ minWidth = _query$selectorName.minWidth,
58
+ maxWidth = _query$selectorName.maxWidth,
59
+ minHeight = _query$selectorName.minHeight,
60
+ maxHeight = _query$selectorName.maxHeight;
64
61
  rules[selectorName] = {
65
62
  minWidth: minWidth && (0, _px.px)(minWidth, el) || 0,
66
63
  maxWidth: maxWidth && (0, _px.px)(maxWidth, el) || Infinity,
@@ -70,22 +67,20 @@ function parseQuery(query, el) {
70
67
  });
71
68
  return function (_ref) {
72
69
  let width = _ref.width,
73
- height = _ref.height;
70
+ height = _ref.height;
74
71
  const selectorMap = {};
75
72
  Object.entries(rules).forEach(_ref2 => {
76
73
  let _ref3 = (0, _slicedToArray2.default)(_ref2, 2),
77
- selectorName = _ref3[0],
78
- query = _ref3[1];
79
-
74
+ selectorName = _ref3[0],
75
+ query = _ref3[1];
80
76
  const minWidth = query.minWidth,
81
- maxWidth = query.maxWidth,
82
- minHeight = query.minHeight,
83
- maxHeight = query.maxHeight;
77
+ maxWidth = query.maxWidth,
78
+ minHeight = query.minHeight,
79
+ maxHeight = query.maxHeight;
84
80
  selectorMap[selectorName] = minWidth <= width && width <= maxWidth && minHeight <= height && height <= maxHeight;
85
81
  });
86
82
  return selectorMap;
87
83
  };
88
84
  }
89
-
90
85
  var _default = parseQuery;
91
86
  exports.default = _default;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@instructure/ui-responsive",
3
- "version": "8.33.1",
3
+ "version": "8.33.2",
4
4
  "description": "A component that allows for rendering a component differently based on either the element or the viewport size",
5
5
  "author": "Instructure, Inc. Engineering and Product Design",
6
6
  "module": "./es/index.js",
@@ -24,19 +24,19 @@
24
24
  "license": "MIT",
25
25
  "dependencies": {
26
26
  "@babel/runtime": "^7.13.10",
27
- "@instructure/console": "8.33.1",
28
- "@instructure/debounce": "8.33.1",
29
- "@instructure/shared-types": "8.33.1",
30
- "@instructure/ui-dom-utils": "8.33.1",
31
- "@instructure/ui-react-utils": "8.33.1",
32
- "@instructure/ui-testable": "8.33.1",
33
- "@instructure/ui-utils": "8.33.1",
27
+ "@instructure/console": "8.33.2",
28
+ "@instructure/debounce": "8.33.2",
29
+ "@instructure/shared-types": "8.33.2",
30
+ "@instructure/ui-dom-utils": "8.33.2",
31
+ "@instructure/ui-react-utils": "8.33.2",
32
+ "@instructure/ui-testable": "8.33.2",
33
+ "@instructure/ui-utils": "8.33.2",
34
34
  "prop-types": "^15"
35
35
  },
36
36
  "devDependencies": {
37
- "@instructure/ui-babel-preset": "8.33.1",
38
- "@instructure/ui-color-utils": "8.33.1",
39
- "@instructure/ui-test-utils": "8.33.1"
37
+ "@instructure/ui-babel-preset": "8.33.2",
38
+ "@instructure/ui-color-utils": "8.33.2",
39
+ "@instructure/ui-test-utils": "8.33.2"
40
40
  },
41
41
  "peerDependencies": {
42
42
  "react": ">=16.8 <=18"