From d4b3daa871f3c619e2971efb63275a8e734bece1 Mon Sep 17 00:00:00 2001 From: Antoine Guenet Date: Fri, 22 Oct 2021 13:27:23 +0000 Subject: [PATCH] [REF] web_editor: import odoo-editor utils into convertInline Some code from odoo-editor utils is needed in convertInline. In order to avoid duplication, we need to import that code. To that effect, we can't have the utils being lazy loaded into mass mailing's iframe while convertInline is loaded the usual way. This loads the lightweight utils together with convertInline and turns convertInline into an odoo-module, which makes it easier to simply import the utils and delete duplicated code. X-original-commit: 067c94b009609caa0bd78a75b826247e37557417 Part-of: odoo/odoo#80621 --- addons/web_editor/__manifest__.py | 2 +- .../static/src/js/backend/convert_inline.js | 22 ++++--------------- 2 files changed, 5 insertions(+), 19 deletions(-) diff --git a/addons/web_editor/__manifest__.py b/addons/web_editor/__manifest__.py index f68bbd9dede..319f10e6857 100644 --- a/addons/web_editor/__manifest__.py +++ b/addons/web_editor/__manifest__.py @@ -41,7 +41,6 @@ Odoo Web Editor widget. 'web_editor/static/lib/odoo-editor/src/utils/constants.js', 'web_editor/static/lib/odoo-editor/src/utils/sanitize.js', 'web_editor/static/lib/odoo-editor/src/utils/serialize.js', - 'web_editor/static/lib/odoo-editor/src/utils/utils.js', 'web_editor/static/lib/odoo-editor/src/utils/DOMPurify.js', 'web_editor/static/lib/odoo-editor/src/tablepicker/TablePicker.js', 'web_editor/static/lib/odoo-editor/src/powerbox/patienceDiff.js', @@ -88,6 +87,7 @@ Odoo Web Editor widget. 'web.assets_common': [ 'web_editor/static/lib/vkbeautify/**/*', 'web_editor/static/src/js/common/**/*', + 'web_editor/static/lib/odoo-editor/src/utils/utils.js', ], 'web.assets_backend': [ 'web_editor/static/src/scss/web_editor.common.scss', diff --git a/addons/web_editor/static/src/js/backend/convert_inline.js b/addons/web_editor/static/src/js/backend/convert_inline.js index 8ae146c96ee..50c81a2395f 100644 --- a/addons/web_editor/static/src/js/backend/convert_inline.js +++ b/addons/web_editor/static/src/js/backend/convert_inline.js @@ -1,24 +1,11 @@ -odoo.define('web_editor.convertInline', function (require) { +/** @odoo-module alias=web_editor.convertInline */ 'use strict'; -var FieldHtml = require('web_editor.field.html'); +import FieldHtml from 'web_editor.field.html'; +import { rgbToHex } from '../../../lib/odoo-editor/src/utils/utils'; const SELECTORS_IGNORE = /(^\*$|:hover|:before|:after|:active|:link|::|'|\([^(),]+[,(])/; -// Note: duplicated from odoo-editor utils. -// DOES NOT SUPPORT RGBA (Outlook doesn't support transparency) -function rgbToHex(rgb = '') { - return ( - '#' + - (rgb.match(/\d{1,3}/g) || []) - .map(x => { - x = parseInt(x).toString(16); - return x.length === 1 ? '0' + x : x; - }) - .join('') - ); -} - /** * Returns the css rules which applies on an element, tweaked so that they are * browser/mail client ok. @@ -839,7 +826,7 @@ FieldHtml.include({ }, }); -return { +export default { fontToImg: fontToImg, bootstrapToTable: bootstrapToTable, cardToTable: cardToTable, @@ -851,4 +838,3 @@ return { normalizeRem: normalizeRem, attachmentThumbnailToLinkImg: attachmentThumbnailToLinkImg, }; -});