editorjs-image 1.0.7 → 1.0.8
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/package.json +1 -1
- package/src/index.css +44 -5
- package/src/index.js +70 -75
package/package.json
CHANGED
package/src/index.css
CHANGED
|
@@ -5,9 +5,31 @@
|
|
|
5
5
|
|
|
6
6
|
.cdx-image-tool-tune--floatLeft.ce-block__content .image-tool__image,
|
|
7
7
|
.cdx-image-tool-tune--floatRight.ce-block__content .image-tool__image {
|
|
8
|
-
margin-top:
|
|
8
|
+
margin-top: 40px;
|
|
9
|
+
margin-left: 20px;
|
|
9
10
|
}
|
|
10
11
|
|
|
12
|
+
.cdx-image-tool-tune--floatLeft.ce-block__content .cdx-input,
|
|
13
|
+
.cdx-image-tool-tune--floatRight.ce-block__content .cdx-input
|
|
14
|
+
{
|
|
15
|
+
margin-left: 20px;
|
|
16
|
+
width: calc(100% - 20px);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.cdx-image-tool-tune--floatLeft .cdx-block,
|
|
20
|
+
.cdx-image-tool-tune--center .cdx-block,
|
|
21
|
+
.cdx-image-tool-tune--floatRight .cdx-block,
|
|
22
|
+
.cdx-image-tool-tune--floatLeft .image-tool__image,
|
|
23
|
+
.cdx-image-tool-tune--center .image-tool__image,
|
|
24
|
+
.cdx-image-tool-tune--floatRight .image-tool__image,
|
|
25
|
+
.cdx-image-tool-tune--floatLeft .cdx-block,
|
|
26
|
+
.cdx-image-tool-tune--center .cdx-block,
|
|
27
|
+
.cdx-image-tool-tune--floatRight .cdx-block
|
|
28
|
+
{
|
|
29
|
+
display: flex;
|
|
30
|
+
flex-direction: column;
|
|
31
|
+
align-items: center;
|
|
32
|
+
}
|
|
11
33
|
|
|
12
34
|
.cdx-image-tool-tune--center .cdx-block {
|
|
13
35
|
margin: auto;
|
|
@@ -23,19 +45,36 @@
|
|
|
23
45
|
margin-left: 10px;
|
|
24
46
|
}
|
|
25
47
|
|
|
48
|
+
.cdx-image-tool-tune--sizeSmall img {
|
|
49
|
+
max-height: 200px !important;
|
|
50
|
+
object-fit:cover;
|
|
51
|
+
}
|
|
52
|
+
|
|
26
53
|
.cdx-image-tool-tune--sizeSmall .cdx-block {
|
|
27
|
-
width:
|
|
54
|
+
max-width: 25% !important;
|
|
28
55
|
}
|
|
29
56
|
|
|
57
|
+
.cdx-image-tool-tune--sizeMiddle img {
|
|
58
|
+
max-height: 300px !important;
|
|
59
|
+
object-fit:cover;
|
|
60
|
+
}
|
|
30
61
|
.cdx-image-tool-tune--sizeMiddle .cdx-block {
|
|
31
|
-
width:
|
|
62
|
+
max-width: 50% !important;
|
|
32
63
|
}
|
|
33
64
|
|
|
65
|
+
.cdx-image-tool-tune--sizeLarge img {
|
|
66
|
+
max-height: 400px !important;
|
|
67
|
+
object-fit:cover;
|
|
68
|
+
}
|
|
34
69
|
.cdx-image-tool-tune--sizeLarge .cdx-block {
|
|
35
|
-
width:
|
|
70
|
+
max-width: 75% !important;
|
|
36
71
|
}
|
|
37
72
|
|
|
38
|
-
|
|
73
|
+
.codex-editor.read-only .cdx-input.image-tool__caption:empty,
|
|
74
|
+
.read-only > .codex-editor .cdx-input.image-tool__caption:empty
|
|
75
|
+
{
|
|
76
|
+
display:none;
|
|
77
|
+
}
|
|
39
78
|
|
|
40
79
|
.cdx-image-tool-tune--resize .cdx-block {
|
|
41
80
|
position: relative;
|
package/src/index.js
CHANGED
|
@@ -30,17 +30,17 @@ export class ImageToolTune {
|
|
|
30
30
|
{
|
|
31
31
|
name: 'sizeSmall',
|
|
32
32
|
icon: '<svg stroke="currentColor" fill="none" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M12 6V4H20V20H12V18H8V16H4V8H8V6H12ZM14 6H18V18H14V6ZM12 8H10V16H12V8ZM8 10V14H6V10H8Z" fill="currentColor"></path></svg>',
|
|
33
|
-
label: '
|
|
33
|
+
label: '25%',
|
|
34
34
|
group: 'size',
|
|
35
35
|
}, {
|
|
36
36
|
name: 'sizeMiddle',
|
|
37
37
|
icon: '<svg stroke="currentColor" fill="none" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M12 6V4H20V20H12V18H8V16H4V8H8V6H12ZM14 6H18V18H14V6ZM12 8H10V16H12V8ZM8 10V14H6V10H8Z" fill="currentColor"></path></svg>',
|
|
38
|
-
label: '
|
|
38
|
+
label: '50%',
|
|
39
39
|
group: 'size',
|
|
40
40
|
}, {
|
|
41
41
|
name: 'sizeLarge',
|
|
42
42
|
icon: '<svg stroke="currentColor" fill="none" stroke-width="0" viewBox="0 0 24 24" height="1em" width="1em" xmlns="http://www.w3.org/2000/svg"><path fill-rule="evenodd" clip-rule="evenodd" d="M12 6V4H20V20H12V18H8V16H4V8H8V6H12ZM14 6H18V18H14V6ZM12 8H10V16H12V8ZM8 10V14H6V10H8Z" fill="currentColor"></path></svg>',
|
|
43
|
-
label: '
|
|
43
|
+
label: '75%',
|
|
44
44
|
group: 'size',
|
|
45
45
|
}, {
|
|
46
46
|
name: 'resize',
|
|
@@ -365,46 +365,41 @@ export class ImageToolTune {
|
|
|
365
365
|
*/
|
|
366
366
|
crop( blockContent ) {
|
|
367
367
|
|
|
368
|
-
//this.appendCrop( blockContent );
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
368
|
//add append crop button to image-tool__image
|
|
373
369
|
//If editor is readOnly, do not add crop button
|
|
374
|
-
if (
|
|
375
|
-
const image = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
|
|
376
|
-
const cropBtn = document.createElement( 'div' );
|
|
377
|
-
cropBtn.classList.add( 'crop-btn', 'btn-crop-action' );
|
|
378
|
-
cropBtn.innerHTML = 'Crop';
|
|
379
|
-
|
|
380
|
-
cropBtn.addEventListener( 'click', e => {
|
|
381
|
-
//remove crop button
|
|
382
|
-
image.removeChild( cropBtn );
|
|
383
|
-
this.appendCrop( blockContent );
|
|
384
|
-
}
|
|
385
|
-
);
|
|
370
|
+
if ( this.api.readOnly.isEnabled ) return;
|
|
386
371
|
|
|
387
|
-
|
|
372
|
+
const image = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
|
|
373
|
+
const cropBtn = document.createElement( 'div' );
|
|
374
|
+
cropBtn.classList.add( 'crop-btn', 'btn-crop-action' );
|
|
375
|
+
cropBtn.innerHTML = 'Crop';
|
|
388
376
|
|
|
377
|
+
cropBtn.addEventListener( 'click', e => {
|
|
378
|
+
//remove crop button
|
|
379
|
+
image.removeChild( cropBtn );
|
|
380
|
+
this.appendCrop( blockContent );
|
|
389
381
|
}
|
|
382
|
+
);
|
|
390
383
|
|
|
384
|
+
image.appendChild( cropBtn );
|
|
391
385
|
}
|
|
392
386
|
|
|
393
387
|
|
|
394
388
|
appendCrop( blockContent ) {
|
|
389
|
+
|
|
390
|
+
if ( this.api.readOnly.isEnabled ) return;
|
|
391
|
+
|
|
395
392
|
this.uncrop( blockContent );
|
|
396
393
|
const image = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].getElementsByTagName( 'img' )[ 0 ];
|
|
397
394
|
blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].classList.add( 'isCropping' );
|
|
398
395
|
this.cropperInterface = new Cropper( image, {
|
|
399
396
|
crop( event ) {
|
|
400
|
-
console.log( event.detail.x );
|
|
401
|
-
console.log( event.detail.y );
|
|
402
|
-
console.log( event.detail.width );
|
|
403
|
-
console.log( event.detail.height );
|
|
404
|
-
console.log( event.detail.scaleX );
|
|
405
|
-
console.log( event.detail.scaleY );
|
|
406
|
-
|
|
407
|
-
|
|
397
|
+
// console.log( event.detail.x );
|
|
398
|
+
// console.log( event.detail.y );
|
|
399
|
+
// console.log( event.detail.width );
|
|
400
|
+
// console.log( event.detail.height );
|
|
401
|
+
// console.log( event.detail.scaleX );
|
|
402
|
+
// console.log( event.detail.scaleY );
|
|
408
403
|
},
|
|
409
404
|
} );
|
|
410
405
|
|
|
@@ -444,6 +439,8 @@ export class ImageToolTune {
|
|
|
444
439
|
|
|
445
440
|
applyCrop( blockContent ) {
|
|
446
441
|
|
|
442
|
+
if ( this.api.readOnly.isEnabled ) return;
|
|
443
|
+
|
|
447
444
|
//apply data to image and remove cropper interface and save button, add crop button
|
|
448
445
|
|
|
449
446
|
const image = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].getElementsByTagName( 'img' )[ 0 ];
|
|
@@ -483,21 +480,20 @@ export class ImageToolTune {
|
|
|
483
480
|
|
|
484
481
|
|
|
485
482
|
//add crop button
|
|
486
|
-
if ( !this.api.readOnly ) {
|
|
487
|
-
|
|
488
|
-
const cropBtn = document.createElement( 'div' );
|
|
489
|
-
cropBtn.classList.add( 'crop-btn', 'btn-crop-action' );
|
|
490
|
-
cropBtn.innerHTML = 'Crop';
|
|
491
483
|
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
this.appendCrop( blockContent );
|
|
496
|
-
}
|
|
497
|
-
);
|
|
484
|
+
const cropBtn = document.createElement( 'div' );
|
|
485
|
+
cropBtn.classList.add( 'crop-btn', 'btn-crop-action' );
|
|
486
|
+
cropBtn.innerHTML = 'Crop';
|
|
498
487
|
|
|
499
|
-
|
|
488
|
+
cropBtn.addEventListener( 'click', e => {
|
|
489
|
+
//remove crop button
|
|
490
|
+
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].removeChild( cropBtn );
|
|
491
|
+
this.appendCrop( blockContent );
|
|
500
492
|
}
|
|
493
|
+
);
|
|
494
|
+
|
|
495
|
+
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].appendChild( cropBtn );
|
|
496
|
+
|
|
501
497
|
blockContent.classList.remove( 'isCropping' );
|
|
502
498
|
|
|
503
499
|
this.block.dispatchChange();
|
|
@@ -507,6 +503,8 @@ export class ImageToolTune {
|
|
|
507
503
|
|
|
508
504
|
uncrop( blockContent ) {
|
|
509
505
|
|
|
506
|
+
if ( this.api.readOnly.isEnabled ) return;
|
|
507
|
+
|
|
510
508
|
//remove crop and save button
|
|
511
509
|
const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
|
|
512
510
|
if ( cropSaveBtn ) {
|
|
@@ -578,50 +576,48 @@ export class ImageToolTune {
|
|
|
578
576
|
* */
|
|
579
577
|
resize( blockContent ) {
|
|
580
578
|
|
|
581
|
-
if ( !this.api.readOnly ) {
|
|
582
579
|
|
|
583
|
-
|
|
584
|
-
|
|
580
|
+
const resizable = document.createElement( 'div' );
|
|
581
|
+
resizable.classList.add( 'resizable' );
|
|
585
582
|
|
|
586
|
-
|
|
583
|
+
// console.log( resizable );
|
|
587
584
|
|
|
588
585
|
|
|
589
|
-
|
|
590
|
-
|
|
586
|
+
const resizers = document.createElement( 'div' );
|
|
587
|
+
resizers.classList.add( 'resizers' );
|
|
591
588
|
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
589
|
+
const resizerTopLeft = document.createElement( 'div' );
|
|
590
|
+
resizerTopLeft.classList.add( 'resizer', 'top-left' );
|
|
591
|
+
resizerTopLeft.addEventListener( 'mousedown', e => {
|
|
592
|
+
this.resizeClick( blockContent.getElementsByClassName( 'cdx-block' )[ 0 ], resizerTopLeft, e );
|
|
593
|
+
} );
|
|
597
594
|
|
|
598
595
|
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
596
|
+
const resizerTopRight = document.createElement( 'div' );
|
|
597
|
+
resizerTopRight.classList.add( 'resizer', 'top-right' );
|
|
598
|
+
resizerTopRight.addEventListener( 'mousedown', e => {
|
|
599
|
+
this.resizeClick( blockContent.getElementsByClassName( 'cdx-block' )[ 0 ], resizerTopRight, e );
|
|
600
|
+
} );
|
|
604
601
|
|
|
605
602
|
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
603
|
+
const resizerBottomLeft = document.createElement( 'div' );
|
|
604
|
+
resizerBottomLeft.classList.add( 'resizer', 'bottom-left' );
|
|
605
|
+
resizerBottomLeft.addEventListener( 'mousedown', e => {
|
|
606
|
+
this.resizeClick( blockContent.getElementsByClassName( 'cdx-block' )[ 0 ], resizerBottomLeft, e );
|
|
607
|
+
} );
|
|
611
608
|
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
609
|
+
const resizerBottomRight = document.createElement( 'div' );
|
|
610
|
+
resizerBottomRight.classList.add( 'resizer', 'bottom-right' );
|
|
611
|
+
resizerBottomRight.addEventListener( 'mousedown', e => {
|
|
612
|
+
this.resizeClick( blockContent.getElementsByClassName( 'cdx-block' )[ 0 ], resizerBottomRight, e );
|
|
613
|
+
} );
|
|
617
614
|
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
}
|
|
615
|
+
resizers.appendChild( resizerTopLeft );
|
|
616
|
+
resizers.appendChild( resizerTopRight );
|
|
617
|
+
resizers.appendChild( resizerBottomLeft );
|
|
618
|
+
resizers.appendChild( resizerBottomRight );
|
|
619
|
+
resizable.appendChild( resizers );
|
|
620
|
+
blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].appendChild( resizable );
|
|
625
621
|
}
|
|
626
622
|
|
|
627
623
|
|
|
@@ -894,5 +890,4 @@ export class ImageToolTune {
|
|
|
894
890
|
this.wrapper = null;
|
|
895
891
|
this.buttons = null;
|
|
896
892
|
}
|
|
897
|
-
|
|
898
|
-
}
|
|
893
|
+
}
|