Skip to content
Snippets Groups Projects
Commit da9a4d9d authored by chris's avatar chris
Browse files

set save method for editora

parent 33dd3e68
No related branches found
No related tags found
1 merge request!232feat(custom-tag-block): added custom-tag-block
...@@ -58,6 +58,10 @@ const updateTitle = title => { ...@@ -58,6 +58,10 @@ const updateTitle = title => {
console.log(title); console.log(title);
}; };
const saveTags = tags => {
console.log(tags);
};
export default { export default {
MenuService: [ MenuService: [
{ {
...@@ -135,6 +139,7 @@ export default { ...@@ -135,6 +139,7 @@ export default {
{ label: 'custom-tag-label-3', tagType: 'block' }, { label: 'custom-tag-label-3', tagType: 'block' },
{ label: 'label 2', tagType: 'block' }, { label: 'label 2', tagType: 'block' },
], ],
// updateTags: saveTags,
}, },
services: [ services: [
......
...@@ -80,6 +80,12 @@ const CustomTagBlockComponent = ({ isShowTag, item }) => { ...@@ -80,6 +80,12 @@ const CustomTagBlockComponent = ({ isShowTag, item }) => {
customTagsConfig && customTagsConfig.tags customTagsConfig && customTagsConfig.tags
? customTagsConfig.tags ? customTagsConfig.tags
: initialArr; : initialArr;
const saveTags =
customTagsConfig && customTagsConfig.tags
? customTagsConfig.updateTags
: () => true;
const [allTags, setAllTags] = useState(configTags); const [allTags, setAllTags] = useState(configTags);
const tagStatus = item.active( const tagStatus = item.active(
activeView.state, activeView.state,
...@@ -105,9 +111,9 @@ const CustomTagBlockComponent = ({ isShowTag, item }) => { ...@@ -105,9 +111,9 @@ const CustomTagBlockComponent = ({ isShowTag, item }) => {
const onClickAdd = () => { const onClickAdd = () => {
if (inputValue.trim() === '') return; if (inputValue.trim() === '') return;
configTags.push({ label: inputValue, tagType: 'block' }); configTags.push({ label: inputValue, tagType: 'block' });
setAllTags(configTags); setAllTags(configTags);
saveTags(configTags);
setInputValue(''); setInputValue('');
if (ref.current) ref.current.focus(); if (ref.current) ref.current.focus();
}; };
......
import React, { useMemo, useRef, useState } from 'react'; import React, { useMemo, useState, useContext } from 'react';
import styled from 'styled-components'; import { WaxContext } from 'wax-prosemirror-core';
import MenuButton from '../../ui/buttons/MenuButton';
const Wrapper = styled.div` import MenuButton from '../../ui/buttons/MenuButton';
font-size: 0;
position: relative;
z-index: 2;
`;
const CustomTagInlineComponent = ({ view: { state }, item }) => { const CustomTagInlineComponent = ({ view: { state }, item }) => {
const { icon, title } = item; const { icon, title } = item;
...@@ -14,7 +9,16 @@ const CustomTagInlineComponent = ({ view: { state }, item }) => { ...@@ -14,7 +9,16 @@ const CustomTagInlineComponent = ({ view: { state }, item }) => {
const [isOpen, setIsOpen] = useState( const [isOpen, setIsOpen] = useState(
!!(localInline !== null && localInline !== false), !!(localInline !== null && localInline !== false),
); );
const ref = useRef();
const {
view: { main },
} = useContext(WaxContext);
let isDisabled = false;
const isEditable = main.props.editable(editable => {
return editable;
});
if (!isEditable) isDisabled = true;
const onClickIcon = () => { const onClickIcon = () => {
setIsOpen(isOpen !== true); setIsOpen(isOpen !== true);
...@@ -23,16 +27,13 @@ const CustomTagInlineComponent = ({ view: { state }, item }) => { ...@@ -23,16 +27,13 @@ const CustomTagInlineComponent = ({ view: { state }, item }) => {
return useMemo( return useMemo(
() => ( () => (
<Wrapper ref={ref}> <MenuButton
<div onClick={onClickIcon}> active={isOpen}
<MenuButton disabled={isDisabled}
active={isOpen} iconName={icon}
disabled={false} onMouseDown={onClickIcon}
iconName={icon} title={title}
title={title} />
/>
</div>
</Wrapper>
), ),
[isOpen], [isOpen],
); );
......
...@@ -100,6 +100,10 @@ const CustomTagInlineOverlayComponent = ({ mark, setPosition, position }) => { ...@@ -100,6 +100,10 @@ const CustomTagInlineOverlayComponent = ({ mark, setPosition, position }) => {
customTagsConfig && customTagsConfig.tags customTagsConfig && customTagsConfig.tags
? customTagsConfig.tags ? customTagsConfig.tags
: initialArr; : initialArr;
const saveTags =
customTagsConfig && customTagsConfig.tags
? customTagsConfig.updateTags
: () => true;
const [allTags, setAllTags] = useState(configTags); const [allTags, setAllTags] = useState(configTags);
const onChangeTagName = () => { const onChangeTagName = () => {
...@@ -117,6 +121,7 @@ const CustomTagInlineOverlayComponent = ({ mark, setPosition, position }) => { ...@@ -117,6 +121,7 @@ const CustomTagInlineOverlayComponent = ({ mark, setPosition, position }) => {
configTags.push({ label: inputValue, tagType: 'inline' }); configTags.push({ label: inputValue, tagType: 'inline' });
setAllTags(configTags); setAllTags(configTags);
saveTags(configTags);
setInputValue(''); setInputValue('');
if (ref.current) ref.current.focus(); if (ref.current) ref.current.focus();
setInputValue(''); setInputValue('');
......
...@@ -21,7 +21,6 @@ const disabledStyles = css` ...@@ -21,7 +21,6 @@ const disabledStyles = css`
const activeStyles = css` const activeStyles = css`
background: ${th('colorPrimary')}; background: ${th('colorPrimary')};
color: ${th('colorTextReverse')}; color: ${th('colorTextReverse')};
pointer-events: none;
> svg { > svg {
fill: ${th('colorTextReverse')}; fill: ${th('colorTextReverse')};
......
...@@ -7,9 +7,7 @@ const captionPlugin = key => ...@@ -7,9 +7,7 @@ const captionPlugin = key =>
init() { init() {
return DecorationSet.empty; return DecorationSet.empty;
}, },
apply(tr, set) { apply(tr, set) {},
console.log('in apply');
},
}, },
props: { props: {
decorations(state) { decorations(state) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment