1 Star 0 Fork 2

王飞/ckeditor5-xccjh

forked from 邹先生/ckeditor5-xccjh 
加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

CKEditor 5 editor Extend

extend support video fileUpload 扩展CKEditor5支持本地视频文件上传功能,图片/视频oss直传,兼容vue,angular,react

dev package environment

server side

开启本地测试环境'

开启本地测试环境

build package

npm run build

Package Usage

config

以下不同框架环境config采用以下配置,全开经典,支持自由配置

const CONFIG= 
{
videoUpload: (file) => {
 return new Promise((resolve, reject) => {
   const formData = new FormData();
   formData.append("file", file);
   // aj函数见下面声明
   const test = aj("http://127.0.0.1:8080/upload", "POST", "json", formData);
   test.subscribe((res) => {
           resolve({url: "http://127.0.0.1:8080/" + res.url});
       }, error => {
           reject(res)
       }
   )});
},
imageUpload: (file) => {
  return new Promise((resolve, reject) => {
    const formData = new FormData();
    formData.append("file", file);
    const test = aj("http://127.0.0.1:8080/upload", "POST", "json", formData);
    test.subscribe((res) => {
            resolve({url: "http://127.0.0.1:8080/" + res.url});
        }, error => {
            reject(res)
        }
    )
});
},
mediaEmbed: {
  extraProviders: [
      {
          name: 'zdy',
          url: [
              /(.*?)/,
          ],
          html: match => {
              const src = match.input;
              return (
'<div style="position: relative; padding-bottom: 100%; height: 0; padding-bottom: 56.2493%;pointer-events: auto;">' +
'<video controls style="position: absolute; width: 100%; height: 100%; top: 0; left: 0;" src="' + src + '">' +
'</video>'+
'</div>'
              );
          }
      },
  ]
},
heading: {
  options: [
      { model: 'paragraph', title: '正文', class: 'ck-heading_paragraph' },
      {
          model: 'heading1',
          view: 'h1',
          title: '标题1',
          class: 'ck-heading_heading1',
      },
      {
          model: 'heading2',
          view: 'h2',
          title: '标题2',
          class: 'ck-heading_heading2',
      },
      {
          model: 'heading3',
          view: 'h3',
          title: '标题3',
          class: 'ck-heading_heading3',
      },
      {
          model: 'heading4',
          view: 'h4',
          title: '标题4',
          class: 'ck-heading_heading4',
      },
  ],
},
toolbar: {
  items: [
      'heading',
      '|',
      'bold',
      'italic',
      'underline',
      'fontBackgroundColor',
      'fontColor',
      'fontSize',
      'fontFamily',
      'link',
      'insertTable',
      'imageUpload',
      'mediaEmbed',
      // 'CKFinder',
      'bulletedList',
      'numberedList',
      'removeFormat',
      '|',
      'alignment',
      'indent',
      'outdent',
      '|',
      'blockQuote',
      'undo',
      'redo',
      'code',
      'codeBlock',
      'highlight',
      'exportPdf',
      'specialCharacters',
      'horizontalLine',
      'MathType',
      'ChemType',
      'strikethrough',
      'subscript',
      'superscript',
      'todoList',
      'restrictedEditingException',
  ]
},
alignment: {
  options: ['left', 'center', 'right', 'justify'],
},
language: 'zh-cn',
image: {
  toolbar: [
      'imageTextAlternative',
      '|',
      'imageStyle:alignLeft',
      'imageStyle:full',
      'imageStyle:alignRight',
  ],
  resizeUnit: 'px',
  types: ['jpeg', 'png', 'gif', 'bmp', 'webp', 'tiff'],
  styles: ['full', 'alignLeft', 'alignRight'],
},
table: {
  contentToolbar: [
      'tableColumn',
      'tableRow',
      'mergeTableCells',
      'tableCellProperties',
      'tableProperties',
  ],
},
tableProperties: {
  // ...
},

tableCellProperties: {
  // ...
},
fontFamily: {
  options: [
      'default',
      'Arial, Helvetica, sans-serif',
      'Courier New, Courier, monospace',
      'Georgia, serif',
      'Lucida Sans Unicode, Lucida Grande, sans-serif',
      'Tahoma, Geneva, sans-serif',
      'Times New Roman, Times, serif',
      'Trebuchet MS, Helvetica, sans-serif',
      'Verdana, Geneva, sans-serif',
  ],
},
licenseKey: '',
}

browser

<div class="editor"></div>
// <script src="https://cdn.staticfile.org/jquery/3.5.1/jquery.js"></script>
// <script src="https://unpkg.com/@reactivex/rxjs@5.0.0-beta.7/dist/global/Rx.umd.js"></script>// 非必须
// <script src='./build/ckeditor.js'></script>
 function aj(url, type = "POST", dataType = "json", data) {
    return Rx.Observable.fromPromise(
            $.ajax({
                url,
                dataType,
                type,
                async: false,
                data,
                processData: false, // 使数据不做处理
                contentType: false, // 不要设置Content-Type请求头
            }).promise()
    );
}

ClassicEditor.create(document.querySelector('.editor'),CONFIG ).then(editor => {
    window.editor = editor;
}).catch(error => {
});

angular

记得安装angular设配器

步骤一装包

npm install --save @ckeditor/ckeditor5-angular @xccjh/xccjh-ckeditor5-video-file-upload

步骤二导包

import { CKEditorModule } from '@ckeditor/ckeditor5-angular';
// 在你用编辑器的模块import
@NgModule( {
    imports: [
        CKEditorModule,
        // ...
    ],
    // ...
} )

步骤三用包

  <ckeditor [editor]="Editor" [(ngModel)]="defineYourselfFrom" placeholder="请输入文章内容"
                        [config]="config" [id]='"editor"' formControlName='defineYourself' ></ckeditor>
import {
  Component,
  OnInit,
  ViewChildren,
  AfterViewInit,
  QueryList,
  Renderer2,
  ElementRef,
  AfterViewChecked,
} from '@angular/core';
import { ActivatedRoute, Params } from '@angular/router';
import { Observable, Observer } from 'rxjs';
import {
  FormBuilder,
  FormControl,
  FormArray,
  FormGroup,
  Validators,
} from '@angular/forms';
import { NzMessageService } from 'ng-zorro-antd/message';
import { UploadOssService } from 'core/services/upload-oss.service';
import { environment } from '../../../../../../../environments-common/environment';
import { UploadDir } from '../../../../../../../core/utils/uploadDir';
==========================================================================
const ClassicEditor = import('@xccjh/xccjh-ckeditor5-video-file-upload');// 这里
==========================================================================

@Component({
  selector: 'app-article-add',
  templateUrl: './article-add.component.html',
  styleUrls: ['./article-add.component.less'],
  providers: [UploadOssService, OfficalManageService],
})
export class Test implements OnInit{
  public Editor = ClassicEditor;
  public defineYourself = ""
  public defineYourselfFrom!: FormGroup;
  ========================================================================== // 重点
  public config = CONFIG;
  ==========================================================================
     ngOnInit(): void {
            this.defineYourselfFrom = this.fb.group({
              defineYourself: ['', [Validators.required]],
            });
     }

react

记得安装react设配器

步骤一装包

npm install --save @ckeditor/ckeditor5-react @xccjh/xccjh-ckeditor5-video-file-upload

步骤二导包用包

// 这里使用axios+promise方式不用jq+rxjs
CONFIG.imageUpload=CONFIG.videoUpload=(file) => {
 return new Promise((resolve, reject) => {
   const formData = new FormData()
   formData.append('file', file)
   const test = this.uploadFile(formData)
   test.then((res) => {
     resolve({ url: 'http://127.0.0.1:8080/' + res.data.url })
   }
   ).catch((e) => {
     console.log('e', e)
   })
 })
},

import React, { Component } from 'react';
import './App.css';
import CKEditor from '@ckeditor/ckeditor5-react';
import ClassicEditor from '@xccjh/xccjh-ckeditor5-video-file-upload';
import axios from 'axios'
class App extends Component {
    uploadFile (formData) {
        const config = {
            headers: {
                'Content-Type': 'mutipart/form-data;charset=UTF-8'
            }
        }
        return axios.post('http://127.0.0.1:8081/upload', formData, config)
    }
    config = CONFIG,
    render () {
        return (
            <div className="App" >
                <CKEditor
                    editor={ClassicEditor}
                    data="<p>Hello from CKEditor 5!</p>"
                    onInit={
                        editor => {
                            console.log('Editor is ready to use!', editor);
                        }}
                    onChange={(event, editor) => {
                        const data = editor.getData();
                        console.log({ event, editor, data });
                    }}
                    onBlur={(event, editor) => {
                        console.log('Blur.', editor);
                    }}
                    onFocus={(event, editor) => {
                        console.log('Focus.', editor);
                    }}
                    config={
                        this.config
                    }
                />
            </div>
        );
    }
}
export default App;

vue

记得安装vue设配器

步骤一装包

npm install --save @ckeditor/ckeditor5-vue @xccjh/xccjh-ckeditor5-video-file-upload

步骤二导包

import Vue from 'vue'
import CKEditor from '@ckeditor/ckeditor5-vue'
// 再main.js导入import
Vue.use(CKEditor)

步骤三用包

<tempalte>
  <ckeditor [editor]="Editor" [(ngModel)]="defineYourselfFrom" placeholder="请输入文章内容"
                        [config]="config" [id]='"editor"' formControlName='defineYourself' ></ckeditor>
</tempalte>
<script >
import ClassicEditor from '@xccjh/xccjh-ckeditor5-video-file-upload'
import axios from 'axios'
// 这里使用axios+promise方式不用jq+rxjs
CONFIG.imageUpload=CONFIG.videoUpload=(file) => {
 return new Promise((resolve, reject) => {
   const formData = new FormData()
   formData.append('file', file)
   const test = this.uploadFile(formData)
   test.then((res) => {
     resolve({ url: 'http://127.0.0.1:8080/' + res.data.url })
   }
   ).catch((e) => {
     console.log('e', e)
   })
 })
}

export default {
  name: 'test',
  methods: {
    uploadFile (formData) {
      const config = {
        headers: {
          'Content-Type': 'mutipart/form-data;charset=UTF-8'
        }
      }
      return axios.post('127.0.0.1:8080/upload', formData, config)
    }
  },
  data () {
    return {
      editor: ClassicEditor,
      editorData: '<p>Content of the editor.</p>',
      editorConfig: CONFIG
    }
  }
}
</script>
Software License Agreement ========================== Copyright (c) 2014-2020, CKSource - Frederico Knabben. All rights reserved. Online builder code samples are licensed under the terms of the MIT License (see Appendix A): http://en.wikipedia.org/wiki/MIT_License CKEditor 5 collaboration features are only available under a commercial license. [Contact us](https://ckeditor.com/contact/) for more details. Free 30-days trials of CKEditor 5 collaboration features are available: * https://ckeditor.com/collaboration/ - Real-time collaboration (with all features). * https://ckeditor.com/collaboration/comments/ - Inline comments feature (without real-time collaborative editing). * https://ckeditor.com/collaboration/track-changes/ - Track changes feature (without real-time collaborative editing). Trademarks ---------- CKEditor is a trademark of CKSource - Frederico Knabben. All other brand and product names are trademarks, registered trademarks or service marks of their respective holders. --- Appendix A: The MIT License --------------------------- The MIT License (MIT) Copyright (c) 2014-{YEAR}, CKSource - Frederico Knabben Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

扩展ckeditor5增加oss视频文件自定义上传npm包源码 包:https://www.npmjs.com/package/@xccjh/xccjh-ckeditor5-video-file-up 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/aiqinggo/ckeditor5-xccjh.git
git@gitee.com:aiqinggo/ckeditor5-xccjh.git
aiqinggo
ckeditor5-xccjh
ckeditor5-xccjh
master

搜索帮助