Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

codex.editor.image

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

codex.editor.image

Image Tool for CodeX.Editor

  • 1.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

Image Tool

Image Block for the CodeX Editor.

Features

  • Uploading file from the device
  • Pasting copied content from the web
  • Pasting images by drag-n-drop
  • Allows to add border, background
  • Allows to stretch image to the container's full-width

Note This Tool requires server-side implementation for file uploading. See backend response format for more details.

Installation

Install via NPM

Get the package

npm i --save-dev codex.editor.image

Include module at your application

const ImageTool = require('codex.editor.image');

Download to your project's source dir

  1. Upload folder dist from repository
  2. Add dist/bundle.js file to your page.

Load from CDN

You can load specific version of package from jsDelivr CDN.

https://cdn.jsdelivr.net/npm/codex.editor.image@1.0.0

Then require this script on page with CodeX Editor through the <script src=""></script> tag.

Usage

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

var editor = CodexEditor({
  ...
  
  tools: {
    ...
    image: {
      class: ImageTool,
      config: {
        url: 'http://localhost:8008/', // Your backend uploader endpoint 
      }
    }
  }
  
  ...
});

Config Params

FieldTypeDescription
urlstringRequired Path for file uploading
fieldstring(default: image) Name of uploaded image field in POST request
typesstring(default: image/*) Mime-types of files that can be accepted with file selection.
captionPlaceholderstring(default: Caption) Placeholder for Caption input

Tool's settings

  1. Add border

  2. Stretch to full-width

  3. Add background

Output data

This Tool returns data with following format

FieldTypeDescription
fileobjectUploaded file data. Any data got from backend uploader. Always contain the url property
captionstringimage's caption
withBorderbooleanadd border to image
withBackgroundbooleanneed to add background
stretchedbooleanstretch image to screen's width
{
    "type" : "image",
    "data" : {
        "file": {
            "url" : "https://www.tesla.com/tesla_theme/assets/img/_vehicle_redesign/roadster_and_semi/roadster/hero.jpg"
        },
        "caption" : "Roadster // tesla.com",
        "withBorder" : false,
        "withBackground" : false,
        "stretched" : true
    }
}

Backend response format

This Tool works by following scheme:

  1. User select file from the device
  2. Tool sends it to your backend
  3. Your backend should save file and return file data with JSON at specified format.
  4. Image tool shows saved image and stores server answer

So, you can implement backend for file saving by your own way. It is a specific and trivial task depending on your environment and stack.

Response of your uploader should cover following format:

{
    "success" : 1,
    "file": {
        "url" : "https://www.tesla.com/tesla_theme/assets/img/_vehicle_redesign/roadster_and_semi/roadster/hero.jpg",
        // ... and any additional fields you want
    }
}

success - uploading status. 1 for successful, 0 for failed

file - uploaded file data. Must contain an url field with full public path to the uploaded image. Also, can contain any additional fields you want to store. For example, width, height, id etc. All additional fields will be saved at the file object of output data.

Keywords

FAQs

Package last updated on 06 Nov 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc