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

Inline custom widgets #5065

Open
ghostbear opened this issue Mar 7, 2021 · 2 comments
Open

Inline custom widgets #5065

ghostbear opened this issue Mar 7, 2021 · 2 comments

Comments

@ghostbear
Copy link

ghostbear commented Mar 7, 2021

Hi!

I'm experiencing some issues with creating custom widgets that are inline with the text, like this

Lorem ipsum dolor sit amet, <Navigation item="more"/> consectetur adipiscing elit.

I'm expecting this to show a selector that writers can use to select a navigation item when using rich text, but none is shown and the preview text is also not shown.

This works fine when they are on their own, like this

Lorem ipsum dolor sit amet,

<Navigation item="more"/>

consectetur adipiscing elit.

This shows a selector that the writers can use to select a navigation item when using rich text

So is it possible to even get it to show custom widgets when they are inline, like bold or italic? Or am I trying to do something that is not possible to do with custom widgets currently?

Image showing the issue:
image


CMS.registerEditorComponent({
	id: "navigation",
	label: "Navigation",
	fields: [
		{
			name: "item",
			label: "Item",
			widget: "select",
			options: Object.keys(itemMap).map(key => {
				return { label: itemMap[key].text, value: key }
			}),
			required: true
		},
	],
	pattern: /<Navigation item="([a-zA-Z\-_]+)"\/>/,
	fromBlock: function(match) {
		return {
			item: match[1] || 'library',
		};
	},
	toBlock: function(obj) {
		return `<Navigation item="${obj.item || 'library'}"/>`;
	},
	toPreview: function(obj) {	
		return `<p>${obj.item || 'library'}<p/>`
	},
});

This code is the code for the custom widget. It gives a warning on all items that are inline for example Sent invalid data to remark. Plugin: navigation. Value: <Navigation item="more"/>. Data: {"item":"more"}. I have tried looking for a solution but I have not found one.

@doompadee
Copy link
Contributor

Same issue here. I'm trying to integrate custom Hugo shortcodes with the editor, but it currently does not seem possible which makes Netlify less ideal if non tech-savvy writers are involved.

@rudasn
Copy link

rudasn commented Apr 8, 2022

Anybody had any luck with getting inline custom editor widgets to work?

I'm also looking into using the rel or refrel Hugo shortcode into the Richtext editor to allow users to add links to other parts of the site using the shortcode (as opposed to copy & pasting a URL). Any links created with this widget should be displayed inline (not block) in the Richtext view (as well as the end result, obviously). The widget would allow to select a page to link to, specify the title, and other properties like target).

From my understanding, that would require a way to specify to netlify that the custom widget (let's call it the Hugo Links widget) should be rendered as an inline element in the richtext editor (using a text slate object as opposed to a block).

Then, using a customised version of the existing Object widget we could display the HugoLinks widget inline with the text, click on it to expand/edit the properties, and click again to toggle back to inline.

I just started to look into netlify a couple of days ago so this may not be right approach, so I would greatly appreciate the input of more experienced members. The ability to not easily handle links is kind of a deal breaker, especially for non-technical users.

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

No branches or pull requests

4 participants