Coder Social home page Coder Social logo

unlayer / vue-email-editor Goto Github PK

View Code? Open in Web Editor NEW
561.0 19.0 162.0 2.04 MB

Drag-n-Drop Email Editor Component for Vue.js

Home Page: https://unlayer.com/embed

JavaScript 2.89% HTML 6.29% Vue 56.40% TypeScript 34.42%
vue vuejs template email-template drag-and-drop email-marketing builder vue-components html-email

vue-email-editor's Introduction

Vue Email Editor

The excellent drag-n-drop email editor by Unlayer as a Vue wrapper component. This is the most powerful and developer friendly visual email builder for your app.

Video Overview
Vue Email Editor
Watch video overview: https://youtu.be/MIWhX-NF3j8

Live Demo

Check out the live demo here: https://vue-email-editor-demo.netlify.app/ (Source Code)

Installation

The easiest way to use Vue Email Editor is to install it from Npm or Yarn and include it in your own Vue build process.

npm install vue-email-editor --save

or

yarn add vue-email-editor

Usage

Next, you'll need to import the Email Editor component to your app.

App.vue

<template>
  <div id="app">
    <div class="container">
      <div id="bar">
        <h1>Vue Email Editor (Demo)</h1>

        <button v-on:click="saveDesign">Save Design</button>
        <button v-on:click="exportHtml">Export HTML</button>
      </div>

      <EmailEditor
        ref="emailEditor"
        v-on:load="editorLoaded"
        v-on:ready="editorReady"
      />
    </div>
  </div>
</template>

<script>
  import { EmailEditor } from 'vue-email-editor';

  export default {
    name: 'app',
    components: {
      EmailEditor,
    },
    methods: {
      // called when the editor is created
      editorLoaded() {
        console.log('editorLoaded');
        // Pass the template JSON here
        // this.$refs.emailEditor.editor.loadDesign({});
      },
      // called when the editor has finished loading
      editorReady() {
        console.log('editorReady');
      },
      saveDesign() {
        this.$refs.emailEditor.editor.saveDesign((design) => {
          console.log('saveDesign', design);
        });
      },
      exportHtml() {
        this.$refs.emailEditor.editor.exportHtml((data) => {
          console.log('exportHtml', data);
        });
      },
    },
  };
</script>

Methods

method params description
loadDesign Object data Takes the design JSON and loads it in the editor
saveDesign Function callback Returns the design JSON in a callback function
exportHtml Function callback Returns the design HTML and JSON in a callback function

See the example source for a reference implementation.

Properties

  • editorId String HTML div id of the container where the editor will be embedded (optional)
  • minHeight String minimum height to initialize the editor with (default 500px)
  • options Object options passed to the Unlayer editor instance (default {})
  • tools Object configuration for the built-in and custom tools (default {})
  • appearance Object configuration for appearance and theme (default {})
  • projectId Integer Unlayer project ID (optional)
  • locale String translations string (default en-US)

See the Unlayer Docs for all available options.

Here's an example using the above properties...

App.vue

<template>
  <div id="app">
    <div class="container">
      <div id="bar">
        <h1>Vue Email Editor (Demo)</h1>

        <button v-on:click="saveDesign">Save Design</button>
        <button v-on:click="exportHtml">Export HTML</button>
      </div>

      <EmailEditor
        :appearance="appearance"
        :min-height="minHeight"
        :project-id="projectId"
        :locale="locale"
        :tools="tools"
        :options="options"
        ref="emailEditor"
        v-on:load="editorLoaded"
        v-on:ready="editorReady"
      />
    </div>
  </div>
</template>

<script>
  import { EmailEditor } from 'vue-email-editor';

  export default {
    name: 'app',
    components: {
      EmailEditor,
    },
    data() {
      return {
        minHeight: '1000px',
        locale: 'en',
        projectId: 0, // replace with your project id
        tools: {
          // disable image tool
          image: {
            enabled: false,
          },
        },
        options: {},
        appearance: {
          theme: 'dark',
          panels: {
            tools: {
              dock: 'right',
            },
          },
        },
      };
    },
    methods: {
      // called when the editor is created
      editorLoaded() {
        console.log('editorLoaded');
        // Pass your template JSON here
        // this.$refs.emailEditor.editor.loadDesign({});
      },
      // called when the editor has finished loading
      editorReady() {
        console.log('editorReady');
      },
      saveDesign() {
        this.$refs.emailEditor.editor.saveDesign((design) => {
          console.log('saveDesign', design);
        });
      },
      exportHtml() {
        this.$refs.emailEditor.editor.exportHtml((data) => {
          console.log('exportHtml', data);
        });
      },
    },
  };
</script>

Custom Tools

Custom tools can help you add your own content blocks to the editor. Every application is different and needs different tools to reach it's full potential. Learn More

Custom Tools

Localization

You can submit new language translations by creating a PR on this GitHub repo: https://github.com/unlayer/translations. Translations managed by PhraseApp

License

Copyright (c) 2021 Unlayer. MIT Licensed.

vue-email-editor's People

Contributors

adeelraza avatar brunolemos avatar lucasbesen avatar mafnankhan avatar omerzahidbajwa avatar umairsiddique avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vue-email-editor's Issues

loadDesign method returns console errors

On rendering of the component, my prop (object) passed from the parent contains the JSON object as a property. But When I render the component I got console errors. What I'm a doing wrong here?

<EmailEditor ref="emailEditor" :min-height="minHeight" @load="editorLoaded" />
editorLoaded() { // Pass the template JSON here console.log(this.newsletterTemplate) this.$refs.emailEditor.editor.loadDesign(this.newsletterTemplate.model) },

JSON Object
model: "{\"counters\":{\"u_column\":4,\"u_row\":2},\"body\":{\"rows\":[{\"cells\":[1],\"columns\":[{\"contents\":[],\"values\":{\"backgroundColor\":\"\",\"padding\":\"0px\",\"border\":{},\"_meta\":{\"htmlID\":\"u_column_1\",\"htmlClassNames\":\"u_column\"}}}],\"values\":{\"displayCondition\":null,\"columns\":false,\"backgroundColor\":\"\",\"columnsBackgroundColor\":\"\",\"backgroundImage\":{\"url\":\"\",\"fullWidth\":true,\"repeat\":false,\"center\":true,\"cover\":false},\"padding\":\"0px\",\"hideDesktop\":false,\"_meta\":{\"htmlID\":\"u_row_1\",\"htmlClassNames\":\"u_row\"},\"selectable\":true,\"draggable\":true,\"duplicatable\":true,\"deletable\":true,\"hideable\":true}},{\"cells\":[1,1,1],\"columns\":[{\"contents\":[],\"values\":{\"backgroundColor\":\"\",\"padding\":\"0px\",\"border\":{},\"_meta\":{\"htmlID\":\"u_column_2\",\"htmlClassNames\":\"u_column\"}}},{\"contents\":[],\"values\":{\"backgroundColor\":\"\",\"padding\":\"0px\",\"border\":{},\"_meta\":{\"htmlID\":\"u_column_3\",\"htmlClassNames\":\"u_column\"}}},{\"contents\":[],\"values\":{\"backgroundColor\":\"\",\"padding\":\"0px\",\"border\":{},\"_meta\":{\"htmlID\":\"u_column_4\",\"htmlClassNames\":\"u_column\"}}}],\"values\":{\"displayCondition\":null,\"columns\":false,\"backgroundColor\":\"\",\"columnsBackgroundColor\":\"\",\"backgroundImage\":{\"url\":\"\",\"fullWidth\":true,\"repeat\":false,\"center\":true,\"cover\":false},\"padding\":\"0px\",\"_meta\":{\"htmlID\":\"u_row_2\",\"htmlClassNames\":\"u_row\"},\"selectable\":true,\"draggable\":true,\"duplicatable\":true,\"deletable\":true,\"hideable\":true}}],\"values\":{\"textColor\":\"#000000\",\"backgroundColor\":\"#e7e7e7\",\"backgroundImage\":{\"url\":\"\",\"fullWidth\":true,\"repeat\":false,\"center\":true,\"cover\":false},\"contentWidth\":\"500px\",\"contentAlign\":\"center\",\"fontFamily\":{\"label\":\"Arial\",\"value\":\"arial,helvetica,sans-serif\"},\"preheaderText\":\"\",\"linkStyle\":{\"body\":true,\"linkColor\":\"#0000ee\",\"linkHoverColor\":\"#0000ee\",\"linkUnderline\":true,\"linkHoverUnderline\":true},\"_meta\":{\"htmlID\":\"u_body\",\"htmlClassNames\":\"u_body\"}}},\"schemaVersion\":6}

Screenshot 2021-09-10 at 12 58 10

Error with drag and drop

Screenshot at May 04 14-37-39

Hello Developers, i'm having issue when run example code in my vue project. I can't drag and drop block or content into the box on the left. Can you help me to resolve this problem. Example code same like your code. Please help me. Thank you so much

locale value doesn't update

      <EmailEditor
        :locale="somecondition ? 'ar': 'en'"
        ref="emailEditor"
        @load="editorLoaded"
        @ready="editorReady"
      />

locale property takes the first value and it doesn't watch for changes.
I need your kind support to make this property reactive.

iframe height does not fill 100% height of parent

I've inserted the editor (full demo) inside a from vuetify
The iframe is 50px height!
When I inspect source:
element.style {
min-width: 1024px;
min-height: 100%;
height: 100%;
width: 100%;
border: 0px;
}

If I set min-height to 500px, it works!
How can I fix 100% or a min-height by default?

vue 3 error

image
is it possible to bypass this error somehow?
on vue2 this error seems not to show

Fade-desktop class added on desktop view when loading a template

When loading a design from JSON, the editor is faded out on the desktop view (class fade-desktop is added to several div's). When switching to mobile view, this behavior is not occurring (and the template is properly displayed). Switching back adds the fade-desktop class again.

I've been trying to troubleshoot this for a few weeks but can't seem to find a solution.

Any tips? You can see the behavior here in this JSFiddle: https://jsfiddle.net/o3bea8fs/3/

Thanks for your time.

Laravel Error

Im trying to run with laravel mix but I can't figure out how,

I installed unlayer-vue with npm install

I created the component App.vue with the name

I load the component in welcome.blade.php and loads only a part of it

image

This is the component that its not loading: <EmailEditor ref="emailEditor" v-on:load="editorLoaded" />

Console show me 3 errors on this route: http://editor.unlayer.com/1.1.73/editor.js

Im pretty far to be an expert in Vuejs but, if you can give me any support to make it work with laravelmix ill appreciated.

Cutom tools

Hello, i already create an account on Unlayer platform, but i didn't found any examples or docs about adding custom tools to the VueJs component .

Merge tag support?

Is there support for the merge tags?

I have noticed there is no setMergeTags method in the Vue, or Angular repos only react.

I have tried to grab the setMergeTags from the react repo and put it into EmailEditor.vue but getting reference errors. I thought maybe this would work modifying my EmailEditor component. But I assume it may be further up in the imported "//editor.unlayer.com/embed.js" file.

setMergeTags(mergeTags){ unlayer.setMergeTags(mergeTags) }

as well as initializing

 unlayerScript.onload = () => {
      this.loadEditor();
      this.modifyStyle();
      this.setMergeTags();
    };

  if (this.mergeTags) {
        options.mergeTags = this.mergeTags
      }

unlayer.init({
        ...options,
        id: 'editor',
        displayMode: 'email',
        appearance: {
          theme: 'dark'
        },
        mergeTags: {}
      });

the reference Error is

ReferenceError: unlayer is not defined
at c.setMergeTags (EmailEditor.vue:88)

URL in MergeTags dont work

<template>
  <div id="app">
    <div class="container">
      <div id="bar">
        <h1>Vue Email Editor (Demo)</h1>

        <button v-on:click="saveDesign">Save Design</button>
        <button v-on:click="exportHtml">Export HTML</button>
      </div>

      <EmailEditor
        style="height: 300px"
        :appearance="appearance"
        :min-height="minHeight"
        :project-id="projectId"
        :locale="locale"
        :tools="tools"
        :options="options"
        :merge-tags="mergeTags"
        :set-merge-tags="setMergeTags"
        ref="emailEditor"
        v-on:load="editorLoaded"
      />
    </div>
  </div>
</template>

<script>
import { EmailEditor } from "vue-email-editor";

export default {
  name: "unlayer",
  components: {
    EmailEditor,
  },
  data() {
    return {
      minHeight: "1000px",
      locale: "en",
      projectId: 0, // replace with your project id
      tools: {
        // disable image tool
        image: {
          enabled: true,
        },
      },
      options: {
        
        mergeTags: {
          productsCard: {
            name: "Produtos do carrinho",
            mergeTags: {
              product_card_name: {
                name: "Nome do produto",
                value: [],
              },
              product_card_image: {
                name:"Product Card Image",
                value: [],
              }
            },
          },
          productsViewed: {
            name: "Produtos que o cliente visualizou",
            mergeTags: {
              product_viewed_name: {
                name: "Nome do produto",
                value: [],
              },
              product_viewed_image: {
                name: "Imagem do produto",
                value: [],
              },
            },
          },
        },
      },
      appearance: {
        theme: "dark",
        panels: {
          tools: {
            dock: "right",
          },
        },
      },
    };
  },
  mounted(){
    this.loadMergeTags();
  },
  methods: {
    loadMergeTags(){
      this.options.mergeTags.productsCard.mergeTags.product_card_name.value.push('testPush');
      this.options.mergeTags.productsCard.mergeTags.product_card_image.value.push('image.png');
    },
    editorLoaded() {
      // Pass your template JSON here
      // this.$refs.emailEditor.editor.loadDesign({});
    },
    saveDesign() {
      this.$refs.emailEditor.editor.saveDesign((design) => {
        console.log("saveDesign", design);
      });
    },
    exportHtml() {
      this.$refs.emailEditor.editor.exportHtml((data) => {
        console.log("exportHtml", data);
      });
    },
  },
};
</script>

inserting URL values in the data of a mergetag doesn't work, although I see examples and copy the way they were made, I'd like to know how to do it.

tested using array (as in the example), tested using variable, tested using sample(default value), using local image URL and an external link, and the image is not inserted, also tested using setMergeTags and it didn't work

the idea is to push the values, according to the products in the system, when the template is loaded, the push insertion of the product name works, but the insertion of an image by URL doesn't work

How do you enable Form tool?

Having an issue getting forms to work with the Vue component. Does it need to be in display mode web, or is it supported in email?

The documentation show enabling forms as the following.

unlayer.init({
  tools: {
    form: {
      enabled: false
    }
  }
});

However when trying to enable it via the tools props it doesn't show up.

<EmailEditor ref="documentEditor" :options="options" :tools="tools" @load="editorLoaded" />

The following is from the example which also does not work.

      tools: {
        form: {
          properties: {
            action: {
              editor: {
                data: {
                  actions: [
                    {
                      label: "Marketing",
                      method: "POST",
                      url: "http://whatever.com/marketing-form-submission",
                    },
                    {
                      label: "Sales",
                      method: "POST",
                      target: "_blank",
                      url: "http://whatever.com/sales-form-submission",
                    },
                  ],
                },
              },
            },
          },
        },
     }

CDN or UNPKG

Hi,
I am trying CDN or UNPKG but it is not working. Could you please take a look?
I need the UMD or JS for use as global CDN.
Can you give me an example, please.
Thank you

previewHtml callback called two times

I saw that the previewHtml callback is called two times when showing the preview and I was wondering why. This is making my implementation a bit more complicated and I was wondering what is the reason, if I can make it trigger only once or if this is a bug.

How to reset the editor?

Is there a way to reset the editor's content so that can the user has a clean start? I think this would be very useful.

vue2 error

i install 'vue-email-editor' in vue2 project, console this error:

[Vue warn]: Error in render: "TypeError: (0 , external_commonjs_vue_commonjs2_vue_root_Vue_namespaceObject.openBlock) is not a function"

and i find out the that there isn't any 'vue.esm-bundler.js' in my node_module/vue/dist

How should i solve this problem?

¿Live Demo?

Idk if this is the right place to ask that, but do you have a live demo ?

Properties and reactivity

Somehow component properties are not reactive.

For example binding the locale property like :locale="en-US" and changing the language dynamically has no effect at the component.

Is there any destroy method? Any thoughts how can I achieve this?

Thanks

Can't save design

Hi there,

I am using this project to integrate it in our backend. There I want to load an initial template which the user can edit however he wants. The template then is saved in our database. However, when I edit the template using the rich text editor, these design adjustments are not saved. When I add text or use the edit section on the right, it is saved.
Auto saving appears to work, it is called every time a change is made, but then the database is not updated. I tried calling exportHtml and saveDesign. Do I actually need to call saveDesign when I already save the html and the json in exportHtml?

Can not add custom tool

I was trying to add a custom tool on vue js component as the documentation for react shows with no luck. Can you demonstrate the correct way to add a new custom tool on vue .js

Doesn't support vue 2

when i try to integrate with vue 2 (^2.6.14) this error occur. Uncaught TypeError: webpack_modules[moduleId] is not a function

designTagsConfig

Adding designTagsConfig to the editors options stops the editor loading:

options:{
    projectId: ****,
    displayMode: 'email',
    designTagsConfig: {
        delimiter: ['[[[', ']]]']
    }
}

Uncaught DOMException: Failed to execute 'postMessage' on 'Window': #<Object> could not be cloned. at http://editor.unlayer.com/embed.js?2:1:13252 at Array.forEach (<anonymous>) at e.value (http://editor.unlayer.com/embed.js?2:1:13174) at iframe.onload (http://editor.unlayer.com/embed.js?2:1:12257)

Has anyone gotten this to work with Vue2 + Vite

Import EmailEditor fails with Vite, and it appears that the master version is no longer compatible with Vue2. There are no tags or releases to reference. Does anybody know which version work2 with Vue2?

Thanks, Juha

trying to load custom block with the JavaScript API

how can we create a custom block JSON? this is my sample code ?
<EmailEditor ref="emailEditor" :min-height="minHeight" :locale="locale" @load="editorLoaded" @ready="editorReady" />

This is the load function

`
const editorLoaded = () => {

 // This is the variable I need fill 
let blocks = [];

emailEditor.value.editor.registerProvider('blocks', function (params, done) {
    console.log('blocks provider', params);
    done(blocks);
});
};

`

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.