@micromag/core 0.4.52 → 0.4.54

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.
package/es/hooks.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import * as react from 'react';
2
- import * as _use_gesture_react_dist_declarations_src_types from '@use-gesture/react/dist/declarations/src/types';
3
2
  import * as _react_spring_core from '@react-spring/core';
3
+ import * as _use_gesture_react_dist_declarations_src_types from '@use-gesture/react/dist/declarations/src/types';
4
4
 
5
5
  declare function useActivityDetector({ element: providedElement, disabled, timeout: timeoutDelay }?: {
6
6
  element?: any;
@@ -29,23 +29,24 @@ declare const useDebounced: (handler: any, watchedValue: any, delay?: number) =>
29
29
 
30
30
  declare const useDocumentEvent: (event: any, callback: any, enabled?: boolean) => void;
31
31
 
32
- declare function useDragProgress({ progress: wantedProgress, onTap, disabled, dragDisabled, computeProgress, onProgress, onPointerDown, onScroll, springParams, dragOptions, }?: {
33
- onTap?: any;
32
+ interface UseDragProgressProps {
33
+ progress: number;
34
+ onTap?: (gestureState: any) => void;
34
35
  disabled?: boolean;
35
36
  dragDisabled?: boolean;
36
- computeProgress?: any;
37
- onProgress?: any;
38
- onPointerDown?: any;
39
- onScroll?: any;
40
- springParams?: any;
41
- dragOptions?: {
42
- filterTaps: boolean;
43
- };
44
- }): {
45
- transitioning: any;
37
+ computeProgress?: (gestureState: any) => number | null;
38
+ onProgress?: (progress: number, gestureState: any) => void | null;
39
+ onPointerDown?: (gestureState: any) => void | null;
40
+ onResolve?: (event: any) => void | null;
41
+ onScroll?: (gestureState: any) => void | null;
42
+ springParams?: object;
43
+ dragOptions?: object;
44
+ }
45
+ declare function useDragProgress({ progress: wantedProgress, onTap, disabled, dragDisabled, computeProgress, onProgress, onPointerDown, onResolve, onScroll, springParams, dragOptions, }: UseDragProgressProps): {
46
+ transitioning: boolean;
46
47
  bind: (...args: any[]) => _use_gesture_react_dist_declarations_src_types.ReactDOMAttributes;
47
48
  dragging: boolean;
48
- progress: any;
49
+ progress: _react_spring_core.SpringValue<number>;
49
50
  direction: number;
50
51
  };
51
52
 
package/es/hooks.js CHANGED
@@ -190,9 +190,8 @@ var useDebounced = function useDebounced(handler, watchedValue) {
190
190
  var eventsManager$1 = typeof document !== 'undefined' ? new EventsManager(document) : null;
191
191
  var useDocumentEvent = createUseEvent(eventsManager$1);
192
192
 
193
- function useDragProgress() {
194
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
195
- wantedProgress = _ref.progress,
193
+ function useDragProgress(_ref) {
194
+ var wantedProgress = _ref.progress,
196
195
  _ref$onTap = _ref.onTap,
197
196
  onTap = _ref$onTap === void 0 ? null : _ref$onTap,
198
197
  _ref$disabled = _ref.disabled,
@@ -205,6 +204,8 @@ function useDragProgress() {
205
204
  onProgress = _ref$onProgress === void 0 ? null : _ref$onProgress,
206
205
  _ref$onPointerDown = _ref.onPointerDown,
207
206
  onPointerDown = _ref$onPointerDown === void 0 ? null : _ref$onPointerDown,
207
+ _ref$onResolve = _ref.onResolve,
208
+ _onResolve = _ref$onResolve === void 0 ? null : _ref$onResolve,
208
209
  _ref$onScroll = _ref.onScroll,
209
210
  onScroll = _ref$onScroll === void 0 ? null : _ref$onScroll,
210
211
  _ref$springParams = _ref.springParams,
@@ -213,8 +214,8 @@ function useDragProgress() {
213
214
  dragOptions = _ref$dragOptions === void 0 ? {
214
215
  filterTaps: true
215
216
  } : _ref$dragOptions;
216
- var refDragging = useRef(false);
217
- var refProgress = useRef(wantedProgress);
217
+ var draggingRef = useRef(false);
218
+ var progressRef = useRef(wantedProgress);
218
219
  var wantedProgressRef = useRef(wantedProgress);
219
220
  if (wantedProgress !== wantedProgressRef.current) {
220
221
  wantedProgressRef.current = wantedProgress;
@@ -249,36 +250,39 @@ function useDragProgress() {
249
250
  var active = gestureState.active,
250
251
  tap = gestureState.tap;
251
252
  if (disabled) {
252
- refDragging.current = false;
253
+ draggingRef.current = false;
253
254
  return;
254
255
  }
255
256
  if (tap) {
256
- refDragging.current = false;
257
+ draggingRef.current = false;
257
258
  if (onTap !== null) onTap(gestureState);
258
259
  return;
259
260
  }
260
261
  if (dragDisabled) {
261
- refDragging.current = false;
262
+ draggingRef.current = false;
262
263
  return;
263
264
  }
264
265
  var newProgress = computeProgress(gestureState);
265
- refDragging.current = active;
266
+ draggingRef.current = active;
266
267
  setDirection(newProgress < wantedProgressRef.current ? -1 : 1);
267
- refProgress.current = newProgress;
268
+ progressRef.current = newProgress;
268
269
  if (active !== dragging) {
269
270
  setDragging(active);
270
271
  }
271
272
  api.start(_objectSpread({
272
273
  progress: newProgress,
273
274
  immediate: active,
274
- onResolve: !active ? function () {
275
+ onResolve: !active ? function (e) {
275
276
  setDirection(0);
276
- } : function () {}
277
+ if (_onResolve !== null) _onResolve(e);
278
+ } : function (e) {
279
+ if (_onResolve !== null) _onResolve(e);
280
+ }
277
281
  }, springParams));
278
282
  if (onProgress !== null) {
279
283
  onProgress(newProgress, gestureState);
280
284
  }
281
- }, [setDragging, disabled, onTap, computeProgress, dragging, onProgress]);
285
+ }, [setDragging, disabled, onTap, computeProgress, dragging, onProgress, _onResolve]);
282
286
  var bind = useGesture({
283
287
  onDrag: onDrag,
284
288
  onPointerDown: onPointerDown !== null ? onPointerDown : function () {},
@@ -287,14 +291,15 @@ function useDragProgress() {
287
291
  drag: dragOptions
288
292
  });
289
293
  useEffect(function () {
290
- if (!refDragging.current && wantedProgress !== refProgress.current) {
291
- setDirection(wantedProgress < refProgress.current ? -1 : 1);
292
- refProgress.current = wantedProgress;
294
+ if (!draggingRef.current && wantedProgress !== progressRef.current) {
295
+ setDirection(wantedProgress < progressRef.current ? -1 : 1);
296
+ progressRef.current = wantedProgress;
293
297
  api.start(_objectSpread({
294
298
  progress: wantedProgress,
295
299
  immediate: disabled,
296
- onResolve: function onResolve() {
300
+ onResolve: function onResolve(e) {
297
301
  setDirection(0);
302
+ if (_onResolve !== null) _onResolve(e);
298
303
  }
299
304
  }, springParams));
300
305
  }
@@ -544,7 +549,17 @@ var useObserver = function useObserver(Observer) {
544
549
  useEffect(function () {
545
550
  var nodeElement = nodeRef.current;
546
551
  var callback = function callback(newEntry) {
547
- return setEntry(newEntry);
552
+ return setEntry(function (prev) {
553
+ // Avoid re-renders when ResizeObserver fires with unchanged dimensions
554
+ if (prev !== null && prev !== void 0 && prev.contentRect && newEntry !== null && newEntry !== void 0 && newEntry.contentRect) {
555
+ var p = prev.contentRect;
556
+ var n = newEntry.contentRect;
557
+ if (p.width === n.width && p.height === n.height) {
558
+ return prev;
559
+ }
560
+ }
561
+ return newEntry;
562
+ });
548
563
  };
549
564
  var unsubscribe = null;
550
565
  if (nodeElement !== null) {
package/es/utils.d.ts CHANGED
@@ -118,6 +118,15 @@ declare const getStyleFromAlignment: (value: any, invertAxis?: boolean, defaultA
118
118
  };
119
119
 
120
120
  declare const getStyleFromBox: (value: any) => {
121
+ paddingTop: any;
122
+ paddingRight: any;
123
+ paddingBottom: any;
124
+ paddingLeft: any;
125
+ boxShadow: string;
126
+ borderStyle: any;
127
+ borderWidth: any;
128
+ borderRadius: any;
129
+ } | {
121
130
  paddingLeft: any;
122
131
  paddingBottom: any;
123
132
  paddingRight: any;
package/es/utils.js CHANGED
@@ -822,19 +822,34 @@ var getStyleFromBox = function getStyleFromBox(value) {
822
822
  paddingValueLeft = _ref$left === void 0 ? null : _ref$left,
823
823
  _ref$padding = _ref.padding,
824
824
  paddingValue = _ref$padding === void 0 ? null : _ref$padding;
825
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, getStyleFromColor(backgroundColor, 'backgroundColor')), borderRadius !== null ? {
826
- borderRadius: borderRadius
827
- } : null), getStyleFromBorder(border)), getStyleFromShadow(shadow)), padding !== null || paddingValue !== null ? {
828
- padding: padding || paddingValue
829
- } : null), paddingTop !== null || paddingValueTop !== null ? {
830
- paddingTop: paddingTop || paddingValueTop
831
- } : null), paddingRight !== null || paddingValueRight != null ? {
832
- paddingRight: paddingRight || paddingValueRight
833
- } : null), paddingBottom !== null || paddingValueBottom !== null ? {
834
- paddingBottom: paddingBottom || paddingValueBottom
835
- } : null), paddingLeft !== null || paddingValueLeft !== null ? {
836
- paddingLeft: paddingLeft || paddingValueLeft
825
+ var basePadding = padding || paddingValue;
826
+ var hasBasePadding = basePadding !== null;
827
+ var topVal = paddingTop || paddingValueTop;
828
+ var rightVal = paddingRight || paddingValueRight;
829
+ var bottomVal = paddingBottom || paddingValueBottom;
830
+ var leftVal = paddingLeft || paddingValueLeft;
831
+ var hasAnyIndividual = topVal !== null || rightVal !== null || bottomVal !== null || leftVal !== null;
832
+
833
+ // Avoid mixing shorthand `padding` with longhand `paddingTop`/etc React warns about this
834
+ var paddingStyles = hasBasePadding && hasAnyIndividual ? {
835
+ paddingTop: topVal !== null && topVal !== void 0 ? topVal : basePadding,
836
+ paddingRight: rightVal !== null && rightVal !== void 0 ? rightVal : basePadding,
837
+ paddingBottom: bottomVal !== null && bottomVal !== void 0 ? bottomVal : basePadding,
838
+ paddingLeft: leftVal !== null && leftVal !== void 0 ? leftVal : basePadding
839
+ } : _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, hasBasePadding ? {
840
+ padding: basePadding
841
+ } : null), topVal !== null ? {
842
+ paddingTop: topVal
843
+ } : null), rightVal !== null ? {
844
+ paddingRight: rightVal
845
+ } : null), bottomVal !== null ? {
846
+ paddingBottom: bottomVal
847
+ } : null), leftVal !== null ? {
848
+ paddingLeft: leftVal
837
849
  } : null);
850
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, getStyleFromColor(backgroundColor, 'backgroundColor')), borderRadius !== null ? {
851
+ borderRadius: borderRadius
852
+ } : null), getStyleFromBorder(border)), getStyleFromShadow(shadow)), paddingStyles);
838
853
  };
839
854
 
840
855
  var getStyleFromContainer = function getStyleFromContainer(value) {
package/lib/hooks.js CHANGED
@@ -192,9 +192,8 @@ var useDebounced = function useDebounced(handler, watchedValue) {
192
192
  var eventsManager$1 = typeof document !== 'undefined' ? new core.EventsManager(document) : null;
193
193
  var useDocumentEvent = utils.createUseEvent(eventsManager$1);
194
194
 
195
- function useDragProgress() {
196
- var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
197
- wantedProgress = _ref.progress,
195
+ function useDragProgress(_ref) {
196
+ var wantedProgress = _ref.progress,
198
197
  _ref$onTap = _ref.onTap,
199
198
  onTap = _ref$onTap === void 0 ? null : _ref$onTap,
200
199
  _ref$disabled = _ref.disabled,
@@ -207,6 +206,8 @@ function useDragProgress() {
207
206
  onProgress = _ref$onProgress === void 0 ? null : _ref$onProgress,
208
207
  _ref$onPointerDown = _ref.onPointerDown,
209
208
  onPointerDown = _ref$onPointerDown === void 0 ? null : _ref$onPointerDown,
209
+ _ref$onResolve = _ref.onResolve,
210
+ _onResolve = _ref$onResolve === void 0 ? null : _ref$onResolve,
210
211
  _ref$onScroll = _ref.onScroll,
211
212
  onScroll = _ref$onScroll === void 0 ? null : _ref$onScroll,
212
213
  _ref$springParams = _ref.springParams,
@@ -215,8 +216,8 @@ function useDragProgress() {
215
216
  dragOptions = _ref$dragOptions === void 0 ? {
216
217
  filterTaps: true
217
218
  } : _ref$dragOptions;
218
- var refDragging = react.useRef(false);
219
- var refProgress = react.useRef(wantedProgress);
219
+ var draggingRef = react.useRef(false);
220
+ var progressRef = react.useRef(wantedProgress);
220
221
  var wantedProgressRef = react.useRef(wantedProgress);
221
222
  if (wantedProgress !== wantedProgressRef.current) {
222
223
  wantedProgressRef.current = wantedProgress;
@@ -251,36 +252,39 @@ function useDragProgress() {
251
252
  var active = gestureState.active,
252
253
  tap = gestureState.tap;
253
254
  if (disabled) {
254
- refDragging.current = false;
255
+ draggingRef.current = false;
255
256
  return;
256
257
  }
257
258
  if (tap) {
258
- refDragging.current = false;
259
+ draggingRef.current = false;
259
260
  if (onTap !== null) onTap(gestureState);
260
261
  return;
261
262
  }
262
263
  if (dragDisabled) {
263
- refDragging.current = false;
264
+ draggingRef.current = false;
264
265
  return;
265
266
  }
266
267
  var newProgress = computeProgress(gestureState);
267
- refDragging.current = active;
268
+ draggingRef.current = active;
268
269
  setDirection(newProgress < wantedProgressRef.current ? -1 : 1);
269
- refProgress.current = newProgress;
270
+ progressRef.current = newProgress;
270
271
  if (active !== dragging) {
271
272
  setDragging(active);
272
273
  }
273
274
  api.start(_objectSpread({
274
275
  progress: newProgress,
275
276
  immediate: active,
276
- onResolve: !active ? function () {
277
+ onResolve: !active ? function (e) {
277
278
  setDirection(0);
278
- } : function () {}
279
+ if (_onResolve !== null) _onResolve(e);
280
+ } : function (e) {
281
+ if (_onResolve !== null) _onResolve(e);
282
+ }
279
283
  }, springParams));
280
284
  if (onProgress !== null) {
281
285
  onProgress(newProgress, gestureState);
282
286
  }
283
- }, [setDragging, disabled, onTap, computeProgress, dragging, onProgress]);
287
+ }, [setDragging, disabled, onTap, computeProgress, dragging, onProgress, _onResolve]);
284
288
  var bind = react$1.useGesture({
285
289
  onDrag: onDrag,
286
290
  onPointerDown: onPointerDown !== null ? onPointerDown : function () {},
@@ -289,14 +293,15 @@ function useDragProgress() {
289
293
  drag: dragOptions
290
294
  });
291
295
  react.useEffect(function () {
292
- if (!refDragging.current && wantedProgress !== refProgress.current) {
293
- setDirection(wantedProgress < refProgress.current ? -1 : 1);
294
- refProgress.current = wantedProgress;
296
+ if (!draggingRef.current && wantedProgress !== progressRef.current) {
297
+ setDirection(wantedProgress < progressRef.current ? -1 : 1);
298
+ progressRef.current = wantedProgress;
295
299
  api.start(_objectSpread({
296
300
  progress: wantedProgress,
297
301
  immediate: disabled,
298
- onResolve: function onResolve() {
302
+ onResolve: function onResolve(e) {
299
303
  setDirection(0);
304
+ if (_onResolve !== null) _onResolve(e);
300
305
  }
301
306
  }, springParams));
302
307
  }
@@ -546,7 +551,17 @@ var useObserver = function useObserver(Observer) {
546
551
  react.useEffect(function () {
547
552
  var nodeElement = nodeRef.current;
548
553
  var callback = function callback(newEntry) {
549
- return setEntry(newEntry);
554
+ return setEntry(function (prev) {
555
+ // Avoid re-renders when ResizeObserver fires with unchanged dimensions
556
+ if (prev !== null && prev !== void 0 && prev.contentRect && newEntry !== null && newEntry !== void 0 && newEntry.contentRect) {
557
+ var p = prev.contentRect;
558
+ var n = newEntry.contentRect;
559
+ if (p.width === n.width && p.height === n.height) {
560
+ return prev;
561
+ }
562
+ }
563
+ return newEntry;
564
+ });
550
565
  };
551
566
  var unsubscribe = null;
552
567
  if (nodeElement !== null) {
package/lib/utils.js CHANGED
@@ -823,19 +823,34 @@ var getStyleFromBox = function getStyleFromBox(value) {
823
823
  paddingValueLeft = _ref$left === void 0 ? null : _ref$left,
824
824
  _ref$padding = _ref.padding,
825
825
  paddingValue = _ref$padding === void 0 ? null : _ref$padding;
826
- return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, getStyleFromColor(backgroundColor, 'backgroundColor')), borderRadius !== null ? {
827
- borderRadius: borderRadius
828
- } : null), getStyleFromBorder(border)), getStyleFromShadow(shadow)), padding !== null || paddingValue !== null ? {
829
- padding: padding || paddingValue
830
- } : null), paddingTop !== null || paddingValueTop !== null ? {
831
- paddingTop: paddingTop || paddingValueTop
832
- } : null), paddingRight !== null || paddingValueRight != null ? {
833
- paddingRight: paddingRight || paddingValueRight
834
- } : null), paddingBottom !== null || paddingValueBottom !== null ? {
835
- paddingBottom: paddingBottom || paddingValueBottom
836
- } : null), paddingLeft !== null || paddingValueLeft !== null ? {
837
- paddingLeft: paddingLeft || paddingValueLeft
826
+ var basePadding = padding || paddingValue;
827
+ var hasBasePadding = basePadding !== null;
828
+ var topVal = paddingTop || paddingValueTop;
829
+ var rightVal = paddingRight || paddingValueRight;
830
+ var bottomVal = paddingBottom || paddingValueBottom;
831
+ var leftVal = paddingLeft || paddingValueLeft;
832
+ var hasAnyIndividual = topVal !== null || rightVal !== null || bottomVal !== null || leftVal !== null;
833
+
834
+ // Avoid mixing shorthand `padding` with longhand `paddingTop`/etc React warns about this
835
+ var paddingStyles = hasBasePadding && hasAnyIndividual ? {
836
+ paddingTop: topVal !== null && topVal !== void 0 ? topVal : basePadding,
837
+ paddingRight: rightVal !== null && rightVal !== void 0 ? rightVal : basePadding,
838
+ paddingBottom: bottomVal !== null && bottomVal !== void 0 ? bottomVal : basePadding,
839
+ paddingLeft: leftVal !== null && leftVal !== void 0 ? leftVal : basePadding
840
+ } : _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, hasBasePadding ? {
841
+ padding: basePadding
842
+ } : null), topVal !== null ? {
843
+ paddingTop: topVal
844
+ } : null), rightVal !== null ? {
845
+ paddingRight: rightVal
846
+ } : null), bottomVal !== null ? {
847
+ paddingBottom: bottomVal
848
+ } : null), leftVal !== null ? {
849
+ paddingLeft: leftVal
838
850
  } : null);
851
+ return _objectSpread(_objectSpread(_objectSpread(_objectSpread(_objectSpread({}, getStyleFromColor(backgroundColor, 'backgroundColor')), borderRadius !== null ? {
852
+ borderRadius: borderRadius
853
+ } : null), getStyleFromBorder(border)), getStyleFromShadow(shadow)), paddingStyles);
839
854
  };
840
855
 
841
856
  var getStyleFromContainer = function getStyleFromContainer(value) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@micromag/core",
3
- "version": "0.4.52",
3
+ "version": "0.4.54",
4
4
  "private": false,
5
5
  "description": "",
6
6
  "keywords": [
@@ -161,6 +161,6 @@
161
161
  "access": "public",
162
162
  "registry": "https://registry.npmjs.org/"
163
163
  },
164
- "gitHead": "7e9283049e6904a73ed2c8ac47b2e45465823656",
164
+ "gitHead": "b7aacdebb4a5c2179a58d21ab2aaea5bcdc43d69",
165
165
  "types": "es/index.d.ts"
166
166
  }