avet-shared
Advanced tools
Comparing version 0.2.3 to 0.3.0
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.AvetScript = exports.Main = exports.Head = undefined; | ||
exports.AvetScript = exports.Main = exports.Head = exports.Body = exports.Html = undefined; | ||
@@ -13,2 +13,6 @@ var _extends2 = require('babel-runtime/helpers/extends'); | ||
var _assign = require('babel-runtime/core-js/object/assign'); | ||
var _assign2 = _interopRequireDefault(_assign); | ||
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of'); | ||
@@ -52,56 +56,83 @@ | ||
var Document = function (_Component) { | ||
(0, _inherits3.default)(Document, _Component); | ||
var mixinHtmlComponents = []; | ||
var mixinHeadComponents = []; | ||
var mixinMainComponents = []; | ||
function Document() { | ||
(0, _classCallCheck3.default)(this, Document); | ||
return (0, _possibleConstructorReturn3.default)(this, (Document.__proto__ || (0, _getPrototypeOf2.default)(Document)).apply(this, arguments)); | ||
function getPagePathname(pathname, avetExport) { | ||
if (!avetExport) return pathname; | ||
if (pathname === '/') return '/index.js'; | ||
return pathname + '/index.js'; | ||
} | ||
var Html = exports.Html = function (_Component) { | ||
(0, _inherits3.default)(Html, _Component); | ||
function Html() { | ||
(0, _classCallCheck3.default)(this, Html); | ||
return (0, _possibleConstructorReturn3.default)(this, (Html.__proto__ || (0, _getPrototypeOf2.default)(Html)).apply(this, arguments)); | ||
} | ||
(0, _createClass3.default)(Document, [{ | ||
key: 'getChildContext', | ||
value: function getChildContext() { | ||
return { _documentProps: this.props }; | ||
} | ||
}, { | ||
(0, _createClass3.default)(Html, [{ | ||
key: 'render', | ||
value: function render() { | ||
var props = this.props; | ||
var lang = props.lang; | ||
var mixinProps = {}; | ||
var mixinChild = []; | ||
if (mixinHtmlComponents.length) { | ||
mixinHtmlComponents.forEach(function (comp) { | ||
if (comp.props) { | ||
mixinProps = (0, _assign2.default)(mixinProps, comp.props); | ||
} | ||
if (comp.content) { | ||
var child = comp.content; | ||
if (!Array.isArray(child)) { | ||
child = [child]; | ||
} | ||
mixinChild = mixinChild.concat(child); | ||
} | ||
}); | ||
} | ||
return _react2.default.createElement( | ||
'html', | ||
{ lang: 'zh' }, | ||
_react2.default.createElement(Head, null), | ||
_react2.default.createElement( | ||
'body', | ||
null, | ||
_react2.default.createElement(Main, null), | ||
_react2.default.createElement(AvetScript, null) | ||
) | ||
(0, _extends3.default)({ lang: lang }, mixinProps, props), | ||
mixinChild, | ||
this.props.children | ||
); | ||
} | ||
}], [{ | ||
key: 'getInitialProps', | ||
value: function getInitialProps(_ref) { | ||
var renderPage = _ref.renderPage; | ||
}]); | ||
return Html; | ||
}(_react.Component); | ||
var _renderPage = renderPage(), | ||
html = _renderPage.html, | ||
head = _renderPage.head, | ||
errorHtml = _renderPage.errorHtml, | ||
chunks = _renderPage.chunks; | ||
Html.defaultProps = { | ||
lang: 'en' | ||
}; | ||
var styles = (0, _server2.default)(); | ||
return { html: html, head: head, errorHtml: errorHtml, chunks: chunks, styles: styles }; | ||
var Body = exports.Body = function (_Component2) { | ||
(0, _inherits3.default)(Body, _Component2); | ||
function Body() { | ||
(0, _classCallCheck3.default)(this, Body); | ||
return (0, _possibleConstructorReturn3.default)(this, (Body.__proto__ || (0, _getPrototypeOf2.default)(Body)).apply(this, arguments)); | ||
} | ||
(0, _createClass3.default)(Body, [{ | ||
key: 'render', | ||
value: function render() { | ||
return _react2.default.createElement( | ||
'body', | ||
this.props, | ||
this.props.children | ||
); | ||
} | ||
}]); | ||
return Document; | ||
return Body; | ||
}(_react.Component); | ||
Document.childContextTypes = { | ||
_documentProps: _propTypes2.default.any | ||
}; | ||
exports.default = Document; | ||
var Head = exports.Head = function (_Component3) { | ||
(0, _inherits3.default)(Head, _Component3); | ||
var Head = exports.Head = function (_Component2) { | ||
(0, _inherits3.default)(Head, _Component2); | ||
function Head() { | ||
@@ -172,5 +203,23 @@ (0, _classCallCheck3.default)(this, Head); | ||
var mixinProps = {}; | ||
var mixinChild = []; | ||
if (mixinHeadComponents.length) { | ||
mixinHeadComponents.forEach(function (comp) { | ||
if (comp.props) { | ||
mixinProps = (0, _assign2.default)(mixinProps, comp.props); | ||
} | ||
if (comp.content) { | ||
var child = comp.content; | ||
if (!Array.isArray(child)) { | ||
child = [child]; | ||
} | ||
mixinChild = mixinChild.concat(child); | ||
} | ||
}); | ||
} | ||
return _react2.default.createElement( | ||
'head', | ||
this.props, | ||
(0, _extends3.default)({}, this.props, mixinProps), | ||
_react2.default.createElement('link', { | ||
@@ -191,2 +240,3 @@ rel: 'preload', | ||
}), | ||
mixinChild, | ||
styles || null, | ||
@@ -204,4 +254,4 @@ this.props.children | ||
var Main = exports.Main = function (_Component3) { | ||
(0, _inherits3.default)(Main, _Component3); | ||
var Main = exports.Main = function (_Component4) { | ||
(0, _inherits3.default)(Main, _Component4); | ||
@@ -221,5 +271,16 @@ function Main() { | ||
var mixinMain = []; | ||
if (mixinMainComponents.length) { | ||
mixinMainComponents.forEach(function (comp) { | ||
if (comp) { | ||
mixinMain.push(comp); | ||
} | ||
}); | ||
} | ||
return _react2.default.createElement( | ||
'div', | ||
{ className: className }, | ||
mixinMain, | ||
_react2.default.createElement('div', { id: '__avet', dangerouslySetInnerHTML: { __html: html } }), | ||
@@ -243,4 +304,4 @@ _react2.default.createElement('div', { | ||
var AvetScript = exports.AvetScript = function (_Component4) { | ||
(0, _inherits3.default)(AvetScript, _Component4); | ||
var AvetScript = exports.AvetScript = function (_Component5) { | ||
(0, _inherits3.default)(AvetScript, _Component5); | ||
@@ -351,7 +412,66 @@ function AvetScript() { | ||
var Document = function (_Component6) { | ||
(0, _inherits3.default)(Document, _Component6); | ||
function getPagePathname(pathname, avetExport) { | ||
if (!avetExport) return pathname; | ||
if (pathname === '/') return '/index.js'; | ||
return pathname + '/index.js'; | ||
} | ||
function Document() { | ||
(0, _classCallCheck3.default)(this, Document); | ||
return (0, _possibleConstructorReturn3.default)(this, (Document.__proto__ || (0, _getPrototypeOf2.default)(Document)).apply(this, arguments)); | ||
} | ||
(0, _createClass3.default)(Document, [{ | ||
key: 'getChildContext', | ||
value: function getChildContext() { | ||
return { _documentProps: this.props }; | ||
} | ||
}, { | ||
key: 'render', | ||
value: function render() { | ||
return _react2.default.createElement( | ||
Html, | ||
null, | ||
_react2.default.createElement(Head, null), | ||
_react2.default.createElement( | ||
Body, | ||
null, | ||
_react2.default.createElement(Main, null), | ||
_react2.default.createElement(AvetScript, null) | ||
) | ||
); | ||
} | ||
}], [{ | ||
key: 'getInitialProps', | ||
value: function getInitialProps(_ref) { | ||
var renderPage = _ref.renderPage; | ||
var _renderPage = renderPage(), | ||
html = _renderPage.html, | ||
head = _renderPage.head, | ||
errorHtml = _renderPage.errorHtml, | ||
chunks = _renderPage.chunks; | ||
var styles = (0, _server2.default)(); | ||
return { html: html, head: head, errorHtml: errorHtml, chunks: chunks, styles: styles }; | ||
} | ||
}, { | ||
key: 'mixinHtml', | ||
value: function mixinHtml(MixinHtmlComponent) { | ||
mixinHtmlComponents.push(MixinHtmlComponent); | ||
} | ||
}, { | ||
key: 'mixinHead', | ||
value: function mixinHead(MixinHeadComponent) { | ||
mixinHeadComponents.push(MixinHeadComponent); | ||
} | ||
}, { | ||
key: 'mixinMain', | ||
value: function mixinMain(MixinMainComponent) { | ||
mixinMainComponents.push(MixinMainComponent); | ||
} | ||
}]); | ||
return Document; | ||
}(_react.Component); | ||
Document.childContextTypes = { | ||
_documentProps: _propTypes2.default.any | ||
}; | ||
exports.default = Document; |
@@ -133,3 +133,3 @@ 'use strict'; | ||
var changeMethod = replace ? 'replace' : 'push'; | ||
console.log('========', changeMethod); | ||
// straight up redirect | ||
@@ -136,0 +136,0 @@ _router2.default[changeMethod](href, as, { shallow: shallow }).then(function (success) { |
@@ -723,3 +723,2 @@ 'use strict'; | ||
var _ref9 = (0, _asyncToGenerator3.default)( /*#__PURE__*/_regenerator2.default.mark(function _callee8(route) { | ||
var res; | ||
return _regenerator2.default.wrap(function _callee8$(_context8) { | ||
@@ -733,6 +732,2 @@ while (1) { | ||
case 2: | ||
res = _context8.sent; | ||
return _context8.abrupt('return', res); | ||
case 4: | ||
case 'end': | ||
@@ -739,0 +734,0 @@ return _context8.stop(); |
{ | ||
"name": "avet-shared", | ||
"description": "avet shared code", | ||
"version": "0.2.3", | ||
"version": "0.3.0", | ||
"author": "okoala <dapixp@gmail.com>", | ||
@@ -6,0 +6,0 @@ "files": ["index.js", "lib", "src"], |
@@ -6,25 +6,42 @@ import React, { Component } from 'react'; | ||
export default class Document extends Component { | ||
static getInitialProps({ renderPage }) { | ||
const { html, head, errorHtml, chunks } = renderPage(); | ||
const styles = flush(); | ||
return { html, head, errorHtml, chunks, styles }; | ||
} | ||
const mixinHtmlComponents = []; | ||
const mixinHeadComponents = []; | ||
const mixinMainComponents = []; | ||
static childContextTypes = { | ||
_documentProps: PropTypes.any, | ||
function getPagePathname(pathname, avetExport) { | ||
if (!avetExport) return pathname; | ||
if (pathname === '/') return '/index.js'; | ||
return `${pathname}/index.js`; | ||
} | ||
export class Html extends Component { | ||
static defaultProps = { | ||
lang: 'en', | ||
}; | ||
getChildContext() { | ||
return { _documentProps: this.props }; | ||
} | ||
render() { | ||
const { props } = this; | ||
const { lang } = props; | ||
let mixinProps = {}; | ||
let mixinChild = []; | ||
render() { | ||
if (mixinHtmlComponents.length) { | ||
mixinHtmlComponents.forEach(comp => { | ||
if (comp.props) { | ||
mixinProps = Object.assign(mixinProps, comp.props); | ||
} | ||
if (comp.content) { | ||
let child = comp.content; | ||
if (!Array.isArray(child)) { | ||
child = [ child ]; | ||
} | ||
mixinChild = mixinChild.concat(child); | ||
} | ||
}); | ||
} | ||
return ( | ||
<html lang="zh"> | ||
<Head /> | ||
<body> | ||
<Main /> | ||
<AvetScript /> | ||
</body> | ||
<html lang={lang} {...mixinProps} {...props}> | ||
{mixinChild} | ||
{this.props.children} | ||
</html> | ||
@@ -35,2 +52,8 @@ ); | ||
export class Body extends Component { | ||
render() { | ||
return <body {...this.props}>{this.props.children}</body>; | ||
} | ||
} | ||
export class Head extends Component { | ||
@@ -88,4 +111,22 @@ static contextTypes = { | ||
let mixinProps = {}; | ||
let mixinChild = []; | ||
if (mixinHeadComponents.length) { | ||
mixinHeadComponents.forEach(comp => { | ||
if (comp.props) { | ||
mixinProps = Object.assign(mixinProps, comp.props); | ||
} | ||
if (comp.content) { | ||
let child = comp.content; | ||
if (!Array.isArray(child)) { | ||
child = [ child ]; | ||
} | ||
mixinChild = mixinChild.concat(child); | ||
} | ||
}); | ||
} | ||
return ( | ||
<head {...this.props}> | ||
<head {...this.props} {...mixinProps}> | ||
<link | ||
@@ -104,2 +145,3 @@ rel="preload" | ||
{(head || []).map((h, i) => React.cloneElement(h, { key: i }))} | ||
{mixinChild} | ||
{styles || null} | ||
@@ -124,4 +166,15 @@ {this.props.children} | ||
const { className } = this.props; | ||
const mixinMain = []; | ||
if (mixinMainComponents.length) { | ||
mixinMainComponents.forEach(comp => { | ||
if (comp) { | ||
mixinMain.push(comp); | ||
} | ||
}); | ||
} | ||
return ( | ||
<div className={className}> | ||
{mixinMain} | ||
<div id="__avet" dangerouslySetInnerHTML={{ __html: html }} /> | ||
@@ -237,6 +290,40 @@ <div | ||
function getPagePathname(pathname, avetExport) { | ||
if (!avetExport) return pathname; | ||
if (pathname === '/') return '/index.js'; | ||
return `${pathname}/index.js`; | ||
export default class Document extends Component { | ||
static getInitialProps({ renderPage }) { | ||
const { html, head, errorHtml, chunks } = renderPage(); | ||
const styles = flush(); | ||
return { html, head, errorHtml, chunks, styles }; | ||
} | ||
static childContextTypes = { | ||
_documentProps: PropTypes.any, | ||
}; | ||
static mixinHtml(MixinHtmlComponent) { | ||
mixinHtmlComponents.push(MixinHtmlComponent); | ||
} | ||
static mixinHead(MixinHeadComponent) { | ||
mixinHeadComponents.push(MixinHeadComponent); | ||
} | ||
static mixinMain(MixinMainComponent) { | ||
mixinMainComponents.push(MixinMainComponent); | ||
} | ||
getChildContext() { | ||
return { _documentProps: this.props }; | ||
} | ||
render() { | ||
return ( | ||
<Html> | ||
<Head /> | ||
<Body> | ||
<Main /> | ||
<AvetScript /> | ||
</Body> | ||
</Html> | ||
); | ||
} | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
156908
4474
35