Skip to content
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

fix: float dom event #4514

Merged
merged 5 commits into from
Jan 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions packages-experimental/debugger/src/components/float-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,51 @@ export const FloatButton = () => {
</div>
);
};

export const AIButton = () => {
const divStyle = {
width: '80px',
height: '50px',
backgroundColor: '#fff',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
textAlign: 'center' as const,
borderRadius: '25px',
border: 'none',
color: 'white',
cursor: 'pointer',
transition: 'all 0.3s ease',

background: 'linear-gradient(90deg, #00C9FF 0%, #92FE9D 50%, #00C9FF 100%)',
backgroundSize: '200% auto',
animation: 'gradient 3s linear infinite',

':hover': {
transform: 'translateY(-2px)',
boxShadow: '0 10px 20px rgba(0, 201, 255, 0.3)',
},
};
const clickHandler = () => {
console.warn('click');
};
return (
<button type="button" style={divStyle} onClick={clickHandler}>
AI
<style>
{`
@keyframes gradient {
0% { background-position: 0% 50%; }
50% { background-position: 100% 50%; }
100% { background-position: 0% 50%; }
}

button:hover {
transform: translateY(-2px);
box-shadow: 0 10px 20px rgba(0, 201, 255, 0.3);
}
`}
</style>
</button>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ import { SidebarOperation } from '../commands/operations/sidebar.operation';

import { ThemeOperation } from '../commands/operations/theme.operation';

import { AIButton, FloatButton } from '../components/float-button';
import { ImageDemo } from '../components/Image';
import { RangeLoading } from '../components/range-loading';
import { FloatButton } from '../components/float-button';
// @ts-ignore
import VueI18nIcon from '../components/VueI18nIcon.vue';
// import { TEST_EDITOR_CONTAINER_COMPONENT } from '../views/test-editor/component-name';
Expand Down Expand Up @@ -92,5 +92,6 @@ export class DebuggerController extends Disposable {
this.disposeWithMe(componentManager.register('ImageDemo', ImageDemo));
this.disposeWithMe(componentManager.register('RangeLoading', RangeLoading));
this.disposeWithMe(componentManager.register('FloatButton', FloatButton));
this.disposeWithMe(componentManager.register('AIButton', AIButton));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { IScale } from '@univerjs/core';
import type { UniverRenderingContext } from '../../../context';

import type { IAColumnCfg, IAColumnCfgObj, IColumnStyleCfg } from '../interfaces';
import type { IAColumnCfg, IAColumnCfgObj, IHeaderStyleCfg } from '../interfaces';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import { numberToABC } from '@univerjs/core';
import { DEFAULT_FONTFACE_PLANE, FIX_ONE_PIXEL_BLUR_OFFSET, MIDDLE_CELL_POS_MAGIC_NUMBER } from '../../../basics/const';
Expand All @@ -27,7 +27,7 @@ import { SheetExtension } from './sheet-extension';

const UNIQUE_KEY = 'DefaultColumnHeaderLayoutExtension';
export interface IColumnsHeaderCfgParam {
headerStyle?: Partial<IColumnStyleCfg>;
headerStyle?: Partial<IHeaderStyleCfg>;
columnsCfg?: IAColumnCfg[];
}
const DEFAULT_COLUMN_STYLE = {
Expand All @@ -47,7 +47,7 @@ export class ColumnHeaderLayout extends SheetExtension {
override uKey = UNIQUE_KEY;
override Z_INDEX = 10;
columnsCfg: IAColumnCfg[] = [];
headerStyle: IColumnStyleCfg = {
headerStyle: IHeaderStyleCfg = {
fontSize: DEFAULT_COLUMN_STYLE.fontSize,
fontFamily: DEFAULT_COLUMN_STYLE.fontFamily,
fontColor: DEFAULT_COLUMN_STYLE.fontColor,
Expand Down Expand Up @@ -78,7 +78,7 @@ export class ColumnHeaderLayout extends SheetExtension {
if (typeof columnsCfg[colIndex] == 'string') {
columnsCfg[colIndex] = { text: columnsCfg[colIndex] } as IAColumnCfgObj;
}
curColSpecCfg = columnsCfg[colIndex] as IColumnStyleCfg & { text: string };
curColSpecCfg = columnsCfg[colIndex] as IHeaderStyleCfg & { text: string };
mergeWithSpecCfg = { ...this.headerStyle, ...curColSpecCfg };
} else {
mergeWithSpecCfg = { ...this.headerStyle, text: numberToABC(colIndex) };
Expand All @@ -87,7 +87,7 @@ export class ColumnHeaderLayout extends SheetExtension {
return [mergeWithSpecCfg, specStyle] as [IAColumnCfgObj, boolean];
}

setStyleToCtx(ctx: UniverRenderingContext, columnStyle: Partial<IColumnStyleCfg>): void {
setStyleToCtx(ctx: UniverRenderingContext, columnStyle: Partial<IHeaderStyleCfg>): void {
if (columnStyle.textAlign) ctx.textAlign = columnStyle.textAlign;
if (columnStyle.textBaseline) ctx.textBaseline = columnStyle.textBaseline;
if (columnStyle.fontColor) ctx.fillStyle = columnStyle.fontColor;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import type { IScale } from '@univerjs/core';

import type { UniverRenderingContext } from '../../../context';
import type { IARowCfg, IARowCfgObj, IColumnStyleCfg, IRowStyleCfg } from '../interfaces';
import type { IARowCfg, IARowCfgObj, IHeaderStyleCfg, IRowStyleCfg } from '../interfaces';
import type { SpreadsheetSkeleton } from '../sheet-skeleton';
import { DEFAULT_FONTFACE_PLANE, FIX_ONE_PIXEL_BLUR_OFFSET, MIDDLE_CELL_POS_MAGIC_NUMBER } from '../../../basics/const';
import { getColor } from '../../../basics/tools';
Expand Down Expand Up @@ -85,7 +85,7 @@ export class RowHeaderLayout extends SheetExtension {
return [mergeWithSpecCfg, specStyle] as [IARowCfgObj, boolean];
}

setStyleToCtx(ctx: UniverRenderingContext, rowStyle: Partial<IColumnStyleCfg>) {
setStyleToCtx(ctx: UniverRenderingContext, rowStyle: Partial<IHeaderStyleCfg>) {
if (rowStyle.textAlign) ctx.textAlign = rowStyle.textAlign;
if (rowStyle.textBaseline) ctx.textBaseline = rowStyle.textBaseline;
if (rowStyle.fontColor) ctx.fillStyle = rowStyle.fontColor;
Expand Down
6 changes: 3 additions & 3 deletions packages/engine-render/src/components/sheets/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export interface IPaintForScrolling {
scaleX: number;
scaleY: number;
}
export interface IColumnStyleCfg {
export interface IHeaderStyleCfg {
fontFamily: string;
fontColor: string;
fontSize: number;
Expand All @@ -115,7 +115,7 @@ export interface IColumnStyleCfg {
backgroundColor: string;
}

export type IAColumnCfgObj = IColumnStyleCfg & { text: string };
export type IAColumnCfgObj = IHeaderStyleCfg & { text: string; headerHeight: number };
export type IAColumnCfg = undefined | null | string | Partial<IAColumnCfgObj>;

export interface IRowStyleCfg {
Expand All @@ -128,5 +128,5 @@ export interface IRowStyleCfg {
backgroundColor: string;
}

export type IARowCfgObj = IColumnStyleCfg & { text: string };
export type IARowCfgObj = IHeaderStyleCfg & { text: string };
export type IARowCfg = undefined | null | string | Partial<IARowCfgObj>;
15 changes: 6 additions & 9 deletions packages/sheets-drawing-ui/src/facade/f-worksheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,7 @@ export interface IFWorksheetLegacy {
// another example-------------------
{
const sheet = univerAPI.getActiveWorkbook().getActiveSheet();
// const range = sheet.getRange(0, 0, 3, 3);
// univerAPI.getActiveWorkbook().setActiveRange(range);
univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange()
const range = univerAPI.getActiveWorkbook().getActiveSheet().getActiveRange()
const {id, dispose } = sheet.addFloatDomToRange(range, {
allowTransform: false,
componentKey: 'FloatButton', // React comp key registered in ComponentManager
Expand All @@ -102,10 +100,12 @@ export interface IFWorksheetLegacy {
}, {
width: 100,
height: 30,
x: '100%',
y: '100%'},
marginX: '100%', // margin percent to range width, or pixel
marginY: '100%'
},
'AIButton') // dom id
}

* ```
*/
addFloatDomToRange(range: FRange, layer: IFICanvasFloatDom, domLayout: IDOMRangeLayout, id?: string): Nullable<{
Expand All @@ -130,11 +130,8 @@ export interface IFWorksheetLegacy {
props: {
a: 1,
},
data: {
aa: '128',
},
},
{width: 100, height: 40, x: 0, y: 0},
{width: 100, height: 40, marginX: 0, marginY: 0, horizonOffsetAlign: 'right'},
'ai-selector' // dom id
)
}
Expand Down
Loading
Loading