mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-17 14:27:02 +08:00
fix: edgeless note preview on the editor settings is editable (#8735)
Fix issue [BS-1779](https://linear.app/affine-design/issue/BS-1779). The attribute `contenteditable` will be `true` if the document is not read-only. In this case, the note preview can be focused on and users can edit the note content. But we can not simply make the document read-only. If the user changes the editor settings, we also need to update the document model, which requires that the document is not read-only. Thus following code sets the document editable before the model updates and resets the document to read-only after the model is updated.
This commit is contained in:
@@ -355,6 +355,7 @@ export const ShapeSettings = () => {
|
|||||||
) as EdgelessRootService;
|
) as EdgelessRootService;
|
||||||
const surface = getSurfaceBlock(doc);
|
const surface = getSurfaceBlock(doc);
|
||||||
if (!surface) return;
|
if (!surface) return;
|
||||||
|
doc.awarenessStore.setReadonly(doc.blockCollection, false);
|
||||||
surface.getElementsByType('shape').forEach(node => {
|
surface.getElementsByType('shape').forEach(node => {
|
||||||
const shape = node as ShapeElementModel;
|
const shape = node as ShapeElementModel;
|
||||||
const { shapeType, radius } = shape;
|
const { shapeType, radius } = shape;
|
||||||
@@ -362,6 +363,7 @@ export const ShapeSettings = () => {
|
|||||||
const props = editorSetting.get(`shape:${shapeName}`);
|
const props = editorSetting.get(`shape:${shapeName}`);
|
||||||
edgelessService.updateElement(shape.id, props);
|
edgelessService.updateElement(shape.id, props);
|
||||||
});
|
});
|
||||||
|
doc.awarenessStore.setReadonly(doc.blockCollection, true);
|
||||||
},
|
},
|
||||||
[editorSetting]
|
[editorSetting]
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import { useCallback, useEffect, useRef } from 'react';
|
|||||||
import { map, pairwise } from 'rxjs';
|
import { map, pairwise } from 'rxjs';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
|
editorWrapper,
|
||||||
snapshotContainer,
|
snapshotContainer,
|
||||||
snapshotLabel,
|
snapshotLabel,
|
||||||
snapshotSkeleton,
|
snapshotSkeleton,
|
||||||
@@ -59,9 +60,11 @@ export const EdgelessSnapshot = (props: Props) => {
|
|||||||
) as EdgelessRootService;
|
) as EdgelessRootService;
|
||||||
const elements = getElements(doc);
|
const elements = getElements(doc);
|
||||||
const props = editorSetting.get(keyName) as any;
|
const props = editorSetting.get(keyName) as any;
|
||||||
|
doc.awarenessStore.setReadonly(doc.blockCollection, false);
|
||||||
elements.forEach(element => {
|
elements.forEach(element => {
|
||||||
edgelessService.updateElement(element.id, props);
|
edgelessService.updateElement(element.id, props);
|
||||||
});
|
});
|
||||||
|
doc.awarenessStore.setReadonly(doc.blockCollection, true);
|
||||||
}, [editorSetting, getElements, keyName]);
|
}, [editorSetting, getElements, keyName]);
|
||||||
|
|
||||||
const renderEditor = useCallback(async () => {
|
const renderEditor = useCallback(async () => {
|
||||||
@@ -74,6 +77,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
|||||||
extensions: SpecProvider.getInstance().getSpec('edgeless:preview').value,
|
extensions: SpecProvider.getInstance().getSpec('edgeless:preview').value,
|
||||||
}).render();
|
}).render();
|
||||||
docRef.current = doc;
|
docRef.current = doc;
|
||||||
|
editorHostRef.current?.remove();
|
||||||
editorHostRef.current = editorHost;
|
editorHostRef.current = editorHost;
|
||||||
|
|
||||||
if (firstUpdate) {
|
if (firstUpdate) {
|
||||||
@@ -88,6 +92,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
|||||||
) as EdgelessRootService;
|
) as EdgelessRootService;
|
||||||
edgelessService.specSlots.viewConnected.once(({ component }) => {
|
edgelessService.specSlots.viewConnected.once(({ component }) => {
|
||||||
const edgelessBlock = component as any;
|
const edgelessBlock = component as any;
|
||||||
|
doc.awarenessStore.setReadonly(doc.blockCollection, false);
|
||||||
edgelessBlock.editorViewportSelector = 'ref-viewport';
|
edgelessBlock.editorViewportSelector = 'ref-viewport';
|
||||||
const frame = getFrameBlock(doc);
|
const frame = getFrameBlock(doc);
|
||||||
if (frame) {
|
if (frame) {
|
||||||
@@ -96,6 +101,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
|||||||
}
|
}
|
||||||
const bound = boundMap.get(docName);
|
const bound = boundMap.get(docName);
|
||||||
bound && edgelessService.viewport.setViewportByBound(bound);
|
bound && edgelessService.viewport.setViewportByBound(bound);
|
||||||
|
doc.awarenessStore.setReadonly(doc.blockCollection, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
// append to dom node
|
// append to dom node
|
||||||
@@ -133,16 +139,7 @@ export const EdgelessSnapshot = (props: Props) => {
|
|||||||
<div className={snapshotContainer}>
|
<div className={snapshotContainer}>
|
||||||
<div className={snapshotTitle}>{title}</div>
|
<div className={snapshotTitle}>{title}</div>
|
||||||
<div className={snapshotLabel}>{title}</div>
|
<div className={snapshotLabel}>{title}</div>
|
||||||
<div
|
<div ref={wrapperRef} className={editorWrapper} style={{ height }}>
|
||||||
ref={wrapperRef}
|
|
||||||
style={{
|
|
||||||
position: 'relative',
|
|
||||||
pointerEvents: 'none',
|
|
||||||
userSelect: 'none',
|
|
||||||
overflow: 'hidden',
|
|
||||||
height,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<Skeleton
|
<Skeleton
|
||||||
className={snapshotSkeleton}
|
className={snapshotSkeleton}
|
||||||
variant="rounded"
|
variant="rounded"
|
||||||
|
|||||||
@@ -76,6 +76,13 @@ export const snapshotLabel = style({
|
|||||||
height: '24px',
|
height: '24px',
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const editorWrapper = style({
|
||||||
|
position: 'relative',
|
||||||
|
pointerEvents: 'none',
|
||||||
|
userSelect: 'none',
|
||||||
|
overflow: 'hidden',
|
||||||
|
});
|
||||||
|
|
||||||
export const shapeIndicator = style({
|
export const shapeIndicator = style({
|
||||||
boxShadow: 'none',
|
boxShadow: 'none',
|
||||||
backgroundColor: cssVarV2('layer/background/tertiary'),
|
backgroundColor: cssVarV2('layer/background/tertiary'),
|
||||||
|
|||||||
Reference in New Issue
Block a user