react-native-system-ui 1.0.2 → 1.0.4

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 (498) hide show
  1. package/README.md +42 -22
  2. package/dist/cjs/components/action-sheet/ActionSheet.js +1 -301
  3. package/dist/cjs/components/action-sheet/index.js +1 -16
  4. package/dist/cjs/components/action-sheet/tokens.js +1 -133
  5. package/dist/cjs/components/area/Area.js +1 -127
  6. package/dist/cjs/components/area/index.js +1 -9
  7. package/dist/cjs/components/area/tokens.js +1 -14
  8. package/dist/cjs/components/avatar/Avatar.js +1 -125
  9. package/dist/cjs/components/avatar/index.js +1 -18
  10. package/dist/cjs/components/avatar/tokens.js +1 -56
  11. package/dist/cjs/components/badge/Badge.js +1 -166
  12. package/dist/cjs/components/badge/index.js +1 -8
  13. package/dist/cjs/components/badge/tokens.js +1 -81
  14. package/dist/cjs/components/button/Button.js +1 -203
  15. package/dist/cjs/components/button/ButtonContext.js +1 -12
  16. package/dist/cjs/components/button/ButtonGroup.js +1 -65
  17. package/dist/cjs/components/button/index.js +1 -12
  18. package/dist/cjs/components/button/tokens.js +1 -176
  19. package/dist/cjs/components/calendar/Calendar.js +1 -452
  20. package/dist/cjs/components/calendar/index.js +1 -9
  21. package/dist/cjs/components/calendar/tokens.js +1 -129
  22. package/dist/cjs/components/cascader/Cascader.js +1 -482
  23. package/dist/cjs/components/cascader/index.js +1 -15
  24. package/dist/cjs/components/cascader/tokens.js +1 -138
  25. package/dist/cjs/components/cascader/useCascaderExtend.js +1 -39
  26. package/dist/cjs/components/cell/Cell.js +1 -181
  27. package/dist/cjs/components/cell/CellContext.js +1 -19
  28. package/dist/cjs/components/cell/CellGroup.js +1 -100
  29. package/dist/cjs/components/cell/index.js +1 -19
  30. package/dist/cjs/components/cell/tokens.js +1 -173
  31. package/dist/cjs/components/checkbox/Checkbox.js +1 -251
  32. package/dist/cjs/components/checkbox/CheckboxContext.js +1 -12
  33. package/dist/cjs/components/checkbox/CheckboxGroup.js +1 -148
  34. package/dist/cjs/components/checkbox/index.js +1 -16
  35. package/dist/cjs/components/checkbox/tokens.js +1 -97
  36. package/dist/cjs/components/circle/Circle.js +1 -212
  37. package/dist/cjs/components/circle/index.js +1 -9
  38. package/dist/cjs/components/circle/tokens.js +1 -55
  39. package/dist/cjs/components/collapse/Collapse.js +1 -311
  40. package/dist/cjs/components/collapse/index.js +1 -8
  41. package/dist/cjs/components/collapse/tokens.js +1 -81
  42. package/dist/cjs/components/config-provider/ConfigProvider.js +1 -44
  43. package/dist/cjs/components/config-provider/DirectionContext.js +1 -15
  44. package/dist/cjs/components/config-provider/LocaleContext.js +1 -16
  45. package/dist/cjs/components/config-provider/index.js +1 -40
  46. package/dist/cjs/components/config-provider/locale/en-US.js +1 -112
  47. package/dist/cjs/components/config-provider/locale/zh-CN.js +1 -112
  48. package/dist/cjs/components/config-provider/tokens.js +1 -11
  49. package/dist/cjs/components/config-provider/useDirection.js +1 -16
  50. package/dist/cjs/components/config-provider/useLocale.js +1 -16
  51. package/dist/cjs/components/count-down/CountDown.js +1 -88
  52. package/dist/cjs/components/count-down/index.js +1 -15
  53. package/dist/cjs/components/count-down/tokens.js +1 -34
  54. package/dist/cjs/components/datetime-picker/DatetimePicker.js +1 -319
  55. package/dist/cjs/components/datetime-picker/index.js +1 -9
  56. package/dist/cjs/components/datetime-picker/tokens.js +1 -22
  57. package/dist/cjs/components/dialog/Dialog.js +1 -433
  58. package/dist/cjs/components/dialog/imperative.js +1 -199
  59. package/dist/cjs/components/dialog/index.js +1 -23
  60. package/dist/cjs/components/dialog/tokens.js +1 -64
  61. package/dist/cjs/components/divider/Divider.js +1 -126
  62. package/dist/cjs/components/divider/index.js +1 -8
  63. package/dist/cjs/components/divider/tokens.js +1 -62
  64. package/dist/cjs/components/empty/Empty.js +1 -125
  65. package/dist/cjs/components/empty/index.js +1 -8
  66. package/dist/cjs/components/empty/tokens.js +1 -55
  67. package/dist/cjs/components/error-boundary/ErrorBoundary.js +1 -74
  68. package/dist/cjs/components/error-boundary/index.js +1 -19
  69. package/dist/cjs/components/field/Field.js +1 -565
  70. package/dist/cjs/components/field/index.js +1 -29
  71. package/dist/cjs/components/field/tokens.js +1 -150
  72. package/dist/cjs/components/flex/Flex.js +1 -85
  73. package/dist/cjs/components/flex/FlexContext.js +1 -12
  74. package/dist/cjs/components/flex/FlexItem.js +1 -95
  75. package/dist/cjs/components/flex/index.js +1 -19
  76. package/dist/cjs/components/flex/tokens.js +1 -21
  77. package/dist/cjs/components/form/Form.js +1 -340
  78. package/dist/cjs/components/form/FormContext.js +1 -12
  79. package/dist/cjs/components/form/FormItem.js +1 -151
  80. package/dist/cjs/components/form/FormList.js +1 -95
  81. package/dist/cjs/components/form/index.js +1 -50
  82. package/dist/cjs/components/form/tokens.js +1 -14
  83. package/dist/cjs/components/form/utils.js +1 -56
  84. package/dist/cjs/components/grid/Grid.js +1 -118
  85. package/dist/cjs/components/grid/GridContext.js +1 -12
  86. package/dist/cjs/components/grid/GridItem.js +1 -158
  87. package/dist/cjs/components/grid/index.js +1 -12
  88. package/dist/cjs/components/grid/tokens.js +1 -105
  89. package/dist/cjs/components/image/Image.js +1 -263
  90. package/dist/cjs/components/image/index.js +1 -16
  91. package/dist/cjs/components/image/tokens.js +1 -66
  92. package/dist/cjs/components/image-preview/ImagePreview.js +1 -408
  93. package/dist/cjs/components/image-preview/imperative.js +1 -72
  94. package/dist/cjs/components/image-preview/index.js +1 -17
  95. package/dist/cjs/components/image-preview/tokens.js +1 -43
  96. package/dist/cjs/components/index.js +1 -769
  97. package/dist/cjs/components/input/Input.js +1 -122
  98. package/dist/cjs/components/input/index.js +1 -15
  99. package/dist/cjs/components/input/tokens.js +1 -22
  100. package/dist/cjs/components/loading/Loading.js +1 -76
  101. package/dist/cjs/components/loading/index.js +1 -8
  102. package/dist/cjs/components/loading/tokens.js +1 -32
  103. package/dist/cjs/components/nav-bar/NavBar.js +1 -196
  104. package/dist/cjs/components/nav-bar/index.js +1 -16
  105. package/dist/cjs/components/nav-bar/tokens.js +1 -90
  106. package/dist/cjs/components/notice-bar/NoticeBar.js +1 -369
  107. package/dist/cjs/components/notice-bar/index.js +1 -8
  108. package/dist/cjs/components/notice-bar/tokens.js +1 -39
  109. package/dist/cjs/components/notify/Notify.js +1 -262
  110. package/dist/cjs/components/notify/imperative.js +1 -145
  111. package/dist/cjs/components/notify/index.js +1 -10
  112. package/dist/cjs/components/notify/tokens.js +1 -74
  113. package/dist/cjs/components/number-keyboard/NumberKeyboard.js +1 -487
  114. package/dist/cjs/components/number-keyboard/index.js +1 -15
  115. package/dist/cjs/components/number-keyboard/tokens.js +1 -59
  116. package/dist/cjs/components/overlay/Overlay.js +1 -81
  117. package/dist/cjs/components/overlay/index.js +1 -28
  118. package/dist/cjs/components/overlay/tokens.js +1 -13
  119. package/dist/cjs/components/password-input/PasswordInput.js +1 -346
  120. package/dist/cjs/components/password-input/index.js +1 -13
  121. package/dist/cjs/components/password-input/tokens.js +1 -53
  122. package/dist/cjs/components/picker/Picker.js +1 -1056
  123. package/dist/cjs/components/picker/index.js +1 -15
  124. package/dist/cjs/components/picker/tokens.js +1 -53
  125. package/dist/cjs/components/popup/Popup.js +1 -518
  126. package/dist/cjs/components/popup/index.js +1 -15
  127. package/dist/cjs/components/popup/tokens.js +1 -62
  128. package/dist/cjs/components/portal/Portal.js +1 -50
  129. package/dist/cjs/components/portal/PortalContext.js +1 -15
  130. package/dist/cjs/components/portal/PortalHost.js +1 -253
  131. package/dist/cjs/components/portal/index.js +1 -25
  132. package/dist/cjs/components/portal/tokens.js +1 -11
  133. package/dist/cjs/components/progress/Progress.js +1 -216
  134. package/dist/cjs/components/progress/index.js +1 -14
  135. package/dist/cjs/components/progress/tokens.js +1 -52
  136. package/dist/cjs/components/radio/Radio.js +1 -245
  137. package/dist/cjs/components/radio/RadioContext.js +1 -12
  138. package/dist/cjs/components/radio/RadioGroup.js +1 -113
  139. package/dist/cjs/components/radio/index.js +1 -16
  140. package/dist/cjs/components/radio/tokens.js +1 -92
  141. package/dist/cjs/components/safe-area-view/SafeAreaView.js +1 -59
  142. package/dist/cjs/components/safe-area-view/index.js +1 -12
  143. package/dist/cjs/components/safe-area-view/tokens.js +1 -11
  144. package/dist/cjs/components/search/Search.js +1 -215
  145. package/dist/cjs/components/search/index.js +1 -15
  146. package/dist/cjs/components/search/tokens.js +1 -54
  147. package/dist/cjs/components/selector/Selector.js +1 -185
  148. package/dist/cjs/components/selector/index.js +1 -15
  149. package/dist/cjs/components/selector/tokens.js +1 -100
  150. package/dist/cjs/components/share-sheet/ShareSheet.js +1 -287
  151. package/dist/cjs/components/share-sheet/index.js +1 -16
  152. package/dist/cjs/components/share-sheet/tokens.js +1 -55
  153. package/dist/cjs/components/sidebar/Sidebar.js +1 -103
  154. package/dist/cjs/components/sidebar/SidebarContext.js +1 -17
  155. package/dist/cjs/components/sidebar/SidebarItem.js +1 -103
  156. package/dist/cjs/components/sidebar/index.js +1 -26
  157. package/dist/cjs/components/sidebar/tokens.js +1 -93
  158. package/dist/cjs/components/skeleton/Skeleton.js +1 -162
  159. package/dist/cjs/components/skeleton/index.js +1 -22
  160. package/dist/cjs/components/skeleton/tokens.js +1 -39
  161. package/dist/cjs/components/slider/Slider.js +1 -633
  162. package/dist/cjs/components/slider/index.js +1 -8
  163. package/dist/cjs/components/slider/tokens.js +1 -37
  164. package/dist/cjs/components/space/Space.js +1 -134
  165. package/dist/cjs/components/space/index.js +1 -18
  166. package/dist/cjs/components/space/tokens.js +1 -39
  167. package/dist/cjs/components/stepper/Stepper.js +1 -484
  168. package/dist/cjs/components/stepper/index.js +1 -15
  169. package/dist/cjs/components/stepper/tokens.js +1 -60
  170. package/dist/cjs/components/swiper/Swiper.js +1 -364
  171. package/dist/cjs/components/swiper/SwiperItem.js +1 -12
  172. package/dist/cjs/components/swiper/SwiperPagIndicator.js +1 -106
  173. package/dist/cjs/components/swiper/index.js +1 -40
  174. package/dist/cjs/components/swiper/tokens.js +1 -18
  175. package/dist/cjs/components/switch/Switch.js +1 -102
  176. package/dist/cjs/components/switch/index.js +1 -15
  177. package/dist/cjs/components/switch/tokens.js +1 -31
  178. package/dist/cjs/components/tabbar/Tabbar.js +1 -149
  179. package/dist/cjs/components/tabbar/TabbarContext.js +1 -17
  180. package/dist/cjs/components/tabbar/TabbarItem.js +1 -159
  181. package/dist/cjs/components/tabbar/index.js +1 -25
  182. package/dist/cjs/components/tabbar/tokens.js +1 -41
  183. package/dist/cjs/components/tabs/Tabs.js +1 -860
  184. package/dist/cjs/components/tabs/index.js +1 -25
  185. package/dist/cjs/components/tabs/tokens.js +1 -111
  186. package/dist/cjs/components/tag/Tag.js +1 -130
  187. package/dist/cjs/components/tag/index.js +1 -8
  188. package/dist/cjs/components/tag/tokens.js +1 -104
  189. package/dist/cjs/components/toast/Toast.js +1 -306
  190. package/dist/cjs/components/toast/imperative.js +1 -144
  191. package/dist/cjs/components/toast/index.js +1 -10
  192. package/dist/cjs/components/toast/tokens.js +1 -43
  193. package/dist/cjs/components/typography/Typography.js +1 -181
  194. package/dist/cjs/components/typography/index.js +1 -9
  195. package/dist/cjs/components/typography/tokens.js +1 -88
  196. package/dist/cjs/components/water-mark/WaterMark.js +1 -172
  197. package/dist/cjs/components/water-mark/index.js +1 -22
  198. package/dist/cjs/components/water-mark/tokens.js +1 -54
  199. package/dist/cjs/design-system/Text.js +1 -38
  200. package/dist/cjs/design-system/ThemeContext.js +1 -19
  201. package/dist/cjs/design-system/ThemeProvider.js +1 -31
  202. package/dist/cjs/design-system/createComponentTokensHook.js +1 -28
  203. package/dist/cjs/design-system/index.js +1 -66
  204. package/dist/cjs/design-system/mergeTokensOverride.js +1 -9
  205. package/dist/cjs/design-system/presets.js +1 -146
  206. package/dist/cjs/design-system/tokens.js +1 -135
  207. package/dist/cjs/design-system/useTheme.js +1 -16
  208. package/dist/cjs/hooks/animation/index.js +1 -25
  209. package/dist/cjs/hooks/animation/useAnimatedTransition.js +1 -72
  210. package/dist/cjs/hooks/animation/useReducedMotion.js +1 -75
  211. package/dist/cjs/hooks/aria/index.js +1 -49
  212. package/dist/cjs/hooks/aria/useAriaListBox.js +1 -50
  213. package/dist/cjs/hooks/aria/useAriaOverlay.js +1 -50
  214. package/dist/cjs/hooks/aria/useAriaPress.js +1 -94
  215. package/dist/cjs/hooks/aria/useAriaToggle.js +1 -41
  216. package/dist/cjs/hooks/gesture/index.js +1 -16
  217. package/dist/cjs/hooks/gesture/useGestureScroll.js +1 -129
  218. package/dist/cjs/hooks/index.js +1 -96
  219. package/dist/cjs/hooks/overlay/OverlayStackStore.js +1 -106
  220. package/dist/cjs/hooks/overlay/index.js +1 -27
  221. package/dist/cjs/hooks/overlay/useOverlayStack.js +1 -53
  222. package/dist/cjs/hooks/useControllableValue.js +1 -41
  223. package/dist/cjs/hooks/useCountDown.js +1 -99
  224. package/dist/cjs/hooks/useHairline.js +1 -46
  225. package/dist/cjs/hooks/useSafeAreaPadding.js +1 -38
  226. package/dist/cjs/index.js +1 -104
  227. package/dist/cjs/nativewind.js +1 -0
  228. package/dist/cjs/platform/animation.js +1 -22
  229. package/dist/cjs/platform/history.js +1 -14
  230. package/dist/cjs/platform/index.js +1 -60
  231. package/dist/cjs/platform/measure.js +1 -39
  232. package/dist/cjs/platform/runtime.js +1 -19
  233. package/dist/cjs/platform/scrollLock.js +1 -24
  234. package/dist/cjs/utils/array.js +1 -12
  235. package/dist/cjs/utils/color.js +1 -33
  236. package/dist/cjs/utils/compare.js +1 -21
  237. package/dist/cjs/utils/createPlatformShadow.js +1 -52
  238. package/dist/cjs/utils/date.js +1 -45
  239. package/dist/cjs/utils/deepMerge.js +1 -27
  240. package/dist/cjs/utils/hairline.js +1 -107
  241. package/dist/cjs/utils/index.js +1 -148
  242. package/dist/cjs/utils/number.js +1 -65
  243. package/dist/cjs/utils/promise.js +1 -9
  244. package/dist/cjs/utils/render.js +1 -21
  245. package/dist/cjs/utils/rtl.js +1 -25
  246. package/dist/cjs/utils/string.js +1 -22
  247. package/dist/cjs/utils/validate.js +1 -39
  248. package/dist/es/components/action-sheet/ActionSheet.js +1 -275
  249. package/dist/es/components/action-sheet/index.js +1 -3
  250. package/dist/es/components/action-sheet/tokens.js +1 -126
  251. package/dist/es/components/area/Area.js +1 -113
  252. package/dist/es/components/area/index.js +1 -2
  253. package/dist/es/components/area/tokens.js +1 -8
  254. package/dist/es/components/avatar/Avatar.js +1 -106
  255. package/dist/es/components/avatar/index.js +1 -1
  256. package/dist/es/components/avatar/tokens.js +1 -49
  257. package/dist/es/components/badge/Badge.js +1 -147
  258. package/dist/es/components/badge/index.js +1 -2
  259. package/dist/es/components/badge/tokens.js +1 -75
  260. package/dist/es/components/button/Button.js +1 -184
  261. package/dist/es/components/button/ButtonContext.js +1 -1
  262. package/dist/es/components/button/ButtonGroup.js +1 -46
  263. package/dist/es/components/button/index.js +1 -7
  264. package/dist/es/components/button/tokens.js +1 -170
  265. package/dist/es/components/calendar/Calendar.js +1 -432
  266. package/dist/es/components/calendar/index.js +1 -2
  267. package/dist/es/components/calendar/tokens.js +1 -122
  268. package/dist/es/components/cascader/Cascader.js +1 -456
  269. package/dist/es/components/cascader/index.js +1 -3
  270. package/dist/es/components/cascader/tokens.js +1 -131
  271. package/dist/es/components/cascader/useCascaderExtend.js +1 -32
  272. package/dist/es/components/cell/Cell.js +1 -156
  273. package/dist/es/components/cell/CellContext.js +1 -6
  274. package/dist/es/components/cell/CellGroup.js +1 -81
  275. package/dist/es/components/cell/index.js +1 -8
  276. package/dist/es/components/cell/tokens.js +1 -160
  277. package/dist/es/components/checkbox/Checkbox.js +1 -220
  278. package/dist/es/components/checkbox/CheckboxContext.js +1 -1
  279. package/dist/es/components/checkbox/CheckboxGroup.js +1 -117
  280. package/dist/es/components/checkbox/index.js +1 -5
  281. package/dist/es/components/checkbox/tokens.js +1 -85
  282. package/dist/es/components/circle/Circle.js +1 -187
  283. package/dist/es/components/circle/index.js +1 -2
  284. package/dist/es/components/circle/tokens.js +1 -48
  285. package/dist/es/components/collapse/Collapse.js +1 -286
  286. package/dist/es/components/collapse/index.js +1 -2
  287. package/dist/es/components/collapse/tokens.js +1 -74
  288. package/dist/es/components/config-provider/ConfigProvider.js +1 -25
  289. package/dist/es/components/config-provider/DirectionContext.js +1 -2
  290. package/dist/es/components/config-provider/LocaleContext.js +1 -3
  291. package/dist/es/components/config-provider/index.js +1 -5
  292. package/dist/es/components/config-provider/locale/en-US.js +1 -106
  293. package/dist/es/components/config-provider/locale/zh-CN.js +1 -106
  294. package/dist/es/components/config-provider/tokens.js +1 -5
  295. package/dist/es/components/config-provider/useDirection.js +1 -3
  296. package/dist/es/components/config-provider/useLocale.js +1 -3
  297. package/dist/es/components/count-down/CountDown.js +1 -69
  298. package/dist/es/components/count-down/index.js +1 -3
  299. package/dist/es/components/count-down/tokens.js +1 -27
  300. package/dist/es/components/datetime-picker/DatetimePicker.js +1 -305
  301. package/dist/es/components/datetime-picker/index.js +1 -2
  302. package/dist/es/components/datetime-picker/tokens.js +1 -16
  303. package/dist/es/components/dialog/Dialog.js +1 -407
  304. package/dist/es/components/dialog/imperative.js +1 -185
  305. package/dist/es/components/dialog/index.js +1 -17
  306. package/dist/es/components/dialog/tokens.js +1 -57
  307. package/dist/es/components/divider/Divider.js +1 -107
  308. package/dist/es/components/divider/index.js +1 -2
  309. package/dist/es/components/divider/tokens.js +1 -55
  310. package/dist/es/components/empty/Empty.js +1 -100
  311. package/dist/es/components/empty/index.js +1 -2
  312. package/dist/es/components/empty/tokens.js +1 -48
  313. package/dist/es/components/error-boundary/ErrorBoundary.js +1 -62
  314. package/dist/es/components/error-boundary/index.js +1 -1
  315. package/dist/es/components/field/Field.js +1 -539
  316. package/dist/es/components/field/index.js +1 -6
  317. package/dist/es/components/field/tokens.js +1 -138
  318. package/dist/es/components/flex/Flex.js +1 -66
  319. package/dist/es/components/flex/FlexContext.js +1 -1
  320. package/dist/es/components/flex/FlexItem.js +1 -76
  321. package/dist/es/components/flex/index.js +1 -8
  322. package/dist/es/components/flex/tokens.js +1 -15
  323. package/dist/es/components/form/Form.js +1 -319
  324. package/dist/es/components/form/FormContext.js +1 -1
  325. package/dist/es/components/form/FormItem.js +1 -138
  326. package/dist/es/components/form/FormList.js +1 -81
  327. package/dist/es/components/form/index.js +1 -13
  328. package/dist/es/components/form/tokens.js +1 -8
  329. package/dist/es/components/form/utils.js +1 -45
  330. package/dist/es/components/grid/Grid.js +1 -99
  331. package/dist/es/components/grid/GridContext.js +1 -1
  332. package/dist/es/components/grid/GridItem.js +1 -138
  333. package/dist/es/components/grid/index.js +1 -6
  334. package/dist/es/components/grid/tokens.js +1 -98
  335. package/dist/es/components/image/Image.js +1 -238
  336. package/dist/es/components/image/index.js +1 -3
  337. package/dist/es/components/image/tokens.js +1 -60
  338. package/dist/es/components/image-preview/ImagePreview.js +1 -388
  339. package/dist/es/components/image-preview/imperative.js +1 -58
  340. package/dist/es/components/image-preview/index.js +1 -11
  341. package/dist/es/components/image-preview/tokens.js +1 -37
  342. package/dist/es/components/index.js +1 -110
  343. package/dist/es/components/input/Input.js +1 -109
  344. package/dist/es/components/input/index.js +1 -3
  345. package/dist/es/components/input/tokens.js +1 -16
  346. package/dist/es/components/loading/Loading.js +1 -57
  347. package/dist/es/components/loading/index.js +1 -2
  348. package/dist/es/components/loading/tokens.js +1 -25
  349. package/dist/es/components/nav-bar/NavBar.js +1 -171
  350. package/dist/es/components/nav-bar/index.js +1 -3
  351. package/dist/es/components/nav-bar/tokens.js +1 -83
  352. package/dist/es/components/notice-bar/NoticeBar.js +1 -344
  353. package/dist/es/components/notice-bar/index.js +1 -2
  354. package/dist/es/components/notice-bar/tokens.js +1 -32
  355. package/dist/es/components/notify/Notify.js +1 -242
  356. package/dist/es/components/notify/imperative.js +1 -131
  357. package/dist/es/components/notify/index.js +1 -5
  358. package/dist/es/components/notify/tokens.js +1 -67
  359. package/dist/es/components/number-keyboard/NumberKeyboard.js +1 -467
  360. package/dist/es/components/number-keyboard/index.js +1 -3
  361. package/dist/es/components/number-keyboard/tokens.js +1 -53
  362. package/dist/es/components/overlay/Overlay.js +1 -50
  363. package/dist/es/components/overlay/index.js +1 -4
  364. package/dist/es/components/overlay/tokens.js +1 -7
  365. package/dist/es/components/password-input/PasswordInput.js +1 -327
  366. package/dist/es/components/password-input/index.js +1 -1
  367. package/dist/es/components/password-input/tokens.js +1 -41
  368. package/dist/es/components/picker/Picker.js +1 -1031
  369. package/dist/es/components/picker/index.js +1 -3
  370. package/dist/es/components/picker/tokens.js +1 -47
  371. package/dist/es/components/popup/Popup.js +1 -492
  372. package/dist/es/components/popup/index.js +1 -3
  373. package/dist/es/components/popup/tokens.js +1 -55
  374. package/dist/es/components/portal/Portal.js +1 -37
  375. package/dist/es/components/portal/PortalContext.js +1 -2
  376. package/dist/es/components/portal/PortalHost.js +1 -234
  377. package/dist/es/components/portal/index.js +1 -3
  378. package/dist/es/components/portal/tokens.js +1 -5
  379. package/dist/es/components/progress/Progress.js +1 -196
  380. package/dist/es/components/progress/index.js +1 -3
  381. package/dist/es/components/progress/tokens.js +1 -45
  382. package/dist/es/components/radio/Radio.js +1 -214
  383. package/dist/es/components/radio/RadioContext.js +1 -1
  384. package/dist/es/components/radio/RadioGroup.js +1 -82
  385. package/dist/es/components/radio/index.js +1 -5
  386. package/dist/es/components/radio/tokens.js +1 -80
  387. package/dist/es/components/safe-area-view/SafeAreaView.js +1 -40
  388. package/dist/es/components/safe-area-view/index.js +1 -1
  389. package/dist/es/components/safe-area-view/tokens.js +1 -5
  390. package/dist/es/components/search/Search.js +1 -189
  391. package/dist/es/components/search/index.js +1 -3
  392. package/dist/es/components/search/tokens.js +1 -48
  393. package/dist/es/components/selector/Selector.js +1 -166
  394. package/dist/es/components/selector/index.js +1 -3
  395. package/dist/es/components/selector/tokens.js +1 -88
  396. package/dist/es/components/share-sheet/ShareSheet.js +1 -267
  397. package/dist/es/components/share-sheet/index.js +1 -3
  398. package/dist/es/components/share-sheet/tokens.js +1 -49
  399. package/dist/es/components/sidebar/Sidebar.js +1 -84
  400. package/dist/es/components/sidebar/SidebarContext.js +1 -3
  401. package/dist/es/components/sidebar/SidebarItem.js +1 -84
  402. package/dist/es/components/sidebar/index.js +1 -8
  403. package/dist/es/components/sidebar/tokens.js +1 -80
  404. package/dist/es/components/skeleton/Skeleton.js +1 -143
  405. package/dist/es/components/skeleton/index.js +1 -4
  406. package/dist/es/components/skeleton/tokens.js +1 -33
  407. package/dist/es/components/slider/Slider.js +1 -596
  408. package/dist/es/components/slider/index.js +1 -2
  409. package/dist/es/components/slider/tokens.js +1 -31
  410. package/dist/es/components/space/Space.js +1 -115
  411. package/dist/es/components/space/index.js +1 -2
  412. package/dist/es/components/space/tokens.js +1 -32
  413. package/dist/es/components/stepper/Stepper.js +1 -465
  414. package/dist/es/components/stepper/index.js +1 -3
  415. package/dist/es/components/stepper/tokens.js +1 -54
  416. package/dist/es/components/swiper/Swiper.js +1 -344
  417. package/dist/es/components/swiper/SwiperItem.js +1 -1
  418. package/dist/es/components/swiper/SwiperPagIndicator.js +1 -87
  419. package/dist/es/components/swiper/index.js +1 -10
  420. package/dist/es/components/swiper/tokens.js +1 -12
  421. package/dist/es/components/switch/Switch.js +1 -83
  422. package/dist/es/components/switch/index.js +1 -3
  423. package/dist/es/components/switch/tokens.js +1 -25
  424. package/dist/es/components/tabbar/Tabbar.js +1 -130
  425. package/dist/es/components/tabbar/TabbarContext.js +1 -3
  426. package/dist/es/components/tabbar/TabbarItem.js +1 -139
  427. package/dist/es/components/tabbar/index.js +1 -7
  428. package/dist/es/components/tabbar/tokens.js +1 -35
  429. package/dist/es/components/tabs/Tabs.js +1 -841
  430. package/dist/es/components/tabs/index.js +1 -7
  431. package/dist/es/components/tabs/tokens.js +1 -105
  432. package/dist/es/components/tag/Tag.js +1 -105
  433. package/dist/es/components/tag/index.js +1 -2
  434. package/dist/es/components/tag/tokens.js +1 -97
  435. package/dist/es/components/toast/Toast.js +1 -280
  436. package/dist/es/components/toast/imperative.js +1 -130
  437. package/dist/es/components/toast/index.js +1 -5
  438. package/dist/es/components/toast/tokens.js +1 -36
  439. package/dist/es/components/typography/Typography.js +1 -162
  440. package/dist/es/components/typography/index.js +1 -2
  441. package/dist/es/components/typography/tokens.js +1 -82
  442. package/dist/es/components/water-mark/WaterMark.js +1 -153
  443. package/dist/es/components/water-mark/index.js +1 -4
  444. package/dist/es/components/water-mark/tokens.js +1 -42
  445. package/dist/es/design-system/Text.js +1 -19
  446. package/dist/es/design-system/ThemeContext.js +1 -6
  447. package/dist/es/design-system/ThemeProvider.js +1 -17
  448. package/dist/es/design-system/createComponentTokensHook.js +1 -15
  449. package/dist/es/design-system/index.js +1 -7
  450. package/dist/es/design-system/mergeTokensOverride.js +1 -2
  451. package/dist/es/design-system/presets.js +1 -139
  452. package/dist/es/design-system/tokens.js +1 -128
  453. package/dist/es/design-system/useTheme.js +1 -3
  454. package/dist/es/hooks/animation/index.js +1 -2
  455. package/dist/es/hooks/animation/useAnimatedTransition.js +1 -53
  456. package/dist/es/hooks/animation/useReducedMotion.js +1 -54
  457. package/dist/es/hooks/aria/index.js +1 -5
  458. package/dist/es/hooks/aria/useAriaListBox.js +1 -25
  459. package/dist/es/hooks/aria/useAriaOverlay.js +1 -25
  460. package/dist/es/hooks/aria/useAriaPress.js +1 -57
  461. package/dist/es/hooks/aria/useAriaToggle.js +1 -16
  462. package/dist/es/hooks/gesture/index.js +1 -2
  463. package/dist/es/hooks/gesture/useGestureScroll.js +1 -110
  464. package/dist/es/hooks/index.js +1 -8
  465. package/dist/es/hooks/overlay/OverlayStackStore.js +1 -93
  466. package/dist/es/hooks/overlay/index.js +1 -3
  467. package/dist/es/hooks/overlay/useOverlayStack.js +1 -40
  468. package/dist/es/hooks/useControllableValue.js +1 -29
  469. package/dist/es/hooks/useCountDown.js +1 -87
  470. package/dist/es/hooks/useHairline.js +1 -26
  471. package/dist/es/hooks/useSafeAreaPadding.js +1 -20
  472. package/dist/es/index.js +1 -11
  473. package/dist/es/nativewind.js +1 -0
  474. package/dist/es/platform/animation.js +1 -10
  475. package/dist/es/platform/history.js +1 -7
  476. package/dist/es/platform/index.js +1 -6
  477. package/dist/es/platform/measure.js +1 -32
  478. package/dist/es/platform/runtime.js +1 -4
  479. package/dist/es/platform/scrollLock.js +1 -16
  480. package/dist/es/types.js +1 -1
  481. package/dist/es/utils/array.js +1 -5
  482. package/dist/es/utils/color.js +1 -25
  483. package/dist/es/utils/compare.js +1 -13
  484. package/dist/es/utils/createPlatformShadow.js +1 -39
  485. package/dist/es/utils/date.js +1 -33
  486. package/dist/es/utils/deepMerge.js +1 -21
  487. package/dist/es/utils/hairline.js +1 -93
  488. package/dist/es/utils/index.js +1 -14
  489. package/dist/es/utils/number.js +1 -48
  490. package/dist/es/utils/promise.js +1 -2
  491. package/dist/es/utils/render.js +1 -7
  492. package/dist/es/utils/rtl.js +1 -17
  493. package/dist/es/utils/string.js +1 -13
  494. package/dist/es/utils/validate.js +1 -14
  495. package/dist/types/components/nav-bar/tokens.d.ts +1 -1
  496. package/dist/types/design-system/tokens.d.ts +1 -0
  497. package/dist/types/nativewind.d.ts +4 -0
  498. package/package.json +15 -3
@@ -1,340 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.useWatch = exports.default = exports.FormSubscribe = exports.FormContext = void 0;
7
- function _react() {
8
- const data = _interopRequireWildcard(require("react"));
9
- _react = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- function _reactNative() {
15
- const data = require("react-native");
16
- _reactNative = function () {
17
- return data;
18
- };
19
- return data;
20
- }
21
- var _utils = require("../../utils");
22
- var _promise = require("../../utils/promise");
23
- var _validate = require("../../utils/validate");
24
- var _utils2 = require("./utils");
25
- var _useLocale = require("../config-provider/useLocale");
26
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
27
- function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
28
- const FormContext = exports.FormContext = /*#__PURE__*/_react().default.createContext(null);
29
- const runRuleValidation = (rule, value, values, fallbackMsg) => {
30
- const msg = rule.message ?? fallbackMsg ?? 'Validation failed';
31
- const empty = value == null || value === '' || Array.isArray(value) && value.length === 0;
32
- if (rule.required && (empty || rule.whitespace && (0, _validate.isString)(value) && value.trim().length === 0)) return msg;
33
- if (empty) return null;
34
- if (rule.pattern && (0, _validate.isString)(value) && !rule.pattern.test(value)) return msg;
35
- if (rule.len !== undefined || rule.min !== undefined || rule.max !== undefined) {
36
- const len = (0, _validate.isNumber)(value) ? value : (0, _validate.isString)(value) || Array.isArray(value) ? value.length : 0;
37
- if (rule.len !== undefined && len !== rule.len) return msg;
38
- if (rule.min !== undefined && len < rule.min) return msg;
39
- if (rule.max !== undefined && len > rule.max) return msg;
40
- }
41
- if (!rule.validator) return null;
42
- const handleResult = r => (0, _validate.isString)(r) ? r : r === false ? msg : null;
43
- const res = rule.validator(value, values);
44
- return (0, _promise.isPromiseLike)(res) ? res.then(handleResult) : handleResult(res);
45
- };
46
- const InternalFormImpl = (props, ref) => {
47
- const {
48
- initialValues,
49
- colon,
50
- labelWidth,
51
- showValidateMessage = true,
52
- onValuesChange,
53
- onFinish,
54
- style,
55
- footer,
56
- children,
57
- ...rest
58
- } = props;
59
- const locale = (0, _useLocale.useLocale)();
60
- const defaultValuesRef = (0, _react().useRef)({}),
61
- errorsRef = (0, _react().useRef)({}),
62
- lastInitialValuesRef = (0, _react().useRef)(initialValues ?? defaultValuesRef.current),
63
- fieldsRef = (0, _react().useRef)({}),
64
- dependencyGraphRef = (0, _react().useRef)(new Map()),
65
- valuesRef = (0, _react().useRef)(initialValues ?? defaultValuesRef.current),
66
- validationSeqRef = (0, _react().useRef)({}),
67
- subscribersRef = (0, _react().useRef)(new Set()),
68
- onValuesChangeRef = (0, _react().useRef)(onValuesChange),
69
- onFinishRef = (0, _react().useRef)(onFinish);
70
- onValuesChangeRef.current = onValuesChange;
71
- onFinishRef.current = onFinish;
72
- const mergedInitialValues = initialValues ?? defaultValuesRef.current;
73
- const [, setVersion] = (0, _react().useState)(0);
74
- const notify = (0, _react().useCallback)((changedValues, newValues) => {
75
- subscribersRef.current.forEach(l => l(changedValues, newValues));
76
- }, []);
77
- (0, _react().useEffect)(() => {
78
- if ((0, _utils.shallowEqualObject)(lastInitialValuesRef.current, mergedInitialValues)) return;
79
- lastInitialValuesRef.current = mergedInitialValues;
80
- valuesRef.current = mergedInitialValues;
81
- errorsRef.current = {};
82
- setVersion(v => v + 1);
83
- notify({
84
- [_utils2.FORM_ALL_FIELDS_KEY]: true
85
- }, mergedInitialValues);
86
- }, [mergedInitialValues, notify]);
87
- const setFieldErrors = (0, _react().useCallback)((name, newErrors) => {
88
- const key = (0, _utils2.serializeNamePath)(name);
89
- const prevE = errorsRef.current[key];
90
- if (!newErrors.length) {
91
- if (!prevE) return;
92
- const cl = {
93
- ...errorsRef.current
94
- };
95
- delete cl[key];
96
- errorsRef.current = cl;
97
- notify({
98
- [key]: (0, _utils2.getValueByName)(valuesRef.current, name)
99
- }, valuesRef.current);
100
- return;
101
- }
102
- if (prevE?.[0] === newErrors[0] && prevE.length === newErrors.length) return;
103
- errorsRef.current = {
104
- ...errorsRef.current,
105
- [key]: newErrors
106
- };
107
- notify({
108
- [key]: (0, _utils2.getValueByName)(valuesRef.current, name)
109
- }, valuesRef.current);
110
- }, [notify]);
111
- const registerField = (0, _react().useCallback)((name, opts) => {
112
- const key = (0, _utils2.serializeNamePath)(name);
113
- const prev = fieldsRef.current[key];
114
- if (prev?.dependencies?.length) {
115
- for (const dep of prev.dependencies) {
116
- const dk = (0, _utils2.serializeNamePath)(dep);
117
- const s = dependencyGraphRef.current.get(dk);
118
- if (!s) continue;
119
- s.delete(key);
120
- if (!s.size) dependencyGraphRef.current.delete(dk);
121
- }
122
- }
123
- fieldsRef.current[key] = {
124
- ...opts,
125
- name
126
- };
127
- if (opts.dependencies?.length) {
128
- for (const dep of opts.dependencies) {
129
- const dk = (0, _utils2.serializeNamePath)(dep);
130
- const s = dependencyGraphRef.current.get(dk);
131
- if (s) s.add(key);else dependencyGraphRef.current.set(dk, new Set([key]));
132
- }
133
- }
134
- if (opts.initialValue !== undefined) {
135
- const exInit = (0, _utils2.getValueByName)(lastInitialValuesRef.current, name);
136
- if (exInit === undefined) lastInitialValuesRef.current = (0, _utils2.setValueByName)(lastInitialValuesRef.current, name, opts.initialValue);
137
- const exState = (0, _utils2.getValueByName)(valuesRef.current, name);
138
- if (exState === undefined) {
139
- const next = (0, _utils2.setValueByName)(valuesRef.current, name, opts.initialValue);
140
- valuesRef.current = next;
141
- notify({
142
- [key]: opts.initialValue
143
- }, next);
144
- }
145
- }
146
- return () => {
147
- const cur = fieldsRef.current[key];
148
- delete fieldsRef.current[key];
149
- if (cur?.dependencies?.length) {
150
- for (const dep of cur.dependencies) {
151
- const dk = (0, _utils2.serializeNamePath)(dep);
152
- const s = dependencyGraphRef.current.get(dk);
153
- if (!s) continue;
154
- s.delete(key);
155
- if (!s.size) dependencyGraphRef.current.delete(dk);
156
- }
157
- }
158
- ;
159
- setFieldErrors(name, []);
160
- };
161
- }, [notify, setFieldErrors]);
162
- const localeRef = (0, _react().useRef)(locale);
163
- localeRef.current = locale;
164
- const validateField = (0, _react().useCallback)(async (name, trigger, valueOverride, valuesOverride) => {
165
- const key = (0, _utils2.serializeNamePath)(name);
166
- const seq = (validationSeqRef.current[key] ?? 0) + 1;
167
- validationSeqRef.current[key] = seq;
168
- const fOpts = fieldsRef.current[key];
169
- const fRules = fOpts?.rules ?? [];
170
- if (!fRules.length) {
171
- setFieldErrors(name, []);
172
- return true;
173
- }
174
- let appRules = trigger ? fRules.filter(r => {
175
- const rt = r.validateTrigger ?? fOpts.validateTrigger;
176
- return !rt || (0, _utils2.normalizeTrigger)(rt).includes(trigger);
177
- }) : fRules;
178
- if (!appRules.length) {
179
- if (!errorsRef.current[key]?.length) return true;
180
- appRules = fRules;
181
- }
182
- const curVals = valuesOverride ?? valuesRef.current;
183
- const val = valueOverride ?? (0, _utils2.getValueByName)(curVals, name);
184
- const fbMsg = localeRef.current?.vanForm?.validationFailed;
185
- for (const rule of appRules) {
186
- const result = runRuleValidation(rule, val, curVals, fbMsg);
187
- const err = (0, _promise.isPromiseLike)(result) ? await result : result;
188
- if (validationSeqRef.current[key] !== seq) return true;
189
- if (err) {
190
- setFieldErrors(name, [err]);
191
- return false;
192
- }
193
- }
194
- if (validationSeqRef.current[key] !== seq) return true;
195
- setFieldErrors(name, []);
196
- return true;
197
- }, [setFieldErrors]);
198
- const validateFields = (0, _react().useCallback)(async names => {
199
- const fNames = names ?? Object.values(fieldsRef.current).map(it => it.name);
200
- const results = await Promise.all(fNames.map(n => validateField(n)));
201
- if (results.some(r => !r)) throw errorsRef.current;
202
- return valuesRef.current;
203
- }, [validateField]);
204
- const validateWithDependencies = (0, _react().useCallback)((key, name, trigger, val, vals) => {
205
- validateField(name, trigger, val, vals);
206
- const deps = dependencyGraphRef.current.get(key);
207
- if (deps?.size) {
208
- for (const dk of deps) {
209
- const m = fieldsRef.current[dk];
210
- if (m) validateField(m.name, trigger, (0, _utils2.getValueByName)(vals, m.name), vals);
211
- }
212
- }
213
- }, [validateField]);
214
- const setFieldValue = (0, _react().useCallback)((name, val, trigger) => {
215
- const nKey = (0, _utils2.serializeNamePath)(name);
216
- const prev = valuesRef.current;
217
- if ((0, _utils2.getValueByName)(prev, name) === val) return;
218
- const next = (0, _utils2.setValueByName)(prev, name, val);
219
- valuesRef.current = next;
220
- onValuesChangeRef.current?.(next, nKey, val);
221
- validateWithDependencies(nKey, name, trigger, val, next);
222
- notify({
223
- [nKey]: val
224
- }, next);
225
- }, [notify, validateWithDependencies]);
226
- const formApi = (0, _react().useMemo)(() => ({
227
- submit: async () => {
228
- try {
229
- const res = await validateFields();
230
- onFinishRef.current?.(res);
231
- return res;
232
- } catch {
233
- return undefined;
234
- }
235
- },
236
- getFieldsValue: () => valuesRef.current,
237
- setFieldsValue: (next, opts) => {
238
- const sV = opts?.validate ?? false;
239
- const prev = valuesRef.current;
240
- let m = prev;
241
- const ch = {};
242
- Object.keys(next).forEach(k => {
243
- const nv = next[k];
244
- if ((0, _utils2.getValueByName)(m, k) === nv) return;
245
- ch[k] = nv;
246
- m = (0, _utils2.setValueByName)(m, k, nv);
247
- onValuesChangeRef.current?.(m, k, nv);
248
- if (sV) validateWithDependencies(k, k, undefined, nv, m);
249
- });
250
- if (m === prev) return;
251
- valuesRef.current = m;
252
- notify(ch, m);
253
- },
254
- resetFields: () => {
255
- let n = lastInitialValuesRef.current;
256
- Object.values(fieldsRef.current).forEach(mem => {
257
- if (mem.initialValue === undefined) return;
258
- if ((0, _utils2.getValueByName)(n, mem.name) !== undefined) return;
259
- n = (0, _utils2.setValueByName)(n, mem.name, mem.initialValue);
260
- });
261
- valuesRef.current = n;
262
- errorsRef.current = {};
263
- notify({
264
- [_utils2.FORM_ALL_FIELDS_KEY]: true
265
- }, n);
266
- },
267
- validateFields,
268
- getFieldError: name => errorsRef.current[(0, _utils2.serializeNamePath)(name)] ?? []
269
- }), [validateFields, validateWithDependencies, notify]);
270
- (0, _react().useImperativeHandle)(ref, () => formApi, [formApi]);
271
- const ctxVal = (0, _react().useMemo)(() => ({
272
- getFieldValue: name => (0, _utils2.getValueByName)(valuesRef.current, name),
273
- setFieldValue,
274
- registerField,
275
- getFieldError: name => errorsRef.current[(0, _utils2.serializeNamePath)(name)],
276
- validateField: (name, trigger) => validateField(name, trigger),
277
- getFieldsValue: () => valuesRef.current,
278
- subscribe: listener => {
279
- subscribersRef.current.add(listener);
280
- return () => subscribersRef.current.delete(listener);
281
- },
282
- form: formApi,
283
- colon,
284
- labelWidth,
285
- showValidateMessage
286
- }), [setFieldValue, registerField, validateField, formApi, colon, labelWidth, showValidateMessage]);
287
- return /*#__PURE__*/_react().default.createElement(FormContext.Provider, {
288
- value: ctxVal
289
- }, /*#__PURE__*/_react().default.createElement(_reactNative().View, _extends({
290
- style: style
291
- }, rest), children, (0, _validate.isText)(footer) ? (0, _utils.renderTextOrNode)(footer, []) : footer));
292
- };
293
- const InternalFormRef = /*#__PURE__*/_react().default.forwardRef(InternalFormImpl);
294
- const InternalForm = /*#__PURE__*/_react().default.memo(InternalFormRef);
295
- const useWatch = (name, formRef) => {
296
- const ctx = (0, _react().useContext)(FormContext);
297
- const nPaths = name === undefined ? undefined : !Array.isArray(name) ? [name] : name.length && (0, _validate.isText)(name[0]) ? [name] : name;
298
- const getValue = (0, _react().useCallback)(allValues => {
299
- const src = allValues ?? ctx?.getFieldsValue?.() ?? formRef?.current?.getFieldsValue?.() ?? {};
300
- if (!nPaths) return src;
301
- if (nPaths.length === 1) return (0, _utils2.getValueByName)(src, nPaths[0]);
302
- const picked = {};
303
- for (const k of nPaths) picked[(0, _utils2.serializeNamePath)(k)] = (0, _utils2.getValueByName)(src, k);
304
- return picked;
305
- }, [ctx, formRef, nPaths]);
306
- const [val, setVal] = (0, _react().useState)(() => getValue());
307
- (0, _react().useEffect)(() => {
308
- if (!ctx?.subscribe) return undefined;
309
- return ctx.subscribe((ch, all) => {
310
- if (_utils2.FORM_ALL_FIELDS_KEY in ch) {
311
- setVal(getValue(all));
312
- return;
313
- }
314
- ;
315
- if (!nPaths || nPaths.some(k => (0, _utils2.serializeNamePath)(k) in ch)) setVal(getValue(all));
316
- });
317
- }, [ctx, getValue, nPaths]);
318
- (0, _react().useEffect)(() => {
319
- setVal(getValue());
320
- }, [getValue]);
321
- return val;
322
- };
323
- exports.useWatch = useWatch;
324
- const FormSubscribe = ({
325
- to,
326
- children
327
- }) => {
328
- const ctx = (0, _react().useContext)(FormContext);
329
- const [chVals, setChVals] = (0, _react().useState)({});
330
- (0, _react().useEffect)(() => {
331
- if (!ctx?.subscribe) return undefined;
332
- return ctx.subscribe(n => {
333
- if (to && !(_utils2.FORM_ALL_FIELDS_KEY in n) && !Object.keys(n).some(k => to.includes(k))) return;
334
- setChVals(n);
335
- });
336
- }, [ctx, to]);
337
- return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children(chVals, ctx?.form || null));
338
- };
339
- exports.FormSubscribe = FormSubscribe;
340
- var _default = exports.default = InternalForm;
1
+ "use strict";function _react(){const e=_interopRequireWildcard(require("react"));return _react=function(){return e},e}function _reactNative(){const e=require("react-native");return _reactNative=function(){return e},e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.useWatch=exports.default=exports.FormSubscribe=exports.FormContext=void 0;var _utils=require("../../utils"),_promise=require("../../utils/promise"),_validate=require("../../utils/validate"),_utils2=require("./utils"),_useLocale=require("../config-provider/useLocale");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,a=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var n,u,i={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return i;if(n=t?a:r){if(n.has(e))return n.get(e);n.set(e,i)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((u=(n=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(u.get||u.set)?n(i,t,u):i[t]=e[t]);return i})(e,t)}function _extends(){return _extends=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var a in r)({}).hasOwnProperty.call(r,a)&&(e[a]=r[a])}return e},_extends.apply(null,arguments)}const FormContext=exports.FormContext=_react().default.createContext(null),runRuleValidation=(e,t,r,a)=>{const n=e.message??a??"Validation failed",u=null==t||""===t||Array.isArray(t)&&0===t.length;if(e.required&&(u||e.whitespace&&(0,_validate.isString)(t)&&0===t.trim().length))return n;if(u)return null;if(e.pattern&&(0,_validate.isString)(t)&&!e.pattern.test(t))return n;if(void 0!==e.len||void 0!==e.min||void 0!==e.max){const r=(0,_validate.isNumber)(t)?t:(0,_validate.isString)(t)||Array.isArray(t)?t.length:0;if(void 0!==e.len&&r!==e.len)return n;if(void 0!==e.min&&r<e.min)return n;if(void 0!==e.max&&r>e.max)return n}if(!e.validator)return null;const i=e=>(0,_validate.isString)(e)?e:!1===e?n:null,l=e.validator(t,r);return(0,_promise.isPromiseLike)(l)?l.then(i):i(l)},InternalFormImpl=(e,t)=>{const{initialValues:r,colon:a,labelWidth:n,showValidateMessage:u=!0,onValuesChange:i,onFinish:l,style:s,footer:c,children:o,..._}=e,d=(0,_useLocale.useLocale)(),f=(0,_react().useRef)({}),m=(0,_react().useRef)({}),g=(0,_react().useRef)(r??f.current),v=(0,_react().useRef)({}),h=(0,_react().useRef)(new Map),p=(0,_react().useRef)(r??f.current),b=(0,_react().useRef)({}),F=(0,_react().useRef)(new Set),y=(0,_react().useRef)(i),V=(0,_react().useRef)(l);y.current=i,V.current=l;const N=r??f.current,[,x]=(0,_react().useState)(0),R=(0,_react().useCallback)((e,t)=>{F.current.forEach(r=>r(e,t))},[]);(0,_react().useEffect)(()=>{(0,_utils.shallowEqualObject)(g.current,N)||(g.current=N,p.current=N,m.current={},x(e=>e+1),R({[_utils2.FORM_ALL_FIELDS_KEY]:!0},N))},[N,R]);const E=(0,_react().useCallback)((e,t)=>{const r=(0,_utils2.serializeNamePath)(e),a=m.current[r];if(!t.length){if(!a)return;const t={...m.current};return delete t[r],m.current=t,void R({[r]:(0,_utils2.getValueByName)(p.current,e)},p.current)}a?.[0]===t[0]&&a.length===t.length||(m.current={...m.current,[r]:t},R({[r]:(0,_utils2.getValueByName)(p.current,e)},p.current))},[R]),P=(0,_react().useCallback)((e,t)=>{const r=(0,_utils2.serializeNamePath)(e),a=v.current[r];if(a?.dependencies?.length)for(const e of a.dependencies){const t=(0,_utils2.serializeNamePath)(e),a=h.current.get(t);a&&(a.delete(r),a.size||h.current.delete(t))}if(v.current[r]={...t,name:e},t.dependencies?.length)for(const e of t.dependencies){const t=(0,_utils2.serializeNamePath)(e),a=h.current.get(t);a?a.add(r):h.current.set(t,new Set([r]))}if(void 0!==t.initialValue){void 0===(0,_utils2.getValueByName)(g.current,e)&&(g.current=(0,_utils2.setValueByName)(g.current,e,t.initialValue));if(void 0===(0,_utils2.getValueByName)(p.current,e)){const a=(0,_utils2.setValueByName)(p.current,e,t.initialValue);p.current=a,R({[r]:t.initialValue},a)}}return()=>{const t=v.current[r];if(delete v.current[r],t?.dependencies?.length)for(const e of t.dependencies){const t=(0,_utils2.serializeNamePath)(e),a=h.current.get(t);a&&(a.delete(r),a.size||h.current.delete(t))}E(e,[])}},[R,E]),w=(0,_react().useRef)(d);w.current=d;const C=(0,_react().useCallback)(async(e,t,r,a)=>{const n=(0,_utils2.serializeNamePath)(e),u=(b.current[n]??0)+1;b.current[n]=u;const i=v.current[n],l=i?.rules??[];if(!l.length)return E(e,[]),!0;let s=t?l.filter(e=>{const r=e.validateTrigger??i.validateTrigger;return!r||(0,_utils2.normalizeTrigger)(r).includes(t)}):l;if(!s.length){if(!m.current[n]?.length)return!0;s=l}const c=a??p.current,o=r??(0,_utils2.getValueByName)(c,e),_=w.current?.vanForm?.validationFailed;for(const t of s){const r=runRuleValidation(t,o,c,_),a=(0,_promise.isPromiseLike)(r)?await r:r;if(b.current[n]!==u)return!0;if(a)return E(e,[a]),!1}return b.current[n]!==u||E(e,[]),!0},[E]),L=(0,_react().useCallback)(async e=>{const t=e??Object.values(v.current).map(e=>e.name);if((await Promise.all(t.map(e=>C(e)))).some(e=>!e))throw m.current;return p.current},[C]),O=(0,_react().useCallback)((e,t,r,a,n)=>{C(t,r,a,n);const u=h.current.get(e);if(u?.size)for(const e of u){const t=v.current[e];t&&C(t.name,r,(0,_utils2.getValueByName)(n,t.name),n)}},[C]),B=(0,_react().useCallback)((e,t,r)=>{const a=(0,_utils2.serializeNamePath)(e),n=p.current;if((0,_utils2.getValueByName)(n,e)===t)return;const u=(0,_utils2.setValueByName)(n,e,t);p.current=u,y.current?.(u,a,t),O(a,e,r,t,u),R({[a]:t},u)},[R,O]),S=(0,_react().useMemo)(()=>({submit:async()=>{try{const e=await L();return V.current?.(e),e}catch{return}},getFieldsValue:()=>p.current,setFieldsValue:(e,t)=>{const r=t?.validate??!1,a=p.current;let n=a;const u={};Object.keys(e).forEach(t=>{const a=e[t];(0,_utils2.getValueByName)(n,t)!==a&&(u[t]=a,n=(0,_utils2.setValueByName)(n,t,a),y.current?.(n,t,a),r&&O(t,t,void 0,a,n))}),n!==a&&(p.current=n,R(u,n))},resetFields:()=>{let e=g.current;Object.values(v.current).forEach(t=>{void 0!==t.initialValue&&void 0===(0,_utils2.getValueByName)(e,t.name)&&(e=(0,_utils2.setValueByName)(e,t.name,t.initialValue))}),p.current=e,m.current={},R({[_utils2.FORM_ALL_FIELDS_KEY]:!0},e)},validateFields:L,getFieldError:e=>m.current[(0,_utils2.serializeNamePath)(e)]??[]}),[L,O,R]);(0,_react().useImperativeHandle)(t,()=>S,[S]);const k=(0,_react().useMemo)(()=>({getFieldValue:e=>(0,_utils2.getValueByName)(p.current,e),setFieldValue:B,registerField:P,getFieldError:e=>m.current[(0,_utils2.serializeNamePath)(e)],validateField:(e,t)=>C(e,t),getFieldsValue:()=>p.current,subscribe:e=>(F.current.add(e),()=>F.current.delete(e)),form:S,colon:a,labelWidth:n,showValidateMessage:u}),[B,P,C,S,a,n,u]);return _react().default.createElement(FormContext.Provider,{value:k},_react().default.createElement(_reactNative().View,_extends({style:s},_),o,(0,_validate.isText)(c)?(0,_utils.renderTextOrNode)(c,[]):c))},InternalFormRef=_react().default.forwardRef(InternalFormImpl),InternalForm=_react().default.memo(InternalFormRef),useWatch=(e,t)=>{const r=(0,_react().useContext)(FormContext),a=void 0===e?void 0:Array.isArray(e)?e.length&&(0,_validate.isText)(e[0])?[e]:e:[e],n=(0,_react().useCallback)(e=>{const n=e??r?.getFieldsValue?.()??t?.current?.getFieldsValue?.()??{};if(!a)return n;if(1===a.length)return(0,_utils2.getValueByName)(n,a[0]);const u={};for(const e of a)u[(0,_utils2.serializeNamePath)(e)]=(0,_utils2.getValueByName)(n,e);return u},[r,t,a]),[u,i]=(0,_react().useState)(()=>n());return(0,_react().useEffect)(()=>{if(r?.subscribe)return r.subscribe((e,t)=>{_utils2.FORM_ALL_FIELDS_KEY in e?i(n(t)):a&&!a.some(t=>(0,_utils2.serializeNamePath)(t)in e)||i(n(t))})},[r,n,a]),(0,_react().useEffect)(()=>{i(n())},[n]),u};exports.useWatch=useWatch;const FormSubscribe=({to:e,children:t})=>{const r=(0,_react().useContext)(FormContext),[a,n]=(0,_react().useState)({});return(0,_react().useEffect)(()=>{if(r?.subscribe)return r.subscribe(t=>{(!e||_utils2.FORM_ALL_FIELDS_KEY in t||Object.keys(t).some(t=>e.includes(t)))&&n(t)})},[r,e]),_react().default.createElement(_react().default.Fragment,null,t(a,r?.form||null))};exports.FormSubscribe=FormSubscribe;var _default=exports.default=InternalForm;
@@ -1,12 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- Object.defineProperty(exports, "FormContext", {
7
- enumerable: true,
8
- get: function () {
9
- return _Form.FormContext;
10
- }
11
- });
12
- var _Form = require("./Form");
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),Object.defineProperty(exports,"FormContext",{enumerable:!0,get:function(){return _Form.FormContext}});var _Form=require("./Form");
@@ -1,151 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.FormItem = void 0;
7
- function _react() {
8
- const data = _interopRequireWildcard(require("react"));
9
- _react = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- var _utils = require("../../utils");
15
- var _FormContext = require("./FormContext");
16
- var _utils2 = require("./utils");
17
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
18
- const EMPTY_RULES = [];
19
- const EMPTY_VALUES = {};
20
- const FormItemImpl = ({
21
- name,
22
- label,
23
- description,
24
- intro,
25
- tooltip,
26
- rules,
27
- dependencies,
28
- valuePropName = 'value',
29
- trigger = 'onChangeText',
30
- validateTrigger,
31
- showValidateMessage,
32
- required,
33
- shouldUpdate,
34
- initialValue,
35
- children
36
- }) => {
37
- const renderProps = typeof children === 'function';
38
- const ctx = (0, _react().useContext)(_FormContext.FormContext);
39
- const normRules = rules ?? EMPTY_RULES;
40
- const nKey = name ? (0, _utils2.serializeNamePath)(name) : undefined;
41
- const shouldAlwaysUp = renderProps && !nKey && !shouldUpdate;
42
- const prevValsRef = (0, _react().useRef)(EMPTY_VALUES);
43
- const [, forceUpdate] = (0, _react().useState)(0);
44
- (0, _react().useEffect)(() => {
45
- if (!ctx?.subscribe) return undefined;
46
- return ctx.subscribe((ch, all) => {
47
- if (_utils2.FORM_ALL_FIELDS_KEY in ch) {
48
- forceUpdate(v => v + 1);
49
- return;
50
- }
51
- ;
52
- if (shouldAlwaysUp) {
53
- forceUpdate(v => v + 1);
54
- return;
55
- }
56
- ;
57
- if (shouldUpdate) {
58
- if (shouldUpdate(prevValsRef.current, all)) forceUpdate(v => v + 1);
59
- return;
60
- }
61
- ;
62
- if (nKey && nKey in ch) forceUpdate(v => v + 1);
63
- });
64
- }, [ctx, nKey, shouldUpdate, shouldAlwaysUp]);
65
- const curVals = ctx?.getFieldsValue() ?? EMPTY_VALUES;
66
- (0, _react().useEffect)(() => {
67
- prevValsRef.current = curVals;
68
- }, [curVals]);
69
- (0, _react().useEffect)(() => {
70
- if (!name || !ctx) return undefined;
71
- return ctx.registerField(name, {
72
- rules: normRules,
73
- dependencies,
74
- initialValue,
75
- validateTrigger: validateTrigger ?? trigger
76
- });
77
- }, [ctx, name, normRules, dependencies, initialValue, validateTrigger, trigger]);
78
- if (!ctx) {
79
- if (renderProps) return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children({
80
- getFieldValue: () => undefined,
81
- getFieldsValue: () => EMPTY_VALUES,
82
- form: null
83
- }));
84
- return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children);
85
- }
86
- ;
87
- const shouldRender = !shouldUpdate || shouldUpdate(prevValsRef.current, curVals);
88
- const modelVal = name ? ctx.getFieldValue(name) : undefined;
89
- const rShowMsg = showValidateMessage ?? ctx.showValidateMessage ?? true;
90
- const fieldErrs = name ? ctx.getFieldError(name) : undefined;
91
- const fieldErr = rShowMsg ? fieldErrs?.[0] : undefined;
92
- const rRequired = required ?? normRules.some(r => r.required);
93
- const rValidateTrigger = (0, _utils2.normalizeTrigger)(validateTrigger ?? trigger);
94
- if (renderProps) {
95
- if (!shouldRender) return null;
96
- return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children({
97
- getFieldValue: ctx.getFieldValue,
98
- getFieldsValue: ctx.getFieldsValue,
99
- form: ctx.form || null
100
- }));
101
- }
102
- ;
103
- if (!name) return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children);
104
- if (!shouldRender) return null;
105
- const chArr = _react().default.Children.toArray(children);
106
- if (chArr.length !== 1) return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children);
107
- const child = chArr[0];
108
- const handleChange = next => {
109
- ctx.setFieldValue(name, next, trigger);
110
- const orig = child.props[trigger];
111
- if ((0, _utils.isFunction)(orig)) orig(next);
112
- };
113
- const dispName = child.type.displayName;
114
- const isFieldLike = (0, _utils.isString)(dispName) && (dispName.includes('Field') || dispName.includes('Input'));
115
- const rValue = () => {
116
- const cv = child.props[valuePropName];
117
- if (cv !== undefined) return cv;
118
- if (modelVal !== undefined) return modelVal;
119
- if (isFieldLike && valuePropName === 'value') return '';
120
- return modelVal;
121
- };
122
- const injected = {
123
- [valuePropName]: rValue(),
124
- [trigger]: handleChange
125
- };
126
- rValidateTrigger.forEach(ev => {
127
- if (!ev || ev === trigger) return;
128
- const orig = child.props[ev];
129
- injected[ev] = (...args) => {
130
- if ((0, _utils.isFunction)(orig)) orig(...args);
131
- ctx.validateField(name, ev);
132
- };
133
- });
134
- const cp = child.props;
135
- if (label !== undefined && cp.label === undefined) injected.label = label;
136
- if (ctx.colon !== undefined && injected.label !== undefined && cp.colon === undefined) injected.colon = ctx.colon;
137
- if (ctx.labelWidth !== undefined && cp.labelWidth === undefined) injected.labelWidth = ctx.labelWidth;
138
- if (description && cp.description === undefined) injected.description = description;
139
- if (intro && cp.intro === undefined) injected.intro = intro;
140
- if (tooltip && cp.tooltip === undefined) injected.tooltip = tooltip;
141
- if (rRequired && cp.required === undefined) injected.required = true;
142
- if (fieldErr && cp.errorMessage === undefined) {
143
- injected.error = true;
144
- injected.errorMessage = fieldErr;
145
- }
146
- ;
147
- return /*#__PURE__*/_react().default.cloneElement(child, injected);
148
- };
149
- FormItemImpl.displayName = 'FormItem';
150
- const FormItem = exports.FormItem = /*#__PURE__*/_react().default.memo(FormItemImpl);
151
- var _default = exports.default = FormItem;
1
+ "use strict";function _react(){const e=_interopRequireWildcard(require("react"));return _react=function(){return e},e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=exports.FormItem=void 0;var _utils=require("../../utils"),_FormContext=require("./FormContext"),_utils2=require("./utils");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,i=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var l,o,a={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return a;if(l=t?i:r){if(l.has(e))return l.get(e);l.set(e,a)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((o=(l=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(o.get||o.set)?l(a,t,o):a[t]=e[t]);return a})(e,t)}const EMPTY_RULES=[],EMPTY_VALUES={},FormItemImpl=({name:e,label:t,description:r,intro:i,tooltip:l,rules:o,dependencies:a,valuePropName:n="value",trigger:u="onChangeText",validateTrigger:d,showValidateMessage:s,required:c,shouldUpdate:f,initialValue:_,children:m})=>{const p="function"==typeof m,F=(0,_react().useContext)(_FormContext.FormContext),g=o??EMPTY_RULES,v=e?(0,_utils2.serializeNamePath)(e):void 0,E=p&&!v&&!f,V=(0,_react().useRef)(EMPTY_VALUES),[,b]=(0,_react().useState)(0);(0,_react().useEffect)(()=>{if(F?.subscribe)return F.subscribe((e,t)=>{_utils2.FORM_ALL_FIELDS_KEY in e||E?b(e=>e+1):f?f(V.current,t)&&b(e=>e+1):v&&v in e&&b(e=>e+1)})},[F,v,f,E]);const M=F?.getFieldsValue()??EMPTY_VALUES;if((0,_react().useEffect)(()=>{V.current=M},[M]),(0,_react().useEffect)(()=>{if(e&&F)return F.registerField(e,{rules:g,dependencies:a,initialValue:_,validateTrigger:d??u})},[F,e,g,a,_,d,u]),!F)return p?_react().default.createElement(_react().default.Fragment,null,m({getFieldValue:()=>{},getFieldsValue:()=>EMPTY_VALUES,form:null})):_react().default.createElement(_react().default.Fragment,null,m);const h=!f||f(V.current,M),I=e?F.getFieldValue(e):void 0,y=s??F.showValidateMessage??!0,P=e?F.getFieldError(e):void 0,q=y?P?.[0]:void 0,x=c??g.some(e=>e.required),T=(0,_utils2.normalizeTrigger)(d??u);if(p)return h?_react().default.createElement(_react().default.Fragment,null,m({getFieldValue:F.getFieldValue,getFieldsValue:F.getFieldsValue,form:F.form||null})):null;if(!e)return _react().default.createElement(_react().default.Fragment,null,m);if(!h)return null;const W=_react().default.Children.toArray(m);if(1!==W.length)return _react().default.createElement(_react().default.Fragment,null,m);const L=W[0],S=L.type.displayName,C=(0,_utils.isString)(S)&&(S.includes("Field")||S.includes("Input")),R={[n]:(()=>{const e=L.props[n];return void 0!==e?e:void 0!==I?I:C&&"value"===n?"":I})(),[u]:t=>{F.setFieldValue(e,t,u);const r=L.props[u];(0,_utils.isFunction)(r)&&r(t)}};T.forEach(t=>{if(!t||t===u)return;const r=L.props[t];R[t]=(...i)=>{(0,_utils.isFunction)(r)&&r(...i),F.validateField(e,t)}});const U=L.props;return void 0!==t&&void 0===U.label&&(R.label=t),void 0!==F.colon&&void 0!==R.label&&void 0===U.colon&&(R.colon=F.colon),void 0!==F.labelWidth&&void 0===U.labelWidth&&(R.labelWidth=F.labelWidth),r&&void 0===U.description&&(R.description=r),i&&void 0===U.intro&&(R.intro=i),l&&void 0===U.tooltip&&(R.tooltip=l),x&&void 0===U.required&&(R.required=!0),q&&void 0===U.errorMessage&&(R.error=!0,R.errorMessage=q),_react().default.cloneElement(L,R)};FormItemImpl.displayName="FormItem";const FormItem=exports.FormItem=_react().default.memo(FormItemImpl);var _default=exports.default=FormItem;
@@ -1,95 +1 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.FormList = void 0;
7
- function _react() {
8
- const data = _interopRequireWildcard(require("react"));
9
- _react = function () {
10
- return data;
11
- };
12
- return data;
13
- }
14
- var _FormContext = require("./FormContext");
15
- var _utils = require("./utils");
16
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function (e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (const t in e) "default" !== t && {}.hasOwnProperty.call(e, t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, t)) && (i.get || i.set) ? o(f, t, i) : f[t] = e[t]); return f; })(e, t); }
17
- const getList = (context, name) => {
18
- const raw = (0, _utils.getValueByName)(context.getFieldsValue(), name);
19
- return Array.isArray(raw) ? raw : [];
20
- };
21
- const FormList = ({
22
- name,
23
- initialValue,
24
- children
25
- }) => {
26
- const ctx = (0, _react().useContext)(_FormContext.FormContext);
27
- const keyCounterRef = (0, _react().useRef)(0);
28
- const keysRef = (0, _react().useRef)([]);
29
- const nKey = (0, _utils.serializeNamePath)(name);
30
- const [listValue, setListValue] = (0, _react().useState)(() => ctx ? getList(ctx, name) : []);
31
- const syncKeys = (0, _react().useCallback)(len => {
32
- const k = keysRef.current;
33
- while (k.length < len) k.push(keyCounterRef.current++);
34
- if (k.length > len) keysRef.current = k.slice(0, len);
35
- }, []);
36
- const ensureInitial = (0, _react().useCallback)(() => {
37
- if (!ctx) return;
38
- if ((0, _utils.getValueByName)(ctx.getFieldsValue(), name) === undefined && initialValue !== undefined) ctx.setFieldValue(name, initialValue);
39
- }, [ctx, initialValue, name]);
40
- (0, _react().useEffect)(() => {
41
- ensureInitial();
42
- }, [ensureInitial]);
43
- (0, _react().useEffect)(() => {
44
- if (!ctx?.subscribe) return undefined;
45
- return ctx.subscribe((ch, all) => {
46
- if (_utils.FORM_ALL_FIELDS_KEY in ch || nKey in ch) {
47
- const next = (0, _utils.getValueByName)(all, name);
48
- const nl = Array.isArray(next) ? next : [];
49
- syncKeys(nl.length);
50
- setListValue(nl);
51
- }
52
- });
53
- }, [ctx, name, nKey, syncKeys]);
54
- const add = (0, _react().useCallback)((defaultValue, index) => {
55
- if (!ctx) return;
56
- const a = getList(ctx, name);
57
- const i = typeof index === 'number' ? index : a.length;
58
- const next = [...a];
59
- next.splice(i, 0, defaultValue);
60
- keysRef.current.splice(i, 0, keyCounterRef.current++);
61
- ctx.setFieldValue(name, next);
62
- }, [ctx, name]);
63
- const remove = (0, _react().useCallback)(index => {
64
- if (!ctx) return;
65
- const a = getList(ctx, name);
66
- if (index < 0 || index >= a.length) return;
67
- keysRef.current.splice(index, 1);
68
- ctx.setFieldValue(name, a.slice(0, index).concat(a.slice(index + 1)));
69
- }, [ctx, name]);
70
- const move = (0, _react().useCallback)((from, to) => {
71
- if (!ctx) return;
72
- const a = getList(ctx, name);
73
- if (from === to || from < 0 || to < 0 || from >= a.length || to >= a.length) return;
74
- const next = [...a];
75
- const item = next.splice(from, 1)[0];
76
- next.splice(to, 0, item);
77
- const [movedKey] = keysRef.current.splice(from, 1);
78
- keysRef.current.splice(to, 0, movedKey);
79
- ctx.setFieldValue(name, next);
80
- }, [ctx, name]);
81
- if (!ctx) return null;
82
- syncKeys(listValue.length);
83
- const fields = listValue.map((_, i) => ({
84
- name: i,
85
- key: keysRef.current[i],
86
- isListField: true
87
- }));
88
- return /*#__PURE__*/_react().default.createElement(_react().default.Fragment, null, children(fields, {
89
- add,
90
- remove,
91
- move
92
- }));
93
- };
94
- exports.FormList = FormList;
95
- FormList.displayName = 'Form.List';
1
+ "use strict";function _react(){const e=_interopRequireWildcard(require("react"));return _react=function(){return e},e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.FormList=void 0;var _FormContext=require("./FormContext"),_utils=require("./utils");function _interopRequireWildcard(e,t){if("function"==typeof WeakMap)var r=new WeakMap,i=new WeakMap;return(_interopRequireWildcard=function(e,t){if(!t&&e&&e.__esModule)return e;var n,s,u={__proto__:null,default:e};if(null===e||"object"!=typeof e&&"function"!=typeof e)return u;if(n=t?i:r){if(n.has(e))return n.get(e);n.set(e,u)}for(const t in e)"default"!==t&&{}.hasOwnProperty.call(e,t)&&((s=(n=Object.defineProperty)&&Object.getOwnPropertyDescriptor(e,t))&&(s.get||s.set)?n(u,t,s):u[t]=e[t]);return u})(e,t)}const getList=(e,t)=>{const r=(0,_utils.getValueByName)(e.getFieldsValue(),t);return Array.isArray(r)?r:[]},FormList=({name:e,initialValue:t,children:r})=>{const i=(0,_react().useContext)(_FormContext.FormContext),n=(0,_react().useRef)(0),s=(0,_react().useRef)([]),u=(0,_utils.serializeNamePath)(e),[c,a]=(0,_react().useState)(()=>i?getList(i,e):[]),l=(0,_react().useCallback)(e=>{const t=s.current;for(;t.length<e;)t.push(n.current++);t.length>e&&(s.current=t.slice(0,e))},[]),o=(0,_react().useCallback)(()=>{i&&void 0===(0,_utils.getValueByName)(i.getFieldsValue(),e)&&void 0!==t&&i.setFieldValue(e,t)},[i,t,e]);(0,_react().useEffect)(()=>{o()},[o]),(0,_react().useEffect)(()=>{if(i?.subscribe)return i.subscribe((t,r)=>{if(_utils.FORM_ALL_FIELDS_KEY in t||u in t){const t=(0,_utils.getValueByName)(r,e),i=Array.isArray(t)?t:[];l(i.length),a(i)}})},[i,e,u,l]);const _=(0,_react().useCallback)((t,r)=>{if(!i)return;const u=getList(i,e),c="number"==typeof r?r:u.length,a=[...u];a.splice(c,0,t),s.current.splice(c,0,n.current++),i.setFieldValue(e,a)},[i,e]),f=(0,_react().useCallback)(t=>{if(!i)return;const r=getList(i,e);t<0||t>=r.length||(s.current.splice(t,1),i.setFieldValue(e,r.slice(0,t).concat(r.slice(t+1))))},[i,e]),p=(0,_react().useCallback)((t,r)=>{if(!i)return;const n=getList(i,e);if(t===r||t<0||r<0||t>=n.length||r>=n.length)return;const u=[...n],c=u.splice(t,1)[0];u.splice(r,0,c);const[a]=s.current.splice(t,1);s.current.splice(r,0,a),i.setFieldValue(e,u)},[i,e]);if(!i)return null;l(c.length);const d=c.map((e,t)=>({name:t,key:s.current[t],isListField:!0}));return _react().default.createElement(_react().default.Fragment,null,r(d,{add:_,remove:f,move:p}))};exports.FormList=FormList,FormList.displayName="Form.List";