diff --git a/wax-prosemirror-core/src/components/Button.js b/wax-prosemirror-core/src/components/Button.js index f8ef7bffbdfc795da59792c3de9b1c3f8db4f516..023a7875b0aa5dd56e52d9023204b71694c4f254 100644 --- a/wax-prosemirror-core/src/components/Button.js +++ b/wax-prosemirror-core/src/components/Button.js @@ -3,9 +3,10 @@ import React, { useContext, useMemo } from 'react'; import { isEmpty } from 'lodash'; import { useTranslation } from 'react-i18next'; import { WaxContext } from '../WaxContext'; +import { StateContext } from '../StateContext'; import MenuButton from './ui/MenuButton'; -const Button = ({ state, item }) => { +const Button = ({ item }) => { const { t, i18n } = useTranslation(); const { active, icon, label, run, select, title } = item; const context = useContext(WaxContext); @@ -15,15 +16,12 @@ const Button = ({ state, item }) => { activeView, } = context; + const { state } = useContext(StateContext); + const isEditable = main.props.editable(editable => { return editable; }); - const handleMouseDown = e => { - e.preventDefault(); - run(state, activeView.dispatch, activeView, context); - }; - const isActive = !!( active(state, activeViewId) && select(state, activeViewId, activeView) ); @@ -31,15 +29,19 @@ const Button = ({ state, item }) => { let isDisabled = !select(state, context.activeViewId, context.activeView); if (!isEditable) isDisabled = true; + const onMouseDown = e => { + e.preventDefault(); + run(state, activeView.dispatch, activeView, context); + }; + const MenuButtonComponent = useMemo(() => { - console.log('kokokoko'); return ( <MenuButton active={isActive || false} disabled={isDisabled} iconName={icon} label={label} - onMouseDown={e => handleMouseDown(e)} + onMouseDown={onMouseDown} title={ !isEmpty(i18n) && i18n.exists(`Wax.Annotations.${title}`) ? t(`Wax.Annotations.${title}`) diff --git a/wax-prosemirror-core/src/config/defaultServices/MenuService/Menu.js b/wax-prosemirror-core/src/config/defaultServices/MenuService/Menu.js index 054b8e6d86ee81ba8263dad45c086f491db4408d..212b817a1abac97add5f97e45f86bb0fc82d6c28 100644 --- a/wax-prosemirror-core/src/config/defaultServices/MenuService/Menu.js +++ b/wax-prosemirror-core/src/config/defaultServices/MenuService/Menu.js @@ -36,10 +36,13 @@ class Menu { render() { return () => { const { state } = useContext(StateContext); - const Bar = useMemo(() => ( - // eslint-disable-next-line react/no-this-in-sfc - <MenuWrapper items={this.toolGroups} state={state} /> - )); + const Bar = useMemo( + () => ( + // eslint-disable-next-line react/no-this-in-sfc + <MenuWrapper items={this.toolGroups} state={state} /> + ), + [], + ); return <>{Bar}</>; }; }