Switch to Rollup (#16)

* Added Rollup config

* Add cjs build

* Remove webpack configs
This commit is contained in:
Faris Ansari 2018-02-20 18:28:32 +05:30 committed by GitHub
parent 664865d024
commit 67ea7746a2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 6092 additions and 2770 deletions

View File

@ -1,9 +0,0 @@
{
"presets": ["env"],
"plugins": [
"babel-plugin-add-module-exports",
["babel-plugin-transform-builtin-extend", {
"globals": ["TypeError", "RangeError", "Error"]
}]
]
}

View File

@ -1,12 +0,0 @@
root = true
[*]
indent_style = space
indent_size = 2
end_of_line = LF
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.md]
trim_trailing_whitespace = false

1
.eslintignore Normal file
View File

@ -0,0 +1 @@
dist

View File

@ -5,6 +5,11 @@
"modules": true
},
"parserOptions": {
"ecmaVersion": 6,
"sourceType": "module"
},
"env": {
"browser": true,
"es6": true,
@ -25,8 +30,6 @@
"Clusterize": true
},
"parser": "babel-eslint",
"plugins": [
],

1
.nvmrc
View File

@ -1 +0,0 @@
v6.10

13
LICENSE
View File

@ -1,6 +1,6 @@
The MIT License (MIT)
The MIT License
Copyright (c) 2017 Faris Ansari
Copyright (c) 2018 Frappé Technologies Pvt. Ltd. <developers@frappe.io>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@ -9,14 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -26,8 +26,8 @@ var grid = new DataTable(document.querySelector('#data-table'), {
## Contribute
* `npm run dev` - run this command and start hacking
* `npm run test` - run tests
* `yarn start` - Start rollup watch
* `yarn build` - Build js/css bundles
## License

2504
dist/frappe-datatable.cjs.js vendored Normal file

File diff suppressed because it is too large Load Diff

251
dist/frappe-datatable.css vendored Normal file
View File

@ -0,0 +1,251 @@
/* variables */
.data-table {
/* styling */
width: 100%;
position: relative;
overflow: auto;
}
/* resets */
.data-table *, .data-table *::after, .data-table *::before {
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
.data-table button, .data-table input {
overflow: visible;
font-family: inherit;
font-size: inherit;
line-height: inherit;
margin: 0;
padding: 0;
}
.data-table *, .data-table *:focus {
outline: none;
border-radius: 0px;
-webkit-box-shadow: none;
box-shadow: none;
}
.data-table table {
border-collapse: collapse;
}
.data-table table td {
padding: 0;
border: 1px solid #d1d8dd;
}
.data-table thead td {
border-bottom-width: 1px;
}
.data-table .freeze-container {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
-ms-flex-line-pack: center;
align-content: center;
position: absolute;
left: 0;
right: 0;
top: 0;
bottom: 0;
background-color: #f5f7fa;
opacity: 0.5;
font-size: 2em;
}
.data-table .freeze-container span {
position: absolute;
top: 50%;
-webkit-transform: translateY(-50%);
transform: translateY(-50%);
}
.data-table .trash-container {
position: absolute;
bottom: 0;
left: 30%;
right: 30%;
height: 70px;
background: palevioletred;
opacity: 0.5;
}
.body-scrollable {
max-height: 500px;
overflow: auto;
border-bottom: 1px solid #d1d8dd;
}
.body-scrollable.row-highlight-all .data-table-row:not(.row-unhighlight) {
background-color: #f5f7fa;
}
.data-table-header {
position: absolute;
top: 0;
left: 0;
background-color: white;
font-weight: bold;
}
.data-table-header .content span:not(.column-resizer) {
cursor: pointer;
}
.data-table-header .column-resizer {
display: none;
position: absolute;
right: 0;
top: 0;
width: 4px;
width: 0.25rem;
height: 100%;
background-color: rgb(82, 146, 247);
cursor: col-resize;
}
.data-table-header .data-table-dropdown {
position: absolute;
right: 10px;
display: -webkit-inline-box;
display: -ms-inline-flexbox;
display: inline-flex;
vertical-align: top;
text-align: left;
}
.data-table-header .data-table-dropdown.is-active .data-table-dropdown-list {
display: block;
}
.data-table-header .data-table-dropdown.is-active .data-table-dropdown-toggle {
display: block;
}
.data-table-header .data-table-dropdown-toggle {
display: none;
background-color: transparent;
border: none;
}
.data-table-header .data-table-dropdown-list {
display: none;
font-weight: normal;
position: absolute;
min-width: 128px;
min-width: 8rem;
top: 100%;
right: 0;
z-index: 1;
background-color: white;
border-radius: 3px;
-webkit-box-shadow: 0 2px 3px rgba(10, 10, 10, .1), 0 0 0 1px rgba(10, 10, 10, .1);
box-shadow: 0 2px 3px rgba(10, 10, 10, .1), 0 0 0 1px rgba(10, 10, 10, .1);
padding-bottom: 8px;
padding-bottom: 0.5rem;
padding-top: 8px;
padding-top: 0.5rem;
}
.data-table-header .data-table-dropdown-list> div {
padding: 8px 16px;
padding: 0.5rem 1rem;
}
.data-table-header .data-table-dropdown-list> div:hover {
background-color: #f5f7fa;
}
.data-table-header .data-table-col.remove-column {
background-color: #FD8B8B;
-webkit-transition: 300ms background-color ease-in-out;
transition: 300ms background-color ease-in-out;
}
.data-table-header .data-table-col.sortable-chosen {
background-color: #f5f7fa;
}
.data-table-col {
position: relative;
}
.data-table-col .content {
padding: 4px;
padding: 0.25rem;
border: 2px solid transparent;
}
.data-table-col .content.ellipsis {
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}
.data-table-col .edit-cell {
display: none;
// position: absolute;
padding: 4px;
padding: 0.25rem;
background: #fff;
z-index: 1;
height: 100%;
}
.data-table-col .edit-cell input {
outline: none;
width: 100%;
border: none;
}
.data-table-col.selected .content {
border: 2px solid rgb(82, 146, 247);
}
.data-table-col.editing .content {
display: none;
}
.data-table-col.editing .edit-cell {
border: 2px solid rgb(82, 146, 247);
display: block;
}
.data-table-col.highlight {
background-color: #f5f7fa;
}
.data-table-col:hover .column-resizer {
display: inline-block;
}
.data-table-col:hover .data-table-dropdown-toggle {
display: block;
}
.data-table-row.row-highlight {
background-color: #f5f7fa;
}
.noselect {
-webkit-touch-callout: none;
-webkit-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
}
body.data-table-resize {
cursor: col-resize;
}

2505
dist/frappe-datatable.js vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -13,7 +13,7 @@
font-size: 14px;
}
</style>
<link href="./assets/octicons/octicons.css" />
<link rel="stylesheet" href="./dist/frappe-datatable.css" />
</head>
<body>
@ -33,7 +33,7 @@
<script src="./node_modules/clusterize.js/clusterize.js"></script>
<script src="./node_modules/sortablejs/Sortable.js"></script>
<script src="./lib/frappe-datatable.js"></script>
<script src="./dist/frappe-datatable.js"></script>
<script>
document.addEventListener('DOMContentLoaded', () => {

File diff suppressed because one or more lines are too long

View File

@ -2,32 +2,27 @@
"name": "frappe-datatable",
"version": "0.0.1",
"description": "A modern datatable library for the web",
"main": "lib/frappe-datatable.js",
"main": "dist/frappe-datatable.cjs.js",
"scripts": {
"start": "npm run dev",
"build": "webpack --env build",
"dev": "webpack --progress --colors --watch --env dev",
"build": "rollup -c",
"dev": "rollup -c -w",
"test": "mocha --compilers js:babel-core/register --colors ./test/*.spec.js",
"test:watch": "mocha --compilers js:babel-core/register --colors -w ./test/*.spec.js"
},
"devDependencies": {
"babel-cli": "6.24.1",
"babel-core": "6.24.1",
"babel-eslint": "7.2.3",
"babel-loader": "7.0.0",
"babel-plugin-add-module-exports": "0.2.1",
"babel-plugin-transform-builtin-extend": "^1.1.2",
"babel-preset-env": "^1.6.1",
"chai": "3.5.0",
"css-loader": "^0.28.7",
"cssnano": "^3.10.0",
"deepmerge": "^2.0.1",
"eslint": "3.19.0",
"eslint-loader": "1.7.1",
"mocha": "3.3.0",
"node-sass": "^4.5.3",
"sass-loader": "^6.0.6",
"style-loader": "^0.18.2",
"webpack": "^3.1.0",
"yargs": "7.1.0"
"postcss-cssnext": "^3.1.0",
"postcss-nested": "^3.0.0",
"precss": "^3.1.0",
"rollup-plugin-json": "^2.3.0",
"rollup-plugin-postcss": "^1.2.8",
"rollup-plugin-uglify": "^3.0.0"
},
"repository": {
"type": "git",

37
rollup.config.js Normal file
View File

@ -0,0 +1,37 @@
import json from 'rollup-plugin-json';
// import uglify from 'rollup-plugin-uglify';
import postcss from 'rollup-plugin-postcss';
import nested from 'postcss-nested';
import cssnext from 'postcss-cssnext';
// import cssnano from 'cssnano';
const dev = {
input: 'src/index.js',
output: {
file: 'dist/frappe-datatable.js',
format: 'iife',
name: 'DataTable',
globals: {
sortablejs: 'Sortable',
'clusterize.js': 'Clusterize'
}
},
plugins: [
json(),
postcss({
extract: 'dist/frappe-datatable.css',
plugins: [
nested(),
cssnext()
]
})
],
external: ['sortablejs', 'clusterize.js']
};
export default [dev, Object.assign(dev, {
output: {
format: 'cjs',
file: 'dist/frappe-datatable.cjs.js'
}
})];

View File

@ -7,7 +7,7 @@ import BodyRenderer from './body-renderer';
import Style from './style';
import Keyboard from './keyboard';
import DEFAULT_OPTIONS from './defaults';
import './style.scss';
import './style.css';
class DataTable {
constructor(wrapper, options) {

View File

@ -1,14 +1,16 @@
/* variables */
$border-color: #d1d8dd;
$primary-color: rgb(82, 146, 247);
$light-bg: #f5f7fa;
$light-red: #FD8B8B;
$text-color: #000000;
:root {
--border-color: #d1d8dd;
--primary-color: rgb(82, 146, 247);
--light-bg: #f5f7fa;
--light-red: #FD8B8B;
--text-color: #000000;
$spacer-1: 0.25rem;
$spacer-2: 0.5rem;
$spacer-3: 1rem;
--spacer-1: 0.25rem;
--spacer-2: 0.5rem;
--spacer-3: 1rem;
}
.data-table {
/* resets */
@ -42,7 +44,7 @@ $spacer-3: 1rem;
table td {
padding: 0;
border: 1px solid $border-color;
border: 1px solid var(--border-color);
}
thead td {
@ -58,7 +60,7 @@ $spacer-3: 1rem;
right: 0;
top: 0;
bottom: 0;
background-color: $light-bg;
background-color: var(--light-bg);
opacity: 0.5;
font-size: 2em;
@ -83,10 +85,10 @@ $spacer-3: 1rem;
.body-scrollable {
max-height: 500px;
overflow: auto;
border-bottom: 1px solid $border-color;
border-bottom: 1px solid var(--border-color);
&.row-highlight-all .data-table-row:not(.row-unhighlight) {
background-color: $light-bg;
background-color: var(--light-bg);
}
}
@ -106,9 +108,9 @@ $spacer-3: 1rem;
position: absolute;
right: 0;
top: 0;
width: $spacer-1;
width: var(--spacer-1);
height: 100%;
background-color: $primary-color;
background-color: var(--primary-color);
cursor: col-resize;
}
@ -148,25 +150,25 @@ $spacer-3: 1rem;
background-color: white;
border-radius: 3px;
box-shadow: 0 2px 3px rgba(10, 10, 10, 0.1), 0 0 0 1px rgba(10, 10, 10, 0.1);
padding-bottom: $spacer-2;
padding-top: $spacer-2;
padding-bottom: var(--spacer-2);
padding-top: var(--spacer-2);
&> div {
padding: $spacer-2 $spacer-3;
padding: var(--spacer-2) var(--spacer-3);
&:hover {
background-color: $light-bg;
background-color: var(--light-bg);
}
}
}
.data-table-col.remove-column {
background-color: $light-red;
background-color: var(--light-red);
transition: 300ms background-color ease-in-out;
}
.data-table-col.sortable-chosen {
background-color: $light-bg;
background-color: var(--light-bg);
}
}
@ -174,7 +176,7 @@ $spacer-3: 1rem;
position: relative;
.content {
padding: $spacer-1;
padding: var(--spacer-1);
border: 2px solid transparent;
&.ellipsis {
@ -187,7 +189,7 @@ $spacer-3: 1rem;
.edit-cell {
display: none;
// position: absolute;
padding: $spacer-1;
padding: var(--spacer-1);
background: #fff;
z-index: 1;
height: 100%;
@ -200,7 +202,7 @@ $spacer-3: 1rem;
}
&.selected .content {
border: 2px solid $primary-color;
border: 2px solid var(--primary-color);
}
&.editing {
@ -209,13 +211,13 @@ $spacer-3: 1rem;
}
.edit-cell {
border: 2px solid $primary-color;
border: 2px solid var(--primary-color);
display: block;
}
}
&.highlight {
background-color: $light-bg;
background-color: var(--light-bg);
}
&:hover .column-resizer {
@ -229,7 +231,7 @@ $spacer-3: 1rem;
.data-table-row {
&.row-highlight {
background-color: $light-bg;
background-color: var(--light-bg);
}
}

View File

@ -1,72 +0,0 @@
/* global __dirname, require, module*/
const webpack = require('webpack');
const UglifyJsPlugin = webpack.optimize.UglifyJsPlugin;
const path = require('path');
const env = require('yargs').argv.env; // use --env with webpack 2
let libraryName = 'DataTable', outputFile = 'frappe-datatable';
let plugins = [];
if (env === 'build') {
plugins.push(new UglifyJsPlugin({ minimize: true }));
outputFile += '.min.js';
} else {
outputFile += '.js';
}
const config = {
entry: __dirname + '/src/index.js',
devtool: 'source-map',
output: {
path: __dirname + '/lib',
filename: outputFile,
library: libraryName,
libraryTarget: 'umd',
umdNamedDefine: true
},
module: {
rules: [
{
test: /(\.jsx|\.js)$/,
loader: 'babel-loader',
exclude: /(node_modules|bower_components)/
},
{
test: /(\.jsx|\.js)$/,
loader: 'eslint-loader',
exclude: /node_modules/
},
{
test: /\.scss$/,
use: [{
loader: 'style-loader' // creates style nodes from JS strings
}, {
loader: 'css-loader' // translates CSS into CommonJS
}, {
loader: 'sass-loader' // compiles Sass to CSS
}]
}
]
},
resolve: {
modules: [path.resolve('./node_modules'), path.resolve('./src')],
extensions: ['.json', '.js']
},
plugins: plugins,
externals: {
'clusterize.js': {
commonjs: 'clusterize.js',
commonjs2: 'clusterize.js',
root: 'Clusterize'
},
sortablejs: {
commonjs: 'sortablejs',
commonjs2: 'sortablejs',
root: 'Sortable'
}
}
};
module.exports = config;

3358
yarn.lock

File diff suppressed because it is too large Load Diff