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

[Feature] Block Tunes API #1596

Merged
merged 29 commits into from
Apr 4, 2021
Merged
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
24dc069
Add internal wrappers for tools classes
gohabereg Mar 14, 2021
224dd3b
FIx lint
gohabereg Mar 14, 2021
83e17bb
Change tools collections to map
gohabereg Mar 15, 2021
1ffcbed
Apply some more refactoring
gohabereg Mar 15, 2021
3d743f3
Make tool instance private field
gohabereg Mar 15, 2021
e56579c
Add some docs
gohabereg Mar 15, 2021
0069a2a
Fix eslint
gohabereg Mar 15, 2021
d407e32
Basic implementation for Block Tunes
gohabereg Mar 15, 2021
a0160ef
Small fix for demo
gohabereg Mar 15, 2021
dde3bd4
Review changes
gohabereg Mar 16, 2021
28bfacf
Merge branch 'next' of github.com:codex-team/editor.js into reafctori…
gohabereg Mar 16, 2021
ca1aef3
Fix
gohabereg Mar 16, 2021
a459ab5
Merge branch 'reafctoring/tools' of github.com:codex-team/editor.js i…
gohabereg Mar 16, 2021
6ecc3ac
Add common tunes and ToolsCollection class
gohabereg Mar 17, 2021
1f9c5f1
Fixes after review
gohabereg Mar 18, 2021
c81b9a0
Merge branch 'reafctoring/tools' of github.com:codex-team/editor.js i…
gohabereg Mar 18, 2021
b8ba38c
Rename tools collections
gohabereg Mar 18, 2021
aea3158
Readonly fix
gohabereg Mar 18, 2021
82f3bfa
Merge branch 'reafctoring/tools' of github.com:codex-team/editor.js i…
gohabereg Mar 18, 2021
a3bb039
Some fixes after review
gohabereg Mar 27, 2021
41274fb
Merge branch 'next' of github.com:codex-team/editor.js into feature/b…
gohabereg Mar 31, 2021
13b64eb
Apply suggestions from code review
gohabereg Apr 2, 2021
4e9a098
Fixes after review
gohabereg Apr 2, 2021
ebc8b3f
Add docs and changelog
gohabereg Apr 2, 2021
cad9691
Update docs/block-tunes.md
gohabereg Apr 2, 2021
66feab7
Apply suggestions from code review
gohabereg Apr 2, 2021
8ce77a8
Update src/components/block/index.ts
gohabereg Apr 4, 2021
94bfd10
[Dev] Tools utils tests (#1602)
gohabereg Apr 4, 2021
5fe699c
Fix test & bump version
gohabereg Apr 4, 2021
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
Some fixes after review
  • Loading branch information
gohabereg committed Mar 27, 2021
commit a3bb039cca1b8050f13141dd3d7d1f227a8df6cf
38 changes: 32 additions & 6 deletions src/components/block/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,20 @@ export default class Block {
*/
private readonly toolInstance: IBlockTool;

/**
* User provided Block Tunes instances
*/
private readonly tunesInstances: Map<string, IBlockTune> = new Map();

/**
* Editor provided Block Tunes instances
*/
private readonly defaultTunesInstances: Map<string, IBlockTune> = new Map();

/**
* If there is saved data for Tune which is not available at the moment,
* we will store it here and provide back on save so data is not lost
*/
private unavailableTunesData: {[name: string]: BlockTuneData} = {};
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand Down Expand Up @@ -544,7 +556,11 @@ export default class Block {
]
.forEach(([name, tune]) => {
if (_.isFunction(tune.save)) {
tunesData[name] = tune.save();
try {
tunesData[name] = tune.save();
} catch (e) {
_.log(`Tune ${tune.constructor.name} save method throws an Error %o`, 'warn', e);
}
}
});

Expand Down Expand Up @@ -686,12 +702,25 @@ export default class Block {

contentNode.appendChild(pluginsContent);

/**
* Block Tunes might wrap Block's content node to provide any UI changes
*
* <tune2wrapper>
* <tune1wrapper>
* <blockContent />
* </tune1wrapper>
* </tune2wrapper>
*/
let wrappedContentNode: HTMLElement = contentNode;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

[...this.tunesInstances.values(), ...this.defaultTunesInstances.values()]
.forEach((tune) => {
if (_.isFunction(tune.wrap)) {
wrappedContentNode = tune.wrap(wrappedContentNode);
try {
wrappedContentNode = tune.wrap(wrappedContentNode);
} catch (e) {
_.log(`Tune ${tune.constructor.name} wrap method throws an Error %o`, 'warn', e);
}
}
});

Expand All @@ -707,10 +736,7 @@ export default class Block {
* @private
*/
private composeTunes(tunesData: {[name: string]: BlockTuneData}): void {
[
...this.tunes.externalTools.values(),
...this.tunes.internalTools.values(),
].forEach((tune) => {
Array.from(this.tunes.values()).forEach((tune) => {
const collection = tune.isInternal ? this.defaultTunesInstances : this.tunesInstances;
neSpecc marked this conversation as resolved.
Show resolved Hide resolved

collection.set(tune.name, tune.instance(tunesData[tune.name], this.blockAPI));
Expand Down