Skip to content

Commit

Permalink
Remove redundant readonly checks. (#2921)
Browse files Browse the repository at this point in the history
* allow selection in readonly mode

* prevent non-collab updates in readonly mode

* remove redundant readOnly checks

* remove code
  • Loading branch information
acywatson authored and thegreatercurve committed Nov 25, 2022
1 parent 11ff2f8 commit a7ce4ce
Show file tree
Hide file tree
Showing 4 changed files with 1 addition and 16 deletions.
1 change: 1 addition & 0 deletions packages/lexical-react/src/shared/useYjsCollaboration.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ export function useYjsCollaboration(
provider.on('status', onStatus);
provider.on('sync', onSync);
awareness.on('update', onAwarenessUpdate);
// This updates the local editor state when we recieve updates from other clients
root.getSharedType().observeDeep(onYjsTreeChanges);
const removeListener = editor.registerUpdateListener(
({
Expand Down
2 changes: 0 additions & 2 deletions packages/lexical/src/LexicalNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -637,7 +637,6 @@ export class LexicalNode {
// Setters and mutators

remove(preserveEmptyParent?: boolean): void {
errorOnReadOnly();
removeNode(this, true, preserveEmptyParent);
}

Expand Down Expand Up @@ -728,7 +727,6 @@ export class LexicalNode {
}

insertBefore(nodeToInsert: LexicalNode): LexicalNode {
errorOnReadOnly();
const writableSelf = this.getWritable();
const writableNodeToInsert = nodeToInsert.getWritable();
removeFromParent(writableNodeToInsert);
Expand Down
6 changes: 0 additions & 6 deletions packages/lexical/src/nodes/LexicalElementNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,30 +292,25 @@ export class ElementNode extends LexicalNode {
return this.select();
}
clear(): this {
errorOnReadOnly();
const writableSelf = this.getWritable();
const children = this.getChildren();
children.forEach((child) => child.remove());
return writableSelf;
}
append(...nodesToAppend: LexicalNode[]): this {
errorOnReadOnly();
return this.splice(this.getChildrenSize(), 0, nodesToAppend);
}
setDirection(direction: 'ltr' | 'rtl' | null): this {
errorOnReadOnly();
const self = this.getWritable();
self.__dir = direction;
return self;
}
setFormat(type: ElementFormatType): this {
errorOnReadOnly();
const self = this.getWritable();
self.__format = type !== '' ? ELEMENT_TYPE_TO_FORMAT[type] : 0;
return this;
}
setIndent(indentLevel: number): this {
errorOnReadOnly();
const self = this.getWritable();
self.__indent = indentLevel;
return this;
Expand All @@ -325,7 +320,6 @@ export class ElementNode extends LexicalNode {
deleteCount: number,
nodesToInsert: Array<LexicalNode>,
): this {
errorOnReadOnly();
const writableSelf = this.getWritable();
const writableSelfKey = writableSelf.__key;
const writableSelfChildren = writableSelf.__children;
Expand Down
8 changes: 0 additions & 8 deletions packages/lexical/src/nodes/LexicalTextNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ export class TextNode extends LexicalNode {

// TODO 0.4 This should just be a `string`.
setFormat(format: TextFormatType | number): this {
errorOnReadOnly();
const self = this.getWritable();
self.__format =
typeof format === 'string' ? TEXT_TYPE_TO_FORMAT[format] : format;
Expand All @@ -519,15 +518,13 @@ export class TextNode extends LexicalNode {

// TODO 0.4 This should just be a `string`.
setDetail(detail: TextDetailType | number): this {
errorOnReadOnly();
const self = this.getWritable();
self.__detail =
typeof detail === 'string' ? DETAIL_TYPE_TO_DETAIL[detail] : detail;
return self;
}

setStyle(style: string): this {
errorOnReadOnly();
const self = this.getWritable();
self.__style = style;
return self;
Expand All @@ -539,29 +536,25 @@ export class TextNode extends LexicalNode {
}

toggleDirectionless(): this {
errorOnReadOnly();
const self = this.getWritable();
self.__detail ^= IS_DIRECTIONLESS;
return self;
}

toggleUnmergeable(): this {
errorOnReadOnly();
const self = this.getWritable();
self.__detail ^= IS_UNMERGEABLE;
return self;
}

setMode(type: TextModeType): this {
errorOnReadOnly();
const mode = TEXT_MODE_TO_TYPE[type];
const self = this.getWritable();
self.__mode = mode;
return self;
}

setTextContent(text: string): this {
errorOnReadOnly();
const writableSelf = this.getWritable();
writableSelf.__text = text;
return writableSelf;
Expand Down Expand Up @@ -614,7 +607,6 @@ export class TextNode extends LexicalNode {
newText: string,
moveSelection?: boolean,
): TextNode {
errorOnReadOnly();
const writableSelf = this.getWritable();
const text = writableSelf.__text;
const handledTextLength = newText.length;
Expand Down

0 comments on commit a7ce4ce

Please sign in to comment.