From f54d83199ec62272ee8b4987b2e63f188e1b2e29 Mon Sep 17 00:00:00 2001 From: JC Brand Date: Fri, 17 Jan 2025 22:07:37 +0200 Subject: [PATCH] Allow Builder instances to be passed as `cnode` parameter --- CHANGELOG.md | 1 + src/builder.js | 5 ++++- src/types/builder.d.ts | 4 ++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6864a4b..a8903ef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ ## Version 3.1.1 - (Unreleased) - Strip unnecessary whitespace from `Stanza` elements +- Allow `Builder` instances to be passed into the `cnode` function - Bugfix. Handle `null` and `undefined` values inside `stx` tagged template literals. ## Version 3.1.0 - (2024-12-16) diff --git a/src/builder.js b/src/builder.js index 3a1bc35..e8e9aab 100644 --- a/src/builder.js +++ b/src/builder.js @@ -293,10 +293,13 @@ class Builder { * name and an attributes object to create the child it uses an * existing DOM element object. * - * @param {Element} elem - A DOM element. + * @param {Element|Builder} elem - A DOM element. * @return {Builder} The Strophe.Builder object. */ cnode(elem) { + if (elem instanceof Builder) { + elem = elem.tree(); + } let impNode; const xmlGen = xmlGenerator(); try { diff --git a/src/types/builder.d.ts b/src/types/builder.d.ts index a848ec8..2248531 100644 --- a/src/types/builder.d.ts +++ b/src/types/builder.d.ts @@ -169,10 +169,10 @@ declare class Builder { * name and an attributes object to create the child it uses an * existing DOM element object. * - * @param {Element} elem - A DOM element. + * @param {Element|Builder} elem - A DOM element. * @return {Builder} The Strophe.Builder object. */ - cnode(elem: Element): Builder; + cnode(elem: Element | Builder): Builder; /** * Add a child text element. *