mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 14:32:22 -04:00
Add lefttopbtns as AddonButtons
This commit is contained in:
parent
928f486867
commit
c9368ed98f
9 changed files with 47 additions and 36 deletions
|
@ -145,7 +145,7 @@ class Editor:
|
||||||
gui_hooks.editor_did_init_left_buttons(lefttopbtns, self)
|
gui_hooks.editor_did_init_left_buttons(lefttopbtns, self)
|
||||||
|
|
||||||
lefttopbtns_defs = [
|
lefttopbtns_defs = [
|
||||||
f"$editorToolbar.then(({{ notetypeButtons }}) => notetypeButtons.addButton({{ component: editorToolbar.Raw, props: {{ html: `{button}` }} }}, -1));"
|
f"$editorToolbar.then(({{ notetypeButtons }}) => notetypeButtons.appendButton({{ component: editorToolbar.Raw, props: {{ html: `{button}` }} }}, -1));"
|
||||||
for button in lefttopbtns
|
for button in lefttopbtns
|
||||||
]
|
]
|
||||||
lefttopbtns_js = "\n".join(lefttopbtns_defs)
|
lefttopbtns_js = "\n".join(lefttopbtns_defs)
|
||||||
|
@ -155,21 +155,21 @@ class Editor:
|
||||||
# legacy filter
|
# legacy filter
|
||||||
righttopbtns = runFilter("setupEditorButtons", righttopbtns, self)
|
righttopbtns = runFilter("setupEditorButtons", righttopbtns, self)
|
||||||
|
|
||||||
righttopbtns_defs = "\n".join(
|
righttopbtns_defs = ", ".join([f"`{button}`" for button in righttopbtns])
|
||||||
[f"editorToolbar.Raw({{ html: `{button}` }})," for button in righttopbtns]
|
|
||||||
)
|
|
||||||
righttopbtns_js = (
|
righttopbtns_js = (
|
||||||
f"""
|
f"""
|
||||||
$editorToolbar.then(({{ addButton }}) => addButton(editorToolbar.buttonGroup({{
|
$editorToolbar.then(({{ toolbar }}) => toolbar.appendGroup({{
|
||||||
id: "addons",
|
component: editorToolbar.AddonButtons,
|
||||||
items: [ {righttopbtns_defs} ]
|
id: "addons",
|
||||||
}}), -1));
|
props: {{ buttons: [ {righttopbtns_defs} ] }},
|
||||||
|
}}));
|
||||||
"""
|
"""
|
||||||
if righttopbtns_defs
|
if len(righttopbtns) > 0
|
||||||
else ""
|
else ""
|
||||||
)
|
)
|
||||||
|
|
||||||
self.web.eval(f"{lefttopbtns_js}")
|
print(righttopbtns_js)
|
||||||
|
self.web.eval(f"{lefttopbtns_js} {righttopbtns_js}")
|
||||||
|
|
||||||
# Top buttons
|
# Top buttons
|
||||||
######################################################################
|
######################################################################
|
||||||
|
|
|
@ -38,10 +38,10 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
buttonToolbarRef
|
buttonToolbarRef
|
||||||
);
|
);
|
||||||
|
|
||||||
const insertGroup = (button: SvelteComponent, position: Identifier = 0) =>
|
const insertGroup = (group: SvelteComponent, position: Identifier = 0) =>
|
||||||
addComponent(button, (added, parent) => insert(added, parent, position));
|
addComponent(group, (added, parent) => insert(added, parent, position));
|
||||||
const appendGroup = (button: SvelteComponent, position: Identifier = -1) =>
|
const appendGroup = (group: SvelteComponent, position: Identifier = -1) =>
|
||||||
addComponent(button, (added, parent) => add(added, parent, position));
|
addComponent(group, (added, parent) => add(added, parent, position));
|
||||||
|
|
||||||
const showGroup = (id: Identifier) =>
|
const showGroup = (id: Identifier) =>
|
||||||
updateRegistration(({ detach }) => detach.set(false), id);
|
updateRegistration(({ detach }) => detach.set(false), id);
|
||||||
|
|
|
@ -34,12 +34,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
|
||||||
button {
|
button {
|
||||||
padding: 0;
|
padding: 0;
|
||||||
|
@include button.btn-border-radius;
|
||||||
border-top-left-radius: var(--border-left-radius);
|
|
||||||
border-bottom-left-radius: var(--border-left-radius);
|
|
||||||
|
|
||||||
border-top-right-radius: var(--border-right-radius);
|
|
||||||
border-bottom-right-radius: var(--border-right-radius);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@include button.btn-day;
|
@include button.btn-day;
|
||||||
|
|
|
@ -37,11 +37,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
width: auto;
|
width: auto;
|
||||||
height: var(--toolbar-size);
|
height: var(--toolbar-size);
|
||||||
|
|
||||||
border-top-left-radius: var(--border-left-radius);
|
@include button.btn-border-radius;
|
||||||
border-bottom-left-radius: var(--border-left-radius);
|
|
||||||
|
|
||||||
border-top-right-radius: var(--border-right-radius);
|
|
||||||
border-bottom-right-radius: var(--border-right-radius);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@include button.btn-day;
|
@include button.btn-day;
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
<!--
|
|
||||||
Copyright: Ankitects Pty Ltd and contributors
|
|
||||||
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
|
||||||
-->
|
|
||||||
<script lang="typescript">
|
|
||||||
export let html: string;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
{@html html}
|
|
18
ts/editor/AddonButtons.svelte
Normal file
18
ts/editor/AddonButtons.svelte
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
<!--
|
||||||
|
Copyright: Ankitects Pty Ltd and contributors
|
||||||
|
License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
|
-->
|
||||||
|
<script lang="typescript">
|
||||||
|
import ButtonGroup from "components/ButtonGroup.svelte";
|
||||||
|
import ButtonGroupItem from "components/ButtonGroupItem.svelte";
|
||||||
|
|
||||||
|
export let buttons: string[];
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<ButtonGroup>
|
||||||
|
{#each buttons as button}
|
||||||
|
<ButtonGroupItem>
|
||||||
|
{@html button}
|
||||||
|
</ButtonGroupItem>
|
||||||
|
{/each}
|
||||||
|
</ButtonGroup>
|
|
@ -28,16 +28,16 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Export components */
|
/* Export components */
|
||||||
|
import AddonButtons from "./AddonButtons.svelte";
|
||||||
import PreviewButton from "./PreviewButton.svelte";
|
import PreviewButton from "./PreviewButton.svelte";
|
||||||
import LabelButton from "components/LabelButton.svelte";
|
import LabelButton from "components/LabelButton.svelte";
|
||||||
import IconButton from "components/IconButton.svelte";
|
import IconButton from "components/IconButton.svelte";
|
||||||
import Raw from "components/Raw.svelte";
|
|
||||||
|
|
||||||
export const editorToolbar = {
|
export const editorToolbar = {
|
||||||
|
AddonButtons,
|
||||||
PreviewButton,
|
PreviewButton,
|
||||||
LabelButton,
|
LabelButton,
|
||||||
IconButton,
|
IconButton,
|
||||||
Raw,
|
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
|
@use "ts/sass/button_mixins" as button;
|
||||||
|
|
||||||
.linkb {
|
.linkb {
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
|
@include button.btn-border-radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
.topbut {
|
.topbut {
|
||||||
|
|
|
@ -1,6 +1,14 @@
|
||||||
@import "ts/sass/bootstrap/functions";
|
@import "ts/sass/bootstrap/functions";
|
||||||
@import "ts/sass/bootstrap/variables";
|
@import "ts/sass/bootstrap/variables";
|
||||||
|
|
||||||
|
@mixin btn-border-radius {
|
||||||
|
border-top-left-radius: var(--border-left-radius);
|
||||||
|
border-bottom-left-radius: var(--border-left-radius);
|
||||||
|
|
||||||
|
border-top-right-radius: var(--border-right-radius);
|
||||||
|
border-bottom-right-radius: var(--border-right-radius);
|
||||||
|
}
|
||||||
|
|
||||||
$btn-base-color-day: white;
|
$btn-base-color-day: white;
|
||||||
|
|
||||||
@mixin btn-day-base {
|
@mixin btn-day-base {
|
||||||
|
|
Loading…
Reference in a new issue