Skip to content

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.

feat(docs): add style settings menu items (#1191)

白熱5828cc59e0af
diff --git a/packages/docs-ui/package.json b/packages/docs-ui/package.json
index 35dd9b7991..596ee445e4 100644
--- a/packages/docs-ui/package.json
+++ b/packages/docs-ui/package.json
@@ -51,7 +51,8 @@
"@univerjs/engine-render": "workspace:*",
"@univerjs/ui": "workspace:*",
"@wendellhu/redi": "^0.12.13",
- "react": "^18.2.0"
+ "react": "^18.2.0",
+ "rxjs": "^7.8.1"
},
"devDependencies": {
"@types/react": "^18.2.47",
diff --git a/packages/docs-ui/src/components/color-picker/index.ts b/packages/docs-ui/src/components/color-picker/index.ts
new file mode 100644
index 0000000000..9153c782a2
--- /dev/null
+++ b/packages/docs-ui/src/components/color-picker/index.ts
@@ -0,0 +1,18 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export { COLOR_PICKER_COMPONENT } from './interface';
+export { ColorPicker } from '@univerjs/design';
diff --git a/packages/docs-ui/src/components/color-picker/interface.ts b/packages/docs-ui/src/components/color-picker/interface.ts
new file mode 100644
index 0000000000..30c73c2492
--- /dev/null
+++ b/packages/docs-ui/src/components/color-picker/interface.ts
@@ -0,0 +1,19 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { COMPONENT_PREFIX } from '../const';
+
+export const COLOR_PICKER_COMPONENT = `${COMPONENT_PREFIX}_COLOR_PICKER_COMPONENT`;
diff --git a/packages/docs-ui/src/components/const.ts b/packages/docs-ui/src/components/const.ts
new file mode 100644
index 0000000000..1fc1ed56cc
--- /dev/null
+++ b/packages/docs-ui/src/components/const.ts
@@ -0,0 +1,17 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export const COMPONENT_PREFIX = 'UI_PLUGIN_DOCS';
diff --git a/packages/docs-ui/src/components/font-family/index.ts b/packages/docs-ui/src/components/font-family/index.ts
new file mode 100644
index 0000000000..ecdba571dc
--- /dev/null
+++ b/packages/docs-ui/src/components/font-family/index.ts
@@ -0,0 +1,19 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export { FONT_FAMILY_COMPONENT, FONT_FAMILY_ITEM_COMPONENT } from './interface';
+export { FontFamily } from '@univerjs/ui';
+export { FontFamilyItem } from '@univerjs/ui';
diff --git a/packages/docs-ui/src/components/font-family/interface.ts b/packages/docs-ui/src/components/font-family/interface.ts
new file mode 100644
index 0000000000..08d440d18d
--- /dev/null
+++ b/packages/docs-ui/src/components/font-family/interface.ts
@@ -0,0 +1,21 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { COMPONENT_PREFIX } from '../const';
+
+export const FONT_FAMILY_COMPONENT = `${COMPONENT_PREFIX}_FONT_FAMILY_COMPONENT`;
+
+export const FONT_FAMILY_ITEM_COMPONENT = `${COMPONENT_PREFIX}_FONT_FAMILY_ITEM_COMPONENT`;
diff --git a/packages/docs-ui/src/components/font-size/index.ts b/packages/docs-ui/src/components/font-size/index.ts
new file mode 100644
index 0000000000..cf3a9ee2ad
--- /dev/null
+++ b/packages/docs-ui/src/components/font-size/index.ts
@@ -0,0 +1,18 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export { FONT_SIZE_COMPONENT } from './interface';
+export { FontSize } from '@univerjs/ui';
diff --git a/packages/docs-ui/src/components/font-size/interface.ts b/packages/docs-ui/src/components/font-size/interface.ts
new file mode 100644
index 0000000000..4c5aa57bfa
--- /dev/null
+++ b/packages/docs-ui/src/components/font-size/interface.ts
@@ -0,0 +1,19 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import { COMPONENT_PREFIX } from '../const';
+
+export const FONT_SIZE_COMPONENT = `${COMPONENT_PREFIX}_FONT_SIZE_COMPONENT`;
diff --git a/packages/docs-ui/src/controllers/doc-ui.controller.ts b/packages/docs-ui/src/controllers/doc-ui.controller.ts
index fd755de369..78b35b7f09 100644
--- a/packages/docs-ui/src/controllers/doc-ui.controller.ts
+++ b/packages/docs-ui/src/controllers/doc-ui.controller.ts
@@ -19,14 +19,25 @@ import type { IDesktopUIController, IMenuItemFactory } from '@univerjs/ui';
import { ComponentManager, IMenuService, IShortcutService, IUIController } from '@univerjs/ui';
import { Inject, Injector } from '@wendellhu/redi';
+import { COLOR_PICKER_COMPONENT, ColorPicker } from '../components/color-picker';
+import {
+ FONT_FAMILY_COMPONENT,
+ FONT_FAMILY_ITEM_COMPONENT,
+ FontFamily,
+ FontFamilyItem,
+} from '../components/font-family';
+import { FONT_SIZE_COMPONENT, FontSize } from '../components/font-size';
import {
BoldMenuItemFactory,
BulletListMenuItemFactory,
+ FontFamilySelectorMenuItemFactory,
+ FontSizeSelectorMenuItemFactory,
ItalicMenuItemFactory,
OrderListMenuItemFactory,
StrikeThroughMenuItemFactory,
SubscriptMenuItemFactory,
SuperscriptMenuItemFactory,
+ TextColorSelectorMenuItemFactory,
UnderlineMenuItemFactory,
} from './menu/menu';
@@ -46,7 +57,15 @@ export class DocUIController extends Disposable {
this._init();
}
- private _init(): void {
+ private _initCustomComponents(): void {
+ const componentManager = this._componentManager;
+ this.disposeWithMe(componentManager.register(COLOR_PICKER_COMPONENT, ColorPicker));
+ this.disposeWithMe(componentManager.register(FONT_FAMILY_COMPONENT, FontFamily));
+ this.disposeWithMe(componentManager.register(FONT_FAMILY_ITEM_COMPONENT, FontFamilyItem));
+ this.disposeWithMe(componentManager.register(FONT_SIZE_COMPONENT, FontSize));
+ }
+
+ private _initMenus(): void {
// init menus
(
[
@@ -56,6 +75,9 @@ export class DocUIController extends Disposable {
StrikeThroughMenuItemFactory,
SubscriptMenuItemFactory,
SuperscriptMenuItemFactory,
+ FontSizeSelectorMenuItemFactory,
+ FontFamilySelectorMenuItemFactory,
+ TextColorSelectorMenuItemFactory,
OrderListMenuItemFactory,
BulletListMenuItemFactory,
] as IMenuItemFactory[]
@@ -63,4 +85,9 @@ export class DocUIController extends Disposable {
this.disposeWithMe(this._menuService.addMenuItem(this._injector.invoke(factory)));
});
}
+
+ private _init(): void {
+ this._initCustomComponents();
+ this._initMenus();
+ }
}
diff --git a/packages/docs-ui/src/controllers/menu/menu.ts b/packages/docs-ui/src/controllers/menu/menu.ts
index b793258cf8..5ec3c8e54d 100644
--- a/packages/docs-ui/src/controllers/menu/menu.ts
+++ b/packages/docs-ui/src/controllers/menu/menu.ts
@@ -14,23 +14,50 @@
* limitations under the License.
*/
-import { UniverInstanceType } from '@univerjs/core';
+import {
+ BaselineOffset,
+ BooleanNumber,
+ ICommandService,
+ IUniverInstanceService,
+ ThemeService,
+ UniverInstanceType,
+} from '@univerjs/core';
import {
BulletListCommand,
OrderListCommand,
SetInlineFormatBoldCommand,
+ SetInlineFormatCommand,
+ SetInlineFormatFontFamilyCommand,
+ SetInlineFormatFontSizeCommand,
SetInlineFormatItalicCommand,
SetInlineFormatStrikethroughCommand,
SetInlineFormatSubscriptCommand,
SetInlineFormatSuperscriptCommand,
+ SetInlineFormatTextColorCommand,
SetInlineFormatUnderlineCommand,
+ SetTextSelectionsOperation,
+ TextSelectionManagerService,
} from '@univerjs/docs';
-import type { IMenuButtonItem } from '@univerjs/ui';
-import { getMenuHiddenObservable, MenuGroup, MenuItemType, MenuPosition } from '@univerjs/ui';
+import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
+import {
+ FONT_FAMILY_LIST,
+ FONT_SIZE_LIST,
+ getMenuHiddenObservable,
+ MenuGroup,
+ MenuItemType,
+ MenuPosition,
+} from '@univerjs/ui';
import type { IAccessor } from '@wendellhu/redi';
+import { Observable } from 'rxjs';
+
+import { COLOR_PICKER_COMPONENT } from '../../components/color-picker';
+import { FONT_FAMILY_COMPONENT, FONT_FAMILY_ITEM_COMPONENT } from '../../components/font-family';
+import { FONT_SIZE_COMPONENT } from '../../components/font-size';
// TODO @Dushusir: use for test, change id later
export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ const commandService = accessor.get(ICommandService);
+
return {
id: SetInlineFormatBoldCommand.id,
group: MenuGroup.TOOLBAR_FORMAT,
@@ -39,11 +66,34 @@ export function BoldMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
title: 'Set bold',
tooltip: 'toolbar.bold',
positions: [MenuPosition.TOOLBAR_START],
+ activated$: new Observable<boolean>((subscriber) => {
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
+ const textRun = getFontStyleAtCursor(accessor);
+
+ if (textRun == null) {
+ return;
+ }
+
+ const bl = textRun.ts?.bl;
+
+ subscriber.next(bl === BooleanNumber.TRUE);
+ }
+ });
+
+ subscriber.next(false);
+
+ return disposable.dispose;
+ }),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
};
}
export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ const commandService = accessor.get(ICommandService);
+
return {
id: SetInlineFormatItalicCommand.id,
group: MenuGroup.TOOLBAR_FORMAT,
@@ -52,11 +102,34 @@ export function ItalicMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
title: 'Set italic',
tooltip: 'toolbar.italic',
positions: [MenuPosition.TOOLBAR_START],
+ activated$: new Observable<boolean>((subscriber) => {
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
+ const textRun = getFontStyleAtCursor(accessor);
+
+ if (textRun == null) {
+ return;
+ }
+
+ const it = textRun.ts?.it;
+
+ subscriber.next(it === BooleanNumber.TRUE);
+ }
+ });
+
+ subscriber.next(false);
+
+ return disposable.dispose;
+ }),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
};
}
export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ const commandService = accessor.get(ICommandService);
+
return {
id: SetInlineFormatUnderlineCommand.id,
group: MenuGroup.TOOLBAR_FORMAT,
@@ -65,11 +138,34 @@ export function UnderlineMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
title: 'Set underline',
tooltip: 'toolbar.underline',
positions: [MenuPosition.TOOLBAR_START],
+ activated$: new Observable<boolean>((subscriber) => {
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
+ const textRun = getFontStyleAtCursor(accessor);
+
+ if (textRun == null) {
+ return;
+ }
+
+ const ul = textRun.ts?.ul;
+
+ subscriber.next(ul?.s === BooleanNumber.TRUE);
+ }
+ });
+
+ subscriber.next(false);
+
+ return disposable.dispose;
+ }),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
};
}
export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ const commandService = accessor.get(ICommandService);
+
return {
id: SetInlineFormatStrikethroughCommand.id,
group: MenuGroup.TOOLBAR_FORMAT,
@@ -78,11 +174,34 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIt
title: 'Set strike through',
tooltip: 'toolbar.strikethrough',
positions: [MenuPosition.TOOLBAR_START],
+ activated$: new Observable<boolean>((subscriber) => {
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
+ const textRun = getFontStyleAtCursor(accessor);
+
+ if (textRun == null) {
+ return;
+ }
+
+ const st = textRun.ts?.st;
+
+ subscriber.next(st?.s === BooleanNumber.TRUE);
+ }
+ });
+
+ subscriber.next(false);
+
+ return disposable.dispose;
+ }),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
};
}
export function SubscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ const commandService = accessor.get(ICommandService);
+
return {
id: SetInlineFormatSubscriptCommand.id,
group: MenuGroup.TOOLBAR_FORMAT,
@@ -90,11 +209,34 @@ export function SubscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
icon: 'SubscriptSingle',
tooltip: 'toolbar.subscript',
positions: [MenuPosition.TOOLBAR_START],
+ activated$: new Observable<boolean>((subscriber) => {
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
+ const textRun = getFontStyleAtCursor(accessor);
+
+ if (textRun == null) {
+ return;
+ }
+
+ const va = textRun.ts?.va;
+
+ subscriber.next(va === BaselineOffset.SUBSCRIPT);
+ }
+ });
+
+ subscriber.next(false);
+
+ return disposable.dispose;
+ }),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
};
}
export function SuperscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
+ const commandService = accessor.get(ICommandService);
+
return {
id: SetInlineFormatSuperscriptCommand.id,
group: MenuGroup.TOOLBAR_FORMAT,
@@ -102,17 +244,163 @@ export function SuperscriptMenuItemFactory(accessor: IAccessor): IMenuButtonItem
icon: 'SuperscriptSingle',
tooltip: 'toolbar.superscript',
positions: [MenuPosition.TOOLBAR_START],
+ activated$: new Observable<boolean>((subscriber) => {
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatCommand.id) {
+ const textRun = getFontStyleAtCursor(accessor);
+
+ if (textRun == null) {
+ return;
+ }
+
+ const va = textRun.ts?.va;
+
+ subscriber.next(va === BaselineOffset.SUPERSCRIPT);
+ }
+ });
+
+ subscriber.next(false);
+
+ return disposable.dispose;
+ }),
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
};
}
+export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ const commandService = accessor.get(ICommandService);
+
+ return {
+ id: SetInlineFormatFontFamilyCommand.id,
+ tooltip: 'toolbar.font',
+ group: MenuGroup.TOOLBAR_FORMAT,
+ type: MenuItemType.SELECTOR,
+ label: FONT_FAMILY_COMPONENT,
+ positions: [MenuPosition.TOOLBAR_START],
+ selections: FONT_FAMILY_LIST.map((item) => ({
+ label: {
+ name: FONT_FAMILY_ITEM_COMPONENT,
+ value: item.value,
+ },
+ })),
+ // disabled$: getCurrentSheetDisabled$(accessor),
+ value$: new Observable((subscriber) => {
+ const defaultValue = FONT_FAMILY_LIST[0].value;
+
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontFamilyCommand.id) {
+ const textRun = getFontStyleAtCursor(accessor);
+
+ if (textRun == null) {
+ return;
+ }
+
+ const ff = textRun.ts?.ff;
+
+ subscriber.next(ff ?? defaultValue);
+ }
+ });
+
+ subscriber.next(defaultValue);
+ return disposable.dispose;
+ }),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
+ };
+}
+
+export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<number> {
+ const commandService = accessor.get(ICommandService);
+
+ return {
+ id: SetInlineFormatFontSizeCommand.id,
+ group: MenuGroup.TOOLBAR_FORMAT,
+ type: MenuItemType.SELECTOR,
+ tooltip: 'toolbar.fontSize',
+ label: {
+ name: FONT_SIZE_COMPONENT,
+ props: {
+ min: 1,
+ max: 400,
+ // disabled$,
+ },
+ },
+ positions: [MenuPosition.TOOLBAR_START],
+ selections: FONT_SIZE_LIST,
+ // disabled$,
+ value$: new Observable((subscriber) => {
+ const DEFAULT_SIZE = 14;
+ const disposable = commandService.onCommandExecuted((c) => {
+ const id = c.id;
+
+ if (id === SetTextSelectionsOperation.id || id === SetInlineFormatFontSizeCommand.id) {
+ const textRun = getFontStyleAtCursor(accessor);
+
+ if (textRun == null) {
+ return;
+ }
+
+ const fs = textRun.ts?.fs;
+
+ subscriber.next(fs ?? DEFAULT_SIZE);
+ }
+ });
+
+ subscriber.next(DEFAULT_SIZE);
+
+ return disposable.dispose;
+ }),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
+ };
+}
+
+export function TextColorSelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
+ const commandService = accessor.get(ICommandService);
+ const themeService = accessor.get(ThemeService);
+
+ return {
+ id: SetInlineFormatTextColorCommand.id,
+ icon: 'FontColor',
+ tooltip: 'toolbar.textColor.main',
+
+ group: MenuGroup.TOOLBAR_FORMAT,
+ type: MenuItemType.BUTTON_SELECTOR,
+ positions: [MenuPosition.TOOLBAR_START],
+ selections: [
+ {
+ label: {
+ name: COLOR_PICKER_COMPONENT,
+ hoverable: false,
+ },
+ },
+ ],
+ value$: new Observable<string>((subscriber) => {
+ const defaultColor = themeService.getCurrentTheme().textColor;
+ const disposable = commandService.onCommandExecuted((c) => {
+ if (c.id === SetInlineFormatTextColorCommand.id) {
+ const color = (c.params as { value: string }).value;
+ subscriber.next(color ?? defaultColor);
+ }
+ });
+
+ subscriber.next(defaultColor);
+ return disposable.dispose;
+ }),
+ hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
+ // disabled$: getCurrentSheetDisabled$(accessor),
+ };
+}
+
export function OrderListMenuItemFactory(accessor: IAccessor): IMenuButtonItem {
return {
id: OrderListCommand.id,
group: MenuGroup.TOOLBAR_LAYOUT,
type: MenuItemType.BUTTON,
icon: 'OrderSingle',
- tooltip: 'toolbar.superscript',
+ tooltip: 'toolbar.order',
positions: [MenuPosition.TOOLBAR_START],
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
};
@@ -124,8 +412,31 @@ export function BulletListMenuItemFactory(accessor: IAccessor): IMenuButtonItem
group: MenuGroup.TOOLBAR_LAYOUT,
type: MenuItemType.BUTTON,
icon: 'UnorderSingle',
- tooltip: 'toolbar.superscript',
+ tooltip: 'toolbar.unorder',
positions: [MenuPosition.TOOLBAR_START],
hidden$: getMenuHiddenObservable(accessor, UniverInstanceType.DOC),
};
}
+
+function getFontStyleAtCursor(accessor: IAccessor) {
+ const currentUniverService = accessor.get(IUniverInstanceService);
+ const textSelectionService = accessor.get(TextSelectionManagerService);
+ const editorDataModel = currentUniverService.getCurrentUniverDocInstance();
+ const activeTextRange = textSelectionService.getActiveRange();
+
+ if (editorDataModel == null || activeTextRange == null) {
+ return;
+ }
+
+ const textRuns = editorDataModel.getBody()?.textRuns;
+
+ if (textRuns == null) {
+ return;
+ }
+
+ const { startOffset } = activeTextRange;
+
+ const textRun = textRuns.find(({ st, ed }) => startOffset >= st && startOffset < ed);
+
+ return textRun;
+}
diff --git a/packages/docs-ui/src/locale/en-US.ts b/packages/docs-ui/src/locale/en-US.ts
index 1c4630e861..73d9133ca0 100644
--- a/packages/docs-ui/src/locale/en-US.ts
+++ b/packages/docs-ui/src/locale/en-US.ts
@@ -14,4 +14,41 @@
* limitations under the License.
*/
-export default {};
+export default {
+ toolbar: {
+ undo: 'Undo',
+ redo: 'Redo',
+ font: 'Font',
+ fontSize: 'Font size',
+ bold: 'Bold',
+ italic: 'Italic',
+ strikethrough: 'Strikethrough',
+ subscript: 'Subscript',
+ superscript: 'Superscript',
+ textColor: {
+ main: 'Text color',
+ right: 'Choose color',
+ },
+ resetColor: 'Reset',
+ order: 'Ordered list',
+ unorder: 'Unordered list',
+ },
+ fontFamily: {
+ TimesNewRoman: 'Times New Roman',
+ Arial: 'Arial',
+ Tahoma: 'Tahoma',
+ Verdana: 'Verdana',
+ MicrosoftYaHei: 'Microsoft YaHei',
+ SimSun: 'SimSun',
+ SimHei: 'SimHei',
+ Kaiti: 'Kaiti',
+ FangSong: 'FangSong',
+ NSimSun: 'NSimSun',
+ STXinwei: 'STXinwei',
+ STXingkai: 'STXingkai',
+ STLiti: 'STLiti',
+ HanaleiFill: 'HanaleiFill',
+ Anton: 'Anton',
+ Pacifico: 'Pacifico',
+ },
+};
diff --git a/packages/docs-ui/src/locale/zh-CN.ts b/packages/docs-ui/src/locale/zh-CN.ts
index 1c4630e861..fa82d3d32c 100644
--- a/packages/docs-ui/src/locale/zh-CN.ts
+++ b/packages/docs-ui/src/locale/zh-CN.ts
@@ -14,4 +14,42 @@
* limitations under the License.
*/
-export default {};
+export default {
+ toolbar: {
+ undo: '撤销',
+ redo: '重做',
+ font: '字体',
+ fontSize: '字号',
+ bold: '粗体',
+ italic: '斜体',
+ strikethrough: '删除线',
+ subscript: '下标',
+ superscript: '上标',
+ underline: '下划线',
+ textColor: {
+ main: '文本颜色',
+ right: '颜色选择',
+ },
+ resetColor: '重置颜色',
+ order: '有序列表',
+ unorder: '无序列表',
+ },
+ fontFamily: {
+ TimesNewRoman: 'Times New Roman',
+ Arial: 'Arial',
+ Tahoma: 'Tahoma',
+ Verdana: 'Verdana',
+ MicrosoftYaHei: '微软雅黑',
+ SimSun: '宋体',
+ SimHei: '黑体',
+ Kaiti: '楷体',
+ FangSong: '仿宋',
+ NSimSun: '新宋体',
+ STXinwei: '华文新魏',
+ STXingkai: '华文行楷',
+ STLiti: '华文隶书',
+ HanaleiFill: 'HanaleiFill',
+ Anton: 'Anton',
+ Pacifico: 'Pacifico',
+ },
+};
diff --git a/packages/docs-ui/vite.config.ts b/packages/docs-ui/vite.config.ts
index 92158411d3..c14da86ad4 100644
--- a/packages/docs-ui/vite.config.ts
+++ b/packages/docs-ui/vite.config.ts
@@ -45,6 +45,7 @@ export default defineConfig(({ mode }) => ({
'@wendellhu/redi',
'@wendellhu/redi/react-bindings',
'react',
+ 'rxjs',
],
output: {
assetFileNames: 'index.css',
@@ -57,6 +58,7 @@ export default defineConfig(({ mode }) => ({
'@wendellhu/redi': '@wendellhu/redi',
'@wendellhu/redi/react-bindings': '@wendellhu/redi/react-bindings',
react: 'React',
+ rxjs: 'rxjs',
},
},
},
diff --git a/packages/sheets-ui/src/components/font-family/index.ts b/packages/sheets-ui/src/components/font-family/index.ts
index 6ae482df36..ecdba571dc 100644
--- a/packages/sheets-ui/src/components/font-family/index.ts
+++ b/packages/sheets-ui/src/components/font-family/index.ts
@@ -14,6 +14,6 @@
* limitations under the License.
*/
-export { FontFamily } from './FontFamily';
-export { FontFamilyItem } from './FontFamilyItem';
export { FONT_FAMILY_COMPONENT, FONT_FAMILY_ITEM_COMPONENT } from './interface';
+export { FontFamily } from '@univerjs/ui';
+export { FontFamilyItem } from '@univerjs/ui';
diff --git a/packages/sheets-ui/src/components/font-family/interface.ts b/packages/sheets-ui/src/components/font-family/interface.ts
index 17ea14eb0d..08d440d18d 100644
--- a/packages/sheets-ui/src/components/font-family/interface.ts
+++ b/packages/sheets-ui/src/components/font-family/interface.ts
@@ -14,18 +14,8 @@
* limitations under the License.
*/
-import type { ICustomComponentProps } from '@univerjs/ui';
-
import { COMPONENT_PREFIX } from '../const';
export const FONT_FAMILY_COMPONENT = `${COMPONENT_PREFIX}_FONT_FAMILY_COMPONENT`;
-export interface IFontFamilyProps extends ICustomComponentProps<string> {
- value: string;
-}
-
export const FONT_FAMILY_ITEM_COMPONENT = `${COMPONENT_PREFIX}_FONT_FAMILY_ITEM_COMPONENT`;
-
-export interface IFontFamilyItemProps extends ICustomComponentProps<string> {
- value: string;
-}
diff --git a/packages/sheets-ui/src/components/font-size/index.ts b/packages/sheets-ui/src/components/font-size/index.ts
index 43badc3ef2..cf3a9ee2ad 100644
--- a/packages/sheets-ui/src/components/font-size/index.ts
+++ b/packages/sheets-ui/src/components/font-size/index.ts
@@ -14,5 +14,5 @@
* limitations under the License.
*/
-export { FontSize } from './FontSize';
export { FONT_SIZE_COMPONENT } from './interface';
+export { FontSize } from '@univerjs/ui';
diff --git a/packages/sheets-ui/src/components/font-size/interface.ts b/packages/sheets-ui/src/components/font-size/interface.ts
index 3898867e73..4c5aa57bfa 100644
--- a/packages/sheets-ui/src/components/font-size/interface.ts
+++ b/packages/sheets-ui/src/components/font-size/interface.ts
@@ -14,21 +14,6 @@
* limitations under the License.
*/
-import type { ICustomComponentProps } from '@univerjs/ui';
-import type { Observable } from 'rxjs';
-
import { COMPONENT_PREFIX } from '../const';
export const FONT_SIZE_COMPONENT = `${COMPONENT_PREFIX}_FONT_SIZE_COMPONENT`;
-
-export interface IFontSizeProps extends ICustomComponentProps<string> {
- value: string;
-
- min: number;
-
- max: number;
-
- onChange: (value: string) => void;
-
- disabled$?: Observable<boolean>;
-}
diff --git a/packages/sheets-ui/src/controllers/menu/menu.ts b/packages/sheets-ui/src/controllers/menu/menu.ts
index d5f47e61a7..19d1bbb9d1 100644
--- a/packages/sheets-ui/src/controllers/menu/menu.ts
+++ b/packages/sheets-ui/src/controllers/menu/menu.ts
@@ -58,6 +58,8 @@ import type { IMenuButtonItem, IMenuSelectorItem } from '@univerjs/ui';
import {
CopyCommand,
CutCommand,
+ FONT_FAMILY_LIST,
+ FONT_SIZE_LIST,
getMenuHiddenObservable,
MenuGroup,
MenuItemType,
@@ -354,141 +356,6 @@ export function StrikeThroughMenuItemFactory(accessor: IAccessor): IMenuButtonIt
};
}
-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 = [
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'Times New Roman',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'Arial',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'Tahoma',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'Verdana',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'Microsoft YaHei',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'SimSun',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'SimHei',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'Kaiti',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'FangSong',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'NSimSun',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'STXinwei',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'STXingkai',
- },
- {
- label: FONT_FAMILY_ITEM_COMPONENT,
- value: 'STLiti',
- },
- // The following 3 fonts do not work, temporarily delete
- // {
- // label: 'fontFamily.HanaleiFill',
- // style: { 'font-family': 'HanaleiFill' },
- // value: 'HanaleiFill',
- // },
- // {
- // label: 'fontFamily.Anton',
- // style: { 'font-family': 'Anton' },
- // value: 'Anton',
- // },
- // {
- // label: 'fontFamily.Pacifico',
- // style: { 'font-family': 'Pacifico' },
- // value: 'Pacifico',
- // },
-];
-
export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSelectorItem<string> {
const commandService = accessor.get(ICommandService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -501,10 +368,15 @@ export function FontFamilySelectorMenuItemFactory(accessor: IAccessor): IMenuSel
type: MenuItemType.SELECTOR,
label: FONT_FAMILY_COMPONENT,
positions: [MenuPosition.TOOLBAR_START],
- selections: FONT_FAMILY_CHILDREN,
+ selections: FONT_FAMILY_LIST.map((item) => ({
+ label: {
+ name: FONT_FAMILY_ITEM_COMPONENT,
+ value: item.value,
+ },
+ })),
disabled$: getCurrentSheetDisabled$(accessor),
value$: new Observable((subscriber) => {
- const defaultValue = FONT_FAMILY_CHILDREN[0].value;
+ const defaultValue = FONT_FAMILY_LIST[0].value;
const disposable = commandService.onCommandExecuted((c) => {
const id = c.id;
@@ -552,7 +424,7 @@ export function FontSizeSelectorMenuItemFactory(accessor: IAccessor): IMenuSelec
},
},
positions: [MenuPosition.TOOLBAR_START],
- selections: FONT_SIZE_CHILDREN,
+ selections: FONT_SIZE_LIST,
disabled$,
value$: new Observable((subscriber) => {
const DEFAULT_SIZE = 14;
diff --git a/packages/sheets-ui/src/components/font-family/FontFamily.tsx b/packages/ui/src/components/font-family/FontFamily.tsx
similarity index 100%
rename from packages/sheets-ui/src/components/font-family/FontFamily.tsx
rename to packages/ui/src/components/font-family/FontFamily.tsx
diff --git a/packages/sheets-ui/src/components/font-family/FontFamilyItem.tsx b/packages/ui/src/components/font-family/FontFamilyItem.tsx
similarity index 100%
rename from packages/sheets-ui/src/components/font-family/FontFamilyItem.tsx
rename to packages/ui/src/components/font-family/FontFamilyItem.tsx
diff --git a/packages/sheets-ui/src/components/font-family/index.module.less b/packages/ui/src/components/font-family/index.module.less
similarity index 100%
rename from packages/sheets-ui/src/components/font-family/index.module.less
rename to packages/ui/src/components/font-family/index.module.less
diff --git a/packages/ui/src/components/font-family/index.ts b/packages/ui/src/components/font-family/index.ts
new file mode 100644
index 0000000000..4c78f1dad0
--- /dev/null
+++ b/packages/ui/src/components/font-family/index.ts
@@ -0,0 +1,19 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export { FontFamily } from './FontFamily';
+export { FontFamilyItem } from './FontFamilyItem';
+export { FONT_FAMILY_LIST } from './interface';
diff --git a/packages/ui/src/components/font-family/interface.ts b/packages/ui/src/components/font-family/interface.ts
new file mode 100644
index 0000000000..1451fa2dd2
--- /dev/null
+++ b/packages/ui/src/components/font-family/interface.ts
@@ -0,0 +1,83 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ICustomComponentProps } from '@univerjs/ui';
+
+export interface IFontFamilyProps extends ICustomComponentProps<string> {
+ value: string;
+}
+
+export interface IFontFamilyItemProps extends ICustomComponentProps<string> {
+ value: string;
+}
+
+export const FONT_FAMILY_LIST = [
+ {
+ value: 'Times New Roman',
+ },
+ {
+ value: 'Arial',
+ },
+ {
+ value: 'Tahoma',
+ },
+ {
+ value: 'Verdana',
+ },
+ {
+ value: 'Microsoft YaHei',
+ },
+ {
+ value: 'SimSun',
+ },
+ {
+ value: 'SimHei',
+ },
+ {
+ value: 'Kaiti',
+ },
+ {
+ value: 'FangSong',
+ },
+ {
+ value: 'NSimSun',
+ },
+ {
+ value: 'STXinwei',
+ },
+ {
+ value: 'STXingkai',
+ },
+ {
+ value: 'STLiti',
+ },
+ // The following 3 fonts do not work, temporarily delete
+ // {
+ // label: 'fontFamily.HanaleiFill',
+ // style: { 'font-family': 'HanaleiFill' },
+ // value: 'HanaleiFill',
+ // },
+ // {
+ // label: 'fontFamily.Anton',
+ // style: { 'font-family': 'Anton' },
+ // value: 'Anton',
+ // },
+ // {
+ // label: 'fontFamily.Pacifico',
+ // style: { 'font-family': 'Pacifico' },
+ // value: 'Pacifico',
+ // },
+];
diff --git a/packages/sheets-ui/src/components/font-size/FontSize.tsx b/packages/ui/src/components/font-size/FontSize.tsx
similarity index 97%
rename from packages/sheets-ui/src/components/font-size/FontSize.tsx
rename to packages/ui/src/components/font-size/FontSize.tsx
index ad1f8c5ae9..580072b296 100644
--- a/packages/sheets-ui/src/components/font-size/FontSize.tsx
+++ b/packages/ui/src/components/font-size/FontSize.tsx
@@ -15,10 +15,10 @@
*/
import { InputNumber } from '@univerjs/design';
-import { useObservable } from '@univerjs/ui';
import React, { useMemo, useState } from 'react';
import { Observable } from 'rxjs';
+import { useObservable } from '../hooks/observable';
import styles from './index.module.less';
import type { IFontSizeProps } from './interface';
diff --git a/packages/sheets-ui/src/components/font-size/index.module.less b/packages/ui/src/components/font-size/index.module.less
similarity index 100%
rename from packages/sheets-ui/src/components/font-size/index.module.less
rename to packages/ui/src/components/font-size/index.module.less
diff --git a/packages/ui/src/components/font-size/index.ts b/packages/ui/src/components/font-size/index.ts
new file mode 100644
index 0000000000..c38b91c45a
--- /dev/null
+++ b/packages/ui/src/components/font-size/index.ts
@@ -0,0 +1,18 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+export { FontSize } from './FontSize';
+export { FONT_SIZE_LIST } from './interface';
diff --git a/packages/ui/src/components/font-size/interface.ts b/packages/ui/src/components/font-size/interface.ts
new file mode 100644
index 0000000000..71ea6e2cab
--- /dev/null
+++ b/packages/ui/src/components/font-size/interface.ts
@@ -0,0 +1,94 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import type { ICustomComponentProps } from '@univerjs/ui';
+import type { Observable } from 'rxjs';
+
+export interface IFontSizeProps extends ICustomComponentProps<string> {
+ value: string;
+
+ min: number;
+
+ max: number;
+
+ onChange: (value: string) => void;
+
+ disabled$?: Observable<boolean>;
+}
+
+export const FONT_SIZE_LIST = [
+ {
+ 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,
+ },
+];
diff --git a/packages/ui/src/components/index.ts b/packages/ui/src/components/index.ts
index fe7a6b90b1..29483efcf4 100644
--- a/packages/ui/src/components/index.ts
+++ b/packages/ui/src/components/index.ts
@@ -15,4 +15,6 @@
*/
export * from './custom-label';
+export * from './font-family';
+export * from './font-size';
export * from './menu';
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index 9c38c8e68b..1786161759 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -444,6 +444,9 @@ importers:
react:
specifier: ^18.2.0
version: 18.2.0
+ rxjs:
+ specifier: ^7.8.1
+ version: 7.8.1
devDependencies:
'@types/react':
specifier: ^18.2.47
@@ -5744,7 +5747,7 @@ packages:
magicast: 0.3.2
picocolors: 1.0.0
test-exclude: 6.0.0
- vitest: 1.1.1(@types/[email protected])([email protected])
transitivePeerDependencies:
- supports-color
dev: true