1- import DomAccess from '../DomAccess.mjs' ;
2-
31const StringBasedRenderer = {
42 /**
5- * @param {String } html representing a single element
3+ * @param {Object } data
4+ * @param {String } data.outerHTML The HTML string of the node to create.
65 * @returns {DocumentFragment }
76 */
8- htmlStringToElement ( html ) {
7+ createNode ( { outerHTML } ) {
98 const template = document . createElement ( 'template' ) ;
10- template . innerHTML = html ;
9+ template . innerHTML = outerHTML ;
1110 return template . content
12- } ,
13-
14- /**
15- * Handles string-based insertion of a new node into the DOM.
16- * This method is called by `insertNode()` when `NeoConfig.useDomApiRenderer` is false.
17- *
18- * @param {Object } data
19- * @param {Boolean } data.hasLeadingTextChildren Flag to honor leading comments.
20- * @param {Number } data.index The index at which to insert the new node.
21- * @param {String } data.outerHTML The HTML string of the node to insert.
22- * @param {HTMLElement } data.parentNode The parent DOM node to insert into.
23- * @param {Object[] } [data.postMountUpdates] Array of post-mount updates (e.g. scroll state).
24- * @private
25- */
26- insertNodeAsString ( { hasLeadingTextChildren, index, outerHTML, parentNode, postMountUpdates} ) {
27- let me = this ;
28-
29- // If comments detected, parse HTML string to a node and use insertBefore/appendChild on childNodes.
30- if ( hasLeadingTextChildren ) {
31- let node = me . htmlStringToElement ( outerHTML ) ;
32-
33- if ( index < parentNode . childNodes . length ) {
34- parentNode . insertBefore ( node , parentNode . childNodes [ index ] )
35- } else {
36- parentNode . appendChild ( node )
37- }
38- }
39- // If no comments detected, use insertAdjacentHTML for element nodes.
40- else {
41- let countChildren = parentNode . children . length ; // Use `children` for `insertAdjacentHTML` context
42-
43- if ( index > 0 && index >= countChildren ) {
44- parentNode . insertAdjacentHTML ( 'beforeend' , outerHTML ) ;
45- } else if ( countChildren > 0 && countChildren > index ) {
46- parentNode . children [ index ] . insertAdjacentHTML ( 'beforebegin' , outerHTML )
47- } else if ( countChildren > 0 ) {
48- parentNode . children [ countChildren - 1 ] . insertAdjacentHTML ( 'afterend' , outerHTML )
49- } else {
50- parentNode . insertAdjacentHTML ( 'beforeend' , outerHTML )
51- }
52- }
53-
54- if ( postMountUpdates ?. length > 0 ) {
55- let node ;
56-
57- postMountUpdates . forEach ( update => {
58- node = DomAccess . getElement ( update . id ) ;
59-
60- if ( node ) {
61- if ( update . scrollLeft ) { node . scrollLeft = update . scrollLeft }
62- if ( update . scrollTop ) { node . scrollTop = update . scrollTop }
63- }
64- } )
65- }
6611 }
6712} ;
6813
6914const ns = Neo . ns ( 'Neo.main.render' , true ) ;
7015ns . StringBasedRenderer = StringBasedRenderer ;
7116
72- export default StringBasedRenderer ;
17+ export default StringBasedRenderer ;
0 commit comments