Commit 59021c3c by Рамис

added resizable image

parent 11f29e9f
...@@ -7,12 +7,13 @@ import 'react-ag-qeditor/dist/index.css' ...@@ -7,12 +7,13 @@ import 'react-ag-qeditor/dist/index.css'
const App = () => { const App = () => {
return <div style={{padding:40}}> return <div style={{padding:40}}>
<QEditor <QEditor
value={'<span style="font-size: 20px;">asds</span>'} value={'<p><b>bold</b></p>' +
'<p><img src="https://cdn.atmaguru.online/2/atma/4/e/4edof0juw55fUp6TC41r7Swt4eCMWFGHJKBvtZxyglvI2B7aae1NRsqkvV7CLkny.jpeg" width="100"></p>'}
onChange={(value)=>{ onChange={(value)=>{
console.log('sads', value); console.log('sads', value);
}} }}
uploadOptions={{ uploadOptions={{
url: 'https://cdn.atmaguru.online/upload/?sid=test&md5=UN8SUwWR8m5XUm9v8uDtew&expires=1652081782', url: 'https://cdn.atmaguru.online/upload/?sid=test&md5=YEUk8Mjmh2h9NnJrVO7Srg&expires=1653194293',
errorMessage: 'Загрузка временно невозможна' errorMessage: 'Загрузка временно невозможна'
}} }}
/> />
......
{ {
"name": "react-ag-qeditor", "name": "react-ag-qeditor",
"version": "0.0.4", "version": "0.0.5",
"description": "WYSIWYG html editor", "description": "WYSIWYG html editor",
"author": "atma", "author": "atma",
"license": "MIT", "license": "MIT",
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
}, },
"scripts": { "scripts": {
"build": "microbundle-crl --no-compress --format modern,cjs --css-modules false", "build": "microbundle-crl --no-compress --format modern,cjs --css-modules false",
"start": "microbundle-crl watch --no-compress --format modern,cjs ", "start": "microbundle-crl watch --no-compress --format modern,cjs --css-modules false",
"prepare": "run-s build", "prepare": "run-s build",
"test": "run-s test:unit test:lint test:build", "test": "run-s test:unit test:lint test:build",
"test:build": "run-s build", "test:build": "run-s build",
...@@ -54,10 +54,12 @@ ...@@ -54,10 +54,12 @@
"dist" "dist"
], ],
"dependencies": { "dependencies": {
"katex": "^0.15.3",
"quill-blot-formatter": "^1.0.5",
"quill-image-resize-module-react": "^3.0.0",
"rc-upload": "^4.3.3",
"react": "^18.0.0", "react": "^18.0.0",
"react-quill": "^1.3.5", "react-quill": "^1.3.5",
"sass": "^1.49.9", "sass": "^1.49.9"
"katex": "^0.15.3",
"rc-upload": "^4.3.3"
} }
} }
...@@ -2,13 +2,21 @@ import React, { Fragment } from 'react' ...@@ -2,13 +2,21 @@ import React, { Fragment } from 'react'
import ReactQuill, { Quill } from 'react-quill'; import ReactQuill, { Quill } from 'react-quill';
import './index.scss'; import './index.scss';
import 'react-quill/dist/quill.snow.css'; import 'react-quill/dist/quill.snow.css';
import ImageBlot from "./blots/ImageBlot";
import VideoBlot from "./blots/VideoBlot"; import VideoBlot from "./blots/VideoBlot";
import VideoLocalBlot from "./blots/VideoLocalBlot"; import VideoLocalBlot from "./blots/VideoLocalBlot";
import EditorModal from "./components/EditorModal"; import EditorModal from "./components/EditorModal";
import Uploader from "./components/Uploader"; import Uploader from "./components/Uploader";
import "katex/dist/katex.min.css"; import "katex/dist/katex.min.css";
import ImageResize from "quill-image-resize-module-react";
import BlotFormatter from 'quill-blot-formatter';
import katex from "katex"; import katex from "katex";
Quill.register('modules/blotFormatter', BlotFormatter);
export default class QEditor extends React.Component { export default class QEditor extends React.Component {
constructor (props) { constructor (props) {
super(props) super(props)
...@@ -24,6 +32,8 @@ export default class QEditor extends React.Component { ...@@ -24,6 +32,8 @@ export default class QEditor extends React.Component {
Quill.register('formats/video', VideoBlot) Quill.register('formats/video', VideoBlot)
Quill.register('formats/videoLocal', VideoLocalBlot) Quill.register('formats/videoLocal', VideoLocalBlot)
// Quill.register('modules/imageResize', ImageResize)
Quill.register('formats/image', ImageBlot)
} }
...@@ -64,13 +74,33 @@ export default class QEditor extends React.Component { ...@@ -64,13 +74,33 @@ export default class QEditor extends React.Component {
innerModalType: 'videoLocal' innerModalType: 'videoLocal'
}, () => this.editorModal.show({title: 'Загрузить видео'})); }, () => this.editorModal.show({title: 'Загрузить видео'}));
}, },
image: () => { image: (a) => {
console.log(a);
this.setState({ this.setState({
innerModalType: 'image' innerModalType: 'image'
}, () => this.editorModal.show({title: 'Загрузить изображение'})); }, () => this.editorModal.show({title: 'Загрузить изображение'}));
} }
} }
}, },
// imageResize: {
// parchment: Quill.import("parchment"),
// modules: ["Resize", "DisplaySize"]
// },
blotFormatter: {}
/* clipboard: {
matchers: [
['IMG', (node, delta)=>{
console.log(delta)
return delta.compose(new Delta().retain(delta.length(), { width: 100, title: 'ekwgon' }));
}]
]
} */
} }
formats = [ formats = [
...@@ -79,7 +109,7 @@ export default class QEditor extends React.Component { ...@@ -79,7 +109,7 @@ export default class QEditor extends React.Component {
'list', 'bullet', 'indent', 'list', 'bullet', 'indent',
'align', 'align',
'link', 'image', 'video', 'color', 'background', 'videoLocal', 'link', 'image', 'video', 'color', 'background', 'videoLocal',
'formula'/*'imageHandler',*/ 'formula'
] ]
buildActionsModal (buttons = []) { buildActionsModal (buttons = []) {
...@@ -170,6 +200,7 @@ export default class QEditor extends React.Component { ...@@ -170,6 +200,7 @@ export default class QEditor extends React.Component {
this.state.uploadedPaths.map((file, i) => { this.state.uploadedPaths.map((file, i) => {
quill.insertEmbed(index, this.state.innerModalType, file.path, Quill.sources.USER); quill.insertEmbed(index, this.state.innerModalType, file.path, Quill.sources.USER);
quill.setSelection(index + 1); quill.setSelection(index + 1);
quill.blur();
}); });
break break
...@@ -251,6 +282,6 @@ QEditor.defaultProps = { ...@@ -251,6 +282,6 @@ QEditor.defaultProps = {
lang: 'ru', lang: 'ru',
uploadOptions: { uploadOptions: {
url: null, url: null,
errorMessage: null errorMessage: 'Загрузка временно невозможна'
} }
} }
import { Quill } from 'react-quill'
const Image = Quill.import('formats/image')
export default class ImageBlot extends Image {
static create(value) {
if (typeof value == 'string') {
return super.create(value);
} else {
return value;
}
}
static value(domNode) {
return domNode;
}
static get ATTRIBUTES() {
return [ 'alt', 'height', 'width' ]
}
//
// static formats(domNode) {
//
// console.log(domNode);
//
//
// return this.ATTRIBUTES.reduce(function(formats, attribute) {
// if (domNode.hasAttribute(attribute)) {
// formats[attribute] = domNode.getAttribute(attribute);
// }
// return formats;
// }, {});
// }
formatAt(name, value) {
console.log(name, value);
if (this.constructor.ATTRIBUTES.indexOf(name) > -1) {
if (value) {
this.domNode.setAttribute(name, value);
} else {
this.domNode.removeAttribute(name);
}
} else {
super.format(name, value);
}
}
}
...@@ -15,9 +15,8 @@ export default class VideoBlot extends Video { ...@@ -15,9 +15,8 @@ export default class VideoBlot extends Video {
switch (url.hostname){ switch (url.hostname){
case 'rutube.ru': case 'rutube.ru':
case 'www.rutube.ru': case 'www.rutube.ru':
value = `//rutube.ru/play/embed/${id}`; value = `https://rutube.ru/pl/?pl_id&pl_type&pl_video=${id}`;
break break
case 'ok.ru': case 'ok.ru':
case 'www.ok.ru': case 'www.ok.ru':
value = `//ok.ru/videoembed/${id}`; value = `//ok.ru/videoembed/${id}`;
......
...@@ -33,8 +33,13 @@ ...@@ -33,8 +33,13 @@
} }
&-editor{ &-editor{
min-height: 350px; overflow: visible;
max-height: 800px;
&:after{
content: "";
display: block;
clear: both;
}
} }
&-container{ &-container{
...@@ -243,8 +248,6 @@ ...@@ -243,8 +248,6 @@
//lang RU //lang RU
&[data-lang="ru"]{ &[data-lang="ru"]{
.ql-snow{ .ql-snow{
.ql-picker.ql-header .ql-picker-label, .ql-picker.ql-header .ql-picker-label,
...@@ -289,8 +292,5 @@ ...@@ -289,8 +292,5 @@
} }
} }
} }
This source diff could not be displayed because it is too large. You can view the blob instead.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment