1 | "use strict";
|
2 |
|
3 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
4 |
|
5 | require("core-js/modules/es.object.to-string.js");
|
6 |
|
7 | require("core-js/modules/es.reflect.construct.js");
|
8 |
|
9 | require("core-js/modules/es.promise.js");
|
10 |
|
11 | require("core-js/modules/es.object.keys.js");
|
12 |
|
13 | require("core-js/modules/es.symbol.js");
|
14 |
|
15 | require("core-js/modules/es.object.assign.js");
|
16 |
|
17 | require("core-js/modules/es.array.iterator.js");
|
18 |
|
19 | require("core-js/modules/es.string.iterator.js");
|
20 |
|
21 | require("core-js/modules/es.weak-map.js");
|
22 |
|
23 | require("core-js/modules/web.dom-collections.iterator.js");
|
24 |
|
25 | require("core-js/modules/es.object.get-own-property-descriptor.js");
|
26 |
|
27 | require("core-js/modules/es.symbol.description.js");
|
28 |
|
29 | require("core-js/modules/es.symbol.iterator.js");
|
30 |
|
31 | Object.defineProperty(exports, "__esModule", {
|
32 | value: true
|
33 | });
|
34 | exports.default = void 0;
|
35 |
|
36 | require("regenerator-runtime/runtime.js");
|
37 |
|
38 | require("core-js/modules/es.array.concat.js");
|
39 |
|
40 | require("core-js/modules/es.object.get-prototype-of.js");
|
41 |
|
42 | var _react = _interopRequireWildcard(require("react"));
|
43 |
|
44 | var _utils = require("../../utils");
|
45 |
|
46 | var _excluded = ["kind", "story", "children"];
|
47 |
|
48 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
49 |
|
50 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && 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; }
|
51 |
|
52 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
53 |
|
54 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
55 |
|
56 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
57 |
|
58 | function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
59 |
|
60 | function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
61 |
|
62 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
63 |
|
64 | 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); } }
|
65 |
|
66 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
67 |
|
68 | 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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
69 |
|
70 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
71 |
|
72 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
73 |
|
74 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
75 |
|
76 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
77 |
|
78 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
79 |
|
80 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
81 |
|
82 |
|
83 |
|
84 |
|
85 | var LEFT_BUTTON = 0;
|
86 |
|
87 | var isPlainLeftClick = function isPlainLeftClick(e) {
|
88 | return e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
|
89 | };
|
90 |
|
91 | var cancelled = function cancelled(e) {
|
92 | var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (_e) {};
|
93 |
|
94 | if (isPlainLeftClick(e)) {
|
95 | e.preventDefault();
|
96 | cb(e);
|
97 | }
|
98 | };
|
99 |
|
100 | var LinkTo = function (_PureComponent) {
|
101 | _inherits(LinkTo, _PureComponent);
|
102 |
|
103 | var _super = _createSuper(LinkTo);
|
104 |
|
105 | function LinkTo() {
|
106 | var _this;
|
107 |
|
108 | _classCallCheck(this, LinkTo);
|
109 |
|
110 | for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
|
111 | args[_key] = arguments[_key];
|
112 | }
|
113 |
|
114 | _this = _super.call.apply(_super, [this].concat(args));
|
115 | _this.state = {
|
116 | href: '/'
|
117 | };
|
118 | _this.updateHref = _asyncToGenerator( regeneratorRuntime.mark(function _callee() {
|
119 | var _this$props, kind, story, href;
|
120 |
|
121 | return regeneratorRuntime.wrap(function _callee$(_context) {
|
122 | while (1) {
|
123 | switch (_context.prev = _context.next) {
|
124 | case 0:
|
125 | _this$props = _this.props, kind = _this$props.kind, story = _this$props.story;
|
126 | _context.next = 3;
|
127 | return (0, _utils.hrefTo)(kind, story);
|
128 |
|
129 | case 3:
|
130 | href = _context.sent;
|
131 |
|
132 | _this.setState({
|
133 | href: href
|
134 | });
|
135 |
|
136 | case 5:
|
137 | case "end":
|
138 | return _context.stop();
|
139 | }
|
140 | }
|
141 | }, _callee);
|
142 | }));
|
143 |
|
144 | _this.handleClick = function () {
|
145 | (0, _utils.navigate)(_this.props);
|
146 | };
|
147 |
|
148 | return _this;
|
149 | }
|
150 |
|
151 | _createClass(LinkTo, [{
|
152 | key: "componentDidMount",
|
153 | value: function componentDidMount() {
|
154 | this.updateHref();
|
155 | }
|
156 | }, {
|
157 | key: "componentDidUpdate",
|
158 | value: function componentDidUpdate(prevProps) {
|
159 | var _this$props2 = this.props,
|
160 | kind = _this$props2.kind,
|
161 | story = _this$props2.story;
|
162 |
|
163 | if (prevProps.kind !== kind || prevProps.story !== story) {
|
164 | this.updateHref();
|
165 | }
|
166 | }
|
167 | }, {
|
168 | key: "render",
|
169 | value: function render() {
|
170 | var _this2 = this;
|
171 |
|
172 | var _this$props3 = this.props,
|
173 | kind = _this$props3.kind,
|
174 | story = _this$props3.story,
|
175 | children = _this$props3.children,
|
176 | rest = _objectWithoutProperties(_this$props3, _excluded);
|
177 |
|
178 | var href = this.state.href;
|
179 | return _react.default.createElement("a", _extends({
|
180 | href: href,
|
181 | onClick: function onClick(e) {
|
182 | return cancelled(e, _this2.handleClick);
|
183 | }
|
184 | }, rest), children);
|
185 | }
|
186 | }]);
|
187 |
|
188 | return LinkTo;
|
189 | }(_react.PureComponent);
|
190 |
|
191 | exports.default = LinkTo;
|
192 | LinkTo.defaultProps = {
|
193 | kind: null,
|
194 | story: null,
|
195 | children: undefined
|
196 | }; |
\ | No newline at end of file |