Skip to content

Commit da49429

Browse files
committed
update svelte; fix editor
1 parent 107b320 commit da49429

File tree

7 files changed

+48
-31
lines changed

7 files changed

+48
-31
lines changed

bun.lockb

0 Bytes
Binary file not shown.

exampleVault/Input Fields/Editor.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ editor: |-
55
**test**
66
77
# Heading
8-
9-
[[Slider]]
108
editor2: |-
119
asd
1210

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@
5353
"svelte-preprocess": "^6.0.2",
5454
"tslib": "^2.6.3",
5555
"typescript": "^5.5.4",
56-
"yaml": "^2.4.5"
56+
"yaml": "^2.5.0"
5757
},
5858
"dependencies": {
5959
"@codemirror/legacy-modes": "^6.4.0",
6060
"@lemons_dev/parsinom": "^0.0.12",
6161
"itertools-ts": "^1.27.1",
6262
"mathjs": "^12.4.3",
6363
"moment": "^2.30.1",
64-
"svelte": "5.0.0-next.195",
64+
"svelte": "5.0.0-next.199",
6565
"zod": "^3.23.8",
6666
"zod-validation-error": "^2.1.0"
6767
},
@@ -71,6 +71,6 @@
7171
"svelte-preprocess"
7272
],
7373
"patchedDependencies": {
74-
"[email protected].195": "patches/[email protected].195.patch"
74+
"[email protected].199": "patches/[email protected].199.patch"
7575
}
7676
}
Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,25 @@
11
<script lang="ts">
2+
import MarkdownRenderComponent from 'packages/core/src/fields/inputFields/fields/Editor/MarkdownRenderComponent.svelte';
23
import type { InputFieldSvelteProps } from 'packages/core/src/fields/inputFields/InputFieldSvelteWrapper';
3-
import { onMount } from 'svelte';
44
55
const props: InputFieldSvelteProps<string> & {
66
render: (el: HTMLElement, value: string) => void;
7+
filePath: string;
78
} = $props();
89
910
let value = $state(props.value);
10-
11-
let renderEl: HTMLElement;
12-
let inputEl: HTMLElement;
13-
14-
onMount(() => {
15-
renderEl.style.display = 'block';
16-
inputEl.style.display = 'none';
17-
props.render(renderEl, value);
18-
});
11+
let editing = $state(false);
1912
2013
export function setValue(v: string): void {
2114
value = v;
22-
props.render(renderEl, v);
2315
}
2416
2517
function focusOut(): void {
26-
renderEl.style.display = 'block';
27-
inputEl.style.display = 'none';
28-
props.render(renderEl, value);
18+
editing = false;
2919
}
3020
3121
function focusIn(): void {
32-
// console.log('focus in');
33-
renderEl.style.display = 'none';
34-
inputEl.style.display = 'block';
35-
inputEl.focus();
22+
editing = true;
3623
}
3724
3825
function focusInOnKey(event: KeyboardEvent): void {
@@ -49,11 +36,11 @@
4936
role="button"
5037
tabindex="0"
5138
>
52-
<textarea
53-
bind:this={inputEl}
54-
bind:value={value}
55-
onfocusout={() => focusOut()}
56-
oninput={() => props.onValueChange(value)}
57-
></textarea>
58-
<div bind:this={renderEl}></div>
39+
{#if editing}
40+
<textarea bind:value={value} onfocusout={() => focusOut()} oninput={() => props.onValueChange(value)}
41+
></textarea>
42+
{:else}
43+
<MarkdownRenderComponent bind:value={value} plugin={props.plugin} filePath={props.filePath}
44+
></MarkdownRenderComponent>
45+
{/if}
5946
</div>

packages/core/src/fields/inputFields/fields/Editor/EditorIPF.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ export class EditorIPF extends AbstractInputField<string, string> {
3030
protected getMountArgs(): Record<string, unknown> {
3131
return {
3232
render: (el: HTMLElement, value: string) => void this.renderInElement(el, value),
33+
filePath: this.mountable.getFilePath(),
3334
};
3435
}
3536

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<script lang="ts">
2+
import type { IPlugin } from 'packages/core/src/IPlugin';
3+
import { onDestroy } from 'svelte';
4+
5+
let element: HTMLElement;
6+
7+
const {
8+
value = $bindable(''),
9+
plugin,
10+
filePath,
11+
}: {
12+
value: string;
13+
plugin: IPlugin;
14+
filePath: string;
15+
} = $props();
16+
17+
let markdownUnloadCallback: (() => void) | undefined = undefined;
18+
19+
onDestroy(() => {
20+
markdownUnloadCallback?.();
21+
});
22+
23+
async function render(v: string): Promise<void> {
24+
markdownUnloadCallback?.();
25+
markdownUnloadCallback = await plugin.internal.renderMarkdown(v, element, filePath);
26+
}
27+
28+
$effect(() => void render(value));
29+
</script>
30+
31+
<div bind:this={element}></div>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
diff --git a/package.json b/package.json
2-
index 37e2ad881a5be0defa8450c06fa4e0641b03e401..6783875d8401917d170f62237eef1e31ea850971 100644
2+
index bf5beb2451f5c4b3d842fcdc59671b9318c802d8..6d2359590800b8fd88f82796817321b46eb75640 100644
33
--- a/package.json
44
+++ b/package.json
55
@@ -22,7 +22,7 @@

0 commit comments

Comments
 (0)