Skip to content
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

feat: superscipt and subscript support to rich text editor [TOL-30] #1280

Merged
merged 23 commits into from
Nov 16, 2022

Conversation

aodhagan-cf
Copy link
Contributor

@aodhagan-cf aodhagan-cf commented Nov 14, 2022

Adding subscript and superscript support to rich text editor

  • Add new RT editor support for sub/sup
  • Sub/sup marks can be mixed with existing marks e.g. bold, italic, code, underline. like this
  • However, sub/sup marks should cancel each other out. A text may only have a sub or sup mark at the same time.
  • No support for hotkeys (aka keyboard shortcuts)
  • Toolbar items for subscript/superscript should only be visible if the marks are enabled in enabledMarks
  • Text with sub/sup marks should be selectable, and copy/pasting it should retain the marks. Both inside the editor and from external sources.
  • Update to latest version of @contentful/rich-text-types

@netlify
Copy link

netlify bot commented Nov 15, 2022

Deploy Preview for contentful-field-editors ready!

Name Link
🔨 Latest commit 9f7e651
🔍 Latest deploy log https://app.netlify.com/sites/contentful-field-editors/deploys/6374c8b4f6ea7a00072f9fe7
😎 Deploy Preview https://deploy-preview-1280--contentful-field-editors.netlify.app/
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@aodhagan-cf aodhagan-cf marked this pull request as ready for review November 15, 2022 11:44
@aodhagan-cf aodhagan-cf requested a review from a team as a code owner November 15, 2022 11:44
@@ -61,7 +61,16 @@ import { RichTextEditor } from '@contentful/field-editor-rich-text';
};

const initialValue = JSON.parse(window.localStorage.getItem('initialValue')) || undefined
const [field, mitt] = useMemo(() => createFakeFieldAPI(mock => mock, initialValue), []);
const [fakeField, mitt] = useMemo(() => createFakeFieldAPI(mock => mock, initialValue), []);
// Overriding mark validation here to show subscript and superscript marks
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default we don't show the superscript and subscript marks but showing in the preview so doing an override here

@@ -0,0 +1,52 @@
import { createFakeFieldAPI } from '@contentful/field-editor-test-utils';
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MayaGillilanContentful testing the logic for validating marks in these unit tests

const findMarkViaToolvar = (mark: MARKS) => cy.findByTestId(`${mark}-toolbar-button`);
const toggleMarkViaToolbar = (mark: MARKS) => cy.findByTestId(`${mark}-toolbar-button`).click();

it(`hides ${MARKS.SUBSCRIPT} and ${MARKS.SUPERSCRIPT} marks if not explicitly allowed`, () => {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MayaGillilanContentful also some cypress tests here for checking the showing/hiding logic

cypress/integration/rich-text/RichTextEditor.spec.ts Outdated Show resolved Hide resolved
@@ -61,7 +61,16 @@ import { RichTextEditor } from '@contentful/field-editor-rich-text';
};

const initialValue = JSON.parse(window.localStorage.getItem('initialValue')) || undefined
const [field, mitt] = useMemo(() => createFakeFieldAPI(mock => mock, initialValue), []);
const fieldValidations = JSON.parse(window.localStorage.getItem('fieldValidations')) || undefined
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this default to undefined and not []?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm falling back to undefined as I think local storage uses null by default. Then later on it will fallback to whatever value the mock gives us if it has one. I don't want to hard code this to []

Copy link
Member

@z0al z0al left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great. Some clarifying questions and suggestions

packages/rich-text/src/helpers/validations.ts Outdated Show resolved Hide resolved
packages/rich-text/src/plugins/Marks/Subscript.tsx Outdated Show resolved Hide resolved
packages/rich-text/src/plugins/Marks/Superscript.tsx Outdated Show resolved Hide resolved
packages/rich-text/src/plugins/Marks/helpers.ts Outdated Show resolved Hide resolved
Copy link
Member

@z0al z0al left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Don't forget to update the snapshot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants