mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-08-18 10:31:50 +08:00
7b6e00d84a
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 -->
66 lines
1.7 KiB
TypeScript
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),
|
|
},
|
|
});
|