editorjs-image 1.0.13 → 1.0.14
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 +2 -20
- package/src/index.js +66 -61
package/package.json
CHANGED
package/src/index.css
CHANGED
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
}
|
|
40
40
|
|
|
41
41
|
|
|
42
|
-
|
|
42
|
+
|
|
43
43
|
.cdx-image-tool-tune--sizeSmall img {
|
|
44
44
|
max-height: 200px !important;
|
|
45
45
|
object-fit:cover;
|
|
@@ -49,7 +49,6 @@
|
|
|
49
49
|
max-width: 25% !important;
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
.cdx-image-tool-tune--sizeMiddle .image-tool__caption { max-height: 300px; }
|
|
53
52
|
.cdx-image-tool-tune--sizeMiddle img {
|
|
54
53
|
max-height: 300px !important;
|
|
55
54
|
object-fit:cover;
|
|
@@ -57,8 +56,7 @@
|
|
|
57
56
|
.cdx-image-tool-tune--sizeMiddle .cdx-block {
|
|
58
57
|
max-width: 50% !important;
|
|
59
58
|
}
|
|
60
|
-
|
|
61
|
-
.cdx-image-tool-tune--sizeLarge .image-tool__caption { max-height: 400px; }
|
|
59
|
+
|
|
62
60
|
.cdx-image-tool-tune--sizeLarge img {
|
|
63
61
|
max-height: 400px !important;
|
|
64
62
|
object-fit:cover;
|
|
@@ -67,22 +65,6 @@
|
|
|
67
65
|
max-width: 75% !important;
|
|
68
66
|
}
|
|
69
67
|
|
|
70
|
-
.cdx-image-tool-tune--sizeLarge img,
|
|
71
|
-
.cdx-image-tool-tune--sizeMiddle img,
|
|
72
|
-
.cdx-image-tool-tune--sizeSmall img,
|
|
73
|
-
.cdx-image-tool-tune--floatLeft img,
|
|
74
|
-
.cdx-image-tool-tune--floatRight img
|
|
75
|
-
{ max-height:500px; }
|
|
76
|
-
|
|
77
|
-
.cdx-image-tool-tune--sizeLarge .image-tool__caption,
|
|
78
|
-
.cdx-image-tool-tune--sizeMiddle .image-tool__caption,
|
|
79
|
-
.cdx-image-tool-tune--sizeSmall .image-tool__caption,
|
|
80
|
-
.cdx-image-tool-tune--floatLeft .image-tool__caption,
|
|
81
|
-
.cdx-image-tool-tune--floatRight .image-tool__caption
|
|
82
|
-
{
|
|
83
|
-
max-height:500px;
|
|
84
|
-
}
|
|
85
|
-
|
|
86
68
|
.codex-editor.read-only .cdx-input.image-tool__caption:empty,
|
|
87
69
|
.read-only > .codex-editor .cdx-input.image-tool__caption:empty
|
|
88
70
|
{
|
package/src/index.js
CHANGED
|
@@ -390,9 +390,8 @@ export class ImageToolTune {
|
|
|
390
390
|
if ( this.api.readOnly.isEnabled ) return;
|
|
391
391
|
|
|
392
392
|
this.uncrop( blockContent );
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
imageBlock.classList.add( 'isCropping' );
|
|
393
|
+
const image = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].getElementsByTagName( 'img' )[ 0 ];
|
|
394
|
+
blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].classList.add( 'isCropping' );
|
|
396
395
|
this.cropperInterface = new Cropper( image, {
|
|
397
396
|
crop( event ) {
|
|
398
397
|
// console.log( event.detail.x );
|
|
@@ -413,6 +412,10 @@ export class ImageToolTune {
|
|
|
413
412
|
|
|
414
413
|
cropSaveBtn.addEventListener( 'click', e => {
|
|
415
414
|
|
|
415
|
+
// console.log( this.cropperInterface.getCropBoxData() );
|
|
416
|
+
// console.log( this.cropperInterface.getImageData() );
|
|
417
|
+
// console.log( this.cropperInterface.getCanvasData() );
|
|
418
|
+
|
|
416
419
|
this.data.cropperFrameHeight = this.cropperInterface.getCropBoxData().height;
|
|
417
420
|
this.data.cropperFrameWidth = this.cropperInterface.getCropBoxData().width;
|
|
418
421
|
this.data.cropperFrameLeft = this.cropperInterface.getCanvasData().left - this.cropperInterface.getCropBoxData().left;
|
|
@@ -438,31 +441,33 @@ export class ImageToolTune {
|
|
|
438
441
|
if ( this.api.readOnly.isEnabled ) return;
|
|
439
442
|
|
|
440
443
|
//apply data to image and remove cropper interface and save button, add crop button
|
|
444
|
+
var blockEl = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ];
|
|
445
|
+
if(blockEl) {
|
|
446
|
+
|
|
447
|
+
blockEl.style.minWidth = this.data.cropperFrameWidth + 'px';
|
|
448
|
+
blockEl.style.maxWidth = this.data.cropperFrameWidth + 'px';
|
|
449
|
+
|
|
450
|
+
const image = blockEl.getElementsByTagName( 'img' )[ 0 ];
|
|
451
|
+
image.style.width = this.data.cropperImageWidth + 'px';
|
|
452
|
+
image.style.height = this.data.cropperImageHeight + 'px';
|
|
453
|
+
|
|
454
|
+
var blockImg = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
|
|
455
|
+
blockImg.style.width = this.data.cropperFrameWidth + 'px';
|
|
456
|
+
blockImg.style.height = this.data.cropperFrameHeight + 'px';
|
|
457
|
+
|
|
458
|
+
var imageEl = blockImg.getElementsByTagName( 'img' )[ 0 ];
|
|
459
|
+
if(imageEl) {
|
|
460
|
+
imageEl.style.left = this.data.cropperFrameLeft + 'px';
|
|
461
|
+
imageEl.style.top = this.data.cropperFrameTop + 'px';
|
|
462
|
+
imageEl.classList.add( 'isCropped' );
|
|
463
|
+
}
|
|
441
464
|
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].style.minWidth = this.data.cropperFrameWidth + 'px';
|
|
448
|
-
blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].style.maxWidth = this.data.cropperFrameWidth + 'px';
|
|
449
|
-
|
|
450
|
-
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].style.width = this.data.cropperFrameWidth + 'px';
|
|
451
|
-
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].style.height = this.data.cropperFrameHeight + 'px';
|
|
452
|
-
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].getElementsByTagName( 'img' )[ 0 ].style.left = this.data.cropperFrameLeft + 'px';
|
|
453
|
-
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].getElementsByTagName( 'img' )[ 0 ].style.top = this.data.cropperFrameTop + 'px';
|
|
454
|
-
|
|
455
|
-
image.style.width = this.data.cropperImageWidth + 'px';
|
|
456
|
-
image.style.height = this.data.cropperImageHeight + 'px';
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].getElementsByTagName( 'img' )[ 0 ].classList.add( 'isCropped' );
|
|
460
|
-
blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].classList.remove( 'isCropping' );
|
|
461
|
-
|
|
465
|
+
blockEl.classList.remove( 'isCropping' );
|
|
462
466
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
467
|
+
const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
|
|
468
|
+
if ( cropSaveBtn ) {
|
|
469
|
+
blockImg.removeChild( cropSaveBtn );
|
|
470
|
+
}
|
|
466
471
|
}
|
|
467
472
|
|
|
468
473
|
|
|
@@ -481,14 +486,18 @@ export class ImageToolTune {
|
|
|
481
486
|
cropBtn.classList.add( 'crop-btn', 'btn-crop-action' );
|
|
482
487
|
cropBtn.innerHTML = 'Crop';
|
|
483
488
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
489
|
+
var imageEl = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
|
|
490
|
+
if(imageEl) {
|
|
491
|
+
|
|
492
|
+
cropBtn.addEventListener( 'click', e => {
|
|
493
|
+
//remove crop button
|
|
494
|
+
imageEl.removeChild( cropBtn );
|
|
495
|
+
this.appendCrop( blockContent );
|
|
496
|
+
}
|
|
497
|
+
);
|
|
490
498
|
|
|
491
|
-
|
|
499
|
+
imageEl.appendChild( cropBtn );
|
|
500
|
+
}
|
|
492
501
|
|
|
493
502
|
blockContent.classList.remove( 'isCropping' );
|
|
494
503
|
|
|
@@ -501,25 +510,25 @@ export class ImageToolTune {
|
|
|
501
510
|
|
|
502
511
|
if ( this.api.readOnly.isEnabled ) return;
|
|
503
512
|
|
|
513
|
+
var imageEl = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
|
|
514
|
+
|
|
504
515
|
//remove crop and save button
|
|
505
|
-
const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ]
|
|
506
|
-
if ( cropSaveBtn ) {
|
|
507
|
-
|
|
516
|
+
const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
|
|
517
|
+
if ( cropSaveBtn && imageEl) {
|
|
518
|
+
imageEl.removeChild( cropSaveBtn );
|
|
508
519
|
}
|
|
509
520
|
|
|
510
|
-
|
|
511
521
|
//remove crop button
|
|
512
|
-
const cropBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ]
|
|
513
|
-
if ( cropBtn ) {
|
|
514
|
-
|
|
522
|
+
const cropBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
|
|
523
|
+
if ( cropBtn && imageEl) {
|
|
524
|
+
imageEl.removeChild( cropBtn );
|
|
515
525
|
}
|
|
516
526
|
|
|
517
527
|
//remove isCropped class
|
|
518
|
-
var blockEl = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ]
|
|
519
|
-
if
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
if (img) img.classList.remove( 'isCropped' );
|
|
528
|
+
var blockEl = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ];
|
|
529
|
+
if(blockEl) {
|
|
530
|
+
var image = blockEl.getElementsByTagName( 'img' )[ 0 ];
|
|
531
|
+
if (image) image.classList.remove( 'isCropped' );
|
|
523
532
|
|
|
524
533
|
//remove isCropping class
|
|
525
534
|
blockEl.classList.remove( 'isCropping' );
|
|
@@ -529,25 +538,25 @@ export class ImageToolTune {
|
|
|
529
538
|
blockEl.style.maxWidth = '';
|
|
530
539
|
}
|
|
531
540
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
541
|
+
if(imageEl) {
|
|
542
|
+
|
|
543
|
+
//remove image width and height
|
|
544
|
+
imageEl.style.width = '';
|
|
545
|
+
imageEl.style.height = '';
|
|
537
546
|
|
|
538
547
|
//remove image left and top
|
|
539
|
-
var
|
|
540
|
-
if
|
|
541
|
-
|
|
542
|
-
|
|
548
|
+
var image = imageEl.getElementsByTagName( 'img' )[ 0 ];
|
|
549
|
+
if(image)
|
|
550
|
+
{
|
|
551
|
+
image.style.left = '';
|
|
552
|
+
image.style.top = '';
|
|
543
553
|
|
|
544
554
|
//remove image width and height
|
|
545
|
-
|
|
546
|
-
|
|
555
|
+
image.style.width = '';
|
|
556
|
+
image.style.height = '';
|
|
547
557
|
}
|
|
548
558
|
}
|
|
549
559
|
|
|
550
|
-
|
|
551
560
|
blockContent.classList.remove( 'isCropping' );
|
|
552
561
|
|
|
553
562
|
|
|
@@ -580,13 +589,9 @@ export class ImageToolTune {
|
|
|
580
589
|
* */
|
|
581
590
|
resize( blockContent ) {
|
|
582
591
|
|
|
583
|
-
|
|
584
592
|
const resizable = document.createElement( 'div' );
|
|
585
593
|
resizable.classList.add( 'resizable' );
|
|
586
594
|
|
|
587
|
-
// console.log( resizable );
|
|
588
|
-
|
|
589
|
-
|
|
590
595
|
const resizers = document.createElement( 'div' );
|
|
591
596
|
resizers.classList.add( 'resizers' );
|
|
592
597
|
|