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

Release/2.17 #1063

Merged
merged 75 commits into from
Mar 14, 2020
Merged
Changes from 1 commit
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
c221a64
2.16.0
Jul 8, 2019
fdeae3f
[Refactor] Separate internal and external settings (#845)
gohabereg Jul 10, 2019
af581d3
Enable flipping tools via standalone class (#830)
khaydarov Jul 15, 2019
0d1c86c
fixed a link in readme.md (#856)
Jul 30, 2019
52669d7
Fix Block selection via CMD+A (#829)
khaydarov Jul 31, 2019
d22667d
Improve style of selected blocks (#858)
neSpecc Jul 31, 2019
e2ca2a6
Fix case when property 'observer' in modificationObserver is not defi…
VLZH Sep 7, 2019
1623839
Bump lodash.template from 4.4.0 to 4.5.0 (#885)
dependabot[bot] Sep 8, 2019
3ab0435
Bump eslint-utils from 1.3.1 to 1.4.2 (#886)
dependabot[bot] Sep 8, 2019
749894b
Bump mixin-deep from 1.3.1 to 1.3.2 (#887)
dependabot[bot] Sep 8, 2019
bbcc13a
update bundle and readme
neSpecc Sep 8, 2019
fc9e13a
Update README.md
neSpecc Sep 8, 2019
3bfaa20
upd codeowners, fix funding
neSpecc Sep 8, 2019
72ee05a
Merge branch 'master' into release/2.16
neSpecc Oct 3, 2019
56839f7
Minor Docs Fix according to main Readme (#916)
ChaituVR Oct 20, 2019
a438185
Inline Toolbar now contains Conversion Toolbar (#932)
neSpecc Nov 20, 2019
a9c4649
Block lifecycle hooks (#906)
gohabereg Nov 21, 2019
d086b6d
[Fix] Arrow selection (#964)
gohabereg Nov 30, 2019
ea3c767
[issue-926]: fix dom iterator leafing when items are empty (#958)
khaydarov Nov 30, 2019
461f9a5
Issue 869 (#963)
gohabereg Nov 30, 2019
3e2bf87
Fix issue 943 (#965)
gohabereg Nov 30, 2019
36f69f0
[Draft] Feature/tooltip enhancements (#907)
khaydarov Nov 30, 2019
b19cb06
[issue-779]: Grammarly conflicts (#956)
khaydarov Nov 30, 2019
2e9faf1
Submodule Header now on master
neSpecc Nov 30, 2019
0689c82
Submodule Marker now on master
neSpecc Nov 30, 2019
533512e
Submodule Paragraph now on master
neSpecc Nov 30, 2019
7547e11
Submodule InlineCode now on master
neSpecc Nov 30, 2019
0d54c94
Submodule Simple Image now on master
neSpecc Nov 30, 2019
fa4b282
[issue-868]: Deleting multiple blocks triggers back button in Firefox…
khaydarov Nov 30, 2019
729f2ea
pass options on removeEventListener (#904)
MarinaZadoyanchuk Nov 30, 2019
1e20882
[Fix] Selection rangecount (#968)
gohabereg Nov 30, 2019
bee449b
Fix #952 (#969)
neSpecc Nov 30, 2019
fdcedb2
Update codex.tooltips
neSpecc Nov 30, 2019
053e25e
Merge branch 'release/2.16' of https://github.com/codex-team/editor.j…
neSpecc Nov 30, 2019
2729f8f
Selection bugfix (#970)
khaydarov Nov 30, 2019
c6f5be6
remove inline toolbar closing on cross block selection mouse up due t…
khaydarov Nov 30, 2019
cff5434
[Feature] Log levels (#971)
gohabereg Nov 30, 2019
ba2fe25
Decrease margins (#973)
neSpecc Nov 30, 2019
9661916
Update src/components/domIterator.ts
neSpecc Nov 30, 2019
6682034
[Fix] Fix delete blocks api method (#974)
gohabereg Nov 30, 2019
f3f94e3
Update docs/usage.md
neSpecc Nov 30, 2019
5910fa8
rm unused
neSpecc Nov 30, 2019
630cb76
Update yarn.lock file
Nov 30, 2019
f50abf4
Merge branch 'release/2.16' of github.com:codex-team/editor.js into r…
Nov 30, 2019
755f429
upd bundle, changelog
neSpecc Nov 30, 2019
964652d
Resolve Firefox issues (#981)
neSpecc Dec 3, 2019
f262bd7
Set initial hidden Inline Toolbar position (#982)
neSpecc Dec 3, 2019
4a9c65d
[Fix] tooltip types (#986)
gohabereg Dec 7, 2019
22b6f80
Fix to set minHeight 0px (#987)
hata6502 Dec 7, 2019
952c148
[Fix] Selection issues (#988)
gohabereg Dec 7, 2019
3476413
[Dev] Update dependencies (#989)
gohabereg Dec 7, 2019
738019f
Merge branch 'master' into release/2.16
neSpecc Dec 7, 2019
a1917da
Delete codex.tooltips
neSpecc Dec 7, 2019
83fcf82
Update submodules
Dec 7, 2019
aae8ca6
Fix/hide conversion toolbar (#991)
khaydarov Dec 7, 2019
7525427
Update CHANGELOG.md
neSpecc Dec 7, 2019
5679fd1
fix some problems at example
neSpecc Mar 3, 2020
b1c2822
Update CHANGELOG.md
neSpecc Mar 3, 2020
e3a7d88
Fix: bind editor when calling onChange (#1048)
melbahja Mar 3, 2020
c8827b5
updated some wording. (#1044)
drbe4t Mar 3, 2020
84eeefa
Fix grammar in readme.md (#1008)
darrelfrancis Mar 3, 2020
9df986c
Merge branch 'master' into release/2.17
neSpecc Mar 3, 2020
0bb7141
Update editor.js
neSpecc Mar 3, 2020
74c7533
Paste listener on editors instead of document (#1025)
ponnex Mar 3, 2020
bc3e290
Bump acorn from 6.4.0 to 6.4.1 (#1059)
dependabot[bot] Mar 14, 2020
3a83a1d
Fix flipper activate/deactivate when conversionToolbarOpened (#1001)
aablinov Mar 14, 2020
e10da45
[Issue-1057]: open new window by clicking anchor with ctrl (#1062)
khaydarov Mar 14, 2020
92eab3b
Fix settings box-sizing (#1013)
hata6502 Mar 14, 2020
06d657c
Improvements: new Block Settings button style (#1064)
neSpecc Mar 14, 2020
3877380
[Feature] In-house copy paste (#1060)
gohabereg Mar 14, 2020
8b838bf
New block lifecycle hook and BlockToolAPI: "moved" (#1007)
natterstefan Mar 14, 2020
a5513a3
Change paste function of text/plain (#1014)
hata6502 Mar 14, 2020
c1860c9
Improve paste function of multiple lines (#1016)
hata6502 Mar 14, 2020
b7e4f91
2.17.0
gohabereg Mar 14, 2020
834930d
Update bundle
gohabereg Mar 14, 2020
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
Prev Previous commit
Next Next commit
New block lifecycle hook and BlockToolAPI: "moved" (#1007)
* Update CHANGELOG.md

* feat: add swapped lifecycle hook

* feat: deprecate swap and add move instead

* feat: set fromIndex by default, add MoveEvent, add indices checks in blockManager

* refactor: MoveEvent interface more event-like; docs: added docs for MoveEvent

* fix asterix alignment due to tslint error

* fix tslint

* extending CustomEvent

* update bundle

* Update CHANGELOG.md

Co-authored-by: Peter Savchenko <[email protected]>
Co-authored-by: Murod Khaydarov <[email protected]>
3 people authored Mar 14, 2020

Verified

This commit was signed with the committer’s verified signature.
oliviertassinari Olivier Tassinari
commit 8b838bf8aa89b3605f06894c84f1045b0f55a5d1
2 changes: 1 addition & 1 deletion dist/editor.js

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@
- `Fix` - Fix block-tune buttons alignment in some CSS-resetors that forces `box-sizing: border-box` rule [#1003](https://github.com/codex-team/editor.js/issues/1003)
- `Improvements` - New style of a Block Settings button. Focused block background removed.
- `New` — Add in-house copy-paste support through `application/x-editor-js` mime-type
- `New` Block [lifecycle hook](tools.md#block-lifecycle-hooks) `moved`
- `Deprecated` — [`blocks.swap(fromIndex, toIndex)`](api.md) method is deprecated. Use `blocks.move(toIndex, fromIndex)` instead.

### 2.16.1

6 changes: 5 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
@@ -26,7 +26,11 @@ Methods that working with Blocks

`renderFromHTML(data)` - parse and render passed HTML string (*not for production use*)

`swap(fromIndex, toIndex)` - swaps two Blocks by their positions
`swap(fromIndex, toIndex)` - swaps two Blocks by their positions (deprecated:
use 'move' instead)

`move(toIndex, fromIndex)` - moves block from one index to another position.
`fromIndex` will be the current block's index by default.

`delete(blockIndex?: Number)` - deletes Block with passed index

5 changes: 5 additions & 0 deletions docs/tools.md
Original file line number Diff line number Diff line change
@@ -476,3 +476,8 @@ Called each time Block contents is updated
### `removed()`

Called after Block contents is removed from the page but before Block instance deleted

### `moved(MoveEvent)`

Called after Block was moved. `MoveEvent` contains `fromIndex` and `toIndex`
respectively.
2 changes: 1 addition & 1 deletion src/components/block-tunes/block-tune-move-down.ts
Original file line number Diff line number Diff line change
@@ -92,7 +92,7 @@ export default class MoveDownTune implements BlockTune {
window.scrollTo(0, scrollOffset);

/** Change blocks positions */
this.api.blocks.swap(currentBlockIndex, currentBlockIndex + 1);
this.api.blocks.move(currentBlockIndex + 1);

/** Hide the Tooltip */
this.api.tooltip.hide();
4 changes: 2 additions & 2 deletions src/components/block-tunes/block-tune-move-up.ts
Original file line number Diff line number Diff line change
@@ -46,7 +46,7 @@ export default class MoveUpTune implements BlockTune {
'click',
(event) => this.handleClick(event as MouseEvent, moveUpButton),
false,
);
);

/**
* Enable tooltip module on button
@@ -99,7 +99,7 @@ export default class MoveUpTune implements BlockTune {
window.scrollBy(0, -1 * scrollUpOffset);

/** Change blocks positions */
this.api.blocks.swap(currentBlockIndex, currentBlockIndex - 1);
this.api.blocks.move(currentBlockIndex - 1);

/** Hide the Tooltip */
this.api.tooltip.hide();
7 changes: 4 additions & 3 deletions src/components/block.ts
Original file line number Diff line number Diff line change
@@ -38,6 +38,7 @@ export enum BlockToolAPI {
*/
APPEND_CALLBACK = 'appendCallback',
RENDERED = 'rendered',
MOVED = 'moved',
UPDATED = 'updated',
REMOVED = 'removed',
ON_PASTE = 'onPaste',
@@ -441,7 +442,7 @@ export default class Block {
* @param {Object} data
*/
public async mergeWith(data: BlockToolData): Promise<void> {
await this.tool.merge(data);
await this.tool.merge(data);
}
/**
* Extracts data from Block
@@ -465,7 +466,7 @@ export default class Block {
return {
tool: this.name,
data: finishedExtraction,
time : measuringEnd - measuringStart,
time: measuringEnd - measuringStart,
};
})
.catch((error) => {
@@ -562,7 +563,7 @@ export default class Block {
private compose(): HTMLDivElement {
const wrapper = $.make('div', Block.CSS.wrapper) as HTMLDivElement,
contentNode = $.make('div', Block.CSS.content),
pluginsContent = this.tool.render();
pluginsContent = this.tool.render();

contentNode.appendChild(pluginsContent);
wrapper.appendChild(contentNode);
53 changes: 52 additions & 1 deletion src/components/blocks.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as _ from './utils';
import $ from './dom';
import Block, {BlockToolAPI} from './block';
import Block, { BlockToolAPI } from './block';
import {MoveEvent, MoveEventDetail} from '../../types/tools';

/**
* @class Blocks
@@ -127,6 +128,7 @@ export default class Blocks {
* Swaps blocks with indexes first and second
* @param {Number} first - first block index
* @param {Number} second - second block index
* @deprecated — use 'move' instead
*/
public swap(first: number, second: number): void {
const secondBlock = this.blocks[second];
@@ -143,6 +145,42 @@ export default class Blocks {
this.blocks[first] = secondBlock;
}

/**
* Move a block from one to another index
* @param {Number} toIndex - new index of the block
* @param {Number} fromIndex - block to move
*/
public move(toIndex: number, fromIndex: number): void {
/**
* cut out the block, move the DOM element and insert at the desired index
* again (the shifting within the blocks array will happen automatically).
* @see https://stackoverflow.com/a/44932690/1238150
*/
const block = this.blocks.splice(fromIndex, 1)[0];

// manipulate DOM
const prevIndex = toIndex - 1;
const previousBlockIndex = Math.max(0, prevIndex);
const previousBlock = this.blocks[previousBlockIndex];

if (toIndex > 0) {
this.insertToDOM(block, 'afterend', previousBlock);
} else {
this.insertToDOM(block, 'beforebegin', previousBlock);
}

// move in array
this.blocks.splice(toIndex, 0, block);

// invoke hook
const event: MoveEvent = this.composeBlockEvent('move', {
fromIndex,
toIndex,
});

block.call(BlockToolAPI.MOVED, event);
}

/**
* Insert new Block at passed index
*
@@ -261,4 +299,17 @@ export default class Blocks {

block.call(BlockToolAPI.RENDERED);
}

/**
* Composes Block event with passed type and details
*
* @param {String} type
* @param {MoveEventDetail} detail
*/
private composeBlockEvent(type: string, detail: MoveEventDetail): MoveEvent {
return new CustomEvent(type, {
detail,
},
) as MoveEvent;
}
}
1 change: 1 addition & 0 deletions src/components/dom.ts
Original file line number Diff line number Diff line change
@@ -130,6 +130,7 @@ export default class Dom {
* Swap two elements in parent
* @param {HTMLElement} el1 - from
* @param {HTMLElement} el2 - to
* @deprecated
*/
public static swap(el1: HTMLElement, el2: HTMLElement): void {
// create marker element and insert it where el1 is
17 changes: 17 additions & 0 deletions src/components/modules/api/blocks.ts
Original file line number Diff line number Diff line change
@@ -20,6 +20,7 @@ export default class BlocksAPI extends Module {
renderFromHTML: (data: string) => this.renderFromHTML(data),
delete: () => this.delete(),
swap: (fromIndex: number, toIndex: number) => this.swap(fromIndex, toIndex),
move: (toIndex: number, fromIndex?: number) => this.move(toIndex, fromIndex),
getBlockByIndex: (index: number) => this.getBlockByIndex(index),
getCurrentBlockIndex: () => this.getCurrentBlockIndex(),
getBlocksCount: () => this.getBlocksCount(),
@@ -60,6 +61,7 @@ export default class BlocksAPI extends Module {
* Call Block Manager method that swap Blocks
* @param {number} fromIndex - position of first Block
* @param {number} toIndex - position of second Block
* @deprecated — use 'move' instead
*/
public swap(fromIndex: number, toIndex: number): void {
this.Editor.BlockManager.swap(fromIndex, toIndex);
@@ -71,6 +73,21 @@ export default class BlocksAPI extends Module {
this.Editor.Toolbar.move(false);
}

/**
* Move block from one index to another
* @param {Number} toIndex
* @param {number} fromIndex
*/
public move(toIndex: number, fromIndex?: number): void {
this.Editor.BlockManager.move(toIndex, fromIndex);

/**
* Move toolbar
* DO not close the settings
*/
this.Editor.Toolbar.move(false);
}

/**
* Deletes Block
* @param blockIndex
37 changes: 37 additions & 0 deletions src/components/modules/blockManager.ts
Original file line number Diff line number Diff line change
@@ -552,6 +552,7 @@ export default class BlockManager extends Module {
* Swap Blocks Position
* @param {Number} fromIndex
* @param {Number} toIndex
* @deprecated — use 'move' instead
*/
public swap(fromIndex, toIndex): void {
/** Move up current Block */
@@ -561,6 +562,30 @@ export default class BlockManager extends Module {
this.currentBlockIndex = toIndex;
}

/**
* Move a block to a new index
* @param {Number} toIndex
* @param {Number} fromIndex
*/
public move(toIndex, fromIndex = this.currentBlockIndex): void {
// make sure indexes are valid and within a valid range
if (isNaN(toIndex) || isNaN(fromIndex)) {
_.log(`Warning during 'move' call: incorrect indices provided.`, 'warn');
return;
}

if (!this.validateIndex(toIndex) || !this.validateIndex(fromIndex)) {
_.log(`Warning during 'move' call: indices cannot be lower than 0 or greater than the amount of blocks.`, 'warn');
return;
}

/** Move up current Block */
this._blocks.move(toIndex, fromIndex);

/** Now actual block moved so that current block index changed */
this.currentBlockIndex = toIndex;
}

/**
* Sets current Block Index -1 which means unknown
* and clear highlightings
@@ -604,4 +629,16 @@ export default class BlockManager extends Module {
Listeners.on(block.holder, 'dragover', (event) => BlockEvents.dragOver(event as DragEvent));
Listeners.on(block.holder, 'dragleave', (event) => BlockEvents.dragLeave(event as DragEvent));
}

/**
* Validates that the given index is not lower than 0 or higher than the amount of blocks
* @param {number} index - index of blocks array to validate
*/
private validateIndex(index: number): boolean {
if (index < 0 || index >= this._blocks.length) {
return false;
}

return true;
}
}
8 changes: 8 additions & 0 deletions types/api/blocks.d.ts
Original file line number Diff line number Diff line change
@@ -33,9 +33,17 @@ export interface Blocks {
* Swaps two Blocks
* @param {number} fromIndex - block to swap
* @param {number} toIndex - block to swap with
* @deprecated — use 'move' instead
*/
swap(fromIndex: number, toIndex: number): void;

/**
* Moves a block to a new index
* @param {number} toIndex - index where the block is moved to
* @param {number} fromIndex - block to move
*/
move(toIndex: number, fromIndex?: number): void;

/**
* Returns Block holder by Block index
* @param {number} index
20 changes: 13 additions & 7 deletions types/tools/block-tool.d.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {ConversionConfig, PasteConfig, SanitizerConfig} from '../configs';
import {BlockToolData} from './block-tool-data';
import {BaseTool, BaseToolConstructable} from './tool';
import {ToolConfig} from './tool-config';
import {API} from '../index';
import {PasteEvent} from './paste-events';
import { ConversionConfig, PasteConfig, SanitizerConfig } from '../configs';
import { BlockToolData } from './block-tool-data';
import { BaseTool, BaseToolConstructable } from './tool';
import { ToolConfig } from './tool-config';
import { API } from '../index';
import { PasteEvent } from './paste-events';
import { MoveEvent } from './hook-events';
/**
* Describe Block Tool object
* @see {@link docs/tools.md}
@@ -65,6 +66,11 @@ export interface BlockTool extends BaseTool {
* Called after block removed from the page but before instance is deleted
*/
removed?(): void;

/**
* Called after block was moved
*/
moved?(event: MoveEvent): void;
}

export interface BlockToolConstructable extends BaseToolConstructable {
@@ -97,5 +103,5 @@ export interface BlockToolConstructable extends BaseToolConstructable {
* @constructor
* @return {BlockTool}
*/
new (config: {api: API, config: ToolConfig, data: BlockToolData}): BlockTool;
new(config: { api: API, config: ToolConfig, data: BlockToolData }): BlockTool;
}
23 changes: 23 additions & 0 deletions types/tools/hook-events.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
* Event detail for block relocation
*/
export interface MoveEventDetail {
/**
* index the block was moved from
*/
fromIndex: number;
/**
* index the block was moved to
*/
toIndex: number;
}

/**
* Move event for block relocation
*/
export interface MoveEvent extends CustomEvent {
/**
* Override detail property of CustomEvent by MoveEvent hook
*/
readonly detail: MoveEventDetail;
}
1 change: 1 addition & 0 deletions types/tools/index.d.ts
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ export * from './tool';
export * from './tool-config';
export * from './tool-settings';
export * from './paste-events';
export * from './hook-events';

export type Tool = BaseTool | BlockTool | InlineTool;
export type ToolConstructable = BaseToolConstructable | BlockToolConstructable | InlineToolConstructable;