Skip to content
Snippets Groups Projects
Commit 3a3e09a5 authored by Christos's avatar Christos
Browse files

Merge branch 'fix' into 'master'

Fix

See merge request !100
parents 4e0cd8cf e0abb387
No related branches found
No related tags found
1 merge request!100Fix
......@@ -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"
},
......
......@@ -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": {},
......
......@@ -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"
......
......@@ -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"
......
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();
......
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;
......@@ -3,7 +3,6 @@ import { Decoration, DecorationSet } from "prosemirror-view";
const placeHolderText = new PluginKey("placeHolderText");
export default props => {
return new Plugin({
key: placeHolderText,
......
......@@ -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"
......
......@@ -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"
......
......@@ -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"
......
......@@ -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"
......
......@@ -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"
......
......@@ -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"
......
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