From c6fedccf686cf39560234486c28e94aa69f5e136 Mon Sep 17 00:00:00 2001 From: Aidan Jones Date: Mon, 18 May 2026 11:17:32 -0500 Subject: [PATCH 1/8] Remove deprecated scripts --- src/lib/data/stores/store-types.js | 55 ------ src/lib/data/stores/view.js | 1 - src/lib/scripts/query.js | 23 --- src/lib/scripts/render.js | 261 ----------------------------- 4 files changed, 340 deletions(-) delete mode 100644 src/lib/data/stores/store-types.js delete mode 100644 src/lib/scripts/query.js delete mode 100644 src/lib/scripts/render.js diff --git a/src/lib/data/stores/store-types.js b/src/lib/data/stores/store-types.js deleted file mode 100644 index 6544c2b12..000000000 --- a/src/lib/data/stores/store-types.js +++ /dev/null @@ -1,55 +0,0 @@ -/** - * a store wrapper for a dynamic list of stores. - * behaves like a normal store if the default key is used. - */ -export const groupStore = (/**@type{any}*/ groupType, /**@type{any}*/ props) => { - /**@type{any}*/ const stores = { default: groupType(props) }; - /**@type{any}*/ const vals = { default: undefined }; - /**@type{any}*/ const mods = { default: undefined }; - /**@type{any}*/ const unsubs = { - default: stores.default.subscribe((v) => (vals['default'] = v)) - }; - /**@type{any}*/ const subs = { default: [] }; - - const subscribe = (cb, key = 'default') => { - if (!Object.prototype.hasOwnProperty.call(stores, key)) { - stores[key] = groupType(props); - unsubs[key] = stores[key].subscribe((v) => (vals[key] = v)); - subs[key] = []; - } - subs[key].push(cb); - cb(vals[key], mods[key]); - return () => { - subs[key] = subs[key].filter((sub) => sub !== cb); - if (key !== 'default' && subs[key].length <= 0) { - unsubs[key](); - delete stores[key]; - delete vals[key]; - delete mods[key]; - delete unsubs[key]; - delete subs[key]; - } - }; - }; - - const set = (val, key = 'default', mod = undefined) => { - stores[key].set(val); - mods[key] = mod; - subs[key].forEach((sub) => sub(vals[key], mods[key])); - }; - - const extras = Object.fromEntries( - Object.entries(stores['default']) - .filter((kv) => kv[0] !== 'subscribe' && kv[0] !== 'set' && typeof kv[1] === 'function') - .map((kv) => [ - kv[0], - (val, key = 'default', mod = undefined) => { - stores[key][kv[0]](val); - mods[key] = mod; - subs[key].forEach((sub) => sub(vals[key], mods[key])); - } - ]) - ); - - return { subscribe, set, ...extras }; -}; diff --git a/src/lib/data/stores/view.js b/src/lib/data/stores/view.js index 653c0f86d..93b40df9f 100644 --- a/src/lib/data/stores/view.js +++ b/src/lib/data/stores/view.js @@ -1,7 +1,6 @@ import { derived, get, readable, writable } from 'svelte/store'; import { defaultSettings, userSettings } from './setting'; import { setDefaultStorage } from './storage'; -import { groupStore } from './store-types'; export const NAVBAR_HEIGHT = '4rem'; diff --git a/src/lib/scripts/query.js b/src/lib/scripts/query.js deleted file mode 100644 index 869246037..000000000 --- a/src/lib/scripts/query.js +++ /dev/null @@ -1,23 +0,0 @@ -/**queries the proskomma endpoint*/ -export const query = async (query, cb) => { - const res = await fetch('/data/proskomma', { - method: 'POST', - body: JSON.stringify({ - query: minifyQuery(query) - }), - headers: { - 'content-type': 'application/json', - accept: 'application/json' - } - }); - const j = await res.json(); - if (cb) { - cb(j); - } - return j; -}; - -function minifyQuery(/**@type{string}*/ query) { - let s = query.replace(/\n/g, ' '); - return s.replace(/([^\w])(\s+)/g, '$1'); -} diff --git a/src/lib/scripts/render.js b/src/lib/scripts/render.js deleted file mode 100644 index 3a26e443e..000000000 --- a/src/lib/scripts/render.js +++ /dev/null @@ -1,261 +0,0 @@ -const seps = '.?!:;,'; -const seprgx = /(\.|\?|!|:|;|,|')/g; -const subc = 'abcdefghijklmnopqrstuvwxyz'; - -export const renderDoc = ( - mainSeq, - root, - /**@type{function(root)}*/ postprocess, - /**@type{function(data, element)}*/ graftHandler, - /**@type{function(root)}*/ finalprocess -) => { - if (!root || !mainSeq?.blocks?.length) { - return; - } - root.replaceChildren(); //clear current blocks from root - - const grafts = []; - - /**add graft to array and create placeholder*/ - const renderGraft = (graft) => { - grafts.push(graft); - return '_{graft-' + (grafts.length - 1) + '}_'; - }; - /**parse innerHTML into phrases*/ - const parsePhrases = (/**@type{string}*/ inner) => { - /**@type{string[]}*/ let phrases = inner.split(seprgx); - for (let i = 1; i < phrases.length; i += 2) { - phrases[i - 1] += phrases[i]; - } - phrases = phrases.filter((s) => s.length > 0 && (s.length > 1 || !s.match(seprgx))); - - //move chars orphaned by phrase parsing to preceding phrase - if (phrases.length > 1) { - for (let i = 0; i < phrases.length - 1; i++) { - const next = phrases[i + 1].split(''); - let c = next.shift(); - while (c && c.match(/[^_a-z]/i)) { - phrases[i] += c; - c = next.shift(); - } - if (c) { - next.unshift(c); - phrases[i + 1] = next.join(''); - } else { - phrases.splice(i + 1, 1); - i--; - } - } - } - - //shift grafts at start of phrase to end of next phrase - for (let i = 1; i < phrases.length; i++) { - const m = phrases[i].match(/^_\{graft-[0-9]\}_/); - if (m) { - phrases[i - 1] += m[0]; - phrases[i] = phrases[i].replace(m, ''); - } - } - return phrases; - }; - /**render array of phrases*/ - const renderPhrases = (phrases, parent, kv) => { - for (let i = 0; i < phrases.length; i++) { - const phrase = document.createElement('div'); - phrase.setAttribute('data-verse', kv[i].split('-')[0]); - phrase.setAttribute('data-phrase', kv[i].split('-')[1] ? kv[i].split('-')[1] : 'none'); - phrase.classList.add('txs', 'seltxt'); - - phrases[i] = phrases[i].replace(/(_\{graft-[0-9]+\}_)/g, (m) => { - return `${m}`; - }); - - phrase.innerHTML = phrases[i]; - phrase.getElementsByClassName('vsp').item(0)?.append('\xA0'); - - parent.append(phrase); - } - }; - /**parses out verse number*/ - const parseVerseNumber = (inner) => { - let v = null; - let phrases = ['']; - - inner = inner.split(/(_\{verse-[0-9]+\}_)/); - if (inner.length === 3) { - v = inner[1].replace(/(_|\{|\}|verse-)/g, ''); - phrases[0] = `${inner[0]}${v}`; - phrases[1] = inner[2]; - } else { - phrases[0] = inner[0]; - } - - return { v: v, phrases: phrases }; - }; - - const renderBlock = (block, parent) => { - if (block.type === 'graft') { - const s = renderGraft(block.sequence); - parent.innerHTML += `${s}`; - } else if (block.type === 'paragraph') { - const div = document.createElement('div'); - const subtype = block.subtype.split(':')[1]; - div.classList.add(subtype); - for (const content of block.content) { - renderContent(content, div, subtype); - } - // process non poetry blocks - if (subtype === 'p') { - const content = Array.from(div.getElementsByTagName('div')); - div.replaceChildren(); - for (const el of content) { - let inner = el.innerHTML; - el.replaceChildren(); - - let o = parseVerseNumber(inner); - let v = o.v; - - if (v) { - inner = parsePhrases(o.phrases[1]); - inner[0] = o.phrases[0] + inner[0]; - - //handle phrases - renderPhrases( - inner, - div, - inner.length > 1 ? inner.map((e, i) => v + '-' + subc.charAt(i)) : [v] - ); - } else { - inner = parsePhrases(o.phrases[0]); - el.innerHTML = inner.join(''); - div.append(el); - } - } - } - parent.append(div); - } else { - console.log('unknown block type: ' + block.type + ' encountered'); - } - }; - - const renderContent = (content, parent, blockType) => { - if (!content.type) { - parent.append(content); - } else if (content.type === 'wrapper') { - if (content.subtype === 'verses') { - if (blockType === 'p') { - const div = document.createElement('div'); - div.classList.add('unprocessed'); - div.setAttribute('data-number', content.atts.number); - for (const c2 of content.content) { - renderContent(c2, div, blockType); - } - parent.append(div); - } else { - for (const c2 of content.content) { - renderContent(c2, parent, blockType); - } - } - } else { - for (const c2 of content.content) { - renderContent(c2, parent, blockType); - } - } - } else if (content.type === 'mark') { - if (content.subtype === 'chapter_label') { - const div = document.createElement('div'); - div.classList.add('c-drop'); - div.append(content.atts.number); - parent.append(div); - } else if (content.subtype === 'verses_label') { - parent.append(`_{verse-${content.atts.number}}_`); - } else { - console.log('unknown mark subtype: ' + content.subtype + ' encountered'); - } - } else if (content.type === 'graft') { - const s = renderGraft(content.sequence); - parent.innerHTML += `${s}`; - } else { - console.log('unknown content type: ' + content.type + ' encountered'); - } - }; - - //<<<<< render main sequence >>>>> - for (const block of mainSeq.blocks) { - renderBlock(block, root); - } - // process poetry here, since it spans multiple blocks - const poetryBlocks = Array.from(root.getElementsByTagName('div')).filter( - (e) => e.classList.contains('q') || e.classList.contains('q2') - ); - const content = poetryBlocks.map((e) => e.innerHTML); - let v = '0'; - let phraseI = 0; - for (let i = 0; i < poetryBlocks.length; i++) { - poetryBlocks[i].replaceChildren(); - let o = parseVerseNumber(content[i]); - let inner = o.phrases; - - if (o.v) { - v = o.v; - phraseI = 0; - let tail = parsePhrases(inner[1]); - inner[0] += tail[0]; - tail.shift(); - inner = [inner[0]].concat(tail); - } else { - inner = parsePhrases(inner[0]); - } - - //handle phrases - renderPhrases( - inner, - poetryBlocks[i], - inner.map((e) => { - const s = v + '-' + subc.charAt(phraseI); - phraseI++; - return s; - }) - ); - } - // handle orphaned blocks - const orphanedBlocks = Array.from(root.getElementsByClassName('unprocessed')); - for (let i = 0; i < orphanedBlocks.length; i++) { - // don't need to handle verse numbers. if it had verse numbers, it wouldn't be orphaned. - let inner = parsePhrases(orphanedBlocks[i].innerHTML); - inner = inner.filter((s) => !s.match(/^\s+$/)); - - orphanedBlocks[i].replaceChildren(); - orphanedBlocks[i].classList.add('current'); - - const n = orphanedBlocks[i].getAttribute('data-number'); - const p = - Array.from( - root.querySelectorAll( - `div[data-verse="${orphanedBlocks[i].getAttribute('data-number')}"]` - ) - ) - .map((el) => subc.indexOf(el.getAttribute('data-phrase'))) - .sort((a, b) => b - a)[0] + 1; - renderPhrases( - inner, - orphanedBlocks[i], - inner.map((e, i) => n + '-' + subc.charAt(p + i)) - ); - orphanedBlocks[i].insertAdjacentHTML('afterend', orphanedBlocks[i].innerHTML); - orphanedBlocks[i].remove(); - } - - postprocess(root); - - if (graftHandler) { - grafts.forEach((g, i) => { - const el = root.querySelector(`span[data-graft="${i}"]`); - graftHandler(g, el); - }); - } else { - console.log('No graft handler was provided. Graft placeholders will be left in text.'); - } - - finalprocess(root); -}; From 6f9b74da80c5fee983cd9c9437b99fbac52b5410 Mon Sep 17 00:00:00 2001 From: Aidan Jones Date: Mon, 18 May 2026 11:18:09 -0500 Subject: [PATCH 2/8] Rename icon exports to TS --- src/lib/components/PlayButton.svelte | 2 +- src/lib/icons/audio/{index.js => index.ts} | 0 src/lib/icons/image/{index.js => index.ts} | 0 src/lib/icons/{index.js => index.ts} | 0 4 files changed, 1 insertion(+), 1 deletion(-) rename src/lib/icons/audio/{index.js => index.ts} (100%) rename src/lib/icons/image/{index.js => index.ts} (100%) rename src/lib/icons/{index.js => index.ts} (100%) diff --git a/src/lib/components/PlayButton.svelte b/src/lib/components/PlayButton.svelte index 31d23c759..c19795f08 100644 --- a/src/lib/components/PlayButton.svelte +++ b/src/lib/components/PlayButton.svelte @@ -21,7 +21,7 @@ } let { color = 'black', state, onclick }: Props = $props(); - const size = config.mainFeatures['audio-play-button-size'] === 'normal' ? 24 : 48; + const size = String(config.mainFeatures['audio-play-button-size'] === 'normal' ? 24 : 48); const style = config.mainFeatures['audio-play-button-style'] as keyof typeof icons; const icon_style = icons[style]; const Icon = $derived(icon_style[state]); diff --git a/src/lib/icons/audio/index.js b/src/lib/icons/audio/index.ts similarity index 100% rename from src/lib/icons/audio/index.js rename to src/lib/icons/audio/index.ts diff --git a/src/lib/icons/image/index.js b/src/lib/icons/image/index.ts similarity index 100% rename from src/lib/icons/image/index.js rename to src/lib/icons/image/index.ts diff --git a/src/lib/icons/index.js b/src/lib/icons/index.ts similarity index 100% rename from src/lib/icons/index.js rename to src/lib/icons/index.ts From 264307cbbf1abc882a25ed65bd81fa24bae65e0a Mon Sep 17 00:00:00 2001 From: Aidan Jones Date: Mon, 18 May 2026 11:33:20 -0500 Subject: [PATCH 3/8] Convert view.js to TS --- src/lib/components/AudioBar.svelte | 4 +-- src/lib/components/ScriptureViewSofria.svelte | 4 +-- src/lib/components/Sidebar.svelte | 10 +++--- .../components/TextAppearanceSelector.svelte | 4 +-- src/lib/data/stores/{view.js => view.ts} | 33 ++++++++++--------- src/routes/+layout.svelte | 27 +++++++-------- src/routes/contents/[id]/+page.svelte | 7 ++-- src/routes/lexicon/+layout.svelte | 4 +-- src/routes/notes/+page.svelte | 2 +- src/routes/plans/[id]/+page.svelte | 16 ++------- .../quiz/[collection]/[id]/+page.svelte | 4 +-- src/routes/text/+page.svelte | 13 +++----- 12 files changed, 58 insertions(+), 70 deletions(-) rename src/lib/data/stores/{view.js => view.ts} (83%) diff --git a/src/lib/components/AudioBar.svelte b/src/lib/components/AudioBar.svelte index dd6a9bf56..84848ff0a 100644 --- a/src/lib/components/AudioBar.svelte +++ b/src/lib/components/AudioBar.svelte @@ -20,7 +20,7 @@ TODO: audioPlayer, convertStyle, modal, - MODAL_PLAYBACK_SPEED, + ModalType, playMode, refs, s, @@ -153,7 +153,7 @@ TODO: {#if showSpeed} diff --git a/src/lib/components/ScriptureViewSofria.svelte b/src/lib/components/ScriptureViewSofria.svelte index e5b90594f..32e74afc9 100644 --- a/src/lib/components/ScriptureViewSofria.svelte +++ b/src/lib/components/ScriptureViewSofria.svelte @@ -31,7 +31,7 @@ LOGGING: language, logs, modal, - MODAL_NOTE, + ModalType, plan, refs, t, @@ -729,7 +729,7 @@ LOGGING: return ''; }; function editNote(note) { - modal.open(MODAL_NOTE, note); + modal.open(ModalType.Note, note); } function addNotedVerses(notesInChapter) { notesInChapter.then((notes) => { diff --git a/src/lib/components/Sidebar.svelte b/src/lib/components/Sidebar.svelte index 7f8677ff7..c557efd05 100644 --- a/src/lib/components/Sidebar.svelte +++ b/src/lib/components/Sidebar.svelte @@ -16,8 +16,7 @@ The sidebar/drawer. language, languageDefault, modal, - MODAL_COLLECTION, - MODAL_TEXT_APPEARANCE, + ModalType, refs, s, showDesktopSidebar, @@ -172,7 +171,10 @@ The sidebar/drawer. {#if showLayouts}
  • -
  • @@ -238,7 +240,7 @@ The sidebar/drawer.
  • diff --git a/src/lib/components/TextAppearanceSelector.svelte b/src/lib/components/TextAppearanceSelector.svelte index c1cf43e19..e4c7587b4 100644 --- a/src/lib/components/TextAppearanceSelector.svelte +++ b/src/lib/components/TextAppearanceSelector.svelte @@ -45,7 +45,7 @@ The navbar component. We have sliders that update reactively to both font size a language, languages, modal, - MODAL_FONT, + ModalType, monoIconColor, theme, themeColors, @@ -185,7 +185,7 @@ The navbar component. We have sliders that update reactively to both font size a style:font-family={$currentFont} style:font-size="large" style:color={$monoIconColor} - on:click={() => modal.open(MODAL_FONT)} + on:click={() => modal.open(ModalType.Font)} >{config.fonts.find((x) => x.family === $currentFont)?.name} diff --git a/src/lib/data/stores/view.js b/src/lib/data/stores/view.ts similarity index 83% rename from src/lib/data/stores/view.js rename to src/lib/data/stores/view.ts index 93b40df9f..d6a34c898 100644 --- a/src/lib/data/stores/view.js +++ b/src/lib/data/stores/view.ts @@ -22,18 +22,21 @@ export const LAYOUT_VERSE_BY_VERSE = 'verse-by-verse'; const singleLayout = { mode: LAYOUT_SINGLE, auxDocSets: [] }; export const layout = writable(singleLayout); -export const MODAL_COLLECTION = 'collection'; -export const MODAL_NOTE = 'note'; -export const MODAL_TEXT_APPEARANCE = 'text-appearance'; -export const MODAL_FONT = 'font'; -export const MODAL_STOP_PLAN = 'stop-plan'; -export const MODAL_PLAYBACK_SPEED = 'playback-speed'; +export const ModalType = { + Collection: 'collection', + Note: 'note', + TextAppearance: 'text-appearance', + Font: 'font', + StopPlan: 'stop-plan', + PlaybackSpeed: 'playback-speed' +} as const; +export type ModalType = (typeof ModalType)[keyof typeof ModalType]; function createModal() { - const { subscribe, set } = writable([]); + const { subscribe, set } = writable([] as { modalType: ModalType; data?: unknown }[]); return { subscribe, - open: (modalType, data = undefined) => { + open: (modalType: ModalType, data?: unknown) => { set([...get(modal), { modalType, data }]); }, clear: () => set([]) @@ -50,7 +53,7 @@ const createWindowSizeStore = () => { let numSubscriptions = 0; - function subscribe(callback) { + function subscribe(callback: Parameters<(typeof internal)['subscribe']>[0]) { // Increment the subscription count numSubscriptions += 1; @@ -103,24 +106,24 @@ export const showDesktopSidebar = derived( ($userSettings) => $userSettings['desktop-sidebar'] ?? defaultSettings['desktop-sidebar'] ); -function createStackStore() { - const { subscribe, update } = writable([]); +function createStackStore() { + const { subscribe, update } = writable([] as T[]); return { subscribe, - pushItem: (id) => + pushItem: (id: T) => update((stack) => { return [...stack, id]; }), popItem: () => { - let poppedValue = 0; + let poppedValue: T | undefined = undefined; update((stack) => { if (stack.length > 0) { poppedValue = stack.pop(); } return [...stack]; }); - return poppedValue; + return poppedValue as T | undefined; }, length: () => { let length = 0; @@ -133,4 +136,4 @@ function createStackStore() { }; } -export const contentsStack = createStackStore(); +export const contentsStack = createStackStore(); diff --git a/src/routes/+layout.svelte b/src/routes/+layout.svelte index 75337429e..41b10154d 100644 --- a/src/routes/+layout.svelte +++ b/src/routes/+layout.svelte @@ -16,12 +16,7 @@ analytics, direction, modal, - MODAL_COLLECTION, - MODAL_FONT, - MODAL_NOTE, - MODAL_PLAYBACK_SPEED, - MODAL_STOP_PLAN, - MODAL_TEXT_APPEARANCE, + ModalType, NAVBAR_HEIGHT, refs, s, @@ -70,24 +65,26 @@ if ($modal.length > 0) { $modal.forEach(({ modalType, data }) => { switch (modalType) { - case MODAL_COLLECTION: + case ModalType.Collection: collectionSelector.showModal(); break; - case MODAL_NOTE: - noteDialog.showModal(data); + case ModalType.Note: + noteDialog?.showModal( + data as Parameters<(typeof noteDialog)['showModal']>[0] + ); break; - case MODAL_TEXT_APPEARANCE: + case ModalType.TextAppearance: textAppearanceSelector.options = data; textAppearanceSelector.showModal(); break; - case MODAL_FONT: + case ModalType.Font: fontSelector.showModal(); break; - case MODAL_STOP_PLAN: - planStopId = data; + case ModalType.StopPlan: + planStopId = data as string; planStopDialog?.showModal(); break; - case MODAL_PLAYBACK_SPEED: + case ModalType.PlaybackSpeed: audioPlaybackSpeed.showModal(); break; } @@ -109,7 +106,7 @@ let textAppearanceSelector: TextAppearanceSelector = $state(); let collectionSelector: CollectionSelector = $state(); let fontSelector: FontSelector = $state(); - let noteDialog: NoteDialog = $state(); + let noteDialog: NoteDialog | undefined = $state(); let planStopDialog: PlanStopDialog | undefined = $state(undefined); let planStopId: string = $state(''); let audioPlaybackSpeed: AudioPlaybackSpeed = $state(); diff --git a/src/routes/contents/[id]/+page.svelte b/src/routes/contents/[id]/+page.svelte index 4ce43a480..e1fd8eaa7 100644 --- a/src/routes/contents/[id]/+page.svelte +++ b/src/routes/contents/[id]/+page.svelte @@ -15,8 +15,7 @@ convertStyle, language, modal, - MODAL_COLLECTION, - MODAL_TEXT_APPEARANCE, + ModalType, refs, s, t, @@ -91,7 +90,7 @@ gotoRoute(`/${item.linkLocation}`); break; case 'layout': - modal.open(MODAL_COLLECTION); + modal.open(ModalType.Collection); break; case 'website': //opens in a separate tab @@ -254,7 +253,7 @@ diff --git a/src/routes/lexicon/+layout.svelte b/src/routes/lexicon/+layout.svelte index 5ffb38a9e..60fa906da 100644 --- a/src/routes/lexicon/+layout.svelte +++ b/src/routes/lexicon/+layout.svelte @@ -3,7 +3,7 @@ import config from '$assets/config'; import Navbar from '$lib/components/Navbar.svelte'; import { showTextAppearance } from '$lib/components/TextAppearanceSelector.svelte'; - import { fontChoices, modal, MODAL_TEXT_APPEARANCE, t } from '$lib/data/stores'; + import { fontChoices, modal, ModalType, t } from '$lib/data/stores'; import { selectedWord, selectWord } from '$lib/data/stores/lexicon.svelte'; import SearchIcon from '$lib/icons/SearchIcon.svelte'; import TextAppearanceIcon from '$lib/icons/TextAppearanceIcon.svelte'; @@ -56,7 +56,7 @@ {#if showTextAppearance($fontChoices)} diff --git a/src/routes/notes/+page.svelte b/src/routes/notes/+page.svelte index 0e151b6b4..d01c6a6b9 100644 --- a/src/routes/notes/+page.svelte +++ b/src/routes/notes/+page.svelte @@ -6,7 +6,7 @@ import { shareAnnotation, shareAnnotations } from '$lib/data/annotation-share'; import { SORT_DATE, SORT_REFERENCE, toSorted } from '$lib/data/annotation-sort'; import { removeNote, type NoteItem } from '$lib/data/notes'; - import { bodyFontSize, modal, MODAL_NOTE, monoIconColor, refs, t } from '$lib/data/stores'; + import { bodyFontSize, monoIconColor, refs, t } from '$lib/data/stores'; import { NoteIcon } from '$lib/icons'; import ShareIcon from '$lib/icons/ShareIcon.svelte'; import { gotoRoute } from '$lib/navigate'; diff --git a/src/routes/plans/[id]/+page.svelte b/src/routes/plans/[id]/+page.svelte index b79956e66..9faa2e4c0 100644 --- a/src/routes/plans/[id]/+page.svelte +++ b/src/routes/plans/[id]/+page.svelte @@ -1,20 +1,10 @@
    @@ -68,7 +74,7 @@ @@ -81,11 +87,11 @@ class="overflow-y-auto p-2.5 max-w-screen-md mx-auto w-full" style:font-size="{$bodyFontSize}px" > - {#if page.data.highlights.length === 0} + {#if data.highlights.length === 0}
    {$t['Annotation_Highlights_None']}
    {$t['Annotation_Highlights_None_Info']}
    {:else} - {#each toSorted(page.data.highlights, sortOrder) as h} + {#each toSorted(data.highlights, sortOrder) as h} {@const colorCard = { docSet: h.docSet, collection: h.collection, diff --git a/src/routes/highlights/+page.js b/src/routes/highlights/+page.ts similarity index 54% rename from src/routes/highlights/+page.js rename to src/routes/highlights/+page.ts index b6c89d152..702db99e7 100644 --- a/src/routes/highlights/+page.js +++ b/src/routes/highlights/+page.ts @@ -1,17 +1,17 @@ -import config from '$assets/config'; +import config, { scriptureConfig } from '$assets/config'; import { getHighlights } from '$lib/data/highlights'; +import type { PageLoad } from './$types'; -/** @type {import('./$types').PageLoad} */ -export async function load({ depends }) { +export const load: PageLoad = async ({ depends }) => { const allHighlights = await getHighlights(); // Make annotations more resiliant to changes in book collection ids over time. // Ignore entries if we don't currently have a collection for the entry. // This can happen during testing of different PWA at the same port and we don't // want to break the feature. - const highlights = allHighlights.filter((item) => { - return config.bookCollections.some((collection) => collection.id === item.collection); - }); - depends('highlights'); + const highlights = allHighlights.filter((item) => + scriptureConfig.bookCollections?.some((collection) => collection.id === item.collection) + ); + depends('note:highlights'); return { highlights }; -} +}; diff --git a/src/routes/history/+page.js b/src/routes/history/+page.ts similarity index 57% rename from src/routes/history/+page.js rename to src/routes/history/+page.ts index 07a31ae6d..7ce9a50d0 100644 --- a/src/routes/history/+page.js +++ b/src/routes/history/+page.ts @@ -1,16 +1,16 @@ -import config from '$assets/config'; +import { scriptureConfig } from '$assets/config'; import { getHistory } from '$lib/data/history'; +import type { PageLoad } from './$types'; -/** @type {import('./$types').PageLoad} */ -export async function load() { +export const load: PageLoad = async () => { const allHistory = await getHistory(); // Make history more resiliant to changes in book collection ids over time. // Ignore entries if we don't currently have a collection for the entry. // This can happen during testing of different PWA at the same port and we don't // want to break the feature. - const history = allHistory.filter((item) => { - return config.bookCollections.some((collection) => collection.id === item.collection); - }); + const history = allHistory.filter((item) => + scriptureConfig.bookCollections?.some((collection) => collection.id === item.collection) + ); return { history }; -} +}; diff --git a/src/routes/notes/+page.js b/src/routes/notes/+page.ts similarity index 56% rename from src/routes/notes/+page.js rename to src/routes/notes/+page.ts index 22c57e588..1a09b1bba 100644 --- a/src/routes/notes/+page.js +++ b/src/routes/notes/+page.ts @@ -1,18 +1,18 @@ -import config from '$assets/config'; +import { scriptureConfig } from '$assets/config'; import { getNotes } from '$lib/data/notes'; +import type { PageLoad } from './$types'; -/** @type {import('./$types').PageLoad} */ -export async function load({ depends }) { +export const load: PageLoad = async ({ depends }) => { const allNotes = await getNotes(); // Make annotations more resiliant to changes in book collection ids over time. // Ignore entries if we don't currently have a collection for the entry. // This can happen during testing of different PWA at the same port and we don't // want to break the feature. - const notes = allNotes.filter((item) => { - return config.bookCollections.some((collection) => collection.id === item.collection); - }); - depends('notes'); + const notes = allNotes.filter((item) => + scriptureConfig.bookCollections?.some((collection) => collection.id === item.collection) + ); + depends('note:notes'); console.log('Notes', notes); return { notes }; -} +}; diff --git a/src/routes/notes/edit/[noteid]/+page.svelte b/src/routes/notes/edit/[noteid]/+page.svelte index 6195f32b2..13baf68de 100644 --- a/src/routes/notes/edit/[noteid]/+page.svelte +++ b/src/routes/notes/edit/[noteid]/+page.svelte @@ -73,9 +73,9 @@ {$t[title]}
    - diff --git a/src/routes/notes/edit/[noteid]/+page.js b/src/routes/notes/edit/[noteid]/+page.ts similarity index 85% rename from src/routes/notes/edit/[noteid]/+page.js rename to src/routes/notes/edit/[noteid]/+page.ts index 4b15673f5..97d4039b7 100644 --- a/src/routes/notes/edit/[noteid]/+page.js +++ b/src/routes/notes/edit/[noteid]/+page.ts @@ -1,7 +1,8 @@ import { error } from '@sveltejs/kit'; import { getNotes } from '$lib/data/notes'; +import type { PageLoad } from './$types'; -export async function load({ params }) { +export const load: PageLoad = async ({ params }) => { const { noteid } = params; if (noteid === 'new') { return { note: undefined }; @@ -24,4 +25,4 @@ export async function load({ params }) { }); } return { note }; -} +}; diff --git a/src/routes/plans/+page.js b/src/routes/plans/+page.ts similarity index 54% rename from src/routes/plans/+page.js rename to src/routes/plans/+page.ts index b0d91c744..8ded8a97b 100644 --- a/src/routes/plans/+page.js +++ b/src/routes/plans/+page.ts @@ -1,14 +1,11 @@ -import { getPlans } from '$lib/data/plans'; - -/** @type {import('./$types').PageLoad} */ -export async function load({ depends }) { - const allPlans = await getPlans(); +import { type PlanItem } from '$lib/data/plans'; +import type { PageLoad } from './$types'; +export const load: PageLoad = async ({ depends }) => { // Make annotations more resiliant to changes in book collection ids over time. // Ignore entries if we don't currently have a collection for the entry. // This can happen during testing of different PWA at the same port and we don't // want to break the feature. - const plans = []; - depends('plans'); - return { plans }; -} + depends('note:plans'); + return { plans: [] as PlanItem[] }; +}; diff --git a/src/routes/plans/[id]/+page.js b/src/routes/plans/[id]/+page.ts similarity index 74% rename from src/routes/plans/[id]/+page.js rename to src/routes/plans/[id]/+page.ts index d5d5608eb..695d6255c 100644 --- a/src/routes/plans/[id]/+page.js +++ b/src/routes/plans/[id]/+page.ts @@ -1,8 +1,9 @@ import { scriptureConfig } from '$assets/config'; import { getAllProgressItemsForPlan } from '$lib/data/planProgressItems'; -import { getPlanData } from '../../../lib/data/plansData'; +import { getPlanData } from '$lib/data/plansData'; +import type { PageLoad } from './$types'; -export async function load({ params, fetch }) { +export const load: PageLoad = async ({ params, fetch }) => { const allPlans = scriptureConfig.plans?.plans ?? []; const id = params.id; @@ -14,4 +15,4 @@ export async function load({ params, fetch }) { const planCompletionData = await getAllProgressItemsForPlan(id); return { planConfig, planData, planCompletionData }; -} +}; diff --git a/src/routes/plans/[id]/settings/+page.js b/src/routes/plans/[id]/settings/+page.ts similarity index 69% rename from src/routes/plans/[id]/settings/+page.js rename to src/routes/plans/[id]/settings/+page.ts index f17d15c76..f4b4a4271 100644 --- a/src/routes/plans/[id]/settings/+page.js +++ b/src/routes/plans/[id]/settings/+page.ts @@ -1,10 +1,11 @@ import { scriptureConfig } from '$assets/config'; +import type { PageLoad } from './$types'; -export async function load({ params }) { +export const load: PageLoad = async ({ params }) => { const allPlans = scriptureConfig.plans?.plans ?? []; const id = params.id; const planConfig = allPlans.find((x) => x.id === id); return { planConfig }; -} +}; diff --git a/src/routes/share/+page.svelte b/src/routes/share/+page.svelte index 4e6eb7bf8..6c553c5c8 100644 --- a/src/routes/share/+page.svelte +++ b/src/routes/share/+page.svelte @@ -1,11 +1,10 @@