Skip to content

Commit

Permalink
revert: note style compatibility (#5471)
Browse files Browse the repository at this point in the history
  • Loading branch information
regischen committed Nov 27, 2023
1 parent 5282fd2 commit 90a575c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 62 deletions.
12 changes: 0 additions & 12 deletions packages/blocks/src/_common/edgeless/note/consts.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { StrokeStyle } from '../../../surface-block/consts.js';
import type { CssVariableName } from '../../theme/css-variables.js';

export const NOTE_COLORS: CssVariableName[] = [
Expand All @@ -20,14 +19,3 @@ export const NOTE_SHADOWS = [
'--affine-note-shadow-float',
`--affine-note-shadow-film`,
];

export const DEFAULT_EDGELESS_PROP = {
style: {
borderRadius: 8,
borderSize: 4,
borderStyle: StrokeStyle.Solid,
shadowType: NOTE_SHADOWS[1],
},
collapse: false,
collapsedHeight: 0,
};
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { assertExists } from '@blocksuite/global/utils';
import { Workspace } from '@blocksuite/store';

import { DEFAULT_EDGELESS_PROP } from '../../../../_common/edgeless/note/consts.js';
import type { NoteBlockModel } from '../../../../models.js';
import {
CanvasTextFontFamily,
Expand Down Expand Up @@ -307,9 +306,6 @@ export function createEdgelessElement(
);
const note = page.getBlockById(id) as NoteBlockModel;
assertExists(note);
if (!note.edgeless) {
note.edgeless = DEFAULT_EDGELESS_PROP;
}
note.edgeless.collapse = true;
page.addBlock('affine:paragraph', {}, note.id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,8 @@ export class EdgelessBlockPortalNote extends EdgelessPortalBase<NoteBlockModel>
}

private get _isShowCollapsedContent() {
const edgeless = this.model.edgeless;
const collapse = edgeless ? edgeless.collapse : false;
return (
collapse &&
this.model.edgeless.collapse &&
(this._isResizing || this._isHover) &&
this.edgeless.selectionManager.elements.includes(this.model)
);
Expand Down Expand Up @@ -181,12 +179,9 @@ export class EdgelessBlockPortalNote extends EdgelessPortalBase<NoteBlockModel>
override render() {
const { model, surface, index } = this;
const { xywh, background, hidden, edgeless } = model;
const borderRadius = edgeless ? edgeless.style.borderRadius : 8;
const borderSize = edgeless ? edgeless.style.borderSize : 4;
const borderStyle = edgeless ? edgeless.style.borderStyle : 'solid';
const shadowType = edgeless ? edgeless.style.shadowType : 'none';
const collapse = edgeless ? edgeless.collapse : false;

const { borderRadius, borderSize, borderStyle, shadowType } =
edgeless.style;
const { collapse } = edgeless;
const bound = Bound.deserialize(xywh);

const style = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import { WithDisposable } from '@blocksuite/lit';
import { css, html, LitElement, nothing, type PropertyValues } from 'lit';
import { customElement, property, query, state } from 'lit/decorators.js';

import { DEFAULT_EDGELESS_PROP } from '../../../../_common/edgeless/note/consts.js';
import {
ExpandIcon,
HiddenIcon,
Expand Down Expand Up @@ -217,10 +216,6 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) {

private _setShadowType(shadowType: string) {
this.notes.forEach(note => {
if (!note.edgeless) {
// FIXME: this is a temporary fix for the note without edgeless
note.edgeless = DEFAULT_EDGELESS_PROP;
}
note.edgeless.style.shadowType = shadowType;
});
}
Expand Down Expand Up @@ -251,18 +246,12 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) {

private _setStrokeWidth(borderSize: number) {
this.notes.forEach(note => {
if (!note.edgeless) {
note.edgeless = DEFAULT_EDGELESS_PROP;
}
note.edgeless.style.borderSize = borderSize;
});
}

private _setStrokeStyle(borderStyle: StrokeStyle) {
this.notes.forEach(note => {
if (!note.edgeless) {
note.edgeless = DEFAULT_EDGELESS_PROP;
}
note.edgeless.style.borderStyle = borderStyle;
});
}
Expand Down Expand Up @@ -290,24 +279,15 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) {

private _setBorderRadius = (size: number) => {
this.notes.forEach(note => {
if (!note.edgeless) {
note.edgeless = DEFAULT_EDGELESS_PROP;
}
note.edgeless.style.borderRadius = size;
});
};

private _setCollapse() {
this.notes.forEach(element => {
const { edgeless } = element;
const collapse = edgeless ? element.edgeless.collapse : false;
const collapsedHeight = edgeless ? element.edgeless.collapsedHeight : 0;
const { collapse, collapsedHeight } = element.edgeless;

const bound = Bound.deserialize(element.xywh);
if (!edgeless) {
element.edgeless = DEFAULT_EDGELESS_PROP;
}

if (collapse) {
element.edgeless.collapsedHeight = bound.h;
element.edgeless.collapse = false;
Expand Down Expand Up @@ -370,11 +350,10 @@ export class EdgelessChangeNoteButton extends WithDisposable(LitElement) {
const enableIndex =
this.surface.page.awarenessStore.getFlag('enable_note_index');
const { hidden, background, edgeless } = note;
const borderRadius = edgeless ? edgeless.style.borderRadius : 8;
const borderSize = edgeless ? edgeless.style.borderSize : 4;
const borderStyle = edgeless ? edgeless.style.borderStyle : 'solid';
const shadowType = edgeless ? edgeless.style.shadowType : 'none';
const collapse = edgeless ? edgeless.collapse : false;
const { shadowType, borderRadius, borderSize, borderStyle } =
edgeless.style;

const { collapse } = edgeless;

return html`
${enableIndex
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ export class EdgelessHoverRect extends WithDisposable(LitElement) {
this.rect.style.width = `${rect.width}px`;
this.rect.style.height = `${rect.height}px`;
this.rect.style.borderRadius = isNote
? `${(element?.edgeless?.style?.borderRadius ?? 8) * zoom}px`
? `${element.edgeless.style.borderRadius * zoom}px`
: '';
this.rect.style.backgroundColor = isNote
? 'var(--affine-hover-color)'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { css, html, LitElement, nothing } from 'lit';
import { customElement, property, state } from 'lit/decorators.js';
import { styleMap } from 'lit/directives/style-map.js';

import { DEFAULT_EDGELESS_PROP } from '../../../../_common/edgeless/note/consts.js';
import { stopPropagation } from '../../../../_common/utils/event.js';
import { pickValues } from '../../../../_common/utils/iterable.js';
import { clamp } from '../../../../_common/utils/math.js';
Expand Down Expand Up @@ -426,11 +425,6 @@ export class EdgelessSelectedRect extends WithDisposable(LitElement) {
if (isNoteBlock(element)) {
const curBound = Bound.deserialize(element.xywh);
const props: Partial<NoteBlockModel> = {};

if (!element.edgeless) {
element.edgeless = DEFAULT_EDGELESS_PROP;
}

if (curBound.h !== bound.h && !element.edgeless.collapse) {
element.edgeless.collapse = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,17 @@ export class NoteResizeObserver {
const container = blockElement?.querySelector(
'.affine-note-block-container'
);
const { edgeless } = model;
const collapse = edgeless ? edgeless.collapse : false;

const cachedElement = this._cachedElements.get(blockId);
if (cachedElement) {
if (container === cachedElement && !collapse) {
if (container === cachedElement && !model.edgeless.collapse) {
return;
}
this._observer.unobserve(cachedElement);
this._cachedElements.delete(blockId);
}

if (!container || collapse) return;
if (!container || model.edgeless.collapse) return;
this._lastRects.set(blockId, container.getBoundingClientRect());
this._observer.observe(container);
this._cachedElements.set(blockId, container);
Expand Down

1 comment on commit 90a575c

@vercel
Copy link

@vercel vercel bot commented on 90a575c Nov 27, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

blocksuite – ./packages/playground

blocksuite-five.vercel.app
blocksuite-git-master-toeverything.vercel.app
blocksuite-toeverything.vercel.app

Please sign in to comment.