@penguinharness/use-bento-slides 0.2.17 → 0.2.19
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 +37 -0
- package/README.zh.md +37 -0
- package/THIRD-PARTY-NOTICES.md +30 -0
- package/ifaces.json +63 -0
- package/package.json +19 -21
- package/skills/bento-slides/SKILL.md +89 -29
- package/skills/bento-slides/references/bento-agents.md +511 -0
- package/workbenches/slides/index.ts +677 -0
- package/workbenches/slides/package.json +43 -0
- package/workbenches/slides/ui/app.js +1101 -0
- package/workbenches/slides/ui/bridge.js +190 -0
- package/workbenches/slides/ui/conversation-view.js +206 -0
- package/workbenches/slides/ui/conversation.css +95 -0
- package/workbenches/slides/ui/conversation.js +115 -0
- package/workbenches/slides/ui/deck-files.css +279 -0
- package/workbenches/slides/ui/deck-files.js +189 -0
- package/workbenches/slides/ui/file-menu.js +72 -0
- package/workbenches/slides/ui/icon.svg +9 -0
- package/workbenches/slides/ui/index.html +252 -0
- package/workbenches/slides/ui/model-choice.js +298 -0
- package/workbenches/slides/ui/model-control.tsx +90 -0
- package/workbenches/slides/ui/powerpoint.js +196 -0
- package/workbenches/slides/ui/sample.bento.json +33 -0
- package/workbenches/slides/ui/strings.js +184 -0
- package/workbenches/slides/ui/style.css +505 -0
- package/workbenches/slides/ui/sync.js +268 -0
- package/workbenches/slides/ui/template-picker.js +128 -0
- package/workbenches/slides/ui/templates.js +256 -0
- package/workbenches/slides/ui/vendor/LICENSE-bento.txt +21 -0
- package/workbenches/slides/ui/vendor/LICENSE-jszip.txt +25 -0
- package/workbenches/slides/ui/vendor/LICENSE-pptxgen.txt +21 -0
- package/workbenches/slides/ui/vendor/bento-slides-1.2.13.runtime.txt +310 -0
- package/workbenches/slides/ui/vendor/pptxgen-4.0.1.bundle.js +96 -0
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
/* The file window owns its scroll area; opening a presentation gives this space to Bento. */
|
|
2
|
+
.app[data-view="start"] .bar {
|
|
3
|
+
display: none;
|
|
4
|
+
}
|
|
5
|
+
.app[data-view="start"] .start {
|
|
6
|
+
display: block;
|
|
7
|
+
min-height: 0;
|
|
8
|
+
overflow: auto;
|
|
9
|
+
padding: clamp(22px, 4vw, 52px) clamp(16px, 4vw, 52px);
|
|
10
|
+
text-align: start;
|
|
11
|
+
}
|
|
12
|
+
.file-home {
|
|
13
|
+
max-width: 1050px;
|
|
14
|
+
margin-inline: auto;
|
|
15
|
+
}
|
|
16
|
+
.file-header,
|
|
17
|
+
.file-actions,
|
|
18
|
+
.file-templates,
|
|
19
|
+
.file-description {
|
|
20
|
+
display: flex;
|
|
21
|
+
align-items: center;
|
|
22
|
+
}
|
|
23
|
+
.file-header {
|
|
24
|
+
justify-content: space-between;
|
|
25
|
+
gap: 1rem;
|
|
26
|
+
}
|
|
27
|
+
.file-home h1 {
|
|
28
|
+
font-size: clamp(25px, 3.4vw, 40px);
|
|
29
|
+
line-height: 1.15;
|
|
30
|
+
letter-spacing: -0.035em;
|
|
31
|
+
}
|
|
32
|
+
.file-home h2 {
|
|
33
|
+
margin: 0;
|
|
34
|
+
font-size: 17px;
|
|
35
|
+
line-height: 1.3;
|
|
36
|
+
}
|
|
37
|
+
.file-launch {
|
|
38
|
+
display: grid;
|
|
39
|
+
grid-template-columns: minmax(0, 1.45fr) minmax(224px, 0.85fr);
|
|
40
|
+
gap: clamp(18px, 4vw, 54px);
|
|
41
|
+
align-items: start;
|
|
42
|
+
margin: clamp(25px, 4vw, 42px) 0;
|
|
43
|
+
padding-block-end: clamp(22px, 4vw, 38px);
|
|
44
|
+
border-block-end: 1px solid var(--wb-border);
|
|
45
|
+
}
|
|
46
|
+
.file-templates {
|
|
47
|
+
gap: 10px;
|
|
48
|
+
margin-block-start: 12px;
|
|
49
|
+
}
|
|
50
|
+
.file-templates button {
|
|
51
|
+
flex: 1;
|
|
52
|
+
min-width: 0;
|
|
53
|
+
padding: 0;
|
|
54
|
+
border: 0;
|
|
55
|
+
background: transparent;
|
|
56
|
+
text-align: start;
|
|
57
|
+
font-weight: 550;
|
|
58
|
+
}
|
|
59
|
+
.template-sheet {
|
|
60
|
+
display: grid;
|
|
61
|
+
aspect-ratio: 16 / 9;
|
|
62
|
+
place-items: center;
|
|
63
|
+
margin-block-end: 6px;
|
|
64
|
+
overflow: hidden;
|
|
65
|
+
border: 1px solid var(--wb-border);
|
|
66
|
+
border-radius: var(--wb-radius);
|
|
67
|
+
}
|
|
68
|
+
.blank-sheet {
|
|
69
|
+
background: var(--wb-canvas);
|
|
70
|
+
color: var(--wb-muted);
|
|
71
|
+
font-size: 26px;
|
|
72
|
+
font-weight: 350;
|
|
73
|
+
}
|
|
74
|
+
.templates-heading {
|
|
75
|
+
display: flex;
|
|
76
|
+
align-items: center;
|
|
77
|
+
justify-content: space-between;
|
|
78
|
+
gap: 10px;
|
|
79
|
+
}
|
|
80
|
+
.templates-heading .link {
|
|
81
|
+
color: var(--wb-muted);
|
|
82
|
+
font-size: 12px;
|
|
83
|
+
}
|
|
84
|
+
.templates-heading .link:hover {
|
|
85
|
+
color: var(--wb-fg);
|
|
86
|
+
text-decoration: underline;
|
|
87
|
+
}
|
|
88
|
+
.slide-preview {
|
|
89
|
+
display: block;
|
|
90
|
+
position: relative;
|
|
91
|
+
container-type: inline-size;
|
|
92
|
+
aspect-ratio: 16/9;
|
|
93
|
+
overflow: hidden;
|
|
94
|
+
text-align: left;
|
|
95
|
+
}
|
|
96
|
+
.slide-preview > span {
|
|
97
|
+
position: absolute;
|
|
98
|
+
display: block;
|
|
99
|
+
overflow: hidden;
|
|
100
|
+
overflow-wrap: anywhere;
|
|
101
|
+
font-family: system-ui, sans-serif;
|
|
102
|
+
}
|
|
103
|
+
.file-templates button:hover .template-sheet {
|
|
104
|
+
border-color: var(--wb-muted);
|
|
105
|
+
}
|
|
106
|
+
.file-home .start-ask {
|
|
107
|
+
width: auto;
|
|
108
|
+
min-width: 0;
|
|
109
|
+
margin: 0;
|
|
110
|
+
align-items: stretch;
|
|
111
|
+
gap: 10px;
|
|
112
|
+
}
|
|
113
|
+
.file-home .start-ask textarea {
|
|
114
|
+
min-height: 65px;
|
|
115
|
+
padding: 10px 12px;
|
|
116
|
+
resize: vertical;
|
|
117
|
+
}
|
|
118
|
+
.file-home .start-ask button {
|
|
119
|
+
align-self: end;
|
|
120
|
+
}
|
|
121
|
+
.file-head,
|
|
122
|
+
.file-row {
|
|
123
|
+
display: grid;
|
|
124
|
+
align-items: center;
|
|
125
|
+
grid-template-columns: minmax(0, 1fr) 140px;
|
|
126
|
+
}
|
|
127
|
+
.file-head {
|
|
128
|
+
grid-template-columns: minmax(0, 1fr) clamp(125px, 22vw, 232px) 140px;
|
|
129
|
+
padding: 12px 0 7px;
|
|
130
|
+
border-bottom: 1px solid var(--wb-border);
|
|
131
|
+
color: var(--wb-muted);
|
|
132
|
+
font-size: 12px;
|
|
133
|
+
}
|
|
134
|
+
.file-rows {
|
|
135
|
+
list-style: none;
|
|
136
|
+
padding: 0;
|
|
137
|
+
margin: 0;
|
|
138
|
+
}
|
|
139
|
+
.file-row {
|
|
140
|
+
border-block-end: 1px solid var(--wb-border);
|
|
141
|
+
}
|
|
142
|
+
.file-row .file-open {
|
|
143
|
+
display: grid;
|
|
144
|
+
grid-template-columns: 38px minmax(0, 1fr) clamp(125px, 22vw, 232px);
|
|
145
|
+
gap: 12px;
|
|
146
|
+
align-items: center;
|
|
147
|
+
align-self: stretch;
|
|
148
|
+
padding: 10px 0 10px 2px;
|
|
149
|
+
border: 0;
|
|
150
|
+
background: transparent;
|
|
151
|
+
text-align: start;
|
|
152
|
+
}
|
|
153
|
+
.file-description {
|
|
154
|
+
flex-direction: column;
|
|
155
|
+
align-items: start;
|
|
156
|
+
min-width: 0;
|
|
157
|
+
}
|
|
158
|
+
.file-open strong {
|
|
159
|
+
font-size: 14px;
|
|
160
|
+
font-weight: 600;
|
|
161
|
+
max-width: 100%;
|
|
162
|
+
overflow: hidden;
|
|
163
|
+
white-space: nowrap;
|
|
164
|
+
text-overflow: ellipsis;
|
|
165
|
+
}
|
|
166
|
+
.file-open small,
|
|
167
|
+
.file-open time {
|
|
168
|
+
color: var(--wb-muted);
|
|
169
|
+
font-size: 12px;
|
|
170
|
+
font-weight: 400;
|
|
171
|
+
}
|
|
172
|
+
.slide-file-icon {
|
|
173
|
+
display: block;
|
|
174
|
+
width: 34px;
|
|
175
|
+
aspect-ratio: 16/10;
|
|
176
|
+
border: 1.5px solid var(--wb-muted);
|
|
177
|
+
border-radius: 3px;
|
|
178
|
+
position: relative;
|
|
179
|
+
color: var(--wb-muted);
|
|
180
|
+
}
|
|
181
|
+
.slide-file-icon::before {
|
|
182
|
+
content: "";
|
|
183
|
+
position: absolute;
|
|
184
|
+
inset: 22% 30% 45% 16%;
|
|
185
|
+
border-block-start: 2px solid currentColor;
|
|
186
|
+
border-block-end: 1px solid currentColor;
|
|
187
|
+
}
|
|
188
|
+
.file-open:hover,
|
|
189
|
+
.file-actions button:hover {
|
|
190
|
+
background: var(--wb-hover);
|
|
191
|
+
}
|
|
192
|
+
.file-actions {
|
|
193
|
+
justify-content: end;
|
|
194
|
+
gap: 2px;
|
|
195
|
+
}
|
|
196
|
+
.file-actions button {
|
|
197
|
+
padding: 7px 8px;
|
|
198
|
+
border: 0;
|
|
199
|
+
background: transparent;
|
|
200
|
+
color: var(--wb-muted);
|
|
201
|
+
font-size: 12px;
|
|
202
|
+
}
|
|
203
|
+
.file-home .file-status {
|
|
204
|
+
color: var(--wb-muted);
|
|
205
|
+
margin: 14px 0;
|
|
206
|
+
}
|
|
207
|
+
.file-home .file-status:empty {
|
|
208
|
+
display: none;
|
|
209
|
+
}
|
|
210
|
+
@media (max-width: 570px) {
|
|
211
|
+
.file-header {
|
|
212
|
+
gap: 8px;
|
|
213
|
+
}
|
|
214
|
+
.file-home h1 {
|
|
215
|
+
flex-shrink: 0;
|
|
216
|
+
font-size: 23px;
|
|
217
|
+
}
|
|
218
|
+
#start-import {
|
|
219
|
+
min-width: 0;
|
|
220
|
+
max-width: 53%;
|
|
221
|
+
}
|
|
222
|
+
.file-launch {
|
|
223
|
+
grid-template-columns: minmax(0, 1fr);
|
|
224
|
+
gap: 22px;
|
|
225
|
+
}
|
|
226
|
+
.file-head {
|
|
227
|
+
display: none;
|
|
228
|
+
}
|
|
229
|
+
.file-rows {
|
|
230
|
+
margin-block-start: 9px;
|
|
231
|
+
border-block-start: 1px solid var(--wb-border);
|
|
232
|
+
}
|
|
233
|
+
.file-row {
|
|
234
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
235
|
+
}
|
|
236
|
+
.file-row .file-open {
|
|
237
|
+
grid-template-columns: 28px minmax(0, 1fr);
|
|
238
|
+
gap: 2px 8px;
|
|
239
|
+
}
|
|
240
|
+
.slide-file-icon {
|
|
241
|
+
width: 26px;
|
|
242
|
+
grid-row: 1 / span 2;
|
|
243
|
+
}
|
|
244
|
+
.file-open time {
|
|
245
|
+
grid-column: 2;
|
|
246
|
+
font-size: 11px;
|
|
247
|
+
}
|
|
248
|
+
.file-actions {
|
|
249
|
+
flex-direction: column;
|
|
250
|
+
align-items: stretch;
|
|
251
|
+
}
|
|
252
|
+
.file-actions button {
|
|
253
|
+
min-height: 32px;
|
|
254
|
+
padding: 4px 6px;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
#deck-action form {
|
|
258
|
+
display: grid;
|
|
259
|
+
gap: 12px;
|
|
260
|
+
max-width: min(360px, 80vw);
|
|
261
|
+
}
|
|
262
|
+
#deck-action h2,
|
|
263
|
+
#deck-action p {
|
|
264
|
+
margin: 0;
|
|
265
|
+
}
|
|
266
|
+
#deck-action-message:empty {
|
|
267
|
+
display: none;
|
|
268
|
+
}
|
|
269
|
+
#rename-field {
|
|
270
|
+
display: grid;
|
|
271
|
+
gap: 4px;
|
|
272
|
+
}
|
|
273
|
+
#deck-action {
|
|
274
|
+
color: var(--wb-fg);
|
|
275
|
+
background: var(--wb-canvas);
|
|
276
|
+
border: 1px solid var(--wb-border);
|
|
277
|
+
border-radius: var(--wb-radius);
|
|
278
|
+
padding: 20px;
|
|
279
|
+
}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
// Saved presentations always come from the Agent's deck collection. Only the open dialog is local.
|
|
2
|
+
import { S, locale } from "./strings.js";
|
|
3
|
+
|
|
4
|
+
const labels =
|
|
5
|
+
locale === "zh"
|
|
6
|
+
? {
|
|
7
|
+
title: "演示文稿",
|
|
8
|
+
recent: "最近编辑",
|
|
9
|
+
modified: "上次修改",
|
|
10
|
+
name: "文稿名称",
|
|
11
|
+
sample: "打开示例",
|
|
12
|
+
open: "导入演示文稿…",
|
|
13
|
+
rename: "重命名",
|
|
14
|
+
remove: "删除",
|
|
15
|
+
importHint: "选择 Bento 演示文稿文件(.html 或 .json)",
|
|
16
|
+
ai: "使用 AI 创建",
|
|
17
|
+
empty: "还没有保存的演示文稿。",
|
|
18
|
+
loading: "正在读取演示文稿…",
|
|
19
|
+
failed: "无法读取演示文稿。",
|
|
20
|
+
retry: "重试",
|
|
21
|
+
editFailed: "无法保存新名称,请重试。",
|
|
22
|
+
conflict: "这份文稿刚刚被修改。请重新打开重命名。",
|
|
23
|
+
save: "保存名称",
|
|
24
|
+
removeHeading: "删除演示文稿?",
|
|
25
|
+
removeBody: (title) => `将删除《${title}》及其版本历史。`,
|
|
26
|
+
returnHome: "返回文稿列表",
|
|
27
|
+
openFailed: "无法打开文稿,请重试。",
|
|
28
|
+
}
|
|
29
|
+
: {
|
|
30
|
+
title: "Presentations",
|
|
31
|
+
recent: "Recently edited",
|
|
32
|
+
modified: "Last modified",
|
|
33
|
+
name: "Presentation name",
|
|
34
|
+
sample: "Open sample",
|
|
35
|
+
open: "Import a presentation…",
|
|
36
|
+
rename: "Rename",
|
|
37
|
+
remove: "Delete",
|
|
38
|
+
importHint: "Choose a Bento presentation file (.html or .json)",
|
|
39
|
+
ai: "Create with AI",
|
|
40
|
+
empty: "No saved presentations yet.",
|
|
41
|
+
loading: "Loading presentations…",
|
|
42
|
+
failed: "Couldn’t load presentations.",
|
|
43
|
+
retry: "Retry",
|
|
44
|
+
editFailed: "Couldn’t save the new name. Try again.",
|
|
45
|
+
conflict: "This presentation has changed. Reopen Rename to use its latest version.",
|
|
46
|
+
save: "Save name",
|
|
47
|
+
removeHeading: "Delete presentation?",
|
|
48
|
+
removeBody: (title) => `“${title}” and its version history will be deleted.`,
|
|
49
|
+
returnHome: "Back to presentations",
|
|
50
|
+
openFailed: "Couldn’t open the presentation. Try again.",
|
|
51
|
+
};
|
|
52
|
+
const dates = new Intl.DateTimeFormat(locale === "zh" ? "zh-CN" : "en", {
|
|
53
|
+
dateStyle: "medium",
|
|
54
|
+
timeStyle: "short",
|
|
55
|
+
});
|
|
56
|
+
const $ = (id) => document.getElementById(id);
|
|
57
|
+
const action = (label, hint = label) => {
|
|
58
|
+
const button = document.createElement("button");
|
|
59
|
+
button.type = "button";
|
|
60
|
+
button.textContent = label;
|
|
61
|
+
button.setAttribute("aria-label", hint);
|
|
62
|
+
return button;
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
export function deckFiles({ onOpen, onRename, onDelete, onRefresh, onBack }) {
|
|
66
|
+
for (const node of document.querySelectorAll("[data-files-copy]"))
|
|
67
|
+
node.textContent = labels[node.dataset.filesCopy];
|
|
68
|
+
$("show-decks").setAttribute("aria-label", labels.returnHome);
|
|
69
|
+
$("show-decks").title = labels.returnHome;
|
|
70
|
+
$("show-decks").onclick = onBack;
|
|
71
|
+
$("start-import").title = $("import").title = labels.importHint;
|
|
72
|
+
$("retry-decks").onclick = onRefresh;
|
|
73
|
+
const dialog = $("deck-action");
|
|
74
|
+
let target = null;
|
|
75
|
+
let busy = false;
|
|
76
|
+
|
|
77
|
+
function edit(deck, mode) {
|
|
78
|
+
target = { deck, mode };
|
|
79
|
+
$("deck-action-title").textContent = mode === "rename" ? labels.rename : labels.removeHeading;
|
|
80
|
+
$("rename-field").hidden = mode !== "rename";
|
|
81
|
+
$("remove-message").hidden = mode !== "delete";
|
|
82
|
+
$("remove-message").textContent = labels.removeBody(deck.title);
|
|
83
|
+
$("rename-title").value = deck.title;
|
|
84
|
+
$("deck-action-message").textContent = "";
|
|
85
|
+
$("confirm-deck-action").textContent = mode === "rename" ? labels.save : labels.remove;
|
|
86
|
+
dialog.showModal();
|
|
87
|
+
if (mode === "rename") {
|
|
88
|
+
$("rename-title").focus();
|
|
89
|
+
$("rename-title").select();
|
|
90
|
+
} else $("cancel-deck-action").focus();
|
|
91
|
+
}
|
|
92
|
+
$("cancel-deck-action").onclick = () => dialog.close();
|
|
93
|
+
dialog.addEventListener("cancel", (event) => {
|
|
94
|
+
if (busy) event.preventDefault();
|
|
95
|
+
});
|
|
96
|
+
dialog.addEventListener("close", () => {
|
|
97
|
+
target = null;
|
|
98
|
+
});
|
|
99
|
+
$("deck-action-form").onsubmit = async (event) => {
|
|
100
|
+
event.preventDefault();
|
|
101
|
+
if (!target || busy) return;
|
|
102
|
+
const { deck, mode } = target;
|
|
103
|
+
const title = $("rename-title").value.trim();
|
|
104
|
+
if (mode === "rename" && !title) {
|
|
105
|
+
$("rename-title").focus();
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
busy = true;
|
|
109
|
+
$("cancel-deck-action").disabled = $("confirm-deck-action").disabled = true;
|
|
110
|
+
try {
|
|
111
|
+
if (mode === "rename" && title !== deck.title) await onRename(deck, title);
|
|
112
|
+
if (mode === "delete") await onDelete(deck.id);
|
|
113
|
+
dialog.close();
|
|
114
|
+
} catch (err) {
|
|
115
|
+
$("deck-action-message").textContent =
|
|
116
|
+
err?.status === 409
|
|
117
|
+
? labels.conflict
|
|
118
|
+
: mode === "rename"
|
|
119
|
+
? labels.editFailed
|
|
120
|
+
: S.deleteFailed(String(err?.message || ""));
|
|
121
|
+
} finally {
|
|
122
|
+
busy = false;
|
|
123
|
+
$("cancel-deck-action").disabled = $("confirm-deck-action").disabled = false;
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
|
|
127
|
+
function render(decks, state) {
|
|
128
|
+
const list = $("recent-decks");
|
|
129
|
+
const message = $("list-message");
|
|
130
|
+
message.textContent =
|
|
131
|
+
state === "error"
|
|
132
|
+
? labels.failed
|
|
133
|
+
: state === "loading"
|
|
134
|
+
? labels.loading
|
|
135
|
+
: decks.length
|
|
136
|
+
? ""
|
|
137
|
+
: labels.empty;
|
|
138
|
+
$("retry-decks").hidden = state !== "error";
|
|
139
|
+
// Keep the last successful listing usable through a transient read error.
|
|
140
|
+
if (state !== "ready") return;
|
|
141
|
+
const rows = decks.map((deck) => {
|
|
142
|
+
const row = document.createElement("li");
|
|
143
|
+
row.className = "file-row";
|
|
144
|
+
const open = document.createElement("button");
|
|
145
|
+
open.type = "button";
|
|
146
|
+
open.setAttribute("aria-label", deck.title);
|
|
147
|
+
open.className = "file-open";
|
|
148
|
+
open.dataset.openDeck = deck.id;
|
|
149
|
+
const name = document.createElement("strong");
|
|
150
|
+
name.textContent = deck.title;
|
|
151
|
+
const meta = document.createElement("small");
|
|
152
|
+
meta.textContent = S.slides(deck.slides);
|
|
153
|
+
const file = document.createElement("span");
|
|
154
|
+
file.className = "file-description";
|
|
155
|
+
file.append(name, meta);
|
|
156
|
+
open.onclick = () => onOpen(deck.id);
|
|
157
|
+
const time = document.createElement("time");
|
|
158
|
+
if (Number.isFinite(deck.mtimeMs)) {
|
|
159
|
+
time.dateTime = new Date(deck.mtimeMs).toISOString();
|
|
160
|
+
time.textContent = dates.format(deck.mtimeMs);
|
|
161
|
+
}
|
|
162
|
+
const icon = document.createElement("span");
|
|
163
|
+
icon.className = "slide-file-icon";
|
|
164
|
+
icon.setAttribute("aria-hidden", "true");
|
|
165
|
+
open.append(icon, file, time);
|
|
166
|
+
const actions = document.createElement("div");
|
|
167
|
+
actions.className = "file-actions";
|
|
168
|
+
const rename = action(labels.rename, `${labels.rename} · ${deck.title}`);
|
|
169
|
+
rename.dataset.renameDeck = deck.id;
|
|
170
|
+
rename.onclick = () => edit(deck, "rename");
|
|
171
|
+
const remove = action(labels.remove, `${labels.remove} · ${deck.title}`);
|
|
172
|
+
remove.dataset.removeDeck = deck.id;
|
|
173
|
+
remove.onclick = () => edit(deck, "delete");
|
|
174
|
+
actions.append(rename, remove);
|
|
175
|
+
row.append(open, actions);
|
|
176
|
+
return row;
|
|
177
|
+
});
|
|
178
|
+
// An Agent save can reorder the list while someone is using it with the keyboard.
|
|
179
|
+
const selected = list.contains(document.activeElement) ? document.activeElement : null;
|
|
180
|
+
const key = selected && Object.keys(selected.dataset)[0];
|
|
181
|
+
const id = key && selected.dataset[key];
|
|
182
|
+
list.replaceChildren(...rows);
|
|
183
|
+
if (id)
|
|
184
|
+
Array.from(list.querySelectorAll("button"))
|
|
185
|
+
.find((button) => button.dataset[key] === id)
|
|
186
|
+
?.focus({ preventScroll: true });
|
|
187
|
+
}
|
|
188
|
+
return { render, openFailed: labels.openFailed };
|
|
189
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
// The editor lives in another frame, so clicks there never bubble to this document.
|
|
2
|
+
export function setupFileMenu(trigger, menu) {
|
|
3
|
+
const items = () => Array.from(menu.querySelectorAll('[role="menuitem"]:not(:disabled)'));
|
|
4
|
+
|
|
5
|
+
function close(restoreFocus = false) {
|
|
6
|
+
if (menu.hidden) return;
|
|
7
|
+
menu.hidden = true;
|
|
8
|
+
trigger.setAttribute("aria-expanded", "false");
|
|
9
|
+
if (restoreFocus) trigger.focus();
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
function open(last = false) {
|
|
13
|
+
menu.hidden = false;
|
|
14
|
+
trigger.setAttribute("aria-expanded", "true");
|
|
15
|
+
items()
|
|
16
|
+
.at(last ? -1 : 0)
|
|
17
|
+
?.focus();
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
trigger.addEventListener("click", () => (menu.hidden ? open() : close(true)));
|
|
21
|
+
trigger.addEventListener("keydown", (event) => {
|
|
22
|
+
if (event.key !== "ArrowDown" && event.key !== "ArrowUp") return;
|
|
23
|
+
event.preventDefault();
|
|
24
|
+
open(event.key === "ArrowUp");
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
menu.addEventListener("keydown", (event) => {
|
|
28
|
+
if (event.key === "Tab") return close(true); // Let Tab continue from the trigger.
|
|
29
|
+
if (event.key === "Escape") {
|
|
30
|
+
event.preventDefault();
|
|
31
|
+
close(true);
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const choices = items();
|
|
35
|
+
const position = choices.indexOf(document.activeElement);
|
|
36
|
+
let next;
|
|
37
|
+
switch (event.key) {
|
|
38
|
+
case "ArrowDown":
|
|
39
|
+
next = (position + 1) % choices.length;
|
|
40
|
+
break;
|
|
41
|
+
case "ArrowUp":
|
|
42
|
+
next = (position + choices.length - 1) % choices.length;
|
|
43
|
+
break;
|
|
44
|
+
case "Home":
|
|
45
|
+
next = 0;
|
|
46
|
+
break;
|
|
47
|
+
case "End":
|
|
48
|
+
next = choices.length - 1;
|
|
49
|
+
break;
|
|
50
|
+
default:
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
event.preventDefault();
|
|
54
|
+
choices[next]?.focus();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
// Close before an action opens its dialog, so closing the dialog restores focus to File.
|
|
58
|
+
menu.addEventListener(
|
|
59
|
+
"click",
|
|
60
|
+
(event) => {
|
|
61
|
+
if (event.target.closest('[role="menuitem"]')) close(true);
|
|
62
|
+
},
|
|
63
|
+
true,
|
|
64
|
+
);
|
|
65
|
+
document.addEventListener("pointerdown", (event) => {
|
|
66
|
+
if (!menu.contains(event.target) && !trigger.contains(event.target)) close();
|
|
67
|
+
});
|
|
68
|
+
document.addEventListener("focusin", (event) => {
|
|
69
|
+
if (!menu.contains(event.target) && event.target !== trigger) close();
|
|
70
|
+
});
|
|
71
|
+
window.addEventListener("blur", () => close());
|
|
72
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 48 48">
|
|
2
|
+
<rect width="48" height="48" rx="11" fill="#ea580c" />
|
|
3
|
+
<g transform="translate(12 12)" fill="none" stroke="#ffffff" stroke-width="1.7" stroke-linecap="round" stroke-linejoin="round">
|
|
4
|
+
<rect x="3" y="4" width="18" height="12" rx="1.6" />
|
|
5
|
+
<path d="M12 16v4" />
|
|
6
|
+
<path d="M8.5 20h7" />
|
|
7
|
+
<path d="m12 6.6 1 2.4 2.4 1-2.4 1-1 2.4-1-2.4-2.4-1 2.4-1z" />
|
|
8
|
+
</g>
|
|
9
|
+
</svg>
|