@pirateandfox/pagestack 0.1.0-beta.7 → 0.1.0-beta.8
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 +39 -12
- package/index.mjs +18 -6
- package/package.json +1 -1
- package/src/client/auth.ts +5 -5
- package/src/client/collection.ts +6 -6
- package/src/client/editor.ts +105 -105
- package/src/client/form.ts +26 -26
- package/src/client/global.ts +4 -4
- package/src/client/inline.ts +4 -4
- package/src/client/inserter.ts +11 -11
- package/src/client/invite.ts +4 -4
- package/src/client/item.ts +202 -54
- package/src/client/live.ts +92 -0
- package/src/client/media.ts +12 -12
- package/src/client/pages.ts +14 -14
- package/src/client/picker.ts +30 -30
- package/src/client/preview.css +58 -58
- package/src/client/rich.ts +14 -14
- package/src/client/shell.css +281 -272
- package/src/client/state.ts +2 -2
- package/src/client/tomarkdown.ts +4 -2
- package/src/client/tree.ts +11 -11
- package/src/client/ui.ts +13 -13
- package/src/client/users.ts +6 -6
- package/src/core/auth.ts +1 -1
- package/src/core/markdown.ts +54 -5
- package/src/core/pages.ts +6 -2
- package/src/core/storage-github.ts +51 -5
- package/src/core/storage.ts +14 -0
- package/src/routes/Nav.astro +5 -3
- package/src/routes/api/collection.ts +30 -8
- package/src/routes/api/live.ts +27 -0
- package/src/routes/edit-collection.astro +14 -14
- package/src/routes/edit-global.astro +8 -8
- package/src/routes/edit-index.astro +18 -18
- package/src/routes/edit-item.astro +25 -23
- package/src/routes/edit-media.astro +9 -9
- package/src/routes/edit-page.astro +32 -30
- package/src/routes/edit-users.astro +9 -9
- package/src/routes/enroll.astro +6 -6
- package/src/routes/login.astro +6 -6
- package/src/routes/preview-item.astro +1 -1
- package/src/routes/preview.astro +1 -1
- package/src/runtime.ts +3 -3
- package/src/server/context.ts +3 -3
- package/src/server/middleware.ts +19 -4
package/src/client/form.ts
CHANGED
|
@@ -23,33 +23,33 @@ const el = <K extends keyof HTMLElementTagNameMap>(tag: K, attrs: Record<string,
|
|
|
23
23
|
export function renderForm(root: HTMLElement, schema: BlockSchema, settings: Record<string, unknown>, cb: FormCallbacks) {
|
|
24
24
|
root.innerHTML = '';
|
|
25
25
|
const groups = formModel(schema, settings);
|
|
26
|
-
if (!groups.length) { root.append(el('p', { class: '
|
|
26
|
+
if (!groups.length) { root.append(el('p', { class: 'ps-muted' }, 'This block has no settings.')); return; }
|
|
27
27
|
for (const g of groups) {
|
|
28
|
-
const body = el('div', { class: '
|
|
28
|
+
const body = el('div', { class: 'ps-fields' });
|
|
29
29
|
for (const f of g.fields) body.append(fieldWidget(f.name, f.field, f.value, cb));
|
|
30
|
-
const details = el('details', { class: '
|
|
30
|
+
const details = el('details', { class: 'ps-group', open: g.name !== 'advanced' }, el('summary', {}, g.label), body) as HTMLDetailsElement;
|
|
31
31
|
root.append(details);
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
function fieldWidget(name: string, field: Field, value: unknown, cb: FormCallbacks, idPrefix = '
|
|
35
|
+
function fieldWidget(name: string, field: Field, value: unknown, cb: FormCallbacks, idPrefix = 'ps-f-'): HTMLElement {
|
|
36
36
|
const id = `${idPrefix}${name}`;
|
|
37
37
|
const label = el('label', { for: id }, field.label);
|
|
38
|
-
const wrap = el('div', { class: `
|
|
39
|
-
const help = field.help ? el('small', { class: '
|
|
38
|
+
const wrap = el('div', { class: `ps-field ps-field--${field.type}` }, label);
|
|
39
|
+
const help = field.help ? el('small', { class: 'ps-muted' }, field.help) : null;
|
|
40
40
|
// `cancel` matters: a live update landing after `change` would reorder the edit and split its undo step.
|
|
41
41
|
const debounce = (fn: () => void, ms = 250) => { let t: ReturnType<typeof setTimeout>; const run = () => { clearTimeout(t); t = setTimeout(fn, ms); }; run.cancel = () => clearTimeout(t); return run; };
|
|
42
42
|
|
|
43
43
|
switch (field.type) {
|
|
44
44
|
case 'text':
|
|
45
45
|
case 'link': {
|
|
46
|
-
const input = el('input', { id, type: 'text', value: (value as string) ?? '', list: field.type === 'link' && cb.pageUrls?.length ? '
|
|
46
|
+
const input = el('input', { id, type: 'text', value: (value as string) ?? '', list: field.type === 'link' && cb.pageUrls?.length ? 'ps-page-urls' : undefined, placeholder: field.type === 'link' ? 'https://… or /page/' : '' }) as HTMLInputElement;
|
|
47
47
|
const live = debounce(() => cb.onChange(name, input.value, { live: true }));
|
|
48
48
|
input.addEventListener('input', live);
|
|
49
49
|
input.addEventListener('change', () => { live.cancel(); cb.onChange(name, input.value); });
|
|
50
50
|
wrap.append(input);
|
|
51
|
-
if (field.type === 'link' && cb.pageUrls?.length && !document.getElementById('
|
|
52
|
-
document.body.append(el('datalist', { id: '
|
|
51
|
+
if (field.type === 'link' && cb.pageUrls?.length && !document.getElementById('ps-page-urls')) {
|
|
52
|
+
document.body.append(el('datalist', { id: 'ps-page-urls' }, ...cb.pageUrls.map((p) => el('option', { value: p.url }, p.title))));
|
|
53
53
|
}
|
|
54
54
|
break;
|
|
55
55
|
}
|
|
@@ -74,7 +74,7 @@ function fieldWidget(name: string, field: Field, value: unknown, cb: FormCallbac
|
|
|
74
74
|
break;
|
|
75
75
|
case 'textarea':
|
|
76
76
|
case 'code': {
|
|
77
|
-
const ta = el('textarea', { id, rows: field.type === 'code' ? 10 : 5, class: field.type === 'code' ? '
|
|
77
|
+
const ta = el('textarea', { id, rows: field.type === 'code' ? 10 : 5, class: field.type === 'code' ? 'ps-mono' : '', spellcheck: 'false' }) as HTMLTextAreaElement;
|
|
78
78
|
ta.value = (value as string) ?? '';
|
|
79
79
|
ta.addEventListener('change', () => cb.onChange(name, ta.value));
|
|
80
80
|
wrap.append(ta);
|
|
@@ -90,7 +90,7 @@ function fieldWidget(name: string, field: Field, value: unknown, cb: FormCallbac
|
|
|
90
90
|
const input = el('input', { id, type: 'checkbox' }) as HTMLInputElement;
|
|
91
91
|
input.checked = !!value;
|
|
92
92
|
input.addEventListener('change', () => cb.onChange(name, input.checked));
|
|
93
|
-
wrap.className += '
|
|
93
|
+
wrap.className += ' ps-field--inline';
|
|
94
94
|
wrap.innerHTML = ''; wrap.append(input, label);
|
|
95
95
|
break;
|
|
96
96
|
}
|
|
@@ -112,14 +112,14 @@ function fieldWidget(name: string, field: Field, value: unknown, cb: FormCallbac
|
|
|
112
112
|
const live = debounce(() => { sync(); cb.onChange(name, text.value, { live: true }); });
|
|
113
113
|
text.addEventListener('input', live);
|
|
114
114
|
text.addEventListener('change', () => { live.cancel(); sync(); cb.onChange(name, text.value); });
|
|
115
|
-
const clear = el('button', { type: 'button', class: '
|
|
116
|
-
wrap.append(el('div', { class: '
|
|
115
|
+
const clear = el('button', { type: 'button', class: 'ps-btn ps-btn--small ps-btn--ghost', title: 'Clear (use theme CSS)', onclick: () => { text.value = ''; sync(); cb.onChange(name, ''); } }, '×');
|
|
116
|
+
wrap.append(el('div', { class: 'ps-row' }, swatch, text, clear));
|
|
117
117
|
break;
|
|
118
118
|
}
|
|
119
119
|
case 'image': {
|
|
120
120
|
// `asUrl` fields hold a bare URL (social images, menu pictures); the widget is the same.
|
|
121
121
|
// It redraws itself: not every caller re-renders the form after a change.
|
|
122
|
-
const box = el('div', { class: '
|
|
122
|
+
const box = el('div', { class: 'ps-field__image' });
|
|
123
123
|
const sibling = () => { if (!field.asUrl || !field.altField) return null; let top: HTMLElement = box; while (top.parentElement) top = top.parentElement; return top.querySelector<HTMLInputElement>(`#${CSS.escape(idPrefix + field.altField)}`); };
|
|
124
124
|
const draw = (img: ImageValue) => {
|
|
125
125
|
const put = (v: ImageValue) => {
|
|
@@ -132,7 +132,7 @@ function fieldWidget(name: string, field: Field, value: unknown, cb: FormCallbac
|
|
|
132
132
|
}
|
|
133
133
|
draw(v);
|
|
134
134
|
};
|
|
135
|
-
const thumb = el('div', { class: '
|
|
135
|
+
const thumb = el('div', { class: 'ps-thumb' }, img.src ? el('img', { src: img.src, alt: '' }) : el('span', { class: 'ps-muted' }, 'No image'));
|
|
136
136
|
const alt = el('input', { type: 'text', value: img.alt ?? '', placeholder: 'Alt text (describe the image)', 'aria-label': 'Alt text' }) as HTMLInputElement;
|
|
137
137
|
alt.addEventListener('change', () => { img = { ...img, alt: alt.value }; cb.onChange(name, img); });
|
|
138
138
|
const current = (): ImageValue | undefined => {
|
|
@@ -140,10 +140,10 @@ function fieldWidget(name: string, field: Field, value: unknown, cb: FormCallbac
|
|
|
140
140
|
const sib = sibling();
|
|
141
141
|
return sib ? { ...img, alt: sib.value } : img;
|
|
142
142
|
};
|
|
143
|
-
const choose = el('button', { type: 'button', class: '
|
|
144
|
-
const clear = el('button', { type: 'button', class: '
|
|
145
|
-
box.replaceChildren(thumb, el('div', { class: '
|
|
146
|
-
if (img.src) box.append(...(field.asUrl ? [] : [alt]), el('small', { class: '
|
|
143
|
+
const choose = el('button', { type: 'button', class: 'ps-btn ps-btn--small', onclick: () => cb.pickImage(current(), put) }, img.src ? 'Replace…' : 'Choose…');
|
|
144
|
+
const clear = el('button', { type: 'button', class: 'ps-btn ps-btn--small ps-btn--ghost', onclick: () => put({ src: '', alt: '' }) }, 'Remove');
|
|
145
|
+
box.replaceChildren(thumb, el('div', { class: 'ps-row' }, choose, img.src ? clear : null));
|
|
146
|
+
if (img.src) box.append(...(field.asUrl ? [] : [alt]), el('small', { class: 'ps-muted ps-ellipsis', title: img.src }, img.src));
|
|
147
147
|
};
|
|
148
148
|
draw(field.asUrl ? { src: (value as string) ?? '', alt: '' } : ((value as ImageValue) ?? { src: '', alt: '' }));
|
|
149
149
|
wrap.append(box);
|
|
@@ -156,7 +156,7 @@ function fieldWidget(name: string, field: Field, value: unknown, cb: FormCallbac
|
|
|
156
156
|
sel.append(el('option', { value: '' }, 'None'));
|
|
157
157
|
for (const n of names) sel.append(el('option', { value: n, selected: value === n }, n));
|
|
158
158
|
sel.append(el('option', { value: '__custom', selected: !!value && !isNamed }, 'Custom SVG…'));
|
|
159
|
-
const ta = el('textarea', { rows: 4, class: '
|
|
159
|
+
const ta = el('textarea', { rows: 4, class: 'ps-mono', hidden: isNamed || !value, placeholder: '<svg …>…</svg>' }) as HTMLTextAreaElement;
|
|
160
160
|
ta.value = !isNamed && typeof value === 'string' ? value : '';
|
|
161
161
|
sel.addEventListener('change', () => { if (sel.value === '__custom') { ta.hidden = false; ta.focus(); } else { ta.hidden = true; cb.onChange(name, sel.value); } });
|
|
162
162
|
ta.addEventListener('change', () => cb.onChange(name, ta.value));
|
|
@@ -176,7 +176,7 @@ function listWidget(name: string, field: Field, value: unknown, cb: FormCallback
|
|
|
176
176
|
const fields = field.fields ?? {};
|
|
177
177
|
let rows: Record<string, any>[] = Array.isArray(value) ? structuredClone(value) : [];
|
|
178
178
|
const open = new Set<number>();
|
|
179
|
-
const root = el('div', { class: '
|
|
179
|
+
const root = el('div', { class: 'ps-list', id });
|
|
180
180
|
const rowName = (row: Record<string, any>, i: number) => (field.itemLabel && row[field.itemLabel]) || `Item ${i + 1}`;
|
|
181
181
|
const save = (live = false) => cb.onChange(name, structuredClone(rows), { live });
|
|
182
182
|
const move = (from: number, to: number) => {
|
|
@@ -189,8 +189,8 @@ function listWidget(name: string, field: Field, value: unknown, cb: FormCallback
|
|
|
189
189
|
const draw = () => {
|
|
190
190
|
root.innerHTML = '';
|
|
191
191
|
rows.forEach((row, i) => {
|
|
192
|
-
const title = el('span', { class: '
|
|
193
|
-
const body = el('div', { class: '
|
|
192
|
+
const title = el('span', { class: 'ps-ellipsis' }, rowName(row, i));
|
|
193
|
+
const body = el('div', { class: 'ps-fields' });
|
|
194
194
|
for (const [k, sub] of Object.entries(fields)) {
|
|
195
195
|
const rowCb: FormCallbacks = { ...cb, onChange: (key, v, o) => {
|
|
196
196
|
if (v === undefined || v === '' || (Array.isArray(v) && !v.length)) delete row[key]; else row[key] = v;
|
|
@@ -200,15 +200,15 @@ function listWidget(name: string, field: Field, value: unknown, cb: FormCallback
|
|
|
200
200
|
body.append(fieldWidget(k, sub, row[k] ?? sub.default, rowCb, `${id}-${i}-`));
|
|
201
201
|
}
|
|
202
202
|
const remove = el('button', { type: 'button', title: 'Remove', 'aria-label': `Remove ${rowName(row, i)}`, onclick: (e: Event) => { e.preventDefault(); rows.splice(i, 1); open.clear(); save(); draw(); } }, '×');
|
|
203
|
-
const details = el('details', { class: '
|
|
203
|
+
const details = el('details', { class: 'ps-list__row', open: open.has(i), ontoggle: () => { if (details.open) open.add(i); else open.delete(i); } }, el('summary', {},
|
|
204
204
|
title,
|
|
205
|
-
el('span', { class: '
|
|
205
|
+
el('span', { class: 'ps-list__tools' },
|
|
206
206
|
el('button', { type: 'button', title: 'Move up', 'aria-label': 'Move up', disabled: i === 0, onclick: (e: Event) => { e.preventDefault(); move(i, i - 1); } }, '↑'),
|
|
207
207
|
el('button', { type: 'button', title: 'Move down', 'aria-label': 'Move down', disabled: i === rows.length - 1, onclick: (e: Event) => { e.preventDefault(); move(i, i + 1); } }, '↓'),
|
|
208
208
|
remove)), body) as HTMLDetailsElement;
|
|
209
209
|
root.append(details);
|
|
210
210
|
});
|
|
211
|
-
root.append(el('button', { type: 'button', class: '
|
|
211
|
+
root.append(el('button', { type: 'button', class: 'ps-btn ps-btn--small', onclick: () => {
|
|
212
212
|
rows.push({});
|
|
213
213
|
open.add(rows.length - 1);
|
|
214
214
|
save(); draw();
|
package/src/client/global.ts
CHANGED
|
@@ -5,9 +5,9 @@ import { pickImage } from './picker';
|
|
|
5
5
|
import { toast } from './ui';
|
|
6
6
|
|
|
7
7
|
interface Boot { id: string; label: string; fields: Record<string, Field>; pages: { title: string; url: string }[] }
|
|
8
|
-
const boot = (window as any).
|
|
9
|
-
const root = document.getElementById('
|
|
10
|
-
const saveBtn = document.getElementById('
|
|
8
|
+
const boot = (window as any).__PS_GLOBAL__ as Boot;
|
|
9
|
+
const root = document.getElementById('ps-global-form')!;
|
|
10
|
+
const saveBtn = document.getElementById('ps-global-save') as HTMLButtonElement;
|
|
11
11
|
const url = `/api/editor/global/${boot.id}`;
|
|
12
12
|
let doc: Record<string, unknown> = {};
|
|
13
13
|
let hash: string | null = null;
|
|
@@ -28,6 +28,6 @@ saveBtn.addEventListener('click', async () => {
|
|
|
28
28
|
const d = await r.json();
|
|
29
29
|
if (!r.ok) { toast(d.error || 'Save failed', 'error'); saveBtn.disabled = false; return; }
|
|
30
30
|
hash = d.hash; dirty = false;
|
|
31
|
-
toast(d.result.kind === 'github' ? 'Saved. The site will rebuild.' : "Saved to the working tree. Commit it with git when you're happy.", 'ok');
|
|
31
|
+
toast(d.result.kind === 'github' ? (document.getElementById('ps-live') ? 'Saved. Use Go live to put it on the site.' : 'Saved. The site will rebuild.') : "Saved to the working tree. Commit it with git when you're happy.", 'ok');
|
|
32
32
|
});
|
|
33
33
|
window.addEventListener('beforeunload', (e) => { if (dirty) e.preventDefault(); });
|
package/src/client/inline.ts
CHANGED
|
@@ -24,13 +24,13 @@ export class InlineEditor {
|
|
|
24
24
|
start(el: HTMLElement) {
|
|
25
25
|
if (this.active?.el === el) return;
|
|
26
26
|
this.stop();
|
|
27
|
-
const path = el.dataset.
|
|
28
|
-
const type = el.dataset.
|
|
27
|
+
const path = el.dataset.psField!;
|
|
28
|
+
const type = el.dataset.psFieldType!;
|
|
29
29
|
if (type !== 'text' && type !== 'richtext') return;
|
|
30
30
|
const original = el.innerHTML;
|
|
31
31
|
this.active = { el, path, type, original };
|
|
32
32
|
el.setAttribute('contenteditable', type === 'text' ? 'plaintext-only' : 'true');
|
|
33
|
-
el.setAttribute('data-
|
|
33
|
+
el.setAttribute('data-ps-editing', '');
|
|
34
34
|
el.addEventListener('input', this.onInput);
|
|
35
35
|
el.addEventListener('keydown', this.onKey);
|
|
36
36
|
el.addEventListener('blur', this.onBlur);
|
|
@@ -53,7 +53,7 @@ export class InlineEditor {
|
|
|
53
53
|
a.el.removeEventListener('blur', this.onBlur);
|
|
54
54
|
a.el.removeEventListener('paste', this.onPaste);
|
|
55
55
|
a.el.removeAttribute('contenteditable');
|
|
56
|
-
a.el.removeAttribute('data-
|
|
56
|
+
a.el.removeAttribute('data-ps-editing');
|
|
57
57
|
a.el.ownerDocument.defaultView?.removeEventListener('scroll', this.place);
|
|
58
58
|
a.toolbar?.remove();
|
|
59
59
|
const value = this.read(a.el, a.type);
|
package/src/client/inserter.ts
CHANGED
|
@@ -14,36 +14,36 @@ export interface InserterOptions {
|
|
|
14
14
|
}
|
|
15
15
|
|
|
16
16
|
export function renderInserter(root: HTMLElement, o: InserterOptions) {
|
|
17
|
-
root.innerHTML = `<div class="
|
|
18
|
-
<div class="
|
|
19
|
-
<p class="
|
|
17
|
+
root.innerHTML = `<div class="ps-panel__head"><span>Add block</span><button type="button" class="ps-iconbtn" aria-label="Close">${icons.close}</button></div>
|
|
18
|
+
<div class="ps-inserter__search"><input type="search" placeholder="Search blocks and patterns" aria-label="Search blocks and patterns" /></div>
|
|
19
|
+
<p class="ps-inserter__where ps-muted"></p><div class="ps-inserter__results"></div>`;
|
|
20
20
|
const input = root.querySelector<HTMLInputElement>('input')!;
|
|
21
|
-
const results = root.querySelector<HTMLElement>('.
|
|
22
|
-
root.querySelector('.
|
|
21
|
+
const results = root.querySelector<HTMLElement>('.ps-inserter__results')!;
|
|
22
|
+
root.querySelector('.ps-inserter__where')!.textContent = o.where();
|
|
23
23
|
root.querySelector('button')!.addEventListener('click', o.onClose);
|
|
24
24
|
|
|
25
25
|
const draw = () => {
|
|
26
26
|
const found = searchItems(o.items(), input.value);
|
|
27
27
|
results.innerHTML = '';
|
|
28
|
-
if (!found.length) { const p = document.createElement('p'); p.className = '
|
|
28
|
+
if (!found.length) { const p = document.createElement('p'); p.className = 'ps-muted ps-inserter__none'; p.textContent = 'No blocks found.'; results.append(p); return; }
|
|
29
29
|
for (const g of groupItems(found)) {
|
|
30
30
|
const h = document.createElement('h3'); h.textContent = g.category;
|
|
31
|
-
const grid = document.createElement('div'); grid.className = '
|
|
31
|
+
const grid = document.createElement('div'); grid.className = 'ps-inserter__grid';
|
|
32
32
|
for (const item of g.items) grid.append(tile(item));
|
|
33
33
|
results.append(h, grid);
|
|
34
34
|
}
|
|
35
35
|
};
|
|
36
36
|
const tile = (item: InsertItem) => {
|
|
37
|
-
const wrap = document.createElement('div'); wrap.className = '
|
|
37
|
+
const wrap = document.createElement('div'); wrap.className = 'ps-tile';
|
|
38
38
|
const b = document.createElement('button');
|
|
39
|
-
b.type = 'button'; b.className = '
|
|
39
|
+
b.type = 'button'; b.className = 'ps-tile__main'; if (item.description) b.title = item.description;
|
|
40
40
|
b.innerHTML = item.type ? icons.block : icons.pattern;
|
|
41
41
|
const name = document.createElement('span'); name.textContent = item.label; b.append(name);
|
|
42
42
|
b.addEventListener('click', () => o.onPick(item));
|
|
43
43
|
wrap.append(b);
|
|
44
44
|
if (item.savedId) {
|
|
45
45
|
const x = document.createElement('button');
|
|
46
|
-
x.type = 'button'; x.className = '
|
|
46
|
+
x.type = 'button'; x.className = 'ps-tile__delete'; x.setAttribute('aria-label', `Delete ${item.label}`); x.innerHTML = icons.close;
|
|
47
47
|
x.addEventListener('click', () => o.onDeleteSaved(item));
|
|
48
48
|
wrap.append(x);
|
|
49
49
|
}
|
|
@@ -51,7 +51,7 @@ export function renderInserter(root: HTMLElement, o: InserterOptions) {
|
|
|
51
51
|
};
|
|
52
52
|
input.addEventListener('input', draw);
|
|
53
53
|
input.addEventListener('keydown', (e) => {
|
|
54
|
-
if (e.key === 'Enter') { e.preventDefault(); results.querySelector<HTMLElement>('.
|
|
54
|
+
if (e.key === 'Enter') { e.preventDefault(); results.querySelector<HTMLElement>('.ps-tile__main')?.click(); }
|
|
55
55
|
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); o.onClose(); }
|
|
56
56
|
});
|
|
57
57
|
draw();
|
package/src/client/invite.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// /edit — "Invite an editor" form (passkey mode only).
|
|
2
|
-
const form = document.getElementById('
|
|
2
|
+
const form = document.getElementById('ps-invite') as HTMLFormElement | null;
|
|
3
3
|
form?.addEventListener('submit', async (e) => {
|
|
4
4
|
e.preventDefault();
|
|
5
5
|
const out = form.querySelector('output')!;
|
|
@@ -9,9 +9,9 @@ form?.addEventListener('submit', async (e) => {
|
|
|
9
9
|
const data = await res.json();
|
|
10
10
|
if (!res.ok) { out.textContent = data.error || 'Failed'; return; }
|
|
11
11
|
out.innerHTML = '';
|
|
12
|
-
const input = Object.assign(document.createElement('input'), { type: 'text', readOnly: true, value: data.url, className: '
|
|
13
|
-
const copy = Object.assign(document.createElement('button'), { type: 'button', className: '
|
|
12
|
+
const input = Object.assign(document.createElement('input'), { type: 'text', readOnly: true, value: data.url, className: 'ps-invite__url' });
|
|
13
|
+
const copy = Object.assign(document.createElement('button'), { type: 'button', className: 'ps-btn ps-btn--small', textContent: 'Copy' });
|
|
14
14
|
copy.addEventListener('click', async () => { await navigator.clipboard.writeText(data.url); copy.textContent = 'Copied'; });
|
|
15
|
-
const hint = Object.assign(document.createElement('small'), { className: '
|
|
15
|
+
const hint = Object.assign(document.createElement('small'), { className: 'ps-muted', textContent: `Send this link to ${fd.get('name')}. It works once and expires in ${Math.round(data.expiresIn / 86400)} days.` });
|
|
16
16
|
out.append(input, copy, hint);
|
|
17
17
|
});
|