Clean up code

This commit is contained in:
Paulo Gustavo Veiga 2021-10-02 19:52:56 -07:00
parent 32d803e271
commit 75ee4529c4
7 changed files with 7 additions and 465 deletions

View File

@ -2,28 +2,6 @@
Core-JS defines custom functions for the **Wisemapping** ecosystem. Core-JS defines custom functions for the **Wisemapping** ecosystem.
## Quick Start
1. Clone repository with the next command:
```
git clone https://[username]@bitbucket.org/wisemapping/wisemapping-frontend.git
```
where the variable _username_ is you username of Bitbucket.
_Note:The project is configured to use the yarn dependency manager_
2. Move to folder core-js
```
cd packages/core-js
```
3. Now you need install all dependence, this is done with command `yarn install`
4. To start the development enviroment you have to use command `yarn start`.
## Production ## Production
To build up the package core-js and use in production, you have to use command `yarn build` To build up the package core-js and use in production, you have to use command `yarn build`

View File

@ -28,10 +28,8 @@
"babel-loader": "^8.2.2", "babel-loader": "^8.2.2",
"clean-webpack-plugin": "^4.0.0-alpha.0", "clean-webpack-plugin": "^4.0.0-alpha.0",
"core-js": "^3.15.2", "core-js": "^3.15.2",
"html-webpack-plugin": "^5.3.2",
"webpack": "^5.44.0", "webpack": "^5.44.0",
"webpack-cli": "^4.7.2", "webpack-cli": "^4.7.2",
"webpack-dev-server": "^3.11.2",
"webpack-merge": "^5.8.0" "webpack-merge": "^5.8.0"
}, },
"dependencies": { "dependencies": {

View File

@ -1,12 +1,10 @@
const path = require('path'); // eslint-disable-line const path = require('path');
const { CleanWebpackPlugin } = require('clean-webpack-plugin'); // eslint-disable-line const { CleanWebpackPlugin } = require('clean-webpack-plugin');
/** @type {import('webpack').Configuration} */
module.exports = { module.exports = {
// eslint-disable-line
entry: './lib/core.js', entry: './lib/core.js',
output: { output: {
path: path.resolve(__dirname, 'dist'), // eslint-disable-line path: path.resolve(__dirname, 'dist'),
filename: 'core.js', filename: 'core.js',
publicPath: '', publicPath: '',
}, },
@ -14,17 +12,13 @@ module.exports = {
rules: [ rules: [
{ {
use: 'babel-loader', use: 'babel-loader',
test: /.(js|jsx)$/, test: /.js$/,
exclude: /node_modules/, exclude: /node_modules/,
}, }
{
type: 'asset',
test: /\.(png|svg|jpg|jpeg|gif)$/i,
},
], ],
}, },
resolve: { resolve: {
extensions: ['.js', '.jsx', '.json'], extensions: ['.js'],
}, },
plugins: [new CleanWebpackPlugin()], plugins: [new CleanWebpackPlugin()],
}; };

View File

@ -2,17 +2,11 @@ const { HotModuleReplacementPlugin } = require('webpack');
const { merge } = require('webpack-merge'); const { merge } = require('webpack-merge');
const common = require('./webpack.common'); const common = require('./webpack.common');
/** @type {import('webpack').Configuration} */
const devConfig = { const devConfig = {
mode: 'development', mode: 'development',
target: 'web', target: 'web',
plugins: [new HotModuleReplacementPlugin()], plugins: [new HotModuleReplacementPlugin()],
devtool: 'eval-source-map', devtool: 'eval-source-map'
devServer: {
port: 8080,
open: 'google-chrome-stable',
hot: true,
},
}; };
module.exports = merge(common, devConfig); module.exports = merge(common, devConfig);

View File

@ -1,7 +1,6 @@
const { merge } = require('webpack-merge'); const { merge } = require('webpack-merge');
const common = require('./webpack.common'); const common = require('./webpack.common');
/** @type {import('webpack').Configuration} */
const prodConfig = { const prodConfig = {
mode: 'production', mode: 'production',
devtool: 'source-map', devtool: 'source-map',

View File

@ -1,286 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JsUnit Test Suite</title>
<link rel="stylesheet" type="text/css" href="../../../../../libraries/jsUnit/css/jsUnitStyle.css">
<script language="JavaScript" type="text/javascript" src="../../../../../libraries/jsUnit/app/jsUnitCore.js"></script> <!--<script language="JavaScript" type="text/javascript" src="../../../src/core.js"></script>-->
<script language="JavaScript" type="text/javascript" src="../../../src/web2d.js"></script>
<script type="text/javascript">
web2d.peer.Toolkit.init();
</script>
</head>
<body>
<h1>JsUnit Test Suite</h1>
<p>This page contains a suite of tests for testing JsUnit. Click <a href="../../lib/jsunit/testRunner.html">here</a> to
start running the test</p>
<div id="divWorkspace" style="border:1px solid red;position:absolute;left:0;top:0;width:400px;height:410px;">
</div>
<script language="JavaScript" type="text/javascript">
function setUp()
{
debug("Setting up workspace");
workspace = new web2d.Workspace();
workspace.addItAsChildTo($('#divWorkspace').first());
group = new web2d.Group();
line = new web2d.Line();
elipse = new web2d.Elipse();
rect = new web2d.Rect();
rectArc = new web2d.Rect(0.3);
}
function testAppendAndRemoveElements()
{
workspace.append(group);
workspace.append(line);
workspace.append(elipse);
workspace.append(rect);
workspace.append(rectArc);
workspace.removeChild(group);
workspace.removeChild(line);
workspace.removeChild(elipse);
workspace.removeChild(rect);
workspace.removeChild(rectArc);
workspace.append(group);
group.append(line);
group.append(elipse);
group.append(rect);
group.append(rectArc);
group.removeChild(line);
group.removeChild(elipse);
group.removeChild(rect);
group.removeChild(rectArc);
workspace.removeChild(group);
}
function testElementFill()
{
var testFill = function(elem, parent, color, opacity, isSupported)
{
if (parent)
{
parent.append(elem);
}
if (isSupported)
{
elem.setFill(color, opacity);
var fill = elem.getFill();
assertEquals(color, fill.color);
if (opacity)
{
assertEquals(opacity, fill.opacity);
}
// Set delegated
elem.setAttribute('fillColor', color);
elem.setAttribute('fillOpacity', opacity);
fill = elem.getFill();
assertEquals(color, fill.color);
if (opacity)
{
assertEquals(opacity, fill.opacity);
}
} else
{
var wasCatched = false;
try
{
line.setFill(color);
} catch (e)
{
wasCatched = true;
}
assertEquals(true, wasCatched);
}
};
testFill(workspace, null, 'blue', null, true);
testFill(elipse, workspace, 'green', 0.3, true);
testFill(rect, workspace, 'blue', 0.3, true);
testFill(rectArc, workspace, 'yellow', 0.3, true);
testFill(line, workspace, 'yellow', 0.3, false);
testFill(group, workspace, 'yellow', null, false);
}
function testElementPosition()
{
var testPosition = function(elem, parent, x, y, isSupported)
{
if (isSupported)
{
// Method setting ...
parent.append(elem);
elem.setPosition(x, y);
assertEquals(x, elem.getPosition().x);
assertEquals(y, elem.getPosition().y);
// Attribute setting
x = x + 10;
elem.setAttribute('x', x);
assertEquals(x, elem.getPosition().x);
y = y + 20;
elem.setAttribute('y', y);
assertEquals(y, elem.getPosition().y);
// Attribute getters
assertEquals(y, elem.getAttribute('y'));
assertEquals(x, elem.getAttribute('x'));
// Attribute setter.
y = y + 20;
x = x + 20;
elem.setAttribute('position', x + ' ' + y);
assertEquals(x, elem.getPosition().x);
assertEquals(y, elem.getPosition().y);
} else
{
var wasCatched = false;
try
{
line.setPosition(44, 34);
} catch (e)
{
wasCatched = true;
}
assertEquals(true, wasCatched);
}
};
testPosition(group, workspace, 41, 31, true);
testPosition(elipse, workspace, 42, 32, true);
testPosition(rect, workspace, 43, 33, true);
testPosition(rectArc, workspace, 44, 34, true);
}
function testElementSize()
{
var testSize = function(elem, parent, width, height, isSupported)
{
if (parent)
{
parent.append(elem);
}
if (isSupported)
{
// Function setter ..
elem.setSize(width, height);
assertEquals(width, elem.getSize().width);
assertEquals(height, elem.getSize().height);
// Attribute setter.
elem.setAttribute('width', width);
assertEquals(height, elem.getSize().height);
assertEquals(width, elem.getSize().width);
elem.setAttribute('height', height);
assertEquals(height, elem.getSize().height);
assertEquals(width, elem.getSize().width);
// Multiple setter.
elem.setAttribute('size', width + ' ' + height);
}
else {
var wasCatched = false;
try
{
elem.setSize(44, 34);
} catch (e)
{
wasCatched = true;
}
assertEquals(true, wasCatched);
}
};
testSize(workspace, null, '43mm', '43mm', true);
testSize(group, workspace, 10, 20, true);
testSize(elipse, group, 11, 21, true);
testSize(rect, workspace, 12, 22, true);
testSize(rectArc, workspace, 23, 13, true);
testSize(line, workspace, 13, 23, false);
}
function testElementEventHandling()
{
var testEventHandling = function(elem, parent, eventType)
{
if (parent)
{
parent.append(elem);
}
var listener = function() { /* Dummy event listener */
};
elem.addEvent(eventType, listener);
elem.removeEvent(eventType, listener);
};
testEventHandling(workspace, null, 'mouseover');
testEventHandling(group, workspace, 'mouseover');
testEventHandling(elipse, workspace, 'mouseover');
testEventHandling(rect, workspace, 'mouseover');
testEventHandling(rectArc, workspace, 'mouseover');
testEventHandling(line, workspace, 'mouseover');
}
;
function testStroke()
{
var testStroke = function(elem, parent, isSupported)
{
if (parent)
{
parent.append(elem);
}
var strokeStyles = ['solid','dot','dash','dashdot','longdash'];
for (var i = 0; i < strokeStyles.length; i++)
{
for (var j = 0; j < 10; j++)
{
elem.setStroke(j, strokeStyles[i], 'red');
}
}
};
// testStroke(workspace,null);
testStroke(elipse, workspace);
testStroke(rect, workspace);
testStroke(rectArc, workspace);
testStroke(line, workspace);
}
;
</script>
</body>
</html>

View File

@ -1,135 +0,0 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JsUnit Test Suite</title>
<link rel="stylesheet" type="text/css" href="../../lib/jsunit/css/jsUnitStyle.css">
<script language="JavaScript" type="text/javascript" src="../../lib/jsunit/app/jsUnitCore.js"></script>
<script language="JavaScript" type="text/javascript" src="../../../src/web2d.js"></script>
<script type="text/javascript">
web2d.peer.Toolkit.init();
</script>
</head>
<body>
<h1>JsUnit Test Suite</h1>
<p>This page contains a suite of tests for testing JsUnit. Click <a href="../../lib/jsunit/testRunner.html">here</a> to
start running the test</p>
<div id="divWorkspace" style="border:1px solid red;position:absolute;left:0px;top:0px;width:400;height:410px;">
</div>
<script language="JavaScript" type="text/javascript">
function setUp()
{
debug("Setting up workspace");
workspace = new web2d.Workspace();
workspace.addItAsChildTo($('#divWorkspace').first());
}
function testGettersTest()
{
// I you initialize a workspace, all default values must have valid values.
var fill = workspace.getFill();
assertEquals("white", fill.color);
}
function testSettersTest()
{
// I you initialize a workspace, all default values must have valid values.
workspace.setFill("red");
var fill = workspace.getFill();
assertEquals("red", fill.color);
}
function testEventTest()
{
var firstListener = function() {
alert("My Listener 1");
};
var secondListener = function() {
alert("My Listener 2");
};
workspace.addEvent("click", firstListener);
// Handle gracefully invalid event types...
var catchException = false
try
{
workspace.addEvent("click2", firstListener);
} catch(e)
{
catchException = true;
}
assert("Invalid type handling check seems to be broken", catchException);
// Test remove event functionality.
//// Fail if a listener is tryed to be removed and it was not previouly added.
catchException = false
try
{
workspace.removeEvent("click", secondListener);
} catch(e)
{
catchException = true;
}
assert("Invalid remove operation seems to be broken", catchException);
//// Remove a valid listener.
workspace.removeEvent("click", firstListener);
//// It has been removed?
catchException = false;
try
{
workspace.removeEvent("click", firstListener);
} catch(e)
{
catchException = true;
}
assert("Could not remove the element", catchException);
// Check multiple registation of a type ...
//// Add two listeners ...
workspace.addEvent("dblclick", firstListener);
workspace.addEvent("dblclick", secondListener);
//// Remove it ...
workspace.removeEvent("dblclick", firstListener);
workspace.removeEvent("dblclick", secondListener);
/// Check multiple registration on different types ...
workspace.addEvent("click", firstListener);
workspace.addEvent("mouseover", secondListener);
}
function testAppendAndRemoveTest()
{
// Append elements ..
var elipse = new web2d.Elipse();
var group = new web2d.Group();
group.append(elipse);
workspace.append(group);
// Remove elements ..
workspace.removeChild(group);
group.removeChild(elipse);
}
</script>
</body>
</html>