react-application-core
Version:
A react-based application core for the business applications.
106 lines • 4.45 kB
JavaScript
;
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
};
var __metadata = (this && this.__metadata) || function (k, v) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.SelectedElementPlugin = void 0;
var di_1 = require("../../di");
var util_1 = require("../../util");
var SelectedElementPlugin = /** @class */ (function () {
/**
* @stable [23.10.2019]
* @param {IGenericComponent} component
*/
function SelectedElementPlugin(component) {
this.component = component;
}
/**
* @stable [23.10.2019]
*/
SelectedElementPlugin.prototype.componentDidMount = function () {
this.refreshScrollPosition();
};
/**
* @stable [25.10.2019]
*/
SelectedElementPlugin.prototype.componentDidUpdate = function () {
if (util_1.WrapperUtils.isRefreshOnUpdateNeeded(this.originalProps)) {
this.refreshScrollPosition();
}
};
/**
* @stable [19.12.2019]
*/
SelectedElementPlugin.prototype.refreshScrollPosition = function () {
var _this = this;
util_1.ConditionUtils.ifNotNilThanValue(this.selectedElement, function (selectedElement) {
var self = _this.selfRef;
if (!_this.domAccessor.isElementVisibleWithinParent(selectedElement, self)) {
_this.domAccessor.scrollTo(selectedElement, self, util_1.ConditionUtils.ifNotNilThanValue(_this.stickyElement, function (stickyElement) { return ({ offsetTop: _this.domAccessor.getHeight(stickyElement) }); }, {}));
}
});
};
Object.defineProperty(SelectedElementPlugin.prototype, "selectedElement", {
/**
* @stable [20.05.2020]
* @returns {Element}
*/
get: function () {
var _this = this;
return util_1.ConditionUtils.ifNotEmptyThanValue(this.originalProps.selectedElementClassName, function (selectedElementClassName) {
return _this.domAccessor.findElement(_this.domAccessor.asSelector(selectedElementClassName), _this.selfRef);
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(SelectedElementPlugin.prototype, "stickyElement", {
/**
* @stable [20.05.2020]
* @returns {Element}
*/
get: function () {
var _this = this;
return util_1.ConditionUtils.ifNotEmptyThanValue(this.originalProps.stickyElementClassName, function (stickyElementClassName) {
return _this.domAccessor.findElement(_this.domAccessor.asSelector(stickyElementClassName), _this.selfRef);
});
},
enumerable: false,
configurable: true
});
Object.defineProperty(SelectedElementPlugin.prototype, "originalProps", {
/**
* @stable [08.06.2020]
* @returns {ISelectedElementComponentProps}
*/
get: function () {
return this.component.props;
},
enumerable: false,
configurable: true
});
Object.defineProperty(SelectedElementPlugin.prototype, "selfRef", {
/**
* @stable [21.04.2020]
* @returns {HTMLElement}
*/
get: function () {
return this.component.actualRef.current;
},
enumerable: false,
configurable: true
});
__decorate([
di_1.lazyInject(di_1.DI_TYPES.DomAccessor),
__metadata("design:type", Object)
], SelectedElementPlugin.prototype, "domAccessor", void 0);
return SelectedElementPlugin;
}());
exports.SelectedElementPlugin = SelectedElementPlugin;
//# sourceMappingURL=selected-element-scroll.plugin.js.map