table/tablecolumnresize/utils
Functions
clamp( number, min, max ) → numberinternalmodule:table/tablecolumnresize/utils~clampClamps the number within the inclusive lower (min) and upper (max) bounds. Returned number is rounded using the
toPrecision()function.Parameters
number : numberA number to be clamped.
min : numberA lower bound.
max : numberAn upper bound.
Returns
numberThe clamped number.
createFilledArray( length, value ) → Array<T>internalmodule:table/tablecolumnresize/utils~createFilledArrayCreates an array with defined length and fills all elements with defined value.
Type parameters
T
Parameters
length : numberThe length of the array.
value : TThe value to fill the array with.
Returns
Array<T>An array with defined length and filled with defined value.
getChangedResizedTables( model ) → Set<ModelElement>internalmodule:table/tablecolumnresize/utils~getChangedResizedTablesReturns all the inserted or changed table model elements in a given change set. Only the tables with 'columnsWidth' attribute are taken into account. The returned set may be empty.
Most notably if an entire table is removed it will not be included in returned set.
Parameters
model : ModelThe model to collect the affected elements from.
Returns
Set<ModelElement>A set of table model elements.
getColumnEdgesIndexes( cell, tableUtils ) → objectinternalmodule:table/tablecolumnresize/utils~getColumnEdgesIndexesReturns the column indexes on the left and right edges of a cell. They differ if the cell spans across multiple columns.
Parameters
cell : ModelElementA table cell model element.
tableUtils : TableUtilsThe Table Utils plugin instance.
Returns
objectAn object containing the indexes of the left and right edges of the cell.
getColumnGroupElement( element ) → ModelElementinternalmodule:table/tablecolumnresize/utils~getColumnGroupElementReturns a 'tableColumnGroup' element from the 'table'.
Parameters
element : ModelElementA 'table' or 'tableColumnGroup' element.
Returns
ModelElementA 'tableColumnGroup' element.
getColumnMinWidthAsPercentage( modelTable, editor ) → numberinternalmodule:table/tablecolumnresize/utils~getColumnMinWidthAsPercentageCalculates the percentage of the minimum column width given in pixels for a given table.
Parameters
modelTable : ModelElementA table model element.
editor : EditorThe editor instance.
Returns
numberThe minimal column width in percentage.
getDomCellOuterWidth( domCell ) → numberinternalmodule:table/tablecolumnresize/utils~getDomCellOuterWidthCalculates the total horizontal space taken by the cell. That includes:
- width,
- left and red padding,
- border width.
Parameters
domCell : HTMLElementA DOM cell element.
Returns
numberWidth in pixels without
pxat the end.
getElementWidthInPixels( domElement ) → numberinternalmodule:table/tablecolumnresize/utils~getElementWidthInPixelsReturns the computed width (in pixels) of the DOM element without padding and borders.
Parameters
domElement : HTMLElementA DOM element.
Returns
numberThe width of the DOM element in pixels.
getTableColumnElements( element ) → Array<ModelElement>internalmodule:table/tablecolumnresize/utils~getTableColumnElementsReturns an array of 'tableColumn' elements. It may be empty if there's no
tableColumnGroupelement.Parameters
element : ModelElementA 'table' or 'tableColumnGroup' element.
Returns
Array<ModelElement>An array of 'tableColumn' elements.
getTableColumnsWidths( element ) → Array<string>internalmodule:table/tablecolumnresize/utils~getTableColumnsWidthsReturns an array of table column widths.
Parameters
element : ModelElementA 'table' or 'tableColumnGroup' element.
Returns
Array<string>An array of table column widths.
getTableWidthInPixels( modelTable, editor ) → numberinternalmodule:table/tablecolumnresize/utils~getTableWidthInPixelsCalculates the table width in pixels.
Parameters
modelTable : ModelElementA table model element.
editor : EditorThe editor instance.
Returns
numberThe width of the table in pixels.
normalizeColumnWidths( columnWidths ) → Array<string>internalmodule:table/tablecolumnresize/utils~normalizeColumnWidthsMakes sure that the sum of the widths from all columns is 100%. If the sum of all the widths is not equal 100%, all the widths are changed proportionally so that they all sum back to 100%. If there are columns without specified width, the amount remaining after assigning the known widths will be distributed equally between them.
Parameters
columnWidths : Array<string>An array of column widths.
Returns
Array<string>An array of column widths guaranteed to sum up to 100%.
sumArray( array ) → numberinternalmodule:table/tablecolumnresize/utils~sumArraySums all array values that can be parsed to a float.
Parameters
array : Array<string | number>An array of numbers.
Returns
numberThe sum of all array values.
toPrecision( value ) → numberinternalmodule:table/tablecolumnresize/utils~toPrecisionRounds the provided value to a fixed-point number with defined number of digits after the decimal point.
Parameters
value : string | numberA number to be rounded.
Returns
numberThe rounded number.
translateColSpanAttribute( element, writer ) → Array<string>internalmodule:table/tablecolumnresize/utils~translateColSpanAttributeTranslates the
colSpanmodel attribute into additional column widths and returns the resulting array.Parameters
element : ModelElementA 'table' or 'tableColumnGroup' element.
writer : ModelWriterA writer instance.
Returns
Array<string>An array of table column widths.
updateColumnElements( columns, tableColumnGroup, normalizedWidths, writer ) → voidinternalmodule:table/tablecolumnresize/utils~updateColumnElementsUpdates column elements to match columns widths.
Parameters
columns : Array<ModelElement>tableColumnGroup : ModelElementnormalizedWidths : Array<string>writer : ModelWriter
Returns
void