adore-quill-image-resize 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.editorconfig +16 -0
- package/.eslintrc +33 -0
- package/CHANGELOG.md +17 -0
- package/LICENSE +20 -0
- package/README.md +185 -0
- package/demo/index.html +22 -0
- package/demo/script.js +60 -0
- package/demo/test.jpg +0 -0
- package/image-resize.min.js +14 -0
- package/package.json +48 -0
- package/src/DefaultOptions.js +59 -0
- package/src/ImageResize.js +269 -0
- package/src/modules/BaseModule.js +41 -0
- package/src/modules/DisplaySize.js +56 -0
- package/src/modules/Resize.js +104 -0
- package/src/modules/Toolbar.js +111 -0
- package/webpack.config.js +33 -0
package/.editorconfig
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# EditorConfig is awesome: http://EditorConfig.org
|
|
2
|
+
|
|
3
|
+
# top-most EditorConfig file
|
|
4
|
+
root = true
|
|
5
|
+
|
|
6
|
+
[*]
|
|
7
|
+
end_of_line = lf
|
|
8
|
+
trim_trailing_whitespace = true
|
|
9
|
+
insert_final_newline = true
|
|
10
|
+
charset = utf-8
|
|
11
|
+
indent_style = tab
|
|
12
|
+
indent_size = 4
|
|
13
|
+
|
|
14
|
+
[*.json,*.eslintrc]
|
|
15
|
+
indent_style = space
|
|
16
|
+
indent_size = 2
|
package/.eslintrc
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"env": {
|
|
3
|
+
"browser": true,
|
|
4
|
+
"node": true,
|
|
5
|
+
"mocha": true,
|
|
6
|
+
"es6": true
|
|
7
|
+
},
|
|
8
|
+
"parser": "babel-eslint",
|
|
9
|
+
"parserOptions": {
|
|
10
|
+
"ecmaVersion": 6,
|
|
11
|
+
"sourceType": "module",
|
|
12
|
+
"ecmaFeatures": {
|
|
13
|
+
"forOf": true,
|
|
14
|
+
"es6": true,
|
|
15
|
+
"experimentalObjectRestSpread": true
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"rules": {
|
|
19
|
+
"comma-dangle": [2, "always-multiline"],
|
|
20
|
+
"default-case": 1,
|
|
21
|
+
"dot-notation": 1,
|
|
22
|
+
"no-cond-assign": 1,
|
|
23
|
+
"no-constant-condition": 2,
|
|
24
|
+
"no-eval": 2,
|
|
25
|
+
"no-extend-native": 2,
|
|
26
|
+
"no-fallthrough": 2,
|
|
27
|
+
"no-lone-blocks": 1,
|
|
28
|
+
"no-loop-func": 1,
|
|
29
|
+
"no-redeclare": 1,
|
|
30
|
+
"no-unused-vars": 1,
|
|
31
|
+
"no-use-before-define": 0
|
|
32
|
+
}
|
|
33
|
+
}
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## v3.0.0 - April 9, 2017
|
|
4
|
+
|
|
5
|
+
- Position drag handles relative to editor, not document
|
|
6
|
+
- Simplify toolbar and use floats
|
|
7
|
+
- Improved styling
|
|
8
|
+
|
|
9
|
+
## v2.0.0 - April 3, 2017
|
|
10
|
+
|
|
11
|
+
- Added toolbar for alignment
|
|
12
|
+
- Modularized
|
|
13
|
+
- Fix resize bug
|
|
14
|
+
|
|
15
|
+
## v1.0.0 - March 25, 2017
|
|
16
|
+
|
|
17
|
+
- Initial version
|
package/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
The MIT License
|
|
2
|
+
Copyright © 2018
|
|
3
|
+
|
|
4
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+
of this software and associated documentation files (the “Software”), to deal
|
|
6
|
+
in the Software without restriction, including without limitation the rights
|
|
7
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+
furnished to do so, subject to the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be included in
|
|
12
|
+
all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+
THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# Quill ImageResize Module
|
|
2
|
+
|
|
3
|
+
A module for Quill rich text editor to allow images to be resized.
|
|
4
|
+
|
|
5
|
+
Also see [quill-image-drop-module](https://github.com/kensnyder/quill-image-drop-module),
|
|
6
|
+
a module that enables copy-paste and drag/drop for Quill.
|
|
7
|
+
|
|
8
|
+
## Demo
|
|
9
|
+
|
|
10
|
+
[Plunker](https://plnkr.co/edit/gq708AOrSBOWSlHcFslG?p=preview)
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
### Webpack/ES6
|
|
15
|
+
|
|
16
|
+
```javascript
|
|
17
|
+
import Quill from 'quill';
|
|
18
|
+
import { ImageResize } from 'quill-image-resize-module';
|
|
19
|
+
|
|
20
|
+
Quill.register('modules/imageResize', ImageResize);
|
|
21
|
+
|
|
22
|
+
const quill = new Quill(editor, {
|
|
23
|
+
// ...
|
|
24
|
+
modules: {
|
|
25
|
+
// ...
|
|
26
|
+
imageResize: {
|
|
27
|
+
// See optional "config" below
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
### Script Tag
|
|
34
|
+
|
|
35
|
+
Copy image-resize.min.js into your web root or include from node_modules
|
|
36
|
+
|
|
37
|
+
```html
|
|
38
|
+
<script src="/node_modules/quill-image-resize-module/image-resize.min.js"></script>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
```javascript
|
|
42
|
+
var quill = new Quill(editor, {
|
|
43
|
+
// ...
|
|
44
|
+
modules: {
|
|
45
|
+
// ...
|
|
46
|
+
ImageResize: {
|
|
47
|
+
// See optional "config" below
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
### Config
|
|
54
|
+
|
|
55
|
+
For the default experience, pass an empty object, like so:
|
|
56
|
+
```javascript
|
|
57
|
+
var quill = new Quill(editor, {
|
|
58
|
+
// ...
|
|
59
|
+
modules: {
|
|
60
|
+
// ...
|
|
61
|
+
ImageResize: {}
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
Functionality is broken down into modules, which can be mixed and matched as you like. For example,
|
|
67
|
+
the default is to include all modules:
|
|
68
|
+
|
|
69
|
+
```javascript
|
|
70
|
+
const quill = new Quill(editor, {
|
|
71
|
+
// ...
|
|
72
|
+
modules: {
|
|
73
|
+
// ...
|
|
74
|
+
ImageResize: {
|
|
75
|
+
modules: [ 'Resize', 'DisplaySize', 'Toolbar' ]
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
Each module is described below.
|
|
82
|
+
|
|
83
|
+
#### `Resize` - Resize the image
|
|
84
|
+
|
|
85
|
+
Adds handles to the image's corners which can be dragged with the mouse to resize the image.
|
|
86
|
+
|
|
87
|
+
The look and feel can be controlled with options:
|
|
88
|
+
|
|
89
|
+
```javascript
|
|
90
|
+
var quill = new Quill(editor, {
|
|
91
|
+
// ...
|
|
92
|
+
modules: {
|
|
93
|
+
// ...
|
|
94
|
+
ImageResize: {
|
|
95
|
+
// ...
|
|
96
|
+
handleStyles: {
|
|
97
|
+
backgroundColor: 'black',
|
|
98
|
+
border: 'none',
|
|
99
|
+
color: white
|
|
100
|
+
// other camelCase styles for size display
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
#### `DisplaySize` - Display pixel size
|
|
108
|
+
|
|
109
|
+
Shows the size of the image in pixels near the bottom right of the image.
|
|
110
|
+
|
|
111
|
+
The look and feel can be controlled with options:
|
|
112
|
+
|
|
113
|
+
```javascript
|
|
114
|
+
var quill = new Quill(editor, {
|
|
115
|
+
// ...
|
|
116
|
+
modules: {
|
|
117
|
+
// ...
|
|
118
|
+
ImageResize: {
|
|
119
|
+
// ...
|
|
120
|
+
displayStyles: {
|
|
121
|
+
backgroundColor: 'black',
|
|
122
|
+
border: 'none',
|
|
123
|
+
color: white
|
|
124
|
+
// other camelCase styles for size display
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
#### `Toolbar` - Image alignment tools
|
|
132
|
+
|
|
133
|
+
Displays a toolbar below the image, where the user can select an alignment for the image.
|
|
134
|
+
|
|
135
|
+
The look and feel can be controlled with options:
|
|
136
|
+
|
|
137
|
+
```javascript
|
|
138
|
+
var quill = new Quill(editor, {
|
|
139
|
+
// ...
|
|
140
|
+
modules: {
|
|
141
|
+
// ...
|
|
142
|
+
ImageResize: {
|
|
143
|
+
// ...
|
|
144
|
+
toolbarStyles: {
|
|
145
|
+
backgroundColor: 'black',
|
|
146
|
+
border: 'none',
|
|
147
|
+
color: white
|
|
148
|
+
// other camelCase styles for size display
|
|
149
|
+
},
|
|
150
|
+
toolbarButtonStyles: {
|
|
151
|
+
// ...
|
|
152
|
+
},
|
|
153
|
+
toolbarButtonSvgStyles: {
|
|
154
|
+
// ...
|
|
155
|
+
},
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
});
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
#### `BaseModule` - Include your own custom module
|
|
162
|
+
|
|
163
|
+
You can write your own module by extending the `BaseModule` class, and then including it in
|
|
164
|
+
the module setup.
|
|
165
|
+
|
|
166
|
+
For example,
|
|
167
|
+
|
|
168
|
+
```javascript
|
|
169
|
+
import { Resize, BaseModule } from 'quill-image-resize-module';
|
|
170
|
+
|
|
171
|
+
class MyModule extends BaseModule {
|
|
172
|
+
// See src/modules/BaseModule.js for documentation on the various lifecycle callbacks
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
var quill = new Quill(editor, {
|
|
176
|
+
// ...
|
|
177
|
+
modules: {
|
|
178
|
+
// ...
|
|
179
|
+
ImageResize: {
|
|
180
|
+
modules: [ MyModule, Resize ],
|
|
181
|
+
// ...
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
```
|
package/demo/index.html
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8">
|
|
5
|
+
<title>Quill Image Resize Module Demo</title>
|
|
6
|
+
<script src="http://cdn.quilljs.com/1.2.2/quill.min.js"></script>
|
|
7
|
+
<link href="http://cdn.quilljs.com/1.2.2/quill.snow.css" rel="stylesheet">
|
|
8
|
+
<script src="../image-resize.min.js"></script>
|
|
9
|
+
</head>¡
|
|
10
|
+
|
|
11
|
+
<body>
|
|
12
|
+
<h1>Quill Image Resize Module Demo</h1>
|
|
13
|
+
<div id="editor" style="max-height:500px;overflow:auto">
|
|
14
|
+
<p><img src="http://p1.music.126.net/dv_qEzbhSkKzufaCenDchA==/109951163434380822.jpg"></p>
|
|
15
|
+
</div>
|
|
16
|
+
<p>Also see <a href="https://github.com/kensnyder/quill-image-drop-module">quill-image-drop-module</a>,
|
|
17
|
+
a module that enables copy-paste and drag/drop for Quill.</p>
|
|
18
|
+
<button onclick="convert()">convert</button>
|
|
19
|
+
<script src="script.js"></script>
|
|
20
|
+
</body>
|
|
21
|
+
|
|
22
|
+
</html>
|
package/demo/script.js
ADDED
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
var quill = new Quill('#editor', {
|
|
2
|
+
theme: 'snow',
|
|
3
|
+
modules: {
|
|
4
|
+
toolbar: [
|
|
5
|
+
['bold', 'italic', 'underline', 'strike',
|
|
6
|
+
{
|
|
7
|
+
'script': 'sub',
|
|
8
|
+
}, {
|
|
9
|
+
'script': 'super',
|
|
10
|
+
},
|
|
11
|
+
{
|
|
12
|
+
'color': [],
|
|
13
|
+
}, {
|
|
14
|
+
'background': [],
|
|
15
|
+
}, 'code',
|
|
16
|
+
],
|
|
17
|
+
[{
|
|
18
|
+
'font': [],
|
|
19
|
+
}, {
|
|
20
|
+
'size': ['small', false, 'large', 'huge'],
|
|
21
|
+
}],
|
|
22
|
+
|
|
23
|
+
['link', 'image', 'video', 'formula'],
|
|
24
|
+
['blockquote', 'code-block', {
|
|
25
|
+
'header': 1,
|
|
26
|
+
},
|
|
27
|
+
{
|
|
28
|
+
'list': 'ordered',
|
|
29
|
+
}, {
|
|
30
|
+
'list': 'bullet',
|
|
31
|
+
},
|
|
32
|
+
],
|
|
33
|
+
[{
|
|
34
|
+
'indent': '-1',
|
|
35
|
+
}, {
|
|
36
|
+
'indent': '+1',
|
|
37
|
+
}, {
|
|
38
|
+
'direction': 'rtl',
|
|
39
|
+
}, {
|
|
40
|
+
'align': [],
|
|
41
|
+
}],
|
|
42
|
+
['clean'],
|
|
43
|
+
],
|
|
44
|
+
imageResize: {},
|
|
45
|
+
},
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
function convert() {
|
|
49
|
+
const delta = quill.getContents();
|
|
50
|
+
console.log(toHtml(delta));
|
|
51
|
+
// return toHtml(delta);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function toHtml(delta){
|
|
55
|
+
const tempCont = document.createElement('div');
|
|
56
|
+
(new Quill(tempCont)).setContents(delta);
|
|
57
|
+
return tempCont.getElementsByClassName('ql-editor')[0].innerHTML;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// console.log(convert());
|
package/demo/test.jpg
ADDED
|
Binary file
|