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.
- painapple_code/__init__.py +30 -0
- painapple_code/__main__.py +18 -0
- painapple_code/_version.py +24 -0
- painapple_code/auth_middleware.py +930 -0
- painapple_code/cli/__init__.py +204 -0
- painapple_code/cli/deploy/__init__.py +15 -0
- painapple_code/cli/deploy/claude_seed.py +41 -0
- painapple_code/cli/deploy/config.py +260 -0
- painapple_code/cli/deploy/container.py +715 -0
- painapple_code/cli/deploy/launch.py +163 -0
- painapple_code/cli/deploy/runtime.py +223 -0
- painapple_code/cli/lifecycle_cmd.py +443 -0
- painapple_code/cli/list_cmd.py +572 -0
- painapple_code/cli/manage_cmd.py +670 -0
- painapple_code/cli/netinfo.py +125 -0
- painapple_code/cli/profiles.py +390 -0
- painapple_code/cli/serve_args.py +163 -0
- painapple_code/cli/serve_config.py +256 -0
- painapple_code/cli/setup_cmd.py +664 -0
- painapple_code/cli/ui.py +438 -0
- painapple_code/cost_analytics.py +879 -0
- painapple_code/data/models.defaults.yaml +18 -0
- painapple_code/data/models.yaml +18 -0
- painapple_code/data/presets.defaults.json +32 -0
- painapple_code/data/strings.yaml +2269 -0
- painapple_code/helpers.py +406 -0
- painapple_code/paths.py +1514 -0
- painapple_code/prompt_explorer.py +984 -0
- painapple_code/providers/__init__.py +224 -0
- painapple_code/providers/base.py +710 -0
- painapple_code/providers/claude/__init__.py +74 -0
- painapple_code/providers/claude/capabilities.py +218 -0
- painapple_code/providers/claude/errors.py +79 -0
- painapple_code/providers/claude/launch.py +50 -0
- painapple_code/providers/claude/summary.py +89 -0
- painapple_code/providers/claude/translate.py +74 -0
- painapple_code/providers/claude_sdk/__init__.py +139 -0
- painapple_code/providers/claude_sdk/driver.py +412 -0
- painapple_code/providers/codex/__init__.py +87 -0
- painapple_code/providers/codex/capabilities.py +321 -0
- painapple_code/providers/codex/errors.py +70 -0
- painapple_code/providers/codex/launch.py +142 -0
- painapple_code/providers/codex/summary.py +196 -0
- painapple_code/providers/codex/translate.py +204 -0
- painapple_code/providers/codex_app_server/__init__.py +100 -0
- painapple_code/providers/codex_app_server/capabilities.py +41 -0
- painapple_code/providers/codex_app_server/launch.py +202 -0
- painapple_code/providers/codex_app_server/summary.py +291 -0
- painapple_code/providers/codex_app_server/translate.py +263 -0
- painapple_code/providers/codex_app_server/transport.py +238 -0
- painapple_code/routes/__init__.py +0 -0
- painapple_code/routes/api_agents.py +441 -0
- painapple_code/routes/api_app.py +368 -0
- painapple_code/routes/api_app_commit_sections.py +127 -0
- painapple_code/routes/api_app_config.py +997 -0
- painapple_code/routes/api_app_session_prefs.py +217 -0
- painapple_code/routes/api_browser.py +690 -0
- painapple_code/routes/api_commands.py +374 -0
- painapple_code/routes/api_costs.py +128 -0
- painapple_code/routes/api_drafts.py +139 -0
- painapple_code/routes/api_exec.py +149 -0
- painapple_code/routes/api_files.py +542 -0
- painapple_code/routes/api_git.py +657 -0
- painapple_code/routes/api_logs.py +649 -0
- painapple_code/routes/api_plugins.py +275 -0
- painapple_code/routes/api_project_config.py +418 -0
- painapple_code/routes/api_prompts.py +231 -0
- painapple_code/routes/api_providers.py +53 -0
- painapple_code/routes/api_search.py +411 -0
- painapple_code/routes/api_session_stash.py +234 -0
- painapple_code/routes/api_session_welcome.py +151 -0
- painapple_code/routes/api_sessions.py +742 -0
- painapple_code/routes/api_shadow.py +323 -0
- painapple_code/routes/api_shadow_db.py +512 -0
- painapple_code/routes/api_shadow_files.py +332 -0
- painapple_code/routes/api_shadow_search.py +476 -0
- painapple_code/routes/api_skills.py +610 -0
- painapple_code/routes/api_tasks.py +147 -0
- painapple_code/routes/api_terminal.py +540 -0
- painapple_code/routes/api_upload.py +293 -0
- painapple_code/routes/api_viewer.py +229 -0
- painapple_code/routes/dependencies.py +109 -0
- painapple_code/routes/ws_chat.py +837 -0
- painapple_code/server.py +2208 -0
- painapple_code/server_logging.py +263 -0
- painapple_code/services/__init__.py +0 -0
- painapple_code/services/agent_session.py +2738 -0
- painapple_code/session_store.py +253 -0
- painapple_code/session_store_core.py +879 -0
- painapple_code/shadow_db.py +830 -0
- painapple_code/shadow_db_plans.py +369 -0
- painapple_code/shadow_db_queries.py +595 -0
- painapple_code/shadow_db_schema.py +676 -0
- painapple_code/shadow_git.py +1296 -0
- painapple_code/shadow_git_frontmatter.py +314 -0
- painapple_code/shadow_git_sections.py +520 -0
- painapple_code/shadow_git_summary.py +462 -0
- painapple_code/shadow_parser.py +560 -0
- painapple_code/static/css/00-variables.css +276 -0
- painapple_code/static/css/01-base.css +245 -0
- painapple_code/static/css/02-tooltips.css +36 -0
- painapple_code/static/css/09-left-rail.css +448 -0
- painapple_code/static/css/10-header.css +777 -0
- painapple_code/static/css/11-connection-bar.css +120 -0
- painapple_code/static/css/20-messages.css +750 -0
- painapple_code/static/css/21-tool-blocks.css +2340 -0
- painapple_code/static/css/22-edit-diff.css +619 -0
- painapple_code/static/css/23-thinking.css +1584 -0
- painapple_code/static/css/24-background-tasks.css +359 -0
- painapple_code/static/css/25-context-block.css +252 -0
- painapple_code/static/css/26-session-setup.css +144 -0
- painapple_code/static/css/30-markdown.css +854 -0
- painapple_code/static/css/40-input.css +2418 -0
- painapple_code/static/css/41-autocomplete.css +127 -0
- painapple_code/static/css/42-activity-strip.css +97 -0
- painapple_code/static/css/43-file-autocomplete.css +121 -0
- painapple_code/static/css/44-snippets-autocomplete.css +224 -0
- painapple_code/static/css/45-selection-bar.css +433 -0
- painapple_code/static/css/46-keyboard-bar.css +119 -0
- painapple_code/static/css/47-keyboard-longpress.css +116 -0
- painapple_code/static/css/47-token-profile.css +106 -0
- painapple_code/static/css/50-welcome.css +3095 -0
- painapple_code/static/css/51-modals.css +301 -0
- painapple_code/static/css/52-utilities.css +77 -0
- painapple_code/static/css/53-image-upload.css +456 -0
- painapple_code/static/css/54-todo-list.css +102 -0
- painapple_code/static/css/55-file-upload.css +113 -0
- painapple_code/static/css/56-chat-navigator.css +218 -0
- painapple_code/static/css/56-permission-card.css +332 -0
- painapple_code/static/css/56-plan-approval.css +204 -0
- painapple_code/static/css/56-question-form.css +602 -0
- painapple_code/static/css/57-swipe-indicator.css +95 -0
- painapple_code/static/css/58-session-families.css +627 -0
- painapple_code/static/css/59-about.css +196 -0
- painapple_code/static/css/61-log-explorer.css +723 -0
- painapple_code/static/css/62-json-tree.css +489 -0
- painapple_code/static/css/62-skills-widget.css +650 -0
- painapple_code/static/css/63-commands-widget.css +30 -0
- painapple_code/static/css/63-plugins-widget.css +174 -0
- painapple_code/static/css/63-terminal.css +516 -0
- painapple_code/static/css/64-search-files-widget.css +448 -0
- painapple_code/static/css/65-snippets-widget.css +426 -0
- painapple_code/static/css/66-active-sessions.css +979 -0
- painapple_code/static/css/66-agents-widget.css +265 -0
- painapple_code/static/css/66-file-explorer-widget.css +855 -0
- painapple_code/static/css/66-git-panel.css +791 -0
- painapple_code/static/css/66-history-explorer.css +1496 -0
- painapple_code/static/css/67-diff-viewer.css +602 -0
- painapple_code/static/css/67-editor-view.css +748 -0
- painapple_code/static/css/67-file-preview-widget.css +1873 -0
- painapple_code/static/css/68-browser-widget.css +337 -0
- painapple_code/static/css/68-compare-wizard.css +355 -0
- painapple_code/static/css/68-csv-preview.css +106 -0
- painapple_code/static/css/68-diff-preview.css +103 -0
- painapple_code/static/css/68-helpers-install-widget.css +491 -0
- painapple_code/static/css/68-image-annotate.css +346 -0
- painapple_code/static/css/68-terminal-view.css +98 -0
- painapple_code/static/css/68-uploads-widget.css +229 -0
- painapple_code/static/css/69-cost-analytics.css +537 -0
- painapple_code/static/css/70-config-panel.css +3736 -0
- painapple_code/static/css/70-excalidraw.css +136 -0
- painapple_code/static/css/70-prompt-explorer.css +890 -0
- painapple_code/static/css/71-chart.css +111 -0
- painapple_code/static/css/72-discussion-sidebar.css +678 -0
- painapple_code/static/css/74-debug-logs.css +656 -0
- painapple_code/static/css/80-open-dialog.css +146 -0
- painapple_code/static/css/80-quick-switcher.css +383 -0
- painapple_code/static/css/80-widget-system.css +1763 -0
- painapple_code/static/css/81-quick-actions.css +1020 -0
- painapple_code/static/css/82-context-popover.css +1233 -0
- painapple_code/static/css/83-context-menu.css +339 -0
- painapple_code/static/css/85-lazy-loading.css +102 -0
- painapple_code/static/css/86-zen-mode.css +708 -0
- painapple_code/static/css/87-grid-switcher.css +346 -0
- painapple_code/static/css/login.css +198 -0
- painapple_code/static/dist/app.bundle.js +7177 -0
- painapple_code/static/feature-triage.html +446 -0
- painapple_code/static/icons/apple-touch-icon.png +0 -0
- painapple_code/static/icons/favicon-32.png +0 -0
- painapple_code/static/icons/favicon.ico +0 -0
- painapple_code/static/icons/icon-128.png +0 -0
- painapple_code/static/icons/icon-144.png +0 -0
- painapple_code/static/icons/icon-152.png +0 -0
- painapple_code/static/icons/icon-180.png +0 -0
- painapple_code/static/icons/icon-192.png +0 -0
- painapple_code/static/icons/icon-384.png +0 -0
- painapple_code/static/icons/icon-512.png +0 -0
- painapple_code/static/icons/icon-72.png +0 -0
- painapple_code/static/icons/icon-96.png +0 -0
- painapple_code/static/js/action-delegate.js +187 -0
- painapple_code/static/js/activity-strip.js +193 -0
- painapple_code/static/js/app/context-menus.js +619 -0
- painapple_code/static/js/app/file-preview.js +163 -0
- painapple_code/static/js/app/init-ui.js +574 -0
- painapple_code/static/js/app/input-events.js +561 -0
- painapple_code/static/js/app/input-resize.js +313 -0
- painapple_code/static/js/app/message-actions.js +419 -0
- painapple_code/static/js/app/panels.js +210 -0
- painapple_code/static/js/app/rendering-delegators.js +246 -0
- painapple_code/static/js/app/server-loading.js +365 -0
- painapple_code/static/js/app/session-ops.js +287 -0
- painapple_code/static/js/app/session-switch.js +443 -0
- painapple_code/static/js/app/settings-helpers.js +280 -0
- painapple_code/static/js/app/startup-welcome.js +290 -0
- painapple_code/static/js/app-context.js +157 -0
- painapple_code/static/js/app.js +2134 -0
- painapple_code/static/js/auth-fetch.js +46 -0
- painapple_code/static/js/background-tasks.js +274 -0
- painapple_code/static/js/boot.js +73 -0
- painapple_code/static/js/caret-position.js +171 -0
- painapple_code/static/js/chat-navigator.js +710 -0
- painapple_code/static/js/chat-search.js +323 -0
- painapple_code/static/js/command-executor.js +176 -0
- painapple_code/static/js/command-store.js +497 -0
- painapple_code/static/js/components.js +1414 -0
- painapple_code/static/js/config.js +218 -0
- painapple_code/static/js/context-menu.js +740 -0
- painapple_code/static/js/controllers/chat-controller.js +4252 -0
- painapple_code/static/js/controllers/dialog-controller.js +217 -0
- painapple_code/static/js/controllers/tab-controller.js +1828 -0
- painapple_code/static/js/controllers/thinking-controller.js +915 -0
- painapple_code/static/js/diff-utils.js +486 -0
- painapple_code/static/js/drafts-pill.js +95 -0
- painapple_code/static/js/editor-view.js +815 -0
- painapple_code/static/js/effort-settings.js +430 -0
- painapple_code/static/js/feature-triage.js +811 -0
- painapple_code/static/js/file-autocomplete.js +516 -0
- painapple_code/static/js/file-tabs.js +123 -0
- painapple_code/static/js/gestures.js +448 -0
- painapple_code/static/js/grid-switcher.js +334 -0
- painapple_code/static/js/input-handler.js +1472 -0
- painapple_code/static/js/keyboard-bar.js +495 -0
- painapple_code/static/js/layout-switcher.js +109 -0
- painapple_code/static/js/linkify-utils.js +200 -0
- painapple_code/static/js/login.js +141 -0
- painapple_code/static/js/open-dialog.js +879 -0
- painapple_code/static/js/orphan-terminals.js +373 -0
- painapple_code/static/js/path-utils.js +179 -0
- painapple_code/static/js/perf-marks.js +102 -0
- painapple_code/static/js/permission-settings.js +475 -0
- painapple_code/static/js/pointer-input.js +59 -0
- painapple_code/static/js/preview/json-tree-menu.js +226 -0
- painapple_code/static/js/preview/json-tree-toolbar.js +291 -0
- painapple_code/static/js/preview/json-tree.js +457 -0
- painapple_code/static/js/preview/preview-breadcrumb.js +387 -0
- painapple_code/static/js/preview/preview-edit.js +367 -0
- painapple_code/static/js/preview/preview-events.js +361 -0
- painapple_code/static/js/preview/preview-history.js +567 -0
- painapple_code/static/js/preview/preview-inline-edit.js +869 -0
- painapple_code/static/js/preview/preview-poll.js +108 -0
- painapple_code/static/js/preview/preview-render.js +572 -0
- painapple_code/static/js/preview/preview-search.js +421 -0
- painapple_code/static/js/preview/preview-state.js +256 -0
- painapple_code/static/js/preview/preview-utils.js +251 -0
- painapple_code/static/js/preview-plugins/chart-plugin.js +22 -0
- painapple_code/static/js/preview-plugins/csv-plugin.js +188 -0
- painapple_code/static/js/preview-plugins/diff-plugin.js +258 -0
- painapple_code/static/js/preview-plugins/excalidraw-plugin.js +25 -0
- painapple_code/static/js/preview-plugins/html-plugin.js +104 -0
- painapple_code/static/js/preview-plugins/image-plugin.js +20 -0
- painapple_code/static/js/preview-plugins/index.js +34 -0
- painapple_code/static/js/preview-plugins/json-plugin.js +99 -0
- painapple_code/static/js/preview-plugins/jsonl-plugin.js +152 -0
- painapple_code/static/js/preview-plugins/markdown-plugin.js +266 -0
- painapple_code/static/js/preview-plugins/panzoom-plugin.js +63 -0
- painapple_code/static/js/preview-plugins/plugin-helpers.js +282 -0
- painapple_code/static/js/project-color-picker.js +110 -0
- painapple_code/static/js/project-colors.js +163 -0
- painapple_code/static/js/prompt-favorites.js +187 -0
- painapple_code/static/js/quick-actions-menu.js +1736 -0
- painapple_code/static/js/quick-actions-registry.js +1239 -0
- painapple_code/static/js/quick-switcher/controller.js +294 -0
- painapple_code/static/js/quick-switcher/fuzzy-scorer.js +123 -0
- painapple_code/static/js/quick-switcher/index.js +30 -0
- painapple_code/static/js/quick-switcher/providers/base-provider.js +51 -0
- painapple_code/static/js/quick-switcher/providers/command-provider.js +56 -0
- painapple_code/static/js/quick-switcher/providers/file-provider.js +291 -0
- painapple_code/static/js/quick-switcher/providers/panel-provider.js +132 -0
- painapple_code/static/js/quick-switcher/providers/project-provider.js +361 -0
- painapple_code/static/js/quick-switcher/providers/read-files-provider.js +104 -0
- painapple_code/static/js/quick-switcher/providers/skills-provider.js +129 -0
- painapple_code/static/js/quick-switcher/registry.js +69 -0
- painapple_code/static/js/quick-switcher/ui/item.js +54 -0
- painapple_code/static/js/quick-switcher/ui/picker.js +464 -0
- painapple_code/static/js/recent-opens.js +40 -0
- painapple_code/static/js/scroll-manager.js +530 -0
- painapple_code/static/js/scroll-state-machine.js +359 -0
- painapple_code/static/js/selection/action-bar.js +793 -0
- painapple_code/static/js/selection/index.js +15 -0
- painapple_code/static/js/selection/selection-handler.js +877 -0
- painapple_code/static/js/selection/state.js +181 -0
- painapple_code/static/js/session/agent-progress.js +202 -0
- painapple_code/static/js/session/handle-agent-message.js +481 -0
- painapple_code/static/js/session/handle-message.js +550 -0
- painapple_code/static/js/session/interactive.js +587 -0
- painapple_code/static/js/session/message-store.js +271 -0
- painapple_code/static/js/session/messages.js +253 -0
- painapple_code/static/js/session/persistence.js +179 -0
- painapple_code/static/js/session/restore.js +136 -0
- painapple_code/static/js/session/sync.js +333 -0
- painapple_code/static/js/session-container-pool.js +371 -0
- painapple_code/static/js/session-setup-panel.js +274 -0
- painapple_code/static/js/session.js +1047 -0
- painapple_code/static/js/shortcut-hints.js +272 -0
- painapple_code/static/js/shortcuts.js +1146 -0
- painapple_code/static/js/skills-autocomplete.js +262 -0
- painapple_code/static/js/snippets-autocomplete.js +738 -0
- painapple_code/static/js/stash-refs-view.js +83 -0
- painapple_code/static/js/stash-ui.js +768 -0
- painapple_code/static/js/stash.js +785 -0
- painapple_code/static/js/status-bar.js +1184 -0
- painapple_code/static/js/token-profile.js +274 -0
- painapple_code/static/js/tool-renderer-blocks.js +1626 -0
- painapple_code/static/js/tool-renderer-thinking.js +813 -0
- painapple_code/static/js/tool-renderer.js +1500 -0
- painapple_code/static/js/tooltips.js +197 -0
- painapple_code/static/js/upload-manager.js +1019 -0
- painapple_code/static/js/utils.js +521 -0
- painapple_code/static/js/welcome/api.js +363 -0
- painapple_code/static/js/welcome/cards.js +626 -0
- painapple_code/static/js/welcome/context-menu.js +585 -0
- painapple_code/static/js/welcome/families.js +801 -0
- painapple_code/static/js/welcome/preview.js +234 -0
- painapple_code/static/js/welcome/state.js +129 -0
- painapple_code/static/js/welcome.js +1874 -0
- painapple_code/static/js/widget-system/base-widget.js +717 -0
- painapple_code/static/js/widget-system/device-manager.js +178 -0
- painapple_code/static/js/widget-system/event-bus.js +152 -0
- painapple_code/static/js/widget-system/icons.js +120 -0
- painapple_code/static/js/widget-system/index.js +49 -0
- painapple_code/static/js/widget-system/init.js +54 -0
- painapple_code/static/js/widget-system/types/bottom-sheet.js +307 -0
- painapple_code/static/js/widget-system/types/floating.js +915 -0
- painapple_code/static/js/widget-system/types/index.js +40 -0
- painapple_code/static/js/widget-system/types/modal.js +147 -0
- painapple_code/static/js/widget-system/types/sidebar.js +158 -0
- painapple_code/static/js/widget-system/types/tab.js +146 -0
- painapple_code/static/js/widget-system/types/top-sheet.js +203 -0
- painapple_code/static/js/widget-system/widget-manager.js +1187 -0
- painapple_code/static/js/widgets/about-widget.js +260 -0
- painapple_code/static/js/widgets/active-sessions-widget.js +760 -0
- painapple_code/static/js/widgets/agents-widget.js +897 -0
- painapple_code/static/js/widgets/browser-widget.js +579 -0
- painapple_code/static/js/widgets/commands-widget.js +694 -0
- painapple_code/static/js/widgets/config/commit-sections.js +449 -0
- painapple_code/static/js/widgets/config/dir-autocomplete.js +224 -0
- painapple_code/static/js/widgets/config/gestures.js +161 -0
- painapple_code/static/js/widgets/config/models-tab.js +988 -0
- painapple_code/static/js/widgets/config/quick-actions-tab.js +882 -0
- painapple_code/static/js/widgets/config/shortcut-editor.js +587 -0
- painapple_code/static/js/widgets/config/state.js +517 -0
- painapple_code/static/js/widgets/config/system-controls.js +90 -0
- painapple_code/static/js/widgets/config-widget.js +1535 -0
- painapple_code/static/js/widgets/cost-analytics-widget.js +621 -0
- painapple_code/static/js/widgets/debug-widget.js +693 -0
- painapple_code/static/js/widgets/diff-viewer-widget.js +1420 -0
- painapple_code/static/js/widgets/discussion-widget.js +1107 -0
- painapple_code/static/js/widgets/file-explorer-widget.js +2166 -0
- painapple_code/static/js/widgets/file-preview-widget.js +861 -0
- painapple_code/static/js/widgets/git-widget.js +794 -0
- painapple_code/static/js/widgets/helpers-install-widget.js +720 -0
- painapple_code/static/js/widgets/history-explorer-widget.js +1804 -0
- painapple_code/static/js/widgets/image-annotate-widget.js +951 -0
- painapple_code/static/js/widgets/image-preview-widget.js +692 -0
- painapple_code/static/js/widgets/index.js +176 -0
- painapple_code/static/js/widgets/log-explorer-widget.js +1057 -0
- painapple_code/static/js/widgets/plugins-widget.js +305 -0
- painapple_code/static/js/widgets/prompt-explorer-widget.js +1119 -0
- painapple_code/static/js/widgets/search-files-widget.js +529 -0
- painapple_code/static/js/widgets/skills-widget.js +843 -0
- painapple_code/static/js/widgets/snippets-widget.js +479 -0
- painapple_code/static/js/widgets/sub-agents-widget.js +333 -0
- painapple_code/static/js/widgets/tasks-widget.js +379 -0
- painapple_code/static/js/widgets/terminal/connection.js +283 -0
- painapple_code/static/js/widgets/terminal/gestures.js +357 -0
- painapple_code/static/js/widgets/terminal/init.js +642 -0
- painapple_code/static/js/widgets/terminal/link-providers.js +532 -0
- painapple_code/static/js/widgets/terminal/osc52.js +213 -0
- painapple_code/static/js/widgets/terminal/render.js +159 -0
- painapple_code/static/js/widgets/terminal/size.js +54 -0
- painapple_code/static/js/widgets/terminal/state.js +211 -0
- painapple_code/static/js/widgets/terminal/wrap-utils.js +101 -0
- painapple_code/static/js/widgets/terminal-widget.js +793 -0
- painapple_code/static/js/widgets/uploads-widget.js +461 -0
- painapple_code/static/js/widgets/zen-widget.js +1001 -0
- painapple_code/static/login.html +51 -0
- painapple_code/static/manifest.json +73 -0
- painapple_code/static/sw.js +293 -0
- painapple_code/static/vendor/LICENSES.txt +769 -0
- painapple_code/static/vendor/README.md +103 -0
- painapple_code/static/vendor/codemirror.js +35 -0
- painapple_code/static/vendor/codemirror.js.LEGAL.txt +304 -0
- painapple_code/static/vendor/github-markdown-dark.min.css +1124 -0
- painapple_code/static/vendor/highlight-github-dark.min.css +10 -0
- painapple_code/static/vendor/highlight-lang-dockerfile.min.js +8 -0
- painapple_code/static/vendor/highlight-lang-nginx.min.js +21 -0
- painapple_code/static/vendor/highlight-lang-properties.min.js +10 -0
- painapple_code/static/vendor/highlight-lang-scala.min.js +28 -0
- painapple_code/static/vendor/highlight.min.js +1213 -0
- painapple_code/static/vendor/marked.min.js +6 -0
- painapple_code/static/vendor/purify.min.js +3 -0
- painapple_code/static/vendor/xterm-addon-fit.js +2 -0
- painapple_code/static/vendor/xterm.css +209 -0
- painapple_code/static/vendor/xterm.js +2 -0
- painapple_code/static/web-client.html +635 -0
- painapple_code/subprocess_registry.py +535 -0
- painapple_code/tls_cert.py +79 -0
- painapple_code/tools/agents/shadow-git-helper.md +400 -0
- painapple_code/tools/excalidraw-to-svg.js +143 -0
- painapple_code/tools/install-helpers.sh +148 -0
- painapple_code/tools/shadow-git +320 -0
- painapple_code/tools/shadow-query +120 -0
- painapple_code/tools/vegalite-to-svg.js +79 -0
- painapple_code/turn_query.py +766 -0
- painapple_code/turn_tracker.py +221 -0
- painapple_code/utils/__init__.py +0 -0
- painapple_code/utils/agent_cli.py +306 -0
- painapple_code/utils/chart.py +103 -0
- painapple_code/utils/excalidraw.py +107 -0
- painapple_code/utils/file_lock.py +162 -0
- painapple_code/utils/file_paths.py +648 -0
- painapple_code/utils/generate_icons.py +251 -0
- painapple_code/utils/proc.py +205 -0
- painapple_code/utils/pty_backend.py +59 -0
- painapple_code/utils/pty_posix.py +160 -0
- painapple_code/utils/pty_windows.py +245 -0
- painapple_code/utils/token_profiles.py +91 -0
- painapple_code/viewer_templates.py +657 -0
- painapple_code/welcome_search.py +879 -0
- painapple_code-1.0.0.dist-info/METADATA +292 -0
- painapple_code-1.0.0.dist-info/RECORD +436 -0
- painapple_code-1.0.0.dist-info/WHEEL +5 -0
- painapple_code-1.0.0.dist-info/entry_points.txt +2 -0
- painapple_code-1.0.0.dist-info/licenses/LICENSE +661 -0
- painapple_code-1.0.0.dist-info/licenses/THIRD_PARTY_NOTICES.md +261 -0
- painapple_code-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,1187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* WidgetManager - Central registry and manager for all widgets
|
|
3
|
+
*
|
|
4
|
+
* Supports two widget scopes:
|
|
5
|
+
* - 'global': One shared instance (config, debug, cost analytics, etc.)
|
|
6
|
+
* - 'session': Separate instance per session tab (terminal, git, changes, etc.)
|
|
7
|
+
*
|
|
8
|
+
* Session-scoped widgets are hidden/shown on session switch (not destroyed/recreated),
|
|
9
|
+
* preserving DOM state, WebSocket connections, scroll positions, etc.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { WidgetBus } from './event-bus.js';
|
|
13
|
+
import { DeviceManager } from './device-manager.js';
|
|
14
|
+
import { getWidgetClass } from './types/index.js';
|
|
15
|
+
import { debug } from '../config.js';
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Default widget types per device
|
|
19
|
+
*/
|
|
20
|
+
const DEVICE_DEFAULTS = {
|
|
21
|
+
'file-explorer': {
|
|
22
|
+
default: 'top-sheet',
|
|
23
|
+
phone: 'top-sheet',
|
|
24
|
+
tablet: 'top-sheet',
|
|
25
|
+
desktop: 'floating'
|
|
26
|
+
},
|
|
27
|
+
'terminal': {
|
|
28
|
+
default: 'top-sheet',
|
|
29
|
+
phone: 'top-sheet',
|
|
30
|
+
tablet: 'floating',
|
|
31
|
+
desktop: 'floating'
|
|
32
|
+
},
|
|
33
|
+
'git': {
|
|
34
|
+
default: 'bottom-sheet',
|
|
35
|
+
phone: 'bottom-sheet',
|
|
36
|
+
tablet: 'bottom-sheet',
|
|
37
|
+
desktop: 'sidebar-right'
|
|
38
|
+
},
|
|
39
|
+
'logs': {
|
|
40
|
+
default: 'bottom-sheet',
|
|
41
|
+
phone: 'bottom-sheet',
|
|
42
|
+
tablet: 'bottom-sheet',
|
|
43
|
+
desktop: 'bottom-sheet'
|
|
44
|
+
},
|
|
45
|
+
'settings': {
|
|
46
|
+
default: 'modal',
|
|
47
|
+
phone: 'modal',
|
|
48
|
+
tablet: 'modal',
|
|
49
|
+
desktop: 'modal'
|
|
50
|
+
},
|
|
51
|
+
'comments': {
|
|
52
|
+
default: 'top-sheet',
|
|
53
|
+
phone: 'top-sheet',
|
|
54
|
+
tablet: 'top-sheet',
|
|
55
|
+
desktop: 'sidebar-right'
|
|
56
|
+
}
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
class WidgetManagerClass {
|
|
60
|
+
constructor() {
|
|
61
|
+
/** @type {Map<string, object>} Widget configs (registration data) */
|
|
62
|
+
this.configs = new Map();
|
|
63
|
+
|
|
64
|
+
/** @type {Map<string, import('./base-widget.js').BaseWidget>} Global widget instances */
|
|
65
|
+
this.globalWidgets = new Map();
|
|
66
|
+
|
|
67
|
+
/** @type {Map<string, Map<string, import('./base-widget.js').BaseWidget>>} Session widget instances: sessionId -> (widgetId -> widget) */
|
|
68
|
+
this.sessionWidgets = new Map();
|
|
69
|
+
|
|
70
|
+
/** @type {Array<import('./base-widget.js').BaseWidget>} Z-index ordering stack */
|
|
71
|
+
this.zIndexStack = [];
|
|
72
|
+
|
|
73
|
+
/** @type {string|null} */
|
|
74
|
+
this.currentSessionId = null;
|
|
75
|
+
|
|
76
|
+
/** @type {string|null} */
|
|
77
|
+
this.currentCwd = null;
|
|
78
|
+
|
|
79
|
+
// Base z-index for floating widgets (above old panels: modals 1000, log-explorer 999, terminal 900)
|
|
80
|
+
this.baseZIndex = 1500;
|
|
81
|
+
|
|
82
|
+
// User type overrides (from settings)
|
|
83
|
+
this.userTypeOverrides = this.loadUserOverrides();
|
|
84
|
+
|
|
85
|
+
// Backwards compat: keep this.widgets as a proxy that routes through _resolve
|
|
86
|
+
// This handles any external code that directly accesses WidgetManager.widgets
|
|
87
|
+
this.widgets = this._createWidgetsProxy();
|
|
88
|
+
|
|
89
|
+
// Set up event listeners
|
|
90
|
+
this.setupEventListeners();
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Create a proxy for backwards-compat this.widgets access.
|
|
95
|
+
* External code that calls WidgetManager.widgets.get(id) still works.
|
|
96
|
+
*/
|
|
97
|
+
_createWidgetsProxy() {
|
|
98
|
+
const self = this;
|
|
99
|
+
return {
|
|
100
|
+
get(id) { return self._resolve(id); },
|
|
101
|
+
has(id) { return !!self._resolve(id); },
|
|
102
|
+
set(id, widget) {
|
|
103
|
+
// Should not be used externally, but route correctly
|
|
104
|
+
const config = self.configs.get(id);
|
|
105
|
+
if (config?.scope === 'session') {
|
|
106
|
+
const map = self._getSessionMap();
|
|
107
|
+
if (map) map.set(id, widget);
|
|
108
|
+
} else {
|
|
109
|
+
self.globalWidgets.set(id, widget);
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
delete(id) {
|
|
113
|
+
const config = self.configs.get(id);
|
|
114
|
+
if (config?.scope === 'session') {
|
|
115
|
+
const map = self.sessionWidgets.get(self.currentSessionId);
|
|
116
|
+
if (map) map.delete(id);
|
|
117
|
+
} else {
|
|
118
|
+
self.globalWidgets.delete(id);
|
|
119
|
+
}
|
|
120
|
+
},
|
|
121
|
+
forEach(fn) {
|
|
122
|
+
// Iterate global + current session widgets
|
|
123
|
+
self.globalWidgets.forEach(fn);
|
|
124
|
+
const sessionMap = self.sessionWidgets.get(self.currentSessionId);
|
|
125
|
+
if (sessionMap) sessionMap.forEach(fn);
|
|
126
|
+
},
|
|
127
|
+
get size() {
|
|
128
|
+
let count = self.globalWidgets.size;
|
|
129
|
+
const sessionMap = self.sessionWidgets.get(self.currentSessionId);
|
|
130
|
+
if (sessionMap) count += sessionMap.size;
|
|
131
|
+
return count;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
// ==================== Internal Helpers ====================
|
|
137
|
+
|
|
138
|
+
/**
|
|
139
|
+
* Get or create the session widget map for a sessionId
|
|
140
|
+
* @param {string} [sessionId]
|
|
141
|
+
* @returns {Map<string, import('./base-widget.js').BaseWidget>|null}
|
|
142
|
+
*/
|
|
143
|
+
_getSessionMap(sessionId = this.currentSessionId) {
|
|
144
|
+
if (!sessionId) return null;
|
|
145
|
+
if (!this.sessionWidgets.has(sessionId)) {
|
|
146
|
+
this.sessionWidgets.set(sessionId, new Map());
|
|
147
|
+
}
|
|
148
|
+
return this.sessionWidgets.get(sessionId);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Resolve a widget by ID, respecting scope.
|
|
153
|
+
* For session-scoped widgets, returns the current session's instance.
|
|
154
|
+
* @param {string} id
|
|
155
|
+
* @returns {import('./base-widget.js').BaseWidget|undefined}
|
|
156
|
+
*/
|
|
157
|
+
_resolve(id) {
|
|
158
|
+
const config = this.configs.get(id);
|
|
159
|
+
if (!config) return undefined;
|
|
160
|
+
|
|
161
|
+
if (config.scope === 'global') {
|
|
162
|
+
return this.globalWidgets.get(id);
|
|
163
|
+
}
|
|
164
|
+
// Session-scoped
|
|
165
|
+
const sessionMap = this.sessionWidgets.get(this.currentSessionId);
|
|
166
|
+
return sessionMap?.get(id);
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/**
|
|
170
|
+
* Store a widget in the correct map
|
|
171
|
+
* @param {string} id
|
|
172
|
+
* @param {import('./base-widget.js').BaseWidget} widget
|
|
173
|
+
*/
|
|
174
|
+
_store(id, widget) {
|
|
175
|
+
const config = this.configs.get(id);
|
|
176
|
+
if (config?.scope === 'global') {
|
|
177
|
+
this.globalWidgets.set(id, widget);
|
|
178
|
+
} else {
|
|
179
|
+
const map = this._getSessionMap();
|
|
180
|
+
if (map) map.set(id, widget);
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* Remove a widget from the correct map
|
|
186
|
+
* @param {string} id
|
|
187
|
+
*/
|
|
188
|
+
_remove(id) {
|
|
189
|
+
const config = this.configs.get(id);
|
|
190
|
+
if (config?.scope === 'global') {
|
|
191
|
+
this.globalWidgets.delete(id);
|
|
192
|
+
} else {
|
|
193
|
+
const sessionMap = this.sessionWidgets.get(this.currentSessionId);
|
|
194
|
+
if (sessionMap) sessionMap.delete(id);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Iterate ALL widget instances (global + all sessions)
|
|
200
|
+
* @param {Function} fn
|
|
201
|
+
*/
|
|
202
|
+
_forEachWidget(fn) {
|
|
203
|
+
this.globalWidgets.forEach(fn);
|
|
204
|
+
this.sessionWidgets.forEach(sessionMap => {
|
|
205
|
+
sessionMap.forEach(fn);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
/**
|
|
210
|
+
* Compare two CWDs for project-scope matching (normalize trailing slashes)
|
|
211
|
+
* @param {string|null} cwd1
|
|
212
|
+
* @param {string|null} cwd2
|
|
213
|
+
* @returns {boolean}
|
|
214
|
+
*/
|
|
215
|
+
_cwdMatch(cwd1, cwd2) {
|
|
216
|
+
if (!cwd1 || !cwd2) return false;
|
|
217
|
+
const normalize = p => p.replace(/\/+$/, '');
|
|
218
|
+
return normalize(cwd1) === normalize(cwd2);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
// ==================== Event Listeners ====================
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Set up event listeners
|
|
225
|
+
*/
|
|
226
|
+
setupEventListeners() {
|
|
227
|
+
// Handle widget focus (bring to front)
|
|
228
|
+
WidgetBus.on('widget:focus', ({ widgetId }) => {
|
|
229
|
+
const widget = this._resolve(widgetId);
|
|
230
|
+
if (widget) {
|
|
231
|
+
this.bringToFront(widget);
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
// Handle session changes — switch widget visibility
|
|
236
|
+
WidgetBus.on('session:changed', ({ sessionId, cwd }) => {
|
|
237
|
+
this.switchSession(sessionId, cwd);
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// Handle widget transform requests (from BaseWidget.transformTo)
|
|
241
|
+
WidgetBus.on('widget:transform-request', ({ widgetId, newType, options }) => {
|
|
242
|
+
this.transform(widgetId, newType, options);
|
|
243
|
+
});
|
|
244
|
+
|
|
245
|
+
// Handle device changes
|
|
246
|
+
DeviceManager.onChange((newDevice, oldDevice) => {
|
|
247
|
+
this.onDeviceChange(newDevice, oldDevice);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
// Persist open widgets when they open/close
|
|
251
|
+
WidgetBus.on('widget:opened', () => {
|
|
252
|
+
this.saveOpenWidgets();
|
|
253
|
+
});
|
|
254
|
+
WidgetBus.on('widget:closed', () => {
|
|
255
|
+
this.saveOpenWidgets();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
// Handle visibility scope changes — re-evaluate widget visibility
|
|
259
|
+
WidgetBus.on('widget:scope-changed', ({ widgetId, scope, ownerSessionId }) => {
|
|
260
|
+
this._onScopeChanged(widgetId, scope, ownerSessionId);
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/**
|
|
265
|
+
* Re-evaluate a widget's visibility after its scope changed
|
|
266
|
+
* @param {string} widgetId
|
|
267
|
+
* @param {string} scope - New effective scope
|
|
268
|
+
* @param {string|null} ownerSessionId - Widget's owning session
|
|
269
|
+
*/
|
|
270
|
+
_onScopeChanged(widgetId, scope, ownerSessionId) {
|
|
271
|
+
// Find the widget across all session maps
|
|
272
|
+
let widget = this.globalWidgets.get(widgetId);
|
|
273
|
+
if (!widget) {
|
|
274
|
+
for (const [, map] of this.sessionWidgets) {
|
|
275
|
+
widget = map.get(widgetId);
|
|
276
|
+
if (widget) break;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
if (!widget || !widget.isVisible) return;
|
|
280
|
+
|
|
281
|
+
const isOwnSession = ownerSessionId === this.currentSessionId;
|
|
282
|
+
|
|
283
|
+
// Determine if widget should be visible now
|
|
284
|
+
let shouldShow;
|
|
285
|
+
if (scope === 'global' || scope === 'all-sessions') {
|
|
286
|
+
shouldShow = true;
|
|
287
|
+
} else if (scope === 'project') {
|
|
288
|
+
shouldShow = isOwnSession || this._cwdMatch(widget._ownerCwd, this.currentCwd);
|
|
289
|
+
} else {
|
|
290
|
+
// 'session' — only visible on own tab
|
|
291
|
+
shouldShow = isOwnSession;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
if (widget.container) widget.container.style.display = shouldShow ? '' : 'none';
|
|
295
|
+
if (widget._backdrop) widget._backdrop.style.display = shouldShow ? '' : 'none';
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
// ==================== Registration ====================
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* Register a widget configuration
|
|
302
|
+
* @param {string} id - Unique widget ID
|
|
303
|
+
* @param {object} config - Widget configuration
|
|
304
|
+
*/
|
|
305
|
+
register(id, config) {
|
|
306
|
+
// Infer scope: explicit scope > sessionAware flag > default 'session'
|
|
307
|
+
const scope = config.scope || (config.sessionAware === false ? 'global' : 'session');
|
|
308
|
+
|
|
309
|
+
this.configs.set(id, {
|
|
310
|
+
...config,
|
|
311
|
+
id,
|
|
312
|
+
scope
|
|
313
|
+
});
|
|
314
|
+
|
|
315
|
+
return this;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
// ==================== Creation ====================
|
|
319
|
+
|
|
320
|
+
/**
|
|
321
|
+
* Create and initialize a widget
|
|
322
|
+
* @param {string} id - Widget ID (must be registered first)
|
|
323
|
+
* @param {object} options - Override options
|
|
324
|
+
* @returns {import('./base-widget.js').BaseWidget}
|
|
325
|
+
*/
|
|
326
|
+
create(id, options = {}) {
|
|
327
|
+
const config = this.configs.get(id);
|
|
328
|
+
if (!config) {
|
|
329
|
+
throw new Error(`Widget not registered: ${id}`);
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Determine type (user override > device default > config default)
|
|
333
|
+
const type = this.getWidgetType(id, config);
|
|
334
|
+
|
|
335
|
+
// Merge config with type and options
|
|
336
|
+
const finalConfig = {
|
|
337
|
+
...config,
|
|
338
|
+
...options,
|
|
339
|
+
type
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
// Get the appropriate widget class
|
|
343
|
+
const WidgetClass = getWidgetClass(type);
|
|
344
|
+
|
|
345
|
+
// Create instance
|
|
346
|
+
const widget = new WidgetClass(id, finalConfig);
|
|
347
|
+
|
|
348
|
+
// For session-scoped widgets, stamp the owning session ID and CWD
|
|
349
|
+
if (config.scope === 'session') {
|
|
350
|
+
widget._ownerSessionId = this.currentSessionId;
|
|
351
|
+
widget.cwd = this.currentCwd;
|
|
352
|
+
widget._ownerCwd = this.currentCwd;
|
|
353
|
+
} else {
|
|
354
|
+
widget._ownerCwd = this.currentCwd;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
// Store in the correct map
|
|
358
|
+
this._store(id, widget);
|
|
359
|
+
|
|
360
|
+
// Initialize (creates DOM, attaches events)
|
|
361
|
+
widget.init();
|
|
362
|
+
|
|
363
|
+
// Set session and render
|
|
364
|
+
if (config.scope === 'session') {
|
|
365
|
+
// Session widget already knows its session via _ownerSessionId
|
|
366
|
+
widget.sessionId = this.currentSessionId;
|
|
367
|
+
widget.render();
|
|
368
|
+
} else if (this.currentSessionId) {
|
|
369
|
+
widget.setSession(this.currentSessionId);
|
|
370
|
+
} else {
|
|
371
|
+
// Render with null session - ensures content container is set
|
|
372
|
+
widget.render();
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Add to z-index stack
|
|
376
|
+
this.zIndexStack.push(widget);
|
|
377
|
+
this.updateZIndices();
|
|
378
|
+
|
|
379
|
+
return widget;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
/**
|
|
383
|
+
* Get or create a widget (scope-aware)
|
|
384
|
+
* @param {string} id
|
|
385
|
+
* @returns {import('./base-widget.js').BaseWidget}
|
|
386
|
+
*/
|
|
387
|
+
get(id) {
|
|
388
|
+
let widget = this._resolve(id);
|
|
389
|
+
if (!widget && this.configs.has(id)) {
|
|
390
|
+
// For session-scoped widgets, need a current session to create
|
|
391
|
+
const config = this.configs.get(id);
|
|
392
|
+
if (config.scope === 'session' && !this.currentSessionId) {
|
|
393
|
+
return undefined;
|
|
394
|
+
}
|
|
395
|
+
widget = this.create(id);
|
|
396
|
+
}
|
|
397
|
+
return widget;
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
/**
|
|
401
|
+
* Check if widget exists for current scope
|
|
402
|
+
* @param {string} id
|
|
403
|
+
* @returns {boolean}
|
|
404
|
+
*/
|
|
405
|
+
has(id) {
|
|
406
|
+
return !!this._resolve(id);
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
/**
|
|
410
|
+
* Get all widgets visible in current context (global + current session)
|
|
411
|
+
* @returns {import('./base-widget.js').BaseWidget[]}
|
|
412
|
+
*/
|
|
413
|
+
list() {
|
|
414
|
+
const result = Array.from(this.globalWidgets.values());
|
|
415
|
+
const sessionMap = this.sessionWidgets.get(this.currentSessionId);
|
|
416
|
+
if (sessionMap) {
|
|
417
|
+
result.push(...sessionMap.values());
|
|
418
|
+
}
|
|
419
|
+
return result;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
// ==================== Type Management ====================
|
|
423
|
+
|
|
424
|
+
/**
|
|
425
|
+
* Determine widget type based on user preference, device, and config
|
|
426
|
+
* @param {string} id
|
|
427
|
+
* @param {object} config
|
|
428
|
+
* @returns {string}
|
|
429
|
+
*/
|
|
430
|
+
getWidgetType(id, config) {
|
|
431
|
+
// 1. User override (highest priority)
|
|
432
|
+
const userOverride = this.userTypeOverrides[id];
|
|
433
|
+
if (userOverride) return userOverride;
|
|
434
|
+
|
|
435
|
+
// 2. Device-specific default
|
|
436
|
+
const deviceDefaults = DEVICE_DEFAULTS[id] || config.deviceTypes;
|
|
437
|
+
if (deviceDefaults) {
|
|
438
|
+
const device = DeviceManager.getDevice();
|
|
439
|
+
if (deviceDefaults[device]) {
|
|
440
|
+
return deviceDefaults[device];
|
|
441
|
+
}
|
|
442
|
+
if (deviceDefaults.default) {
|
|
443
|
+
return deviceDefaults.default;
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
// 3. Config default
|
|
448
|
+
return config.type || 'bottom-sheet';
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
/**
|
|
452
|
+
* Set widget type override (user preference)
|
|
453
|
+
* @param {string} id
|
|
454
|
+
* @param {string} type
|
|
455
|
+
*/
|
|
456
|
+
setWidgetType(id, type) {
|
|
457
|
+
this.userTypeOverrides[id] = type;
|
|
458
|
+
this.saveUserOverrides();
|
|
459
|
+
|
|
460
|
+
// Transform existing widget if it exists
|
|
461
|
+
const widget = this._resolve(id);
|
|
462
|
+
if (widget && widget.type !== type && widget.canTransformTo(type)) {
|
|
463
|
+
widget.transformTo(type);
|
|
464
|
+
}
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
/**
|
|
468
|
+
* Clear type override for a widget
|
|
469
|
+
* @param {string} id
|
|
470
|
+
*/
|
|
471
|
+
clearWidgetType(id) {
|
|
472
|
+
delete this.userTypeOverrides[id];
|
|
473
|
+
this.saveUserOverrides();
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
/**
|
|
477
|
+
* Load user type overrides from localStorage
|
|
478
|
+
*/
|
|
479
|
+
loadUserOverrides() {
|
|
480
|
+
try {
|
|
481
|
+
const data = localStorage.getItem('widget-type-overrides');
|
|
482
|
+
return data ? JSON.parse(data) : {};
|
|
483
|
+
} catch {
|
|
484
|
+
return {};
|
|
485
|
+
}
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/**
|
|
489
|
+
* Save user type overrides to localStorage
|
|
490
|
+
*/
|
|
491
|
+
saveUserOverrides() {
|
|
492
|
+
try {
|
|
493
|
+
localStorage.setItem('widget-type-overrides', JSON.stringify(this.userTypeOverrides));
|
|
494
|
+
} catch {
|
|
495
|
+
// Storage full or unavailable
|
|
496
|
+
}
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
// ==================== Session Switching ====================
|
|
500
|
+
|
|
501
|
+
/**
|
|
502
|
+
* Switch active session — hide old session's widgets, show new session's.
|
|
503
|
+
* No re-rendering, no reconnection. Just CSS visibility toggle.
|
|
504
|
+
* @param {string} newSessionId
|
|
505
|
+
* @param {string} newCwd
|
|
506
|
+
*/
|
|
507
|
+
switchSession(newSessionId, newCwd) {
|
|
508
|
+
const oldSessionId = this.currentSessionId;
|
|
509
|
+
|
|
510
|
+
// Update current references
|
|
511
|
+
this.currentSessionId = newSessionId;
|
|
512
|
+
this.currentCwd = newCwd;
|
|
513
|
+
|
|
514
|
+
// Hide old session's widget containers (respecting visibility scope)
|
|
515
|
+
if (oldSessionId && oldSessionId !== newSessionId) {
|
|
516
|
+
const oldMap = this.sessionWidgets.get(oldSessionId);
|
|
517
|
+
if (oldMap) {
|
|
518
|
+
oldMap.forEach(widget => {
|
|
519
|
+
const vScope = widget.getEffectiveVisibilityScope();
|
|
520
|
+
// 'all-sessions' and 'global' stay visible across all sessions
|
|
521
|
+
if (vScope === 'all-sessions' || vScope === 'global') return;
|
|
522
|
+
// 'project' stays visible if CWD matches the new session
|
|
523
|
+
if (vScope === 'project' && this._cwdMatch(widget._ownerCwd, newCwd)) return;
|
|
524
|
+
// 'session' (default) — hide
|
|
525
|
+
if (widget.container) widget.container.style.display = 'none';
|
|
526
|
+
if (widget._backdrop) widget._backdrop.style.display = 'none';
|
|
527
|
+
});
|
|
528
|
+
}
|
|
529
|
+
|
|
530
|
+
// Update project-scoped widgets from OTHER sessions:
|
|
531
|
+
// show if their CWD matches the new session, hide if not
|
|
532
|
+
this.sessionWidgets.forEach((map, sessionId) => {
|
|
533
|
+
if (sessionId === oldSessionId || sessionId === newSessionId) return;
|
|
534
|
+
map.forEach(widget => {
|
|
535
|
+
if (widget.getEffectiveVisibilityScope() !== 'project') return;
|
|
536
|
+
if (!widget.isVisible) return;
|
|
537
|
+
const show = this._cwdMatch(widget._ownerCwd, newCwd);
|
|
538
|
+
if (widget.container) widget.container.style.display = show ? '' : 'none';
|
|
539
|
+
if (widget._backdrop) widget._backdrop.style.display = show ? '' : 'none';
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
}
|
|
543
|
+
|
|
544
|
+
// Show new session's widget containers (only those that are logically open)
|
|
545
|
+
if (newSessionId) {
|
|
546
|
+
const newMap = this.sessionWidgets.get(newSessionId);
|
|
547
|
+
if (newMap) {
|
|
548
|
+
newMap.forEach(widget => {
|
|
549
|
+
if (widget.container) {
|
|
550
|
+
widget.container.style.display = '';
|
|
551
|
+
}
|
|
552
|
+
if (widget._backdrop) {
|
|
553
|
+
widget._backdrop.style.display = '';
|
|
554
|
+
}
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
|
|
559
|
+
// Hide/show global widgets tied to their opening session
|
|
560
|
+
// (e.g., file-preview opened in context of one session should hide on switch,
|
|
561
|
+
// then restore when switching back)
|
|
562
|
+
if (oldSessionId && oldSessionId !== newSessionId) {
|
|
563
|
+
this.globalWidgets.forEach(widget => {
|
|
564
|
+
if (!widget.config.closeOnSessionSwitch) return;
|
|
565
|
+
// Restore: widget was hidden when we previously left newSessionId
|
|
566
|
+
if (widget._visibleInSession === newSessionId) {
|
|
567
|
+
widget.container.style.display = '';
|
|
568
|
+
if (widget._backdrop) widget._backdrop.style.display = '';
|
|
569
|
+
delete widget._visibleInSession;
|
|
570
|
+
}
|
|
571
|
+
// Hide: widget is visible and not already hidden by a prior switch
|
|
572
|
+
else if (widget.isVisible && !widget._visibleInSession) {
|
|
573
|
+
widget._visibleInSession = oldSessionId;
|
|
574
|
+
widget.container.style.display = 'none';
|
|
575
|
+
if (widget._backdrop) widget._backdrop.style.display = 'none';
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
// Notify global widgets that care about session context
|
|
581
|
+
this.globalWidgets.forEach(widget => {
|
|
582
|
+
if (widget.config.sessionAware !== false && widget.config.onSessionChange) {
|
|
583
|
+
const oldCwd = widget.cwd;
|
|
584
|
+
widget.setSession(newSessionId);
|
|
585
|
+
widget.cwd = newCwd;
|
|
586
|
+
// If CWD changed within the same session, notify via onCwdChange
|
|
587
|
+
if (newCwd && newCwd !== oldCwd && oldSessionId === newSessionId && widget.config.onCwdChange) {
|
|
588
|
+
widget.config.onCwdChange(newCwd);
|
|
589
|
+
}
|
|
590
|
+
}
|
|
591
|
+
});
|
|
592
|
+
|
|
593
|
+
// Emit event for widgets that need to adjust after becoming visible
|
|
594
|
+
// (e.g., terminal needs to call fitAddon.fit())
|
|
595
|
+
if (newSessionId && oldSessionId !== newSessionId) {
|
|
596
|
+
requestAnimationFrame(() => {
|
|
597
|
+
WidgetBus.emit('session:widgets-shown', { sessionId: newSessionId, cwd: newCwd });
|
|
598
|
+
});
|
|
599
|
+
}
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
/**
|
|
603
|
+
* Hide/show the current session's widgets (containers + backdrops).
|
|
604
|
+
* Used when switching to/from widget tab mode — the floating widgets
|
|
605
|
+
* should disappear while a full-page tab (terminal, file preview) is active.
|
|
606
|
+
* @param {boolean} visible
|
|
607
|
+
*/
|
|
608
|
+
setSessionWidgetsVisible(visible) {
|
|
609
|
+
const sessionId = this.currentSessionId;
|
|
610
|
+
if (!sessionId) return;
|
|
611
|
+
const map = this.sessionWidgets.get(sessionId);
|
|
612
|
+
if (!map) return;
|
|
613
|
+
map.forEach(widget => {
|
|
614
|
+
// 'global' visibility scope stays visible even during terminal fullscreen
|
|
615
|
+
if (!visible && widget.getEffectiveVisibilityScope() === 'global') return;
|
|
616
|
+
if (widget.container) {
|
|
617
|
+
widget.container.style.display = visible ? '' : 'none';
|
|
618
|
+
}
|
|
619
|
+
if (widget._backdrop) {
|
|
620
|
+
widget._backdrop.style.display = visible ? '' : 'none';
|
|
621
|
+
}
|
|
622
|
+
});
|
|
623
|
+
// Also hide/show global widgets that act session-bound (e.g., file-preview)
|
|
624
|
+
this.globalWidgets.forEach(widget => {
|
|
625
|
+
if (!widget.config.closeOnSessionSwitch || !widget.isVisible) return;
|
|
626
|
+
if (!visible && widget.getEffectiveVisibilityScope() === 'global') return;
|
|
627
|
+
if (widget.container) {
|
|
628
|
+
widget.container.style.display = visible ? '' : 'none';
|
|
629
|
+
}
|
|
630
|
+
if (widget._backdrop) {
|
|
631
|
+
widget._backdrop.style.display = visible ? '' : 'none';
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* Destroy all session-scoped widgets for a given session.
|
|
638
|
+
* Called when a session tab is closed.
|
|
639
|
+
* @param {string} sessionId
|
|
640
|
+
*/
|
|
641
|
+
destroySessionWidgets(sessionId) {
|
|
642
|
+
const sessionMap = this.sessionWidgets.get(sessionId);
|
|
643
|
+
if (!sessionMap) return;
|
|
644
|
+
|
|
645
|
+
sessionMap.forEach((widget, id) => {
|
|
646
|
+
// Remove from z-index stack
|
|
647
|
+
const stackIndex = this.zIndexStack.indexOf(widget);
|
|
648
|
+
if (stackIndex > -1) {
|
|
649
|
+
this.zIndexStack.splice(stackIndex, 1);
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
// Call widget-specific cleanup callback
|
|
653
|
+
widget.config.onDestroy?.(sessionId);
|
|
654
|
+
|
|
655
|
+
// Destroy DOM and handlers
|
|
656
|
+
widget.destroy();
|
|
657
|
+
});
|
|
658
|
+
|
|
659
|
+
this.sessionWidgets.delete(sessionId);
|
|
660
|
+
|
|
661
|
+
// Clean up localStorage for this session
|
|
662
|
+
try {
|
|
663
|
+
localStorage.removeItem(`widget-open-set-${sessionId}`);
|
|
664
|
+
// Clean up per-widget state keys
|
|
665
|
+
this.configs.forEach((config, id) => {
|
|
666
|
+
if (config.scope === 'session') {
|
|
667
|
+
localStorage.removeItem(`widget-${id}-${sessionId}-state`);
|
|
668
|
+
}
|
|
669
|
+
});
|
|
670
|
+
} catch {
|
|
671
|
+
// Ignore storage errors
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
debug.log(`[WidgetManager] Destroyed widgets for session ${sessionId}`);
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// ==================== Open Widget Persistence ====================
|
|
678
|
+
|
|
679
|
+
/**
|
|
680
|
+
* Get list of currently open widget IDs (split by scope)
|
|
681
|
+
* @returns {{ global: string[], session: string[] }}
|
|
682
|
+
*/
|
|
683
|
+
getOpenWidgetIds() {
|
|
684
|
+
const global = [];
|
|
685
|
+
const session = [];
|
|
686
|
+
|
|
687
|
+
this.globalWidgets.forEach((widget, id) => {
|
|
688
|
+
if (widget.isVisible) global.push(id);
|
|
689
|
+
});
|
|
690
|
+
|
|
691
|
+
if (this.currentSessionId) {
|
|
692
|
+
const sessionMap = this.sessionWidgets.get(this.currentSessionId);
|
|
693
|
+
if (sessionMap) {
|
|
694
|
+
sessionMap.forEach((widget, id) => {
|
|
695
|
+
if (widget.isVisible) session.push(id);
|
|
696
|
+
});
|
|
697
|
+
}
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
return { global, session };
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
/**
|
|
704
|
+
* Save open widget sets to localStorage
|
|
705
|
+
*/
|
|
706
|
+
saveOpenWidgets() {
|
|
707
|
+
try {
|
|
708
|
+
const { global, session } = this.getOpenWidgetIds();
|
|
709
|
+
localStorage.setItem('widget-open-set-global', JSON.stringify(global));
|
|
710
|
+
if (this.currentSessionId) {
|
|
711
|
+
localStorage.setItem(`widget-open-set-${this.currentSessionId}`, JSON.stringify(session));
|
|
712
|
+
}
|
|
713
|
+
} catch {
|
|
714
|
+
// Storage full or unavailable
|
|
715
|
+
}
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/**
|
|
719
|
+
* Load open widget set from localStorage
|
|
720
|
+
* @param {'global'|string} scope - 'global' or a sessionId
|
|
721
|
+
* @returns {string[]}
|
|
722
|
+
*/
|
|
723
|
+
loadOpenWidgets(scope = 'global') {
|
|
724
|
+
try {
|
|
725
|
+
const key = scope === 'global' ? 'widget-open-set-global' : `widget-open-set-${scope}`;
|
|
726
|
+
const data = localStorage.getItem(key);
|
|
727
|
+
return data ? JSON.parse(data) : [];
|
|
728
|
+
} catch {
|
|
729
|
+
return [];
|
|
730
|
+
}
|
|
731
|
+
}
|
|
732
|
+
|
|
733
|
+
/**
|
|
734
|
+
* Restore previously open widgets after initialization.
|
|
735
|
+
* Call this after all widgets are registered.
|
|
736
|
+
*/
|
|
737
|
+
restoreOpenWidgets() {
|
|
738
|
+
// Migrate from old format if needed
|
|
739
|
+
this._migrateLocalStorage();
|
|
740
|
+
|
|
741
|
+
// Restore global widgets
|
|
742
|
+
const globalIds = this.loadOpenWidgets('global');
|
|
743
|
+
if (globalIds.length > 0) {
|
|
744
|
+
debug.log('[WidgetManager] Restoring global widgets:', globalIds);
|
|
745
|
+
this._restoreWidgetSet(globalIds);
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
// Restore current session's widgets
|
|
749
|
+
if (this.currentSessionId) {
|
|
750
|
+
const sessionIds = this.loadOpenWidgets(this.currentSessionId);
|
|
751
|
+
if (sessionIds.length > 0) {
|
|
752
|
+
debug.log('[WidgetManager] Restoring session widgets:', sessionIds);
|
|
753
|
+
this._restoreWidgetSet(sessionIds);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
|
|
758
|
+
/**
|
|
759
|
+
* Restore a set of widgets by ID
|
|
760
|
+
* @param {string[]} ids
|
|
761
|
+
*/
|
|
762
|
+
_restoreWidgetSet(ids) {
|
|
763
|
+
ids.forEach(id => {
|
|
764
|
+
if (this.configs.has(id)) {
|
|
765
|
+
const config = this.configs.get(id);
|
|
766
|
+
// Skip session widgets if no current session
|
|
767
|
+
if (config.scope === 'session' && !this.currentSessionId) return;
|
|
768
|
+
|
|
769
|
+
const widget = this.get(id);
|
|
770
|
+
if (widget) {
|
|
771
|
+
const persistedState = widget._persistedState?.state;
|
|
772
|
+
if (persistedState && persistedState !== 'collapsed' && persistedState !== 'hidden') {
|
|
773
|
+
widget.setState(persistedState);
|
|
774
|
+
} else {
|
|
775
|
+
widget.open();
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
}
|
|
779
|
+
});
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
/**
|
|
783
|
+
* Restore session widgets for a specific session (called on session switch when
|
|
784
|
+
* the session has no widgets yet but has persisted open-set data).
|
|
785
|
+
* @param {string} sessionId
|
|
786
|
+
*/
|
|
787
|
+
restoreSessionWidgets(sessionId) {
|
|
788
|
+
if (!sessionId) return;
|
|
789
|
+
|
|
790
|
+
const sessionMap = this.sessionWidgets.get(sessionId);
|
|
791
|
+
// Only restore if the session has no widgets yet (first visit)
|
|
792
|
+
if (sessionMap && sessionMap.size > 0) return;
|
|
793
|
+
|
|
794
|
+
const sessionIds = this.loadOpenWidgets(sessionId);
|
|
795
|
+
if (sessionIds.length > 0) {
|
|
796
|
+
debug.log(`[WidgetManager] Restoring session ${sessionId} widgets:`, sessionIds);
|
|
797
|
+
this._restoreWidgetSet(sessionIds);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
/**
|
|
802
|
+
* One-time migration from old localStorage format
|
|
803
|
+
*/
|
|
804
|
+
_migrateLocalStorage() {
|
|
805
|
+
try {
|
|
806
|
+
if (localStorage.getItem('widget-scope-v2')) return;
|
|
807
|
+
|
|
808
|
+
// Migrate old widget-open-set to global
|
|
809
|
+
const oldOpenSet = localStorage.getItem('widget-open-set');
|
|
810
|
+
if (oldOpenSet) {
|
|
811
|
+
const ids = JSON.parse(oldOpenSet);
|
|
812
|
+
const globalIds = [];
|
|
813
|
+
const sessionIds = [];
|
|
814
|
+
|
|
815
|
+
ids.forEach(id => {
|
|
816
|
+
const config = this.configs.get(id);
|
|
817
|
+
if (config?.scope === 'global') {
|
|
818
|
+
globalIds.push(id);
|
|
819
|
+
} else {
|
|
820
|
+
sessionIds.push(id);
|
|
821
|
+
}
|
|
822
|
+
});
|
|
823
|
+
|
|
824
|
+
localStorage.setItem('widget-open-set-global', JSON.stringify(globalIds));
|
|
825
|
+
|
|
826
|
+
// Apply session widgets to current session (if any)
|
|
827
|
+
if (this.currentSessionId && sessionIds.length > 0) {
|
|
828
|
+
localStorage.setItem(`widget-open-set-${this.currentSessionId}`, JSON.stringify(sessionIds));
|
|
829
|
+
}
|
|
830
|
+
|
|
831
|
+
localStorage.removeItem('widget-open-set');
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
localStorage.setItem('widget-scope-v2', '1');
|
|
835
|
+
} catch {
|
|
836
|
+
// Ignore migration errors
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
// ==================== Device Change ====================
|
|
841
|
+
|
|
842
|
+
/**
|
|
843
|
+
* Handle device type change
|
|
844
|
+
*/
|
|
845
|
+
onDeviceChange(newDevice, oldDevice) {
|
|
846
|
+
// Transform all widgets to device-appropriate types (unless user override)
|
|
847
|
+
this._forEachWidget((widget) => {
|
|
848
|
+
const id = widget.id;
|
|
849
|
+
if (this.userTypeOverrides[id]) return;
|
|
850
|
+
|
|
851
|
+
const config = this.configs.get(id);
|
|
852
|
+
const newType = this.getWidgetType(id, config);
|
|
853
|
+
|
|
854
|
+
if (widget.type !== newType && widget.canTransformTo(newType)) {
|
|
855
|
+
widget.transformTo(newType);
|
|
856
|
+
}
|
|
857
|
+
});
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
// ==================== Z-Index Management ====================
|
|
861
|
+
|
|
862
|
+
/**
|
|
863
|
+
* Bring a widget to front (z-index)
|
|
864
|
+
*/
|
|
865
|
+
bringToFront(widget) {
|
|
866
|
+
const index = this.zIndexStack.indexOf(widget);
|
|
867
|
+
if (index > -1) {
|
|
868
|
+
this.zIndexStack.splice(index, 1);
|
|
869
|
+
}
|
|
870
|
+
this.zIndexStack.push(widget);
|
|
871
|
+
this.updateZIndices();
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
/**
|
|
875
|
+
* Update z-indices for all widgets in stack
|
|
876
|
+
*/
|
|
877
|
+
updateZIndices() {
|
|
878
|
+
this.zIndexStack.forEach((widget, i) => {
|
|
879
|
+
if (widget.container) {
|
|
880
|
+
// Skip modal widgets - they use fixed CSS z-index (above backdrop)
|
|
881
|
+
if (widget.type === 'modal') return;
|
|
882
|
+
widget.container.style.zIndex = String(this.baseZIndex + i * 10);
|
|
883
|
+
}
|
|
884
|
+
});
|
|
885
|
+
}
|
|
886
|
+
|
|
887
|
+
// ==================== Widget Operations ====================
|
|
888
|
+
|
|
889
|
+
/**
|
|
890
|
+
* Close all widgets (global + current session)
|
|
891
|
+
*/
|
|
892
|
+
closeAll() {
|
|
893
|
+
this.globalWidgets.forEach(widget => widget.close());
|
|
894
|
+
const sessionMap = this.sessionWidgets.get(this.currentSessionId);
|
|
895
|
+
if (sessionMap) sessionMap.forEach(widget => widget.close());
|
|
896
|
+
}
|
|
897
|
+
|
|
898
|
+
/**
|
|
899
|
+
* Destroy a widget by ID
|
|
900
|
+
* @param {string} id
|
|
901
|
+
*/
|
|
902
|
+
destroy(id) {
|
|
903
|
+
const widget = this._resolve(id);
|
|
904
|
+
if (widget) {
|
|
905
|
+
widget.destroy();
|
|
906
|
+
this._remove(id);
|
|
907
|
+
|
|
908
|
+
const stackIndex = this.zIndexStack.indexOf(widget);
|
|
909
|
+
if (stackIndex > -1) {
|
|
910
|
+
this.zIndexStack.splice(stackIndex, 1);
|
|
911
|
+
}
|
|
912
|
+
}
|
|
913
|
+
}
|
|
914
|
+
|
|
915
|
+
/**
|
|
916
|
+
* Destroy all widgets
|
|
917
|
+
*/
|
|
918
|
+
destroyAll() {
|
|
919
|
+
this._forEachWidget(widget => widget.destroy());
|
|
920
|
+
this.globalWidgets.clear();
|
|
921
|
+
this.sessionWidgets.clear();
|
|
922
|
+
this.zIndexStack = [];
|
|
923
|
+
}
|
|
924
|
+
|
|
925
|
+
/**
|
|
926
|
+
* Toggle a widget (open if closed, close if open)
|
|
927
|
+
* @param {string} id
|
|
928
|
+
*/
|
|
929
|
+
toggle(id) {
|
|
930
|
+
const widget = this.get(id);
|
|
931
|
+
if (widget) {
|
|
932
|
+
widget.toggle();
|
|
933
|
+
if (widget.isVisible) {
|
|
934
|
+
this.bringToFront(widget);
|
|
935
|
+
}
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
|
|
939
|
+
/**
|
|
940
|
+
* Open a widget
|
|
941
|
+
* @param {string} id
|
|
942
|
+
* @param {object} context - Optional context to pass to render()
|
|
943
|
+
*/
|
|
944
|
+
open(id, context) {
|
|
945
|
+
// NOTE: No console.log here - causes infinite loop with debug-logs widget!
|
|
946
|
+
const widget = this.get(id);
|
|
947
|
+
if (widget) {
|
|
948
|
+
// Store context for render
|
|
949
|
+
if (context) {
|
|
950
|
+
widget._openContext = context;
|
|
951
|
+
}
|
|
952
|
+
widget.open();
|
|
953
|
+
// Re-render when context is provided (context is consumed by render)
|
|
954
|
+
if (context) {
|
|
955
|
+
widget.render();
|
|
956
|
+
}
|
|
957
|
+
this.bringToFront(widget);
|
|
958
|
+
}
|
|
959
|
+
}
|
|
960
|
+
|
|
961
|
+
/**
|
|
962
|
+
* Close a widget
|
|
963
|
+
* @param {string} id
|
|
964
|
+
*/
|
|
965
|
+
close(id) {
|
|
966
|
+
// Don't use this.get() here - don't create widget just to close it
|
|
967
|
+
const widget = this._resolve(id);
|
|
968
|
+
if (widget) {
|
|
969
|
+
widget.close();
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
|
|
973
|
+
/**
|
|
974
|
+
* Update/re-render a widget's content
|
|
975
|
+
* @param {string} id
|
|
976
|
+
*/
|
|
977
|
+
update(id) {
|
|
978
|
+
// NOTE: No console.log here - causes infinite loop with debug-logs widget!
|
|
979
|
+
const widget = this.get(id); // Use this.get() to auto-create if needed
|
|
980
|
+
if (widget) {
|
|
981
|
+
widget.render();
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
|
|
985
|
+
/**
|
|
986
|
+
* Check if a widget is currently open
|
|
987
|
+
* @param {string} id
|
|
988
|
+
* @returns {boolean}
|
|
989
|
+
*/
|
|
990
|
+
isOpen(id) {
|
|
991
|
+
const widget = this._resolve(id);
|
|
992
|
+
return widget ? widget.isVisible : false;
|
|
993
|
+
}
|
|
994
|
+
|
|
995
|
+
/**
|
|
996
|
+
* Check if a widget is not just logically open but actually on screen.
|
|
997
|
+
*
|
|
998
|
+
* switchSession() hides a session's widgets with an inline display:none
|
|
999
|
+
* while leaving isVisible true, so isOpen() alone reports "open" for a
|
|
1000
|
+
* widget the user cannot see. Same display test getVisibleWidgets() uses.
|
|
1001
|
+
* This is the right primitive for UI that mirrors widget state (rail
|
|
1002
|
+
* highlighting, toggles) — isOpen() stays the logical-state question.
|
|
1003
|
+
* @param {string} id
|
|
1004
|
+
* @returns {boolean}
|
|
1005
|
+
*/
|
|
1006
|
+
isShowing(id) {
|
|
1007
|
+
const widget = this._resolve(id);
|
|
1008
|
+
return !!(widget && widget.isVisible && widget.container &&
|
|
1009
|
+
widget.container.style.display !== 'none');
|
|
1010
|
+
}
|
|
1011
|
+
|
|
1012
|
+
/**
|
|
1013
|
+
* Get all visible widgets sorted by z-index (topmost first)
|
|
1014
|
+
* Only returns widgets whose containers are actually displayed (not session-hidden)
|
|
1015
|
+
* @returns {import('./base-widget.js').BaseWidget[]}
|
|
1016
|
+
*/
|
|
1017
|
+
getVisibleWidgets() {
|
|
1018
|
+
return this.zIndexStack.filter(w =>
|
|
1019
|
+
w.isVisible && w.container && w.container.style.display !== 'none'
|
|
1020
|
+
).reverse();
|
|
1021
|
+
}
|
|
1022
|
+
|
|
1023
|
+
/**
|
|
1024
|
+
* Close the topmost visible widget
|
|
1025
|
+
* Used for ESC key handling - close widgets before stopping Claude
|
|
1026
|
+
* @param {Object} options
|
|
1027
|
+
* @param {boolean} options.allowTerminalPassthrough - If true (default), don't close if
|
|
1028
|
+
* user is focused in terminal (for ESC to pass through to vim/nano).
|
|
1029
|
+
* Set to false for Ctrl+W which should always close the terminal.
|
|
1030
|
+
* @returns {boolean} True if a widget was closed, false if none were open
|
|
1031
|
+
*/
|
|
1032
|
+
closeTopmost(options = {}) {
|
|
1033
|
+
const { allowTerminalPassthrough = true } = options;
|
|
1034
|
+
const visible = this.getVisibleWidgets();
|
|
1035
|
+
if (visible.length === 0) return false;
|
|
1036
|
+
|
|
1037
|
+
const topmost = visible[0];
|
|
1038
|
+
const activeEl = document.activeElement;
|
|
1039
|
+
|
|
1040
|
+
// Don't close if user is focused inside a terminal within this widget
|
|
1041
|
+
// Terminal needs ESC for vim, nano, escape sequences, etc.
|
|
1042
|
+
// But Ctrl+W should always close (allowTerminalPassthrough: false)
|
|
1043
|
+
if (allowTerminalPassthrough && activeEl && topmost.container?.contains(activeEl)) {
|
|
1044
|
+
const inTerminal = activeEl.closest('.xterm') ||
|
|
1045
|
+
activeEl.closest('.terminal-widget-xterm');
|
|
1046
|
+
if (inTerminal) {
|
|
1047
|
+
return false; // Let ESC pass through to terminal
|
|
1048
|
+
}
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
const closed = topmost.close();
|
|
1052
|
+
return closed !== false; // beforeClose can prevent close
|
|
1053
|
+
}
|
|
1054
|
+
|
|
1055
|
+
/**
|
|
1056
|
+
* Check if any widget is currently visible (and not session-hidden)
|
|
1057
|
+
* @returns {boolean}
|
|
1058
|
+
*/
|
|
1059
|
+
hasVisibleWidgets() {
|
|
1060
|
+
return this.zIndexStack.some(w =>
|
|
1061
|
+
w.isVisible && w.container && w.container.style.display !== 'none'
|
|
1062
|
+
);
|
|
1063
|
+
}
|
|
1064
|
+
|
|
1065
|
+
// ==================== Transform ====================
|
|
1066
|
+
|
|
1067
|
+
/**
|
|
1068
|
+
* Transform a widget to a different type
|
|
1069
|
+
* This properly destroys the old widget and creates a new one with the correct class
|
|
1070
|
+
* @param {string} id - Widget ID
|
|
1071
|
+
* @param {string} newType - New widget type
|
|
1072
|
+
* @param {Object} options - Additional options
|
|
1073
|
+
* @returns {import('./base-widget.js').BaseWidget} The new widget
|
|
1074
|
+
*/
|
|
1075
|
+
transform(id, newType, options = {}) {
|
|
1076
|
+
const oldWidget = this._resolve(id);
|
|
1077
|
+
if (!oldWidget) {
|
|
1078
|
+
console.warn(`[WidgetManager] Cannot transform: widget ${id} not found`);
|
|
1079
|
+
return null;
|
|
1080
|
+
}
|
|
1081
|
+
|
|
1082
|
+
const config = this.configs.get(id);
|
|
1083
|
+
if (!config) {
|
|
1084
|
+
console.warn(`[WidgetManager] Cannot transform: config for ${id} not found`);
|
|
1085
|
+
return null;
|
|
1086
|
+
}
|
|
1087
|
+
|
|
1088
|
+
const oldType = oldWidget.type;
|
|
1089
|
+
|
|
1090
|
+
// 1. Capture state from old widget
|
|
1091
|
+
const snapshot = {
|
|
1092
|
+
sessionId: oldWidget.sessionId,
|
|
1093
|
+
cwd: oldWidget.cwd,
|
|
1094
|
+
ownerSessionId: oldWidget._ownerSessionId,
|
|
1095
|
+
scrollTop: oldWidget.contentContainer?.scrollTop || 0,
|
|
1096
|
+
wasVisible: oldWidget.isVisible,
|
|
1097
|
+
previousState: oldWidget.state,
|
|
1098
|
+
previousType: oldType,
|
|
1099
|
+
previousPosition: oldWidget.getPosition?.() || null,
|
|
1100
|
+
previousDimensions: oldWidget.getDimensions?.() || null
|
|
1101
|
+
};
|
|
1102
|
+
|
|
1103
|
+
// 2. Remove old widget from z-index stack
|
|
1104
|
+
const stackIndex = this.zIndexStack.indexOf(oldWidget);
|
|
1105
|
+
if (stackIndex > -1) {
|
|
1106
|
+
this.zIndexStack.splice(stackIndex, 1);
|
|
1107
|
+
}
|
|
1108
|
+
|
|
1109
|
+
// 3. Destroy old widget (removes from DOM)
|
|
1110
|
+
oldWidget.destroy();
|
|
1111
|
+
this._remove(id);
|
|
1112
|
+
|
|
1113
|
+
// 4. Create new widget with the new type
|
|
1114
|
+
const finalConfig = {
|
|
1115
|
+
...config,
|
|
1116
|
+
...options,
|
|
1117
|
+
type: newType,
|
|
1118
|
+
_transformSnapshot: snapshot,
|
|
1119
|
+
_previousType: oldType
|
|
1120
|
+
};
|
|
1121
|
+
|
|
1122
|
+
const WidgetClass = getWidgetClass(newType);
|
|
1123
|
+
const newWidget = new WidgetClass(id, finalConfig);
|
|
1124
|
+
|
|
1125
|
+
// Preserve session ownership across transform
|
|
1126
|
+
if (snapshot.ownerSessionId) {
|
|
1127
|
+
newWidget._ownerSessionId = snapshot.ownerSessionId;
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1130
|
+
// Store in correct map
|
|
1131
|
+
this._store(id, newWidget);
|
|
1132
|
+
|
|
1133
|
+
// Initialize (creates container and base DOM)
|
|
1134
|
+
newWidget.init();
|
|
1135
|
+
|
|
1136
|
+
// 5. Restore session and cwd
|
|
1137
|
+
if (snapshot.sessionId) {
|
|
1138
|
+
newWidget.sessionId = snapshot.sessionId;
|
|
1139
|
+
newWidget.cwd = snapshot.cwd;
|
|
1140
|
+
}
|
|
1141
|
+
|
|
1142
|
+
// 6. Store previous type for popBack
|
|
1143
|
+
newWidget._previousType = oldType;
|
|
1144
|
+
newWidget._previousPosition = snapshot.previousPosition;
|
|
1145
|
+
newWidget._previousDimensions = snapshot.previousDimensions;
|
|
1146
|
+
|
|
1147
|
+
// 7. Add to z-index stack and bring to front
|
|
1148
|
+
this.zIndexStack.push(newWidget);
|
|
1149
|
+
this.updateZIndices();
|
|
1150
|
+
|
|
1151
|
+
// 8. Restore visibility state (only open if was previously visible)
|
|
1152
|
+
if (snapshot.wasVisible) {
|
|
1153
|
+
if (newType === 'tab') {
|
|
1154
|
+
newWidget.open();
|
|
1155
|
+
} else {
|
|
1156
|
+
newWidget.setState('visible');
|
|
1157
|
+
}
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// 9. Re-render content
|
|
1161
|
+
newWidget.render();
|
|
1162
|
+
|
|
1163
|
+
// 10. Restore scroll position after render
|
|
1164
|
+
if (newWidget.contentContainer && snapshot.scrollTop) {
|
|
1165
|
+
requestAnimationFrame(() => {
|
|
1166
|
+
newWidget.contentContainer.scrollTop = snapshot.scrollTop;
|
|
1167
|
+
});
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
// 11. Emit transform event
|
|
1171
|
+
WidgetBus.emit('widget:transformed', {
|
|
1172
|
+
widgetId: id,
|
|
1173
|
+
from: oldType,
|
|
1174
|
+
to: newType
|
|
1175
|
+
});
|
|
1176
|
+
|
|
1177
|
+
debug.log(`[WidgetManager] Transformed ${id}: ${oldType} → ${newType}`);
|
|
1178
|
+
|
|
1179
|
+
return newWidget;
|
|
1180
|
+
}
|
|
1181
|
+
}
|
|
1182
|
+
|
|
1183
|
+
// Global singleton
|
|
1184
|
+
export const WidgetManager = new WidgetManagerClass();
|
|
1185
|
+
|
|
1186
|
+
// Also export class for testing
|
|
1187
|
+
export { WidgetManagerClass };
|