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
Inline text formatting #1323
Inline text formatting #1323
Conversation
Size Change: +4.22 kB (0%) Total Size: 830 kB
ℹ️ View Unchanged
|
Codecov Report
@@ Coverage Diff @@
## master #1323 +/- ##
=========================================
Coverage 59.38% 59.38%
Complexity 216 216
=========================================
Files 555 555
Lines 9109 9109
=========================================
Hits 5409 5409
Misses 3700 3700 |
Actually the whole `forceFocus` variable was superfluous - `EditorState.forceSelection` autimatically forces focus to the editor. And selection was remembered, just not visible while unfocused, so things still work as expected.
Font weight dropdown simply gets a new placeholder, as the placeholder will only be shown, when there's multiple font weights selected. For now, font weight logic is removed from font selector (but must be readded in a new version later), and tests are updated.
Found and fixed the underlying issue this time - it's the faux selection removal, that caused errors if the component was remounted. Fixed in e03baf3. |
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 posted a few more responses on the existing threads. But otherwise my only question is what to do with !important
styles for the output (and lesser extend the editor as well). Otherwise, I'm ready to approve this.
# Conflicts: # package.json
@dvoytenko, I think I've addressed most/all of your points now - can you approve, so we can merge or how do you feel? |
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.
Approved, but at least one thing I'd like to change to add useMemo on valid content.
Reverted changes to `getValidHTML` and reused the existing HTML manipulation functions.
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.
Two more things noticed.
// Setting the text color of the entire block to black essentially removes all inline | ||
// color styling allowing us to apply transparent to all of them. | ||
const backgroundContent = useMemo( | ||
() => getHTMLFormatters().setColor(content, createSolid(0, 0, 0)), |
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.
Is the createSolid
missing an alpha 0?
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.
No - we apply solid opaque black, which is default meaning that no color style will be applied to the entire text field. Thus allowing us to overwrite the whole thing with color:transparent
.
* master: (53 commits) Inline text formatting (#1323) Bump terser-webpack-plugin from 2.3.6 to 3.0.1 (#1597) Allow disabling warning on exit in development (#1176) fixing indent that was missed by automation Deploy plugin bundle to wiki repo for easier QA (#1590) Fix initial height of preset panel (#1591) Fixes editor resizing after fullbleed (#1553) More error handling Fix file drag & drop crash for unsupported media types (#1431) Improve test Bump polished from 3.6.1 to 3.6.2 (#1577) Bump react-transition-group from 4.3.0 to 4.4.0 (#1565) Remove Delete Page shortcut tooltip (#1574) renaming filteredStories to just stories. they are not filtered. updating typeahead input and options for new designs. New colors, tighter space, different expanded view. Removing option to filter internally through typeahead since we do all of that outside of the component. some styled component cleanup Remove wp element. Bump @testing-library/dom from 7.2.2 to 7.3.0 (#1563) Remove wp element Lints in tests Add more tests ...
* master: (109 commits) Inline text formatting (#1323) Bump terser-webpack-plugin from 2.3.6 to 3.0.1 (#1597) Allow disabling warning on exit in development (#1176) fixing indent that was missed by automation Deploy plugin bundle to wiki repo for easier QA (#1590) Fix initial height of preset panel (#1591) Fixes editor resizing after fullbleed (#1553) More error handling Fix file drag & drop crash for unsupported media types (#1431) Improve test Bump polished from 3.6.1 to 3.6.2 (#1577) Bump react-transition-group from 4.3.0 to 4.4.0 (#1565) Remove Delete Page shortcut tooltip (#1574) renaming filteredStories to just stories. they are not filtered. updating typeahead input and options for new designs. New colors, tighter space, different expanded view. Removing option to filter internally through typeahead since we do all of that outside of the component. some styled component cleanup Remove wp element. Bump @testing-library/dom from 7.2.2 to 7.3.0 (#1563) Remove wp element Lints in tests Add more tests ...
#1275) * Add resize support to box when changing font-face on display/edit mode * Cover unicode chars, font-weight, font-style * Add ((MULTIPLE)) support proposal * Improve docs. * Fix problematic rest approach. * Add fontSize support. Remove content support. Add a better support for MULTIPLE. Improve useLoadFontFiles.js * Update textStyle tests * Force display=auto on @font-face declaration while loading fonts from Google Fonts. * Fix typo * Add codecov to useLoadFontFiles * Update tests to match new APIs proposed after merge. * Address PR reviews * Address some PR reviews. * Adjustments after #1323 merge. Revert content as parameter to load font (To address #923). * Address recent PR review * Improve code performance/reusability. Thanks @dvoytenko * Clean up promise logic a bit Co-authored-by: Pascal Birchler <pascalb@google.com> Co-authored-by: Morten Barklund <morten.barklund@xwp.co>
This is an initial implementation of inline text formatting.
Fixes #413.
Fixes #1007.
Fixes #925.
TL;DR:
It works for all the properties: bold, italic, underline font weight, letter spacing and text color, but there's still some stuff to do - however everything can and will be fixed! Also, there's a couple of open questions, that need be answered to fully implement.
Goal
The goal is to be able to update font weight (and bold as a subset of that), italic, underline, text color and letter-spacing both inline and on the entire text field.
This also includes that the text panel is aware of which of these features are currently set to which values while editing the text field - so when selecting text, that "B" button is correctly pressed or not based on whether the currently selected text is all (some) bold.
All of this has to work as before for multiple text fields as well and things should work when pasted too.
Implementation details
Structure
This introduces a new provider located just inside the
CanvasProvider
inWorkspace
.Also, the entire rich text editor is moved to a new component that is then utilized by the text edit component. We might not need this component elsewhere, but the split made sense.
One caveat is, that the rich text provider directly accesses the
editingElementState
from theCanvasProvider
. It would probably be cleaner to pass this in all the way from the text edit component. I might do that in the future.The text edit component now only updates the HTML on unmount.
Formatting
This PR also completely overrules draftjs' built-in formatting and creates a completely new formatting setup with custom style names. There's a parser, a serializer and a set of rules for display.
This also re-implements the logic as to what it means to press "italic" (both by shortcut and button) by answering the question "is current selection italic or not?" explicitly. It seems like a trivial question, and kind of is for italic, but for bold is a lot more complex - what if some characters are semibold, others are black - what happens when you press the "bold" button? All this is answered in code in
styleManipulation
.These same rules will be applied to the entire text field (in upcoming posts) as well as partial selection (which works now for a subset of the properties).
Status
This is the progress so far:
fontStyle
,textDecoration
,bold
,fontWeight
).color
,letterSpacing
).(multiple)
in font weight dropdown when it's the casefontWeight
versusbold
- I'm thinking thatif fontWeight=400 and bold
wrap everything infont-weight:700
, else use actual font weight). Plus intensive unit test!Known bugs:
Proper parsing of multiple styles applied to the same character (due to Allow multiple inlineStyles to be returned by customInlineFn sstur/draft-js-utils#155 going unmerged) - will fix withFixed in 854510fpatch-package
in a future commit) [bug can be seen by making some text both italic and bold, exiting edit mode and re-entering edit mode]Possible optimizations:
<span />
with class names and inline styles for all formatting) – proper semantic DOM is not easy due to limitations todraft-js-utils
, where only one node can be returned per styled section, where something both bold and italic should have two surrounding nodes (thus the single<span />
used now with multiple styles and class names).Open questions:
What should the font weight drop down display, when multiple font weights are present in selection? (my current idea is to push a disabledadded as a proper task above<option>(multiple)</option>
to the front of the list and mark it as selected)What should the letter spacing input display, when multiple letter spacings are present in selection? (currently going foralready handled by component(multiple)
as used in inputs elsewhere)What should the font color component display, when multiple color are present in selection? (will implement some kind ofalready handled by component(multiple)
logic which currently doesn't exist for color display as far as I know).Demo
(when you see the text change without the mouse being over the buttons, it's because I'm using shortcuts - forgot to include the on-screen key-logger for this video)