Skip to content

Commit

Permalink
improve build (#91)
Browse files Browse the repository at this point in the history
* improve build

* minify umd format

* fix exports declaration
  • Loading branch information
malcolm-kee authored Nov 21, 2021
1 parent 3ac2fe5 commit 2c49bcd
Show file tree
Hide file tree
Showing 41 changed files with 6,326 additions and 1,190 deletions.
3 changes: 1 addition & 2 deletions .babelrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
"@babel/preset-env"
],
"plugins": [
"@babel/plugin-proposal-object-rest-spread",
"@babel/plugin-proposal-class-properties"
"@babel/plugin-transform-runtime"
]
}
28 changes: 8 additions & 20 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"extends": "eslint:recommended",
"extends": ["eslint:recommended", "plugin:prettier/recommended"],
"env": {
"es6": true,
"browser": true,
Expand All @@ -17,40 +17,28 @@
"settings": {
"react": { "version": "detect" }
},
"plugins": [
"react"
],
"plugins": ["react"],
"rules": {
"eqeqeq": 2,
"no-const-assign": 2,
"prefer-const": 2,
"semi": [2, "always"],

"array-bracket-spacing": [1, "never"],
"arrow-spacing": 1,
"brace-style": [1, "1tbs", {"allowSingleLine": true}],
"comma-style": [1, "last"],
"indent": [1, 2],
"keyword-spacing": 1,
"linebreak-style": [1, "unix"],
"no-console": 1,
"no-unused-vars": 1,
"no-trailing-spaces": 1,
"object-curly-spacing": [1, "always", {"objectsInObjects": false, "arraysInObjects": false}],
"padded-blocks": [1, "never"],
"space-before-blocks": 1,
"space-in-parens": 1,
"space-infix-ops": 1,

"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/jsx-no-undef": 2,
"react/no-did-mount-set-state": 2,
"react/no-did-update-set-state": 2,
"react/no-direct-mutation-state": 2,
"react/no-unknown-property": 2,
"react/sort-comp": [1, {
"order": ["static-methods", "lifecycle", "render", "everything-else"]
}]
"react/sort-comp": [
1,
{
"order": ["static-methods", "lifecycle", "render", "everything-else"]
}
]
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ npm-debug.log
node_modules/
.DS_Store
dist/
demo-dist/
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
demo/
src/
test/
demo-dist/
2 changes: 2 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dist/
node_modules/
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
12 changes: 5 additions & 7 deletions demo/ClickCounterAtom.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { classToDOMAtom } from '../src';
import { classToDOMAtom } from 'react-mobiledoc-editor';

/**
* Component-based atoms are rendered with these props:
Expand All @@ -19,21 +19,19 @@ class Counter extends React.Component {
const { payload, save, value } = this.props;
const clicks = (payload.clicks || 0) + 1;
save(value, { ...payload, clicks }); // updates payload.clicks, rerenders button
}
};

render() {
const { payload } = this.props;

return (
<button onClick={this.handleClick}>
Clicks: {payload.clicks || 0}
</button>
<button onClick={this.handleClick}>Clicks: {payload.clicks || 0}</button>
);
}
}

Counter.displayName = 'Counter'
Counter.displayName = 'Counter';

const ClickCounterAtom = classToDOMAtom(Counter);

export default ClickCounterAtom;
export default ClickCounterAtom;
32 changes: 25 additions & 7 deletions demo/ImageCard.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { classToDOMCard } from '../src';
import { classToDOMCard } from 'react-mobiledoc-editor';

/**
* Component-based cards are rendered with these props:
Expand Down Expand Up @@ -27,21 +27,39 @@ import { classToDOMCard } from '../src';
class ImageCard extends React.Component {
render() {
const { isInEditor, payload, save, edit, isEditing } = this.props;

if (isEditing) {
return (
<div>
<input type="text" ref={r => (this.srcEl = r)} defaultValue={payload.src} /><br />
<input type="text" ref={r => (this.captionEl = r)} defaultValue={payload.caption} /><br />
<button onClick={() => save({ src: this.srcEl.value, caption: this.captionEl.value })}>Save</button>
<input
type="text"
ref={(r) => (this.srcEl = r)}
defaultValue={payload.src}
/>
<br />
<input
type="text"
ref={(r) => (this.captionEl = r)}
defaultValue={payload.caption}
/>
<br />
<button
onClick={() =>
save({ src: this.srcEl.value, caption: this.captionEl.value })
}
>
Save
</button>
</div>
);
} else {
const onClick = isInEditor ? edit : null;
return (
<div>
<img src={payload.src} onClick={onClick} /><br />
<small>{payload.caption}</small><br />
<img src={payload.src} onClick={onClick} />
<br />
<small>{payload.caption}</small>
<br />
{isInEditor && <button onClick={onClick}>Edit</button>}
</div>
);
Expand Down
9 changes: 5 additions & 4 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
<!doctype html>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta charset="UTF-8" />
<title>MobileDoc</title>
<style type="text/css">
/* Core Mobiledoc CSS is imported via webpack in index.js */
.active { font-weight: bold; }
.active {
font-weight: bold;
}
</style>
</head>
<body>
<div id="root"></div>
<script src="main.js"></script>
</body>
</html>
29 changes: 18 additions & 11 deletions demo/index.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,27 @@
import React from 'react';
import ReactDOM from 'react-dom';
import 'mobiledoc-kit/dist/mobiledoc.css';

import * as ReactMobiledoc from '../src';
import * as ReactMobiledoc from 'react-mobiledoc-editor';
import ImageCard from './ImageCard';
import ClickCounterAtom from './ClickCounterAtom';


const config = {
cards: [ImageCard],
atoms: [ClickCounterAtom],
placeholder: "Welcome to Mobiledoc!",
willCreateEditor:() => { console.log('creating editor...'); },
didCreateEditor:(e) => { console.log('created editor:', e); },
placeholder: 'Welcome to Mobiledoc!',
willCreateEditor: () => {
console.log('creating editor...');
},
didCreateEditor: (e) => {
console.log('created editor:', e);
},
};

const imgPayload = { caption: "Edit this right meow!", src: "http://www.placekitten.com/200/200" };

const imgPayload = {
caption: 'Edit this right meow!',
src: 'http://www.placekitten.com/200/200',
};

const ImageButton = (props) => {
const { isEditing } = props;
Expand All @@ -25,7 +31,6 @@ const ImageButton = (props) => {
return <button onClick={onClick}>Image Card</button>;
};


const ClickCounterButton = () => {
const { editor } = React.useContext(ReactMobiledoc.ReactMobileDocContext);
const onClick = () => editor.insertAtom('Counter', '', { clicks: 0 });
Expand All @@ -37,7 +42,11 @@ const App = () => {

return (
<div>
<ReactMobiledoc.Container {...config} mobiledoc={state} onChange={setState}>
<ReactMobiledoc.Container
{...config}
mobiledoc={state}
onChange={setState}
>
<ReactMobiledoc.Toolbar />
<ImageButton />
<ClickCounterButton />
Expand All @@ -49,5 +58,3 @@ const App = () => {
};

ReactDOM.render(<App />, document.getElementById('root'));

require("!style-loader!css-loader!../node_modules/mobiledoc-kit/dist/mobiledoc.css");
25 changes: 14 additions & 11 deletions karma.conf.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = function(config) {
module.exports = function (config) {
config.set({
// base path that will be used to resolve all patterns (eg. files, exclude)
basePath: './test',
Expand All @@ -8,35 +8,38 @@ module.exports = function(config) {
frameworks: ['mocha'],

// list of files / patterns to load in the browser
files: [
'setup.js'
],
files: ['setup.js'],

// list of files to exclude
exclude: [],

// preprocess matching files before serving them to the browser
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
preprocessors: {
'**/*': ['webpack', 'sourcemap']
'**/*': ['webpack', 'sourcemap'],
},

webpack: {
mode: 'development',
devtool: 'inline-source-map',
resolve: {
alias: {
'react-mobiledoc-editor': __dirname,
},
},
module: {
rules: [
{
test: /\.js$/,
loader: 'babel-loader',
exclude: /node_modules\//
}
]
}
exclude: /node_modules\//,
},
],
},
},

webpackMiddleware: {
noInfo: true
noInfo: true,
},

// test results reporter to use
Expand Down Expand Up @@ -64,6 +67,6 @@ module.exports = function(config) {

// Continuous Integration mode
// if true, Karma captures browsers, runs the tests and exits
singleRun: false
singleRun: false,
});
};
Loading

0 comments on commit 2c49bcd

Please sign in to comment.