Skip to content

Commit d5a8d72

Browse files
authored
chore: sync affine blocksuite to packages (#9138)
Co-authored-by: Saul-Mirone <10047788+Saul-Mirone@users.noreply.github.com>
1 parent 79ea09e commit d5a8d72

File tree

37 files changed

+869
-354
lines changed

37 files changed

+869
-354
lines changed

packages/affine/blocks/attachment/src/attachment-block.ts

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
AttachmentBlockStyles,
1818
} from '@blocksuite/affine-model';
1919
import {
20+
CitationProvider,
2021
DocModeProvider,
2122
FileSizeLimitProvider,
2223
TelemetryProvider,
@@ -37,6 +38,7 @@ import { type ClassInfo, classMap } from 'lit/directives/class-map.js';
3738
import { guard } from 'lit/directives/guard.js';
3839
import { styleMap } from 'lit/directives/style-map.js';
3940
import { when } from 'lit/directives/when.js';
41+
import { filter } from 'rxjs/operators';
4042

4143
import { AttachmentEmbedProvider } from './embed';
4244
import { styles } from './styles';
@@ -79,8 +81,12 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
7981
return this.std.get(FileSizeLimitProvider).maxFileSize;
8082
}
8183

84+
get citationService() {
85+
return this.std.get(CitationProvider);
86+
}
87+
8288
get isCitation() {
83-
return !!this.model.props.footnoteIdentifier;
89+
return this.citationService.isCitationModel(this.model);
8490
}
8591

8692
convertTo = () => {
@@ -139,6 +145,34 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
139145
selectionManager.setGroup('note', [blockSelection]);
140146
}
141147

148+
private readonly _trackCitationDeleteEvent = () => {
149+
// Check citation delete event
150+
this._disposables.add(
151+
this.std.store.slots.blockUpdated
152+
.pipe(
153+
filter(payload => {
154+
if (!payload.isLocal) return false;
155+
156+
const { flavour, id, type } = payload;
157+
if (
158+
type !== 'delete' ||
159+
flavour !== this.model.flavour ||
160+
id !== this.model.id
161+
)
162+
return false;
163+
164+
const { model } = payload;
165+
if (!this.citationService.isCitationModel(model)) return false;
166+
167+
return true;
168+
})
169+
)
170+
.subscribe(() => {
171+
this.citationService.trackEvent('Delete');
172+
})
173+
);
174+
};
175+
142176
override connectedCallback() {
143177
super.connectedCallback();
144178

@@ -162,6 +196,8 @@ export class AttachmentBlockComponent extends CaptionedBlockComponent<Attachment
162196
});
163197
});
164198
}
199+
200+
this._trackCitationDeleteEvent();
165201
}
166202

167203
override firstUpdated() {

packages/affine/blocks/attachment/src/components/rename-model.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { ConfirmIcon } from '@blocksuite/affine-components/icons';
22
import { toast } from '@blocksuite/affine-components/toast';
33
import type { AttachmentBlockModel } from '@blocksuite/affine-model';
4+
import { CitationProvider } from '@blocksuite/affine-shared/services';
45
import type { EditorHost } from '@blocksuite/std';
56
import { html } from 'lit';
67
import { createRef, ref } from 'lit/directives/ref.js';
@@ -33,6 +34,7 @@ export const RenameModal = ({
3334

3435
let fileName = includeExtension ? nameWithoutExtension : originalName;
3536
const extension = includeExtension ? originalExtension : '';
37+
const citationService = editorHost.std.get(CitationProvider);
3638

3739
const abort = () => abortController.abort();
3840
const onConfirm = () => {
@@ -44,6 +46,9 @@ export const RenameModal = ({
4446
model.store.updateBlock(model, {
4547
name: newFileName,
4648
});
49+
if (citationService.isCitationModel(model)) {
50+
citationService.trackEvent('Edit');
51+
}
4752
abort();
4853
};
4954
const onInput = (e: InputEvent) => {

packages/affine/blocks/bookmark/src/bookmark-block.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import type {
88
} from '@blocksuite/affine-model';
99
import { ImageProxyService } from '@blocksuite/affine-shared/adapters';
1010
import {
11+
CitationProvider,
1112
DocModeProvider,
1213
LinkPreviewServiceIdentifier,
1314
} from '@blocksuite/affine-shared/services';
@@ -18,6 +19,7 @@ import { html } from 'lit';
1819
import { property, query } from 'lit/decorators.js';
1920
import { type ClassInfo, classMap } from 'lit/directives/class-map.js';
2021
import { type StyleInfo, styleMap } from 'lit/directives/style-map.js';
22+
import { filter } from 'rxjs/operators';
2123

2224
import { refreshBookmarkUrlData } from './utils.js';
2325

@@ -114,11 +116,12 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
114116
);
115117
};
116118

119+
get citationService() {
120+
return this.std.get(CitationProvider);
121+
}
122+
117123
get isCitation() {
118-
return (
119-
!!this.model.props.footnoteIdentifier &&
120-
this.model.props.style === 'citation'
121-
);
124+
return this.citationService.isCitationModel(this.model);
122125
}
123126

124127
get imageProxyService() {
@@ -166,6 +169,31 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
166169
></bookmark-card>`;
167170
};
168171

172+
private readonly _trackCitationDeleteEvent = () => {
173+
// Check citation delete event
174+
this._disposables.add(
175+
this.std.store.slots.blockUpdated
176+
.pipe(
177+
filter(payload => {
178+
if (!payload.isLocal) return false;
179+
const { flavour, id, type } = payload;
180+
if (
181+
type !== 'delete' ||
182+
flavour !== this.model.flavour ||
183+
id !== this.model.id
184+
)
185+
return false;
186+
const { model } = payload;
187+
if (!this.citationService.isCitationModel(model)) return false;
188+
return true;
189+
})
190+
)
191+
.subscribe(() => {
192+
this.citationService.trackEvent('Delete');
193+
})
194+
);
195+
};
196+
169197
override connectedCallback() {
170198
super.connectedCallback();
171199

@@ -203,6 +231,8 @@ export class BookmarkBlockComponent extends CaptionedBlockComponent<BookmarkBloc
203231
}
204232
})
205233
);
234+
235+
this._trackCitationDeleteEvent();
206236
}
207237

208238
override disconnectedCallback(): void {

packages/affine/blocks/code/src/code-block.ts

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,16 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
4040

4141
private _inlineRangeProvider: InlineRangeProvider | null = null;
4242

43+
private readonly _localPreview$ = signal<boolean | null>(null);
44+
45+
preview$: Signal<boolean> = computed(() => {
46+
const modelPreview = !!this.model.props.preview$.value;
47+
if (this.store.readonly) {
48+
return this._localPreview$.value ?? modelPreview;
49+
}
50+
return modelPreview;
51+
});
52+
4353
highlightTokens$: Signal<ThemedToken[][]> = signal([]);
4454

4555
languageName$: Signal<string> = computed(() => {
@@ -393,7 +403,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
393403
true) &&
394404
(this.model.props.lineNumber ?? true);
395405

396-
const preview = !!this.model.props.preview;
406+
const preview = this.preview$.value;
397407
const previewContext = this.std.getOptional(
398408
CodeBlockPreviewIdentifier(this.model.props.language ?? '')
399409
);
@@ -461,6 +471,14 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
461471
override accessor useCaptionEditor = true;
462472

463473
override accessor useZeroWidth = true;
474+
475+
setPreviewState(preview: boolean) {
476+
if (this.store.readonly) {
477+
this._localPreview$.value = preview;
478+
} else {
479+
this.store.updateBlock(this.model, { preview });
480+
}
481+
}
464482
}
465483

466484
declare global {

packages/affine/blocks/code/src/code-toolbar/components/preview-button.ts

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,7 @@ export class PreviewButton extends WithDisposable(SignalWatcher(LitElement)) {
5858
`;
5959

6060
private readonly _toggle = (value: boolean) => {
61-
if (this.blockComponent.store.readonly) return;
62-
63-
this.blockComponent.store.updateBlock(this.blockComponent.model, {
64-
preview: value,
65-
});
61+
this.blockComponent.setPreviewState(value);
6662

6763
const std = this.blockComponent.std;
6864
const mode = std.getOptional(DocModeProvider)?.getEditorMode() ?? 'page';
@@ -77,7 +73,7 @@ export class PreviewButton extends WithDisposable(SignalWatcher(LitElement)) {
7773
};
7874

7975
get preview() {
80-
return !!this.blockComponent.model.props.preview$.value;
76+
return this.blockComponent.preview$.value;
8177
}
8278

8379
override render() {

packages/affine/blocks/embed-doc/src/embed-linked-doc-block/embed-linked-doc-block.ts

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import {
1717
REFERENCE_NODE,
1818
} from '@blocksuite/affine-shared/consts';
1919
import {
20+
CitationProvider,
2021
DocDisplayMetaProvider,
2122
DocModeProvider,
2223
OpenDocExtensionIdentifier,
@@ -43,6 +44,7 @@ import { repeat } from 'lit/directives/repeat.js';
4344
import { styleMap } from 'lit/directives/style-map.js';
4445
import { when } from 'lit/directives/when.js';
4546
import throttle from 'lodash-es/throttle';
47+
import { filter } from 'rxjs/operators';
4648
import * as Y from 'yjs';
4749

4850
import { renderLinkedDocInCard } from '../common/render-linked-doc';
@@ -254,11 +256,12 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
254256
return this.store.readonly;
255257
}
256258

259+
get citationService() {
260+
return this.std.get(CitationProvider);
261+
}
262+
257263
get isCitation() {
258-
return (
259-
!!this.model.props.footnoteIdentifier &&
260-
this.model.props.style === 'citation'
261-
);
264+
return this.citationService.isCitationModel(this.model);
262265
}
263266

264267
private readonly _handleDoubleClick = (event: MouseEvent) => {
@@ -454,6 +457,31 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
454457
);
455458
};
456459

460+
private readonly _trackCitationDeleteEvent = () => {
461+
// Check citation delete event
462+
this._disposables.add(
463+
this.std.store.slots.blockUpdated
464+
.pipe(
465+
filter(payload => {
466+
if (!payload.isLocal) return false;
467+
const { flavour, id, type } = payload;
468+
if (
469+
type !== 'delete' ||
470+
flavour !== this.model.flavour ||
471+
id !== this.model.id
472+
)
473+
return false;
474+
const { model } = payload;
475+
if (!this.citationService.isCitationModel(model)) return false;
476+
return true;
477+
})
478+
)
479+
.subscribe(() => {
480+
this.citationService.trackEvent('Delete');
481+
})
482+
);
483+
};
484+
457485
override connectedCallback() {
458486
super.connectedCallback();
459487

@@ -532,6 +560,8 @@ export class EmbedLinkedDocBlockComponent extends EmbedBlockComponent<EmbedLinke
532560
}
533561
})
534562
);
563+
564+
this._trackCitationDeleteEvent();
535565
}
536566

537567
getInitialState(): {

packages/affine/blocks/embed/src/embed-html-block/components/fullscreen-toolbar.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -107,10 +107,10 @@ export class EmbedHtmlFullscreenToolbar extends LitElement {
107107
if (this._copied) return;
108108

109109
this.embedHtml.std.clipboard
110-
.writeToClipboard(items => {
111-
items['text/plain'] = this.embedHtml.model.props.html ?? '';
112-
return items;
113-
})
110+
.writeToClipboard(items => ({
111+
...items,
112+
'text/plain': this.embedHtml.model.props.html ?? '',
113+
}))
114114
.then(() => {
115115
this._copied = true;
116116
setTimeout(() => (this._copied = false), 1500);

packages/affine/blocks/frame/src/frame-block.ts

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
import { cssVarV2 } from '@toeverything/theme/v2';
1717
import { html } from 'lit';
1818
import { state } from 'lit/decorators.js';
19+
import { repeat } from 'lit/directives/repeat.js';
1920
import { styleMap } from 'lit/directives/style-map.js';
2021

2122
import {
@@ -87,6 +88,12 @@ export class FrameBlockComponent extends GfxBlockComponent<FrameBlockModel> {
8788
this.gfx.tool.currentToolName$.value === 'frameNavigator';
8889
const frameIndex = this.gfx.layer.getZIndex(model);
8990

91+
const widgets = html`${repeat(
92+
Object.entries(this.widgets),
93+
([id]) => id,
94+
([_, widget]) => widget
95+
)}`;
96+
9097
return html`
9198
<div
9299
class="affine-frame-container"
@@ -102,6 +109,7 @@ export class FrameBlockComponent extends GfxBlockComponent<FrameBlockModel> {
102109
: `1px solid ${cssVarV2('edgeless/frame/border/default')}`,
103110
})}
104111
></div>
112+
${widgets}
105113
`;
106114
}
107115

@@ -178,11 +186,22 @@ export const FrameBlockInteraction =
178186
selectable(context) {
179187
const { model } = context;
180188

189+
const onTitle =
190+
model.externalBound?.containsPoint([
191+
context.position.x,
192+
context.position.y,
193+
]) ?? false;
194+
181195
return (
182196
context.default(context) &&
183-
(model.isLocked() || !isTransparent(model.props.background))
197+
(model.isLocked() ||
198+
!isTransparent(model.props.background) ||
199+
onTitle)
184200
);
185201
},
202+
onSelect(context) {
203+
return context.default(context);
204+
},
186205
};
187206
},
188207
}

0 commit comments

Comments
 (0)