anki/ts/editor/editor-toolbar/EditorToolbar.svelte
Mani 135de7f9ed
image occlusion button in note editor (#2485)
* setup mask editor in note editor
- add image on mask button click (only one time)
- show hide add button for io on notetype change
- hide field in io notetype
- icon for toggle
and replace image

* add update io notes

* Tidy up i/o notetype check and fix error

- Make it a method on editor
- Use .get(), because the setting doesn't exist on older notetypes
- Pass the bool value into the ts code, instead of the enum

* reset io page after adding

* remove adjust function & add target for mask editor

* handle browse mode & merged sidetoolbar and toptoolbar to toolbar

* fix: shape, button click in browse, dropdown menu

* add arrow to add button

* store for handling visiblity of maskeditor
- remove update  button in edit mode, implement autoupdate

* update var name

* simplify store
2023-07-27 22:45:49 +10:00

138 lines
4.2 KiB
Svelte

<!--
Copyright: Ankitects Pty Ltd and contributors
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
-->
<script context="module" lang="ts">
import type { Writable } from "svelte/store";
import { resetAllState, updateAllState } from "../../components/WithState.svelte";
import type { DefaultSlotInterface } from "../../sveltelib/dynamic-slotting";
export function updateActiveButtons(event: Event) {
updateAllState(event);
}
export function clearActiveButtons() {
resetAllState(false);
}
export interface RemoveFormat {
name: string;
key: string;
show: boolean;
active: boolean;
}
export interface EditorToolbarAPI {
toolbar: DefaultSlotInterface;
notetypeButtons: DefaultSlotInterface;
inlineButtons: DefaultSlotInterface;
blockButtons: DefaultSlotInterface;
templateButtons: DefaultSlotInterface;
removeFormats: Writable<RemoveFormat[]>;
}
/* Our dynamic components */
import AddonButtons from "./AddonButtons.svelte";
export const editorToolbar = {
AddonButtons,
};
import contextProperty from "../../sveltelib/context-property";
const key = Symbol("editorToolbar");
const [context, setContextProperty] = contextProperty<EditorToolbarAPI>(key);
export { context };
</script>
<script lang="ts">
import { createEventDispatcher } from "svelte";
import { writable } from "svelte/store";
import ButtonToolbar from "../../components/ButtonToolbar.svelte";
import DynamicallySlottable from "../../components/DynamicallySlottable.svelte";
import Item from "../../components/Item.svelte";
import BlockButtons from "./BlockButtons.svelte";
import ImageOcclusionButton from "./ImageOcclusionButton.svelte";
import InlineButtons from "./InlineButtons.svelte";
import NotetypeButtons from "./NotetypeButtons.svelte";
import OptionsButtons from "./OptionsButtons.svelte";
import RichTextClozeButtons from "./RichTextClozeButtons.svelte";
import TemplateButtons from "./TemplateButtons.svelte";
export let size: number;
export let wrap: boolean;
const toolbar = {} as DefaultSlotInterface;
const notetypeButtons = {} as DefaultSlotInterface;
const optionsButtons = {} as DefaultSlotInterface;
const inlineButtons = {} as DefaultSlotInterface;
const blockButtons = {} as DefaultSlotInterface;
const templateButtons = {} as DefaultSlotInterface;
const removeFormats = writable<RemoveFormat[]>([]);
let apiPartial: Partial<EditorToolbarAPI> = {};
export { apiPartial as api };
const api: EditorToolbarAPI = Object.assign(apiPartial, {
toolbar,
notetypeButtons,
inlineButtons,
blockButtons,
templateButtons,
removeFormats,
} as EditorToolbarAPI);
setContextProperty(api);
const dispatch = createEventDispatcher();
let clientHeight: number;
$: dispatch("heightChange", { height: clientHeight });
</script>
<div class="editor-toolbar" bind:clientHeight>
<ButtonToolbar {size} {wrap}>
<DynamicallySlottable slotHost={Item} api={toolbar}>
<Item id="notetype">
<NotetypeButtons api={notetypeButtons}>
<slot name="notetypeButtons" />
</NotetypeButtons>
</Item>
<Item id="settings">
<OptionsButtons api={optionsButtons} />
</Item>
<Item id="inlineFormatting">
<InlineButtons api={inlineButtons} />
</Item>
<Item id="blockFormatting">
<BlockButtons api={blockButtons} />
</Item>
<Item id="template">
<TemplateButtons api={templateButtons} />
</Item>
<Item id="cloze">
<RichTextClozeButtons />
</Item>
<Item id="image-occlusion-button">
<ImageOcclusionButton />
</Item>
</DynamicallySlottable>
</ButtonToolbar>
</div>
<style lang="scss">
.editor-toolbar {
padding: 0 0 4px;
border-bottom: 1px solid var(--border);
}
</style>