mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 14:02:21 -04:00
Add EditorField export (#1915)
- This is useful when you want to set up hooks, etc. on the EditorField component - Because when you can only use the NoteEditor export, you cannot notice when fields are mounted or destroyed
This commit is contained in:
parent
05adb50153
commit
336ad05693
3 changed files with 16 additions and 2 deletions
|
@ -5,7 +5,6 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
<script context="module" lang="ts">
|
||||
import type { Readable } from "svelte/store";
|
||||
|
||||
import contextProperty from "../sveltelib/context-property";
|
||||
import type { EditingAreaAPI } from "./EditingArea.svelte";
|
||||
|
||||
export interface FieldData {
|
||||
|
@ -22,10 +21,22 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
editingArea: EditingAreaAPI;
|
||||
}
|
||||
|
||||
import { registerPackage } from "../lib/runtime-require";
|
||||
import contextProperty from "../sveltelib/context-property";
|
||||
import lifecycleHooks from "../sveltelib/lifecycle-hooks";
|
||||
|
||||
const key = Symbol("editorField");
|
||||
const [context, setContextProperty] = contextProperty<EditorFieldAPI>(key);
|
||||
const [lifecycle, instances, setupLifecycleHooks] =
|
||||
lifecycleHooks<EditorFieldAPI>();
|
||||
|
||||
export { context };
|
||||
|
||||
registerPackage("anki/EditorField", {
|
||||
context,
|
||||
lifecycle,
|
||||
instances,
|
||||
});
|
||||
</script>
|
||||
|
||||
<script lang="ts">
|
||||
|
@ -67,6 +78,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|||
});
|
||||
|
||||
setContextProperty(api);
|
||||
setupLifecycleHooks(api);
|
||||
|
||||
onDestroy(() => api?.destroy());
|
||||
</script>
|
||||
|
|
|
@ -13,6 +13,7 @@ html {
|
|||
overflow: hidden;
|
||||
}
|
||||
|
||||
html, body {
|
||||
html,
|
||||
body {
|
||||
height: 100%;
|
||||
}
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
type AnkiPackages =
|
||||
| "anki/NoteEditor"
|
||||
| "anki/EditorField"
|
||||
| "anki/PlainTextInput"
|
||||
| "anki/TemplateButtons"
|
||||
| "anki/packages"
|
||||
|
|
Loading…
Reference in a new issue