mirror of
https://github.com/tenrok/BBob.git
synced 2026-06-08 17:22:26 +03:00
refactor(*): convert to babel and generation to lib, es, dist folders (#2)
* refactor(*): convert to babel and generation to lib, es, dist * chore(*): remove generated files * fix(*): lint run command
This commit is contained in:
committed by
GitHub
parent
d22a2895a4
commit
32a7fb51da
@@ -1,5 +0,0 @@
|
||||
{
|
||||
"presets": [
|
||||
"react"
|
||||
]
|
||||
}
|
||||
@@ -1,2 +1,4 @@
|
||||
dist
|
||||
es
|
||||
lib
|
||||
test
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
package-lock.json
|
||||
coverage
|
||||
dist
|
||||
dist
|
||||
lib
|
||||
es
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package-lock.json
|
||||
coverage
|
||||
src
|
||||
dist
|
||||
!dist
|
||||
!lib
|
||||
!es
|
||||
*.test.js
|
||||
|
||||
@@ -1,21 +1,41 @@
|
||||
# @bbob/react
|
||||
|
||||
```js
|
||||
```jsx
|
||||
import React from 'react'
|
||||
import BBCode from '@bbob/react';
|
||||
import presetHTML5 from '@bbob/react/lib/preset-html5';
|
||||
import presetReact from '@bbob/preset-react';
|
||||
|
||||
const plugins = [presetHTML5()];
|
||||
const plugins = [presetReact()];
|
||||
|
||||
<BBCode plugins={plugins}>
|
||||
export default () => (
|
||||
<BBCode plugins={plugins}>
|
||||
[table]
|
||||
[tr]
|
||||
[td]table 1[/td]
|
||||
[td]table 2[/td]
|
||||
[/tr]
|
||||
[tr]
|
||||
[td]table 3[/td]
|
||||
[td]table 4[/td]
|
||||
[/tr]
|
||||
[/table]
|
||||
</BBCode>
|
||||
)
|
||||
```
|
||||
|
||||
```jsx
|
||||
import { render } from '@bbob/react'
|
||||
|
||||
export default () => render(`
|
||||
[table]
|
||||
[tr]
|
||||
[td]table 1[/td]
|
||||
[td]table 2[/td]
|
||||
[td]table 1[/td]
|
||||
[td]table 2[/td]
|
||||
[/tr]
|
||||
[tr]
|
||||
[td]table 3[/td]
|
||||
[td]table 4[/td]
|
||||
[td]table 3[/td]
|
||||
[td]table 4[/td]
|
||||
[/tr]
|
||||
[/table]
|
||||
</BBCode>
|
||||
`)
|
||||
```
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
module.exports = require('./Component');
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
const presetHTML5 = require('@bbob/preset-html5');
|
||||
|
||||
module.exports = presetHTML5.extend(tags => ({
|
||||
...tags,
|
||||
|
||||
b: (...args) => ({
|
||||
...tags.b(...args),
|
||||
attrs: {
|
||||
style: { fontWeight: 'bold' },
|
||||
},
|
||||
}),
|
||||
|
||||
i: (...args) => ({
|
||||
...tags.b(...args),
|
||||
attrs: {
|
||||
style: { fontStyle: 'italic' },
|
||||
},
|
||||
}),
|
||||
|
||||
u: (...args) => ({
|
||||
...tags.b(...args),
|
||||
attrs: {
|
||||
style: { textDecoration: 'underline' },
|
||||
},
|
||||
}),
|
||||
|
||||
s: (...args) => ({
|
||||
...tags.b(...args),
|
||||
attrs: {
|
||||
style: { textDecoration: 'line-through' },
|
||||
},
|
||||
}),
|
||||
}));
|
||||
@@ -2,48 +2,65 @@
|
||||
"name": "@bbob/react",
|
||||
"version": "1.1.0",
|
||||
"description": "",
|
||||
"main": "lib/index.js",
|
||||
"directories": {
|
||||
"lib": "lib"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git+https://github.com/JiLiZART/bbob.git"
|
||||
},
|
||||
"keywords": [
|
||||
"bbob",
|
||||
"react",
|
||||
"helper"
|
||||
],
|
||||
"bugs": {
|
||||
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||
},
|
||||
"homepage": "https://github.com/JiLiZART/bbob#readme",
|
||||
"scripts": {
|
||||
"test": "../../node_modules/.bin/jest --",
|
||||
"cover": "../../node_modules/.bin/jest --coverage",
|
||||
"lint": "../../node_modules/.bin/eslint ."
|
||||
},
|
||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||
"license": "MIT",
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"dependencies": {
|
||||
"@bbob/core": "^1.1.0",
|
||||
"@bbob/html": "^1.1.0",
|
||||
"@bbob/plugin-helper": "^1.1.0",
|
||||
"@bbob/preset-html5": "^1.1.0",
|
||||
"@bbob/preset-react": "^1.1.0",
|
||||
"prop-types": "^15.6.1"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": "15.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"babel-preset-react": "^6.24.1",
|
||||
"enzyme": "^3.4.0",
|
||||
"enzyme-adapter-react-15": "^1.0.6",
|
||||
"react": "15.x",
|
||||
"react-dom": "^15.6.2",
|
||||
"react-test-renderer": "^15.6.2"
|
||||
}
|
||||
},
|
||||
"main": "lib/index.js",
|
||||
"module": "es/index.js",
|
||||
"jsnext:main": "es/index.js",
|
||||
"browser": "dist/index.js",
|
||||
"browserName": "BbobReact",
|
||||
"homepage": "https://github.com/JiLiZART/bbob",
|
||||
"author": "Nikolay Kostyurin <jilizart@gmail.com>",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://github.com/JiLiZART/bbob/issues"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "git://github.com/JiLiZART/bbob.git"
|
||||
},
|
||||
"scripts": {
|
||||
"build:commonjs": "../../node_modules/.bin/cross-env BABEL_ENV=commonjs ../../node_modules/.bin/babel src --out-dir lib",
|
||||
"build:es": "../../node_modules/.bin/cross-env BABEL_ENV=es ../../node_modules/.bin/babel src --out-dir es",
|
||||
"build:umd": "../../node_modules/.bin/cross-env BABEL_ENV=rollup NODE_ENV=development ../../node_modules/.bin/rollup --config ../../rollup.config.js",
|
||||
"build": "npm run build:commonjs && npm run build:es && npm run build:umd",
|
||||
"test": "../../node_modules/.bin/jest --",
|
||||
"cover": "../../node_modules/.bin/jest --coverage",
|
||||
"lint": "../../node_modules/.bin/eslint .",
|
||||
"size": "../../node_modules/.bin/size-limit"
|
||||
},
|
||||
"size-limit": [
|
||||
{
|
||||
"path": "lib/index.js"
|
||||
}
|
||||
],
|
||||
"publishConfig": {
|
||||
"registry": "https://registry.npmjs.org/"
|
||||
},
|
||||
"files": [
|
||||
"dist",
|
||||
"lib",
|
||||
"src",
|
||||
"es"
|
||||
]
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
const React = require('react');
|
||||
const PropTypes = require('prop-types');
|
||||
const core = require('@bbob/core');
|
||||
const render = require('./render');
|
||||
|
||||
const toAST = (source, plugins) => core(plugins).process(source).tree;
|
||||
const { render } = require('./render');
|
||||
|
||||
const content = (children, plugins) => React.Children.map(children, child =>
|
||||
(typeof child === 'string' ? render(toAST(child, plugins)) : child));
|
||||
(typeof child === 'string' ? render(child, plugins) : child));
|
||||
|
||||
const Component = props =>
|
||||
React.createElement(props.container, {}, content(props.children, props.plugins));
|
||||
@@ -24,4 +22,4 @@ Component.defaultProps = {
|
||||
plugins: [],
|
||||
};
|
||||
|
||||
module.exports = Component;
|
||||
export default Component;
|
||||
@@ -0,0 +1,2 @@
|
||||
export { default } from './Component';
|
||||
export { render } from './render';
|
||||
@@ -1,5 +1,13 @@
|
||||
const React = require('react');
|
||||
const { isTagNode, isStringNode } = require('@bbob/plugin-helper');
|
||||
import React from 'react';
|
||||
import core from '@bbob/core';
|
||||
import html from '@bbob/html';
|
||||
|
||||
import { isTagNode, isStringNode } from '@bbob/plugin-helper';
|
||||
|
||||
const toAST = (source, plugins) => core(plugins)
|
||||
.process(source, {
|
||||
render: input => html(input, { stripTags: true }),
|
||||
}).tree;
|
||||
|
||||
function tagToReactElement(node) {
|
||||
if (node.content === null) {
|
||||
@@ -14,11 +22,11 @@ function tagToReactElement(node) {
|
||||
node.tag,
|
||||
node.attrs,
|
||||
// eslint-disable-next-line no-use-before-define
|
||||
render(node.content),
|
||||
renderToReactNodes(node.content),
|
||||
);
|
||||
}
|
||||
|
||||
function render(nodes) {
|
||||
function renderToReactNodes(nodes) {
|
||||
const els = nodes.reduce((arr, node) => {
|
||||
if (isTagNode(node)) {
|
||||
arr.push(tagToReactElement(node));
|
||||
@@ -32,4 +40,9 @@ function render(nodes) {
|
||||
return els;
|
||||
}
|
||||
|
||||
module.exports = render;
|
||||
function render(source, plugins) {
|
||||
return renderToReactNodes(toAST(source, plugins));
|
||||
}
|
||||
|
||||
export { render };
|
||||
export default render;
|
||||
@@ -1,14 +1,15 @@
|
||||
const React = require('react');
|
||||
const { shallow } = require('enzyme');
|
||||
const BBCode = require('../lib');
|
||||
const presetHTML5 = require('../lib/preset-html5');
|
||||
const Enzyme = require('enzyme');
|
||||
const Adapter = require('enzyme-adapter-react-15');
|
||||
import React from 'react';
|
||||
import preset from '@bbob/preset-react';
|
||||
|
||||
import { shallow } from 'enzyme';
|
||||
import Enzyme from 'enzyme';
|
||||
import Adapter from 'enzyme-adapter-react-15';
|
||||
|
||||
import BBCode from '../src';
|
||||
Enzyme.configure({ adapter: new Adapter() });
|
||||
|
||||
const renderBBCode = input => shallow(
|
||||
<BBCode plugins={[presetHTML5()]}>{input}</BBCode>
|
||||
<BBCode plugins={[preset()]}>{input}</BBCode>
|
||||
).html();
|
||||
|
||||
describe('@bbob/react', () => {
|
||||
|
||||
Reference in New Issue
Block a user