2021-04-20 15:43:59 +02:00
|
|
|
// Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
2021-04-25 18:25:03 +02:00
|
|
|
|
2021-05-06 23:33:28 +02:00
|
|
|
/* eslint
|
|
|
|
@typescript-eslint/no-non-null-assertion: "off",
|
2021-05-06 23:42:25 +02:00
|
|
|
@typescript-eslint/no-explicit-any: "off",
|
2021-05-06 23:33:28 +02:00
|
|
|
*/
|
|
|
|
|
2021-05-06 23:04:38 +02:00
|
|
|
import { disabledKey, nightModeKey } from "components/contextKeys";
|
|
|
|
import { writable } from "svelte/store";
|
|
|
|
|
2021-04-27 23:08:47 +02:00
|
|
|
import EditorToolbar from "./EditorToolbar.svelte";
|
|
|
|
import "./bootstrap.css";
|
2021-04-20 15:32:02 +02:00
|
|
|
|
2021-05-06 23:04:38 +02:00
|
|
|
const disabled = writable(false);
|
|
|
|
|
2021-04-27 23:08:47 +02:00
|
|
|
export function initToolbar(i18n: Promise<void>): Promise<EditorToolbar> {
|
2021-04-25 19:15:00 +02:00
|
|
|
let toolbarResolve: (value: EditorToolbar) => void;
|
|
|
|
const toolbarPromise = new Promise<EditorToolbar>((resolve) => {
|
2021-04-25 18:25:03 +02:00
|
|
|
toolbarResolve = resolve;
|
|
|
|
});
|
|
|
|
|
2021-04-20 15:32:02 +02:00
|
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
|
|
i18n.then(() => {
|
2021-04-27 17:20:13 +02:00
|
|
|
const target = document.body;
|
|
|
|
const anchor = document.getElementById("fields")!;
|
2021-04-25 18:25:03 +02:00
|
|
|
|
2021-05-06 23:04:38 +02:00
|
|
|
const context = new Map();
|
|
|
|
context.set(disabledKey, disabled);
|
|
|
|
context.set(
|
|
|
|
nightModeKey,
|
|
|
|
document.documentElement.classList.contains("night-mode")
|
2021-04-27 23:08:47 +02:00
|
|
|
);
|
2021-05-06 23:04:38 +02:00
|
|
|
|
2021-05-06 23:42:25 +02:00
|
|
|
toolbarResolve(new EditorToolbar({ target, anchor, context } as any));
|
2021-04-20 15:32:02 +02:00
|
|
|
});
|
|
|
|
});
|
2021-04-25 18:25:03 +02:00
|
|
|
|
|
|
|
return toolbarPromise;
|
2021-04-20 15:32:02 +02:00
|
|
|
}
|
2021-04-27 23:08:47 +02:00
|
|
|
|
2021-05-06 23:04:38 +02:00
|
|
|
export function enableButtons(): void {
|
|
|
|
disabled.set(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function disableButtons(): void {
|
|
|
|
disabled.set(true);
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:32:12 +02:00
|
|
|
export {
|
|
|
|
updateActiveButtons,
|
|
|
|
clearActiveButtons,
|
2021-05-06 23:04:38 +02:00
|
|
|
editorToolbar,
|
2021-04-28 22:32:12 +02:00
|
|
|
} from "./EditorToolbar.svelte";
|