@folijs/react 0.5.0 → 1.0.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.
@@ -1,5 +1,6 @@
1
- import { type Editor } from "@folijs/core";
1
+ import { type Command, type Editor, type EditorState } from "@folijs/core";
2
2
  import { type EditorViewOptions } from "@folijs/view";
3
+ import { type ReactNode } from "react";
3
4
  export interface FoliToolbarProps {
4
5
  /** Default: the editor of the nearest `FoliEditorProvider`. */
5
6
  editor?: Editor | undefined;
@@ -25,16 +26,90 @@ export interface FoliToolbarProps {
25
26
  * inserts one from a file; without it, it only edits a selected picture.
26
27
  */
27
28
  upload?: EditorViewOptions["upload"] | undefined;
29
+ /**
30
+ * The items, in groups (a separator between groups), in place of `defaultToolbarItems`: the
31
+ * built-in ones from `toolbarItems`, and the app's own. "New comment" shows only with
32
+ * `comments`; an empty group is left out.
33
+ */
34
+ items?: readonly (readonly ToolbarItem[])[] | undefined;
28
35
  className?: string | undefined;
29
36
  }
37
+ /** What every toolbar item has. */
38
+ interface ToolbarItemBase {
39
+ /** Unique in the toolbar; also its class, `foli-toolbar-<key>`. */
40
+ readonly key: string;
41
+ /** What it does: the tooltip, and the accessible name when an `icon` stands for the text. */
42
+ readonly label: string;
43
+ /** Visible text, which is then the accessible name (default `label`). */
44
+ readonly text?: string | undefined;
45
+ /** Shown instead of the text (a symbol or an SVG): `label` is then the accessible name. */
46
+ readonly icon?: ReactNode | undefined;
47
+ /**
48
+ * Whether it can be used now. Default: a button's dry run of its `command` (`editor.can`); for
49
+ * a menu, whether it has entries. Runs after every transaction: keep it cheap.
50
+ */
51
+ readonly enabled?: ((state: EditorState, editor: Editor) => boolean) | undefined;
52
+ }
53
+ /** A toolbar button that runs a command. */
54
+ export interface ToolbarButton extends ToolbarItemBase {
55
+ /**
56
+ * What a press runs, on the editor of the header, footer or note open on its page, else the
57
+ * body's (as the built-in buttons do).
58
+ */
59
+ readonly command: Command;
60
+ /** A toggle: whether it shows as pressed (`aria-pressed`). Runs after every transaction. */
61
+ readonly pressed?: ((state: EditorState, editor: Editor) => boolean) | undefined;
62
+ readonly actions?: undefined;
63
+ }
64
+ /** A toolbar menu button: a WAI-ARIA menu of its `actions`. */
65
+ export interface ToolbarMenu extends ToolbarItemBase {
66
+ /**
67
+ * Its entries, in order, or a function of the body's editor making them (as the built-in
68
+ * menus do). Each entry is dry-run when the menu opens; without entries the button is disabled.
69
+ */
70
+ readonly actions: readonly ToolbarAction[] | ((editor: Editor) => readonly ToolbarAction[]);
71
+ readonly command?: undefined;
72
+ readonly pressed?: undefined;
73
+ }
74
+ /**
75
+ * A toolbar item, built-in (`toolbarItems`) or the app's own: a button running a command, or a
76
+ * menu button. The toolbar keeps one tab stop for all its items (arrow keys, Home and End move
77
+ * between them), gives toggles `aria-pressed` and an item that cannot apply now `aria-disabled`
78
+ * (still focusable), and leaves the focus and selection in the document on click.
79
+ */
80
+ export type ToolbarItem = ToolbarButton | ToolbarMenu;
81
+ /** An entry of a toolbar menu (a `menuitem`, or a `menuitemcheckbox` when it has `checked`). */
82
+ export interface ToolbarAction {
83
+ /** Unique in its menu. */
84
+ readonly key: string;
85
+ readonly label: string;
86
+ /** What it runs; a dry run when the menu opens decides whether it is enabled. */
87
+ readonly command: Command;
88
+ /** A checkable entry: whether it is checked (with the same arguments as `pressed`). */
89
+ readonly checked?: ((state: EditorState, editor: Editor) => boolean) | undefined;
90
+ }
91
+ /** The names of the built-in items in `toolbarItems`. */
92
+ export type ToolbarItemName = "style" | "font" | "size" | "bold" | "italic" | "underline" | "strike" | "link" | "textColor" | "highlight" | "alignStart" | "alignCenter" | "alignEnd" | "alignJustify" | "lineSpacing" | "bulletList" | "orderedList" | "outdent" | "indent" | "newComment" | "trackChanges" | "reviewView" | "previousChange" | "nextChange" | "acceptChange" | "rejectChange" | "acceptAll" | "rejectAll" | "undo" | "redo" | "table" | "tableStyle" | "cellShading" | "picture" | "pageBreak" | "section" | "headerFooter" | "fields" | "navigate" | "notes" | "controls";
93
+ /** The built-in menu buttons of `actions` (the color menus and boxes are buttons to an app). */
94
+ type ToolbarMenuName = "table" | "section" | "headerFooter" | "fields" | "navigate" | "notes" | "controls";
95
+ /**
96
+ * The built-in items by name, to place in `FoliToolbarProps.items` (an item's `key` is its name,
97
+ * except the alignments: `align-start`, `align-center`, `align-end`, `align-justify`). A copy
98
+ * with another `label` or `icon` keeps what the built-in does.
99
+ */
100
+ export declare const toolbarItems: { readonly [Name in ToolbarItemName]: Name extends ToolbarMenuName ? ToolbarMenu : ToolbarButton; };
101
+ /** The default toolbar: groups of `toolbarItems`, a separator between groups. */
102
+ export declare const defaultToolbarItems: readonly (readonly ToolbarItem[])[];
30
103
  /**
31
- * Word's formatting controls for an editor: paragraph style, font and size boxes, marks, link (a
32
- * dialog, also on Mod-K in the document), text color and highlight menus, alignment and line
33
- * spacing, lists (bulleted, numbered, decrease and increase indent), undo, redo, tables (a Table
34
- * menu with an insert table dialog, a table style box, a cell shading menu), page break.
104
+ * Word's formatting controls for an editor (`defaultToolbarItems`, or `items`): paragraph
105
+ * style, font and size boxes, marks, link (a dialog, also on Mod-K in the document), text color
106
+ * and highlight menus, alignment and line spacing, lists (bulleted, numbered, decrease and
107
+ * increase indent), undo, redo, tables (a Table menu with an insert table dialog, a table style
108
+ * box, a cell shading menu), page break.
35
109
  * One tab stop (arrow keys, Home and End move between buttons); toggles carry
36
110
  * `aria-pressed`; a button whose command cannot run now is `aria-disabled` (still focusable).
37
111
  * Clicks leave the focus and selection in the document.
38
112
  */
39
- export declare function FoliToolbar({ editor: given, disabled, onClickCommand, label, className, comments, upload, }: FoliToolbarProps): import("react").JSX.Element;
113
+ export declare function FoliToolbar({ editor: given, disabled, onClickCommand, label, className, comments, upload, items: itemGroups, }: FoliToolbarProps): import("react").JSX.Element;
114
+ export {};
40
115
  //# sourceMappingURL=FoliToolbar.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"FoliToolbar.d.ts","sourceRoot":"","sources":["../src/FoliTo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