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

image alt

parent 3fe687d7
No related branches found
No related tags found
1 merge request!430Hhmi issues
...@@ -2,6 +2,24 @@ import React, { useContext, useLayoutEffect, useRef, useState } from 'react'; ...@@ -2,6 +2,24 @@ import React, { useContext, useLayoutEffect, useRef, useState } from 'react';
import styled from 'styled-components'; import styled from 'styled-components';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext } from 'wax-prosemirror-core';
const StyledInputAlt = styled.input`
background: #e2ebff;
border: none;
box-sizing: border-box;
width: 240px;
min-height: 20px;
padding: 4px;
&:focus {
outline: none;
}
&::placeholder {
color: black;
font-weight: bold;
}
`;
export default ({ setPosition, position }) => { export default ({ setPosition, position }) => {
const altRef = useRef(null); const altRef = useRef(null);
const [altText, setAltText] = useState(''); const [altText, setAltText] = useState('');
...@@ -17,32 +35,15 @@ export default ({ setPosition, position }) => { ...@@ -17,32 +35,15 @@ export default ({ setPosition, position }) => {
const readOnly = !isEditable; const readOnly = !isEditable;
const StyledInputAlt = styled.input`
background: #e2ebff;
border: none;
box-sizing: border-box;
width: 240px;
min-height: 20px;
padding: 4px;
&:focus {
outline: none;
}
&::placeholder {
color: black;
font-weight: bold;
}
`;
useLayoutEffect(() => { useLayoutEffect(() => {
const WaxSurface = activeView.dom.getBoundingClientRect(); const WaxSurface = main.dom.getBoundingClientRect();
const { selection } = activeView.state; const { selection } = activeView.state;
if (!selection || !selection.node || !selection.node.attrs.id) return; if (!selection || !selection.node || !selection.node.attrs.id) return;
const imageId = selection.node.attrs.id; const imageId = selection.node.attrs.id;
const image = document.querySelector(`[data-id='${imageId}']`); const image = document.querySelector(`[data-id='${imageId}']`);
const figCaption = document.getElementsByTagName('figcaption')[0]; const figCaption = document.getElementsByTagName('figcaption')[0];
if (!image) return;
const imagePosition = image.getBoundingClientRect(); const imagePosition = image.getBoundingClientRect();
const figCaptionPosition = figCaption.getBoundingClientRect().height - 5; const figCaptionPosition = figCaption.getBoundingClientRect().height - 5;
const left = imagePosition.left - WaxSurface.left; const left = imagePosition.left - WaxSurface.left;
......
...@@ -6,7 +6,7 @@ import { StepMap } from 'prosemirror-transform'; ...@@ -6,7 +6,7 @@ import { StepMap } from 'prosemirror-transform';
import { keymap } from 'prosemirror-keymap'; import { keymap } from 'prosemirror-keymap';
import { baseKeymap, chainCommands } from 'prosemirror-commands'; import { baseKeymap, chainCommands } from 'prosemirror-commands';
import { undo, redo } from 'prosemirror-history'; import { undo, redo } from 'prosemirror-history';
import { WaxContext } from 'wax-prosemirror-core'; import { WaxContext, ComponentPlugin } from 'wax-prosemirror-core';
import { import {
splitListItem, splitListItem,
liftListItem, liftListItem,
...@@ -54,6 +54,9 @@ const EditorWrapper = styled.div` ...@@ -54,6 +54,9 @@ const EditorWrapper = styled.div`
} }
} }
`; `;
let WaxOverlays = () => true;
const QuestionEditorComponent = ({ node, view, getPos }) => { const QuestionEditorComponent = ({ node, view, getPos }) => {
const editorRef = useRef(); const editorRef = useRef();
...@@ -130,6 +133,7 @@ const QuestionEditorComponent = ({ node, view, getPos }) => { ...@@ -130,6 +133,7 @@ const QuestionEditorComponent = ({ node, view, getPos }) => {
]); ]);
useEffect(() => { useEffect(() => {
WaxOverlays = ComponentPlugin('waxOverlays');
questionView = new EditorView( questionView = new EditorView(
{ {
mount: editorRef.current, mount: editorRef.current,
...@@ -206,6 +210,7 @@ const QuestionEditorComponent = ({ node, view, getPos }) => { ...@@ -206,6 +210,7 @@ const QuestionEditorComponent = ({ node, view, getPos }) => {
return ( return (
<EditorWrapper> <EditorWrapper>
<div ref={editorRef} /> <div ref={editorRef} />
<WaxOverlays activeViewId={questionId} />
</EditorWrapper> </EditorWrapper>
); );
}; };
......
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