Skip to content

Commit 6eed9fc

Browse files
authored
Build update (#42)
* build update
1 parent 9ab732a commit 6eed9fc

File tree

12 files changed

+64
-33
lines changed

12 files changed

+64
-33
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# production
1212
/build
1313
/dist
14+
/styles/dist
1415
/.storybook/utils/jsdoc-ast.json
1516

1617
# misc

.storybook/base-component.jsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
2-
import { Graph } from '../src/index.js';
2+
import Graph from '../src/index.js';
3+
import '../src/styles/index.js';
34

45
class BaseComponent extends React.Component {
56
constructor(props) {

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,16 @@ Create node based visual graphs in the browser. Supports undirected / directed g
66

77
## Getting Started
88

9-
To build the graph library, run the following in the root directory.
9+
First install PCUI Graph into your npm project:
1010

1111
```
12-
npm install
13-
npm run build
12+
npm install @playcanvas/pcui-graph
1413
```
1514

16-
You can then use the library in your own project by including the `dist/index.mjs` file. The graph can then be instantiated as follows:
15+
You can then use the library in your own project by importing the PCUI Graph build and its styling file into your project. The graph can then be instantiated as follows:
1716
```javascript
18-
import { Graph } from 'dist/index.mjs';
17+
import Graph from '@playcanvas/pcui-graph';
18+
import '@playcanvas/pcui-graph/styles';
1919

2020
const schema = {
2121
nodes: {

docs/events.md

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
After creating a graph, you can register a callback for various events. This is achieved using the graphs [on function](./Graph.md#on). The following events are supported:
66

77
```javascript
8-
import { Graph, GRAPH_ACTIONS } from 'dist/pcuiGraph';
8+
import Graph from '@playcanvas/pcui-graph';
99

1010
const schema = { ... };
1111
const graph = new Graph(schema);
@@ -14,75 +14,75 @@ const graph = new Graph(schema);
1414
* @event
1515
* @param {object} args.node - The node that was added
1616
*/
17-
graph.on(GRAPH_ACTIONS.ADD_NODE, ({ node }) => { ... });
17+
graph.on(Graph.GRAPH_ACTIONS.ADD_NODE, ({ node }) => { ... });
1818

1919
/*
2020
* @event
2121
* @param {object} args.node - The node that was deleted
2222
* @param {object} args.edgeData - The edges contained in the graph
2323
* @param {object} args.edges - The edges that were removed when deleting this node
2424
*/
25-
graph.on(GRAPH_ACTIONS.DELETE_NODE, ({ node, edgeData, edges }) => { ... });
25+
graph.on(Graph.GRAPH_ACTIONS.DELETE_NODE, ({ node, edgeData, edges }) => { ... });
2626

2727
/*
2828
* @event
2929
* @param {object} args.node - The node that was selected
3030
* @param {object} args.prevItem - The previously selected item, either a node or an edge
3131
*/
32-
graph.on(GRAPH_ACTIONS.SELECT_NODE, ({ node, prevItem }) => { ... });
32+
graph.on(Graph.GRAPH_ACTIONS.SELECT_NODE, ({ node, prevItem }) => { ... });
3333

3434
/*
3535
* @event
3636
* @param {object} args.node - The node that was updated
3737
* @param {object} args.nodeId - The node id of the node that was updated
3838
*/
39-
graph.on(GRAPH_ACTIONS.UPDATE_NODE_POSITION, ({ node, nodeId }) => { ... });
39+
graph.on(Graph.GRAPH_ACTIONS.UPDATE_NODE_POSITION, ({ node, nodeId }) => { ... });
4040

4141
/*
4242
* @event
4343
* @param {object} args.node - The node that was updated
4444
* @param {object} args.attribute - The name of the attribute that was updated
4545
* @param {object} args.attributeKey - The key of the attribute that was updated
4646
*/
47-
graph.on(GRAPH_ACTIONS.UPDATE_NODE_ATTRIBUTE, ({ node, attribute, attributeKey }) => { ... });
47+
graph.on(Graph.GRAPH_ACTIONS.UPDATE_NODE_ATTRIBUTE, ({ node, attribute, attributeKey }) => { ... });
4848

4949
/*
5050
* @event
5151
* @param {object} args.edge - The edge that was updated
5252
* @param {object} args.edgeId - The id of the edge that was updated
5353
*/
54-
graph.on(GRAPH_ACTIONS.ADD_EDGE, ({ edge, edgeId }) => { ... });
54+
graph.on(Graph.GRAPH_ACTIONS.ADD_EDGE, ({ edge, edgeId }) => { ... });
5555

5656
/*
5757
* @event
5858
* @param {object} args.edge - The edge that was updated
5959
* @param {object} args.edgeId - The id of the edge that was updated
6060
*/
61-
graph.on(GRAPH_ACTIONS.DELETE_EDGE, ({ edge, edgeId }) => { ... });
61+
graph.on(Graph.GRAPH_ACTIONS.DELETE_EDGE, ({ edge, edgeId }) => { ... });
6262

6363
/*
6464
* @event
6565
* @param {object} args.edge - The edge that was selected
6666
* @param {object} args.prevItem - The previously selected item, either a node or an edge
6767
*/
68-
graph.on(GRAPH_ACTIONS.SELECT_EDGE, ({ edge, prevItem }) => { ... });
68+
graph.on(Graph.GRAPH_ACTIONS.SELECT_EDGE, ({ edge, prevItem }) => { ... });
6969

7070
/*
7171
* @event
7272
* @param {object} args.prevItem - The previously selected item, either a node or an edge
7373
*/
74-
graph.on(GRAPH_ACTIONS.DESELECT_ITEM, ({ prevItem }) => { ... });
74+
graph.on(Graph.GRAPH_ACTIONS.DESELECT_ITEM, ({ prevItem }) => { ... });
7575

7676
/*
7777
* @event
7878
* @param {number} args.pos.x - The x position of the viewport in relation to the graph
7979
* @param {number} args.pos.y - The y position of the viewport in relation to the graph
8080
*/
81-
graph.on(GRAPH_ACTIONS.UPDATE_TRANSLATE, ({ pos }) => { ... });
81+
graph.on(Graph.GRAPH_ACTIONS.UPDATE_TRANSLATE, ({ pos }) => { ... });
8282

8383
/*
8484
* @event
8585
* param {number} args.scale - The current scale of the graph
8686
*/
87-
graph.on(GRAPH_ACTIONS.UPDATE_SCALE, ({ scale }) => { ... });
87+
graph.on(Graph.GRAPH_ACTIONS.UPDATE_SCALE, ({ scale }) => { ... });
8888
```

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
},
1818
"scripts": {
1919
"build": "cross-env NODE_ENV=production rollup -c --environment target:all && npm run bundle:styles",
20-
"bundle:styles": "scss-bundle -e ./src/style.scss -o ./dist/pcui-graph.scss",
20+
"bundle:styles": "scss-bundle -e ./src/styles/style.scss -o ./dist/pcui-graph.scss",
2121
"watch": "rollup -c --environment target:all --watch",
2222
"watch:umd": "rollup -c --environment target:umd --watch",
2323
"watch:module": "rollup -c --environment target:module --watch",
@@ -33,7 +33,8 @@
3333
"dist/pcui-graph.scss",
3434
"package.json",
3535
"README.md",
36-
"LICENSE"
36+
"LICENSE",
37+
"styles"
3738
],
3839
"browserslist": {
3940
"production": [

rollup.config.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,29 @@ const module = {
7474
};
7575

7676

77+
const styles = {
78+
input: 'src/styles/index.js',
79+
output: {
80+
file: 'styles/dist/index.mjs',
81+
format: 'esm'
82+
},
83+
plugins: [
84+
resolve(),
85+
postcss({
86+
minimize: false,
87+
extensions: ['.css', '.scss']
88+
})
89+
]
90+
};
91+
92+
7793
let targets;
7894
if (process.env.target) {
7995
switch (process.env.target.toLowerCase()) {
8096
case "umd": targets = [umd]; break;
8197
case "module": targets = [module]; break;
82-
case "all": targets = [umd, module]; break;
98+
case "styles": targets = [styles]; break;
99+
case "all": targets = [umd, module, styles]; break;
83100
}
84101
}
85102

src/index.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { deepCopyFunction } from './util';
22
import GraphView from './graph-view';
3-
import './style.scss';
43
import { GRAPH_ACTIONS, DEFAULT_CONFIG } from './constants.js';
54
import { Element } from '@playcanvas/pcui';
6-
import '@playcanvas/pcui/styles';
75
import { Observer } from '@playcanvas/observer';
86
import SelectedItem from './selected-item';
97

@@ -658,4 +656,4 @@ class Graph extends Element {
658656

659657
Graph.GRAPH_ACTIONS = GRAPH_ACTIONS;
660658

661-
export { Graph };
659+
export default Graph;

src/joint-graph.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import './lib/joint.scss';
2-
import './lib/layout.scss';
3-
import './lib/material.scss';
41
import 'jquery';
52
import _ from 'lodash';
63
import 'backbone';

src/joint-shape-node.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
import 'jointjs/dist/joint.css';
2-
import 'jointjs/css/layout.css';
3-
import 'jointjs/css/themes/material.css';
41
import 'jquery';
52
import 'backbone';
63
import _ from 'lodash';

src/styles/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import './style.scss';

0 commit comments

Comments
 (0)