UNPKG

4.77 kBJavaScriptView Raw
1"use strict";
2
3Object.defineProperty(exports, "__esModule", {
4 value: true
5});
6exports.Interactions = exports.InteractionKey = 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
36var InteractionKey;
37/**
38 * Encapsulates all interaction data needed by the Media component. The data is
39 * generated on initialization so no further runtime work is necessary.
40 */
41
42exports.InteractionKey = InteractionKey;
43
44(function (InteractionKey) {
45 InteractionKey["interaction"] = "interaction";
46})(InteractionKey || (exports.InteractionKey = InteractionKey = {}));
47
48var Interactions =
49/*#__PURE__*/
50function () {
51 _createClass(Interactions, null, [{
52 key: "validKeys",
53 value: function validKeys() {
54 return [InteractionKey.interaction];
55 }
56 }]);
57
58 function Interactions(interactions) {
59 _classCallCheck(this, Interactions);
60
61 _defineProperty(this, "_interactions", void 0);
62
63 this._interactions = interactions;
64 }
65
66 _createClass(Interactions, [{
67 key: "toRuleSets",
68 value: function toRuleSets() {
69 return Object.entries(this._interactions).reduce(function (acc, _ref) {
70 var _ref2 = _slicedToArray(_ref, 2),
71 name = _ref2[0],
72 query = _ref2[1];
73
74 return _toConsumableArray(acc).concat([(0, _Utils.createRuleSet)((0, _Utils.createClassName)(InteractionKey.interaction, name), query)]);
75 }, []);
76 }
77 }, {
78 key: "shouldRenderMediaQuery",
79 value: function shouldRenderMediaQuery(interaction, onlyMatch) {
80 return !!(onlyMatch && onlyMatch.includes(interaction));
81 }
82 }, {
83 key: "interactions",
84 get: function get() {
85 return Object.keys(this._interactions);
86 }
87 }, {
88 key: "dynamicResponsiveMediaQueries",
89 get: function get() {
90 return Object.entries(this._interactions).reduce(function (acc, _ref3) {
91 var _ref4 = _slicedToArray(_ref3, 2),
92 name = _ref4[0],
93 query = _ref4[1];
94
95 return _objectSpread({}, acc, _defineProperty({}, name, query));
96 }, {});
97 }
98 }]);
99
100 return Interactions;
101}();
102
103exports.Interactions = Interactions;
104//# sourceMappingURL=Interactions.js.map
\No newline at end of file