/
updateListMetadata.ts
50 lines (48 loc) · 1.57 KB
/
updateListMetadata.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import { BulletListType } from '../../constants/BulletListType';
import { NumberingListType } from '../../constants/NumberingListType';
import { updateMetadata } from './updateMetadata';
import {
createBooleanDefinition,
createNumberDefinition,
createObjectDefinition,
} from './definitionCreators';
import type {
ContentModelWithDataset,
ListMetadataFormat,
ObjectDefinition,
} from 'roosterjs-content-model-types';
/**
* Metadata definition for List
*/
export const ListMetadataDefinition: ObjectDefinition<ListMetadataFormat> = createObjectDefinition<
ListMetadataFormat
>(
{
orderedStyleType: createNumberDefinition(
true /** isOptional */,
undefined /** value **/,
NumberingListType.Min,
NumberingListType.Max
),
unorderedStyleType: createNumberDefinition(
true /** isOptional */,
undefined /** value **/,
BulletListType.Min,
BulletListType.Max
),
applyListStyleFromLevel: createBooleanDefinition(true /*isOptional*/),
},
true /** isOptional */,
true /** allowNull */
);
/**
* Update list metadata with a callback
* @param list The list Content Model (metadata holder)
* @param callback The callback function used for updating metadata
*/
export function updateListMetadata(
list: ContentModelWithDataset<ListMetadataFormat>,
callback?: (format: ListMetadataFormat | null) => ListMetadataFormat | null
): ListMetadataFormat | null {
return updateMetadata(list, callback, ListMetadataDefinition);
}