mirror of
https://github.com/ankitects/anki.git
synced 2025-09-19 22:42:25 -04:00
Pass button groups as actual button groups, not arrays
This commit is contained in:
parent
d3e1bfa841
commit
86c57d5b75
7 changed files with 66 additions and 23 deletions
7
ts/editor-toolbar/ButtonGroup.d.ts
vendored
Normal file
7
ts/editor-toolbar/ButtonGroup.d.ts
vendored
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import type { Buttons } from "./types";
|
||||||
|
|
||||||
|
export interface ButtonGroupProps {
|
||||||
|
id: string;
|
||||||
|
className?: string;
|
||||||
|
buttons: Buttons;
|
||||||
|
}
|
|
@ -58,7 +58,7 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<div style={`--toolbar-size: ${size}px; --toolbar-wrap: ${wraps ? "wrap" : "nowrap"}`}>
|
<div style={`--toolbar-size: ${size}px; --toolbar-wrap: ${wraps ? 'wrap' : 'nowrap'}`}>
|
||||||
<div>
|
<div>
|
||||||
{#each _menus as menu}
|
{#each _menus as menu}
|
||||||
<svelte:component this={menu.component} {...menu} />
|
<svelte:component this={menu.component} {...menu} />
|
||||||
|
|
|
@ -2,6 +2,8 @@ import IconButton from "./IconButton.svelte";
|
||||||
import type { IconButtonProps } from "./IconButton";
|
import type { IconButtonProps } from "./IconButton";
|
||||||
import ColorPicker from "./ColorPicker.svelte";
|
import ColorPicker from "./ColorPicker.svelte";
|
||||||
import type { ColorPickerProps } from "./ColorPicker";
|
import type { ColorPickerProps } from "./ColorPicker";
|
||||||
|
import ButtonGroup from "./ButtonGroup.svelte";
|
||||||
|
import type { ButtonGroupProps } from "./ButtonGroup";
|
||||||
|
|
||||||
import { dynamicComponent } from "sveltelib/dynamicComponent";
|
import { dynamicComponent } from "sveltelib/dynamicComponent";
|
||||||
import * as tr from "anki/i18n";
|
import * as tr from "anki/i18n";
|
||||||
|
@ -47,4 +49,11 @@ const colorpickerButton = colorPicker<ColorPickerProps, "tooltip">(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const colorButtons = [forecolorButton, colorpickerButton];
|
const buttonGroup = dynamicComponent(ButtonGroup);
|
||||||
|
export const colorGroup = buttonGroup<ButtonGroupProps>(
|
||||||
|
{
|
||||||
|
id: "color",
|
||||||
|
buttons: [forecolorButton, colorpickerButton],
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import CommandIconButton from "./CommandIconButton.svelte";
|
import CommandIconButton from "./CommandIconButton.svelte";
|
||||||
import type { CommandIconButtonProps } from "./CommandIconButton";
|
import type { CommandIconButtonProps } from "./CommandIconButton";
|
||||||
|
import ButtonGroup from "./ButtonGroup.svelte";
|
||||||
|
import type { ButtonGroupProps } from "./ButtonGroup";
|
||||||
|
|
||||||
import { dynamicComponent } from "sveltelib/dynamicComponent";
|
import { dynamicComponent } from "sveltelib/dynamicComponent";
|
||||||
import * as tr from "anki/i18n";
|
import * as tr from "anki/i18n";
|
||||||
|
@ -74,11 +76,18 @@ const removeFormatButton = commandIconButton<CommandIconButtonProps, "tooltip">(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const formatButtons = [
|
const buttonGroup = dynamicComponent(ButtonGroup);
|
||||||
boldButton,
|
export const formatGroup = buttonGroup<ButtonGroupProps>(
|
||||||
italicButton,
|
{
|
||||||
underlineButton,
|
id: "color",
|
||||||
superscriptButton,
|
buttons: [
|
||||||
subscriptButton,
|
boldButton,
|
||||||
removeFormatButton,
|
italicButton,
|
||||||
];
|
underlineButton,
|
||||||
|
superscriptButton,
|
||||||
|
subscriptButton,
|
||||||
|
removeFormatButton,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
|
@ -6,16 +6,16 @@ import EditorToolbarSvelte from "./EditorToolbar.svelte";
|
||||||
import { checkNightMode } from "anki/nightmode";
|
import { checkNightMode } from "anki/nightmode";
|
||||||
import { setupI18n, ModuleName } from "anki/i18n";
|
import { setupI18n, ModuleName } from "anki/i18n";
|
||||||
|
|
||||||
import { notetypeButtons } from "./notetype";
|
import { notetypeGroup } from "./notetype";
|
||||||
import { formatButtons } from "./format";
|
import { formatGroup } from "./format";
|
||||||
import { colorButtons } from "./color";
|
import { colorGroup } from "./color";
|
||||||
import { templateButtons, templateMenus } from "./template";
|
import { templateGroup, templateMenus } from "./template";
|
||||||
|
|
||||||
// @ts-expect-error
|
// @ts-expect-error
|
||||||
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
|
export { updateActiveButtons, clearActiveButtons } from "./CommandIconButton.svelte";
|
||||||
export { enableButtons, disableButtons } from "./EditorToolbar.svelte";
|
export { enableButtons, disableButtons } from "./EditorToolbar.svelte";
|
||||||
|
|
||||||
const defaultButtons = [notetypeButtons, formatButtons, colorButtons, templateButtons];
|
const defaultButtons = [notetypeGroup, formatGroup, colorGroup, templateGroup];
|
||||||
const defaultMenus = [...templateMenus];
|
const defaultMenus = [...templateMenus];
|
||||||
|
|
||||||
class EditorToolbar extends HTMLElement {
|
class EditorToolbar extends HTMLElement {
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import LabelButton from "./LabelButton.svelte";
|
import LabelButton from "./LabelButton.svelte";
|
||||||
import type { LabelButtonProps } from "./LabelButton";
|
import type { LabelButtonProps } from "./LabelButton";
|
||||||
|
import ButtonGroup from "./ButtonGroup.svelte";
|
||||||
|
import type { ButtonGroupProps } from "./ButtonGroup";
|
||||||
|
|
||||||
import { dynamicComponent } from "sveltelib/dynamicComponent";
|
import { dynamicComponent } from "sveltelib/dynamicComponent";
|
||||||
import { bridgeCommand } from "anki/bridgecommand";
|
import { bridgeCommand } from "anki/bridgecommand";
|
||||||
|
@ -28,4 +30,11 @@ const cardsButton = labelButton<LabelButtonProps, "label" | "tooltip">(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const notetypeButtons = [fieldsButton, cardsButton];
|
const buttonGroup = dynamicComponent(ButtonGroup);
|
||||||
|
export const notetypeGroup = buttonGroup<ButtonGroupProps>(
|
||||||
|
{
|
||||||
|
id: "notetype",
|
||||||
|
buttons: [fieldsButton, cardsButton],
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
|
@ -6,6 +6,8 @@ import DropdownItem from "./DropdownItem.svelte";
|
||||||
import type { DropdownItemProps } from "./DropdownItem";
|
import type { DropdownItemProps } from "./DropdownItem";
|
||||||
import WithDropdownMenu from "./WithDropdownMenu.svelte";
|
import WithDropdownMenu from "./WithDropdownMenu.svelte";
|
||||||
import type { WithDropdownMenuProps } from "./WithDropdownMenu";
|
import type { WithDropdownMenuProps } from "./WithDropdownMenu";
|
||||||
|
import ButtonGroup from "./ButtonGroup.svelte";
|
||||||
|
import type { ButtonGroupProps } from "./ButtonGroup";
|
||||||
|
|
||||||
import { bridgeCommand } from "anki/bridgecommand";
|
import { bridgeCommand } from "anki/bridgecommand";
|
||||||
import { dynamicComponent } from "sveltelib/dynamicComponent";
|
import { dynamicComponent } from "sveltelib/dynamicComponent";
|
||||||
|
@ -126,12 +128,19 @@ const htmlButton = iconButton<IconButtonProps, "tooltip">(
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export const templateButtons = [
|
const buttonGroup = dynamicComponent(ButtonGroup);
|
||||||
attachmentButton,
|
export const templateGroup = buttonGroup<ButtonGroupProps>(
|
||||||
recordButton,
|
{
|
||||||
clozeButton,
|
id: "template",
|
||||||
mathjaxButtonWithMenu,
|
buttons: [
|
||||||
htmlButton,
|
attachmentButton,
|
||||||
];
|
recordButton,
|
||||||
|
clozeButton,
|
||||||
|
mathjaxButtonWithMenu,
|
||||||
|
htmlButton,
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{}
|
||||||
|
);
|
||||||
|
|
||||||
export const templateMenus = [mathjaxMenu];
|
export const templateMenus = [mathjaxMenu];
|
||||||
|
|
Loading…
Reference in a new issue