Skip to content

Commit 0321b33

Browse files
authored
Build update (#28)
* build update
1 parent ab6744f commit 0321b33

File tree

10 files changed

+3742
-4286
lines changed

10 files changed

+3742
-4286
lines changed

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,10 @@ The library is also available on [npm](https://www.npmjs.com/package/pcui-graph)
4646
npm install --save @playcanvas/pcui-graph @playcanvas/pcui @playcanvas/observer
4747
```
4848

49-
The npm package includes three builds of the library:
49+
The npm package includes two builds of the library:
5050
```
51-
@playcanvas/pcui-graph/index.js // UMD build, excluding external dependencies (requires dependencies to be placed in the global namespace)
52-
@playcanvas/pcui-graph/index.mjs // module build, excluding external dependencies (requires a build tool like rollup / webpack)
53-
@playcanvas/pcui-graph/bundle.mjs // module build, with all external dependencies bundled
51+
@playcanvas/pcui-graph/dist/pcui-graph.js // UMD build (requires that the pcui and observer libraries are present in the global namespace)
52+
@playcanvas/pcui-graph/dist/pcui-graph.mjs // module build (requires a build tool like rollup / webpack)
5453
```
5554

5655
## Storybook

conf-tsd.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"source": {
3+
"include": ["src/index.js"]
4+
},
5+
"opts": {
6+
"destination": "dist",
7+
"outFile": "pcui-graph.d.ts",
8+
"recurse": true,
9+
"template": "node_modules/tsd-jsdoc/dist"
10+
}
11+
}

package-lock.json

Lines changed: 3647 additions & 4199 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
{
22
"name": "@playcanvas/pcui-graph",
3-
"version": "1.1.4",
3+
"version": "2.0.0",
44
"author": "PlayCanvas <support@playcanvas.com>",
55
"homepage": "https://github.com/playcanvas/pcui-graph",
66
"description": "",
77
"license": "MIT",
8-
"main": "pcui-graph.js",
8+
"main": "dist/pcui-graph.js",
9+
"module": "dist/pcui-graph.mjs",
10+
"types": "dist/pcui-graph.d.ts",
911
"bugs": {
1012
"url": "https://github.com/playcanvas/pcui-graph/issues"
1113
},
@@ -24,18 +26,23 @@
2426
"webpack-bundle-analyzer": "^3.8.0"
2527
},
2628
"scripts": {
27-
"build": "rollup -c --environment target:all",
28-
"build:umd": "rollup -c --environment target:umd",
29-
"build:module": "rollup -c --environment target:module",
30-
"build:bundle": "rollup -c --environment target:bundle",
31-
"build:watch": "rollup -c --environment target:all --watch",
32-
"build:prod": "NODE_ENV=production rollup -c --environment target:all",
29+
"build": "cross-env NODE_ENV=production rollup -c --environment target:all",
30+
"watch": "rollup -c --environment target:all --watch",
31+
"watch:umd": "rollup -c --environment target:umd --watch",
32+
"watch:module": "rollup -c --environment target:module --watch",
3333
"lint": "eslint --ext .js src",
3434
"storybook": "start-storybook -p 9010 -s public",
3535
"build:docs": "typedoc --options typedoc.json; cp ./_docs/classes/Graph.md ./docs/Graph.md; rm -rf ./_docs",
36-
"pkg:publish": "rm -rf ./dist/ && npm run build:prod && cp ./package.json dist && cp ./LICENSE dist && cp README.md dist && cp -r ./docs dist && npm publish dist --access=public",
37-
"pkg:publish:dry": "rm -rf ./dist/ && npm run build:prod && cp ./package.json dist && cp ./LICENSE dist && cp README.md dist && cp -r ./docs dist && npm publish dist --dry-run --access=public"
36+
"tsd": "jsdoc -c conf-tsd.json && node tsd.js"
3837
},
38+
"files": [
39+
"dist/pcui-graph.js",
40+
"dist/pcui-graph.mjs",
41+
"dist/pcui-graph.d.ts",
42+
"package.json",
43+
"README.md",
44+
"LICENSE"
45+
],
3946
"browserslist": {
4047
"production": [
4148
">0.2%",
@@ -62,7 +69,7 @@
6269
"@babel/preset-react": "^7.10.4",
6370
"@playcanvas/eslint-config": "^1.0.6",
6471
"@playcanvas/observer": "1.1.0",
65-
"@playcanvas/pcui": "2.1.1",
72+
"@playcanvas/pcui": "2.3.1",
6673
"@rollup/plugin-babel": "^5.3.0",
6774
"@rollup/plugin-commonjs": "^20.0.0",
6875
"@storybook/addon-actions": "^6.0.3",
@@ -75,10 +82,11 @@
7582
"@storybook/react": "^6.0.3",
7683
"babel-loader": "^8.1.0",
7784
"backbone": "^1.4.0",
85+
"cross-env": "^7.0.3",
7886
"eslint": "^7.10.0",
7987
"jointjs": "^3.2.0",
8088
"jquery": "^3.5.1",
81-
"jsdoc": "^3.6.5",
89+
"jsdoc": "^3.6.10",
8290
"json-diff": "^0.5.4",
8391
"json-loader": "^0.5.7",
8492
"lodash": "^4.17.20",
@@ -98,6 +106,7 @@
98106
"rollup-plugin-postcss": "^4.0.1",
99107
"rollup-plugin-sass": "^1.2.6",
100108
"rollup-plugin-uglify": "^6.0.4",
109+
"tsd-jsdoc": "^2.5.0",
101110
"typedoc": "^0.21.6",
102111
"typedoc-plugin-markdown": "^3.10.4",
103112
"typescript": "^4.3.5",

rollup.config.js

Lines changed: 7 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import jscc from 'rollup-plugin-jscc';
77
import builtins from 'rollup-plugin-node-builtins';
88
import globals from 'rollup-plugin-node-globals';
99

10-
const umdBuild = {
10+
const umd = {
1111
input: 'src/index.js',
1212
output: {
13-
file: 'dist/index.js',
13+
file: 'dist/pcui-graph.js',
1414
format: 'umd',
1515
name: 'pcuiGraph',
1616
globals: {
@@ -36,10 +36,10 @@ const umdBuild = {
3636
]
3737
};
3838

39-
const moduleBuild = {
39+
const module = {
4040
input: 'src/index.js',
4141
output: {
42-
file: 'dist/index.mjs',
42+
file: 'dist/pcui-graph.mjs',
4343
format: 'module'
4444
},
4545
external: ['@playcanvas/observer', '@playcanvas/pcui'],
@@ -57,34 +57,13 @@ const moduleBuild = {
5757
]
5858
};
5959

60-
const bundleBuild = {
61-
input: 'src/index.js',
62-
output: {
63-
file: 'dist/bundle.mjs',
64-
format: 'module'
65-
},
66-
plugins: [
67-
commonjs({ transformMixedEsModules: true }),
68-
globals(),
69-
builtins(),
70-
babel({ babelHelpers: 'bundled' }),
71-
postcss({
72-
minimize: false,
73-
extensions: ['.css', '.scss']
74-
}),
75-
resolve(),
76-
process.env.NODE_ENV === 'production' && uglify()
77-
]
78-
};
79-
8060

8161
let targets;
8262
if (process.env.target) {
8363
switch (process.env.target.toLowerCase()) {
84-
case "umd": targets = [umdBuild]; break;
85-
case "module": targets = [moduleBuild]; break;
86-
case "bundle": targets = [bundleBuild]; break;
87-
case "all": targets = [umdBuild, moduleBuild, bundleBuild]; break;
64+
case "umd": targets = [umd]; break;
65+
case "module": targets = [module]; break;
66+
case "all": targets = [umd, module]; break;
8867
}
8968
}
9069

src/graph-view-edge.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as joint from 'jointjs/dist/joint.min';
2+
import { ContextMenu } from '@playcanvas/pcui';
23

34
joint.connectors.smoothInOut = function (sourcePoint, targetPoint, vertices, args) {
45
var p1 = sourcePoint.clone();
@@ -108,7 +109,7 @@ class GraphViewEdge {
108109
if (!edgeCell) return;
109110
var contextMenu = document.createElement('div');
110111
this._paper.el.appendChild(contextMenu);
111-
new this._graphView.pcui.ContextMenu({
112+
new ContextMenu({
112113
triggerElement: edgeCell.el,
113114
dom: contextMenu,
114115
items: items

src/graph-view-node.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as joint from 'jointjs/dist/joint.min';
2+
import { ContextMenu, Container, Label, TextInput, BooleanInput, NumericInput, VectorInput } from '@playcanvas/pcui';
23

34
const Colors = {
45
bcgDarkest: '#20292b',
@@ -265,8 +266,8 @@ class GraphViewNode {
265266
var containers = [];
266267
if (visibleAttributes) {
267268
visibleAttributes.forEach((attribute, i) => {
268-
const container = new this._graphView.pcui.Container({ class: 'graph-node-container' });
269-
const label = new this._graphView.pcui.Label({ text: attribute.name, class: 'graph-node-label' });
269+
const container = new Container({ class: 'graph-node-container' });
270+
const label = new Label({ text: attribute.name, class: 'graph-node-label' });
270271
let input;
271272
let nodeValue;
272273
if (nodeData.attributes) {
@@ -286,16 +287,16 @@ class GraphViewNode {
286287
}
287288
switch (attribute.type) {
288289
case 'TEXT_INPUT':
289-
input = new this._graphView.pcui.TextInput({ class: 'graph-node-input', value: nodeValue });
290+
input = new TextInput({ class: 'graph-node-input', value: nodeValue });
290291
break;
291292
case 'BOOLEAN_INPUT':
292-
input = new this._graphView.pcui.BooleanInput({ class: 'graph-node-input', value: nodeValue });
293+
input = new BooleanInput({ class: 'graph-node-input', value: nodeValue });
293294
break;
294295
case 'NUMERIC_INPUT':
295-
input = new this._graphView.pcui.NumericInput({ class: 'graph-node-input', hideSlider: true, value: nodeValue && nodeValue.x ? nodeValue.x : nodeValue });
296+
input = new NumericInput({ class: 'graph-node-input', hideSlider: true, value: nodeValue && nodeValue.x ? nodeValue.x : nodeValue });
296297
break;
297298
case 'VEC_2_INPUT':
298-
input = new this._graphView.pcui.VectorInput({ dimensions: 2,
299+
input = new VectorInput({ dimensions: 2,
299300
class: 'graph-node-input',
300301
hideSlider: true,
301302
value: [
@@ -306,7 +307,7 @@ class GraphViewNode {
306307
input.inputs.forEach((i) => i._sliderControl.dom.remove());
307308
break;
308309
case 'VEC_3_INPUT':
309-
input = new this._graphView.pcui.VectorInput({ dimensions: 3,
310+
input = new VectorInput({ dimensions: 3,
310311
class: 'graph-node-input',
311312
hideSlider: true,
312313
value: [
@@ -318,7 +319,7 @@ class GraphViewNode {
318319
input.inputs.forEach((i) => i._sliderControl.dom.remove());
319320
break;
320321
case 'VEC_4_INPUT':
321-
input = new this._graphView.pcui.VectorInput({ dimensions: 4,
322+
input = new VectorInput({ dimensions: 4,
322323
class: 'graph-node-input',
323324
hideSlider: true,
324325
value: [
@@ -375,7 +376,7 @@ class GraphViewNode {
375376
var contextMenu = document.createElement('div');
376377
this._paper.el.appendChild(contextMenu);
377378
this._contextMenuElement = contextMenu;
378-
this._contextMenu = new this._graphView.pcui.ContextMenu({
379+
this._contextMenu = new ContextMenu({
379380
triggerElement: nodeView.el,
380381
dom: contextMenu,
381382
items: this._graphView._parent._initialiseNodeContextMenuItems(this.nodeData, items)

src/graph-view.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { jointShapeElement, jointShapeElementView } from './joint-shape-node.js'
66
import { GRAPH_ACTIONS } from './constants.js';
77
// TODO replace with a lighter math library
88
import { Vec2 } from 'playcanvas/src/math/vec2.js';
9+
import { ContextMenu } from '@playcanvas/pcui';
910

1011
class GraphView extends JointGraph {
1112
constructor(parent, dom, graphSchema, graphData, config) {
@@ -15,7 +16,6 @@ class GraphView extends JointGraph {
1516
this._dom = dom;
1617
this._graphSchema = graphSchema;
1718
this._graphData = graphData;
18-
this.pcui = parent.pcui;
1919

2020
this._config = config;
2121

@@ -165,7 +165,7 @@ class GraphView extends JointGraph {
165165
addCanvasContextMenu(items) {
166166
this._viewContextMenu = document.createElement('div');
167167
this._paper.el.appendChild(this._viewContextMenu);
168-
var contextMenu = new this.pcui.ContextMenu({
168+
var contextMenu = new ContextMenu({
169169
dom: this._viewContextMenu,
170170
items: items
171171
});

src/index.js

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { deepCopyFunction } from './util';
22
import GraphView from './graph-view';
33
import './style.scss';
44
import { GRAPH_ACTIONS, DEFAULT_CONFIG } from './constants.js';
5-
import Element from '@playcanvas/pcui/Element';
5+
import { Element } from '@playcanvas/pcui';
66
import { Observer } from '@playcanvas/observer';
77
import SelectedItem from './selected-item';
88

@@ -14,18 +14,18 @@ class Graph extends Element {
1414
* Creates a new Graph.
1515
*
1616
* @param {object} schema - The graph schema.
17-
* @param {object} options - The graph configuration. Optional.
18-
* @param {object} options.initialData - The graph data to initialize the graph with.
19-
* @param {HTMLElement} options.dom - If supplied, the graph will be attached to this element.
20-
* @param {object[]} options.contextMenuItems - The context menu items to add to the graph. Optional.
21-
* @param {boolean} options.readOnly - Whether the graph is read only. Optional. Defaults to false.
22-
* @param {boolean} options.passiveUIEvents - If true, the graph will not update its data and view upon user interaction. Instead, these interactions can be handled explicitly by listening to fired events. Optional. Defaults to false.
23-
* @param {boolean} options.incrementNodeNames - Whether the graph should increment the node name when a node with the same name already exists. Optional. Defaults to false.
24-
* @param {boolean} options.restrictTranslate - Whether the graph should restrict the translate graph operation to the graph area. Optional. Defaults to false.
25-
* @param {boolean} options.edgeHoverEffect - Whether the graph should show an edge highlight effect when the mouse is hovering over edges. Optional. Defaults to true.
26-
* @param {boolean} options.includeFonts - If true the graph will include a default font style. Defaults to true.
27-
* @param {object} options.defaultStyles - Used to override the graph's default styling. Check ./constants.js for a full list of style properties.
28-
* @param {object} options.adjustVertices - If true, multiple edges conntected between two nodes will be spaced apart.
17+
* @param {object} [options] - The graph configuration. Optional.
18+
* @param {object} [options.initialData] - The graph data to initialize the graph with.
19+
* @param {HTMLElement} [options.dom] - If supplied, the graph will be attached to this element.
20+
* @param {object[]} [options.contextMenuItems] - The context menu items to add to the graph. Optional.
21+
* @param {boolean} [options.readOnly] - Whether the graph is read only. Optional. Defaults to false.
22+
* @param {boolean} [options.passiveUIEvents] - If true, the graph will not update its data and view upon user interaction. Instead, these interactions can be handled explicitly by listening to fired events. Optional. Defaults to false.
23+
* @param {boolean} [options.incrementNodeNames] - Whether the graph should increment the node name when a node with the same name already exists. Optional. Defaults to false.
24+
* @param {boolean} [options.restrictTranslate] - Whether the graph should restrict the translate graph operation to the graph area. Optional. Defaults to false.
25+
* @param {boolean} [options.edgeHoverEffect] - Whether the graph should show an edge highlight effect when the mouse is hovering over edges. Optional. Defaults to true.
26+
* @param {boolean} [options.includeFonts] - If true the graph will include a default font style. Defaults to true.
27+
* @param {object} [options.defaultStyles] - Used to override the graph's default styling. Check ./constants.js for a full list of style properties.
28+
* @param {object} [options.adjustVertices] - If true, multiple edges conntected between two nodes will be spaced apart.
2929
*/
3030
constructor(schema, options = {}) {
3131
super(options.dom ? options.dom : document.createElement('div'), {});
@@ -43,7 +43,6 @@ class Graph extends Element {
4343
restrictTranslate: options.restrictTranslate,
4444
edgeHoverEffect: options.edgeHoverEffect,
4545
includeFonts: options.includeFonts,
46-
useGlobalPCUI: options.useGlobalPCUI,
4746
adjustVertices: options.adjustVertices
4847
};
4948
if (options.defaultStyles) {
@@ -74,23 +73,6 @@ class Graph extends Element {
7473
//#endif
7574
}
7675

77-
if (!this._config.useGlobalPCUI) {
78-
/*#if _STRIP_SCSS
79-
//#else */
80-
this.pcui = {
81-
ContextMenu: require('@playcanvas/pcui/ContextMenu').default,
82-
Container: require('@playcanvas/pcui/Container').default,
83-
Label: require('@playcanvas/pcui/Label').default,
84-
TextInput: require('@playcanvas/pcui/TextInput').default,
85-
BooleanInput: require('@playcanvas/pcui/BooleanInput').default,
86-
NumericInput: require('@playcanvas/pcui/NumericInput').default,
87-
VectorInput: require('@playcanvas/pcui/VectorInput').default
88-
};
89-
//#endif
90-
} else {
91-
this.pcui = window.pcui;
92-
}
93-
9476
this._buildGraphFromData();
9577
if (options.defaultStyles.initialScale) {
9678
this.setGraphScale(options.defaultStyles.initialScale);

tsd.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const fs = require('fs');
2+
3+
const path = './dist/pcui-graph.d.ts';
4+
5+
var lastClass = '';
6+
function removeDuplicateClasses(str) {
7+
return str.replace(/(\/\*[\s\S]*?\*\/[\r\n]?)?declare class ([a-zA-Z]+).*\{[\s\S]*?\}/g, function (all, jsdoc, classname) {
8+
if (all == lastClass) {
9+
return `// drop duplicate: ${classname}`;
10+
}
11+
lastClass = all;
12+
return all;
13+
});
14+
}
15+
16+
// replace declare with export and add 'export as namespace pc' in the end
17+
let ts = fs.readFileSync(path, 'utf8');
18+
ts = removeDuplicateClasses(ts);
19+
ts = ts.replace(/^declare /gm, 'export ');
20+
// Remove empty interfaces
21+
ts = ts.replace(/export interface ([a-zA-Z]+).*\{\n\}/g, function (all, interfacename) {
22+
return `// drop empty interface: ${interfacename}`
23+
});
24+
// export namespace
25+
ts += 'export as namespace pcuiGraph;\n';
26+
fs.writeFileSync(path, ts);

0 commit comments

Comments
 (0)