@daisu-ui/ui 0.0.0-stage → 0.1.0-beta.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 (402) hide show
  1. package/CHANGELOG.md +67 -0
  2. package/LICENSE +21 -0
  3. package/README.md +179 -2
  4. package/THIRD_PARTY_NOTICES.md +19 -0
  5. package/dist/ActionSheet.d.ts +45 -0
  6. package/dist/ActionSheet.jsx +37 -0
  7. package/dist/AnchoredBubble.d.ts +36 -0
  8. package/dist/AnchoredBubble.jsx +120 -0
  9. package/dist/Avatar.d.ts +35 -0
  10. package/dist/Avatar.jsx +29 -0
  11. package/dist/Backtop.d.ts +22 -0
  12. package/dist/Backtop.jsx +18 -0
  13. package/dist/Badge.d.ts +19 -0
  14. package/dist/Badge.jsx +11 -0
  15. package/dist/BarCode.d.ts +20 -0
  16. package/dist/BarCode.jsx +38 -0
  17. package/dist/Button.d.ts +21 -0
  18. package/dist/Button.jsx +19 -0
  19. package/dist/Calendar.d.ts +90 -0
  20. package/dist/Calendar.jsx +164 -0
  21. package/dist/CalendarView.d.ts +51 -0
  22. package/dist/CalendarView.jsx +136 -0
  23. package/dist/Card.d.ts +21 -0
  24. package/dist/Card.jsx +21 -0
  25. package/dist/Cascader.d.ts +75 -0
  26. package/dist/Cascader.jsx +212 -0
  27. package/dist/Cell.d.ts +34 -0
  28. package/dist/Cell.jsx +37 -0
  29. package/dist/Checkbox.d.ts +50 -0
  30. package/dist/Checkbox.jsx +74 -0
  31. package/dist/Circle.d.ts +19 -0
  32. package/dist/Circle.jsx +35 -0
  33. package/dist/Collapse.d.ts +31 -0
  34. package/dist/Collapse.jsx +61 -0
  35. package/dist/ConfigProvider.d.ts +15 -0
  36. package/dist/ConfigProvider.jsx +20 -0
  37. package/dist/CountDown.d.ts +20 -0
  38. package/dist/CountDown.jsx +15 -0
  39. package/dist/CountTo.d.ts +28 -0
  40. package/dist/CountTo.jsx +27 -0
  41. package/dist/Curtain.d.ts +29 -0
  42. package/dist/Curtain.jsx +51 -0
  43. package/dist/DatetimePicker.d.ts +46 -0
  44. package/dist/DatetimePicker.jsx +138 -0
  45. package/dist/DatetimePickerView.d.ts +38 -0
  46. package/dist/DatetimePickerView.jsx +36 -0
  47. package/dist/Dialog.d.ts +64 -0
  48. package/dist/Dialog.jsx +105 -0
  49. package/dist/Divider.d.ts +16 -0
  50. package/dist/Divider.jsx +9 -0
  51. package/dist/DropMenu.d.ts +55 -0
  52. package/dist/DropMenu.jsx +210 -0
  53. package/dist/Empty.d.ts +14 -0
  54. package/dist/Empty.jsx +14 -0
  55. package/dist/EmptyState.d.ts +6 -0
  56. package/dist/EmptyState.jsx +9 -0
  57. package/dist/Fab.d.ts +30 -0
  58. package/dist/Fab.jsx +127 -0
  59. package/dist/FloatingPanel.d.ts +21 -0
  60. package/dist/FloatingPanel.jsx +102 -0
  61. package/dist/Form.d.ts +63 -0
  62. package/dist/Form.jsx +108 -0
  63. package/dist/FormFieldRow.d.ts +56 -0
  64. package/dist/FormFieldRow.jsx +63 -0
  65. package/dist/Gap.d.ts +10 -0
  66. package/dist/Gap.jsx +14 -0
  67. package/dist/Grid.d.ts +47 -0
  68. package/dist/Grid.jsx +31 -0
  69. package/dist/Icon.d.ts +11 -0
  70. package/dist/Icon.jsx +12 -0
  71. package/dist/ImagePreview.d.ts +62 -0
  72. package/dist/ImagePreview.jsx +78 -0
  73. package/dist/Img.d.ts +28 -0
  74. package/dist/Img.jsx +59 -0
  75. package/dist/ImgCropper.d.ts +74 -0
  76. package/dist/ImgCropper.jsx +114 -0
  77. package/dist/IndexBar.d.ts +36 -0
  78. package/dist/IndexBar.jsx +149 -0
  79. package/dist/Input.d.ts +11 -0
  80. package/dist/Input.jsx +3 -0
  81. package/dist/InputNumber.d.ts +32 -0
  82. package/dist/InputNumber.jsx +165 -0
  83. package/dist/Keyboard.d.ts +37 -0
  84. package/dist/Keyboard.jsx +130 -0
  85. package/dist/Layout.d.ts +31 -0
  86. package/dist/Layout.jsx +14 -0
  87. package/dist/Loading.d.ts +18 -0
  88. package/dist/Loading.jsx +15 -0
  89. package/dist/Loadmore.d.ts +18 -0
  90. package/dist/Loadmore.jsx +16 -0
  91. package/dist/Navbar.d.ts +35 -0
  92. package/dist/Navbar.jsx +50 -0
  93. package/dist/NoticeBar.d.ts +30 -0
  94. package/dist/NoticeBar.jsx +86 -0
  95. package/dist/Notify.d.ts +34 -0
  96. package/dist/Notify.jsx +52 -0
  97. package/dist/NumberStepper.d.ts +11 -0
  98. package/dist/NumberStepper.jsx +41 -0
  99. package/dist/Overlay.d.ts +16 -0
  100. package/dist/Overlay.jsx +12 -0
  101. package/dist/PagedList.d.ts +13 -0
  102. package/dist/PagedList.jsx +36 -0
  103. package/dist/Pagination.d.ts +29 -0
  104. package/dist/Pagination.jsx +33 -0
  105. package/dist/PasswordInput.d.ts +16 -0
  106. package/dist/PasswordInput.jsx +20 -0
  107. package/dist/Picker.d.ts +61 -0
  108. package/dist/Picker.jsx +80 -0
  109. package/dist/PickerView.d.ts +43 -0
  110. package/dist/PickerView.jsx +142 -0
  111. package/dist/Popover.d.ts +23 -0
  112. package/dist/Popover.jsx +35 -0
  113. package/dist/Popup.d.ts +30 -0
  114. package/dist/Popup.jsx +32 -0
  115. package/dist/Progress.d.ts +17 -0
  116. package/dist/Progress.jsx +45 -0
  117. package/dist/QrCode.d.ts +46 -0
  118. package/dist/QrCode.jsx +67 -0
  119. package/dist/Radio.d.ts +21 -0
  120. package/dist/Radio.jsx +34 -0
  121. package/dist/Rate.d.ts +25 -0
  122. package/dist/Rate.jsx +39 -0
  123. package/dist/Resize.d.ts +17 -0
  124. package/dist/Resize.jsx +17 -0
  125. package/dist/RichText.d.ts +133 -0
  126. package/dist/RichText.jsx +288 -0
  127. package/dist/RootPortal.d.ts +11 -0
  128. package/dist/RootPortal.jsx +19 -0
  129. package/dist/Search.d.ts +39 -0
  130. package/dist/Search.jsx +94 -0
  131. package/dist/Segmented.d.ts +18 -0
  132. package/dist/Segmented.jsx +35 -0
  133. package/dist/SelectPicker.d.ts +54 -0
  134. package/dist/SelectPicker.jsx +136 -0
  135. package/dist/Sidebar.d.ts +34 -0
  136. package/dist/Sidebar.jsx +43 -0
  137. package/dist/Signature.d.ts +46 -0
  138. package/dist/Signature.jsx +203 -0
  139. package/dist/Skeleton.d.ts +27 -0
  140. package/dist/Skeleton.jsx +29 -0
  141. package/dist/SlideVerify.d.ts +27 -0
  142. package/dist/SlideVerify.jsx +138 -0
  143. package/dist/Slider.d.ts +21 -0
  144. package/dist/Slider.jsx +131 -0
  145. package/dist/SortButton.d.ts +16 -0
  146. package/dist/SortButton.jsx +19 -0
  147. package/dist/Steps.d.ts +23 -0
  148. package/dist/Steps.jsx +25 -0
  149. package/dist/Sticky.d.ts +17 -0
  150. package/dist/Sticky.jsx +69 -0
  151. package/dist/SwipeAction.d.ts +27 -0
  152. package/dist/SwipeAction.jsx +187 -0
  153. package/dist/Swiper.d.ts +54 -0
  154. package/dist/Swiper.jsx +94 -0
  155. package/dist/SwiperNav.d.ts +18 -0
  156. package/dist/SwiperNav.jsx +10 -0
  157. package/dist/Switch.d.ts +31 -0
  158. package/dist/Switch.jsx +46 -0
  159. package/dist/SyncedInput.d.ts +12 -0
  160. package/dist/SyncedInput.jsx +18 -0
  161. package/dist/SyncedTextarea.d.ts +11 -0
  162. package/dist/SyncedTextarea.jsx +18 -0
  163. package/dist/Tabbar.d.ts +37 -0
  164. package/dist/Tabbar.jsx +46 -0
  165. package/dist/Table.d.ts +51 -0
  166. package/dist/Table.jsx +125 -0
  167. package/dist/Tabs.d.ts +65 -0
  168. package/dist/Tabs.jsx +132 -0
  169. package/dist/Tag.d.ts +33 -0
  170. package/dist/Tag.jsx +63 -0
  171. package/dist/Text.d.ts +19 -0
  172. package/dist/Text.jsx +7 -0
  173. package/dist/TextField.d.ts +89 -0
  174. package/dist/TextField.jsx +149 -0
  175. package/dist/Textarea.d.ts +22 -0
  176. package/dist/Textarea.jsx +3 -0
  177. package/dist/Toast.d.ts +36 -0
  178. package/dist/Toast.jsx +30 -0
  179. package/dist/Tooltip.d.ts +8 -0
  180. package/dist/Tooltip.jsx +5 -0
  181. package/dist/Tour.d.ts +85 -0
  182. package/dist/Tour.jsx +150 -0
  183. package/dist/Transition.d.ts +32 -0
  184. package/dist/Transition.jsx +43 -0
  185. package/dist/Upload.d.ts +64 -0
  186. package/dist/Upload.jsx +163 -0
  187. package/dist/VideoPreview.d.ts +47 -0
  188. package/dist/VideoPreview.jsx +59 -0
  189. package/dist/Watermark.d.ts +36 -0
  190. package/dist/Watermark.jsx +18 -0
  191. package/dist/action-sheet.css +19 -0
  192. package/dist/avatar.css +23 -0
  193. package/dist/avatarModel.d.ts +8 -0
  194. package/dist/avatarModel.js +17 -0
  195. package/dist/backtop.css +6 -0
  196. package/dist/badge.css +15 -0
  197. package/dist/badgeModel.d.ts +2 -0
  198. package/dist/badgeModel.js +18 -0
  199. package/dist/bar-code.css +5 -0
  200. package/dist/barCodeModel.d.ts +80 -0
  201. package/dist/barCodeModel.js +99 -0
  202. package/dist/brand/logo.svg +8 -0
  203. package/dist/bubble.css +14 -0
  204. package/dist/bubblePosition.d.ts +19 -0
  205. package/dist/bubblePosition.js +41 -0
  206. package/dist/button.css +56 -0
  207. package/dist/calendar.css +56 -0
  208. package/dist/calendarModel.d.ts +62 -0
  209. package/dist/calendarModel.js +141 -0
  210. package/dist/card.css +8 -0
  211. package/dist/cascader.css +16 -0
  212. package/dist/cascaderModel.d.ts +21 -0
  213. package/dist/cascaderModel.js +32 -0
  214. package/dist/cell.css +41 -0
  215. package/dist/choice.css +27 -0
  216. package/dist/choice.d.ts +28 -0
  217. package/dist/choice.jsx +16 -0
  218. package/dist/circle.css +4 -0
  219. package/dist/circleModel.d.ts +15 -0
  220. package/dist/circleModel.js +31 -0
  221. package/dist/config-provider.css +2 -0
  222. package/dist/configContext.d.ts +23 -0
  223. package/dist/configContext.js +24 -0
  224. package/dist/configTheme.d.ts +3 -0
  225. package/dist/configTheme.js +22 -0
  226. package/dist/count-down.css +2 -0
  227. package/dist/count-to.css +8 -0
  228. package/dist/countDownModel.d.ts +11 -0
  229. package/dist/countDownModel.js +7 -0
  230. package/dist/countToModel.d.ts +3 -0
  231. package/dist/countToModel.js +3 -0
  232. package/dist/curtain.css +10 -0
  233. package/dist/datetime-picker.css +11 -0
  234. package/dist/datetimePickerModel.d.ts +47 -0
  235. package/dist/datetimePickerModel.js +128 -0
  236. package/dist/dialog.css +23 -0
  237. package/dist/divider.css +14 -0
  238. package/dist/drop-menu.css +28 -0
  239. package/dist/empty.css +7 -0
  240. package/dist/fab.css +23 -0
  241. package/dist/fabModel.d.ts +26 -0
  242. package/dist/fabModel.js +16 -0
  243. package/dist/floating-panel.css +6 -0
  244. package/dist/floatingPanelModel.d.ts +3 -0
  245. package/dist/floatingPanelModel.js +10 -0
  246. package/dist/form.css +10 -0
  247. package/dist/formContext.d.ts +7 -0
  248. package/dist/formContext.js +2 -0
  249. package/dist/formModel.d.ts +38 -0
  250. package/dist/formModel.js +16 -0
  251. package/dist/gap.css +1 -0
  252. package/dist/grid.css +17 -0
  253. package/dist/icon.css +8 -0
  254. package/dist/icons/LICENSE.tabler +21 -0
  255. package/dist/icons/paths.d.ts +309 -0
  256. package/dist/icons/paths.js +310 -0
  257. package/dist/icons/render.d.ts +2 -0
  258. package/dist/icons/render.js +5 -0
  259. package/dist/image-preview.css +8 -0
  260. package/dist/img-cropper.css +1 -0
  261. package/dist/img.css +5 -0
  262. package/dist/imgCropperModel.d.ts +55 -0
  263. package/dist/imgCropperModel.js +41 -0
  264. package/dist/imgModel.d.ts +13 -0
  265. package/dist/imgModel.js +22 -0
  266. package/dist/index-bar.css +12 -0
  267. package/dist/index.d.ts +200 -0
  268. package/dist/index.js +99 -0
  269. package/dist/indexBarModel.d.ts +19 -0
  270. package/dist/indexBarModel.js +37 -0
  271. package/dist/input-number.css +24 -0
  272. package/dist/inputNumberModel.d.ts +23 -0
  273. package/dist/inputNumberModel.js +40 -0
  274. package/dist/keyboard.css +26 -0
  275. package/dist/keyboardModel.d.ts +11 -0
  276. package/dist/keyboardModel.js +34 -0
  277. package/dist/layout.css +2 -0
  278. package/dist/legacy/RadioGroup.d.ts +13 -0
  279. package/dist/legacy/RadioGroup.jsx +13 -0
  280. package/dist/legacy-controls.css +87 -0
  281. package/dist/loading.css +31 -0
  282. package/dist/loadingModel.d.ts +2 -0
  283. package/dist/loadingModel.js +21 -0
  284. package/dist/loadmore.css +5 -0
  285. package/dist/navbar.css +16 -0
  286. package/dist/notice-bar.css +19 -0
  287. package/dist/notify.css +14 -0
  288. package/dist/overlay.css +2 -0
  289. package/dist/pagination.css +12 -0
  290. package/dist/paginationModel.d.ts +6 -0
  291. package/dist/paginationModel.js +7 -0
  292. package/dist/password-input.css +14 -0
  293. package/dist/passwordInputModel.d.ts +6 -0
  294. package/dist/passwordInputModel.js +11 -0
  295. package/dist/picker.css +42 -0
  296. package/dist/pickerModel.d.ts +32 -0
  297. package/dist/pickerModel.js +49 -0
  298. package/dist/popover.css +5 -0
  299. package/dist/popup.css +17 -0
  300. package/dist/progress.css +16 -0
  301. package/dist/progressModel.d.ts +12 -0
  302. package/dist/progressModel.js +19 -0
  303. package/dist/qr-code.css +4 -0
  304. package/dist/qrCodeModel.d.ts +36 -0
  305. package/dist/qrCodeModel.js +61 -0
  306. package/dist/rate.css +20 -0
  307. package/dist/rateModel.d.ts +4 -0
  308. package/dist/rateModel.js +38 -0
  309. package/dist/resize.css +2 -0
  310. package/dist/rich-text.css +19 -0
  311. package/dist/richTextMedia.d.ts +28 -0
  312. package/dist/richTextMedia.js +3 -0
  313. package/dist/richTextModel.d.ts +52 -0
  314. package/dist/richTextModel.js +195 -0
  315. package/dist/root-portal.css +1 -0
  316. package/dist/router/RouterView.d.ts +21 -0
  317. package/dist/router/RouterView.jsx +120 -0
  318. package/dist/router/core.d.ts +85 -0
  319. package/dist/router/core.js +255 -0
  320. package/dist/router/hooks.d.ts +17 -0
  321. package/dist/router/hooks.jsx +71 -0
  322. package/dist/router/index.d.ts +5 -0
  323. package/dist/router/index.js +3 -0
  324. package/dist/router/location.d.ts +8 -0
  325. package/dist/router/location.js +46 -0
  326. package/dist/router/router.css +7 -0
  327. package/dist/router/runtime.d.ts +1 -0
  328. package/dist/router/runtime.js +25 -0
  329. package/dist/search.css +23 -0
  330. package/dist/segmented.css +19 -0
  331. package/dist/segmentedModel.d.ts +10 -0
  332. package/dist/segmentedModel.js +8 -0
  333. package/dist/sidebar.css +18 -0
  334. package/dist/sidebarModel.d.ts +8 -0
  335. package/dist/sidebarModel.js +27 -0
  336. package/dist/signature.css +5 -0
  337. package/dist/signatureModel.d.ts +23 -0
  338. package/dist/signatureModel.js +80 -0
  339. package/dist/skeleton.css +16 -0
  340. package/dist/slide-verify.css +7 -0
  341. package/dist/slider.css +49 -0
  342. package/dist/sliderModel.d.ts +10 -0
  343. package/dist/sliderModel.js +27 -0
  344. package/dist/sort-button.css +12 -0
  345. package/dist/steps.css +35 -0
  346. package/dist/sticky.css +7 -0
  347. package/dist/styles.css +136 -0
  348. package/dist/styles.d.ts +1 -0
  349. package/dist/swipe-action.css +6 -0
  350. package/dist/swiper.css +27 -0
  351. package/dist/swiperAnimation.d.ts +3 -0
  352. package/dist/swiperAnimation.js +6 -0
  353. package/dist/swiperModel.d.ts +2 -0
  354. package/dist/swiperModel.js +3 -0
  355. package/dist/switch.css +12 -0
  356. package/dist/tabbar.css +17 -0
  357. package/dist/tabbarModel.d.ts +8 -0
  358. package/dist/tabbarModel.js +27 -0
  359. package/dist/table.css +21 -0
  360. package/dist/tableModel.d.ts +10 -0
  361. package/dist/tableModel.js +17 -0
  362. package/dist/tabs.css +31 -0
  363. package/dist/tabsModel.d.ts +7 -0
  364. package/dist/tabsModel.js +14 -0
  365. package/dist/tag.css +66 -0
  366. package/dist/text-field.css +15 -0
  367. package/dist/text.css +7 -0
  368. package/dist/textModel.d.ts +3 -0
  369. package/dist/textModel.js +24 -0
  370. package/dist/toast.css +13 -0
  371. package/dist/tokens.d.ts +34 -0
  372. package/dist/tokens.js +10 -0
  373. package/dist/tour.css +8 -0
  374. package/dist/transition.css +12 -0
  375. package/dist/upload.css +11 -0
  376. package/dist/useCountDown.d.ts +14 -0
  377. package/dist/useCountDown.js +73 -0
  378. package/dist/useDialog.d.ts +9 -0
  379. package/dist/useDialog.js +33 -0
  380. package/dist/useImagePreview.d.ts +7 -0
  381. package/dist/useImagePreview.js +17 -0
  382. package/dist/useNotify.d.ts +9 -0
  383. package/dist/useNotify.js +26 -0
  384. package/dist/usePressState.d.ts +6 -0
  385. package/dist/usePressState.js +17 -0
  386. package/dist/useToast.d.ts +11 -0
  387. package/dist/useToast.js +23 -0
  388. package/dist/useVideoPreview.d.ts +7 -0
  389. package/dist/useVideoPreview.js +17 -0
  390. package/dist/utils.d.ts +4 -0
  391. package/dist/utils.js +4 -0
  392. package/dist/video-preview.css +7 -0
  393. package/dist/watermark.css +6 -0
  394. package/dist/web/imgCropperElement.d.ts +2 -0
  395. package/dist/web/imgCropperElement.js +309 -0
  396. package/dist/web/index.d.ts +6 -0
  397. package/dist/web/index.js +6 -0
  398. package/dist/web/qrCodeExportElement.d.ts +4 -0
  399. package/dist/web/qrCodeExportElement.js +70 -0
  400. package/dist/web/richTextMediaElement.d.ts +2 -0
  401. package/dist/web/richTextMediaElement.js +276 -0
  402. package/package.json +98 -4
@@ -0,0 +1,187 @@
1
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
2
+ function point(event) {
3
+ 'background only';
4
+ const touch = event.touches?.[0] ?? event.changedTouches?.[0] ?? event.detail ?? event;
5
+ const x = touch.clientX ?? touch.pageX ?? touch.x, y = touch.clientY ?? touch.pageY ?? touch.y;
6
+ return Number.isFinite(x) && Number.isFinite(y) ? { x: x, y: y } : undefined;
7
+ }
8
+ export const SwipeAction = forwardRef(function SwipeAction({ value, defaultValue = 'close', disabled = false, beforeClose, onChange, onClick, left, right, children, duration = 600, className = '', style }, ref) {
9
+ const normalize = (status) => status === 'left' && left ? 'left' : status === 'right' && right ? 'right' : 'close';
10
+ const [status, setStatus] = useState(() => normalize(value ?? defaultValue));
11
+ const [widths, setWidths] = useState({ left: 0, right: 0 });
12
+ const [offset, setOffset] = useState();
13
+ const [retainSides, setRetainSides] = useState(status !== 'close');
14
+ const [dragging, setDragging] = useState(false);
15
+ const [pending, setPending] = useState(false);
16
+ const leftRef = useRef(null), rightRef = useRef(null);
17
+ const mounted = useRef(true), generation = useRef(0), busy = useRef(false);
18
+ const suppressTap = useRef(false);
19
+ const releaseTimer = useRef();
20
+ const drag = useRef();
21
+ const callbacks = useRef({ beforeClose, onChange, onClick });
22
+ callbacks.current = { beforeClose, onChange, onClick };
23
+ const live = useRef({ status, disabled, value, left: !!left, right: !!right });
24
+ live.current = { status, disabled, value, left: !!left, right: !!right };
25
+ const base = status === 'left' ? widths.left : status === 'right' ? -widths.right : 0;
26
+ const sidesVisible = status !== 'close' || offset !== undefined || retainSides;
27
+ useEffect(() => {
28
+ if (status !== 'close' || offset !== undefined) {
29
+ setRetainSides(true);
30
+ return;
31
+ }
32
+ const timer = setTimeout(() => setRetainSides(false), Number.isFinite(duration) ? Math.max(0, duration) : 600);
33
+ return () => clearTimeout(timer);
34
+ }, [status, offset, duration]);
35
+ const updateWidth = (side, width) => {
36
+ 'background only';
37
+ if (!mounted.current || !Number.isFinite(width) || width < 0)
38
+ return;
39
+ setWidths(previous => previous[side] === width ? previous : { ...previous, [side]: width });
40
+ };
41
+ useEffect(() => {
42
+ mounted.current = true;
43
+ const timer = setTimeout(() => {
44
+ for (const [side, node] of [['left', leftRef], ['right', rightRef]])
45
+ node.current?.invoke({ method: 'boundingClientRect', success: (rect) => {
46
+ 'background only';
47
+ updateWidth(side, rect.width);
48
+ } }).exec();
49
+ }, 32);
50
+ return () => { mounted.current = false; generation.current++; clearTimeout(timer); clearTimeout(releaseTimer.current); };
51
+ }, []);
52
+ const request = async (next, reason, position, fromProp = false) => {
53
+ 'background only';
54
+ if (!mounted.current || live.current.disabled && !fromProp || busy.current)
55
+ return false;
56
+ const previous = live.current.status;
57
+ next = next === 'left' && live.current.left ? 'left' : next === 'right' && live.current.right ? 'right' : 'close';
58
+ if (next === previous)
59
+ return false;
60
+ const token = ++generation.current;
61
+ if (previous !== 'close' && callbacks.current.beforeClose) {
62
+ busy.current = true;
63
+ let accepted = false;
64
+ try {
65
+ const result = callbacks.current.beforeClose(reason, position);
66
+ if (typeof result !== 'boolean')
67
+ setPending(true);
68
+ accepted = await result;
69
+ }
70
+ catch { /* A rejected guard keeps the opened side visible. */ }
71
+ if (!mounted.current || token !== generation.current)
72
+ return false;
73
+ busy.current = false;
74
+ setPending(false);
75
+ if (!accepted) {
76
+ if (fromProp)
77
+ callbacks.current.onChange?.(previous);
78
+ return false;
79
+ }
80
+ }
81
+ if (!mounted.current || token !== generation.current)
82
+ return false;
83
+ if (fromProp || live.current.value === undefined) {
84
+ live.current.status = next;
85
+ setStatus(next);
86
+ }
87
+ if (!fromProp)
88
+ callbacks.current.onChange?.(next);
89
+ if (reason === 'click' && previous !== 'close' && next === 'close')
90
+ callbacks.current.onClick?.({ value: position });
91
+ return true;
92
+ };
93
+ const requestRef = useRef(request);
94
+ requestRef.current = request;
95
+ const previousValue = useRef(value);
96
+ useEffect(() => {
97
+ if (previousValue.current === value)
98
+ return;
99
+ previousValue.current = value;
100
+ generation.current++;
101
+ busy.current = false;
102
+ setPending(false);
103
+ drag.current = undefined;
104
+ setOffset(undefined);
105
+ setDragging(false);
106
+ if (value !== undefined)
107
+ void requestRef.current(value, 'value', live.current.status === 'close' ? value === 'left' ? 'left' : 'right' : live.current.status, true);
108
+ }, [value]);
109
+ useEffect(() => {
110
+ generation.current++;
111
+ busy.current = false;
112
+ setPending(false);
113
+ drag.current = undefined;
114
+ setOffset(undefined);
115
+ setDragging(false);
116
+ if (live.current.status === 'left' && !left || live.current.status === 'right' && !right) {
117
+ live.current.status = 'close';
118
+ setStatus('close');
119
+ callbacks.current.onChange?.('close');
120
+ }
121
+ }, [disabled, !!left, !!right]);
122
+ useImperativeHandle(ref, () => ({ close: (reason = 'value', position) => {
123
+ 'background only';
124
+ const state = live.current.status;
125
+ return requestRef.current('close', reason, position ?? (state === 'close' ? 'inside' : state));
126
+ } }), []);
127
+ const start = (event) => {
128
+ 'background only';
129
+ const p = point(event);
130
+ if (!p || disabled || busy.current || drag.current)
131
+ return;
132
+ clearTimeout(releaseTimer.current);
133
+ suppressTap.current = false;
134
+ drag.current = { ...p, initial: base, next: base, active: false };
135
+ };
136
+ const move = (event) => {
137
+ 'background only';
138
+ const state = drag.current, p = point(event);
139
+ if (!state || !p || disabled)
140
+ return;
141
+ const dx = p.x - state.x, dy = p.y - state.y;
142
+ if (!state.active) {
143
+ if (Math.max(Math.abs(dx), Math.abs(dy)) < 5)
144
+ return;
145
+ if (Math.abs(dy) >= Math.abs(dx)) {
146
+ drag.current = undefined;
147
+ return;
148
+ }
149
+ state.active = true;
150
+ suppressTap.current = true;
151
+ setDragging(true);
152
+ }
153
+ state.next = Math.max(-widths.right, Math.min(widths.left, state.initial + dx));
154
+ setOffset(state.next);
155
+ };
156
+ const finish = (cancelled = false) => {
157
+ 'background only';
158
+ const state = drag.current;
159
+ if (!state)
160
+ return;
161
+ drag.current = undefined;
162
+ setDragging(false);
163
+ setOffset(undefined);
164
+ if (!state.active)
165
+ return;
166
+ clearTimeout(releaseTimer.current);
167
+ releaseTimer.current = setTimeout(() => { suppressTap.current = false; }, 250);
168
+ if (cancelled)
169
+ return;
170
+ const next = widths.left > 0 && state.next > widths.left / 2 ? 'left' : widths.right > 0 && state.next < -widths.right / 2 ? 'right' : 'close';
171
+ const current = live.current.status;
172
+ void requestRef.current(next, 'swipe', current === 'close' ? next === 'left' ? 'left' : 'right' : current);
173
+ };
174
+ const click = (position) => {
175
+ 'background only';
176
+ if (suppressTap.current || disabled || live.current.status === 'close')
177
+ return;
178
+ void requestRef.current('close', 'click', position);
179
+ };
180
+ return <view className={`ui-swipe-action ${disabled ? 'ui-swipe-action-disabled' : ''} ${pending ? 'ui-swipe-action-pending' : ''} ${className}`} style={style}>
181
+ <view className="ui-swipe-track" style={{ transform: `translateX(${offset ?? base}px)`, transitionDuration: `${dragging ? 0 : Number.isFinite(duration) ? Math.max(0, duration) : 600}ms` }} consume-slide-event={disabled ? undefined : [[-45, 45], [135, 180], [-180, -135]]} bindtouchstart={start} bindtouchmove={move} bindtouchend={() => finish()} bindtouchcancel={() => finish(true)} bindmousedown={start} global-bindmousemove={move} global-bindmouseup={() => finish()} global-bindtouchmove={move} global-bindtouchend={() => finish()} global-bindtouchcancel={() => finish(true)}>
182
+ {left ? <view ref={leftRef} flatten={false} className="ui-swipe-side ui-swipe-left" style={{ visibility: sidesVisible ? 'visible' : 'hidden' }} bindlayoutchange={event => updateWidth('left', event.detail.width)} catchtap={() => click('left')}>{left}</view> : null}
183
+ <view className="ui-swipe-body" catchtap={() => click('inside')}>{children}</view>
184
+ {right ? <view ref={rightRef} flatten={false} className="ui-swipe-side ui-swipe-right" style={{ visibility: sidesVisible ? 'visible' : 'hidden' }} bindlayoutchange={event => updateWidth('right', event.detail.width)} catchtap={() => click('right')}>{right}</view> : null}
185
+ </view>
186
+ </view>;
187
+ });
@@ -0,0 +1,54 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ import type { ImgMode } from './imgModel.js';
4
+ export type SwiperItem = string | Record<string, unknown>;
5
+ export type SwiperChangeSource = 'autoplay' | 'touch' | 'nav';
6
+ export type SwiperIndicator = {
7
+ type?: 'dots' | 'dots-bar' | 'fraction';
8
+ minShowNum?: number;
9
+ showControls?: boolean;
10
+ };
11
+ export type SwiperRef = {
12
+ swipeTo: (index: number) => void;
13
+ swipeNext: () => void;
14
+ swipePrev: () => void;
15
+ };
16
+ export type SwiperProps = {
17
+ list: readonly SwiperItem[];
18
+ current?: number;
19
+ defaultCurrent?: number;
20
+ onChange?: (current: number, source: SwiperChangeSource) => void;
21
+ onClick?: (index: number, item: SwiperItem) => void;
22
+ autoplay?: boolean;
23
+ interval?: number;
24
+ duration?: number;
25
+ loop?: boolean;
26
+ height?: number | string;
27
+ displayMultipleItems?: number;
28
+ previousMargin?: number;
29
+ nextMargin?: number;
30
+ neighborHeight?: number;
31
+ indicator?: boolean | SwiperIndicator;
32
+ indicatorPosition?: 'left' | 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right' | 'right';
33
+ valueKey?: string;
34
+ textKey?: string;
35
+ imageMode?: ImgMode;
36
+ renderItem?: (options: {
37
+ item: SwiperItem;
38
+ index: number;
39
+ }) => ReactNode;
40
+ renderIndicator?: (options: {
41
+ current: number;
42
+ total: number;
43
+ }) => ReactNode;
44
+ customIndicatorClass?: string;
45
+ customItemClass?: string;
46
+ customPrevClass?: string;
47
+ customNextClass?: string;
48
+ customTextClass?: string;
49
+ customTextStyle?: CSSProperties;
50
+ className?: string;
51
+ style?: CSSProperties;
52
+ };
53
+ /** Horizontal paging and touch animations run in lynx-ui's main-thread Swiper. */
54
+ export declare const Swiper: (props: SwiperProps & import("react").RefAttributes<SwiperRef>) => React.ReactElement | null;
@@ -0,0 +1,94 @@
1
+ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from '@lynx-js/react';
2
+ import { Swiper as NativeSwiper, SwiperItem as NativeSwiperItem } from '@lynx-js/lynx-ui';
3
+ import { SwiperNav } from "./SwiperNav.jsx";
4
+ import { Img } from "./Img.jsx";
5
+ import { imgDimension } from './imgModel.js';
6
+ import { swiperIndex, swiperNumber } from './swiperModel.js';
7
+ import { swiperCardFrame } from './swiperAnimation.js' with { runtime: 'shared' };
8
+ /** Horizontal paging and touch animations run in lynx-ui's main-thread Swiper. */
9
+ export const Swiper = forwardRef(function Swiper({ list, current, defaultCurrent = 0, onChange, onClick, autoplay = true, interval = 5000, duration = 300, loop = true, height = 192, displayMultipleItems = 1, previousMargin = 0, nextMargin = 0, neighborHeight, indicator = true, indicatorPosition = 'bottom', valueKey = 'value', textKey = 'text', imageMode = 'aspectFill', renderItem, renderIndicator, customIndicatorClass = '', customItemClass = '', customPrevClass = '', customNextClass = '', customTextClass = '', customTextStyle, className = '', style }, ref) {
10
+ const count = list.length, [inner, setInner] = useState(defaultCurrent), actual = swiperIndex(current ?? inner, count, loop), [nativeIndex, setNativeIndex] = useState(actual), [box, setBox] = useState({ width: 0, height: 0 }), [dragging, setDragging] = useState(false), native = useRef(null);
11
+ const pending = useRef(null), previousCurrent = useRef(current), draggingRef = useRef(false), latest = useRef(actual), ready = box.width > 0 && box.height > 0 && count > 0;
12
+ latest.current = actual;
13
+ const data = useMemo(() => [...list], [list]);
14
+ const before = swiperNumber(previousMargin, 0, 0, Math.max(0, box.width - 1)), after = swiperNumber(nextMargin, 0, 0, Math.max(0, box.width - before - 1)), viewport = Math.max(1, box.width - before - after), multiple = Math.max(1, Math.floor(swiperNumber(displayMultipleItems, 1, 1, Math.max(1, count)))), itemWidth = viewport / multiple;
15
+ const card = neighborHeight !== undefined, smallHeight = swiperNumber(neighborHeight, box.height, 0, box.height);
16
+ function cardAnimation(value) {
17
+ 'main thread';
18
+ return swiperCardFrame(value, box.height, smallHeight);
19
+ }
20
+ const cardFirstFrame = (value) => swiperCardFrame(value, box.height, smallHeight);
21
+ const change = (next) => {
22
+ 'background only';
23
+ const normalized = swiperIndex(next, count, loop), request = pending.current;
24
+ if (request && request.index !== normalized)
25
+ return;
26
+ pending.current = null;
27
+ draggingRef.current = false;
28
+ setDragging(false);
29
+ setNativeIndex(normalized);
30
+ if (normalized === latest.current && !request)
31
+ return;
32
+ if (current === undefined) {
33
+ latest.current = normalized;
34
+ setInner(normalized);
35
+ }
36
+ if (!request || request.notify)
37
+ onChange?.(normalized, request?.source ?? 'touch');
38
+ };
39
+ const move = (target, source = 'nav') => {
40
+ 'background only';
41
+ if (!ready || (draggingRef.current && !pending.current) || !native.current)
42
+ return;
43
+ const next = swiperIndex(target, count, loop);
44
+ if (next === latest.current)
45
+ return;
46
+ pending.current = { index: next, source, notify: true };
47
+ if (loop && target === latest.current + 1)
48
+ native.current.swipeNext();
49
+ else if (loop && target === latest.current - 1)
50
+ native.current.swipePrev();
51
+ else
52
+ native.current.swipeTo(next, { animate: true });
53
+ };
54
+ useImperativeHandle(ref, () => ({ swipeTo: index => move(index), swipeNext: () => move(latest.current + 1), swipePrev: () => move(latest.current - 1) }), [ready, count, loop, actual]);
55
+ useEffect(() => {
56
+ if (!ready || dragging)
57
+ return;
58
+ const propChanged = previousCurrent.current !== current;
59
+ previousCurrent.current = current;
60
+ if (actual === nativeIndex || pending.current?.index === actual)
61
+ return;
62
+ pending.current = { index: actual, source: 'nav', notify: propChanged };
63
+ native.current?.swipeTo(actual, { animate: propChanged });
64
+ }, [actual, current, nativeIndex, ready, count, loop, dragging]);
65
+ useEffect(() => {
66
+ if (!ready || !autoplay || dragging || count <= 1 || (!loop && actual === count - 1))
67
+ return;
68
+ const timer = setTimeout(() => move(latest.current + 1, 'autoplay'), swiperNumber(interval, 5000, 16));
69
+ return () => clearTimeout(timer);
70
+ }, [ready, autoplay, dragging, count, loop, actual, interval]);
71
+ const config = typeof indicator === 'object' ? indicator : {}, slot = (node) => typeof node === 'string' || typeof node === 'number' ? <text>{node}</text> : node;
72
+ return <view className={`ui-swiper ${card ? 'ui-swiper-card-motion' : ''} ${className}`} style={{ height: imgDimension(height, 192), ...style }} flatten={false} bindtouchstart={() => {
73
+ 'background only';
74
+ pending.current = null;
75
+ }}>
76
+ <view className="ui-swiper-measure" flatten={false} user-interaction-enabled={false} event-through bindlayoutchange={event => { const { width: w, height: h } = event.detail; if (w >= 0 && h >= 0 && Number.isFinite(w) && Number.isFinite(h))
77
+ setBox(previous => previous.width === w && previous.height === h ? previous : { width: w, height: h }); }}/>
78
+ {ready ? <view className="ui-swiper-clip"><view className="ui-swiper-native" style={{ marginLeft: `${before}px`, width: `${viewport}px`, height: `${box.height}px` }}><NativeSwiper ref={native} swiperKey={`${count}:${loop}:${viewport}:${multiple}:${box.height}`} data={data} itemWidth={itemWidth} containerWidth={viewport} itemHeight={box.height} initialIndex={actual} loop={loop && count > 1} duration={swiperNumber(duration, 300)} autoPlay={false} loopDuplicateCount={Math.min(count, Math.max(2, multiple + 1))} main-thread:customAnimation={card ? cardAnimation : undefined} customAnimationFirstScreen={card ? cardFirstFrame : undefined} experimentalHorizontalSwipeOnly mode="normal" modeConfig={{ align: 'start' }} onSwipeStart={() => {
79
+ 'background only';
80
+ draggingRef.current = true;
81
+ setDragging(true);
82
+ }} onSwipeStop={change} style={{ overflow: 'visible' }}>
83
+ {({ item, index }) => <NativeSwiperItem><view className={`ui-swiper-item ${customItemClass} ${index === swiperIndex(actual - 1, count, loop) ? customPrevClass : ''} ${index === swiperIndex(actual + 1, count, loop) ? customNextClass : ''}`} style={{ width: `${itemWidth}px`, height: card ? '100%' : `${box.height}px` }} bindtap={() => {
84
+ 'background only';
85
+ if (!draggingRef.current)
86
+ onClick?.(index, item);
87
+ }}>
88
+ {renderItem ? slot(renderItem({ item, index })) : <Img className="ui-swiper-image" width="100%" height="100%" src={typeof item === 'string' ? item : typeof item[valueKey] === 'string' ? item[valueKey] : ''} mode={imageMode} showLoading={false} showError={false}/>}
89
+ {typeof item !== 'string' && item[textKey] !== undefined ? <text className={`ui-swiper-title ${customTextClass}`} style={customTextStyle}>{String(item[textKey])}</text> : null}
90
+ </view></NativeSwiperItem>}
91
+ </NativeSwiper></view></view> : null}
92
+ {renderIndicator ? slot(renderIndicator({ current: actual, total: count })) : indicator !== false ? <SwiperNav current={actual} total={count} type={config.type} minShowNum={config.minShowNum} showControls={config.showControls} indicatorPosition={indicatorPosition} className={customIndicatorClass} hidePrev={!loop && actual === 0} hideNext={!loop && actual === count - 1} onSelect={index => move(index)} onChange={({ dir }) => move(actual + (dir === 'next' ? 1 : -1))}/> : null}
93
+ </view>;
94
+ });
@@ -0,0 +1,18 @@
1
+ import type { CSSProperties } from '@lynx-js/types';
2
+ export type SwiperNavProps = {
3
+ current?: number;
4
+ total?: number;
5
+ type?: 'dots' | 'dots-bar' | 'fraction';
6
+ indicatorPosition?: 'left' | 'top-left' | 'top' | 'top-right' | 'bottom-left' | 'bottom' | 'bottom-right' | 'right';
7
+ minShowNum?: number;
8
+ showControls?: boolean;
9
+ hidePrev?: boolean;
10
+ hideNext?: boolean;
11
+ onChange?: (event: {
12
+ dir: 'prev' | 'next';
13
+ }) => void;
14
+ onSelect?: (index: number) => void;
15
+ className?: string;
16
+ style?: CSSProperties;
17
+ };
18
+ export declare function SwiperNav({ current, total, type, indicatorPosition, minShowNum, showControls, hidePrev, hideNext, onChange, onSelect, className, style }: SwiperNavProps): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,10 @@
1
+ import { Icon } from "./Icon.jsx";
2
+ export function SwiperNav({ current = 0, total = 0, type = 'dots', indicatorPosition = 'bottom', minShowNum = 2, showControls = false, hidePrev = false, hideNext = false, onChange, onSelect, className = '', style }) {
3
+ const count = Number.isFinite(total) ? Math.max(0, Math.floor(total)) : 0, index = Number.isFinite(current) ? Math.max(0, Math.min(count - 1, Math.floor(current))) : 0;
4
+ return <>
5
+ {count >= Math.max(1, Number.isFinite(minShowNum) ? minShowNum : 2) ? <view className={`ui-swiper-indicator ui-swiper-indicator-${type} ui-swiper-indicator-${indicatorPosition} ${className}`} style={style}>
6
+ {type === 'fraction' ? <text className="ui-swiper-fraction">{`${index + 1}/${count}`}</text> : Array.from({ length: count }, (_, i) => <view key={i} className={`ui-swiper-dot ${type === 'dots-bar' ? 'ui-swiper-dot-bar' : ''} ${i === index ? 'ui-swiper-dot-active' : ''}`} catchtap={onSelect ? () => onSelect(i) : undefined}/>)}
7
+ </view> : null}
8
+ {showControls && count > 1 ? <>{!hidePrev ? <view className="ui-swiper-control ui-swiper-control-prev" catchtap={() => onChange?.({ dir: 'prev' })} accessibility-element accessibility-traits="button" accessibility-label="上一张"><Icon name="arrow-left" size={16} color="#fff"/></view> : null}{!hideNext ? <view className="ui-swiper-control ui-swiper-control-next" catchtap={() => onChange?.({ dir: 'next' })} accessibility-element accessibility-traits="button" accessibility-label="下一张"><Icon name="arrow-right" size={16} color="#fff"/></view> : null}</> : null}
9
+ </>;
10
+ }
@@ -0,0 +1,31 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ import type { LoadingProps } from "./Loading.jsx";
4
+ export type SwitchValue = boolean | string | number;
5
+ export type SwitchProps = {
6
+ value?: SwitchValue;
7
+ defaultValue?: SwitchValue;
8
+ onChange?: (event: {
9
+ value: SwitchValue;
10
+ }) => void;
11
+ activeValue?: SwitchValue;
12
+ inactiveValue?: SwitchValue;
13
+ activeColor?: string;
14
+ inactiveColor?: string;
15
+ size?: number | string;
16
+ shape?: 'round' | 'square';
17
+ disabled?: boolean;
18
+ loading?: boolean;
19
+ loadingProps?: Partial<LoadingProps>;
20
+ activeText?: string;
21
+ inactiveText?: string;
22
+ activeIcon?: string | ReactNode;
23
+ inactiveIcon?: string | ReactNode;
24
+ activeActionIcon?: string | ReactNode;
25
+ inactiveActionIcon?: string | ReactNode;
26
+ beforeChange?: (value: SwitchValue) => boolean | Promise<boolean>;
27
+ className?: string;
28
+ style?: CSSProperties;
29
+ accessibilityLabel?: string;
30
+ };
31
+ export declare function Switch({ value, defaultValue, onChange, activeValue, inactiveValue, activeColor, inactiveColor, size, shape, disabled: disabledProp, loading, loadingProps, activeText, inactiveText, activeIcon, inactiveIcon, activeActionIcon, inactiveActionIcon, beforeChange, className, style, accessibilityLabel }: SwitchProps): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,46 @@
1
+ import { FormFieldContext } from './formContext.js';
2
+ import { useContext, useEffect, useRef, useState } from '@lynx-js/react';
3
+ import { Icon } from "./Icon.jsx";
4
+ import { Loading } from "./Loading.jsx";
5
+ import { loadingDimension } from './loadingModel.js';
6
+ export function Switch({ value, defaultValue = false, onChange, activeValue = true, inactiveValue = false, activeColor, inactiveColor, size = 26, shape = 'round', disabled: disabledProp, loading = false, loadingProps, activeText = '', inactiveText = '', activeIcon, inactiveIcon, activeActionIcon, inactiveActionIcon, beforeChange, className = '', style, accessibilityLabel = '开关' }) {
7
+ const field = useContext(FormFieldContext), disabled = disabledProp ?? field?.disabled ?? false;
8
+ const [inner, setInner] = useState(defaultValue);
9
+ const [pending, setPending] = useState(false);
10
+ const sequence = useRef(0);
11
+ const busy = useRef(false);
12
+ useEffect(() => { sequence.current++; busy.current = false; setPending(false); return () => { sequence.current++; }; }, [value, activeValue, inactiveValue, disabled, loading]);
13
+ const active = (value === undefined ? inner : value) === activeValue;
14
+ const icon = active ? activeIcon : inactiveIcon;
15
+ const actionIcon = active ? activeActionIcon : inactiveActionIcon;
16
+ const toggle = async () => {
17
+ 'background only';
18
+ if (disabled || loading || busy.current)
19
+ return;
20
+ const next = active ? inactiveValue : activeValue;
21
+ const token = ++sequence.current;
22
+ busy.current = true;
23
+ try {
24
+ const decision = beforeChange?.(next) ?? true;
25
+ if (typeof decision !== 'boolean')
26
+ setPending(true);
27
+ if (!await decision || sequence.current !== token)
28
+ return;
29
+ if (value === undefined)
30
+ setInner(next);
31
+ onChange?.({ value: next });
32
+ }
33
+ catch { /* A rejected guard cancels the requested change. */ }
34
+ finally {
35
+ if (sequence.current === token) {
36
+ busy.current = false;
37
+ setPending(false);
38
+ }
39
+ }
40
+ };
41
+ const controlStyle = { '--ui-switch-size': loadingDimension(size), backgroundColor: active ? activeColor : inactiveColor, ...style };
42
+ return <view className={`ui-switch ui-switch-${shape} ${active ? 'ui-switch-active' : ''} ${disabled ? 'ui-switch-disabled' : ''} ${className}`} style={controlStyle} bindtap={() => { void toggle(); }} accessibility-element accessibility-traits="button" accessibility-label={`${accessibilityLabel},${active ? '开启' : '关闭'}`}>
43
+ <view className="ui-switch-label">{icon ? typeof icon === 'string' ? <Icon name={icon} size={13} color="#fff"/> : icon : <text>{active ? activeText : inactiveText}</text>}</view>
44
+ <view className="ui-switch-action">{loading || pending ? <Loading size={14} color={activeColor ?? '#1c64fd'} {...loadingProps}/> : actionIcon ? typeof actionIcon === 'string' ? <Icon name={actionIcon} size={16} color={active ? activeColor ?? '#1c64fd' : '#a9acb8'}/> : actionIcon : null}</view>
45
+ </view>;
46
+ }
@@ -0,0 +1,12 @@
1
+ type SyncedInputProps = {
2
+ className?: string;
3
+ value: string;
4
+ placeholder?: string;
5
+ maxlength?: number;
6
+ softInputMode?: 'unspecified' | 'nothing' | 'pan' | 'resize';
7
+ avoidKeyboard?: boolean;
8
+ onInput: (value: string) => void;
9
+ onBlur?: () => void;
10
+ };
11
+ export declare function SyncedInput({ className, value, placeholder, maxlength, softInputMode, avoidKeyboard, onInput, onBlur }: SyncedInputProps): import("@lynx-js/react").JSX.Element;
12
+ export {};
@@ -0,0 +1,18 @@
1
+ import { useEffect, useRef } from '@lynx-js/react';
2
+ export function SyncedInput({ className, value, placeholder, maxlength, softInputMode = 'nothing', avoidKeyboard = false, onInput, onBlur }) {
3
+ const inputRef = useRef(null);
4
+ const nativeValue = useRef(null);
5
+ useEffect(() => {
6
+ if (nativeValue.current === value)
7
+ return;
8
+ inputRef.current?.invoke({
9
+ method: 'setValue',
10
+ params: { value },
11
+ success: () => { nativeValue.current = value; },
12
+ }).exec();
13
+ }, [value]);
14
+ return <input ref={inputRef} className={className} default-value={value} placeholder={placeholder} maxlength={maxlength} set-soft-input-mode={softInputMode} avoid-keyboard={avoidKeyboard} bindinput={(event) => {
15
+ nativeValue.current = event.detail.value;
16
+ onInput(event.detail.value);
17
+ }} bindblur={() => onBlur?.()}/>;
18
+ }
@@ -0,0 +1,11 @@
1
+ type SyncedTextareaProps = {
2
+ className?: string;
3
+ value: string;
4
+ placeholder?: string;
5
+ maxlength?: number;
6
+ maxlines?: number;
7
+ onInput: (value: string) => void;
8
+ onBlur?: () => void;
9
+ };
10
+ export declare function SyncedTextarea({ className, value, placeholder, maxlength, maxlines, onInput, onBlur }: SyncedTextareaProps): import("@lynx-js/react").JSX.Element;
11
+ export {};
@@ -0,0 +1,18 @@
1
+ import { useEffect, useRef } from '@lynx-js/react';
2
+ export function SyncedTextarea({ className, value, placeholder, maxlength, maxlines, onInput, onBlur }) {
3
+ const textareaRef = useRef(null);
4
+ const nativeValue = useRef(null);
5
+ useEffect(() => {
6
+ if (nativeValue.current === value)
7
+ return;
8
+ textareaRef.current?.invoke({
9
+ method: 'setValue',
10
+ params: { value },
11
+ success: () => { nativeValue.current = value; },
12
+ }).exec();
13
+ }, [value]);
14
+ return <textarea ref={textareaRef} className={className} default-value={value} placeholder={placeholder} maxlength={maxlength} maxlines={maxlines} set-soft-input-mode="nothing" avoid-keyboard={false} bindinput={(event) => {
15
+ nativeValue.current = event.detail.value;
16
+ onInput(event.detail.value);
17
+ }} bindblur={() => onBlur?.()}/>;
18
+ }
@@ -0,0 +1,37 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { BadgeProps } from "./Badge.jsx";
3
+ import type { TabbarBeforeChange, TabbarValue } from './tabbarModel.js';
4
+ export type TabbarItem = {
5
+ name?: TabbarValue;
6
+ title?: string;
7
+ icon?: string;
8
+ value?: string | number;
9
+ isDot?: boolean;
10
+ max?: number;
11
+ badgeProps?: Omit<BadgeProps, 'children'>;
12
+ renderIcon?: (state: {
13
+ active: boolean;
14
+ }) => ReactNode;
15
+ children?: ReactNode;
16
+ className?: string;
17
+ };
18
+ export type TabbarProps = {
19
+ items: readonly TabbarItem[];
20
+ value?: TabbarValue;
21
+ defaultValue?: TabbarValue;
22
+ onChange?: (event: {
23
+ value: TabbarValue;
24
+ }) => void;
25
+ beforeChange?: TabbarBeforeChange;
26
+ fixed?: boolean;
27
+ placeholder?: boolean;
28
+ bordered?: boolean;
29
+ safeAreaInsetBottom?: boolean;
30
+ bottomSafeAreaHeight?: number;
31
+ shape?: 'default' | 'round';
32
+ activeColor?: string;
33
+ inactiveColor?: string;
34
+ zIndex?: number;
35
+ className?: string;
36
+ };
37
+ export declare function Tabbar({ items, value, defaultValue, onChange, beforeChange, fixed, placeholder, bordered, safeAreaInsetBottom, bottomSafeAreaHeight, shape, activeColor, inactiveColor, zIndex, className }: TabbarProps): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,46 @@
1
+ import { useEffect, useRef, useState } from '@lynx-js/react';
2
+ import { Icon } from "./Icon.jsx";
3
+ import { Badge } from "./Badge.jsx";
4
+ import { createTabbarGuard, tabbarBadge } from './tabbarModel.js';
5
+ export function Tabbar({ items, value, defaultValue = 0, onChange, beforeChange, fixed = false, placeholder = false, bordered = false, safeAreaInsetBottom = false, bottomSafeAreaHeight = 0, shape = 'default', activeColor, inactiveColor, zIndex = 10, className = '' }) {
6
+ const [inner, setInner] = useState(defaultValue);
7
+ const selected = value ?? inner;
8
+ const guard = useRef(createTabbarGuard());
9
+ const names = JSON.stringify(items.map((item, index) => item.name ?? index));
10
+ useEffect(() => { guard.current.cancel(); }, [selected, names]);
11
+ useEffect(() => () => guard.current.cancel(), []);
12
+ const change = (next) => {
13
+ 'background only';
14
+ if (next === selected) {
15
+ guard.current.cancel();
16
+ return;
17
+ }
18
+ void guard.current.request(next, beforeChange, () => {
19
+ 'background only';
20
+ if (value === undefined)
21
+ setInner(next);
22
+ onChange?.({ value: next });
23
+ });
24
+ };
25
+ const safe = safeAreaInsetBottom && Number.isFinite(bottomSafeAreaHeight) ? Math.max(0, bottomSafeAreaHeight) : 0;
26
+ const bar = <view className={`ui-tabbar ${shape === 'round' ? 'ui-tabbar-round' : bordered ? 'ui-tabbar-bordered' : ''} ${fixed ? 'ui-tabbar-fixed' : ''} ${className}`} style={{ height: `${50 + (fixed && shape === 'default' ? safe : 0)}px`, paddingBottom: `${fixed && shape === 'default' ? safe : 0}px`, ...(fixed ? { bottom: `${shape === 'round' ? safe : 0}px`, zIndex } : {}) }}>
27
+ {items.map((item, index) => {
28
+ const name = item.name ?? index;
29
+ const active = name === selected;
30
+ const color = active ? activeColor : inactiveColor;
31
+ const badge = tabbarBadge(item.value, item.badgeProps?.max ?? item.max);
32
+ return <view key={`${typeof name}:${name}`} className={`ui-tabbar-item ${active ? 'ui-tabbar-item-active' : ''} ${item.className ?? ''}`} accessibility-element accessibility-traits="button" accessibility-label={`${item.title ?? '标签'}${active ? ',已选中' : ''}`} bindtap={() => {
33
+ 'background only';
34
+ change(name);
35
+ }}>
36
+ {item.children ?? <view className="ui-tabbar-item-body">
37
+ <Badge value={badge} max={item.max ?? 99} isDot={item.isDot} showZero {...item.badgeProps} className={`ui-tabbar-item-icon ${item.badgeProps?.className ?? ''}`}>
38
+ {item.renderIcon ? item.renderIcon({ active }) : item.icon ? color ? <Icon name={item.icon} size={24} color={color}/> : active ? <><Icon className="ui-tabbar-icon-light" name={item.icon} size={24} color="#f86100"/><Icon className="ui-tabbar-icon-dark" name={item.icon} size={24} color="#ff812e"/></> : <Icon name={item.icon} size={24}/> : null}
39
+ </Badge>
40
+ {item.title ? <text className="ui-tabbar-item-title" style={color ? { color } : undefined}>{item.title}</text> : null}
41
+ </view>}
42
+ </view>;
43
+ })}
44
+ </view>;
45
+ return <>{fixed && placeholder ? <view className="ui-tabbar-placeholder" style={{ height: `${50 + safe}px` }}/> : null}{bar}</>;
46
+ }
@@ -0,0 +1,51 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ import type { SortButtonValue } from "./SortButton.jsx";
4
+ import type { TableSpan } from './tableModel.js';
5
+ export type TableColumn<T> = {
6
+ prop: keyof T & string;
7
+ label?: string;
8
+ width?: number | string;
9
+ sortable?: boolean;
10
+ fixed?: boolean;
11
+ align?: 'left' | 'center' | 'right';
12
+ render?: (scope: {
13
+ row: T;
14
+ index: number;
15
+ }) => ReactNode;
16
+ };
17
+ export type TableSortEvent<T> = Omit<TableColumn<T>, 'render'> & {
18
+ sortDirection: SortButtonValue;
19
+ };
20
+ export type TableSpanScope<T> = {
21
+ row: T;
22
+ column: TableColumn<T>;
23
+ rowIndex: number;
24
+ columnIndex: number;
25
+ };
26
+ export type TableProps<T> = {
27
+ data: readonly T[];
28
+ columns: readonly TableColumn<T>[];
29
+ border?: boolean;
30
+ stripe?: boolean;
31
+ height?: number | string;
32
+ rowHeight?: number;
33
+ showHeader?: boolean;
34
+ ellipsis?: boolean;
35
+ index?: boolean | Partial<TableColumn<T>>;
36
+ fixedHeader?: boolean;
37
+ /** Cell padding in px: one value or [vertical, horizontal]. */
38
+ cellPadding?: number | readonly [number, number];
39
+ spanMethod?: (scope: TableSpanScope<T>) => TableSpan | readonly number[] | void;
40
+ virtual?: boolean;
41
+ buffer?: number;
42
+ rowKey?: keyof T | ((row: T, index: number) => string | number);
43
+ onSortMethod?: (column: TableSortEvent<T>) => void;
44
+ onRowClick?: (event: {
45
+ rowIndex: number;
46
+ }) => void;
47
+ className?: string;
48
+ style?: CSSProperties;
49
+ };
50
+ /** Bounded tables use native scroll-views; virtual mode mounts only a buffered row window. */
51
+ export declare function Table<T>({ data, columns, border, stripe, height, rowHeight, showHeader, ellipsis, index, fixedHeader, cellPadding, spanMethod, virtual, buffer, rowKey, onSortMethod, onRowClick, className, style }: TableProps<T>): import("@lynx-js/react").JSX.Element;