@whzxc/agent-design-gallery 0.14.0 → 0.15.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/README.md +26 -16
- package/package.json +1 -1
- package/public/access.css +15 -2
- package/public/app.js +708 -483
- package/public/arrangement-worker.js +7 -7
- package/public/arrangement.js +35 -30
- package/public/assets.js +60 -38
- package/public/auth.js +59 -4
- package/public/boards.js +124 -0
- package/public/comment-anchors.js +50 -0
- package/public/comments.css +400 -0
- package/public/comments.js +1106 -0
- package/public/context-menu.js +97 -0
- package/public/frame-identity.js +26 -2
- package/public/hub.css +25 -3
- package/public/hub.html +10 -2
- package/public/hub.js +127 -23
- package/public/icons.js +2 -0
- package/public/index.html +13 -9
- package/public/instance-actions.js +9 -2
- package/public/layout.js +156 -86
- package/public/selection.js +1 -1
- package/public/style.css +74 -152
- package/public/switcher.css +5 -4
- package/public/switcher.js +109 -34
- package/public/token-catalog.js +8 -3
- package/public/tokens.css +14 -1
- package/public/view-route.js +0 -1
- package/src/boards/board.mjs +30 -0
- package/src/boards/token-board.mjs +196 -0
- package/src/cli-output.mjs +8 -5
- package/src/cli.mjs +49 -29
- package/src/comments.mjs +293 -0
- package/src/http.mjs +2 -3
- package/src/hub/project-link.mjs +41 -0
- package/src/hub/registry.mjs +5 -0
- package/src/hub.mjs +14 -10
- package/src/link.mjs +13 -1
- package/src/server.mjs +57 -93
- package/src/service.mjs +46 -12
- package/src/toolkit/arch.mjs +3 -2
- package/src/toolkit/asset-rules.mjs +24 -1
- package/src/toolkit/build-worker.mjs +6 -2
- package/src/toolkit/build.mjs +4 -2
- package/src/toolkit/commands.mjs +12 -7
- package/{public/review.js → src/toolkit/diff-document.mjs} +137 -43
- package/src/toolkit/diff-inputs.mjs +66 -30
- package/src/toolkit/diff.mjs +181 -39
- package/src/toolkit/impact-selection.mjs +25 -10
- package/src/toolkit/impact.mjs +32 -12
- package/src/toolkit/move-pairing.mjs +140 -0
- package/src/toolkit/project-index.mjs +2 -2
- package/src/toolkit/results.mjs +1 -1
- package/src/toolkit/review-document.mjs +435 -0
- package/src/toolkit/review-groups.mjs +29 -0
- package/src/toolkit/review-observation.mjs +131 -0
- package/src/toolkit/review-sheet.mjs +117 -0
- package/src/toolkit/review-specimens.mjs +60 -0
- package/src/toolkit/review.mjs +140 -0
- package/src/toolkit/runtime.mjs +1 -1
- package/src/toolkit/theme.mjs +16 -0
- package/public/annotations.js +0 -816
- package/public/labels.js +0 -122
- package/src/annotations.mjs +0 -238
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export function createContextMenu(menu, { viewport, onOverlayChange }) {
|
|
2
|
+
let restoreTarget = null;
|
|
3
|
+
let suppressAutoRestore = false;
|
|
4
|
+
|
|
5
|
+
const enabledItems = () => [...menu.querySelectorAll('button[role="menuitem"]:not(:disabled)')];
|
|
6
|
+
|
|
7
|
+
menu.addEventListener('toggle', event => {
|
|
8
|
+
if (event.newState === 'open') {
|
|
9
|
+
for (const other of document.querySelectorAll(':popover-open')) {
|
|
10
|
+
if (other !== menu) other.hidePopover();
|
|
11
|
+
}
|
|
12
|
+
} else if (!suppressAutoRestore && restoreTarget?.isConnected) {
|
|
13
|
+
if (!document.activeElement || document.activeElement === document.body || menu.contains(document.activeElement)) {
|
|
14
|
+
restoreTarget.focus({ preventScroll: true });
|
|
15
|
+
}
|
|
16
|
+
restoreTarget = null;
|
|
17
|
+
}
|
|
18
|
+
onOverlayChange?.();
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
menu.addEventListener('keydown', event => {
|
|
22
|
+
const items = enabledItems();
|
|
23
|
+
const index = items.indexOf(document.activeElement);
|
|
24
|
+
if (event.key === 'ArrowDown' && items.length) {
|
|
25
|
+
event.preventDefault();
|
|
26
|
+
event.stopPropagation();
|
|
27
|
+
items[(index + 1 + items.length) % items.length].focus();
|
|
28
|
+
} else if (event.key === 'ArrowUp' && items.length) {
|
|
29
|
+
event.preventDefault();
|
|
30
|
+
event.stopPropagation();
|
|
31
|
+
items[(index - 1 + items.length) % items.length].focus();
|
|
32
|
+
} else if (event.key === 'Home' && items.length) {
|
|
33
|
+
event.preventDefault();
|
|
34
|
+
event.stopPropagation();
|
|
35
|
+
items[0].focus();
|
|
36
|
+
} else if (event.key === 'End' && items.length) {
|
|
37
|
+
event.preventDefault();
|
|
38
|
+
event.stopPropagation();
|
|
39
|
+
items.at(-1).focus();
|
|
40
|
+
} else if ((event.key === 'Enter' || event.key === ' ') && index >= 0) {
|
|
41
|
+
event.preventDefault();
|
|
42
|
+
event.stopPropagation();
|
|
43
|
+
items[index].click();
|
|
44
|
+
} else if (event.key === 'Escape' || event.key === 'Tab') {
|
|
45
|
+
event.preventDefault();
|
|
46
|
+
event.stopPropagation();
|
|
47
|
+
close(true);
|
|
48
|
+
}
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
function close(restore = true) {
|
|
52
|
+
const target = restoreTarget;
|
|
53
|
+
suppressAutoRestore = true;
|
|
54
|
+
if (menu.matches(':popover-open')) menu.hidePopover();
|
|
55
|
+
suppressAutoRestore = false;
|
|
56
|
+
restoreTarget = null;
|
|
57
|
+
if (restore && target?.isConnected) target.focus({ preventScroll: true });
|
|
58
|
+
onOverlayChange?.();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function open(items, { x, y, returnFocus } = {}) {
|
|
62
|
+
restoreTarget = returnFocus ?? (document.activeElement instanceof HTMLElement ? document.activeElement : viewport);
|
|
63
|
+
const nodes = items.map(entry => {
|
|
64
|
+
if (entry.separator) {
|
|
65
|
+
const rule = document.createElement('div');
|
|
66
|
+
rule.className = 'rule';
|
|
67
|
+
rule.setAttribute('role', 'separator');
|
|
68
|
+
return rule;
|
|
69
|
+
}
|
|
70
|
+
const button = document.createElement('button');
|
|
71
|
+
button.type = 'button';
|
|
72
|
+
button.setAttribute('role', 'menuitem');
|
|
73
|
+
button.textContent = entry.label;
|
|
74
|
+
button.disabled = !!entry.disabled;
|
|
75
|
+
button.onclick = () => {
|
|
76
|
+
const target = restoreTarget;
|
|
77
|
+
close(false);
|
|
78
|
+
if (target?.isConnected) target.focus({ preventScroll: true });
|
|
79
|
+
entry.action?.();
|
|
80
|
+
};
|
|
81
|
+
return button;
|
|
82
|
+
});
|
|
83
|
+
menu.replaceChildren(...nodes);
|
|
84
|
+
menu.style.left = '0px';
|
|
85
|
+
menu.style.top = '0px';
|
|
86
|
+
if (!menu.matches(':popover-open')) menu.showPopover();
|
|
87
|
+
const mw = menu.offsetWidth || 220, mh = menu.offsetHeight || 160;
|
|
88
|
+
const left = Math.max(8, Math.min(window.innerWidth - mw - 8, Math.round(x)));
|
|
89
|
+
const top = Math.max(8, Math.min(window.innerHeight - mh - 8, Math.round(y)));
|
|
90
|
+
menu.style.left = `${left}px`;
|
|
91
|
+
menu.style.top = `${top}px`;
|
|
92
|
+
enabledItems()[0]?.focus({ preventScroll: true });
|
|
93
|
+
onOverlayChange?.();
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return { open, close, isOpen: () => menu.matches(':popover-open') };
|
|
97
|
+
}
|
package/public/frame-identity.js
CHANGED
|
@@ -53,6 +53,11 @@ const digest = value => sha256Hex(value).slice(0, 24);
|
|
|
53
53
|
const normalize = value => value.normalize('NFC').replace(/\p{White_Space}+/gu, ' ').trim();
|
|
54
54
|
const namingAttributes = new Set(['id', 'data-part', 'role', 'aria-label', 'aria-labelledby', 'aria-describedby']);
|
|
55
55
|
const containerRoots = new Set(['div', 'main', 'section', 'article', 'aside', 'header', 'footer', 'nav', 'form']);
|
|
56
|
+
const additionalCommentRoles = new Map(Object.entries({
|
|
57
|
+
article: 'article', aside: 'complementary', dialog: 'dialog', fieldset: 'group', hr: 'separator',
|
|
58
|
+
li: 'listitem', main: 'main', meter: 'meter', nav: 'navigation', ol: 'list', option: 'option', output: 'status',
|
|
59
|
+
progress: 'progressbar', summary: 'button', table: 'table', td: 'cell', th: 'columnheader', tr: 'row', ul: 'list',
|
|
60
|
+
}));
|
|
56
61
|
|
|
57
62
|
export function identityNode(node, path, parentPath, owners, styleFor) {
|
|
58
63
|
const attributes = {};
|
|
@@ -77,7 +82,7 @@ export function identityNode(node, path, parentPath, owners, styleFor) {
|
|
|
77
82
|
const name = normalize(labelled || node.getAttribute('aria-label') || node.getAttribute('alt') || (role === 'textbox' || role === 'combobox' ? Array.from(node.labels ?? []).map(l => l.textContent).join(' ') : role ? node.textContent : '') || '');
|
|
78
83
|
const resource = node.localName === 'svg' && (node.hasAttribute('data-adg-icon') || node.getAttribute('aria-hidden') === 'true' || !node.querySelector('text,foreignObject') && !node.hasAttribute('role'));
|
|
79
84
|
return {
|
|
80
|
-
path, parentPath, tag: node.localName, namespace: node.namespaceURI, attributes, owners, neutral, resource,
|
|
85
|
+
path, parentPath, tag: node.localName, namespace: node.namespaceURI, attributes, owners, neutral, resource, role, name,
|
|
81
86
|
...(role && name ? { semantic: { role, name } } : {}),
|
|
82
87
|
keys: JSON.parse(node.getAttribute('data-adg-keys') ?? '[]'),
|
|
83
88
|
password,
|
|
@@ -191,10 +196,20 @@ export function collectViewerElements(shell, { projectSource, assetPath, frame,
|
|
|
191
196
|
}
|
|
192
197
|
const clean = n => n === 0 ? 0 : n;
|
|
193
198
|
const elements = [];
|
|
199
|
+
const boundaries = new Map();
|
|
194
200
|
for (let i = 0; i < domNodes.length; i++) {
|
|
195
201
|
const node = domNodes[i], input = inputs[i], idRow = assigned[i];
|
|
202
|
+
const parentBoundary = boundaries.get(input.parentPath) ?? null;
|
|
203
|
+
boundaries.set(input.path, parentBoundary);
|
|
196
204
|
if (input.neutral) continue;
|
|
197
|
-
|
|
205
|
+
const semanticRole = input.role ?? additionalCommentRoles.get(input.tag);
|
|
206
|
+
const role = /^(none|presentation)$/.test(semanticRole) ? null : semanticRole?.trim().split(/\s+/, 1)[0];
|
|
207
|
+
const boundary = Boolean(input.owners.length || input.keys.length || role ||
|
|
208
|
+
Object.keys(input.attributes).some(name => name === 'data-adg-id' || name !== 'role' && namingAttributes.has(name)) ||
|
|
209
|
+
node.hasAttribute('alt') || node.hasAttribute('title'));
|
|
210
|
+
const commentOnly = node === root && !input.owners.length && !node.hasAttribute('data-adg-id') &&
|
|
211
|
+
!node.hasAttribute('role') && containerRoots.has(node.localName);
|
|
212
|
+
if (commentOnly && !boundary) continue;
|
|
198
213
|
const rect = rectFor(node);
|
|
199
214
|
let left = Math.max(rect.left, origin.left), right = Math.min(rect.right, origin.right);
|
|
200
215
|
let top = Math.max(rect.top, origin.top), bottom = Math.min(rect.bottom, origin.bottom);
|
|
@@ -209,10 +224,19 @@ export function collectViewerElements(shell, { projectSource, assetPath, frame,
|
|
|
209
224
|
}
|
|
210
225
|
if (right <= left || bottom <= top) continue;
|
|
211
226
|
const owner = idRow.defining.at(-1) ?? { source: assetPath, export: null };
|
|
227
|
+
if (boundary) boundaries.set(input.path, idRow.id);
|
|
228
|
+
const text = (input.semantic?.name || normalize(input.directText)).slice(0, 120) || null;
|
|
212
229
|
elements.push({
|
|
213
230
|
id: idRow.id,
|
|
214
231
|
owners: input.owners,
|
|
215
232
|
owner,
|
|
233
|
+
tag: input.tag,
|
|
234
|
+
text,
|
|
235
|
+
...(commentOnly ? { commentOnly } : {}),
|
|
236
|
+
commentBoundary: boundaries.get(input.path),
|
|
237
|
+
commentName: role || owner.export || null,
|
|
238
|
+
commentText: (input.name || text || (boundary && !input.password ? normalize(node.textContent) : '') ||
|
|
239
|
+
normalize(node.getAttribute('title') ?? '')).slice(0, 120) || null,
|
|
216
240
|
x: clean(left - origin.left),
|
|
217
241
|
y: clean(top - origin.top),
|
|
218
242
|
width: Math.max(0, right - left),
|
package/public/hub.css
CHANGED
|
@@ -10,22 +10,39 @@ a:focus-visible,button:focus-visible { outline:1px solid var(--accent); outline-
|
|
|
10
10
|
button { font:inherit; color:inherit; border:0; cursor:pointer; }
|
|
11
11
|
.icon { display:block; flex:none; pointer-events:none; }
|
|
12
12
|
[data-icon] { display:inline-flex; flex:none; }
|
|
13
|
+
@keyframes hub-spin { to { transform:rotate(360deg); } }
|
|
13
14
|
#hub { min-height:100dvh; padding:12px; display:flex; flex-direction:column; gap:32px; }
|
|
14
15
|
.hub-bar { display:inline-flex; align-self:flex-start; align-items:center; height:44px; padding:6px; border-radius:var(--radius-panel); background:var(--surface); box-shadow:var(--shadow-float); }
|
|
15
16
|
.hub-bar span { padding:0 8px; font-size:var(--text-section); font-weight:650; }
|
|
16
17
|
#hub main { display:flex; flex-direction:column; gap:32px; width:100%; max-width:1080px; margin:0 auto; padding-top:24px; }
|
|
17
18
|
#hub main>section { display:flex; flex-direction:column; gap:16px; }
|
|
18
19
|
#hub main>.live-section { gap:12px; }
|
|
19
|
-
.hub-heading { display:flex; align-items:center; justify-content:space-between; gap:16px; }
|
|
20
|
+
.hub-heading { display:flex; align-items:center; justify-content:space-between; flex-wrap:wrap; gap:12px 16px; }
|
|
21
|
+
.hub-controls { display:flex; align-items:center; gap:8px; margin-left:auto; }
|
|
22
|
+
.hub-search { width:240px; height:var(--field-height); display:flex; align-items:center; gap:8px; padding:0 10px; border-radius:var(--radius-field); background:var(--surface); box-shadow:var(--shadow-float); color:var(--text-tertiary); }
|
|
23
|
+
.hub-search:focus-within { outline:1px solid var(--accent); outline-offset:-1px; }
|
|
24
|
+
.hub-search input { flex:1; min-width:0; height:100%; padding:0; border:0; outline:none; background:none; color:var(--text); font:inherit; }
|
|
25
|
+
.hub-search input::placeholder { color:var(--text-tertiary); opacity:1; }
|
|
26
|
+
.hub-search input::-webkit-search-cancel-button { display:none; }
|
|
27
|
+
.hub-search kbd { flex:none; font:var(--text-caption)/1 var(--font-mono); color:var(--text-tertiary); }
|
|
28
|
+
#hub-search-clear { display:grid; place-items:center; flex:none; padding:2px; background:none; color:var(--text-tertiary); border-radius:var(--radius-row); }
|
|
29
|
+
#hub-search-clear:hover { color:var(--text); }
|
|
20
30
|
h1 { font-size:var(--text-title); font-weight:650; }
|
|
21
31
|
h2 { font-size:var(--text-section); font-weight:600; }
|
|
22
32
|
#rescan { height:32px; display:inline-flex; align-items:center; gap:10px; padding:0 12px; flex:none; border-radius:var(--radius-field); background:var(--surface-sunken); font-weight:550; line-height:16px; }
|
|
23
33
|
#rescan .icon { color:var(--text-secondary); }
|
|
24
34
|
#rescan:disabled { opacity:.6; cursor:default; }
|
|
35
|
+
#rescan:disabled[data-loading] .icon, .instance-close[data-loading] .icon { animation:hub-spin .9s linear infinite; }
|
|
25
36
|
.hub-list { overflow:hidden; border-radius:var(--radius-panel); background:var(--surface); box-shadow:var(--shadow-float); }
|
|
26
37
|
.project-columns { display:grid; grid-template-columns:minmax(0,1fr) 144px 200px 148px; gap:24px; align-items:center; }
|
|
27
38
|
.project-header { padding:12px 20px; border-bottom:1px solid var(--border); font-size:var(--text-caption); color:var(--text-tertiary); }
|
|
39
|
+
.project-row, .instance-row { position:relative; }
|
|
28
40
|
.project-row { padding:20px; }
|
|
41
|
+
.project-row:has(a.hub-title):hover, .instance-row:has(a.hub-title):hover { background:var(--surface-sunken); }
|
|
42
|
+
a.hub-title::after { content:''; position:absolute; inset:0; }
|
|
43
|
+
a.hub-title:hover { text-decoration:none; }
|
|
44
|
+
a.hub-title:focus-visible { outline:none; }
|
|
45
|
+
.project-row:has(a.hub-title:focus-visible), .instance-row:has(a.hub-title:focus-visible) { outline:1px solid var(--accent); outline-offset:-1px; }
|
|
29
46
|
.project-row+.project-row,.instance-row+.instance-row { border-top:1px solid var(--border); }
|
|
30
47
|
.project-identity { min-width:0; }
|
|
31
48
|
.hub-name { display:flex; align-items:center; gap:8px; }
|
|
@@ -44,11 +61,13 @@ h2 { font-size:var(--text-section); font-weight:600; }
|
|
|
44
61
|
.instance-row { padding:16px 20px; display:flex; align-items:center; justify-content:space-between; gap:24px; }
|
|
45
62
|
.instance-identity { display:flex; min-width:0; flex-direction:column; gap:4px; }
|
|
46
63
|
.instance-row .hub-name a,.instance-row .hub-name>span { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
64
|
+
.instance-meta { flex-wrap:nowrap; }
|
|
65
|
+
.instance-dir { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--text-secondary); }
|
|
47
66
|
.instance-start { flex:none; color:var(--text-tertiary); }
|
|
48
67
|
.instance-warning { display:flex; align-items:center; flex:none; gap:8px; font-size:var(--text-meta); color:var(--danger); }
|
|
49
|
-
.instance-close { display:grid; place-items:center; flex:none; width:var(--control-size); height:var(--control-size); padding:0;
|
|
68
|
+
.instance-close { position:relative; z-index:1; display:grid; place-items:center; flex:none; width:var(--control-size); height:var(--control-size); padding:0;
|
|
50
69
|
border-radius:var(--radius-row); background:none; color:var(--text-secondary); }
|
|
51
|
-
.instance-close:hover:not(:disabled) { background:var(--surface
|
|
70
|
+
.instance-close:hover:not(:disabled) { background:var(--surface); color:var(--text); }
|
|
52
71
|
.instance-close:disabled { opacity:.45; cursor:default; }
|
|
53
72
|
.hub-empty { display:flex; flex-direction:column; align-items:center; gap:12px; padding:48px 24px; text-align:center; }
|
|
54
73
|
.hub-empty>.icon { color:var(--text-tertiary); }
|
|
@@ -56,6 +75,9 @@ h2 { font-size:var(--text-section); font-weight:600; }
|
|
|
56
75
|
#error { color:var(--danger); }
|
|
57
76
|
@media (max-width:700px) {
|
|
58
77
|
#hub main { padding-top:0; }
|
|
78
|
+
.hub-controls { flex:1 1 100%; }
|
|
79
|
+
.hub-search { flex:1; width:auto; min-width:0; }
|
|
80
|
+
.hub-search kbd { display:none; }
|
|
59
81
|
.project-header.project-columns,.desktop-change { display:none; }
|
|
60
82
|
.project-row { padding:16px; }
|
|
61
83
|
.project-columns { display:flex; flex-direction:column; align-items:stretch; gap:12px; }
|
package/public/hub.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="utf-8">
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
6
6
|
<meta name="referrer" content="same-origin">
|
|
7
|
-
<title>
|
|
7
|
+
<title>Projects — Agent Design Gallery</title>
|
|
8
8
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
|
9
9
|
<link rel="stylesheet" href="tokens.css">
|
|
10
10
|
<link rel="stylesheet" href="hub.css">
|
|
@@ -18,7 +18,15 @@
|
|
|
18
18
|
<section aria-labelledby="projects-title">
|
|
19
19
|
<div class="hub-heading">
|
|
20
20
|
<h1 id="projects-title">Projects</h1>
|
|
21
|
-
<
|
|
21
|
+
<div class="hub-controls">
|
|
22
|
+
<div id="hub-search" class="hub-search" hidden>
|
|
23
|
+
<span data-icon="search" data-size="14"></span>
|
|
24
|
+
<input id="hub-search-input" type="search" placeholder="Find project or instance…" aria-label="Find project or instance" autocomplete="off">
|
|
25
|
+
<kbd id="hub-search-key">⌘F</kbd>
|
|
26
|
+
<button id="hub-search-clear" type="button" aria-label="Clear search" hidden><span data-icon="x" data-size="14"></span></button>
|
|
27
|
+
</div>
|
|
28
|
+
<button id="rescan" type="button"><span data-icon="refresh-cw" data-size="14"></span><span>Rescan</span></button>
|
|
29
|
+
</div>
|
|
22
30
|
</div>
|
|
23
31
|
<p id="error" role="alert" hidden></p>
|
|
24
32
|
<div id="projects"></div>
|
package/public/hub.js
CHANGED
|
@@ -4,9 +4,20 @@ import { instanceCloseButton } from './instance-actions.js';
|
|
|
4
4
|
|
|
5
5
|
const projects = document.querySelector('#projects');
|
|
6
6
|
const instances = document.querySelector('#instances');
|
|
7
|
+
const liveSection = document.querySelector('.live-section');
|
|
7
8
|
const error = document.querySelector('#error');
|
|
8
9
|
const rescan = document.querySelector('#rescan');
|
|
10
|
+
const searchBox = document.querySelector('#hub-search');
|
|
11
|
+
const searchInput = document.querySelector('#hub-search-input');
|
|
12
|
+
const searchKey = document.querySelector('#hub-search-key');
|
|
13
|
+
const searchClear = document.querySelector('#hub-search-clear');
|
|
9
14
|
const media = matchMedia('(prefers-color-scheme: dark)');
|
|
15
|
+
|
|
16
|
+
let projectData = [];
|
|
17
|
+
let instanceData = [];
|
|
18
|
+
let rootData = [];
|
|
19
|
+
let rescanning = false;
|
|
20
|
+
|
|
10
21
|
function applyTheme() {
|
|
11
22
|
const saved = localStorage.getItem('adg-theme');
|
|
12
23
|
document.documentElement.dataset.theme = saved === 'light' || saved === 'dark' ? saved : media.matches ? 'dark' : 'light';
|
|
@@ -41,6 +52,19 @@ function relativeTime(value) {
|
|
|
41
52
|
const days = Math.floor(seconds / 86400);
|
|
42
53
|
return `${days} ${days === 1 ? 'day' : 'days'} ago`;
|
|
43
54
|
}
|
|
55
|
+
function proxyReason(reason) {
|
|
56
|
+
if (reason === 'proxy-auth-unsupported') return 'Update ADG to proxy';
|
|
57
|
+
if (reason === 'health-unavailable') return 'Viewer not responding';
|
|
58
|
+
return 'Proxy unavailable';
|
|
59
|
+
}
|
|
60
|
+
function formatCounts(project) {
|
|
61
|
+
if (project.sourceCount == null && project.frameCount == null) return '—';
|
|
62
|
+
const s = project.sourceCount ?? 0;
|
|
63
|
+
const sources = `${s} ${s === 1 ? 'source' : 'sources'}`;
|
|
64
|
+
if (project.frameCount == null) return sources;
|
|
65
|
+
const f = project.frameCount;
|
|
66
|
+
return `${sources} · ${f} ${f === 1 ? 'frame' : 'frames'}`;
|
|
67
|
+
}
|
|
44
68
|
function change(project, phone = false) {
|
|
45
69
|
const node = element('span', phone ? 'phone-change' : 'hub-change desktop-change');
|
|
46
70
|
if (project.lastDesignChange?.dirty) {
|
|
@@ -57,8 +81,9 @@ function change(project, phone = false) {
|
|
|
57
81
|
}
|
|
58
82
|
function git(branch, head) {
|
|
59
83
|
const node = element('div', 'hub-git');
|
|
60
|
-
const
|
|
61
|
-
label
|
|
84
|
+
const text = branch || (head ? 'HEAD' : '—');
|
|
85
|
+
const label = element('span', '', text);
|
|
86
|
+
label.title = branch || (head ? 'Detached HEAD' : '');
|
|
62
87
|
node.append(glyph('git-branch', 13), label);
|
|
63
88
|
if (head) node.append(element('code', '', head));
|
|
64
89
|
return node;
|
|
@@ -83,7 +108,7 @@ function projectRow(project) {
|
|
|
83
108
|
pathNode.title = path;
|
|
84
109
|
identity.append(name, pathNode);
|
|
85
110
|
columns.append(identity, change(project), git(project.branch, project.head),
|
|
86
|
-
element('div', 'hub-counts',
|
|
111
|
+
element('div', 'hub-counts', formatCounts(project)));
|
|
87
112
|
row.append(columns);
|
|
88
113
|
if (incompatible || project.error) {
|
|
89
114
|
const warning = element('div', 'hub-warning');
|
|
@@ -100,23 +125,34 @@ function instanceRow(instance) {
|
|
|
100
125
|
const identity = element('div', 'instance-identity');
|
|
101
126
|
identity.append(destination(instance.projectName ?? instance.name ?? instance.id,
|
|
102
127
|
instance.proxyable ? instance.url ?? `/i/${encodeURIComponent(instance.id)}/` : null, 'radio'));
|
|
103
|
-
const
|
|
104
|
-
|
|
128
|
+
const meta = element('div', 'hub-git instance-meta');
|
|
129
|
+
if (instance.branch) {
|
|
130
|
+
const branchLabel = element('span', '', instance.branch);
|
|
131
|
+
branchLabel.title = instance.branch;
|
|
132
|
+
meta.append(glyph('git-branch', 13), branchLabel);
|
|
133
|
+
}
|
|
134
|
+
if (instance.port != null) meta.append(element('code', '', `:${instance.port}`));
|
|
135
|
+
if (instance.directory) {
|
|
136
|
+
const dir = element('span', 'instance-dir', instance.directory);
|
|
137
|
+
dir.title = instance.directory;
|
|
138
|
+
meta.append(dir);
|
|
139
|
+
}
|
|
140
|
+
const started = element('span', 'instance-start', `${meta.childElementCount ? '· ' : ''}Started ${relativeTime(instance.startedAt)}`);
|
|
105
141
|
started.title = instance.startedAt || '';
|
|
106
|
-
|
|
107
|
-
identity.append(
|
|
142
|
+
meta.append(started);
|
|
143
|
+
identity.append(meta);
|
|
108
144
|
row.append(identity);
|
|
109
145
|
if (!instance.proxyable) {
|
|
110
|
-
const warning = element('span', 'instance-warning',
|
|
146
|
+
const warning = element('span', 'instance-warning', proxyReason(instance.reason));
|
|
111
147
|
warning.prepend(glyph('circle-alert', 14));
|
|
112
148
|
row.append(warning);
|
|
113
149
|
}
|
|
114
150
|
if (instance.stoppable) {
|
|
115
151
|
row.classList.add('instance-row-closeable');
|
|
116
152
|
row.append(instanceCloseButton(instance, 'instance-close', () => {
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
(instances.querySelector('a, button') ?? rescan)
|
|
153
|
+
instanceData = instanceData.filter(item => item !== instance);
|
|
154
|
+
renderLists();
|
|
155
|
+
(instances.querySelector('a, button') ?? (rescan.disabled ? document.querySelector('#projects a') : rescan))?.focus({ preventScroll: true });
|
|
120
156
|
}, report));
|
|
121
157
|
}
|
|
122
158
|
return row;
|
|
@@ -128,22 +164,63 @@ function empty(title, detail) {
|
|
|
128
164
|
node.append(glyph('folders', 24), copy);
|
|
129
165
|
return node;
|
|
130
166
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
167
|
+
function matchesQuery(fields, query) {
|
|
168
|
+
if (!query) return true;
|
|
169
|
+
return fields.some(value => value && String(value).toLowerCase().includes(query));
|
|
170
|
+
}
|
|
171
|
+
function updateRescanState() {
|
|
172
|
+
rescan.disabled = rescanning || rootData.length === 0;
|
|
173
|
+
rescan.toggleAttribute('data-loading', rescanning);
|
|
174
|
+
rescan.title = !rescanning && rootData.length === 0 ? 'No roots registered' : '';
|
|
175
|
+
rescan.replaceChildren(glyph(rescanning ? 'loader-circle' : 'refresh-cw', 14),
|
|
176
|
+
element('span', '', rescanning ? 'Rescanning…' : 'Rescan'));
|
|
177
|
+
}
|
|
178
|
+
function renderLists() {
|
|
179
|
+
const total = projectData.length + instanceData.length;
|
|
180
|
+
const showSearch = total >= 5;
|
|
181
|
+
searchBox.hidden = !showSearch;
|
|
182
|
+
if (!showSearch && searchInput.value) {
|
|
183
|
+
searchInput.value = '';
|
|
184
|
+
searchClear.hidden = true;
|
|
185
|
+
searchKey.hidden = false;
|
|
186
|
+
}
|
|
187
|
+
const query = showSearch ? searchInput.value.trim().toLowerCase() : '';
|
|
188
|
+
const filteredProjects = projectData.filter(project =>
|
|
189
|
+
matchesQuery([project.name, project.design, project.path, project.branch, project.head], query));
|
|
190
|
+
const filteredInstances = instanceData.filter(instance =>
|
|
191
|
+
matchesQuery([instance.projectName, instance.name, instance.id, instance.directory, instance.branch, instance.port != null ? `:${instance.port}` : ''], query));
|
|
192
|
+
|
|
193
|
+
if (filteredProjects.length) {
|
|
194
|
+
projects.hidden = false;
|
|
134
195
|
projects.className = 'hub-list';
|
|
135
196
|
const header = element('div', 'project-columns project-header');
|
|
136
197
|
header.append(...['Projects', 'Design changed', 'Git', 'Designs'].map(label => element('span', '', label)));
|
|
137
|
-
projects.replaceChildren(header, ...
|
|
198
|
+
projects.replaceChildren(header, ...filteredProjects.map(projectRow));
|
|
199
|
+
} else if (query) {
|
|
200
|
+
if (filteredInstances.length) {
|
|
201
|
+
projects.hidden = true;
|
|
202
|
+
projects.replaceChildren();
|
|
203
|
+
} else {
|
|
204
|
+
projects.hidden = false;
|
|
205
|
+
projects.className = '';
|
|
206
|
+
projects.replaceChildren(empty('No matches', `Nothing matched “${searchInput.value.trim()}”.`));
|
|
207
|
+
}
|
|
138
208
|
} else {
|
|
209
|
+
projects.hidden = false;
|
|
139
210
|
projects.className = '';
|
|
140
|
-
projects.replaceChildren(empty(
|
|
141
|
-
? `No design sources found in the ${
|
|
142
|
-
: '
|
|
211
|
+
projects.replaceChildren(empty(rootData.length ? 'No projects found' : 'No roots registered', rootData.length
|
|
212
|
+
? `No design sources found in the ${rootData.length} registered ${rootData.length === 1 ? 'root' : 'roots'}.`
|
|
213
|
+
: 'Run adg root add <dir> to register a workspace.'));
|
|
143
214
|
}
|
|
215
|
+
|
|
144
216
|
instances.className = 'hub-list';
|
|
145
|
-
instances.replaceChildren(...
|
|
146
|
-
|
|
217
|
+
instances.replaceChildren(...filteredInstances.map(instanceRow));
|
|
218
|
+
liveSection.hidden = !filteredInstances.length;
|
|
219
|
+
}
|
|
220
|
+
async function refresh() {
|
|
221
|
+
[projectData, instanceData, rootData] = await Promise.all([api('api/projects'), api('api/instances'), api('api/roots')]);
|
|
222
|
+
updateRescanState();
|
|
223
|
+
renderLists();
|
|
147
224
|
}
|
|
148
225
|
function report(failure) {
|
|
149
226
|
if (isUnauthorized()) return;
|
|
@@ -151,10 +228,37 @@ function report(failure) {
|
|
|
151
228
|
error.hidden = false;
|
|
152
229
|
}
|
|
153
230
|
function pending(value) {
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
element('span', '', value ? 'Rescanning…' : 'Rescan'));
|
|
231
|
+
rescanning = value;
|
|
232
|
+
updateRescanState();
|
|
157
233
|
}
|
|
234
|
+
|
|
235
|
+
searchInput.addEventListener('input', () => {
|
|
236
|
+
const hasValue = Boolean(searchInput.value);
|
|
237
|
+
searchClear.hidden = !hasValue;
|
|
238
|
+
searchKey.hidden = hasValue;
|
|
239
|
+
renderLists();
|
|
240
|
+
});
|
|
241
|
+
searchClear.addEventListener('click', () => {
|
|
242
|
+
searchInput.value = '';
|
|
243
|
+
searchClear.hidden = true;
|
|
244
|
+
searchKey.hidden = false;
|
|
245
|
+
renderLists();
|
|
246
|
+
searchInput.focus();
|
|
247
|
+
});
|
|
248
|
+
searchInput.addEventListener('keydown', event => {
|
|
249
|
+
if (event.key === 'Escape' && searchInput.value) {
|
|
250
|
+
event.preventDefault();
|
|
251
|
+
searchClear.click();
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
document.addEventListener('keydown', event => {
|
|
255
|
+
if ((event.metaKey || event.ctrlKey) && event.key.toLowerCase() === 'f' && !searchBox.hidden) {
|
|
256
|
+
event.preventDefault();
|
|
257
|
+
searchInput.focus();
|
|
258
|
+
searchInput.select();
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
|
|
158
262
|
rescan.addEventListener('click', async () => {
|
|
159
263
|
pending(true);
|
|
160
264
|
error.hidden = true;
|
package/public/icons.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
// Lucide geometry (ISC; see LICENSE). No runtime dependency.
|
|
2
2
|
const geometry = {
|
|
3
3
|
"message-square": '<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z" />',
|
|
4
|
+
"message-square-plus": '<path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2zM9 10h6m-3-3v6" />',
|
|
5
|
+
"messages-square": '<path d="M14 9a2 2 0 0 1-2 2H6l-4 4V4a2 2 0 0 1 2-2h8a2 2 0 0 1 2 2zm4-5h2a2 2 0 0 1 2 2v16l-4-4h-7a2 2 0 0 1-2-2v-1" />',
|
|
4
6
|
"palette": "<path d=\"M12 22a1 1 0 0 1 0-20 10 9 0 0 1 10 9 5 5 0 0 1-5 5h-2.25a1.75 1.75 0 0 0-1.4 2.8l.3.4a1.75 1.75 0 0 1-1.4 2.8z\"></path><circle cx=\"13.5\" cy=\"6.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"17.5\" cy=\"10.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"6.5\" cy=\"12.5\" r=\".5\" fill=\"currentColor\"></circle><circle cx=\"8.5\" cy=\"7.5\" r=\".5\" fill=\"currentColor\"></circle>",
|
|
5
7
|
"type": "<path d=\"M12 4v16\"></path><path d=\"M4 7V5a1 1 0 0 1 1-1h14a1 1 0 0 1 1 1v2\"></path><path d=\"M9 20h6\"></path>",
|
|
6
8
|
"ruler": "<path d=\"M21.3 15.3a2.4 2.4 0 0 1 0 3.4l-2.6 2.6a2.4 2.4 0 0 1-3.4 0L2.7 8.7a2.41 2.41 0 0 1 0-3.4l2.6-2.6a2.41 2.41 0 0 1 3.4 0Z\"></path><path d=\"m14.5 12.5 2-2\"></path><path d=\"m11.5 9.5 2-2\"></path><path d=\"m8.5 6.5 2-2\"></path><path d=\"m17.5 15.5 2-2\"></path>",
|
package/public/index.html
CHANGED
|
@@ -5,17 +5,17 @@
|
|
|
5
5
|
<base href="/">
|
|
6
6
|
<title>Agent Design Gallery</title>
|
|
7
7
|
<link rel="icon" type="image/svg+xml" href="/favicon.svg">
|
|
8
|
-
<link rel="stylesheet" href="tokens.css"><link rel="stylesheet" href="style.css"><link rel="stylesheet" href="switcher.css"><link rel="stylesheet" href="access.css">
|
|
8
|
+
<link rel="stylesheet" href="tokens.css"><link rel="stylesheet" href="style.css"><link rel="stylesheet" href="switcher.css"><link rel="stylesheet" href="access.css"><link rel="stylesheet" href="comments.css">
|
|
9
9
|
<script type="module" src="app.js"></script>
|
|
10
10
|
</head>
|
|
11
11
|
<body>
|
|
12
12
|
<div class="gallery">
|
|
13
13
|
<main class="gallery-viewport" tabindex="0" aria-label="Design canvas" aria-describedby="controls">
|
|
14
|
-
<canvas id="canvas-background" aria-hidden="true"></canvas><canvas id="drawings" aria-hidden="true"></canvas><div id="hover-outline" hidden></div><div id="selection-outline" hidden></div><div id="
|
|
15
|
-
<div id="empty" hidden>No
|
|
14
|
+
<canvas id="canvas-background" aria-hidden="true"></canvas><canvas id="drawings" aria-hidden="true"></canvas><div id="hover-outline" hidden></div><div id="selection-outline" hidden></div><div id="asset-access" class="sr"></div>
|
|
15
|
+
<div id="empty" hidden>No design sources in this directory.</div>
|
|
16
16
|
</main>
|
|
17
17
|
<main id="token-catalog" class="floating" aria-labelledby="token-title" hidden>
|
|
18
|
-
<header><h2 id="token-title">Tokens</h2><code id="token-source"></code></header>
|
|
18
|
+
<header><div class="token-header-meta"><h2 id="token-title">Tokens</h2><code id="token-source"></code></div><button type="button" id="token-board-button" class="view-pill" hidden><span data-icon="layout-grid" data-size="14"></span><span>Board view</span></button></header>
|
|
19
19
|
<div class="token-scroll">
|
|
20
20
|
<table id="token-table">
|
|
21
21
|
<thead><tr><th scope="col">Token</th><th scope="col">Light</th><th scope="col">Dark</th></tr></thead>
|
|
@@ -23,12 +23,13 @@
|
|
|
23
23
|
<p id="token-status" role="status" hidden></p>
|
|
24
24
|
</div>
|
|
25
25
|
</main>
|
|
26
|
-
<main id="review-page" class="floating" aria-labelledby="review-title" hidden></main>
|
|
27
26
|
<div id="app-bar" class="floating" role="toolbar" aria-label="Gallery navigation" hidden>
|
|
28
27
|
<button id="sidebar-toggle" class="icon-button" aria-label="Contents" aria-controls="sidebar" aria-expanded="false" data-tooltip="Contents"><span data-icon="panel-left"></span></button>
|
|
29
28
|
<button type="button" id="app-directory" class="picker" aria-label="Current project"><span data-icon="folder" data-size="14"></span><span class="directory-name"></span><span class="switcher-chevron" data-icon="chevron-down" data-size="12" hidden></span></button>
|
|
30
29
|
<span class="separator project-divider"></span>
|
|
31
30
|
<div id="scope-tabs" role="tablist" aria-label="Design scope"></div>
|
|
31
|
+
<button type="button" id="scope-isolation" class="isolation-pill" data-tooltip="Show full layer" hidden></button>
|
|
32
|
+
<button type="button" id="token-view-toggle" class="view-pill" hidden></button>
|
|
32
33
|
<span class="separator search-divider"></span>
|
|
33
34
|
<div class="search-field"><span data-icon="search" data-size="14"></span><input id="search" type="search" placeholder="Find assets…" aria-label="Find assets" autocomplete="off"><span id="search-key">⌘F</span><button id="search-clear" aria-label="Clear search" hidden><span data-icon="x" data-size="14"></span></button></div>
|
|
34
35
|
</div>
|
|
@@ -36,11 +37,12 @@
|
|
|
36
37
|
<nav id="modules" aria-label="Design modules"></nav>
|
|
37
38
|
</aside>
|
|
38
39
|
<div id="tools" class="floating" role="toolbar" aria-label="View controls" hidden>
|
|
39
|
-
<button id="
|
|
40
|
+
<button id="comments-toggle" class="icon-button" aria-label="Comments" aria-controls="comments-panel" aria-expanded="false" data-tooltip="Comments"><span data-icon="messages-square"></span></button>
|
|
40
41
|
<button id="more" class="icon-button" popovertarget="more-menu" aria-label="More" aria-expanded="false" data-tooltip="More"><span data-icon="ellipsis"></span></button>
|
|
41
42
|
<button id="inspect" class="icon-button" aria-label="Inspector" aria-controls="source" aria-expanded="false" data-tooltip="Inspector" disabled><span data-icon="panel-right"></span></button>
|
|
42
43
|
</div>
|
|
43
|
-
<aside id="
|
|
44
|
+
<aside id="comments-panel" class="floating" hidden aria-label="Comments"></aside>
|
|
45
|
+
<div id="comment-layer"></div>
|
|
44
46
|
<aside id="source" class="floating" hidden aria-label="Inspector">
|
|
45
47
|
<div class="inspector-heading"><h2 id="source-name"></h2><button id="copy-path" class="detail-copy" aria-label="Copy source path"><span id="source-path"></span><span data-icon="copy" data-size="12"></span></button><div id="frame-detail"><button id="copy-frame" class="detail-copy" aria-label="Copy frame name"><span id="frame-name"></span><span data-icon="copy" data-size="12"></span></button><span id="frame-size"></span></div></div>
|
|
46
48
|
<div class="rule"></div><h3 id="forms-heading">Frames</h3><div id="forms"></div>
|
|
@@ -53,19 +55,21 @@
|
|
|
53
55
|
<button id="plus" class="icon-button" aria-label="Zoom in" data-tooltip="Zoom in"><span data-icon="plus"></span></button><span class="separator"></span>
|
|
54
56
|
<button id="fit-current" class="icon-button" aria-label="Fit" data-tooltip="Fit"><span data-icon="scan"></span></button>
|
|
55
57
|
<button id="map-toggle" class="icon-button" aria-label="Minimap" aria-pressed="false" data-tooltip="Minimap"><span data-icon="map"></span></button>
|
|
58
|
+
<button id="comment-tool" class="icon-button" aria-label="Comment" aria-pressed="false" data-tooltip="Comment (C)"><span data-icon="message-square-plus"></span></button>
|
|
56
59
|
</div>
|
|
57
60
|
<canvas id="minimap" class="floating" hidden aria-label="Minimap"></canvas>
|
|
58
61
|
<div id="more-menu" class="menu" popover aria-label="More">
|
|
59
62
|
<button id="fullscreen">Fullscreen</button><div class="rule"></div>
|
|
60
63
|
<h3>Theme</h3><div id="themes"><button data-theme="system">System</button><button data-theme="light">Light</button><button data-theme="dark">Dark</button></div>
|
|
61
|
-
<div class="rule"></div><h3>Canvas</h3><div id="backgrounds"><button data-background="theme">Match theme</button><button data-background="light">Light</button><button data-background="dark">Dark</button><button data-background="neutral">Neutral</button></div>
|
|
62
|
-
<div id="canvas-actions"><div class="rule"></div><button id="arrange">Arrange current group</button><button id="shortcuts">Keyboard shortcuts<span class="key">?</span></button></div>
|
|
64
|
+
<div id="canvas-background-section"><div class="rule"></div><h3>Canvas</h3><div id="backgrounds"><button data-background="theme">Match theme</button><button data-background="light">Light</button><button data-background="dark">Dark</button><button data-background="neutral">Neutral</button></div></div>
|
|
65
|
+
<div id="canvas-actions"><div class="rule"></div><button id="token-list-toggle" hidden>List view</button><button id="arrange">Arrange current group</button><button id="shortcuts">Keyboard shortcuts<span class="key">?</span></button></div>
|
|
63
66
|
</div>
|
|
64
67
|
<div id="zoom-menu" class="menu" popover aria-label="Zoom"><button id="zoom-fit-all">Fit all<span class="key">0</span></button><button id="zoom-fit-group">Fit group</button><button id="zoom-fit-selection">Fit selection</button><div class="rule"></div><button id="zoom-actual">Zoom to 100%<span class="key">1</span></button></div>
|
|
65
68
|
<div id="context-menu" class="menu" popover role="menu" aria-label="Context menu"></div>
|
|
66
69
|
<div id="tooltip" role="tooltip" hidden></div>
|
|
67
70
|
<dialog id="keys" aria-labelledby="keys-title"><h2 id="keys-title">Keyboard shortcuts</h2><button id="keys-close" class="icon-button dialog-close" aria-label="Close keyboard shortcuts"><span data-icon="x" data-size="14"></span></button><dl>
|
|
68
71
|
<div><dt>Search</dt><dd><kbd>⌘F</kbd></dd></div><div><dt>Fit all</dt><dd><kbd>0</kbd></dd></div><div><dt>Zoom to 100%</dt><dd><kbd>1</kbd></dd></div><div><dt>Zoom in or out</dt><dd><kbd>+</kbd><kbd>−</kbd></dd></div><div><dt>Pan</dt><dd><kbd>←</kbd><kbd>↑</kbd><kbd>→</kbd><kbd>↓</kbd></dd></div><div><dt>Focus selection</dt><dd><kbd>Enter</kbd></dd></div><div><dt>Back or close</dt><dd><kbd>Esc</kbd></dd></div>
|
|
72
|
+
<div><dt>Comment</dt><dd><kbd>C</kbd></dd></div><div><dt>Hide or show comment pins</dt><dd><kbd>⇧C</kbd></dd></div>
|
|
69
73
|
</dl></dialog>
|
|
70
74
|
<div id="error" role="alert" hidden></div>
|
|
71
75
|
<p id="controls" class="sr">Drag or scroll to pan. Pinch or Control or Command scroll to zoom. Arrow keys pan; plus and minus zoom; zero fits all; Escape goes back; one sets 100%. Click to select; double-click or Enter to focus.</p>
|
|
@@ -8,8 +8,11 @@ export function instanceCloseButton(instance, className, closed, report) {
|
|
|
8
8
|
button.title = `Close instance: ${instance.name ?? instance.id} (:${instance.port})`;
|
|
9
9
|
button.setAttribute('aria-label', button.title);
|
|
10
10
|
button.innerHTML = icon('x');
|
|
11
|
-
button.onclick = async
|
|
11
|
+
button.onclick = async event => {
|
|
12
|
+
event.stopPropagation();
|
|
12
13
|
button.disabled = true;
|
|
14
|
+
button.dataset.loading = 'true';
|
|
15
|
+
button.innerHTML = icon('loader-circle');
|
|
13
16
|
try {
|
|
14
17
|
const response = await dataFetch(`/api/instances/${encodeURIComponent(instance.id)}/stop`, { method: 'POST' });
|
|
15
18
|
if (!response.ok && response.status !== 404) {
|
|
@@ -20,7 +23,11 @@ export function instanceCloseButton(instance, className, closed, report) {
|
|
|
20
23
|
} catch (error) {
|
|
21
24
|
if (!isUnauthorized()) report(error);
|
|
22
25
|
} finally {
|
|
23
|
-
button.
|
|
26
|
+
delete button.dataset.loading;
|
|
27
|
+
if (button.isConnected) {
|
|
28
|
+
button.innerHTML = icon('x');
|
|
29
|
+
button.disabled = false;
|
|
30
|
+
}
|
|
24
31
|
}
|
|
25
32
|
};
|
|
26
33
|
return button;
|