@celljs/ta-web 4.9.1 → 4.10.0

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 (302) hide show
  1. package/README.en.md +4 -3
  2. package/README.md +4 -3
  3. package/esm/browser/assistant/assistant-chat-list.js +8 -2
  4. package/esm/browser/assistant/assistant-extension.d.ts +8 -1
  5. package/esm/browser/assistant/assistant-extension.js +20 -0
  6. package/esm/browser/assistant/assistant-protocol.d.ts +3 -1
  7. package/esm/browser/assistant/assistant-task-util.d.ts +2 -0
  8. package/esm/browser/assistant/assistant-task-util.js +5 -3
  9. package/esm/browser/assistant/assistant-view.js +81 -56
  10. package/esm/browser/assistant/assistant.d.ts +10 -1
  11. package/esm/browser/assistant/assistant.js +44 -5
  12. package/esm/browser/chat/chat-packages.d.ts +39 -0
  13. package/esm/browser/chat/chat-packages.js +70 -0
  14. package/esm/browser/chat/chat-protocol.d.ts +23 -1
  15. package/esm/browser/chat/chat-stores.d.ts +59 -0
  16. package/esm/browser/chat/chat-stores.js +121 -0
  17. package/esm/browser/chat/chat-util.d.ts +17 -0
  18. package/esm/browser/chat/chat-util.js +61 -0
  19. package/esm/browser/chat/chat-view.js +33 -12
  20. package/esm/browser/chat/chat.d.ts +31 -39
  21. package/esm/browser/chat/chat.js +226 -175
  22. package/esm/browser/components/app-nav.d.ts +6 -3
  23. package/esm/browser/components/app-nav.js +19 -10
  24. package/esm/browser/components/app-shell-hooks.d.ts +2 -2
  25. package/esm/browser/components/app-shell-hooks.js +7 -3
  26. package/esm/browser/components/app-view.js +75 -21
  27. package/esm/browser/components/chat-list.d.ts +20 -2
  28. package/esm/browser/components/chat-list.js +138 -22
  29. package/esm/browser/components/composer-box.d.ts +5 -5
  30. package/esm/browser/components/composer-box.js +111 -4
  31. package/esm/browser/components/composer.d.ts +7 -0
  32. package/esm/browser/components/composer.js +5 -4
  33. package/esm/browser/components/connection-bar.js +50 -17
  34. package/esm/browser/components/context-menu.d.ts +30 -4
  35. package/esm/browser/components/context-menu.js +199 -37
  36. package/esm/browser/components/conversation-scroll.d.ts +129 -6
  37. package/esm/browser/components/conversation-scroll.js +429 -109
  38. package/esm/browser/components/earlier-messages.d.ts +2 -1
  39. package/esm/browser/components/earlier-messages.js +2 -17
  40. package/esm/browser/components/editor-area.d.ts +3 -1
  41. package/esm/browser/components/editor-area.js +6 -5
  42. package/esm/browser/components/empty-pictures.d.ts +0 -2
  43. package/esm/browser/components/empty-pictures.js +0 -16
  44. package/esm/browser/components/folder-picker.d.ts +5 -2
  45. package/esm/browser/components/folder-picker.js +26 -8
  46. package/esm/browser/components/held-talk.d.ts +28 -0
  47. package/esm/browser/components/held-talk.js +76 -0
  48. package/esm/browser/components/host-view.d.ts +1 -1
  49. package/esm/browser/components/icon.d.ts +2 -2
  50. package/esm/browser/components/icon.js +5 -6
  51. package/esm/browser/components/image-viewer.d.ts +124 -0
  52. package/esm/browser/components/image-viewer.js +397 -0
  53. package/esm/browser/components/lightbox.d.ts +11 -0
  54. package/esm/browser/components/lightbox.js +24 -0
  55. package/esm/browser/components/markdown.d.ts +6 -2
  56. package/esm/browser/components/markdown.js +24 -10
  57. package/esm/browser/components/media.js +1 -10
  58. package/esm/browser/components/message-footer.d.ts +16 -2
  59. package/esm/browser/components/message-footer.js +29 -12
  60. package/esm/browser/components/message-list.d.ts +24 -3
  61. package/esm/browser/components/message-list.js +149 -20
  62. package/esm/browser/components/message-menu.d.ts +3 -1
  63. package/esm/browser/components/message-menu.js +18 -3
  64. package/esm/browser/components/nav-places.d.ts +16 -1
  65. package/esm/browser/components/nav-places.js +12 -3
  66. package/esm/browser/components/phone-shell.d.ts +4 -1
  67. package/esm/browser/components/phone-shell.js +3 -1
  68. package/esm/browser/components/run-status.js +3 -3
  69. package/esm/browser/components/session-settings.d.ts +6 -0
  70. package/esm/browser/components/session-settings.js +14 -1
  71. package/esm/browser/components/session-view.js +8 -4
  72. package/esm/browser/components/settings-parts.d.ts +2 -2
  73. package/esm/browser/components/settings-parts.js +24 -1
  74. package/esm/browser/components/swipe-row.d.ts +2 -2
  75. package/esm/browser/components/swipe-row.js +7 -3
  76. package/esm/browser/components/tool-view.js +14 -12
  77. package/esm/browser/components/voice-button.d.ts +1 -1
  78. package/esm/browser/components/voice-button.js +1 -1
  79. package/esm/browser/components/voice-talk.d.ts +43 -0
  80. package/esm/browser/components/voice-talk.js +222 -0
  81. package/esm/browser/device/device.d.ts +3 -0
  82. package/esm/browser/device/device.js +11 -1
  83. package/esm/browser/device/hold.d.ts +42 -0
  84. package/esm/browser/device/hold.js +136 -0
  85. package/esm/browser/device/launch-screen.d.ts +1 -1
  86. package/esm/browser/device/launch-screen.js +1 -1
  87. package/esm/browser/device/long-press.d.ts +2 -0
  88. package/esm/browser/device/long-press.js +16 -1
  89. package/esm/browser/device/pull-down.d.ts +4 -2
  90. package/esm/browser/device/pull-down.js +64 -76
  91. package/esm/browser/device/row-swipe.d.ts +35 -10
  92. package/esm/browser/device/row-swipe.js +149 -71
  93. package/esm/browser/device/shake-undo.d.ts +16 -0
  94. package/esm/browser/device/shake-undo.js +59 -0
  95. package/esm/browser/device/sheet-swipe.d.ts +118 -18
  96. package/esm/browser/device/sheet-swipe.js +406 -107
  97. package/esm/browser/extension/web-extension-api.d.ts +97 -1
  98. package/esm/browser/extension/web-extension-code.d.ts +6 -0
  99. package/esm/browser/extension/web-extension-code.js +24 -0
  100. package/esm/browser/extension/web-extension-protocol.d.ts +23 -1
  101. package/esm/browser/extension/web-extension-protocol.js +8 -0
  102. package/esm/browser/extension/web-extensions.d.ts +14 -1
  103. package/esm/browser/extension/web-extensions.js +122 -23
  104. package/esm/browser/files/files-protocol.d.ts +25 -0
  105. package/esm/browser/files/files-protocol.js +2 -0
  106. package/esm/browser/files/files.d.ts +35 -0
  107. package/esm/browser/files/files.js +119 -0
  108. package/esm/browser/i18n/locales.d.ts +24 -2
  109. package/esm/browser/i18n/messages.d.ts +23 -1
  110. package/esm/browser/i18n/messages.js +48 -4
  111. package/esm/browser/index.d.ts +6 -0
  112. package/esm/browser/index.js +6 -0
  113. package/esm/browser/notices/notices-protocol.d.ts +9 -1
  114. package/esm/browser/notices/notices.d.ts +2 -0
  115. package/esm/browser/notices/notices.js +20 -10
  116. package/esm/browser/offline/device-values.d.ts +55 -0
  117. package/esm/browser/offline/device-values.js +142 -0
  118. package/esm/browser/offline/kept-chats-protocol.d.ts +17 -0
  119. package/esm/browser/offline/kept-chats-protocol.js +2 -0
  120. package/esm/browser/offline/kept-chats.d.ts +47 -0
  121. package/esm/browser/offline/kept-chats.js +146 -0
  122. package/esm/browser/offline/offline-reads.d.ts +44 -0
  123. package/esm/browser/offline/offline-reads.js +107 -0
  124. package/esm/browser/settings/settings-protocol.d.ts +2 -0
  125. package/esm/browser/settings/settings-protocol.js +2 -0
  126. package/esm/browser/style/conversation.d.ts +1 -1
  127. package/esm/browser/style/conversation.js +57 -17
  128. package/esm/browser/style/device.js +27 -4
  129. package/esm/browser/style/layout.d.ts +1 -1
  130. package/esm/browser/style/layout.js +67 -15
  131. package/esm/browser/style/pages.d.ts +1 -1
  132. package/esm/browser/style/pages.js +2 -1
  133. package/esm/browser/style/shell.d.ts +1 -1
  134. package/esm/browser/style/shell.js +46 -3
  135. package/esm/browser/util/frame.d.ts +5 -4
  136. package/esm/browser/util/frame.js +5 -4
  137. package/esm/browser/util/markdown.d.ts +18 -1
  138. package/esm/browser/util/markdown.js +119 -5
  139. package/esm/browser/util/process.d.ts +21 -0
  140. package/esm/browser/util/process.js +45 -1
  141. package/esm/browser/util/voice.d.ts +5 -2
  142. package/esm/browser/util/voice.js +6 -3
  143. package/esm/browser/util/zoom.d.ts +46 -0
  144. package/esm/browser/util/zoom.js +96 -0
  145. package/esm/browser/workbench-calls.d.ts +59 -0
  146. package/esm/browser/workbench-calls.js +141 -0
  147. package/esm/browser/workbench-protocol.d.ts +5 -1
  148. package/esm/browser/workbench-util.d.ts +7 -0
  149. package/esm/browser/workbench-util.js +9 -2
  150. package/esm/browser/workbench.d.ts +14 -5
  151. package/esm/browser/workbench.js +51 -31
  152. package/lib/browser/assistant/assistant-chat-list.js +8 -2
  153. package/lib/browser/assistant/assistant-extension.d.ts +8 -1
  154. package/lib/browser/assistant/assistant-extension.js +20 -0
  155. package/lib/browser/assistant/assistant-protocol.d.ts +3 -1
  156. package/lib/browser/assistant/assistant-task-util.d.ts +2 -0
  157. package/lib/browser/assistant/assistant-task-util.js +5 -3
  158. package/lib/browser/assistant/assistant-view.js +78 -53
  159. package/lib/browser/assistant/assistant.d.ts +10 -1
  160. package/lib/browser/assistant/assistant.js +44 -5
  161. package/lib/browser/chat/chat-packages.d.ts +40 -0
  162. package/lib/browser/chat/chat-packages.js +74 -0
  163. package/lib/browser/chat/chat-protocol.d.ts +23 -1
  164. package/lib/browser/chat/chat-stores.d.ts +60 -0
  165. package/lib/browser/chat/chat-stores.js +125 -0
  166. package/lib/browser/chat/chat-util.d.ts +18 -0
  167. package/lib/browser/chat/chat-util.js +64 -0
  168. package/lib/browser/chat/chat-view.js +33 -12
  169. package/lib/browser/chat/chat.d.ts +31 -39
  170. package/lib/browser/chat/chat.js +227 -176
  171. package/lib/browser/components/app-nav.d.ts +6 -3
  172. package/lib/browser/components/app-nav.js +17 -8
  173. package/lib/browser/components/app-shell-hooks.d.ts +2 -2
  174. package/lib/browser/components/app-shell-hooks.js +7 -3
  175. package/lib/browser/components/app-view.js +74 -20
  176. package/lib/browser/components/chat-list.d.ts +20 -2
  177. package/lib/browser/components/chat-list.js +137 -21
  178. package/lib/browser/components/composer-box.d.ts +5 -5
  179. package/lib/browser/components/composer-box.js +111 -4
  180. package/lib/browser/components/composer.d.ts +7 -0
  181. package/lib/browser/components/composer.js +5 -4
  182. package/lib/browser/components/connection-bar.js +48 -15
  183. package/lib/browser/components/context-menu.d.ts +30 -4
  184. package/lib/browser/components/context-menu.js +198 -36
  185. package/lib/browser/components/conversation-scroll.d.ts +129 -6
  186. package/lib/browser/components/conversation-scroll.js +431 -110
  187. package/lib/browser/components/earlier-messages.d.ts +2 -1
  188. package/lib/browser/components/earlier-messages.js +2 -17
  189. package/lib/browser/components/editor-area.d.ts +3 -1
  190. package/lib/browser/components/editor-area.js +5 -4
  191. package/lib/browser/components/empty-pictures.d.ts +0 -2
  192. package/lib/browser/components/empty-pictures.js +0 -17
  193. package/lib/browser/components/folder-picker.d.ts +5 -2
  194. package/lib/browser/components/folder-picker.js +26 -8
  195. package/lib/browser/components/held-talk.d.ts +29 -0
  196. package/lib/browser/components/held-talk.js +79 -0
  197. package/lib/browser/components/host-view.d.ts +1 -1
  198. package/lib/browser/components/icon.d.ts +2 -2
  199. package/lib/browser/components/icon.js +7 -6
  200. package/lib/browser/components/image-viewer.d.ts +125 -0
  201. package/lib/browser/components/image-viewer.js +435 -0
  202. package/lib/browser/components/lightbox.d.ts +12 -0
  203. package/lib/browser/components/lightbox.js +60 -0
  204. package/lib/browser/components/markdown.d.ts +6 -2
  205. package/lib/browser/components/markdown.js +24 -10
  206. package/lib/browser/components/media.js +2 -11
  207. package/lib/browser/components/message-footer.d.ts +16 -2
  208. package/lib/browser/components/message-footer.js +31 -12
  209. package/lib/browser/components/message-list.d.ts +24 -3
  210. package/lib/browser/components/message-list.js +146 -16
  211. package/lib/browser/components/message-menu.d.ts +3 -1
  212. package/lib/browser/components/message-menu.js +17 -2
  213. package/lib/browser/components/nav-places.d.ts +16 -1
  214. package/lib/browser/components/nav-places.js +13 -3
  215. package/lib/browser/components/phone-shell.d.ts +4 -1
  216. package/lib/browser/components/phone-shell.js +3 -1
  217. package/lib/browser/components/run-status.js +3 -3
  218. package/lib/browser/components/session-settings.d.ts +6 -0
  219. package/lib/browser/components/session-settings.js +14 -1
  220. package/lib/browser/components/session-view.js +7 -3
  221. package/lib/browser/components/settings-parts.d.ts +2 -2
  222. package/lib/browser/components/settings-parts.js +24 -1
  223. package/lib/browser/components/swipe-row.d.ts +2 -2
  224. package/lib/browser/components/swipe-row.js +7 -3
  225. package/lib/browser/components/tool-view.js +14 -12
  226. package/lib/browser/components/voice-button.d.ts +1 -1
  227. package/lib/browser/components/voice-button.js +1 -1
  228. package/lib/browser/components/voice-talk.d.ts +44 -0
  229. package/lib/browser/components/voice-talk.js +260 -0
  230. package/lib/browser/device/device.d.ts +3 -0
  231. package/lib/browser/device/device.js +11 -1
  232. package/lib/browser/device/hold.d.ts +43 -0
  233. package/lib/browser/device/hold.js +173 -0
  234. package/lib/browser/device/launch-screen.d.ts +1 -1
  235. package/lib/browser/device/launch-screen.js +1 -1
  236. package/lib/browser/device/long-press.d.ts +2 -0
  237. package/lib/browser/device/long-press.js +16 -1
  238. package/lib/browser/device/pull-down.d.ts +4 -2
  239. package/lib/browser/device/pull-down.js +63 -75
  240. package/lib/browser/device/row-swipe.d.ts +35 -10
  241. package/lib/browser/device/row-swipe.js +148 -70
  242. package/lib/browser/device/shake-undo.d.ts +17 -0
  243. package/lib/browser/device/shake-undo.js +63 -0
  244. package/lib/browser/device/sheet-swipe.d.ts +118 -18
  245. package/lib/browser/device/sheet-swipe.js +410 -108
  246. package/lib/browser/extension/web-extension-api.d.ts +97 -1
  247. package/lib/browser/extension/web-extension-code.d.ts +6 -0
  248. package/lib/browser/extension/web-extension-code.js +24 -0
  249. package/lib/browser/extension/web-extension-protocol.d.ts +23 -1
  250. package/lib/browser/extension/web-extension-protocol.js +9 -1
  251. package/lib/browser/extension/web-extensions.d.ts +14 -1
  252. package/lib/browser/extension/web-extensions.js +120 -21
  253. package/lib/browser/files/files-protocol.d.ts +26 -0
  254. package/lib/browser/files/files-protocol.js +5 -0
  255. package/lib/browser/files/files.d.ts +36 -0
  256. package/lib/browser/files/files.js +122 -0
  257. package/lib/browser/i18n/locales.d.ts +24 -2
  258. package/lib/browser/i18n/messages.d.ts +23 -1
  259. package/lib/browser/i18n/messages.js +48 -4
  260. package/lib/browser/index.d.ts +6 -0
  261. package/lib/browser/index.js +6 -0
  262. package/lib/browser/notices/notices-protocol.d.ts +9 -1
  263. package/lib/browser/notices/notices.d.ts +2 -0
  264. package/lib/browser/notices/notices.js +20 -10
  265. package/lib/browser/offline/device-values.d.ts +56 -0
  266. package/lib/browser/offline/device-values.js +148 -0
  267. package/lib/browser/offline/kept-chats-protocol.d.ts +18 -0
  268. package/lib/browser/offline/kept-chats-protocol.js +5 -0
  269. package/lib/browser/offline/kept-chats.d.ts +48 -0
  270. package/lib/browser/offline/kept-chats.js +149 -0
  271. package/lib/browser/offline/offline-reads.d.ts +45 -0
  272. package/lib/browser/offline/offline-reads.js +111 -0
  273. package/lib/browser/settings/settings-protocol.d.ts +2 -0
  274. package/lib/browser/settings/settings-protocol.js +2 -0
  275. package/lib/browser/style/conversation.d.ts +1 -1
  276. package/lib/browser/style/conversation.js +57 -17
  277. package/lib/browser/style/device.js +27 -4
  278. package/lib/browser/style/layout.d.ts +1 -1
  279. package/lib/browser/style/layout.js +67 -15
  280. package/lib/browser/style/pages.d.ts +1 -1
  281. package/lib/browser/style/pages.js +2 -1
  282. package/lib/browser/style/shell.d.ts +1 -1
  283. package/lib/browser/style/shell.js +46 -3
  284. package/lib/browser/util/frame.d.ts +5 -4
  285. package/lib/browser/util/frame.js +5 -4
  286. package/lib/browser/util/markdown.d.ts +18 -1
  287. package/lib/browser/util/markdown.js +119 -5
  288. package/lib/browser/util/process.d.ts +21 -0
  289. package/lib/browser/util/process.js +46 -2
  290. package/lib/browser/util/voice.d.ts +5 -2
  291. package/lib/browser/util/voice.js +6 -3
  292. package/lib/browser/util/zoom.d.ts +47 -0
  293. package/lib/browser/util/zoom.js +99 -0
  294. package/lib/browser/workbench-calls.d.ts +60 -0
  295. package/lib/browser/workbench-calls.js +145 -0
  296. package/lib/browser/workbench-protocol.d.ts +5 -1
  297. package/lib/browser/workbench-util.d.ts +7 -0
  298. package/lib/browser/workbench-util.js +10 -3
  299. package/lib/browser/workbench.d.ts +14 -5
  300. package/lib/browser/workbench.js +51 -31
  301. package/package.json +10 -10
  302. package/public/launch.svg +46 -42
@@ -1,63 +1,223 @@
1
1
  import * as React from 'react';
2
- import { Device } from '../device/device.js';
2
+ import { createPortal } from 'react-dom';
3
+ import { Device, nativePlugin } from '../device/device.js';
4
+ import { LongPressUtil } from '../device/long-press.js';
3
5
  export var ContextMenuUtil;
4
6
  (function (ContextMenuUtil) {
5
- /** Between a finger and the menu it opened: the finger does not cover it. */
6
- const FINGER_GAP = 14;
7
+ /** Between the menu and the edges of the screen. */
8
+ const MARGIN = 4;
9
+ /** How far around the point it touches a fingertip covers the screen. */
10
+ const FINGER = 28;
11
+ /** Between the menu and the finger, or the row it was opened on. */
12
+ const GAP = 8;
13
+ /** A row this close to the finger stays in sight whole; of a longer element (a long message) only what is around the finger. */
14
+ const ROW_REACH = 96;
15
+ /** A tap outside a menu a finger opened closes it, and that is all it does: its click, if it comes this soon. */
16
+ const TAP_MS = 1000;
7
17
  /**
8
- * Where a menu of `size` goes for a click at `at`: its corner at the pointer, as a browser's; above a finger
9
- * (below when there is no room), centred on it, as the menus of a phone. Always on the screen.
18
+ * Where a menu of `size` goes for a click at `at`: its corner at the pointer, as a browser's. Under a finger,
19
+ * never where the finger covers it: above the finger and the row it pressed (`around`), centred, as the menus
20
+ * of a phone; with no room there, beside the finger on the side with more room; else below the row, as far
21
+ * from the finger sideways as the screen allows. Always on the screen, out of the status bar and the home
22
+ * indicator (`safe`). `origin` is where it grows from: the side of the finger.
10
23
  */
11
- function place(at, size, screen, touch, safe = { top: 0, bottom: 0 }) {
12
- const clamp = (value, max) => Math.max(4, Math.min(value, max - 4));
13
- if (touch) {
14
- const left = clamp(at.x - size.width / 2, screen.width - size.width);
15
- const above = at.y - FINGER_GAP - size.height;
16
- // Not under the status bar nor the home indicator.
17
- const top = above >= safe.top + 4 ? above : Math.max(safe.top + 4, Math.min(at.y + FINGER_GAP, screen.height - safe.bottom - size.height - 4));
18
- return { left, top };
24
+ function place(at, size, screen, touch, safe = { top: 0, bottom: 0 }, around) {
25
+ const clamp = (value, low, high) => Math.max(low, Math.min(value, high));
26
+ const widest = screen.width - MARGIN - size.width;
27
+ if (!touch) {
28
+ const top = at.y + size.height > screen.height - MARGIN ? Math.max(MARGIN, at.y - size.height) : at.y;
29
+ return { left: clamp(at.x, MARGIN, widest), top, origin: 'left top' };
19
30
  }
20
- const left = clamp(at.x, screen.width - size.width);
21
- const top = at.y + size.height > screen.height - 4 ? Math.max(4, at.y - size.height) : at.y;
22
- return { left, top };
31
+ const highest = safe.top + MARGIN;
32
+ const lowest = screen.height - safe.bottom - MARGIN - size.height;
33
+ const covered = {
34
+ top: Math.min(at.y - FINGER, around && around.top >= at.y - ROW_REACH ? around.top : at.y),
35
+ bottom: Math.max(at.y + FINGER, around && around.bottom <= at.y + ROW_REACH ? around.bottom : at.y),
36
+ };
37
+ // The hand comes from below: above the finger nothing covers the menu.
38
+ const above = covered.top - GAP - size.height;
39
+ if (above >= highest) {
40
+ return { left: clamp(at.x - size.width / 2, MARGIN, widest), top: above, origin: 'center bottom' };
41
+ }
42
+ const leftRoom = at.x - FINGER - GAP - MARGIN;
43
+ const rightRoom = screen.width - at.x - FINGER - GAP - MARGIN;
44
+ // Beside it while the point it touches stays off the menu: at most the edge of the fingertip on its padding.
45
+ if (Math.max(leftRoom, rightRoom) + FINGER >= size.width) {
46
+ const top = clamp(at.y - size.height / 2, highest, lowest);
47
+ return leftRoom >= rightRoom
48
+ ? { left: Math.max(MARGIN, at.x - FINGER - GAP - size.width), top, origin: 'right center' }
49
+ : { left: Math.min(at.x + FINGER + GAP, widest), top, origin: 'left center' };
50
+ }
51
+ const left = at.x >= screen.width / 2 ? MARGIN : widest;
52
+ return { left: clamp(left, MARGIN, widest), top: clamp(covered.bottom + GAP, highest, lowest), origin: 'center top' };
23
53
  }
24
54
  ContextMenuUtil.place = place;
55
+ /**
56
+ * Places a menu of the page, fixed to the screen, where it was `opened` (`place`), and on a touch screen lets
57
+ * the finger have it as on a phone: the finger of the long press that opened it slides onto an entry and lets go
58
+ * to choose it (the entry under it marked `data-armed`), or slides off and lets go to close it; let go where it
59
+ * was, the menu stays for a tap. A tap outside only closes it (the menu's own listener), not also tapping what is
60
+ * under it. For the menus of a layout effect, after the menu rendered its entries (`role="menuitem"`). Returns
61
+ * how to stop.
62
+ */
63
+ function attach(menu, opened, close) {
64
+ const touch = Device.state.touch;
65
+ const size = { width: menu.offsetWidth, height: menu.offsetHeight };
66
+ const screen = { width: window.innerWidth, height: window.innerHeight };
67
+ const at = place(opened, size, screen, touch, touch ? Device.safeArea() : undefined, opened.around);
68
+ menu.style.left = `${at.left}px`;
69
+ menu.style.top = `${at.top}px`;
70
+ if (!touch) {
71
+ return () => undefined;
72
+ }
73
+ menu.style.transformOrigin = at.origin;
74
+ const onOutside = (event) => {
75
+ if (event.pointerType !== 'mouse' && !menu.contains(event.target)) {
76
+ swallowTap(event.timeStamp);
77
+ }
78
+ };
79
+ document.addEventListener('pointerdown', onOutside, true);
80
+ const pressed = LongPressUtil.held();
81
+ const slide = pressed ? slideOn(menu, pressed, opened, close) : () => undefined;
82
+ return () => {
83
+ document.removeEventListener('pointerdown', onOutside, true);
84
+ slide();
85
+ };
86
+ }
87
+ ContextMenuUtil.attach = attach;
88
+ /** The finger that opened `menu` on `pressed` is the menu's until let go: not a scroll, nor a swipe of the row under it. */
89
+ function slideOn(menu, pressed, from, close) {
90
+ let armed;
91
+ let slid = false;
92
+ const still = holdStill(pressed);
93
+ const arm = (item) => {
94
+ var _a;
95
+ if (item === armed) {
96
+ return;
97
+ }
98
+ armed === null || armed === void 0 ? void 0 : armed.removeAttribute('data-armed');
99
+ armed = item;
100
+ if (item) {
101
+ item.setAttribute('data-armed', '');
102
+ (_a = nativePlugin('Haptics')) === null || _a === void 0 ? void 0 : _a('impact', { style: 'LIGHT' }).catch(() => undefined);
103
+ }
104
+ };
105
+ const onMove = (event) => {
106
+ var _a;
107
+ const touch = event.touches[0];
108
+ if (!touch) {
109
+ return;
110
+ }
111
+ if (event.cancelable) {
112
+ event.preventDefault();
113
+ }
114
+ event.stopPropagation();
115
+ slid || (slid = LongPressUtil.moved(from, { x: touch.clientX, y: touch.clientY }));
116
+ const item = (_a = document.elementFromPoint(touch.clientX, touch.clientY)) === null || _a === void 0 ? void 0 : _a.closest('[role="menuitem"]:not(:disabled)');
117
+ arm(item && menu.contains(item) ? item : undefined);
118
+ };
119
+ const onEnd = () => {
120
+ stop();
121
+ const item = armed;
122
+ arm(undefined);
123
+ if (item) {
124
+ item.click();
125
+ }
126
+ else if (slid) {
127
+ close();
128
+ }
129
+ };
130
+ const stop = () => {
131
+ still();
132
+ window.removeEventListener('touchmove', onMove, true);
133
+ window.removeEventListener('touchend', onEnd, true);
134
+ window.removeEventListener('touchcancel', stop, true);
135
+ };
136
+ window.addEventListener('touchmove', onMove, { capture: true, passive: false });
137
+ window.addEventListener('touchend', onEnd, true);
138
+ window.addEventListener('touchcancel', stop, true);
139
+ return () => {
140
+ stop();
141
+ arm(undefined);
142
+ };
143
+ }
144
+ /**
145
+ * Keeps what scrolls around `element` from scrolling until the returned function is called. A touch that began
146
+ * on a list may scroll it however its moves are cancelled after (iOS decides at its start whether they can be),
147
+ * and the finger now slides on the menu: the lists are held still instead.
148
+ */
149
+ function holdStill(element) {
150
+ const held = [];
151
+ for (let node = element.parentElement; node; node = node.parentElement) {
152
+ const style = getComputedStyle(node);
153
+ if (/auto|scroll/.test(style.overflowX + style.overflowY)) {
154
+ held.push([node, node.style.overflow]);
155
+ }
156
+ }
157
+ for (const [node] of held) {
158
+ node.style.overflow = 'hidden';
159
+ }
160
+ return () => {
161
+ for (const [node, overflow] of held.splice(0)) {
162
+ node.style.overflow = overflow;
163
+ }
164
+ };
165
+ }
166
+ /** The click of the touch that began at `since`, if one comes before the next touch: swallowed. */
167
+ function swallowTap(since) {
168
+ const swallow = (event) => {
169
+ off();
170
+ if (event.timeStamp - since < TAP_MS) {
171
+ event.preventDefault();
172
+ event.stopImmediatePropagation();
173
+ }
174
+ };
175
+ const off = () => {
176
+ clearTimeout(timer);
177
+ document.removeEventListener('click', swallow, true);
178
+ document.removeEventListener('pointerdown', off, true);
179
+ };
180
+ const timer = setTimeout(off, TAP_MS);
181
+ document.addEventListener('click', swallow, true);
182
+ document.addEventListener('pointerdown', off, true);
183
+ }
25
184
  })(ContextMenuUtil || (ContextMenuUtil = {}));
26
185
  /**
27
186
  * A context menu at the pointer, as a browser's tabs have: arrows move, Enter runs, Escape or a click
28
- * elsewhere closes. `open` takes the event of a right click (or of the menu key) and the entries.
187
+ * elsewhere closes. `open` takes the event of a right click (or of the menu key) and the entries. Opened by a
188
+ * long press, it keeps out from under the finger and the finger may slide onto an entry (ContextMenuUtil.attach).
29
189
  */
30
190
  export function useContextMenu() {
31
191
  const [menu, setMenu] = React.useState();
32
- const open = React.useCallback((event, items) => {
192
+ const open = React.useCallback((event, items, caption) => {
33
193
  event.preventDefault();
34
194
  event.stopPropagation();
35
195
  const box = event.currentTarget.getBoundingClientRect();
36
196
  // The menu key gives no pointer: under the element.
37
197
  const pointer = event.clientX || event.clientY;
38
- setMenu({ x: pointer ? event.clientX : box.left + 8, y: pointer ? event.clientY : box.bottom, items });
198
+ setMenu(pointer
199
+ ? { x: event.clientX, y: event.clientY, around: { top: box.top, bottom: box.bottom }, items, caption }
200
+ : { x: box.left + 8, y: box.bottom, items, caption });
39
201
  }, []);
40
202
  const close = React.useCallback(() => setMenu(undefined), []);
41
- const element = menu ? React.createElement(ContextMenu, { ...menu, onClose: close }) : null;
203
+ // On the page, not in what opened it: a row far up of a conversation (content-visibility) or one coming in
204
+ // with a motion contains what is fixed in it, which the menu would be clipped by.
205
+ const element = menu ? createPortal(React.createElement(ContextMenu, { ...menu, onClose: close }), document.body) : null;
42
206
  return [element, open];
43
207
  }
44
- function ContextMenu({ x, y, items, onClose }) {
208
+ function ContextMenu({ x, y, around, items, caption, onClose }) {
45
209
  const root = React.useRef(null);
46
- // Measured where it has the whole width, not squeezed against the edge it may open by; then placed.
47
- const [place, setPlace] = React.useState({ left: 0, top: 0, ready: false });
48
210
  React.useLayoutEffect(() => {
49
- var _a, _b;
211
+ var _a;
50
212
  const element = root.current;
51
- // Its size without the scale it comes in with.
52
- const box = element && { width: element.offsetWidth, height: element.offsetHeight };
53
- if (box) {
54
- setPlace({
55
- ...ContextMenuUtil.place({ x, y }, box, { width: window.innerWidth, height: window.innerHeight }, Device.state.touch, Device.safeArea()),
56
- ready: true,
57
- });
213
+ if (!element) {
214
+ return;
58
215
  }
59
- (_b = (_a = root.current) === null || _a === void 0 ? void 0 : _a.querySelector('button:not(:disabled)')) === null || _b === void 0 ? void 0 : _b.focus();
60
- }, [x, y]);
216
+ // Measured where it has the whole width (at 0, 0), not squeezed against the edge it may open by; then placed.
217
+ const stop = ContextMenuUtil.attach(element, { x, y, around }, onClose);
218
+ (_a = element.querySelector('button:not(:disabled)')) === null || _a === void 0 ? void 0 : _a.focus();
219
+ return stop;
220
+ }, [x, y, around, onClose]);
61
221
  React.useEffect(() => {
62
222
  const onPointer = (event) => {
63
223
  var _a;
@@ -88,9 +248,11 @@ function ContextMenu({ x, y, items, onClose }) {
88
248
  const at = buttons.indexOf(document.activeElement);
89
249
  (_b = buttons[(at + (event.key === 'ArrowDown' ? 1 : buttons.length - 1)) % buttons.length]) === null || _b === void 0 ? void 0 : _b.focus();
90
250
  };
91
- return (React.createElement("div", { ref: root, className: "ta-context-menu", role: "menu", style: { left: place.left, top: place.top, visibility: place.ready ? 'visible' : 'hidden' }, onKeyDown: onKeyDown, onContextMenu: event => event.preventDefault() }, items.map((item, index) => item === '-' ? (React.createElement("hr", { key: `-${index}`, className: "ta-context-menu-line" })) : (React.createElement("button", { key: item.label, type: "button", role: "menuitem", className: `ta-context-menu-item${item.danger ? ' ta-danger' : ''}`, disabled: item.disabled, onClick: () => {
92
- onClose();
93
- item.run();
94
- } }, item.label)))));
251
+ return (React.createElement("div", { ref: root, className: "ta-context-menu", role: "menu", onKeyDown: onKeyDown, onContextMenu: event => event.preventDefault() },
252
+ caption && React.createElement("div", { className: "ta-context-menu-caption" }, caption),
253
+ items.map((item, index) => item === '-' ? (React.createElement("hr", { key: `-${index}`, className: "ta-context-menu-line" })) : (React.createElement("button", { key: item.label, type: "button", role: "menuitem", className: `ta-context-menu-item${item.danger ? ' ta-danger' : ''}`, disabled: item.disabled, onClick: () => {
254
+ onClose();
255
+ item.run();
256
+ } }, item.label)))));
95
257
  }
96
258
  //# sourceMappingURL=context-menu.js.map
@@ -1,15 +1,138 @@
1
1
  import * as React from 'react';
2
2
  /** A message of the user in the thread: where the view goes when one is sent. */
3
3
  export declare const ASK_CLASS = "ta-thread-ask";
4
+ /** A row of the thread under which earlier rows come in (what says they load): the row read is the one after it. */
5
+ export declare const SCROLL_SKIP: {
6
+ readonly 'data-scroll-skip': '';
7
+ };
8
+ /** What the scrolling of a conversation reads of its view. */
9
+ export interface ScrollView {
10
+ scrollTop: number;
11
+ readonly scrollHeight: number;
12
+ readonly clientHeight: number;
13
+ scrollTo(options: ScrollToOptions): void;
14
+ getBoundingClientRect(): {
15
+ top: number;
16
+ };
17
+ }
18
+ /** A row of the thread. */
19
+ export interface ScrollRow {
20
+ /** From the top of the thread. */
21
+ readonly offsetTop: number;
22
+ readonly offsetHeight: number;
23
+ readonly isConnected: boolean;
24
+ /** `scrollSkip`: SCROLL_SKIP. */
25
+ readonly dataset?: {
26
+ readonly scrollSkip?: string;
27
+ };
28
+ }
29
+ /** The thread in the view: its rows (HTML elements: ScrollRow), and the room under them for the answer to a message sent. */
30
+ export interface ScrollThread {
31
+ readonly children: ArrayLike<object>;
32
+ readonly offsetHeight: number;
33
+ readonly style: {
34
+ paddingBottom: string;
35
+ };
36
+ }
4
37
  /**
5
- * The scrolling of a conversation, whose thread is the first child of the element of the returned ref.
6
- * A message the user sends goes to the top of the view, and the answer comes in under it: the thread
7
- * keeps the room for that until the answer fills it. Past that, the view follows what comes in while it
8
- * is at the bottom, after layout, on a change of the size of the thread or of the view rather than of the state.
9
- * Opened, and when messages of the user go (a rewind), the view goes to the bottom.
38
+ * The scrolling of a conversation: its view scrolls, its thread (the first child of the view, positioned)
39
+ * holds a row for each message.
40
+ *
41
+ * - At the bottom, the view follows what comes in, after layout, on a change of the size of the thread or of
42
+ * the view. The user scrolling up, by however little, leaves it where they took it: a wheel, a finger, a key,
43
+ * the scroll bar, whatever else moved the view up. Back down near the bottom, it follows again.
44
+ * - Away from the bottom, what the user reads stays where it is: the row at the top of the view keeps its place
45
+ * as rows above it change their height (earlier messages coming in, pictures, rows laid out as they come into
46
+ * view), and the bottom of the view keeps to the message box as it grows and shrinks (lines typed, the
47
+ * keyboard of a phone), as in a chat app.
48
+ * - A part of a message opened or closed by a click (what has `aria-expanded`, a `summary`) stays where it was
49
+ * clicked; opened past the bottom, the view stops following, for the user to read it.
50
+ * - While the user holds the view (a finger on it, the mouse on its scroll bar), nothing moves it under them.
51
+ * - A message the user sends goes to the top of the view, and the answer comes in under it: the thread keeps
52
+ * the room for that until the answer fills it (`send`), and the message keeps to the top as rows above it
53
+ * change their height (the turn it was sent into folding its steps).
54
+ */
55
+ export declare class ConversationScroller {
56
+ private readonly view;
57
+ private readonly thread;
58
+ private readonly now;
59
+ private static readonly views;
60
+ /** The scroller of a view, while it has one. */
61
+ static of(view: object): ConversationScroller | undefined;
62
+ private following;
63
+ /** Where a smooth scroll to a message sent goes: the view need not follow a bottom it is on its way to. */
64
+ private heading;
65
+ /** On a smooth way to the bottom (`toBottom`): what comes in meanwhile moves the end of the way. */
66
+ private chasing;
67
+ /** The message sent last, kept at the top until the user scrolls: rows above it may still change their height. */
68
+ private sent;
69
+ /** Where the view was when it last moved, and how high it was. */
70
+ private top;
71
+ private height;
72
+ private held;
73
+ private touchY;
74
+ /** The row at the top of the view while it does not follow, and how far it starts below the top of the view. */
75
+ private anchor;
76
+ /** What the user just opened or closed, and how far it was below the top of the view. */
77
+ private toggled;
78
+ /**
79
+ * The room under the thread for the answer to the message sent, added to the padding of its bottom: a least
80
+ * height would hide from the observer rows above the message that change their height.
81
+ */
82
+ private room;
83
+ private padding;
84
+ constructor(view: ScrollView, thread: ScrollThread, now?: () => number);
85
+ /** Whether the view follows what comes in. */
86
+ get atLatest(): boolean;
87
+ /** Listens to `view` (the view of this scroller) and its thread; returns what stops it. */
88
+ attach(view: HTMLElement, thread: HTMLElement): () => void;
89
+ /** To the bottom at once, following from there: a conversation opened, loaded again or rewound. */
90
+ reset(): void;
91
+ /** A message sent (its row): to the top of the view, smoothly, with the room under it that its answer will fill. */
92
+ send(message: ScrollRow & Element): void;
93
+ /** Back to the latest (the button that shows away from it): following again at once, the view on its way. */
94
+ toBottom(): void;
95
+ scrolled(): void;
96
+ /** A smooth scroll that ended short of where it went (the page moved under it) counts as there. */
97
+ scrollEnded(): void;
98
+ wheel(deltaY: number, target: EventTarget | null): void;
99
+ key(key: string, shift: boolean): void;
100
+ touchStart(y: number | undefined): void;
101
+ touchMove(y: number | undefined, target: EventTarget | null): void;
102
+ hold(): void;
103
+ /** Let go: what came in meanwhile shows, if the view follows. */
104
+ release(): void;
105
+ clicked(target: EventTarget | null): void;
106
+ /** The thread or the view changed its size. */
107
+ resized(): void;
108
+ /** Where the view goes for the message sent to be at its top, with the room under the thread for that. */
109
+ private place;
110
+ private makeRoom;
111
+ private arrive;
112
+ /** The user moves the view: a smooth scroll on its way is theirs now, the message sent no longer holds the top. */
113
+ private byUser;
114
+ /** The user moves the view up: it stops following before the scroll comes, which a follow would undo. */
115
+ private leave;
116
+ private toBottomNow;
117
+ private moveTo;
118
+ /** The first row in the view, while it does not follow. */
119
+ private remember;
120
+ private offsetOf;
121
+ /** Whether what `element` opened goes on past the bottom of the view. */
122
+ private past;
123
+ }
124
+ export interface ConversationScrollOptions {
125
+ /** Where a message sent goes: to the top of the view with its answer under it (a conversation), or to the bottom (a group chat). */
126
+ sentTo?: 'top' | 'bottom';
127
+ /** Another key (another chat in the same view) goes to the bottom. */
128
+ key?: string;
129
+ }
130
+ /**
131
+ * The scrolling of a conversation (ConversationScroller), whose thread is the first child of the element of the
132
+ * returned ref. Opened, and when messages of the user go (a rewind), the view goes to the bottom.
10
133
  *
11
134
  * `asked`: how many messages of the user there are; the thread marks them with ASK_CLASS.
12
135
  */
13
- export declare function useConversationScroll(asked: number): React.RefObject<HTMLDivElement | null>;
136
+ export declare function useConversationScroll(asked: number, options?: ConversationScrollOptions): React.RefObject<HTMLDivElement | null>;
14
137
  /** Whether the conversation of `ref` is scrolled up from its latest, and a way back to it. */
15
138
  export declare function useAwayFromBottom(ref: React.RefObject<HTMLDivElement | null>): [boolean, () => void];