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

Rename Tool's makeSettings -> renderSettings #315

Merged
merged 2 commits into from
Jul 19, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 16 additions & 2 deletions build/codex-editor.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions docs/toolbar-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,52 +10,52 @@ regardless to the plugin's option.

### Let's look the examples:

«Plugin»'s Developers need to expand «makeSettings» method that returns HTML.
«Plugin»'s Developers need to expand «renderSettings» method that returns HTML.
Every user action will be handled by itself. So, you can easily write
callbacks that switches your content or makes better. For more information
read [Tools](tools.md).

---

«Tune»'s Developers need to implement core-provided interface to develop
tunes that will be appeared in Toolbar default settings zone.

Tunes must expand two important methods:
- `render()` - returns HTML and it is appended to the default settings zone
- `save()` - extracts important information to be saved

No restrictions. Handle user action by yourself

Create Class that implements block-tune.ts

Your Tune's constructor gets argument as object and it includes:
- {Object} api - object contains public methods from modules. @see [API](api.md)
- {Object} settings - settings contains block default state.
Your Tune's constructor gets argument as object and it includes:
- {Object} api - object contains public methods from modules. @see [API](api.md)
- {Object} settings - settings contains block default state.
This object could have information about cover, anchor and so on.

Example on TypeScript:
Example on TypeScript:

```js

import IBlockTune from './block-tune';

export default class YourCustomTune implements IBlockTune {

public constructor({api, settings}) {
this.api = api;
this.settings = settings;
}

render() {
let someHTML = '...';
let someHTML = '...';
return someHTML;
}

save() {
// Return the important data that needs to be saved
return object
}

someMethod() {
// moves current block down
this.api.blocks.moveDown();
Expand All @@ -67,22 +67,22 @@ Example on ES6

```js
export default class YourCustomTune {

constructor({api, settings}) {
this.api = api;
this.settings = settings;
}

render() {
let someHTML = '...';
let someHTML = '...';
return someHTML;
}

save() {
// Return the important data that needs to be saved
return object
}

someMethod() {
// moves current block down
this.api.blocks.moveDown();
Expand Down
2 changes: 1 addition & 1 deletion example/plugins/header/header.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ class Header {
*
* @return {HTMLElement}
*/
makeSettings() {
renderSettings() {
let holder = document.createElement('DIV');

/** Add type selectors */
Expand Down
2 changes: 1 addition & 1 deletion src/components/interfaces/block-tool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export interface IBlockTool {
* Create Block's settings block
* @return {HTMLElement}
*/
makeSettings(): HTMLElement;
renderSettings(): HTMLElement;

/**
* Return Tool's main block-wrapper
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/api-blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export default class BlocksAPI extends Module implements IBlocksAPI {
if (this.Editor.BlockManager.currentBlockIndex === 0) {
this.Editor.Caret.setToBlock(this.Editor.BlockManager.currentBlock);
} else {
this.Editor.Caret.navigatePrevious(true)
this.Editor.Caret.navigatePrevious(true);
}

this.Editor.Toolbar.close();
Expand Down
4 changes: 2 additions & 2 deletions src/components/modules/toolbar-blockSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,8 @@ export default class BlockSettings extends Module {
* Add Tool's settings
*/
addToolSettings() {
if (typeof this.Editor.BlockManager.currentBlock.tool.makeSettings === 'function') {
$.append(this.nodes.toolSettings, this.Editor.BlockManager.currentBlock.tool.makeSettings());
if (typeof this.Editor.BlockManager.currentBlock.tool.renderSettings === 'function') {
$.append(this.nodes.toolSettings, this.Editor.BlockManager.currentBlock.tool.renderSettings());
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/components/modules/toolbar/settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ module.exports = (function (settings) {
* Append settings content
* It's stored in tool.settings
*/
if ( !editor.tools[toolType] || !editor.tools[toolType].makeSettings ) {
if ( !editor.tools[toolType] || !editor.tools[toolType].renderSettings ) {
return;
}

/**
* Draw settings block
*/
var settingsBlock = editor.tools[toolType].makeSettings();
var settingsBlock = editor.tools[toolType].renderSettings();

editor.nodes.pluginSettings.appendChild(settingsBlock);

Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/toolbar/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ module.exports = (function (toolbar) {

let toolType = editor.content.currentNode.dataset.tool;

if (!editor.tools[toolType] || !editor.tools[toolType].makeSettings ) {
if (!editor.tools[toolType] || !editor.tools[toolType].renderSettings ) {
editor.nodes.showSettingsButton.classList.add('hide');
} else {
editor.nodes.showSettingsButton.classList.remove('hide');
Expand Down
12 changes: 12 additions & 0 deletions src/components/modules/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,17 @@ export default class UI extends Module {
case _.keyCodes.ENTER:
this.enterPressed(event);
break;

default:
this.defaultBehaviour(event);
break;
}
}

/**
* Ignore all other document's keydown events
* @param {KeyboardEvent} event
*/
defaultBehaviour(event) {
const keyDownOnEditor = event.target.closest(`.${this.CSS.editorWrapper}`);

Expand All @@ -184,7 +189,14 @@ export default class UI extends Module {
* clear pointer and close toolbar
*/
if (!keyDownOnEditor) {
/**
* Remove all highlights and remove caret
*/
this.Editor.BlockManager.dropPointer();

/**
* Close Toolbar
*/
this.Editor.Toolbar.close();
}
}
Expand Down