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.

[QUESTION] Custom component property that is not a trait

See original GitHub issue

I would like to create a custom component with a property that will be updated by specific code, but I don’t want this property to be visible and updatable as a trait; let say my property is called “ebTesto”, I wrote a plugin function like that:

function addComponentX(editor, options){
	const COMPONENT_TYPE = 'eb-componentx';
	editor.DomComponents.addType(COMPONENT_TYPE, {
		isComponent: function(el) {
			if(el.getAttribute && el.getAttribute('data-gjs-type') ==COMPONENT_TYPE) {
				return {type:COMPONENT_TYPE};
			}
		 },		      	
		 model: {
		      defaults: {
			      ebTesto: 'Ciao',
			      tagName: 'div',
			      components: [
					{
						type:'text',
						content: 'Title component X',
						removable: false
					}
				]						
			},
			ebTesto: 'Ciao'				
		}		      	
	});
	editor.BlockManager.add(COMPONENT_TYPE, {
		    label: 'Component X',
		    category: 'EB',
		    attributes: {class:'eb-componentx-block'},
		    content: `<div class="eb-componentx" data-gjs-type="${COMPONENT_TYPE}"></div>`
      });
}

I expected to find my new property in the “gjs-components” part of the stored JSON, but this is what I got:

[
  {
    "type": "eb-componentx",
    "classes": [
      "eb-componentx"
    ],
    "components": [
      {
        "type": "text",
        "removable": false,
        "content": "Title component X"
      }
    ]
  }
]

Maybe I’m trying the wrong way? Has anyone ever had a similar need? Thanks for your help!

Issue Analytics

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

github_iconTop GitHub Comments

2reactions
ltenti-eventboostcommented, Apr 23, 2021

Thank you both!

1reaction
Ju99ernautcommented, Apr 22, 2021

I think it’s not stored since the property hasn’t been changed from the default. The editor should be able to recover the property from the component definition itself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

[QUESTION] Reset trait on edit the content of a custom ...
Hi,. I have a custom component which content can be changed by switching trait select options, but also can be edited similar to...
Read more >
How to Define Custom Traits on Grapes-js and How to ...
I am trying to do changing the position of the components by selecting the option on traits like if I Select traits to...
Read more >
Overriding properties of trait - Laracasts
I want to be able to use my trait in a model like below but set properties in the model that define the...
Read more >
Adding custom component to app in lightning experience
I deployed custom lightning web component (deployed source) to org. It was redirected to my org but that custom component is not visible...
Read more >
Custom Property Disappearing from Component After
The custom property in question is the one called "On Select". ... does this when the Component Property has a name not containing...
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