Skip to content

Commit f9b3764

Browse files
authored
fix: text leaf to detect parent correctly (#340)
1 parent 0f587db commit f9b3764

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

packages/2d/src/lib/components/Txt.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import {is} from '../utils';
1111
import type {Node} from './Node';
1212
import type {ShapeProps} from './Shape';
1313
import {Shape} from './Shape';
14-
import {TxtLeaf} from './TxtLeaf';
14+
import {TXT_TYPE, TxtLeaf} from './TxtLeaf';
1515
import type {ComponentChildren} from './types';
1616

1717
type TxtChildren = string | Node | (string | Node)[];
@@ -24,6 +24,8 @@ export interface TxtProps extends ShapeProps {
2424

2525
@nodeName('Txt')
2626
export class Txt extends Shape {
27+
public readonly [TXT_TYPE] = true;
28+
2729
/**
2830
* Create a bold text node.
2931
*

packages/2d/src/lib/components/TxtLeaf.ts

+11-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ export interface TxtLeafProps extends ShapeProps {
1515
text?: SignalValue<string>;
1616
}
1717

18+
export const TXT_TYPE = Symbol('Txt');
19+
1820
@nodeName('TxtLeaf')
1921
export class TxtLeaf extends Shape {
2022
@lazy(() => {
@@ -43,7 +45,15 @@ export class TxtLeaf extends Shape {
4345
@computed()
4446
protected parentTxt() {
4547
const parent = this.parent();
46-
return parent?.constructor.name === 'Txt' ? parent : null;
48+
if (!parent) {
49+
return null;
50+
}
51+
52+
if (!(TXT_TYPE in parent)) {
53+
return null;
54+
}
55+
56+
return parent;
4757
}
4858

4959
protected override async draw(context: CanvasRenderingContext2D) {

packages/2d/src/lib/jsx-runtime.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ function isClassComponent(
2121
return !!fn.prototype?.isClass;
2222
}
2323

24-
export const Fragment = Symbol.for('@revideo/2d/fragment');
24+
export const Fragment: FunctionComponent = ({children}) => children;
25+
2526
export function jsx(
2627
type: NodeConstructor | FunctionComponent | typeof Fragment,
2728
config: JSXProps,

0 commit comments

Comments
 (0)