-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bump Rooster to 8.49, content-model to 0.8.0 (#1859)
* Add Size Format Handler to tables (#1838) * add width format handler * Revert "add width format handler" This reverts commit b36f17d. * add size handle to table * add default style override when pasting table * fix test * revert * Remove Table temp elements from Word Online (#1842) * init * fix test * Remove the support of ShadowDOM entity (#1841) * Undo with entity (#1791) * Prototype: Undo with entity * check entity type * Content Model: Only optimize paragraph * do not optimize entity * fix build * Improve * improve * improve * fix test * improve * improve sample entity * fix build * improve * Fix test * Add test * fix test * improve * Content Model: Improve link and heading behavior (#1812) * Improve link and heading behavior * fix build * improve format state, fix test * Make roosterjs work with nodejs 17+ (#1849) * Make roosterjs work with nodejs 17+ * update node version in workflow * Content Model: Fix #1847 (#1848) * Content Model: Fix #1847 * improve * Fix config for test:coverage (#1851) * Try fix #1816 (#1846) * Add new param (#1853) * Content Model: Maintain selection on empty line (#1814) * Content Model: Maintain selection on empty line * fix build * improve * Content Model: Fix #1802 Default format is not applied when type in a not-empty line (#1805) * Try fix #1802 * fix build * Improve * fix test * add more test * Remove zeroFontSize from paragraph * fix build * fix bug * fix test * Improve * fix test * Fix list bug when pasting from Word Online (#1855) Right now when copying from Word Online, if text is between 2 lists, the text between would be transformed to list too. So we need to clear the list context to prevent this from happening. We will do this when: Element is not wrapped in a ListContainerDiv Element is not contained inside of a List item * Make paste with content model a public api instead of a Editor Class member (#1852) * init * Remove unused function * remove unused type * Content Model: Fix #1839: Fix toggleBold on heading text (#1845) * Content Model: Fix #1839 * add test --------- Co-authored-by: Bryan Valverde U <[email protected]> * Fix #1322: Copying some table structure transform the table to single line text (#1843) * add width format handler * Revert "add width format handler" This reverts commit b36f17d. * add size handle to table * add default style override when pasting table * fix test * revert * fix * address comment * handle only on copy and cut * Revert "address comment" This reverts commit e268795. * handle only on cut and paste * fix tests & build * use onNodeCreated instead * Improve test running (#1854) * Use default format for empty line below entity (#1858) * Use default format for empty line below entity * fix build * Fix bug when pasting from Outlook Win 32 to Rooster (#1857) * init * fix * fix test in ff * add a constants * address comments --------- Co-authored-by: Jiuqing Song <[email protected]> * bump --------- Co-authored-by: Bryan Valverde U <[email protected]> Co-authored-by: Jiuqing Song <[email protected]>
- Loading branch information
1 parent
0e88e6b
commit 6b6210e
Showing
137 changed files
with
4,406 additions
and
2,754 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
178 changes: 178 additions & 0 deletions
178
demo/scripts/controls/sampleEntity/SampleEntityPlugin.ts
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,178 @@ | ||
import { insertEntity } from 'roosterjs-editor-api'; | ||
import { | ||
createNumberDefinition, | ||
createObjectDefinition, | ||
findClosestElementAncestor, | ||
getEntityFromElement, | ||
getEntitySelector, | ||
getMetadata, | ||
setMetadata, | ||
} from 'roosterjs-editor-dom'; | ||
import { | ||
EditorPlugin, | ||
Entity, | ||
EntityOperation, | ||
EntityState, | ||
IEditor, | ||
PluginEvent, | ||
PluginEventType, | ||
} from 'roosterjs-editor-types'; | ||
|
||
const EntityType = 'SampleEntity'; | ||
|
||
interface EntityMetadata { | ||
count: number; | ||
} | ||
|
||
const EntityMetadataDefinition = createObjectDefinition<EntityMetadata>({ | ||
count: createNumberDefinition(), | ||
}); | ||
|
||
export default class SampleEntityPlugin implements EditorPlugin { | ||
private editor: IEditor; | ||
|
||
getName() { | ||
return 'SampleEntity'; | ||
} | ||
|
||
initialize(editor: IEditor) { | ||
this.editor = editor; | ||
} | ||
|
||
dispose() { | ||
this.editor = null; | ||
} | ||
|
||
onPluginEvent(event: PluginEvent) { | ||
if ( | ||
event.eventType == PluginEventType.KeyDown && | ||
event.rawEvent.key == 'm' && | ||
event.rawEvent.ctrlKey | ||
) { | ||
const entityNode = this.createEntity(); | ||
let entity: Entity | undefined; | ||
|
||
this.editor.addUndoSnapshot( | ||
() => { | ||
entity = insertEntity(this.editor, EntityType, entityNode, true, true); | ||
}, | ||
undefined /*changeSource*/, | ||
false /*canUndoByBackspace*/, | ||
{ | ||
getEntityState: () => this.getEntityStates(entity), | ||
} | ||
); | ||
|
||
event.rawEvent.preventDefault(); | ||
} else if ( | ||
event.eventType == PluginEventType.EntityOperation && | ||
event.entity.type == EntityType | ||
) { | ||
switch (event.operation) { | ||
case EntityOperation.NewEntity: | ||
this.dehydrate(event.entity); | ||
this.hydrate(event.entity); | ||
|
||
event.shouldPersist = true; | ||
|
||
break; | ||
|
||
case EntityOperation.RemoveFromEnd: | ||
case EntityOperation.RemoveFromStart: | ||
case EntityOperation.Overwrite: | ||
case EntityOperation.ReplaceTemporaryContent: | ||
this.dehydrate(event.entity); | ||
|
||
break; | ||
|
||
case EntityOperation.UpdateEntityState: | ||
if (event.state) { | ||
setMetadata( | ||
event.entity.wrapper, | ||
JSON.parse(event.state), | ||
EntityMetadataDefinition | ||
); | ||
this.updateEntity(event.entity); | ||
} | ||
|
||
break; | ||
} | ||
} | ||
} | ||
|
||
private hydrate(entity: Entity) { | ||
const containerDiv = entity.wrapper.querySelector('div'); | ||
|
||
const span = document.createElement('span'); | ||
const button = document.createElement('button'); | ||
|
||
containerDiv.appendChild(span); | ||
containerDiv.appendChild(button); | ||
|
||
button.textContent = 'Test entity'; | ||
button.addEventListener('click', this.onClickEntity); | ||
|
||
this.updateEntity(entity); | ||
} | ||
|
||
private dehydrate(entity: Entity) { | ||
const containerDiv = entity.wrapper.querySelector('div'); | ||
const button = containerDiv.querySelector('button'); | ||
|
||
if (button) { | ||
button.removeEventListener('click', this.onClickEntity); | ||
containerDiv.removeChild(button); | ||
} | ||
} | ||
|
||
private updateEntity(entity: Entity, increase: number = 0) { | ||
const metadata = getMetadata<EntityMetadata>(entity.wrapper); | ||
const count = (metadata?.count || 0) + increase; | ||
|
||
setMetadata(entity.wrapper, { | ||
count, | ||
}); | ||
|
||
entity.wrapper.querySelector('span').textContent = 'Count: ' + count; | ||
} | ||
|
||
private createEntity() { | ||
const div = document.createElement('div'); | ||
|
||
return div; | ||
} | ||
|
||
private onClickEntity = (e: MouseEvent) => { | ||
const wrapper = findClosestElementAncestor( | ||
e.target as Node, | ||
undefined, | ||
getEntitySelector(EntityType) | ||
); | ||
const entity = getEntityFromElement(wrapper); | ||
|
||
if (entity) { | ||
this.editor.addUndoSnapshot( | ||
() => { | ||
this.updateEntity(entity, 1); | ||
}, | ||
undefined /*changeSource*/, | ||
false /*canUndoByBackspace*/, | ||
{ | ||
getEntityState: () => this.getEntityStates(entity), | ||
} | ||
); | ||
} | ||
}; | ||
|
||
private getEntityStates(entity: Entity | undefined): EntityState[] { | ||
return entity | ||
? [ | ||
{ | ||
id: entity.id, | ||
type: entity.type, | ||
state: entity.wrapper.dataset.editingInfo, | ||
}, | ||
] | ||
: undefined; | ||
} | ||
} |
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
Oops, something went wrong.