Skip to content

Commit

Permalink
Remove contentless and irreplaceable (codex-team#535)
Browse files Browse the repository at this point in the history
* Remove contentless and irreplacable settings

* update version
  • Loading branch information
neSpecc authored Nov 24, 2018
1 parent 953949e commit feace16
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 88 deletions.
24 changes: 12 additions & 12 deletions build/codex-editor.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion build/codex-editor.js.map

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ Options that Tool can specify. All settings should be passed as static propertie
| `displayInToolbox` | _Boolean_ | `false` | Pass `true` to display this `Tool` in the Editor's `Toolbox` |
| `toolboxIcon` | _String_ || Icon for Toolbox HTML string |
| `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. |
| `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. |
| `contentless` | _Boolean_ | `false` | Pass `true` for Tool which represents decorative empty `Blocks` |
| `isInline` | _Boolean_ | `false` | Describes Tool as a [Tool for the Inline Toolbar](tools-inline.md) |

### User configuration
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": "codex.editor",
"version": "2.5.4",
"version": "2.5.5",
"description": "Codex Editor. Native JS, based on API and Open Source",
"main": "build/codex-editor.js",
"types": "./types/index.d.ts",
Expand Down
15 changes: 1 addition & 14 deletions src/components/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -179,14 +179,6 @@ export default class Block {
* @return {Boolean}
*/
get isEmpty(): boolean {
/**
* Allow Tool to represent decorative contentless blocks: for example "* * *"-tool
* That Tools are not empty
*/
if (this.class.contentless) {
return false;
}

const emptyText = $.isEmpty(this.pluginsContent),
emptyMedia = !this.hasMedia;

Expand Down Expand Up @@ -218,15 +210,10 @@ export default class Block {

/**
* Set focused state
* We don't need to mark Block as focused when it is empty
* @param {Boolean} state - 'true' to select, 'false' to remove selection
*/
set focused(state: boolean) {
if (state === true && !this.isEmpty) {
this.holder.classList.add(Block.CSS.focused);
} else {
this.holder.classList.remove(Block.CSS.focused);
}
this.holder.classList.toggle(Block.CSS.focused, state);
}

/**
Expand Down
18 changes: 13 additions & 5 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,19 @@ export default class BlockEvents extends Module {
const shiftKey = event.shiftKey,
direction = shiftKey ? 'left' : 'right';

if (this.Editor.Toolbar.opened && currentBlock.isEmpty) {
this.Editor.Toolbox.open();
} else if (currentBlock.isEmpty) {
this.Editor.Toolbar.open();
this.Editor.Toolbar.plusButton.show();
/**
* Don't show Plus and Toolbox near not-inital Tools
*/
if (!this.Editor.Tools.isInitial(currentBlock.tool)) {
return;
}

if (currentBlock.isEmpty) {
if (!this.Editor.Toolbar.opened) {
this.Editor.Toolbar.open(false , false);
this.Editor.Toolbar.plusButton.show();
}

this.Editor.Toolbox.open();
}

Expand Down
11 changes: 6 additions & 5 deletions src/components/modules/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,14 @@ export default class Toolbar extends Module {
* Open Toolbar with Plus Button and Actions
* @param {boolean} withBlockActions - by default, Toolbar opens with Block Actions.
* This flag allows to open Toolbar without Actions.
* @param {boolean} needToCloseToolbox - by default, Toolbar will be moved with opening
* (by click on Block, or by enter)
* with closing Toolbox and Block Settings
* This flag allows to open Toolbar with Toolbox
*/
public open(withBlockActions: boolean = true): void {
/**
* Wait Block rendering for correct height computing
*/
public open(withBlockActions: boolean = true, needToCloseToolbox: boolean = true): void {
setTimeout(() => {
this.move();
this.move(needToCloseToolbox);
this.nodes.wrapper.classList.add(Toolbar.CSS.toolbarOpened);

if (withBlockActions) {
Expand Down
8 changes: 1 addition & 7 deletions src/components/modules/toolbar/toolbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,15 +309,9 @@ export default class Toolbox extends Module {
*/
const currentBlock = this.Editor.BlockManager.currentBlock;

/**
* We do replace if:
* - block is empty
* - block is not irreplaceable
* @type {Array}
*/
let newBlock;

if (!tool[this.Editor.Tools.apiSettings.IS_IRREPLACEBLE_TOOL] && currentBlock.isEmpty) {
if (currentBlock.isEmpty) {
newBlock = this.Editor.BlockManager.replace(toolName);
} else {
newBlock = this.Editor.BlockManager.insert(toolName);
Expand Down
31 changes: 0 additions & 31 deletions src/components/modules/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,35 +12,6 @@ import LinkInlineTool from '../inline-tools/inline-tool-link';
* Creates Instances from Plugins and binds external config to the instances
*/

/**
* Each Tool must contain the following important objects:
*
* @typedef {Object} ToolConfig {@link docs/tools.md}
* @property {String} iconClassname - this a icon in toolbar
* @property {Boolean} displayInToolbox - will be displayed in toolbox. Default value is TRUE
* @property {Boolean} enableLineBreaks - inserts new block or break lines. Default value is FALSE
* @property {Boolean|String[]} inlineToolbar - Pass `true` to enable the Inline Toolbar with all Tools,
* all pass an array with specified Tools list
* @property render @todo add description
* @property save @todo add description
* @property settings @todo add description
* @property validate - method that validates output data before saving
*/

/**
* @typedef {Function} Tool {@link docs/tools.md}
* @property {Boolean} displayInToolbox - By default, tools won't be added in the Toolbox. Pass true to add.
* @property {String} iconClassName - CSS class name for the Toolbox button
* @property {Boolean} irreplaceable - Toolbox behaviour: replace or add new block below
* @property render
* @property save
* @property settings
* @property validate
*
* @todo update according to current API
* @todo describe Tool in the {@link docs/tools.md}
*/

/**
* Class properties:
*
Expand Down Expand Up @@ -142,12 +113,10 @@ export default class Tools extends Module {
public get apiSettings() {
return {
CONFIG: 'config',
IS_CONTENTLESS: 'contentless',
IS_DISPLAYED_IN_TOOLBOX: 'displayInToolbox',
IS_ENABLED_INLINE_TOOLBAR: 'inlineToolbar',
IS_ENABLED_LINE_BREAKS: 'enableLineBreaks',
IS_INLINE: 'isInline',
IS_IRREPLACEBLE_TOOL: 'irreplaceable',
IS_PASTE_DISALLOWED: 'disallowPaste',
SHORTCUT: 'shortcut',
TOOLBAR_ICON: 'toolboxIcon',
Expand Down
10 changes: 0 additions & 10 deletions types/tools/block-tool.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,21 +53,11 @@ export interface BlockTool extends Tool {
}

export interface BlockToolConstructable extends ToolConstructable {
/**
* Pass `true` if Tool represents decorative empty Block
*/
contentless?: boolean;

/**
* Should this Tool be displayed in the Editor's Toolbox
*/
displayInToolbox?: boolean;

/**
* Disable ability to replace empty Block by Toolbox
*/
irreplaceable?: boolean;

/**
* String with an icon for Toolbox
*/
Expand Down

0 comments on commit feace16

Please sign in to comment.