-
Notifications
You must be signed in to change notification settings - Fork 161
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove NodeType from Content Model (#2106)
- Loading branch information
1 parent
368e88e
commit 0c928db
Showing
14 changed files
with
40 additions
and
56 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
23 changes: 11 additions & 12 deletions
23
packages-content-model/roosterjs-content-model-dom/lib/domUtils/isNodeOfType.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 |
---|---|---|
@@ -1,57 +1,56 @@ | ||
import { NodeType } from 'roosterjs-editor-types'; | ||
|
||
/** | ||
* A type map from node type number to its type declaration. This is used by utility function isNodeOfType() | ||
*/ | ||
export interface NodeTypeMap { | ||
/** | ||
* Attribute node | ||
*/ | ||
[NodeType.Attribute]: Attr; | ||
ATTRIBUTE_NODE: Attr; | ||
|
||
/** | ||
* Comment node | ||
*/ | ||
[NodeType.Comment]: Comment; | ||
COMMENT_NODE: Comment; | ||
|
||
/** | ||
* DocumentFragment node | ||
*/ | ||
[NodeType.DocumentFragment]: DocumentFragment; | ||
DOCUMENT_FRAGMENT_NODE: DocumentFragment; | ||
|
||
/** | ||
* Document node | ||
*/ | ||
[NodeType.Document]: Document; | ||
DOCUMENT_NODE: Document; | ||
|
||
/** | ||
* DocumentType node | ||
*/ | ||
[NodeType.DocumentType]: DocumentType; | ||
DOCUMENT_TYPE_NODE: DocumentType; | ||
|
||
/** | ||
* HTMLElement node | ||
*/ | ||
[NodeType.Element]: HTMLElement; | ||
ELEMENT_NODE: HTMLElement; | ||
|
||
/** | ||
* ProcessingInstruction node | ||
*/ | ||
[NodeType.ProcessingInstruction]: ProcessingInstruction; | ||
PROCESSING_INSTRUCTION_NODE: ProcessingInstruction; | ||
|
||
/** | ||
* Text node | ||
*/ | ||
[NodeType.Text]: Text; | ||
TEXT_NODE: Text; | ||
} | ||
|
||
/** | ||
* Type checker for Node. Return true if it of the specified node type | ||
* @param node The node to check | ||
* @param expectedType The type to check | ||
*/ | ||
export function isNodeOfType<T extends NodeType>( | ||
export function isNodeOfType<T extends keyof NodeTypeMap>( | ||
node: Node | null | undefined, | ||
expectedType: T | ||
): node is NodeTypeMap[T] { | ||
return !!node && node.nodeType == expectedType; | ||
return !!node && node.nodeType == Node[expectedType]; | ||
} |
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
3 changes: 1 addition & 2 deletions
3
...tent-model/roosterjs-content-model-dom/lib/modelToDom/optimizers/removeUnnecessarySpan.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
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