mirror of
https://bitbucket.org/wisemapping/wisemapping-frontend.git
synced 2024-12-22 19:53:49 +01:00
Fix cycle dependency
This commit is contained in:
parent
45ad796c3b
commit
ef3984cfd0
@ -37,7 +37,7 @@ import RelationshipPivot from './RelationshipPivot';
|
||||
import Relationship from './Relationship';
|
||||
|
||||
import TopicEventDispatcher, { TopicEvent } from './TopicEventDispatcher';
|
||||
import TopicFeature from './TopicFeature';
|
||||
import TopicFeatureFactory from './TopicFeature';
|
||||
|
||||
import { create } from './NodeGraphUtils';
|
||||
|
||||
@ -952,7 +952,7 @@ class Designer extends Events {
|
||||
addIconType(iconType) {
|
||||
const topicsIds = this.getModel().filterTopicsIds();
|
||||
if (topicsIds.length > 0) {
|
||||
this._actionDispatcher.addFeatureToTopic(topicsIds[0], TopicFeature.Icon.id, {
|
||||
this._actionDispatcher.addFeatureToTopic(topicsIds[0], TopicFeatureFactory.Icon.id, {
|
||||
id: iconType,
|
||||
});
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ import {
|
||||
import NodeGraph from './NodeGraph';
|
||||
import TopicConfig from './TopicConfig';
|
||||
import TopicStyle from './TopicStyle';
|
||||
import TopicFeature from './TopicFeature';
|
||||
import TopicFeatureFactory from './TopicFeature';
|
||||
import ConnectionLine from './ConnectionLine';
|
||||
import IconGroup from './IconGroup';
|
||||
import FadeEffect from './util/FadeEffect';
|
||||
@ -311,8 +311,8 @@ class Topic extends NodeGraph {
|
||||
const model = this.getModel();
|
||||
const featuresModel = model.getFeatures();
|
||||
featuresModel.forEach((f) => {
|
||||
const icon = TopicFeature.createIcon(this, f, this.isReadOnly());
|
||||
result.addIcon(icon, f.getType() === TopicFeature.Icon.id && !this.isReadOnly());
|
||||
const icon = TopicFeatureFactory.createIcon(this, f, this.isReadOnly());
|
||||
result.addIcon(icon, f.getType() === TopicFeatureFactory.Icon.id && !this.isReadOnly());
|
||||
});
|
||||
|
||||
return result;
|
||||
@ -331,10 +331,10 @@ class Topic extends NodeGraph {
|
||||
const model = this.getModel();
|
||||
model.addFeature(featureModel);
|
||||
|
||||
const result = TopicFeature.createIcon(this, featureModel, this.isReadOnly());
|
||||
const result = TopicFeatureFactory.createIcon(this, featureModel, this.isReadOnly());
|
||||
iconGroup.addIcon(
|
||||
result,
|
||||
featureModel.getType() === TopicFeature.Icon.id && !this.isReadOnly(),
|
||||
featureModel.getType() === TopicFeatureFactory.Icon.id && !this.isReadOnly(),
|
||||
);
|
||||
|
||||
this._adjustShapes();
|
||||
@ -764,7 +764,7 @@ class Topic extends NodeGraph {
|
||||
const model = this.getModel();
|
||||
const editorModel = {
|
||||
getValue() {
|
||||
const notes = model.findFeatureByType(TopicFeature.Note.id);
|
||||
const notes = model.findFeatureByType(TopicFeatureFactory.Note.id);
|
||||
let result;
|
||||
if (notes.length > 0) result = notes[0].getText();
|
||||
|
||||
@ -773,7 +773,7 @@ class Topic extends NodeGraph {
|
||||
|
||||
setValue(value) {
|
||||
const dispatcher = ActionDispatcher.getInstance();
|
||||
const notes = model.findFeatureByType(TopicFeature.Note.id);
|
||||
const notes = model.findFeatureByType(TopicFeatureFactory.Note.id);
|
||||
if (!$defined(value)) {
|
||||
const featureId = notes[0].getId();
|
||||
dispatcher.removeFeatureFromTopic(topicId, featureId);
|
||||
@ -782,7 +782,7 @@ class Topic extends NodeGraph {
|
||||
text: value,
|
||||
});
|
||||
} else {
|
||||
dispatcher.addFeatureToTopic(topicId, TopicFeature.Note.id, {
|
||||
dispatcher.addFeatureToTopic(topicId, TopicFeatureFactory.Note.id, {
|
||||
text: value,
|
||||
});
|
||||
}
|
||||
@ -800,7 +800,7 @@ class Topic extends NodeGraph {
|
||||
const editorModel = {
|
||||
getValue() {
|
||||
// @param {mindplot.model.LinkModel[]} links
|
||||
const links = model.findFeatureByType(TopicFeature.Link.id);
|
||||
const links = model.findFeatureByType(TopicFeatureFactory.Link.id);
|
||||
let result;
|
||||
if (links.length > 0) result = links[0].getUrl();
|
||||
|
||||
@ -809,7 +809,7 @@ class Topic extends NodeGraph {
|
||||
|
||||
setValue(value) {
|
||||
const dispatcher = ActionDispatcher.getInstance();
|
||||
const links = model.findFeatureByType(TopicFeature.Link.id);
|
||||
const links = model.findFeatureByType(TopicFeatureFactory.Link.id);
|
||||
if (!$defined(value)) {
|
||||
const featureId = links[0].getId();
|
||||
dispatcher.removeFeatureFromTopic(topicId, featureId);
|
||||
@ -818,7 +818,7 @@ class Topic extends NodeGraph {
|
||||
url: value,
|
||||
});
|
||||
} else {
|
||||
dispatcher.addFeatureToTopic(topicId, TopicFeature.Link.id, {
|
||||
dispatcher.addFeatureToTopic(topicId, TopicFeatureFactory.Link.id, {
|
||||
url: value,
|
||||
});
|
||||
}
|
||||
|
@ -24,53 +24,25 @@ import LinkIcon from './LinkIcon';
|
||||
import NoteModel from './model/NoteModel';
|
||||
import NoteIcon from './NoteIcon';
|
||||
|
||||
const TopicFeature = {
|
||||
const TopicFeatureFactory = {
|
||||
/** the icon object */
|
||||
Icon: {
|
||||
id: IconModel.FEATURE_TYPE,
|
||||
model: IconModel,
|
||||
icon: ImageIcon,
|
||||
},
|
||||
|
||||
/** the link object */
|
||||
Link: {
|
||||
id: LinkModel.FEATURE_TYPE,
|
||||
model: LinkModel,
|
||||
icon: LinkIcon,
|
||||
},
|
||||
|
||||
/** the note object */
|
||||
Note: {
|
||||
id: NoteModel.FEATURE_TYPE,
|
||||
model: NoteModel,
|
||||
icon: NoteIcon,
|
||||
},
|
||||
|
||||
/**
|
||||
* @param id the feature metadata id
|
||||
* @return {Boolean} returns true if the given id is contained in the metadata array
|
||||
*/
|
||||
isSupported(id) {
|
||||
return TopicFeature._featuresMetadataById.some((elem) => elem.id === id);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param type
|
||||
* @param attributes
|
||||
* @throws will throw an error if type is null or undefined
|
||||
* @throws will throw an error if attributes is null or undefined
|
||||
* @return {mindplot.model.FeatureModel} a new instance of the feature model subclass matching
|
||||
* the topic feature
|
||||
*/
|
||||
createModel(type, attributes) {
|
||||
$assert(type, 'type can not be null');
|
||||
$assert(attributes, 'attributes can not be null');
|
||||
|
||||
const { model: Model } = TopicFeature._featuresMetadataById
|
||||
.filter((elem) => elem.id === type)[0];
|
||||
return new Model(attributes);
|
||||
},
|
||||
|
||||
/**
|
||||
* @param {mindplot.Topic} topic
|
||||
* @param {mindplot.model.FeatureModel} model
|
||||
@ -83,12 +55,12 @@ const TopicFeature = {
|
||||
$assert(topic, 'topic can not be null');
|
||||
$assert(model, 'model can not be null');
|
||||
|
||||
const { icon: Icon } = TopicFeature._featuresMetadataById
|
||||
const { icon: Icon } = TopicFeatureFactory._featuresMetadataById
|
||||
.filter((elem) => elem.id === model.getType())[0];
|
||||
return new Icon(topic, model, readOnly);
|
||||
},
|
||||
};
|
||||
|
||||
TopicFeature._featuresMetadataById = [TopicFeature.Icon, TopicFeature.Link, TopicFeature.Note];
|
||||
TopicFeatureFactory._featuresMetadataById = [TopicFeatureFactory.Icon, TopicFeatureFactory.Link, TopicFeatureFactory.Note];
|
||||
|
||||
export default TopicFeature;
|
||||
export default TopicFeatureFactory;
|
||||
|
@ -4,10 +4,7 @@ import Mindmap from "src/components/model/Mindmap";
|
||||
|
||||
class TextExporter implements Exporter {
|
||||
export(mindplot: Mindmap): string {
|
||||
|
||||
|
||||
|
||||
throw new Error("Method not implemented.");
|
||||
return "some value";
|
||||
}
|
||||
}
|
||||
export default TextExporter;
|
@ -0,0 +1,42 @@
|
||||
import { $assert } from '@wisemapping/core-js';
|
||||
import IconModel from './IconModel';
|
||||
import LinkModel from './LinkModel';
|
||||
import NoteModel from './NoteModel';
|
||||
|
||||
const FeatureModelFactory = {
|
||||
Icon: {
|
||||
id: IconModel.FEATURE_TYPE,
|
||||
model: IconModel,
|
||||
},
|
||||
|
||||
Link: {
|
||||
id: LinkModel.FEATURE_TYPE,
|
||||
model: LinkModel,
|
||||
},
|
||||
|
||||
/** the note object */
|
||||
Note: {
|
||||
id: NoteModel.FEATURE_TYPE,
|
||||
model: NoteModel,
|
||||
},
|
||||
|
||||
createModel(type, attributes) {
|
||||
$assert(type, 'type can not be null');
|
||||
$assert(attributes, 'attributes can not be null');
|
||||
|
||||
const { model: Model } = FeatureModelFactory._featuresMetadataById
|
||||
.filter((elem) => elem.id === type)[0];
|
||||
return new Model(attributes);
|
||||
},
|
||||
/**
|
||||
* @param id the feature metadata id
|
||||
* @return {Boolean} returns true if the given id is contained in the metadata array
|
||||
*/
|
||||
isSupported(id) {
|
||||
return FeatureModelFactory._featuresMetadataById.some((elem) => elem.id === id);
|
||||
},
|
||||
};
|
||||
|
||||
FeatureModelFactory._featuresMetadataById = [FeatureModelFactory.Icon, FeatureModelFactory.Link, FeatureModelFactory.Note];
|
||||
|
||||
export default FeatureModelFactory;
|
@ -18,7 +18,7 @@
|
||||
import { $assert, $defined } from '@wisemapping/core-js';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import INodeModel from './INodeModel';
|
||||
import TopicFeature from '../TopicFeature';
|
||||
import FeatureModelFactory from './FeatureModelFactory';
|
||||
|
||||
class NodeModel extends INodeModel {
|
||||
constructor(type, mindmap, id) {
|
||||
@ -40,7 +40,7 @@ class NodeModel extends INodeModel {
|
||||
* @return {mindplot.model.FeatureModel} the created feature model
|
||||
*/
|
||||
createFeature(type, attributes) {
|
||||
return TopicFeature.createModel(type, attributes);
|
||||
return FeatureModelFactory.createModel(type, attributes);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -20,7 +20,7 @@ import {
|
||||
import ModelCodeName from './ModelCodeName';
|
||||
import Mindmap from '../model/Mindmap';
|
||||
import INodeModel from '../model/INodeModel';
|
||||
import TopicFeature from '../TopicFeature';
|
||||
import FeatureModelFactory from '../model/FeatureModelFactory';
|
||||
|
||||
class XMLSerializerBeta {
|
||||
toXML(mindmap) {
|
||||
@ -306,16 +306,16 @@ class XMLSerializerBeta {
|
||||
_deserializeIcon(domElem) {
|
||||
let icon = domElem.getAttribute('id');
|
||||
icon = icon.replace('images/', 'icons/legacy/');
|
||||
return TopicFeature.createModel(TopicFeature.Icon.id, { id: icon });
|
||||
return FeatureModelFactory.createModel(FeatureModelFactory.Icon.id, { id: icon });
|
||||
}
|
||||
|
||||
_deserializeLink(domElem) {
|
||||
return TopicFeature.createModel(TopicFeature.Link.id, { url: domElem.getAttribute('url') });
|
||||
return FeatureModelFactory.createModel(FeatureModelFactory.Link.id, { url: domElem.getAttribute('url') });
|
||||
}
|
||||
|
||||
_deserializeNote(domElem) {
|
||||
const text = domElem.getAttribute('text');
|
||||
return TopicFeature.createModel(TopicFeature.Note.id, { text: text == null ? ' ' : text });
|
||||
return FeatureModelFactory.createModel(FeatureModelFactory.Note.id, { text: text == null ? ' ' : text });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -19,8 +19,8 @@ import { $assert, $defined, createDocument } from '@wisemapping/core-js';
|
||||
import { Point } from '@wisemapping/web2d';
|
||||
import Mindmap from '../model/Mindmap';
|
||||
import INodeModel, { TopicShape } from '../model/INodeModel';
|
||||
import TopicFeature from '../TopicFeature';
|
||||
import ConnectionLine from '../ConnectionLine';
|
||||
import FeatureModelFactory from '../model/FeatureModelFactory';
|
||||
|
||||
class XMLSerializerPela {
|
||||
toXML(mindmap) {
|
||||
@ -371,7 +371,7 @@ class XMLSerializerPela {
|
||||
if (child.tagName === 'topic') {
|
||||
const childTopic = this._deserializeNode(child, mindmap);
|
||||
childTopic.connectTo(topic);
|
||||
} else if (TopicFeature.isSupported(child.tagName)) {
|
||||
} else if (FeatureModelFactory.isSupported(child.tagName)) {
|
||||
// Load attributes ...
|
||||
const namedNodeMap = child.attributes;
|
||||
const attributes = {};
|
||||
@ -388,7 +388,7 @@ class XMLSerializerPela {
|
||||
|
||||
// Create a new element ....
|
||||
const featureType = child.tagName;
|
||||
const feature = TopicFeature.createModel(featureType, attributes);
|
||||
const feature = FeatureModelFactory.createModel(featureType, attributes);
|
||||
topic.addFeature(feature);
|
||||
} else if (child.tagName === 'text') {
|
||||
const nodeText = XMLSerializerPela._deserializeNodeText(child);
|
||||
|
@ -22,6 +22,7 @@ import Mindmap from './components/model/Mindmap';
|
||||
import PersistenceManager from './components/PersistenceManager';
|
||||
import Designer from './components/Designer';
|
||||
import LocalStorageManager from './components/LocalStorageManager';
|
||||
import TxtExporter from './components/export/TxtExporter';
|
||||
|
||||
import Menu from './components/widget/Menu';
|
||||
|
||||
@ -36,4 +37,5 @@ export {
|
||||
LocalStorageManager,
|
||||
Menu,
|
||||
DesignerBuilder,
|
||||
};
|
||||
TxtExporter,
|
||||
};
|
||||
|
@ -1,5 +1,9 @@
|
||||
import TxtExporter from '../../src/components/export/TxtExporter';
|
||||
import Mindmap from '../../src/components/model/Mindmap';
|
||||
|
||||
test('adds 1 + 2 to equal 3', () => {
|
||||
|
||||
const m = new Mindmap();
|
||||
|
||||
const exporter = new TxtExporter();
|
||||
console.log(exporter.export(m));
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user