stilo-editor 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +172 -2
- package/dist/characters--8h5uTeF.js +854 -0
- package/dist/content.css +161 -0
- package/dist/core/drop.d.ts +6 -0
- package/dist/core/editor.d.ts +108 -0
- package/dist/core/errors.d.ts +6 -0
- package/dist/core/events.d.ts +19 -0
- package/dist/core/extension-manager.d.ts +57 -0
- package/dist/core/extension.d.ts +43 -0
- package/dist/core/helpers/active.d.ts +33 -0
- package/dist/core/helpers/input-rules.d.ts +21 -0
- package/dist/core/helpers/lists.d.ts +12 -0
- package/dist/core/helpers/marks.d.ts +38 -0
- package/dist/core/helpers/nodes.d.ts +14 -0
- package/dist/core/helpers/parse-rules.d.ts +8 -0
- package/dist/core/html/css.d.ts +91 -0
- package/dist/core/html/parse.d.ts +7 -0
- package/dist/core/html/sanitize.d.ts +49 -0
- package/dist/core/html/serialize.d.ts +31 -0
- package/dist/core/types.d.ts +107 -0
- package/dist/extensions/blockquote/index.d.ts +15 -0
- package/dist/extensions/bold/index.d.ts +17 -0
- package/dist/extensions/bullet-list/index.d.ts +9 -0
- package/dist/extensions/clear-formatting/index.d.ts +12 -0
- package/dist/extensions/code/index.d.ts +15 -0
- package/dist/extensions/default-extensions/index.d.ts +46 -0
- package/dist/extensions/document/index.d.ts +17 -0
- package/dist/extensions/drop-cursor/index.d.ts +15 -0
- package/dist/extensions/gap-cursor/index.d.ts +6 -0
- package/dist/extensions/hard-break/index.d.ts +11 -0
- package/dist/extensions/heading/index.d.ts +24 -0
- package/dist/extensions/highlight/index.d.ts +24 -0
- package/dist/extensions/history/index.d.ts +21 -0
- package/dist/extensions/horizontal-rule/index.d.ts +11 -0
- package/dist/extensions/index.d.ts +27 -0
- package/dist/extensions/italic/index.d.ts +16 -0
- package/dist/extensions/link/index.d.ts +23 -0
- package/dist/extensions/list-item/index.d.ts +16 -0
- package/dist/extensions/move-block/index.d.ts +17 -0
- package/dist/extensions/ordered-list/index.d.ts +12 -0
- package/dist/extensions/paragraph/index.d.ts +14 -0
- package/dist/extensions/placeholder/index.d.ts +13 -0
- package/dist/extensions/strike/index.d.ts +16 -0
- package/dist/extensions/subscript/index.d.ts +16 -0
- package/dist/extensions/superscript/index.d.ts +17 -0
- package/dist/extensions/text/index.d.ts +12 -0
- package/dist/extensions/text-style/index.d.ts +14 -0
- package/dist/extensions/underline/index.d.ts +15 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +1 -0
- package/dist/src-3tAxKI0c.js +1316 -0
- package/dist/style.css +797 -0
- package/dist/ui/components/character-picker.d.ts +22 -0
- package/dist/ui/components/characters.d.ts +10 -0
- package/dist/ui/components/color-button.d.ts +23 -0
- package/dist/ui/components/dropdown.d.ts +25 -0
- package/dist/ui/components/icon.d.ts +3 -0
- package/dist/ui/components/link-bubble.d.ts +19 -0
- package/dist/ui/components/link-popover.d.ts +20 -0
- package/dist/ui/components/popover.d.ts +27 -0
- package/dist/ui/components/shortcut.d.ts +11 -0
- package/dist/ui/i18n/en.d.ts +3 -0
- package/dist/ui/i18n/it.d.ts +3 -0
- package/dist/ui/i18n/types.d.ts +4 -0
- package/dist/ui/index.d.ts +19 -0
- package/dist/ui/toolbar/items.d.ts +12 -0
- package/dist/ui/toolbar/palette.d.ts +6 -0
- package/dist/ui/toolbar/toolbar.d.ts +28 -0
- package/dist/ui/toolbar/types.d.ts +87 -0
- package/dist/ui.css +635 -0
- package/dist/ui.js +1292 -0
- package/package.json +86 -4
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { Editor } from '../../index';
|
|
2
|
+
import type { Messages } from '../i18n/types';
|
|
3
|
+
/** Options of {@link createCharacterPicker}. */
|
|
4
|
+
export interface CharacterPickerOptions {
|
|
5
|
+
/** The toolbar button that opens the picker. */
|
|
6
|
+
anchor: HTMLElement;
|
|
7
|
+
/** The element the picker scrolls with: the toolbar. */
|
|
8
|
+
container: HTMLElement;
|
|
9
|
+
messages: Messages;
|
|
10
|
+
}
|
|
11
|
+
/** The special characters and emoji picker; it stays open after each insertion. */
|
|
12
|
+
export interface CharacterPicker {
|
|
13
|
+
readonly isOpen: boolean;
|
|
14
|
+
/** Opens the picker, loading its data the first time; the focus goes to the search field. */
|
|
15
|
+
open(): Promise<void>;
|
|
16
|
+
/** Closes the picker and gives the focus back to the editor. */
|
|
17
|
+
close(): void;
|
|
18
|
+
toggle(): void;
|
|
19
|
+
destroy(): void;
|
|
20
|
+
}
|
|
21
|
+
/** Creates the character picker (closed), anchored to the toolbar button. */
|
|
22
|
+
export declare function createCharacterPicker(editor: Editor, options: CharacterPickerOptions): CharacterPicker;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { MessageKey } from '../i18n/types';
|
|
2
|
+
/** A category of the character picker: its label and its characters with their names. */
|
|
3
|
+
export interface CharacterCategory {
|
|
4
|
+
labelKey: MessageKey;
|
|
5
|
+
characters: ReadonlyArray<readonly [character: string, name: string]>;
|
|
6
|
+
}
|
|
7
|
+
/** Special characters, by category. */
|
|
8
|
+
export declare const SYMBOLS: readonly CharacterCategory[];
|
|
9
|
+
/** Emoji, by category. */
|
|
10
|
+
export declare const EMOJI: readonly CharacterCategory[];
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type { Editor } from '../../index';
|
|
2
|
+
import type { Messages } from '../i18n/types';
|
|
3
|
+
import type { ToolbarColorButton } from '../toolbar/types';
|
|
4
|
+
/** Options of {@link createColorButton}. */
|
|
5
|
+
export interface ColorButtonOptions {
|
|
6
|
+
/** The element the popover scrolls with: the toolbar. */
|
|
7
|
+
container: HTMLElement;
|
|
8
|
+
messages: Messages;
|
|
9
|
+
}
|
|
10
|
+
/** A color split button and its popover (T-026). */
|
|
11
|
+
export interface ColorButton {
|
|
12
|
+
/** The wrapper of the two parts. */
|
|
13
|
+
readonly element: HTMLElement;
|
|
14
|
+
/** Applies the last used color. */
|
|
15
|
+
readonly main: HTMLButtonElement;
|
|
16
|
+
/** Opens the popover. */
|
|
17
|
+
readonly arrow: HTMLButtonElement;
|
|
18
|
+
/** Refreshes the enabled and pressed states. */
|
|
19
|
+
update(): void;
|
|
20
|
+
destroy(): void;
|
|
21
|
+
}
|
|
22
|
+
/** Creates the split button of `item` and its popover (closed), mounted in `container`. */
|
|
23
|
+
export declare function createColorButton(editor: Editor, item: ToolbarColorButton, options: ColorButtonOptions): ColorButton;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** One option as displayed: label and shortcut already resolved and formatted. */
|
|
2
|
+
export interface DropdownOptionView {
|
|
3
|
+
id: string;
|
|
4
|
+
label: string;
|
|
5
|
+
shortcut?: string;
|
|
6
|
+
}
|
|
7
|
+
export interface DropdownOptions {
|
|
8
|
+
/** Accessible name of the trigger and of the menu; shown when no option is active. */
|
|
9
|
+
label: string;
|
|
10
|
+
options: DropdownOptionView[];
|
|
11
|
+
/** The popover container (the toolbar element). */
|
|
12
|
+
container: HTMLElement;
|
|
13
|
+
onSelect(id: string): void;
|
|
14
|
+
}
|
|
15
|
+
export interface DropdownState {
|
|
16
|
+
activeId: string | null;
|
|
17
|
+
disabledIds: ReadonlySet<string>;
|
|
18
|
+
}
|
|
19
|
+
export interface Dropdown {
|
|
20
|
+
/** The trigger button; the toolbar inserts it in its group. */
|
|
21
|
+
readonly trigger: HTMLButtonElement;
|
|
22
|
+
update(state: DropdownState): void;
|
|
23
|
+
destroy(): void;
|
|
24
|
+
}
|
|
25
|
+
export declare function createDropdown(options: DropdownOptions): Dropdown;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type { Editor } from '../../index';
|
|
2
|
+
import type { Messages } from '../i18n/types';
|
|
3
|
+
/** Options of {@link createLinkBubble}. */
|
|
4
|
+
export interface LinkBubbleOptions {
|
|
5
|
+
/** The element the bubble scrolls with: the parent of the editable element. */
|
|
6
|
+
container: HTMLElement;
|
|
7
|
+
messages: Messages;
|
|
8
|
+
/** Called by the edit button (the toolbar opens the link popover). */
|
|
9
|
+
onEdit(): void;
|
|
10
|
+
}
|
|
11
|
+
/** The link bubble: shown under the link at the cursor while the editor has the focus. */
|
|
12
|
+
export interface LinkBubble {
|
|
13
|
+
readonly isOpen: boolean;
|
|
14
|
+
/** Shows, moves or hides the bubble after the selection or the focus changed. */
|
|
15
|
+
update(): void;
|
|
16
|
+
destroy(): void;
|
|
17
|
+
}
|
|
18
|
+
/** Creates the link bubble, which follows the editor on its own. */
|
|
19
|
+
export declare function createLinkBubble(editor: Editor, options: LinkBubbleOptions): LinkBubble;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { Editor } from '../../index';
|
|
2
|
+
import type { Messages } from '../i18n/types';
|
|
3
|
+
/** Options of {@link createLinkPopover}. */
|
|
4
|
+
export interface LinkPopoverOptions {
|
|
5
|
+
/** The element the popover scrolls with: the parent of the editable element. */
|
|
6
|
+
container: HTMLElement;
|
|
7
|
+
messages: Messages;
|
|
8
|
+
}
|
|
9
|
+
/** The link popover: adds, edits or removes the link of the selection. */
|
|
10
|
+
export interface LinkPopover {
|
|
11
|
+
readonly isOpen: boolean;
|
|
12
|
+
/** Opens the popover under the selection; does nothing when {@link canEditLink} is false. */
|
|
13
|
+
open(): void;
|
|
14
|
+
close(): void;
|
|
15
|
+
destroy(): void;
|
|
16
|
+
}
|
|
17
|
+
/** Whether the selection is in a link or can be linked (a cursor outside a link cannot). */
|
|
18
|
+
export declare function canEditLink(editor: Editor): boolean;
|
|
19
|
+
/** Creates the link popover (closed), anchored to the selection of `editor`. */
|
|
20
|
+
export declare function createLinkPopover(editor: Editor, options: LinkPopoverOptions): LinkPopover;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { Placement, VirtualElement } from '@floating-ui/dom';
|
|
2
|
+
/** Why a popover closed. `api` = `close()` or `destroy()` was called. */
|
|
3
|
+
export type PopoverCloseReason = 'escape' | 'outside' | 'api';
|
|
4
|
+
export interface PopoverOptions {
|
|
5
|
+
/** What the popover is anchored to: an element, or a rectangle (e.g. the selection). */
|
|
6
|
+
anchor: Element | VirtualElement;
|
|
7
|
+
/** The floating element; the popover appends it to `container`. */
|
|
8
|
+
content: HTMLElement;
|
|
9
|
+
/**
|
|
10
|
+
* The element the popover scrolls with: it gets the class `stilo-popover-host`
|
|
11
|
+
* (`position: relative`), so the browser moves the popover with it on scroll.
|
|
12
|
+
*/
|
|
13
|
+
container: HTMLElement;
|
|
14
|
+
/** Default: 'bottom-start'. */
|
|
15
|
+
placement?: Placement;
|
|
16
|
+
/** Distance from the anchor in px. Default: 4. */
|
|
17
|
+
offset?: number;
|
|
18
|
+
/** Called on every open → closed transition. */
|
|
19
|
+
onClose?(reason: PopoverCloseReason): void;
|
|
20
|
+
}
|
|
21
|
+
export interface Popover {
|
|
22
|
+
readonly isOpen: boolean;
|
|
23
|
+
open(): void;
|
|
24
|
+
close(): void;
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
27
|
+
export declare function createPopover(options: PopoverOptions): Popover;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Whether the platform shows Mac shortcuts. */
|
|
2
|
+
export declare function isMacPlatform(): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* Formats a keymap shortcut for display.
|
|
5
|
+
*
|
|
6
|
+
* Off Mac: `Mod` means `Ctrl`; modifiers in the order `Ctrl`, `Alt`, `Shift`, then the key,
|
|
7
|
+
* joined with `+`. On Mac: `Ctrl` → `⌃`, `Alt` → `⌥`, `Shift` → `⇧`, `Mod` → `⌘`, in the
|
|
8
|
+
* order `⌃⌥⇧⌘`, then the key, no separator. A single-character key is uppercased; longer
|
|
9
|
+
* keys stay as written.
|
|
10
|
+
*/
|
|
11
|
+
export declare function formatShortcut(shortcut: string, mac: boolean): string;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Keys of the built-in UI strings (dot.case). */
|
|
2
|
+
export type MessageKey = 'toolbar.label' | 'toolbar.undo' | 'toolbar.redo' | 'toolbar.bold' | 'toolbar.italic' | 'toolbar.underline' | 'toolbar.strike' | 'toolbar.subscript' | 'toolbar.superscript' | 'toolbar.code' | 'toolbar.clearFormatting' | 'toolbar.bulletList' | 'toolbar.orderedList' | 'toolbar.blockquote' | 'toolbar.horizontalRule' | 'toolbar.link' | 'toolbar.heading' | 'heading.paragraph' | 'heading.h1' | 'heading.h2' | 'heading.h3' | 'heading.h4' | 'heading.h5' | 'heading.h6' | 'link.url' | 'link.newTab' | 'link.apply' | 'link.remove' | 'link.edit' | 'link.open' | 'toolbar.characters' | 'characters.search' | 'characters.noResults' | 'characters.symbols' | 'characters.emoji' | 'characters.punctuation' | 'characters.currency' | 'characters.math' | 'characters.arrows' | 'characters.greek' | 'characters.latin' | 'characters.signs' | 'characters.smileys' | 'characters.people' | 'characters.nature' | 'characters.food' | 'characters.travel' | 'characters.activities' | 'characters.objects' | 'characters.emojiSymbols' | 'toolbar.textColor' | 'toolbar.highlight' | 'color.more' | 'color.default' | 'color.none' | 'color.pick' | 'color.custom' | 'color.apply' | 'color.black' | 'color.darkGray2' | 'color.darkGray1' | 'color.gray' | 'color.lightGray1' | 'color.lightGray2' | 'color.lightGray3' | 'color.white' | 'color.red' | 'color.orange' | 'color.yellow' | 'color.green' | 'color.cyan' | 'color.blue' | 'color.purple' | 'color.pink' | 'color.lightRed' | 'color.lightOrange' | 'color.lightYellow' | 'color.lightGreen' | 'color.lightCyan' | 'color.lightBlue' | 'color.lightPurple' | 'color.lightPink' | 'color.darkRed' | 'color.darkOrange' | 'color.darkYellow' | 'color.darkGreen' | 'color.darkCyan' | 'color.darkBlue' | 'color.darkPurple' | 'color.darkPink';
|
|
3
|
+
/** UI strings: every {@link MessageKey}, plus the label keys of custom toolbar items. */
|
|
4
|
+
export type Messages = Readonly<Record<MessageKey, string>> & Readonly<Record<string, string>>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/** Public API of the Stilo default UI. */
|
|
2
|
+
/** Dropdown component. */
|
|
3
|
+
export type { Dropdown, DropdownOptions, DropdownOptionView, DropdownState, } from './components/dropdown';
|
|
4
|
+
/** Shortcut formatting utilities. */
|
|
5
|
+
export { formatShortcut } from './components/shortcut';
|
|
6
|
+
/** English UI strings. */
|
|
7
|
+
export { en } from './i18n/en';
|
|
8
|
+
/** Italian UI strings. */
|
|
9
|
+
export { it } from './i18n/it';
|
|
10
|
+
/** i18n types. */
|
|
11
|
+
export type { MessageKey, Messages } from './i18n/types';
|
|
12
|
+
/** Default toolbar items and layout. */
|
|
13
|
+
export { DEFAULT_ITEMS, DEFAULT_TOOLBAR, headingDropdown, highlightButton, textColorButton, } from './toolbar/items';
|
|
14
|
+
/** Default palette of the color buttons. */
|
|
15
|
+
export { DEFAULT_PALETTE } from './toolbar/palette';
|
|
16
|
+
/** Toolbar element and creation function. */
|
|
17
|
+
export { createToolbar, type Toolbar, type ToolbarOptions } from './toolbar/toolbar';
|
|
18
|
+
/** Toolbar item types. */
|
|
19
|
+
export type { ToolbarButton, ToolbarColor, ToolbarColorButton, ToolbarContext, ToolbarDropdown, ToolbarDropdownOption, ToolbarItem, } from './toolbar/types';
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { HeadingLevel } from '../../index';
|
|
2
|
+
import type { ToolbarColor, ToolbarColorButton, ToolbarDropdown, ToolbarItem } from './types';
|
|
3
|
+
/** Default toolbar item IDs for the `items` configuration. */
|
|
4
|
+
export declare const DEFAULT_TOOLBAR: ReadonlyArray<ReadonlyArray<string>>;
|
|
5
|
+
/** The default toolbar items, by ID. */
|
|
6
|
+
export declare const DEFAULT_ITEMS: Readonly<Record<string, ToolbarItem>>;
|
|
7
|
+
/** The text color split button (`TextStyle` extension), default color black. */
|
|
8
|
+
export declare function textColorButton(palette?: readonly ToolbarColor[]): ToolbarColorButton;
|
|
9
|
+
/** The highlight split button (`Highlight` extension), default a plain `<mark>`. */
|
|
10
|
+
export declare function highlightButton(palette?: readonly ToolbarColor[]): ToolbarColorButton;
|
|
11
|
+
/** A heading dropdown toolbar item. */
|
|
12
|
+
export declare function headingDropdown(levels?: HeadingLevel[]): ToolbarDropdown;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Editor } from '../../index';
|
|
2
|
+
import type { Messages } from '../i18n/types';
|
|
3
|
+
import type { ToolbarItem } from './types';
|
|
4
|
+
/** Options of {@link createToolbar}. */
|
|
5
|
+
export interface ToolbarOptions {
|
|
6
|
+
/** The toolbar element is appended inside it. */
|
|
7
|
+
container: HTMLElement;
|
|
8
|
+
/** Groups of items: an ID of DEFAULT_ITEMS or a custom item. Default: DEFAULT_TOOLBAR. */
|
|
9
|
+
items?: ReadonlyArray<ReadonlyArray<string | ToolbarItem>>;
|
|
10
|
+
/** UI strings. Default: `en`. */
|
|
11
|
+
messages?: Messages;
|
|
12
|
+
/**
|
|
13
|
+
* Keeps the toolbar visible at the top of the scrolling area: `container` gets the class
|
|
14
|
+
* `stilo-toolbar-host` (`position: sticky`). Default: `true`.
|
|
15
|
+
*/
|
|
16
|
+
sticky?: boolean;
|
|
17
|
+
}
|
|
18
|
+
/** A toolbar created by {@link createToolbar}. */
|
|
19
|
+
export interface Toolbar {
|
|
20
|
+
/** The `role="toolbar"` element. */
|
|
21
|
+
readonly element: HTMLElement;
|
|
22
|
+
/** Refreshes active/enabled states now (they also refresh on every transaction). */
|
|
23
|
+
update(): void;
|
|
24
|
+
/** Removes the toolbar and every listener. Calling it twice is a no-op. */
|
|
25
|
+
destroy(): void;
|
|
26
|
+
}
|
|
27
|
+
/** Creates the toolbar element and buttons, and registers event handlers. */
|
|
28
|
+
export declare function createToolbar(editor: Editor, options: ToolbarOptions): Toolbar;
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
import type { IconNode } from 'lucide';
|
|
2
|
+
import type { Editor } from '../../index';
|
|
3
|
+
/** A toolbar button. */
|
|
4
|
+
export interface ToolbarButton {
|
|
5
|
+
/** Unique within the toolbar; written as `data-item`. */
|
|
6
|
+
id: string;
|
|
7
|
+
kind: 'button';
|
|
8
|
+
icon: IconNode;
|
|
9
|
+
/** Key of the label in `messages`; a missing key is shown as is. */
|
|
10
|
+
labelKey: string;
|
|
11
|
+
/** Keymap notation shown in the tooltip, e.g. 'Mod-b'. */
|
|
12
|
+
shortcut?: string;
|
|
13
|
+
/** Runs on click, after the editor got the focus back. */
|
|
14
|
+
run(editor: Editor, context: ToolbarContext): void;
|
|
15
|
+
/** Present = toggle button (`aria-pressed`). */
|
|
16
|
+
isActive?(editor: Editor): boolean;
|
|
17
|
+
/** Default: always enabled. */
|
|
18
|
+
isEnabled?(editor: Editor): boolean;
|
|
19
|
+
/** False = not rendered (e.g. its extension is disabled). Default: available. */
|
|
20
|
+
isAvailable?(editor: Editor): boolean;
|
|
21
|
+
}
|
|
22
|
+
/** UI services the toolbar offers to {@link ToolbarButton.run}. */
|
|
23
|
+
export interface ToolbarContext {
|
|
24
|
+
/** Opens the link popover under the selection (no-op without the `Link` extension). */
|
|
25
|
+
openLinkPopover(): void;
|
|
26
|
+
/** Opens or closes the character picker (no-op without the `characters` item). */
|
|
27
|
+
toggleCharacterPicker(): void;
|
|
28
|
+
}
|
|
29
|
+
/** A dropdown of mutually exclusive options (T-014). */
|
|
30
|
+
export interface ToolbarDropdown {
|
|
31
|
+
id: string;
|
|
32
|
+
kind: 'dropdown';
|
|
33
|
+
/** Key of the accessible name of the trigger and of the menu. */
|
|
34
|
+
labelKey: string;
|
|
35
|
+
options: ToolbarDropdownOption[];
|
|
36
|
+
isAvailable?(editor: Editor): boolean;
|
|
37
|
+
}
|
|
38
|
+
/** An option of a {@link ToolbarDropdown}. */
|
|
39
|
+
export interface ToolbarDropdownOption {
|
|
40
|
+
/** Unique within the dropdown; used in the class `stilo-dropdown__option--<id>`. */
|
|
41
|
+
id: string;
|
|
42
|
+
labelKey: string;
|
|
43
|
+
shortcut?: string;
|
|
44
|
+
run(editor: Editor): void;
|
|
45
|
+
isActive(editor: Editor): boolean;
|
|
46
|
+
/** Default: always enabled. */
|
|
47
|
+
isEnabled?(editor: Editor): boolean;
|
|
48
|
+
}
|
|
49
|
+
/** A color of a {@link ToolbarColorButton} palette. */
|
|
50
|
+
export interface ToolbarColor {
|
|
51
|
+
/** A CSS color, written as the editor stores it (e.g. lowercase `#rrggbb`). */
|
|
52
|
+
color: string;
|
|
53
|
+
/** Key of the color name in `messages`; a missing key is shown as is. */
|
|
54
|
+
labelKey: string;
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* A split button that applies a color (T-026): the main part applies the last used color (or
|
|
58
|
+
* removes it when the whole selection has it), the arrow opens a popover with the palette.
|
|
59
|
+
*/
|
|
60
|
+
export interface ToolbarColorButton {
|
|
61
|
+
/** Unique within the toolbar; written as `data-item` on both parts. */
|
|
62
|
+
id: string;
|
|
63
|
+
kind: 'color';
|
|
64
|
+
icon: IconNode;
|
|
65
|
+
labelKey: string;
|
|
66
|
+
palette: readonly ToolbarColor[];
|
|
67
|
+
/** The color the main part applies until one is picked (`null`: the mark without a color). */
|
|
68
|
+
defaultColor: string | null;
|
|
69
|
+
/**
|
|
70
|
+
* Shows a "Default" choice next to "No color" that applies the color `null`; its label is
|
|
71
|
+
* drawn inside a `<mark>`, the browser's look of a highlight without a color.
|
|
72
|
+
*/
|
|
73
|
+
defaultChoice?: boolean;
|
|
74
|
+
/** Applies `color` to the selection; `false` when the color is refused. */
|
|
75
|
+
setColor(editor: Editor, color: string | null): boolean;
|
|
76
|
+
/** Removes the color from the selection. */
|
|
77
|
+
unsetColor(editor: Editor): void;
|
|
78
|
+
/** Whether the whole selection has `color`. */
|
|
79
|
+
hasColor(editor: Editor, color: string | null): boolean;
|
|
80
|
+
/** The color at the selection, `null` when there is none. */
|
|
81
|
+
getColor(editor: Editor): string | null;
|
|
82
|
+
/** Default: always enabled. */
|
|
83
|
+
isEnabled?(editor: Editor): boolean;
|
|
84
|
+
isAvailable?(editor: Editor): boolean;
|
|
85
|
+
}
|
|
86
|
+
/** A single item in the toolbar. */
|
|
87
|
+
export type ToolbarItem = ToolbarButton | ToolbarDropdown | ToolbarColorButton;
|