@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,9 @@
1
+ export function Divider({ children, label, align = 'center', contentPosition = align, color, hairline = true, dashed = false, vertical = false, className = '', style }) {
2
+ const content = children ?? label;
3
+ const hasContent = !vertical && content !== undefined && content !== null && content !== false && content !== '';
4
+ const line = <view className="ui-divider-line"/>;
5
+ return <view className={`ui-divider ui-divider-${contentPosition} ${hasContent ? 'ui-divider-with-content' : ''} ${hairline ? 'ui-divider-hairline' : ''} ${dashed ? 'ui-divider-dashed' : ''} ${vertical ? 'ui-divider-vertical' : ''} ${className}`} style={style}>
6
+ {line}
7
+ {hasContent ? <><view className="ui-divider-content">{typeof content === 'string' || typeof content === 'number' ? <text className="ui-divider-label" style={{ color }}>{content}</text> : content}</view><view className="ui-divider-line"/></> : null}
8
+ </view>;
9
+ }
@@ -0,0 +1,55 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ export type DropMenuProps = {
4
+ zIndex?: number;
5
+ direction?: 'down' | 'up';
6
+ topOffset?: number;
7
+ modal?: boolean;
8
+ closeOnClickModal?: boolean;
9
+ duration?: number;
10
+ className?: string;
11
+ style?: CSSProperties;
12
+ children?: ReactNode;
13
+ };
14
+ export type DropMenuValue = string | number;
15
+ export type DropMenuOption = Record<string, unknown>;
16
+ export type DropMenuItemRef = {
17
+ getShowPop: () => boolean;
18
+ open: () => void;
19
+ close: () => void;
20
+ toggle: () => void;
21
+ };
22
+ export type DropMenuItemProps = {
23
+ value?: DropMenuValue;
24
+ defaultValue?: DropMenuValue;
25
+ onChange?: (event: {
26
+ value: DropMenuValue;
27
+ selectedItem: DropMenuOption;
28
+ }) => void;
29
+ options?: readonly DropMenuOption[];
30
+ disabled?: boolean;
31
+ title?: string;
32
+ icon?: string;
33
+ iconSize?: number;
34
+ iconName?: string;
35
+ activeColor?: string;
36
+ beforeToggle?: (event: {
37
+ status: boolean;
38
+ }) => boolean | Promise<boolean>;
39
+ valueKey?: string;
40
+ labelKey?: string;
41
+ tipKey?: string;
42
+ popupClassName?: string;
43
+ popupStyle?: CSSProperties;
44
+ popupHeight?: string | number;
45
+ rootPortal?: boolean;
46
+ className?: string;
47
+ style?: CSSProperties;
48
+ children?: ReactNode;
49
+ onOpen?: () => void;
50
+ onOpened?: () => void;
51
+ onClose?: () => void;
52
+ onClosed?: () => void;
53
+ };
54
+ export declare function DropMenu({ zIndex, direction, topOffset, modal, closeOnClickModal, duration, className, style, children }: DropMenuProps): import("@lynx-js/react").JSX.Element;
55
+ export declare const DropMenuItem: (props: DropMenuItemProps & import("react").RefAttributes<DropMenuItemRef>) => React.ReactElement | null;
@@ -0,0 +1,210 @@
1
+ import { createContext, forwardRef, useContext, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
2
+ import { Icon } from "./Icon.jsx";
3
+ import { Overlay } from "./Overlay.jsx";
4
+ import { RootPortal } from "./RootPortal.jsx";
5
+ import { Transition } from "./Transition.jsx";
6
+ const MenuContext = createContext(undefined);
7
+ function anchorStyle(rect, direction, topOffset = 0) {
8
+ return direction === 'down' ? { top: `${Math.max(0, rect?.bottom ?? 0)}px`, bottom: 0 } : { top: `${Math.max(0, topOffset)}px`, bottom: `calc(100% - ${Math.max(0, rect?.top ?? 0)}px)` };
9
+ }
10
+ export function DropMenu({ zIndex = 12, direction = 'down', topOffset = 0, modal = true, closeOnClickModal = true, duration = 200, className = '', style, children }) {
11
+ const node = useRef(null);
12
+ const [active, setActive] = useState();
13
+ const [rect, setRect] = useState();
14
+ const activeRef = useRef();
15
+ const lastPortal = useRef(false);
16
+ const generation = useRef(0);
17
+ const measure = () => {
18
+ 'background only';
19
+ return new Promise(resolve => {
20
+ if (!node.current) {
21
+ resolve(undefined);
22
+ return;
23
+ }
24
+ node.current.invoke({ method: 'boundingClientRect', params: { androidEnableTransformProps: true, iosEnableTransformProps: true }, success: (result) => {
25
+ 'background only';
26
+ const value = result;
27
+ resolve(value && typeof value.top === 'number' && typeof value.bottom === 'number' && Number.isFinite(value.top) && Number.isFinite(value.bottom) ? { top: value.top, bottom: value.bottom } : undefined);
28
+ }, fail: () => resolve(undefined) }).exec();
29
+ });
30
+ };
31
+ const close = (id) => {
32
+ 'background only';
33
+ if (activeRef.current?.id === id) {
34
+ activeRef.current = undefined;
35
+ setActive(undefined);
36
+ }
37
+ };
38
+ useEffect(() => () => { generation.current++; activeRef.current = undefined; }, []);
39
+ const context = {
40
+ active: active?.id, rect, direction, topOffset, duration, zIndex,
41
+ claim: () => {
42
+ 'background only';
43
+ return ++generation.current;
44
+ },
45
+ isCurrent: ticket => {
46
+ 'background only';
47
+ return ticket === generation.current;
48
+ },
49
+ measure,
50
+ activate: (item, nextRect) => {
51
+ 'background only';
52
+ lastPortal.current = item.portal;
53
+ activeRef.current = item;
54
+ setRect(nextRect);
55
+ setActive(item);
56
+ },
57
+ close,
58
+ };
59
+ return <MenuContext.Provider value={context}>
60
+ <view ref={node} flatten={false} className={`ui-drop-menu ${className}`} style={style} bindlayoutchange={() => {
61
+ 'background only';
62
+ const current = activeRef.current;
63
+ if (current)
64
+ void measure().then(next => {
65
+ 'background only';
66
+ if (next && current === activeRef.current)
67
+ setRect(next);
68
+ });
69
+ }}>{children}</view>
70
+ {modal ? <Overlay show={!!active} rootPortal={lastPortal.current} zIndex={zIndex} duration={duration} style={anchorStyle(rect, direction, topOffset)} onTap={() => {
71
+ 'background only';
72
+ if (closeOnClickModal)
73
+ activeRef.current?.close();
74
+ }}/> : null}
75
+ </MenuContext.Provider>;
76
+ }
77
+ function SelectedIcon({ name, size, color }) {
78
+ return color ? <Icon name={name} size={size} color={color}/> : <><Icon name={name} size={size} color="#f86100" className="ui-drop-menu-primary-light"/><Icon name={name} size={size} color="#ff812e" className="ui-drop-menu-primary-dark"/></>;
79
+ }
80
+ export const DropMenuItem = forwardRef(function DropMenuItem({ value, defaultValue, onChange, options = [], disabled = false, title, icon = 'caret-down', iconSize = 16, iconName = 'check', activeColor, beforeToggle, valueKey = 'value', labelKey = 'label', tipKey = 'tip', popupClassName = '', popupStyle, popupHeight, rootPortal = false, className = '', style, children, onOpen, onOpened, onClose, onClosed }, ref) {
81
+ const menu = useContext(MenuContext);
82
+ if (!menu)
83
+ throw new Error('DropMenuItem requires a DropMenu parent.');
84
+ const id = useRef({}).current;
85
+ const [inner, setInner] = useState(defaultValue);
86
+ const [present, setPresent] = useState(false);
87
+ const [hidden, setHidden] = useState(true);
88
+ const [height, setHeight] = useState(0);
89
+ const show = menu.active === id;
90
+ const current = value === undefined ? inner : value;
91
+ const selected = options.find(item => item[valueKey] === current);
92
+ const label = title ?? String(selected?.[labelKey] ?? '');
93
+ const requestId = useRef(0);
94
+ const pending = useRef(undefined);
95
+ const latest = useRef({ menu, disabled, show, beforeToggle, rootPortal });
96
+ latest.current = { menu, disabled, show, beforeToggle, rootPortal };
97
+ const requestRef = useRef(() => { });
98
+ const request = (status) => {
99
+ 'background only';
100
+ const state = latest.current;
101
+ if (state.disabled || pending.current === status)
102
+ return;
103
+ if (state.show === status) {
104
+ requestId.current++;
105
+ pending.current = undefined;
106
+ return;
107
+ }
108
+ const sequence = ++requestId.current;
109
+ pending.current = status;
110
+ const ticket = status ? state.menu.claim() : undefined;
111
+ const valid = () => sequence === requestId.current && !latest.current.disabled && (ticket === undefined || latest.current.menu.isCurrent(ticket));
112
+ void (async () => {
113
+ try {
114
+ if (state.beforeToggle && !await state.beforeToggle({ status }))
115
+ return;
116
+ if (!valid())
117
+ return;
118
+ if (status) {
119
+ const nextRect = await latest.current.menu.measure();
120
+ if (!nextRect || !valid())
121
+ return;
122
+ setPresent(true);
123
+ setHidden(false);
124
+ latest.current.menu.activate({ id, portal: latest.current.rootPortal, close: () => {
125
+ 'background only';
126
+ requestRef.current(false);
127
+ } }, nextRect);
128
+ }
129
+ else
130
+ latest.current.menu.close(id);
131
+ }
132
+ catch { /* A rejected guard cancels only this item's request. */ }
133
+ finally {
134
+ if (sequence === requestId.current)
135
+ pending.current = undefined;
136
+ }
137
+ })();
138
+ };
139
+ requestRef.current = request;
140
+ useEffect(() => {
141
+ if (disabled) {
142
+ requestId.current++;
143
+ pending.current = undefined;
144
+ menu.close(id);
145
+ }
146
+ }, [disabled]);
147
+ useEffect(() => () => { requestId.current++; latest.current.menu.close(id); }, []);
148
+ useImperativeHandle(ref, () => ({
149
+ getShowPop: () => {
150
+ 'background only';
151
+ return latest.current.show;
152
+ },
153
+ open: () => {
154
+ 'background only';
155
+ requestRef.current(true);
156
+ },
157
+ close: () => {
158
+ 'background only';
159
+ requestRef.current(false);
160
+ },
161
+ toggle: () => {
162
+ 'background only';
163
+ requestRef.current(!(pending.current ?? latest.current.show));
164
+ },
165
+ }), []);
166
+ const select = (option) => {
167
+ 'background only';
168
+ const next = option[valueKey];
169
+ if (!latest.current.show || disabled || typeof next !== 'string' && typeof next !== 'number')
170
+ return;
171
+ if (next !== current) {
172
+ if (value === undefined)
173
+ setInner(next);
174
+ onChange?.({ value: next, selectedItem: option });
175
+ }
176
+ request(false);
177
+ };
178
+ const layer = present ? <view className={`ui-drop-menu-layer ui-drop-menu-layer-${menu.direction}`} style={{ ...anchorStyle(menu.rect, menu.direction, menu.topOffset), zIndex: menu.zIndex + 1, display: hidden ? 'none' : 'flex' }} event-through>
179
+ <Transition show={show} name={menu.direction === 'down' ? 'slide-down' : 'slide-up'} duration={menu.duration} lazyRender destroy={false} interactiveDuringLeave className={`ui-drop-menu-popup ${popupClassName}`} style={popupStyle} onBeforeEnter={onOpen} onAfterEnter={onOpened} onBeforeLeave={onClose} onAfterLeave={() => {
180
+ 'background only';
181
+ setHidden(true);
182
+ onClosed?.();
183
+ }}>
184
+ <scroll-view className="ui-drop-menu-scroll" scroll-orientation="vertical" scroll-y scroll-bar-enable={false} style={{ height: popupHeight === undefined ? `${height}px` : typeof popupHeight === 'number' ? `${Math.max(0, popupHeight)}px` : popupHeight }}>
185
+ <view className="ui-drop-menu-content" flatten={false} bindlayoutchange={event => {
186
+ 'background only';
187
+ const next = event.detail.height;
188
+ if (Number.isFinite(next) && next !== height)
189
+ setHeight(next);
190
+ }} catchtap={() => { }}>
191
+ {children ?? <view className="ui-drop-menu-options">
192
+ {options.map((option, index) => {
193
+ const active = option[valueKey] === current;
194
+ return <view key={`${typeof option[valueKey]}:${String(option[valueKey])}:${index}`} className={`ui-drop-menu-option ${active ? 'ui-drop-menu-option-selected' : ''}`} bindtap={() => select(option)} accessibility-element accessibility-traits="button" accessibility-label={`${String(option[labelKey] ?? '')}${active ? ',已选中' : ''}`}>
195
+ <view className="ui-drop-menu-option-copy"><text className="ui-drop-menu-option-label" style={active ? { color: activeColor } : undefined} text-maxline="1" text-overflow="ellipsis">{String(option[labelKey] ?? '')}</text>{option[tipKey] ? <text className="ui-drop-menu-option-tip" style={active ? { color: activeColor } : undefined} text-maxline="1" text-overflow="ellipsis">{String(option[tipKey])}</text> : null}</view>
196
+ {active && iconName ? <SelectedIcon name={iconName} size={20} color={activeColor}/> : null}
197
+ </view>;
198
+ })}
199
+ </view>}
200
+ </view>
201
+ </scroll-view>
202
+ </Transition>
203
+ </view> : null;
204
+ return <>
205
+ <view className={`ui-drop-menu-item ${show ? 'ui-drop-menu-item-open' : ''} ${disabled ? 'ui-drop-menu-item-disabled' : ''} ${className}`} style={style} catchtap={() => request(!(pending.current ?? show))} accessibility-element accessibility-traits="button" accessibility-label={`${label}${disabled ? ',已禁用' : show ? ',已展开' : ',已折叠'}`}>
206
+ <view className="ui-drop-menu-title"><text className="ui-drop-menu-title-text" style={show ? { color: activeColor } : undefined} text-maxline="1" text-overflow="ellipsis">{label}</text>{icon ? <view className="ui-drop-menu-arrow" style={{ transform: `rotate(${show ? 180 : 0}deg)`, transitionDuration: `${menu.duration}ms` }}>{show ? <SelectedIcon name={icon} size={iconSize} color={activeColor}/> : <><Icon name={icon} size={iconSize} color="#868a9c" className="ui-drop-menu-primary-light"/><Icon name={icon} size={iconSize} color="#a9acb8" className="ui-drop-menu-primary-dark"/></>}</view> : null}</view>
207
+ </view>
208
+ {rootPortal ? <RootPortal>{layer}</RootPortal> : layer}
209
+ </>;
210
+ });
@@ -0,0 +1,14 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ export type EmptyProps = {
4
+ icon?: string;
5
+ iconSize?: number | string;
6
+ iconColor?: string;
7
+ tip?: ReactNode;
8
+ image?: ReactNode;
9
+ bottom?: ReactNode;
10
+ className?: string;
11
+ style?: CSSProperties;
12
+ };
13
+ /** Empty uses SVG glyphs; the business EmptyState remains independent. */
14
+ export declare function Empty({ icon, iconSize, iconColor, tip, image, bottom, className, style }: EmptyProps): import("@lynx-js/react").JSX.Element;
package/dist/Empty.jsx ADDED
@@ -0,0 +1,14 @@
1
+ import { Icon } from "./Icon.jsx";
2
+ import { imgDimension } from './imgModel.js';
3
+ /** Empty uses SVG glyphs; the business EmptyState remains independent. */
4
+ export function Empty({ icon = 'empty', iconSize = 98, iconColor, tip, image, bottom, className = '', style }) {
5
+ const dimension = imgDimension(iconSize, 98);
6
+ const customImage = image !== undefined && image !== null;
7
+ return <view className={`ui-empty ${className}`} style={style}>
8
+ {customImage ? typeof image === 'string' || typeof image === 'number' ? <text>{image}</text> : image : <view className="ui-empty-icon" style={{ width: dimension, height: dimension }}>
9
+ {iconColor ? <Icon name={icon} size={1} color={iconColor} className="ui-empty-glyph"/> : <><Icon name={icon} size={1} color="#c9cbd4" className="ui-empty-glyph ui-empty-glyph-light"/><Icon name={icon} size={1} color="#4e5369" className="ui-empty-glyph ui-empty-glyph-dark"/></>}
10
+ </view>}
11
+ {tip !== undefined && tip !== null && tip !== false && tip !== '' ? typeof tip === 'string' || typeof tip === 'number' ? <text className="ui-empty-tip">{tip}</text> : <view className="ui-empty-tip">{tip}</view> : null}
12
+ {bottom !== undefined && bottom !== null && bottom !== false ? typeof bottom === 'string' || typeof bottom === 'number' ? <text>{bottom}</text> : bottom : null}
13
+ </view>;
14
+ }
@@ -0,0 +1,6 @@
1
+ export declare function EmptyState({ title, description, actionLabel, onAction }: {
2
+ title?: string;
3
+ description?: string;
4
+ actionLabel?: string;
5
+ onAction?: () => void;
6
+ }): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,9 @@
1
+ import { Button } from "./Button.jsx";
2
+ export function EmptyState({ title = '暂无数据', description, actionLabel, onAction }) {
3
+ return <view className="ui-empty-state">
4
+ <view className="ui-empty-mark"><view className="ui-empty-mark-line"/></view>
5
+ <text className="ui-empty-title">{title}</text>
6
+ {description ? <text className="ui-empty-description">{description}</text> : null}
7
+ {actionLabel ? <view className="ui-empty-action"><Button label={actionLabel} variant="plain" size="small" onTap={onAction}/></view> : null}
8
+ </view>;
9
+ }
package/dist/Fab.d.ts ADDED
@@ -0,0 +1,30 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { ButtonTone } from "./Button.jsx";
3
+ import type { FabDirection, FabGap, FabPosition } from './fabModel.js';
4
+ export type FabProps = {
5
+ active?: boolean;
6
+ defaultActive?: boolean;
7
+ onActiveChange?: (active: boolean) => void;
8
+ type?: ButtonTone | 'default' | 'error';
9
+ position?: FabPosition;
10
+ direction?: FabDirection;
11
+ disabled?: boolean;
12
+ draggable?: boolean;
13
+ expandable?: boolean;
14
+ inactiveIcon?: string;
15
+ activeIcon?: string;
16
+ zIndex?: number;
17
+ gap?: FabGap;
18
+ className?: string;
19
+ children?: ReactNode;
20
+ trigger?: ReactNode | ((state: {
21
+ active: boolean;
22
+ disabled: boolean;
23
+ }) => ReactNode);
24
+ onTap?: () => void;
25
+ };
26
+ export type FabRef = {
27
+ open: () => void;
28
+ close: () => void;
29
+ };
30
+ export declare const Fab: (props: FabProps & import("react").RefAttributes<FabRef>) => React.ReactElement | null;
package/dist/Fab.jsx ADDED
@@ -0,0 +1,127 @@
1
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
2
+ import { Button } from "./Button.jsx";
3
+ import { Icon } from "./Icon.jsx";
4
+ import { Transition } from "./Transition.jsx";
5
+ import { clampFab, fabBounds, fabPosition, snapFab } from './fabModel.js';
6
+ const pointOf = (event, end = false) => {
7
+ const p = (end ? event.changedTouches?.[0] : event.touches?.[0]) ?? event;
8
+ const x = p.clientX ?? p.x, y = p.clientY ?? p.y;
9
+ return Number.isFinite(x) && Number.isFinite(y) ? { x: x, y: y } : null;
10
+ };
11
+ export const Fab = forwardRef(function Fab({ active, defaultActive = false, onActiveChange, type = 'primary', position = 'right-bottom', direction = 'top', disabled = false, draggable = false, expandable = true, inactiveIcon = 'add', activeIcon = 'close', zIndex = 99, gap = {}, className = '', children, trigger, onTap }, ref) {
12
+ const [inner, setInner] = useState(defaultActive);
13
+ const expanded = active ?? inner;
14
+ const [viewport, setViewport] = useState({ width: 0, height: 0 });
15
+ const [size, setSize] = useState({ width: 60, height: 60 });
16
+ const [location, setLocation] = useState({ x: 0, y: 0 });
17
+ const [dragDirection, setDragDirection] = useState(null);
18
+ const [attract, setAttract] = useState(false);
19
+ const drag = useRef(null);
20
+ const suppressTap = useRef(false);
21
+ const bounds = fabBounds(viewport.width, viewport.height, size.width, size.height, gap);
22
+ useEffect(() => { setLocation(fabPosition(position, bounds)); setDragDirection(null); setAttract(false); drag.current = null; }, [position, viewport.width, viewport.height, size.width, size.height, gap.top, gap.left, gap.right, gap.bottom]);
23
+ useEffect(() => { if (disabled || !draggable)
24
+ drag.current = null; }, [disabled, draggable]);
25
+ const update = (next) => {
26
+ 'background only';
27
+ if (next && (disabled || !expandable))
28
+ return;
29
+ if (next === expanded)
30
+ return;
31
+ if (active === undefined)
32
+ setInner(next);
33
+ onActiveChange?.(next);
34
+ };
35
+ useImperativeHandle(ref, () => ({ open: () => {
36
+ 'background only';
37
+ update(true);
38
+ }, close: () => {
39
+ 'background only';
40
+ update(false);
41
+ } }), [active, expanded, disabled, expandable, onActiveChange]);
42
+ const start = (event) => {
43
+ 'background only';
44
+ suppressTap.current = false;
45
+ const point = pointOf(event);
46
+ if (!draggable || disabled || !point)
47
+ return;
48
+ drag.current = { start: point, origin: location, last: location, moved: false };
49
+ setAttract(false);
50
+ };
51
+ const move = (event, end = false) => {
52
+ 'background only';
53
+ const state = drag.current, point = pointOf(event, end);
54
+ if (!state || !point)
55
+ return;
56
+ if (Math.abs(point.x - state.start.x) + Math.abs(point.y - state.start.y) > 5)
57
+ state.moved = true;
58
+ if (!state.moved)
59
+ return;
60
+ suppressTap.current = true;
61
+ state.last = clampFab({ x: state.origin.x + point.x - state.start.x, y: state.origin.y + point.y - state.start.y }, bounds);
62
+ setLocation(state.last);
63
+ };
64
+ const finish = (event, cancel = false) => {
65
+ 'background only';
66
+ if (!cancel)
67
+ move(event, true);
68
+ const state = drag.current;
69
+ drag.current = null;
70
+ if (!state?.moved)
71
+ return;
72
+ const snap = snapFab(state.last, bounds);
73
+ setAttract(true);
74
+ setLocation({ x: snap.x, y: snap.y });
75
+ setDragDirection(snap.direction);
76
+ };
77
+ const toggle = () => {
78
+ 'background only';
79
+ if (disabled || suppressTap.current)
80
+ return;
81
+ if (expandable)
82
+ update(!expanded);
83
+ else
84
+ onTap?.();
85
+ };
86
+ const menuDirection = draggable && dragDirection ? dragDirection : direction;
87
+ const tone = type === 'error' ? 'danger' : type === 'default' ? 'neutral' : type;
88
+ return <>
89
+ <view className="ui-fab-viewport" flatten={false} user-interaction-enabled={false} bindlayoutchange={event => {
90
+ 'background only';
91
+ const { width } = event.detail;
92
+ setViewport(old => old.width === width ? old : { ...old, width });
93
+ }}/>
94
+ <view className="ui-fab-viewport ui-fab-viewport-vertical" flatten={false} user-interaction-enabled={false} bindlayoutchange={event => {
95
+ 'background only';
96
+ const { height } = event.detail;
97
+ setViewport(old => old.height === height ? old : { ...old, height });
98
+ }}/>
99
+ <view className={`ui-fab ${draggable ? 'ui-fab-draggable' : ''} ${disabled ? 'ui-fab-disabled' : ''} ${className}`} style={{ left: `${location.x}px`, top: `${location.y}px`, zIndex, visibility: viewport.width && viewport.height ? 'visible' : 'hidden', transitionDuration: attract ? '300ms' : '0ms' }} catchtap={() => {
100
+ 'background only';
101
+ }}>
102
+ <view className="ui-fab-trigger" flatten={false} bindlayoutchange={event => {
103
+ 'background only';
104
+ const { width, height } = event.detail;
105
+ setSize(old => old.width === width && old.height === height ? old : { width, height });
106
+ }} bindtap={toggle} bindtouchstart={start} catchtouchmove={event => {
107
+ 'background only';
108
+ move(event);
109
+ }} bindtouchend={event => {
110
+ 'background only';
111
+ finish(event);
112
+ }} bindtouchcancel={event => {
113
+ 'background only';
114
+ finish(event, true);
115
+ }} bindmousedown={start} global-bindmousemove={draggable ? event => {
116
+ 'background only';
117
+ move(event);
118
+ } : undefined} global-bindmouseup={draggable ? event => {
119
+ 'background only';
120
+ finish(event);
121
+ } : undefined} consume-slide-event={draggable ? [[0, 360]] : undefined}>
122
+ {trigger ? typeof trigger === 'function' ? trigger({ active: expanded, disabled }) : trigger : <Button className="ui-fab-default-trigger" tone={tone} round disabled={disabled} icon={<Icon name={expanded ? activeIcon : inactiveIcon === 'add' ? 'plus' : inactiveIcon} size={32} color={tone === 'neutral' ? '#4e5369' : '#fff'}/>} accessibilityLabel={expanded ? '收起动作菜单' : '展开动作菜单'}/>}
123
+ </view>
124
+ {expandable ? <Transition show={expanded} name={[]} className={`ui-fab-actions ui-fab-actions-${menuDirection}`} enterClassName={`ui-fab-offset-${menuDirection}`} leaveToClassName={`ui-fab-offset-${menuDirection}`} enterActiveClassName="ui-fab-actions-animating" leaveActiveClassName="ui-fab-actions-animating"><view className="ui-fab-action-content" user-interaction-enabled={!disabled}>{children}</view></Transition> : null}
125
+ </view>
126
+ </>;
127
+ });
@@ -0,0 +1,21 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ export type FloatingPanelProps = {
4
+ height?: number;
5
+ defaultHeight?: number;
6
+ anchors?: readonly number[];
7
+ duration?: number;
8
+ contentDraggable?: boolean;
9
+ safeAreaInsetBottom?: boolean;
10
+ safeAreaBottom?: number;
11
+ showScrollbar?: boolean;
12
+ zIndex?: number;
13
+ rootPortal?: boolean;
14
+ onHeightChange?: (event: {
15
+ height: number;
16
+ }) => void;
17
+ className?: string;
18
+ style?: CSSProperties;
19
+ children?: ReactNode;
20
+ };
21
+ export declare function FloatingPanel({ height, defaultHeight, anchors: anchorProps, duration, contentDraggable, safeAreaInsetBottom, safeAreaBottom, showScrollbar, zIndex, rootPortal, onHeightChange, className, style, children }: FloatingPanelProps): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,102 @@
1
+ import { useEffect, useRef, useState } from '@lynx-js/react';
2
+ import { RootPortal } from "./RootPortal.jsx";
3
+ import { nearestPanelAnchor, panelAnchors, panelHeight } from './floatingPanelModel.js';
4
+ function point(event) {
5
+ 'background only';
6
+ const touch = event.touches?.[0] ?? event.changedTouches?.[0] ?? event.detail ?? event;
7
+ const x = touch.clientX ?? touch.pageX ?? touch.x, y = touch.clientY ?? touch.pageY ?? touch.y;
8
+ return Number.isFinite(x) && Number.isFinite(y) ? { x: x, y: y } : undefined;
9
+ }
10
+ export function FloatingPanel({ height, defaultHeight = 0, anchors: anchorProps, duration = 300, contentDraggable = true, safeAreaInsetBottom = false, safeAreaBottom = 0, showScrollbar = true, zIndex = 10, rootPortal = false, onHeightChange, className = '', style, children }) {
11
+ const viewport = useRef(null);
12
+ const scroll = useRef(null);
13
+ const scrollTop = useRef(0);
14
+ const [viewportHeight, setViewportHeight] = useState(0);
15
+ const [inner, setInner] = useState(defaultHeight);
16
+ const [dragHeight, setDragHeight] = useState();
17
+ const [dragging, setDragging] = useState(false);
18
+ const anchors = panelAnchors(anchorProps, viewportHeight);
19
+ const key = anchors.join(',');
20
+ const max = anchors[anchors.length - 1];
21
+ const current = panelHeight(height ?? inner, anchors);
22
+ const shownHeight = dragHeight ?? current;
23
+ const atMax = shownHeight >= max - .5;
24
+ const drag = useRef();
25
+ const measured = (value) => {
26
+ 'background only';
27
+ if (Number.isFinite(value) && value > 0)
28
+ setViewportHeight(value);
29
+ };
30
+ useEffect(() => {
31
+ let cancelled = false;
32
+ const timer = setTimeout(() => viewport.current?.invoke({ method: 'boundingClientRect', success: (value) => {
33
+ 'background only';
34
+ if (!cancelled)
35
+ measured(value.height);
36
+ } }).exec(), 32);
37
+ return () => { cancelled = true; clearTimeout(timer); };
38
+ }, []);
39
+ useEffect(() => { drag.current = undefined; setDragging(false); setDragHeight(undefined); }, [height, key, contentDraggable]);
40
+ useEffect(() => {
41
+ if (!atMax && scrollTop.current > 0) {
42
+ scrollTop.current = 0;
43
+ scroll.current?.invoke({ method: 'scrollTo', params: { offset: 0, smooth: false } }).exec();
44
+ }
45
+ }, [atMax]);
46
+ const start = (event, source) => {
47
+ 'background only';
48
+ const p = point(event);
49
+ if (!p || source === 'content' && !contentDraggable || drag.current)
50
+ return;
51
+ drag.current = { ...p, height: current, next: current, source, active: false };
52
+ };
53
+ const move = (event) => {
54
+ 'background only';
55
+ const state = drag.current, p = point(event);
56
+ if (!state || !p)
57
+ return;
58
+ const dy = p.y - state.y, dx = p.x - state.x;
59
+ if (!state.active) {
60
+ if (Math.max(Math.abs(dy), Math.abs(dx)) < 5)
61
+ return;
62
+ if (Math.abs(dx) >= Math.abs(dy) || state.source === 'content' && (scrollTop.current > 0 || state.height >= max - .5 && dy < 0)) {
63
+ drag.current = undefined;
64
+ return;
65
+ }
66
+ state.active = true;
67
+ setDragging(true);
68
+ }
69
+ state.next = panelHeight(state.height - dy, anchors);
70
+ setDragHeight(state.next);
71
+ };
72
+ const finish = (cancelled = false) => {
73
+ 'background only';
74
+ const state = drag.current;
75
+ if (!state)
76
+ return;
77
+ drag.current = undefined;
78
+ setDragging(false);
79
+ setDragHeight(undefined);
80
+ if (!state.active || cancelled)
81
+ return;
82
+ const next = nearestPanelAnchor(state.next, anchors);
83
+ if (height === undefined)
84
+ setInner(next);
85
+ if (next !== current)
86
+ onHeightChange?.({ height: next });
87
+ };
88
+ const inset = safeAreaInsetBottom && Number.isFinite(safeAreaBottom) ? Math.max(0, safeAreaBottom) : 0;
89
+ const layer = <>
90
+ <view ref={viewport} flatten={false} className="ui-floating-panel-viewport" bindlayoutchange={event => measured(event.detail.height)}/>
91
+ <view className={`ui-floating-panel ${className}`} style={{ ...style, height: `${max}px`, transform: `translateY(${max - shownHeight}px)`, transitionDuration: `${dragging ? 0 : Math.max(0, Number.isFinite(duration) ? duration : 300)}ms`, paddingBottom: `${inset}px`, zIndex }}>
92
+ <view className="ui-floating-panel-header" consume-slide-event={[[-180, 180]]} catchtouchstart={event => start(event, 'header')} catchtouchmove={move} catchtouchend={() => finish()} catchtouchcancel={() => finish(true)} catchmousedown={event => start(event, 'header')} global-bindmousemove={move} global-bindmouseup={() => finish()} global-bindtouchmove={move} global-bindtouchend={() => finish()} global-bindtouchcancel={() => finish(true)} accessibility-element accessibility-traits="adjustable" accessibility-label={`浮动面板,高度${Math.round(shownHeight)}`}><view className="ui-floating-panel-bar"/></view>
93
+ <scroll-view ref={scroll} className="ui-floating-panel-scroll" scroll-orientation="vertical" scroll-bar-enable={showScrollbar} enable-scroll={!contentDraggable || atMax && !dragging} bounces={false} bindscroll={event => {
94
+ 'background only';
95
+ scrollTop.current = Math.max(0, event.detail.scrollTop);
96
+ }}>
97
+ <view className="ui-floating-panel-content" consume-slide-event={contentDraggable && !atMax ? [[-180, 180]] : undefined} bindtouchstart={event => start(event, 'content')} bindtouchmove={move} bindtouchend={() => finish()} bindtouchcancel={() => finish(true)} bindmousedown={event => start(event, 'content')}>{children}</view>
98
+ </scroll-view>
99
+ </view>
100
+ </>;
101
+ return rootPortal ? <RootPortal>{layer}</RootPortal> : layer;
102
+ }