question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Adding new components to existing ones

See original GitHub issue

Hello,

I would like to ask if there’s any existing support or API for adding new components to an existing component list (e. g. after fetching or generating them dynamically). I’m talking about something like this:

editor.addComponent({
  parent: 'parent_id',
  component: '<p>New child component</p>'
})

I’ve studied the documentation and the closest I got is the addComponents() function. Unfortunately, this function specifies no target where the new component should be placed.

I’m asking this because my intention is to use GrapesJS in a real-time collaborative way and sending the whole HTML representation back and forth after every user action is just too slow.

Best regards, Michal

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
baxxoscommented, Nov 27, 2017

Thanks for your replies, I think my question has been answered and there’s not much else to add. I’m closing this now, however the find() method would be a welcome addition to this awesome framework.

1reaction
ryandebacommented, Nov 22, 2017

Unfortunately I am not aware of a simple way to get a specific component object without recursively iterating through them to find the one you want, but that sounds like a great idea!

You might be able to do something like this to get all components and then filter for the one that you want (this code is not fully tested, but hopefully can get you started in the right direction if you’re stuck):

function getAllComponents(component) {
	component = component || editor.DomComponents.getWrapper();

	var components = component.get("components").models;
	component.get("components").forEach(function(component) {
		components = components.concat(getAllComponents(component));
	});

	return components;
};

getAllComponents().filter(function(component) { return component.cid == "someID"; } )[0]

Read more comments on GitHub >

github_iconTop Results From Across the Web

Create and insert component instances - Figma Help Center
Select the Assets tab in the left sidebar, or use the shortcut: Mac: ⌥ Option 2; Windows: Alt + 2 · Find the...
Read more >
How to Add Components to an Existing Build
To add components you first fetch the missing component(s). The way to fetch the new component is to add the missing component(s) on...
Read more >
Fusion 360 Help | Create new components | Autodesk
Click the X to clear the selection. In the Browser, click to select the new parent component. From Bodies: Check the box to...
Read more >
Adding new components to existing design - PCB Design
Basically, just add few new resistors - copy nearest one and paste as much times as I need. Make needed connections, and use...
Read more >
Add new elements in Master Component – Adobe XD Feedback
Requirement Reason: This way we wouldn't need to ungroup the component to add the new element every time. The requirement usually occurs in ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found