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][@lexical/selection] Feature: add a generic classes property to all nodes for easier customization #6929

Open
wants to merge 24 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
6323262
add __classes, getClasses and mutateClasses
GermanJablo Dec 5, 2024
7bb7820
amend
GermanJablo Dec 5, 2024
bede9a9
fix errors
GermanJablo Dec 5, 2024
264b87b
fix $canSimpleTextNodesBeMerged and exportDOM
GermanJablo Dec 6, 2024
f290e0c
add test
GermanJablo Dec 6, 2024
b9fa298
rename $mutateSelectedTextNodes to $forEachSelectedTextNode
GermanJablo Dec 6, 2024
0ff2383
add docs
GermanJablo Dec 6, 2024
10454ee
add tests for exportJSON
GermanJablo Dec 6, 2024
5c554d2
test name
GermanJablo Dec 6, 2024
b6e7525
spread classes
GermanJablo Dec 9, 2024
38764d4
fix updateDOM
GermanJablo Dec 9, 2024
a367219
comment typo
GermanJablo Dec 9, 2024
df4f570
remove comment
GermanJablo Dec 9, 2024
ae2c32a
replace mutateClasses with setClass
GermanJablo Dec 10, 2024
727d47d
update docs
GermanJablo Dec 10, 2024
00c711e
revert getClasses, allow empty object classes, move clone logic to af…
GermanJablo Dec 10, 2024
3da33aa
fix afterCloneFrom
GermanJablo Dec 10, 2024
110e591
Update packages/lexical/src/LexicalNode.ts
GermanJablo Dec 11, 2024
b96a12e
Update packages/lexical/src/LexicalNode.ts
GermanJablo Dec 11, 2024
a2fb1df
Update packages/lexical/src/LexicalEditorState.ts
GermanJablo Dec 11, 2024
66d0679
revert doc url name changed
GermanJablo Dec 11, 2024
2908b29
node.__classes check is actually needed as long as the property is op…
GermanJablo Dec 11, 2024
b8e09bb
|| {} is actually needed as long as the property is optional
GermanJablo Dec 11, 2024
0372f9e
revert || {} is actually needed as long as the property is optional. …
GermanJablo Dec 11, 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
7 changes: 3 additions & 4 deletions packages/lexical/src/LexicalNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ export class LexicalNode {
*/
getClasses(): ReadonlyClasses {
const self = this.getLatest();
return {...self.__classes};
return self.__classes || {};
GermanJablo marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand All @@ -233,9 +233,7 @@ export class LexicalNode {
} else {
classes[key] = value;
}
if (Object.keys(classes).length > 0) {
self.__classes = classes;
}
self.__classes = classes;
}

// Flow doesn't support abstract classes unfortunately, so we can't _force_
Expand Down Expand Up @@ -325,6 +323,7 @@ export class LexicalNode {
this.__parent = prevNode.__parent;
this.__next = prevNode.__next;
this.__prev = prevNode.__prev;
this.__classes = {...prevNode.__classes};
GermanJablo marked this conversation as resolved.
Show resolved Hide resolved
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down
6 changes: 0 additions & 6 deletions packages/lexical/src/LexicalUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1436,9 +1436,6 @@ export function $isRootOrShadowRoot(
*/
export function $copyNode<T extends LexicalNode>(node: T): T {
const copy = node.constructor.clone(node) as T;
if (node.__classes) {
copy.__classes = {...node.__classes};
}
$setNodeKey(copy, null);
return copy;
}
Expand Down Expand Up @@ -1844,9 +1841,6 @@ export function getCachedTypeToNodeMap(
export function $cloneWithProperties<T extends LexicalNode>(latestNode: T): T {
const constructor = latestNode.constructor;
const mutableNode = constructor.clone(latestNode) as T;
if (latestNode.__classes) {
mutableNode.__classes = {...latestNode.__classes};
}
mutableNode.afterCloneFrom(latestNode);
if (__DEV__) {
invariant(
Expand Down
Loading