editorjs-image 1.0.12 → 1.0.13
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.js +64 -55
package/package.json
CHANGED
package/src/index.js
CHANGED
|
@@ -271,6 +271,9 @@ export class ImageToolTune {
|
|
|
271
271
|
this.apply( blockContent );
|
|
272
272
|
|
|
273
273
|
this.block.dispatchChange();
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
|
|
274
277
|
}
|
|
275
278
|
|
|
276
279
|
|
|
@@ -345,6 +348,10 @@ export class ImageToolTune {
|
|
|
345
348
|
blockContent.classList.remove( this.CSS.isCrop );
|
|
346
349
|
this.uncrop( blockContent );
|
|
347
350
|
}
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
|
|
348
355
|
}
|
|
349
356
|
|
|
350
357
|
|
|
@@ -383,22 +390,20 @@ export class ImageToolTune {
|
|
|
383
390
|
if ( this.api.readOnly.isEnabled ) return;
|
|
384
391
|
|
|
385
392
|
this.uncrop( blockContent );
|
|
393
|
+
var imageBlock = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ];
|
|
394
|
+
const image = imageBlock.getElementsByTagName( 'img' )[ 0 ];
|
|
395
|
+
imageBlock.classList.add( 'isCropping' );
|
|
396
|
+
this.cropperInterface = new Cropper( image, {
|
|
397
|
+
crop( event ) {
|
|
398
|
+
// console.log( event.detail.x );
|
|
399
|
+
// console.log( event.detail.y );
|
|
400
|
+
// console.log( event.detail.width );
|
|
401
|
+
// console.log( event.detail.height );
|
|
402
|
+
// console.log( event.detail.scaleX );
|
|
403
|
+
// console.log( event.detail.scaleY );
|
|
404
|
+
},
|
|
405
|
+
} );
|
|
386
406
|
|
|
387
|
-
var element = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ];
|
|
388
|
-
const image = element.getElementsByTagName( 'img' )[ 0 ];
|
|
389
|
-
if(image && element) {
|
|
390
|
-
element.classList.add( 'isCropping' );
|
|
391
|
-
this.cropperInterface = new Cropper( image, {
|
|
392
|
-
crop( event ) {
|
|
393
|
-
// console.log( event.detail.x );
|
|
394
|
-
// console.log( event.detail.y );
|
|
395
|
-
// console.log( event.detail.width );
|
|
396
|
-
// console.log( event.detail.height );
|
|
397
|
-
// console.log( event.detail.scaleX );
|
|
398
|
-
// console.log( event.detail.scaleY );
|
|
399
|
-
},
|
|
400
|
-
} );
|
|
401
|
-
}
|
|
402
407
|
|
|
403
408
|
//append save crop button
|
|
404
409
|
const cropSaveBtn = document.createElement( 'div' );
|
|
@@ -416,7 +421,9 @@ export class ImageToolTune {
|
|
|
416
421
|
this.data.cropperImageWidth = this.cropperInterface.getImageData().width;
|
|
417
422
|
|
|
418
423
|
this.applyCrop( blockContent );
|
|
419
|
-
|
|
424
|
+
|
|
425
|
+
}
|
|
426
|
+
);
|
|
420
427
|
|
|
421
428
|
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].appendChild( cropSaveBtn );
|
|
422
429
|
|
|
@@ -495,67 +502,70 @@ export class ImageToolTune {
|
|
|
495
502
|
if ( this.api.readOnly.isEnabled ) return;
|
|
496
503
|
|
|
497
504
|
//remove crop and save button
|
|
498
|
-
const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ]
|
|
505
|
+
const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ] ?? undefined
|
|
499
506
|
if ( cropSaveBtn ) {
|
|
500
507
|
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].removeChild( cropSaveBtn );
|
|
501
508
|
}
|
|
502
509
|
|
|
503
510
|
|
|
504
511
|
//remove crop button
|
|
505
|
-
const cropBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ]
|
|
512
|
+
const cropBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ] ?? undefined
|
|
506
513
|
if ( cropBtn ) {
|
|
507
514
|
blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].removeChild( cropBtn );
|
|
508
515
|
}
|
|
509
516
|
|
|
510
517
|
//remove isCropped class
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
var imgBlockEl = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
|
|
524
|
-
if (imgBlockEl) {
|
|
525
|
-
imgBlockEl.style.width = '';
|
|
526
|
-
imgBlockEl.style.height = '';
|
|
518
|
+
var blockEl = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ] ?? undefined
|
|
519
|
+
if (blockEl) {
|
|
520
|
+
|
|
521
|
+
var img = blockEl.getElementsByTagName( 'img' )[ 0 ] || undefined;
|
|
522
|
+
if (img) img.classList.remove( 'isCropped' );
|
|
523
|
+
|
|
524
|
+
//remove isCropping class
|
|
525
|
+
blockEl.classList.remove( 'isCropping' );
|
|
526
|
+
|
|
527
|
+
//remove min and max width
|
|
528
|
+
blockEl.style.minWidth = '';
|
|
529
|
+
blockEl.style.maxWidth = '';
|
|
527
530
|
}
|
|
528
531
|
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
//remove image left and top
|
|
533
|
-
imgEl.style.left = '';
|
|
534
|
-
imgEl.style.top = '';
|
|
535
|
-
|
|
536
|
-
//remove image width and height
|
|
532
|
+
//remove image width and height
|
|
533
|
+
var imgEl = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ] ?? undefined;
|
|
534
|
+
if (imgEl) {
|
|
537
535
|
imgEl.style.width = '';
|
|
538
536
|
imgEl.style.height = '';
|
|
537
|
+
|
|
538
|
+
//remove image left and top
|
|
539
|
+
var img = imgEl.getElementsByTagName( 'img' )[ 0 ] ?? undefined;
|
|
540
|
+
if (img) {
|
|
541
|
+
img.style.left = '';
|
|
542
|
+
img.style.top = '';
|
|
543
|
+
|
|
544
|
+
//remove image width and height
|
|
545
|
+
img.style.width = '';
|
|
546
|
+
img.style.height = '';
|
|
547
|
+
}
|
|
539
548
|
}
|
|
540
549
|
|
|
541
550
|
|
|
542
551
|
blockContent.classList.remove( 'isCropping' );
|
|
543
552
|
|
|
553
|
+
|
|
554
|
+
|
|
544
555
|
//remove cropper interface
|
|
545
|
-
|
|
546
556
|
if ( this.cropperInterface ) {
|
|
547
557
|
this.cropperInterface.destroy();
|
|
558
|
+
}
|
|
548
559
|
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
560
|
+
//remove crop data
|
|
561
|
+
this.data.cropperFrameHeight = 0;
|
|
562
|
+
this.data.cropperFrameWidth = 0;
|
|
563
|
+
this.data.cropperFrameLeft = 0;
|
|
564
|
+
this.data.cropperFrameTop = 0;
|
|
565
|
+
this.data.cropperImageHeight = 0;
|
|
566
|
+
this.data.cropperImageWidth = 0;
|
|
556
567
|
|
|
557
|
-
|
|
558
|
-
}
|
|
568
|
+
// this.block.dispatchChange();
|
|
559
569
|
}
|
|
560
570
|
|
|
561
571
|
|
|
@@ -570,11 +580,13 @@ export class ImageToolTune {
|
|
|
570
580
|
* */
|
|
571
581
|
resize( blockContent ) {
|
|
572
582
|
|
|
583
|
+
|
|
573
584
|
const resizable = document.createElement( 'div' );
|
|
574
585
|
resizable.classList.add( 'resizable' );
|
|
575
586
|
|
|
576
587
|
// console.log( resizable );
|
|
577
588
|
|
|
589
|
+
|
|
578
590
|
const resizers = document.createElement( 'div' );
|
|
579
591
|
resizers.classList.add( 'resizers' );
|
|
580
592
|
|
|
@@ -710,8 +722,6 @@ export class ImageToolTune {
|
|
|
710
722
|
button.classList.remove( this.CSS.buttonActive );
|
|
711
723
|
} );
|
|
712
724
|
|
|
713
|
-
blockContent.classList.remove( this.CSS.wrapper );
|
|
714
|
-
|
|
715
725
|
//remove isFloatLeft class
|
|
716
726
|
blockContent.classList.remove( this.CSS.isFloatLeft );
|
|
717
727
|
|
|
@@ -806,7 +816,6 @@ export class ImageToolTune {
|
|
|
806
816
|
this.wrapper = this.createView();
|
|
807
817
|
}
|
|
808
818
|
|
|
809
|
-
blockContent.classList.add( this.CSS.wrapper );
|
|
810
819
|
|
|
811
820
|
this.apply( blockContent );
|
|
812
821
|
|