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

Feat: auto-create the link block when a non-image link is pasted #83

Open
wants to merge 22 commits into
base: master
Choose a base branch
from

Conversation

antoineol
Copy link

@antoineol antoineol commented Jun 25, 2023

Here is a feature I need for my project, and I thought it would be good to suggest a merge in the main repo.

Use case: when users paste links in the editor, in an empty paragraph, it should automatically attempt to create a link block.

It may introduce a couple of UX issues, so I also changed:

  • if the auto-link fails, it falls back to replacing the failed link with a paragraph with the raw link (only for auto-links, not for user-created link blocks)
  • a tune has been added: replace the embed with a raw link, in case the user's attempt was not to create a link block.
  • Those behaviors are only enabled if the auto-link is enabled.

Improvements I've identified, but I don't know how to do them:

  • I added 2 configs. In the second one, the user should repeat the plugin key, just because I wasn't able to get it dynamically in the plugin code (any idea about how to do that?)
  • When the URL is pasted and the block created, auto-show the tune menu

If you have any suggestions for them, I would be happy to improve the code.

When a URL is pasted and a link block created,
it automatically opens the block settings,
to show the user they can remove the preview.
@noistudio
Copy link

Вся ваша проблема решается , следующим куском кода
`static get pasteConfig() {
return {
// ... tags
// ... files
patterns: {
link: /https?://(www.)?[-a-zA-Z0-9@:%.+~#=]{1,256}.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%+.~#?&//=]*)/i
}
}
}

onPaste(event){
    switch (event.type){
        // ... case 'tag'
        // ... case 'file'
        case 'pattern':
            const link = event.detail.data;

            this.data.link=link;
            this.nodes.input.textContent=link;


            var event = new KeyboardEvent('keypress', {keyCode: 13});
            this.startFetching(event);



            break;
    }
}`

@Slowl
Copy link

Slowl commented Apr 22, 2024

Will this ever be merged or should I also fork the project and make my own version of it?

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

Successfully merging this pull request may close these issues.

4 participants