Giter VIP home page Giter VIP logo

vue-froala-wysiwyg's Introduction

Vue JS Froala WYSIWYG Editor

npm npm npm

vue-froala-wyswiyg provides Vue bindings to the Froala WYSIWYG editor VERSION 3.

Compatibility

  • v3 later
    • Vue.js 3.x

Installation

Install vue-froala-wysiwyg from npm

npm install vue-froala-wysiwyg --save

Integration

1. Require and use Froala Editor component inside your application.

main.js file:

//Import Froala Editor 
import 'froala-editor/js/plugins.pkgd.min.js';
//Import third party plugins
import 'froala-editor/js/third_party/embedly.min';
import 'froala-editor/js/third_party/font_awesome.min';
import 'froala-editor/js/third_party/spell_checker.min';
import 'froala-editor/js/third_party/image_tui.min';
// Import Froala Editor css files.
import 'froala-editor/css/froala_editor.pkgd.min.css';
import 'froala-editor/css/froala_style.min.css';

import App from './App'
import { createApp } from 'vue'
import VueFroala from 'vue-froala-wysiwyg';

const app = createApp(App);          

app.use(VueFroala);
app.mount('#app');

App.vue file:

<template>
  <div id="app">
    <froala id="edit" :tag="'textarea'" :config="config" v-model:value="model"></froala>
  </div>
</template>

<script>

export default {
  name: 'App',
  data () {
    return {
      config: {
        events: {
          initialized: function () {
            console.log('initialized')
          }
        }
      },
      model: 'Edit Your Content Here!'
    }
  }
}
</script>

2. Make sure you have the right Webpack settings for loading the CSS files.

var webpack = require('webpack')
var path = require('path')

module.exports = {
  module: {
    loaders: [

      // ...

      // Css loader.
      {
        test: /\.css$/,
        loader: 'cssLoader'
      }

    ]
  },
  vue: {
    loaders: {

      // ...

      // Css loader for Webpack 1.x .
      css: 'cssLoader'
    }
  }
})

Usage

Initialize

// If model is initialized, 'Init text' text child will be overwritten.
<froala :tag="'textarea'" :config="config" v-model:value="model">Init text</froala>

:tag attr is used to tell on which tag the editor is initialized.

There are special tags: a, button, img, input.

Options

You can pass editor options as component attribute (optional).

:config="config"

You can pass any existing Froala option. Consult the Froala documentation to view the list of all the available options:

config: {
  placeholderText: 'Edit Your Content Here!',
  charCounterCount: false
}

Aditional option is used:

  • immediateVueModelUpdate: (default: false) This option updates the Vue model as soon as a key is released in the editor. Note that it may affect performances.

Events and Methods

Events can be passed in with the options, with a key events and object where the key is the event name and the value is the callback function.

config: {
  placeholder: "Edit Me",
  events : {
    focus : function(e, editor) {
      console.log(editor.selection.get());
    }
  }
}

Using the editor instance from the arguments of the callback you can call editor methods as described in the method docs.

Froala events are described in the events docs.

Model

The WYSIWYG HTML editor content model. Two way binding is suported.

v-model:value="model"

Use the content in other places:

<input v-model:value="model"/>

Special tags

You can also use the editor on img, button, input and a tags:

<froala :tag="img" v-model:value="imgModel"></froala>

The model must be an object containing the attributes for your special tags. Example:

imgModel: {
  src: require('./image.jpg')
}

The model will change as the attributes change during usage.

  • The model can contain a special attribute named innerHTML which inserts innerHTML in the element: If you are using 'button' tag, you can specify the button text like this:
buttonModel: {
  innerHTML: 'Click Me'
}

As the button text is modified by the editor, the innerHTML attribute from buttonModel model will be modified too.

Specific option for special tags

  • vueIgnoreAttrs: (default: null) This option is an array of attributes that you want to ignore when the editor updates the v-model:
config: {
 vueIgnoreAttrs: ['class', 'id']
}

Custom Buttons

You can pass the custom buttons to the editor by following way:

App.vue file:

<script>
import FroalaEditor from 'froala-editor';

FroalaEditor.DefineIcon('alert', {NAME: 'info', SVG_KEY: 'help'});
  FroalaEditor.RegisterCommand('alert', {
    title: 'Hello',
    focus: false,
    undo: false,
    refreshAfterCallback: false,
    callback: function () {
      alert('Hello!');
    }
  });

  FroalaEditor.DefineIcon('clear', {NAME: 'remove', SVG_KEY: 'remove'});
  FroalaEditor.RegisterCommand('clear', {
    title: 'Clear HTML',
    focus: false,
    undo: true,
    refreshAfterCallback: true,
    callback: function () {
      this.html.set('');
      this.events.focus();
    }
  });

  FroalaEditor.DefineIcon('insert', {NAME: 'plus', SVG_KEY: 'add'});
  FroalaEditor.RegisterCommand('insert', {
    title: 'Insert HTML',
    focus: true,
    undo: true,
    refreshAfterCallback: true,
    callback: function () {
      this.html.insert('My New HTML');
    }
  });
  </script>
  

Now you can use these buttons in options:

toolbarButtons: [['undo', 'redo' , 'bold'], ['alert', 'clear', 'insert']],

Manual Instantiation

Gets the functionality to operate on the editor: create, destroy and get editor instance. Use it if you want to manually initialize the editor.

:onManualControllerReady="initialize"

initialize: function(initControls) {
  this.initControls = initControls;
  this.deleteAll = () => {
      this.initControls.getEditor().html.set('');
      this.initControls.getEditor().undo.reset();
      this.initControls.getEditor().undo.saveStep();
  };
}

The object received by the function will contain the following methods:

  • initialize: Call this method to initialize the Froala Editor
  • destroy: Call this method to destroy the Froala Editor
  • getEditor: Call this method to retrieve the editor that was created. This method will return null if the editor was not yet created

Displaying HTML

To display content created with the froala editor use the froalaView component.

<froala v-model:value="content"></froala>

<froalaView v-model:value="content"></froalaView>

License

The vue-froala-wyswiyg project is under MIT license. However, in order to use Froala WYSIWYG HTML Editor plugin you should purchase a license for it.

Froala Editor has 3 different licenses for commercial use. For details please see License Agreement.

Development environment setup

If you want to contribute to vue-froala-wyswiyg, you will first need to install the required tools to get the project going.

Prerequisites

Install dependencies

$ npm install

Build

$ npm run build

Run Demo

$ npm run dev

vue-froala-wysiwyg's People

Contributors

demianh avatar dheerajaccolite avatar dianaprajescu avatar florinpopescu avatar froala-travis-bot avatar harasunu-narayan avatar kapil2704 avatar nikpok avatar shashikantu7 avatar shreypasari-accolite avatar stefanneculai 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

vue-froala-wysiwyg's Issues

this._$element.froalaEditor is not a function"

I made all from example, but there are 2 errors:
(I use laravel as backend and buid app.js with laravel-mix;
ProjectRepo)
1:

[Vue warn]: Error in mounted hook: "TypeError: this._$element.froalaEditor is not a function"

found in

---> <Froala>
       <EditPost> at resources/assets/js/components/EditPost.vue
         <Root>

2:

TypeError: this._$element.froalaEditor is not a function
    at VueComponent.createEditor (app.js:sourcemap:51491)
    at VueComponent.boundFn [as createEditor] (app.js:sourcemap:786)
    at VueComponent.mounted (app.js:sourcemap:51434)
    at callHook (app.js:sourcemap:3307)
    at Object.insert (app.js:sourcemap:4194)
    at invokeInsertHook (app.js:sourcemap:6147)
    at Vue$3.patch [as __patch__] (app.js:sourcemap:6350)
    at Vue$3.Vue._update (app.js:sourcemap:3066)
    at Vue$3.updateComponent (app.js:sourcemap:3180)
    at Watcher.get (app.js:sourcemap:3523)

My files:
bootstrap.js:

window._ = require('lodash')

try {
  $.ajaxSetup({
    headers: {
      'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
    }
  })

  window.Popper = require('popper.js').default
  require('bootstrap')
} catch (e) { }

window.axios = require('axios')
window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest'

require('froala-editor/js/froala_editor.pkgd.min')

App.js:

import Vue from 'vue'
import VueRouter from 'vue-router'
import Vuex from 'vuex'
import router from './router'
import store from './store'
import VueFroala from 'vue-froala-wysiwyg'

require('./bootstrap')
require('./main')

Vue.component('index', require('./components/IndexView.vue'))
Vue.component('posts-list', require('./components/PostsList.vue'))
Vue.component('post', require('./components/Post.vue'))
Vue.component('editPost', require('./components/EditPost.vue'))
Vue.component('user', require('./components/UserView.vue'))
Vue.component('single-post', require('./components/SinglePostView.vue'))
Vue.component('login', require('./components/LoginView.vue'))
Vue.component('register', require('./components/RegisterView.vue'))
Vue.component('logout', require('./components/Logout.vue'))
Vue.component('header-comp', require('./components/Header.vue'))

Vue.use(Vuex)
Vue.use(VueRouter)
Vue.use(VueFroala)

new Vue({
  router,
  store,
  data () {
    return {
      // ...
    }
  },
  mounted () {
    // ...
  }
}).$mount('#app')

EditPost.vue:

<template>
  <form>
    <div class="form-group">
      <label for="edit">Example textarea</label>
      <froala :tag="'textarea'" :config="config" v-model="model"></froala>
    </div>
    <button type="submit" class="btn btn-primary">Submit</button>
  </form>
</template>

<script>
  export default {
    data() {
      return {
        config: {
          events: {
            'froalaEditor.initialized': function () {
              console.log('initialized')
            }
          }
        },
        model: 'Edit Your Content Here!'
      }
    },
    mounted() {
      // ...
    }
  }
</script>

how to set set size .

hello: i want to init set size , like this:

 <froala :tag="'textarea'" :autosize="{minRows: 10,maxRows: 20}" 
    :config="config"   model="form.description"></froala>

but it do not work .

Crash with code view

I have played with a demo and was thinking to buy a license, but found a weird bug. When quickly make some paragraphs (typing something and pressing enter, probably more than 3 times) or just add a youtube video and once you try to switch into the Code view - it's freezing, and actually sometimes after you even can't just close the current tab with the editor, need to rerun the browser.

Chrome, Firefox, Safari - the same bug

TypeError: Vue.component is not a function

I'm following the example to add froala to a .vue component. It compiled with no errrors, but I get a runtime error:

Error in render function: "TypeError: Vue.component is not a function"

Anyone have ideas of what I may have missed?

TypeError: Ee.FE is null

After typing for a bit, the editor crashes every time, without any error. Then I'm left with the textarea that I used as a tag filled with the html content. When I click inside it, I get "TypeError: Ee.FE is null" in console.

I'm using Laravel and put the main.js content into bootstrap.js. Not sure how to follow step 2 to verify webpack settings. Tried to copy the code into bootstrap.js too, but I'm getting a lot of errors. I assume that's not how to do that?

Thank you!

Multiple instances

Hi! How to pass instance name dynamically like:

<div v-quill="editorOption" instanceName="myEditor"></div>

Thank you!

Can't access to component data from event

Hello,
I need to send params before uploading an image file.
I've tried this but without success...

events: { 'froalaEditor.image.beforeUpload': function (e, editor, images) { editor.opts.imageUploadParams['pageId'] = this.pageData.id }

I guess I'm out of the component scope but I don't know how to figure this out.
Is there another way to get datas from my component ?

Thanks !
B

How to add License Key

What is the best way to pass the license key to the Vue Froala Editor.
I've tried the following:

Note I'm still in development mode in localhost, not sure if adding the license at this stage will work.

Thanks!

$('froala-editor').froalaEditor({
key: 'XXXXXXXXXX'
})

data() {
return {
config: {
events: {
'froalaEditor.initialized': function() {
console.log('initialized')
$('froala-editor').froalaEditor({
key: 'XXXXXXXXXX',
})
},
},
key: 'XXXXXXXXXX',
},
model: 'Edit Your Content Here!',
key: 'XXXXXXXXXX',
}
},

Build Error

I'm using webpack and getting a bunch of these errors:

Module build failed: ModuleBuildError: Module build failed: Error: Couldn't find preset "es2015" relative to directory ...

Anyone have ideas how to fix?

keydown event to detect a special key and insert some foobar

The Editor is initialized. Keydown becomes fired and my event listener is called. Could you please give some examples how to access the Editor and add Content like a hyperlink?

                froalaConfig: {
                    events: {
                        'froalaEditor.initialized': function (initControls) {

                        },
                        'froalaEditor.keydown': function (e, editor, keyupEvent) {

                        },
                    }
                },

change toolbarButtons at run time

I am passing "toolbarButtons" at run time as a prop

<app-wysiwyg :dynamic-config="{toolbarButtons: ['insertImage']}"></app-wysiwyg>

and assign it in mounted() hook

mounted() {
    this.config.toolbarButtons = this.dynamicConfig.toolbarButtons;
}

However, it won't change the buttons. Is there any way to change which buttons to show at run time through props?

I need to configure a different button per instance.

@stefanneculai

Model is not updating accordingly to the input in real time

Whenever I type in froala editor initialized in Vue, it does not update the model in real time.

It updates but after approx. 0.5s - 1s which is not bad, but neither acceptable.

Simple test would be to watch the model in vue devtools when typing, if you keep typing continuously - it won't update untill you stop typing, right after that model will be updated.

Expectations would be to update model in real time, like casual textarea or input.

Here's actual behaviour (treat the upper text as model):
kapture 2017-10-05 at 14 00 14

Event input emitted by froala is also delayed.

How to include Wiris plug-in?

I'm trying to add Wiris to my editor but the buttons are not being added (I've included the buttons through the :config attribute).

I've followed their installation instructions and the tests are all positive. I've added Froala via NPM, compiling it with Laravel Mix (uses webpack).

image.insert() alaways insert at the head

I use a different image response?
$('.selector') .froalaEditor() .on('froalaEditor.image.uploaded', function (e, editor, response) { // Parse response to get image url. var img_url = ... ; editor.image.insert(img_url); });
like this. but image.insert() alaways insert at the head. how do I?
thanks

Modern Typescript and Vue

I see that this codebase has not been updated in quite a while.
Has anyone had luck getting this to work in newer versions of Typescript and Vue?
The "require" approach just isnt working and there is a need here to user actual imports on types.

Anyone made this work ?

Drop event not working

Drop event not working after drop text or image to editor area.

js:

new Vue({
el: '#article_editor',
data: {
froalaOptions: {
language: 'ru',
toolbarInline: true,
charCounterCount: false,
toolbarButtons: ['bold', 'italic', 'underline', 'strikeThrough', 'subscript', 'superscript', '-', 'paragraphFormat', 'align', 'formatOL', 'formatUL', 'indent', 'outdent', '-', 'insertImage', 'insertLink', 'insertFile', 'insertVideo', 'undo', 'redo'],
toolbarVisibleWithoutSelection: true,
events: {
'froalaEditor.drop': function () {
console.log('drop');
return false;
}
}
},
text: 'text example',
}
});

html

<froala v-model="text" :config="froalaOptions"></froala>

But other events (focus, click, etc..) working normally

ReferenceError: $ is not defined at VueComponent.createEditor

i have some trouble when i want to use Froala,
app.js:1732 ReferenceError: $ is not defined
at VueComponent.createEditor (app.js:26430)
at VueComponent.boundFn [as createEditor] (app.js:1374)
at VueComponent.mounted (app.js:26378)
at callHook (app.js:3765)
at Object.insert (app.js:4592)
at invokeInsertHook (app.js:6420)
at Vue$3.patch [as patch] (app.js:6585)
at Vue$3.Vue._update (app.js:3525)
at Vue$3.updateComponent (app.js:3648)
at Watcher.get (app.js:3987)

How to use froala plugins

We tried using the 'code_view' plugin and the javascript is loaded by the browser, but we never see the actual code view button. We've tried various webpack configuration changes and it dawned on me that an example of how to load froala plugins for use with this Vue component would be a perfect addition to the README file.

Thanks.

editor.events.add not working

Hi, i'm checking out froala editor on my local machine to figure out if the editor fits in our needs.

The console.log(editor) is working but the next lines are not working

      // You can listen to any event from documentation.
      // editor.events.add('contentChanged', function (params) {});

Error in Console:

[Vue warn]: Error in mounted hook: "TypeError: editor.events.add is not a function"

found in

---> <Froala>
       <Root>

I guess this is something special within the vuejs froala plugin.

Custom icons?

According to Froala documentation there is a possibility to add custom icons instead of default one. Possibly I've missed it in vue-froala-wysiwyg documentation, but is there is any way to add custom icons or replace existing one?

Call methods

Can you show an example for calling the method in vue component?

is jQuery needed?

Hi!

Is jQuery a dependency needed in the core editor? is it possible to separate core functionality from DOM stuff so we can use the vue.js version and not have jQuery as a dependency?

cheers

Versioning

Hi,

I see the npm package is tagged version 2.0.0 but there in this repository there is no versioning, no releases yet.

Could you fix this so we can follow the versioning and see changes that come with new versions?

Cheers

Editor disappearing

After writing many character editor disappearing.Console output this error.Uncaught TypeError: Cannot read property 'VOID_ELEMENTS' of null. What can i do?

Image delete not working with imageManagerDeleteURL

I need to delete an uploaded image from my server if image is removed from editor. I have the following in the config
imageManagerDeleteURL : myServer + '/delete-upload'
When I remove the image, it is removed from editor, but no request to server is made.

Unknown custom element: <froala>

My project use vue but it is not a SPA, i try to include vue-froala like that:
<script src="/libs/froala_editor-2.7.0/js/vue-froala.js"></script>
and use it:
<froala :tag="'textarea'" :config="config" v-model="newWork.body"></froala>
But console error:
Unknown custom element: <froala> - did you register the component correctly? ...

So i try set this line :
<script type="text/javascript"> Vue.component('froala', VueFroala) </script>
Then get console error:
Uncaught ReferenceError: VueFroala is not defined

I know i can import vue froala if i use .vue file like that:

import VueFroala from 'vue-froala-wysiwyg'
Vue.use(VueFroala)

But if i want to use vue-froala without .vue , how can i make it work ?

Thk~

How can I use it in nuxt.js with Vue?

Hello, I tried to use with nuxt.js and vue and didn't work, how can I make it work?

I get this error

Nuxt.js Error:

TypeError: Cannot set property 'froalaEditor' of undefined
    at Object.<anonymous> (~/froala-editor/js/froala_editor.pkgd.min.js:7:5384)
    at module.exports.d.id (~/froala-editor/js/froala_editor.pkgd.min.js:7:13)
    at Object.module.exports.module.exports (~/froala-editor/js/froala_editor.pkgd.min.js:7:253)
    at __webpack_require__ (webpack:/webpack/bootstrap 05279711d0e113a80524:25:0)
    at Object.module.exports.Object.defineProperty.value (server-bundle.js:2405:101)
    at __webpack_require__ (webpack:/webpack/bootstrap 05279711d0e113a80524:25:0)
    at Object.<anonymous> (.nuxt/index.js:94:0)
    at __webpack_require__ (webpack:/webpack/bootstrap 05279711d0e113a80524:25:0)
    at Object.<anonymous> (server-bundle.js:2068:65)
    at __webpack_require__ (webpack:/webpack/bootstrap 05279711d0e113a80524:25:0)

disabling borders and automatic gray bg

How can i disable those within tables? I can't have them in my emails.
Meaning: gray background in body > table > th and gray border on body > table > td, body > table > th

image

Using froala in modern environment

To sum it up, it is pretty much the same thing as this issue =>
froala/wysiwyg-editor#1668

We don't want to have to define a global jquery variable when we use vue froala. jQuery should be imported / required instead of being used as a global variable.

If this isn't fixed this will be a dealbreaker for us and we'll let go of froala and use tiny / ck instead. We want to be able to chunk / bundle froala (and its dependencies) with webpack. Therefore, webpack.providePlugin is a big no go for us.

Thank you.

Creating a working demo

Hi, I have multiple problem with vue-froala so could you create a working demo with CodeSandBox we could use as test base when reporting issue please.

toggling v-if on froala component create duplicate textarea

I have the following HTML =>

<froala :tag="tag" :config="internalOptions" :value="value" @input="refreshModel" v-if="!readOnly"></froala>

with a button that allows me to toggle readonly on and off.

Each time readOnly === true (froala is removed from the dom) a new textarea is created.

And I end up with something like this
image

As a workaround I can change my HTML to be

<div v-if="!readOnly">
    <froala :tag="tag" :config="internalOptions" :value="value" @input="refreshModel"></froala>
</div>

but it's sad to have to create a div for this purpose.

How insert image with custom url

Hi

I'm using this wonderfull lib, but I need help.
I upload a image to S3, but with event froalaEditor.image.beforeUpload, how can I do to charge the image uploaded in S3?

      'froalaEditor.image.beforeUpload': (e, editor, images) => {
            s3.putObject(params, (err, data) => {
              if (err) {
                console.error('ERROR: ', JSON.stringify(err, null, 2))
              } else {
                // I need show the url image uploaded, but doesn't work
                console.log('Correctamente subido!!', JSON.stringify(data, null, 2))
              }
            })
          // return to false by doesn't upload to froala
            return false
          }

Thanks

emoji not show

with useClasses: false, froala will use inline style, it works perfect except emojis not showing in froalaView nor other doms.

image

the problem is background was setted to just https, not https://cdnjs.cloudflare.com/ajax/libs/emojione/2.0.1/assets/svg/1f600.svg

is it a bug or am i wrong in using?

thanks

Can't use custom buttom in quick insert tool bar

I register a custom buttom:

$.FroalaEditor.RegisterCommand('alert', {
	title: 'Hello',
	focus: false,
	undo: false,
	refreshAfterCallback: false,
	callback: function () {
		alert('Hello!');
	}
});

I add the custom buttom to the quickInsertButtons option:


quickInsertButtons: ['alert']

And then nothing shows up when I click the quick insert buttom.

The quick insert buttom works as expected if I use other buttons:


quickInsertButtons: ['image', 'ul', 'li']

And my custom buttom shows up in the top toolbar:


toolbarButtons: ['alert'],

So, do I need to do something different to use a custom button in the quick insert toolbar?

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.