Skip to content

Commit

Permalink
fix(docs-ui): limit list maxLevel to 3 when in table & set line-throu…
Browse files Browse the repository at this point in the history
…gh style on checklist (#3096)
  • Loading branch information
weird94 authored Aug 22, 2024
1 parent 106e7c4 commit 9a62d77
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 144 deletions.
12 changes: 12 additions & 0 deletions packages/core/src/docs/data-model/document-data-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@ 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';
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',
Expand Down Expand Up @@ -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;
}
Expand Down
127 changes: 60 additions & 67 deletions packages/core/src/docs/data-model/preset-list-type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 0 additions & 2 deletions packages/core/src/types/interfaces/i-document-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
21 changes: 21 additions & 0 deletions packages/docs/src/basics/paragraph.ts
Original file line number Diff line number Diff line change
@@ -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);
}
Loading

0 comments on commit 9a62d77

Please sign in to comment.