From 717f4e023bcb8b99ef94a8595651fbdb7feb4acf Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 29 Dec 2021 17:10:28 -0800 Subject: [PATCH] Add first SVG test --- packages/core-js/src/index.js | 15 +---------- packages/mindplot/package.json | 2 +- .../src/components/export/FreemindExporter.ts | 14 ++++++++++ .../src/components/export/ImageExport.ts | 15 ----------- .../src/components/export/SVGExporter.ts | 23 ++++++++++++++++ .../persistence/XMLSerializerPela.js | 2 +- ....ts => PlainTextExporterTestSuite.test.ts} | 13 ++++------ .../unit/export/SVGExporterTestSuite.test.ts | 26 +++++++++++++++++++ .../unit/{ => export}/samples/welcome.svg | 0 .../unit/{ => export}/samples/welcome.xml | 0 .../src/components/peer/utils/DomUtils.js | 2 +- 11 files changed, 72 insertions(+), 40 deletions(-) create mode 100644 packages/mindplot/src/components/export/FreemindExporter.ts delete mode 100644 packages/mindplot/src/components/export/ImageExport.ts create mode 100644 packages/mindplot/src/components/export/SVGExporter.ts rename packages/mindplot/test/unit/export/{PlainTextExportTestSuite.test.ts => PlainTextExporterTestSuite.test.ts} (66%) create mode 100644 packages/mindplot/test/unit/export/SVGExporterTestSuite.test.ts rename packages/mindplot/test/unit/{ => export}/samples/welcome.svg (100%) rename packages/mindplot/test/unit/{ => export}/samples/welcome.xml (100%) diff --git a/packages/core-js/src/index.js b/packages/core-js/src/index.js index 651c773b..0dc37010 100644 --- a/packages/core-js/src/index.js +++ b/packages/core-js/src/index.js @@ -16,20 +16,7 @@ * limitations under the License. */ -export const innerXML = function (node) { - // summary: - // Implementation of MS's innerXML function. - if ($defined(node.innerXML)) { - return node.innerXML; - // string - } else if ($defined(node.xml)) { - return node.xml; - // string - } else if ($defined(XMLSerializer)) { - return new XMLSerializer().serializeToString(node); - // string - } -}; + /** * Cross-browser implementation of creating an XML document object. diff --git a/packages/mindplot/package.json b/packages/mindplot/package.json index e6da2e57..e4a55f78 100644 --- a/packages/mindplot/package.json +++ b/packages/mindplot/package.json @@ -34,7 +34,7 @@ "dependencies": { "@wisemapping/core-js": "^0.4.0", "@wisemapping/web2d": "^0.4.0", - "jest": "^27.4.3", + "jest": "^27.4.5", "jquery": "3.6.0", "lodash": "^4.17.21" }, diff --git a/packages/mindplot/src/components/export/FreemindExporter.ts b/packages/mindplot/src/components/export/FreemindExporter.ts new file mode 100644 index 00000000..57ba68f4 --- /dev/null +++ b/packages/mindplot/src/components/export/FreemindExporter.ts @@ -0,0 +1,14 @@ +import Exporter from "./Exporter"; +import Mindmap from "../model/Mindmap"; + +class FreemindExporter implements Exporter { + mindplot: Mindmap; + constructor(mindplot: Mindmap) { + this.mindplot = mindplot; + } + + export(): string { + return "TBI"; + } +} +export default FreemindExporter; \ No newline at end of file diff --git a/packages/mindplot/src/components/export/ImageExport.ts b/packages/mindplot/src/components/export/ImageExport.ts deleted file mode 100644 index 9e05b026..00000000 --- a/packages/mindplot/src/components/export/ImageExport.ts +++ /dev/null @@ -1,15 +0,0 @@ - -import Exporter from "./Exporter"; - -class TextExporter implements Exporter { - svgElement: Element; - constructor(svgElement: Element) { - this.svgElement = svgElement; - } - - export(): string { - return "TBI"; - - } -} -export default TextExporter; \ No newline at end of file diff --git a/packages/mindplot/src/components/export/SVGExporter.ts b/packages/mindplot/src/components/export/SVGExporter.ts new file mode 100644 index 00000000..d67da42e --- /dev/null +++ b/packages/mindplot/src/components/export/SVGExporter.ts @@ -0,0 +1,23 @@ + +import { Mindmap } from "../.."; +import Exporter from "./Exporter"; + +class SVGExporter implements Exporter { + svgElement: Element; + constructor(mindmap: Mindmap, svgElement: Element) { + this.svgElement = svgElement; + } + + export(): string { + // Replace all images for in-line images ... + const imagesElements:HTMLCollection = this.svgElement.children + console.log(imagesElements.length); + Array.from(imagesElements).forEach((image) => { + console.log(image); + + }); + return ""; + + } +} +export default SVGExporter; \ No newline at end of file diff --git a/packages/mindplot/src/components/persistence/XMLSerializerPela.js b/packages/mindplot/src/components/persistence/XMLSerializerPela.js index 585d1cef..3f5921e5 100644 --- a/packages/mindplot/src/components/persistence/XMLSerializerPela.js +++ b/packages/mindplot/src/components/persistence/XMLSerializerPela.js @@ -233,7 +233,7 @@ class XMLSerializerPela { // Is a wisemap?. $assert( rootElem.tagName === XMLSerializerPela.MAP_ROOT_NODE, - 'This seem not to be a map document.', + `This seem not to be a map document. Found tag: ${rootElem.tagName}`, ); this._idsMap = {}; diff --git a/packages/mindplot/test/unit/export/PlainTextExportTestSuite.test.ts b/packages/mindplot/test/unit/export/PlainTextExporterTestSuite.test.ts similarity index 66% rename from packages/mindplot/test/unit/export/PlainTextExportTestSuite.test.ts rename to packages/mindplot/test/unit/export/PlainTextExporterTestSuite.test.ts index f27ff0a7..7c8dfa01 100644 --- a/packages/mindplot/test/unit/export/PlainTextExportTestSuite.test.ts +++ b/packages/mindplot/test/unit/export/PlainTextExporterTestSuite.test.ts @@ -1,23 +1,20 @@ import PlainTextExporter from '../../../src/components/export/PlainTextExporter'; import Mindmap from '../../../src/components/model/Mindmap'; -import XMLSerializerTango from '../../../src/components/persistence/XMLSerializerTango'; import fs from 'fs'; import path from 'path'; +import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory'; test('mindplot generation of simple maps', () => { - - // Load DOM ... - const mapStream =fs.readFileSync(path.resolve(__dirname, '../samples/welcome.xml'),{encoding: 'utf-8'}); const parser = new DOMParser(); + + // Load DOM ... + const mapStream =fs.readFileSync(path.resolve(__dirname, './samples/welcome.xml'),{encoding: 'utf-8'}); const document = parser.parseFromString(mapStream.toString(), 'text/xml') // Convert to mindmap ... - const serializer = new XMLSerializerTango(); + const serializer = XMLSerializerFactory.getSerializerFromDocument(document); const mindmap:Mindmap = serializer.loadFromDom(document,'welcome'); - // Inspect ... - console.log(mindmap); - const exporter = new PlainTextExporter(mindmap); console.log(exporter.export()); }); diff --git a/packages/mindplot/test/unit/export/SVGExporterTestSuite.test.ts b/packages/mindplot/test/unit/export/SVGExporterTestSuite.test.ts new file mode 100644 index 00000000..8db9d781 --- /dev/null +++ b/packages/mindplot/test/unit/export/SVGExporterTestSuite.test.ts @@ -0,0 +1,26 @@ +import Mindmap from '../../../src/components/model/Mindmap'; +import fs from 'fs'; +import path from 'path'; +import XMLSerializerFactory from '../../../src/components/persistence/XMLSerializerFactory'; +import SVGExporter from '../../../src/components/export/SVGExporter'; + +test('mindplot generation of simple maps', () => { + const parser = new DOMParser(); + + // Load DOM ... + const mapStream = fs.readFileSync(path.resolve(__dirname, './samples/welcome.xml'), { encoding: 'utf-8' }); + const mapDocument = parser.parseFromString(mapStream.toString(), 'text/xml') + + // Convert to mindmap ... + const serializer = XMLSerializerFactory.getSerializerFromDocument(mapDocument); + const mindmap: Mindmap = serializer.loadFromDom(mapDocument, 'welcome'); + + // Load SVG ... + const svgStream = fs.readFileSync(path.resolve(__dirname, './samples/welcome.svg'), { encoding: 'utf-8' }); + const svgDocument = parser.parseFromString(svgStream.toString(), 'application/xml') + console.log(svgDocument); + + // Inspect ... + const exporter = new SVGExporter(mindmap, svgDocument.documentElement); + console.log(exporter.export()); +}); diff --git a/packages/mindplot/test/unit/samples/welcome.svg b/packages/mindplot/test/unit/export/samples/welcome.svg similarity index 100% rename from packages/mindplot/test/unit/samples/welcome.svg rename to packages/mindplot/test/unit/export/samples/welcome.svg diff --git a/packages/mindplot/test/unit/samples/welcome.xml b/packages/mindplot/test/unit/export/samples/welcome.xml similarity index 100% rename from packages/mindplot/test/unit/samples/welcome.xml rename to packages/mindplot/test/unit/export/samples/welcome.xml diff --git a/packages/web2d/src/components/peer/utils/DomUtils.js b/packages/web2d/src/components/peer/utils/DomUtils.js index 1180f76f..dff713c5 100644 --- a/packages/web2d/src/components/peer/utils/DomUtils.js +++ b/packages/web2d/src/components/peer/utils/DomUtils.js @@ -1,4 +1,4 @@ -/* eslint-disable import/prefer-default-export */ +import { $defined } from '@wisemapping/core-js'; // quick hand-made version of $.css() export const getStyle = (elem, prop) => {