From c71879ffbf5daed152dca9b5320a341d1d33e89b Mon Sep 17 00:00:00 2001 From: Jonathan Holt Date: Mon, 4 Oct 2021 11:39:00 +0100 Subject: [PATCH 01/10] remove polyfills --- package-lock.json | 4 +- package.json | 2 +- src/util/build.js | 5 -- templates/module/index.js | 108 +------------------------------------- 4 files changed, 4 insertions(+), 115 deletions(-) diff --git a/package-lock.json b/package-lock.json index db505f8..dc3eb06 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.0", + "version": "2.0.0-alpha.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.0", + "version": "2.0.0-alpha.1", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index dc8434e..03daa30 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.0", + "version": "2.0.0-alpha.1", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { diff --git a/src/util/build.js b/src/util/build.js index 36741a3..3c98cc2 100644 --- a/src/util/build.js +++ b/src/util/build.js @@ -68,7 +68,6 @@ const createModule = (config, styles, dir) => { fs.copySync(templateIndexPath, location); - const es5Path = getRightPathLocation(path.join(webcomponent, 'custom-elements-es5-adapter.js')); const loaderPath = getRightPathLocation(path.join(webcomponent, 'webcomponents-loader.js')); const bundles = getRightPathLocation(path.join(webcomponent, 'bundles')); const incPolyPath = path.join(path.dirname(__filename), '..', 'lib', 'includes.js'); @@ -76,8 +75,6 @@ const createModule = (config, styles, dir) => { fs.copySync(bundles, `${dir}/bundles`); const fileData = fs.readFileSync(location, 'utf8'); - const incPoly = fs.readFileSync(incPolyPath, 'utf8'); - const es5 = `${fs.readFileSync(es5Path, 'utf8')}${incPoly}`; const loader = fs.readFileSync(loaderPath, 'utf8'); const component = fs.readFileSync(path.join(libraryPath, dir, 'only.components.min.js'), 'utf8'); let cssContent = ''; @@ -96,8 +93,6 @@ const createModule = (config, styles, dir) => { const result = fileData .replace(/_INSERT_COMPONENT_JS_/g, component) - .replace(/_INSERT_ES5_ADAPTER_/g, es5) - .replace(/_INSERT_WEBCOMPONENT_LOADER_/g, loader) .replace(/_INSERT_NAME_/g, `${name}.?m?i?n?.js`) .replace(/_INLINE_STYLES_/g, cssContent); diff --git a/templates/module/index.js b/templates/module/index.js index 319e03e..8c3d4f5 100644 --- a/templates/module/index.js +++ b/templates/module/index.js @@ -1,113 +1,7 @@ -_INSERT_ES5_ADAPTER_ - (function () { var _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},asyncToGenerator=function(e){return function(){var c=e.apply(this,arguments);return new Promise(function(u,i){return function t(e,n){try{var o=c[e](n),r=o.value}catch(e){return void i(e)}if(!o.done)return Promise.resolve(r).then(function(e){t("next",e)},function(e){t("throw",e)});u(r)}("next")})}},classCallCheck=function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")},createClass=function(){function o(e,t){for(var n=0;n 0 ? 1 : -1) * Math.floor(Math.abs(number)); - }; - var maxSafeInteger = Math.pow(2, 53) - 1; - var toLength = function (value) { - var len = toInteger(value); - return Math.min(Math.max(len, 0), maxSafeInteger); - }; - - // The length property of the from method is 1. - return function from(arrayLike/*, mapFn, thisArg */) { - // 1. Let C be the this value. - var C = this; - - // 2. Let items be ToObject(arrayLike). - var items = Object(arrayLike); - - // 3. ReturnIfAbrupt(items). - if (arrayLike == null) { - throw new TypeError('Array.from requires an array-like object - not null or undefined'); - } - - // 4. If mapfn is undefined, then let mapping be false. - var mapFn = arguments.length > 1 ? arguments[1] : void undefined; - var T; - if (typeof mapFn !== 'undefined') { - // 5. else - // 5. a If IsCallable(mapfn) is false, throw a TypeError exception. - if (!isCallable(mapFn)) { - throw new TypeError('Array.from: when provided, the second argument must be a function'); - } - - // 5. b. If thisArg was supplied, let T be thisArg; else let T be undefined. - if (arguments.length > 2) { - T = arguments[2]; - } - } - - // 10. Let lenValue be Get(items, "length"). - // 11. Let len be ToLength(lenValue). - var len = toLength(items.length); - - // 13. If IsConstructor(C) is true, then - // 13. a. Let A be the result of calling the [[Construct]] internal method - // of C with an argument list containing the single item len. - // 14. a. Else, Let A be ArrayCreate(len). - var A = isCallable(C) ? Object(new C(len)) : new Array(len); - - // 16. Let k be 0. - var k = 0; - // 17. Repeat, while k < len… (also steps a - h) - var kValue; - while (k < len) { - kValue = items[k]; - if (mapFn) { - A[k] = typeof T === 'undefined' ? mapFn(kValue, k) : mapFn.call(T, kValue, k); - } else { - A[k] = kValue; - } - k += 1; - } - // 18. Let putStatus be Put(A, "length", len, true). - A.length = len; - // 20. Return A. - return A; - }; - }()); - } - - function getRoot() { - var scripts = document.getElementsByTagName('script'); - var list = [].slice.call(scripts).reduce(function (acc, script) { - var src = script.src; - - if (src && src.match(new RegExp('_INSERT_NAME_'))) { - var host = src.replace(new RegExp('_INSERT_NAME_'), ''); - acc.push(host); - } - - return acc; - }, []); - return list && list[0] || '/'; - }; - - var root = getRoot(); - - window.WebComponents = window.WebComponents || {}; - window.WebComponents.root = root; - - _INSERT_WEBCOMPONENT_LOADER_ - //_INLINE_STYLES_ - window.addEventListener('WebComponentsReady', function() { - _INSERT_COMPONENT_JS_ - }); - + _INSERT_COMPONENT_JS_ }()); From a6692f9d9217d4a1787d244c910bf10907281197 Mon Sep 17 00:00:00 2001 From: jholt1 Date: Mon, 4 Oct 2021 14:09:24 +0100 Subject: [PATCH 02/10] 2.0.1-alpha.1 --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package-lock.json b/package-lock.json index dc3eb06..cba32d1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.0-alpha.1", + "version": "2.0.1-alpha.1", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.0-alpha.1", + "version": "2.0.1-alpha.1", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index 03daa30..793e712 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.0-alpha.1", + "version": "2.0.1-alpha.1", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { From 242b9b52a0359bfa33f86e2cd154d7bcbff2b0d0 Mon Sep 17 00:00:00 2001 From: jholt1 Date: Mon, 4 Oct 2021 16:21:09 +0100 Subject: [PATCH 03/10] update browser, babel and cleanup --- package-lock.json | 4 ++-- package.json | 2 +- src/commands/build.js | 2 +- src/util/build.js | 3 --- src/util/index.js | 3 +-- 5 files changed, 5 insertions(+), 9 deletions(-) diff --git a/package-lock.json b/package-lock.json index cba32d1..0746975 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.1-alpha.1", + "version": "2.0.1-alpha.2", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.1-alpha.1", + "version": "2.0.1-alpha.2", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index 793e712..3c88286 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.1-alpha.1", + "version": "2.0.1-alpha.2", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { diff --git a/src/commands/build.js b/src/commands/build.js index e095853..39e88b1 100644 --- a/src/commands/build.js +++ b/src/commands/build.js @@ -22,7 +22,7 @@ import { watchStyles } from '../util/build'; -const autoprefixPlugin = new Autoprefix({grid: true, overrideBrowserslist: ['last 2 versions']}); +const autoprefixPlugin = new Autoprefix({ grid: true, overrideBrowserslist: ['>0.25%, not dead, not IE 11'] }); const cleanCSSPlugin = new CleanCSS({advanced: true, level: 2}); const cliPath = path.join(path.dirname(__filename), '..'); diff --git a/src/util/build.js b/src/util/build.js index 3c98cc2..c1ba4c6 100644 --- a/src/util/build.js +++ b/src/util/build.js @@ -68,14 +68,11 @@ const createModule = (config, styles, dir) => { fs.copySync(templateIndexPath, location); - const loaderPath = getRightPathLocation(path.join(webcomponent, 'webcomponents-loader.js')); const bundles = getRightPathLocation(path.join(webcomponent, 'bundles')); - const incPolyPath = path.join(path.dirname(__filename), '..', 'lib', 'includes.js'); fs.copySync(bundles, `${dir}/bundles`); const fileData = fs.readFileSync(location, 'utf8'); - const loader = fs.readFileSync(loaderPath, 'utf8'); const component = fs.readFileSync(path.join(libraryPath, dir, 'only.components.min.js'), 'utf8'); let cssContent = ''; diff --git a/src/util/index.js b/src/util/index.js index be1b4fb..5575e5e 100644 --- a/src/util/index.js +++ b/src/util/index.js @@ -32,14 +32,13 @@ const babelConfig = { compact: false, presets: [ ['@babel/preset-env', { - targets: ">0.25%", + targets: ">0.25%, not dead, not IE 11", loose: true, corejs: 3, useBuiltIns: 'entry' }] ], plugins: [ - "@babel/plugin-transform-spread", ["@babel/plugin-transform-runtime", { "regenerator": true, "useESModules": true From b38131becd11b3fa5df19a1c7821220e40c3ad2d Mon Sep 17 00:00:00 2001 From: jholt1 Date: Fri, 8 Oct 2021 14:23:41 +0100 Subject: [PATCH 04/10] allow components to be built individually --- package-lock.json | 4 ++-- package.json | 2 +- src/commands/build.js | 5 +++++ src/index.js | 1 + src/util/rollup.js | 4 +++- 5 files changed, 12 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 0746975..11d5aeb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.1-alpha.2", + "version": "2.0.1-alpha.3", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.1-alpha.2", + "version": "2.0.1-alpha.3", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index 3c88286..a12a4d9 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.1-alpha.2", + "version": "2.0.1-alpha.3", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { diff --git a/src/commands/build.js b/src/commands/build.js index 39e88b1..e5fb747 100644 --- a/src/commands/build.js +++ b/src/commands/build.js @@ -35,6 +35,7 @@ export default async (config) => { const polyfillPath = `${dir}/polyfill.js`; const componentsPath = `${dir}/components.js`; + const componentsDir = `${dir}/components`; const mergedComponentsPath = `${dir}/components.min.js`; const modernComponentsPath = `${dir}/components.modern.min.js`; const onlyComponentsPath = `${dir}/only.components.min.js`; @@ -119,6 +120,10 @@ export default async (config) => { return; } + if (options.components) { + await rollup(['src/*/component.js'], componentsDir, {...options, separate: true}, [commonjs(), ...plugins]); + } + await copyFiles(config, dir); const styles = await createStyles(config, [autoprefixPlugin, cleanCSSPlugin]); diff --git a/src/index.js b/src/index.js index 12ae39c..ba128e6 100644 --- a/src/index.js +++ b/src/index.js @@ -16,6 +16,7 @@ program .command('build') .description('Build padl web component files') .option('--storybook', 'Creates static storybook with build') + .option('--components', 'Builds components individually') .action((options) => { const config = { ...getConfigArgs(), diff --git a/src/util/rollup.js b/src/util/rollup.js index c5d697c..eabe42d 100644 --- a/src/util/rollup.js +++ b/src/util/rollup.js @@ -23,8 +23,10 @@ export default async (inputPaths, outputPath, options = {}, plugins = []) => { ...warning }; + const outputLocation = options.separate ? 'dir' : 'file'; + const outputOptions = { - file: outputPath, + [outputLocation]: outputPath, format: options.format || 'es', banner: `/* @version: ${packageVersion} */`, }; From 7976885bc795e496965216779efcad5b808f1103 Mon Sep 17 00:00:00 2001 From: jholt1 Date: Fri, 8 Oct 2021 15:11:06 +0100 Subject: [PATCH 05/10] fix build --- package-lock.json | 4 ++-- package.json | 2 +- src/commands/build.js | 16 ++++++++++++++-- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index 11d5aeb..efa4f9e 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.1-alpha.3", + "version": "2.0.1-alpha.4", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.1-alpha.3", + "version": "2.0.1-alpha.4", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index a12a4d9..5db8fea 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.1-alpha.3", + "version": "2.0.1-alpha.4", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { diff --git a/src/commands/build.js b/src/commands/build.js index e5fb747..b7fa724 100644 --- a/src/commands/build.js +++ b/src/commands/build.js @@ -35,7 +35,7 @@ export default async (config) => { const polyfillPath = `${dir}/polyfill.js`; const componentsPath = `${dir}/components.js`; - const componentsDir = `${dir}/components`; + const componentsDir = `${dir}/components/index.js`; const mergedComponentsPath = `${dir}/components.min.js`; const modernComponentsPath = `${dir}/components.modern.min.js`; const onlyComponentsPath = `${dir}/only.components.min.js`; @@ -81,6 +81,18 @@ export default async (config) => { resolve() ]; + const compPlugins = [ + multiEntry(), + resolve(), + stylesPlugin({ + mode: 'extract', + less: { + plugins: [autoprefixPlugin, cleanCSSPlugin], + output: false + } + }), + ]; + if (!options.from) { minPlugins.push(filesize()); } @@ -121,7 +133,7 @@ export default async (config) => { } if (options.components) { - await rollup(['src/*/component.js'], componentsDir, {...options, separate: true}, [commonjs(), ...plugins]); + await rollup('src/*/*[^story].js', componentsDir, { ...options }, compPlugins); } await copyFiles(config, dir); From cda43ee5c1770b6e983fead643f4d779170bb9c1 Mon Sep 17 00:00:00 2001 From: jholt1 Date: Thu, 14 Oct 2021 14:08:21 +0100 Subject: [PATCH 06/10] update component setup --- package-lock.json | 4 ++-- package.json | 2 +- src/commands/build.js | 6 +++--- src/util/rollup.js | 1 + 4 files changed, 7 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index efa4f9e..3372da2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.1-alpha.4", + "version": "2.0.1-alpha.5", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.1-alpha.4", + "version": "2.0.1-alpha.5", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index 5db8fea..b440114 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.1-alpha.4", + "version": "2.0.1-alpha.5", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { diff --git a/src/commands/build.js b/src/commands/build.js index b7fa724..14378a3 100644 --- a/src/commands/build.js +++ b/src/commands/build.js @@ -35,7 +35,7 @@ export default async (config) => { const polyfillPath = `${dir}/polyfill.js`; const componentsPath = `${dir}/components.js`; - const componentsDir = `${dir}/components/index.js`; + const componentsDir = `${dir}/components`; const mergedComponentsPath = `${dir}/components.min.js`; const modernComponentsPath = `${dir}/components.modern.min.js`; const onlyComponentsPath = `${dir}/only.components.min.js`; @@ -82,7 +82,7 @@ export default async (config) => { ]; const compPlugins = [ - multiEntry(), + multiEntry({ entryFileName: 'index.js' }), resolve(), stylesPlugin({ mode: 'extract', @@ -133,7 +133,7 @@ export default async (config) => { } if (options.components) { - await rollup('src/*/*[^story].js', componentsDir, { ...options }, compPlugins); + await rollup('src/index.js', componentsDir, { ...options, separate: true }, compPlugins); } await copyFiles(config, dir); diff --git a/src/util/rollup.js b/src/util/rollup.js index eabe42d..02d1c46 100644 --- a/src/util/rollup.js +++ b/src/util/rollup.js @@ -29,6 +29,7 @@ export default async (inputPaths, outputPath, options = {}, plugins = []) => { [outputLocation]: outputPath, format: options.format || 'es', banner: `/* @version: ${packageVersion} */`, + preserveModules: options.separate }; if (!options.noWatch && From 927b8b962da98c84c9c382f83db8a6eaeeb6e7a6 Mon Sep 17 00:00:00 2001 From: jholt1 Date: Thu, 14 Oct 2021 14:37:01 +0100 Subject: [PATCH 07/10] treeshaking fix --- package-lock.json | 4 ++-- package.json | 2 +- src/util/rollup.js | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 3372da2..4c0d6a0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.1-alpha.5", + "version": "2.0.1-alpha.6", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.1-alpha.5", + "version": "2.0.1-alpha.6", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index b440114..6d6faed 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.1-alpha.5", + "version": "2.0.1-alpha.6", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { diff --git a/src/util/rollup.js b/src/util/rollup.js index 02d1c46..68db29f 100644 --- a/src/util/rollup.js +++ b/src/util/rollup.js @@ -16,7 +16,7 @@ export default async (inputPaths, outputPath, options = {}, plugins = []) => { const inputOptions = { // external: [/@babel\/runtime/], - treeshake: true, + treeshake: !options.separate, input: inputPaths, plugins, cache: cache[outputPath], From 23a2a633d5f0c5f82cf8101576a4de5f86f24eb1 Mon Sep 17 00:00:00 2001 From: jholt1 Date: Fri, 22 Oct 2021 14:52:17 +0100 Subject: [PATCH 08/10] content loaded wait --- package-lock.json | 4 ++-- package.json | 2 +- templates/module/index.js | 4 +++- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4c0d6a0..e76a2c0 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.1-alpha.6", + "version": "2.0.1-alpha.7", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.1-alpha.6", + "version": "2.0.1-alpha.7", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index 6d6faed..0460172 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.1-alpha.6", + "version": "2.0.1-alpha.7", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { diff --git a/templates/module/index.js b/templates/module/index.js index 8c3d4f5..afb0114 100644 --- a/templates/module/index.js +++ b/templates/module/index.js @@ -3,5 +3,7 @@ //_INLINE_STYLES_ - _INSERT_COMPONENT_JS_ + document.addEventListener("DOMContentLoaded", () => { + _INSERT_COMPONENT_JS_ + }); }()); From 6c800dd282a13778474aace5177fd753bd0c7fab Mon Sep 17 00:00:00 2001 From: jholt1 Date: Tue, 26 Oct 2021 11:03:23 +0100 Subject: [PATCH 09/10] readystate --- package-lock.json | 4 ++-- package.json | 2 +- templates/module/index.js | 8 +++++--- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index e76a2c0..03e9898 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.1-alpha.7", + "version": "2.0.1-alpha.8", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.1-alpha.7", + "version": "2.0.1-alpha.8", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index 0460172..61f32fe 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.1-alpha.7", + "version": "2.0.1-alpha.8", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { diff --git a/templates/module/index.js b/templates/module/index.js index afb0114..1478b81 100644 --- a/templates/module/index.js +++ b/templates/module/index.js @@ -3,7 +3,9 @@ //_INLINE_STYLES_ - document.addEventListener("DOMContentLoaded", () => { - _INSERT_COMPONENT_JS_ - }); + document.onreadystatechange = function () { + if (document.readyState === 'complete') { + _INSERT_COMPONENT_JS_ + } + }; }()); From ce6a8bc290b2ed43a3c6b16c53bc68f54ce4739b Mon Sep 17 00:00:00 2001 From: jholt1 Date: Thu, 28 Oct 2021 14:36:23 +0100 Subject: [PATCH 10/10] detect if loading --- package-lock.json | 4 ++-- package.json | 2 +- templates/module/index.js | 16 +++++++++++----- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/package-lock.json b/package-lock.json index 03e9898..20f69b1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,11 +1,11 @@ { "name": "padl", - "version": "2.0.1-alpha.8", + "version": "2.0.1-alpha.9", "lockfileVersion": 2, "requires": true, "packages": { "": { - "version": "2.0.1-alpha.8", + "version": "2.0.1-alpha.9", "license": "MIT", "dependencies": { "@babel/cli": "^7.12.1", diff --git a/package.json b/package.json index 61f32fe..03c8e6c 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "padl", - "version": "2.0.1-alpha.8", + "version": "2.0.1-alpha.9", "description": "Develop pattern libraries with lit-element", "homepage": "https://github.com/britishgas-engineering/padl", "bug": { diff --git a/templates/module/index.js b/templates/module/index.js index 1478b81..d175e87 100644 --- a/templates/module/index.js +++ b/templates/module/index.js @@ -3,9 +3,15 @@ //_INLINE_STYLES_ - document.onreadystatechange = function () { - if (document.readyState === 'complete') { - _INSERT_COMPONENT_JS_ - } - }; + function loadComponents() { + _INSERT_COMPONENT_JS_ + } + + if (document.readyState == 'loading') { + // still loading, wait for the event + document.addEventListener('DOMContentLoaded', loadComponents); + } else { + // DOM is ready! + loadComponents(); + } }());