react-application-core
Version:
A react-based application core for the business applications.
120 lines • 4.64 kB
JavaScript
"use strict";
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.StickyHeaderPlugin = void 0;
var R = require("ramda");
var di_1 = require("../../di");
var util_1 = require("../../util");
var definition_1 = require("../../definition");
var StickyHeaderPlugin = /** @class */ (function () {
/**
* @stable [06.02.2020]
* @param {IComponent<IStickyComponentProps>} component
*/
function StickyHeaderPlugin(component) {
this.component = component;
this.isStickyElementMounted = false;
this.doSetStickyElementProperties = this.doSetStickyElementProperties.bind(this);
}
/**
* @stable [11.10.2019]
*/
StickyHeaderPlugin.prototype.componentDidMount = function () {
this.checkStickyElement();
};
/**
* @stable [11.10.2019]
*/
StickyHeaderPlugin.prototype.componentDidUpdate = function () {
this.checkStickyElement();
this.doSetStickyElementProperties();
};
/**
* @stable [11.10.2019]
*/
StickyHeaderPlugin.prototype.componentWillUnmount = function () {
this.clearAllListeners();
};
/**
* @stable [11.10.2019]
*/
StickyHeaderPlugin.prototype.doSetStickyElementProperties = function () {
if (!this.isStickyElementMounted) {
return;
}
util_1.setStickyElementProperties(this.selfRef, this.stickySelector);
};
/**
* @stable [16.10.2019]
*/
StickyHeaderPlugin.prototype.checkStickyElement = function () {
var element = this.selfRef;
this.isStickyElementMounted = !R.isNil(this.domAccessor.findElement(this.stickySelector, element));
this.clearAllListeners();
if (this.isStickyElementMounted) {
this.resizeUnsubscriber = this.domAccessor.captureEvent({
callback: this.doSetStickyElementProperties,
eventName: definition_1.EventsEnum.RESIZE,
});
this.scrollUnsubscriber = this.domAccessor.captureEvent({
callback: this.doSetStickyElementProperties,
eventName: definition_1.EventsEnum.SCROLL,
element: element,
});
}
};
/**
* @stable [16.10.2019]
*/
StickyHeaderPlugin.prototype.clearAllListeners = function () {
if (util_1.isFn(this.resizeUnsubscriber)) {
this.resizeUnsubscriber();
this.resizeUnsubscriber = null;
}
if (util_1.isFn(this.scrollUnsubscriber)) {
this.scrollUnsubscriber();
this.scrollUnsubscriber = null;
}
};
Object.defineProperty(StickyHeaderPlugin.prototype, "stickySelector", {
/**
* @stable [16.10.2019]
* @returns {string}
*/
get: function () {
return this.domAccessor.asSelector(this.component.props.stickyElementClassName);
},
enumerable: false,
configurable: true
});
Object.defineProperty(StickyHeaderPlugin.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)
], StickyHeaderPlugin.prototype, "domAccessor", void 0);
__decorate([
di_1.lazyInject(di_1.DI_TYPES.EventManager),
__metadata("design:type", Object)
], StickyHeaderPlugin.prototype, "eventManager", void 0);
return StickyHeaderPlugin;
}());
exports.StickyHeaderPlugin = StickyHeaderPlugin;
//# sourceMappingURL=sticky-header.plugin.js.map