@nsite/stealthis 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/nostr.ts +15 -15
- package/src/widget.ts +16 -16
package/package.json
CHANGED
package/src/nostr.ts
CHANGED
|
@@ -9,7 +9,7 @@ export interface NsiteContext {
|
|
|
9
9
|
baseDomain: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export interface
|
|
12
|
+
export interface Muse {
|
|
13
13
|
index: number;
|
|
14
14
|
pubkey: string;
|
|
15
15
|
relays: string[];
|
|
@@ -232,11 +232,11 @@ export async function checkExistingSite(
|
|
|
232
232
|
return events.length > 0;
|
|
233
233
|
}
|
|
234
234
|
|
|
235
|
-
const
|
|
235
|
+
const MAX_MUSE_TAGS = 9;
|
|
236
236
|
|
|
237
|
-
export function
|
|
237
|
+
export function extractMuses(event: RelayEvent): Muse[] {
|
|
238
238
|
return event.tags
|
|
239
|
-
.filter((t) => t[0] === '
|
|
239
|
+
.filter((t) => t[0] === 'muse' && t[1] && t[2])
|
|
240
240
|
.map((t) => ({ index: parseInt(t[1], 10), pubkey: t[2], relays: t.slice(3) }))
|
|
241
241
|
.sort((a, b) => a.index - b.index);
|
|
242
242
|
}
|
|
@@ -257,25 +257,25 @@ export function createDeployEvent(
|
|
|
257
257
|
if (t[0] === 'path' || t[0] === 'server') tags.push([...t]);
|
|
258
258
|
}
|
|
259
259
|
|
|
260
|
-
// Paper trail: copy
|
|
261
|
-
const
|
|
262
|
-
.filter((t) => t[0] === '
|
|
260
|
+
// Paper trail: copy muse tags, add new one, enforce max 9
|
|
261
|
+
const sourceMuses = source.tags
|
|
262
|
+
.filter((t) => t[0] === 'muse' && t[1] && t[2])
|
|
263
263
|
.map((t) => [...t])
|
|
264
264
|
.sort((a, b) => parseInt(a[1], 10) - parseInt(b[1], 10));
|
|
265
265
|
|
|
266
|
-
const maxIndex =
|
|
267
|
-
? Math.max(...
|
|
266
|
+
const maxIndex = sourceMuses.length > 0
|
|
267
|
+
? Math.max(...sourceMuses.map((t) => parseInt(t[1], 10)))
|
|
268
268
|
: -1;
|
|
269
|
-
const
|
|
270
|
-
const
|
|
269
|
+
const newMuse = ['muse', String(maxIndex + 1), options.deployerPubkey, ...options.deployerRelays];
|
|
270
|
+
const allMuses = [...sourceMuses, newMuse];
|
|
271
271
|
|
|
272
272
|
// Keep index 0 (originator) + newest, FIFO truncate the middle
|
|
273
|
-
if (
|
|
274
|
-
const originator =
|
|
275
|
-
const keep =
|
|
273
|
+
if (allMuses.length > MAX_MUSE_TAGS) {
|
|
274
|
+
const originator = allMuses[0];
|
|
275
|
+
const keep = allMuses.slice(allMuses.length - (MAX_MUSE_TAGS - 1));
|
|
276
276
|
tags.push(originator, ...keep);
|
|
277
277
|
} else {
|
|
278
|
-
for (const t of
|
|
278
|
+
for (const t of allMuses) tags.push(t);
|
|
279
279
|
}
|
|
280
280
|
|
|
281
281
|
if (options.title) tags.push(['title', options.title]);
|
package/src/widget.ts
CHANGED
|
@@ -45,8 +45,8 @@ export class NsiteDeployButton extends HTMLElement {
|
|
|
45
45
|
private ncConnect: ReturnType<typeof prepareNostrConnect> | null = null;
|
|
46
46
|
private manifestPromise: Promise<nostr.SignedEvent | null> | null = null;
|
|
47
47
|
private relaysPromise: Promise<string[]> | null = null;
|
|
48
|
-
private
|
|
49
|
-
private
|
|
48
|
+
private muses: nostr.Muse[] = [];
|
|
49
|
+
private musesExpanded = false;
|
|
50
50
|
|
|
51
51
|
constructor() {
|
|
52
52
|
super();
|
|
@@ -56,8 +56,8 @@ export class NsiteDeployButton extends HTMLElement {
|
|
|
56
56
|
this.manifestPromise = nostr.fetchManifest(this.ctx);
|
|
57
57
|
this.manifestPromise.then((manifest) => {
|
|
58
58
|
if (manifest) {
|
|
59
|
-
this.
|
|
60
|
-
if (this.
|
|
59
|
+
this.muses = nostr.extractMuses(manifest);
|
|
60
|
+
if (this.muses.length > 0 && this.state === 'idle') this.render();
|
|
61
61
|
}
|
|
62
62
|
});
|
|
63
63
|
this.render();
|
|
@@ -172,18 +172,18 @@ export class NsiteDeployButton extends HTMLElement {
|
|
|
172
172
|
// --- Content builders ---
|
|
173
173
|
|
|
174
174
|
private paperTrailContent(): string {
|
|
175
|
-
if (this.
|
|
175
|
+
if (this.muses.length === 0) return '';
|
|
176
176
|
|
|
177
177
|
let html = `<div class="nd-trail">
|
|
178
|
-
<button class="nd-trail-toggle" data-action="toggle-trail">
|
|
178
|
+
<button class="nd-trail-toggle" data-action="toggle-trail">Inspired ${this.muses.length} npub${this.muses.length === 1 ? '' : 's'}</button>`;
|
|
179
179
|
|
|
180
|
-
if (this.
|
|
180
|
+
if (this.musesExpanded) {
|
|
181
181
|
html += `<div class="nd-trail-list">`;
|
|
182
|
-
const first = this.
|
|
183
|
-
const second = this.
|
|
182
|
+
const first = this.muses[0];
|
|
183
|
+
const second = this.muses.length > 1 ? this.muses[1] : null;
|
|
184
184
|
|
|
185
185
|
// Show originator
|
|
186
|
-
html += this.
|
|
186
|
+
html += this.museItem(first);
|
|
187
187
|
|
|
188
188
|
// Show gap if indices aren't sequential (truncated middle)
|
|
189
189
|
if (second && second.index > first.index + 1) {
|
|
@@ -192,8 +192,8 @@ export class NsiteDeployButton extends HTMLElement {
|
|
|
192
192
|
}
|
|
193
193
|
|
|
194
194
|
// Show the rest
|
|
195
|
-
for (let i = 1; i < this.
|
|
196
|
-
html += this.
|
|
195
|
+
for (let i = 1; i < this.muses.length; i++) {
|
|
196
|
+
html += this.museItem(this.muses[i]);
|
|
197
197
|
}
|
|
198
198
|
html += `</div>`;
|
|
199
199
|
}
|
|
@@ -202,11 +202,11 @@ export class NsiteDeployButton extends HTMLElement {
|
|
|
202
202
|
return html;
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
private
|
|
206
|
-
const npub = nostr.npubEncode(
|
|
205
|
+
private museItem(muse: nostr.Muse): string {
|
|
206
|
+
const npub = nostr.npubEncode(muse.pubkey);
|
|
207
207
|
const short = npub.slice(0, 12) + '...' + npub.slice(-4);
|
|
208
208
|
return `<div class="nd-trail-item">
|
|
209
|
-
<span class="nd-trail-idx">#${
|
|
209
|
+
<span class="nd-trail-idx">#${muse.index}</span>
|
|
210
210
|
<span class="nd-trail-pk">${short}</span>
|
|
211
211
|
</div>`;
|
|
212
212
|
}
|
|
@@ -345,7 +345,7 @@ export class NsiteDeployButton extends HTMLElement {
|
|
|
345
345
|
this.shadow
|
|
346
346
|
.querySelector('[data-action="toggle-trail"]')
|
|
347
347
|
?.addEventListener('click', () => {
|
|
348
|
-
this.
|
|
348
|
+
this.musesExpanded = !this.musesExpanded;
|
|
349
349
|
this.render();
|
|
350
350
|
});
|
|
351
351
|
this.shadow
|