@kortix/ui 0.14.19 → 0.15.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 (414) hide show
  1. package/README.md +1 -1
  2. package/dist/_vendor/kortix-shared.js +956 -73
  3. package/dist/_vendor/shared/artifact-annotations.d.ts +85 -607
  4. package/dist/_vendor/shared/artifact-comments.d.ts +53 -489
  5. package/dist/_vendor/shared/index.d.ts +0 -1
  6. package/dist/_vendor/shared/peer-message-prompt.d.ts +7 -1
  7. package/dist/_vendor/shared/project-glyphs.d.ts +103 -20
  8. package/dist/_vendor/shared/webhook-signing.d.ts +3 -1
  9. package/dist/access/access/access-dialog-share.d.ts +3 -28
  10. package/dist/access/access/access-dialog-share.js +3 -75
  11. package/dist/artifacts/artifact-frame.js +26 -2
  12. package/dist/artifacts/artifact-session.js +6 -2
  13. package/dist/artifacts/frame-policy.d.ts +2 -9
  14. package/dist/artifacts/frame-policy.js +2 -25
  15. package/dist/customize/agents/agents-page.js +1 -1
  16. package/dist/customize/agents/create-agent-modal.js +1 -1
  17. package/dist/customize/connectors/connector-filter.d.ts +2 -1
  18. package/dist/customize/connectors/connector-filter.js +2 -3
  19. package/dist/customize/connectors/connectors-page.js +15 -24
  20. package/dist/customize/connectors/detail/connector-status.d.ts +3 -24
  21. package/dist/customize/connectors/detail/connector-status.js +2 -42
  22. package/dist/customize/connectors/detail/use-connector-detail.d.ts +2 -6
  23. package/dist/customize/connectors/detail/use-connector-detail.js +3 -13
  24. package/dist/customize/connectors/install/install.d.ts +2 -6
  25. package/dist/customize/connectors/install/install.js +2 -16
  26. package/dist/customize/connectors/provider-label.d.ts +4 -17
  27. package/dist/customize/connectors/provider-label.js +4 -37
  28. package/dist/customize/providers/provider-connect.d.ts +6 -15
  29. package/dist/customize/providers/provider-connect.js +5 -36
  30. package/dist/customize/sections/connector-connection-form.d.ts +3 -7
  31. package/dist/customize/sections/connector-connection-form.js +2 -33
  32. package/dist/customize/sections/connector-oauth2-auto.d.ts +3 -33
  33. package/dist/customize/sections/connector-oauth2-auto.js +2 -64
  34. package/dist/customize/sections/gateway-view.d.ts +6 -5
  35. package/dist/customize/sections/gateway-view.js +31 -13
  36. package/dist/customize/sections/llm-provider/constants.d.ts +1 -2
  37. package/dist/customize/sections/llm-provider/constants.js +1 -2
  38. package/dist/customize/sections/llm-provider/utils.d.ts +1 -41
  39. package/dist/customize/sections/llm-provider/utils.js +1 -52
  40. package/dist/customize/sections/view/account-secret-resources-panel.js +4 -1
  41. package/dist/customize/sections/view/agent-editor-catalog.js +0 -5
  42. package/dist/customize/sections/view/channel-settings-patch.js +1 -1
  43. package/dist/customize/sections/view/channels-view.js +8 -8
  44. package/dist/customize/sections/view/connector-connections.d.ts +5 -85
  45. package/dist/customize/sections/view/connector-connections.js +5 -99
  46. package/dist/customize/sections/view/gateway/gateway-logs.d.ts +42 -3
  47. package/dist/customize/sections/view/gateway/gateway-logs.js +212 -15
  48. package/dist/customize/sections/view/gateway/gateway-overview.js +1 -1
  49. package/dist/customize/sections/view/gateway/gateway-routing.d.ts +3 -3
  50. package/dist/customize/sections/view/gateway/gateway-routing.js +81 -200
  51. package/dist/customize/sections/view/gateway/routing-parts.d.ts +101 -0
  52. package/dist/customize/sections/view/gateway/routing-parts.js +154 -0
  53. package/dist/customize/sections/view/gateway/routing-sentence-layout.d.ts +2 -0
  54. package/dist/customize/sections/view/gateway/routing-sentence-layout.js +82 -0
  55. package/dist/customize/sections/view/review-center-connected.js +17 -15
  56. package/dist/customize/sections/view/review-view.d.ts +7 -0
  57. package/dist/customize/sections/view/review-view.js +11 -0
  58. package/dist/customize/sections/view/secret-delivery.js +1 -1
  59. package/dist/customize/sections/view/secrets-view.js +1 -1
  60. package/dist/customize/sections/view/subscription-usage-tab.d.ts +14 -0
  61. package/dist/customize/sections/view/subscription-usage-tab.js +122 -0
  62. package/dist/customize/sections/view/subscription-usage.d.ts +34 -0
  63. package/dist/customize/sections/view/subscription-usage.js +98 -0
  64. package/dist/customize/settings/tabs/experimental-tab.js +3 -3
  65. package/dist/customize/settings/tabs/general-tab.js +65 -10
  66. package/dist/customize/shared/catalog/catalog-card.d.ts +9 -4
  67. package/dist/customize/shared/catalog/catalog-card.js +3 -3
  68. package/dist/customize/shared/channels-switch-dialog.d.ts +1 -1
  69. package/dist/customize/shared/channels-switch-dialog.js +1 -1
  70. package/dist/customize/shared/feature-gate-screen.js +1 -1
  71. package/dist/customize/triggers/schedule/post-to-field.d.ts +1 -1
  72. package/dist/customize/triggers/schedule/post-to-field.js +2 -2
  73. package/dist/customize/triggers/schedule/trigger-composer-logic.d.ts +1 -1
  74. package/dist/files/drives/conflict-marks.d.ts +28 -0
  75. package/dist/files/drives/conflict-marks.js +39 -0
  76. package/dist/files/drives/session-drives-chip.js +15 -10
  77. package/dist/files/viewer/index.d.ts +1 -1
  78. package/dist/files/viewer/index.js +1 -1
  79. package/dist/i18n/en.d.ts +451 -203
  80. package/dist/i18n/en.js +543 -295
  81. package/dist/index.d.ts +1 -1
  82. package/dist/index.js +1 -1
  83. package/dist/internal/account-hub/sections.d.ts +1 -1
  84. package/dist/internal/capture/use-capture-area.d.ts +5 -1
  85. package/dist/internal/capture/use-capture-area.js +16 -9
  86. package/dist/internal/goals/goal-meta.d.ts +50 -3
  87. package/dist/internal/goals/goal-meta.js +144 -9
  88. package/dist/internal/hooks/connectors/use-add-account.d.ts +3 -9
  89. package/dist/internal/hooks/connectors/use-add-account.js +3 -18
  90. package/dist/internal/hooks/connectors/use-connect-link.d.ts +3 -2
  91. package/dist/internal/hooks/connectors/use-connect-link.js +15 -24
  92. package/dist/internal/hooks/connectors/use-pipedream-connect-project.d.ts +3 -56
  93. package/dist/internal/hooks/connectors/use-pipedream-connect-project.js +3 -87
  94. package/dist/internal/hooks/projects/use-new-project-session.d.ts +3 -2
  95. package/dist/internal/hooks/projects/use-new-project-session.js +4 -3
  96. package/dist/internal/hooks/projects/use-project-can-run.d.ts +7 -0
  97. package/dist/internal/hooks/projects/use-project-can-run.js +12 -5
  98. package/dist/internal/hooks/projects/use-restart-project-session.d.ts +0 -1
  99. package/dist/internal/hooks/projects/use-restart-project-session.js +0 -1
  100. package/dist/internal/layout/project-capability-nav.js +6 -2
  101. package/dist/internal/layout/project-page-header.d.ts +3 -1
  102. package/dist/internal/layout/project-page-header.js +2 -2
  103. package/dist/internal/lib/account-secret-access.d.ts +1 -41
  104. package/dist/internal/lib/account-secret-access.js +3 -46
  105. package/dist/internal/lib/browser-error-noise.d.ts +1 -1
  106. package/dist/internal/lib/browser-error-noise.js +1 -1
  107. package/dist/internal/lib/browser-noise/rules/expected-states.d.ts +2 -15
  108. package/dist/internal/lib/browser-noise/rules/expected-states.js +5 -55
  109. package/dist/internal/lib/capability-tab-routes.d.ts +3 -3
  110. package/dist/internal/lib/capability-tab-routes.js +11 -3
  111. package/dist/internal/lib/llm-providers.d.ts +4 -110
  112. package/dist/internal/lib/llm-providers.js +5 -102
  113. package/dist/internal/lib/navigation/message-link.d.ts +32 -0
  114. package/dist/internal/lib/navigation/message-link.js +51 -0
  115. package/dist/internal/lib/navigation/session-href.d.ts +11 -0
  116. package/dist/internal/lib/navigation/session-href.js +20 -0
  117. package/dist/internal/lib/navigation/session-spawn-urls.d.ts +17 -0
  118. package/dist/internal/lib/navigation/session-spawn-urls.js +26 -0
  119. package/dist/internal/lib/space-scope.d.ts +3 -3
  120. package/dist/internal/lib/space-scope.js +3 -3
  121. package/dist/internal/lib/use-project-feature-flags.js +7 -7
  122. package/dist/internal/lib/web-notifications.d.ts +1 -1
  123. package/dist/internal/lib/web-notifications.js +0 -3
  124. package/dist/internal/notifications/notification-bell.js +1 -3
  125. package/dist/internal/notifications/notification-rows.d.ts +2 -2
  126. package/dist/internal/notifications/notification-rows.js +2 -3
  127. package/dist/internal/session-types/index.d.ts +5 -7
  128. package/dist/internal/session-types/index.js +5 -7
  129. package/dist/internal/stores/active-space-store.d.ts +1 -1
  130. package/dist/internal/stores/active-space-store.js +1 -1
  131. package/dist/internal/stores/kortix-computer-store.d.ts +15 -0
  132. package/dist/internal/stores/kortix-computer-store.js +12 -0
  133. package/dist/lib/routes.d.ts +17 -7
  134. package/dist/lib/routes.js +18 -2
  135. package/dist/markdown/app-link-icons.d.ts +7 -0
  136. package/dist/markdown/app-link-icons.js +20 -0
  137. package/dist/markdown/app-links.d.ts +9 -0
  138. package/dist/markdown/app-links.js +112 -0
  139. package/dist/markdown/doc-editor/doc-attrs.d.ts +28 -0
  140. package/dist/markdown/doc-editor/doc-attrs.js +156 -0
  141. package/dist/markdown/doc-editor/doc-embed.d.ts +6 -0
  142. package/dist/markdown/doc-editor/doc-embed.js +26 -8
  143. package/dist/markdown/doc-editor/doc-extensions.d.ts +10 -0
  144. package/dist/markdown/doc-editor/doc-extensions.js +55 -8
  145. package/dist/markdown/doc-editor/doc-fidelity.d.ts +72 -0
  146. package/dist/markdown/doc-editor/doc-fidelity.js +135 -0
  147. package/dist/markdown/doc-editor/doc-node-view.d.ts +9 -0
  148. package/dist/markdown/doc-editor/doc-node-view.js +29 -0
  149. package/dist/markdown/doc-editor/markdown.d.ts +20 -0
  150. package/dist/markdown/doc-editor/markdown.js +455 -18
  151. package/dist/markdown/unified-markdown.d.ts +1 -1
  152. package/dist/markdown/unified-markdown.js +129 -10
  153. package/dist/primitives/emoji-picker.js +16 -100
  154. package/dist/primitives/emoji-tint.js +12 -12
  155. package/dist/primitives/entity-avatar.js +14 -9
  156. package/dist/primitives/glyph-face.d.ts +19 -12
  157. package/dist/primitives/glyph-face.js +59 -20
  158. package/dist/primitives/glyph-paths-source.d.ts +7 -0
  159. package/dist/primitives/glyph-paths-source.js +14 -6
  160. package/dist/primitives/glyph-paths.generated.d.ts +1 -1
  161. package/dist/primitives/glyph-paths.generated.js +947 -204
  162. package/dist/primitives/glyph-picker.d.ts +6 -10
  163. package/dist/primitives/glyph-picker.js +147 -98
  164. package/dist/primitives/glyph-registry.js +1604 -1
  165. package/dist/primitives/glyph-tint.d.ts +28 -3
  166. package/dist/primitives/glyph-tint.js +41 -83
  167. package/dist/primitives/kortix-glyphs.d.ts +32 -0
  168. package/dist/primitives/kortix-glyphs.js +157 -0
  169. package/dist/primitives/project-icon-picker.d.ts +8 -1
  170. package/dist/primitives/project-icon-picker.js +13 -5
  171. package/dist/primitives/user-avatar.d.ts +8 -1
  172. package/dist/primitives/user-avatar.js +2 -2
  173. package/dist/providers/ui-provider.d.ts +1 -8
  174. package/dist/session/actions/project-session-list-helpers.js +1 -1
  175. package/dist/session/agents/agent-model.js +4 -0
  176. package/dist/session/agents/agent-state-mark.d.ts +12 -7
  177. package/dist/session/agents/agent-state-mark.js +37 -15
  178. package/dist/session/agents/agent-strip.js +8 -2
  179. package/dist/session/agents/agent-surface.d.ts +81 -0
  180. package/dist/session/agents/agent-surface.js +97 -0
  181. package/dist/session/agents/held-messages.js +7 -4
  182. package/dist/session/agents/legacy-subagent-chat.js +1 -1
  183. package/dist/session/agents/session-peek.js +24 -12
  184. package/dist/session/agents/steer-session.d.ts +2 -0
  185. package/dist/session/agents/steer-session.js +3 -2
  186. package/dist/session/agents/subagent-dialog-content.d.ts +30 -1
  187. package/dist/session/agents/subagent-dialog-content.js +147 -33
  188. package/dist/session/agents/subagent-view.d.ts +15 -5
  189. package/dist/session/agents/subagent-view.js +28 -6
  190. package/dist/session/agents/tasks-panel.js +2 -12
  191. package/dist/session/agents/workflow-run-controls.d.ts +3 -1
  192. package/dist/session/agents/workflow-run-controls.js +12 -7
  193. package/dist/session/composer/ComposerCard.d.ts +7 -1
  194. package/dist/session/composer/ComposerCard.js +74 -9
  195. package/dist/session/composer/agent-selector.d.ts +16 -0
  196. package/dist/session/composer/agent-selector.js +19 -11
  197. package/dist/session/composer/chat-input/chat-input-control.d.ts +64 -0
  198. package/dist/session/composer/chat-input/chat-input-control.js +578 -0
  199. package/dist/session/composer/chat-input/chat-input-overrides.d.ts +76 -0
  200. package/dist/session/composer/chat-input/chat-input-overrides.js +40 -0
  201. package/dist/session/composer/chat-input/chat-input-panes.d.ts +56 -0
  202. package/dist/session/composer/chat-input/chat-input-panes.js +148 -0
  203. package/dist/session/composer/chat-input/chat-input-summary.d.ts +67 -0
  204. package/dist/session/composer/chat-input/chat-input-summary.js +67 -0
  205. package/dist/session/composer/chat-queue-lines.d.ts +20 -0
  206. package/dist/session/composer/chat-queue-lines.js +20 -0
  207. package/dist/session/composer/composer-chat-input.d.ts +8 -1
  208. package/dist/session/composer/composer-chat-input.js +12 -4
  209. package/dist/session/composer/composer-focus-context.d.ts +7 -0
  210. package/dist/session/composer/composer-focus-context.js +9 -0
  211. package/dist/session/composer/composer-toolbar.d.ts +3 -1
  212. package/dist/session/composer/composer-toolbar.js +3 -3
  213. package/dist/session/composer/composer-underbar.d.ts +10 -1
  214. package/dist/session/composer/composer-underbar.js +10 -2
  215. package/dist/session/composer/composer.d.ts +12 -0
  216. package/dist/session/composer/composer.js +55 -1
  217. package/dist/session/composer/editor/composer-editor.d.ts +10 -2
  218. package/dist/session/composer/editor/composer-editor.js +22 -6
  219. package/dist/session/composer/editor/first-visual-line.d.ts +2 -0
  220. package/dist/session/composer/editor/first-visual-line.js +9 -0
  221. package/dist/session/composer/editor/mention-node.js +2 -0
  222. package/dist/session/composer/editor/serialize.js +9 -1
  223. package/dist/session/composer/hooks/use-file-search.d.ts +1 -1
  224. package/dist/session/composer/hooks/use-file-search.js +1 -1
  225. package/dist/session/composer/menus/mention-controller.d.ts +3 -11
  226. package/dist/session/composer/menus/mention-controller.js +56 -16
  227. package/dist/session/composer/menus/mention-menu.d.ts +7 -2
  228. package/dist/session/composer/menus/mention-menu.js +17 -9
  229. package/dist/session/composer/menus/menu-items.d.ts +9 -0
  230. package/dist/session/composer/menus/space-mentions.d.ts +48 -0
  231. package/dist/session/composer/menus/space-mentions.js +83 -0
  232. package/dist/session/composer/prompt-history.d.ts +9 -0
  233. package/dist/session/composer/prompt-history.js +45 -0
  234. package/dist/session/composer/queue-projection.d.ts +2 -0
  235. package/dist/session/composer/queue-projection.js +1 -0
  236. package/dist/session/composer/queued-prompt-list.js +53 -4
  237. package/dist/session/composer/reasoning-effort-selector.d.ts +20 -0
  238. package/dist/session/composer/reasoning-effort-selector.js +3 -3
  239. package/dist/session/composer/types.d.ts +2 -1
  240. package/dist/session/header/session-site-header.js +7 -3
  241. package/dist/session/header/subagent-hover-card.d.ts +7 -4
  242. package/dist/session/header/subagent-hover-card.js +62 -11
  243. package/dist/session/list/session-status-mark.d.ts +42 -0
  244. package/dist/{workspace/sidebar → session/list}/session-status-mark.js +37 -2
  245. package/dist/session/models/model-selector.d.ts +7 -2
  246. package/dist/session/models/model-selector.js +39 -31
  247. package/dist/session/overrides/provider-secret-pool-editor.d.ts +11 -0
  248. package/dist/session/overrides/provider-secret-pool-editor.js +17 -0
  249. package/dist/session/overrides/session-overrides-control.d.ts +5 -0
  250. package/dist/session/overrides/session-overrides-toolbar.js +147 -7
  251. package/dist/session/panel/model-switch-event.d.ts +8 -0
  252. package/dist/session/panel/model-switch-event.js +19 -0
  253. package/dist/session/panel/session-audit-panel.js +3 -2
  254. package/dist/session/panel/session-desktop.js +5 -1
  255. package/dist/session/panel/session-panel-provider.js +1 -1
  256. package/dist/session/panel/shared/use-panel-handoffs.d.ts +2 -2
  257. package/dist/session/panel/shared/use-panel-handoffs.js +21 -2
  258. package/dist/session/prompts/ask-deck.d.ts +21 -0
  259. package/dist/session/prompts/ask-deck.js +253 -0
  260. package/dist/session/prompts/session-permission-prompt.d.ts +7 -1
  261. package/dist/session/prompts/session-permission-prompt.js +3 -3
  262. package/dist/session/status/session-load-state.d.ts +0 -1
  263. package/dist/session/status/session-load-state.js +2 -4
  264. package/dist/session/thread/message-parsing.d.ts +0 -1
  265. package/dist/session/thread/message-parsing.js +0 -1
  266. package/dist/session/thread/session-chat.d.ts +3 -1
  267. package/dist/session/thread/session-chat.js +459 -310
  268. package/dist/session/thread/session-context-metrics.d.ts +0 -1
  269. package/dist/session/thread/session-context-metrics.js +1 -1
  270. package/dist/session/thread/session-context-sub-sessions.js +3 -1
  271. package/dist/session/thread/show-work.d.ts +38 -0
  272. package/dist/session/thread/show-work.js +115 -0
  273. package/dist/session/thread/thread-boot-rows.d.ts +2 -1
  274. package/dist/session/thread/thread-boot-rows.js +7 -3
  275. package/dist/session/thread/transcript-rows.d.ts +36 -0
  276. package/dist/session/thread/transcript.d.ts +46 -2
  277. package/dist/session/thread/transcript.js +226 -34
  278. package/dist/session/thread/typing-indicator.d.ts +21 -0
  279. package/dist/session/thread/typing-indicator.js +46 -0
  280. package/dist/session/tool/shared/infrastructure-contexts.d.ts +12 -0
  281. package/dist/session/tool/shared/infrastructure-contexts.js +6 -0
  282. package/dist/session/tool/tool-part-renderer.d.ts +2 -0
  283. package/dist/session/tool/tool-part-renderer.js +16 -2
  284. package/dist/session/tool/tools/kortix-action-tool.js +8 -1
  285. package/dist/session/tool/tools/multi-agent-tool-bodies.d.ts +19 -0
  286. package/dist/session/tool/tools/multi-agent-tool-bodies.js +34 -13
  287. package/dist/session/tool/tools/session-spawn-urls.d.ts +1 -16
  288. package/dist/session/tool/tools/session-spawn-urls.js +4 -26
  289. package/dist/session/tool/tools/task-tool.d.ts +5 -18
  290. package/dist/session/tool/tools/task-tool.js +47 -86
  291. package/dist/session/tool/tools/workflow-progress.d.ts +14 -18
  292. package/dist/session/tool/tools/workflow-progress.js +24 -179
  293. package/dist/session/tool/tools/workflow-result-text.d.ts +15 -0
  294. package/dist/session/tool/tools/workflow-result-text.js +34 -0
  295. package/dist/session/tool/tools/workflow-run-card.d.ts +35 -0
  296. package/dist/session/tool/tools/workflow-run-card.js +157 -0
  297. package/dist/session/tool/tools/workflow-tool.js +45 -58
  298. package/dist/session/turn/activity-burst.d.ts +2 -2
  299. package/dist/session/turn/activity-burst.js +11 -5
  300. package/dist/session/turn/answered-question-step.d.ts +29 -0
  301. package/dist/session/turn/answered-question-step.js +48 -3
  302. package/dist/session/turn/notice-batch-group.d.ts +4 -4
  303. package/dist/session/turn/notice-batch-group.js +5 -8
  304. package/dist/session/turn/peer-message-row.d.ts +15 -0
  305. package/dist/session/turn/peer-message-row.js +38 -47
  306. package/dist/session/turn/subagent-notice-row.d.ts +16 -1
  307. package/dist/session/turn/subagent-notice-row.js +47 -35
  308. package/dist/session/turn/throttled-markdown.js +4 -1
  309. package/dist/session/turn/turn-work-accordion.d.ts +10 -3
  310. package/dist/session/turn/turn-work-accordion.js +18 -11
  311. package/dist/session/turn/user-message.js +16 -42
  312. package/dist/session/turn/voice-turn.d.ts +22 -0
  313. package/dist/session/turn/voice-turn.js +32 -0
  314. package/dist/session/voice/call-ring.d.ts +10 -0
  315. package/dist/session/voice/call-ring.js +52 -0
  316. package/dist/session/voice/use-voice-call.d.ts +4 -4
  317. package/dist/session/voice/use-voice-call.js +6 -9
  318. package/dist/session/voice/voice-call-card.d.ts +6 -0
  319. package/dist/session/voice/voice-call-card.js +113 -0
  320. package/dist/session/voice/voice-call-state.d.ts +3 -0
  321. package/dist/session/voice/voice-call-state.js +2 -1
  322. package/dist/session/voice/voice-call-store.d.ts +16 -6
  323. package/dist/session/voice/voice-call-store.js +5 -5
  324. package/dist/session/voice/voice-call.d.ts +4 -8
  325. package/dist/session/voice/voice-call.js +33 -36
  326. package/dist/styles/components.css +33 -0
  327. package/dist/styles/theme.css +26 -0
  328. package/dist/styles.css +1 -1
  329. package/dist/workspace/admin/project-admin-dashboard.d.ts +1 -1
  330. package/dist/workspace/admin/project-admin-dashboard.js +12 -9
  331. package/dist/workspace/index.d.ts +3 -2
  332. package/dist/workspace/index.js +2 -1
  333. package/dist/workspace/layout/use-project-home-send.d.ts +2 -0
  334. package/dist/workspace/layout/use-project-home-send.js +5 -3
  335. package/dist/workspace/memory/company-memory-page.d.ts +1 -1
  336. package/dist/workspace/memory/company-memory-page.js +1 -1
  337. package/dist/workspace/new/use-creatable-accounts.js +13 -4
  338. package/dist/workspace/projects/modal/project-icon-field.js +49 -34
  339. package/dist/workspace/review/review-center.d.ts +4 -1
  340. package/dist/workspace/review/review-center.js +6 -3
  341. package/dist/workspace/sessions/project-sessions-helpers.js +1 -1
  342. package/dist/workspace/sessions/project-sessions-view.js +1 -1
  343. package/dist/workspace/sessions/session-row.js +6 -4
  344. package/dist/workspace/sessions/sessions-toolbar.d.ts +1 -1
  345. package/dist/workspace/sessions/sessions-toolbar.js +4 -4
  346. package/dist/workspace/sidebar/footer/project-memory-nav.d.ts +1 -1
  347. package/dist/workspace/sidebar/footer/project-memory-nav.js +1 -1
  348. package/dist/workspace/sidebar/project-nav-items.js +2 -5
  349. package/dist/workspace/sidebar/project-session-list.d.ts +7 -1
  350. package/dist/workspace/sidebar/project-session-list.js +63 -24
  351. package/dist/workspace/sidebar/project-sidebar.js +10 -7
  352. package/dist/workspace/sidebar/project-spaces-nav.d.ts +7 -3
  353. package/dist/workspace/sidebar/project-spaces-nav.js +77 -46
  354. package/dist/workspace/sidebar/session-brief-hover-card.d.ts +4 -2
  355. package/dist/workspace/sidebar/session-brief-hover-card.js +47 -28
  356. package/dist/workspace/sidebar/session-group-sections.js +12 -4
  357. package/dist/workspace/sidebar/sidebar-more-group.d.ts +13 -0
  358. package/dist/workspace/sidebar/sidebar-more-group.js +27 -0
  359. package/dist/workspace/space/space-blocks.d.ts +3 -1
  360. package/dist/workspace/space/space-blocks.js +4 -7
  361. package/dist/workspace/space/space-page.d.ts +4 -6
  362. package/dist/workspace/space/space-page.js +10 -24
  363. package/dist/workspace/space/space-tab-panels.d.ts +14 -1
  364. package/dist/workspace/space/space-tab-panels.js +12 -21
  365. package/dist/workspace/space/space-templates.d.ts +4 -5
  366. package/dist/workspace/space/space-templates.js +2 -7
  367. package/dist/workspace/space/use-space-filter.d.ts +1 -1
  368. package/dist/workspace/space/use-space-filter.js +1 -1
  369. package/dist/workspace/spaces/channels-onboarding.d.ts +2 -2
  370. package/dist/workspace/spaces/channels-onboarding.js +4 -3
  371. package/dist/workspace/spaces/create-channel-dialog.js +4 -2
  372. package/dist/workspace/spaces/principal-card.d.ts +71 -0
  373. package/dist/workspace/spaces/principal-card.js +246 -0
  374. package/dist/workspace/spaces/space-auto-open.d.ts +8 -0
  375. package/dist/workspace/spaces/space-auto-open.js +18 -0
  376. package/dist/workspace/spaces/space-avatar.d.ts +44 -0
  377. package/dist/workspace/spaces/space-avatar.js +41 -0
  378. package/dist/workspace/spaces/space-details-panel.d.ts +26 -0
  379. package/dist/workspace/spaces/space-details-panel.js +119 -0
  380. package/dist/workspace/spaces/space-identity.d.ts +49 -0
  381. package/dist/workspace/spaces/space-identity.js +104 -0
  382. package/dist/workspace/spaces/space-members.js +1 -1
  383. package/dist/workspace/spaces/space-mention-source.d.ts +12 -0
  384. package/dist/workspace/spaces/space-mention-source.js +78 -0
  385. package/dist/workspace/spaces/space-people.d.ts +29 -0
  386. package/dist/workspace/spaces/space-people.js +87 -0
  387. package/dist/workspace/spaces/space-roster.d.ts +3 -2
  388. package/dist/workspace/spaces/space-roster.js +7 -4
  389. package/dist/workspace/spaces/space-tab-list.d.ts +37 -0
  390. package/dist/workspace/spaces/space-tab-list.js +82 -0
  391. package/dist/workspace/spaces/space-tabs.d.ts +74 -0
  392. package/dist/workspace/spaces/space-tabs.js +199 -0
  393. package/dist/workspace/spaces/space-threads-tab.js +1 -1
  394. package/dist/workspace/spaces/space-timeline-view.js +126 -17
  395. package/dist/workspace/spaces/space-timeline.d.ts +44 -9
  396. package/dist/workspace/spaces/space-timeline.js +120 -12
  397. package/dist/workspace/spaces/space-view.d.ts +19 -12
  398. package/dist/workspace/spaces/space-view.js +201 -67
  399. package/dist/workspace/spaces/use-personal-space-name.d.ts +2 -0
  400. package/dist/workspace/spaces/use-personal-space-name.js +10 -0
  401. package/package.json +11 -7
  402. package/skills/kortix-ui/SKILL.md +1 -1
  403. package/skills/kortix-ui/references/custom-dashboard.md +2 -3
  404. package/skills/kortix-ui/references/modules.md +4 -4
  405. package/dist/_vendor/shared/room-prompt.d.ts +0 -66
  406. package/dist/session/voice/voice-call-bar.d.ts +0 -4
  407. package/dist/session/voice/voice-call-bar.js +0 -39
  408. package/dist/workspace/sidebar/footer/project-rooms-nav.d.ts +0 -9
  409. package/dist/workspace/sidebar/footer/project-rooms-nav.js +0 -32
  410. package/dist/workspace/sidebar/session-status-mark.d.ts +0 -19
  411. package/dist/workspace/space/space-room.d.ts +0 -20
  412. package/dist/workspace/space/space-room.js +0 -27
  413. /package/dist/{workspace/sidebar → session/list}/session-list-chrome.d.ts +0 -0
  414. /package/dist/{workspace/sidebar → session/list}/session-list-chrome.js +0 -0
@@ -1,19 +1,41 @@
1
- import { Marked } from 'marked';
1
+ import { getSchema } from '@tiptap/core';
2
+ import { DOMParser as ProseMirrorParser, DOMSerializer } from '@tiptap/pm/model';
3
+ import { Lexer, Marked } from 'marked';
2
4
  import TurndownService from 'turndown';
3
5
  import { strikethrough, tables } from 'turndown-plugin-gfm';
6
+ import { docExtensions } from './doc-extensions.js';
7
+ import { LAYOUT_WHITESPACE, MAX_DOC_BYTES, MD_ATTRIBUTE, RAW_ATTRIBUTE, blockKind, hashText, readMd, writeMd, } from './doc-fidelity.js';
4
8
  const escapeHtml = (text) => text.replace(/&/g, '&amp;').replace(/</g, '&lt;').replace(/>/g, '&gt;');
5
9
  /**
6
10
  * Raw HTML in the Markdown shows as the text it is (`<package>` in a
7
11
  * sentence), so the editor keeps it and saves it back. The editor has no
8
12
  * node for an unknown tag and would drop it. A `<video>` and a link card
9
- * (`<div class="kx-embed">`, doc-embed.tsx) are the tags a doc holds as HTML.
13
+ * (`<div class="kx-embed">`, doc-embed.tsx) are the tags a doc holds as HTML,
14
+ * and `<u>` in a sentence is the editor's underline (Markdown has none).
10
15
  */
11
16
  const DOC_HTML = /^(<\/?video\b|<div class="kx-embed">)/i;
17
+ const UNDERLINE = /^<\/?u>$/i;
12
18
  const parser = new Marked({
13
19
  renderer: {
14
- html: ({ text }) => (DOC_HTML.test(text.trim()) ? text : escapeHtml(text)),
20
+ html: ({ text, block }) => DOC_HTML.test(text.trim()) || (!block && UNDERLINE.test(text.trim())) ? text : escapeHtml(text),
15
21
  },
16
22
  });
23
+ /** marked's HTML in the editor's shape. */
24
+ function editorHtml(html) {
25
+ return (html
26
+ // marked's task items → the editor's (`li[data-type=taskItem]`).
27
+ // A loose list (blank lines between items) puts the box inside a <p>: keep the <p> as the item's text.
28
+ .replace(/<li>(<p>)?<input (checked="" )?disabled="" type="checkbox">\s*/g, (_m, p, checked) => `<li data-type="taskItem" data-checked="${checked ? 'true' : 'false'}">${p ?? ''}`)
29
+ .replace(/<ul>(\s*<li data-type="taskItem")/g, '<ul data-type="taskList">$1')
30
+ // marked keeps a fence's last newline; the editor would show it as an empty line.
31
+ .replace(/\n<\/code><\/pre>/g, '</code></pre>'));
32
+ }
33
+ /** The whole file through marked, as the editor has always opened it (`tokens`: the file already lexed). */
34
+ function convertedHtml(markdown, tokens = parser.lexer(markdown)) {
35
+ const doc = new DOMParser().parseFromString(editorHtml(parser.parser(tokens)), 'text/html');
36
+ markSoftBreaks(doc);
37
+ return doc.body.innerHTML;
38
+ }
17
39
  /**
18
40
  * The document editor holds Markdown files (a doc artifact, an agent's
19
41
  * instructions). The editor works in HTML, so a doc goes Markdown → HTML on
@@ -23,23 +45,316 @@ const parser = new Marked({
23
45
  * `<span data-soft-break>`, which reads as a space and saves as a newline.
24
46
  * A file wrapped at 72 columns stays wrapped, so a one-word edit is a
25
47
  * one-line diff.
48
+ *
49
+ * A file the editor would write differently (`* item`, a setext heading, an
50
+ * aligned table, three blank lines, no final newline) keeps its own spelling
51
+ * (`sourcePlan`): an unedited block saves byte for byte, and a block the
52
+ * editor cannot show at all (front matter, a link definition, an HTML block)
53
+ * opens as a raw block of Markdown text.
26
54
  */
27
55
  export function markdownToHtml(markdown) {
28
- const html = parser.parse(markdown, { gfm: true, async: false })
29
- // marked's task items → the editor's (`li[data-type=taskItem]`).
30
- // A loose list (blank lines between items) puts the box inside a <p>: keep the <p> as the item's text.
31
- .replace(/<li>(<p>)?<input (checked="" )?disabled="" type="checkbox">\s*/g, (_m, p, checked) => `<li data-type="taskItem" data-checked="${checked ? 'true' : 'false'}">${p ?? ''}`)
32
- .replace(/<ul>(\s*<li data-type="taskItem")/g, '<ul data-type="taskList">$1')
33
- // marked keeps a fence's last newline; the editor would show it as an empty line.
34
- .replace(/\n<\/code><\/pre>/g, '</code></pre>');
35
- return markSoftBreaks(html);
56
+ return plan(markdown).html;
57
+ }
58
+ /**
59
+ * Whether a person can open `markdown` in the editor and save it without a
60
+ * byte changing: the condition for co-editing a doc, where every client
61
+ * flushes the file from the editor. One whole-document pass when the editor
62
+ * already writes the file as it is; the plan is cached for the
63
+ * `markdownToHtml` call that opens it.
64
+ */
65
+ export function docRoundTrips(markdown) {
66
+ const { ok, reason } = plan(markdown);
67
+ return ok ? { ok } : { ok, reason };
68
+ }
69
+ // The last few files planned: the guard and the editor's load ask for the same one.
70
+ const plans = new Map();
71
+ function plan(markdown) {
72
+ const hit = plans.get(markdown);
73
+ if (hit)
74
+ return hit;
75
+ const made = makePlan(markdown);
76
+ plans.set(markdown, made);
77
+ if (plans.size > 4)
78
+ plans.delete(plans.keys().next().value);
79
+ return made;
80
+ }
81
+ function tooLarge(text) {
82
+ // A UTF-16 unit is 1 to 3 UTF-8 bytes.
83
+ if (text.length > MAX_DOC_BYTES)
84
+ return true;
85
+ if (text.length * 3 <= MAX_DOC_BYTES)
86
+ return false;
87
+ return new TextEncoder().encode(text).length > MAX_DOC_BYTES;
88
+ }
89
+ function makePlan(markdown) {
90
+ if (tooLarge(markdown))
91
+ return { html: convertedHtml(markdown), ok: false, reason: 'too-large' };
92
+ const crlf = markdown.includes('\r');
93
+ // Every line ends in CRLF, or none does. A mix saves with LF endings; its blocks still keep their spelling.
94
+ if (crlf && (/\r(?!\n)/.test(markdown) || /(^|[^\r])\n/.test(markdown))) {
95
+ const lf = markdown.replace(/\r\n?/g, '\n');
96
+ return { html: sourcePlan(lf, false, parser.lexer(lf)).html, ok: false, reason: 'line-endings' };
97
+ }
98
+ const text = crlf ? markdown.replace(/\r\n/g, '\n') : markdown;
99
+ // Lexing is the costliest step on a long file: once, for both paths.
100
+ const tokens = parser.lexer(text);
101
+ // The plain save trims the file, ends it with one newline and reads front matter as a rule and a
102
+ // heading: a file it cannot give back skips the fast path.
103
+ const plain = !crlf && /^\S/.test(text) && /[^\n]\n$/.test(text) && !frontMatter(text);
104
+ if (plain) {
105
+ // The fast path: the editor already writes this file as it is. marked's renderer changes
106
+ // the tokens it renders (a loose task item takes its checkbox), so it renders a copy.
107
+ const html = convertedHtml(text, structuredClone(tokens));
108
+ if (saveDoc(throughSchema(html)).text === text)
109
+ return { html, ok: true };
110
+ }
111
+ return sourcePlan(text, crlf, tokens);
112
+ }
113
+ /**
114
+ * YAML front matter: `---` on the first line, a `key:` line under it, and a
115
+ * closing `---` or `...` line. (`---` above a paragraph is a rule, not front matter.)
116
+ */
117
+ function frontMatter(text) {
118
+ if (!text.startsWith('---\n') || !/^[A-Za-z_][\w-]*[ \t]*:/.test(text.slice(4)))
119
+ return null;
120
+ for (let at = 4; at < text.length;) {
121
+ const nl = text.indexOf('\n', at);
122
+ const end = nl === -1 ? text.length : nl;
123
+ if (/^(---|\.\.\.)[ \t]*$/.test(text.slice(at, end)))
124
+ return text.slice(0, end);
125
+ if (nl === -1)
126
+ return null;
127
+ at = nl + 1;
128
+ }
129
+ return null;
130
+ }
131
+ /** The file as top-level blocks and the whitespace around them: `gap₀ text₀ gap₁ text₁ … tail`. */
132
+ function splitUnits(text, tokens) {
133
+ const units = [];
134
+ let pending = '';
135
+ const front = frontMatter(text);
136
+ if (front)
137
+ units.push({ text: front, gap: '', token: null });
138
+ for (const token of front ? parser.lexer(text.slice(front.length)) : tokens) {
139
+ const lead = /^\n*/.exec(token.raw)?.[0] ?? '';
140
+ const body = token.raw.slice(lead.length).replace(/[ \t\n]+$/, '');
141
+ if (token.type === 'space' || !body) {
142
+ pending += token.raw;
143
+ continue;
144
+ }
145
+ const shown = token.type === 'def' ? false : token.type === 'html' ? DOC_HTML.test(body) : true;
146
+ units.push({ text: body, gap: pending + lead, token: shown ? token : null });
147
+ pending = token.raw.slice(lead.length + body.length);
148
+ }
149
+ return { units, tail: pending };
150
+ }
151
+ const standardGap = (index) => (index === 0 ? '' : '\n\n');
152
+ const STANDARD_END = '\n';
153
+ function sourcePlan(text, crlf, tokens) {
154
+ const { units, tail } = splitUnits(text, tokens);
155
+ if (units.map((u) => u.gap + u.text).join('') + tail !== text) {
156
+ // marked dropped or reordered text: nothing to anchor the blocks on.
157
+ return { html: convertedHtml(text, tokens), ok: false, reason: 'unstable' };
158
+ }
159
+ const readings = readUnits(units);
160
+ const needsAttribute = (i) => crlf || units[i].gap !== standardGap(i) || (i === units.length - 1 && tail !== STANDARD_END);
161
+ const shapes = units.map((unit, i) => {
162
+ const reading = readings[i];
163
+ if (!reading)
164
+ return 'raw';
165
+ // Several blocks (a paragraph the editor splits around an image) are kept together (`span`).
166
+ return reading.markdown.join('\n\n') === unit.text && (reading.markdown.length === 1 || !needsAttribute(i)) ? 'native' : 'kept';
167
+ });
168
+ // Where each unit ends in the file.
169
+ const ends = [];
170
+ units.reduce((offset, u) => {
171
+ ends.push(offset + u.gap.length + u.text.length);
172
+ return ends[ends.length - 1];
173
+ }, 0);
174
+ // A block the editor still rewrites in context opens raw, one at a time from the first difference;
175
+ // after three, every block from the difference on opens raw, so a file costs at most five passes.
176
+ for (let attempt = 0;; attempt++) {
177
+ const html = assemble(units, tail, crlf, readings, shapes);
178
+ const saved = saveDoc(throughSchema(html));
179
+ if (saved.text === text && saved.crlf === crlf)
180
+ return { html, ok: true };
181
+ const at = firstDifference(saved.text, text);
182
+ let index = ends.findIndex((end) => at < end);
183
+ if (index === -1)
184
+ index = units.length - 1;
185
+ while (index >= 0 && shapes[index] === 'raw')
186
+ index--;
187
+ if (index < 0 || attempt === 4)
188
+ return { html, ok: false, reason: 'unstable' };
189
+ for (let i = index; i < (attempt < 3 ? index + 1 : units.length); i++)
190
+ shapes[i] = 'raw';
191
+ }
192
+ }
193
+ function firstDifference(a, b) {
194
+ const n = Math.min(a.length, b.length);
195
+ for (let i = 0; i < n; i++)
196
+ if (a[i] !== b[i])
197
+ return i;
198
+ return n;
199
+ }
200
+ /**
201
+ * Each shown unit through marked and the editor's schema, in one pass: a
202
+ * marker paragraph before each unit separates what the editor makes of it.
203
+ */
204
+ function readUnits(units) {
205
+ const sections = renderUnits(units.map((u) => (u.token ? [u.token] : null)));
206
+ const readings = units.map((u, i) => (u.token ? { kinds: [], markdown: [], html: sections[i] } : null));
207
+ const opened = openSections(sections, units.map((u) => u.text));
208
+ opened.forEach((blocks, i) => {
209
+ const reading = readings[i];
210
+ for (const block of reading ? blocks : []) {
211
+ reading.kinds.push(block.kind);
212
+ reading.markdown.push(block.markdown);
213
+ }
214
+ });
215
+ return readings.map((r) => (r && r.markdown.length ? r : null));
216
+ }
217
+ /** Each unit's tokens as the HTML the editor opens (`''` for none): marked, soft breaks, media as blocks. */
218
+ function renderUnits(units) {
219
+ const doc = new DOMParser().parseFromString(units.map((tokens) => `<section>${tokens ? editorHtml(parser.parser(tokens)) : ''}</section>`).join(''), 'text/html');
220
+ markSoftBreaks(doc);
221
+ const sections = Array.from(doc.body.children);
222
+ sections.forEach(unwrapImageParagraph);
223
+ return sections.map((s) => s.innerHTML);
224
+ }
225
+ /**
226
+ * Sections of HTML through the editor's schema, in one pass: a marker
227
+ * paragraph before each separates the blocks the editor makes of it (empty
228
+ * blocks left out, as a save leaves them out). `texts`: the sources, which
229
+ * the marker must not occur in.
230
+ */
231
+ function openSections(sections, texts) {
232
+ let marker = 'kxunit';
233
+ while (texts.some((t) => t.includes(marker)))
234
+ marker += Math.random().toString(36).slice(2, 6);
235
+ const html = sections.map((s, i) => (s ? `<p>${marker}${i}</p>${s}` : '')).join('');
236
+ const opened = sections.map(() => []);
237
+ const isMarker = new RegExp(`^${marker}(\\d+)$`);
238
+ let current = null;
239
+ for (const block of savedBlocks(throughSchema(html)) ?? []) {
240
+ const index = block.kind === 'p' ? isMarker.exec(block.markdown)?.[1] : undefined;
241
+ if (index !== undefined)
242
+ current = opened[Number(index)] ?? null;
243
+ else if (current && block.markdown)
244
+ current.push(block);
245
+ }
246
+ return opened;
247
+ }
248
+ /**
249
+ * Whether a kept source holds text the editor would not show: a link
250
+ * reference definition, or a link with no text. A block of the file never
251
+ * holds one (a definition is a block of its own, opened raw).
252
+ */
253
+ function hidesText(tokens) {
254
+ let hidden = false;
255
+ parser.walkTokens(tokens, (token) => {
256
+ if (token.type === 'def' || (token.type === 'link' && !token.text.trim()))
257
+ hidden = true;
258
+ });
259
+ return hidden;
260
+ }
261
+ /**
262
+ * Which kept sources open as exactly the blocks shown (their HTML through the
263
+ * schema, `md` aside). A matching hash is cheap but proves nothing: a writer
264
+ * or a paste can set `md`. `links`: the file's link definitions.
265
+ */
266
+ function sourcesShown(candidates, links) {
267
+ if (!candidates.length)
268
+ return [];
269
+ const tokens = candidates.map(({ src }) => {
270
+ const lexer = new Lexer(parser.defaults);
271
+ Object.assign(lexer.tokens.links, links);
272
+ return lexer.lex(src);
273
+ });
274
+ const opened = openSections(renderUnits(tokens), candidates.map((c) => c.src));
275
+ return candidates.map(({ shown }, i) => !hidesText(tokens[i]) && opened[i].length === shown.length && opened[i].every((block, j) => block.html === shown[j]));
276
+ }
277
+ /** `<p><img></p>` → `<img>` (and a `<video>` line): media is a block in the editor, and its `md` must sit on it. */
278
+ function unwrapImageParagraph(section) {
279
+ const only = section.children.length === 1 ? section.firstElementChild : null;
280
+ const media = only?.nodeName === 'P' && only.children.length === 1 ? only.firstElementChild : null;
281
+ if (!only || !media || !['IMG', 'VIDEO'].includes(media.nodeName) || only.textContent?.trim())
282
+ return;
283
+ only.replaceWith(media);
284
+ }
285
+ /** The editor's HTML for the file: each unit as the editor shows it, with what it must keep in `data-md`. */
286
+ function assemble(units, tail, crlf, readings, shapes) {
287
+ const doc = new DOMParser().parseFromString('', 'text/html');
288
+ const kinds = units.map((_u, i) => (shapes[i] === 'raw' ? ['raw'] : (readings[i]?.kinds ?? ['raw'])));
289
+ const parts = units.map((unit, i) => {
290
+ const md = {};
291
+ if (unit.gap !== standardGap(i)) {
292
+ md.gap = unit.gap;
293
+ md.pair = `${i === 0 ? '^' : (kinds[i - 1].at(-1) ?? 'raw')}>${kinds[i][0]}`;
294
+ }
295
+ if (i === units.length - 1 && tail !== STANDARD_END)
296
+ md.end = tail;
297
+ if (crlf)
298
+ md.crlf = true;
299
+ const shape = shapes[i];
300
+ const value = (extra = {}) => writeMd({ ...md, ...extra });
301
+ if (shape === 'raw') {
302
+ const attribute = value();
303
+ return `<pre ${RAW_ATTRIBUTE}=""${attribute ? ` ${MD_ATTRIBUTE}="${escapeAttribute(attribute)}"` : ''}>${escapeHtml(unit.text)}</pre>`;
304
+ }
305
+ const reading = readings[i];
306
+ const { length } = reading.markdown;
307
+ const attribute = shape === 'kept'
308
+ ? value({ src: unit.text, norm: hashText(reading.markdown.join('\n\n')), ...(length > 1 ? { span: length } : {}) })
309
+ : value();
310
+ if (!attribute)
311
+ return reading.html;
312
+ const holder = doc.createElement('div');
313
+ holder.innerHTML = reading.html;
314
+ holder.firstElementChild?.setAttribute(MD_ATTRIBUTE, attribute);
315
+ return holder.innerHTML;
316
+ });
317
+ if (!units.length && (tail !== STANDARD_END || crlf)) {
318
+ // A file of whitespace alone: an empty paragraph holds its end.
319
+ const attribute = writeMd({ ...(tail !== STANDARD_END ? { end: tail } : {}), ...(crlf ? { crlf: true } : {}) });
320
+ return `<p ${MD_ATTRIBUTE}="${escapeAttribute(attribute ?? '')}"></p>`;
321
+ }
322
+ return parts.join('');
36
323
  }
324
+ const escapeAttribute = (text) => escapeHtml(text).replace(/"/g, '&quot;');
325
+ /* ------------------------------------------------------------------------ */
326
+ /* The editor's schema, without an editor */
327
+ /* ------------------------------------------------------------------------ */
328
+ let schema = null;
329
+ const docSchema = () => (schema ??= getSchema(docExtensions({ editable: true, placeholder: () => '' })));
330
+ /** TipTap's `elementFromString`: it drops whitespace-only text nodes of a newline (and two spaces). */
331
+ function removeWhitespaces(node) {
332
+ for (let i = node.childNodes.length - 1; i >= 0; i--) {
333
+ const child = node.childNodes[i];
334
+ if (child.nodeType === 3 && child.nodeValue && /^(\n\s\s|\n)$/.test(child.nodeValue))
335
+ node.removeChild(child);
336
+ else if (child.nodeType === 1)
337
+ removeWhitespaces(child);
338
+ }
339
+ }
340
+ /** HTML → the editor's document → `editor.getHTML()`, as TipTap does on load and on save. */
341
+ function throughSchema(html) {
342
+ const dom = new DOMParser().parseFromString(`<body>${html}</body>`, 'text/html');
343
+ removeWhitespaces(dom.body);
344
+ const node = ProseMirrorParser.fromSchema(docSchema()).parse(dom.body);
345
+ const fragment = DOMSerializer.fromSchema(docSchema()).serializeFragment(node.content, { document: dom });
346
+ const container = dom.createElement('div');
347
+ container.appendChild(fragment);
348
+ return container.innerHTML;
349
+ }
350
+ /* ------------------------------------------------------------------------ */
351
+ /* Soft breaks */
352
+ /* ------------------------------------------------------------------------ */
37
353
  const TEXT_BLOCK = 'p, li, h1, h2, h3, h4, h5, h6, td, th';
38
354
  const BLOCK_TAGS = new Set(['UL', 'OL', 'P', 'PRE', 'BLOCKQUOTE', 'TABLE', 'DIV', 'HR', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6']);
39
355
  const CONTAINER_TAGS = new Set([...BLOCK_TAGS, 'LI', 'THEAD', 'TBODY', 'TR']);
40
356
  /** Each newline inside a text block's text → `<span data-soft-break> </span>`. */
41
- function markSoftBreaks(html) {
42
- const doc = new DOMParser().parseFromString(html, 'text/html');
357
+ function markSoftBreaks(doc) {
43
358
  const walker = doc.createTreeWalker(doc.body, 4 /* NodeFilter.SHOW_TEXT */);
44
359
  const texts = [];
45
360
  for (let node = walker.nextNode(); node; node = walker.nextNode())
@@ -72,14 +387,17 @@ function markSoftBreaks(html) {
72
387
  });
73
388
  text.replaceWith(...pieces);
74
389
  }
75
- return doc.body.innerHTML;
76
390
  }
391
+ /* ------------------------------------------------------------------------ */
392
+ /* HTML → Markdown */
393
+ /* ------------------------------------------------------------------------ */
77
394
  let service = null;
78
395
  function turndown() {
79
396
  if (service)
80
397
  return service;
81
398
  const td = new TurndownService({
82
399
  headingStyle: 'atx',
400
+ hr: '---',
83
401
  bulletListMarker: '-',
84
402
  codeBlockStyle: 'fenced',
85
403
  emDelimiter: '*',
@@ -92,11 +410,26 @@ function turndown() {
92
410
  });
93
411
  tables(td);
94
412
  strikethrough(td);
413
+ // GFM's own strikethrough (`~~`), not the plugin's single tilde.
414
+ td.addRule('strikethroughGfm', {
415
+ filter: (node) => ['DEL', 'S', 'STRIKE'].includes(node.nodeName),
416
+ replacement: (content) => `~~${content}~~`,
417
+ });
418
+ // Markdown has no underline: the editor's (⌘U) stays an HTML tag, which opens as underline again.
419
+ td.addRule('underline', { filter: ['u'], replacement: (content) => (content.trim() ? `<u>${content}</u>` : content) });
420
+ // An empty line inside a quote is a bare `>`.
421
+ td.addRule('blockquote', {
422
+ filter: 'blockquote',
423
+ replacement: (content) => `\n\n${content
424
+ .replace(/^\n+|\n+$/g, '')
425
+ .replace(/^/gm, '> ')
426
+ .replace(/^> $/gm, '>')}\n\n`,
427
+ });
95
428
  td.addRule('taskItem', {
96
429
  filter: (node) => node.nodeName === 'LI' && node.getAttribute('data-type') === 'taskItem',
97
430
  replacement: (content, node) => `- [${node.getAttribute('data-checked') === 'true' ? 'x' : ' '}] ${content.trim().replace(/\n+/g, ' ')}\n`,
98
431
  });
99
- // Tight items (`- a`, `1. a`), nested lines indented to the marker's width.
432
+ // Tight items (`- a`, `1. a`), nested lines indented to the marker's width; an empty line stays empty.
100
433
  // Added after taskItem, so it would win (turndown tries later rules first): skip task items.
101
434
  td.addRule('listItem', {
102
435
  filter: (node) => node.nodeName === 'LI' && node.getAttribute('data-type') !== 'taskItem',
@@ -105,7 +438,7 @@ function turndown() {
105
438
  const index = parent ? Array.prototype.indexOf.call(parent.children, node) : 0;
106
439
  const start = Number(parent?.getAttribute('start') ?? 1);
107
440
  const prefix = parent?.nodeName === 'OL' ? `${start + index}. ` : '- ';
108
- const body = content.replace(/^\n+/, '').replace(/\n+$/, '').replace(/\n/g, `\n${' '.repeat(prefix.length)}`);
441
+ const body = content.replace(/^\n+/, '').replace(/\n+$/, '').replace(/\n(?=[^\n])/g, `\n${' '.repeat(prefix.length)}`);
109
442
  return `${prefix}${body}\n`;
110
443
  },
111
444
  });
@@ -120,11 +453,21 @@ function turndown() {
120
453
  filter: (node) => node.nodeName === 'DIV' && node.classList.contains('kx-embed'),
121
454
  replacement: (_content, node) => `\n\n${node.outerHTML.replace(/\s*\n\s*/g, ' ')}\n\n`,
122
455
  });
456
+ // A raw block moved into a list or a quote: its text, as written.
457
+ td.addRule('rawMarkdown', {
458
+ filter: (node) => node.nodeName === 'PRE' && node.hasAttribute(RAW_ATTRIBUTE),
459
+ replacement: (_content, node) => `\n\n${node.textContent ?? ''}\n\n`,
460
+ });
123
461
  service = td;
124
462
  return td;
125
463
  }
126
- export function htmlToMarkdown(html) {
464
+ /** The editor's HTML, cleaned for turndown. */
465
+ function cleanedBody(html) {
127
466
  const doc = new DOMParser().parseFromString(html, 'text/html');
467
+ clean(doc);
468
+ return doc.body;
469
+ }
470
+ function clean(doc) {
128
471
  // A table cell holds one line in Markdown: unwrap the editor's paragraphs.
129
472
  doc.querySelectorAll('td > p, th > p').forEach((p) => p.replaceWith(...Array.from(p.childNodes)));
130
473
  // A list item with one paragraph is one line: unwrap it, so the list stays tight.
@@ -136,5 +479,99 @@ export function htmlToMarkdown(html) {
136
479
  doc.querySelectorAll('span[data-soft-break]').forEach((s) => {
137
480
  s.textContent = '';
138
481
  });
139
- return `${turndown().turndown(doc.body.innerHTML).trim()}\n`;
482
+ }
483
+ /** Each top-level block of the editor's HTML. */
484
+ function savedBlocks(html) {
485
+ const doc = new DOMParser().parseFromString(html, 'text/html');
486
+ const { body } = doc;
487
+ const shown = new Map();
488
+ for (const el of Array.from(body.children)) {
489
+ const copy = el.cloneNode(true);
490
+ copy.removeAttribute(MD_ATTRIBUTE);
491
+ shown.set(el, copy.outerHTML);
492
+ }
493
+ clean(doc);
494
+ // Text outside a block (not from the editor) has no block to belong to.
495
+ if (Array.from(body.childNodes).some((n) => n.nodeType === 3 && n.textContent?.trim()))
496
+ return null;
497
+ const elements = Array.from(body.children);
498
+ const blocks = elements.map((el) => ({
499
+ kind: blockKind(el),
500
+ md: readMd(el),
501
+ raw: el.hasAttribute(RAW_ATTRIBUTE),
502
+ markdown: '',
503
+ html: shown.get(el) ?? '',
504
+ }));
505
+ // `md` never reaches the file (a video and a link card save as their HTML).
506
+ body.querySelectorAll(`[${MD_ATTRIBUTE}]`).forEach((el) => el.removeAttribute(MD_ATTRIBUTE));
507
+ elements.forEach((el, i) => {
508
+ blocks[i].markdown = blocks[i].raw ? (el.textContent ?? '') : turndown().turndown(el.outerHTML);
509
+ });
510
+ return blocks;
511
+ }
512
+ /** The editor's HTML → the file: `text` with LF line endings, and whether the file uses CRLF. */
513
+ function saveDoc(html) {
514
+ if (!html.includes(MD_ATTRIBUTE) && !html.includes(RAW_ATTRIBUTE))
515
+ return { text: plainMarkdown(html), crlf: false };
516
+ const blocks = savedBlocks(html);
517
+ if (!blocks)
518
+ return { text: plainMarkdown(html), crlf: false };
519
+ // An empty block (the editor's trailing paragraph) saves as nothing, as it always has.
520
+ const shown = blocks.filter((b) => b.markdown);
521
+ const kept = keptSources(shown);
522
+ let text = '';
523
+ let previous = '^';
524
+ let last = null;
525
+ for (let i = 0; i < shown.length;) {
526
+ const { md, kind } = shown[i];
527
+ // The file's spelling of a block nobody edited, proven to open as the blocks shown.
528
+ const count = kept.get(i) ?? 1;
529
+ const markdown = kept.has(i) ? md?.src : shown[i].markdown;
530
+ const gap = md?.gap !== undefined && LAYOUT_WHITESPACE.test(md.gap) && md.pair === `${previous}>${kind}` ? md.gap : i ? '\n\n' : '';
531
+ text += gap + markdown;
532
+ previous = shown[i + count - 1].kind;
533
+ last = count > 1 ? md : shown[i].md;
534
+ i += count;
535
+ }
536
+ const end = (shown.length ? last : blocks[0]?.md)?.end;
537
+ return { text: text + (end !== undefined && LAYOUT_WHITESPACE.test(end) ? end : STANDARD_END), crlf: blocks.some((b) => b.md?.crlf) };
538
+ }
539
+ /**
540
+ * The shown blocks whose kept source the file takes, by index → the number of
541
+ * blocks it covers: the editor still writes `norm` for them (nobody edited
542
+ * them), and the source opens as exactly these blocks (`sourcesShown`).
543
+ */
544
+ function keptSources(shown) {
545
+ const candidates = [];
546
+ shown.forEach((block, index) => {
547
+ const { md } = block;
548
+ if (block.raw || typeof md?.src !== 'string')
549
+ return;
550
+ const span = Math.max(1, Number(md.span) || 1);
551
+ const group = shown.slice(index, index + span);
552
+ if (group.length === span && md.norm === hashText(group.map((b) => b.markdown).join('\n\n')))
553
+ candidates.push({ index, span, src: md.src, shown: group.map((b) => b.html) });
554
+ });
555
+ if (!candidates.length)
556
+ return new Map();
557
+ // The file's link definitions (each a raw block), so a kept `[text][ref]` opens as its link.
558
+ const definitions = shown.filter((b) => b.raw && /^ {0,3}\[[^\]]+\]:/.test(b.markdown)).map((b) => b.markdown);
559
+ const links = definitions.length ? parser.lexer(definitions.join('\n\n')).links : {};
560
+ const proven = sourcesShown(candidates, links);
561
+ return new Map(candidates.filter((_c, i) => proven[i]).map((c) => [c.index, c.span]));
562
+ }
563
+ /** A document with nothing kept: one turndown pass, as the editor has always saved. */
564
+ function plainMarkdown(html) {
565
+ const body = cleanedBody(html);
566
+ // A top-level image or video is a block: one blank line apart, like every block.
567
+ body.querySelectorAll(':scope > img, :scope > video').forEach((el) => {
568
+ const p = body.ownerDocument.createElement('p');
569
+ el.replaceWith(p);
570
+ p.appendChild(el);
571
+ });
572
+ return `${turndown().turndown(body.innerHTML).trim()}\n`;
573
+ }
574
+ export function htmlToMarkdown(html) {
575
+ const { text, crlf } = saveDoc(html);
576
+ return crlf ? text.replace(/\n/g, '\r\n') : text;
140
577
  }
@@ -1,6 +1,6 @@
1
1
  import { type MarkdownTrust, type MarkdownVariant } from './markdown-policy.js';
2
2
  import React from 'react';
3
- export declare function MarkdownLink({ href, children }: {
3
+ export declare function MarkdownLink({ href, children, }: {
4
4
  href?: string;
5
5
  children?: React.ReactNode;
6
6
  }): React.JSX.Element;