mirror of
https://github.com/outline/outline.git
synced 2026-11-21 21:44:30 +03:00
* fix: Selection toolbar not displaying on mobile The mobile branch of FloatingToolbar rendered nothing until `position.visible` was true, but `usePosition` only reports a visible position once the menu element has been measured through `menuRef`. On desktop the wrapper is always mounted (it animates in via opacity) so the ref is populated on first render, while on mobile the toolbar is the only thing that mounts the ref — leaving it permanently null and the bar never displayed. Gate the mobile bar on there being toolbar content instead. Position is irrelevant on mobile: the bar is fixed to the bottom of the viewport and its vertical offset is owned by useKeyboardStickyOffset. Also size the bar with border-box and center its content vertically, so the declared 60px is the height of the bar rather than 60px of content plus padding with the buttons pinned to the top. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GhGyxA663bMFZ1NxBhLAoF * fix: Keep the mobile selection toolbar visible while editing On mobile the toolbar is a bar docked above the on-screen keyboard rather than a floating menu anchored to the selection, but it was only rendered while something was selected — so it appeared and vanished as the selection came and went while typing. The formatting menu was already written for this: `canFormatBlock` shows headings, quotes, toggles and list indent/outdent precisely when the selection is empty on mobile, mirroring `canFormatInline` for selected text. That branch was unreachable, as an empty selection always resolved the toolbar to nothing. Show the menu whenever the editor is focused on mobile, so the bar carries block formatting for a bare cursor and swaps to inline formatting on selection. Visibility is derived at render rather than folded into `activeToolbar` so that focus moving into the link editor's input cannot tear down a toolbar the user opened. Focus is threaded to widgets through WidgetProps. Tapping the bar now also prevents the default action of mousedown, keeping focus (and the keyboard) in the editor. Without it a tap would blur the editor and unmount the bar before the tap became a click; fields inside the bar are excluded so the link editor still takes focus. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01GhGyxA663bMFZ1NxBhLAoF * fix: Mobile toolbar is not visible * Update mobile toolbar styling fix: Does not account for stored marks --------- Co-authored-by: Claude <noreply@anthropic.com>
141 lines
4.0 KiB
TypeScript
141 lines
4.0 KiB
TypeScript
import type { PluginSimple } from "markdown-it";
|
|
import type { InputRule } from "prosemirror-inputrules";
|
|
import type { Mark, NodeType, MarkType, Schema } from "prosemirror-model";
|
|
import type { Command, Plugin, Selection } from "prosemirror-state";
|
|
import type { Editor } from "../../../app/editor";
|
|
import type { SelectionToolbarMenuDescriptor } from "../types";
|
|
|
|
export type CommandFactory = (attrs?: unknown, options?: unknown) => Command;
|
|
|
|
/** Props passed to the widget rendered by an extension. */
|
|
export type WidgetProps = {
|
|
/** Whether the editor is displayed right-to-left */
|
|
rtl: boolean;
|
|
/** Whether the editor is read-only */
|
|
readOnly: boolean | undefined;
|
|
/** The current editor selection */
|
|
selection?: Selection;
|
|
/** The marks that will be applied to text typed at the cursor */
|
|
storedMarks?: readonly Mark[] | null;
|
|
/** Whether the editor currently holds focus */
|
|
isEditorFocused: boolean;
|
|
};
|
|
|
|
export default class Extension<TOptions extends object = object> {
|
|
options: TOptions;
|
|
editor: Editor;
|
|
|
|
constructor(options: Partial<TOptions> = {}) {
|
|
this.options = {
|
|
...this.defaultOptions,
|
|
...options,
|
|
} as TOptions;
|
|
}
|
|
|
|
bindEditor(editor: Editor) {
|
|
this.editor = editor;
|
|
}
|
|
|
|
get type() {
|
|
return "extension";
|
|
}
|
|
|
|
get name() {
|
|
return "";
|
|
}
|
|
|
|
get plugins(): Plugin[] {
|
|
return [];
|
|
}
|
|
|
|
get rulePlugins(): PluginSimple[] {
|
|
return [];
|
|
}
|
|
|
|
get defaultOptions(): Partial<TOptions> {
|
|
return {};
|
|
}
|
|
|
|
/**
|
|
* Whether this extension is needed in read-only mode. When false (default), pure Extension types
|
|
* are not instantiated and their commands are blocked. Node and Mark extensions are always
|
|
* instantiated for the schema regardless of this setting.
|
|
*/
|
|
get allowInReadOnly(): boolean {
|
|
return false;
|
|
}
|
|
|
|
/**
|
|
* Whether a node's React component may be used to render it when generating static HTML on the
|
|
* server. When false, the node renders from its `toDOM` spec instead — set this when the
|
|
* component depends on browser behavior or app context unavailable outside the editor.
|
|
*/
|
|
get allowComponentInStaticHTML(): boolean {
|
|
return true;
|
|
}
|
|
|
|
get focusAfterExecution(): boolean {
|
|
return true;
|
|
}
|
|
|
|
/**
|
|
* A widget is a React component to be rendered in the editor's context, independent of any
|
|
* specific node or mark. It can be used to render things like toolbars, menus, etc. Note that
|
|
* all widgets are observed automatically, so you can use observable values.
|
|
*
|
|
* @returns A React component
|
|
*/
|
|
widget(_props: WidgetProps): React.ReactElement | undefined {
|
|
return undefined;
|
|
}
|
|
|
|
/**
|
|
* A map of ProseMirror keymap bindings. It can be used to bind keyboard shortcuts to commands.
|
|
*
|
|
* @returns An object mapping key bindings to commands
|
|
*/
|
|
keys(_options: {
|
|
type?: NodeType | MarkType;
|
|
schema: Schema;
|
|
}): Record<string, Command | CommandFactory> {
|
|
return {};
|
|
}
|
|
|
|
/**
|
|
* A map of ProseMirror input rules. It can be used to automatically replace certain patterns
|
|
* while typing.
|
|
*
|
|
* @returns An array of input rules
|
|
*/
|
|
inputRules(_options: {
|
|
type?: NodeType | MarkType;
|
|
schema: Schema;
|
|
}): InputRule[] {
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* A map of ProseMirror commands. It can be used to expose commands to the editor. If a single
|
|
* command is returned, it will be available under the extension's name.
|
|
*
|
|
* @returns An object mapping command names to command factories, or a command factory
|
|
*/
|
|
commands(_options: {
|
|
type?: NodeType | MarkType;
|
|
schema: Schema;
|
|
}): Record<string, CommandFactory> | CommandFactory | undefined {
|
|
return {};
|
|
}
|
|
|
|
/**
|
|
* Declares selection toolbar menus contributed by this extension. When
|
|
* the user selects content or clicks a node, the toolbar evaluates all
|
|
* registered menus in priority order and displays the first match.
|
|
*
|
|
* @returns an array of menu descriptors, or an empty array if this extension does not contribute menus.
|
|
*/
|
|
selectionToolbarMenus(): SelectionToolbarMenuDescriptor[] {
|
|
return [];
|
|
}
|
|
}
|