Skip to content

Commit 49516dd

Browse files
ranemihirneSpeccgohaberegtasuku-sathul7744
authored
Rename initialBlock to defaultBlock (#1209)
* [Improvements] ESLint action (#1099) * TSLint -> ESLint, GitHub Action * Update eslint.yml * Autofix * more autofix * fix * manually fix some issues * Update CHANGELOG.md * [Refactor] ESLint fixed (#1100) Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * [Feature] i18n (#1106) * i18n first steps * i18n internal, toolbox, api for tools * namespaced api * tn, t * tn in block tunes * join toolbox and inlineTools under toolNames * translations * make enum toolTypes * Update block.ts * Update src/components/core.ts Co-Authored-By: George Berezhnoy <gohabereg@users.noreply.github.com> * add more types * rm tn * export i18n types * upd bundle * fix tabulation * Add type-safe namespaces * upd * Improve example * Update toolbox.ts * improve examplle * upd * fix typo * Add comments for complex types Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com> Co-authored-by: Georgy Berezhnoy <gohabereg@gmail.com> * Remove unused submodule * Fixed: icon centering in Firefox * Do not load styles twice (#1112) * Do not load styles twice * Add changelog * Fix issue link Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Show warning if Block to delete is not found (#1111) Resolves #1102 * Save Tools' order in the Toolbox (#1113) Resolves #1073 * fix $.isEmpty performance (#1096) * fix $.isEmpty performance * add changelog * upd bundle Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Add issue templates (#1114) * Update issue templates (#1121) * Update issue templates * Apply suggestions from code review Co-Authored-By: George Berezhnoy <gohabereg@users.noreply.github.com> * upd texts * Update feature_request.md * Update .github/ISSUE_TEMPLATE/discussion.md Co-Authored-By: George Berezhnoy <gohabereg@users.noreply.github.com> Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com> * Allowing deleting block by block id (#1108) * Allowing deleting block by block id * Fixed no argument error * Making index value optional for delete operation * Added to changelog * Making index value optional for delete operation * Added parameter description * Update docs/CHANGELOG.md * Update types/api/blocks.d.ts * Update editor.js Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Allow navigate next from last non-initial block (#1110) Resolves #1103 * Create CODE_OF_CONDUCT.md (#1171) * Create CODE_OF_CONDUCT.md * Update changelog file * Update dependencies (#1122) * Update dependencies * upd codex.tooltip * Update editor.js.LICENSE.txt Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Feature/disable tab event config (#1164) * Highlight first block on autofocus (#1127) * Fix shortcut for external tools (#1141) * fix/shortcut-for-external-tools * Check inline tools property for shortcut Co-authored-by: George Berezhnoy <gohabereg@gmail.com> * Hotfix/issue1133 selection shortcut removed on editor destroy (#1140) * Removed shortcut CMD+A on editor destroy #1133 * Removed patch version and made code cleaner #1133 * lint error fixes #1133 Co-authored-by: Sisir <sisir@hellosivi.com> Co-authored-by: George Berezhnoy <gohabereg@gmail.com> * [Feature] BlockAPI Interface (#1075) * Fix BlockManager.insert method (#1172) * Fix BlockManager.insert method * upd * Explicitly check for undefined * Update tools master branches (#1180) * Update master branches * Update image * Update CHANGELOG.md * Fix behaviour of inputs editing in block settings (#1123) * lint code * Update CHANGELOG.md * Rename initialBlock to defaultBlock Closes #993 The initialBlock property is renamed to defaultBlock. * Change keyword 'InitialBlock' to 'DefaultBlock' in all methods Fixes #993 All the methods using the keyword 'Initial' or 'initial' for initial block are replace with 'Default' or 'default'. For example, the Tools.isIntitial() method is changed to Tools.isDefault(). * Keep initialBlock and defaultBlock both. initialBlock property is still kept but it will deprecated in the next major release. * Change defaultBlock in example.html and rebuild. * Remove package-lock.json file. * Update docs/tools.md Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update example/example-dev.html Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update example/example.html Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update example/example-dev.html Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update example/example.html Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update src/components/utils.ts Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update src/components/utils.ts Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update types/configs/editor-config.d.ts Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update types/configs/editor-config.d.ts Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Update src/components/utils.ts Co-authored-by: Peter Savchenko <specc.dev@gmail.com> * Fix needAddDefaultBlock to needToAddDefaultBlock * Add as an Improvement to CHANGELOG.md * Delete editor.js.map * fix log, rename some more places * Update example.html * Update blockManager.ts Co-authored-by: Peter Savchenko <specc.dev@gmail.com> Co-authored-by: George Berezhnoy <gohabereg@users.noreply.github.com> Co-authored-by: Georgy Berezhnoy <gohabereg@gmail.com> Co-authored-by: tasuku-s <tasuku@freemind.co.jp> Co-authored-by: Athul Anil Kumar <athul7744@outlook.com> Co-authored-by: Taly <vitalik7tv@yandex.ru> Co-authored-by: flaming-cl <51183663+flaming-cl@users.noreply.github.com> Co-authored-by: Nguyen Ngoc Son <sonnn.se@gmail.com> Co-authored-by: Sisir Das K <37764463+sis-dk@users.noreply.github.com> Co-authored-by: Sisir <sisir@hellosivi.com>
1 parent 05c675c commit 49516dd

File tree

17 files changed

+98
-73
lines changed

17 files changed

+98
-73
lines changed

dist/editor.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### 2.19
44

5+
- `Improvements` - The `initialBlock` property of Editor config is deprecated. Use the `defaultBlock` instead. [#993](https://github.com/codex-team/editor.js/issues/993)
56
- `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)
67
- `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)
78

docs/tools.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ var editor = new EditorJS({
7878
},
7979
header: Header
8080
},
81-
initialBlock : 'text',
81+
defaultBlock : 'text',
8282
});
8383
```
8484

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

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

123123
> Example
124124
@@ -144,7 +144,7 @@ Your Tool can analyze text by RegExp patterns to substitute pasted string with d
144144

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

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

149149
> Example
150150

example/example-dev.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@
167167
/**
168168
* This Tool will be used as default
169169
*/
170-
// initialBlock: 'paragraph',
170+
// defaultBlock: 'paragraph',
171171

172172
/**
173173
* Initial Editor data

example/example.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
/**
157157
* This Tool will be used as default
158158
*/
159-
// initialBlock: 'paragraph',
159+
// defaultBlock: 'paragraph',
160160

161161
/**
162162
* Initial Editor data

src/components/core.ts

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,10 @@ export default class Core {
130130
/**
131131
* If holderId is preset, assign him to holder property and work next only with holder
132132
*/
133+
_.deprecationAssert(!!config.holderId, 'config.holderId', 'config.holder');
133134
if (config.holderId && !config.holder) {
134135
config.holder = config.holderId;
135136
config.holderId = null;
136-
_.log('holderId property is deprecated and will be removed in the next major release. ' +
137-
'Use holder property instead.', 'warn');
138137
}
139138

140139
/**
@@ -157,10 +156,13 @@ export default class Core {
157156

158157
_.setLogLevel(this.config.logLevel);
159158

159+
160160
/**
161-
* If initial Block's Tool was not passed, use the Paragraph Tool
161+
* If default Block's Tool was not passed, use the Paragraph Tool
162162
*/
163-
this.config.initialBlock = this.config.initialBlock || 'paragraph';
163+
_.deprecationAssert(Boolean(this.config.initialBlock), 'config.initialBlock', 'config.defaultBlock');
164+
this.config.defaultBlock = this.config.defaultBlock || this.config.initialBlock || 'paragraph';
165+
164166

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

172174
/**
173-
* Initial block type
175+
* Default block type
174176
* Uses in case when there is no blocks passed
175177
*
176178
* @type {{type: (*), data: {text: null}}}
177179
*/
178-
const initialBlockData = {
179-
type: this.config.initialBlock,
180+
const defaultBlockData = {
181+
type: this.config.defaultBlock,
180182
data: {},
181183
};
182184

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

198200
/**
199-
* Initialize Blocks to pass data to the Renderer
201+
* Initialize default Block to pass data to the Renderer
200202
*/
201203
if (_.isEmpty(this.config.data)) {
202204
this.config.data = {} as OutputData;
203-
this.config.data.blocks = [ initialBlockData ];
205+
this.config.data.blocks = [ defaultBlockData ];
204206
} else {
205207
if (!this.config.data.blocks || this.config.data.blocks.length === 0) {
206-
this.config.data.blocks = [ initialBlockData ];
208+
this.config.data.blocks = [ defaultBlockData ];
207209
}
208210
}
209211

src/components/modules/api/blocks.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ export default class BlocksAPI extends Module {
118118

119119
/**
120120
* in case of last block deletion
121-
* Insert new initial empty block
121+
* Insert the new default empty block
122122
*/
123123
if (this.Editor.BlockManager.blocks.length === 0) {
124124
this.Editor.BlockManager.insert();
@@ -172,10 +172,10 @@ export default class BlocksAPI extends Module {
172172
* @deprecated Use BlockAPI interface to stretch Blocks
173173
*/
174174
public stretchBlock(index: number, status = true): void {
175-
_.log(
176-
'`blocks.stretchBlock()` method is deprecated and will be removed in the next major release. ' +
177-
'Use BlockAPI interface instead',
178-
'warn'
175+
_.deprecationAssert(
176+
true,
177+
'blocks.stretchBlock()',
178+
'BlockAPI'
179179
);
180180

181181
const block = this.Editor.BlockManager.getBlockByIndex(index);
@@ -197,7 +197,7 @@ export default class BlocksAPI extends Module {
197197
* @param {boolean?} needToFocus - flag to focus inserted Block
198198
*/
199199
public insert = (
200-
type: string = this.config.initialBlock,
200+
type: string = this.config.defaultBlock,
201201
data: BlockToolData = {},
202202
config: ToolConfig = {},
203203
index?: number,

src/components/modules/blockEvents.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,12 +140,12 @@ export default class BlockEvents extends Module {
140140
return;
141141
}
142142

143-
const canOpenToolbox = Tools.isInitial(currentBlock.tool) && currentBlock.isEmpty;
143+
const canOpenToolbox = Tools.isDefault(currentBlock.tool) && currentBlock.isEmpty;
144144
const conversionToolbarOpened = !currentBlock.isEmpty && ConversionToolbar.opened;
145145
const inlineToolbarOpened = !currentBlock.isEmpty && !SelectionUtils.isCollapsed && InlineToolbar.opened;
146146

147147
/**
148-
* For empty Blocks we show Plus button via Toolbox only for initial Blocks
148+
* For empty Blocks we show Plus button via Toolbox only for default Blocks
149149
*/
150150
if (canOpenToolbox) {
151151
this.activateToolbox();
@@ -209,7 +209,7 @@ export default class BlockEvents extends Module {
209209

210210
const selectionPositionIndex = BlockManager.removeSelectedBlocks();
211211

212-
Caret.setToBlock(BlockManager.insertInitialBlockAtIndex(selectionPositionIndex, true), Caret.positions.START);
212+
Caret.setToBlock(BlockManager.insertDefaultBlockAtIndex(selectionPositionIndex, true), Caret.positions.START);
213213

214214
/** Clear selection */
215215
BlockSelection.clearSelection(event);
@@ -254,7 +254,7 @@ export default class BlockEvents extends Module {
254254
* If enter has been pressed at the start of the text, just insert paragraph Block above
255255
*/
256256
if (this.Editor.Caret.isAtStart && !this.Editor.BlockManager.currentBlock.hasMedia) {
257-
this.Editor.BlockManager.insertInitialBlockAtIndex(this.Editor.BlockManager.currentBlockIndex);
257+
this.Editor.BlockManager.insertDefaultBlockAtIndex(this.Editor.BlockManager.currentBlockIndex);
258258
} else {
259259
/**
260260
* Split the Current Block into two blocks
@@ -268,7 +268,7 @@ export default class BlockEvents extends Module {
268268
/**
269269
* If new Block is empty
270270
*/
271-
if (this.Editor.Tools.isInitial(newCurrent.tool) && newCurrent.isEmpty) {
271+
if (this.Editor.Tools.isDefault(newCurrent.tool) && newCurrent.isEmpty) {
272272
/**
273273
* Show Toolbar
274274
*/

src/components/modules/blockManager.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ export default class BlockManager extends Module {
230230
* Insert new block into _blocks
231231
*
232232
* @param {object} options - insert options
233-
* @param {string} options.tool - plugin name, by default method inserts initial block type
233+
* @param {string} options.tool - plugin name, by default method inserts the default block type
234234
* @param {object} options.data - plugin data
235235
* @param {number} options.index - index where to insert new Block
236236
* @param {boolean} options.needToFocus - flag shows if needed to update current Block index
@@ -239,7 +239,7 @@ export default class BlockManager extends Module {
239239
* @returns {Block}
240240
*/
241241
public insert({
242-
tool = this.config.initialBlock,
242+
tool = this.config.defaultBlock,
243243
data = {},
244244
index,
245245
needToFocus = true,
@@ -283,7 +283,7 @@ export default class BlockManager extends Module {
283283
* @returns {Block}
284284
*/
285285
public replace({
286-
tool = this.config.initialBlock,
286+
tool = this.config.defaultBlock,
287287
data = {},
288288
}): Block {
289289
return this.insert({
@@ -321,7 +321,7 @@ export default class BlockManager extends Module {
321321
}
322322

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

336336
this._blocks[index] = block;
337337

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

358358
/**
359-
* Insert initial typed block
359+
* Insert the default typed block
360360
*/
361361
return this.insert();
362362
}
@@ -443,7 +443,7 @@ export default class BlockManager extends Module {
443443

444444
/**
445445
* Attention!
446-
* After removing insert new initial typed Block and focus on it
446+
* After removing insert the new default typed Block and focus on it
447447
* Removes all blocks
448448
*/
449449
public removeAllBlocks(): void {
@@ -649,15 +649,15 @@ export default class BlockManager extends Module {
649649
/**
650650
* Clears Editor
651651
*
652-
* @param {boolean} needAddInitialBlock - 1) in internal calls (for example, in api.blocks.render)
653-
* we don't need to add empty initial block
652+
* @param {boolean} needToAddDefaultBlock - 1) in internal calls (for example, in api.blocks.render)
653+
* we don't need to add an empty default block
654654
* 2) in api.blocks.clear we should add empty block
655655
*/
656-
public clear(needAddInitialBlock = false): void {
656+
public clear(needToAddDefaultBlock = false): void {
657657
this._blocks.removeAll();
658658
this.dropPointer();
659659

660-
if (needAddInitialBlock) {
660+
if (needToAddDefaultBlock) {
661661
this.insert();
662662
}
663663

src/components/modules/blockSelection.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ export default class BlockSelection extends Module {
198198
if (this.anyBlockSelected && isKeyboard && isPrintableKey && !SelectionUtils.isSelectionExists) {
199199
const indexToInsert = BlockManager.removeSelectedBlocks();
200200

201-
BlockManager.insertInitialBlockAtIndex(indexToInsert, true);
201+
BlockManager.insertDefaultBlockAtIndex(indexToInsert, true);
202202
Caret.setToBlock(BlockManager.currentBlock);
203203
_.delay(() => {
204204
Caret.insertContentAtCaretPosition((reason as KeyboardEvent).key);

0 commit comments

Comments
 (0)