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

Chore/popover refactoring #2249

Merged
merged 50 commits into from
Feb 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
8f9809b
Add new popover class
TatianaFomina Jan 7, 2023
0592461
Add flipper
TatianaFomina Jan 7, 2023
a9cb883
confirmation
TatianaFomina Jan 10, 2023
2c73b2c
confirmation
TatianaFomina Jan 10, 2023
e687006
Add confirmation support
TatianaFomina Jan 12, 2023
28c7bb5
Add search
TatianaFomina Jan 14, 2023
f2928db
Add toggle group support and update popover tests
TatianaFomina Jan 14, 2023
77ab1b8
Add custom content support
TatianaFomina Jan 18, 2023
54d5f69
Fix scroll issue
TatianaFomina Jan 18, 2023
0f49e85
Add mobile version
TatianaFomina Jan 18, 2023
a0160a4
Integration
TatianaFomina Jan 18, 2023
ab4a9fe
Fix animation
TatianaFomina Jan 23, 2023
4659331
Cleanup
TatianaFomina Jan 23, 2023
ef17b42
Fix popover position for narrow mode
TatianaFomina Jan 23, 2023
578137e
Fix tests
TatianaFomina Jan 23, 2023
2b42f78
Update version and changelog
TatianaFomina Jan 23, 2023
acdd257
Rename css classes
TatianaFomina Jan 24, 2023
2f5f277
Move files
TatianaFomina Jan 24, 2023
a08052f
Stop using PopoverItem from outside of popover context
TatianaFomina Jan 26, 2023
bd8f53c
Fix jsdoc
TatianaFomina Jan 26, 2023
a0c5895
Move error animation to popover item
TatianaFomina Jan 26, 2023
4769075
Update css variables
TatianaFomina Jan 26, 2023
cfc9767
Update docs/CHANGELOG.md
TatianaFomina Jan 26, 2023
e8a413c
Merge branch 'next' into chore/popover-refactoring
TatianaFomina Jan 26, 2023
9d60665
Update src/components/block-tunes/block-tune-move-down.ts
TatianaFomina Jan 26, 2023
ddbe7ca
Update src/components/block-tunes/block-tune-move-up.ts
TatianaFomina Jan 26, 2023
555db89
Fixes
TatianaFomina Jan 30, 2023
f320185
Fix imports
TatianaFomina Jan 30, 2023
4b94a51
Fix toolbox close event
TatianaFomina Jan 30, 2023
72c0bff
Move search-input file
TatianaFomina Jan 30, 2023
2afe9f5
Fix comment
TatianaFomina Jan 30, 2023
0811c43
Rename method
TatianaFomina Jan 30, 2023
61de389
Cleanup
TatianaFomina Jan 30, 2023
a30c6b6
Remove onFlip callback from popover item
TatianaFomina Jan 31, 2023
9012195
Rename
TatianaFomina Jan 31, 2023
c4c212c
Fix removing event listener
TatianaFomina Jan 31, 2023
0dccf9d
Move popover animations to popover.css file
TatianaFomina Jan 31, 2023
9be9cb9
Cleanup styles
TatianaFomina Jan 31, 2023
23e532c
Fix jsdoc
TatianaFomina Feb 7, 2023
c196864
Fix confirmation chains
TatianaFomina Feb 10, 2023
eabee56
Close toolbox oly when it's open
TatianaFomina Feb 10, 2023
69061ea
Change activation error animation
TatianaFomina Feb 10, 2023
eee3b25
Merge branch 'next' into chore/popover-refactoring
TatianaFomina Feb 10, 2023
6850acc
Update version and changelog
TatianaFomina Feb 10, 2023
5c1727f
Fix overlay
TatianaFomina Feb 10, 2023
cb989a9
Update icon border-radius on mobile
TatianaFomina Feb 10, 2023
f7a8181
Disable item text select
TatianaFomina Feb 10, 2023
82a71fc
Update changelog
TatianaFomina Feb 10, 2023
e2e3519
Update yarn.lock
TatianaFomina Feb 10, 2023
2a59a7b
Add rc postfix to version
TatianaFomina Feb 10, 2023
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
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

### 2.27.0

- `Refactoring` — Popover class refactored.
- `Improvement` — *Toolbox* — Number of `close()` method calls optimized.

### 2.26.5

- `Fix` — *Types* — Remove unnecessary import that creates a dependency on the `cypress`.
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@editorjs/editorjs",
"version": "2.26.5",
"version": "2.27.0-rc.0",
"description": "Editor.js — Native JS, based on API and Open Source",
"main": "dist/editor.js",
"types": "./types/index.d.ts",
Expand Down
20 changes: 3 additions & 17 deletions src/components/block-tunes/block-tune-move-down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
*/

import { API, BlockTune } from '../../../types';
import Popover from '../utils/popover';
import { IconChevronDown } from '@codexteam/icons';
import { TunesMenuConfig } from '../../../types/tools';

Expand Down Expand Up @@ -49,34 +48,21 @@ export default class MoveDownTune implements BlockTune {
return {
icon: IconChevronDown,
title: this.api.i18n.t('Move down'),
onActivate: (item, event): void => this.handleClick(event),
onActivate: (): void => this.handleClick(),
name: 'move-down',
};
}

/**
* Handle clicks on 'move down' button
*
* @param event - click event
*/
public handleClick(event: MouseEvent): void {
public handleClick(): void {
const currentBlockIndex = this.api.blocks.getCurrentBlockIndex();
const nextBlock = this.api.blocks.getBlockByIndex(currentBlockIndex + 1);

// If Block is last do nothing
if (!nextBlock) {
const button = (event.target as HTMLElement)
.closest('.' + Popover.CSS.item)
.querySelector('.' + Popover.CSS.itemIcon);

button.classList.add(this.CSS.animation);

window.setTimeout(() => {
button.classList.remove(this.CSS.animation);
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
}, 500);

return;
throw new Error('Unable to move Block down since it is already the last');
}

const nextBlockElement = nextBlock.holder;
Expand Down
20 changes: 3 additions & 17 deletions src/components/block-tunes/block-tune-move-up.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
* @copyright <CodeX Team> 2018
*/
import { API, BlockTune } from '../../../types';
import Popover from '../../components/utils/popover';
import { IconChevronUp } from '@codexteam/icons';
import { TunesMenuConfig } from '../../../types/tools';

Expand Down Expand Up @@ -47,34 +46,21 @@ export default class MoveUpTune implements BlockTune {
return {
icon: IconChevronUp,
title: this.api.i18n.t('Move up'),
onActivate: (item, e): void => this.handleClick(e),
onActivate: (): void => this.handleClick(),
name: 'move-up',
};
}

/**
* Move current block up
*
* @param {MouseEvent} event - click event
*/
public handleClick(event: MouseEvent): void {
public handleClick(): void {
const currentBlockIndex = this.api.blocks.getCurrentBlockIndex();
const currentBlock = this.api.blocks.getBlockByIndex(currentBlockIndex);
const previousBlock = this.api.blocks.getBlockByIndex(currentBlockIndex - 1);

if (currentBlockIndex === 0 || !currentBlock || !previousBlock) {
const button = (event.target as HTMLElement)
.closest('.' + Popover.CSS.item)
.querySelector('.' + Popover.CSS.itemIcon);

button.classList.add(this.CSS.animation);

window.setTimeout(() => {
button.classList.remove(this.CSS.animation);
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
}, 500);

return;
throw new Error('Unable to move Block up since it is already the first');
}

const currentBlockElement = currentBlock.holder;
Expand Down
33 changes: 17 additions & 16 deletions src/components/modules/toolbar/blockSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ import Module from '../../__module';
import $ from '../../dom';
import SelectionUtils from '../../selection';
import Block from '../../block';
import Popover, { PopoverEvent } from '../../utils/popover';
import I18n from '../../i18n';
import { I18nInternalNS } from '../../i18n/namespace-internal';
import Flipper from '../../flipper';
import { TunesMenuConfigItem } from '../../../../types/tools';
import { resolveAliases } from '../../utils/resolve-aliases';
import Popover, { PopoverEvent } from '../../utils/popover';

/**
* HTML Elements that used for BlockSettings
Expand Down Expand Up @@ -67,13 +67,14 @@ export default class BlockSettings extends Module<BlockSettingsNodes> {
*/
private popover: Popover | undefined;


/**
* Panel with block settings with 2 sections:
* - Tool's Settings
* - Default Settings [Move, Remove, etc]
*/
public make(): void {
this.nodes.wrapper = $.make('div');
this.nodes.wrapper = $.make('div', [ this.CSS.settings ]);
}

/**
Expand Down Expand Up @@ -110,19 +111,19 @@ export default class BlockSettings extends Module<BlockSettingsNodes> {

/** Tell to subscribers that block settings is opened */
this.eventsDispatcher.emit(this.events.opened);

this.popover = new Popover({
className: this.CSS.settings,
searchable: true,
filterLabel: I18n.ui(I18nInternalNS.ui.popover, 'Filter'),
nothingFoundLabel: I18n.ui(I18nInternalNS.ui.popover, 'Nothing found'),
items: tunesItems.map(tune => this.resolveTuneAliases(tune)),
customContent: customHtmlTunesContainer,
customContentFlippableItems: this.getControls(customHtmlTunesContainer),
scopeElement: this.Editor.API.methods.ui.nodes.redactor,
messages: {
nothingFound: I18n.ui(I18nInternalNS.ui.popover, 'Nothing found'),
search: I18n.ui(I18nInternalNS.ui.popover, 'Filter'),
},
});
this.popover.on(PopoverEvent.OverlayClicked, this.onOverlayClicked);
this.popover.on(PopoverEvent.Close, () => this.close());

this.popover.on(PopoverEvent.Close, this.onPopoverClose);

this.nodes.wrapper.append(this.popover.getElement());

Expand Down Expand Up @@ -166,13 +167,20 @@ export default class BlockSettings extends Module<BlockSettingsNodes> {
this.eventsDispatcher.emit(this.events.closed);

if (this.popover) {
this.popover.off(PopoverEvent.OverlayClicked, this.onOverlayClicked);
this.popover.off(PopoverEvent.Close, this.onPopoverClose);
this.popover.destroy();
this.popover.getElement().remove();
this.popover = null;
}
}

/**
* Handles popover close event
*/
private onPopoverClose = (): void => {
this.close();
};

/**
* Returns list of buttons and inputs inside specified container
*
Expand All @@ -188,13 +196,6 @@ export default class BlockSettings extends Module<BlockSettingsNodes> {
return Array.from(controls);
}

/**
* Handles overlay click
*/
private onOverlayClicked = (): void => {
this.close();
};

/**
* Resolves aliases in tunes menu items
*
Expand Down
13 changes: 10 additions & 3 deletions src/components/modules/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,8 +228,13 @@ export default class Toolbar extends Module<ToolbarNodes> {
/**
* Close Toolbox when we move toolbar
*/
this.toolboxInstance.close();
this.Editor.BlockSettings.close();
if (this.toolboxInstance.opened) {
this.toolboxInstance.close();
}

if (this.Editor.BlockSettings.opened) {
this.Editor.BlockSettings.close();
}

/**
* If no one Block selected as a Current
Expand Down Expand Up @@ -468,7 +473,9 @@ export default class Toolbar extends Module<ToolbarNodes> {

this.settingsTogglerClicked();

this.toolboxInstance.close();
if (this.toolboxInstance.opened) {
this.toolboxInstance.close();
}

this.tooltip.hide(true);
}, true);
Expand Down
19 changes: 11 additions & 8 deletions src/components/ui/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,21 +123,23 @@ export default class Toolbox extends EventsDispatcher<ToolboxEvent> {
public make(): Element {
this.popover = new Popover({
scopeElement: this.api.ui.nodes.redactor,
className: Toolbox.CSS.toolbox,
searchable: true,
filterLabel: this.i18nLabels.filter,
nothingFoundLabel: this.i18nLabels.nothingFound,
messages: {
nothingFound: this.i18nLabels.nothingFound,
search: this.i18nLabels.filter,
},
items: this.toolboxItemsToBeDisplayed,
});

this.popover.on(PopoverEvent.OverlayClicked, this.onOverlayClicked);
this.popover.on(PopoverEvent.Close, this.onPopoverClose);

/**
* Enable tools shortcuts
*/
this.enableShortcuts();

this.nodes.toolbox = this.popover.getElement();
this.nodes.toolbox.classList.add(Toolbox.CSS.toolbox);

return this.nodes.toolbox;
}
Expand All @@ -161,7 +163,7 @@ export default class Toolbox extends EventsDispatcher<ToolboxEvent> {
}

this.removeAllShortcuts();
this.popover?.off(PopoverEvent.OverlayClicked, this.onOverlayClicked);
this.popover?.off(PopoverEvent.Close, this.onPopoverClose);
}

/**
Expand Down Expand Up @@ -208,10 +210,11 @@ export default class Toolbox extends EventsDispatcher<ToolboxEvent> {
}

/**
* Handles overlay click
* Handles popover close event
*/
private onOverlayClicked = (): void => {
this.close();
private onPopoverClose = (): void => {
this.opened = false;
this.emit(ToolboxEvent.Closed);
};

/**
Expand Down
Loading