UNPKG

storybook-addon-material-ui5-react18

Version:

Storybook Addon for Material UI 5 Library with React 18 Support

78 lines (77 loc) 5 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports["default"] = void 0; var _addons = _interopRequireDefault(require("@storybook/addons")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } 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, _toPropertyKey(descriptor.key), descriptor); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var ChannelStore = exports["default"] = /*#__PURE__*/_createClass(function ChannelStore(_ref) { var _this = this; var EVENT_ID_INIT = _ref.EVENT_ID_INIT, EVENT_ID_DATA = _ref.EVENT_ID_DATA, EVENT_ID_BACK = _ref.EVENT_ID_BACK, _ref$name = _ref.name, name = _ref$name === void 0 ? 'store' : _ref$name, _ref$initData = _ref.initData, _initData = _ref$initData === void 0 ? {} : _ref$initData, _ref$isPanel = _ref.isPanel, isPanel = _ref$isPanel === void 0 ? false : _ref$isPanel; _classCallCheck(this, ChannelStore); _defineProperty(this, "onInitChannel", function (initData) { _this.store = initData; _this.subscriber(_this.store); }); _defineProperty(this, "onDataChannel", function (updData) { _this.store = _objectSpread(_objectSpread({}, _this.store), updData); _this.subscriber(_this.store); }); _defineProperty(this, "onData", function (subscriberFn) { _this.subscriber = subscriberFn; }); _defineProperty(this, "onConnected", function (onConnectedFn) { _this.onConnectedFn = onConnectedFn; }); _defineProperty(this, "send", function (data) { _this.store = _objectSpread(_objectSpread({}, _this.store), data); _this.emit(_this.store); _this.subscriber(_this.store); }); _defineProperty(this, "sendInit", function (data) { _this.init(data); }); _defineProperty(this, "disconnect", function () { _this.removeInit(); _this.removeData(); }); this.store = _initData; this.name = name; this.subscriber = function () {}; this.onConnectedFn = function () {}; this.channel = _addons["default"].getChannel(); this.connect = function () { _this.channel.on(EVENT_ID_INIT, _this.onInitChannel); _this.channel.on(isPanel ? EVENT_ID_DATA : EVENT_ID_BACK, _this.onDataChannel); _this.onConnectedFn(); }; this.emit = function (data) { return _this.channel.emit(isPanel ? EVENT_ID_BACK : EVENT_ID_DATA, data); }; this.init = function (data) { return _this.channel.emit(EVENT_ID_INIT, data); }; this.removeInit = function () { return _this.channel.removeListener(EVENT_ID_INIT, _this.onInitChannel); }; this.removeData = function () { return _this.channel.removeListener(EVENT_ID_DATA, _this.onDataChannel); }; });