@micromag/core 0.3.175 → 0.3.180

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.js CHANGED
@@ -6,6 +6,8 @@ import isString from 'lodash/isString';
6
6
  import dayjs from 'dayjs';
7
7
  import { EventsManager, MediasParser, StoryParser, ThemeParser } from '@micromag/core';
8
8
  import { createUseEvent, getMediaFilesAsArray } from '@micromag/core/utils';
9
+ import { useDrag } from '@use-gesture/react';
10
+ import { useSpring, useSprings } from '@react-spring/core';
9
11
  import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
10
12
  import { useForm as useForm$1 } from '@folklore/forms';
11
13
  import _defineProperty from '@babel/runtime/helpers/defineProperty';
@@ -17,8 +19,6 @@ import isObject from 'lodash/isObject';
17
19
  import raf from 'raf';
18
20
  import { useScreensManager, useFieldsManager, useTracking, useScreen } from '@micromag/core/contexts';
19
21
  import { match } from 'css-mediaquery';
20
- import { useSprings } from '@react-spring/core';
21
- import { useDrag } from '@use-gesture/react';
22
22
  import clamp from 'lodash/clamp';
23
23
 
24
24
  function useActivityDetector() {
@@ -196,6 +196,120 @@ var useFormattedTime = function useFormattedTime() {
196
196
  var eventsManager$1 = typeof document !== 'undefined' ? new EventsManager(document) : null;
197
197
  var useDocumentEvent = createUseEvent(eventsManager$1);
198
198
 
199
+ var getValueFromSpring = function getValueFromSpring(s) {
200
+ var _ref = s || {},
201
+ _ref$value = _ref.value,
202
+ v = _ref$value === void 0 ? null : _ref$value;
203
+
204
+ var _ref2 = v || {},
205
+ p = _ref2.progress;
206
+
207
+ return p;
208
+ };
209
+
210
+ function useSpringValue(wantedProgress, immediate, params) {
211
+ var _useState = useState(wantedProgress),
212
+ _useState2 = _slicedToArray(_useState, 2),
213
+ progress = _useState2[0],
214
+ setProgress = _useState2[1];
215
+
216
+ var onChange = useCallback(function (spring) {
217
+ return setProgress(getValueFromSpring(spring));
218
+ }, [setProgress]);
219
+
220
+ var _useSpring = useSpring(function () {
221
+ return _objectSpread({
222
+ progress: wantedProgress,
223
+ onChange: onChange,
224
+ immediate: immediate
225
+ }, params);
226
+ }),
227
+ _useSpring2 = _slicedToArray(_useSpring, 2),
228
+ api = _useSpring2[1];
229
+
230
+ useEffect(function () {
231
+ if (wantedProgress !== null) {
232
+ api.start(_objectSpread({
233
+ progress: wantedProgress,
234
+ immediate: immediate
235
+ }, params));
236
+ }
237
+ }, [wantedProgress, immediate, params, api]);
238
+ return immediate ? wantedProgress : progress;
239
+ }
240
+
241
+ function useDragProgress() {
242
+ var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
243
+ wantedProgress = _ref.progress,
244
+ _ref$onTap = _ref.onTap,
245
+ onTap = _ref$onTap === void 0 ? null : _ref$onTap,
246
+ _ref$disabled = _ref.disabled,
247
+ disabled = _ref$disabled === void 0 ? false : _ref$disabled,
248
+ _ref$dragDisabled = _ref.dragDisabled,
249
+ dragDisabled = _ref$dragDisabled === void 0 ? false : _ref$dragDisabled,
250
+ _ref$computeProgress = _ref.computeProgress,
251
+ computeProgress = _ref$computeProgress === void 0 ? null : _ref$computeProgress,
252
+ _ref$onProgress = _ref.onProgress,
253
+ onProgress = _ref$onProgress === void 0 ? null : _ref$onProgress,
254
+ _ref$springParams = _ref.springParams,
255
+ springParams = _ref$springParams === void 0 ? undefined : _ref$springParams;
256
+
257
+ var _useState = useState({
258
+ dragging: false,
259
+ progress: wantedProgress
260
+ }),
261
+ _useState2 = _slicedToArray(_useState, 2),
262
+ _useState2$ = _useState2[0],
263
+ dragging = _useState2$.dragging,
264
+ progress = _useState2$.progress,
265
+ setDragState = _useState2[1];
266
+
267
+ var onDragContent = useCallback(function (gestureState) {
268
+ if (disabled) {
269
+ return;
270
+ }
271
+
272
+ var active = gestureState.active,
273
+ tap = gestureState.tap;
274
+
275
+ if (tap) {
276
+ if (onTap !== null) onTap(gestureState);
277
+ return;
278
+ }
279
+
280
+ if (dragDisabled) {
281
+ return;
282
+ }
283
+
284
+ var newProgress = computeProgress(gestureState);
285
+ setDragState({
286
+ dragging: active,
287
+ progress: newProgress
288
+ });
289
+
290
+ if (onProgress !== null) {
291
+ onProgress(newProgress, gestureState);
292
+ }
293
+ }, [setDragState, disabled, onTap, computeProgress, setDragState, onProgress]);
294
+ var bind = useDrag(onDragContent, {
295
+ filterTaps: true
296
+ });
297
+ var springedProgress = useSpringValue(progress, dragging || disabled, springParams);
298
+ useEffect(function () {
299
+ if (wantedProgress !== progress && !dragging) {
300
+ setDragState({
301
+ dragging: dragging,
302
+ progress: wantedProgress
303
+ });
304
+ }
305
+ }, [wantedProgress]);
306
+ return {
307
+ bind: bind,
308
+ dragging: dragging,
309
+ progress: springedProgress
310
+ };
311
+ }
312
+
199
313
  var _excluded$3 = ["fields", "injectInFields"],
200
314
  _excluded2 = ["fields"];
201
315
 
@@ -751,25 +865,48 @@ var useLongPress = function useLongPress() {
751
865
  var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
752
866
  _ref$onLongPress = _ref.onLongPress,
753
867
  onLongPress = _ref$onLongPress === void 0 ? null : _ref$onLongPress,
868
+ _ref$onLongPressStart = _ref.onLongPressStart,
869
+ onLongPressStart = _ref$onLongPressStart === void 0 ? null : _ref$onLongPressStart,
870
+ _ref$onLongPressEnd = _ref.onLongPressEnd,
871
+ onLongPressEnd = _ref$onLongPressEnd === void 0 ? null : _ref$onLongPressEnd,
754
872
  _ref$onClick = _ref.onClick,
755
873
  onClick = _ref$onClick === void 0 ? null : _ref$onClick,
756
874
  _ref$shouldPreventDef = _ref.shouldPreventDefault,
757
875
  shouldPreventDefault = _ref$shouldPreventDef === void 0 ? true : _ref$shouldPreventDef,
876
+ _ref$shouldStopPropag = _ref.shouldStopPropagation,
877
+ shouldStopPropagation = _ref$shouldStopPropag === void 0 ? false : _ref$shouldStopPropag,
878
+ _ref$preventClick = _ref.preventClick,
879
+ preventClick = _ref$preventClick === void 0 ? false : _ref$preventClick,
758
880
  _ref$delay = _ref.delay,
759
881
  delay = _ref$delay === void 0 ? 350 : _ref$delay;
760
882
 
761
883
  var _useState = useState(false),
762
884
  _useState2 = _slicedToArray(_useState, 2),
763
- longPressTriggered = _useState2[0],
764
- setLongPressTriggered = _useState2[1];
885
+ pressed = _useState2[0],
886
+ setPressed = _useState2[1];
887
+
888
+ var _useState3 = useState(false),
889
+ _useState4 = _slicedToArray(_useState3, 2),
890
+ triggered = _useState4[0],
891
+ setTriggered = _useState4[1];
765
892
 
766
893
  var timeout = useRef(null);
767
894
  var target = useRef(null);
768
- var start = useCallback(function (event) {
895
+ var start = useCallback(function (event, props) {
896
+ setPressed(true);
897
+
898
+ if (shouldStopPropagation) {
899
+ event.stopPropagation();
900
+ }
901
+
769
902
  if (event.target !== null) {
770
903
  target.current = event.target;
771
904
  }
772
905
 
906
+ if (onLongPressStart !== null) {
907
+ onLongPressStart(event, props);
908
+ }
909
+
773
910
  timeout.current = setTimeout(function () {
774
911
  if (shouldPreventDefault && target.current !== null) {
775
912
  target.current.addEventListener('touchend', preventDefault, {
@@ -780,16 +917,23 @@ var useLongPress = function useLongPress() {
780
917
  });
781
918
  }
782
919
 
920
+ setTriggered(true);
921
+
783
922
  if (onLongPress !== null) {
784
- onLongPress(event);
923
+ onLongPress(event, props);
924
+ setPressed(false);
785
925
  }
786
926
 
787
- setLongPressTriggered(true);
788
927
  timeout.current = null;
789
928
  }, delay);
790
- }, [onLongPress, delay, shouldPreventDefault]);
791
- var clear = useCallback(function (event) {
792
- var shouldTriggerClick = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
929
+ }, [onLongPress, onLongPressStart, delay, setPressed, shouldPreventDefault]);
930
+ var clear = useCallback(function (event, props) {
931
+ var shouldTriggerClick = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
932
+ setPressed(false);
933
+
934
+ if (preventClick && triggered) {
935
+ return;
936
+ }
793
937
 
794
938
  if (timeout.current !== null) {
795
939
  clearTimeout(timeout.current);
@@ -801,28 +945,39 @@ var useLongPress = function useLongPress() {
801
945
  }, 10);
802
946
  }
803
947
 
804
- if (shouldTriggerClick && !longPressTriggered && onClick !== null) {
805
- onClick();
948
+ if (shouldTriggerClick && !triggered && onClick !== null) {
949
+ onClick(props);
806
950
  }
807
951
 
808
- setLongPressTriggered(false);
809
- }, [shouldPreventDefault, onClick, longPressTriggered]);
952
+ onLongPressEnd(event, props, triggered);
953
+ setTriggered(false);
954
+ }, [shouldPreventDefault, onClick, onLongPressEnd, setPressed, triggered, preventClick]);
955
+
956
+ var bind = function bind() {
957
+ var props = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
958
+ return {
959
+ onMouseDown: function onMouseDown(e) {
960
+ return start(e, props);
961
+ },
962
+ onTouchStart: function onTouchStart(e) {
963
+ return start(e, props);
964
+ },
965
+ onMouseUp: function onMouseUp(e) {
966
+ return clear(e, props);
967
+ },
968
+ onMouseLeave: function onMouseLeave(e) {
969
+ return clear(e, props, false);
970
+ },
971
+ onTouchEnd: function onTouchEnd(e) {
972
+ return clear(e, props);
973
+ }
974
+ };
975
+ };
976
+
810
977
  return {
811
- onMouseDown: function onMouseDown(e) {
812
- return start(e);
813
- },
814
- onTouchStart: function onTouchStart(e) {
815
- return start(e);
816
- },
817
- onMouseUp: function onMouseUp(e) {
818
- return clear(e);
819
- },
820
- onMouseLeave: function onMouseLeave(e) {
821
- return clear(e, false);
822
- },
823
- onTouchEnd: function onTouchEnd(e) {
824
- return clear(e);
825
- }
978
+ bind: bind,
979
+ pressed: pressed,
980
+ triggered: triggered
826
981
  };
827
982
  };
828
983
 
@@ -2172,4 +2327,4 @@ var useTrackMedia = function useTrackMedia() {
2172
2327
  var eventsManager = typeof window !== 'undefined' ? new EventsManager(window) : null;
2173
2328
  var useWindowEvent = createUseEvent(eventsManager);
2174
2329
 
2175
- export { getObserver, useActivityDetector, useAnimationFrame, useDimensionObserver, useDocumentEvent, useForm, useFormTransition, useFormattedDate, useFormattedTime, useFullscreen, useIntersectionObserver, useIsVisible, useLoadedFonts, useLongPress, useMediaApi, useMediaCurrentTime, useMediaDuration, useMediaLoad, useMediaProgress, useMediaReady, useMediaThumbnail, useMediaWaveform, useMediasParser, useObserver, useParsedStory, useProgressSteps, useResizeObserver, useScreenSizeFromElement, useScreenSizeFromWindow, useSwipe, useThemeParser, useTrackEvent, useTrackMedia, useTrackScreenEvent, useTrackScreenMedia, useTrackScreenView, useWindowEvent };
2330
+ export { getObserver, useActivityDetector, useAnimationFrame, useDimensionObserver, useDocumentEvent, useDragProgress, useForm, useFormTransition, useFormattedDate, useFormattedTime, useFullscreen, useIntersectionObserver, useIsVisible, useLoadedFonts, useLongPress, useMediaApi, useMediaCurrentTime, useMediaDuration, useMediaLoad, useMediaProgress, useMediaReady, useMediaThumbnail, useMediaWaveform, useMediasParser, useObserver, useParsedStory, useProgressSteps, useResizeObserver, useScreenSizeFromElement, useScreenSizeFromWindow, useSpringValue, useSwipe, useThemeParser, useTrackEvent, useTrackMedia, useTrackScreenEvent, useTrackScreenMedia, useTrackScreenView, useWindowEvent };
package/es/index.js CHANGED
@@ -577,7 +577,7 @@ var pageMetadata = PropTypes$1.shape({
577
577
  microformats: PropTypes$1.arrayOf(PropTypes$1.shape({}))
578
578
  });
579
579
  var authorElement = PropTypes$1.shape({
580
- name: PropTypes$1.string,
580
+ name: textElement,
581
581
  avatar: PropTypes$1.shape({
582
582
  url: PropTypes$1.string
583
583
  })
package/es/utils.js CHANGED
@@ -195,6 +195,94 @@ var createUseEvent = function createUseEvent(eventsManager) {
195
195
  };
196
196
  };
197
197
 
198
+ /* eslint-disable */
199
+ var easings = {
200
+ linear: function linear(x) {
201
+ return x;
202
+ },
203
+ easeInQuad: function easeInQuad(x) {
204
+ return x * x;
205
+ },
206
+ easeOutQuad: function easeOutQuad(x) {
207
+ return 1 - (1 - x) * (1 - x);
208
+ },
209
+ easeInOutQuad: function easeInOutQuad(x) {
210
+ return x < 0.5 ? 2 * x * x : 1 - Math.pow(-2 * x + 2, 2) / 2;
211
+ },
212
+ easeInCubic: function easeInCubic(x) {
213
+ return x * x * x;
214
+ },
215
+ easeOutCubic: function easeOutCubic(x) {
216
+ return 1 - Math.pow(1 - x, 3);
217
+ },
218
+ easeInOutCubic: function easeInOutCubic(x) {
219
+ return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;
220
+ },
221
+ easeInQuart: function easeInQuart(x) {
222
+ return x * x * x * x;
223
+ },
224
+ easeOutQuart: function easeOutQuart(x) {
225
+ return 1 - Math.pow(1 - x, 4);
226
+ },
227
+ easeInOutQuart: function easeInOutQuart(x) {
228
+ return x < 0.5 ? 8 * x * x * x * x : 1 - Math.pow(-2 * x + 2, 4) / 2;
229
+ },
230
+ easeInQuint: function easeInQuint(x) {
231
+ return x * x * x * x * x;
232
+ },
233
+ easeOutQuint: function easeOutQuint(x) {
234
+ return 1 - Math.pow(1 - x, 5);
235
+ },
236
+ easeInOutQuint: function easeInOutQuint(x) {
237
+ return x < 0.5 ? 16 * x * x * x * x * x : 1 - Math.pow(-2 * x + 2, 5) / 2;
238
+ },
239
+ easeInSine: function easeInSine(x) {
240
+ return 1 - Math.cos(x * Math.PI / 2);
241
+ },
242
+ easeOutSine: function easeOutSine(x) {
243
+ return Math.sin(x * Math.PI / 2);
244
+ },
245
+ easeInOutSine: function easeInOutSine(x) {
246
+ return -(Math.cos(Math.PI * x) - 1) / 2;
247
+ },
248
+ easeInExpo: function easeInExpo(x) {
249
+ return x === 0 ? 0 : Math.pow(2, 10 * x - 10);
250
+ },
251
+ easeOutExpo: function easeOutExpo(x) {
252
+ return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
253
+ },
254
+ easeInOutExpo: function easeInOutExpo(x) {
255
+ return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? Math.pow(2, 20 * x - 10) / 2 : (2 - Math.pow(2, -20 * x + 10)) / 2;
256
+ },
257
+ easeInCirc: function easeInCirc(x) {
258
+ return 1 - Math.sqrt(1 - Math.pow(x, 2));
259
+ },
260
+ easeOutCirc: function easeOutCirc(x) {
261
+ return Math.sqrt(1 - Math.pow(x - 1, 2));
262
+ },
263
+ easeInOutCirc: function easeInOutCirc(x) {
264
+ return x < 0.5 ? (1 - Math.sqrt(1 - Math.pow(2 * x, 2))) / 2 : (Math.sqrt(1 - Math.pow(-2 * x + 2, 2)) + 1) / 2;
265
+ },
266
+ easeInBack: function easeInBack(x) {
267
+ return c3 * x * x * x - c1 * x * x;
268
+ },
269
+ easeOutBack: function easeOutBack(x) {
270
+ return 1 + c3 * Math.pow(x - 1, 3) + c1 * Math.pow(x - 1, 2);
271
+ },
272
+ easeInOutBack: function easeInOutBack(x) {
273
+ return x < 0.5 ? Math.pow(2 * x, 2) * ((c2 + 1) * 2 * x - c2) / 2 : (Math.pow(2 * x - 2, 2) * ((c2 + 1) * (x * 2 - 2) + c2) + 2) / 2;
274
+ },
275
+ easeInElastic: function easeInElastic(x) {
276
+ return x === 0 ? 0 : x === 1 ? 1 : -Math.pow(2, 10 * x - 10) * Math.sin((x * 10 - 10.75) * c4);
277
+ },
278
+ easeOutElastic: function easeOutElastic(x) {
279
+ return x === 0 ? 0 : x === 1 ? 1 : Math.pow(2, -10 * x) * Math.sin((x * 10 - 0.75) * c4) + 1;
280
+ },
281
+ easeInOutElastic: function easeInOutElastic(x) {
282
+ return x === 0 ? 0 : x === 1 ? 1 : x < 0.5 ? -(Math.pow(2, 20 * x - 10) * Math.sin((20 * x - 11.125) * c5)) / 2 : Math.pow(2, -20 * x + 10) * Math.sin((20 * x - 11.125) * c5) / 2 + 1;
283
+ }
284
+ };
285
+
198
286
  var getColorAsString = function getColorAsString() {
199
287
  var value = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : null;
200
288
  var overideAlpha = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
@@ -1005,4 +1093,4 @@ var getContrastingColor = function getContrastingColor(backgroundColor) {
1005
1093
  return tinycolor(color).spin(30).toString();
1006
1094
  };
1007
1095
 
1008
- export { convertStyleToString, copyToClipboard, createNullableOnChange, createUseEvent, getColorAsString, getComponentFromName, getContrastingColor, getDeviceScreens, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getFontFamily as getFontFamilyFromFont, getGridLayoutName, largestRemainderRound as getLargestRemainderRound, getLayersFromBackground, getLayoutParts, getMediaFilesAsArray, getOptimalImageUrl, getScreenExtraField, getSecondsFromTime, getShadowCoords, getStyleFromBorder, getStyleFromBox, getStyleFromColor, getStyleFromContainer, getStyleFromHighlight, getStyleFromImage, getStyleFromLink, getStyleFromMargin, getStyleFromText, isImageFilled, isIos, isTextFilled$1 as isLabelFilled, isMessage, isTextFilled, isValidUrl, schemaId, setValue as setFieldValue, slug, unique, validateFields };
1096
+ export { convertStyleToString, copyToClipboard, createNullableOnChange, createUseEvent, easings, getColorAsString, getComponentFromName, getContrastingColor, getDeviceScreens, getDisplayName, getFieldByName, getFieldFromPath, getFileName, getFontFamily as getFontFamilyFromFont, getGridLayoutName, largestRemainderRound as getLargestRemainderRound, getLayersFromBackground, getLayoutParts, getMediaFilesAsArray, getOptimalImageUrl, getScreenExtraField, getSecondsFromTime, getShadowCoords, getStyleFromBorder, getStyleFromBox, getStyleFromColor, getStyleFromContainer, getStyleFromHighlight, getStyleFromImage, getStyleFromLink, getStyleFromMargin, getStyleFromText, isImageFilled, isIos, isTextFilled$1 as isLabelFilled, isMessage, isTextFilled, isValidUrl, schemaId, setValue as setFieldValue, slug, unique, validateFields };