@daisu-ui/ui 0.0.0-stage → 0.1.0-beta.3

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 (401) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/LICENSE +21 -0
  3. package/README.md +93 -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/bubble.css +14 -0
  203. package/dist/bubblePosition.d.ts +19 -0
  204. package/dist/bubblePosition.js +41 -0
  205. package/dist/button.css +56 -0
  206. package/dist/calendar.css +56 -0
  207. package/dist/calendarModel.d.ts +62 -0
  208. package/dist/calendarModel.js +141 -0
  209. package/dist/card.css +8 -0
  210. package/dist/cascader.css +16 -0
  211. package/dist/cascaderModel.d.ts +21 -0
  212. package/dist/cascaderModel.js +32 -0
  213. package/dist/cell.css +41 -0
  214. package/dist/choice.css +27 -0
  215. package/dist/choice.d.ts +28 -0
  216. package/dist/choice.jsx +16 -0
  217. package/dist/circle.css +4 -0
  218. package/dist/circleModel.d.ts +15 -0
  219. package/dist/circleModel.js +31 -0
  220. package/dist/config-provider.css +2 -0
  221. package/dist/configContext.d.ts +23 -0
  222. package/dist/configContext.js +24 -0
  223. package/dist/configTheme.d.ts +3 -0
  224. package/dist/configTheme.js +22 -0
  225. package/dist/count-down.css +2 -0
  226. package/dist/count-to.css +8 -0
  227. package/dist/countDownModel.d.ts +11 -0
  228. package/dist/countDownModel.js +7 -0
  229. package/dist/countToModel.d.ts +3 -0
  230. package/dist/countToModel.js +3 -0
  231. package/dist/curtain.css +10 -0
  232. package/dist/datetime-picker.css +11 -0
  233. package/dist/datetimePickerModel.d.ts +47 -0
  234. package/dist/datetimePickerModel.js +128 -0
  235. package/dist/dialog.css +23 -0
  236. package/dist/divider.css +14 -0
  237. package/dist/drop-menu.css +28 -0
  238. package/dist/empty.css +7 -0
  239. package/dist/fab.css +23 -0
  240. package/dist/fabModel.d.ts +26 -0
  241. package/dist/fabModel.js +16 -0
  242. package/dist/floating-panel.css +6 -0
  243. package/dist/floatingPanelModel.d.ts +3 -0
  244. package/dist/floatingPanelModel.js +10 -0
  245. package/dist/form.css +10 -0
  246. package/dist/formContext.d.ts +7 -0
  247. package/dist/formContext.js +2 -0
  248. package/dist/formModel.d.ts +38 -0
  249. package/dist/formModel.js +16 -0
  250. package/dist/gap.css +1 -0
  251. package/dist/grid.css +17 -0
  252. package/dist/icon.css +8 -0
  253. package/dist/icons/LICENSE.tabler +21 -0
  254. package/dist/icons/paths.d.ts +309 -0
  255. package/dist/icons/paths.js +310 -0
  256. package/dist/icons/render.d.ts +2 -0
  257. package/dist/icons/render.js +5 -0
  258. package/dist/image-preview.css +8 -0
  259. package/dist/img-cropper.css +1 -0
  260. package/dist/img.css +5 -0
  261. package/dist/imgCropperModel.d.ts +55 -0
  262. package/dist/imgCropperModel.js +41 -0
  263. package/dist/imgModel.d.ts +13 -0
  264. package/dist/imgModel.js +22 -0
  265. package/dist/index-bar.css +12 -0
  266. package/dist/index.d.ts +200 -0
  267. package/dist/index.js +99 -0
  268. package/dist/indexBarModel.d.ts +19 -0
  269. package/dist/indexBarModel.js +37 -0
  270. package/dist/input-number.css +24 -0
  271. package/dist/inputNumberModel.d.ts +23 -0
  272. package/dist/inputNumberModel.js +40 -0
  273. package/dist/keyboard.css +26 -0
  274. package/dist/keyboardModel.d.ts +11 -0
  275. package/dist/keyboardModel.js +34 -0
  276. package/dist/layout.css +2 -0
  277. package/dist/legacy/RadioGroup.d.ts +13 -0
  278. package/dist/legacy/RadioGroup.jsx +13 -0
  279. package/dist/legacy-controls.css +87 -0
  280. package/dist/loading.css +31 -0
  281. package/dist/loadingModel.d.ts +2 -0
  282. package/dist/loadingModel.js +21 -0
  283. package/dist/loadmore.css +5 -0
  284. package/dist/navbar.css +16 -0
  285. package/dist/notice-bar.css +19 -0
  286. package/dist/notify.css +14 -0
  287. package/dist/overlay.css +2 -0
  288. package/dist/pagination.css +12 -0
  289. package/dist/paginationModel.d.ts +6 -0
  290. package/dist/paginationModel.js +7 -0
  291. package/dist/password-input.css +14 -0
  292. package/dist/passwordInputModel.d.ts +6 -0
  293. package/dist/passwordInputModel.js +11 -0
  294. package/dist/picker.css +42 -0
  295. package/dist/pickerModel.d.ts +32 -0
  296. package/dist/pickerModel.js +49 -0
  297. package/dist/popover.css +5 -0
  298. package/dist/popup.css +17 -0
  299. package/dist/progress.css +16 -0
  300. package/dist/progressModel.d.ts +12 -0
  301. package/dist/progressModel.js +19 -0
  302. package/dist/qr-code.css +4 -0
  303. package/dist/qrCodeModel.d.ts +36 -0
  304. package/dist/qrCodeModel.js +61 -0
  305. package/dist/rate.css +20 -0
  306. package/dist/rateModel.d.ts +4 -0
  307. package/dist/rateModel.js +38 -0
  308. package/dist/resize.css +2 -0
  309. package/dist/rich-text.css +19 -0
  310. package/dist/richTextMedia.d.ts +28 -0
  311. package/dist/richTextMedia.js +3 -0
  312. package/dist/richTextModel.d.ts +52 -0
  313. package/dist/richTextModel.js +195 -0
  314. package/dist/root-portal.css +1 -0
  315. package/dist/router/RouterView.d.ts +21 -0
  316. package/dist/router/RouterView.jsx +120 -0
  317. package/dist/router/core.d.ts +85 -0
  318. package/dist/router/core.js +255 -0
  319. package/dist/router/hooks.d.ts +17 -0
  320. package/dist/router/hooks.jsx +71 -0
  321. package/dist/router/index.d.ts +5 -0
  322. package/dist/router/index.js +3 -0
  323. package/dist/router/location.d.ts +8 -0
  324. package/dist/router/location.js +46 -0
  325. package/dist/router/router.css +7 -0
  326. package/dist/router/runtime.d.ts +1 -0
  327. package/dist/router/runtime.js +25 -0
  328. package/dist/search.css +23 -0
  329. package/dist/segmented.css +19 -0
  330. package/dist/segmentedModel.d.ts +10 -0
  331. package/dist/segmentedModel.js +8 -0
  332. package/dist/sidebar.css +18 -0
  333. package/dist/sidebarModel.d.ts +8 -0
  334. package/dist/sidebarModel.js +27 -0
  335. package/dist/signature.css +5 -0
  336. package/dist/signatureModel.d.ts +23 -0
  337. package/dist/signatureModel.js +80 -0
  338. package/dist/skeleton.css +16 -0
  339. package/dist/slide-verify.css +7 -0
  340. package/dist/slider.css +49 -0
  341. package/dist/sliderModel.d.ts +10 -0
  342. package/dist/sliderModel.js +27 -0
  343. package/dist/sort-button.css +12 -0
  344. package/dist/steps.css +35 -0
  345. package/dist/sticky.css +7 -0
  346. package/dist/styles.css +136 -0
  347. package/dist/styles.d.ts +1 -0
  348. package/dist/swipe-action.css +6 -0
  349. package/dist/swiper.css +27 -0
  350. package/dist/swiperAnimation.d.ts +3 -0
  351. package/dist/swiperAnimation.js +6 -0
  352. package/dist/swiperModel.d.ts +2 -0
  353. package/dist/swiperModel.js +3 -0
  354. package/dist/switch.css +12 -0
  355. package/dist/tabbar.css +17 -0
  356. package/dist/tabbarModel.d.ts +8 -0
  357. package/dist/tabbarModel.js +27 -0
  358. package/dist/table.css +21 -0
  359. package/dist/tableModel.d.ts +10 -0
  360. package/dist/tableModel.js +17 -0
  361. package/dist/tabs.css +31 -0
  362. package/dist/tabsModel.d.ts +7 -0
  363. package/dist/tabsModel.js +14 -0
  364. package/dist/tag.css +66 -0
  365. package/dist/text-field.css +15 -0
  366. package/dist/text.css +7 -0
  367. package/dist/textModel.d.ts +3 -0
  368. package/dist/textModel.js +24 -0
  369. package/dist/toast.css +13 -0
  370. package/dist/tokens.d.ts +34 -0
  371. package/dist/tokens.js +10 -0
  372. package/dist/tour.css +8 -0
  373. package/dist/transition.css +12 -0
  374. package/dist/upload.css +11 -0
  375. package/dist/useCountDown.d.ts +14 -0
  376. package/dist/useCountDown.js +73 -0
  377. package/dist/useDialog.d.ts +9 -0
  378. package/dist/useDialog.js +33 -0
  379. package/dist/useImagePreview.d.ts +7 -0
  380. package/dist/useImagePreview.js +17 -0
  381. package/dist/useNotify.d.ts +9 -0
  382. package/dist/useNotify.js +26 -0
  383. package/dist/usePressState.d.ts +6 -0
  384. package/dist/usePressState.js +17 -0
  385. package/dist/useToast.d.ts +11 -0
  386. package/dist/useToast.js +23 -0
  387. package/dist/useVideoPreview.d.ts +7 -0
  388. package/dist/useVideoPreview.js +17 -0
  389. package/dist/utils.d.ts +4 -0
  390. package/dist/utils.js +4 -0
  391. package/dist/video-preview.css +7 -0
  392. package/dist/watermark.css +6 -0
  393. package/dist/web/imgCropperElement.d.ts +2 -0
  394. package/dist/web/imgCropperElement.js +309 -0
  395. package/dist/web/index.d.ts +6 -0
  396. package/dist/web/index.js +6 -0
  397. package/dist/web/qrCodeExportElement.d.ts +4 -0
  398. package/dist/web/qrCodeExportElement.js +70 -0
  399. package/dist/web/richTextMediaElement.d.ts +2 -0
  400. package/dist/web/richTextMediaElement.js +276 -0
  401. package/package.json +98 -4
@@ -0,0 +1,288 @@
1
+ import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from '@lynx-js/react';
2
+ import { Img } from "./Img.jsx";
3
+ import { ImagePreview } from "./ImagePreview.jsx";
4
+ import { useImagePreview } from './useImagePreview.js';
5
+ import { Table } from "./Table.jsx";
6
+ import { parseRichText, richBlockTags, richTextTableGrid } from './richTextModel.js';
7
+ import { validRichTextMediaId } from './richTextMedia.js';
8
+ const textDefaults = {
9
+ p: { margin: '0 0 12px' },
10
+ h1: { fontSize: '2em', fontWeight: 'bold', margin: '0 0 0.6em' },
11
+ h2: { fontSize: '1.5em', fontWeight: 'bold', margin: '0 0 0.6em' },
12
+ h3: { fontSize: '1.17em', fontWeight: 'bold', margin: '0 0 0.6em' },
13
+ h4: { fontSize: '1em', fontWeight: 'bold', margin: '0 0 0.6em' },
14
+ h5: { fontSize: '0.83em', fontWeight: 'bold', margin: '0 0 0.6em' },
15
+ h6: { fontSize: '0.67em', fontWeight: 'bold', margin: '0 0 0.6em' },
16
+ ul: { margin: '0 0 12px' }, ol: { margin: '0 0 12px' },
17
+ strong: { fontWeight: 'bold' }, b: { fontWeight: 'bold' }, em: { fontStyle: 'italic' }, i: { fontStyle: 'italic' },
18
+ u: { textDecoration: 'underline' }, s: { textDecoration: 'line-through' }, del: { textDecoration: 'line-through' },
19
+ a: { color: 'var(--cso-ui-rich-text-link-color, var(--cso-ui-primary))', textDecoration: 'underline' },
20
+ small: { fontSize: '0.8em' }, sub: { fontSize: '0.8em', verticalAlign: 'sub' }, sup: { fontSize: '0.8em', verticalAlign: 'super' },
21
+ code: { fontFamily: 'monospace' }, pre: { fontFamily: 'monospace', margin: '0 0 12px' },
22
+ blockquote: { borderLeftWidth: '3px', borderLeftStyle: 'solid', borderLeftColor: 'var(--cso-ui-line)', paddingLeft: '12px', margin: '0 0 12px' },
23
+ figure: { margin: '0 0 12px' }, figcaption: { fontSize: '0.9em', textAlign: 'center' },
24
+ dl: { margin: '0 0 12px' }, dt: { fontWeight: 'bold' }, dd: { margin: '0 0 8px 24px' },
25
+ mark: { backgroundColor: 'yellow', color: 'black' }, hr: { margin: '12px 0' },
26
+ };
27
+ function margins(style) {
28
+ let top = 0, bottom = 0;
29
+ const px = (value) => typeof value === 'number' ? value : /^-?[\d.]+(?:px)?$/.test(String(value)) ? parseFloat(String(value)) : 0;
30
+ for (const [name, value] of Object.entries(style)) {
31
+ if (name === 'margin') {
32
+ const parts = String(value).split(/\s+/);
33
+ top = px(parts[0]);
34
+ bottom = px(parts[2] ?? parts[0]);
35
+ }
36
+ else if (name === 'marginTop')
37
+ top = px(value);
38
+ else if (name === 'marginBottom')
39
+ bottom = px(value);
40
+ }
41
+ return { top, bottom };
42
+ }
43
+ function Placeholder({ src, text }) { const [failed, setFailed] = useState(false); return src && !failed ? <image src={src} mode="aspectFit" style={{ width: '48px', height: '48px' }} binderror={() => {
44
+ 'background only';
45
+ setFailed(true);
46
+ }}/> : <text className="ui-rich-text-image-alt">{text}</text>; }
47
+ function RichImage(props) {
48
+ const loaded = useRef(false);
49
+ useEffect(() => { if (!props.src)
50
+ props.onError?.({ detail: {} }); }, []);
51
+ if (!props.src)
52
+ return <view className="ui-rich-text-missing-image" style={{ minHeight: '48px', height: props.height === undefined ? undefined : typeof props.height === 'number' ? `${props.height}px` : props.height }}>{props.error}</view>;
53
+ return <Img {...props} onLoad={event => {
54
+ 'background only';
55
+ loaded.current = true;
56
+ props.onLoad?.(event);
57
+ }} onClick={() => {
58
+ 'background only';
59
+ if (loaded.current)
60
+ props.onClick?.();
61
+ }}/>;
62
+ }
63
+ /** HTML is parsed into native views, nested text, images and the public Table. */
64
+ export const RichText = forwardRef(function RichText({ content = '', mediaMode = 'none', onMediaPlay, onMediaPause, onMediaEnded, onMediaTimeUpdate, baseUrl, allowDataImage = false, enableAnchor = false, selectable = false, tagStyle, classStyles, previewImage = true, loadingImage, errorImage, children, onLoad, onError, onLinkClick, onImageClick, onImageLoad, onScrollToAnchor, className = '', style }, ref) {
65
+ const parsed = useMemo(() => { try {
66
+ return { ...parseRichText(content, { enableMedia: mediaMode === 'browser', baseUrl, allowDataImage, enableAnchor, tagStyle, classStyles }), error: undefined };
67
+ }
68
+ catch (reason) {
69
+ const error = reason;
70
+ return { nodes: [], images: [], media: [], headings: [], text: '', error: { source: 'parse', message: error.message, code: error.code } };
71
+ } }, [content, mediaMode, baseUrl, allowDataImage, enableAnchor, JSON.stringify(tagStyle), JSON.stringify(classStyles)]);
72
+ const fallback = typeof children === 'string' || typeof children === 'number' ? <text className="ui-rich-text-line">{children}</text> : children;
73
+ const [previewMounted, setPreviewMounted] = useState(false);
74
+ const [width, setWidth] = useState(300), preview = useImagePreview();
75
+ const anchors = useRef(new Map()), alive = useRef(true), current = useRef(parsed), scrollRequest = useRef(0);
76
+ const failedMedia = useRef(new WeakSet());
77
+ const mediaRefs = useRef(new Map());
78
+ const callbacks = useRef({ onLoad, onError, onLinkClick, onImageClick, onImageLoad, onScrollToAnchor, onMediaPlay, onMediaPause, onMediaEnded, onMediaTimeUpdate });
79
+ callbacks.current = { onLoad, onError, onLinkClick, onImageClick, onImageLoad, onScrollToAnchor, onMediaPlay, onMediaPause, onMediaEnded, onMediaTimeUpdate };
80
+ current.current = parsed;
81
+ useEffect(() => { if (parsed.error)
82
+ callbacks.current.onError?.(parsed.error);
83
+ else
84
+ callbacks.current.onLoad?.({ imageCount: parsed.images.length }); }, [parsed]);
85
+ useEffect(() => () => { alive.current = false; scrollRequest.current++; anchors.current.clear(); mediaRefs.current.clear(); }, []);
86
+ const readAnchor = async (id) => {
87
+ 'background only';
88
+ const version = current.current, node = anchors.current.get(id);
89
+ if (!enableAnchor || !node || !alive.current)
90
+ throw new Error('RichText anchor is unavailable');
91
+ const rect = await new Promise((resolve, reject) => node.invoke({ method: 'boundingClientRect', params: { androidEnableTransformProps: true, iosEnableTransformProps: true }, success: result => resolve(result), fail: () => reject(new Error('RichText anchor measurement failed')) }).exec());
92
+ if (!alive.current || version !== current.current || ![rect.top, rect.left, rect.width, rect.height].every(Number.isFinite) || rect.width <= 0 || rect.height <= 0)
93
+ throw new Error('RichText anchor is unavailable');
94
+ return rect;
95
+ };
96
+ const mediaTarget = (id) => { const matches = current.current.media.filter(node => node.media?.id === id); return validRichTextMediaId(id) && matches.length === 1 ? mediaRefs.current.get(matches[0]) : undefined; };
97
+ const sendMedia = (target, method, params = {}) => {
98
+ 'background only';
99
+ if (!alive.current || !target || target.failed)
100
+ return false;
101
+ target.node.invoke({ method, params }).exec();
102
+ return true;
103
+ };
104
+ useImperativeHandle(ref, () => ({
105
+ playMedia(id) {
106
+ 'background only';
107
+ return sendMedia(mediaTarget(id), 'playMedia');
108
+ },
109
+ pauseMedia(id) {
110
+ 'background only';
111
+ if (id !== undefined)
112
+ return sendMedia(mediaTarget(id), 'pauseMedia');
113
+ let sent = false;
114
+ for (const node of current.current.media)
115
+ sent = sendMedia(mediaRefs.current.get(node), 'pauseMedia') || sent;
116
+ return sent;
117
+ },
118
+ seekMedia(id, seconds) {
119
+ 'background only';
120
+ return Number.isFinite(seconds) && seconds >= 0 && sendMedia(mediaTarget(id), 'seekMedia', { seconds });
121
+ },
122
+ getText() {
123
+ 'background only';
124
+ return parsed.text;
125
+ }, getHeadings() {
126
+ 'background only';
127
+ return parsed.headings.map(h => ({ ...h }));
128
+ }, getAnchorRect: readAnchor, async scrollToAnchor(id, { offset = 0, duration = 300 } = {}) {
129
+ 'background only';
130
+ if (!Number.isFinite(offset) || !Number.isFinite(duration) || duration < 0)
131
+ throw new Error('Invalid anchor scroll options');
132
+ if (!callbacks.current.onScrollToAnchor)
133
+ throw new Error('Provide onScrollToAnchor for the parent scroll container');
134
+ const request = ++scrollRequest.current, version = current.current, rect = await readAnchor(id);
135
+ if (!alive.current || version !== current.current || request !== scrollRequest.current)
136
+ throw new Error('RichText anchor scroll interrupted');
137
+ await callbacks.current.onScrollToAnchor({ id, rect, offset, duration });
138
+ if (!alive.current || version !== current.current || request !== scrollRequest.current)
139
+ throw new Error('RichText anchor scroll interrupted');
140
+ }
141
+ }), [parsed, enableAnchor]);
142
+ const anchor = (node) => node.anchor ? { ref: (ref) => {
143
+ 'background only';
144
+ if (ref)
145
+ anchors.current.set(node.anchor, ref);
146
+ else
147
+ anchors.current.delete(node.anchor);
148
+ } } : {};
149
+ const image = (node, parent, href) => {
150
+ const src = node.src || '', index = node.imageIndex, fixedHeight = node.style.height ?? node.attrs.height;
151
+ const dimension = (v) => v === undefined ? undefined : /^\d+(\.\d+)?$/.test(String(v)) ? Number(v) : v;
152
+ return <view key={node.key} {...anchor(node)}><RichImage key={src} src={src} width={dimension(node.style.width ?? node.attrs.width) ?? '100%'} height={dimension(fixedHeight)} mode={fixedHeight ? 'aspectFill' : 'widthFix'} alt={node.attrs.alt} loading={<Placeholder key={loadingImage} src={loadingImage} text="加载中"/>} error={<Placeholder key={errorImage} src={errorImage} text={node.attrs.alt || '×'}/>} style={{ minHeight: fixedHeight ? undefined : '48px', ...parent, ...node.style }} onError={() => {
153
+ 'background only';
154
+ if (current.current === parsed && alive.current)
155
+ callbacks.current.onError?.({ source: 'image', src, index });
156
+ }} onLoad={event => {
157
+ 'background only';
158
+ if (current.current === parsed && alive.current)
159
+ callbacks.current.onImageLoad?.({ src, index, width: event.detail.width, height: event.detail.height });
160
+ }} onClick={() => {
161
+ 'background only';
162
+ if (!alive.current || current.current !== parsed)
163
+ return;
164
+ if (href) {
165
+ callbacks.current.onLinkClick?.({ href });
166
+ return;
167
+ }
168
+ callbacks.current.onImageClick?.({ src, index });
169
+ if (previewImage && node.previewSrc && !node.previewSrc.startsWith('data:')) {
170
+ const eligible = parsed.images.filter(n => n.previewSrc && !n.previewSrc.startsWith('data:'));
171
+ const position = eligible.indexOf(node);
172
+ if (position >= 0) {
173
+ setPreviewMounted(true);
174
+ preview.previewImage({ images: eligible.map(n => n.previewSrc), startPosition: position });
175
+ }
176
+ }
177
+ }}/></view>;
178
+ };
179
+ const inline = (node) => node.tag === '#text' ? node.text : node.tag === 'br' ? '\n' : <text key={node.key} {...anchor(node)} style={{ ...textDefaults[node.tag], ...node.style }} bindtap={node.tag === 'a' && node.attrs.href ? () => {
180
+ 'background only';
181
+ callbacks.current.onLinkClick?.({ href: node.attrs.href });
182
+ } : undefined}>{node.children.map(inline)}</text>;
183
+ const table = (node, parent) => {
184
+ const { grid, columns: count } = richTextTableGrid(node);
185
+ const tableWidth = Math.max(0, (typeof node.style.width === 'string' && /^[\d.]+px$/.test(node.style.width) ? parseFloat(node.style.width) : width) - 2);
186
+ const definitions = [];
187
+ for (const child of node.children) {
188
+ if (child.tag === 'col')
189
+ definitions.push(child);
190
+ else if (child.tag === 'colgroup')
191
+ for (const col of child.children)
192
+ if (col.tag === 'col')
193
+ definitions.push(col);
194
+ }
195
+ const widths = Array.from({ length: count }, (_, i) => { const value = definitions[i]?.style.width ?? definitions[i]?.attrs.width; return value && String(value).endsWith('%') ? tableWidth * parseFloat(String(value)) / 100 : value ? parseFloat(String(value)) : tableWidth / count; });
196
+ const data = grid.map((row, r) => ({ r, ...Object.fromEntries(row.map((cell, i) => [String(i), cell])) }));
197
+ return <view key={node.key} {...anchor(node)} className="ui-rich-text-table" style={{ ...node.style, width: '100%' }}><Table data={data} columns={widths.map((w, i) => ({ prop: String(i), width: w, render: ({ row }) => { const cell = grid[row.r]?.[i]; return cell ? <view {...anchor(cell.node)} className={`ui-rich-text-cell ${cell.node.tag === 'th' ? 'ui-rich-text-th' : ''}`} style={{ ...parent, ...cell.node.style }}>{flow(cell.node.children, {})}</view> : null; } }))} showHeader={false} stripe={false} cellPadding={0} rowHeight={38} spanMethod={({ rowIndex, columnIndex }) => grid[rowIndex]?.[columnIndex]}/></view>;
198
+ };
199
+ const media = (node) => {
200
+ const config = node.media;
201
+ const receive = ({ detail: event }) => {
202
+ 'background only';
203
+ if (!alive.current || current.current !== parsed)
204
+ return;
205
+ const target = mediaRefs.current.get(node);
206
+ if (!target)
207
+ return;
208
+ if (event.kind === 'error') {
209
+ if (event.fatal) {
210
+ target.failed = true;
211
+ failedMedia.current.add(node);
212
+ }
213
+ callbacks.current.onError?.({ source: config.type, src: event.src, message: event.message, code: event.code });
214
+ return;
215
+ }
216
+ const value = { id: config.id, type: config.type, src: event.src };
217
+ if (event.kind === 'play') {
218
+ for (const [other, entry] of mediaRefs.current)
219
+ if (other !== node && parsed.media.includes(other))
220
+ sendMedia(entry, 'pauseMedia');
221
+ callbacks.current.onMediaPlay?.(value);
222
+ }
223
+ else if (event.kind === 'pause')
224
+ callbacks.current.onMediaPause?.(value);
225
+ else if (event.kind === 'ended')
226
+ callbacks.current.onMediaEnded?.(value);
227
+ else if (event.kind === 'timeupdate')
228
+ callbacks.current.onMediaTimeUpdate?.({ ...value, currentTime: event.currentTime, duration: event.duration });
229
+ };
230
+ return <view key={node.key} {...anchor(node)} className="ui-rich-text-media"><daisu-rich-media className={`ui-rich-text-${config.type}`} style={{ ...node.style, width: node.style.width ?? node.attrs.width ?? '100%', height: node.style.height ?? (node.attrs.height ? `${parseFloat(node.attrs.height)}px` : undefined) }} media-config={JSON.stringify(config)} ref={ref => {
231
+ 'background only';
232
+ if (ref)
233
+ mediaRefs.current.set(node, { node: ref, failed: failedMedia.current.has(node) });
234
+ else
235
+ mediaRefs.current.delete(node);
236
+ }} bindmediaevent={receive}/></view>;
237
+ };
238
+ const block = (node, parent, href, adjustment = {}) => {
239
+ if (node.media)
240
+ return media(node);
241
+ if (node.tag === 'img')
242
+ return image(node, parent, href);
243
+ if (node.tag === 'table')
244
+ return table(node, parent);
245
+ const authored = { ...textDefaults[node.tag], ...node.style };
246
+ const styles = { ...Object.fromEntries(Object.entries(authored).filter(([name]) => !(name in adjustment))), ...adjustment }, childStyle = {};
247
+ if (node.tag === 'hr')
248
+ return <view key={node.key} {...anchor(node)} className="ui-rich-text-hr" style={styles}/>;
249
+ if (node.tag === 'ul' || node.tag === 'ol') {
250
+ let index = parseInt(node.attrs.start || '1') || 1;
251
+ return <view key={node.key} {...anchor(node)} className="ui-rich-text-list" style={styles}>{node.children.map(child => child.tag === 'li' ? <view key={child.key} {...anchor(child)} className={`ui-rich-text-li ${child.attrs['data-list'] ? 'ui-rich-text-li-task' : ''}`} style={child.style}><text className="ui-rich-text-marker" style={childStyle}>{child.attrs['data-list'] === 'checked' ? '☑\u00a0' : child.attrs['data-list'] === 'unchecked' ? '☐\u00a0' : node.tag === 'ol' ? `${index++}.` : '•'}</text><view className="ui-rich-text-li-content">{flow(child.children, {})}</view></view> : block(child, childStyle))}</view>;
252
+ }
253
+ return <view key={node.key} {...anchor(node)} className={`ui-rich-text-block ui-rich-text-${node.tag}`} style={styles}>{flow(node.children, childStyle, node.tag === 'a' ? node.attrs.href || href : href)}</view>;
254
+ };
255
+ function flow(nodes, parent = {}, href) {
256
+ const output = [];
257
+ let run = [];
258
+ let previousBottom = 0;
259
+ const flush = () => { if (run.length) {
260
+ output.push(<text key={`text-${run[0].key}`} className="ui-rich-text-line" text-selection={selectable} bindtap={href ? () => {
261
+ 'background only';
262
+ callbacks.current.onLinkClick?.({ href });
263
+ } : undefined}>{run.map(inline)}</text>);
264
+ run = [];
265
+ } };
266
+ for (const node of nodes) {
267
+ const hasBlock = (n) => !!n.media || n.tag === 'img' || richBlockTags.has(n.tag) || n.children.some(hasBlock);
268
+ if (hasBlock(node)) {
269
+ flush();
270
+ const margin = margins({ ...textDefaults[node.tag], ...node.style });
271
+ // Native Lynx does not collapse adjacent block margins. Reproduce the
272
+ // positive HTML paragraph spacing explicitly within rich content.
273
+ const adjustment = margin.top > 0 && previousBottom > 0 ? { marginTop: `${Math.max(0, margin.top - previousBottom)}px` } : {};
274
+ output.push(block(node, parent, href, adjustment));
275
+ previousBottom = margin.bottom;
276
+ }
277
+ else
278
+ run.push(node);
279
+ }
280
+ flush();
281
+ return output;
282
+ }
283
+ return <view className={`ui-rich-text ${className}`} style={style} bindlayoutchange={e => {
284
+ 'background only';
285
+ if (e.detail.width > 0)
286
+ setWidth(old => old === e.detail.width ? old : e.detail.width);
287
+ }}>{parsed.nodes.length ? flow(parsed.nodes) : fallback}{previewMounted ? <ImagePreview {...preview.props} rootPortal/> : null}</view>;
288
+ });
@@ -0,0 +1,11 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ export type RootPortalHostProps = {
3
+ children?: ReactNode;
4
+ };
5
+ export type RootPortalProps = {
6
+ children?: ReactNode;
7
+ };
8
+ /** Place once inside the page root, above transformed/clipped layout containers. */
9
+ export declare function RootPortalHost({ children }: RootPortalHostProps): import("@lynx-js/react").JSX.Element;
10
+ /** Uses ReactLynx's native portal; no DOM or fixed-position fallback. */
11
+ export declare function RootPortal({ children }: RootPortalProps): ReactNode;
@@ -0,0 +1,19 @@
1
+ import { createContext, createPortal, useCallback, useContext, useState } from '@lynx-js/react';
2
+ import { ConfigContext } from './configContext.js';
3
+ const PortalTarget = createContext(undefined);
4
+ /** Place once inside the page root, above transformed/clipped layout containers. */
5
+ export function RootPortalHost({ children }) {
6
+ const [target, setTarget] = useState(null);
7
+ const attach = useCallback((node) => {
8
+ 'background only';
9
+ setTarget(node);
10
+ }, []);
11
+ return <PortalTarget.Provider value={target}>{children}<view className="ui-root-portal-target" flatten={false} ref={attach}/></PortalTarget.Provider>;
12
+ }
13
+ /** Uses ReactLynx's native portal; no DOM or fixed-position fallback. */
14
+ export function RootPortal({ children }) {
15
+ const target = useContext(PortalTarget), config = useContext(ConfigContext);
16
+ if (target === undefined)
17
+ throw new Error('RootPortal requires a RootPortalHost at the page root.');
18
+ return target ? createPortal(config ? <ConfigContext.Provider value={config}><view className="ui-config-portal" style={config.tokens}>{children}</view></ConfigContext.Provider> : children, target) : null;
19
+ }
@@ -0,0 +1,39 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { CSSProperties } from '@lynx-js/types';
3
+ import type { InputProps, InputRef, TextFieldEvent } from "./Input.jsx";
4
+ export type SearchRef = InputRef;
5
+ export type SearchProps = {
6
+ value?: string;
7
+ defaultValue?: string;
8
+ onChange?: (event: {
9
+ value: string;
10
+ }) => void;
11
+ type?: InputProps['type'];
12
+ placeholder?: string;
13
+ cancelTxt?: string;
14
+ variant?: 'plain' | 'filled' | 'light';
15
+ hideCancel?: boolean;
16
+ disabled?: boolean;
17
+ maxlength?: number | string;
18
+ placeholderLeft?: boolean;
19
+ focus?: boolean;
20
+ focusWhenClear?: boolean;
21
+ placeholderColor?: string;
22
+ prefix?: ReactNode;
23
+ inputSuffix?: ReactNode;
24
+ suffix?: ReactNode;
25
+ onSearch?: (event: {
26
+ value: string;
27
+ }) => void;
28
+ onCancel?: (event: {
29
+ value: string;
30
+ }) => void;
31
+ onClear?: () => void;
32
+ onFocus?: (event: TextFieldEvent) => void;
33
+ onBlur?: (event: TextFieldEvent) => void;
34
+ onTap?: () => void;
35
+ inputClassName?: string;
36
+ className?: string;
37
+ style?: CSSProperties;
38
+ };
39
+ export declare const Search: (props: SearchProps & import("react").RefAttributes<import("./TextField.jsx").TextFieldRef>) => React.ReactElement | null;
@@ -0,0 +1,94 @@
1
+ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from '@lynx-js/react';
2
+ import { Icon } from "./Icon.jsx";
3
+ import { Input } from "./Input.jsx";
4
+ const content = (node) => typeof node === 'string' || typeof node === 'number' ? <text>{node}</text> : node;
5
+ function Glyph({ clear = false }) {
6
+ const name = clear ? 'close-circle-fill' : 'search-line';
7
+ return <view className={`ui-search-glyph ${clear ? 'ui-search-clear-glyph' : ''}`}>
8
+ <Icon name={name} size={clear ? 20 : 18} color={clear ? '#c9cbd4' : '#4e5369'} className="ui-search-glyph-light"/>
9
+ <Icon name={name} size={clear ? 20 : 18} color={clear ? '#6b7085' : '#e5e6eb'} className="ui-search-glyph-dark"/>
10
+ </view>;
11
+ }
12
+ export const Search = forwardRef(function Search({ value, defaultValue = '', onChange, type = 'text', placeholder = '搜索', cancelTxt = '取消', variant = 'plain', hideCancel = false, disabled = false, maxlength = -1, placeholderLeft = false, focus, focusWhenClear = false, placeholderColor, prefix, inputSuffix, suffix, onSearch, onCancel, onClear, onFocus, onBlur, onTap, inputClassName = '', className = '', style }, ref) {
13
+ const [inner, setInner] = useState(defaultValue), [active, setActive] = useState(!!focus && !disabled);
14
+ const text = value === undefined ? inner : value;
15
+ const input = useRef(null), blurTimer = useRef();
16
+ const requestFocus = () => {
17
+ 'background only';
18
+ if (disabled)
19
+ return;
20
+ clearTimeout(blurTimer.current);
21
+ setActive(true);
22
+ input.current?.focus();
23
+ };
24
+ const requestBlur = () => {
25
+ 'background only';
26
+ input.current?.blur();
27
+ setActive(false);
28
+ };
29
+ useImperativeHandle(ref, () => ({ focus: requestFocus, blur: requestBlur, setSelectionRange: (start, end) => {
30
+ 'background only';
31
+ input.current?.setSelectionRange(start, end);
32
+ } }), [disabled]);
33
+ useEffect(() => { if (focus === true)
34
+ requestFocus();
35
+ else if (focus === false)
36
+ requestBlur(); }, [focus, disabled]);
37
+ useEffect(() => () => clearTimeout(blurTimer.current), []);
38
+ const update = (next) => {
39
+ 'background only';
40
+ if (disabled)
41
+ return;
42
+ setInner(next);
43
+ onChange?.({ value: next });
44
+ };
45
+ const clear = () => {
46
+ 'background only';
47
+ if (disabled || !text)
48
+ return;
49
+ update('');
50
+ onClear?.();
51
+ if (focusWhenClear)
52
+ requestFocus();
53
+ else
54
+ requestBlur();
55
+ };
56
+ const cover = !text && !active && !placeholderLeft;
57
+ const limit = Number(maxlength);
58
+ return <view className={`ui-search ui-search-${variant} ${disabled ? 'ui-search-disabled' : ''} ${className}`} style={style}>
59
+ <view className="ui-search-block" bindtap={() => {
60
+ 'background only';
61
+ if (disabled)
62
+ onTap?.();
63
+ }}>
64
+ {variant === 'plain' ? <view className="ui-search-outline" user-interaction-enabled={false}/> : null}
65
+ {prefix !== undefined ? <view className="ui-search-prefix">{content(prefix)}</view> : null}
66
+ <view className="ui-search-field">
67
+ {!cover ? <Glyph /> : null}
68
+ <view className="ui-search-edit-area">
69
+ <Input ref={input} compact type={type} value={text} onChange={update} placeholder={cover ? '' : placeholder} placeholderColor={placeholderColor} maxlength={Number.isFinite(limit) ? limit : -1} disabled={disabled} confirmType="search" className="ui-search-editor" inputClassName={inputClassName} onFocus={event => {
70
+ 'background only';
71
+ clearTimeout(blurTimer.current);
72
+ setActive(true);
73
+ onFocus?.(event);
74
+ }} onBlur={event => {
75
+ 'background only';
76
+ clearTimeout(blurTimer.current);
77
+ blurTimer.current = setTimeout(() => { setActive(false); onBlur?.(event); }, 150);
78
+ }} onConfirm={event => {
79
+ 'background only';
80
+ if (!disabled)
81
+ onSearch?.({ value: event.value });
82
+ }}/>
83
+ {cover ? <view className="ui-search-cover" bindtap={requestFocus} accessibility-element accessibility-traits="button" accessibility-label={placeholder}><Glyph /><text className="ui-search-placeholder" style={placeholderColor ? { color: placeholderColor } : undefined}>{placeholder}</text></view> : null}
84
+ </view>
85
+ {text && !disabled ? <view className="ui-search-clear" catchtap={clear} accessibility-element accessibility-traits="button" accessibility-label="清空搜索"><Glyph clear/></view> : null}
86
+ {inputSuffix !== undefined ? <view className="ui-search-input-suffix">{content(inputSuffix)}</view> : null}
87
+ </view>
88
+ </view>
89
+ {!hideCancel ? suffix !== undefined ? <view className="ui-search-suffix">{content(suffix)}</view> : <text className="ui-search-cancel" bindtap={() => {
90
+ 'background only';
91
+ onCancel?.({ value: text });
92
+ }}>{cancelTxt}</text> : null}
93
+ </view>;
94
+ });
@@ -0,0 +1,18 @@
1
+ import type { ReactNode } from '@lynx-js/react';
2
+ import type { SegmentedInput, SegmentedOption, SegmentedValue } from './segmentedModel.js';
3
+ export type SegmentedProps<T = unknown> = {
4
+ options?: readonly SegmentedInput<T>[];
5
+ value?: SegmentedValue;
6
+ defaultValue?: SegmentedValue;
7
+ onChange?: (option: SegmentedOption<T>) => void;
8
+ onClick?: (option: SegmentedOption<T>) => void;
9
+ disabled?: boolean;
10
+ theme?: 'card' | 'outline';
11
+ renderLabel?: (state: {
12
+ option: SegmentedOption<T>;
13
+ active: boolean;
14
+ disabled: boolean;
15
+ }) => ReactNode;
16
+ className?: string;
17
+ };
18
+ export declare function Segmented<T = unknown>({ options, value, defaultValue, onChange, onClick, disabled, theme, renderLabel, className }: SegmentedProps<T>): import("@lynx-js/react").JSX.Element;
@@ -0,0 +1,35 @@
1
+ import { useState } from '@lynx-js/react';
2
+ import { segmentedIndex, segmentedOptions } from './segmentedModel.js';
3
+ export function Segmented({ options = [], value, defaultValue, onChange, onClick, disabled = false, theme = 'card', renderLabel, className = '' }) {
4
+ const [inner, setInner] = useState(defaultValue);
5
+ const items = segmentedOptions(options);
6
+ const selected = segmentedIndex(items, value ?? inner);
7
+ const choose = (index) => {
8
+ 'background only';
9
+ const option = items[index];
10
+ if (!option || disabled || option.disabled)
11
+ return;
12
+ if (selected !== index) {
13
+ if (value === undefined)
14
+ setInner(option.value);
15
+ onChange?.(option);
16
+ }
17
+ onClick?.(option);
18
+ };
19
+ return <view className={`ui-segmented ui-segmented-${theme} ${disabled ? 'ui-segmented-disabled' : ''} ${className}`}>
20
+ <view className="ui-segmented-track">
21
+ {theme === 'card' && selected >= 0 ? <view className="ui-segmented-slider" user-interaction-enabled={false} style={{ width: `${100 / items.length}%`, transform: `translateX(${selected * 100}%)` }}/> : null}
22
+ {items.map((option, index) => {
23
+ const active = selected === index;
24
+ const blocked = disabled || !!option.disabled;
25
+ return <view key={`${typeof option.value}:${option.value}`} className={`ui-segmented-item ${active ? 'ui-segmented-item-active' : ''} ${blocked ? 'ui-segmented-item-disabled' : ''} ${index === 0 ? 'ui-segmented-item-first' : ''} ${index === items.length - 1 ? 'ui-segmented-item-last' : ''}`} style={{ width: `${100 / items.length}%` }} accessibility-element accessibility-traits="button" accessibility-label={`${option.value}${active ? ',已选中' : ''}${blocked ? ',禁用' : ''}`} bindtap={() => {
26
+ 'background only';
27
+ choose(index);
28
+ }}>
29
+ {renderLabel ? renderLabel({ option, active, disabled: blocked }) : <text className="ui-segmented-label">{option.value}</text>}
30
+ {theme === 'outline' ? <view className="ui-segmented-outline-border" user-interaction-enabled={false}/> : null}
31
+ </view>;
32
+ })}
33
+ </view>
34
+ </view>;
35
+ }
@@ -0,0 +1,54 @@
1
+ import type { CSSProperties } from '@lynx-js/types';
2
+ import type { ChoiceValue } from "./choice.jsx";
3
+ export type SelectPickerOption = {
4
+ value: ChoiceValue;
5
+ label: string;
6
+ disabled?: boolean;
7
+ };
8
+ export type SelectPickerValue = ChoiceValue | readonly ChoiceValue[];
9
+ export type SelectPickerProps = {
10
+ value?: SelectPickerValue;
11
+ onChange?: (event: {
12
+ value: ChoiceValue | ChoiceValue[];
13
+ }) => void;
14
+ visible?: boolean;
15
+ onVisibleChange?: (visible: boolean) => void;
16
+ columns: readonly (SelectPickerOption | Readonly<Record<string, unknown>>)[];
17
+ type?: 'checkbox' | 'radio';
18
+ title?: string;
19
+ min?: number;
20
+ max?: number;
21
+ disabled?: boolean;
22
+ loading?: boolean;
23
+ filterable?: boolean;
24
+ filterPlaceholder?: string;
25
+ confirmButtonText?: string;
26
+ showConfirm?: boolean;
27
+ valueKey?: string;
28
+ labelKey?: string;
29
+ checkedColor?: string;
30
+ selectSize?: 'large';
31
+ loadingColor?: string;
32
+ beforeConfirm?: (value: ChoiceValue | ChoiceValue[]) => boolean | Promise<boolean>;
33
+ onConfirm?: (event: {
34
+ value: ChoiceValue | ChoiceValue[];
35
+ selectedItems: SelectPickerOption[];
36
+ }) => void;
37
+ onCancel?: () => void;
38
+ onClose?: () => void;
39
+ onOpen?: () => void;
40
+ closeOnClickModal?: boolean;
41
+ scrollIntoView?: boolean;
42
+ rootPortal?: boolean;
43
+ zIndex?: number;
44
+ safeAreaInsetBottom?: boolean;
45
+ safeAreaBottom?: number;
46
+ className?: string;
47
+ style?: CSSProperties;
48
+ contentClassName?: string;
49
+ };
50
+ export type SelectPickerRef = {
51
+ open: () => void;
52
+ close: () => void;
53
+ };
54
+ export declare const SelectPicker: (props: SelectPickerProps & import("react").RefAttributes<SelectPickerRef>) => React.ReactElement | null;