npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@xccjh/xccjh-ckeditor5-video-file-upload

v7.0.0

Published

ckeditor5 support local video fileUpload,image/video oss direct upload

Downloads

36

Readme

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/[email protected]/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>