Skip to content

Commit b1b582b

Browse files
authored
feat(icons): codex icons package is used instead of svg sprite (codex-team#2173)
* chore(icons): migrating to the coded icon pack * conversion toolbar * inline toolbar, part 1 * inline-link tool has the new icons * added a test for creating a link by Enter keydown in link input * rm last icons, svg sprite, loaders * rollback .ce-settings styles * Update CHANGELOG.md * Update settings.json
1 parent f0f8f8f commit b1b582b

39 files changed

+1863
-3105
lines changed

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"cSpell.words": [
33
"Behaviour",
44
"cacheable",
5+
"childs",
56
"codexteam",
67
"colspan",
78
"contenteditable",
@@ -11,6 +12,7 @@
1112
"editorjs",
1213
"entrypoints",
1314
"Flippable",
15+
"GRAMMARLY",
1416
"hsablonniere",
1517
"intellij",
1618
"keydowns",

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
- `New`*UI* — Block Tunes became vertical just like the Toolbox 🤩
77
- `New`*Block Tunes API* — Now `render()` method of a Block Tune can return config with just icon, label and callback instead of custom HTML. This impovement is a key to the new straightforward way of configuring tune's appearance in Block Tunes menu.
88
- `New`*Tools API* — As well as `render()` in `Tunes API`, Tool's `renderSettings()` now also supports new configuration format.
9+
- `New`*UI* — Meet the new icons from [CodeX Icons](https://github.com/codex-team/icons) pack 🛍 💝
910
- `Deprecated`*Styles API* — CSS classes `.cdx-settings-button` and `.cdx-settings-button--active` are not recommended to use. Consider configuring your block settings with new JSON API instead.
1011
- `Fix` — Wrong element not highlighted anymore when popover opened.
1112
- `Fix` — When Tunes Menu open keydown events can not be handled inside plugins.

package.json

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,14 @@
1313
],
1414
"scripts": {
1515
"clear": "rimraf dist && mkdirp dist",
16-
"build": "yarn clear && yarn svg && yarn build:webpack:prod",
17-
"build:dev": "yarn clear && yarn svg && yarn build:webpack:dev",
16+
"build": "yarn clear && yarn build:webpack:prod",
17+
"build:dev": "yarn clear && yarn build:webpack:dev",
1818
"build:webpack:dev": "webpack --mode development --progress --display-error-details --display-entrypoints --watch",
1919
"build:webpack:prod": "webpack --mode production",
2020
"lint": "eslint src/ --ext .ts && yarn lint:tests",
2121
"lint:errors": "eslint src/ --ext .ts --quiet",
2222
"lint:fix": "eslint src/ --ext .ts --fix",
2323
"lint:tests": "eslint test/ --ext .ts",
24-
"svg": "svg-sprite-generate -d src/assets/ -o dist/sprite.svg",
2524
"ci:pull_paragraph": "git submodule update --init ./src/tools/paragraph",
2625
"pull_tools": "git submodule update --init --recursive",
2726
"_tools:checkout": "git submodule foreach \"git checkout master || git checkout main\"",
@@ -73,7 +72,6 @@
7372
"eslint-plugin-chai-friendly": "^0.7.2",
7473
"eslint-plugin-cypress": "^2.12.1",
7574
"extract-text-webpack-plugin": "^3.0.2",
76-
"html-janitor": "^2.0.4",
7775
"license-webpack-plugin": "^2.1.4",
7876
"mkdirp": "^1.0.4",
7977
"postcss-apply": "^0.12.0",
@@ -82,10 +80,8 @@
8280
"postcss-nested": "^4.1.2",
8381
"postcss-nested-ancestors": "^2.0.0",
8482
"postcss-preset-env": "^6.6.0",
85-
"raw-loader": "^4.0.1",
8683
"rimraf": "^3.0.2",
8784
"stylelint": "^13.3.3",
88-
"svg-sprite-generator": "^0.0.7",
8985
"terser-webpack-plugin": "^2.3.6",
9086
"ts-loader": "^7.0.1",
9187
"tslint": "^6.1.1",
@@ -98,8 +94,10 @@
9894
"url": "https://opencollective.com/editorjs"
9995
},
10096
"dependencies": {
97+
"@codexteam/icons": "^0.0.4",
10198
"codex-notifier": "^1.1.2",
10299
"codex-tooltip": "^1.0.5",
100+
"html-janitor": "^2.0.4",
103101
"nanoid": "^3.1.22"
104102
}
105103
}

src/assets/arrow-down.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assets/arrow-up.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assets/bold.svg

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/assets/cross.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assets/dots.svg

Lines changed: 0 additions & 10 deletions
This file was deleted.

src/assets/italic.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assets/link.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assets/plus.svg

Lines changed: 0 additions & 6 deletions
This file was deleted.

src/assets/sad-face.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assets/search.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assets/toggler-down.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/assets/unlink.svg

Lines changed: 0 additions & 3 deletions
This file was deleted.

src/components/block-tunes/block-tune-delete.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* @copyright <CodeX Team> 2018
55
*/
66
import { API, BlockTune, PopoverItem } from '../../../types';
7-
import $ from '../dom';
7+
import { IconCross } from '@codexteam/icons';
88

99
/**
1010
*
@@ -36,8 +36,7 @@ export default class DeleteTune implements BlockTune {
3636
*/
3737
public render(): PopoverItem {
3838
return {
39-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
40-
icon: $.svg('cross', 14, 14).outerHTML,
39+
icon: IconCross,
4140
label: this.api.i18n.t('Delete'),
4241
name: 'delete',
4342
confirmation: {

src/components/block-tunes/block-tune-move-down.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
* @copyright <CodeX Team> 2018
55
*/
66

7-
import $ from '../dom';
87
import { API, BlockTune, PopoverItem } from '../../../types';
98
import Popover from '../utils/popover';
9+
import { IconChevronDown } from '@codexteam/icons';
10+
1011

1112
/**
1213
*
@@ -45,8 +46,7 @@ export default class MoveDownTune implements BlockTune {
4546
*/
4647
public render(): PopoverItem {
4748
return {
48-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
49-
icon: $.svg('arrow-down', 14, 14).outerHTML,
49+
icon: IconChevronDown,
5050
label: this.api.i18n.t('Move down'),
5151
onActivate: (item, event): void => this.handleClick(event),
5252
name: 'move-down',

src/components/block-tunes/block-tune-move-up.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
* @classdesc Editor's default tune that moves up selected block
44
* @copyright <CodeX Team> 2018
55
*/
6-
import $ from '../dom';
76
import { API, BlockTune, PopoverItem } from '../../../types';
87
import Popover from '../../components/utils/popover';
8+
import { IconChevronUp } from '@codexteam/icons';
99

1010
/**
1111
*
@@ -44,8 +44,7 @@ export default class MoveUpTune implements BlockTune {
4444
*/
4545
public render(): PopoverItem {
4646
return {
47-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
48-
icon: $.svg('arrow-up', 14, 14).outerHTML,
47+
icon: IconChevronUp,
4948
label: this.api.i18n.t('Move up'),
5049
onActivate: (item, e): void => this.handleClick(e),
5150
name: 'move-up',

src/components/dom.ts

Lines changed: 3 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ export default class Dom {
4545
}
4646

4747
/**
48-
* Helper for making Elements with classname and attributes
48+
* Helper for making Elements with class name and attributes
4949
*
5050
* @param {string} tagName - new Element tag name
51-
* @param {string[]|string} [classNames] - list or name of CSS classname(s)
51+
* @param {string[]|string} [classNames] - list or name of CSS class name(s)
5252
* @param {object} [attributes] - any attributes
5353
* @returns {HTMLElement}
5454
*/
@@ -80,25 +80,6 @@ export default class Dom {
8080
return document.createTextNode(content);
8181
}
8282

83-
/**
84-
* Creates SVG icon linked to the sprite
85-
*
86-
* @param {string} name - name (id) of icon from sprite
87-
* @param {number} [width] - icon width
88-
* @param {number} [height] - icon height
89-
* @returns {SVGElement}
90-
*/
91-
public static svg(name: string, width = 14, height = 14): SVGElement {
92-
const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
93-
94-
icon.classList.add('icon', 'icon--' + name);
95-
icon.setAttribute('width', width + 'px');
96-
icon.setAttribute('height', height + 'px');
97-
icon.innerHTML = `<use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#${name}"></use>`;
98-
99-
return icon;
100-
}
101-
10283
/**
10384
* Append one or several elements to the parent
10485
*
@@ -202,7 +183,7 @@ export default class Dom {
202183
}
203184

204185
/**
205-
* Find all contendeditable, textarea and editable input elements passed holder contains
186+
* Find all contenteditable, textarea and editable input elements passed holder contains
206187
*
207188
* @param holder - element where to find inputs
208189
*/

src/components/inline-tools/inline-tool-bold.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import $ from '../dom';
21
import { InlineTool, SanitizerConfig } from '../../../types';
2+
import { IconBold } from '@codexteam/icons';
33

44
/**
55
* Bold Tool
@@ -61,8 +61,7 @@ export default class BoldInlineTool implements InlineTool {
6161
this.nodes.button = document.createElement('button') as HTMLButtonElement;
6262
this.nodes.button.type = 'button';
6363
this.nodes.button.classList.add(this.CSS.button, this.CSS.buttonModifier);
64-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
65-
this.nodes.button.appendChild($.svg('bold', 12, 14));
64+
this.nodes.button.innerHTML = IconBold;
6665

6766
return this.nodes.button;
6867
}

src/components/inline-tools/inline-tool-italic.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import $ from '../dom';
21
import { InlineTool, SanitizerConfig } from '../../../types';
2+
import { IconItalic } from '@codexteam/icons';
33

44
/**
55
* Italic Tool
@@ -61,8 +61,7 @@ export default class ItalicInlineTool implements InlineTool {
6161
this.nodes.button = document.createElement('button') as HTMLButtonElement;
6262
this.nodes.button.type = 'button';
6363
this.nodes.button.classList.add(this.CSS.button, this.CSS.buttonModifier);
64-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
65-
this.nodes.button.appendChild($.svg('italic', 4, 11));
64+
this.nodes.button.innerHTML = IconItalic;
6665

6766
return this.nodes.button;
6867
}

src/components/inline-tools/inline-tool-link.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
import SelectionUtils from '../selection';
2-
3-
import $ from '../dom';
42
import * as _ from '../utils';
5-
import { API, InlineTool, SanitizerConfig } from '../../../types';
3+
import { InlineTool, SanitizerConfig, API } from '../../../types';
64
import { Notifier, Toolbar, I18n, InlineToolbar } from '../../../types/api';
5+
import { IconLink, IconUnlink } from '@codexteam/icons';
76

87
/**
98
* Link Tool
@@ -123,10 +122,8 @@ export default class LinkInlineTool implements InlineTool {
123122
this.nodes.button = document.createElement('button') as HTMLButtonElement;
124123
this.nodes.button.type = 'button';
125124
this.nodes.button.classList.add(this.CSS.button, this.CSS.buttonModifier);
126-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
127-
this.nodes.button.appendChild($.svg('link', 14, 10));
128-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
129-
this.nodes.button.appendChild($.svg('unlink', 15, 11));
125+
126+
this.nodes.button.innerHTML = IconLink;
130127

131128
return this.nodes.button;
132129
}
@@ -194,6 +191,7 @@ export default class LinkInlineTool implements InlineTool {
194191
const anchorTag = this.selection.findParentTag('A');
195192

196193
if (anchorTag) {
194+
this.nodes.button.innerHTML = IconUnlink;
197195
this.nodes.button.classList.add(this.CSS.buttonUnlink);
198196
this.nodes.button.classList.add(this.CSS.buttonActive);
199197
this.openActions();
@@ -207,6 +205,7 @@ export default class LinkInlineTool implements InlineTool {
207205

208206
this.selection.save();
209207
} else {
208+
this.nodes.button.innerHTML = IconLink;
210209
this.nodes.button.classList.remove(this.CSS.buttonUnlink);
211210
this.nodes.button.classList.remove(this.CSS.buttonActive);
212211
}

src/components/modules/toolbar/index.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { ModuleConfig } from '../../../types-internal/module-config';
88
import { BlockAPI } from '../../../../types';
99
import Block from '../../block';
1010
import Toolbox, { ToolboxEvent } from '../../ui/toolbox';
11+
import { IconMenu, IconPlus } from '@codexteam/icons';
1112

1213
/**
1314
* @todo Tab on non-empty block should open Block Settings of the hoveredBlock (not where caret is set)
@@ -335,9 +336,9 @@ export default class Toolbar extends Module<ToolbarNodes> {
335336
* - Plus Button
336337
* - Toolbox
337338
*/
338-
this.nodes.plusButton = $.make('div', this.CSS.plusButton);
339-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
340-
$.append(this.nodes.plusButton, $.svg('plus', 16, 16));
339+
this.nodes.plusButton = $.make('div', this.CSS.plusButton, {
340+
innerHTML: IconPlus,
341+
});
341342
$.append(this.nodes.actions, this.nodes.plusButton);
342343

343344
this.readOnlyMutableListeners.on(this.nodes.plusButton, 'click', () => {
@@ -365,11 +366,10 @@ export default class Toolbar extends Module<ToolbarNodes> {
365366
* - Remove Block Button
366367
* - Settings Panel
367368
*/
368-
this.nodes.settingsToggler = $.make('span', this.CSS.settingsToggler);
369-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
370-
const settingsIcon = $.svg('dots', 16, 16);
369+
this.nodes.settingsToggler = $.make('span', this.CSS.settingsToggler, {
370+
innerHTML: IconMenu,
371+
});
371372

372-
$.append(this.nodes.settingsToggler, settingsIcon);
373373
$.append(this.nodes.actions, this.nodes.settingsToggler);
374374

375375
this.tooltip.onHover(

src/components/modules/toolbar/inline.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Tooltip from '../../utils/tooltip';
1111
import { ModuleConfig } from '../../../types-internal/module-config';
1212
import InlineTool from '../../tools/inline';
1313
import { CommonInternalSettings } from '../../tools/base';
14+
import { IconChevronDown } from '@codexteam/icons';
1415

1516
/**
1617
* Inline Toolbar elements
@@ -51,6 +52,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
5152
inputField: 'cdx-input',
5253
focusedButton: 'ce-inline-tool--focused',
5354
conversionToggler: 'ce-inline-toolbar__dropdown',
55+
conversionTogglerArrow: 'ce-inline-toolbar__dropdown-arrow',
5456
conversionTogglerHidden: 'ce-inline-toolbar__dropdown--hidden',
5557
conversionTogglerContent: 'ce-inline-toolbar__dropdown-content',
5658
togglerAndButtonsWrapper: 'ce-inline-toolbar__toggler-and-button-wrapper',
@@ -428,11 +430,12 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
428430
this.nodes.conversionToggler = $.make('div', this.CSS.conversionToggler);
429431
this.nodes.conversionTogglerContent = $.make('div', this.CSS.conversionTogglerContent);
430432

431-
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
432-
const icon = $.svg('toggler-down', 13, 13);
433+
const iconWrapper = $.make('div', this.CSS.conversionTogglerArrow, {
434+
innerHTML: IconChevronDown,
435+
});
433436

434437
this.nodes.conversionToggler.appendChild(this.nodes.conversionTogglerContent);
435-
this.nodes.conversionToggler.appendChild(icon);
438+
this.nodes.conversionToggler.appendChild(iconWrapper);
436439

437440
this.nodes.togglerAndButtonsWrapper.appendChild(this.nodes.conversionToggler);
438441

@@ -665,6 +668,15 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
665668

666669
tool.surround(range);
667670
this.checkToolsState();
671+
672+
/**
673+
* If tool has "actions", so after click it will probably toggle them on.
674+
* For example, the Inline Link Tool will show the URL-input.
675+
* So we disable the Flipper for that case to allow Tool bind own Enter listener
676+
*/
677+
if (tool.renderActions !== undefined) {
678+
this.flipper.deactivate();
679+
}
668680
}
669681

670682
/**

0 commit comments

Comments
 (0)