@@ -21,7 +21,7 @@ import { injectNgtStore, provideNgtStore, type NgtStore } from '../store';
21
21
import type { NgtAnyRecord } from '../types' ;
22
22
import { is } from '../utils/is' ;
23
23
import { injectNgtCatalogue , type NgtAnyConstructor } from './catalogue' ;
24
- import { ROUTED_SCENE , SPECIAL_DOM_TAG } from './constants' ;
24
+ import { HTML , ROUTED_SCENE , SPECIAL_DOM_TAG } from './constants' ;
25
25
import { NGT_COMPOUND_PREFIXES , NgtRendererStore , type NgtRendererNode , type NgtRendererState } from './store' ;
26
26
import { NgtRendererClassId , attachThreeChild , kebabToPascal , processThreeEvent , removeThreeChild } from './utils' ;
27
27
@@ -47,9 +47,10 @@ class NgtRendererFactory implements RendererFactory2 {
47
47
const delegate = this . delegateRendererFactory . createRenderer ( hostElement , type ) ;
48
48
if ( ! type ) return delegate ;
49
49
// TODO: handle html in canvas
50
- // if ((type as NgtAnyRecord)['type']['isHtml']) {
51
- // return delegateRenderer;
52
- // }
50
+ if ( ( type as NgtAnyRecord ) [ 'type' ] [ HTML ] ) {
51
+ this . rendererMap . set ( type . id , delegate ) ;
52
+ return delegate ;
53
+ }
53
54
if ( ( type as NgtAnyRecord ) [ 'type' ] [ ROUTED_SCENE ] ) {
54
55
this . routedSet . add ( type . id ) ;
55
56
}
@@ -176,10 +177,17 @@ class NgtRenderer implements Renderer2 {
176
177
}
177
178
178
179
appendChild ( parent : NgtRendererNode , newChild : NgtRendererNode ) : void {
179
- // TODO: just ignore text node for now
180
- if ( newChild instanceof Text ) return ;
181
- const cRS = newChild . __ngt_renderer__ ;
182
180
const pRS = parent . __ngt_renderer__ ;
181
+ const cRS = newChild . __ngt_renderer__ ;
182
+
183
+ if (
184
+ pRS [ NgtRendererClassId . type ] === 'dom' &&
185
+ ( newChild instanceof Text || cRS [ NgtRendererClassId . type ] === 'dom' )
186
+ ) {
187
+ this . store . addChild ( parent , newChild ) ;
188
+ this . delegate . appendChild ( parent , newChild ) ;
189
+ return ;
190
+ }
183
191
184
192
if ( cRS [ NgtRendererClassId . type ] === 'comment' ) {
185
193
this . store . setParent ( newChild , parent ) ;
@@ -296,6 +304,7 @@ class NgtRenderer implements Renderer2 {
296
304
// we'll try to get the grandparent instance here so that we can run appendChild with both instances
297
305
const closestGrandparentInstance = this . store . getClosestParentWithInstance ( parent ) ;
298
306
if ( closestGrandparentInstance ) this . appendChild ( closestGrandparentInstance , newChild ) ;
307
+ return ;
299
308
}
300
309
}
301
310
@@ -313,6 +322,13 @@ class NgtRenderer implements Renderer2 {
313
322
removeChild ( parent : NgtRendererNode , oldChild : NgtRendererNode , isHostElement ?: boolean | undefined ) : void {
314
323
const pRS = parent . __ngt_renderer__ ;
315
324
const cRS = oldChild . __ngt_renderer__ ;
325
+
326
+ if ( cRS [ NgtRendererClassId . type ] === 'dom' && ( ! pRS || pRS [ NgtRendererClassId . type ] === 'dom' ) ) {
327
+ this . delegate . removeChild ( parent , oldChild ) ;
328
+ this . store . destroy ( oldChild , parent ) ;
329
+ return ;
330
+ }
331
+
316
332
if ( pRS [ NgtRendererClassId . type ] === 'three' && cRS [ NgtRendererClassId . type ] === 'three' ) {
317
333
removeThreeChild ( parent , oldChild , true ) ;
318
334
this . store . destroy ( oldChild , parent ) ;
@@ -354,7 +370,12 @@ class NgtRenderer implements Renderer2 {
354
370
return ;
355
371
}
356
372
357
- if ( rS [ NgtRendererClassId . type ] === 'three' ) this . store . applyAttribute ( el , name , value ) ;
373
+ if ( rS [ NgtRendererClassId . type ] === 'three' ) {
374
+ this . store . applyAttribute ( el , name , value ) ;
375
+ return ;
376
+ }
377
+
378
+ return this . delegate . setAttribute ( el , name , value ) ;
358
379
}
359
380
360
381
setProperty ( el : NgtRendererNode , name : string , value : any ) : void {
@@ -379,7 +400,12 @@ class NgtRenderer implements Renderer2 {
379
400
return ;
380
401
}
381
402
382
- if ( rS [ NgtRendererClassId . type ] === 'three' ) this . store . applyProperty ( el , name , value ) ;
403
+ if ( rS [ NgtRendererClassId . type ] === 'three' ) {
404
+ this . store . applyProperty ( el , name , value ) ;
405
+ return ;
406
+ }
407
+
408
+ return this . delegate . setProperty ( el , name , value ) ;
383
409
}
384
410
385
411
listen ( target : NgtRendererNode , eventName : string , callback : ( event : any ) => boolean | void ) : ( ) => void {
@@ -462,3 +488,4 @@ export function provideNgtRenderer(store: NgtStore, compoundPrefixes: string[],
462
488
}
463
489
464
490
export { extend } from './catalogue' ;
491
+ export { HTML } from './constants' ;
0 commit comments