@g9tm/lynxcontrols 2.5.6 → 2.5.8

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 (337) hide show
  1. package/catalog/cards/G9AppBar.md +1 -1
  2. package/catalog/cards/G9AppearancePage.md +17 -0
  3. package/catalog/cards/G9Badge.md +1 -1
  4. package/catalog/cards/G9Button.md +2 -2
  5. package/catalog/cards/G9Card.md +1 -1
  6. package/catalog/cards/G9CarryContexts.md +10 -0
  7. package/catalog/cards/G9CheckBox.md +1 -1
  8. package/catalog/cards/G9Chip.md +1 -1
  9. package/catalog/cards/G9ChipStrip.md +16 -0
  10. package/catalog/cards/G9CodeBlock.md +17 -0
  11. package/catalog/cards/G9CommandPalette.md +3 -1
  12. package/catalog/cards/G9ConnectionBanner.md +1 -1
  13. package/catalog/cards/G9ContrastPanel.md +15 -0
  14. package/catalog/cards/G9DashboardCustomizeSheet.md +17 -0
  15. package/catalog/cards/G9DashboardGrid.md +17 -0
  16. package/catalog/cards/G9DragList.md +4 -2
  17. package/catalog/cards/G9Editor.md +1 -1
  18. package/catalog/cards/G9ErrorBoundary.md +3 -2
  19. package/catalog/cards/G9FormField.md +2 -2
  20. package/catalog/cards/G9ListRow.md +1 -1
  21. package/catalog/cards/G9Menu.md +1 -1
  22. package/catalog/cards/G9MenuList.md +2 -0
  23. package/catalog/cards/G9NotificationCenter.md +17 -0
  24. package/catalog/cards/G9NotificationCenterPanel.md +17 -0
  25. package/catalog/cards/G9PathNavigator.md +13 -0
  26. package/catalog/cards/G9PersonalThemeSheet.md +17 -0
  27. package/catalog/cards/G9Popover.md +1 -1
  28. package/catalog/cards/G9Provider.md +1 -1
  29. package/catalog/cards/G9RangeSlider.md +2 -2
  30. package/catalog/cards/G9ReaderSheet.md +17 -0
  31. package/catalog/cards/G9ReaderView.md +17 -0
  32. package/catalog/cards/G9SafeButton.md +2 -2
  33. package/catalog/cards/G9SearchEntry.md +1 -1
  34. package/catalog/cards/G9SecretValue.md +17 -0
  35. package/catalog/cards/G9ShortcutList.md +4 -0
  36. package/catalog/cards/G9ShortcutsSheet.md +3 -1
  37. package/catalog/cards/G9StatusPill.md +1 -1
  38. package/catalog/cards/G9Stepper.md +1 -1
  39. package/catalog/cards/G9SwitchRow.md +1 -1
  40. package/catalog/cards/G9Tag.md +1 -1
  41. package/catalog/cards/G9TextEntry.md +1 -1
  42. package/catalog/cards/G9UpdateBar.md +2 -1
  43. package/catalog/cards/G9VirtualList.md +1 -1
  44. package/catalog/cards/G9WallpaperSwatch.md +16 -0
  45. package/catalog/cards/G9WidgetSkeleton.md +9 -0
  46. package/catalog/cards/G9WidgetSlot.md +13 -0
  47. package/catalog/cards/PopupFrame.md +2 -2
  48. package/catalog/catalog.json +9460 -2155
  49. package/catalog/index.md +20 -3
  50. package/dist/.tsbuildinfo +1 -1
  51. package/dist/appearance/appearance.css +264 -0
  52. package/dist/appearance/appearance.css.map +1 -0
  53. package/dist/appearance/appearance.d.ts +148 -0
  54. package/dist/appearance/appearance.d.ts.map +1 -0
  55. package/dist/appearance/appearance.jsx +604 -0
  56. package/dist/appearance/index.d.ts +2 -0
  57. package/dist/appearance/index.d.ts.map +1 -0
  58. package/dist/appearance/index.jsx +1 -0
  59. package/dist/base/control.d.ts +15 -0
  60. package/dist/base/control.d.ts.map +1 -1
  61. package/dist/base/control.jsx +13 -1
  62. package/dist/base/index.d.ts +1 -1
  63. package/dist/base/index.d.ts.map +1 -1
  64. package/dist/base/index.jsx +1 -1
  65. package/dist/base/selection-item.d.ts +5 -0
  66. package/dist/base/selection-item.d.ts.map +1 -1
  67. package/dist/button/button.css +4 -0
  68. package/dist/button/button.css.map +1 -1
  69. package/dist/cascade/cascade.css +2 -0
  70. package/dist/cascade/cascade.css.map +1 -1
  71. package/dist/commands/commands.css +46 -0
  72. package/dist/commands/commands.css.map +1 -1
  73. package/dist/commands/index.d.ts +2 -2
  74. package/dist/commands/index.d.ts.map +1 -1
  75. package/dist/commands/index.jsx +2 -2
  76. package/dist/commands/keys.d.ts +15 -1
  77. package/dist/commands/keys.d.ts.map +1 -1
  78. package/dist/commands/keys.jsx +20 -1
  79. package/dist/commands/palette.d.ts +73 -7
  80. package/dist/commands/palette.d.ts.map +1 -1
  81. package/dist/commands/palette.jsx +174 -20
  82. package/dist/dashboard/dashboard.css +101 -0
  83. package/dist/dashboard/dashboard.css.map +1 -0
  84. package/dist/dashboard/dashboard.d.ts +73 -0
  85. package/dist/dashboard/dashboard.d.ts.map +1 -0
  86. package/dist/dashboard/dashboard.jsx +297 -0
  87. package/dist/dashboard/index.d.ts +3 -0
  88. package/dist/dashboard/index.d.ts.map +1 -0
  89. package/dist/dashboard/index.jsx +2 -0
  90. package/dist/dashboard/model.d.ts +53 -0
  91. package/dist/dashboard/model.d.ts.map +1 -0
  92. package/dist/dashboard/model.jsx +76 -0
  93. package/dist/display/code.css +109 -0
  94. package/dist/display/code.css.map +1 -0
  95. package/dist/display/code.d.ts +43 -0
  96. package/dist/display/code.d.ts.map +1 -0
  97. package/dist/display/code.jsx +101 -0
  98. package/dist/display/extras.d.ts +7 -2
  99. package/dist/display/extras.d.ts.map +1 -1
  100. package/dist/display/extras.jsx +13 -4
  101. package/dist/display/figures.d.ts.map +1 -1
  102. package/dist/display/figures.jsx +10 -2
  103. package/dist/display/index.d.ts +1 -0
  104. package/dist/display/index.d.ts.map +1 -1
  105. package/dist/display/index.jsx +1 -0
  106. package/dist/display/motion-figures.css +2 -0
  107. package/dist/display/motion-figures.css.map +1 -1
  108. package/dist/display/motion-figures.d.ts.map +1 -1
  109. package/dist/display/motion-figures.jsx +14 -7
  110. package/dist/display/status.d.ts +1 -1
  111. package/dist/display/status.d.ts.map +1 -1
  112. package/dist/display/status.jsx +15 -3
  113. package/dist/display/theme-preview.css +4 -0
  114. package/dist/display/theme-preview.css.map +1 -1
  115. package/dist/effects/effects.d.ts.map +1 -1
  116. package/dist/effects/effects.jsx +8 -1
  117. package/dist/fields/extra-entries.css +1 -0
  118. package/dist/fields/extra-entries.css.map +1 -1
  119. package/dist/fields/extra-entries.d.ts +4 -1
  120. package/dist/fields/extra-entries.d.ts.map +1 -1
  121. package/dist/fields/extra-entries.jsx +54 -19
  122. package/dist/fields/fields.css +21 -0
  123. package/dist/fields/fields.css.map +1 -1
  124. package/dist/fields/outlined-field.d.ts +9 -0
  125. package/dist/fields/outlined-field.d.ts.map +1 -1
  126. package/dist/fields/outlined-field.jsx +6 -1
  127. package/dist/fields/pin-entry.d.ts.map +1 -1
  128. package/dist/fields/pin-entry.jsx +36 -3
  129. package/dist/fields/text-entry.d.ts +4 -0
  130. package/dist/fields/text-entry.d.ts.map +1 -1
  131. package/dist/fields/text-entry.jsx +32 -25
  132. package/dist/fields/use-text-input.d.ts +3 -2
  133. package/dist/fields/use-text-input.d.ts.map +1 -1
  134. package/dist/fields/use-text-input.jsx +3 -0
  135. package/dist/header/app-bar.d.ts +6 -0
  136. package/dist/header/app-bar.d.ts.map +1 -1
  137. package/dist/header/app-bar.jsx +22 -8
  138. package/dist/header/header.css +14 -0
  139. package/dist/header/header.css.map +1 -1
  140. package/dist/host/bottom-overlays.d.ts +5 -0
  141. package/dist/host/bottom-overlays.d.ts.map +1 -1
  142. package/dist/host/bottom-overlays.jsx +17 -1
  143. package/dist/host/carry-contexts.d.ts +28 -0
  144. package/dist/host/carry-contexts.d.ts.map +1 -0
  145. package/dist/host/carry-contexts.jsx +76 -0
  146. package/dist/host/host.d.ts.map +1 -1
  147. package/dist/host/host.jsx +5 -1
  148. package/dist/host/index.d.ts +2 -0
  149. package/dist/host/index.d.ts.map +1 -1
  150. package/dist/host/index.jsx +2 -0
  151. package/dist/icon/icon.d.ts.map +1 -1
  152. package/dist/icon/icon.jsx +13 -9
  153. package/dist/index.d.ts +4 -0
  154. package/dist/index.d.ts.map +1 -1
  155. package/dist/layout/containers.d.ts.map +1 -1
  156. package/dist/layout/containers.jsx +2 -1
  157. package/dist/layout/layout.css +7 -0
  158. package/dist/layout/layout.css.map +1 -1
  159. package/dist/list/gestures.d.ts +39 -6
  160. package/dist/list/gestures.d.ts.map +1 -1
  161. package/dist/list/gestures.jsx +284 -89
  162. package/dist/list/index.d.ts +3 -2
  163. package/dist/list/index.d.ts.map +1 -1
  164. package/dist/list/index.jsx +2 -1
  165. package/dist/list/keyboard.d.ts +50 -0
  166. package/dist/list/keyboard.d.ts.map +1 -0
  167. package/dist/list/keyboard.jsx +117 -0
  168. package/dist/list/list.css +50 -5
  169. package/dist/list/list.css.map +1 -1
  170. package/dist/list/rows.d.ts +13 -1
  171. package/dist/list/rows.d.ts.map +1 -1
  172. package/dist/list/rows.jsx +42 -23
  173. package/dist/list/virtual-list.d.ts +27 -1
  174. package/dist/list/virtual-list.d.ts.map +1 -1
  175. package/dist/list/virtual-list.jsx +49 -4
  176. package/dist/notifications/index.d.ts +3 -0
  177. package/dist/notifications/index.d.ts.map +1 -0
  178. package/dist/notifications/index.jsx +2 -0
  179. package/dist/notifications/model.d.ts +47 -0
  180. package/dist/notifications/model.d.ts.map +1 -0
  181. package/dist/notifications/model.jsx +51 -0
  182. package/dist/notifications/notification-center.d.ts +98 -0
  183. package/dist/notifications/notification-center.d.ts.map +1 -0
  184. package/dist/notifications/notification-center.jsx +424 -0
  185. package/dist/notifications/notifications.css +266 -0
  186. package/dist/notifications/notifications.css.map +1 -0
  187. package/dist/orb/orb.css +2 -0
  188. package/dist/orb/orb.css.map +1 -1
  189. package/dist/pickers/pickers.css +15 -0
  190. package/dist/pickers/pickers.css.map +1 -1
  191. package/dist/plus-button/plus-button.css +2 -0
  192. package/dist/plus-button/plus-button.css.map +1 -1
  193. package/dist/plus-button/plus-button.d.ts.map +1 -1
  194. package/dist/plus-button/plus-button.jsx +2 -1
  195. package/dist/popover/popover.css +23 -1
  196. package/dist/popover/popover.css.map +1 -1
  197. package/dist/popover/popover.d.ts +14 -0
  198. package/dist/popover/popover.d.ts.map +1 -1
  199. package/dist/popover/popover.jsx +73 -12
  200. package/dist/popover/position.d.ts +6 -2
  201. package/dist/popover/position.d.ts.map +1 -1
  202. package/dist/popover/position.jsx +15 -4
  203. package/dist/popup/popup.css +3 -0
  204. package/dist/popup/popup.css.map +1 -1
  205. package/dist/provider/direction-scope.d.ts +8 -0
  206. package/dist/provider/direction-scope.d.ts.map +1 -1
  207. package/dist/provider/direction-scope.jsx +13 -2
  208. package/dist/provider/index.d.ts +1 -1
  209. package/dist/provider/index.d.ts.map +1 -1
  210. package/dist/provider/provider.css +7 -0
  211. package/dist/provider/provider.css.map +1 -1
  212. package/dist/provider/provider.d.ts +6 -1
  213. package/dist/provider/provider.d.ts.map +1 -1
  214. package/dist/provider/provider.jsx +22 -2
  215. package/dist/provider/settings.d.ts +14 -0
  216. package/dist/provider/settings.d.ts.map +1 -1
  217. package/dist/provider/settings.jsx +4 -1
  218. package/dist/range-slider/index.d.ts +1 -1
  219. package/dist/range-slider/index.d.ts.map +1 -1
  220. package/dist/range-slider/range-slider.css +69 -0
  221. package/dist/range-slider/range-slider.css.map +1 -1
  222. package/dist/range-slider/range-slider.d.ts +22 -0
  223. package/dist/range-slider/range-slider.d.ts.map +1 -1
  224. package/dist/range-slider/range-slider.jsx +34 -5
  225. package/dist/reader/index.d.ts +2 -0
  226. package/dist/reader/index.d.ts.map +1 -0
  227. package/dist/reader/index.jsx +1 -0
  228. package/dist/reader/reader.css +74 -0
  229. package/dist/reader/reader.css.map +1 -0
  230. package/dist/reader/reader.d.ts +76 -0
  231. package/dist/reader/reader.d.ts.map +1 -0
  232. package/dist/reader/reader.jsx +149 -0
  233. package/dist/route/index.d.ts +2 -0
  234. package/dist/route/index.d.ts.map +1 -1
  235. package/dist/route/index.jsx +2 -0
  236. package/dist/route/path-navigator.css +42 -0
  237. package/dist/route/path-navigator.css.map +1 -0
  238. package/dist/route/path-navigator.d.ts +25 -0
  239. package/dist/route/path-navigator.d.ts.map +1 -0
  240. package/dist/route/path-navigator.jsx +98 -0
  241. package/dist/route/path-router.d.ts +162 -0
  242. package/dist/route/path-router.d.ts.map +1 -0
  243. package/dist/route/path-router.jsx +327 -0
  244. package/dist/selection/selection-sheet.d.ts.map +1 -1
  245. package/dist/selection/selection-sheet.jsx +23 -10
  246. package/dist/selection/selection.css +18 -1
  247. package/dist/selection/selection.css.map +1 -1
  248. package/dist/sheet/frame.d.ts.map +1 -1
  249. package/dist/sheet/frame.jsx +9 -8
  250. package/dist/sheet/options.d.ts +6 -1
  251. package/dist/sheet/options.d.ts.map +1 -1
  252. package/dist/sheet/options.jsx +2 -1
  253. package/dist/sheet/panel-frame.d.ts.map +1 -1
  254. package/dist/sheet/panel-frame.jsx +5 -4
  255. package/dist/sheet/sizing.d.ts +3 -3
  256. package/dist/sheet/sizing.d.ts.map +1 -1
  257. package/dist/sheet/sizing.jsx +1 -0
  258. package/dist/shell/shell.css +18 -1
  259. package/dist/shell/shell.css.map +1 -1
  260. package/dist/shell/shell.d.ts +10 -1
  261. package/dist/shell/shell.d.ts.map +1 -1
  262. package/dist/shell/shell.jsx +13 -9
  263. package/dist/survey/survey.css +15 -0
  264. package/dist/survey/survey.css.map +1 -1
  265. package/dist/survey/survey.d.ts +6 -0
  266. package/dist/survey/survey.d.ts.map +1 -1
  267. package/dist/survey/survey.jsx +24 -6
  268. package/dist/swipe/swipe.css +2 -0
  269. package/dist/swipe/swipe.css.map +1 -1
  270. package/dist/tab-bar/flat.d.ts.map +1 -1
  271. package/dist/tab-bar/flat.jsx +53 -38
  272. package/dist/tab-bar/tab-bar.css +2 -0
  273. package/dist/tab-bar/tab-bar.css.map +1 -1
  274. package/dist/tab-bar/tab-bar.d.ts.map +1 -1
  275. package/dist/tab-bar/tab-bar.jsx +28 -6
  276. package/dist/tabs/tab-view.jsx +10 -3
  277. package/dist/tabs/tabs.css +5 -0
  278. package/dist/tabs/tabs.css.map +1 -1
  279. package/dist/toast/index.d.ts +1 -1
  280. package/dist/toast/index.d.ts.map +1 -1
  281. package/dist/toast/service.d.ts.map +1 -1
  282. package/dist/toast/service.jsx +18 -5
  283. package/dist/toast/store.d.ts +22 -0
  284. package/dist/toast/store.d.ts.map +1 -1
  285. package/dist/toast/store.jsx +35 -3
  286. package/dist/toast/toast.css +22 -0
  287. package/dist/toast/toast.css.map +1 -1
  288. package/dist/toggle/checkbox.d.ts +5 -0
  289. package/dist/toggle/checkbox.d.ts.map +1 -1
  290. package/dist/toggle/checkbox.jsx +7 -2
  291. package/dist/toggle/choice.css +35 -0
  292. package/dist/toggle/choice.css.map +1 -1
  293. package/dist/toggle/choice.d.ts +45 -0
  294. package/dist/toggle/choice.d.ts.map +1 -1
  295. package/dist/toggle/choice.jsx +97 -23
  296. package/dist/toggle/index.d.ts +1 -1
  297. package/dist/toggle/index.d.ts.map +1 -1
  298. package/dist/toggle/index.jsx +1 -1
  299. package/package.json +22 -2
  300. package/skills/g9-lynx-app/references/catalog-index.md +24 -8
  301. package/skills/g9-lynx-app/references/components/appearance.md +70 -0
  302. package/skills/g9-lynx-app/references/components/barcode.md +1 -1
  303. package/skills/g9-lynx-app/references/components/button.md +4 -4
  304. package/skills/g9-lynx-app/references/components/calendar-1.md +205 -0
  305. package/skills/g9-lynx-app/references/components/calendar-2.md +36 -0
  306. package/skills/g9-lynx-app/references/components/canvas.md +33 -0
  307. package/skills/g9-lynx-app/references/components/chat-1.md +199 -0
  308. package/skills/g9-lynx-app/references/components/chat-2.md +119 -0
  309. package/skills/g9-lynx-app/references/components/commands.md +10 -2
  310. package/skills/g9-lynx-app/references/components/commerce.md +1 -1
  311. package/skills/g9-lynx-app/references/components/dashboard.md +61 -0
  312. package/skills/g9-lynx-app/references/components/display-1.md +22 -21
  313. package/skills/g9-lynx-app/references/components/display-2.md +36 -39
  314. package/skills/g9-lynx-app/references/components/display-3.md +41 -2
  315. package/skills/g9-lynx-app/references/components/fields.md +5 -5
  316. package/skills/g9-lynx-app/references/components/header.md +1 -1
  317. package/skills/g9-lynx-app/references/components/host.md +11 -0
  318. package/skills/g9-lynx-app/references/components/layout-1.md +1 -1
  319. package/skills/g9-lynx-app/references/components/list.md +7 -5
  320. package/skills/g9-lynx-app/references/components/map.md +19 -1
  321. package/skills/g9-lynx-app/references/components/media-1.md +203 -0
  322. package/skills/g9-lynx-app/references/components/media-2.md +66 -0
  323. package/skills/g9-lynx-app/references/components/notifications.md +37 -0
  324. package/skills/g9-lynx-app/references/components/popover.md +4 -2
  325. package/skills/g9-lynx-app/references/components/popup.md +2 -2
  326. package/skills/g9-lynx-app/references/components/projects.md +73 -0
  327. package/skills/g9-lynx-app/references/components/provider.md +1 -1
  328. package/skills/g9-lynx-app/references/components/range-slider.md +2 -2
  329. package/skills/g9-lynx-app/references/components/reader.md +37 -0
  330. package/skills/g9-lynx-app/references/components/richtext.md +54 -0
  331. package/skills/g9-lynx-app/references/components/route.md +14 -0
  332. package/skills/g9-lynx-app/references/components/shell.md +3 -2
  333. package/skills/g9-lynx-app/references/components/toggle.md +20 -3
  334. package/skills/g9-lynx-app/references/provider-and-host.md +4 -3
  335. package/skills/g9-lynx-app/references/components/calendar.md +0 -128
  336. package/skills/g9-lynx-app/references/components/chat.md +0 -98
  337. package/skills/g9-lynx-app/references/components/media.md +0 -115
@@ -1,6 +1,6 @@
1
1
  import "./list.css";
2
2
  import { g9Haptic } from "@g9tm/lynxcontrols-foundation";
3
- import { useRef, useState } from "@lynx-js/react";
3
+ import { runOnBackground, runOnMainThread, useEffect, useMainThreadRef, useRef, useState } from "@lynx-js/react";
4
4
  import { g9IdProps } from "../base/control.jsx";
5
5
  import { G9ActivityIndicator } from "../display/activity-indicator.jsx";
6
6
  function moveItem(list, from, to) {
@@ -31,112 +31,307 @@ function dropIndex(heights, from, dy) {
31
31
  }
32
32
  return i;
33
33
  }
34
- const touchY = (e)=>{
35
- var _ref, _ref1;
36
- var _e_touches_, _e_touches, _e_detail;
37
- return null != (_ref = null != (_ref1 = null == (_e_touches = e.touches) ? void 0 : null == (_e_touches_ = _e_touches[0]) ? void 0 : _e_touches_.clientY) ? _ref1 : null == (_e_detail = e.detail) ? void 0 : _e_detail.y) ? _ref : 0;
38
- };
34
+ function pullDistance(dy, threshold) {
35
+ return Math.min(Math.max(0, dy / 2), 1.6 * threshold);
36
+ }
37
+ function pullDistanceMT(dy, threshold) {
38
+ 'main thread';
39
+ return Math.min(Math.max(0, dy / 2), 1.6 * threshold);
40
+ }
41
+ function pullIntent(dx, dy) {
42
+ if (Math.abs(dx) < 6 && Math.abs(dy) < 6) return null;
43
+ return dy > 0 && dy >= Math.abs(dx) ? 'pull' : 'other';
44
+ }
45
+ function pullIntentMT(dx, dy) {
46
+ 'main thread';
47
+ if (Math.abs(dx) < 6 && Math.abs(dy) < 6) return null;
48
+ return dy > 0 && dy >= Math.abs(dx) ? 'pull' : 'other';
49
+ }
39
50
  function G9PullToRefresh(props) {
40
51
  var _props_threshold;
41
52
  const threshold = null != (_props_threshold = props.threshold) ? _props_threshold : 72;
42
- const [pull, setPull] = useState(0);
43
53
  const [busy, setBusy] = useState(false);
44
- const top = useRef(0);
45
- const start = useRef(null);
46
- const armed = useRef(false);
47
- const shown = busy ? threshold : pull;
48
- const end = ()=>{
49
- if (null === start.current) return;
50
- start.current = null;
51
- if (pull >= threshold && !busy) {
52
- setBusy(true);
53
- setPull(threshold);
54
- Promise.resolve(props.onRefresh()).catch(()=>void 0).then(()=>{
55
- setBusy(false);
56
- setPull(0);
57
- });
58
- } else if (!busy) setPull(0);
59
- armed.current = false;
54
+ const blocked = true === props.disabled || busy;
55
+ const scroll = useMainThreadRef(null);
56
+ const indicator = useMainThreadRef(null);
57
+ const gesture = useMainThreadRef({
58
+ x: 0,
59
+ y: 0,
60
+ top: 0,
61
+ active: false,
62
+ intent: null,
63
+ distance: 0,
64
+ armed: false
65
+ });
66
+ const latest = useRef(props.onRefresh);
67
+ latest.current = props.onRefresh;
68
+ const refresh = ()=>{
69
+ setBusy(true);
70
+ Promise.resolve().then(()=>latest.current()).catch(()=>void 0).then(()=>setBusy(false));
60
71
  };
72
+ const armedHaptic = ()=>g9Haptic('impact');
73
+ function place(d, animated) {
74
+ 'main thread';
75
+ var _scroll_current, _indicator_current;
76
+ const transition = animated ? 'transform 220ms ease-out' : 'none';
77
+ null == (_scroll_current = scroll.current) || _scroll_current.setStyleProperties({
78
+ transition,
79
+ transform: `translateY(${d}px)`
80
+ });
81
+ null == (_indicator_current = indicator.current) || _indicator_current.setStyleProperties({
82
+ transition: animated ? 'transform 220ms ease-out, opacity 220ms ease-out' : 'none',
83
+ transform: `translateY(${d - 44}px)`,
84
+ opacity: String(Math.min(1, d / threshold))
85
+ });
86
+ }
87
+ function scrollMT(e) {
88
+ 'main thread';
89
+ var _ref;
90
+ var _e_detail;
91
+ gesture.current.top = null != (_ref = null == (_e_detail = e.detail) ? void 0 : _e_detail.scrollTop) ? _ref : 0;
92
+ }
93
+ function startMT(e) {
94
+ 'main thread';
95
+ var _ref, _ref1, _ref2;
96
+ var _e_touches, _e_detail, _e_detail1;
97
+ const g = gesture.current;
98
+ if ((null != (_ref = null == (_e_touches = e.touches) ? void 0 : _e_touches.length) ? _ref : 1) > 1) {
99
+ if (g.active && 'pull' === g.intent) place(0, true);
100
+ g.active = false;
101
+ return;
102
+ }
103
+ if (blocked || g.top > 0) return;
104
+ g.x = null != (_ref1 = null == (_e_detail = e.detail) ? void 0 : _e_detail.x) ? _ref1 : 0;
105
+ g.y = null != (_ref2 = null == (_e_detail1 = e.detail) ? void 0 : _e_detail1.y) ? _ref2 : 0;
106
+ g.active = true;
107
+ g.intent = null;
108
+ g.distance = 0;
109
+ g.armed = false;
110
+ }
111
+ function moveMT(e) {
112
+ 'main thread';
113
+ var _ref, _ref1, _ref2;
114
+ var _e_touches, _e_detail, _e_detail1;
115
+ const g = gesture.current;
116
+ if (!g.active) return;
117
+ if ((null != (_ref = null == (_e_touches = e.touches) ? void 0 : _e_touches.length) ? _ref : 1) > 1) {
118
+ if ('pull' === g.intent) place(0, true);
119
+ g.active = false;
120
+ return;
121
+ }
122
+ const dx = (null != (_ref1 = null == (_e_detail = e.detail) ? void 0 : _e_detail.x) ? _ref1 : 0) - g.x;
123
+ const dy = (null != (_ref2 = null == (_e_detail1 = e.detail) ? void 0 : _e_detail1.y) ? _ref2 : 0) - g.y;
124
+ if (null === g.intent) {
125
+ g.intent = pullIntentMT(dx, dy);
126
+ if ('other' === g.intent) {
127
+ g.active = false;
128
+ return;
129
+ }
130
+ if (null === g.intent) return;
131
+ }
132
+ g.distance = pullDistanceMT(dy, threshold);
133
+ if (g.distance >= threshold && !g.armed) {
134
+ g.armed = true;
135
+ runOnBackground(armedHaptic)();
136
+ }
137
+ place(g.distance, false);
138
+ }
139
+ function endMT() {
140
+ 'main thread';
141
+ const g = gesture.current;
142
+ if (!g.active) return;
143
+ g.active = false;
144
+ if ('pull' !== g.intent) return;
145
+ if (g.distance >= threshold) {
146
+ place(threshold, true);
147
+ runOnBackground(refresh)();
148
+ } else place(0, true);
149
+ }
150
+ const wasBusy = useRef(false);
151
+ useEffect(()=>{
152
+ if (wasBusy.current && !busy) runOnMainThread((d)=>{
153
+ 'main thread';
154
+ place(d, true);
155
+ })(0);
156
+ wasBusy.current = busy;
157
+ }, [
158
+ busy
159
+ ]);
61
160
  return <view className={`g9-ptr${props.className ? ` ${props.className}` : ''}`} {...g9IdProps(props.id)}>
62
- <view className="g9-ptr__indicator" style={{
63
- transform: `translateY(${shown - 44}px)`,
64
- opacity: Math.min(1, shown / threshold)
161
+ <view className="g9-ptr__indicator" main-thread:ref={indicator} style={{
162
+ transform: `translateY(${busy ? threshold - 44 : -44}px)`,
163
+ opacity: busy ? 1 : 0
65
164
  }}>
66
- <G9ActivityIndicator running={busy || shown >= 0.6 * threshold} size={22}/>
165
+ <G9ActivityIndicator running={busy} size={22}/>
67
166
  </view>
68
- <scroll-view className="g9-ptr__scroll" scroll-orientation="vertical" style={{
69
- transform: `translateY(${shown}px)`,
70
- transition: null === start.current ? 'transform 220ms ease-out' : 'none'
71
- }} bindscroll={(e)=>{
72
- top.current = e.detail.scrollTop;
73
- }} bindtouchstart={(e)=>{
74
- if (props.disabled || busy || top.current > 0) return;
75
- start.current = touchY(e);
76
- }} bindtouchmove={(e)=>{
77
- if (null === start.current) return;
78
- const d = Math.max(0, (touchY(e) - start.current) / 2);
79
- if (d >= threshold && !armed.current) {
80
- armed.current = true;
81
- g9Haptic('impact');
82
- }
83
- setPull(Math.min(d, 1.6 * threshold));
84
- }} bindtouchend={end} bindtouchcancel={end}>
167
+ <scroll-view className="g9-ptr__scroll" scroll-orientation="vertical" main-thread:ref={scroll} main-thread:bindscroll={scrollMT} main-thread:bindtouchstart={startMT} main-thread:bindtouchmove={moveMT} main-thread:bindtouchend={endMT} main-thread:bindtouchcancel={endMT}>
85
168
  {props.children}
86
169
  </scroll-view>
87
170
  </view>;
88
171
  }
172
+ function dropIndexMT(heights, from, dy) {
173
+ 'main thread';
174
+ let i = from;
175
+ let moved = dy;
176
+ if (moved > 0) {
177
+ var _heights_;
178
+ while(i < heights.length - 1 && moved > (null != (_heights_ = heights[i + 1]) ? _heights_ : 0) / 2){
179
+ var _heights_1;
180
+ moved -= null != (_heights_1 = heights[i + 1]) ? _heights_1 : 0;
181
+ i++;
182
+ }
183
+ } else {
184
+ var _heights_2;
185
+ while(i > 0 && -moved > (null != (_heights_2 = heights[i - 1]) ? _heights_2 : 0) / 2){
186
+ var _heights_3;
187
+ moved += null != (_heights_3 = heights[i - 1]) ? _heights_3 : 0;
188
+ i--;
189
+ }
190
+ }
191
+ return i;
192
+ }
193
+ function dragOffset(i, from, target, liftedHeight) {
194
+ if (null === from || i === from) return 0;
195
+ if (from < i && i <= target) return -liftedHeight;
196
+ if (target <= i && i < from) return liftedHeight;
197
+ return 0;
198
+ }
199
+ const DRAG_ICON = '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><circle cx="9" cy="6" r="1.6" fill="#8a8f98"/><circle cx="15" cy="6" r="1.6" fill="#8a8f98"/><circle cx="9" cy="12" r="1.6" fill="#8a8f98"/><circle cx="15" cy="12" r="1.6" fill="#8a8f98"/><circle cx="9" cy="18" r="1.6" fill="#8a8f98"/><circle cx="15" cy="18" r="1.6" fill="#8a8f98"/></svg>';
200
+ function DragRow(props) {
201
+ const { index, heights } = props;
202
+ const inner = useMainThreadRef(null);
203
+ const gesture = useMainThreadRef({
204
+ active: false,
205
+ startY: 0,
206
+ target: index
207
+ });
208
+ const disabled = props.disabled;
209
+ const onLift = props.onLift;
210
+ const onTarget = props.onTarget;
211
+ const onDrop = props.onDrop;
212
+ function beginMT(y) {
213
+ 'main thread';
214
+ var _inner_current;
215
+ gesture.current = {
216
+ active: true,
217
+ startY: y,
218
+ target: index
219
+ };
220
+ null == (_inner_current = inner.current) || _inner_current.setStyleProperties({
221
+ transition: 'none',
222
+ transform: 'translateY(0px)'
223
+ });
224
+ }
225
+ function handleStartMT(e) {
226
+ 'main thread';
227
+ var _ref, _ref1;
228
+ var _e_detail, _e_touches_, _e_touches;
229
+ if (disabled) return;
230
+ beginMT(null != (_ref = null != (_ref1 = null == (_e_detail = e.detail) ? void 0 : _e_detail.y) ? _ref1 : null == (_e_touches = e.touches) ? void 0 : null == (_e_touches_ = _e_touches[0]) ? void 0 : _e_touches_.clientY) ? _ref : 0);
231
+ runOnBackground(onLift)(index);
232
+ }
233
+ function moveMT(e) {
234
+ 'main thread';
235
+ var _ref, _ref1;
236
+ var _e_detail, _e_touches_, _e_touches, _inner_current;
237
+ const g = gesture.current;
238
+ if (!g.active) return;
239
+ const dy = (null != (_ref = null != (_ref1 = null == (_e_detail = e.detail) ? void 0 : _e_detail.y) ? _ref1 : null == (_e_touches = e.touches) ? void 0 : null == (_e_touches_ = _e_touches[0]) ? void 0 : _e_touches_.clientY) ? _ref : 0) - g.startY;
240
+ null == (_inner_current = inner.current) || _inner_current.setStyleProperties({
241
+ transform: `translateY(${dy}px)`
242
+ });
243
+ const to = dropIndexMT(heights, index, dy);
244
+ if (to !== g.target) {
245
+ g.target = to;
246
+ runOnBackground(onTarget)(to);
247
+ }
248
+ }
249
+ function endMT() {
250
+ 'main thread';
251
+ var _inner_current;
252
+ const g = gesture.current;
253
+ if (!g.active) return;
254
+ g.active = false;
255
+ null == (_inner_current = inner.current) || _inner_current.setStyleProperties({
256
+ transition: 'none',
257
+ transform: 'translateY(0px)'
258
+ });
259
+ runOnBackground(onDrop)(g.target);
260
+ }
261
+ const handleNode = props.handle ? <view className="g9-drag-list__handle" main-thread:bindtouchstart={handleStartMT} accessibility-element={true} accessibility-traits="button" accessibility-label={props.handleLabel}>
262
+ <svg className="g9-drag-list__handle-icon" content={DRAG_ICON}/>
263
+ </view> : null;
264
+ return <view className={`g9-drag-list__row${props.lifted ? ' g9-drag-list__row--lifted' : ''}`} style={{
265
+ transform: `translateY(${props.offset}px)`,
266
+ transition: props.lifted ? 'none' : 'transform 160ms ease-out'
267
+ }} bindlayoutchange={(e)=>props.onHeight(index, Math.round(e.detail.height))} {...props.handle ? {} : {
268
+ bindlongpress: (e)=>{
269
+ var _ref, _ref1;
270
+ var _e_detail, _e_touches_, _e_touches;
271
+ if (disabled) return;
272
+ const y = null != (_ref = null != (_ref1 = null == (_e_detail = e.detail) ? void 0 : _e_detail.y) ? _ref1 : null == (_e_touches = e.touches) ? void 0 : null == (_e_touches_ = _e_touches[0]) ? void 0 : _e_touches_.clientY) ? _ref : 0;
273
+ runOnMainThread(beginMT)(y);
274
+ onLift(index);
275
+ }
276
+ }} main-thread:bindtouchmove={moveMT} main-thread:bindtouchend={endMT} main-thread:bindtouchcancel={endMT}>
277
+ <view className="g9-drag-list__inner" main-thread:ref={inner}>
278
+ {props.render(handleNode)}
279
+ </view>
280
+ </view>;
281
+ }
89
282
  function G9DragList(props) {
90
283
  var _props_rowHeight;
91
- const h = null != (_props_rowHeight = props.rowHeight) ? _props_rowHeight : 56;
92
- const [drag, setDrag] = useState(null);
93
- const startY = useRef(0);
94
- const heights = props.items.map(()=>h);
95
- const target = drag ? dropIndex(heights, drag.from, drag.dy) : -1;
96
- const offsetOf = (i)=>{
97
- if (!drag || i === drag.from) return 0;
98
- if (drag.from < i && i <= target) return -h;
99
- if (target <= i && i < drag.from) return h;
100
- return 0;
284
+ const est = null != (_props_rowHeight = props.rowHeight) ? _props_rowHeight : 56;
285
+ const [lift, setLift] = useState(null);
286
+ const [measured, setMeasured] = useState({});
287
+ const keys = props.items.map((item)=>props.getKey(item));
288
+ const heights = keys.map((k)=>{
289
+ var _measured_k;
290
+ return null != (_measured_k = measured[k]) ? _measured_k : est;
291
+ });
292
+ const latest = useRef(props);
293
+ latest.current = props;
294
+ const reorder = (from, to)=>{
295
+ if (to === from || to < 0 || to >= latest.current.items.length) return;
296
+ g9Haptic('select');
297
+ latest.current.onReorder(moveItem(latest.current.items, from, to));
101
298
  };
102
- const drop = ()=>{
103
- if (!drag) return;
104
- const to = dropIndex(heights, drag.from, drag.dy);
105
- setDrag(null);
106
- if (to !== drag.from) {
107
- g9Haptic('select');
108
- props.onReorder(moveItem(props.items, drag.from, to));
109
- }
110
- };
111
- return <view className="g9-drag-list" {...g9IdProps(props.id)} style={{
112
- height: `${props.items.length * h}px`
113
- }}>
299
+ return <view className="g9-drag-list" {...g9IdProps(props.id)}>
114
300
  {props.items.map((item, i)=>{
115
- var _ref;
116
- const lifted = (null == drag ? void 0 : drag.from) === i;
117
- return <view key={props.getKey(item)} className={`g9-drag-list__row${lifted ? ' g9-drag-list__row--lifted' : ''}`} style={{
118
- top: `${i * h}px`,
119
- height: `${h}px`,
120
- transform: `translateY(${lifted ? null != (_ref = null == drag ? void 0 : drag.dy) ? _ref : 0 : offsetOf(i)}px)`,
121
- transition: lifted ? 'none' : 'transform 160ms ease-out'
122
- }} bindlongpress={(e)=>{
123
- if (props.disabled) return;
124
- g9Haptic('impact');
125
- startY.current = touchY(e);
126
- setDrag({
127
- from: i,
128
- dy: 0
301
+ var _heights_lift_from, _props_handleLabel;
302
+ const key = keys[i];
303
+ const lifted = (null == lift ? void 0 : lift.from) === i;
304
+ const controls = (handle)=>({
305
+ index: i,
306
+ handle,
307
+ moveUp: ()=>reorder(i, i - 1),
308
+ moveDown: ()=>reorder(i, i + 1),
309
+ canMoveUp: i > 0,
310
+ canMoveDown: i < props.items.length - 1
129
311
  });
130
- }} bindtouchmove={(e)=>{
131
- if ((null == drag ? void 0 : drag.from) !== i) return;
132
- setDrag({
133
- from: i,
134
- dy: touchY(e) - startY.current
312
+ return <DragRow key={key} index={i} count={props.items.length} heights={heights} lifted={lifted} offset={lift ? dragOffset(i, lift.from, lift.target, null != (_heights_lift_from = heights[lift.from]) ? _heights_lift_from : est) : 0} handle={true === props.handle} handleLabel={null != (_props_handleLabel = props.handleLabel) ? _props_handleLabel : 'Reorder'} disabled={true === props.disabled} onLift={(from)=>{
313
+ var _latest_current_onStart, _latest_current;
314
+ g9Haptic('impact');
315
+ setLift({
316
+ from,
317
+ target: from
135
318
  });
136
- }} bindtouchend={drop} bindtouchcancel={drop}>
137
- {props.renderItem(item, lifted)}
138
- </view>;
319
+ const it = latest.current.items[from];
320
+ if (void 0 !== it) null == (_latest_current_onStart = (_latest_current = latest.current).onStart) || _latest_current_onStart.call(_latest_current, it, from);
321
+ }} onTarget={(to)=>setLift((l)=>l ? {
322
+ ...l,
323
+ target: to
324
+ } : l)} onDrop={(to)=>{
325
+ const from = i;
326
+ setLift(null);
327
+ reorder(from, to);
328
+ }} onHeight={(_, h)=>{
329
+ if (h > 0 && measured[key] !== h) setMeasured((m)=>({
330
+ ...m,
331
+ [key]: h
332
+ }));
333
+ }} render={(handle)=>props.renderItem(item, lifted, controls(handle))}/>;
139
334
  })}
140
335
  </view>;
141
336
  }
142
- export { G9DragList, G9PullToRefresh, dropIndex, moveItem };
337
+ export { G9DragList, G9PullToRefresh, dragOffset, dropIndex, moveItem, pullDistance, pullIntent };
@@ -1,4 +1,5 @@
1
- export { dropIndex, G9DragList, type G9DragListProps, G9PullToRefresh, type G9PullToRefreshProps, moveItem, } from './gestures.js';
1
+ export { dragOffset, dropIndex, G9DragList, type G9DragListProps, type G9DragRowControls, G9PullToRefresh, type G9PullToRefreshProps, moveItem, } from './gestures.js';
2
+ export { type G9ListKeyAction, type G9ListKeyOptions, type G9UseListKeyboardOptions, listKeyAction, typeAheadIndex, useG9ListKeyboard, } from './keyboard.js';
2
3
  export { G9ListRow, type G9ListRowProps, G9Pager, type G9PagerProps, G9SettingsGroup, type G9SettingsGroupProps, G9SwitchRow, type G9SwitchRowProps, } from './rows.js';
3
- export { G9VirtualList, type G9VirtualListHandle, type G9VirtualListProps, g9LastRowWatcher, g9ListFirstBatch, g9ListNextBatch, g9ListProgressiveFrom, g9ReadableLanding, } from './virtual-list.js';
4
+ export { G9VirtualList, type G9VirtualListHandle, type G9VirtualListKeyboard, type G9VirtualListProps, type G9VirtualRowState, g9LastRowWatcher, g9ListFirstBatch, g9ListNextBatch, g9ListProgressiveFrom, g9ReadableLanding, } from './virtual-list.js';
4
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/list/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,EACT,UAAU,EACV,KAAK,eAAe,EACpB,eAAe,EACf,KAAK,oBAAoB,EACzB,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,SAAS,EACT,KAAK,cAAc,EACnB,OAAO,EACP,KAAK,YAAY,EACjB,eAAe,EACf,KAAK,oBAAoB,EACzB,WAAW,EACX,KAAK,gBAAgB,GACtB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/list/index.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,SAAS,EACT,UAAU,EACV,KAAK,eAAe,EACpB,KAAK,iBAAiB,EACtB,eAAe,EACf,KAAK,oBAAoB,EACzB,QAAQ,GACT,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,gBAAgB,EACrB,KAAK,wBAAwB,EAC7B,aAAa,EACb,cAAc,EACd,iBAAiB,GAClB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,SAAS,EACT,KAAK,cAAc,EACnB,OAAO,EACP,KAAK,YAAY,EACjB,eAAe,EACf,KAAK,oBAAoB,EACzB,WAAW,EACX,KAAK,gBAAgB,GACtB,MAAM,QAAQ,CAAC;AAChB,OAAO,EACL,aAAa,EACb,KAAK,mBAAmB,EACxB,KAAK,qBAAqB,EAC1B,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACtB,gBAAgB,EAChB,gBAAgB,EAChB,eAAe,EACf,qBAAqB,EACrB,iBAAiB,GAClB,MAAM,gBAAgB,CAAC"}
@@ -1,3 +1,4 @@
1
- export { G9DragList, G9PullToRefresh, dropIndex, moveItem } from "./gestures.jsx";
1
+ export { G9DragList, G9PullToRefresh, dragOffset, dropIndex, moveItem } from "./gestures.jsx";
2
+ export { listKeyAction, typeAheadIndex, useG9ListKeyboard } from "./keyboard.jsx";
2
3
  export { G9ListRow, G9Pager, G9SettingsGroup, G9SwitchRow } from "./rows.jsx";
3
4
  export { G9VirtualList, g9LastRowWatcher, g9ListFirstBatch, g9ListNextBatch, g9ListProgressiveFrom, g9ReadableLanding } from "./virtual-list.jsx";
@@ -0,0 +1,50 @@
1
+ import type { G9KeyEvent } from '@g9tm/lynxcontrols-foundation';
2
+ /** What a key does to the active row (pure). */
3
+ export type G9ListKeyAction = {
4
+ readonly kind: 'move';
5
+ readonly index: number;
6
+ } | {
7
+ readonly kind: 'activate';
8
+ readonly index: number;
9
+ } | {
10
+ readonly kind: 'none';
11
+ };
12
+ /** Options of {@link listKeyAction}. */
13
+ export interface G9ListKeyOptions {
14
+ /** J and K move too (G9Hub's lists, mail-style). Default true. */
15
+ readonly vim?: boolean;
16
+ /** The list is horizontal: the left and right arrows move (mirrored in RTL). Default false. */
17
+ readonly horizontal?: boolean;
18
+ readonly rtl?: boolean;
19
+ /** Past the last row comes the first. Default false. */
20
+ readonly wrap?: boolean;
21
+ /** Rows that cannot be active (a heading, a disabled entry). */
22
+ readonly skip?: (index: number) => boolean;
23
+ }
24
+ /** The action of `e` on a list of `count` rows whose active row is `active` (-1: none yet). */
25
+ export declare function listKeyAction(e: G9KeyEvent, active: number, count: number, o?: G9ListKeyOptions): G9ListKeyAction;
26
+ /**
27
+ * The next row whose label starts with `typed` (the search key: Persian spelling variants and case fold), after
28
+ * `active` and around; -1 when none.
29
+ */
30
+ export declare function typeAheadIndex(labels: readonly string[], typed: string, active: number): number;
31
+ /** Options of {@link useG9ListKeyboard}. */
32
+ export interface G9UseListKeyboardOptions extends G9ListKeyOptions {
33
+ readonly count: number;
34
+ /** Enter on the active row. */
35
+ readonly onActivate: (index: number) => void;
36
+ /** A row's words, for type-ahead; without it type-ahead is off. */
37
+ readonly labelOf?: (index: number) => string;
38
+ /** After the active row changed (scroll it into view). */
39
+ readonly onActiveChange?: (index: number) => void;
40
+ /** Default true. */
41
+ readonly enabled?: boolean;
42
+ /** The row active at first. Default none (-1): the first key picks the first or last row. */
43
+ readonly initial?: number;
44
+ }
45
+ /** Keyboard navigation of a list: the active row's index (-1 none) and a setter (a pointer hover may move it). */
46
+ export declare function useG9ListKeyboard(o: G9UseListKeyboardOptions): {
47
+ readonly active: number;
48
+ setActive(i: number): void;
49
+ };
50
+ //# sourceMappingURL=keyboard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"keyboard.d.ts","sourceRoot":"","sources":["../../src/list/keyboard.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAC;AAKhE,gDAAgD;AAChD,MAAM,MAAM,eAAe,GACvB;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACjD;IAAE,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAA;CAAE,GACrD;IAAE,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAE9B,wCAAwC;AACxC,MAAM,WAAW,gBAAgB;IAC/B,kEAAkE;IAClE,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,+FAA+F;IAC/F,QAAQ,CAAC,UAAU,CAAC,EAAE,OAAO,CAAC;IAC9B,QAAQ,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;IACvB,wDAAwD;IACxD,QAAQ,CAAC,IAAI,CAAC,EAAE,OAAO,CAAC;IACxB,gEAAgE;IAChE,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,OAAO,CAAC;CAC5C;AAeD,+FAA+F;AAC/F,wBAAgB,aAAa,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,CAAC,GAAE,gBAAqB,GAAG,eAAe,CAgBrH;AAED;;;GAGG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,SAAS,MAAM,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAS/F;AAED,4CAA4C;AAC5C,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAChE,QAAQ,CAAC,KAAK,EAAE,MAAM,CAAC;IACvB,+BAA+B;IAC/B,QAAQ,CAAC,UAAU,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,mEAAmE;IACnE,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC7C,0DAA0D;IAC1D,QAAQ,CAAC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClD,oBAAoB;IACpB,QAAQ,CAAC,OAAO,CAAC,EAAE,OAAO,CAAC;IAC3B,6FAA6F;IAC7F,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC;CAC3B;AAED,kHAAkH;AAClH,wBAAgB,iBAAiB,CAAC,CAAC,EAAE,wBAAwB,GAAG;IAC9D,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,SAAS,CAAC,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC5B,CAqCA"}
@@ -0,0 +1,117 @@
1
+ import { searchKey } from "@g9tm/lynxcontrols-foundation";
2
+ import { useRef, useState } from "@lynx-js/react";
3
+ import { useG9Keys } from "../commands/keys.jsx";
4
+ function step(from, by, count, o) {
5
+ let i = from;
6
+ for(let n = 0; n < count; n++){
7
+ var _o_skip;
8
+ i += by;
9
+ if (i < 0 || i >= count) {
10
+ if (!o.wrap) return from;
11
+ i = (i + count) % count;
12
+ }
13
+ if (!(null == (_o_skip = o.skip) ? void 0 : _o_skip.call(o, i))) return i;
14
+ }
15
+ return from;
16
+ }
17
+ function listKeyAction(e, active, count, o = {}) {
18
+ if (count <= 0 || e.ctrl || e.meta || e.alt) return {
19
+ kind: 'none'
20
+ };
21
+ const k = 1 === e.key.length ? e.key.toLowerCase() : e.key;
22
+ const vim = false !== o.vim;
23
+ const forward = o.horizontal ? o.rtl ? 'ArrowLeft' : 'ArrowRight' : 'ArrowDown';
24
+ const back = o.horizontal ? o.rtl ? 'ArrowRight' : 'ArrowLeft' : 'ArrowUp';
25
+ const first = ()=>step(-1, 1, count, {
26
+ ...o,
27
+ wrap: false
28
+ });
29
+ const last = ()=>step(count, -1, count, {
30
+ ...o,
31
+ wrap: false
32
+ });
33
+ if (k === forward || vim && 'j' === k) return {
34
+ kind: 'move',
35
+ index: active < 0 ? first() : step(active, 1, count, o)
36
+ };
37
+ if (k === back || vim && 'k' === k) return {
38
+ kind: 'move',
39
+ index: active < 0 ? last() : step(active, -1, count, o)
40
+ };
41
+ if ('Home' === k) return {
42
+ kind: 'move',
43
+ index: first()
44
+ };
45
+ if ('End' === k) return {
46
+ kind: 'move',
47
+ index: last()
48
+ };
49
+ if (('Enter' === k || ' ' === k) && active >= 0) return {
50
+ kind: 'activate',
51
+ index: active
52
+ };
53
+ return {
54
+ kind: 'none'
55
+ };
56
+ }
57
+ function typeAheadIndex(labels, typed, active) {
58
+ const q = searchKey(typed);
59
+ if (!q) return -1;
60
+ const n = labels.length;
61
+ for(let d = 1; d <= n; d++){
62
+ var _labels_i;
63
+ const i = (Math.max(-1, active) + d) % n;
64
+ if (searchKey(null != (_labels_i = labels[i]) ? _labels_i : '').startsWith(q)) return i;
65
+ }
66
+ return -1;
67
+ }
68
+ function useG9ListKeyboard(o) {
69
+ var _o_initial;
70
+ const [active, setActiveState] = useState(null != (_o_initial = o.initial) ? _o_initial : -1);
71
+ const typed = useRef({
72
+ text: '',
73
+ at: 0
74
+ });
75
+ const setActive = (i)=>{
76
+ var _o_onActiveChange;
77
+ setActiveState(i);
78
+ null == (_o_onActiveChange = o.onActiveChange) || _o_onActiveChange.call(o, i);
79
+ };
80
+ const current = active >= o.count ? -1 : active;
81
+ useG9Keys((e)=>{
82
+ const action = listKeyAction(e, current, o.count, o);
83
+ if ('move' === action.kind) {
84
+ if (action.index !== current) setActive(action.index);
85
+ return true;
86
+ }
87
+ if ('activate' === action.kind) {
88
+ o.onActivate(action.index);
89
+ return true;
90
+ }
91
+ if (o.labelOf && 1 === e.key.length && !e.ctrl && !e.meta && !e.alt && ' ' !== e.key) {
92
+ const now = Date.now();
93
+ const text = now - typed.current.at < 700 ? typed.current.text + e.key : e.key;
94
+ typed.current = {
95
+ text,
96
+ at: now
97
+ };
98
+ const labels = Array.from({
99
+ length: o.count
100
+ }, (_, i)=>o.labelOf(i));
101
+ const from = text.length > 1 ? current - 1 : current;
102
+ const i = typeAheadIndex(labels, text, from);
103
+ if (i >= 0) {
104
+ if (i !== current) setActive(i);
105
+ return true;
106
+ }
107
+ }
108
+ return false;
109
+ }, {
110
+ enabled: false !== o.enabled && o.count > 0
111
+ });
112
+ return {
113
+ active: current,
114
+ setActive
115
+ };
116
+ }
117
+ export { listKeyAction, typeAheadIndex, useG9ListKeyboard };