devexpress-richedit
Version:
DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.
149 lines (148 loc) • 5.62 kB
JavaScript
import { SearchUtils } from '@devexpress/utils/lib/utils/search';
import { NumberingList } from '../numbering-lists/numbering-list';
import { ParagraphPropertiesMerger } from '../properties-merger/paragraph-properties-merger';
import { StyleBase } from '../style-base';
import { TabAlign } from './paragraph';
import { EnumUtils } from '@devexpress/utils/lib/utils/enum';
export class ParagraphStyle extends StyleBase {
static normalStyleName = "Normal";
static headingStyleName = "Heading";
static tocStyleName = "toc";
linkedStyle = null;
nextParagraphStyle = null;
maskedCharacterProperties;
maskedParagraphProperties;
tabs;
autoUpdate;
numberingListIndex;
listLevelIndex;
constructor(styleName, localizedName, deleted, hidden, semihidden, isDefault, maskedCharacterProperties, maskedParagraphProperties, tabs, autoUpdate, numberingListIndex, listLevelIndex, base64EncodedImage, id) {
super(styleName, localizedName, deleted, hidden, semihidden, isDefault, base64EncodedImage, id);
this.maskedCharacterProperties = maskedCharacterProperties;
this.maskedParagraphProperties = maskedParagraphProperties;
this.tabs = tabs;
this.autoUpdate = autoUpdate;
this.numberingListIndex = numberingListIndex;
this.listLevelIndex = listLevelIndex;
}
getResultTabs() {
const parentTabs = this.parent?.getResultTabs();
const tabs = this.tabs.clone();
tabs.merge(parentTabs);
return tabs;
}
getMergedParagraphProperties() {
const paragraphMerger = new ParagraphPropertiesMerger();
paragraphMerger.mergeParagraphStyle(this);
return paragraphMerger.getMergedProperties();
}
isInOwnList() {
return this.numberingListIndex >= 0;
}
isInList() {
return this.getNumberingListIndex() >= 0;
}
getListLevel(model) {
return this.getNumberingList(model).levels[this.getListLevelIndex()];
}
getNumberingList(model) {
return model.numberingLists[this.getNumberingListIndex()];
}
getNumberingListIndex() {
if (this.numberingListIndex >= 0 || this.numberingListIndex === NumberingList.NoNumberingListIndex || !this.parent)
return this.numberingListIndex;
else
return this.parent.getNumberingListIndex();
}
getListLevelIndex() {
if (this.listLevelIndex >= 0)
return this.listLevelIndex;
else
return this.parent?.getListLevelIndex() ?? 0;
}
clone() {
const style = new ParagraphStyle(this.styleName, this.localizedName, this.deleted, this.hidden, this.semihidden, this.isDefault, this.maskedCharacterProperties, this.maskedParagraphProperties, this.tabs.clone(), this.autoUpdate, this.numberingListIndex, this.listLevelIndex, this.base64EncodedImage, this.id);
style.parent = this.parent;
style.linkedStyle = this.linkedStyle;
style.nextParagraphStyle = this.nextParagraphStyle;
style.primary = this.primary;
return style;
}
}
export class TabProperties {
tabsInfo = [];
clone() {
const tabProperties = new TabProperties();
for (let tab of this.tabsInfo)
tabProperties.tabsInfo.push(tab.clone());
return tabProperties;
}
equals(obj) {
for (var i = 0, tab; tab = this.tabsInfo[i]; i++)
if (!tab.equals(obj.tabsInfo[i]))
return false;
return true;
}
sort() {
this.tabsInfo.sort((a, b) => a.position - b.position);
}
indexOf(tabInfo) {
return SearchUtils.binaryIndexOf(this.tabsInfo, (t) => t.position - tabInfo.position);
}
add(tabInfo) {
this.tabsInfo.push(tabInfo);
this.sort();
}
deleteByIndex(index) {
this.tabsInfo.splice(index, 1);
}
setTabs(tabProp) {
this.tabsInfo = tabProp.tabsInfo;
this.tabsInfo.sort((a, b) => a.position - b.position);
}
merge(tabProperties) {
if (!tabProperties)
return;
tabProperties.tabsInfo.filter(t => !t.deleted).forEach(t => {
if (!this.tabsInfo.some(st => t.position === st.position))
this.add(t.clone());
});
this.sort();
}
}
export class TabInfoBase {
alignment;
leader;
deleted;
isDefault;
constructor(alignment, leader, deleted, isDefault) {
this.alignment = alignment;
this.leader = leader;
this.deleted = deleted;
this.isDefault = isDefault;
}
get isLeftAlignment() { return EnumUtils.isAnyOf(this.alignment, TabAlign.Left, TabAlign.Numbering); }
equals(obj) {
if (!obj)
return false;
return this.alignment === obj.alignment &&
this.leader === obj.leader &&
this.deleted === obj.deleted &&
this.isDefault === obj.isDefault;
}
}
export class TabInfo extends TabInfoBase {
position;
isParagraphIndent;
constructor(position, alignment, leader, deleted, isDefault, isParagraphIndent = false) {
super(alignment, leader, deleted, isDefault);
this.position = position;
this.isParagraphIndent = isParagraphIndent;
}
equals(obj) {
return super.equals(obj) && this.position == obj.position;
}
clone() {
return new TabInfo(this.position, this.alignment, this.leader, this.deleted, this.isDefault);
}
}