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

Fixes for 2.19 #1356

Merged
merged 6 commits into from
Oct 12, 2020
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
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- `Fix` - Fixed the `Tab` key behavior when the caret is not set inside contenteditable element, but the block is selected [#1302](https://github.com/codex-team/editor.js/issues/1302).
- `Fix` - Fixed the `onChange` callback issue. This method didn't be called for native inputs before some contentedtable element changed [#843](https://github.com/codex-team/editor.js/issues/843)
- `Fix` - Fixed the `onChange` callback issue. This method didn't be called after the callback throws an exception [#1339](https://github.com/codex-team/editor.js/issues/1339)
- `Deprecated` — The Inline Tool `clear()` method is deprecated because the new instance of Inline Tools will be created on every showing of the Inline Toolbar

### 2.18

Expand Down
4 changes: 2 additions & 2 deletions example/example-rtl.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<!--
Use this page for debugging purposes.
Use this page for RTL mode debugging.
Editor Tools are loaded as git-submodules.
You can pull modules by running `yarn pull_tools` and start experimenting.
-->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Editor.js 🤩🧦🤨 example</title>
<title>Editor.js RTL example</title>
<link href="https://fonts.googleapis.com/css?family=PT+Mono" rel="stylesheet">
<link href="assets/demo.css" rel="stylesheet">
<script src="assets/json-preview.js"></script>
Expand Down
60 changes: 51 additions & 9 deletions example/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,16 @@
<div class="ce-example__button" id="saveButton">
editor.save()
</div>

<div class="ce-example__statusbar">
Readonly:
<b id="readonly-state">
Off
</b>
<div class="ce-example__statusbar-button" id="toggleReadOnlyButton">
toggle
</div>
</div>
</div>
<div class="ce-example__output">
<pre class="ce-example__output-content" id="output"></pre>
Expand Down Expand Up @@ -65,21 +75,29 @@

<!-- Initialization -->
<script>
/**
* Saving button
*/
const saveButton = document.getElementById('saveButton');

/**
* To initialize the Editor, create a new instance with configuration object
* @see docs/installation.md for mode details
*/
var editor = new EditorJS({
/**
* Enable/Disable the read only mode
*/
readOnly: false,

/**
* Wrapper of Editor
*/
holder: 'editorjs',

/**
* Common Inline Toolbar settings
* - if true (or not specified), the order from 'tool' property will be used
* - if an array of tool names, this order will be used
*/
// inlineToolbar: ['link', 'marker', 'bold', 'italic'],
// inlineToolbar: true,

/**
* Tools list
*/
Expand All @@ -89,7 +107,7 @@
*/
header: {
class: Header,
inlineToolbar: ['link'],
inlineToolbar: ['marker', 'link'],
config: {
placeholder: 'Header'
},
Expand Down Expand Up @@ -268,13 +286,37 @@
}
});

/**
* Saving button
*/
const saveButton = document.getElementById('saveButton');

/**
* Toggle read-only button
*/
const toggleReadOnlyButton = document.getElementById('toggleReadOnlyButton');
const readOnlyIndicator = document.getElementById('readonly-state');

/**
* Saving example
*/
saveButton.addEventListener('click', function () {
editor.save().then((savedData) => {
cPreview.show(savedData, document.getElementById("output"));
});
editor.save()
.then((savedData) => {
cPreview.show(savedData, document.getElementById("output"));
})
.catch((error) => {
console.error('Saving error', error);
});
});

/**
* Toggle read-only example
*/
toggleReadOnlyButton.addEventListener('click', async () => {
const readOnlyState = await editor.readOnly.toggle();

readOnlyIndicator.textContent = readOnlyState ? 'On' : 'Off';
});
</script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion src/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export default class EditorJS {
/**
* If `onReady` was passed in `configuration` then redefine onReady function
*/
if (typeof configuration === 'object' && typeof configuration.onReady === 'function') {
if (typeof configuration === 'object' && _.isFunction(configuration.onReady)) {
onReady = configuration.onReady;
}

Expand Down
9 changes: 2 additions & 7 deletions src/components/block-tunes/block-tune-move-down.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,10 @@ export default class MoveDownTune implements BlockTune {
*/
public handleClick(event: MouseEvent, button: HTMLElement): void {
const currentBlockIndex = this.api.blocks.getCurrentBlockIndex();
const nextBlock = this.api.blocks.getBlockByIndex(currentBlockIndex + 1);

// If Block is last do nothing
if (currentBlockIndex === this.api.blocks.getBlocksCount() - 1) {
if (!nextBlock) {
button.classList.add(this.CSS.animation);

window.setTimeout(() => {
Expand All @@ -83,12 +84,6 @@ export default class MoveDownTune implements BlockTune {
return;
}

const nextBlock = this.api.blocks.getBlockByIndex(currentBlockIndex + 1);

if (!nextBlock) {
return;
}

const nextBlockElement = nextBlock.holder;
const nextBlockCoords = nextBlockElement.getBoundingClientRect();

Expand Down
6 changes: 3 additions & 3 deletions src/components/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ export default class Block {
config: this.config,
api: this.api.getMethodsForTool(name, ToolType.Block),
block: this.blockAPI,
readOnly: readOnly,
readOnly,
});

this.holder = this.compose();
Expand Down Expand Up @@ -359,7 +359,7 @@ export default class Block {
* @returns {boolean}
*/
public mergeable(): boolean {
return typeof this.tool.merge === 'function';
return _.isFunction(this.tool.merge);
}

/**
Expand Down Expand Up @@ -659,7 +659,7 @@ export default class Block {

/**
* Mutation observer doesn't track changes in "<input>" and "<textarea>"
* so we need to track focus events
* so we need to track focus events to update current input and clear cache.
*/
this.addInputEvents();
}
Expand Down
12 changes: 3 additions & 9 deletions src/components/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ export default class Core {
a: true,
} as SanitizerConfig;


this.config.hideToolbar = this.config.hideToolbar ? this.config.hideToolbar : false;
this.config.tools = this.config.tools || {};
this.config.i18n = this.config.i18n || {};
Expand All @@ -208,7 +209,6 @@ export default class Core {
}

this.config.readOnly = this.config.readOnly as boolean || false;
this.config.i18n = {};

/**
* Adjust i18n
Expand All @@ -220,11 +220,7 @@ export default class Core {
/**
* Text direction. If not set, uses ltr
*/
if (config.i18n?.direction) {
this.config.i18n = {
direction: config.i18n?.direction || 'ltr',
};
}
this.config.i18n.direction = config.i18n?.direction || 'ltr';
}

/**
Expand Down Expand Up @@ -292,8 +288,6 @@ export default class Core {
'InlineToolbar',
'BlockManager',
'Paste',
'DragNDrop',
'ModificationsObserver',
'BlockSelection',
'RectangleSelection',
'CrossBlockSelection',
Expand Down Expand Up @@ -337,7 +331,7 @@ export default class Core {
/**
* If module has non-default exports, passed object contains them all and default export as 'default' property
*/
const Module = typeof module === 'function' ? module : module.default;
const Module = _.isFunction(module) ? module : module.default;

try {
/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/flipper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ export default class Flipper {
this.iterator.currentItem.click();
}

if (typeof this.activateCallback === 'function') {
if (_.isFunction(this.activateCallback)) {
this.activateCallback(this.iterator.currentItem);
}

Expand Down
9 changes: 0 additions & 9 deletions src/components/modules/dragNDrop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,6 @@ export default class DragNDrop extends Module {
*/
private isStartedAtEditor = false;

/**
* Bind module. Enable all bindings if it is not read-only mode
*/
public prepare(): void {
if (!this.Editor.ReadOnly.isEnabled) {
this.enableModuleBindings();
}
}

/**
* Toggle read-only state
*
Expand Down
13 changes: 1 addition & 12 deletions src/components/modules/modificationsObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default class ModificationsObserver extends Module {
private mutationDebouncer = _.debounce(() => {
this.updateNativeInputs();

if (typeof this.config.onChange === 'function') {
if (_.isFunction(this.config.onChange)) {
this.config.onChange(this.Editor.API.methods);
}
}, ModificationsObserver.DebounceTimer);
Expand All @@ -62,17 +62,6 @@ export default class ModificationsObserver extends Module {
this.mutationDebouncer = null;
}

/**
* Preparation method
*
* @returns {Promise<void>}
*/
public async prepare(): Promise<void> {
if (!this.Editor.ReadOnly.isEnabled) {
this.enableModule();
}
}

/**
* Set read-only state
*
Expand Down
3 changes: 0 additions & 3 deletions src/components/modules/paste.ts
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,6 @@ export default class Paste extends Module {
*/
public async prepare(): Promise<void> {
this.processTools();
if (!this.Editor.ReadOnly.isEnabled) {
this.setCallback();
}
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/sanitizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ export default class Sanitizer extends Module {
* @param {SanitizerConfig} config - config to check
*/
private isRule(config: SanitizerConfig): boolean {
return typeof config === 'object' || typeof config === 'boolean' || typeof config === 'function';
return typeof config === 'object' || typeof config === 'boolean' || _.isFunction(config);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/toolbar/blockSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ export default class BlockSettings extends Module<BlockSettingsNodes> {
* Add Tool's settings
*/
private addToolSettings(): void {
if (typeof this.Editor.BlockManager.currentBlock.tool.renderSettings === 'function') {
if (_.isFunction(this.Editor.BlockManager.currentBlock.tool.renderSettings)) {
$.append(this.nodes.toolSettings, this.Editor.BlockManager.currentBlock.tool.renderSettings());
}
}
Expand Down
10 changes: 5 additions & 5 deletions src/components/modules/toolbar/conversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ export default class ConversionToolbar extends Module<ConversionToolbarNodes> {
this.close();
}

if (typeof togglingCallback === 'function') {
if (_.isFunction(togglingCallback)) {
this.togglingCallback = togglingCallback;
}
}
Expand All @@ -136,7 +136,7 @@ export default class ConversionToolbar extends Module<ConversionToolbarNodes> {
}));
this.flipper.focusFirst();

if (typeof this.togglingCallback === 'function') {
if (_.isFunction(this.togglingCallback)) {
this.togglingCallback(true);
}
}, 50);
Expand All @@ -150,7 +150,7 @@ export default class ConversionToolbar extends Module<ConversionToolbarNodes> {
this.flipper.deactivate();
this.nodes.wrapper.classList.remove(ConversionToolbar.CSS.conversionToolbarShowed);

if (typeof this.togglingCallback === 'function') {
if (_.isFunction(this.togglingCallback)) {
this.togglingCallback(false);
}
}
Expand Down Expand Up @@ -207,7 +207,7 @@ export default class ConversionToolbar extends Module<ConversionToolbarNodes> {
let exportData = '';
const exportProp = currentBlockClass[INTERNAL_SETTINGS.CONVERSION_CONFIG].export;

if (typeof exportProp === 'function') {
if (_.isFunction(exportProp)) {
exportData = exportProp(blockData);
} else if (typeof exportProp === 'string') {
exportData = blockData[exportProp];
Expand All @@ -234,7 +234,7 @@ export default class ConversionToolbar extends Module<ConversionToolbarNodes> {
let newBlockData = {};
const importProp = replacingTool[INTERNAL_SETTINGS.CONVERSION_CONFIG].import;

if (typeof importProp === 'function') {
if (_.isFunction(importProp)) {
newBlockData = importProp(cleaned);
} else if (typeof importProp === 'string') {
newBlockData[importProp] = cleaned;
Expand Down
8 changes: 5 additions & 3 deletions src/components/modules/toolbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,6 @@ export default class Toolbar extends Module<ToolbarNodes> {

/**
* Module preparation method
* Steps:
* - Make Toolbar dependent components like BlockSettings, Toolbox and so on
* - Make itself and append dependent nodes to itself
*/
public async prepare(): Promise<void> {
/**
Expand Down Expand Up @@ -369,6 +366,11 @@ export default class Toolbar extends Module<ToolbarNodes> {
*
* Toolbar contains BlockSettings and Toolbox.
* Thats why at first we draw its components and then Toolbar itself
*
* Steps:
* - Make Toolbar dependent components like BlockSettings, Toolbox and so on
* - Make itself and append dependent nodes to itself
*
*/
private drawUI(): void {
/**
Expand Down
4 changes: 2 additions & 2 deletions src/components/modules/toolbar/inline.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
/**
* @todo replace 'clear' with 'destroy'
*/
if (typeof toolInstance.clear === 'function') {
if (_.isFunction(toolInstance.clear)) {
toolInstance.clear();
}
});
Expand Down Expand Up @@ -614,7 +614,7 @@ export default class InlineToolbar extends Module<InlineToolbarNodes> {
this.nodes.buttons.appendChild(button);
this.toolsInstances.set(toolName, tool);

if (typeof tool.renderActions === 'function') {
if (_.isFunction(tool.renderActions)) {
const actions = tool.renderActions();

this.nodes.actions.appendChild(actions);
Expand Down
Loading