From 61fc3f4fdc6c6dd9271ebdccd218c035a97e0d8d Mon Sep 17 00:00:00 2001 From: Samuel Degueldre Date: Fri, 12 Jan 2024 11:03:03 +0100 Subject: [PATCH] [REL] v2.2.8 # v2.2.8 - [IMP] template set config: getTemplate function - [IMP] parser: .trim modifier implies .lazy modifier - [REF] parser, template_set: factor out parseXML function --- docs/owl.js | 65 +++++++++++++++-------------------------------- package-lock.json | 2 +- package.json | 2 +- src/version.ts | 2 +- 4 files changed, 23 insertions(+), 48 deletions(-) diff --git a/docs/owl.js b/docs/owl.js index e857c50c9..2115c64de 100644 --- a/docs/owl.js +++ b/docs/owl.js @@ -3159,8 +3159,14 @@ const helpers = { makeRefWrapper, }; -const bdom = { text, createBlock, list, multi, html, toggler, comment }; -function parseXML$1(xml) { +/** + * Parses an XML string into an XML document, throwing errors on parser errors + * instead of returning an XML document containing the parseerror. + * + * @param xml the string to parse + * @returns an XML document corresponding to the content of the string + */ +function parseXML(xml) { const parser = new DOMParser(); const doc = parser.parseFromString(xml, "text/xml"); if (doc.getElementsByTagName("parsererror").length) { @@ -3187,7 +3193,9 @@ function parseXML$1(xml) { throw new OwlError(msg); } return doc; -} +} + +const bdom = { text, createBlock, list, multi, html, toggler, comment }; class TemplateSet { constructor(config = {}) { this.rawTemplates = Object.create(globalTemplates); @@ -3206,6 +3214,7 @@ class TemplateSet { } } } + this.getRawTemplate = config.getTemplate; } static registerTemplate(name, fn) { globalTemplates[name] = fn; @@ -3235,15 +3244,16 @@ class TemplateSet { // empty string return; } - xml = xml instanceof Document ? xml : parseXML$1(xml); + xml = xml instanceof Document ? xml : parseXML(xml); for (const template of xml.querySelectorAll("[t-name]")) { const name = template.getAttribute("t-name"); this.addTemplate(name, template); } } getTemplate(name) { + var _a; if (!(name in this.templates)) { - const rawTemplate = this.rawTemplates[name]; + const rawTemplate = ((_a = this.getRawTemplate) === null || _a === void 0 ? void 0 : _a.call(this, name)) || this.rawTemplates[name]; if (rawTemplate === undefined) { let extraInfo = ""; try { @@ -4953,9 +4963,9 @@ function parseDOMNode(node, ctx) { const isSelect = tagName === "select"; const isCheckboxInput = isInput && typeAttr === "checkbox"; const isRadioInput = isInput && typeAttr === "radio"; - const hasLazyMod = attr.includes(".lazy"); - const hasNumberMod = attr.includes(".number"); const hasTrimMod = attr.includes(".trim"); + const hasLazyMod = hasTrimMod || attr.includes(".lazy"); + const hasNumberMod = attr.includes(".number"); const eventType = isRadioInput ? "click" : isSelect || hasLazyMod ? "change" : "input"; model = { baseExpr, @@ -5501,41 +5511,6 @@ function normalizeTEscTOut(el) { function normalizeXML(el) { normalizeTIf(el); normalizeTEscTOut(el); -} -/** - * Parses an XML string into an XML document, throwing errors on parser errors - * instead of returning an XML document containing the parseerror. - * - * @param xml the string to parse - * @returns an XML document corresponding to the content of the string - */ -function parseXML(xml) { - const parser = new DOMParser(); - const doc = parser.parseFromString(xml, "text/xml"); - if (doc.getElementsByTagName("parsererror").length) { - let msg = "Invalid XML in template."; - const parsererrorText = doc.getElementsByTagName("parsererror")[0].textContent; - if (parsererrorText) { - msg += "\nThe parser has produced the following error message:\n" + parsererrorText; - const re = /\d+/g; - const firstMatch = re.exec(parsererrorText); - if (firstMatch) { - const lineNumber = Number(firstMatch[0]); - const line = xml.split("\n")[lineNumber - 1]; - const secondMatch = re.exec(parsererrorText); - if (line && secondMatch) { - const columnIndex = Number(secondMatch[0]) - 1; - if (line[columnIndex]) { - msg += - `\nThe error might be located at xml line ${lineNumber} column ${columnIndex}\n` + - `${line}\n${"-".repeat(columnIndex - 1)}^`; - } - } - } - } - throw new OwlError(msg); - } - return doc; } function compile(template, options = {}) { @@ -5562,7 +5537,7 @@ function compile(template, options = {}) { } // do not modify manually. This file is generated by the release script. -const version = "2.2.7"; +const version = "2.2.8"; // ----------------------------------------------------------------------------- // Scheduler @@ -5991,6 +5966,6 @@ TemplateSet.prototype._compileTemplate = function _compileTemplate(name, templat export { App, Component, EventBus, OwlError, __info__, blockDom, loadFile, markRaw, markup, mount, onError, onMounted, onPatched, onRendered, onWillDestroy, onWillPatch, onWillRender, onWillStart, onWillUnmount, onWillUpdateProps, reactive, status, toRaw, useChildSubEnv, useComponent, useEffect, useEnv, useExternalListener, useRef, useState, useSubEnv, validate, validateType, whenReady, xml }; -__info__.date = '2023-12-06T13:56:01.636Z'; -__info__.hash = 'e94428a'; +__info__.date = '2024-01-12T10:02:46.131Z'; +__info__.hash = '7b454da'; __info__.url = 'https://github.com/odoo/owl'; diff --git a/package-lock.json b/package-lock.json index 90f112f89..67bcf450d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@odoo/owl", - "version": "2.2.7", + "version": "2.2.8", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/package.json b/package.json index 26508924e..b3966dc64 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@odoo/owl", - "version": "2.2.7", + "version": "2.2.8", "description": "Odoo Web Library (OWL)", "main": "dist/owl.cjs.js", "module": "dist/owl.es.js", diff --git a/src/version.ts b/src/version.ts index 6657bdbf7..7e2ca0093 100644 --- a/src/version.ts +++ b/src/version.ts @@ -1,2 +1,2 @@ // do not modify manually. This file is generated by the release script. -export const version = "2.2.7"; +export const version = "2.2.8";