Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
xiugai
tonytonychopper12308e13be859af
diff --git a/packages/base-ui/src/Common/ComponentManager.ts b/packages/base-ui/src/Common/ComponentManager.tsindex 4c8b9d2090..4488ef139b 100644--- a/packages/base-ui/src/Common/ComponentManager.ts+++ b/packages/base-ui/src/Common/ComponentManager.ts@@ -1,14 +1,6 @@-import { ModalGroup } from '../UI/ModalGroup/ModalGroup';-export class ComponentManager {private _componentList: Map<string, any> = new Map();- private _modalManager: ModalManager;-- constructor() {- this._modalManager = new ModalManager();- }-register(name: string, component: any) {this._componentList.set(name, component);}@@ -21,28 +13,3 @@ export class ComponentManager {this._componentList.delete(name);}}--export class ModalManager {- private _modalGroup: ModalGroup;-- private _group = [];-- getComponent(ref: ModalGroup) {- this._modalGroup = ref;- }-- addModal(name: string, component: any) {- const index = this._modalGroup.findIndex((item) => item === name);- if (index < 0) {- this._plugin.registerComponent(name, component);- this._modalGroup.push(name);-- this._ModalGroupComponent?.setModalGroup(this._modalGroup);- }- }-- getModal(name: string) {- const ModalGroup = this._ModalGroupComponent.getModalGroup();- return ModalGroup.find((item) => item.constructor.name === name);- }-}diff --git a/packages/base-ui/src/Components/Slot/Slot.tsx b/packages/base-ui/src/Components/Slot/Slot.tsxnew file mode 100644index 0000000000..e71ec74dc0--- /dev/null+++ b/packages/base-ui/src/Components/Slot/Slot.tsx@@ -0,0 +1,43 @@+import { BaseComponentProps } from '../../BaseComponent';+import { Component } from '../../Framework';++interface IState {+ slotGroup: any[];+}++export class Slot extends Component<BaseComponentProps, IState> {+ refs: any[] = [];++ initialize() {+ this.state = {+ slotGroup: [],+ };+ }++ componentDidMount(): void {+ this.props.getComponent?.(this);+ }++ setSlotGroup(group: any[]) {+ const slotGroup = group.map((item, index) => {+ const Modal = plugin?.getRegisterComponent(item);+ if (Modal) {+ return <Modal ref={(ele: any) => (this.refs[index] = ele)} />;+ }+ return null;+ });++ this.setState({+ modalGroup,+ });+ }++ getModalGroup() {+ return this.refs;+ }++ render() {+ const { modalGroup } = this.state;+ return <>{modalGroup.map((item) => item)}</>;+ }+}diff --git a/packages/base-ui/src/Locale/en.ts b/packages/base-ui/src/Locale/en.tsindex f23a5a60df..796ed2d38d 100644--- a/packages/base-ui/src/Locale/en.ts+++ b/packages/base-ui/src/Locale/en.ts@@ -1,514 +1,8 @@export default {- spreadsheetLabel: 'Spreadsheet',- spreadsheetRightLabel: 'more Sheets',- spreadsheet: {+ SheetUI: {+ tooltip: 'SheetUI',one: 'one',two: 'two',three: 'three',},-- toolbar: {- undo: 'Undo',- redo: 'Redo',- paintFormat: 'Paint format',- currencyFormat: 'Format as currency',- percentageFormat: 'Format as percent',- numberDecrease: 'Decrease decimal places',- numberIncrease: 'Increase decimal places',- moreFormats: 'More formats',- font: 'Font',- fontSize: 'Font size',- bold: 'Bold (Ctrl+B)',- italic: 'Italic (Ctrl+I)',- strikethrough: 'Strikethrough (Alt+Shift+5)',- underline: 'Underline',- textColor: {- main: 'Text color',- right: 'Choose color',- },- resetColor: 'Reset',- customColor: 'CUSTOM',- alternatingColors: 'Alternating colors',- confirmColor: 'OK',- cancelColor: 'Cancel',- collapse: 'Collapse',- fillColor: {- main: 'Fill color',- right: 'Choose color',- },- border: {- main: 'Border',- right: 'Border style',- },- mergeCell: {- main: 'Merge cells',- right: 'Choose merge type',- },- horizontalAlignMode: {- main: 'Horizontal align',- right: 'Alignment',- },- verticalAlignMode: {- main: 'Vertical align',- right: 'Alignment',- },- textWrapMode: {- main: 'Text wrap',- right: 'Text wrap mode',- },- textRotateMode: {- main: 'Text rotate',- right: 'Text rotate mode',- },- freezeTopRow: 'Freeze top row',- sortAndFilter: 'Sort and filter',- findAndReplace: 'Find and replace',- sum: 'SUM',- autoSum: 'Auto SUM',- moreFunction: 'More functions',- conditionalFormat: 'Conditional format',- comment: 'Comment',- pivotTable: 'Pivot Table',- chart: 'Chart',- screenshot: 'Screenshot',- splitColumn: 'Split text',- insertImage: 'Insert image',- insertLink: 'Insert link',- dataValidation: 'Data validation',- protection: 'Protect the sheet',-- clearText: 'Clear color',- noColorSelectedText: 'No color is selected',-- toolMore: 'More',- toolLess: 'Less',- toolClose: 'Close',- toolMoreTip: 'More features',- moreOptions: 'More options',-- cellFormat: 'Cell format config',- print: 'Print',- borderMethod: {- top: 'Upper frame line',- bottom: 'Lower frame line',- left: 'Left frame line',- right: 'Right frame line',- },- more: 'More',- },- defaultFmt: {- Automatic: {- text: 'Automatic',- value: 'General',- example: '',- },- Number: {- text: 'Number',- value: '##0.00',- example: '1000.12',- },- Percent: {- text: 'Percent',- value: '#0.00%',- example: '12.21%',- },- PlainText: {- text: 'Plain text',- value: '@',- example: '',- },- Scientific: {- text: 'Scientific',- value: '0.00E+00',- example: '1.01E+5',- },- Accounting: {- text: 'Accounting',- value: '¥(0.00)',- example: '¥(1200.09)',- },- Thousand: {- text: 'Ten Thousand',- value: 'w',- example: '1亿2000万2500',- },- Currency: {- text: 'Currency',- value: '¥0.00',- example: '¥1200.09',- },- Digit: {- text: '万元2位小数',- value: 'w0.00',- example: '2万2500.55',- },- Date: {- text: 'Date',- value: 'yyyy-MM-dd',- example: '2017-11-29',- },- Time: { text: 'Time', value: 'hh:mm AM/PM', example: '3:00 PM' },- Time24H: { text: 'Time 24H', value: 'hh:mm', example: '15:00' },- DateTime: { text: 'Date time', value: 'yyyy-MM-dd hh:mm AM/PM', example: '2017-11-29 3:00 PM' },- DateTime24H: { text: 'Date time 24H', value: 'yyyy-MM-dd hh:mm', example: '2017-11-29 15:00' },- CustomFormats: { text: 'Custom Formats', value: 'fmtOtherSelf', example: '' },- },- format: {- moreCurrency: 'More currency formats',- moreDateTime: 'More date and time formats',- moreNumber: 'More number formats',-- titleCurrency: 'Currency formats',- decimalPlaces: 'Decimal places',- titleDateTime: 'Date and time formats',- titleNumber: 'Number formats',- },- fontFamily: {- TimesNewRoman: 'Times New Roman',- Arial: 'Arial',- Tahoma: 'Tahoma',- Verdana: 'Verdana',- MicrosoftAccorblack: 'Microsoft Accor black ',- SimSun: 'SimSun',- SimHei: 'SimHei',- Kaiti: 'Kaiti',- FangSong: 'FangSong',- NSimSun: 'NSimSun',- STXinwei: 'STXinwei',- STXingkai: 'STXingkai',- STLiti: 'STLiti',- HanaleiFill: 'HanaleiFill',- Anton: 'Anton',- Pacifico: 'Pacifico',- },- print: {- normalBtn: 'Normal',- layoutBtn: 'Page Layout',- pageBtn: 'Page break preview',-- menuItemPrint: 'Print (Ctrl+P)',- menuItemAreas: 'Print areas',- menuItemRows: 'Print title rows',- menuItemColumns: 'Print title columns',- },- align: {- left: 'left',- center: 'center',- right: 'right',-- top: 'top',- middle: 'middle',- bottom: 'bottom',- },-- dateFmtList: [- {- name: '1930-08-05',- value: 'yyyy-MM-dd',- },- {- name: '1930/8/5',- value: 'yyyy/MM/dd',- },- {- name: '08-05',- value: 'MM-dd',- },- {- name: '8-5',- value: 'M-d',- },- {- name: '13:30:30',- value: 'h:mm:ss',- },- {- name: '13:30',- value: 'h:mm',- },- {- name: 'PM 01:30',- value: 'AM/PM hh:mm',- },- {- name: 'PM 1:30',- value: 'AM/PM h:mm',- },- {- name: 'PM 1:30:30',- value: 'AM/PM h:mm:ss',- },- {- name: '08-05 PM 01:30',- value: 'MM-dd AM/PM hh:mm',- },- ],- numFmtList: [- {- name: '1235',- value: '0',- },- {- name: '1234.56',- value: '0.00',- },- {- name: '1,235',- value: '#,##0',- },- {- name: '1,234.56',- value: '#,##0.00',- },- {- name: '1,235',- value: '#,##0_);(#,##0)',- },- {- name: '1,235',- value: '#,##0_);[Red](#,##0)',- },- {- name: '1,234.56',- value: '#,##0.00_);(#,##0.00)',- },- {- name: '1,234.56',- value: '#,##0.00_);[Red](#,##0.00)',- },- {- name: '$1,235',- value: '$#,##0_);($#,##0)',- },- {- name: '$1,235',- value: '$#,##0_);[Red]($#,##0)',- },- {- name: '$1,234.56',- value: '$#,##0.00_);($#,##0.00)',- },- {- name: '$1,234.56',- value: '$#,##0.00_);[Red]($#,##0.00)',- },- {- name: '1234.56',- value: '@',- },- {- name: '123456%',- value: '0%',- },- {- name: '123456.00%',- value: '0.00%',- },- {- name: '1.23E+03',- value: '0.00E+00',- },- {- name: '1.2E+3',- value: '##0.0E+0',- },- {- name: '1234 5/9',- value: '# ?/?',- },- {- name: '1234 14/25',- value: '# ??/??',- },- {- name: '$ 1,235',- value: '_($* #,##0_);_(...($* "-"_);_(@_)',- },- {- name: '1,235',- value: '_(* #,##0_);_(*..._(* "-"_);_(@_)',- },- {- name: '$ 1,234.56',- // "value": '_($* #,##0.00_)...* "-"??_);_(@_)'- value: '_($* #,##0.00_);_(...($* "-"_);_(@_)',- },- {- name: '1,234.56',- value: '_(* #,##0.00_);...* "-"??_);_(@_)',- },- ],- button: {- confirm: 'OK',- cancel: 'Cancel',- close: 'Close',- update: 'Update',- delete: 'Delete',- insert: 'Insert',- prevPage: 'Previous',- nextPage: 'Next',- total: 'total:',- },- punctuation: {- tab: 'Tab',- semicolon: 'semicolond',- comma: 'comma',- space: 'space',- },- colorPicker: {- collapse: 'Collapse',- customColor: 'CUSTOM',- change: 'Change',- confirmColor: 'OK',- cancelColor: 'Cancel',- },- borderLine: {- borderTop: 'borderTop',- borderBottom: 'borderBottom',- borderLeft: 'borderLeft',- borderRight: 'borderRight',- borderNone: 'borderNone',- borderAll: 'borderAll',- borderOutside: 'borderOutside',- borderInside: 'borderInside',- borderHorizontal: 'borderHorizontal',- borderVertical: 'borderVertical',- borderColor: 'borderColor',- borderSize: 'borderSize',- },- merge: {- all: 'Merge all',- vertical: 'Vertical merge',- horizontal: 'Horizontal merger',- cancel: 'Cancel merge',- overlappingError: 'Cannot merge overlapping areas',- partiallyError: 'Cannot perform this operation on partially merged cells',- },- textWrap: {- overflow: 'Overflow',- wrap: 'Wrap',- clip: 'Clip',- },- textRotate: {- none: 'None',- angleUp: 'Tilt Up',- angleDown: 'Tilt Down',- vertical: 'Stack Vertically',- rotationUp: 'Rotate Up',- rotationDown: 'Rotate Down',- },- sheetConfig: {- delete: 'Delete',- copy: 'Copy',- rename: 'Rename',- changeColor: 'Change color',- hide: 'Hide',- unhide: 'Unhide',- moveLeft: 'Move left',- moveRight: 'Move right',- resetColor: 'Reset color',- cancelText: 'Cancel',- chooseText: 'Confirm color',-- tipNameRepeat: 'The name of the tab page cannot be repeated! Please revise',- noMoreSheet: 'The workbook contains at least one visual worksheet. To delete the selected worksheet, please insert a new worksheet or show a hidden worksheet.',- confirmDelete: 'Are you sure to delete',- redoDelete: 'Can be undo by Ctrl+Z',- noHide: "Can't hide, at least keep one sheet tag",- chartEditNoOpt: 'This operation is not allowed in chart editing mode!',- sheetNameSpecCharError: 'The name cannot contain:[ ] : ? * / \' "',- sheetNameCannotIsEmptyError: 'Sheet name cannot be empty',- },- rightClick: {- copy: 'Copy',- copyAs: 'Copy as',- cut: 'Cut',- paste: 'Paste',- insert: 'Insert',- delete: 'Delete',- deleteCell: 'Delete cell',- deleteSelected: 'Delete selected ',- hide: 'Hide',- hideSelected: 'Hide selected ',- showHide: 'Show hidden ',- to: 'Towards',- left: 'Left',- right: 'Right',- top: 'Top',- bottom: 'Bottom',- moveLeft: 'Move left',- moveUp: 'Move up',- add: 'Add',- row: 'Row',- column: 'Column',- width: 'Width',- height: 'Height',- number: 'Number',- confirm: 'Confirm',- orderAZ: 'A-Z order',- orderZA: 'Z-A order',- clearContent: 'Clear content',- matrix: 'Matrix operation',- sortSelection: 'Sort',- filterSelection: 'Filter',- chartGeneration: 'Create chart',- firstLineTitle: 'first line title',- untitled: 'untitled',- array1: 'One-dimensional array',- array2: 'Two-dimensional array',- array3: 'Multidimensional Arrays',- diagonal: 'Diagonal',- antiDiagonal: 'Anti-diagonal',- diagonalOffset: 'Diagonal offset',- offset: 'Offset',- boolean: 'Boolean',- flip: 'Flip',- upAndDown: 'Up and down',- leftAndRight: 'Left and right',- clockwise: 'Clockwise',- counterclockwise: 'Counterclockwise',- transpose: 'Transpose',- matrixCalculation: 'Matrix calculation',- plus: 'Plus',- minus: 'Minus',- multiply: 'Multiply',- divided: 'Divided',- power: 'Power',- root: 'Root',- log: 'Log',- delete0: 'Delete 0 values at both ends',- removeDuplicate: 'Remove duplicate values',- byRow: 'By row',- byCol: 'By column',- generateNewMatrix: 'Generate new matrix',- },- info: {- detailUpdate: 'New opened',- detailSave: 'Local cache restored',- row: '',- column: '',- loading: 'Loading...',-- copy: 'Copy',- return: 'Exit',- rename: 'Rename',- tips: 'Rename',- noName: 'Untitled spreadsheet',- wait: 'waiting for update',-- add: 'Add',- addLast: 'more rows at bottom',- backTop: 'Back to the top',- // eslint-disable-next-line no-template-curly-in-string- pageInfo: 'Total ${total},${totalPage} page,current ${currentPage}',- nextPage: 'Next',-- tipInputNumber: 'Please enter the number',- tipInputNumberLimit: 'The increase range is limited to 1-100',-- tipRowHeightLimit: 'Row height must be between 0 ~ 545',- tipColumnWidthLimit: 'The column width must be between 0 ~ 2038',- // eslint-disable-next-line no-template-curly-in-string- pageInfoFull: 'Total ${total},${totalPage} page,All data displayed',- },};diff --git a/packages/base-ui/src/Locale/zh.ts b/packages/base-ui/src/Locale/zh.tsindex 410b39a524..943ed476f8 100644--- a/packages/base-ui/src/Locale/zh.ts+++ b/packages/base-ui/src/Locale/zh.ts@@ -1,377 +1,8 @@export default {- spreadsheetLabel: '插件',- spreadsheetRightLabel: '更多 Sheets',- spreadsheet: {+ SheetUI: {+ tooltip: 'SheetUI',one: '一',two: '二',three: '三',},-- toolbar: {- undo: '撤销',- redo: '重做',- paintFormat: '格式刷',- currencyFormat: '货币格式',- percentageFormat: '百分比格式',- numberDecrease: '减少小数位数',- numberIncrease: '增加小数位数',- moreFormats: '更多格式',- font: '字体',- fontSize: '字号大小',- bold: '粗体 (Ctrl+B)',- italic: '斜体 (Ctrl+I)',- strikethrough: '删除线 (Alt+Shift+5)',- underline: '下划线',- textColor: {- main: '文本颜色',- right: '颜色选择',- },- resetColor: '重置颜色',- customColor: '自定义',- alternatingColors: '交替颜色',- confirmColor: '确定颜色',- cancelColor: '取消',- collapse: '收起',- fillColor: {- main: '单元格颜色',- right: '颜色选择',- },- border: {- main: '边框',- right: '边框类型',- },- mergeCell: {- main: '合并单元格',- right: '选择合并类型',- },- horizontalAlignMode: {- main: '水平对齐',- right: '对齐方式',- },- verticalAlignMode: {- main: '垂直对齐',- right: '对齐方式',- },- textWrapMode: {- main: '文本换行',- right: '换行方式',- },- textRotateMode: {- main: '文本旋转',- right: '旋转方式',- },- freezeTopRow: '冻结首行',- sortAndFilter: '排序和筛选',- findAndReplace: '查找替换',- sum: '求和',- autoSum: '自动求和',- moreFunction: '更多函数',- conditionalalFormat: '条件格式',- comment: '批注',- pivotTable: '数据透视表',- chart: '图表',- screenshot: '截图',- splitColumn: '分列',- insertImage: '插入图片',- insertLink: '插入链接',- dataValidation: '数据验证',- protection: '保护工作表内容',-- clearText: '清除颜色选择',- noColorSelectedText: '没有颜色被选择',-- toolMore: '更多',- toolLess: '少于',- toolClose: '收起',- toolMoreTip: '更多功能',- moreOptions: '更多选项',-- cellFormat: '设置单元格格式',- print: '打印',- borderMethod: {- top: '上框线',- bottom: '下框线',- left: '左框线',- right: '右框线',- },- more: '更多',- },- defaultFmt: {- Automatic: {- text: '自动',- value: 'General',- example: '',- },- Number: {- text: '数字',- value: '##0.00',- example: '1000.12',- },- Percent: {- text: '百分比',- value: '#0.00%',- example: '12.21%',- },- PlainText: {- text: '纯文本',- value: '@',- example: '',- },- Scientific: {- text: '科学计数',- value: '0.00E+00',- example: '1.01E+5',- },- Accounting: {- text: '会计',- value: '¥(0.00)',- example: '¥(1200.09)',- },- Thousand: {- text: '万元',- value: 'w',- example: '1亿2000万2500',- },- Currency: {- text: '货币',- value: '¥0.00',- example: '¥1200.09',- },- Digit: {- text: '万元2位小数',- value: 'w0.00',- example: '2万2500.55',- },- Date: {- text: '日期',- value: 'yyyy-MM-dd',- example: '2017-11-29',- },- Time: { text: '时间', value: 'hh:mm AM/PM', example: '3:00 PM' },- Time24H: { text: '时间24H', value: 'hh:mm', example: '15:00' },- DateTime: { text: '日期时间', value: 'yyyy-MM-dd hh:mm AM/PM', example: '2017-11-29 3:00 PM' },- DateTime24H: { text: '日期时间24H', value: 'yyyy-MM-dd hh:mm', example: '2017-11-29 15:00' },- CustomFormats: { text: '自定义格式', value: 'fmtOtherSelf', example: '' },- },- format: {- moreCurrency: '更多货币格式',- moreDateTime: '更多日期与时间格式',- moreNumber: '更多数字格式',-- titleCurrency: '货币格式',- decimalPlaces: '小数位数',- titleDateTime: '日期与时间格式',- titleNumber: '数字格式',- },- fontFamily: {- TimesNewRoman: 'Times New Roman',- Arial: 'Arial',- Tahoma: 'Tahoma',- Verdana: 'Verdana',- MicrosoftAccorblack: '微软雅黑',- SimSun: '宋体',- SimHei: '黑体',- Kaiti: '楷体',- FangSong: '仿宋',- NSimSun: '新宋体',- STXinwei: '华文新魏',- STXingkai: '华文行楷',- STLiti: '华文隶书',- HanaleiFill: 'HanaleiFill',- Anton: 'Anton',- Pacifico: 'Pacifico',- },- print: {- normalBtn: '常规视图',- layoutBtn: '页面布局',- pageBtn: '分页预览',-- menuItemPrint: '打印(Ctrl+P)',- menuItemAreas: '打印区域',- menuItemRows: '打印标题行',- menuItemColumns: '打印标题列',- },- align: {- left: '左对齐',- center: '中间对齐',- right: '右对齐',-- top: '顶部对齐',- middle: '居中对齐',- bottom: '底部对齐',- },-- button: {- confirm: '确定',- cancel: '取消',- close: '关闭',- update: 'Update',- delete: 'Delete',- insert: '新建',- prevPage: '上一页',- nextPage: '下一页',- total: '总共:',- },- punctuation: {- tab: 'Tab 键',- semicolon: '分号',- comma: '逗号',- space: '空格',- },- colorPicker: {- collapse: '收起',- customColor: '自定义',- change: '切换',- confirmColor: '确定',- cancelColor: '取消',- },- borderLine: {- borderTop: '上框线',- borderBottom: '下框线',- borderLeft: '左框线',- borderRight: '右框线',- borderNone: '无',- borderAll: '所有',- borderOutside: '外侧',- borderInside: '内侧',- borderHorizontal: '内侧横线',- borderVertical: '内侧竖线',- borderColor: '边框颜色',- borderSize: '边框粗细',- },- merge: {- all: '全部合并',- vertical: '垂直合并',- horizontal: '水平合并',- cancel: '取消合并',- overlappingError: '不能合并重叠区域',- partiallyError: '无法对部分合并单元格执行此操作',- },- textWrap: {- overflow: '溢出',- wrap: '自动换行',- clip: '截断',- },- textRotate: {- none: '无旋转',- angleUp: '向上倾斜',- angleDown: '向下倾斜',- vertical: '竖排文字',- rotationUp: '向上90°',- rotationDown: '向下90°',- },- sheetConfig: {- delete: '删除',- copy: '复制',- rename: '重命名',- changeColor: '更改颜色',- hide: '隐藏',- unhide: '取消隐藏',- moveLeft: '向左移',- moveRight: '向右移',- resetColor: '重置颜色',- cancelText: '取消',- chooseText: '确定颜色',-- tipNameRepeat: '标签页的名称不能重复!请重新修改',- noMoreSheet: '工作薄内至少含有一张可视工作表。若需删除选定的工作表,请先插入一张新工作表或显示一张隐藏的工作表。',- confirmDelete: '是否删除',- redoDelete: '可以通过Ctrl+Z撤销删除',- noHide: '不能隐藏, 至少保留一个sheet标签',- chartEditNoOpt: '图表编辑模式下不允许该操作!',- sheetNameSpecCharError: "名称不能超过31个字符,首尾不能是' 且名称不能包含:\r\n[ ] : \\ ? * /",- sheetNameCannotIsEmptyError: '名称不能为空!',- },- rightClick: {- copy: '复制',- copyAs: '复制为',- cut: '剪切',- paste: '粘贴',- insert: '插入',- delete: '删除',- deleteCell: '删除单元格',- deleteSelected: '删除选中',- hide: '隐藏',- hideSelected: '隐藏选中',- showHide: '显示隐藏',- to: '向',- left: '左',- right: '右',- top: '上',- bottom: '下',- moveLeft: '左移',- moveUp: '上移',- add: '增加',- row: '行',- column: '列',- width: '宽',- height: '高',- number: '数字',- confirm: '确认',- orderAZ: 'A-Z顺序排列',- orderZA: 'Z-A降序排列',- clearContent: '清除内容',- matrix: '矩阵操作选区',- sortSelection: '排序选区',- filterSelection: '筛选选区',- chartGeneration: '图表生成',- firstLineTitle: '首行为标题',- untitled: '无标题',- array1: '一维数组',- array2: '二维数组',- array3: '多维数组',- diagonal: '对角线',- antiDiagonal: '反对角线',- diagonalOffset: '对角偏移',- offset: '偏移量',- boolean: '布尔值',- flip: '翻转',- upAndDown: '上下',- leftAndRight: '左右',- clockwise: '顺时针',- counterclockwise: '逆时针',- transpose: '转置',- matrixCalculation: '矩阵计算',- plus: '加',- minus: '减',- multiply: '乘',- divided: '除',- power: '次方',- root: '次方根',- log: 'log',- delete0: '删除两端0值',- removeDuplicate: '删除重复值',- byRow: '按行',- byCol: '按列',- generateNewMatrix: '生成新矩阵',- },- info: {- detailUpdate: '新打开',- detailSave: '已恢复本地缓存',- row: '行',- column: '列',- loading: '渲染中···',-- copy: '副本',- return: '返回',- rename: '重命名',- tips: '重命名',- noName: '无标题的电子表格',- wait: '待更新',-- add: '添加',- addLast: '在底部添加',- backTop: '回到顶部',- // eslint-disable-next-line no-template-curly-in-string- pageInfo: '共${total}条,${totalPage}页,当前已显示${currentPage}页',- nextPage: '下一页',-- tipInputNumber: '请输入数字',- tipInputNumberLimit: '增加范围限制在1-100',-- tipRowHeightLimit: '行高必须在0 ~ 545之间',- tipColumnWidthLimit: '列宽必须在0 ~ 2038之间',- // eslint-disable-next-line no-template-curly-in-string- pageInfoFull: '共${total}条,${totalPage}页,已显示全部数据',- },};diff --git a/packages/base-ui/src/UI/ModalGroup/ModalGroup.tsx b/packages/base-ui/src/UI/ModalGroup/ModalGroup.tsxindex 769a73b75f..e71ec74dc0 100644--- a/packages/base-ui/src/UI/ModalGroup/ModalGroup.tsx+++ b/packages/base-ui/src/UI/ModalGroup/ModalGroup.tsx@@ -2,24 +2,24 @@ import { BaseComponentProps } from '../../BaseComponent';import { Component } from '../../Framework';interface IState {- modalGroup: any[];+ slotGroup: any[];}-export class ModalGroup extends Component<BaseComponentProps, IState> {+export class Slot extends Component<BaseComponentProps, IState> {refs: any[] = [];initialize() {this.state = {- modalGroup: [],+ slotGroup: [],};}componentDidMount(): void {- this._context.getObserverManager().getObserver<ModalGroup>('onModalGroupDidMountObservable')?.notifyObservers(this);+ this.props.getComponent?.(this);}- setModalGroup(group: ModalGroupProps) {- const modalGroup = group.map((item, index) => {+ setSlotGroup(group: any[]) {+ const slotGroup = group.map((item, index) => {const Modal = plugin?.getRegisterComponent(item);if (Modal) {return <Modal ref={(ele: any) => (this.refs[index] = ele)} />;diff --git a/packages/style-univer/README-zh.md b/packages/style-univer/README-zh.mddeleted file mode 100644index 3f3671eee9..0000000000--- a/packages/style-univer/README-zh.md+++ /dev/null@@ -1,98 +0,0 @@-# style-univer--简体中文 | [English](./README.md)--## 介绍--Universheet 官方 UI 组件库--## 特性--- 纯 tsx 组件,可方便集成到 vue/react-- 按需引入,不用担心影响打包体积--## 用法--### 安装--```shell-npm i @univerjs/style-univer-```--### 使用--```js-import baseUI from '@univerjs/style-univer';-universheet.install(baseUI);-universheet.create({- plugins: ['style-univer'],-});-```--## 本地开发--### 环境--- [Node.js](https://nodejs.org/en/) Version >= 10-- [npm](https://www.npmjs.com/) Version >= 7--### 安装--```-npm i-```--### 开发--```-# 当前目录 ./packages/style-univer/-npm run dev--# 或者项目根目录 ./-npm run dev -w @univerjs/style-univer-```--### 打包--```-# 当前目录 ./packages/style-univer/-npm run build--# 或者根目录 ./-npm run build -w @univerjs/style-univer-```--## 组件库文档--使用[Docusaurus 2](https://docusaurus.io/)构建--### 安装--```console-# 根目录-npm i-```--### 开发--```console-# 当前目录-npm run start--# 或者根目录-npm run start -w @univerjs/style-univer-```--此命令启动本地开发服务器并打开浏览器窗口。 大多数更改都会实时刷新,而无需重新启动服务器。--### 打包--```console-# 当前目录-npm run build:doc--# 或者根目录-npm run build:doc -w @univerjs/style-univer-```--此命令将静态内容生成到 `build` 目录中,并且可以使用任何静态内容托管服务来提供。diff --git a/packages/style-univer/README.md b/packages/style-univer/README.mddeleted file mode 100644index 9b453d3c1e..0000000000--- a/packages/style-univer/README.md+++ /dev/null@@ -1,98 +0,0 @@-# style-univer--English| [简体中文](./README-zh.md)--## Introduction--Universheet official UI component library--## Features--- Pure tsx components, which can be easily integrated into vue/react-- Import on demand, don’t worry about affecting the package size--## Usage--### Install--```shell-npm i @univerjs/style-univer-```--### Import--```js-import baseUI from '@univerjs/style-univer';-universheet.install(baseUI);-universheet.create({- plugins: ['style-univer'],-});-```--## Local development--### Requirements--- [Node.js](https://nodejs.org/en/) Version >= 10-- [npm](https://www.npmjs.com/) Version >= 7--### Installation--```-npm i-```--### Development--```-# Current directory ./packages/style-univer/-npm run dev--# Or project root directory ./-npm run dev -w @univerjs/style-univer-```--### Package--```-# Current directory ./packages/style-univer/-npm run build--# Or root directory ./-npm run build -w @univerjs/style-univer-```--## Doc Website--This website is built using [Docusaurus 2](https://docusaurus.io/), a modern static website generator.--### Installation--```console-# root folder-npm i-```--### Development--```console-# style-univer folder-npm run start--# or root folder-npm run start -w @univerjs/style-univer-```--This command starts a local development server and opens up a browser window. Most changes are reflected live without having to restart the server.--### Build--```console-# style-univer folder-npm run build:doc--# or root folder-npm run build:doc -w @univerjs/style-univer-```--This command generates static content into the `build` directory and can be served using any static contents hosting service.diff --git a/packages/style-univer/index.html b/packages/style-univer/index.htmldeleted file mode 100644index 1e3b8b2a6a..0000000000--- a/packages/style-univer/index.html+++ /dev/null@@ -1,31 +0,0 @@-<!DOCTYPE html>-<html lang="en">--<head>- <meta charset="UTF-8" />- <link rel="icon" type="image/svg+xml" href="favicon.svg" />- <meta name="viewport" content="width=device-width, initial-scale=1.0" />- <title>Universheet</title>- <style>- #universheet-demo-up {- width: 100%;- height: 50vh;- }-- #universheet-demo-down {- width: 100%;- height: 40vh;- position: absolute;- bottom: 0;- }- </style>-</head>--<body>- <div id="universheet-demo-up"></div>- <div id="universheet-demo-down"></div>-- <script type="module" src="/src/main.tsx"></script>-</body>--</html>\ No newline at end of filediff --git a/packages/style-univer/jest.config.js b/packages/style-univer/jest.config.jsdeleted file mode 100644index 2612503f8a..0000000000--- a/packages/style-univer/jest.config.js+++ /dev/null@@ -1,26 +0,0 @@-/** @type {import('ts-jest/dist/types').InitialOptionsTsJest} */-module.exports = {- preset: 'ts-jest',- // preset: 'jest-puppeteer',- testEnvironment: 'jsdom',- // testRegex: "./*\\e2e\\.test\\.js$",- moduleFileExtensions: ['js', 'ts', 'tsx'],-- roots: ['<rootDir>'],- testMatch: ['**/__tests__/**/*.+(ts|tsx|js)', '**/?(*.)+(spec|test).+(ts|tsx|js)'],- transform: {- '^.+\\.(ts|tsx)$': 'ts-jest',- '^.+\\.tsx?$': 'babel-jest', // https://github.com/kulshekhar/ts-jest/issues/937#issuecomment-455431207- },- moduleNameMapper: {- '\\.(css|less)$': 'identity-obj-proxy',- },- globals: {- 'ts-jest': {- tsconfig: '<rootDir>/tsconfig.test.json',- },- },-- collectCoverage: true,- coverageReporters: ['json', 'html'],-};diff --git a/packages/style-univer/tsconfig.json b/packages/style-univer/tsconfig.jsondeleted file mode 100644index dc7673060c..0000000000--- a/packages/style-univer/tsconfig.json+++ /dev/null@@ -1,28 +0,0 @@-{- "compilerOptions": {- "rootDir": "./",- "outDir": "lib",- "target": "ESNext",- "lib": ["ESNext", "DOM", "WebWorker"],- "module": "ESNext",- "moduleResolution": "Node", //This value is needed for Node.js.- "declaration": true,- "declarationDir": "./lib",- "declarationMap": true,- "sourceMap": true,- "resolveJsonModule": true,- "strict": true,- "allowJs": true,- "baseUrl": "./",- "skipLibCheck": true,- "esModuleInterop": true, // auto allowSyntheticDefaultImports tru- "suppressImplicitAnyIndexErrors": true,- "experimentalDecorators": true,- "jsx": "preserve",- "jsxFactory": "h",- "jsxFragmentFactory": "Fragment",- "strictPropertyInitialization": false,- "types": ["jest", "node", "@types/jest"]- },- "include": ["src/**/*", "tests/**/*.(spec|test).(ts|tsx|js)", "../base-ui/src/StyleUniver.ts"]-}diff --git a/packages/style-univer/tsconfig.ref.json b/packages/style-univer/tsconfig.ref.jsondeleted file mode 100644index 0c86b2c554..0000000000--- a/packages/style-univer/tsconfig.ref.json+++ /dev/null@@ -1,7 +0,0 @@-{- "extends": "./tsconfig.json",- "include": ["src/**/*"],- "compilerOptions": {- "composite": true- }-}diff --git a/packages/style-univer/tsconfig.test.json b/packages/style-univer/tsconfig.test.jsondeleted file mode 100644index a2ac02c4ae..0000000000--- a/packages/style-univer/tsconfig.test.json+++ /dev/null@@ -1,7 +0,0 @@-{- "extends": "./tsconfig.json",- "compilerOptions": {- "jsx": "react-jsx",- "jsxImportSource": "preact"- }-}diff --git a/packages/style-univer/vite.config.ts b/packages/style-univer/vite.config.tsdeleted file mode 100644index 0d633f4a13..0000000000--- a/packages/style-univer/vite.config.ts+++ /dev/null@@ -1,53 +0,0 @@-import { defineConfig } from 'vite';-import path from 'path';-import preact from '@preact/preset-vite';-import createExternal from 'vite-plugin-external';--import { name, version } from './package.json';--const resolve = (url: string) => path.resolve(__dirname, url);--export default defineConfig({- build: {- lib: {- entry: resolve('src/index.ts'),- name: 'StyleUniver',- formats: ['es', 'umd', 'cjs'],- fileName: 'univer-style-univer',- },- outDir: './lib',- sourcemap: true,- },- define: {- pkgJson: { name, version },- },- css: {- modules: {- localsConvention: 'camelCaseOnly', // dash to camelCase conversion// .apply-color -> applyColor- generateScopedName: 'univer-[local]', // custom prefix class name- },- preprocessorOptions: {- less: {- javascriptEnabled: true,- },- },- },- server: {- port: 3103,- // open: true, // Automatically open the app in the browser on server start.- },- plugins: [- preact(),- createExternal({- externals: {- '@univerjs/core': '@univerjs/core',- '@univerjs/base-ui': '@univerjs/base-ui',- 'css-vars-ponyfill': 'css-vars-ponyfill',- nanoid: 'nanoid',- 'react-colorful': 'react-colorful',- preact: 'preact',- react: 'react',- },- }),- ],-});diff --git a/packages/ui-plugin-sheets/src/Basic/Enum/index.ts b/packages/ui-plugin-sheets/src/Basic/Enum/index.tsnew file mode 100644index 0000000000..8ab1531b5b--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basic/Enum/index.ts@@ -0,0 +1 @@+export * from './LocaleType';diff --git a/packages/ui-plugin-sheets/src/Basic/Shared/index.ts b/packages/ui-plugin-sheets/src/Basic/Shared/index.tsnew file mode 100644index 0000000000..28d40166a9--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basic/Shared/index.ts@@ -0,0 +1 @@+export * from './Locale';diff --git a/packages/ui-plugin-sheets/src/Basics/Const/DefaultUniverSheetConfig.ts b/packages/ui-plugin-sheets/src/Basics/Const/DefaultUniverSheetConfig.tsnew file mode 100644index 0000000000..542fe9c055--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Const/DefaultUniverSheetConfig.ts@@ -0,0 +1,70 @@+export const DefaultRightMenuConfig = {+ InsertRow: true,+ InsertColumn: true,+ AddRowTop: true,+ AddRowBottom: true,+ AddColumnLeft: true,+ AddColumnRight: true,+ DeleteRow: true,+ DeleteColumn: true,+ HideRow: true,+ ShowRow: true,+ RowHeight: true,+ HideColumn: true,+ ShowColumn: true,+ ColumnWidth: true,+ DeleteCell: true,+ ClearContent: true,+ Matrix: true,+};++export const DefaultToolbarConfig = {+ undo: true,+ redo: true, // Undo redo+ paintFormat: true, // Format brush+ currencyFormat: true, // currency format+ percentageFormat: true, // Percentage format+ numberDecrease: true, // 'Decrease the number of decimal places'+ numberIncrease: true, // 'Increase the number of decimal places+ moreFormats: true, // 'More Formats'+ font: true, // 'font'+ fontSize: true, // 'Font size'+ bold: true, // 'Bold (Ctrl+B)'+ italic: true, // 'Italic (Ctrl+I)'+ strikethrough: true, // 'Strikethrough (Alt+Shift+5)'+ underline: true, // 'Underline (Alt+Shift+6)'+ textColor: true, // 'Text color'+ fillColor: true, // 'Cell color'+ border: true, // 'border'+ horizontalAlignMode: true, // 'Horizontal alignment'+ verticalAlignMode: true, // 'Vertical alignment'+ textWrapMode: true, // 'Wrap mode'+ textRotateMode: true, // 'Text Rotation Mode'+ mergeCell: true,+};++export const DefaultSheetContainerConfig = {+ outerLeft: false,+ outerRight: false,+ header: true,+ footer: true,+ innerLeft: false,+ innerRight: false,+ frozenHeaderLT: false,+ frozenHeaderRT: false,+ frozenHeaderLM: false,+ frozenContent: false,+ infoBar: true,+ toolBar: true,+ rightMenu: true,+ countBar: true,+ sheetBar: true,+};++export const DefaultSheetUiConfig = {+ layout: {+ sheetContainerConfig: DefaultSheetContainerConfig,+ rightMenuConfig: DefaultRightMenuConfig,+ toolbarConfig: DefaultToolbarConfig,+ },+};diff --git a/packages/ui-plugin-sheets/src/Basics/Const/index.ts b/packages/ui-plugin-sheets/src/Basics/Const/index.tsindex 0dc96d927a..e9bfab2012 100644--- a/packages/ui-plugin-sheets/src/Basics/Const/index.ts+++ b/packages/ui-plugin-sheets/src/Basics/Const/index.ts@@ -1 +1,2 @@export * from './PLUGIN_NAME';+export * from './DefaultUniverSheetConfig';diff --git a/packages/ui-plugin-sheets/src/Basics/Enum/LocaleType.ts b/packages/ui-plugin-sheets/src/Basics/Enum/LocaleType.tsnew file mode 100644index 0000000000..a820b34120--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Enum/LocaleType.ts@@ -0,0 +1,11 @@+/**+ * Internationalized enumeration information.+ *+ * Refer to {@link https://github.com/ladjs/i18n-locales | i18n-locales}+ */+export enum LocaleType {+ EN = 'en',+ ZH = 'zh',+}++export type LocaleTypes = `${LocaleType}`;diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/Cell.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/Cell.tsnew file mode 100644index 0000000000..f0ec176b46--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/Cell.ts@@ -0,0 +1,5 @@+export interface ICell {+ row: number;+ column: number;+ value: string;+}diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ISheetsPluginConfig.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ISheetsPluginConfig.tsnew file mode 100644index 0000000000..539dd534b2--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ISheetsPluginConfig.ts@@ -0,0 +1,19 @@+import { SheetRightMenuConfig } from './RightMenuConfig';+import { SheetContainerConfig } from './SheetContainerConfig';+import { SheetToolBarConfig } from './ToolBarConfig';+import { SheetContext } from '@univerjs/core';+import { LocaleType } from '../../Enum';++export interface ILayout {+ sheetContainerConfig?: SheetContainerConfig;+ toolBarConfig?: SheetToolBarConfig;+ rightMenuConfig?: SheetRightMenuConfig;+}++export interface ISheetsPluginConfig {+ container?: HTMLElement | string;+ layout?: ILayout;+ skin?: string;+ locale?: LocaleType;+ context?: SheetContext;+}diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/RightMenuConfig.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/RightMenuConfig.tsnew file mode 100644index 0000000000..079dd77036--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/RightMenuConfig.ts@@ -0,0 +1,25 @@+export interface SheetRightMenuConfig {+ InsertRow?: boolean;+ InsertColumn?: boolean;+ AddRowTop?: boolean;+ AddRowBottom?: boolean;+ AddColumnLeft?: boolean;+ AddColumnRight?: boolean;+ DeleteRow?: boolean;+ DeleteColumn?: boolean;+ HideRow?: boolean;+ ShowRow?: boolean;+ RowHeight?: boolean;+ HideColumn?: boolean;+ ShowColumn?: boolean;+ ColumnWidth?: boolean;+ DeleteCell?: boolean;+ ClearContent?: boolean;+ Matrix?: boolean;+}++export interface DocRightMenuConfig {}++export interface SlideRightMenuConfig {}++export interface RightMenuConfig extends SheetRightMenuConfig, DocRightMenuConfig, SlideRightMenuConfig {}diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/SheetContainerConfig.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/SheetContainerConfig.tsnew file mode 100644index 0000000000..c68a79e28a--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/SheetContainerConfig.ts@@ -0,0 +1,36 @@+export interface SheetContainerConfig {+ outerLeft?: boolean;++ outerRight?: boolean;++ header?: boolean;++ footer?: boolean;++ innerLeft?: boolean;++ innerRight?: boolean;++ frozenHeaderLT?: boolean;++ frozenHeaderRT?: boolean;++ frozenHeaderLM?: boolean;++ frozenContent?: boolean;++ infoBar?: boolean;++ formulaBar?: boolean;++ countBar?: boolean;++ sheetBar?: boolean;++ // Whether to show the toolbar+ toolBar?: boolean;++ rightMenu?: boolean;++ contentSplit?: boolean | string;+}diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ToolBarConfig.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ToolBarConfig.tsnew file mode 100644index 0000000000..281b3fd8aa--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/ToolBarConfig.ts@@ -0,0 +1,35 @@+// 基础工具栏配置+export interface BaseToolBarConfig {+ undo?: boolean; // Undo redo+ redo?: boolean; // Undo redo+ paintFormat?: boolean; // Format brush+ currencyFormat?: boolean; // currency format+ percentageFormat?: boolean; // Percentage format+ numberDecrease?: boolean; // 'Decrease the number of decimal places'+ numberIncrease?: boolean; // 'Increase the number of decimal places+ font?: boolean; // 'font'+ moreFormats?: boolean;+ fontSize?: boolean; // 'Font size'+ bold?: boolean; // 'Bold (Ctrl+B)'+ italic?: boolean; // 'Italic (Ctrl+I)'+ strikethrough?: boolean; // 'Strikethrough (Alt+Shift+5)'+ underline?: boolean; // 'Underline (Alt+Shift+6)'+ textColor?: boolean; // 'Text color'+ fillColor?: boolean; // 'Cell color'+ border?: boolean; // 'border'+ horizontalAlignMode?: boolean; // 'Horizontal alignment'+ verticalAlignMode?: boolean; // 'Vertical alignment'+ textWrapMode?: boolean; // 'Wrap mode'+ textRotateMode?: boolean; // 'Text Rotation Mode'+}++// sheet工具栏配置+export interface SheetToolBarConfig extends BaseToolBarConfig {+ mergeCell?: boolean; // 'Merge cells'+}++export interface DocToolBarConfig extends BaseToolBarConfig {}++export interface SlideToolBarConfig extends BaseToolBarConfig {}++export interface ToolBarConfig extends SheetToolBarConfig, DocToolBarConfig, SlideToolBarConfig {}diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/index.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/index.tsnew file mode 100644index 0000000000..77485d17a8--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/ComponentConfig/index.ts@@ -0,0 +1,3 @@+export * from './ToolBarConfig';+export * from './RightMenuConfig';+export * from './ISheetsPluginConfig';diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/IClipboardData.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/IClipboardData.tsnew file mode 100644index 0000000000..36401ff5c4--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/IClipboardData.ts@@ -0,0 +1,4 @@+export interface IClipboardData {+ plain?: string;+ html?: string;+}diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/IDragAndDropData.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/IDragAndDropData.tsnew file mode 100644index 0000000000..d6e80ce70b--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/IDragAndDropData.ts@@ -0,0 +1,16 @@+export interface IDragAndDropData {+ /**+ * drag data item kind, one of: "string", "file"+ */+ kind: string;++ /**+ * MIME type, "text/plain", "image/jpeg"+ */+ type: string;++ /**+ * File object+ */+ file: File;+}diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/PasteType.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/PasteType.tsnew file mode 100644index 0000000000..f20b0b115c--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/PasteType.ts@@ -0,0 +1,4 @@+export interface PasteType {+ type: string;+ result: string | ArrayBuffer | null;+}diff --git a/packages/ui-plugin-sheets/src/Basics/Interfaces/index.ts b/packages/ui-plugin-sheets/src/Basics/Interfaces/index.tsnew file mode 100644index 0000000000..04b5538a4e--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Interfaces/index.ts@@ -0,0 +1,5 @@+export * from './IClipboardData';+export * from './IDragAndDropData';+export * from './PasteType';+export * from './ComponentConfig';+// @endindexdiff --git a/packages/ui-plugin-sheets/src/Basics/Shared/Locale.ts b/packages/ui-plugin-sheets/src/Basics/Shared/Locale.tsnew file mode 100644index 0000000000..7b0d38860e--- /dev/null+++ b/packages/ui-plugin-sheets/src/Basics/Shared/Locale.ts@@ -0,0 +1,143 @@+import { Nullable, Tools } from '@univerjs/core';+import { LocaleType } from '../../Enum';++/**+ * The data structure stored by the Locale class+ */+export type ILocaleOptions = {+ /**+ * Current Locale such as 'en' / 'en-US' / 'zh' / ''zh-CN / 'zh-TW'+ *+ * @remarks+ * See {@link LocaleType| the LocaleType enum} for more details.+ *+ * @defaultValue `LocaleType.EN`+ */+ currentLocale: LocaleType;++ /**+ * The content of international translation, stored in key-value form,+ *+ * @example+ * Locale data like+ * ```json+ * {+ * "en": {+ * "name": "value"+ * },+ * "zh": {+ * "name": "值"+ * }+ * }+ * ```+ */+ locales: object;+};++/**+ * Basic English internationalization object+ *+ * The internationalized language pack of the plug-in will be dynamically loaded in each plug-in.+ */+const zh = {};+const en = {};++/**+ * Internationalization+ *+ * @remarks+ * Get inspiration from the react-intl-universal project, see {@link https://github.com/alibaba/react-intl-universal | the protocol spec}.+ *+ * @beta+ */+export class Locale {+ options: ILocaleOptions;++ constructor(locale: Nullable<LocaleType>) {+ this.options = {+ // use config first, or get language setting from browser+ currentLocale: locale || ['zh', 'zh-CN'].includes(Tools.getLanguage()) ? LocaleType.ZH : LocaleType.EN,+ locales: { zh, en },+ };+ }++ initialize(locale: Nullable<LocaleType>) {+ this.options = {+ // use config first, or get language setting from browser+ currentLocale: locale || ['zh', 'zh-CN'].includes(Tools.getLanguage()) ? LocaleType.ZH : LocaleType.EN,+ locales: { zh, en },+ };+ }++ /**+ * Get the formatted message by key+ *+ * @example+ * ```ts+ * Locale.get('name')+ * ```+ *+ * @param key - The string representing key in Locale data file+ * @returns Get the translation corresponding to the Key+ */+ get(key: string | undefined): string {+ if (key) {+ const { locales, currentLocale } = this.options;+ return (Locale.getValue(locales[currentLocale], key) as string) || '';+ }+ return String();+ }++ getObject<T>(key: string): T {+ const { locales, currentLocale } = this.options;+ return Locale.getValue(locales[currentLocale], key) as unknown as T;+ }++ /**+ * Load more locales after init+ *+ * @example+ * ```ts+ * Locale.load({zh,en})+ * ```+ *+ * @param locales - Locale object+ * @returns void+ *+ */+ load(locales: object): void {+ Tools.deepMerge(this.options.locales, locales);+ }++ /**+ * change Locale+ *+ * @example+ * Change to Chinese+ * ```ts+ * Locale.change(LocaleType.ZH)+ * ```+ *+ * @param locale - Locale Type, see {@link LocaleType}+ *+ */+ change(locale: LocaleType): void {+ this.options.currentLocale = locale;+ }++ /**+ * get value from Locale object and key+ * @param locale - A specified language pack+ * @param key - Specify key+ * @returns Get the translation corresponding to the Key+ *+ * @private+ */+ private static getValue(locale: object, key: string): Nullable<string | object> {+ try {+ return locale[key] ? locale[key] : key.split('.').reduce((a, b) => a[b], locale);+ } catch (error) {+ console.error('Key %s not found', key);+ }+ }+}diff --git a/packages/ui-plugin-sheets/src/Basics/index.ts b/packages/ui-plugin-sheets/src/Basics/index.tsindex 640d1bb8b3..14c41ec033 100644--- a/packages/ui-plugin-sheets/src/Basics/index.ts+++ b/packages/ui-plugin-sheets/src/Basics/index.ts@@ -2,3 +2,4 @@ export * from './Const';export * from './Enum';export * from '../Locale';export * from './Shared';+export * from './Interfaces';diff --git a/packages/ui-plugin-sheets/src/Controller/CellEditorController.ts b/packages/ui-plugin-sheets/src/Controller/CellEditorController.tsnew file mode 100644index 0000000000..cbc1f80ee4--- /dev/null+++ b/packages/ui-plugin-sheets/src/Controller/CellEditorController.ts@@ -0,0 +1,334 @@+import { BaseComponentPlugin } from '../BaseComponentPlugin';+++export class CellEditorController {+ private _plugin: BaseComponentPlugin;++ private _sheetContainer: SheetContainer;++ private _cellEditExtensionManager: CellEditExtensionManager;++ private _keyboardManager: KeyboardManager;++ richTextEle: HTMLElement;++ richTextEditEle: HTMLElement;++ richText: RichText;++ constructor(plugin: BaseComponentPlugin) {+ this._plugin = plugin;++ this._initialize();+ }++ private _initialize() {+ this._plugin.getObserver('onSheetContainerDidMountObservable')?.add((sheetContainer: SheetContainer) => {+ this._initRegisterComponent();++ this._sheetContainer = sheetContainer;+ // const mainItem: IMainProps = {+ // name: 'cellEditor',+ // type: ISlotElement.JSX_STRING,+ // content: 'RichText',+ // show: false,+ // };++ // init RichText component+ this._initRegisterComponent();+ this._plugin.getObserver('onRichTextDidMountObservable')?.add((cellEditor) => {+ this.richTextEle = getRefElement(cellEditor.container);+ this.richTextEditEle = $$('div', this.richTextEle);+ this.richText = cellEditor;++ // // focus+ // this.richTextEditEle.focus();++ // this.focusEditEle();+ this.hideEditContainer();++ // init event+ // this._handleKeyboardAction();+ this._keyboardManager.handleKeyboardAction(this.richTextEditEle);+ this._handleKeyboardObserver();++ // Get the display status of the formula prompt box+ this.richText.hooks.set('onKeyDown', (event: KeyboardEvent) => {+ this._plugin.getObserver('onRichTextKeyDownObservable')?.notifyObservers(event);+ });+ // Get the display status of the formula prompt box+ this.richText.hooks.set('onKeyUp', (event: KeyboardEvent) => {+ this._plugin.getObserver('onRichTextKeyUpObservable')?.notifyObservers(event);+ });+ });+ });++ // If other plugins are loaded asynchronously, they may be initialized after the rendering layer is loaded, and they will not receive obs listeners.+ this._plugin.context+ .getObserverManager()+ .getObserver('onSheetRenderDidMountObservable', 'core')+ ?.add((e) => {+ const main = this._plugin.getMainComponent();++ main.onDblclickObserver.add((evt: IPointerEvent | IMouseEvent) => {+ // Prevent left + right double click+ if (evt.button !== 2) {+ this.enterEditMode();+ }+ });+ main.onPointerDownObserver.add((evt: IPointerEvent | IMouseEvent) => {+ this.exitEditMode();+ evt.preventDefault();+ });+ });++ this._cellEditExtensionManager = new CellEditExtensionManager();++ this._keyboardManager = new KeyboardManager(this._plugin);+ // this.richTextEditEle+ }++ /**+ * Register custom components+ */+ private _initRegisterComponent() {+ // this._plugin.registerComponent(PLUGIN_NAMES.SPREADSHEET + RichText.name, RichText, { activeKey: 'cellEdit' });+ this._plugin.registerModal(`${PLUGIN_NAMES.SPREADSHEET + RichText.name}cell`, RichText);+ this._plugin.registerModal(`${PLUGIN_NAMES.SPREADSHEET + RichText.name}formula`, RichText);+ }++ private _handleKeyboardObserver() {+ const onKeyDownObservable = this._plugin.getContext().getObserverManager().getObserver<KeyboardEvent>('onKeyDownObservable', 'core');+ const onKeyCompositionStartObservable = this._plugin.getContext().getObserverManager().getObserver<CompositionEvent>('onKeyCompositionStartObservable', 'core');++ if (onKeyDownObservable && !onKeyDownObservable.hasObservers()) {+ onKeyDownObservable.add((evt: KeyboardEvent) => {+ if (!evt.ctrlKey && isKeyPrintable(evt.key)) {+ // character key+ this.enterEditMode(true);+ } else {+ // control key+ switch (evt.key) {+ case 'Enter':+ if (this.isEditMode) {+ this.exitEditMode();++ const currentCell = this._plugin.getSelectionManager().getCurrentCellModel();+ if (!currentCell?.isMerged) {+ // move to cell below+ this._plugin.getSelectionManager().move(Direction.BOTTOM);+ }+ } else {+ this.enterEditMode();+ }+ break;++ case 'Space':+ if (!this.isEditMode) {+ this.enterEditMode(true);+ }+ break;++ case 'ArrowUp':+ if (!this.isEditMode) {+ this._plugin.getSelectionManager().move(Direction.TOP);+ }+ break;++ case 'ArrowDown':+ if (!this.isEditMode) {+ this._plugin.getSelectionManager().move(Direction.BOTTOM);+ }+ break;++ case 'ArrowLeft':+ if (!this.isEditMode) {+ this._plugin.getSelectionManager().move(Direction.LEFT);+ }+ break;++ case 'ArrowRight':+ if (!this.isEditMode) {+ this._plugin.getSelectionManager().move(Direction.RIGHT);+ }+ break;++ case 'Tab':+ if (!this.isEditMode) {+ this._plugin.getSelectionManager().move(Direction.RIGHT);+ }+ evt.preventDefault();+ break;++ default:+ break;+ }+ }+ });+ }++ if (onKeyCompositionStartObservable && !onKeyCompositionStartObservable.hasObservers()) {+ onKeyCompositionStartObservable.add((evt: CompositionEvent) => {+ if (!this.isEditMode) {+ this.enterEditMode(true);+ }+ });+ }+ }+++ hideEditContainer() {+ // It cannot be set to 0px, otherwise the paste event cannot be listened+ this.richTextEle.style.maxHeight = '1px';+ this.richTextEle.style.maxWidth = '1px';++ this.richTextEle.style.minWidth = `1px`;+ this.richTextEle.style.minHeight = `1px`;++ this.richTextEle.style.borderWidth = '0px';+ this.richTextEle.style.transform = 'scale(0)';+ }++ /**+ * 1. When a printable character is entered, trigger editing+ * 2. When CompositionStart, trigger editing+ * @param clear Whether to clear the cell+ * @returns+ */+ enterEditMode(clear: boolean = false) {+ this.focusEditEle();+ // setTimeout(() => {+ // this.richTextEditEle.focus();++ // }, 1);++ if (this.isEditMode) return;++ // set focus to last position+ setTimeout(() => {+ setLastCaretPosition(this.richTextEditEle);+ }, 1);++ this.isEditMode = true;++ const currentCell = this._plugin.getSelectionManager().getCurrentCellModel();++ if (!currentCell) {+ return false;+ }++ let startX;+ let endX;+ let startY;+ let endY;++ if (currentCell.isMerged) {+ const mergeInfo = currentCell.mergeInfo;+ startX = mergeInfo.startX;+ endX = mergeInfo.endX;+ startY = mergeInfo.startY;+ endY = mergeInfo.endY;+ } else {+ startX = currentCell.startX;+ endX = currentCell.endX;+ startY = currentCell.startY;+ endY = currentCell.endY;+ }++ const scrollX = this._plugin.getMainScene()?.getViewport(CANVAS_VIEW_KEY.VIEW_TOP)?.actualScrollX || 0;+ const scrollY = this._plugin.getMainScene()?.getViewport(CANVAS_VIEW_KEY.VIEW_LEFT)?.actualScrollY || 0;++ this.richTextEle.style.left = `${startX - scrollX}px`;+ this.richTextEle.style.top = `${startY - scrollY}px`;++ this.richTextEle.style.minWidth = `${endX - startX}px`;+ this.richTextEle.style.minHeight = `${endY - startY}px`;++ this.richTextEle.style.borderWidth = '2px';++ const sheetContentRect = getRefElement(this._sheetContainer.contentRef).getBoundingClientRect();++ this.richTextEle.style.maxWidth = `${sheetContentRect.width - startX + scrollX}px`;+ this.richTextEle.style.maxHeight = `${sheetContentRect.height - startY + scrollY}px`;++ this.richTextEle.style.transform = '';++ // this._plugin.showMainByName('cellEditor', true).then(() => {+ let cellValue = this.getSelectionValue();++ // Intercept, the formula needs to modify the value of the edit state+ const cell = this._cellEditExtensionManager.handle({+ row: currentCell.row,+ column: currentCell.column,+ value: cellValue,+ });++ if (cell) {+ cellValue = cell.value;+ }++ if (clear) {+ cellValue = '';+ }+ this.richText.setValue(cellValue);++ const style = this.getSelectionStyle();++ this.richTextEditEle.style.cssText = '';++ // set cell style+ if (style) {+ this.richTextEditEle.style.cssText = handleStyleToString(style, true);+ }++ // });+ this.setCurrentEditRangeData();+ }++ exitEditMode() {+ this.focusEditEle();++ if (!this.isEditMode) return;++ this.isEditMode = false;+ // this._plugin.showMainByName('cellEditor', false).then(() => {+ const value = handleDomToJson(this.richTextEditEle);+ const text = this.richTextEditEle.innerText;++ let cell: ICellData = {};++ // get value+ if (typeof value === 'string') {+ cell.v = value;+ cell.m = value;+ }+ // get rich text+ else if (typeof value === 'object') {+ cell.p = value;+ cell.v = text;+ cell.m = text;+ }++ // get style+ const style = handleStringToStyle(this.richTextEditEle);+ if (Tools.isPlainObject(style)) {+ cell.s = style;+ }+ this.setCurrentEditRangeValue(cell);+ this.hideEditContainer();+ }++ focusEditEle() {+ // If there is no settimeout, the first letter will be intercepted in Chinese state+ setTimeout(() => {+ this.richTextEditEle.focus();+ }, 100);+ }++ // 获取Toolbar组件+ getComponent = (ref: RichText) => {+ this.richText = ref;+ };+++}diff --git a/packages/ui-plugin-sheets/src/Controller/CountBarController.ts b/packages/ui-plugin-sheets/src/Controller/CountBarController.tsnew file mode 100644index 0000000000..0e4c0901e1--- /dev/null+++ b/packages/ui-plugin-sheets/src/Controller/CountBarController.ts@@ -0,0 +1,28 @@+import { BaseComponentPlugin } from '..';+import { CountBar } from '../UI/CountBar';++export class CountBarController {+ private _plugin: BaseComponentPlugin;++ private _countBar: CountBar;++ constructor(plugin: BaseComponentPlugin) {+ this._plugin = plugin;+ }++ // 获取CountBar组件+ getComponent = (ref: CountBar) => {+ this._countBar = ref;+ // this.setCountBar()+ };++ // changeRatio+ changeRatio(ratio: string) {}++ // 刷新组件+ setCountBar(content: string) {+ this._countBar.setValue({+ content,+ });+ }+}diff --git a/packages/ui-plugin-sheets/src/Controller/InfoBarController.ts b/packages/ui-plugin-sheets/src/Controller/InfoBarController.tsnew file mode 100644index 0000000000..51bfb1ecd4--- /dev/null+++ b/packages/ui-plugin-sheets/src/Controller/InfoBarController.ts@@ -0,0 +1,64 @@+import { BaseComponentPlugin } from '..';+import { InfoBar } from '../UI/InfoBar';++type IProps = {+ locale?: string;+ label?: string;+};++export interface BaseInfoBarProps {+ back: IProps;+ update: IProps;+ save: IProps;+ rename: IProps;+ sheetName: string;+}++export class InfoBarController {+ private _infoBar: InfoBar;++ private _plugin: BaseComponentPlugin;++ private _infoList: BaseInfoBarProps;++ constructor(plugin: BaseComponentPlugin) {+ this._plugin = plugin;++ this._infoList = {+ back: {+ locale: 'info.return',+ },+ update: {+ locale: 'info.detailUpdate',+ },+ save: {+ locale: 'info.detailSave',+ },+ rename: {+ locale: 'info.tips',+ },+ sheetName: 'UniverSheet',+ };+ this._initialize();+ }++ private _initialize() {}++ // 获取Toolbar组件+ getComponent = (ref: InfoBar) => {+ this._infoBar = ref;+ this.resetInfoList(this._infoList);+ };++ resetInfoList(list: BaseInfoBarProps) {+ const locale = this._plugin.getLocale();+ for (let k in list) {+ if (list[k].locale) {+ list[k].label = locale.get(list[k].locale);+ }+ }+ this._infoBar.setInfoList(list);+ }++ renameSheet() {}+}diff --git a/packages/ui-plugin-sheets/src/Controller/RightMenuController.ts b/packages/ui-plugin-sheets/src/Controller/RightMenuController.tsnew file mode 100644index 0000000000..dd42939e1e--- /dev/null+++ b/packages/ui-plugin-sheets/src/Controller/RightMenuController.ts@@ -0,0 +1,80 @@+import { BaseSelectChildrenProps } from '@univerjs/style-univer/src/Components/Select';+import { BaseComponentPlugin, BaseMenuItem, resetDataLabel, RightMenuConfig } from '..';+import { RightMenu } from '../UI/RightMenu';++export interface CustomLabelOptions extends BaseSelectChildrenProps {+ locale?: string;+}++interface CustomLabelProps {+ prefix?: string;+ suffix?: string;+ prefixLocale?: string[] | string;+ suffixLocale?: string[] | string;+ options?: CustomLabelOptions[];+ locale?: string;+ label?: string;+ children?: CustomLabelProps[];+ onKeyUp?: (e: Event) => void;+}++export interface RightMenuProps extends BaseMenuItem {+ locale?: string[];+ customLabel?: {+ name: string;+ props?: CustomLabelProps;+ };+ children?: RightMenuProps[];+ suffix?: string;+ border?: boolean;+}++export class RightMenuController {+ private _plugin: BaseComponentPlugin;++ private _configList: Map<string, RightMenuConfig> = new Map();++ private _rightMenu: RightMenu;++ private _currentConfig: RightMenuConfig = {};++ private _menuList: RightMenuProps[];++ constructor(plugin: BaseComponentPlugin) {+ this._plugin = plugin;++ this._menuList = [+ {+ locale: ['rightClick.insert', 'rightClick.row'],+ onClick: () => {},+ show: this._currentConfig.InsertRow,+ },+ ];++ this._initialize();+ }++ private _initialize() {+ setTimeout(() => {+ this._plugin+ .getUniverContainerController()+ .getContentRef()+ .current?.addEventListener('click', (e) => {+ this._rightMenu.handleContextMenu(e);+ });+ }, 1000);+ }++ // 获取RightMenu组件+ getComponent = (ref: RightMenu) => {+ this._rightMenu = ref;+ this.setMenuList();+ };++ // 刷新+ setMenuList() {+ const locale = this._plugin.getLocale();+ const menuList = resetDataLabel(this._menuList, locale);+ this._rightMenu?.setMenuList(menuList);+ }+}diff --git a/packages/ui-plugin-sheets/src/Controller/SheetBarController.ts b/packages/ui-plugin-sheets/src/Controller/SheetBarController.tsnew file mode 100644index 0000000000..65a2f3a0eb--- /dev/null+++ b/packages/ui-plugin-sheets/src/Controller/SheetBarController.ts@@ -0,0 +1,144 @@+import { Nullable } from '@univerjs/core';+import { BaseComponentPlugin } from '..';+import { BaseMenuItem, BaseUlProps } from '../Components';+import { SheetBar } from '../UI/SheetBar';++interface CustomComponent {+ name: string;+ props?: Record<string, any>;+}++interface SheetUlProps extends BaseUlProps {+ index: string;+ color?: Nullable<string>;+ sheetId: string;+}++interface SheetUl extends BaseMenuItem {+ locale?: string;+ customLabel?: CustomComponent;+ children?: SheetUl[];+}++export class SheetBarControl {+ private _plugin: BaseComponentPlugin;++ private _sheetBar: SheetBar;++ private _sheetUl: SheetUl[];++ private _sheetList: SheetUlProps[];++ private _menuList: SheetUlProps[];++ constructor(plugin: BaseComponentPlugin) {+ this._plugin = plugin;++ this._sheetUl = [+ {+ locale: 'sheetConfig.delete',+ onClick: () => {},+ },+ {+ locale: 'sheetConfig.copy',+ onClick: () => {},+ },+ {+ locale: 'sheetConfig.rename',+ onClick: () => {},+ },+ ];+ }++ private _initializeData() {+ const sheets = [1, 2, 3];+ this._menuList = sheets.map((sheet, index) => ({+ label: `sheet${index + 1}`,+ index: String(index),+ sheetId: '123',+ hidden: 1,+ selected: true,+ onClick: (e: MouseEvent) => {},+ }));+ this._sheetList = sheets+ // .filter((sheet) => {})+ .map((sheet, index) => ({+ sheetId: '123',+ label: `sheet${index + 1}`,+ index: String(index),+ selected: true,+ color: '#abcdef',+ onDown: (e: MouseEvent) => {},+ onClick: (e: MouseEvent) => {},+ }));+ }++ // 获取sheetBar组件+ getComponent = (ref: SheetBar) => {+ this._sheetBar = ref;+ this._initializeData();+ this.setSheetBar();+ };++ setSheetBar() {+ this._sheetBar.setValue({+ menuList: this._menuList,+ sheetUl: this._sheetUl,+ sheetList: this._sheetList,+ });+ }++ /**+ * 选中sheet+ * @param args+ */+ selectSheet(id: string): void {}++ /**+ * 隐藏sheet+ */+ hideSheet(): void {}++ /**+ * 取消隐藏+ */+ unHideSheet(): void {}++ /**+ * 增加sheet+ */+ addSheet(): void {}++ /**+ * 删除sheet+ */+ deleteSheet(): void {}++ /**+ * 向左向右移动sheet+ * @param direct+ */+ moveSheet(direct: string): void {}++ /**+ * 复制sheet+ */+ copySheet(): void {}++ /**+ * 可以更改sheet名+ */+ reNameSheet(): void {}++ /**+ * 重命名sheet+ * @param e+ */+ changeSheetName(e: Event): void {}++ /**+ * Set Sheet Color+ * @param color+ */+ setSheetColor(color: string): void {}+}diff --git a/packages/ui-plugin-sheets/src/Controller/ToolbarController.ts b/packages/ui-plugin-sheets/src/Controller/ToolbarController.tsnew file mode 100644index 0000000000..f877034da6--- /dev/null+++ b/packages/ui-plugin-sheets/src/Controller/ToolbarController.ts@@ -0,0 +1,115 @@+import { UIObserver } from '@univerjs/core';+import { BaseSelectChildrenProps, BaseSelectProps } from '@univerjs/style-univer/src/Components/Select';+import { BaseTextButtonProps } from '@univerjs/style-univer/src/Components/TextButton/TextButton';+import { BaseComponentPlugin } from '../BaseComponentPlugin';+import { SheetToolBarConfig, ToolBarConfig } from '../Basics/Interfaces/ComponentConfig/ToolBarConfig';+import { ToolBar } from '../UI/ToolBar';+import { resetDataLabel } from '../Utils';++// 继承基础下拉属性,添加国际化+export interface BaseToolBarSelectChildrenProps extends BaseSelectChildrenProps {+ locale?: string;+ suffixLocale?: string;+ children?: BaseToolBarSelectChildrenProps[];+}++export interface BaseToolBarSelectProps extends BaseSelectProps {+ locale?: string;+ suffixLocale?: string;+ children?: BaseToolBarSelectChildrenProps[];+}++enum ToolbarType {+ SELECT,+ BUTTON,+}++export interface IToolBarItemProps extends BaseToolBarSelectProps, BaseTextButtonProps {+ show?: boolean; //是否显示按钮+ toolbarType?: ToolbarType;+ locale?: string; //label国际化+ tooltipLocale?: string; //tooltip国际化 TODO: need right label+ tooltip?: string; //tooltip文字+ border?: boolean;+}++export class ToolBarController {+ private _plugin: BaseComponentPlugin;++ private _toolbar: ToolBar;++ private _currentConfig: ToolBarConfig = {};++ private _configList: Map<string, ToolBarConfig> = new Map();++ private _toolList: IToolBarItemProps[];++ constructor(plugin: BaseComponentPlugin) {+ this._plugin = plugin;+ this._toolList = [+ {+ toolbarType: 1,+ tooltipLocale: 'toolbar.undo',+ name: 'undo',+ customLabel: {+ name: 'ForwardIcon',+ },+ show: this._currentConfig.undo,+ onClick: () => {+ console.log('undo click');+ const msg = {+ name: 'undo',+ };+ // sheets-plugin-ui Univer => GlobalContext+ // 插件不必要用+ this._plugin.getContext().getObserverManager().requiredObserver<UIObserver>('onUIChangeObservable', 'core').notifyObservers(msg);+ },+ },+ ];+ }++ // 获取Toolbar组件+ getComponent = (ref: ToolBar) => {+ this._toolbar = ref;+ this.setToolbar();+ };++ // 增加toolbar配置+ addToolbarConfig(id: string, config: SheetToolBarConfig) {+ this._configList.set(id, config);+ this.setCurrentToolbarConfig(id);+ }++ // 删除toolbar配置+ deleteToolbarConfig(id: string) {+ this._configList.delete(id);+ }++ // 设置当前toolbar配置+ setCurrentToolbarConfig(id: string) {+ const config = this._configList.get(id);+ if (!config) return;+ this._currentConfig = config;+ this.modifyToolList(config);+ }++ // 根据配置修改toolList+ modifyToolList(config: ToolBarConfig) {+ for (let i = 0; i < this._toolList.length; i++) {+ this._toolList[i].show = false;+ for (let k in config) {+ if (this._toolList[i].name === k) {+ this._toolList[i].show = true;+ }+ }+ }+ this.setToolbar();+ }++ // 刷新toolbar+ setToolbar() {+ const locale = this._plugin.getLocale();+ const toolList = resetDataLabel(this._toolList, locale);+ this._toolbar.setToolBar(toolList);+ }+}diff --git a/packages/ui-plugin-sheets/src/Controller/UniverContainerController.ts b/packages/ui-plugin-sheets/src/Controller/UniverContainerController.tsnew file mode 100644index 0000000000..72ad916a79--- /dev/null+++ b/packages/ui-plugin-sheets/src/Controller/UniverContainerController.ts@@ -0,0 +1,204 @@+import { InfoBarController, RightMenuController } from '.';+import { BaseComponentRender, BaseComponentSheet } from '../BaseComponent';+import { BaseComponentPlugin } from '../BaseComponentPlugin';+import { UniverConfig } from '../Basics';+import { UniverSheetConfig } from '../Basics/Interfaces/ComponentConfig/UniverSheetConfig';+import { LocaleType } from '../Enum';+import { UI } from '../UI';+import { UniverContainer } from '../UI/UniverContainer';+import { CellEditorController } from './CellEditorController';+import { ToolBarController } from './ToolbarController';+import { CountBarController } from './CountBarController';+import { SheetBarControl } from './SheetBarController';++export class UniverContainerController {+ private _plugin: BaseComponentPlugin;++ private _render: BaseComponentRender;++ private _univerContainer: UniverContainer;++ private _toolbarController: ToolBarController;++ private _cellEditorController: CellEditorController;++ private _infoBarController: InfoBarController;++ private _rightMenuController: RightMenuController;++ private _countBarController: CountBarController;++ private _sheetBarController: SheetBarControl;++ private _config: UniverConfig;++ constructor(plugin: BaseComponentPlugin) {+ this._plugin = plugin;++ this._config = this._plugin.getConfig();++ this._initRegisterComponent();++ this._initialize();++ this._toolbarController = new ToolBarController(this._plugin);+ this._cellEditorController = new CellEditorController(this._plugin);+ this._infoBarController = new InfoBarController(this._plugin);+ this._rightMenuController = new RightMenuController(this._plugin);+ this._countBarController = new CountBarController(this._plugin);+ this._sheetBarController = new SheetBarControl(this._plugin);++ // 初始化UI+ const config = {+ config: this._config,+ changeSkin: this.changeSkin,+ changeLocale: this.changeLocale,+ getComponent: this.getComponent,+ mountCanvas: this.mountCanvas,+ methods: {+ toolbar: {+ getComponent: this._toolbarController.getComponent,+ },+ cellEditor: {+ getComponent: this._cellEditorController.getComponent,+ },+ infoBar: {+ getComponent: this._infoBarController.getComponent,+ renameSheet: this._infoBarController.renameSheet,+ },+ rightMenu: {+ getComponent: this._rightMenuController.getComponent,+ },+ countBar: {+ getComponent: this._countBarController.getComponent,+ },+ sheetBar: {+ getComponent: this._sheetBarController.getComponent,+ addSheet: this._sheetBarController.addSheet,+ selectSheet: this._sheetBarController.selectSheet,+ changeSheetName: this._sheetBarController.changeSheetName,+ },+ },+ };+ UI.create(config);+ }++ // 注册常用icon和组件+ private _initRegisterComponent() {+ // TODO: import 组件+ const component = this._plugin.context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();++ const registerIcon = {+ ForwardIcon: this._render.renderFunction('ForwardIcon'),+ BackIcon: this._render.renderFunction('BackIcon'),+ BoldIcon: this._render.renderFunction('BoldIcon'),+ RightIcon: this._render.renderFunction('RightIcon'),+ ItalicIcon: this._render.renderFunction('ItalicIcon'),+ DeleteLineIcon: this._render.renderFunction('DeleteLineIcon'),+ UnderLineIcon: this._render.renderFunction('UnderLineIcon'),+ TextColorIcon: this._render.renderFunction('TextColorIcon'),+ FillColorIcon: this._render.renderFunction('FillColorIcon'),+ MergeIcon: this._render.renderFunction('MergeIcon'),+ TopBorderIcon: this._render.renderFunction('TopBorderIcon'),+ BottomBorderIcon: this._render.renderFunction('BottomBorderIcon'),+ LeftBorderIcon: this._render.renderFunction('LeftBorderIcon'),+ RightBorderIcon: this._render.renderFunction('RightBorderIcon'),+ NoneBorderIcon: this._render.renderFunction('NoneBorderIcon'),+ FullBorderIcon: this._render.renderFunction('FullBorderIcon'),+ OuterBorderIcon: this._render.renderFunction('OuterBorderIcon'),+ InnerBorderIcon: this._render.renderFunction('InnerBorderIcon'),+ StripingBorderIcon: this._render.renderFunction('StripingBorderIcon'),+ VerticalBorderIcon: this._render.renderFunction('VerticalBorderIcon'),+ LeftAlignIcon: this._render.renderFunction('LeftAlignIcon'),+ CenterAlignIcon: this._render.renderFunction('CenterAlignIcon'),+ RightAlignIcon: this._render.renderFunction('RightAlignIcon'),+ TopVerticalIcon: this._render.renderFunction('TopVerticalIcon'),+ CenterVerticalIcon: this._render.renderFunction('CenterVerticalIcon'),+ BottomVerticalIcon: this._render.renderFunction('BottomVerticalIcon'),+ OverflowIcon: this._render.renderFunction('OverflowIcon'),+ BrIcon: this._render.renderFunction('BrIcon'),+ CutIcon: this._render.renderFunction('CutIcon'),+ TextRotateIcon: this._render.renderFunction('TextRotateIcon'),+ TextRotateAngleUpIcon: this._render.renderFunction('TextRotateAngleUpIcon'),+ TextRotateAngleDownIcon: this._render.renderFunction('TextRotateAngleDownIcon'),+ TextRotateVerticalIcon: this._render.renderFunction('TextRotateVerticalIcon'),+ TextRotateRotationUpIcon: this._render.renderFunction('TextRotateRotationUpIcon'),+ TextRotateRotationDownIcon: this._render.renderFunction('TextRotateRotationDownIcon'),+ SearchIcon: this._render.renderFunction('SearchIcon'),+ ReplaceIcon: this._render.renderFunction('ReplaceIcon'),+ LocationIcon: this._render.renderFunction('LocationIcon'),+ BorderDashDot: this._render.renderFunction('BorderDashDot'),+ BorderDashDotDot: this._render.renderFunction('BorderDashDotDot'),+ BorderDashed: this._render.renderFunction('BorderDashed'),+ BorderDotted: this._render.renderFunction('BorderDotted'),+ BorderHair: this._render.renderFunction('BorderHair'),+ BorderMedium: this._render.renderFunction('BorderMedium'),+ BorderMediumDashDot: this._render.renderFunction('BorderMediumDashDot'),+ BorderMediumDashDotDot: this._render.renderFunction('BorderMediumDashDotDot'),+ BorderMediumDashed: this._render.renderFunction('BorderMediumDashed'),+ BorderThick: this._render.renderFunction('BorderThick'),+ BorderThin: this._render.renderFunction('BorderThin'),+ };++ // 注册自定义组件+ for (let k in registerIcon) {+ this._plugin.getComponentManager().register(k, registerIcon[k]);+ }+ }++ private _initialize() {}++ // 获取container组件+ getComponent = (ref: UniverContainer) => {+ this._univerContainer = ref;+ };++ // 挂载canvas+ mountCanvas = (container: HTMLElement) => {+ // const engine = this._plugin.getPluginByName<RenderEngine>(PLUGIN_NAMES.BASE_RENDER)?.getEngine()!;+ // engine.setContainer(container);+ // new CanvasView(engine, this._plugin.getSheetPlugin());+ // window.addEventListener('resize', () => {+ // engine.resize();+ // });+ // // should be clear+ // setTimeout(() => {+ // engine.resize();+ // }, 0);+ };++ /**+ * Change skin+ * @param {String} lang new skin+ */+ changeSkin = () => {+ // publish+ this._plugin.getObserver('onAfterChangeUISkinObservable')!.notifyObservers();+ };++ /**+ * Change language+ * @param {String} lang new language+ *+ * e: {target: HTMLSelectElement } reference from https://stackoverflow.com/a/48443771+ *+ */+ changeLocale = (locale: string) => {+ this._plugin+ .getContext()+ .getLocale()+ .change(locale as LocaleType);++ // publish+ this._plugin.getObserver('onAfterChangeUILocaleObservable')!.notifyObservers();+ };++ addSheet(config: UniverSheetConfig) {+ this._toolbarController.addToolbarConfig('123', config.toolBarConfig!);+ }++ getContentRef() {+ return this._univerContainer.getContentRef();+ }+}diff --git a/packages/ui-plugin-sheets/src/Controller/index.ts b/packages/ui-plugin-sheets/src/Controller/index.tsindex e69de29bb2..700804ad6c 100644--- a/packages/ui-plugin-sheets/src/Controller/index.ts+++ b/packages/ui-plugin-sheets/src/Controller/index.ts@@ -0,0 +1,4 @@+export * from './InfoBarController';+export * from './RightMenuController';+export * from './ToolbarController';+export * from './UniverContainerController';diff --git a/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsxindex d5a06aa915..1a55416035 100644--- a/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx+++ b/packages/ui-plugin-sheets/src/SheetUIPlugin.tsx@@ -1,22 +1,25 @@-import { Plugin, UniverSheet, UniverDoc, UniverSlide } from '@univerjs/core';+import { Plugin, UniverSheet, Tools } from '@univerjs/core';import { zh, en } from './Locale';-import { SHEET_UI_PLUGIN_NAME } from './Basics/Const/PLUGIN_NAME';import { SheetUIController } from './Controller/SheetUIController';--export interface ISheetsPluginConfig {}+import { DefaultSheetUiConfig, ISheetsPluginConfig, Locale, SHEET_UI_PLUGIN_NAME } from './Basic';export class SheetUIPlugin extends Plugin {private _sheetsController: SheetUIController;+ private _config: ISheetsPluginConfig;++ private _locale: Locale;+constructor(config?: ISheetsPluginConfig) {super(SHEET_UI_PLUGIN_NAME);+ this._config = Tools.deepMerge({}, DefaultSheetUiConfig, config);}static create(config?: ISheetsPluginConfig) {return new SheetUIPlugin(config);}- installTo(univerInstance: UniverSheet | UniverDoc | UniverSlide) {+ installTo(univerInstance: UniverSheet) {univerInstance.installPlugin(this);}diff --git a/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsxnew file mode 100644index 0000000000..ba5c12b091--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/CountBar/CountBar.tsx@@ -0,0 +1,110 @@+import { BaseCountBarProps } from '../../Components';+import { Component, createRef } from '../../Framework';+import styles from './index.module.less';++type CountState = {+ zoom: number;+ content: string;+};++export class CountBar extends Component<BaseCountBarProps, CountState> {+ max = 400;++ min = 0;++ ref = createRef();++ initialize(props: BaseCountBarProps) {+ this.state = {+ zoom: 100,+ content: '',+ };+ }++ setValue = (value: object, fn?: () => void) => {+ this.setState(+ (prevState) => ({+ ...value,+ }),+ fn+ );+ };++ setZoom(zoom: number): void {+ if (zoom !== this.state.zoom) {+ this.setValue({+ zoom,+ });+ this.ref.current.changeInputValue(0, zoom);+ }+ }++ onChange = (e: Event) => {+ let target = e.target as HTMLInputElement;+ this.props.changeRatio?.(target.value);+ this.setValue({ zoom: target.value });+ this.ref.current.changeInputValue(0, target.value);+ };++ handleClick = (e: Event, value: number | string) => {+ this.setValue({ zoom: value });+ };++ addZoom = () => {+ let number = Math.floor(this.state.zoom / 10);+ let value = (number + 1) * 10;+ if (value >= this.max) value = this.max;+ this.setValue({ zoom: value });+ this.props.changeRatio?.(String(value));+ };++ reduceZoom = () => {+ let number = Math.ceil(this.state.zoom / 10);+ let value = (number - 1) * 10;+ if (value <= this.min) value = this.min;+ this.setValue({ zoom: value });+ this.props.changeRatio?.(String(value));+ this.ref.current.changeInputValue(0, value);+ };++ componentDidMount() {+ this.props.getComponent?.(this);+ }++ render(props: BaseCountBarProps, state: CountState) {+ const { zoom, content } = state;+ const ReduceIcon = this.getComponentRender().renderFunction('ReduceIcon');+ const RegularIcon = this.getComponentRender().renderFunction('RegularIcon');+ const Slider = this.getComponentRender().renderFunction('Slider');+ const Button = this.getComponentRender().renderFunction('Button');+ const AddIcon = this.getComponentRender().renderFunction('AddIcon');+ // const PageIcon = this.getComponentRender().renderFunction('PageIcon');+ // const LayoutIcon = this.getComponentRender().renderFunction('LayoutIcon');+ return (+ <div className={styles.countBar}>+ <Button type="text" className={styles.countZoom}>+ {zoom}+ </Button>+ <Button type="text" onClick={this.addZoom}>+ <AddIcon />+ </Button>+ <div className={styles.countSlider}>+ <Slider ref={this.ref} onChange={this.onChange} value={zoom} min={this.min} max={this.max} onClick={this.handleClick} />+ </div>+ <Button type="text" onClick={this.reduceZoom}>+ <ReduceIcon />+ </Button>+ {/* <Button type="text">+ <PageIcon />+ </Button> */}+ {/* <Button type="text">+ <LayoutIcon />+ </Button> */}+ <Button type="text">+ <RegularIcon />+ </Button>+ <span className={styles.countStatistic}>{content}</span>+ </div>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/CountBar/index.module.less b/packages/ui-plugin-sheets/src/View/CountBar/index.module.lessnew file mode 100644index 0000000000..27d3e523f3--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/CountBar/index.module.less@@ -0,0 +1,32 @@+.count-bar {+ display: flex;+ flex-direction: row-reverse;+ // height: 22px;+ border-top: 1px solid var(--border-color-base);+ background-color: var(--bg);+ // line-height: 22px;+ font-size: 12px;++ .btn {+ height: auto;+ padding: 0;+ }++ svg {+ font-size: 21px;+ }++ .count-zoom {+ width: 35px;+ }++ .count-slider {+ width: 100px;+ }++ .count-statistic {+ margin-right: 1em;+ display: flex;+ align-items: center;+ }+}diff --git a/packages/ui-plugin-sheets/src/View/CountBar/index.ts b/packages/ui-plugin-sheets/src/View/CountBar/index.tsnew file mode 100644index 0000000000..2429282b86--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/CountBar/index.ts@@ -0,0 +1 @@+export * from './CountBar';diff --git a/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx b/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsxnew file mode 100644index 0000000000..91338ea350--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/InfoBar/InfoBar.tsx@@ -0,0 +1,69 @@+import { Nullable } from '@univerjs/core';+import { BaseComponentProps, BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';+import { BaseInfoBarProps } from '../../Controller/InfoBarController';+import { Component } from '../../Framework';+import styles from './index.module.less';++interface IState {+ infoList: Nullable<BaseInfoBarProps>;+}++interface IProps extends BaseComponentProps {+ renameSheet: () => void;+}++export class InfoBar extends Component<IProps, IState> {+ private _render: BaseComponentRender;++ initialize() {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();++ this.state = {+ infoList: null,+ };+ }++ componentDidMount() {+ this.props.getComponent?.(this);+ }++ setInfoList(list: BaseInfoBarProps) {+ this.setState({+ infoList: list,+ });+ }++ render() {+ const { renameSheet } = this.props;+ if (!this.state.infoList) return;+ const Button = this._render.renderFunction('Button');+ const Container = this._render.renderFunction('Container');+ const Input = this._render.renderFunction('Input');+ const Tooltip = this._render.renderFunction('Tooltip');+ const DropDownIcon = this._render.renderFunction('DropDownIcon');+ const LogoIcon = this._render.renderFunction('LogoIcon');++ const { back, sheetName, update, save, rename } = this.state.infoList;++ return (+ <Container className={styles.infoDetail}>+ {/* <div style={{ marginRight: '18px' }}>+ <Tooltip title={back.label} placement={'bottom'}>+ <Button className={styles.infoReturn} type="text">+ <DropDownIcon rotate={90} />+ </Button>+ </Tooltip>+ </div> */}+ {/* <LogoIcon style={{ width: '152px', height: '32px' }} /> */}+ <div className={styles.sheetName}>+ <Tooltip title={rename.label} placement={'bottom'}>+ <Input bordered={false} value={sheetName} onBlur={renameSheet} />+ </Tooltip>+ </div>+ <div className={styles.infoDetailUpdate}>{update.label}</div>+ <div className={styles.infoDetailSave}>{save.label}</div>+ </Container>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/InfoBar/index.module.less b/packages/ui-plugin-sheets/src/View/InfoBar/index.module.lessnew file mode 100644index 0000000000..bb3e266e29--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/InfoBar/index.module.less@@ -0,0 +1,44 @@+.info-detail {+ position: relative;+ left: 0;+ top: 0;+ margin: 0;+ padding: 0 17px;+ height: 56px;+ display: flex;+ align-items: center;+ background: var(--bg);+ box-shadow: 0 -1px 0 0 var(--gray-16);+ border-bottom: 1px solid var(--border-color-base);++ .info-return {+ font-size: 16px;+ padding: 0 5px;+ font-size: 14px;+ }++ .univericon.univericon-logo {+ margin-left: 18px;++ svg {+ width: 100%;+ height: 100%;+ }+ }++ .sheet-name {+ margin: 0 auto;+ }++ .info-detail-update {+ color: var(--gray-17);+ font-size: 12px;+ margin-left: 15px;+ }++ .info-detail-save {+ color: var(--gray-7);+ font-size: 12px;+ margin: 0 5px;+ }+}diff --git a/packages/ui-plugin-sheets/src/View/InfoBar/index.ts b/packages/ui-plugin-sheets/src/View/InfoBar/index.tsnew file mode 100644index 0000000000..345955a1ce--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/InfoBar/index.ts@@ -0,0 +1 @@+export * from './InfoBar';diff --git a/packages/ui-plugin-sheets/src/View/InfoBar/infobar-zh.md b/packages/ui-plugin-sheets/src/View/InfoBar/infobar-zh.mdnew file mode 100644index 0000000000..89972db6ef--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/InfoBar/infobar-zh.md@@ -0,0 +1,10 @@+---+category: Components+type: 通用+title: InfoBar+cover: ''+---++## 介绍++最顶部的栏目,包含 logo/项目名diff --git a/packages/ui-plugin-sheets/src/View/RichText/CellTextStyle.ts b/packages/ui-plugin-sheets/src/View/RichText/CellTextStyle.tsnew file mode 100644index 0000000000..488dbf3d24--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RichText/CellTextStyle.ts@@ -0,0 +1,625 @@+import { Color } from '@univerjs/core';+import { $$, selectTextContent, selectTextContentCross, textTrim } from '../../Utils';+import styles from './index.module.less';++interface IStyleSetting {+ bl?: string; // font-weight+ it?: string; // font-style+ ff?: string; // font-family+ fs?: number; // font-size+ fc?: string; // color+ bg?: string; // background+ cl?: string; // text-decoration(Strikethrough)+ un?: string; // border-bottom(Underline)+ // attr is un+ _fontSize?: number;+ _color?: string;+}++/**+ * update rich text style+ */+export class CellTextStyle {+ inlineStyleAffectAttribute: {+ [key: string]: number;+ };++ inlineStyleAffectCssName: {+ [key: string]: number;+ };++ univerToCssName: {+ [key: string]: string;+ };++ editor: HTMLDivElement;++ constructor(ele: HTMLDivElement) {+ this.inlineStyleAffectAttribute = { bl: 1, it: 1, ff: 1, cl: 1, un: 1, fs: 1, fc: 1, bg: 1 };+ this.inlineStyleAffectCssName = { 'font-weight': 1, 'font-style': 1, 'font-family': 1, 'text-decoration': 1, 'border-bottom': 1, 'font-size': 1, color: 1, background: 1 };++ this.univerToCssName = {+ bl: 'font-weight',+ it: 'font-style',+ ff: 'font-family',+ fs: 'font-size',+ fc: 'color',+ bg: 'background',+ cl: 'text-decoration',+ un: 'border-bottom',+ };+ this.editor = ele;+ }++ // TODO:指定单元格更新+ updateFormat(attr: string, foucsStatus: number | string) {+ if (attr in this.inlineStyleAffectAttribute) {+ // TODO: 不要使用 $$+ let value = this.editor.textContent!;+ if (value.substr(0, 1) !== '=') {+ this.updateInlineStringFormat(attr, foucsStatus);+ }+ }+ }++ updateInlineStringFormat(attr: string, value: number | string) {+ let w = window.getSelection();+ let range;+ if (w?.type === 'None') {+ // range = Store.inlineStringEditRange;+ } else {+ range = w?.getRangeAt(0);+ }++ if (!range) return;++ // TODO: 不要使用 $$+ let $textEditor = this.editor;++ let endContainer = range.endContainer;+ let startContainer = range.startContainer;+ let endOffset = range.endOffset;+ let startOffset = range.startOffset;++ if ($textEditor) {+ if (startContainer === endContainer) {+ let span = startContainer.parentNode as HTMLElement;+ let spanIndex;+ let inherit = false;++ let content = span.innerHTML;++ let fullContent = $textEditor.innerHTML;+ if (fullContent.substr(0, 5) !== '<span') {+ inherit = true;+ }++ let left = '';+ let mid = '';+ let right = '';+ let s1 = 0;+ let s2 = startOffset;+ let s3 = endOffset;+ let s4 = content.length;+ left = content.substring(s1, s2);+ mid = content.substring(s2, s3);+ right = content.substring(s3, s4);++ let cont = '';+ if (left !== '') {+ let cssText = span.style.cssText;+ if (inherit) {+ let box = span.closest(`.${styles.richTextEditorContainer}`) as HTMLElement;+ if (box != null) {+ cssText = this.extendCssText(box.style.cssText, cssText);+ }+ }+ cont += `<span style='${cssText}'>${left}</span>`;+ }++ if (mid !== '') {+ let cssText = this.getCssText(span.style.cssText, attr, value);++ if (inherit) {+ let box = span.closest(`.${styles.richTextEditorContainer}`) as HTMLElement;+ if (box != null) {+ cssText = this.extendCssText(box.style.cssText, cssText);+ }+ }++ cont += `<span style='${cssText}'>${mid}</span>`;+ }++ if (right !== '') {+ let cssText = span.style.cssText;+ if (inherit) {+ let box = span.closest(`.${styles.richTextEditorContainer}`) as HTMLElement;+ if (box != null) {+ cssText = this.extendCssText(box.style.cssText, cssText);+ }+ }+ cont += `<span style='${cssText}'>${right}</span>`;+ }++ if ((startContainer.parentNode as HTMLElement).tagName === 'SPAN') {+ spanIndex = $$('span', $textEditor).indexOf(span);+ // spanIndex = $textEditor.find('span').index(span);+ let spanP = span.parentElement?.innerHTML;+ let spanText = span.outerHTML.replace('\\', '');+ const newS = spanP?.replace(spanText, cont);+ span.parentElement!.innerHTML = newS!;+ // span.replaceWith(cont);+ } else {+ spanIndex = 0;+ span.innerHTML = cont;+ }++ let seletedNodeIndex = 0;+ if (s1 === s2) {+ seletedNodeIndex = spanIndex;+ } else {+ seletedNodeIndex = spanIndex + 1;+ }++ selectTextContent($textEditor.querySelectorAll('span')[seletedNodeIndex]);+ } else if ((startContainer.parentNode as HTMLElement).tagName === 'SPAN' && (endContainer.parentNode as HTMLElement).tagName === 'SPAN') {+ let startSpan = startContainer.parentNode as HTMLElement;+ let startSpanIndex;+ let endSpan = endContainer.parentNode as HTMLElement;+ let endSpanIndex;++ startSpanIndex = $$('span', $textEditor).indexOf(startSpan);+ endSpanIndex = $$('span', $textEditor).indexOf(endSpan);+ // startSpanIndex = $textEditor.find('span').index(startSpan);+ // endSpanIndex = $textEditor.find('span').index(endSpan);++ let startContent = (startSpan as HTMLElement).innerHTML;+ let endContent = (endSpan as HTMLElement).innerHTML;+ let sleft = '';+ let sright = '';+ let eleft = '';+ let eright = '';+ let s1 = 0;+ let s2 = startOffset;+ let s3 = endOffset;+ let s4 = endContent.length;++ sleft = startContent.substring(s1, s2);+ sright = startContent.substring(s2, startContent.length);++ eleft = endContent.substring(0, s3);+ eright = endContent.substring(s3, s4);+ let spans = Array.prototype.slice.call($textEditor.querySelectorAll('span'));+ let replaceSpans = spans.slice(startSpanIndex, endSpanIndex + 1);+ let cont = '';+ for (let i = 0; i < startSpanIndex; i++) {+ // let span = spans.get(i),+ let span: HTMLElement = spans[`${i}`];+ let content = span.innerHTML;+ cont += `<span style='${span.style.cssText}'>${content}</span>`;+ }+ if (sleft !== '') {+ cont += `<span style='${startSpan.style.cssText}'>${sleft}</span>`;+ }++ if (sright !== '') {+ let cssText = this.getCssText(startSpan.style.cssText, attr, value);+ cont += `<span style='${cssText}'>${sright}</span>`;+ }++ if (startSpanIndex < endSpanIndex) {+ for (let i = startSpanIndex + 1; i < endSpanIndex; i++) {+ // let span = spans.get(i),+ let span = spans[`${i}`];+ let content = span.innerHTML;+ let cssText = this.getCssText(span.style.cssText, attr, value);+ cont += `<span style='${cssText}'>${content}</span>`;+ }+ }++ if (eleft !== '') {+ let cssText = this.getCssText(endSpan.style.cssText, attr, value);+ cont += `<span style='${cssText}'>${eleft}</span>`;+ }++ if (eright !== '') {+ cont += `<span style='${endSpan.style.cssText}'>${eright}</span>`;+ }++ for (let i = endSpanIndex + 1; i < spans.length; i++) {+ // let span = spans.get(i),+ let span = spans[`${i}`];+ let content = span.innerHTML;+ cont += `<span style='${span.style.cssText}'>${content}</span>`;+ }++ $textEditor.innerHTML = cont;++ // console.log(replaceSpans, cont);+ // replaceSpans.replaceWith(cont);++ let startSeletedNodeIndex;+ let endSeletedNodeIndex;+ if (s1 === s2) {+ startSeletedNodeIndex = startSpanIndex;+ endSeletedNodeIndex = endSpanIndex;+ } else {+ startSeletedNodeIndex = startSpanIndex + 1;+ endSeletedNodeIndex = endSpanIndex + 1;+ }++ // spans = $textEditor.find('span');+ spans = $textEditor.querySelectorAll('span') as unknown as [];++ // selectTextContentCross(spans.get(startSeletedNodeIndex), spans.get(endSeletedNodeIndex));++ selectTextContentCross(spans[`${startSeletedNodeIndex}`], spans[`${endSeletedNodeIndex}`]);+ }+ }+ }++ extendCssText(origin: string, cover: string, isLimit = true) {+ let originArray = origin.split(';');+ let coverArray = cover.split(';');+ let newCss = '';++ let addKeyList = {};+ for (let i = 0; i < originArray.length; i++) {+ let so = originArray[i];+ let isAdd = true;+ so = so.toLowerCase();+ let okey = textTrim(so.substr(0, so.indexOf(':')));++ /* 不设置文字的大小,解决设置删除线等后字体变大的问题 */+ if (okey === 'font-size') {+ continue;+ }++ let ovalue = textTrim(so.substr(so.indexOf(':') + 1));++ if (isLimit) {+ if (!(okey in this.inlineStyleAffectCssName)) {+ continue;+ }+ }++ for (let a = 0; a < coverArray.length; a++) {+ let sc = coverArray[a];+ sc = sc.toLowerCase();+ let ckey = textTrim(sc.substr(0, sc.indexOf(':')));+ let cvalue = textTrim(sc.substr(sc.indexOf(':') + 1));++ if (okey === ckey) {+ newCss += `${ckey}:${cvalue};`;+ isAdd = false;+ continue;+ }+ }++ if (isAdd) {+ newCss += `${okey}:${ovalue};`;+ }++ addKeyList[okey] = 1;+ }++ for (let a = 0; a < coverArray.length; a++) {+ let sc = coverArray[a];+ sc = sc.toLowerCase();+ let ckey = textTrim(sc.substr(0, sc.indexOf(':')));+ let cvalue = textTrim(sc.substr(sc.indexOf(':') + 1));++ if (isLimit) {+ if (!(ckey in this.inlineStyleAffectCssName)) {+ continue;+ }+ }++ if (!(ckey in addKeyList)) {+ newCss += `${ckey}:${cvalue};`;+ }+ }++ return newCss;+ }++ getCssText(cssText: string, attr: string, value: string | number) {+ let styleObj: IStyleSetting = {};+ styleObj[attr] = value;+ if (attr === 'un') {+ let fontColor = this.getClassWithcss(cssText, 'color');+ if (fontColor === '') {+ fontColor = '#000000';+ }+ let fs = this.getClassWithcss(cssText, 'font-size');+ let fsNum = parseInt(fs);+ if (fs === '') {+ fsNum = 11;+ }++ styleObj._fontSize = fsNum;+ styleObj._color = fontColor;+ }+ let s: string | undefined = this.getFontStyleByCell(styleObj, undefined, undefined, false);+ let ukey = textTrim(s && s.substr(0, s.indexOf(':')));+ let uvalue = textTrim(s && s.substr(s.indexOf(':') + 1));+ uvalue = uvalue.substr(0, uvalue.length - 1);+ // let cssText = span.style.cssText;+ cssText = this.removeClassWidthCss(cssText, attr);++ cssText = this.upsetClassWithCss(cssText, ukey, uvalue);++ return cssText;+ }++ getClassWithcss(cssText: string, ukey: string): string {+ let cssTextArray = cssText.split(';');+ if (ukey == null || ukey.length === 0) {+ return cssText;+ }+ if (cssText.indexOf(ukey) > -1) {+ for (let i = 0; i < cssTextArray.length; i++) {+ let s = cssTextArray[i];+ s = s.toLowerCase();+ let key = textTrim(s.substr(0, s.indexOf(':')));+ let value = textTrim(s.substr(s.indexOf(':') + 1));+ if (key === ukey) {+ return value;+ }+ }+ }++ return '';+ }++ removeClassWidthCss(cssText: string, ukey: string) {+ let cssTextArray = cssText.split(';');+ let newCss = '';+ let oUkey = ukey;+ if (ukey == null || ukey.length === 0) {+ return cssText;+ }+ if (ukey in this.univerToCssName) {+ ukey = this.univerToCssName[ukey];+ }+ if (cssText.indexOf(ukey) > -1) {+ for (let i = 0; i < cssTextArray.length; i++) {+ let s = cssTextArray[i];+ s = s.toLowerCase();+ let key = textTrim(s.substr(0, s.indexOf(':')));+ let value = textTrim(s.substr(s.indexOf(':') + 1));+ if (key === ukey || (oUkey === 'cl' && key === 'lucky-strike') || (oUkey === 'un' && key === 'lucky-underline')) {+ continue;+ } else if (key.length > 0) {+ newCss += `${key}:${value};`;+ }+ }+ } else {+ newCss = cssText;+ }++ return newCss;+ }++ upsetClassWithCss(cssText: string, ukey: string, uvalue: string) {+ let cssTextArray = cssText.split(';');+ let newCss = '';+ if (ukey == null || ukey.length === 0) {+ return cssText;+ }+ if (cssText.indexOf(ukey) > -1) {+ for (let i = 0; i < cssTextArray.length; i++) {+ let s = cssTextArray[i];+ s = s.toLowerCase();+ let key = textTrim(s.substr(0, s.indexOf(':')));+ let value = textTrim(s.substr(s.indexOf(':') + 1));+ if (key === ukey) {+ newCss += `${key}:${uvalue};`;+ } else if (key.length > 0) {+ newCss += `${key}:${value};`;+ }+ }+ } else if (ukey.length > 0) {+ cssText += `${ukey}:${uvalue};`;+ newCss = cssText;+ }++ return newCss;+ }++ getFontStyleByCell(cell: IStyleSetting, checksAF: any, checksCF: any, isCheck = true): string {+ if (cell == null) {+ return '';+ }+ let style = '';+ for (let key in cell) {+ let value = cell[key];+ if (isCheck) {+ value = this.checkstatusByCell(cell, key);+ }+ if (key === 'bl' && value !== '0') {+ style += 'font-weight: bold;';+ }++ if (key === 'it' && value !== '0') {+ style += 'font-style:italic;';+ }++ if (key === 'ff') {+ let f = value;+ style += `font-family: ${f};`;+ }++ if (key === 'fs' && value !== '10') {+ style += `font-size: ${value}pt;`;+ }++ if ((key === 'fc' && value !== '#000000') || checksAF != null || (checksCF != null && checksCF.textColor != null)) {+ if (checksCF != null && checksCF.textColor != null) {+ style += `color: ${checksCF.textColor};`;+ } else if (checksAF != null) {+ style += `color: ${checksAF[0]};`;+ } else {+ style += `color: ${value};`;+ }+ }++ if (key === 'bg' && value !== '#ffffff' && value !== '#fff') {+ style += `background: ${value};`;+ }++ if (key === 'cl' && value !== '0') {+ style += 'text-decoration: line-through;';+ }++ if (key === 'un' && (value === '1' || value === '3')) {+ let color = cell._color;+ if (color == null) {+ color = cell.fc;+ }+ let fs = cell._fontSize || 11;+ if (fs == null) {+ fs = cell.fs || 11;+ }+ style += `border-bottom: ${Math.floor(fs / 9)}px solid ${color};`;+ }+ }+ return style;+ }++ checkstatusByCell(cell: IStyleSetting, a: string) {+ // 获取当前单元格配置 默认值+ let foucsStatus: any;+ let tf = { bl: 1, it: 1, ff: 1, cl: 1, un: 1 };++ if (a in tf) {+ if (foucsStatus == null) {+ foucsStatus = '0';+ } else {+ foucsStatus = foucsStatus[a];++ if (foucsStatus == null) {+ foucsStatus = '0';+ }+ }+ } else if (a === 'fc') {+ if (foucsStatus == null) {+ foucsStatus = '#000000';+ } else {+ foucsStatus = foucsStatus[a];++ if (foucsStatus == null) {+ foucsStatus = '#000000';+ }++ if (foucsStatus.indexOf('rgba') > -1) {+ foucsStatus = Color.rgbColorToHexValue(foucsStatus);+ }+ }+ } else if (a === 'bg') {+ if (foucsStatus == null) {+ foucsStatus = null;+ } else {+ foucsStatus = foucsStatus[a];++ if (foucsStatus == null) {+ foucsStatus = null;+ } else if ((foucsStatus as string).toString().indexOf('rgba') > -1) {+ foucsStatus = Color.rgbColorToHexValue(foucsStatus);+ }+ }+ } else if (a.substr(0, 2) === 'bs') {+ if (foucsStatus == null) {+ foucsStatus = 'none';+ } else {+ foucsStatus = foucsStatus[a];+ if (foucsStatus == null) {+ foucsStatus = 'none';+ }+ }+ } else if (a.substr(0, 2) === 'bc') {+ if (foucsStatus == null) {+ foucsStatus = '#000000';+ } else {+ foucsStatus = foucsStatus[a];+ if (foucsStatus == null) {+ foucsStatus = '#000000';+ }+ }+ } else if (a === 'ht') {+ if (foucsStatus == null) {+ foucsStatus = '1';+ } else {+ foucsStatus = foucsStatus[a];+ if (foucsStatus == null) {+ foucsStatus = '1';+ }+ }++ if (['0', '1', '2'].indexOf(foucsStatus.toString()) === -1) {+ foucsStatus = '1';+ }+ } else if (a === 'vt') {+ // 默认垂直居中+ if (foucsStatus == null) {+ foucsStatus = '0';+ } else {+ foucsStatus = foucsStatus[a];+ if (foucsStatus == null) {+ foucsStatus = '0';+ }+ }++ if (['0', '1', '2'].indexOf(foucsStatus.toString()) === -1) {+ foucsStatus = '0';+ }+ } else if (a === 'ct') {+ if (foucsStatus == null) {+ foucsStatus = null;+ } else {+ foucsStatus = foucsStatus[a];+ if (foucsStatus == null) {+ foucsStatus = null;+ }+ }+ } else if (a === 'fs') {+ if (foucsStatus == null) {+ foucsStatus = '10';+ } else {+ foucsStatus = foucsStatus[a];+ if (foucsStatus == null) {+ foucsStatus = '10';+ }+ }+ } else if (a === 'tb') {+ if (foucsStatus == null) {+ foucsStatus = '0';+ } else {+ foucsStatus = foucsStatus[a];+ if (foucsStatus == null) {+ foucsStatus = '0';+ }+ }+ } else if (a === 'tr') {+ if (foucsStatus == null) {+ foucsStatus = '0';+ } else {+ foucsStatus = foucsStatus[a];+ if (foucsStatus == null) {+ foucsStatus = '0';+ }+ }+ } else if (a === 'rt') {+ if (foucsStatus == null) {+ foucsStatus = null;+ } else {+ foucsStatus = foucsStatus[a];+ if (foucsStatus == null) {+ foucsStatus = null;+ }+ }+ }++ return foucsStatus;+ }+}diff --git a/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx b/packages/ui-plugin-sheets/src/View/RichText/RichText.tsxnew file mode 100644index 0000000000..0aa4e9b523--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RichText/RichText.tsx@@ -0,0 +1,182 @@+// import { CellInputHandler } from '@univerjs/sheets-plugin-formula/src/Controller/CellInputHandler';+import { Component, createRef } from '../../Framework';+import { xssDeal } from '../../Utils';+import { CellTextStyle } from './CellTextStyle';+import styles from './index.module.less';+// interface IProps {+// style?: {};+// className?: string;+// onClick?: (e: MouseEvent) => void;+// text?: string;+// }++export interface IRichTextState {}++export interface BaseRichTextProps {+ style?: {};+ className?: string;+ onClick?: (e: MouseEvent) => void;+ text?: string;+}++/**+ *+ * 现在已支持 =A2+B3 公式高亮+ * 设置字体大小+ * TODO:+ * 1. rich text editor 丰富,其他样式+ * 2. 单元格编辑框编辑,实时复制到公式栏+ * 3. 公式栏编辑,实时复制到单元格编辑框+ * 4. 单元格编辑后敲击ENTER,获取刚刚输入的最新内容更新单元格数据(用到2.x updateFormatCell)+ * 5. 单元格编辑框输入公式,实时高亮单元格(下一步:支持高亮范围拖拽)+ * 6. 单元格编辑框输入公式,实时提示公式推荐框+ * 7. 单元格编辑框 其他快捷键支持 ESC、TAB、F4、UP、DOWN、LEFT、RIGHT等+ *+ * Rich Text Cell Editor Component+ */+export class RichText extends Component<BaseRichTextProps, IRichTextState> {+ container = createRef<HTMLDivElement>();++ ref = createRef<HTMLDivElement>();++ cellTextStyle: CellTextStyle;++ hooks = new Map<string, (args: any) => void>();++ initialize(props: BaseRichTextProps) {}++ setValue(value: string) {+ if (this.ref.current) {+ this.ref.current.innerHTML = xssDeal(value);+ }+ }++ getValue(): string {+ return this.ref.current?.innerHTML || '';+ }++ show() {+ this.container.current!.style.display = 'block';+ }++ hide() {+ this.container.current!.style.display = 'none';+ }++ onKeyDown(event: KeyboardEvent) {+ // let ctrlKey = event.ctrlKey;+ // let altKey = event.altKey;+ // let shiftKey = event.shiftKey;+ // let kcode = event.keyCode;++ // execute hooks+ const onKeyDown = this.hooks.get('onKeyDown');+ onKeyDown && onKeyDown(event);++ // stop edit+ if (event.key === 'Enter') {+ event.preventDefault();+ }++ // let $inputbox = $('#universheet-input-box');+ // if (kcode === keycode.ESC && parseInt($('#universheet-input-box').css('top')) > 0) {+ // formula.dontupdate();+ // universheetMoveHighlightCell('down', 0, 'rangeOfSelect');+ // event.preventDefault();+ // } else if (kcode === keycode.ENTER && parseInt($inputbox.css('top')) > 0) {+ // if ($('#universheet-formula-search-c').is(':visible') && formula.searchFunctionCell !== null) {+ // formula.searchFunctionEnter($('#universheet-formula-search-c').find('.universheet-formula-search-item-active'));+ // event.preventDefault();+ // }+ // }+ // else if(kcode === keycode.TAB && parseInt($inputbox.css("top")) > 0){+ // if ($("#universheet-formula-search-c").is(":visible") && formula.searchFunctionCell !== null) {+ // formula.searchFunctionEnter($("#universheet-formula-search-c").find(".universheet-formula-search-item-active"));+ // }+ // else{+ // formula.updatecell(Store.universheetCellUpdate[0], Store.universheetCellUpdate[1]);+ // universheetMoveHighlightCell("right", 1, "rangeOfSelect");+ // }++ // event.preventDefault();+ // }+ // else if (kcode === keycode.F4 && parseInt($inputbox.css("top")) > 0) {+ // formula.setfreezonFuc(event);+ // event.preventDefault();+ // }+ // else if (kcode === keycode.UP && parseInt($inputbox.css("top")) > 0) {+ // formulaMoveEvent("up", ctrlKey, shiftKey,event);+ // }+ // else if (kcode === keycode.DOWN && parseInt($inputbox.css("top")) > 0) {+ // formulaMoveEvent("down", ctrlKey, shiftKey,event);+ // }+ // else if (kcode === keycode.LEFT && parseInt($inputbox.css("top")) > 0) {+ // formulaMoveEvent("left", ctrlKey, shiftKey,event);+ // }+ // else if (kcode === keycode.RIGHT && parseInt($inputbox.css("top")) > 0) {+ // formulaMoveEvent("right", ctrlKey, shiftKey,event);+ // }++ // if (kcode === KeyCode.UP) {+ // let index = this.state.funIndex;+ // if (index !== 0) index--;+ // this.setState({+ // funIndex: index,+ // });+ // } else if (kcode === KeyCode.DOWN) {+ // let index = this.state.funIndex;+ // if (index !== 10) index++;+ // this.setState({+ // funIndex: index,+ // });+ // }+ }++ onKeyUp(event: KeyboardEvent) {+ const onKeyUp = this.hooks.get('onKeyUp');+ onKeyUp && onKeyUp(event);++ // stop edit+ if (event.key === 'Enter') {+ event.preventDefault();+ }+ // if (kcode === KeyCode.DOWN) {+ // this.cellTextStyle.convertSpanToShareString(this.ref.current);+ // }+ }++ /**+ * init+ */+ componentWillMount() {}++ componentDidMount() {+ this.cellTextStyle = new CellTextStyle(this.ref.current!);++ this._context.getObserverManager().getObserver<RichText>('onRichTextDidMountObservable', 'core')?.notifyObservers(this);+ }++ /**+ * destory+ */+ componentWillUnmount() {+ // this._context.getObserverManager().getObserver<WorkBook>('onAfterChangeUILocaleObservable', 'workbook')?.remove(this._localeObserver);+ }++ render(props: BaseRichTextProps, state: IRichTextState) {+ const { style, className = '', onClick, text } = props;+ return (+ <div className={`${styles.richTextEditorContainer} ${className}`} style={style} ref={this.container}>+ <div+ ref={this.ref}+ className={styles.richTextEditor}+ onClick={onClick}+ onKeyDown={this.onKeyDown.bind(this)}+ onKeyUp={this.onKeyUp.bind(this)}+ dangerouslySetInnerHTML={{ __html: text || '' }}+ contentEditable+ ></div>+ </div>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/RichText/index.module.less b/packages/ui-plugin-sheets/src/View/RichText/index.module.lessnew file mode 100644index 0000000000..842a66130f--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RichText/index.module.less@@ -0,0 +1,37 @@+.rich-text-editor-container {+ position: absolute;+ z-index: 1;+ border: 2px #5292f7 solid;++ background-color: rgb(255, 255, 255);+ padding: 0px 2px;+ right: auto;+ overflow-y: auto;+ box-sizing: border-box;+ display: flex;+ font-family: 'Times New Roman';+ font-size: 11pt;+ color: rgb(51, 51, 51);++ text-align: left;+ resize: none;+ white-space: pre-wrap;+ outline: 0;+ box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);+ word-wrap: break-word;++ .rich-text-editor {+ width: 100%;+ // height: 100%; // Don't set the height, otherwise the rich text editor background color will not fill the height+ margin: 0;+ outline: 0;+ cursor: text;+ white-space: pre-wrap;+ .formula-text-color {+ color: black;+ }+ .formula-text-string {+ color: forestgreen;+ }+ }+}diff --git a/packages/ui-plugin-sheets/src/View/RichText/index.ts b/packages/ui-plugin-sheets/src/View/RichText/index.tsnew file mode 100644index 0000000000..735dd7d121--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RichText/index.ts@@ -0,0 +1 @@+export * from './RichText';diff --git a/packages/ui-plugin-sheets/src/View/Render/index.ts b/packages/ui-plugin-sheets/src/View/RichText/rich-text-zh.mdsimilarity index 100%rename from packages/ui-plugin-sheets/src/View/Render/index.tsrename to packages/ui-plugin-sheets/src/View/RichText/rich-text-zh.mddiff --git a/packages/ui-plugin-sheets/src/View/UI/index.ts b/packages/ui-plugin-sheets/src/View/RichText/rich-text.mdsimilarity index 100%rename from packages/ui-plugin-sheets/src/View/UI/index.tsrename to packages/ui-plugin-sheets/src/View/RichText/rich-text.mddiff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsxnew file mode 100644index 0000000000..5abe6f44e9--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenu.tsx@@ -0,0 +1,168 @@+import { IMouseEvent } from '@univerjs/base-render';+import { PLUGIN_NAMES } from '@univerjs/core';+import { BaseComponentPlugin } from '../..';+import { BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';+import { BaseRightMenuProps } from '../../Components';+import { RightMenuProps } from '../../Controller';+import { Component, createRef } from '../../Framework';+import Style from './index.module.less';++interface IState {+ visible: boolean;+ srcElement: any;+ eventType: string | null;+ children: RightMenuProps[];+}++export class RightMenu extends Component<BaseRightMenuProps, IState> {+ ulRef = createRef();++ private _render: BaseComponentRender;++ initialize() {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();++ this.state = {+ visible: false,+ srcElement: null,+ eventType: null,+ children: [],+ };+ }++ root = createRef();++ // 转换成渲染需要的数据+ resetMenuList(children: RightMenuProps[]) {+ const componentManager = this._context.getPluginManager().getPluginByName<BaseComponentPlugin>(PLUGIN_NAMES.BASE_COMPONENT)?.getComponentManager();++ for (let i = 0; i < children.length; i++) {+ const item = children[i];+ if (item.customLabel) {+ const Label = componentManager?.get(item.customLabel.name);++ const props = item.customLabel.props ?? {};+ if (Label) {+ item.label = <Label {...props} />;+ }+ }+ if (item.children) {+ item.children = this.resetMenuList(item.children);+ }+ }++ return children;+ }++ setMenuList(children: RightMenuProps[]) {+ this.setState({+ children: this.resetMenuList(children),+ });+ }++ // TODO:添加到具体的元素+ componentDidMount() {+ this.props.getComponent?.(this);+ // 添加右键点击、点击事件监听+ document.addEventListener('click', this.handleClick);+ }++ componentWillUnmount() {+ // 移除事件监听+ document.removeEventListener('click', this.handleClick);+ }++ // 右键菜单事件+ handleContextMenu = async (event: IMouseEvent, rect?: any, down?: boolean) => {+ event.preventDefault();++ this.setState({ visible: true, srcElement: event.target, eventType: event.type }, () => {+ new Promise<void>((resolve, reject) => {+ this.ulRef.current.showMenu(true);+ resolve();+ }).then(() => {+ // clientX/Y 获取到的是触发点相对于浏览器可视区域左上角距离+ const clickX = !down ? event.clientX : rect.x;+ const clickY = !down ? event.clientY : rect.y;++ // console.log(event);++ // window.innerWidth/innerHeight 获取的是当前浏览器窗口的视口宽度/高度+ const screenW = window.innerWidth;+ const screenH = window.innerHeight;+ // 获取自定义菜单的宽度/高度++ const rootW = this.ulRef.current.base.offsetWidth;+ const rootH = this.ulRef.current.base.offsetHeight;++ // right为true,说明鼠标点击的位置到浏览器的右边界的宽度可以放下菜单。否则,菜单放到左边。+ // bottom为true,说明鼠标点击位置到浏览器的下边界的高度可以放下菜单。否则,菜单放到上边。+ const right = screenW - clickX > rootW;+ const left = !right;+ const bottom = screenH - clickY > rootH;+ const top = !bottom;++ if (right) {+ this.root.current.style.left = `${clickX}px`;+ }++ if (left) {+ this.root.current.style.left = `${clickX - rootW}px`;+ }++ if (bottom) {+ this.root.current.style.top = `${clickY}px`;+ }+ if (top) {+ this.root.current.style.top = `${clickY - rootH}px`;+ }+ });+ });+ };++ // 鼠标单击事件,当鼠标在任何地方单击时,设置菜单不显示+ handleClick = (e: MouseEvent) => {+ const { visible, eventType, srcElement } = this.state;+ if (!this.root.current) return;+ if (eventType === 'click' && srcElement && srcElement.contains(e.target)) {+ return;+ }+ if (this.root.current.contains(e.target)) {+ return;+ }+ if (visible) {+ this.setState({ visible: false });+ }+ };++ // 显示隐藏菜单栏+ showRightMenu(show: boolean) {+ this.ulRef.current.showMenu(show);+ }++ render() {+ if (!this.state.children.length) {+ return;+ }++ const wrapStyles = { ...this.props.style };+ const { visible } = this.state;+ const Menu = this._render.renderFunction('Menu');++ return (+ visible && (+ <div+ ref={this.root}+ className={Style.contextMenu}+ style={wrapStyles}+ onContextMenu={(e) => {+ e.preventDefault();+ }}+ >+ <Menu ref={this.ulRef} menu={this.state.children} onClick={this.handleClick}></Menu>+ </div>+ )+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsxnew file mode 100644index 0000000000..bb3427718e--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuButton.tsx@@ -0,0 +1,34 @@+import { BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';+import { Component } from '../../Framework';++interface IProps {+ label: string;+ children: IPropsChildren[];+}++interface IPropsChildren {+ label: string;+}++export class RightMenuButton extends Component<IProps> {+ private _render: BaseComponentRender;++ initialize() {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();+ }++ render() {+ const { label, children } = this.props;+ const Button = this._render.renderFunction('Button');++ return (+ <div>+ {label}+ {children.map((item: IPropsChildren) => (+ <Button type="primary">{item.label}</Button>+ ))}+ </div>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsxnew file mode 100644index 0000000000..2d80b89e4f--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuInput.tsx@@ -0,0 +1,39 @@+import { BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';+import { Component } from '../../Framework';++interface IProps {+ prefix: string[];+ suffix: string;+ onKeyUp?: (e: Event) => void;+}++export class RightMenuInput extends Component<IProps> {+ private _render: BaseComponentRender;++ initialize() {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();+ }++ handleClick(e: Event) {+ e.stopPropagation();+ }++ handleKeyUp(e: Event) {+ const { onKeyUp } = this.props;+ onKeyUp?.(e);+ }++ render() {+ const { prefix, suffix } = this.props;+ const Input = this._render.renderFunction('Input');++ return (+ <div>+ {prefix}+ <Input onKeyUp={this.handleKeyUp.bind(this)} type="number" placeholder="1" onClick={this.handleClick}></Input>+ {suffix}+ </div>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsxnew file mode 100644index 0000000000..f7ffe30f92--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuItem.tsx@@ -0,0 +1,28 @@+import { BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';+import { Component } from '../../Framework';+import styles from './index.module.less';++interface IProps {+ label: string;+}++export class RightMenuItem extends Component<IProps> {+ private _render: BaseComponentRender;++ initialize() {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();+ }++ render() {+ const { label } = this.props;+ const RightIcon = this._render.renderFunction('RightIcon');++ return (+ <div className={styles.rightMenuItem}>+ {label}+ <RightIcon />+ </div>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuSelect.tsx b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuSelect.tsxnew file mode 100644index 0000000000..13cfb2c2f2--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RightMenu/RightMenuSelect.tsx@@ -0,0 +1,34 @@+import { BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';+import { CustomLabelOptions } from '../../Controller';+import { Component } from '../../Framework';++interface IProps {+ label: string;+ options: CustomLabelOptions[];+}++export class RightMenuSelect extends Component<IProps> {+ private _render: BaseComponentRender;++ initialize() {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();+ }++ render() {+ const { label, options } = this.props;+ const Input = this._render.renderFunction('Input');++ return (+ <div>+ <div>{label}</div>+ <select>+ {options.map((item) => (+ <option>{item.label}</option>+ ))}+ </select>+ <Input type="number" placeholder="2"></Input>+ </div>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/index.module.less b/packages/ui-plugin-sheets/src/View/RightMenu/index.module.lessnew file mode 100644index 0000000000..148b7a60d6--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RightMenu/index.module.less@@ -0,0 +1,50 @@+.context-menu {+ position: fixed;++ left: 0;+ top: 26px;+ background-color: var(--bg);+ box-shadow: var(--box-shadow-base);+ z-index: 100;++ .cols-menu {+ .cols-menuitem {+ text-align: left;+ padding: 6px 25px 6px 25px;++ input {+ width: 40px;+ height: 20px;+ text-align: center;+ margin: 0 3px;+ padding: 0;+ }++ button {+ margin-left: 5px;+ padding: 2px 3px;+ line-height: 12px;+ font-size: 12px;+ }++ .btn {+ height: auto;+ }++ .right-menu-center {+ min-width: auto;+ }+ }+ }++ .right-menu-item {+ position: relative;++ span {+ position: absolute;+ right: -15px;+ top: 50%;+ transform: translateY(-50%);+ }+ }+}diff --git a/packages/ui-plugin-sheets/src/View/RightMenu/index.ts b/packages/ui-plugin-sheets/src/View/RightMenu/index.tsnew file mode 100644index 0000000000..405d194f0f--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/RightMenu/index.ts@@ -0,0 +1,5 @@+export * from './RightMenu';+export * from './RightMenuButton';+export * from './RightMenuInput';+export * from './RightMenuItem';+export * from './RightMenuSelect';diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsxnew file mode 100644index 0000000000..916b9144c6--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBar.tsx@@ -0,0 +1,267 @@+import { Nullable, Observer, PLUGIN_NAMES, Workbook } from '@univerjs/core';+import { Menu } from '@univerjs/style-univer';+import { BaseComponentPlugin } from '../..';+import { BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';+import { SlideTabBar } from '../../Basics/SlideTabBar/SlideTabBar';+import { BaseMenuItem, BaseSheetBarProps } from '../../Components';+import { Component, createRef, RefObject } from '../../Framework';+import styles from './index.module.less';+import { SheetBarMenu } from './SheetBarMenu';++type SheetState = {+ sheetList: BaseSheetBarProps[];+ menuList: BaseSheetBarProps[];+ sheetUl: BaseMenuItem[];+};++export class SheetBar extends Component<BaseSheetBarProps, SheetState> {+ ref = createRef();++ ulRef = createRef();++ sheetContainerRef = createRef();++ slideTabRoot = createRef();++ sheetContentRef = createRef();++ sheetBarContentRef = createRef();++ slideTabBar: SlideTabBar;++ private _render: BaseComponentRender;++ private _localeObserver: Nullable<Observer<Workbook>>;++ private _renderKey: number = 1;++ initialize(props: BaseSheetBarProps) {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();++ this.state = {+ sheetList: [],+ sheetUl: [],+ menuList: [],+ };+ }++ resetLabel(list: any) {+ const componentManager = this._context.getPluginManager().getPluginByName<BaseComponentPlugin>(PLUGIN_NAMES.BASE_COMPONENT)?.getComponentManager();++ for (let i = 0; i < list.length; i++) {+ const item = list[i];++ // 优先寻找自定义组件+ if (item.customLabel) {+ const Label = componentManager?.get(item.customLabel.name);+ if (Label) {+ const props = item.customLabel.props ?? {};+ item.label = <Label {...props} />;+ }+ }++ if (item.children) {+ item.children = this.resetLabel(item.children);+ }+ }+ return list;+ }++ // setstate+ setValue = (value: any, fn?: () => void) => {+ let { sheetList, menuList, sheetUl } = value;+ if (sheetList) {+ sheetList = this.resetLabel(sheetList);+ }+ if (menuList) {+ menuList = this.resetLabel(menuList);+ }+ if (sheetUl) {+ sheetUl = this.resetLabel(sheetUl);+ }+ this.setState((prevState) => ({ ...value }), fn);+ };++ // 点击按钮左右滑动+ scrollLeft = (e: MouseEvent) => {+ this.slideTabBar.getScrollbar().scrollX(this.slideTabBar.getScrollbar().getScrollX() - 50);+ };++ scrollRight = (e: MouseEvent) => {+ this.slideTabBar.getScrollbar().scrollX(this.slideTabBar.getScrollbar().getScrollX() + 50);+ };++ overGrid = () => {};++ // 右击显示菜单+ contextMenu = (e: MouseEvent) => {+ e.preventDefault();+ this.showUlList(e);+ };++ // 显示下拉+ showSelect = (e: MouseEvent, ref: RefObject<Menu>) => {+ e.stopImmediatePropagation();+ const current = ref.current;+ if (current) current.showMenu(true);+ // 点击外部隐藏子组件+ window.addEventListener('click', this.hideSelect);+ };++ // 隐藏下拉+ hideSelect = (e: MouseEvent) => {+ const current = this.ref.current;+ const ulCurrent = this.ulRef.current;+ if (current) current.showMenu(false);+ if (ulCurrent) ulCurrent.showMenu(false);+ window.removeEventListener('click', this.hideSelect);+ };++ // 点击不同sheet页显示ullist+ showUlList = (e: MouseEvent) => {+ new Promise<void>((resolve) => {+ const target = e.currentTarget as HTMLDivElement;+ const id = target.dataset.id as string;+ this.showSelect(e, this.ulRef);+ resolve();+ }).then(() => {+ const currentTarget = (e.currentTarget as HTMLElement).closest(`.${styles.slideTabItem}`);+ if (currentTarget) {+ const currentRect = currentTarget.getBoundingClientRect();+ const left = `${currentRect.left}px`;+ const bottom = `${currentRect.height}px`;+ const ul = this.ulRef.current.base;+ ul.style.left = left;+ ul.style.bottom = bottom;+ ul.style.top = 'auto';+ ul.style.right = 'auto';+ }+ });+ };++ // 重命名sheet+ reNameSheet = (id: string) => {+ const item = this.slideTabBar.getSlideTabItems().find((item) => item.primeval().dataset.id === id);+ if (item) {+ item.editor();+ }+ };++ changeEditable = (e: MouseEvent) => {+ const target = e.target as HTMLDivElement;+ let listener: (event: Event) => void;+ target.contentEditable = 'true';+ target.focus();+ target.addEventListener(+ 'blur',+ (listener = (event) => {+ this.props.changeSheetName?.(e);+ target.contentEditable = 'false';+ target.removeEventListener('blur', listener);+ })+ );+ };++ componentDidUpdate() {+ if (this.slideTabBar) {+ this.slideTabBar.destroy();+ }+ this.slideTabBar = new SlideTabBar({+ slideTabBarClassName: 'univer-slide-tab-bar',+ slideTabBarItemActiveClassName: 'univer-slide-tab-active',+ slideTabBarItemClassName: 'univer-slide-tab-item',+ slideTabBarItemAutoSort: true,+ slideTabRoot: this.slideTabRoot.current,+ onChangeName: (event: Event) => {+ this.props.changeSheetName?.(event);+ },+ onSlideEnd: (event: Event) => {+ this.props.dragEnd?.(this.slideTabBar.getSlideTabItems().map((item) => item.primeval()));+ },+ });+ }++ componentDidMount() {+ this.props.getComponent?.(this);+ }++ // 先生成移动对象的副本,移动对象固定定位,达到边界的时候将副本移位+ time = 0;++ target: any = null;++ cloneTarget: any = null;++ startLeft: number;++ startClientX: number;++ render(props: BaseSheetBarProps, state: SheetState) {+ const { sheetList, menuList, sheetUl } = state;+ const { addSheet, selectSheet } = this.props;++ if (!sheetList.length) return;++ const Button = this._render.renderFunction('Button');+ const AddIcon = this._render.renderFunction('AddIcon');+ const MenuIcon = this._render.renderFunction('MenuIcon');+ const NextIcon = this._render.renderFunction('NextIcon');+ const Menu = this._render.renderFunction('Menu');++ return (+ <div className={styles.sheetBar} ref={this.slideTabRoot}>+ {/* user options button */}+ <div className={styles.sheetBarOptions}>+ <Button className={styles.sheetBarOptionsButton} onClick={addSheet} type="text">+ <AddIcon style={{ fontSize: '20px' }} />+ </Button>+ <Button className={styles.sheetBarOptionsButton} onClick={(e: MouseEvent) => this.ref.current.showMenu(true)} type="text">+ <MenuIcon style={{ fontSize: '20px' }} />+ <SheetBarMenu onClick={selectSheet} menu={menuList} ref={this.ref}></SheetBarMenu>+ </Button>+ </div>++ {/* user slide button */}+ <div className={styles.slideTabBar} ref={this.sheetContainerRef}>+ {sheetList.map((item) => (+ <div+ onMouseDown={item.onDown}+ onClick={item.onClick}+ onContextMenu={this.contextMenu}+ data-id={item.sheetId}+ key={this._renderKey++}+ className={`${styles.slideTabItem} ${item.selected ? styles.slideTabActive : ''}`}+ >+ <div className={`${styles.slideTabContent}`}>+ <div className={`${styles.slideTabDivider}`}></div>+ <div className={`${styles.slideTabTitle}`}>+ <span style={{ padding: '2px 5px 2px 5px' }}>{item.label}</span>+ </div>+ <div className={`${styles.slideTabIcon}`} data-slide-skip="true" style={{ lineHeight: 1 }} data-id={item.sheetId} onClick={this.contextMenu}>+ <NextIcon />+ </div>+ </div>+ <div className={`${styles.slideTabFooter}`}>+ <div className={`${styles.slideTabActiveBar}`} style={item.color ? { background: item.color } : {}}></div>+ </div>+ </div>+ ))}+ </div>++ {/* mouse right button context menu */}+ <Menu className={styles.sheetUl} menu={sheetUl} ref={this.ulRef} />++ {/* prev next scroll button */}+ <div className={`${styles.sheetBarOptions} ${styles.sheetBarScrollButton}`}>+ <Button type="text" className={styles.sheetBarOptionsButton} onClick={this.scrollLeft}>+ <NextIcon rotate={90} style={{ padding: '5px' }} />+ </Button>+ <Button type="text" className={styles.sheetBarOptionsButton} onClick={this.scrollRight}>+ <NextIcon rotate={-90} style={{ padding: '5px' }} />+ </Button>+ </div>+ </div>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsxnew file mode 100644index 0000000000..6493b473b8--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/SheetBar/SheetBarMenu.tsx@@ -0,0 +1,84 @@+import { BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';+import { Component } from '../../Framework';+import { joinClassNames } from '../../Utils';+import styles from './index.module.less';++interface SheetBarMenuItem {+ label?: string;+ hide?: boolean;+ selected?: boolean;+ index?: string;+ sheetId?: string;+ onClick?: (e?: MouseEvent) => void;+}++export interface SheetBarMenuProps {+ menu: SheetBarMenuItem[];+ style?: JSX.CSSProperties;+ onClick?: (e?: MouseEvent) => void;+}++interface IState {+ show: boolean;+}++export class SheetBarMenu extends Component<SheetBarMenuProps, IState> {+ private _render: BaseComponentRender;++ initialize() {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();++ this.state = {+ show: false,+ };+ }++ handleClick(e: MouseEvent, item: SheetBarMenuItem) {+ const { onClick } = this.props;+ if (item.onClick) {+ item.onClick(e);+ }+ onClick?.(e);+ this.showMenu(false);+ window.removeEventListener('click', this.hideMenu);+ }++ hideMenu = () => {+ this.showMenu(false);+ };++ showMenu(show: boolean) {+ this.setState(+ {+ show,+ },+ () => {+ if (show) {+ window.addEventListener('click', this.hideMenu, true);+ }+ }+ );+ }++ render() {+ const { menu, style } = this.props;+ const { show } = this.state;+ const CheckIcon = this._render.renderFunction('CheckIcon');+ const HideIcon = this._render.renderFunction('HideIcon');++ return (+ <ul className={styles.sheetBarMenu} style={{ ...style, display: show ? 'block' : ' none' }}>+ {menu.map((item) => (+ <li onClick={(e) => this.handleClick(e, item)} className={joinClassNames(styles.sheetBarMenuItem, item.hide ? styles.sheetBarMenuItemHide : '')}>+ <span className={styles.sheetBarMenuIcon}>+ {item.hide ? <HideIcon /> : ''}+ {item.selected ? <CheckIcon /> : ''}+ </span>+ {item.label}+ </li>+ ))}+ </ul>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/index.module.css b/packages/ui-plugin-sheets/src/View/SheetBar/index.module.cssnew file mode 100644index 0000000000..93f982d224--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/SheetBar/index.module.css@@ -0,0 +1,171 @@+.sheet-bar {+ position: relative;+ height: 31px;+ display: flex;+ flex-direction: row;+ background-color: var(--bg);+}+.sheet-bar-options {+ border-right: 1px solid var(--border-color-base);+ display: flex;+ flex-direction: row;+ align-items: center;+ padding-right: 5px;+}+.sheet-bar-options-button {+ padding: 0;+ margin: 0;+ border: none;+ height: initial;+ line-height: initial;+ padding-right: 2px;+}+.sheet_bar_scroll_button {+ border: none;+ border-left: 1px solid var(--border-color-base);+ padding-left: 5px;+}+.slide-tab-bar {+ user-select: none;+ max-width: 100%;+ height: 100%;+ display: flex;+ flex-direction: row;+ align-items: center;+ overflow: auto;+ overflow-y: hidden;+ scrollbar-width: none;+}+.slide-tab-bar::-webkit-scrollbar {+ display: none;+}+/**+ 高亮标记+ */+.slide-tab-active {+ position: relative;+}+/**+ Tab Item+*/+.slide-tab-item {+ user-select: none;+ display: flex;+ flex-direction: column;+ justify-content: center;+ cursor: pointer;+ height: 100%;+ background-color: var(--bg);+}+.slide-tab-item:first-child .slide-tab-divider {+ opacity: 0;+}+.slide-tab-item:hover {+ background: #efefef;+}+.slide-tab-item:hover .slide-tab-divider {+ opacity: 0;+}+.slide-tab-item:hover + .slide-tab-item .slide-tab-divider {+ opacity: 0;+}+/**+ 内容区域+*/+.slide-tab-content {+ display: flex;+ flex-direction: row;+ align-items: center;+ flex-grow: 1;+}+.slide-tab-title {+ font-size: 14px;+ color: #676464;+ margin-right: 3px;+ margin-left: 6px;+}+.slide-tab-icon {+ width: 16px;+ height: 16px;+ font-size: 15px;+ color: #a1a1a1;+ margin-right: 6px;+}+.slide-tab-divider {+ width: 1px;+ height: 16px;+ background: var(--border-color-base);+}+.slide-tab-active .slide-tab-content {+ background: #efefef;+ color: #222;+}+.slide-tab-active .slide-tab-divider {+ opacity: 0;+}+.slide-tab-active + .slide-tab-item .slide-tab-divider {+ opacity: 0;+}+/**+ 底部区域+ */+.slide-tab-footer {+ height: auto;+ width: 100%;+ flex-grow: 0;+}+.slide-tab-active-bar {+ height: 2px;+ width: 100%;+}+.slide-tab-active .slide-tab-active-bar {+ background: #d0d0d0;+}+.sheet-ul .cols-menuitem {+ text-align: left;+ padding: 5px 5px 5px 25px;+}+.sheet-ul .select-color-picker-parent .select-item-content {+ width: 100%;+}+.sheet-ul .select-color-picker-parent ul {+ padding: 0;+}+.sheet-ul .select-color-picker-parent .select-color-picker {+ padding: 0;+}+.sheet-ul .select-color-picker-parent .select-color-picker .select-item {+ padding: 0;+}+.sheet-bar-menu {+ position: absolute;+ bottom: 120%;+ left: 0;+ padding: 0;+ border: 1px solid rgba(0, 0, 0, 0.2);+ border-radius: 0;+ transition: opacity 218ms;+ background: var(--bg);+ margin: 0;+ outline: 0;+ z-index: 100;+ box-sizing: border-box;+ user-select: none;+}+.sheet-bar-menu li {+ list-style: none;+}+.sheet-bar-menu .sheet-bar-menu-item {+ position: relative;+ padding: 5px 10px 5px 20px;+}+.sheet-bar-menu .sheet-bar-menu-item .sheet-bar-menu-icon {+ position: absolute;+ left: 5px;+ top: 50%;+ transform: translateY(-50%);+}+.sheet-bar-menu .sheet-bar-menu-item-hide {+ pointer-events: none;+ color: #eee;+}diff --git a/packages/ui-plugin-sheets/src/View/SheetBar/index.module.less b/packages/ui-plugin-sheets/src/View/SheetBar/index.module.lessnew file mode 100644index 0000000000..305ced0125--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/SheetBar/index.module.less@@ -0,0 +1,206 @@+.sheet-bar {+ position: relative;+ height: 31px;+ display: flex;+ flex-direction: row;+ background-color: var(--bg);+}++.sheet-bar-options {+ border-right: 1px solid var(--border-color-base);+ display: flex;+ flex-direction: row;+ align-items: center;+ padding-right: 5px;+}++.sheet-bar-options-button {+ padding: 0;+ margin: 0;+ border: none;+ height: initial;+ line-height: initial;+ padding-right: 2px;+}++.sheet_bar_scroll_button {+ border: none;+ border-left: 1px solid var(--border-color-base);+ padding-left: 5px;+}++.slide-tab-bar {+ user-select: none;+ max-width: 100%;+ height: 100%;+ display: flex;+ flex-direction: row;+ align-items: center;+ overflow: auto;+ overflow-y: hidden;+ scrollbar-width: none;+}++.slide-tab-bar::-webkit-scrollbar {+ display: none;+}++/**+ 高亮标记+ */+.slide-tab-active {+ position: relative;+}++/**+ Tab Item+*/+.slide-tab-item {+ user-select: none;+ display: flex;+ flex-direction: column;+ justify-content: center;+ cursor: pointer;+ height: 100%;+ background-color: var(--bg);+}++.slide-tab-item:first-child .slide-tab-divider {+ opacity: 0;+}++.slide-tab-item:hover {+ background: #efefef;+}++.slide-tab-item:hover .slide-tab-divider {+ opacity: 0;+}++.slide-tab-item:hover+.slide-tab-item .slide-tab-divider {+ opacity: 0;+}++/**+ 内容区域+*/+.slide-tab-content {+ display: flex;+ flex-direction: row;+ align-items: center;+ flex-grow: 1;+}++.slide-tab-title {+ font-size: 14px;+ color: #676464;+ margin-right: 3px;+ margin-left: 6px;+}++.slide-tab-icon {+ width: 16px;+ height: 16px;+ font-size: 15px;+ color: #a1a1a1;+ margin-right: 6px;+}++.slide-tab-divider {+ width: 1px;+ height: 16px;+ background: var(--border-color-base);+}++.slide-tab-active .slide-tab-content {+ background: #efefef;+ color: #222;+}++.slide-tab-active .slide-tab-divider {+ opacity: 0;+}++.slide-tab-active+.slide-tab-item .slide-tab-divider {+ opacity: 0;+}++/**+ 底部区域+ */+.slide-tab-footer {+ height: auto;+ width: 100%;+ flex-grow: 0;+}++.slide-tab-active-bar {+ height: 2px;+ width: 100%;+}++.slide-tab-active .slide-tab-active-bar {+ background: #d0d0d0;+}++.sheet-ul {+ .cols-menuitem {+ text-align: left;+ padding: 5px 5px 5px 25px;+ }++ .select-color-picker-parent {+ .select-item-content {+ width: 100%;+ }++ ul {+ padding: 0;+ }++ .select-color-picker {+ padding: 0;++ .select-item {+ padding: 0;+ }+ }+ }+}++.sheet-bar-menu {+ position: absolute;+ bottom: 120%;+ left: 0;+ padding: 0;+ border: 1px solid rgba(0, 0, 0, 0.2);+ border-radius: 0;+ transition: opacity 218ms;+ background: var(--bg);+ margin: 0;+ outline: 0;+ z-index: 100;+ box-sizing: border-box;+ user-select: none;++ li {+ list-style: none;+ }++ .sheet-bar-menu-item {+ position: relative;+ padding: 5px 10px 5px 20px;++ .sheet-bar-menu-icon {+ position: absolute;+ left: 5px;+ top: 50%;+ transform: translateY(-50%);+ }++ &-hide {+ pointer-events: none;+ color: #eee;+ }+ }+}\ No newline at end of filediff --git a/packages/ui-plugin-sheets/src/View/SheetBar/index.ts b/packages/ui-plugin-sheets/src/View/SheetBar/index.tsnew file mode 100644index 0000000000..327b3d528e--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/SheetBar/index.ts@@ -0,0 +1 @@+export * from './SheetBar';diff --git a/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx b/packages/ui-plugin-sheets/src/View/Slot/Slot.tsxnew file mode 100644index 0000000000..e71ec74dc0--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/Slot/Slot.tsx@@ -0,0 +1,43 @@+import { BaseComponentProps } from '../../BaseComponent';+import { Component } from '../../Framework';++interface IState {+ slotGroup: any[];+}++export class Slot extends Component<BaseComponentProps, IState> {+ refs: any[] = [];++ initialize() {+ this.state = {+ slotGroup: [],+ };+ }++ componentDidMount(): void {+ this.props.getComponent?.(this);+ }++ setSlotGroup(group: any[]) {+ const slotGroup = group.map((item, index) => {+ const Modal = plugin?.getRegisterComponent(item);+ if (Modal) {+ return <Modal ref={(ele: any) => (this.refs[index] = ele)} />;+ }+ return null;+ });++ this.setState({+ modalGroup,+ });+ }++ getModalGroup() {+ return this.refs;+ }++ render() {+ const { modalGroup } = this.state;+ return <>{modalGroup.map((item) => item)}</>;+ }+}diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/Const.ts b/packages/ui-plugin-sheets/src/View/ToolBar/Const.tsnew file mode 100644index 0000000000..76d834f9a7--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/ToolBar/Const.ts@@ -0,0 +1,432 @@+export const FONT_SIZE_CHILDREN = [+ {+ label: '9',+ value: 9,+ },+ {+ label: '10',+ value: 10,+ },+ {+ label: '11',+ value: 11,+ },+ {+ label: '12',+ value: 12,+ },+ {+ label: '14',+ value: 14,+ },+ {+ label: '16',+ value: 16,+ },+ {+ label: '18',+ value: 18,+ },+ {+ label: '20',+ value: 20,+ },++ {+ label: '22',+ value: 22,+ },+ {+ label: '24',+ value: 24,+ },+ {+ label: '26',+ value: 26,+ },+ {+ label: '28',+ value: 28,+ },+ {+ label: '36',+ value: 36,+ },+ {+ label: '48',+ value: 48,+ },+ {+ label: '72',+ value: 72,+ },+];++export const FONT_FAMILY_CHILDREN = [+ {+ locale: 'fontFamily.TimesNewRoman',+ style: { 'font-family': 'Times New Roman' },+ value: 'Times New Roman',+ selected: true,+ },+ {+ locale: 'fontFamily.Arial',+ style: { 'font-family': 'Arial' },+ value: 'Arial',+ },+ {+ locale: 'fontFamily.Tahoma',+ style: { 'font-family': 'Tahoma' },+ value: 'Tahoma',+ },+ {+ locale: 'fontFamily.Verdana',+ style: { 'font-family': 'Verdana' },+ value: 'Verdana',+ },+ {+ locale: 'fontFamily.MicrosoftAccorblack',+ style: { 'font-family': '微软雅黑' },+ value: '微软雅黑',+ },+ {+ locale: 'fontFamily.SimSun',+ style: { 'font-family': '宋体' },+ value: '宋体',+ },+ {+ locale: 'fontFamily.SimHei',+ style: { 'font-family': '黑体' },+ value: '黑体',+ },+ {+ locale: 'fontFamily.Kaiti',+ style: { 'font-family': '楷体' },+ value: '楷体',+ },+ {+ locale: 'fontFamily.FangSong',+ style: { 'font-family': '仿宋' },+ value: '仿宋',+ },+ {+ locale: 'fontFamily.NSimSun',+ style: { 'font-family': '新宋体' },+ value: '新宋体',+ },+ {+ locale: 'fontFamily.STXinwei',+ style: { 'font-family': '华文新魏' },+ value: '华文新魏',+ },+ {+ locale: 'fontFamily.STXingkai',+ style: { 'font-family': '华文行楷' },+ value: '华文行楷',+ },+ {+ locale: 'fontFamily.STLiti',+ style: { 'font-family': '华文隶书' },+ value: '华文隶书',+ },+ {+ locale: 'fontFamily.HanaleiFill',+ style: { 'font-family': 'HanaleiFill' },+ value: 'HanaleiFill',+ },+ {+ locale: 'fontFamily.Anton',+ style: { 'font-family': 'Anton' },+ value: 'Anton',+ },+ {+ locale: 'fontFamily.Pacifico',+ style: { 'font-family': 'Pacifico' },+ value: 'Pacifico',+ },+];++export const BORDER_LINE_CHILDREN = [+ {+ locale: 'borderLine.borderTop',+ customSuffix: {+ name: 'TopBorderIcon',+ },+ value: 'top',+ },+ {+ locale: 'borderLine.borderBottom',+ customSuffix: {+ name: 'BottomBorderIcon',+ },+ value: 'bottom',+ },+ {+ locale: 'borderLine.borderLeft',+ customSuffix: {+ name: 'LeftBorderIcon',+ },+ value: 'left',+ },+ {+ locale: 'borderLine.borderRight',+ customSuffix: {+ name: 'RightBorderIcon',+ },+ value: 'right',+ border: true,+ },+ {+ locale: 'borderLine.borderNone',+ customSuffix: {+ name: 'NoneBorderIcon',+ },+ value: 'none',+ },+ {+ locale: 'borderLine.borderAll',+ customSuffix: {+ name: 'FullBorderIcon',+ },+ value: 'all',+ selected: true,+ },+ {+ locale: 'borderLine.borderOutside',+ customSuffix: {+ name: 'OuterBorderIcon',+ },+ value: 'outside',+ },+ {+ locale: 'borderLine.borderInside',+ customSuffix: {+ name: 'InnerBorderIcon',+ },+ value: 'inside',+ },+ {+ locale: 'borderLine.borderHorizontal',+ customSuffix: {+ name: 'StripingBorderIcon',+ },+ value: 'horizontal',+ },+ {+ locale: 'borderLine.borderVertical',+ customSuffix: {+ name: 'VerticalBorderIcon',+ },+ value: 'vertical',+ },+];++export const BORDER_SIZE_CHILDREN = [+ {+ locale: 'borderLine.borderNone',+ value: '',+ },+ {+ customLabel: {+ name: 'BorderThin',+ },+ value: 'BorderThin',+ },+ {+ customLabel: {+ name: 'BorderHair',+ },+ value: 'BorderHair',+ },+ {+ customLabel: {+ name: 'BorderDotted',+ },+ value: 'BorderDotted',+ },+ {+ customLabel: {+ name: 'BorderDashed',+ },+ value: 'BorderDashed',+ },+ {+ customLabel: {+ name: 'BorderDashDot',+ },+ value: 'BorderDashDot',+ },+ {+ customLabel: {+ name: 'BorderDashDotDot',+ },+ value: 'BorderDashDotDot',+ },+ {+ customLabel: {+ name: 'BorderMedium',+ },+ value: 'BorderMedium',+ },+ {+ customLabel: {+ name: 'BorderMediumDashed',+ },+ value: 'BorderMediumDashed',+ },+ {+ customLabel: {+ name: 'BorderMediumDashDot',+ },+ value: 'BorderMediumDashDot',+ },+ {+ customLabel: {+ name: 'BorderMediumDashDotDot',+ },+ value: 'BorderMediumDashDotDot',+ },+ {+ customLabel: {+ name: 'BorderThick',+ },+ value: 'BorderThick',+ },+];++export const MERGE_CHILDREN = [+ {+ locale: 'merge.all',+ value: 'all',+ },+ {+ locale: 'merge.vertical',+ value: 'vertical',+ },+ {+ locale: 'merge.horizontal',+ value: 'horizontal',+ },+ {+ locale: 'merge.cancel',+ value: 'cancel',+ },+];++export const HORIZONTAL_ALIGN_CHILDREN = [+ {+ locale: 'align.left',+ customSuffix: {+ name: 'LeftAlignIcon',+ },+ value: 1,+ },+ {+ locale: 'align.center',+ selected: true,+ customSuffix: {+ name: 'CenterAlignIcon',+ },+ value: 2,+ },+ {+ locale: 'align.right',+ customSuffix: {+ name: 'RightAlignIcon',+ },+ value: 3,+ },+];++export const VERTICAL_ALIGN_CHILDREN = [+ {+ locale: 'align.top',+ customSuffix: {+ name: 'TopVerticalIcon',+ },+ value: 1,+ },+ {+ locale: 'align.middle',+ customSuffix: {+ name: 'CenterVerticalIcon',+ },+ value: 2,+ },+ {+ locale: 'align.bottom',+ customSuffix: {+ name: 'BottomVerticalIcon',+ },+ value: 3,+ },+];++export const TEXT_WRAP_CHILDREN = [+ {+ locale: 'textWrap.overflow',+ customSuffix: {+ name: 'OverflowIcon',+ },+ value: 1,+ },+ {+ locale: 'textWrap.wrap',+ customSuffix: {+ name: 'BrIcon',+ },+ value: 3,+ },+ {+ locale: 'textWrap.clip',+ customSuffix: {+ name: 'CutIcon',+ },+ value: 2,+ },+];++export const TEXT_ROTATE_CHILDREN = [+ {+ locale: 'textRotate.none',+ customSuffix: {+ name: 'TextRotateIcon',+ },+ value: 0,+ },+ {+ locale: 'textRotate.angleUp',+ customSuffix: {+ name: 'TextRotateAngleUpIcon',+ },+ value: -45,+ },+ {+ locale: 'textRotate.angleDown',+ customSuffix: {+ name: 'TextRotateAngleDownIcon',+ },+ value: 45,+ },+ {+ locale: 'textRotate.vertical',+ customSuffix: {+ name: 'TextRotateVerticalIcon',+ },+ value: 'v',+ },+ {+ locale: 'textRotate.rotationUp',+ customSuffix: {+ name: 'TextRotateRotationUpIcon',+ },+ value: -90,+ },+ {+ locale: 'textRotate.rotationDown',+ customSuffix: {+ name: 'TextRotateRotationDownIcon',+ },+ value: 90,+ },+];diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/DataBar.tsx b/packages/ui-plugin-sheets/src/View/ToolBar/DataBar.tsxnew file mode 100644index 0000000000..f0f4350aa8--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/ToolBar/DataBar.tsx@@ -0,0 +1,22 @@+type BarProps = {+ list: Array<Record<string, string>>;+ img: string;+ onClick?: (item: {}, index: number) => void;+};++export const DataBar = (props: BarProps) => {+ const { list, img, onClick } = props;+ const background = `url(${img}) no-repeat`;++ let handleClick = (item: {}, index: number) => {+ onClick?.call(this, item, index);+ };++ return (+ <div style="display: flex;">+ {list.map((item, index) => (+ <div onClick={() => handleClick(item, index)} style={{ width: '28px', height: '26px', background, backgroundPosition: `${item.x} ${item.y}` }}></div>+ ))}+ </div>+ );+};diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/SingleButton.tsx b/packages/ui-plugin-sheets/src/View/ToolBar/SingleButton.tsxnew file mode 100644index 0000000000..01b41e842d--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/ToolBar/SingleButton.tsx@@ -0,0 +1,68 @@+import { BaseSingleButtonProps, Component, JSXComponent, SingleButtonComponent } from '@univerjs/base-component';+import { Button, Tooltip } from '@univerjs/style-univer';++import styles from './index.module.less';++export interface SingleButtonProps {+ label?: string | JSX.Element;+ icon?: JSX.Element | string | null | undefined;+ tooltip?: string;+ name?: string;+ key?: string;+ onClick?: (...arg: any[]) => void;+ active?: boolean;+ triggerUpdate?: (func: Function) => void;+}+export interface IState {+ active: boolean;+}++class SingleButton extends Component<SingleButtonProps, IState> {+ initialize(props: SingleButtonProps): void {+ // Mount update function, when updating the selection range, the cell formats corresponding to different ranges are different, and the toolbar status and values need to be updated in real time+ const { triggerUpdate, active } = props;+ triggerUpdate && triggerUpdate(this.update.bind(this));++ this.state = {+ active: active || false,+ };+ }++ update(active: boolean) {+ this.setState({ active });+ }++ onClick() {+ this.setState(+ (prevState: IState) => ({+ active: !prevState.active,+ }),+ () => {+ this.props.onClick && this.props.onClick(this.state.active);+ }+ );+ }++ render() {+ const { name, tooltip, label, icon, onClick, key } = this.props;+ const { active } = this.state;+ return (+ <div className={styles.singleButton} key={key}>+ <Tooltip title={tooltip!} placement={'bottom'}>+ <Button type="text" onClick={() => this.onClick()} active={active}>+ {label}+ {icon}+ </Button>+ </Tooltip>+ </div>+ );+ }+}++export class UniverSingleButton implements SingleButtonComponent {+ render(): JSXComponent<BaseSingleButtonProps> {+ return SingleButton;+ }+}++export { SingleButton };diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar-zh.md b/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar-zh.mdnew file mode 100644index 0000000000..4e8d509888--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar-zh.md@@ -0,0 +1,92 @@+---+category: Components+type: 定制+title: ToolBar+subtitle: 工具栏+cover: ''+---++## 介绍++工具栏++## API++工具栏的属性说明如下:++| 属性 | 说明 | 类型 | 默认值 |+| ---------- | --------------------- | --------------------------- | -------------------------- |+| style | 自定义 css 央样式对象 | `JSX.CSSProperties` | - |+| config | 配置项 | `IShowToolBarConfig` | `IShowToolBarConfig` |+| forwardRef | preact refs 引用 | `RefObject<HTMLDivElement>` | - |+| func | 回调挂载 | `object` | `{ addButton: Function; }` |++`IShowToolBarConfig`包含以下配置,默认都为 `true`,可以指定想隐藏的工具栏按钮为`false`++```json+{+ "undoRedo": false, //撤销重做,注意撤消重做是两个按钮,由这一个配置决定显示还是隐藏+ "paintFormat": false, //格式刷+ "currencyFormat": false, //货币格式+ "percentageFormat": false, //百分比格式+ "numberDecrease": false, // '减少小数位数'+ "numberIncrease": false, // '增加小数位数+ "moreFormats": false, // '更多格式'+ "font": false, // '字体'+ "fontSize": false, // '字号大小'+ "bold": false, // '粗体 (Ctrl+B)'+ "italic": false, // '斜体 (Ctrl+I)'+ "strikethrough": false, // '删除线 (Alt+Shift+5)'+ "underline": false, // '下划线 (Alt+Shift+6)'+ "textColor": false, // '文本颜色'+ "fillColor": false, // '单元格颜色'+ "border": false, // '边框'+ "mergeCell": false, // '合并单元格'+ "horizontalAlignMode": false, // '水平对齐方式'+ "verticalAlignMode": false, // '垂直对齐方式'+ "textWrapMode": false, // '换行方式'+ "textRotateMode": false // '文本旋转方式'+}+```++以下这些配置已经分配到各个插件中了++```json+{+ "link": false, // '插入链接'+ "image": false, // '插入图片'+ "chart": false, // '图表'+ "comment": false, //'批注'+ "pivotTable": false, //'数据透视表'+ "function": false, // '公式'+ "frozenMode": false, // '冻结方式'+ "sort": false, // '排序'+ "filter": false, // '筛选'+ "conditionalalFormat": false, // '条件格式'+ "dataValidation": false, // '数据验证'+ "splitColumn": false, // '分列'+ "screenshot": false, // '截图'+ "findAndReplace": false, // '查找替换'+ "protection": false, // '工作表保护'+ "print": false // '打印'+}+```++## 案例++```jsx+import { ToolBar } from '@univerjs/style-univer';++const SheetContainer = () => {+ return (+ <ToolBar+ style={{+ display: layout.toolBar ? 'block' : 'none',+ }}+ config={layout.toolBarConfig!}+ func={{ addButton }}+ ref={this.toolBarRef}+ ></ToolBar>+ );+};+```diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar.md b/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar.mdnew file mode 100644index 0000000000..e69de29bb2diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar.tsx b/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar.tsxnew file mode 100644index 0000000000..c9fb07b03c--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/ToolBar/ToolBar.tsx@@ -0,0 +1,298 @@+import { PLUGIN_NAMES } from '@univerjs/core';+import { Select, TextButton } from '@univerjs/style-univer';+import { BaseComponentProps, BaseComponentRender, BaseComponentSheet } from '../../BaseComponent';+import { BaseComponentPlugin } from '../../BaseComponentPlugin';+import { IToolBarItemProps } from '../../Controller/ToolbarController';+import { Component, createRef } from '../../Framework';+import { debounce } from '../../Utils';+import styles from './index.module.less';++interface IProps extends BaseComponentProps {+ style?: JSX.CSSProperties;+ toolList: IToolBarItemProps[];+}++interface IState {+ toolList: IToolBarItemProps[];+ moreToolList: IToolBarItemProps[];+ defaultToolList: IToolBarItemProps[];+ showMore: boolean;+ toolbarListWidths: number[];+ moreText: Record<string, string>;+}++export class ToolBar extends Component<IProps, IState> {+ toolbarRef = createRef();++ moreBtnRef = createRef();++ moreToolRef = createRef();++ SelectRef = createRef();++ private _render: BaseComponentRender;++ clientWidth = 0;++ initialize() {+ const component = this._context.getPluginManager().getPluginByName<BaseComponentSheet>('ComponentSheet')!;+ this._render = component.getComponentRender();+ this.state = {+ // Button contains main button and drop down arrow, translation file contains main and right+ showMore: false,+ toolList: [],+ defaultToolList: [],+ moreToolList: [],+ toolbarListWidths: [],+ moreText: {},+ };+ }++ /**+ * show more tool buttons+ *+ * TODO : 点击其他地方需要隐藏more buttons+ */+ showMore = () => {+ let showMore = this.state.showMore;+ this.setState({ showMore: !showMore });++ if (!showMore) {+ document.addEventListener('click', this.hide, true);+ }+ };++ hide = (e: Event) => {+ if (this.moreToolRef.current.contains(e.target)) return;+ e.stopImmediatePropagation();+ this.setState({ showMore: false });+ document.removeEventListener('click', this.hide, true);+ };++ /**+ * Gets the distance of each button from the parent element+ */+ debounceSetToolbarListWidth = debounce(() => {+ this.setToolbarListWidth();+ }, 50);++ setToolbarListWidth = () => {+ if (!this.clientWidth) {+ this.clientWidth = document.documentElement.clientWidth;+ }+ const list = this.toolbarRef.current.querySelectorAll(`.${styles.toolbarWarp} > div`);+ const moreButtonWidth = this.moreBtnRef.current.clientWidth;+ let width = 60 + moreButtonWidth;+ let index = null;++ const clientWidth = document.documentElement.clientWidth;+ if (clientWidth <= this.clientWidth) {+ // 向左resize+ this.clientWidth = clientWidth;+ for (let i = 0; i < list.length; i++) {+ width += list[i].clientWidth + 6;++ if (width > clientWidth) {+ index = i;+ break;+ }+ }+ if (index !== null) {+ this.setState(+ {+ defaultToolList: this.state.toolList.slice(0, index),+ moreToolList: index ? this.state.toolList.slice(index) : [],+ },+ () => {+ this.resetUl();+ this.forceUpdate();+ }+ );+ }+ } else {+ // 向右resize+ this.clientWidth = clientWidth;+ if (this.state.moreToolList.length) {+ let toolWidth = 30 + moreButtonWidth;+ for (let i = 0; i < list.length; i++) {+ toolWidth += list[i].clientWidth + 6;+ }++ const moreList = this.moreToolRef.current.querySelectorAll(`.${styles.moreTool} > div`);+ let moreIndex = null;+ let last = false; //最后一个元素++ for (let i = 0; i < moreList.length; i++) {+ toolWidth += moreList[i].clientWidth + 6;++ if (toolWidth > clientWidth) {+ moreIndex = i;+ break;+ } else if (i === moreList.length - 1) {+ moreIndex = i;+ last = true;+ }+ }++ if (moreIndex !== null) {+ this.setState(+ {+ defaultToolList: this.state.defaultToolList.concat(this.state.moreToolList.slice(0, last ? moreIndex + 1 : moreIndex)),+ moreToolList: last ? [] : this.state.moreToolList.slice(moreIndex),+ },+ () => {+ this.resetUl();+ this.forceUpdate();+ }+ );+ }+ }+ }+ };++ resetLabel = (toolList: any[]) => {+ const componentManager = this._context.getPluginManager().getPluginByName<BaseComponentPlugin>(PLUGIN_NAMES.BASE_COMPONENT)?.getComponentManager();++ for (let i = 0; i < toolList.length; i++) {+ const item = toolList[i];++ // 优先寻找自定义组件+ if (item.customLabel) {+ const Label = componentManager?.get(item.customLabel.name);+ if (Label) {+ const props = item.customLabel.props ?? {};+ item.label = <Label {...props} />;+ }+ }++ if (item.customSuffix) {+ const Suffix = componentManager?.get(item.customSuffix.name);+ if (Suffix) {+ const props = item.customSuffix.props ?? {};+ item.suffix = <Suffix {...props} />;+ }+ }++ if (item.children) {+ item.children = this.resetLabel(item.children);+ }+ }+ return toolList;+ };++ // setToolBar = (toolList: any[], moreText: Record<string, string>) => {+ // toolList = this.resetLabel(toolList);++ // this.setState(+ // {+ // toolList,+ // defaultToolList: toolList,+ // moreText,+ // },+ // () => {+ // this.setToolbarListWidth();+ // }+ // );+ // };++ setToolBar = (toolList: any[]) => {+ toolList = this.resetLabel(toolList);++ this.setState(+ {+ toolList,+ defaultToolList: toolList,+ },+ () => {+ this.setToolbarListWidth();+ }+ );+ };++ resetUl = () => {+ const wrapper = this._context.getPluginManager().getPluginByName<BaseComponentPlugin>(PLUGIN_NAMES.BASE_COMPONENT)?.getUniverContainerController().getContentRef().current!;+ const height = `${(wrapper as HTMLDivElement).offsetHeight}px`;+ const ul = this.toolbarRef.current.querySelectorAll('ul');+ for (let i = 0; i < ul.length; i++) {+ ul[i].style.maxHeight = height;+ }+ };++ componentDidMount() {+ this.props.getComponent?.(this);+ window.addEventListener('resize', this.debounceSetToolbarListWidth);+ }++ componentWillUnmount() {+ window.removeEventListener('resize', this.debounceSetToolbarListWidth);+ }++ // 渲染dom+ getToolBarList(list: IToolBarItemProps[]) {+ const Tooltip = this._render.renderFunction('Tooltip');++ return list.map((item) => {+ if (item.toolbarType) {+ if (item.show) {+ return (+ <Tooltip title={item.tooltip} placement={'bottom'}>+ <TextButton active={item.active} label={item.label} onClick={item.onClick}></TextButton>+ </Tooltip>+ );+ }+ } else {+ if (item.show) {+ return (+ <Select+ tooltip={item.tooltip}+ type={item.type}+ display={item.display}+ children={item.children}+ customLabel={item.customLabel}+ customSuffix={item.customSuffix}+ label={item.label}+ onClick={item.onClick}+ onKeyUp={item.onKeyUp}+ defaultColor={item.defaultColor}+ hideSelectedIcon={item.hideSelectedIcon}+ className={item.className}+ ></Select>+ );+ }+ }+ return null;+ });+ }++ render() {+ const { defaultToolList, moreToolList, moreText, showMore } = this.state;++ const Button = this._render.renderFunction('Button');+ const Container = this._render.renderFunction('Container');+ const Tooltip = this._render.renderFunction('Tooltip');++ return (+ <Container style={{ position: 'relative' }}>+ <div className={`${styles.toolbarWarp} ${styles.toolbar}`} ref={this.toolbarRef}>+ {this.getToolBarList(defaultToolList)}++ <div ref={this.moreBtnRef} className={styles.moreButton} style={{ visibility: moreToolList.length ? 'visible' : 'hidden' }}>+ <Tooltip title={moreText.tip} placement={'bottom'}>+ <Button type="text" onClick={this.showMore}>+ <div style={{ fontSize: '14px' }}>{moreText.more}</div>+ </Button>+ </Tooltip>+ </div>+ </div>++ {moreToolList.length ? (+ <div style={{ visibility: showMore ? 'visible' : 'hidden' }} className={`${styles.moreTool} ${styles.toolbar}`} ref={this.moreToolRef}>+ {this.getToolBarList(moreToolList)}+ </div>+ ) : (+ ''+ )}+ </Container>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/index.less b/packages/ui-plugin-sheets/src/View/ToolBar/index.lessnew file mode 100644index 0000000000..ce9e6d429b--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/ToolBar/index.less@@ -0,0 +1,310 @@+.universheet-wa-editor.toolbar {+ height: 32px;+ background: var(--bg);+ position: relative;+ padding: 5px 0 3px 15px;+ border-bottom: 1px solid var(--bg);+ white-space: nowrap;+ transition: all 0.2s;+ box-sizing: initial;++ span[role='img'] {+ font-size: 24px;+ display: inline-block;+ }++ span[role='img'].univericon-nextIcon {+ font-size: 13px;+ }++ span[role='img'].univericon-rightIcon {+ font-size: 13px;+ }++ .universheet-toolbar-left-skin {+ width: 15px;+ position: absolute;+ left: 0;+ top: 1px;+ bottom: 1px;+ }++ .universheet-inline-block {+ display: inline-block;+ }++ .universheet-flex {+ display: flex;+ }++ .universheet-toolbar-button,+ .universheet-toolbar-menu-button {+ vertical-align: middle;++ &:hover {+ background: rgba(0, 0, 0, 0.06);+ }++ button {+ min-width: 26px;+ height: 26px;+ padding: 0;+ border: none;+ .toolbar-button();++ span {+ height: 100%;+ vertical-align: text-bottom;+ }+ }+ }++ .universheet-toolbar-button-outer-box,+ .universheet-toolbar-menu-button-outer-box {+ .outer-inner-box();+ }++ .universheet-toolbar-select {+ position: relative;+ }++ .universheet-toolbar-button-inner-box,+ .universheet-toolbar-menu-button-inner-box {+ padding: 0 2px;+ padding: 0;+ text-align: center;+ height: 26px;+ min-width: 26px;+ font-size: 12px;+ }++ .universheet-toolbar-menu-button-caption {+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ margin-left: 1px;+ text-align: center;+ height: 100%;+ }++ .universheet-toolbar-menu-button-text {+ width: 55px !important;+ }++ .universheet-toolbar-separator {+ line-height: normal;+ list-style: none;+ outline: 0;+ overflow: hidden;+ padding: 0;+ text-decoration: none;+ width: 0;+ height: 20px;+ vertical-align: top;+ border-left: 1px solid #e0e0e0;+ margin: 5px 1px;+ }++ .universheet-toolbar-combo-button {+ font-weight: 700;+ vertical-align: inherit;+ margin: 0 1px;+ .toolbar-button();+ }++ .universheet-toolbar-combo-button-inner-box,+ .universheet-toolbar-combo-button-outer-box {+ .outer-inner-box();+ }++ .universheet-toolbar-zoom-combobox .universheet-toolbar-combo-button-caption {+ width: 36px !important;+ }++ .universheet-toolbar-combo-button-caption {+ padding: 0;+ margin: 0 0 0 -3px;+ }++ .universheet-toolbar-textinput {+ -webkit-border-radius: 1px;+ -moz-border-radius: 1px;+ border-radius: 1px;+ border: 1px solid #d9d9d9;+ border-top: 1px solid silver;+ font-size: 13px;+ height: 25px;+ padding: 1px 0 1px 8px;+ }++ .universheet-toolbar-combo-button-input {+ background: 0 0;+ border: 1px solid transparent !important;+ color: var(--text-color);+ font-family: Arial, sans-serif !important;+ font-size: 11px !important;+ font-weight: 700 !important;+ height: 20px !important;+ overflow: hidden !important;+ color: rgba(0, 0, 0, 0.7);+ height: 22px !important;+ width: 22px;+ }++ .universheet-cols-menu {+ .menu-button();+ width: 252px;+ left: 0;+ top: 26px;+ display: none;+ }++ .universheet-cols-menu .universheet-cols-menuitem-hover,+ .universheet-cols-menu .universheet-cols-menuitem:hover {+ background-color: #efefef;+ }++ .universheet-cols-menu .universheet-cols-menuitem {+ position: relative;+ color: var(--text-color);+ cursor: pointer;+ list-style: none;+ margin: 0;+ padding: 1px 6em 1px 20px;+ white-space: nowrap;+ padding-left: 8px;+ vertical-align: middle;+ padding-right: 24px;+ user-select: none;+ line-height: 16px;+ }++ .universheet-submenu-arrow {+ -webkit-transition: all 218ms;+ -moz-transition: all 218ms;+ -o-transition: all 218ms;+ transition: all 218ms;+ font-size: 12px;+ left: auto;+ right: 15px;+ top: 50%;+ transform: translateY(-50%);+ padding-right: 0;+ position: absolute;+ text-align: right;+ opacity: 0.5;+ color: #000;+ user-select: none;+ font-family: Arial;+ }++ .universheet-toolbar-dblbutton {+ .universheet-toolbar-next-button {+ border-left: 1px solid transparent;+ position: relative;++ .universheet-next-menu {+ position: absolute;+ z-index: 100;+ background-color: #fff;+ box-shadow: var(--box-shadow-base);+ font-size: 12px;+ width: fit-content;++ .univer-menu-item > div {+ width: 100%;+ display: flex;+ justify-content: space-between;+ box-sizing: border-box;+ padding: 0 5px 0 0;++ .universheet-next-menu-icon {+ width: 25px;++ & ~ div {+ flex: 1;+ display: flex;+ justify-content: space-between;+ align-items: center;+ }+ }+ }++ svg {+ font-size: 24px;+ vertical-align: top;+ }+ }++ svg {+ font-size: 12px;+ vertical-align: middle;+ }+ }++ .universheet-color-bottom {+ width: 10px;+ margin: 0 auto;+ outline: 2px solid;+ position: relative;+ bottom: 7px;+ }++ button.univer-btn {+ min-width: 15px;++ &:active {+ background: transparent !important;+ }+ }++ :hover .universheet-toolbar-next-button {+ border-left: 1px solid #e0e0e0;+ }+ }+}++// 重复样式+.outer-inner-box() {+ border: 0;+ vertical-align: top;+ margin: 0;+ padding: 0;+}++.toolbar-button() {+ -webkit-border-radius: 2px;+ -moz-border-radius: 2px;+ border-radius: 2px;+ -webkit-user-select: none;+ -moz-user-select: none;+ -ms-user-select: none;+ background: 0;+ border: 1px solid transparent;+ outline: 0;+ padding: 0;+ list-style: none;+ font-size: 11px;+ text-decoration: none;+ cursor: default;+ height: 26px;+ line-height: 26px;+ color: var(--text-color);+}++.menu-button() {+ border-radius: 0;+ box-shadow: 0 2px 4px rgb(0 0 0 / 20%);+ transition: opacity 218ms;+ background: #fff;+ border: 1px solid rgba(0, 0, 0, 0.2);+ cursor: default;+ font-size: 13px;+ margin: 0;+ outline: 0;+ padding: 6px 0;+ position: absolute;+ z-index: 100;+ box-sizing: border-box;+ user-select: none;+}diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/index.module.css b/packages/ui-plugin-sheets/src/View/ToolBar/index.module.cssnew file mode 100644index 0000000000..8245552da9--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/ToolBar/index.module.css@@ -0,0 +1,98 @@+.toolbar-warp {+ max-height: fit-content;+ width: 100%;+ overflow: unset;+ box-sizing: border-box;+ font-size: var(--font-size);+ background-color: var(--bg);+ position: relative;+ display: flex;+ align-items: center;+ border-bottom: 1px solid var(--border-color-base);+}+.toolbar-warp .single-button.more-hide {+ display: none;+}+.toolbar-warp .single-button.more-show {+ display: block;+}+.toolbar {+ max-width: 100%;+ color: var(--text-color);+ padding: 0 15px;+ height: 40px;+ position: relative;+ display: flex;+ align-items: center;+}+.toolbar > div {+ height: 26px;+ display: inline-block;+ vertical-align: middle;+ margin: 0 3px;+ cursor: pointer;+}+.toolbar > div.select-button:hover {+ background-color: #efefef;+}+.toolbar .cols-menu {+ overflow-y: auto;+}+.toolbar .select-label-string .drop-content > div {+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ width: 90px;+}+.toolbar .select-double-string .drop-content > div {+ width: 24px;+}+.toolbar .select-color-picker-parent .select-item-content {+ width: 100%;+}+.toolbar .select-color-picker-parent ul {+ padding: 0;+}+.toolbar .select-color-picker-parent .select-color-picker {+ padding: 0;+}+.toolbar .select-color-picker-parent .select-color-picker .select-item {+ padding: 0;+}+.toolbar .select-line-bold-parent .select-item-content {+ width: 100%;+}+.toolbar button {+ padding: 0;+ height: 26px;+}+.toolbar span[role='img'].univericon-nextIcon {+ font-size: 12px;+}+.more-button {+ position: absolute;+ right: 15px;+ top: 50%;+ transform: translateY(-50%);+ padding: 0px;+ line-height: 1;+}+.more-button.more-show {+ display: block;+}+.more-tool {+ padding: 0 10px;+ background-color: var(--bg);+ box-shadow: var(--box-shadow-base);+ position: absolute;+ right: 2em;+ top: 40px;+ z-index: 100;+}+.more-tool.more-show {+ display: flex;+}+.more-tool button {+ padding: 0px;+ line-height: 1;+}diff --git a/packages/ui-plugin-sheets/src/View/ToolBar/index.module.less b/packages/ui-plugin-sheets/src/View/ToolBar/index.module.lessnew file mode 100644index 0000000000..9a11e2623e--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/ToolBar/index.module.less@@ -0,0 +1,139 @@+.toolbar-warp {+ max-height: fit-content;+ width: 100%;+ overflow: unset;+ box-sizing: border-box;+ font-size: var(--font-size);+ background-color: var(--bg);+ position: relative;+ display: flex;+ align-items: center;+ border-bottom: 1px solid var(--border-color-base);++ .single-button {+ &.more-hide {+ display: none;+ }++ &.more-show {+ display: block;+ }+ }+}++.toolbar {+ max-width: 100%;+ color: var(--text-color);+ padding: 0 15px;+ height: 40px;+ position: relative;+ display: flex;+ align-items: center;++ >div {+ height: 26px;+ display: inline-block;+ vertical-align: middle;+ margin: 0 3px;+ cursor: pointer;++ &.select-button:hover {+ background-color: #efefef;+ }+ }++ .cols-menu {+ overflow-y: auto;+ }++ .select-label-string {+ .drop-content {+ >div {+ overflow: hidden;+ text-overflow: ellipsis;+ white-space: nowrap;+ width: 90px;+ }+ }+ }++ .select-double-string {+ .drop-content {+ >div {+ width: 24px;+ }+ }+ }++ .select-color-picker-parent {+ .select-item-content {+ width: 100%;+ }++ ul {+ padding: 0;+ }++ .select-color-picker {+ padding: 0;++ .select-item {+ padding: 0;+ }+ }+ }++ .select-line-bold-parent {+ .select-item-content {+ width: 100%;+ }+ }++ button {+ padding: 0;+ height: 26px;+ }++ span[role='img'].univericon-nextIcon {+ font-size: 12px;+ }+}++.more-button {+ position: absolute;+ right: 15px;+ top: 50%;+ transform: translateY(-50%);+ .button();++ &.more-show {+ display: block;+ }+}++.more-tool {+ // height: 40px;+ // display: none;+ // align-items: center;+ padding: 0 10px;+ background-color: var(--bg);+ box-shadow: var(--box-shadow-base);+ position: absolute;+ right: 2em;+ top: 40px;+ z-index: 100;++ &.more-show {+ display: flex;+ }++ button {+ .button();+ // font-size: 24px;+ }+}++.button() {+ padding: 0px;+ line-height: 1;+}\ No newline at end of filediff --git a/packages/ui-plugin-sheets/src/View/ToolBar/index.ts b/packages/ui-plugin-sheets/src/View/ToolBar/index.tsnew file mode 100644index 0000000000..f88f595157--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/ToolBar/index.ts@@ -0,0 +1 @@+export * from './ToolBar';diff --git a/packages/ui-plugin-sheets/src/View/UniverContainer/UniverContainer.tsx b/packages/ui-plugin-sheets/src/View/UniverContainer/UniverContainer.tsxnew file mode 100644index 0000000000..f6cbf45a07--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/UniverContainer/UniverContainer.tsx@@ -0,0 +1,317 @@+import { Tools } from '@univerjs/core';+import { Container, Content, Footer, Header, Layout, Sider } from '@univerjs/style-univer';+import cssVars from 'css-vars-ponyfill';+import defaultSkin from '@univerjs/style-univer/assets/css/skin/default.module.less';+import darkSkin from '@univerjs/style-univer/assets/css/skin/dark.module.less';+import greenSkin from '@univerjs/style-univer/assets/css/skin/green.module.less';+import { BaseComponentProps } from '../../BaseComponent';+import { AppContext } from '../../Common';+import { Component, createRef } from '../../Framework';+import style from './index.module.less';+import { ToolBar } from '../ToolBar';+import { InfoBar } from '../InfoBar';+import { UniverConfig } from '../../Basics/Interfaces/ComponentConfig/UniverConfig';+import { RightMenu } from '../RightMenu';+import { CountBar } from '../CountBar';+import { SheetBar } from '../SheetBar';++export interface BaseSheetContainerProps extends BaseComponentProps {+ config: UniverConfig;+ container?: HTMLElement;+ changeSkin: () => void;+ changeLocale: (locale: string) => void;+ mountCanvas?: (container: HTMLElement) => void;+ methods?: any;+}++// Types for state+interface IState {+ currentLocale: string;+ currentSkin: string;+}++/**+ * One universheet instance DOM container+ */+export class UniverContainer extends Component<BaseSheetContainerProps, IState> {+ leftContentLeft: number;++ leftContentTop: number;++ rightBorderX: number;++ rightBorderY: number;++ splitLeftRef = createRef<HTMLDivElement>();++ contentRef = createRef<HTMLDivElement>();++ constructor(props: BaseSheetContainerProps) {+ super(props, { context: props.config.context });+ const defaultSkin = props.config.skin ?? 'default';+ // init state+ this.state = {+ currentLocale: props.config.locale ?? 'zh',+ currentSkin: defaultSkin,+ };+ this.changeSkin(props.container!, defaultSkin);+ }++ componentDidMount() {+ this.props.getComponent?.(this);+ // this.props.mountCanvas?.(this.getContentRef().current!);+ }++ /**+ * split mouse down+ * @param e+ */+ handleSplitBarMouseDown = (e: MouseEvent) => {+ e = e || window.event; // Compatible with IE browser+ // Store the current mouse position+ this.leftContentLeft = this.splitLeftRef.current?.getBoundingClientRect().left!;+ this.leftContentTop = this.splitLeftRef.current?.getBoundingClientRect().top!;+ const mainContainer = this.splitLeftRef.current?.parentElement;+ this.rightBorderX = mainContainer?.getBoundingClientRect()?.width!;+ this.rightBorderY = mainContainer?.getBoundingClientRect()?.height!;+ document.addEventListener('mousemove', this.handleSplitBarMouseMove, false);+ document.addEventListener('mouseup', this.handleSplitBarMouseUp, false);+ };++ /**+ * split mouse move+ * @param e+ */+ handleSplitBarMouseMove = (e: MouseEvent) => {+ const layout = this.props.config.layout!;+ e = e || window.event; // Compatible with IE browser+ let diffLeft = e.clientX - this.leftContentLeft;+ let diffTop = e.clientY - this.leftContentTop;+ // Prevent crossing borders+ diffLeft = diffLeft >= this.rightBorderX ? this.rightBorderX : diffLeft;+ diffTop = diffTop >= this.rightBorderY ? this.rightBorderY : diffTop;+ // set new width+ if (layout.contentSplit === 'vertical') {+ this.splitLeftRef.current!.style.height = `${diffTop}px`;+ } else {+ this.splitLeftRef.current!.style.width = `${diffLeft}px`;+ }+ };++ /**+ * split mouse up+ * @param e+ */+ handleSplitBarMouseUp = (e: MouseEvent) => {+ document.removeEventListener('mousemove', this.handleSplitBarMouseMove, false);+ document.removeEventListener('mouseup', this.handleSplitBarMouseUp, false);+ };++ getContentRef() {+ return this.contentRef;+ }++ getSplitLeftRef() {+ return this.splitLeftRef;+ }++ handleChangeSkin(e: Event) {+ const { changeSkin } = this.props;+ const target = e.target as HTMLSelectElement;+ const skin = target.value;+ this.setState(+ {+ currentSkin: skin,+ },+ () => {+ this.changeSkin(this.props.container!, skin);+ }+ );+ changeSkin();+ }++ /**+ * Modify Dom Skin+ */+ changeSkin(container: HTMLElement, skin: string) {+ // Collect all skins+ let root = document.documentElement;+ // get all skins+ const skins = {+ default: defaultSkin,+ dark: darkSkin,+ green: greenSkin,+ };+ // current skin set by user+ let currentSkin = skins[skin];+ // transform "primaryColor" to "--primary-color"+ currentSkin = Object.fromEntries(Object.keys(currentSkin).map((item) => [`--${item.replace(/([A-Z0-9])/g, '-$1').toLowerCase()}`, currentSkin[item]]));+ // ie11 does not support css variables, use css-vars-ponyfill to handle+ if (Tools.isIEBrowser()) {+ cssVars({+ // Options...+ // The container is invalid as rootElement, so the default setting is root.+ // Disadvantages: In ie11, only one set of skins can be used for multiple workbooks, and it is the skin set by the last workbook+ rootElement: root, // default+ variables: currentSkin,+ });+ } else {+ // set css variable+ let sheet = getSkinStyleSheet(container.id);+ /**+ * covert object to style, remove " and replace , to ;+ *+ * Example:+ *+ * before: {--primary-color:"#0188fb",--primary-color-hover:"#5391ff"}+ * after: {--primary-color:#0188fb;--primary-color-hover:#5391ff;}+ */+ sheet.insertRule(+ `#${container.id} ${JSON.stringify(currentSkin)+ .replace(/"/g, '')+ .replace(/,(?=--)/g, ';')}`+ );+ }+ /**+ * get skin style sheet+ * @param id+ * @returns+ */+ function getSkinStyleSheet(id: string) {+ const title = 'universheet-skin-style';+ // avoid duplicates+ for (let i = 0; i < document.styleSheets.length; i++) {+ if (document.styleSheets[i].title === title) {+ deleteStyleRuleIndexBySelector(document.styleSheets[i], id);+ return document.styleSheets[i];+ }+ }+ const head = document.head || document.getElementsByTagName('head')[0];+ const styleEle = document.createElement('style');+ styleEle.title = title;+ head.appendChild(styleEle);+ return document.styleSheets[document.styleSheets.length - 1];+ }+ /**+ * delete style rule in universheet-skin-style+ * @param skinStyleSheet+ * @param id+ */+ function deleteStyleRuleIndexBySelector(skinStyleSheet: CSSStyleSheet, id: string) {+ let index = 0;+ for (let i = 0; i < skinStyleSheet.cssRules.length; i++) {+ const rule = skinStyleSheet.cssRules[i];+ if (rule instanceof CSSStyleRule && rule.selectorText === `#${id}`) {+ index = i;+ skinStyleSheet.deleteRule(index);+ break;+ }+ }+ }+ }++ setLocale(e: Event) {+ const { changeLocale } = this.props;+ const target = e.target as HTMLSelectElement;+ const locale = target.value;+ // You must use setState to trigger the re-rendering of the child component+ this.setState(+ {+ currentLocale: locale,+ },+ () => {+ changeLocale(locale);+ }+ );+ }++ /**+ * Render the component's HTML+ *+ * @returns {void}+ */+ render() {+ const { methods } = this.props;+ const { context, layout } = this.props.config;+ const { currentLocale, currentSkin } = this.state;+ const config = layout!;+ // Set Provider for entire Container+ return (+ <AppContext.Provider+ value={{+ context,+ }}+ >+ <Container className={style.layoutContainer}>+ <Layout>+ <Sider style={{ display: config.outerLeft ? 'block' : 'none' }}></Sider>+ <Layout className={style.mainContent} style={{ position: 'relative' }}>+ <Header style={{ display: config.header ? 'block' : 'none' }}>+ {config.infoBar && <InfoBar {...methods.infoBar}></InfoBar>}+ {config.toolBar && <ToolBar {...methods.toolbar}></ToolBar>}+ {/* {config.infoBar && <InfoBar></InfoBar>}+ {config.formulaBar && <FormulaBar></FormulaBar>} */}+ </Header>+ <Layout>+ <Sider+ style={{+ display: config.innerLeft ? 'block' : 'none',+ }}+ >+ {/* innerLeft */}+ </Sider>+ <Content className={config.contentSplit === 'vertical' ? style.contentContainerVertical : style.contentContainerHorizontal}>+ {/* extend main content */}+ {/* <ModalGroup></ModalGroup> */}+ {!!config.contentSplit && (+ <Container ref={this.splitLeftRef} className={style.contentInnerLeftContainer}>+ <div className={style.hoverCursor} onMouseDown={this.handleSplitBarMouseDown}></div>+ </Container>+ )}+ <Container ref={this.contentRef} className={style.contentInnerRightContainer}>+ {config.rightMenu && <RightMenu {...methods.rightMenu}></RightMenu>}+ <div style={{ position: 'fixed', right: '200px', top: '10px', fontSize: '14px' }}>+ <span style={{ display: 'inline-block', width: 50, margin: '5px 0 0 5px' }}>皮肤</span>+ <select value={currentSkin} onChange={this.handleChangeSkin.bind(this)} style={{ width: 55 }}>+ <option value="default">默认</option>+ <option value="dark">暗黑</option>+ <option value="green">绿色</option>+ </select>+ <span style={{ display: 'inline-block', width: 50, margin: '5px 0 0 5px' }}>语言</span>+ <select value={currentLocale} onChange={this.setLocale.bind(this)} style={{ width: 55 }}>+ <option value="en">English</option>+ <option value="zh">中文</option>+ </select>+ </div>+ </Container>+ </Content>+ <Sider+ style={{+ display: config.innerRight ? 'block' : 'none',+ }}+ >+ {/* innerRight */}+ {/* <SideGroup></SideGroup> */}+ </Sider>+ </Layout>+ <Footer+ style={{+ display: config.footer ? 'block' : 'none',+ }}+ >+ {config.sheetBar && <SheetBar {...methods.sheetBar}></SheetBar>}+ {config.countBar && <CountBar {...methods.countBar}></CountBar>}+ </Footer>+ </Layout>+ <Sider+ style={{+ display: config.outerRight ? 'block' : 'none',+ }}+ className={style.outerRightContainer}+ ></Sider>+ </Layout>+ </Container>+ </AppContext.Provider>+ );+ }+}diff --git a/packages/ui-plugin-sheets/src/View/UniverContainer/index.module.less b/packages/ui-plugin-sheets/src/View/UniverContainer/index.module.lessnew file mode 100644index 0000000000..100caac0a5--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/UniverContainer/index.module.less@@ -0,0 +1,77 @@+.layout-container {+ // theme+ background-color: var(--bg);+ color: var(--text-color);+ height: 100%;++ .content-container-horizontal {+ display: flex;+ min-height: 14em;+ position: relative;++ .content-inner-left-container {+ // position: relative;+ width: 50%;+ padding-right: 10px;+ flex: none;++ .hover-cursor {+ position: absolute;+ right: 0;+ top: 0;+ height: 100%;+ width: 10px;+ background: gray;+ cursor: e-resize;+ }+ }++ .content-inner-right-container {+ width: 50%;+ flex: 1;+ // position: relative;+ }+ }++ .content-container-vertical {+ display: flex;+ flex-direction: column;+ min-height: 14em;+ position: relative;++ .content-inner-left-container {+ // position: relative;+ height: 50%;+ padding-bottom: 10px;+ flex: none;++ .hover-cursor {+ position: absolute;+ left: 0;+ bottom: 0;+ height: 10px;+ width: 100%;+ background: gray;+ cursor: n-resize;+ }+ }++ .content-inner-right-container {+ height: 50%;+ flex: 1;+ }+ }++ .main-content {+ background: var(--bg);+ }++ .outer-right-container {+ // position: relative;+ flex: 0 0 280px;+ > div {+ position: absolute;+ width: 100%;+ }+ }+}diff --git a/packages/ui-plugin-sheets/src/View/UniverContainer/index.ts b/packages/ui-plugin-sheets/src/View/UniverContainer/index.tsnew file mode 100644index 0000000000..2d4a88ebe5--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/UniverContainer/index.ts@@ -0,0 +1 @@+export * from './UniverContainer';diff --git a/packages/ui-plugin-sheets/src/View/index.tsx b/packages/ui-plugin-sheets/src/View/index.tsxnew file mode 100644index 0000000000..144926d7fd--- /dev/null+++ b/packages/ui-plugin-sheets/src/View/index.tsx@@ -0,0 +1,37 @@+import { render } from '../Framework';+import { isElement } from '../Utils';+import { BaseSheetContainerProps, UniverContainer } from './UniverContainer';++export class UI {+ constructor(props: BaseSheetContainerProps) {+ this._initialize(props);+ }++ static create(props: BaseSheetContainerProps) {+ return new UI(props);+ }++ private _initialize(props: BaseSheetContainerProps) {+ let univerContainer: HTMLElement;+ const container = props.config.container;++ if (typeof container === 'string') {+ const containerDOM = document.getElementById(container);+ if (containerDOM == null) {+ univerContainer = document.createElement('div');+ univerContainer.id = container;+ } else {+ univerContainer = containerDOM;+ }+ } else if (isElement(container)) {+ univerContainer = container!;+ } else {+ univerContainer = document.createElement('div');+ univerContainer.id = 'univer';+ }++ props.container = univerContainer;++ render(<UniverContainer {...props} />, univerContainer);+ }+}