Inserting/Editing links is hard
Question
You can only insert them in particular places, and making them "inline" is impossible. By "inline" I mean; I'm writing a line of text, and I want to put a link there, with some highlighted words that are the link, and continue with the words of the line. This is a very typical action and GrapesJS just won't let me do it.
Once you do get it dropped somewhere, it's hard to get the editor to actually edit them. You have to time the double-click, then click, just right to get it into the edit mode. I can't imagine giving my users that.
I'm going to give up and disable links altogether for my project, since I'm using the email preset, and the target document is an email, I'm going to rely on the typical email client's functionality of making a link clickable. I'm hopeful that this gets worked out in the near future. I understand that it's probably a hard problem.
Answers (3)
Hi @duskhacker,
I agree that link inserting/editing is not as intuitive as I would like, and am currently working on customizing it through a plugin. Here's a brief outline of what I'm working on, let me know if you're interested and I can provide the code (it's currently buried in a single plugin with lots of other customizations, so I'd need to do some work to isolate it):
- Link editing is done through a custom modal rather than the component settings
- When creating new link through the RTE toolbar (clicking the "link" button), the modal immediately appears and allows you to configure the link options (href, title, content)
- You can also open the modal by double clicking on an existing link. This kind of gets in the way of enabling the RTE, but I think it's a fair trade-off since you can edit the link content/text from the modal.
- The modal provides a more user friendly way to create different types of links (mailto, custom url, pre-defined links, anchor)
- I am also disabling all the default traits for links (might replace it with a custom "Edit Link" button...not sure yet) so that there is only 1 way to change the link attributes
Hi @lahdekorpi I think something like this should work
result: rte => {
// Use a custom attribute in order to find the component later
rte.insertHTML(`<span data-selectme>${rte.selection()}</span>`);
const sel = editor.getSelected(); // get the currect selected text component
sel.once('rte:disable', () => {
const toSel = sel.find('[data-selectme]')[0]; // Find the componenet to select
const attr = toSel.getAttributes();
delete attr['data-selectme'];
toSel.setAttributes(attr); // remove the custom attribute
toSel.set('selectable', true); // ensure the component is selectable
editor.select(toSel);
});
sel.trigger('disable'); // disables editing on the current component (this will also trigger the parser)
},
@YevhenShashnin updated the example as the RTE enable/disable functions became asynchronous.
Related Questions and Answers
Continue research with similar issue discussions.
Issue #2170
[QUESTION] Custom component - how to set editable to true
Hi, I've created a custom component type, but I am having some trouble making it editable. The component is a "span" with component type "t...
Issue #4383
BUG: A "." character is injected when inserting two whitespaces when editing any text component in grapesjs
GrapesJS version [X] I confirm to use the latest version of GrapesJS What browser are you using? Chrome Reproducible demo link https://grap...
Issue #3069
BUG: Style gone on link or nested text elements after exiting edit
Hello, I am editing legacy HTML with version 0.16.3 + newsleter-plugin. The style is stored inline (since the tool is used for authoring em...
Issue #3012
How to avoid tags to be detected as Component
I want to avoid some of the tags not to detect as components like 'B', 'I' etc tag. The problem is I have a component like this <p data-gjs...
Paid Plugins That Match This Issue
Curated by issue keywords and label relevance to help you ship faster.
Loading paid plugin recommendations...
Browse Plugin Categories
Jump directly to plugin category pages on the marketplace.