@fringeworks/react-utils 0.8.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 (177) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +3 -0
  3. package/_helpers/_traverseContent.cjs +24 -0
  4. package/_helpers/_traverseContent.d.cts +15 -0
  5. package/_helpers/_traverseContent.d.mts +16 -0
  6. package/_helpers/_traverseContent.mjs +22 -0
  7. package/_helpers/_traverseElement.cjs +23 -0
  8. package/_helpers/_traverseElement.d.cts +15 -0
  9. package/_helpers/_traverseElement.d.mts +16 -0
  10. package/_helpers/_traverseElement.mjs +21 -0
  11. package/_virtual/_rolldown/runtime.cjs +43 -0
  12. package/_virtual/_rolldown/runtime.mjs +18 -0
  13. package/hooks/index.cjs +42 -0
  14. package/hooks/index.d.cts +14 -0
  15. package/hooks/index.d.mts +14 -0
  16. package/hooks/index.mjs +29 -0
  17. package/hooks/useCombinedRefs/index.cjs +3 -0
  18. package/hooks/useCombinedRefs/index.d.cts +2 -0
  19. package/hooks/useCombinedRefs/index.d.mts +2 -0
  20. package/hooks/useCombinedRefs/index.mjs +3 -0
  21. package/hooks/useCombinedRefs/useCombinedRefs.cjs +20 -0
  22. package/hooks/useCombinedRefs/useCombinedRefs.d.cts +10 -0
  23. package/hooks/useCombinedRefs/useCombinedRefs.d.mts +11 -0
  24. package/hooks/useCombinedRefs/useCombinedRefs.mjs +20 -0
  25. package/hooks/useConstant/index.cjs +3 -0
  26. package/hooks/useConstant/index.d.cts +2 -0
  27. package/hooks/useConstant/index.d.mts +2 -0
  28. package/hooks/useConstant/index.mjs +3 -0
  29. package/hooks/useConstant/useConstant.cjs +19 -0
  30. package/hooks/useConstant/useConstant.d.cts +12 -0
  31. package/hooks/useConstant/useConstant.d.mts +13 -0
  32. package/hooks/useConstant/useConstant.mjs +19 -0
  33. package/hooks/useExecutionAt/index.cjs +3 -0
  34. package/hooks/useExecutionAt/index.d.cts +3 -0
  35. package/hooks/useExecutionAt/index.d.mts +3 -0
  36. package/hooks/useExecutionAt/index.mjs +3 -0
  37. package/hooks/useExecutionAt/types.cjs +0 -0
  38. package/hooks/useExecutionAt/types.d.cts +35 -0
  39. package/hooks/useExecutionAt/types.d.mts +35 -0
  40. package/hooks/useExecutionAt/types.mjs +1 -0
  41. package/hooks/useExecutionAt/useExecutionAt.cjs +38 -0
  42. package/hooks/useExecutionAt/useExecutionAt.d.cts +24 -0
  43. package/hooks/useExecutionAt/useExecutionAt.d.mts +25 -0
  44. package/hooks/useExecutionAt/useExecutionAt.mjs +38 -0
  45. package/hooks/useIsMounted/index.cjs +3 -0
  46. package/hooks/useIsMounted/index.d.cts +2 -0
  47. package/hooks/useIsMounted/index.d.mts +2 -0
  48. package/hooks/useIsMounted/index.mjs +3 -0
  49. package/hooks/useIsMounted/useIsMounted.cjs +21 -0
  50. package/hooks/useIsMounted/useIsMounted.d.cts +7 -0
  51. package/hooks/useIsMounted/useIsMounted.d.mts +8 -0
  52. package/hooks/useIsMounted/useIsMounted.mjs +21 -0
  53. package/hooks/useLatestRef/index.cjs +3 -0
  54. package/hooks/useLatestRef/index.d.cts +3 -0
  55. package/hooks/useLatestRef/index.d.mts +3 -0
  56. package/hooks/useLatestRef/index.mjs +3 -0
  57. package/hooks/useLatestRef/types.cjs +0 -0
  58. package/hooks/useLatestRef/types.d.cts +12 -0
  59. package/hooks/useLatestRef/types.d.mts +12 -0
  60. package/hooks/useLatestRef/types.mjs +1 -0
  61. package/hooks/useLatestRef/useLatestRef.cjs +23 -0
  62. package/hooks/useLatestRef/useLatestRef.d.cts +15 -0
  63. package/hooks/useLatestRef/useLatestRef.d.mts +16 -0
  64. package/hooks/useLatestRef/useLatestRef.mjs +23 -0
  65. package/hooks/usePreviousValue/index.cjs +3 -0
  66. package/hooks/usePreviousValue/index.d.cts +3 -0
  67. package/hooks/usePreviousValue/index.d.mts +3 -0
  68. package/hooks/usePreviousValue/index.mjs +3 -0
  69. package/hooks/usePreviousValue/types.cjs +0 -0
  70. package/hooks/usePreviousValue/types.d.cts +18 -0
  71. package/hooks/usePreviousValue/types.d.mts +18 -0
  72. package/hooks/usePreviousValue/types.mjs +1 -0
  73. package/hooks/usePreviousValue/usePreviousValue.cjs +23 -0
  74. package/hooks/usePreviousValue/usePreviousValue.d.cts +11 -0
  75. package/hooks/usePreviousValue/usePreviousValue.d.mts +12 -0
  76. package/hooks/usePreviousValue/usePreviousValue.mjs +23 -0
  77. package/hooks/useStableLength/index.cjs +3 -0
  78. package/hooks/useStableLength/index.d.cts +2 -0
  79. package/hooks/useStableLength/index.d.mts +2 -0
  80. package/hooks/useStableLength/index.mjs +3 -0
  81. package/hooks/useStableLength/useStableLength.cjs +16 -0
  82. package/hooks/useStableLength/useStableLength.d.cts +9 -0
  83. package/hooks/useStableLength/useStableLength.d.mts +10 -0
  84. package/hooks/useStableLength/useStableLength.mjs +16 -0
  85. package/index.cjs +16 -0
  86. package/index.d.cts +4 -0
  87. package/index.d.mts +4 -0
  88. package/index.mjs +4 -0
  89. package/package.json +91 -0
  90. package/types.cjs +0 -0
  91. package/types.d.cts +11 -0
  92. package/types.d.mts +11 -0
  93. package/types.mjs +1 -0
  94. package/utils/applyDefaultProps/applyDefaultProps.cjs +41 -0
  95. package/utils/applyDefaultProps/applyDefaultProps.d.cts +33 -0
  96. package/utils/applyDefaultProps/applyDefaultProps.d.mts +34 -0
  97. package/utils/applyDefaultProps/applyDefaultProps.mjs +40 -0
  98. package/utils/applyDefaultProps/index.cjs +3 -0
  99. package/utils/applyDefaultProps/index.d.cts +3 -0
  100. package/utils/applyDefaultProps/index.d.mts +3 -0
  101. package/utils/applyDefaultProps/index.mjs +3 -0
  102. package/utils/applyDefaultProps/types.cjs +0 -0
  103. package/utils/applyDefaultProps/types.d.cts +27 -0
  104. package/utils/applyDefaultProps/types.d.mts +27 -0
  105. package/utils/applyDefaultProps/types.mjs +1 -0
  106. package/utils/ensureComponent/ensureComponent.cjs +28 -0
  107. package/utils/ensureComponent/ensureComponent.d.cts +10 -0
  108. package/utils/ensureComponent/ensureComponent.d.mts +11 -0
  109. package/utils/ensureComponent/ensureComponent.mjs +28 -0
  110. package/utils/ensureComponent/index.cjs +3 -0
  111. package/utils/ensureComponent/index.d.cts +2 -0
  112. package/utils/ensureComponent/index.d.mts +2 -0
  113. package/utils/ensureComponent/index.mjs +3 -0
  114. package/utils/extendElement/extendElement.cjs +30 -0
  115. package/utils/extendElement/extendElement.d.cts +12 -0
  116. package/utils/extendElement/extendElement.d.mts +13 -0
  117. package/utils/extendElement/extendElement.mjs +30 -0
  118. package/utils/extendElement/index.cjs +3 -0
  119. package/utils/extendElement/index.d.cts +2 -0
  120. package/utils/extendElement/index.d.mts +2 -0
  121. package/utils/extendElement/index.mjs +3 -0
  122. package/utils/forEachContent/forEachContent.cjs +14 -0
  123. package/utils/forEachContent/forEachContent.d.cts +10 -0
  124. package/utils/forEachContent/forEachContent.d.mts +11 -0
  125. package/utils/forEachContent/forEachContent.mjs +14 -0
  126. package/utils/forEachContent/index.cjs +3 -0
  127. package/utils/forEachContent/index.d.cts +2 -0
  128. package/utils/forEachContent/index.d.mts +2 -0
  129. package/utils/forEachContent/index.mjs +3 -0
  130. package/utils/forEachElement/forEachElement.cjs +14 -0
  131. package/utils/forEachElement/forEachElement.d.cts +10 -0
  132. package/utils/forEachElement/forEachElement.d.mts +11 -0
  133. package/utils/forEachElement/forEachElement.mjs +14 -0
  134. package/utils/forEachElement/index.cjs +3 -0
  135. package/utils/forEachElement/index.d.cts +2 -0
  136. package/utils/forEachElement/index.d.mts +2 -0
  137. package/utils/forEachElement/index.mjs +3 -0
  138. package/utils/index.cjs +47 -0
  139. package/utils/index.d.cts +14 -0
  140. package/utils/index.d.mts +14 -0
  141. package/utils/index.mjs +32 -0
  142. package/utils/markAt/index.cjs +3 -0
  143. package/utils/markAt/index.d.cts +3 -0
  144. package/utils/markAt/index.d.mts +3 -0
  145. package/utils/markAt/index.mjs +3 -0
  146. package/utils/markAt/markAt.cjs +14 -0
  147. package/utils/markAt/markAt.d.cts +9 -0
  148. package/utils/markAt/markAt.d.mts +10 -0
  149. package/utils/markAt/markAt.mjs +13 -0
  150. package/utils/markAt/types.cjs +0 -0
  151. package/utils/markAt/types.d.cts +4 -0
  152. package/utils/markAt/types.d.mts +4 -0
  153. package/utils/markAt/types.mjs +1 -0
  154. package/utils/setRefCurrent/index.cjs +3 -0
  155. package/utils/setRefCurrent/index.d.cts +2 -0
  156. package/utils/setRefCurrent/index.d.mts +2 -0
  157. package/utils/setRefCurrent/index.mjs +3 -0
  158. package/utils/setRefCurrent/setRefCurrent.cjs +29 -0
  159. package/utils/setRefCurrent/setRefCurrent.d.cts +11 -0
  160. package/utils/setRefCurrent/setRefCurrent.d.mts +12 -0
  161. package/utils/setRefCurrent/setRefCurrent.mjs +28 -0
  162. package/utils/transformContent/index.cjs +3 -0
  163. package/utils/transformContent/index.d.cts +2 -0
  164. package/utils/transformContent/index.d.mts +2 -0
  165. package/utils/transformContent/index.mjs +3 -0
  166. package/utils/transformContent/transformContent.cjs +16 -0
  167. package/utils/transformContent/transformContent.d.cts +10 -0
  168. package/utils/transformContent/transformContent.d.mts +11 -0
  169. package/utils/transformContent/transformContent.mjs +16 -0
  170. package/utils/transformElement/index.cjs +3 -0
  171. package/utils/transformElement/index.d.cts +2 -0
  172. package/utils/transformElement/index.d.mts +2 -0
  173. package/utils/transformElement/index.mjs +3 -0
  174. package/utils/transformElement/transformElement.cjs +16 -0
  175. package/utils/transformElement/transformElement.d.cts +10 -0
  176. package/utils/transformElement/transformElement.d.mts +11 -0
  177. package/utils/transformElement/transformElement.mjs +16 -0
@@ -0,0 +1,38 @@
1
+ const require_utils_markAt_markAt = require('../../utils/markAt/markAt.cjs');
2
+ let react = require("react");
3
+
4
+ //#region src/hooks/useExecutionAt/useExecutionAt.ts
5
+ /**
6
+ * Execution Requestプロパティ(xxxxxAt)へ渡す値と、\
7
+ * 処理実行用のトリガー関数を作るフック。\
8
+ * 命令的コンポーネントをラップしたreactコンポーネントで、\
9
+ * プロパティを通じて命令的コンポーネントのメソッドを実行する仕組みを提供する。
10
+ *
11
+ * @template P 実行時にExecution Requestプロパティに渡すペイロードの型
12
+ * @param options オプション
13
+ * @returns [request, execute]
14
+ * - `request`: 現在のリクエスト
15
+ * - `execute`: 新しいリクエストを発行する関数
16
+ * @example
17
+ * // 1. Hookの宣言
18
+ * const [undoAt, undo] = useExecutionAt<string>();
19
+ * // 2. 実行のトリガーになるコンポーネント
20
+ * <button onClick={() => undo('no-123')}>Undo</button>
21
+ * // 3. 処理を実行するコンポーネント
22
+ * <WrappedImperativeComponent undoAt={undoAt} />
23
+ */
24
+ function useExecutionAt(options = {}) {
25
+ const [executionRequest, setExecutionRequest] = (0, react.useState)({
26
+ at: 0,
27
+ payload: options.initialPayload
28
+ });
29
+ return [executionRequest, (0, react.useCallback)((payload) => {
30
+ setExecutionRequest({
31
+ at: require_utils_markAt_markAt(),
32
+ payload
33
+ });
34
+ }, [])];
35
+ }
36
+
37
+ //#endregion
38
+ module.exports = useExecutionAt;
@@ -0,0 +1,24 @@
1
+ import { UseExecutionAtOptions, UseExecutionAtResult } from "./types.cjs";
2
+
3
+ //#region src/hooks/useExecutionAt/useExecutionAt.d.ts
4
+ /**
5
+ * Execution Requestプロパティ(xxxxxAt)へ渡す値と、\
6
+ * 処理実行用のトリガー関数を作るフック。\
7
+ * 命令的コンポーネントをラップしたreactコンポーネントで、\
8
+ * プロパティを通じて命令的コンポーネントのメソッドを実行する仕組みを提供する。
9
+ *
10
+ * @template P 実行時にExecution Requestプロパティに渡すペイロードの型
11
+ * @param options オプション
12
+ * @returns [request, execute]
13
+ * - `request`: 現在のリクエスト
14
+ * - `execute`: 新しいリクエストを発行する関数
15
+ * @example
16
+ * // 1. Hookの宣言
17
+ * const [undoAt, undo] = useExecutionAt<string>();
18
+ * // 2. 実行のトリガーになるコンポーネント
19
+ * <button onClick={() => undo('no-123')}>Undo</button>
20
+ * // 3. 処理を実行するコンポーネント
21
+ * <WrappedImperativeComponent undoAt={undoAt} />
22
+ */
23
+ declare function useExecutionAt<P = void>(options?: UseExecutionAtOptions<P>): UseExecutionAtResult<P>;
24
+ export = useExecutionAt;
@@ -0,0 +1,25 @@
1
+ import { UseExecutionAtOptions, UseExecutionAtResult } from "./types.mjs";
2
+
3
+ //#region src/hooks/useExecutionAt/useExecutionAt.d.ts
4
+ /**
5
+ * Execution Requestプロパティ(xxxxxAt)へ渡す値と、\
6
+ * 処理実行用のトリガー関数を作るフック。\
7
+ * 命令的コンポーネントをラップしたreactコンポーネントで、\
8
+ * プロパティを通じて命令的コンポーネントのメソッドを実行する仕組みを提供する。
9
+ *
10
+ * @template P 実行時にExecution Requestプロパティに渡すペイロードの型
11
+ * @param options オプション
12
+ * @returns [request, execute]
13
+ * - `request`: 現在のリクエスト
14
+ * - `execute`: 新しいリクエストを発行する関数
15
+ * @example
16
+ * // 1. Hookの宣言
17
+ * const [undoAt, undo] = useExecutionAt<string>();
18
+ * // 2. 実行のトリガーになるコンポーネント
19
+ * <button onClick={() => undo('no-123')}>Undo</button>
20
+ * // 3. 処理を実行するコンポーネント
21
+ * <WrappedImperativeComponent undoAt={undoAt} />
22
+ */
23
+ declare function useExecutionAt<P = void>(options?: UseExecutionAtOptions<P>): UseExecutionAtResult<P>;
24
+ //#endregion
25
+ export { useExecutionAt as default };
@@ -0,0 +1,38 @@
1
+ import markAt from "../../utils/markAt/markAt.mjs";
2
+ import { useCallback, useState } from "react";
3
+
4
+ //#region src/hooks/useExecutionAt/useExecutionAt.ts
5
+ /**
6
+ * Execution Requestプロパティ(xxxxxAt)へ渡す値と、\
7
+ * 処理実行用のトリガー関数を作るフック。\
8
+ * 命令的コンポーネントをラップしたreactコンポーネントで、\
9
+ * プロパティを通じて命令的コンポーネントのメソッドを実行する仕組みを提供する。
10
+ *
11
+ * @template P 実行時にExecution Requestプロパティに渡すペイロードの型
12
+ * @param options オプション
13
+ * @returns [request, execute]
14
+ * - `request`: 現在のリクエスト
15
+ * - `execute`: 新しいリクエストを発行する関数
16
+ * @example
17
+ * // 1. Hookの宣言
18
+ * const [undoAt, undo] = useExecutionAt<string>();
19
+ * // 2. 実行のトリガーになるコンポーネント
20
+ * <button onClick={() => undo('no-123')}>Undo</button>
21
+ * // 3. 処理を実行するコンポーネント
22
+ * <WrappedImperativeComponent undoAt={undoAt} />
23
+ */
24
+ function useExecutionAt(options = {}) {
25
+ const [executionRequest, setExecutionRequest] = useState({
26
+ at: 0,
27
+ payload: options.initialPayload
28
+ });
29
+ return [executionRequest, useCallback((payload) => {
30
+ setExecutionRequest({
31
+ at: markAt(),
32
+ payload
33
+ });
34
+ }, [])];
35
+ }
36
+
37
+ //#endregion
38
+ export { useExecutionAt as default };
@@ -0,0 +1,3 @@
1
+ const require_hooks_useIsMounted_useIsMounted = require('./useIsMounted.cjs');
2
+
3
+ module.exports = require_hooks_useIsMounted_useIsMounted;
@@ -0,0 +1,2 @@
1
+ import useIsMounted from "./useIsMounted.cjs";
2
+ export = useIsMounted;
@@ -0,0 +1,2 @@
1
+ import useIsMounted from "./useIsMounted.mjs";
2
+ export { useIsMounted as default };
@@ -0,0 +1,3 @@
1
+ import useIsMounted from "./useIsMounted.mjs";
2
+
3
+ export { useIsMounted as default };
@@ -0,0 +1,21 @@
1
+ let react = require("react");
2
+
3
+ //#region src/hooks/useIsMounted/useIsMounted.ts
4
+ /**
5
+ * マウントされているかどうかを判定する関数を返すフック
6
+ * @returns
7
+ */
8
+ function useIsMounted() {
9
+ const isMountedRef = (0, react.useRef)(false);
10
+ const isMounted = (0, react.useCallback)(() => isMountedRef.current, []);
11
+ (0, react.useEffect)(() => {
12
+ isMountedRef.current = true;
13
+ return () => {
14
+ isMountedRef.current = false;
15
+ };
16
+ }, []);
17
+ return isMounted;
18
+ }
19
+
20
+ //#endregion
21
+ module.exports = useIsMounted;
@@ -0,0 +1,7 @@
1
+ //#region src/hooks/useIsMounted/useIsMounted.d.ts
2
+ /**
3
+ * マウントされているかどうかを判定する関数を返すフック
4
+ * @returns
5
+ */
6
+ declare function useIsMounted(): () => boolean;
7
+ export = useIsMounted;
@@ -0,0 +1,8 @@
1
+ //#region src/hooks/useIsMounted/useIsMounted.d.ts
2
+ /**
3
+ * マウントされているかどうかを判定する関数を返すフック
4
+ * @returns
5
+ */
6
+ declare function useIsMounted(): () => boolean;
7
+ //#endregion
8
+ export { useIsMounted as default };
@@ -0,0 +1,21 @@
1
+ import { useCallback, useEffect, useRef } from "react";
2
+
3
+ //#region src/hooks/useIsMounted/useIsMounted.ts
4
+ /**
5
+ * マウントされているかどうかを判定する関数を返すフック
6
+ * @returns
7
+ */
8
+ function useIsMounted() {
9
+ const isMountedRef = useRef(false);
10
+ const isMounted = useCallback(() => isMountedRef.current, []);
11
+ useEffect(() => {
12
+ isMountedRef.current = true;
13
+ return () => {
14
+ isMountedRef.current = false;
15
+ };
16
+ }, []);
17
+ return isMounted;
18
+ }
19
+
20
+ //#endregion
21
+ export { useIsMounted as default };
@@ -0,0 +1,3 @@
1
+ const require_hooks_useLatestRef_useLatestRef = require('./useLatestRef.cjs');
2
+
3
+ module.exports = require_hooks_useLatestRef_useLatestRef;
@@ -0,0 +1,3 @@
1
+ import { LatestRef } from "./types.cjs";
2
+ import useLatestRef from "./useLatestRef.cjs";
3
+ export { type LatestRef, useLatestRef as default };
@@ -0,0 +1,3 @@
1
+ import { LatestRef } from "./types.mjs";
2
+ import useLatestRef from "./useLatestRef.mjs";
3
+ export { type LatestRef, useLatestRef as default };
@@ -0,0 +1,3 @@
1
+ import useLatestRef from "./useLatestRef.mjs";
2
+
3
+ export { useLatestRef as default };
File without changes
@@ -0,0 +1,12 @@
1
+ //#region src/hooks/useLatestRef/types.d.ts
2
+ /**
3
+ * 最新の値を保持する参照
4
+ */
5
+ type LatestRef<T> = {
6
+ /**
7
+ * 最後にコミットされたレンダリングでの値
8
+ */
9
+ readonly current: T;
10
+ };
11
+ //#endregion
12
+ export { LatestRef };
@@ -0,0 +1,12 @@
1
+ //#region src/hooks/useLatestRef/types.d.ts
2
+ /**
3
+ * 最新の値を保持する参照
4
+ */
5
+ type LatestRef<T> = {
6
+ /**
7
+ * 最後にコミットされたレンダリングでの値
8
+ */
9
+ readonly current: T;
10
+ };
11
+ //#endregion
12
+ export { LatestRef };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,23 @@
1
+ let react = require("react");
2
+
3
+ //#region src/hooks/useLatestRef/useLatestRef.ts
4
+ /**
5
+ * 最新の値を保持する参照を返すhook
6
+ *
7
+ * 返却する参照は常に同じオブジェクトのため、依存配列に含めずに
8
+ * イベントハンドラーやエフェクトの中から最新の値を参照できる。
9
+ * 値はコミット時に更新されるため、レンダリング中には参照しないこと。
10
+ *
11
+ * @param value 値
12
+ * @returns 最新の値を保持する参照
13
+ */
14
+ function useLatestRef(value) {
15
+ const ref = (0, react.useRef)(value);
16
+ (0, react.useInsertionEffect)(() => {
17
+ ref.current = value;
18
+ });
19
+ return ref;
20
+ }
21
+
22
+ //#endregion
23
+ module.exports = useLatestRef;
@@ -0,0 +1,15 @@
1
+ import { LatestRef } from "./types.cjs";
2
+
3
+ //#region src/hooks/useLatestRef/useLatestRef.d.ts
4
+ /**
5
+ * 最新の値を保持する参照を返すhook
6
+ *
7
+ * 返却する参照は常に同じオブジェクトのため、依存配列に含めずに
8
+ * イベントハンドラーやエフェクトの中から最新の値を参照できる。
9
+ * 値はコミット時に更新されるため、レンダリング中には参照しないこと。
10
+ *
11
+ * @param value 値
12
+ * @returns 最新の値を保持する参照
13
+ */
14
+ declare function useLatestRef<T>(value: T): LatestRef<T>;
15
+ export = useLatestRef;
@@ -0,0 +1,16 @@
1
+ import { LatestRef } from "./types.mjs";
2
+
3
+ //#region src/hooks/useLatestRef/useLatestRef.d.ts
4
+ /**
5
+ * 最新の値を保持する参照を返すhook
6
+ *
7
+ * 返却する参照は常に同じオブジェクトのため、依存配列に含めずに
8
+ * イベントハンドラーやエフェクトの中から最新の値を参照できる。
9
+ * 値はコミット時に更新されるため、レンダリング中には参照しないこと。
10
+ *
11
+ * @param value 値
12
+ * @returns 最新の値を保持する参照
13
+ */
14
+ declare function useLatestRef<T>(value: T): LatestRef<T>;
15
+ //#endregion
16
+ export { useLatestRef as default };
@@ -0,0 +1,23 @@
1
+ import { useInsertionEffect, useRef } from "react";
2
+
3
+ //#region src/hooks/useLatestRef/useLatestRef.ts
4
+ /**
5
+ * 最新の値を保持する参照を返すhook
6
+ *
7
+ * 返却する参照は常に同じオブジェクトのため、依存配列に含めずに
8
+ * イベントハンドラーやエフェクトの中から最新の値を参照できる。
9
+ * 値はコミット時に更新されるため、レンダリング中には参照しないこと。
10
+ *
11
+ * @param value 値
12
+ * @returns 最新の値を保持する参照
13
+ */
14
+ function useLatestRef(value) {
15
+ const ref = useRef(value);
16
+ useInsertionEffect(() => {
17
+ ref.current = value;
18
+ });
19
+ return ref;
20
+ }
21
+
22
+ //#endregion
23
+ export { useLatestRef as default };
@@ -0,0 +1,3 @@
1
+ const require_hooks_usePreviousValue_usePreviousValue = require('./usePreviousValue.cjs');
2
+
3
+ module.exports = require_hooks_usePreviousValue_usePreviousValue;
@@ -0,0 +1,3 @@
1
+ import { UsePreviousValueOptions } from "./types.cjs";
2
+ import usePreviousValue from "./usePreviousValue.cjs";
3
+ export { type UsePreviousValueOptions, usePreviousValue as default };
@@ -0,0 +1,3 @@
1
+ import { UsePreviousValueOptions } from "./types.mjs";
2
+ import usePreviousValue from "./usePreviousValue.mjs";
3
+ export { type UsePreviousValueOptions, usePreviousValue as default };
@@ -0,0 +1,3 @@
1
+ import usePreviousValue from "./usePreviousValue.mjs";
2
+
3
+ export { usePreviousValue as default };
File without changes
@@ -0,0 +1,18 @@
1
+ //#region src/hooks/usePreviousValue/types.d.ts
2
+ type UsePreviousValueOptions<T = any> = {
3
+ /**
4
+ * 初期値
5
+ */
6
+ initialValue?: T;
7
+ /**
8
+ * 値の比較関数
9
+ * falseの場合に値を更新する
10
+ * 未指定の場合は`===`で比較
11
+ * @param oldValue
12
+ * @param newValue
13
+ * @returns
14
+ */
15
+ isEqual?: (oldValue: T | undefined, newValue: T) => boolean;
16
+ };
17
+ //#endregion
18
+ export { UsePreviousValueOptions };
@@ -0,0 +1,18 @@
1
+ //#region src/hooks/usePreviousValue/types.d.ts
2
+ type UsePreviousValueOptions<T = any> = {
3
+ /**
4
+ * 初期値
5
+ */
6
+ initialValue?: T;
7
+ /**
8
+ * 値の比較関数
9
+ * falseの場合に値を更新する
10
+ * 未指定の場合は`===`で比較
11
+ * @param oldValue
12
+ * @param newValue
13
+ * @returns
14
+ */
15
+ isEqual?: (oldValue: T | undefined, newValue: T) => boolean;
16
+ };
17
+ //#endregion
18
+ export { UsePreviousValueOptions };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,23 @@
1
+ let react = require("react");
2
+
3
+ //#region src/hooks/usePreviousValue/usePreviousValue.ts
4
+ const defaultIsEqual = (oldValue, newValue) => oldValue === newValue;
5
+ /**
6
+ * 前回の値を返すhook
7
+ * @param value 現在の値
8
+ * @param options オプション
9
+ * @returns 前回の値
10
+ */
11
+ function usePreviousValue(value, options = {}) {
12
+ const isEqual = options.isEqual ?? defaultIsEqual;
13
+ const [currentValue, setCurrentValue] = (0, react.useState)(options.initialValue);
14
+ const [prevValue, setPrevValue] = (0, react.useState)(options.initialValue);
15
+ if (!isEqual(currentValue, value)) {
16
+ setPrevValue(currentValue);
17
+ setCurrentValue(value);
18
+ }
19
+ return prevValue;
20
+ }
21
+
22
+ //#endregion
23
+ module.exports = usePreviousValue;
@@ -0,0 +1,11 @@
1
+ import { UsePreviousValueOptions } from "./types.cjs";
2
+
3
+ //#region src/hooks/usePreviousValue/usePreviousValue.d.ts
4
+ /**
5
+ * 前回の値を返すhook
6
+ * @param value 現在の値
7
+ * @param options オプション
8
+ * @returns 前回の値
9
+ */
10
+ declare function usePreviousValue<T = unknown>(value: T, options?: UsePreviousValueOptions<T>): T | undefined;
11
+ export = usePreviousValue;
@@ -0,0 +1,12 @@
1
+ import { UsePreviousValueOptions } from "./types.mjs";
2
+
3
+ //#region src/hooks/usePreviousValue/usePreviousValue.d.ts
4
+ /**
5
+ * 前回の値を返すhook
6
+ * @param value 現在の値
7
+ * @param options オプション
8
+ * @returns 前回の値
9
+ */
10
+ declare function usePreviousValue<T = unknown>(value: T, options?: UsePreviousValueOptions<T>): T | undefined;
11
+ //#endregion
12
+ export { usePreviousValue as default };
@@ -0,0 +1,23 @@
1
+ import { useState } from "react";
2
+
3
+ //#region src/hooks/usePreviousValue/usePreviousValue.ts
4
+ const defaultIsEqual = (oldValue, newValue) => oldValue === newValue;
5
+ /**
6
+ * 前回の値を返すhook
7
+ * @param value 現在の値
8
+ * @param options オプション
9
+ * @returns 前回の値
10
+ */
11
+ function usePreviousValue(value, options = {}) {
12
+ const isEqual = options.isEqual ?? defaultIsEqual;
13
+ const [currentValue, setCurrentValue] = useState(options.initialValue);
14
+ const [prevValue, setPrevValue] = useState(options.initialValue);
15
+ if (!isEqual(currentValue, value)) {
16
+ setPrevValue(currentValue);
17
+ setCurrentValue(value);
18
+ }
19
+ return prevValue;
20
+ }
21
+
22
+ //#endregion
23
+ export { usePreviousValue as default };
@@ -0,0 +1,3 @@
1
+ const require_hooks_useStableLength_useStableLength = require('./useStableLength.cjs');
2
+
3
+ module.exports = require_hooks_useStableLength_useStableLength;
@@ -0,0 +1,2 @@
1
+ import useStableLength from "./useStableLength.cjs";
2
+ export = useStableLength;
@@ -0,0 +1,2 @@
1
+ import useStableLength from "./useStableLength.mjs";
2
+ export { useStableLength as default };
@@ -0,0 +1,3 @@
1
+ import useStableLength from "./useStableLength.mjs";
2
+
3
+ export { useStableLength as default };
@@ -0,0 +1,16 @@
1
+ let react = require("react");
2
+
3
+ //#region src/hooks/useStableLength/useStableLength.ts
4
+ /**
5
+ * 配列数が常に一定であることを保証する為のフック\
6
+ * 配列数が変わった際にはエラーをスローする
7
+ * @param arr 配列
8
+ * @throws Error
9
+ */
10
+ function useStableLength(arr) {
11
+ const length = (0, react.useRef)(arr.length).current;
12
+ if (length !== arr.length) throw new Error(`useStableLength: Array length must remain stable across renders (${length} → ${arr.length})`);
13
+ }
14
+
15
+ //#endregion
16
+ module.exports = useStableLength;
@@ -0,0 +1,9 @@
1
+ //#region src/hooks/useStableLength/useStableLength.d.ts
2
+ /**
3
+ * 配列数が常に一定であることを保証する為のフック\
4
+ * 配列数が変わった際にはエラーをスローする
5
+ * @param arr 配列
6
+ * @throws Error
7
+ */
8
+ declare function useStableLength(arr: unknown[]): void;
9
+ export = useStableLength;
@@ -0,0 +1,10 @@
1
+ //#region src/hooks/useStableLength/useStableLength.d.ts
2
+ /**
3
+ * 配列数が常に一定であることを保証する為のフック\
4
+ * 配列数が変わった際にはエラーをスローする
5
+ * @param arr 配列
6
+ * @throws Error
7
+ */
8
+ declare function useStableLength(arr: unknown[]): void;
9
+ //#endregion
10
+ export { useStableLength as default };
@@ -0,0 +1,16 @@
1
+ import { useRef } from "react";
2
+
3
+ //#region src/hooks/useStableLength/useStableLength.ts
4
+ /**
5
+ * 配列数が常に一定であることを保証する為のフック\
6
+ * 配列数が変わった際にはエラーをスローする
7
+ * @param arr 配列
8
+ * @throws Error
9
+ */
10
+ function useStableLength(arr) {
11
+ const length = useRef(arr.length).current;
12
+ if (length !== arr.length) throw new Error(`useStableLength: Array length must remain stable across renders (${length} → ${arr.length})`);
13
+ }
14
+
15
+ //#endregion
16
+ export { useStableLength as default };
package/index.cjs ADDED
@@ -0,0 +1,16 @@
1
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
2
+ const require_hooks_index = require('./hooks/index.cjs');
3
+ const require_utils_index = require('./utils/index.cjs');
4
+
5
+ Object.defineProperty(exports, 'hooks', {
6
+ enumerable: true,
7
+ get: function () {
8
+ return require_hooks_index.hooks_exports;
9
+ }
10
+ });
11
+ Object.defineProperty(exports, 'utils', {
12
+ enumerable: true,
13
+ get: function () {
14
+ return require_utils_index.utils_exports;
15
+ }
16
+ });
package/index.d.cts ADDED
@@ -0,0 +1,4 @@
1
+ import { index_d_exports } from "./hooks/index.cjs";
2
+ import { CSSPropertiesWithVars } from "./types.cjs";
3
+ import { index_d_exports as index_d_exports$1 } from "./utils/index.cjs";
4
+ export { type CSSPropertiesWithVars, index_d_exports as hooks, index_d_exports$1 as utils };
package/index.d.mts ADDED
@@ -0,0 +1,4 @@
1
+ import { index_d_exports } from "./hooks/index.mjs";
2
+ import { CSSPropertiesWithVars } from "./types.mjs";
3
+ import { index_d_exports as index_d_exports$1 } from "./utils/index.mjs";
4
+ export { type CSSPropertiesWithVars, index_d_exports as hooks, index_d_exports$1 as utils };
package/index.mjs ADDED
@@ -0,0 +1,4 @@
1
+ import { hooks_exports } from "./hooks/index.mjs";
2
+ import { utils_exports } from "./utils/index.mjs";
3
+
4
+ export { hooks_exports as hooks, utils_exports as utils };