UNPKG

devexpress-richedit

Version:

DevExpress Rich Text Editor is an advanced word-processing tool designed for working with rich text documents.

52 lines (51 loc) 3.23 kB
import { EnumUtils } from '@devexpress/utils/lib/utils/enum'; import { ModelIterator } from '../../model/model-iterator'; import { RunType } from '../../model/runs/run-type'; import { __DEBUG_TABLE } from './debug-table'; import { Log } from './logger/base-logger/log'; export class ModelChecks { static DEBUG_TABLES_CHECKS(subDocument, forceCheck = false) { if (!forceCheck && !Log.isEnabled) return; __DEBUG_TABLE.tables(subDocument); } static DEBUG_FIELDS_CHECKS(subDocument, forceCheck = false) { if (!forceCheck && !Log.isEnabled) return; var fields = subDocument.fields; for (var fieldIndex = 0, field; field = fields[fieldIndex]; fieldIndex++) { if (field.index != fieldIndex) throw new Error("DEBUG_FIELDS_CHECKS incorrect index " + field.index + " must be " + fieldIndex); var chunkAndRunInfoStartCode = subDocument.getRunAndIndexesByPosition(field.getFieldStartPosition()); if (chunkAndRunInfoStartCode.run.getType() != RunType.FieldCodeStartRun) throw new Error("DEBUG_FIELDS_CHECKS incorrect run type"); var chunkAndRunInfoSeparator = subDocument.getRunAndIndexesByPosition(field.getSeparatorPosition()); if (chunkAndRunInfoSeparator.run.getType() != RunType.FieldCodeEndRun) throw new Error("DEBUG_FIELDS_CHECKS incorrect run type"); var chunkAndRunInfoEndField = subDocument.getRunAndIndexesByPosition(field.getResultEndPosition()); if (chunkAndRunInfoEndField.run.getType() != RunType.FieldResultEndRun) throw new Error("DEBUG_FIELDS_CHECKS incorrect run type"); if (chunkAndRunInfoStartCode.getAbsoluteRunPosition() >= chunkAndRunInfoSeparator.getAbsoluteRunPosition() || chunkAndRunInfoStartCode.getAbsoluteRunPosition() >= chunkAndRunInfoEndField.getAbsoluteRunPosition() || chunkAndRunInfoSeparator.getAbsoluteRunPosition() >= chunkAndRunInfoEndField.getAbsoluteRunPosition()) throw new Error("DEBUG_FIELDS_CHECKS incorrect some of main positions"); if (field.parent) { var fieldInterval = field.getAllFieldInterval(); if (!(field.parent.getCodeInterval().containsInterval(fieldInterval) || field.parent.getResultInterval().containsInterval(fieldInterval))) throw new Error("DEBUG_FIELDS_CHECKS error with intervals"); if (field.parent.index >= field.index) throw new Error("DEBUG_FIELDS_CHECKS error with parent and current indexes"); } } let numFieldRuns = 0; const it = new ModelIterator(subDocument, false); it.setPosition(0); do { if (EnumUtils.isAnyOf(it.run.getType(), RunType.FieldCodeStartRun, RunType.FieldCodeEndRun, RunType.FieldResultEndRun)) numFieldRuns++; } while (it.moveToNextRun()); if (numFieldRuns != subDocument.fields.length * 3) throw new Error("DEBUG_FIELDS_CHECKS error with num runs of fields (excess runs)"); } }