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

feat(ui): the toolbox became vertical #2014

Merged
merged 36 commits into from
Apr 25, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
11c0405
the popover component, vertical toolbox
neSpecc Jan 13, 2022
015f409
toolbox position improved
neSpecc Jan 13, 2022
229b9a2
popover width improved
neSpecc Jan 13, 2022
9a15cf5
always show the plus button
neSpecc Feb 2, 2022
3a3403e
search field added
neSpecc Feb 5, 2022
06a5766
Merge branch 'next' into feat/vertical-toolbox
neSpecc Feb 10, 2022
a020ca5
search input in popover
neSpecc Mar 2, 2022
a005b07
trying to create mobile toolbox
neSpecc Mar 12, 2022
e7b2698
Merge branch 'next' into feat/vertical-toolbox
neSpecc Mar 13, 2022
2bc1427
Merge branch 'next' into feat/vertical-toolbox
neSpecc Apr 5, 2022
c29d244
feat(toolbox): popover adapted for mobile devices (#2004)
TatianaFomina Apr 7, 2022
f947d36
Vertical toolbox fixes (#2017)
TatianaFomina Apr 14, 2022
5e00998
Extend element interface to avoid ts errors
TatianaFomina Apr 16, 2022
f3e253f
Do not subscribe to block hovered if mobile
TatianaFomina Apr 16, 2022
262baee
Add unsubscribing from overlay click event
TatianaFomina Apr 16, 2022
0c006d6
Rename isMobile to isMobileScreen
TatianaFomina Apr 16, 2022
adb8b77
Cleanup
TatianaFomina Apr 16, 2022
ae2ac42
fix: popover opening direction (#2022)
TatianaFomina Apr 17, 2022
d44b9a9
Update src/components/flipper.ts
TatianaFomina Apr 17, 2022
83a8c86
Fixes
TatianaFomina Apr 17, 2022
054f23d
Merge branch 'next' into feat/vertical-toolbox
TatianaFomina Apr 17, 2022
6a31e72
Merge branch 'feat/vertical-toolbox' of https://github.com/codex-team…
TatianaFomina Apr 17, 2022
2bc4c80
Fix test
TatianaFomina Apr 17, 2022
b43a22a
Clear search on popover hide
TatianaFomina Apr 18, 2022
7c2cb80
Fix popover width
TatianaFomina Apr 18, 2022
9c2d665
Fix for tests
TatianaFomina Apr 18, 2022
ede63a4
Update todos
TatianaFomina Apr 18, 2022
b5dd459
Linter fixes
TatianaFomina Apr 19, 2022
061b2c9
rm todo about beforeInsert
neSpecc Apr 19, 2022
ca7b2ab
i18n for search labels done
neSpecc Apr 19, 2022
cc0530c
rm methods for hiding/showing of +
neSpecc Apr 19, 2022
c36eca2
some code style update
neSpecc Apr 19, 2022
3a98e9b
Merge branch 'next' into feat/vertical-toolbox
neSpecc Apr 22, 2022
04376f9
Update CHANGELOG.md
neSpecc Apr 22, 2022
25b06c0
make the list items a little bit compact
neSpecc Apr 22, 2022
70fd937
fix z-index issue caused by block-appearing animation
neSpecc Apr 22, 2022
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
7 changes: 5 additions & 2 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Changelog

### 2.23.3
### 2.24.0

- `New` — *UI* — The Toolbox became vertical 🥳
- `Improvement` — *UI* — the Plus button will always be shown (previously, it appears only for empty blocks)
- `Improvement` — *Dev Example Page* - Server added to allow opening example page on other devices in network.
- `Fix` - `UI` - the Toolbar won't move on hover at mobile viewports. Resolves [#1972](https://github.com/codex-team/editor.js/issues/1972)
- `Fix` — `OnChange` event invocation after block insertion. [#1997](https://github.com/codex-team/editor.js/issues/1997)

### 2.23.2
Expand Down Expand Up @@ -435,4 +438,4 @@ See a whole [Changelog](/docs/)
- `New` New [Editor.js PHP](http://github.com/codex-team/codex.editor.backend) — example of server-side implementation with HTML purifying and data validation.
- `Improvements` - Improvements of Toolbar's position calculation.
- `Improvements` — Improved zero-configuration initialization.
- and many little improvements.
- and many little improvements.
4 changes: 3 additions & 1 deletion example/example-i18n.html
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,9 @@
},
"toolbar": {
"toolbox": {
"Add": "Добавить"
"Add": "Добавить",
"Filter": "Поиск",
"Noting found": "Ничего не найдено"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions src/assets/search.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
75 changes: 34 additions & 41 deletions src/components/flipper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ export interface FlipperOptions {
items?: HTMLElement[];

/**
* Defines arrows usage. By default Flipper leafs items also via RIGHT/LEFT.
*
* true by default
*
* Pass 'false' if you don't need this behaviour
* (for example, Inline Toolbar should be closed by arrows,
* because it means caret moving with selection clearing)
* Optional callback for button click
*/
allowArrows?: boolean;
activateCallback?: (item: HTMLElement) => void;

/**
* Optional callback for button click
* List of keys allowed for handling.
* Can include codes of the following keys:
* - Tab
* - Enter
* - Arrow up
* - Arrow down
* - Arrow right
* - Arrow left
* If not specified all keys are enabled
*/
activateCallback?: (item: HTMLElement) => void;
allowedKeys?: number[];
}

/**
Expand All @@ -53,11 +55,9 @@ export default class Flipper {
private activated = false;

/**
* Flag that allows arrows usage to flip items
*
* @type {boolean}
* List codes of the keys allowed for handling
*/
private readonly allowArrows: boolean = true;
private readonly allowedKeys: number[];

/**
* Call back for button click/enter
Expand All @@ -68,9 +68,9 @@ export default class Flipper {
* @param {FlipperOptions} options - different constructing settings
*/
constructor(options: FlipperOptions) {
this.allowArrows = _.isBoolean(options.allowArrows) ? options.allowArrows : true;
this.iterator = new DomIterator(options.items, options.focusedItemClass);
this.activateCallback = options.activateCallback;
this.allowedKeys = options.allowedKeys || Flipper.usedKeys;
}

/**
Expand Down Expand Up @@ -120,15 +120,6 @@ export default class Flipper {
document.removeEventListener('keydown', this.onKeyDown);
}

/**
* Return current focused button
*
* @returns {HTMLElement|null}
*/
public get currentItem(): HTMLElement|null {
return this.iterator.currentItem;
}

/**
* Focus first item
*/
Expand All @@ -142,13 +133,22 @@ export default class Flipper {
*/
public flipLeft(): void {
this.iterator.previous();
this.flipCallback();
}

/**
* Focuses next flipper iterator item
*/
public flipRight(): void {
this.iterator.next();
this.flipCallback();
}

/**
* Return true if some button is focused
*/
public hasFocus(): boolean {
return !!this.iterator.currentItem;
}

/**
Expand Down Expand Up @@ -206,23 +206,7 @@ export default class Flipper {
* @returns {boolean}
*/
private isEventReadyForHandling(event: KeyboardEvent): boolean {
const handlingKeyCodeList = [
_.keyCodes.TAB,
_.keyCodes.ENTER,
];

const isCurrentItemIsFocusedInput = this.iterator.currentItem == document.activeElement;

if (this.allowArrows && !isCurrentItemIsFocusedInput) {
handlingKeyCodeList.push(
_.keyCodes.LEFT,
_.keyCodes.RIGHT,
_.keyCodes.UP,
_.keyCodes.DOWN
);
}

return this.activated && handlingKeyCodeList.indexOf(event.keyCode) !== -1;
return this.activated && this.allowedKeys.includes(event.keyCode);
}

/**
Expand Down Expand Up @@ -266,4 +250,13 @@ export default class Flipper {
event.preventDefault();
event.stopPropagation();
}

/**
* Fired after flipping in any direction
*/
private flipCallback(): void {
if (this.iterator.currentItem) {
this.iterator.currentItem.scrollIntoViewIfNeeded();
}
}
}
4 changes: 3 additions & 1 deletion src/components/i18n/locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@
},
"toolbar": {
"toolbox": {
"Add": ""
"Add": "",
"Filter": "",
"Noting found": ""
}
}
},
Expand Down
3 changes: 1 addition & 2 deletions src/components/modules/saver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ export default class Saver extends Module {
chainData = [];

try {

blocks.forEach((block: Block) => {
chainData.push(this.getSavedData(block));
});
Expand All @@ -46,7 +45,7 @@ export default class Saver extends Module {
return this.makeOutput(sanitizedData);
} catch (e) {
_.logLabeled(`Saving failed due to the Error %o`, 'error', e);
}
}
}

/**
Expand Down
Loading