-
Notifications
You must be signed in to change notification settings - Fork 183
Do not copy div ID on Enter #3011
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
231f94b
wip
juliaroldi a418141
Merge branch 'master' of https://github.com/microsoft/roosterjs into …
juliaroldi 8a4ecfa
insertCustom
juliaroldi b9c11f5
Merge branch 'master' into u/juliaroldi/custom-container
juliaroldi 91c5ab1
refactor
juliaroldi 633fc85
Merge branch 'u/juliaroldi/custom-container' of https://github.com/mi…
juliaroldi 2de2017
Merge branch 'master' into u/juliaroldi/custom-container
juliaroldi 5abda24
Merge branch 'master' into u/juliaroldi/custom-container
juliaroldi 4fbad4b
formatKeys
juliaroldi c24c728
conflicts
juliaroldi 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 hidden or 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
13 changes: 13 additions & 0 deletions
13
...ts/controlsV2/sidePane/apiPlayground/insertCustomContainer/InsertCustomContainerPane.scss
This file contains hidden or 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,13 @@ | ||
| .textarea { | ||
| height: 200px; | ||
| } | ||
|
|
||
| .blockContent { | ||
| display: grid; | ||
| row-gap: 5px; | ||
| padding-bottom: 5px; | ||
| } | ||
|
|
||
| .results { | ||
| overflow-wrap: anywhere; | ||
| } |
103 changes: 103 additions & 0 deletions
103
...pts/controlsV2/sidePane/apiPlayground/insertCustomContainer/InsertCustomContainerPane.tsx
This file contains hidden or 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,103 @@ | ||
| import * as React from 'react'; | ||
| import { ApiPaneProps } from '../ApiPaneProps'; | ||
| import { createFormatContainer, mergeModel } from 'roosterjs-content-model-dom'; | ||
| import { createModelFromHtml } from 'roosterjs-content-model-core'; | ||
| import { trustedHTMLHandler } from '../../../../utils/trustedHTMLHandler'; | ||
| import { | ||
| ContentModelDocument, | ||
| ContentModelFormatContainer, | ||
| IEditor, | ||
| } from 'roosterjs-content-model-types'; | ||
|
|
||
| interface InsertCustomContainerPaneState { | ||
| containers: { | ||
| [id: string]: ContentModelFormatContainer; | ||
| }; | ||
| } | ||
|
|
||
| const styles = require('./InsertCustomContainerPane.scss'); | ||
|
|
||
| export default class InsertCustomContainerPane extends React.Component< | ||
| ApiPaneProps, | ||
| InsertCustomContainerPaneState | ||
| > { | ||
| public html = React.createRef<HTMLTextAreaElement>(); | ||
| private containerId = React.createRef<HTMLInputElement>(); | ||
| private searchId = React.createRef<HTMLInputElement>(); | ||
| private result = React.createRef<HTMLParagraphElement>(); | ||
|
|
||
| constructor(props: ApiPaneProps) { | ||
| super(props); | ||
| this.state = { | ||
| containers: {}, | ||
| }; | ||
| } | ||
|
|
||
| private insertCustomContainer = () => { | ||
| const model = createModelFromHtml(this.html.current.value, undefined, trustedHTMLHandler); | ||
| const container = createFormatContainer('div'); | ||
| const containerId = this.containerId.current.value; | ||
| container.format.id = containerId; | ||
| container.blocks = [...model.blocks]; | ||
| this.state.containers[containerId] = container; | ||
| model.blocks = [container]; | ||
| const editor = this.props.getEditor(); | ||
| insertContainer(editor, model); | ||
| }; | ||
|
|
||
| private getCustomContainer = () => { | ||
| const id = this.searchId.current.value; | ||
| const container = this.state.containers[id]; | ||
| if (container) { | ||
| this.result.current.innerText = JSON.stringify(container); | ||
| } else { | ||
| this.result.current.innerText = 'No container found'; | ||
| } | ||
| }; | ||
|
|
||
| render() { | ||
| return ( | ||
| <> | ||
| <div className={styles.blockContent}> | ||
| <label htmlFor="containerId"> Insert container</label> | ||
| <input | ||
| ref={this.containerId} | ||
| title="Container Id" | ||
| id="containerId" | ||
| type="text" | ||
| placeholder="Container Id" | ||
| /> | ||
| <textarea | ||
| ref={this.html} | ||
| className={styles.textarea} | ||
| title="Custom Content" | ||
| name="Content" | ||
| id="customContent" | ||
| placeholder="Insert HTML Content"></textarea> | ||
| <button onClick={this.insertCustomContainer} type="button"> | ||
| Insert container | ||
| </button> | ||
| </div> | ||
|
|
||
| <div className={styles.blockContent}> | ||
| <label htmlFor="containerId">Id:</label> | ||
| <input ref={this.searchId} title="Container Id" id="containerId" type="text" /> | ||
| <button onClick={this.getCustomContainer} type="button"> | ||
| Get Custom Container | ||
| </button> | ||
| <label htmlFor="results"> Results:</label> | ||
| <p className={styles.results} ref={this.result} id="results"></p> | ||
| </div> | ||
| </> | ||
| ); | ||
| } | ||
| } | ||
|
|
||
| function insertContainer(editor: IEditor, newModel: ContentModelDocument) { | ||
| editor.formatContentModel((model, context) => { | ||
| mergeModel(model, newModel, context, { | ||
| mergeFormat: 'mergeAll', | ||
| }); | ||
| return true; | ||
| }); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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.
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.
I prefer we keep this parameter here and still check it if the one in EditorOptions is not passed. Because it can be used by some team today, so if we remove the check here, it will break their feature
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.
We can save a checker function in the class, initialize it in ctor, so no need to check it everytime when Enter is pressed. for example:
When handle enter key, just call this.handleNormalEnter(event), no additional checking needed.
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.
And add comment in the experimental feature and the new option to explain the priority
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.
I did a bit different than what you proposed, I added back the experimental feature check, so it do not break the code of the user that has the experimental features enabled.