etudes 1.2.0 → 2.0.0

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 (120) hide show
  1. package/README.md +1 -1
  2. package/lib/Accordion.d.ts +80 -71
  3. package/lib/Accordion.js +173 -183
  4. package/lib/Accordion.js.map +1 -1
  5. package/lib/BurgerButton.d.ts +20 -7
  6. package/lib/BurgerButton.js +113 -20
  7. package/lib/BurgerButton.js.map +1 -1
  8. package/lib/Conditional.d.ts +2 -3
  9. package/lib/Conditional.js +0 -1
  10. package/lib/Conditional.js.map +1 -1
  11. package/lib/DebugConsole.d.ts +14 -23
  12. package/lib/DebugConsole.js +86 -87
  13. package/lib/DebugConsole.js.map +1 -1
  14. package/lib/Dial.d.ts +53 -16
  15. package/lib/Dial.js +121 -35
  16. package/lib/Dial.js.map +1 -1
  17. package/lib/Dropdown.d.ts +68 -83
  18. package/lib/Dropdown.js +226 -161
  19. package/lib/Dropdown.js.map +1 -1
  20. package/lib/Each.d.ts +2 -2
  21. package/lib/Each.js.map +1 -1
  22. package/lib/ExtractChild.d.ts +5 -4
  23. package/lib/ExtractChild.js +13 -11
  24. package/lib/ExtractChild.js.map +1 -1
  25. package/lib/ExtractChildren.d.ts +2 -2
  26. package/lib/ExtractChildren.js +7 -5
  27. package/lib/ExtractChildren.js.map +1 -1
  28. package/lib/FlatSVG.d.ts +30 -25
  29. package/lib/FlatSVG.js +28 -37
  30. package/lib/FlatSVG.js.map +1 -1
  31. package/lib/List.d.ts +97 -54
  32. package/lib/List.js +124 -63
  33. package/lib/List.js.map +1 -1
  34. package/lib/MasonryGrid.d.ts +27 -15
  35. package/lib/MasonryGrid.js +163 -148
  36. package/lib/MasonryGrid.js.map +1 -1
  37. package/lib/Panorama.d.ts +100 -21
  38. package/lib/Panorama.js +45 -44
  39. package/lib/Panorama.js.map +1 -1
  40. package/lib/PanoramaSlider.d.ts +65 -23
  41. package/lib/PanoramaSlider.js +150 -45
  42. package/lib/PanoramaSlider.js.map +1 -1
  43. package/lib/RangeSlider.d.ts +29 -89
  44. package/lib/RangeSlider.js +272 -286
  45. package/lib/RangeSlider.js.map +1 -1
  46. package/lib/Repeat.d.ts +4 -3
  47. package/lib/Repeat.js +3 -2
  48. package/lib/Repeat.js.map +1 -1
  49. package/lib/RotatingGallery.d.ts +38 -36
  50. package/lib/RotatingGallery.js +47 -17
  51. package/lib/RotatingGallery.js.map +1 -1
  52. package/lib/SelectableButton.d.ts +13 -4
  53. package/lib/SelectableButton.js +3 -14
  54. package/lib/SelectableButton.js.map +1 -1
  55. package/lib/Slider.d.ts +103 -41
  56. package/lib/Slider.js +182 -82
  57. package/lib/Slider.js.map +1 -1
  58. package/lib/StepwiseSlider.d.ts +146 -59
  59. package/lib/StepwiseSlider.js +248 -142
  60. package/lib/StepwiseSlider.js.map +1 -1
  61. package/lib/SwipeContainer.d.ts +13 -5
  62. package/lib/SwipeContainer.js +5 -15
  63. package/lib/SwipeContainer.js.map +1 -1
  64. package/lib/TextField.d.ts +1 -1
  65. package/lib/TextField.js +5 -15
  66. package/lib/TextField.js.map +1 -1
  67. package/lib/Video.d.ts +30 -51
  68. package/lib/Video.js +77 -119
  69. package/lib/Video.js.map +1 -1
  70. package/lib/WithTooltip.d.ts +16 -18
  71. package/lib/WithTooltip.js +167 -101
  72. package/lib/WithTooltip.js.map +1 -1
  73. package/lib/hooks/useDocumentTitle.d.ts +2 -1
  74. package/lib/hooks/useDocumentTitle.js +2 -1
  75. package/lib/hooks/useDocumentTitle.js.map +1 -1
  76. package/lib/hooks/useDragEffect.d.ts +25 -16
  77. package/lib/hooks/useDragEffect.js +30 -20
  78. package/lib/hooks/useDragEffect.js.map +1 -1
  79. package/lib/hooks/useElementRect.d.ts +2 -1
  80. package/lib/hooks/useElementRect.js +5 -4
  81. package/lib/hooks/useElementRect.js.map +1 -1
  82. package/lib/hooks/useInterval.d.ts +2 -2
  83. package/lib/hooks/useInterval.js +1 -1
  84. package/lib/hooks/useInterval.js.map +1 -1
  85. package/lib/hooks/useLoadImageEffect.d.ts +6 -6
  86. package/lib/hooks/useLoadImageEffect.js.map +1 -1
  87. package/lib/hooks/usePrevious.d.ts +6 -0
  88. package/lib/hooks/usePrevious.js +17 -0
  89. package/lib/hooks/usePrevious.js.map +1 -0
  90. package/lib/hooks/useResizeEffect.d.ts +2 -2
  91. package/lib/hooks/useResizeEffect.js +5 -8
  92. package/lib/hooks/useResizeEffect.js.map +1 -1
  93. package/lib/hooks/useSearchParamState.d.ts +10 -7
  94. package/lib/hooks/useSearchParamState.js +14 -10
  95. package/lib/hooks/useSearchParamState.js.map +1 -1
  96. package/lib/utils/asClassNameDict.d.ts +3 -0
  97. package/lib/utils/asClassNameDict.js +7 -0
  98. package/lib/utils/asClassNameDict.js.map +1 -0
  99. package/lib/utils/asComponentDict.d.ts +5 -0
  100. package/lib/utils/asComponentDict.js +23 -0
  101. package/lib/utils/asComponentDict.js.map +1 -0
  102. package/lib/utils/asStyleDict.d.ts +4 -0
  103. package/lib/utils/asStyleDict.js +7 -0
  104. package/lib/utils/asStyleDict.js.map +1 -0
  105. package/lib/utils/cloneStyledElement.d.ts +18 -0
  106. package/lib/utils/cloneStyledElement.js +63 -0
  107. package/lib/utils/cloneStyledElement.js.map +1 -0
  108. package/lib/utils/styles.d.ts +2 -0
  109. package/lib/utils/styles.js +22 -0
  110. package/lib/utils/styles.js.map +1 -0
  111. package/lib/utils/useDebug.d.ts +2 -0
  112. package/lib/utils/useDebug.js +46 -0
  113. package/lib/utils/useDebug.js.map +1 -0
  114. package/package.json +25 -33
  115. package/lib/AbstractSelectableCollection.d.ts +0 -94
  116. package/lib/AbstractSelectableCollection.js +0 -151
  117. package/lib/AbstractSelectableCollection.js.map +0 -1
  118. package/lib/types/index.d.ts +0 -7
  119. package/lib/types/index.js +0 -3
  120. package/lib/types/index.js.map +0 -1
@@ -50,74 +50,84 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
50
50
  return (mod && mod.__esModule) ? mod : { "default": mod };
51
51
  };
52
52
  Object.defineProperty(exports, "__esModule", { value: true });
53
+ var fast_deep_equal_1 = __importDefault(require("fast-deep-equal"));
53
54
  var interactjs_1 = __importDefault(require("interactjs"));
54
- var lodash_1 = __importDefault(require("lodash"));
55
55
  var react_1 = require("react");
56
56
  /**
57
57
  * Hook for adding effectful dragging interaction to an element.
58
58
  *
59
- * @param targetRef - The reference to the target element to add drag interaction to.
60
- * @param options - Additional options which include options for `module:interactjs.draggable`.
59
+ * @param targetRef - The reference to the target element to add drag
60
+ * interaction to.
61
+ * @param options - Additional options which include options for
62
+ * `module:interactjs.draggable`.
61
63
  * @param deps - Dependencies that trigger this effect.
62
64
  *
63
65
  * @returns The states created for this effect.
64
66
  */
65
67
  function useDragEffect(targetRef, _a, deps) {
66
- var onDragStart = _a.onDragStart, onDragMove = _a.onDragMove, onDragEnd = _a.onDragEnd, initialValue = _a.initialValue, transform = _a.transform, options = __rest(_a, ["onDragStart", "onDragMove", "onDragEnd", "initialValue", "transform"]);
68
+ var initialValue = _a.initialValue, transform = _a.transform, onDragStart = _a.onDragStart, onDragMove = _a.onDragMove, onDragEnd = _a.onDragEnd, options = __rest(_a, ["initialValue", "transform", "onDragStart", "onDragMove", "onDragEnd"]);
67
69
  /**
68
- * Sets the current associated value reference. This reference object is equal to the `value`
69
- * state but differs slightly in how they are set. Because states are asynchronous by nature, this
70
- * reference object is used to cache time-sensitive value changes while drag event happens.
70
+ * Sets the current associated value reference. This reference object is equal
71
+ * to the `value` state but differs slightly in how they are set. Because
72
+ * states are asynchronous by nature, this reference object is used to cache
73
+ * time-sensitive value changes while drag event happens.
71
74
  *
72
75
  * @param value - The value to set the associated value to.
73
76
  *
74
77
  * @returns `true` if the value was set, `false` otherwise.
75
78
  */
76
79
  var setValueRef = function (value) {
77
- if (lodash_1.default.isEqual(valueRef.current, value))
80
+ if ((0, fast_deep_equal_1.default)(valueRef.current, value))
78
81
  return false;
79
82
  valueRef.current = value;
80
83
  return true;
81
84
  };
82
85
  var valueRef = (0, react_1.useRef)(initialValue);
83
- var _b = __read((0, react_1.useState)(false), 2), isDragging = _b[0], setIsDragging = _b[1];
84
- var _c = __read((0, react_1.useState)(valueRef.current), 2), value = _c[0], setValue = _c[1];
86
+ var _b = __read((0, react_1.useState)(false), 2), hasDragged = _b[0], setHasDragged = _b[1];
87
+ var _c = __read((0, react_1.useState)(false), 2), isDragging = _c[0], setIsDragging = _c[1];
88
+ var _d = __read((0, react_1.useState)(false), 2), isReleasing = _d[0], setIsReleasing = _d[1];
89
+ var _e = __read((0, react_1.useState)(initialValue), 2), value = _e[0], setValue = _e[1];
85
90
  (0, react_1.useEffect)(function () {
86
- // debug(`Using drag effect for element ${targetRef.current}...`, 'OK', `value=${valueRef.current}`)
87
91
  if (targetRef.current && !interactjs_1.default.isSet(targetRef.current)) {
88
- // Do not consume states in these listeners as they will remain their initial values within
89
- // the scope of the listeners.
92
+ // Do not consume states in these listeners as they will remain their
93
+ // initial values within the scope of the listeners.
90
94
  (0, interactjs_1.default)(targetRef.current).draggable(__assign(__assign({ inertia: true }, options), { onstart: function () {
95
+ setHasDragged(true);
91
96
  setIsDragging(true);
97
+ setIsReleasing(false);
92
98
  onDragStart === null || onDragStart === void 0 ? void 0 : onDragStart();
93
99
  }, onmove: function (_a) {
94
- var _b;
95
100
  var dx = _a.dx, dy = _a.dy;
96
- var newValue = (_b = transform === null || transform === void 0 ? void 0 : transform(valueRef.current, dx, dy)) !== null && _b !== void 0 ? _b : [dx, dy];
101
+ var newValue = transform(valueRef.current, dx, dy);
97
102
  if (setValueRef(newValue)) {
98
- // debug('Updating value from dragging...', 'OK', newValue)
99
103
  setValue(newValue);
100
104
  }
105
+ setIsDragging(true);
106
+ setIsReleasing(false);
101
107
  onDragMove === null || onDragMove === void 0 ? void 0 : onDragMove(dx, dy);
102
108
  }, onend: function () {
103
109
  setIsDragging(false);
110
+ setIsReleasing(true);
104
111
  onDragEnd === null || onDragEnd === void 0 ? void 0 : onDragEnd();
105
112
  } }));
106
113
  }
107
114
  return function () {
108
- // debug(`Removing drag effect for element ${targetRef.current}...`, 'OK', `value=${valueRef.current}`)
109
115
  if (targetRef.current && interactjs_1.default.isSet(targetRef.current)) {
110
116
  (0, interactjs_1.default)(targetRef.current).unset();
111
117
  }
112
118
  };
113
119
  }, __spreadArray([], __read(deps ? deps : []), false));
114
120
  (0, react_1.useEffect)(function () {
115
- if (setValueRef(value)) {
116
- // debug('Updating value from externally...', 'OK', value)
117
- }
121
+ if (hasDragged)
122
+ return;
123
+ setValue(initialValue);
124
+ }, [initialValue]);
125
+ (0, react_1.useEffect)(function () {
126
+ setValueRef(value);
118
127
  }, [value]);
119
128
  return {
120
129
  isDragging: [isDragging, setIsDragging],
130
+ isReleasing: [isReleasing, setIsReleasing],
121
131
  value: [value, setValue],
122
132
  };
123
133
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useDragEffect.js","sourceRoot":"/","sources":["hooks/useDragEffect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,0DAAiC;AACjC,kDAAsB;AACtB,+BAAwG;AA6CxG;;;;;;;;GAQG;AACH,SAAwB,aAAa,CAAuB,SAAiC,EAAE,EAAuF,EAAE,IAAqB;IAA5G,IAAA,WAAW,iBAAA,EAAE,UAAU,gBAAA,EAAE,SAAS,eAAA,EAAE,YAAY,kBAAA,EAAE,SAAS,eAAA,EAAK,OAAO,cAAzE,uEAA2E,CAAF;IACtK;;;;;;;;OAQG;IACH,IAAM,WAAW,GAAG,UAAC,KAAQ;QAC3B,IAAI,gBAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QACpD,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAA;QACxB,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,IAAM,QAAQ,GAAG,IAAA,cAAM,EAAI,YAAY,CAAC,CAAA;IAClC,I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Q,CAAC,KAAK,CAAC,SAAS,CAAC,OAAO,CAAC,EAAE;gBAC1D,IAAA,oBAAQ,EAAC,SAAS,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,CAAA;aACpC;QACH,CAAC,CAAA;IACH,CAAC,2BAAM,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAE,CAAA;IAEzB,IAAA,iBAAS,EAAC;QACR,IAAI,WAAW,CAAC,KAAK,CAAC,EAAE;YACtB,0DAA0D;SAC3D;IACH,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO;QACL,UAAU,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC;QACvC,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC;KACzB,CAAA;AACH,CAAC;AArED,gCAqEC","sourcesContent":["import interact from 'interactjs'\nimport _ from 'lodash'\nimport { DependencyList, Dispatch, RefObject, SetStateAction, useEffect, useRef, useState } from 'react'\n\n// const debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:hooks') : () => {}\n\ntype ReturnedStates<T> = {\n isDragging: [boolean, Dispatch<SetStateAction<boolean>>]\n value: [T, Dispatch<SetStateAction<T>>]\n}\n\ntype Options<T> = Omit<Parameters<Interact.Interactable['draggable']>[0], 'onstart' | 'onmove' | 'onend'> & {\n /**\n * The initial associated value of this hook.\n */\n initialValue: T\n\n /**\n * Handler invoked when dragging starts.\n */\n onDragStart?: () => void\n\n /**\n * Handler invoked when dragging.\n *\n * @param dx - The displacement on the x-axis (in pixels) since the last emitted drag move event.\n * @param dy - The displacement on the y-axis (in pixels) since the last emitted drag move event.\n */\n onDragMove?: (dx: number, dy: number) => void\n\n /**\n * Handler invoked when dragging ends.\n */\n onDragEnd?: () => void\n\n /**\n * A function that transforms the drag move delta values to the associated value of this hook.\n *\n * @param currentValue - The current associated value.\n * @param dx - The displacement on the x-axis (in pixels) since the last emitted drag move event.\n * @param dy - The displacement on the y-axis (in pixels) since the last emitted drag move event.\n *\n * @returns The transformed value.\n */\n transform?: (currentValue: T, dx: number, dy: number) => T\n}\n\n/**\n * Hook for adding effectful dragging interaction to an element.\n *\n * @param targetRef - The reference to the target element to add drag interaction to.\n * @param options - Additional options which include options for `module:interactjs.draggable`.\n * @param deps - Dependencies that trigger this effect.\n *\n * @returns The states created for this effect.\n */\nexport default function useDragEffect<T = [number, number]>(targetRef: RefObject<HTMLElement>, { onDragStart, onDragMove, onDragEnd, initialValue, transform, ...options }: Options<T>, deps?: DependencyList): ReturnedStates<T> {\n /**\n * Sets the current associated value reference. This reference object is equal to the `value`\n * state but differs slightly in how they are set. Because states are asynchronous by nature, this\n * reference object is used to cache time-sensitive value changes while drag event happens.\n *\n * @param value - The value to set the associated value to.\n *\n * @returns `true` if the value was set, `false` otherwise.\n */\n const setValueRef = (value: T): boolean => {\n if (_.isEqual(valueRef.current, value)) return false\n valueRef.current = value\n return true\n }\n\n const valueRef = useRef<T>(initialValue)\n const [isDragging, setIsDragging] = useState<boolean>(false)\n const [value, setValue] = useState(valueRef.current)\n\n useEffect(() => {\n // debug(`Using drag effect for element ${targetRef.current}...`, 'OK', `value=${valueRef.current}`)\n\n if (targetRef.current && !interact.isSet(targetRef.current)) {\n // Do not consume states in these listeners as they will remain their initial values within\n // the scope of the listeners.\n interact(targetRef.current).draggable({\n inertia: true,\n ...options,\n onstart: () => {\n setIsDragging(true)\n onDragStart?.()\n },\n onmove: ({ dx, dy }) => {\n const newValue = transform?.(valueRef.current, dx, dy) ?? [dx, dy] as unknown as T\n\n if (setValueRef(newValue)) {\n // debug('Updating value from dragging...', 'OK', newValue)\n setValue(newValue)\n }\n\n onDragMove?.(dx, dy)\n },\n onend: () => {\n setIsDragging(false)\n onDragEnd?.()\n },\n })\n }\n\n return () => {\n // debug(`Removing drag effect for element ${targetRef.current}...`, 'OK', `value=${valueRef.current}`)\n\n if (targetRef.current && interact.isSet(targetRef.current)) {\n interact(targetRef.current).unset()\n }\n }\n }, [...deps ? deps : []])\n\n useEffect(() => {\n if (setValueRef(value)) {\n // debug('Updating value from externally...', 'OK', value)\n }\n }, [value])\n\n return {\n isDragging: [isDragging, setIsDragging],\n value: [value, setValue],\n }\n}\n"]}
1
+ {"version":3,"file":"useDragEffect.js","sourceRoot":"/","sources":["hooks/useDragEffect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oEAAqC;AACrC,0DAAiC;AACjC,+BAAwG;AAmDxG;;;;;;;;;;GAUG;AACH,SAAwB,aAAa,CAAuB,SAAiC,EAAE,EAOlF,EAAE,IAAqB;IANlC,IAAA,YAAY,kBAAA,EACZ,SAAS,eAAA,EACT,WAAW,iBAAA,EACX,UAAU,gBAAA,EACV,SAAS,eAAA,EACN,OAAO,cANmF,uEAO9F,CADW;IAEV;;;;;;;;;OASG;IACH,IAAM,WAAW,GAAG,UAAC,KAAQ;QAC3B,IAAI,IAAA,yBAAO,EAAC,QAAQ,CAAC,OAAO,EAAE,KAAK,CAAC;YAAE,OAAO,KAAK,CAAA;QAClD,QAAQ,CAAC,OAAO,GAAG,KAAK,CAAA;QAExB,OAAO,IAAI,CAAA;IACb,CAAC,CAAA;IAED,IAAM,QAAQ,GAAG,IAAA,cAAM,EAAI,YAAY,CAAC,CAAA;IAClC,IAAA,KAAA,OAA8B,IAAA,gBAAQ,EAAU,KAAK,CAAC,IAAA,EAArD,UAAU,QAAA,EAAE,aAAa,QAA4B,CAAA;IACtD,IAAA,KAAA,OAA8B,IAAA,gBAAQ,EAAU,KAAK,CAAC,IAAA,EAArD,UAAU,QAAA,EAAE,aAAa,QAA4B,CAAA;IACtD,IAAA,KAAA,OAAgC,IAAA,gBAAQ,EAAU,KAAK,CAAC,IAAA,EAAvD,WAAW,QAAA,EAAE,cAAc,QAA4B,CAAA;IACxD,IAAA,KAAA,OAAoB,IAAA,gBAAQ,EAAC,YAAY,CAAC,IAAA,EAAzC,KAAK,QAAA,EAAE,QAA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CAAC,CAAA;IACH,CAAC,2BAAM,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAE,CAAA;IAEzB,IAAA,iBAAS,EAAC;QACR,IAAI,UAAU;YAAE,OAAM;QACtB,QAAQ,CAAC,YAAY,CAAC,CAAA;IACxB,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IAElB,IAAA,iBAAS,EAAC;QACR,WAAW,CAAC,KAAK,CAAC,CAAA;IACpB,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO;QACL,UAAU,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC;QACvC,WAAW,EAAE,CAAC,WAAW,EAAE,cAAc,CAAC;QAC1C,KAAK,EAAE,CAAC,KAAK,EAAE,QAAQ,CAAC;KACzB,CAAA;AACH,CAAC;AApFD,gCAoFC","sourcesContent":["import isEqual from 'fast-deep-equal'\nimport interact from 'interactjs'\nimport { DependencyList, Dispatch, RefObject, SetStateAction, useEffect, useRef, useState } from 'react'\n\ntype ReturnedStates<T> = {\n isDragging: [boolean, Dispatch<SetStateAction<boolean>>]\n isReleasing: [boolean, Dispatch<SetStateAction<boolean>>]\n value: [T, Dispatch<SetStateAction<T>>]\n}\n\ntype InteractDraggableOptions = Parameters<Interact.Interactable['draggable']>[0]\n\ntype Options<T> = Omit<InteractDraggableOptions, 'onstart' | 'onmove' | 'onend'> & {\n /**\n * The initial associated value of this hook.\n */\n initialValue: T\n\n /**\n * A function that transforms the drag move delta values to the associated\n * value of this hook.\n *\n * @param currentValue - The current associated value.\n * @param dx - The displacement on the x-axis (in pixels) since the last\n * emitted drag move event.\n * @param dy - The displacement on the y-axis (in pixels) since the last\n * emitted drag move event.\n *\n * @returns The transformed value.\n */\n transform: (currentValue: T, dx: number, dy: number) => T\n\n /**\n * Handler invoked when dragging starts.\n */\n onDragStart?: () => void\n\n /**\n * Handler invoked when dragging.\n *\n * @param dx - The displacement on the x-axis (in pixels) since the last\n * emitted drag move event.\n * @param dy - The displacement on the y-axis (in pixels) since the last\n * emitted drag move event.\n */\n onDragMove?: (dx: number, dy: number) => void\n\n /**\n * Handler invoked when dragging ends.\n */\n onDragEnd?: () => void\n}\n\n/**\n * Hook for adding effectful dragging interaction to an element.\n *\n * @param targetRef - The reference to the target element to add drag\n * interaction to.\n * @param options - Additional options which include options for\n * `module:interactjs.draggable`.\n * @param deps - Dependencies that trigger this effect.\n *\n * @returns The states created for this effect.\n */\nexport default function useDragEffect<T = [number, number]>(targetRef: RefObject<HTMLElement>, {\n initialValue,\n transform,\n onDragStart,\n onDragMove,\n onDragEnd,\n ...options\n}: Options<T>, deps?: DependencyList): ReturnedStates<T> {\n /**\n * Sets the current associated value reference. This reference object is equal\n * to the `value` state but differs slightly in how they are set. Because\n * states are asynchronous by nature, this reference object is used to cache\n * time-sensitive value changes while drag event happens.\n *\n * @param value - The value to set the associated value to.\n *\n * @returns `true` if the value was set, `false` otherwise.\n */\n const setValueRef = (value: T): boolean => {\n if (isEqual(valueRef.current, value)) return false\n valueRef.current = value\n\n return true\n }\n\n const valueRef = useRef<T>(initialValue)\n const [hasDragged, setHasDragged] = useState<boolean>(false)\n const [isDragging, setIsDragging] = useState<boolean>(false)\n const [isReleasing, setIsReleasing] = useState<boolean>(false)\n const [value, setValue] = useState(initialValue)\n\n useEffect(() => {\n if (targetRef.current && !interact.isSet(targetRef.current)) {\n // Do not consume states in these listeners as they will remain their\n // initial values within the scope of the listeners.\n interact(targetRef.current).draggable({\n inertia: true,\n ...options,\n onstart: () => {\n setHasDragged(true)\n setIsDragging(true)\n setIsReleasing(false)\n onDragStart?.()\n },\n onmove: ({ dx, dy }) => {\n const newValue = transform(valueRef.current, dx, dy)\n\n if (setValueRef(newValue)) {\n setValue(newValue)\n }\n\n setIsDragging(true)\n setIsReleasing(false)\n onDragMove?.(dx, dy)\n },\n onend: () => {\n setIsDragging(false)\n setIsReleasing(true)\n onDragEnd?.()\n },\n })\n }\n\n return () => {\n if (targetRef.current && interact.isSet(targetRef.current)) {\n interact(targetRef.current).unset()\n }\n }\n }, [...deps ? deps : []])\n\n useEffect(() => {\n if (hasDragged) return\n setValue(initialValue)\n }, [initialValue])\n\n useEffect(() => {\n setValueRef(value)\n }, [value])\n\n return {\n isDragging: [isDragging, setIsDragging],\n isReleasing: [isReleasing, setIsReleasing],\n value: [value, setValue],\n }\n}\n"]}
@@ -1,7 +1,8 @@
1
1
  import { RefObject } from 'react';
2
2
  import { Rect } from 'spase';
3
3
  /**
4
- * Hook for monitoring changes in and returning the size and position of the target element.
4
+ * Hook for monitoring changes in and returning the size and position of the
5
+ * target element.
5
6
  *
6
7
  * @param targetRef - Reference to the target element.
7
8
  *
@@ -23,7 +23,8 @@ var react_1 = require("react");
23
23
  var resize_observer_polyfill_1 = __importDefault(require("resize-observer-polyfill"));
24
24
  var spase_1 = require("spase");
25
25
  /**
26
- * Hook for monitoring changes in and returning the size and position of the target element.
26
+ * Hook for monitoring changes in and returning the size and position of the
27
+ * target element.
27
28
  *
28
29
  * @param targetRef - Reference to the target element.
29
30
  *
@@ -34,10 +35,10 @@ function useElementRect(targetRef) {
34
35
  var _a = __read((0, react_1.useState)(new spase_1.Rect()), 2), rect = _a[0], setRect = _a[1];
35
36
  (0, react_1.useEffect)(function () {
36
37
  observerRef.current = new resize_observer_polyfill_1.default(function () {
37
- var rect = spase_1.Rect.from(targetRef.current);
38
- if (!rect)
38
+ var newRect = spase_1.Rect.from(targetRef.current);
39
+ if (!newRect)
39
40
  return;
40
- setRect(rect);
41
+ setRect(newRect);
41
42
  });
42
43
  if (observerRef.current && targetRef.current) {
43
44
  observerRef.current.observe(targetRef.current);
@@ -1 +1 @@
1
- {"version":3,"file":"useElementRect.js","sourceRoot":"/","sources":["hooks/useElementRect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+BAA8D;AAC9D,sFAAqD;AACrD,+BAA4B;AAE5B;;;;;;GAMG;AACH,SAAwB,cAAc,CAAC,SAA6B;IAClE,IAAM,WAAW,GAAG,IAAA,cAAM,EAA6B,SAAS,CAAC,CAAA;IAC3D,IAAA,KAAA,OAAkB,IAAA,gBAAQ,EAAO,IAAI,YAAI,EAAE,CAAC,IAAA,EAA3C,IAAI,QAAA,EAAE,OAAO,QAA8B,CAAA;IAElD,IAAA,iBAAS,EAAC;QACR,WAAW,CAAC,OAAO,GAAG,IAAI,kCAAc,CAAC;YACvC,IAAM,IAAI,GAAG,YAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YAEzC,IAAI,CAAC,IAAI;gBAAE,OAAM;YAEjB,OAAO,CAAC,IAAI,CAAC,CAAA;QACf,CAAC,CAAC,CAAA;QAEF,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;YAC5C,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAC/C;QAED,OAAO;YACL,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;gBAC5C,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;aACjD;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,OAAO,IAAI,CAAA;AACb,CAAC;AAzBD,iCAyBC","sourcesContent":["import { RefObject, useEffect, useRef, useState } from 'react'\nimport ResizeObserver from 'resize-observer-polyfill'\nimport { Rect } from 'spase'\n\n/**\n * Hook for monitoring changes in and returning the size and position of the target element.\n *\n * @param targetRef - Reference to the target element.\n *\n * @returns The most current {@link Rect} of the target element.\n */\nexport default function useElementRect(targetRef: RefObject<Element>): Rect {\n const observerRef = useRef<ResizeObserver | undefined>(undefined)\n const [rect, setRect] = useState<Rect>(new Rect())\n\n useEffect(() => {\n observerRef.current = new ResizeObserver(() => {\n const rect = Rect.from(targetRef.current)\n\n if (!rect) return\n\n setRect(rect)\n })\n\n if (observerRef.current && targetRef.current) {\n observerRef.current.observe(targetRef.current)\n }\n\n return () => {\n if (observerRef.current && targetRef.current) {\n observerRef.current.unobserve(targetRef.current)\n }\n }\n }, [targetRef])\n\n return rect\n}\n"]}
1
+ {"version":3,"file":"useElementRect.js","sourceRoot":"/","sources":["hooks/useElementRect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+BAA8D;AAC9D,sFAAqD;AACrD,+BAA4B;AAE5B;;;;;;;GAOG;AACH,SAAwB,cAAc,CAAC,SAA6B;IAClE,IAAM,WAAW,GAAG,IAAA,cAAM,EAA6B,SAAS,CAAC,CAAA;IAC3D,IAAA,KAAA,OAAkB,IAAA,gBAAQ,EAAO,IAAI,YAAI,EAAE,CAAC,IAAA,EAA3C,IAAI,QAAA,EAAE,OAAO,QAA8B,CAAA;IAElD,IAAA,iBAAS,EAAC;QACR,WAAW,CAAC,OAAO,GAAG,IAAI,kCAAc,CAAC;YACvC,IAAM,OAAO,GAAG,YAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YAE5C,IAAI,CAAC,OAAO;gBAAE,OAAM;YAEpB,OAAO,CAAC,OAAO,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;QAEF,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;YAC5C,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAC/C;QAED,OAAO;YACL,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;gBAC5C,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;aACjD;QACH,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,OAAO,IAAI,CAAA;AACb,CAAC;AAzBD,iCAyBC","sourcesContent":["import { RefObject, useEffect, useRef, useState } from 'react'\nimport ResizeObserver from 'resize-observer-polyfill'\nimport { Rect } from 'spase'\n\n/**\n * Hook for monitoring changes in and returning the size and position of the\n * target element.\n *\n * @param targetRef - Reference to the target element.\n *\n * @returns The most current {@link Rect} of the target element.\n */\nexport default function useElementRect(targetRef: RefObject<Element>): Rect {\n const observerRef = useRef<ResizeObserver | undefined>(undefined)\n const [rect, setRect] = useState<Rect>(new Rect())\n\n useEffect(() => {\n observerRef.current = new ResizeObserver(() => {\n const newRect = Rect.from(targetRef.current)\n\n if (!newRect) return\n\n setRect(newRect)\n })\n\n if (observerRef.current && targetRef.current) {\n observerRef.current.observe(targetRef.current)\n }\n\n return () => {\n if (observerRef.current && targetRef.current) {\n observerRef.current.unobserve(targetRef.current)\n }\n }\n }, [targetRef])\n\n return rect\n}\n"]}
@@ -1,8 +1,8 @@
1
1
  import { DependencyList } from 'react';
2
2
  declare type Options = {
3
3
  /**
4
- * Specifies if the handler should be invoked initially (as opposed to waiting for the specified
5
- * interval for the initial invocation).
4
+ * Specifies if the handler should be invoked initially (as opposed to waiting
5
+ * for the specified interval for the initial invocation).
6
6
  */
7
7
  shouldInvokeInitially?: boolean;
8
8
  };
@@ -36,7 +36,7 @@ var react_1 = require("react");
36
36
  */
37
37
  function useInterval(handler, timeout, _a, deps) {
38
38
  var _b = _a === void 0 ? {} : _a, _c = _b.shouldInvokeInitially, shouldInvokeInitially = _c === void 0 ? false : _c;
39
- var handlerRef = (0, react_1.useRef)(undefined);
39
+ var handlerRef = (0, react_1.useRef)();
40
40
  (0, react_1.useEffect)(function () {
41
41
  handlerRef.current = handler;
42
42
  }, [handler]);
@@ -1 +1 @@
1
- {"version":3,"file":"useInterval.js","sourceRoot":"/","sources":["hooks/useInterval.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAyD;AAUzD;;;;;;;GAOG;AACH,SAAwB,WAAW,CAAC,OAAmB,EAAE,OAAgB,EAAE,EAA+C,EAAE,IAAqB;QAAtE,qBAA6C,EAAE,KAAA,EAA7C,6BAA6B,EAA7B,qBAAqB,mBAAG,KAAK,KAAA;IACxG,IAAM,UAAU,GAAG,IAAA,cAAM,EAA2B,SAAS,CAAC,CAAA;IAE9D,IAAA,iBAAS,EAAC;QACR,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA;IAC9B,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,IAAA,iBAAS,EAAC;;QACR,IAAI,OAAO,KAAK,SAAS;YAAE,OAAM;QAEjC,IAAI,qBAAqB,KAAK,IAAI;YAAE,MAAA,UAAU,CAAC,OAAO,0DAAI,CAAA;QAC1D,IAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,sBAAM,OAAA,MAAA,UAAU,CAAC,OAAO,0DAAI,CAAA,EAAA,EAAE,OAAO,CAAC,CAAA;QACvE,OAAO,cAAM,OAAA,aAAa,CAAC,KAAK,CAAC,EAApB,CAAoB,CAAA;IACnC,CAAC,yCAAM,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,YAAE,OAAO,UAAE,CAAA;AACpC,CAAC;AAdD,8BAcC","sourcesContent":["import { DependencyList, useEffect, useRef } from 'react'\n\ntype Options = {\n /**\n * Specifies if the handler should be invoked initially (as opposed to waiting for the specified\n * interval for the initial invocation).\n */\n shouldInvokeInitially?: boolean\n}\n\n/**\n * Hoook for invoking a method repeatedly on every set interval.\n *\n * @param handler - The method to invoke on every interval.\n * @param timeout - Time (in milliseconds) between each invocation.\n * @param options - See {@link Options}.\n * @param deps - Dependencies that trigger this effect.\n */\nexport default function useInterval(handler: () => void, timeout?: number, { shouldInvokeInitially = false }: Options = {}, deps?: DependencyList) {\n const handlerRef = useRef<(() => void) | undefined>(undefined)\n\n useEffect(() => {\n handlerRef.current = handler\n }, [handler])\n\n useEffect(() => {\n if (timeout === undefined) return\n\n if (shouldInvokeInitially === true) handlerRef.current?.()\n const timer = window.setInterval(() => handlerRef.current?.(), timeout)\n return () => clearInterval(timer)\n }, [...deps ? deps : [], timeout])\n}\n"]}
1
+ {"version":3,"file":"useInterval.js","sourceRoot":"/","sources":["hooks/useInterval.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAyD;AAUzD;;;;;;;GAOG;AACH,SAAwB,WAAW,CAAC,OAAmB,EAAE,OAAgB,EAAE,EAA+C,EAAE,IAAqB;QAAtE,qBAA6C,EAAE,KAAA,EAA7C,6BAA6B,EAA7B,qBAAqB,mBAAG,KAAK,KAAA;IACxG,IAAM,UAAU,GAAG,IAAA,cAAM,GAAgB,CAAA;IAEzC,IAAA,iBAAS,EAAC;QACR,UAAU,CAAC,OAAO,GAAG,OAAO,CAAA;IAC9B,CAAC,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAEb,IAAA,iBAAS,EAAC;;QACR,IAAI,OAAO,KAAK,SAAS;YAAE,OAAM;QAEjC,IAAI,qBAAqB,KAAK,IAAI;YAAE,MAAA,UAAU,CAAC,OAAO,0DAAI,CAAA;QAC1D,IAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAAC,sBAAM,OAAA,MAAA,UAAU,CAAC,OAAO,0DAAI,CAAA,EAAA,EAAE,OAAO,CAAC,CAAA;QAEvE,OAAO,cAAM,OAAA,aAAa,CAAC,KAAK,CAAC,EAApB,CAAoB,CAAA;IACnC,CAAC,yCAAM,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,YAAE,OAAO,UAAE,CAAA;AACpC,CAAC;AAfD,8BAeC","sourcesContent":["import { DependencyList, useEffect, useRef } from 'react'\n\ntype Options = {\n /**\n * Specifies if the handler should be invoked initially (as opposed to waiting\n * for the specified interval for the initial invocation).\n */\n shouldInvokeInitially?: boolean\n}\n\n/**\n * Hoook for invoking a method repeatedly on every set interval.\n *\n * @param handler - The method to invoke on every interval.\n * @param timeout - Time (in milliseconds) between each invocation.\n * @param options - See {@link Options}.\n * @param deps - Dependencies that trigger this effect.\n */\nexport default function useInterval(handler: () => void, timeout?: number, { shouldInvokeInitially = false }: Options = {}, deps?: DependencyList) {\n const handlerRef = useRef<(() => void)>()\n\n useEffect(() => {\n handlerRef.current = handler\n }, [handler])\n\n useEffect(() => {\n if (timeout === undefined) return\n\n if (shouldInvokeInitially === true) handlerRef.current?.()\n const timer = window.setInterval(() => handlerRef.current?.(), timeout)\n\n return () => clearInterval(timer)\n }, [...deps ? deps : [], timeout])\n}\n"]}
@@ -2,13 +2,13 @@ import { DependencyList, Dispatch, SetStateAction } from 'react';
2
2
  import { Size } from 'spase';
3
3
  declare type ReturnedStates = {
4
4
  /**
5
- * A tuple consisting of a stateful value indicating if the image is loading, and a function that
6
- * updates the loading state.
5
+ * A tuple consisting of a stateful value indicating if the image is loading,
6
+ * and a function that updates the loading state.
7
7
  */
8
8
  isLoading: [boolean, Dispatch<SetStateAction<boolean>>];
9
9
  /**
10
- * A tuple consisting of a stateful value representing the size of the image, and a function that
11
- * updates the size.
10
+ * A tuple consisting of a stateful value representing the size of the image,
11
+ * and a function that updates the size.
12
12
  */
13
13
  imageSize: [Size | undefined, Dispatch<SetStateAction<Size | undefined>>];
14
14
  };
@@ -24,8 +24,8 @@ declare type Options = {
24
24
  */
25
25
  onImageLoadError?: () => void;
26
26
  /**
27
- * Handler invoked when the image size changes. If there is no loaded image, the size is
28
- * `undefined`.
27
+ * Handler invoked when the image size changes. If there is no loaded image,
28
+ * the size is `undefined`.
29
29
  *
30
30
  * @param size - The original image size.
31
31
  */
@@ -1 +1 @@
1
- {"version":3,"file":"useLoadImageEffect.js","sourceRoot":"/","sources":["hooks/useLoadImageEffect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAA6F;AAC7F,+BAA4B;AAsC5B,SAAS,YAAY,CAAC,YAA8B;IAClD,OAAO,IAAI,YAAI,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CAAA;AAC5D,CAAC;AAED;;;;;;;;GAQG;AACH,SAAwB,k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CAAC,gBAAgB,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAA;QAEjE,OAAO;;YACL,MAAA,QAAQ,CAAC,OAAO,0CAAE,mBAAmB,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAA;YACvE,MAAA,QAAQ,CAAC,OAAO,0CAAE,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAA;YACrE,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAA;QAC9B,CAAC,CAAA;IACH,CAAC,iBAAG,GAAG,UAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAE,CAAA;IAE9B,IAAA,iBAAS,EAAC;QACR,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAG,SAAS,CAAC,CAAA;IAChC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,OAAO;QACL,SAAS,EAAE,CAAC,SAAS,EAAE,YAAY,CAAC;QACpC,SAAS,EAAE,CAAC,SAAS,EAAE,YAAY,CAAC;KACrC,CAAA;AACH,CAAC;AA/CD,qCA+CC","sourcesContent":["import { DependencyList, Dispatch, SetStateAction, useEffect, useRef, useState } from 'react'\nimport { Size } from 'spase'\n\ntype ReturnedStates = {\n /**\n * A tuple consisting of a stateful value indicating if the image is loading, and a function that\n * updates the loading state.\n */\n isLoading: [boolean, Dispatch<SetStateAction<boolean>>]\n\n /**\n * A tuple consisting of a stateful value representing the size of the image, and a function that\n * updates the size.\n */\n imageSize: [Size | undefined, Dispatch<SetStateAction<Size | undefined>>]\n}\n\ntype Options = {\n /**\n * Handler invoked when the image is done loading.\n *\n * @param imageElement - The loaded image element.\n */\n onImageLoadComplete?: (imageElement: HTMLImageElement) => void\n\n /**\n * Handler invoked when there is an error loading the image.\n */\n onImageLoadError?: () => void\n\n /**\n * Handler invoked when the image size changes. If there is no loaded image, the size is\n * `undefined`.\n *\n * @param size - The original image size.\n */\n onImageSizeChange?: (size?: Size) => void\n}\n\nfunction getImageSize(imageElement: HTMLImageElement): Size {\n return new Size([imageElement.width, imageElement.height])\n}\n\n/**\n * Hook for preloading an image.\n *\n * @param src - The image source.\n * @param options - See {@link Options}.\n * @param deps - Additional dependencies.\n *\n * @returns See {@link ReturnedStates}.\n */\nexport default function useLoadImageEffect(src?: string, { onImageLoadComplete, onImageLoadError, onImageSizeChange }: Options = {}, deps?: DependencyList): ReturnedStates {\n const imageLoadCompleteHandler = (event: Event) => {\n const imageElement = event.currentTarget as HTMLImageElement\n const imageSize = getImageSize(imageElement)\n\n setIsLoading(false)\n setImageSize(imageSize)\n\n onImageLoadComplete?.(imageElement)\n }\n\n const imageLoadErrorHandler = (event: Event) => {\n setIsLoading(false)\n setImageSize(undefined)\n\n onImageLoadError?.()\n }\n\n const imageRef = useRef<HTMLImageElement | undefined>(undefined)\n const [isLoading, setIsLoading] = useState(true)\n const [imageSize, setImageSize] = useState<Size | undefined>(undefined)\n\n useEffect(() => {\n if (!src) return\n\n setIsLoading(true)\n\n imageRef.current = new Image()\n imageRef.current.src = src\n imageRef.current.addEventListener('load', imageLoadCompleteHandler)\n imageRef.current.addEventListener('error', imageLoadErrorHandler)\n\n return () => {\n imageRef.current?.removeEventListener('load', imageLoadCompleteHandler)\n imageRef.current?.removeEventListener('error', imageLoadErrorHandler)\n imageRef.current = undefined\n }\n }, [src, ...deps ? deps : []])\n\n useEffect(() => {\n onImageSizeChange?.(imageSize)\n }, [imageSize])\n\n return {\n isLoading: [isLoading, setIsLoading],\n imageSize: [imageSize, setImageSize],\n }\n}\n"]}
1
+ {"version":3,"file":"useLoadImageEffect.js","sourceRoot":"/","sources":["hooks/useLoadImageEffect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAA6F;AAC7F,+BAA4B;AAsC5B,SAAS,YAAY,CAAC,YAA8B;IAClD,OAAO,IAAI,YAAI,CAAC,CAAC,YAAY,CAAC,KAAK,EAAE,YAAY,CAAC,MAAM,CAAC,CAAC,CA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AE,wBAAwB,CAAC,CAAA;QACnE,QAAQ,CAAC,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAA;QAEjE,OAAO;;YACL,MAAA,QAAQ,CAAC,OAAO,0CAAE,mBAAmB,CAAC,MAAM,EAAE,wBAAwB,CAAC,CAAA;YACvE,MAAA,QAAQ,CAAC,OAAO,0CAAE,mBAAmB,CAAC,OAAO,EAAE,qBAAqB,CAAC,CAAA;YACrE,QAAQ,CAAC,OAAO,GAAG,SAAS,CAAA;QAC9B,CAAC,CAAA;IACH,CAAC,iBAAG,GAAG,UAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAE,CAAA;IAE9B,IAAA,iBAAS,EAAC;QACR,iBAAiB,aAAjB,iBAAiB,uBAAjB,iBAAiB,CAAG,SAAS,CAAC,CAAA;IAChC,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAA;IAEf,OAAO;QACL,SAAS,EAAE,CAAC,SAAS,EAAE,YAAY,CAAC;QACpC,SAAS,EAAE,CAAC,SAAS,EAAE,YAAY,CAAC;KACrC,CAAA;AACH,CAAC;AA/CD,qCA+CC","sourcesContent":["import { DependencyList, Dispatch, SetStateAction, useEffect, useRef, useState } from 'react'\nimport { Size } from 'spase'\n\ntype ReturnedStates = {\n /**\n * A tuple consisting of a stateful value indicating if the image is loading,\n * and a function that updates the loading state.\n */\n isLoading: [boolean, Dispatch<SetStateAction<boolean>>]\n\n /**\n * A tuple consisting of a stateful value representing the size of the image,\n * and a function that updates the size.\n */\n imageSize: [Size | undefined, Dispatch<SetStateAction<Size | undefined>>]\n}\n\ntype Options = {\n /**\n * Handler invoked when the image is done loading.\n *\n * @param imageElement - The loaded image element.\n */\n onImageLoadComplete?: (imageElement: HTMLImageElement) => void\n\n /**\n * Handler invoked when there is an error loading the image.\n */\n onImageLoadError?: () => void\n\n /**\n * Handler invoked when the image size changes. If there is no loaded image,\n * the size is `undefined`.\n *\n * @param size - The original image size.\n */\n onImageSizeChange?: (size?: Size) => void\n}\n\nfunction getImageSize(imageElement: HTMLImageElement): Size {\n return new Size([imageElement.width, imageElement.height])\n}\n\n/**\n * Hook for preloading an image.\n *\n * @param src - The image source.\n * @param options - See {@link Options}.\n * @param deps - Additional dependencies.\n *\n * @returns See {@link ReturnedStates}.\n */\nexport default function useLoadImageEffect(src?: string, { onImageLoadComplete, onImageLoadError, onImageSizeChange }: Options = {}, deps?: DependencyList): ReturnedStates {\n const imageLoadCompleteHandler = (event: Event) => {\n const imageElement = event.currentTarget as HTMLImageElement\n const imageSize = getImageSize(imageElement)\n\n setIsLoading(false)\n setImageSize(imageSize)\n\n onImageLoadComplete?.(imageElement)\n }\n\n const imageLoadErrorHandler = (event: Event) => {\n setIsLoading(false)\n setImageSize(undefined)\n\n onImageLoadError?.()\n }\n\n const imageRef = useRef<HTMLImageElement | undefined>(undefined)\n const [isLoading, setIsLoading] = useState(true)\n const [imageSize, setImageSize] = useState<Size | undefined>(undefined)\n\n useEffect(() => {\n if (!src) return\n\n setIsLoading(true)\n\n imageRef.current = new Image()\n imageRef.current.src = src\n imageRef.current.addEventListener('load', imageLoadCompleteHandler)\n imageRef.current.addEventListener('error', imageLoadErrorHandler)\n\n return () => {\n imageRef.current?.removeEventListener('load', imageLoadCompleteHandler)\n imageRef.current?.removeEventListener('error', imageLoadErrorHandler)\n imageRef.current = undefined\n }\n }, [src, ...deps ? deps : []])\n\n useEffect(() => {\n onImageSizeChange?.(imageSize)\n }, [imageSize])\n\n return {\n isLoading: [isLoading, setIsLoading],\n imageSize: [imageSize, setImageSize],\n }\n}\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Returns the previous value of a state or prop.
3
+ *
4
+ * @param stateOrProp - The state or prop.
5
+ */
6
+ export default function usePrevious<T>(stateOrProp: T): T | undefined;
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var react_1 = require("react");
4
+ /**
5
+ * Returns the previous value of a state or prop.
6
+ *
7
+ * @param stateOrProp - The state or prop.
8
+ */
9
+ function usePrevious(stateOrProp) {
10
+ var ref = (0, react_1.useRef)();
11
+ (0, react_1.useEffect)(function () {
12
+ ref.current = stateOrProp;
13
+ }, [stateOrProp]);
14
+ return ref.current;
15
+ }
16
+ exports.default = usePrevious;
17
+ //# sourceMappingURL=usePrevious.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"usePrevious.js","sourceRoot":"/","sources":["hooks/usePrevious.ts"],"names":[],"mappings":";;AAAA,+BAAyC;AAEzC;;;;GAIG;AACH,SAAwB,WAAW,CAAI,WAAc;IACnD,IAAM,GAAG,GAAG,IAAA,cAAM,GAAK,CAAA;IAEvB,IAAA,iBAAS,EAAC;QACR,GAAG,CAAC,OAAO,GAAG,WAAW,CAAA;IAC3B,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAA;IAEjB,OAAO,GAAG,CAAC,OAAO,CAAA;AACpB,CAAC;AARD,8BAQC","sourcesContent":["import { useEffect, useRef } from 'react'\n\n/**\n * Returns the previous value of a state or prop.\n *\n * @param stateOrProp - The state or prop.\n */\nexport default function usePrevious<T>(stateOrProp: T): T | undefined {\n const ref = useRef<T>()\n\n useEffect(() => {\n ref.current = stateOrProp\n }, [stateOrProp])\n\n return ref.current\n}\n"]}
@@ -15,8 +15,8 @@ declare type Options = {
15
15
  * @param options - See {@link Options}.
16
16
  * @param deps - Additional dependencies.
17
17
  *
18
- * @returns A tuple consisting of a stateful value indicating the size of the target ref, and a
19
- * function that sets its size.
18
+ * @returns A tuple consisting of a stateful value indicating the size of the
19
+ * target ref, and a function that sets its size.
20
20
  */
21
21
  export default function useResizeEffect(targetRef: RefObject<Element>, { onResize }?: Options, deps?: DependencyList): [Size, Dispatch<SetStateAction<Size>>];
22
22
  export {};
@@ -38,29 +38,26 @@ var spase_1 = require("spase");
38
38
  * @param options - See {@link Options}.
39
39
  * @param deps - Additional dependencies.
40
40
  *
41
- * @returns A tuple consisting of a stateful value indicating the size of the target ref, and a
42
- * function that sets its size.
41
+ * @returns A tuple consisting of a stateful value indicating the size of the
42
+ * target ref, and a function that sets its size.
43
43
  */
44
44
  function useResizeEffect(targetRef, _a, deps) {
45
45
  var _b = _a === void 0 ? {} : _a, onResize = _b.onResize;
46
46
  var observerRef = (0, react_1.useRef)(undefined);
47
47
  var _c = __read((0, react_1.useState)(new spase_1.Size()), 2), size = _c[0], setSize = _c[1];
48
48
  (0, react_1.useEffect)(function () {
49
- // debug(`Using resize effect for element ${targetRef.current}...`, 'OK')
50
49
  observerRef.current = new resize_observer_polyfill_1.default(function () {
51
50
  var rect = spase_1.Rect.from(targetRef.current);
52
51
  if (!rect)
53
52
  return;
54
- var size = rect.size;
55
- // debug(`Observing size change for element ${targetRef.current}...`, 'OK', size)
56
- setSize(size);
57
- onResize === null || onResize === void 0 ? void 0 : onResize(size);
53
+ var newSize = rect.size;
54
+ setSize(newSize);
55
+ onResize === null || onResize === void 0 ? void 0 : onResize(newSize);
58
56
  });
59
57
  if (observerRef.current && targetRef.current) {
60
58
  observerRef.current.observe(targetRef.current);
61
59
  }
62
60
  return function () {
63
- // debug(`Removing resize effect for element ${targetRef.current}...`, 'OK')
64
61
  if (observerRef.current && targetRef.current) {
65
62
  observerRef.current.unobserve(targetRef.current);
66
63
  }
@@ -1 +1 @@
1
- {"version":3,"file":"useResizeEffect.js","sourceRoot":"/","sources":["hooks/useResizeEffect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAwG;AACxG,sFAAqD;AACrD,+BAAkC;AAalC;;;;;;;;;GASG;AACH,SAAwB,eAAe,CAAC,SAA6B,EAAE,EAA0B,EAAE,IAAqB;QAAjD,qBAAwB,EAAE,KAAA,EAAxB,QAAQ,cAAA;IAC/E,IAAM,WAAW,GAAG,IAAA,cAAM,EAA6B,SAAS,CAAC,CAAA;IAC3D,IAAA,KAAA,OAAkB,IAAA,gBAAQ,EAAO,IAAI,YAAI,EAAE,CAAC,IAAA,EAA3C,IAAI,QAAA,EAAE,OAAO,QAA8B,CAAA;IAElD,IAAA,iBAAS,EAAC;QACR,yEAAyE;QAEzE,WAAW,CAAC,OAAO,GAAG,IAAI,kCAAc,CAAC;YACvC,IAAM,IAAI,GAAG,YAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YAEzC,IAAI,CAAC,IAAI;gBAAE,OAAM;YAEjB,IAAM,IAAI,GAAG,IAAI,CAAC,IAAI,CAAA;YAEtB,iFAAiF;YAEjF,OAAO,CAAC,IAAI,CAAC,CAAA;YACb,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,IAAI,CAAC,CAAA;QAClB,CAAC,CAAC,CAAA;QAEF,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;YAC5C,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAC/C;QAED,OAAO;YACL,4EAA4E;YAE5E,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;gBAC5C,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;aACjD;QACH,CAAC,CAAA;IACH,CAAC,iBAAG,SAAS,UAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAE,CAAA;IAEpC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AACxB,CAAC;AAlCD,kCAkCC","sourcesContent":["import { DependencyList, Dispatch, RefObject, SetStateAction, useEffect, useRef, useState } from 'react'\nimport ResizeObserver from 'resize-observer-polyfill'\nimport { Rect, Size } from 'spase'\n\n// const debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:hooks') : () => {}\n\ntype Options = {\n /**\n * Handler invoked when the target element resizes.\n *\n * @param size - The current size of the target element.\n */\n onResize?: (size: Size) => void\n}\n\n/**\n * Hook for monitoring the resizing event of the target element.\n *\n * @param targetRef - Reference to the target element.\n * @param options - See {@link Options}.\n * @param deps - Additional dependencies.\n *\n * @returns A tuple consisting of a stateful value indicating the size of the target ref, and a\n * function that sets its size.\n */\nexport default function useResizeEffect(targetRef: RefObject<Element>, { onResize }: Options = {}, deps?: DependencyList): [Size, Dispatch<SetStateAction<Size>>] {\n const observerRef = useRef<ResizeObserver | undefined>(undefined)\n const [size, setSize] = useState<Size>(new Size())\n\n useEffect(() => {\n // debug(`Using resize effect for element ${targetRef.current}...`, 'OK')\n\n observerRef.current = new ResizeObserver(() => {\n const rect = Rect.from(targetRef.current)\n\n if (!rect) return\n\n const size = rect.size\n\n // debug(`Observing size change for element ${targetRef.current}...`, 'OK', size)\n\n setSize(size)\n onResize?.(size)\n })\n\n if (observerRef.current && targetRef.current) {\n observerRef.current.observe(targetRef.current)\n }\n\n return () => {\n // debug(`Removing resize effect for element ${targetRef.current}...`, 'OK')\n\n if (observerRef.current && targetRef.current) {\n observerRef.current.unobserve(targetRef.current)\n }\n }\n }, [targetRef, ...deps ? deps : []])\n\n return [size, setSize]\n}\n"]}
1
+ {"version":3,"file":"useResizeEffect.js","sourceRoot":"/","sources":["hooks/useResizeEffect.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,+BAAwG;AACxG,sFAAqD;AACrD,+BAAkC;AAWlC;;;;;;;;;GASG;AACH,SAAwB,eAAe,CAAC,SAA6B,EAAE,EAA0B,EAAE,IAAqB;QAAjD,qBAAwB,EAAE,KAAA,EAAxB,QAAQ,cAAA;IAC/E,IAAM,WAAW,GAAG,IAAA,cAAM,EAA6B,SAAS,CAAC,CAAA;IAC3D,IAAA,KAAA,OAAkB,IAAA,gBAAQ,EAAO,IAAI,YAAI,EAAE,CAAC,IAAA,EAA3C,IAAI,QAAA,EAAE,OAAO,QAA8B,CAAA;IAElD,IAAA,iBAAS,EAAC;QACR,WAAW,CAAC,OAAO,GAAG,IAAI,kCAAc,CAAC;YACvC,IAAM,IAAI,GAAG,YAAI,CAAC,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;YAEzC,IAAI,CAAC,IAAI;gBAAE,OAAM;YAEjB,IAAM,OAAO,GAAG,IAAI,CAAC,IAAI,CAAA;YAEzB,OAAO,CAAC,OAAO,CAAC,CAAA;YAChB,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAG,OAAO,CAAC,CAAA;QACrB,CAAC,CAAC,CAAA;QAEF,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;YAC5C,WAAW,CAAC,OAAO,CAAC,OAAO,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;SAC/C;QAED,OAAO;YACL,IAAI,WAAW,CAAC,OAAO,IAAI,SAAS,CAAC,OAAO,EAAE;gBAC5C,WAAW,CAAC,OAAO,CAAC,SAAS,CAAC,SAAS,CAAC,OAAO,CAAC,CAAA;aACjD;QACH,CAAC,CAAA;IACH,CAAC,iBAAG,SAAS,UAAK,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,UAAE,CAAA;IAEpC,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;AACxB,CAAC;AA5BD,kCA4BC","sourcesContent":["import { DependencyList, Dispatch, RefObject, SetStateAction, useEffect, useRef, useState } from 'react'\nimport ResizeObserver from 'resize-observer-polyfill'\nimport { Rect, Size } from 'spase'\n\ntype Options = {\n /**\n * Handler invoked when the target element resizes.\n *\n * @param size - The current size of the target element.\n */\n onResize?: (size: Size) => void\n}\n\n/**\n * Hook for monitoring the resizing event of the target element.\n *\n * @param targetRef - Reference to the target element.\n * @param options - See {@link Options}.\n * @param deps - Additional dependencies.\n *\n * @returns A tuple consisting of a stateful value indicating the size of the\n * target ref, and a function that sets its size.\n */\nexport default function useResizeEffect(targetRef: RefObject<Element>, { onResize }: Options = {}, deps?: DependencyList): [Size, Dispatch<SetStateAction<Size>>] {\n const observerRef = useRef<ResizeObserver | undefined>(undefined)\n const [size, setSize] = useState<Size>(new Size())\n\n useEffect(() => {\n observerRef.current = new ResizeObserver(() => {\n const rect = Rect.from(targetRef.current)\n\n if (!rect) return\n\n const newSize = rect.size\n\n setSize(newSize)\n onResize?.(newSize)\n })\n\n if (observerRef.current && targetRef.current) {\n observerRef.current.observe(targetRef.current)\n }\n\n return () => {\n if (observerRef.current && targetRef.current) {\n observerRef.current.unobserve(targetRef.current)\n }\n }\n }, [targetRef, ...deps ? deps : []])\n\n return [size, setSize]\n}\n"]}
@@ -1,15 +1,18 @@
1
1
  import { Dispatch, SetStateAction } from 'react';
2
2
  export declare type Options<T> = {
3
3
  /**
4
- * Function for transforming the search param value to the value of the mapped state.
4
+ * Function for transforming the search param value to the value of the mapped
5
+ * state.
5
6
  *
6
- * @param value - The search param value. `undefined` means the value is unavailable.
7
+ * @param value - The search param value. `undefined` means the value is
8
+ * unavailable.
7
9
  *
8
10
  * @returns The equivalent state value.
9
11
  */
10
12
  mapSearchParamToState?: (value?: string) => T;
11
13
  /**
12
- * Function for transforming the value of the mapped state to the search param value.
14
+ * Function for transforming the value of the mapped state to the search param
15
+ * value.
13
16
  *
14
17
  * @param state - The state value.
15
18
  *
@@ -18,14 +21,14 @@ export declare type Options<T> = {
18
21
  mapStateToSearchParam?: (state: T) => string | undefined;
19
22
  };
20
23
  /**
21
- * Hook for mapping a search param to a state. Whenever the value of the target search param
22
- * changes, the mapped state will change as well, and vice versa.
24
+ * Hook for mapping a search param to a state. Whenever the value of the target
25
+ * search param changes, the mapped state will change as well, and vice versa.
23
26
  *
24
27
  * @param param - The search param key.
25
28
  * @param defaultValue - The default value of the state.
26
29
  * @param options - See {@link Options}.
27
30
  *
28
- * @returns A tuple consisting of a stateful value representing the current value of the mapped
29
- * state and a function that updates it.
31
+ * @returns A tuple consisting of a stateful value representing the current
32
+ * value of the mapped state and a function that updates it.
30
33
  */
31
34
  export default function useSearchParamState<T>(param: string, defaultValue: T, { mapSearchParamToState, mapStateToSearchParam }?: Options<T>): [T, Dispatch<SetStateAction<T>>];
@@ -15,36 +15,40 @@ var __read = (this && this.__read) || function (o, n) {
15
15
  }
16
16
  return ar;
17
17
  };
18
+ var __importDefault = (this && this.__importDefault) || function (mod) {
19
+ return (mod && mod.__esModule) ? mod : { "default": mod };
20
+ };
18
21
  Object.defineProperty(exports, "__esModule", { value: true });
19
22
  var react_1 = require("react");
20
23
  var react_router_dom_1 = require("react-router-dom");
21
- var debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:hooks') : function () { };
24
+ var useDebug_1 = __importDefault(require("../utils/useDebug"));
25
+ var debug = (0, useDebug_1.default)('hooks');
22
26
  /**
23
- * Hook for mapping a search param to a state. Whenever the value of the target search param
24
- * changes, the mapped state will change as well, and vice versa.
27
+ * Hook for mapping a search param to a state. Whenever the value of the target
28
+ * search param changes, the mapped state will change as well, and vice versa.
25
29
  *
26
30
  * @param param - The search param key.
27
31
  * @param defaultValue - The default value of the state.
28
32
  * @param options - See {@link Options}.
29
33
  *
30
- * @returns A tuple consisting of a stateful value representing the current value of the mapped
31
- * state and a function that updates it.
34
+ * @returns A tuple consisting of a stateful value representing the current
35
+ * value of the mapped state and a function that updates it.
32
36
  */
33
37
  function useSearchParamState(param, defaultValue, _a) {
34
38
  var _b;
35
39
  var _c = _a === void 0 ? {} : _a, mapSearchParamToState = _c.mapSearchParamToState, mapStateToSearchParam = _c.mapStateToSearchParam;
36
- var _mapSearchParamToState = function (value, defaultValue) {
40
+ var defaultMapSearchParamToState = function (value, fallback) {
37
41
  if (mapSearchParamToState) {
38
42
  return mapSearchParamToState(value);
39
43
  }
40
44
  else if (!value) {
41
- return defaultValue;
45
+ return fallback;
42
46
  }
43
47
  else {
44
48
  return value;
45
49
  }
46
50
  };
47
- var _mapStateToSearchParam = function (state) {
51
+ var defaultMapStateToSearchParam = function (state) {
48
52
  if (mapStateToSearchParam) {
49
53
  return mapStateToSearchParam(state);
50
54
  }
@@ -56,12 +60,12 @@ function useSearchParamState(param, defaultValue, _a) {
56
60
  }
57
61
  };
58
62
  var _d = __read((0, react_router_dom_1.useSearchParams)(), 2), searchParams = _d[0], setSearchParams = _d[1];
59
- var currentState = _mapSearchParamToState((_b = searchParams.get(param)) !== null && _b !== void 0 ? _b : undefined, defaultValue);
63
+ var currentState = defaultMapSearchParamToState((_b = searchParams.get(param)) !== null && _b !== void 0 ? _b : undefined, defaultValue);
60
64
  var _e = __read((0, react_1.useState)(currentState), 2), state = _e[0], setState = _e[1];
61
65
  debug('Using search param state...', 'OK', "param=".concat(param, ", defaultValue=").concat(currentState));
62
66
  (0, react_1.useEffect)(function () {
63
67
  var value = searchParams.get(param);
64
- var newValue = _mapStateToSearchParam(state);
68
+ var newValue = defaultMapStateToSearchParam(state);
65
69
  if (newValue === value)
66
70
  return;
67
71
  if (!newValue) {
@@ -1 +1 @@
1
- {"version":3,"file":"useSearchParamState.js","sourceRoot":"/","sources":["hooks/useSearchParamState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;AAAA,+BAAqE;AACrE,qDAAkD;AAElD,IAAM,KAAK,GAAG,OAAO,CAAC,GAAG,CAAC,QAAQ,KAAK,aAAa,CAAC,CAAC,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,cAAc,CAAC,CAAC,CAAC,CAAC,cAAO,CAAC,CAAA;AAsBlG;;;;;;;;;;GAUG;AACH,SAAwB,mBAAmB,CAAI,KAAa,EAAE,YAAe,EAAE,EAAiE;;QAAjE,qBAA+D,EAAE,KAAA,EAA/D,qBAAqB,2BAAA,EAAE,qBAAqB,2BAAA;IAC3H,IAAM,sBAAsB,GAAG,UAAC,KAAyB,EAAE,YAAe;QACxE,IAAI,qBAAqB,EAAE;YACzB,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAA;SACpC;aACI,IAAI,CAAC,KAAK,EAAE;YACf,OAAO,YAAY,CAAA;SACpB;aACI;YACH,OAAO,KAAkC,CAAA;SAC1C;IACH,CAAC,CAAA;IAED,IAAM,sBAAs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C1B,CAAC;AAlDD,sCAkDC","sourcesContent":["import { Dispatch, SetStateAction, useEffect, useState } from 'react'\nimport { useSearchParams } from 'react-router-dom'\n\nconst debug = process.env.NODE_ENV === 'development' ? require('debug')('etudes:hooks') : () => {}\n\nexport type Options<T> = {\n /**\n * Function for transforming the search param value to the value of the mapped state.\n *\n * @param value - The search param value. `undefined` means the value is unavailable.\n *\n * @returns The equivalent state value.\n */\n mapSearchParamToState?: (value?: string) => T\n\n /**\n * Function for transforming the value of the mapped state to the search param value.\n *\n * @param state - The state value.\n *\n * @returns The equivalent search param value.\n */\n mapStateToSearchParam?: (state: T) => string | undefined\n}\n\n/**\n * Hook for mapping a search param to a state. Whenever the value of the target search param\n * changes, the mapped state will change as well, and vice versa.\n *\n * @param param - The search param key.\n * @param defaultValue - The default value of the state.\n * @param options - See {@link Options}.\n *\n * @returns A tuple consisting of a stateful value representing the current value of the mapped\n * state and a function that updates it.\n */\nexport default function useSearchParamState<T>(param: string, defaultValue: T, { mapSearchParamToState, mapStateToSearchParam }: Options<T> = {}): [T, Dispatch<SetStateAction<T>>] {\n const _mapSearchParamToState = (value: string | undefined, defaultValue: T): T => {\n if (mapSearchParamToState) {\n return mapSearchParamToState(value)\n }\n else if (!value) {\n return defaultValue\n }\n else {\n return value as unknown as NonNullable<T>\n }\n }\n\n const _mapStateToSearchParam = (state: T): string | undefined => {\n if (mapStateToSearchParam) {\n return mapStateToSearchParam(state)\n }\n else if (state === defaultValue) {\n return undefined\n }\n else {\n return `${state}`\n }\n }\n\n const [searchParams, setSearchParams] = useSearchParams()\n const currentState = _mapSearchParamToState(searchParams.get(param) ?? undefined, defaultValue)\n const [state, setState] = useState(currentState)\n\n debug('Using search param state...', 'OK', `param=${param}, defaultValue=${currentState}`)\n\n useEffect(() => {\n const value = searchParams.get(param)\n const newValue = _mapStateToSearchParam(state)\n\n if (newValue === value) return\n\n if (!newValue) {\n searchParams.delete(param)\n }\n else {\n searchParams.set(param, newValue)\n }\n\n debug('Handling state change...', 'OK', `state=${state}, oldValue=${value}, newValue=${newValue}`)\n\n setSearchParams(searchParams)\n }, [state])\n\n return [state, setState]\n}\n"]}
1
+ {"version":3,"file":"useSearchParamState.js","sourceRoot":"/","sources":["hooks/useSearchParamState.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;AAAA,+BAAqE;AACrE,qDAAkD;AAClD,+DAAwC;AAExC,IAAM,KAAK,GAAG,IAAA,kBAAQ,EAAC,OAAO,CAAC,CAAA;AAyB/B;;;;;;;;;;GAUG;AACH,SAAwB,mBAAmB,CAAI,KAAa,EAAE,YAAe,EAAE,EAAiE;;QAAjE,qBAA+D,EAAE,KAAA,EAA/D,qBAAqB,2BAAA,EAAE,qBAAqB,2BAAA;IAC3H,IAAM,4BAA4B,GAAG,UAAC,KAAyB,EAAE,QAAW;QAC1E,IAAI,qBAAqB,EAAE;YACzB,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAA;SACpC;aACI,IAAI,CAAC,KAAK,EAAE;YACf,OAAO,QAAQ,CAAA;SAChB;aACI;YACH,OAAO,KAAkC,CAAA;SAC1C;IACH,CAAC,CAAA;IAED,IAAM,4BAA4B,GAAG,UAAC,KAAQ;QAC5C,IAAI,qBAAqB,EAAE;YACzB,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAA;SACpC;aACI,IAAI,KAAK,KAAK,YAAY,EAAE;YAC/B,OAAO,SAAS,CAAA;SACjB;aACI;YACH,OAAO,UAAG,KAAK,CAAE,CAAA;SAClB;IACH,CAAC,CAAA;IAEK,IAAA,KAAA,OAAkC,IAAA,kCAAe,GAAE,IAAA,EAAlD,YAAY,QAAA,EAAE,eAAe,QAAqB,CAAA;IACzD,IAAM,YAAY,GAAG,4BAA4B,CAAC,MAAA,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,mCAAI,SAAS,EAAE,YAAY,CAAC,CAAA;IAC/F,IAAA,KAAA,OAAoB,IAAA,gBAAQ,EAAC,YAAY,CAAC,IAAA,EAAzC,KAAK,QAAA,EAAE,QAAQ,QAA0B,CAAA;IAEhD,KAAK,CAAC,6BAA6B,EAAE,IAAI,EAAE,gBAAS,KAAK,4BAAkB,YAAY,CAAE,CAAC,CAAA;IAE1F,IAAA,iBAAS,EAAC;QACR,IAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,KAAK,CAAC,CAAA;QACrC,IAAM,QAAQ,GAAG,4BAA4B,CAAC,KAAK,CAAC,CAAA;QAEpD,IAAI,QAAQ,KAAK,KAAK;YAAE,OAAM;QAE9B,IAAI,CAAC,QAAQ,EAAE;YACb,YAAY,CAAC,MAAM,CAAC,KAAK,CAAC,CAAA;SAC3B;aACI;YACH,YAAY,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;SAClC;QAED,KAAK,CAAC,0BAA0B,EAAE,IAAI,EAAE,gBAAS,KAAK,wBAAc,KAAK,wBAAc,QAAQ,CAAE,CAAC,CAAA;QAElG,eAAe,CAAC,YAAY,CAAC,CAAA;IAC/B,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAA;IAEX,OAAO,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAA;AAC1B,CAAC;AAlDD,sCAkDC","sourcesContent":["import { Dispatch, SetStateAction, useEffect, useState } from 'react'\nimport { useSearchParams } from 'react-router-dom'\nimport useDebug from '../utils/useDebug'\n\nconst debug = useDebug('hooks')\n\nexport type Options<T> = {\n /**\n * Function for transforming the search param value to the value of the mapped\n * state.\n *\n * @param value - The search param value. `undefined` means the value is\n * unavailable.\n *\n * @returns The equivalent state value.\n */\n mapSearchParamToState?: (value?: string) => T\n\n /**\n * Function for transforming the value of the mapped state to the search param\n * value.\n *\n * @param state - The state value.\n *\n * @returns The equivalent search param value.\n */\n mapStateToSearchParam?: (state: T) => string | undefined\n}\n\n/**\n * Hook for mapping a search param to a state. Whenever the value of the target\n * search param changes, the mapped state will change as well, and vice versa.\n *\n * @param param - The search param key.\n * @param defaultValue - The default value of the state.\n * @param options - See {@link Options}.\n *\n * @returns A tuple consisting of a stateful value representing the current\n * value of the mapped state and a function that updates it.\n */\nexport default function useSearchParamState<T>(param: string, defaultValue: T, { mapSearchParamToState, mapStateToSearchParam }: Options<T> = {}): [T, Dispatch<SetStateAction<T>>] {\n const defaultMapSearchParamToState = (value: string | undefined, fallback: T): T => {\n if (mapSearchParamToState) {\n return mapSearchParamToState(value)\n }\n else if (!value) {\n return fallback\n }\n else {\n return value as unknown as NonNullable<T>\n }\n }\n\n const defaultMapStateToSearchParam = (state: T): string | undefined => {\n if (mapStateToSearchParam) {\n return mapStateToSearchParam(state)\n }\n else if (state === defaultValue) {\n return undefined\n }\n else {\n return `${state}`\n }\n }\n\n const [searchParams, setSearchParams] = useSearchParams()\n const currentState = defaultMapSearchParamToState(searchParams.get(param) ?? undefined, defaultValue)\n const [state, setState] = useState(currentState)\n\n debug('Using search param state...', 'OK', `param=${param}, defaultValue=${currentState}`)\n\n useEffect(() => {\n const value = searchParams.get(param)\n const newValue = defaultMapStateToSearchParam(state)\n\n if (newValue === value) return\n\n if (!newValue) {\n searchParams.delete(param)\n }\n else {\n searchParams.set(param, newValue)\n }\n\n debug('Handling state change...', 'OK', `state=${state}, oldValue=${value}, newValue=${newValue}`)\n\n setSearchParams(searchParams)\n }, [state])\n\n return [state, setState]\n}\n"]}
@@ -0,0 +1,3 @@
1
+ export default function asClassNameDict<T>(dict: {
2
+ [K in keyof T]: string;
3
+ }): { [K in keyof T]: string; };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function asClassNameDict(dict) {
4
+ return dict;
5
+ }
6
+ exports.default = asClassNameDict;
7
+ //# sourceMappingURL=asClassNameDict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asClassNameDict.js","sourceRoot":"/","sources":["utils/asClassNameDict.ts"],"names":[],"mappings":";;AAAA,SAAwB,eAAe,CAAI,IAAgC;IACzE,OAAO,IAAI,CAAA;AACb,CAAC;AAFD,kCAEC","sourcesContent":["export default function asClassNameDict<T>(dict: { [K in keyof T]: string }) {\n return dict\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import { JSXElementConstructor, ReactNode } from 'react';
2
+ declare type ComponentTypeDict = Record<string, JSXElementConstructor<any>>;
3
+ declare type ComponentElementDict<T extends ComponentTypeDict> = Record<keyof T, JSX.Element>;
4
+ export default function asComponentDict<T extends ComponentTypeDict>(children?: ReactNode, typeDict?: T): Partial<ComponentElementDict<T>>;
5
+ export {};
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ var react_1 = require("react");
4
+ function asComponentDict(children, typeDict) {
5
+ if (typeDict === void 0) { typeDict = {}; }
6
+ var keys = Object.keys(typeDict);
7
+ var types = Object.values(typeDict);
8
+ var components = {};
9
+ react_1.Children.forEach(children, function (child) {
10
+ if (!(0, react_1.isValidElement)(child))
11
+ throw Error('Invalid child detected');
12
+ var index = types.indexOf(child.type);
13
+ if (index < 0)
14
+ throw Error("Unsupported child, only the following children are allowed: ".concat(types));
15
+ var key = keys[index];
16
+ if (components[key])
17
+ throw Error("Only one ".concat(types[index], " can be provided as a child"));
18
+ components[key] = child;
19
+ });
20
+ return components;
21
+ }
22
+ exports.default = asComponentDict;
23
+ //# sourceMappingURL=asComponentDict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asComponentDict.js","sourceRoot":"/","sources":["utils/asComponentDict.ts"],"names":[],"mappings":";;AAAA,+BAAkF;AAMlF,SAAwB,eAAe,CAA8B,QAAoB,EAAE,QAAqB;IAArB,yBAAA,EAAA,WAAc,EAAO;IAC9G,IAAM,IAAI,GAAgB,MAAM,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAA;IAC/C,IAAM,KAAK,GAAG,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;IACrC,IAAM,UAAU,GAAqC,EAAE,CAAA;IAEvD,gBAAQ,CAAC,OAAO,CAAC,QAAQ,EAAE,UAAA,KAAK;QAC9B,IAAI,CAAC,IAAA,sBAAc,EAAC,KAAK,CAAC;YAAE,MAAM,KAAK,CAAC,wBAAwB,CAAC,CAAA;QAEjE,IAAM,KAAK,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,IAAW,CAAC,CAAA;QAC9C,IAAI,KAAK,GAAG,CAAC;YAAE,MAAM,KAAK,CAAC,sEAA+D,KAAK,CAAE,CAAC,CAAA;QAElG,IAAM,GAAG,GAAG,IAAI,CAAC,KAAK,CAAC,CAAA;QACvB,IAAI,UAAU,CAAC,GAAG,CAAC;YAAE,MAAM,KAAK,CAAC,mBAAY,KAAK,CAAC,KAAK,CAAC,gCAA6B,CAAC,CAAA;QAEvF,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,CAAA;IACzB,CAAC,CAAC,CAAA;IAEF,OAAO,UAAU,CAAA;AACnB,CAAC;AAlBD,kCAkBC","sourcesContent":["import { Children, isValidElement, JSXElementConstructor, ReactNode } from 'react'\n\ntype ComponentTypeDict = Record<string, JSXElementConstructor<any>>\n\ntype ComponentElementDict<T extends ComponentTypeDict> = Record<keyof T, JSX.Element>\n\nexport default function asComponentDict<T extends ComponentTypeDict>(children?: ReactNode, typeDict: T = {} as T): Partial<ComponentElementDict<T>> {\n const keys: (keyof T)[] = Object.keys(typeDict)\n const types = Object.values(typeDict)\n const components: Partial<ComponentElementDict<T>> = {}\n\n Children.forEach(children, child => {\n if (!isValidElement(child)) throw Error('Invalid child detected')\n\n const index = types.indexOf(child.type as any)\n if (index < 0) throw Error(`Unsupported child, only the following children are allowed: ${types}`)\n\n const key = keys[index]\n if (components[key]) throw Error(`Only one ${types[index]} can be provided as a child`)\n\n components[key] = child\n })\n\n return components\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import { CSSProperties } from 'react';
2
+ export default function asStyleDict<T>(dict: {
3
+ [K in keyof T]: CSSProperties;
4
+ }): { [K in keyof T]: CSSProperties; };
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ function asStyleDict(dict) {
4
+ return dict;
5
+ }
6
+ exports.default = asStyleDict;
7
+ //# sourceMappingURL=asStyleDict.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"asStyleDict.js","sourceRoot":"/","sources":["utils/asStyleDict.ts"],"names":[],"mappings":";;AAEA,SAAwB,WAAW,CAAI,IAAuC;IAC5E,OAAO,IAAI,CAAA;AACb,CAAC;AAFD,8BAEC","sourcesContent":["import { CSSProperties } from 'react'\n\nexport default function asStyleDict<T>(dict: { [K in keyof T]: CSSProperties }) {\n return dict\n}\n"]}
@@ -0,0 +1,18 @@
1
+ import { Attributes, CElement, ClassAttributes, Component, ComponentState, FunctionComponentElement, ReactElement, ReactNode } from 'react';
2
+ /**
3
+ * Wrapper for {@link cloneElement} but instead of overwriting `className` and
4
+ * `style` of the cloned element with the values specified in the `props`
5
+ * argument, they are merged instead.
6
+ *
7
+ * @param element - The target element to clone.
8
+ * @param props - The props to apply to the cloned element. Overlapping props
9
+ * are overwritten with the exception of `className` and `style`,
10
+ * which are merged.
11
+ * @param children - Optional child elements add into the cloned element.
12
+ *
13
+ * @returns The cloned element.
14
+ */
15
+ declare function cloneStyledElement<P>(element: FunctionComponentElement<P>, props?: Partial<P> & Attributes, ...children: ReactNode[]): FunctionComponentElement<P>;
16
+ declare function cloneStyledElement<P, T extends Component<P, ComponentState>>(element: CElement<P, T>, props?: Partial<P> & ClassAttributes<T>, ...children: ReactNode[]): CElement<P, T>;
17
+ declare function cloneStyledElement<P>(element: ReactElement<P>, props?: Partial<P> & Attributes, ...children: ReactNode[]): ReactElement<P>;
18
+ export default cloneStyledElement;