quill-resize-module 2.0.4 → 2.0.5
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/README.md +5 -0
- package/demo/demo.jpg +0 -0
- package/demo/index.html +9 -2
- package/demo/index.js +14 -0
- package/package.json +2 -2
- package/src/assets/resize.scss +4 -0
- package/src/modules/Resize.js +0 -2
- package/src/modules/Toolbar.js +70 -25
package/README.md
CHANGED
|
@@ -108,6 +108,11 @@ const quill = new Quill(editor, {
|
|
|
108
108
|
'left', 'right',
|
|
109
109
|
{
|
|
110
110
|
text: 'Alt',
|
|
111
|
+
// set attributes
|
|
112
|
+
attrs: {
|
|
113
|
+
title: 'Set image alt',
|
|
114
|
+
class: 'btn-alt'
|
|
115
|
+
},
|
|
111
116
|
verify (activeEle) {
|
|
112
117
|
return (activeEle && activeEle.tagName === 'IMG')
|
|
113
118
|
},
|
package/demo/demo.jpg
CHANGED
|
Binary file
|
package/demo/index.html
CHANGED
|
@@ -46,6 +46,10 @@
|
|
|
46
46
|
opacity: .5;
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
+
.ql-resize-toolbar .btn-alt {
|
|
50
|
+
background-color: #ccc;
|
|
51
|
+
}
|
|
52
|
+
|
|
49
53
|
#result {
|
|
50
54
|
width: 100%;
|
|
51
55
|
}
|
|
@@ -57,9 +61,9 @@
|
|
|
57
61
|
<div class="editor-box">
|
|
58
62
|
<div id="editor">
|
|
59
63
|
<p>Click target to resize.</p>
|
|
60
|
-
<p><img src="https://i.ytimg.com/vi/Fp5ghKduTK8/hq720.jpg" width="
|
|
64
|
+
<p><img src="https://i.ytimg.com/vi/Fp5ghKduTK8/hq720.jpg" width="400"> text <img src="https://i.ytimg.com/vi/etdb8-v2enI/hq720.jpg" width="350"></p>
|
|
61
65
|
<p><br></p>
|
|
62
|
-
<iframe width="560" height="315" src="https://www.youtube.com/embed/
|
|
66
|
+
<iframe width="560" height="315" src="https://www.youtube.com/embed/HGl75kurxok?si=xZWI9qVC3oJs0Lll" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" referrerpolicy="strict-origin-when-cross-origin" allowfullscreen></iframe>
|
|
63
67
|
<p><br></p>
|
|
64
68
|
<p>Try to press left/right key around the placeholder.</p>
|
|
65
69
|
</div>
|
|
@@ -69,6 +73,9 @@
|
|
|
69
73
|
<button class="btn btn-content">getContent</button>
|
|
70
74
|
<button class="btn btn-text">getText</button>
|
|
71
75
|
|
|
76
|
+
<button class="btn btn-set-html">setHTML</button>
|
|
77
|
+
<button class="btn btn-set-content">setContent</button>
|
|
78
|
+
|
|
72
79
|
<button class="btn btn-undo">undo</button>
|
|
73
80
|
<button class="btn btn-redo">redo</button>
|
|
74
81
|
</div>
|
package/demo/index.js
CHANGED
|
@@ -26,6 +26,10 @@ const demoEditor = new Quill('#editor', {
|
|
|
26
26
|
'left', 'center', 'right', 'full', 'edit',
|
|
27
27
|
{
|
|
28
28
|
text: 'Alt',
|
|
29
|
+
attrs: {
|
|
30
|
+
title: 'Set image alt',
|
|
31
|
+
class: 'btn-alt'
|
|
32
|
+
},
|
|
29
33
|
verify (activeEle) {
|
|
30
34
|
return (activeEle && activeEle.tagName === 'IMG')
|
|
31
35
|
},
|
|
@@ -53,6 +57,16 @@ document.querySelector('.btn-content').addEventListener('click', function () {
|
|
|
53
57
|
document.querySelector('.btn-text').addEventListener('click', function () {
|
|
54
58
|
$result.value = demoEditor.getText()
|
|
55
59
|
})
|
|
60
|
+
document.querySelector('.btn-set-html').addEventListener('click', function () {
|
|
61
|
+
const contents = demoEditor.clipboard.convert({
|
|
62
|
+
html: `${$result.value}<p><br></p>`,
|
|
63
|
+
text: '\n'
|
|
64
|
+
})
|
|
65
|
+
demoEditor.setContents(contents)
|
|
66
|
+
})
|
|
67
|
+
document.querySelector('.btn-set-content').addEventListener('click', function () {
|
|
68
|
+
demoEditor.setContents(JSON.parse($result.value))
|
|
69
|
+
})
|
|
56
70
|
document.querySelector('.btn-undo').addEventListener('click', function () {
|
|
57
71
|
demoEditor.history.undo()
|
|
58
72
|
})
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "quill-resize-module",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "A module for Quill rich text editor to allow images/iframe/video and custom elements
|
|
3
|
+
"version": "2.0.5",
|
|
4
|
+
"description": "A module for Quill rich text editor to allow images/iframe/video and custom elements to be resized.",
|
|
5
5
|
"main": "dist/resize.js",
|
|
6
6
|
"module": "src/index.js",
|
|
7
7
|
"scripts": {
|
package/src/assets/resize.scss
CHANGED
|
@@ -102,6 +102,7 @@
|
|
|
102
102
|
.ql-resize-style-center {
|
|
103
103
|
display: block;
|
|
104
104
|
margin: auto;
|
|
105
|
+
text-align: center;
|
|
105
106
|
}
|
|
106
107
|
.ql-resize-style-right {
|
|
107
108
|
float: right;
|
|
@@ -109,4 +110,7 @@
|
|
|
109
110
|
}
|
|
110
111
|
.ql-resize-style-full {
|
|
111
112
|
width: 100% !important;
|
|
113
|
+
> * {
|
|
114
|
+
width: 100%;
|
|
115
|
+
}
|
|
112
116
|
}
|
package/src/modules/Resize.js
CHANGED
|
@@ -32,7 +32,6 @@ export default class Resize extends BaseModule {
|
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
handleMousedown (evt) {
|
|
35
|
-
this.blot.handling && this.blot.handling(true)
|
|
36
35
|
// note which box
|
|
37
36
|
this.dragBox = evt.target
|
|
38
37
|
// note starting mousedown position
|
|
@@ -64,7 +63,6 @@ export default class Resize extends BaseModule {
|
|
|
64
63
|
|
|
65
64
|
// reset cursor everywhere
|
|
66
65
|
this.setCursor('')
|
|
67
|
-
this.blot.handling && this.blot.handling(false)
|
|
68
66
|
// stop listening for movement and mouseup
|
|
69
67
|
document.removeEventListener('mousemove', this.handleDragProxy)
|
|
70
68
|
document.removeEventListener('mouseup', this.handleMouseupProxy)
|
package/src/modules/Toolbar.js
CHANGED
|
@@ -11,11 +11,32 @@ const Quill = window.Quill || _Quill
|
|
|
11
11
|
|
|
12
12
|
const Parchment = Quill.import('parchment')
|
|
13
13
|
|
|
14
|
+
const ALIGNMENT_CLASSES = {
|
|
15
|
+
LEFT: 'left',
|
|
16
|
+
RIGHT: 'right',
|
|
17
|
+
CENTER: 'center',
|
|
18
|
+
FULL: 'full'
|
|
19
|
+
}
|
|
20
|
+
|
|
14
21
|
// Quill.js 2.x support
|
|
15
22
|
const ClassAttributor = Parchment.ClassAttributor
|
|
16
23
|
? Parchment.ClassAttributor
|
|
17
24
|
: Parchment.Attributor.Class
|
|
18
|
-
|
|
25
|
+
|
|
26
|
+
const INLINE_FORMAT_ATTRIBUTOR = 'resize-inline'
|
|
27
|
+
const InlineFormatClass = new ClassAttributor(INLINE_FORMAT_ATTRIBUTOR, 'ql-resize-style', {
|
|
28
|
+
scope: Parchment.Scope.INLINE,
|
|
29
|
+
whitelist: Object.values(ALIGNMENT_CLASSES)
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
const BLOCK_FORMAT_ATTRIBUTOR = 'resize-block'
|
|
33
|
+
const BlockFormatClass = new ClassAttributor(BLOCK_FORMAT_ATTRIBUTOR, 'ql-resize-style', {
|
|
34
|
+
scope: Parchment.Scope.BLOCK,
|
|
35
|
+
whitelist: Object.values(ALIGNMENT_CLASSES)
|
|
36
|
+
})
|
|
37
|
+
|
|
38
|
+
Quill.register(InlineFormatClass, true)
|
|
39
|
+
Quill.register(BlockFormatClass, true)
|
|
19
40
|
|
|
20
41
|
export default class Toolbar extends BaseModule {
|
|
21
42
|
static Icons = {
|
|
@@ -28,35 +49,27 @@ export default class Toolbar extends BaseModule {
|
|
|
28
49
|
|
|
29
50
|
static Tools = {
|
|
30
51
|
left: {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
isApplied (activeEle) {
|
|
35
|
-
return ImageFormatClass.value(activeEle) === 'left'
|
|
52
|
+
toolClass: ALIGNMENT_CLASSES.LEFT,
|
|
53
|
+
isApplied (activeEle, blot) {
|
|
54
|
+
return this._getFormatValue(activeEle, blot) === ALIGNMENT_CLASSES.LEFT
|
|
36
55
|
}
|
|
37
56
|
},
|
|
38
57
|
center: {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
isApplied (activeEle) {
|
|
43
|
-
return ImageFormatClass.value(activeEle) === 'center'
|
|
58
|
+
toolClass: ALIGNMENT_CLASSES.CENTER,
|
|
59
|
+
isApplied (activeEle, blot) {
|
|
60
|
+
return this._getFormatValue(activeEle, blot) === ALIGNMENT_CLASSES.CENTER
|
|
44
61
|
}
|
|
45
62
|
},
|
|
46
63
|
right: {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
isApplied (activeEle) {
|
|
51
|
-
return ImageFormatClass.value(activeEle) === 'right'
|
|
64
|
+
toolClass: ALIGNMENT_CLASSES.RIGHT,
|
|
65
|
+
isApplied (activeEle, blot) {
|
|
66
|
+
return this._getFormatValue(activeEle, blot) === ALIGNMENT_CLASSES.RIGHT
|
|
52
67
|
}
|
|
53
68
|
},
|
|
54
69
|
full: {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
isApplied (activeEle) {
|
|
59
|
-
return ImageFormatClass.value(activeEle) === 'full'
|
|
70
|
+
toolClass: ALIGNMENT_CLASSES.FULL,
|
|
71
|
+
isApplied (activeEle, blot) {
|
|
72
|
+
return this._getFormatValue(activeEle, blot) === ALIGNMENT_CLASSES.FULL
|
|
60
73
|
}
|
|
61
74
|
},
|
|
62
75
|
edit: {
|
|
@@ -88,29 +101,61 @@ export default class Toolbar extends BaseModule {
|
|
|
88
101
|
button.type = 'button'
|
|
89
102
|
buttons.push(button)
|
|
90
103
|
button.innerHTML = ((tool.icon || '') + (tool.text || '')) || Icons[t]
|
|
104
|
+
if (typeof t === 'string') button.className = `ql-resize-toolbar-${t}`
|
|
105
|
+
if (tool.attrs) {
|
|
106
|
+
Object.keys(tool.attrs).forEach((key) => {
|
|
107
|
+
button.setAttribute(key, tool.attrs[key])
|
|
108
|
+
})
|
|
109
|
+
}
|
|
91
110
|
button.addEventListener('click', (evt) => {
|
|
92
111
|
if (tool.handler && tool.handler.call(this, evt, button, this.activeEle) !== true) return
|
|
93
112
|
|
|
94
113
|
// deselect all buttons
|
|
95
114
|
buttons.forEach(button => (button.classList.remove('active')))
|
|
96
|
-
if (tool.isApplied && tool.isApplied.call(this, this.activeEle)) {
|
|
115
|
+
if (tool.isApplied && tool.isApplied.call(this, this.activeEle, this.blot)) {
|
|
97
116
|
// If applied, unapply
|
|
98
|
-
|
|
117
|
+
this._applyToolFormatting('')
|
|
99
118
|
} else {
|
|
100
119
|
// otherwise, select button and apply
|
|
101
120
|
button.classList.add('active')
|
|
102
|
-
|
|
121
|
+
|
|
122
|
+
if (tool.toolClass) {
|
|
123
|
+
this._applyToolFormatting(tool.toolClass)
|
|
124
|
+
}
|
|
103
125
|
}
|
|
104
126
|
|
|
105
127
|
// image may change position; redraw drag handles
|
|
106
128
|
this.requestUpdate()
|
|
107
129
|
})
|
|
108
130
|
|
|
109
|
-
if (tool.isApplied && tool.isApplied.call(this, this.activeEle)) {
|
|
131
|
+
if (tool.isApplied && tool.isApplied.call(this, this.activeEle, this.blot)) {
|
|
110
132
|
// select button if previously applied
|
|
111
133
|
button.classList.add('active')
|
|
112
134
|
}
|
|
113
135
|
this.toolbar.appendChild(button)
|
|
114
136
|
})
|
|
115
137
|
}
|
|
138
|
+
|
|
139
|
+
_getFormatValue (activeEle, blot) {
|
|
140
|
+
if (blot.statics.scope === Parchment.Scope.INLINE_BLOT) {
|
|
141
|
+
// return InlineFormatClass.value(activeEle)
|
|
142
|
+
const blotIndex = this.quill.getIndex(blot)
|
|
143
|
+
const formats = this.quill.getFormat(blotIndex, 1)
|
|
144
|
+
return formats[INLINE_FORMAT_ATTRIBUTOR]
|
|
145
|
+
} else if (blot.statics.scope === Parchment.Scope.BLOCK_BLOT) {
|
|
146
|
+
return BlockFormatClass.value(activeEle)
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
_applyToolFormatting (toolClass) {
|
|
151
|
+
const blotIndex = this.quill.getIndex(this.blot)
|
|
152
|
+
|
|
153
|
+
if (this.blot.statics.scope === Parchment.Scope.INLINE_BLOT) {
|
|
154
|
+
// Format inline blot
|
|
155
|
+
this.quill.formatText(blotIndex, 1, INLINE_FORMAT_ATTRIBUTOR, toolClass)
|
|
156
|
+
} else if (this.blot.statics.scope === Parchment.Scope.BLOCK_BLOT) {
|
|
157
|
+
// Format block blot
|
|
158
|
+
this.quill.formatLine(blotIndex, 1, BLOCK_FORMAT_ATTRIBUTOR, toolClass)
|
|
159
|
+
}
|
|
160
|
+
}
|
|
116
161
|
}
|