-
Notifications
You must be signed in to change notification settings - Fork 201
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: 单元格渲染支持图片、视频、富文本 #3101
base: next
Are you sure you want to change the base?
feat: 单元格渲染支持图片、视频、富文本 #3101
Conversation
你好 @Alexzjt,非常感谢你的贡献. Hello, @Alexzjt, Thanks for your contribution. In order to make the code more robust, please add the corresponding unit tests, and update the docs if there are API changes. |
WalkthroughThis pull request introduces a new feature that enables cell rendering to support images, videos, and rich text. It also resolves issue #3095. The changes involve adding custom renderer configurations and handling media click interactions to provide a preview overlay for media content. Changes
|
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## next #3101 +/- ##
==========================================
+ Coverage 75.77% 79.28% +3.51%
==========================================
Files 257 213 -44
Lines 11994 11742 -252
Branches 2464 2634 +170
==========================================
+ Hits 9088 9310 +222
+ Misses 1398 851 -547
- Partials 1508 1581 +73 ☔ View full report in Codecov by Sentry. |
Size Change: +2.2 kB (+0.36%) Total Size: 621 kB
ℹ️ View Unchanged
|
@@ -0,0 +1,5 @@ | |||
export enum RendererType { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
风格保持一致,枚举的 key 大写
export enum RendererType { | |
export enum CellRendererType { | |
HTML = 'html' | |
} |
@@ -485,6 +486,14 @@ export abstract class BaseCell<T extends SimpleBBox> extends Group { | |||
} | |||
|
|||
public drawTextShape() { | |||
const renderer = this.getRenderer(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
加在这里虽然改动最小,但是和函数名做的事情不符了
另外 facet 在预测量文本宽度也会调用
S2/packages/s2-core/src/facet/base-facet.ts
Lines 527 to 529 in a68f134
// 预生成 icon 配置, 用于计算文本正确的最大可用宽度 | |
(cell as HeaderCell).generateIconConfig?.(); | |
cell.drawTextShape(); |
)?.renderer; | ||
} | ||
|
||
public abstract getMetaField(): string; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
abstract 写在 class 的最上面
S2/packages/s2-core/src/cell/base-cell.ts
Lines 159 to 170 in a68f134
protected abstract mappingValue<Result>( | |
condition: Condition<Result>, | |
): ConditionMappingResult<Result>; | |
protected abstract getBackgroundColor(): { | |
backgroundColor: string | undefined; | |
backgroundColorOpacity: number | undefined; | |
intelligentReverseTextColor: boolean; | |
}; | |
public constructor( | |
meta: T, |
@@ -16,6 +16,7 @@ import type { Node } from '../../facet/layout/node'; | |||
import type { SpreadSheet } from '../../sheet-type'; | |||
import type { CellType } from '../constant'; | |||
import type { S2CellType } from './interaction'; | |||
import { CustomRendererConfig } from './renderer'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
按理说 lint 会提示吧
import { CustomRendererConfig } from './renderer'; | |
import type { CustomRendererConfig } from './renderer'; |
overlayStyle?: CSSStyleDeclaration; | ||
mediaContainerStyle?: CSSStyleDeclaration; | ||
} | ||
| false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
boolean ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
关闭点击预览就是配false。不配置默认有这个功能,或者配样式。不太可能会配个true
} | ||
|
||
// 图片渲染配置 | ||
export interface ImageRendererConfig extends BaseRendererConfig { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
用范型是不是要好点
export interface ImageRendererConfig extends BaseRendererConfig { | |
export interface ImageRendererConfig extends BaseRendererConfig<RendererType.image> { | |
config?: Partial<ImageStyleProps>; | |
} |
@@ -43,6 +44,12 @@ export class DataCellClick extends BaseEvent implements BaseEventImplement { | |||
const cell = this.spreadsheet.getCell<DataCell>(event.target)!; | |||
const meta = cell.getMeta(); | |||
|
|||
if (cell.getRenderer?.()?.type) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
交互建议相互独立
可以抽一个 media-cell-click 的 class 来专门处理 header/data cell 的点击
@@ -19,6 +21,14 @@ export class HeaderCellLinkClick | |||
return; | |||
} | |||
|
|||
const cell = this.spreadsheet.getCell<HeaderCell>(event.target); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
同上
const overlay = document.createElement('div'); | ||
|
||
Object.assign(overlay.style, { | ||
width: '100vw', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
层级,背景色之类的,建议做到主题里面
}); | ||
} | ||
|
||
export async function drawCustomRenderer( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
注意下滚动坐标同步/拖拽宽高同步/滚动卸载 等场景
👀 PR includes
✨ Feature
🎨 Enhance
🐛 Bugfix
🔧 Chore
📝 Description
🖼️ Screenshot
🔗 Related issue link
🔍 Self-Check before the merge