tabby-paneworks 1.0.1 → 1.1.3
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.
- package/README.md +49 -27
- package/index.d.ts +1 -1
- package/index.d.ts.map +1 -1
- package/index.js +1 -1
- package/index.js.LICENSE.txt +3 -3
- package/index.js.map +1 -1
- package/models/workspace.model.d.ts +23 -2
- package/models/workspace.model.d.ts.map +1 -1
- package/package.json +1 -1
- package/providers/config.provider.d.ts +6 -0
- package/providers/config.provider.d.ts.map +1 -1
- package/providers/hotkey.provider.d.ts +8 -0
- package/providers/hotkey.provider.d.ts.map +1 -0
- package/providers/toolbar.provider.d.ts +3 -3
- package/providers/toolbar.provider.d.ts.map +1 -1
- package/services/layout.service.d.ts +42 -3
- package/services/layout.service.d.ts.map +1 -1
- package/services/workspaceEditor.service.d.ts +56 -4
- package/services/workspaceEditor.service.d.ts.map +1 -1
package/README.md
CHANGED
|
@@ -8,14 +8,21 @@ Made for running several long-lived sessions side by side (coding agents, dev se
|
|
|
8
8
|
|
|
9
9
|
## Features
|
|
10
10
|
|
|
11
|
-
- **
|
|
11
|
+
- **Views.** A workspace can have several views (for example "Agents", "Servers", "Everything"). Each view has its own set of switched-on panes. Pick a view in the sidebar to see its panes in a grid.
|
|
12
|
+
- **Automatic grid.** A view shows every pane switched on in it. You set a minimum pane size; Paneworks fits as many panes as that allows, in as many rows as give each pane the most room, and rearranges when the window changes size.
|
|
12
13
|
- **Focus view.** Click a pane in the sidebar to see it alone, full size. Click it again to go back.
|
|
13
14
|
- **Every pane runs.** All panes start with the workspace, switched off or not. Hiding a pane never stops it; it comes back exactly as it was.
|
|
14
|
-
- **On/off switches and drag-and-drop order**, saved in the workspace.
|
|
15
|
+
- **On/off switches per view and drag-and-drop order**, saved in the workspace. All views share the same pane order.
|
|
15
16
|
- **Live titles.** Each pane's label shows the title its program sets (for example a coding agent's session title), optionally prefixed with a pane name. The tab itself always shows the workspace name.
|
|
16
17
|
- **Label colours** per pane, so you recognise panes at a glance.
|
|
18
|
+
- **Open in VS Code** from the sidebar header: opens the workspace's project folder (set in the workspace menu; by default the first pane folder). WSL folders open in VS Code's WSL mode.
|
|
19
|
+
- **Copy the project folder path** from the sidebar header.
|
|
20
|
+
- **Edit a workspace's settings in VS Code** as a JSON file (workspace menu). Every save is checked and applied right away. **Copy settings file path** (same menu) copies the file's path, for editing it with any editor.
|
|
21
|
+
- **Duplicate a pane** from its editor: same settings, switched on in the same views.
|
|
22
|
+
- **Tab colour** per workspace, applied to the workspace tab every time it opens, also after a Tabby restart.
|
|
17
23
|
- **NEW marker** on hidden panes that printed something since you last looked.
|
|
18
24
|
- **Startup commands** that wait for the shell to be ready.
|
|
25
|
+
- **F1 opens the Paneworks menu** (open or create a workspace) from anywhere in Tabby. Rebind it under **Settings → Hotkeys → Paneworks: open menu**.
|
|
19
26
|
- **Everything in the sidebar**: add, edit, restart and remove panes; rename, configure, create, switch and delete workspaces. No settings page.
|
|
20
27
|
|
|
21
28
|

|
|
@@ -26,27 +33,31 @@ In Tabby: **Settings → Plugins**, search **paneworks**, **Install**, restart T
|
|
|
26
33
|
|
|
27
34
|
## Getting started
|
|
28
35
|
|
|
29
|
-
1. Click the **Paneworks** button (grid icon) in Tabby's toolbar and choose **New workspace**.
|
|
30
|
-
2.
|
|
31
|
-
3.
|
|
32
|
-
4. Click the workspace name at the top of the sidebar to rename it, set the minimum pane size or let it open when Tabby starts.
|
|
36
|
+
1. Click the **Paneworks** button (grid icon) in Tabby's toolbar, or press **F1**, and choose **New workspace**. Pick a profile, a folder and a startup command (optional). Paneworks creates 4 panes with them (you can change the number). The workspace is named after the folder, which also becomes its project folder. It opens with the sidebar on the left.
|
|
37
|
+
2. Change single panes with **⋯** (name, label colour, command, folder, profile), add more with **+** next to "Panes", or copy one with **Duplicate** in its editor.
|
|
38
|
+
3. Under **Views**, click a view to see its switched-on panes in a grid. Click **+** next to "Views" to add another view, select it, and use the pane switches to choose what it shows.
|
|
39
|
+
4. Click the workspace name at the top of the sidebar to rename it, pick a tab colour, set the project folder, set the minimum pane size or let it open when Tabby starts.
|
|
33
40
|
|
|
34
|
-
Next time, open the workspace from the toolbar button. If it is already open,
|
|
41
|
+
Next time, open the workspace from the toolbar button or F1. If it is already open, this brings its tab to the front.
|
|
35
42
|
|
|
36
|
-
When a workspace opens, you briefly see all of its panes: Tabby starts a terminal only once it has been on screen. As soon as every pane runs, Paneworks switches to
|
|
43
|
+
When a workspace opens, you briefly see all of its panes: Tabby starts a terminal only once it has been on screen. As soon as every pane runs, Paneworks switches to the selected view.
|
|
37
44
|
|
|
38
45
|
## The sidebar
|
|
39
46
|
|
|
40
47
|
| Element | What it does |
|
|
41
48
|
|---|---|
|
|
42
|
-
| Workspace name (top) | Workspace menu: rename, minimum pane size, open when Tabby starts, switch to or open another workspace, new workspace, delete this one |
|
|
49
|
+
| Workspace name (top) | Workspace menu: rename, tab colour, project folder, minimum pane size, open when Tabby starts, switch to or open another workspace, new workspace, delete this one |
|
|
50
|
+
| Copy icon | Copy the project folder path to the clipboard (the settings file path is in the workspace menu) |
|
|
51
|
+
| `</>` | Open the project folder in VS Code (needs the `code` command, which VS Code's installer puts on PATH) |
|
|
43
52
|
| « / » | Collapse or expand the sidebar |
|
|
44
|
-
| **
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
53
|
+
| **Views** **+** | Add a view, with all panes switched on |
|
|
54
|
+
| View row | Select the view and show its switched-on panes in a grid. Shows how many are on screen out of how many are on |
|
|
55
|
+
| ⋯ on a view | Rename, duplicate (same switches) or delete the view |
|
|
56
|
+
| **Panes** **+** | Add a pane (opens its editor). A new pane is switched on in the selected view only |
|
|
57
|
+
| Pane title | Focus view: this pane alone. Click again to go back to the selected view |
|
|
58
|
+
| Switch | Belongs to the selected view. On: shown in that view. Off: hidden there, still running, reachable through its title |
|
|
48
59
|
| ⋮⋮ (drag the row) | Sort the panes; the order is the grid order |
|
|
49
|
-
| ⋯ | Edit the pane: name, label colour, startup command, folder, profile. **Restart** applies a changed command, folder or profile; **Remove** deletes the pane |
|
|
60
|
+
| ⋯ | Edit the pane: name, label colour, startup command, folder, profile. **Restart** applies a changed command, folder or profile; **Duplicate** adds a copy right below it (started at once); **Remove** deletes the pane |
|
|
50
61
|
|
|
51
62
|

|
|
52
63
|
|
|
@@ -56,7 +67,7 @@ When a workspace opens, you briefly see all of its panes: Tabby starts a termina
|
|
|
56
67
|
|---|---|
|
|
57
68
|
| Accent bar on the left, full brightness | On screen |
|
|
58
69
|
| Dimmed | Running, not on screen |
|
|
59
|
-
| Dimmer, switch off | Switched off (running, not
|
|
70
|
+
| Dimmer, switch off | Switched off in the selected view (running, not shown) |
|
|
60
71
|
| Highlighted row | Shown alone (focus view) |
|
|
61
72
|
| **NEW** label | New output since the pane left the screen |
|
|
62
73
|
| "no room" under the title | Switched on, but doesn't fit at the minimum pane size |
|
|
@@ -68,7 +79,7 @@ Hover over a row for the same information as a tooltip. On screen, every pane ha
|
|
|
68
79
|
|
|
69
80
|
## How the grid is chosen
|
|
70
81
|
|
|
71
|
-
With a minimum pane size of W × H, the pane area fits `floor(width / W)` columns and `floor(height / H)` rows. Paneworks shows as many switched-on panes as fit, in their sidebar order, and among the arrangements that fit picks the one with the largest panes; rows are filled evenly, fuller rows first.
|
|
82
|
+
With a minimum pane size of W × H, the pane area fits `floor(width / W)` columns and `floor(height / H)` rows. Paneworks shows as many of the view's switched-on panes as fit, in their sidebar order, and among the arrangements that fit picks the one with the largest panes; rows are filled evenly, fuller rows first.
|
|
72
83
|
|
|
73
84
|
Examples for 600 × 260 px in a 1900 × 1000 px area: 3 panes → 2 + 1, 4 → 2 + 2, 5 → 2 + 2 + 1, 8 → 3 + 3 + 2. In 1200 × 700 px only 2 × 2 fit, so of 8 switched-on panes the first 4 are shown and the others are marked "no room" (they keep running).
|
|
74
85
|
|
|
@@ -85,17 +96,31 @@ set -g set-titles-string "#{pane_title}"
|
|
|
85
96
|
|
|
86
97
|
## Configuration file
|
|
87
98
|
|
|
88
|
-
Workspaces are stored in Tabby's `config.yaml` under `paneworks.workspaces`.
|
|
99
|
+
Workspaces are stored in Tabby's `config.yaml` under `paneworks.workspaces`.
|
|
100
|
+
|
|
101
|
+
To edit one by hand while Tabby runs, use **Edit settings in VS Code** in the workspace menu, not `config.yaml`: Tabby keeps `config.yaml` in memory and overwrites it on its next save. The menu item writes the workspace to its own JSON file (in a `paneworks` folder next to `config.yaml`) and opens it in VS Code. Each save is checked and applied to the open tab: renamed views, changed switches, panes added or removed. A file that isn't valid is not applied, and a notification says why. Panes and views without an `id` get one. Changes you make in the sidebar are written back to the file. Panes whose command, folder or profile changed are restarted. While the file has an error, the sidebar stops writing to it, so your edits stay until you fix them.
|
|
102
|
+
|
|
103
|
+
The format in `config.yaml` is plain YAML:
|
|
89
104
|
|
|
90
105
|
```yaml
|
|
91
106
|
paneworks:
|
|
92
107
|
workspaces:
|
|
93
108
|
- id: 0b7c… # any unique id
|
|
94
109
|
name: My project
|
|
110
|
+
color: '#10b981' # optional tab colour
|
|
111
|
+
folder: C:\code\my-project # optional, for Open in VS Code (default: first pane folder)
|
|
95
112
|
minPaneWidth: 600 # optional, px (default 600)
|
|
96
113
|
minPaneHeight: 260 # optional, px (default 260)
|
|
97
114
|
launchOnStartup: false
|
|
98
|
-
|
|
115
|
+
activeViewId: 3c4d… # the selected view (default: the first)
|
|
116
|
+
views:
|
|
117
|
+
- id: 3c4d… # any unique id
|
|
118
|
+
name: Default
|
|
119
|
+
hidden: [9a2d…] # pane ids switched off in this view
|
|
120
|
+
- id: 7e8f…
|
|
121
|
+
name: Tests
|
|
122
|
+
hidden: [5f1e…]
|
|
123
|
+
panes: # sidebar and grid order, shared by all views
|
|
99
124
|
- id: 5f1e… # any unique id
|
|
100
125
|
name: api # optional
|
|
101
126
|
color: '#3b82f6' # optional label colour
|
|
@@ -106,14 +131,14 @@ paneworks:
|
|
|
106
131
|
profileId: local:powershell
|
|
107
132
|
cwd: C:\code\my-project
|
|
108
133
|
startupCommand: npm test -- --watch
|
|
109
|
-
hidden: true # switched off
|
|
110
134
|
```
|
|
111
135
|
|
|
112
136
|
## Notes and limits
|
|
113
137
|
|
|
114
138
|
- Panes live as long as the workspace tab. Closing the tab closes all of its panes, hidden ones included. After a Tabby restart, the workspace tab comes back through Tabby's tab recovery and starts its panes again.
|
|
115
|
-
- If a pane's program exits, the pane closes;
|
|
139
|
+
- If a pane's program exits, the pane closes; a view or its title starts it again.
|
|
116
140
|
- Paneworks rearranges panes through Tabby's split-tab internals (the same mechanism as Tabby's own pane drag and drop). Developed and tested with Tabby 1.0.231 on Windows. A major Tabby update could need a Paneworks update.
|
|
141
|
+
- Tabby catches F1 before the terminal does, so programs that use F1 themselves (htop, mc) won't see it. Rebind the hotkey if you need F1 there.
|
|
117
142
|
- Paneworks keeps its data under its own config key and profile ids, so it does not interfere with other workspace plugins.
|
|
118
143
|
|
|
119
144
|
## Develop
|
|
@@ -125,7 +150,7 @@ npm run build
|
|
|
125
150
|
|
|
126
151
|
`.npmrc` sets `legacy-peer-deps`, so npm doesn't pull Tabby's own packages. The build writes `dist/`: the published package (plugin code, its `package.json`, README, LICENSE).
|
|
127
152
|
|
|
128
|
-
To try a local build in Tabby,
|
|
153
|
+
To try a local build in Tabby, install it once in place of the published version:
|
|
129
154
|
|
|
130
155
|
```
|
|
131
156
|
cd %APPDATA%\tabby\plugins
|
|
@@ -133,16 +158,13 @@ npm uninstall tabby-paneworks
|
|
|
133
158
|
npm install --legacy-peer-deps <path to this repo>\dist
|
|
134
159
|
```
|
|
135
160
|
|
|
161
|
+
After that, every `npm run build` (and `npm run build:dev` for the DEV variant) copies the build into the local Tabby (from Windows or WSL), including the folder a `file:` install points to, so a reinstall from Tabby's plugin manager can't bring back an older build. Restart Tabby to load it. CI builds skip this.
|
|
162
|
+
|
|
136
163
|
Back to the published version: `npm uninstall tabby-paneworks`, then install it from Tabby's plugin manager. Console messages are prefixed `[Paneworks]` (Ctrl+Shift+I in Tabby).
|
|
137
164
|
|
|
138
165
|
## Release
|
|
139
166
|
|
|
140
|
-
|
|
141
|
-
npm version patch # or minor / major: bumps package.json, commits, tags vX.Y.Z
|
|
142
|
-
git push --follow-tags
|
|
143
|
-
```
|
|
144
|
-
|
|
145
|
-
The tag runs `.github/workflows/release.yml`: build, publish to npm with trusted publishing (no token), GitHub release with generated notes.
|
|
167
|
+
Every push to `main` runs `.github/workflows/release.yml`: build, publish to npm with trusted publishing (no token) and provenance, tag the commit `vX.Y.Z`. The version is `<major>.<minor>` from `package.json` plus the workflow run number, e.g. `1.0.17`. For a new minor or major version, change `package.json` by hand (e.g. to `1.1.0`).
|
|
146
168
|
|
|
147
169
|
## License
|
|
148
170
|
|
package/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { WorkspaceEditorService } from './services/workspaceEditor.service';
|
|
2
2
|
/**
|
|
3
|
-
* Paneworks: no settings page. The toolbar button opens and creates workspaces;
|
|
3
|
+
* Paneworks: no settings page. The toolbar button (or F1) opens and creates workspaces;
|
|
4
4
|
* everything else is managed in the sidebar of a workspace tab (LayoutService).
|
|
5
5
|
*/
|
|
6
6
|
export default class PaneworksModule {
|
package/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,sBAAsB,EAAE,MAAM,oCAAoC,CAAA;AAI3E;;;GAGG;AAYH,MAAM,CAAC,OAAO,OAAO,eAAe;CAAG;AAEvC,OAAO,EAAE,sBAAsB,EAAE,CAAA"}
|
package/index.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/*! For license information please see index.js.LICENSE.txt */
|
|
2
|
-
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@angular/common"),require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("tabby-core"),require("tabby-terminal"));else if("function"==typeof define&&define.amd)define(["@angular/common","@angular/core","rxjs","rxjs/operators","tabby-core","tabby-terminal"],t);else{var n="object"==typeof exports?t(require("@angular/common"),require("@angular/core"),require("rxjs"),require("rxjs/operators"),require("tabby-core"),require("tabby-terminal")):t(e["@angular/common"],e["@angular/core"],e.rxjs,e["rxjs/operators"],e["tabby-core"],e["tabby-terminal"]);for(var a in n)("object"==typeof exports?exports:e)[a]=n[a]}}(global,(e,t,n,a,s,i)=>(()=>{"use strict";var r={358(t){t.exports=e},860(e){e.exports=t},961(e){e.exports=n},439(e){e.exports=a},650(e){e.exports=s},349(e){e.exports=i}};const o={};function p(e){const t=o[e];if(void 0!==t)return t.exports;const n=o[e]={exports:{}};return r[e](n,n.exports,p),n.exports}p.d=(e,t)=>{for(var n in t)p.o(t,n)&&!p.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},p.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),p.r=e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};let c={};p.r(c),p.d(c,{WorkspaceEditorService:()=>C,default:()=>N});var l=p(860),d=p(358),h=p(650);const u="paneworks",w="Paneworks";let f=class extends h.ConfigProvider{constructor(){super(...arguments),this.defaults={[u]:{workspaces:[]}}}};function m(e){return"children"in e}function b(e){return e.children.flatMap(e=>m(e)?b(e):[e.paneId])}function g(e,t,n,a,s){if(e<=0)return[];const i=Math.max(1,Math.floor(t/Math.max(1,a))),r=Math.max(1,Math.floor(n/Math.max(1,s))),o=Math.min(e,i*r);let p=null;for(let e=1;e<=Math.min(o,r);e++){const r=Math.ceil(o/e);if(r>i)continue;const c=Math.min(t/r/a,n/e/s);(!p||c>p.score+1e-9)&&(p={rows:e,score:c})}const c=p?.rows??1,l=Math.floor(o/c),d=o%c;return Array.from({length:c},(e,t)=>l+(t<d?1:0))}function k(e,t){let n=0;const a=t.map(t=>{const a=e.slice(n,n+t);return n+=t,1===a.length?{paneId:a[0]}:{orientation:"horizontal",ratios:a.map(()=>1/a.length),children:a.map(e=>({paneId:e}))}});return 1===a.length&&m(a[0])?a[0]:{orientation:"vertical",ratios:a.map(()=>1/a.length),children:a}}function y(e){return Array.isArray(e.panes)||(e.panes=[]),e}f=function(e,t,n,a){var s,i=arguments.length,r=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(i<3?s(r):i>3?s(t,n,r):s(t,n))||r);return i>3&&r&&Object.defineProperty(t,n,r),r}([(0,l.Injectable)()],f);const v="paneworks:";function x(e){if("string"!=typeof e||!e.startsWith(v))return null;const[t,n]=e.slice(10).split(":");return t&&n?{workspaceId:t,paneId:n}:null}function P(e,t){const n=(e??"").trim(),a=(t??"").trim();return n?!a||a===n||a.startsWith(`${n} · `)?n:`${n} · ${a}`:a}function T(){return{id:W(),profileId:"",cwd:"",startupCommand:""}}const S=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899","#06b6d4","#f97316"],I=["columns","terminal","code","folder","home","briefcase","cog","database","server","cloud","rocket","flask","bug","wrench","cube","layer-group","sitemap","project-diagram"];function W(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}let C=class{constructor(e,t,n){this.config=e,this.notifications=t,this.profilesService=n,this.cachedProfiles=null,this.cacheTimestamp=0,this.CACHE_TTL=3e4}async getCachedProfiles(){const e=Date.now();return(!this.cachedProfiles||e-this.cacheTimestamp>this.CACHE_TTL)&&(this.cachedProfiles=await this.profilesService.getProfiles(),this.cacheTimestamp=e),this.cachedProfiles}getWorkspaces(){const e=this.config.store?.[u]?.workspaces??[];for(const t of e)Array.isArray(t.panes)||y(t);return e}async saveWorkspaceQuietly(e){const t=this.getWorkspaces(),n=t.findIndex(t=>t.id===e.id);-1!==n&&(t[n]=e,await this.saveWorkspaces(t))}minPaneSize(e){return{width:e.minPaneWidth||600,height:e.minPaneHeight||260}}planViewAll(e,t,n){const a=e.panes.filter(e=>!e.hidden).map(e=>e.id),s=this.minPaneSize(e),i=g(a.length,t,n,s.width,s.height),r=i.reduce((e,t)=>e+t,0),o=a.slice(0,r);return{tree:o.length?k(o,i):null,shown:o}}allPanesLayout(e,t,n){const a=e.panes.map(e=>e.id);if(!a.length)return null;const s=Math.max(1,t??window.innerWidth-210),i=Math.max(1,n??window.innerHeight-80);return k(a,g(a.length,s,i,1,1))}initialLayout(e){return this.allPanesLayout(e)}async saveWorkspaces(e){if(!this.config.store?.[u])throw new Error("Config store not initialized");this.config.store[u].workspaces=e,await this.saveConfig()}async addWorkspace(e){try{const t=this.getWorkspaces();t.push(e),await this.saveWorkspaces(t),this.notifications.info(`Workspace "${e.name}" created`)}catch(t){throw this.notifications.error(`Failed to create workspace "${e.name}"`),t}}async deleteWorkspace(e){const t=this.getWorkspaces(),n=t.find(t=>t.id===e);try{const a=t.filter(t=>t.id!==e);await this.saveWorkspaces(a),n&&this.notifications.info(`Workspace "${n.name}" deleted`)}catch(t){throw this.notifications.error(`Failed to delete workspace "${n?.name||e}"`),t}}async getAvailableProfiles(){return(await this.profilesService.getProfiles()).filter(e=>!e.id?.startsWith("split-layout:"))}cleanupOrphanedProfiles(){if(!this.config.store?.profiles)return;const e=this.config.store.profiles,t=`split-layout:${u}:`,n=e.filter(e=>!e.id?.startsWith(t));n.length!==e.length&&(this.config.store.profiles=n,this.config.save(),console.log(`[${w}] Cleaned up ${e.length-n.length} orphaned profiles`))}async generateTabbyProfile(e){await this.getCachedProfiles();const t=this.initialLayout(e);if(!t)return null;const n=this.sanitizeForProfileId(e.name);return{id:`split-layout:${u}:${n}:${e.id}`,type:"split-layout",name:e.name,group:w,icon:e.icon,color:e.color,isBuiltin:!1,options:{recoveryToken:this.generateRecoveryToken(t,e)}}}async createPaneToken(e,t){return await this.getCachedProfiles(),this.generatePaneToken(t,e.name,e.id)}generateRecoveryToken(e,t){return{type:"app:split-tab",orientation:"horizontal"===e.orientation?"h":"v",ratios:[...e.ratios],paneworksWorkspaceId:t.id,tabTitle:t.name,disableDynamicTitle:!0,children:e.children.map(e=>{if(m(e))return this.generateRecoveryToken(e,t);const n=t.panes.find(t=>t.id===e.paneId);return this.generatePaneToken(n,t.name,t.id)})}}generatePaneToken(e,t,n){const a=this.getProfileById(e.profileId),s=function(e,t){return`${v}${e}:${t}`}(n,e.id),i=P(e.name,"");if(!a)return{type:"app:local-tab",profile:{type:"local",name:"Shell",group:s},savedState:!1,tabTitle:e.name||"Shell",tabCustomTitle:i,paneworksWorkspaceId:n,disableDynamicTitle:!1};if(!this.isLocalProfile(a))return{type:`app:${a.type}-tab`,profile:{...a,group:s,disableDynamicTitle:!1},savedState:!1,tabTitle:e.name||a.name,tabCustomTitle:i,paneworksWorkspaceId:n,disableDynamicTitle:!1};const r=e.cwd||a.options?.cwd||"",o=this.isWslProfile(a),p=a.options?.args||[],c={restoreFromPTYID:!1,command:a.options?.command||"",args:o&&r?[...p,"--cd",r]:p,cwd:o?"":r,env:a.options?.env||{},width:null,height:null,pauseAfterExit:!1,runAsAdministrator:!1};return{type:"app:local-tab",profile:{id:a.id,type:"local",name:a.name||"Shell",group:s,options:c,icon:a.icon||"",color:a.color||"",disableDynamicTitle:!1,weight:0,isBuiltin:!1,isTemplate:!1,terminalColorScheme:null,behaviorOnSessionEnd:"auto"},savedState:!1,tabTitle:e.name||a.name||"Shell",tabCustomTitle:i,paneworksWorkspaceId:n,disableDynamicTitle:!1,cwd:o?"":r}}sanitizeForProfileId(e){return e.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"workspace"}isLocalProfile(e){return"local"===e.type||e.type?.startsWith("local:")||!1}isWslProfile(e){if(e.id?.startsWith("local:wsl"))return!0;const t=(e.options?.command||"").toLowerCase();return"wsl.exe"===t||"wsl"===t||t.endsWith("\\wsl.exe")||t.endsWith("/wsl.exe")}getProfileById(e){return(this.config.store?.profiles??[]).find(t=>t.id===e)||this.cachedProfiles?.find(t=>t.id===e)}collectStartupCommands(e){return e.panes.filter(e=>e.startupCommand).map(e=>({paneId:e.id,command:e.startupCommand}))}getWorkspace(e){return this.getWorkspaces().find(t=>t.id===e)}async saveConfig(){try{await this.config.save()}catch(e){throw console.error(`[${w}] Save error:`,e),e}}};C=function(e,t,n,a){var s,i=arguments.length,r=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(i<3?s(r):i>3?s(t,n,r):s(t,n))||r);return i>3&&r&&Object.defineProperty(t,n,r),r}([(0,l.Injectable)({providedIn:"root"}),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[h.ConfigService,h.NotificationsService,h.ProfilesService])],C);var O=p(349),A=p(961),R=p(439);const j=[0,300,1e3,3e3,8e3];let $=class{constructor(e,t){this.app=e,this.workspaces=t,this.workspaceSplitFound$=new A.Subject,this.pendingCommands=new Map,this.watchedSplits=new WeakSet,this.attachedPanes=new WeakSet,this.app.tabOpened$.subscribe(e=>this.onTabOpened(e))}registerCommands(e){for(const t of e)this.pendingCommands.set(t.paneId,t)}onTabOpened(e){e instanceof h.SplitTabComponent?this.watchSplit(e):e instanceof O.BaseTerminalTabComponent&&this.processPane(e,null)}watchSplit(e){if(this.watchedSplits.has(e))return;this.watchedSplits.add(e);const t=()=>this.scanSplit(e);e.initialized$?.subscribe({complete:t}),e.tabAdded$?.subscribe(()=>t());for(const e of j)setTimeout(t,e)}scanSplit(e){for(const t of e.getAllTabs())t instanceof O.BaseTerminalTabComponent&&this.processPane(t,e)}processPane(e,t){const n=x(e.profile?.group);n&&(t&&(this.pinSplitTitle(t,n.workspaceId),this.workspaceSplitFound$.next({split:t,workspaceId:n.workspaceId})),this.attachedPanes.has(e)||(this.attachedPanes.add(e),this.attachLabelSync(e,n.workspaceId,n.paneId),this.runPendingCommand(e,n.paneId)))}pinSplitTitle(e,t){const n=this.workspaces.getWorkspace(t)?.name;e.disableDynamicTitle=!0,n&&e.title!==n&&e.setTitle(n)}attachLabelSync(e,t,n){const a=e;a.disableDynamicTitle=!1;let s=e.customTitle,i=!0;const r=()=>{if(!i)return;if(e.customTitle!==s)return void(i=!1);const r=this.workspaces.getWorkspace(t),o=r?function(e,t){return e.panes.find(e=>e.id===t)}(r,n)?.name:void 0,p=P(o,e.title);p&&p!==e.customTitle&&(s=p,"function"==typeof a.setCustomTitle?a.setCustomTitle(p):e.customTitle=p)},o=e.setTitle.bind(e);e.setTitle=e=>{o(e),r()},r()}runPendingCommand(e,t,n=!1){const a=this.pendingCommands.get(t);if(!a?.command)return;this.pendingCommands.delete(t);const s=a.command,i=()=>{console.log(`[${w}] Sending startup command:`,s),e.sendInput(s+"\r"),this.clearProfileArgs(e)},r=e.sessionChanged$;if(!e.session&&r&&!n)return this.pendingCommands.set(t,a),void r.pipe((0,A.first)(e=>!!e),(0,A.timeout)(5e3),(0,R.catchError)(()=>(0,A.of)(null))).subscribe(()=>this.runPendingCommand(e,t,!0));e.session?.output$?e.session.output$.pipe((0,A.first)(),(0,A.timeout)(2e3),(0,R.catchError)(()=>(0,A.of)(null))).subscribe(()=>setTimeout(i,100)):setTimeout(i,500)}clearProfileArgs(e){const t=e.profile;t?.options?.args&&(t.options.args=[])}};$=function(e,t,n,a){var s,i=arguments.length,r=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(i<3?s(r):i>3?s(t,n,r):s(t,n))||r);return i>3&&r&&Object.defineProperty(t,n,r),r}([(0,l.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[h.AppService,C])],$);const E=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899","#06b6d4","#f97316"];let z=class{constructor(e,t,n,a,s,i){this.app=e,this.profilesService=t,this.runtime=n,this.workspaces=a,this.tabsService=s,this.tabRecovery=i,this.states=new WeakMap,this.active=new Set,this.resizeTimer=null,this.profiles=[],this.watchedSessions=new WeakSet,this.runtime.workspaceSplitFound$.subscribe(({split:e,workspaceId:t})=>this.attach(e,t)),window.addEventListener("resize",()=>{this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=setTimeout(()=>this.refreshAllGrids(),250)})}findOpenTab(e){for(const t of this.active)if(t.workspaceId===e)return t.split;for(const t of this.app.tabs)if(t instanceof h.SplitTabComponent&&t.getAllTabs().some(t=>x(t.profile?.group)?.workspaceId===e))return t;return null}async openWorkspace(e){const t=this.findOpenTab(e);if(t)return void this.app.selectTab(t);const n=this.workspaces.getWorkspace(e);if(!n)return;const a=this.workspaces.collectStartupCommands(n);a.length&&this.runtime.registerCommands(a);const s=await this.workspaces.generateTabbyProfile(n);s&&this.profilesService.openNewTabForProfile(s)}async createWorkspace(){await this.loadProfiles();const e=new Set(this.workspaces.getWorkspaces().map(e=>e.name));let t=1;for(;e.has(`Workspace ${t}`);)t++;const n=function(e=""){return{id:W(),name:e,icon:I[Math.floor(Math.random()*I.length)],color:S[Math.floor(Math.random()*S.length)],panes:[T(),T()],launchOnStartup:!1}}(`Workspace ${t}`),a=this.profiles.find(e=>"local"===e.type||e.type?.startsWith("local:"))??this.profiles[0];n.panes=[{...T(),profileId:a?.id??""}],await this.workspaces.addWorkspace(n),await this.openWorkspace(n.id)}async loadProfiles(){this.profiles.length||(this.profiles=await this.workspaces.getAvailableProfiles())}attach(e,t){const n=this.states.get(e);if(n)return void(n.sidebar?.isConnected||this.mountSidebar(n));const a={split:e,workspaceId:t,view:{kind:"all"},appliedPlan:null,parked:new Map,sidebar:null,collapsed:this.loadCollapsed(t),busy:!1,dragging:!1,editingPaneId:null,menuOpen:!1,timer:null,unseen:new Set,starting:!0,leftAt:new Map};this.states.set(e,a),this.active.add(a),this.loadProfiles(),e.destroyed$.subscribe(()=>{for(const e of a.parked.values())e.destroy();a.parked.clear(),a.timer&&clearInterval(a.timer),a.sidebar?.remove(),this.active.delete(a)}),e.visibility$?.subscribe(e=>{e&&setTimeout(()=>this.refreshGrid(a),50)}),this.mountSidebar(a),a.timer=setInterval(()=>this.render(a),1e3),this.startAllPanes(a)}async showAll(e,t=!1){const n=this.workspaces.getWorkspace(e.workspaceId),a=this.paneArea(e);if(!n||!a)return;const s=this.workspaces.planViewAll(n,a.width,a.height),i=JSON.stringify(s.tree);i!==e.appliedPlan&&console.log(`[${w}] View all:`,{area:a,shown:s.shown.length,min:this.workspaces.minPaneSize(n)});const r="all"===e.view.kind;e.view={kind:"all"},!s.tree||!t&&r&&i===e.appliedPlan||await this.apply(e,n,s.tree)&&(e.appliedPlan=i),this.render(e,!0)}async showFocus(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);if(!n)return;const a={orientation:"horizontal",ratios:[1],children:[{paneId:t}]};await this.apply(e,n,a)&&(e.view={kind:"focus",paneId:t},e.appliedPlan=null),this.render(e,!0)}async reapplyView(e){"focus"===e.view.kind?await this.showFocus(e,e.view.paneId):await this.showAll(e,!0)}refreshGrid(e){"all"!==e.view.kind||e.busy||e.starting||this.showAll(e)}async startAllPanes(e){const t=e.view;e.starting=!0;try{const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;const n=await this.waitFor(()=>this.paneArea(e),3e3),a=t.panes.some(t=>!this.livePanes(e).has(t.id)),s=this.workspaces.allPanesLayout(t,n?.width,n?.height);a&&s&&await this.apply(e,t,s),await this.waitFor(()=>{const t=[...this.livePanes(e).values()];return!(!t.length||!t.every(e=>e.session))||null},8e3)}finally{e.starting=!1}"focus"===t.kind?await this.showFocus(e,t.paneId):await this.showAll(e,!0)}async waitFor(e,t){const n=Date.now()+t;for(;;){const t=e();if(t)return t;if(Date.now()>n)return null;await new Promise(e=>setTimeout(e,100))}}refreshAllGrids(){for(const e of this.active)this.refreshGrid(e)}paneArea(e){const t=this.splitElement(e)?.getBoundingClientRect();return t&&t.width>0&&t.height>0?{width:t.width,height:t.height}:null}async apply(e,t,n){if(e.busy)return!1;e.busy=!0;try{const a=e.split,s=new Map(t.panes.map(e=>[e.id,e])),i=this.livePanes(e),r=b(n).filter(e=>s.has(e));for(const e of r)if(!i.has(e)){const n=await this.createPane(t,s.get(e));n&&i.set(e,n)}const o=r.filter(e=>i.has(e));if(!o.length)return!1;for(const t of e.split.getAllTabs()){const n=this.paneIdOf(t);n&&o.includes(n)||(t.removeFromContainer(),a.viewRefs?.delete(t),t.parent=null,n?(e.parked.set(n,t),e.leftAt.set(n,Date.now())):t.destroy())}const p=this.buildContainer(n,i);if(!p)return!1;a.maximizedTab=null,a.root=p;for(const t of o){const n=i.get(t);e.unseen.delete(t),n.clearActivity(),a.viewRefs?.has(n)||(e.parked.delete(t),n.parent=e.split,n.emitVisibility?.(a.visibility?.value??!0),a.attachTabView(n),a.onAfterTabAdded(n))}return a.layout(),e.split.focus(i.get(o[0])),a.recoveryStateChangedHint?.next(),this.nudgeResize(),setTimeout(()=>this.applyLabelColors(e,this.workspaces.getWorkspace(e.workspaceId)),100),!0}catch(e){return console.error(`[${w}] Layout change failed:`,e),!1}finally{e.busy=!1}}buildContainer(e,t){const n=[],a=[];if(e.children.forEach((s,i)=>{const r=m(s)?this.buildContainer(s,t):t.get(s.paneId)??null;r&&(n.push(r),a.push(e.ratios[i]??1))}),!n.length)return null;const s=a.reduce((e,t)=>e+t,0)||1,i=new h.SplitContainer;return i.orientation="horizontal"===e.orientation?"h":"v",i.children=n,i.ratios=a.map(e=>e/s),i}async createPane(e,t){try{const n=await this.workspaces.createPaneToken(e,t),a=await this.tabRecovery.recoverTab(n);return a?(t.startupCommand&&this.runtime.registerCommands([{paneId:t.id,command:t.startupCommand}]),this.tabsService.create(a)):null}catch(e){return console.error(`[${w}] Could not create pane:`,t,e),null}}livePanes(e){const t=new Map;for(const n of e.split.getAllTabs()){const e=this.paneIdOf(n);e&&t.set(e,n)}for(const[n,a]of e.parked)t.set(n,a);return t}paneIdOf(e){return x(e.profile?.group)?.paneId??null}nudgeResize(){setTimeout(()=>window.dispatchEvent(new Event("resize")),50)}async toggleShown(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),a=n?.panes.find(e=>e.id===t);n&&a&&(a.hidden?delete a.hidden:a.hidden=!0,await this.workspaces.saveWorkspaceQuietly(n),"all"===e.view.kind?await this.showAll(e):this.render(e,!0))}async movePane(e,t,n){const a=this.workspaces.getWorkspace(e.workspaceId);if(!a)return;const s=a.panes.findIndex(e=>e.id===t);if(-1===s||t===n)return;const[i]=a.panes.splice(s,1),r=n?a.panes.findIndex(e=>e.id===n):-1;a.panes.splice(-1===r?a.panes.length:r,0,i),await this.workspaces.saveWorkspaceQuietly(a),"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}async addPane(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;await this.loadProfiles();const n=t.panes[t.panes.length-1],a={...T(),profileId:n?.profileId||this.profiles[0]?.id||"",cwd:n?.cwd||""};t.panes.push(a),await this.workspaces.saveWorkspaceQuietly(t),e.editingPaneId=a.id,e.menuOpen=!1,this.render(e,!0)}async savePane(e,t,n){const a=this.workspaces.getWorkspace(e.workspaceId),s=a?.panes.find(e=>e.id===t);if(a&&s){Object.assign(s,n);for(const e of["name","color"])s[e]||delete s[e];await this.workspaces.saveWorkspaceQuietly(a),e.editingPaneId=null,this.render(e,!0),this.livePanes(e).has(t)||await this.startAllPanes(e)}}async restartPane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),a=n?.panes.find(e=>e.id===t);if(!n||!a)return;const s=this.livePanes(e).get(t),i=await this.createPane(n,a);i&&(s&&e.parked.get(t)===s?(e.parked.set(t,i),s.destroy()):s&&s.parent===e.split?(i.parent=e.split,e.split.replaceTab(s,i),e.split.viewRefs?.delete(s),s.destroy(),e.split.layout(),e.split.focus(i),this.nudgeResize()):e.parked.set(t,i),this.render(e,!0))}async removePane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),a=n?.panes.find(e=>e.id===t);if(!n||!a)return;if(n.panes.length<=1)return void window.alert("A workspace needs at least one pane. Delete the workspace from its menu instead.");const s=a.name||a.startupCommand||"this pane";if(!window.confirm(`Remove "${s}" from ${n.name}? Its terminal is closed.`))return;n.panes=n.panes.filter(e=>e.id!==t),await this.workspaces.saveWorkspaceQuietly(n),e.editingPaneId=null;const i=this.livePanes(e).get(t);i&&i.parent===e.split&&("focus"===e.view.kind&&e.view.paneId===t&&(e.view={kind:"all"}),await this.reapplyView(e));const r=this.livePanes(e).get(t);if(r&&r.parent===e.split&&e.split.getAllTabs().length<=1){const t=n.panes[0];delete t.hidden,await this.workspaces.saveWorkspaceQuietly(n),await this.showFocus(e,t.id)}e.parked.delete(t),this.livePanes(e).get(t)?.destroy(),i?.destroy(),this.render(e,!0)}async saveWorkspaceSettings(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);if(n){n.name=t.name.trim()||n.name;for(const e of["minPaneWidth","minPaneHeight"]){const a=t[e];a&&a>0?n[e]=Math.round(a):delete n[e]}t.launchOnStartup?n.launchOnStartup=!0:n.launchOnStartup=!1,await this.workspaces.saveWorkspaceQuietly(n),e.split.setTitle(n.name),e.menuOpen=!1,"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}}async deleteWorkspace(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;if(!window.confirm(`Delete the workspace "${t.name}"? Its tab and all its panes are closed.`))return;await this.workspaces.deleteWorkspace(t.id);const n=this.app;"function"==typeof n.closeTab?n.closeTab(e.split,!1):e.split.destroy()}splitElement(e){const t=e.split;for(const e of[t.hostView,t.viewContainerEmbeddedRef]){const t=e?.rootNodes?.[0];if(t instanceof HTMLElement)return t}return null}mountSidebar(e){const t=this.splitElement(e),n=t?.parentElement;t&&n?(e.sidebar||(e.sidebar=document.createElement("div"),e.sidebar.className="paneworks-sidebar",this.ensureStyles()),n.insertBefore(e.sidebar,t),t.setAttribute("data-paneworks",""),this.render(e,!0),this.nudgeResize(),setTimeout(()=>this.refreshGrid(e),100)):setTimeout(()=>{!e.sidebar?.isConnected&&this.active.has(e)&&this.mountSidebar(e)},500)}applyLabelColors(e,t){const n=this.splitElement(e);if(!n||!t)return;const a=new Map(t.panes.map(e=>[e.id,e.color])),s=Array.from(n.querySelectorAll(":scope > split-tab-pane-label")),i=e.split.getAllTabs();s.forEach((e,t)=>{const n=e.querySelector(".custom-name");if(!n)return;const s=i[t]?this.paneIdOf(i[t]):null,r=s?a.get(s):void 0;r?(n.style.background=r,n.style.color=function(e){const t=e.replace("#","");if(!/^[0-9a-f]{6}$/i.test(t))return"#fff";const[n,a,s]=[0,2,4].map(e=>parseInt(t.slice(e,e+2),16)/255).map(e=>e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4));return.2126*n+.7152*a+.0722*s>.4?"#000":"#fff"}(r)):(n.style.removeProperty("background"),n.style.removeProperty("color"))})}watchOutput(e){for(const[t,n]of this.livePanes(e)){const a=n.session;a?.output$&&!this.watchedSessions.has(a)&&(this.watchedSessions.add(a),a.output$.subscribe(()=>{n.parent===e.split||e.unseen.has(t)||Date.now()-(e.leftAt.get(t)??0)<2500||e.unseen.add(t)}))}}render(e,t=!1){const n=e.sidebar;if(!n||!n.isConnected||e.dragging)return;if(this.watchOutput(e),this.applyLabelColors(e,this.workspaces.getWorkspace(e.workspaceId)),!t&&(e.editingPaneId||e.menuOpen))return;const a=this.workspaces.getWorkspace(e.workspaceId),s=this.livePanes(e),i=new Set(e.split.getAllTabs().map(e=>this.paneIdOf(e))),r=JSON.stringify([e.collapsed,e.view,e.editingPaneId,e.menuOpen,a,a?.panes.map(t=>{const n=s.get(t.id);return[n?.customTitle,n?.title,e.unseen.has(t.id),i.has(t.id)]})]);if(!t&&n.__pwSignature===r)return;n.__pwSignature=r,n.classList.toggle("collapsed",e.collapsed),n.style.flex=`0 0 ${e.collapsed?22:210}px`,n.textContent="";const o=this.button("pw-icon-btn pw-toggle",e.collapsed?"»":"«",e.collapsed?"Show sidebar":"Hide sidebar",()=>{e.collapsed=!e.collapsed,this.saveCollapsed(e.workspaceId,e.collapsed),this.render(e,!0),this.nudgeResize()});if(e.collapsed||!a)return void n.append(o);const p=this.node("div","pw-header"),c=this.button("pw-ws","","Workspace menu",()=>{e.menuOpen=!e.menuOpen,e.editingPaneId=null,this.render(e,!0)});c.append(this.node("span","pw-ws-name",a.name),this.node("span","pw-caret",e.menuOpen?"▴":"▾")),p.append(c,o),n.append(p),e.menuOpen&&n.append(this.workspaceMenu(e,a));const l=a.panes.filter(e=>!e.hidden),d=l.filter(e=>i.has(e.id)).length,h=this.node("div","pw-row pw-all"+("all"===e.view.kind?" active":""));h.append(this.node("span","pw-main","View all"),this.node("span","pw-count","all"===e.view.kind?`${d} / ${l.length}`:`${l.length} on`)),h.title="Show all switched-on panes in a grid",h.onclick=()=>this.showAll(e,!0),n.append(h);const u=this.node("div","pw-section");u.append(this.node("span","","Panes"),this.button("pw-icon-btn pw-add","+","Add a pane",()=>this.addPane(e))),n.append(u);const w="focus"===e.view.kind?e.view.paneId:null,f=this.node("div","pw-list");for(const t of a.panes)f.append(this.paneRow(e,t,s.get(t.id),i.has(t.id),w)),e.editingPaneId===t.id&&f.append(this.paneEditor(e,t));const m=this.node("div","pw-drop-end");this.makeDropTarget(e,m,null),f.append(m),n.append(f)}paneRow(e,t,n,a,s){const i=(n?n.customTitle||n.title:"")||t.name||t.startupCommand||"New pane",r=[t.name,t.startupCommand].filter(Boolean).join(" · "),o=!t.hidden&&!a&&"all"===e.view.kind,p=!a&&e.unseen.has(t.id),c=["pw-row","pw-pane"];a&&c.push("onscreen"),t.id===s&&c.push("focused"),t.hidden&&c.push("off"),e.editingPaneId===t.id&&c.push("editing");const l=this.node("div",c.join(" "));l.title=[a?"On screen":n?"Running, not on screen":"Not running (shown again by View all or its title)",t.hidden?'switched off (not in "View all")':o?"switched on, but no room at the minimum pane size":""].filter(Boolean).join(" · "),l.draggable=!0,l.append(this.node("span","pw-handle","⋮⋮")),l.addEventListener("dragstart",n=>{e.dragging=!0,n.dataTransfer?.setData("text/plain",t.id),n.dataTransfer&&(n.dataTransfer.effectAllowed="move"),l.classList.add("dragging")}),l.addEventListener("dragend",()=>{e.dragging=!1,l.classList.remove("dragging"),this.render(e,!0)}),this.makeDropTarget(e,l,t.id);const d=this.node("span","pw-pane-color"+(t.color?"":" none"));t.color&&(d.style.background=t.color),d.title=t.color?`Label colour ${t.color}`:"No label colour",l.append(d);const h=this.node("span","pw-text"),u=this.node("span","pw-main");if(u.append(this.node("span","pw-name",i)),p){const e=this.node("span","pw-news","new");e.title="New output since it left the screen",u.append(e)}h.append(u),(r||o)&&h.append(this.node("span","pw-sub",[r,o?"no room":""].filter(Boolean).join(" · "))),h.onclick=()=>{t.id===s?this.showAll(e,!0):this.showFocus(e,t.id)},h.title=t.id===s?'Back to "View all"':"Show this pane alone";const w=this.node("label","pw-switch");w.title=t.hidden?'Off: not in "View all"':'On: in "View all"';const f=document.createElement("input");f.type="checkbox",f.checked=!t.hidden,f.onchange=()=>this.toggleShown(e,t.id),w.append(f,this.node("span","pw-slider")),w.addEventListener("click",e=>e.stopPropagation());const m=this.button("pw-icon-btn pw-more","⋯","Edit pane",()=>{e.editingPaneId=e.editingPaneId===t.id?null:t.id,e.menuOpen=!1,this.render(e,!0)});return l.append(h,w,m),l}paneEditor(e,t){const n=this.node("div","pw-form"),a=this.input("text",t.name??"","optional"),s=this.input("text",t.startupCommand??"","e.g. c 1"),i=this.input("text",t.cwd??"","C:\\path or /home/user"),r=document.createElement("select");r.className="pw-input";const o=document.createElement("option");o.value="",o.textContent="-- profile --",r.append(o);for(const e of this.profiles){const t=document.createElement("option");t.value=e.id,t.textContent=e.name,r.append(t)}r.value=t.profileId??"";let p=t.color??"";const c=this.node("div","pw-colors"),l=document.createElement("input");l.type="color",l.className="pw-color-custom",l.title="Custom colour";const d=()=>{c.querySelectorAll(".pw-swatch").forEach(e=>{e.classList.toggle("selected",e.dataset.color===p)}),l.classList.toggle("selected",!!p&&!E.includes(p)),p&&(l.value=p)};for(const e of["",...E]){const t=this.button("pw-swatch"+(e?"":" none"),"",e||"No colour",()=>{p=e,d()});t.dataset.color=e,e&&(t.style.background=e),c.append(t)}l.addEventListener("input",()=>{p=l.value,d()}),c.append(l),d(),n.append(this.field("Name",a),this.field("Label colour",c),this.field("Startup command",s),this.field("Folder",i),this.field("Profile",r),this.node("div","pw-hint","Command, folder and profile apply when the pane (re)starts."));const h=()=>this.savePane(e,t.id,{name:a.value.trim(),color:p,startupCommand:s.value.trim(),cwd:i.value.trim(),profileId:r.value});for(const t of[a,s,i])t.addEventListener("keydown",t=>{"Enter"===t.key&&h(),"Escape"===t.key&&(e.editingPaneId=null,this.render(e,!0))});const u=this.node("div","pw-actions");return u.append(this.button("pw-btn primary","Save","Save the pane settings",h),this.button("pw-btn","Restart","Save, then close and start the pane again",async()=>{await h(),await this.restartPane(e,t.id)}),this.button("pw-btn danger","Remove","Remove the pane from the workspace",()=>this.removePane(e,t.id))),n.append(u),setTimeout(()=>a.focus(),0),n}workspaceMenu(e,t){const n=this.node("div","pw-form pw-menu"),a=this.input("text",t.name,"Workspace name"),s=this.input("number",t.minPaneWidth?String(t.minPaneWidth):"",String(600)),i=this.input("number",t.minPaneHeight?String(t.minPaneHeight):"",String(260));s.classList.add("pw-size"),i.classList.add("pw-size");const r=this.node("div","pw-size-row");r.append(s,this.node("span","","×"),i,this.node("span","","px"));const o=document.createElement("input");o.type="checkbox",o.checked=!!t.launchOnStartup;const p=this.node("label","pw-check");p.append(o,this.node("span","","Open when Tabby starts")),n.append(this.field("Name",a),this.field("Minimum pane size",r),this.node("div","pw-hint",'"View all" fits as many switched-on panes as this size allows.'),p);const c=()=>this.saveWorkspaceSettings(e,{name:a.value,minPaneWidth:Number(s.value)||null,minPaneHeight:Number(i.value)||null,launchOnStartup:o.checked});for(const t of[a,s,i])t.addEventListener("keydown",t=>{"Enter"===t.key&&c(),"Escape"===t.key&&(e.menuOpen=!1,this.render(e,!0))});const l=this.node("div","pw-actions");l.append(this.button("pw-btn primary","Save","Save the workspace settings",c),this.button("pw-btn","Close","Close the menu",()=>{e.menuOpen=!1,this.render(e,!0)})),n.append(l),n.append(this.node("div","pw-menu-title","Workspaces"));for(const a of this.workspaces.getWorkspaces()){const s=a.id===t.id,i=!s&&!!this.findOpenTab(a.id),r=this.button("pw-menu-item"+(s?" current":""),"",s?"This workspace":i?"Switch to its tab":"Open it",()=>{s||(e.menuOpen=!1,this.render(e,!0),this.openWorkspace(a.id))});r.append(this.node("span","pw-name",a.name),this.node("span","pw-count",s?"this":i?"open":"")),n.append(r)}return n.append(this.button("pw-menu-item","+ New workspace","Create a workspace with one pane",()=>{e.menuOpen=!1,this.render(e,!0),this.createWorkspace()}),this.button("pw-menu-item danger","Delete this workspace…","Delete it and close its tab",()=>this.deleteWorkspace(e))),n}makeDropTarget(e,t,n){t.addEventListener("dragover",n=>{e.dragging&&(n.preventDefault(),n.dataTransfer&&(n.dataTransfer.dropEffect="move"),t.classList.add("drop-before"))}),t.addEventListener("dragleave",()=>t.classList.remove("drop-before")),t.addEventListener("drop",a=>{a.preventDefault(),t.classList.remove("drop-before");const s=a.dataTransfer?.getData("text/plain");e.dragging=!1,s&&this.movePane(e,s,n)})}node(e,t,n){const a=document.createElement(e);return t&&(a.className=t),void 0!==n&&(a.textContent=n),a}button(e,t,n,a){const s=document.createElement("button");return s.type="button",s.className=e,s.textContent=t,s.title=n,s.addEventListener("click",e=>{e.stopPropagation(),a()}),s}input(e,t,n){const a=document.createElement("input");return a.type=e,a.className="pw-input",a.value=t,a.placeholder=n,a.addEventListener("keydown",e=>e.stopPropagation()),a}field(e,t){const n=this.node("label","pw-field");return n.append(this.node("span","pw-label",e),t),n}ensureStyles(){if(document.getElementById("paneworks-sidebar-styles"))return;const e=document.createElement("style");e.id="paneworks-sidebar-styles",e.textContent="\n /* Pane frames in Paneworks tabs: every pane gets a frame and a small gap,\n the pane with keyboard focus an accent frame. Tabby positions the panes\n (class \"child\") absolutely; border-box keeps them inside their slot. */\n [data-paneworks] > .child {\n box-sizing: border-box;\n border: 3px solid var(--theme-bg-more, rgba(0,0,0,.35));\n border-radius: 6px;\n overflow: hidden;\n transition: border-color .12s;\n }\n [data-paneworks] > .child.focused {\n border-color: var(--theme-primary, #4c9aff);\n }\n [data-paneworks] split-tab-pane-label .custom-name {\n font-weight: 600;\n }\n /* Split handles: Tabby's handle is a 10px band centred on the border between two\n panes. A bright 4px bar in its middle (inset 3px works for both orientations)\n stands out against the panes; brighter on hover, accent while dragging. */\n [data-paneworks] > split-tab-spanner::after {\n content: '';\n position: absolute;\n inset: 3px;\n border-radius: 2px;\n background: rgba(255, 255, 255, .30);\n background: color-mix(in srgb, var(--theme-fg, #fff) 32%, transparent);\n pointer-events: none;\n transition: background .12s;\n }\n [data-paneworks] > split-tab-spanner:hover::after {\n background: rgba(255, 255, 255, .55);\n background: color-mix(in srgb, var(--theme-fg, #fff) 60%, transparent);\n }\n [data-paneworks] > split-tab-spanner.active::after {\n background: var(--theme-primary, #4c9aff);\n }\n\n .paneworks-sidebar {\n --pw-accent: var(--theme-primary, #4c9aff);\n display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;\n background: var(--theme-bg-more, rgba(0,0,0,.25));\n border-right: 1px solid var(--theme-bg-more-2, rgba(255,255,255,.08));\n color: var(--theme-fg, inherit); font-size: 12px; user-select: none;\n }\n .paneworks-sidebar.collapsed { align-items: center; }\n .paneworks-sidebar button { font: inherit; color: inherit; }\n .paneworks-sidebar .pw-icon-btn {\n background: none; border: none; opacity: .6; cursor: pointer; padding: 2px 6px; line-height: 1; font-size: 13px;\n }\n .paneworks-sidebar .pw-icon-btn:hover { opacity: 1; }\n .paneworks-sidebar.collapsed .pw-toggle { margin-top: 8px; }\n\n .paneworks-sidebar .pw-header { display: flex; align-items: center; padding: 6px 4px 4px 4px; }\n .paneworks-sidebar .pw-ws {\n flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; background: none; border: none;\n padding: 4px 6px; border-radius: 4px; cursor: pointer; font-weight: 600; text-align: left;\n }\n .paneworks-sidebar .pw-ws:hover { background: rgba(127,127,127,.15); }\n .paneworks-sidebar .pw-ws-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n .paneworks-sidebar .pw-caret { opacity: .5; font-size: 10px; }\n\n .paneworks-sidebar .pw-section {\n display: flex; align-items: center; justify-content: space-between;\n padding: 10px 6px 2px 10px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; opacity: .6;\n }\n .paneworks-sidebar .pw-add { font-size: 15px; opacity: .9; }\n\n .paneworks-sidebar .pw-row {\n display: flex; align-items: center; gap: 6px; padding: 5px 4px 5px 4px;\n border-left: 3px solid transparent; border-top: 2px solid transparent;\n }\n .paneworks-sidebar .pw-row:hover { background: rgba(127,127,127,.10); }\n .paneworks-sidebar .pw-all { cursor: pointer; padding-left: 10px; }\n .paneworks-sidebar .pw-all .pw-main { flex: 1; font-weight: 600; }\n .paneworks-sidebar .pw-all.active { border-left-color: var(--pw-accent); background: rgba(127,127,127,.14); }\n .paneworks-sidebar .pw-count { font-size: 10px; opacity: .55; }\n\n /* Pane states: on screen = accent bar + full brightness; running elsewhere = dimmed;\n switched off = dimmer; focus view = highlighted row. */\n .paneworks-sidebar .pw-pane .pw-text { opacity: .6; }\n .paneworks-sidebar .pw-pane.onscreen { border-left-color: var(--pw-accent); }\n .paneworks-sidebar .pw-pane.onscreen .pw-text { opacity: 1; }\n .paneworks-sidebar .pw-pane.off .pw-text { opacity: .38; }\n .paneworks-sidebar .pw-pane.focused { background: rgba(127,127,127,.20); }\n .paneworks-sidebar .pw-pane.focused .pw-name { font-weight: 600; }\n .paneworks-sidebar .pw-pane.editing { background: rgba(127,127,127,.14); }\n\n .paneworks-sidebar .pw-pane-color { flex: 0 0 8px; height: 8px; border-radius: 2px; }\n .paneworks-sidebar .pw-pane-color.none { border: 1px dashed rgba(127,127,127,.5); box-sizing: border-box; }\n .paneworks-sidebar .pw-colors { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }\n .paneworks-sidebar .pw-swatch {\n width: 16px; height: 16px; padding: 0; border-radius: 3px; cursor: pointer;\n border: 2px solid transparent; box-sizing: border-box;\n }\n .paneworks-sidebar .pw-swatch.none {\n background: repeating-linear-gradient(45deg, transparent 0 3px, rgba(127,127,127,.5) 3px 4px);\n border-color: rgba(127,127,127,.4);\n }\n .paneworks-sidebar .pw-swatch.selected, .paneworks-sidebar .pw-color-custom.selected {\n border-color: var(--theme-fg, #fff);\n }\n .paneworks-sidebar .pw-color-custom {\n width: 22px; height: 18px; padding: 0; border: 2px solid transparent; border-radius: 3px;\n background: none; cursor: pointer;\n }\n .paneworks-sidebar .pw-handle { cursor: grab; opacity: .25; font-size: 10px; letter-spacing: -2px; }\n .paneworks-sidebar .pw-row:hover .pw-handle { opacity: .7; }\n .paneworks-sidebar .pw-row.dragging { opacity: .35; }\n .paneworks-sidebar .drop-before { border-top-color: var(--pw-accent); }\n .paneworks-sidebar .pw-drop-end { flex: 1; min-height: 24px; border-top: 2px solid transparent; }\n\n .paneworks-sidebar .pw-text { display: flex; flex-direction: column; min-width: 0; flex: 1; cursor: pointer; }\n .paneworks-sidebar .pw-main { display: flex; align-items: center; gap: 5px; min-width: 0; }\n .paneworks-sidebar .pw-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n .paneworks-sidebar .pw-sub { font-size: 10px; opacity: .6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n .paneworks-sidebar .pw-news {\n flex: none; font-size: 9px; line-height: 1; padding: 2px 4px; border-radius: 3px;\n background: var(--pw-accent); color: var(--theme-bg, #000); font-weight: 600; text-transform: uppercase;\n }\n .paneworks-sidebar .pw-more { opacity: .35; font-size: 14px; }\n .paneworks-sidebar .pw-row:hover .pw-more, .paneworks-sidebar .pw-pane.editing .pw-more { opacity: .9; }\n\n .paneworks-sidebar .pw-switch { position: relative; flex: 0 0 26px; height: 14px; cursor: pointer; }\n .paneworks-sidebar .pw-switch input { opacity: 0; width: 0; height: 0; position: absolute; }\n .paneworks-sidebar .pw-slider {\n position: absolute; inset: 0; border-radius: 7px; background: rgba(127,127,127,.35); transition: background .15s;\n }\n .paneworks-sidebar .pw-slider::before {\n content: ''; position: absolute; left: 2px; top: 2px; width: 10px; height: 10px; border-radius: 50%;\n background: var(--theme-fg, #fff); transition: transform .15s;\n }\n .paneworks-sidebar .pw-switch input:checked + .pw-slider { background: var(--pw-accent); }\n .paneworks-sidebar .pw-switch input:checked + .pw-slider::before { transform: translateX(12px); }\n\n .paneworks-sidebar .pw-form {\n display: flex; flex-direction: column; gap: 6px; margin: 2px 6px 6px 7px; padding: 8px;\n border-radius: 4px; background: rgba(127,127,127,.10); user-select: text;\n }\n .paneworks-sidebar .pw-menu { margin-top: 0; }\n .paneworks-sidebar .pw-field { display: flex; flex-direction: column; gap: 2px; margin: 0; }\n .paneworks-sidebar .pw-label { font-size: 10px; opacity: .6; }\n .paneworks-sidebar .pw-input {\n width: 100%; box-sizing: border-box; padding: 3px 6px; font: inherit; color: inherit; border-radius: 3px;\n background: var(--theme-bg, rgba(0,0,0,.3)); border: 1px solid rgba(127,127,127,.35);\n }\n .paneworks-sidebar .pw-input:focus { outline: none; border-color: var(--pw-accent); }\n .paneworks-sidebar .pw-size-row { display: flex; align-items: center; gap: 4px; }\n .paneworks-sidebar .pw-size { width: 64px; }\n .paneworks-sidebar .pw-check { display: flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; }\n .paneworks-sidebar .pw-hint { font-size: 10px; opacity: .55; }\n .paneworks-sidebar .pw-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }\n .paneworks-sidebar .pw-btn {\n padding: 3px 8px; border-radius: 3px; cursor: pointer; background: rgba(127,127,127,.2);\n border: 1px solid transparent;\n }\n .paneworks-sidebar .pw-btn:hover { background: rgba(127,127,127,.3); }\n .paneworks-sidebar .pw-btn.primary { background: var(--pw-accent); color: var(--theme-bg, #000); }\n .paneworks-sidebar .pw-btn.danger:hover { background: #c0392b; color: #fff; }\n .paneworks-sidebar .pw-menu-title { margin-top: 8px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; opacity: .6; }\n .paneworks-sidebar .pw-menu-item {\n display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%;\n background: none; border: none; padding: 4px 6px; border-radius: 3px; cursor: pointer; text-align: left;\n }\n .paneworks-sidebar .pw-menu-item:hover { background: rgba(127,127,127,.2); }\n .paneworks-sidebar .pw-menu-item.current { cursor: default; font-weight: 600; }\n .paneworks-sidebar .pw-menu-item.danger:hover { background: #c0392b; color: #fff; }\n ",document.head.appendChild(e)}loadCollapsed(e){try{return"1"===localStorage.getItem(`paneworks-sidebar-collapsed:${e}`)}catch{return!1}}saveCollapsed(e,t){try{localStorage.setItem(`paneworks-sidebar-collapsed:${e}`,t?"1":"0")}catch{}}};z=function(e,t,n,a){var s,i=arguments.length,r=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(i<3?s(r):i>3?s(t,n,r):s(t,n))||r);return i>3&&r&&Object.defineProperty(t,n,r),r}([(0,l.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[h.AppService,h.ProfilesService,$,C,h.TabsService,h.TabRecoveryService])],z);const L="__new__";let M=class extends h.ToolbarButtonProvider{constructor(e,t,n){super(),this.workspaceService=e,this.app=t,this.layout=n,this.waitForTabbyReady().then(()=>{this.workspaceService.cleanupOrphanedProfiles(),this.launchStartupWorkspaces()})}waitForTabbyReady(){return new Promise(e=>{let t=-1;const n=()=>{const a=this.app.tabs.length;a===t?e():(t=a,setTimeout(n,300))};setTimeout(n,500)})}async launchStartupWorkspaces(){for(const e of this.workspaceService.getWorkspaces().filter(e=>e.launchOnStartup))this.layout.findOpenTab(e.id)?console.log(`[${w}] Workspace "${e.name}" already open, skipping`):await this.layout.openWorkspace(e.id)}provide(){return[{icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <rect x="3" y="3" width="7" height="7"/>\n <rect x="14" y="3" width="7" height="7"/>\n <rect x="14" y="14" width="7" height="7"/>\n <rect x="3" y="14" width="7" height="7"/>\n</svg>',title:w,weight:5,click:()=>this.showWorkspaceSelector()}]}async showWorkspaceSelector(){const e=this.workspaceService.getWorkspaces().map(e=>({name:e.name,description:`${e.panes.length} panes${this.layout.findOpenTab(e.id)?" · open":""}`,icon:e.icon||"columns",color:e.color,result:e.id}));e.push({name:"New workspace",description:"Create a workspace with one pane; set it up in its sidebar",icon:"plus",color:void 0,result:L});const t=await this.app.showSelector(w,e);t===L?await this.layout.createWorkspace():t&&await this.layout.openWorkspace(t)}};M=function(e,t,n,a){var s,i=arguments.length,r=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(i<3?s(r):i>3?s(t,n,r):s(t,n))||r);return i>3&&r&&Object.defineProperty(t,n,r),r}([(0,l.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[C,h.AppService,z])],M);let D=class{};D=function(e,t,n,a){var s,i=arguments.length,r=i<3?t:null===a?a=Object.getOwnPropertyDescriptor(t,n):a;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,n,a);else for(var o=e.length-1;o>=0;o--)(s=e[o])&&(r=(i<3?s(r):i>3?s(t,n,r):s(t,n))||r);return i>3&&r&&Object.defineProperty(t,n,r),r}([(0,l.NgModule)({imports:[d.CommonModule],providers:[{provide:h.ConfigProvider,useClass:f,multi:!0},{provide:h.ToolbarButtonProvider,useClass:M,multi:!0},C,$,z]})],D);const N=D;return c})());
|
|
2
|
+
!function(e,t){if("object"==typeof exports&&"object"==typeof module)module.exports=t(require("@angular/common"),require("@angular/core"),require("fs"),require("path"),require("rxjs"),require("rxjs/operators"),require("tabby-core"),require("tabby-terminal"));else if("function"==typeof define&&define.amd)define(["@angular/common","@angular/core","fs","path","rxjs","rxjs/operators","tabby-core","tabby-terminal"],t);else{var n="object"==typeof exports?t(require("@angular/common"),require("@angular/core"),require("fs"),require("path"),require("rxjs"),require("rxjs/operators"),require("tabby-core"),require("tabby-terminal")):t(e["@angular/common"],e["@angular/core"],e.fs,e.path,e.rxjs,e["rxjs/operators"],e["tabby-core"],e["tabby-terminal"]);for(var i in n)("object"==typeof exports?exports:e)[i]=n[i]}}(global,(e,t,n,i,s,a,o,r)=>(()=>{"use strict";var p={358(t){t.exports=e},860(e){e.exports=t},947(e){e.exports=n},911(e){e.exports=i},961(e){e.exports=s},439(e){e.exports=a},650(e){e.exports=o},349(e){e.exports=r}};const d={};function c(e){const t=d[e];if(void 0!==t)return t.exports;const n=d[e]={exports:{}};return p[e](n,n.exports,c),n.exports}c.d=(e,t)=>{for(var n in t)c.o(t,n)&&!c.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},c.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),c.r=e=>{Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};let l={};c.r(l),c.d(l,{WorkspaceEditorService:()=>N,default:()=>Z});var h=c(860),w=c(358),f=c(650);const u="paneworks",m="Paneworks";const g=`${u}-open-menu`;let b=class extends f.HotkeyProvider{async provide(){return[{id:g,name:`${m}: open menu`}]}};b=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)()],b);let k=class extends f.ConfigProvider{constructor(){super(...arguments),this.defaults={[u]:{workspaces:[]},hotkeys:{[g]:["F1"]}}}};k=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)()],k);const v=require("child_process");var y=c(947);const x=require("os");var P=c(911),C=c(961);function S(e){return"children"in e}function I(e){return e.children.flatMap(e=>S(e)?I(e):[e.paneId])}function T(e,t,n,i,s){if(e<=0)return[];const a=Math.max(1,Math.floor(t/Math.max(1,i))),o=Math.max(1,Math.floor(n/Math.max(1,s))),r=Math.min(e,a*o);let p=null;for(let e=1;e<=Math.min(r,o);e++){const o=Math.ceil(r/e);if(o>a)continue;const d=Math.min(t/o/i,n/e/s);(!p||d>p.score+1e-9)&&(p={rows:e,score:d})}const d=p?.rows??1,c=Math.floor(r/d),l=r%d;return Array.from({length:d},(e,t)=>c+(t<l?1:0))}function W(e,t){let n=0;const i=t.map(t=>{const i=e.slice(n,n+t);return n+=t,1===i.length?{paneId:i[0]}:{orientation:"horizontal",ratios:i.map(()=>1/i.length),children:i.map(e=>({paneId:e}))}});return 1===i.length&&S(i[0])?i[0]:{orientation:"vertical",ratios:i.map(()=>1/i.length),children:i}}function $(e){if(Array.isArray(e.panes)||(e.panes=[]),e.panes=e.panes.filter(e=>e&&"object"==typeof e),Array.isArray(e.views)){e.views=e.views.filter(e=>e&&"object"==typeof e);for(const t of e.views){const e=t.hidden;"string"==typeof e?t.hidden=[e]:void 0===e||Array.isArray(e)||delete t.hidden}}if(Array.isArray(e.views)&&e.views.length){const t=e.panes.filter(e=>e.hidden).map(e=>e.id),n=e.views[0];if(t.length){const e=Array.isArray(n.hidden)?n.hidden:[];n.hidden=[...e,...t.filter(t=>!e.includes(t))]}}if(!Array.isArray(e.views)||!e.views.length){const t=e.panes.filter(e=>e.hidden).map(e=>e.id);e.views=[{id:`${e.id}-default`,name:"Default",...t.length?{hidden:t}:{}}]}for(const t of e.panes)"hidden"in t&&delete t.hidden;return e}function O(e){return e.views.find(t=>t.id===e.activeViewId)??e.views[0]}function E(e,t){return!e.hidden?.includes(t)}function A(e,t,n){const i=(e.hidden??[]).filter(e=>e!==t);n||i.push(t),i.length?e.hidden=i:delete e.hidden}function j(e="Default"){return{id:M(),name:e}}const V="paneworks:";function F(e){if("string"!=typeof e||!e.startsWith(V))return null;const[t,n]=e.slice(10).split(":");return t&&n?{workspaceId:t,paneId:n}:null}function R(e,t){const n=(e??"").trim(),i=(t??"").trim();return n?!i||i===n||i.startsWith(`${n} · `)?n:`${n} · ${i}`:i}function z(){return{id:M(),profileId:"",cwd:"",startupCommand:""}}const L=["columns","terminal","code","folder","home","briefcase","cog","database","server","cloud","rocket","flask","bug","wrench","cube","layer-group","sitemap","project-diagram"];function M(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,e=>{const t=16*Math.random()|0;return("x"===e?t:3&t|8).toString(16)})}function D(e){if(null===e||"object"!=typeof e)return e;if(Array.isArray(e))return e.map(e=>D(e));const t={};for(const n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=D(e[n]));return t}let N=class{constructor(e,t,n,i){this.config=e,this.notifications=t,this.profilesService=n,this.platform=i,this.cachedProfiles=null,this.cacheTimestamp=0,this.CACHE_TTL=3e4,this.configFiles=new Map,this.workspaceEdited$=new C.Subject}async getCachedProfiles(){const e=Date.now();return(!this.cachedProfiles||e-this.cacheTimestamp>this.CACHE_TTL)&&(this.cachedProfiles=await this.profilesService.getProfiles(),this.cacheTimestamp=e),this.cachedProfiles}getWorkspaces(){const e=this.config.store?.[u]?.workspaces??[];for(const t of e)Array.isArray(t.panes)&&Array.isArray(t.views)&&t.views.length&&!t.panes.some(e=>!e||"hidden"in e)&&!t.views.some(e=>!e||"object"!=typeof e||void 0!==e.hidden&&!Array.isArray(e.hidden))||$(t);return e}async saveWorkspaceQuietly(e){const t=this.getWorkspaces(),n=t.findIndex(t=>t.id===e.id);-1!==n&&(t[n]=e,await this.saveWorkspaces(t),this.writeConfigFile(e))}minPaneSize(e){return{width:e.minPaneWidth||600,height:e.minPaneHeight||260}}planViewAll(e,t,n){const i=O(e),s=e.panes.filter(e=>E(i,e.id)).map(e=>e.id),a=this.minPaneSize(e),o=T(s.length,t,n,a.width,a.height),r=o.reduce((e,t)=>e+t,0),p=s.slice(0,r);return{tree:p.length?W(p,o):null,shown:p}}allPanesLayout(e,t,n){const i=e.panes.map(e=>e.id);if(!i.length)return null;const s=Math.max(1,t??window.innerWidth-210),a=Math.max(1,n??window.innerHeight-80);return W(i,T(i.length,s,a,1,1))}initialLayout(e){return this.allPanesLayout(e)}async saveWorkspaces(e){if(!this.config.store?.[u])throw new Error("Config store not initialized");this.config.store[u].workspaces=e,await this.saveConfig()}async addWorkspace(e){try{const t=this.getWorkspaces();t.push(e),await this.saveWorkspaces(t),this.notifications.info(`Workspace "${e.name}" created`)}catch(t){throw this.notifications.error(`Failed to create workspace "${e.name}"`),t}}async deleteWorkspace(e){const t=this.getWorkspaces(),n=t.find(t=>t.id===e);try{const i=t.filter(t=>t.id!==e);await this.saveWorkspaces(i),this.closeConfigFile(e),n&&this.notifications.info(`Workspace "${n.name}" deleted`)}catch(t){throw this.notifications.error(`Failed to delete workspace "${n?.name||e}"`),t}}async getAvailableProfiles(){return(await this.profilesService.getProfiles()).filter(e=>!e.id?.startsWith("split-layout:"))}cleanupOrphanedProfiles(){if(!this.config.store?.profiles)return;const e=this.config.store.profiles,t=`split-layout:${u}:`,n=e.filter(e=>!e.id?.startsWith(t));n.length!==e.length&&(this.config.store.profiles=n,this.config.save(),console.log(`[${m}] Cleaned up ${e.length-n.length} orphaned profiles`))}async generateTabbyProfile(e){await this.getCachedProfiles();const t=this.initialLayout(e);if(!t)return null;const n=this.sanitizeForProfileId(e.name);return{id:`split-layout:${u}:${n}:${e.id}`,type:"split-layout",name:e.name,group:m,icon:e.icon,color:e.color,isBuiltin:!1,options:{recoveryToken:this.generateRecoveryToken(t,e)}}}async createPaneToken(e,t){return await this.getCachedProfiles(),this.generatePaneToken(t,e.name,e.id)}generateRecoveryToken(e,t){return{type:"app:split-tab",orientation:"horizontal"===e.orientation?"h":"v",ratios:[...e.ratios],paneworksWorkspaceId:t.id,tabTitle:t.name,disableDynamicTitle:!0,children:e.children.map(e=>{if(S(e))return this.generateRecoveryToken(e,t);const n=t.panes.find(t=>t.id===e.paneId);return this.generatePaneToken(n,t.name,t.id)})}}generatePaneToken(e,t,n){const i=this.getProfileById(e.profileId),s=function(e,t){return`${V}${e}:${t}`}(n,e.id),a=R(e.name,"");if(!i)return{type:"app:local-tab",profile:{type:"local",name:"Shell",group:s},savedState:!1,tabTitle:e.name||"Shell",tabCustomTitle:a,paneworksWorkspaceId:n,disableDynamicTitle:!1};if(!this.isLocalProfile(i))return{type:`app:${i.type}-tab`,profile:{...i,group:s,disableDynamicTitle:!1},savedState:!1,tabTitle:e.name||i.name,tabCustomTitle:a,paneworksWorkspaceId:n,disableDynamicTitle:!1};const o=e.cwd||i.options?.cwd||"",r=this.isWslProfile(i),p=i.options?.args||[],d={restoreFromPTYID:!1,command:i.options?.command||"",args:r&&o?[...p,"--cd",o]:p,cwd:r?"":o,env:i.options?.env||{},width:null,height:null,pauseAfterExit:!1,runAsAdministrator:!1};return{type:"app:local-tab",profile:{id:i.id,type:"local",name:i.name||"Shell",group:s,options:d,icon:i.icon||"",color:i.color||"",disableDynamicTitle:!1,weight:0,isBuiltin:!1,isTemplate:!1,terminalColorScheme:null,behaviorOnSessionEnd:"auto"},savedState:!1,tabTitle:e.name||i.name||"Shell",tabCustomTitle:a,paneworksWorkspaceId:n,disableDynamicTitle:!1,cwd:r?"":o}}sanitizeForProfileId(e){return e.toLowerCase().replace(/[^a-z0-9-]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"")||"workspace"}isLocalProfile(e){return"local"===e.type||e.type?.startsWith("local:")||!1}projectFolder(e){const t=e.panes.find(e=>e.cwd?.trim());let n=e.folder?.trim()||t?.cwd?.trim();if(!n)return null;const i="win32"===process.platform&&(n.startsWith("/")||"~"===n||n.startsWith("~/"));if(i||"~"!==n&&!n.startsWith("~/")||(n=x.homedir()+n.slice(1)),!i)return{path:n,wsl:i,distro:null};const s=t?[t,...e.panes]:e.panes;for(const e of s){const t=this.getProfileById(e.profileId);if(t&&this.isWslProfile(t))return{path:n,wsl:i,distro:this.wslDistro(t)}}return{path:n,wsl:i,distro:null}}async openInVsCode(e){await this.getCachedProfiles();const t=this.projectFolder(e);if(t)if(t.wsl){const e=t.path.startsWith("~/");this.spawnCode("wsl.exe",[...t.distro?["-d",t.distro]:[],"--cd",e?"~":t.path,"code",e?t.path.slice(2):"."])}else this.spawnCode("code",[t.path]);else this.notifications.info("No project folder: set one in the workspace menu, or a folder on a pane")}copyProjectFolder(e){const t=this.projectFolder(e);t?(this.platform.setClipboard({text:t.path}),this.notifications.info(`Copied ${t.path}`)):this.notifications.info("No project folder: set one in the workspace menu, or a folder on a pane")}openConfigInVsCode(e){const t=this.writeConfigFile(e,!0);t&&this.spawnCode("code",[t])}copyConfigFilePath(e){const t=this.writeConfigFile(e,!0);t&&(this.platform.setClipboard({text:t}),this.notifications.info(`Copied ${t}`))}configFilePath(e){const t=this.platform.getConfigPath(),n=P.join(t?P.dirname(t):x.tmpdir(),"paneworks"),i=`-${e.id.replace(/[^A-Za-z0-9_-]/g,"_")}.json`;try{const e=y.readdirSync(n).find(e=>e.endsWith(i));if(e)return P.join(n,e)}catch{}const s=e.name.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-|-$/g,"")||"workspace";return P.join(n,s+i)}writeConfigFile(e,t=!1){let n=this.configFiles.get(e.id);if(!n&&!t)return null;const i=JSON.stringify(e,null,2)+"\n";try{if(!n){const t=this.configFilePath(e);y.mkdirSync(P.dirname(t),{recursive:!0}),n={file:t,written:""},this.configFiles.set(e.id,n);const i=n;y.watchFile(t,{interval:700},()=>this.configFileChanged(e.id,i))}if(t)n.invalid=!1;else{let t=null;try{t=y.readFileSync(n.file,"utf8")}catch{}if(null!==t&&t!==n.written&&t.trim())return this.configFileChanged(e.id,n),n.file}return i===n.written||n.invalid||(y.writeFileSync(n.file,i),n.written=i),n.file}catch(e){return console.error(`[${m}] Could not write the workspace file:`,e),this.notifications.error(`Could not write the workspace file: ${e}`),null}}closeConfigFile(e){const t=this.configFiles.get(e);t&&(y.unwatchFile(t.file),this.configFiles.delete(e))}async configFileChanged(e,t){let n;try{n=y.readFileSync(t.file,"utf8")}catch{return}if(n===t.written||!n.trim())return;t.written=n;const i=this.getWorkspaces(),s=i.findIndex(t=>t.id===e);if(-1===s)return void this.closeConfigFile(e);let a;try{a=this.parseWorkspace(n,i[s])}catch(e){return t.invalid?this.notifications.error(`${i[s].name}: not applied, ${e.message}`):this.notifications.error(`${i[s].name}: not applied, ${e.message}. Until the file is valid, sidebar changes are not written to it; "Edit settings in VS Code" starts it over.`),void(t.invalid=!0)}t.invalid=!1;const o=i[s],r=D(o);for(const e of Object.keys(o))delete o[e];Object.assign(o,a),await this.saveWorkspaces(i),this.writeConfigFile(o),this.notifications.info(`${o.name}: settings applied from the file`),this.workspaceEdited$.next({workspaceId:e,before:r})}parseWorkspace(e,t){let n;try{n=JSON.parse(e)}catch(e){throw new Error(`invalid JSON (${e.message})`)}if(!n||"object"!=typeof n||Array.isArray(n))throw new Error("the file must hold one JSON object");if(!Array.isArray(n.panes)||!n.panes.length)throw new Error('"panes" must be a list with at least one pane');for(const e of n.panes){if(!e||"object"!=typeof e)throw new Error("every pane must be an object");if("string"==typeof e.id&&e.id||(e.id=M()),"string"!=typeof e.profileId)throw new Error(`pane ${e.name??e.id}: "profileId" must be a string`);for(const t of["name","cwd","startupCommand","color"])if(null===e[t]&&delete e[t],void 0!==e[t]&&"string"!=typeof e[t])throw new Error(`pane ${e.id}: "${t}" must be a string`)}for(const e of["name","folder","color","icon","activeViewId"])if(null===n[e]&&delete n[e],void 0!==n[e]&&"string"!=typeof n[e])throw new Error(`"${e}" must be a string`);for(const e of["minPaneWidth","minPaneHeight"])if(null===n[e]&&delete n[e],!(void 0===n[e]||"number"==typeof n[e]&&n[e]>0))throw new Error(`"${e}" must be a number above 0`);if(void 0!==n.launchOnStartup&&"boolean"!=typeof n.launchOnStartup)throw new Error('"launchOnStartup" must be true or false');const i=n.panes.map(e=>e.id);if(new Set(i).size!==i.length)throw new Error("two panes have the same id");if(void 0!==n.views){if(!Array.isArray(n.views))throw new Error('"views" must be a list');const e=new Set;for(const t of n.views){if(!t||"object"!=typeof t)throw new Error("every view must be an object");if("string"==typeof t.id&&t.id&&!e.has(t.id)||(t.id=M()),e.add(t.id),"string"!=typeof t.name||!t.name.trim())throw new Error('every view needs a "name"');if(void 0!==t.hidden&&!Array.isArray(t.hidden))throw new Error(`view ${t.name}: "hidden" must be a list of pane ids`);if(t.hidden){if(t.hidden.some(e=>"string"!=typeof e))throw new Error(`view ${t.name}: "hidden" must be a list of pane ids`);t.hidden=t.hidden.filter(e=>i.includes(e)),t.hidden.length||delete t.hidden}}}return n.id=t.id,"string"==typeof n.name&&n.name.trim()||(n.name=t.name),$(D(n))}spawnCode(e,t){let n=e,i=t,s={detached:!0,stdio:"ignore",windowsHide:!0};if("win32"===process.platform&&"code"===e){if(t.some(e=>/["%\r\n]/.test(e)))return void this.notifications.error('This path has characters that cannot be passed to VS Code safely: " or %');n=process.env.ComSpec||"cmd.exe",i=["/d","/v:off","/s","/c",`"code ${t.map(e=>`"${e.replace(/(\\+)$/,"$1$1")}"`).join(" ")}"`],s={...s,windowsVerbatimArguments:!0}}try{const a=(0,v.spawn)(n,i,s);a.on("error",n=>{if("ENOENT"===n.code&&"win32"!==process.platform&&"code"===e){const e=process.env.SHELL??"",n=/\/(ba|z|k|da)?sh$/.test(e)?e:"/bin/sh",i=(0,v.spawn)(n,["-lc",'exec code "$@"',"code",...t],s);return i.on("error",()=>this.vsCodeFailed()),i.on("exit",e=>{e&&this.vsCodeFailed()}),void i.unref()}this.vsCodeFailed()}),a.on("exit",e=>{e&&this.vsCodeFailed()}),a.unref()}catch{this.vsCodeFailed()}}vsCodeFailed(){this.notifications.error('Could not start VS Code. Is the "code" command on your PATH?')}wslDistro(e){const t=e.options?.args??[],n=t.findIndex(e=>"-d"===e||"--distribution"===e);return n>=0&&t[n+1]?t[n+1]:null}isWslProfile(e){if(e.id?.startsWith("local:wsl"))return!0;const t=(e.options?.command||"").toLowerCase();return"wsl.exe"===t||"wsl"===t||t.endsWith("\\wsl.exe")||t.endsWith("/wsl.exe")}getProfileById(e){return(this.config.store?.profiles??[]).find(t=>t.id===e)||this.cachedProfiles?.find(t=>t.id===e)}collectStartupCommands(e){return e.panes.filter(e=>e.startupCommand).map(e=>({paneId:e.id,command:e.startupCommand}))}getWorkspace(e){return this.getWorkspaces().find(t=>t.id===e)}async saveConfig(){try{await this.config.save()}catch(e){throw console.error(`[${m}] Save error:`,e),e}}};N=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)({providedIn:"root"}),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[f.ConfigService,f.NotificationsService,f.ProfilesService,f.PlatformService])],N);var H=c(349),q=c(439);const B=[0,300,1e3,3e3,8e3];let _=class{constructor(e,t){this.app=e,this.workspaces=t,this.workspaceSplitFound$=new C.Subject,this.pendingCommands=new Map,this.watchedSplits=new WeakSet,this.attachedPanes=new WeakSet,this.app.tabOpened$.subscribe(e=>this.onTabOpened(e))}registerCommands(e){for(const t of e)this.pendingCommands.set(t.paneId,t)}onTabOpened(e){e instanceof f.SplitTabComponent?this.watchSplit(e):e instanceof H.BaseTerminalTabComponent&&this.processPane(e,null)}watchSplit(e){if(this.watchedSplits.has(e))return;this.watchedSplits.add(e);const t=()=>this.scanSplit(e);e.initialized$?.subscribe({complete:t}),e.tabAdded$?.subscribe(()=>t());for(const e of B)setTimeout(t,e)}scanSplit(e){for(const t of e.getAllTabs())t instanceof H.BaseTerminalTabComponent&&this.processPane(t,e)}processPane(e,t){const n=F(e.profile?.group);n&&(t&&(this.pinSplitTitle(t,n.workspaceId),this.workspaceSplitFound$.next({split:t,workspaceId:n.workspaceId})),this.attachedPanes.has(e)||(this.attachedPanes.add(e),this.attachLabelSync(e,n.workspaceId,n.paneId),this.runPendingCommand(e,n.paneId)))}pinSplitTitle(e,t){const n=this.workspaces.getWorkspace(t)?.name;e.disableDynamicTitle=!0,n&&e.title!==n&&e.setTitle(n)}attachLabelSync(e,t,n){const i=e;i.disableDynamicTitle=!1;let s=e.customTitle,a=!0;const o=()=>{if(!a)return;if(e.customTitle!==s)return void(a=!1);const o=this.workspaces.getWorkspace(t),r=o?function(e,t){return e.panes.find(e=>e.id===t)}(o,n)?.name:void 0,p=R(r,e.title);p&&p!==e.customTitle&&(s=p,"function"==typeof i.setCustomTitle?i.setCustomTitle(p):e.customTitle=p)},r=e.setTitle.bind(e);e.setTitle=e=>{r(e),o()},o()}runPendingCommand(e,t,n=!1){const i=this.pendingCommands.get(t);if(!i?.command)return;this.pendingCommands.delete(t);const s=i.command,a=()=>{console.log(`[${m}] Sending startup command:`,s),e.sendInput(s+"\r"),this.clearProfileArgs(e)},o=e.sessionChanged$;if(!e.session&&o&&!n)return this.pendingCommands.set(t,i),void o.pipe((0,C.first)(e=>!!e),(0,C.timeout)(5e3),(0,q.catchError)(()=>(0,C.of)(null))).subscribe(()=>this.runPendingCommand(e,t,!0));e.session?.output$?e.session.output$.pipe((0,C.first)(),(0,C.timeout)(2e3),(0,q.catchError)(()=>(0,C.of)(null))).subscribe(()=>setTimeout(a,100)):setTimeout(a,500)}clearProfileArgs(e){const t=e.profile;t?.options?.args&&(t.options.args=[])}};_=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[f.AppService,N])],_);const Q=["#3b82f6","#10b981","#f59e0b","#ef4444","#8b5cf6","#ec4899","#06b6d4","#f97316"];function J(e){const t=e.trim().split(/[\\/]+/).filter(Boolean),n=t[t.length-1]??"";return/^[a-z]:$/i.test(n)||"~"===n?"":n}let G=class{constructor(e,t,n,i,s,a,o){this.app=e,this.profilesService=t,this.runtime=n,this.workspaces=i,this.tabsService=s,this.tabRecovery=a,this.platform=o,this.states=new WeakMap,this.active=new Set,this.resizeTimer=null,this.profiles=[],this.watchedSessions=new WeakSet,this.autofocus=!1,this.runtime.workspaceSplitFound$.subscribe(({split:e,workspaceId:t})=>this.attach(e,t)),this.workspaces.workspaceEdited$.subscribe(({workspaceId:e,before:t})=>this.syncEdited(e,t)),window.addEventListener("resize",()=>{this.resizeTimer&&clearTimeout(this.resizeTimer),this.resizeTimer=setTimeout(()=>this.refreshAllGrids(),250)})}findOpenTab(e){for(const t of this.active)if(t.workspaceId===e)return t.split;for(const t of this.app.tabs)if(t instanceof f.SplitTabComponent&&t.getAllTabs().some(t=>F(t.profile?.group)?.workspaceId===e))return t;return null}async openWorkspace(e){const t=this.findOpenTab(e);if(t)return void this.app.selectTab(t);const n=this.workspaces.getWorkspace(e);if(!n)return;const i=this.workspaces.collectStartupCommands(n);i.length&&this.runtime.registerCommands(i);const s=await this.workspaces.generateTabbyProfile(n);s&&this.profilesService.openNewTabForProfile(s)}async createWorkspace(){await this.loadProfiles();const e=await this.askWorkspaceSetup();if(!e)return;const t=new Set(this.workspaces.getWorkspaces().map(e=>e.name));let n=J(e.folder);if(!n){let e=1;for(;t.has(`Workspace ${e}`);)e++;n=`Workspace ${e}`}let i=n;for(let e=2;t.has(i);e++)i=`${n} ${e}`;const s=function(e=""){return{id:M(),name:e,icon:L[Math.floor(Math.random()*L.length)],panes:[z(),z()],views:[j()],launchOnStartup:!1}}(i);s.panes=Array.from({length:e.panes},()=>({id:z().id,profileId:e.profileId,...e.folder?{cwd:e.folder}:{},...e.command?{startupCommand:e.command}:{}})),e.folder&&(s.folder=e.folder),await this.workspaces.addWorkspace(s),await this.openWorkspace(s.id)}askWorkspaceSetup(){return this.ensureStyles(),new Promise(e=>{const t=this.node("div","paneworks-overlay"),n=this.node("div","paneworks-sidebar pw-dialog"),i=this.node("div","pw-form"),s=document.createElement("select");s.className="pw-input";for(const e of this.profiles){const t=document.createElement("option");t.value=e.id,t.textContent=e.name,s.append(t)}const a=this.profiles.find(e=>"local"===e.type||e.type?.startsWith("local:"))??this.profiles[0];s.value=a?.id??"";const o=this.input("text","","C:\\path or /home/user"),r=this.button("pw-btn","Browse…","Pick a folder",async()=>{try{const e=await this.platform.pickDirectory();e&&(o.value=e),h()}catch{}}),p=this.node("div","pw-folder-row");p.append(o,r);const d=this.input("text","","e.g. claude (optional)"),c=this.input("number","4","4");c.min="1",c.max="16",c.classList.add("pw-size");const l=this.node("div","pw-hint"),h=()=>{const e=J(o.value);l.textContent=e?`Workspace name: ${e}`:"The workspace is named after the folder."};o.addEventListener("input",h),h(),i.append(this.node("div","pw-dialog-title","New workspace"),this.field("Profile",s),this.field("Folder",p),l,this.field("Startup command",d),this.field("Panes",c),this.node("div","pw-hint","Every pane starts with this profile, folder and command. Change single panes later in the sidebar."));const w=n=>{t.remove(),e(n)},f=()=>w({profileId:s.value,folder:o.value.trim(),command:d.value.trim(),panes:Math.min(16,Math.max(1,Math.round(c.value.trim()&&Number.isFinite(Number(c.value))?Number(c.value):4)))});for(const e of[o,d,c])e.addEventListener("keydown",e=>{"Enter"===e.key&&f(),"Escape"===e.key&&w(null)});s.addEventListener("keydown",e=>{e.stopPropagation(),"Escape"===e.key&&w(null)});const u=this.node("div","pw-actions");u.append(this.button("pw-btn primary","Create","Create and open the workspace",f),this.button("pw-btn","Cancel","Close without creating",()=>w(null))),i.append(u),n.append(i),t.append(n),t.addEventListener("mousedown",e=>{e.target===t&&w(null)}),document.body.append(t),setTimeout(()=>o.focus(),0)})}async loadProfiles(){this.profiles.length||(this.profiles=await this.workspaces.getAvailableProfiles())}applyTabColor(e){const t=this.workspaces.getWorkspace(e.workspaceId)?.color||null;t?e.split.color=t:e.appliedColor&&(e.split.color=null),e.appliedColor=t}attach(e,t){const n=this.states.get(e);if(n)return void(n.sidebar?.isConnected||this.mountSidebar(n));const i={split:e,workspaceId:t,view:{kind:"all"},appliedPlan:null,parked:new Map,sidebar:null,collapsed:this.loadCollapsed(t),busy:!1,dragging:!1,editingPaneId:null,editingViewId:null,menuOpen:!1,timer:null,unseen:new Set,starting:!0,syncPending:!1,restartPending:new Set,drafts:new Map,draftOwner:null,appliedColor:null,leftAt:new Map};this.states.set(e,i),this.active.add(i),this.loadProfiles(),this.applyTabColor(i),e.destroyed$.subscribe(()=>{for(const e of i.parked.values())e.destroy();i.parked.clear(),i.timer&&clearInterval(i.timer),i.sidebar?.remove(),this.active.delete(i)}),e.visibility$?.subscribe(e=>{e&&setTimeout(()=>{i.syncPending?this.syncTab(i):this.refreshGrid(i)},50)}),this.mountSidebar(i),i.timer=setInterval(()=>this.render(i),1e3),this.startAllPanes(i)}async showAll(e,t=!1){const n=this.workspaces.getWorkspace(e.workspaceId),i=this.paneArea(e);if(!n||!i)return;const s=this.workspaces.planViewAll(n,i.width,i.height),a=JSON.stringify(s.tree);a!==e.appliedPlan&&console.log(`[${m}] View all:`,{area:i,shown:s.shown.length,min:this.workspaces.minPaneSize(n)});const o="all"===e.view.kind;if(e.view={kind:"all"},!s.tree&&n.panes.length&&(t||!o||"empty"!==e.appliedPlan)){const t=n.panes[0].id;await this.apply(e,n,{orientation:"horizontal",ratios:[1],children:[{paneId:t}]})&&(e.appliedPlan="empty")}!s.tree||!t&&o&&a===e.appliedPlan||await this.apply(e,n,s.tree)&&(e.appliedPlan=a),this.render(e,!0)}async showFocus(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);if(!n)return;const i={orientation:"horizontal",ratios:[1],children:[{paneId:t}]};await this.apply(e,n,i)&&(e.view={kind:"focus",paneId:t},e.appliedPlan=null),this.render(e,!0)}async reapplyView(e){"focus"===e.view.kind?await this.showFocus(e,e.view.paneId):await this.showAll(e,!0)}refreshGrid(e){"all"!==e.view.kind||e.busy||e.starting||this.showAll(e)}async startAllPanes(e){const t=e.view;e.starting=!0;try{const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;const n=await this.waitFor(()=>this.paneArea(e),3e3),i=t.panes.some(t=>!this.livePanes(e).has(t.id)),s=this.workspaces.allPanesLayout(t,n?.width,n?.height);i&&s&&await this.apply(e,t,s),await this.waitFor(()=>{const t=[...this.livePanes(e).values()];return!(!t.length||!t.every(e=>e.session))||null},8e3)}finally{e.starting=!1}"focus"===t.kind?await this.showFocus(e,t.paneId):await this.showAll(e,!0)}async waitFor(e,t){const n=Date.now()+t;for(;;){const t=e();if(t)return t;if(Date.now()>n)return null;await new Promise(e=>setTimeout(e,100))}}refreshAllGrids(){for(const e of this.active)this.refreshGrid(e)}paneArea(e){const t=this.splitElement(e)?.getBoundingClientRect();return t&&t.width>0&&t.height>0?{width:t.width,height:t.height}:null}async apply(e,t,n){if(e.busy)return!1;e.busy=!0;try{const i=e.split,s=new Map(t.panes.map(e=>[e.id,e])),a=this.livePanes(e),o=I(n).filter(e=>s.has(e));for(const e of o)if(!a.has(e)){const n=await this.createPane(t,s.get(e));n&&a.set(e,n)}const r=o.filter(e=>a.has(e));if(!r.length)return!1;for(const t of e.split.getAllTabs()){const n=this.paneIdOf(t);n&&r.includes(n)||(t.removeFromContainer(),i.viewRefs?.delete(t),t.parent=null,n?(e.parked.set(n,t),e.leftAt.set(n,Date.now())):t.destroy())}const p=this.buildContainer(n,a);if(!p)return!1;i.maximizedTab=null,i.root=p;for(const t of r){const n=a.get(t);e.unseen.delete(t),n.clearActivity(),i.viewRefs?.has(n)||(e.parked.delete(t),n.parent=e.split,n.emitVisibility?.(i.visibility?.value??!0),i.attachTabView(n),i.onAfterTabAdded(n))}return i.layout(),e.split.focus(a.get(r[0])),i.recoveryStateChangedHint?.next(),this.nudgeResize(),setTimeout(()=>this.applyLabelColors(e,this.workspaces.getWorkspace(e.workspaceId)),100),!0}catch(e){return console.error(`[${m}] Layout change failed:`,e),!1}finally{e.busy=!1}}buildContainer(e,t){const n=[],i=[];if(e.children.forEach((s,a)=>{const o=S(s)?this.buildContainer(s,t):t.get(s.paneId)??null;o&&(n.push(o),i.push(e.ratios[a]??1))}),!n.length)return null;const s=i.reduce((e,t)=>e+t,0)||1,a=new f.SplitContainer;return a.orientation="horizontal"===e.orientation?"h":"v",a.children=n,a.ratios=i.map(e=>e/s),a}async createPane(e,t){try{const n=await this.workspaces.createPaneToken(e,t),i=await this.tabRecovery.recoverTab(n);return i?(t.startupCommand&&this.runtime.registerCommands([{paneId:t.id,command:t.startupCommand}]),this.tabsService.create(i)):null}catch(e){return console.error(`[${m}] Could not create pane:`,t,e),null}}livePanes(e){const t=new Map;for(const n of e.split.getAllTabs()){const e=this.paneIdOf(n);e&&t.set(e,n)}for(const[n,i]of e.parked)t.set(n,i);return t}paneIdOf(e){return F(e.profile?.group)?.paneId??null}nudgeResize(){setTimeout(()=>window.dispatchEvent(new Event("resize")),50)}async toggleShown(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;const s=O(n);A(s,t,!E(s,t)),await this.workspaces.saveWorkspaceQuietly(n),"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}async duplicatePane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;const s={...i,id:z().id};i.name&&(s.name=`${i.name} copy`),n.panes.splice(n.panes.indexOf(i)+1,0,s);for(const e of n.views)A(e,s.id,E(e,i.id));await this.workspaces.saveWorkspaceQuietly(n),e.editingPaneId=s.id,e.editingViewId=null,this.render(e,!0),await this.startAllPanes(e)}async syncEdited(e,t){const n=this.workspaces.getWorkspace(e),i=new Map(t.panes.map(e=>[e.id,e])),s=(n?.panes??[]).filter(e=>{const t=i.get(e.id);return!!t&&((t.startupCommand??"")!==(e.startupCommand??"")||(t.cwd??"")!==(e.cwd??"")||t.profileId!==e.profileId)}).map(e=>e.id);for(const t of[...this.active])if(t.workspaceId===e){for(const e of s)t.restartPending.add(e);await this.syncTab(t)}}async syncTab(e){await this.waitFor(()=>!e.busy&&!e.starting,1e4);const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;if(!this.paneArea(e))return e.syncPending=!0,e.split.setTitle(t.name),void this.applyTabColor(e);e.syncPending=!1,e.split.setTitle(t.name),this.applyTabColor(e);const n=new Set(t.panes.map(e=>e.id));e.editingPaneId&&!n.has(e.editingPaneId)&&(e.editingPaneId=null),e.editingViewId&&!t.views.some(t=>t.id===e.editingViewId)&&(e.editingViewId=null),"focus"!==e.view.kind||n.has(e.view.paneId)||(e.view={kind:"all"}),await this.reapplyView(e);const i=()=>[...this.livePanes(e)].filter(([e])=>!n.has(e)),s=e.view;i().some(([,t])=>t.parent===e.split)&&await this.showFocus(e,t.panes[0].id);for(const[t,n]of i())n.parent!==e.split&&(e.parked.delete(t),n.destroy());"all"===s.kind&&"focus"===e.view.kind&&await this.showAll(e,!0);for(const t of[...e.restartPending])e.restartPending.delete(t),n.has(t)&&this.livePanes(e).has(t)&&await this.restartPane(e,t);this.render(e,!0),t.panes.some(t=>!this.livePanes(e).has(t.id))&&await this.startAllPanes(e)}async movePane(e,t,n){const i=this.workspaces.getWorkspace(e.workspaceId);if(!i)return;const s=i.panes.findIndex(e=>e.id===t);if(-1===s||t===n)return;const[a]=i.panes.splice(s,1),o=n?i.panes.findIndex(e=>e.id===n):-1;i.panes.splice(-1===o?i.panes.length:o,0,a),await this.workspaces.saveWorkspaceQuietly(i),"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}async addPane(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;await this.loadProfiles();const n=t.panes[t.panes.length-1],i={...z(),profileId:n?.profileId||this.profiles[0]?.id||"",cwd:n?.cwd||""};t.panes.push(i);const s=O(t);for(const e of t.views)e!==s&&A(e,i.id,!1);await this.workspaces.saveWorkspaceQuietly(t),e.editingPaneId=i.id,e.editingViewId=null,e.menuOpen=!1,this.render(e,!0)}async savePane(e,t,n){const i=this.workspaces.getWorkspace(e.workspaceId),s=i?.panes.find(e=>e.id===t);if(i&&s){Object.assign(s,n);for(const e of["name","color"])s[e]||delete s[e];await this.workspaces.saveWorkspaceQuietly(i),e.editingPaneId=null,this.render(e,!0),this.livePanes(e).has(t)||await this.startAllPanes(e)}}async restartPane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;const s=this.livePanes(e).get(t),a=await this.createPane(n,i);a&&(s&&e.parked.get(t)===s?(e.parked.set(t,a),s.destroy()):s&&s.parent===e.split?(a.parent=e.split,e.split.replaceTab(s,a),e.split.viewRefs?.delete(s),s.destroy(),e.split.layout(),e.split.focus(a),this.nudgeResize()):e.parked.set(t,a),this.render(e,!0))}async removePane(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.panes.find(e=>e.id===t);if(!n||!i)return;if(n.panes.length<=1)return void window.alert("A workspace needs at least one pane. Delete the workspace from its menu instead.");const s=i.name||i.startupCommand||"this pane";if(!window.confirm(`Remove "${s}" from ${n.name}? Its terminal is closed.`))return;n.panes=n.panes.filter(e=>e.id!==t);for(const e of n.views)A(e,t,!0);await this.workspaces.saveWorkspaceQuietly(n),e.editingPaneId=null;const a=this.livePanes(e).get(t);a&&a.parent===e.split&&("focus"===e.view.kind&&e.view.paneId===t&&(e.view={kind:"all"}),await this.reapplyView(e));const o=this.livePanes(e).get(t);if(o&&o.parent===e.split&&e.split.getAllTabs().length<=1){const t=n.panes[0];A(O(n),t.id,!0),await this.workspaces.saveWorkspaceQuietly(n),await this.showFocus(e,t.id)}e.parked.delete(t),this.livePanes(e).get(t)?.destroy(),a?.destroy(),this.render(e,!0)}async selectView(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);n&&n.views.some(e=>e.id===t)&&(n.activeViewId!==t&&(n.activeViewId=t,await this.workspaces.saveWorkspaceQuietly(n)),await this.showAll(e,!0))}async addView(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;const n=new Set(t.views.map(e=>e.name));let i=t.views.length+1;for(;n.has(`View ${i}`);)i++;const s=j(`View ${i}`);t.views.push(s),t.activeViewId=s.id,await this.workspaces.saveWorkspaceQuietly(t),e.editingViewId=s.id,e.editingPaneId=null,e.menuOpen=!1,await this.showAll(e,!0)}async renameView(e,t,n){const i=this.workspaces.getWorkspace(e.workspaceId),s=i?.views.find(e=>e.id===t);i&&s&&(s.name=n.trim()||s.name,await this.workspaces.saveWorkspaceQuietly(i),e.editingViewId=null,this.render(e,!0))}async duplicateView(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.views.find(e=>e.id===t);if(!n||!i)return;const s={...j(`${i.name} copy`),...i.hidden?.length?{hidden:[...i.hidden]}:{}};n.views.splice(n.views.indexOf(i)+1,0,s),n.activeViewId=s.id,await this.workspaces.saveWorkspaceQuietly(n),e.editingViewId=s.id,await this.showAll(e,!0)}async deleteView(e,t){const n=this.workspaces.getWorkspace(e.workspaceId),i=n?.views.find(e=>e.id===t);if(!n||!i)return;if(n.views.length<=1)return void window.alert("A workspace needs at least one view.");if(!window.confirm(`Delete the view "${i.name}"? Its panes keep running.`))return;const s=O(n)===i;n.views=n.views.filter(e=>e!==i),s&&(n.activeViewId=n.views[0].id),await this.workspaces.saveWorkspaceQuietly(n),e.editingViewId=null,s&&"all"===e.view.kind?await this.showAll(e,!0):this.render(e,!0)}async saveWorkspaceSettings(e,t){const n=this.workspaces.getWorkspace(e.workspaceId);if(n){n.name=t.name.trim()||n.name;for(const e of["minPaneWidth","minPaneHeight"]){const i=t[e];i&&i>0?n[e]=Math.round(i):delete n[e]}t.launchOnStartup?n.launchOnStartup=!0:n.launchOnStartup=!1,t.color?n.color=t.color:delete n.color,t.folder.trim()?n.folder=t.folder.trim():delete n.folder,await this.workspaces.saveWorkspaceQuietly(n),e.split.setTitle(n.name),this.applyTabColor(e),e.menuOpen=!1,"all"===e.view.kind?await this.showAll(e):this.render(e,!0)}}async deleteWorkspace(e){const t=this.workspaces.getWorkspace(e.workspaceId);if(!t)return;if(!window.confirm(`Delete the workspace "${t.name}"? Its tab and all its panes are closed.`))return;await this.workspaces.deleteWorkspace(t.id);const n=this.app;"function"==typeof n.closeTab?n.closeTab(e.split,!1):e.split.destroy()}splitElement(e){const t=e.split;for(const e of[t.hostView,t.viewContainerEmbeddedRef]){const t=e?.rootNodes?.[0];if(t instanceof HTMLElement)return t}return null}mountSidebar(e){const t=this.splitElement(e),n=t?.parentElement;t&&n?(e.sidebar||(e.sidebar=document.createElement("div"),e.sidebar.className="paneworks-sidebar",this.ensureStyles()),n.insertBefore(e.sidebar,t),t.setAttribute("data-paneworks",""),this.render(e,!0),this.nudgeResize(),setTimeout(()=>this.refreshGrid(e),100)):setTimeout(()=>{!e.sidebar?.isConnected&&this.active.has(e)&&this.mountSidebar(e)},500)}applyLabelColors(e,t){const n=this.splitElement(e);if(!n||!t)return;const i=new Map(t.panes.map(e=>[e.id,e.color])),s=Array.from(n.querySelectorAll(":scope > split-tab-pane-label")),a=e.split.getAllTabs();s.forEach((e,t)=>{const n=e.querySelector(".custom-name");if(!n)return;const s=a[t]?this.paneIdOf(a[t]):null,o=s?i.get(s):void 0;o?(n.style.background=o,n.style.color=function(e){const t=e.replace("#","");if(!/^[0-9a-f]{6}$/i.test(t))return"#fff";const[n,i,s]=[0,2,4].map(e=>parseInt(t.slice(e,e+2),16)/255).map(e=>e<=.03928?e/12.92:Math.pow((e+.055)/1.055,2.4));return.2126*n+.7152*i+.0722*s>.4?"#000":"#fff"}(o)):(n.style.removeProperty("background"),n.style.removeProperty("color"))})}watchOutput(e){for(const[t,n]of this.livePanes(e)){const i=n.session;i?.output$&&!this.watchedSessions.has(i)&&(this.watchedSessions.add(i),i.output$.subscribe(()=>{n.parent===e.split||e.unseen.has(t)||Date.now()-(e.leftAt.get(t)??0)<2500||e.unseen.add(t)}))}}render(e,t=!1){const n=e.sidebar;if(!n||!n.isConnected||e.dragging)return;if(this.watchOutput(e),this.applyLabelColors(e,this.workspaces.getWorkspace(e.workspaceId)),!t&&(e.editingPaneId||e.editingViewId||e.menuOpen))return;const i=this.workspaces.getWorkspace(e.workspaceId),s=this.livePanes(e),a=new Set(e.split.getAllTabs().map(e=>this.paneIdOf(e))),o=JSON.stringify([e.collapsed,e.view,e.editingPaneId,e.editingViewId,e.menuOpen,i,i?.panes.map(t=>{const n=s.get(t.id);return[n?.customTitle,n?.title,e.unseen.has(t.id),a.has(t.id)]})]);if(!t&&n.__pwSignature===o)return;n.__pwSignature=o;const r=e.editingPaneId?`p:${e.editingPaneId}`:e.editingViewId?`v:${e.editingViewId}`:e.menuOpen?"m":null,p=r!==e.draftOwner;p&&(e.drafts.clear(),e.draftOwner=r);const d=document.activeElement,c=d&&n.contains(d)?d.dataset?.draft??null:null,l=c&&"number"==typeof d.selectionStart?[d.selectionStart,d.selectionEnd]:null;this.autofocus=p,n.classList.toggle("collapsed",e.collapsed),n.style.flex=`0 0 ${e.collapsed?22:210}px`,n.textContent="";const h=this.button("pw-icon-btn pw-toggle",e.collapsed?"»":"«",e.collapsed?"Show sidebar":"Hide sidebar",()=>{e.collapsed=!e.collapsed,this.saveCollapsed(e.workspaceId,e.collapsed),this.render(e,!0),this.nudgeResize()});if(e.collapsed||!i)return void n.append(h);const w=this.node("div","pw-header"),f=this.button("pw-ws","","Workspace menu",()=>{e.menuOpen=!e.menuOpen,e.editingPaneId=null,e.editingViewId=null,this.render(e,!0)});f.append(this.node("span","pw-ws-name",i.name),this.node("span","pw-caret",e.menuOpen?"▴":"▾"));const u=this.workspaces.projectFolder(i),m=this.button("pw-icon-btn pw-code","",u?`Open ${u.path} in VS Code`:"Open in VS Code (no project folder yet: set one in the workspace menu)",()=>this.workspaces.openInVsCode(i));m.innerHTML='<svg viewBox="0 0 24 24" width="14" height="14" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <polyline points="16 18 22 12 16 6"/><polyline points="8 6 2 12 8 18"/>\n</svg>';const g=this.button("pw-icon-btn pw-code","",u?`Copy ${u.path}`:"Copy the project folder path (no project folder yet: set one in the workspace menu)",()=>this.workspaces.copyProjectFolder(i));g.innerHTML='<svg viewBox="0 0 24 24" width="13" height="13" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <rect x="9" y="9" width="12" height="12" rx="2"/><path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"/>\n</svg>',w.append(f,g,m,h),n.append(w),e.menuOpen&&n.append(this.workspaceMenu(e,i));const b=O(i),k=this.node("div","pw-section");k.append(this.node("span","","Views"),this.button("pw-icon-btn pw-add","+","Add a view (all panes on)",()=>this.addView(e))),n.append(k);for(const t of i.views)n.append(this.viewRow(e,i,t,t===b,a)),e.editingViewId===t.id&&n.append(this.viewEditor(e,i,t));i.panes.some(e=>E(b,e.id))||n.append(this.node("div","pw-hint pw-empty-view",`Nothing is switched on in "${b.name}": switch panes on below.`));const v=this.node("div","pw-section");v.append(this.node("span","pw-section-title",`Panes · ${b.name}`),this.button("pw-icon-btn pw-add","+","Add a pane",()=>this.addPane(e))),n.append(v);const y="focus"===e.view.kind?e.view.paneId:null,x=this.node("div","pw-list");for(const t of i.panes)x.append(this.paneRow(e,t,s.get(t.id),a.has(t.id),y,E(b,t.id),b.name)),e.editingPaneId===t.id&&x.append(this.paneEditor(e,t));const P=this.node("div","pw-drop-end");if(this.makeDropTarget(e,P,null),x.append(P),n.append(x),c){const e=n.querySelector(`[data-draft="${c}"]`);if(e&&(e.focus(),l))try{e.setSelectionRange(l[0],l[1])}catch{}}}draft(e,t,n){n.dataset.draft=t;const i=n instanceof HTMLInputElement&&"checkbox"===n.type,s=e.drafts.get(t);void 0!==s&&(i?n.checked="1"===s:n.value=s);const a=()=>e.drafts.set(t,i?n.checked?"1":"0":n.value);return n.addEventListener("input",a),n.addEventListener("change",a),n}draftColor(e,t,n){return this.colorPicker(e.drafts.get(t)??n,n=>e.drafts.set(t,n))}paneRow(e,t,n,i,s,a,o){const r=(n?n.customTitle||n.title:"")||t.name||t.startupCommand||"New pane",p=[t.name,t.startupCommand].filter(Boolean).join(" · "),d=a&&!i&&"all"===e.view.kind,c=!i&&e.unseen.has(t.id),l=["pw-row","pw-pane"];i&&l.push("onscreen"),t.id===s&&l.push("focused"),a||l.push("off"),e.editingPaneId===t.id&&l.push("editing");const h=this.node("div",l.join(" "));h.title=[i?"On screen":n?"Running, not on screen":"Not running (shown again by a view or its title)",a?d?"switched on, but no room at the minimum pane size":"":`switched off in "${o}"`].filter(Boolean).join(" · "),h.draggable=!0,h.append(this.node("span","pw-handle","⋮⋮")),h.addEventListener("dragstart",n=>{e.dragging=!0,n.dataTransfer?.setData("text/plain",t.id),n.dataTransfer&&(n.dataTransfer.effectAllowed="move"),h.classList.add("dragging")}),h.addEventListener("dragend",()=>{e.dragging=!1,h.classList.remove("dragging"),this.render(e,!0)}),this.makeDropTarget(e,h,t.id);const w=this.node("span","pw-pane-color"+(t.color?"":" none"));t.color&&(w.style.background=t.color),w.title=t.color?`Label colour ${t.color}`:"No label colour",h.append(w);const f=this.node("span","pw-text"),u=this.node("span","pw-main");if(u.append(this.node("span","pw-name",r)),c){const e=this.node("span","pw-news","new");e.title="New output since it left the screen",u.append(e)}f.append(u),(p||d)&&f.append(this.node("span","pw-sub",[p,d?"no room":""].filter(Boolean).join(" · "))),f.onclick=()=>{t.id===s?this.showAll(e,!0):this.showFocus(e,t.id)},f.title=t.id===s?`Back to "${o}"`:"Show this pane alone";const m=this.node("label","pw-switch");m.title=a?`On: shown in "${o}"`:`Off: not in "${o}"`;const g=document.createElement("input");g.type="checkbox",g.checked=a,g.onchange=()=>this.toggleShown(e,t.id),m.append(g,this.node("span","pw-slider")),m.addEventListener("click",e=>e.stopPropagation());const b=this.button("pw-icon-btn pw-more","⋯","Edit pane",()=>{e.editingPaneId=e.editingPaneId===t.id?null:t.id,e.editingViewId=null,e.menuOpen=!1,this.render(e,!0)});return h.append(f,m,b),h}viewRow(e,t,n,i,s){const a=t.panes.filter(e=>E(n,e.id)),o=i&&"all"===e.view.kind,r=a.filter(e=>s.has(e.id)).length,p=["pw-row","pw-all","pw-view"];o?p.push("active"):i&&p.push("selected"),e.editingViewId===n.id&&p.push("editing");const d=this.node("div",p.join(" "));return d.append(this.node("span","pw-main",n.name),this.node("span","pw-count",o?`${r} / ${a.length}`:`${a.length} on`),this.button("pw-icon-btn pw-more","⋯","Edit view",()=>{e.editingViewId=e.editingViewId===n.id?null:n.id,e.editingPaneId=null,e.menuOpen=!1,this.render(e,!0)})),d.title=i?"Selected view: the pane switches below belong to it. Click to show its panes in a grid":"Select this view and show its switched-on panes in a grid",d.onclick=()=>this.selectView(e,n.id),d}viewEditor(e,t,n){const i=this.node("div","pw-form"),s=this.draft(e,"name",this.input("text",n.name,"View name"));i.append(this.field("Name",s),this.node("div","pw-hint","Select the view, then use the pane switches to choose what it shows."));const a=()=>this.renameView(e,n.id,s.value);s.addEventListener("keydown",t=>{"Enter"===t.key&&a(),"Escape"===t.key&&(e.editingViewId=null,this.render(e,!0))});const o=this.node("div","pw-actions");return o.append(this.button("pw-btn primary","Save","Save the view name",a),this.button("pw-btn","Duplicate","New view with the same switches",()=>this.duplicateView(e,n.id))),t.views.length>1&&o.append(this.button("pw-btn danger","Delete","Delete this view (panes keep running)",()=>this.deleteView(e,n.id))),i.append(o),this.autofocus&&setTimeout(()=>{s.focus(),s.select()},0),i}paneEditor(e,t){const n=this.node("div","pw-form"),i=this.draft(e,"name",this.input("text",t.name??"","optional")),s=this.draft(e,"command",this.input("text",t.startupCommand??"","e.g. c 1")),a=this.draft(e,"cwd",this.input("text",t.cwd??"","C:\\path or /home/user")),o=document.createElement("select");o.className="pw-input";const r=document.createElement("option");r.value="",r.textContent="-- profile --",o.append(r);for(const e of this.profiles){const t=document.createElement("option");t.value=e.id,t.textContent=e.name,o.append(t)}o.value=t.profileId??"",this.draft(e,"profile",o);const p=this.draftColor(e,"color",t.color??"");n.append(this.field("Name",i),this.field("Label colour",p.element),this.field("Startup command",s),this.field("Folder",a),this.field("Profile",o),this.node("div","pw-hint","Command, folder and profile apply when the pane (re)starts."));const d=()=>this.savePane(e,t.id,{name:i.value.trim(),color:p.value(),startupCommand:s.value.trim(),cwd:a.value.trim(),profileId:o.value});for(const t of[i,s,a])t.addEventListener("keydown",t=>{"Enter"===t.key&&d(),"Escape"===t.key&&(e.editingPaneId=null,this.render(e,!0))});const c=this.node("div","pw-actions");return c.append(this.button("pw-btn primary","Save","Save the pane settings",d),this.button("pw-btn","Restart","Save, then close and start the pane again",async()=>{await d(),await this.restartPane(e,t.id)}),this.button("pw-btn","Duplicate","Save, then add a copy of this pane (same settings and view switches)",async()=>{await d(),await this.duplicatePane(e,t.id)}),this.button("pw-btn danger","Remove","Remove the pane from the workspace",()=>this.removePane(e,t.id))),n.append(c),this.autofocus&&setTimeout(()=>i.focus(),0),n}colorPicker(e,t){let n=e;const i=this.node("div","pw-colors"),s=document.createElement("input");s.type="color",s.className="pw-color-custom",s.title="Custom colour";const a=()=>{i.querySelectorAll(".pw-swatch").forEach(e=>{e.classList.toggle("selected",e.dataset.color===n)}),s.classList.toggle("selected",!!n&&!Q.includes(n)),n&&(s.value=n)};for(const e of["",...Q]){const s=this.button("pw-swatch"+(e?"":" none"),"",e||"No colour",()=>{n=e,t?.(n),a()});s.dataset.color=e,e&&(s.style.background=e),i.append(s)}return s.addEventListener("input",()=>{n=s.value,t?.(n),a()}),i.append(s),a(),{element:i,value:()=>n}}workspaceMenu(e,t){const n=this.node("div","pw-form pw-menu"),i=this.draft(e,"name",this.input("text",t.name,"Workspace name")),s=this.draft(e,"minW",this.input("number",t.minPaneWidth?String(t.minPaneWidth):"",String(600))),a=this.draft(e,"minH",this.input("number",t.minPaneHeight?String(t.minPaneHeight):"",String(260)));s.classList.add("pw-size"),a.classList.add("pw-size");const o=this.node("div","pw-size-row");o.append(s,this.node("span","","×"),a,this.node("span","","px"));const r=document.createElement("input");r.type="checkbox",r.checked=!!t.launchOnStartup,this.draft(e,"startup",r);const p=this.node("label","pw-check");p.append(r,this.node("span","","Open when Tabby starts"));const d=this.draftColor(e,"color",t.color??""),c=t.panes.find(e=>e.cwd?.trim())?.cwd?.trim(),l=this.draft(e,"folder",this.input("text",t.folder??"",c||"C:\\path or /home/user"));n.append(this.field("Name",i),this.field("Tab colour",d.element),this.field("Project folder",l),this.node("div","pw-hint","Opened by the VS Code button. Empty: the first pane folder."),this.field("Minimum pane size",o),this.node("div","pw-hint","A view fits as many switched-on panes as this size allows."),p);const h=()=>this.saveWorkspaceSettings(e,{name:i.value,minPaneWidth:Number(s.value)||null,minPaneHeight:Number(a.value)||null,launchOnStartup:r.checked,color:d.value(),folder:l.value});for(const t of[i,l,s,a])t.addEventListener("keydown",t=>{"Enter"===t.key&&h(),"Escape"===t.key&&(e.menuOpen=!1,this.render(e,!0))});const w=this.node("div","pw-actions");w.append(this.button("pw-btn primary","Save","Save the workspace settings",h),this.button("pw-btn","Close","Close the menu",()=>{e.menuOpen=!1,this.render(e,!0)})),n.append(w),n.append(this.button("pw-menu-item","Edit settings in VS Code","Open this workspace as a JSON file; every save there is applied right away",()=>{e.menuOpen=!1,this.render(e,!0),this.workspaces.openConfigInVsCode(t)}),this.button("pw-menu-item","Copy settings file path","Copy the path of this workspace's JSON settings file; saves to it are applied right away",()=>{this.workspaces.copyConfigFilePath(t)})),n.append(this.node("div","pw-menu-title","Workspaces"));for(const i of this.workspaces.getWorkspaces()){const s=i.id===t.id,a=!s&&!!this.findOpenTab(i.id),o=this.button("pw-menu-item"+(s?" current":""),"",s?"This workspace":a?"Switch to its tab":"Open it",()=>{s||(e.menuOpen=!1,this.render(e,!0),this.openWorkspace(i.id))});o.append(this.node("span","pw-name",i.name),this.node("span","pw-count",s?"this":a?"open":"")),n.append(o)}return n.append(this.button("pw-menu-item","+ New workspace","Create a workspace from a profile, folder and command",()=>{e.menuOpen=!1,this.render(e,!0),this.createWorkspace()}),this.button("pw-menu-item danger","Delete this workspace…","Delete it and close its tab",()=>this.deleteWorkspace(e))),n}makeDropTarget(e,t,n){t.addEventListener("dragover",n=>{e.dragging&&(n.preventDefault(),n.dataTransfer&&(n.dataTransfer.dropEffect="move"),t.classList.add("drop-before"))}),t.addEventListener("dragleave",()=>t.classList.remove("drop-before")),t.addEventListener("drop",i=>{i.preventDefault(),t.classList.remove("drop-before");const s=i.dataTransfer?.getData("text/plain");e.dragging=!1,s&&this.movePane(e,s,n)})}node(e,t,n){const i=document.createElement(e);return t&&(i.className=t),void 0!==n&&(i.textContent=n),i}button(e,t,n,i){const s=document.createElement("button");return s.type="button",s.className=e,s.textContent=t,s.title=n,s.addEventListener("click",e=>{e.stopPropagation(),i()}),s}input(e,t,n){const i=document.createElement("input");return i.type=e,i.className="pw-input",i.value=t,i.placeholder=n,i.addEventListener("keydown",e=>e.stopPropagation()),i}field(e,t){const n=this.node("label","pw-field");return n.append(this.node("span","pw-label",e),t),n}ensureStyles(){if(document.getElementById("paneworks-sidebar-styles"))return;const e=document.createElement("style");e.id="paneworks-sidebar-styles",e.textContent="\n /* Pane frames in Paneworks tabs: every pane gets a frame and a small gap,\n the pane with keyboard focus an accent frame. Tabby positions the panes\n (class \"child\") absolutely; border-box keeps them inside their slot. */\n [data-paneworks] > .child {\n box-sizing: border-box;\n border: 3px solid var(--theme-bg-more, rgba(0,0,0,.35));\n border-radius: 6px;\n overflow: hidden;\n transition: border-color .12s;\n }\n [data-paneworks] > .child.focused {\n border-color: var(--theme-primary, #4c9aff);\n }\n [data-paneworks] split-tab-pane-label .custom-name {\n font-weight: 600;\n }\n /* Split handles: Tabby's handle is a 10px band centred on the border between two\n panes. A bright 4px bar in its middle (inset 3px works for both orientations)\n stands out against the panes; brighter on hover, accent while dragging. */\n [data-paneworks] > split-tab-spanner::after {\n content: '';\n position: absolute;\n inset: 3px;\n border-radius: 2px;\n background: rgba(255, 255, 255, .30);\n background: color-mix(in srgb, var(--theme-fg, #fff) 32%, transparent);\n pointer-events: none;\n transition: background .12s;\n }\n [data-paneworks] > split-tab-spanner:hover::after {\n background: rgba(255, 255, 255, .55);\n background: color-mix(in srgb, var(--theme-fg, #fff) 60%, transparent);\n }\n [data-paneworks] > split-tab-spanner.active::after {\n background: var(--theme-primary, #4c9aff);\n }\n\n .paneworks-overlay {\n position: fixed; inset: 0; z-index: 10000; display: flex; align-items: flex-start; justify-content: center;\n padding-top: 12vh; background: rgba(0,0,0,.45);\n }\n .paneworks-sidebar.pw-dialog {\n width: 380px; max-width: calc(100vw - 32px); border: 1px solid var(--theme-bg-more-2, rgba(255,255,255,.12));\n border-radius: 6px; background: var(--theme-bg, #1e1e1e); box-shadow: 0 10px 40px rgba(0,0,0,.5); overflow: visible;\n }\n .paneworks-sidebar.pw-dialog .pw-form { margin: 0; padding: 14px; gap: 8px; background: none; }\n .paneworks-sidebar .pw-dialog-title { font-size: 14px; font-weight: 600; margin-bottom: 2px; }\n .paneworks-sidebar .pw-folder-row { display: flex; gap: 4px; }\n .paneworks-sidebar .pw-folder-row .pw-input { flex: 1; min-width: 0; }\n .paneworks-sidebar .pw-folder-row .pw-btn { flex: none; }\n\n .paneworks-sidebar {\n --pw-accent: var(--theme-primary, #4c9aff);\n display: flex; flex-direction: column; overflow-y: auto; overflow-x: hidden;\n background: var(--theme-bg-more, rgba(0,0,0,.25));\n border-right: 1px solid var(--theme-bg-more-2, rgba(255,255,255,.08));\n color: var(--theme-fg, inherit); font-size: 12px; user-select: none;\n }\n .paneworks-sidebar.collapsed { align-items: center; }\n .paneworks-sidebar button { font: inherit; color: inherit; }\n .paneworks-sidebar .pw-icon-btn {\n background: none; border: none; opacity: .6; cursor: pointer; padding: 2px 6px; line-height: 1; font-size: 13px;\n }\n .paneworks-sidebar .pw-icon-btn:hover { opacity: 1; }\n .paneworks-sidebar .pw-code { display: flex; align-items: center; }\n .paneworks-sidebar.collapsed .pw-toggle { margin-top: 8px; }\n\n .paneworks-sidebar .pw-header { display: flex; align-items: center; padding: 6px 4px 4px 4px; }\n .paneworks-sidebar .pw-ws {\n flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; background: none; border: none;\n padding: 4px 6px; border-radius: 4px; cursor: pointer; font-weight: 600; text-align: left;\n }\n .paneworks-sidebar .pw-ws:hover { background: rgba(127,127,127,.15); }\n .paneworks-sidebar .pw-ws-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n .paneworks-sidebar .pw-caret { opacity: .5; font-size: 10px; }\n\n .paneworks-sidebar .pw-section {\n display: flex; align-items: center; justify-content: space-between;\n padding: 10px 6px 2px 10px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; opacity: .6;\n }\n .paneworks-sidebar .pw-add { font-size: 15px; opacity: .9; }\n\n .paneworks-sidebar .pw-row {\n display: flex; align-items: center; gap: 6px; padding: 5px 4px 5px 4px;\n border-left: 3px solid transparent; border-top: 2px solid transparent;\n }\n .paneworks-sidebar .pw-row:hover { background: rgba(127,127,127,.10); }\n .paneworks-sidebar .pw-all { cursor: pointer; padding-left: 10px; }\n .paneworks-sidebar .pw-all .pw-main { flex: 1; font-weight: 600; }\n .paneworks-sidebar .pw-all.active { border-left-color: var(--pw-accent); background: rgba(127,127,127,.14); }\n .paneworks-sidebar .pw-count { font-size: 10px; opacity: .55; }\n .paneworks-sidebar .pw-view { padding-right: 4px; }\n .paneworks-sidebar .pw-view .pw-main { font-weight: 400; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n .paneworks-sidebar .pw-view.active .pw-main, .paneworks-sidebar .pw-view.selected .pw-main { font-weight: 600; }\n .paneworks-sidebar .pw-view.selected { border-left-color: rgba(127,127,127,.5); }\n .paneworks-sidebar .pw-view.editing { background: rgba(127,127,127,.14); }\n .paneworks-sidebar .pw-empty-view { padding: 4px 10px; }\n .paneworks-sidebar .pw-section-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }\n\n /* Pane states: on screen = accent bar + full brightness; running elsewhere = dimmed;\n switched off = dimmer; focus view = highlighted row. */\n .paneworks-sidebar .pw-pane .pw-text { opacity: .6; }\n .paneworks-sidebar .pw-pane.onscreen { border-left-color: var(--pw-accent); }\n .paneworks-sidebar .pw-pane.onscreen .pw-text { opacity: 1; }\n .paneworks-sidebar .pw-pane.off .pw-text { opacity: .38; }\n .paneworks-sidebar .pw-pane.focused { background: rgba(127,127,127,.20); }\n .paneworks-sidebar .pw-pane.focused .pw-name { font-weight: 600; }\n .paneworks-sidebar .pw-pane.editing { background: rgba(127,127,127,.14); }\n\n .paneworks-sidebar .pw-pane-color { flex: 0 0 8px; height: 8px; border-radius: 2px; }\n .paneworks-sidebar .pw-pane-color.none { border: 1px dashed rgba(127,127,127,.5); box-sizing: border-box; }\n .paneworks-sidebar .pw-colors { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }\n .paneworks-sidebar .pw-swatch {\n width: 16px; height: 16px; padding: 0; border-radius: 3px; cursor: pointer;\n border: 2px solid transparent; box-sizing: border-box;\n }\n .paneworks-sidebar .pw-swatch.none {\n background: repeating-linear-gradient(45deg, transparent 0 3px, rgba(127,127,127,.5) 3px 4px);\n border-color: rgba(127,127,127,.4);\n }\n .paneworks-sidebar .pw-swatch.selected, .paneworks-sidebar .pw-color-custom.selected {\n border-color: var(--theme-fg, #fff);\n }\n .paneworks-sidebar .pw-color-custom {\n width: 22px; height: 18px; padding: 0; border: 2px solid transparent; border-radius: 3px;\n background: none; cursor: pointer;\n }\n .paneworks-sidebar .pw-handle { cursor: grab; opacity: .25; font-size: 10px; letter-spacing: -2px; }\n .paneworks-sidebar .pw-row:hover .pw-handle { opacity: .7; }\n .paneworks-sidebar .pw-row.dragging { opacity: .35; }\n .paneworks-sidebar .drop-before { border-top-color: var(--pw-accent); }\n .paneworks-sidebar .pw-drop-end { flex: 1; min-height: 24px; border-top: 2px solid transparent; }\n\n .paneworks-sidebar .pw-text { display: flex; flex-direction: column; min-width: 0; flex: 1; cursor: pointer; }\n .paneworks-sidebar .pw-main { display: flex; align-items: center; gap: 5px; min-width: 0; }\n .paneworks-sidebar .pw-name { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n .paneworks-sidebar .pw-sub { font-size: 10px; opacity: .6; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }\n .paneworks-sidebar .pw-news {\n flex: none; font-size: 9px; line-height: 1; padding: 2px 4px; border-radius: 3px;\n background: var(--pw-accent); color: var(--theme-bg, #000); font-weight: 600; text-transform: uppercase;\n }\n .paneworks-sidebar .pw-more { opacity: .35; font-size: 14px; }\n .paneworks-sidebar .pw-row:hover .pw-more, .paneworks-sidebar .pw-row.editing .pw-more { opacity: .9; }\n\n .paneworks-sidebar .pw-switch { position: relative; flex: 0 0 26px; height: 14px; cursor: pointer; }\n .paneworks-sidebar .pw-switch input { opacity: 0; width: 0; height: 0; position: absolute; }\n .paneworks-sidebar .pw-slider {\n position: absolute; inset: 0; border-radius: 7px; background: rgba(127,127,127,.35); transition: background .15s;\n }\n .paneworks-sidebar .pw-slider::before {\n content: ''; position: absolute; left: 2px; top: 2px; width: 10px; height: 10px; border-radius: 50%;\n background: var(--theme-fg, #fff); transition: transform .15s;\n }\n .paneworks-sidebar .pw-switch input:checked + .pw-slider { background: var(--pw-accent); }\n .paneworks-sidebar .pw-switch input:checked + .pw-slider::before { transform: translateX(12px); }\n\n .paneworks-sidebar .pw-form {\n display: flex; flex-direction: column; gap: 6px; margin: 2px 6px 6px 7px; padding: 8px;\n border-radius: 4px; background: rgba(127,127,127,.10); user-select: text;\n }\n .paneworks-sidebar .pw-menu { margin-top: 0; }\n .paneworks-sidebar .pw-field { display: flex; flex-direction: column; gap: 2px; margin: 0; }\n .paneworks-sidebar .pw-label { font-size: 10px; opacity: .6; }\n .paneworks-sidebar .pw-input {\n width: 100%; box-sizing: border-box; padding: 3px 6px; font: inherit; color: inherit; border-radius: 3px;\n background: var(--theme-bg, rgba(0,0,0,.3)); border: 1px solid rgba(127,127,127,.35);\n }\n .paneworks-sidebar .pw-input:focus { outline: none; border-color: var(--pw-accent); }\n .paneworks-sidebar .pw-size-row { display: flex; align-items: center; gap: 4px; }\n .paneworks-sidebar .pw-size { width: 64px; }\n .paneworks-sidebar .pw-check { display: flex; align-items: center; gap: 6px; margin: 0; cursor: pointer; }\n .paneworks-sidebar .pw-hint { font-size: 10px; opacity: .55; }\n .paneworks-sidebar .pw-actions { display: flex; gap: 4px; flex-wrap: wrap; margin-top: 2px; }\n .paneworks-sidebar .pw-btn {\n padding: 3px 8px; border-radius: 3px; cursor: pointer; background: rgba(127,127,127,.2);\n border: 1px solid transparent;\n }\n .paneworks-sidebar .pw-btn:hover { background: rgba(127,127,127,.3); }\n .paneworks-sidebar .pw-btn.primary { background: var(--pw-accent); color: var(--theme-bg, #000); }\n .paneworks-sidebar .pw-btn.danger:hover { background: #c0392b; color: #fff; }\n .paneworks-sidebar .pw-menu-title { margin-top: 8px; font-size: 10px; letter-spacing: .06em; text-transform: uppercase; opacity: .6; }\n .paneworks-sidebar .pw-menu-item {\n display: flex; align-items: center; justify-content: space-between; gap: 6px; width: 100%;\n background: none; border: none; padding: 4px 6px; border-radius: 3px; cursor: pointer; text-align: left;\n }\n .paneworks-sidebar .pw-menu-item:hover { background: rgba(127,127,127,.2); }\n .paneworks-sidebar .pw-menu-item.current { cursor: default; font-weight: 600; }\n .paneworks-sidebar .pw-menu-item.danger:hover { background: #c0392b; color: #fff; }\n ",document.head.appendChild(e)}loadCollapsed(e){try{return"1"===localStorage.getItem(`paneworks-sidebar-collapsed:${e}`)}catch{return!1}}saveCollapsed(e,t){try{localStorage.setItem(`paneworks-sidebar-collapsed:${e}`,t?"1":"0")}catch{}}};G=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[f.AppService,f.ProfilesService,_,N,f.TabsService,f.TabRecoveryService,f.PlatformService])],G);const U="__new__";let X=class extends f.ToolbarButtonProvider{constructor(e,t,n,i){super(),this.workspaceService=e,this.app=t,this.layout=n,i.hotkey$.subscribe(e=>{e===g&&this.showWorkspaceSelector()}),this.waitForTabbyReady().then(()=>{this.workspaceService.cleanupOrphanedProfiles(),this.launchStartupWorkspaces()})}waitForTabbyReady(){return new Promise(e=>{let t=-1;const n=()=>{const i=this.app.tabs.length;i===t?e():(t=i,setTimeout(n,300))};setTimeout(n,500)})}async launchStartupWorkspaces(){for(const e of this.workspaceService.getWorkspaces().filter(e=>e.launchOnStartup))this.layout.findOpenTab(e.id)?console.log(`[${m}] Workspace "${e.name}" already open, skipping`):await this.layout.openWorkspace(e.id)}provide(){return[{icon:'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">\n <rect x="3" y="3" width="7" height="7"/>\n <rect x="14" y="3" width="7" height="7"/>\n <rect x="14" y="14" width="7" height="7"/>\n <rect x="3" y="14" width="7" height="7"/>\n</svg>',title:m,weight:5,click:()=>this.showWorkspaceSelector()}]}async showWorkspaceSelector(){const e=this.workspaceService.getWorkspaces().map(e=>({name:e.name,description:`${e.panes.length} panes${this.layout.findOpenTab(e.id)?" · open":""}`,icon:e.icon||"columns",color:e.color,result:e.id}));e.push({name:"New workspace",description:"Pick a profile, folder, command and number of panes (default 4)",icon:"plus",color:void 0,result:U});const t=await this.app.showSelector(m,e);t===U?await this.layout.createWorkspace():t&&await this.layout.openWorkspace(t)}};X=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.Injectable)(),function(e,t){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(e,t)}("design:paramtypes",[N,f.AppService,G,f.HotkeysService])],X);let Y=class{};Y=function(e,t,n,i){var s,a=arguments.length,o=a<3?t:null===i?i=Object.getOwnPropertyDescriptor(t,n):i;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)o=Reflect.decorate(e,t,n,i);else for(var r=e.length-1;r>=0;r--)(s=e[r])&&(o=(a<3?s(o):a>3?s(t,n,o):s(t,n))||o);return a>3&&o&&Object.defineProperty(t,n,o),o}([(0,h.NgModule)({imports:[w.CommonModule],providers:[{provide:f.ConfigProvider,useClass:k,multi:!0},{provide:f.ToolbarButtonProvider,useClass:X,multi:!0},{provide:f.HotkeyProvider,useClass:b,multi:!0},N,_,G]})],Y);const Z=Y;return l})());
|
|
3
3
|
//# sourceMappingURL=index.js.map
|
package/index.js.LICENSE.txt
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
!*** ./src/index.ts +
|
|
3
|
-
|
|
1
|
+
/*!***********************************!*\
|
|
2
|
+
!*** ./src/index.ts + 10 modules ***!
|
|
3
|
+
\***********************************/
|