mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-11-11 01:43:23 +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 DragManager from './DragManager';
|
||||||
import RelationshipPivot from './RelationshipPivot';
|
import RelationshipPivot from './RelationshipPivot';
|
||||||
import Relationship from './Relationship';
|
import Relationship from './Relationship';
|
||||||
import SVGExporter from './export/SVGExporter';
|
|
||||||
import BinaryImageExporter from './export/BinaryImageExporter';
|
|
||||||
|
|
||||||
import TopicEventDispatcher, { TopicEvent } from './TopicEventDispatcher';
|
import TopicEventDispatcher, { TopicEvent } from './TopicEventDispatcher';
|
||||||
import TopicFeatureFactory from './TopicFeature';
|
import TopicFeatureFactory from './TopicFeature';
|
||||||
@ -50,6 +48,8 @@ import LayoutManager from './layout/LayoutManager';
|
|||||||
|
|
||||||
import INodeModel, { TopicShape } from './model/INodeModel';
|
import INodeModel, { TopicShape } from './model/INodeModel';
|
||||||
import { $notify } from './widget/ToolbarNotifier';
|
import { $notify } from './widget/ToolbarNotifier';
|
||||||
|
import ImageExpoterFactory from './export/ImageExporterFactory';
|
||||||
|
import TextExporterFactory from './export/TextExporterFactory';
|
||||||
|
|
||||||
class Designer extends Events {
|
class Designer extends Events {
|
||||||
constructor(options, divElement) {
|
constructor(options, divElement) {
|
||||||
@ -360,20 +360,14 @@ class Designer extends Events {
|
|||||||
const svgElement = workspace.getSVGElement();
|
const svgElement = workspace.getSVGElement();
|
||||||
const size = workspace.getSize();
|
const size = workspace.getSize();
|
||||||
|
|
||||||
const mindmap = this._mindmap;
|
|
||||||
|
|
||||||
let exporter;
|
let exporter;
|
||||||
switch (formatType) {
|
switch (formatType) {
|
||||||
case 'svg': {
|
case 'svg' || 'png' || 'jpg': {
|
||||||
exporter = new SVGExporter(mindmap, svgElement);
|
exporter = ImageExpoterFactory.create(formatType, this._mindmap, svgElement, size.width, size.height);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 'png': {
|
case 'wxml': {
|
||||||
exporter = new BinaryImageExporter(mindmap, svgElement, size.width, size.height, 'image/png');
|
exporter = TextExporterFactory.create(formatType, this._mindmap);
|
||||||
break;
|
|
||||||
}
|
|
||||||
case 'jpeg': {
|
|
||||||
exporter = new BinaryImageExporter(mindmap, svgElement, size.width, size.height, 'image/jpeg');
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
default:
|
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 { Mindmap } from "../..";
|
||||||
import Exporter from "./Exporter";
|
import Exporter from "./Exporter";
|
||||||
import SVGExporter from "./SVGExporter";
|
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 {
|
interface Exporter {
|
||||||
export(): Promise<string>;
|
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 { Mindmap } from "../..";
|
||||||
import Exporter from "./Exporter";
|
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, () => {
|
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) => {
|
.then((url) => {
|
||||||
// Create hidden anchor to force download ...
|
// Create hidden anchor to force download ...
|
||||||
const anchor = document.createElement('a');
|
const anchor = document.createElement('a');
|
||||||
anchor.style = 'display: none';
|
anchor.style = 'display: none';
|
||||||
anchor.download = `${mapId}.${formatType}`;
|
anchor.download = `${mapId}.${formatExtension}`;
|
||||||
anchor.href = url;
|
anchor.href = url;
|
||||||
document.body.appendChild(anchor);
|
document.body.appendChild(anchor);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user