@vibelord/lanes 1.8.0 → 1.9.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.
Files changed (61) hide show
  1. package/package.json +1 -1
  2. package/payload/lanes/README.md +29 -11
  3. package/payload/lanes/VERSION +1 -1
  4. package/payload/lanes/bin/lanes +159 -59
  5. package/payload/lanes/bin-rs/BINARIES.json +2 -17
  6. package/payload/lanes/client/lanes-launch +51 -2
  7. package/payload/lanes/container/lane +142 -19
  8. package/payload/lanes/container/lane-mcp +168 -55
  9. package/payload/lanes/container/lane-peerd +6 -6
  10. package/payload/lanes/container/lane-signal +48 -3
  11. package/payload/lanes/container/lane_core.py +1040 -164
  12. package/payload/lanes/container/throttle-pulse +13 -4
  13. package/payload/lanes/docs/AGENTS-lanes.md +15 -7
  14. package/payload/lanes/docs/ARCHITECTURE.md +478 -101
  15. package/payload/lanes/docs/DESIGN.md +7 -2
  16. package/payload/lanes/docs/INSTALL.md +20 -3
  17. package/payload/lanes/docs/PLAN-1.9.1-SIDEBAR-CODEX.md +128 -0
  18. package/payload/lanes/docs/RUNBOOK.md +1428 -107
  19. package/payload/lanes/docs/USERGUIDE.md +488 -86
  20. package/payload/lanes/holders/tmux.sh +3 -3
  21. package/payload/lanes/install/services.py +68 -11
  22. package/payload/lanes/libexec/agent_state.py +2 -5
  23. package/payload/lanes/libexec/attach.py +11 -3
  24. package/payload/lanes/libexec/cursor_sync.py +22 -2
  25. package/payload/lanes/libexec/docsd.py +38 -4
  26. package/payload/lanes/libexec/lanes_lib.py +377 -39
  27. package/payload/lanes/libexec/mdlite.py +43 -3
  28. package/payload/lanes/libexec/notify.py +69 -26
  29. package/payload/lanes/libexec/registrations.py +5 -0
  30. package/payload/lanes/libexec/session_actions.py +114 -27
  31. package/payload/lanes/libexec/sidebar.py +246 -64
  32. package/payload/lanes/libexec/site_hooks.py +65 -0
  33. package/payload/lanes/libexec/statusd.py +139 -189
  34. package/payload/lanes/libexec/studio_host.py +8 -2
  35. package/payload/lanes/libexec/tokens.py +6 -2
  36. package/payload/lanes/libexec/update.py +13 -5
  37. package/payload/lanes/libexec/view.sh +39 -4
  38. package/payload/lanes/libexec/workspace_keys.py +54 -0
  39. package/payload/lanes/site/protocol.py +15 -5
  40. package/payload/lanes/site/relay.py +5 -2
  41. package/payload/lanes/site/server.py +29 -18
  42. package/payload/lanes/systemd/lanes-economy.service +3 -1
  43. package/payload/lanes/tokens/README.md +10 -0
  44. package/payload/lanes/tokens/generate.py +1 -1
  45. package/payload/lanes/web/Caddyfile +9 -2
  46. package/payload/lanes/web/README.md +2410 -95
  47. package/payload/lanes/web/browser.css +2 -0
  48. package/payload/lanes/web/browser.js +18 -6
  49. package/payload/lanes/web/directory.js +1 -1
  50. package/payload/lanes/web/docs.js +23 -0
  51. package/payload/lanes/web/links.js +157 -0
  52. package/payload/lanes/web/manifest.webmanifest +0 -2
  53. package/payload/lanes/web/mobile.css +30 -32
  54. package/payload/lanes/web/mobile.js +286 -227
  55. package/payload/lanes/web/upload.js +65 -22
  56. package/payload/lanes/web/workspace-keys.js +65 -0
  57. package/payload/lanes/zellij/config.kdl +1 -1
  58. package/payload/manifest.json +5 -22
  59. package/payload/lanes/bin-rs/THIRD-PARTY-NOTICES +0 -18953
  60. package/payload/lanes/bin-rs/x86_64-unknown-linux-musl/lanes-hook +0 -0
  61. package/payload/lanes/bin-rs/x86_64-unknown-linux-musl/lanes-terminal +0 -0
@@ -2,58 +2,80 @@ function laneShellMode({userAgent, coarse, width, height} = {}) {
2
2
  if (/iPhone|iPod|Android.*Mobile/i.test(userAgent) || (coarse && (width <= 600 || height <= 500))) return 'phone';
3
3
  return coarse ? 'tablet' : 'desktop';
4
4
  }
5
- if (typeof module === 'object') module.exports = {laneShellMode};
5
+ if (typeof module == 'object') module.exports = {laneShellMode};
6
6
  (() => {
7
7
  'use strict';
8
- if (typeof document === 'undefined') return;
8
+ if (typeof document == 'undefined') return;
9
9
  const mode = laneShellMode({userAgent: navigator.userAgent, coarse: matchMedia('(pointer: coarse)').matches,
10
10
  width: innerWidth, height: innerHeight});
11
- const root = document.documentElement;
11
+ const D = document, root = D.documentElement, classes = root.classList;
12
12
  // BEGIN lanes tokens (generated by libexec/tokens.py --js; do not edit by hand)
13
13
  const LANES_ANSI = {dark: ['#8792a0', '#ff7b6e', '#5fdc8a', '#ffc233', '#6fb6ff', '#c58bff', '#3fd9cf', '#a6b1be', '#97a3b1', '#ff9a8e', '#86f0ad', '#ffd866', '#98cbff', '#dcb2ff', '#7deee6', '#f2f5f8'], light: ['#2f3b34', '#c41c1c', '#0d7338', '#a04d00', '#1a56c4', '#8228c4', '#006f73', '#4a5661', '#55625b', '#d0221a', '#0e7a3a', '#a85200', '#1f5fd8', '#9133d0', '#00797c', '#111a14']};
14
14
  // END lanes tokens
15
15
  root.dataset.lanesShell = mode;
16
- const add = (tag, props) => document.head.append(Object.assign(document.createElement(tag), props)), js = src => add('script', {src});
17
- if (mode !== 'phone') add('link', {rel: 'stylesheet', href: '/lanes-assets/browser.css'}), js('/lanes-assets/browser.js');
16
+ const add = (tag, props) => D.head.append(Object.assign(D.createElement(tag), props)), js = src => add('script', {src});
17
+ if (globalThis.location?.search === '?keys') js('/lanes-assets/workspace-keys.js');
18
+ if (mode != 'phone') add('link', {rel: 'stylesheet', href: '/lanes-assets/browser.css'}), js('/lanes-assets/browser.js');
18
19
  let d; const dir = () => !d && /^#lane(s$|=)/.test(globalThis.location?.hash) && js('/lanes-assets/directory.js', d = 1);
19
20
  let o; const ops = () => !o && /^#(inbox|schedule|results)(=|$)/.test(globalThis.location?.hash) && js('/lanes-assets/inbox.js', o = 1);
20
21
  globalThis.addEventListener?.('hashchange', dir); dir();
21
22
  globalThis.addEventListener?.('hashchange', ops); ops();
22
23
  if (mode === 'desktop') return;
23
- root.classList.add('lanes-mobile');
24
- if (mode === 'tablet') {
25
- root.classList.add('lanes-tablet');
24
+ classes.add('lanes-mobile');
25
+ if (mode == 'tablet') {
26
+ classes.add('lanes-tablet');
26
27
  try {localStorage.getItem('zellij:mobile-ui') || localStorage.setItem('zellij:mobile-ui', 'on');} catch {}
27
28
  }
28
29
 
29
30
  const elementFocus = HTMLElement.prototype.focus;
30
31
  HTMLElement.prototype.focus = function(...args) {
31
- const textInput = this instanceof HTMLInputElement &&
32
- ['text', 'search', 'email', 'number', 'password', 'tel', 'url'].includes(this.type);
32
+ const textInput = this instanceof HTMLInputElement && /^(text|search|email|number|password|tel|url)$/.test(this.type);
33
33
  if (textInput || this instanceof HTMLTextAreaElement || this.isContentEditable) return;
34
34
  return elementFocus.apply(this, args);
35
35
  };
36
- Object.defineProperty(window, '__zjSoftKbdEnabled', {configurable: false, get: () => false, set: () => {}});
36
+ const W = window, on = (t, ...a) => t.addEventListener(...a), now = () => Date.now();
37
+ Object.defineProperty(W, '__zjSoftKbdEnabled', {configurable: false, get: () => false, set: () => {}});
38
+ W.WebSocket &&= new Proxy(WebSocket, {construct(T, a, n) {
39
+ const s = Reflect.construct(T, a, n);
40
+ try {
41
+ if (/\/ws\/terminal/.test(a[0])) {
42
+ sock = s;
43
+ on(s, 'message', () => { unacked = 0; if (doubt) doubt = hintN = 0, refresh(); }); on(s, 'open', () => /no c/.test(note) && (note = 'Not sent: try again', hintN || text(status, note)));
44
+ on(s, 'close', ev => {
45
+ gone = unacked || now() - sentAt < 5e3 ? 2 : 1;
46
+ bye = ev.code == 4001;
47
+ if (gone > 1 && !away) unsure();
48
+ id('terminal').style.opacity = '.5';
49
+ if (doubt) doubt = hintN = 0; refresh();
50
+ away || back();
51
+ });
52
+ }
53
+ } catch {}
54
+ return s;
55
+ }});
37
56
  try {
38
57
  const theme = localStorage.getItem('zellij:mobile-theme') || 'dark';
39
58
  localStorage.setItem('zellij:mobile-theme', theme);
40
59
  root.dataset.zjTheme = theme;
41
60
  } catch {}
61
+ const rect = (x, y, w, h, r) => `<rect x="${x}" y="${y}" width="${w}" height="${h}" rx="${r}"/>`;
62
+ const path = d => `<path d="${d}"/>`;
63
+ const circle = (x, y, r) => `<circle cx="${x}" cy="${y}" r="${r}"/>`;
42
64
  const icons = {
43
- workspaces: [[3, 3], [14, 3], [3, 14], [14, 14]].map(([x, y]) => `<rect x="${x}" y="${y}" width="7" height="7" rx="2"/>`).join(''),
44
- lanes: '<path d="M8 5h13M8 12h13M8 19h13"/><path d="M3 5h.01M3 12h.01M3 19h.01"/>',
45
- panes: '<rect x="3" y="4" width="18" height="16" rx="3"/><path d="M12 4v16"/>',
46
- keyboard: '<rect x="2" y="5" width="20" height="14" rx="3"/><path d="M6 9h.01M10 9h.01M14 9h.01M18 9h.01M6 13h.01M10 13h.01M14 13h.01M18 13h.01M8 16h8"/>',
47
- more: '<circle cx="5" cy="12" r="1"/><circle cx="12" cy="12" r="1"/><circle cx="19" cy="12" r="1"/>',
48
- close: '<path d="m6 6 12 12M6 18 18 6"/>',
49
- arrow: '<path d="m9 5 7 7-7 7"/>',
50
- check: '<path d="m5 12 4 4L19 6"/>',
51
- search: '<circle cx="10.5" cy="10.5" r="6.5"/><path d="m16 16 5 5"/>',
52
- copy: '<rect x="9" y="9" width="11" height="11" rx="2"/><path d="M5 15V5h10"/>',
53
- paste: '<rect x="5" y="5" width="14" height="16" rx="2"/><path d="M9 3h6v4H9z"/>',
65
+ workspaces: [[3, 3], [14, 3], [3, 14], [14, 14]].map(([x, y]) => rect(x, y, 7, 7, 2)).join(''),
66
+ lanes: path('M8 5h13M8 12h13M8 19h13M3 5h.01M3 12h.01M3 19h.01'),
67
+ panes: rect(3, 4, 18, 16, 3) + path('M12 4v16'),
68
+ keyboard: rect(2, 5, 20, 14, 3) + path('M6 9h.01m4 0h.01m4 0h.01m4 0h.01M6 13h.01m4 0h.01m4 0h.01m4 0h.01M8 16h8'),
69
+ more: [5, 12, 19].map(x => circle(x, 12, 1)).join(''),
70
+ close: path('m6 6 12 12M6 18 18 6'),
71
+ arrow: path('m9 5 7 7-7 7'),
72
+ check: path('m5 12 4 4L19 6'),
73
+ search: circle(10.5, 10.5, 6.5) + path('m16 16 5 5'),
74
+ copy: rect(9, 9, 11, 11, 2) + path('M5 15V5h10'),
75
+ paste: rect(5, 5, 14, 16, 2) + path('M9 3h6v4H9z'),
54
76
  };
55
77
  const svg = name => `<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${icons[name]}</svg>`;
56
- const make = (tag, cls, text) => Object.assign(document.createElement(tag), tag == 'button' && {type: tag},
78
+ const make = (tag, cls, text) => Object.assign(D.createElement(tag), tag == 'button' && {type: tag},
57
79
  cls && {className: cls}, text !== undefined && {textContent: text});
58
80
  const text = (el, value) => { if (el.textContent !== value) el.textContent = value; };
59
81
  const button = (label, icon, action) => {
@@ -61,272 +83,291 @@ if (typeof module === 'object') module.exports = {laneShellMode};
61
83
  aria(el, label);
62
84
  el.innerHTML = svg(icon);
63
85
  el.append(make('span', '', label));
64
- el.addEventListener('click', action);
86
+ on(el, 'click', action);
65
87
  return el;
66
88
  };
67
- let shell, heading, subtitle, dock, sheet, list, search, count, lanesButton, panesButton, pasteKey, typingField, quickRow, quickOn;
68
- let laneFilterBar, laneFilterInput, laneFilterPrev = '', sentAt = 0, filterTab, owed = new Set();
69
- let api, term, previousCards = '', sheetOpen = false, returnFocus, menuWas, hintN = 0, timer;
70
- const queue = [];
71
- let fontSize = 16;
89
+ let shell, heading, subtitle, status, note, empty, dock, sheet, list, search, count, lanesButton, panesButton, pasteKey, typingField, quickRow, quickOn, keysKey, view;
90
+ let laneFilterBar, laneFilterInput, laneFilterPrev = '', sentAt, filterTab, owed = new Set(), sock, unacked, gone, away, armed, seen, rl, hid, bye, retry, hiddenAt, doubt;
91
+ let api, term, previousCards, sheetOpen, shot, pre, said, down, returnFocus, menuWas, hintN, timer, queue = [], fontSize = 16, lastKey, restoring, mem = {ws: {}};
92
+ const fontKey = 'lanes:font-size';
72
93
  try {
73
- const stored = Number(localStorage.getItem('lanes:font-size'));
94
+ const stored = Number(localStorage.getItem(fontKey));
74
95
  if (stored >= 14 && stored <= 24) fontSize = stored;
75
96
  } catch {}
76
97
  const state = () => api?.getState();
77
- const data = () => state()?.data, paneAt = pos => data()?.panes.find(p => p.tab_position === pos && !p.is_plugin);
78
- const nativeClick = selector => document.querySelector(selector)?.click();
79
- const resize = () => window.dispatchEvent(new Event('zellij:rendering-resize'));
80
- const kbd = () => window.__zjSoftKbdCapture, aria = (el, label) => el.setAttribute('aria-label', label), keep = ev => ev.preventDefault();
81
- const finder = (placeholder, label) => {
98
+ const data = () => state()?.data, panesAt = pos => pos >= 0 && data()?.panes.filter(p => p.tab_position === pos && !p.is_plugin) || [], paneAt = pos => panesAt(pos)[0];
99
+ const id = i => D.getElementById(i), q = s => D.querySelector(s), nativeClick = s => q(s)?.click();
100
+ const resize = () => dispatchEvent(new Event('zellij:rendering-resize'));
101
+ const unsure = () => { try { sessionStorage.setItem('lanes:unsure', 1); } catch {} };
102
+ const reconnect = () => rl ||= (api && hint('Reconnecting…', 25), fetch('/info/version', {cache: 'no-store', signal: AbortSignal.timeout?.(5e3)}))
103
+ .then(r => r.ok, () => 0).then(ok => ok ? ((gone > 1 || unacked) && unsure(), W.location?.reload()) : (rl = 0, api && hint('No connection to Lanes')));
104
+ const back = () => hid && !bye && sock?.readyState > 1 && reconnect();
105
+ const set = (el, k, v) => el.setAttribute(k, v), kbd = () => W.__zjSoftKbdCapture, aria = (el, label) => set(el, 'aria-label', label), keep = ev => ev.preventDefault(), act = () => D.activeElement, unfocus = () => (kbd()?.element.blur(), act()?.blur());
106
+ const finder = (placeholder, label = placeholder) => {
82
107
  const el = Object.assign(make('input'), {type: 'search', placeholder, autocomplete: 'off', spellcheck: false});
83
108
  aria(el, label);
84
109
  return el;
85
110
  };
86
111
 
87
112
  function viewport() {
88
- const vv = window.visualViewport;
113
+ const vv = W.visualViewport;
114
+ if (vv?.scale > 1.01) return;
89
115
  const px = (k, v) => root.style.setProperty(`--lanes-${k}`, `${v}px`);
90
116
  px('vh', vv?.height ?? innerHeight); px('vw', vv?.width ?? innerWidth);
91
117
  px('offset-top', vv?.offsetTop ?? 0); px('offset-left', vv?.offsetLeft ?? 0);
92
- const occluded = !!vv && innerHeight - vv.height - vv.offsetTop > 120;
93
- const focused = kbd()?.isFocused || document.activeElement?.matches('input, textarea');
94
- setKeyboard(occluded && focused);
95
- }
96
- function setKeyboard(visible) {
97
- if (root.classList.contains('lanes-keyboard') !== !!visible) {
98
- root.classList.toggle('lanes-keyboard', !!visible);
118
+ const kb = !!(vv && innerHeight - vv.height - vv.offsetTop > 120 && (kbd()?.isFocused || act()?.matches('input, textarea')));
119
+ if (classes.contains('lanes-keyboard') != kb) {
120
+ classes.toggle('lanes-keyboard', kb);
99
121
  resize();
100
122
  }
101
123
  typingField?.classList.toggle('is-typing', !!kbd()?.isFocused);
102
124
  }
103
125
  function buildTypingField() {
104
126
  const capture = kbd()?.element;
105
- const host = document.getElementById('zj-mobile-capture-host');
127
+ const host = id('zj-mobile-capture-host');
106
128
  if (!capture || !host) return null;
107
129
  const field = make('div', 'lanes-terminal-input');
108
130
  const label = make('span', 'lanes-input-label');
109
131
  label.innerHTML = svg('keyboard');
110
132
  label.append(make('span', '', 'Type here'));
111
- label.setAttribute('aria-hidden', 'true');
133
+ set(label, 'aria-hidden', 'true');
112
134
  host.removeAttribute('aria-hidden');
113
135
  const fill = 'position:absolute;inset:0;width:100%;height:100%;opacity:1;pointer-events:auto;';
114
136
  host.style.cssText = fill;
115
137
  capture.removeAttribute('aria-hidden');
116
138
  aria(capture, 'Type in terminal');
117
- for (const a of ['type text', 'autocomplete off', 'autocapitalize none']) capture.setAttribute(...a.split(' '));
139
+ for (const a of ['type text', 'autocomplete off', 'autocapitalize none']) set(capture, ...a.split(' '));
118
140
  capture.tabIndex = 0;
119
141
  capture.style.cssText = fill + 'box-sizing:border-box;font-size:16px;border:0;border-radius:12px;padding:0;margin:0;background:transparent;color:transparent;caret-color:transparent;outline:none;user-select:text;-webkit-user-select:text;';
120
142
  field.append(label, host);
121
- capture.addEventListener('beforeinput', ev => {
143
+ on(capture, 'beforeinput', ev => {
122
144
  const t = ev.data ?? ev.dataTransfer?.getData('text'), r = ev.getTargetRanges?.()[0];
123
145
  if (ev.cancelable && t && (ev.inputType == 'insertReplacementText' || ev.inputType == 'insertText' && t.length > 1)) {
124
- ev.preventDefault();
146
+ keep(ev);
125
147
  send('\x7f'.repeat(r ? r.endOffset - r.startOffset : capture.selectionEnd - capture.selectionStart) + t);
126
148
  }
127
149
  });
128
- capture.addEventListener('paste', ev => { ev.preventDefault(); paste(ev.clipboardData.getData('text')); });
150
+ on(capture, 'paste', ev => { keep(ev); paste(ev.clipboardData.getData('text')); });
129
151
  return field;
130
152
  }
131
- function focusTab(tab) {
132
- const pane = paneAt(tab?.position);
153
+ function focusTab(tab, or) {
154
+ const pane = paneAt(tab?.position) || paneAt(or?.position);
133
155
  if (!pane) return;
134
- window.__zjSendControl?.({type: 'FocusPane', pane_id: pane.pane_id, is_plugin: false});
156
+ W.__zjSendControl?.({type: 'FocusPane', pane_id: pane.pane_id, is_plugin: false});
135
157
  closeSheet();
136
158
  }
137
159
  const currentTab = () => data()?.tabs.find(t => t.position === data()?.active_pane?.tab_position);
138
- const GLYPHS = '◆◇▸✓', TONES = ['urgent', 'attention', 'working', 'done'];
160
+ const tabKey = () => 'lanes:tab:' + W.location?.pathname;
161
+ const bare = () => (currentTab()?.name || '').replace(/ ☰$/, '');
162
+ const at = (a = data()?.active_pane) => JSON.stringify([currentTab()?.name, a?.is_plugin, a?.pane_id]);
163
+ const GLYPHS = '◆◇▸✓', TONES = ['urgent', 'attention', 'working', 'done'], WORDS = ['need approval', 'need you', 'working', 'done'];
139
164
  function parseCounts(title) {
140
165
  const c = {approval: 0, input: 0, working: 0, done: 0}, keys = Object.keys(c);
141
166
  let found = 0;
142
167
  for (const [, g, n] of String(title || '').matchAll(/([◆◇▸✓])(\d+)/g)) { c[keys[GLYPHS.indexOf(g)]] = +n; found = 1; }
143
168
  return found ? c : null;
144
169
  }
145
- window.__lanesParseCounts = parseCounts;
146
- const countParts = c => c ? Object.values(c).map((n, i) => [GLYPHS[i], n, TONES[i]]).filter(p => p[1]) : [];
147
- const pickerTab = name => data()?.tabs.find(t => t.name === `${name} ☰`);
148
- function pickerTitle(name) {
149
- const picker = pickerTab(name);
150
- return picker ? paneAt(picker.position)?.title || '' : '';
151
- }
170
+ W.__lanesParseCounts = parseCounts;
171
+ const countParts = c => c ? Object.values(c).map((n, i) => [GLYPHS[i], n, TONES[i], WORDS[i]]).filter(p => p[1]) : [];
172
+ const tabNamed = name => data()?.tabs.find(t => t.name === name), pickerTab = name => tabNamed(name + ' ☰');
173
+ const pickerTitle = name => paneAt(pickerTab(name)?.position)?.title || '';
152
174
  function workspaces() {
153
- const tabs = data()?.tabs || [];
154
- const pickers = tabs.filter(t => t.name.endsWith(' ☰'));
155
- const names = new Set(pickers.map(t => t.name.slice(0, -2)));
156
- return [
157
- ...pickers.map(t => ({tab: t, name: t.name.slice(0, -2), picker: true})),
158
- ...tabs.filter(t => !t.name.endsWith(' ☰') && !names.has(t.name)).map(t => ({tab: t, name: t.name, picker: false})),
159
- ];
175
+ const tabs = data()?.tabs || [], pickers = tabs.filter(t => t.name.endsWith(' ☰')).map(tab => ({tab, name: tab.name.slice(0, -2), picker: 1}));
176
+ return [...pickers, ...tabs.filter(t => !pickers.some(p => p.tab == t || p.name == t.name)).map(tab => ({tab, name: tab.name}))];
160
177
  }
161
- function openSheet() {
162
- returnFocus = document.activeElement;
163
- kbd()?.element.blur();
164
- document.activeElement?.blur();
165
- sheetOpen = true;
166
- sheet.hidden = false;
167
- sheet.setAttribute('aria-modal', 'true');
168
- document.getElementById('terminal').setAttribute('inert', '');
178
+ function openSheet(_, s = sheet) {
179
+ returnFocus = act();
180
+ unfocus();
181
+ sheetOpen = s;
182
+ s.hidden = false;
183
+ set(id('terminal'), 'inert', '');
169
184
  search.value = '';
170
- previousCards = '';
171
185
  renderCards();
172
- sheet.querySelector('button').focus({preventScroll: true});
186
+ s.querySelector('button').focus({preventScroll: true});
173
187
  }
174
188
  function closeSheet() {
175
189
  if (!sheetOpen) return;
190
+ sheetOpen.hidden = true;
176
191
  sheetOpen = false;
177
- sheet.hidden = true;
178
- document.getElementById('terminal').removeAttribute('inert');
179
- document.activeElement?.blur();
180
- if (returnFocus?.isConnected && returnFocus.tagName === 'BUTTON') returnFocus.focus({preventScroll: true});
192
+ id('terminal').removeAttribute('inert');
193
+ act()?.blur();
194
+ if (returnFocus?.isConnected && returnFocus.tagName == 'BUTTON') returnFocus.focus({preventScroll: true});
181
195
  }
182
196
  function renderCards() {
183
- if (!sheetOpen) return;
184
- const items = workspaces();
185
- const activeName = (currentTab()?.name || '').replace(/ ☰$/, '');
186
- const query = search.value.trim().toLocaleLowerCase();
187
- const titles = items.map(w => w.picker ? pickerTitle(w.name) : '');
188
- const signature = JSON.stringify([items, titles, activeName, query]);
189
- if (signature === previousCards) return;
190
- previousCards = signature;
191
- list.replaceChildren();
192
- text(count, `${items.length} workspaces`);
193
- for (const [index, item] of items.entries()) {
194
- if (!item.name.toLocaleLowerCase().includes(query)) continue;
195
- const active = item.name === activeName;
196
- const card = make('button', `lanes-workspace${active ? ' is-current' : ''}`);
197
- aria(card, `${item.name}${active ? ', current workspace' : ''}`);
198
- if (active) card.setAttribute('aria-current', 'true');
199
- const monogram = make('span', 'lanes-monogram', Array.from(item.name)[0]?.toUpperCase() || 'L');
200
- const copy = make('span', 'lanes-workspace-copy');
201
- const small = make('small'), parts = countParts(parseCounts(titles[index]));
202
- parts.forEach(([g, n, tone], i) => small.append(i ? ' · ' : '', make('span', `lanes-tone-${tone}`, `${g} ${n}`)));
203
- if (!parts.length) small.textContent = item.picker ? 'Choose a lane' : 'Open workspace';
204
- copy.append(make('strong', '', item.name), small);
205
- const arrow = make('span', 'lanes-workspace-arrow');
206
- arrow.innerHTML = svg(active ? 'check' : 'arrow');
207
- card.append(monogram, copy, arrow);
208
- card.addEventListener('click', () => focusTab(item.tab));
209
- list.append(card);
197
+ if (sheet.hidden) return;
198
+ const items = workspaces(), activeName = bare(), query = search.value.trim().toLocaleLowerCase();
199
+ const names = JSON.stringify(items.map(w => [w.tab.name, w.tab.position]));
200
+ if (names != previousCards) {
201
+ previousCards = names;
202
+ list.replaceChildren(...items.map(({name, tab}) => {
203
+ const card = make('button', 'lanes-workspace'), copy = make('span', 'lanes-workspace-copy');
204
+ copy.append(make('strong', '', name), make('small'));
205
+ card.append(make('span', 'lanes-monogram', Array.from(name)[0]?.toUpperCase() || 'L'), copy, make('span', 'lanes-workspace-arrow'));
206
+ on(card, 'click', () => name == bare() ? closeSheet() : focusTab(tabNamed(mem.ws[name]), tab));
207
+ return card;
208
+ }), empty);
210
209
  }
211
- if (!list.childElementCount) list.append(make('p', 'lanes-empty', 'No matching workspaces'));
210
+ let shown = 0;
211
+ items.forEach((item, i) => {
212
+ const card = list.children[i], active = item.name == activeName, parts = countParts(parseCounts(item.picker && pickerTitle(item.name)));
213
+ shown += !(card.hidden = !item.name.toLocaleLowerCase().includes(query));
214
+ const said = parts.map(p => p[1] + ' ' + p[3]), sig = [active, said] + '';
215
+ if (card.s == sig) return;
216
+ card.s = sig;
217
+ card.classList.toggle('is-current', active);
218
+ aria(card, [item.name, ...said, ...active ? ['current workspace'] : []].join(', '));
219
+ set(card, 'aria-current', active);
220
+ card.querySelector('small').replaceChildren(...parts.length ? parts.flatMap(([g, n, tone, w], j) => [j ? ' · ' : '', make('span', `lanes-tone-${tone}`, `${g} ${n} ${w}`)])
221
+ : [item.picker ? 'Choose a lane' : 'Open workspace']);
222
+ card.children[2].innerHTML = svg(active ? 'check' : 'arrow');
223
+ });
224
+ empty.hidden = !!shown;
225
+ text(count, `${shown < items.length ? shown + ' of ' : ''}${items.length} workspace${items.length == 1 ? '' : 's'}`);
226
+ }
227
+ function dialog(name, head, ...body) {
228
+ const s = make('div', 'lanes-sheet'), panel = make('section', 'lanes-sheet-panel'), top = make('div', 'lanes-sheet-head'), title = make('div'), close = button('Close', 'close', closeSheet);
229
+ s.hidden = true; s.tabIndex = -1;
230
+ set(s, 'role', 'dialog'); aria(s, name); set(s, 'aria-modal', true);
231
+ title.append(make('h2', '', name), head);
232
+ close.classList.add('lanes-close'); top.append(title, close);
233
+ panel.append(top, ...body); s.append(panel);
234
+ on(s, 'click', ev => {if (ev.target == s && down == s) closeSheet();});
235
+ on(s, 'keydown', ev => {
236
+ if (ev.key == 'Escape') {keep(ev); closeSheet();}
237
+ if (ev.key != 'Tab') return;
238
+ const controls = [...s.querySelectorAll('button, input')];
239
+ if (act() == s || act() === controls.at(ev.shiftKey - 1)) {keep(ev); controls.at(-ev.shiftKey).focus();}
240
+ });
241
+ return s;
212
242
  }
213
243
  function build() {
214
244
  shell = make('div', 'lanes-shell zj-mobile-chrome');
215
245
  shell.id = 'lanes-shell';
216
246
  const header = make('header', 'lanes-header');
217
- const brand = make('img', 'lanes-brand');
218
- brand.src = '/lanes-assets/icon.svg'; brand.alt = 'Lanes';
219
247
  const context = make('button', 'lanes-context');
220
- aria(context, 'Choose workspace');
248
+ set(context, 'aria-haspopup', 'dialog');
221
249
  heading = make('strong', '', 'Lanes'); subtitle = make('span', '', 'Connecting…');
222
- context.append(heading, subtitle); context.addEventListener('click', openSheet);
223
- addEventListener('pointerdown', () => menuWas = document.querySelector('.zj-mobile-menu.zj-open'), true);
250
+ status = make('output', 'lanes-status'); set(status, 'aria-live', 'polite');
251
+ context.append(heading, ' ', subtitle); on(context, 'click', openSheet);
252
+ on(W, 'pointerdown', ev => (down = ev.target, menuWas = q('.zj-mobile-menu.zj-open'), restoring = 0), true);
224
253
  const more = button('More options', 'more', () => menuWas ? menuWas = null : nativeClick('.zj-hamburger'));
225
- const copyKey = button('Copy screen', 'copy', () => clip(c => c.writeText(screen()), () => hint('Copied')));
226
- pasteKey = button('Paste', 'paste', () => clip(c => c.readText(), t => paste(t) && hint('Pasted')));
227
- for (const b of [copyKey, pasteKey, more]) b.classList.add('lanes-more');
228
- for (const b of [copyKey, pasteKey]) b.addEventListener('mousedown', keep);
229
- header.append(brand, context, copyKey, pasteKey, more);
254
+ const copyKey = button('Copy screen', 'copy', () => clip(c => c.writeText(pre.textContent), () => hint('Copied', 8), openSheet(pre.textContent = screen(), shot, said.textContent = '')));
255
+ pasteKey = button('Paste', 'paste', () => clip(c => c.readText(), paste, at()));
256
+ const done = make('button', 'lanes-button lanes-done', 'Done');
257
+ for (const b of [copyKey, pasteKey, more]) b.classList.add('lanes-more'), b != more && on(b, 'mousedown', keep);
258
+ on(done, 'mousedown', keep); on(done, 'click', unfocus);
259
+ header.append(context, copyKey, pasteKey, done, more, status);
230
260
  dock = make('nav', 'lanes-dock'); aria(dock, 'Workspace controls');
231
- const spaces = button('Workspaces', 'workspaces', openSheet);
232
261
  lanesButton = button('Lanes', 'lanes', () => {
233
- const picker = pickerTab((currentTab()?.name || '').replace(/ ☰$/, ''));
234
- if (picker) focusTab(picker); else openSheet();
262
+ const picker = pickerTab(bare());
263
+ if (picker) focusTab(picker == currentTab() ? tabNamed(bare()) : picker); else openSheet();
235
264
  });
236
265
  panesButton = button('Panes', 'panes', () => nativeClick('.zj-pane'));
237
266
  typingField = buildTypingField();
238
267
  laneFilterBar = buildLaneFilterBar();
239
- dock.append(spaces, lanesButton, panesButton, laneFilterBar, typingField);
240
- sheet = make('div', 'lanes-sheet'); sheet.hidden = true;
241
- sheet.setAttribute('role', 'dialog'); sheet.setAttribute('aria-labelledby', 'lanes-sheet-title');
242
- const panel = make('section', 'lanes-sheet-panel');
243
- const sheetHead = make('div', 'lanes-sheet-head');
244
- const titleGroup = make('div');
245
- const title = make('h2', '', 'Workspaces'); title.id = 'lanes-sheet-title';
246
- count = make('p', '', ''); titleGroup.append(title, count);
247
- const close = button('Close workspaces', 'close', closeSheet);
248
- close.classList.add('lanes-close'); sheetHead.append(titleGroup, close);
268
+ dock.append(button('Workspaces', 'workspaces', openSheet), lanesButton, panesButton, laneFilterBar, typingField);
269
+ empty = make('p', 'lanes-empty', 'No matching workspaces');
249
270
  const searchWrap = make('label', 'lanes-search');
250
271
  searchWrap.innerHTML = svg('search');
251
- search = finder('Find a workspace', 'Find a workspace');
252
- search.addEventListener('input', renderCards); searchWrap.append(search);
272
+ search = finder('Find a workspace');
273
+ on(search, 'input', renderCards); searchWrap.append(search);
253
274
  list = make('div', 'lanes-workspaces');
254
275
  const sessionButton = make('button', 'lanes-session-link', 'Switch session');
255
- sessionButton.addEventListener('click', () => {closeSheet(); nativeClick('.zj-session');});
256
- panel.append(sheetHead, searchWrap, list, sessionButton); sheet.append(panel);
257
- sheet.addEventListener('click', ev => {if (ev.target === sheet) closeSheet();});
258
- sheet.addEventListener('keydown', ev => {
259
- if (ev.key === 'Escape') {ev.preventDefault(); closeSheet();}
260
- if (ev.key !== 'Tab') return;
261
- const controls = [...sheet.querySelectorAll('button, input')];
262
- const first = controls[0], last = controls.at(-1);
263
- if (ev.shiftKey && document.activeElement === first) {ev.preventDefault(); last.focus();}
264
- else if (!ev.shiftKey && document.activeElement === last) {ev.preventDefault(); first.focus();}
265
- });
276
+ on(sessionButton, 'click', () => {closeSheet(); nativeClick('.zj-session');});
277
+ sheet = dialog('Workspaces', count = make('output'), searchWrap, list, sessionButton);
278
+ shot = dialog('Captured screen', said = make('output'), pre = make('pre', 'lanes-shot'));
266
279
  quickRow = buildQuickRow();
267
- shell.append(header, quickRow, dock, sheet); document.body.append(shell);
268
- if (mode === 'tablet') more.before(dock);
269
- root.classList.add('lanes-ready');
270
- for (const key of document.querySelectorAll('.zj-mobile-modbar button')) {
271
- key.addEventListener('pointerdown', ev => ev.stopImmediatePropagation(), true);
272
- key.addEventListener('mousedown', keep);
280
+ shell.append(header, quickRow, dock, sheet, shot); D.body.append(shell);
281
+ if (mode == 'tablet') done.before(dock);
282
+ classes.add('lanes-ready');
283
+ const bar = q('.zj-mobile-modbar');
284
+ for (const key of bar?.children || []) {
285
+ on(key, 'pointerdown', ev => ev.stopImmediatePropagation(), true);
286
+ on(key, 'mousedown', keep);
273
287
  }
288
+ bar?.append(quickRow.lastChild); bar?.prepend(quickRow.lastChild);
274
289
  installFontControls();
275
290
  resize();
276
291
  }
277
292
  function send(...frames) {
278
- const f = kbd()?.sendFn;
293
+ const f = kbd()?.sendFn, t = at();
294
+ if (t != seen && queue.splice(0).length && laneFilterPrev) clearLaneFilter();
295
+ seen = t;
296
+ if (frames.length) note &&= !hintN && text(status, '');
279
297
  queue.push(...frames);
280
- if (f) try {
298
+ try {
299
+ if (!f || sock?.readyState - 1) throw 0;
281
300
  while (queue.length) {
282
- if (queue[0] !== null) { f(queue.shift()); sentAt = Date.now(); }
283
- else if (Date.now() - sentAt < 60) return arm();
301
+ if (queue[0] !== null) { f(queue.shift()); sentAt = now(); unacked = 1; }
302
+ else if (now() - sentAt < 60) return arm(), 2;
284
303
  else queue.shift();
285
304
  }
286
- } catch { queue.length = 0; }
305
+ return sock && !doubt ? 1 : 3;
306
+ } catch {
307
+ queue.length = 0;
308
+ if (frames.length) hint('Not sent: no connection');
309
+ return 0;
310
+ }
287
311
  }
288
- const paste = t => currentTab()?.name.endsWith(' ☰') ? hint('Open a lane to paste') :
289
- (send('\x1b[200~' + t.replace(/\x1b+(?=\[201~)/g, '').replace(/\r?\n/g, '\r') + '\x1b[201~'), 1);
290
- function applyLaneFilter(value) {
291
- const q = [...new TextDecoder().decode(new TextEncoder().encode(value).filter(b => b > 31 && b != 127))];
312
+ const paste = (t, v = at()) => {
313
+ const s = v != at() ? 'Not sent: view changed' : !t ? 'No text to paste' :
314
+ currentTab()?.name.endsWith(' ☰') ? 'Open a lane to paste' :
315
+ ['', 'Paste sent', , 'Paste unconfirmed'][send('\x1b[200~' + t.replace(/\x1b+(?=\[201~)/g, '').replace(/\r?\n/g, '\r') + '\x1b[201~')];
316
+ if (s) hint(s, s == 'Paste sent' && 8);
317
+ };
318
+ function applyLaneFilter() {
319
+ send();
320
+ const q = [...new TextDecoder().decode(new TextEncoder().encode(laneFilterInput.value).filter(b => b > 31 && b != 127))];
292
321
  const p = [...laneFilterPrev], s = q.join('');
293
- if (s === laneFilterPrev) return;
322
+ if (s == laneFilterPrev) return;
294
323
  let i = 0;
295
- while (i < p.length && p[i] === q[i]) i++;
324
+ while (i < p.length && p[i] == q[i]) i++;
296
325
  laneFilterPrev = s;
297
326
  if (!s) { clearLaneFilter(); refresh(); }
298
- else if (!p.length) send('\x1b', null, '/', s);
299
- else send('\x7f'.repeat(p.length - i) + q.slice(i).join(''));
327
+ else if (!(p.length ? send('\x7f'.repeat(p.length - i) + q.slice(i).join('')) :
328
+ (owed.delete(currentTab()?.name), send('\x1b', null, '/', s)))) clearLaneFilter();
300
329
  }
301
- async function clip(f, ok) {
302
- try { ok(await f(navigator.clipboard)); } catch { hint('Clipboard blocked'); }
330
+ async function clip(f, ok, v) {
331
+ try { ok(await f(navigator.clipboard), v); } catch { hint('Clipboard blocked'); }
303
332
  }
304
333
  function screen() {
305
334
  if (term.hasSelection()) return term.getSelection();
306
- const b = term.buffer.active, rows = [];
307
- for (let i = 0; i < term.rows; i++) rows.push(b.getLine(b.viewportY + i)?.translateToString(true));
308
- return rows.join('\n').trimEnd();
335
+ const b = term.buffer.active;
336
+ return Array.from({length: term.rows}, (_, i) => b.getLine(b.viewportY + i)?.translateToString(true)).join('\n').trimEnd();
309
337
  }
310
- function hint(s) { text(subtitle, s); hintN = 8; arm(); }
338
+ function hint(s, n) { text(status, s); text(said, s); (hintN = n || gone && 8) || (note = s); armed = 0; arm(); }
311
339
  function buildQuickRow() {
312
- const row = make('div', 'lanes-quick');
340
+ const row = make('div', 'lanes-quick'), disarm = () => armed && (armed = hintN = 0, refresh());
313
341
  row.hidden = true;
314
- for (const [label, key, name, hold] of [['⏎', '\r', 'Enter'], ['y'], ['n', 0, 0, 1], ['Esc', '\x1b'],
315
- ['^C', '\x03', 'Control C', 1], ['↑', '\x1b[A', 'Up'], ['↓', '\x1b[B', 'Down']]) {
316
- const b = make('button', hold ? 'is-destructive' : '', label);
317
- let down = -1;
342
+ for (const [label, key, name, hold] of [['⏎', '\r', 'Enter'], ['y', 0, 'Send y'], ['↑', '\x1b[A', 'Up'], ['↓', '\x1b[B', 'Down'],
343
+ ['Esc', '\x1b', 'Escape'], ['^C', '\x03', 'Control C', 1], ['Keys', openKeys], ['y', 0, 'Send y'], ['n', 0, 'Send n']]) {
344
+ const b = make('button', hold ? 'is-destructive' : '', label), go = () => key.call ? key() : send(key || label);
345
+ let down = -1, up;
318
346
  if (name) aria(b, name);
319
- b.addEventListener('mousedown', keep);
320
- b.addEventListener('pointerdown', ev => down = ev.timeStamp);
321
- for (const t of ['pointercancel', 'pointerleave']) b.addEventListener(t, () => down = -1);
322
- b.addEventListener('pointerup', ev => {
323
- if (down >= 0) !hold || ev.timeStamp - down >= 400 ? send(key || label) : hint('Hold to send');
324
- down = -1;
347
+ on(b, 'mousedown', keep);
348
+ on(b, 'keydown', ev => ev.repeat && /^( |Enter)$/.test(ev.key) && keep(ev));
349
+ on(b, 'pointerdown', ev => { down = ev.timeStamp; disarm(); });
350
+ for (const t of ['pointercancel', 'pointerleave']) on(b, t, () => down = -1);
351
+ on(b, 'pointerup', ev => {
352
+ if (down >= 0) !hold || ev.timeStamp - down >= 400 ? go() : hint('Hold to send', 8);
353
+ down = -1; up = now();
354
+ });
355
+ on(b, 'click', ev => {
356
+ if (ev.detail || now() - up < 500) return;
357
+ if (!hold) go();
358
+ else if (armed === b && hintN) disarm(), go();
359
+ else hint('Press again to send', 20), armed = b;
325
360
  });
326
361
  row.append(b);
327
362
  }
363
+ keysKey = row.children[6];
328
364
  return row;
329
365
  }
366
+ function openKeys(to) {
367
+ if (!(to = classes.toggle('lanes-keys-open', to))) for (const c of D.querySelectorAll('.zj-armed')) c.click();
368
+ set(keysKey, 'aria-expanded', to);
369
+ resize();
370
+ }
330
371
  function clearLaneFilter() {
331
372
  owed.add(filterTab);
332
373
  laneFilterPrev = laneFilterInput.value = '';
@@ -337,29 +378,25 @@ if (typeof module === 'object') module.exports = {laneShellMode};
337
378
  bar.hidden = true;
338
379
  bar.innerHTML = svg('search');
339
380
  laneFilterInput = finder('Filter lanes', 'Filter lanes in this workspace');
340
- laneFilterInput.addEventListener('input', () => applyLaneFilter(laneFilterInput.value));
341
- laneFilterInput.addEventListener('keydown', ev => {
342
- if (ev.key === 'Escape') { clearLaneFilter(); refresh(); }
343
- if (/^E(scape|nter)$/.test(ev.key)) { ev.preventDefault(); laneFilterInput.blur(); }
381
+ on(laneFilterInput, 'input', applyLaneFilter);
382
+ on(laneFilterInput, 'keydown', ev => {
383
+ if (ev.key == 'Escape') { clearLaneFilter(); refresh(); }
384
+ if (/^E(scape|nter)$/.test(ev.key)) { keep(ev); laneFilterInput.blur(); }
344
385
  });
345
386
  bar.append(laneFilterInput);
346
387
  return bar;
347
388
  }
348
389
  function updateLaneFilterBar(tab, isPicker) {
349
390
  laneFilterBar.hidden = !isPicker;
350
- if (tab !== filterTab) {
351
- const wait = queue.indexOf(null);
352
- if (wait >= 0) queue.length = wait;
353
- if (laneFilterPrev) clearLaneFilter();
354
- }
391
+ if (tab != filterTab && laneFilterPrev) clearLaneFilter();
355
392
  if (owed.delete(tab)) send('\x1b', null);
356
393
  if (isPicker) filterTab = tab;
357
394
  }
395
+ const setFont = n => { fontSize = Math.min(24, Math.max(14, Math.round(n))); applyFont(); };
358
396
  function applyFont() {
359
- term.options.fontSize = fontSize;
360
- term.options.lineHeight = 1.1;
361
- try {localStorage.setItem('lanes:font-size', String(fontSize));} catch {}
362
- text(document.getElementById('lanes-font-value'), `${fontSize} px`);
397
+ Object.assign(term.options, {fontSize, lineHeight: 1.1});
398
+ try {localStorage.getItem(fontKey) != fontSize && localStorage.setItem(fontKey, fontSize);} catch {}
399
+ text(id('lanes-font-value'), `${fontSize} px`);
363
400
  resize();
364
401
  }
365
402
  function lanesTheme() {
@@ -376,14 +413,14 @@ if (typeof module === 'object') module.exports = {laneShellMode};
376
413
  function menuRow(label, tag = 'div', more = '') {
377
414
  const row = make(tag, 'lanes-font-controls' + more);
378
415
  row.append(make('span', '', label));
379
- document.querySelector('.zj-mobile-menu')?.prepend(row);
416
+ q('.zj-mobile-menu')?.prepend(row);
380
417
  return row;
381
418
  }
382
419
  function installFontControls() {
383
420
  const row = menuRow('Text size');
384
421
  const step = (t, name, by) => { const b = make('button', '', t); aria(b, name + ' terminal text');
385
- b.addEventListener('click', () => {fontSize = Math.min(24, Math.max(14, fontSize + by)); applyFont();}); return b; };
386
- const value = make('output', '', `${fontSize} px`); value.id = 'lanes-font-value';
422
+ on(b, 'click', () => setFont(fontSize + by)); return b; };
423
+ const value = make('output'); value.id = 'lanes-font-value';
387
424
  row.append(step('A−', 'Smaller', -1), value, step('A+', 'Larger', 1));
388
425
  Object.assign(menuRow('Docs', 'a', ' lanes-session-link'), {href: '/lanes-docs/', target: '_blank'});
389
426
  fetch('/enrol/site', {credentials: 'same-origin'}).then(r => r.json())
@@ -392,49 +429,64 @@ if (typeof module === 'object') module.exports = {laneShellMode};
392
429
  function refresh() {
393
430
  if (!api || !shell) return;
394
431
  const active = !!state()?.active;
395
- root.classList.toggle('lanes-ready', active);
432
+ classes.toggle('lanes-ready', active);
396
433
  shell.hidden = !active;
397
434
  const tab = currentTab();
398
- const name = tab?.name.replace(/ ☰$/, '') || 'Lanes';
435
+ const name = bare() || 'Lanes';
399
436
  const picker = tab?.name.endsWith(' ☰');
437
+ if (tab && restoring) restoring.name ??= tab.name;
438
+ if (tab && restoring?.name != tab.name) restoring = 0;
439
+ if (!restoring && tab && (tab.name !== mem.tab || tabKey() != lastKey)) try { mem.ws[name] = mem.tab = tab.name; localStorage.setItem(lastKey = tabKey(), JSON.stringify(mem)); } catch {}
400
440
  const pane = data()?.panes.find(p => p.pane_id === data()?.active_pane?.pane_id && !p.is_plugin);
401
441
  const title = pickerTitle(name), counts = parseCounts(title);
402
442
  const chips = countParts(counts).map(([glyph, n]) => glyph + n).join(' ');
403
443
  text(heading, name);
404
- if (!hintN) text(subtitle, picker ? chips || 'Choose a lane to continue' : pane?.title || 'Your workspace');
405
- lanesButton.setAttribute('aria-pressed', String(!!picker));
406
- panesButton.hidden = pasteKey.hidden = !!picker;
444
+ text(subtitle, picker ? chips || 'Choose a lane to continue' : pane?.title || 'Your workspace');
445
+ if (!hintN) text(status, [note, 'Disconnected', 'Check last input'][gone | 0] || '');
446
+ set(lanesButton, 'aria-pressed', !!picker);
407
447
  const needs = counts ? counts.approval + counts.input : 0;
408
448
  if (needs) lanesButton.dataset.count = String(needs); else delete lanesButton.dataset.count;
409
449
  updateLaneFilterBar(tab?.name, picker);
410
450
  send();
411
- const quick = active && (!picker || / · [›>] \w+$/.test(title) && 2);
412
- if (quick !== quickOn) {
413
- quickOn = quick;
451
+ const quick = active && (!picker || / · [›>] \w+$/.test(title) && 2), v = at();
452
+ if (quick !== quickOn || v != view) {
453
+ quickOn = quick; view = v;
414
454
  quickRow.hidden = !quick;
415
- for (const key of quickRow.children) key.hidden = quick > 1 && !['⏎', 'y', 'Esc'].includes(key.textContent);
455
+ for (const key of quickRow.children) key.hidden = quick > 1 ? !['⏎', 'y', 'Esc'].includes(key.textContent) : 'yn'.includes(key.textContent);
416
456
  root.style.setProperty('--lanes-quick', quick ? '48px' : '0px');
417
- resize();
457
+ openKeys(false);
418
458
  }
419
- document.title = `${chips ? chips + ' · ' : ''}${name} · Lanes`;
459
+ if (gone && !retry) pasteKey.before(retry = make('button', 'lanes-button', 'Reconnect')), on(retry, 'click', reconnect);
460
+ panesButton.hidden = picker || !panesAt(tab?.position)[1]; pasteKey.hidden = !!picker || !!gone;
461
+ if (typingField) typingField.style.gridColumn = panesButton.hidden && !picker ? 'span 2' : '';
462
+ for (const c of ['ctrl', 'alt']) q(`[data-cell=${c}]`)?.setAttribute('aria-pressed', !!state()?.armed?.[c]);
463
+ D.title = `${chips ? chips + ' · ' : ''}${name} · Lanes`;
420
464
  renderCards();
421
465
  }
422
466
  function connect() {
423
- if (api || !window.__zjMobileUi || !window.term || !kbd()?.element) return;
424
- if (!window.__zjMobileUi.getState()?.data?.tabs?.length) return;
425
- api = window.__zjMobileUi; term = window.term;
426
- build(); applyFont(); applyTheme();
427
- const sync = window.__zjSyncInactiveCursorStyle;
467
+ if (api || !W.term || !kbd()?.element || !W.__zjMobileUi?.getState()?.data?.tabs?.length) return;
468
+ api = W.__zjMobileUi; term = W.term;
469
+ const k = kbd(), f = k.sendFn;
470
+ k.sendFn = b => sock?.readyState - 1 ? hint('Not sent: no connection') : (f(b), sentAt = now(), unacked = 1);
471
+ build(hintN = gone && 2);
472
+ try { if (sessionStorage.getItem('lanes:unsure')) sessionStorage.removeItem('lanes:unsure'), note = 'Check last input', hintN = 2; } catch {}
473
+ const ws = new URLSearchParams(W.location?.search).get('ws');
474
+ try { const kept = JSON.parse(localStorage.getItem(tabKey())); mem = {tab: kept.tab, ws: {...kept.ws}}; } catch {}
475
+ const saved = ws && pickerTab(ws) || tabNamed(mem.tab);
476
+ if (saved && saved != currentTab()) restoring = {}, focusTab(saved);
477
+ applyFont(); applyTheme();
478
+ on(W, 'zellij:rendering-resize', () => term.options.fontSize != fontSize && setFont(term.options.fontSize));
479
+ const sync = W.__zjSyncInactiveCursorStyle;
428
480
  window.__zjSyncInactiveCursorStyle = () => { sync?.(); applyTheme(); };
429
481
  new MutationObserver(applyTheme).observe(root, {attributes: true, attributeFilter: ['data-zj-theme']});
430
482
  const setData = api.setData;
431
- api.setData = function(value) {setData.call(api, value); refresh();};
432
- const nativeRoot = document.getElementById('zj-mobile-root');
433
- new MutationObserver(refresh).observe(nativeRoot, {attributes: true, attributeFilter: ['class'], subtree: true});
434
- refresh(); viewport();
483
+ api.setData = function(value) {setData.call(api, value); if (doubt) doubt = hintN = 0; refresh();};
484
+ new MutationObserver(refresh).observe(id('zj-mobile-root'), {attributes: true, attributeFilter: ['class'], subtree: true});
485
+ ws && history.replaceState(null, '', location.pathname + location.hash);
486
+ refresh(); viewport(); js('/lanes-assets/links.js');
435
487
  }
436
488
  function styleLogin() {
437
- const token = document.getElementById('token');
489
+ const token = id('token');
438
490
  if (!token || token.dataset.lanes) return;
439
491
  token.dataset.lanes = 'true';
440
492
  token.autocomplete = 'current-password'; aria(token, 'Login token');
@@ -443,18 +495,25 @@ if (typeof module === 'object') module.exports = {laneShellMode};
443
495
  box.querySelector('.submit-btn').textContent = 'Connect';
444
496
  }
445
497
  viewport();
446
- window.addEventListener('resize', viewport);
447
- window.visualViewport?.addEventListener('resize', viewport);
448
- window.visualViewport?.addEventListener('scroll', viewport);
449
- window.addEventListener('zellij:soft-keyboard-visibility', () => {
498
+ for (const t of [W, W.visualViewport]) t?.addEventListener('resize', viewport);
499
+ W.visualViewport?.addEventListener('scroll', viewport);
500
+ on(W, 'pagehide', () => away = hid = 1);
501
+ on(W, 'pageshow', () => { away = 0; back(); });
502
+ on(D, 'visibilitychange', () => {
503
+ if (D.hidden) return hiddenAt = now();
504
+ if (api && sock?.readyState == 1 && now() - hiddenAt > 3e4) doubt = 25, hint('Reconnecting…', 25);
505
+ back();
506
+ });
507
+ on(W, 'online', back);
508
+ on(W, 'zellij:soft-keyboard-visibility', () => {
450
509
  viewport();
451
- requestAnimationFrame(() => window.__zjSendControl?.({
452
- type: 'SoftKeyboardVisibilityChanged', visible: root.classList.contains('lanes-keyboard'),
510
+ requestAnimationFrame(() => W.__zjSendControl?.({
511
+ type: 'SoftKeyboardVisibilityChanged', visible: classes.contains('lanes-keyboard'),
453
512
  }));
454
513
  });
455
- document.addEventListener('focusout', () => requestAnimationFrame(viewport));
456
- new MutationObserver(() => {styleLogin(); connect();}).observe(document.body, {childList: true});
457
- function tick() { connect(); send(); if (hintN && !--hintN) refresh(); if (api && !hintN && queue[0] !== null) timer = clearInterval(timer); }
514
+ on(D, 'focusout', () => requestAnimationFrame(viewport));
515
+ new MutationObserver(() => {styleLogin(); connect();}).observe(D.body, {childList: true});
516
+ function tick() { connect(); send(); if (hintN && !--hintN) refresh(); if (doubt && !--doubt) reconnect(); if (api && !hintN && !doubt && queue[0] !== null) timer = clearInterval(timer); }
458
517
  function arm() { timer ||= setInterval(tick, 200); }
459
518
  arm(); styleLogin(); connect();
460
519
  })();