This repository has been archived by the owner on Sep 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 830
Replace Draft with Slate #1890
Merged
Merged
Replace Draft with Slate #1890
Changes from 82 commits
Commits
Show all changes
108 commits
Select commit
Hold shift + click to select a range
75a2be1
WIP (doesn't build yet) replacing draft with slate
ara4n 0294706
Merge branch 'develop' into matthew/slate
ara4n e62e43d
comment out more draft stuff
ara4n f4ed820
fix stubbing
ara4n 05eba3f
stub out more until it loads...
ara4n a2233a4
stub out yet more
ara4n 190f6d9
make slate actually work as a textarea
ara4n ff42ef4
make it work for MD mode (modulo history)
ara4n 8b2eb2c
make history work again
ara4n 984961a
blind fix to the overlapping sticker bug
ara4n cbb8432
unbreak switching from draft to slate
ara4n 410a168
make autocomplete selection work
ara4n d7c2c8b
include the plaintext representation of a pill within it
ara4n 9c0c806
correctly send pills in messages
ara4n c91dcff
fix cursor behaviour around pills
ara4n 33eaa84
fix NPEs when deleting mentions
ara4n 877a619
unbreak history scrolling for pills & emoji
ara4n c967ecc
autocomplete polishing
ara4n 5605439
autocomplete polishing
ara4n e06763c
show all slashcommands on /
ara4n 4c3588d
don't lose focus after a / command
ara4n 79f7c5d
remove // support, as it never worked
ara4n 721410b
Merge branch 'develop' into matthew/slate
ara4n dd0726f
fix navigating history downwards on tall messages; remove obsolete code
ara4n ddfe069
fix insert_mention
ara4n a247ea2
delete duplicate propTypes(!!!)
ara4n 7405b49
unify setState() and onChange()
ara4n 7ecb4e3
remove dead removeMDLinks code
ara4n b10f9a9
remove spurious vendor prefixing
ara4n c1000a7
emojioneify the composer
ara4n 12a56e8
remove spurious comment
ara4n b60ccad
Merge branch 'develop' into matthew/slate
ara4n 4eb6942
let onChange set originalEditorState
ara4n ae208da
nudge towards supporting formatting buttons in MD
ara4n e51554c
actually hook up RTE
ara4n 089ac33
remove unused html serializer
ara4n 4972a23
Merge branch 'develop' into matthew/slate
ara4n 167742d
make RTE sending work
ara4n a4d9338
let backspace delete list nodes in RTE
ara4n 58670cc
exit list more sanely on backspace
ara4n d426c34
fix strikethough & code, improve shift-return & backspace
ara4n 1536ab4
make file pasting work again
ara4n 1f05aea
make HTML pasting work
ara4n 572a313
add h4, h5 and h6
ara4n 65f0b05
fix typo
ara4n 1175195
remove HRs from H1/H2s
ara4n f211694
switch schema to match the MD serializer
ara4n c3a6a41
support links in RTE
ara4n d76a2ab
use <p/> as our root node everywhere and fix blank roundtrip bug
ara4n a0d88a8
support sending inlines from the RTE.
ara4n e9cabf0
add pill and emoji serialisation to Md
ara4n ad7782b
remove the remaining Draft specific stuff from RichText
ara4n c5676ee
comment out more old draft stuff
ara4n 9aba046
fix MD pill serialization
ara4n aac6866
switch back to using commonmark for serialising MD when roundtripping
ara4n d799b7e
refactor roundtripping into a single place
ara4n f981d7b
unify buttons on the node type names, and make them work
ara4n e460cf3
hide formatting bar for MD editor
ara4n b616fd0
comment out all the tests for now
ara4n 4439a04
fix lint
ara4n 7de45f8
make quoting work
ara4n 11cea61
refocus editor after clicking on autocompletes
ara4n cace5e8
fix bug where selection breaks after inserting emoji
ara4n e7a4ffa
fix emojioneifying autoconverted emoji
ara4n 794a60b
refocus editor immediately after executing commands
ara4n 6ac2324
fix wordwrap and pre formatting
ara4n 6fba831
escape blockquotes correctly
ara4n fc1c499
slate-md-serializer 3.1.0 now escapes correctly
ara4n edc8264
shift to custom slate-md-serializer
ara4n 6f3634c
bump slate-md-serializer
ara4n a822a1c
bump dep
ara4n 079b123
bump right dep
ara4n 95bffac
comment out broken logic for stripping p tags & bump dep
ara4n f40af43
unbreak Markdown.toPlaintext
ara4n 5b4a036
bump dep
ara4n 87c3e92
bump dep
ara4n fb5240a
explain why we're now including <p/>s
ara4n b0ff61f
switch code schema to match slate-md-serializer
ara4n 294565c
switch code schema to match slate-md-serializer
ara4n 864a33f
switch to using 'code' for both blocks & marks to match md-serializer
ara4n ab41212
fix double-nested code blocks & bump md-serializer
ara4n 6299e18
unbreak keyboard shortcuts & ctrl-backspace
ara4n efdc543
merge develop
ara4n c6837af
import-type Change from slate
t3chguy 372fa29
take edge into consideration when moving focus region on arrow keys
t3chguy 483116f
add rule to slate-md-serializer: make underlined and removed work for CM
t3chguy faf17f0
remove debugger statement
t3chguy 43204ea
fix Control-Backspace after select-all
t3chguy 5b74c61
add missing import
t3chguy 5bd4104
modify ComposerHistoryManager
t3chguy 8665f10
pin slate to 0.33.4 to avoid https://github.com/ianstormtaylor/slate/…
ara4n 83f2614
add guide to slate's data formats and how we convert
ara4n 021409a
apply review feedback from @lukebarnard1
ara4n 0d0934a
unbreak modifier+space (e.g. emoji insert on macOS)
ara4n 8bcb987
delint
t3chguy 51591a4
fix lint
ara4n 58301e5
navigateHistory only when at edges of document, to prevent Firefox bug
t3chguy 100ecfe
remove trailing spaces to make linter happy (no-trailing-spaces)
t3chguy abbb69d
fix fn call, fixes usage of SlashCommands
t3chguy fd4f967
convert md<->rt if the stored editorState was in a different state
t3chguy c3aef6e
workaround for tommoor/slate-md-serializer#14
t3chguy 95909de
fix MessageComposer not marking translatable strings. run gen-i18n
t3chguy 3e05bf1
hide autocomplete when moving caret to match existing behaviour
t3chguy b4bc09c
null-guard savedState since now we're accessing its props
t3chguy 7405c5e
specify alternate history storage key to prevent conflicts with draft
t3chguy 59a14f2
re-hydrate Values which have been serialized into LocalStorage
t3chguy d7ff7cd
stupid thinkotypo
ara4n eb497d4
Merge pull request #2049 from matrix-org/t3chguy/slate_cont2
dbkr 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
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
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 |
---|---|---|
|
@@ -112,7 +112,7 @@ export function charactersToImageNode(alt, useSvg, ...unicode) { | |
/>; | ||
} | ||
|
||
|
||
/* | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think we need to keep this around. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
export function processHtmlForSending(html: string): string { | ||
const contentDiv = document.createElement('div'); | ||
contentDiv.innerHTML = html; | ||
|
@@ -146,6 +146,7 @@ export function processHtmlForSending(html: string): string { | |
|
||
return contentHTML; | ||
} | ||
*/ | ||
|
||
/* | ||
* Given an untrusted HTML string, return a React node with an sanitized version | ||
|
@@ -402,19 +403,22 @@ class TextHighlighter extends BaseHighlighter { | |
} | ||
|
||
|
||
/* turn a matrix event body into html | ||
* | ||
* content: 'content' of the MatrixEvent | ||
* | ||
* highlights: optional list of words to highlight, ordered by longest word first | ||
* | ||
* opts.highlightLink: optional href to add to highlighted words | ||
* opts.disableBigEmoji: optional argument to disable the big emoji class. | ||
* opts.stripReplyFallback: optional argument specifying the event is a reply and so fallback needs removing | ||
*/ | ||
/* turn a matrix event body into html | ||
* | ||
* content: 'content' of the MatrixEvent | ||
* | ||
* highlights: optional list of words to highlight, ordered by longest word first | ||
* | ||
* opts.highlightLink: optional href to add to highlighted words | ||
* opts.disableBigEmoji: optional argument to disable the big emoji class. | ||
* opts.stripReplyFallback: optional argument specifying the event is a reply and so fallback needs removing | ||
* opts.returnString: return an HTML string rather than JSX elements | ||
* opts.emojiOne: optional param to do emojiOne (default true) | ||
*/ | ||
export function bodyToHtml(content, highlights, opts={}) { | ||
const isHtmlMessage = content.format === "org.matrix.custom.html" && content.formatted_body; | ||
|
||
const doEmojiOne = opts.emojiOne === undefined ? true : opts.emojiOne; | ||
let bodyHasEmoji = false; | ||
|
||
let strippedBody; | ||
|
@@ -440,8 +444,9 @@ export function bodyToHtml(content, highlights, opts={}) { | |
if (opts.stripReplyFallback && formattedBody) formattedBody = ReplyThread.stripHTMLReply(formattedBody); | ||
strippedBody = opts.stripReplyFallback ? ReplyThread.stripPlainReply(content.body) : content.body; | ||
|
||
bodyHasEmoji = containsEmoji(isHtmlMessage ? formattedBody : content.body); | ||
|
||
if (doEmojiOne) { | ||
bodyHasEmoji = containsEmoji(isHtmlMessage ? formattedBody : content.body); | ||
} | ||
|
||
// Only generate safeBody if the message was sent as org.matrix.custom.html | ||
if (isHtmlMessage) { | ||
|
@@ -466,6 +471,10 @@ export function bodyToHtml(content, highlights, opts={}) { | |
delete sanitizeHtmlParams.textFilter; | ||
} | ||
|
||
if (opts.returnString) { | ||
return isDisplayedWithHtml ? safeBody : strippedBody; | ||
} | ||
|
||
let emojiBody = false; | ||
if (!opts.disableBigEmoji && bodyHasEmoji) { | ||
EMOJI_REGEX.lastIndex = 0; | ||
|
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 |
---|---|---|
|
@@ -102,6 +102,16 @@ export default class Markdown { | |
// (https://github.com/vector-im/riot-web/issues/3154) | ||
softbreak: '<br />', | ||
}); | ||
|
||
// Trying to strip out the wrapping <p/> causes a lot more complication | ||
// than it's worth, i think. For instance, this code will go and strip | ||
// out any <p/> tag (no matter where it is in the tree) which doesn't | ||
// contain \n's. | ||
// On the flip side, <p/>s are quite opionated and restricted on where | ||
// you can nest them. | ||
// | ||
// Let's try sending with <p/>s anyway for now, though. | ||
/* | ||
const real_paragraph = renderer.paragraph; | ||
|
||
renderer.paragraph = function(node, entering) { | ||
|
@@ -114,16 +124,21 @@ export default class Markdown { | |
real_paragraph.call(this, node, entering); | ||
} | ||
}; | ||
*/ | ||
|
||
renderer.html_inline = html_if_tag_allowed; | ||
|
||
renderer.html_block = function(node) { | ||
/* | ||
// as with `paragraph`, we only insert line breaks | ||
// if there are multiple lines in the markdown. | ||
const isMultiLine = is_multi_line(node); | ||
|
||
if (isMultiLine) this.cr(); | ||
*/ | ||
html_if_tag_allowed.call(this, node); | ||
/* | ||
if (isMultiLine) this.cr(); | ||
*/ | ||
}; | ||
|
||
return renderer.render(this.parsed); | ||
|
@@ -133,7 +148,10 @@ export default class Markdown { | |
* Render the markdown message to plain text. That is, essentially | ||
* just remove any backslashes escaping what would otherwise be | ||
* markdown syntax | ||
* (to fix https://github.com/vector-im/riot-web/issues/2870) | ||
* (to fix https://github.com/vector-im/riot-web/issues/2870). | ||
* | ||
* N.B. this does **NOT** render arbitrary MD to plain text - only MD | ||
* which has no formatting. Otherwise it emits HTML(!). | ||
*/ | ||
toPlaintext() { | ||
const renderer = new commonmark.HtmlRenderer({safe: false}); | ||
|
@@ -156,11 +174,20 @@ export default class Markdown { | |
} | ||
} | ||
}; | ||
|
||
renderer.html_block = function(node) { | ||
this.lit(node.literal); | ||
if (is_multi_line(node) && node.next) this.lit('\n\n'); | ||
}; | ||
|
||
// convert MD links into console-friendly ' < http://foo >' style links | ||
// ...except given this function never gets called with links, it's useless. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's useless, maybe we could remove it? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done |
||
// renderer.link = function(node, entering) { | ||
// if (!entering) { | ||
// this.lit(` < ${node.destination} >`); | ||
// } | ||
// }; | ||
|
||
return renderer.render(this.parsed); | ||
} | ||
} |
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.
Looks like these changes are still in the process of being brought upstream (tommoor/slate-md-serializer#11).
Let's remember to pin on the next release when it happens!