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
fix(ui): improve handling of `CustomLabel` default values (#3536)
白熱fde58d71d2fb
diff --git a/examples/esbuild.config.mjs b/examples/esbuild.config.mjsindex 921bc04a21..6220a278ca 100644--- a/examples/esbuild.config.mjs+++ b/examples/esbuild.config.mjs@@ -2,6 +2,7 @@ import { execSync } from 'node:child_process';import path from 'node:path';import process from 'node:process';+import detect from 'detect-port';import esbuild from 'esbuild';import cleanPlugin from 'esbuild-plugin-clean';import copyPlugin from 'esbuild-plugin-copy';@@ -124,9 +125,11 @@ if (args.watch) {await monacoBuildTask();await ctx.watch();- const { port } = await ctx.serve({+ const port = isE2E ? 3000 : await detect(3002);++ await ctx.serve({servedir: './local',- port: isE2E ? 3000 : 3002,+ port,});const url = `http://localhost:${port}`;diff --git a/examples/package.json b/examples/package.jsonindex e66b998e1d..5eaff0f6f2 100644--- a/examples/package.json+++ b/examples/package.json@@ -75,6 +75,7 @@"@types/react": "^18.3.5","@types/react-dom": "^18.3.0","@univerjs-infra/shared": "workspace:*",+ "detect-port": "^1.6.1","esbuild": "^0.23.1","esbuild-plugin-clean": "^1.0.1","esbuild-plugin-copy": "^2.1.1",diff --git a/packages/sheets-numfmt/src/components/index.tsx b/packages/sheets-numfmt/src/components/index.tsxindex 1e31cbd671..bb1ea6ca96 100644--- a/packages/sheets-numfmt/src/components/index.tsx+++ b/packages/sheets-numfmt/src/components/index.tsx@@ -14,26 +14,26 @@* limitations under the License.*/-// FIXME: DO NOT USE GLOBAL STYLES-import './index.less';-import { LocaleService, useDependency } from '@univerjs/core';-import type { ISelectProps } from '@univerjs/design';+import { Button, Select } from '@univerjs/design';-import type { FC } from 'react';import React, { useEffect, useMemo, useRef, useState } from 'react';--import type { IBusinessComponentProps } from '../base/types';+import type { ISelectProps } from '@univerjs/design';+import type { FC } from 'react';import { UserHabitCurrencyContext } from '../context/user-habit';+import { useCurrencyOptions } from '../hooks/useCurrencyOptions';import { useNextTick } from '../hooks/useNextTick';import { getCurrencyType } from '../utils/currency';import { AccountingPanel, isAccountingPanel } from './accounting';import { CurrencyPanel, isCurrencyPanel } from './currency';+import { CustomFormat } from './custom-format';import { DatePanel, isDatePanel } from './date';import { GeneralPanel, isGeneralPanel } from './general';import { isThousandthPercentilePanel, ThousandthPercentilePanel } from './thousandth-percentile';-import { CustomFormat } from './custom-format';+import type { IBusinessComponentProps } from '../base/types';+// FIXME: DO NOT USE GLOBAL STYLES+import './index.less';export interface ISheetNumfmtPanelProps {value: { defaultValue: number; defaultPattern: string; row: number; col: number };diff --git a/packages/ui/src/components/custom-label/CustomLabel.tsx b/packages/ui/src/components/custom-label/CustomLabel.tsxindex efaec5db2d..5610de4683 100644--- a/packages/ui/src/components/custom-label/CustomLabel.tsx+++ b/packages/ui/src/components/custom-label/CustomLabel.tsx@@ -15,7 +15,7 @@*/import { ColorKit, LocaleService, useDependency } from '@univerjs/core';-import React, { useEffect, useState } from 'react';+import React, { useEffect, useMemo, useState } from 'react';import { isObservable } from 'rxjs';import type { Observable } from 'rxjs';@@ -35,31 +35,31 @@ export type ICustomLabelProps<T = undefined> = {/*** The component to render toolbar item label and menu item label.* @param props- * @returns*/-export function CustomLabel(props: ICustomLabelProps): JSX.Element | null {+export function CustomLabel(props: ICustomLabelProps): JSX.Element {const { title, icon, label, value, value$ } = props;const localeService = useDependency(LocaleService);const componentManager = useDependency(ComponentManager);- const [realValue, setRealValue] = useState(value);+ const [subscribedValue, setSubscribedValue] = useState(value);const [realIcon, setRealIcon] = useState('');const nodes = [];let index = 0;useEffect(() => {- setRealValue(value);-if (value$) {const subscription = value$.subscribe((v) => {- setRealValue(v);+ setSubscribedValue(v);});return () => {subscription.unsubscribe();};}- }, [value, value$]);+ }, [value$]);+ const realValue = useMemo(() => {+ return value ?? subscribedValue;+ }, [subscribedValue, value]);useEffect(() => {let subscription = null;@@ -77,10 +77,16 @@ export function CustomLabel(props: ICustomLabelProps): JSX.Element | null {}, [icon]);// if value is not valid, use primary color- let isValid = false;- if (realValue && typeof realValue === 'string') {- isValid = new ColorKit(realValue).isValid;- }+ // let isValid = false;+ // if (realValue && typeof realValue === 'string') {+ // isValid = new ColorKit(realValue).isValid;+ // }+ const isValid = useMemo(() => {+ if (realValue && typeof realValue === 'string') {+ return new ColorKit(realValue).isValid;+ }+ return false;+ }, [realValue]);if (icon) {const Icon = componentManager.get(realIcon ?? '');diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex ba04d70726..5a6f2dfa14 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -10,7 +10,7 @@ importers:devDependencies:'@antfu/eslint-config':specifier: 3.5.1- version: 3.5.1(@eslint-react/[email protected]([email protected]([email protected]))([email protected]))(@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))(@vue/[email protected])([email protected]([email protected]([email protected])))([email protected]([email protected]([email protected])))([email protected]([email protected]([email protected])))([email protected]([email protected]))([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected]))+ version: 3.5.1(@eslint-react/[email protected]([email protected]([email protected]))([email protected]))(@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))(@vue/[email protected])([email protected]([email protected]([email protected])))([email protected]([email protected]([email protected])))([email protected]([email protected]([email protected])))([email protected]([email protected]))([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))'@commitlint/cli':specifier: ^19.5.0version: 19.5.0(@types/[email protected])([email protected])@@ -379,6 +379,9 @@ importers:'@univerjs-infra/shared':specifier: workspace:*version: link:../common/shared+ detect-port:+ specifier: ^1.6.1+ version: 1.6.1esbuild:specifier: ^0.23.1version: 0.23.1@@ -5242,6 +5245,10 @@ packages:resolution: {integrity: sha512-qQLMr+8o0WC4FZGQTcJiKBVC59JylcPSrTtk6usvmIDFUOCKegapy1VHQwRbFMOFyb/inzUVqHs+eMYKDM1YeQ==}+ resolution: {integrity: sha512-4B/qKCfeE/ODUaAUpSwfzazo5x29WD4r3vXiWsB7I2mSDAihwEqKO+g8GELZUQSSAo5e1XTYh3ZVfLyxBc12nA==}+ engines: {node: '>= 10.0.0'}+resolution: {integrity: sha512-H0TSyFNDMomMNJQBn8wFV5YC/2eJ+VXECwOadZJT554xP6cODZHPX3H9QMQECxvrgiSOP1pHjy1sMWQVYJOUOA==}engines: {node: '>= 14'}@@ -6170,6 +6177,11 @@ packages:resolution: {integrity: sha512-TLz+x/vEXm/Y7P7wn1EJFNLxYpUD4TgMosxY6fAVJUnJMbupHBOncxyWUG9OpTaH9EBD7uFI5LfEgmMOc54DsA==}engines: {node: '>=8'}+ resolution: {integrity: sha512-CmnVc+Hek2egPx1PeTFVta2W78xy2K/9Rkf6cC4T59S50tVnzKj+tnx5mmx5lwvCkujZ4uRrpRSuV+IVs3f90Q==}+ engines: {node: '>= 4.0.0'}+ hasBin: true+resolution: {integrity: sha512-RWmIqhcFf1lRYBvNmr7qTNuyCt/7/ns2jbpp1+PalgE/rDQcBT0fioSMUpJ93irlUhC5hrg4cYqe6U+0ImW0rA==}@@ -10420,7 +10432,7 @@ snapshots:dependencies:'@babel/runtime': 7.25.0- '@antfu/[email protected](@eslint-react/[email protected]([email protected]([email protected]))([email protected]))(@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))(@vue/[email protected])([email protected]([email protected]([email protected])))([email protected]([email protected]([email protected])))([email protected]([email protected]([email protected])))([email protected]([email protected]))([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected]))':+ '@antfu/[email protected](@eslint-react/[email protected]([email protected]([email protected]))([email protected]))(@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))(@vue/[email protected])([email protected]([email protected]([email protected])))([email protected]([email protected]([email protected])))([email protected]([email protected]([email protected])))([email protected]([email protected]))([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))':dependencies:'@antfu/install-pkg': 0.4.1'@clack/prompts': 0.7.0@@ -10429,7 +10441,7 @@ snapshots:'@typescript-eslint/eslint-plugin': 8.5.0(@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])- '@vitest/eslint-plugin': 1.1.0(@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected]))+ '@vitest/eslint-plugin': 1.1.0(@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))eslint: 9.10.0([email protected])eslint-config-flat-gitignore: 0.3.0([email protected]([email protected]))eslint-flat-config-utils: 0.4.0@@ -10694,7 +10706,7 @@ snapshots:'@babel/helper-split-export-declaration': 7.24.7'@babel/parser': 7.24.7'@babel/types': 7.24.7- debug: 4.3.5+ debug: 4.3.6globals: 11.12.0transitivePeerDependencies:- supports-color@@ -12500,7 +12512,7 @@ snapshots:transitivePeerDependencies:- supports-color- '@vitest/[email protected](@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected]))':+ '@vitest/[email protected](@typescript-eslint/[email protected]([email protected]([email protected]))([email protected]))([email protected]([email protected]))([email protected])([email protected](@types/[email protected])([email protected])([email protected])([email protected])([email protected])([email protected]))':dependencies:eslint: 9.10.0([email protected])optionalDependencies:@@ -12762,6 +12774,8 @@ snapshots:+ [email protected]: {}+dependencies:debug: 4.3.6@@ -13686,6 +13700,13 @@ snapshots:+ dependencies:+ address: 1.2.2+ debug: 4.3.6+ transitivePeerDependencies:+ - supports-color+dependencies:dequal: 2.0.3@@ -15094,7 +15115,7 @@ snapshots:dependencies:agent-base: 7.1.1- debug: 4.3.5+ debug: 4.3.6transitivePeerDependencies:- supports-color