import { MouseMovePayload } from 'shimo-js-sdk-shared'; import { BaseEditor, EventMap as BaseEventMap } from './BaseEditor'; /** 表格范围 */ export interface Range { row: number; column: number; rowCount: number; columnCount: number; } /** * 锁定权限等级 * 0 - 可编辑 * 1 - 只能查看 * 2 - 禁止查看 */ export type PermissionLevel = 0 | 1 | 2; /** 用户ID对应的权限等级 */ export interface UserPermission { [userId: number]: PermissionLevel; } /** 部门ID对应的权限等级 */ export interface DepartmentPermission { [departmentId: number]: PermissionLevel; } export interface EventMap extends BaseEventMap { error: { /** 错误信息 */ data?: any; /** 错误码 */ code: number; }; /** * 鼠标移动事件 */ MouseMove: MouseMovePayload; /** * 垂直滚动事件 */ VerticalScroll: MouseMovePayload; /** * 水平滚动事件 */ HorizontalScroll: MouseMovePayload; } /** 查找结果 */ export type SearchMatch = { /** * 单元格所在行号 */ row: number; /** * 单元格所在列号 */ column: number; /** * 单元格的text */ text: string; /** * 是否是链接单元格 */ isLinkCell?: boolean; }; /** 通知类型,由服务端事件推送,参见https://open.shimo.im/docs/04service-callback/push-message(https://open.shimo.im/docs/04service-callback/push-message) */ /** * comment - 评论 * mention_at - 提及 * date_mention - 日期提醒 */ export type NotificationType = 'comment' | 'mention_at' | 'date_mention'; /** 单元格数据信息 */ export type RangeData = { /** * 单元格数据 */ value: CellValue; /** * 单元格格式 */ format: string | undefined; /** * 合并单元格范围 */ span: Range | undefined; /** * 单元格格式类型 */ formatCategory: FormatCategory; /** * 单元格数字精度 */ precision: number | undefined; }; /** * 单元格格式类型 * auto - 常规 * text - 纯文本 * number - 数字 * percent - 百分比 * currency - 货币 * accounting - 会计 * date - 日期 * time - 时间 * fraction - 分数 * scientific - 科学计数 * special - 特殊 * custom - 自定义 */ export type FormatCategory = 'auto' /** 常规 */ | 'text' /** 纯文本 */ | 'number' /** 数字 */ | 'percent' /** 百分比 */ | 'currency' /** 货币 */ | 'accounting' /** 会计 */ | 'date' /** 日期 */ | 'time' /** 时间 */ | 'fraction' /** 分数 */ | 'scientific' /** 科学计数 */ | 'special' /** 特殊 */ | 'custom'; /** 自定义 */ /** 单元格值类型 */ export type CellValue = string | number | boolean | null; export interface Editor extends BaseEditor { /** * 展示评论侧边栏 * @since PD2.10 */ showComments(this: Editor): Promise; /** * 关闭评论侧边栏 * @since PD2.10 */ hideComments(this: Editor): Promise; /** * 展示历史侧边栏 * @since PD2.10 */ showHistory(this: Editor): Promise; /** * 关闭历史侧边栏 * @since PD2.10 */ hideHistory(this: Editor): Promise; /** * 展示锁定侧边栏 * @since PD2.10 */ showLocks(this: Editor): Promise; /** * 关闭锁定侧边栏 * @since PD2.10 */ hideLocks(this: Editor): Promise; /** * 创建版本 * @since PD2.10 * @param options.name 版本名称,since co-1.6 */ createRevision(this: Editor, options?: { name?: string; }): Promise; /** * 进入演示模式 * @since PD2.10 */ startDemonstration(this: Editor): Promise; /** * 离开演示模式 * @since PD2.10 */ endDemonstration(this: Editor): Promise; /** * 打印 * @since PD2.10 */ print(this: Editor): Promise; /** * 创建单元格锁定 * @since PD2.10 */ addRangeLock(this: Editor, options: { /** 用户id对应的权限 */ userPermissions: UserPermission; /** * 单元格范围 * @default 默认当前选中区域范围 */ ranges?: Range[]; /** * 工作表id * @default 默认当前工作表id */ sheetId?: string; /** 对该锁定的描述 */ description?: string; /** 部门id对应的权限 */ departmentPermissions?: DepartmentPermission; /** * 其他访问者的权限 * @default 1 */ visitorPermission?: PermissionLevel; }): Promise; /** * 创建工作表锁定 * @since PD2.10 */ addSheetLock(this: Editor, options: { /** 用户id对应的权限 */ userPermissions: UserPermission; /** * 工作表id * @default 默认当前工作表id */ sheetId?: string; /** 对该锁定的描述 */ description?: string; /** 部门id对应的权限 */ departmentPermissions?: DepartmentPermission; /** * 其他访问者的权限 * @default 1 */ visitorPermission?: PermissionLevel; }): Promise; /** * 删除指定范围内的所有单元格锁定 * @since PD2.10 */ removeRangeLocksInRanges(this: Editor, options: { /** * 工作表id * @default 默认当前工作表id */ sheetId?: string; /** * 单元格范围 * @default 默认当前选中区域范围 */ ranges?: Range[]; }): Promise; /** * 删除工作表锁定 * @since PD2.10 */ removeSheetLock(this: Editor, options: { /** * 工作表id * @default 默认当前工作表id */ sheetId?: string; preview?: undefined; }): Promise; /** * 获取当前激活sheet的id * @since PD2.10 */ getActiveSheetId(this: Editor): Promise; /** * 获取所有工作表的id * @since PD2.10 */ getSheetIds(this: Editor): Promise; /** * 根据工作表index获取工作表id * @since PD2.10 */ getSheetIdByIndex(this: Editor, options: { /** 工作表index(从0开始) */ index: number; }): Promise; /** * 获取工作表指定范围内的单元格的值 * @since PD2.10 */ getRangeValues(this: Editor, options: { /** * 工作表id * @default 默认当前工作表id */ sheetId?: string; /** * 单元格范围 * @default 默认当前选中范围 */ range?: Range[]; }): Promise; /** * 获取指定单元格的值 * @since PD2.10 */ getCellValue(this: Editor, options: { /** * 工作表id * @default 默认当前工作表id */ sheetId?: string; /** 行index(从0开始) */ row: number; /** 列index(从0开始) */ column: number; }): Promise; /** * 获取指定工作表行数量 * @since PD2.10 */ getRowCount(this: Editor, options: { /** * 工作表id * @default 默认当前工作表id */ sheetId?: string; }): Promise; /** * 获取指定工作表列数量 * @since PD2.10 */ getColumnCount(this: Editor, options: { /** * 工作表id * @default 默认当前工作表id */ sheetId?: string; }): Promise; /** * 获取指定工作表是否可见 * @since PD2.10 */ isSheetVisible(this: Editor, options: { /** * 工作表id * @default 默认当前工作表id */ sheetId?: string; }): Promise; /** * 更新环境变量 * @since PD3.4 */ updateRuntimeEnv(this: Editor, options: { /** 要更新的环境变量 */ env: { [key: string]: any; }; }): Promise; /** * 设置文件内容 * @since PD3.4 */ setContent(this: Editor, options: { /** 要设置的文件内容,会替换当前内容,实际类型接受 string | Delta */ content: any; }): Promise; /** * 设置聚焦状态 * @since PD3.4 */ setFocus(this: Editor, options: { /** * 设置表格聚焦状态 * @default true */ isFocus?: boolean; }): Promise; /** * 导出csv * @since pd-3.12 */ exportCsv(this: Editor): Promise; /** * 查找表格内容并高亮 * @since co-1.0 */ search(this: Editor, options: { /** 要查找的内容 */ text: string; /** * 查找的范围 * @default 默认当前选中的范围 */ range?: Range | Range[]; }): Promise; /** * 定位单元格 * @since co-1.0 */ locateCell(this: Editor, options: { /** 要定位的单元格行坐标 */ row: number; /** 要定位的单元格列坐标 */ column: number; /** * 要定位的工作表id * @default 默认当前激活工作表id */ sheetId?: string; }): Promise; /** * 取消搜索高亮 * @since co-1.0 */ cancelSearchHighlights(this: Editor): Promise; /** * 通过通知的guid定位单元格 * @since co-1.0 */ locateCellByGuid(this: Editor, options: { /** 通知类型 */ notificationType: NotificationType; /** 锚点guid */ guid: string; }): Promise; /** * 设置激活工作表 * @since co-1.0 */ setActiveSheet(this: Editor, options: { /** 要激活的工作表id */ sheetId: string; }): Promise; /** * 获取工作表列表信息 * @since co-1.0 */ getSheetList(this: Editor): Promise<{ name: string; id: string; }[]>; /** * 获取当前表格选中的范围 * @since co-1.0 */ getSelections(this: Editor): Promise; /** * 获取工作表指定范围内的单元格的数据 * @since co-1.0 */ getRangeData(this: Editor, options: { /** * 范围 * @default 默认当前选中的范围 */ range?: Range; }): Promise; /** * 粘贴内容 * @since co-1.0 */ paste(this: Editor, options: { /** 从剪切板获取的text/html */ html: string; /** 从剪切板获取的text/plain */ text: string; /** 从剪切板获取的file, 由于postMessage传输的限制,File对象需转成base64 */ base64File?: string; /** 是否删除末尾空白行 */ removeTrailingEmptyRows?: boolean; /** 是否删除末尾空白列 */ removeTrailingEmptyCols?: boolean; }): Promise; /** * 获取表格视图区域大小 * @since co-1.0 */ getViewportSize(this: Editor): Promise<{ width: number; height: number; }>; /** * 导出 * @since co-1.5 */ export(type: 'image' | 'imagePdf'): Promise; } /** * 控制插件是否开启,无特殊说明默认都是 true。某些插件设置为 false 后,可能影响数据呈现。 * 受后端服务版本影响,不是所有插件都可用,请以实际部署版本为准。 */ export interface PluginOptions { /** * 附件 (附件 / 云文件) */ Attachment?: boolean; /** * 高亮行列 */ HighlightPosition?: boolean; /** * 计算选项 */ CalcOption?: boolean; /** * 单元格历史 */ CellHistory?: boolean; /** * 图表 */ ChartV2?: boolean; /** * 任务清单 */ CheckList?: boolean; /** * 清除重复项 */ ClearRepeat?: boolean; /** * 合并工作表 (合并工作表依赖跨表格引用,如果跨表格引用设置为不可见,合并工作表也会不可见) */ CombineSheets?: boolean; /** * 评论 */ Comment?: boolean; /** * 条件格式 */ ConditionalFormat?: boolean; /** * 复制为图片 */ CopyAsImage?: boolean; CustomNames?: boolean; DataValidation?: boolean; FileSlimming?: boolean; HistorySidebar?: boolean; IndependentViewport?: boolean; Outline?: boolean; PivotTable?: boolean; Remarks?: boolean; SheetStyles?: boolean; Slicer?: boolean; SplitColumns?: boolean; ImagePermission?: boolean; CopyRangeLink?: boolean; CopyViewportLink?: boolean; ImportFormula?: boolean; BatchLock?: boolean; Mention?: boolean; DateMention?: boolean; Lock?: boolean; SheetTab?: boolean; MobileSheetTab?: boolean; Toolbar?: boolean; MobileToolbar?: boolean; FxEditor?: boolean; }