diff --git a/packages/mindplot/src/components/Designer.js b/packages/mindplot/src/components/Designer.js index 69877292..cfb2a39d 100644 --- a/packages/mindplot/src/components/Designer.js +++ b/packages/mindplot/src/components/Designer.js @@ -35,8 +35,6 @@ import DragConnector from './DragConnector'; import DragManager from './DragManager'; import RelationshipPivot from './RelationshipPivot'; import Relationship from './Relationship'; -import SVGExporter from './export/SVGExporter'; -import BinaryImageExporter from './export/BinaryImageExporter'; import TopicEventDispatcher, { TopicEvent } from './TopicEventDispatcher'; import TopicFeatureFactory from './TopicFeature'; @@ -50,6 +48,8 @@ import LayoutManager from './layout/LayoutManager'; import INodeModel, { TopicShape } from './model/INodeModel'; import { $notify } from './widget/ToolbarNotifier'; +import ImageExpoterFactory from './export/ImageExporterFactory'; +import TextExporterFactory from './export/TextExporterFactory'; class Designer extends Events { constructor(options, divElement) { @@ -360,20 +360,14 @@ class Designer extends Events { const svgElement = workspace.getSVGElement(); const size = workspace.getSize(); - const mindmap = this._mindmap; - let exporter; switch (formatType) { - case 'svg': { - exporter = new SVGExporter(mindmap, svgElement); + case 'svg' || 'png' || 'jpg': { + exporter = ImageExpoterFactory.create(formatType, this._mindmap, svgElement, size.width, size.height); break; } - case 'png': { - exporter = new BinaryImageExporter(mindmap, svgElement, size.width, size.height, 'image/png'); - break; - } - case 'jpeg': { - exporter = new BinaryImageExporter(mindmap, svgElement, size.width, size.height, 'image/jpeg'); + case 'wxml': { + exporter = TextExporterFactory.create(formatType, this._mindmap); break; } default: diff --git a/packages/mindplot/src/components/export/BinaryImageExporter.ts b/packages/mindplot/src/components/export/BinaryImageExporter.ts index c8e61098..a5670b7d 100644 --- a/packages/mindplot/src/components/export/BinaryImageExporter.ts +++ b/packages/mindplot/src/components/export/BinaryImageExporter.ts @@ -1,4 +1,20 @@ - +/* + * Copyright [2021] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import { Mindmap } from "../.."; import Exporter from "./Exporter"; import SVGExporter from "./SVGExporter"; diff --git a/packages/mindplot/src/components/export/Exporter.ts b/packages/mindplot/src/components/export/Exporter.ts index 55bb29c4..9eccd26a 100644 --- a/packages/mindplot/src/components/export/Exporter.ts +++ b/packages/mindplot/src/components/export/Exporter.ts @@ -1,4 +1,20 @@ - +/* + * Copyright [2021] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ interface Exporter { export(): Promise; } diff --git a/packages/mindplot/src/components/export/ImageExporterFactory.ts b/packages/mindplot/src/components/export/ImageExporterFactory.ts new file mode 100644 index 00000000..2205e951 --- /dev/null +++ b/packages/mindplot/src/components/export/ImageExporterFactory.ts @@ -0,0 +1,47 @@ +/* + * Copyright [2021] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { result } from "cypress/types/lodash"; +import { Mindmap } from "../.."; +import BinaryImageExporter from "./BinaryImageExporter"; +import Exporter from "./Exporter"; +import SVGExporter from "./SVGExporter"; + +type type = 'svg' | 'png' | 'jpg'; +class ImageExpoterFactory { + static create(type: type, mindmap: Mindmap, svgElement: Element, width: number, height: number, isCenter: boolean = false): Exporter { + let result; + switch (type) { + case 'svg': { + result = new SVGExporter(mindmap, svgElement); + break; + } + case 'png': { + result = new BinaryImageExporter(mindmap, svgElement, width, height, 'image/png'); + break; + } + case 'jpg': { + result = new BinaryImageExporter(mindmap, svgElement, width, height, 'image/jpeg'); + break; + } + default: + throw new Error(`Unsupported encoding ${type}`); + } + return result; + } +} +export default ImageExpoterFactory diff --git a/packages/mindplot/src/components/export/SVGExporter.ts b/packages/mindplot/src/components/export/SVGExporter.ts index a394fedd..5f8f132d 100644 --- a/packages/mindplot/src/components/export/SVGExporter.ts +++ b/packages/mindplot/src/components/export/SVGExporter.ts @@ -1,4 +1,21 @@ +/* + * Copyright [2021] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ import { Mindmap } from "../.."; import Exporter from "./Exporter"; diff --git a/packages/mindplot/src/components/export/TextExporterFactory.ts b/packages/mindplot/src/components/export/TextExporterFactory.ts new file mode 100644 index 00000000..9a9627df --- /dev/null +++ b/packages/mindplot/src/components/export/TextExporterFactory.ts @@ -0,0 +1,37 @@ +/* + * Copyright [2021] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { Mindmap } from "../.."; +import Exporter from "./Exporter"; +import WiseXMLExporter from "./WiseXMLExporter"; + +type type = 'wxml' | 'txt' | 'mm' | 'csv'; +class TextExporterFactory { + static create(type: type, mindmap: Mindmap): Exporter { + let result: Exporter; + switch (type) { + case 'wxml': + result = new WiseXMLExporter(mindmap); + break; + default: + throw new Error(`Unsupported type ${type}`); + } + return result; + + } +} +export default TextExporterFactory; diff --git a/packages/mindplot/src/components/export/WiseXMLExporter.ts b/packages/mindplot/src/components/export/WiseXMLExporter.ts new file mode 100644 index 00000000..3bd347a0 --- /dev/null +++ b/packages/mindplot/src/components/export/WiseXMLExporter.ts @@ -0,0 +1,41 @@ +/* + * Copyright [2021] [wisemapping] + * + * Licensed under WiseMapping Public License, Version 1.0 (the "License"). + * It is basically the Apache License, Version 2.0 (the "License") plus the + * "powered by wisemapping" text requirement on every single page; + * you may not use this file except in compliance with the License. + * You may obtain a copy of the license at + * + * http://www.wisemapping.org/license + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import { Mindmap } from "../.."; +import XMLSerializerFactory from "../persistence/XMLSerializerFactory"; +import Exporter from "./Exporter"; + +class WiseXMLExporter implements Exporter { + mindmap: Mindmap; + constructor(mindmap: Mindmap) { + this.mindmap = mindmap; + } + + export(): Promise { + + const mindmap = this.mindmap; + const serializer = XMLSerializerFactory.getSerializerFromMindmap(mindmap); + const document: Document = serializer.toXML(mindmap); + + const xmlStr: string = new XMLSerializer().serializeToString(document) + const blob = new Blob([xmlStr], { type: 'application/xml' }); + const result = URL.createObjectURL(blob); + return Promise.resolve(result); + + } +} +export default WiseXMLExporter; \ No newline at end of file diff --git a/packages/mindplot/src/components/widget/Menu.js b/packages/mindplot/src/components/widget/Menu.js index 8715934b..0f1df253 100644 --- a/packages/mindplot/src/components/widget/Menu.js +++ b/packages/mindplot/src/components/widget/Menu.js @@ -212,14 +212,15 @@ class Menu extends IMenu { } this._addButton('export', false, false, () => { - const formatType = 'png'; + // @Todo: this must be configured in the dialog... + const formatExtension = 'wxml'; - designer.export(formatType) + designer.export(formatExtension) .then((url) => { // Create hidden anchor to force download ... const anchor = document.createElement('a'); anchor.style = 'display: none'; - anchor.download = `${mapId}.${formatType}`; + anchor.download = `${mapId}.${formatExtension}`; anchor.href = url; document.body.appendChild(anchor);