0.1.37 • Published 4 years ago

media-quill v0.1.37

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

Media Quill

Rich text editor based on Quill。
The pictures in the copied HTML content, pasteboard pictures, custom picture upload, pictures can be freely controlled in size. You can upload and insert videos by yourself. Since it is an extension of quill, all methods of quill are applicable

Support

Built in vanilla JS, typescript support, so it can be used on React, Vue, Angular as well

Demo

Test Demo

https://www.domilin.com/submit

API

Provide two apis

1: videoInit

Used to reedit text and rich text display

// display side
videoInit({ width: "600px", height: "400px" });
// editor side
mediaQuill.videoInit({ width: "600px", height: "400px" });

width: video component width
height: Video component height

2: mediaUploading

Check for pictures and videos uploaded when submitting rich text

mediaQuill.mediaUploading();

Installation

npm install --save media-quill

VideoPlayer

The video player can be used alone

import { videoInit, videoPlayerCreate, videoPlayer } from "./MediaQuill/blots/VideoPlayBlots/videoPlayer";

// video player example
videoPlayerCreate({
  videoWrapper: document.getElementById("videoPlayerTestWrapper") as HTMLDivElement,
  src: "https://test-hx24-media.huoxing24.com/video/news/2020/06/30/20200630204904878346.mp4",
  id: "videoPlayerTest"
});
videoPlayer({
  id: "videoPlayerTest",
  width: "400px"
});

// html
<div id="videoPlayerTestWrapper"></div>

//css
@import "media-quill/es/videoPlayer.scss";

Example

Since it contains the video player, it contains both ends: editor side, display side

The editor side instance code use Typescript
The display side instance code use Javascript

But they can all use JS or TS

EditorSide

import React, { useState, useEffect } from "react";
import { useDispatch } from "react-redux";
import MediaQuill from "media-quill";
import { RootDispatch } from "../../models/store";

import "./index.scss";

const toolbarOptions = [
  [{ header: [1, 2, 3, false] }],
  ["bold", "italic", "underline", "strike"], // toggled buttons
  ["blockquote"],
  [{ align: [] }],
  [{ list: "ordered" }, { list: "bullet" }],
  ["link", "image", "video"],
  ["clean"], // remove formatting button
];

export default (): JSX.Element => {
  const dispatch: RootDispatch = useDispatch();
  // 设置编辑器
  const [editor, setEditor] = useState<null | MediaQuill>(null);
  useEffect(() => {
    if (editor) return;
    const options = {
      modules: {
        toolbar: {
          container: toolbarOptions,
        },
        imageResize: {},
        clipboard: {
          imageUpload: async (url: string): Promise<string | undefined> => {
            const res = await dispatch.common.urlImgUpload([
              {
                signTime: new Date().getTime(),
                imgSrc: url || "",
              },
            ]);
            if (res?.code === 1 && res?.obj[0]?.imgSrc) {
              return res.obj[0].imgSrc;
            }
          },
          paste: function (event: MouseEvent) {
            console.log(event);
          },
        },
        mediaUploader: {
          imageUpload: async (file: File): Promise<string | undefined> => {
            const res = await dispatch.common.fileImgUpload({
              type: "news",
              uploadFile: file,
            });

            if (res?.code === 1) {
              return res.obj;
            }
          },
          videoUpload: async (file: File): Promise<string | undefined> => {
            const videoUrl = await dispatch.common.fileLargeUpload({ file });
            if (videoUrl) return videoUrl;
          },
        },
      },
      placeholder: "请输入文章内容",
      theme: "snow",
    };
    const editorQuill = new MediaQuill("#editorQuill", options);
    setEditor(editorQuill);

    // Initialize the video player
    editorQuill.videoInit();
    // Check if a picture or video is uploading
    console.log(editorQuill.mediaUploading());
  }, [editor, dispatch]);
  return <div id="editorQuill"></div>;
};
@import "../../../node_modules/media-quill/es/index.scss";

DisplaySide

import React, { useEffect, useState } from "react";
import { videoInit } from "media-quill/es/videoPlayer";
export default () => {
  useEffect(() => {
    videoInit({ width: "640px" });
  }, []);
  return (
    <div className="ql-container ql-snow">
      <div
        className="ql-editor"
        dangerouslySetInnerHTML={{ __html: htmlString }}
      />
    </div>
  );
};
@import "../../../node_modules/media-quill/es/index.scss";

.ql-editor {
    padding: 0;
}

.ql-container.ql-snow {
    border: none;
}
0.1.37

4 years ago

0.1.36

4 years ago

0.1.35

4 years ago

0.1.34

4 years ago

0.1.32

4 years ago

0.1.33

4 years ago

0.1.30

4 years ago

0.1.31

4 years ago

0.1.29

4 years ago

0.1.28

4 years ago

0.1.27

4 years ago

0.1.26

4 years ago

0.1.22

4 years ago

0.1.24

4 years ago

0.1.25

4 years ago

0.1.21

4 years ago

0.1.18

4 years ago

0.1.19

4 years ago

0.1.16

4 years ago

0.1.17

4 years ago

0.1.15

4 years ago

0.1.14

4 years ago

0.1.11

4 years ago

0.1.12

4 years ago

0.1.10

4 years ago

0.1.8

4 years ago

0.1.7

4 years ago

0.1.9

4 years ago

0.1.4

4 years ago

0.1.6

4 years ago

0.1.5

4 years ago

0.1.3

4 years ago

0.1.2

4 years ago

0.1.1

4 years ago

0.1.0

4 years ago