@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
package/package.json ADDED
@@ -0,0 +1,91 @@
1
+ {
2
+ "name": "@fringeworks/react-utils",
3
+ "version": "0.8.0",
4
+ "keywords": [
5
+ "react"
6
+ ],
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/fringeworks-js/react-utils.git"
10
+ },
11
+ "license": "MIT",
12
+ "author": "Mitsuhiro Seino",
13
+ "exports": {
14
+ ".": {
15
+ "import": {
16
+ "types": "./index.d.mts",
17
+ "default": "./index.mjs"
18
+ },
19
+ "require": {
20
+ "types": "./index.d.cts",
21
+ "default": "./index.cjs"
22
+ }
23
+ },
24
+ "./package.json": "./package.json",
25
+ "./constants": {
26
+ "import": {
27
+ "types": "./constants.d.mts",
28
+ "default": "./constants.mjs"
29
+ },
30
+ "require": {
31
+ "types": "./constants.d.cts",
32
+ "default": "./constants.cjs"
33
+ }
34
+ },
35
+ "./*/constants": {
36
+ "import": {
37
+ "types": "./*/constants.d.mts",
38
+ "default": "./*/constants.mjs"
39
+ },
40
+ "require": {
41
+ "types": "./*/constants.d.cts",
42
+ "default": "./*/constants.cjs"
43
+ }
44
+ },
45
+ "./types": {
46
+ "import": {
47
+ "types": "./types.d.mts",
48
+ "default": "./types.mjs"
49
+ },
50
+ "require": {
51
+ "types": "./types.d.cts",
52
+ "default": "./types.cjs"
53
+ }
54
+ },
55
+ "./*/types": {
56
+ "import": {
57
+ "types": "./*/types.d.mts",
58
+ "default": "./*/types.mjs"
59
+ },
60
+ "require": {
61
+ "types": "./*/types.d.cts",
62
+ "default": "./*/types.cjs"
63
+ }
64
+ },
65
+ "./*": {
66
+ "import": {
67
+ "types": "./*/index.d.mts",
68
+ "default": "./*/index.mjs"
69
+ },
70
+ "require": {
71
+ "types": "./*/index.d.cts",
72
+ "default": "./*/index.cjs"
73
+ }
74
+ }
75
+ },
76
+ "main": "./index.cjs",
77
+ "module": "./index.mjs",
78
+ "types": "./index.d.cts",
79
+ "dependencies": {
80
+ "@fringeworks/utils": "^0.8.0"
81
+ },
82
+ "peerDependencies": {
83
+ "react": "^18.0.0 || ^19.0.0",
84
+ "react-dom": "^18.0.0 || ^19.0.0"
85
+ },
86
+ "peerDependenciesMeta": {
87
+ "react-dom": {
88
+ "optional": true
89
+ }
90
+ }
91
+ }
package/types.cjs ADDED
File without changes
package/types.d.cts ADDED
@@ -0,0 +1,11 @@
1
+ import { CSSProperties } from "react";
2
+
3
+ //#region src/types.d.ts
4
+ /**
5
+ * CSS変数を許容するCSSProperties
6
+ */
7
+ type CSSPropertiesWithVars = CSSProperties & {
8
+ [key: `--${string}`]: string | number | undefined;
9
+ };
10
+ //#endregion
11
+ export { CSSPropertiesWithVars };
package/types.d.mts ADDED
@@ -0,0 +1,11 @@
1
+ import { CSSProperties } from "react";
2
+
3
+ //#region src/types.d.ts
4
+ /**
5
+ * CSS変数を許容するCSSProperties
6
+ */
7
+ type CSSPropertiesWithVars = CSSProperties & {
8
+ [key: `--${string}`]: string | number | undefined;
9
+ };
10
+ //#endregion
11
+ export { CSSPropertiesWithVars };
package/types.mjs ADDED
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,41 @@
1
+
2
+ //#region src/utils/applyDefaultProps/applyDefaultProps.ts
3
+ /**
4
+ * props のプロパティが undefined または null で、
5
+ * かつデフォルト値が undefined 以外の場合に、デフォルト値を反映した新しいオブジェクトを返す。
6
+ * 元の props は変更しない。
7
+ *
8
+ * defaults は複数渡せる。その場合は上記のルールを左の defaults から順に適用するため、
9
+ * 先の引数ほど優先される。つまり次の2つは同じ結果になる。
10
+ *
11
+ * applyDefaultProps(props, d1, d2)
12
+ * applyDefaultProps(applyDefaultProps(props, d1), d2)
13
+ *
14
+ * キーごとに見ると `props[key] ?? d1[key] ?? d2[key] ?? ...` と同様に振る舞う。
15
+ * defaults の null は反映されても反映先が null のままなので、後続の defaults に
16
+ * null / undefined 以外の値があればそちらで埋められる。
17
+ *
18
+ * defaults の要素として null / undefined / false を渡した場合は、その要素はスキップされる
19
+ * (渡さなかったのと同じ扱いになる)。条件付きのデフォルト値を次のように書ける。
20
+ *
21
+ * applyDefaultProps(props, isCompact && compactDefaults, baseDefaults)
22
+ *
23
+ * @param props コンポーネントに渡された props
24
+ * @param defaults props の一部のプロパティにデフォルト値を設定したオブジェクト
25
+ * (複数可、先の引数ほど優先。null / undefined / false はスキップ)
26
+ */
27
+ function applyDefaultProps(props, ...defaults) {
28
+ const result = { ...props };
29
+ for (const values of defaults) {
30
+ if (!values) continue;
31
+ for (const key of Object.keys(values)) {
32
+ const current = result[key];
33
+ const defaultValue = values[key];
34
+ if ((current === void 0 || current === null) && defaultValue !== void 0) result[key] = defaultValue;
35
+ }
36
+ }
37
+ return result;
38
+ }
39
+
40
+ //#endregion
41
+ module.exports = applyDefaultProps;
@@ -0,0 +1,33 @@
1
+ import { AppliedProps, SkippedDefaults } from "./types.cjs";
2
+
3
+ //#region src/utils/applyDefaultProps/applyDefaultProps.d.ts
4
+ /** props に存在しないキーを含む defaults を型エラーにする */
5
+ type NoExtraKeys<P, Ds extends readonly unknown[]> = { [I in keyof Ds]: CheckKeys<P, Ds[I]> };
6
+ /** 要素がオブジェクトの場合のみキーを検査する(ユニオンの各要素ごとに分配) */
7
+ type CheckKeys<P, T> = T extends SkippedDefaults ? T : T & { [K in Exclude<keyof T, keyof P>]: never };
8
+ /**
9
+ * props のプロパティが undefined または null で、
10
+ * かつデフォルト値が undefined 以外の場合に、デフォルト値を反映した新しいオブジェクトを返す。
11
+ * 元の props は変更しない。
12
+ *
13
+ * defaults は複数渡せる。その場合は上記のルールを左の defaults から順に適用するため、
14
+ * 先の引数ほど優先される。つまり次の2つは同じ結果になる。
15
+ *
16
+ * applyDefaultProps(props, d1, d2)
17
+ * applyDefaultProps(applyDefaultProps(props, d1), d2)
18
+ *
19
+ * キーごとに見ると `props[key] ?? d1[key] ?? d2[key] ?? ...` と同様に振る舞う。
20
+ * defaults の null は反映されても反映先が null のままなので、後続の defaults に
21
+ * null / undefined 以外の値があればそちらで埋められる。
22
+ *
23
+ * defaults の要素として null / undefined / false を渡した場合は、その要素はスキップされる
24
+ * (渡さなかったのと同じ扱いになる)。条件付きのデフォルト値を次のように書ける。
25
+ *
26
+ * applyDefaultProps(props, isCompact && compactDefaults, baseDefaults)
27
+ *
28
+ * @param props コンポーネントに渡された props
29
+ * @param defaults props の一部のプロパティにデフォルト値を設定したオブジェクト
30
+ * (複数可、先の引数ほど優先。null / undefined / false はスキップ)
31
+ */
32
+ declare function applyDefaultProps<P extends object, const Ds extends readonly (Partial<P> | SkippedDefaults)[]>(props: P, ...defaults: Ds & NoExtraKeys<P, Ds>): AppliedProps<P, Ds>;
33
+ export = applyDefaultProps;
@@ -0,0 +1,34 @@
1
+ import { AppliedProps, SkippedDefaults } from "./types.mjs";
2
+
3
+ //#region src/utils/applyDefaultProps/applyDefaultProps.d.ts
4
+ /** props に存在しないキーを含む defaults を型エラーにする */
5
+ type NoExtraKeys<P, Ds extends readonly unknown[]> = { [I in keyof Ds]: CheckKeys<P, Ds[I]> };
6
+ /** 要素がオブジェクトの場合のみキーを検査する(ユニオンの各要素ごとに分配) */
7
+ type CheckKeys<P, T> = T extends SkippedDefaults ? T : T & { [K in Exclude<keyof T, keyof P>]: never };
8
+ /**
9
+ * props のプロパティが undefined または null で、
10
+ * かつデフォルト値が undefined 以外の場合に、デフォルト値を反映した新しいオブジェクトを返す。
11
+ * 元の props は変更しない。
12
+ *
13
+ * defaults は複数渡せる。その場合は上記のルールを左の defaults から順に適用するため、
14
+ * 先の引数ほど優先される。つまり次の2つは同じ結果になる。
15
+ *
16
+ * applyDefaultProps(props, d1, d2)
17
+ * applyDefaultProps(applyDefaultProps(props, d1), d2)
18
+ *
19
+ * キーごとに見ると `props[key] ?? d1[key] ?? d2[key] ?? ...` と同様に振る舞う。
20
+ * defaults の null は反映されても反映先が null のままなので、後続の defaults に
21
+ * null / undefined 以外の値があればそちらで埋められる。
22
+ *
23
+ * defaults の要素として null / undefined / false を渡した場合は、その要素はスキップされる
24
+ * (渡さなかったのと同じ扱いになる)。条件付きのデフォルト値を次のように書ける。
25
+ *
26
+ * applyDefaultProps(props, isCompact && compactDefaults, baseDefaults)
27
+ *
28
+ * @param props コンポーネントに渡された props
29
+ * @param defaults props の一部のプロパティにデフォルト値を設定したオブジェクト
30
+ * (複数可、先の引数ほど優先。null / undefined / false はスキップ)
31
+ */
32
+ declare function applyDefaultProps<P extends object, const Ds extends readonly (Partial<P> | SkippedDefaults)[]>(props: P, ...defaults: Ds & NoExtraKeys<P, Ds>): AppliedProps<P, Ds>;
33
+ //#endregion
34
+ export { applyDefaultProps as default };
@@ -0,0 +1,40 @@
1
+ //#region src/utils/applyDefaultProps/applyDefaultProps.ts
2
+ /**
3
+ * props のプロパティが undefined または null で、
4
+ * かつデフォルト値が undefined 以外の場合に、デフォルト値を反映した新しいオブジェクトを返す。
5
+ * 元の props は変更しない。
6
+ *
7
+ * defaults は複数渡せる。その場合は上記のルールを左の defaults から順に適用するため、
8
+ * 先の引数ほど優先される。つまり次の2つは同じ結果になる。
9
+ *
10
+ * applyDefaultProps(props, d1, d2)
11
+ * applyDefaultProps(applyDefaultProps(props, d1), d2)
12
+ *
13
+ * キーごとに見ると `props[key] ?? d1[key] ?? d2[key] ?? ...` と同様に振る舞う。
14
+ * defaults の null は反映されても反映先が null のままなので、後続の defaults に
15
+ * null / undefined 以外の値があればそちらで埋められる。
16
+ *
17
+ * defaults の要素として null / undefined / false を渡した場合は、その要素はスキップされる
18
+ * (渡さなかったのと同じ扱いになる)。条件付きのデフォルト値を次のように書ける。
19
+ *
20
+ * applyDefaultProps(props, isCompact && compactDefaults, baseDefaults)
21
+ *
22
+ * @param props コンポーネントに渡された props
23
+ * @param defaults props の一部のプロパティにデフォルト値を設定したオブジェクト
24
+ * (複数可、先の引数ほど優先。null / undefined / false はスキップ)
25
+ */
26
+ function applyDefaultProps(props, ...defaults) {
27
+ const result = { ...props };
28
+ for (const values of defaults) {
29
+ if (!values) continue;
30
+ for (const key of Object.keys(values)) {
31
+ const current = result[key];
32
+ const defaultValue = values[key];
33
+ if ((current === void 0 || current === null) && defaultValue !== void 0) result[key] = defaultValue;
34
+ }
35
+ }
36
+ return result;
37
+ }
38
+
39
+ //#endregion
40
+ export { applyDefaultProps as default };
@@ -0,0 +1,3 @@
1
+ const require_utils_applyDefaultProps_applyDefaultProps = require('./applyDefaultProps.cjs');
2
+
3
+ module.exports = require_utils_applyDefaultProps_applyDefaultProps;
@@ -0,0 +1,3 @@
1
+ import { AppliedProps, SkippedDefaults } from "./types.cjs";
2
+ import applyDefaultProps from "./applyDefaultProps.cjs";
3
+ export { type AppliedProps, type SkippedDefaults, applyDefaultProps as default };
@@ -0,0 +1,3 @@
1
+ import { AppliedProps, SkippedDefaults } from "./types.mjs";
2
+ import applyDefaultProps from "./applyDefaultProps.mjs";
3
+ export { type AppliedProps, type SkippedDefaults, applyDefaultProps as default };
@@ -0,0 +1,3 @@
1
+ import applyDefaultProps from "./applyDefaultProps.mjs";
2
+
3
+ export { applyDefaultProps as default };
File without changes
@@ -0,0 +1,27 @@
1
+ //#region src/utils/applyDefaultProps/types.d.ts
2
+ /**
3
+ * 交差型を1つのオブジェクト型に展開して、エディタ上の型表示を見やすくする
4
+ */
5
+ type Simplify<T> = { [K in keyof T]: T[K] } & {};
6
+ /** defaults として渡されてもスキップされる値 */
7
+ type SkippedDefaults = null | undefined | false;
8
+ /** スキップされる値を除いた defaults の要素の和集合 */
9
+ type DefaultsOf<Ds extends readonly unknown[]> = Exclude<Ds[number], SkippedDefaults>;
10
+ /** defaults 群のいずれかに含まれるキーの和集合 */
11
+ type KeysOf<Ds extends readonly unknown[]> = DefaultsOf<Ds> extends infer U ? U extends unknown ? keyof U : never : never;
12
+ /**
13
+ * キー K について、undefined にならない値を確実に持つ defaults があるか。
14
+ * スキップされ得る要素(`cond && defaults` など)は確実とはみなさない。
15
+ */
16
+ type IsDefinitelyDefined<Ds extends readonly unknown[], K> = Ds extends readonly [infer Head, ...infer Rest] ? [Head] extends [object] ? K extends keyof Head ? undefined extends Head[K] ? IsDefinitelyDefined<Rest, K> : true : IsDefinitelyDefined<Rest, K> : IsDefinitelyDefined<Rest, K> : false;
17
+ /** キー K について、defaults 群から採用され得る値の型(undefined を除く) */
18
+ type DefaultValueOf<Ds extends readonly unknown[], K> = DefaultsOf<Ds> extends infer U ? U extends unknown ? K extends keyof U ? Exclude<U[K], undefined> : never : never : never;
19
+ /**
20
+ * マージ後の props の型
21
+ * - どの defaults にも含まれないキー: props の型をそのまま維持
22
+ * - いずれかの defaults が確実に値を持つキー: null / undefined が取り除かれ、デフォルト値の型が加わる
23
+ * - defaults の値が undefined になり得るキー: props の型にデフォルト値の型が加わる
24
+ */
25
+ type AppliedProps<P, Ds extends readonly unknown[]> = Simplify<Omit<P, KeysOf<Ds>> & { [K in KeysOf<Ds> & keyof P]: IsDefinitelyDefined<Ds, K> extends true ? NonNullable<P[K]> | DefaultValueOf<Ds, K> : P[K] | DefaultValueOf<Ds, K> }>;
26
+ //#endregion
27
+ export { AppliedProps, SkippedDefaults };
@@ -0,0 +1,27 @@
1
+ //#region src/utils/applyDefaultProps/types.d.ts
2
+ /**
3
+ * 交差型を1つのオブジェクト型に展開して、エディタ上の型表示を見やすくする
4
+ */
5
+ type Simplify<T> = { [K in keyof T]: T[K] } & {};
6
+ /** defaults として渡されてもスキップされる値 */
7
+ type SkippedDefaults = null | undefined | false;
8
+ /** スキップされる値を除いた defaults の要素の和集合 */
9
+ type DefaultsOf<Ds extends readonly unknown[]> = Exclude<Ds[number], SkippedDefaults>;
10
+ /** defaults 群のいずれかに含まれるキーの和集合 */
11
+ type KeysOf<Ds extends readonly unknown[]> = DefaultsOf<Ds> extends infer U ? U extends unknown ? keyof U : never : never;
12
+ /**
13
+ * キー K について、undefined にならない値を確実に持つ defaults があるか。
14
+ * スキップされ得る要素(`cond && defaults` など)は確実とはみなさない。
15
+ */
16
+ type IsDefinitelyDefined<Ds extends readonly unknown[], K> = Ds extends readonly [infer Head, ...infer Rest] ? [Head] extends [object] ? K extends keyof Head ? undefined extends Head[K] ? IsDefinitelyDefined<Rest, K> : true : IsDefinitelyDefined<Rest, K> : IsDefinitelyDefined<Rest, K> : false;
17
+ /** キー K について、defaults 群から採用され得る値の型(undefined を除く) */
18
+ type DefaultValueOf<Ds extends readonly unknown[], K> = DefaultsOf<Ds> extends infer U ? U extends unknown ? K extends keyof U ? Exclude<U[K], undefined> : never : never : never;
19
+ /**
20
+ * マージ後の props の型
21
+ * - どの defaults にも含まれないキー: props の型をそのまま維持
22
+ * - いずれかの defaults が確実に値を持つキー: null / undefined が取り除かれ、デフォルト値の型が加わる
23
+ * - defaults の値が undefined になり得るキー: props の型にデフォルト値の型が加わる
24
+ */
25
+ type AppliedProps<P, Ds extends readonly unknown[]> = Simplify<Omit<P, KeysOf<Ds>> & { [K in KeysOf<Ds> & keyof P]: IsDefinitelyDefined<Ds, K> extends true ? NonNullable<P[K]> | DefaultValueOf<Ds, K> : P[K] | DefaultValueOf<Ds, K> }>;
26
+ //#endregion
27
+ export { AppliedProps, SkippedDefaults };
@@ -0,0 +1 @@
1
+ export { };
@@ -0,0 +1,28 @@
1
+ let react = require("react");
2
+
3
+ //#region src/utils/ensureComponent/ensureComponent.ts
4
+ const cache = /* @__PURE__ */ new Map();
5
+ /**
6
+ * 組み込みタグの場合はコンポーネントに変換して返す
7
+ * @param component 組み込みタグ or コンポーネント
8
+ * @returns コンポーネント
9
+ */
10
+ function ensureComponent(component) {
11
+ if (typeof component === "string") {
12
+ const cached = cache.get(component);
13
+ if (cached) return cached;
14
+ const Comp = (0, react.forwardRef)((props, ref) => {
15
+ return (0, react.createElement)(component, {
16
+ ...props,
17
+ ref
18
+ });
19
+ });
20
+ Comp.displayName = `ensureComponent(${component})`;
21
+ cache.set(component, Comp);
22
+ return Comp;
23
+ }
24
+ return component;
25
+ }
26
+
27
+ //#endregion
28
+ module.exports = ensureComponent;
@@ -0,0 +1,10 @@
1
+ import { ComponentPropsWithRef, ComponentType, ElementType } from "react";
2
+
3
+ //#region src/utils/ensureComponent/ensureComponent.d.ts
4
+ /**
5
+ * 組み込みタグの場合はコンポーネントに変換して返す
6
+ * @param component 組み込みタグ or コンポーネント
7
+ * @returns コンポーネント
8
+ */
9
+ declare function ensureComponent<C extends ElementType>(component: C): ComponentType<ComponentPropsWithRef<C>>;
10
+ export = ensureComponent;
@@ -0,0 +1,11 @@
1
+ import { ComponentPropsWithRef, ComponentType, ElementType } from "react";
2
+
3
+ //#region src/utils/ensureComponent/ensureComponent.d.ts
4
+ /**
5
+ * 組み込みタグの場合はコンポーネントに変換して返す
6
+ * @param component 組み込みタグ or コンポーネント
7
+ * @returns コンポーネント
8
+ */
9
+ declare function ensureComponent<C extends ElementType>(component: C): ComponentType<ComponentPropsWithRef<C>>;
10
+ //#endregion
11
+ export { ensureComponent as default };
@@ -0,0 +1,28 @@
1
+ import { createElement, forwardRef } from "react";
2
+
3
+ //#region src/utils/ensureComponent/ensureComponent.ts
4
+ const cache = /* @__PURE__ */ new Map();
5
+ /**
6
+ * 組み込みタグの場合はコンポーネントに変換して返す
7
+ * @param component 組み込みタグ or コンポーネント
8
+ * @returns コンポーネント
9
+ */
10
+ function ensureComponent(component) {
11
+ if (typeof component === "string") {
12
+ const cached = cache.get(component);
13
+ if (cached) return cached;
14
+ const Comp = forwardRef((props, ref) => {
15
+ return createElement(component, {
16
+ ...props,
17
+ ref
18
+ });
19
+ });
20
+ Comp.displayName = `ensureComponent(${component})`;
21
+ cache.set(component, Comp);
22
+ return Comp;
23
+ }
24
+ return component;
25
+ }
26
+
27
+ //#endregion
28
+ export { ensureComponent as default };
@@ -0,0 +1,3 @@
1
+ const require_utils_ensureComponent_ensureComponent = require('./ensureComponent.cjs');
2
+
3
+ module.exports = require_utils_ensureComponent_ensureComponent;
@@ -0,0 +1,2 @@
1
+ import ensureComponent from "./ensureComponent.cjs";
2
+ export = ensureComponent;
@@ -0,0 +1,2 @@
1
+ import ensureComponent from "./ensureComponent.mjs";
2
+ export { ensureComponent as default };
@@ -0,0 +1,3 @@
1
+ import ensureComponent from "./ensureComponent.mjs";
2
+
3
+ export { ensureComponent as default };
@@ -0,0 +1,30 @@
1
+ let react = require("react");
2
+
3
+ //#region src/utils/extendElement/extendElement.ts
4
+ /**
5
+ * classNameとstyleはマージ、それ以外のプロパティはpropsの値で上書きしてcloneElementを実行する
6
+ * @param element エレメント
7
+ * @param overrideProps 新しいエレメントのプロパティをオーバーライドするプロパティ
8
+ * @param children 子要素
9
+ * @returns
10
+ */
11
+ function extendElement(element, overrideProps, ...children) {
12
+ const { className: elClassName, style: elStyle, ...elRest } = element.props;
13
+ const { className: orClassName, style: orStyle, ...orRest } = overrideProps || {};
14
+ let className = elClassName;
15
+ if (orClassName != null) className = className ? `${className} ${orClassName}` : orClassName;
16
+ const style = { ...elStyle };
17
+ if (orStyle) {
18
+ for (const key in orStyle) if (orStyle[key] !== void 0) style[key] = orStyle[key];
19
+ }
20
+ const props = {
21
+ className,
22
+ style,
23
+ ...elRest
24
+ };
25
+ for (const key in orRest) if (orRest[key] !== void 0) props[key] = orRest[key];
26
+ return (0, react.cloneElement)(element, props, ...children);
27
+ }
28
+
29
+ //#endregion
30
+ module.exports = extendElement;
@@ -0,0 +1,12 @@
1
+ import { HTMLAttributes, ReactElement, ReactNode } from "react";
2
+
3
+ //#region src/utils/extendElement/extendElement.d.ts
4
+ /**
5
+ * classNameとstyleはマージ、それ以外のプロパティはpropsの値で上書きしてcloneElementを実行する
6
+ * @param element エレメント
7
+ * @param overrideProps 新しいエレメントのプロパティをオーバーライドするプロパティ
8
+ * @param children 子要素
9
+ * @returns
10
+ */
11
+ declare function extendElement<P extends HTMLAttributes<T>, T extends HTMLElement>(element: ReactElement<P>, overrideProps?: P, ...children: ReactNode[]): ReactElement<P>;
12
+ export = extendElement;
@@ -0,0 +1,13 @@
1
+ import { HTMLAttributes, ReactElement, ReactNode } from "react";
2
+
3
+ //#region src/utils/extendElement/extendElement.d.ts
4
+ /**
5
+ * classNameとstyleはマージ、それ以外のプロパティはpropsの値で上書きしてcloneElementを実行する
6
+ * @param element エレメント
7
+ * @param overrideProps 新しいエレメントのプロパティをオーバーライドするプロパティ
8
+ * @param children 子要素
9
+ * @returns
10
+ */
11
+ declare function extendElement<P extends HTMLAttributes<T>, T extends HTMLElement>(element: ReactElement<P>, overrideProps?: P, ...children: ReactNode[]): ReactElement<P>;
12
+ //#endregion
13
+ export { extendElement as default };
@@ -0,0 +1,30 @@
1
+ import { cloneElement } from "react";
2
+
3
+ //#region src/utils/extendElement/extendElement.ts
4
+ /**
5
+ * classNameとstyleはマージ、それ以外のプロパティはpropsの値で上書きしてcloneElementを実行する
6
+ * @param element エレメント
7
+ * @param overrideProps 新しいエレメントのプロパティをオーバーライドするプロパティ
8
+ * @param children 子要素
9
+ * @returns
10
+ */
11
+ function extendElement(element, overrideProps, ...children) {
12
+ const { className: elClassName, style: elStyle, ...elRest } = element.props;
13
+ const { className: orClassName, style: orStyle, ...orRest } = overrideProps || {};
14
+ let className = elClassName;
15
+ if (orClassName != null) className = className ? `${className} ${orClassName}` : orClassName;
16
+ const style = { ...elStyle };
17
+ if (orStyle) {
18
+ for (const key in orStyle) if (orStyle[key] !== void 0) style[key] = orStyle[key];
19
+ }
20
+ const props = {
21
+ className,
22
+ style,
23
+ ...elRest
24
+ };
25
+ for (const key in orRest) if (orRest[key] !== void 0) props[key] = orRest[key];
26
+ return cloneElement(element, props, ...children);
27
+ }
28
+
29
+ //#endregion
30
+ export { extendElement as default };
@@ -0,0 +1,3 @@
1
+ const require_utils_extendElement_extendElement = require('./extendElement.cjs');
2
+
3
+ module.exports = require_utils_extendElement_extendElement;
@@ -0,0 +1,2 @@
1
+ import extendElement from "./extendElement.cjs";
2
+ export = extendElement;
@@ -0,0 +1,2 @@
1
+ import extendElement from "./extendElement.mjs";
2
+ export { extendElement as default };
@@ -0,0 +1,3 @@
1
+ import extendElement from "./extendElement.mjs";
2
+
3
+ export { extendElement as default };
@@ -0,0 +1,14 @@
1
+ const require__helpers__traverseContent = require('../../_helpers/_traverseContent.cjs');
2
+
3
+ //#region src/utils/forEachContent/forEachContent.ts
4
+ /**
5
+ * React.Fragmentを透過し、children内のReactElement、string、numberを処理する
6
+ * @param children エレメントの子要素
7
+ * @param callback コールバック
8
+ */
9
+ function forEachContent(children, callback) {
10
+ require__helpers__traverseContent(children, callback);
11
+ }
12
+
13
+ //#endregion
14
+ module.exports = forEachContent;
@@ -0,0 +1,10 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+
3
+ //#region src/utils/forEachContent/forEachContent.d.ts
4
+ /**
5
+ * React.Fragmentを透過し、children内のReactElement、string、numberを処理する
6
+ * @param children エレメントの子要素
7
+ * @param callback コールバック
8
+ */
9
+ declare function forEachContent(children: ReactNode, callback: (node: ReactElement | string | number, index: number) => void): void;
10
+ export = forEachContent;
@@ -0,0 +1,11 @@
1
+ import { ReactElement, ReactNode } from "react";
2
+
3
+ //#region src/utils/forEachContent/forEachContent.d.ts
4
+ /**
5
+ * React.Fragmentを透過し、children内のReactElement、string、numberを処理する
6
+ * @param children エレメントの子要素
7
+ * @param callback コールバック
8
+ */
9
+ declare function forEachContent(children: ReactNode, callback: (node: ReactElement | string | number, index: number) => void): void;
10
+ //#endregion
11
+ export { forEachContent as default };
@@ -0,0 +1,14 @@
1
+ import _traverseContent from "../../_helpers/_traverseContent.mjs";
2
+
3
+ //#region src/utils/forEachContent/forEachContent.ts
4
+ /**
5
+ * React.Fragmentを透過し、children内のReactElement、string、numberを処理する
6
+ * @param children エレメントの子要素
7
+ * @param callback コールバック
8
+ */
9
+ function forEachContent(children, callback) {
10
+ _traverseContent(children, callback);
11
+ }
12
+
13
+ //#endregion
14
+ export { forEachContent as default };
@@ -0,0 +1,3 @@
1
+ const require_utils_forEachContent_forEachContent = require('./forEachContent.cjs');
2
+
3
+ module.exports = require_utils_forEachContent_forEachContent;
@@ -0,0 +1,2 @@
1
+ import forEachContent from "./forEachContent.cjs";
2
+ export = forEachContent;
@@ -0,0 +1,2 @@
1
+ import forEachContent from "./forEachContent.mjs";
2
+ export { forEachContent as default };
@@ -0,0 +1,3 @@
1
+ import forEachContent from "./forEachContent.mjs";
2
+
3
+ export { forEachContent as default };