mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
This commit refactors the `SelectionToolbar` to operate as a Prosemirror editor extension using the widget interface. This aligns its architecture with other dynamic editor elements like `HoverPreviews`. Key changes include: - **New `SelectionToolbarExtension`**: Created in `app/editor/extensions/` to manage the lifecycle, visibility, and state of the selection toolbar. It uses a Prosemirror plugin to monitor selection changes and updates an observable `isActive` state. - **Modified `SelectionToolbar` Component**: The React component in `app/editor/components/` has been simplified. It no longer manages its own visibility or selection-tracking state. Instead, it receives an `active` prop from the extension and focuses solely on rendering the appropriate menu items based on the current editor state and props. - **Editor Integration**: The main editor setup in `app/editor/index.tsx` (and its usage in `app/components/Editor.tsx`) has been updated to include `SelectionToolbarExtension` and remove the old direct rendering of the `SelectionToolbar` component. - **Prop Handling**: The `SelectionToolbarExtension` now correctly sources necessary props (like `rtl`, `isTemplate`, `readOnly`, `canComment`, `canUpdate`, `onClickLink`) from the editor's props and passes them to the `SelectionToolbar` component. - **Testing**: Added new unit tests for `SelectionToolbarExtension` in `app/editor/extensions/SelectionToolbarExtension.test.tsx`. These tests cover the core visibility logic (activation/deactivation based on selection) and serve as placeholders for verifying menu contexts. This refactoring improves the modularity of the editor, centralizes the logic for the selection toolbar's behavior within an extension, and follows the established pattern for editor UI widgets.