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'; ...@@ -16,7 +16,7 @@ import {treeBeardTheme, getTreeDecorators} from './TreeOverrides';
import PartBrowserItem from './PartBrowserItem'; import PartBrowserItem from './PartBrowserItem';
import PartBrowserDragPreview from './PartBrowserDragPreview'; import PartBrowserDragPreview from './PartBrowserDragPreview';
import defaultSVG from '../../utils/defaultSVG'; import getSVGData from '../../utils/getSVGData';
const TREE_PATH_SEP = '$'; const TREE_PATH_SEP = '$';
const EXPAND_ALL = false; const EXPAND_ALL = false;
...@@ -120,7 +120,7 @@ class PartBrowser extends SingleConnectedNode { ...@@ -120,7 +120,7 @@ class PartBrowser extends SingleConnectedNode {
id: metaNode.getId(), id: metaNode.getId(),
name: getTitle(metaNode), name: getTitle(metaNode),
treePath: getTreePath(metaNode), treePath: getTreePath(metaNode),
svg: defaultSVG, svg: getSVGData(metaNode),
}; };
}); });
......
...@@ -5,7 +5,7 @@ import {DragLayer} from 'react-dnd'; ...@@ -5,7 +5,7 @@ import {DragLayer} from 'react-dnd';
// noinspection JSUnresolvedVariable // noinspection JSUnresolvedVariable
import {Samy} from 'react-samy-svg'; import {Samy} from 'react-samy-svg';
import DRAG_TYPES from '../../utils/dragTypes'; import DRAG_TYPES from '../../utils/dragTypes';
import defaultSVG from '../../utils/defaultSVG'; import getSVGData from '../../utils/getSVGData';
// DragLayer // DragLayer
function collect(monitor) { function collect(monitor) {
...@@ -53,7 +53,7 @@ class PartBrowserDragPreview extends Component { ...@@ -53,7 +53,7 @@ class PartBrowserDragPreview extends Component {
const {x, y} = {x: currentOffset.x - initialOffset.x, y: currentOffset.y - initialOffset.y}; const {x, y} = {x: currentOffset.x - initialOffset.x, y: currentOffset.y - initialOffset.y};
const transform = `translate(${x}px, ${y}px)`; const transform = `translate(${x}px, ${y}px)`;
const {base, bbox} = defaultSVG; const {base, bbox} = item.nodeData.svg;
return ( return (
<Samy <Samy
......
...@@ -13,7 +13,7 @@ import SVGRegistryBasedCanvasItemPort from './SVGRegistryBasedCanvasItemPort'; ...@@ -13,7 +13,7 @@ import SVGRegistryBasedCanvasItemPort from './SVGRegistryBasedCanvasItemPort';
import Territory from '../Territory/Territory'; import Territory from '../Territory/Territory';
import BasicConnection from '../BasicConnection/BasicConnection'; import BasicConnection from '../BasicConnection/BasicConnection';
import Z_LEVELS from '../../utils/zLevels'; import Z_LEVELS from '../../utils/zLevels';
import defaultSVG from '../../utils/defaultSVG'; import getSVGData from '../../utils/getSVGData';
const canvasItemSource = { const canvasItemSource = {
beginDrag(props) { beginDrag(props) {
...@@ -62,7 +62,7 @@ class SVGRegistryBasedCanvasItem extends Component { ...@@ -62,7 +62,7 @@ class SVGRegistryBasedCanvasItem extends Component {
state = { state = {
position: null, position: null,
showActions: false, showActions: false,
svg: defaultSVG, svg: getSVGData(),
childrenName2Id: {}, childrenName2Id: {},
childInfo: {}, childInfo: {},
isConnection: null, isConnection: null,
...@@ -224,7 +224,7 @@ class SVGRegistryBasedCanvasItem extends Component { ...@@ -224,7 +224,7 @@ class SVGRegistryBasedCanvasItem extends Component {
this.setState({ this.setState({
position: null, position: null,
showActions: false, showActions: false,
svg: defaultSVG, svg: getSVGData(),
childrenName2Id: {}, childrenName2Id: {},
childInfo: {}, childInfo: {},
isConnection: null, isConnection: null,
...@@ -303,13 +303,7 @@ class SVGRegistryBasedCanvasItem extends Component { ...@@ -303,13 +303,7 @@ class SVGRegistryBasedCanvasItem extends Component {
territory[activeNode] = {children: 1}; territory[activeNode] = {children: 1};
} }
const newSvg = { const newSvg = getSVGData(nodeObj);
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
};
this.setState({ this.setState({
position: nodeObj.getRegistry('position'), 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;
Supports Markdown
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