viser-react
Version:
viser-react is react of viser.
136 lines (103 loc) • 4.07 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = void 0;
var PropTypes = _interopRequireWildcard(require("prop-types"));
var React = _interopRequireWildcard(require("react"));
var viser = _interopRequireWildcard(require("viser"));
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; if (obj != null) { var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
var __extends = void 0 && (void 0).__extends || function () {
var _extendStatics = function extendStatics(d, b) {
_extendStatics = Object.setPrototypeOf || {
__proto__: []
} instanceof Array && function (d, b) {
d.__proto__ = b;
} || function (d, b) {
for (var p in b) {
if (b.hasOwnProperty(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 = void 0 && (void 0).__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 PluginComponent = function (_super) {
__extends(PluginComponent, _super);
function PluginComponent() {
var _this = _super !== null && _super.apply(this, arguments) || this;
_this.config = {};
_this.plugins = null;
_this.centralizedUpdates = function (unit) {
var config = _this.config;
var props = unit.props;
var displayName = unit.displayName;
if (displayName === 'Slider') {
var container = props.container;
if (!container || !document.getElementById(container)) {
props = __assign({}, props, {
container: unit.state.containerId
});
}
}
_this.combineContentConfig(displayName, props, config);
_this.updateSliderInstance(config);
};
_this.portalRef = function (container) {
if (!_this.container) {
_this.container = container;
}
};
return _this;
}
PluginComponent.prototype.getChildContext = function () {
return {
centralizedUpdates: this.centralizedUpdates
};
};
PluginComponent.prototype.combineContentConfig = function (displayName, props, config) {
var nameLowerCase = displayName.toLowerCase();
config[nameLowerCase] = props;
};
PluginComponent.prototype.updateSliderInstance = function (config) {
if (!this.plugins) {
this.plugins = viser.Plugin(config);
}
if (this.plugins && this.plugins.slider && config.slider) {
this.plugins = viser.Plugin(config);
}
};
PluginComponent.prototype.clearConfigData = function () {
this.config = {};
};
PluginComponent.prototype.render = function () {
return React.createElement("div", {
ref: this.portalRef
}, this.props.children);
};
PluginComponent.childContextTypes = {
centralizedUpdates: PropTypes.func
};
return PluginComponent;
}(React.Component);
var _default = PluginComponent;
exports.default = _default;