1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.flush = flush;
|
7 | exports.default = void 0;
|
8 |
|
9 | var _react = require("react");
|
10 |
|
11 | var _stylesheetRegistry = _interopRequireDefault(require("./stylesheet-registry"));
|
12 |
|
13 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
14 |
|
15 | function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
16 |
|
17 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
18 |
|
19 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
20 |
|
21 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
22 |
|
23 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
|
24 |
|
25 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
26 |
|
27 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
28 |
|
29 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
30 |
|
31 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
32 |
|
33 | var styleSheetRegistry = new _stylesheetRegistry.default();
|
34 |
|
35 | var JSXStyle =
|
36 |
|
37 | function (_Component) {
|
38 | _inherits(JSXStyle, _Component);
|
39 |
|
40 | function JSXStyle(props) {
|
41 | var _this;
|
42 |
|
43 | _classCallCheck(this, JSXStyle);
|
44 |
|
45 | _this = _possibleConstructorReturn(this, _getPrototypeOf(JSXStyle).call(this, props));
|
46 | _this.prevProps = {};
|
47 | return _this;
|
48 | }
|
49 |
|
50 | _createClass(JSXStyle, [{
|
51 | key: "shouldComponentUpdate",
|
52 |
|
53 | value: function shouldComponentUpdate(otherProps) {
|
54 | return this.props.id !== otherProps.id ||
|
55 |
|
56 | String(this.props.dynamic) !== String(otherProps.dynamic);
|
57 | }
|
58 | }, {
|
59 | key: "componentWillUnmount",
|
60 | value: function componentWillUnmount() {
|
61 | styleSheetRegistry.remove(this.props);
|
62 | }
|
63 | }, {
|
64 | key: "render",
|
65 | value: function render() {
|
66 |
|
67 |
|
68 | if (this.shouldComponentUpdate(this.prevProps)) {
|
69 |
|
70 | if (this.prevProps.id) {
|
71 | styleSheetRegistry.remove(this.prevProps);
|
72 | }
|
73 |
|
74 | styleSheetRegistry.add(this.props);
|
75 | this.prevProps = this.props;
|
76 | }
|
77 |
|
78 | return null;
|
79 | }
|
80 | }], [{
|
81 | key: "dynamic",
|
82 | value: function dynamic(info) {
|
83 | return info.map(function (tagInfo) {
|
84 | var baseId = tagInfo[0];
|
85 | var props = tagInfo[1];
|
86 | return styleSheetRegistry.computeId(baseId, props);
|
87 | }).join(' ');
|
88 | }
|
89 | }]);
|
90 |
|
91 | return JSXStyle;
|
92 | }(_react.Component);
|
93 |
|
94 | exports.default = JSXStyle;
|
95 |
|
96 | function flush() {
|
97 | var cssRules = styleSheetRegistry.cssRules();
|
98 | styleSheetRegistry.flush();
|
99 | return cssRules;
|
100 | } |
\ | No newline at end of file |