|
|
@@ -1706,8 +1706,9 @@ Vue.component('spaceEditor', {
|
|
|
view: { key: 'style', value: { 'text-indent': '2em' } }
|
|
|
});
|
|
|
},
|
|
|
- getSelectedTextBlocks: function (editor) {
|
|
|
+ getSelectedTextBlocks: function (editor, attributeName) {
|
|
|
var blocks = [];
|
|
|
+ var attribute = attributeName || 'textIndent';
|
|
|
var selection = editor.model.document.selection;
|
|
|
if (!selection.isCollapsed && typeof selection.getSelectedBlocks === 'function') {
|
|
|
blocks = Array.prototype.slice.call(selection.getSelectedBlocks());
|
|
|
@@ -1722,7 +1723,7 @@ Vue.component('spaceEditor', {
|
|
|
}
|
|
|
|
|
|
return blocks.filter(function (block) {
|
|
|
- return block && editor.model.schema.checkAttribute(block.name, 'textIndent');
|
|
|
+ return block && editor.model.schema.checkAttribute(block.name, attribute);
|
|
|
});
|
|
|
},
|
|
|
toggleFirstLineIndent: function (editor) {
|
|
|
@@ -1835,6 +1836,152 @@ Vue.component('spaceEditor', {
|
|
|
});
|
|
|
this.refreshFirstLineIndentButton(editor);
|
|
|
},
|
|
|
+ installLineHeightPlugin: function (editor) {
|
|
|
+ if (!editor.model.schema.checkAttribute('$block', 'lineHeight')) {
|
|
|
+ editor.model.schema.extend('$block', { allowAttributes: ['lineHeight'] });
|
|
|
+ }
|
|
|
+ editor.model.schema.setAttributeProperties('lineHeight', { isFormatting: true });
|
|
|
+
|
|
|
+ editor.conversion.for('downcast').attributeToAttribute({
|
|
|
+ model: 'lineHeight',
|
|
|
+ view: function (modelAttributeValue) {
|
|
|
+ return {
|
|
|
+ key: 'style',
|
|
|
+ value: { 'line-height': modelAttributeValue }
|
|
|
+ };
|
|
|
+ }
|
|
|
+ });
|
|
|
+ editor.conversion.for('upcast').attributeToAttribute({
|
|
|
+ view: {
|
|
|
+ styles: { 'line-height': /[\s\S]+/ }
|
|
|
+ },
|
|
|
+ model: {
|
|
|
+ key: 'lineHeight',
|
|
|
+ value: function (viewElement) {
|
|
|
+ return viewElement.getStyle('line-height');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ },
|
|
|
+ applyLineHeight: function (editor, value) {
|
|
|
+ var blocks = this.getSelectedTextBlocks(editor, 'lineHeight');
|
|
|
+ if (!blocks.length) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ editor.model.change(function (writer) {
|
|
|
+ blocks.forEach(function (block) {
|
|
|
+ if (value) {
|
|
|
+ writer.setAttribute('lineHeight', value, block);
|
|
|
+ } else {
|
|
|
+ writer.removeAttribute('lineHeight', block);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ });
|
|
|
+ editor.editing.view.focus();
|
|
|
+ },
|
|
|
+ refreshLineHeightControl: function (editor) {
|
|
|
+ if (!editor || !editor.ui || !editor.ui.view || !editor.ui.view.element) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var control = editor.ui.view.element.querySelector('[data-space-line-height="true"]');
|
|
|
+ if (!control) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var blocks = this.getSelectedTextBlocks(editor, 'lineHeight');
|
|
|
+ var current = '';
|
|
|
+ if (blocks.length) {
|
|
|
+ current = blocks[0].getAttribute('lineHeight') || '';
|
|
|
+ for (var i = 1; i < blocks.length; i++) {
|
|
|
+ if ((blocks[i].getAttribute('lineHeight') || '') !== current) {
|
|
|
+ current = '';
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ control.value = current;
|
|
|
+ },
|
|
|
+ mountLineHeightToolbar: function (editor) {
|
|
|
+ if (!editor || !editor.ui || !editor.ui.view || !editor.ui.view.element) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var toolbarItems = editor.ui.view.element.querySelector('.ck-toolbar__items');
|
|
|
+ if (!toolbarItems || toolbarItems.querySelector('[data-space-line-height="true"]')) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ var _this = this;
|
|
|
+ var wrapper = document.createElement('label');
|
|
|
+ wrapper.className = 'space-editor-line-height';
|
|
|
+ wrapper.setAttribute('title', '行距');
|
|
|
+
|
|
|
+ var label = document.createElement('span');
|
|
|
+ label.className = 'space-editor-line-height-label';
|
|
|
+ label.textContent = '行距';
|
|
|
+
|
|
|
+ var select = document.createElement('select');
|
|
|
+ select.className = 'space-editor-line-height-select';
|
|
|
+ select.setAttribute('aria-label', '行距');
|
|
|
+ select.setAttribute('data-space-line-height', 'true');
|
|
|
+ [
|
|
|
+ ['', '默认'],
|
|
|
+ ['1', '1.0 倍'],
|
|
|
+ ['1.25', '1.25 倍'],
|
|
|
+ ['1.5', '1.5 倍'],
|
|
|
+ ['1.75', '1.75 倍'],
|
|
|
+ ['1.8', '1.8 倍'],
|
|
|
+ ['2', '2.0 倍'],
|
|
|
+ ['2.5', '2.5 倍'],
|
|
|
+ ['3', '3.0 倍']
|
|
|
+ ].forEach(function (item) {
|
|
|
+ var option = document.createElement('option');
|
|
|
+ option.value = item[0];
|
|
|
+ option.textContent = item[1];
|
|
|
+ select.appendChild(option);
|
|
|
+ });
|
|
|
+
|
|
|
+ wrapper.appendChild(label);
|
|
|
+ wrapper.appendChild(select);
|
|
|
+ wrapper.addEventListener('mousedown', function (event) {
|
|
|
+ event.stopPropagation();
|
|
|
+ });
|
|
|
+ wrapper.addEventListener('click', function (event) {
|
|
|
+ event.stopPropagation();
|
|
|
+ });
|
|
|
+ select.addEventListener('change', function (event) {
|
|
|
+ event.stopPropagation();
|
|
|
+ _this.applyLineHeight(editor, select.value);
|
|
|
+ });
|
|
|
+
|
|
|
+ var fontSizeDropdown = null;
|
|
|
+ var dropdowns = toolbarItems.querySelectorAll('.ck-dropdown');
|
|
|
+ for (var i = 0; i < dropdowns.length; i++) {
|
|
|
+ var button = dropdowns[i].querySelector('.ck-button');
|
|
|
+ var buttonLabel = button ? (button.getAttribute('aria-label') || button.getAttribute('title') || button.textContent || '') : '';
|
|
|
+ buttonLabel = buttonLabel.replace(/\s/g, '').toLowerCase();
|
|
|
+ if (buttonLabel.indexOf('字体大小') !== -1 || buttonLabel.indexOf('字号') !== -1 || buttonLabel.indexOf('fontsize') !== -1) {
|
|
|
+ fontSizeDropdown = dropdowns[i];
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (fontSizeDropdown && fontSizeDropdown.parentNode === toolbarItems) {
|
|
|
+ toolbarItems.insertBefore(wrapper, fontSizeDropdown.nextSibling);
|
|
|
+ } else {
|
|
|
+ toolbarItems.appendChild(wrapper);
|
|
|
+ }
|
|
|
+
|
|
|
+ editor.model.document.selection.on('change', function () {
|
|
|
+ _this.refreshLineHeightControl(editor);
|
|
|
+ });
|
|
|
+ editor.model.document.on('change:data', function () {
|
|
|
+ _this.refreshLineHeightControl(editor);
|
|
|
+ });
|
|
|
+ this.refreshLineHeightControl(editor);
|
|
|
+ },
|
|
|
alignFullScreenToolbarButton: function () {
|
|
|
if (!this.editor || !this.editor.ui || !this.editor.ui.view || !this.editor.ui.view.element) {
|
|
|
return;
|
|
|
@@ -3330,6 +3477,7 @@ Vue.component('spaceEditor', {
|
|
|
extraPlugins: [function (editor) {
|
|
|
_this.installUploadAdapter(editor);
|
|
|
_this.installFirstLineIndentPlugin(editor);
|
|
|
+ _this.installLineHeightPlugin(editor);
|
|
|
_this.installVideoViewerPlugin(editor);
|
|
|
_this.installPdfViewerPlugin(editor);
|
|
|
}], // 添加上传适配器
|
|
|
@@ -3342,6 +3490,7 @@ Vue.component('spaceEditor', {
|
|
|
'default',
|
|
|
{ title: '宋体', model: 'SimSun, serif', view: { name: 'span', styles: { 'font-family': "'SimSun', serif" }, priority: 7 } },
|
|
|
{ title: '仿宋', model: 'FangSong, serif', view: { name: 'span', styles: { 'font-family': "'FangSong', serif" }, priority: 7 } },
|
|
|
+ { title: '仿宋_GB2312', model: "'仿宋_GB2312', 'FangSong_GB2312', FangSong, serif", view: { name: 'span', styles: { 'font-family': "'仿宋_GB2312', 'FangSong_GB2312', FangSong, serif" }, priority: 7 } },
|
|
|
{ title: '楷体', model: 'KaiTi, serif', view: { name: 'span', styles: { 'font-family': "'KaiTi', serif" }, priority: 7 } },
|
|
|
{ title: '黑体', model: 'SimHei, sans-serif', view: { name: 'span', styles: { 'font-family': "'SimHei', sans-serif" }, priority: 7 } },
|
|
|
{ title: '微软雅黑', model: 'Microsoft YaHei, sans-serif', view: { name: 'span', styles: { 'font-family': "'Microsoft YaHei', sans-serif" }, priority: 7 } },
|
|
|
@@ -3354,7 +3503,7 @@ Vue.component('spaceEditor', {
|
|
|
},
|
|
|
fontSize: {
|
|
|
supportAllValues: true,
|
|
|
- options: ['default', '10.5pt', '12pt', '14pt', '16pt', '18pt', '22pt', '26pt', '36pt']
|
|
|
+ options: ['default', '10.5pt', '12pt', '14pt', '16pt', '18pt', '20pt', '22pt', '26pt', '36pt']
|
|
|
},
|
|
|
mediaEmbed: {
|
|
|
previewsInData: true,
|
|
|
@@ -3403,6 +3552,7 @@ Vue.component('spaceEditor', {
|
|
|
_this.editor = editor;
|
|
|
_this.alignFullScreenToolbarButton();
|
|
|
_this.mountFirstLineIndentToolbarButton(editor);
|
|
|
+ _this.mountLineHeightToolbar(editor);
|
|
|
_this.configureWordUploadPlugin(editor);
|
|
|
if (_this.type !== 'flow') {
|
|
|
_this.mountVideoUploadToolbarButton();
|