2021-04-15 15:59:52 +02:00
|
|
|
<!--
|
|
|
|
Copyright: Ankitects Pty Ltd and contributors
|
|
|
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
|
|
-->
|
2021-04-07 23:53:09 +02:00
|
|
|
<script context="module" lang="typescript">
|
2021-04-09 20:55:49 +02:00
|
|
|
import "./legacy.css";
|
2021-04-07 23:53:09 +02:00
|
|
|
import { writable } from "svelte/store";
|
|
|
|
|
|
|
|
const disabled = writable(false);
|
|
|
|
|
|
|
|
export function enableButtons(): void {
|
|
|
|
disabled.set(false);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function disableButtons(): void {
|
|
|
|
disabled.set(true);
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2021-03-25 23:32:23 +01:00
|
|
|
<script lang="typescript">
|
2021-04-25 19:15:00 +02:00
|
|
|
import type { Identifier } from "./identifiable";
|
2021-04-23 18:53:52 +02:00
|
|
|
import type { ToolbarItem, IterableToolbarItem } from "./types";
|
2021-04-25 19:15:00 +02:00
|
|
|
|
2021-03-30 06:14:00 +02:00
|
|
|
import { setContext } from "svelte";
|
|
|
|
import { disabledKey, nightModeKey } from "./contextKeys";
|
2021-04-25 19:15:00 +02:00
|
|
|
import { add, insert, updateRecursive } from "./identifiable";
|
|
|
|
import { showComponent, hideComponent, toggleComponent } from "./hideable";
|
2021-03-30 06:14:00 +02:00
|
|
|
|
2021-03-29 21:48:31 +02:00
|
|
|
import ButtonGroup from "./ButtonGroup.svelte";
|
2021-03-25 23:32:23 +01:00
|
|
|
|
2021-04-25 19:15:00 +02:00
|
|
|
export let buttons: IterableToolbarItem[];
|
|
|
|
export let menus: ToolbarItem[];
|
2021-03-25 23:32:23 +01:00
|
|
|
export let nightMode: boolean;
|
|
|
|
|
2021-03-30 06:14:00 +02:00
|
|
|
setContext(nightModeKey, nightMode);
|
2021-03-31 03:34:08 +02:00
|
|
|
setContext(disabledKey, disabled);
|
2021-04-08 23:25:13 +02:00
|
|
|
|
|
|
|
export let size: number = 30;
|
|
|
|
export let wraps: boolean = true;
|
|
|
|
|
|
|
|
$: style = `--toolbar-size: ${size}px; --toolbar-wrap: ${
|
|
|
|
wraps ? "wrap" : "nowrap"
|
|
|
|
}`;
|
2021-04-25 19:15:00 +02:00
|
|
|
|
|
|
|
export function updateButton(
|
|
|
|
update: (component: ToolbarItem) => ToolbarItem,
|
|
|
|
...identifiers: Identifier[]
|
|
|
|
): void {
|
|
|
|
buttons = updateRecursive(
|
|
|
|
update,
|
|
|
|
({ items: buttons } as unknown) as ToolbarItem,
|
|
|
|
...identifiers
|
|
|
|
).items as IterableToolbarItem[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function showButton(...identifiers: Identifier[]): void {
|
|
|
|
updateButton(showComponent, ...identifiers);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function hideButton(...identifiers: Identifier[]): void {
|
|
|
|
updateButton(hideComponent, ...identifiers);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function toggleButton(...identifiers: Identifier[]): void {
|
|
|
|
updateButton(toggleComponent, ...identifiers);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function insertButton(
|
|
|
|
newButton: ToolbarItem,
|
|
|
|
...identifiers: Identifier[]
|
|
|
|
): void {
|
|
|
|
const initIdentifiers = identifiers.slice(0, -1);
|
|
|
|
const lastIdentifier = identifiers[identifiers.length - 1];
|
|
|
|
updateButton(
|
|
|
|
(component: ToolbarItem) =>
|
|
|
|
insert(component as IterableToolbarItem, newButton, lastIdentifier),
|
|
|
|
|
|
|
|
...initIdentifiers
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addButton(
|
|
|
|
newButton: ToolbarItem,
|
|
|
|
...identifiers: Identifier[]
|
|
|
|
): void {
|
|
|
|
const initIdentifiers = identifiers.slice(0, -1);
|
|
|
|
const lastIdentifier = identifiers[identifiers.length - 1];
|
|
|
|
updateButton(
|
|
|
|
(component: ToolbarItem) =>
|
|
|
|
add(component as IterableToolbarItem, newButton, lastIdentifier),
|
|
|
|
...initIdentifiers
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function updateMenu(
|
|
|
|
update: (component: ToolbarItem) => ToolbarItem,
|
|
|
|
...identifiers: Identifier[]
|
|
|
|
): void {
|
|
|
|
menus = updateRecursive(
|
|
|
|
update,
|
|
|
|
({ items: menus } as unknown) as ToolbarItem,
|
|
|
|
...identifiers
|
|
|
|
).items as ToolbarItem[];
|
|
|
|
}
|
|
|
|
|
|
|
|
export function addMenu(newMenu: ToolbarItem, ...identifiers: Identifier[]): void {
|
|
|
|
const initIdentifiers = identifiers.slice(0, -1);
|
|
|
|
const lastIdentifier = identifiers[identifiers.length - 1];
|
|
|
|
updateMenu(
|
|
|
|
(component: ToolbarItem) =>
|
|
|
|
add(component as IterableToolbarItem, newMenu, lastIdentifier),
|
|
|
|
...initIdentifiers
|
|
|
|
);
|
|
|
|
}
|
2021-03-25 21:11:40 +01:00
|
|
|
</script>
|
|
|
|
|
2021-03-30 00:51:44 +02:00
|
|
|
<style lang="scss">
|
2021-03-30 15:56:54 +02:00
|
|
|
nav {
|
2021-03-30 00:51:44 +02:00
|
|
|
position: sticky;
|
|
|
|
top: 0;
|
|
|
|
left: 0;
|
2021-03-30 03:11:51 +02:00
|
|
|
z-index: 10;
|
2021-03-30 00:51:44 +02:00
|
|
|
|
2021-04-27 17:20:13 +02:00
|
|
|
background-color: var(--window-bg);
|
2021-03-30 01:23:39 +02:00
|
|
|
border-bottom: 1px solid var(--border);
|
2021-03-30 00:51:44 +02:00
|
|
|
}
|
|
|
|
</style>
|
|
|
|
|
2021-04-27 17:20:13 +02:00
|
|
|
<nav {style}>
|
2021-04-25 19:15:00 +02:00
|
|
|
{#each menus as menu}
|
2021-04-08 23:25:13 +02:00
|
|
|
<svelte:component this={menu.component} {...menu} />
|
|
|
|
{/each}
|
|
|
|
|
2021-04-25 19:15:00 +02:00
|
|
|
<ButtonGroup items={buttons} className="p-0 mb-1" />
|
2021-04-08 23:25:13 +02:00
|
|
|
</nav>
|