painapple-code 1.0.0__py3-none-any.whl

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 (436) hide show
  1. painapple_code/__init__.py +30 -0
  2. painapple_code/__main__.py +18 -0
  3. painapple_code/_version.py +24 -0
  4. painapple_code/auth_middleware.py +930 -0
  5. painapple_code/cli/__init__.py +204 -0
  6. painapple_code/cli/deploy/__init__.py +15 -0
  7. painapple_code/cli/deploy/claude_seed.py +41 -0
  8. painapple_code/cli/deploy/config.py +260 -0
  9. painapple_code/cli/deploy/container.py +715 -0
  10. painapple_code/cli/deploy/launch.py +163 -0
  11. painapple_code/cli/deploy/runtime.py +223 -0
  12. painapple_code/cli/lifecycle_cmd.py +443 -0
  13. painapple_code/cli/list_cmd.py +572 -0
  14. painapple_code/cli/manage_cmd.py +670 -0
  15. painapple_code/cli/netinfo.py +125 -0
  16. painapple_code/cli/profiles.py +390 -0
  17. painapple_code/cli/serve_args.py +163 -0
  18. painapple_code/cli/serve_config.py +256 -0
  19. painapple_code/cli/setup_cmd.py +664 -0
  20. painapple_code/cli/ui.py +438 -0
  21. painapple_code/cost_analytics.py +879 -0
  22. painapple_code/data/models.defaults.yaml +18 -0
  23. painapple_code/data/models.yaml +18 -0
  24. painapple_code/data/presets.defaults.json +32 -0
  25. painapple_code/data/strings.yaml +2269 -0
  26. painapple_code/helpers.py +406 -0
  27. painapple_code/paths.py +1514 -0
  28. painapple_code/prompt_explorer.py +984 -0
  29. painapple_code/providers/__init__.py +224 -0
  30. painapple_code/providers/base.py +710 -0
  31. painapple_code/providers/claude/__init__.py +74 -0
  32. painapple_code/providers/claude/capabilities.py +218 -0
  33. painapple_code/providers/claude/errors.py +79 -0
  34. painapple_code/providers/claude/launch.py +50 -0
  35. painapple_code/providers/claude/summary.py +89 -0
  36. painapple_code/providers/claude/translate.py +74 -0
  37. painapple_code/providers/claude_sdk/__init__.py +139 -0
  38. painapple_code/providers/claude_sdk/driver.py +412 -0
  39. painapple_code/providers/codex/__init__.py +87 -0
  40. painapple_code/providers/codex/capabilities.py +321 -0
  41. painapple_code/providers/codex/errors.py +70 -0
  42. painapple_code/providers/codex/launch.py +142 -0
  43. painapple_code/providers/codex/summary.py +196 -0
  44. painapple_code/providers/codex/translate.py +204 -0
  45. painapple_code/providers/codex_app_server/__init__.py +100 -0
  46. painapple_code/providers/codex_app_server/capabilities.py +41 -0
  47. painapple_code/providers/codex_app_server/launch.py +202 -0
  48. painapple_code/providers/codex_app_server/summary.py +291 -0
  49. painapple_code/providers/codex_app_server/translate.py +263 -0
  50. painapple_code/providers/codex_app_server/transport.py +238 -0
  51. painapple_code/routes/__init__.py +0 -0
  52. painapple_code/routes/api_agents.py +441 -0
  53. painapple_code/routes/api_app.py +368 -0
  54. painapple_code/routes/api_app_commit_sections.py +127 -0
  55. painapple_code/routes/api_app_config.py +997 -0
  56. painapple_code/routes/api_app_session_prefs.py +217 -0
  57. painapple_code/routes/api_browser.py +690 -0
  58. painapple_code/routes/api_commands.py +374 -0
  59. painapple_code/routes/api_costs.py +128 -0
  60. painapple_code/routes/api_drafts.py +139 -0
  61. painapple_code/routes/api_exec.py +149 -0
  62. painapple_code/routes/api_files.py +542 -0
  63. painapple_code/routes/api_git.py +657 -0
  64. painapple_code/routes/api_logs.py +649 -0
  65. painapple_code/routes/api_plugins.py +275 -0
  66. painapple_code/routes/api_project_config.py +418 -0
  67. painapple_code/routes/api_prompts.py +231 -0
  68. painapple_code/routes/api_providers.py +53 -0
  69. painapple_code/routes/api_search.py +411 -0
  70. painapple_code/routes/api_session_stash.py +234 -0
  71. painapple_code/routes/api_session_welcome.py +151 -0
  72. painapple_code/routes/api_sessions.py +742 -0
  73. painapple_code/routes/api_shadow.py +323 -0
  74. painapple_code/routes/api_shadow_db.py +512 -0
  75. painapple_code/routes/api_shadow_files.py +332 -0
  76. painapple_code/routes/api_shadow_search.py +476 -0
  77. painapple_code/routes/api_skills.py +610 -0
  78. painapple_code/routes/api_tasks.py +147 -0
  79. painapple_code/routes/api_terminal.py +540 -0
  80. painapple_code/routes/api_upload.py +293 -0
  81. painapple_code/routes/api_viewer.py +229 -0
  82. painapple_code/routes/dependencies.py +109 -0
  83. painapple_code/routes/ws_chat.py +837 -0
  84. painapple_code/server.py +2208 -0
  85. painapple_code/server_logging.py +263 -0
  86. painapple_code/services/__init__.py +0 -0
  87. painapple_code/services/agent_session.py +2738 -0
  88. painapple_code/session_store.py +253 -0
  89. painapple_code/session_store_core.py +879 -0
  90. painapple_code/shadow_db.py +830 -0
  91. painapple_code/shadow_db_plans.py +369 -0
  92. painapple_code/shadow_db_queries.py +595 -0
  93. painapple_code/shadow_db_schema.py +676 -0
  94. painapple_code/shadow_git.py +1296 -0
  95. painapple_code/shadow_git_frontmatter.py +314 -0
  96. painapple_code/shadow_git_sections.py +520 -0
  97. painapple_code/shadow_git_summary.py +462 -0
  98. painapple_code/shadow_parser.py +560 -0
  99. painapple_code/static/css/00-variables.css +276 -0
  100. painapple_code/static/css/01-base.css +245 -0
  101. painapple_code/static/css/02-tooltips.css +36 -0
  102. painapple_code/static/css/09-left-rail.css +448 -0
  103. painapple_code/static/css/10-header.css +777 -0
  104. painapple_code/static/css/11-connection-bar.css +120 -0
  105. painapple_code/static/css/20-messages.css +750 -0
  106. painapple_code/static/css/21-tool-blocks.css +2340 -0
  107. painapple_code/static/css/22-edit-diff.css +619 -0
  108. painapple_code/static/css/23-thinking.css +1584 -0
  109. painapple_code/static/css/24-background-tasks.css +359 -0
  110. painapple_code/static/css/25-context-block.css +252 -0
  111. painapple_code/static/css/26-session-setup.css +144 -0
  112. painapple_code/static/css/30-markdown.css +854 -0
  113. painapple_code/static/css/40-input.css +2418 -0
  114. painapple_code/static/css/41-autocomplete.css +127 -0
  115. painapple_code/static/css/42-activity-strip.css +97 -0
  116. painapple_code/static/css/43-file-autocomplete.css +121 -0
  117. painapple_code/static/css/44-snippets-autocomplete.css +224 -0
  118. painapple_code/static/css/45-selection-bar.css +433 -0
  119. painapple_code/static/css/46-keyboard-bar.css +119 -0
  120. painapple_code/static/css/47-keyboard-longpress.css +116 -0
  121. painapple_code/static/css/47-token-profile.css +106 -0
  122. painapple_code/static/css/50-welcome.css +3095 -0
  123. painapple_code/static/css/51-modals.css +301 -0
  124. painapple_code/static/css/52-utilities.css +77 -0
  125. painapple_code/static/css/53-image-upload.css +456 -0
  126. painapple_code/static/css/54-todo-list.css +102 -0
  127. painapple_code/static/css/55-file-upload.css +113 -0
  128. painapple_code/static/css/56-chat-navigator.css +218 -0
  129. painapple_code/static/css/56-permission-card.css +332 -0
  130. painapple_code/static/css/56-plan-approval.css +204 -0
  131. painapple_code/static/css/56-question-form.css +602 -0
  132. painapple_code/static/css/57-swipe-indicator.css +95 -0
  133. painapple_code/static/css/58-session-families.css +627 -0
  134. painapple_code/static/css/59-about.css +196 -0
  135. painapple_code/static/css/61-log-explorer.css +723 -0
  136. painapple_code/static/css/62-json-tree.css +489 -0
  137. painapple_code/static/css/62-skills-widget.css +650 -0
  138. painapple_code/static/css/63-commands-widget.css +30 -0
  139. painapple_code/static/css/63-plugins-widget.css +174 -0
  140. painapple_code/static/css/63-terminal.css +516 -0
  141. painapple_code/static/css/64-search-files-widget.css +448 -0
  142. painapple_code/static/css/65-snippets-widget.css +426 -0
  143. painapple_code/static/css/66-active-sessions.css +979 -0
  144. painapple_code/static/css/66-agents-widget.css +265 -0
  145. painapple_code/static/css/66-file-explorer-widget.css +855 -0
  146. painapple_code/static/css/66-git-panel.css +791 -0
  147. painapple_code/static/css/66-history-explorer.css +1496 -0
  148. painapple_code/static/css/67-diff-viewer.css +602 -0
  149. painapple_code/static/css/67-editor-view.css +748 -0
  150. painapple_code/static/css/67-file-preview-widget.css +1873 -0
  151. painapple_code/static/css/68-browser-widget.css +337 -0
  152. painapple_code/static/css/68-compare-wizard.css +355 -0
  153. painapple_code/static/css/68-csv-preview.css +106 -0
  154. painapple_code/static/css/68-diff-preview.css +103 -0
  155. painapple_code/static/css/68-helpers-install-widget.css +491 -0
  156. painapple_code/static/css/68-image-annotate.css +346 -0
  157. painapple_code/static/css/68-terminal-view.css +98 -0
  158. painapple_code/static/css/68-uploads-widget.css +229 -0
  159. painapple_code/static/css/69-cost-analytics.css +537 -0
  160. painapple_code/static/css/70-config-panel.css +3736 -0
  161. painapple_code/static/css/70-excalidraw.css +136 -0
  162. painapple_code/static/css/70-prompt-explorer.css +890 -0
  163. painapple_code/static/css/71-chart.css +111 -0
  164. painapple_code/static/css/72-discussion-sidebar.css +678 -0
  165. painapple_code/static/css/74-debug-logs.css +656 -0
  166. painapple_code/static/css/80-open-dialog.css +146 -0
  167. painapple_code/static/css/80-quick-switcher.css +383 -0
  168. painapple_code/static/css/80-widget-system.css +1763 -0
  169. painapple_code/static/css/81-quick-actions.css +1020 -0
  170. painapple_code/static/css/82-context-popover.css +1233 -0
  171. painapple_code/static/css/83-context-menu.css +339 -0
  172. painapple_code/static/css/85-lazy-loading.css +102 -0
  173. painapple_code/static/css/86-zen-mode.css +708 -0
  174. painapple_code/static/css/87-grid-switcher.css +346 -0
  175. painapple_code/static/css/login.css +198 -0
  176. painapple_code/static/dist/app.bundle.js +7177 -0
  177. painapple_code/static/feature-triage.html +446 -0
  178. painapple_code/static/icons/apple-touch-icon.png +0 -0
  179. painapple_code/static/icons/favicon-32.png +0 -0
  180. painapple_code/static/icons/favicon.ico +0 -0
  181. painapple_code/static/icons/icon-128.png +0 -0
  182. painapple_code/static/icons/icon-144.png +0 -0
  183. painapple_code/static/icons/icon-152.png +0 -0
  184. painapple_code/static/icons/icon-180.png +0 -0
  185. painapple_code/static/icons/icon-192.png +0 -0
  186. painapple_code/static/icons/icon-384.png +0 -0
  187. painapple_code/static/icons/icon-512.png +0 -0
  188. painapple_code/static/icons/icon-72.png +0 -0
  189. painapple_code/static/icons/icon-96.png +0 -0
  190. painapple_code/static/js/action-delegate.js +187 -0
  191. painapple_code/static/js/activity-strip.js +193 -0
  192. painapple_code/static/js/app/context-menus.js +619 -0
  193. painapple_code/static/js/app/file-preview.js +163 -0
  194. painapple_code/static/js/app/init-ui.js +574 -0
  195. painapple_code/static/js/app/input-events.js +561 -0
  196. painapple_code/static/js/app/input-resize.js +313 -0
  197. painapple_code/static/js/app/message-actions.js +419 -0
  198. painapple_code/static/js/app/panels.js +210 -0
  199. painapple_code/static/js/app/rendering-delegators.js +246 -0
  200. painapple_code/static/js/app/server-loading.js +365 -0
  201. painapple_code/static/js/app/session-ops.js +287 -0
  202. painapple_code/static/js/app/session-switch.js +443 -0
  203. painapple_code/static/js/app/settings-helpers.js +280 -0
  204. painapple_code/static/js/app/startup-welcome.js +290 -0
  205. painapple_code/static/js/app-context.js +157 -0
  206. painapple_code/static/js/app.js +2134 -0
  207. painapple_code/static/js/auth-fetch.js +46 -0
  208. painapple_code/static/js/background-tasks.js +274 -0
  209. painapple_code/static/js/boot.js +73 -0
  210. painapple_code/static/js/caret-position.js +171 -0
  211. painapple_code/static/js/chat-navigator.js +710 -0
  212. painapple_code/static/js/chat-search.js +323 -0
  213. painapple_code/static/js/command-executor.js +176 -0
  214. painapple_code/static/js/command-store.js +497 -0
  215. painapple_code/static/js/components.js +1414 -0
  216. painapple_code/static/js/config.js +218 -0
  217. painapple_code/static/js/context-menu.js +740 -0
  218. painapple_code/static/js/controllers/chat-controller.js +4252 -0
  219. painapple_code/static/js/controllers/dialog-controller.js +217 -0
  220. painapple_code/static/js/controllers/tab-controller.js +1828 -0
  221. painapple_code/static/js/controllers/thinking-controller.js +915 -0
  222. painapple_code/static/js/diff-utils.js +486 -0
  223. painapple_code/static/js/drafts-pill.js +95 -0
  224. painapple_code/static/js/editor-view.js +815 -0
  225. painapple_code/static/js/effort-settings.js +430 -0
  226. painapple_code/static/js/feature-triage.js +811 -0
  227. painapple_code/static/js/file-autocomplete.js +516 -0
  228. painapple_code/static/js/file-tabs.js +123 -0
  229. painapple_code/static/js/gestures.js +448 -0
  230. painapple_code/static/js/grid-switcher.js +334 -0
  231. painapple_code/static/js/input-handler.js +1472 -0
  232. painapple_code/static/js/keyboard-bar.js +495 -0
  233. painapple_code/static/js/layout-switcher.js +109 -0
  234. painapple_code/static/js/linkify-utils.js +200 -0
  235. painapple_code/static/js/login.js +141 -0
  236. painapple_code/static/js/open-dialog.js +879 -0
  237. painapple_code/static/js/orphan-terminals.js +373 -0
  238. painapple_code/static/js/path-utils.js +179 -0
  239. painapple_code/static/js/perf-marks.js +102 -0
  240. painapple_code/static/js/permission-settings.js +475 -0
  241. painapple_code/static/js/pointer-input.js +59 -0
  242. painapple_code/static/js/preview/json-tree-menu.js +226 -0
  243. painapple_code/static/js/preview/json-tree-toolbar.js +291 -0
  244. painapple_code/static/js/preview/json-tree.js +457 -0
  245. painapple_code/static/js/preview/preview-breadcrumb.js +387 -0
  246. painapple_code/static/js/preview/preview-edit.js +367 -0
  247. painapple_code/static/js/preview/preview-events.js +361 -0
  248. painapple_code/static/js/preview/preview-history.js +567 -0
  249. painapple_code/static/js/preview/preview-inline-edit.js +869 -0
  250. painapple_code/static/js/preview/preview-poll.js +108 -0
  251. painapple_code/static/js/preview/preview-render.js +572 -0
  252. painapple_code/static/js/preview/preview-search.js +421 -0
  253. painapple_code/static/js/preview/preview-state.js +256 -0
  254. painapple_code/static/js/preview/preview-utils.js +251 -0
  255. painapple_code/static/js/preview-plugins/chart-plugin.js +22 -0
  256. painapple_code/static/js/preview-plugins/csv-plugin.js +188 -0
  257. painapple_code/static/js/preview-plugins/diff-plugin.js +258 -0
  258. painapple_code/static/js/preview-plugins/excalidraw-plugin.js +25 -0
  259. painapple_code/static/js/preview-plugins/html-plugin.js +104 -0
  260. painapple_code/static/js/preview-plugins/image-plugin.js +20 -0
  261. painapple_code/static/js/preview-plugins/index.js +34 -0
  262. painapple_code/static/js/preview-plugins/json-plugin.js +99 -0
  263. painapple_code/static/js/preview-plugins/jsonl-plugin.js +152 -0
  264. painapple_code/static/js/preview-plugins/markdown-plugin.js +266 -0
  265. painapple_code/static/js/preview-plugins/panzoom-plugin.js +63 -0
  266. painapple_code/static/js/preview-plugins/plugin-helpers.js +282 -0
  267. painapple_code/static/js/project-color-picker.js +110 -0
  268. painapple_code/static/js/project-colors.js +163 -0
  269. painapple_code/static/js/prompt-favorites.js +187 -0
  270. painapple_code/static/js/quick-actions-menu.js +1736 -0
  271. painapple_code/static/js/quick-actions-registry.js +1239 -0
  272. painapple_code/static/js/quick-switcher/controller.js +294 -0
  273. painapple_code/static/js/quick-switcher/fuzzy-scorer.js +123 -0
  274. painapple_code/static/js/quick-switcher/index.js +30 -0
  275. painapple_code/static/js/quick-switcher/providers/base-provider.js +51 -0
  276. painapple_code/static/js/quick-switcher/providers/command-provider.js +56 -0
  277. painapple_code/static/js/quick-switcher/providers/file-provider.js +291 -0
  278. painapple_code/static/js/quick-switcher/providers/panel-provider.js +132 -0
  279. painapple_code/static/js/quick-switcher/providers/project-provider.js +361 -0
  280. painapple_code/static/js/quick-switcher/providers/read-files-provider.js +104 -0
  281. painapple_code/static/js/quick-switcher/providers/skills-provider.js +129 -0
  282. painapple_code/static/js/quick-switcher/registry.js +69 -0
  283. painapple_code/static/js/quick-switcher/ui/item.js +54 -0
  284. painapple_code/static/js/quick-switcher/ui/picker.js +464 -0
  285. painapple_code/static/js/recent-opens.js +40 -0
  286. painapple_code/static/js/scroll-manager.js +530 -0
  287. painapple_code/static/js/scroll-state-machine.js +359 -0
  288. painapple_code/static/js/selection/action-bar.js +793 -0
  289. painapple_code/static/js/selection/index.js +15 -0
  290. painapple_code/static/js/selection/selection-handler.js +877 -0
  291. painapple_code/static/js/selection/state.js +181 -0
  292. painapple_code/static/js/session/agent-progress.js +202 -0
  293. painapple_code/static/js/session/handle-agent-message.js +481 -0
  294. painapple_code/static/js/session/handle-message.js +550 -0
  295. painapple_code/static/js/session/interactive.js +587 -0
  296. painapple_code/static/js/session/message-store.js +271 -0
  297. painapple_code/static/js/session/messages.js +253 -0
  298. painapple_code/static/js/session/persistence.js +179 -0
  299. painapple_code/static/js/session/restore.js +136 -0
  300. painapple_code/static/js/session/sync.js +333 -0
  301. painapple_code/static/js/session-container-pool.js +371 -0
  302. painapple_code/static/js/session-setup-panel.js +274 -0
  303. painapple_code/static/js/session.js +1047 -0
  304. painapple_code/static/js/shortcut-hints.js +272 -0
  305. painapple_code/static/js/shortcuts.js +1146 -0
  306. painapple_code/static/js/skills-autocomplete.js +262 -0
  307. painapple_code/static/js/snippets-autocomplete.js +738 -0
  308. painapple_code/static/js/stash-refs-view.js +83 -0
  309. painapple_code/static/js/stash-ui.js +768 -0
  310. painapple_code/static/js/stash.js +785 -0
  311. painapple_code/static/js/status-bar.js +1184 -0
  312. painapple_code/static/js/token-profile.js +274 -0
  313. painapple_code/static/js/tool-renderer-blocks.js +1626 -0
  314. painapple_code/static/js/tool-renderer-thinking.js +813 -0
  315. painapple_code/static/js/tool-renderer.js +1500 -0
  316. painapple_code/static/js/tooltips.js +197 -0
  317. painapple_code/static/js/upload-manager.js +1019 -0
  318. painapple_code/static/js/utils.js +521 -0
  319. painapple_code/static/js/welcome/api.js +363 -0
  320. painapple_code/static/js/welcome/cards.js +626 -0
  321. painapple_code/static/js/welcome/context-menu.js +585 -0
  322. painapple_code/static/js/welcome/families.js +801 -0
  323. painapple_code/static/js/welcome/preview.js +234 -0
  324. painapple_code/static/js/welcome/state.js +129 -0
  325. painapple_code/static/js/welcome.js +1874 -0
  326. painapple_code/static/js/widget-system/base-widget.js +717 -0
  327. painapple_code/static/js/widget-system/device-manager.js +178 -0
  328. painapple_code/static/js/widget-system/event-bus.js +152 -0
  329. painapple_code/static/js/widget-system/icons.js +120 -0
  330. painapple_code/static/js/widget-system/index.js +49 -0
  331. painapple_code/static/js/widget-system/init.js +54 -0
  332. painapple_code/static/js/widget-system/types/bottom-sheet.js +307 -0
  333. painapple_code/static/js/widget-system/types/floating.js +915 -0
  334. painapple_code/static/js/widget-system/types/index.js +40 -0
  335. painapple_code/static/js/widget-system/types/modal.js +147 -0
  336. painapple_code/static/js/widget-system/types/sidebar.js +158 -0
  337. painapple_code/static/js/widget-system/types/tab.js +146 -0
  338. painapple_code/static/js/widget-system/types/top-sheet.js +203 -0
  339. painapple_code/static/js/widget-system/widget-manager.js +1187 -0
  340. painapple_code/static/js/widgets/about-widget.js +260 -0
  341. painapple_code/static/js/widgets/active-sessions-widget.js +760 -0
  342. painapple_code/static/js/widgets/agents-widget.js +897 -0
  343. painapple_code/static/js/widgets/browser-widget.js +579 -0
  344. painapple_code/static/js/widgets/commands-widget.js +694 -0
  345. painapple_code/static/js/widgets/config/commit-sections.js +449 -0
  346. painapple_code/static/js/widgets/config/dir-autocomplete.js +224 -0
  347. painapple_code/static/js/widgets/config/gestures.js +161 -0
  348. painapple_code/static/js/widgets/config/models-tab.js +988 -0
  349. painapple_code/static/js/widgets/config/quick-actions-tab.js +882 -0
  350. painapple_code/static/js/widgets/config/shortcut-editor.js +587 -0
  351. painapple_code/static/js/widgets/config/state.js +517 -0
  352. painapple_code/static/js/widgets/config/system-controls.js +90 -0
  353. painapple_code/static/js/widgets/config-widget.js +1535 -0
  354. painapple_code/static/js/widgets/cost-analytics-widget.js +621 -0
  355. painapple_code/static/js/widgets/debug-widget.js +693 -0
  356. painapple_code/static/js/widgets/diff-viewer-widget.js +1420 -0
  357. painapple_code/static/js/widgets/discussion-widget.js +1107 -0
  358. painapple_code/static/js/widgets/file-explorer-widget.js +2166 -0
  359. painapple_code/static/js/widgets/file-preview-widget.js +861 -0
  360. painapple_code/static/js/widgets/git-widget.js +794 -0
  361. painapple_code/static/js/widgets/helpers-install-widget.js +720 -0
  362. painapple_code/static/js/widgets/history-explorer-widget.js +1804 -0
  363. painapple_code/static/js/widgets/image-annotate-widget.js +951 -0
  364. painapple_code/static/js/widgets/image-preview-widget.js +692 -0
  365. painapple_code/static/js/widgets/index.js +176 -0
  366. painapple_code/static/js/widgets/log-explorer-widget.js +1057 -0
  367. painapple_code/static/js/widgets/plugins-widget.js +305 -0
  368. painapple_code/static/js/widgets/prompt-explorer-widget.js +1119 -0
  369. painapple_code/static/js/widgets/search-files-widget.js +529 -0
  370. painapple_code/static/js/widgets/skills-widget.js +843 -0
  371. painapple_code/static/js/widgets/snippets-widget.js +479 -0
  372. painapple_code/static/js/widgets/sub-agents-widget.js +333 -0
  373. painapple_code/static/js/widgets/tasks-widget.js +379 -0
  374. painapple_code/static/js/widgets/terminal/connection.js +283 -0
  375. painapple_code/static/js/widgets/terminal/gestures.js +357 -0
  376. painapple_code/static/js/widgets/terminal/init.js +642 -0
  377. painapple_code/static/js/widgets/terminal/link-providers.js +532 -0
  378. painapple_code/static/js/widgets/terminal/osc52.js +213 -0
  379. painapple_code/static/js/widgets/terminal/render.js +159 -0
  380. painapple_code/static/js/widgets/terminal/size.js +54 -0
  381. painapple_code/static/js/widgets/terminal/state.js +211 -0
  382. painapple_code/static/js/widgets/terminal/wrap-utils.js +101 -0
  383. painapple_code/static/js/widgets/terminal-widget.js +793 -0
  384. painapple_code/static/js/widgets/uploads-widget.js +461 -0
  385. painapple_code/static/js/widgets/zen-widget.js +1001 -0
  386. painapple_code/static/login.html +51 -0
  387. painapple_code/static/manifest.json +73 -0
  388. painapple_code/static/sw.js +293 -0
  389. painapple_code/static/vendor/LICENSES.txt +769 -0
  390. painapple_code/static/vendor/README.md +103 -0
  391. painapple_code/static/vendor/codemirror.js +35 -0
  392. painapple_code/static/vendor/codemirror.js.LEGAL.txt +304 -0
  393. painapple_code/static/vendor/github-markdown-dark.min.css +1124 -0
  394. painapple_code/static/vendor/highlight-github-dark.min.css +10 -0
  395. painapple_code/static/vendor/highlight-lang-dockerfile.min.js +8 -0
  396. painapple_code/static/vendor/highlight-lang-nginx.min.js +21 -0
  397. painapple_code/static/vendor/highlight-lang-properties.min.js +10 -0
  398. painapple_code/static/vendor/highlight-lang-scala.min.js +28 -0
  399. painapple_code/static/vendor/highlight.min.js +1213 -0
  400. painapple_code/static/vendor/marked.min.js +6 -0
  401. painapple_code/static/vendor/purify.min.js +3 -0
  402. painapple_code/static/vendor/xterm-addon-fit.js +2 -0
  403. painapple_code/static/vendor/xterm.css +209 -0
  404. painapple_code/static/vendor/xterm.js +2 -0
  405. painapple_code/static/web-client.html +635 -0
  406. painapple_code/subprocess_registry.py +535 -0
  407. painapple_code/tls_cert.py +79 -0
  408. painapple_code/tools/agents/shadow-git-helper.md +400 -0
  409. painapple_code/tools/excalidraw-to-svg.js +143 -0
  410. painapple_code/tools/install-helpers.sh +148 -0
  411. painapple_code/tools/shadow-git +320 -0
  412. painapple_code/tools/shadow-query +120 -0
  413. painapple_code/tools/vegalite-to-svg.js +79 -0
  414. painapple_code/turn_query.py +766 -0
  415. painapple_code/turn_tracker.py +221 -0
  416. painapple_code/utils/__init__.py +0 -0
  417. painapple_code/utils/agent_cli.py +306 -0
  418. painapple_code/utils/chart.py +103 -0
  419. painapple_code/utils/excalidraw.py +107 -0
  420. painapple_code/utils/file_lock.py +162 -0
  421. painapple_code/utils/file_paths.py +648 -0
  422. painapple_code/utils/generate_icons.py +251 -0
  423. painapple_code/utils/proc.py +205 -0
  424. painapple_code/utils/pty_backend.py +59 -0
  425. painapple_code/utils/pty_posix.py +160 -0
  426. painapple_code/utils/pty_windows.py +245 -0
  427. painapple_code/utils/token_profiles.py +91 -0
  428. painapple_code/viewer_templates.py +657 -0
  429. painapple_code/welcome_search.py +879 -0
  430. painapple_code-1.0.0.dist-info/METADATA +292 -0
  431. painapple_code-1.0.0.dist-info/RECORD +436 -0
  432. painapple_code-1.0.0.dist-info/WHEEL +5 -0
  433. painapple_code-1.0.0.dist-info/entry_points.txt +2 -0
  434. painapple_code-1.0.0.dist-info/licenses/LICENSE +661 -0
  435. painapple_code-1.0.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +261 -0
  436. painapple_code-1.0.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,1736 @@
1
+ /**
2
+ * Quick Actions Radial Menu
3
+ *
4
+ * A floating action button that expands into a radial menu for quick access
5
+ * to common actions. Replaces the debug FAB with a more powerful interface.
6
+ *
7
+ * Features:
8
+ * - Radial menu layout with configurable actions
9
+ * - Tap-to-open, tap-to-select interaction
10
+ * - Press-drag-release for power users (optional)
11
+ * - Draggable FAB position
12
+ * - Smooth animations with staggered reveals
13
+ * - Context-aware action swapping
14
+ * - Configurable via Settings
15
+ * - Context menu with search and preset switching (right-click / long-press)
16
+ */
17
+
18
+ import { Storage } from './utils.js';
19
+ import { QuickActionsRegistry, DEFAULT_QUICK_ACTIONS_CONFIG, QUICK_ACTION_PRESETS, updatePresets, syncCustomActions } from './quick-actions-registry.js';
20
+ // Note: showConfigPanel is imported dynamically to avoid circular dependency with config-widget.js
21
+ import { TooltipManager } from './tooltips.js';
22
+ import { WidgetBus } from './widget-system/index.js';
23
+ import S from './strings.js';
24
+ import { debug } from './config.js';
25
+
26
+ // ─────────────────────────────────────────────────────────────────────────────
27
+ // Constants
28
+ // ─────────────────────────────────────────────────────────────────────────────
29
+
30
+ const STORAGE_KEY = 'claude-quick-actions';
31
+ /**
32
+ * Compute default FAB position. On wide screens, sits just outside the 900px content area.
33
+ */
34
+ function getDefaultPosition() {
35
+ const vw = window.innerWidth;
36
+ let right = 16;
37
+ if (vw > 1100) {
38
+ const style = getComputedStyle(document.documentElement);
39
+ const padding = parseFloat(style.getPropertyValue('--layout-content-padding')) || 14;
40
+ const rail = parseFloat(style.getPropertyValue('--left-rail-width')) || 48;
41
+ // Place FAB past content + gutter arrows (rail + padding + 900 + 56px clearance)
42
+ right = vw - rail - padding - 900 - 56 - 52; // 52 = FAB width
43
+ }
44
+ return { right, bottom: 100 };
45
+ }
46
+ const DRAG_THRESHOLD = 8;
47
+ const MENU_RADIUS = 80; // Distance from center to items
48
+ const ITEM_SIZE = 48; // Item diameter (44px + buffer)
49
+ const EDGE_PADDING = 12; // Minimum distance from viewport edge
50
+ const LONG_PRESS_DELAY = 300; // ms for drag-release mode
51
+ const CONTEXT_MENU_LONG_PRESS = 500; // ms for context menu on mobile
52
+
53
+ // Keyboard shortcuts: 1-4 for top arc (L→R), Q-W-E-R for bottom arc (L→R)
54
+ // Bottom arc positions go clockwise (R→L visually), so keys are assigned in reverse
55
+ // to make them read left-to-right: position n-1 gets Q, position n-2 gets W, etc.
56
+ const ALL_KEYS = ['1', '2', '3', '4', 'q', 'w', 'e', 'r'];
57
+ const ALL_LABELS = ['1', '2', '3', '4', 'Q', 'W', 'E', 'R'];
58
+
59
+ /**
60
+ * Get the key label for a slot position (handles bottom-arc reversal)
61
+ */
62
+ function getSlotKeyLabel(position, totalSlots) {
63
+ if (position < 4) {
64
+ return ALL_LABELS[position];
65
+ }
66
+ // Bottom arc: reverse so it reads L→R visually
67
+ const keyIndex = 4 + (totalSlots - 1 - position);
68
+ return keyIndex < ALL_LABELS.length ? ALL_LABELS[keyIndex] : '';
69
+ }
70
+
71
+ /**
72
+ * Get the slot position for a key press (handles bottom-arc reversal)
73
+ */
74
+ function getSlotForKey(key, totalSlots) {
75
+ const k = key.toLowerCase();
76
+ const keyIndex = ALL_KEYS.indexOf(k);
77
+ if (keyIndex === -1) return -1;
78
+
79
+ if (keyIndex < 4) {
80
+ return keyIndex < totalSlots ? keyIndex : -1;
81
+ }
82
+ // Q→position n-1, W→position n-2, E→position n-3, R→position n-4
83
+ const position = totalSlots - 1 - (keyIndex - 4);
84
+ return position >= 4 ? position : -1;
85
+ }
86
+
87
+ // Feather icons SVG paths (subset we need)
88
+ const ICONS = {
89
+ 'plus-circle': '<circle cx="12" cy="12" r="10"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/>',
90
+ 'x': '<line x1="18" y1="6" x2="6" y2="18"/><line x1="6" y1="6" x2="18" y2="18"/>',
91
+ 'chevron-left': '<polyline points="15 18 9 12 15 6"/>',
92
+ 'chevron-right': '<polyline points="9 18 15 12 9 6"/>',
93
+ 'git-branch': '<line x1="6" y1="3" x2="6" y2="15"/><circle cx="18" cy="6" r="3"/><circle cx="6" cy="18" r="3"/><path d="M18 9a9 9 0 0 1-9 9"/>',
94
+ 'copy': '<rect x="9" y="9" width="13" height="13" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>',
95
+ 'edit-3': '<path d="M12 20h9"/><path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"/>',
96
+ 'terminal': '<polyline points="4 17 10 11 4 5"/><line x1="12" y1="19" x2="20" y2="19"/>',
97
+ 'plus-square': '<rect x="3" y="3" width="18" height="18" rx="2"/><line x1="12" y1="8" x2="12" y2="16"/><line x1="8" y1="12" x2="16" y2="12"/>',
98
+ 'folder': '<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/>',
99
+ 'scroll': '<path d="M8 21h12a2 2 0 0 0 2-2v-2H10v2a2 2 0 1 1-4 0V5a2 2 0 1 0-4 0v3h4"/><path d="M19 3H9a2 2 0 0 0-2 2v11a2 2 0 0 1 2-2h8"/>',
100
+ 'file-diff': '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="12" y1="18" x2="12" y2="12"/><line x1="9" y1="15" x2="15" y2="15"/>',
101
+ 'git-merge': '<circle cx="18" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><path d="M6 21V9a9 9 0 0 0 9 9"/>',
102
+ 'dollar-sign': '<line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/>',
103
+ 'dollarSign': '<line x1="12" y1="1" x2="12" y2="23"/><path d="M17 5H9.5a3.5 3.5 0 0 0 0 7h5a3.5 3.5 0 0 1 0 7H6"/>',
104
+ 'coins': '<circle cx="8" cy="8" r="6"/><path d="M18.09 10.37A6 6 0 1 1 10.34 18"/><path d="M7 6h1v4"/><path d="m16.71 13.88.7.71-2.82 2.82"/>',
105
+ 'activity': '<polyline points="22 12 18 12 15 21 9 3 6 12 2 12"/>',
106
+ 'database': '<ellipse cx="12" cy="5" rx="9" ry="3"/><path d="M21 12c0 1.66-4 3-9 3s-9-1.34-9-3"/><path d="M3 5v14c0 1.66 4 3 9 3s9-1.34 9-3V5"/>',
107
+ 'message-circle': '<path d="M21 11.5a8.38 8.38 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.38 8.38 0 0 1-3.8-.9L3 21l1.9-5.7a8.38 8.38 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.38 8.38 0 0 1 3.8-.9h.5a8.48 8.48 0 0 1 8 8v.5z"/>',
108
+ 'bug': '<path d="M8 2l1.88 1.88"/><path d="M14.12 3.88 16 2"/><path d="M9 7.13v-1a3.003 3.003 0 1 1 6 0v1"/><path d="M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6"/><path d="M12 20v-9"/><path d="M6.53 9C4.6 8.8 3 7.1 3 5"/><path d="M6 13H2"/><path d="M3 21c0-2.1 1.7-3.9 3.8-4"/><path d="M20.97 5c0 2.1-1.6 3.8-3.5 4"/><path d="M22 13h-4"/><path d="M17.2 17c2.1.1 3.8 1.9 3.8 4"/>',
109
+ 'settings': '<circle cx="12" cy="12" r="3"/><path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>',
110
+ 'help-circle': '<circle cx="12" cy="12" r="10"/><path d="M9.09 9a3 3 0 0 1 5.83 1c0 2-3 3-3 3"/><line x1="12" y1="17" x2="12.01" y2="17"/>',
111
+ 'square': '<rect x="3" y="3" width="18" height="18" rx="2"/>',
112
+ 'trash-2': '<polyline points="3 6 5 6 21 6"/><path d="M19 6v14a2 2 0 0 1-2 2H7a2 2 0 0 1-2-2V6m3 0V4a2 2 0 0 1 2-2h4a2 2 0 0 1 2 2v2"/><line x1="10" y1="11" x2="10" y2="17"/><line x1="14" y1="11" x2="14" y2="17"/>',
113
+ 'minimize-2': '<polyline points="4 14 10 14 10 20"/><polyline points="20 10 14 10 14 4"/><line x1="14" y1="10" x2="21" y2="3"/><line x1="3" y1="21" x2="10" y2="14"/>',
114
+ 'chevrons-down': '<polyline points="7 13 12 18 17 13"/><polyline points="7 6 12 11 17 6"/>',
115
+ 'chevrons-up': '<polyline points="17 11 12 6 7 11"/><polyline points="17 18 12 13 7 18"/>',
116
+ 'maximize-2': '<polyline points="15 3 21 3 21 9"/><polyline points="9 21 3 21 3 15"/><line x1="21" y1="3" x2="14" y2="10"/><line x1="3" y1="21" x2="10" y2="14"/>',
117
+ 'edit': '<path d="M11 4H4a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h14a2 2 0 0 0 2-2v-7"/><path d="M18.5 2.5a2.121 2.121 0 0 1 3 3L12 15l-4 1 1-4 9.5-9.5z"/>',
118
+ 'clipboard': '<path d="M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2"/><rect x="8" y="2" width="8" height="4" rx="1"/>',
119
+ 'code': '<polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>',
120
+ 'bookmark-plus': '<path d="M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"/><line x1="12" y1="7" x2="12" y2="13"/><line x1="9" y1="10" x2="15" y2="10"/>',
121
+ 'bookmark': '<path d="M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"/>',
122
+ 'bookmark-minus': '<path d="M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"/><line x1="9" y1="10" x2="15" y2="10"/>',
123
+ 'search': '<circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>',
124
+ 'file-plus': '<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/><line x1="12" y1="18" x2="12" y2="12"/><line x1="9" y1="15" x2="15" y2="15"/>',
125
+ 'image': '<rect x="3" y="3" width="18" height="18" rx="2"/><circle cx="8.5" cy="8.5" r="1.5"/><polyline points="21 15 16 10 5 21"/>',
126
+ 'paperclip': '<path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"/>',
127
+ 'camera': '<path d="M23 19a2 2 0 0 1-2 2H3a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h4l2-3h6l2 3h4a2 2 0 0 1 2 2z"/><circle cx="12" cy="13" r="4"/>',
128
+ 'folder-open': '<path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/><path d="M2 10h20"/>',
129
+ 'home': '<path d="M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z"/><polyline points="9 22 9 12 15 12 15 22"/>',
130
+ 'arrow-left': '<line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/>',
131
+ 'clock': '<circle cx="12" cy="12" r="10"/><polyline points="12 6 12 12 16 14"/>',
132
+ 'star': '<polygon points="12 2 15.09 8.26 22 9.27 17 14.14 18.18 21.02 12 17.77 5.82 21.02 7 14.14 2 9.27 8.91 8.26 12 2"/>',
133
+ 'refresh-cw': '<polyline points="23 4 23 10 17 10"/><polyline points="1 20 1 14 7 14"/><path d="M3.51 9a9 9 0 0 1 14.85-3.36L23 10M1 14l4.64 4.36A9 9 0 0 0 20.49 15"/>',
134
+ 'wifi': '<path d="M5 12.55a11 11 0 0 1 14.08 0"/><path d="M1.42 9a16 16 0 0 1 21.16 0"/><path d="M8.53 16.11a6 6 0 0 1 6.95 0"/><line x1="12" y1="20" x2="12.01" y2="20"/>',
135
+ 'moon': '<path d="M21 12.79A9 9 0 1 1 11.21 3 7 7 0 0 0 21 12.79z"/>',
136
+ 'maximize': '<path d="M8 3H5a2 2 0 0 0-2 2v3m18 0V5a2 2 0 0 0-2-2h-3m0 18h3a2 2 0 0 0 2-2v-3M3 16v3a2 2 0 0 0 2 2h3"/>',
137
+ 'share-2': '<circle cx="18" cy="5" r="3"/><circle cx="6" cy="12" r="3"/><circle cx="18" cy="19" r="3"/><line x1="8.59" y1="13.51" x2="15.42" y2="17.49"/><line x1="15.41" y1="6.51" x2="8.59" y2="10.49"/>',
138
+ 'slash': '<circle cx="12" cy="12" r="10"/><line x1="4.93" y1="4.93" x2="19.07" y2="19.07"/>',
139
+ 'play': '<polygon points="5 3 19 12 5 21 5 3"/>',
140
+ 'package': '<line x1="16.5" y1="9.4" x2="7.5" y2="4.21"/><path d="M21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16z"/><polyline points="3.27 6.96 12 12.01 20.73 6.96"/><line x1="12" y1="22.08" x2="12" y2="12"/>',
141
+ 'check-circle': '<path d="M22 11.08V12a10 10 0 1 1-5.93-9.14"/><polyline points="22 4 12 14.01 9 11.01"/>',
142
+ 'git-commit': '<circle cx="12" cy="12" r="4"/><line x1="1.05" y1="12" x2="7" y2="12"/><line x1="17.01" y1="12" x2="22.96" y2="12"/>',
143
+ 'git-pull-request': '<circle cx="18" cy="18" r="3"/><circle cx="6" cy="6" r="3"/><path d="M13 6h3a2 2 0 0 1 2 2v7"/><line x1="6" y1="9" x2="6" y2="21"/>',
144
+ 'check-square': '<polyline points="9 11 12 14 22 4"/><path d="M21 12v7a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h11"/>',
145
+ 'zap': '<polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"/>',
146
+ 'check': '<polyline points="20 6 9 17 4 12"/>',
147
+ 'crosshair': '<circle cx="12" cy="12" r="10"/><line x1="22" y1="12" x2="18" y2="12"/><line x1="6" y1="12" x2="2" y2="12"/><line x1="12" y1="6" x2="12" y2="2"/><line x1="12" y1="22" x2="12" y2="18"/>',
148
+ 'command': '<path d="M18 3a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3H6a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3V6a3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3h12a3 3 0 0 0 3-3 3 3 0 0 0-3-3z"/>',
149
+ };
150
+
151
+ // ─────────────────────────────────────────────────────────────────────────────
152
+ // Quick Actions Menu Class
153
+ // ─────────────────────────────────────────────────────────────────────────────
154
+
155
+ class QuickActionsMenu {
156
+ constructor() {
157
+ this.fab = null;
158
+ this.menu = null;
159
+ this.overlay = null;
160
+ this.contextMenu = null;
161
+ this.isOpen = false;
162
+ this.isContextMenuOpen = false;
163
+ this.visibility = 'always'; // 'always' | 'mobile' | 'disabled'
164
+ this.position = getDefaultPosition();
165
+ this.config = { ...DEFAULT_QUICK_ACTIONS_CONFIG };
166
+ // User-defined custom actions (terminal/prompt/slash) — synced into
167
+ // the registry via syncCustomActions() whenever they change
168
+ this.customActions = [];
169
+
170
+ // Drag state
171
+ this.startX = 0;
172
+ this.startY = 0;
173
+ this.startRight = 0;
174
+ this.startBottom = 0;
175
+ this.isDragging = false;
176
+ this.didDrag = false;
177
+
178
+ // Long press for drag-release mode
179
+ this.longPressTimer = null;
180
+ this.isLongPress = false;
181
+ this.highlightedIndex = -1;
182
+
183
+ // Context menu state
184
+ this.contextMenuTimer = null;
185
+ this.searchResults = [];
186
+ this.selectedResultIndex = 0;
187
+
188
+ // Store focused element to restore after action (keeps keyboard open)
189
+ this.previousFocus = null;
190
+
191
+ // Track if menu was opened at cursor position (vs FAB position)
192
+ this.openedAtCursor = false;
193
+
194
+ // Edge-aware positioning: track if we shifted the menu to fit all items
195
+ this.menuOffset = { x: 0, y: 0 };
196
+
197
+ this.loadState();
198
+ }
199
+
200
+ /**
201
+ * Load state from localStorage (position is device-local, config syncs from server)
202
+ */
203
+ loadState() {
204
+ // Load position from localStorage (device-specific)
205
+ const saved = Storage.get(STORAGE_KEY);
206
+ if (saved) {
207
+ if (saved.position) this.position = saved.position;
208
+ }
209
+
210
+ // Config (slots, preset, visibility) will be loaded from server in loadServerConfig()
211
+ // Use localStorage as fallback until server responds
212
+ if (saved?.config) {
213
+ this.config = { ...DEFAULT_QUICK_ACTIONS_CONFIG, ...saved.config };
214
+ }
215
+ if (saved?.visibility !== undefined) {
216
+ this.visibility = saved.visibility;
217
+ } else if (saved?.enabled !== undefined) {
218
+ // Migrate legacy boolean → tri-state
219
+ this.visibility = saved.enabled ? 'always' : 'disabled';
220
+ }
221
+ if (Array.isArray(saved?.customActions)) {
222
+ this.customActions = saved.customActions;
223
+ syncCustomActions(this.customActions);
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Resolve current visibility setting against device into a boolean
229
+ */
230
+ isVisibleHere() {
231
+ if (this.visibility === 'disabled') return false;
232
+ if (this.visibility === 'mobile') {
233
+ // Mobile = touch-primary devices (phones, tablets including iPad)
234
+ return window.matchMedia('(pointer: coarse)').matches;
235
+ }
236
+ return true; // 'always'
237
+ }
238
+
239
+ /**
240
+ * Load config from server (cross-device sync)
241
+ */
242
+ async loadServerConfig() {
243
+ try {
244
+ // Load presets from ~/.painapple-code/presets/*.json
245
+ const presetsRes = await fetch('/api/app/presets');
246
+ if (presetsRes.ok) {
247
+ const presets = await presetsRes.json();
248
+ if (Object.keys(presets).length > 0) {
249
+ updatePresets(presets);
250
+ this.rebuildPresetsSection();
251
+ }
252
+ }
253
+ // Load user's active config (slots, options)
254
+ const response = await fetch('/api/app/config');
255
+ if (response.ok) {
256
+ const globalConfig = await response.json();
257
+ if (globalConfig.quickActions) {
258
+ const qa = globalConfig.quickActions;
259
+ if (qa.visibility !== undefined) {
260
+ this.visibility = qa.visibility;
261
+ } else if (qa.enabled !== undefined) {
262
+ // Migrate legacy boolean → tri-state
263
+ this.visibility = qa.enabled ? 'always' : 'disabled';
264
+ }
265
+ if (qa.config) this.config = { ...DEFAULT_QUICK_ACTIONS_CONFIG, ...qa.config };
266
+ if (Array.isArray(qa.customActions)) {
267
+ this.customActions = qa.customActions;
268
+ syncCustomActions(this.customActions);
269
+ }
270
+ this.updateVisibility();
271
+ if (this.isOpen) this.renderMenuItems();
272
+ debug.log('[QuickActions] Loaded config from server');
273
+ }
274
+ }
275
+ } catch (e) {
276
+ console.warn('[QuickActions] Failed to load server config:', e);
277
+ }
278
+ }
279
+
280
+ /**
281
+ * Save state - position to localStorage, config to server
282
+ */
283
+ saveState() {
284
+ // Save position to localStorage (device-specific)
285
+ Storage.set(STORAGE_KEY, {
286
+ position: this.position,
287
+ // Keep config in localStorage as fallback
288
+ visibility: this.visibility,
289
+ config: this.config,
290
+ customActions: this.customActions
291
+ });
292
+
293
+ // Save config to server (cross-device sync)
294
+ this.saveServerConfig();
295
+ }
296
+
297
+ /**
298
+ * Save config to server (debounced)
299
+ */
300
+ saveServerConfig() {
301
+ // Debounce server saves
302
+ if (this._saveTimeout) clearTimeout(this._saveTimeout);
303
+ this._saveTimeout = setTimeout(() => this._doSaveServerConfig(), 500);
304
+ }
305
+
306
+ async _doSaveServerConfig() {
307
+ try {
308
+ // Load current global config first
309
+ const response = await fetch('/api/app/config');
310
+ const globalConfig = response.ok ? await response.json() : {};
311
+
312
+ // Update quickActions section
313
+ globalConfig.quickActions = {
314
+ visibility: this.visibility,
315
+ config: this.config,
316
+ customActions: this.customActions
317
+ };
318
+
319
+ // Save back
320
+ await fetch('/api/app/config', {
321
+ method: 'PUT',
322
+ headers: { 'Content-Type': 'application/json' },
323
+ body: JSON.stringify(globalConfig)
324
+ });
325
+ debug.log('[QuickActions] Saved config to server');
326
+ } catch (e) {
327
+ console.warn('[QuickActions] Failed to save server config:', e);
328
+ }
329
+ }
330
+
331
+ /**
332
+ * Initialize the menu - call once after DOM is ready
333
+ */
334
+ init() {
335
+ if (this.fab) return;
336
+
337
+ this.createElements();
338
+ this.attachEventListeners();
339
+ this.updateVisibility();
340
+ this.applyPosition();
341
+
342
+ // Re-evaluate visibility when device pointer type changes (mobile mode)
343
+ const coarseMq = window.matchMedia('(pointer: coarse)');
344
+ if (coarseMq.addEventListener) {
345
+ coarseMq.addEventListener('change', () => this.updateVisibility());
346
+ }
347
+
348
+ // Load config from server (async, will update UI when ready)
349
+ this.loadServerConfig();
350
+
351
+ // Listen for debug error events to show badge on FAB
352
+ WidgetBus.on('debug:errors-changed', ({ unseen }) => {
353
+ this.updateFabBadge(unseen);
354
+ });
355
+
356
+ debug.log('[QuickActions] Initialized');
357
+ }
358
+
359
+ createElements() {
360
+ // Create FAB
361
+ this.fab = document.createElement('button');
362
+ this.fab.className = 'quick-actions-fab';
363
+ this.fab.setAttribute('aria-label', 'Quick actions menu');
364
+ this.fab.setAttribute('aria-expanded', 'false');
365
+ this.fab.setAttribute('aria-haspopup', 'true');
366
+ this.fab.setAttribute('data-tooltip', 'Quick Actions - Drag to move, right-click for options');
367
+ this.fab.innerHTML = `
368
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
369
+ ${ICONS['zap']}
370
+ </svg>
371
+ `;
372
+
373
+ // Error badge on FAB
374
+ this.fabBadge = document.createElement('span');
375
+ this.fabBadge.className = 'quick-actions-fab-badge';
376
+ this.fab.appendChild(this.fabBadge);
377
+
378
+ // Create overlay for clicking outside
379
+ this.overlay = document.createElement('div');
380
+ this.overlay.className = 'quick-actions-overlay';
381
+
382
+ // Create radial menu container
383
+ this.menu = document.createElement('div');
384
+ this.menu.className = 'quick-actions-menu';
385
+ this.menu.setAttribute('role', 'menu');
386
+
387
+ // Create context menu
388
+ this.contextMenu = document.createElement('div');
389
+ this.contextMenu.className = 'quick-actions-context-menu';
390
+ this.contextMenu.innerHTML = this.renderContextMenuHTML();
391
+
392
+ // Add to DOM
393
+ document.body.appendChild(this.overlay);
394
+ document.body.appendChild(this.menu);
395
+ document.body.appendChild(this.contextMenu);
396
+ document.body.appendChild(this.fab);
397
+ }
398
+
399
+ renderContextMenuHTML() {
400
+ return `
401
+ <div class="qa-context-search">
402
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
403
+ ${ICONS['search']}
404
+ </svg>
405
+ <input type="text" placeholder="Find action..." autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false">
406
+ </div>
407
+ <div class="qa-context-results"></div>
408
+ <div class="qa-context-presets">
409
+ <div class="qa-context-section-title">Presets</div>
410
+ ${Object.entries(QUICK_ACTION_PRESETS).map(([id, preset]) => `
411
+ <button class="qa-context-preset" data-preset="${id}">
412
+ <span class="qa-preset-radio"></span>
413
+ <span class="qa-preset-name">${preset.name}</span>
414
+ <span class="qa-preset-desc">${preset.slots.length} actions</span>
415
+ </button>
416
+ `).join('')}
417
+ </div>
418
+ <div class="qa-context-footer">
419
+ <button class="qa-context-footer-item qa-debug-logs-item" data-action="debug-logs" style="display:none">
420
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
421
+ ${ICONS['bug']}
422
+ </svg>
423
+ ${S.quick_actions?.open_debug_logs || 'Open Debug Logs'}
424
+ </button>
425
+ <button class="qa-context-footer-item" data-action="customize">
426
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
427
+ ${ICONS['settings']}
428
+ </svg>
429
+ Customize...
430
+ </button>
431
+ </div>
432
+ `;
433
+ }
434
+
435
+ attachEventListeners() {
436
+ // FAB click (left click)
437
+ this.fab.addEventListener('click', (e) => {
438
+ if (this.didDrag) {
439
+ e.preventDefault();
440
+ e.stopPropagation();
441
+ return;
442
+ }
443
+ // If context menu is open, close it
444
+ if (this.isContextMenuOpen) {
445
+ e.preventDefault();
446
+ e.stopPropagation();
447
+ this.closeContextMenu();
448
+ return;
449
+ }
450
+ this.toggle();
451
+ });
452
+
453
+ // FAB right-click (context menu)
454
+ this.fab.addEventListener('contextmenu', (e) => {
455
+ e.preventDefault();
456
+ e.stopPropagation();
457
+ this.openContextMenu();
458
+ });
459
+
460
+ // Overlay click to close
461
+ this.overlay.addEventListener('click', () => {
462
+ this.close();
463
+ this.closeContextMenu();
464
+ });
465
+
466
+ // Mouse drag
467
+ this.fab.addEventListener('mousedown', (e) => {
468
+ if (e.button === 0) { // Left click only
469
+ this.onPointerDown(e.clientX, e.clientY, e);
470
+ }
471
+ });
472
+ document.addEventListener('mousemove', (e) => this.onPointerMove(e.clientX, e.clientY));
473
+ document.addEventListener('mouseup', () => this.onPointerUp());
474
+
475
+ // Touch drag + long press for context menu
476
+ this.fab.addEventListener('touchstart', (e) => {
477
+ // Store currently focused element to restore after action (keeps keyboard open)
478
+ this.previousFocus = document.activeElement;
479
+
480
+ // Stop propagation to prevent swipe gesture detection from starting
481
+ e.stopPropagation();
482
+
483
+ const touch = e.touches[0];
484
+ this.onPointerDown(touch.clientX, touch.clientY, e);
485
+
486
+ // Start context menu timer (longer than drag-release)
487
+ // Works whether radial is open or closed — openContextMenu()
488
+ // handles closing the radial first if needed
489
+ this.contextMenuTimer = setTimeout(() => {
490
+ if (!this.didDrag) {
491
+ this.openContextMenu();
492
+ // Prevent the radial menu from opening
493
+ if (this.longPressTimer) {
494
+ clearTimeout(this.longPressTimer);
495
+ this.longPressTimer = null;
496
+ }
497
+ }
498
+ }, CONTEXT_MENU_LONG_PRESS);
499
+ }, { passive: true });
500
+
501
+ document.addEventListener('touchmove', (e) => {
502
+ if (!this.isDragging && !this.isLongPress) return;
503
+
504
+ // Prevent swipe gestures (tab switching) while dragging FAB
505
+ if (this.didDrag) {
506
+ e.preventDefault();
507
+ e.stopPropagation();
508
+ }
509
+
510
+ const touch = e.touches[0];
511
+ this.onPointerMove(touch.clientX, touch.clientY);
512
+
513
+ // Cancel context menu if dragging
514
+ if (this.didDrag && this.contextMenuTimer) {
515
+ clearTimeout(this.contextMenuTimer);
516
+ this.contextMenuTimer = null;
517
+ }
518
+ }, { passive: false, capture: true });
519
+
520
+ document.addEventListener('touchend', () => {
521
+ this.onPointerUp();
522
+ if (this.contextMenuTimer) {
523
+ clearTimeout(this.contextMenuTimer);
524
+ this.contextMenuTimer = null;
525
+ }
526
+ });
527
+
528
+ // Keyboard
529
+ document.addEventListener('keydown', (e) => {
530
+ if (e.key === 'Escape') {
531
+ if (this.isContextMenuOpen) {
532
+ this.closeContextMenu();
533
+ e.preventDefault();
534
+ } else if (this.isOpen) {
535
+ this.close();
536
+ e.preventDefault();
537
+ }
538
+ }
539
+ // Ctrl+. to toggle menu (legacy, Ctrl+Q is configurable via shortcuts)
540
+ if ((e.ctrlKey || e.metaKey) && e.key === '.') {
541
+ e.preventDefault();
542
+ this.toggle();
543
+ }
544
+ // Slot keys (1-4 + Q-W-E-R) to execute slot action when menu is open
545
+ if (this.isOpen && !this.isContextMenuOpen) {
546
+ const slots = this.config.slots;
547
+ const slotIndex = getSlotForKey(e.key, slots.length);
548
+ if (slotIndex !== -1 && slotIndex < slots.length) {
549
+ e.preventDefault();
550
+ e.stopPropagation();
551
+
552
+ // Highlight the item briefly
553
+ const item = this.menu?.querySelector(`[data-slot-index="${slotIndex}"]`);
554
+ if (item) {
555
+ item.classList.add('key-pressed');
556
+ }
557
+
558
+ // Check if action is disabled
559
+ const actionId = slots[slotIndex];
560
+ const action = QuickActionsRegistry.get(actionId);
561
+ if (action?.disabled?.()) {
562
+ // Shake animation via CSS, then remove class
563
+ setTimeout(() => item?.classList.remove('key-pressed'), 300);
564
+ return;
565
+ }
566
+
567
+ // Delay execution so user sees the highlight before menu closes
568
+ setTimeout(() => {
569
+ this.executeAction(actionId);
570
+ }, 120);
571
+ }
572
+ }
573
+ });
574
+
575
+ // Right-click on background to show radial menu at cursor position
576
+ document.addEventListener('contextmenu', (e) => {
577
+ // Skip if context menu is open (radial menu can be reopened at new position)
578
+ if (this.isContextMenuOpen) return;
579
+
580
+ // If radial menu is already open, right-click opens context menu instead
581
+ if (this.isOpen) {
582
+ e.preventDefault();
583
+ this.openContextMenu();
584
+ return;
585
+ }
586
+
587
+ // Skip if clicking on interactive elements that have their own context menus
588
+ const target = e.target;
589
+ const interactiveSelectors = [
590
+ 'input', 'textarea', 'select', 'button', 'a',
591
+ '[contenteditable]', '[data-context-menu]',
592
+ '.code-block', '.tool-block',
593
+ '.quick-actions-fab', '.widget', '.widget-tab-content', '.modal',
594
+ '.fe-container', '.terminal', '.editor',
595
+ '.tab', '.file-path-link', '.turn-file-pill',
596
+ '.turn-summary-bar'
597
+ ];
598
+
599
+ // Check if target or any parent matches interactive selectors
600
+ const isInteractive = interactiveSelectors.some(sel =>
601
+ target.matches(sel) || target.closest(sel)
602
+ );
603
+
604
+ // Also skip if there's a text selection (user might want to copy)
605
+ const hasSelection = window.getSelection()?.toString().trim().length > 0;
606
+
607
+ if (isInteractive || hasSelection) return;
608
+
609
+ // Check if cursor is actually over selectable text
610
+ // caretRangeFromPoint returns nearest caret position even for empty space,
611
+ // so we must verify the click is within the text's visual bounds
612
+ const range = document.caretRangeFromPoint(e.clientX, e.clientY);
613
+ if (range && range.startContainer.nodeType === Node.TEXT_NODE) {
614
+ // Get the bounding rect of the character at this position
615
+ const textNode = range.startContainer;
616
+ const offset = range.startOffset;
617
+
618
+ // Create a range for the character at the caret position
619
+ const charRange = document.createRange();
620
+ charRange.setStart(textNode, offset);
621
+ charRange.setEnd(textNode, Math.min(offset + 1, textNode.length));
622
+ const charRect = charRange.getBoundingClientRect();
623
+
624
+ // Check if click is actually within the text line's vertical bounds
625
+ // (horizontal can be looser since text reflows)
626
+ const isOverText = (
627
+ charRect.height > 0 &&
628
+ e.clientY >= charRect.top &&
629
+ e.clientY <= charRect.bottom &&
630
+ e.clientX >= charRect.left - 20 && // Some horizontal tolerance
631
+ e.clientX <= charRect.right + 20
632
+ );
633
+
634
+ if (isOverText) {
635
+ // Actually over text - check if it's selectable
636
+ const textParent = textNode.parentElement;
637
+ if (textParent) {
638
+ const userSelect = window.getComputedStyle(textParent).userSelect;
639
+ if (userSelect !== 'none') {
640
+ return; // Don't show quick actions over selectable text
641
+ }
642
+ }
643
+ }
644
+ }
645
+
646
+ // Open radial menu at cursor position
647
+ e.preventDefault();
648
+ this.openAtPosition(e.clientX, e.clientY);
649
+ });
650
+
651
+ // Radial menu item clicks (or click inside menu area to close)
652
+ this.menu.addEventListener('click', (e) => {
653
+ const item = e.target.closest('.quick-action-item');
654
+ if (item) {
655
+ const actionId = item.dataset.actionId;
656
+ this.executeAction(actionId);
657
+ } else {
658
+ // Clicked inside menu area but not on an item - close the menu
659
+ this.close();
660
+ }
661
+ });
662
+
663
+ // Context menu interactions
664
+ this.attachContextMenuListeners();
665
+ }
666
+
667
+ attachContextMenuListeners() {
668
+ const searchInput = this.contextMenu.querySelector('.qa-context-search input');
669
+ const resultsContainer = this.contextMenu.querySelector('.qa-context-results');
670
+
671
+ // Search input
672
+ searchInput.addEventListener('input', (e) => {
673
+ this.handleSearch(e.target.value);
674
+ });
675
+
676
+ // Search keyboard navigation
677
+ searchInput.addEventListener('keydown', (e) => {
678
+ if (e.key === 'ArrowDown') {
679
+ e.preventDefault();
680
+ this.navigateResults(1);
681
+ } else if (e.key === 'ArrowUp') {
682
+ e.preventDefault();
683
+ this.navigateResults(-1);
684
+ } else if (e.key === 'Enter') {
685
+ e.preventDefault();
686
+ this.executeSelectedResult();
687
+ }
688
+ });
689
+
690
+ // Results click - handle add button, slot picker, and result execution
691
+ resultsContainer.addEventListener('click', (e) => {
692
+ // Handle slot picker item click (replace or add)
693
+ const slotItem = e.target.closest('.qa-slot-picker-item');
694
+ if (slotItem) {
695
+ e.stopPropagation();
696
+ const slotIndex = parseInt(slotItem.dataset.slotIndex, 10);
697
+ const newActionId = slotItem.dataset.newAction;
698
+ this.handleSlotReplace(slotIndex, newActionId);
699
+ return;
700
+ }
701
+
702
+ // Handle add button click
703
+ const addBtn = e.target.closest('.qa-result-add-btn');
704
+ if (addBtn) {
705
+ e.stopPropagation();
706
+ const actionId = addBtn.dataset.actionId;
707
+ this.handleAddToMenu(actionId);
708
+ return;
709
+ }
710
+
711
+ // Handle result click (execute action)
712
+ const result = e.target.closest('.qa-context-result');
713
+ if (result) {
714
+ const actionId = result.dataset.actionId;
715
+ this.executeAction(actionId);
716
+ this.closeContextMenu();
717
+ }
718
+ });
719
+
720
+ // Preset clicks
721
+ this.contextMenu.querySelectorAll('.qa-context-preset').forEach(btn => {
722
+ btn.addEventListener('click', () => {
723
+ const presetId = btn.dataset.preset;
724
+ this.applyPreset(presetId);
725
+ this.updateContextMenuPresets();
726
+ // Brief visual feedback, then close context menu and open radial
727
+ // so the user can immediately use an action from the new preset
728
+ setTimeout(() => {
729
+ this.closeContextMenu();
730
+ this.open();
731
+ }, 150);
732
+ });
733
+ });
734
+
735
+ // Footer actions
736
+ this.contextMenu.querySelectorAll('.qa-context-footer-item').forEach(btn => {
737
+ btn.addEventListener('click', () => {
738
+ const action = btn.dataset.action;
739
+ if (action === 'debug-logs') {
740
+ window.WidgetManager.open('debug-logs');
741
+ } else if (action === 'customize') {
742
+ // Use WidgetManager directly instead of dynamic import
743
+ // (dynamic import gets a separate module instance due to cache-busting)
744
+ window.WidgetManager.open('config', { tab: 'quickactions' });
745
+ }
746
+ this.closeContextMenu();
747
+ });
748
+ });
749
+ }
750
+
751
+ // ─────────────────────────────────────────────────────────────────────────
752
+ // Context Menu Methods
753
+ // ─────────────────────────────────────────────────────────────────────────
754
+
755
+ openContextMenu(anchor) {
756
+ if (this.isContextMenuOpen) return;
757
+
758
+ // If radial is open, capture its visual center as anchor before closing
759
+ // (edge-aware offset may have shifted items away from the FAB)
760
+ if (this.isOpen && !anchor) {
761
+ const menuRect = this.menu.getBoundingClientRect();
762
+ anchor = {
763
+ x: menuRect.left + menuRect.width / 2,
764
+ y: menuRect.top + menuRect.height / 2
765
+ };
766
+ }
767
+
768
+ // Close radial menu if open
769
+ if (this.isOpen) this.close();
770
+
771
+ this.isContextMenuOpen = true;
772
+ this.fab.removeAttribute('data-tooltip'); // Hide tooltip while context menu is open
773
+ TooltipManager.hideTooltip(); // Clear any pending/active tooltip
774
+ this.overlay.classList.add('visible');
775
+
776
+ // Position context menu near anchor point (or FAB if no anchor)
777
+ this.positionContextMenu(anchor);
778
+
779
+ this.contextMenu.classList.add('open');
780
+ this.updateContextMenuPresets();
781
+
782
+ // Sync debug logs item visibility with current error state
783
+ const debugItem = this.contextMenu.querySelector('.qa-debug-logs-item');
784
+ if (debugItem) {
785
+ debugItem.style.display = this.fab.classList.contains('has-errors') ? '' : 'none';
786
+ }
787
+
788
+ // Clear and focus search
789
+ const searchInput = this.contextMenu.querySelector('.qa-context-search input');
790
+ searchInput.value = '';
791
+ this.handleSearch('');
792
+
793
+ // Focus search input after animation
794
+ setTimeout(() => searchInput.focus(), 50);
795
+ }
796
+
797
+ closeContextMenu() {
798
+ if (!this.isContextMenuOpen) return;
799
+
800
+ this.isContextMenuOpen = false;
801
+ this.contextMenu.classList.remove('open');
802
+ this.fab.setAttribute('data-tooltip', 'Quick Actions - Drag to move, right-click for options'); // Restore tooltip
803
+ this.overlay.classList.remove('visible');
804
+ this.searchResults = [];
805
+ this.selectedResultIndex = 0;
806
+ }
807
+
808
+ positionContextMenu(anchor) {
809
+ const fabRect = this.fab.getBoundingClientRect();
810
+ const menuWidth = 280;
811
+ const padding = 12;
812
+
813
+ // Use anchor point if provided (e.g., from radial menu center),
814
+ // otherwise use FAB position
815
+ const anchorY = anchor ? anchor.y : (fabRect.top + fabRect.height / 2);
816
+ const anchorX = anchor ? anchor.x : (fabRect.left + fabRect.width / 2);
817
+ // Virtual rect around anchor point for space calculations
818
+ const anchorTop = anchor ? anchor.y - 26 : fabRect.top;
819
+ const anchorBottom = anchor ? anchor.y + 26 : fabRect.bottom;
820
+
821
+ // Use visualViewport for accurate dimensions with keyboard open (iOS Safari)
822
+ const viewportHeight = window.visualViewport?.height || window.innerHeight;
823
+
824
+ // Calculate available space above and below anchor
825
+ const spaceAbove = anchorTop;
826
+ const spaceBelow = viewportHeight - anchorBottom;
827
+
828
+ const isAbove = spaceAbove > spaceBelow;
829
+
830
+ // Toggle class for layout direction
831
+ this.contextMenu.classList.toggle('menu-above', isAbove);
832
+ this.isMenuAbove = isAbove; // Store for handleSearch to use
833
+
834
+ if (isAbove) {
835
+ // Anchor menu BOTTOM to just above anchor - menu grows UPWARD
836
+ // With column-reverse, search input (at flex-end) stays near anchor
837
+ const bottomPos = viewportHeight - anchorTop + padding;
838
+ this.contextMenu.style.top = 'auto';
839
+ this.contextMenu.style.bottom = `${bottomPos}px`;
840
+ // Constrain height to available space above anchor
841
+ this.contextMenu.style.maxHeight = `${anchorTop - padding * 2}px`;
842
+ } else {
843
+ // Anchor menu TOP to just below anchor - menu grows DOWNWARD
844
+ this.contextMenu.style.bottom = 'auto';
845
+ this.contextMenu.style.top = `${anchorBottom + padding}px`;
846
+ // Constrain height to available space below anchor
847
+ this.contextMenu.style.maxHeight = `${viewportHeight - anchorBottom - padding * 2}px`;
848
+ }
849
+
850
+ // Horizontal positioning - center on anchor, clamped to screen bounds
851
+ const viewportWidth = window.visualViewport?.width || window.innerWidth;
852
+ const idealLeft = anchorX - menuWidth / 2;
853
+ // Clamp: at least `padding` from left, and right edge at least `padding` from viewport right
854
+ const maxLeft = viewportWidth - menuWidth - padding;
855
+ const left = Math.max(padding, Math.min(maxLeft, idealLeft));
856
+ this.contextMenu.style.left = `${left}px`;
857
+ }
858
+
859
+ updateContextMenuPresets() {
860
+ const currentPreset = this.config.preset || 'balanced';
861
+ this.contextMenu.querySelectorAll('.qa-context-preset').forEach(btn => {
862
+ const isActive = btn.dataset.preset === currentPreset;
863
+ btn.classList.toggle('active', isActive);
864
+ });
865
+ }
866
+
867
+ /** Rebuild presets section from current QUICK_ACTION_PRESETS (called after server load). */
868
+ rebuildPresetsSection() {
869
+ const section = this.contextMenu.querySelector('.qa-context-presets');
870
+ if (!section) return;
871
+ const currentPreset = this.config.preset || 'balanced';
872
+ section.innerHTML = `
873
+ <div class="qa-context-section-title">Presets</div>
874
+ ${Object.entries(QUICK_ACTION_PRESETS).map(([id, preset]) => `
875
+ <button class="qa-context-preset${id === currentPreset ? ' active' : ''}" data-preset="${id}">
876
+ <span class="qa-preset-radio"></span>
877
+ <span class="qa-preset-name">${preset.name}</span>
878
+ <span class="qa-preset-desc">${preset.slots.length} actions</span>
879
+ </button>
880
+ `).join('')}
881
+ `;
882
+ // Rebind click handlers
883
+ section.querySelectorAll('.qa-context-preset').forEach(btn => {
884
+ btn.addEventListener('click', () => {
885
+ const presetId = btn.dataset.preset;
886
+ this.applyPreset(presetId);
887
+ this.updateContextMenuPresets();
888
+ setTimeout(() => {
889
+ this.closeContextMenu();
890
+ this.open();
891
+ }, 150);
892
+ });
893
+ });
894
+ }
895
+
896
+ handleSearch(query) {
897
+ const resultsContainer = this.contextMenu.querySelector('.qa-context-results');
898
+ const presetsSection = this.contextMenu.querySelector('.qa-context-presets');
899
+ const footerSection = this.contextMenu.querySelector('.qa-context-footer');
900
+
901
+ if (!query.trim()) {
902
+ resultsContainer.innerHTML = '';
903
+ resultsContainer.classList.remove('has-results');
904
+ presetsSection.style.display = '';
905
+ footerSection.style.display = '';
906
+ this.searchResults = [];
907
+ this.expandedResultId = null;
908
+ return;
909
+ }
910
+
911
+ // Search all actions
912
+ const results = this.searchActions(query.toLowerCase());
913
+ this.searchResults = results;
914
+ this.selectedResultIndex = 0;
915
+
916
+ if (results.length > 0) {
917
+ // Hide presets and footer to maximize space for results
918
+ presetsSection.style.display = 'none';
919
+ footerSection.style.display = 'none';
920
+ resultsContainer.classList.add('has-results');
921
+ resultsContainer.innerHTML = results.slice(0, 6).map((result, i) => {
922
+ const isInSlots = this.config.slots.includes(result.action.id);
923
+ const isExpanded = this.expandedResultId === result.action.id;
924
+
925
+ return `
926
+ <div class="qa-context-result-wrapper${isExpanded ? ' expanded' : ''}">
927
+ <div class="qa-context-result-row">
928
+ <button class="qa-context-result${i === 0 ? ' selected' : ''}" data-action-id="${result.action.id}">
929
+ <div class="qa-result-icon">
930
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
931
+ ${ICONS[result.action.icon] || ICONS['help-circle']}
932
+ </svg>
933
+ </div>
934
+ <div class="qa-result-text">
935
+ <div class="qa-result-label">${this.highlightMatch(result.action.label, query)}</div>
936
+ <div class="qa-result-desc">${result.action.description}</div>
937
+ </div>
938
+ ${result.action.shortcut ? `<div class="qa-result-shortcut">${result.action.shortcutDisplay}</div>` : ''}
939
+ </button>
940
+ <button class="qa-result-add-btn${isInSlots ? ' in-menu' : ''}"
941
+ data-action-id="${result.action.id}"
942
+ data-tooltip="${isInSlots ? 'Already in menu' : 'Add to quick actions'}">
943
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
944
+ ${isInSlots ? ICONS['check'] : ICONS['plus-circle']}
945
+ </svg>
946
+ </button>
947
+ </div>
948
+ ${isExpanded ? this.renderSlotPicker(result.action.id) : ''}
949
+ </div>
950
+ `}).join('');
951
+ } else {
952
+ // No results - still hide presets/footer, show "no results" message
953
+ presetsSection.style.display = 'none';
954
+ footerSection.style.display = 'none';
955
+ resultsContainer.classList.add('has-results');
956
+ resultsContainer.innerHTML = `
957
+ <div class="qa-context-no-results">No actions found for "${query}"</div>
958
+ `;
959
+ }
960
+ }
961
+
962
+ renderSlotPicker(actionId) {
963
+ const slots = this.config.slots;
964
+ const canAdd = slots.length < 8;
965
+
966
+ return `
967
+ <div class="qa-slot-picker">
968
+ <div class="qa-slot-picker-title">${canAdd ? 'Add or replace:' : 'Replace which slot?'}</div>
969
+ <div class="qa-slot-picker-slots">
970
+ ${slots.map((slotId, i) => {
971
+ const action = QuickActionsRegistry.get(slotId);
972
+ const icon = action ? (ICONS[action.icon] || ICONS['help-circle']) : ICONS['help-circle'];
973
+ const label = action?.label || slotId;
974
+ return `
975
+ <button class="qa-slot-picker-item" data-slot-index="${i}" data-new-action="${actionId}" data-tooltip="Replace: ${label}">
976
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
977
+ ${icon}
978
+ </svg>
979
+ </button>
980
+ `;
981
+ }).join('')}
982
+ ${canAdd ? `
983
+ <button class="qa-slot-picker-item add-new" data-slot-index="-1" data-new-action="${actionId}" data-tooltip="Add as new">
984
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
985
+ ${ICONS['plus-circle']}
986
+ </svg>
987
+ </button>
988
+ ` : ''}
989
+ </div>
990
+ </div>
991
+ `;
992
+ }
993
+
994
+ handleAddToMenu(actionId) {
995
+ const isInSlots = this.config.slots.includes(actionId);
996
+ if (isInSlots) {
997
+ // Already in menu - could remove or just ignore
998
+ this.showToast(S.toast.already_in_quick);
999
+ return;
1000
+ }
1001
+
1002
+ if (this.config.slots.length < 8) {
1003
+ // Can add directly
1004
+ this.config.slots.push(actionId);
1005
+ this.config.preset = 'custom';
1006
+ this.saveState();
1007
+ this.showToast(S.toast.added_to_quick);
1008
+ // Re-render search results to update the + button
1009
+ const searchInput = this.contextMenu.querySelector('.qa-context-search input');
1010
+ this.handleSearch(searchInput.value);
1011
+ } else {
1012
+ // Need to replace - expand the slot picker
1013
+ this.expandedResultId = actionId;
1014
+ const searchInput = this.contextMenu.querySelector('.qa-context-search input');
1015
+ this.handleSearch(searchInput.value);
1016
+ }
1017
+ }
1018
+
1019
+ handleSlotReplace(slotIndex, newActionId) {
1020
+ if (slotIndex === -1) {
1021
+ // Add as new slot
1022
+ this.config.slots.push(newActionId);
1023
+ } else {
1024
+ // Replace existing slot
1025
+ this.config.slots[slotIndex] = newActionId;
1026
+ }
1027
+ this.config.preset = 'custom';
1028
+ this.saveState();
1029
+ this.expandedResultId = null;
1030
+ this.showToast(slotIndex === -1 ? 'Added to quick actions' : 'Replaced in quick actions');
1031
+
1032
+ // Re-render search results
1033
+ const searchInput = this.contextMenu.querySelector('.qa-context-search input');
1034
+ this.handleSearch(searchInput.value);
1035
+ }
1036
+
1037
+ showToast(message) {
1038
+ // Remove any existing toast
1039
+ const existing = this.contextMenu.querySelector('.qa-toast');
1040
+ if (existing) existing.remove();
1041
+
1042
+ const toast = document.createElement('div');
1043
+ toast.className = 'qa-toast';
1044
+ toast.textContent = message;
1045
+ this.contextMenu.appendChild(toast);
1046
+
1047
+ // Animate in
1048
+ requestAnimationFrame(() => toast.classList.add('visible'));
1049
+
1050
+ // Remove after delay
1051
+ setTimeout(() => {
1052
+ toast.classList.remove('visible');
1053
+ setTimeout(() => toast.remove(), 200);
1054
+ }, 1500);
1055
+ }
1056
+
1057
+ searchActions(query) {
1058
+ const allActions = QuickActionsRegistry.getAll();
1059
+ const results = [];
1060
+
1061
+ for (const action of allActions) {
1062
+ const score = this.scoreMatch(query, action);
1063
+ if (score > 0) {
1064
+ results.push({ action, score });
1065
+ }
1066
+ }
1067
+
1068
+ // Sort by score descending
1069
+ results.sort((a, b) => b.score - a.score);
1070
+ return results;
1071
+ }
1072
+
1073
+ scoreMatch(query, action) {
1074
+ const q = query.toLowerCase();
1075
+ let score = 0;
1076
+
1077
+ // Exact label start (highest)
1078
+ if (action.label.toLowerCase().startsWith(q)) score += 100;
1079
+ // Label contains
1080
+ else if (action.label.toLowerCase().includes(q)) score += 50;
1081
+
1082
+ // Action ID contains (for power users: "git", "term", etc.)
1083
+ if (action.id.toLowerCase().includes(q)) score += 40;
1084
+
1085
+ // Description contains
1086
+ if (action.description.toLowerCase().includes(q)) score += 25;
1087
+
1088
+ // Category contains
1089
+ if (action.category.toLowerCase().includes(q)) score += 10;
1090
+
1091
+ // Shortcut exact match — check both the declared chord and the one
1092
+ // shown here, so a Mac user typing "cmd" hits it too.
1093
+ if (action.shortcut?.toLowerCase().includes(q)) score += 30;
1094
+ else if (action.shortcutDisplay?.toLowerCase().includes(q)) score += 30;
1095
+
1096
+ return score;
1097
+ }
1098
+
1099
+ highlightMatch(text, query) {
1100
+ const idx = text.toLowerCase().indexOf(query.toLowerCase());
1101
+ if (idx === -1) return text;
1102
+ return text.slice(0, idx) +
1103
+ `<mark>${text.slice(idx, idx + query.length)}</mark>` +
1104
+ text.slice(idx + query.length);
1105
+ }
1106
+
1107
+ navigateResults(direction) {
1108
+ if (this.searchResults.length === 0) return;
1109
+
1110
+ const maxIndex = Math.min(this.searchResults.length - 1, 5);
1111
+ this.selectedResultIndex = Math.max(0, Math.min(maxIndex, this.selectedResultIndex + direction));
1112
+
1113
+ // Update visual selection
1114
+ const results = this.contextMenu.querySelectorAll('.qa-context-result');
1115
+ results.forEach((el, i) => {
1116
+ el.classList.toggle('selected', i === this.selectedResultIndex);
1117
+ });
1118
+ }
1119
+
1120
+ executeSelectedResult() {
1121
+ if (this.searchResults.length === 0) return;
1122
+ const selected = this.searchResults[this.selectedResultIndex];
1123
+ if (selected) {
1124
+ this.executeAction(selected.action.id);
1125
+ this.closeContextMenu();
1126
+ }
1127
+ }
1128
+
1129
+ // ─────────────────────────────────────────────────────────────────────────
1130
+ // Pointer/Drag Methods
1131
+ // ─────────────────────────────────────────────────────────────────────────
1132
+
1133
+ onPointerDown(clientX, clientY, e) {
1134
+ this.startX = clientX;
1135
+ this.startY = clientY;
1136
+ this.startRight = this.position.right;
1137
+ this.startBottom = this.position.bottom;
1138
+ this.isDragging = true;
1139
+ this.didDrag = false;
1140
+
1141
+ // Start long press timer for drag-release mode
1142
+ if (this.config.options.dragRelease) {
1143
+ this.longPressTimer = setTimeout(() => {
1144
+ this.isLongPress = true;
1145
+ if (!this.isOpen && !this.isContextMenuOpen) {
1146
+ this.open();
1147
+ }
1148
+ }, LONG_PRESS_DELAY);
1149
+ }
1150
+ }
1151
+
1152
+ onPointerMove(clientX, clientY) {
1153
+ if (!this.isDragging) return;
1154
+
1155
+ const dx = clientX - this.startX;
1156
+ const dy = clientY - this.startY;
1157
+
1158
+ // Check if we've moved beyond threshold
1159
+ if (!this.didDrag && (Math.abs(dx) > DRAG_THRESHOLD || Math.abs(dy) > DRAG_THRESHOLD)) {
1160
+ this.didDrag = true;
1161
+ this.fab.classList.add('dragging');
1162
+ // Cancel long press if we're dragging
1163
+ if (this.longPressTimer) {
1164
+ clearTimeout(this.longPressTimer);
1165
+ this.longPressTimer = null;
1166
+ }
1167
+ }
1168
+
1169
+ if (this.didDrag) {
1170
+ // Dragging FAB position (works with any menu open)
1171
+ const newRight = this.startRight - dx;
1172
+ const newBottom = this.startBottom - dy;
1173
+
1174
+ const padding = 8;
1175
+ const fabSize = 52;
1176
+ const viewportWidth = window.visualViewport?.width || window.innerWidth;
1177
+ const viewportHeight = window.visualViewport?.height || window.innerHeight;
1178
+
1179
+ this.position = {
1180
+ right: Math.max(padding, Math.min(viewportWidth - fabSize - padding, newRight)),
1181
+ bottom: Math.max(padding, Math.min(viewportHeight - fabSize - padding, newBottom))
1182
+ };
1183
+
1184
+ this.applyPosition();
1185
+
1186
+ // Reposition any open menu to follow FAB
1187
+ if (this.isContextMenuOpen) {
1188
+ this.positionContextMenu();
1189
+ }
1190
+ if (this.isOpen) {
1191
+ // Radial menu position is tied to FAB via CSS, but re-render to update tooltips
1192
+ this.renderMenuItems();
1193
+ }
1194
+ } else if (this.isLongPress && this.isOpen) {
1195
+ // Drag-to-select mode
1196
+ this.updateHighlight(clientX, clientY);
1197
+ }
1198
+ }
1199
+
1200
+ onPointerUp() {
1201
+ if (!this.isDragging) return;
1202
+
1203
+ this.isDragging = false;
1204
+ this.fab.classList.remove('dragging');
1205
+
1206
+ if (this.longPressTimer) {
1207
+ clearTimeout(this.longPressTimer);
1208
+ this.longPressTimer = null;
1209
+ }
1210
+
1211
+ if (this.didDrag) {
1212
+ // Save position after dragging (works with any menu open)
1213
+ this.saveState();
1214
+ setTimeout(() => { this.didDrag = false; }, 100);
1215
+ }
1216
+
1217
+ if (this.isLongPress && this.isOpen) {
1218
+ // Execute highlighted action on release
1219
+ if (this.highlightedIndex >= 0) {
1220
+ const slots = this.config.slots;
1221
+ if (this.highlightedIndex < slots.length) {
1222
+ this.executeAction(slots[this.highlightedIndex]);
1223
+ }
1224
+ }
1225
+ this.isLongPress = false;
1226
+ this.highlightedIndex = -1;
1227
+ this.close();
1228
+ }
1229
+ }
1230
+
1231
+ updateHighlight(clientX, clientY) {
1232
+ const fabRect = this.fab.getBoundingClientRect();
1233
+ const centerX = fabRect.left + fabRect.width / 2;
1234
+ const centerY = fabRect.top + fabRect.height / 2;
1235
+
1236
+ const dx = clientX - centerX;
1237
+ const dy = clientY - centerY;
1238
+ const distance = Math.sqrt(dx * dx + dy * dy);
1239
+
1240
+ // Only select if dragged far enough from center
1241
+ if (distance < 30) {
1242
+ this.setHighlight(-1);
1243
+ return;
1244
+ }
1245
+
1246
+ // Calculate angle and map to item index
1247
+ const angle = Math.atan2(dy, dx);
1248
+ const slots = this.config.slots;
1249
+ const itemCount = slots.length;
1250
+ const angleStep = (2 * Math.PI) / itemCount;
1251
+ const startAngle = -3 * Math.PI / 4; // Start from top-left (more horizontal layout)
1252
+
1253
+ // Normalize angle to 0-2PI range starting from top-left
1254
+ let normalizedAngle = angle - startAngle;
1255
+ if (normalizedAngle < 0) normalizedAngle += 2 * Math.PI;
1256
+ if (normalizedAngle >= 2 * Math.PI) normalizedAngle -= 2 * Math.PI;
1257
+
1258
+ const index = Math.floor(normalizedAngle / angleStep);
1259
+ this.setHighlight(Math.min(index, itemCount - 1));
1260
+ }
1261
+
1262
+ setHighlight(index) {
1263
+ if (this.highlightedIndex === index) return;
1264
+
1265
+ // Remove old highlight
1266
+ const oldItem = this.menu.querySelector('.quick-action-item.highlighted');
1267
+ if (oldItem) oldItem.classList.remove('highlighted');
1268
+
1269
+ this.highlightedIndex = index;
1270
+
1271
+ // Add new highlight
1272
+ if (index >= 0) {
1273
+ const items = this.menu.querySelectorAll('.quick-action-item');
1274
+ if (items[index]) {
1275
+ items[index].classList.add('highlighted');
1276
+ // Haptic feedback
1277
+ if (this.config.options.hapticFeedback && navigator.vibrate) {
1278
+ navigator.vibrate(10);
1279
+ }
1280
+ }
1281
+ }
1282
+ }
1283
+
1284
+ applyPosition() {
1285
+ if (!this.fab) return;
1286
+ this.fab.style.right = `${this.position.right}px`;
1287
+ this.fab.style.bottom = `${this.position.bottom}px`;
1288
+
1289
+ // Position menu relative to FAB (with offset for edge-awareness)
1290
+ if (this.menu) {
1291
+ this.menu.style.right = `${this.position.right}px`;
1292
+ this.menu.style.bottom = `${this.position.bottom}px`;
1293
+ }
1294
+ }
1295
+
1296
+ /**
1297
+ * Calculate offset needed to ensure all menu items are visible.
1298
+ * Returns {x, y} offset to apply to the menu (positive = move right/up).
1299
+ */
1300
+ calculateEdgeOffset() {
1301
+ const viewportWidth = window.visualViewport?.width || window.innerWidth;
1302
+ const viewportHeight = window.visualViewport?.height || window.innerHeight;
1303
+
1304
+ // FAB center position in viewport coordinates
1305
+ const fabCenterX = viewportWidth - this.position.right - 26; // 26 = half FAB width
1306
+ const fabCenterY = viewportHeight - this.position.bottom - 26;
1307
+
1308
+ // Calculate item positions for current slot configuration
1309
+ const slots = this.config.slots;
1310
+ const itemCount = slots.length;
1311
+ const angleStep = (2 * Math.PI) / itemCount;
1312
+ const startAngle = -3 * Math.PI / 4;
1313
+
1314
+ let minX = Infinity, maxX = -Infinity;
1315
+ let minY = Infinity, maxY = -Infinity;
1316
+
1317
+ for (let i = 0; i < itemCount; i++) {
1318
+ const angle = startAngle + (i * angleStep);
1319
+ const itemX = fabCenterX + Math.cos(angle) * MENU_RADIUS;
1320
+ const itemY = fabCenterY + Math.sin(angle) * MENU_RADIUS;
1321
+
1322
+ // Account for item size (item center ± half item size)
1323
+ minX = Math.min(minX, itemX - ITEM_SIZE / 2);
1324
+ maxX = Math.max(maxX, itemX + ITEM_SIZE / 2);
1325
+ minY = Math.min(minY, itemY - ITEM_SIZE / 2);
1326
+ maxY = Math.max(maxY, itemY + ITEM_SIZE / 2);
1327
+ }
1328
+
1329
+ // Calculate how much we need to shift to keep all items in viewport
1330
+ let offsetX = 0;
1331
+ let offsetY = 0;
1332
+
1333
+ // Check left edge
1334
+ if (minX < EDGE_PADDING) {
1335
+ offsetX = EDGE_PADDING - minX;
1336
+ }
1337
+ // Check right edge
1338
+ if (maxX > viewportWidth - EDGE_PADDING) {
1339
+ offsetX = viewportWidth - EDGE_PADDING - maxX;
1340
+ }
1341
+ // Check top edge
1342
+ if (minY < EDGE_PADDING) {
1343
+ offsetY = EDGE_PADDING - minY;
1344
+ }
1345
+ // Check bottom edge
1346
+ if (maxY > viewportHeight - EDGE_PADDING) {
1347
+ offsetY = viewportHeight - EDGE_PADDING - maxY;
1348
+ }
1349
+
1350
+ return { x: offsetX, y: offsetY };
1351
+ }
1352
+
1353
+ /**
1354
+ * Apply offset to menu for edge-aware positioning.
1355
+ * Uses CSS transform for smooth animation.
1356
+ * Offset: positive X = move right, positive Y = move down
1357
+ */
1358
+ applyMenuOffset(offset, animate = true) {
1359
+ if (!this.menu) return;
1360
+
1361
+ if (animate) {
1362
+ this.menu.classList.add('edge-shift');
1363
+ } else {
1364
+ this.menu.classList.remove('edge-shift');
1365
+ }
1366
+
1367
+ this.menu.style.transform = `translate(${offset.x}px, ${offset.y}px)`;
1368
+ }
1369
+
1370
+ /**
1371
+ * Reset menu offset (used when closing)
1372
+ */
1373
+ resetMenuOffset(animate = true) {
1374
+ if (!this.menu) return;
1375
+
1376
+ if (animate) {
1377
+ this.menu.classList.add('edge-shift');
1378
+ // Remove the class after animation completes
1379
+ setTimeout(() => {
1380
+ this.menu?.classList.remove('edge-shift');
1381
+ }, 300);
1382
+ } else {
1383
+ this.menu.classList.remove('edge-shift');
1384
+ }
1385
+
1386
+ this.menu.style.transform = '';
1387
+ this.menuOffset = { x: 0, y: 0 };
1388
+ }
1389
+
1390
+ /**
1391
+ * Calculate offset for a specific center position (used by openAtPosition)
1392
+ */
1393
+ calculateEdgeOffsetAt(centerX, centerY) {
1394
+ const viewportWidth = window.visualViewport?.width || window.innerWidth;
1395
+ const viewportHeight = window.visualViewport?.height || window.innerHeight;
1396
+
1397
+ // Calculate item positions for current slot configuration
1398
+ const slots = this.config.slots;
1399
+ const itemCount = slots.length;
1400
+ const angleStep = (2 * Math.PI) / itemCount;
1401
+ const startAngle = -3 * Math.PI / 4;
1402
+
1403
+ let minX = Infinity, maxX = -Infinity;
1404
+ let minY = Infinity, maxY = -Infinity;
1405
+
1406
+ for (let i = 0; i < itemCount; i++) {
1407
+ const angle = startAngle + (i * angleStep);
1408
+ const itemX = centerX + Math.cos(angle) * MENU_RADIUS;
1409
+ const itemY = centerY + Math.sin(angle) * MENU_RADIUS;
1410
+
1411
+ minX = Math.min(minX, itemX - ITEM_SIZE / 2);
1412
+ maxX = Math.max(maxX, itemX + ITEM_SIZE / 2);
1413
+ minY = Math.min(minY, itemY - ITEM_SIZE / 2);
1414
+ maxY = Math.max(maxY, itemY + ITEM_SIZE / 2);
1415
+ }
1416
+
1417
+ let offsetX = 0;
1418
+ let offsetY = 0;
1419
+
1420
+ if (minX < EDGE_PADDING) {
1421
+ offsetX = EDGE_PADDING - minX;
1422
+ }
1423
+ if (maxX > viewportWidth - EDGE_PADDING) {
1424
+ offsetX = viewportWidth - EDGE_PADDING - maxX;
1425
+ }
1426
+ if (minY < EDGE_PADDING) {
1427
+ offsetY = EDGE_PADDING - minY;
1428
+ }
1429
+ if (maxY > viewportHeight - EDGE_PADDING) {
1430
+ offsetY = viewportHeight - EDGE_PADDING - maxY;
1431
+ }
1432
+
1433
+ return { x: offsetX, y: offsetY };
1434
+ }
1435
+
1436
+ updateVisibility() {
1437
+ if (!this.fab) return;
1438
+ this.fab.style.display = this.isVisibleHere() ? 'flex' : 'none';
1439
+ }
1440
+
1441
+ updateFabBadge(count) {
1442
+ if (!this.fabBadge) return;
1443
+ // Show/hide debug logs item in context menu
1444
+ const debugItem = this.contextMenu?.querySelector('.qa-debug-logs-item');
1445
+ if (debugItem) debugItem.style.display = count > 0 ? '' : 'none';
1446
+
1447
+ if (count > 0) {
1448
+ this.fabBadge.textContent = count > 99 ? '99+' : String(count);
1449
+ this.fabBadge.classList.add('visible');
1450
+ this.fab.classList.add('has-errors');
1451
+ // Brief attention animation on first error
1452
+ if (!this._hadErrors) {
1453
+ this._hadErrors = true;
1454
+ this.fab.classList.add('error-attention');
1455
+ setTimeout(() => this.fab.classList.remove('error-attention'), 600);
1456
+ }
1457
+ } else {
1458
+ this.fabBadge.textContent = '';
1459
+ this.fabBadge.classList.remove('visible');
1460
+ this.fab.classList.remove('has-errors');
1461
+ this._hadErrors = false;
1462
+ }
1463
+ }
1464
+
1465
+ // ─────────────────────────────────────────────────────────────────────────
1466
+ // Radial Menu Methods
1467
+ // ─────────────────────────────────────────────────────────────────────────
1468
+
1469
+ toggle() {
1470
+ if (this.isOpen) {
1471
+ this.close();
1472
+ } else {
1473
+ this.open();
1474
+ }
1475
+ }
1476
+
1477
+ open() {
1478
+ if (this.isOpen) return;
1479
+
1480
+ this.isOpen = true;
1481
+ this.fab.classList.add('open');
1482
+ this.fab.setAttribute('aria-expanded', 'true');
1483
+ this.fab.removeAttribute('data-tooltip'); // Hide tooltip while menu is open
1484
+ TooltipManager.hideTooltip(); // Clear any pending/active tooltip
1485
+ this.overlay.classList.add('visible');
1486
+ this.menu.classList.add('open');
1487
+
1488
+ // Calculate and apply edge-aware offset
1489
+ this.menuOffset = this.calculateEdgeOffset();
1490
+ if (this.menuOffset.x !== 0 || this.menuOffset.y !== 0) {
1491
+ this.applyMenuOffset(this.menuOffset, true);
1492
+ }
1493
+
1494
+ this.renderMenuItems();
1495
+ }
1496
+
1497
+ close() {
1498
+ if (!this.isOpen) return;
1499
+
1500
+ this.isOpen = false;
1501
+ this.fab.classList.remove('open');
1502
+ this.fab.setAttribute('aria-expanded', 'false');
1503
+ this.fab.setAttribute('data-tooltip', 'Quick Actions - Drag to move, right-click for options'); // Restore tooltip
1504
+ this.overlay.classList.remove('visible');
1505
+ this.menu.classList.remove('open');
1506
+
1507
+ // Clear highlights
1508
+ this.highlightedIndex = -1;
1509
+
1510
+ // Reset edge-aware offset
1511
+ if (this.menuOffset.x !== 0 || this.menuOffset.y !== 0) {
1512
+ this.resetMenuOffset(true);
1513
+ }
1514
+
1515
+ // Reset menu position if it was opened at cursor
1516
+ if (this.openedAtCursor) {
1517
+ this.openedAtCursor = false;
1518
+ this.applyPosition(); // Restore menu to FAB position
1519
+ }
1520
+ }
1521
+
1522
+ /**
1523
+ * Open the radial menu at a specific screen position (e.g., right-click location)
1524
+ */
1525
+ openAtPosition(x, y) {
1526
+ // Calculate position from right/bottom edges
1527
+ const viewportWidth = window.visualViewport?.width || window.innerWidth;
1528
+ const viewportHeight = window.visualViewport?.height || window.innerHeight;
1529
+
1530
+ // Position menu centered at cursor
1531
+ const menuRight = viewportWidth - x - 26; // 26 = half of menu center
1532
+ const menuBottom = viewportHeight - y - 26;
1533
+
1534
+ // Apply cursor position to menu only (FAB stays in place)
1535
+ this.menu.style.right = `${menuRight}px`;
1536
+ this.menu.style.bottom = `${menuBottom}px`;
1537
+ this.openedAtCursor = true;
1538
+
1539
+ // Calculate edge offset for cursor position
1540
+ this.menuOffset = this.calculateEdgeOffsetAt(x, y);
1541
+ if (this.menuOffset.x !== 0 || this.menuOffset.y !== 0) {
1542
+ this.applyMenuOffset(this.menuOffset, true);
1543
+ }
1544
+
1545
+ // If already open, just reposition (no animation needed)
1546
+ if (this.isOpen) return;
1547
+
1548
+ this.isOpen = true;
1549
+ // Don't change FAB appearance when opened via background click
1550
+ this.overlay.classList.add('visible');
1551
+ this.menu.classList.add('open');
1552
+
1553
+ this.renderMenuItems();
1554
+ }
1555
+
1556
+ renderMenuItems() {
1557
+ const slots = this.config.slots;
1558
+ const itemCount = slots.length;
1559
+ const angleStep = (2 * Math.PI) / itemCount;
1560
+ const startAngle = -3 * Math.PI / 4; // Start from top-left (more horizontal layout)
1561
+
1562
+ let html = '';
1563
+
1564
+ slots.forEach((actionId, index) => {
1565
+ const action = QuickActionsRegistry.get(actionId);
1566
+ if (!action) {
1567
+ console.warn(`[QuickActions] Unknown action in slot: ${actionId}`);
1568
+ return;
1569
+ }
1570
+
1571
+ const angle = startAngle + (index * angleStep);
1572
+ const x = Math.cos(angle) * MENU_RADIUS;
1573
+ const y = Math.sin(angle) * MENU_RADIUS;
1574
+
1575
+ const isEnabled = action.isEnabled();
1576
+ const badge = action.badge ? action.badge() : null;
1577
+ const iconSvg = ICONS[action.icon] || ICONS['help-circle'];
1578
+
1579
+ // Calculate tooltip position based on item position
1580
+ let tooltipPosition = 'left';
1581
+ if (x > 20) tooltipPosition = 'left';
1582
+ else if (x < -20) tooltipPosition = 'right';
1583
+ else if (y < 0) tooltipPosition = 'bottom';
1584
+ else tooltipPosition = 'top';
1585
+
1586
+ // Slot key for keyboard shortcut (1-4 for top, Q-W-E-R for bottom L→R)
1587
+ const slotKey = getSlotKeyLabel(index, itemCount);
1588
+
1589
+ html += `
1590
+ <button class="quick-action-item${isEnabled ? '' : ' disabled'}"
1591
+ data-action-id="${actionId}"
1592
+ data-slot="${slotKey}"
1593
+ data-slot-index="${index}"
1594
+ data-tooltip="${action.label}${action.shortcut ? ` (${action.shortcutDisplay})` : ''}"
1595
+ data-tooltip-position="${tooltipPosition}"
1596
+ style="--item-x: ${x}px; --item-y: ${y}px; --item-delay: ${index * 30}ms"
1597
+ ${isEnabled ? '' : 'disabled'}
1598
+ role="menuitem"
1599
+ aria-label="${action.label}${action.shortcut ? ` (${action.shortcutDisplay})` : ''} - Press ${slotKey}">
1600
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
1601
+ ${iconSvg}
1602
+ </svg>
1603
+ <span class="quick-action-slot-number">${slotKey}</span>
1604
+ ${badge ? `<span class="quick-action-badge">${badge}</span>` : ''}
1605
+ </button>
1606
+ `;
1607
+ });
1608
+
1609
+ this.menu.innerHTML = html;
1610
+ }
1611
+
1612
+ executeAction(actionId) {
1613
+ const success = QuickActionsRegistry.execute(actionId);
1614
+ if (success) {
1615
+ this.close();
1616
+ }
1617
+
1618
+ // Restore focus to previous element (keeps keyboard open on iOS)
1619
+ // Use setTimeout to run after action completes.
1620
+ // Skip the restore if the action moved focus to a different input
1621
+ // (e.g. quick switcher) — otherwise we'd steal focus and dismiss
1622
+ // the mobile keyboard that the new input just brought up.
1623
+ if (this.previousFocus && this.previousFocus.focus) {
1624
+ setTimeout(() => {
1625
+ const current = document.activeElement;
1626
+ const tookFocus = current && current !== this.previousFocus &&
1627
+ (current.tagName === 'INPUT' ||
1628
+ current.tagName === 'TEXTAREA' ||
1629
+ current.isContentEditable);
1630
+ if (!tookFocus) {
1631
+ this.previousFocus?.focus();
1632
+ }
1633
+ this.previousFocus = null;
1634
+ }, 50);
1635
+ }
1636
+ }
1637
+
1638
+ /**
1639
+ * Update configuration (called from settings)
1640
+ */
1641
+ setConfig(newConfig) {
1642
+ this.config = { ...this.config, ...newConfig };
1643
+ this.saveState();
1644
+ if (this.isOpen) {
1645
+ this.renderMenuItems();
1646
+ }
1647
+ }
1648
+
1649
+ /**
1650
+ * Apply a preset
1651
+ */
1652
+ applyPreset(presetId) {
1653
+ const preset = QUICK_ACTION_PRESETS[presetId];
1654
+ if (!preset) {
1655
+ console.warn(`[QuickActions] Unknown preset: ${presetId}`);
1656
+ return;
1657
+ }
1658
+
1659
+ this.config.preset = presetId;
1660
+ this.config.slots = [...preset.slots];
1661
+ this.saveState();
1662
+
1663
+ if (this.isOpen) {
1664
+ this.renderMenuItems();
1665
+ }
1666
+ }
1667
+
1668
+ /**
1669
+ * Get current configuration
1670
+ */
1671
+ getConfig() {
1672
+ return { ...this.config };
1673
+ }
1674
+
1675
+ /**
1676
+ * Get user-defined custom actions
1677
+ */
1678
+ getCustomActions() {
1679
+ return [...this.customActions];
1680
+ }
1681
+
1682
+ /**
1683
+ * Replace custom actions: re-sync the registry, persist, refresh menu
1684
+ */
1685
+ setCustomActions(list) {
1686
+ this.customActions = Array.isArray(list) ? list : [];
1687
+ syncCustomActions(this.customActions);
1688
+ this.saveState();
1689
+
1690
+ if (this.isOpen) {
1691
+ this.renderMenuItems();
1692
+ }
1693
+ }
1694
+
1695
+ /**
1696
+ * Set FAB visibility mode: 'always' | 'mobile' | 'disabled'
1697
+ */
1698
+ setVisibility(mode) {
1699
+ if (!['always', 'mobile', 'disabled'].includes(mode)) return;
1700
+ this.visibility = mode;
1701
+ this.updateVisibility();
1702
+ this.saveState();
1703
+ }
1704
+
1705
+ /**
1706
+ * Get FAB visibility mode
1707
+ */
1708
+ getVisibility() {
1709
+ return this.visibility;
1710
+ }
1711
+
1712
+ /**
1713
+ * Reset position to default
1714
+ */
1715
+ resetPosition() {
1716
+ this.position = getDefaultPosition();
1717
+ this.applyPosition();
1718
+ this.saveState();
1719
+ }
1720
+ }
1721
+
1722
+ // ─────────────────────────────────────────────────────────────────────────────
1723
+ // Singleton instance
1724
+ // ─────────────────────────────────────────────────────────────────────────────
1725
+
1726
+ export const quickActionsMenu = new QuickActionsMenu();
1727
+
1728
+ /**
1729
+ * Initialize the quick actions menu
1730
+ */
1731
+ export function initQuickActionsMenu() {
1732
+ quickActionsMenu.init();
1733
+ }
1734
+
1735
+ // Export for settings panel
1736
+ export { QUICK_ACTION_PRESETS, getSlotKeyLabel };