From da9a4d9d19d4aeffee64c4c8b3ff6a9a33538d92 Mon Sep 17 00:00:00 2001
From: chris <kokosias@yahoo.gr>
Date: Thu, 11 Feb 2021 17:38:51 +0200
Subject: [PATCH] set save method for editora

---
 editors/editoria/src/config/config.js         |  5 +++
 .../customtag/CustomTagBlockComponent.js      |  8 +++-
 .../customtag/CustomTagInlineComponent.js     | 39 ++++++++++---------
 .../CustomTagInlineOverlayCompoment.js        |  5 +++
 .../src/ui/buttons/MenuButton.js              |  1 -
 .../src/images/captionPlugin.js               |  4 +-
 6 files changed, 38 insertions(+), 24 deletions(-)

diff --git a/editors/editoria/src/config/config.js b/editors/editoria/src/config/config.js
index 3784d96ed..de11fc6f4 100644
--- a/editors/editoria/src/config/config.js
+++ b/editors/editoria/src/config/config.js
@@ -58,6 +58,10 @@ const updateTitle = title => {
   console.log(title);
 };
 
+const saveTags = tags => {
+  console.log(tags);
+};
+
 export default {
   MenuService: [
     {
@@ -135,6 +139,7 @@ export default {
       { label: 'custom-tag-label-3', tagType: 'block' },
       { label: 'label 2', tagType: 'block' },
     ],
+    // updateTags: saveTags,
   },
 
   services: [
diff --git a/wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js b/wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js
index 0b37b919d..0b40e4c05 100644
--- a/wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js
+++ b/wax-prosemirror-components/src/components/customtag/CustomTagBlockComponent.js
@@ -80,6 +80,12 @@ const CustomTagBlockComponent = ({ isShowTag, item }) => {
     customTagsConfig && customTagsConfig.tags
       ? customTagsConfig.tags
       : initialArr;
+
+  const saveTags =
+    customTagsConfig && customTagsConfig.tags
+      ? customTagsConfig.updateTags
+      : () => true;
+
   const [allTags, setAllTags] = useState(configTags);
   const tagStatus = item.active(
     activeView.state,
@@ -105,9 +111,9 @@ const CustomTagBlockComponent = ({ isShowTag, item }) => {
 
   const onClickAdd = () => {
     if (inputValue.trim() === '') return;
-
     configTags.push({ label: inputValue, tagType: 'block' });
     setAllTags(configTags);
+    saveTags(configTags);
     setInputValue('');
     if (ref.current) ref.current.focus();
   };
diff --git a/wax-prosemirror-components/src/components/customtag/CustomTagInlineComponent.js b/wax-prosemirror-components/src/components/customtag/CustomTagInlineComponent.js
index 9ae7027de..522afa887 100644
--- a/wax-prosemirror-components/src/components/customtag/CustomTagInlineComponent.js
+++ b/wax-prosemirror-components/src/components/customtag/CustomTagInlineComponent.js
@@ -1,12 +1,7 @@
-import React, { useMemo, useRef, useState } from 'react';
-import styled from 'styled-components';
-import MenuButton from '../../ui/buttons/MenuButton';
+import React, { useMemo, useState, useContext } from 'react';
+import { WaxContext } from 'wax-prosemirror-core';
 
-const Wrapper = styled.div`
-  font-size: 0;
-  position: relative;
-  z-index: 2;
-`;
+import MenuButton from '../../ui/buttons/MenuButton';
 
 const CustomTagInlineComponent = ({ view: { state }, item }) => {
   const { icon, title } = item;
@@ -14,7 +9,16 @@ const CustomTagInlineComponent = ({ view: { state }, item }) => {
   const [isOpen, setIsOpen] = useState(
     !!(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 = () => {
     setIsOpen(isOpen !== true);
@@ -23,16 +27,13 @@ const CustomTagInlineComponent = ({ view: { state }, item }) => {
 
   return useMemo(
     () => (
-      <Wrapper ref={ref}>
-        <div onClick={onClickIcon}>
-          <MenuButton
-            active={isOpen}
-            disabled={false}
-            iconName={icon}
-            title={title}
-          />
-        </div>
-      </Wrapper>
+      <MenuButton
+        active={isOpen}
+        disabled={isDisabled}
+        iconName={icon}
+        onMouseDown={onClickIcon}
+        title={title}
+      />
     ),
     [isOpen],
   );
diff --git a/wax-prosemirror-components/src/components/customtag/CustomTagInlineOverlayCompoment.js b/wax-prosemirror-components/src/components/customtag/CustomTagInlineOverlayCompoment.js
index c69940f4f..135ba97f4 100644
--- a/wax-prosemirror-components/src/components/customtag/CustomTagInlineOverlayCompoment.js
+++ b/wax-prosemirror-components/src/components/customtag/CustomTagInlineOverlayCompoment.js
@@ -100,6 +100,10 @@ const CustomTagInlineOverlayComponent = ({ mark, setPosition, position }) => {
     customTagsConfig && customTagsConfig.tags
       ? customTagsConfig.tags
       : initialArr;
+  const saveTags =
+    customTagsConfig && customTagsConfig.tags
+      ? customTagsConfig.updateTags
+      : () => true;
   const [allTags, setAllTags] = useState(configTags);
 
   const onChangeTagName = () => {
@@ -117,6 +121,7 @@ const CustomTagInlineOverlayComponent = ({ mark, setPosition, position }) => {
 
     configTags.push({ label: inputValue, tagType: 'inline' });
     setAllTags(configTags);
+    saveTags(configTags);
     setInputValue('');
     if (ref.current) ref.current.focus();
     setInputValue('');
diff --git a/wax-prosemirror-components/src/ui/buttons/MenuButton.js b/wax-prosemirror-components/src/ui/buttons/MenuButton.js
index aa85ed3e5..7e5606dc0 100644
--- a/wax-prosemirror-components/src/ui/buttons/MenuButton.js
+++ b/wax-prosemirror-components/src/ui/buttons/MenuButton.js
@@ -21,7 +21,6 @@ const disabledStyles = css`
 const activeStyles = css`
   background: ${th('colorPrimary')};
   color: ${th('colorTextReverse')};
-  pointer-events: none;
 
   > svg {
     fill: ${th('colorTextReverse')};
diff --git a/wax-prosemirror-plugins/src/images/captionPlugin.js b/wax-prosemirror-plugins/src/images/captionPlugin.js
index fb6345e62..6ae3b7a1d 100644
--- a/wax-prosemirror-plugins/src/images/captionPlugin.js
+++ b/wax-prosemirror-plugins/src/images/captionPlugin.js
@@ -7,9 +7,7 @@ const captionPlugin = key =>
       init() {
         return DecorationSet.empty;
       },
-      apply(tr, set) {
-        console.log('in apply');
-      },
+      apply(tr, set) {},
     },
     props: {
       decorations(state) {
-- 
GitLab