@cosmicdrift/kumiko-samples 0.388.0 → 0.390.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 (385) hide show
  1. package/package.json +1 -1
  2. package/packages/bundled-features/package.json +25 -13
  3. package/packages/bundled-features/src/agent-tools/changes.json +6 -0
  4. package/packages/bundled-features/src/agent-tools/index.ts +1 -1
  5. package/packages/bundled-features/src/agent-tools/tool-dispatch.ts +42 -26
  6. package/packages/bundled-features/src/audit/feature.ts +2 -1
  7. package/packages/bundled-features/src/auth-email-password/auth-user-row.ts +1 -1
  8. package/packages/bundled-features/src/auth-email-password/bootstrap.ts +13 -1
  9. package/packages/bundled-features/src/auth-email-password/changes.json +18 -0
  10. package/packages/bundled-features/src/auth-email-password/feature.ts +2 -2
  11. package/packages/bundled-features/src/auth-email-password/handlers/change-password.write.ts +7 -7
  12. package/packages/bundled-features/src/auth-email-password/handlers/confirm-account-unlock.write.ts +3 -3
  13. package/packages/bundled-features/src/auth-email-password/handlers/confirm-token-flow.ts +5 -5
  14. package/packages/bundled-features/src/auth-email-password/handlers/invite-accept-with-login.write.ts +9 -7
  15. package/packages/bundled-features/src/auth-email-password/handlers/invite-accept.write.ts +11 -7
  16. package/packages/bundled-features/src/auth-email-password/handlers/invite-create.write.ts +4 -4
  17. package/packages/bundled-features/src/auth-email-password/handlers/invite-info.query.ts +2 -2
  18. package/packages/bundled-features/src/auth-email-password/handlers/invite-signup-complete.write.ts +9 -7
  19. package/packages/bundled-features/src/auth-email-password/handlers/login.write.ts +23 -16
  20. package/packages/bundled-features/src/auth-email-password/handlers/request-account-unlock.write.ts +1 -0
  21. package/packages/bundled-features/src/auth-email-password/handlers/request-email-verification.write.ts +1 -0
  22. package/packages/bundled-features/src/auth-email-password/handlers/request-password-reset.write.ts +1 -0
  23. package/packages/bundled-features/src/auth-email-password/handlers/reset-password.write.ts +3 -2
  24. package/packages/bundled-features/src/auth-email-password/handlers/signup-confirm.write.ts +12 -12
  25. package/packages/bundled-features/src/auth-email-password/handlers/signup-request.write.ts +16 -8
  26. package/packages/bundled-features/src/auth-email-password/handlers/switch-tenant-mfa-gate.write.ts +4 -2
  27. package/packages/bundled-features/src/auth-email-password/handlers/token-request-handler.ts +10 -2
  28. package/packages/bundled-features/src/auth-email-password/handlers/verify-email.write.ts +3 -2
  29. package/packages/bundled-features/src/auth-email-password/magic-link-mail.ts +16 -3
  30. package/packages/bundled-features/src/auth-email-password/seeding.ts +14 -9
  31. package/packages/bundled-features/src/auth-email-password/signup-activation.ts +2 -0
  32. package/packages/bundled-features/src/auth-email-password/web/auth-client.ts +8 -2
  33. package/packages/bundled-features/src/auth-email-password/web/auth-redirect.ts +23 -21
  34. package/packages/bundled-features/src/auth-email-password/web/default-auth-pages-gate.tsx +6 -3
  35. package/packages/bundled-features/src/auth-email-password/web/forgot-password-screen.tsx +11 -1
  36. package/packages/bundled-features/src/auth-email-password/web/index.ts +5 -0
  37. package/packages/bundled-features/src/auth-email-password/web/login-screen.tsx +16 -5
  38. package/packages/bundled-features/src/auth-email-password/web/reset-password-screen.tsx +7 -1
  39. package/packages/bundled-features/src/auth-email-password/web/return-path.ts +35 -0
  40. package/packages/bundled-features/src/auth-email-password/web/session.tsx +6 -1
  41. package/packages/bundled-features/src/auth-email-password/web/signup-complete-screen.tsx +11 -3
  42. package/packages/bundled-features/src/auth-email-password/web/signup-screen.tsx +12 -2
  43. package/packages/bundled-features/src/auth-foundation/feature.ts +13 -4
  44. package/packages/bundled-features/src/auth-mfa/changes.json +6 -0
  45. package/packages/bundled-features/src/auth-mfa/config.ts +3 -7
  46. package/packages/bundled-features/src/auth-mfa/handlers/disable.write.ts +5 -5
  47. package/packages/bundled-features/src/auth-mfa/handlers/enable-confirm-preauth.write.ts +24 -14
  48. package/packages/bundled-features/src/auth-mfa/handlers/enable-confirm.write.ts +9 -3
  49. package/packages/bundled-features/src/auth-mfa/handlers/enable-start-preauth.write.ts +6 -1
  50. package/packages/bundled-features/src/auth-mfa/handlers/enable-start.write.ts +3 -1
  51. package/packages/bundled-features/src/auth-mfa/handlers/reencrypt.job.ts +14 -9
  52. package/packages/bundled-features/src/auth-mfa/handlers/regenerate-recovery.write.ts +5 -4
  53. package/packages/bundled-features/src/auth-mfa/handlers/verify.write.ts +25 -14
  54. package/packages/bundled-features/src/auth-mfa/mfa-code-verifier.ts +10 -4
  55. package/packages/bundled-features/src/auth-mfa/mfa-status-checker.ts +17 -8
  56. package/packages/bundled-features/src/auth-mfa/verify-factor.ts +1 -1
  57. package/packages/bundled-features/src/billing-foundation/billing-info-query.ts +2 -2
  58. package/packages/bundled-features/src/billing-foundation/changes.json +6 -0
  59. package/packages/bundled-features/src/billing-foundation/consumer-protection/consent-gate.ts +1 -1
  60. package/packages/bundled-features/src/billing-foundation/consumer-protection/issue-confirmation.ts +5 -5
  61. package/packages/bundled-features/src/billing-foundation/consumer-protection/register-consent.ts +10 -7
  62. package/packages/bundled-features/src/billing-foundation/consumer-protection/register-termination.ts +15 -12
  63. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-open-cancels.ts +22 -0
  64. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-provider-lock.ts +4 -0
  65. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-receipt-limit.ts +4 -4
  66. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-record.ts +17 -58
  67. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-request.ts +10 -8
  68. package/packages/bundled-features/src/billing-foundation/consumer-protection/termination-revoke.ts +18 -15
  69. package/packages/bundled-features/src/billing-foundation/events.ts +1 -1
  70. package/packages/bundled-features/src/billing-foundation/feature.ts +8 -3
  71. package/packages/bundled-features/src/billing-foundation/get-subscription-for-tenant.ts +1 -1
  72. package/packages/bundled-features/src/billing-foundation/handlers/process-event.write.ts +5 -5
  73. package/packages/bundled-features/src/billing-foundation/handlers/process-payment-event.write.ts +3 -3
  74. package/packages/bundled-features/src/billing-foundation/plan-catalog.ts +2 -2
  75. package/packages/bundled-features/src/billing-foundation/projection.ts +1 -1
  76. package/packages/bundled-features/src/billing-foundation/types.ts +1 -1
  77. package/packages/bundled-features/src/cap-counter/aggregate-id.ts +1 -1
  78. package/packages/bundled-features/src/cap-counter/book-cap-usage.ts +5 -4
  79. package/packages/bundled-features/src/cap-counter/cap-reservation.ts +21 -8
  80. package/packages/bundled-features/src/cap-counter/changes.json +12 -0
  81. package/packages/bundled-features/src/cap-counter/constants.ts +1 -1
  82. package/packages/bundled-features/src/cap-counter/feature.ts +3 -2
  83. package/packages/bundled-features/src/cap-counter/handlers/increment-rolling.write.ts +1 -1
  84. package/packages/bundled-features/src/cap-counter/reservation-chain.ts +1 -1
  85. package/packages/bundled-features/src/cap-counter/with-cap-enforcement.ts +4 -4
  86. package/packages/bundled-features/src/cap-overview/feature.ts +1 -0
  87. package/packages/bundled-features/src/cap-overview/handlers/caps-usage.query.ts +1 -1
  88. package/packages/bundled-features/src/cap-overview/handlers/tenant-caps-list.query.ts +1 -1
  89. package/packages/bundled-features/src/compliance-profiles/seeding.ts +12 -7
  90. package/packages/bundled-features/src/config/changes.json +6 -0
  91. package/packages/bundled-features/src/config/feature.ts +6 -6
  92. package/packages/bundled-features/src/config/handlers/cascade.query.ts +1 -1
  93. package/packages/bundled-features/src/config/handlers/readiness.query.ts +1 -1
  94. package/packages/bundled-features/src/config/handlers/reencrypt.job.ts +23 -13
  95. package/packages/bundled-features/src/config/handlers/reset.write.ts +3 -3
  96. package/packages/bundled-features/src/config/handlers/selected-extensions.query.ts +1 -1
  97. package/packages/bundled-features/src/config/handlers/set.write.ts +22 -5
  98. package/packages/bundled-features/src/config/handlers/values.query.ts +1 -1
  99. package/packages/bundled-features/src/crypto-shredding/changes.json +12 -0
  100. package/packages/bundled-features/src/crypto-shredding/handlers/forget-subject.write.ts +9 -9
  101. package/packages/bundled-features/src/crypto-shredding/resolve-file-bytes-deleter.ts +3 -3
  102. package/packages/bundled-features/src/custom-fields/changes.json +6 -0
  103. package/packages/bundled-features/src/custom-fields/handlers/clear-custom-field.write.ts +1 -1
  104. package/packages/bundled-features/src/custom-fields/handlers/delete-system-field.write.ts +1 -1
  105. package/packages/bundled-features/src/custom-fields/handlers/delete-tenant-field.write.ts +1 -1
  106. package/packages/bundled-features/src/custom-fields/handlers/set-custom-field.write.ts +1 -1
  107. package/packages/bundled-features/src/custom-fields/index.ts +4 -0
  108. package/packages/bundled-features/src/custom-fields/lib/parse-serialized-field.ts +1 -1
  109. package/packages/bundled-features/src/data-retention/feature.ts +1 -1
  110. package/packages/bundled-features/src/data-retention/run-retention-cleanup.ts +12 -2
  111. package/packages/bundled-features/src/delivery/attempt-log.ts +1 -1
  112. package/packages/bundled-features/src/delivery/changes.json +12 -0
  113. package/packages/bundled-features/src/delivery/delivery-service.ts +6 -5
  114. package/packages/bundled-features/src/delivery/feature.ts +3 -2
  115. package/packages/bundled-features/src/delivery/index.ts +5 -0
  116. package/packages/bundled-features/src/delivery/jobs.ts +11 -11
  117. package/packages/bundled-features/src/delivery/system-channel-context.ts +33 -0
  118. package/packages/bundled-features/src/delivery/testing.ts +1 -1
  119. package/packages/bundled-features/src/document-ingest-foundation/append-missing-extract-event.ts +84 -0
  120. package/packages/bundled-features/src/document-ingest-foundation/changes.json +6 -0
  121. package/packages/bundled-features/src/document-ingest-foundation/events.ts +16 -1
  122. package/packages/bundled-features/src/document-ingest-foundation/index.ts +11 -0
  123. package/packages/bundled-features/src/feature-toggles/feature.ts +1 -0
  124. package/packages/bundled-features/src/feature-toggles/handlers/registered.query.ts +1 -1
  125. package/packages/bundled-features/src/feature-toggles/handlers/set.write.ts +1 -1
  126. package/packages/bundled-features/src/feature-toggles/toggle-sync-signal.ts +1 -1
  127. package/packages/bundled-features/src/file-derivatives/feature.ts +2 -2
  128. package/packages/bundled-features/src/file-derivatives/handlers/public-variant-by-file-ref.query.ts +5 -1
  129. package/packages/bundled-features/src/file-derivatives/handlers/public-variant.query.ts +7 -5
  130. package/packages/bundled-features/src/file-foundation/feature.ts +1 -1
  131. package/packages/bundled-features/src/file-foundation/read-file-ref-content.ts +7 -5
  132. package/packages/bundled-features/src/file-provider-s3/feature.ts +4 -1
  133. package/packages/bundled-features/src/files-tenant-data/handlers/sweep-orphaned-derivatives.job.ts +8 -8
  134. package/packages/bundled-features/src/form-draft/feature.ts +1 -1
  135. package/packages/bundled-features/src/form-draft/handlers/cleanup.job.ts +22 -12
  136. package/packages/bundled-features/src/form-draft/handlers/discard.write.ts +3 -3
  137. package/packages/bundled-features/src/form-draft/handlers/get.query.ts +1 -1
  138. package/packages/bundled-features/src/foundation-shared/config-helpers.ts +1 -1
  139. package/packages/bundled-features/src/host-routing/changes.json +6 -0
  140. package/packages/bundled-features/src/host-routing/validate-options.ts +5 -0
  141. package/packages/bundled-features/src/inbound-mail-foundation/events.ts +1 -1
  142. package/packages/bundled-features/src/inbound-mail-foundation/feature.ts +2 -1
  143. package/packages/bundled-features/src/inbound-mail-foundation/handlers/account-state.ts +2 -2
  144. package/packages/bundled-features/src/inbound-mail-foundation/handlers/connect-account.write.ts +1 -1
  145. package/packages/bundled-features/src/inbound-mail-foundation/handlers/disconnect-account.write.ts +1 -1
  146. package/packages/bundled-features/src/inbound-mail-foundation/handlers/ingest-message.write.ts +10 -10
  147. package/packages/bundled-features/src/inbound-mail-foundation/handlers/update-account.write.ts +1 -1
  148. package/packages/bundled-features/src/inbound-mail-foundation/projection.ts +1 -1
  149. package/packages/bundled-features/src/inbound-mail-foundation/watch-supervisor.ts +1 -1
  150. package/packages/bundled-features/src/inbound-provider-imap/feature.ts +4 -1
  151. package/packages/bundled-features/src/jobs/changes.json +6 -0
  152. package/packages/bundled-features/src/jobs/events.ts +1 -1
  153. package/packages/bundled-features/src/jobs/feature.ts +1 -0
  154. package/packages/bundled-features/src/jobs/handlers/consumer.write.ts +7 -4
  155. package/packages/bundled-features/src/jobs/handlers/projection-rebuild.job.ts +1 -1
  156. package/packages/bundled-features/src/jobs/handlers/reindex-entity.job.ts +11 -5
  157. package/packages/bundled-features/src/jobs/handlers/retention-cleanup.job.ts +1 -1
  158. package/packages/bundled-features/src/jobs/handlers/retry.write.ts +1 -1
  159. package/packages/bundled-features/src/jobs/handlers/stale-run-sweep.job.ts +1 -1
  160. package/packages/bundled-features/src/jobs/handlers/trigger.write.ts +2 -2
  161. package/packages/bundled-features/src/jobs/job-run-logger.ts +139 -90
  162. package/packages/bundled-features/src/ledger/web/index.ts +1 -1
  163. package/packages/bundled-features/src/legal-pages/README.md +1 -1
  164. package/packages/bundled-features/src/legal-pages/lib/boot-check.ts +12 -8
  165. package/packages/bundled-features/src/legal-pages/seed.ts +5 -2
  166. package/packages/bundled-features/src/mail-foundation/feature.ts +2 -2
  167. package/packages/bundled-features/src/mail-transport-smtp/changes.json +12 -0
  168. package/packages/bundled-features/src/mail-transport-smtp/config-keys.ts +1 -1
  169. package/packages/bundled-features/src/mail-transport-smtp/feature.ts +13 -12
  170. package/packages/bundled-features/src/managed-pages/changes.json +6 -0
  171. package/packages/bundled-features/src/managed-pages/constants.ts +1 -0
  172. package/packages/bundled-features/src/managed-pages/feature.ts +3 -1
  173. package/packages/bundled-features/src/managed-pages/index.ts +1 -0
  174. package/packages/bundled-features/src/managed-pages/seeding.ts +13 -8
  175. package/packages/bundled-features/src/notes-history/handlers/add-note.write.ts +2 -2
  176. package/packages/bundled-features/src/personal-access-tokens/feature.ts +2 -1
  177. package/packages/bundled-features/src/personal-access-tokens/handlers/create.write.ts +2 -2
  178. package/packages/bundled-features/src/personal-access-tokens/handlers/revoke.write.ts +1 -1
  179. package/packages/bundled-features/src/rate-limiting/handlers/status.query.ts +2 -2
  180. package/packages/bundled-features/src/readiness/handlers/status.query.ts +4 -1
  181. package/packages/bundled-features/src/renderer-foundation/api.ts +3 -3
  182. package/packages/bundled-features/src/secrets/announce-secret-change.ts +4 -4
  183. package/packages/bundled-features/src/secrets/changes.json +6 -0
  184. package/packages/bundled-features/src/secrets/feature.ts +9 -9
  185. package/packages/bundled-features/src/secrets/handlers/delete.write.ts +4 -3
  186. package/packages/bundled-features/src/secrets/handlers/rotate.job.ts +13 -8
  187. package/packages/bundled-features/src/secrets/handlers/set.write.ts +4 -3
  188. package/packages/bundled-features/src/secrets/secrets-context.ts +16 -6
  189. package/packages/bundled-features/src/secrets/write-gate.ts +10 -3
  190. package/packages/bundled-features/src/seo/feature.ts +1 -1
  191. package/packages/bundled-features/src/sessions/changes.json +19 -0
  192. package/packages/bundled-features/src/sessions/feature.ts +2 -1
  193. package/packages/bundled-features/src/sessions/handlers/cleanup.job.ts +2 -2
  194. package/packages/bundled-features/src/sessions/handlers/detail.query.ts +5 -2
  195. package/packages/bundled-features/src/sessions/handlers/list.query.ts +5 -2
  196. package/packages/bundled-features/src/sessions/handlers/mine.query.ts +5 -2
  197. package/packages/bundled-features/src/sessions/handlers/revoke-all-for-user.write.ts +3 -3
  198. package/packages/bundled-features/src/sessions/handlers/revoke-all-others.write.ts +1 -1
  199. package/packages/bundled-features/src/sessions/handlers/revoke.write.ts +1 -1
  200. package/packages/bundled-features/src/sessions/index.ts +1 -1
  201. package/packages/bundled-features/src/sessions/screens.ts +8 -4
  202. package/packages/bundled-features/src/sessions/session-callbacks.ts +1 -9
  203. package/packages/bundled-features/src/sessions/session-revoked-event.ts +1 -1
  204. package/packages/bundled-features/src/sessions/web/session-device-cell.tsx +10 -12
  205. package/packages/bundled-features/src/sessions/web/user-agent.ts +12 -0
  206. package/packages/bundled-features/src/shared/index.ts +15 -0
  207. package/packages/bundled-features/src/shared/purge-files-reaching-subject.ts +36 -4
  208. package/packages/bundled-features/src/shared/require-for-tenant.ts +7 -5
  209. package/packages/bundled-features/src/shared/run-in-sub-transaction.ts +5 -5
  210. package/packages/bundled-features/src/shared/stream-tenant-backfill.ts +201 -0
  211. package/packages/bundled-features/src/shared/stream-tenant-derived-state.ts +107 -0
  212. package/packages/bundled-features/src/step-dispatcher/changes.json +6 -0
  213. package/packages/bundled-features/src/step-dispatcher/deliver-dispatch-request.ts +17 -3
  214. package/packages/bundled-features/src/step-dispatcher/feature.ts +1 -1
  215. package/packages/bundled-features/src/step-dispatcher/mail-runner.ts +2 -1
  216. package/packages/bundled-features/src/subscription-dodo/plugin-methods.ts +1 -1
  217. package/packages/bundled-features/src/subscription-dodo/runtime.ts +7 -7
  218. package/packages/bundled-features/src/subscription-stripe/plugin-methods.ts +5 -3
  219. package/packages/bundled-features/src/subscription-stripe/runtime.ts +7 -7
  220. package/packages/bundled-features/src/tags/feature.ts +1 -0
  221. package/packages/bundled-features/src/template-resolver/api.ts +3 -3
  222. package/packages/bundled-features/src/template-resolver/changes.json +54 -0
  223. package/packages/bundled-features/src/template-resolver/document-ops.ts +20 -1
  224. package/packages/bundled-features/src/template-resolver/feature.ts +2 -2
  225. package/packages/bundled-features/src/template-resolver/handlers/bundle-import.ts +5 -4
  226. package/packages/bundled-features/src/template-resolver/handlers/copy-locale.write.ts +2 -2
  227. package/packages/bundled-features/src/template-resolver/handlers/export-bundle.query.ts +1 -1
  228. package/packages/bundled-features/src/template-resolver/handlers/layout-source.query.ts +36 -11
  229. package/packages/bundled-features/src/template-resolver/handlers/overview.query.ts +32 -7
  230. package/packages/bundled-features/src/template-resolver/handlers/patch-draft.write.ts +1 -1
  231. package/packages/bundled-features/src/template-resolver/handlers/send-test-shared.ts +1 -1
  232. package/packages/bundled-features/src/template-resolver/handlers/send-test-status.query.ts +22 -19
  233. package/packages/bundled-features/src/template-resolver/handlers/send-test.write.ts +2 -2
  234. package/packages/bundled-features/src/template-resolver/handlers/tenant-override-selection.ts +6 -2
  235. package/packages/bundled-features/src/template-resolver/handlers/tenant-overrides.query.ts +4 -2
  236. package/packages/bundled-features/src/template-resolver/handlers/usage.query.ts +1 -1
  237. package/packages/bundled-features/src/template-resolver/seeding.ts +22 -5
  238. package/packages/bundled-features/src/template-resolver/store-template-resource.ts +68 -19
  239. package/packages/bundled-features/src/template-resolver/template-resources.ts +4 -4
  240. package/packages/bundled-features/src/template-resolver/testing.ts +2 -2
  241. package/packages/bundled-features/src/template-resolver/web/document-insert-fields.tsx +222 -0
  242. package/packages/bundled-features/src/template-resolver/web/document-insert-model.ts +164 -0
  243. package/packages/bundled-features/src/template-resolver/web/document-insert-panel.tsx +115 -0
  244. package/packages/bundled-features/src/template-resolver/web/document-tiptap-bubble.tsx +177 -0
  245. package/packages/bundled-features/src/template-resolver/web/document-tiptap-content.tsx +38 -0
  246. package/packages/bundled-features/src/template-resolver/web/document-tiptap-context.ts +119 -0
  247. package/packages/bundled-features/src/template-resolver/web/document-tiptap-editor.tsx +51 -1098
  248. package/packages/bundled-features/src/template-resolver/web/document-tiptap-helpers.ts +161 -0
  249. package/packages/bundled-features/src/template-resolver/web/document-tiptap-layout.tsx +83 -0
  250. package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar-groups.tsx +153 -0
  251. package/packages/bundled-features/src/template-resolver/web/document-tiptap-toolbar.tsx +182 -0
  252. package/packages/bundled-features/src/template-resolver/web/editor-handle.ts +18 -0
  253. package/packages/bundled-features/src/template-resolver/web/i18n.ts +6 -0
  254. package/packages/bundled-features/src/template-resolver/web/placeholder-line-editor.tsx +19 -6
  255. package/packages/bundled-features/src/template-resolver/web/qualified-names.ts +1 -0
  256. package/packages/bundled-features/src/template-resolver/web/use-document-tiptap-model.ts +138 -0
  257. package/packages/bundled-features/src/tenant/changes.json +19 -0
  258. package/packages/bundled-features/src/tenant/feature.ts +1 -0
  259. package/packages/bundled-features/src/tenant/handlers/cancel-invitation.write.ts +1 -1
  260. package/packages/bundled-features/src/tenant/handlers/memberships.query.ts +1 -1
  261. package/packages/bundled-features/src/tenant/handlers/remove-member.write.ts +2 -2
  262. package/packages/bundled-features/src/tenant/handlers/team-list.query.ts +3 -3
  263. package/packages/bundled-features/src/tenant/handlers/update-member-roles.write.ts +1 -1
  264. package/packages/bundled-features/src/tenant/index.ts +5 -0
  265. package/packages/bundled-features/src/tenant/invited-membership.ts +6 -1
  266. package/packages/bundled-features/src/tenant/schema/tenant.ts +4 -1
  267. package/packages/bundled-features/src/tenant/seeding.ts +65 -62
  268. package/packages/bundled-features/src/tenant/stream-tenant-backfill.ts +115 -0
  269. package/packages/bundled-features/src/tenant/testing.ts +77 -0
  270. package/packages/bundled-features/src/tenant-handover/events.ts +1 -1
  271. package/packages/bundled-features/src/tenant-handover/handlers/claim.write.ts +1 -1
  272. package/packages/bundled-features/src/tenant-lifecycle/changes.json +6 -0
  273. package/packages/bundled-features/src/tenant-lifecycle/feature.ts +5 -5
  274. package/packages/bundled-features/src/tenant-lifecycle/handlers/cancel-destruction.write.ts +22 -10
  275. package/packages/bundled-features/src/tenant-lifecycle/handlers/request-destruction.write.ts +22 -11
  276. package/packages/bundled-features/src/tenant-lifecycle/run-tenant-destroy.ts +23 -12
  277. package/packages/bundled-features/src/tenant-lifecycle/stages.ts +42 -4
  278. package/packages/bundled-features/src/tenant-lifecycle/testing.ts +9 -8
  279. package/packages/bundled-features/src/tier-engine/entity.ts +1 -1
  280. package/packages/bundled-features/src/tier-engine/feature.ts +8 -3
  281. package/packages/bundled-features/src/tier-engine/handlers/active-tier.query.ts +3 -3
  282. package/packages/bundled-features/src/tier-engine/handlers/get-tenant-tier.query.ts +7 -1
  283. package/packages/bundled-features/src/tier-engine/handlers/set-tenant-tier.write.ts +3 -3
  284. package/packages/bundled-features/src/user/db/queries/stream-tenant-backfill.ts +71 -97
  285. package/packages/bundled-features/src/user/feature.ts +1 -0
  286. package/packages/bundled-features/src/user/handlers/find-for-auth.query.ts +2 -2
  287. package/packages/bundled-features/src/user/handlers/update-roles.ts +2 -2
  288. package/packages/bundled-features/src/user/index.ts +2 -0
  289. package/packages/bundled-features/src/user/invited-global-roles.ts +6 -1
  290. package/packages/bundled-features/src/user/principal-status.ts +1 -1
  291. package/packages/bundled-features/src/user/seeding.ts +24 -6
  292. package/packages/bundled-features/src/user/testing.ts +22 -0
  293. package/packages/bundled-features/src/user-data-rights/COMPLIANCE.md +1 -1
  294. package/packages/bundled-features/src/user-data-rights/README.md +1 -1
  295. package/packages/bundled-features/src/user-data-rights/audit-download.ts +12 -2
  296. package/packages/bundled-features/src/user-data-rights/changes.json +36 -0
  297. package/packages/bundled-features/src/user-data-rights/feature.ts +30 -24
  298. package/packages/bundled-features/src/user-data-rights/handlers/confirm-deletion-by-token.write.ts +1 -1
  299. package/packages/bundled-features/src/user-data-rights/handlers/deletion-grace-period.ts +1 -1
  300. package/packages/bundled-features/src/user-data-rights/handlers/download-by-job.query.ts +2 -2
  301. package/packages/bundled-features/src/user-data-rights/handlers/download-by-token.query.ts +2 -2
  302. package/packages/bundled-features/src/user-data-rights/handlers/request-deletion.write.ts +1 -1
  303. package/packages/bundled-features/src/user-data-rights/handlers/restrict-account.write.ts +4 -4
  304. package/packages/bundled-features/src/user-data-rights/handlers/run-forget-cleanup.write.ts +12 -6
  305. package/packages/bundled-features/src/user-data-rights/index.ts +8 -1
  306. package/packages/bundled-features/src/user-data-rights/lib/mail-transport-resolver.ts +1 -1
  307. package/packages/bundled-features/src/user-data-rights/lib/storage-provider-resolver.ts +1 -1
  308. package/packages/bundled-features/src/user-data-rights/lib/update-user-lifecycle.ts +6 -1
  309. package/packages/bundled-features/src/user-data-rights/run-export-jobs.ts +8 -2
  310. package/packages/bundled-features/src/user-data-rights/run-forget-cleanup.ts +14 -3
  311. package/packages/bundled-features/src/user-data-rights/run-user-export.ts +11 -1
  312. package/packages/bundled-features/src/user-data-rights/web/constants.ts +16 -0
  313. package/packages/bundled-features/src/user-data-rights/web/index.ts +6 -0
  314. package/packages/bundled-features/src/user-profile/handlers/change-email.write.ts +8 -6
  315. package/packages/bundled-features/src/waitlist/changes.json +18 -0
  316. package/packages/bundled-features/src/waitlist/feature.ts +1 -0
  317. package/packages/bundled-features/src/waitlist/handlers/export-purge.write.ts +1 -1
  318. package/packages/bundled-features/src/waitlist/handlers/invite.write.ts +2 -2
  319. package/packages/bundled-features/src/waitlist/handlers/reject.write.ts +1 -1
  320. package/packages/bundled-features/src/waitlist/handlers/submit.write.ts +34 -10
  321. package/packages/bundled-features/src/waitlist/import.ts +23 -3
  322. package/packages/bundled-features/src/waitlist/legacy-migrate.ts +8 -2
  323. package/packages/bundled-features/src/waitlist/link-on-signup.ts +7 -1
  324. package/packages/bundled-features/src/waitlist/options.ts +2 -1
  325. package/packages/bundled-features/src/workflow-runner/changes.json +6 -0
  326. package/packages/bundled-features/src/workflow-runner/db/queries/due-runs.ts +1 -1
  327. package/packages/bundled-features/src/workflow-runner/event-subscriber.ts +4 -3
  328. package/packages/bundled-features/src/workflow-runner/event-trigger.ts +2 -1
  329. package/packages/bundled-features/src/workflow-runner/feature.ts +2 -2
  330. package/packages/bundled-features/src/workflow-runner/handlers/resume-run.write.ts +8 -8
  331. package/packages/bundled-features/src/workflow-runner/runner.ts +6 -4
  332. package/samples/apps/cap-billing-demo/src/feature.ts +19 -5
  333. package/samples/apps/config-demo/src/app/server.ts +1 -1
  334. package/samples/apps/styleguide/src/app/client.tsx +2 -0
  335. package/samples/apps/styleguide/src/app/seed.ts +6 -4
  336. package/samples/apps/styleguide/src/app/server.ts +6 -3
  337. package/samples/apps/styleguide/src/features/widgets/feature.ts +15 -4
  338. package/samples/apps/styleguide/src/features/workboard/feature.ts +185 -0
  339. package/samples/apps/styleguide/src/features/workboard/i18n.ts +27 -0
  340. package/samples/apps/styleguide/src/features/workboard/seed.ts +121 -0
  341. package/samples/apps/styleguide/src/features/workboard/web.ts +13 -0
  342. package/samples/apps/ui-walkthrough/src/features/rental/i18n.ts +2 -0
  343. package/samples/apps/ui-walkthrough/src/features/rental/screens.ts +9 -0
  344. package/samples/apps/use-all-bundled/bin/main.ts +2 -0
  345. package/samples/apps/use-all-bundled/feature-manifest.json +17 -1
  346. package/samples/apps/use-all-bundled/kumiko/schema.ts +2 -0
  347. package/samples/apps/use-all-bundled/kumiko.config.ts +2 -0
  348. package/samples/apps/use-all-bundled/package.json +2 -1
  349. package/samples/apps/use-all-bundled/src/app/dev-app-options.ts +2 -0
  350. package/samples/apps/use-all-bundled/src/app/notes-feature.ts +2 -0
  351. package/samples/apps/use-all-bundled/src/app/seed.ts +12 -2
  352. package/samples/apps/use-all-bundled/src/bundled-lists.ts +15 -0
  353. package/samples/apps/user-data-rights-demo/README.md +1 -1
  354. package/samples/apps/user-data-rights-demo/src/feature.ts +3 -2
  355. package/samples/recipes/api-worker-split/README.md +2 -1
  356. package/samples/recipes/api-worker-split/src/feature.ts +2 -1
  357. package/samples/recipes/cross-feature-events/README.md +5 -5
  358. package/samples/recipes/cross-feature-events/package.json +1 -1
  359. package/samples/recipes/cross-feature-events/src/feature.ts +4 -4
  360. package/samples/recipes/event-sourcing/README.md +5 -5
  361. package/samples/recipes/event-sourcing/package.json +1 -1
  362. package/samples/recipes/event-sourcing/src/feature.ts +15 -15
  363. package/samples/recipes/files-post-processing/README.md +1 -1
  364. package/samples/recipes/files-post-processing/package.json +1 -1
  365. package/samples/recipes/files-post-processing/src/feature.ts +6 -4
  366. package/samples/recipes/golden-path/src/feature.ts +2 -1
  367. package/samples/recipes/lane-routing/package.json +1 -1
  368. package/samples/recipes/legal-pages/README.md +2 -2
  369. package/samples/recipes/lifecycle-hooks/README.md +4 -0
  370. package/samples/recipes/lifecycle-hooks/src/feature.ts +26 -1
  371. package/samples/recipes/list-table-options/README.md +50 -0
  372. package/samples/recipes/list-table-options/package.json +11 -0
  373. package/samples/recipes/list-table-options/src/feature.ts +221 -0
  374. package/samples/recipes/managed-config/README.md +3 -3
  375. package/samples/recipes/pdf-audit-export/src/feature.ts +2 -1
  376. package/samples/recipes/search/README.md +1 -1
  377. package/samples/recipes/search/src/feature.ts +3 -3
  378. package/samples/recipes/secrets-demo/README.md +1 -1
  379. package/samples/recipes/secrets-demo/src/feature.ts +5 -2
  380. package/samples/recipes/state-machine/src/events.ts +4 -3
  381. package/samples/recipes/state-machine/src/reducer.ts +1 -1
  382. package/samples/recipes/tenant-isolation/README.md +1 -0
  383. package/samples/recipes/tenant-isolation/src/feature.ts +36 -0
  384. package/samples/recipes/workflow-engine/src/resume-loop.ts +4 -4
  385. package/samples/recipes/workflow-engine/src/workflow-runner.ts +2 -2
@@ -0,0 +1,164 @@
1
+ import type { usePrimitives } from "@cosmicdrift/kumiko-renderer";
2
+ import type { Editor, JSONContent } from "@tiptap/core";
3
+ import {
4
+ isAllowedDocumentLinkHref,
5
+ isDocumentPlaceholderHref,
6
+ isDocumentReferenceName,
7
+ isDocumentResourceKey,
8
+ } from "./document-schema.ts";
9
+ import { parseDocumentStepsInput } from "./document-steps.ts";
10
+ import { type PanelKind, repeatTableContent } from "./document-tiptap-helpers.ts";
11
+
12
+ type Translate = (key: string, params?: Readonly<Record<string, unknown>>) => string;
13
+ type Primitives = ReturnType<typeof usePrimitives>;
14
+
15
+ export type PanelModel = {
16
+ readonly t: Translate;
17
+ readonly Button: Primitives["Button"];
18
+ readonly Field: Primitives["Field"];
19
+ readonly Input: Primitives["Input"];
20
+ readonly editor: Editor;
21
+ readonly kind: PanelKind;
22
+ readonly idPrefix: string;
23
+ readonly variableLabels: Readonly<Record<string, string>>;
24
+ readonly onClose: () => void;
25
+ readonly href: string;
26
+ readonly setHref: (value: string) => void;
27
+ readonly resource: string;
28
+ readonly setResource: (value: string) => void;
29
+ readonly alt: string;
30
+ readonly setAlt: (value: string) => void;
31
+ readonly buttonText: string;
32
+ readonly setButtonText: (value: string) => void;
33
+ readonly stepsText: string;
34
+ readonly setStepsText: (value: string) => void;
35
+ readonly setChosenName: (value: string) => void;
36
+ readonly setError: (value: string | null) => void;
37
+ readonly selectable: readonly string[];
38
+ readonly selectedName: string;
39
+ readonly noVariables: boolean;
40
+ };
41
+
42
+ type ChosenNames = {
43
+ readonly selectable: readonly string[];
44
+ readonly selectedName: string;
45
+ readonly noVariables: boolean;
46
+ };
47
+
48
+ export function chosenNamesOf(
49
+ kind: PanelKind,
50
+ variables: readonly string[],
51
+ chosenName: string,
52
+ ): ChosenNames {
53
+ const referenceNames = variables.filter(isDocumentReferenceName);
54
+ const buttonTargets = referenceNames.filter((name) => isDocumentPlaceholderHref(`{{${name}}}`));
55
+ const selectable = kind === "button" ? buttonTargets : referenceNames;
56
+ const selectedName = selectable.includes(chosenName) ? chosenName : (selectable[0] ?? "");
57
+ const needsVariables =
58
+ kind === "button" ||
59
+ kind === "repeat" ||
60
+ kind === "placeholder" ||
61
+ kind === "steps" ||
62
+ kind === "images";
63
+ return { selectable, selectedName, noVariables: needsVariables && selectable.length === 0 };
64
+ }
65
+
66
+ export function insertAndCloseOf(m: PanelModel): (content: JSONContent) => void {
67
+ return (content) => {
68
+ m.editor.chain().focus().insertContent(content).run();
69
+ m.onClose();
70
+ };
71
+ }
72
+
73
+ function submitLinkOf(m: PanelModel): () => void {
74
+ const { editor, href, t } = m;
75
+ return () => {
76
+ if (!isAllowedDocumentLinkHref(href)) {
77
+ m.setError(t("template-resolver.documentEditor.invalidLink"));
78
+ // skip: invalid input is reported through the panel error
79
+ return;
80
+ }
81
+ const chain = editor.chain().focus();
82
+ if (!editor.state.selection.empty) chain.setLink({ href }).run();
83
+ else if (editor.isActive("link")) chain.extendMarkRange("link").setLink({ href }).run();
84
+ else if (isDocumentPlaceholderHref(href))
85
+ // Placeholders are never inserted as {{name}} text; the link shows the variable's value.
86
+ chain
87
+ .insertContent({
88
+ type: "variable",
89
+ attrs: { name: href.slice(2, -2) },
90
+ marks: [{ type: "link", attrs: { href } }],
91
+ })
92
+ .run();
93
+ else
94
+ chain
95
+ .insertContent({ type: "text", text: href, marks: [{ type: "link", attrs: { href } }] })
96
+ .run();
97
+ m.onClose();
98
+ };
99
+ }
100
+
101
+ function submitImageOf(m: PanelModel): () => void {
102
+ const { resource, alt, t } = m;
103
+ return () => {
104
+ if (!isDocumentResourceKey(resource)) {
105
+ m.setError(t("template-resolver.documentEditor.invalidResourceKey"));
106
+ // skip: invalid input is reported through the panel error
107
+ return;
108
+ }
109
+ if (/[<>]/.test(alt)) {
110
+ m.setError(t("template-resolver.documentEditor.invalidImageAlt"));
111
+ // skip: invalid input is reported through the panel error
112
+ return;
113
+ }
114
+ insertAndCloseOf(m)({ type: "resource", attrs: { resource, alt: alt || null } });
115
+ };
116
+ }
117
+
118
+ function submitStepsOf(m: PanelModel): () => void {
119
+ return () => {
120
+ const steps = parseDocumentStepsInput(m.stepsText);
121
+ if (steps === null) {
122
+ m.setError(m.t("template-resolver.documentEditor.invalidSteps"));
123
+ // skip: invalid input is reported through the panel error
124
+ return;
125
+ }
126
+ insertAndCloseOf(m)({ type: "steps", attrs: { variable: m.selectedName, steps } });
127
+ };
128
+ }
129
+
130
+ // Variable-bound kinds offer no insert while there is nothing to bind to.
131
+ const INSERT_HANDLERS: Partial<Record<PanelKind, (m: PanelModel) => () => void>> = {
132
+ link: submitLinkOf,
133
+ image: submitImageOf,
134
+ button: (m) => () =>
135
+ insertAndCloseOf(m)({
136
+ type: "button",
137
+ attrs: { href: `{{${m.selectedName}}}` },
138
+ content: m.buttonText ? [{ type: "text", text: m.buttonText }] : [],
139
+ }),
140
+ repeat: (m) => () => insertAndCloseOf(m)(repeatTableContent(m.selectedName)),
141
+ steps: submitStepsOf,
142
+ images: (m) => () => insertAndCloseOf(m)({ type: "images", attrs: { variable: m.selectedName } }),
143
+ };
144
+
145
+ const KINDS_WITHOUT_VARIABLE_GUARD: readonly PanelKind[] = ["link", "image"];
146
+
147
+ export function panelActionProps(m: PanelModel): {
148
+ onInsert?: () => void;
149
+ onRemoveLink?: () => void;
150
+ } {
151
+ const { editor, kind } = m;
152
+ const build = INSERT_HANDLERS[kind];
153
+ const insertAllowed = KINDS_WITHOUT_VARIABLE_GUARD.includes(kind) || !m.noVariables;
154
+ return {
155
+ ...(build !== undefined && insertAllowed && { onInsert: build(m) }),
156
+ ...(kind === "link" &&
157
+ editor.isActive("link") && {
158
+ onRemoveLink: () => {
159
+ editor.chain().focus().extendMarkRange("link").unsetLink().run();
160
+ m.onClose();
161
+ },
162
+ }),
163
+ };
164
+ }
@@ -0,0 +1,115 @@
1
+ import { usePrimitives, useTranslation } from "@cosmicdrift/kumiko-renderer";
2
+ import type { Editor } from "@tiptap/core";
3
+ import { type ReactNode, useState } from "react";
4
+ import { PANEL_FIELDS } from "./document-insert-fields.tsx";
5
+ import { chosenNamesOf, type PanelModel, panelActionProps } from "./document-insert-model.ts";
6
+ import type { PanelKind } from "./document-tiptap-helpers.ts";
7
+
8
+ function PanelActions({
9
+ onInsert,
10
+ onRemoveLink,
11
+ onCancel,
12
+ }: {
13
+ readonly onInsert?: () => void;
14
+ readonly onRemoveLink?: () => void;
15
+ readonly onCancel: () => void;
16
+ }): ReactNode {
17
+ const { Button } = usePrimitives();
18
+ const t = useTranslation();
19
+ return (
20
+ <div className="flex gap-2">
21
+ {onInsert && (
22
+ <Button type="button" size="sm" onClick={onInsert}>
23
+ {t("template-resolver.documentEditor.insert")}
24
+ </Button>
25
+ )}
26
+ {onRemoveLink && (
27
+ <Button type="button" size="sm" variant="danger-ghost" onClick={onRemoveLink}>
28
+ {t("template-resolver.documentEditor.removeLink")}
29
+ </Button>
30
+ )}
31
+ <Button type="button" size="sm" variant="secondary" onClick={onCancel}>
32
+ {t("template-resolver.documentEditor.cancel")}
33
+ </Button>
34
+ </div>
35
+ );
36
+ }
37
+
38
+ type PanelProps = {
39
+ readonly editor: Editor;
40
+ readonly editorId: string;
41
+ readonly kind: PanelKind;
42
+ readonly variables: readonly string[];
43
+ readonly variableLabels: Readonly<Record<string, string>>;
44
+ readonly onClose: () => void;
45
+ };
46
+
47
+ export function InsertPanel({
48
+ editor,
49
+ editorId,
50
+ kind,
51
+ variables,
52
+ variableLabels,
53
+ onClose,
54
+ }: PanelProps): ReactNode {
55
+ const { Button, Field, Input } = usePrimitives();
56
+ const t = useTranslation();
57
+ const [href, setHref] = useState(() => {
58
+ const current = editor.getAttributes("link")["href"];
59
+ return typeof current === "string" ? current : "";
60
+ });
61
+ const [resource, setResource] = useState("");
62
+ const [alt, setAlt] = useState("");
63
+ const [buttonText, setButtonText] = useState(() =>
64
+ t("template-resolver.documentEditor.buttonDefaultText"),
65
+ );
66
+ const [stepsText, setStepsText] = useState(() =>
67
+ t("template-resolver.documentEditor.stepsDefault"),
68
+ );
69
+ const [chosenName, setChosenName] = useState("");
70
+ const [error, setError] = useState<string | null>(null);
71
+
72
+ const model: PanelModel = {
73
+ t,
74
+ Button,
75
+ Field,
76
+ Input,
77
+ editor,
78
+ kind,
79
+ idPrefix: `${editorId}-panel`,
80
+ variableLabels,
81
+ onClose,
82
+ href,
83
+ setHref,
84
+ resource,
85
+ setResource,
86
+ alt,
87
+ setAlt,
88
+ buttonText,
89
+ setButtonText,
90
+ stepsText,
91
+ setStepsText,
92
+ setChosenName,
93
+ setError,
94
+ ...chosenNamesOf(kind, variables, chosenName),
95
+ };
96
+
97
+ return (
98
+ <div className="flex flex-col gap-2 border-b border-input bg-muted/40 p-2">
99
+ {model.noVariables && (
100
+ <p className="text-sm text-muted-foreground">
101
+ {t("template-resolver.documentEditor.noVariables")}
102
+ </p>
103
+ )}
104
+ {PANEL_FIELDS[kind](model)}
105
+ {error !== null && (
106
+ <p role="alert" className="text-sm text-destructive">
107
+ {error}
108
+ </p>
109
+ )}
110
+ <div className="flex flex-wrap gap-2">
111
+ <PanelActions onCancel={onClose} {...panelActionProps(model)} />
112
+ </div>
113
+ </div>
114
+ );
115
+ }
@@ -0,0 +1,177 @@
1
+ import type { Editor } from "@tiptap/core";
2
+ import { BubbleMenu } from "@tiptap/react/menus";
3
+ import type { ReactNode } from "react";
4
+ import { DOCUMENT_BLOCK_ATTRIBUTE } from "./document-editor-extensions.ts";
5
+ import type { TiptapContext } from "./document-tiptap-context.ts";
6
+ import {
7
+ buttonTargetLabel,
8
+ findRepeatTable,
9
+ toggleRepeatHeader,
10
+ } from "./document-tiptap-helpers.ts";
11
+
12
+ // The bubble menu registers its plugin once per mount, so a rebuilt editor needs a fresh mount.
13
+ const editorMountKeys = new WeakMap<Editor, number>();
14
+ let lastMountKey = 0;
15
+ function mountKeyOf(editor: Editor): number {
16
+ const known = editorMountKeys.get(editor);
17
+ if (known !== undefined) return known;
18
+ lastMountKey += 1;
19
+ const created = lastMountKey;
20
+ editorMountKeys.set(editor, created);
21
+ return created;
22
+ }
23
+
24
+ // Board .hb: a small bar that straddles the block's top frame line on the right; above a table it sits fully
25
+ // outside so the header row stays readable.
26
+ const BUBBLE_BAR_CLASS =
27
+ "flex w-max items-center gap-1 rounded border border-input bg-popover p-px text-xs [&_button]:h-5 [&_button]:px-1.5 [&_button]:text-[10px]";
28
+
29
+ function bubbleOffset(editor: Editor): (args: { rects: { floating: { height: number } } }) => {
30
+ mainAxis: number;
31
+ crossAxis: number;
32
+ } {
33
+ return ({ rects }) => ({
34
+ mainAxis: findRepeatTable(editor) !== null ? 2 : -rects.floating.height / 2,
35
+ crossAxis: -8,
36
+ });
37
+ }
38
+
39
+ const BUBBLE_MENU_PLUGIN_KEY = "documentBlockOptions";
40
+
41
+ // The options bar belongs to the block frame, not to the caret inside it.
42
+ function selectedBlockReference(editor: Editor): {
43
+ getBoundingClientRect: () => DOMRect;
44
+ getClientRects: () => DOMRect[];
45
+ contextElement: Element;
46
+ } | null {
47
+ const { node } = editor.view.domAtPos(editor.state.selection.from);
48
+ const start = node instanceof Element ? node : node.parentElement;
49
+ const block = start?.closest(`[${DOCUMENT_BLOCK_ATTRIBUTE}], table`);
50
+ if (block === null || block === undefined) return null;
51
+ return {
52
+ getBoundingClientRect: () => block.getBoundingClientRect(),
53
+ getClientRects: () => [block.getBoundingClientRect()],
54
+ contextElement: block,
55
+ };
56
+ }
57
+
58
+ // The bubble is first measured before React has filled it, so it sits at the wrong place until a second pass.
59
+ function repositionBubble(editor: Editor): void {
60
+ if (editor.isDestroyed) return;
61
+ editor.view.dispatch(editor.state.tr.setMeta(BUBBLE_MENU_PLUGIN_KEY, "updatePosition"));
62
+ }
63
+
64
+ function repeatBarLabelOf(c: TiptapContext): string {
65
+ const { t, repeatListLabel } = c;
66
+ return repeatListLabel === undefined
67
+ ? t("template-resolver.documentEditor.repeat")
68
+ : t("template-resolver.documentEditor.repeatBarList", { list: repeatListLabel });
69
+ }
70
+
71
+ function renderBlockOptionsBar(
72
+ c: TiptapContext,
73
+ selectedBlock: { readonly type: "resource" | "button"; readonly detail: string },
74
+ ): ReactNode {
75
+ const { t, Button, editor } = c;
76
+ return (
77
+ <div className={BUBBLE_BAR_CLASS} data-testid="document-block-options">
78
+ <span className="px-1.5 text-[10px] text-muted-foreground">
79
+ {selectedBlock.type === "resource"
80
+ ? t("template-resolver.documentEditor.resourceKey")
81
+ : t("template-resolver.documentEditor.buttonTarget")}
82
+ {": "}
83
+ {selectedBlock.type === "button" ? (
84
+ <strong>{buttonTargetLabel(selectedBlock.detail, c.variableLabels)}</strong>
85
+ ) : (
86
+ <code>{selectedBlock.detail}</code>
87
+ )}
88
+ </span>
89
+ <Button
90
+ type="button"
91
+ size="sm"
92
+ variant="danger-ghost"
93
+ onClick={() => {
94
+ editor.chain().focus().deleteNode(selectedBlock.type).run();
95
+ }}
96
+ >
97
+ {t("template-resolver.documentEditor.removeBlock")}
98
+ </Button>
99
+ </div>
100
+ );
101
+ }
102
+
103
+ function renderBubbleRepeatBar(c: TiptapContext): ReactNode {
104
+ const { t, Button, editor } = c;
105
+ const repeatTable = c.activeState?.repeatTable ?? null;
106
+ return (
107
+ repeatTable !== null && (
108
+ <div data-testid="document-repeat-bar" className={BUBBLE_BAR_CLASS}>
109
+ <span className="px-1.5 text-[10px] uppercase tracking-wide text-muted-foreground">
110
+ {repeatBarLabelOf(c)}
111
+ </span>
112
+ <Button
113
+ type="button"
114
+ variant="secondary"
115
+ size="sm"
116
+ pressed={repeatTable.headerRepeats}
117
+ onClick={() => toggleRepeatHeader(editor)}
118
+ >
119
+ {t("template-resolver.documentEditor.repeatHeader")}
120
+ </Button>
121
+ </div>
122
+ )
123
+ );
124
+ }
125
+
126
+ export function renderBubbleMenu(c: TiptapContext): ReactNode {
127
+ const { editor } = c;
128
+ const selectedBlock = c.activeState?.selectedBlock ?? null;
129
+ return (
130
+ <BubbleMenu
131
+ key={mountKeyOf(editor)}
132
+ pluginKey={BUBBLE_MENU_PLUGIN_KEY}
133
+ editor={editor}
134
+ options={{
135
+ strategy: "fixed",
136
+ placement: "top-end",
137
+ offset: bubbleOffset(editor),
138
+ scrollTarget: c.canvasScroller ?? window,
139
+ onShow: () => requestAnimationFrame(() => repositionBubble(editor)),
140
+ }}
141
+ getReferencedVirtualElement={() => selectedBlockReference(editor)}
142
+ shouldShow={({ editor: e, element }) =>
143
+ // A leading image is selected by default; the bubble belongs to a deliberate selection.
144
+ (e.isFocused || element.contains(document.activeElement)) &&
145
+ (e.isActive("resource") || e.isActive("button") || findRepeatTable(e) !== null)
146
+ }
147
+ >
148
+ {selectedBlock !== null ? renderBlockOptionsBar(c, selectedBlock) : renderBubbleRepeatBar(c)}
149
+ </BubbleMenu>
150
+ );
151
+ }
152
+
153
+ export function renderInlineRepeatBar(c: TiptapContext): ReactNode {
154
+ const { t, Button, editor } = c;
155
+ const repeatTable = c.activeState?.repeatTable ?? null;
156
+ return (
157
+ repeatTable !== null &&
158
+ !c.readOnly &&
159
+ !c.canvas && (
160
+ <div
161
+ data-testid="document-repeat-bar"
162
+ className="flex flex-wrap items-center gap-3 border-b border-input bg-muted/40 px-2 py-1 text-xs"
163
+ >
164
+ <span className="font-medium">{repeatBarLabelOf(c)}</span>
165
+ <Button
166
+ type="button"
167
+ variant="secondary"
168
+ size="sm"
169
+ pressed={repeatTable.headerRepeats}
170
+ onClick={() => toggleRepeatHeader(editor)}
171
+ >
172
+ {t("template-resolver.documentEditor.repeatHeader")}
173
+ </Button>
174
+ </div>
175
+ )
176
+ );
177
+ }
@@ -0,0 +1,38 @@
1
+ import { cn } from "@cosmicdrift/kumiko-renderer/web";
2
+ import type { Editor } from "@tiptap/core";
3
+ import { EditorContent } from "@tiptap/react";
4
+ import type { ReactNode } from "react";
5
+
6
+ export function renderEditorContent(editor: Editor, canvas: boolean, hosted: boolean): ReactNode {
7
+ return (
8
+ <EditorContent
9
+ editor={editor}
10
+ className={cn(
11
+ !canvas && "min-h-40 px-3 py-2 text-base outline-none md:text-sm",
12
+ canvas && "text-sm",
13
+ "[&_.ProseMirror-focused_.ProseMirror-selectednode]:ring-2 [&_.ProseMirror-focused_.ProseMirror-selectednode]:ring-primary",
14
+ hosted
15
+ ? "[&_.ProseMirror]:outline-none"
16
+ : "[&_.ProseMirror]:min-h-40 [&_.ProseMirror]:outline-none",
17
+ "[&_ul]:list-disc [&_ol]:list-decimal [&_ul]:pl-6 [&_ol]:pl-6",
18
+ "[&_h1]:text-xl [&_h1]:font-bold [&_h2]:text-lg [&_h2]:font-bold [&_h3]:text-base [&_h3]:font-bold",
19
+ "[&_a]:underline [&_a]:text-primary",
20
+ "[&_strong]:font-bold [&_em]:italic [&_u]:underline",
21
+ canvas
22
+ ? "[&_table]:mb-2 [&_table]:mt-6 [&_.ProseMirror>:first-child_table]:mt-0 [&_.ProseMirror>table:first-child]:mt-0 [&_td:last-child>p[data-size=small][data-align=right]]:whitespace-nowrap"
23
+ : "[&_table]:my-2",
24
+ "[&_table]:w-full [&_table]:border-collapse",
25
+ "[&_td]:border-b [&_td]:border-border [&_td]:px-2 [&_td]:py-1.5 [&_td>p]:m-0 [&_th>p]:m-0",
26
+ "[&_th]:border-b [&_th]:border-border [&_th]:px-2 [&_th]:py-1.5 [&_th]:text-left [&_th]:text-xs [&_th]:font-medium [&_th]:text-muted-foreground",
27
+ "[&_tr[data-each]>td]:bg-muted/50",
28
+ "[&_[data-align=left]]:text-left [&_[data-align=center]]:text-center [&_[data-align=right]]:text-right [&_[data-align=justify]]:text-justify",
29
+ "[&_p[data-size=small]]:text-xs [&_p[data-size=small]]:text-muted-foreground",
30
+ "[&_a[data-button]]:inline-block [&_a[data-button]]:rounded-full [&_a[data-button]]:bg-primary [&_a[data-button]]:px-4 [&_a[data-button]]:py-1.5 [&_a[data-button]]:text-primary-foreground [&_a[data-button]]:no-underline",
31
+ // A chip in the button would be primary on primary; it inverts to stay readable.
32
+ "[&_a[data-button]_[data-variable-chip]]:border-primary-foreground/40 [&_a[data-button]_[data-variable-chip]]:bg-primary-foreground/15 [&_a[data-button]_[data-variable-chip]]:text-primary-foreground",
33
+ "[&_hr]:my-3 [&_hr]:border-input",
34
+ "[&_.is-editor-empty]:before:pointer-events-none [&_.is-editor-empty]:before:float-left [&_.is-editor-empty]:before:h-0 [&_.is-editor-empty]:before:text-muted-foreground [&_.is-editor-empty]:before:content-[attr(data-placeholder)]",
35
+ )}
36
+ />
37
+ );
38
+ }
@@ -0,0 +1,119 @@
1
+ import type { usePrimitives } from "@cosmicdrift/kumiko-renderer";
2
+ import type { Editor } from "@tiptap/core";
3
+ import type { Dispatch, SetStateAction } from "react";
4
+ import {
5
+ type ActiveState,
6
+ BLOCK_PANEL,
7
+ HEADING_LEVELS,
8
+ isParagraphStyle,
9
+ type PanelKind,
10
+ } from "./document-tiptap-helpers.ts";
11
+ import type { DocumentToolbarBlock } from "./document-toolbar-blocks.ts";
12
+ import type { DocumentEditorLabels } from "./use-document-tiptap-model.ts";
13
+
14
+ type Translate = (key: string, params?: Readonly<Record<string, unknown>>) => string;
15
+ type Primitives = ReturnType<typeof usePrimitives>;
16
+
17
+ export type TiptapContext = {
18
+ readonly id: string;
19
+ readonly t: Translate;
20
+ readonly Button: Primitives["Button"];
21
+ readonly Field: Primitives["Field"];
22
+ readonly Input: Primitives["Input"];
23
+ readonly ActionOverflowMenu: Primitives["ActionOverflowMenu"];
24
+ readonly editor: Editor;
25
+ readonly readOnly: boolean;
26
+ readonly canvas: boolean;
27
+ readonly compact: boolean;
28
+ readonly hosted: boolean;
29
+ readonly labels: DocumentEditorLabels;
30
+ readonly activeState: ActiveState | null;
31
+ readonly openPanel: PanelKind | null;
32
+ readonly setOpenPanel: Dispatch<SetStateAction<PanelKind | null>>;
33
+ readonly canvasScroller: HTMLElement | null;
34
+ readonly setCanvasScroller: Dispatch<SetStateAction<HTMLElement | null>>;
35
+ readonly showHtml: boolean;
36
+ readonly setShowHtml: Dispatch<SetStateAction<boolean>>;
37
+ readonly blocks: readonly DocumentToolbarBlock[];
38
+ readonly variables: readonly string[];
39
+ readonly imageVariables: readonly string[];
40
+ readonly variableLabels: Readonly<Record<string, string>>;
41
+ readonly stableLabels: Readonly<Record<string, string>>;
42
+ readonly togglePanel: (kind: PanelKind) => void;
43
+ readonly runBlock: (block: DocumentToolbarBlock) => void;
44
+ readonly setBlockStyle: (style: string) => void;
45
+ readonly repeatListLabel: string | undefined;
46
+ };
47
+
48
+ export type TiptapContextInput = Pick<
49
+ TiptapContext,
50
+ | "id"
51
+ | "t"
52
+ | "Button"
53
+ | "Field"
54
+ | "Input"
55
+ | "ActionOverflowMenu"
56
+ | "editor"
57
+ | "readOnly"
58
+ | "canvas"
59
+ | "compact"
60
+ | "hosted"
61
+ | "labels"
62
+ | "activeState"
63
+ | "openPanel"
64
+ | "setOpenPanel"
65
+ | "canvasScroller"
66
+ | "setCanvasScroller"
67
+ | "showHtml"
68
+ | "setShowHtml"
69
+ | "blocks"
70
+ | "variables"
71
+ | "imageVariables"
72
+ | "variableLabels"
73
+ | "stableLabels"
74
+ >;
75
+
76
+ function repeatListLabelOf(
77
+ activeState: ActiveState | null,
78
+ variableLabels: Readonly<Record<string, string>>,
79
+ ): string | undefined {
80
+ const repeatTable = activeState?.repeatTable ?? null;
81
+ return repeatTable !== null && repeatTable.lists.length === 1
82
+ ? (variableLabels[repeatTable.lists[0] ?? ""] ?? repeatTable.lists[0])
83
+ : undefined;
84
+ }
85
+
86
+ export function buildTiptapContext(input: TiptapContextInput): TiptapContext {
87
+ const { editor, setOpenPanel } = input;
88
+ const togglePanel = (kind: PanelKind): void =>
89
+ setOpenPanel((current) => (current === kind ? null : kind));
90
+
91
+ const setBlockStyle = (style: string): void => {
92
+ // skip: not a paragraph style value
93
+ if (!isParagraphStyle(style)) return;
94
+ const chain = editor.chain().focus();
95
+ if (style === "paragraph") chain.setParagraph().run();
96
+ else chain.setHeading({ level: HEADING_LEVELS[style] }).run();
97
+ };
98
+
99
+ const runBlock = (block: DocumentToolbarBlock): void => {
100
+ const panel = BLOCK_PANEL[block];
101
+ if (panel) {
102
+ togglePanel(panel);
103
+ // skip: panel blocks open their panel instead of inserting directly
104
+ return;
105
+ }
106
+ const chain = editor.chain().focus();
107
+ if (block === "table") chain.insertTable({ rows: 3, cols: 2, withHeaderRow: true }).run();
108
+ else if (block === "divider") chain.insertContent({ type: "divider" }).run();
109
+ else if (block === "pageBreak") chain.insertContent({ type: "pageBreak" }).run();
110
+ };
111
+
112
+ return {
113
+ ...input,
114
+ togglePanel,
115
+ runBlock,
116
+ setBlockStyle,
117
+ repeatListLabel: repeatListLabelOf(input.activeState, input.variableLabels),
118
+ };
119
+ }