mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 04:48:53 +00:00
refactor(editor): set readonly (#9475)
This commit is contained in:
@@ -163,17 +163,14 @@ describe('basic', () => {
|
||||
doc.slots.rootAdded.on(rootAddedCallback);
|
||||
|
||||
doc.load(() => {
|
||||
expect(doc.ready).toBe(false);
|
||||
const rootId = doc.addBlock('affine:page', {
|
||||
title: new doc.Text(),
|
||||
});
|
||||
expect(rootAddedCallback).toBeCalledTimes(1);
|
||||
expect(doc.ready).toBe(false);
|
||||
|
||||
doc.addBlock('affine:note', {}, rootId);
|
||||
});
|
||||
|
||||
expect(doc.ready).toBe(true);
|
||||
expect(readyCallback).toBeCalledTimes(1);
|
||||
});
|
||||
|
||||
|
||||
@@ -258,13 +258,13 @@ test('local readonly', () => {
|
||||
expect(doc2?.readonly).toBeTruthy();
|
||||
expect(doc3?.readonly).toBeFalsy();
|
||||
|
||||
collection.awarenessStore.setReadonly(doc1.blockCollection, true);
|
||||
doc1.readonly = true;
|
||||
|
||||
expect(doc1.readonly).toBeTruthy();
|
||||
expect(doc2?.readonly).toBeTruthy();
|
||||
expect(doc3?.readonly).toBeTruthy();
|
||||
|
||||
collection.awarenessStore.setReadonly(doc1.blockCollection, false);
|
||||
doc1.readonly = false;
|
||||
|
||||
expect(doc1.readonly).toBeFalsy();
|
||||
expect(doc2?.readonly).toBeTruthy();
|
||||
|
||||
@@ -37,7 +37,7 @@ export class Doc {
|
||||
mode: 'loose',
|
||||
};
|
||||
|
||||
protected readonly _readonly?: boolean;
|
||||
protected _readonly?: boolean;
|
||||
|
||||
protected readonly _schema: Schema;
|
||||
|
||||
@@ -144,10 +144,6 @@ export class Doc {
|
||||
return this._blockCollection.awarenessStore;
|
||||
}
|
||||
|
||||
get awarenessSync() {
|
||||
return this.collection.awarenessSync;
|
||||
}
|
||||
|
||||
get blobSync() {
|
||||
return this.collection.blobSync;
|
||||
}
|
||||
@@ -184,10 +180,6 @@ export class Doc {
|
||||
return this._blockCollection.collection;
|
||||
}
|
||||
|
||||
get docSync() {
|
||||
return this.collection.docSync;
|
||||
}
|
||||
|
||||
get generateBlockId() {
|
||||
return this._blockCollection.generateBlockId.bind(this._blockCollection);
|
||||
}
|
||||
@@ -219,6 +211,16 @@ export class Doc {
|
||||
return this._readonly === true;
|
||||
}
|
||||
|
||||
set readonly(value: boolean) {
|
||||
this._blockCollection.awarenessStore.setReadonly(
|
||||
this._blockCollection,
|
||||
value
|
||||
);
|
||||
if (this._readonly !== undefined && this._readonly !== value) {
|
||||
this._readonly = value;
|
||||
}
|
||||
}
|
||||
|
||||
get ready() {
|
||||
return this._blockCollection.ready;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user