From 1af262f32c095431a8ea038bef2b4d42d9ae97db Mon Sep 17 00:00:00 2001 From: Deleephan <deleephan.sanjeevi@amnet-systems.com> Date: Wed, 3 Feb 2021 09:07:55 +0530 Subject: [PATCH] fix(custom-tag-block): fixed custom-tag-block --- .../customtag/CustomTagBlockComponent.js | 15 +++++---------- .../src/ui/tabs/BlockElementGroup.js | 3 +-- .../CustomTagBlockService/CustomTagBlockTool.js | 13 ++++++++++--- 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js b/wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js index a09c91c56..e0903bed2 100644 --- a/wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js +++ b/wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js @@ -51,19 +51,19 @@ const StyledButton = styled.div``; -const CustomTagBlockComponent = (isIconClicked, item) => { +const CustomTagBlockComponent = props => { + const { isShowTag, item } = props; const ref = useRef(); const [inputValue, setInputValue] = useState(''); const [tagName, setTagName] = useState(''); const localTagList = JSON.parse(localStorage.getItem('tagBlockList')); - const { app, view: { main }, activeView } = useContext(WaxContext); + const { app, view: { main }, activeView, activeViewId } = useContext(WaxContext); const { state, dispatch } = main; const { selection: { $from, $to } } = state; const serviceConfig = app.config.get('config.CustomTagService'); const [serviceList, setServiceList] = useState([]); - const onChangeTagName = (e) => { setTagName(e.target.value) setInputValue(e.target.value) @@ -86,12 +86,7 @@ const CustomTagBlockComponent = (isIconClicked, item) => { const onSelectTag = (e, val) => { val = val.replace(/ /g, "-"); - - Commands.setBlockType(state.config.schema.nodes.customTagBlock, { - class: 'custom-tag-block ' + val - })(state, dispatch); - - + item.run(state, dispatch, val); } useDeepCompareEffect(() => { @@ -115,7 +110,7 @@ const CustomTagBlockComponent = (isIconClicked, item) => { return useMemo( () => ( <Wrapper> - {isIconClicked.isShowTag === true && <FlexDiv> + {isShowTag === true && <FlexDiv> <Input ref={ref} type="text" diff --git a/wax-prosemirror-components/src/ui/tabs/BlockElementGroup.js b/wax-prosemirror-components/src/ui/tabs/BlockElementGroup.js index 0f0e47e6e..15477e494 100644 --- a/wax-prosemirror-components/src/ui/tabs/BlockElementGroup.js +++ b/wax-prosemirror-components/src/ui/tabs/BlockElementGroup.js @@ -66,7 +66,6 @@ const BlockElementGroup = props => { setIconClicked(isIconClicked === true ? false : true); } - return ( <Wrapper> {groupName !== "Custom Block" && <> @@ -87,7 +86,7 @@ const BlockElementGroup = props => { </div> </FlexDiv> <ListWrapper> - <CustomTagBlockComponent isShowTag={isIconClicked} view={view} /> + <CustomTagBlockComponent isShowTag={isIconClicked} view={view} item={items[0]} /> </ListWrapper> </>} diff --git a/wax-prosemirror-services/src/CustomTagService/CustomTagBlockService/CustomTagBlockTool.js b/wax-prosemirror-services/src/CustomTagService/CustomTagBlockService/CustomTagBlockTool.js index 8ae004422..e413effa4 100644 --- a/wax-prosemirror-services/src/CustomTagService/CustomTagBlockService/CustomTagBlockTool.js +++ b/wax-prosemirror-services/src/CustomTagService/CustomTagBlockService/CustomTagBlockTool.js @@ -1,16 +1,23 @@ import React from 'react'; // eslint-disable-next-line import/no-named-as-default,import/no-named-as-default-member import Tools from '../../lib/Tools'; +import { Commands } from 'wax-prosemirror-utilities'; class CustomTagBlockTool extends Tools { title = 'Custom Tag Block'; name = 'CustomTagBlock'; + get run() { + return (state, dispatch, val) => { + Commands.setBlockType(state.config.schema.nodes.customTagBlock, { + class: 'custom-tag-block ' + val + })(state, dispatch); + }; + } + get active() { return state => { - return Commands.blockActive(state.config.schema.nodes.customTagBlock)( - state, - ); + return Commands.blockActive(state.config.schema.nodes.customTagBlock)(state); }; } } -- GitLab