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

[lexical][Breaking Change][lexical-rich-text][lexical-playground] Feature: Support capitalization format #6897

Merged
merged 27 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from 25 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
3f1fd82
WIP: create capitalization node
bedre7 Nov 11, 2024
4bb2071
add capitalization types to lexical text node format types
bedre7 Nov 18, 2024
d88f2db
add capitalization format to the lexical playground
bedre7 Nov 18, 2024
e0aec5b
unit test for capitalization formats
bedre7 Nov 19, 2024
e5f931e
refactor unit test
bedre7 Nov 19, 2024
284a189
add icons to capitalization toolbar buttons
bedre7 Nov 19, 2024
7760eb3
add new capitalization formats to flow
bedre7 Nov 19, 2024
2b926a6
update toolbar labels for new formats
bedre7 Nov 21, 2024
e512eab
remove titlecase
bedre7 Nov 22, 2024
53809bd
add keyboard shortcuts for new formatting options
bedre7 Nov 29, 2024
a789195
e2e test for new keyboard shortcuts
bedre7 Nov 29, 2024
fdc5785
Merge branch 'main' into feature/support-capitalization
bedre7 Nov 29, 2024
73e0a0d
add missing type to flow
bedre7 Nov 29, 2024
6dcb401
e2e test for new formatting options
bedre7 Dec 2, 2024
5339161
Merge branch 'main' into feature/support-capitalization
bedre7 Dec 2, 2024
90dd330
refactor
bedre7 Dec 2, 2024
d258d0d
add capitalize format
bedre7 Dec 3, 2024
22faa2c
fix failing integrity test
bedre7 Dec 5, 2024
8469d94
test for capitalize format
Shopiley Dec 11, 2024
44f2078
keyboard shortcut handler for capitalize
Shopiley Dec 12, 2024
16937b4
add capitalization formats to floating toolbar
Shopiley Dec 12, 2024
1e437b7
Merge branch 'main' into feature/support-capitalization
bedre7 Dec 13, 2024
b2dca35
Merge branch 'feature/support-capitalization2' of https://github.com/…
bedre7 Dec 13, 2024
41dd59a
Merge branch 'feature/support-capitalization' of https://github.com/b…
bedre7 Dec 13, 2024
ac60ad9
fix failing tests and add title attribute to floating toolbar buttons
bedre7 Dec 13, 2024
39132d6
Update packages/lexical/flow/Lexical.js.flow
etrepum Dec 14, 2024
8138785
Merge branch 'main' into feature/support-capitalization
etrepum Dec 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,17 @@ import {
selectCharacters,
toggleBold,
toggleBulletList,
toggleCapitalize,
toggleChecklist,
toggleInsertCodeBlock,
toggleItalic,
toggleLowercase,
toggleNumberedList,
toggleStrikethrough,
toggleSubscript,
toggleSuperscript,
toggleUnderline,
toggleUppercase,
} from '../keyboardShortcuts/index.mjs';
import {
assertHTML,
Expand Down Expand Up @@ -112,6 +115,18 @@ const alignmentTestCases = [
];

const additionalStylesTestCases = [
{
applyShortcut: (page) => toggleLowercase(page),
style: 'Lowercase',
},
{
applyShortcut: (page) => toggleUppercase(page),
style: 'Uppercase',
},
{
applyShortcut: (page) => toggleCapitalize(page),
style: 'Capitalize',
},
{
applyShortcut: (page) => toggleStrikethrough(page),
style: 'Strikethrough',
Expand Down
142 changes: 142 additions & 0 deletions packages/lexical-playground/__tests__/e2e/TextFormatting.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,11 @@ import {
moveToLineEnd,
selectCharacters,
toggleBold,
toggleCapitalize,
toggleItalic,
toggleLowercase,
toggleUnderline,
toggleUppercase,
} from '../keyboardShortcuts/index.mjs';
import {
assertHTML,
Expand Down Expand Up @@ -428,6 +431,145 @@ test.describe.parallel('TextFormatting', () => {
});
});

const capitalizationFormats = [
{
applyCapitalization: toggleLowercase,
className: 'PlaygroundEditorTheme__textLowercase',
format: 'lowercase',
},
{
applyCapitalization: toggleUppercase,
className: 'PlaygroundEditorTheme__textUppercase',
format: 'uppercase',
},
{
applyCapitalization: toggleCapitalize,
className: 'PlaygroundEditorTheme__textCapitalize',
format: 'capitalize',
},
];

capitalizationFormats.forEach(({className, format, applyCapitalization}) => {
test(`Can select text and change it to ${format}`, async ({
page,
isPlainText,
}) => {
test.skip(isPlainText);

await focusEditor(page);
await page.keyboard.type('Hello world!');
await moveLeft(page);
await selectCharacters(page, 'left', 5);

await assertSelection(page, {
anchorOffset: 11,
anchorPath: [0, 0, 0],
focusOffset: 6,
focusPath: [0, 0, 0],
});

await applyCapitalization(page);
await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">Hello</span>
<span class="${className}" data-lexical-text="true">world</span>
<span data-lexical-text="true">!</span>
</p>
`,
);

await assertSelection(page, {
anchorOffset: 5,
anchorPath: [0, 1, 0],
focusOffset: 0,
focusPath: [0, 1, 0],
});
});
});

const capitalizationResettingTestCases = [
{
expectedFinalHTML: html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span class="$formatClassName" data-lexical-text="true">Hello</span>
<span data-lexical-text="true">world!</span>
</p>
`,
key: 'Space',
},
{
expectedFinalHTML: html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span class="$formatClassName" data-lexical-text="true">Hello</span>
<span
class="PlaygroundEditorTheme__tabNode"
data-lexical-text="true"></span>
<span data-lexical-text="true">world!</span>
</p>
`,
key: 'Tab',
},
{
expectedFinalHTML: html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span class="$formatClassName" data-lexical-text="true">Hello</span>
</p>
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span data-lexical-text="true">world!</span>
</p>
`,
key: 'Enter',
},
];

capitalizationFormats.forEach(({format, className, applyCapitalization}) => {
capitalizationResettingTestCases.forEach(({key, expectedFinalHTML}) => {
test(`Pressing ${key} resets ${format} format`, async ({
page,
isPlainText,
}) => {
test.skip(isPlainText);

await focusEditor(page);

await applyCapitalization(page);
await page.keyboard.type('Hello');

await assertHTML(
page,
html`
<p
class="PlaygroundEditorTheme__paragraph PlaygroundEditorTheme__ltr"
dir="ltr">
<span class="${className}" data-lexical-text="true">Hello</span>
</p>
`,
);

// Pressing the key should reset the format
await page.keyboard.press(key);
await page.keyboard.type(' world!');

await assertHTML(
page,
expectedFinalHTML.replace('$formatClassName', className),
);
});
});
});

test(`Can select text and increase the font-size`, async ({
page,
isPlainText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,30 @@ export async function toggleInsertCodeBlock(page) {
await page.keyboard.up('Shift');
}

export async function toggleLowercase(page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.down('Shift');
await page.keyboard.press('1');
await keyUpCtrlOrMeta(page);
await page.keyboard.up('Shift');
}

export async function toggleUppercase(page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.down('Shift');
await page.keyboard.press('2');
await keyUpCtrlOrMeta(page);
await page.keyboard.up('Shift');
}

export async function toggleCapitalize(page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.down('Shift');
await page.keyboard.press('3');
await keyUpCtrlOrMeta(page);
await page.keyboard.up('Shift');
}

export async function toggleStrikethrough(page) {
await keyDownCtrlOrMeta(page);
await page.keyboard.down('Shift');
Expand Down
5 changes: 5 additions & 0 deletions packages/lexical-playground/src/context/ToolbarContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export const blockTypeToBlockName = {
quote: 'Quote',
};

//disable eslint sorting rule for quick reference to toolbar state
/* eslint-disable sort-keys-fix/sort-keys-fix */
const INITIAL_TOOLBAR_STATE = {
bgColor: '#fff',
blockType: 'paragraph' as keyof typeof blockTypeToBlockName,
Expand All @@ -63,6 +65,9 @@ const INITIAL_TOOLBAR_STATE = {
isSubscript: false,
isSuperscript: false,
isUnderline: false,
isLowercase: false,
isUppercase: false,
isCapitalize: false,
rootType: 'root' as keyof typeof rootTypeToRootName,
};

Expand Down
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.
12 changes: 12 additions & 0 deletions packages/lexical-playground/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,18 @@ i.underline {
background-image: url(images/icons/type-underline.svg);
}

i.uppercase {
background-image: url(images/icons/type-uppercase.svg);
}

i.lowercase {
background-image: url(images/icons/type-lowercase.svg);
}

i.capitalize {
background-image: url(images/icons/type-capitalize.svg);
}

i.strikethrough {
background-image: url(images/icons/type-strikethrough.svg);
}
Expand Down
Loading
Loading