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

Nested elements are created as Linked Nodes instead of child nodes #603

Closed
caseymilne opened this issue Jan 18, 2024 · 1 comment
Closed

Comments

@caseymilne
Copy link

Describe the bug
I don't know if this is a bug or normal behavior but when I provide a toolbox to drop in a component with multiple Elements nested, these do not show up as parent/child in the node tree data. This means in my custom layers I see only the top node. Upon inspection I find that top node has linked node, and those nodes are created properly, but they are not connected as children. Strangely though, in the UI they do appear nested, so maybe that relationship is maintained somewhere? Is this normal behavior? Because this is clearly a tree, I want them made as a tree rather than using linked nodes, which I thought would be the normal default behavior?

import React from 'react';
import { Element, useNode } from "@craftjs/core";
import StandardProperties from '../Properties/StandardProperties';
import { SectionElement } from '../UserComponents/SectionElement';
import { ImgElement } from '../UserComponents/ImgElement';

export const HeroTypeA = ({ classes }) => {

	const { connectors: { connect, drag } } = useNode();

	return (
		<Element id="hero-section" is={SectionElement} ref={ref => connect(drag(ref))} classes={classes} canvas>
			<Element id="hero-logo" is={ImgElement} ref={ref => connect(drag(ref))} classes={classes} src="https://tailwindui.com/img/logos/mark.svg?color=indigo&shade=600"/>
		</Element>
  );

}

HeroTypeA.craft = {
	displayName: "Hero Type A",
	props: {
		classes: '',
	},
	related: {
    settings: StandardProperties,
  },
	isCanvas: true,
}
@caseymilne
Copy link
Author

I realized after creating more nested Elements that the children further nested are stored in data.nodes[]. It's just this component itself where it is parented to ROOT or whatever parent it's dropped into, and it uses data.linkedNodes instead of data.nodes[] to store the reference to it's first child.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants