tailcat-webui 0.0.0-stage → 0.2.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/LICENSE +21 -0
- package/NOTICE +29 -0
- package/README.en.md +112 -0
- package/README.md +101 -2
- package/bin/tailcat-webui.js +12 -0
- package/docs/CORE-API.md +343 -0
- package/docs/DESIGN.md +398 -0
- package/docs/assets/character.jpg +0 -0
- package/docs/assets/portrait.jpg +0 -0
- package/docs/screenshots/01-overview-light.png +0 -0
- package/docs/screenshots/02-overview-dark.png +0 -0
- package/docs/screenshots/03-ticket-light.png +0 -0
- package/docs/screenshots/04-ticket-qr-light.png +0 -0
- package/docs/screenshots/05-settings-light.png +0 -0
- package/docs/screenshots/06-diagnostics-light.png +0 -0
- package/docs/screenshots/07-mobile-overview.png +0 -0
- package/docs/screenshots/08-install-missing.png +0 -0
- package/docs/screenshots/09-keeper.png +0 -0
- package/package.json +56 -4
- package/src/cli.js +238 -0
- package/src/config.js +167 -0
- package/src/devices.js +163 -0
- package/src/errors.js +24 -0
- package/src/index.js +19 -0
- package/src/installer.js +907 -0
- package/src/manager.js +647 -0
- package/src/parse.js +207 -0
- package/src/paths.js +97 -0
- package/src/preferences.js +190 -0
- package/src/qr.js +37 -0
- package/src/relay.js +76 -0
- package/src/runtime/node.js +281 -0
- package/src/serve-targets.js +127 -0
- package/src/server.js +674 -0
- package/src/settings.js +262 -0
- package/src/supervisor.js +833 -0
- package/vendor/qrcode.mjs +2289 -0
- package/web/api.js +114 -0
- package/web/assets/portrait.jpg +0 -0
- package/web/boot.js +29 -0
- package/web/components.js +558 -0
- package/web/dict.js +663 -0
- package/web/drawer-access.js +318 -0
- package/web/drawer-address.js +271 -0
- package/web/drawer-automation.js +223 -0
- package/web/drawer-relay.js +128 -0
- package/web/drawer-tunnel.js +309 -0
- package/web/drawer.js +302 -0
- package/web/format.js +252 -0
- package/web/icon.png +0 -0
- package/web/index.html +29 -0
- package/web/main.js +471 -0
- package/web/room-diagnostics.js +426 -0
- package/web/room-overview.js +438 -0
- package/web/room-settings.js +71 -0
- package/web/store.js +168 -0
- package/web/styles.css +2873 -0
- package/web/ticket.js +212 -0
package/web/ticket.js
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The pairing ticket: the address (masked by default), the client command, the
|
|
3
|
+
* local URL, and the QR code behind the perforation on the stub.
|
|
4
|
+
*
|
|
5
|
+
* The ticket owns only its own two toggles (show address, show QR); everything
|
|
6
|
+
* else is derived from the snapshot on every update.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import {
|
|
10
|
+
h,
|
|
11
|
+
button,
|
|
12
|
+
copyButton,
|
|
13
|
+
codeBlock,
|
|
14
|
+
catSeal,
|
|
15
|
+
qrBoard,
|
|
16
|
+
setText,
|
|
17
|
+
setHidden,
|
|
18
|
+
setDisabled,
|
|
19
|
+
setClass,
|
|
20
|
+
syncSignature,
|
|
21
|
+
} from './components.js';
|
|
22
|
+
import {
|
|
23
|
+
ADDRESS_MASK,
|
|
24
|
+
addressOf,
|
|
25
|
+
pairingOf,
|
|
26
|
+
relayOf,
|
|
27
|
+
hasTargets,
|
|
28
|
+
} from './format.js';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {object} ctx - shell context.
|
|
32
|
+
* @param {object} ui - ticket UI state shared across rebuilds.
|
|
33
|
+
* @returns {{ el: HTMLElement, update: (state: object | null) => void }} ticket.
|
|
34
|
+
*/
|
|
35
|
+
export function createTicket(ctx, ui) {
|
|
36
|
+
const t = ctx.t;
|
|
37
|
+
if (typeof ui.showAddress !== 'boolean') ui.showAddress = false;
|
|
38
|
+
if (typeof ui.showQr !== 'boolean') ui.showQr = false;
|
|
39
|
+
|
|
40
|
+
const titleId = 'ticket-title';
|
|
41
|
+
const title = h('h2', { class: 'ticket-title', id: titleId }, t('ticketTitle'));
|
|
42
|
+
const addressEl = h('code', {
|
|
43
|
+
class: 'ticket-address',
|
|
44
|
+
'data-testid': 'ticket-address',
|
|
45
|
+
'aria-live': 'polite',
|
|
46
|
+
});
|
|
47
|
+
const showButton = button({
|
|
48
|
+
label: t('ticketShowAddress'),
|
|
49
|
+
variant: 'ghost',
|
|
50
|
+
testid: 'ticket-show-address',
|
|
51
|
+
onClick: () => {
|
|
52
|
+
ui.showAddress = !ui.showAddress;
|
|
53
|
+
update(ctx.state());
|
|
54
|
+
},
|
|
55
|
+
});
|
|
56
|
+
const copySlot = h('span', { class: 'ticket-action-slot' });
|
|
57
|
+
const addressRow = h('div', { class: 'ticket-address-row' },
|
|
58
|
+
addressEl,
|
|
59
|
+
h('div', { class: 'ticket-address-actions' }, showButton, copySlot));
|
|
60
|
+
const credentialHint = h('p', { class: 'ticket-hint' }, t('ticketCredentialHint'));
|
|
61
|
+
|
|
62
|
+
const commandSlot = h('div', { class: 'ticket-code-slot' });
|
|
63
|
+
const localUrlEl = h('code', { class: 'ticket-address ticket-local-url', 'data-testid': 'ticket-local-url' });
|
|
64
|
+
const localCopySlot = h('span', { class: 'ticket-action-slot' });
|
|
65
|
+
const localLink = h('a', {
|
|
66
|
+
class: 'ticket-link',
|
|
67
|
+
href: '#',
|
|
68
|
+
target: '_blank',
|
|
69
|
+
rel: 'noopener noreferrer',
|
|
70
|
+
'data-testid': 'ticket-open-local',
|
|
71
|
+
}, t('openLocal'));
|
|
72
|
+
const localRow = h('div', { class: 'ticket-local-row' }, localUrlEl, localCopySlot);
|
|
73
|
+
const localSection = h('div', { class: 'ticket-section', hidden: true },
|
|
74
|
+
h('p', { class: 'ticket-label' }, t('localAddress')),
|
|
75
|
+
localRow,
|
|
76
|
+
localLink);
|
|
77
|
+
|
|
78
|
+
const emptyCta = button({
|
|
79
|
+
label: t('ticketEmptyAction'),
|
|
80
|
+
variant: 'secondary',
|
|
81
|
+
testid: 'ticket-empty-action',
|
|
82
|
+
onClick: () => {
|
|
83
|
+
ctx.goRoom('settings');
|
|
84
|
+
ctx.openDrawer('tunnel', { focus: true });
|
|
85
|
+
},
|
|
86
|
+
});
|
|
87
|
+
const emptyRow = h('div', { class: 'ticket-empty-row', hidden: true },
|
|
88
|
+
h('p', { class: 'ticket-empty-note' }, t('ticketEmptyNoTargets')),
|
|
89
|
+
emptyCta);
|
|
90
|
+
|
|
91
|
+
const main = h('div', { class: 'ticket-main' },
|
|
92
|
+
title,
|
|
93
|
+
addressRow,
|
|
94
|
+
credentialHint,
|
|
95
|
+
h('div', { class: 'ticket-divider', 'aria-hidden': 'true' }),
|
|
96
|
+
h('p', { class: 'ticket-label' }, t('clientRun')),
|
|
97
|
+
commandSlot,
|
|
98
|
+
h('div', { class: 'ticket-divider', 'aria-hidden': 'true' }),
|
|
99
|
+
localSection,
|
|
100
|
+
emptyRow);
|
|
101
|
+
|
|
102
|
+
const qrButton = button({
|
|
103
|
+
label: t('qrShow'),
|
|
104
|
+
variant: 'ghost',
|
|
105
|
+
testid: 'ticket-show-qr',
|
|
106
|
+
onClick: () => {
|
|
107
|
+
ui.showQr = !ui.showQr;
|
|
108
|
+
update(ctx.state());
|
|
109
|
+
},
|
|
110
|
+
});
|
|
111
|
+
const qrCaption = h('p', { class: 'ticket-qr-caption' }, t('qrCaption'));
|
|
112
|
+
const qrFailure = h('p', { class: 'ticket-qr-failure', hidden: true }, t('qrFailed'));
|
|
113
|
+
const qrBoardSlot = h('div', { class: 'ticket-qr-board-slot' });
|
|
114
|
+
const qrPanel = h('div', { class: 'ticket-qr', id: 'ticket-qr-panel', hidden: true }, qrBoardSlot, qrCaption, qrFailure);
|
|
115
|
+
qrButton.setAttribute('aria-controls', qrPanel.id);
|
|
116
|
+
const stub = h('aside', { class: 'ticket-stub' },
|
|
117
|
+
h('div', { class: 'ticket-stub-row' },
|
|
118
|
+
catSeal(56),
|
|
119
|
+
h('span', { class: 'ticket-wordmark', 'aria-hidden': 'true' }, t('sealWordmark'))),
|
|
120
|
+
qrButton,
|
|
121
|
+
qrPanel);
|
|
122
|
+
|
|
123
|
+
const footnote = h('p', { class: 'ticket-footnote', hidden: true }, t('customMapNote'));
|
|
124
|
+
|
|
125
|
+
const el = h('section', {
|
|
126
|
+
class: 'ticket',
|
|
127
|
+
'data-testid': 'ticket',
|
|
128
|
+
'aria-labelledby': titleId,
|
|
129
|
+
},
|
|
130
|
+
h('div', { class: 'ticket-grid' }, main, stub),
|
|
131
|
+
footnote);
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* @param {object | null} state - latest snapshot.
|
|
135
|
+
*/
|
|
136
|
+
function update(state) {
|
|
137
|
+
if (!state) return;
|
|
138
|
+
const address = addressOf(state);
|
|
139
|
+
const pairing = pairingOf(state);
|
|
140
|
+
const relay = relayOf(state);
|
|
141
|
+
const empty = address === null;
|
|
142
|
+
const targets = hasTargets(state);
|
|
143
|
+
setClass(el, 'is-empty', empty);
|
|
144
|
+
|
|
145
|
+
if (empty) {
|
|
146
|
+
setText(addressEl, t('ticketEmpty'));
|
|
147
|
+
addressEl.classList.add('is-empty-copy');
|
|
148
|
+
} else {
|
|
149
|
+
setText(addressEl, ui.showAddress ? address : ADDRESS_MASK);
|
|
150
|
+
addressEl.classList.remove('is-empty-copy');
|
|
151
|
+
}
|
|
152
|
+
showButton.hidden = empty;
|
|
153
|
+
setText(showButton, ui.showAddress ? t('ticketHideAddress') : t('ticketShowAddress'));
|
|
154
|
+
showButton.setAttribute('aria-pressed', ui.showAddress ? 'true' : 'false');
|
|
155
|
+
setDisabled(showButton, empty);
|
|
156
|
+
setHidden(credentialHint, empty);
|
|
157
|
+
|
|
158
|
+
syncSignature(copySlot, empty ? 'empty' : address, () => {
|
|
159
|
+
if (empty) return [h('button', { type: 'button', class: 'btn btn-ghost', disabled: true, 'aria-label': t('copy') }, t('copy'))];
|
|
160
|
+
return [copyButton({
|
|
161
|
+
text: address,
|
|
162
|
+
t,
|
|
163
|
+
onResult: (ok) => {
|
|
164
|
+
if (!ok) ctx.notify('error', t('copyFailed'));
|
|
165
|
+
},
|
|
166
|
+
testid: 'ticket-copy',
|
|
167
|
+
})];
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
const command = pairing && typeof pairing.command === 'string' && pairing.command !== '' ? pairing.command : '';
|
|
171
|
+
syncSignature(commandSlot, empty ? 'empty' : command, () => (command
|
|
172
|
+
? [codeBlock({ text: command, t, testid: 'ticket-command' })]
|
|
173
|
+
: [h('p', { class: 'code-empty' }, t('commandEmpty'))]));
|
|
174
|
+
|
|
175
|
+
const localPort = pairing && Number.isFinite(Number(pairing.localPort)) ? Number(pairing.localPort) : 18_080;
|
|
176
|
+
const localUrl = `http://127.0.0.1:${localPort}/`;
|
|
177
|
+
setHidden(localSection, empty);
|
|
178
|
+
if (!empty) {
|
|
179
|
+
setText(localUrlEl, localUrl);
|
|
180
|
+
localLink.href = localUrl;
|
|
181
|
+
syncSignature(localCopySlot, localUrl, () => [copyButton({
|
|
182
|
+
text: localUrl,
|
|
183
|
+
t,
|
|
184
|
+
onResult: (ok) => {
|
|
185
|
+
if (!ok) ctx.notify('error', t('copyFailed'));
|
|
186
|
+
},
|
|
187
|
+
testid: 'ticket-copy-local',
|
|
188
|
+
})]);
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
setHidden(emptyRow, !(empty && !targets));
|
|
192
|
+
setDisabled(qrButton, empty);
|
|
193
|
+
setText(qrButton, ui.showQr ? t('qrHide') : t('qrShow'));
|
|
194
|
+
qrButton.setAttribute('aria-expanded', ui.showQr && !empty ? 'true' : 'false');
|
|
195
|
+
setHidden(qrPanel, empty || !ui.showQr);
|
|
196
|
+
setClass(el, 'is-qr-open', !empty && ui.showQr);
|
|
197
|
+
if (!empty && ui.showQr) {
|
|
198
|
+
const matrix = pairing.qr;
|
|
199
|
+
const board = qrBoard({ matrix, t });
|
|
200
|
+
syncSignature(qrBoardSlot, board ? `qr:${pairing.address}:${matrix.size}` : 'none', () => (board ? [board] : []));
|
|
201
|
+
setHidden(qrCaption, !board);
|
|
202
|
+
setHidden(qrFailure, Boolean(board));
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
const footnoteVisible = !empty && relay.custom === true && relay.needsClientMap === true;
|
|
206
|
+
setHidden(footnote, !footnoteVisible);
|
|
207
|
+
setClass(el, 'has-footnote', footnoteVisible);
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
update(ctx.state());
|
|
211
|
+
return { el, update };
|
|
212
|
+
}
|