handsontable
Version:
Handsontable is a JavaScript Data Grid available for React, Angular and Vue.
72 lines (69 loc) • 3.26 kB
JavaScript
;
exports.__esModule = true;
exports.numericRenderer = numericRenderer;
exports.valueFormatter = valueFormatter;
var _textRenderer = require("../textRenderer");
var _number = require("../../helpers/number");
var _console = require("../../helpers/console");
var _utils = require("./utils");
const RENDERER_TYPE = exports.RENDERER_TYPE = 'numeric';
const deprecatedMessageShown = new WeakSet();
/**
* Formats the value using the numeric format.
*
* @param {*} value Value to be rendered.
* @param {CellMeta} cellProperties Cell meta object.
* @returns {*} Returns the formatted value.
*/
function valueFormatter(value, cellProperties) {
if ((0, _number.isNumeric)(value)) {
if ((0, _utils.isNumbroScheme)(cellProperties)) {
value = (0, _utils.numbroFormatter)(value, cellProperties);
} else {
value = (0, _utils.intlFormatter)(value, cellProperties);
}
}
return value;
}
/**
* Numeric cell renderer.
*
* @private
* @param {Core} hotInstance The Handsontable instance.
* @param {HTMLTableCellElement} TD The rendered cell element.
* @param {number} row The visual row index.
* @param {number} col The visual column index.
* @param {number|string} prop The column property (passed when datasource is an array of objects).
* @param {*} value The rendered value.
* @param {object} cellProperties The cell meta object (see {@link Core#getCellMeta}).
*/
function numericRenderer(hotInstance, TD, row, col, prop, value, cellProperties) {
const isNumbroFormat = (0, _utils.isNumbroScheme)(cellProperties);
if (isNumbroFormat && !deprecatedMessageShown.has(cellProperties.instance)) {
deprecatedMessageShown.add(cellProperties.instance);
(0, _console.deprecatedWarn)('The `numericFormat.pattern` and `numericFormat.culture` options are deprecated ' + 'and will be removed in the next major release. Pass `Intl.NumberFormat` options ' + 'directly to `numericFormat` and use the `locale` cell property instead of `culture`.\n\n' + 'Migration guide: https://handsontable.com/docs/migration-from-16.2-to-17.0/\n' + '`numericFormat` documentation: https://handsontable.com/docs/api/options/#numericformat\n' + '`locale` documentation: https://handsontable.com/docs/api/options/#locale');
}
if ((0, _number.isNumeric)(hotInstance.getDataAtCell(row, col))) {
let classArr = [];
if (Array.isArray(cellProperties.className)) {
classArr = cellProperties.className;
} else {
var _cellProperties$class;
const className = (_cellProperties$class = cellProperties.className) !== null && _cellProperties$class !== void 0 ? _cellProperties$class : '';
if (className.length) {
classArr = className.split(' ');
}
}
if (classArr.indexOf('htLeft') < 0 && classArr.indexOf('htCenter') < 0 && classArr.indexOf('htRight') < 0 && classArr.indexOf('htJustify') < 0) {
classArr.push('htRight');
}
if (classArr.indexOf('htNumeric') < 0) {
classArr.push('htNumeric');
}
cellProperties.className = classArr.join(' ');
TD.dir = 'ltr';
}
_textRenderer.textRenderer.apply(this, [hotInstance, TD, row, col, prop, value, cellProperties]);
}
numericRenderer.valueFormatter = valueFormatter;
numericRenderer.RENDERER_TYPE = RENDERER_TYPE;