@swisper.ai/web-chat-ui 0.0.2 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (355) hide show
  1. package/README.md +9 -12
  2. package/dist/components/canvas-shell/canvas-shell.d.ts +32 -10
  3. package/dist/components/canvas-shell/canvas-shell.d.ts.map +1 -1
  4. package/dist/components/canvas-shell/canvas-shell.stories.d.ts +49 -17
  5. package/dist/components/canvas-shell/canvas-shell.stories.d.ts.map +1 -1
  6. package/dist/components/chat-card/chat-card.d.ts +1 -0
  7. package/dist/components/chat-card/chat-card.d.ts.map +1 -1
  8. package/dist/components/chat-card/chat-card.stories.d.ts +47 -1
  9. package/dist/components/chat-card/chat-card.stories.d.ts.map +1 -1
  10. package/dist/components/chat-card/components/chat-card-body.d.ts +8 -0
  11. package/dist/components/chat-card/components/chat-card-body.d.ts.map +1 -1
  12. package/dist/components/chat-card/components/chat-card-footer.d.ts +8 -0
  13. package/dist/components/chat-card/components/chat-card-footer.d.ts.map +1 -1
  14. package/dist/components/chat-card/components/chat-card-form.d.ts +15 -2
  15. package/dist/components/chat-card/components/chat-card-form.d.ts.map +1 -1
  16. package/dist/components/chat-card/components/chat-card-header.d.ts +23 -2
  17. package/dist/components/chat-card/components/chat-card-header.d.ts.map +1 -1
  18. package/dist/components/chat-card/contexts.d.ts +2 -0
  19. package/dist/components/chat-card/contexts.d.ts.map +1 -1
  20. package/dist/components/chat-card/hooks.d.ts +1 -0
  21. package/dist/components/chat-card/hooks.d.ts.map +1 -1
  22. package/dist/components/chat-card/types.d.ts +3 -0
  23. package/dist/components/chat-card/types.d.ts.map +1 -1
  24. package/dist/components/chat-card-container/chat-card-container.d.ts +4 -0
  25. package/dist/components/chat-card-container/chat-card-container.d.ts.map +1 -1
  26. package/dist/components/chat-card-container/chat-card-container.stories.d.ts +12 -1
  27. package/dist/components/chat-card-container/chat-card-container.stories.d.ts.map +1 -1
  28. package/dist/components/chat-container/chat-container.d.ts.map +1 -1
  29. package/dist/components/chat-container/chat-container.stories.d.ts +36 -11
  30. package/dist/components/chat-container/chat-container.stories.d.ts.map +1 -1
  31. package/dist/components/chat-input/chat-input.d.ts +27 -2
  32. package/dist/components/chat-input/chat-input.d.ts.map +1 -1
  33. package/dist/components/chat-input/chat-input.stories.d.ts +63 -3
  34. package/dist/components/chat-input/chat-input.stories.d.ts.map +1 -1
  35. package/dist/components/chat-list/chat-list-item.d.ts +6 -0
  36. package/dist/components/chat-list/chat-list-item.d.ts.map +1 -1
  37. package/dist/components/chat-list/chat-list-items.d.ts +12 -1
  38. package/dist/components/chat-list/chat-list-items.d.ts.map +1 -1
  39. package/dist/components/chat-list/chat-list.d.ts +36 -2
  40. package/dist/components/chat-list/chat-list.d.ts.map +1 -1
  41. package/dist/components/chat-list/chat-list.stories.d.ts +67 -9
  42. package/dist/components/chat-list/chat-list.stories.d.ts.map +1 -1
  43. package/dist/components/chat-message/chat-message.d.ts +12 -1
  44. package/dist/components/chat-message/chat-message.d.ts.map +1 -1
  45. package/dist/components/chat-message/chat-message.stories.d.ts +31 -0
  46. package/dist/components/chat-message/chat-message.stories.d.ts.map +1 -1
  47. package/dist/components/chat-message/index.d.ts +1 -1
  48. package/dist/components/chat-message/index.d.ts.map +1 -1
  49. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts +3 -0
  50. package/dist/components/chat-message-attachment-card/chat-message-attachment-card-icon.d.ts.map +1 -1
  51. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts +25 -5
  52. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.d.ts.map +1 -1
  53. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts +32 -1
  54. package/dist/components/chat-message-attachment-card/chat-message-attachment-card.stories.d.ts.map +1 -1
  55. package/dist/components/chat-message-attachment-card/index.d.ts +2 -2
  56. package/dist/components/chat-message-attachment-card/index.d.ts.map +1 -1
  57. package/dist/components/chat-message-attachment-card/utils.d.ts +1 -0
  58. package/dist/components/chat-message-attachment-card/utils.d.ts.map +1 -1
  59. package/dist/components/chat-message-response/chat-message-response.stories.d.ts +13 -0
  60. package/dist/components/chat-message-response/chat-message-response.stories.d.ts.map +1 -1
  61. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts +22 -5
  62. package/dist/components/chat-message-toolbar/chat-message-toolbar.d.ts.map +1 -1
  63. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts +42 -0
  64. package/dist/components/chat-message-toolbar/chat-message-toolbar.stories.d.ts.map +1 -1
  65. package/dist/components/chat-message-toolbar/index.d.ts +1 -1
  66. package/dist/components/chat-message-toolbar/index.d.ts.map +1 -1
  67. package/dist/components/chat-messages/chat-messages.d.ts +34 -2
  68. package/dist/components/chat-messages/chat-messages.d.ts.map +1 -1
  69. package/dist/components/chat-messages/chat-messages.stories.d.ts +33 -2
  70. package/dist/components/chat-messages/chat-messages.stories.d.ts.map +1 -1
  71. package/dist/components/chat-notification-card/chat-notification-card.d.ts +56 -4
  72. package/dist/components/chat-notification-card/chat-notification-card.d.ts.map +1 -1
  73. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts +50 -1
  74. package/dist/components/chat-notification-card/chat-notification-card.stories.d.ts.map +1 -1
  75. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts +6 -0
  76. package/dist/components/chat-notification-popup/chat-notification-popup.d.ts.map +1 -1
  77. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts +43 -1
  78. package/dist/components/chat-notification-popup/chat-notification-popup.stories.d.ts.map +1 -1
  79. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts +37 -17
  80. package/dist/components/chat-prompt-box/chat-prompt-box.d.ts.map +1 -1
  81. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts +53 -1
  82. package/dist/components/chat-prompt-box/chat-prompt-box.stories.d.ts.map +1 -1
  83. package/dist/components/chat-reply/chat-reply.d.ts +11 -0
  84. package/dist/components/chat-reply/chat-reply.d.ts.map +1 -1
  85. package/dist/components/chat-reply/chat-reply.stories.d.ts +23 -0
  86. package/dist/components/chat-reply/chat-reply.stories.d.ts.map +1 -1
  87. package/dist/components/chat-reply/index.d.ts +1 -1
  88. package/dist/components/chat-reply/index.d.ts.map +1 -1
  89. package/dist/components/chat-suggestion/chat-suggestion.d.ts +36 -10
  90. package/dist/components/chat-suggestion/chat-suggestion.d.ts.map +1 -1
  91. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts +66 -2
  92. package/dist/components/chat-suggestion/chat-suggestion.stories.d.ts.map +1 -1
  93. package/dist/components/chat-suggestion/index.d.ts +2 -1
  94. package/dist/components/chat-suggestion/index.d.ts.map +1 -1
  95. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts +26 -1
  96. package/dist/components/chat-thinking-process/chat-thinking-process.d.ts.map +1 -1
  97. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts +25 -1
  98. package/dist/components/chat-thinking-process/chat-thinking-process.stories.d.ts.map +1 -1
  99. package/dist/components/chat-thread/chat-thread.d.ts +17 -2
  100. package/dist/components/chat-thread/chat-thread.d.ts.map +1 -1
  101. package/dist/components/chat-thread/chat-thread.stories.d.ts +75 -10
  102. package/dist/components/chat-thread/chat-thread.stories.d.ts.map +1 -1
  103. package/dist/components/index.d.ts +1 -3
  104. package/dist/components/index.d.ts.map +1 -1
  105. package/dist/components/markdown-viewer/markdown-viewer.d.ts +8 -1
  106. package/dist/components/markdown-viewer/markdown-viewer.d.ts.map +1 -1
  107. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts +18 -1
  108. package/dist/components/markdown-viewer/markdown-viewer.stories.d.ts.map +1 -1
  109. package/dist/components/rich-text-area/rich-text-area.d.ts +17 -0
  110. package/dist/components/rich-text-area/rich-text-area.d.ts.map +1 -1
  111. package/dist/components/rich-text-area/rich-text-area.stories.d.ts +52 -0
  112. package/dist/components/rich-text-area/rich-text-area.stories.d.ts.map +1 -1
  113. package/dist/components/rich-text-area/styled.d.ts +6 -2
  114. package/dist/components/rich-text-area/styled.d.ts.map +1 -1
  115. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts +9 -2
  116. package/dist/components/rich-text-field/components/formatting-toolbar-plugin.d.ts.map +1 -1
  117. package/dist/components/rich-text-field/components/index.d.ts +5 -5
  118. package/dist/components/rich-text-field/components/index.d.ts.map +1 -1
  119. package/dist/components/rich-text-field/components/text-color-button.d.ts +12 -1
  120. package/dist/components/rich-text-field/components/text-color-button.d.ts.map +1 -1
  121. package/dist/components/rich-text-field/rich-text-field.d.ts +22 -0
  122. package/dist/components/rich-text-field/rich-text-field.d.ts.map +1 -1
  123. package/dist/components/rich-text-field/rich-text-field.stories.d.ts +28 -1
  124. package/dist/components/rich-text-field/rich-text-field.stories.d.ts.map +1 -1
  125. package/dist/components/topmenu/index.d.ts +2 -0
  126. package/dist/components/topmenu/index.d.ts.map +1 -0
  127. package/dist/components/topmenu/topmenu.d.ts +22 -0
  128. package/dist/components/topmenu/topmenu.d.ts.map +1 -0
  129. package/dist/components/topmenu/topmenu.stories.d.ts +31 -0
  130. package/dist/components/topmenu/topmenu.stories.d.ts.map +1 -0
  131. package/dist/docs/agent.stories.d.ts.map +1 -1
  132. package/dist/docs/chat-panel.d.ts +7 -5
  133. package/dist/docs/chat-panel.d.ts.map +1 -1
  134. package/dist/docs/chatbot-panel.d.ts.map +1 -1
  135. package/dist/docs/chatbot.stories.d.ts.map +1 -1
  136. package/dist/index.css +1 -1
  137. package/dist/index.es.js +1227 -1260
  138. package/dist/index.es.js.map +1 -1
  139. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts +9 -7
  140. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.d.ts.map +1 -1
  141. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts +37 -9
  142. package/dist/layouts/chat-card-list-layout/chat-card-list-layout.stories.d.ts.map +1 -1
  143. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts +41 -16
  144. package/dist/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.d.ts.map +1 -1
  145. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts +6 -0
  146. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.d.ts.map +1 -1
  147. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts +22 -1
  148. package/dist/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.d.ts.map +1 -1
  149. package/package.json +15 -9
  150. package/src/__storybook__/parent-block.tsx +21 -0
  151. package/src/components/canvas-shell/__stories__/canvas-panel.tsx +25 -0
  152. package/src/components/canvas-shell/__stories__/document-list.tsx +29 -0
  153. package/src/components/canvas-shell/__stories__/fixtures.ts +222 -0
  154. package/src/components/canvas-shell/__stories__/holdings-table.tsx +56 -0
  155. package/src/components/canvas-shell/__stories__/types.ts +47 -0
  156. package/src/components/canvas-shell/{canvas-shell.test.tsx → __tests__/canvas-shell.spec.tsx} +1 -1
  157. package/src/components/canvas-shell/canvas-shell.json +24 -0
  158. package/src/components/canvas-shell/canvas-shell.stories.tsx +581 -122
  159. package/src/components/canvas-shell/canvas-shell.tsx +44 -17
  160. package/src/components/chat-card/__stories__/fixtures.ts +119 -0
  161. package/src/components/chat-card/__stories__/types.ts +44 -0
  162. package/src/components/chat-card/chat-card.json +67 -3
  163. package/src/components/chat-card/chat-card.stories.tsx +872 -148
  164. package/src/components/chat-card/chat-card.tsx +2 -0
  165. package/src/components/chat-card/components/chat-card-body.tsx +12 -0
  166. package/src/components/chat-card/components/chat-card-footer.tsx +11 -0
  167. package/src/components/chat-card/components/chat-card-form.tsx +21 -2
  168. package/src/components/chat-card/components/chat-card-header.tsx +39 -2
  169. package/src/components/chat-card/contexts.tsx +2 -0
  170. package/src/components/chat-card/hooks.ts +1 -0
  171. package/src/components/chat-card/types.ts +3 -0
  172. package/src/components/chat-card-container/__stories__/fixtures.ts +54 -0
  173. package/src/components/chat-card-container/__stories__/resizable-chat-window.tsx +19 -0
  174. package/src/components/chat-card-container/__stories__/result-card.tsx +31 -0
  175. package/src/components/chat-card-container/__stories__/types.ts +16 -0
  176. package/src/components/chat-card-container/chat-card-container.json +7 -0
  177. package/src/components/chat-card-container/chat-card-container.stories.tsx +209 -56
  178. package/src/components/chat-card-container/chat-card-container.tsx +5 -0
  179. package/src/components/chat-container/__stories__/chat-composer.tsx +67 -0
  180. package/src/components/chat-container/__stories__/fixtures.ts +27 -0
  181. package/src/components/chat-container/__stories__/measure.ts +22 -0
  182. package/src/components/chat-container/__stories__/types.ts +7 -0
  183. package/src/components/chat-container/__stories__/variable-readout.tsx +64 -0
  184. package/src/components/chat-container/chat-container.json +9 -1
  185. package/src/components/chat-container/chat-container.stories.tsx +538 -106
  186. package/src/components/chat-container/chat-container.tsx +3 -0
  187. package/src/components/chat-input/__stories__/fixtures.ts +31 -0
  188. package/src/components/chat-input/chat-input.json +10 -2
  189. package/src/components/chat-input/chat-input.stories.tsx +660 -197
  190. package/src/components/chat-input/chat-input.tsx +32 -2
  191. package/src/components/chat-list/__stories__/chat-row.tsx +41 -0
  192. package/src/components/chat-list/__stories__/fixtures.ts +94 -0
  193. package/src/components/chat-list/__stories__/types.ts +13 -0
  194. package/src/components/chat-list/chat-list-item.tsx +6 -0
  195. package/src/components/chat-list/chat-list-items.tsx +16 -0
  196. package/src/components/chat-list/chat-list.json +24 -2
  197. package/src/components/chat-list/chat-list.stories.tsx +631 -215
  198. package/src/components/chat-list/chat-list.tsx +51 -4
  199. package/src/components/chat-message/__stories__/fixtures.ts +53 -0
  200. package/src/components/chat-message/__stories__/sent-attachment.tsx +22 -0
  201. package/src/components/chat-message/__stories__/tool-steps.tsx +37 -0
  202. package/src/components/chat-message/chat-message.json +10 -1
  203. package/src/components/chat-message/chat-message.stories.tsx +282 -20
  204. package/src/components/chat-message/chat-message.tsx +16 -1
  205. package/src/components/chat-message/index.ts +8 -1
  206. package/src/components/chat-message-attachment-card/__stories__/fixtures.ts +30 -0
  207. package/src/components/chat-message-attachment-card/__stories__/types.ts +14 -0
  208. package/src/components/chat-message-attachment-card/chat-message-attachment-card-icon.tsx +4 -0
  209. package/src/components/chat-message-attachment-card/chat-message-attachment-card.json +20 -0
  210. package/src/components/chat-message-attachment-card/chat-message-attachment-card.stories.tsx +266 -51
  211. package/src/components/chat-message-attachment-card/chat-message-attachment-card.tsx +37 -4
  212. package/src/components/chat-message-attachment-card/index.ts +6 -0
  213. package/src/components/chat-message-attachment-card/utils.ts +1 -0
  214. package/src/components/chat-message-response/__stories__/fixtures.ts +50 -0
  215. package/src/components/chat-message-response/chat-message-response.json +5 -0
  216. package/src/components/chat-message-response/chat-message-response.stories.tsx +135 -26
  217. package/src/components/chat-message-toolbar/chat-message-toolbar.json +21 -3
  218. package/src/components/chat-message-toolbar/chat-message-toolbar.stories.tsx +377 -6
  219. package/src/components/chat-message-toolbar/chat-message-toolbar.tsx +47 -12
  220. package/src/components/chat-message-toolbar/index.ts +4 -0
  221. package/src/components/chat-messages/__stories__/conversation-frame.tsx +25 -0
  222. package/src/components/chat-messages/__stories__/conversation-group.tsx +22 -0
  223. package/src/components/chat-messages/__stories__/fixtures.ts +70 -0
  224. package/src/components/chat-messages/__stories__/types.ts +5 -0
  225. package/src/components/chat-messages/chat-messages.json +30 -12
  226. package/src/components/chat-messages/chat-messages.stories.tsx +439 -212
  227. package/src/components/chat-messages/chat-messages.tsx +46 -3
  228. package/src/components/chat-notification-card/__stories__/fixtures.ts +38 -0
  229. package/src/components/chat-notification-card/__stories__/types.ts +13 -0
  230. package/src/components/chat-notification-card/chat-notification-card.json +52 -2
  231. package/src/components/chat-notification-card/chat-notification-card.stories.tsx +542 -62
  232. package/src/components/chat-notification-card/chat-notification-card.tsx +97 -6
  233. package/src/components/chat-notification-popup/__stories__/fixtures.ts +36 -0
  234. package/src/components/chat-notification-popup/__stories__/notification-item.tsx +93 -0
  235. package/src/components/chat-notification-popup/__stories__/types.ts +14 -0
  236. package/src/components/chat-notification-popup/chat-notification-popup.json +14 -1
  237. package/src/components/chat-notification-popup/chat-notification-popup.stories.tsx +467 -17
  238. package/src/components/chat-notification-popup/chat-notification-popup.tsx +18 -3
  239. package/src/components/chat-prompt-box/__stories__/fixtures.ts +16 -0
  240. package/src/components/chat-prompt-box/__stories__/types.ts +8 -0
  241. package/src/components/chat-prompt-box/chat-prompt-box.json +25 -2
  242. package/src/components/chat-prompt-box/chat-prompt-box.stories.tsx +535 -43
  243. package/src/components/chat-prompt-box/chat-prompt-box.tsx +73 -19
  244. package/src/components/chat-reply/chat-reply.json +10 -0
  245. package/src/components/chat-reply/chat-reply.stories.tsx +264 -21
  246. package/src/components/chat-reply/chat-reply.tsx +15 -0
  247. package/src/components/chat-reply/index.ts +10 -1
  248. package/src/components/chat-suggestion/__stories__/fixtures.ts +16 -0
  249. package/src/components/chat-suggestion/__tests__/chat-suggestion.spec.tsx +185 -0
  250. package/src/components/chat-suggestion/chat-suggestion.json +62 -20
  251. package/src/components/chat-suggestion/chat-suggestion.stories.tsx +542 -58
  252. package/src/components/chat-suggestion/chat-suggestion.tsx +154 -65
  253. package/src/components/chat-suggestion/index.ts +9 -0
  254. package/src/components/chat-thinking-process/__stories__/fixtures.ts +56 -0
  255. package/src/components/chat-thinking-process/chat-thinking-process.json +28 -3
  256. package/src/components/chat-thinking-process/chat-thinking-process.stories.tsx +354 -78
  257. package/src/components/chat-thinking-process/chat-thinking-process.tsx +55 -4
  258. package/src/components/chat-thread/__stories__/fixtures.ts +171 -0
  259. package/src/components/chat-thread/__stories__/scroll-position.ts +9 -0
  260. package/src/components/chat-thread/__stories__/snippets.ts +129 -0
  261. package/src/components/chat-thread/__stories__/thread-frame.tsx +22 -0
  262. package/src/components/chat-thread/__stories__/thread-turns.tsx +35 -0
  263. package/src/components/chat-thread/__stories__/types.ts +12 -0
  264. package/src/components/chat-thread/__stories__/use-turn-stream.ts +78 -0
  265. package/src/components/chat-thread/chat-thread.json +23 -3
  266. package/src/components/chat-thread/chat-thread.stories.tsx +804 -142
  267. package/src/components/chat-thread/chat-thread.tsx +64 -16
  268. package/src/components/index.ts +1 -3
  269. package/src/components/markdown-viewer/__stories__/fixtures.ts +67 -0
  270. package/src/components/markdown-viewer/markdown-viewer.json +7 -1
  271. package/src/components/markdown-viewer/markdown-viewer.stories.tsx +219 -50
  272. package/src/components/markdown-viewer/markdown-viewer.tsx +9 -0
  273. package/src/components/rich-text-area/__stories__/fixtures.ts +30 -0
  274. package/src/components/rich-text-area/rich-text-area.json +6 -4
  275. package/src/components/rich-text-area/rich-text-area.stories.tsx +597 -41
  276. package/src/components/rich-text-area/rich-text-area.tsx +22 -1
  277. package/src/components/rich-text-area/styled.tsx +11 -5
  278. package/src/components/rich-text-field/__stories__/fixtures.ts +29 -0
  279. package/src/components/rich-text-field/components/formatting-toolbar-plugin.tsx +10 -1
  280. package/src/components/rich-text-field/components/index.ts +8 -5
  281. package/src/components/rich-text-field/components/text-color-button.tsx +16 -2
  282. package/src/components/rich-text-field/rich-text-field.json +3 -1
  283. package/src/components/rich-text-field/rich-text-field.stories.tsx +452 -61
  284. package/src/components/rich-text-field/rich-text-field.tsx +23 -0
  285. package/src/components/topmenu/index.ts +1 -0
  286. package/src/components/topmenu/topmenu.json +107 -0
  287. package/src/components/topmenu/topmenu.stories.tsx +334 -0
  288. package/src/components/topmenu/topmenu.tsx +71 -0
  289. package/src/docs/agent.stories.tsx +16 -16
  290. package/src/docs/chat-panel.tsx +37 -32
  291. package/src/docs/chatbot-panel.tsx +11 -2
  292. package/src/docs/chatbot.mdx +17 -12
  293. package/src/docs/chatbot.stories.tsx +7 -8
  294. package/src/layouts/chat-card-list-layout/__stories__/fixtures.ts +112 -0
  295. package/src/layouts/chat-card-list-layout/__stories__/result-card.tsx +36 -0
  296. package/src/layouts/chat-card-list-layout/__stories__/types.ts +31 -0
  297. package/src/layouts/chat-card-list-layout/chat-card-list-layout.json +14 -1
  298. package/src/layouts/chat-card-list-layout/chat-card-list-layout.stories.tsx +316 -84
  299. package/src/layouts/chat-card-list-layout/chat-card-list-layout.tsx +11 -7
  300. package/src/layouts/chat-card-three-column-layout/__stories__/fixtures.ts +117 -0
  301. package/src/layouts/chat-card-three-column-layout/__stories__/resizable-chat-window.tsx +18 -0
  302. package/src/layouts/chat-card-three-column-layout/__stories__/stay-details.tsx +85 -0
  303. package/src/layouts/chat-card-three-column-layout/__stories__/stay-list.tsx +50 -0
  304. package/src/layouts/chat-card-three-column-layout/__stories__/stay-map.tsx +44 -0
  305. package/src/layouts/chat-card-three-column-layout/__stories__/stay-rooms.tsx +61 -0
  306. package/src/layouts/chat-card-three-column-layout/__stories__/types.ts +35 -0
  307. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.json +16 -0
  308. package/src/layouts/chat-card-three-column-layout/chat-card-three-column-layout.stories.tsx +603 -182
  309. package/src/layouts/chat-card-two-column-layout/__stories__/connection-itinerary.tsx +51 -0
  310. package/src/layouts/chat-card-two-column-layout/__stories__/fixtures.ts +83 -0
  311. package/src/layouts/chat-card-two-column-layout/__stories__/route-map.tsx +24 -0
  312. package/src/layouts/chat-card-two-column-layout/__stories__/types.ts +15 -0
  313. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.json +13 -1
  314. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.stories.tsx +368 -67
  315. package/src/layouts/chat-card-two-column-layout/chat-card-two-column-layout.tsx +11 -2
  316. package/dist/components/card-item-picker/card-item-picker-context.d.ts +0 -21
  317. package/dist/components/card-item-picker/card-item-picker-context.d.ts.map +0 -1
  318. package/dist/components/card-item-picker/card-item-picker-list.d.ts +0 -24
  319. package/dist/components/card-item-picker/card-item-picker-list.d.ts.map +0 -1
  320. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts +0 -28
  321. package/dist/components/card-item-picker/card-item-picker-row-parts.d.ts.map +0 -1
  322. package/dist/components/card-item-picker/card-item-picker-row.d.ts +0 -12
  323. package/dist/components/card-item-picker/card-item-picker-row.d.ts.map +0 -1
  324. package/dist/components/card-item-picker/card-item-picker.stories.d.ts +0 -19
  325. package/dist/components/card-item-picker/card-item-picker.stories.d.ts.map +0 -1
  326. package/dist/components/card-item-picker/index.d.ts +0 -9
  327. package/dist/components/card-item-picker/index.d.ts.map +0 -1
  328. package/dist/components/chat-message-history/chat-message-history.d.ts +0 -48
  329. package/dist/components/chat-message-history/chat-message-history.d.ts.map +0 -1
  330. package/dist/components/chat-message-history/chat-message-history.stories.d.ts +0 -7
  331. package/dist/components/chat-message-history/chat-message-history.stories.d.ts.map +0 -1
  332. package/dist/components/chat-message-history/index.d.ts +0 -2
  333. package/dist/components/chat-message-history/index.d.ts.map +0 -1
  334. package/dist/components/spinner/index.d.ts +0 -2
  335. package/dist/components/spinner/index.d.ts.map +0 -1
  336. package/dist/components/spinner/spinner.d.ts +0 -9
  337. package/dist/components/spinner/spinner.d.ts.map +0 -1
  338. package/dist/components/spinner/spinner.stories.d.ts +0 -8
  339. package/dist/components/spinner/spinner.stories.d.ts.map +0 -1
  340. package/src/components/card-item-picker/__tests__/card-item-picker.spec.tsx +0 -279
  341. package/src/components/card-item-picker/card-item-picker-context.tsx +0 -44
  342. package/src/components/card-item-picker/card-item-picker-list.tsx +0 -95
  343. package/src/components/card-item-picker/card-item-picker-row-parts.tsx +0 -96
  344. package/src/components/card-item-picker/card-item-picker-row.tsx +0 -109
  345. package/src/components/card-item-picker/card-item-picker.json +0 -147
  346. package/src/components/card-item-picker/card-item-picker.stories.tsx +0 -158
  347. package/src/components/card-item-picker/index.ts +0 -24
  348. package/src/components/chat-message-history/chat-message-history.json +0 -99
  349. package/src/components/chat-message-history/chat-message-history.stories.tsx +0 -136
  350. package/src/components/chat-message-history/chat-message-history.tsx +0 -277
  351. package/src/components/chat-message-history/index.ts +0 -13
  352. package/src/components/spinner/index.ts +0 -1
  353. package/src/components/spinner/spinner.json +0 -73
  354. package/src/components/spinner/spinner.stories.tsx +0 -41
  355. package/src/components/spinner/spinner.tsx +0 -32
@@ -1,20 +1,43 @@
1
1
  import type { Meta, StoryObj } from '@storybook/react-vite';
2
- import { useState } from 'react';
3
- import { fn } from 'storybook/test';
2
+ import { useRef, useState } from 'react';
3
+ import type { KeyboardEvent } from 'react';
4
+ import { expect, fn, waitFor } from 'storybook/test';
4
5
 
6
+ import { EnterIcon, ScribeAssistantIcon } from '@swisper.ai/icons';
7
+ import { Button, Divider, IconButton, Typography } from '@swisper.ai/ui';
5
8
  import { cn } from '@swisper.ai/web-core';
6
9
 
10
+ import { ParentBlock } from '../../__storybook__/parent-block';
11
+
12
+ import {
13
+ OFFER_EMAIL_HTML,
14
+ REPLY_DRAFT_MARKDOWN,
15
+ SCRIBE_SELECTION,
16
+ SIGNATURE_DISCLAIMER_HTML,
17
+ SIGNATURE_HTML,
18
+ SIGNATURE_LOGO,
19
+ } from './__stories__/fixtures';
20
+ import { HtmlPastePlugin, InsertHtmlEvent } from './plugins/html-paste-plugin';
21
+ import { ImageAddedEvent, ImageDropPlugin } from './plugins/image-drop-plugin';
7
22
  import { RichTextArea } from './rich-text-area';
8
23
 
24
+ // RichTextArea ships unstyled. This is the look a consumer gives the editable area: body
25
+ // typography, plus list markers and heading sizes, which the CSS reset removes.
26
+ const editorClassName =
27
+ 'size-full font-noto-sans text-base leading-relaxed text-text-primary [&_h2]:text-lg [&_h2]:font-semibold [&_ol]:list-decimal [&_ol]:pl-20 [&_ul]:list-disc [&_ul]:pl-20 [&_a]:underline';
28
+
29
+ // The surface around an editor: RichTextArea draws no border or background of its own.
30
+ const surfaceClassName = 'rounded-10 border border-component-divider bg-paper-elevation-1 p-12';
31
+
9
32
  const meta: Meta<typeof RichTextArea> = {
10
- title: 'Chatbot/RichTextArea',
33
+ title: 'Chat/RichTextArea',
11
34
  component: RichTextArea,
12
35
  parameters: {
13
36
  layout: 'padded',
14
37
  },
15
38
  decorators: [
16
39
  (Story) => (
17
- <div className="relative w-[688px] min-h-[72px] bg-paper-elevation-1 rounded-[12px]">
40
+ <div className="relative min-h-18 max-w-172 rounded-10 bg-paper-elevation-1">
18
41
  <Story />
19
42
  </div>
20
43
  ),
@@ -29,7 +52,7 @@ const meta: Meta<typeof RichTextArea> = {
29
52
  control: 'select',
30
53
  options: ['markdown', 'html'],
31
54
  description:
32
- 'Format of `value` and of what `onChange` returns. `markdown` also pastes plain markdown as formatted text.',
55
+ 'Format of `value` and of what `onChange` returns. `markdown` also pastes the clipboard as plain text.',
33
56
  table: { defaultValue: { summary: 'markdown' } },
34
57
  },
35
58
  placeholder: {
@@ -61,7 +84,7 @@ const meta: Meta<typeof RichTextArea> = {
61
84
  children: {
62
85
  control: false,
63
86
  description:
64
- 'Extra Lexical plugins rendered inside the editor, e.g. a toolbar or file attachment plugin.',
87
+ 'Extra Lexical plugins rendered inside the editor, e.g. `ImageDropPlugin` or `HtmlPastePlugin`.',
65
88
  },
66
89
  onChange: {
67
90
  description: 'Called with the new content, serialised as `source`, on every edit.',
@@ -77,12 +100,9 @@ const meta: Meta<typeof RichTextArea> = {
77
100
  },
78
101
  },
79
102
  args: {
80
- className: cn(
81
- 'rich-text-area w-full h-full',
82
- 'text-text-primary font-noto-sans font-normal text-base leading-[160%]',
83
- ),
103
+ className: editorClassName,
84
104
  source: 'markdown',
85
- placeholder: 'Ask Swisper anything',
105
+ placeholder: 'Write a reply',
86
106
  isDisabled: false,
87
107
  onChange: fn(),
88
108
  onBlur: fn(),
@@ -95,46 +115,582 @@ const meta: Meta<typeof RichTextArea> = {
95
115
  export default meta;
96
116
  type Story = StoryObj<typeof RichTextArea>;
97
117
 
98
- const presetMarkdown = `**Bold text** and *italic text*
118
+ /** A reply draft stored as Markdown: bold, italic and a list, edited without a toolbar. */
119
+ export const Default: Story = {
120
+ args: {
121
+ value: REPLY_DRAFT_MARKDOWN,
122
+ },
123
+ };
99
124
 
100
- A list of items:
101
- - First item
102
- - Second item
103
- - Third item`;
125
+ /** No value yet: the placeholder says what to write and goes away with the first character. */
126
+ export const Empty: Story = {
127
+ args: {
128
+ placeholder: 'Write a reply',
129
+ },
130
+ };
104
131
 
105
- export const Default: Story = {
132
+ /** A draft that can't be edited while it is being sent: dimmed, not selectable and out of the tab order. */
133
+ export const Disabled: Story = {
106
134
  args: {
107
- value: presetMarkdown,
108
- placeholder: 'Type something...',
135
+ value: REPLY_DRAFT_MARKDOWN,
136
+ isDisabled: true,
109
137
  },
110
- render: (args) => {
111
- const [value, setValue] = useState(args.value);
138
+ };
112
139
 
113
- return (
114
- <div style={{ display: 'flex', flexDirection: 'column', gap: 16 }}>
115
- <RichTextArea
116
- {...args}
117
- value={value}
118
- onChange={setValue}
119
- className={cn(
120
- 'rich-text-area w-full h-full',
121
- 'text-text-primary font-noto-sans font-normal text-base leading-[160%]',
122
- )}
123
- />
140
+ /** `source="html"` for text a mail client renders: an email signature whose value and `onChange` are HTML. */
141
+ export const HtmlSource: Story = {
142
+ args: {
143
+ source: 'html',
144
+ value: SIGNATURE_HTML,
145
+ placeholder: 'Write your signature',
146
+ },
147
+ };
148
+
149
+ interface ReplyDraftProps {
150
+ initialDraft: string;
151
+ onChange: (markdown: string) => void;
152
+ }
153
+
154
+ function ReplyDraft({ initialDraft, onChange }: ReplyDraftProps) {
155
+ const [draft, setDraft] = useState(initialDraft);
124
156
 
157
+ const handleChange = (markdown: string) => {
158
+ setDraft(markdown);
159
+ onChange(markdown);
160
+ };
161
+
162
+ return (
163
+ <div className="flex flex-col gap-16">
164
+ <RichTextArea
165
+ value={draft}
166
+ placeholder="Write a reply"
167
+ className={editorClassName}
168
+ onChange={handleChange}
169
+ />
170
+ <div className="flex flex-col gap-8 border-t border-component-divider p-12">
171
+ <Typography variant="caption-md" className="text-text-tertiary">
172
+ Stored as Markdown
173
+ </Typography>
125
174
  <pre
126
- style={{
127
- padding: 12,
128
- borderRadius: 8,
129
- background: '#1a1a2e',
130
- color: '#e0e0e0',
131
- fontSize: 12,
132
- whiteSpace: 'pre-wrap',
133
- }}
175
+ aria-label="Stored Markdown"
176
+ className="font-mono text-xs whitespace-pre-wrap text-text-secondary"
134
177
  >
135
- {value}
178
+ {draft}
136
179
  </pre>
137
180
  </div>
181
+ <div>
182
+ <Button variant="tertiary" size="sm" onClick={() => handleChange('')}>
183
+ Discard draft
184
+ </Button>
185
+ </div>
186
+ </div>
187
+ );
188
+ }
189
+
190
+ type ReplyDraftStory = StoryObj<typeof ReplyDraft>;
191
+
192
+ /** The value kept in state: every edit comes back through `onChange` as Markdown, and setting `''` clears the editor. */
193
+ export const Controlled: ReplyDraftStory = {
194
+ parameters: { controls: { disable: true } },
195
+ args: { initialDraft: REPLY_DRAFT_MARKDOWN, onChange: fn() },
196
+ render: (args) => <ReplyDraft {...args} />,
197
+ };
198
+
199
+ interface SignatureEditorProps {
200
+ signature: string;
201
+ onChange: (html: string) => void;
202
+ }
203
+
204
+ function SignatureEditor({ signature, onChange }: SignatureEditorProps) {
205
+ return (
206
+ <div className="flex flex-col gap-8 p-12">
207
+ <Typography variant="body-small-high" fontWeight="medium" asChild>
208
+ <h3 id="signature-editor-title">Signature</h3>
209
+ </Typography>
210
+ <div role="group" aria-labelledby="signature-editor-title" className={surfaceClassName}>
211
+ <RichTextArea
212
+ source="html"
213
+ value={signature}
214
+ placeholder="Write your signature"
215
+ className={editorClassName}
216
+ onChange={onChange}
217
+ >
218
+ <ImageDropPlugin />
219
+ <HtmlPastePlugin />
220
+ </RichTextArea>
221
+ </div>
222
+ <div className="flex gap-8">
223
+ <Button
224
+ variant="secondary"
225
+ size="sm"
226
+ onClick={() => document.dispatchEvent(new ImageAddedEvent(SIGNATURE_LOGO))}
227
+ >
228
+ Add logo
229
+ </Button>
230
+ <Button
231
+ variant="secondary"
232
+ size="sm"
233
+ onClick={() =>
234
+ document.dispatchEvent(new InsertHtmlEvent({ html: SIGNATURE_DISCLAIMER_HTML }))
235
+ }
236
+ >
237
+ Add disclaimer
238
+ </Button>
239
+ </div>
240
+ </div>
241
+ );
242
+ }
243
+
244
+ type SignatureEditorStory = StoryObj<typeof SignatureEditor>;
245
+
246
+ /** Plugins as children: `ImageDropPlugin` and `HtmlPastePlugin` insert a logo and an HTML snippet when the page dispatches their events. */
247
+ export const WithPlugins: SignatureEditorStory = {
248
+ parameters: { controls: { disable: true } },
249
+ args: { signature: SIGNATURE_HTML, onChange: fn() },
250
+ render: (args) => <SignatureEditor {...args} />,
251
+ };
252
+
253
+ function delay(ms: number) {
254
+ return new Promise<void>((resolve) => setTimeout(resolve, ms));
255
+ }
256
+
257
+ interface ScribeAssistFormProps {
258
+ /** The text the writer selected in the email, quoted above the instruction. */
259
+ selection: string;
260
+ onAssist: (instruction: string) => Promise<void>;
261
+ }
262
+
263
+ function ScribeAssistForm({ selection, onAssist }: ScribeAssistFormProps) {
264
+ const editorRef = useRef<HTMLInputElement>(null);
265
+ const [instruction, setInstruction] = useState('');
266
+ const [isSubmitting, setIsSubmitting] = useState(false);
267
+ const [hasError, setHasError] = useState(false);
268
+
269
+ const handleSubmit = async () => {
270
+ if (isSubmitting) {
271
+ return;
272
+ }
273
+ if (!instruction.trim()) {
274
+ editorRef.current?.focus();
275
+ return;
276
+ }
277
+
278
+ setHasError(false);
279
+ setIsSubmitting(true);
280
+ try {
281
+ await onAssist(instruction.trim());
282
+ setInstruction('');
283
+ } catch {
284
+ setHasError(true);
285
+ } finally {
286
+ setIsSubmitting(false);
287
+ }
288
+ };
289
+
290
+ // A bare Enter submits; Enter with a modifier stays a new line. `onKeyDown` runs in the capture
291
+ // phase, so stopping the event there keeps it from Lexical, which would add a paragraph.
292
+ const handleKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
293
+ const hasModifier = event.shiftKey || event.metaKey || event.ctrlKey || event.altKey;
294
+ if (event.key === 'Enter' && !hasModifier) {
295
+ event.preventDefault();
296
+ event.stopPropagation();
297
+ void handleSubmit();
298
+ }
299
+ };
300
+
301
+ return (
302
+ <div
303
+ role="group"
304
+ aria-label="Writing assistant"
305
+ data-submitting={isSubmitting}
306
+ className="group/scribe-assist-form flex gap-8 px-16 py-12"
307
+ >
308
+ <div className="flex flex-1 flex-col items-start gap-8">
309
+ <div className="flex gap-8 text-text-secondary">
310
+ <span className="inline-flex size-16 shrink-0 items-center justify-center">
311
+ <ScribeAssistantIcon fontSize="inherit" aria-hidden />
312
+ </span>
313
+ <Typography variant="caption-md" className="line-clamp-3 text-inherit">
314
+ “{selection}”
315
+ </Typography>
316
+ </div>
317
+ <Divider />
318
+ <div className="relative w-full flex-1">
319
+ <Typography
320
+ variant="body"
321
+ role="status"
322
+ className="pointer-events-none absolute top-0 left-0 w-full text-text-tertiary opacity-0 group-data-[submitting=true]/scribe-assist-form:opacity-100"
323
+ >
324
+ {isSubmitting ? 'Executing…' : ''}
325
+ </Typography>
326
+ <RichTextArea
327
+ ref={editorRef}
328
+ value={instruction}
329
+ placeholder="Tell the writing assistant what to write"
330
+ isDisabled={isSubmitting}
331
+ className={cn(
332
+ editorClassName,
333
+ 'group-data-[submitting=true]/scribe-assist-form:opacity-0',
334
+ )}
335
+ placeholderClassName="group-data-[submitting=true]/scribe-assist-form:opacity-0"
336
+ onChange={setInstruction}
337
+ onKeyDown={handleKeyDown}
338
+ />
339
+ </div>
340
+ {hasError && (
341
+ <Typography variant="caption-md" role="alert" className="text-error-main">
342
+ The text couldn’t be rewritten. Try again.
343
+ </Typography>
344
+ )}
345
+ </div>
346
+ <div className="flex shrink-0 items-end">
347
+ <IconButton
348
+ type="button"
349
+ size="md"
350
+ variant="primary"
351
+ aria-label="Rewrite selection"
352
+ isDisabled={isSubmitting}
353
+ onClick={() => void handleSubmit()}
354
+ >
355
+ <EnterIcon />
356
+ </IconButton>
357
+ </div>
358
+ </div>
359
+ );
360
+ }
361
+
362
+ type ScribeAssistStory = StoryObj<typeof ScribeAssistForm>;
363
+
364
+ /** An instruction field that submits on Enter through `onKeyDown`: the writing assistant under a quoted selection. */
365
+ export const SubmitOnEnter: ScribeAssistStory = {
366
+ parameters: { controls: { disable: true } },
367
+ args: { selection: SCRIBE_SELECTION, onAssist: fn(() => delay(800)) },
368
+ render: (args) => <ScribeAssistForm {...args} />,
369
+ };
370
+
371
+ /** The editor in each place it goes: a form section, a reply composer and a document editor. */
372
+ export const Examples: Story = {
373
+ parameters: { controls: { disable: true } },
374
+ decorators: [
375
+ (Story) => (
376
+ <div className="bg-paper-elevation-0 p-16">
377
+ <Story />
378
+ </div>
379
+ ),
380
+ ],
381
+ render: () => (
382
+ <div className="flex flex-col gap-24">
383
+ <ParentBlock parent="form section">
384
+ <section aria-labelledby="examples-signature-title" className="flex flex-col gap-8">
385
+ <Typography variant="body-small-high" fontWeight="medium" asChild>
386
+ <h3 id="examples-signature-title">Signature</h3>
387
+ </Typography>
388
+ <div className={cn(surfaceClassName, 'min-h-25')}>
389
+ <RichTextArea
390
+ source="html"
391
+ name="signature"
392
+ value={SIGNATURE_HTML}
393
+ placeholder="Write your signature"
394
+ className={editorClassName}
395
+ onChange={fn()}
396
+ />
397
+ </div>
398
+ </section>
399
+ </ParentBlock>
400
+
401
+ <ParentBlock parent="reply composer">
402
+ <div
403
+ role="group"
404
+ aria-label="Reply to Lena Brunner"
405
+ className={cn(surfaceClassName, 'flex items-end gap-8')}
406
+ >
407
+ <div className="relative min-h-40 flex-1">
408
+ <RichTextArea
409
+ placeholder="Write a reply"
410
+ className={editorClassName}
411
+ onChange={fn()}
412
+ onKeyDown={fn()}
413
+ />
414
+ </div>
415
+ <IconButton variant="primary" size="md" aria-label="Send reply">
416
+ <EnterIcon />
417
+ </IconButton>
418
+ </div>
419
+ </ParentBlock>
420
+
421
+ <ParentBlock parent="document editor">
422
+ <article aria-label="Email draft" className={cn(surfaceClassName, 'h-60')}>
423
+ <RichTextArea
424
+ source="html"
425
+ value={OFFER_EMAIL_HTML}
426
+ placeholder="Write your email"
427
+ className={editorClassName}
428
+ onChange={fn()}
429
+ />
430
+ </article>
431
+ </ParentBlock>
432
+ </div>
433
+ ),
434
+ };
435
+
436
+ // TODO(echo-ds): the editable element has no accessible name and RichTextArea has no prop to give
437
+ // it one, so these tests find it by role alone.
438
+
439
+ /** Typing appends to the draft, reports the Markdown through `onChange`, and every styled element carries its slot name. */
440
+ export const DefaultTypeAndSlots: Story = {
441
+ ...Default,
442
+ tags: ['e2e', '!autodocs'],
443
+ play: async ({ args, canvas, canvasElement, userEvent, step }) => {
444
+ const editor = canvas.getByRole('textbox');
445
+ const root = canvasElement.querySelector('[data-slot="rich-text-area"]');
446
+
447
+ await step('Renders the Markdown as formatted text', async () => {
448
+ await expect(editor).toHaveTextContent('Thursday at 14:00 works for me.');
449
+ await expect(canvas.getAllByRole('listitem')).toHaveLength(3);
450
+ await expect(canvas.getByText('Thursday at 14:00').tagName).toBe('STRONG');
451
+ });
452
+
453
+ await step('Root and editable carry their slot names', async () => {
454
+ await expect(root).toHaveAttribute('data-disabled', 'false');
455
+ await expect(editor).toHaveAttribute('data-slot', 'rich-text-area-editable');
456
+ await expect(root).toContainElement(editor);
457
+ });
458
+
459
+ await step('Typing reports the whole draft as Markdown', async () => {
460
+ await userEvent.click(editor);
461
+ await expect(args.onFocusChange).toHaveBeenCalledWith(true);
462
+ await userEvent.keyboard(' for 2025');
463
+ await expect(editor).toHaveTextContent('usage report for 2025');
464
+ await expect(args.onChange).toHaveBeenLastCalledWith(
465
+ expect.stringContaining('**Thursday at 14:00** works for me.'),
466
+ );
467
+ await expect(args.onChange).toHaveBeenLastCalledWith(
468
+ expect.stringContaining("- Last quarter's usage report for 2025"),
469
+ );
470
+ await expect(args.onKeyDown).toHaveBeenCalled();
471
+ });
472
+
473
+ await step('Leaving the editor reports the blur', async () => {
474
+ await userEvent.tab();
475
+ await expect(args.onBlur).toHaveBeenCalled();
476
+ await expect(args.onFocusChange).toHaveBeenLastCalledWith(false);
477
+ });
478
+ },
479
+ };
480
+
481
+ /** An empty editor shows the placeholder in its own slot, and the first character removes it. */
482
+ export const EmptyShowsPlaceholder: Story = {
483
+ ...Empty,
484
+ tags: ['e2e', '!autodocs'],
485
+ play: async ({ canvas, userEvent, step }) => {
486
+ const editor = canvas.getByRole('textbox');
487
+
488
+ await step('Shows the placeholder and announces it', async () => {
489
+ await expect(editor).toHaveAttribute('aria-placeholder', 'Write a reply');
490
+ await expect(canvas.getByText('Write a reply')).toBeVisible();
491
+ await expect(canvas.getByText('Write a reply')).toHaveAttribute(
492
+ 'data-slot',
493
+ 'rich-text-area-placeholder',
494
+ );
495
+ });
496
+
497
+ await step('Typing removes it', async () => {
498
+ await userEvent.click(editor);
499
+ await userEvent.keyboard('Thanks, that works');
500
+ await expect(editor).toHaveTextContent('Thanks, that works');
501
+ await expect(canvas.queryByText('Write a reply')).toBeNull();
502
+ });
503
+ },
504
+ };
505
+
506
+ /** A disabled editor is marked disabled and read-only, and typing at it changes nothing. */
507
+ export const DisabledBlocksEditing: Story = {
508
+ ...Disabled,
509
+ tags: ['e2e', '!autodocs'],
510
+ play: async ({ args, canvas, canvasElement, userEvent }) => {
511
+ const editor = canvas.getByRole('textbox');
512
+ const root = canvasElement.querySelector('[data-slot="rich-text-area"]');
513
+
514
+ await expect(root).toHaveAttribute('data-disabled', 'true');
515
+ await expect(root).toHaveAttribute('aria-disabled', 'true');
516
+ await expect(editor).toHaveAttribute('aria-readonly', 'true');
517
+ await expect(editor).toHaveAttribute('contenteditable', 'false');
518
+
519
+ const before = editor.textContent;
520
+ await userEvent.click(editor);
521
+ await userEvent.keyboard('Not typed');
522
+ await expect(editor.textContent).toBe(before);
523
+ await expect(args.onChange).not.toHaveBeenCalledWith(expect.stringContaining('Not typed'));
524
+ },
525
+ };
526
+
527
+ /** With `source="html"` the value is read as HTML and edits come back as HTML. */
528
+ export const HtmlSourceRoundTrip: Story = {
529
+ ...HtmlSource,
530
+ tags: ['e2e', '!autodocs'],
531
+ play: async ({ args, canvas, userEvent }) => {
532
+ const editor = canvas.getByRole('textbox');
533
+
534
+ await expect(canvas.getByText('Noah Keller').tagName).toBe('STRONG');
535
+ await expect(canvas.getByRole('link', { name: 'noah.keller@company.com' })).toBeVisible();
536
+
537
+ await userEvent.click(editor);
538
+ await userEvent.keyboard('!');
539
+ await expect(args.onChange).toHaveBeenLastCalledWith(expect.stringContaining('<a href='));
540
+ await expect(args.onChange).toHaveBeenLastCalledWith(expect.stringContaining('Noah Keller'));
541
+ },
542
+ };
543
+
544
+ /** An edit reaches the stored value, and setting the value to an empty string clears the editor. */
545
+ export const ControlledEditAndClear: ReplyDraftStory = {
546
+ ...Controlled,
547
+ tags: ['e2e', '!autodocs'],
548
+ play: async ({ args, canvas, userEvent, step }) => {
549
+ const editor = canvas.getByRole('textbox');
550
+ const stored = canvas.getByLabelText('Stored Markdown');
551
+
552
+ await step('Typing updates the stored Markdown', async () => {
553
+ await userEvent.click(editor);
554
+ await userEvent.keyboard(' for 2025');
555
+ await expect(stored).toHaveTextContent("- Last quarter's usage report for 2025");
556
+ await expect(args.onChange).toHaveBeenLastCalledWith(
557
+ expect.stringContaining('usage report for 2025'),
558
+ );
559
+ });
560
+
561
+ await step('Discarding clears the editor and brings the placeholder back', async () => {
562
+ await userEvent.click(canvas.getByRole('button', { name: 'Discard draft' }));
563
+ await waitFor(() => expect(editor).toHaveTextContent(''));
564
+ await expect(canvas.getByText('Write a reply')).toBeVisible();
565
+ });
566
+ },
567
+ };
568
+
569
+ /** The plugins act on the events the page dispatches: a logo and an HTML snippet land in the editor. */
570
+ export const WithPluginsInsert: SignatureEditorStory = {
571
+ ...WithPlugins,
572
+ tags: ['e2e', '!autodocs'],
573
+ play: async ({ args, canvas, userEvent, step }) => {
574
+ const editor = canvas.getByRole('textbox');
575
+
576
+ await step('ImageDropPlugin inserts the image', async () => {
577
+ await userEvent.click(canvas.getByRole('button', { name: 'Add logo' }));
578
+ await expect(
579
+ await canvas.findByRole('img', { name: 'Northwind Trading logo' }),
580
+ ).toBeVisible();
581
+ });
582
+
583
+ await step('HtmlPastePlugin inserts the HTML and keeps what was there', async () => {
584
+ await userEvent.click(canvas.getByRole('button', { name: 'Add disclaimer' }));
585
+ await waitFor(() =>
586
+ expect(editor).toHaveTextContent('This message is confidential and intended'),
587
+ );
588
+ await expect(editor).toHaveTextContent('Noah Keller');
589
+ await expect(args.onChange).toHaveBeenLastCalledWith(
590
+ expect.stringContaining('This message is confidential'),
591
+ );
592
+ });
593
+ },
594
+ };
595
+
596
+ /** Enter submits the instruction, Shift+Enter adds a line, and the field clears when the request succeeds. */
597
+ export const SubmitOnEnterSuccess: ScribeAssistStory = {
598
+ ...SubmitOnEnter,
599
+ tags: ['e2e', '!autodocs'],
600
+ args: { selection: SCRIBE_SELECTION, onAssist: fn(() => delay(300)) },
601
+ play: async ({ args, canvas, userEvent, step }) => {
602
+ const editor = canvas.getByRole('textbox');
603
+
604
+ await step('Enter on an empty field submits nothing and adds no line', async () => {
605
+ await userEvent.click(editor);
606
+ await userEvent.keyboard('{Enter}');
607
+ await expect(args.onAssist).not.toHaveBeenCalled();
608
+ await expect(editor.querySelectorAll('p')).toHaveLength(1);
609
+ });
610
+
611
+ await step('Shift+Enter adds a line without submitting', async () => {
612
+ await userEvent.keyboard('Make it shorter{Shift>}{Enter}{/Shift}Keep the greeting');
613
+ await expect(args.onAssist).not.toHaveBeenCalled();
614
+ await expect(editor).toHaveTextContent('Make it shorter');
615
+ await expect(editor).toHaveTextContent('Keep the greeting');
616
+ });
617
+
618
+ await step('Enter submits and locks the field while the request runs', async () => {
619
+ await userEvent.keyboard('{Enter}');
620
+ await expect(args.onAssist).toHaveBeenCalledTimes(1);
621
+ await expect(args.onAssist).toHaveBeenCalledWith(expect.stringContaining('Make it shorter'));
622
+ await expect(args.onAssist).toHaveBeenCalledWith(
623
+ expect.stringContaining('Keep the greeting'),
624
+ );
625
+ await expect(await canvas.findByText('Executing…')).toBeVisible();
626
+ await expect(editor).toHaveAttribute('contenteditable', 'false');
627
+ });
628
+
629
+ await step('Success clears the field for the next instruction', async () => {
630
+ await waitFor(() => expect(editor).toHaveTextContent(''));
631
+ await expect(editor).toHaveAttribute('contenteditable', 'true');
632
+ await expect(
633
+ await canvas.findByText('Tell the writing assistant what to write'),
634
+ ).toBeVisible();
635
+ });
636
+ },
637
+ };
638
+
639
+ /** A failed request keeps the instruction in the field and says what happened. */
640
+ export const SubmitOnEnterError: ScribeAssistStory = {
641
+ ...SubmitOnEnter,
642
+ tags: ['e2e', '!autodocs'],
643
+ args: {
644
+ selection: SCRIBE_SELECTION,
645
+ onAssist: fn(async () => {
646
+ await delay(300);
647
+ throw new Error('Network error');
648
+ }),
649
+ },
650
+ play: async ({ args, canvas, userEvent }) => {
651
+ const editor = canvas.getByRole('textbox');
652
+
653
+ await userEvent.click(editor);
654
+ await userEvent.keyboard('Make it shorter{Enter}');
655
+
656
+ await expect(await canvas.findByRole('alert')).toHaveTextContent(
657
+ 'The text couldn’t be rewritten. Try again.',
138
658
  );
659
+ await expect(args.onAssist).toHaveBeenCalledWith('Make it shorter');
660
+ await expect(editor).toHaveTextContent('Make it shorter');
661
+ await waitFor(() => expect(editor).toHaveAttribute('contenteditable', 'true'));
662
+ },
663
+ };
664
+
665
+ /** Every prop on the Controls panel, starting from a signature editor with both plugins mounted. */
666
+ export const Playground: Story = {
667
+ tags: ['!autodocs'],
668
+ args: {
669
+ name: 'signature',
670
+ source: 'html',
671
+ value: SIGNATURE_HTML,
672
+ placeholder: 'Write your signature',
673
+ isDisabled: false,
674
+ className: editorClassName,
675
+ containerClassName: 'p-12',
676
+ placeholderClassName: 'left-12 top-12',
677
+ children: 'Image drop and HTML paste',
678
+ },
679
+ argTypes: {
680
+ children: {
681
+ control: 'select',
682
+ options: ['None', 'Image drop and HTML paste'],
683
+ mapping: {
684
+ None: undefined,
685
+ 'Image drop and HTML paste': (
686
+ <>
687
+ <ImageDropPlugin />
688
+ <HtmlPastePlugin />
689
+ </>
690
+ ),
691
+ },
692
+ description:
693
+ 'Extra Lexical plugins rendered inside the editor. They draw nothing; they act on `ImageAddedEvent`, `PasteHtmlEvent` and `InsertHtmlEvent`.',
694
+ },
139
695
  },
140
696
  };