Skip to content

Commit 9859731

Browse files
committed
html
1 parent 9e1ad4c commit 9859731

File tree

9 files changed

+984
-15
lines changed

9 files changed

+984
-15
lines changed

libs/core/src/lib/renderer/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
export const ROUTED_SCENE = '__ngt_renderer_is_routed_scene__';
2+
export const HTML = '__ngt_renderer_is_html';
23
export const SPECIAL_INTERNAL_ADD_COMMENT = '__ngt_renderer_add_comment__';
34

45
export const SPECIAL_DOM_TAG = {

libs/core/src/lib/renderer/index.ts

Lines changed: 36 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import { injectNgtStore, provideNgtStore, type NgtStore } from '../store';
2121
import type { NgtAnyRecord } from '../types';
2222
import { is } from '../utils/is';
2323
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';
2525
import { NGT_COMPOUND_PREFIXES, NgtRendererStore, type NgtRendererNode, type NgtRendererState } from './store';
2626
import { NgtRendererClassId, attachThreeChild, kebabToPascal, processThreeEvent, removeThreeChild } from './utils';
2727

@@ -47,9 +47,10 @@ class NgtRendererFactory implements RendererFactory2 {
4747
const delegate = this.delegateRendererFactory.createRenderer(hostElement, type);
4848
if (!type) return delegate;
4949
// 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+
}
5354
if ((type as NgtAnyRecord)['type'][ROUTED_SCENE]) {
5455
this.routedSet.add(type.id);
5556
}
@@ -176,10 +177,17 @@ class NgtRenderer implements Renderer2 {
176177
}
177178

178179
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__;
182180
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+
}
183191

184192
if (cRS[NgtRendererClassId.type] === 'comment') {
185193
this.store.setParent(newChild, parent);
@@ -296,6 +304,7 @@ class NgtRenderer implements Renderer2 {
296304
// we'll try to get the grandparent instance here so that we can run appendChild with both instances
297305
const closestGrandparentInstance = this.store.getClosestParentWithInstance(parent);
298306
if (closestGrandparentInstance) this.appendChild(closestGrandparentInstance, newChild);
307+
return;
299308
}
300309
}
301310

@@ -313,6 +322,13 @@ class NgtRenderer implements Renderer2 {
313322
removeChild(parent: NgtRendererNode, oldChild: NgtRendererNode, isHostElement?: boolean | undefined): void {
314323
const pRS = parent.__ngt_renderer__;
315324
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+
316332
if (pRS[NgtRendererClassId.type] === 'three' && cRS[NgtRendererClassId.type] === 'three') {
317333
removeThreeChild(parent, oldChild, true);
318334
this.store.destroy(oldChild, parent);
@@ -354,7 +370,12 @@ class NgtRenderer implements Renderer2 {
354370
return;
355371
}
356372

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);
358379
}
359380

360381
setProperty(el: NgtRendererNode, name: string, value: any): void {
@@ -379,7 +400,12 @@ class NgtRenderer implements Renderer2 {
379400
return;
380401
}
381402

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);
383409
}
384410

385411
listen(target: NgtRendererNode, eventName: string, callback: (event: any) => boolean | void): () => void {
@@ -462,3 +488,4 @@ export function provideNgtRenderer(store: NgtStore, compoundPrefixes: string[],
462488
}
463489

464490
export { extend } from './catalogue';
491+
export { HTML } from './constants';

libs/core/src/lib/renderer/store.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ export class NgtRendererStore {
116116
}
117117

118118
removeChild(node: NgtRendererNode, child: NgtRendererNode) {
119-
const index = node.__ngt_renderer__[NgtRendererClassId.children].findIndex((c) => child === c);
119+
const index = node.__ngt_renderer__?.[NgtRendererClassId.children].findIndex((c) => child === c);
120120
if (index >= 0) {
121121
node.__ngt_renderer__[NgtRendererClassId.children].splice(index, 1);
122122
}
@@ -331,7 +331,7 @@ export class NgtRendererStore {
331331

332332
destroy(node: NgtRendererNode, parent?: NgtRendererNode) {
333333
const rS = node.__ngt_renderer__;
334-
if (rS[NgtRendererClassId.destroyed]) return;
334+
if (!rS || rS[NgtRendererClassId.destroyed]) return;
335335
if (rS[NgtRendererClassId.type] === 'three') {
336336
rS[NgtRendererClassId.compound] = undefined!;
337337
rS[NgtRendererClassId.compoundParent] = undefined!;
@@ -398,7 +398,7 @@ export class NgtRendererStore {
398398
// nullify parent
399399
rS[NgtRendererClassId.parent] = null;
400400
for (const renderChild of rS[NgtRendererClassId.children] || []) {
401-
if (renderChild.__ngt_renderer__[NgtRendererClassId.type] === 'three' && parent) {
401+
if (renderChild.__ngt_renderer__?.[NgtRendererClassId.type] === 'three' && parent) {
402402
removeThreeChild(parent, renderChild, true);
403403
}
404404
this.destroy(renderChild, parent);

libs/soba/.storybook/preview-body.html

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,9 @@
3434
.html-story-label {
3535
background-color: white;
3636
color: black;
37-
width: 100px;
38-
height: 20px;
37+
font-size: 2rem;
38+
width: auto;
39+
height: auto;
3940
display: flex;
4041
align-items: center;
4142
justify-content: center;

0 commit comments

Comments
 (0)