diff --git a/addons/web/static/src/core/browser/browser.js b/addons/web/static/src/core/browser/browser.js index 0223cc526d6..eb341750fa5 100644 --- a/addons/web/static/src/core/browser/browser.js +++ b/addons/web/static/src/core/browser/browser.js @@ -52,11 +52,11 @@ Object.defineProperty(browser, "location", { configurable: true, }); -Object.defineProperty(browser, 'innerHeight', { +Object.defineProperty(browser, "innerHeight", { get: () => window.innerHeight, configurable: true, }); -Object.defineProperty(browser, 'innerWidth', { +Object.defineProperty(browser, "innerWidth", { get: () => window.innerWidth, configurable: true, }); diff --git a/addons/web/static/src/core/file_input/file_input.xml b/addons/web/static/src/core/file_input/file_input.xml index aec7608927d..cb94c5d790d 100644 --- a/addons/web/static/src/core/file_input/file_input.xml +++ b/addons/web/static/src/core/file_input/file_input.xml @@ -9,7 +9,7 @@ diff --git a/addons/web/static/src/core/macro.js b/addons/web/static/src/core/macro.js index 3fd121ca403..7511e564dab 100644 --- a/addons/web/static/src/core/macro.js +++ b/addons/web/static/src/core/macro.js @@ -4,7 +4,9 @@ import { browser } from "@web/core/browser/browser"; // rough approximation of a visible element. not perfect (does not take into // account opacity = 0 for example), but good enough for our purpose -const isVisible = (e) => e.offsetWidth > 0 || e.offsetHeight > 0; +function isVisible(e) { + return e.offsetWidth > 0 || e.offsetHeight > 0; +} export const ACTION_HELPERS = { click(el, _step) { diff --git a/addons/web/static/src/core/ui/ui_service.js b/addons/web/static/src/core/ui/ui_service.js index 70e5245e707..6ad6ce1e9ec 100644 --- a/addons/web/static/src/core/ui/ui_service.js +++ b/addons/web/static/src/core/ui/ui_service.js @@ -55,7 +55,7 @@ export const MEDIAS_BREAKPOINTS = [ * * @returns {MediaQueryList[]} */ - export function getMediaQueryLists() { +export function getMediaQueryLists() { return MEDIAS_BREAKPOINTS.map(({ minWidth, maxWidth }) => { if (!maxWidth) { return window.matchMedia(`(min-width: ${minWidth}px)`); @@ -72,11 +72,9 @@ const MEDIAS = getMediaQueryLists(); export const uiService = { getSize() { - return MEDIAS.findIndex(media => media.matches); + return MEDIAS.findIndex((media) => media.matches); }, start(env) { - let ui = {}; - // block/unblock code const bus = new EventBus(); registry.category("main_components").add("BlockUI", { Component: BlockUI, props: { bus } }); @@ -101,18 +99,6 @@ export const uiService = { } } - Object.assign(ui, { - bus, - block, - unblock, - }); - - Object.defineProperty(ui, "isBlocked", { - get() { - return blockCount > 0; - }, - }); - // UI active element code let activeElems = [document]; @@ -132,34 +118,34 @@ export const uiService = { } } - Object.assign(ui, { + const ui = { + bus, + size: this.getSize(), + get activeElement() { + return activeElems[activeElems.length - 1]; + }, + get isBlocked() { + return blockCount > 0; + }, + get isSmall() { + return ui.size <= SIZES.SM; + }, + block, + unblock, activateElement, deactivateElement, getActiveElementOf, - }); - Object.defineProperty(ui, "activeElement", { - get() { - return activeElems[activeElems.length - 1]; - }, - }); + }; // listen to media query status changes - function updateSize() { + const updateSize = () => { ui.size = this.getSize(); - } - browser.addEventListener("resize", debounce(updateSize.bind(this), 100)); + }; + browser.addEventListener("resize", debounce(updateSize, 100)); - Object.assign(ui, { - size: this.getSize(), - }); - Object.defineProperty(ui, "isSmall", { - get() { - return ui.size <= SIZES.SM; - }, - }); Object.defineProperty(env, "isSmall", { get() { - return ui.size <= SIZES.SM; + return ui.isSmall; }, }); diff --git a/addons/web/static/src/core/utils/numbers.js b/addons/web/static/src/core/utils/numbers.js index 38a9d09e7da..a7bc46b8676 100644 --- a/addons/web/static/src/core/utils/numbers.js +++ b/addons/web/static/src/core/utils/numbers.js @@ -23,10 +23,10 @@ export function computeVariation(value, comparisonValue) { /** * Returns value clamped to the inclusive range of min and max. - * + * * @param {Number} num * @param {Number} min - * @param {Number} max + * @param {Number} max * @returns {Number} */ export function clamp(num, min, max) { diff --git a/addons/web/static/src/core/utils/strings.js b/addons/web/static/src/core/utils/strings.js index 879355ccebc..88b5185e3f9 100644 --- a/addons/web/static/src/core/utils/strings.js +++ b/addons/web/static/src/core/utils/strings.js @@ -91,9 +91,9 @@ export function intersperse(str, indices, separator = "") { export function sprintf(s, ...values) { if (values.length === 1 && Object.prototype.toString.call(values[0]) === "[object Object]") { const valuesDict = values[0]; - s = s.replace(/\%\(?([^\)]+)\)s/g, (match, value) => valuesDict[value]); + s = s.replace(/%\(?([^)]+)\)s/g, (match, value) => valuesDict[value]); } else if (values.length > 0) { - s = s.replace(/\%s/g, () => values.shift()); + s = s.replace(/%s/g, () => values.shift()); } return s; } @@ -108,6 +108,7 @@ export function capitalize(s) { return s ? s[0].toUpperCase() + s.slice(1) : ""; } +/* eslint-disable */ // prettier-ignore const diacriticsMap = { '\u0041': 'A','\u24B6': 'A','\uFF21': 'A','\u00C0': 'A','\u00C1': 'A','\u00C2': 'A','\u1EA6': 'A','\u1EA4': 'A','\u1EAA': 'A','\u1EA8': 'A', diff --git a/addons/web/static/src/env.js b/addons/web/static/src/env.js index bee4ef2fd4d..721fec8b261 100644 --- a/addons/web/static/src/env.js +++ b/addons/web/static/src/env.js @@ -118,7 +118,7 @@ async function _startServices(env, toStart) { } if (value instanceof Promise) { proms.push( - new Promise(async (resolve) => { + new Promise((resolve) => { value .then((val) => { services[name] = val || null; diff --git a/addons/web/static/src/webclient/actions/client_actions.js b/addons/web/static/src/webclient/actions/client_actions.js index 844142f381e..e157040d885 100644 --- a/addons/web/static/src/webclient/actions/client_actions.js +++ b/addons/web/static/src/webclient/actions/client_actions.js @@ -6,7 +6,7 @@ import { escape, sprintf } from "@web/core/utils/strings"; const { Component, onMounted, xml } = owl; -export const displayNotificationAction = (env, action) => { +export function displayNotificationAction(env, action) { const params = action.params || {}; const options = { className: params.className || "", @@ -20,7 +20,7 @@ export const displayNotificationAction = (env, action) => { const message = owl.markup(sprintf(escape(params.message), ...links)); env.services.notification.add(message, options); return params.next; -}; +} registry.category("actions").add("display_notification", displayNotificationAction); diff --git a/addons/web/static/tests/core/commands/command_service_tests.js b/addons/web/static/tests/core/commands/command_service_tests.js index 98b98579008..960030ffe7c 100644 --- a/addons/web/static/tests/core/commands/command_service_tests.js +++ b/addons/web/static/tests/core/commands/command_service_tests.js @@ -228,13 +228,13 @@ QUnit.test("data-hotkey added to command palette", async (assert) => { } MyComponent.components = { TestComponent }; MyComponent.template = xml` -
-
- `; +
+
+ `; await mount(MyComponent, target, { env }); // Open palette diff --git a/addons/web/static/tests/core/l10n/translation_tests.js b/addons/web/static/tests/core/l10n/translation_tests.js index 56048645de8..e675b319d2c 100644 --- a/addons/web/static/tests/core/l10n/translation_tests.js +++ b/addons/web/static/tests/core/l10n/translation_tests.js @@ -24,7 +24,7 @@ class TestComponent extends Component {} * @param {string} lang * @returns {Promise} */ -const patchLang = async (lang) => { +async function patchLang(lang) { const { defaultLocale, defaultNumberingSystem } = Settings; registerCleanup(() => { Settings.defaultLocale = defaultLocale; @@ -50,7 +50,7 @@ const patchLang = async (lang) => { }); serviceRegistry.add("localization", localizationService); await makeTestEnv(); -}; +} QUnit.module("Translations"); diff --git a/addons/web/static/tests/core/position_hook_tests.js b/addons/web/static/tests/core/position_hook_tests.js index f95c6134f18..7004c188ab3 100644 --- a/addons/web/static/tests/core/position_hook_tests.js +++ b/addons/web/static/tests/core/position_hook_tests.js @@ -153,7 +153,7 @@ QUnit.test("has no effect when component is destroyed", async (assert) => { ); }); -const getPositionTest = (position, positionToCheck) => { +function getPositionTest(position, positionToCheck) { return async (assert) => { assert.expect(2); positionToCheck = positionToCheck || position; @@ -167,7 +167,8 @@ const getPositionTest = (position, positionToCheck) => { }); await mount(TestComp, container); }; -}; +} + QUnit.test("position top", getPositionTest("top")); QUnit.test("position left", getPositionTest("left")); QUnit.test("position bottom", getPositionTest("bottom")); @@ -198,7 +199,8 @@ const CONTAINER_STYLE_MAP = { h125: { height: "125px" }, // height of popper + 1/2 reference w125: { width: "125px" }, // width of popper + 1/2 reference }; -const getRepositionTest = (from, to, containerStyleChanges) => { + +function getRepositionTest(from, to, containerStyleChanges) { return async (assert) => { assert.expect(4); const TestComp = getTestComponent({ @@ -220,7 +222,8 @@ const getRepositionTest = (from, to, containerStyleChanges) => { [d, v = "middle"] = to.split("-"); assert.verifySteps([`${d}-${v}`], `has ${to} position`); }; -}; +} + // ----------------------------------------------------------------------------- QUnit.test( "reposition from top-start to bottom-start",