Issue #1638💬 AnsweredOpened December 7, 2018by Abhisheknanda13444631 reactions

How to stop css repeatition

快速解答by artf1

Update your grapesjs and next time, please, create a live demo of your issues

Read full answer below ↓

Question

hi @artf here is my code of Export-template i make it editable

define(function() {
  const juice = require('juice');
  return (opt = {}) => {
    let editor = opt.editor;
    let codeViewer = editor && editor.CodeManager.getViewer('CodeMirror').clone();
    let btnImp = document.createElement("button");
    let container = document.createElement("div");
      var cmdm = editor.Commands;
    let pfx = opt.pfx || '';
    const juiceOpts = opt.juiceOpts || {};
    // Init import button
    btnImp.innerHTML = opt.modalBtnImport;
    btnImp.className = pfx + 'btn-prim ' + pfx + 'btn-import';
    btnImp.onclick = () => {
      let code = codeViewer.editor.getValue();
      editor.DomComponents.getWrapper().set('content', '');
      editor.setComponents(code);
      editor.Modal.close();
    };
    // Init code viewer
    codeViewer.set({
      codeName: 'htmlmixed',
      theme: opt.codeViewerTheme,
      readOnly: 0
    });

    // Set the command which could be used outside
    cmdm.add(opt.cmdInlineHtml, {
      run(editor, sender, opts = {}) {
        const tmpl = editor.getHtml() + `<style>${editor.getCss()}</style>`;
        return juice(tmpl, opts);
      }
    })

    return {
      run(editor, sender) {
        let md = editor.Modal;
        let modalContent = md.getContentEl();
        let viewer = codeViewer.editor;
        md.setTitle(opt.modalTitleImport);
        // Init code viewer if not yet instantiated
        if(!viewer){
          let txtarea = document.createElement('textarea');
          if(opt.modalLabelImport){
            let labelEl = document.createElement('div');
            labelEl.className = pfx + 'import-label';
            labelEl.innerHTML = opt.modalLabelImport;
            container.appendChild(labelEl);
          }
          container.appendChild(txtarea);
          container.appendChild(btnImp);
          codeViewer.init(txtarea);
          viewer = codeViewer.editor;
          viewer.setOption('lineWrapping', 1);
        }
        md.setContent(container);
        const tmpl = editor.getHtml() + `<style>${editor.getCss()}</style>`;
        codeViewer.setContent(opt.inlineCss ? juice(tmpl, juiceOpts) : tmpl);
        md.open();
        viewer.refresh();
        sender && sender.set('active', 0);
      },
    }
  };
});

Also, i add a media-query to display in view code with this

editor.setComponents(mycss) screen shot 2018-12-07 at 1 52 07 pm

when i update something form this button it'll work fine but i am using it in my rails app by including minified version . and when update something in rails all media-query css got repeated Can you please suggest me something to handle this.???

Thanks

Answers (3)

artfDecember 7, 2018

Update your grapesjs and next time, please, create a live demo of your issues

Abhisheknanda1344463December 10, 2018

Thanks @artf
yeah definitely :)

lock[bot]December 10, 2019

This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

Related Questions and Answers

Continue research with similar issue discussions.

Paid Plugins That Match This Issue

Curated by issue keywords and label relevance to help you ship faster.

View all plugins

Loading paid plugin recommendations...

Free option

Check the open-source GrapesJS plugins on GitHub or run a quick search in our free catalog.

Browse free plugins →
Premium option

Premium plugins ship with support, regular updates, and production-ready features — save days of integration work.

Browse premium plugins →

Related tutorials

In-depth guides on the same topic.

All tutorials →

Browse Plugin Categories

Jump directly to plugin category pages on the marketplace.