From 723df253ec65f980da45ca69d2e7002e2f156544 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Wed, 11 Oct 2023 16:14:34 +0200 Subject: [PATCH 01/25] chore: update fstab --- fstab.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fstab.yaml b/fstab.yaml index 40ef9de12c..c54f824631 100644 --- a/fstab.yaml +++ b/fstab.yaml @@ -1,2 +1,2 @@ mountpoints: - /: https://drive.google.com/drive/u/0/folders/1MGzOt7ubUh3gu7zhZIPb7R7dyRzG371j \ No newline at end of file + /: https://drive.google.com/drive/u/0/folders/1MGzOt7ubUh3gu7zhZIPb7R7dyRzG371j From 804de77d6900398dc601c3336ce8c2e3480c860c Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 21 Jun 2024 15:18:22 -0700 Subject: [PATCH 02/25] fix: properly namespace events --- scripts/aem.js | 257 +++++++++++++++++++++++++++++++++++---------- scripts/scripts.js | 75 +++++++++---- 2 files changed, 259 insertions(+), 73 deletions(-) diff --git a/scripts/aem.js b/scripts/aem.js index e1f845cbd4..f06deb0461 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -1,3 +1,4 @@ +/* eslint-disable max-classes-per-file */ /* * Copyright 2024 Adobe. All rights reserved. * This file is licensed to you under the Apache License, Version 2.0 (the "License"); @@ -98,43 +99,12 @@ function sampleRUM(checkpoint, data = {}) { } } -/** - * Setup block utils. - */ -function setup() { - window.hlx = window.hlx || {}; - window.hlx.RUM_MASK_URL = 'full'; - window.hlx.codeBasePath = ''; - window.hlx.lighthouse = new URLSearchParams(window.location.search).get('lighthouse') === 'on'; - - const scriptEl = document.querySelector('script[src$="/scripts/scripts.js"]'); - if (scriptEl) { - try { - [window.hlx.codeBasePath] = new URL(scriptEl.src).pathname.split('/scripts/scripts.js'); - } catch (error) { - // eslint-disable-next-line no-console - console.log(error); - } - } -} - -/** - * Auto initializiation. - */ - -function init() { - setup(); - sampleRUM('top'); - - window.addEventListener('load', () => sampleRUM('load')); - - window.addEventListener('unhandledrejection', (event) => { - sampleRUM('error', { source: event.reason.sourceURL, target: event.reason.line }); - }); - - window.addEventListener('error', (event) => { - sampleRUM('error', { source: event.filename, target: event.lineno }); - }); +async function dispatchAsyncEvent(eventName, detail = {}) { + const promises = []; + const event = new CustomEvent(eventName, { detail }); + event.await = (p) => promises.push(p); + document.dispatchEvent(event); + return Promise.all(promises); } /** @@ -533,6 +503,7 @@ function updateSectionsStatus(main) { } else { section.dataset.sectionStatus = 'loaded'; section.style.display = null; + dispatchAsyncEvent('aem:section:loaded', { section }); } } } @@ -569,6 +540,39 @@ function buildBlock(blockName, content) { return blockEl; } +/** + * Loads the specified module with its JS and CSS files and returns the JS API if applicable. + * @param {String} name The module name + * @param {String} cssPath A path to the CSS file to load, or null + * @param {String} jsPath A path to the JS file to load, or null + * @param {...any} args Arguments to use to call the default export on the JS file + * @returns a promsie that the module was loaded, and that returns the JS API is any + */ +async function loadModule({ + name, cssPath, jsPath, el, +}) { + const cssLoaded = cssPath ? loadCSS(cssPath) : Promise.resolve(); + const decorationComplete = jsPath + ? new Promise((resolve) => { + (async () => { + let mod; + try { + mod = await import(jsPath); + if (mod.default) { + await mod.default(el); + } + } catch (error) { + // eslint-disable-next-line no-console + console.log(`failed to load module for ${name}`, error); + } + resolve(mod); + })(); + }) + : Promise.resolve(); + return Promise.all([cssLoaded, decorationComplete]) + .then(([, api]) => api); +} + /** * Loads JS and CSS for a block. * @param {Element} block The block element @@ -579,29 +583,25 @@ async function loadBlock(block) { block.dataset.blockStatus = 'loading'; const { blockName } = block.dataset; try { - const cssLoaded = loadCSS(`${window.hlx.codeBasePath}/blocks/${blockName}/${blockName}.css`); - const decorationComplete = new Promise((resolve) => { - (async () => { - try { - const mod = await import( - `${window.hlx.codeBasePath}/blocks/${blockName}/${blockName}.js` - ); - if (mod.default) { - await mod.default(block); - } - } catch (error) { - // eslint-disable-next-line no-console - console.log(`failed to load module for ${blockName}`, error); - } - resolve(); - })(); + const cssPath = `${window.hlx.codeBasePath}/blocks/${blockName}/${blockName}.css`; + const jsPath = `${window.hlx.codeBasePath}/blocks/${blockName}/${blockName}.js`; + const config = { + block, + blockName, + cssPath, + jsPath, + }; + await dispatchAsyncEvent('aem:block:config', config); + await loadModule({ + name: blockName, cssPath, jsPath, el: block, }); - await Promise.all([cssLoaded, decorationComplete]); + await dispatchAsyncEvent('aem:blockdecorated', { name: blockName, block }); } catch (error) { // eslint-disable-next-line no-console console.log(`failed to load block ${blockName}`, error); } block.dataset.blockStatus = 'loaded'; + await dispatchAsyncEvent('aem:block:loaded', { name: blockName, block }); } return block; } @@ -693,8 +693,154 @@ async function waitForLCP(lcpBlocks) { }); } +// function withPlugin(url, condition, options = {}) { +// const conditionFn = typeof condition === 'function' ? condition : () => true; +// const optionsObj = (typeof condition === 'function' ? options : condition) || {}; +// document.addEventListener(optionsObj.event || 'aem:lazy', (ev) => { +// if (conditionFn()) { +// ev.await = import(url) +// .then((module) => module.default(optionsObj)) +// .then((api) => { +// window.hlx.plugins['foo'] = api; +// }); +// } +// }); +// } + +// function withTemplate(url) { +// withPlugin(url, () => { +// const templateName = toClassName(getMetadata('template')); +// return new URL(url, window.location).pathname.endsWith(templateName); +// }, { event: 'aem:eager' }); +// } + +/** + * Parses the plugin id and config paramters and returns a proper config + * + * @param {String} id A string that idenfies the plugin, or a path to it + * @param {String|Object} [config] A string representing the path to the plugin, or a config object + * @returns an object returning the the plugin id and its config + */ +function parsePluginParams(id, config) { + const pluginId = !config + ? id.split('/').splice(id.endsWith('/') ? -2 : -1, 1)[0].replace(/\.js/, '') + : id; + const pluginConfig = typeof config === 'string' || !config + ? { load: 'lazy', url: (config || id).replace(/\/$/, '') } + : { load: config.eager ? 'eager' : 'lazy', ...config }; + pluginConfig.options ||= {}; + return { id: toClassName(pluginId), config: pluginConfig }; +} + +class PluginsRegistry { + #plugins; + + constructor() { + this.#plugins = new Map(); + } + + // Register a new plugin + add(id, config) { + const { id: pluginId, config: plugin } = parsePluginParams(id, config); + this.#plugins.set(pluginId, plugin); + document.addEventListener(`aem:${plugin.load}`, (ev) => { + if (plugin.condition && !plugin.condition(document, plugin.options)) { + return; + } + if (plugin.url) { + const isJsUrl = plugin.url.endsWith('.js'); + const loadPromise = loadModule({ + name: pluginId, + cssPath: !isJsUrl ? `${plugin.url}/${pluginId}.css` : null, + jsPath: !isJsUrl ? `${plugin.url}/${pluginId}.js` : plugin.url, + el: document, + }).then((api = {}) => { + this.#plugins.set(pluginId, { ...plugin, ...api }); + }); + ev.await(loadPromise); + } else if (plugin.run) { + plugin.run(document, plugin.options); + } + ['eager', 'lazy', 'delayed'].forEach((phase) => { + if (plugin[phase] && ev.type !== `aem:${phase}`) { + document.addEventListener(`aem:${phase}`, () => plugin[phase](document, plugin.options), { once: true }); + } else if (plugin[phase] && ev.type === `aem:${phase}`) { + plugin[phase](document, plugin.options); + } + }); + }, { once: true }); + } + + // Get the plugin + get(id) { return this.#plugins.get(id); } + + // Check if the plugin exists + has(id) { return !!this.#plugins.has(id); } +} + +class TemplatesRegistry { + // Register a new template + // eslint-disable-next-line class-methods-use-this + add(id, url) { + const { id: templateId, config: templateConfig } = parsePluginParams(id, url); + templateConfig.condition = () => toClassName(getMetadata('template')) === templateId; + window.hlx.plugins.add(templateId, templateConfig); + } + + // Get the template + // eslint-disable-next-line class-methods-use-this + get(id) { return window.hlx.plugins.get(id); } + + // Check if the template exists + // eslint-disable-next-line class-methods-use-this + has(id) { return window.hlx.plugins.includes(id); } +} + +/** + * Setup block utils. + */ +function setup() { + window.hlx = window.hlx || {}; + window.hlx.RUM_MASK_URL = 'full'; + window.hlx.codeBasePath = ''; + window.hlx.lighthouse = new URLSearchParams(window.location.search).get('lighthouse') === 'on'; + window.hlx.plugins = new PluginsRegistry(); + window.hlx.templates = new TemplatesRegistry(); + + const scriptEl = document.querySelector('script[src$="/scripts/scripts.js"]'); + if (scriptEl) { + try { + [window.hlx.codeBasePath] = new URL(scriptEl.src).pathname.split('/scripts/scripts.js'); + } catch (error) { + // eslint-disable-next-line no-console + console.log(error); + } + } +} + +/** + * Auto initializiation. + */ +async function init() { + setup(); + sampleRUM('top'); + + window.addEventListener('load', () => sampleRUM('load')); + + window.addEventListener('unhandledrejection', (event) => { + sampleRUM('error', { source: event.reason.sourceURL, target: event.reason.line }); + }); + + window.addEventListener('error', (event) => { + sampleRUM('error', { source: event.filename, target: event.lineno }); + }); +} + init(); +const withPlugin = window.hlx.plugins.add.bind(window.hlx.plugins); +const withTemplate = window.hlx.templates.add.bind(window.hlx.templates); + export { buildBlock, createOptimizedPicture, @@ -720,4 +866,7 @@ export { updateSectionsStatus, waitForLCP, wrapTextNodes, + withPlugin, + withTemplate, + dispatchAsyncEvent, }; diff --git a/scripts/scripts.js b/scripts/scripts.js index 0211c1dd34..44716d259b 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -11,6 +11,10 @@ import { waitForLCP, loadBlocks, loadCSS, + getMetadata, + toClassName, + dispatchAsyncEvent, + withPlugin, } from './aem.js'; const LCP_BLOCKS = []; // add your LCP blocks to the list @@ -71,12 +75,11 @@ export function decorateMain(main) { /** * Loads everything needed to get to LCP. - * @param {Element} doc The container element */ -async function loadEager(doc) { +document.addEventListener('aem:eager', async () => { document.documentElement.lang = 'en'; decorateTemplateAndTheme(); - const main = doc.querySelector('main'); + const main = document.querySelector('main'); if (main) { decorateMain(main); document.body.classList.add('appear'); @@ -91,22 +94,21 @@ async function loadEager(doc) { } catch (e) { // do nothing } -} +}); /** * Loads everything that doesn't need to be delayed. - * @param {Element} doc The container element */ -async function loadLazy(doc) { - const main = doc.querySelector('main'); +document.addEventListener('aem:lazy', async () => { + const main = document.querySelector('main'); await loadBlocks(main); const { hash } = window.location; - const element = hash ? doc.getElementById(hash.substring(1)) : false; + const element = hash ? document.getElementById(hash.substring(1)) : false; if (hash && element) element.scrollIntoView(); - loadHeader(doc.querySelector('header')); - loadFooter(doc.querySelector('footer')); + loadHeader(document.querySelector('header')); + loadFooter(document.querySelector('footer')); loadCSS(`${window.hlx.codeBasePath}/styles/lazy-styles.css`); loadFonts(); @@ -114,22 +116,57 @@ async function loadLazy(doc) { sampleRUM('lazy'); sampleRUM.observe(main.querySelectorAll('div[data-block-name]')); sampleRUM.observe(main.querySelectorAll('picture > img')); -} +}); /** * Loads everything that happens a lot later, * without impacting the user experience. */ -function loadDelayed() { - // eslint-disable-next-line import/no-cycle - window.setTimeout(() => import('./delayed.js'), 3000); - // load anything that can be postponed to the latest here -} +document.addEventListener('aem:delayed', async () => { + import('./delayed.js'); +}); + +document.addEventListener('aem:eager', (ev) => { + console.log(1, ev.type, ev.detail); + ev.await(new Promise((res) => { + setTimeout(() => { + console.log('foo from', ev.type); + res(); + }, 1000); + })); +}); + +document.addEventListener('aem:eager', (ev) => { + console.log(2, ev.type, ev.detail); +}); + +withPlugin('dummy-plugin', { + eager: () => console.log('plugin:eager'), + lazy: () => console.log('plugin:lazy'), + delayed: () => console.log('plugin:delayed'), +}); + +withPlugin('block-debugger', { + condition: () => true, + run: () => { + document.addEventListener('aem:block:config', (ev) => console.group(ev.detail.name) && console.log(ev.type, ev.detail)); + document.addEventListener('aem:block:decorated', (ev) => console.log(ev.type, ev.detail)); + document.addEventListener('aem:block:loaded', (ev) => console.log(ev.type, ev.detail) && console.groupEnd()); + }, +}); + +window.addEventListener('load', (ev) => console.log(ev.type, ev.detail)); +document.addEventListener('DOMContentLoaded', (ev) => console.log(ev.type, ev.detail)); +document.addEventListener('aem:eager', (ev) => console.log(ev.type, ev.detail)); +document.addEventListener('aem:lazy', (ev) => console.log(ev.type, ev.detail)); +document.addEventListener('aem:delayed', (ev) => console.log(ev.type, ev.detail)); async function loadPage() { - await loadEager(document); - await loadLazy(document); - loadDelayed(); + await dispatchAsyncEvent('aem:eager'); + await dispatchAsyncEvent('aem:lazy'); + window.setTimeout(async () => { + await dispatchAsyncEvent('aem:delayed'); + }, 3000); } loadPage(); From 70813c3075841fbc40fff66ac7946f82c5ea78d7 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 21 Jun 2024 15:23:48 -0700 Subject: [PATCH 03/25] chore: cleanup PR --- fstab.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fstab.yaml b/fstab.yaml index c54f824631..40ef9de12c 100644 --- a/fstab.yaml +++ b/fstab.yaml @@ -1,2 +1,2 @@ mountpoints: - /: https://drive.google.com/drive/u/0/folders/1MGzOt7ubUh3gu7zhZIPb7R7dyRzG371j + /: https://drive.google.com/drive/u/0/folders/1MGzOt7ubUh3gu7zhZIPb7R7dyRzG371j \ No newline at end of file From fe2f5c6f567eb1f18a85c7edbf6d558b36673044 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 21 Jun 2024 15:24:22 -0700 Subject: [PATCH 04/25] chore: cleanup PR --- scripts/aem.js | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/scripts/aem.js b/scripts/aem.js index f06deb0461..7adc7a08ee 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -693,27 +693,6 @@ async function waitForLCP(lcpBlocks) { }); } -// function withPlugin(url, condition, options = {}) { -// const conditionFn = typeof condition === 'function' ? condition : () => true; -// const optionsObj = (typeof condition === 'function' ? options : condition) || {}; -// document.addEventListener(optionsObj.event || 'aem:lazy', (ev) => { -// if (conditionFn()) { -// ev.await = import(url) -// .then((module) => module.default(optionsObj)) -// .then((api) => { -// window.hlx.plugins['foo'] = api; -// }); -// } -// }); -// } - -// function withTemplate(url) { -// withPlugin(url, () => { -// const templateName = toClassName(getMetadata('template')); -// return new URL(url, window.location).pathname.endsWith(templateName); -// }, { event: 'aem:eager' }); -// } - /** * Parses the plugin id and config paramters and returns a proper config * From e3531d78544d49cbfbf3243d911e8538b8bccaec Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 21 Jun 2024 15:26:37 -0700 Subject: [PATCH 05/25] chore: cleanup PR --- scripts/scripts.js | 68 +++++++++++++--------------------------------- 1 file changed, 19 insertions(+), 49 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 44716d259b..173bc219c8 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -76,13 +76,13 @@ export function decorateMain(main) { /** * Loads everything needed to get to LCP. */ -document.addEventListener('aem:eager', async () => { - document.documentElement.lang = 'en'; +async function loadEager(doc) { + doc.documentElement.lang = 'en'; decorateTemplateAndTheme(); - const main = document.querySelector('main'); + const main = doc.querySelector('main'); if (main) { decorateMain(main); - document.body.classList.add('appear'); + doc.body.classList.add('appear'); await waitForLCP(LCP_BLOCKS); } @@ -94,21 +94,21 @@ document.addEventListener('aem:eager', async () => { } catch (e) { // do nothing } -}); +} /** * Loads everything that doesn't need to be delayed. */ -document.addEventListener('aem:lazy', async () => { - const main = document.querySelector('main'); +async function loadLazy(doc) { + const main = doc.querySelector('main'); await loadBlocks(main); const { hash } = window.location; - const element = hash ? document.getElementById(hash.substring(1)) : false; + const element = hash ? doc.getElementById(hash.substring(1)) : false; if (hash && element) element.scrollIntoView(); - loadHeader(document.querySelector('header')); - loadFooter(document.querySelector('footer')); + loadHeader(doc.querySelector('header')); + loadFooter(doc.querySelector('footer')); loadCSS(`${window.hlx.codeBasePath}/styles/lazy-styles.css`); loadFonts(); @@ -116,54 +116,24 @@ document.addEventListener('aem:lazy', async () => { sampleRUM('lazy'); sampleRUM.observe(main.querySelectorAll('div[data-block-name]')); sampleRUM.observe(main.querySelectorAll('picture > img')); -}); +} /** * Loads everything that happens a lot later, * without impacting the user experience. */ -document.addEventListener('aem:delayed', async () => { - import('./delayed.js'); -}); - -document.addEventListener('aem:eager', (ev) => { - console.log(1, ev.type, ev.detail); - ev.await(new Promise((res) => { - setTimeout(() => { - console.log('foo from', ev.type); - res(); - }, 1000); - })); -}); - -document.addEventListener('aem:eager', (ev) => { - console.log(2, ev.type, ev.detail); -}); - -withPlugin('dummy-plugin', { - eager: () => console.log('plugin:eager'), - lazy: () => console.log('plugin:lazy'), - delayed: () => console.log('plugin:delayed'), -}); - -withPlugin('block-debugger', { - condition: () => true, - run: () => { - document.addEventListener('aem:block:config', (ev) => console.group(ev.detail.name) && console.log(ev.type, ev.detail)); - document.addEventListener('aem:block:decorated', (ev) => console.log(ev.type, ev.detail)); - document.addEventListener('aem:block:loaded', (ev) => console.log(ev.type, ev.detail) && console.groupEnd()); - }, -}); - -window.addEventListener('load', (ev) => console.log(ev.type, ev.detail)); -document.addEventListener('DOMContentLoaded', (ev) => console.log(ev.type, ev.detail)); -document.addEventListener('aem:eager', (ev) => console.log(ev.type, ev.detail)); -document.addEventListener('aem:lazy', (ev) => console.log(ev.type, ev.detail)); -document.addEventListener('aem:delayed', (ev) => console.log(ev.type, ev.detail)); +function loadDelayed() { + // eslint-disable-next-line import/no-cycle + window.setTimeout(() => import('./delayed.js'), 3000); + // load anything that can be postponed to the latest here +} async function loadPage() { await dispatchAsyncEvent('aem:eager'); + await loadEager(document); await dispatchAsyncEvent('aem:lazy'); + await loadLazy(document); + loadDelayed(); window.setTimeout(async () => { await dispatchAsyncEvent('aem:delayed'); }, 3000); From 7880a856cfefd84d1f276429ef9554d66acf6d59 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 21 Jun 2024 15:27:00 -0700 Subject: [PATCH 06/25] chore: cleanup PR --- scripts/scripts.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 173bc219c8..e76c70c7ff 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -134,9 +134,6 @@ async function loadPage() { await dispatchAsyncEvent('aem:lazy'); await loadLazy(document); loadDelayed(); - window.setTimeout(async () => { - await dispatchAsyncEvent('aem:delayed'); - }, 3000); } loadPage(); From 6c1a4e5abc0faa1fa5261e9bbed410ef2f2d2b05 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 21 Jun 2024 15:27:27 -0700 Subject: [PATCH 07/25] chore: cleanup PR --- scripts/scripts.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scripts/scripts.js b/scripts/scripts.js index e76c70c7ff..b0198584a6 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -75,6 +75,7 @@ export function decorateMain(main) { /** * Loads everything needed to get to LCP. + * @param {Element} doc The container element */ async function loadEager(doc) { doc.documentElement.lang = 'en'; @@ -98,6 +99,7 @@ async function loadEager(doc) { /** * Loads everything that doesn't need to be delayed. + * @param {Element} doc The container element */ async function loadLazy(doc) { const main = doc.querySelector('main'); From 69f097bdc5b16947c29ebd6e57b33a2cc40e36ab Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 21 Jun 2024 15:27:40 -0700 Subject: [PATCH 08/25] chore: cleanup PR --- scripts/scripts.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index b0198584a6..63dc3e6b05 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -11,10 +11,7 @@ import { waitForLCP, loadBlocks, loadCSS, - getMetadata, - toClassName, dispatchAsyncEvent, - withPlugin, } from './aem.js'; const LCP_BLOCKS = []; // add your LCP blocks to the list From 95b9a86f473a3bd9571a670c02e0d78d26098b5b Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 21 Jun 2024 15:28:21 -0700 Subject: [PATCH 09/25] chore: cleanup PR --- scripts/scripts.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scripts/scripts.js b/scripts/scripts.js index 63dc3e6b05..709141398e 100644 --- a/scripts/scripts.js +++ b/scripts/scripts.js @@ -123,7 +123,10 @@ async function loadLazy(doc) { */ function loadDelayed() { // eslint-disable-next-line import/no-cycle - window.setTimeout(() => import('./delayed.js'), 3000); + window.setTimeout(async () => { + await dispatchAsyncEvent('aem:lazy'); + import('./delayed.js'); + }, 3000); // load anything that can be postponed to the latest here } From 2381f58582f818bdcbcfa545accecb013fbef769 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Fri, 21 Jun 2024 15:37:47 -0700 Subject: [PATCH 10/25] chore: update to latest code --- scripts/aem.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/aem.js b/scripts/aem.js index 7adc7a08ee..903123a8f0 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -762,8 +762,11 @@ class TemplatesRegistry { // eslint-disable-next-line class-methods-use-this add(id, url) { const { id: templateId, config: templateConfig } = parsePluginParams(id, url); - templateConfig.condition = () => toClassName(getMetadata('template')) === templateId; - window.hlx.plugins.add(templateId, templateConfig); + window.hlx.plugins.add(templateId, { + ...templateConfig, + condition: () => toClassName(getMetadata('template')) === templateId, + load: 'eager', + }); } // Get the template From 430287af55137a149c6890db66ba97faa6d4fca1 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Tue, 23 Jul 2024 15:44:50 -0700 Subject: [PATCH 11/25] doc: add jsdoc --- scripts/aem.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/scripts/aem.js b/scripts/aem.js index 903123a8f0..0e4c5c818e 100644 --- a/scripts/aem.js +++ b/scripts/aem.js @@ -99,6 +99,12 @@ function sampleRUM(checkpoint, data = {}) { } } +/** + * Dispatches a custom DOM event and awaits all listeners before returning. + * @param {String} eventName The custom event to trigger + * @param {Object} [detail] Optional detail objec to pass to the event + * @returns a promise that all async listeners have run + */ async function dispatchAsyncEvent(eventName, detail = {}) { const promises = []; const event = new CustomEvent(eventName, { detail }); From d4e3999cc17b3f62e15ecd4321ad6f051edd3f43 Mon Sep 17 00:00:00 2001 From: Julien Ramboz Date: Wed, 11 Oct 2023 16:14:34 +0200 Subject: [PATCH 12/25] chore: update fstab --- fstab.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fstab.yaml b/fstab.yaml index 40ef9de12c..c54f824631 100644 --- a/fstab.yaml +++ b/fstab.yaml @@ -1,2 +1,2 @@ mountpoints: - /: https://drive.google.com/drive/u/0/folders/1MGzOt7ubUh3gu7zhZIPb7R7dyRzG371j \ No newline at end of file + /: https://drive.google.com/drive/u/0/folders/1MGzOt7ubUh3gu7zhZIPb7R7dyRzG371j From ef1e74836422be44818714084bb267ea59fb1fdc Mon Sep 17 00:00:00 2001 From: Alexandre Capt Date: Thu, 27 Jun 2024 09:53:49 +0200 Subject: [PATCH 13/25] feat: better error tracking (#375) --- 404.html | 7 ++++--- scripts/aem.js | 18 ++++++++++++------ 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/404.html b/404.html index 3baecc8d9a..6b37021f8d 100644 --- a/404.html +++ b/404.html @@ -11,8 +11,6 @@ +