@7polo/editorjs-image 中文文档教程

发布于 3年前 浏览 19 更新于 3年前

Image

Editor.js 2.0 的图像工具

Feature

  • Embed Url ✌️
  • Unsplash ✌️
  • upload ✌️
  • extend
  • image viewer ✌️ (use by viewerjs)

tab

embed url

upsplash

upload

extend

只需添加您想要


viewer

的任何选项卡 只需双击图像


Usage

添加一个新工具到 Editor.js 初始配置的 tools 属性。

  1. npm
npm i @7polo/editorjs-image
  1. init & config
var editor = EditorJS({
  ...
  tools: {
    ...
    image: {
        class: Image,
        config: {
            unsplash: {
                search: ()=> {
                    return new Promise(function(resolve){
                        // resp from api : https://api.unsplash.com/search/photos 
                        resolve({});
                    })
                }
            },
            upload: {
                doUplaod: ()=> {
                    return new Promise(function(resolve){
                        resolve({url});
                    })
                }
            }
        }
    }
  }
  ...
});

Config Params

FieldTypeDescription
unsplash.searchfunctionresponse from unsplash https://api.unsplash.com/search/photos

unsplash.search like this

export const searchImages = (query) => {
    console.log("search" + query)

    return axios.get(`https://api.unsplash.com/search/photos`, {
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Credentials': false,
            'Content-Type':'application/x-www-form-urlencoded'
        },
        params: {
            client_id: 'your client_id',
            query
        }
    })
}

Output data

此工具返回代码。

{
  "type" : "image",
  "data" : {
    "url" : "https://www.example.com/image.jpg",
    "withBorder" : false,
    "withBackground" : false,
    "stretched" : true
  }
}

Image

Image Tool for Editor.js 2.0

Feature

  • Embed Url ✌️
  • Unsplash ✌️
  • upload ✌️
  • extend
  • image viewer ✌️ (use by viewerjs)

tab

embed url

upsplash

upload

extend

just add any tab you wanted


viewer

just double click the image


Usage

Add a new Tool to the tools property of the Editor.js initial config.

  1. npm
npm i @7polo/editorjs-image
  1. init & config
var editor = EditorJS({
  ...
  tools: {
    ...
    image: {
        class: Image,
        config: {
            unsplash: {
                search: ()=> {
                    return new Promise(function(resolve){
                        // resp from api : https://api.unsplash.com/search/photos 
                        resolve({});
                    })
                }
            },
            upload: {
                doUplaod: ()=> {
                    return new Promise(function(resolve){
                        resolve({url});
                    })
                }
            }
        }
    }
  }
  ...
});

Config Params

FieldTypeDescription
unsplash.searchfunctionresponse from unsplash https://api.unsplash.com/search/photos

unsplash.search like this

export const searchImages = (query) => {
    console.log("search" + query)

    return axios.get(`https://api.unsplash.com/search/photos`, {
        headers: {
            'Access-Control-Allow-Origin': '*',
            'Access-Control-Allow-Credentials': false,
            'Content-Type':'application/x-www-form-urlencoded'
        },
        params: {
            client_id: 'your client_id',
            query
        }
    })
}

Output data

This Tool returns code.

{
  "type" : "image",
  "data" : {
    "url" : "https://www.example.com/image.jpg",
    "withBorder" : false,
    "withBackground" : false,
    "stretched" : true
  }
}
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文