@uniqbit/mate-core 1.0.0-canary.8 → 1.0.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 (244) hide show
  1. package/claude-capability-plugins/companion-mentions/.claude-plugin/plugin.json +1 -1
  2. package/package.json +5 -4
  3. package/src/cli/commands/artifact/delivery/link.ts +1 -1
  4. package/src/cli/commands/artifact/delivery/output.ts +10 -1
  5. package/src/cli/commands/artifact/delivery/resolve.ts +3 -2
  6. package/src/cli/commands/artifact/delivery/submit.ts +9 -4
  7. package/src/cli/commands/artifact/delivery/take.ts +12 -9
  8. package/src/cli/commands/artifact/finish/command.ts +16 -14
  9. package/src/cli/commands/artifact/finish/engine.ts +8 -8
  10. package/src/cli/commands/artifact/project/command.ts +2 -3
  11. package/src/cli/commands/companion/hub.ts +11 -6
  12. package/src/cli/commands/companion/link.ts +173 -46
  13. package/src/cli/commands/doctor.ts +17 -0
  14. package/src/cli/commands/report/contract.ts +0 -17
  15. package/src/cli/commands/studio/access.ts +4 -0
  16. package/src/cli/commands/studio/actions.ts +35 -2
  17. package/src/cli/commands/studio/mcp-manager.ts +162 -0
  18. package/src/cli/commands/studio/routes.ts +12 -0
  19. package/src/cli/commands/studio/selection.ts +44 -11
  20. package/src/cli/commands/studio/server.ts +246 -2
  21. package/src/cli/commands/studio/services.ts +26 -0
  22. package/src/cli/commands/studio/terminal-launch.ts +21 -4
  23. package/src/cli/commands/studio/terminal.ts +3 -14
  24. package/src/cli/commands/studio/work-requests.ts +9 -0
  25. package/src/cli/commands/studio/work.ts +473 -0
  26. package/src/cli/commands/vscode/release-vsix.json +2 -2
  27. package/src/cli/commands/working/cleanup.ts +1 -18
  28. package/src/cli/companion-link-wizard.tsx +158 -91
  29. package/src/cli/usage.ts +1 -1
  30. package/src/create-mate.ts +4 -1
  31. package/src/lib/agent-credential.ts +131 -0
  32. package/src/lib/credential-kinds.ts +7 -0
  33. package/src/lib/delivery/merge-git.ts +16 -0
  34. package/src/lib/delivery/record-delivery.ts +12 -6
  35. package/src/lib/delivery/record.ts +5 -0
  36. package/src/lib/delivery/refresh.ts +34 -6
  37. package/src/lib/delivery/staging/refs.ts +9 -4
  38. package/src/lib/delivery/staging/submit.ts +81 -22
  39. package/src/lib/mcp-manager/resolve.ts +88 -0
  40. package/src/lib/mcp-manager/store.ts +133 -0
  41. package/src/lib/mcp-manager/types.ts +72 -0
  42. package/src/lib/mcp-manager/validate.ts +242 -0
  43. package/src/lib/opencode-server.ts +2 -17
  44. package/src/lib/orchestrator/config-store.ts +30 -7
  45. package/src/lib/orchestrator/engine-floor.ts +16 -4
  46. package/src/lib/orchestrator/engine-guard.ts +7 -1
  47. package/src/lib/orchestrator/repo-local-store.ts +14 -0
  48. package/src/lib/orchestrator/repository-link.ts +80 -52
  49. package/src/lib/orchestrator/root-context.ts +17 -1
  50. package/src/lib/orchestrator/types.ts +4 -0
  51. package/src/lib/studio-chat/agent.ts +139 -0
  52. package/src/lib/studio-chat/companion-context.ts +136 -0
  53. package/src/lib/studio-chat/credential.ts +79 -0
  54. package/src/lib/studio-chat/harness-chat-agent.ts +334 -0
  55. package/src/lib/studio-chat/host-sandbox.ts +578 -0
  56. package/src/lib/studio-chat/prepare-bridges.ts +95 -0
  57. package/src/lib/studio-chat/session.ts +15 -0
  58. package/src/lib/studio-chat/turns.ts +112 -0
  59. package/src/lib/workset/claims.ts +85 -0
  60. package/src/lib/workset/execution.ts +71 -0
  61. package/src/lib/workset/git-transaction.ts +74 -0
  62. package/src/lib/workset/groups.ts +176 -0
  63. package/src/lib/workset/inventory.ts +196 -0
  64. package/src/lib/workset/projection.ts +237 -0
  65. package/src/lib/workset/record.ts +101 -36
  66. package/src/lib/workset/repositories.ts +24 -0
  67. package/src/lib/workset/sharing.ts +951 -0
  68. package/src/lib/workset/stages.ts +50 -14
  69. package/src/lib/workset/transactions.ts +158 -0
  70. package/src/runtime/companion-git-state.ts +1 -0
  71. package/src/runtime/companion-guidance.ts +2 -2
  72. package/src/runtime/forge-remote.ts +6 -0
  73. package/src/runtime/host-process.ts +28 -0
  74. package/src/runtime/secret-guard.ts +18 -1
  75. package/src/runtime/secret-patterns.ts +4 -3
  76. package/src/runtime/submitted-arrivals.ts +28 -2
  77. package/src/runtime/workflow/turn.ts +14 -12
  78. package/src/runtime/write-atomic.ts +2 -2
  79. package/src/studio.ts +61 -0
  80. package/src/templates/capabilities/openspec-cap/mate-full/schema.yaml +1 -1
  81. package/src/templates/capabilities/openspec-cap/mate-full/templates/proposal.md +1 -1
  82. package/src/templates/mate-skills/agents/mate-publish-artifact/SKILL.md +3 -2
  83. package/src/templates/mate-skills/agents/mate-submit-change/SKILL.md +5 -3
  84. package/src/templates/mate-skills/claude/mate-publish-artifact/SKILL.md +3 -2
  85. package/src/templates/mate-skills/claude/mate-submit-change/SKILL.md +5 -3
  86. package/src/tools/setup/__snapshots__/runtime-surface-golden.test.ts.snap +12 -12
  87. package/src/tools/setup/capabilities/mcp-manager.ts +73 -0
  88. package/src/tools/setup/context-services.ts +35 -6
  89. package/src/tools/setup/dynamic-plugins/audiences.ts +3 -2
  90. package/src/tools/setup/dynamic-plugins/declarations.ts +0 -26
  91. package/src/tools/setup/engine.ts +55 -3
  92. package/src/tools/setup/plugin.ts +14 -0
  93. package/src/tools/setup/plugins/gitignore.ts +1 -0
  94. package/src/tools/setup/providers/claude-format.ts +40 -7
  95. package/src/tools/setup/providers/claude.ts +38 -3
  96. package/src/tools/setup/providers/opencode-format.ts +13 -3
  97. package/src/tools/setup/providers/opencode.ts +7 -18
  98. package/src/tools/setup/providers/relative-path-warnings.ts +26 -0
  99. package/studio-dist/THIRD-PARTY-NOTICES.md +297 -0
  100. package/studio-dist/client/THIRD-PARTY-LICENSES.md +4294 -0
  101. package/studio-dist/client/assets/DialogTitle-DOhjDa7H.js +1 -0
  102. package/studio-dist/client/assets/app-CG3vCgyA.css +2 -0
  103. package/studio-dist/client/assets/bundle-mjs-CdK3cBzO.js +1 -0
  104. package/studio-dist/client/assets/button-upSzkd-q.js +1 -0
  105. package/studio-dist/client/assets/chat-DbaMXb8H.js +157 -0
  106. package/studio-dist/client/assets/cn-BCnYnarL.js +1 -0
  107. package/studio-dist/client/assets/combobox-cP9OsRf2.js +1 -0
  108. package/studio-dist/client/assets/{companion-view-C_N237bf.js → companion-view-B54_Lj0S.js} +1 -1
  109. package/studio-dist/client/assets/fields-DNZ4a89M.js +1 -0
  110. package/studio-dist/client/assets/friction-DgEimeDB.js +1 -0
  111. package/studio-dist/client/assets/getting-started-BTfYCt5s.js +1 -0
  112. package/studio-dist/client/assets/{getting-started-djaQeWlu.js → getting-started-CAszmdDJ.js} +1 -1
  113. package/studio-dist/client/assets/getting-started._topic-CHJMf0pa.js +1 -0
  114. package/studio-dist/client/assets/getting-started.index-MR6HftWs.js +1 -0
  115. package/studio-dist/client/assets/{graph-canvas-ySGKMhmk.js → graph-canvas-BdNk2F9O.js} +1 -1
  116. package/studio-dist/client/assets/graph-hRijsC89.js +2 -0
  117. package/studio-dist/client/assets/guides-CwFnh08E.js +1 -0
  118. package/studio-dist/client/assets/highlighted-body-JLMTFACH-BcroQey-.js +1 -0
  119. package/studio-dist/client/assets/index-D5oGyvG8.js +41 -0
  120. package/studio-dist/client/assets/{markdown-view-jMiaBTSO.js → markdown-view-CJ8JsLb7.js} +1 -1
  121. package/studio-dist/client/assets/marked.esm-vFuq1cCd.js +65 -0
  122. package/studio-dist/client/assets/mcp-BE9M-bkO.js +4 -0
  123. package/studio-dist/client/assets/mermaid-WFAXDIZX-BjSsakrn.js +1 -0
  124. package/studio-dist/client/assets/panel-CDQ6Lryw.js +1 -0
  125. package/studio-dist/client/assets/plugins._service._view-DRVPUAWN.js +1 -0
  126. package/studio-dist/client/assets/{prepaint-CKsXyJOR.js → prepaint-sD_LlrDN.js} +1 -1
  127. package/studio-dist/client/assets/{queries-Dfp5deWj.js → queries-COL925ML.js} +1 -1
  128. package/studio-dist/client/assets/react-dom-K3Hp2Cdj.js +1 -0
  129. package/studio-dist/client/assets/{react-BYUSgtBs.js → react-h2xQ_NSp.js} +1 -1
  130. package/studio-dist/client/assets/reports-BClsojkb.js +1 -0
  131. package/studio-dist/client/assets/routes-CJQ2MAej.js +1 -0
  132. package/studio-dist/client/assets/search-DhWdEiKT.js +1 -0
  133. package/studio-dist/client/assets/select-B2FsN9FY.js +1 -0
  134. package/studio-dist/client/assets/skills-SoUHk77W.js +1 -0
  135. package/studio-dist/client/assets/{specs-BrCOjOch.js → specs-C_tZnAvF.js} +1 -1
  136. package/studio-dist/client/assets/specs-view-C6t3Y5IT.js +1 -0
  137. package/studio-dist/client/assets/steps-CF3-Zpmh.js +1 -0
  138. package/studio-dist/client/assets/{store-C3vJq8Wj.js → store-pY9gU4uS.js} +1 -1
  139. package/studio-dist/client/assets/studio-X7bnFrRe.js +36 -0
  140. package/studio-dist/client/assets/studio-queries-CKtAnIKP.js +2 -0
  141. package/studio-dist/client/assets/usage-BaaqUpTG.js +55 -0
  142. package/studio-dist/client/assets/useAnchoredPopupScrollLock-BspHR7Wt.js +1 -0
  143. package/studio-dist/client/assets/useBlocker-BQOfcu_f.js +1 -0
  144. package/studio-dist/client/assets/useMutation-DKeEoP5S.js +1 -0
  145. package/studio-dist/client/assets/useOpenInteractionType-CtaZCaFT.js +1 -0
  146. package/studio-dist/client/assets/usePopupHandleStore-Bc7Q4bnF.js +1 -0
  147. package/studio-dist/client/assets/vault-sAPFUnPN.js +1 -0
  148. package/studio-dist/client/assets/{warnings-CqOOGlPD.js → warnings-D7YY1HSG.js} +1 -1
  149. package/studio-dist/client/assets/work-BZek_LGB.js +5 -0
  150. package/studio-dist/client/assets/workflow-N5boHXFz.js +1 -0
  151. package/studio-dist/server/THIRD-PARTY-LICENSES.md +4371 -0
  152. package/studio-dist/server/assets/DialogTitle-DnKSl2V0.js +421 -0
  153. package/studio-dist/server/assets/{__23tanstack-start-server-fn-resolver-gVfW5vIV.js → __23tanstack-start-server-fn-resolver-Bli9bpSB.js} +38 -18
  154. package/studio-dist/server/assets/_tanstack-start-manifest_v.js +91 -59
  155. package/studio-dist/server/assets/{actions-D8erOphH.js → actions-CHEFA1i9.js} +33 -1
  156. package/studio-dist/server/assets/{cn-FXJAM0KO.js → bundle-mjs-Ot6dQ8Pq.js} +1 -2056
  157. package/studio-dist/server/assets/{button-D6bvrFmm.js → button-BqA1urbl.js} +14 -7
  158. package/studio-dist/server/assets/chat-zl332Tvu.js +49486 -0
  159. package/studio-dist/server/assets/cn-B0fl6NWK.js +2057 -0
  160. package/studio-dist/server/assets/{combobox-D2MbYV1O.js → combobox-iTjvPCtS.js} +7 -6
  161. package/studio-dist/server/assets/{companion-view-Mf1ANbMb.js → companion-view-DIQ6AFIY.js} +2 -2
  162. package/studio-dist/server/assets/{companions-Dr6IpNAb.js → companions-aVwjRL8j.js} +1 -1
  163. package/studio-dist/server/assets/{fields-B4mAPETz.js → fields-BMap2_Ju.js} +10 -3
  164. package/studio-dist/server/assets/{friction-CWOTjpCV.js → friction-BER50hoD.js} +2 -2
  165. package/studio-dist/server/assets/{friction-9a5S1m7U.js → friction-BPs9KWdq.js} +8 -8
  166. package/studio-dist/server/assets/{getting-started-RU6tYU2Q.js → getting-started-DGfRVmZ_.js} +2 -2
  167. package/studio-dist/server/assets/{getting-started._topic-C02HGrC6.js → getting-started._topic-BgrBA4Vj.js} +2 -2
  168. package/studio-dist/server/assets/{getting-started.index-EzLRosbb.js → getting-started.index-BaFfQ9Mn.js} +2 -2
  169. package/studio-dist/server/assets/{graph-CZ2H9Fzr.js → graph-Cgzlrv3P.js} +8 -8
  170. package/studio-dist/server/assets/{graph-B11ITte0.js → graph-DODpuOy_.js} +1 -1
  171. package/studio-dist/server/assets/{graph-canvas-rP5TT14Z.js → graph-canvas-DW_zU1nA.js} +2 -2
  172. package/studio-dist/server/assets/{guides-BGftp4wf.js → guides-CA_EMG7E.js} +1 -1
  173. package/studio-dist/server/assets/{guides-B8HdeK_C.js → guides-D0SpoD32.js} +1 -1
  174. package/studio-dist/server/assets/{guides.server-DqFQAStf.js → guides.server-DJjQuy03.js} +1 -1
  175. package/studio-dist/server/assets/highlighted-body-JLMTFACH-BeHllu-r.js +41 -0
  176. package/studio-dist/server/assets/{markdown-view-CArpV-CS.js → markdown-view-CvVBGMZV.js} +1 -1
  177. package/studio-dist/server/assets/mcp-BU0fLYyJ.js +1103 -0
  178. package/studio-dist/server/assets/mcp-manager-D9YctTQe.js +50 -0
  179. package/studio-dist/server/assets/mermaid-WFAXDIZX-B1yDN6vG.js +1 -0
  180. package/studio-dist/server/assets/{panel-DR0iq46J.js → panel-D1K6Bsux.js} +4 -32
  181. package/studio-dist/server/assets/{plugins._service._view-n7u2k5dF.js → plugins._service._view-DdO1nELF.js} +4 -4
  182. package/studio-dist/server/assets/{prepaint-B28ClcPN.js → prepaint-BB3dwSmz.js} +1 -1
  183. package/studio-dist/server/assets/{queries-D-yVP9i0.js → queries-BwiDxQy5.js} +1 -1
  184. package/studio-dist/server/assets/{react-CiBZPDs8.js → react-B2cLiz-i.js} +1 -1
  185. package/studio-dist/server/assets/{reports-C2SmTgqh.js → reports-9Pr7Bz6o.js} +7 -7
  186. package/studio-dist/server/assets/{reports-B9k98oE6.js → reports-Cc9M3phM.js} +1 -1
  187. package/studio-dist/server/assets/{router-CPt0TAk_.js → router-DcWe0J7Y.js} +827 -548
  188. package/studio-dist/server/assets/{routes-CwH8LEy2.js → routes-BEXxl0py.js} +8 -8
  189. package/studio-dist/server/assets/{search-b-yQesv3.js → search-bltT7gwy.js} +39 -7
  190. package/studio-dist/server/assets/{select-C3i6TTX-.js → select-CZvHgGCi.js} +7 -6
  191. package/studio-dist/server/assets/{shell-CagqZZMZ.js → shell-BQ0vMKXN.js} +13 -4
  192. package/studio-dist/server/assets/{skills-DGg0mWDM.js → skills-Be_52h0i.js} +1 -1
  193. package/studio-dist/server/assets/{skills-C21Mg_8-.js → skills-BpGGUl6L.js} +8 -8
  194. package/studio-dist/server/assets/{specs-DetoMiaB.js → specs-CCGgXE-V.js} +5 -5
  195. package/studio-dist/server/assets/{specs-view-CmbfLDwN.js → specs-view-DtL5JxYM.js} +12 -11
  196. package/studio-dist/server/assets/{steps-D1tYAyWZ.js → steps-BWFSO6dM.js} +1 -1
  197. package/studio-dist/server/assets/{store-aC-I6f6o.js → store-X7yLPp7v.js} +1 -1
  198. package/studio-dist/server/assets/{studio-queries-Dqf-3nzj.js → studio-queries-ur1ygXi3.js} +117 -13
  199. package/studio-dist/server/assets/{studio-qRvQjRpz.js → studio-qzH-UETC.js} +1555 -179
  200. package/studio-dist/server/assets/{usage-Cwle9-xY.js → usage-C1o0DLzS.js} +1 -1
  201. package/studio-dist/server/assets/{usage-CS4CBK9D.js → usage-DWbSPrPD.js} +10 -9
  202. package/studio-dist/server/assets/{useAnchoredPopupScrollLock-BjMNgXv9.js → useAnchoredPopupScrollLock-DLDmv6kM.js} +4 -135
  203. package/studio-dist/server/assets/useBlocker-CQtANHK8.js +111 -0
  204. package/studio-dist/server/assets/{useMutation-DpBIuWXt.js → useMutation-NjlA8oFY.js} +2 -2
  205. package/studio-dist/server/assets/useOpenInteractionType-CZYscfOb.js +136 -0
  206. package/studio-dist/server/assets/usePopupHandleStore-DEEXJYv0.js +26 -0
  207. package/studio-dist/server/assets/{vault-CEBBRLMb.js → vault-B_kfi1h-.js} +1 -1
  208. package/studio-dist/server/assets/{vault-DVQidlId.js → vault-dL79JlKH.js} +8 -115
  209. package/studio-dist/server/assets/{views-UgO0Qz_g.js → views-BSGH56lb.js} +3 -3
  210. package/studio-dist/server/assets/{warnings-C7hgXpdk.js → warnings-DtUVPV-k.js} +2 -2
  211. package/studio-dist/server/assets/work-D789VXGH.js +110 -0
  212. package/studio-dist/server/assets/work-DsCEfhmK.js +3817 -0
  213. package/studio-dist/server/assets/work-requests-BLhOmQFO.js +11 -0
  214. package/studio-dist/server/assets/{workflow-6dZZ1ofw.js → workflow-BOZ2sRYg.js} +9 -9
  215. package/studio-dist/server/server.js +3 -3
  216. package/wrappers/bin/openspec +87 -2
  217. package/studio-dist/client/assets/app-ggXJ_QVh.css +0 -2
  218. package/studio-dist/client/assets/button-amJ3g5oD.js +0 -1
  219. package/studio-dist/client/assets/cn-BQPKiwI4.js +0 -1
  220. package/studio-dist/client/assets/combobox-CJ7aGFid.js +0 -1
  221. package/studio-dist/client/assets/fields-BAiGkJ5N.js +0 -1
  222. package/studio-dist/client/assets/friction-DqOU59v7.js +0 -1
  223. package/studio-dist/client/assets/getting-started-yp42dj5S.js +0 -1
  224. package/studio-dist/client/assets/getting-started._topic-C9zVXz_m.js +0 -1
  225. package/studio-dist/client/assets/getting-started.index-DWbDKICP.js +0 -1
  226. package/studio-dist/client/assets/graph-BYaD_5Bq.js +0 -2
  227. package/studio-dist/client/assets/guides-D6T6W_jV.js +0 -1
  228. package/studio-dist/client/assets/index-Qx7reRPD.js +0 -40
  229. package/studio-dist/client/assets/panel-C4bf_h2W.js +0 -1
  230. package/studio-dist/client/assets/plugins._service._view-y6f2FDAB.js +0 -1
  231. package/studio-dist/client/assets/reports-JFSwSueq.js +0 -1
  232. package/studio-dist/client/assets/routes-BdOWSgzK.js +0 -1
  233. package/studio-dist/client/assets/search-CXosfvYh.js +0 -1
  234. package/studio-dist/client/assets/select-BHYYWPhK.js +0 -1
  235. package/studio-dist/client/assets/skills-Bo9FLsBd.js +0 -1
  236. package/studio-dist/client/assets/specs-view-CdE2rlli.js +0 -1
  237. package/studio-dist/client/assets/steps-CKUno4lh.js +0 -1
  238. package/studio-dist/client/assets/studio-0ueISxwP.js +0 -100
  239. package/studio-dist/client/assets/studio-queries-BflKt9va.js +0 -2
  240. package/studio-dist/client/assets/usage-BLsLy0nN.js +0 -55
  241. package/studio-dist/client/assets/useAnchoredPopupScrollLock-DC7f8GOp.js +0 -1
  242. package/studio-dist/client/assets/useMutation-uJUrejsi.js +0 -1
  243. package/studio-dist/client/assets/vault-BB1B_OhR.js +0 -1
  244. package/studio-dist/client/assets/workflow-BFzmI-06.js +0 -1
@@ -0,0 +1,3817 @@
1
+ import { $ as DialogContent, D as persist, E as createJSONStorage, Ft as WORK_BUCKETS, It as isShared, Lt as useSuspenseQuery, Z as Dialog, et as DialogDescription, o as Route, tt as DialogTitle } from "./router-DcWe0J7Y.js";
2
+ import { _ as runWorkAction, a as afterWorkAction, dt as useNavigate, g as workQuery } from "./studio-queries-ur1ygXi3.js";
3
+ import { n as require_react, o as __toESM, t as require_jsx_runtime } from "./jsx-runtime-Bt0s0YKS.js";
4
+ import { i as require_react_dom } from "../server.js";
5
+ import "./studio-qzH-UETC.js";
6
+ import { $ as Age, ct as ROW, et as CommandLine, it as PAGE_PAD, lt as StatusWord, n as buttonVariants, nt as EmptyNote, r as Icon, t as Button, tt as Count } from "./button-BqA1urbl.js";
7
+ import { i as Textarea, t as Input } from "./fields-BMap2_Ju.js";
8
+ import { p as useQueryClient, t as cn } from "./cn-B0fl6NWK.js";
9
+ import { t as create } from "./react-B2cLiz-i.js";
10
+ import { t as useMutation } from "./useMutation-NjlA8oFY.js";
11
+ // ../../node_modules/.bun/@dnd-kit+utilities@3.2.2+e14d3f224186685e/node_modules/@dnd-kit/utilities/dist/utilities.esm.js
12
+ var import_react_dom = /* @__PURE__ */ __toESM(require_react_dom());
13
+ var import_react = /* @__PURE__ */ __toESM(require_react());
14
+ var canUseDOM = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
15
+ function isWindow(element) {
16
+ const elementString = Object.prototype.toString.call(element);
17
+ return elementString === "[object Window]" || elementString === "[object global]";
18
+ }
19
+ function isNode(node) {
20
+ return "nodeType" in node;
21
+ }
22
+ function getWindow(target) {
23
+ var _target$ownerDocument, _target$ownerDocument2;
24
+ if (!target) return window;
25
+ if (isWindow(target)) return target;
26
+ if (!isNode(target)) return window;
27
+ return (_target$ownerDocument = (_target$ownerDocument2 = target.ownerDocument) == null ? void 0 : _target$ownerDocument2.defaultView) != null ? _target$ownerDocument : window;
28
+ }
29
+ function isDocument(node) {
30
+ const { Document } = getWindow(node);
31
+ return node instanceof Document;
32
+ }
33
+ function isHTMLElement(node) {
34
+ if (isWindow(node)) return false;
35
+ return node instanceof getWindow(node).HTMLElement;
36
+ }
37
+ function isSVGElement(node) {
38
+ return node instanceof getWindow(node).SVGElement;
39
+ }
40
+ function getOwnerDocument(target) {
41
+ if (!target) return document;
42
+ if (isWindow(target)) return target.document;
43
+ if (!isNode(target)) return document;
44
+ if (isDocument(target)) return target;
45
+ if (isHTMLElement(target) || isSVGElement(target)) return target.ownerDocument;
46
+ return document;
47
+ }
48
+ /**
49
+ * A hook that resolves to useEffect on the server and useLayoutEffect on the client
50
+ * @param callback {function} Callback function that is invoked when the dependencies of the hook change
51
+ */
52
+ var useIsomorphicLayoutEffect = canUseDOM ? import_react.useLayoutEffect : import_react.useEffect;
53
+ function useEvent(handler) {
54
+ const handlerRef = (0, import_react.useRef)(handler);
55
+ useIsomorphicLayoutEffect(() => {
56
+ handlerRef.current = handler;
57
+ });
58
+ return (0, import_react.useCallback)(function() {
59
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) args[_key] = arguments[_key];
60
+ return handlerRef.current == null ? void 0 : handlerRef.current(...args);
61
+ }, []);
62
+ }
63
+ function useInterval() {
64
+ const intervalRef = (0, import_react.useRef)(null);
65
+ return [(0, import_react.useCallback)((listener, duration) => {
66
+ intervalRef.current = setInterval(listener, duration);
67
+ }, []), (0, import_react.useCallback)(() => {
68
+ if (intervalRef.current !== null) {
69
+ clearInterval(intervalRef.current);
70
+ intervalRef.current = null;
71
+ }
72
+ }, [])];
73
+ }
74
+ function useLatestValue(value, dependencies) {
75
+ if (dependencies === void 0) dependencies = [value];
76
+ const valueRef = (0, import_react.useRef)(value);
77
+ useIsomorphicLayoutEffect(() => {
78
+ if (valueRef.current !== value) valueRef.current = value;
79
+ }, dependencies);
80
+ return valueRef;
81
+ }
82
+ function useLazyMemo(callback, dependencies) {
83
+ const valueRef = (0, import_react.useRef)();
84
+ return (0, import_react.useMemo)(() => {
85
+ const newValue = callback(valueRef.current);
86
+ valueRef.current = newValue;
87
+ return newValue;
88
+ }, [...dependencies]);
89
+ }
90
+ function useNodeRef(onChange) {
91
+ const onChangeHandler = useEvent(onChange);
92
+ const node = (0, import_react.useRef)(null);
93
+ return [node, (0, import_react.useCallback)((element) => {
94
+ if (element !== node.current) onChangeHandler?.(element, node.current);
95
+ node.current = element;
96
+ }, [])];
97
+ }
98
+ function usePrevious(value) {
99
+ const ref = (0, import_react.useRef)();
100
+ (0, import_react.useEffect)(() => {
101
+ ref.current = value;
102
+ }, [value]);
103
+ return ref.current;
104
+ }
105
+ var ids = {};
106
+ function useUniqueId(prefix, value) {
107
+ return (0, import_react.useMemo)(() => {
108
+ if (value) return value;
109
+ const id = ids[prefix] == null ? 0 : ids[prefix] + 1;
110
+ ids[prefix] = id;
111
+ return prefix + "-" + id;
112
+ }, [prefix, value]);
113
+ }
114
+ function createAdjustmentFn(modifier) {
115
+ return function(object) {
116
+ for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) adjustments[_key - 1] = arguments[_key];
117
+ return adjustments.reduce((accumulator, adjustment) => {
118
+ const entries = Object.entries(adjustment);
119
+ for (const [key, valueAdjustment] of entries) {
120
+ const value = accumulator[key];
121
+ if (value != null) accumulator[key] = value + modifier * valueAdjustment;
122
+ }
123
+ return accumulator;
124
+ }, { ...object });
125
+ };
126
+ }
127
+ var add = /*#__PURE__*/ createAdjustmentFn(1);
128
+ var subtract = /*#__PURE__*/ createAdjustmentFn(-1);
129
+ function hasViewportRelativeCoordinates(event) {
130
+ return "clientX" in event && "clientY" in event;
131
+ }
132
+ function isKeyboardEvent(event) {
133
+ if (!event) return false;
134
+ const { KeyboardEvent } = getWindow(event.target);
135
+ return KeyboardEvent && event instanceof KeyboardEvent;
136
+ }
137
+ function isTouchEvent(event) {
138
+ if (!event) return false;
139
+ const { TouchEvent } = getWindow(event.target);
140
+ return TouchEvent && event instanceof TouchEvent;
141
+ }
142
+ /**
143
+ * Returns the normalized x and y coordinates for mouse and touch events.
144
+ */
145
+ function getEventCoordinates(event) {
146
+ if (isTouchEvent(event)) {
147
+ if (event.touches && event.touches.length) {
148
+ const { clientX: x, clientY: y } = event.touches[0];
149
+ return {
150
+ x,
151
+ y
152
+ };
153
+ } else if (event.changedTouches && event.changedTouches.length) {
154
+ const { clientX: x, clientY: y } = event.changedTouches[0];
155
+ return {
156
+ x,
157
+ y
158
+ };
159
+ }
160
+ }
161
+ if (hasViewportRelativeCoordinates(event)) return {
162
+ x: event.clientX,
163
+ y: event.clientY
164
+ };
165
+ return null;
166
+ }
167
+ var CSS$1 = /*#__PURE__*/ Object.freeze({
168
+ Translate: { toString(transform) {
169
+ if (!transform) return;
170
+ const { x, y } = transform;
171
+ return "translate3d(" + (x ? Math.round(x) : 0) + "px, " + (y ? Math.round(y) : 0) + "px, 0)";
172
+ } },
173
+ Scale: { toString(transform) {
174
+ if (!transform) return;
175
+ const { scaleX, scaleY } = transform;
176
+ return "scaleX(" + scaleX + ") scaleY(" + scaleY + ")";
177
+ } },
178
+ Transform: { toString(transform) {
179
+ if (!transform) return;
180
+ return [CSS$1.Translate.toString(transform), CSS$1.Scale.toString(transform)].join(" ");
181
+ } },
182
+ Transition: { toString(_ref) {
183
+ let { property, duration, easing } = _ref;
184
+ return property + " " + duration + "ms " + easing;
185
+ } }
186
+ });
187
+ var SELECTOR = "a,frame,iframe,input:not([type=hidden]):not(:disabled),select:not(:disabled),textarea:not(:disabled),button:not(:disabled),*[tabindex]";
188
+ function findFirstFocusableNode(element) {
189
+ if (element.matches(SELECTOR)) return element;
190
+ return element.querySelector(SELECTOR);
191
+ }
192
+ // ../../node_modules/.bun/@dnd-kit+accessibility@3.1.1+e14d3f224186685e/node_modules/@dnd-kit/accessibility/dist/accessibility.esm.js
193
+ var hiddenStyles = { display: "none" };
194
+ function HiddenText(_ref) {
195
+ let { id, value } = _ref;
196
+ return import_react.createElement("div", {
197
+ id,
198
+ style: hiddenStyles
199
+ }, value);
200
+ }
201
+ function LiveRegion(_ref) {
202
+ let { id, announcement, ariaLiveType = "assertive" } = _ref;
203
+ return import_react.createElement("div", {
204
+ id,
205
+ style: {
206
+ position: "fixed",
207
+ top: 0,
208
+ left: 0,
209
+ width: 1,
210
+ height: 1,
211
+ margin: -1,
212
+ border: 0,
213
+ padding: 0,
214
+ overflow: "hidden",
215
+ clip: "rect(0 0 0 0)",
216
+ clipPath: "inset(100%)",
217
+ whiteSpace: "nowrap"
218
+ },
219
+ role: "status",
220
+ "aria-live": ariaLiveType,
221
+ "aria-atomic": true
222
+ }, announcement);
223
+ }
224
+ function useAnnouncement() {
225
+ const [announcement, setAnnouncement] = (0, import_react.useState)("");
226
+ return {
227
+ announce: (0, import_react.useCallback)((value) => {
228
+ if (value != null) setAnnouncement(value);
229
+ }, []),
230
+ announcement
231
+ };
232
+ }
233
+ // ../../node_modules/.bun/@dnd-kit+core@6.3.1+7492c01c6988791b/node_modules/@dnd-kit/core/dist/core.esm.js
234
+ var DndMonitorContext = /*#__PURE__*/ (0, import_react.createContext)(null);
235
+ function useDndMonitor(listener) {
236
+ const registerListener = (0, import_react.useContext)(DndMonitorContext);
237
+ (0, import_react.useEffect)(() => {
238
+ if (!registerListener) throw new Error("useDndMonitor must be used within a children of <DndContext>");
239
+ return registerListener(listener);
240
+ }, [listener, registerListener]);
241
+ }
242
+ function useDndMonitorProvider() {
243
+ const [listeners] = (0, import_react.useState)(() => /* @__PURE__ */ new Set());
244
+ const registerListener = (0, import_react.useCallback)((listener) => {
245
+ listeners.add(listener);
246
+ return () => listeners.delete(listener);
247
+ }, [listeners]);
248
+ return [(0, import_react.useCallback)((_ref) => {
249
+ let { type, event } = _ref;
250
+ listeners.forEach((listener) => {
251
+ var _listener$type;
252
+ return (_listener$type = listener[type]) == null ? void 0 : _listener$type.call(listener, event);
253
+ });
254
+ }, [listeners]), registerListener];
255
+ }
256
+ var defaultScreenReaderInstructions = { draggable: "\n To pick up a draggable item, press the space bar.\n While dragging, use the arrow keys to move the item.\n Press space again to drop the item in its new position, or press escape to cancel.\n " };
257
+ var defaultAnnouncements = {
258
+ onDragStart(_ref) {
259
+ let { active } = _ref;
260
+ return "Picked up draggable item " + active.id + ".";
261
+ },
262
+ onDragOver(_ref2) {
263
+ let { active, over } = _ref2;
264
+ if (over) return "Draggable item " + active.id + " was moved over droppable area " + over.id + ".";
265
+ return "Draggable item " + active.id + " is no longer over a droppable area.";
266
+ },
267
+ onDragEnd(_ref3) {
268
+ let { active, over } = _ref3;
269
+ if (over) return "Draggable item " + active.id + " was dropped over droppable area " + over.id;
270
+ return "Draggable item " + active.id + " was dropped.";
271
+ },
272
+ onDragCancel(_ref4) {
273
+ let { active } = _ref4;
274
+ return "Dragging was cancelled. Draggable item " + active.id + " was dropped.";
275
+ }
276
+ };
277
+ function Accessibility(_ref) {
278
+ let { announcements = defaultAnnouncements, container, hiddenTextDescribedById, screenReaderInstructions = defaultScreenReaderInstructions } = _ref;
279
+ const { announce, announcement } = useAnnouncement();
280
+ const liveRegionId = useUniqueId("DndLiveRegion");
281
+ const [mounted, setMounted] = (0, import_react.useState)(false);
282
+ (0, import_react.useEffect)(() => {
283
+ setMounted(true);
284
+ }, []);
285
+ useDndMonitor((0, import_react.useMemo)(() => ({
286
+ onDragStart(_ref2) {
287
+ let { active } = _ref2;
288
+ announce(announcements.onDragStart({ active }));
289
+ },
290
+ onDragMove(_ref3) {
291
+ let { active, over } = _ref3;
292
+ if (announcements.onDragMove) announce(announcements.onDragMove({
293
+ active,
294
+ over
295
+ }));
296
+ },
297
+ onDragOver(_ref4) {
298
+ let { active, over } = _ref4;
299
+ announce(announcements.onDragOver({
300
+ active,
301
+ over
302
+ }));
303
+ },
304
+ onDragEnd(_ref5) {
305
+ let { active, over } = _ref5;
306
+ announce(announcements.onDragEnd({
307
+ active,
308
+ over
309
+ }));
310
+ },
311
+ onDragCancel(_ref6) {
312
+ let { active, over } = _ref6;
313
+ announce(announcements.onDragCancel({
314
+ active,
315
+ over
316
+ }));
317
+ }
318
+ }), [announce, announcements]));
319
+ if (!mounted) return null;
320
+ const markup = import_react.createElement(import_react.Fragment, null, import_react.createElement(HiddenText, {
321
+ id: hiddenTextDescribedById,
322
+ value: screenReaderInstructions.draggable
323
+ }), import_react.createElement(LiveRegion, {
324
+ id: liveRegionId,
325
+ announcement
326
+ }));
327
+ return container ? (0, import_react_dom.createPortal)(markup, container) : markup;
328
+ }
329
+ var Action;
330
+ (function(Action) {
331
+ Action["DragStart"] = "dragStart";
332
+ Action["DragMove"] = "dragMove";
333
+ Action["DragEnd"] = "dragEnd";
334
+ Action["DragCancel"] = "dragCancel";
335
+ Action["DragOver"] = "dragOver";
336
+ Action["RegisterDroppable"] = "registerDroppable";
337
+ Action["SetDroppableDisabled"] = "setDroppableDisabled";
338
+ Action["UnregisterDroppable"] = "unregisterDroppable";
339
+ })(Action || (Action = {}));
340
+ function noop() {}
341
+ function useSensor(sensor, options) {
342
+ return (0, import_react.useMemo)(() => ({
343
+ sensor,
344
+ options: options != null ? options : {}
345
+ }), [sensor, options]);
346
+ }
347
+ function useSensors() {
348
+ for (var _len = arguments.length, sensors = new Array(_len), _key = 0; _key < _len; _key++) sensors[_key] = arguments[_key];
349
+ return (0, import_react.useMemo)(() => [...sensors].filter((sensor) => sensor != null), [...sensors]);
350
+ }
351
+ var defaultCoordinates = /*#__PURE__*/ Object.freeze({
352
+ x: 0,
353
+ y: 0
354
+ });
355
+ /**
356
+ * Returns the distance between two points
357
+ */
358
+ function distanceBetween(p1, p2) {
359
+ return Math.sqrt(Math.pow(p1.x - p2.x, 2) + Math.pow(p1.y - p2.y, 2));
360
+ }
361
+ function getRelativeTransformOrigin(event, rect) {
362
+ const eventCoordinates = getEventCoordinates(event);
363
+ if (!eventCoordinates) return "0 0";
364
+ const transformOrigin = {
365
+ x: (eventCoordinates.x - rect.left) / rect.width * 100,
366
+ y: (eventCoordinates.y - rect.top) / rect.height * 100
367
+ };
368
+ return transformOrigin.x + "% " + transformOrigin.y + "%";
369
+ }
370
+ /**
371
+ * Sort collisions from smallest to greatest value
372
+ */
373
+ function sortCollisionsAsc(_ref, _ref2) {
374
+ let { data: { value: a } } = _ref;
375
+ let { data: { value: b } } = _ref2;
376
+ return a - b;
377
+ }
378
+ /**
379
+ * Sort collisions from greatest to smallest value
380
+ */
381
+ function sortCollisionsDesc(_ref3, _ref4) {
382
+ let { data: { value: a } } = _ref3;
383
+ let { data: { value: b } } = _ref4;
384
+ return b - a;
385
+ }
386
+ /**
387
+ * Returns the coordinates of the corners of a given rectangle:
388
+ * [TopLeft {x, y}, TopRight {x, y}, BottomLeft {x, y}, BottomRight {x, y}]
389
+ */
390
+ function cornersOfRectangle(_ref5) {
391
+ let { left, top, height, width } = _ref5;
392
+ return [
393
+ {
394
+ x: left,
395
+ y: top
396
+ },
397
+ {
398
+ x: left + width,
399
+ y: top
400
+ },
401
+ {
402
+ x: left,
403
+ y: top + height
404
+ },
405
+ {
406
+ x: left + width,
407
+ y: top + height
408
+ }
409
+ ];
410
+ }
411
+ function getFirstCollision(collisions, property) {
412
+ if (!collisions || collisions.length === 0) return null;
413
+ const [firstCollision] = collisions;
414
+ return property ? firstCollision[property] : firstCollision;
415
+ }
416
+ /**
417
+ * Returns the intersecting rectangle area between two rectangles
418
+ */
419
+ function getIntersectionRatio(entry, target) {
420
+ const top = Math.max(target.top, entry.top);
421
+ const left = Math.max(target.left, entry.left);
422
+ const right = Math.min(target.left + target.width, entry.left + entry.width);
423
+ const bottom = Math.min(target.top + target.height, entry.top + entry.height);
424
+ const width = right - left;
425
+ const height = bottom - top;
426
+ if (left < right && top < bottom) {
427
+ const targetArea = target.width * target.height;
428
+ const entryArea = entry.width * entry.height;
429
+ const intersectionArea = width * height;
430
+ const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea);
431
+ return Number(intersectionRatio.toFixed(4));
432
+ }
433
+ return 0;
434
+ }
435
+ /**
436
+ * Returns the rectangles that has the greatest intersection area with a given
437
+ * rectangle in an array of rectangles.
438
+ */
439
+ var rectIntersection = (_ref) => {
440
+ let { collisionRect, droppableRects, droppableContainers } = _ref;
441
+ const collisions = [];
442
+ for (const droppableContainer of droppableContainers) {
443
+ const { id } = droppableContainer;
444
+ const rect = droppableRects.get(id);
445
+ if (rect) {
446
+ const intersectionRatio = getIntersectionRatio(rect, collisionRect);
447
+ if (intersectionRatio > 0) collisions.push({
448
+ id,
449
+ data: {
450
+ droppableContainer,
451
+ value: intersectionRatio
452
+ }
453
+ });
454
+ }
455
+ }
456
+ return collisions.sort(sortCollisionsDesc);
457
+ };
458
+ /**
459
+ * Check if a given point is contained within a bounding rectangle
460
+ */
461
+ function isPointWithinRect(point, rect) {
462
+ const { top, left, bottom, right } = rect;
463
+ return top <= point.y && point.y <= bottom && left <= point.x && point.x <= right;
464
+ }
465
+ /**
466
+ * Returns the rectangles that the pointer is hovering over
467
+ */
468
+ var pointerWithin = (_ref) => {
469
+ let { droppableContainers, droppableRects, pointerCoordinates } = _ref;
470
+ if (!pointerCoordinates) return [];
471
+ const collisions = [];
472
+ for (const droppableContainer of droppableContainers) {
473
+ const { id } = droppableContainer;
474
+ const rect = droppableRects.get(id);
475
+ if (rect && isPointWithinRect(pointerCoordinates, rect)) {
476
+ const distances = cornersOfRectangle(rect).reduce((accumulator, corner) => {
477
+ return accumulator + distanceBetween(pointerCoordinates, corner);
478
+ }, 0);
479
+ const effectiveDistance = Number((distances / 4).toFixed(4));
480
+ collisions.push({
481
+ id,
482
+ data: {
483
+ droppableContainer,
484
+ value: effectiveDistance
485
+ }
486
+ });
487
+ }
488
+ }
489
+ return collisions.sort(sortCollisionsAsc);
490
+ };
491
+ function adjustScale(transform, rect1, rect2) {
492
+ return {
493
+ ...transform,
494
+ scaleX: rect1 && rect2 ? rect1.width / rect2.width : 1,
495
+ scaleY: rect1 && rect2 ? rect1.height / rect2.height : 1
496
+ };
497
+ }
498
+ function getRectDelta(rect1, rect2) {
499
+ return rect1 && rect2 ? {
500
+ x: rect1.left - rect2.left,
501
+ y: rect1.top - rect2.top
502
+ } : defaultCoordinates;
503
+ }
504
+ function createRectAdjustmentFn(modifier) {
505
+ return function adjustClientRect(rect) {
506
+ for (var _len = arguments.length, adjustments = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) adjustments[_key - 1] = arguments[_key];
507
+ return adjustments.reduce((acc, adjustment) => ({
508
+ ...acc,
509
+ top: acc.top + modifier * adjustment.y,
510
+ bottom: acc.bottom + modifier * adjustment.y,
511
+ left: acc.left + modifier * adjustment.x,
512
+ right: acc.right + modifier * adjustment.x
513
+ }), { ...rect });
514
+ };
515
+ }
516
+ var getAdjustedRect = /*#__PURE__*/ createRectAdjustmentFn(1);
517
+ function parseTransform(transform) {
518
+ if (transform.startsWith("matrix3d(")) {
519
+ const transformArray = transform.slice(9, -1).split(/, /);
520
+ return {
521
+ x: +transformArray[12],
522
+ y: +transformArray[13],
523
+ scaleX: +transformArray[0],
524
+ scaleY: +transformArray[5]
525
+ };
526
+ } else if (transform.startsWith("matrix(")) {
527
+ const transformArray = transform.slice(7, -1).split(/, /);
528
+ return {
529
+ x: +transformArray[4],
530
+ y: +transformArray[5],
531
+ scaleX: +transformArray[0],
532
+ scaleY: +transformArray[3]
533
+ };
534
+ }
535
+ return null;
536
+ }
537
+ function inverseTransform(rect, transform, transformOrigin) {
538
+ const parsedTransform = parseTransform(transform);
539
+ if (!parsedTransform) return rect;
540
+ const { scaleX, scaleY, x: translateX, y: translateY } = parsedTransform;
541
+ const x = rect.left - translateX - (1 - scaleX) * parseFloat(transformOrigin);
542
+ const y = rect.top - translateY - (1 - scaleY) * parseFloat(transformOrigin.slice(transformOrigin.indexOf(" ") + 1));
543
+ const w = scaleX ? rect.width / scaleX : rect.width;
544
+ const h = scaleY ? rect.height / scaleY : rect.height;
545
+ return {
546
+ width: w,
547
+ height: h,
548
+ top: y,
549
+ right: x + w,
550
+ bottom: y + h,
551
+ left: x
552
+ };
553
+ }
554
+ var defaultOptions = { ignoreTransform: false };
555
+ /**
556
+ * Returns the bounding client rect of an element relative to the viewport.
557
+ */
558
+ function getClientRect(element, options) {
559
+ if (options === void 0) options = defaultOptions;
560
+ let rect = element.getBoundingClientRect();
561
+ if (options.ignoreTransform) {
562
+ const { transform, transformOrigin } = getWindow(element).getComputedStyle(element);
563
+ if (transform) rect = inverseTransform(rect, transform, transformOrigin);
564
+ }
565
+ const { top, left, width, height, bottom, right } = rect;
566
+ return {
567
+ top,
568
+ left,
569
+ width,
570
+ height,
571
+ bottom,
572
+ right
573
+ };
574
+ }
575
+ /**
576
+ * Returns the bounding client rect of an element relative to the viewport.
577
+ *
578
+ * @remarks
579
+ * The ClientRect returned by this method does not take into account transforms
580
+ * applied to the element it measures.
581
+ *
582
+ */
583
+ function getTransformAgnosticClientRect(element) {
584
+ return getClientRect(element, { ignoreTransform: true });
585
+ }
586
+ function getWindowClientRect(element) {
587
+ const width = element.innerWidth;
588
+ const height = element.innerHeight;
589
+ return {
590
+ top: 0,
591
+ left: 0,
592
+ right: width,
593
+ bottom: height,
594
+ width,
595
+ height
596
+ };
597
+ }
598
+ function isFixed(node, computedStyle) {
599
+ if (computedStyle === void 0) computedStyle = getWindow(node).getComputedStyle(node);
600
+ return computedStyle.position === "fixed";
601
+ }
602
+ function isScrollable(element, computedStyle) {
603
+ if (computedStyle === void 0) computedStyle = getWindow(element).getComputedStyle(element);
604
+ const overflowRegex = /(auto|scroll|overlay)/;
605
+ return [
606
+ "overflow",
607
+ "overflowX",
608
+ "overflowY"
609
+ ].some((property) => {
610
+ const value = computedStyle[property];
611
+ return typeof value === "string" ? overflowRegex.test(value) : false;
612
+ });
613
+ }
614
+ function getScrollableAncestors(element, limit) {
615
+ const scrollParents = [];
616
+ function findScrollableAncestors(node) {
617
+ if (limit != null && scrollParents.length >= limit) return scrollParents;
618
+ if (!node) return scrollParents;
619
+ if (isDocument(node) && node.scrollingElement != null && !scrollParents.includes(node.scrollingElement)) {
620
+ scrollParents.push(node.scrollingElement);
621
+ return scrollParents;
622
+ }
623
+ if (!isHTMLElement(node) || isSVGElement(node)) return scrollParents;
624
+ if (scrollParents.includes(node)) return scrollParents;
625
+ const computedStyle = getWindow(element).getComputedStyle(node);
626
+ if (node !== element) {
627
+ if (isScrollable(node, computedStyle)) scrollParents.push(node);
628
+ }
629
+ if (isFixed(node, computedStyle)) return scrollParents;
630
+ return findScrollableAncestors(node.parentNode);
631
+ }
632
+ if (!element) return scrollParents;
633
+ return findScrollableAncestors(element);
634
+ }
635
+ function getFirstScrollableAncestor(node) {
636
+ const [firstScrollableAncestor] = getScrollableAncestors(node, 1);
637
+ return firstScrollableAncestor != null ? firstScrollableAncestor : null;
638
+ }
639
+ function getScrollableElement(element) {
640
+ if (!canUseDOM || !element) return null;
641
+ if (isWindow(element)) return element;
642
+ if (!isNode(element)) return null;
643
+ if (isDocument(element) || element === getOwnerDocument(element).scrollingElement) return window;
644
+ if (isHTMLElement(element)) return element;
645
+ return null;
646
+ }
647
+ function getScrollXCoordinate(element) {
648
+ if (isWindow(element)) return element.scrollX;
649
+ return element.scrollLeft;
650
+ }
651
+ function getScrollYCoordinate(element) {
652
+ if (isWindow(element)) return element.scrollY;
653
+ return element.scrollTop;
654
+ }
655
+ function getScrollCoordinates(element) {
656
+ return {
657
+ x: getScrollXCoordinate(element),
658
+ y: getScrollYCoordinate(element)
659
+ };
660
+ }
661
+ var Direction;
662
+ (function(Direction) {
663
+ Direction[Direction["Forward"] = 1] = "Forward";
664
+ Direction[Direction["Backward"] = -1] = "Backward";
665
+ })(Direction || (Direction = {}));
666
+ function isDocumentScrollingElement(element) {
667
+ if (!canUseDOM || !element) return false;
668
+ return element === document.scrollingElement;
669
+ }
670
+ function getScrollPosition(scrollingContainer) {
671
+ const minScroll = {
672
+ x: 0,
673
+ y: 0
674
+ };
675
+ const dimensions = isDocumentScrollingElement(scrollingContainer) ? {
676
+ height: window.innerHeight,
677
+ width: window.innerWidth
678
+ } : {
679
+ height: scrollingContainer.clientHeight,
680
+ width: scrollingContainer.clientWidth
681
+ };
682
+ const maxScroll = {
683
+ x: scrollingContainer.scrollWidth - dimensions.width,
684
+ y: scrollingContainer.scrollHeight - dimensions.height
685
+ };
686
+ return {
687
+ isTop: scrollingContainer.scrollTop <= minScroll.y,
688
+ isLeft: scrollingContainer.scrollLeft <= minScroll.x,
689
+ isBottom: scrollingContainer.scrollTop >= maxScroll.y,
690
+ isRight: scrollingContainer.scrollLeft >= maxScroll.x,
691
+ maxScroll,
692
+ minScroll
693
+ };
694
+ }
695
+ var defaultThreshold = {
696
+ x: .2,
697
+ y: .2
698
+ };
699
+ function getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, _ref, acceleration, thresholdPercentage) {
700
+ let { top, left, right, bottom } = _ref;
701
+ if (acceleration === void 0) acceleration = 10;
702
+ if (thresholdPercentage === void 0) thresholdPercentage = defaultThreshold;
703
+ const { isTop, isBottom, isLeft, isRight } = getScrollPosition(scrollContainer);
704
+ const direction = {
705
+ x: 0,
706
+ y: 0
707
+ };
708
+ const speed = {
709
+ x: 0,
710
+ y: 0
711
+ };
712
+ const threshold = {
713
+ height: scrollContainerRect.height * thresholdPercentage.y,
714
+ width: scrollContainerRect.width * thresholdPercentage.x
715
+ };
716
+ if (!isTop && top <= scrollContainerRect.top + threshold.height) {
717
+ direction.y = Direction.Backward;
718
+ speed.y = acceleration * Math.abs((scrollContainerRect.top + threshold.height - top) / threshold.height);
719
+ } else if (!isBottom && bottom >= scrollContainerRect.bottom - threshold.height) {
720
+ direction.y = Direction.Forward;
721
+ speed.y = acceleration * Math.abs((scrollContainerRect.bottom - threshold.height - bottom) / threshold.height);
722
+ }
723
+ if (!isRight && right >= scrollContainerRect.right - threshold.width) {
724
+ direction.x = Direction.Forward;
725
+ speed.x = acceleration * Math.abs((scrollContainerRect.right - threshold.width - right) / threshold.width);
726
+ } else if (!isLeft && left <= scrollContainerRect.left + threshold.width) {
727
+ direction.x = Direction.Backward;
728
+ speed.x = acceleration * Math.abs((scrollContainerRect.left + threshold.width - left) / threshold.width);
729
+ }
730
+ return {
731
+ direction,
732
+ speed
733
+ };
734
+ }
735
+ function getScrollElementRect(element) {
736
+ if (element === document.scrollingElement) {
737
+ const { innerWidth, innerHeight } = window;
738
+ return {
739
+ top: 0,
740
+ left: 0,
741
+ right: innerWidth,
742
+ bottom: innerHeight,
743
+ width: innerWidth,
744
+ height: innerHeight
745
+ };
746
+ }
747
+ const { top, left, right, bottom } = element.getBoundingClientRect();
748
+ return {
749
+ top,
750
+ left,
751
+ right,
752
+ bottom,
753
+ width: element.clientWidth,
754
+ height: element.clientHeight
755
+ };
756
+ }
757
+ function getScrollOffsets(scrollableAncestors) {
758
+ return scrollableAncestors.reduce((acc, node) => {
759
+ return add(acc, getScrollCoordinates(node));
760
+ }, defaultCoordinates);
761
+ }
762
+ function getScrollXOffset(scrollableAncestors) {
763
+ return scrollableAncestors.reduce((acc, node) => {
764
+ return acc + getScrollXCoordinate(node);
765
+ }, 0);
766
+ }
767
+ function getScrollYOffset(scrollableAncestors) {
768
+ return scrollableAncestors.reduce((acc, node) => {
769
+ return acc + getScrollYCoordinate(node);
770
+ }, 0);
771
+ }
772
+ function scrollIntoViewIfNeeded(element, measure) {
773
+ if (measure === void 0) measure = getClientRect;
774
+ if (!element) return;
775
+ const { top, left, bottom, right } = measure(element);
776
+ if (!getFirstScrollableAncestor(element)) return;
777
+ if (bottom <= 0 || right <= 0 || top >= window.innerHeight || left >= window.innerWidth) element.scrollIntoView({
778
+ block: "center",
779
+ inline: "center"
780
+ });
781
+ }
782
+ var properties = [[
783
+ "x",
784
+ ["left", "right"],
785
+ getScrollXOffset
786
+ ], [
787
+ "y",
788
+ ["top", "bottom"],
789
+ getScrollYOffset
790
+ ]];
791
+ var Rect = class {
792
+ constructor(rect, element) {
793
+ this.rect = void 0;
794
+ this.width = void 0;
795
+ this.height = void 0;
796
+ this.top = void 0;
797
+ this.bottom = void 0;
798
+ this.right = void 0;
799
+ this.left = void 0;
800
+ const scrollableAncestors = getScrollableAncestors(element);
801
+ const scrollOffsets = getScrollOffsets(scrollableAncestors);
802
+ this.rect = { ...rect };
803
+ this.width = rect.width;
804
+ this.height = rect.height;
805
+ for (const [axis, keys, getScrollOffset] of properties) for (const key of keys) Object.defineProperty(this, key, {
806
+ get: () => {
807
+ const currentOffsets = getScrollOffset(scrollableAncestors);
808
+ const scrollOffsetsDeltla = scrollOffsets[axis] - currentOffsets;
809
+ return this.rect[key] + scrollOffsetsDeltla;
810
+ },
811
+ enumerable: true
812
+ });
813
+ Object.defineProperty(this, "rect", { enumerable: false });
814
+ }
815
+ };
816
+ var Listeners = class {
817
+ constructor(target) {
818
+ this.target = void 0;
819
+ this.listeners = [];
820
+ this.removeAll = () => {
821
+ this.listeners.forEach((listener) => {
822
+ var _this$target;
823
+ return (_this$target = this.target) == null ? void 0 : _this$target.removeEventListener(...listener);
824
+ });
825
+ };
826
+ this.target = target;
827
+ }
828
+ add(eventName, handler, options) {
829
+ var _this$target2;
830
+ (_this$target2 = this.target) == null || _this$target2.addEventListener(eventName, handler, options);
831
+ this.listeners.push([
832
+ eventName,
833
+ handler,
834
+ options
835
+ ]);
836
+ }
837
+ };
838
+ function getEventListenerTarget(target) {
839
+ const { EventTarget } = getWindow(target);
840
+ return target instanceof EventTarget ? target : getOwnerDocument(target);
841
+ }
842
+ function hasExceededDistance(delta, measurement) {
843
+ const dx = Math.abs(delta.x);
844
+ const dy = Math.abs(delta.y);
845
+ if (typeof measurement === "number") return Math.sqrt(dx ** 2 + dy ** 2) > measurement;
846
+ if ("x" in measurement && "y" in measurement) return dx > measurement.x && dy > measurement.y;
847
+ if ("x" in measurement) return dx > measurement.x;
848
+ if ("y" in measurement) return dy > measurement.y;
849
+ return false;
850
+ }
851
+ var EventName;
852
+ (function(EventName) {
853
+ EventName["Click"] = "click";
854
+ EventName["DragStart"] = "dragstart";
855
+ EventName["Keydown"] = "keydown";
856
+ EventName["ContextMenu"] = "contextmenu";
857
+ EventName["Resize"] = "resize";
858
+ EventName["SelectionChange"] = "selectionchange";
859
+ EventName["VisibilityChange"] = "visibilitychange";
860
+ })(EventName || (EventName = {}));
861
+ function preventDefault(event) {
862
+ event.preventDefault();
863
+ }
864
+ function stopPropagation(event) {
865
+ event.stopPropagation();
866
+ }
867
+ var KeyboardCode;
868
+ (function(KeyboardCode) {
869
+ KeyboardCode["Space"] = "Space";
870
+ KeyboardCode["Down"] = "ArrowDown";
871
+ KeyboardCode["Right"] = "ArrowRight";
872
+ KeyboardCode["Left"] = "ArrowLeft";
873
+ KeyboardCode["Up"] = "ArrowUp";
874
+ KeyboardCode["Esc"] = "Escape";
875
+ KeyboardCode["Enter"] = "Enter";
876
+ KeyboardCode["Tab"] = "Tab";
877
+ })(KeyboardCode || (KeyboardCode = {}));
878
+ var defaultKeyboardCodes = {
879
+ start: [KeyboardCode.Space, KeyboardCode.Enter],
880
+ cancel: [KeyboardCode.Esc],
881
+ end: [
882
+ KeyboardCode.Space,
883
+ KeyboardCode.Enter,
884
+ KeyboardCode.Tab
885
+ ]
886
+ };
887
+ var defaultKeyboardCoordinateGetter = (event, _ref) => {
888
+ let { currentCoordinates } = _ref;
889
+ switch (event.code) {
890
+ case KeyboardCode.Right: return {
891
+ ...currentCoordinates,
892
+ x: currentCoordinates.x + 25
893
+ };
894
+ case KeyboardCode.Left: return {
895
+ ...currentCoordinates,
896
+ x: currentCoordinates.x - 25
897
+ };
898
+ case KeyboardCode.Down: return {
899
+ ...currentCoordinates,
900
+ y: currentCoordinates.y + 25
901
+ };
902
+ case KeyboardCode.Up: return {
903
+ ...currentCoordinates,
904
+ y: currentCoordinates.y - 25
905
+ };
906
+ }
907
+ };
908
+ var KeyboardSensor = class {
909
+ constructor(props) {
910
+ this.props = void 0;
911
+ this.autoScrollEnabled = false;
912
+ this.referenceCoordinates = void 0;
913
+ this.listeners = void 0;
914
+ this.windowListeners = void 0;
915
+ this.props = props;
916
+ const { event: { target } } = props;
917
+ this.props = props;
918
+ this.listeners = new Listeners(getOwnerDocument(target));
919
+ this.windowListeners = new Listeners(getWindow(target));
920
+ this.handleKeyDown = this.handleKeyDown.bind(this);
921
+ this.handleCancel = this.handleCancel.bind(this);
922
+ this.attach();
923
+ }
924
+ attach() {
925
+ this.handleStart();
926
+ this.windowListeners.add(EventName.Resize, this.handleCancel);
927
+ this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
928
+ setTimeout(() => this.listeners.add(EventName.Keydown, this.handleKeyDown));
929
+ }
930
+ handleStart() {
931
+ const { activeNode, onStart } = this.props;
932
+ const node = activeNode.node.current;
933
+ if (node) scrollIntoViewIfNeeded(node);
934
+ onStart(defaultCoordinates);
935
+ }
936
+ handleKeyDown(event) {
937
+ if (isKeyboardEvent(event)) {
938
+ const { active, context, options } = this.props;
939
+ const { keyboardCodes = defaultKeyboardCodes, coordinateGetter = defaultKeyboardCoordinateGetter, scrollBehavior = "smooth" } = options;
940
+ const { code } = event;
941
+ if (keyboardCodes.end.includes(code)) {
942
+ this.handleEnd(event);
943
+ return;
944
+ }
945
+ if (keyboardCodes.cancel.includes(code)) {
946
+ this.handleCancel(event);
947
+ return;
948
+ }
949
+ const { collisionRect } = context.current;
950
+ const currentCoordinates = collisionRect ? {
951
+ x: collisionRect.left,
952
+ y: collisionRect.top
953
+ } : defaultCoordinates;
954
+ if (!this.referenceCoordinates) this.referenceCoordinates = currentCoordinates;
955
+ const newCoordinates = coordinateGetter(event, {
956
+ active,
957
+ context: context.current,
958
+ currentCoordinates
959
+ });
960
+ if (newCoordinates) {
961
+ const coordinatesDelta = subtract(newCoordinates, currentCoordinates);
962
+ const scrollDelta = {
963
+ x: 0,
964
+ y: 0
965
+ };
966
+ const { scrollableAncestors } = context.current;
967
+ for (const scrollContainer of scrollableAncestors) {
968
+ const direction = event.code;
969
+ const { isTop, isRight, isLeft, isBottom, maxScroll, minScroll } = getScrollPosition(scrollContainer);
970
+ const scrollElementRect = getScrollElementRect(scrollContainer);
971
+ const clampedCoordinates = {
972
+ x: Math.min(direction === KeyboardCode.Right ? scrollElementRect.right - scrollElementRect.width / 2 : scrollElementRect.right, Math.max(direction === KeyboardCode.Right ? scrollElementRect.left : scrollElementRect.left + scrollElementRect.width / 2, newCoordinates.x)),
973
+ y: Math.min(direction === KeyboardCode.Down ? scrollElementRect.bottom - scrollElementRect.height / 2 : scrollElementRect.bottom, Math.max(direction === KeyboardCode.Down ? scrollElementRect.top : scrollElementRect.top + scrollElementRect.height / 2, newCoordinates.y))
974
+ };
975
+ const canScrollX = direction === KeyboardCode.Right && !isRight || direction === KeyboardCode.Left && !isLeft;
976
+ const canScrollY = direction === KeyboardCode.Down && !isBottom || direction === KeyboardCode.Up && !isTop;
977
+ if (canScrollX && clampedCoordinates.x !== newCoordinates.x) {
978
+ const newScrollCoordinates = scrollContainer.scrollLeft + coordinatesDelta.x;
979
+ const canScrollToNewCoordinates = direction === KeyboardCode.Right && newScrollCoordinates <= maxScroll.x || direction === KeyboardCode.Left && newScrollCoordinates >= minScroll.x;
980
+ if (canScrollToNewCoordinates && !coordinatesDelta.y) {
981
+ scrollContainer.scrollTo({
982
+ left: newScrollCoordinates,
983
+ behavior: scrollBehavior
984
+ });
985
+ return;
986
+ }
987
+ if (canScrollToNewCoordinates) scrollDelta.x = scrollContainer.scrollLeft - newScrollCoordinates;
988
+ else scrollDelta.x = direction === KeyboardCode.Right ? scrollContainer.scrollLeft - maxScroll.x : scrollContainer.scrollLeft - minScroll.x;
989
+ if (scrollDelta.x) scrollContainer.scrollBy({
990
+ left: -scrollDelta.x,
991
+ behavior: scrollBehavior
992
+ });
993
+ break;
994
+ } else if (canScrollY && clampedCoordinates.y !== newCoordinates.y) {
995
+ const newScrollCoordinates = scrollContainer.scrollTop + coordinatesDelta.y;
996
+ const canScrollToNewCoordinates = direction === KeyboardCode.Down && newScrollCoordinates <= maxScroll.y || direction === KeyboardCode.Up && newScrollCoordinates >= minScroll.y;
997
+ if (canScrollToNewCoordinates && !coordinatesDelta.x) {
998
+ scrollContainer.scrollTo({
999
+ top: newScrollCoordinates,
1000
+ behavior: scrollBehavior
1001
+ });
1002
+ return;
1003
+ }
1004
+ if (canScrollToNewCoordinates) scrollDelta.y = scrollContainer.scrollTop - newScrollCoordinates;
1005
+ else scrollDelta.y = direction === KeyboardCode.Down ? scrollContainer.scrollTop - maxScroll.y : scrollContainer.scrollTop - minScroll.y;
1006
+ if (scrollDelta.y) scrollContainer.scrollBy({
1007
+ top: -scrollDelta.y,
1008
+ behavior: scrollBehavior
1009
+ });
1010
+ break;
1011
+ }
1012
+ }
1013
+ this.handleMove(event, add(subtract(newCoordinates, this.referenceCoordinates), scrollDelta));
1014
+ }
1015
+ }
1016
+ }
1017
+ handleMove(event, coordinates) {
1018
+ const { onMove } = this.props;
1019
+ event.preventDefault();
1020
+ onMove(coordinates);
1021
+ }
1022
+ handleEnd(event) {
1023
+ const { onEnd } = this.props;
1024
+ event.preventDefault();
1025
+ this.detach();
1026
+ onEnd();
1027
+ }
1028
+ handleCancel(event) {
1029
+ const { onCancel } = this.props;
1030
+ event.preventDefault();
1031
+ this.detach();
1032
+ onCancel();
1033
+ }
1034
+ detach() {
1035
+ this.listeners.removeAll();
1036
+ this.windowListeners.removeAll();
1037
+ }
1038
+ };
1039
+ KeyboardSensor.activators = [{
1040
+ eventName: "onKeyDown",
1041
+ handler: (event, _ref, _ref2) => {
1042
+ let { keyboardCodes = defaultKeyboardCodes, onActivation } = _ref;
1043
+ let { active } = _ref2;
1044
+ const { code } = event.nativeEvent;
1045
+ if (keyboardCodes.start.includes(code)) {
1046
+ const activator = active.activatorNode.current;
1047
+ if (activator && event.target !== activator) return false;
1048
+ event.preventDefault();
1049
+ onActivation?.({ event: event.nativeEvent });
1050
+ return true;
1051
+ }
1052
+ return false;
1053
+ }
1054
+ }];
1055
+ function isDistanceConstraint(constraint) {
1056
+ return Boolean(constraint && "distance" in constraint);
1057
+ }
1058
+ function isDelayConstraint(constraint) {
1059
+ return Boolean(constraint && "delay" in constraint);
1060
+ }
1061
+ var AbstractPointerSensor = class {
1062
+ constructor(props, events, listenerTarget) {
1063
+ var _getEventCoordinates;
1064
+ if (listenerTarget === void 0) listenerTarget = getEventListenerTarget(props.event.target);
1065
+ this.props = void 0;
1066
+ this.events = void 0;
1067
+ this.autoScrollEnabled = true;
1068
+ this.document = void 0;
1069
+ this.activated = false;
1070
+ this.initialCoordinates = void 0;
1071
+ this.timeoutId = null;
1072
+ this.listeners = void 0;
1073
+ this.documentListeners = void 0;
1074
+ this.windowListeners = void 0;
1075
+ this.props = props;
1076
+ this.events = events;
1077
+ const { event } = props;
1078
+ const { target } = event;
1079
+ this.props = props;
1080
+ this.events = events;
1081
+ this.document = getOwnerDocument(target);
1082
+ this.documentListeners = new Listeners(this.document);
1083
+ this.listeners = new Listeners(listenerTarget);
1084
+ this.windowListeners = new Listeners(getWindow(target));
1085
+ this.initialCoordinates = (_getEventCoordinates = getEventCoordinates(event)) != null ? _getEventCoordinates : defaultCoordinates;
1086
+ this.handleStart = this.handleStart.bind(this);
1087
+ this.handleMove = this.handleMove.bind(this);
1088
+ this.handleEnd = this.handleEnd.bind(this);
1089
+ this.handleCancel = this.handleCancel.bind(this);
1090
+ this.handleKeydown = this.handleKeydown.bind(this);
1091
+ this.removeTextSelection = this.removeTextSelection.bind(this);
1092
+ this.attach();
1093
+ }
1094
+ attach() {
1095
+ const { events, props: { options: { activationConstraint, bypassActivationConstraint } } } = this;
1096
+ this.listeners.add(events.move.name, this.handleMove, { passive: false });
1097
+ this.listeners.add(events.end.name, this.handleEnd);
1098
+ if (events.cancel) this.listeners.add(events.cancel.name, this.handleCancel);
1099
+ this.windowListeners.add(EventName.Resize, this.handleCancel);
1100
+ this.windowListeners.add(EventName.DragStart, preventDefault);
1101
+ this.windowListeners.add(EventName.VisibilityChange, this.handleCancel);
1102
+ this.windowListeners.add(EventName.ContextMenu, preventDefault);
1103
+ this.documentListeners.add(EventName.Keydown, this.handleKeydown);
1104
+ if (activationConstraint) {
1105
+ if (bypassActivationConstraint != null && bypassActivationConstraint({
1106
+ event: this.props.event,
1107
+ activeNode: this.props.activeNode,
1108
+ options: this.props.options
1109
+ })) return this.handleStart();
1110
+ if (isDelayConstraint(activationConstraint)) {
1111
+ this.timeoutId = setTimeout(this.handleStart, activationConstraint.delay);
1112
+ this.handlePending(activationConstraint);
1113
+ return;
1114
+ }
1115
+ if (isDistanceConstraint(activationConstraint)) {
1116
+ this.handlePending(activationConstraint);
1117
+ return;
1118
+ }
1119
+ }
1120
+ this.handleStart();
1121
+ }
1122
+ detach() {
1123
+ this.listeners.removeAll();
1124
+ this.windowListeners.removeAll();
1125
+ setTimeout(this.documentListeners.removeAll, 50);
1126
+ if (this.timeoutId !== null) {
1127
+ clearTimeout(this.timeoutId);
1128
+ this.timeoutId = null;
1129
+ }
1130
+ }
1131
+ handlePending(constraint, offset) {
1132
+ const { active, onPending } = this.props;
1133
+ onPending(active, constraint, this.initialCoordinates, offset);
1134
+ }
1135
+ handleStart() {
1136
+ const { initialCoordinates } = this;
1137
+ const { onStart } = this.props;
1138
+ if (initialCoordinates) {
1139
+ this.activated = true;
1140
+ this.documentListeners.add(EventName.Click, stopPropagation, { capture: true });
1141
+ this.removeTextSelection();
1142
+ this.documentListeners.add(EventName.SelectionChange, this.removeTextSelection);
1143
+ onStart(initialCoordinates);
1144
+ }
1145
+ }
1146
+ handleMove(event) {
1147
+ var _getEventCoordinates2;
1148
+ const { activated, initialCoordinates, props } = this;
1149
+ const { onMove, options: { activationConstraint } } = props;
1150
+ if (!initialCoordinates) return;
1151
+ const coordinates = (_getEventCoordinates2 = getEventCoordinates(event)) != null ? _getEventCoordinates2 : defaultCoordinates;
1152
+ const delta = subtract(initialCoordinates, coordinates);
1153
+ if (!activated && activationConstraint) {
1154
+ if (isDistanceConstraint(activationConstraint)) {
1155
+ if (activationConstraint.tolerance != null && hasExceededDistance(delta, activationConstraint.tolerance)) return this.handleCancel();
1156
+ if (hasExceededDistance(delta, activationConstraint.distance)) return this.handleStart();
1157
+ }
1158
+ if (isDelayConstraint(activationConstraint)) {
1159
+ if (hasExceededDistance(delta, activationConstraint.tolerance)) return this.handleCancel();
1160
+ }
1161
+ this.handlePending(activationConstraint, delta);
1162
+ return;
1163
+ }
1164
+ if (event.cancelable) event.preventDefault();
1165
+ onMove(coordinates);
1166
+ }
1167
+ handleEnd() {
1168
+ const { onAbort, onEnd } = this.props;
1169
+ this.detach();
1170
+ if (!this.activated) onAbort(this.props.active);
1171
+ onEnd();
1172
+ }
1173
+ handleCancel() {
1174
+ const { onAbort, onCancel } = this.props;
1175
+ this.detach();
1176
+ if (!this.activated) onAbort(this.props.active);
1177
+ onCancel();
1178
+ }
1179
+ handleKeydown(event) {
1180
+ if (event.code === KeyboardCode.Esc) this.handleCancel();
1181
+ }
1182
+ removeTextSelection() {
1183
+ var _this$document$getSel;
1184
+ (_this$document$getSel = this.document.getSelection()) == null || _this$document$getSel.removeAllRanges();
1185
+ }
1186
+ };
1187
+ var events = {
1188
+ cancel: { name: "pointercancel" },
1189
+ move: { name: "pointermove" },
1190
+ end: { name: "pointerup" }
1191
+ };
1192
+ var PointerSensor = class extends AbstractPointerSensor {
1193
+ constructor(props) {
1194
+ const { event } = props;
1195
+ const listenerTarget = getOwnerDocument(event.target);
1196
+ super(props, events, listenerTarget);
1197
+ }
1198
+ };
1199
+ PointerSensor.activators = [{
1200
+ eventName: "onPointerDown",
1201
+ handler: (_ref, _ref2) => {
1202
+ let { nativeEvent: event } = _ref;
1203
+ let { onActivation } = _ref2;
1204
+ if (!event.isPrimary || event.button !== 0) return false;
1205
+ onActivation?.({ event });
1206
+ return true;
1207
+ }
1208
+ }];
1209
+ var events$1 = {
1210
+ move: { name: "mousemove" },
1211
+ end: { name: "mouseup" }
1212
+ };
1213
+ var MouseButton;
1214
+ (function(MouseButton) {
1215
+ MouseButton[MouseButton["RightClick"] = 2] = "RightClick";
1216
+ })(MouseButton || (MouseButton = {}));
1217
+ var MouseSensor = class extends AbstractPointerSensor {
1218
+ constructor(props) {
1219
+ super(props, events$1, getOwnerDocument(props.event.target));
1220
+ }
1221
+ };
1222
+ MouseSensor.activators = [{
1223
+ eventName: "onMouseDown",
1224
+ handler: (_ref, _ref2) => {
1225
+ let { nativeEvent: event } = _ref;
1226
+ let { onActivation } = _ref2;
1227
+ if (event.button === MouseButton.RightClick) return false;
1228
+ onActivation?.({ event });
1229
+ return true;
1230
+ }
1231
+ }];
1232
+ var events$2 = {
1233
+ cancel: { name: "touchcancel" },
1234
+ move: { name: "touchmove" },
1235
+ end: { name: "touchend" }
1236
+ };
1237
+ var TouchSensor = class extends AbstractPointerSensor {
1238
+ constructor(props) {
1239
+ super(props, events$2);
1240
+ }
1241
+ static setup() {
1242
+ window.addEventListener(events$2.move.name, noop, {
1243
+ capture: false,
1244
+ passive: false
1245
+ });
1246
+ return function teardown() {
1247
+ window.removeEventListener(events$2.move.name, noop);
1248
+ };
1249
+ function noop() {}
1250
+ }
1251
+ };
1252
+ TouchSensor.activators = [{
1253
+ eventName: "onTouchStart",
1254
+ handler: (_ref, _ref2) => {
1255
+ let { nativeEvent: event } = _ref;
1256
+ let { onActivation } = _ref2;
1257
+ const { touches } = event;
1258
+ if (touches.length > 1) return false;
1259
+ onActivation?.({ event });
1260
+ return true;
1261
+ }
1262
+ }];
1263
+ var AutoScrollActivator;
1264
+ (function(AutoScrollActivator) {
1265
+ AutoScrollActivator[AutoScrollActivator["Pointer"] = 0] = "Pointer";
1266
+ AutoScrollActivator[AutoScrollActivator["DraggableRect"] = 1] = "DraggableRect";
1267
+ })(AutoScrollActivator || (AutoScrollActivator = {}));
1268
+ var TraversalOrder;
1269
+ (function(TraversalOrder) {
1270
+ TraversalOrder[TraversalOrder["TreeOrder"] = 0] = "TreeOrder";
1271
+ TraversalOrder[TraversalOrder["ReversedTreeOrder"] = 1] = "ReversedTreeOrder";
1272
+ })(TraversalOrder || (TraversalOrder = {}));
1273
+ function useAutoScroller(_ref) {
1274
+ let { acceleration, activator = AutoScrollActivator.Pointer, canScroll, draggingRect, enabled, interval = 5, order = TraversalOrder.TreeOrder, pointerCoordinates, scrollableAncestors, scrollableAncestorRects, delta, threshold } = _ref;
1275
+ const scrollIntent = useScrollIntent({
1276
+ delta,
1277
+ disabled: !enabled
1278
+ });
1279
+ const [setAutoScrollInterval, clearAutoScrollInterval] = useInterval();
1280
+ const scrollSpeed = (0, import_react.useRef)({
1281
+ x: 0,
1282
+ y: 0
1283
+ });
1284
+ const scrollDirection = (0, import_react.useRef)({
1285
+ x: 0,
1286
+ y: 0
1287
+ });
1288
+ const rect = (0, import_react.useMemo)(() => {
1289
+ switch (activator) {
1290
+ case AutoScrollActivator.Pointer: return pointerCoordinates ? {
1291
+ top: pointerCoordinates.y,
1292
+ bottom: pointerCoordinates.y,
1293
+ left: pointerCoordinates.x,
1294
+ right: pointerCoordinates.x
1295
+ } : null;
1296
+ case AutoScrollActivator.DraggableRect: return draggingRect;
1297
+ }
1298
+ }, [
1299
+ activator,
1300
+ draggingRect,
1301
+ pointerCoordinates
1302
+ ]);
1303
+ const scrollContainerRef = (0, import_react.useRef)(null);
1304
+ const autoScroll = (0, import_react.useCallback)(() => {
1305
+ const scrollContainer = scrollContainerRef.current;
1306
+ if (!scrollContainer) return;
1307
+ const scrollLeft = scrollSpeed.current.x * scrollDirection.current.x;
1308
+ const scrollTop = scrollSpeed.current.y * scrollDirection.current.y;
1309
+ scrollContainer.scrollBy(scrollLeft, scrollTop);
1310
+ }, []);
1311
+ const sortedScrollableAncestors = (0, import_react.useMemo)(() => order === TraversalOrder.TreeOrder ? [...scrollableAncestors].reverse() : scrollableAncestors, [order, scrollableAncestors]);
1312
+ (0, import_react.useEffect)(() => {
1313
+ if (!enabled || !scrollableAncestors.length || !rect) {
1314
+ clearAutoScrollInterval();
1315
+ return;
1316
+ }
1317
+ for (const scrollContainer of sortedScrollableAncestors) {
1318
+ if ((canScroll == null ? void 0 : canScroll(scrollContainer)) === false) continue;
1319
+ const index = scrollableAncestors.indexOf(scrollContainer);
1320
+ const scrollContainerRect = scrollableAncestorRects[index];
1321
+ if (!scrollContainerRect) continue;
1322
+ const { direction, speed } = getScrollDirectionAndSpeed(scrollContainer, scrollContainerRect, rect, acceleration, threshold);
1323
+ for (const axis of ["x", "y"]) if (!scrollIntent[axis][direction[axis]]) {
1324
+ speed[axis] = 0;
1325
+ direction[axis] = 0;
1326
+ }
1327
+ if (speed.x > 0 || speed.y > 0) {
1328
+ clearAutoScrollInterval();
1329
+ scrollContainerRef.current = scrollContainer;
1330
+ setAutoScrollInterval(autoScroll, interval);
1331
+ scrollSpeed.current = speed;
1332
+ scrollDirection.current = direction;
1333
+ return;
1334
+ }
1335
+ }
1336
+ scrollSpeed.current = {
1337
+ x: 0,
1338
+ y: 0
1339
+ };
1340
+ scrollDirection.current = {
1341
+ x: 0,
1342
+ y: 0
1343
+ };
1344
+ clearAutoScrollInterval();
1345
+ }, [
1346
+ acceleration,
1347
+ autoScroll,
1348
+ canScroll,
1349
+ clearAutoScrollInterval,
1350
+ enabled,
1351
+ interval,
1352
+ JSON.stringify(rect),
1353
+ JSON.stringify(scrollIntent),
1354
+ setAutoScrollInterval,
1355
+ scrollableAncestors,
1356
+ sortedScrollableAncestors,
1357
+ scrollableAncestorRects,
1358
+ JSON.stringify(threshold)
1359
+ ]);
1360
+ }
1361
+ var defaultScrollIntent = {
1362
+ x: {
1363
+ [Direction.Backward]: false,
1364
+ [Direction.Forward]: false
1365
+ },
1366
+ y: {
1367
+ [Direction.Backward]: false,
1368
+ [Direction.Forward]: false
1369
+ }
1370
+ };
1371
+ function useScrollIntent(_ref2) {
1372
+ let { delta, disabled } = _ref2;
1373
+ const previousDelta = usePrevious(delta);
1374
+ return useLazyMemo((previousIntent) => {
1375
+ if (disabled || !previousDelta || !previousIntent) return defaultScrollIntent;
1376
+ const direction = {
1377
+ x: Math.sign(delta.x - previousDelta.x),
1378
+ y: Math.sign(delta.y - previousDelta.y)
1379
+ };
1380
+ return {
1381
+ x: {
1382
+ [Direction.Backward]: previousIntent.x[Direction.Backward] || direction.x === -1,
1383
+ [Direction.Forward]: previousIntent.x[Direction.Forward] || direction.x === 1
1384
+ },
1385
+ y: {
1386
+ [Direction.Backward]: previousIntent.y[Direction.Backward] || direction.y === -1,
1387
+ [Direction.Forward]: previousIntent.y[Direction.Forward] || direction.y === 1
1388
+ }
1389
+ };
1390
+ }, [
1391
+ disabled,
1392
+ delta,
1393
+ previousDelta
1394
+ ]);
1395
+ }
1396
+ function useCachedNode(draggableNodes, id) {
1397
+ const draggableNode = id != null ? draggableNodes.get(id) : void 0;
1398
+ const node = draggableNode ? draggableNode.node.current : null;
1399
+ return useLazyMemo((cachedNode) => {
1400
+ var _ref;
1401
+ if (id == null) return null;
1402
+ return (_ref = node != null ? node : cachedNode) != null ? _ref : null;
1403
+ }, [node, id]);
1404
+ }
1405
+ function useCombineActivators(sensors, getSyntheticHandler) {
1406
+ return (0, import_react.useMemo)(() => sensors.reduce((accumulator, sensor) => {
1407
+ const { sensor: Sensor } = sensor;
1408
+ const sensorActivators = Sensor.activators.map((activator) => ({
1409
+ eventName: activator.eventName,
1410
+ handler: getSyntheticHandler(activator.handler, sensor)
1411
+ }));
1412
+ return [...accumulator, ...sensorActivators];
1413
+ }, []), [sensors, getSyntheticHandler]);
1414
+ }
1415
+ var MeasuringStrategy;
1416
+ (function(MeasuringStrategy) {
1417
+ MeasuringStrategy[MeasuringStrategy["Always"] = 0] = "Always";
1418
+ MeasuringStrategy[MeasuringStrategy["BeforeDragging"] = 1] = "BeforeDragging";
1419
+ MeasuringStrategy[MeasuringStrategy["WhileDragging"] = 2] = "WhileDragging";
1420
+ })(MeasuringStrategy || (MeasuringStrategy = {}));
1421
+ var MeasuringFrequency;
1422
+ (function(MeasuringFrequency) {
1423
+ MeasuringFrequency["Optimized"] = "optimized";
1424
+ })(MeasuringFrequency || (MeasuringFrequency = {}));
1425
+ var defaultValue = /*#__PURE__*/ new Map();
1426
+ function useDroppableMeasuring(containers, _ref) {
1427
+ let { dragging, dependencies, config } = _ref;
1428
+ const [queue, setQueue] = (0, import_react.useState)(null);
1429
+ const { frequency, measure, strategy } = config;
1430
+ const containersRef = (0, import_react.useRef)(containers);
1431
+ const disabled = isDisabled();
1432
+ const disabledRef = useLatestValue(disabled);
1433
+ const measureDroppableContainers = (0, import_react.useCallback)(function(ids) {
1434
+ if (ids === void 0) ids = [];
1435
+ if (disabledRef.current) return;
1436
+ setQueue((value) => {
1437
+ if (value === null) return ids;
1438
+ return value.concat(ids.filter((id) => !value.includes(id)));
1439
+ });
1440
+ }, [disabledRef]);
1441
+ const timeoutId = (0, import_react.useRef)(null);
1442
+ const droppableRects = useLazyMemo((previousValue) => {
1443
+ if (disabled && !dragging) return defaultValue;
1444
+ if (!previousValue || previousValue === defaultValue || containersRef.current !== containers || queue != null) {
1445
+ const map = /* @__PURE__ */ new Map();
1446
+ for (let container of containers) {
1447
+ if (!container) continue;
1448
+ if (queue && queue.length > 0 && !queue.includes(container.id) && container.rect.current) {
1449
+ map.set(container.id, container.rect.current);
1450
+ continue;
1451
+ }
1452
+ const node = container.node.current;
1453
+ const rect = node ? new Rect(measure(node), node) : null;
1454
+ container.rect.current = rect;
1455
+ if (rect) map.set(container.id, rect);
1456
+ }
1457
+ return map;
1458
+ }
1459
+ return previousValue;
1460
+ }, [
1461
+ containers,
1462
+ queue,
1463
+ dragging,
1464
+ disabled,
1465
+ measure
1466
+ ]);
1467
+ (0, import_react.useEffect)(() => {
1468
+ containersRef.current = containers;
1469
+ }, [containers]);
1470
+ (0, import_react.useEffect)(() => {
1471
+ if (disabled) return;
1472
+ measureDroppableContainers();
1473
+ }, [dragging, disabled]);
1474
+ (0, import_react.useEffect)(() => {
1475
+ if (queue && queue.length > 0) setQueue(null);
1476
+ }, [JSON.stringify(queue)]);
1477
+ (0, import_react.useEffect)(() => {
1478
+ if (disabled || typeof frequency !== "number" || timeoutId.current !== null) return;
1479
+ timeoutId.current = setTimeout(() => {
1480
+ measureDroppableContainers();
1481
+ timeoutId.current = null;
1482
+ }, frequency);
1483
+ }, [
1484
+ frequency,
1485
+ disabled,
1486
+ measureDroppableContainers,
1487
+ ...dependencies
1488
+ ]);
1489
+ return {
1490
+ droppableRects,
1491
+ measureDroppableContainers,
1492
+ measuringScheduled: queue != null
1493
+ };
1494
+ function isDisabled() {
1495
+ switch (strategy) {
1496
+ case MeasuringStrategy.Always: return false;
1497
+ case MeasuringStrategy.BeforeDragging: return dragging;
1498
+ default: return !dragging;
1499
+ }
1500
+ }
1501
+ }
1502
+ function useInitialValue(value, computeFn) {
1503
+ return useLazyMemo((previousValue) => {
1504
+ if (!value) return null;
1505
+ if (previousValue) return previousValue;
1506
+ return typeof computeFn === "function" ? computeFn(value) : value;
1507
+ }, [computeFn, value]);
1508
+ }
1509
+ function useInitialRect(node, measure) {
1510
+ return useInitialValue(node, measure);
1511
+ }
1512
+ /**
1513
+ * Returns a new MutationObserver instance.
1514
+ * If `MutationObserver` is undefined in the execution environment, returns `undefined`.
1515
+ */
1516
+ function useMutationObserver(_ref) {
1517
+ let { callback, disabled } = _ref;
1518
+ const handleMutations = useEvent(callback);
1519
+ const mutationObserver = (0, import_react.useMemo)(() => {
1520
+ if (disabled || typeof window === "undefined" || typeof window.MutationObserver === "undefined") return;
1521
+ const { MutationObserver } = window;
1522
+ return new MutationObserver(handleMutations);
1523
+ }, [handleMutations, disabled]);
1524
+ (0, import_react.useEffect)(() => {
1525
+ return () => mutationObserver == null ? void 0 : mutationObserver.disconnect();
1526
+ }, [mutationObserver]);
1527
+ return mutationObserver;
1528
+ }
1529
+ /**
1530
+ * Returns a new ResizeObserver instance bound to the `onResize` callback.
1531
+ * If `ResizeObserver` is undefined in the execution environment, returns `undefined`.
1532
+ */
1533
+ function useResizeObserver(_ref) {
1534
+ let { callback, disabled } = _ref;
1535
+ const handleResize = useEvent(callback);
1536
+ const resizeObserver = (0, import_react.useMemo)(() => {
1537
+ if (disabled || typeof window === "undefined" || typeof window.ResizeObserver === "undefined") return;
1538
+ const { ResizeObserver } = window;
1539
+ return new ResizeObserver(handleResize);
1540
+ }, [disabled]);
1541
+ (0, import_react.useEffect)(() => {
1542
+ return () => resizeObserver == null ? void 0 : resizeObserver.disconnect();
1543
+ }, [resizeObserver]);
1544
+ return resizeObserver;
1545
+ }
1546
+ function defaultMeasure(element) {
1547
+ return new Rect(getClientRect(element), element);
1548
+ }
1549
+ function useRect(element, measure, fallbackRect) {
1550
+ if (measure === void 0) measure = defaultMeasure;
1551
+ const [rect, setRect] = (0, import_react.useState)(null);
1552
+ function measureRect() {
1553
+ setRect((currentRect) => {
1554
+ if (!element) return null;
1555
+ if (element.isConnected === false) {
1556
+ var _ref;
1557
+ return (_ref = currentRect != null ? currentRect : fallbackRect) != null ? _ref : null;
1558
+ }
1559
+ const newRect = measure(element);
1560
+ if (JSON.stringify(currentRect) === JSON.stringify(newRect)) return currentRect;
1561
+ return newRect;
1562
+ });
1563
+ }
1564
+ const mutationObserver = useMutationObserver({ callback(records) {
1565
+ if (!element) return;
1566
+ for (const record of records) {
1567
+ const { type, target } = record;
1568
+ if (type === "childList" && target instanceof HTMLElement && target.contains(element)) {
1569
+ measureRect();
1570
+ break;
1571
+ }
1572
+ }
1573
+ } });
1574
+ const resizeObserver = useResizeObserver({ callback: measureRect });
1575
+ useIsomorphicLayoutEffect(() => {
1576
+ measureRect();
1577
+ if (element) {
1578
+ resizeObserver?.observe(element);
1579
+ mutationObserver?.observe(document.body, {
1580
+ childList: true,
1581
+ subtree: true
1582
+ });
1583
+ } else {
1584
+ resizeObserver?.disconnect();
1585
+ mutationObserver?.disconnect();
1586
+ }
1587
+ }, [element]);
1588
+ return rect;
1589
+ }
1590
+ function useRectDelta(rect) {
1591
+ return getRectDelta(rect, useInitialValue(rect));
1592
+ }
1593
+ var defaultValue$1 = [];
1594
+ function useScrollableAncestors(node) {
1595
+ const previousNode = (0, import_react.useRef)(node);
1596
+ const ancestors = useLazyMemo((previousValue) => {
1597
+ if (!node) return defaultValue$1;
1598
+ if (previousValue && previousValue !== defaultValue$1 && node && previousNode.current && node.parentNode === previousNode.current.parentNode) return previousValue;
1599
+ return getScrollableAncestors(node);
1600
+ }, [node]);
1601
+ (0, import_react.useEffect)(() => {
1602
+ previousNode.current = node;
1603
+ }, [node]);
1604
+ return ancestors;
1605
+ }
1606
+ function useScrollOffsets(elements) {
1607
+ const [scrollCoordinates, setScrollCoordinates] = (0, import_react.useState)(null);
1608
+ const prevElements = (0, import_react.useRef)(elements);
1609
+ const handleScroll = (0, import_react.useCallback)((event) => {
1610
+ const scrollingElement = getScrollableElement(event.target);
1611
+ if (!scrollingElement) return;
1612
+ setScrollCoordinates((scrollCoordinates) => {
1613
+ if (!scrollCoordinates) return null;
1614
+ scrollCoordinates.set(scrollingElement, getScrollCoordinates(scrollingElement));
1615
+ return new Map(scrollCoordinates);
1616
+ });
1617
+ }, []);
1618
+ (0, import_react.useEffect)(() => {
1619
+ const previousElements = prevElements.current;
1620
+ if (elements !== previousElements) {
1621
+ cleanup(previousElements);
1622
+ const entries = elements.map((element) => {
1623
+ const scrollableElement = getScrollableElement(element);
1624
+ if (scrollableElement) {
1625
+ scrollableElement.addEventListener("scroll", handleScroll, { passive: true });
1626
+ return [scrollableElement, getScrollCoordinates(scrollableElement)];
1627
+ }
1628
+ return null;
1629
+ }).filter((entry) => entry != null);
1630
+ setScrollCoordinates(entries.length ? new Map(entries) : null);
1631
+ prevElements.current = elements;
1632
+ }
1633
+ return () => {
1634
+ cleanup(elements);
1635
+ cleanup(previousElements);
1636
+ };
1637
+ function cleanup(elements) {
1638
+ elements.forEach((element) => {
1639
+ getScrollableElement(element)?.removeEventListener("scroll", handleScroll);
1640
+ });
1641
+ }
1642
+ }, [handleScroll, elements]);
1643
+ return (0, import_react.useMemo)(() => {
1644
+ if (elements.length) return scrollCoordinates ? Array.from(scrollCoordinates.values()).reduce((acc, coordinates) => add(acc, coordinates), defaultCoordinates) : getScrollOffsets(elements);
1645
+ return defaultCoordinates;
1646
+ }, [elements, scrollCoordinates]);
1647
+ }
1648
+ function useScrollOffsetsDelta(scrollOffsets, dependencies) {
1649
+ if (dependencies === void 0) dependencies = [];
1650
+ const initialScrollOffsets = (0, import_react.useRef)(null);
1651
+ (0, import_react.useEffect)(() => {
1652
+ initialScrollOffsets.current = null;
1653
+ }, dependencies);
1654
+ (0, import_react.useEffect)(() => {
1655
+ const hasScrollOffsets = scrollOffsets !== defaultCoordinates;
1656
+ if (hasScrollOffsets && !initialScrollOffsets.current) initialScrollOffsets.current = scrollOffsets;
1657
+ if (!hasScrollOffsets && initialScrollOffsets.current) initialScrollOffsets.current = null;
1658
+ }, [scrollOffsets]);
1659
+ return initialScrollOffsets.current ? subtract(scrollOffsets, initialScrollOffsets.current) : defaultCoordinates;
1660
+ }
1661
+ function useSensorSetup(sensors) {
1662
+ (0, import_react.useEffect)(() => {
1663
+ if (!canUseDOM) return;
1664
+ const teardownFns = sensors.map((_ref) => {
1665
+ let { sensor } = _ref;
1666
+ return sensor.setup == null ? void 0 : sensor.setup();
1667
+ });
1668
+ return () => {
1669
+ for (const teardown of teardownFns) teardown?.();
1670
+ };
1671
+ }, sensors.map((_ref2) => {
1672
+ let { sensor } = _ref2;
1673
+ return sensor;
1674
+ }));
1675
+ }
1676
+ function useSyntheticListeners(listeners, id) {
1677
+ return (0, import_react.useMemo)(() => {
1678
+ return listeners.reduce((acc, _ref) => {
1679
+ let { eventName, handler } = _ref;
1680
+ acc[eventName] = (event) => {
1681
+ handler(event, id);
1682
+ };
1683
+ return acc;
1684
+ }, {});
1685
+ }, [listeners, id]);
1686
+ }
1687
+ function useWindowRect(element) {
1688
+ return (0, import_react.useMemo)(() => element ? getWindowClientRect(element) : null, [element]);
1689
+ }
1690
+ var defaultValue$2 = [];
1691
+ function useRects(elements, measure) {
1692
+ if (measure === void 0) measure = getClientRect;
1693
+ const [firstElement] = elements;
1694
+ const windowRect = useWindowRect(firstElement ? getWindow(firstElement) : null);
1695
+ const [rects, setRects] = (0, import_react.useState)(defaultValue$2);
1696
+ function measureRects() {
1697
+ setRects(() => {
1698
+ if (!elements.length) return defaultValue$2;
1699
+ return elements.map((element) => isDocumentScrollingElement(element) ? windowRect : new Rect(measure(element), element));
1700
+ });
1701
+ }
1702
+ const resizeObserver = useResizeObserver({ callback: measureRects });
1703
+ useIsomorphicLayoutEffect(() => {
1704
+ resizeObserver?.disconnect();
1705
+ measureRects();
1706
+ elements.forEach((element) => resizeObserver == null ? void 0 : resizeObserver.observe(element));
1707
+ }, [elements]);
1708
+ return rects;
1709
+ }
1710
+ function getMeasurableNode(node) {
1711
+ if (!node) return null;
1712
+ if (node.children.length > 1) return node;
1713
+ const firstChild = node.children[0];
1714
+ return isHTMLElement(firstChild) ? firstChild : node;
1715
+ }
1716
+ function useDragOverlayMeasuring(_ref) {
1717
+ let { measure } = _ref;
1718
+ const [rect, setRect] = (0, import_react.useState)(null);
1719
+ const resizeObserver = useResizeObserver({ callback: (0, import_react.useCallback)((entries) => {
1720
+ for (const { target } of entries) if (isHTMLElement(target)) {
1721
+ setRect((rect) => {
1722
+ const newRect = measure(target);
1723
+ return rect ? {
1724
+ ...rect,
1725
+ width: newRect.width,
1726
+ height: newRect.height
1727
+ } : newRect;
1728
+ });
1729
+ break;
1730
+ }
1731
+ }, [measure]) });
1732
+ const [nodeRef, setRef] = useNodeRef((0, import_react.useCallback)((element) => {
1733
+ const node = getMeasurableNode(element);
1734
+ resizeObserver?.disconnect();
1735
+ if (node) resizeObserver?.observe(node);
1736
+ setRect(node ? measure(node) : null);
1737
+ }, [measure, resizeObserver]));
1738
+ return (0, import_react.useMemo)(() => ({
1739
+ nodeRef,
1740
+ rect,
1741
+ setRef
1742
+ }), [
1743
+ rect,
1744
+ nodeRef,
1745
+ setRef
1746
+ ]);
1747
+ }
1748
+ var defaultSensors = [{
1749
+ sensor: PointerSensor,
1750
+ options: {}
1751
+ }, {
1752
+ sensor: KeyboardSensor,
1753
+ options: {}
1754
+ }];
1755
+ var defaultData = { current: {} };
1756
+ var defaultMeasuringConfiguration = {
1757
+ draggable: { measure: getTransformAgnosticClientRect },
1758
+ droppable: {
1759
+ measure: getTransformAgnosticClientRect,
1760
+ strategy: MeasuringStrategy.WhileDragging,
1761
+ frequency: MeasuringFrequency.Optimized
1762
+ },
1763
+ dragOverlay: { measure: getClientRect }
1764
+ };
1765
+ var DroppableContainersMap = class extends Map {
1766
+ get(id) {
1767
+ var _super$get;
1768
+ return id != null ? (_super$get = super.get(id)) != null ? _super$get : void 0 : void 0;
1769
+ }
1770
+ toArray() {
1771
+ return Array.from(this.values());
1772
+ }
1773
+ getEnabled() {
1774
+ return this.toArray().filter((_ref) => {
1775
+ let { disabled } = _ref;
1776
+ return !disabled;
1777
+ });
1778
+ }
1779
+ getNodeFor(id) {
1780
+ var _this$get$node$curren, _this$get;
1781
+ return (_this$get$node$curren = (_this$get = this.get(id)) == null ? void 0 : _this$get.node.current) != null ? _this$get$node$curren : void 0;
1782
+ }
1783
+ };
1784
+ var defaultPublicContext = {
1785
+ activatorEvent: null,
1786
+ active: null,
1787
+ activeNode: null,
1788
+ activeNodeRect: null,
1789
+ collisions: null,
1790
+ containerNodeRect: null,
1791
+ draggableNodes: /*#__PURE__*/ new Map(),
1792
+ droppableRects: /*#__PURE__*/ new Map(),
1793
+ droppableContainers: /*#__PURE__*/ new DroppableContainersMap(),
1794
+ over: null,
1795
+ dragOverlay: {
1796
+ nodeRef: { current: null },
1797
+ rect: null,
1798
+ setRef: noop
1799
+ },
1800
+ scrollableAncestors: [],
1801
+ scrollableAncestorRects: [],
1802
+ measuringConfiguration: defaultMeasuringConfiguration,
1803
+ measureDroppableContainers: noop,
1804
+ windowRect: null,
1805
+ measuringScheduled: false
1806
+ };
1807
+ var defaultInternalContext = {
1808
+ activatorEvent: null,
1809
+ activators: [],
1810
+ active: null,
1811
+ activeNodeRect: null,
1812
+ ariaDescribedById: { draggable: "" },
1813
+ dispatch: noop,
1814
+ draggableNodes: /*#__PURE__*/ new Map(),
1815
+ over: null,
1816
+ measureDroppableContainers: noop
1817
+ };
1818
+ var InternalContext = /*#__PURE__*/ (0, import_react.createContext)(defaultInternalContext);
1819
+ var PublicContext = /*#__PURE__*/ (0, import_react.createContext)(defaultPublicContext);
1820
+ function getInitialState() {
1821
+ return {
1822
+ draggable: {
1823
+ active: null,
1824
+ initialCoordinates: {
1825
+ x: 0,
1826
+ y: 0
1827
+ },
1828
+ nodes: /* @__PURE__ */ new Map(),
1829
+ translate: {
1830
+ x: 0,
1831
+ y: 0
1832
+ }
1833
+ },
1834
+ droppable: { containers: new DroppableContainersMap() }
1835
+ };
1836
+ }
1837
+ function reducer(state, action) {
1838
+ switch (action.type) {
1839
+ case Action.DragStart: return {
1840
+ ...state,
1841
+ draggable: {
1842
+ ...state.draggable,
1843
+ initialCoordinates: action.initialCoordinates,
1844
+ active: action.active
1845
+ }
1846
+ };
1847
+ case Action.DragMove:
1848
+ if (state.draggable.active == null) return state;
1849
+ return {
1850
+ ...state,
1851
+ draggable: {
1852
+ ...state.draggable,
1853
+ translate: {
1854
+ x: action.coordinates.x - state.draggable.initialCoordinates.x,
1855
+ y: action.coordinates.y - state.draggable.initialCoordinates.y
1856
+ }
1857
+ }
1858
+ };
1859
+ case Action.DragEnd:
1860
+ case Action.DragCancel: return {
1861
+ ...state,
1862
+ draggable: {
1863
+ ...state.draggable,
1864
+ active: null,
1865
+ initialCoordinates: {
1866
+ x: 0,
1867
+ y: 0
1868
+ },
1869
+ translate: {
1870
+ x: 0,
1871
+ y: 0
1872
+ }
1873
+ }
1874
+ };
1875
+ case Action.RegisterDroppable: {
1876
+ const { element } = action;
1877
+ const { id } = element;
1878
+ const containers = new DroppableContainersMap(state.droppable.containers);
1879
+ containers.set(id, element);
1880
+ return {
1881
+ ...state,
1882
+ droppable: {
1883
+ ...state.droppable,
1884
+ containers
1885
+ }
1886
+ };
1887
+ }
1888
+ case Action.SetDroppableDisabled: {
1889
+ const { id, key, disabled } = action;
1890
+ const element = state.droppable.containers.get(id);
1891
+ if (!element || key !== element.key) return state;
1892
+ const containers = new DroppableContainersMap(state.droppable.containers);
1893
+ containers.set(id, {
1894
+ ...element,
1895
+ disabled
1896
+ });
1897
+ return {
1898
+ ...state,
1899
+ droppable: {
1900
+ ...state.droppable,
1901
+ containers
1902
+ }
1903
+ };
1904
+ }
1905
+ case Action.UnregisterDroppable: {
1906
+ const { id, key } = action;
1907
+ const element = state.droppable.containers.get(id);
1908
+ if (!element || key !== element.key) return state;
1909
+ const containers = new DroppableContainersMap(state.droppable.containers);
1910
+ containers.delete(id);
1911
+ return {
1912
+ ...state,
1913
+ droppable: {
1914
+ ...state.droppable,
1915
+ containers
1916
+ }
1917
+ };
1918
+ }
1919
+ default: return state;
1920
+ }
1921
+ }
1922
+ function RestoreFocus(_ref) {
1923
+ let { disabled } = _ref;
1924
+ const { active, activatorEvent, draggableNodes } = (0, import_react.useContext)(InternalContext);
1925
+ const previousActivatorEvent = usePrevious(activatorEvent);
1926
+ const previousActiveId = usePrevious(active == null ? void 0 : active.id);
1927
+ (0, import_react.useEffect)(() => {
1928
+ if (disabled) return;
1929
+ if (!activatorEvent && previousActivatorEvent && previousActiveId != null) {
1930
+ if (!isKeyboardEvent(previousActivatorEvent)) return;
1931
+ if (document.activeElement === previousActivatorEvent.target) return;
1932
+ const draggableNode = draggableNodes.get(previousActiveId);
1933
+ if (!draggableNode) return;
1934
+ const { activatorNode, node } = draggableNode;
1935
+ if (!activatorNode.current && !node.current) return;
1936
+ requestAnimationFrame(() => {
1937
+ for (const element of [activatorNode.current, node.current]) {
1938
+ if (!element) continue;
1939
+ const focusableNode = findFirstFocusableNode(element);
1940
+ if (focusableNode) {
1941
+ focusableNode.focus();
1942
+ break;
1943
+ }
1944
+ }
1945
+ });
1946
+ }
1947
+ }, [
1948
+ activatorEvent,
1949
+ disabled,
1950
+ draggableNodes,
1951
+ previousActiveId,
1952
+ previousActivatorEvent
1953
+ ]);
1954
+ return null;
1955
+ }
1956
+ function applyModifiers(modifiers, _ref) {
1957
+ let { transform, ...args } = _ref;
1958
+ return modifiers != null && modifiers.length ? modifiers.reduce((accumulator, modifier) => {
1959
+ return modifier({
1960
+ transform: accumulator,
1961
+ ...args
1962
+ });
1963
+ }, transform) : transform;
1964
+ }
1965
+ function useMeasuringConfiguration(config) {
1966
+ return (0, import_react.useMemo)(() => ({
1967
+ draggable: {
1968
+ ...defaultMeasuringConfiguration.draggable,
1969
+ ...config == null ? void 0 : config.draggable
1970
+ },
1971
+ droppable: {
1972
+ ...defaultMeasuringConfiguration.droppable,
1973
+ ...config == null ? void 0 : config.droppable
1974
+ },
1975
+ dragOverlay: {
1976
+ ...defaultMeasuringConfiguration.dragOverlay,
1977
+ ...config == null ? void 0 : config.dragOverlay
1978
+ }
1979
+ }), [
1980
+ config == null ? void 0 : config.draggable,
1981
+ config == null ? void 0 : config.droppable,
1982
+ config == null ? void 0 : config.dragOverlay
1983
+ ]);
1984
+ }
1985
+ function useLayoutShiftScrollCompensation(_ref) {
1986
+ let { activeNode, measure, initialRect, config = true } = _ref;
1987
+ const initialized = (0, import_react.useRef)(false);
1988
+ const { x, y } = typeof config === "boolean" ? {
1989
+ x: config,
1990
+ y: config
1991
+ } : config;
1992
+ useIsomorphicLayoutEffect(() => {
1993
+ if (!x && !y || !activeNode) {
1994
+ initialized.current = false;
1995
+ return;
1996
+ }
1997
+ if (initialized.current || !initialRect) return;
1998
+ const node = activeNode == null ? void 0 : activeNode.node.current;
1999
+ if (!node || node.isConnected === false) return;
2000
+ const rectDelta = getRectDelta(measure(node), initialRect);
2001
+ if (!x) rectDelta.x = 0;
2002
+ if (!y) rectDelta.y = 0;
2003
+ initialized.current = true;
2004
+ if (Math.abs(rectDelta.x) > 0 || Math.abs(rectDelta.y) > 0) {
2005
+ const firstScrollableAncestor = getFirstScrollableAncestor(node);
2006
+ if (firstScrollableAncestor) firstScrollableAncestor.scrollBy({
2007
+ top: rectDelta.y,
2008
+ left: rectDelta.x
2009
+ });
2010
+ }
2011
+ }, [
2012
+ activeNode,
2013
+ x,
2014
+ y,
2015
+ initialRect,
2016
+ measure
2017
+ ]);
2018
+ }
2019
+ var ActiveDraggableContext = /*#__PURE__*/ (0, import_react.createContext)({
2020
+ ...defaultCoordinates,
2021
+ scaleX: 1,
2022
+ scaleY: 1
2023
+ });
2024
+ var Status;
2025
+ (function(Status) {
2026
+ Status[Status["Uninitialized"] = 0] = "Uninitialized";
2027
+ Status[Status["Initializing"] = 1] = "Initializing";
2028
+ Status[Status["Initialized"] = 2] = "Initialized";
2029
+ })(Status || (Status = {}));
2030
+ var DndContext = /*#__PURE__*/ (0, import_react.memo)(function DndContext(_ref) {
2031
+ var _sensorContext$curren, _dragOverlay$nodeRef$, _dragOverlay$rect, _over$rect;
2032
+ let { id, accessibility, autoScroll = true, children, sensors = defaultSensors, collisionDetection = rectIntersection, measuring, modifiers, ...props } = _ref;
2033
+ const [state, dispatch] = (0, import_react.useReducer)(reducer, void 0, getInitialState);
2034
+ const [dispatchMonitorEvent, registerMonitorListener] = useDndMonitorProvider();
2035
+ const [status, setStatus] = (0, import_react.useState)(Status.Uninitialized);
2036
+ const isInitialized = status === Status.Initialized;
2037
+ const { draggable: { active: activeId, nodes: draggableNodes, translate }, droppable: { containers: droppableContainers } } = state;
2038
+ const node = activeId != null ? draggableNodes.get(activeId) : null;
2039
+ const activeRects = (0, import_react.useRef)({
2040
+ initial: null,
2041
+ translated: null
2042
+ });
2043
+ const active = (0, import_react.useMemo)(() => {
2044
+ var _node$data;
2045
+ return activeId != null ? {
2046
+ id: activeId,
2047
+ data: (_node$data = node == null ? void 0 : node.data) != null ? _node$data : defaultData,
2048
+ rect: activeRects
2049
+ } : null;
2050
+ }, [activeId, node]);
2051
+ const activeRef = (0, import_react.useRef)(null);
2052
+ const [activeSensor, setActiveSensor] = (0, import_react.useState)(null);
2053
+ const [activatorEvent, setActivatorEvent] = (0, import_react.useState)(null);
2054
+ const latestProps = useLatestValue(props, Object.values(props));
2055
+ const draggableDescribedById = useUniqueId("DndDescribedBy", id);
2056
+ const enabledDroppableContainers = (0, import_react.useMemo)(() => droppableContainers.getEnabled(), [droppableContainers]);
2057
+ const measuringConfiguration = useMeasuringConfiguration(measuring);
2058
+ const { droppableRects, measureDroppableContainers, measuringScheduled } = useDroppableMeasuring(enabledDroppableContainers, {
2059
+ dragging: isInitialized,
2060
+ dependencies: [translate.x, translate.y],
2061
+ config: measuringConfiguration.droppable
2062
+ });
2063
+ const activeNode = useCachedNode(draggableNodes, activeId);
2064
+ const activationCoordinates = (0, import_react.useMemo)(() => activatorEvent ? getEventCoordinates(activatorEvent) : null, [activatorEvent]);
2065
+ const autoScrollOptions = getAutoScrollerOptions();
2066
+ const initialActiveNodeRect = useInitialRect(activeNode, measuringConfiguration.draggable.measure);
2067
+ useLayoutShiftScrollCompensation({
2068
+ activeNode: activeId != null ? draggableNodes.get(activeId) : null,
2069
+ config: autoScrollOptions.layoutShiftCompensation,
2070
+ initialRect: initialActiveNodeRect,
2071
+ measure: measuringConfiguration.draggable.measure
2072
+ });
2073
+ const activeNodeRect = useRect(activeNode, measuringConfiguration.draggable.measure, initialActiveNodeRect);
2074
+ const containerNodeRect = useRect(activeNode ? activeNode.parentElement : null);
2075
+ const sensorContext = (0, import_react.useRef)({
2076
+ activatorEvent: null,
2077
+ active: null,
2078
+ activeNode,
2079
+ collisionRect: null,
2080
+ collisions: null,
2081
+ droppableRects,
2082
+ draggableNodes,
2083
+ draggingNode: null,
2084
+ draggingNodeRect: null,
2085
+ droppableContainers,
2086
+ over: null,
2087
+ scrollableAncestors: [],
2088
+ scrollAdjustedTranslate: null
2089
+ });
2090
+ const overNode = droppableContainers.getNodeFor((_sensorContext$curren = sensorContext.current.over) == null ? void 0 : _sensorContext$curren.id);
2091
+ const dragOverlay = useDragOverlayMeasuring({ measure: measuringConfiguration.dragOverlay.measure });
2092
+ const draggingNode = (_dragOverlay$nodeRef$ = dragOverlay.nodeRef.current) != null ? _dragOverlay$nodeRef$ : activeNode;
2093
+ const draggingNodeRect = isInitialized ? (_dragOverlay$rect = dragOverlay.rect) != null ? _dragOverlay$rect : activeNodeRect : null;
2094
+ const usesDragOverlay = Boolean(dragOverlay.nodeRef.current && dragOverlay.rect);
2095
+ const nodeRectDelta = useRectDelta(usesDragOverlay ? null : activeNodeRect);
2096
+ const windowRect = useWindowRect(draggingNode ? getWindow(draggingNode) : null);
2097
+ const scrollableAncestors = useScrollableAncestors(isInitialized ? overNode != null ? overNode : activeNode : null);
2098
+ const scrollableAncestorRects = useRects(scrollableAncestors);
2099
+ const modifiedTranslate = applyModifiers(modifiers, {
2100
+ transform: {
2101
+ x: translate.x - nodeRectDelta.x,
2102
+ y: translate.y - nodeRectDelta.y,
2103
+ scaleX: 1,
2104
+ scaleY: 1
2105
+ },
2106
+ activatorEvent,
2107
+ active,
2108
+ activeNodeRect,
2109
+ containerNodeRect,
2110
+ draggingNodeRect,
2111
+ over: sensorContext.current.over,
2112
+ overlayNodeRect: dragOverlay.rect,
2113
+ scrollableAncestors,
2114
+ scrollableAncestorRects,
2115
+ windowRect
2116
+ });
2117
+ const pointerCoordinates = activationCoordinates ? add(activationCoordinates, translate) : null;
2118
+ const scrollOffsets = useScrollOffsets(scrollableAncestors);
2119
+ const scrollAdjustment = useScrollOffsetsDelta(scrollOffsets);
2120
+ const activeNodeScrollDelta = useScrollOffsetsDelta(scrollOffsets, [activeNodeRect]);
2121
+ const scrollAdjustedTranslate = add(modifiedTranslate, scrollAdjustment);
2122
+ const collisionRect = draggingNodeRect ? getAdjustedRect(draggingNodeRect, modifiedTranslate) : null;
2123
+ const collisions = active && collisionRect ? collisionDetection({
2124
+ active,
2125
+ collisionRect,
2126
+ droppableRects,
2127
+ droppableContainers: enabledDroppableContainers,
2128
+ pointerCoordinates
2129
+ }) : null;
2130
+ const overId = getFirstCollision(collisions, "id");
2131
+ const [over, setOver] = (0, import_react.useState)(null);
2132
+ const transform = adjustScale(usesDragOverlay ? modifiedTranslate : add(modifiedTranslate, activeNodeScrollDelta), (_over$rect = over == null ? void 0 : over.rect) != null ? _over$rect : null, activeNodeRect);
2133
+ const activeSensorRef = (0, import_react.useRef)(null);
2134
+ const instantiateSensor = (0, import_react.useCallback)((event, _ref2) => {
2135
+ let { sensor: Sensor, options } = _ref2;
2136
+ if (activeRef.current == null) return;
2137
+ const activeNode = draggableNodes.get(activeRef.current);
2138
+ if (!activeNode) return;
2139
+ const activatorEvent = event.nativeEvent;
2140
+ const sensorInstance = new Sensor({
2141
+ active: activeRef.current,
2142
+ activeNode,
2143
+ event: activatorEvent,
2144
+ options,
2145
+ context: sensorContext,
2146
+ onAbort(id) {
2147
+ if (!draggableNodes.get(id)) return;
2148
+ const { onDragAbort } = latestProps.current;
2149
+ const event = { id };
2150
+ onDragAbort?.(event);
2151
+ dispatchMonitorEvent({
2152
+ type: "onDragAbort",
2153
+ event
2154
+ });
2155
+ },
2156
+ onPending(id, constraint, initialCoordinates, offset) {
2157
+ if (!draggableNodes.get(id)) return;
2158
+ const { onDragPending } = latestProps.current;
2159
+ const event = {
2160
+ id,
2161
+ constraint,
2162
+ initialCoordinates,
2163
+ offset
2164
+ };
2165
+ onDragPending?.(event);
2166
+ dispatchMonitorEvent({
2167
+ type: "onDragPending",
2168
+ event
2169
+ });
2170
+ },
2171
+ onStart(initialCoordinates) {
2172
+ const id = activeRef.current;
2173
+ if (id == null) return;
2174
+ const draggableNode = draggableNodes.get(id);
2175
+ if (!draggableNode) return;
2176
+ const { onDragStart } = latestProps.current;
2177
+ const event = {
2178
+ activatorEvent,
2179
+ active: {
2180
+ id,
2181
+ data: draggableNode.data,
2182
+ rect: activeRects
2183
+ }
2184
+ };
2185
+ (0, import_react_dom.unstable_batchedUpdates)(() => {
2186
+ onDragStart?.(event);
2187
+ setStatus(Status.Initializing);
2188
+ dispatch({
2189
+ type: Action.DragStart,
2190
+ initialCoordinates,
2191
+ active: id
2192
+ });
2193
+ dispatchMonitorEvent({
2194
+ type: "onDragStart",
2195
+ event
2196
+ });
2197
+ setActiveSensor(activeSensorRef.current);
2198
+ setActivatorEvent(activatorEvent);
2199
+ });
2200
+ },
2201
+ onMove(coordinates) {
2202
+ dispatch({
2203
+ type: Action.DragMove,
2204
+ coordinates
2205
+ });
2206
+ },
2207
+ onEnd: createHandler(Action.DragEnd),
2208
+ onCancel: createHandler(Action.DragCancel)
2209
+ });
2210
+ activeSensorRef.current = sensorInstance;
2211
+ function createHandler(type) {
2212
+ return async function handler() {
2213
+ const { active, collisions, over, scrollAdjustedTranslate } = sensorContext.current;
2214
+ let event = null;
2215
+ if (active && scrollAdjustedTranslate) {
2216
+ const { cancelDrop } = latestProps.current;
2217
+ event = {
2218
+ activatorEvent,
2219
+ active,
2220
+ collisions,
2221
+ delta: scrollAdjustedTranslate,
2222
+ over
2223
+ };
2224
+ if (type === Action.DragEnd && typeof cancelDrop === "function") {
2225
+ if (await Promise.resolve(cancelDrop(event))) type = Action.DragCancel;
2226
+ }
2227
+ }
2228
+ activeRef.current = null;
2229
+ (0, import_react_dom.unstable_batchedUpdates)(() => {
2230
+ dispatch({ type });
2231
+ setStatus(Status.Uninitialized);
2232
+ setOver(null);
2233
+ setActiveSensor(null);
2234
+ setActivatorEvent(null);
2235
+ activeSensorRef.current = null;
2236
+ const eventName = type === Action.DragEnd ? "onDragEnd" : "onDragCancel";
2237
+ if (event) {
2238
+ const handler = latestProps.current[eventName];
2239
+ handler?.(event);
2240
+ dispatchMonitorEvent({
2241
+ type: eventName,
2242
+ event
2243
+ });
2244
+ }
2245
+ });
2246
+ };
2247
+ }
2248
+ }, [draggableNodes]);
2249
+ const activators = useCombineActivators(sensors, (0, import_react.useCallback)((handler, sensor) => {
2250
+ return (event, active) => {
2251
+ const nativeEvent = event.nativeEvent;
2252
+ const activeDraggableNode = draggableNodes.get(active);
2253
+ if (activeRef.current !== null || !activeDraggableNode || nativeEvent.dndKit || nativeEvent.defaultPrevented) return;
2254
+ const activationContext = { active: activeDraggableNode };
2255
+ if (handler(event, sensor.options, activationContext) === true) {
2256
+ nativeEvent.dndKit = { capturedBy: sensor.sensor };
2257
+ activeRef.current = active;
2258
+ instantiateSensor(event, sensor);
2259
+ }
2260
+ };
2261
+ }, [draggableNodes, instantiateSensor]));
2262
+ useSensorSetup(sensors);
2263
+ useIsomorphicLayoutEffect(() => {
2264
+ if (activeNodeRect && status === Status.Initializing) setStatus(Status.Initialized);
2265
+ }, [activeNodeRect, status]);
2266
+ (0, import_react.useEffect)(() => {
2267
+ const { onDragMove } = latestProps.current;
2268
+ const { active, activatorEvent, collisions, over } = sensorContext.current;
2269
+ if (!active || !activatorEvent) return;
2270
+ const event = {
2271
+ active,
2272
+ activatorEvent,
2273
+ collisions,
2274
+ delta: {
2275
+ x: scrollAdjustedTranslate.x,
2276
+ y: scrollAdjustedTranslate.y
2277
+ },
2278
+ over
2279
+ };
2280
+ (0, import_react_dom.unstable_batchedUpdates)(() => {
2281
+ onDragMove?.(event);
2282
+ dispatchMonitorEvent({
2283
+ type: "onDragMove",
2284
+ event
2285
+ });
2286
+ });
2287
+ }, [scrollAdjustedTranslate.x, scrollAdjustedTranslate.y]);
2288
+ (0, import_react.useEffect)(() => {
2289
+ const { active, activatorEvent, collisions, droppableContainers, scrollAdjustedTranslate } = sensorContext.current;
2290
+ if (!active || activeRef.current == null || !activatorEvent || !scrollAdjustedTranslate) return;
2291
+ const { onDragOver } = latestProps.current;
2292
+ const overContainer = droppableContainers.get(overId);
2293
+ const over = overContainer && overContainer.rect.current ? {
2294
+ id: overContainer.id,
2295
+ rect: overContainer.rect.current,
2296
+ data: overContainer.data,
2297
+ disabled: overContainer.disabled
2298
+ } : null;
2299
+ const event = {
2300
+ active,
2301
+ activatorEvent,
2302
+ collisions,
2303
+ delta: {
2304
+ x: scrollAdjustedTranslate.x,
2305
+ y: scrollAdjustedTranslate.y
2306
+ },
2307
+ over
2308
+ };
2309
+ (0, import_react_dom.unstable_batchedUpdates)(() => {
2310
+ setOver(over);
2311
+ onDragOver?.(event);
2312
+ dispatchMonitorEvent({
2313
+ type: "onDragOver",
2314
+ event
2315
+ });
2316
+ });
2317
+ }, [overId]);
2318
+ useIsomorphicLayoutEffect(() => {
2319
+ sensorContext.current = {
2320
+ activatorEvent,
2321
+ active,
2322
+ activeNode,
2323
+ collisionRect,
2324
+ collisions,
2325
+ droppableRects,
2326
+ draggableNodes,
2327
+ draggingNode,
2328
+ draggingNodeRect,
2329
+ droppableContainers,
2330
+ over,
2331
+ scrollableAncestors,
2332
+ scrollAdjustedTranslate
2333
+ };
2334
+ activeRects.current = {
2335
+ initial: draggingNodeRect,
2336
+ translated: collisionRect
2337
+ };
2338
+ }, [
2339
+ active,
2340
+ activeNode,
2341
+ collisions,
2342
+ collisionRect,
2343
+ draggableNodes,
2344
+ draggingNode,
2345
+ draggingNodeRect,
2346
+ droppableRects,
2347
+ droppableContainers,
2348
+ over,
2349
+ scrollableAncestors,
2350
+ scrollAdjustedTranslate
2351
+ ]);
2352
+ useAutoScroller({
2353
+ ...autoScrollOptions,
2354
+ delta: translate,
2355
+ draggingRect: collisionRect,
2356
+ pointerCoordinates,
2357
+ scrollableAncestors,
2358
+ scrollableAncestorRects
2359
+ });
2360
+ const publicContext = (0, import_react.useMemo)(() => {
2361
+ return {
2362
+ active,
2363
+ activeNode,
2364
+ activeNodeRect,
2365
+ activatorEvent,
2366
+ collisions,
2367
+ containerNodeRect,
2368
+ dragOverlay,
2369
+ draggableNodes,
2370
+ droppableContainers,
2371
+ droppableRects,
2372
+ over,
2373
+ measureDroppableContainers,
2374
+ scrollableAncestors,
2375
+ scrollableAncestorRects,
2376
+ measuringConfiguration,
2377
+ measuringScheduled,
2378
+ windowRect
2379
+ };
2380
+ }, [
2381
+ active,
2382
+ activeNode,
2383
+ activeNodeRect,
2384
+ activatorEvent,
2385
+ collisions,
2386
+ containerNodeRect,
2387
+ dragOverlay,
2388
+ draggableNodes,
2389
+ droppableContainers,
2390
+ droppableRects,
2391
+ over,
2392
+ measureDroppableContainers,
2393
+ scrollableAncestors,
2394
+ scrollableAncestorRects,
2395
+ measuringConfiguration,
2396
+ measuringScheduled,
2397
+ windowRect
2398
+ ]);
2399
+ const internalContext = (0, import_react.useMemo)(() => {
2400
+ return {
2401
+ activatorEvent,
2402
+ activators,
2403
+ active,
2404
+ activeNodeRect,
2405
+ ariaDescribedById: { draggable: draggableDescribedById },
2406
+ dispatch,
2407
+ draggableNodes,
2408
+ over,
2409
+ measureDroppableContainers
2410
+ };
2411
+ }, [
2412
+ activatorEvent,
2413
+ activators,
2414
+ active,
2415
+ activeNodeRect,
2416
+ dispatch,
2417
+ draggableDescribedById,
2418
+ draggableNodes,
2419
+ over,
2420
+ measureDroppableContainers
2421
+ ]);
2422
+ return import_react.createElement(DndMonitorContext.Provider, { value: registerMonitorListener }, import_react.createElement(InternalContext.Provider, { value: internalContext }, import_react.createElement(PublicContext.Provider, { value: publicContext }, import_react.createElement(ActiveDraggableContext.Provider, { value: transform }, children)), import_react.createElement(RestoreFocus, { disabled: (accessibility == null ? void 0 : accessibility.restoreFocus) === false })), import_react.createElement(Accessibility, {
2423
+ ...accessibility,
2424
+ hiddenTextDescribedById: draggableDescribedById
2425
+ }));
2426
+ function getAutoScrollerOptions() {
2427
+ const activeSensorDisablesAutoscroll = (activeSensor == null ? void 0 : activeSensor.autoScrollEnabled) === false;
2428
+ const autoScrollGloballyDisabled = typeof autoScroll === "object" ? autoScroll.enabled === false : autoScroll === false;
2429
+ const enabled = isInitialized && !activeSensorDisablesAutoscroll && !autoScrollGloballyDisabled;
2430
+ if (typeof autoScroll === "object") return {
2431
+ ...autoScroll,
2432
+ enabled
2433
+ };
2434
+ return { enabled };
2435
+ }
2436
+ });
2437
+ var NullContext = /*#__PURE__*/ (0, import_react.createContext)(null);
2438
+ var defaultRole = "button";
2439
+ var ID_PREFIX = "Draggable";
2440
+ function useDraggable(_ref) {
2441
+ let { id, data, disabled = false, attributes } = _ref;
2442
+ const key = useUniqueId(ID_PREFIX);
2443
+ const { activators, activatorEvent, active, activeNodeRect, ariaDescribedById, draggableNodes, over } = (0, import_react.useContext)(InternalContext);
2444
+ const { role = defaultRole, roleDescription = "draggable", tabIndex = 0 } = attributes != null ? attributes : {};
2445
+ const isDragging = (active == null ? void 0 : active.id) === id;
2446
+ const transform = (0, import_react.useContext)(isDragging ? ActiveDraggableContext : NullContext);
2447
+ const [node, setNodeRef] = useNodeRef();
2448
+ const [activatorNode, setActivatorNodeRef] = useNodeRef();
2449
+ const listeners = useSyntheticListeners(activators, id);
2450
+ const dataRef = useLatestValue(data);
2451
+ useIsomorphicLayoutEffect(() => {
2452
+ draggableNodes.set(id, {
2453
+ id,
2454
+ key,
2455
+ node,
2456
+ activatorNode,
2457
+ data: dataRef
2458
+ });
2459
+ return () => {
2460
+ const node = draggableNodes.get(id);
2461
+ if (node && node.key === key) draggableNodes.delete(id);
2462
+ };
2463
+ }, [draggableNodes, id]);
2464
+ return {
2465
+ active,
2466
+ activatorEvent,
2467
+ activeNodeRect,
2468
+ attributes: (0, import_react.useMemo)(() => ({
2469
+ role,
2470
+ tabIndex,
2471
+ "aria-disabled": disabled,
2472
+ "aria-pressed": isDragging && role === defaultRole ? true : void 0,
2473
+ "aria-roledescription": roleDescription,
2474
+ "aria-describedby": ariaDescribedById.draggable
2475
+ }), [
2476
+ disabled,
2477
+ role,
2478
+ tabIndex,
2479
+ isDragging,
2480
+ roleDescription,
2481
+ ariaDescribedById.draggable
2482
+ ]),
2483
+ isDragging,
2484
+ listeners: disabled ? void 0 : listeners,
2485
+ node,
2486
+ over,
2487
+ setNodeRef,
2488
+ setActivatorNodeRef,
2489
+ transform
2490
+ };
2491
+ }
2492
+ function useDndContext() {
2493
+ return (0, import_react.useContext)(PublicContext);
2494
+ }
2495
+ var ID_PREFIX$1 = "Droppable";
2496
+ var defaultResizeObserverConfig = { timeout: 25 };
2497
+ function useDroppable(_ref) {
2498
+ let { data, disabled = false, id, resizeObserverConfig } = _ref;
2499
+ const key = useUniqueId(ID_PREFIX$1);
2500
+ const { active, dispatch, over, measureDroppableContainers } = (0, import_react.useContext)(InternalContext);
2501
+ const previous = (0, import_react.useRef)({ disabled });
2502
+ const resizeObserverConnected = (0, import_react.useRef)(false);
2503
+ const rect = (0, import_react.useRef)(null);
2504
+ const callbackId = (0, import_react.useRef)(null);
2505
+ const { disabled: resizeObserverDisabled, updateMeasurementsFor, timeout: resizeObserverTimeout } = {
2506
+ ...defaultResizeObserverConfig,
2507
+ ...resizeObserverConfig
2508
+ };
2509
+ const ids = useLatestValue(updateMeasurementsFor != null ? updateMeasurementsFor : id);
2510
+ const resizeObserver = useResizeObserver({
2511
+ callback: (0, import_react.useCallback)(() => {
2512
+ if (!resizeObserverConnected.current) {
2513
+ resizeObserverConnected.current = true;
2514
+ return;
2515
+ }
2516
+ if (callbackId.current != null) clearTimeout(callbackId.current);
2517
+ callbackId.current = setTimeout(() => {
2518
+ measureDroppableContainers(Array.isArray(ids.current) ? ids.current : [ids.current]);
2519
+ callbackId.current = null;
2520
+ }, resizeObserverTimeout);
2521
+ }, [resizeObserverTimeout]),
2522
+ disabled: resizeObserverDisabled || !active
2523
+ });
2524
+ const [nodeRef, setNodeRef] = useNodeRef((0, import_react.useCallback)((newElement, previousElement) => {
2525
+ if (!resizeObserver) return;
2526
+ if (previousElement) {
2527
+ resizeObserver.unobserve(previousElement);
2528
+ resizeObserverConnected.current = false;
2529
+ }
2530
+ if (newElement) resizeObserver.observe(newElement);
2531
+ }, [resizeObserver]));
2532
+ const dataRef = useLatestValue(data);
2533
+ (0, import_react.useEffect)(() => {
2534
+ if (!resizeObserver || !nodeRef.current) return;
2535
+ resizeObserver.disconnect();
2536
+ resizeObserverConnected.current = false;
2537
+ resizeObserver.observe(nodeRef.current);
2538
+ }, [nodeRef, resizeObserver]);
2539
+ (0, import_react.useEffect)(() => {
2540
+ dispatch({
2541
+ type: Action.RegisterDroppable,
2542
+ element: {
2543
+ id,
2544
+ key,
2545
+ disabled,
2546
+ node: nodeRef,
2547
+ rect,
2548
+ data: dataRef
2549
+ }
2550
+ });
2551
+ return () => dispatch({
2552
+ type: Action.UnregisterDroppable,
2553
+ key,
2554
+ id
2555
+ });
2556
+ }, [id]);
2557
+ (0, import_react.useEffect)(() => {
2558
+ if (disabled !== previous.current.disabled) {
2559
+ dispatch({
2560
+ type: Action.SetDroppableDisabled,
2561
+ id,
2562
+ key,
2563
+ disabled
2564
+ });
2565
+ previous.current.disabled = disabled;
2566
+ }
2567
+ }, [
2568
+ id,
2569
+ key,
2570
+ disabled,
2571
+ dispatch
2572
+ ]);
2573
+ return {
2574
+ active,
2575
+ rect,
2576
+ isOver: (over == null ? void 0 : over.id) === id,
2577
+ node: nodeRef,
2578
+ over,
2579
+ setNodeRef
2580
+ };
2581
+ }
2582
+ function AnimationManager(_ref) {
2583
+ let { animation, children } = _ref;
2584
+ const [clonedChildren, setClonedChildren] = (0, import_react.useState)(null);
2585
+ const [element, setElement] = (0, import_react.useState)(null);
2586
+ const previousChildren = usePrevious(children);
2587
+ if (!children && !clonedChildren && previousChildren) setClonedChildren(previousChildren);
2588
+ useIsomorphicLayoutEffect(() => {
2589
+ if (!element) return;
2590
+ const key = clonedChildren == null ? void 0 : clonedChildren.key;
2591
+ const id = clonedChildren == null ? void 0 : clonedChildren.props.id;
2592
+ if (key == null || id == null) {
2593
+ setClonedChildren(null);
2594
+ return;
2595
+ }
2596
+ Promise.resolve(animation(id, element)).then(() => {
2597
+ setClonedChildren(null);
2598
+ });
2599
+ }, [
2600
+ animation,
2601
+ clonedChildren,
2602
+ element
2603
+ ]);
2604
+ return import_react.createElement(import_react.Fragment, null, children, clonedChildren ? (0, import_react.cloneElement)(clonedChildren, { ref: setElement }) : null);
2605
+ }
2606
+ var defaultTransform = {
2607
+ x: 0,
2608
+ y: 0,
2609
+ scaleX: 1,
2610
+ scaleY: 1
2611
+ };
2612
+ function NullifiedContextProvider(_ref) {
2613
+ let { children } = _ref;
2614
+ return import_react.createElement(InternalContext.Provider, { value: defaultInternalContext }, import_react.createElement(ActiveDraggableContext.Provider, { value: defaultTransform }, children));
2615
+ }
2616
+ var baseStyles = {
2617
+ position: "fixed",
2618
+ touchAction: "none"
2619
+ };
2620
+ var defaultTransition = (activatorEvent) => {
2621
+ return isKeyboardEvent(activatorEvent) ? "transform 250ms ease" : void 0;
2622
+ };
2623
+ var PositionedOverlay = /*#__PURE__*/ (0, import_react.forwardRef)((_ref, ref) => {
2624
+ let { as, activatorEvent, adjustScale, children, className, rect, style, transform, transition = defaultTransition } = _ref;
2625
+ if (!rect) return null;
2626
+ const scaleAdjustedTransform = adjustScale ? transform : {
2627
+ ...transform,
2628
+ scaleX: 1,
2629
+ scaleY: 1
2630
+ };
2631
+ const styles = {
2632
+ ...baseStyles,
2633
+ width: rect.width,
2634
+ height: rect.height,
2635
+ top: rect.top,
2636
+ left: rect.left,
2637
+ transform: CSS$1.Transform.toString(scaleAdjustedTransform),
2638
+ transformOrigin: adjustScale && activatorEvent ? getRelativeTransformOrigin(activatorEvent, rect) : void 0,
2639
+ transition: typeof transition === "function" ? transition(activatorEvent) : transition,
2640
+ ...style
2641
+ };
2642
+ return import_react.createElement(as, {
2643
+ className,
2644
+ style: styles,
2645
+ ref
2646
+ }, children);
2647
+ });
2648
+ var defaultDropAnimationSideEffects = (options) => (_ref) => {
2649
+ let { active, dragOverlay } = _ref;
2650
+ const originalStyles = {};
2651
+ const { styles, className } = options;
2652
+ if (styles != null && styles.active) for (const [key, value] of Object.entries(styles.active)) {
2653
+ if (value === void 0) continue;
2654
+ originalStyles[key] = active.node.style.getPropertyValue(key);
2655
+ active.node.style.setProperty(key, value);
2656
+ }
2657
+ if (styles != null && styles.dragOverlay) for (const [key, value] of Object.entries(styles.dragOverlay)) {
2658
+ if (value === void 0) continue;
2659
+ dragOverlay.node.style.setProperty(key, value);
2660
+ }
2661
+ if (className != null && className.active) active.node.classList.add(className.active);
2662
+ if (className != null && className.dragOverlay) dragOverlay.node.classList.add(className.dragOverlay);
2663
+ return function cleanup() {
2664
+ for (const [key, value] of Object.entries(originalStyles)) active.node.style.setProperty(key, value);
2665
+ if (className != null && className.active) active.node.classList.remove(className.active);
2666
+ };
2667
+ };
2668
+ var defaultKeyframeResolver = (_ref2) => {
2669
+ let { transform: { initial, final } } = _ref2;
2670
+ return [{ transform: CSS$1.Transform.toString(initial) }, { transform: CSS$1.Transform.toString(final) }];
2671
+ };
2672
+ var defaultDropAnimationConfiguration = {
2673
+ duration: 250,
2674
+ easing: "ease",
2675
+ keyframes: defaultKeyframeResolver,
2676
+ sideEffects: /*#__PURE__*/ defaultDropAnimationSideEffects({ styles: { active: { opacity: "0" } } })
2677
+ };
2678
+ function useDropAnimation(_ref3) {
2679
+ let { config, draggableNodes, droppableContainers, measuringConfiguration } = _ref3;
2680
+ return useEvent((id, node) => {
2681
+ if (config === null) return;
2682
+ const activeDraggable = draggableNodes.get(id);
2683
+ if (!activeDraggable) return;
2684
+ const activeNode = activeDraggable.node.current;
2685
+ if (!activeNode) return;
2686
+ const measurableNode = getMeasurableNode(node);
2687
+ if (!measurableNode) return;
2688
+ const { transform } = getWindow(node).getComputedStyle(node);
2689
+ const parsedTransform = parseTransform(transform);
2690
+ if (!parsedTransform) return;
2691
+ const animation = typeof config === "function" ? config : createDefaultDropAnimation(config);
2692
+ scrollIntoViewIfNeeded(activeNode, measuringConfiguration.draggable.measure);
2693
+ return animation({
2694
+ active: {
2695
+ id,
2696
+ data: activeDraggable.data,
2697
+ node: activeNode,
2698
+ rect: measuringConfiguration.draggable.measure(activeNode)
2699
+ },
2700
+ draggableNodes,
2701
+ dragOverlay: {
2702
+ node,
2703
+ rect: measuringConfiguration.dragOverlay.measure(measurableNode)
2704
+ },
2705
+ droppableContainers,
2706
+ measuringConfiguration,
2707
+ transform: parsedTransform
2708
+ });
2709
+ });
2710
+ }
2711
+ function createDefaultDropAnimation(options) {
2712
+ const { duration, easing, sideEffects, keyframes } = {
2713
+ ...defaultDropAnimationConfiguration,
2714
+ ...options
2715
+ };
2716
+ return (_ref4) => {
2717
+ let { active, dragOverlay, transform, ...rest } = _ref4;
2718
+ if (!duration) return;
2719
+ const delta = {
2720
+ x: dragOverlay.rect.left - active.rect.left,
2721
+ y: dragOverlay.rect.top - active.rect.top
2722
+ };
2723
+ const scale = {
2724
+ scaleX: transform.scaleX !== 1 ? active.rect.width * transform.scaleX / dragOverlay.rect.width : 1,
2725
+ scaleY: transform.scaleY !== 1 ? active.rect.height * transform.scaleY / dragOverlay.rect.height : 1
2726
+ };
2727
+ const finalTransform = {
2728
+ x: transform.x - delta.x,
2729
+ y: transform.y - delta.y,
2730
+ ...scale
2731
+ };
2732
+ const animationKeyframes = keyframes({
2733
+ ...rest,
2734
+ active,
2735
+ dragOverlay,
2736
+ transform: {
2737
+ initial: transform,
2738
+ final: finalTransform
2739
+ }
2740
+ });
2741
+ const [firstKeyframe] = animationKeyframes;
2742
+ const lastKeyframe = animationKeyframes[animationKeyframes.length - 1];
2743
+ if (JSON.stringify(firstKeyframe) === JSON.stringify(lastKeyframe)) return;
2744
+ const cleanup = sideEffects == null ? void 0 : sideEffects({
2745
+ active,
2746
+ dragOverlay,
2747
+ ...rest
2748
+ });
2749
+ const animation = dragOverlay.node.animate(animationKeyframes, {
2750
+ duration,
2751
+ easing,
2752
+ fill: "forwards"
2753
+ });
2754
+ return new Promise((resolve) => {
2755
+ animation.onfinish = () => {
2756
+ cleanup?.();
2757
+ resolve();
2758
+ };
2759
+ });
2760
+ };
2761
+ }
2762
+ var key = 0;
2763
+ function useKey(id) {
2764
+ return (0, import_react.useMemo)(() => {
2765
+ if (id == null) return;
2766
+ key++;
2767
+ return key;
2768
+ }, [id]);
2769
+ }
2770
+ var DragOverlay = /*#__PURE__*/ import_react.memo((_ref) => {
2771
+ let { adjustScale = false, children, dropAnimation: dropAnimationConfig, style, transition, modifiers, wrapperElement = "div", className, zIndex = 999 } = _ref;
2772
+ const { activatorEvent, active, activeNodeRect, containerNodeRect, draggableNodes, droppableContainers, dragOverlay, over, measuringConfiguration, scrollableAncestors, scrollableAncestorRects, windowRect } = useDndContext();
2773
+ const transform = (0, import_react.useContext)(ActiveDraggableContext);
2774
+ const key = useKey(active == null ? void 0 : active.id);
2775
+ const modifiedTransform = applyModifiers(modifiers, {
2776
+ activatorEvent,
2777
+ active,
2778
+ activeNodeRect,
2779
+ containerNodeRect,
2780
+ draggingNodeRect: dragOverlay.rect,
2781
+ over,
2782
+ overlayNodeRect: dragOverlay.rect,
2783
+ scrollableAncestors,
2784
+ scrollableAncestorRects,
2785
+ transform,
2786
+ windowRect
2787
+ });
2788
+ const initialRect = useInitialValue(activeNodeRect);
2789
+ const dropAnimation = useDropAnimation({
2790
+ config: dropAnimationConfig,
2791
+ draggableNodes,
2792
+ droppableContainers,
2793
+ measuringConfiguration
2794
+ });
2795
+ const ref = initialRect ? dragOverlay.setRef : void 0;
2796
+ return import_react.createElement(NullifiedContextProvider, null, import_react.createElement(AnimationManager, { animation: dropAnimation }, active && key ? import_react.createElement(PositionedOverlay, {
2797
+ key,
2798
+ id: active.id,
2799
+ ref,
2800
+ as: wrapperElement,
2801
+ activatorEvent,
2802
+ adjustScale,
2803
+ className,
2804
+ transition,
2805
+ rect: initialRect,
2806
+ style: {
2807
+ zIndex,
2808
+ ...style
2809
+ },
2810
+ transform: modifiedTransform
2811
+ }, children) : null));
2812
+ });
2813
+ // src/stores/work-ui.ts
2814
+ var useWorkUi = create()(persist((set) => ({
2815
+ drafts: {},
2816
+ setDraft: (companion, text) => set((state) => ({ drafts: {
2817
+ ...state.drafts,
2818
+ [companion]: text
2819
+ } })),
2820
+ dialog: null,
2821
+ open: (dialog) => set({
2822
+ dialog,
2823
+ focusAfter: null
2824
+ }),
2825
+ close: () => set({ dialog: null }),
2826
+ focusAfter: null,
2827
+ acted: (card) => set({
2828
+ dialog: null,
2829
+ focusAfter: card
2830
+ }),
2831
+ focused: () => set({ focusAfter: null }),
2832
+ expanded: {},
2833
+ toggle: (workset) => set((state) => ({ expanded: {
2834
+ ...state.expanded,
2835
+ [workset]: !state.expanded[workset]
2836
+ } }))
2837
+ }), {
2838
+ name: "mate.work.drafts",
2839
+ storage: createJSONStorage(() => sessionStorage),
2840
+ partialize: ({ drafts }) => ({ drafts })
2841
+ }));
2842
+ // src/views/work/work-card-model.ts
2843
+ var ACTION_LABELS = {
2844
+ share: "Share",
2845
+ claim: "Claim",
2846
+ "start-manual": "Continue manually",
2847
+ release: "Release"
2848
+ };
2849
+ function acceptedActions(card) {
2850
+ return Object.keys(ACTION_LABELS).filter((action) => card.actions[action] === null);
2851
+ }
2852
+ function dropTargetsOf(card) {
2853
+ const accepts = (action) => card.actions[action] === null;
2854
+ const targets = {};
2855
+ if (card.bucket === "local") {
2856
+ const remote = card.claim.kind === "mine" ? "release" : "share";
2857
+ if (accepts(remote)) targets.remote = remote;
2858
+ }
2859
+ if (card.bucket === "remote" && accepts("claim")) targets.local = "claim";
2860
+ return targets;
2861
+ }
2862
+ var DROP_VERBS = {
2863
+ share: "share it",
2864
+ release: "release your claim",
2865
+ claim: "claim it"
2866
+ };
2867
+ // src/views/work/work-card.tsx
2868
+ var import_jsx_runtime = require_jsx_runtime();
2869
+ var STAGE_MARKERS = {
2870
+ "clarify-intent": "idle",
2871
+ explore: "idle",
2872
+ propose: "idle",
2873
+ "human-review": "review",
2874
+ apply: "build",
2875
+ "merge-wait": "review",
2876
+ publish: "review",
2877
+ done: "done"
2878
+ };
2879
+ var PRIMARY = /* @__PURE__ */ new Set(["claim", "start-manual"]);
2880
+ function claimText(card) {
2881
+ switch (card.claim.kind) {
2882
+ case "mine": return `Claimed by you (${card.claim.label})`;
2883
+ case "other": return `Claimed by ${card.claim.label}`;
2884
+ case "none": return card.bucket === "remote" && card.progress.kind === "none" ? "Available" : null;
2885
+ case "conflict": return null;
2886
+ }
2887
+ }
2888
+ function progressText(card) {
2889
+ if (card.progress.kind === "here") return `In progress here on ${card.progress.branch}`;
2890
+ if (card.progress.kind === "elsewhere") return `In progress on ${card.progress.branch}`;
2891
+ return null;
2892
+ }
2893
+ var SYNC_NOTES = {
2894
+ ahead: "Local changes not shared",
2895
+ behind: "The shared version is newer; take it with mate artifact take",
2896
+ diverged: "Local and shared versions differ"
2897
+ };
2898
+ function sharingNotes(card) {
2899
+ const { sharing } = card;
2900
+ const shared = isShared(sharing.presence);
2901
+ const notes = [];
2902
+ if (shared && SYNC_NOTES[sharing.sync]) notes.push(SYNC_NOTES[sharing.sync]);
2903
+ if (sharing.remoteOnly) notes.push("Only on the inbox; take it with mate artifact take");
2904
+ if (sharing.stale && shared) notes.push("Shared information may be stale");
2905
+ return notes;
2906
+ }
2907
+ var QUIET_BUTTON = cn(buttonVariants({ size: "sm" }), "gap-1.5");
2908
+ function CardFacts({ card }) {
2909
+ const expanded = useWorkUi((state) => state.expanded[card.id] === true);
2910
+ const toggle = useWorkUi((state) => state.toggle);
2911
+ const claim = claimText(card);
2912
+ const progress = progressText(card);
2913
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
2914
+ className: "flex flex-wrap items-center gap-x-3 gap-y-1 text-xs text-muted",
2915
+ children: [
2916
+ claim ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
2917
+ className: cn(card.claim.kind === "mine" && "text-text"),
2918
+ children: claim
2919
+ }) : null,
2920
+ progress ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: progress }) : null,
2921
+ card.memberNames.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
2922
+ type: "button",
2923
+ className: "inline-flex items-center gap-1 text-xs text-muted hover:text-text",
2924
+ "aria-expanded": expanded,
2925
+ "aria-controls": `members-${card.id}`,
2926
+ onClick: () => toggle(card.id),
2927
+ children: [
2928
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {
2929
+ name: expanded ? "chevron" : "right",
2930
+ className: "size-3.5"
2931
+ }),
2932
+ card.memberNames.length,
2933
+ " changes"
2934
+ ]
2935
+ }) : null
2936
+ ]
2937
+ });
2938
+ }
2939
+ function TextList({ items, className, label }) {
2940
+ if (items.length === 0) return null;
2941
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
2942
+ className: cn("m-0 list-none p-0 text-xs", className),
2943
+ "aria-label": label,
2944
+ children: items.map((item) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: item }, item))
2945
+ });
2946
+ }
2947
+ function CardOffers({ card, writable }) {
2948
+ return card.offers.map((offer) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
2949
+ className: "inline-flex gap-1.5",
2950
+ children: [writable && offer.runAgents.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
2951
+ type: "button",
2952
+ className: cn(QUIET_BUTTON, "work-action"),
2953
+ "data-studio-action": offer.action,
2954
+ "data-studio-subject": offer.subject,
2955
+ "data-studio-agents": offer.runAgents.join(" "),
2956
+ "aria-label": `${offer.label} ${offer.subject} in the terminal`,
2957
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {
2958
+ name: "play",
2959
+ className: "size-3.5"
2960
+ }), offer.label]
2961
+ }) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
2962
+ type: "button",
2963
+ className: cn(QUIET_BUTTON, "work-copy"),
2964
+ "data-studio-copy-prompt": offer.action,
2965
+ "data-prompt-claude": offer.prompts.claude,
2966
+ "data-prompt-opencode": offer.prompts.opencode,
2967
+ "aria-label": `Copy the ${offer.label.toLowerCase()} prompt for ${offer.subject}`,
2968
+ children: [
2969
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {
2970
+ name: "copy",
2971
+ className: "size-3.5"
2972
+ }),
2973
+ offer.label,
2974
+ " prompt"
2975
+ ]
2976
+ })]
2977
+ }, `${offer.action}:${offer.subject}`));
2978
+ }
2979
+ function CardActions({ card, actions }) {
2980
+ const open = useWorkUi((state) => state.open);
2981
+ return actions.map((action) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
2982
+ type: "button",
2983
+ className: cn(buttonVariants({
2984
+ variant: PRIMARY.has(action) ? "primary" : "default",
2985
+ size: "sm"
2986
+ }), "work-action"),
2987
+ "data-work-action": action,
2988
+ onClick: () => open({
2989
+ kind: action,
2990
+ workset: card.id
2991
+ }),
2992
+ children: ACTION_LABELS[action]
2993
+ }, action));
2994
+ }
2995
+ function CardMembers({ card }) {
2996
+ if (!useWorkUi((state) => state.expanded[card.id] === true) || card.memberNames.length < 2) return null;
2997
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
2998
+ id: `members-${card.id}`,
2999
+ className: "m-0 grid list-none gap-1 pr-3 pb-2.5 pl-10",
3000
+ "aria-label": "Changes",
3001
+ children: card.members.map((member) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
3002
+ className: "flex flex-wrap items-center gap-3 text-xs",
3003
+ children: [
3004
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
3005
+ className: "font-mono",
3006
+ children: member.name
3007
+ }),
3008
+ card.sharing.remoteOnly ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusWord, {
3009
+ marker: member.problem ? "issue" : STAGE_MARKERS[member.stage],
3010
+ children: member.delivered ? "Delivered" : member.stageLabel
3011
+ }),
3012
+ member.problem ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
3013
+ className: "text-bad",
3014
+ children: member.problem
3015
+ }) : null
3016
+ ]
3017
+ }, member.name))
3018
+ });
3019
+ }
3020
+ function CardHeading({ card }) {
3021
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3022
+ className: "grid min-w-0 flex-1 gap-1",
3023
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
3024
+ className: "line-clamp-2 font-medium [overflow-wrap:anywhere]",
3025
+ children: card.title
3026
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3027
+ className: "flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1",
3028
+ children: [card.sharing.remoteOnly && card.diagnostics.length === 0 ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StatusWord, {
3029
+ marker: card.diagnostics.length > 0 ? "issue" : STAGE_MARKERS[card.stage],
3030
+ children: card.done ? "Done" : card.stageLabel
3031
+ }), card.title === card.id ? null : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
3032
+ className: "min-w-0 truncate font-mono text-xs text-muted",
3033
+ children: card.id
3034
+ })]
3035
+ })]
3036
+ });
3037
+ }
3038
+ function WorkCard({ card, writable }) {
3039
+ const actions = writable ? acceptedActions(card) : [];
3040
+ const targets = writable ? dropTargetsOf(card) : {};
3041
+ const draggable = Object.keys(targets).length > 0;
3042
+ const data = {
3043
+ title: card.title,
3044
+ targets
3045
+ };
3046
+ const { attributes, listeners, setNodeRef, setActivatorNodeRef, isDragging } = useDraggable({
3047
+ id: card.id,
3048
+ data,
3049
+ disabled: !draggable
3050
+ });
3051
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("li", {
3052
+ ref: setNodeRef,
3053
+ className: cn("work-card border-t border-rule-soft transition-opacity first:border-t-0", isDragging && "opacity-40"),
3054
+ "data-workset": card.id,
3055
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3056
+ className: cn(ROW, "items-start gap-2 border-t-0 py-2.5 pr-3 pl-2 hover:bg-transparent"),
3057
+ children: [draggable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", {
3058
+ ref: setActivatorNodeRef,
3059
+ type: "button",
3060
+ className: "work-drag -my-0.5 grid size-6 flex-none cursor-grab touch-none place-items-center rounded-control text-muted hover:bg-surface hover:text-text active:cursor-grabbing",
3061
+ "data-work-drag": card.id,
3062
+ ...attributes,
3063
+ ...listeners,
3064
+ "aria-label": `Move ${card.title}`,
3065
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {
3066
+ name: "grip",
3067
+ className: "size-4 [stroke-width:2.6]"
3068
+ })
3069
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
3070
+ className: "size-6 flex-none",
3071
+ "aria-hidden": "true"
3072
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3073
+ className: "grid min-w-0 flex-1 gap-1.5",
3074
+ children: [
3075
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardHeading, { card }),
3076
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardFacts, { card }),
3077
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextList, {
3078
+ items: sharingNotes(card),
3079
+ className: "grid gap-0.5 text-muted"
3080
+ }),
3081
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TextList, {
3082
+ items: card.diagnostics,
3083
+ className: "grid gap-0.5 text-bad",
3084
+ label: "Problems"
3085
+ }),
3086
+ actions.length > 0 || card.offers.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3087
+ className: "flex flex-wrap items-center gap-1.5 pt-0.5",
3088
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardActions, {
3089
+ card,
3090
+ actions
3091
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardOffers, {
3092
+ card,
3093
+ writable
3094
+ })]
3095
+ }) : null
3096
+ ]
3097
+ })]
3098
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardMembers, { card })]
3099
+ });
3100
+ }
3101
+ // src/views/work/use-work-action.ts
3102
+ function newWorkKey() {
3103
+ return typeof crypto !== "undefined" && "randomUUID" in crypto ? crypto.randomUUID() : `k-${Date.now()}-${Math.random().toString(36).slice(2)}`;
3104
+ }
3105
+ function useWorkAction(companion) {
3106
+ const queryClient = useQueryClient();
3107
+ return useMutation({
3108
+ mutationFn: async (request) => runWorkAction({ data: {
3109
+ companion,
3110
+ request
3111
+ } }),
3112
+ onSettled: (_result, _error, request) => request.action === "share-preview" ? void 0 : afterWorkAction(queryClient, companion)
3113
+ });
3114
+ }
3115
+ function workResultOf(mutation) {
3116
+ if (!mutation.error) return mutation.data;
3117
+ const { error } = mutation;
3118
+ return {
3119
+ ok: false,
3120
+ kind: "failed",
3121
+ reason: error instanceof Error && error.message ? error.message : "The request failed."
3122
+ };
3123
+ }
3124
+ var REFUSAL_HINTS = {
3125
+ stale: "Something changed meanwhile. Review the current state and confirm again.",
3126
+ access: "This needs write access, or it is someone else's."
3127
+ };
3128
+ // src/views/work/work-dialogs.tsx
3129
+ function Refusal({ result }) {
3130
+ if (!result || result.ok) return null;
3131
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3132
+ className: "grid gap-1 rounded-control border border-bad bg-bad-soft px-3 py-2 text-sm",
3133
+ role: "alert",
3134
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: result.reason }), REFUSAL_HINTS[result.kind] ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
3135
+ className: "text-xs text-muted",
3136
+ children: REFUSAL_HINTS[result.kind]
3137
+ }) : null]
3138
+ });
3139
+ }
3140
+ function Frame({ title, description, children, footer }) {
3141
+ const close = useWorkUi((state) => state.close);
3142
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Dialog, {
3143
+ open: true,
3144
+ onOpenChange: (open) => open ? void 0 : close(),
3145
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DialogContent, {
3146
+ className: "grid gap-4 p-5",
3147
+ "data-work-dialog": "",
3148
+ children: [
3149
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3150
+ className: "grid gap-1",
3151
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogTitle, { children: title }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DialogDescription, { children: description })]
3152
+ }),
3153
+ children,
3154
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3155
+ className: "flex flex-wrap justify-end gap-2",
3156
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
3157
+ variant: "ghost",
3158
+ onClick: close,
3159
+ children: "Cancel"
3160
+ }), footer]
3161
+ })
3162
+ ]
3163
+ })
3164
+ });
3165
+ }
3166
+ function useConfirm(companion) {
3167
+ const close = useWorkUi((state) => state.close);
3168
+ const mutation = useWorkAction(companion);
3169
+ const [key] = (0, import_react.useState)(newWorkKey);
3170
+ const run = (request, onOk, onRefused) => mutation.mutate(request, { onSuccess: (result) => {
3171
+ if (!result.ok) return onRefused?.(result);
3172
+ if (onOk) onOk(result);
3173
+ else close();
3174
+ } });
3175
+ return {
3176
+ mutation,
3177
+ run,
3178
+ key,
3179
+ result: workResultOf(mutation)
3180
+ };
3181
+ }
3182
+ function PreviewSummary({ preview }) {
3183
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
3184
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
3185
+ className: "m-0",
3186
+ children: [
3187
+ "To ",
3188
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
3189
+ className: "font-mono",
3190
+ children: `${preview.target.remote}/${preview.target.branch}`
3191
+ }),
3192
+ ":",
3193
+ " ",
3194
+ preview.members.length,
3195
+ " ",
3196
+ preview.members.length === 1 ? "change" : "changes",
3197
+ ",",
3198
+ " ",
3199
+ preview.files.length,
3200
+ " files."
3201
+ ]
3202
+ }),
3203
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("details", { children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("summary", {
3204
+ className: "cursor-pointer text-xs text-muted",
3205
+ children: "Files"
3206
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
3207
+ className: "m-0 mt-1 max-h-40 list-none overflow-auto p-0 font-mono text-xs",
3208
+ children: preview.files.map((file) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: file.path }, file.path))
3209
+ })] }),
3210
+ preview.excluded.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", {
3211
+ className: "m-0 text-xs text-muted",
3212
+ children: ["Not shared: ", preview.excluded.map((entry) => entry.path).join(", ")]
3213
+ }) : null,
3214
+ preview.problems.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
3215
+ className: "m-0 list-none p-0 text-xs text-bad",
3216
+ children: preview.problems.map((problem) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: problem }, problem))
3217
+ }) : null
3218
+ ] });
3219
+ }
3220
+ function DependencyChoice({ dependencies, included, onChange }) {
3221
+ if (dependencies.length === 0) return null;
3222
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", {
3223
+ className: "m-0 grid gap-1 border-0 p-0",
3224
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", {
3225
+ className: "text-xs text-warn",
3226
+ children: "It depends on unshared active changes. Include them, or share them first."
3227
+ }), dependencies.map((dependency) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
3228
+ className: "flex items-center gap-2 text-xs",
3229
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("input", {
3230
+ type: "checkbox",
3231
+ checked: included.has(dependency),
3232
+ onChange: (event) => {
3233
+ const checked = event.target.checked;
3234
+ onChange((current) => checked ? [...current, dependency] : current.filter((name) => name !== dependency));
3235
+ }
3236
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
3237
+ className: "font-mono",
3238
+ children: dependency
3239
+ })]
3240
+ }, dependency))]
3241
+ });
3242
+ }
3243
+ function ShareDialog({ companion, card }) {
3244
+ const acted = useWorkUi((state) => state.acted);
3245
+ const preview = useWorkAction(companion);
3246
+ const { mutation, run, key, result } = useConfirm(companion);
3247
+ const [include, setInclude] = (0, import_react.useState)([]);
3248
+ const { mutate } = preview;
3249
+ const loadPreview = (0, import_react.useCallback)(() => mutate({
3250
+ action: "share-preview",
3251
+ workset: card.id,
3252
+ include
3253
+ }), [
3254
+ mutate,
3255
+ card.id,
3256
+ include
3257
+ ]);
3258
+ (0, import_react.useEffect)(() => loadPreview(), [loadPreview]);
3259
+ const shown = preview.data?.ok ? preview.data.preview : void 0;
3260
+ const blocked = !shown || shown.problems.length > 0 || shown.externalDependencies.length > 0 || preview.isPending;
3261
+ const included = new Set(include);
3262
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Frame, {
3263
+ title: `Share ${card.title}`,
3264
+ description: `Pushes only these files to the team inbox ${shown?.target.branch ?? "mate/inbox"}, where teammates can claim it. Your checkout stays as it is. It starts no work, claims nothing new, submits nothing and records no approval.`,
3265
+ footer: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
3266
+ variant: "primary",
3267
+ disabled: blocked || mutation.isPending,
3268
+ onClick: () => shown && run({
3269
+ action: "share",
3270
+ workset: card.id,
3271
+ hash: shown.hash,
3272
+ include,
3273
+ key
3274
+ }, () => acted(card), (refused) => {
3275
+ if (refused.kind === "stale") loadPreview();
3276
+ }),
3277
+ children: "Share"
3278
+ }),
3279
+ children: [
3280
+ preview.isPending ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
3281
+ className: "m-0 text-sm text-muted",
3282
+ children: "Reading what would be shared…"
3283
+ }) : null,
3284
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Refusal, { result: workResultOf(preview) }),
3285
+ shown ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3286
+ className: "grid gap-3 text-sm",
3287
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(PreviewSummary, { preview: shown }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DependencyChoice, {
3288
+ dependencies: [.../* @__PURE__ */ new Set([...include, ...shown.externalDependencies])],
3289
+ included,
3290
+ onChange: setInclude
3291
+ })]
3292
+ }) : null,
3293
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Refusal, { result })
3294
+ ]
3295
+ });
3296
+ }
3297
+ function ClaimDialog({ companion, card, kind, operator }) {
3298
+ const { mutation, run, key, result } = useConfirm(companion);
3299
+ const close = useWorkUi((state) => state.close);
3300
+ const acted = useWorkUi((state) => state.acted);
3301
+ const needsTake = kind === "claim" && result?.ok ? result.needsTake ?? [] : [];
3302
+ const copy = {
3303
+ claim: {
3304
+ title: `Claim ${card.title}`,
3305
+ description: `Adds owner.yaml naming ${operator?.label ?? "you"} to all ${card.claimMemberNames.length} of its changes on the team inbox. A claim coordinates trusted teammates; it is not access control.`,
3306
+ button: "Claim"
3307
+ },
3308
+ release: {
3309
+ title: `Release ${card.title}`,
3310
+ description: card.progress.kind === "none" ? "Removes its owner.yaml files, so anyone on the team may claim it. Its files and branches stay as they are." : `Removes its owner.yaml files. It still records ${card.progress.branch}, so teammates see it as in progress and cannot claim it; whoever checks out ${card.progress.branch} may continue it. Its files and branches stay as they are.`,
3311
+ button: "Release"
3312
+ }
3313
+ }[kind];
3314
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Frame, {
3315
+ title: copy.title,
3316
+ description: copy.description,
3317
+ footer: needsTake.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
3318
+ variant: "primary",
3319
+ onClick: close,
3320
+ children: "Done"
3321
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
3322
+ variant: "primary",
3323
+ disabled: mutation.isPending,
3324
+ onClick: () => run({
3325
+ action: kind,
3326
+ workset: card.id,
3327
+ members: card.claimMemberNames,
3328
+ key
3329
+ }, (ok) => {
3330
+ if (kind === "release" || !ok.needsTake?.length) acted(card);
3331
+ }),
3332
+ children: copy.button
3333
+ }),
3334
+ children: [needsTake.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3335
+ className: "grid gap-2 text-sm",
3336
+ role: "status",
3337
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
3338
+ className: "m-0",
3339
+ children: "Claimed. Take its changes into this checkout before you start:"
3340
+ }), needsTake.map((change) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CommandLine, {
3341
+ text: `mate artifact take ${change}`,
3342
+ label: `Take ${change}`
3343
+ }, change))]
3344
+ }) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Refusal, { result })]
3345
+ });
3346
+ }
3347
+ function StartManualDialog({ companion, card }) {
3348
+ const { mutation, run, result } = useConfirm(companion);
3349
+ const prompts = result?.ok ? result.prompts ?? [] : null;
3350
+ const close = useWorkUi((state) => state.close);
3351
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Frame, {
3352
+ title: `Continue ${card.title} manually`,
3353
+ description: "Checks that it is yours to continue, then shows the prompts for your own agent session. Nothing is written.",
3354
+ footer: prompts ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
3355
+ variant: "primary",
3356
+ onClick: close,
3357
+ children: "Done"
3358
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
3359
+ variant: "primary",
3360
+ disabled: mutation.isPending,
3361
+ onClick: () => run({
3362
+ action: "start-manual",
3363
+ workset: card.id,
3364
+ members: card.memberNames
3365
+ }, () => void 0),
3366
+ children: "Continue"
3367
+ }),
3368
+ children: [prompts ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3369
+ className: "grid gap-2",
3370
+ children: [prompts.flatMap((entry) => Object.entries(entry).map(([agent, prompt]) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CommandLine, {
3371
+ text: prompt ?? "",
3372
+ label: `${agent} prompt`
3373
+ }, `${agent}:${prompt}`))), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
3374
+ className: "m-0 text-xs text-muted",
3375
+ children: "A copied prompt runs wherever you paste it; Studio cannot see or fence that session."
3376
+ })]
3377
+ }) : null, /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Refusal, { result })]
3378
+ });
3379
+ }
3380
+ function WorkDialogs({ companion, payload, dialog }) {
3381
+ const close = useWorkUi((state) => state.close);
3382
+ const card = dialog ? payload.cards.find((entry) => entry.id === dialog.workset) : void 0;
3383
+ const orphaned = !!dialog && !card;
3384
+ (0, import_react.useEffect)(() => {
3385
+ if (orphaned) close();
3386
+ }, [orphaned, close]);
3387
+ (0, import_react.useEffect)(() => close, [close]);
3388
+ if (!dialog || !card) return null;
3389
+ switch (dialog.kind) {
3390
+ case "share": return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ShareDialog, {
3391
+ companion,
3392
+ card
3393
+ }, card.id);
3394
+ case "claim":
3395
+ case "release": return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(ClaimDialog, {
3396
+ companion,
3397
+ card,
3398
+ kind: dialog.kind,
3399
+ operator: payload.operator
3400
+ }, card.id);
3401
+ case "start-manual": return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(StartManualDialog, {
3402
+ companion,
3403
+ card
3404
+ }, card.id);
3405
+ }
3406
+ }
3407
+ // src/views/work/work-view.tsx
3408
+ var BUCKET_LABELS = {
3409
+ scratchpad: "Scratchpad",
3410
+ local: "Local work",
3411
+ remote: "Remote work"
3412
+ };
3413
+ var BUCKET_HINTS = {
3414
+ scratchpad: "Ideas on this checkout only. Nothing here runs or is pushed.",
3415
+ local: "Your changes: not shared yet, claimed by you, or built here.",
3416
+ remote: "Shared changes: available to claim, claimed by others, or built elsewhere."
3417
+ };
3418
+ var EMPTY = {
3419
+ scratchpad: "No saved ideas.",
3420
+ local: "No local work. Propose a change to see it here.",
3421
+ remote: "Nothing shared. Refresh to look at the team branch."
3422
+ };
3423
+ var REMOTE_EMPTY_WITH_SHARED = "No shared work to claim.";
3424
+ function dropOf(active, over) {
3425
+ const bucket = (over?.data.current)?.bucket;
3426
+ const action = bucket ? dragData(active)?.targets[bucket] : void 0;
3427
+ return bucket && action ? {
3428
+ bucket,
3429
+ action
3430
+ } : null;
3431
+ }
3432
+ var dragData = (active) => active?.data.current;
3433
+ var titleOf = (active) => dragData(active)?.title ?? String(active.id);
3434
+ var KEY_STEPS = {
3435
+ ArrowRight: 1,
3436
+ ArrowDown: 1,
3437
+ ArrowLeft: -1,
3438
+ ArrowUp: -1
3439
+ };
3440
+ var isDisplayed = (rect) => rect.width > 0;
3441
+ var bucketKeys = (event, { currentCoordinates, context }) => {
3442
+ const step = KEY_STEPS[event.code];
3443
+ const from = context.collisionRect;
3444
+ if (!step || !from) return void 0;
3445
+ event.preventDefault();
3446
+ const here = {
3447
+ x: from.left + from.width / 2,
3448
+ y: from.top + from.height / 2
3449
+ };
3450
+ const target = context.droppableContainers.getEnabled().flatMap((container) => {
3451
+ const rect = context.droppableRects.get(container.id);
3452
+ const ahead = rect && Math.sign(rect.left + rect.width / 2 - here.x) === step;
3453
+ return rect && isDisplayed(rect) && ahead ? [rect] : [];
3454
+ }).reduce((nearest, rect) => !nearest || step * (rect.left - nearest.left) < 0 ? rect : nearest, void 0);
3455
+ if (!target) return void 0;
3456
+ const y = Math.min(Math.max(here.y, target.top + from.height / 2), target.bottom - from.height / 2);
3457
+ return {
3458
+ x: currentCoordinates.x + target.left + target.width / 2 - here.x,
3459
+ y: currentCoordinates.y + (target.height > from.height ? y : target.top + target.height / 2) - here.y
3460
+ };
3461
+ };
3462
+ var collisions = (args) => {
3463
+ const within = pointerWithin(args);
3464
+ return within.length > 0 ? within : rectIntersection(args);
3465
+ };
3466
+ function MovingCard({ cards }) {
3467
+ const { active } = useDndContext();
3468
+ const card = active ? cards.find((candidate) => candidate.id === active.id) : void 0;
3469
+ if (!card) return null;
3470
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3471
+ className: "flex w-[min(340px,80vw)] cursor-grabbing items-start gap-2 rounded-card border border-accent bg-surface py-2.5 pr-3 pl-2 text-base text-text shadow-float",
3472
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
3473
+ className: "grid size-6 flex-none place-items-center text-accent",
3474
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {
3475
+ name: "grip",
3476
+ className: "size-4 [stroke-width:2.6]"
3477
+ })
3478
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(CardHeading, { card })]
3479
+ });
3480
+ }
3481
+ function Work({ payload, search }) {
3482
+ const companion = search.companion;
3483
+ const navigate = useNavigate();
3484
+ const bucket = search.bucket ?? "scratchpad";
3485
+ const dialog = useWorkUi((state) => state.dialog);
3486
+ const openDialog = useWorkUi((state) => state.open);
3487
+ const focusAfter = useWorkUi((state) => state.focusAfter);
3488
+ const focused = useWorkUi((state) => state.focused);
3489
+ const view = (0, import_react.useRef)(null);
3490
+ (0, import_react.useEffect)(() => {
3491
+ if (!focusAfter || dialog) return;
3492
+ const moved = payload.cards.find((card) => card.id === focusAfter.id);
3493
+ if (moved === focusAfter) return;
3494
+ focused();
3495
+ const tabs = view.current?.querySelector("[role=\"tablist\"]");
3496
+ const target = !!tabs && isDisplayed(tabs.getBoundingClientRect()) && moved?.bucket !== bucket ? view.current?.querySelector(`#work-tab-${(moved ?? focusAfter).bucket}`) : view.current?.querySelector(`[data-workset="${CSS.escape(focusAfter.id)}"]`)?.querySelector(".work-action, .work-copy");
3497
+ queueMicrotask(() => target?.focus());
3498
+ }, [
3499
+ focusAfter,
3500
+ dialog,
3501
+ focused,
3502
+ payload.cards,
3503
+ bucket
3504
+ ]);
3505
+ const sensors = useSensors(useSensor(PointerSensor, { activationConstraint: { distance: 4 } }), useSensor(KeyboardSensor, { coordinateGetter: bucketKeys }));
3506
+ const byBucket = (name) => payload.cards.filter((card) => card.bucket === name);
3507
+ const anyShared = payload.cards.some((card) => isShared(card.sharing.presence));
3508
+ const select = (next) => void navigate({
3509
+ to: "/work",
3510
+ search: (previous) => ({
3511
+ companion: previous.companion,
3512
+ studioMode: previous.studioMode,
3513
+ ...next === "scratchpad" ? {} : { bucket: next }
3514
+ }),
3515
+ resetScroll: false
3516
+ });
3517
+ const onDragEnd = ({ active, over }) => {
3518
+ const drop = dropOf(active, over);
3519
+ if (drop) openDialog({
3520
+ kind: drop.action,
3521
+ workset: String(active.id)
3522
+ });
3523
+ };
3524
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
3525
+ ref: view,
3526
+ className: cn(PAGE_PAD, "view-section work @container grid content-start gap-4 pb-10"),
3527
+ "aria-label": "Work",
3528
+ children: [
3529
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(DndContext, {
3530
+ id: "work-dnd",
3531
+ sensors,
3532
+ collisionDetection: collisions,
3533
+ onDragEnd,
3534
+ accessibility: {
3535
+ screenReaderInstructions: { draggable: "To move a Workset, press Space or Enter, choose a bucket with the arrow keys, then press Space or Enter to drop it, or Escape to cancel. A drop asks for confirmation." },
3536
+ announcements: {
3537
+ onDragStart: ({ active }) => `Picked up ${titleOf(active)}.`,
3538
+ onDragOver: ({ active, over }) => {
3539
+ const drop = dropOf(active, over);
3540
+ return drop ? `Over ${BUCKET_LABELS[drop.bucket]}: drop to ${DROP_VERBS[drop.action]}.` : `${titleOf(active)} is not over a bucket that takes it.`;
3541
+ },
3542
+ onDragEnd: ({ active, over }) => {
3543
+ const drop = dropOf(active, over);
3544
+ return drop ? `Dropped on ${BUCKET_LABELS[drop.bucket]}. Confirm to ${DROP_VERBS[drop.action]}.` : `${titleOf(active)} stays where it was.`;
3545
+ },
3546
+ onDragCancel: ({ active }) => `Moving ${titleOf(active)} was cancelled.`
3547
+ }
3548
+ },
3549
+ children: [
3550
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3551
+ className: "flex flex-wrap items-center gap-3",
3552
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
3553
+ role: "tablist",
3554
+ "aria-label": "Work buckets",
3555
+ className: "flex flex-wrap gap-1.5 @min-[56rem]:hidden",
3556
+ children: WORK_BUCKETS.map((name) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(BucketTab, {
3557
+ bucket: name,
3558
+ cards: byBucket(name),
3559
+ selected: bucket === name,
3560
+ onSelect: () => select(name)
3561
+ }, name))
3562
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TeamStatus, {
3563
+ payload,
3564
+ companion
3565
+ })]
3566
+ }),
3567
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
3568
+ className: "grid items-start gap-4 @min-[56rem]:grid-cols-3",
3569
+ children: WORK_BUCKETS.map((name) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Lane, {
3570
+ bucket: name,
3571
+ cards: byBucket(name),
3572
+ empty: name === "remote" && anyShared ? REMOTE_EMPTY_WITH_SHARED : EMPTY[name],
3573
+ selected: bucket === name,
3574
+ writable: payload.writable,
3575
+ children: name === "scratchpad" ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Capture, {
3576
+ payload,
3577
+ companion
3578
+ }) : null
3579
+ }, name))
3580
+ }),
3581
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(DragOverlay, {
3582
+ dropAnimation: null,
3583
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(MovingCard, { cards: payload.cards })
3584
+ })
3585
+ ]
3586
+ }),
3587
+ payload.diagnostics.length > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
3588
+ className: "m-0 list-none p-0 text-xs text-warn",
3589
+ "aria-label": "Workset records that cannot be read",
3590
+ children: payload.diagnostics.map((diagnostic) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("li", { children: diagnostic }, diagnostic))
3591
+ }) : null,
3592
+ payload.writable ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WorkDialogs, {
3593
+ companion,
3594
+ payload,
3595
+ dialog
3596
+ }) : null
3597
+ ]
3598
+ });
3599
+ }
3600
+ function useDropTarget(id, bucket) {
3601
+ const { active } = useDndContext();
3602
+ const action = dragData(active)?.targets[bucket];
3603
+ const { setNodeRef, isOver } = useDroppable({
3604
+ id,
3605
+ data: { bucket },
3606
+ disabled: !action
3607
+ });
3608
+ return {
3609
+ setNodeRef,
3610
+ action,
3611
+ over: isOver && action !== void 0
3612
+ };
3613
+ }
3614
+ function BucketTab({ bucket, cards, selected, onSelect }) {
3615
+ const { setNodeRef, action, over } = useDropTarget(`tab:${bucket}`, bucket);
3616
+ const needs = cards.filter((card) => card.needsYou).length;
3617
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("button", {
3618
+ ref: setNodeRef,
3619
+ type: "button",
3620
+ role: "tab",
3621
+ id: `work-tab-${bucket}`,
3622
+ "aria-selected": selected,
3623
+ "aria-controls": `work-lane-${bucket}`,
3624
+ "data-work-bucket": bucket,
3625
+ className: cn("inline-flex h-8 items-center gap-2 rounded-control border px-3 text-sm transition-colors", selected ? "border-accent bg-accent-soft font-semibold" : "border-rule bg-surface", action && "outline-1 outline-offset-2 outline-accent outline-dashed", over && "border-accent bg-accent-soft outline-2 outline-solid"),
3626
+ onClick: onSelect,
3627
+ children: [BUCKET_LABELS[bucket], needs > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Count, {
3628
+ value: needs,
3629
+ tone: "warn",
3630
+ label: `${needs} need you`
3631
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Count, { value: cards.length })]
3632
+ });
3633
+ }
3634
+ function Lane({ bucket, cards, empty, selected, writable, children }) {
3635
+ const { setNodeRef, action, over } = useDropTarget(`lane:${bucket}`, bucket);
3636
+ const needs = cards.filter((card) => card.needsYou).length;
3637
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", {
3638
+ ref: setNodeRef,
3639
+ id: `work-lane-${bucket}`,
3640
+ "aria-labelledby": `work-lane-${bucket}-title`,
3641
+ "data-work-lane": bucket,
3642
+ className: cn("work-lane grid min-w-0 content-start gap-3 rounded-panel p-2 transition-[background-color,outline-color] duration-150", !selected && "@max-[56rem]:hidden", action && "outline-1 -outline-offset-1 outline-accent outline-dashed", over && "bg-accent-soft outline-2 outline-solid"),
3643
+ children: [
3644
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("header", {
3645
+ className: "grid gap-0.5 px-1 pt-0.5",
3646
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3647
+ className: "flex items-center gap-2 @max-[56rem]:sr-only",
3648
+ children: [
3649
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", {
3650
+ id: `work-lane-${bucket}-title`,
3651
+ className: "m-0 text-[0.9rem] font-semibold",
3652
+ children: BUCKET_LABELS[bucket]
3653
+ }),
3654
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Count, { value: cards.length }),
3655
+ needs > 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Count, {
3656
+ value: needs,
3657
+ tone: "warn",
3658
+ label: `${needs} need you`
3659
+ }) : null,
3660
+ action ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
3661
+ className: "ml-auto text-xs font-medium text-accent",
3662
+ "aria-hidden": "true",
3663
+ children: ["Drop to ", DROP_VERBS[action]]
3664
+ }) : null
3665
+ ]
3666
+ }), /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
3667
+ className: "m-0 text-xs text-muted @min-[56rem]:min-h-[2lh]",
3668
+ children: BUCKET_HINTS[bucket]
3669
+ })]
3670
+ }),
3671
+ children,
3672
+ cards.length === 0 ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(EmptyNote, {
3673
+ className: "px-4 py-4 text-sm",
3674
+ children: empty
3675
+ }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("ul", {
3676
+ className: "m-0 list-none overflow-hidden rounded-card border border-rule bg-page p-0",
3677
+ "aria-label": BUCKET_LABELS[bucket],
3678
+ children: cards.map((card) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WorkCard, {
3679
+ card,
3680
+ writable
3681
+ }, card.id))
3682
+ })
3683
+ ]
3684
+ });
3685
+ }
3686
+ function TeamStatus({ payload, companion }) {
3687
+ const refresh = useWorkAction(companion);
3688
+ const { team } = payload;
3689
+ if (!payload.gitBacked) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", {
3690
+ className: "text-xs text-muted",
3691
+ children: "Local only: the companion is not a Git repository."
3692
+ });
3693
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3694
+ className: "ml-auto flex flex-wrap items-center gap-2 text-xs text-muted",
3695
+ children: [
3696
+ team.remote && team.branch ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", { children: ["Shared on ", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("code", {
3697
+ className: "font-mono",
3698
+ children: `${team.remote}/${team.branch}`
3699
+ })] }) : null,
3700
+ team.fetchedAt ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Age, { at: team.fetchedAt }) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("span", { children: "never refreshed" }),
3701
+ team.failure ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("span", {
3702
+ className: "text-warn",
3703
+ role: "status",
3704
+ children: ["Stale: ", team.failure]
3705
+ }) : null,
3706
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(Button, {
3707
+ size: "sm",
3708
+ disabled: refresh.isPending,
3709
+ onClick: () => refresh.mutate({ action: "refresh" }),
3710
+ "aria-label": "Refresh shared work",
3711
+ children: [/* @__PURE__ */ (0, import_jsx_runtime.jsx)(Icon, {
3712
+ name: "refresh",
3713
+ className: "size-3.5"
3714
+ }), "Refresh"]
3715
+ })
3716
+ ]
3717
+ });
3718
+ }
3719
+ function Capture({ payload, companion }) {
3720
+ const draft = useWorkUi((state) => state.drafts[companion] ?? "");
3721
+ const setDraft = useWorkUi((state) => state.setDraft);
3722
+ const [repository, setRepository] = (0, import_react.useState)(payload.linkedRepositories[0] ?? "");
3723
+ const [ticket, setTicket] = (0, import_react.useState)("");
3724
+ const save = useWorkAction(companion);
3725
+ if (!payload.writable) return null;
3726
+ const fields = {
3727
+ ...payload.linkedRepositories.length > 1 ? { repository } : {},
3728
+ ...ticket.trim() ? { ticket: ticket.trim() } : {}
3729
+ };
3730
+ const clear = () => {
3731
+ setDraft(companion, "");
3732
+ setTicket("");
3733
+ };
3734
+ const submit = (event) => {
3735
+ event.preventDefault();
3736
+ if (!draft.trim()) return;
3737
+ save.mutate({
3738
+ action: "capture",
3739
+ text: draft,
3740
+ ...fields
3741
+ }, { onSuccess: (result) => {
3742
+ if (result.ok) clear();
3743
+ } });
3744
+ };
3745
+ const result = workResultOf(save);
3746
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("form", {
3747
+ className: "work-capture grid min-w-0 grid-cols-[minmax(0,1fr)] gap-2",
3748
+ onSubmit: submit,
3749
+ "aria-label": "Capture an idea",
3750
+ children: [
3751
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", {
3752
+ htmlFor: "work-capture-text",
3753
+ className: "text-sm font-medium",
3754
+ children: "What should we build or improve?"
3755
+ }),
3756
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Textarea, {
3757
+ id: "work-capture-text",
3758
+ value: draft,
3759
+ onChange: (event) => setDraft(companion, event.target.value),
3760
+ placeholder: "Describe the outcome in plain words."
3761
+ }),
3762
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", {
3763
+ className: "flex flex-wrap items-center gap-2",
3764
+ children: [
3765
+ payload.linkedRepositories.length > 1 ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
3766
+ className: "flex min-w-0 max-w-full items-center gap-2 text-xs text-muted",
3767
+ children: ["Repository", /* @__PURE__ */ (0, import_jsx_runtime.jsx)("select", {
3768
+ className: "h-8 min-w-0 max-w-full truncate rounded-control border border-rule bg-page px-2 text-sm text-text",
3769
+ value: repository,
3770
+ onChange: (event) => setRepository(event.target.value),
3771
+ children: payload.linkedRepositories.map((entry) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", {
3772
+ value: entry,
3773
+ children: entry
3774
+ }, entry))
3775
+ })]
3776
+ }) : null,
3777
+ payload.ticketFormat === "jira" ? /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("label", {
3778
+ className: "flex items-center gap-2 text-xs text-muted",
3779
+ children: ["Ticket", /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Input, {
3780
+ className: "h-8 w-32",
3781
+ value: ticket,
3782
+ onChange: (event) => setTicket(event.target.value),
3783
+ placeholder: "ABC-123"
3784
+ })]
3785
+ }) : null,
3786
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", {
3787
+ className: "ml-auto flex gap-2",
3788
+ children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Button, {
3789
+ type: "submit",
3790
+ disabled: !draft.trim() || save.isPending,
3791
+ children: "Save"
3792
+ })
3793
+ })
3794
+ ]
3795
+ }),
3796
+ result && !result.ok ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", {
3797
+ className: "m-0 text-sm text-bad",
3798
+ role: "alert",
3799
+ children: result.reason
3800
+ }) : null
3801
+ ]
3802
+ });
3803
+ }
3804
+ // src/routes/work.tsx?tsr-split=component
3805
+ function WorkRoute() {
3806
+ const search = Route.useSearch();
3807
+ if (!search.companion) return null;
3808
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WorkBoard, { search });
3809
+ }
3810
+ function WorkBoard({ search }) {
3811
+ const { data } = useSuspenseQuery(workQuery(search.companion));
3812
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Work, {
3813
+ payload: data,
3814
+ search
3815
+ });
3816
+ }
3817
+ export { WorkRoute as component };