editorjs-image 1.0.13 → 1.0.16
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 +6 -44
- package/src/index.js +67 -66
package/package.json
CHANGED
package/src/index.css
CHANGED
|
@@ -38,50 +38,12 @@
|
|
|
38
38
|
margin-left: 10px;
|
|
39
39
|
}
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
.cdx-image-tool-tune--
|
|
43
|
-
.cdx-image-tool-tune--
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
.cdx-image-tool-tune--sizeSmall .cdx-block {
|
|
49
|
-
max-width: 25% !important;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
.cdx-image-tool-tune--sizeMiddle .image-tool__caption { max-height: 300px; }
|
|
53
|
-
.cdx-image-tool-tune--sizeMiddle img {
|
|
54
|
-
max-height: 300px !important;
|
|
55
|
-
object-fit:cover;
|
|
56
|
-
}
|
|
57
|
-
.cdx-image-tool-tune--sizeMiddle .cdx-block {
|
|
58
|
-
max-width: 50% !important;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
.cdx-image-tool-tune--sizeLarge .image-tool__caption { max-height: 400px; }
|
|
62
|
-
.cdx-image-tool-tune--sizeLarge img {
|
|
63
|
-
max-height: 400px !important;
|
|
64
|
-
object-fit:cover;
|
|
65
|
-
}
|
|
66
|
-
.cdx-image-tool-tune--sizeLarge .cdx-block {
|
|
67
|
-
max-width: 75% !important;
|
|
68
|
-
}
|
|
69
|
-
|
|
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
|
-
}
|
|
41
|
+
.cdx-image-tool-tune--sizeSmall .cdx-block { max-width: 25% !important; }
|
|
42
|
+
.cdx-image-tool-tune--sizeMiddle .cdx-block { max-width: 50% !important; }
|
|
43
|
+
.cdx-image-tool-tune--sizeLarge .cdx-block { max-width: 75% !important; }
|
|
44
|
+
.cdx-image-tool-tune--sizeLarge img { object-fit:cover; }
|
|
45
|
+
.cdx-image-tool-tune--sizeSmall img { object-fit:cover; }
|
|
46
|
+
.cdx-image-tool-tune--sizeMiddle img { object-fit:cover; }
|
|
85
47
|
|
|
86
48
|
.codex-editor.read-only .cdx-input.image-tool__caption:empty,
|
|
87
49
|
.read-only > .codex-editor .cdx-input.image-tool__caption:empty
|
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;
|
|
@@ -432,37 +435,36 @@ export class ImageToolTune {
|
|
|
432
435
|
|
|
433
436
|
}
|
|
434
437
|
|
|
435
|
-
|
|
436
438
|
applyCrop( blockContent ) {
|
|
437
|
-
|
|
438
|
-
if ( this.api.readOnly.isEnabled ) return;
|
|
439
439
|
|
|
440
440
|
//apply data to image and remove cropper interface and save button, add crop button
|
|
441
|
+
var blockEl = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ];
|
|
442
|
+
if(blockEl) {
|
|
443
|
+
|
|
444
|
+
blockEl.style.minWidth = this.data.cropperFrameWidth + 'px';
|
|
445
|
+
blockEl.style.maxWidth = this.data.cropperFrameWidth + 'px';
|
|
446
|
+
|
|
447
|
+
const image = blockEl.getElementsByTagName( 'img' )[ 0 ];
|
|
448
|
+
image.style.width = this.data.cropperImageWidth + 'px';
|
|
449
|
+
image.style.height = this.data.cropperImageHeight + 'px';
|
|
450
|
+
|
|
451
|
+
var blockImg = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
|
|
452
|
+
blockImg.style.width = this.data.cropperFrameWidth + 'px';
|
|
453
|
+
blockImg.style.height = this.data.cropperFrameHeight + 'px';
|
|
454
|
+
|
|
455
|
+
var imageEl = blockImg.getElementsByTagName( 'img' )[ 0 ];
|
|
456
|
+
if(imageEl) {
|
|
457
|
+
imageEl.style.left = this.data.cropperFrameLeft + 'px';
|
|
458
|
+
imageEl.style.top = this.data.cropperFrameTop + 'px';
|
|
459
|
+
imageEl.classList.add( 'isCropped' );
|
|
460
|
+
}
|
|
441
461
|
|
|
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
|
-
|
|
462
|
+
blockEl.classList.remove( 'isCropping' );
|
|
462
463
|
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
464
|
+
const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
|
|
465
|
+
if ( cropSaveBtn ) {
|
|
466
|
+
blockImg.removeChild( cropSaveBtn );
|
|
467
|
+
}
|
|
466
468
|
}
|
|
467
469
|
|
|
468
470
|
|
|
@@ -481,17 +483,21 @@ export class ImageToolTune {
|
|
|
481
483
|
cropBtn.classList.add( 'crop-btn', 'btn-crop-action' );
|
|
482
484
|
cropBtn.innerHTML = 'Crop';
|
|
483
485
|
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
486
|
+
var imageEl = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
|
|
487
|
+
if(imageEl) {
|
|
488
|
+
|
|
489
|
+
cropBtn.addEventListener( 'click', e => {
|
|
490
|
+
//remove crop button
|
|
491
|
+
imageEl.removeChild( cropBtn );
|
|
492
|
+
this.appendCrop( blockContent );
|
|
493
|
+
}
|
|
494
|
+
);
|
|
490
495
|
|
|
491
|
-
|
|
496
|
+
imageEl.appendChild( cropBtn );
|
|
497
|
+
}
|
|
492
498
|
|
|
493
499
|
blockContent.classList.remove( 'isCropping' );
|
|
494
|
-
|
|
500
|
+
|
|
495
501
|
this.block.dispatchChange();
|
|
496
502
|
|
|
497
503
|
}
|
|
@@ -501,25 +507,25 @@ export class ImageToolTune {
|
|
|
501
507
|
|
|
502
508
|
if ( this.api.readOnly.isEnabled ) return;
|
|
503
509
|
|
|
510
|
+
var imageEl = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
|
|
511
|
+
|
|
504
512
|
//remove crop and save button
|
|
505
|
-
const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ]
|
|
506
|
-
if ( cropSaveBtn ) {
|
|
507
|
-
|
|
513
|
+
const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
|
|
514
|
+
if ( cropSaveBtn && imageEl) {
|
|
515
|
+
imageEl.removeChild( cropSaveBtn );
|
|
508
516
|
}
|
|
509
517
|
|
|
510
|
-
|
|
511
518
|
//remove crop button
|
|
512
|
-
const cropBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ]
|
|
513
|
-
if ( cropBtn ) {
|
|
514
|
-
|
|
519
|
+
const cropBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
|
|
520
|
+
if ( cropBtn && imageEl) {
|
|
521
|
+
imageEl.removeChild( cropBtn );
|
|
515
522
|
}
|
|
516
523
|
|
|
517
524
|
//remove isCropped class
|
|
518
|
-
var blockEl = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ]
|
|
519
|
-
if
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
if (img) img.classList.remove( 'isCropped' );
|
|
525
|
+
var blockEl = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ];
|
|
526
|
+
if(blockEl) {
|
|
527
|
+
var image = blockEl.getElementsByTagName( 'img' )[ 0 ];
|
|
528
|
+
if (image) image.classList.remove( 'isCropped' );
|
|
523
529
|
|
|
524
530
|
//remove isCropping class
|
|
525
531
|
blockEl.classList.remove( 'isCropping' );
|
|
@@ -529,25 +535,25 @@ export class ImageToolTune {
|
|
|
529
535
|
blockEl.style.maxWidth = '';
|
|
530
536
|
}
|
|
531
537
|
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
538
|
+
if(imageEl) {
|
|
539
|
+
|
|
540
|
+
//remove image width and height
|
|
541
|
+
imageEl.style.width = '';
|
|
542
|
+
imageEl.style.height = '';
|
|
537
543
|
|
|
538
544
|
//remove image left and top
|
|
539
|
-
var
|
|
540
|
-
if
|
|
541
|
-
|
|
542
|
-
|
|
545
|
+
var image = imageEl.getElementsByTagName( 'img' )[ 0 ];
|
|
546
|
+
if(image)
|
|
547
|
+
{
|
|
548
|
+
image.style.left = '';
|
|
549
|
+
image.style.top = '';
|
|
543
550
|
|
|
544
551
|
//remove image width and height
|
|
545
|
-
|
|
546
|
-
|
|
552
|
+
image.style.width = '';
|
|
553
|
+
image.style.height = '';
|
|
547
554
|
}
|
|
548
555
|
}
|
|
549
556
|
|
|
550
|
-
|
|
551
557
|
blockContent.classList.remove( 'isCropping' );
|
|
552
558
|
|
|
553
559
|
|
|
@@ -580,13 +586,9 @@ export class ImageToolTune {
|
|
|
580
586
|
* */
|
|
581
587
|
resize( blockContent ) {
|
|
582
588
|
|
|
583
|
-
|
|
584
589
|
const resizable = document.createElement( 'div' );
|
|
585
590
|
resizable.classList.add( 'resizable' );
|
|
586
591
|
|
|
587
|
-
// console.log( resizable );
|
|
588
|
-
|
|
589
|
-
|
|
590
592
|
const resizers = document.createElement( 'div' );
|
|
591
593
|
resizers.classList.add( 'resizers' );
|
|
592
594
|
|
|
@@ -816,7 +818,6 @@ export class ImageToolTune {
|
|
|
816
818
|
this.wrapper = this.createView();
|
|
817
819
|
}
|
|
818
820
|
|
|
819
|
-
|
|
820
821
|
this.apply( blockContent );
|
|
821
822
|
|
|
822
823
|
|