-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(merge): blocks of different types can be merged (#2671)
* feature: possibilities to merge blocks of different types * fix: remove scope change * feat: use convert config instead of defined property * chore:: use built-in function for type check * fix: remove console.log * chore: remove styling added by mistakes * test: add testing for different blocks types merging * fix: remove unused import * fix: remove type argument * fix: use existing functions for data export * chore: update changelog * fix: re put await * fix: remove unnecessary check * fix: typo in test name * fix: re-add condition for merge * test: add caret position test * fix caret issues, add sanitize * make if-else statement more clear * upgrade cypress * Update cypress.yml * upd cypress to 13 * make sanitize test simpler * patch rc version --------- Co-authored-by: GuillaumeOnepilot <guillaume@onepilot.co> Co-authored-by: Guillaume Leon <97881811+GuillaumeOnepilot@users.noreply.github.com>
- Loading branch information
1 parent
b355f16
commit 1320b04
Showing
12 changed files
with
571 additions
and
140 deletions.
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.