Skip to content

Commit

Permalink
feat(richtext-lexical): allow customizing maxActiveItems for toolbar …
Browse files Browse the repository at this point in the history
…groups (#9417)

Previously, they were hardcoded to 1. This is useful for lexical toolbar
groups where multiple items can be active at the same time.
  • Loading branch information
AlessioGr authored Nov 21, 2024
1 parent 18b139b commit 38de760
Show file tree
Hide file tree
Showing 17 changed files with 115 additions and 6 deletions.
6 changes: 6 additions & 0 deletions packages/richtext-lexical/src/features/align/server/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ export const i18n: Partial<GenericLanguages> = {
alignLeftLabel: 'Zarovnat vlevo',
alignRightLabel: 'Zarovnat vpravo',
},
da: {
alignCenterLabel: 'Centrer teksten',
alignJustifyLabel: 'Justér til begge sider',
alignLeftLabel: 'Justér til venstre',
alignRightLabel: 'Juster til højre',
},
de: {
alignCenterLabel: 'Zentrieren',
alignJustifyLabel: 'Blocksatz',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const i18n: Partial<GenericLanguages> = {
cs: {
label: 'Citace',
},
da: {
label: 'Blokering',
},
de: {
label: 'Blockzitat',
},
Expand Down
9 changes: 9 additions & 0 deletions packages/richtext-lexical/src/features/blocks/server/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ export const i18n: Partial<GenericLanguages> = {
},
label: 'Bloky',
},
da: {
inlineBlocks: {
create: 'Opret {{label}}',
edit: 'Rediger {{label}}',
label: 'Indlejrede blokke',
remove: 'Fjern {{label}}',
},
label: 'Blokke',
},
de: {
inlineBlocks: {
create: 'Erstelle {{label}}',
Expand Down
3 changes: 3 additions & 0 deletions packages/richtext-lexical/src/features/heading/server/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const i18n: Partial<GenericLanguages> = {
cs: {
label: 'Nadpis {{headingLevel}}',
},
da: {
label: 'Overskrift {{overskriftNiveau}}',
},
de: {
label: 'Überschrift {{headingLevel}}',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const i18n: Partial<GenericLanguages> = {
cs: {
label: 'Vodorovný pravítko',
},
da: {
label: 'Horisontal Regel',
},
de: {
label: 'Trennlinie',
},
Expand Down
4 changes: 4 additions & 0 deletions packages/richtext-lexical/src/features/indent/server/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const i18n: Partial<GenericLanguages> = {
decreaseLabel: 'Zmenšit odsazení',
increaseLabel: 'Zvětšit odsazení',
},
da: {
decreaseLabel: 'Reducer Indrykning',
increaseLabel: 'Forøg indrykning',
},
de: {
decreaseLabel: 'Einzug verkleinern',
increaseLabel: 'Einzug erhöhen',
Expand Down
4 changes: 4 additions & 0 deletions packages/richtext-lexical/src/features/link/server/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const i18n: Partial<GenericLanguages> = {
label: 'Odkaz',
loadingWithEllipsis: 'Načítání...',
},
da: {
label: 'Link',
loadingWithEllipsis: 'Indlæser...',
},
de: {
label: 'Verknüpfung',
loadingWithEllipsis: 'Laden...',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const i18n: Partial<GenericLanguages> = {
cs: {
label: 'Seznam kontrol',
},
da: {
label: 'Tjekliste',
},
de: {
label: 'Checkliste',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const i18n: Partial<GenericLanguages> = {
cs: {
label: 'Seřazený seznam',
},
da: {
label: 'Ordnet Liste',
},
de: {
label: 'Geordnete Liste',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const i18n: Partial<GenericLanguages> = {
cs: {
label: 'Neuspořádaný seznam',
},
da: {
label: 'Usorteret Liste',
},
de: {
label: 'Ungeordnete Liste',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ export const i18n: Partial<GenericLanguages> = {
label: 'Odstavec',
label2: 'Normální text',
},
da: {
label: 'Afsnit',
label2: 'Normal tekst',
},
de: {
label: 'Paragraph',
label2: 'Normaler Text',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const i18n: Partial<GenericLanguages> = {
cs: {
label: 'Vztah',
},
da: {
label: 'Forhold',
},
de: {
label: 'Beziehung',
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,19 @@ function ToolbarGroupComponent({
if (label.length > 25) {
label = label.substring(0, 25) + '...'
}
setDropdownLabel(label)
setDropdownIcon(() => item.ChildComponent)
if (activeItems.length === 1) {
setDropdownLabel(label)
setDropdownIcon(() => item.ChildComponent)
} else {
setDropdownLabel(
i18n.t('lexical:general:toolbarItemsActive', { count: activeItems.length }),
)
if (group?.type === 'dropdown' && group.items.length && group.ChildComponent) {
setDropdownIcon(() => group.ChildComponent!)
} else {
setDropdownIcon(undefined)
}
}
},
[group, i18n, featureClientSchemaMap, schemaPath],
)
Expand All @@ -115,7 +126,7 @@ function ToolbarGroupComponent({
Icon={DropdownIcon}
itemsContainerClassNames={['fixed-toolbar__dropdown-items']}
label={dropdownLabel}
maxActiveItems={1}
maxActiveItems={group.maxActiveItems ?? 1}
onActiveChange={onActiveChange}
/>
) : (
Expand All @@ -125,7 +136,7 @@ function ToolbarGroupComponent({
group={group}
itemsContainerClassNames={['fixed-toolbar__dropdown-items']}
label={dropdownLabel}
maxActiveItems={1}
maxActiveItems={group.maxActiveItems ?? 1}
onActiveChange={onActiveChange}
/>
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,15 +102,15 @@ function ToolbarGroupComponent({
editor={editor}
group={group}
Icon={DropdownIcon}
maxActiveItems={1}
maxActiveItems={group.maxActiveItems ?? 1}
onActiveChange={onActiveChange}
/>
) : (
<ToolbarDropdown
anchorElem={anchorElem}
editor={editor}
group={group}
maxActiveItems={1}
maxActiveItems={group.maxActiveItems ?? 1}
onActiveChange={onActiveChange}
/>
)
Expand Down
9 changes: 9 additions & 0 deletions packages/richtext-lexical/src/features/toolbars/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ export type ToolbarDropdownGroup = {
* Each toolbar group needs to have a unique key. Groups with the same keys will have their items merged together.
*/
key: string
/**
* The maximum number of active items that can be selected at once.
* Increasing this will hurt performance, as more nodes need to be checked for their active state.
*
* E.g. if this is 1, we can stop checking nodes once we find an active node.
*
* @default 1
*/
maxActiveItems?: number
/**
* Determines where the toolbar group will be.
*/
Expand Down
3 changes: 3 additions & 0 deletions packages/richtext-lexical/src/features/upload/server/i18n.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ export const i18n: Partial<GenericLanguages> = {
cs: {
label: 'Nahrát',
},
da: {
label: 'Upload',
},
de: {
label: 'Datei',
},
Expand Down
Loading

0 comments on commit 38de760

Please sign in to comment.