quill-js-rails-adnan 0.0.1
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.
- checksums.yaml +7 -0
- data/lib/quill-editor.js +115 -0
- metadata +46 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b0612b25ab2b9685353c05213cbef6b27be678456e41f37c0969f232943a3db9
|
4
|
+
data.tar.gz: 69ba25b7eb349ecbbc5d62ab32b027daace6161072269296d26cb74768535057
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 40505b07ed9229098f6de3744bbde58798236ba414a8d1e6e86d22c3c87f480922fd846c07f8e3657c4b769efffa9151525ecdc97fe82f727a0ca010875d15db
|
7
|
+
data.tar.gz: 9510a280959435cc12d80fd5cafe13d9c2fb0f108aa41da6a627ddb55f7734423232f19f5d69bc08155a3d292511eb3f3a51827049e1ca32ae124043fb5fa92a
|
data/lib/quill-editor.js
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
import { DirectUpload } from "@rails/activestorage"
|
2
|
+
import ImageResize from "@taoqf/quill-image-resize-module/image-resize.min";
|
3
|
+
import Quill from 'quill/quill';
|
4
|
+
export default Quill;
|
5
|
+
|
6
|
+
Quill.register('modules/imageResize', ImageResize);
|
7
|
+
|
8
|
+
// document.addEventListener("DOMContentLoaded", function (event) {
|
9
|
+
// var quill = new Quill('#editor-container', {
|
10
|
+
// modules: {
|
11
|
+
// toolbar: [
|
12
|
+
// [{ header: [1, 2, false] }],
|
13
|
+
// ['bold', 'italic', 'underline'],
|
14
|
+
// ['image', 'code-block']
|
15
|
+
// ]
|
16
|
+
// },
|
17
|
+
// placeholder: 'Compose an epic...',
|
18
|
+
// theme: 'snow'
|
19
|
+
// });
|
20
|
+
//
|
21
|
+
// document.querySelector('form').onsubmit = function () {
|
22
|
+
// var body = document.querySelector('input[class=article-content]');
|
23
|
+
// body.value = quill.root.innerHTML
|
24
|
+
// };
|
25
|
+
// });
|
26
|
+
|
27
|
+
document.addEventListener("DOMContentLoaded", function (event) {
|
28
|
+
var quill = new Quill('#editor-container', {
|
29
|
+
modules: {
|
30
|
+
toolbar: [
|
31
|
+
[{ header: [1, 2, 3, 4, 5, 6, false] }],
|
32
|
+
[{ color: [] }],
|
33
|
+
[{ size: [] }],
|
34
|
+
[
|
35
|
+
'bold', 'italic', 'underline', 'strike',
|
36
|
+
{ 'script': 'super'},
|
37
|
+
{ 'script': 'sub' },
|
38
|
+
'code', 'link'
|
39
|
+
],
|
40
|
+
['blockquote', 'code-block', 'image'],
|
41
|
+
[{ list: 'ordered' }, { list: 'bullet' }],
|
42
|
+
[{ align: ['center', 'right', 'justify', false] }],
|
43
|
+
[{ indent: '-1'}, { indent: '+1' }]
|
44
|
+
|
45
|
+
|
46
|
+
],
|
47
|
+
imageResize: {
|
48
|
+
displaySize: true,
|
49
|
+
displayStyles: {
|
50
|
+
backgroundColor: 'black',
|
51
|
+
border: 'none',
|
52
|
+
color: 'white'
|
53
|
+
},
|
54
|
+
modules: [ 'Resize', 'DisplaySize', 'Toolbar' ]
|
55
|
+
}
|
56
|
+
},
|
57
|
+
value: document.querySelector('input[class=article-content]').value,
|
58
|
+
theme: 'snow'
|
59
|
+
});
|
60
|
+
|
61
|
+
document.querySelector('form').onsubmit = function () {
|
62
|
+
var body = document.querySelector('input[class=article-content]');
|
63
|
+
body.value = quill.root.innerHTML
|
64
|
+
};
|
65
|
+
|
66
|
+
// More on this in a bit!
|
67
|
+
quill.getModule('toolbar').addHandler('image', () => {
|
68
|
+
importImage(quill);
|
69
|
+
});
|
70
|
+
});
|
71
|
+
|
72
|
+
var importImage = function (textEditor) {
|
73
|
+
const input = document.createElement('input');
|
74
|
+
input.setAttribute('type', 'file');
|
75
|
+
input.click();
|
76
|
+
|
77
|
+
input.onchange = () => {
|
78
|
+
const file = input.files[0];
|
79
|
+
|
80
|
+
// Ensure only images are uploaded
|
81
|
+
if (/^image\//.test(file.type)) {
|
82
|
+
uploadImage(textEditor, file);
|
83
|
+
} else {
|
84
|
+
alert('Only images allowed');
|
85
|
+
}
|
86
|
+
};
|
87
|
+
};
|
88
|
+
|
89
|
+
var uploadImage = function (textEditor, file) {
|
90
|
+
var fd = new FormData();
|
91
|
+
fd.append('blob', file);
|
92
|
+
|
93
|
+
var upload = new DirectUpload(file, '/rails/active_storage/direct_uploads')
|
94
|
+
upload.create((error, blob) => {
|
95
|
+
if (error) {
|
96
|
+
console.log(error)
|
97
|
+
} else {
|
98
|
+
insertImage(
|
99
|
+
textEditor,
|
100
|
+
`/rails/active_storage/blobs/${blob.signed_id}/${blob.filename}`
|
101
|
+
);
|
102
|
+
}
|
103
|
+
});
|
104
|
+
};
|
105
|
+
|
106
|
+
var insertImage = function (textEditor, fileUrl) {
|
107
|
+
const range = textEditor.getSelection();
|
108
|
+
textEditor.insertEmbed(range.index, 'image', fileUrl);
|
109
|
+
};
|
110
|
+
|
111
|
+
var icons = Quill.import('ui/icons');
|
112
|
+
|
113
|
+
icons['code'] = `<svg class="bi bi-code" width="1.5em" height="1.5em" viewBox="0 0 16 16" fill="currentColor" xmlns="http://www.w3.org/2000/svg">
|
114
|
+
<path fill-rule="evenodd" d="M5.854 4.146a.5.5 0 010 .708L2.707 8l3.147 3.146a.5.5 0 01-.708.708l-3.5-3.5a.5.5 0 010-.708l3.5-3.5a.5.5 0 01.708 0zm4.292 0a.5.5 0 000 .708L13.293 8l-3.147 3.146a.5.5 0 00.708.708l3.5-3.5a.5.5 0 000-.708l-3.5-3.5a.5.5 0 00-.708 0z" clip-rule="evenodd"/>
|
115
|
+
</svg>`;
|
metadata
ADDED
@@ -0,0 +1,46 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: quill-js-rails-adnan
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Adnan Mustafa
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2021-09-07 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Quill is a free, open source WYSIWYG editor built for the modern web.
|
14
|
+
With its modular architecture and expressive API, it is completely customizable
|
15
|
+
to fit any need.
|
16
|
+
email: mirzaadnanmustafa@yahoo.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/quill-editor.js
|
22
|
+
homepage: https://rubygems.org/gems/quill-js-rails-adnan
|
23
|
+
licenses: []
|
24
|
+
metadata: {}
|
25
|
+
post_install_message:
|
26
|
+
rdoc_options: []
|
27
|
+
require_paths:
|
28
|
+
- lib
|
29
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
35
|
+
requirements:
|
36
|
+
- - ">="
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
requirements: []
|
40
|
+
rubygems_version: 3.0.6
|
41
|
+
signing_key:
|
42
|
+
specification_version: 4
|
43
|
+
summary: Quill is a free, open source WYSIWYG editor built for the modern web. With
|
44
|
+
its modular architecture and expressive API, it is completely customizable to fit
|
45
|
+
any need.
|
46
|
+
test_files: []
|