Skip to content

Commit 58f111f

Browse files
committed
fix: resolve caption bug, fix css and bump to 2.10.2
1 parent c8236e5 commit 58f111f

File tree

5 files changed

+52
-15
lines changed

5 files changed

+52
-15
lines changed

dev/index.html

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,24 +7,43 @@
77
</head>
88
<body>
99
<div id="editorjs"></div>
10-
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest/dist/editor.js"></script>
10+
<script src="https://cdn.jsdelivr.net/npm/@editorjs/editorjs@latest"></script>
1111
<script type="module">
12-
import ImageTool from "../src/index.ts"
12+
import ImageTool from "../src/index.ts";
1313
const editor = new EditorJS({
1414
holder: "editorjs",
15+
data: {
16+
time: 1700475383740,
17+
blocks: [
18+
{
19+
id: "hZAjSnqYMX",
20+
type: "image",
21+
data: {
22+
file: {
23+
url: "https://images.unsplash.com/photo-1607604276583-eef5d076aa5f?q=80&w=1974&auto=format&fit=crop&ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D",
24+
},
25+
withBorder: false,
26+
withBackground: false,
27+
stretched: false,
28+
caption: "kimitsu no yayiba",
29+
},
30+
},
31+
],
32+
},
33+
1534
tools: {
16-
code: {
35+
image: {
1736
class: ImageTool,
1837
config: {
1938
endpoints: {
2039
byFile: "http://localhost:8008/uploadFile",
2140
byUrl: "http://localhost:8008/fetchUrl",
2241
},
2342
features: {
24-
// caption: false,
43+
caption: "optional",
2544
border: false,
2645
background: false,
27-
stretch: false,
46+
stretch: true,
2847
},
2948
},
3049
},

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@editorjs/image",
3-
"version": "2.10.1",
3+
"version": "2.10.2",
44
"keywords": [
55
"codex editor",
66
"image",

src/index.css

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
border-radius: 3px;
88
overflow: hidden;
99
margin-bottom: 10px;
10+
padding-bottom: 0;
1011

1112
&-picture {
1213
max-width: 100%;
@@ -44,7 +45,11 @@
4445
}
4546

4647
&__caption {
47-
display: none;
48+
visibility: hidden;
49+
position: absolute;
50+
bottom: 0;
51+
left: 0;
52+
margin-bottom: 10px;
4853

4954
&[contentEditable="true"][data-placeholder]::before {
5055
position: absolute !important;
@@ -112,10 +117,6 @@
112117
display: none;
113118
}
114119
}
115-
116-
.cdx-button {
117-
display: none;
118-
}
119120
}
120121

121122
/**
@@ -151,8 +152,10 @@
151152

152153
&--caption {
153154
^&__caption {
154-
display: block;
155+
visibility: visible;
155156
}
157+
158+
padding-bottom: 50px
156159
}
157160
}
158161

src/index.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,10 @@ export default class ImageTool implements BlockTool {
367367

368368
this.setTune(tune as keyof ImageToolData, value);
369369
});
370+
371+
if (data.caption) {
372+
this.setTune('caption', true);
373+
}
370374
}
371375

372376
/**
@@ -419,11 +423,13 @@ export default class ImageTool implements BlockTool {
419423
* @param tuneName - tune that has been clicked
420424
*/
421425
private tuneToggled(tuneName: keyof ImageToolData): void {
422-
// inverse tune state
423-
this.setTune(tuneName, !(this._data[tuneName] as boolean));
426+
// check the tune state
427+
const currentState = this.ui.isTuneActive(tuneName);
428+
429+
this.setTune(tuneName, !currentState);
424430

425431
// reset caption on toggle
426-
if (tuneName === 'caption' && !this._data[tuneName]) {
432+
if (tuneName === 'caption' && !this.ui.isTuneActive(tuneName)) {
427433
this._data.caption = '';
428434
this.ui.fillCaption('');
429435
}

src/ui.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,15 @@ export default class Ui {
161161
this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${tuneName}`, status);
162162
}
163163

164+
/**
165+
* Utility to determine if a tune is currently active
166+
* @param tuneName - one of available tunes {@link Tunes.tunes}
167+
* @returns - true for active and vice versa
168+
*/
169+
public isTuneActive(tuneName: string): boolean {
170+
return this.nodes.wrapper.classList.contains(`${this.CSS.wrapper}--${tuneName}`);
171+
}
172+
164173
/**
165174
* Renders tool UI
166175
* @param toolData - saved tool data

0 commit comments

Comments
 (0)