editorjs-image 1.0.7 → 1.0.9

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 +49 -18
  3. package/src/index.js +70 -75
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "editorjs-image",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "Image tool plugin for Editor.js",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
package/src/index.css CHANGED
@@ -1,17 +1,32 @@
1
1
  .cdx-image-tool-tune--floatLeft.ce-block__content,
2
- .cdx-image-tool-tune--floatRight.ce-block__content {
3
- min-height: 20px;
4
- }
2
+ .cdx-image-tool-tune--floatRight.ce-block__content { min-height: 20px; }
5
3
 
6
4
  .cdx-image-tool-tune--floatLeft.ce-block__content .image-tool__image,
7
- .cdx-image-tool-tune--floatRight.ce-block__content .image-tool__image {
8
- margin-top: 20px;
9
- }
10
-
11
-
12
- .cdx-image-tool-tune--center .cdx-block {
13
- margin: auto;
14
- }
5
+ .cdx-image-tool-tune--floatRight.ce-block__content .image-tool__image { margin-top: 40px; }
6
+ .cdx-image-tool-tune--floatLeft.ce-block__content .image-tool__image { margin-left: 20px; }
7
+ .cdx-image-tool-tune--floatRight.ce-block__content .image-tool__image { margin-right: 20px; }
8
+
9
+ .cdx-image-tool-tune--floatLeft.ce-block__content .cdx-input,
10
+ .cdx-image-tool-tune--floatRight.ce-block__content .cdx-input { width: calc(100% - 20px); }
11
+ .cdx-image-tool-tune--floatLeft.ce-block__content .cdx-input { margin-left: 20px; }
12
+ .cdx-image-tool-tune--floatRight.ce-block__content .cdx-input { margin-right: 20px; }
13
+
14
+ .cdx-image-tool-tune--floatLeft .cdx-block,
15
+ .cdx-image-tool-tune--center .cdx-block,
16
+ .cdx-image-tool-tune--floatRight .cdx-block,
17
+ .cdx-image-tool-tune--floatLeft .image-tool__image,
18
+ .cdx-image-tool-tune--center .image-tool__image,
19
+ .cdx-image-tool-tune--floatRight .image-tool__image,
20
+ .cdx-image-tool-tune--floatLeft .cdx-block,
21
+ .cdx-image-tool-tune--center .cdx-block,
22
+ .cdx-image-tool-tune--floatRight .cdx-block
23
+ {
24
+ display: flex;
25
+ flex-direction: column;
26
+ align-items: center;
27
+ }
28
+
29
+ .cdx-image-tool-tune--center .cdx-block { margin: auto; }
15
30
 
16
31
  .cdx-image-tool-tune--floatLeft .cdx-block {
17
32
  float: left;
@@ -23,19 +38,38 @@
23
38
  margin-left: 10px;
24
39
  }
25
40
 
41
+
42
+
43
+ .cdx-image-tool-tune--sizeSmall img {
44
+ max-height: 200px !important;
45
+ object-fit:cover;
46
+ }
47
+
26
48
  .cdx-image-tool-tune--sizeSmall .cdx-block {
27
- width: 50% !important;
49
+ max-width: 25% !important;
28
50
  }
29
51
 
52
+ .cdx-image-tool-tune--sizeMiddle img {
53
+ max-height: 300px !important;
54
+ object-fit:cover;
55
+ }
30
56
  .cdx-image-tool-tune--sizeMiddle .cdx-block {
31
- width: 70% !important;
57
+ max-width: 50% !important;
32
58
  }
33
59
 
60
+ .cdx-image-tool-tune--sizeLarge img {
61
+ max-height: 400px !important;
62
+ object-fit:cover;
63
+ }
34
64
  .cdx-image-tool-tune--sizeLarge .cdx-block {
35
- width: 100% !important;
65
+ max-width: 75% !important;
36
66
  }
37
67
 
38
-
68
+ .codex-editor.read-only .cdx-input.image-tool__caption:empty,
69
+ .read-only > .codex-editor .cdx-input.image-tool__caption:empty
70
+ {
71
+ display:none;
72
+ }
39
73
 
40
74
  .cdx-image-tool-tune--resize .cdx-block {
41
75
  position: relative;
@@ -84,9 +118,6 @@
84
118
  cursor: nwse-resize;
85
119
  }
86
120
 
87
-
88
-
89
-
90
121
  .cdx-image-tool-tune--crop:hover,
91
122
  .cdx-image-tool-tune--crop.isCropping,
92
123
  .cdx-image-tool-tune--resize:hover {
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: '50%',
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: '70%',
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: '100%',
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 ( !this.api.readOnly ) {
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
- image.appendChild( cropBtn );
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
- cropBtn.addEventListener( 'click', e => {
493
- //remove crop button
494
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].removeChild( cropBtn );
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
- blockContent.getElementsByClassName( 'image-tool__image' )[ 0 ].appendChild( cropBtn );
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
- const resizable = document.createElement( 'div' );
584
- resizable.classList.add( 'resizable' );
580
+ const resizable = document.createElement( 'div' );
581
+ resizable.classList.add( 'resizable' );
585
582
 
586
- console.log( resizable );
583
+ // console.log( resizable );
587
584
 
588
585
 
589
- const resizers = document.createElement( 'div' );
590
- resizers.classList.add( 'resizers' );
586
+ const resizers = document.createElement( 'div' );
587
+ resizers.classList.add( 'resizers' );
591
588
 
592
- const resizerTopLeft = document.createElement( 'div' );
593
- resizerTopLeft.classList.add( 'resizer', 'top-left' );
594
- resizerTopLeft.addEventListener( 'mousedown', e => {
595
- this.resizeClick( blockContent.getElementsByClassName( 'cdx-block' )[ 0 ], resizerTopLeft, e );
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
- const resizerTopRight = document.createElement( 'div' );
600
- resizerTopRight.classList.add( 'resizer', 'top-right' );
601
- resizerTopRight.addEventListener( 'mousedown', e => {
602
- this.resizeClick( blockContent.getElementsByClassName( 'cdx-block' )[ 0 ], resizerTopRight, e );
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
- const resizerBottomLeft = document.createElement( 'div' );
607
- resizerBottomLeft.classList.add( 'resizer', 'bottom-left' );
608
- resizerBottomLeft.addEventListener( 'mousedown', e => {
609
- this.resizeClick( blockContent.getElementsByClassName( 'cdx-block' )[ 0 ], resizerBottomLeft, e );
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
- const resizerBottomRight = document.createElement( 'div' );
613
- resizerBottomRight.classList.add( 'resizer', 'bottom-right' );
614
- resizerBottomRight.addEventListener( 'mousedown', e => {
615
- this.resizeClick( blockContent.getElementsByClassName( 'cdx-block' )[ 0 ], resizerBottomRight, e );
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
- resizers.appendChild( resizerTopLeft );
619
- resizers.appendChild( resizerTopRight );
620
- resizers.appendChild( resizerBottomLeft );
621
- resizers.appendChild( resizerBottomRight );
622
- resizable.appendChild( resizers );
623
- blockContent.getElementsByClassName( 'cdx-block' )[ 0 ].appendChild( resizable );
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
+ }