Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: text leaf to detect parent correctly #340

Merged
merged 2 commits into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion packages/2d/src/lib/components/Txt.ts
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@ import {is} from '../utils';
import type {Node} from './Node';
import type {ShapeProps} from './Shape';
import {Shape} from './Shape';
import {TxtLeaf} from './TxtLeaf';
import {TXT_TYPE, TxtLeaf} from './TxtLeaf';
import type {ComponentChildren} from './types';

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

@nodeName('Txt')
export class Txt extends Shape {
public readonly [TXT_TYPE] = true;

/**
* Create a bold text node.
*
12 changes: 11 additions & 1 deletion packages/2d/src/lib/components/TxtLeaf.ts
Original file line number Diff line number Diff line change
@@ -15,6 +15,8 @@ export interface TxtLeafProps extends ShapeProps {
text?: SignalValue<string>;
}

export const TXT_TYPE = Symbol('Txt');

@nodeName('TxtLeaf')
export class TxtLeaf extends Shape {
@lazy(() => {
@@ -43,7 +45,15 @@ export class TxtLeaf extends Shape {
@computed()
protected parentTxt() {
const parent = this.parent();
return parent?.constructor.name === 'Txt' ? parent : null;
if (!parent) {
return null;
}

if (!(TXT_TYPE in parent)) {
return null;
}

return parent;
}

protected override async draw(context: CanvasRenderingContext2D) {
3 changes: 2 additions & 1 deletion packages/2d/src/lib/jsx-runtime.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ function isClassComponent(
return !!fn.prototype?.isClass;
}

export const Fragment = Symbol.for('@revideo/2d/fragment');
export const Fragment: FunctionComponent = ({children}) => children;

export function jsx(
type: NodeConstructor | FunctionComponent | typeof Fragment,
config: JSXProps,
Loading