Commit adffefd702688ba5fa8c5df616b8f3685a0fb778

Authored by 接个吻开一枪
Committed by GitHub
1 parent 1d47d8a4

feat(tinymce): add line height (#58)

* feat:add lineheight

Co-authored-by: fengli <fengli@biaodianyun.com>
src/components/Tinymce/src/Editor.vue
... ... @@ -23,6 +23,7 @@
23 23 import { useScript } from '/@/hooks/web/useScript';
24 24 import { snowUuid } from '/@/utils/uuid';
25 25 import { bindHandlers } from './helper';
  26 + import LineHeight from './lineHeight';
26 27  
27 28 const CDN_URL = 'https://cdn.bootcdn.net/ajax/libs/tinymce/5.5.1';
28 29  
... ... @@ -69,6 +70,8 @@
69 70 advlist_bullet_styles: 'square',
70 71 advlist_number_styles: 'default',
71 72 object_resizing: false,
  73 + fontsize_formats: '10px 11px 12px 14px 16px 18px 20px 24px 36px 48px',
  74 + lineheight_formats: "1 1.5 1.75 2.0 3.0 4.0 5.0",
72 75 ...options,
73 76 setup: (editor: any) => {
74 77 editorRef.value = editor;
... ... @@ -117,6 +120,7 @@
117 120 }
118 121  
119 122 function initEditor() {
  123 + getTinymce().PluginManager.add('lineHeight', LineHeight(getTinymce()));
120 124 getTinymce().init(unref(initOptions));
121 125 }
122 126  
... ...
src/components/Tinymce/src/lineHeight.js 0 → 100644
  1 +const LineHeight = function (e) {
  2 + e.PluginManager.add('lineheight', function (t, n, r) {
  3 + t.on('init', function () {
  4 + t.formatter.register({
  5 + lineheight: {
  6 + inline: 'span',
  7 + styles: {
  8 + 'line-height': '%value',
  9 + },
  10 + },
  11 + });
  12 + });
  13 + t.ui.registry.addMenuButton('lineheight', {
  14 + icon: 'lineheight',
  15 + tooltip: '设置行高',
  16 + fetch: function (callback) {
  17 + var dom = t.dom;
  18 + var blocks = t.selection.getSelectedBlocks();
  19 + var lhv = 0;
  20 + global$1.each(blocks, function (block) {
  21 + if (lhv == 0) {
  22 + lhv = dom.getStyle(block, 'line-height') ? dom.getStyle(block, 'line-height') : 0;
  23 + }
  24 + });
  25 + var items = lineheight_val.split(' ').map(function (item) {
  26 + var text = item;
  27 + var value = item;
  28 + return {
  29 + type: 'togglemenuitem',
  30 + text: text,
  31 + active: lhv == value ? true : false,
  32 + onAction: function () {
  33 + doAct(value);
  34 + },
  35 + };
  36 + });
  37 + callback(items);
  38 + },
  39 + });
  40 + });
  41 + e.PluginManager.requireLangPack('lineheight', 'de');
  42 +};
  43 +
  44 +export default LineHeight;
... ...
src/components/Tinymce/src/toolbar.ts
... ... @@ -2,7 +2,7 @@
2 2 // Detail list see https://www.tinymce.com/docs/advanced/editor-control-identifiers/#toolbarcontrols
3 3  
4 4 const toolbar = [
5   - 'searchreplace bold italic underline strikethrough alignleft aligncenter alignright outdent indent blockquote undo redo removeformat subscript superscript code codesample',
  5 + 'fontsizeselect lineheight searchreplace bold italic underline strikethrough alignleft aligncenter alignright outdent indent blockquote undo redo removeformat subscript superscript code codesample',
6 6 'hr bullist numlist link image charmap preview anchor pagebreak insertdatetime media table emoticons forecolor backcolor fullscreen',
7 7 ];
8 8  
... ...