UNPKG

4.51 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.Interactions = void 0;
7
8var _Utils = require("./Utils");
9
10function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }
11
12function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); }
13
14function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); }
15
16function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); }
17
18function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } }
19
20function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); }
21
22function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); }
23
24function _iterableToArrayLimit(arr, i) { var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
25
26function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
27
28function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
29
30function _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); } }
31
32function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
33
34function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
35
36/**
37 * Encapsulates all interaction data needed by the Media component. The data is
38 * generated on initialization so no further runtime work is necessary.
39 */
40var Interactions =
41/*#__PURE__*/
42function () {
43 _createClass(Interactions, null, [{
44 key: "validKeys",
45 value: function validKeys() {
46 return ["interaction"];
47 }
48 }]);
49
50 function Interactions(interactions) {
51 _classCallCheck(this, Interactions);
52
53 _defineProperty(this, "_interactions", void 0);
54
55 this._interactions = interactions;
56 }
57
58 _createClass(Interactions, [{
59 key: "toRuleSets",
60 value: function toRuleSets() {
61 return Object.entries(this._interactions).reduce(function (acc, _ref) {
62 var _ref2 = _slicedToArray(_ref, 2),
63 name = _ref2[0],
64 query = _ref2[1];
65
66 return _toConsumableArray(acc).concat([(0, _Utils.createRuleSet)((0, _Utils.createClassName)("interaction", name), query)]);
67 }, []);
68 }
69 }, {
70 key: "shouldRenderMediaQuery",
71 value: function shouldRenderMediaQuery(interaction, onlyMatch) {
72 return !!(onlyMatch && onlyMatch.includes(interaction));
73 }
74 }, {
75 key: "interactions",
76 get: function get() {
77 return Object.keys(this._interactions);
78 }
79 }, {
80 key: "dynamicResponsiveMediaQueries",
81 get: function get() {
82 return Object.entries(this._interactions).reduce(function (acc, _ref3) {
83 var _ref4 = _slicedToArray(_ref3, 2),
84 name = _ref4[0],
85 query = _ref4[1];
86
87 return _objectSpread({}, acc, _defineProperty({}, name, query));
88 }, {});
89 }
90 }]);
91
92 return Interactions;
93}();
94
95exports.Interactions = Interactions;
96//# sourceMappingURL=Interactions.js.map
\No newline at end of file