diff --git a/editors/editoria/src/config/config.js b/editors/editoria/src/config/config.js index 669174167eb0446813151bc361a0e1a8d75fdbff..30f8b1ebe0155552dea3b013669e5dc9c0f347c8 100644 --- a/editors/editoria/src/config/config.js +++ b/editors/editoria/src/config/config.js @@ -1,5 +1,22 @@ import { emDash, ellipsis } from "prosemirror-inputrules"; import { columnResizing, tableEditing } from "prosemirror-tables"; +import { + ImageService, + PlaceholderService, + TextStyleService, + InlineAnnotationsService, + LinkService, + ListsService, + ListToolGroupService, + TablesService, + TableToolGroupService, + BaseService, + BaseToolGroupService, + DisplayBlockLevelService, + DisplayToolGroupService, + ImageToolGroupService +} from "wax-prosemirror-services"; + import invisibles, { space, hardBreak, @@ -27,5 +44,25 @@ export default { tableEditing(), // TrackChangePlugin({ options: {} }), invisibles([hardBreak()]) + ], + services: [ + new ListToolGroupService(), + new TextStyleService(), + new PlaceholderService(), + new ImageService(), + new InlineAnnotationsService(), + // new OverlayService() + new LinkService(), + new ListsService(), + new TableToolGroupService(), + new TablesService(), + new BaseService(), + new BaseToolGroupService(), + //new ImageToolGroupService(), + new DisplayBlockLevelService(), + new DisplayToolGroupService(), + // new TextBlockLevelService(), + // new TextToolGroupService() + new ImageToolGroupService() ] }; diff --git a/wax-prosemirror-core/package.json b/wax-prosemirror-core/package.json index ebea988a47b261a27e764293e28454152c8c98d0..00f69f138c4842b858b109cd5db2e79a39e9e438 100644 --- a/wax-prosemirror-core/package.json +++ b/wax-prosemirror-core/package.json @@ -27,7 +27,8 @@ "inversify": "^5.0.1", "inversify-inject-decorators": "^3.1.0", "reflect-metadata": "^0.1.13", - "wax-prosemirror-services": "^0.0.3" + "wax-prosemirror-services": "^0.0.3", + "deepmerge": "^4.2.2" }, "devDependencies": { "mocha": "^3.4.2", diff --git a/wax-prosemirror-core/src/Application.js b/wax-prosemirror-core/src/Application.js index bc376c346905e53de0d6d1077f178b878bdc2d18..6b16d39f4c4c25114aa2cce0aed15fa6d09ae4dc 100644 --- a/wax-prosemirror-core/src/Application.js +++ b/wax-prosemirror-core/src/Application.js @@ -1,5 +1,6 @@ import { Container } from "inversify"; import "reflect-metadata"; +import deepmerge from "deepmerge"; import Config from "./config/Config"; import defaultConfig from "./config/defaultConfig"; import PmPlugins from "./PmPlugins"; @@ -77,6 +78,11 @@ export default class Application { .inSingletonScope(); container.bind("Wax").toFactory(() => new Application(container)); + + defaultConfig.services = defaultConfig.services.concat( + config.config.services + ); + container.bind("config").toConstantValue(defaultConfig); container .bind("Config") diff --git a/wax-prosemirror-core/src/Wax.js b/wax-prosemirror-core/src/Wax.js index 44947d8219097c3788303485020d231b08f20bae..c84b0fd9eddbfa9af5d636bcf9163c6fb6265319 100644 --- a/wax-prosemirror-core/src/Wax.js +++ b/wax-prosemirror-core/src/Wax.js @@ -44,7 +44,6 @@ class Wax extends Component { this.application = Application.create(props); const schema = this.application.getSchema(); this.application.bootServices(); - const { value, onChange } = this.props; const WaxOnchange = onChange ? onChange : value => true; diff --git a/wax-prosemirror-core/src/config/defaultConfig.js b/wax-prosemirror-core/src/config/defaultConfig.js index 9a02cf18e80952213ee5dba6ebffb09e8b96852d..211788c643cf37bde44419deeb22b614a65a2807 100644 --- a/wax-prosemirror-core/src/config/defaultConfig.js +++ b/wax-prosemirror-core/src/config/defaultConfig.js @@ -4,25 +4,7 @@ import { MenuService, RulesService, ShortCutsService, - AnnotationToolGroupService, - /*TODO MOVE FROM DEFAULT CONFIG*/ - ImageService, - PlaceholderService, - TextStyleService, - InlineAnnotationsService, - LinkService, - OverlayService, - ListsService, - ListToolGroupService, - TablesService, - TableToolGroupService, - BaseService, - BaseToolGroupService, - ImageToolGroupService, - TextBlockLevelService, - TextToolGroupService, - DisplayBlockLevelService, - DisplayToolGroupService + AnnotationToolGroupService } from "wax-prosemirror-services"; export default { @@ -32,23 +14,6 @@ export default { new ShortCutsService(), new LayoutService(), new MenuService(), - new AnnotationToolGroupService(), - new ListToolGroupService(), - new DisplayBlockLevelService(), - new DisplayToolGroupService(), - // new TextStyleService(), - new PlaceholderService(), - new ImageService(), - new InlineAnnotationsService(), - // new OverlayService() - new LinkService(), - new ListsService(), - new TableToolGroupService(), - new TablesService(), - new BaseService(), - new BaseToolGroupService(), - new ImageToolGroupService() - // new TextBlockLevelService(), - // new TextToolGroupService() + new AnnotationToolGroupService() ] }; diff --git a/wax-prosemirror-services/src/LinkService/LinkService.js b/wax-prosemirror-services/src/LinkService/LinkService.js index 8c14dc4937f88f244e408e50f5fbe21f9a51f1e3..5dd1e6e40164b53562736dfbeabb1625f1605f76 100644 --- a/wax-prosemirror-services/src/LinkService/LinkService.js +++ b/wax-prosemirror-services/src/LinkService/LinkService.js @@ -17,13 +17,13 @@ export default class LinkService extends Service { register() { this.container.bind("Link").to(LinkTool); - - this.container - .bind("schema") - .toConstantValue({ + const createMark = this.container.get("CreateMark"); + createMark( + { link: linkMark - }) - .whenTargetNamed("mark"); + }, + { toWaxSchema: true } + ); } dependencies = [new OverlayService()]; diff --git a/wax-prosemirror-services/src/LinkService/LinkTool.js b/wax-prosemirror-services/src/LinkService/LinkTool.js index 533c9ae096849f5f74d20cf85f83f5a7c83971fe..93696847b1458640337c7045568d96e903b672c8 100644 --- a/wax-prosemirror-services/src/LinkService/LinkTool.js +++ b/wax-prosemirror-services/src/LinkService/LinkTool.js @@ -16,7 +16,7 @@ export default class LinkTool extends Tools { return true; } - toggleMark(state.config.schema.marks.link, { href: "#" })( + toggleMark(state.config.schema.marks.link, { href: "ld#" })( state, dispatch ); diff --git a/wax-prosemirror-services/src/SchemaService/Schema.js b/wax-prosemirror-services/src/SchemaService/Schema.js index a72582e2af85f09f3fa1f620c044c47164629d86..17b801a959b35f8f9901be94a14c7bcdf5f1e44a 100644 --- a/wax-prosemirror-services/src/SchemaService/Schema.js +++ b/wax-prosemirror-services/src/SchemaService/Schema.js @@ -12,54 +12,38 @@ export default class Schema { prosemirrorSchema = { nodes: {}, marks: {} }; schema = null; - constructor( - @multiInject("schema") - @named("mark") - marks, - @multiInject("schema") - @named("node") - nodes - ) { - this.setNodes(nodes); - this.setMarks(marks); - } - - setNodes(nodes) { - return nodes.map(schemaConfig => { - const name = Object.keys(schemaConfig)[0]; - const config = schemaConfig[name]; + addNode(schemaConfig) { + const name = Object.keys(schemaConfig)[0]; + const config = schemaConfig[name]; - const node = new Node(name); - let nd = {}; + const node = new Node(name); + let nd = {}; - if ((nd = this.has(node))) { - nd.fromJSON(config); - return nd; - } else { - node.fromJSON(config); - this.addSchema(node); + if ((nd = this.has(node))) { + nd.fromJSON(config); + return nd; + } else { + node.fromJSON(config); + this.addSchema(node); - return { [name]: node }; - } - }); + return { [name]: node }; + } } - setMarks(marks) { - return marks.map(schemaConfig => { - const name = Object.keys(schemaConfig)[0]; - const config = schemaConfig[name]; - - const mark = new Mark(name); - let mr = {}; - if ((mr = this.has(mark))) { - mr.fromJSON(config); - return mr; - } else { - mark.fromJSON(config); - this.addSchema(mark); - return { [name]: mark }; - } - }); + addMark(schemaConfig) { + const name = Object.keys(schemaConfig)[0]; + const config = schemaConfig[name]; + + const mark = new Mark(name); + let mr = {}; + if ((mr = this.has(mark))) { + mr.fromJSON(config); + return mr; + } else { + mark.fromJSON(config); + this.addSchema(mark); + return { [name]: mark }; + } } has(instance) { diff --git a/wax-prosemirror-services/src/SchemaService/SchemaService.js b/wax-prosemirror-services/src/SchemaService/SchemaService.js index 925e16bbed0616af249a5dba7f4f9f4130d0d972..e530c3eb488cb64090e70e8bb29460aeae91dea5 100644 --- a/wax-prosemirror-services/src/SchemaService/SchemaService.js +++ b/wax-prosemirror-services/src/SchemaService/SchemaService.js @@ -14,14 +14,10 @@ export default class SchemaService extends Service { this.container.bind("CreateNode").toFactory(context => { return (schema, options = { toWaxSchema: false }) => { + const schemaInstance = context.container.get("Schema"); if (options.toWaxSchema) { - context.container - .bind("schema") - .toConstantValue(schema) - .whenTargetNamed("node"); + schemaInstance.addNode(schema); } else { - const schemaInstance = context.container.get("Schema"); - schemaInstance.addProsemirrorSchema(schema, "nodes"); } }; @@ -29,13 +25,10 @@ export default class SchemaService extends Service { this.container.bind("CreateMark").toFactory(context => { return (schema, options = { toWaxSchema: false }) => { + const schemaInstance = context.container.get("Schema"); if (options.toWaxSchema) { - context.container - .bind("schema") - .toConstantValue(schema) - .whenTargetNamed("mark"); + schemaInstance.addMark(schema); } else { - const schemaInstance = context.container.get("Schema"); schemaInstance.addProsemirrorSchema(schema, "marks"); } };