mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 21:05:19 +00:00
refactor(editor): set readonly (#9475)
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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));
|
||||
|
||||
@@ -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]
|
||||
|
||||
@@ -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]
|
||||
);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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]);
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user