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.

fix(sheet): update internal id (#1825)

Univerfc4cc4cb2db8
diff --git a/examples/src/plugins/debugger/views/test-editor/TestTextEditor.tsx b/examples/src/plugins/debugger/views/test-editor/TestTextEditor.tsx
index 6eabbf5e63..7d09e0d601 100644
--- a/examples/src/plugins/debugger/views/test-editor/TestTextEditor.tsx
+++ b/examples/src/plugins/debugger/views/test-editor/TestTextEditor.tsx
@@ -17,7 +17,7 @@
import React, { useState } from 'react';
import { RangeSelector, TextEditor } from '@univerjs/ui';
-import { IUniverInstanceService } from '@univerjs/core';
+import { createInternalEditorID, IUniverInstanceService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import { Input } from '@univerjs/design';
@@ -54,17 +54,17 @@ export const TestEditorContainer = () => {
<div
style={containerStyle}
>
- <TextEditor id="test-editor-1" placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} style={editorStyle} canvasStyle={{ fontSize: 10 }} value="I found one cent on the roadside." />
+ <TextEditor id={createInternalEditorID('test-editor-1')} placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} style={editorStyle} canvasStyle={{ fontSize: 10 }} value="I found one cent on the roadside." />
<br></br>
- <TextEditor id="test-editor-2" placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} onlyInputFormula={true} style={editorStyle} canvasStyle={{ fontSize: 10 }} />
+ <TextEditor id={createInternalEditorID('test-editor-2')} placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} onlyInputFormula={true} style={editorStyle} canvasStyle={{ fontSize: 10 }} />
<br></br>
- <TextEditor id="test-editor-3" placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} onlyInputRange={true} style={editorStyle} canvasStyle={{ fontSize: 10 }} />
+ <TextEditor id={createInternalEditorID('test-editor-3')} placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} onlyInputRange={true} style={editorStyle} canvasStyle={{ fontSize: 10 }} />
<br></br>
- <TextEditor id="test-editor-4" placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} isSingle={false} onlyInputContent={true} style={{ ...editorStyle, height: '140px' }} canvasStyle={{ fontSize: 14 }} />
+ <TextEditor id={createInternalEditorID('test-editor-4')} placeholder="please input value" openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} isReadonly={readonly} isSingle={false} onlyInputContent={true} style={{ ...editorStyle, height: '140px' }} canvasStyle={{ fontSize: 14 }} />
<br></br>
- <RangeSelector placeholder="please input value" id="test-rangeSelector-1" width={280} openForSheetUnitId={unitId} isReadonly={readonly} openForSheetSubUnitId={sheetId} />
+ <RangeSelector placeholder="please input value" id={createInternalEditorID('test-rangeSelector-1')} width={280} openForSheetUnitId={unitId} isReadonly={readonly} openForSheetSubUnitId={sheetId} />
<br></br>
- <RangeSelector placeholder="please input value" value="I am a wolf man" id="test-rangeSelector-2" isSingleChoice={true} isReadonly={readonly} openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} />
+ <RangeSelector placeholder="please input value" value="I am a wolf man" id={createInternalEditorID('test-rangeSelector-2')} isSingleChoice={true} isReadonly={readonly} openForSheetUnitId={unitId} openForSheetSubUnitId={sheetId} />
<br></br>
<Input placeholder="please input value" allowClear />
<br></br>
diff --git a/packages/core/src/common/const.ts b/packages/core/src/common/const.ts
index 6a5bc0e048..46c68bd3f5 100644
--- a/packages/core/src/common/const.ts
+++ b/packages/core/src/common/const.ts
@@ -19,3 +19,11 @@ export const DOCS_NORMAL_EDITOR_UNIT_ID_KEY = '__defaultDocumentNormalEditorSpec
export const DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY = '__defaultDocumentFormulaBarEditorSpecialUnitId_20231012__';
export const DEFAULT_EMPTY_DOCUMENT_VALUE = '\r\n';
+
+export function createInternalEditorID(id: string) {
+ return `__internalEditorId__${id}`;
+}
+
+export function isInternalEditorID(id: string) {
+ return id.startsWith('__');
+}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index f1ffe51d21..b8ce3e9da4 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -23,6 +23,8 @@ export {
DEFAULT_EMPTY_DOCUMENT_VALUE,
DOCS_FORMULA_BAR_EDITOR_UNIT_ID_KEY,
DOCS_NORMAL_EDITOR_UNIT_ID_KEY,
+ createInternalEditorID,
+ isInternalEditorID,
} from './common/const';
export { throttle } from './common/function';
export { MemoryCursor } from './common/memory-cursor';
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/colorScale.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/colorScale.tsx
index 1a5d9babe5..1da1a0670f 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/colorScale.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/colorScale.tsx
@@ -16,7 +16,7 @@
import React, { useEffect, useMemo, useState } from 'react';
import { useDependency } from '@wendellhu/redi/react-bindings';
-import { IUniverInstanceService, LocaleService } from '@univerjs/core';
+import { createInternalEditorID, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { InputNumber, Select } from '@univerjs/design';
import { TextEditor } from '@univerjs/ui';
import { CFRuleType, CFValueType, createDefaultValueByValueType, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
@@ -55,7 +55,7 @@ const TextInput = (props: { id: string; type: CFValueType | 'none';value: number
<TextEditor
openForSheetSubUnitId={subUnitId}
openForSheetUnitId={unitId}
- id={`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_colo_scale_${id}`}
+ id={createInternalEditorID(`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_colo_scale_${id}`)}
value={formulaInitValue}
style={{ maxWidth: '50%', marginLeft: 4 }}
canvasStyle={{ fontSize: 10 }}
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx
index 2bb5082e61..a770d8037c 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/dataBar.tsx
@@ -17,7 +17,7 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import { InputNumber, Radio, RadioGroup, Select } from '@univerjs/design';
import { useDependency } from '@wendellhu/redi/react-bindings';
-import { IUniverInstanceService, LocaleService } from '@univerjs/core';
+import { createInternalEditorID, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { TextEditor } from '@univerjs/ui';
import { CFRuleType, CFValueType, createDefaultValueByValueType, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
import type { IConditionalFormattingRuleConfig, IValueConfig } from '@univerjs/sheets-conditional-formatting';
@@ -50,7 +50,7 @@ const InputText = (props: { disabled?: boolean; id: string; className: string; t
const v = String(_value.current).startsWith('=') ? String(_value.current) || '' : '=';
return (
<TextEditor
- id={`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_data_bar_${id}`}
+ id={createInternalEditorID(`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_data_bar_${id}`)}
value={v}
openForSheetSubUnitId={subUnitId}
openForSheetUnitId={unitId}
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/formula.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/formula.tsx
index 5adf9bf522..9d4bd38648 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/formula.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/formula.tsx
@@ -16,7 +16,7 @@
import React, { useEffect, useState } from 'react';
import { useDependency } from '@wendellhu/redi/react-bindings';
-import { IUniverInstanceService, LocaleService } from '@univerjs/core';
+import { createInternalEditorID, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { TextEditor } from '@univerjs/ui';
import { CFRuleType, CFSubRuleType, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
import type { IAverageHighlightCell, IConditionalFormattingRuleConfig, IHighlightCell, IRankHighlightCell } from '@univerjs/sheets-conditional-formatting';
@@ -72,7 +72,7 @@ export const FormulaStyleEditor = (props: IStyleEditorProps) => {
<div className={`${stylesBase.title} ${stylesBase.mTBase}`}>{localeService.t('sheet.cf.panel.styleRule')}</div>
<div className={`${stylesBase.mTSm}`}>
<TextEditor
- id={`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_formula`}
+ id={createInternalEditorID(`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_formula`)}
openForSheetSubUnitId={worksheet.getSheetId()}
openForSheetUnitId={workbook.getUnitId()}
value={formula}
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/iconSet.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/iconSet.tsx
index 73e221cdbc..fd839dfe19 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/iconSet.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/iconSet.tsx
@@ -22,7 +22,7 @@ import { MoreDownSingle, SlashSingle } from '@univerjs/icons';
import { Checkbox, Dropdown, InputNumber, Select } from '@univerjs/design';
import { useDependency } from '@wendellhu/redi/react-bindings';
-import { IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';
+import { createInternalEditorID, IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';
import { TextEditor } from '@univerjs/ui';
import type { IIconSet, IIconType } from '@univerjs/sheets-conditional-formatting';
import { CFNumberOperator, CFRuleType, CFSubRuleType, CFValueType, compareWithNumber, createDefaultValue, EMPTY_ICON_TYPE, getOppositeOperator, iconGroup, iconMap, SHEET_CONDITIONAL_FORMATTING_PLUGIN } from '@univerjs/sheets-conditional-formatting';
@@ -61,7 +61,7 @@ const TextInput = (props: { id: number; type: CFValueType; value: number | strin
)
: (
<TextEditor
- id={`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_icon_set_${props.id}`}
+ id={createInternalEditorID(`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_icon_set_${props.id}`)}
value={String(props.value).startsWith('=') ? String(props.value) : '='}
openForSheetSubUnitId={subUnitId}
openForSheetUnitId={unitId}
diff --git a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx
index 95d49098e4..d656a1d4d6 100644
--- a/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx
+++ b/packages/sheets-conditional-formatting-ui/src/components/panel/rule-edit/index.tsx
@@ -16,7 +16,7 @@
import React, { useEffect, useMemo, useRef, useState } from 'react';
import type { IRange, IUnitRange } from '@univerjs/core';
-import { ICommandService, InterceptorManager, IUniverInstanceService, LocaleService } from '@univerjs/core';
+import { createInternalEditorID, ICommandService, InterceptorManager, IUniverInstanceService, LocaleService } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import { serializeRange } from '@univerjs/engine-formula';
import { Button, Select } from '@univerjs/design';
@@ -215,7 +215,7 @@ export const RuleEdit = (props: IRuleEditProps) => {
<div className={styles.cfRuleStyleEditor}>
<div className={styleBase.title}>{localeService.t('sheet.cf.panel.range')}</div>
<div className={`${styleBase.mTBase}`}>
- <RangeSelector placeholder={localeService.t('sheet.cf.form.rangeSelector')} width={'100%' as unknown as number} openForSheetSubUnitId={subUnitId} openForSheetUnitId={unitId} value={rangeString} id={`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_rangeSelector`} onChange={onRangeSelectorChange} />
+ <RangeSelector placeholder={localeService.t('sheet.cf.form.rangeSelector')} width={'100%' as unknown as number} openForSheetSubUnitId={subUnitId} openForSheetUnitId={unitId} value={rangeString} id={createInternalEditorID(`${SHEET_CONDITIONAL_FORMATTING_PLUGIN}_rangeSelector`)} onChange={onRangeSelectorChange} />
</div>
<div className={styleBase.title}>{localeService.t('sheet.cf.panel.styleType')}</div>
<div className={styleBase.mTBase}>
diff --git a/packages/sheets-data-validation/src/views/detail/index.tsx b/packages/sheets-data-validation/src/views/detail/index.tsx
index e313e45772..c695e68244 100644
--- a/packages/sheets-data-validation/src/views/detail/index.tsx
+++ b/packages/sheets-data-validation/src/views/detail/index.tsx
@@ -15,7 +15,7 @@
*/
import type { DataValidationOperator, IDataValidationRuleBase, IDataValidationRuleOptions, IExecutionOptions, ISheetDataValidationRule, IUnitRange } from '@univerjs/core';
-import { DataValidationType, debounce, ICommandService, isUnitRangesEqual, isValidRange, LocaleService, RedoCommand, shallowEqual, UndoCommand } from '@univerjs/core';
+import { createInternalEditorID, DataValidationType, debounce, ICommandService, isUnitRangesEqual, isValidRange, LocaleService, RedoCommand, shallowEqual, UndoCommand } from '@univerjs/core';
import type { IUpdateDataValidationSettingCommandParams } from '@univerjs/data-validation';
import { DataValidationModel, DataValidatorRegistryScope, DataValidatorRegistryService, getRuleOptions, getRuleSetting, RemoveDataValidationCommand, TWO_FORMULA_OPERATOR_COUNT, UpdateDataValidationOptionsCommand, UpdateDataValidationSettingCommand } from '@univerjs/data-validation';
import { Button, FormLayout, Select } from '@univerjs/design';
@@ -211,7 +211,7 @@ export function DataValidationDetail() {
key={key}
className={styles.dataValidationDetailFormItem}
value={rangeStr}
- id="data-validation-detail"
+ id={createInternalEditorID('data-validation-detail')}
openForSheetUnitId={unitId}
openForSheetSubUnitId={subUnitId}
onChange={(newRange) => {
diff --git a/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx
index 974546b059..39fb543058 100644
--- a/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx
+++ b/packages/sheets-data-validation/src/views/formula-input/custom-formula-input.tsx
@@ -19,6 +19,7 @@ import React from 'react';
import { TextEditor } from '@univerjs/ui';
import type { IFormulaInputProps } from '@univerjs/data-validation';
+import { createInternalEditorID } from '@univerjs/core';
export function CustomFormulaInput(props: IFormulaInputProps) {
const { unitId, subUnitId, value, onChange, showError, validResult } = props;
@@ -28,7 +29,7 @@ export function CustomFormulaInput(props: IFormulaInputProps) {
<FormLayout error={formula1Res}>
<TextEditor
value={value?.formula1 ?? ''}
- id={`dataValidation-custom-formula-${unitId}-${subUnitId}`}
+ id={createInternalEditorID(`dataValidation-custom-formula-${unitId}-${subUnitId}`)}
onChange={(newValue) => {
onChange?.({
...value,
diff --git a/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
index 7ff4dc3b09..80eb5d2e57 100644
--- a/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
+++ b/packages/sheets-data-validation/src/views/formula-input/list-formula-input.tsx
@@ -20,7 +20,7 @@ import { DraggableList, FormLayout, Input, Radio, RadioGroup, Select } from '@un
import { deserializeRangeWithSheet, isReferenceString, serializeRangeWithSheet } from '@univerjs/engine-formula';
import { useDependency } from '@wendellhu/redi/react-bindings';
import type { IRange } from '@univerjs/core';
-import { IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';
+import { createInternalEditorID, IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';
import type { IFormulaInputProps } from '@univerjs/data-validation';
import { DeleteSingle, IncreaseSingle, SequenceSingle } from '@univerjs/icons';
import cs from 'clsx';
@@ -272,7 +272,7 @@ export function ListFormulaInput(props: IFormulaInputProps) {
<>
<FormLayout error={formula1Res}>
<RangeSelector
- id={`list-ref-range-${unitId}-${subUnitId}`}
+ id={createInternalEditorID(`list-ref-range-${unitId}-${subUnitId}`)}
value={refRange}
openForSheetUnitId={unitId}
openForSheetSubUnitId={subUnitId}
diff --git a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx
index 01aa90f6af..67a7289b8a 100644
--- a/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx
+++ b/packages/sheets-ui/src/views/defined-name/DefinedNameInput.tsx
@@ -18,7 +18,7 @@ import React, { useEffect, useState } from 'react';
import { RangeSelector, TextEditor } from '@univerjs/ui';
import type { IUnitRange, Nullable } from '@univerjs/core';
-import { AbsoluteRefType, IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';
+import { AbsoluteRefType, createInternalEditorID, IUniverInstanceService, LocaleService, Tools } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import { Button, Input, Radio, RadioGroup, Select } from '@univerjs/design';
import { IDefinedNamesService, type IDefinedNamesServiceParam, IFunctionService, isReferenceString, LexerTreeBuilder, operatorToken, serializeRangeToRefString } from '@univerjs/engine-formula';
@@ -215,10 +215,10 @@ export const DefinedNameInput = (props: IDefinedNameInputProps) => {
</RadioGroup>
</div>
<div style={{ display: typeValue === 'range' ? 'block' : 'none' }}>
- <RangeSelector key={`${inputId}-rangeSelector`} value={formulaOrRefStringValue} onValid={setValidFormulaOrRange} onChange={rangeSelectorChange} placeholder={localeService.t('definedName.inputRangePlaceholder')} id={`${inputId}-rangeSelector`} width="99%" openForSheetUnitId={unitId} />
+ <RangeSelector key={`${inputId}-rangeSelector`} value={formulaOrRefStringValue} onValid={setValidFormulaOrRange} onChange={rangeSelectorChange} placeholder={localeService.t('definedName.inputRangePlaceholder')} id={createInternalEditorID(`${inputId}-rangeSelector`)} width="99%" openForSheetUnitId={unitId} />
</div>
<div style={{ display: typeValue === 'range' ? 'none' : 'block' }}>
- <TextEditor key={`${inputId}-editor`} value={formulaOrRefStringValue} onValid={setValidFormulaOrRange} onChange={formulaEditorChange} id={`${inputId}-editor`} placeholder={localeService.t('definedName.inputFormulaPlaceholder')} openForSheetUnitId={unitId} onlyInputFormula={true} style={{ width: '99%' }} canvasStyle={{ fontSize: 10 }} />
+ <TextEditor key={`${inputId}-editor`} value={formulaOrRefStringValue} onValid={setValidFormulaOrRange} onChange={formulaEditorChange} id={createInternalEditorID(`${inputId}-editor`)} placeholder={localeService.t('definedName.inputFormulaPlaceholder')} openForSheetUnitId={unitId} onlyInputFormula={true} style={{ width: '99%' }} canvasStyle={{ fontSize: 10 }} />
</div>
<div>
<Select style={widthStyle} value={localSheetIdValue} options={options} onChange={setLocalSheetIdValue} />
diff --git a/packages/ui/src/components/editor/TextEditor.tsx b/packages/ui/src/components/editor/TextEditor.tsx
index a43e7310fa..e4f3c0a4ce 100644
--- a/packages/ui/src/components/editor/TextEditor.tsx
+++ b/packages/ui/src/components/editor/TextEditor.tsx
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import { debounce, type IDocumentData, LocaleService, type Nullable } from '@univerjs/core';
+import { debounce, type IDocumentData, isInternalEditorID, LocaleService, type Nullable } from '@univerjs/core';
import { useDependency } from '@wendellhu/redi/react-bindings';
import React, { useEffect, useRef, useState } from 'react';
import { Popup } from '@univerjs/design';
@@ -129,6 +129,10 @@ export function TextEditor(props: ITextEditorProps & Omit<MyComponentProps, 'onC
const [active, setActive] = useState(false);
+ if (!isInternalEditorID(id)) {
+ throw new Error('Invalid editor ID');
+ }
+
useEffect(() => {
const editor = editorRef.current;