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. *