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] Define components in template

See original GitHub issue

Questions

  • How can I make a part of my template a component ?
  • How can I set draggableComponents on such a component?
  • If so, then can I stop setting selectable: false, highlightable: false, hoverable: false on the child nodes inside said component?
  • Is it possible to supply a different external link to the component?

More explanation and a code part

I have a question because I think grapesjs is smarter than I use it currently. We have an asp.net app where its integrated, and we initialize it from an element. That element is the combination of our html template and data which give our users every day a prefilled newsletter with new content. They can drag articles around and then send it.

Our template has stuff like this (code in there is razor/cshtml stuff):

	<tr data-gjs-draggable="#main" data-gjs-copyable="false">
		<td data-gjs-selectable="false" data-gjs-highlightable="false" data-gjs-hoverable="false">
			<a data-gjs-selectable="false" data-gjs-highlightable="false" data-gjs-hoverable="false" href="https://www.@(Model.Site.Address)/subscribe/" target="_blank">
				<img data-gjs-selectable="false" data-gjs-highlightable="false" data-gjs-hoverable="false" style="margin-bottom: 5px;" alt="" src="https://cdn.@(Model.Site.Address)/Subscribe.jpg" border="0" width="468" />
			</a>
		</td>
	</tr>

To me it looks if this should be a component with the new draggableComponents option enabled. (see question 1-3)

This piece has an external link that will end up in the output. It would help our users if there could be another link that is not send out, but just for internal use (link to the editor in our cms). Maybe only available in the layer manager.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:8 (1 by maintainers)

github_iconTop GitHub Comments

2reactions
artfcommented, Nov 2, 2019

for the moment grapes has some issue on storing custom components defined outside plugins.

Actually, are stored correctly, it’s just about loading components that are not recognized because the custom type doesn’t exist yet, so this is the reason for putting the code in the plugin (plugins are loaded before fetching components). We’re updating the Component documentation and this thing will be the first recommendation (and the only available) for defining custom types

BTW @Jogai the approach described by @pouyamiralayi is correct. Instead of writing

<tr data-gjs-draggable="#main" data-gjs-copyable="false">

You can just define a custom component type (or extend the built-in row one)

 editor.DomComponents.addType('my-row',{
			extend: 'row',
            model:{
                defaults:{
					draggable: '#main',
					copyable: 'false',
				}
// ...

And use it where you need it

<tr data-gjs-type="my-row">

The properties will be taken from the defined component type. In this way, you’re more Component-oriented and it’s easier to reuse them around your templates

1reaction
pouyamiralayicommented, Aug 20, 2019

yes exactly. just remember defining your custom type inside a plugin. for the moment grapes has some issue on storing custom components defined outside plugins. cheers.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Template Components - Charm EHR
ChARM EHR Template Framework allow you to create your own templates with the ... Drag and Drop the 'Simple Question' component to the...
Read more >
Vue define component with template and script from Vue()
I am using Vue with typescript. import ListClubsComponent from "./components/ts/list-club"; new Vue({ el: "#app", components: { "list-clubs": { ...
Read more >
Which Components Can I Use with Each Aura Template?
Consult this table to find out which Aura template each component can be used in, and when the component became available.
Read more >
Templates - Lit.dev
Add a template to your component to define internal DOM to implement your component. To encapsulate the templated DOM LitElement uses shadow DOM....
Read more >
Component - Angular
Angular components are a subset of directives, always associated with a template. Unlike other directives, only one component can be instantiated for a...
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