X Tutup
Skip to content

Commit feace16

Browse files
authored
Remove contentless and irreplaceable (codex-team#535)
* Remove contentless and irreplacable settings * update version
1 parent 953949e commit feace16

File tree

10 files changed

+35
-88
lines changed

10 files changed

+35
-88
lines changed

build/codex-editor.js

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build/codex-editor.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/tools.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,6 @@ Options that Tool can specify. All settings should be passed as static propertie
5656
| `displayInToolbox` | _Boolean_ | `false` | Pass `true` to display this `Tool` in the Editor's `Toolbox` |
5757
| `toolboxIcon` | _String_ || Icon for Toolbox HTML string |
5858
| `enableLineBreaks` | _Boolean_ | `false` | With this option, CodeX Editor won't handle Enter keydowns. Can be helpful for Tools like `<code>` where line breaks should be handled by default behaviour. |
59-
| `irreplaceable` | _Boolean_ | `false` | By default, **empty** `Blocks` can be **replaced** by other `Blocks` with the `Toolbox`. Some tools with media-content may prefer another behaviour. Pass `true` and `Toolbox` will add a new block below yours. |
60-
| `contentless` | _Boolean_ | `false` | Pass `true` for Tool which represents decorative empty `Blocks` |
6159
| `isInline` | _Boolean_ | `false` | Describes Tool as a [Tool for the Inline Toolbar](tools-inline.md) |
6260

6361
### User configuration

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "codex.editor",
3-
"version": "2.5.4",
3+
"version": "2.5.5",
44
"description": "Codex Editor. Native JS, based on API and Open Source",
55
"main": "build/codex-editor.js",
66
"types": "./types/index.d.ts",

src/components/block.ts

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -179,14 +179,6 @@ export default class Block {
179179
* @return {Boolean}
180180
*/
181181
get isEmpty(): boolean {
182-
/**
183-
* Allow Tool to represent decorative contentless blocks: for example "* * *"-tool
184-
* That Tools are not empty
185-
*/
186-
if (this.class.contentless) {
187-
return false;
188-
}
189-
190182
const emptyText = $.isEmpty(this.pluginsContent),
191183
emptyMedia = !this.hasMedia;
192184

@@ -218,15 +210,10 @@ export default class Block {
218210

219211
/**
220212
* Set focused state
221-
* We don't need to mark Block as focused when it is empty
222213
* @param {Boolean} state - 'true' to select, 'false' to remove selection
223214
*/
224215
set focused(state: boolean) {
225-
if (state === true && !this.isEmpty) {
226-
this.holder.classList.add(Block.CSS.focused);
227-
} else {
228-
this.holder.classList.remove(Block.CSS.focused);
229-
}
216+
this.holder.classList.toggle(Block.CSS.focused, state);
230217
}
231218

232219
/**

src/components/modules/blockEvents.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,19 @@ export default class BlockEvents extends Module {
114114
const shiftKey = event.shiftKey,
115115
direction = shiftKey ? 'left' : 'right';
116116

117-
if (this.Editor.Toolbar.opened && currentBlock.isEmpty) {
118-
this.Editor.Toolbox.open();
119-
} else if (currentBlock.isEmpty) {
120-
this.Editor.Toolbar.open();
121-
this.Editor.Toolbar.plusButton.show();
117+
/**
118+
* Don't show Plus and Toolbox near not-inital Tools
119+
*/
120+
if (!this.Editor.Tools.isInitial(currentBlock.tool)) {
121+
return;
122+
}
123+
124+
if (currentBlock.isEmpty) {
125+
if (!this.Editor.Toolbar.opened) {
126+
this.Editor.Toolbar.open(false , false);
127+
this.Editor.Toolbar.plusButton.show();
128+
}
129+
122130
this.Editor.Toolbox.open();
123131
}
124132

src/components/modules/toolbar/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -190,13 +190,14 @@ export default class Toolbar extends Module {
190190
* Open Toolbar with Plus Button and Actions
191191
* @param {boolean} withBlockActions - by default, Toolbar opens with Block Actions.
192192
* This flag allows to open Toolbar without Actions.
193+
* @param {boolean} needToCloseToolbox - by default, Toolbar will be moved with opening
194+
* (by click on Block, or by enter)
195+
* with closing Toolbox and Block Settings
196+
* This flag allows to open Toolbar with Toolbox
193197
*/
194-
public open(withBlockActions: boolean = true): void {
195-
/**
196-
* Wait Block rendering for correct height computing
197-
*/
198+
public open(withBlockActions: boolean = true, needToCloseToolbox: boolean = true): void {
198199
setTimeout(() => {
199-
this.move();
200+
this.move(needToCloseToolbox);
200201
this.nodes.wrapper.classList.add(Toolbar.CSS.toolbarOpened);
201202

202203
if (withBlockActions) {

src/components/modules/toolbar/toolbox.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -309,15 +309,9 @@ export default class Toolbox extends Module {
309309
*/
310310
const currentBlock = this.Editor.BlockManager.currentBlock;
311311

312-
/**
313-
* We do replace if:
314-
* - block is empty
315-
* - block is not irreplaceable
316-
* @type {Array}
317-
*/
318312
let newBlock;
319313

320-
if (!tool[this.Editor.Tools.apiSettings.IS_IRREPLACEBLE_TOOL] && currentBlock.isEmpty) {
314+
if (currentBlock.isEmpty) {
321315
newBlock = this.Editor.BlockManager.replace(toolName);
322316
} else {
323317
newBlock = this.Editor.BlockManager.insert(toolName);

src/components/modules/tools.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -12,35 +12,6 @@ import LinkInlineTool from '../inline-tools/inline-tool-link';
1212
* Creates Instances from Plugins and binds external config to the instances
1313
*/
1414

15-
/**
16-
* Each Tool must contain the following important objects:
17-
*
18-
* @typedef {Object} ToolConfig {@link docs/tools.md}
19-
* @property {String} iconClassname - this a icon in toolbar
20-
* @property {Boolean} displayInToolbox - will be displayed in toolbox. Default value is TRUE
21-
* @property {Boolean} enableLineBreaks - inserts new block or break lines. Default value is FALSE
22-
* @property {Boolean|String[]} inlineToolbar - Pass `true` to enable the Inline Toolbar with all Tools,
23-
* all pass an array with specified Tools list
24-
* @property render @todo add description
25-
* @property save @todo add description
26-
* @property settings @todo add description
27-
* @property validate - method that validates output data before saving
28-
*/
29-
30-
/**
31-
* @typedef {Function} Tool {@link docs/tools.md}
32-
* @property {Boolean} displayInToolbox - By default, tools won't be added in the Toolbox. Pass true to add.
33-
* @property {String} iconClassName - CSS class name for the Toolbox button
34-
* @property {Boolean} irreplaceable - Toolbox behaviour: replace or add new block below
35-
* @property render
36-
* @property save
37-
* @property settings
38-
* @property validate
39-
*
40-
* @todo update according to current API
41-
* @todo describe Tool in the {@link docs/tools.md}
42-
*/
43-
4415
/**
4516
* Class properties:
4617
*
@@ -142,12 +113,10 @@ export default class Tools extends Module {
142113
public get apiSettings() {
143114
return {
144115
CONFIG: 'config',
145-
IS_CONTENTLESS: 'contentless',
146116
IS_DISPLAYED_IN_TOOLBOX: 'displayInToolbox',
147117
IS_ENABLED_INLINE_TOOLBAR: 'inlineToolbar',
148118
IS_ENABLED_LINE_BREAKS: 'enableLineBreaks',
149119
IS_INLINE: 'isInline',
150-
IS_IRREPLACEBLE_TOOL: 'irreplaceable',
151120
IS_PASTE_DISALLOWED: 'disallowPaste',
152121
SHORTCUT: 'shortcut',
153122
TOOLBAR_ICON: 'toolboxIcon',

types/tools/block-tool.d.ts

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,11 @@ export interface BlockTool extends Tool {
5353
}
5454

5555
export interface BlockToolConstructable extends ToolConstructable {
56-
/**
57-
* Pass `true` if Tool represents decorative empty Block
58-
*/
59-
contentless?: boolean;
60-
6156
/**
6257
* Should this Tool be displayed in the Editor's Toolbox
6358
*/
6459
displayInToolbox?: boolean;
6560

66-
/**
67-
* Disable ability to replace empty Block by Toolbox
68-
*/
69-
irreplaceable?: boolean;
70-
7161
/**
7262
* String with an icon for Toolbox
7363
*/

0 commit comments

Comments
 (0)
X Tutup