-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
feat(merge): blocks of different types can be merged #2671
Merged
Merged
Changes from all commits
Commits
Show all changes
31 commits
Select commit
Hold shift + click to select a range
bd839d8
feature: possibilities to merge blocks of different types
GuillaumeOnepilot 5f471cd
Merge branch 'next' into feature/merge-block-of-different-types
GuillaumeOnepilot 391e8ed
fix: remove scope change
GuillaumeOnepilot a4b5631
Merge branch 'feature/merge-block-of-different-types' of https://gith…
GuillaumeOnepilot 810935b
feat: use convert config instead of defined property
GuillaumeOnepilot 5daba98
chore:: use built-in function for type check
GuillaumeOnepilot f8460a2
fix: remove console.log
GuillaumeOnepilot 2a32d3e
Merge branch 'next' into feature/merge-block-of-different-types
GuillaumeOnepilot 2074dd1
chore: remove styling added by mistakes
GuillaumeOnepilot 909a8fb
Merge branch 'feature/merge-block-of-different-types' of https://gith…
GuillaumeOnepilot 809503a
test: add testing for different blocks types merging
GuillaumeOnepilot 63703a9
fix: remove unused import
GuillaumeOnepilot d4afe8c
Merge branch 'next' into feature/merge-block-of-different-types
GuillaumeOnepilot f320cf2
Merge branch 'next' into feature/merge-block-of-different-types
GuillaumeOnepilot 887a2ec
fix: remove type argument
GuillaumeOnepilot b7a7042
fix: use existing functions for data export
GuillaumeOnepilot d350cfb
Merge branch 'next' into feature/merge-block-of-different-types
GuillaumeOnepilot d9d6aaf
Merge branch 'feature/merge-block-of-different-types' of https://gith…
GuillaumeOnepilot 58ba673
chore: update changelog
GuillaumeOnepilot f9718ca
fix: re put await
GuillaumeOnepilot 995d5ee
fix: remove unnecessary check
GuillaumeOnepilot 17059d0
fix: typo in test name
GuillaumeOnepilot d59715b
fix: re-add condition for merge
GuillaumeOnepilot f33445a
test: add caret position test
GuillaumeOnepilot 238a1fe
fix caret issues, add sanitize
neSpecc 8da5cfa
make if-else statement more clear
neSpecc 94d6ea5
upgrade cypress
neSpecc c5d5f84
Update cypress.yml
neSpecc ee4f018
upd cypress to 13
neSpecc ebec260
make sanitize test simpler
neSpecc 92c5fb0
patch rc version
neSpecc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import { | ||
BaseTool, | ||
BlockToolConstructorOptions, | ||
BlockToolData, | ||
ConversionConfig | ||
} from '../../../../types'; | ||
|
||
/** | ||
* Simplified Header for testing | ||
*/ | ||
export class SimpleHeader implements BaseTool { | ||
private _data: BlockToolData; | ||
private element: HTMLHeadingElement; | ||
|
||
/** | ||
* | ||
* @param options - constructor options | ||
*/ | ||
constructor({ data }: BlockToolConstructorOptions) { | ||
this._data = data; | ||
} | ||
|
||
/** | ||
* Return Tool's view | ||
* | ||
* @returns {HTMLHeadingElement} | ||
* @public | ||
*/ | ||
public render(): HTMLHeadingElement { | ||
this.element = document.createElement('h1'); | ||
|
||
this.element.contentEditable = 'true'; | ||
this.element.innerHTML = this._data.text; | ||
|
||
return this.element; | ||
} | ||
|
||
/** | ||
* @param data - saved data to merger with current block | ||
*/ | ||
public merge(data: BlockToolData): void { | ||
this.data = { | ||
text: this.data.text + data.text, | ||
level: this.data.level, | ||
}; | ||
} | ||
|
||
/** | ||
* Extract Tool's data from the view | ||
* | ||
* @param toolsContent - Text tools rendered view | ||
*/ | ||
public save(toolsContent: HTMLHeadingElement): BlockToolData { | ||
return { | ||
text: toolsContent.innerHTML, | ||
level: 1, | ||
}; | ||
} | ||
|
||
/** | ||
* Allow Header to be converted to/from other blocks | ||
*/ | ||
public static get conversionConfig(): ConversionConfig { | ||
return { | ||
export: 'text', // use 'text' property for other blocks | ||
import: 'text', // fill 'text' property from other block's export string | ||
}; | ||
} | ||
|
||
/** | ||
* Data getter | ||
*/ | ||
private get data(): BlockToolData { | ||
this._data.text = this.element.innerHTML; | ||
this._data.level = 1; | ||
|
||
return this._data; | ||
} | ||
|
||
/** | ||
* Data setter | ||
*/ | ||
private set data(data: BlockToolData) { | ||
this._data = data; | ||
|
||
if (data.text !== undefined) { | ||
this.element.innerHTML = this._data.text || ''; | ||
} | ||
} | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems
areBlocksMergable
can be used hereThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
areBlockMergeable
is checked beforemergeBlocks
call. I've written these 2 statements explicitly for clarity: first about same-tool merge, second about merging through the conversion