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

temp

parent dd8ef540
No related branches found
No related tags found
1 merge request!597Use view context
......@@ -30,6 +30,7 @@ const user = {
const Editoria = () => {
const [width] = useWindowSize();
const [myConfig, setMyConfig] = useState(config);
const [myName, setMyName] = useState('COKO');
let layout = EditoriaLayout;
let finalConfig = config;
......@@ -56,6 +57,15 @@ const Editoria = () => {
change config
</button>
<button
onClick={() => {
setMyName('GIANNIS');
}}
>
{' '}
change name
</button>
<Wax
ref={editorRef}
key={key}
......@@ -66,6 +76,7 @@ const Editoria = () => {
// value={demo}
// readonly
layout={layout}
name={myName}
// onChange={debounce(source => {
// console.log(JSON.stringify(source));
// }, 200)}
......
......@@ -20,21 +20,23 @@ const WaxPortals = ComponentPlugin('waxPortals');
const WaxOverlays = ComponentPlugin('waxOverlays');
const WaxView = props => {
const { autoFocus } = props;
useWaxView(props);
const {
pmViews: { main },
} = useContext(WaxContext);
const { autoFocus, configHash } = props;
console.log(configHash);
const main = useWaxView(props);
console.log(main);
// const {
// pmViews: { main },
// } = useContext(WaxContext);
const editorRef = useCallback(
element => {
console.log('WAXXXX');
if (element && main) {
element.replaceChildren(main?.dom);
}
// return () => element.remove();
},
[main],
);
......
......@@ -11,7 +11,7 @@ import helpers from './helpers/helpers';
import './styles/styles.css';
let previousDoc;
let view;
const useWaxView = props => {
const {
browserSpellCheck,
......@@ -26,8 +26,6 @@ const useWaxView = props => {
scrollThreshold,
} = props;
let view;
const context = useContext(WaxContext);
const { createPortal } = useContext(PortalContext);
......@@ -95,6 +93,11 @@ const useWaxView = props => {
const state = view.state.apply(tr);
view.updateState(state);
const docContent =
targetFormat === 'JSON' ? state.doc.toJSON() : state.doc.content;
if (!previousDoc.eq(view.state.doc) || tr.getMeta('forceUpdate'))
props.onChange(docContent);
/* when a transaction comes from a view other than
main don't keep updating the view ,as this is
the central point of each transaction
......@@ -109,12 +112,9 @@ const useWaxView = props => {
'main',
);
}
const docContent =
targetFormat === 'JSON' ? state.doc.toJSON() : state.doc.content;
if (!previousDoc.eq(view.state.doc) || tr.getMeta('forceUpdate'))
props.onChange(docContent);
};
return view;
};
export default useWaxView;
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