diff --git a/deno.lock b/deno.lock
index e3b827f..f113237 100644
--- a/deno.lock
+++ b/deno.lock
@@ -2862,6 +2862,22 @@
}
},
"workspace": {
+ "dependencies": [
+ "npm:@nostr-dev-kit/ndk-cache-dexie@2.5",
+ "npm:@nostr-dev-kit/ndk@2.11",
+ "npm:@popperjs/core@2.11",
+ "npm:@tailwindcss/forms@0.5",
+ "npm:@tailwindcss/typography@0.5",
+ "npm:asciidoctor@3.0",
+ "npm:d3@7.9",
+ "npm:flowbite-svelte-icons@2.0",
+ "npm:flowbite-svelte@0.44",
+ "npm:flowbite@2.2",
+ "npm:he@1.2",
+ "npm:nostr-tools@2.10",
+ "npm:svelte@5.0",
+ "npm:tailwind-merge@2.5"
+ ],
"packageJson": {
"dependencies": [
"npm:@nostr-dev-kit/ndk-cache-dexie@2.5",
diff --git a/src/lib/Modal.svelte b/src/lib/components/Modal.svelte
similarity index 100%
rename from src/lib/Modal.svelte
rename to src/lib/components/Modal.svelte
diff --git a/src/lib/components/Preview.svelte b/src/lib/components/Preview.svelte
index 6130feb..30b7f10 100644
--- a/src/lib/components/Preview.svelte
+++ b/src/lib/components/Preview.svelte
@@ -1,8 +1,9 @@
+
+{#snippet sectionHeading(title: string, depth: number)}
+ {#if depth === 0}
+
+ {title}
+
+ {:else if depth === 1}
+
+ {title}
+
+ {:else if depth === 2}
+
+ {title}
+
+ {:else if depth === 3}
+
+ {title}
+
+ {:else if depth === 4}
+
+ {title}
+
+ {:else}
+
+ {title}
+
+ {/if}
+{/snippet}
+
+{#snippet contentParagraph(content: string, publicationType: string, isSectionStart: boolean)}
+ {#if publicationType === 'novel'}
+
+ {@html content}
+
+ {:else}
+
+ {@html content}
+
+ {/if}
+{/snippet}
diff --git a/src/lib/utils.ts b/src/lib/utils.ts
index 3a54d64..021c979 100644
--- a/src/lib/utils.ts
+++ b/src/lib/utils.ts
@@ -109,3 +109,38 @@ export function filterValidIndexEvents(events: Set): Set {
console.debug(`Filtered index events: ${events.size} events remaining.`);
return events;
}
+
+/**
+ * Async version of Array.findIndex() that runs sequentially.
+ * Returns the index of the first element that satisfies the provided testing function.
+ * @param array The array to search
+ * @param predicate The async testing function
+ * @returns A promise that resolves to the index of the first matching element, or -1 if none found
+ */
+export async function findIndexAsync(
+ array: T[],
+ predicate: (element: T, index: number, array: T[]) => Promise
+): Promise {
+ for (let i = 0; i < array.length; i++) {
+ if (await predicate(array[i], i, array)) {
+ return i;
+ }
+ }
+ return -1;
+}
+
+// Extend Array prototype with findIndexAsync
+declare global {
+ interface Array {
+ findIndexAsync(
+ predicate: (element: T, index: number, array: T[]) => Promise
+ ): Promise;
+ }
+}
+
+Array.prototype.findIndexAsync = function(
+ this: T[],
+ predicate: (element: T, index: number, array: T[]) => Promise
+): Promise {
+ return findIndexAsync(this, predicate);
+};
diff --git a/src/routes/publication/+page.ts b/src/routes/publication/+page.ts
index 3d58b39..7fddcdc 100644
--- a/src/routes/publication/+page.ts
+++ b/src/routes/publication/+page.ts
@@ -1,11 +1,11 @@
import { error } from '@sveltejs/kit';
-import { NDKRelay, NDKRelaySet, type NDKEvent } from '@nostr-dev-kit/ndk';
+import type { NDKEvent } from '@nostr-dev-kit/ndk';
import type { PageLoad } from './$types';
-import { get } from 'svelte/store';
-import { getActiveRelays, inboxRelays, ndkInstance } from '$lib/ndk';
-import { standardRelays } from '$lib/consts';
+import { getActiveRelays } from '$lib/ndk.ts';
+import { setContext } from 'svelte';
+import { PublicationTree } from '$lib/data_structures/publication_tree.ts';
-export const load: PageLoad = async ({ url, parent }) => {
+export const load: PageLoad = async ({ url, parent }: { url: URL; parent: () => Promise }) => {
const id = url.searchParams.get('id');
const dTag = url.searchParams.get('d');
@@ -41,6 +41,8 @@ export const load: PageLoad = async ({ url, parent }) => {
const publicationType = indexEvent?.getMatchingTags('type')[0]?.[1];
const fetchPromise = parser.fetch(indexEvent);
+ setContext('publicationTree', new PublicationTree(indexEvent, ndk));
+
return {
waitable: fetchPromise,
publicationType,
diff --git a/tsconfig.json b/tsconfig.json
index 794b95b..ec41776 100644
--- a/tsconfig.json
+++ b/tsconfig.json
@@ -8,7 +8,8 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"sourceMap": true,
- "strict": true
+ "strict": true,
+ "allowImportingTsExtensions": true
}
// Path aliases are handled by https://kit.svelte.dev/docs/configuration#alias
//
diff --git a/vite.config.ts b/vite.config.ts
index b9ba52c..d723dc1 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -3,6 +3,12 @@ import { defineConfig } from "vite";
export default defineConfig({
plugins: [sveltekit()],
+ resolve: {
+ alias: {
+ $lib: './src/lib',
+ $components: './src/components'
+ }
+ },
test: {
include: ['./tests/unit/**/*.unit-test.js']
}