pinokiod 7.2.17 → 7.3.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/Dockerfile +2 -0
- package/kernel/api/index.js +1 -42
- package/kernel/api/process/index.js +44 -99
- package/kernel/bin/conda-python.js +30 -0
- package/kernel/bin/conda.js +22 -3
- package/kernel/bin/index.js +11 -1
- package/kernel/environment.js +2 -182
- package/kernel/git.js +13 -0
- package/kernel/index.js +1 -64
- package/kernel/plugin.js +58 -6
- package/kernel/shell.js +2 -21
- package/kernel/util.js +0 -60
- package/package.json +1 -1
- package/server/index.js +149 -176
- package/server/lib/content_validation.js +25 -28
- package/server/public/common.js +29 -103
- package/server/public/create-launcher.js +31 -4
- package/server/public/electron.css +6 -0
- package/server/public/style.css +0 -337
- package/server/public/task-launcher.js +32 -5
- package/server/public/universal-launcher.js +26 -3
- package/server/socket.js +11 -22
- package/server/views/app.ejs +30 -167
- package/server/views/d.ejs +33 -0
- package/server/views/editor.ejs +4 -25
- package/server/views/partials/main_sidebar.ejs +0 -1
- package/server/views/shell.ejs +3 -11
- package/server/views/terminal.ejs +3 -23
- package/server/views/terminals.ejs +0 -1
- package/spec/INSTRUCTION_SYNC.md +5 -5
- package/kernel/api/shell_run_template.js +0 -273
- package/kernel/api/uri/index.js +0 -51
- package/kernel/plugin_sources.js +0 -236
- package/kernel/watch/context.js +0 -42
- package/kernel/watch/drivers/fs.js +0 -71
- package/kernel/watch/drivers/poll.js +0 -33
- package/kernel/watch/index.js +0 -158
- package/server/features/drafts/index.js +0 -41
- package/server/features/drafts/parser.js +0 -169
- package/server/features/drafts/public/drafts.js +0 -1504
- package/server/features/drafts/registry_import.js +0 -412
- package/server/features/drafts/routes.js +0 -68
- package/server/features/drafts/service.js +0 -261
- package/server/features/drafts/watcher.js +0 -76
- package/server/features/index.js +0 -13
- package/server/lib/workspace_catalog.js +0 -151
- package/server/lib/workspace_runtime.js +0 -390
- package/server/routes/workspaces.js +0 -44
- package/server/views/partials/workspace_row.ejs +0 -61
- package/server/views/workspaces.ejs +0 -812
- package/system/plugin/antigravity/antigravity.png +0 -0
- package/system/plugin/antigravity/pinokio.js +0 -37
- package/system/plugin/claude/claude.png +0 -0
- package/system/plugin/claude/pinokio.js +0 -63
- package/system/plugin/claude-auto/claude.png +0 -0
- package/system/plugin/claude-auto/pinokio.js +0 -74
- package/system/plugin/claude-desktop/icon.jpeg +0 -0
- package/system/plugin/claude-desktop/pinokio.js +0 -39
- package/system/plugin/codex/openai.webp +0 -0
- package/system/plugin/codex/pinokio.js +0 -58
- package/system/plugin/codex-auto/openai.webp +0 -0
- package/system/plugin/codex-auto/pinokio.js +0 -65
- package/system/plugin/codex-desktop/icon.png +0 -0
- package/system/plugin/codex-desktop/pinokio.js +0 -39
- package/system/plugin/crush/crush.png +0 -0
- package/system/plugin/crush/pinokio.js +0 -31
- package/system/plugin/cursor/cursor.jpeg +0 -0
- package/system/plugin/cursor/pinokio.js +0 -39
- package/system/plugin/gemini/gemini.jpeg +0 -0
- package/system/plugin/gemini/pinokio.js +0 -40
- package/system/plugin/gemini-auto/gemini.jpeg +0 -0
- package/system/plugin/gemini-auto/pinokio.js +0 -43
- package/system/plugin/qwen/pinokio.js +0 -50
- package/system/plugin/qwen/qwen.png +0 -0
- package/system/plugin/vscode/pinokio.js +0 -36
- package/system/plugin/vscode/vscode.png +0 -0
- package/system/plugin/windsurf/pinokio.js +0 -39
- package/system/plugin/windsurf/windsurf.png +0 -0
|
@@ -1,1504 +0,0 @@
|
|
|
1
|
-
(function () {
|
|
2
|
-
if (window.__PinokioDraftsLoaded) {
|
|
3
|
-
return;
|
|
4
|
-
}
|
|
5
|
-
window.__PinokioDraftsLoaded = true;
|
|
6
|
-
|
|
7
|
-
const context = window.PinokioDraftContext || {};
|
|
8
|
-
const activeCwd = typeof context.cwd === "string" ? context.cwd.trim() : "";
|
|
9
|
-
if (!activeCwd) {
|
|
10
|
-
return;
|
|
11
|
-
}
|
|
12
|
-
const PUSH_ENDPOINT = "/push";
|
|
13
|
-
const SOUND_PREF_STORAGE_KEY = "pinokio:idle-sound";
|
|
14
|
-
const SOUND_SILENT_CHOICE = "__silent__";
|
|
15
|
-
const DRAFT_NOTIFIED_PREFIX = "pinokio:draft-notified:";
|
|
16
|
-
const state = {
|
|
17
|
-
expanded: new Set(),
|
|
18
|
-
initialRefreshComplete: false,
|
|
19
|
-
items: [],
|
|
20
|
-
lastSignature: "",
|
|
21
|
-
notifiedIds: new Set(),
|
|
22
|
-
drawerItemId: "",
|
|
23
|
-
drawerTab: "preview"
|
|
24
|
-
};
|
|
25
|
-
function resolveNotificationSound() {
|
|
26
|
-
try {
|
|
27
|
-
const raw = localStorage.getItem(SOUND_PREF_STORAGE_KEY);
|
|
28
|
-
const parsed = raw ? JSON.parse(raw) : null;
|
|
29
|
-
const choice = parsed && typeof parsed.choice === "string" ? parsed.choice.trim() : "";
|
|
30
|
-
if (choice === SOUND_SILENT_CHOICE) {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
const withLeading = choice.startsWith("/") ? choice : `/${choice}`;
|
|
34
|
-
const decoded = decodeURIComponent(withLeading);
|
|
35
|
-
if (decoded.startsWith("/sound/") && !decoded.includes("..")) {
|
|
36
|
-
return withLeading;
|
|
37
|
-
}
|
|
38
|
-
} catch (_) {}
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function claimDraftNotification(id) {
|
|
43
|
-
const normalized = typeof id === "string" ? id.trim() : "";
|
|
44
|
-
if (!normalized) {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
if (state.notifiedIds.has(normalized)) {
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
state.notifiedIds.add(normalized);
|
|
51
|
-
try {
|
|
52
|
-
const key = `${DRAFT_NOTIFIED_PREFIX}${normalized}`;
|
|
53
|
-
if (localStorage.getItem(key)) {
|
|
54
|
-
return false;
|
|
55
|
-
}
|
|
56
|
-
const token = `${Date.now()}:${Math.random().toString(36).slice(2)}`;
|
|
57
|
-
localStorage.setItem(key, token);
|
|
58
|
-
return localStorage.getItem(key) === token;
|
|
59
|
-
} catch (_) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function notifyDraftReady(item) {
|
|
65
|
-
const notificationKey = item && item.id
|
|
66
|
-
? `${item.id}:${item.revision || item.updatedAt || ""}`
|
|
67
|
-
: "";
|
|
68
|
-
if (!item || !claimDraftNotification(notificationKey)) {
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
const title = typeof item.title === "string" && item.title.trim() ? item.title.trim() : "Draft";
|
|
72
|
-
const workspaceName = typeof item.workspaceName === "string" && item.workspaceName.trim() ? item.workspaceName.trim() : "";
|
|
73
|
-
const message = workspaceName ? `${workspaceName}: ${title}` : `Draft ready: ${title}`;
|
|
74
|
-
const sound = resolveNotificationSound();
|
|
75
|
-
const playedInline = typeof window.PinokioPlayNotificationSound === "function"
|
|
76
|
-
? window.PinokioPlayNotificationSound(sound)
|
|
77
|
-
: false;
|
|
78
|
-
const payload = {
|
|
79
|
-
title: "Pinokio",
|
|
80
|
-
message,
|
|
81
|
-
timeout: 60,
|
|
82
|
-
sound: playedInline ? false : sound,
|
|
83
|
-
audience: "device",
|
|
84
|
-
device_id: (typeof window.PinokioGetDeviceId === "function") ? window.PinokioGetDeviceId() : undefined
|
|
85
|
-
};
|
|
86
|
-
try {
|
|
87
|
-
fetch(PUSH_ENDPOINT, {
|
|
88
|
-
method: "POST",
|
|
89
|
-
headers: {
|
|
90
|
-
"Content-Type": "application/json"
|
|
91
|
-
},
|
|
92
|
-
credentials: "include",
|
|
93
|
-
body: JSON.stringify(payload)
|
|
94
|
-
}).catch(() => {});
|
|
95
|
-
} catch (_) {
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function ensureStyles() {
|
|
100
|
-
if (document.getElementById("pinokio-drafts-style")) {
|
|
101
|
-
return;
|
|
102
|
-
}
|
|
103
|
-
const style = document.createElement("style");
|
|
104
|
-
style.id = "pinokio-drafts-style";
|
|
105
|
-
style.textContent = `
|
|
106
|
-
.pinokio-drafts {
|
|
107
|
-
position: fixed;
|
|
108
|
-
right: 16px;
|
|
109
|
-
bottom: 16px;
|
|
110
|
-
z-index: 2147483000;
|
|
111
|
-
display: flex;
|
|
112
|
-
flex-direction: column;
|
|
113
|
-
gap: 10px;
|
|
114
|
-
width: min(390px, calc(100vw - 24px));
|
|
115
|
-
pointer-events: none;
|
|
116
|
-
color: #111827;
|
|
117
|
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
118
|
-
}
|
|
119
|
-
.pinokio-draft-card {
|
|
120
|
-
border: 1px solid rgba(15, 23, 42, 0.16);
|
|
121
|
-
border-radius: 8px;
|
|
122
|
-
background: rgba(255, 255, 255, 0.96);
|
|
123
|
-
box-shadow: 0 14px 38px rgba(15, 23, 42, 0.18);
|
|
124
|
-
cursor: pointer;
|
|
125
|
-
overflow: hidden;
|
|
126
|
-
pointer-events: auto;
|
|
127
|
-
transition: border-color 120ms ease, box-shadow 120ms ease, transform 120ms ease;
|
|
128
|
-
}
|
|
129
|
-
.pinokio-draft-card:hover,
|
|
130
|
-
.pinokio-draft-card:focus {
|
|
131
|
-
border-color: rgba(15, 23, 42, 0.28);
|
|
132
|
-
box-shadow: 0 16px 42px rgba(15, 23, 42, 0.22);
|
|
133
|
-
outline: none;
|
|
134
|
-
transform: translateY(-1px);
|
|
135
|
-
}
|
|
136
|
-
body.dark .pinokio-draft-card {
|
|
137
|
-
border-color: rgba(255, 255, 255, 0.16);
|
|
138
|
-
background: rgba(23, 23, 25, 0.96);
|
|
139
|
-
box-shadow: 0 16px 42px rgba(0, 0, 0, 0.38);
|
|
140
|
-
}
|
|
141
|
-
body.dark .pinokio-draft-card:hover,
|
|
142
|
-
body.dark .pinokio-draft-card:focus {
|
|
143
|
-
border-color: rgba(251, 191, 36, 0.38);
|
|
144
|
-
box-shadow: 0 18px 46px rgba(0, 0, 0, 0.46);
|
|
145
|
-
}
|
|
146
|
-
.pinokio-draft-head {
|
|
147
|
-
display: flex;
|
|
148
|
-
gap: 10px;
|
|
149
|
-
align-items: flex-start;
|
|
150
|
-
padding: 14px 14px 16px;
|
|
151
|
-
}
|
|
152
|
-
.pinokio-draft-icon {
|
|
153
|
-
display: grid;
|
|
154
|
-
place-items: center;
|
|
155
|
-
flex: 0 0 auto;
|
|
156
|
-
width: 30px;
|
|
157
|
-
height: 30px;
|
|
158
|
-
border-radius: 7px;
|
|
159
|
-
background: #fef3c7;
|
|
160
|
-
color: #a16207;
|
|
161
|
-
font-size: 14px;
|
|
162
|
-
}
|
|
163
|
-
body.dark .pinokio-draft-icon {
|
|
164
|
-
background: rgba(245, 158, 11, 0.18);
|
|
165
|
-
color: #fbbf24;
|
|
166
|
-
}
|
|
167
|
-
.pinokio-draft-copy {
|
|
168
|
-
min-width: 0;
|
|
169
|
-
flex: 1 1 auto;
|
|
170
|
-
}
|
|
171
|
-
.pinokio-draft-kicker {
|
|
172
|
-
display: inline-flex;
|
|
173
|
-
align-items: center;
|
|
174
|
-
gap: 5px;
|
|
175
|
-
color: #a16207;
|
|
176
|
-
font-size: 11px;
|
|
177
|
-
font-weight: 700;
|
|
178
|
-
letter-spacing: 0;
|
|
179
|
-
text-transform: uppercase;
|
|
180
|
-
line-height: 1.2;
|
|
181
|
-
margin-bottom: 3px;
|
|
182
|
-
}
|
|
183
|
-
body.dark .pinokio-draft-kicker {
|
|
184
|
-
color: #fbbf24;
|
|
185
|
-
}
|
|
186
|
-
.pinokio-draft-kicker i {
|
|
187
|
-
font-size: 10px;
|
|
188
|
-
}
|
|
189
|
-
.pinokio-draft-title {
|
|
190
|
-
color: #111827;
|
|
191
|
-
font-size: 14px;
|
|
192
|
-
font-weight: 700;
|
|
193
|
-
line-height: 1.25;
|
|
194
|
-
overflow-wrap: anywhere;
|
|
195
|
-
}
|
|
196
|
-
body.dark .pinokio-draft-title {
|
|
197
|
-
color: #f8fafc;
|
|
198
|
-
}
|
|
199
|
-
.pinokio-draft-meta {
|
|
200
|
-
display: flex;
|
|
201
|
-
flex-wrap: wrap;
|
|
202
|
-
gap: 4px 8px;
|
|
203
|
-
margin-top: 7px;
|
|
204
|
-
color: rgba(55, 65, 81, 0.78);
|
|
205
|
-
font-size: 12px;
|
|
206
|
-
line-height: 1.25;
|
|
207
|
-
}
|
|
208
|
-
body.dark .pinokio-draft-meta {
|
|
209
|
-
color: rgba(212, 212, 216, 0.78);
|
|
210
|
-
}
|
|
211
|
-
.pinokio-draft-close {
|
|
212
|
-
flex: 0 0 auto;
|
|
213
|
-
width: 28px;
|
|
214
|
-
height: 28px;
|
|
215
|
-
border: 0;
|
|
216
|
-
border-radius: 6px;
|
|
217
|
-
background: transparent;
|
|
218
|
-
color: rgba(55, 65, 81, 0.74);
|
|
219
|
-
cursor: pointer;
|
|
220
|
-
font-size: 16px;
|
|
221
|
-
line-height: 1;
|
|
222
|
-
}
|
|
223
|
-
body.dark .pinokio-draft-close {
|
|
224
|
-
color: rgba(212, 212, 216, 0.78);
|
|
225
|
-
}
|
|
226
|
-
.pinokio-draft-close:hover,
|
|
227
|
-
.pinokio-draft-close:focus {
|
|
228
|
-
background: rgba(15, 23, 42, 0.06);
|
|
229
|
-
color: #111827;
|
|
230
|
-
}
|
|
231
|
-
body.dark .pinokio-draft-close:hover,
|
|
232
|
-
body.dark .pinokio-draft-close:focus {
|
|
233
|
-
background: rgba(255, 255, 255, 0.08);
|
|
234
|
-
color: #ffffff;
|
|
235
|
-
}
|
|
236
|
-
.pinokio-draft-preview {
|
|
237
|
-
border-top: 1px solid rgba(15, 23, 42, 0.1);
|
|
238
|
-
padding: 10px 12px 0;
|
|
239
|
-
color: rgba(31, 41, 55, 0.9);
|
|
240
|
-
font-size: 12px;
|
|
241
|
-
line-height: 1.45;
|
|
242
|
-
}
|
|
243
|
-
body.dark .pinokio-draft-preview {
|
|
244
|
-
border-top-color: rgba(255, 255, 255, 0.12);
|
|
245
|
-
color: rgba(244, 244, 245, 0.9);
|
|
246
|
-
}
|
|
247
|
-
.pinokio-draft-path {
|
|
248
|
-
margin-top: 8px;
|
|
249
|
-
color: rgba(75, 85, 99, 0.82);
|
|
250
|
-
font-family: "SFMono-Regular", Consolas, monospace;
|
|
251
|
-
font-size: 11px;
|
|
252
|
-
line-height: 1.35;
|
|
253
|
-
overflow-wrap: anywhere;
|
|
254
|
-
}
|
|
255
|
-
body.dark .pinokio-draft-path {
|
|
256
|
-
color: rgba(161, 161, 170, 0.86);
|
|
257
|
-
}
|
|
258
|
-
.pinokio-draft-actions {
|
|
259
|
-
display: flex;
|
|
260
|
-
align-items: center;
|
|
261
|
-
gap: 8px;
|
|
262
|
-
padding: 10px 12px 12px;
|
|
263
|
-
}
|
|
264
|
-
.pinokio-draft-button {
|
|
265
|
-
display: inline-flex;
|
|
266
|
-
align-items: center;
|
|
267
|
-
justify-content: center;
|
|
268
|
-
gap: 6px;
|
|
269
|
-
min-height: 30px;
|
|
270
|
-
border: 1px solid var(--pinokio-chrome-accent-bg-light);
|
|
271
|
-
border-radius: 6px;
|
|
272
|
-
background: var(--pinokio-chrome-accent-bg-light);
|
|
273
|
-
color: var(--pinokio-chrome-accent-fg-light);
|
|
274
|
-
cursor: pointer;
|
|
275
|
-
font-size: 12px;
|
|
276
|
-
font-weight: 700;
|
|
277
|
-
line-height: 1.1;
|
|
278
|
-
padding: 7px 10px;
|
|
279
|
-
white-space: nowrap;
|
|
280
|
-
}
|
|
281
|
-
.pinokio-draft-button:hover,
|
|
282
|
-
.pinokio-draft-button:focus {
|
|
283
|
-
border-color: color-mix(in srgb, var(--pinokio-chrome-accent-bg-light) 88%, #ffffff);
|
|
284
|
-
background: color-mix(in srgb, var(--pinokio-chrome-accent-bg-light) 88%, #ffffff);
|
|
285
|
-
}
|
|
286
|
-
body.dark .pinokio-draft-button {
|
|
287
|
-
border-color: #fbbf24;
|
|
288
|
-
background: #fbbf24;
|
|
289
|
-
color: var(--universal-launcher-surface-solid, #0a0a0b);
|
|
290
|
-
}
|
|
291
|
-
body.dark .pinokio-draft-button:hover,
|
|
292
|
-
body.dark .pinokio-draft-button:focus {
|
|
293
|
-
border-color: color-mix(in srgb, #fbbf24 90%, #ffffff);
|
|
294
|
-
background: color-mix(in srgb, #fbbf24 90%, #ffffff);
|
|
295
|
-
color: var(--universal-launcher-surface-solid, #0a0a0b);
|
|
296
|
-
}
|
|
297
|
-
.pinokio-draft-button.secondary {
|
|
298
|
-
border-color: rgba(15, 23, 42, 0.14);
|
|
299
|
-
color: #374151;
|
|
300
|
-
background: rgba(255, 255, 255, 0.72);
|
|
301
|
-
}
|
|
302
|
-
.pinokio-draft-button.secondary:hover,
|
|
303
|
-
.pinokio-draft-button.secondary:focus {
|
|
304
|
-
border-color: rgba(15, 23, 42, 0.24);
|
|
305
|
-
background: rgba(15, 23, 42, 0.04);
|
|
306
|
-
}
|
|
307
|
-
body.dark .pinokio-draft-button.secondary {
|
|
308
|
-
border-color: rgba(148, 163, 184, 0.28);
|
|
309
|
-
color: #dbeafe;
|
|
310
|
-
background: transparent;
|
|
311
|
-
}
|
|
312
|
-
body.dark .pinokio-draft-button.secondary:hover,
|
|
313
|
-
body.dark .pinokio-draft-button.secondary:focus {
|
|
314
|
-
border-color: rgba(148, 163, 184, 0.38);
|
|
315
|
-
background: rgba(255, 255, 255, 0.06);
|
|
316
|
-
}
|
|
317
|
-
.pinokio-draft-drawer .pinokio-draft-button.secondary {
|
|
318
|
-
border-color: rgba(15, 23, 42, 0.18);
|
|
319
|
-
color: #1f2937;
|
|
320
|
-
background: #ffffff;
|
|
321
|
-
}
|
|
322
|
-
.pinokio-draft-drawer .pinokio-draft-button.secondary:hover,
|
|
323
|
-
.pinokio-draft-drawer .pinokio-draft-button.secondary:focus {
|
|
324
|
-
border-color: rgba(15, 23, 42, 0.28);
|
|
325
|
-
background: rgba(15, 23, 42, 0.05);
|
|
326
|
-
}
|
|
327
|
-
body.dark .pinokio-draft-drawer .pinokio-draft-button.secondary {
|
|
328
|
-
border-color: rgba(148, 163, 184, 0.28);
|
|
329
|
-
color: #dbeafe;
|
|
330
|
-
background: transparent;
|
|
331
|
-
}
|
|
332
|
-
body.dark .pinokio-draft-drawer .pinokio-draft-button.secondary:hover,
|
|
333
|
-
body.dark .pinokio-draft-drawer .pinokio-draft-button.secondary:focus {
|
|
334
|
-
border-color: rgba(148, 163, 184, 0.38);
|
|
335
|
-
background: rgba(255, 255, 255, 0.06);
|
|
336
|
-
}
|
|
337
|
-
.pinokio-draft-button:disabled {
|
|
338
|
-
cursor: default;
|
|
339
|
-
opacity: 0.68;
|
|
340
|
-
}
|
|
341
|
-
.pinokio-draft-more {
|
|
342
|
-
align-self: flex-end;
|
|
343
|
-
border-radius: 999px;
|
|
344
|
-
background: rgba(255, 255, 255, 0.92);
|
|
345
|
-
border: 1px solid rgba(15, 23, 42, 0.14);
|
|
346
|
-
color: rgba(55, 65, 81, 0.82);
|
|
347
|
-
font-size: 12px;
|
|
348
|
-
line-height: 1.2;
|
|
349
|
-
padding: 6px 10px;
|
|
350
|
-
pointer-events: auto;
|
|
351
|
-
}
|
|
352
|
-
body.dark .pinokio-draft-more {
|
|
353
|
-
background: rgba(23, 23, 25, 0.96);
|
|
354
|
-
border-color: rgba(255, 255, 255, 0.16);
|
|
355
|
-
color: rgba(212, 212, 216, 0.82);
|
|
356
|
-
}
|
|
357
|
-
.pinokio-draft-drawer-backdrop {
|
|
358
|
-
position: fixed;
|
|
359
|
-
inset: 0;
|
|
360
|
-
z-index: 2147483001;
|
|
361
|
-
background: rgba(15, 23, 42, 0.28);
|
|
362
|
-
display: flex;
|
|
363
|
-
justify-content: flex-end;
|
|
364
|
-
color: #111827;
|
|
365
|
-
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
|
|
366
|
-
}
|
|
367
|
-
.pinokio-draft-drawer {
|
|
368
|
-
width: min(920px, calc(100vw - 34px));
|
|
369
|
-
height: 100vh;
|
|
370
|
-
background: #fbfbfc;
|
|
371
|
-
border-left: 1px solid rgba(15, 23, 42, 0.12);
|
|
372
|
-
box-shadow: -24px 0 72px rgba(15, 23, 42, 0.24);
|
|
373
|
-
display: flex;
|
|
374
|
-
flex-direction: column;
|
|
375
|
-
}
|
|
376
|
-
body.dark .pinokio-draft-drawer {
|
|
377
|
-
background: #171719;
|
|
378
|
-
border-left-color: rgba(255, 255, 255, 0.1);
|
|
379
|
-
color: rgba(250, 250, 250, 0.96);
|
|
380
|
-
}
|
|
381
|
-
body.dark .pinokio-draft-drawer-backdrop {
|
|
382
|
-
background: rgba(0, 0, 0, 0.42);
|
|
383
|
-
}
|
|
384
|
-
.pinokio-draft-drawer-header {
|
|
385
|
-
display: flex;
|
|
386
|
-
align-items: flex-start;
|
|
387
|
-
gap: 16px;
|
|
388
|
-
padding: 22px 24px 18px;
|
|
389
|
-
border-bottom: 1px solid rgba(15, 23, 42, 0.1);
|
|
390
|
-
}
|
|
391
|
-
body.dark .pinokio-draft-drawer-header {
|
|
392
|
-
border-bottom-color: rgba(255, 255, 255, 0.1);
|
|
393
|
-
}
|
|
394
|
-
.pinokio-draft-drawer-title-block {
|
|
395
|
-
min-width: 0;
|
|
396
|
-
flex: 1 1 auto;
|
|
397
|
-
}
|
|
398
|
-
.pinokio-draft-drawer-kicker {
|
|
399
|
-
display: inline-flex;
|
|
400
|
-
align-items: center;
|
|
401
|
-
gap: 5px;
|
|
402
|
-
color: #a16207;
|
|
403
|
-
font-size: 11px;
|
|
404
|
-
font-weight: 800;
|
|
405
|
-
letter-spacing: 0;
|
|
406
|
-
text-transform: uppercase;
|
|
407
|
-
}
|
|
408
|
-
.pinokio-draft-drawer-kicker i {
|
|
409
|
-
font-size: 10px;
|
|
410
|
-
}
|
|
411
|
-
body.dark .pinokio-draft-drawer-kicker {
|
|
412
|
-
color: #fbbf24;
|
|
413
|
-
}
|
|
414
|
-
.pinokio-draft-drawer-title {
|
|
415
|
-
margin-top: 5px;
|
|
416
|
-
color: inherit;
|
|
417
|
-
font-size: 22px;
|
|
418
|
-
font-weight: 800;
|
|
419
|
-
line-height: 1.16;
|
|
420
|
-
overflow-wrap: anywhere;
|
|
421
|
-
}
|
|
422
|
-
.pinokio-draft-drawer-meta {
|
|
423
|
-
display: flex;
|
|
424
|
-
flex-wrap: wrap;
|
|
425
|
-
gap: 6px 10px;
|
|
426
|
-
margin-top: 9px;
|
|
427
|
-
color: rgba(55, 65, 81, 0.76);
|
|
428
|
-
font-size: 12px;
|
|
429
|
-
line-height: 1.3;
|
|
430
|
-
}
|
|
431
|
-
body.dark .pinokio-draft-drawer-meta {
|
|
432
|
-
color: rgba(212, 212, 216, 0.78);
|
|
433
|
-
}
|
|
434
|
-
.pinokio-draft-drawer-close {
|
|
435
|
-
width: 34px;
|
|
436
|
-
height: 34px;
|
|
437
|
-
border: 1px solid rgba(15, 23, 42, 0.12);
|
|
438
|
-
border-radius: 8px;
|
|
439
|
-
background: transparent;
|
|
440
|
-
color: inherit;
|
|
441
|
-
cursor: pointer;
|
|
442
|
-
font-size: 18px;
|
|
443
|
-
}
|
|
444
|
-
body.dark .pinokio-draft-drawer-close {
|
|
445
|
-
border-color: rgba(255, 255, 255, 0.12);
|
|
446
|
-
}
|
|
447
|
-
.pinokio-draft-drawer-close:hover,
|
|
448
|
-
.pinokio-draft-drawer-close:focus {
|
|
449
|
-
background: rgba(15, 23, 42, 0.06);
|
|
450
|
-
}
|
|
451
|
-
body.dark .pinokio-draft-drawer-close:hover,
|
|
452
|
-
body.dark .pinokio-draft-drawer-close:focus {
|
|
453
|
-
background: rgba(255, 255, 255, 0.08);
|
|
454
|
-
}
|
|
455
|
-
.pinokio-draft-drawer-toolbar {
|
|
456
|
-
display: flex;
|
|
457
|
-
align-items: center;
|
|
458
|
-
justify-content: space-between;
|
|
459
|
-
gap: 12px;
|
|
460
|
-
padding: 12px 24px;
|
|
461
|
-
border-bottom: 1px solid rgba(15, 23, 42, 0.1);
|
|
462
|
-
}
|
|
463
|
-
body.dark .pinokio-draft-drawer-toolbar {
|
|
464
|
-
border-bottom-color: rgba(255, 255, 255, 0.1);
|
|
465
|
-
}
|
|
466
|
-
.pinokio-draft-tabs {
|
|
467
|
-
display: inline-flex;
|
|
468
|
-
gap: 4px;
|
|
469
|
-
border: 1px solid rgba(15, 23, 42, 0.1);
|
|
470
|
-
border-radius: 8px;
|
|
471
|
-
padding: 3px;
|
|
472
|
-
background: rgba(15, 23, 42, 0.04);
|
|
473
|
-
}
|
|
474
|
-
body.dark .pinokio-draft-tabs {
|
|
475
|
-
background: rgba(255, 255, 255, 0.05);
|
|
476
|
-
border-color: rgba(255, 255, 255, 0.1);
|
|
477
|
-
}
|
|
478
|
-
.pinokio-draft-tab {
|
|
479
|
-
border: 0;
|
|
480
|
-
border-radius: 6px;
|
|
481
|
-
background: transparent;
|
|
482
|
-
color: rgba(55, 65, 81, 0.86);
|
|
483
|
-
cursor: pointer;
|
|
484
|
-
font-size: 12px;
|
|
485
|
-
font-weight: 800;
|
|
486
|
-
padding: 7px 10px;
|
|
487
|
-
}
|
|
488
|
-
.pinokio-draft-tab.is-active {
|
|
489
|
-
background: #ffffff;
|
|
490
|
-
color: #111827;
|
|
491
|
-
box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
|
|
492
|
-
}
|
|
493
|
-
body.dark .pinokio-draft-tab {
|
|
494
|
-
color: rgba(228, 228, 231, 0.78);
|
|
495
|
-
}
|
|
496
|
-
body.dark .pinokio-draft-tab.is-active {
|
|
497
|
-
background: rgba(255, 255, 255, 0.12);
|
|
498
|
-
color: #fafafa;
|
|
499
|
-
}
|
|
500
|
-
.pinokio-draft-drawer-actions {
|
|
501
|
-
display: flex;
|
|
502
|
-
flex-wrap: wrap;
|
|
503
|
-
justify-content: flex-end;
|
|
504
|
-
gap: 8px;
|
|
505
|
-
}
|
|
506
|
-
.pinokio-draft-drawer-body {
|
|
507
|
-
min-height: 0;
|
|
508
|
-
flex: 1 1 auto;
|
|
509
|
-
overflow: auto;
|
|
510
|
-
padding: 22px 24px 28px;
|
|
511
|
-
}
|
|
512
|
-
.pinokio-draft-markdown {
|
|
513
|
-
max-width: 760px;
|
|
514
|
-
color: #1f2937;
|
|
515
|
-
font-size: 15px;
|
|
516
|
-
line-height: 1.62;
|
|
517
|
-
}
|
|
518
|
-
body.dark .pinokio-draft-markdown {
|
|
519
|
-
color: rgba(244, 244, 245, 0.92);
|
|
520
|
-
}
|
|
521
|
-
.pinokio-draft-markdown h1,
|
|
522
|
-
.pinokio-draft-markdown h2,
|
|
523
|
-
.pinokio-draft-markdown h3 {
|
|
524
|
-
color: inherit;
|
|
525
|
-
line-height: 1.18;
|
|
526
|
-
letter-spacing: 0;
|
|
527
|
-
margin: 24px 0 10px;
|
|
528
|
-
}
|
|
529
|
-
.pinokio-draft-markdown h1 { font-size: 26px; }
|
|
530
|
-
.pinokio-draft-markdown h2 { font-size: 21px; }
|
|
531
|
-
.pinokio-draft-markdown h3 { font-size: 17px; }
|
|
532
|
-
.pinokio-draft-markdown p,
|
|
533
|
-
.pinokio-draft-markdown ul,
|
|
534
|
-
.pinokio-draft-markdown ol,
|
|
535
|
-
.pinokio-draft-markdown blockquote,
|
|
536
|
-
.pinokio-draft-markdown pre {
|
|
537
|
-
margin: 0 0 14px;
|
|
538
|
-
}
|
|
539
|
-
.pinokio-draft-markdown ul,
|
|
540
|
-
.pinokio-draft-markdown ol {
|
|
541
|
-
padding-left: 24px;
|
|
542
|
-
}
|
|
543
|
-
.pinokio-draft-markdown a {
|
|
544
|
-
color: #2563eb;
|
|
545
|
-
text-decoration: none;
|
|
546
|
-
}
|
|
547
|
-
.pinokio-draft-markdown a:hover {
|
|
548
|
-
text-decoration: underline;
|
|
549
|
-
}
|
|
550
|
-
body.dark .pinokio-draft-markdown a {
|
|
551
|
-
color: #93c5fd;
|
|
552
|
-
}
|
|
553
|
-
.pinokio-draft-markdown code {
|
|
554
|
-
border: 1px solid rgba(15, 23, 42, 0.1);
|
|
555
|
-
border-radius: 5px;
|
|
556
|
-
background: rgba(15, 23, 42, 0.05);
|
|
557
|
-
font-family: "SFMono-Regular", Consolas, monospace;
|
|
558
|
-
font-size: 0.9em;
|
|
559
|
-
padding: 1px 4px;
|
|
560
|
-
}
|
|
561
|
-
body.dark .pinokio-draft-markdown code {
|
|
562
|
-
border-color: rgba(255, 255, 255, 0.12);
|
|
563
|
-
background: rgba(255, 255, 255, 0.07);
|
|
564
|
-
}
|
|
565
|
-
.pinokio-draft-markdown pre {
|
|
566
|
-
overflow: auto;
|
|
567
|
-
border: 1px solid rgba(15, 23, 42, 0.1);
|
|
568
|
-
border-radius: 8px;
|
|
569
|
-
background: rgba(15, 23, 42, 0.05);
|
|
570
|
-
padding: 12px;
|
|
571
|
-
}
|
|
572
|
-
.pinokio-draft-markdown pre code {
|
|
573
|
-
border: 0;
|
|
574
|
-
background: transparent;
|
|
575
|
-
padding: 0;
|
|
576
|
-
}
|
|
577
|
-
.pinokio-draft-markdown blockquote {
|
|
578
|
-
border-left: 3px solid rgba(15, 23, 42, 0.2);
|
|
579
|
-
color: rgba(55, 65, 81, 0.84);
|
|
580
|
-
padding-left: 12px;
|
|
581
|
-
}
|
|
582
|
-
body.dark .pinokio-draft-markdown blockquote {
|
|
583
|
-
border-left-color: rgba(255, 255, 255, 0.24);
|
|
584
|
-
color: rgba(212, 212, 216, 0.84);
|
|
585
|
-
}
|
|
586
|
-
.pinokio-draft-markdown table {
|
|
587
|
-
border-collapse: collapse;
|
|
588
|
-
width: 100%;
|
|
589
|
-
margin: 0 0 16px;
|
|
590
|
-
font-size: 13px;
|
|
591
|
-
}
|
|
592
|
-
.pinokio-draft-markdown th,
|
|
593
|
-
.pinokio-draft-markdown td {
|
|
594
|
-
border: 1px solid rgba(15, 23, 42, 0.12);
|
|
595
|
-
padding: 8px 9px;
|
|
596
|
-
text-align: left;
|
|
597
|
-
vertical-align: top;
|
|
598
|
-
}
|
|
599
|
-
.pinokio-draft-markdown th {
|
|
600
|
-
background: rgba(15, 23, 42, 0.05);
|
|
601
|
-
font-weight: 800;
|
|
602
|
-
}
|
|
603
|
-
body.dark .pinokio-draft-markdown th,
|
|
604
|
-
body.dark .pinokio-draft-markdown td {
|
|
605
|
-
border-color: rgba(255, 255, 255, 0.12);
|
|
606
|
-
}
|
|
607
|
-
body.dark .pinokio-draft-markdown th {
|
|
608
|
-
background: rgba(255, 255, 255, 0.08);
|
|
609
|
-
}
|
|
610
|
-
.pinokio-draft-media-figure {
|
|
611
|
-
margin: 0 0 16px;
|
|
612
|
-
}
|
|
613
|
-
.pinokio-draft-media-figure img,
|
|
614
|
-
.pinokio-draft-media-figure video {
|
|
615
|
-
display: block;
|
|
616
|
-
max-width: 100%;
|
|
617
|
-
max-height: 520px;
|
|
618
|
-
border: 1px solid rgba(15, 23, 42, 0.1);
|
|
619
|
-
border-radius: 8px;
|
|
620
|
-
background: rgba(15, 23, 42, 0.04);
|
|
621
|
-
}
|
|
622
|
-
.pinokio-draft-media-figure audio {
|
|
623
|
-
width: min(520px, 100%);
|
|
624
|
-
}
|
|
625
|
-
body.dark .pinokio-draft-media-figure img,
|
|
626
|
-
body.dark .pinokio-draft-media-figure video {
|
|
627
|
-
border-color: rgba(255, 255, 255, 0.12);
|
|
628
|
-
background: rgba(255, 255, 255, 0.06);
|
|
629
|
-
}
|
|
630
|
-
.pinokio-draft-media-caption {
|
|
631
|
-
margin-top: 6px;
|
|
632
|
-
color: rgba(55, 65, 81, 0.72);
|
|
633
|
-
font-size: 12px;
|
|
634
|
-
}
|
|
635
|
-
body.dark .pinokio-draft-media-caption {
|
|
636
|
-
color: rgba(212, 212, 216, 0.72);
|
|
637
|
-
}
|
|
638
|
-
.pinokio-draft-raw {
|
|
639
|
-
box-sizing: border-box;
|
|
640
|
-
width: 100%;
|
|
641
|
-
min-height: calc(100vh - 210px);
|
|
642
|
-
margin: 0;
|
|
643
|
-
border: 1px solid rgba(15, 23, 42, 0.12);
|
|
644
|
-
border-radius: 8px;
|
|
645
|
-
background: #ffffff;
|
|
646
|
-
color: #111827;
|
|
647
|
-
overflow: auto;
|
|
648
|
-
padding: 14px;
|
|
649
|
-
white-space: pre-wrap;
|
|
650
|
-
word-break: break-word;
|
|
651
|
-
font-family: "SFMono-Regular", Consolas, monospace;
|
|
652
|
-
font-size: 13px;
|
|
653
|
-
line-height: 1.55;
|
|
654
|
-
}
|
|
655
|
-
body.dark .pinokio-draft-raw {
|
|
656
|
-
border-color: rgba(255, 255, 255, 0.12);
|
|
657
|
-
background: rgba(255, 255, 255, 0.04);
|
|
658
|
-
color: rgba(250, 250, 250, 0.92);
|
|
659
|
-
}
|
|
660
|
-
.pinokio-draft-media-list {
|
|
661
|
-
display: grid;
|
|
662
|
-
gap: 10px;
|
|
663
|
-
max-width: 760px;
|
|
664
|
-
}
|
|
665
|
-
.pinokio-draft-media-item {
|
|
666
|
-
display: flex;
|
|
667
|
-
align-items: center;
|
|
668
|
-
gap: 12px;
|
|
669
|
-
border: 1px solid rgba(15, 23, 42, 0.1);
|
|
670
|
-
border-radius: 8px;
|
|
671
|
-
background: rgba(255, 255, 255, 0.72);
|
|
672
|
-
padding: 11px 12px;
|
|
673
|
-
}
|
|
674
|
-
body.dark .pinokio-draft-media-item {
|
|
675
|
-
border-color: rgba(255, 255, 255, 0.1);
|
|
676
|
-
background: rgba(255, 255, 255, 0.05);
|
|
677
|
-
}
|
|
678
|
-
.pinokio-draft-media-item-icon {
|
|
679
|
-
display: grid;
|
|
680
|
-
place-items: center;
|
|
681
|
-
width: 32px;
|
|
682
|
-
height: 32px;
|
|
683
|
-
border-radius: 7px;
|
|
684
|
-
background: rgba(15, 23, 42, 0.06);
|
|
685
|
-
color: #0f766e;
|
|
686
|
-
}
|
|
687
|
-
body.dark .pinokio-draft-media-item-icon {
|
|
688
|
-
background: rgba(255, 255, 255, 0.08);
|
|
689
|
-
color: #5eead4;
|
|
690
|
-
}
|
|
691
|
-
.pinokio-draft-media-item-copy {
|
|
692
|
-
min-width: 0;
|
|
693
|
-
flex: 1 1 auto;
|
|
694
|
-
}
|
|
695
|
-
.pinokio-draft-media-item-title {
|
|
696
|
-
font-size: 13px;
|
|
697
|
-
font-weight: 800;
|
|
698
|
-
overflow-wrap: anywhere;
|
|
699
|
-
}
|
|
700
|
-
.pinokio-draft-media-item-meta {
|
|
701
|
-
margin-top: 3px;
|
|
702
|
-
color: rgba(55, 65, 81, 0.72);
|
|
703
|
-
font-size: 12px;
|
|
704
|
-
}
|
|
705
|
-
body.dark .pinokio-draft-media-item-meta {
|
|
706
|
-
color: rgba(212, 212, 216, 0.72);
|
|
707
|
-
}
|
|
708
|
-
@media (max-width: 520px) {
|
|
709
|
-
.pinokio-drafts {
|
|
710
|
-
right: 12px;
|
|
711
|
-
bottom: 12px;
|
|
712
|
-
}
|
|
713
|
-
.pinokio-draft-actions {
|
|
714
|
-
flex-wrap: wrap;
|
|
715
|
-
}
|
|
716
|
-
.pinokio-draft-drawer {
|
|
717
|
-
width: 100vw;
|
|
718
|
-
}
|
|
719
|
-
.pinokio-draft-drawer-header,
|
|
720
|
-
.pinokio-draft-drawer-toolbar,
|
|
721
|
-
.pinokio-draft-drawer-body {
|
|
722
|
-
padding-left: 16px;
|
|
723
|
-
padding-right: 16px;
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
`;
|
|
727
|
-
document.head.appendChild(style);
|
|
728
|
-
}
|
|
729
|
-
|
|
730
|
-
function getRoot() {
|
|
731
|
-
ensureStyles();
|
|
732
|
-
let root = document.getElementById("pinokio-drafts");
|
|
733
|
-
if (!root) {
|
|
734
|
-
root = document.createElement("div");
|
|
735
|
-
root.id = "pinokio-drafts";
|
|
736
|
-
root.className = "pinokio-drafts";
|
|
737
|
-
root.setAttribute("aria-live", "polite");
|
|
738
|
-
document.body.appendChild(root);
|
|
739
|
-
}
|
|
740
|
-
return root;
|
|
741
|
-
}
|
|
742
|
-
|
|
743
|
-
function removeRoot() {
|
|
744
|
-
const root = document.getElementById("pinokio-drafts");
|
|
745
|
-
if (root) {
|
|
746
|
-
root.remove();
|
|
747
|
-
}
|
|
748
|
-
}
|
|
749
|
-
|
|
750
|
-
function createElement(tag, className, text) {
|
|
751
|
-
const element = document.createElement(tag);
|
|
752
|
-
if (className) {
|
|
753
|
-
element.className = className;
|
|
754
|
-
}
|
|
755
|
-
if (text !== undefined && text !== null) {
|
|
756
|
-
element.textContent = text;
|
|
757
|
-
}
|
|
758
|
-
return element;
|
|
759
|
-
}
|
|
760
|
-
|
|
761
|
-
function createIcon(name) {
|
|
762
|
-
const icon = createElement("i", name);
|
|
763
|
-
icon.setAttribute("aria-hidden", "true");
|
|
764
|
-
return icon;
|
|
765
|
-
}
|
|
766
|
-
|
|
767
|
-
function createActionButton(className, label, iconName) {
|
|
768
|
-
const button = createElement("button", className);
|
|
769
|
-
if (iconName) {
|
|
770
|
-
button.appendChild(createIcon(iconName));
|
|
771
|
-
}
|
|
772
|
-
const text = createElement("span", "", label);
|
|
773
|
-
text.setAttribute("data-pinokio-draft-label", "true");
|
|
774
|
-
button.appendChild(text);
|
|
775
|
-
return button;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
function setActionButtonLabel(button, label) {
|
|
779
|
-
if (!button) {
|
|
780
|
-
return;
|
|
781
|
-
}
|
|
782
|
-
const text = button.querySelector("[data-pinokio-draft-label]");
|
|
783
|
-
if (text) {
|
|
784
|
-
text.textContent = label;
|
|
785
|
-
} else {
|
|
786
|
-
button.textContent = label;
|
|
787
|
-
}
|
|
788
|
-
}
|
|
789
|
-
|
|
790
|
-
function createDraftStatus(className) {
|
|
791
|
-
const status = createElement("div", className);
|
|
792
|
-
status.appendChild(createIcon("fa-solid fa-circle-check"));
|
|
793
|
-
status.appendChild(document.createTextNode("Draft ready"));
|
|
794
|
-
return status;
|
|
795
|
-
}
|
|
796
|
-
|
|
797
|
-
function canPublishToRegistry(item) {
|
|
798
|
-
const publish = item && item.publish && typeof item.publish === "object" ? item.publish : null;
|
|
799
|
-
const target = publish && typeof publish.target === "string" ? publish.target.trim().toLowerCase() : "";
|
|
800
|
-
const type = publish && typeof publish.type === "string" ? publish.type.trim().toLowerCase() : "post";
|
|
801
|
-
return target === "registry" && type === "post";
|
|
802
|
-
}
|
|
803
|
-
|
|
804
|
-
function formatBytes(bytes) {
|
|
805
|
-
const value = Number(bytes);
|
|
806
|
-
if (!Number.isFinite(value) || value < 0) {
|
|
807
|
-
return "";
|
|
808
|
-
}
|
|
809
|
-
if (value < 1024) {
|
|
810
|
-
return `${value} B`;
|
|
811
|
-
}
|
|
812
|
-
if (value < 1024 * 1024) {
|
|
813
|
-
return `${(value / 1024).toFixed(1)} KB`;
|
|
814
|
-
}
|
|
815
|
-
return `${(value / 1024 / 1024).toFixed(1)} MB`;
|
|
816
|
-
}
|
|
817
|
-
|
|
818
|
-
function formatUpdatedAt(value) {
|
|
819
|
-
const date = new Date(value);
|
|
820
|
-
if (!Number.isFinite(date.getTime())) {
|
|
821
|
-
return "";
|
|
822
|
-
}
|
|
823
|
-
return date.toLocaleString([], {
|
|
824
|
-
month: "short",
|
|
825
|
-
day: "numeric",
|
|
826
|
-
hour: "numeric",
|
|
827
|
-
minute: "2-digit"
|
|
828
|
-
});
|
|
829
|
-
}
|
|
830
|
-
|
|
831
|
-
function getItemById(id) {
|
|
832
|
-
return (Array.isArray(state.items) ? state.items : []).find((item) => item && item.id === id) || null;
|
|
833
|
-
}
|
|
834
|
-
|
|
835
|
-
function getDraftMetaParts(item) {
|
|
836
|
-
const parts = [];
|
|
837
|
-
const updatedAt = formatUpdatedAt(item && item.updatedAt);
|
|
838
|
-
const postSize = formatBytes(item && item.postBytes);
|
|
839
|
-
const mediaCount = Number(item && item.mediaCount || 0);
|
|
840
|
-
const missingMedia = Number(item && item.missingMediaCount || 0);
|
|
841
|
-
if (item && item.workspaceName) {
|
|
842
|
-
parts.push(item.workspaceName);
|
|
843
|
-
}
|
|
844
|
-
if (updatedAt) {
|
|
845
|
-
parts.push(updatedAt);
|
|
846
|
-
}
|
|
847
|
-
if (postSize) {
|
|
848
|
-
parts.push(postSize);
|
|
849
|
-
}
|
|
850
|
-
if (mediaCount > 0) {
|
|
851
|
-
parts.push(`${mediaCount} media ${mediaCount === 1 ? "file" : "files"}`);
|
|
852
|
-
}
|
|
853
|
-
if (missingMedia > 0) {
|
|
854
|
-
parts.push(`${missingMedia} missing`);
|
|
855
|
-
}
|
|
856
|
-
return parts;
|
|
857
|
-
}
|
|
858
|
-
|
|
859
|
-
function normalizeRef(value) {
|
|
860
|
-
const raw = String(value || "").trim().replace(/^<|>$/g, "").replace(/\\/g, "/");
|
|
861
|
-
if (!raw) {
|
|
862
|
-
return "";
|
|
863
|
-
}
|
|
864
|
-
const withoutHash = raw.split("#")[0];
|
|
865
|
-
return withoutHash.split("?")[0];
|
|
866
|
-
}
|
|
867
|
-
|
|
868
|
-
function getMediaItems(item) {
|
|
869
|
-
return Array.isArray(item && item.media) ? item.media : [];
|
|
870
|
-
}
|
|
871
|
-
|
|
872
|
-
function findMediaByRef(item, ref) {
|
|
873
|
-
const normalized = normalizeRef(ref);
|
|
874
|
-
if (!normalized) {
|
|
875
|
-
return null;
|
|
876
|
-
}
|
|
877
|
-
return getMediaItems(item).find((media) => normalizeRef(media && media.ref) === normalized) || null;
|
|
878
|
-
}
|
|
879
|
-
|
|
880
|
-
function getMediaUrl(item, media) {
|
|
881
|
-
return `/drafts/${encodeURIComponent(item.id)}/media/${encodeURIComponent(String(media.index))}`;
|
|
882
|
-
}
|
|
883
|
-
|
|
884
|
-
function mediaKind(media) {
|
|
885
|
-
const ext = String((media && media.ext) || "").toLowerCase();
|
|
886
|
-
if ([".apng", ".avif", ".gif", ".jpeg", ".jpg", ".png", ".svg", ".webp"].includes(ext)) {
|
|
887
|
-
return "image";
|
|
888
|
-
}
|
|
889
|
-
if ([".mp4", ".webm", ".ogg"].includes(ext)) {
|
|
890
|
-
return "video";
|
|
891
|
-
}
|
|
892
|
-
if ([".m4a", ".mp3", ".wav"].includes(ext)) {
|
|
893
|
-
return "audio";
|
|
894
|
-
}
|
|
895
|
-
return "file";
|
|
896
|
-
}
|
|
897
|
-
|
|
898
|
-
function isSafeExternalHref(value) {
|
|
899
|
-
return /^(https?:|mailto:)/i.test(String(value || "").trim());
|
|
900
|
-
}
|
|
901
|
-
|
|
902
|
-
function appendInline(parent, text, item) {
|
|
903
|
-
const source = String(text || "");
|
|
904
|
-
const pattern = /(`[^`]+`|\*\*[^*]+\*\*|\[[^\]]+]\([^)]+\))/g;
|
|
905
|
-
let cursor = 0;
|
|
906
|
-
let match = null;
|
|
907
|
-
while ((match = pattern.exec(source))) {
|
|
908
|
-
if (match.index > cursor) {
|
|
909
|
-
parent.appendChild(document.createTextNode(source.slice(cursor, match.index)));
|
|
910
|
-
}
|
|
911
|
-
const token = match[0];
|
|
912
|
-
if (token.startsWith("`") && token.endsWith("`")) {
|
|
913
|
-
parent.appendChild(createElement("code", "", token.slice(1, -1)));
|
|
914
|
-
} else if (token.startsWith("**") && token.endsWith("**")) {
|
|
915
|
-
const strong = createElement("strong");
|
|
916
|
-
appendInline(strong, token.slice(2, -2), item);
|
|
917
|
-
parent.appendChild(strong);
|
|
918
|
-
} else {
|
|
919
|
-
const linkMatch = token.match(/^\[([^\]]+)]\(([^)]+)\)$/);
|
|
920
|
-
const label = linkMatch ? linkMatch[1] : token;
|
|
921
|
-
const href = linkMatch ? String(linkMatch[2] || "").trim() : "";
|
|
922
|
-
const media = findMediaByRef(item, href);
|
|
923
|
-
const safeHref = media && media.exists
|
|
924
|
-
? getMediaUrl(item, media)
|
|
925
|
-
: (isSafeExternalHref(href) ? href : "");
|
|
926
|
-
if (safeHref) {
|
|
927
|
-
const link = createElement("a");
|
|
928
|
-
link.href = safeHref;
|
|
929
|
-
if (isSafeExternalHref(safeHref)) {
|
|
930
|
-
link.target = "_blank";
|
|
931
|
-
link.rel = "noreferrer";
|
|
932
|
-
}
|
|
933
|
-
link.textContent = label;
|
|
934
|
-
parent.appendChild(link);
|
|
935
|
-
} else {
|
|
936
|
-
parent.appendChild(document.createTextNode(label));
|
|
937
|
-
}
|
|
938
|
-
}
|
|
939
|
-
cursor = pattern.lastIndex;
|
|
940
|
-
}
|
|
941
|
-
if (cursor < source.length) {
|
|
942
|
-
parent.appendChild(document.createTextNode(source.slice(cursor)));
|
|
943
|
-
}
|
|
944
|
-
}
|
|
945
|
-
|
|
946
|
-
function createMissingMedia(ref) {
|
|
947
|
-
const figure = createElement("figure", "pinokio-draft-media-figure");
|
|
948
|
-
const missing = createElement("div", "pinokio-draft-media-item");
|
|
949
|
-
const icon = createElement("div", "pinokio-draft-media-item-icon");
|
|
950
|
-
icon.appendChild(createIcon("fa-solid fa-triangle-exclamation"));
|
|
951
|
-
const copy = createElement("div", "pinokio-draft-media-item-copy");
|
|
952
|
-
copy.appendChild(createElement("div", "pinokio-draft-media-item-title", ref || "Missing media"));
|
|
953
|
-
copy.appendChild(createElement("div", "pinokio-draft-media-item-meta", "Referenced file was not found in the draft folder."));
|
|
954
|
-
missing.appendChild(icon);
|
|
955
|
-
missing.appendChild(copy);
|
|
956
|
-
figure.appendChild(missing);
|
|
957
|
-
return figure;
|
|
958
|
-
}
|
|
959
|
-
|
|
960
|
-
function createMediaFigure(item, ref, altText) {
|
|
961
|
-
const media = findMediaByRef(item, ref);
|
|
962
|
-
if (!media || !media.exists) {
|
|
963
|
-
return createMissingMedia(ref);
|
|
964
|
-
}
|
|
965
|
-
const figure = createElement("figure", "pinokio-draft-media-figure");
|
|
966
|
-
const kind = mediaKind(media);
|
|
967
|
-
const url = getMediaUrl(item, media);
|
|
968
|
-
let element = null;
|
|
969
|
-
if (kind === "image") {
|
|
970
|
-
element = document.createElement("img");
|
|
971
|
-
element.alt = altText || media.ref || "";
|
|
972
|
-
element.loading = "lazy";
|
|
973
|
-
} else if (kind === "video") {
|
|
974
|
-
element = document.createElement("video");
|
|
975
|
-
element.controls = true;
|
|
976
|
-
element.preload = "metadata";
|
|
977
|
-
} else if (kind === "audio") {
|
|
978
|
-
element = document.createElement("audio");
|
|
979
|
-
element.controls = true;
|
|
980
|
-
element.preload = "metadata";
|
|
981
|
-
}
|
|
982
|
-
if (!element) {
|
|
983
|
-
const link = createElement("a", "", media.ref || "Open media");
|
|
984
|
-
link.href = url;
|
|
985
|
-
figure.appendChild(link);
|
|
986
|
-
} else {
|
|
987
|
-
element.src = url;
|
|
988
|
-
figure.appendChild(element);
|
|
989
|
-
}
|
|
990
|
-
const captionBits = [media.ref || ""];
|
|
991
|
-
const size = formatBytes(media.bytes);
|
|
992
|
-
if (size) {
|
|
993
|
-
captionBits.push(size);
|
|
994
|
-
}
|
|
995
|
-
figure.appendChild(createElement("figcaption", "pinokio-draft-media-caption", captionBits.filter(Boolean).join(" / ")));
|
|
996
|
-
return figure;
|
|
997
|
-
}
|
|
998
|
-
|
|
999
|
-
function splitTableRow(line) {
|
|
1000
|
-
let value = String(line || "").trim();
|
|
1001
|
-
if (value.startsWith("|")) {
|
|
1002
|
-
value = value.slice(1);
|
|
1003
|
-
}
|
|
1004
|
-
if (value.endsWith("|")) {
|
|
1005
|
-
value = value.slice(0, -1);
|
|
1006
|
-
}
|
|
1007
|
-
return value.split("|").map((cell) => cell.trim());
|
|
1008
|
-
}
|
|
1009
|
-
|
|
1010
|
-
function isMarkdownTableSeparator(line) {
|
|
1011
|
-
const cells = splitTableRow(line);
|
|
1012
|
-
return cells.length > 1 && cells.every((cell) => /^:?-{3,}:?$/.test(cell));
|
|
1013
|
-
}
|
|
1014
|
-
|
|
1015
|
-
function renderMarkdownTable(root, item, headerLine, rowLines) {
|
|
1016
|
-
const table = createElement("table");
|
|
1017
|
-
const thead = createElement("thead");
|
|
1018
|
-
const headerRow = createElement("tr");
|
|
1019
|
-
splitTableRow(headerLine).forEach((cell) => {
|
|
1020
|
-
const th = createElement("th");
|
|
1021
|
-
appendInline(th, cell, item);
|
|
1022
|
-
headerRow.appendChild(th);
|
|
1023
|
-
});
|
|
1024
|
-
thead.appendChild(headerRow);
|
|
1025
|
-
table.appendChild(thead);
|
|
1026
|
-
const tbody = createElement("tbody");
|
|
1027
|
-
rowLines.forEach((line) => {
|
|
1028
|
-
const row = createElement("tr");
|
|
1029
|
-
splitTableRow(line).forEach((cell) => {
|
|
1030
|
-
const td = createElement("td");
|
|
1031
|
-
appendInline(td, cell, item);
|
|
1032
|
-
row.appendChild(td);
|
|
1033
|
-
});
|
|
1034
|
-
tbody.appendChild(row);
|
|
1035
|
-
});
|
|
1036
|
-
table.appendChild(tbody);
|
|
1037
|
-
root.appendChild(table);
|
|
1038
|
-
}
|
|
1039
|
-
|
|
1040
|
-
function renderMarkdownPreview(container, item) {
|
|
1041
|
-
const markdown = String((item && item.markdown) || "");
|
|
1042
|
-
const lines = markdown.split(/\r?\n/);
|
|
1043
|
-
const root = createElement("div", "pinokio-draft-markdown");
|
|
1044
|
-
let paragraph = [];
|
|
1045
|
-
let list = null;
|
|
1046
|
-
let code = null;
|
|
1047
|
-
|
|
1048
|
-
const flushParagraph = () => {
|
|
1049
|
-
if (!paragraph.length) {
|
|
1050
|
-
return;
|
|
1051
|
-
}
|
|
1052
|
-
const p = createElement("p");
|
|
1053
|
-
appendInline(p, paragraph.join(" "), item);
|
|
1054
|
-
root.appendChild(p);
|
|
1055
|
-
paragraph = [];
|
|
1056
|
-
};
|
|
1057
|
-
const flushList = () => {
|
|
1058
|
-
if (list) {
|
|
1059
|
-
root.appendChild(list);
|
|
1060
|
-
list = null;
|
|
1061
|
-
}
|
|
1062
|
-
};
|
|
1063
|
-
const flushCode = () => {
|
|
1064
|
-
if (!code) {
|
|
1065
|
-
return;
|
|
1066
|
-
}
|
|
1067
|
-
const pre = createElement("pre");
|
|
1068
|
-
const codeEl = createElement("code", "", code.join("\n"));
|
|
1069
|
-
pre.appendChild(codeEl);
|
|
1070
|
-
root.appendChild(pre);
|
|
1071
|
-
code = null;
|
|
1072
|
-
};
|
|
1073
|
-
|
|
1074
|
-
for (let lineIndex = 0; lineIndex < lines.length; lineIndex += 1) {
|
|
1075
|
-
const line = lines[lineIndex];
|
|
1076
|
-
const fenceMatch = line.match(/^```/);
|
|
1077
|
-
if (fenceMatch) {
|
|
1078
|
-
if (code) {
|
|
1079
|
-
flushCode();
|
|
1080
|
-
} else {
|
|
1081
|
-
flushParagraph();
|
|
1082
|
-
flushList();
|
|
1083
|
-
code = [];
|
|
1084
|
-
}
|
|
1085
|
-
continue;
|
|
1086
|
-
}
|
|
1087
|
-
if (code) {
|
|
1088
|
-
code.push(line);
|
|
1089
|
-
continue;
|
|
1090
|
-
}
|
|
1091
|
-
if (!line.trim()) {
|
|
1092
|
-
flushParagraph();
|
|
1093
|
-
flushList();
|
|
1094
|
-
continue;
|
|
1095
|
-
}
|
|
1096
|
-
if (line.trim().startsWith("|") && isMarkdownTableSeparator(lines[lineIndex + 1])) {
|
|
1097
|
-
flushParagraph();
|
|
1098
|
-
flushList();
|
|
1099
|
-
const rowLines = [];
|
|
1100
|
-
lineIndex += 1;
|
|
1101
|
-
while (lineIndex + 1 < lines.length && lines[lineIndex + 1].trim().startsWith("|")) {
|
|
1102
|
-
lineIndex += 1;
|
|
1103
|
-
rowLines.push(lines[lineIndex]);
|
|
1104
|
-
}
|
|
1105
|
-
renderMarkdownTable(root, item, line, rowLines);
|
|
1106
|
-
continue;
|
|
1107
|
-
}
|
|
1108
|
-
const imageMatch = line.trim().match(/^!\[([^\]]*)]\(([^)\s]+)(?:\s+["'][^"']*["'])?\)$/);
|
|
1109
|
-
if (imageMatch) {
|
|
1110
|
-
flushParagraph();
|
|
1111
|
-
flushList();
|
|
1112
|
-
root.appendChild(createMediaFigure(item, imageMatch[2], imageMatch[1]));
|
|
1113
|
-
continue;
|
|
1114
|
-
}
|
|
1115
|
-
const heading = line.match(/^(#{1,3})\s+(.+?)\s*#*\s*$/);
|
|
1116
|
-
if (heading) {
|
|
1117
|
-
flushParagraph();
|
|
1118
|
-
flushList();
|
|
1119
|
-
const h = createElement(`h${heading[1].length}`);
|
|
1120
|
-
appendInline(h, heading[2], item);
|
|
1121
|
-
root.appendChild(h);
|
|
1122
|
-
continue;
|
|
1123
|
-
}
|
|
1124
|
-
const quote = line.match(/^>\s?(.*)$/);
|
|
1125
|
-
if (quote) {
|
|
1126
|
-
flushParagraph();
|
|
1127
|
-
flushList();
|
|
1128
|
-
const blockquote = createElement("blockquote");
|
|
1129
|
-
appendInline(blockquote, quote[1], item);
|
|
1130
|
-
root.appendChild(blockquote);
|
|
1131
|
-
continue;
|
|
1132
|
-
}
|
|
1133
|
-
const unordered = line.match(/^\s*[-*]\s+(.+)$/);
|
|
1134
|
-
const ordered = line.match(/^\s*\d+[.)]\s+(.+)$/);
|
|
1135
|
-
if (unordered || ordered) {
|
|
1136
|
-
flushParagraph();
|
|
1137
|
-
const tag = ordered ? "ol" : "ul";
|
|
1138
|
-
if (!list || list.tagName.toLowerCase() !== tag) {
|
|
1139
|
-
flushList();
|
|
1140
|
-
list = createElement(tag);
|
|
1141
|
-
}
|
|
1142
|
-
const li = createElement("li");
|
|
1143
|
-
appendInline(li, (unordered || ordered)[1], item);
|
|
1144
|
-
list.appendChild(li);
|
|
1145
|
-
continue;
|
|
1146
|
-
}
|
|
1147
|
-
paragraph.push(line.trim());
|
|
1148
|
-
}
|
|
1149
|
-
flushCode();
|
|
1150
|
-
flushParagraph();
|
|
1151
|
-
flushList();
|
|
1152
|
-
if (!root.childNodes.length) {
|
|
1153
|
-
root.appendChild(createElement("p", "", "No preview available."));
|
|
1154
|
-
}
|
|
1155
|
-
container.appendChild(root);
|
|
1156
|
-
}
|
|
1157
|
-
|
|
1158
|
-
function renderRawMarkdown(container, item) {
|
|
1159
|
-
container.appendChild(createElement("pre", "pinokio-draft-raw", String((item && item.markdown) || "")));
|
|
1160
|
-
}
|
|
1161
|
-
|
|
1162
|
-
function renderMediaList(container, item) {
|
|
1163
|
-
const mediaItems = getMediaItems(item);
|
|
1164
|
-
const list = createElement("div", "pinokio-draft-media-list");
|
|
1165
|
-
if (!mediaItems.length) {
|
|
1166
|
-
list.appendChild(createElement("div", "pinokio-draft-media-item", "No media files referenced from this draft."));
|
|
1167
|
-
container.appendChild(list);
|
|
1168
|
-
return;
|
|
1169
|
-
}
|
|
1170
|
-
mediaItems.forEach((media) => {
|
|
1171
|
-
const row = createElement("div", "pinokio-draft-media-item");
|
|
1172
|
-
const icon = createElement("div", "pinokio-draft-media-item-icon");
|
|
1173
|
-
const kind = mediaKind(media);
|
|
1174
|
-
icon.appendChild(createIcon(kind === "video"
|
|
1175
|
-
? "fa-solid fa-video"
|
|
1176
|
-
: (kind === "audio" ? "fa-solid fa-volume-high" : (kind === "image" ? "fa-solid fa-image" : "fa-solid fa-file"))));
|
|
1177
|
-
const copy = createElement("div", "pinokio-draft-media-item-copy");
|
|
1178
|
-
copy.appendChild(createElement("div", "pinokio-draft-media-item-title", media.ref || "Media"));
|
|
1179
|
-
const size = formatBytes(media.bytes);
|
|
1180
|
-
copy.appendChild(createElement("div", "pinokio-draft-media-item-meta", [media.exists ? "Ready" : "Missing", size].filter(Boolean).join(" / ")));
|
|
1181
|
-
row.appendChild(icon);
|
|
1182
|
-
row.appendChild(copy);
|
|
1183
|
-
if (media.exists) {
|
|
1184
|
-
const link = createActionButton("pinokio-draft-button secondary", "Open", "fa-solid fa-up-right-from-square");
|
|
1185
|
-
link.type = "button";
|
|
1186
|
-
link.addEventListener("click", () => {
|
|
1187
|
-
window.open(getMediaUrl(item, media), "_blank");
|
|
1188
|
-
});
|
|
1189
|
-
row.appendChild(link);
|
|
1190
|
-
}
|
|
1191
|
-
list.appendChild(row);
|
|
1192
|
-
});
|
|
1193
|
-
container.appendChild(list);
|
|
1194
|
-
}
|
|
1195
|
-
|
|
1196
|
-
function getApiUrl() {
|
|
1197
|
-
const url = new URL("/drafts", window.location.origin);
|
|
1198
|
-
if (activeCwd) {
|
|
1199
|
-
url.searchParams.set("cwd", activeCwd);
|
|
1200
|
-
}
|
|
1201
|
-
return url.toString();
|
|
1202
|
-
}
|
|
1203
|
-
|
|
1204
|
-
async function dismissItem(item) {
|
|
1205
|
-
const id = item && typeof item === "object" ? item.id : item;
|
|
1206
|
-
const revision = item && typeof item === "object" ? item.revision : "";
|
|
1207
|
-
if (!id) {
|
|
1208
|
-
return;
|
|
1209
|
-
}
|
|
1210
|
-
state.items = state.items.filter((item) => item.id !== id);
|
|
1211
|
-
state.expanded.delete(id);
|
|
1212
|
-
render();
|
|
1213
|
-
await fetch(`/drafts/${encodeURIComponent(id)}/dismiss`, {
|
|
1214
|
-
method: "POST",
|
|
1215
|
-
headers: {
|
|
1216
|
-
"Content-Type": "application/json"
|
|
1217
|
-
},
|
|
1218
|
-
body: JSON.stringify({
|
|
1219
|
-
revision: revision || ""
|
|
1220
|
-
})
|
|
1221
|
-
}).catch(() => {});
|
|
1222
|
-
}
|
|
1223
|
-
|
|
1224
|
-
async function openDraft(item, button) {
|
|
1225
|
-
if (!item || !item.postPath) {
|
|
1226
|
-
return;
|
|
1227
|
-
}
|
|
1228
|
-
const originalTextNode = button ? button.querySelector("[data-pinokio-draft-label]") : null;
|
|
1229
|
-
const originalText = originalTextNode ? originalTextNode.textContent : (button ? button.textContent : "");
|
|
1230
|
-
if (button) {
|
|
1231
|
-
button.disabled = true;
|
|
1232
|
-
setActionButtonLabel(button, "Opening...");
|
|
1233
|
-
}
|
|
1234
|
-
try {
|
|
1235
|
-
await fetch("/openfs", {
|
|
1236
|
-
method: "POST",
|
|
1237
|
-
headers: {
|
|
1238
|
-
"Content-Type": "application/json"
|
|
1239
|
-
},
|
|
1240
|
-
body: JSON.stringify({
|
|
1241
|
-
path: item.postPath
|
|
1242
|
-
})
|
|
1243
|
-
});
|
|
1244
|
-
} finally {
|
|
1245
|
-
if (button) {
|
|
1246
|
-
button.disabled = false;
|
|
1247
|
-
setActionButtonLabel(button, originalText || "File explorer");
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
|
|
1252
|
-
function closeDraftDrawer() {
|
|
1253
|
-
state.drawerItemId = "";
|
|
1254
|
-
const existing = document.getElementById("pinokio-draft-drawer-root");
|
|
1255
|
-
if (existing) {
|
|
1256
|
-
existing.remove();
|
|
1257
|
-
}
|
|
1258
|
-
}
|
|
1259
|
-
|
|
1260
|
-
function openDraftDrawer(item, tab) {
|
|
1261
|
-
if (!item || !item.id) {
|
|
1262
|
-
return;
|
|
1263
|
-
}
|
|
1264
|
-
state.drawerItemId = item.id;
|
|
1265
|
-
state.drawerTab = tab || "preview";
|
|
1266
|
-
renderDrawer();
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
function createDrawerTab(label, tab) {
|
|
1270
|
-
const button = createElement("button", `pinokio-draft-tab${state.drawerTab === tab ? " is-active" : ""}`, label);
|
|
1271
|
-
button.type = "button";
|
|
1272
|
-
button.setAttribute("aria-selected", state.drawerTab === tab ? "true" : "false");
|
|
1273
|
-
button.addEventListener("click", () => {
|
|
1274
|
-
state.drawerTab = tab;
|
|
1275
|
-
renderDrawer();
|
|
1276
|
-
});
|
|
1277
|
-
return button;
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
function renderDrawer() {
|
|
1281
|
-
const previous = document.getElementById("pinokio-draft-drawer-root");
|
|
1282
|
-
if (previous) {
|
|
1283
|
-
previous.remove();
|
|
1284
|
-
}
|
|
1285
|
-
const item = getItemById(state.drawerItemId);
|
|
1286
|
-
if (!item) {
|
|
1287
|
-
state.drawerItemId = "";
|
|
1288
|
-
return;
|
|
1289
|
-
}
|
|
1290
|
-
|
|
1291
|
-
const backdrop = createElement("div", "pinokio-draft-drawer-backdrop");
|
|
1292
|
-
backdrop.id = "pinokio-draft-drawer-root";
|
|
1293
|
-
backdrop.addEventListener("click", (event) => {
|
|
1294
|
-
if (event.target === backdrop) {
|
|
1295
|
-
closeDraftDrawer();
|
|
1296
|
-
}
|
|
1297
|
-
});
|
|
1298
|
-
|
|
1299
|
-
const drawer = createElement("section", "pinokio-draft-drawer");
|
|
1300
|
-
drawer.setAttribute("role", "dialog");
|
|
1301
|
-
drawer.setAttribute("aria-modal", "true");
|
|
1302
|
-
drawer.setAttribute("aria-label", "Draft preview");
|
|
1303
|
-
|
|
1304
|
-
const header = createElement("div", "pinokio-draft-drawer-header");
|
|
1305
|
-
const titleBlock = createElement("div", "pinokio-draft-drawer-title-block");
|
|
1306
|
-
titleBlock.appendChild(createDraftStatus("pinokio-draft-drawer-kicker"));
|
|
1307
|
-
titleBlock.appendChild(createElement("div", "pinokio-draft-drawer-title", item.title || "Draft"));
|
|
1308
|
-
titleBlock.appendChild(createElement("div", "pinokio-draft-drawer-meta", getDraftMetaParts(item).join(" / ")));
|
|
1309
|
-
const close = createElement("button", "pinokio-draft-drawer-close", "x");
|
|
1310
|
-
close.type = "button";
|
|
1311
|
-
close.setAttribute("aria-label", "Close draft preview");
|
|
1312
|
-
close.addEventListener("click", closeDraftDrawer);
|
|
1313
|
-
header.appendChild(titleBlock);
|
|
1314
|
-
header.appendChild(close);
|
|
1315
|
-
|
|
1316
|
-
const toolbar = createElement("div", "pinokio-draft-drawer-toolbar");
|
|
1317
|
-
const tabs = createElement("div", "pinokio-draft-tabs");
|
|
1318
|
-
tabs.setAttribute("role", "tablist");
|
|
1319
|
-
tabs.appendChild(createDrawerTab("Preview", "preview"));
|
|
1320
|
-
tabs.appendChild(createDrawerTab("Markdown", "markdown"));
|
|
1321
|
-
tabs.appendChild(createDrawerTab("Media", "media"));
|
|
1322
|
-
const actions = createElement("div", "pinokio-draft-drawer-actions");
|
|
1323
|
-
const openButton = createActionButton("pinokio-draft-button secondary", "File explorer", "fa-solid fa-folder-open");
|
|
1324
|
-
openButton.type = "button";
|
|
1325
|
-
openButton.addEventListener("click", () => {
|
|
1326
|
-
void openDraft(item, openButton);
|
|
1327
|
-
});
|
|
1328
|
-
actions.appendChild(openButton);
|
|
1329
|
-
if (canPublishToRegistry(item)) {
|
|
1330
|
-
const publishButton = createActionButton("pinokio-draft-button", "Publish", "fa-solid fa-arrow-up-from-bracket");
|
|
1331
|
-
publishButton.type = "button";
|
|
1332
|
-
publishButton.addEventListener("click", () => {
|
|
1333
|
-
void openRegistryDraftImport(item);
|
|
1334
|
-
});
|
|
1335
|
-
actions.appendChild(publishButton);
|
|
1336
|
-
}
|
|
1337
|
-
toolbar.appendChild(tabs);
|
|
1338
|
-
toolbar.appendChild(actions);
|
|
1339
|
-
|
|
1340
|
-
const body = createElement("div", "pinokio-draft-drawer-body");
|
|
1341
|
-
if (state.drawerTab === "markdown") {
|
|
1342
|
-
renderRawMarkdown(body, item);
|
|
1343
|
-
} else if (state.drawerTab === "media") {
|
|
1344
|
-
renderMediaList(body, item);
|
|
1345
|
-
} else {
|
|
1346
|
-
renderMarkdownPreview(body, item);
|
|
1347
|
-
}
|
|
1348
|
-
|
|
1349
|
-
drawer.appendChild(header);
|
|
1350
|
-
drawer.appendChild(toolbar);
|
|
1351
|
-
drawer.appendChild(body);
|
|
1352
|
-
backdrop.appendChild(drawer);
|
|
1353
|
-
document.body.appendChild(backdrop);
|
|
1354
|
-
}
|
|
1355
|
-
|
|
1356
|
-
async function openRegistryDraftImport(item) {
|
|
1357
|
-
if (!item || !item.id || !canPublishToRegistry(item)) {
|
|
1358
|
-
return;
|
|
1359
|
-
}
|
|
1360
|
-
try {
|
|
1361
|
-
const url = new URL("/registry/draft-import/authorize-url", window.location.origin);
|
|
1362
|
-
url.searchParams.set("draft", item.id);
|
|
1363
|
-
url.searchParams.set("_", String(Date.now()));
|
|
1364
|
-
const response = await fetch(url.toString(), {
|
|
1365
|
-
headers: {
|
|
1366
|
-
Accept: "application/json"
|
|
1367
|
-
}
|
|
1368
|
-
});
|
|
1369
|
-
const data = await response.json().catch(() => null);
|
|
1370
|
-
if (!response.ok || !data || !data.authorizeUrl) {
|
|
1371
|
-
throw new Error((data && data.error) || "Unable to start registry import.");
|
|
1372
|
-
}
|
|
1373
|
-
const openResponse = await fetch("/pinokio/open", {
|
|
1374
|
-
method: "POST",
|
|
1375
|
-
headers: {
|
|
1376
|
-
"Content-Type": "application/json"
|
|
1377
|
-
},
|
|
1378
|
-
body: JSON.stringify({
|
|
1379
|
-
url: data.authorizeUrl,
|
|
1380
|
-
surface: "browser"
|
|
1381
|
-
})
|
|
1382
|
-
});
|
|
1383
|
-
if (!openResponse.ok) {
|
|
1384
|
-
throw new Error("Unable to open registry.");
|
|
1385
|
-
}
|
|
1386
|
-
} catch (error) {
|
|
1387
|
-
window.alert(error && error.message ? error.message : "Unable to start registry import.");
|
|
1388
|
-
}
|
|
1389
|
-
}
|
|
1390
|
-
|
|
1391
|
-
function renderItem(item) {
|
|
1392
|
-
const card = createElement("div", "pinokio-draft-card");
|
|
1393
|
-
card.tabIndex = 0;
|
|
1394
|
-
card.setAttribute("role", "button");
|
|
1395
|
-
card.setAttribute("aria-label", `Open draft preview for ${item.title || "Draft"}`);
|
|
1396
|
-
card.addEventListener("click", () => {
|
|
1397
|
-
openDraftDrawer(item, "preview");
|
|
1398
|
-
});
|
|
1399
|
-
card.addEventListener("keydown", (event) => {
|
|
1400
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
1401
|
-
event.preventDefault();
|
|
1402
|
-
openDraftDrawer(item, "preview");
|
|
1403
|
-
}
|
|
1404
|
-
});
|
|
1405
|
-
|
|
1406
|
-
const head = createElement("div", "pinokio-draft-head");
|
|
1407
|
-
const iconWrap = createElement("div", "pinokio-draft-icon");
|
|
1408
|
-
iconWrap.appendChild(createIcon("fa-solid fa-file-lines"));
|
|
1409
|
-
|
|
1410
|
-
const copy = createElement("div", "pinokio-draft-copy");
|
|
1411
|
-
copy.appendChild(createDraftStatus("pinokio-draft-kicker"));
|
|
1412
|
-
copy.appendChild(createElement("div", "pinokio-draft-title", item.title || "Draft"));
|
|
1413
|
-
|
|
1414
|
-
const meta = createElement("div", "pinokio-draft-meta");
|
|
1415
|
-
meta.textContent = getDraftMetaParts(item).join(" / ");
|
|
1416
|
-
copy.appendChild(meta);
|
|
1417
|
-
|
|
1418
|
-
const close = createElement("button", "pinokio-draft-close", "x");
|
|
1419
|
-
close.type = "button";
|
|
1420
|
-
close.title = "Dismiss";
|
|
1421
|
-
close.setAttribute("aria-label", "Dismiss draft");
|
|
1422
|
-
close.addEventListener("click", (event) => {
|
|
1423
|
-
event.stopPropagation();
|
|
1424
|
-
void dismissItem(item);
|
|
1425
|
-
});
|
|
1426
|
-
close.addEventListener("keydown", (event) => {
|
|
1427
|
-
event.stopPropagation();
|
|
1428
|
-
});
|
|
1429
|
-
|
|
1430
|
-
head.appendChild(iconWrap);
|
|
1431
|
-
head.appendChild(copy);
|
|
1432
|
-
head.appendChild(close);
|
|
1433
|
-
card.appendChild(head);
|
|
1434
|
-
|
|
1435
|
-
return card;
|
|
1436
|
-
}
|
|
1437
|
-
|
|
1438
|
-
function render() {
|
|
1439
|
-
const items = Array.isArray(state.items) ? state.items : [];
|
|
1440
|
-
if (items.length === 0) {
|
|
1441
|
-
removeRoot();
|
|
1442
|
-
closeDraftDrawer();
|
|
1443
|
-
state.lastSignature = "";
|
|
1444
|
-
return;
|
|
1445
|
-
}
|
|
1446
|
-
const root = getRoot();
|
|
1447
|
-
root.innerHTML = "";
|
|
1448
|
-
items.slice(0, 3).forEach((item) => {
|
|
1449
|
-
root.appendChild(renderItem(item));
|
|
1450
|
-
});
|
|
1451
|
-
if (items.length > 3) {
|
|
1452
|
-
root.appendChild(createElement("div", "pinokio-draft-more", `${items.length - 3} more drafts`));
|
|
1453
|
-
}
|
|
1454
|
-
if (state.drawerItemId) {
|
|
1455
|
-
renderDrawer();
|
|
1456
|
-
}
|
|
1457
|
-
}
|
|
1458
|
-
|
|
1459
|
-
async function refresh() {
|
|
1460
|
-
try {
|
|
1461
|
-
const response = await fetch(getApiUrl(), {
|
|
1462
|
-
headers: {
|
|
1463
|
-
Accept: "application/json"
|
|
1464
|
-
}
|
|
1465
|
-
});
|
|
1466
|
-
if (!response.ok) {
|
|
1467
|
-
return;
|
|
1468
|
-
}
|
|
1469
|
-
const payload = await response.json();
|
|
1470
|
-
const items = payload && Array.isArray(payload.items) ? payload.items : [];
|
|
1471
|
-
const signature = items.map((item) => `${item.id}:${item.revision || item.updatedAt}`).join("|");
|
|
1472
|
-
if (signature === state.lastSignature) {
|
|
1473
|
-
state.initialRefreshComplete = true;
|
|
1474
|
-
return;
|
|
1475
|
-
}
|
|
1476
|
-
const previousIds = new Set((Array.isArray(state.items) ? state.items : []).map((item) => item && item.id).filter(Boolean));
|
|
1477
|
-
const newItems = state.initialRefreshComplete
|
|
1478
|
-
? items.filter((item) => item && item.id && !previousIds.has(item.id))
|
|
1479
|
-
: [];
|
|
1480
|
-
state.lastSignature = signature;
|
|
1481
|
-
state.items = items;
|
|
1482
|
-
render();
|
|
1483
|
-
newItems.forEach(notifyDraftReady);
|
|
1484
|
-
state.initialRefreshComplete = true;
|
|
1485
|
-
} catch (_) {
|
|
1486
|
-
}
|
|
1487
|
-
}
|
|
1488
|
-
|
|
1489
|
-
function start() {
|
|
1490
|
-
if (!document.body) {
|
|
1491
|
-
window.addEventListener("DOMContentLoaded", start, { once: true });
|
|
1492
|
-
return;
|
|
1493
|
-
}
|
|
1494
|
-
void refresh();
|
|
1495
|
-
window.setInterval(refresh, 5000);
|
|
1496
|
-
document.addEventListener("visibilitychange", () => {
|
|
1497
|
-
if (!document.hidden) {
|
|
1498
|
-
void refresh();
|
|
1499
|
-
}
|
|
1500
|
-
});
|
|
1501
|
-
}
|
|
1502
|
-
|
|
1503
|
-
start();
|
|
1504
|
-
})();
|