UNPKG

react-application-core

Version:

A react-based application core for the business applications.

160 lines 6.02 kB
"use strict"; 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); }; 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.PerfectScrollPlugin = void 0; var R = require("ramda"); var PerfectScrollbar = require("./perfect-scrollbar"); // TODO var definition_1 = require("../../definition"); var di_1 = require("../../di"); var util_1 = require("../../util"); var PerfectScrollPlugin = /** @class */ (function () { /** * @stable [04.12.2019] * @param {} component */ function PerfectScrollPlugin(component) { this.component = component; this.doUpdate = this.doUpdate.bind(this); this.onScroll = this.onScroll.bind(this); } /** * @stable [04.12.2019] */ PerfectScrollPlugin.prototype.componentDidMount = function () { this.registerPlugin(); }; /** * @stable [04.12.2019] */ PerfectScrollPlugin.prototype.componentDidUpdate = function () { this.registerPlugin(); this.doUpdate(); }; /** * @stable [04.12.2019] */ PerfectScrollPlugin.prototype.componentWillUnmount = function () { this.doDestroy(); }; /** * @stable [06.12.2019] */ PerfectScrollPlugin.prototype.doUpdate = function () { var _this = this; if (R.isNil(this.ps)) { return; } util_1.ConditionUtils.ifNotNilThanValue(this.selfRef, function (selfRef) { // When a node has a changeable dynamic class and in the second time a registered 'ps' class is not recovered // <nav ref='...' className={staticCls, ..., props.param && staticClsN} _this.domAccessor.addClassNames(selfRef, definition_1.ComponentClassesEnum.PS); }); this.ps.update(); }; /** * @stable [06.12.2019] */ PerfectScrollPlugin.prototype.registerPlugin = function () { var selfRef = this.selfRef; if (R.isNil(selfRef)) { this.doDestroy(); return; } if (this.doesPsExist) { return; } this.ps = new PerfectScrollbar(selfRef, __assign({ wheelSpeed: 2, wheelPropagation: false, minScrollbarLength: 20 }, this.component.props.perfectScroll)); this.scrollUnsubscriber = this.domAccessor.captureEvent({ eventName: definition_1.EventsEnum.SCROLL, element: selfRef, callback: this.onScroll, }); this.resizeUnsubscriber = this.domAccessor.captureEvent({ eventName: definition_1.EventsEnum.RESIZE, callback: this.doUpdate, }); this.refreshUnsubscriber = this.eventEmitter.subscribe({ callback: this.doUpdate, eventName: definition_1.SyntheticEmitterEventsEnum.REFRESH, }); }; /** * @stable [17.01.2020] */ PerfectScrollPlugin.prototype.onScroll = function () { this.eventEmitter.emit(definition_1.SyntheticEmitterEventsEnum.SCROLL, this.selfRef); }; /** * @stable [06.12.2019] */ PerfectScrollPlugin.prototype.doDestroy = function () { if (this.doesPsExist) { this.ps.destroy(); this.ps = null; } if (util_1.TypeUtils.isFn(this.resizeUnsubscriber)) { this.resizeUnsubscriber(); this.resizeUnsubscriber = null; } if (util_1.TypeUtils.isFn(this.scrollUnsubscriber)) { this.scrollUnsubscriber(); this.scrollUnsubscriber = null; } if (util_1.TypeUtils.isFn(this.refreshUnsubscriber)) { this.refreshUnsubscriber(); this.refreshUnsubscriber = null; } }; Object.defineProperty(PerfectScrollPlugin.prototype, "doesPsExist", { /** * @stable [06.12.2019] * @returns {boolean} */ get: function () { return !R.isNil(this.ps); }, enumerable: false, configurable: true }); Object.defineProperty(PerfectScrollPlugin.prototype, "selfRef", { /** * @stable [04.05.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) ], PerfectScrollPlugin.prototype, "domAccessor", void 0); __decorate([ di_1.lazyInject(di_1.DI_TYPES.EventEmitter), __metadata("design:type", Object) ], PerfectScrollPlugin.prototype, "eventEmitter", void 0); return PerfectScrollPlugin; }()); exports.PerfectScrollPlugin = PerfectScrollPlugin; //# sourceMappingURL=perfect-scroll.plugin.js.map