react-application-core
Version:
A react-based application core for the business applications.
175 lines • 6.25 kB
JavaScript
;
var __extends = (this && this.__extends) || (function () {
var extendStatics = function (d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
return extendStatics(d, b);
};
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
var __assign = (this && this.__assign) || function () {
__assign = Object.assign || function(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.MultiField = void 0;
var base_select_component_1 = require("../../field/select/base-select.component");
var multifield_plugin_1 = require("./multifield.plugin");
var util_1 = require("../../../util");
var definition_1 = require("../../../definition");
var MultiField = /** @class */ (function (_super) {
__extends(MultiField, _super);
/**
* @stable [21.01.2021]
* @param originalProps
*/
function MultiField(originalProps) {
var _this = _super.call(this, originalProps) || this;
/**
* @stable [16.06.2020]
*/
_this.multiFieldPlugin = new multifield_plugin_1.MultiFieldPlugin(_this);
_this.onMenuInlineOptionClose = _this.onMenuInlineOptionClose.bind(_this);
return _this;
}
/**
* @stable [01.06.2018]
* @param {IKeyboardEvent} event
*/
MultiField.prototype.onKeyBackspace = function (event) {
// Do nothing, only need to invoke the props callback
var props = this.props;
if (props.onKeyBackspace) {
props.onKeyBackspace(event);
}
};
/**
* @stable [21.01.2021]
* @param item
*/
MultiField.prototype.addItem = function (item) {
this.multiFieldPlugin.onAddItem(item);
};
/**
* @stable [29.08.2020]
* @param item
*/
MultiField.prototype.deleteItem = function (item) {
this.onDelete(item);
};
/**
* @stable [21.01.2021]
* @param item
*/
MultiField.prototype.editItem = function (item) {
this.multiFieldPlugin.onEditItem(item);
};
/**
* @stable [21.01.2021]
* @param item
*/
MultiField.prototype.mergeItem = function (item) {
this.multiFieldPlugin.onMergeItem(item);
};
Object.defineProperty(MultiField.prototype, "originalEmptyValue", {
/**
* @stable [01.06.2018]
* @returns {EntityIdT[]}
*/
get: function () {
return [];
},
enumerable: false,
configurable: true
});
/**
* @stable [21.01.2021]
* @param option
*/
MultiField.prototype.onSelect = function (option) {
this.multiFieldPlugin.onAddItem({ id: option.value, rawData: option.rawData });
util_1.ConditionUtils.ifNotNilThanValue(this.originalProps.onSelect, function (onSelect) { return onSelect(option); });
};
/**
* @stable [29.08.2020]
* @param item
* @protected
*/
MultiField.prototype.onDelete = function (item) {
this.multiFieldPlugin.onDeleteItem(item);
};
/**
* @stable [08.07.2020]
* @returns {IMenuProps}
*/
MultiField.prototype.getMenuProps = function () {
return __assign({ inlineOptions: this.menuInlineOptions, onInlineOptionClose: this.onMenuInlineOptionClose }, _super.prototype.getMenuProps.call(this));
};
/**
* @stable [16.06.2020]
* @returns {IPresetsSelectOptionEntity[]}
*/
MultiField.prototype.getFilteredOptions = function () {
var _this = this;
var activeValue = this.multiFieldPlugin.activeValue;
var selectedValueIgnored = this.mergedProps.selectedValueIgnored;
return selectedValueIgnored
? this.options
: (this.options.filter(function (option) { return !activeValue.some(function (item) { return item.id === _this.fromSelectValueToId(option); }); }));
};
/**
* @stable [16.06.2020]
* @returns {string}
*/
MultiField.prototype.getFieldClassName = function () {
return util_1.ClsUtils.joinClassName(_super.prototype.getFieldClassName.call(this), definition_1.MultiFieldClassesEnum.MULTI_FIELD);
};
/**
* @stable [14.01.2019]
* @param {AnyT} value
* @returns {string}
*/
MultiField.prototype.decorateDisplayValue = function (value) {
var len = this.multiFieldPlugin.getActiveValueLength(value);
return this.buildDisplayMessage(len > 0, len);
};
/**
* @stable [08.07.2020]
* @param {IPresetsRawDataLabeledValueEntity} option
*/
MultiField.prototype.onMenuInlineOptionClose = function (option) {
this.onDelete({ id: this.fieldConverter.fromSelectValueToId(option) });
};
Object.defineProperty(MultiField.prototype, "menuInlineOptions", {
/**
* @stable [21.01.2021]
*/
get: function () {
return this.multiFieldPlugin
.activeValue
.map(this.fieldConverter.fromNamedEntityToRawDataLabeledValueEntity);
},
enumerable: false,
configurable: true
});
MultiField.defaultProps = util_1.PropsUtils.mergeWithParentDefaultProps({
clearActionRendered: false,
displayMessage: '%d value(s)',
preventFocus: true,
}, base_select_component_1.BaseSelect);
return MultiField;
}(base_select_component_1.BaseSelect));
exports.MultiField = MultiField;
//# sourceMappingURL=multifield.component.js.map