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(docs-ui): limit list maxLevel to 3 when in table & set line-through style on checklist (#3096)

zhangw9a62d774a0ff
diff --git a/packages/core/src/docs/data-model/document-data-model.ts b/packages/core/src/docs/data-model/document-data-model.ts
index 4d73dea313..6a4f924f5f 100644
--- a/packages/core/src/docs/data-model/document-data-model.ts
+++ b/packages/core/src/docs/data-model/document-data-model.ts
@@ -23,6 +23,7 @@ import type {
IDocumentRenderConfig,
IDocumentStyle,
IDrawings,
+ IListData,
} from '../../types/interfaces/i-document-data';
import type { IPaddingData } from '../../types/interfaces/i-style-data';
import { UnitModel, UniverInstanceType } from '../../common/unit';
@@ -30,6 +31,7 @@ import { getBodySlice, SliceBodyType } from './text-x/utils';
import { getEmptySnapshot } from './empty-snapshot';
import type { JSONXActions } from './json-x/json-x';
import { JSONX } from './json-x/json-x';
+import { PRESET_LIST_TYPE } from './preset-list-type';
export const DEFAULT_DOC = {
id: 'default_doc',
@@ -106,6 +108,16 @@ class DocumentDataModelSimple extends UnitModel<IDocumentData, UniverInstanceTyp
return this.snapshot;
}
+ getBulletPresetList() {
+ const customLists = this.snapshot.lists ?? {};
+ const lists: Record<string, IListData> = {
+ ...PRESET_LIST_TYPE,
+ ...customLists,
+ };
+
+ return lists;
+ }
+
updateDocumentId(unitId: string) {
this.snapshot.id = unitId;
}
diff --git a/packages/core/src/docs/data-model/preset-list-type.ts b/packages/core/src/docs/data-model/preset-list-type.ts
index e43837eeab..e013f427f1 100644
--- a/packages/core/src/docs/data-model/preset-list-type.ts
+++ b/packages/core/src/docs/data-model/preset-list-type.ts
@@ -73,12 +73,12 @@ export enum PresetListType {
}
const orderListSymbolMap = {
- 'a)': { glyphFormat: ' %1)', glyphType: GlyphType.DECIMAL },
- '1.': { glyphFormat: ' %1.', glyphType: GlyphType.DECIMAL },
- 'a.': { glyphFormat: ' %1.', glyphType: GlyphType.LOWER_LETTER },
- 'A.': { glyphFormat: ' %1.', glyphType: GlyphType.UPPER_LETTER },
- 'i.': { glyphFormat: ' %1.', glyphType: GlyphType.LOWER_ROMAN },
- 'I.': { glyphFormat: ' %1.', glyphType: GlyphType.UPPER_LETTER },
+ 'a)': { glyphFormat: '%1)', glyphType: GlyphType.DECIMAL },
+ '1.': { glyphFormat: '%1.', glyphType: GlyphType.DECIMAL },
+ 'a.': { glyphFormat: '%1.', glyphType: GlyphType.LOWER_LETTER },
+ 'A.': { glyphFormat: '%1.', glyphType: GlyphType.UPPER_LETTER },
+ 'i.': { glyphFormat: '%1.', glyphType: GlyphType.LOWER_ROMAN },
+ 'I.': { glyphFormat: '%1.', glyphType: GlyphType.UPPER_LETTER },
};
type BulletSymbols = [string, string, string];
@@ -117,7 +117,7 @@ const orderListFactory = (options: { glyphFormat: string; glyphType: GlyphType }
}));
};
-const checkListFactory = (symbol: string, textStyle: ITextStyle): INestingLevel[] => {
+const checkListFactory = (symbol: string, textStyle?: ITextStyle): INestingLevel[] => {
return Array(9).fill(0).map((_, i) => ({
glyphFormat: ` %${i + 1}`,
glyphSymbol: symbol,
@@ -163,96 +163,89 @@ export const PRESET_LIST_TYPE: Record<string, IListData> = {
[PresetListType.ORDER_LIST]: {
listType: PresetListType.ORDER_LIST,
nestingLevel: orderListFactory([
- { glyphFormat: ' %1.', glyphType: GlyphType.DECIMAL },
- { glyphFormat: ' %2.', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %3.', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %4.', glyphType: GlyphType.DECIMAL },
- { glyphFormat: ' %5.', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %6.', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %7.', glyphType: GlyphType.DECIMAL },
- { glyphFormat: ' %8.', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %9.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%1.', glyphType: GlyphType.DECIMAL },
+ { glyphFormat: '%2.', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%3.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%4.', glyphType: GlyphType.DECIMAL },
+ { glyphFormat: '%5.', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%6.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%7.', glyphType: GlyphType.DECIMAL },
+ { glyphFormat: '%8.', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%9.', glyphType: GlyphType.LOWER_ROMAN },
]),
} as IListData,
[PresetListType.ORDER_LIST_1]: {
listType: PresetListType.ORDER_LIST,
nestingLevel: orderListFactory([
- { glyphFormat: ' %1)', glyphType: GlyphType.DECIMAL },
- { glyphFormat: ' %2)', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %3)', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %4)', glyphType: GlyphType.DECIMAL },
- { glyphFormat: ' %5)', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %6)', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %7)', glyphType: GlyphType.DECIMAL },
- { glyphFormat: ' %8)', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %9)', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%1)', glyphType: GlyphType.DECIMAL },
+ { glyphFormat: '%2)', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%3)', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%4)', glyphType: GlyphType.DECIMAL },
+ { glyphFormat: '%5)', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%6)', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%7)', glyphType: GlyphType.DECIMAL },
+ { glyphFormat: '%8)', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%9)', glyphType: GlyphType.LOWER_ROMAN },
]),
} as IListData,
[PresetListType.ORDER_LIST_2]: {
listType: PresetListType.ORDER_LIST,
nestingLevel: orderListFactory([
- ' %1.',
- ' %1.%2.',
- ' %1.%2.%3.',
- ' %1.%2.%3.%4.',
- ' %1.%2.%3.%4.%5.',
- ' %1.%2.%3.%4.%5.%6.',
- ' %1.%2.%3.%4.%5.%6.%7.',
+ '%1.',
+ '%1.%2.',
+ '%1.%2.%3.',
+ '%1.%2.%3.%4.',
+ '%1.%2.%3.%4.%5.',
+ '%1.%2.%3.%4.%5.%6.',
+ '%1.%2.%3.%4.%5.%6.%7.',
].map((format) => ({ glyphFormat: format, glyphType: GlyphType.DECIMAL }))),
} as IListData,
[PresetListType.ORDER_LIST_3]: {
listType: PresetListType.ORDER_LIST,
nestingLevel: orderListFactory([
- { glyphFormat: ' %1.', glyphType: GlyphType.UPPER_LETTER },
- { glyphFormat: ' %2.', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %3.', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %4.', glyphType: GlyphType.UPPER_LETTER },
- { glyphFormat: ' %5.', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %6.', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %7.', glyphType: GlyphType.UPPER_LETTER },
- { glyphFormat: ' %8.', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %9.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%1.', glyphType: GlyphType.UPPER_LETTER },
+ { glyphFormat: '%2.', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%3.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%4.', glyphType: GlyphType.UPPER_LETTER },
+ { glyphFormat: '%5.', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%6.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%7.', glyphType: GlyphType.UPPER_LETTER },
+ { glyphFormat: '%8.', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%9.', glyphType: GlyphType.LOWER_ROMAN },
]),
} as IListData,
[PresetListType.ORDER_LIST_4]: {
listType: PresetListType.ORDER_LIST,
nestingLevel: orderListFactory([
- { glyphFormat: ' %1.', glyphType: GlyphType.UPPER_LETTER },
- { glyphFormat: ' %2.', glyphType: GlyphType.DECIMAL },
- { glyphFormat: ' %3.', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %4.', glyphType: GlyphType.UPPER_LETTER },
- { glyphFormat: ' %5.', glyphType: GlyphType.DECIMAL },
- { glyphFormat: ' %6.', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %7.', glyphType: GlyphType.UPPER_LETTER },
- { glyphFormat: ' %8.', glyphType: GlyphType.DECIMAL },
- { glyphFormat: ' %9.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%1.', glyphType: GlyphType.UPPER_LETTER },
+ { glyphFormat: '%2.', glyphType: GlyphType.DECIMAL },
+ { glyphFormat: '%3.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%4.', glyphType: GlyphType.UPPER_LETTER },
+ { glyphFormat: '%5.', glyphType: GlyphType.DECIMAL },
+ { glyphFormat: '%6.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%7.', glyphType: GlyphType.UPPER_LETTER },
+ { glyphFormat: '%8.', glyphType: GlyphType.DECIMAL },
+ { glyphFormat: '%9.', glyphType: GlyphType.LOWER_ROMAN },
]),
} as IListData,
[PresetListType.ORDER_LIST_5]: {
listType: PresetListType.ORDER_LIST,
nestingLevel: orderListFactory([
- { glyphFormat: ' %1.', glyphType: GlyphType.DECIMAL_ZERO },
- { glyphFormat: ' %2.', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %3.', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %4.', glyphType: GlyphType.DECIMAL_ZERO },
- { glyphFormat: ' %5.', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %6.', glyphType: GlyphType.LOWER_ROMAN },
- { glyphFormat: ' %7.', glyphType: GlyphType.DECIMAL_ZERO },
- { glyphFormat: ' %8.', glyphType: GlyphType.LOWER_LETTER },
- { glyphFormat: ' %9.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%1.', glyphType: GlyphType.DECIMAL_ZERO },
+ { glyphFormat: '%2.', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%3.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%4.', glyphType: GlyphType.DECIMAL_ZERO },
+ { glyphFormat: '%5.', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%6.', glyphType: GlyphType.LOWER_ROMAN },
+ { glyphFormat: '%7.', glyphType: GlyphType.DECIMAL_ZERO },
+ { glyphFormat: '%8.', glyphType: GlyphType.LOWER_LETTER },
+ { glyphFormat: '%9.', glyphType: GlyphType.LOWER_ROMAN },
]),
} as IListData,
[PresetListType.CHECK_LIST]: {
listType: PresetListType.CHECK_LIST,
- nestingLevel: checkListFactory(
- '\u2610',
- {
- st: {
- s: BooleanNumber.FALSE,
- },
- }
- ),
+ nestingLevel: checkListFactory('\u2610'),
} as IListData,
[PresetListType.CHECK_LIST_CHECKED]: {
listType: PresetListType.CHECK_LIST_CHECKED,
diff --git a/packages/core/src/types/interfaces/i-document-data.ts b/packages/core/src/types/interfaces/i-document-data.ts
index c82d7edc38..9bc6cffc2b 100644
--- a/packages/core/src/types/interfaces/i-document-data.ts
+++ b/packages/core/src/types/interfaces/i-document-data.ts
@@ -188,8 +188,6 @@ export interface IListData {
*/
export interface INestingLevel {
paragraphProperties?: IParagraphStyle;
- paragraphTextStyle?: ITextStyle;
-
bulletAlignment: BulletAlignment; // ordered list support lvlJc
// The glyph format contains one or more placeholders, and these placeholder are replaced with the appropriate values depending on the glyphType or glyphSymbol. The placeholders follow the pattern %[nestingLevel]. Furthermore, placeholders can have prefixes and suffixes. Thus, the glyph format follows the pattern <prefix>%[nestingLevel]<suffix>. Note that the prefix and suffix are optional and can be arbitrary strings.
// <prefix>%[nestingLevel]<suffix>
diff --git a/packages/docs/src/basics/paragraph.ts b/packages/docs/src/basics/paragraph.ts
new file mode 100644
index 0000000000..8d7cef2ac7
--- /dev/null
+++ b/packages/docs/src/basics/paragraph.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 type { ICustomTable, IParagraph } from '@univerjs/core';
+
+export function hasParagraphInTable(paragraph: IParagraph, tables: ICustomTable[]) {
+ return tables.some((table) => paragraph.startIndex > table.startIndex && paragraph.startIndex < table.endIndex);
+}
diff --git a/packages/docs/src/commands/commands/list.command.ts b/packages/docs/src/commands/commands/list.command.ts
index b9e5c1ee31..f142a93c69 100644
--- a/packages/docs/src/commands/commands/list.command.ts
+++ b/packages/docs/src/commands/commands/list.command.ts
@@ -16,7 +16,6 @@
import type { ICommand, IListData, IMutationInfo, IParagraph, IParagraphRange, ISectionBreak } from '@univerjs/core';
import {
- BooleanNumber,
CommandType,
GridType,
ICommandService,
@@ -38,6 +37,7 @@ import { serializeDocRange, TextSelectionManagerService } from '../../services/t
import type { IRichTextEditingMutationParams } from '../mutations/core-editing.mutation';
import { RichTextEditingMutation } from '../mutations/core-editing.mutation';
import { getRichTextEditPath } from '../util';
+import { hasParagraphInTable } from '../../basics/paragraph';
interface IListOperationCommandParams {
listType: PresetListType;
@@ -130,13 +130,7 @@ export const ListOperationCommand: ICommand<IListOperationCommandParams> = {
const { indentFirstLine, snapToGrid, indentStart } = paragraphStyle;
const paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {};
const { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties;
- const bulletParagraphTextStyle = paragraphProperties.textStyle;
const { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES };
- const bulletParagraphTextStyleEmpty = Object.keys(bulletParagraphTextStyle ?? {})
- .reduce((acc: Record<string, any>, key) => {
- acc[key] = undefined;
- return acc;
- }, {});
const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
textX.push({
@@ -157,10 +151,6 @@ export const ListOperationCommand: ICommand<IListOperationCommandParams> = {
...paragraphStyle,
hanging: undefined,
indentStart: indentStart ? { v: Math.max(0, getNumberUnitValue(indentStart, charSpaceApply) + getNumberUnitValue(listHanging, charSpaceApply) - getNumberUnitValue(listIndentStart, charSpaceApply)) } : undefined,
- textStyle: {
- ...paragraphStyle.textStyle,
- ...bulletParagraphTextStyleEmpty,
- },
},
startIndex: 0,
}
@@ -168,17 +158,6 @@ export const ListOperationCommand: ICommand<IListOperationCommandParams> = {
startIndex: 0,
paragraphStyle: {
...paragraphStyle,
- textStyle: {
- ...paragraphStyle.textStyle,
- ...bulletParagraphTextStyle,
- ...bullet?.listType === PresetListType.CHECK_LIST_CHECKED
- ? {
- st: {
- s: BooleanNumber.FALSE,
- },
- }
- : null,
- },
indentFirstLine: undefined,
hanging: listHanging,
indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) },
@@ -220,7 +199,7 @@ interface IChangeListTypeCommandParams {
export const ChangeListTypeCommand: ICommand<IChangeListTypeCommandParams> = {
id: 'doc.command.change-list-type',
type: CommandType.COMMAND,
- // eslint-disable-next-line max-lines-per-function, complexity
+ // eslint-disable-next-line max-lines-per-function
handler: (accessor, params: IChangeListTypeCommandParams) => {
const textSelectionManagerService = accessor.get(TextSelectionManagerService);
const univerInstanceService = accessor.get(IUniverInstanceService);
@@ -276,7 +255,7 @@ export const ChangeListTypeCommand: ICommand<IChangeListTypeCommandParams> = {
const { startIndex, paragraphStyle = {}, bullet } = paragraph;
const { indentFirstLine, snapToGrid, indentStart } = paragraphStyle;
const paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {};
- const bulletParagraphTextStyle = paragraphProperties.textStyle;
+ // const bulletParagraphTextStyle = paragraphProperties.textStyle;
const { hanging: listHanging, indentStart: listIndentStart } = paragraphProperties;
const { charSpace, gridType } = findNearestSectionBreak(startIndex, sectionBreaks) || { charSpace: 0, gridType: GridType.LINES };
@@ -298,17 +277,6 @@ export const ChangeListTypeCommand: ICommand<IChangeListTypeCommandParams> = {
startIndex: 0,
paragraphStyle: {
...paragraphStyle,
- textStyle: {
- ...paragraphStyle.textStyle,
- ...bulletParagraphTextStyle,
- ...bullet?.listType === PresetListType.CHECK_LIST_CHECKED
- ? {
- st: {
- s: BooleanNumber.FALSE,
- },
- }
- : null,
- },
indentFirstLine: undefined,
hanging: listHanging,
indentStart: { v: getNumberUnitValue(listIndentStart, charSpaceApply) - getNumberUnitValue(listHanging, charSpaceApply) + getNumberUnitValue(indentFirstLine, charSpaceApply) + getNumberUnitValue(indentStart, charSpaceApply) },
@@ -375,7 +343,7 @@ export const ChangeListNestingLevelCommand: ICommand<IChangeListNestingLevelComm
}
const { segmentId } = activeRange;
-
+ const tables = docDataModel.getBody()?.tables ?? [];
const selections = textSelectionManagerService.getDocRanges() ?? [];
const paragraphs = docDataModel.getSelfOrHeaderFooterModel(segmentId).getBody()?.paragraphs;
const serializedSelections = selections.map(serializeDocRange);
@@ -413,6 +381,7 @@ export const ChangeListNestingLevelCommand: ICommand<IChangeListNestingLevelComm
for (const paragraph of currentParagraphs) {
const { startIndex, paragraphStyle = {}, bullet } = paragraph;
+ const isInTable = hasParagraphInTable(paragraph, tables);
textX.push({
t: TextXActionType.RETAIN,
@@ -422,7 +391,10 @@ export const ChangeListNestingLevelCommand: ICommand<IChangeListNestingLevelComm
if (bullet) {
const listType = bullet.listType as keyof typeof lists;
- const maxLevel = lists[listType].nestingLevel.length - 1;
+ let maxLevel = lists[listType].nestingLevel.length - 1;
+ if (isInTable) {
+ maxLevel = Math.min(maxLevel, 2);
+ }
textX.push({
t: TextXActionType.RETAIN,
@@ -518,7 +490,7 @@ export interface IToggleCheckListCommandParams {
export const ToggleCheckListCommand: ICommand<IToggleCheckListCommandParams> = {
id: 'doc.command.toggle-check-list',
type: CommandType.COMMAND,
- // eslint-disable-next-line max-lines-per-function
+
handler: (accessor, params) => {
if (!params) {
return false;
@@ -558,19 +530,10 @@ export const ToggleCheckListCommand: ICommand<IToggleCheckListCommandParams> = {
const textX = new TextX();
const jsonX = JSONX.getInstance();
- const customLists = docDataModel.getSnapshot().lists ?? {};
-
- const lists: Record<string, IListData> = {
- ...PRESET_LIST_TYPE,
- ...customLists,
- };
-
const { startIndex, paragraphStyle = {} } = currentParagraph;
const listType = currentParagraph.bullet.listType === PresetListType.CHECK_LIST ?
PresetListType.CHECK_LIST_CHECKED
: PresetListType.CHECK_LIST;
- const paragraphProperties = lists[listType].nestingLevel[0].paragraphProperties || {};
- const bulletParagraphTextStyle = paragraphProperties.textStyle;
textX.push({
t: TextXActionType.RETAIN,
@@ -586,13 +549,7 @@ export const ToggleCheckListCommand: ICommand<IToggleCheckListCommandParams> = {
paragraphs: [
{
...currentParagraph,
- paragraphStyle: {
- ...paragraphStyle,
- textStyle: {
- ...paragraphStyle.textStyle,
- ...bulletParagraphTextStyle,
- },
- },
+ paragraphStyle,
startIndex: 0,
bullet: {
...currentParagraph.bullet,
diff --git a/packages/docs/src/index.ts b/packages/docs/src/index.ts
index f70bf09150..4690d8eb88 100644
--- a/packages/docs/src/index.ts
+++ b/packages/docs/src/index.ts
@@ -18,6 +18,7 @@ export { getCustomRangesInterestsWithRange } from './basics/custom-range';
export { getParagraphsInRange, getParagraphsInRanges } from './commands/commands/list.command';
export { replaceSelectionFactory } from './basics/replace';
export { makeSelection, getSelectionText, getDeleteSelection, getInsertSelection, isSegmentIntersects } from './basics/selection';
+export { hasParagraphInTable } from './basics/paragraph';
export type { IDocObjectParam } from './basics/component-tools';
export { getDocObject, neoGetDocObject, getDocObjectById } from './basics/component-tools';
export * from './basics/docs-view-key';
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/language-ruler.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/language-ruler.ts
index 9e7e26b358..7dd88805d4 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/language-ruler.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/language-ruler.ts
@@ -14,7 +14,7 @@
* limitations under the License.
*/
-import type { IParagraphStyle } from '@univerjs/core';
+import type { IParagraph } from '@univerjs/core';
import type { ISectionBreakConfig } from '../../../../../basics/interfaces';
import { EMOJI_REG, hasArabic, hasSpace, hasTibetan, startWithEmoji } from '../../../../../basics/tools';
@@ -31,7 +31,7 @@ export function otherHandler(
viewModel: DocumentViewModel,
paragraphNode: DataStreamTreeNode,
sectionBreakConfig: ISectionBreakConfig,
- paragraphStyle: IParagraphStyle
+ paragraph: IParagraph
) {
const glyphGroup = [];
let step = 0;
@@ -43,7 +43,7 @@ export function otherHandler(
break;
}
- const config = getFontCreateConfig(index + i, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
+ const config = getFontCreateConfig(index + i, viewModel, paragraphNode, sectionBreakConfig, paragraph);
const glyph = createSkeletonLetterGlyph(newChar, config);
glyphGroup.push(glyph);
@@ -62,10 +62,10 @@ export function ArabicHandler(
viewModel: DocumentViewModel,
paragraphNode: DataStreamTreeNode,
sectionBreakConfig: ISectionBreakConfig,
- paragraphStyle: IParagraphStyle
+ paragraph: IParagraph
) {
// 组合阿拉伯语的词组
- const config = getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
+ const config = getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig, paragraph);
const glyph = [];
let step = 0;
@@ -91,9 +91,9 @@ export function emojiHandler(
viewModel: DocumentViewModel,
paragraphNode: DataStreamTreeNode,
sectionBreakConfig: ISectionBreakConfig,
- paragraphStyle: IParagraphStyle
+ paragraph: IParagraph
) {
- const config = getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
+ const config = getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig, paragraph);
const match = charArray.match(EMOJI_REG);
return {
@@ -108,10 +108,10 @@ export function TibetanHandler(
viewModel: DocumentViewModel,
paragraphNode: DataStreamTreeNode,
sectionBreakConfig: ISectionBreakConfig,
- paragraphStyle: IParagraphStyle
+ paragraph: IParagraph
) {
// 组合藏语词组
- const config = getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
+ const config = getFontCreateConfig(index, viewModel, paragraphNode, sectionBreakConfig, paragraph);
const glyph = [];
let step = 0;
for (let i = 0; i < charArray.length; i++) {
diff --git a/packages/engine-render/src/components/docs/layout/block/paragraph/shaping.ts b/packages/engine-render/src/components/docs/layout/block/paragraph/shaping.ts
index 68ba73ef3f..1e582606ad 100644
--- a/packages/engine-render/src/components/docs/layout/block/paragraph/shaping.ts
+++ b/packages/engine-render/src/components/docs/layout/block/paragraph/shaping.ts
@@ -122,7 +122,8 @@ export function shaping(
const shapedTextList: IShapedText[] = [];
let breaker = new LineBreaker(content);
const { endIndex } = paragraphNode;
- const { paragraphStyle = {} } = viewModel.getParagraph(endIndex) || { startIndex: 0 };
+ const paragraph = viewModel.getParagraph(endIndex) || { startIndex: 0 };
+ const { paragraphStyle = {} } = paragraph;
const { snapToGrid = BooleanNumber.TRUE } = paragraphStyle;
let last = 0;
let bk;
@@ -182,7 +183,7 @@ export function shaping(
for (const glyphInfo of glyphInfosInWord) {
const { start, char } = glyphInfo;
- const config = getFontCreateConfig(start, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
+ const config = getFontCreateConfig(start, viewModel, paragraphNode, sectionBreakConfig, paragraph);
if (char === DataStreamTreeTokenType.TAB) {
const charSpaceApply = getCharSpaceApply(charSpace, defaultTabStop, gridType, snapToGrid);
@@ -207,7 +208,7 @@ export function shaping(
}
if (char === DataStreamTreeTokenType.CUSTOM_BLOCK) {
- const config = getFontCreateConfig(i, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
+ const config = getFontCreateConfig(i, viewModel, paragraphNode, sectionBreakConfig, paragraph);
let newGlyph: Nullable<IDocumentSkeletonGlyph> = null;
const customBlock = viewModel.getCustomBlockWithoutSetCurrentIndex(paragraphNode.startIndex + i);
@@ -235,7 +236,7 @@ export function shaping(
i += char.length;
src = src.substring(char.length);
} else if (/\s/.test(char) || hasCJK(char)) {
- const config = getFontCreateConfig(i, viewModel, paragraphNode, sectionBreakConfig, paragraphStyle);
+ const config = getFontCreateConfig(i, viewModel, paragraphNode, sectionBreakConfig, paragraph);
let newGlyph: Nullable<IDocumentSkeletonGlyph> = null;
if (char === DataStreamTreeTokenType.TAB) {
@@ -255,7 +256,7 @@ export function shaping(
viewModel,
paragraphNode,
sectionBreakConfig,
- paragraphStyle
+ paragraph
);
shapedGlyphs.push(...glyphGroup);
i += step;
@@ -268,7 +269,7 @@ export function shaping(
viewModel,
paragraphNode,
sectionBreakConfig,
- paragraphStyle
+ paragraph
);
shapedGlyphs.push(...glyphGroup);
i += step;
@@ -281,7 +282,7 @@ export function shaping(
viewModel,
paragraphNode,
sectionBreakConfig,
- paragraphStyle
+ paragraph
);
shapedGlyphs.push(...glyphGroup);
i += step;
@@ -295,7 +296,7 @@ export function shaping(
viewModel,
paragraphNode,
sectionBreakConfig,
- paragraphStyle
+ paragraph
);
shapedGlyphs.push(...glyphGroup);
i += step;
diff --git a/packages/engine-render/src/components/docs/layout/tools.ts b/packages/engine-render/src/components/docs/layout/tools.ts
index 6d40abeebf..95059c4515 100644
--- a/packages/engine-render/src/components/docs/layout/tools.ts
+++ b/packages/engine-render/src/components/docs/layout/tools.ts
@@ -16,9 +16,11 @@
import type {
DocumentDataModel,
+ IBullet,
INumberUnit,
IObjectPositionH,
IObjectPositionV,
+ IParagraph,
IParagraphStyle,
ISectionBreak,
ITextStyle,
@@ -793,12 +795,19 @@ export function getFontConfigFromLastGlyph(
return result;
}
+function getBulletParagraphTextStyle(bullet: IBullet, viewModel: DocumentViewModel) {
+ const { listType } = bullet;
+ const lists = viewModel.getDataModel().getBulletPresetList();
+
+ return lists[listType].nestingLevel[0].paragraphProperties?.textStyle;
+}
+
export function getFontCreateConfig(
index: number,
viewModel: DocumentViewModel,
paragraphNode: DataStreamTreeNode,
sectionBreakConfig: ISectionBreakConfig,
- paragraphStyle: IParagraphStyle
+ paragraph: IParagraph
) {
const {
gridType = GridType.LINES,
@@ -808,12 +817,12 @@ export function getFontCreateConfig(
width: Number.POSITIVE_INFINITY,
height: Number.POSITIVE_INFINITY,
},
-
marginRight = 0,
marginLeft = 0,
localeService,
renderConfig = {},
} = sectionBreakConfig;
+ const { paragraphStyle = {}, bullet } = paragraph;
const { isRenderStyle } = renderConfig;
const { startIndex } = paragraphNode;
@@ -834,13 +843,15 @@ export function getFontCreateConfig(
return cache;
}
- const { snapToGrid = BooleanNumber.TRUE, textStyle: paragraphStyleTextStyle } = paragraphStyle;
+ const { snapToGrid = BooleanNumber.TRUE } = paragraphStyle;
+ const bulletTextStyle = bullet ? getBulletParagraphTextStyle(bullet, viewModel) : null;
+
textStyle = {
...documentTextStyle,
...textStyle,
...customDecorationStyle,
...customRangeStyle,
- ...paragraphStyleTextStyle,
+ ...bulletTextStyle,
};
const fontStyle = getFontStyleString(textStyle, localeService);