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 initialBlock to defaultBlock #1209

Merged
merged 49 commits into from
Aug 18, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
49 commits
Select commit Hold shift + click to select a range
f5e9a66
[Improvements] ESLint action (#1099)
neSpecc Apr 11, 2020
4c0d806
[Refactor] ESLint fixed (#1100)
gohabereg Apr 18, 2020
21cac86
[Feature] i18n (#1106)
neSpecc Apr 20, 2020
775ccbc
Remove unused submodule
tasuku-s Apr 23, 2020
f4c4051
Fixed: icon centering in Firefox
neSpecc Apr 25, 2020
2997ed0
Do not load styles twice (#1112)
gohabereg Apr 25, 2020
4a81699
Show warning if Block to delete is not found (#1111)
gohabereg Apr 25, 2020
7eb642d
Save Tools' order in the Toolbox (#1113)
gohabereg Apr 25, 2020
72213f2
fix $.isEmpty performance (#1096)
tasuku-s Apr 25, 2020
7f876e8
Add issue templates (#1114)
gohabereg Apr 25, 2020
66e70fa
Update issue templates (#1121)
neSpecc Apr 25, 2020
5218a6a
Allowing deleting block by block id (#1108)
athul7744 Apr 25, 2020
ae8591c
Allow navigate next from last non-initial block (#1110)
gohabereg Apr 25, 2020
f6b7b2e
Create CODE_OF_CONDUCT.md (#1171)
talyguryn May 27, 2020
e3410be
Update dependencies (#1122)
gohabereg May 27, 2020
b0ddb10
Feature/disable tab event config (#1164)
flaming-cl May 27, 2020
1eb6d81
Highlight first block on autofocus (#1127)
gohabereg May 27, 2020
5fe8b08
Fix shortcut for external tools (#1141)
sonnn May 27, 2020
7c3bf76
Hotfix/issue1133 selection shortcut removed on editor destroy (#1140)
sis-dk May 27, 2020
ffe5bbc
[Feature] BlockAPI Interface (#1075)
gohabereg May 27, 2020
ff6bd2d
Fix BlockManager.insert method (#1172)
gohabereg Jun 2, 2020
e1500f7
Update tools master branches (#1180)
talyguryn Jun 2, 2020
26b19a3
Fix behaviour of inputs editing in block settings (#1123)
gohabereg Jun 2, 2020
8341c33
Merge branch 'master' into release/2.18
neSpecc Jun 2, 2020
239aaf6
lint code
neSpecc Jun 3, 2020
4cea66f
Update CHANGELOG.md
neSpecc Jun 3, 2020
d2904ee
Rename initialBlock to defaultBlock
ranemihir Jun 19, 2020
4966710
Change keyword 'InitialBlock' to 'DefaultBlock' in all methods
ranemihir Jun 19, 2020
5275699
Merge branch 'next' of github.com:codex-team/editor.js into pr/1209
gohabereg Jul 26, 2020
8a23905
Keep initialBlock and defaultBlock both.
ranemihir Aug 6, 2020
d0aefe1
Change defaultBlock in example.html and rebuild.
ranemihir Aug 6, 2020
0683a46
Remove package-lock.json file.
ranemihir Aug 6, 2020
bdd0d83
Update docs/tools.md
ranemihir Aug 13, 2020
480d492
Update example/example-dev.html
ranemihir Aug 13, 2020
f7b8f41
Update example/example.html
ranemihir Aug 13, 2020
471568d
Update example/example-dev.html
ranemihir Aug 13, 2020
6067979
Update example/example.html
ranemihir Aug 13, 2020
4bccc5a
Update src/components/utils.ts
ranemihir Aug 13, 2020
244e8f2
Update src/components/utils.ts
ranemihir Aug 13, 2020
9b79daa
Update types/configs/editor-config.d.ts
ranemihir Aug 13, 2020
8db75c2
Update types/configs/editor-config.d.ts
ranemihir Aug 13, 2020
eb61ce8
Update src/components/utils.ts
ranemihir Aug 13, 2020
88f686e
Fix needAddDefaultBlock to needToAddDefaultBlock
ranemihir Aug 13, 2020
04d4d7a
Add as an Improvement to CHANGELOG.md
ranemihir Aug 14, 2020
4af93a1
Merge branch 'next' into pr/1209
neSpecc Aug 18, 2020
16cefe5
Delete editor.js.map
neSpecc Aug 18, 2020
9cec09e
fix log, rename some more places
neSpecc Aug 18, 2020
b7ff6c1
Update example.html
neSpecc Aug 18, 2020
56c09b6
Update blockManager.ts
neSpecc Aug 18, 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
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 @@ -2,6 +2,7 @@

### 2.19

- `Improvements` - The `initialBlock` property of Editor config is deprecated. Use the `defaultBlock` instead. [#993](https://github.com/codex-team/editor.js/issues/993)
- `Fix` - Fixed the issue of toolbar not disappearing on entering input in Chinese, Hindi and some other languages. [#1196](https://github.com/codex-team/editor.js/issues/1196)
- `Improvements` - BlockAPI `call()` method now returns the result of calling method, thus allowing it to expose arbitrary data as needed [#1205](https://github.com/codex-team/editor.js/pull/1205)

Expand Down
6 changes: 3 additions & 3 deletions docs/tools.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ var editor = new EditorJS({
},
header: Header
},
initialBlock : 'text',
defaultBlock : 'text',
});
```

Expand Down Expand Up @@ -118,7 +118,7 @@ To handle pasted HTML elements object returned from `pasteConfig` getter should
| -- | -- | -- |
| `tags` | `String[]` | _Optional_. Should contain all tag names you want to be extracted from pasted data and processed by your `onPaste` method |

For correct work you MUST provide `onPaste` handler at least for `initialBlock` Tool.
For correct work you MUST provide `onPaste` handler at least for `defaultBlock` Tool.

> Example

Expand All @@ -144,7 +144,7 @@ Your Tool can analyze text by RegExp patterns to substitute pasted string with d

**Note** Editor will check pattern's full match, so don't forget to handle all available chars in there.

Pattern will be processed only if paste was on `initialBlock` Tool and pasted string length is less than 450 characters.
Pattern will be processed only if paste was on `defaultBlock` Tool and pasted string length is less than 450 characters.

> Example

Expand Down
2 changes: 1 addition & 1 deletion example/example-dev.html
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@
/**
* This Tool will be used as default
*/
// initialBlock: 'paragraph',
// defaultBlock: 'paragraph',

/**
* Initial Editor data
Expand Down
2 changes: 1 addition & 1 deletion example/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@
/**
* This Tool will be used as default
*/
// initialBlock: 'paragraph',
// defaultBlock: 'paragraph',

/**
* Initial Editor data
Expand Down
22 changes: 12 additions & 10 deletions src/components/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,10 @@ export default class Core {
/**
* If holderId is preset, assign him to holder property and work next only with holder
*/
_.deprecationAssert(!!config.holderId, 'config.holderId', 'config.holder');
if (config.holderId && !config.holder) {
config.holder = config.holderId;
config.holderId = null;
_.log('holderId property is deprecated and will be removed in the next major release. ' +
'Use holder property instead.', 'warn');
}

/**
Expand All @@ -157,10 +156,13 @@ export default class Core {

_.setLogLevel(this.config.logLevel);


/**
* If initial Block's Tool was not passed, use the Paragraph Tool
* If default Block's Tool was not passed, use the Paragraph Tool
*/
this.config.initialBlock = this.config.initialBlock || 'paragraph';
_.deprecationAssert(Boolean(this.config.initialBlock), 'config.initialBlock', 'config.defaultBlock');
this.config.defaultBlock = this.config.defaultBlock || this.config.initialBlock || 'paragraph';


/**
* Height of Editor's bottom area that allows to set focus on the last Block
Expand All @@ -170,13 +172,13 @@ export default class Core {
this.config.minHeight = this.config.minHeight !== undefined ? this.config.minHeight : 300;

/**
* Initial block type
* Default block type
* Uses in case when there is no blocks passed
*
* @type {{type: (*), data: {text: null}}}
*/
const initialBlockData = {
type: this.config.initialBlock,
const defaultBlockData = {
type: this.config.defaultBlock,
data: {},
};

Expand All @@ -196,14 +198,14 @@ export default class Core {
this.config.onChange = this.config.onChange || ((): void => {});

/**
* Initialize Blocks to pass data to the Renderer
* Initialize default Block to pass data to the Renderer
*/
if (_.isEmpty(this.config.data)) {
this.config.data = {} as OutputData;
this.config.data.blocks = [ initialBlockData ];
this.config.data.blocks = [ defaultBlockData ];
} else {
if (!this.config.data.blocks || this.config.data.blocks.length === 0) {
this.config.data.blocks = [ initialBlockData ];
this.config.data.blocks = [ defaultBlockData ];
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/components/modules/api/blocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default class BlocksAPI extends Module {

/**
* in case of last block deletion
* Insert new initial empty block
* Insert the new default empty block
*/
if (this.Editor.BlockManager.blocks.length === 0) {
this.Editor.BlockManager.insert();
Expand Down Expand Up @@ -172,10 +172,10 @@ export default class BlocksAPI extends Module {
* @deprecated Use BlockAPI interface to stretch Blocks
*/
public stretchBlock(index: number, status = true): void {
_.log(
'`blocks.stretchBlock()` method is deprecated and will be removed in the next major release. ' +
'Use BlockAPI interface instead',
'warn'
_.deprecationAssert(
true,
'blocks.stretchBlock()',
'BlockAPI'
);

const block = this.Editor.BlockManager.getBlockByIndex(index);
Expand All @@ -197,7 +197,7 @@ export default class BlocksAPI extends Module {
* @param {boolean?} needToFocus - flag to focus inserted Block
*/
public insert = (
type: string = this.config.initialBlock,
type: string = this.config.defaultBlock,
data: BlockToolData = {},
config: ToolConfig = {},
index?: number,
Expand Down
10 changes: 5 additions & 5 deletions src/components/modules/blockEvents.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,12 +140,12 @@ export default class BlockEvents extends Module {
return;
}

const canOpenToolbox = Tools.isInitial(currentBlock.tool) && currentBlock.isEmpty;
const canOpenToolbox = Tools.isDefault(currentBlock.tool) && currentBlock.isEmpty;
const conversionToolbarOpened = !currentBlock.isEmpty && ConversionToolbar.opened;
const inlineToolbarOpened = !currentBlock.isEmpty && !SelectionUtils.isCollapsed && InlineToolbar.opened;

/**
* For empty Blocks we show Plus button via Toolbox only for initial Blocks
* For empty Blocks we show Plus button via Toolbox only for default Blocks
*/
if (canOpenToolbox) {
this.activateToolbox();
Expand Down Expand Up @@ -209,7 +209,7 @@ export default class BlockEvents extends Module {

const selectionPositionIndex = BlockManager.removeSelectedBlocks();

Caret.setToBlock(BlockManager.insertInitialBlockAtIndex(selectionPositionIndex, true), Caret.positions.START);
Caret.setToBlock(BlockManager.insertDefaultBlockAtIndex(selectionPositionIndex, true), Caret.positions.START);

/** Clear selection */
BlockSelection.clearSelection(event);
Expand Down Expand Up @@ -254,7 +254,7 @@ export default class BlockEvents extends Module {
* If enter has been pressed at the start of the text, just insert paragraph Block above
*/
if (this.Editor.Caret.isAtStart && !this.Editor.BlockManager.currentBlock.hasMedia) {
this.Editor.BlockManager.insertInitialBlockAtIndex(this.Editor.BlockManager.currentBlockIndex);
this.Editor.BlockManager.insertDefaultBlockAtIndex(this.Editor.BlockManager.currentBlockIndex);
} else {
/**
* Split the Current Block into two blocks
Expand All @@ -268,7 +268,7 @@ export default class BlockEvents extends Module {
/**
* If new Block is empty
*/
if (this.Editor.Tools.isInitial(newCurrent.tool) && newCurrent.isEmpty) {
if (this.Editor.Tools.isDefault(newCurrent.tool) && newCurrent.isEmpty) {
/**
* Show Toolbar
*/
Expand Down
24 changes: 12 additions & 12 deletions src/components/modules/blockManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export default class BlockManager extends Module {
* Insert new block into _blocks
*
* @param {object} options - insert options
* @param {string} options.tool - plugin name, by default method inserts initial block type
* @param {string} options.tool - plugin name, by default method inserts the default block type
* @param {object} options.data - plugin data
* @param {number} options.index - index where to insert new Block
* @param {boolean} options.needToFocus - flag shows if needed to update current Block index
Expand All @@ -239,7 +239,7 @@ export default class BlockManager extends Module {
* @returns {Block}
*/
public insert({
tool = this.config.initialBlock,
tool = this.config.defaultBlock,
data = {},
index,
needToFocus = true,
Expand Down Expand Up @@ -283,7 +283,7 @@ export default class BlockManager extends Module {
* @returns {Block}
*/
public replace({
tool = this.config.initialBlock,
tool = this.config.defaultBlock,
data = {},
}): Block {
return this.insert({
Expand Down Expand Up @@ -321,7 +321,7 @@ export default class BlockManager extends Module {
}

/**
* Insert new initial block at passed index
* Insert new default block at passed index
*
* @param {number} index - index where Block should be inserted
* @param {boolean} needToFocus - if true, updates current Block index
Expand All @@ -330,8 +330,8 @@ export default class BlockManager extends Module {
*
* @returns {Block} inserted Block
*/
public insertInitialBlockAtIndex(index: number, needToFocus = false): Block {
const block = this.composeBlock({ tool: this.config.initialBlock });
public insertDefaultBlockAtIndex(index: number, needToFocus = false): Block {
const block = this.composeBlock({ tool: this.config.defaultBlock });

this._blocks[index] = block;

Expand All @@ -356,7 +356,7 @@ export default class BlockManager extends Module {
this.currentBlockIndex = this.blocks.length - 1;

/**
* Insert initial typed block
* Insert the default typed block
*/
return this.insert();
}
Expand Down Expand Up @@ -443,7 +443,7 @@ export default class BlockManager extends Module {

/**
* Attention!
* After removing insert new initial typed Block and focus on it
* After removing insert the new default typed Block and focus on it
* Removes all blocks
*/
public removeAllBlocks(): void {
Expand Down Expand Up @@ -649,15 +649,15 @@ export default class BlockManager extends Module {
/**
* Clears Editor
*
* @param {boolean} needAddInitialBlock - 1) in internal calls (for example, in api.blocks.render)
* we don't need to add empty initial block
* @param {boolean} needToAddDefaultBlock - 1) in internal calls (for example, in api.blocks.render)
* we don't need to add an empty default block
* 2) in api.blocks.clear we should add empty block
*/
public clear(needAddInitialBlock = false): void {
public clear(needToAddDefaultBlock = false): void {
this._blocks.removeAll();
this.dropPointer();

if (needAddInitialBlock) {
if (needToAddDefaultBlock) {
this.insert();
}

Expand Down
2 changes: 1 addition & 1 deletion src/components/modules/blockSelection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ export default class BlockSelection extends Module {
if (this.anyBlockSelected && isKeyboard && isPrintableKey && !SelectionUtils.isSelectionExists) {
const indexToInsert = BlockManager.removeSelectedBlocks();

BlockManager.insertInitialBlockAtIndex(indexToInsert, true);
BlockManager.insertDefaultBlockAtIndex(indexToInsert, true);
Caret.setToBlock(BlockManager.currentBlock);
_.delay(() => {
Caret.insertContentAtCaretPosition((reason as KeyboardEvent).key);
Expand Down
12 changes: 6 additions & 6 deletions src/components/modules/caret.ts
Original file line number Diff line number Diff line change
Expand Up @@ -330,10 +330,10 @@ export default class Caret extends Module {
}

/**
* If last block is empty and it is an initialBlock, set to that.
* If last block is empty and it is an defaultBlock, set to that.
* Otherwise, append new empty block and set to that
*/
if (this.Editor.Tools.isInitial(lastBlock.tool) && lastBlock.isEmpty) {
if (this.Editor.Tools.isDefault(lastBlock.tool) && lastBlock.isEmpty) {
this.setToBlock(lastBlock);
} else {
const newBlock = this.Editor.BlockManager.insertAtEnd();
Expand Down Expand Up @@ -383,15 +383,15 @@ export default class Caret extends Module {

if (!nextBlock && !nextInput) {
/**
* If there is no nextBlock and currentBlock is initial, do not navigate
* If there is no nextBlock and currentBlock is default, do not navigate
*/
if (Tools.isInitial(currentBlock.tool)) {
if (Tools.isDefault(currentBlock.tool)) {
return false;
}

/**
* If there is no nextBlock, but currentBlock is not initial,
* insert new initial block at the end and navigate to it
* If there is no nextBlock, but currentBlock is not default,
* insert new default block at the end and navigate to it
*/
nextBlock = BlockManager.insertAtEnd();
}
Expand Down
Loading