mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 02:56:23 +08:00
388641bc89
<!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **Refactor** - Unified internal data access by replacing all references from `doc` to `store` across all components, blocks, widgets, and utilities. This affects how readonly state, block operations, and service retrieval are handled throughout the application. - **Tests** - Updated all test utilities and test cases to use `store` instead of `doc` for document-related operations. - **Chores** - Updated context providers and property names to reflect the change from `doc` to `store` for improved consistency and maintainability. No user-facing features or behaviors have changed. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
60 lines
1.6 KiB
TypeScript
60 lines
1.6 KiB
TypeScript
import { stopPropagation } from '@blocksuite/affine-shared/utils';
|
|
import { type BlockComponent, TextSelection } from '@blocksuite/std';
|
|
import { css, html, LitElement } from 'lit';
|
|
import { property } from 'lit/decorators.js';
|
|
|
|
export class BlockZeroWidth extends LitElement {
|
|
static override styles = css`
|
|
.block-zero-width {
|
|
position: absolute;
|
|
bottom: -15px;
|
|
height: 10px;
|
|
width: 100%;
|
|
cursor: text;
|
|
z-index: 1;
|
|
}
|
|
`;
|
|
|
|
_handleClick = (e: MouseEvent) => {
|
|
stopPropagation(e);
|
|
if (this.block.store.readonly) return;
|
|
const nextBlock = this.block.store.getNext(this.block.model);
|
|
if (nextBlock?.flavour !== 'affine:paragraph') {
|
|
const [paragraphId] = this.block.store.addSiblingBlocks(
|
|
this.block.model,
|
|
[{ flavour: 'affine:paragraph' }]
|
|
);
|
|
const std = this.block.std;
|
|
std.selection.setGroup('note', [
|
|
std.selection.create(TextSelection, {
|
|
from: { blockId: paragraphId, index: 0, length: 0 },
|
|
to: null,
|
|
}),
|
|
]);
|
|
}
|
|
};
|
|
|
|
override connectedCallback(): void {
|
|
super.connectedCallback();
|
|
this.addEventListener('click', this._handleClick);
|
|
}
|
|
|
|
override disconnectedCallback(): void {
|
|
this.removeEventListener('click', this._handleClick);
|
|
super.disconnectedCallback();
|
|
}
|
|
|
|
override render() {
|
|
return html`<div class="block-zero-width"></div>`;
|
|
}
|
|
|
|
@property({ attribute: false })
|
|
accessor block!: BlockComponent;
|
|
}
|
|
|
|
declare global {
|
|
interface HTMLElementTagNameMap {
|
|
'block-zero-width': BlockZeroWidth;
|
|
}
|
|
}
|