refactor(editor): set readonly (#9475)

This commit is contained in:
Saul-Mirone
2025-01-02 04:02:15 +00:00
parent d0983696c0
commit be387a6f33
17 changed files with 32 additions and 50 deletions

View File

@@ -226,10 +226,7 @@ export class TextRenderer extends WithDisposable(ShadowlessElement) {
this.disposables.add(() => {
doc.blockCollection.clearQuery(this._query);
});
this._doc.awarenessStore.setReadonly(
this._doc.blockCollection,
true
);
this._doc.readonly = true;
this.requestUpdate();
if (this.state !== 'generating') {
this._clearTimer();

View File

@@ -169,7 +169,7 @@ export const useSnapshotPage = (
page = historyShellWorkspace.createDoc({
id: pageId,
});
page.awarenessStore.setReadonly(page.blockCollection, true);
page.readonly = true;
const spaceDoc = page.spaceDoc;
page.load(() => {
applyUpdate(spaceDoc, new Uint8Array(snapshot));

View File

@@ -56,11 +56,8 @@ export function useDocMetaHelper() {
const setDocReadonly = useCallback(
(docId: string, readonly: boolean) => {
const doc = workspaceService.workspace.docCollection.getDoc(docId);
if (doc?.blockCollection) {
workspaceService.workspace.docCollection.awarenessStore.setReadonly(
doc.blockCollection,
readonly
);
if (doc) {
doc.readonly = readonly;
}
},
[workspaceService]

View File

@@ -359,7 +359,7 @@ export const ShapeSettings = () => {
) as EdgelessRootService;
const surface = getSurfaceBlock(doc);
if (!surface) return;
doc.awarenessStore.setReadonly(doc.blockCollection, false);
doc.readonly = false;
surface.getElementsByType('shape').forEach(node => {
const shape = node as ShapeElementModel;
const { shapeType, radius } = shape;
@@ -367,7 +367,7 @@ export const ShapeSettings = () => {
const props = editorSetting.get(`shape:${shapeName}`);
edgelessService.crud.updateElement(shape.id, props);
});
doc.awarenessStore.setReadonly(doc.blockCollection, true);
doc.readonly = true;
},
[editorSetting]
);

View File

@@ -77,11 +77,11 @@ export const EdgelessSnapshot = (props: Props) => {
) as EdgelessRootService;
const elements = getElements(doc);
const props = editorSetting.get(keyName) as any;
doc.awarenessStore.setReadonly(doc.blockCollection, false);
doc.readonly = false;
elements.forEach(element => {
edgelessService.crud.updateElement(element.id, props);
});
doc.awarenessStore.setReadonly(doc.blockCollection, true);
doc.readonly = true;
}, [editorSetting, getElements, keyName]);
const renderEditor = useCallback(async () => {
@@ -112,7 +112,7 @@ export const EdgelessSnapshot = (props: Props) => {
) as EdgelessRootService;
edgelessService.specSlots.viewConnected.once(({ component }) => {
const edgelessBlock = component as any;
doc.awarenessStore.setReadonly(doc.blockCollection, false);
doc.readonly = false;
edgelessBlock.editorViewportSelector = 'ref-viewport';
const frame = getFrameBlock(doc);
if (frame) {
@@ -121,7 +121,7 @@ export const EdgelessSnapshot = (props: Props) => {
}
const bound = boundMap.get(docName);
bound && edgelessService.viewport.setViewportByBound(bound);
doc.awarenessStore.setReadonly(doc.blockCollection, true);
doc.readonly = true;
});
// append to dom node

View File

@@ -51,10 +51,7 @@ const useLoadDoc = (pageId: string) => {
useEffect(() => {
if (doc && isInTrash) {
currentWorkspace.docCollection.awarenessStore.setReadonly(
doc.blockSuiteDoc.blockCollection,
true
);
doc.blockSuiteDoc.readonly = true;
}
}, [currentWorkspace.docCollection.awarenessStore, doc, isInTrash]);

View File

@@ -211,10 +211,7 @@ const SharePageInner = ({
.then(() => {
const { doc } = workspace.scope.get(DocsService).open(docId);
workspace.docCollection.awarenessStore.setReadonly(
doc.blockSuiteDoc.blockCollection,
true
);
doc.blockSuiteDoc.readonly = true;
setPage(doc);