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

issue-705: Leaf BlockSettings and InlineTools via keyboard #723

Merged
merged 51 commits into from
May 24, 2019
Merged
Show file tree
Hide file tree
Changes from 42 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
84689b5
Do not start multi-block selection on UI elements (#662)
gohabereg Apr 4, 2019
d2cb37f
Add link to issue
gohabereg Apr 5, 2019
7d1ce59
Merge branch 'release/2.12' of https://github.com/codex-team/codex.ed…
Apr 5, 2019
a750894
Fix loss of pointer (#666)
gohabereg Apr 5, 2019
4073724
Update shortcuts module (#685)
khaydarov Apr 6, 2019
a146c2e
Remove margin top for inline-link icon (#690)
talyguryn Apr 6, 2019
f0d9548
Pull fresh tools
talyguryn Apr 6, 2019
d5bc6fa
Remove changelog contents from readme (#700)
kabachook Apr 8, 2019
57b5a09
Merge branch 'master' of https://github.com/codex-team/codex.editor i…
gohabereg Apr 10, 2019
f554945
#665 API to open and close inline-toolbar (#711)
tanmayv Apr 11, 2019
53df2d5
leaf buttons: initial
khaydarov Apr 12, 2019
ee9321a
leaf inline toolbar buttons
khaydarov Apr 12, 2019
5f71c6f
Allow holderId work with ref on dom element (#710)
dimensi Apr 15, 2019
00622cd
leaf inline tools and drop index after click
khaydarov Apr 26, 2019
b2d0acc
leaf toolbox and clear active button after activation
khaydarov Apr 26, 2019
72c0987
debugging blockSettings
khaydarov Apr 26, 2019
5f0d242
Activating Open Collective (#736)
monkeywithacupcake Apr 27, 2019
800657e
Do not install editor.js as dev-dependency (#731)
davidsneighbour Apr 27, 2019
2de4318
Move codex-notifier to dependencies for typescript declarations (#728)
gohabereg Apr 27, 2019
27cbaa5
Close inline toolbar after creating new link by pressing ENTER (#722)
tanmayv Apr 27, 2019
ca58f74
Link Logo Image to homepage (#738)
goldensunliu Apr 27, 2019
3befe95
Update README.md (#744)
neSpecc Apr 27, 2019
f518a67
Config minHeight option that allows to customize bottom zone (#745)
neSpecc Apr 28, 2019
1cd6149
issue-739: allow Block's editable element selection (#747)
khaydarov Apr 28, 2019
0ab6a29
Fix typo in example paragraph (#749)
stephan281094 Apr 29, 2019
4816fb4
minor release
neSpecc Apr 29, 2019
f25c497
Merge branch 'release/2.13' into issue-705-block-actions-from-keyboard
khaydarov May 19, 2019
b730ed8
done
khaydarov May 19, 2019
e99b21c
requested changes
khaydarov May 20, 2019
1ca9b64
production build
khaydarov May 20, 2019
c5f1ba3
Merge branch 'release/2.14' into issue-705-block-actions-from-keyboard
khaydarov May 20, 2019
ffcf176
update package.json
khaydarov May 20, 2019
9ebc7a4
some improvements
khaydarov May 20, 2019
9d2a009
ready for testing
khaydarov May 20, 2019
e37b3bf
Merge branch 'release/2.14' into issue-705-block-actions-from-keyboard
khaydarov May 22, 2019
0f68cfd
update
khaydarov May 22, 2019
2bac1a6
ready
khaydarov May 22, 2019
3d3e7f6
requested changes
khaydarov May 23, 2019
14a3b30
updates
khaydarov May 23, 2019
7ac2e42
use setToBlock instead of focus
khaydarov May 23, 2019
1b176a5
active -> focused
khaydarov May 23, 2019
5a734b3
update
khaydarov May 23, 2019
eb32095
refactor types
khaydarov May 23, 2019
460bf4b
fix inline tools flipping
khaydarov May 23, 2019
202f5eb
inhancements
khaydarov May 24, 2019
369ce68
rm check for focus at the handleShowingEvent
neSpecc May 24, 2019
f4dd0c9
fix IT closing after second enter
neSpecc May 24, 2019
092281e
add animation to settings buttons
khaydarov May 24, 2019
a7d5123
Click animation
neSpecc May 24, 2019
e64e948
Add changelog
neSpecc May 24, 2019
031d687
do not patch version
neSpecc May 24, 2019
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
10 changes: 5 additions & 5 deletions dist/editor.js

Large diffs are not rendered by default.

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.14.0",
"version": "2.14.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Не нужно поднимать версию тут

"description": "Editor.js — Native JS, based on API and Open Source",
"main": "dist/editor.js",
"types": "./types/index.d.ts",
Expand Down
74 changes: 74 additions & 0 deletions src/components/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -520,6 +520,80 @@ export default class Dom {
}

/**
* Leafs nodes inside the target list from active element
*
* @param {HTMLElement[]} nodeList - target list of nodes
* @param {number} activeIndex — index of active node. By default it must be -1
* @param {string} direction - leaf direction. Can be 'left' or 'right'
* @param {string} activeCSSClass - css class that will be added
*
* @return {Number} index of active node
*/
public static leafNodesAndReturnIndex(nodeList, activeIndex, direction, activeCSSClass): number {
/**
* If activeButtonIndex === -1 then we have no chosen Tool in Toolbox
*/
if (activeIndex === -1) {
/**
* Normalize "previous" Tool index depending on direction.
* We need to do this to highlight "first" Tool correctly
*
* Order of Tools: [0] [1] ... [n - 1]
* [0 = n] because of: n % n = 0 % n
*
* Direction 'right': for [0] the [n - 1] is a previous index
* [n - 1] -> [0]
*
* Direction 'left': for [n - 1] the [0] is a previous index
* [n - 1] <- [0]
*
* @type {number}
*/
activeIndex = direction === 'right' ? -1 : 0;
} else {
/**
* If we have chosen Tool then remove highlighting
*/
(nodeList[activeIndex] as HTMLElement).classList.remove(activeCSSClass);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Нужно задать типы аргументов и не придется так писать

}

/**
* Count index for next Tool
*/
if (direction === 'right') {
/**
* If we go right then choose next (+1) Tool
* @type {number}
*/
activeIndex = (activeIndex + 1) % nodeList.length;
} else {
/**
* If we go left then choose previous (-1) Tool
* Before counting module we need to add length before because of "The JavaScript Modulo Bug"
* @type {number}
*/
activeIndex = (nodeList.length + activeIndex - 1) % nodeList.length;
}

if (Dom.isNativeInput(nodeList[activeIndex])) {
/**
* Focus input
*/
nodeList[activeIndex].focus();
}

/**
* Highlight new chosen Tool
*/
(nodeList[activeIndex] as HTMLElement).classList.add(activeCSSClass);

/**
* Return Active index
*/
return activeIndex;
}

/*
* Helper for get holder from {string} or return HTMLElement
* @param element
*/
Expand Down
108 changes: 93 additions & 15 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
*/
import Module from '../__module';
import _ from '../utils';
import SelectionUtils from '../selection';

export default class BlockEvents extends Module {

/**
* All keydowns on Block
* @param {KeyboardEvent} event - keydown
Expand Down Expand Up @@ -62,7 +64,12 @@ export default class BlockEvents extends Module {
return;
}

this.Editor.Toolbar.close();
/**
* Close Toolbar on any keypress except TAB, because TAB leafs Tools
*/
if (event.keyCode !== _.keyCodes.TAB) {
this.Editor.Toolbar.close();
}

const cmdKey = event.ctrlKey || event.metaKey;
const altKey = event.altKey;
Expand Down Expand Up @@ -110,6 +117,10 @@ export default class BlockEvents extends Module {

const {currentBlock} = this.Editor.BlockManager;

if (!currentBlock) {
return;
}

/** Prevent Default behaviour */
event.preventDefault();
event.stopPropagation();
Expand All @@ -119,31 +130,77 @@ export default class BlockEvents extends Module {
direction = shiftKey ? 'left' : 'right';

/**
* Don't show Plus and Toolbox near not-inital Tools
* For empty Blocks we show Plus button via Toobox only for initial Blocks
*/
if (!this.Editor.Tools.isInitial(currentBlock.tool)) {
return;
}

if (currentBlock.isEmpty) {
if (this.Editor.Tools.isInitial(currentBlock.tool) && currentBlock.isEmpty) {
/**
* Work with Toolbox
* ------------------
*
* If Toolbox is not open, then just open it and show plus button
* Next Tab press will leaf Toolbox Tools
*/
if (!this.Editor.Toolbar.opened) {
this.Editor.Toolbar.open(false , false);
this.Editor.Toolbar.plusButton.show();
} else {
this.Editor.Toolbox.leaf(direction);
}

this.Editor.Toolbox.open();
}
} else if (!currentBlock.isEmpty && !SelectionUtils.isCollapsed) {
/**
* Work with Inline Tools
* -----------------------
*
* If InlineToolbar is not open, just open it and focus first button
* Next Tab press will leaf InlineToolbar Tools
*/
if (this.Editor.InlineToolbar.opened) {
this.Editor.InlineToolbar.leaf(direction);
}
} else {
/**
* Open Toolbar and show BlockSettings
*/
if (!this.Editor.Toolbar.opened) {
this.Editor.BlockManager.currentBlock.focused = true;
this.Editor.Toolbar.open(true, false);
this.Editor.Toolbar.plusButton.hide();
}

if (this.Editor.Toolbox.opened) {
this.Editor.Toolbox.leaf(direction);
/**
* Work with Block Tunes
* ----------------------
*
* If BlockSettings is not open, then open BlockSettings
* Next Tab press will leaf Settings Buttons
*/
if (!this.Editor.BlockSettings.opened) {
this.Editor.BlockSettings.open();
}

this.Editor.BlockSettings.leaf(direction);
}
}

/**
* Escape pressed
* @param event
* If some of Toolbar components are opened, then close it otherwise close Toolbar
*
* @param {Event} event
*/
public escapePressed(event): void { }
public escapePressed(event): void {
if (this.Editor.Toolbox.opened) {
this.Editor.Toolbox.close();
} else if (this.Editor.BlockSettings.opened) {
this.Editor.BlockSettings.close();
} else if (this.Editor.InlineToolbar.opened) {
this.Editor.InlineToolbar.close();
} else {
this.Editor.Toolbar.close();
}
}

/**
* Add drop target styles
Expand Down Expand Up @@ -231,18 +288,32 @@ export default class BlockEvents extends Module {
* Don't handle Enter keydowns when Tool sets enableLineBreaks to true.
* Uses for Tools like <code> where line breaks should be handled by default behaviour.
*/
if (tool && tool[this.Editor.Tools.apiSettings.IS_ENABLED_LINE_BREAKS]) {
if (tool
&& tool[this.Editor.Tools.apiSettings.IS_ENABLED_LINE_BREAKS]
&& !this.Editor.BlockSettings.opened
&& !this.Editor.InlineToolbar.opened) {
return;
}

if (this.Editor.Toolbox.opened && this.Editor.Toolbox.getActiveTool) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();

this.Editor.Toolbox.toolButtonActivate(event, this.Editor.Toolbox.getActiveTool);
return;
}

if (this.Editor.InlineToolbar.opened && this.Editor.InlineToolbar.focusedButton) {
event.preventDefault();
event.stopPropagation();
event.stopImmediatePropagation();

(this.Editor.InlineToolbar.focusedButton as HTMLElement).click();
this.Editor.InlineToolbar.dropFocusedButtonIndex();
return;
}

/**
* Allow to create linebreaks by Shift+Enter
*/
Expand Down Expand Up @@ -441,8 +512,15 @@ export default class BlockEvents extends Module {
*/
private needToolbarClosing(event) {
const toolboxItemSelected = (event.keyCode === _.keyCodes.ENTER && this.Editor.Toolbox.opened),
flippingToolboxItems = event.keyCode === _.keyCodes.TAB;
blockSettingsItemSelected = (event.keyCode === _.keyCodes.ENTER && this.Editor.BlockSettings.opened),
flippingToolbarItems = event.keyCode === _.keyCodes.TAB;

return !(event.shiftKey || flippingToolboxItems || toolboxItemSelected);
/**
* Do not close Toolbar in cases:
* 1. ShiftKey pressed (or combination with shiftKey)
* 2. When Toolbar is opened and Tab leafs its Tools
* 3. When Toolbar's component is opened and some its item selected
*/
return !(event.shiftKey || flippingToolbarItems || toolboxItemSelected || blockSettingsItemSelected);
}
}
68 changes: 68 additions & 0 deletions src/components/modules/toolbar/blockSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export default class BlockSettings extends Module {
defaultSettings: 'ce-settings__default-zone',

button: 'ce-settings__button',

focusedButton : 'ce-settings__button--focused',
};
}

Expand All @@ -58,6 +60,16 @@ export default class BlockSettings extends Module {
defaultSettings: null,
};

/**
* List of buttons
*/
private buttons: Node[] = [];

/**
* Index of active button
*/
private focusedButtonIndex: number = -1;

/**
* Panel with block settings with 2 sections:
* - Tool's Settings
Expand Down Expand Up @@ -106,8 +118,64 @@ export default class BlockSettings extends Module {

/** Tell to subscribers that block settings is closed */
this.Editor.Events.emit(this.events.closed);

/** Clear cached buttons */
this.buttons = [];

/** Clear focus on active button */
this.focusedButtonIndex = -1;

}

/**
* Returns Tools Settings and Default Settings
* @return {HTMLElement[]}
*/
public get blockTunesButtons(): Node[] {
/**
* Return from cache
* if exists
*/
if (this.buttons.length !== 0) {
return this.buttons;
}

const toolSettings = this.nodes.toolSettings.querySelectorAll(`.${this.Editor.StylesAPI.classes.settingsButton}`);
const defaultSettings = this.nodes.defaultSettings.querySelectorAll(`.${BlockSettings.CSS.button}`);

toolSettings.forEach((item, index) => {
this.buttons.push(item);
if (item.classList.contains(BlockSettings.CSS.focusedButton)) {
this.focusedButtonIndex = index;
}
});

defaultSettings.forEach((item) => {
this.buttons.push(item);
});

return this.buttons;
}

/**
* Leaf Block Tunes
* @param {string} direction
*/
public leaf(direction: string = 'right'): void {
this.focusedButtonIndex = $.leafNodesAndReturnIndex(this.blockTunesButtons, this.focusedButtonIndex, direction, BlockSettings.CSS.focusedButton);
}

/**
* Returns active button HTML element
* @return {HTMLElement}
*/
public get focusedButton(): HTMLElement {
if (this.focusedButtonIndex === -1) {
return null;
}

return (this.buttons[this.focusedButtonIndex] as HTMLElement);
}
/**
* Add Tool's settings
*/
Expand Down
Loading