diff --git a/config/async-component-loader.js b/config/async-component-loader.js index 10131ddb..90ca4cd3 100644 --- a/config/async-component-loader.js +++ b/config/async-component-loader.js @@ -3,27 +3,27 @@ let componentPath = require.resolve('./async-component'); module.exports = function () { }; module.exports.pitch = function (remainingRequest) { - this.cacheable && this.cacheable(); - let query = loaderUtils.getOptions(this) || {}; - let routeName = typeof query.name === 'function' ? query.name(this.resourcePath) : null; - let name; - if (routeName !== null) { - name = routeName; - } - else if ('name' in query) { - name = query.name; - } - else if ('formatName' in query) { - name = query.formatName(this.resourcePath); - } + this.cacheable && this.cacheable(); + let query = loaderUtils.getOptions(this) || {}; + let routeName = typeof query.name === 'function' ? query.name(this.resourcePath) : null; + let name; + if (routeName !== null) { + name = routeName; + } + else if ('name' in query) { + name = query.name; + } + else if ('formatName' in query) { + name = query.formatName(this.resourcePath); + } - return ` - import async from ${JSON.stringify(componentPath)}; - function load(cb) { - require.ensure([], function (require) { - cb( require(${loaderUtils.stringifyRequest(this, '!!' + remainingRequest)}) ); - }${name ? (', ' + JSON.stringify(name)) : ''}); - } - export default async(load); - `; + return ` + import async from ${JSON.stringify(componentPath)}; + function load(cb) { + require.ensure([], function (require) { + cb( require(${loaderUtils.stringifyRequest(this, '!!' + remainingRequest)}) ); + }${name ? (', ' + JSON.stringify(name)) : ''}); + } + export default async(load); + `; }; \ No newline at end of file diff --git a/config/async-component.js b/config/async-component.js index b9ba69f3..b4dfc4d4 100644 --- a/config/async-component.js +++ b/config/async-component.js @@ -1,30 +1,30 @@ import { h, Component } from 'preact'; export default function (req) { - function Async() { - Component.call(this); + function Async() { + Component.call(this); - let b, old; - this.componentWillMount = () => { - b = this.base = this.nextBase || this.__b; // short circuits 1st render - req(m => { - this.setState({ child: m.default || m }); - }); - }; + let b, old; + this.componentWillMount = () => { + b = this.base = this.nextBase || this.__b; // short circuits 1st render + req(m => { + this.setState({ child: m.default || m }); + }); + }; - this.shouldComponentUpdate = (_, nxt) => { - nxt = nxt.child === void 0; - if (nxt && old === void 0 && !!b) { - old = h(b.nodeName, { dangerouslySetInnerHTML: { __html: b.innerHTML } }); - } - else { - old = ''; // dump it - } - return !nxt; - }; + this.shouldComponentUpdate = (_, nxt) => { + nxt = nxt.child === void 0; + if (nxt && old === void 0 && !!b) { + old = h(b.nodeName, { dangerouslySetInnerHTML: { __html: b.innerHTML } }); + } + else { + old = ''; // dump it + } + return !nxt; + }; - this.render = (p, s) => s.child ? h(s.child, p) : old; - } - (Async.prototype = new Component()).constructor = Async; - return Async; + this.render = (p, s) => s.child ? h(s.child, p) : old; + } + (Async.prototype = new Component()).constructor = Async; + return Async; } \ No newline at end of file diff --git a/config/client-boot.js b/config/client-boot.js deleted file mode 100644 index 742acf1b..00000000 --- a/config/client-boot.js +++ /dev/null @@ -1,27 +0,0 @@ -import { h, render } from 'preact'; - -if (process.env.NODE_ENV === 'development') { - // enable preact devtools - require('preact/debug'); -} -else if (process.env.ADD_SW && 'serviceWorker' in navigator && location.protocol === 'https:') { - // eslint-disable-next-line no-undef - navigator.serviceWorker.register(__webpack_public_path__ + 'sw.js'); -} - -const interopDefault = m => m && m.default ? m.default : m; - -let app = interopDefault(require('app-entry-point')); - -if (typeof app === 'function') { - let root = document.getElementById('app') || document.body.firstElementChild; - - let init = () => { - let app = interopDefault(require('app-entry-point')); - root = render(h(app), document.body, root); - }; - - if (module.hot) module.hot.accept('app-entry-point', init); - - init(); -} diff --git a/config/prerender-loader.js b/config/prerender-loader.js new file mode 100644 index 00000000..91f0647a --- /dev/null +++ b/config/prerender-loader.js @@ -0,0 +1,64 @@ +const path = require('path'); +const vm = require('vm'); + +module.exports = function (content) { + const jsdom = require('jsdom'); + const preact = require('preact'); + const renderToString = require('preact-render-to-string'); + + this.cacheable && this.cacheable(); + + const callback = this.async(); + + // const dom = new jsdom.JSDOM(`
`, { + const dom = new jsdom.JSDOM(content, { + includeNodeLocations: false, + runScripts: 'outside-only' + }); + const { window } = dom; + const { document } = window; + + // console.log(content); + + const root = document.getElementById('app'); + this.loadModule(path.join(__dirname, 'client-boot.js'), (err, source) => { + if (err) return callback(err); + + console.log(source); + + let mod = eval(source); + let props = {}; + // console.log(mod); + let vnode = preact.createElement(mod, props); + let frag = document.createElement('div'); + frag.innerHTML = renderToString(vnode); + root.parentNode.replaceChild(frag.firstChild, root); + + let html = dom.serialize(); + callback(null, html); + // return html = `module.exports = ${JSON.stringify(html)}`; + // return 'module.exports = ' + JSON.stringify(content).replace(/\{\{PRERENDER\}\}/gi, `" + require("preact-render-to-string")(require("app-entry-point")) + "`); + }); + + // global.window = global; + // global.document = {}; + // return 'module.exports = ' + JSON.stringify(content).replace(/\{\{PRERENDER\}\}/gi, `" + require("preact-render-to-string")(require("app-entry-point")) + "`); + + /* + let callback = this.async(); + + let parts = content.split(/\{\{prerender\}\}/gi); + + if (parts.length<2) { + // callback(null, `module.exports = ${JSON.stringify(content)}`); + callback(null, content); + return; + } + + // let html = ` + // window = {}; + // module.exports = ${JSON.stringify(parts[0])} + require("preact-render-to-string")(require("app-entry-point")) + ${JSON.stringify(parts[1])}`; + let html = `module.exports = ${JSON.stringify(parts[0])} + require("preact-render-to-string")(require("app-entry-point")) + ${JSON.stringify(parts[1])}`; + callback(null, html); + */ +}; \ No newline at end of file diff --git a/config/prerender.js b/config/prerender.js index 14f7f83c..65fda441 100644 --- a/config/prerender.js +++ b/config/prerender.js @@ -5,16 +5,16 @@ let renderToString = require('preact-render-to-string'); let appPath = path.join(__dirname, '../src/index'); module.exports = function(options) { - options = options || {}; - let url = typeof options==='string' ? options : options.url; - global.history = {}; - global.location = { href: url, pathname: url }; + options = options || {}; + let url = typeof options==='string' ? options : options.url; + global.history = {}; + global.location = { href: url, pathname: url }; - // let app = require('app-entry-point'); - let app = require(appPath); + // let app = require('app-entry-point'); + let app = require(appPath); - let html = renderToString(preact.h(app, { url })); - console.log(html); + let html = renderToString(preact.h(app, { url })); + console.log(html); - return html; + return html; }; diff --git a/config/watch-timestamps-plugin.js b/config/watch-timestamps-plugin.js index 6db23a03..942ddb85 100644 --- a/config/watch-timestamps-plugin.js +++ b/config/watch-timestamps-plugin.js @@ -8,23 +8,23 @@ const fs = require('fs'); * https://github.com/Jimdo/typings-for-css-modules-loader/issues/48#issuecomment-347036461 */ module.exports = class WatchTimestampsPlugin { - constructor(patterns) { - this.patterns = patterns; - } + constructor(patterns) { + this.patterns = patterns; + } - apply(compiler) { - compiler.plugin('watch-run', (watch, callback) => { - const patterns = this.patterns; - const timestamps = watch.fileTimestamps; + apply(compiler) { + compiler.plugin('watch-run', (watch, callback) => { + const patterns = this.patterns; + const timestamps = watch.fileTimestamps; - for (const filepath of timestamps) { - if (patterns.some(pat => pat instanceof RegExp ? pat.test(filepath) : filepath.indexOf(pat) === 0)) { - let time = fs.statSync(filepath).mtime; - if (timestamps instanceof Map) timestamps.set(filepath, time); - else timestamps[filepath] = time; - } - } - callback(); - }); - } + for (const filepath of timestamps) { + if (patterns.some(pat => pat instanceof RegExp ? pat.test(filepath) : filepath.indexOf(pat) === 0)) { + let time = fs.statSync(filepath).mtime; + if (timestamps instanceof Map) timestamps.set(filepath, time); + else timestamps[filepath] = time; + } + } + callback(); + }); + } }; diff --git a/src/assets/icon.png b/src/assets/icon.png index fb9b1fc4..8371feaa 100644 Binary files a/src/assets/icon.png and b/src/assets/icon.png differ diff --git a/src/components/app/style.scss b/src/components/app/style.scss index dd1192d6..e3c6e10b 100644 --- a/src/components/app/style.scss +++ b/src/components/app/style.scss @@ -1,21 +1,25 @@ @import '~style/helpers.scss'; .app { - position: absolute; - top: $toolbar-height; - left: 0; - width: 100%; - bottom: 0; - contain: size layout style; - overflow: auto; - -webkit-overflow-scrolling: touch; + position: absolute; + display: flex; + flex-direction: column; + top: 0; + left: 0; + width: 100%; + bottom: 0; + overflow: hidden; + z-index: 1; - > .content { - position: absolute; - left: 0; - top: 0; - width: 100%; - height: 100%; - overflow: visible; - } + .header { + flex: 0 0 auto; + position: relative; + } + + .content { + flex: 1 1 auto; + contain: size layout style; + overflow: auto; + -webkit-overflow-scrolling: touch; + } } diff --git a/src/components/app/style.scss.d.ts b/src/components/app/style.scss.d.ts index 9a895562..44bf86f2 100644 --- a/src/components/app/style.scss.d.ts +++ b/src/components/app/style.scss.d.ts @@ -1,2 +1,3 @@ export const app: string; +export const header: string; export const content: string; diff --git a/src/components/drawer/style.scss b/src/components/drawer/style.scss index e5751318..41acac3e 100644 --- a/src/components/drawer/style.scss +++ b/src/components/drawer/style.scss @@ -1,29 +1,29 @@ @import '~style/helpers.scss'; :global { - // @import '~preact-material-components/Drawer/style.css'; - @import '~preact-material-components/List/mdc-list.scss'; + // @import '~preact-material-components/Drawer/style.css'; + @import '~preact-material-components/List/mdc-list.scss'; } .drawer { - :global(.mdc-list-item__start-detail) { - margin-right: 16px; - } + :global(.mdc-list-item__start-detail) { + margin-right: 16px; + } } .logo { - width: 50%; + width: 50%; } .category img { - opacity: .6; + opacity: .6; } .bottom { - position: absolute; - bottom: 0; - bottom: constant(safe-area-inset-bottom); - bottom: env(safe-area-inset-bottom); - left: 0; - width: 100%; + position: absolute; + bottom: 0; + bottom: constant(safe-area-inset-bottom); + bottom: env(safe-area-inset-bottom); + left: 0; + width: 100%; } diff --git a/src/components/fab/style.scss b/src/components/fab/style.scss index 765f50b2..69e67345 100644 --- a/src/components/fab/style.scss +++ b/src/components/fab/style.scss @@ -1,18 +1,18 @@ @import '~style/helpers.scss'; :global { - @import '~preact-material-components/Fab/mdc-fab.scss'; + @import '~preact-material-components/Fab/mdc-fab.scss'; } .fab { - position: fixed; - right: 14px; - bottom: 14px; - z-index: 4; - - .progress { - width: 24px; - height: 24px; - color: white; - --mdc-theme-primary: #fff; - } + position: fixed; + right: 14px; + bottom: 14px; + z-index: 4; + + .progress { + width: 24px; + height: 24px; + color: white; + --mdc-theme-primary: #fff; + } } diff --git a/src/components/header/style.scss b/src/components/header/style.scss index 8c22f295..61bee8ce 100644 --- a/src/components/header/style.scss +++ b/src/components/header/style.scss @@ -1,51 +1,52 @@ @import '~style/helpers.scss'; :global { - @import '~preact-material-components/Toolbar/mdc-toolbar.scss'; + @import '~preact-material-components/Toolbar/mdc-toolbar.scss'; } .toolbar { - height: $toolbar-height; + // height: $toolbar-height; - &.minimal { - height: $toolbar-height / 2; - } + &.minimal { + display: none; + // height: $toolbar-height / 2; + } - // > * { - // min-height: 0; - // } + // > * { + // min-height: 0; + // } } .fileInput { - position: absolute; - left: 0; - top: -999px; + position: absolute; + left: 0; + top: -999px; } .fab { - position: fixed; - display: block; - right: 14px; - bottom: 14px; - // z-index: 999; - // transform: translateZ(0); + position: fixed; + display: block; + right: 14px; + bottom: 14px; + // z-index: 999; + // transform: translateZ(0); } .logo { - height: 1em; + height: 1em; } - + .menu { - position: absolute; - top: $toolbar-height; - right: 5px; + position: absolute; + top: $toolbar-height; + right: 5px; - .menuItem { - margin-right: 16px; - } + .menuItem { + margin-right: 16px; + } } .title { - padding: 3px 0 0; - font-weight: 300; - font-size: 140%; + padding: 3px 0 0; + font-weight: 300; + font-size: 140%; } \ No newline at end of file diff --git a/src/components/home/style.scss b/src/components/home/style.scss index ee19608e..09d9fa5b 100644 --- a/src/components/home/style.scss +++ b/src/components/home/style.scss @@ -1,20 +1,20 @@ @import '~style/helpers.scss'; // :global { -// @import '~preact-material-components/Button/mdc-button.scss'; -// // @import '~preact-material-components/Switch/mdc-switch.scss'; +// @import '~preact-material-components/Button/mdc-button.scss'; +// // @import '~preact-material-components/Switch/mdc-switch.scss'; // } .home { - padding: 20px; - opacity: 0; + padding: 20px; + opacity: 0; } .active { - animation: fadeIn 2s forwards ease 1; + animation: fadeIn 2s forwards ease 1; } @keyframes fadeIn { - from { opacity: 0; } - to { opacity: 1; } + from { opacity: 0; } + to { opacity: 1; } } \ No newline at end of file diff --git a/src/index.html b/src/index.html index 8f003453..6fecc701 100644 --- a/src/index.html +++ b/src/index.html @@ -6,23 +6,11 @@ + - - <%= - /*require('../config/prerender')()*/ - htmlWebpackPlugin.options.prerender() - %> + +