Files
AFFiNE-Mirror/blocksuite/affine/data-view/src/property-presets/text/cell-renderer.ts
T
zzj3720 7b6e00d84a refactor(editor): replace @vanilla-extract/css with @emotion/css (#12195)
close: BS-3446

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit

- **Refactor**
  - Migrated all styling from vanilla-extract to Emotion for improved CSS-in-JS consistency across database, table, and data view components.
  - Updated import paths for style modules to reflect the new Emotion-based file naming.
  - Removed unused or redundant style exports and updated selector syntax where necessary.

- **Chores**
  - Updated dependencies: removed vanilla-extract and added Emotion in relevant package files.

- **Style**
  - No visual changes to existing components; all style definitions remain consistent with previous designs.

- **New Features**
  - Introduced new reusable CSS classes for data view and table components using Emotion.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2025-05-09 10:08:03 +00:00

66 lines
1.7 KiB
TypeScript

import { html } from 'lit';
import { query } from 'lit/decorators.js';
import { BaseCellRenderer } from '../../core/property/index.js';
import { createFromBaseCellRenderer } from '../../core/property/renderer.js';
import { createIcon } from '../../core/utils/uni-icon.js';
import { textInputStyle, textStyle } from './cell-renderer-css.js';
import { textPropertyModelConfig } from './define.js';
export class TextCell extends BaseCellRenderer<string, string> {
@query('input')
private accessor _inputEle!: HTMLInputElement;
private readonly _keydown = (e: KeyboardEvent) => {
if (e.key === 'Enter' && !e.isComposing) {
this._setValue();
setTimeout(() => {
this.selectCurrentCell(false);
});
}
};
private readonly _setValue = (str: string = this._inputEle?.value) => {
if (this._inputEle) {
this._inputEle.value = `${this.value ?? ''}`;
}
this.valueSetNextTick(str);
};
focusEnd = () => {
if (!this._inputEle) return;
const end = this._inputEle.value.length;
this._inputEle.focus();
this._inputEle.setSelectionRange(end, end);
};
override afterEnterEditingMode() {
this.focusEnd();
}
override beforeExitEditingMode() {
this._setValue();
}
override render() {
if (this.isEditing$.value) {
return html`<input
.value="${this.value ?? ''}"
@keydown="${this._keydown}"
class="${textInputStyle}"
/>`;
} else {
return html`<div class="${textStyle}">${this.value ?? ''}</div>`;
}
}
}
export const textPropertyConfig = textPropertyModelConfig.createPropertyMeta({
icon: createIcon('TextIcon'),
cellRenderer: {
view: createFromBaseCellRenderer(TextCell),
},
});