refactor(editor): unify directories naming (#11516)

**Directory Structure Changes**

- Renamed multiple block-related directories by removing the "block-" prefix:
  - `block-attachment` → `attachment`
  - `block-bookmark` → `bookmark`
  - `block-callout` → `callout`
  - `block-code` → `code`
  - `block-data-view` → `data-view`
  - `block-database` → `database`
  - `block-divider` → `divider`
  - `block-edgeless-text` → `edgeless-text`
  - `block-embed` → `embed`
This commit is contained in:
Saul-Mirone
2025-04-07 12:34:40 +00:00
parent e1bd2047c4
commit 1f45cc5dec
893 changed files with 439 additions and 460 deletions
@@ -0,0 +1,69 @@
import { createModal } from '@blocksuite/affine-components/context-menu';
import { CloseIcon } from '@blocksuite/icons/lit';
import { ShadowlessElement } from '@blocksuite/std';
import { css, html, type TemplateResult } from 'lit';
import { property } from 'lit/decorators.js';
export class CenterPeek extends ShadowlessElement {
static override styles = css`
center-peek {
flex-direction: column;
position: absolute;
top: 5%;
left: 5%;
width: 90%;
height: 90%;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.05);
border-radius: 12px;
}
.side-modal-content {
flex: 1;
overflow-y: auto;
}
.close-modal:hover {
background-color: var(--affine-hover-color);
}
.close-modal {
position: absolute;
right: -32px;
top: 0;
width: 24px;
height: 24px;
border-radius: 4px;
display: flex;
align-items: center;
justify-content: center;
cursor: pointer;
}
`;
override render() {
return html`
<div @click="${this.close}" class="close-modal">${CloseIcon()}</div>
${this.content}
`;
}
@property({ attribute: false })
accessor close: (() => void) | undefined = undefined;
@property({ attribute: false })
accessor content: TemplateResult | undefined = undefined;
}
export const popSideDetail = (template: TemplateResult) => {
return new Promise<void>(res => {
const modal = createModal(document.body);
const close = () => {
modal.remove();
res();
};
const sideContainer = new CenterPeek();
sideContainer.content = template;
sideContainer.close = close;
modal.onclick = e => e.target === modal && close();
modal.append(sideContainer);
});
};
@@ -0,0 +1,185 @@
import { stopPropagation } from '@blocksuite/affine-shared/utils';
import { WithDisposable } from '@blocksuite/global/lit';
import { ShadowlessElement } from '@blocksuite/std';
import type { Text } from '@blocksuite/store';
import { css, html } from 'lit';
import { property, query, state } from 'lit/decorators.js';
import { classMap } from 'lit/directives/class-map.js';
import { styleMap } from 'lit/directives/style-map.js';
import type { DatabaseBlockComponent } from '../../database-block.js';
export class DatabaseTitle extends WithDisposable(ShadowlessElement) {
static override styles = css`
.affine-database-title {
position: relative;
flex: 1;
font-family: inherit;
font-size: 20px;
line-height: 28px;
font-weight: 600;
color: var(--affine-text-primary-color);
overflow: hidden;
}
.affine-database-title textarea {
font-size: inherit;
line-height: inherit;
font-weight: inherit;
letter-spacing: inherit;
font-family: inherit;
border: none;
background-color: transparent;
padding: 0;
position: absolute;
left: 0;
top: 0;
bottom: 0;
right: 0;
outline: none;
resize: none;
scrollbar-width: none;
}
.affine-database-title .text {
user-select: none;
opacity: 0;
white-space: pre-wrap;
}
.affine-database-title[data-title-focus='false'] textarea {
opacity: 0;
}
.affine-database-title[data-title-focus='false'] .text {
text-overflow: ellipsis;
overflow: hidden;
opacity: 1;
white-space: pre;
}
.affine-database-title [data-title-empty='true']::before {
content: 'Untitled';
position: absolute;
pointer-events: none;
color: var(--affine-text-primary-color);
}
.affine-database-title [data-title-focus='true']::before {
color: var(--affine-placeholder-color);
}
`;
private readonly compositionEnd = () => {
this.titleText.replace(0, this.titleText.length, this.input.value);
};
private readonly onBlur = () => {
this.isFocus = false;
};
private readonly onFocus = () => {
this.isFocus = true;
if (this.database?.viewSelection$?.value) {
this.database?.setSelection(undefined);
}
};
private readonly onInput = (e: InputEvent) => {
this.text = this.input.value;
if (!e.isComposing) {
this.titleText.replace(0, this.titleText.length, this.input.value);
}
};
private readonly onKeyDown = (event: KeyboardEvent) => {
event.stopPropagation();
if (event.key === 'Enter' && !event.isComposing) {
event.preventDefault();
this.onPressEnterKey?.();
return;
}
};
updateText = () => {
if (!this.isFocus) {
this.input.value = this.titleText.toString();
this.text = this.input.value;
}
};
get database() {
return this.closest<DatabaseBlockComponent>('affine-database');
}
override connectedCallback() {
super.connectedCallback();
requestAnimationFrame(() => {
this.updateText();
});
this.titleText.yText.observe(this.updateText);
this.disposables.add(() => {
this.titleText.yText.unobserve(this.updateText);
});
}
override render() {
const isEmpty = !this.text;
const classList = classMap({
'affine-database-title': true,
ellipsis: !this.isFocus,
});
const untitledStyle = styleMap({
height: isEmpty ? 'auto' : 0,
opacity: isEmpty && !this.isFocus ? 1 : 0,
});
return html` <div
class="${classList}"
data-title-empty="${isEmpty}"
data-title-focus="${this.isFocus}"
>
<div class="text" style="${untitledStyle}">Untitled</div>
<div class="text">${this.text}</div>
<textarea
.disabled="${this.readonly}"
@input="${this.onInput}"
@keydown="${this.onKeyDown}"
@copy="${stopPropagation}"
@paste="${stopPropagation}"
@focus="${this.onFocus}"
@blur="${this.onBlur}"
@compositionend="${this.compositionEnd}"
data-block-is-database-title="true"
title="${this.titleText.toString()}"
></textarea>
</div>`;
}
@query('textarea')
private accessor input!: HTMLTextAreaElement;
@state()
accessor isComposing = false;
@state()
private accessor isFocus = false;
@property({ attribute: false })
accessor onPressEnterKey: (() => void) | undefined = undefined;
@property({ attribute: false })
accessor readonly!: boolean;
@state()
private accessor text = '';
@property({ attribute: false })
accessor titleText!: Text;
}
declare global {
interface HTMLElementTagNameMap {
'affine-database-title': DatabaseTitle;
}
}