No manual global mermaid

This commit is contained in:
Tyler Long 2017-09-09 21:47:21 +08:00
parent 5da8c26cb6
commit fc5c07027c
6 changed files with 46 additions and 118 deletions

View File

@ -1,9 +1,9 @@
// Karma configuration
// Generated on Mon Nov 03 2014 07:53:38 GMT+0100 (CET)
import { webConfig } from './webpack.config.base.js'
import { jsConfig } from './webpack.config.base.js'
const webpackConfig = webConfig()
const webpackConfig = jsConfig()
module.exports = function (config) {
config.set({

View File

@ -1,8 +1,8 @@
{
"name": "mermaid",
"version": "7.0.10",
"version": "7.0.11",
"description": "Markdownish syntax for generating flowcharts, sequence diagrams, class diagrams, gantt charts and git graphs.",
"main": "src/mermaid.js",
"main": "dist/mermaid.core.js",
"keywords": [
"diagram",
"markdown",

View File

@ -9,7 +9,6 @@ var log = Logger.Log
var mermaidAPI = require('./mermaidAPI')
var nextId = 0
module.exports.mermaidAPI = mermaidAPI
/**
* ## init
* Function that goes through the document to find the chart definitions in there and render them.
@ -110,23 +109,11 @@ var init = function () {
}
}
module.exports.init = init
module.exports.parse = mermaidAPI.parse
/**
* ## version
* Function returning version information
* @returns {string} A string containing the version info
*/
module.exports.version = function () {
const version = function () {
return 'v' + require('../package.json').version
}
/**
* ## initialize
* This function overrides the default configuration.
* @param config
*/
module.exports.initialize = function (config) {
const initialize = function (config) {
log.debug('Initializing mermaid')
if (typeof config.mermaid !== 'undefined') {
if (typeof config.mermaid.startOnLoad !== 'undefined') {
@ -139,65 +126,16 @@ module.exports.initialize = function (config) {
mermaidAPI.initialize(config)
}
var equals = function (val, variable) {
if (typeof variable === 'undefined') {
return false
} else {
return (val === variable)
}
}
/**
* Global mermaid object. Contains the functions:
* * init
* * initialize
* * version
* * parse
* * parseError
* * render
*/
global.mermaid = {
startOnLoad: true,
htmlLabels: true,
init: function () {
init.apply(null, arguments)
},
initialize: function (config) {
module.exports.initialize(config)
},
version: function () {
return mermaidAPI.version()
},
parse: function (text) {
return mermaidAPI.parse(text)
},
parseError: function (err) {
log.debug('Mermaid Syntax error:')
log.debug(err)
},
render: function (id, text, callback, element) {
return mermaidAPI.render(id, text, callback, element)
}
}
/**
* ## parseError
* This function overrides the default configuration.
* @param config
*/
module.exports.parseError = global.mermaid.parseError
/**
* ##contentLoaded
* Callback function that is called when page is loaded. This functions fetches configuration for mermaid rendering and
* calls init for rendering the mermaid diagrams on the page.
*/
module.exports.contentLoaded = function () {
const contentLoaded = function () {
var config
// Check state of start config mermaid namespace
if (typeof global.mermaid_config !== 'undefined') {
if (equals(false, global.mermaid_config.htmlLabels)) {
if (global.mermaid_config.htmlLabels === false) {
global.mermaid.htmlLabels = false
}
}
@ -206,7 +144,7 @@ module.exports.contentLoaded = function () {
// For backwards compatability reasons also check mermaid_config variable
if (typeof global.mermaid_config !== 'undefined') {
// Check if property startOnLoad is set
if (equals(true, global.mermaid_config.startOnLoad)) {
if (global.mermaid_config.startOnLoad === true) {
global.mermaid.init()
}
} else {
@ -232,6 +170,27 @@ if (typeof document !== 'undefined') {
* Wait for document loaded before starting the execution
*/
window.addEventListener('load', function () {
module.exports.contentLoaded()
contentLoaded()
}, false)
}
const mermaid = {
mermaidAPI,
startOnLoad: true,
htmlLabels: true,
init,
initialize,
version,
parse: mermaidAPI.parse,
parseError: function (err) {
log.debug('Mermaid Syntax error:')
log.debug(err)
},
render: mermaidAPI.render,
contentLoaded
}
export default mermaid

View File

@ -5,7 +5,9 @@
/**
* Created by knut on 14-11-23.
*/
var mermaid = require('./mermaid')
import mermaid from './mermaid'
global.mermaid = mermaid
describe('when using mermaid and ', function () {
describe('when detecting chart type ', function () {

View File

@ -1,5 +1,4 @@
import path from 'path'
import nodeExternals from 'webpack-node-externals'
import ExtractTextPlugin from 'extract-text-webpack-plugin'
const rules = [
@ -11,7 +10,7 @@ const rules = [
}
]
export const webConfig = () => {
export const jsConfig = () => {
return {
target: 'web',
entry: {
@ -20,7 +19,10 @@ export const webConfig = () => {
externals: ['fs'],
output: {
path: path.join(__dirname, './dist/'),
filename: '[name].js'
filename: '[name].js',
library: 'mermaid',
libraryTarget: 'umd',
libraryExport: 'default'
},
module: {
rules: rules.concat([
@ -46,41 +48,6 @@ export const webConfig = () => {
}
}
export const nodeConfig = () => {
return {
target: 'node',
entry: {
mermaidAPI: './src/mermaidAPI.js'
},
externals: [nodeExternals()],
output: {
path: path.join(__dirname, './dist/'),
filename: '[name].js',
libraryTarget: 'commonjs2'
},
module: {
rules: rules.concat([
{
test: /\.js$/,
exclude: /node_modules/,
use: {
loader: 'babel-loader',
options: {
presets: [
['env', {
'targets': {
'node': '6.9'
}
}]
]
}
}
}
])
}
}
}
export const lessConfig = () => {
return {
target: 'web',

View File

@ -1,13 +1,13 @@
import { webConfig, nodeConfig, lessConfig } from './webpack.config.base.js'
import nodeExternals from 'webpack-node-externals'
const config = webConfig()
import { jsConfig, lessConfig } from './webpack.config.base.js'
const slimConfig = webConfig()
slimConfig.externals = ['fs', 'd3']
slimConfig.output.filename = '[name].slim.js'
const config = jsConfig()
const apiConfig = nodeConfig()
const coreConfig = jsConfig()
coreConfig.externals = [nodeExternals(), 'fs']
coreConfig.output.filename = '[name].core.js'
const cssConfig = lessConfig()
export default [config, slimConfig, apiConfig, cssConfig]
export default [config, coreConfig, cssConfig]