diff --git a/editors/editoria/package.json b/editors/editoria/package.json index 339f2ec357d134b3f730b41b96dccedb3c706c7b..f591410f11e4c126fbb8474de91868703c1f222f 100644 --- a/editors/editoria/package.json +++ b/editors/editoria/package.json @@ -17,7 +17,6 @@ }, "scripts": { "start": "react-app-rewired start", - "build": "lerna run build && react-app-rewired start", "test": "react-app-rewired test --env=jsdom", "eject": "react-scripts eject" }, diff --git a/package.json b/package.json index c5a676d1840f5e3d43b60dd90e95241bd967cfe4..08a39a25141b739f37949d2a753993c27507778b 100644 --- a/package.json +++ b/package.json @@ -19,7 +19,7 @@ "clean:packages": "lerna clean --yes", "clean:root": "rm -rf node_modules", "reset": "yarn clean && yarn", - "build": "lerna run build --concurrency=1 --stream", + "build": "lerna run build", "editoria": "cd editors/editoria && yarn start" }, "dependencies": {}, diff --git a/wax-prosemirror-components/package.json b/wax-prosemirror-components/package.json index c172251d92b316a89917e4e9d9ed5991a67ba30b..53802e8b9ab71e6cc74f1711a94d507c135b1d30 100644 --- a/wax-prosemirror-components/package.json +++ b/wax-prosemirror-components/package.json @@ -4,7 +4,7 @@ "version": "0.0.7", "description": "Wax prosemirror UI components", "license": "MIT", - "main": "index.js", + "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "BABEL_ENV=production rollup -c" diff --git a/wax-prosemirror-core/package.json b/wax-prosemirror-core/package.json index 975c992339563b3ae4b2a90116c1b444427728e8..98e5a904caffaf1d2d9582fbafc6137d4a573009 100644 --- a/wax-prosemirror-core/package.json +++ b/wax-prosemirror-core/package.json @@ -4,7 +4,7 @@ "version": "0.0.7", "description": "Wax prosemirror core", "license": "MIT", - "main": "index.js", + "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "BABEL_ENV=production rollup -c" diff --git a/wax-prosemirror-core/src/Application.js b/wax-prosemirror-core/src/Application.js index fbe681b5c98b31c0f0d5dee7d39fd2901d41d387..77344349307396d6c6927ce8d92ed1fbd44b6792 100644 --- a/wax-prosemirror-core/src/Application.js +++ b/wax-prosemirror-core/src/Application.js @@ -1,6 +1,6 @@ import { Container } from "inversify"; import "reflect-metadata"; -//import deepmerge from "deepmerge"; +import deepmerge from "deepmerge"; import Config from "./config/Config"; import defaultConfig from "./config/defaultConfig"; import PmPlugins from "./PmPlugins"; @@ -18,9 +18,9 @@ export default class Application { registerServices() { let count = 0; - while (count < this.config.get("services").length) { - const allServices = this.config.get("services"); - const service = this.config.get("services")[count]; + while (count < this.config.get("config.services").length) { + const allServices = this.config.get("config.services"); + const service = this.config.get("config.services")[count]; /* set App to every service so services can have access to containers and config @@ -40,16 +40,13 @@ export default class Application { } } - setConfig(config) { + setConfig() { this.config = this.container.get("Config"); - Object.keys(config).forEach(conf => { - this.config = this.config.pushToArray(conf, config[conf]); - }); } bootServices() { - const services = this.config.get("services"); - services.forEach(plugin => { + const services = this.config.get("config.services"); + services.forEach((plugin) => { if (plugin.boot) { plugin.boot(); } @@ -66,37 +63,38 @@ export default class Application { } static create(config) { + /* Merge Core Config with User Config */ + const appConfig = deepmerge({ config: defaultConfig }, config, { + customMerge: (key) => { + if (key === "services") { + return (coreService, configService) => { + return coreService.concat(configService); + }; + } + }, + }); + /* Create Container */ const container = new Container(); - const configPlugins = config.config.PmPlugins; /* + Set base bindings for the App to work */ - container - .bind("PmPlugins") - .to(PmPlugins) - .inSingletonScope(); + container.bind("PmPlugins").to(PmPlugins).inSingletonScope(); container.bind("Wax").toFactory(() => new Application(container)); - defaultConfig.services = defaultConfig.services.concat( - config.config.services - ); - - container.bind("config").toConstantValue(defaultConfig); - container - .bind("Config") - .to(Config) - .inSingletonScope(); + container.bind("config").toConstantValue(appConfig); + container.bind("Config").to(Config).inSingletonScope(); /* Start the App */ const app = container.get("Wax"); - app.setConfig(config); - configPlugins.forEach(configPlugin => { + app.setConfig(); + appConfig.config.PmPlugins.forEach((configPlugin) => { app.PmPlugins.add(configPlugin.key, configPlugin); }); app.registerServices(); diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index ed44866f24171f183dc0470d587126efe5ebb95a..7e260db033b0b44a183d9fa7a6536dabafda3c82 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -1,4 +1,4 @@ -import React, { Component } from "react"; +import React, { useEffect, useState } from "react"; import WaxProvider from "./ioc-react"; import Application from "./Application"; @@ -10,7 +10,7 @@ import WaxDOMParser from "./WaxDOMParser"; import WaxView from "./WaxView"; import defaultPlugins from "./plugins/defaultPlugins"; -import placeholder from "./plugins/placeholder"; +import Placeholder from "./plugins/placeholder"; const parser = schema => { const parser = WaxDOMParser.fromSchema(schema); @@ -31,88 +31,100 @@ const serializer = schema => { }; }; +const createApplication = props => { + const application = Application.create(props); + application.getSchema(); + application.bootServices(); + return application; +}; + +const createPlaceholder = placeholder => { + return Placeholder({ content: placeholder }); +}; + const LayoutWrapper = styled.div` display: flex; flex-direction: column; height: 99%; `; -class Wax extends Component { - application = {}; - constructor(props) { - super(props); - this.application = Application.create(props); - const schema = this.application.getSchema(); - this.application.bootServices(); - const { value, onChange } = this.props; - - const WaxOnchange = onChange ? onChange : value => true; - - const editorContent = value ? value : ""; - - const finalPlugins = defaultPlugins.concat([ - placeholder({ content: this.props.placeholder }), - ...this.application.getPlugins() - ]); - - this.WaxOptions = { - schema, - plugins: finalPlugins - }; - - const parse = parser(schema); - const serialize = serializer(schema); - this.WaxOptions.doc = parse(editorContent); - - this.onChange = debounce( - value => { - WaxOnchange(serialize(value)); - }, - 1000, - { maxWait: 5000 } - ); - } - - render() { - const { - autoFocus, - className, - debug, - fileUpload, - layout, - onBlur, - placeholder, - readonly, - TrackChange, - value, - user - } = this.props; - - const Layout = this.application.container.get("Layout"); - if (layout) Layout.setLayout(layout); - const WaxRender = Layout.layoutComponent; - - return ( - <LayoutWrapper className={`${className}`}> - <WaxProvider app={this.application}> - <WaxView - autoFocus={autoFocus} - readonly={readonly} - options={this.WaxOptions} - placeholder={placeholder} - fileUpload={fileUpload} - onBlur={onBlur || (value => true)} - onChange={this.onChange || (value => true)} - debug={debug} - TrackChange={TrackChange} - user={user} - > - {({ editor }) => <WaxRender editor={editor} />} - </WaxView> - </WaxProvider> - </LayoutWrapper> - ); - } -} +const Wax = props => { + let finalPlugins; + let schema; + const [application, setApplication] = useState(); + + useEffect(() => { + setApplication(createApplication(props)); + }, []); + + const { + autoFocus, + className, + debug, + fileUpload, + layout, + onBlur, + placeholder, + readonly, + TrackChange, + value, + user, + onChange + } = props; + + if (!application) return null; + + schema = application.getSchema(); + + const WaxOnchange = onChange ? onChange : value => true; + + const editorContent = value ? value : ""; + + finalPlugins = defaultPlugins.concat([ + createPlaceholder(placeholder), + ...application.getPlugins() + ]); + + const WaxOptions = { + schema, + plugins: finalPlugins + }; + const parse = parser(schema); + const serialize = serializer(schema); + WaxOptions.doc = parse(editorContent); + + const finalOnChange = debounce( + value => { + WaxOnchange(serialize(value)); + }, + 1000, + { maxWait: 5000 } + ); + + const Layout = application.container.get("Layout"); + if (layout) Layout.setLayout(layout); + const WaxRender = Layout.layoutComponent; + + return ( + <LayoutWrapper className={`${className}`}> + <WaxProvider app={application}> + <WaxView + autoFocus={autoFocus} + readonly={readonly} + options={WaxOptions} + placeholder={placeholder} + fileUpload={fileUpload} + onBlur={onBlur || (value => true)} + onChange={finalOnChange || (value => true)} + debug={debug} + TrackChange={TrackChange} + user={user} + > + {({ editor }) => <WaxRender editor={editor} />} + </WaxView> + </WaxProvider> + </LayoutWrapper> + ); +}; export default Wax; diff --git a/wax-prosemirror-core/src/plugins/placeholder.js b/wax-prosemirror-core/src/plugins/placeholder.js index 80a861a932d699e6806d76bc60870be5b390ed1c..9a1595255314421161ae17a4222cffdf09e491a2 100644 --- a/wax-prosemirror-core/src/plugins/placeholder.js +++ b/wax-prosemirror-core/src/plugins/placeholder.js @@ -3,7 +3,6 @@ import { Decoration, DecorationSet } from "prosemirror-view"; const placeHolderText = new PluginKey("placeHolderText"); - export default props => { return new Plugin({ key: placeHolderText, diff --git a/wax-prosemirror-layouts/package.json b/wax-prosemirror-layouts/package.json index 611d994e6e5e56cb311bd4ae287e727fd005d005..cf2dd35e5511f8e3994dee10d7f3b3782165902d 100644 --- a/wax-prosemirror-layouts/package.json +++ b/wax-prosemirror-layouts/package.json @@ -4,7 +4,7 @@ "version": "0.0.7", "description": "Wax prosemirror layouts", "license": "MIT", - "main": "index.js", + "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "BABEL_ENV=production rollup -c" diff --git a/wax-prosemirror-plugins/package.json b/wax-prosemirror-plugins/package.json index f99528f06e8ef021e51416c795de1110baf5ea65..911872ee87f3132bb8faf3ac8b46cf908d8328e0 100644 --- a/wax-prosemirror-plugins/package.json +++ b/wax-prosemirror-plugins/package.json @@ -4,7 +4,7 @@ "version": "0.0.7", "description": "Wax prosemirror plugins", "license": "MIT", - "main": "index.js", + "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "BABEL_ENV=production rollup -c" diff --git a/wax-prosemirror-schema/package.json b/wax-prosemirror-schema/package.json index e0bf5c4103663288a0af26471032d2b5a6239862..6be7c0dd10d8115f8ca88efb822f1d0c4f2af45d 100644 --- a/wax-prosemirror-schema/package.json +++ b/wax-prosemirror-schema/package.json @@ -4,7 +4,7 @@ "version": "0.0.7", "description": "Wax prosemirror schema", "license": "MIT", - "main": "index.js", + "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "BABEL_ENV=production rollup -c" diff --git a/wax-prosemirror-services/package.json b/wax-prosemirror-services/package.json index 67207883b4088e37bbec4058d9ff6bfe4bab3d07..8d4177798a240991a84c0f1ead030061a6e03495 100644 --- a/wax-prosemirror-services/package.json +++ b/wax-prosemirror-services/package.json @@ -4,7 +4,7 @@ "version": "0.0.7", "description": "Wax prosemirror services", "license": "MIT", - "main": "index.js", + "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "BABEL_ENV=production rollup -c" diff --git a/wax-prosemirror-themes/package.json b/wax-prosemirror-themes/package.json index a7ba237db7b39fbc12607eeeac34f7d558d3e95d..9800db0f8bbdcb01adadfcdc0f51fa09cfe17ebf 100644 --- a/wax-prosemirror-themes/package.json +++ b/wax-prosemirror-themes/package.json @@ -4,7 +4,7 @@ "version": "0.0.7", "description": "Wax prosemirror themes", "license": "MIT", - "main": "index.js", + "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "BABEL_ENV=production rollup -c" diff --git a/wax-prosemirror-utilities/package.json b/wax-prosemirror-utilities/package.json index b23a3ff900a85520caa34fe9156d1c48cdf07e3a..b2431f3e6582f327a02087946d746c34e5e9b5b7 100644 --- a/wax-prosemirror-utilities/package.json +++ b/wax-prosemirror-utilities/package.json @@ -4,7 +4,7 @@ "version": "0.0.7", "description": "Wax prosemirror utilities", "license": "MIT", - "main": "index.js", + "main": "dist/index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1", "build": "BABEL_ENV=production rollup -c"