vue中 使用Tinymce 的一键布局插件

这篇具有很好参考价值的文章主要介绍了vue中 使用Tinymce 的一键布局插件。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

一、 Tinymce

                首先需要配置好 Tinymce 相关的组件已经配置操作 。

                可以参考 官网:将 TinyMCE 包与 Vue.js 框架一起使用|TinyMCE 文档。

二、一键布局插件实现 

        Tinymce 是提供了一系列的插件的,但是默认是没有一键布局的插件,需要引入其他的来进行实现 。

tinymce is not defined,tinymce is not defined ,vue.js,前端,javascript

        本次使用 Tinymce-Plugin 中提供了 一键布局的方式。 

2.1  Tinymce-Plugin 的介绍 

        Tinymce-Plugin 的官方文档

        这个官网文档里面讲解的是 js 的使用方式,如果使用在vue 中会出现 tinymce is not defined 的问题,需要用手动的方式进行解决。

2.2 组件的使用 

1.安装 Tinymce-Plugin 

npm i tinymce-plugin 或 npm i @npkg/tinymce-plugin 

      注意安装只是为了获取插件的源码,不要进行任何的import导入操作,否则会报错!!!

2.需要找到 layout 插件 源码 

tinymce is not defined,tinymce is not defined ,vue.js,前端,javascript

        通过源码可以得知 这个插件也是使用默认 tinymce 自定义添加插件的方式,如果直接import导入的方式则会出现 tinymce is not defined 问题。


 /**
 * layout 1.6v  2021-03-30
 * The tinymce-plugins is used to set up a layout
 *
 * https://github.com/Five-great/tinymce-plugins
 *
 * Copyright 2021, Five(Li Hailong) The Chengdu, China https://fivecc.cn/
 *
 * Licensed under MIT
 */
tinymce.PluginManager.add('layout', function(editor, url) {
    var pluginName='一键布局';
    var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
    var layout_opt = editor.getParam('layout_options', {selection: 'p,table,tr,td,h1,h2,h3,h4,h5,h6,ul,blockquote' ,learStyle:[],filterTags:['table>*'],style:{'text-align':'justify','text-indent':'2em','line-height': 1.5},tagsStyle:{}});
    var layout_filterTags={};
    var layout_filterTagsRegex={};
    for( let key in layout_opt.filterTags){layout_opt.filterTags[key].indexOf('>*')!=-1?layout_filterTagsRegex[layout_opt.filterTags[key].replace('>*','').toUpperCase()]=true :layout_filterTags[layout_opt.filterTags[key].toUpperCase()]=true;}
    for( let key in layout_opt.tagsStyle){
        let ckeyList = key.split(',');
        layout_opt.selection += ','+key;
        for(let ckey in ckeyList)ckeyList[ckey].indexOf('>*')!=-1?layout_filterTagsRegex[ckeyList[ckey].replace('>*','').toUpperCase()]=key :layout_filterTags[ckeyList[ckey].toUpperCase()]=key;
    }
    var doAct = function () {
        var dom = editor.dom;
        editor.execCommand('selectAll');
        layout_opt.selection = layout_opt.selection || 'p,table,tr,td,h1,h2,h3,h4,h5,h6,ul,blockquote';
        for( let key in layout_opt.tagsStyle) {layout_opt.selection += ','+key;}
        blocks= editor.selection.getNode().querySelectorAll(layout_opt.selection)
        function _indent2$getValue( key, str ) {
            var m = str.match( new RegExp(key + ':?(.+?)"?[;}]') );
            return m ? m[ 1 ] : false;
        }
        function filterFun(el,_r) {
            let parentSelector = 'BODY';
            let parents = el.tagName;
            if(layout_filterTags[parents] || layout_filterTagsRegex[parents]) {

                !layout_opt.tagsStyle[layout_filterTags[parents]] || _r ?_r ? removeStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]]) :'': setStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]])
                return true;
            }
            let _p = el.parentNode;
            let _pName = _p.tagName
            while (_pName !== parentSelector) {
                let o = _p;
                parents = _pName + '>' + parents;
                if(layout_filterTags[parents] || layout_filterTagsRegex[_pName]) {
                    !layout_opt.tagsStyle[layout_filterTagsRegex[_pName]] || _r ? _r ? removeStyleFun(el,layout_opt.tagsStyle[layout_filterTagsRegex[_pName]]) :'' : setStyleFun(el,layout_opt.tagsStyle[layout_filterTagsRegex[_pName]])
                    !layout_opt.tagsStyle[layout_filterTags[parents]] || _r ? _r ? removeStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]]) :'': setStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]])
                    return true;
                }
                _p = o.parentNode;
                _pName = _p.tagName;
            }
            return false;
        }
        function clearStyleFun(_block){
            let style=dom.getAttrib(_block,'style');
            for(let key in layout_opt.clearStyle){
                let reg = new RegExp(layout_opt.clearStyle[key] + ':?(.+?)"?[;}]')
                    style = style.replace(reg, '');
                }
                dom.setAttrib(_block,'style',style);
        }
        function removeStyleFun(_block,_style){
            let style=dom.getAttrib(_block,'style');
            for(let key in _style){
            let reg = new RegExp(key + ':?(.+?)"?[;}]')
            style = style.replace(reg, '');
            }
            dom.setAttrib(_block,'style',style);
        }
        function setStyleFun(_block,_style){
            for(let key in _style){
               dom.setStyle(_block, key, _style[key]);
            }
            if(_style["text-indent"]){
            let kv = "",kl = "";
            if(_block&&_block.children['0']&&_block.children['0'].attributes&&_block.children['0'].attributes.style){
                kv = _indent2$getValue('font-size',_block.children['0'].attributes.style.textContent);
                kl = _indent2$getValue('letter-spacing',_block.children['0'].attributes.style.textContent);
                if(kv) {kv=(parseInt(kv)+parseInt((kl?kl:0)))*2+'px';}
                else kv=(parseInt((kl?kl:0))+16)*2+'px';
            }
            dom.setStyle(_block, 'text-indent', layout_opt.style['text-indent']&&layout_opt.style['text-indent']!='2em'?layout_opt.style['text-indent']: kv?kv:'2em');
           }
        }
        var layoutAct = '';
        global$1.each(blocks, function (block) {

                if(layoutAct==''){if(dom.hasClass(block,'layoutFV')){layoutAct =  'remove'; dom.removeClass(block,'layoutFV')}else{ layoutAct =  'add'; dom.addClass(block,'layoutFV')}}
                if( layoutAct =='add'){
                    !filterFun(block)?setStyleFun(block,layout_opt.style):'';
                    layout_opt.clearStyle?clearStyleFun(block):'';
                }else{
                    !filterFun(block,'remove')?removeStyleFun(block,layout_opt.style):'';
                }
        });
    };
    editor.ui.registry.getAll().icons.layout || editor.ui.registry.addIcon('layout','<svg t="1603868236215" class="icon" viewBox="0 0 1035 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="17720" width="20" height="20"><path d="M357.445818 285.358545L1005.730909 518.830545c21.76 8.192 32.628364 31.394909 24.471273 51.87491a40.634182 40.634182 0 0 1-21.748364 23.214545l-245.992727 110.592a80.034909 80.034909 0 0 0-42.135273 42.321455l-104.657454 249.856c-8.145455 20.48-32.616727 30.045091-53.003637 21.85309-10.868364-4.096-19.025455-13.661091-23.098182-24.576L305.792 337.221818a40.075636 40.075636 0 0 1 24.471273-51.874909c8.145455-4.096 17.664-4.096 27.182545 0z m8.145455-255.32509v99.67709c0 16.384-13.579636 30.033455-29.893818 30.033455-16.302545 0-29.905455-13.649455-29.905455-30.033455V30.021818C305.803636 13.649455 319.406545 0 335.709091 0c16.314182 0 29.905455 13.649455 29.905454 30.033455zM29.905455 303.104h99.211636c16.302545 0 29.905455 13.649455 29.905454 30.033455s-13.602909 30.045091-29.905454 30.04509H29.905455C13.591273 363.170909 0 349.521455 0 333.137455s13.591273-30.033455 29.905455-30.033455zM645.573818 66.897455l-144.058182 144.73309c-12.241455 12.288-29.905455 12.288-42.135272 0-12.229818-12.288-12.229818-30.045091 0-42.33309l144.058181-144.721455c12.229818-12.288 29.905455-12.288 42.135273 0 10.868364 10.926545 10.868364 30.033455 0 42.321455zM67.944727 20.48L212.014545 165.201455c12.241455 12.288 12.241455 30.045091 0 42.33309-12.218182 12.288-29.905455 12.288-42.123636 0L25.832727 62.801455c-12.241455-12.288-12.241455-30.033455 0-42.321455 10.868364-12.288 29.893818-12.288 42.123637 0z m149.515637 480.593455L73.402182 645.818182c-12.241455 12.288-29.905455 12.288-42.146909 0-12.218182-12.288-12.218182-30.045091 0-42.333091l144.058182-144.721455c12.241455-12.288 29.905455-12.288 42.146909 0 12.218182 12.288 12.218182 30.033455 0 42.321455z" style="width:20px; height:20px" p-id="17721"></path></svg>');
    editor.ui.registry.addToggleButton('layout', {
        icon: 'layout',
        tooltip: pluginName,
        onAction: function () {
            editor.undoManager.transact(function(){
                editor.focus();
                doAct();
             })
        }
    });
    editor.ui.registry.addMenuItem('layout', {
        text: pluginName,
        onAction: function() {
            editor.undoManager.transact(function(){
               editor.focus();
               doAct();
            })
        }
    });
    return {
        getMetadata: function () {
            return  {
                name: pluginName,
                url: "https://github.com/Five-great/tinymce-plugins",
            };
        }
    };
});

3.解决 tinymce is not defined 问题 

        通过测试得知 如果直接通过官网提供的 import "tinymce-plugin/plugins/tpLayout"; 方式会出现 tinymce is not defined 问题 。需要手动操作。

        通过 tinymce 的官网得知 tinymce 的生命周期 setup是组件初始化的生命周期回调,可以在这个方法里调用 tinymce 的添加插件的方法 文章来源地址https://www.toymoban.com/news/detail-730611.html

    // 初始化方法
      setup: function (editor) {

        console.log(editor);
        console.log("--------------------------");
        console.log(tinymce);
        // 添加自定义一键布局
        tinymce.PluginManager.add('layout', function(editor, url) {
          var pluginName='一键布局';
          console.log(pluginName);
          var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
          var layout_opt = editor.getParam('layout_options', {selection: 'p,table,tr,td,h1,h2,h3,h4,h5,h6,ul,blockquote' ,learStyle:[],filterTags:['table>*'],style:{'text-align':'justify','text-indent':'2em','line-height': 1.5},tagsStyle:{}});
          var layout_filterTags={};
          var layout_filterTagsRegex={};
          for( let key in layout_opt.filterTags){layout_opt.filterTags[key].indexOf('>*')!=-1?layout_filterTagsRegex[layout_opt.filterTags[key].replace('>*','').toUpperCase()]=true :layout_filterTags[layout_opt.filterTags[key].toUpperCase()]=true;}
          for( let key in layout_opt.tagsStyle){
              let ckeyList = key.split(',');
              layout_opt.selection += ','+key;
              for(let ckey in ckeyList)ckeyList[ckey].indexOf('>*')!=-1?layout_filterTagsRegex[ckeyList[ckey].replace('>*','').toUpperCase()]=key :layout_filterTags[ckeyList[ckey].toUpperCase()]=key;
          }
          var doAct = function () {
              var dom = editor.dom;
              editor.execCommand('selectAll');
              layout_opt.selection = layout_opt.selection || 'p,table,tr,td,h1,h2,h3,h4,h5,h6,ul,blockquote';
              for( let key in layout_opt.tagsStyle) {layout_opt.selection += ','+key;}
              console.log(editor);
              let blocks= editor.selection.getNode().querySelectorAll(layout_opt.selection)
              console.log(blocks);
              function _indent2$getValue( key, str ) {
                  var m = str.match( new RegExp(key + ':?(.+?)"?[;}]') );
                  return m ? m[ 1 ] : false;
              }
              function filterFun(el,_r) {
                  let parentSelector = 'BODY';
                  let parents = el.tagName;
                  if(layout_filterTags[parents] || layout_filterTagsRegex[parents]) {

                      !layout_opt.tagsStyle[layout_filterTags[parents]] || _r ?_r ? removeStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]]) :'': setStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]])
                      return true;
                  }
                  let _p = el.parentNode;
                  let _pName = _p.tagName
                  while (_pName !== parentSelector) {
                      let o = _p;
                      parents = _pName + '>' + parents;
                      if(layout_filterTags[parents] || layout_filterTagsRegex[_pName]) {
                          !layout_opt.tagsStyle[layout_filterTagsRegex[_pName]] || _r ? _r ? removeStyleFun(el,layout_opt.tagsStyle[layout_filterTagsRegex[_pName]]) :'' : setStyleFun(el,layout_opt.tagsStyle[layout_filterTagsRegex[_pName]])
                          !layout_opt.tagsStyle[layout_filterTags[parents]] || _r ? _r ? removeStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]]) :'': setStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]])
                          return true;
                      }
                      _p = o.parentNode;
                      _pName = _p.tagName;
                  }
                  return false;
              }
              function clearStyleFun(_block){
                  let style=dom.getAttrib(_block,'style');
                  for(let key in layout_opt.clearStyle){
                      let reg = new RegExp(layout_opt.clearStyle[key] + ':?(.+?)"?[;}]')
                          style = style.replace(reg, '');
                      }
                      dom.setAttrib(_block,'style',style);
              }
              function removeStyleFun(_block,_style){
                  let style=dom.getAttrib(_block,'style');
                  for(let key in _style){
                  let reg = new RegExp(key + ':?(.+?)"?[;}]')
                  style = style.replace(reg, '');
                  }
                  dom.setAttrib(_block,'style',style);
              }
              function setStyleFun(_block,_style){
                  for(let key in _style){
                    dom.setStyle(_block, key, _style[key]);
                  }
                  if(_style["text-indent"]){
                  let kv = "",kl = "";
                  if(_block&&_block.children['0']&&_block.children['0'].attributes&&_block.children['0'].attributes.style){
                      kv = _indent2$getValue('font-size',_block.children['0'].attributes.style.textContent);
                      kl = _indent2$getValue('letter-spacing',_block.children['0'].attributes.style.textContent);
                      if(kv) {kv=(parseInt(kv)+parseInt((kl?kl:0)))*2+'px';}
                      else kv=(parseInt((kl?kl:0))+16)*2+'px';
                  }
                  dom.setStyle(_block, 'text-indent', layout_opt.style['text-indent']&&layout_opt.style['text-indent']!='2em'?layout_opt.style['text-indent']: kv?kv:'2em');
                }
              }
              var layoutAct = '';
              global$1.each(blocks, function (block) {

                      if(layoutAct==''){if(dom.hasClass(block,'layoutFV')){layoutAct =  'remove'; dom.removeClass(block,'layoutFV')}else{ layoutAct =  'add'; dom.addClass(block,'layoutFV')}}
                      if( layoutAct =='add'){
                          !filterFun(block)?setStyleFun(block,layout_opt.style):'';
                          layout_opt.clearStyle?clearStyleFun(block):'';
                      }else{
                          !filterFun(block,'remove')?removeStyleFun(block,layout_opt.style):'';
                      }
              });
          };
          editor.ui.registry.getAll().icons.layout || editor.ui.registry.addIcon('layout','<svg t="1603868236215" class="icon" viewBox="0 0 1035 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="17720" width="20" height="20"><path d="M357.445818 285.358545L1005.730909 518.830545c21.76 8.192 32.628364 31.394909 24.471273 51.87491a40.634182 40.634182 0 0 1-21.748364 23.214545l-245.992727 110.592a80.034909 80.034909 0 0 0-42.135273 42.321455l-104.657454 249.856c-8.145455 20.48-32.616727 30.045091-53.003637 21.85309-10.868364-4.096-19.025455-13.661091-23.098182-24.576L305.792 337.221818a40.075636 40.075636 0 0 1 24.471273-51.874909c8.145455-4.096 17.664-4.096 27.182545 0z m8.145455-255.32509v99.67709c0 16.384-13.579636 30.033455-29.893818 30.033455-16.302545 0-29.905455-13.649455-29.905455-30.033455V30.021818C305.803636 13.649455 319.406545 0 335.709091 0c16.314182 0 29.905455 13.649455 29.905454 30.033455zM29.905455 303.104h99.211636c16.302545 0 29.905455 13.649455 29.905454 30.033455s-13.602909 30.045091-29.905454 30.04509H29.905455C13.591273 363.170909 0 349.521455 0 333.137455s13.591273-30.033455 29.905455-30.033455zM645.573818 66.897455l-144.058182 144.73309c-12.241455 12.288-29.905455 12.288-42.135272 0-12.229818-12.288-12.229818-30.045091 0-42.33309l144.058181-144.721455c12.229818-12.288 29.905455-12.288 42.135273 0 10.868364 10.926545 10.868364 30.033455 0 42.321455zM67.944727 20.48L212.014545 165.201455c12.241455 12.288 12.241455 30.045091 0 42.33309-12.218182 12.288-29.905455 12.288-42.123636 0L25.832727 62.801455c-12.241455-12.288-12.241455-30.033455 0-42.321455 10.868364-12.288 29.893818-12.288 42.123637 0z m149.515637 480.593455L73.402182 645.818182c-12.241455 12.288-29.905455 12.288-42.146909 0-12.218182-12.288-12.218182-30.045091 0-42.333091l144.058182-144.721455c12.241455-12.288 29.905455-12.288 42.146909 0 12.218182 12.288 12.218182 30.033455 0 42.321455z" style="width:20px; height:20px" p-id="17721"></path></svg>');
          editor.ui.registry.addToggleButton('layout', {
              icon: 'layout',
              tooltip: pluginName,
              onAction: function () {
                  editor.undoManager.transact(function(){
                      editor.focus();
                      doAct();
                  })
              }
          });
          editor.ui.registry.addMenuItem('layout', {
              text: pluginName,
              onAction: function() {
                  editor.undoManager.transact(function(){
                    editor.focus();
                    doAct();
                  })
              }
          });
          return {
              getMetadata: function () {
                  return  {
                      name: pluginName,
                      url: "https://github.com/Five-great/tinymce-plugins",
                  };
              }
          };
      });

      },

     4.完整的一键布局配置 

<template> 
 <editor
    :id="id"
    v-model="content"
    :init="initConfig"
    :api-key="apiKey"
  />
</template>


<script>
export default {
    
   data () {
    return {
        initConfig: {

        // selector: '#tinydemo',
         plugins:'layout',
        toolbar:'layout',
        tp_layout_options: {
                style: {
                   'text-align':'justify',
                   'text-indent':'2em',
                   'line-height': 1.5
                },
                filterTags:['table>*','tbody'], //'table,'tbody','td','tr' 将会忽略掉 同时 table>*,忽略table 标签 以及所有子标签
                clearStyle: ['text-indent'],//text-indent 将会被清除掉
                tagsStyle: {
                   'table': {
                       'line-height': 3,
                       'text-align': 'center'
                   },
                  'table,tbody,tr,td': { //支持并集选择
                    'line-height': 2
                   },
                   'tr>td,table>tbody': { //支持, 精准定位 通过 ' > '
                    'line-height': 3,
                    'text-align': 'center'
                   }
               }
      },
      // 初始化方法
      setup: function (editor) {

        console.log(editor);
        console.log("--------------------------");
        console.log(tinymce);
        // 添加自定义一键布局
        tinymce.PluginManager.add('layout', function(editor, url) {
          var pluginName='一键布局';
          console.log(pluginName);
          var global$1 = tinymce.util.Tools.resolve('tinymce.util.Tools');
          var layout_opt = editor.getParam('layout_options', {selection: 'p,table,tr,td,h1,h2,h3,h4,h5,h6,ul,blockquote' ,learStyle:[],filterTags:['table>*'],style:{'text-align':'justify','text-indent':'2em','line-height': 1.5},tagsStyle:{}});
          var layout_filterTags={};
          var layout_filterTagsRegex={};
          for( let key in layout_opt.filterTags){layout_opt.filterTags[key].indexOf('>*')!=-1?layout_filterTagsRegex[layout_opt.filterTags[key].replace('>*','').toUpperCase()]=true :layout_filterTags[layout_opt.filterTags[key].toUpperCase()]=true;}
          for( let key in layout_opt.tagsStyle){
              let ckeyList = key.split(',');
              layout_opt.selection += ','+key;
              for(let ckey in ckeyList)ckeyList[ckey].indexOf('>*')!=-1?layout_filterTagsRegex[ckeyList[ckey].replace('>*','').toUpperCase()]=key :layout_filterTags[ckeyList[ckey].toUpperCase()]=key;
          }
          var doAct = function () {
              var dom = editor.dom;
              editor.execCommand('selectAll');
              layout_opt.selection = layout_opt.selection || 'p,table,tr,td,h1,h2,h3,h4,h5,h6,ul,blockquote';
              for( let key in layout_opt.tagsStyle) {layout_opt.selection += ','+key;}
              console.log(editor);
              let blocks= editor.selection.getNode().querySelectorAll(layout_opt.selection)
              console.log(blocks);
              function _indent2$getValue( key, str ) {
                  var m = str.match( new RegExp(key + ':?(.+?)"?[;}]') );
                  return m ? m[ 1 ] : false;
              }
              function filterFun(el,_r) {
                  let parentSelector = 'BODY';
                  let parents = el.tagName;
                  if(layout_filterTags[parents] || layout_filterTagsRegex[parents]) {

                      !layout_opt.tagsStyle[layout_filterTags[parents]] || _r ?_r ? removeStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]]) :'': setStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]])
                      return true;
                  }
                  let _p = el.parentNode;
                  let _pName = _p.tagName
                  while (_pName !== parentSelector) {
                      let o = _p;
                      parents = _pName + '>' + parents;
                      if(layout_filterTags[parents] || layout_filterTagsRegex[_pName]) {
                          !layout_opt.tagsStyle[layout_filterTagsRegex[_pName]] || _r ? _r ? removeStyleFun(el,layout_opt.tagsStyle[layout_filterTagsRegex[_pName]]) :'' : setStyleFun(el,layout_opt.tagsStyle[layout_filterTagsRegex[_pName]])
                          !layout_opt.tagsStyle[layout_filterTags[parents]] || _r ? _r ? removeStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]]) :'': setStyleFun(el,layout_opt.tagsStyle[layout_filterTags[parents]])
                          return true;
                      }
                      _p = o.parentNode;
                      _pName = _p.tagName;
                  }
                  return false;
              }
              function clearStyleFun(_block){
                  let style=dom.getAttrib(_block,'style');
                  for(let key in layout_opt.clearStyle){
                      let reg = new RegExp(layout_opt.clearStyle[key] + ':?(.+?)"?[;}]')
                          style = style.replace(reg, '');
                      }
                      dom.setAttrib(_block,'style',style);
              }
              function removeStyleFun(_block,_style){
                  let style=dom.getAttrib(_block,'style');
                  for(let key in _style){
                  let reg = new RegExp(key + ':?(.+?)"?[;}]')
                  style = style.replace(reg, '');
                  }
                  dom.setAttrib(_block,'style',style);
              }
              function setStyleFun(_block,_style){
                  for(let key in _style){
                    dom.setStyle(_block, key, _style[key]);
                  }
                  if(_style["text-indent"]){
                  let kv = "",kl = "";
                  if(_block&&_block.children['0']&&_block.children['0'].attributes&&_block.children['0'].attributes.style){
                      kv = _indent2$getValue('font-size',_block.children['0'].attributes.style.textContent);
                      kl = _indent2$getValue('letter-spacing',_block.children['0'].attributes.style.textContent);
                      if(kv) {kv=(parseInt(kv)+parseInt((kl?kl:0)))*2+'px';}
                      else kv=(parseInt((kl?kl:0))+16)*2+'px';
                  }
                  dom.setStyle(_block, 'text-indent', layout_opt.style['text-indent']&&layout_opt.style['text-indent']!='2em'?layout_opt.style['text-indent']: kv?kv:'2em');
                }
              }
              var layoutAct = '';
              global$1.each(blocks, function (block) {

                      if(layoutAct==''){if(dom.hasClass(block,'layoutFV')){layoutAct =  'remove'; dom.removeClass(block,'layoutFV')}else{ layoutAct =  'add'; dom.addClass(block,'layoutFV')}}
                      if( layoutAct =='add'){
                          !filterFun(block)?setStyleFun(block,layout_opt.style):'';
                          layout_opt.clearStyle?clearStyleFun(block):'';
                      }else{
                          !filterFun(block,'remove')?removeStyleFun(block,layout_opt.style):'';
                      }
              });
          };
          editor.ui.registry.getAll().icons.layout || editor.ui.registry.addIcon('layout','<svg t="1603868236215" class="icon" viewBox="0 0 1035 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="17720" width="20" height="20"><path d="M357.445818 285.358545L1005.730909 518.830545c21.76 8.192 32.628364 31.394909 24.471273 51.87491a40.634182 40.634182 0 0 1-21.748364 23.214545l-245.992727 110.592a80.034909 80.034909 0 0 0-42.135273 42.321455l-104.657454 249.856c-8.145455 20.48-32.616727 30.045091-53.003637 21.85309-10.868364-4.096-19.025455-13.661091-23.098182-24.576L305.792 337.221818a40.075636 40.075636 0 0 1 24.471273-51.874909c8.145455-4.096 17.664-4.096 27.182545 0z m8.145455-255.32509v99.67709c0 16.384-13.579636 30.033455-29.893818 30.033455-16.302545 0-29.905455-13.649455-29.905455-30.033455V30.021818C305.803636 13.649455 319.406545 0 335.709091 0c16.314182 0 29.905455 13.649455 29.905454 30.033455zM29.905455 303.104h99.211636c16.302545 0 29.905455 13.649455 29.905454 30.033455s-13.602909 30.045091-29.905454 30.04509H29.905455C13.591273 363.170909 0 349.521455 0 333.137455s13.591273-30.033455 29.905455-30.033455zM645.573818 66.897455l-144.058182 144.73309c-12.241455 12.288-29.905455 12.288-42.135272 0-12.229818-12.288-12.229818-30.045091 0-42.33309l144.058181-144.721455c12.229818-12.288 29.905455-12.288 42.135273 0 10.868364 10.926545 10.868364 30.033455 0 42.321455zM67.944727 20.48L212.014545 165.201455c12.241455 12.288 12.241455 30.045091 0 42.33309-12.218182 12.288-29.905455 12.288-42.123636 0L25.832727 62.801455c-12.241455-12.288-12.241455-30.033455 0-42.321455 10.868364-12.288 29.893818-12.288 42.123637 0z m149.515637 480.593455L73.402182 645.818182c-12.241455 12.288-29.905455 12.288-42.146909 0-12.218182-12.288-12.218182-30.045091 0-42.333091l144.058182-144.721455c12.241455-12.288 29.905455-12.288 42.146909 0 12.218182 12.288 12.218182 30.033455 0 42.321455z" style="width:20px; height:20px" p-id="17721"></path></svg>');
          editor.ui.registry.addToggleButton('layout', {
              icon: 'layout',
              tooltip: pluginName,
              onAction: function () {
                  editor.undoManager.transact(function(){
                      editor.focus();
                      doAct();
                  })
              }
          });
          editor.ui.registry.addMenuItem('layout', {
              text: pluginName,
              onAction: function() {
                  editor.undoManager.transact(function(){
                    editor.focus();
                    doAct();
                  })
              }
          });
          return {
              getMetadata: function () {
                  return  {
                      name: pluginName,
                      url: "https://github.com/Five-great/tinymce-plugins",
                  };
              }
          };
      });

      },
}
}
}
</script>

到了这里,关于vue中 使用Tinymce 的一键布局插件的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • vue中使用Base64转码(Tinymce富文本保留HTML标签)

    在vue项目中,我们经常使用到富文本编辑器,例如博主的项目(见上图),这里需要把富文本内的HTML结构,发放到Android端做混合应用的开发,因此HTML结构必不可少的! 但是浏览器在向服务器发送数据时,有可能出现不识别前端发送的特殊字符,或者直接丢弃特殊字符,此时

    2024年02月15日
    浏览(31)
  • tinymce4/5实现将word中内容(文字图片等)直接粘贴至编辑器中——利用插件tinymce-powerpaste-plugin

    TinyMCE是一款易用、且功能强大的所见即所得的富文本编辑器。同类程序有:UEditor、Kindeditor、Simditor、CKEditor、wangEditor、Suneditor、froala等等。 TinyMCE的优势: 开源可商用,基于LGPL2.1 插件丰富,自带插件基本涵盖日常所需功能(示例看下面的Demo-2) 接口丰富,可扩展性强,有

    2024年02月15日
    浏览(33)
  • vue2使用 tinymce富文本编辑器-图片上传、粘贴图片上传致服务器

    1.安装tinymce富文本编辑器插件 npm i tinymce npm i @tinymce/tinymce-vue 2.创建Editor.js文件 封装组件 以便使用 3.汉化包 (我放在public/tynymce/langs文件夹里) 4.vue组件中使用 本次记录重点在于 上传图片方法 需要区分工具栏中图片上传方法 以及 粘贴进去的图片也需要走上传方法。两个方

    2024年02月09日
    浏览(41)
  • vue3 使用require报错:require is not defined

    1.报错原因 vue3使用vite打包 里面没有require方法, webpack 里面有这个方法 2.解决方案 使用import 代替 *注: 资源可使用import.meta.globEager(“…/*.png”) ; 动态引入,需要给 css 路径加括号 vite官网静态资源处理 new URL(url, import.meta.url) import.meta.url : ESM 的原生功能,会暴露当前模块的

    2024年02月07日
    浏览(36)
  • Vue使用ffmpeg,报ReferenceError: SharedArrayBuffer is not defined 如何解决

    “SharedArrayBuffer is not defined” 错误是因为在浏览器环境中,SharedArrayBuffer 对象被认为是一种潜在的安全风险。为了防止 Spectre 攻击等漏洞,现代浏览器通常会禁用或限制对 SharedArrayBuffer 的使用。 SharedArrayBuffer 是一种 JavaScript 对象,用于在多线程环境中共享内存。然而,由于

    2024年02月11日
    浏览(48)
  • vue3使用process报错Uncaught ReferenceError: process is not defined

    之前使用 vue-cli创建项目 时,使用 process.env.变量名 获取环境变量(在根目录下配置环境配置文件之后)。 今天使用 vite+vue3 创建项目时,使用相同的方法却获取不到,还报以下错误,这是为什么呢? 后来查看了VITE官网才知道,使用vite+vue的时候环境变量的获取方式变成如下

    2024年02月11日
    浏览(37)
  • vue中使用amqplib 会报出Uncaught ReferenceError: Buffer is not defined错误

    这个错误是由于Vue项目中缺少Buffer对象导致的。amqplib库在运行时需要使用Buffer对象来处理二进制数据,而在Vue项目中,Buffer对象可能没有被正确引入。 解决方法有两种: 在main.js文件中引入Buffer对象,如: 2.在webpack.config.js文件中加入以下配置: 这样就能在vue中使用amqplib了

    2024年02月17日
    浏览(38)
  • ReferenceError: require is not defined 【vue3 +vite +setup语法使用报错】

    原本我们在vue2时代,可以使用require 导入静态资源,如下所示 但在vue3中的vite没有require方法定义的使用,说白了就是不使用require方法进行资源的导入,而是使用新的方法。详情请看官网。 Vite官网 我这里提供两种方法: 方法1: 使用 import导入资源 方法2: 直接使用 new URL(

    2024年02月13日
    浏览(32)
  • vue 集成tinymce2实现图片,视频以及文件的上传

    1. 安装插件 (1)安装tinymce npm install tinymce -S (2)安装tinymce-vue npm install @tinymce/tinymce-vue@3.0.1 -S 2. 复制静态文件到 public 目录 资源下载路径:https://download.csdn.net/download/weixin_44021888/88063970?spm=1001.2014.3001.5503 3. 新建组件:tinymce 注意:如果上传过后的视频,只有一张图片的占位

    2024年02月16日
    浏览(32)
  • Vue 富文本编辑器tinymce的安装教程(前端必备小知识)

    目录 一、Tinymce编辑器简介 二、安装以及配置tinymce         2.1.安装tinymce编辑器         2.2.从node_modules/tinymce复制样式到public目录下,复制完毕的public下的目录结构如下 三、在Vue里面使用         3.1.在components 目录下新建 Editor.vue 将下面代码复制进去        

    2024年02月11日
    浏览(41)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包