|
5 | 5 | import { renderSpecialTag, trimTrailingSlash } from "./util"; |
6 | 6 |
|
7 | 7 | import ScrollViewMarkdown from "ScrollViewMarkdownComponent.svelte"; |
8 | | - import { onDestroy, onMount } from "svelte"; |
| 8 | + import { onDestroy } from "svelte"; |
9 | 9 | import type TagFolderPlugin from "main"; |
10 | 10 |
|
11 | | - export let store: Writable<ScrollViewState> = writable<ScrollViewState>({ |
12 | | - files: [], |
13 | | - title: "", |
14 | | - tagPath: "", |
15 | | - }); |
16 | | - export let openfile: (path: string, specialKey: boolean) => void; |
17 | | - export let plugin: TagFolderPlugin; |
18 | | -
|
19 | | - let state: ScrollViewState = { files: [], title: "", tagPath: "" }; |
20 | | - $: { |
21 | | - store.subscribe((_state) => { |
22 | | - state = { ..._state }; |
23 | | - return () => {}; |
24 | | - }); |
| 11 | + interface Props { |
| 12 | + store?: Writable<ScrollViewState>; |
| 13 | + openfile: (path: string, specialKey: boolean) => void; |
| 14 | + plugin: TagFolderPlugin; |
25 | 15 | } |
26 | | - $: files = state.files; |
27 | | - $: tagPath = state.tagPath |
28 | | - .split(", ") |
29 | | - .map( |
30 | | - (e) => |
31 | | - "#" + |
32 | | - trimTrailingSlash(e) |
33 | | - .split("/") |
34 | | - .map((e) => renderSpecialTag(e.trim())) |
35 | | - .join("/"), |
36 | | - ) |
37 | | - .join(", "); |
| 16 | +
|
| 17 | + let { |
| 18 | + store = writable<ScrollViewState>({ |
| 19 | + files: [], |
| 20 | + title: "", |
| 21 | + tagPath: "", |
| 22 | + }), |
| 23 | + openfile, |
| 24 | + plugin, |
| 25 | + }: Props = $props(); |
| 26 | +
|
| 27 | + const _state: ScrollViewState = $derived($store); |
| 28 | + let files = $derived(_state.files); |
| 29 | + const tagPath = $derived( |
| 30 | + _state.tagPath |
| 31 | + .split(", ") |
| 32 | + .map( |
| 33 | + (e) => |
| 34 | + "#" + |
| 35 | + trimTrailingSlash(e) |
| 36 | + .split("/") |
| 37 | + .map((e) => renderSpecialTag(e.trim())) |
| 38 | + .join("/"), |
| 39 | + ) |
| 40 | + .join(", "), |
| 41 | + ); |
38 | 42 | function handleOpenFile(e: MouseEvent, file: ScrollViewFile) { |
39 | 43 | openfile(file.path, false); |
40 | 44 | e.preventDefault(); |
41 | 45 | } |
42 | 46 | // Observe appearing and notify the component that you should render the content. |
43 | | - let scrollEl: HTMLElement; |
44 | | - let observer: IntersectionObserver; |
| 47 | + let scrollEl = $state<HTMLElement>(); |
| 48 | + let observer = $state<IntersectionObserver>(); |
45 | 49 | const onAppearing = new CustomEvent("appearing", { |
46 | 50 | detail: {}, |
47 | 51 | }); |
48 | | - onMount(() => { |
| 52 | + $effect(() => { |
49 | 53 | const options = { |
50 | 54 | root: scrollEl, |
51 | 55 | rootMargin: "10px", |
|
63 | 67 | ); |
64 | 68 | }); |
65 | 69 | onDestroy(() => { |
66 | | - observer.disconnect(); |
| 70 | + observer?.disconnect(); |
67 | 71 | }); |
68 | 72 | </script> |
69 | 73 |
|
|
73 | 77 | </div> |
74 | 78 | <hr /> |
75 | 79 | {#each files as file} |
76 | | - <!-- svelte-ignore a11y-click-events-have-key-events --> |
77 | | - <!-- svelte-ignore a11y-no-static-element-interactions --> |
| 80 | + <!-- svelte-ignore a11y_click_events_have_key_events --> |
| 81 | + <!-- svelte-ignore a11y_no_static_element_interactions --> |
78 | 82 | <div |
79 | 83 | class="file" |
80 | | - on:click={(evt) => handleOpenFile(evt, file)} |
| 84 | + onclick={(evt) => handleOpenFile(evt, file)} |
81 | 85 | bind:this={scrollEl} |
82 | 86 | > |
83 | 87 | <div class="header"> |
|
0 commit comments