editor-js / link

Link Tool for Editor.js 2.0
MIT License
92 stars 79 forks source link

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

Open antoineol opened 1 year ago

antoineol commented 1 year ago

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:

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

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

noistudio commented 1 year ago

Вся ваша проблема решается , следующим куском кода `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 commented 7 months ago

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