-
Notifications
You must be signed in to change notification settings - Fork 51
feat(web): enriched text component #651
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
Open
hejsztynx
wants to merge
30
commits into
main
Choose a base branch
from
@ksienkiewicz/feat-web-enriched-text
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 19 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
27cac3c
feat: base
hejsztynx 8a79e28
feat: style prop and theming implementation
hejsztynx c7ff13a
feat: impl html style
hejsztynx 36f0424
feat: checkbox list conversion to web html
hejsztynx 53970ec
fix: empty elements in list collapsing
hejsztynx 9c649cb
feat: html sanitization
hejsztynx cfc85ba
feat: image placeholder
hejsztynx 3207367
refactor: broken image glyph css var
hejsztynx 1905a8c
test: enriched text tests
hejsztynx dfd8915
docs: update docs
hejsztynx bb1edff
refactor: cleanup
hejsztynx bdf9483
fix: onerror when setting img placeholders
hejsztynx 0c70ea7
fix: css tweaks
hejsztynx 6917372
fix: domparser existence check
hejsztynx 82515f4
feat: merge with default styles
hejsztynx 0a4a774
fix: build mention rules default flow
hejsztynx 45d0d36
feat: disable default link press handling
hejsztynx 9dc110a
fix: placeholder images not displaying on safari
hejsztynx 72f566c
feat: clear input on push text
hejsztynx f2c8f2a
test: cleanup
hejsztynx b6f3e59
docs: web docs update
hejsztynx 950ed5a
docs: web.md update
hejsztynx 459d0f1
Update package.json
hejsztynx 361f710
fix: unnecessary img placeholder logic on every rerender
hejsztynx 6d068f1
Merge branch 'main' into @ksienkiewicz/feat-web-enriched-text
hejsztynx 90b938b
Merge branch 'main' into @ksienkiewicz/feat-web-enriched-text
hejsztynx 5f06822
chore: deps
hejsztynx 7c542b0
chore: lint
hejsztynx 6a4c7e1
Merge branch 'main' into @ksienkiewicz/feat-web-enriched-text
hejsztynx 5e8693d
test: fix tests
hejsztynx 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,235 @@ | ||
| import { test, expect, type Locator, type Page } from '@playwright/test'; | ||
|
|
||
| test.setTimeout(90_000); | ||
|
|
||
| const sel = { | ||
| root: '[data-testid="test-enriched-text-root"]', | ||
| htmlInput: '[data-testid="test-enriched-text-html-input"]', | ||
| setValueButton: '[data-testid="test-enriched-text-set-value-button"]', | ||
| valueOutput: '[data-testid="test-enriched-text-value-output"]', | ||
| display: '[data-testid="test-enriched-text-display"]', | ||
| displayInner: '[data-testid="test-enriched-text-display"] .et-view', | ||
| } as const; | ||
|
|
||
| function displayLocator(page: Page): Locator { | ||
| return page.locator(sel.display); | ||
| } | ||
|
|
||
| async function gotoTestEnrichedText(page: Page): Promise<void> { | ||
| await page.goto('/test-enriched-text'); | ||
| await page.waitForSelector(sel.displayInner); | ||
| } | ||
|
|
||
| async function setEnrichedTextValue(page: Page, html: string): Promise<void> { | ||
| await page.fill(sel.htmlInput, html); | ||
| await page.click(sel.setValueButton); | ||
|
|
||
| await expect | ||
| .poll(async () => (await page.locator(sel.valueOutput).textContent()) ?? '') | ||
| .toBe(html); | ||
| } | ||
|
|
||
| test.describe('EnrichedText display visual regression', () => { | ||
| const cases: { name: string; snapshot: string; html: string }[] = [ | ||
| { | ||
| name: 'rich text: heading, bold, italic and link', | ||
| snapshot: 'enriched-text-rich-text.png', | ||
| html: [ | ||
| '<html>', | ||
| '<h3>Heading</h3>', | ||
| '<p>Some <b>bold</b> and <i>italic</i> text.</p>', | ||
| '<p><b>S</i>om</i>e</b> <b>mix</b><i>ed</i> <s>t<u>ex</u>t</s>.</p>', | ||
| '<p>A <a href="https://example.com">link</a> here.</p>', | ||
| '<p>A bold <a href="https://example.com">l<b>in<b/>k</a> here.</p>', | ||
| '</html>', | ||
| ].join(''), | ||
| }, | ||
| { | ||
| name: 'unordered list', | ||
| snapshot: 'enriched-text-unordered-list.png', | ||
| html: '<html><ul><li>Alpha</li><li>Beta</li><li>Gamma</li></ul></html>', | ||
| }, | ||
| { | ||
| name: 'unordered list with empty items', | ||
| snapshot: 'enriched-text-unordered-list-empty-items.png', | ||
| html: '<html><h4>Empty lists</h4><ul><li></li><li>Alpha</li><li></li><li>Gamma</li><li></li></ul><p>bottom</p></html>', | ||
| }, | ||
| { | ||
| name: 'ordered list', | ||
| snapshot: 'enriched-text-ordered-list.png', | ||
| html: '<html><ol><li>One</li><li>Two</li><li>Three</li></ol></html>', | ||
| }, | ||
| { | ||
| name: 'ordered list with empty items', | ||
| snapshot: 'enriched-text-ordered-list-empty-items.png', | ||
| html: '<html><h4>Empty lists</h4><ol><li></li><li>One</li><li></li><li>Three</li><li></li></ol><p>bottom</p></html>', | ||
| }, | ||
| { | ||
| name: 'checkbox list all unchecked', | ||
| snapshot: 'enriched-text-checkbox-list-unchecked.png', | ||
| html: '<html><ul data-type="checkbox"><li>one</li><li>two</li></ul></html>', | ||
| }, | ||
| { | ||
| name: 'checkbox list with checked item', | ||
| snapshot: 'enriched-text-checkbox-list-checked.png', | ||
| html: '<html><ul data-type="checkbox"><li checked>one</li><li>two</li></ul></html>', | ||
| }, | ||
| { | ||
| name: 'checkbox list with empty items', | ||
| snapshot: 'enriched-text-checkbox-list-empty-items.png', | ||
| html: '<html><h4>Empty lists</h4><ul data-type="checkbox"><li></li><li checked>one</li><li></li><li>three</li><li checked></li></ul><p>bottom</p></html>', | ||
| }, | ||
| ]; | ||
|
|
||
| for (const c of cases) { | ||
| test(c.name, async ({ page }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue(page, c.html); | ||
|
|
||
| await expect(displayLocator(page)).toHaveScreenshot(c.snapshot); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| test.describe('visual: complex lists and layouts', () => { | ||
| const cases = [ | ||
| { | ||
| name: 'all 3 types of the list at once', | ||
| snapshot: 'enriched-text-all-list-types.png', | ||
| html: [ | ||
| '<html>', | ||
| '<ul><li>Bullet item</li></ul>', | ||
| '<ol><li>Numbered item</li></ol>', | ||
| '<ul data-type="checkbox"><li checked>Checked item</li><li>Unchecked item</li></ul>', | ||
| '</html>', | ||
| ].join(''), | ||
| }, | ||
| ]; | ||
|
|
||
| for (const c of cases) { | ||
| test(c.name, async ({ page }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue(page, c.html); | ||
| await expect(displayLocator(page)).toHaveScreenshot(c.snapshot); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| test.describe('visual: typography, blocks, and wrapping', () => { | ||
| const cases = [ | ||
| { | ||
| name: 'all 6 headings', | ||
| snapshot: 'enriched-text-all-headings.png', | ||
| html: '<html><h1>Heading 1</h1><h2>Heading 2</h2><h3>Heading 3</h3><h4>Heading 4</h4><h5>Heading 5</h5><h6>Heading 6</h6></html>', | ||
| }, | ||
| { | ||
| name: 'blockquote, code, codeblock', | ||
| snapshot: 'enriched-text-blockquote-code-codeblock.png', | ||
| html: [ | ||
| '<html>', | ||
| '<blockquote><p>This is a blockquote. Blockquote for quoting in a block.</p></blockquote>', | ||
| '<p>Here is some <code>inline code</code> mixed in text.</p>', | ||
| '<codeblock><p>function test() {</p><p> return true;</p><p>}</p></codeblock>', | ||
| '</html>', | ||
| ].join(''), | ||
| }, | ||
| { | ||
| name: 'multiple newlines and multiple spaces', | ||
| snapshot: 'enriched-text-newlines-spaces.png', | ||
| html: [ | ||
| '<html>', | ||
| '<p>Word spaced out a lot.</p>', | ||
| '<p><br></p>', | ||
| '<p><br></p>', | ||
| '<p>Text after empty newlines.</p>', | ||
| '</html>', | ||
| ].join(''), | ||
| }, | ||
| { | ||
| name: 'line wrapping', | ||
| snapshot: 'enriched-text-line-wrapping.png', | ||
| html: [ | ||
| '<html>', | ||
| '<p>This is a standard paragraph with enough text that it should naturally wrap to the next line when it reaches the edge of the container.</p>', | ||
| '<p>SuperLongWordWithoutAnySpacesThatShouldForceTheWordBreakOrOverflowWrapRuleToKickInAndPreventTheLayoutFromBreakingHorizontally</p>', | ||
| '</html>', | ||
| ].join(''), | ||
| }, | ||
| ]; | ||
|
|
||
| for (const c of cases) { | ||
| test(c.name, async ({ page }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue(page, c.html); | ||
| await expect(displayLocator(page)).toHaveScreenshot(c.snapshot); | ||
| }); | ||
| } | ||
| }); | ||
|
|
||
| test.describe('visual: mentions', () => { | ||
| test('display mentions', async ({ page }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue( | ||
| page, | ||
| '<html><p>Hello <mention indicator="@" text="@John Doe">@Jo<s>hn D</s>oe</mention>!</p></html>' | ||
| ); | ||
| await expect(displayLocator(page)).toHaveScreenshot( | ||
| 'enriched-text-mentions.png' | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| test.describe('visual: images', () => { | ||
| test.beforeEach(async ({ page }) => { | ||
| const routePattern = '**/pw-e2e-ok.png'; | ||
| const pngBody = Buffer.from( | ||
| 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mP8z8BQDwAEhQGAhKmMIQAAAABJRU5ErkJggg==', | ||
| 'base64' | ||
| ); | ||
| await page.route(routePattern, async (route) => { | ||
| await route.fulfill({ | ||
| status: 200, | ||
| contentType: 'image/png', | ||
| body: pngBody, | ||
| }); | ||
| }); | ||
|
|
||
| // Abort broken image to force placeholder | ||
| const brokenPattern = '**/pw-e2e-broken.png'; | ||
| await page.route(brokenPattern, (route) => route.abort()); | ||
| }); | ||
|
|
||
| const cases = [ | ||
| { | ||
| name: 'inline images next to some text', | ||
| snapshot: 'enriched-text-images-inline.png', | ||
| html: '<html><p>Start text <img src="/pw-e2e-ok.png" width="40" height="40" /> end text.</p></html>', | ||
| }, | ||
| { | ||
| name: 'inline images inside list', | ||
| snapshot: 'enriched-text-images-inside-list.png', | ||
| html: '<html><ul><li>Bullet item <img src="/pw-e2e-ok.png" width="20" height="20" /> with image.</li></ul></html>', | ||
| }, | ||
| { | ||
| name: 'image placeholder display next to some text', | ||
| snapshot: 'enriched-text-images-placeholder-inline.png', | ||
| html: '<html><p>Look at this broken <img src="/pw-e2e-broken.png" width="60" height="60" /> picture.</p></html>', | ||
| }, | ||
| { | ||
| name: 'image placeholder inside lists', | ||
| snapshot: 'enriched-text-images-placeholder-list.png', | ||
| html: '<html><ol><li>List with a broken image <img src="" width="20" height="20" /> inside.</li></ol></html>', | ||
| }, | ||
| ]; | ||
|
|
||
| for (const c of cases) { | ||
| test(c.name, async ({ page }) => { | ||
| await gotoTestEnrichedText(page); | ||
| await setEnrichedTextValue(page, c.html); | ||
|
|
||
| await page.waitForTimeout(100); | ||
|
|
||
| await expect(displayLocator(page)).toHaveScreenshot(c.snapshot); | ||
| }); | ||
| } | ||
| }); | ||
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.
Uh oh!
There was an error while loading. Please reload this page.