diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index 222961eb8475fbc2c1528d4bf718c3b8dd8bb7f8..92c12e65fcbc7bbfb72111395d0668f304a14972 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -22,7 +22,7 @@ const serializer = schema => { let schema; const createApplication = props => { const application = Application.create(props); - schema = application.getSchema(); + // schema = application.getSchema(); // application.bootServices(); return application; }; @@ -54,39 +54,40 @@ const Wax = props => { if (!application) return null; const WaxOnchange = onChange || (v => true); - const finalOnChange = debounce( - // eslint-disable-next-line no-shadow - value => { - /* HACK alter toDOM of footnote, because of how PM treats inline nodes - with content */ - if (schema.nodes.footnote) { - const old = schema.nodes.footnote.spec.toDOM; - schema.nodes.footnote.spec.toDOM = node => { - // eslint-disable-next-line prefer-rest-params - old.apply(this); - return ['footnote', node.attrs, 0]; - }; - } + const finalOnChange = () => {}; + // const finalOnChange = debounce( + // // eslint-disable-next-line no-shadow + // value => { + // /* HACK alter toDOM of footnote, because of how PM treats inline nodes + // with content */ + // if (schema.nodes.footnote) { + // const old = schema.nodes.footnote.spec.toDOM; + // schema.nodes.footnote.spec.toDOM = node => { + // // eslint-disable-next-line prefer-rest-params + // old.apply(this); + // return ['footnote', node.attrs, 0]; + // }; + // } - if (targetFormat === 'JSON') { - WaxOnchange(value); - } else { - const serialize = serializer(schema); - WaxOnchange(serialize(value)); - } + // if (targetFormat === 'JSON') { + // WaxOnchange(value); + // } else { + // const serialize = serializer(schema); + // WaxOnchange(serialize(value)); + // } - if (schema.nodes.footnote) { - const old = schema.nodes.footnote.spec.toDOM; - schema.nodes.footnote.spec.toDOM = node => { - // eslint-disable-next-line prefer-rest-params - old.apply(this); - return ['footnote', node.attrs]; - }; - } - }, - 1000, - { maxWait: 5000 }, - ); + // if (schema.nodes.footnote) { + // const old = schema.nodes.footnote.spec.toDOM; + // schema.nodes.footnote.spec.toDOM = node => { + // // eslint-disable-next-line prefer-rest-params + // old.apply(this); + // return ['footnote', node.attrs]; + // }; + // } + // }, + // 1000, + // { maxWait: 5000 }, + // ); const TrackChange = application.config.get('config.EnableTrackChangeService'); const Layout = application.container.get('Layout'); diff --git a/wax-prosemirror-core/src/useWaxOptions.js b/wax-prosemirror-core/src/WaxOptions.js similarity index 87% rename from wax-prosemirror-core/src/useWaxOptions.js rename to wax-prosemirror-core/src/WaxOptions.js index 41d0fbb69a8e80b5fc36394ee7e73d2e738ea69c..5f8bad7dfd7ac584ab67234665f44b131a6a57da 100644 --- a/wax-prosemirror-core/src/useWaxOptions.js +++ b/wax-prosemirror-core/src/WaxOptions.js @@ -15,9 +15,7 @@ const parser = schema => { }; }; -export default ({ placeholder, targetFormat, value }) => { - const context = useContext(WaxContext); - +export default ({ placeholder, targetFormat, value, schema, plugins }) => { let finalPlugins = []; // eslint-disable-next-line no-shadow @@ -25,13 +23,12 @@ export default ({ placeholder, targetFormat, value }) => { return Placeholder({ content: placeholder }); }; + console.log(plugins); finalPlugins = defaultPlugins.concat([ createPlaceholder(placeholder), - ...context.app.getPlugins(), + ...plugins, ]); - const schema = context.app.getSchema(); - const WaxOptions = { schema, plugins: finalPlugins, diff --git a/wax-prosemirror-core/src/WaxView.js b/wax-prosemirror-core/src/WaxView.js index 3094211059b022d9d2a6c1c847e40fc43842b2ba..7f6e5b04f933e77108961a93fcbdaefa4e145c6c 100644 --- a/wax-prosemirror-core/src/WaxView.js +++ b/wax-prosemirror-core/src/WaxView.js @@ -1,4 +1,10 @@ -import React, { useRef, useContext, useCallback, useMemo } from 'react'; +import React, { + useRef, + useContext, + useCallback, + useMemo, + useEffect, +} from 'react'; import applyDevTools from 'prosemirror-dev-tools'; import { EditorState } from 'prosemirror-state'; @@ -10,7 +16,7 @@ import ComponentPlugin from './ComponentPlugin'; import { WaxContext } from './WaxContext'; import { PortalContext } from './PortalContext'; import transformPasted from './helpers/TransformPasted'; -import useWaxOptions from './useWaxOptions'; +import WaxOptions from './WaxOptions'; let previousDoc; @@ -29,14 +35,17 @@ export default props => { export default props => { const { readonly, onBlur, debug, autoFocus, user, targetFormat } = props; const editorRef = useRef(); - let view; + const context = useContext(WaxContext); const { createPortal } = useContext(PortalContext); context.app.setContext({ ...context, createPortal }); - context.app.bootServices(); - const options = useWaxOptions(props); + const schema = context.app.getSchema(); + + if (!view) { + context.app.bootServices(); + } const setEditorRef = useCallback( // eslint-disable-next-line consistent-return @@ -47,6 +56,14 @@ export default props => { // clean up the unmount if you need to. } if (node) { + const options = WaxOptions({ + ...props, + schema, + plugins: context.app.getPlugins(), + }); + + console.log(options); + // debugger; view = new EditorView( { mount: node }, {