mirror of
https://github.com/ankitects/anki.git
synced 2025-09-25 01:06:35 -04:00
Add titles to buttons with lazyProperties
This commit is contained in:
parent
4e6d5d9adb
commit
216b93c060
12 changed files with 126 additions and 34 deletions
|
@ -2,6 +2,7 @@
|
||||||
export let id = "";
|
export let id = "";
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let props: Record<string, string> = {};
|
export let props: Record<string, string> = {};
|
||||||
|
export let title: string;
|
||||||
|
|
||||||
export let onChange: (event: ChangeEvent) => void;
|
export let onChange: (event: ChangeEvent) => void;
|
||||||
</script>
|
</script>
|
||||||
|
@ -41,6 +42,12 @@
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<button tabindex="-1" {id} class={className} {...props} on:mousedown|preventDefault>
|
<button
|
||||||
|
tabindex="-1"
|
||||||
|
{id}
|
||||||
|
class={className}
|
||||||
|
{...props}
|
||||||
|
{title}
|
||||||
|
on:mousedown|preventDefault>
|
||||||
<span> <input type="color" on:change={onChange} /> </span>
|
<span> <input type="color" on:change={onChange} /> </span>
|
||||||
</button>
|
</button>
|
||||||
|
|
|
@ -39,6 +39,7 @@
|
||||||
export let id = "";
|
export let id = "";
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let props: Record<string, string> = {};
|
export let props: Record<string, string> = {};
|
||||||
|
export let title: string;
|
||||||
|
|
||||||
export let icon = "";
|
export let icon = "";
|
||||||
export let command: string;
|
export let command: string;
|
||||||
|
@ -60,6 +61,6 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SquareButton {id} {className} {props} {active} {onClick} on:mount>
|
<SquareButton {id} {className} {props} {title} {active} {onClick} on:mount>
|
||||||
{@html icon}
|
{@html icon}
|
||||||
</SquareButton>
|
</SquareButton>
|
||||||
|
|
22
ts/editor-toolbar/DropdownItem.svelte
Normal file
22
ts/editor-toolbar/DropdownItem.svelte
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
<script lang="typescript">
|
||||||
|
export let id = "";
|
||||||
|
export let className = "";
|
||||||
|
export let props: Record<string, string> = {};
|
||||||
|
export let title: string;
|
||||||
|
|
||||||
|
export let onClick: (event: ClickEvent) => void;
|
||||||
|
export let label: string;
|
||||||
|
export let endLabel: string;
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<button
|
||||||
|
{id}
|
||||||
|
class={`dropdown-item ${className}`}
|
||||||
|
{...props}
|
||||||
|
{title}
|
||||||
|
on:click={onClick}
|
||||||
|
on:mousedown|preventDefault>
|
||||||
|
<span class="float-start">{label}</span>
|
||||||
|
|
||||||
|
{#if endLabel}<span class="float-end">{endLabel}</span>{/if}
|
||||||
|
</button>
|
|
@ -1,26 +1,14 @@
|
||||||
<script lang="typescript">
|
<script lang="typescript">
|
||||||
interface DropdownItem {
|
import type { SvelteComponentDefinition } from "./types";
|
||||||
label: string;
|
|
||||||
endLabel: string;
|
|
||||||
onClick: (event: ClickEvent) => void;
|
|
||||||
}
|
|
||||||
|
|
||||||
export let id: string;
|
export let id: string;
|
||||||
export let menuItems: DropdownItem[];
|
export let menuItems: SvelteComponentDefinition[];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ul class="dropdown-menu" {id}>
|
<ul class="dropdown-menu" {id}>
|
||||||
{#each menuItems as menuItem}
|
{#each menuItems as menuItem}
|
||||||
<li>
|
<li>
|
||||||
<button
|
<svelte:component this={menuItem.component} {...menuItem} />
|
||||||
class="dropdown-item"
|
|
||||||
on:click={menuItem.onClick}
|
|
||||||
on:mousedown|preventDefault>
|
|
||||||
<span class="float-start">{menuItem.label}</span>
|
|
||||||
{#if menuItem.endLabel}
|
|
||||||
<span class="float-end">{menuItem.endLabel}</span>
|
|
||||||
{/if}
|
|
||||||
</button>
|
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -4,11 +4,12 @@
|
||||||
export let id = "";
|
export let id = "";
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let props: Record<string, string> = {};
|
export let props: Record<string, string> = {};
|
||||||
|
export let title: string;
|
||||||
|
|
||||||
export let icon = "";
|
export let icon = "";
|
||||||
export let onClick: (event: ClickEvent) => void;
|
export let onClick: (event: ClickEvent) => void;
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<SquareButton {id} {className} {props} {onClick} on:mount>
|
<SquareButton {id} {className} {props} {title} {onClick} on:mount>
|
||||||
{@html icon}
|
{@html icon}
|
||||||
</SquareButton>
|
</SquareButton>
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
export let id = "";
|
export let id = "";
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let props: Record<string, string> = {};
|
export let props: Record<string, string> = {};
|
||||||
|
export let title: string;
|
||||||
|
|
||||||
function extendClassName(classes: string) {
|
function extendClassName(classes: string) {
|
||||||
return `form-select ${classes}`;
|
return `form-select ${classes}`;
|
||||||
|
@ -59,7 +60,8 @@
|
||||||
{disabled}
|
{disabled}
|
||||||
{id}
|
{id}
|
||||||
class={extendClassName(className)}
|
class={extendClassName(className)}
|
||||||
{...props}>
|
{...props}
|
||||||
|
{title}>
|
||||||
{#each options as option}
|
{#each options as option}
|
||||||
<SelectOption {...option} />
|
<SelectOption {...option} />
|
||||||
{/each}
|
{/each}
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
export let id = "";
|
export let id = "";
|
||||||
export let className = "";
|
export let className = "";
|
||||||
export let props: Record<string, string> = {};
|
export let props: Record<string, string> = {};
|
||||||
|
export let title: string;
|
||||||
|
|
||||||
export let onClick: (event: ClickEvent) => void;
|
export let onClick: (event: ClickEvent) => void;
|
||||||
export let active = false;
|
export let active = false;
|
||||||
|
@ -85,6 +86,7 @@
|
||||||
{id}
|
{id}
|
||||||
class={className}
|
class={className}
|
||||||
{...props}
|
{...props}
|
||||||
|
{title}
|
||||||
class:active
|
class:active
|
||||||
tabindex="-1"
|
tabindex="-1"
|
||||||
{disabled}
|
{disabled}
|
||||||
|
|
|
@ -1,5 +1,9 @@
|
||||||
import IconButton from "./IconButton.svelte";
|
import IconButton from "./IconButton.svelte";
|
||||||
import ColorPicker from "./ColorPicker.svelte";
|
import ColorPicker from "./ColorPicker.svelte";
|
||||||
|
|
||||||
|
import { lazyProperties } from "anki/lazy";
|
||||||
|
import * as tr from "anki/i18n";
|
||||||
|
|
||||||
import squareFillIcon from "./square-fill.svg";
|
import squareFillIcon from "./square-fill.svg";
|
||||||
import "./color.css";
|
import "./color.css";
|
||||||
|
|
||||||
|
@ -24,10 +28,18 @@ const forecolorButton = {
|
||||||
onClick: () => wrapWithForecolor(getForecolor()),
|
onClick: () => wrapWithForecolor(getForecolor()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(forecolorButton, {
|
||||||
|
title: tr.editingSetForegroundColourF7,
|
||||||
|
});
|
||||||
|
|
||||||
const colorpickerButton = {
|
const colorpickerButton = {
|
||||||
component: ColorPicker,
|
component: ColorPicker,
|
||||||
className: "rainbow",
|
className: "rainbow",
|
||||||
onChange: ({ currentTarget }) => setForegroundColor(currentTarget.value),
|
onChange: ({ currentTarget }) => setForegroundColor(currentTarget.value),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(colorpickerButton, {
|
||||||
|
title: tr.editingChangeColourF8,
|
||||||
|
});
|
||||||
|
|
||||||
export const colorButtons = [forecolorButton, colorpickerButton];
|
export const colorButtons = [forecolorButton, colorpickerButton];
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
// @ts-ignore
|
|
||||||
import CommandIconButton from "./CommandIconButton.svelte";
|
import CommandIconButton from "./CommandIconButton.svelte";
|
||||||
|
|
||||||
|
import { lazyProperties } from "anki/lazy";
|
||||||
|
import * as tr from "anki/i18n";
|
||||||
|
|
||||||
import boldIcon from "./type-bold.svg";
|
import boldIcon from "./type-bold.svg";
|
||||||
import italicIcon from "./type-italic.svg";
|
import italicIcon from "./type-italic.svg";
|
||||||
import underlineIcon from "./type-underline.svg";
|
import underlineIcon from "./type-underline.svg";
|
||||||
|
@ -13,42 +16,66 @@ const boldButton = {
|
||||||
command: "bold",
|
command: "bold",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(boldButton, {
|
||||||
|
title: tr.editingBoldTextCtrlandb,
|
||||||
|
});
|
||||||
|
|
||||||
const italicButton = {
|
const italicButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: italicIcon,
|
icon: italicIcon,
|
||||||
command: "italic",
|
command: "italic",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(italicButton, {
|
||||||
|
title: tr.editingItalicTextCtrlandi,
|
||||||
|
});
|
||||||
|
|
||||||
const underlineButton = {
|
const underlineButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: underlineIcon,
|
icon: underlineIcon,
|
||||||
command: "underline",
|
command: "underline",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(underlineButton, {
|
||||||
|
title: tr.editingUnderlineTextCtrlandu,
|
||||||
|
});
|
||||||
|
|
||||||
const superscriptButton = {
|
const superscriptButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: superscriptIcon,
|
icon: superscriptIcon,
|
||||||
command: "superscript",
|
command: "superscript",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(superscriptButton, {
|
||||||
|
title: tr.editingSuperscriptCtrlandand,
|
||||||
|
});
|
||||||
|
|
||||||
const subscriptButton = {
|
const subscriptButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: subscriptIcon,
|
icon: subscriptIcon,
|
||||||
command: "subscript",
|
command: "subscript",
|
||||||
};
|
};
|
||||||
|
|
||||||
const eraserButton = {
|
lazyProperties(subscriptButton, {
|
||||||
|
title: tr.editingSubscriptCtrland,
|
||||||
|
});
|
||||||
|
|
||||||
|
const removeFormatButton = {
|
||||||
component: CommandIconButton,
|
component: CommandIconButton,
|
||||||
icon: eraserIcon,
|
icon: eraserIcon,
|
||||||
command: "removeFormat",
|
command: "removeFormat",
|
||||||
highlightable: false,
|
activatable: false,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(removeFormatButton, {
|
||||||
|
title: tr.editingRemoveFormattingCtrlandr,
|
||||||
|
});
|
||||||
|
|
||||||
export const formatButtons = [
|
export const formatButtons = [
|
||||||
boldButton,
|
boldButton,
|
||||||
italicButton,
|
italicButton,
|
||||||
underlineButton,
|
underlineButton,
|
||||||
superscriptButton,
|
superscriptButton,
|
||||||
subscriptButton,
|
subscriptButton,
|
||||||
eraserButton,
|
removeFormatButton,
|
||||||
];
|
];
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
import type { SvelteComponent } from "svelte";
|
import type { SvelteComponent } from "svelte";
|
||||||
|
|
||||||
import { checkNightMode } from "anki/nightmode";
|
import { checkNightMode } from "anki/nightmode";
|
||||||
import { setupI18n, ModuleName, i18n } from "anki/i18n";
|
import { setupI18n, ModuleName } from "anki/i18n";
|
||||||
import * as tr from "anki/i18n";
|
|
||||||
|
|
||||||
import EditorToolbarSvelte from "./EditorToolbar.svelte";
|
import EditorToolbarSvelte from "./EditorToolbar.svelte";
|
||||||
|
|
||||||
|
@ -27,8 +26,6 @@ class EditorToolbar extends HTMLElement {
|
||||||
this.disabled = writable(false);
|
this.disabled = writable(false);
|
||||||
|
|
||||||
setupI18n({ modules: [ModuleName.EDITING] }).then(() => {
|
setupI18n({ modules: [ModuleName.EDITING] }).then(() => {
|
||||||
console.log(i18n, tr);
|
|
||||||
|
|
||||||
this.component = new EditorToolbarSvelte({
|
this.component = new EditorToolbarSvelte({
|
||||||
target: this,
|
target: this,
|
||||||
props: {
|
props: {
|
||||||
|
|
|
@ -1,7 +1,11 @@
|
||||||
import { bridgeCommand } from "anki/bridgecommand";
|
|
||||||
|
|
||||||
import IconButton from "./IconButton.svelte";
|
import IconButton from "./IconButton.svelte";
|
||||||
import DropdownMenu from "./DropdownMenu.svelte";
|
import DropdownMenu from "./DropdownMenu.svelte";
|
||||||
|
import DropdownItem from "./DropdownItem.svelte";
|
||||||
|
import WithDropdownMenu from "./WithDropdownMenu.svelte";
|
||||||
|
|
||||||
|
import { bridgeCommand } from "anki/bridgecommand";
|
||||||
|
import { lazyProperties } from "anki/lazy";
|
||||||
|
import * as tr from "anki/i18n";
|
||||||
|
|
||||||
import paperclipIcon from "./paperclip.svg";
|
import paperclipIcon from "./paperclip.svg";
|
||||||
import micIcon from "./mic.svg";
|
import micIcon from "./mic.svg";
|
||||||
|
@ -31,23 +35,45 @@ const attachmentButton = {
|
||||||
onClick: onAttachment,
|
onClick: onAttachment,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(attachmentButton, {
|
||||||
|
title: tr.editingAttachPicturesaudiovideoF3,
|
||||||
|
});
|
||||||
|
|
||||||
const recordButton = { component: IconButton, icon: micIcon, onClick: onRecord };
|
const recordButton = { component: IconButton, icon: micIcon, onClick: onRecord };
|
||||||
|
|
||||||
|
lazyProperties(recordButton, {
|
||||||
|
title: tr.editingRecordAudioF5,
|
||||||
|
});
|
||||||
|
|
||||||
const clozeButton = {
|
const clozeButton = {
|
||||||
component: IconButton,
|
component: IconButton,
|
||||||
icon: bracketsIcon,
|
icon: bracketsIcon,
|
||||||
onClick: onCloze,
|
onClick: onCloze,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(clozeButton, {
|
||||||
|
title: tr.editingClozeDeletionCtrlandshiftandc,
|
||||||
|
});
|
||||||
|
|
||||||
const mathjaxButton = {
|
const mathjaxButton = {
|
||||||
component: IconButton,
|
component: IconButton,
|
||||||
icon: functionIcon,
|
icon: functionIcon,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const mathjaxMenuId = "mathjaxMenu";
|
||||||
|
|
||||||
const mathjaxMenu = {
|
const mathjaxMenu = {
|
||||||
component: DropdownMenu,
|
component: DropdownMenu,
|
||||||
id: "mathjaxMenu",
|
id: mathjaxMenuId,
|
||||||
menuItems: [{ label: "Foo", onClick: () => console.log("foo") }],
|
menuItems: [
|
||||||
|
{ component: DropdownItem, label: "Foo", onClick: () => console.log("foo") },
|
||||||
|
],
|
||||||
|
};
|
||||||
|
|
||||||
|
const mathjaxButtonWithMenu = {
|
||||||
|
component: WithDropdownMenu,
|
||||||
|
button: mathjaxButton,
|
||||||
|
menuId: mathjaxMenuId,
|
||||||
};
|
};
|
||||||
|
|
||||||
const htmlButton = {
|
const htmlButton = {
|
||||||
|
@ -56,11 +82,15 @@ const htmlButton = {
|
||||||
onClick: onHtmlEdit,
|
onClick: onHtmlEdit,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
lazyProperties(htmlButton, {
|
||||||
|
title: tr.editingHtmlEditor,
|
||||||
|
});
|
||||||
|
|
||||||
export const templateButtons = [
|
export const templateButtons = [
|
||||||
attachmentButton,
|
attachmentButton,
|
||||||
recordButton,
|
recordButton,
|
||||||
clozeButton,
|
clozeButton,
|
||||||
mathjaxButton,
|
mathjaxButtonWithMenu,
|
||||||
htmlButton,
|
htmlButton,
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,15 @@
|
||||||
import type { SvelteComponent } from "svelte/internal";
|
import type { SvelteComponent } from "svelte/internal";
|
||||||
|
|
||||||
export interface ButtonDefinition {
|
export interface SvelteComponentDefinition {
|
||||||
component: SvelteComponent;
|
component: SvelteComponent;
|
||||||
|
[arg: string]: unknown;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ButtonDefinition extends SvelteComponentDefinition {
|
||||||
id?: string;
|
id?: string;
|
||||||
className?: string;
|
className?: string;
|
||||||
props?: Record<string, string>;
|
props?: Record<string, string>;
|
||||||
button: HTMLButtonElement;
|
button: HTMLButtonElement;
|
||||||
[arg: string]: unknown;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export type Buttons = ButtonDefinition | Buttons[];
|
export type Buttons = ButtonDefinition | Buttons[];
|
||||||
|
|
Loading…
Reference in a new issue