Skip to content
Snippets Groups Projects
Commit 68414e06 authored by Giannis Kopanas's avatar Giannis Kopanas Committed by chris
Browse files

fix(core): fix portal views editor

parent bfe9b806
No related branches found
No related tags found
1 merge request!289Pm node views portals
...@@ -22,7 +22,7 @@ const serializer = schema => { ...@@ -22,7 +22,7 @@ const serializer = schema => {
let schema; let schema;
const createApplication = props => { const createApplication = props => {
const application = Application.create(props); const application = Application.create(props);
schema = application.getSchema(); // schema = application.getSchema();
// application.bootServices(); // application.bootServices();
return application; return application;
}; };
...@@ -54,39 +54,40 @@ const Wax = props => { ...@@ -54,39 +54,40 @@ const Wax = props => {
if (!application) return null; if (!application) return null;
const WaxOnchange = onChange || (v => true); const WaxOnchange = onChange || (v => true);
const finalOnChange = debounce( const finalOnChange = () => {};
// eslint-disable-next-line no-shadow // const finalOnChange = debounce(
value => { // // eslint-disable-next-line no-shadow
/* HACK alter toDOM of footnote, because of how PM treats inline nodes // value => {
with content */ // /* HACK alter toDOM of footnote, because of how PM treats inline nodes
if (schema.nodes.footnote) { // with content */
const old = schema.nodes.footnote.spec.toDOM; // if (schema.nodes.footnote) {
schema.nodes.footnote.spec.toDOM = node => { // const old = schema.nodes.footnote.spec.toDOM;
// eslint-disable-next-line prefer-rest-params // schema.nodes.footnote.spec.toDOM = node => {
old.apply(this); // // eslint-disable-next-line prefer-rest-params
return ['footnote', node.attrs, 0]; // old.apply(this);
}; // return ['footnote', node.attrs, 0];
} // };
// }
if (targetFormat === 'JSON') { // if (targetFormat === 'JSON') {
WaxOnchange(value); // WaxOnchange(value);
} else { // } else {
const serialize = serializer(schema); // const serialize = serializer(schema);
WaxOnchange(serialize(value)); // WaxOnchange(serialize(value));
} // }
if (schema.nodes.footnote) { // if (schema.nodes.footnote) {
const old = schema.nodes.footnote.spec.toDOM; // const old = schema.nodes.footnote.spec.toDOM;
schema.nodes.footnote.spec.toDOM = node => { // schema.nodes.footnote.spec.toDOM = node => {
// eslint-disable-next-line prefer-rest-params // // eslint-disable-next-line prefer-rest-params
old.apply(this); // old.apply(this);
return ['footnote', node.attrs]; // return ['footnote', node.attrs];
}; // };
} // }
}, // },
1000, // 1000,
{ maxWait: 5000 }, // { maxWait: 5000 },
); // );
const TrackChange = application.config.get('config.EnableTrackChangeService'); const TrackChange = application.config.get('config.EnableTrackChangeService');
const Layout = application.container.get('Layout'); const Layout = application.container.get('Layout');
......
...@@ -15,9 +15,7 @@ const parser = schema => { ...@@ -15,9 +15,7 @@ const parser = schema => {
}; };
}; };
export default ({ placeholder, targetFormat, value }) => { export default ({ placeholder, targetFormat, value, schema, plugins }) => {
const context = useContext(WaxContext);
let finalPlugins = []; let finalPlugins = [];
// eslint-disable-next-line no-shadow // eslint-disable-next-line no-shadow
...@@ -25,13 +23,12 @@ export default ({ placeholder, targetFormat, value }) => { ...@@ -25,13 +23,12 @@ export default ({ placeholder, targetFormat, value }) => {
return Placeholder({ content: placeholder }); return Placeholder({ content: placeholder });
}; };
console.log(plugins);
finalPlugins = defaultPlugins.concat([ finalPlugins = defaultPlugins.concat([
createPlaceholder(placeholder), createPlaceholder(placeholder),
...context.app.getPlugins(), ...plugins,
]); ]);
const schema = context.app.getSchema();
const WaxOptions = { const WaxOptions = {
schema, schema,
plugins: finalPlugins, plugins: finalPlugins,
......
import React, { useRef, useContext, useCallback, useMemo } from 'react'; import React, {
useRef,
useContext,
useCallback,
useMemo,
useEffect,
} from 'react';
import applyDevTools from 'prosemirror-dev-tools'; import applyDevTools from 'prosemirror-dev-tools';
import { EditorState } from 'prosemirror-state'; import { EditorState } from 'prosemirror-state';
...@@ -10,7 +16,7 @@ import ComponentPlugin from './ComponentPlugin'; ...@@ -10,7 +16,7 @@ import ComponentPlugin from './ComponentPlugin';
import { WaxContext } from './WaxContext'; import { WaxContext } from './WaxContext';
import { PortalContext } from './PortalContext'; import { PortalContext } from './PortalContext';
import transformPasted from './helpers/TransformPasted'; import transformPasted from './helpers/TransformPasted';
import useWaxOptions from './useWaxOptions'; import WaxOptions from './WaxOptions';
let previousDoc; let previousDoc;
...@@ -29,14 +35,17 @@ export default props => { ...@@ -29,14 +35,17 @@ export default props => {
export default props => { export default props => {
const { readonly, onBlur, debug, autoFocus, user, targetFormat } = props; const { readonly, onBlur, debug, autoFocus, user, targetFormat } = props;
const editorRef = useRef(); const editorRef = useRef();
let view;
const context = useContext(WaxContext); const context = useContext(WaxContext);
const { createPortal } = useContext(PortalContext); const { createPortal } = useContext(PortalContext);
context.app.setContext({ ...context, createPortal }); context.app.setContext({ ...context, createPortal });
context.app.bootServices(); const schema = context.app.getSchema();
const options = useWaxOptions(props);
if (!view) {
context.app.bootServices();
}
const setEditorRef = useCallback( const setEditorRef = useCallback(
// eslint-disable-next-line consistent-return // eslint-disable-next-line consistent-return
...@@ -47,6 +56,14 @@ export default props => { ...@@ -47,6 +56,14 @@ export default props => {
// clean up the unmount if you need to. // clean up the unmount if you need to.
} }
if (node) { if (node) {
const options = WaxOptions({
...props,
schema,
plugins: context.app.getPlugins(),
});
console.log(options);
// debugger;
view = new EditorView( view = new EditorView(
{ mount: node }, { mount: node },
{ {
......
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