Ju99ernaut / grapesjs-component-code-editor

Code editor for grapesjs
MIT License
64 stars 21 forks source link

Plugin brake editor loading in safari #34

Closed alextaranishyn closed 2 years ago

alextaranishyn commented 2 years ago

grapesjs-component-code-editor/index.js updateHtml method uses invalid regex symbols for Safari browser


        e?.preventDefault();
        const { editor, component } = this;
        let htmlCode = this.htmlCodeEditor.getContent().trim();
        if (!htmlCode || htmlCode === this.previousHtmlCode) return;
        this.previousHtmlCode = htmlCode;

        let idStyles = '';
        this.cssCodeEditor
            .getContent()
            .split(/(?<=}\n)/g)
            .forEach(rule => {
                if (/^#/.test(rule))
                    idStyles += rule;
            });

        htmlCode += `<style>${idStyles}</style>`;

        if (component.attributes.type === 'wrapper') {
            editor.setComponents(htmlCode);
        } else {
            editor.select(component.replaceWith(htmlCode));
        }
    }```

   .split(/(?<=}\n)/g) use lookbehind symbol 
Ju99ernaut commented 2 years ago

Haven't had the chance to test on safari, is there an alternative that would work for safari and other browsers? Would be open to merging the PR