editorjs-image 1.0.12 → 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.
Files changed (3) hide show
  1. package/package.json +1 -1
  2. package/src/index.css +2 -20
  3. package/src/index.js +102 -88
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "editorjs-image",
3
- "version": "1.0.12",
3
+ "version": "1.0.14",
4
4
  "description": "Image tool plugin for Editor.js",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.css CHANGED
@@ -39,7 +39,7 @@
39
39
  }
40
40
 
41
41
 
42
- .cdx-image-tool-tune--sizeSmall .image-tool__caption { max-height: 200px; }
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
@@ -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,19 @@ export class ImageToolTune {
383
390
  if ( this.api.readOnly.isEnabled ) return;
384
391
 
385
392
  this.uncrop( blockContent );
393
+ const image = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].getElementsByTagName( 'img' )[ 0 ];
394
+ blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].classList.add( 'isCropping' );
395
+ this.cropperInterface = new Cropper( image, {
396
+ crop( event ) {
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 );
403
+ },
404
+ } );
386
405
 
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
406
 
403
407
  //append save crop button
404
408
  const cropSaveBtn = document.createElement( 'div' );
@@ -408,6 +412,10 @@ export class ImageToolTune {
408
412
 
409
413
  cropSaveBtn.addEventListener( 'click', e => {
410
414
 
415
+ // console.log( this.cropperInterface.getCropBoxData() );
416
+ // console.log( this.cropperInterface.getImageData() );
417
+ // console.log( this.cropperInterface.getCanvasData() );
418
+
411
419
  this.data.cropperFrameHeight = this.cropperInterface.getCropBoxData().height;
412
420
  this.data.cropperFrameWidth = this.cropperInterface.getCropBoxData().width;
413
421
  this.data.cropperFrameLeft = this.cropperInterface.getCanvasData().left - this.cropperInterface.getCropBoxData().left;
@@ -416,7 +424,9 @@ export class ImageToolTune {
416
424
  this.data.cropperImageWidth = this.cropperInterface.getImageData().width;
417
425
 
418
426
  this.applyCrop( blockContent );
419
- });
427
+
428
+ }
429
+ );
420
430
 
421
431
  blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].appendChild( cropSaveBtn );
422
432
 
@@ -431,31 +441,33 @@ export class ImageToolTune {
431
441
  if ( this.api.readOnly.isEnabled ) return;
432
442
 
433
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
+ }
434
464
 
435
- const image = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].getElementsByTagName( 'img' )[ 0 ];
436
-
437
-
438
-
439
-
440
- blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].style.minWidth = this.data.cropperFrameWidth + 'px';
441
- blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].style.maxWidth = this.data.cropperFrameWidth + 'px';
442
-
443
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].style.width = this.data.cropperFrameWidth + 'px';
444
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].style.height = this.data.cropperFrameHeight + 'px';
445
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].getElementsByTagName( 'img' )[ 0 ].style.left = this.data.cropperFrameLeft + 'px';
446
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].getElementsByTagName( 'img' )[ 0 ].style.top = this.data.cropperFrameTop + 'px';
447
-
448
- image.style.width = this.data.cropperImageWidth + 'px';
449
- image.style.height = this.data.cropperImageHeight + 'px';
450
-
451
-
452
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].getElementsByTagName( 'img' )[ 0 ].classList.add( 'isCropped' );
453
- blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].classList.remove( 'isCropping' );
454
-
465
+ blockEl.classList.remove( 'isCropping' );
455
466
 
456
- const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
457
- if ( cropSaveBtn ) {
458
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].removeChild( cropSaveBtn );
467
+ const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
468
+ if ( cropSaveBtn ) {
469
+ blockImg.removeChild( cropSaveBtn );
470
+ }
459
471
  }
460
472
 
461
473
 
@@ -474,14 +486,18 @@ export class ImageToolTune {
474
486
  cropBtn.classList.add( 'crop-btn', 'btn-crop-action' );
475
487
  cropBtn.innerHTML = 'Crop';
476
488
 
477
- cropBtn.addEventListener( 'click', e => {
478
- //remove crop button
479
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].removeChild( cropBtn );
480
- this.appendCrop( blockContent );
481
- }
482
- );
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
+ );
483
498
 
484
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].appendChild( cropBtn );
499
+ imageEl.appendChild( cropBtn );
500
+ }
485
501
 
486
502
  blockContent.classList.remove( 'isCropping' );
487
503
 
@@ -494,68 +510,71 @@ export class ImageToolTune {
494
510
 
495
511
  if ( this.api.readOnly.isEnabled ) return;
496
512
 
513
+ var imageEl = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
514
+
497
515
  //remove crop and save button
498
516
  const cropSaveBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
499
- if ( cropSaveBtn ) {
500
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].removeChild( cropSaveBtn );
517
+ if ( cropSaveBtn && imageEl) {
518
+ imageEl.removeChild( cropSaveBtn );
501
519
  }
502
520
 
503
-
504
521
  //remove crop button
505
522
  const cropBtn = blockContent.getElementsByClassName( 'btn-crop-action' )[ 0 ];
506
- if ( cropBtn ) {
507
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].removeChild( cropBtn );
523
+ if ( cropBtn && imageEl) {
524
+ imageEl.removeChild( cropBtn );
508
525
  }
509
526
 
510
527
  //remove isCropped class
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' );
511
532
 
512
- var img = blockContent.getElementsByClassName( 'cdx-block' )[ 0 ]?.getElementsByTagName( 'img' )[ 0 ] || undefined;
513
- if(img) img.classList.remove( 'isCropped' );
514
-
515
- //remove isCropping class
516
- blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].classList.remove( 'isCropping' );
517
-
518
- //remove min and max width
519
- blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].style.minWidth = '';
520
- blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].style.maxWidth = '';
533
+ //remove isCropping class
534
+ blockEl.classList.remove( 'isCropping' );
521
535
 
522
- //remove image width and height
523
- var imgBlockEl = blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ];
524
- if (imgBlockEl) {
525
- imgBlockEl.style.width = '';
526
- imgBlockEl.style.height = '';
536
+ //remove min and max width
537
+ blockEl.style.minWidth = '';
538
+ blockEl.style.maxWidth = '';
527
539
  }
528
540
 
529
- var imgEl = imgBlockEl?.getElementsByTagName( 'img' )[ 0 ] || undefined;
530
- if(imgEl) {
541
+ if(imageEl) {
542
+
543
+ //remove image width and height
544
+ imageEl.style.width = '';
545
+ imageEl.style.height = '';
531
546
 
532
547
  //remove image left and top
533
- imgEl.style.left = '';
534
- imgEl.style.top = '';
548
+ var image = imageEl.getElementsByTagName( 'img' )[ 0 ];
549
+ if(image)
550
+ {
551
+ image.style.left = '';
552
+ image.style.top = '';
535
553
 
536
- //remove image width and height
537
- imgEl.style.width = '';
538
- imgEl.style.height = '';
554
+ //remove image width and height
555
+ image.style.width = '';
556
+ image.style.height = '';
557
+ }
539
558
  }
540
559
 
541
-
542
560
  blockContent.classList.remove( 'isCropping' );
543
561
 
562
+
563
+
544
564
  //remove cropper interface
545
-
546
565
  if ( this.cropperInterface ) {
547
566
  this.cropperInterface.destroy();
567
+ }
548
568
 
549
- //remove crop data
550
- this.data.cropperFrameHeight = 0;
551
- this.data.cropperFrameWidth = 0;
552
- this.data.cropperFrameLeft = 0;
553
- this.data.cropperFrameTop = 0;
554
- this.data.cropperImageHeight = 0;
555
- this.data.cropperImageWidth = 0;
569
+ //remove crop data
570
+ this.data.cropperFrameHeight = 0;
571
+ this.data.cropperFrameWidth = 0;
572
+ this.data.cropperFrameLeft = 0;
573
+ this.data.cropperFrameTop = 0;
574
+ this.data.cropperImageHeight = 0;
575
+ this.data.cropperImageWidth = 0;
556
576
 
557
- this.block.dispatchChange();
558
- }
577
+ // this.block.dispatchChange();
559
578
  }
560
579
 
561
580
 
@@ -573,8 +592,6 @@ export class ImageToolTune {
573
592
  const resizable = document.createElement( 'div' );
574
593
  resizable.classList.add( 'resizable' );
575
594
 
576
- // console.log( resizable );
577
-
578
595
  const resizers = document.createElement( 'div' );
579
596
  resizers.classList.add( 'resizers' );
580
597
 
@@ -710,8 +727,6 @@ export class ImageToolTune {
710
727
  button.classList.remove( this.CSS.buttonActive );
711
728
  } );
712
729
 
713
- blockContent.classList.remove( this.CSS.wrapper );
714
-
715
730
  //remove isFloatLeft class
716
731
  blockContent.classList.remove( this.CSS.isFloatLeft );
717
732
 
@@ -806,7 +821,6 @@ export class ImageToolTune {
806
821
  this.wrapper = this.createView();
807
822
  }
808
823
 
809
- blockContent.classList.add( this.CSS.wrapper );
810
824
 
811
825
  this.apply( blockContent );
812
826