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 827
T3chguy/slate cont2 #2049
Merged
Merged
T3chguy/slate cont2 #2049
Changes from 23 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
Guide to data types used by the Slate-based Rich Text Editor | ||
------------------------------------------------------------ | ||
|
||
We always store the Slate editor state in its Value form. | ||
|
||
The schema for the Value is the same whether the editor is in MD or rich text mode, and is currently (rather arbitrarily) | ||
dictated by the schema expected by slate-md-serializer, simply because it was the only bit of the pipeline which | ||
has opinions on the schema. (slate-html-serializer lets you define how to serialize whatever schema you like). | ||
|
||
The BLOCK_TAGS and MARK_TAGS give the mapping from HTML tags to the schema's node types (for blocks, which describe | ||
block content like divs, and marks, which describe inline formatted sections like spans). | ||
|
||
We use <p/> as the parent tag for the message (XXX: although some tags are technically not allowed to be nested within p's) | ||
|
||
Various conversions are performed as content is moved between HTML, MD, and plaintext representations of HTML and MD. | ||
|
||
The primitives used are: | ||
|
||
* Markdown.js - models commonmark-formatted MD strings (as entered by the composer in MD mode) | ||
* toHtml() - renders them to HTML suitable for sending on the wire | ||
* isPlainText() - checks whether the parsed MD contains anything other than simple text. | ||
* toPlainText() - renders MD to plain text in order to remove backslashes. Only works if the MD is already plaintext (otherwise it just emits HTML) | ||
|
||
* slate-html-serializer | ||
* converts Values to HTML (serialising) using our schema rules | ||
* converts HTML to Values (deserialising) using our schema rules | ||
|
||
* slate-md-serializer | ||
* converts rich Values to MD strings (serialising) but using a non-commonmark generic MD dialect. | ||
* This should use commonmark, but we use the serializer here for expedience rather than writing a commonmark one. | ||
|
||
* slate-plain-serializer | ||
* converts Values to plain text strings (serialising them) by concatenating the strings together | ||
* converts Values from plain text strings (deserialiasing them). | ||
* Used to initialise the editor by deserializing "" into a Value. Apparently this is the idiomatic way to initialise a blank editor. | ||
* Used (as a bodge) to turn a rich text editor into a MD editor, when deserialising the converted MD string of the editor into a value | ||
|
||
* PlainWithPillsSerializer | ||
* A fork of slate-plain-serializer which is aware of Pills (hence the name) and Emoji. | ||
* It can be configured to output Pills as: | ||
* "plain": Pills are rendered via their 'completion' text - e.g. 'Matthew'; used for sending messages) | ||
* "md": Pills are rendered as MD, e.g. [Matthew](https://matrix.to/#/@matthew:matrix.org) ) | ||
* "id": Pills are rendered as IDs, e.g. '@matthew:matrix.org' (used for authoring / commands) | ||
* Emoji nodes are converted to inline utf8 emoji. | ||
|
||
The actual conversion transitions are: | ||
|
||
* Quoting: | ||
* The message being quoted is taken as HTML | ||
* ...and deserialised into a Value | ||
* ...and then serialised into MD via slate-md-serializer if the editor is in MD mode | ||
|
||
* Roundtripping between MD and rich text editor mode | ||
* From MD to richtext (mdToRichEditorState): | ||
* Serialise the MD-format Value to a MD string (converting pills to MD) with PlainWithPillsSerializer in 'md' mode | ||
* Convert that MD string to HTML via Markdown.js | ||
* Deserialise that Value to HTML via slate-html-serializer | ||
* From richtext to MD (richToMdEditorState): | ||
* Serialise the richtext-format Value to a MD string with slate-md-serializer (XXX: this should use commonmark) | ||
* Deserialise that to a plain text value via slate-plain-serializer | ||
|
||
* Loading history in one format into an editor which is in the other format | ||
* Uses the same functions as for roundtripping | ||
|
||
* Scanning the editor for a slash command | ||
* If the editor is a single line node starting with /, then serialize it to a string with PlainWithPillsSerializer in 'id' mode | ||
So that pills get converted to IDs suitable for commands being passed around | ||
|
||
* Sending messages | ||
* In RT mode: | ||
* If there is rich content, serialize the RT-format Value to HTML body via slate-html-serializer | ||
* Serialize the RT-format Value to the plain text fallback via PlainWithPillsSerializer in 'plain' mode | ||
* In MD mode: | ||
* Serialize the MD-format Value into an MD string with PlainWithPillsSerializer in 'md' mode | ||
* Parse the string with Markdown.js | ||
* If it contains no formatting: | ||
* Send as plaintext (as taken from Markdown.toPlainText()) | ||
* Otherwise | ||
* Send as HTML (as taken from Markdown.toHtml()) | ||
* Serialize the RT-format Value to the plain text fallback via PlainWithPillsSerializer in 'plain' mode | ||
|
||
* Pasting HTML | ||
* Deserialize HTML to a RT Value via slate-html-serializer | ||
* In RT mode, insert it straight into the editor as a fragment | ||
* In MD mode, serialise it to an MD string via slate-md-serializer and then insert the string into the editor as a fragment. | ||
|
||
The various scenarios and transitions could be drawn into a pretty diagram if one felt the urge, but hopefully the enough | ||
gives sufficient detail on how it's all meant to work. |
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
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.
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.
the above?