Commit 8b06e02f authored by Patrik Meijer's avatar Patrik Meijer
Browse files

Move svg handling to utils/getSVGData

parent 01911292
......@@ -16,7 +16,7 @@ import {treeBeardTheme, getTreeDecorators} from './TreeOverrides';
import PartBrowserItem from './PartBrowserItem';
import PartBrowserDragPreview from './PartBrowserDragPreview';
import defaultSVG from '../../utils/defaultSVG';
import getSVGData from '../../utils/getSVGData';
const TREE_PATH_SEP = '$';
const EXPAND_ALL = false;
......@@ -120,7 +120,7 @@ class PartBrowser extends SingleConnectedNode {
id: metaNode.getId(),
name: getTitle(metaNode),
treePath: getTreePath(metaNode),
svg: defaultSVG,
svg: getSVGData(metaNode),
};
});
......
......@@ -5,7 +5,7 @@ import {DragLayer} from 'react-dnd';
// noinspection JSUnresolvedVariable
import {Samy} from 'react-samy-svg';
import DRAG_TYPES from '../../utils/dragTypes';
import defaultSVG from '../../utils/defaultSVG';
import getSVGData from '../../utils/getSVGData';
// DragLayer
function collect(monitor) {
......@@ -53,7 +53,7 @@ class PartBrowserDragPreview extends Component {
const {x, y} = {x: currentOffset.x - initialOffset.x, y: currentOffset.y - initialOffset.y};
const transform = `translate(${x}px, ${y}px)`;
const {base, bbox} = defaultSVG;
const {base, bbox} = item.nodeData.svg;
return (
<Samy
......
......@@ -13,7 +13,7 @@ import SVGRegistryBasedCanvasItemPort from './SVGRegistryBasedCanvasItemPort';
import Territory from '../Territory/Territory';
import BasicConnection from '../BasicConnection/BasicConnection';
import Z_LEVELS from '../../utils/zLevels';
import defaultSVG from '../../utils/defaultSVG';
import getSVGData from '../../utils/getSVGData';
const canvasItemSource = {
beginDrag(props) {
......@@ -62,7 +62,7 @@ class SVGRegistryBasedCanvasItem extends Component {
state = {
position: null,
showActions: false,
svg: defaultSVG,
svg: getSVGData(),
childrenName2Id: {},
childInfo: {},
isConnection: null,
......@@ -224,7 +224,7 @@ class SVGRegistryBasedCanvasItem extends Component {
this.setState({
position: null,
showActions: false,
svg: defaultSVG,
svg: getSVGData(),
childrenName2Id: {},
childInfo: {},
isConnection: null,
......@@ -303,13 +303,7 @@ class SVGRegistryBasedCanvasItem extends Component {
territory[activeNode] = {children: 1};
}
const newSvg = {
base: nodeObj.getRegistry('SVGIcon') || defaultSVG.base,
bbox: nodeObj.getRegistry('SVGBbox') || defaultSVG.bbox,
ports: nodeObj.getRegistry('SVGPorts') || defaultSVG.ports,
attributes: nodeObj.getRegistry('SVGAttributes') || defaultSVG.attributes,
// TODO probably would be better to move towards ejs
};
const newSvg = getSVGData(nodeObj);
this.setState({
position: nodeObj.getRegistry('position'),
......
import defaultSVG from './defaultSVG';
const getSVGData = (nodeObj) => {
if (nodeObj) {
return {
base: nodeObj.getRegistry('SVGIcon') || defaultSVG.base,
bbox: nodeObj.getRegistry('SVGBbox') || defaultSVG.bbox,
ports: nodeObj.getRegistry('SVGPorts') || defaultSVG.ports,
attributes: nodeObj.getRegistry('SVGAttributes') || defaultSVG.attributes,
};
}
return defaultSVG;
};
export default getSVGData;
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment