Added importer wisemapping

This commit is contained in:
Ezequiel-Vega 2022-03-21 16:02:37 -03:00
parent 968623e4f0
commit cb9f0e7abe
6 changed files with 84 additions and 18 deletions

View File

@ -25,15 +25,17 @@ import XMLSerializerFactory from '../persistence/XMLSerializerFactory';
export default class FreemindImporter extends Importer { export default class FreemindImporter extends Importer {
private mindmap: Mindmap; private mindmap: Mindmap;
private freemindInput: string;
private freemindMap: FreemindMap; private freemindMap: FreemindMap;
private nodesmap: Map<string, NodeModel>; private nodesmap: Map<string, NodeModel>;
private relationship: Array<RelationshipModel>; private relationship: Array<RelationshipModel>;
constructor(map: FreemindMap) { constructor(map: string) {
super(); super();
this.freemindMap = map; this.freemindInput = map;
} }
import(nameMap: string, description: string): Promise<string> { import(nameMap: string, description: string): Promise<string> {
@ -42,6 +44,10 @@ export default class FreemindImporter extends Importer {
this.relationship = new Array<RelationshipModel>(); this.relationship = new Array<RelationshipModel>();
let wiseTopicId = 0; let wiseTopicId = 0;
const parser = new DOMParser();
const freemindDoc = parser.parseFromString(this.freemindInput, 'application/xml');
this.freemindMap = new FreemindMap().loadFromDom(freemindDoc);
const version: string = this.freemindMap.getVersion(); const version: string = this.freemindMap.getVersion();
if (!version || version.startsWith('freeplane')) { if (!version || version.startsWith('freeplane')) {

View File

@ -1,14 +1,16 @@
import WisemappingImporter from './WisemappingImporter';
import FreemindImporter from './FreemindImporter'; import FreemindImporter from './FreemindImporter';
import FreemindMap from '../export/freemind/Map';
import Importer from './Importer'; import Importer from './Importer';
type textType = 'mm'; type textType = 'wxml' | 'mm';
type mapType = FreemindMap
export default class TextImporterFactory { export default class TextImporterFactory {
static create(type: textType, map: mapType): Importer { static create(type: textType, map: string): Importer {
let result: Importer; let result: Importer;
switch (type) { switch (type) {
case 'wxml':
result = new WisemappingImporter(map);
return result;
case 'mm': case 'mm':
result = new FreemindImporter(map); result = new FreemindImporter(map);
return result; return result;

View File

@ -0,0 +1,29 @@
import Mindmap from '../model/Mindmap';
import XMLSerializerFactory from '../persistence/XMLSerializerFactory';
import Importer from './Importer';
export default class WisemappingImporter extends Importer {
private wisemappingInput: string;
private mindmap: Mindmap;
constructor(map: string) {
super();
this.wisemappingInput = map;
}
import(nameMap: string, description: string): Promise<string> {
const parser = new DOMParser();
const wiseDoc = parser.parseFromString(this.wisemappingInput, 'application/xml');
const serialize = XMLSerializerFactory.createInstanceFromDocument(wiseDoc);
this.mindmap = serialize.loadFromDom(wiseDoc, nameMap);
this.mindmap.setDescription(description);
const mindmapToXml = serialize.toXML(this.mindmap);
const xmlStr = new XMLSerializer().serializeToString(mindmapToXml);
return Promise.resolve(xmlStr);
}
}

View File

@ -26,7 +26,9 @@ import MockPersistenceManager from './components/MockPersistenceManager';
import DesignerOptionsBuilder from './components/DesignerOptionsBuilder'; import DesignerOptionsBuilder from './components/DesignerOptionsBuilder';
import ImageExporterFactory from './components/export/ImageExporterFactory'; import ImageExporterFactory from './components/export/ImageExporterFactory';
import TextExporterFactory from './components/export/TextExporterFactory'; import TextExporterFactory from './components/export/TextExporterFactory';
import TextImporterFactory from './components/import/TextImporterFactory';
import Exporter from './components/export/Exporter'; import Exporter from './components/export/Exporter';
import Importer from './components/import/Importer';
import DesignerKeyboard from './components/DesignerKeyboard'; import DesignerKeyboard from './components/DesignerKeyboard';
import EditorRenderMode from './components/EditorRenderMode'; import EditorRenderMode from './components/EditorRenderMode';
import ImageIcon from './components/ImageIcon'; import ImageIcon from './components/ImageIcon';
@ -61,7 +63,9 @@ export {
EditorRenderMode, EditorRenderMode,
TextExporterFactory, TextExporterFactory,
ImageExporterFactory, ImageExporterFactory,
TextImporterFactory,
Exporter, Exporter,
Importer,
ImageIcon, ImageIcon,
$notify, $notify,
$msg, $msg,

View File

@ -1,5 +1,6 @@
import Button from '@mui/material/Button'; import Button from '@mui/material/Button';
import FormControl from '@mui/material/FormControl'; import FormControl from '@mui/material/FormControl';
import { Importer, TextImporterFactory } from '@wisemapping/mindplot';
import React from 'react'; import React from 'react';
import { FormattedMessage, useIntl } from 'react-intl'; import { FormattedMessage, useIntl } from 'react-intl';
@ -14,7 +15,7 @@ export type ImportModel = {
title: string; title: string;
description?: string; description?: string;
contentType?: string; contentType?: string;
content?: ArrayBuffer | null | string; content?: null | string;
}; };
export type CreateProps = { export type CreateProps = {
@ -69,9 +70,6 @@ const ImportDialog = ({ onClose }: CreateProps): React.ReactElement => {
const file = files[0]; const file = files[0];
// Closure to capture the file information. // Closure to capture the file information.
reader.onload = (event) => { reader.onload = (event) => {
const fileContent = event?.target?.result;
model.content = fileContent;
// Suggest file name ... // Suggest file name ...
const fileName = file.name; const fileName = file.name;
if (fileName) { if (fileName) {
@ -80,11 +78,38 @@ const ImportDialog = ({ onClose }: CreateProps): React.ReactElement => {
model.title = title; model.title = title;
} }
} }
model.contentType =
file.name.lastIndexOf('.wxml') != -1 const extensionFile = file.name.split('.')[1]
? 'application/xml' const extensionAccept = ['wxml', 'mm'];
: 'application/freemind';
if ( extensionAccept.find(ext => ext === extensionFile) ) {
new Error('The file extension is invalid');
}
model.contentType = 'application/xml'
const fileContent = event?.target?.result;
const mapConent: string = typeof fileContent === 'string' ? fileContent : fileContent.toString();
let importer: Importer
switch(extensionFile) {
case 'wxml': {
importer = TextImporterFactory.create('wxml', mapConent);
break;
}
case 'mm': {
importer = TextImporterFactory.create('mm', mapConent);
break;
}
}
importer.import(model.title, model.description)
.then(res => {
model.content = res;
setModel({ ...model }); setModel({ ...model });
})
.catch(e => console.log(e));
}; };
// Read in the image file as a data URL. // Read in the image file as a data URL.