Skip to content

Commit 24a5fe2

Browse files
authored
Merge pull request #1 from codex-editor/initial-version
alpha version
2 parents 0b7b628 + 7d780b6 commit 24a5fe2

File tree

18 files changed

+6542
-1
lines changed

18 files changed

+6542
-1
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
node_modules/*
22
npm-debug.log
33
.idea/
4-
.DS_Store
4+
.DS_Store

README.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
![](https://badgen.net/badge/CodeX%20Editor/v2.0/blue)
2+
3+
# Image Tool
4+
5+
Image Block for the [CodeX Editor](https://ifmo.su/editor).
6+
7+
![](https://capella.pics/63a03d04-3816-45b2-87b2-d85e556f0066.jpg)
8+
9+
## Features
10+
11+
- Uploading file from the device
12+
- Pasting copied content from the web
13+
- Pasting images by drag-n-drop
14+
- Allows to add border, background
15+
- Allows to stretch image to the container's full-width
16+
17+
**Note** This Tool requires server-side implementation for file uploading. See [backend response format](#server-format) for more details.
18+
19+
## Installation
20+
21+
### Install via NPM
22+
23+
Get the package
24+
25+
```shell
26+
npm i --save-dev codex.editor.image
27+
```
28+
29+
Include module at your application
30+
31+
```javascript
32+
const ImageTool = require('codex.editor.image');
33+
```
34+
35+
### Download to your project's source dir
36+
37+
1. Upload folder `dist` from repository
38+
2. Add `dist/bundle.js` file to your page.
39+
40+
### Load from CDN
41+
42+
You can load specific version of package from [jsDelivr CDN](https://www.jsdelivr.com/package/npm/codex.editor.image).
43+
44+
`https://cdn.jsdelivr.net/npm/[email protected]`
45+
46+
Then require this script on page with CodeX Editor through the `<script src=""></script>` tag.
47+
48+
## Usage
49+
50+
Add a new Tool to the `tools` property of the CodeX Editor initial config.
51+
52+
```javascript
53+
var editor = CodexEditor({
54+
...
55+
56+
tools: {
57+
...
58+
image: {
59+
class: ImageTool,
60+
config: {
61+
url: 'http://localhost:8008/', // Your backend uploader endpoint
62+
}
63+
}
64+
}
65+
66+
...
67+
});
68+
```
69+
70+
## Config Params
71+
72+
| Field | Type | Description |
73+
| ----- | -------- | ------------------ |
74+
| url | `string` | **Required** Path for file uploading |
75+
| field | `string` | (default: `image`) Name of uploaded image field in POST request |
76+
| types | `string` | (default: `image/*`) Mime-types of files that can be [accepted with file selection](https://github.com/codex-team/ajax#accept-string).|
77+
| captionPlaceholder | `string` | (default: `Caption`) Placeholder for Caption input |
78+
79+
## Tool's settings
80+
81+
![](https://capella.pics/c74cdeec-3405-48ac-a960-f784188cf9b4.jpg)
82+
83+
1. Add border
84+
85+
2. Stretch to full-width
86+
87+
3. Add background
88+
89+
## Output data
90+
91+
This Tool returns `data` with following format
92+
93+
| Field | Type | Description |
94+
| -------------- | --------- | ------------------------------- |
95+
| file | `object` | Uploaded file data. Any data got from backend uploader. Always contain the `url` property |
96+
| caption | `string` | image's caption |
97+
| withBorder | `boolean` | add border to image |
98+
| withBackground | `boolean` | need to add background |
99+
| stretched | `boolean` | stretch image to screen's width |
100+
101+
102+
```json
103+
{
104+
"type" : "image",
105+
"data" : {
106+
"file": {
107+
"url" : "https://www.tesla.com/tesla_theme/assets/img/_vehicle_redesign/roadster_and_semi/roadster/hero.jpg"
108+
},
109+
"caption" : "Roadster // tesla.com",
110+
"withBorder" : false,
111+
"withBackground" : false,
112+
"stretched" : true
113+
}
114+
}
115+
```
116+
117+
## Backend response format <a name="server-format"></a>
118+
119+
This Tool works by following scheme:
120+
121+
1. User select file from the device
122+
2. Tool sends it to **your** backend
123+
3. Your backend should save file and return file data with JSON at specified format.
124+
4. Image tool shows saved image and stores server answer
125+
126+
So, you can implement backend for file saving by your own way. It is a specific and trivial task depending on your
127+
environment and stack.
128+
129+
Response of your uploader **should** cover following format:
130+
131+
```json5
132+
{
133+
"success" : 1,
134+
"file": {
135+
"url" : "https://www.tesla.com/tesla_theme/assets/img/_vehicle_redesign/roadster_and_semi/roadster/hero.jpg",
136+
// ... and any additional fields you want
137+
}
138+
}
139+
```
140+
141+
**success** - uploading status. 1 for successful, 0 for failed
142+
143+
**file** - uploaded file data. **Must** contain an `url` field with full public path to the uploaded image.
144+
Also, can contain any additional fields you want to store. For example, width, height, id etc.
145+
All additional fields will be saved at the `file` object of output data.
146+
147+

dist/bundle.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)