Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add-close-icon #229

Open
wants to merge 28 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
node_modules/*
npm-debug.log
.idea/
.DS_Store
dist
.DS_Store
1 change: 0 additions & 1 deletion .npmignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea/
dev/
src/
.babelrc
.eslintrc
Expand Down
41 changes: 41 additions & 0 deletions dist/bundle.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/image",
"version": "2.8.1",
"name": "@personalai/editorjs-image",
"version": "2.8.24",
"keywords": [
"codex editor",
"tool",
Expand All @@ -10,7 +10,7 @@
],
"description": "Image Tool for Editor.js",
"license": "MIT",
"repository": "https://github.com/editor-js/image",
"repository": "https://github.com/personal-ai/editorjs-image-fork.git",
"main": "./dist/bundle.js",
"scripts": {
"build": "webpack --mode production",
Expand Down
3 changes: 3 additions & 0 deletions src/assets/x-circle.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
72 changes: 69 additions & 3 deletions src/ui.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IconPicture } from '@codexteam/icons';
import { make } from './utils/dom';
import IconClose from './assets/x-circle.svg';

/**
* Class for working with UI:
Expand All @@ -24,7 +25,9 @@ export default class Ui {
wrapper: make('div', [this.CSS.baseClass, this.CSS.wrapper]),
imageContainer: make('div', [ this.CSS.imageContainer ]),
fileButton: this.createFileButton(),
imageWrapper: make('div', [this.CSS.imageWrapper, 'tw-relative', 'tw-w-24', 'tw-h-24']),
imageEl: undefined,
imageDeleteIcon: undefined,
imagePreloader: make('div', this.CSS.imagePreloader),
caption: make('div', [this.CSS.input, this.CSS.caption], {
contentEditable: !this.readOnly,
Expand All @@ -43,6 +46,7 @@ export default class Ui {
*/
this.nodes.caption.dataset.placeholder = this.config.captionPlaceholder;
this.nodes.imageContainer.appendChild(this.nodes.imagePreloader);
this.nodes.imageContainer.appendChild(this.nodes.imageWrapper);
this.nodes.wrapper.appendChild(this.nodes.imageContainer);
this.nodes.wrapper.appendChild(this.nodes.caption);
this.nodes.wrapper.appendChild(this.nodes.fileButton);
Expand All @@ -66,6 +70,7 @@ export default class Ui {
wrapper: 'image-tool',
imageContainer: 'image-tool__image',
imagePreloader: 'image-tool__image-preloader',
imageWrapper: 'image-tool__image-wrapper',
imageEl: 'image-tool__image-picture',
caption: 'image-tool__caption',
};
Expand Down Expand Up @@ -103,6 +108,16 @@ export default class Ui {
return this.nodes.wrapper;
}

/**
* convert pixels to rem
*
* @param {number} size - size of px
* @returns {string}
*/
pxToRem(size) {
return `${(size / 16) * 1}rem`;
};

/**
* Creates upload-file button
*
Expand Down Expand Up @@ -189,12 +204,63 @@ export default class Ui {
eventName = 'loadeddata';
}

/**
* compose iconWrapper
*/
const iconWrapper = document.createElement('div');

iconWrapper.style.strokeWidth = '0px';

iconWrapper.style.position = 'absolute';
iconWrapper.style.right = this.pxToRem(0);
iconWrapper.style.top = this.pxToRem(0);
iconWrapper.style.cursor = 'pointer';
iconWrapper.addEventListener('click', () => {
this.api.blocks.delete(this.api.blocks.getCurrentBlockIndex());
});
iconWrapper.addEventListener('mouseover', () => {
const svgWrapper = iconWrapper.firstChild;

svgWrapper.style.fill = '#585A68';
});
iconWrapper.addEventListener('mouseout', () => {
const svgWrapper = iconWrapper.firstChild;

svgWrapper.style.fill = '#7E8194';
});
iconWrapper.innerHTML = IconClose;
const svgWrapper = iconWrapper.firstChild;

svgWrapper.style.fill = '#7E8194';
this.nodes.imageDeleteIcon = iconWrapper;
this.nodes.imageDeleteIcon.style.display = 'none';

/**
* Compose tag with defined attributes
*
* @type {Element}
*/
this.nodes.imageEl = make(tag, this.CSS.imageEl, attributes);
this.nodes.imageEl = make(tag, [this.CSS.imageEl, 'tw-w-24', 'tw-h-24'], attributes);
this.nodes.imageEl.style.width = this.pxToRem(96);
this.nodes.imageEl.style.height = this.pxToRem(96);

/**
* add imageWrapper hover event listener
*/
this.nodes.imageWrapper.addEventListener('mouseover', (event) => {
event.preventDefault();
if (!this.nodes.imageDeleteIcon) {
return;
}
this.nodes.imageDeleteIcon.style.display = 'block';
});
this.nodes.imageWrapper.addEventListener('mouseout', (event) => {
event.preventDefault();
if (!this.nodes.imageDeleteIcon) {
return;
}
this.nodes.imageDeleteIcon.style.display = 'none';
});

/**
* Add load event listener
Expand All @@ -210,7 +276,8 @@ export default class Ui {
}
});

this.nodes.imageContainer.appendChild(this.nodes.imageEl);
this.nodes.imageWrapper.appendChild(this.nodes.imageDeleteIcon);
this.nodes.imageWrapper.appendChild(this.nodes.imageEl);
}

/**
Expand Down Expand Up @@ -250,4 +317,3 @@ export default class Ui {
this.nodes.wrapper.classList.toggle(`${this.CSS.wrapper}--${tuneName}`, status);
}
}