"use strict";

exports.__esModule = true;
exports.numberCellType = void 0;
var _types = require("../../types");
var _View = require("./View");
exports.NumberView = _View.NumberView;
var _Edit = require("./Edit");
exports.NumberEdit = _Edit.NumberEdit;
const numberCellType = exports.numberCellType = (0, _types.defineCellType)({
  type: 'number',
  ViewComponent: _View.NumberView,
  EditComponent: _Edit.NumberEdit,
  serialize: value => value != null ? String(value) : '',
  deserialize: raw => {
    if (raw === '') {
      return null;
    }
    const parsed = Number(raw);
    if (!Number.isFinite(parsed)) {
      throw new Error();
    }
    return parsed;
  },
  validate: value => {
    if (value != null && typeof value !== 'number') {
      return 'Value must be a number';
    }
    return null;
  },
  editable: true,
  clearable: true,
  onTypeToEdit: ({
    key
  }) => /^\d$/.test(key) ? {
    value: Number(key)
  } : undefined
});
//# sourceMappingURL=index.js.map