@brett_lamy/ui 5.10.0 → 5.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/avatar.d.ts +4 -1
- package/dist/components/avatar.d.ts.map +1 -1
- package/dist/components/avatar.js +55 -47
- package/dist/components/canvas.d.ts +18 -0
- package/dist/components/canvas.d.ts.map +1 -1
- package/dist/components/canvas.js +79 -11
- package/dist/components/command-menu.js +1 -1
- package/dist/components/floating-chat.d.ts +1 -1
- package/dist/components/floating-sheet.d.ts +1 -1
- package/dist/components/hover-card.d.ts +69 -0
- package/dist/components/hover-card.d.ts.map +1 -0
- package/dist/components/hover-card.js +164 -0
- package/dist/components/list.d.ts +3 -0
- package/dist/components/list.d.ts.map +1 -1
- package/dist/components/list.js +265 -250
- package/dist/components/markdown-view.d.ts +3 -1
- package/dist/components/markdown-view.d.ts.map +1 -1
- package/dist/components/markdown-view.js +12 -11
- package/dist/components/open-code.d.ts +31 -0
- package/dist/components/open-code.d.ts.map +1 -0
- package/dist/components/open-code.js +253 -0
- package/dist/components/replay-preview.d.ts +2 -2
- package/dist/components/replay-preview.d.ts.map +1 -1
- package/dist/components/replay-preview.js +3 -3
- package/dist/components/sql-console.js +1 -1
- package/dist/components/tree.d.ts +4 -1
- package/dist/components/tree.d.ts.map +1 -1
- package/dist/components/tree.js +229 -202
- package/dist/components/tui-preview.d.ts +3 -0
- package/dist/components/tui-preview.d.ts.map +1 -0
- package/dist/components/tui-preview.js +3 -0
- package/dist/components/workspace.d.ts +11 -0
- package/dist/components/workspace.d.ts.map +1 -0
- package/dist/components/workspace.js +74 -0
- package/dist/index.css +1 -1
- package/dist/index.d.ts +17 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +163 -156
- package/dist/lib/canvas-math.d.ts +1 -1
- package/dist/lib/canvas-math.d.ts.map +1 -1
- package/dist/lib/canvas-math.js +1 -1
- package/dist/lib/open-code-browser-agent.d.ts +7 -0
- package/dist/lib/open-code-browser-agent.d.ts.map +1 -0
- package/dist/lib/open-code-browser-agent.js +161 -0
- package/dist/lib/open-code-browser.d.ts +17 -0
- package/dist/lib/open-code-browser.d.ts.map +1 -0
- package/dist/lib/open-code-browser.js +252 -0
- package/dist/lib/open-code-host.d.ts +182 -0
- package/dist/lib/open-code-host.d.ts.map +1 -0
- package/dist/lib/open-code-host.js +118 -0
- package/dist/lib/open-code-keychain.d.ts +11 -0
- package/dist/lib/open-code-keychain.d.ts.map +1 -0
- package/dist/lib/open-code-keychain.js +19 -0
- package/dist/lib/open-code-preview.d.ts +16 -0
- package/dist/lib/open-code-preview.d.ts.map +1 -0
- package/dist/lib/open-code-preview.js +112 -0
- package/dist/lib/tailscale-connect.d.ts.map +1 -1
- package/dist/lib/tailscale-connect.js +97 -62
- package/dist/lib/tailscale-policy.d.ts +11 -2
- package/dist/lib/tailscale-policy.d.ts.map +1 -1
- package/dist/lib/tailscale-policy.js +27 -18
- package/dist/lib/tailscale-router/bridge.d.ts +7 -2
- package/dist/lib/tailscale-router/bridge.d.ts.map +1 -1
- package/dist/lib/tailscale-router/bridge.js +64 -57
- package/dist/lib/theme.d.ts.map +1 -1
- package/dist/lib/theme.js +8 -5
- package/dist/opencode.d.ts +7 -0
- package/dist/opencode.d.ts.map +1 -0
- package/dist/opencode.js +6 -0
- package/dist/tailscale-sw.js +237 -12
- package/package.json +21 -3
package/dist/tailscale-sw.js
CHANGED
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
|
|
22
22
|
const DEFAULT_POLICY = {
|
|
23
23
|
v: 1, intercept: 'tailnet', hosts: [], cidrs: [], shortNames: false, exclude: [], schemes: ['http', 'https'], methods: null,
|
|
24
|
-
sameOrigin: false, whenUnavailable: 'network', maxBodyBytes: 32 * 1024 * 1024, timeoutMs: 60000,
|
|
24
|
+
sameOrigin: false, whenUnavailable: 'network', maxBodyBytes: 32 * 1024 * 1024, timeoutMs: 60000, proxyPath: null,
|
|
25
25
|
};
|
|
26
26
|
|
|
27
27
|
function parseIPv4(text) {
|
|
@@ -118,6 +118,7 @@
|
|
|
118
118
|
const host = u.hostname.toLowerCase();
|
|
119
119
|
const addr = parseAddress(host);
|
|
120
120
|
if (host === 'localhost' || host.endsWith('.localhost') || (addr && (inCidr(addr, LOOPBACK_V4) || inCidr(addr, LOOPBACK_V6)))) return { route: false, reason: 'loopback' };
|
|
121
|
+
if (/(^|\.)tailscale\.(com|io)$/.test(host)) return { route: false, reason: 'tailscale' };
|
|
121
122
|
if (policy.methods && policy.methods.indexOf(method.toUpperCase()) < 0) return { route: false, reason: 'method' };
|
|
122
123
|
if (hostIn(host, addr, policy.exclude)) return { route: false, reason: 'excluded' };
|
|
123
124
|
if (policy.intercept === 'all') return { route: true, reason: 'all' };
|
|
@@ -141,6 +142,7 @@
|
|
|
141
142
|
for (const k in DEFAULT_POLICY) out[k] = parsed[k] !== undefined ? parsed[k] : DEFAULT_POLICY[k];
|
|
142
143
|
if (out.intercept !== 'all') out.intercept = 'tailnet';
|
|
143
144
|
if (out.whenUnavailable !== 'error') out.whenUnavailable = 'network';
|
|
145
|
+
if (typeof out.proxyPath !== 'string' || !/^[A-Za-z0-9_-]+\/$/.test(out.proxyPath)) out.proxyPath = null;
|
|
144
146
|
return out;
|
|
145
147
|
} catch {
|
|
146
148
|
return DEFAULT_POLICY;
|
|
@@ -225,6 +227,164 @@
|
|
|
225
227
|
}
|
|
226
228
|
});
|
|
227
229
|
|
|
230
|
+
/* ── proxied sites (policy.proxyPath) ── */
|
|
231
|
+
|
|
232
|
+
const PROXY_PREFIX = policy.proxyPath && sw.registration ? new URL(policy.proxyPath, sw.registration.scope).href : null;
|
|
233
|
+
// Response headers that would stop a proxied page from being framed here or from running its scripts on this origin.
|
|
234
|
+
const STRIPPED = {
|
|
235
|
+
'content-security-policy': 1, 'content-security-policy-report-only': 1, 'x-frame-options': 1, 'set-cookie': 1,
|
|
236
|
+
'cross-origin-opener-policy': 1, 'cross-origin-embedder-policy': 1, 'cross-origin-resource-policy': 1, 'strict-transport-security': 1,
|
|
237
|
+
};
|
|
238
|
+
const tailscaleHost = function (host) { return /(^|\.)tailscale\.(com|io)$/.test(host); };
|
|
239
|
+
|
|
240
|
+
/** The site a proxy address loads (`<scope><proxyPath>https/example.com/a` → `https://example.com/a`), or null. */
|
|
241
|
+
function proxyTarget(url) {
|
|
242
|
+
if (!PROXY_PREFIX || url.indexOf(PROXY_PREFIX) !== 0) return null;
|
|
243
|
+
const m = /^(https?)\/([^/?#]+)(.*)$/.exec(url.slice(PROXY_PREFIX.length));
|
|
244
|
+
if (!m) return null;
|
|
245
|
+
const rest = m[3] || '';
|
|
246
|
+
return m[1] + '://' + m[2] + (rest.charAt(0) === '/' ? rest : '/' + rest);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
/** A URL on this origin as the proxied site would have it (`/watch?v=1` → `https://www.youtube.com/watch?v=1`). */
|
|
250
|
+
function siteUrl(url, origin) {
|
|
251
|
+
try {
|
|
252
|
+
const u = new URL(url);
|
|
253
|
+
const site = proxyTarget(u.href);
|
|
254
|
+
if (site) return site;
|
|
255
|
+
return u.origin === sw.location.origin ? origin + u.pathname + u.search : u.href;
|
|
256
|
+
} catch { return null; }
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// Which clients (frames) show which site. Kept in the Cache API too: the browser stops an idle worker, and the frame lives on.
|
|
260
|
+
const frames = new Map();
|
|
261
|
+
const notFrames = new Set();
|
|
262
|
+
const FRAME_CACHE = 'bl-ts-frames-v1';
|
|
263
|
+
let hasFrameCache = false;
|
|
264
|
+
const frameKey = function (id) { return new Request(sw.location.origin + '/__bl-ts-frame/' + encodeURIComponent(id)); };
|
|
265
|
+
if (PROXY_PREFIX && typeof caches !== 'undefined') caches.has(FRAME_CACHE).then(function (yes) { hasFrameCache = yes; }, function () { /* no Cache API here */ });
|
|
266
|
+
|
|
267
|
+
function rememberFrame(id, origin) {
|
|
268
|
+
if (!id) return;
|
|
269
|
+
frames.set(id, origin);
|
|
270
|
+
notFrames.delete(id);
|
|
271
|
+
if (typeof caches === 'undefined') return;
|
|
272
|
+
hasFrameCache = true;
|
|
273
|
+
caches.open(FRAME_CACHE).then(function (c) { return c.put(frameKey(id), new Response(origin)); }).catch(function () { /* kept in memory only */ });
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
function lookupFrame(id) {
|
|
277
|
+
if (!id) return Promise.resolve(null);
|
|
278
|
+
if (frames.has(id)) return Promise.resolve(frames.get(id));
|
|
279
|
+
if (typeof caches === 'undefined') return Promise.resolve(null);
|
|
280
|
+
return caches.open(FRAME_CACHE)
|
|
281
|
+
.then(function (c) { return c.match(frameKey(id)); })
|
|
282
|
+
.then(function (r) { return r ? r.text() : null; })
|
|
283
|
+
.then(function (origin) { if (origin) frames.set(id, origin); return origin; })
|
|
284
|
+
.catch(function () { return null; });
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
sw.addEventListener('activate', function (event) {
|
|
288
|
+
// Forget frames whose windows are gone.
|
|
289
|
+
if (typeof caches === 'undefined') return;
|
|
290
|
+
event.waitUntil(caches.open(FRAME_CACHE).then(function (c) {
|
|
291
|
+
return Promise.all([c.keys(), sw.clients.matchAll({ includeUncontrolled: true })]).then(function (got) {
|
|
292
|
+
const live = {};
|
|
293
|
+
got[1].forEach(function (cl) { live[cl.id] = 1; });
|
|
294
|
+
return Promise.all(got[0].map(function (req) {
|
|
295
|
+
const id = decodeURIComponent(req.url.split('/__bl-ts-frame/')[1] || '');
|
|
296
|
+
return live[id] ? null : c.delete(req);
|
|
297
|
+
}));
|
|
298
|
+
});
|
|
299
|
+
}).catch(function () { /* nothing to forget */ }));
|
|
300
|
+
});
|
|
301
|
+
|
|
302
|
+
/** A value as a JavaScript literal that is safe inside an inline <script> (no "</script>" can end it early). */
|
|
303
|
+
const literal = function (v) { return JSON.stringify(v).replace(/</g, '\\u003c'); };
|
|
304
|
+
|
|
305
|
+
/** An error page for a proxied frame (a document) or a plain error response (anything else). */
|
|
306
|
+
function failed(proxy, status, message) {
|
|
307
|
+
if (!proxy.document) return new Response(message, { status: status, headers: { 'content-type': 'text/plain; charset=utf-8', 'x-bl-tailscale': 'error' } });
|
|
308
|
+
const esc = function (text) { return String(text).replace(/[&<>"]/g, function (c) { return { '&': '&', '<': '<', '>': '>', '"': '"' }[c]; }); };
|
|
309
|
+
const html = '<!doctype html><meta charset="utf-8"><title>Can\u2019t open the page</title><body style="font:15px system-ui;margin:3em;color:#555">'
|
|
310
|
+
+ '<h1 style="font-size:20px;color:#222">Can\u2019t open ' + esc(proxy.url) + '</h1><p>' + esc(message) + '</p>'
|
|
311
|
+
+ '<script>parent.postMessage({ type: "bl-tailnet-frame", url: ' + literal(proxy.url) + ', title: document.title, error: ' + literal(String(message)) + ' }, location.origin)</script>';
|
|
312
|
+
return new Response(html, { status: status, headers: { 'content-type': 'text/html; charset=utf-8', 'x-bl-tailscale': 'error' } });
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
/** Runs first in every proxied page: the page sees its own path (not the proxy address), its links and forms stay in the
|
|
316
|
+
* proxy, and the embedding page hears where it is and what it is called. Its origin stays this one: that is the limit. */
|
|
317
|
+
function frameScript(PREFIX, START) {
|
|
318
|
+
const here = location.origin;
|
|
319
|
+
const site = new URL(START).origin;
|
|
320
|
+
const real = function (u) {
|
|
321
|
+
const x = new URL(u, location.href);
|
|
322
|
+
if (x.origin !== here) return x.href;
|
|
323
|
+
if (x.href.indexOf(PREFIX) === 0) return null;
|
|
324
|
+
return site + x.pathname + x.search + x.hash;
|
|
325
|
+
};
|
|
326
|
+
const proxy = function (u) { const x = new URL(u); return PREFIX + x.protocol.slice(0, -1) + '/' + x.host + x.pathname + x.search + x.hash; };
|
|
327
|
+
const start = new URL(START);
|
|
328
|
+
try { history.replaceState(history.state, '', start.pathname + start.search + (location.hash || start.hash)); } catch (e) { /* keep the proxy address */ }
|
|
329
|
+
let last = '';
|
|
330
|
+
const report = function () {
|
|
331
|
+
const url = real(location.href) || START;
|
|
332
|
+
const key = url + '\n' + document.title;
|
|
333
|
+
if (key === last) return;
|
|
334
|
+
last = key;
|
|
335
|
+
try { parent.postMessage({ type: 'bl-tailnet-frame', url: url, title: document.title }, here); } catch (e) { /* no parent */ }
|
|
336
|
+
};
|
|
337
|
+
['pushState', 'replaceState'].forEach(function (k) {
|
|
338
|
+
const f = history[k];
|
|
339
|
+
history[k] = function (...args) { const r = f.apply(this, args); report(); return r; };
|
|
340
|
+
});
|
|
341
|
+
addEventListener('popstate', report);
|
|
342
|
+
addEventListener('hashchange', report);
|
|
343
|
+
addEventListener('DOMContentLoaded', report);
|
|
344
|
+
addEventListener('load', report);
|
|
345
|
+
setInterval(report, 1000);
|
|
346
|
+
const http = function (u) { return u && /^https?:/i.test(u); };
|
|
347
|
+
addEventListener('click', function (e) {
|
|
348
|
+
if (e.defaultPrevented || e.button !== 0) return;
|
|
349
|
+
const a = e.target && e.target.closest ? e.target.closest('a[href]') : null;
|
|
350
|
+
if (!a || a.hasAttribute('download')) return;
|
|
351
|
+
const href = a.getAttribute('href') || '';
|
|
352
|
+
if (href.charAt(0) === '#' || /^(javascript|mailto|tel):/i.test(href)) return;
|
|
353
|
+
const r = real(a.href);
|
|
354
|
+
if (!http(r)) return;
|
|
355
|
+
e.preventDefault();
|
|
356
|
+
if (a.target === '_blank' || e.metaKey || e.ctrlKey || e.shiftKey) parent.postMessage({ type: 'bl-tailnet-open', url: r }, here);
|
|
357
|
+
else if (a.target === '_top' || a.target === '_parent') parent.postMessage({ type: 'bl-tailnet-go', url: r }, here);
|
|
358
|
+
else location.href = proxy(r);
|
|
359
|
+
});
|
|
360
|
+
addEventListener('submit', function (e) {
|
|
361
|
+
const f = e.target;
|
|
362
|
+
if (!f || !f.getAttribute) return;
|
|
363
|
+
const r = real(f.getAttribute('action') ? f.action : location.href);
|
|
364
|
+
if (http(r)) f.setAttribute('action', proxy(r));
|
|
365
|
+
f.removeAttribute('target');
|
|
366
|
+
}, true);
|
|
367
|
+
window.open = function (u) {
|
|
368
|
+
if (u) { const r = real(String(u)); if (http(r)) parent.postMessage({ type: 'bl-tailnet-open', url: r }, here); }
|
|
369
|
+
return null;
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
/** The document's bytes with the frame script as the first thing in it. */
|
|
374
|
+
function withFrameScript(chunks, url) {
|
|
375
|
+
let size = 0;
|
|
376
|
+
chunks.forEach(function (c) { size += c.byteLength; });
|
|
377
|
+
const all = new Uint8Array(size);
|
|
378
|
+
let at = 0;
|
|
379
|
+
chunks.forEach(function (c) { all.set(c, at); at += c.byteLength; });
|
|
380
|
+
const text = new TextDecoder().decode(all);
|
|
381
|
+
const tag = '<script>(' + frameScript.toString() + ')(' + literal(PROXY_PREFIX) + ',' + literal(url) + ')</script>';
|
|
382
|
+
const head = /<head[^>]*>/i.exec(text);
|
|
383
|
+
const doctype = /^\s*<!doctype[^>]*>/i.exec(text);
|
|
384
|
+
const at2 = head ? head.index + head[0].length : doctype ? doctype[0].length : 0;
|
|
385
|
+
return text.slice(0, at2) + tag + text.slice(at2);
|
|
386
|
+
}
|
|
387
|
+
|
|
228
388
|
/* ── requests ── */
|
|
229
389
|
|
|
230
390
|
const NULL_BODY = { 101: 1, 103: 1, 204: 1, 205: 1, 304: 1 };
|
|
@@ -250,17 +410,25 @@
|
|
|
250
410
|
headers.append('vary', 'Origin');
|
|
251
411
|
}
|
|
252
412
|
|
|
253
|
-
function route(event) {
|
|
413
|
+
function route(event, proxy) {
|
|
254
414
|
const request = event.request;
|
|
415
|
+
const target = proxy ? proxy.url : request.url;
|
|
255
416
|
const bodyPromise = request.method === 'GET' || request.method === 'HEAD' ? Promise.resolve(null) : request.clone().arrayBuffer();
|
|
256
417
|
return Promise.all([bodyPromise, waitForOwner(1500)]).then(function (got) {
|
|
257
418
|
const body = got[0];
|
|
258
419
|
const owner = got[1];
|
|
259
|
-
|
|
260
|
-
if (
|
|
420
|
+
// A proxied page has no public network to fall back to: its relative URLs only mean something on the site it shows.
|
|
421
|
+
if (body && body.byteLength > policy.maxBodyBytes) return proxy ? failed(proxy, 413, 'The request body is too large to send through the tailnet.') : unavailable(request, 'request body too large');
|
|
422
|
+
if (!owner) return proxy ? failed(proxy, 503, 'No tab is connected to Tailscale.') : unavailable(request, 'no connected page');
|
|
261
423
|
const id = nextId++;
|
|
262
424
|
const headers = [];
|
|
263
425
|
request.headers.forEach(function (v, k) { if (k !== 'cookie') headers.push([k, v]); });
|
|
426
|
+
if (proxy) {
|
|
427
|
+
// The site sees itself as the origin and referrer, not this page.
|
|
428
|
+
const ref = request.referrer && request.referrer !== 'about:client' ? siteUrl(request.referrer, proxy.frameOrigin) : null;
|
|
429
|
+
if (ref) headers.push(['referer', ref]);
|
|
430
|
+
if (request.mode === 'cors' || (request.method !== 'GET' && request.method !== 'HEAD')) headers.push(['origin', proxy.frameOrigin]);
|
|
431
|
+
}
|
|
264
432
|
return new Promise(function (resolve, reject) {
|
|
265
433
|
let controller = null;
|
|
266
434
|
let settled = false;
|
|
@@ -277,16 +445,30 @@
|
|
|
277
445
|
owner.port.postMessage({ type: 'cancel', id: id });
|
|
278
446
|
};
|
|
279
447
|
if (request.signal) request.signal.addEventListener('abort', cancel);
|
|
448
|
+
let page = null; // a proxied HTML document, gathered whole so the frame script can go in first
|
|
280
449
|
pending.set(id, {
|
|
281
450
|
handle: function (m) {
|
|
282
451
|
if (m.type === 'head') {
|
|
283
452
|
settled = true;
|
|
284
453
|
clearTimeout(timer);
|
|
285
454
|
const h = new Headers();
|
|
286
|
-
(m.headers || []).forEach(function (pair) {
|
|
455
|
+
(m.headers || []).forEach(function (pair) {
|
|
456
|
+
if (proxy && STRIPPED[pair[0].toLowerCase()]) return;
|
|
457
|
+
try { h.append(pair[0], pair[1]); } catch { /* forbidden */ }
|
|
458
|
+
});
|
|
287
459
|
h.set('x-bl-tailscale', 'routed');
|
|
288
460
|
withCors(h, request);
|
|
289
461
|
const status = m.status >= 200 && m.status <= 599 ? m.status : 502;
|
|
462
|
+
if (proxy && proxy.document) {
|
|
463
|
+
const finalUrl = typeof m.url === 'string' && /^https?:/.test(m.url) ? m.url : proxy.url;
|
|
464
|
+
rememberFrame(event.resultingClientId, new URL(finalUrl).origin);
|
|
465
|
+
if (/html/i.test(h.get('content-type') || '') || !h.get('content-type')) {
|
|
466
|
+
h.set('content-type', 'text/html; charset=utf-8');
|
|
467
|
+
h.delete('content-length');
|
|
468
|
+
page = { chunks: [], status: status, statusText: m.statusText || '', headers: h, url: finalUrl, resolve: resolve };
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
290
472
|
const stream = NULL_BODY[status] || request.method === 'HEAD' ? null : new ReadableStream({
|
|
291
473
|
start: function (c) { controller = c; },
|
|
292
474
|
cancel: cancel,
|
|
@@ -294,25 +476,30 @@
|
|
|
294
476
|
if (!stream) pending.delete(id);
|
|
295
477
|
resolve(new Response(stream, { status: status, statusText: m.statusText || '', headers: h }));
|
|
296
478
|
} else if (m.type === 'chunk') {
|
|
297
|
-
if (
|
|
479
|
+
if (page && m.data) page.chunks.push(new Uint8Array(m.data));
|
|
480
|
+
else if (controller && m.data) controller.enqueue(new Uint8Array(m.data));
|
|
298
481
|
} else if (m.type === 'end') {
|
|
299
482
|
pending.delete(id);
|
|
300
|
-
if (
|
|
483
|
+
if (page) page.resolve(new Response(withFrameScript(page.chunks, page.url), { status: page.status, statusText: page.statusText, headers: page.headers }));
|
|
484
|
+
else if (controller) controller.close();
|
|
301
485
|
} else if (m.type === 'error') {
|
|
302
486
|
pending.delete(id);
|
|
303
487
|
clearTimeout(timer);
|
|
304
|
-
if (
|
|
305
|
-
else if (
|
|
488
|
+
if (page) page.resolve(failed(proxy, 502, m.message || 'Tailscale request failed'));
|
|
489
|
+
else if (controller) controller.error(new TypeError(m.message || 'Tailscale request failed'));
|
|
490
|
+
else if (!settled) { settled = true; resolve(proxy && proxy.document ? failed(proxy, 502, m.message || 'Tailscale request failed') : Promise.reject(new TypeError(m.message || 'Tailscale request failed'))); }
|
|
306
491
|
} else if (m.type === 'passthrough' || m.type === 'unavailable') {
|
|
307
492
|
pending.delete(id);
|
|
308
493
|
clearTimeout(timer);
|
|
309
|
-
if (!settled) { settled = true; resolve(m.type === 'passthrough' ? fetch(request) : unavailable(request, 'disconnected')); }
|
|
494
|
+
if (!settled) { settled = true; resolve(proxy ? failed(proxy, 503, 'Tailscale is not connected.') : m.type === 'passthrough' ? fetch(request) : unavailable(request, 'disconnected')); }
|
|
310
495
|
}
|
|
311
496
|
},
|
|
312
497
|
});
|
|
313
498
|
const message = {
|
|
314
|
-
type: 'request', id: id, url:
|
|
315
|
-
|
|
499
|
+
type: 'request', id: id, url: target, method: request.method, headers: headers, body: body,
|
|
500
|
+
// A document is fetched as GET by the frame; redirects are followed in the page so the frame learns where it ended up.
|
|
501
|
+
redirect: proxy && proxy.document ? 'follow' : request.redirect, credentials: request.credentials, mode: request.mode, destination: request.destination,
|
|
502
|
+
proxied: !!proxy,
|
|
316
503
|
};
|
|
317
504
|
owner.port.postMessage(message, body ? [body] : []);
|
|
318
505
|
});
|
|
@@ -321,6 +508,44 @@
|
|
|
321
508
|
|
|
322
509
|
sw.addEventListener('fetch', function (event) {
|
|
323
510
|
const request = event.request;
|
|
511
|
+
if (PROXY_PREFIX) {
|
|
512
|
+
const site = proxyTarget(request.url);
|
|
513
|
+
if (site) {
|
|
514
|
+
// A frame opening a site through the tailnet (or a resource asked for by its proxy address).
|
|
515
|
+
const isDocument = request.mode === 'navigate' || request.destination === 'iframe' || request.destination === 'document';
|
|
516
|
+
event.respondWith(lookupFrame(event.clientId).then(function (origin) {
|
|
517
|
+
return route(event, { url: site, frameOrigin: isDocument ? new URL(site).origin : origin || new URL(site).origin, document: isDocument });
|
|
518
|
+
}));
|
|
519
|
+
return;
|
|
520
|
+
}
|
|
521
|
+
if (request.mode !== 'navigate' && event.clientId && !notFrames.has(event.clientId)) {
|
|
522
|
+
// Is this request from a proxied page? Everything it asks for goes through the tailnet; its own-origin URLs mean its site.
|
|
523
|
+
const known = frames.get(event.clientId);
|
|
524
|
+
const forFrame = function (origin) {
|
|
525
|
+
if (!origin) {
|
|
526
|
+
notFrames.add(event.clientId);
|
|
527
|
+
return null;
|
|
528
|
+
}
|
|
529
|
+
const u = new URL(request.url);
|
|
530
|
+
if (u.protocol !== 'http:' && u.protocol !== 'https:') return null;
|
|
531
|
+
const url = u.origin === sw.location.origin ? origin + u.pathname + u.search : u.href;
|
|
532
|
+
if (tailscaleHost(new URL(url).hostname)) return null;
|
|
533
|
+
return { url: url, frameOrigin: origin, document: false };
|
|
534
|
+
};
|
|
535
|
+
if (known) {
|
|
536
|
+
const proxy = forFrame(known);
|
|
537
|
+
if (proxy) { event.respondWith(route(event, proxy)); return; }
|
|
538
|
+
} else if (frames.size || hasFrameCache) {
|
|
539
|
+
// Not seen since this worker started: ask the cache (it outlives the worker), else let the request through untouched.
|
|
540
|
+
event.respondWith(lookupFrame(event.clientId).then(function (origin) {
|
|
541
|
+
const proxy = forFrame(origin);
|
|
542
|
+
if (proxy) return route(event, proxy);
|
|
543
|
+
return match(request.url, request.method, policy, sw.location.origin).route ? route(event) : fetch(request);
|
|
544
|
+
}));
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
}
|
|
548
|
+
}
|
|
324
549
|
if (request.mode === 'navigate') return; // a navigation is the page itself, never the tailnet's
|
|
325
550
|
const m = match(request.url, request.method, policy, sw.location.origin);
|
|
326
551
|
if (!m.route) return; // not ours: the browser handles it as if there were no worker
|
package/package.json
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@brett_lamy/ui",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.13.0",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "git+https://github.com/BLamy/ui.git",
|
|
7
|
+
"directory": "packages/ui"
|
|
8
|
+
},
|
|
4
9
|
"type": "module",
|
|
5
10
|
"main": "./dist/index.js",
|
|
6
11
|
"module": "./dist/index.js",
|
|
@@ -21,6 +26,18 @@
|
|
|
21
26
|
"@org/source": "./src/theme.css",
|
|
22
27
|
"default": "./dist/theme.css"
|
|
23
28
|
},
|
|
29
|
+
"./tui": {
|
|
30
|
+
"@org/source": "./src/components/tui-preview.tsx",
|
|
31
|
+
"types": "./dist/components/tui-preview.d.ts",
|
|
32
|
+
"import": "./dist/components/tui-preview.js",
|
|
33
|
+
"default": "./dist/components/tui-preview.js"
|
|
34
|
+
},
|
|
35
|
+
"./opencode": {
|
|
36
|
+
"@org/source": "./src/opencode.ts",
|
|
37
|
+
"types": "./dist/opencode.d.ts",
|
|
38
|
+
"import": "./dist/opencode.js",
|
|
39
|
+
"default": "./dist/opencode.js"
|
|
40
|
+
},
|
|
24
41
|
"./tailscale-sw.js": {
|
|
25
42
|
"@org/source": "./src/lib/tailscale-router/tailscale-sw.js",
|
|
26
43
|
"default": "./dist/tailscale-sw.js"
|
|
@@ -31,8 +48,8 @@
|
|
|
31
48
|
}
|
|
32
49
|
},
|
|
33
50
|
"dependencies": {
|
|
34
|
-
"@brett_lamy/docstream": "1.
|
|
35
|
-
"@brett_lamy/docstream-editor": "1.
|
|
51
|
+
"@brett_lamy/docstream": "1.34.4",
|
|
52
|
+
"@brett_lamy/docstream-editor": "1.34.4",
|
|
36
53
|
"@internationalized/date": "^3.12.4",
|
|
37
54
|
"@pierre/trees": "1.0.0-beta.6",
|
|
38
55
|
"@tiptap/core": "3.30.5",
|
|
@@ -54,6 +71,7 @@
|
|
|
54
71
|
"perfect-freehand": "^1.2.2",
|
|
55
72
|
"react-aria": "^3.51.0",
|
|
56
73
|
"react-aria-components": "^1",
|
|
74
|
+
"react-resizable-panels": "4.16.0",
|
|
57
75
|
"rrweb": "2.0.0-alpha.20",
|
|
58
76
|
"tailwind-merge": "^3"
|
|
59
77
|
},
|