diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000000..f85c5a3f84 --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +node_modules +javascript/dist +.jshintrc +javascript/examples/**/dist diff --git a/Gruntfile.js b/Gruntfile.js new file mode 100644 index 0000000000..1ea3126722 --- /dev/null +++ b/Gruntfile.js @@ -0,0 +1,101 @@ +var path = require("path"), + fs = require("fs"), + parentFolderName = path.basename(path.resolve('..')), + mxClientContent, + deps; + +// To get the dependencies for the project, read the filenames by matching +// mxClient.include([...]) in mxClient.js. This is not perfect, but the list is +// required in mxClient.js for compatibility. +mxClientContent = fs.readFileSync( + path.join(__dirname, "./javascript/src/js/mxClient.js"), + "utf8" +); +deps = mxClientContent.match(/mxClient\.include\([^"']+["'](.*?)["']/gi).map(function (str) { + return "." + str.match(/mxClient\.include\([^"']+["'](.*?)["']/)[1]; +}); +deps = ["./js/mxClient.js"].concat(deps.slice(0)); + +module.exports = function (grunt) { + grunt.initConfig({ + copy: { + main: { + files: [{ + expand: true, + cwd: "./javascript/src", + src: deps, + dest: "./javascript/dist" + }], + options: { + // After each module, add the object to the '__mxOutput' namespace + // E.g. __mxOutput.mxLog, etc. + process: function (content, srcpath) { + var afterContent = "", + moduleName = path.basename(srcpath, ".js"); + + afterContent += "\n__mxOutput." + path.basename(srcpath, ".js") + + " = typeof " + moduleName + " !== 'undefined' ? " + moduleName + " : undefined;\n"; + + return content + afterContent; + } + } + } + }, + concat: { + dist: { + src: deps.map(function (dep) { + return path.join("./javascript/dist", dep); + }), + dest: './javascript/dist/build.js' + }, + options: { + banner: "(function (root, factory) {\n" + + "if (typeof define === 'function' && define.amd) {\n" + + "define([], factory);\n" + + "} else if (typeof module === 'object' && module.exports) {\n" + + "module.exports = factory();\n" + + "} else {\n" + + "root.mxgraph = factory();\n" + + "}\n" + + "}(this, function () {\n" + + "return function (opts) {\n" + + // Opts will be passed into this function, expand them out as if + // they were globals so they can get picked up by the logic in + // mxClient.js. + "for (var name in opts) { this[name] = opts[name]; }\n" + + "var __mxOutput = {};\n", + footer: "return __mxOutput;\n" + + "};\n" + + "}));" + } + }, + webpack: { + examples: { + entry: "./javascript/examples/webpack/src/anchors.js", + output: { + path: "javascript/examples/webpack/dist", + filename: "anchors.js" + } + } + }, + watch: { + javascripts: { + files: "javascript/src/**/*.js", + tasks: ["umdify"], + options: { + interrupt: true + } + } + }, + }); + + require(parentFolderName === "node_modules" ? "load-grunt-parent-tasks" : "load-grunt-tasks")(grunt); + grunt.registerTask("default", [ + "copy", + "concat", + "webpack" + ]); + grunt.registerTask("build", [ + "default" + ]); +}; diff --git a/docs/manual.html b/docs/manual.html index 6b31799b0e..5135c5e391 100644 --- a/docs/manual.html +++ b/docs/manual.html @@ -384,6 +384,30 @@
Table: Project Directory Structure
mxGraph is also available via the npm package manager. To use mxGraph as
+ a depedency, use npm install
:
npm install mxgraph --save+ +
The module can be loaded using require()
. This returns a
+ factory function that accepts an object of options. Options such as
+ mxBasePath
must be provided to the factory function, rather
+ than specified as global variables.
var mxgraph = require("mxgraph")({ + mxImageBasePath: "./src/images", + mxBasePath: "./src" +})+ +
The factory function returns a 'namespace object' that provides access to
+ all objects of the mxGraph package. For example, the mxEvent
+ object is available at mxgraph.mxEvent
.
var mxEvent = mxgraph.mxEvent; +mxEvent.disableContextMenu(container);+
Web applications, specifically the use of JavaScript to attempt @@ -1652,4 +1676,4 @@