mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-12-22 19:53:49 +01:00
Complete WiseXMLExporter implementation
This commit is contained in:
parent
43d264e87d
commit
2fa5434bf9
@ -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:
|
||||
|
@ -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";
|
||||
|
@ -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<string>;
|
||||
}
|
||||
|
@ -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
|
@ -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";
|
||||
|
||||
|
@ -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;
|
41
packages/mindplot/src/components/export/WiseXMLExporter.ts
Normal file
41
packages/mindplot/src/components/export/WiseXMLExporter.ts
Normal file
@ -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<string> {
|
||||
|
||||
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;
|
@ -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);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user