@storybook/addon-links 6.5.7 → 7.0.0-alpha.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. package/dist/cjs/react/components/link.js +29 -15
  2. package/dist/cjs/utils.js +28 -14
  3. package/dist/esm/constants.js +5 -5
  4. package/dist/esm/index.js +5 -9
  5. package/dist/esm/manager.js +7 -7
  6. package/dist/esm/preview.js +1 -1
  7. package/dist/esm/react/components/RoutedLink.js +17 -20
  8. package/dist/esm/react/components/link.js +49 -134
  9. package/dist/esm/utils.js +61 -87
  10. package/dist/{ts3.9 → types}/constants.d.ts +0 -0
  11. package/dist/{ts3.9 → types}/index.d.ts +0 -0
  12. package/dist/{ts3.9 → types}/manager.d.ts +0 -0
  13. package/dist/{ts3.9 → types}/preview.d.ts +0 -0
  14. package/dist/{ts3.9 → types}/react/components/RoutedLink.d.ts +0 -0
  15. package/dist/{ts3.9 → types}/react/components/link.d.ts +0 -0
  16. package/dist/{ts3.9 → types}/react/index.d.ts +0 -0
  17. package/dist/{ts3.9 → types}/utils.d.ts +0 -0
  18. package/package.json +7 -20
  19. package/react.d.ts +2 -2
  20. package/dist/modern/constants.js +0 -7
  21. package/dist/modern/index.js +0 -19
  22. package/dist/modern/manager.js +0 -12
  23. package/dist/modern/preview.js +0 -2
  24. package/dist/modern/react/components/RoutedLink.js +0 -39
  25. package/dist/modern/react/components/link.js +0 -82
  26. package/dist/modern/react/index.js +0 -2
  27. package/dist/modern/utils.js +0 -99
  28. package/dist/ts3.4/constants.d.ts +0 -8
  29. package/dist/ts3.4/index.d.ts +0 -2
  30. package/dist/ts3.4/manager.d.ts +0 -1
  31. package/dist/ts3.4/preview.d.ts +0 -1
  32. package/dist/ts3.4/react/components/RoutedLink.d.ts +0 -3
  33. package/dist/ts3.4/react/components/link.d.ts +0 -19
  34. package/dist/ts3.4/react/index.d.ts +0 -2
  35. package/dist/ts3.4/utils.d.ts +0 -13
@@ -8,33 +8,45 @@ require("core-js/modules/es.reflect.construct.js");
8
8
 
9
9
  require("core-js/modules/es.promise.js");
10
10
 
11
- require("core-js/modules/es.object.keys.js");
12
-
13
11
  require("core-js/modules/es.symbol.js");
14
12
 
15
- require("core-js/modules/es.object.assign.js");
13
+ require("core-js/modules/es.symbol.description.js");
14
+
15
+ require("core-js/modules/es.symbol.iterator.js");
16
16
 
17
17
  require("core-js/modules/es.array.iterator.js");
18
18
 
19
19
  require("core-js/modules/es.string.iterator.js");
20
20
 
21
- require("core-js/modules/es.weak-map.js");
22
-
23
21
  require("core-js/modules/web.dom-collections.iterator.js");
24
22
 
25
- require("core-js/modules/es.object.get-own-property-descriptor.js");
23
+ require("core-js/modules/es.symbol.async-iterator.js");
26
24
 
27
- require("core-js/modules/es.symbol.description.js");
25
+ require("core-js/modules/es.symbol.to-string-tag.js");
28
26
 
29
- require("core-js/modules/es.symbol.iterator.js");
27
+ require("core-js/modules/es.json.to-string-tag.js");
28
+
29
+ require("core-js/modules/es.math.to-string-tag.js");
30
+
31
+ require("core-js/modules/web.dom-collections.for-each.js");
32
+
33
+ require("core-js/modules/es.function.name.js");
34
+
35
+ require("core-js/modules/es.array.slice.js");
36
+
37
+ require("core-js/modules/es.object.keys.js");
38
+
39
+ require("core-js/modules/es.object.assign.js");
40
+
41
+ require("core-js/modules/es.weak-map.js");
42
+
43
+ require("core-js/modules/es.object.get-own-property-descriptor.js");
30
44
 
31
45
  Object.defineProperty(exports, "__esModule", {
32
46
  value: true
33
47
  });
34
48
  exports.default = void 0;
35
49
 
36
- require("regenerator-runtime/runtime.js");
37
-
38
50
  require("core-js/modules/es.array.concat.js");
39
51
 
40
52
  require("core-js/modules/es.object.get-prototype-of.js");
@@ -49,12 +61,14 @@ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "functio
49
61
 
50
62
  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
63
 
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); }
64
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : 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
65
 
54
66
  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
67
 
56
68
  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
69
 
70
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return exports; }; var exports = {}, Op = Object.prototype, hasOwn = Op.hasOwnProperty, $Symbol = "function" == typeof Symbol ? Symbol : {}, iteratorSymbol = $Symbol.iterator || "@@iterator", asyncIteratorSymbol = $Symbol.asyncIterator || "@@asyncIterator", toStringTagSymbol = $Symbol.toStringTag || "@@toStringTag"; function define(obj, key, value) { return Object.defineProperty(obj, key, { value: value, enumerable: !0, configurable: !0, writable: !0 }), obj[key]; } try { define({}, ""); } catch (err) { define = function define(obj, key, value) { return obj[key] = value; }; } function wrap(innerFn, outerFn, self, tryLocsList) { var protoGenerator = outerFn && outerFn.prototype instanceof Generator ? outerFn : Generator, generator = Object.create(protoGenerator.prototype), context = new Context(tryLocsList || []); return generator._invoke = function (innerFn, self, context) { var state = "suspendedStart"; return function (method, arg) { if ("executing" === state) throw new Error("Generator is already running"); if ("completed" === state) { if ("throw" === method) throw arg; return doneResult(); } for (context.method = method, context.arg = arg;;) { var delegate = context.delegate; if (delegate) { var delegateResult = maybeInvokeDelegate(delegate, context); if (delegateResult) { if (delegateResult === ContinueSentinel) continue; return delegateResult; } } if ("next" === context.method) context.sent = context._sent = context.arg;else if ("throw" === context.method) { if ("suspendedStart" === state) throw state = "completed", context.arg; context.dispatchException(context.arg); } else "return" === context.method && context.abrupt("return", context.arg); state = "executing"; var record = tryCatch(innerFn, self, context); if ("normal" === record.type) { if (state = context.done ? "completed" : "suspendedYield", record.arg === ContinueSentinel) continue; return { value: record.arg, done: context.done }; } "throw" === record.type && (state = "completed", context.method = "throw", context.arg = record.arg); } }; }(innerFn, self, context), generator; } function tryCatch(fn, obj, arg) { try { return { type: "normal", arg: fn.call(obj, arg) }; } catch (err) { return { type: "throw", arg: err }; } } exports.wrap = wrap; var ContinueSentinel = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var IteratorPrototype = {}; define(IteratorPrototype, iteratorSymbol, function () { return this; }); var getProto = Object.getPrototypeOf, NativeIteratorPrototype = getProto && getProto(getProto(values([]))); NativeIteratorPrototype && NativeIteratorPrototype !== Op && hasOwn.call(NativeIteratorPrototype, iteratorSymbol) && (IteratorPrototype = NativeIteratorPrototype); var Gp = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(IteratorPrototype); function defineIteratorMethods(prototype) { ["next", "throw", "return"].forEach(function (method) { define(prototype, method, function (arg) { return this._invoke(method, arg); }); }); } function AsyncIterator(generator, PromiseImpl) { function invoke(method, arg, resolve, reject) { var record = tryCatch(generator[method], generator, arg); if ("throw" !== record.type) { var result = record.arg, value = result.value; return value && "object" == _typeof(value) && hasOwn.call(value, "__await") ? PromiseImpl.resolve(value.__await).then(function (value) { invoke("next", value, resolve, reject); }, function (err) { invoke("throw", err, resolve, reject); }) : PromiseImpl.resolve(value).then(function (unwrapped) { result.value = unwrapped, resolve(result); }, function (error) { return invoke("throw", error, resolve, reject); }); } reject(record.arg); } var previousPromise; this._invoke = function (method, arg) { function callInvokeWithMethodAndArg() { return new PromiseImpl(function (resolve, reject) { invoke(method, arg, resolve, reject); }); } return previousPromise = previousPromise ? previousPromise.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); }; } function maybeInvokeDelegate(delegate, context) { var method = delegate.iterator[context.method]; if (undefined === method) { if (context.delegate = null, "throw" === context.method) { if (delegate.iterator.return && (context.method = "return", context.arg = undefined, maybeInvokeDelegate(delegate, context), "throw" === context.method)) return ContinueSentinel; context.method = "throw", context.arg = new TypeError("The iterator does not provide a 'throw' method"); } return ContinueSentinel; } var record = tryCatch(method, delegate.iterator, context.arg); if ("throw" === record.type) return context.method = "throw", context.arg = record.arg, context.delegate = null, ContinueSentinel; var info = record.arg; return info ? info.done ? (context[delegate.resultName] = info.value, context.next = delegate.nextLoc, "return" !== context.method && (context.method = "next", context.arg = undefined), context.delegate = null, ContinueSentinel) : info : (context.method = "throw", context.arg = new TypeError("iterator result is not an object"), context.delegate = null, ContinueSentinel); } function pushTryEntry(locs) { var entry = { tryLoc: locs[0] }; 1 in locs && (entry.catchLoc = locs[1]), 2 in locs && (entry.finallyLoc = locs[2], entry.afterLoc = locs[3]), this.tryEntries.push(entry); } function resetTryEntry(entry) { var record = entry.completion || {}; record.type = "normal", delete record.arg, entry.completion = record; } function Context(tryLocsList) { this.tryEntries = [{ tryLoc: "root" }], tryLocsList.forEach(pushTryEntry, this), this.reset(!0); } function values(iterable) { if (iterable) { var iteratorMethod = iterable[iteratorSymbol]; if (iteratorMethod) return iteratorMethod.call(iterable); if ("function" == typeof iterable.next) return iterable; if (!isNaN(iterable.length)) { var i = -1, next = function next() { for (; ++i < iterable.length;) { if (hasOwn.call(iterable, i)) return next.value = iterable[i], next.done = !1, next; } return next.value = undefined, next.done = !0, next; }; return next.next = next; } } return { next: doneResult }; } function doneResult() { return { value: undefined, done: !0 }; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, define(Gp, "constructor", GeneratorFunctionPrototype), define(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, toStringTagSymbol, "GeneratorFunction"), exports.isGeneratorFunction = function (genFun) { var ctor = "function" == typeof genFun && genFun.constructor; return !!ctor && (ctor === GeneratorFunction || "GeneratorFunction" === (ctor.displayName || ctor.name)); }, exports.mark = function (genFun) { return Object.setPrototypeOf ? Object.setPrototypeOf(genFun, GeneratorFunctionPrototype) : (genFun.__proto__ = GeneratorFunctionPrototype, define(genFun, toStringTagSymbol, "GeneratorFunction")), genFun.prototype = Object.create(Gp), genFun; }, exports.awrap = function (arg) { return { __await: arg }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, asyncIteratorSymbol, function () { return this; }), exports.AsyncIterator = AsyncIterator, exports.async = function (innerFn, outerFn, self, tryLocsList, PromiseImpl) { void 0 === PromiseImpl && (PromiseImpl = Promise); var iter = new AsyncIterator(wrap(innerFn, outerFn, self, tryLocsList), PromiseImpl); return exports.isGeneratorFunction(outerFn) ? iter : iter.next().then(function (result) { return result.done ? result.value : iter.next(); }); }, defineIteratorMethods(Gp), define(Gp, toStringTagSymbol, "Generator"), define(Gp, iteratorSymbol, function () { return this; }), define(Gp, "toString", function () { return "[object Generator]"; }), exports.keys = function (object) { var keys = []; for (var key in object) { keys.push(key); } return keys.reverse(), function next() { for (; keys.length;) { var key = keys.pop(); if (key in object) return next.value = key, next.done = !1, next; } return next.done = !0, next; }; }, exports.values = values, Context.prototype = { constructor: Context, reset: function reset(skipTempReset) { if (this.prev = 0, this.next = 0, this.sent = this._sent = undefined, this.done = !1, this.delegate = null, this.method = "next", this.arg = undefined, this.tryEntries.forEach(resetTryEntry), !skipTempReset) for (var name in this) { "t" === name.charAt(0) && hasOwn.call(this, name) && !isNaN(+name.slice(1)) && (this[name] = undefined); } }, stop: function stop() { this.done = !0; var rootRecord = this.tryEntries[0].completion; if ("throw" === rootRecord.type) throw rootRecord.arg; return this.rval; }, dispatchException: function dispatchException(exception) { if (this.done) throw exception; var context = this; function handle(loc, caught) { return record.type = "throw", record.arg = exception, context.next = loc, caught && (context.method = "next", context.arg = undefined), !!caught; } for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i], record = entry.completion; if ("root" === entry.tryLoc) return handle("end"); if (entry.tryLoc <= this.prev) { var hasCatch = hasOwn.call(entry, "catchLoc"), hasFinally = hasOwn.call(entry, "finallyLoc"); if (hasCatch && hasFinally) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } else if (hasCatch) { if (this.prev < entry.catchLoc) return handle(entry.catchLoc, !0); } else { if (!hasFinally) throw new Error("try statement without catch or finally"); if (this.prev < entry.finallyLoc) return handle(entry.finallyLoc); } } } }, abrupt: function abrupt(type, arg) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc <= this.prev && hasOwn.call(entry, "finallyLoc") && this.prev < entry.finallyLoc) { var finallyEntry = entry; break; } } finallyEntry && ("break" === type || "continue" === type) && finallyEntry.tryLoc <= arg && arg <= finallyEntry.finallyLoc && (finallyEntry = null); var record = finallyEntry ? finallyEntry.completion : {}; return record.type = type, record.arg = arg, finallyEntry ? (this.method = "next", this.next = finallyEntry.finallyLoc, ContinueSentinel) : this.complete(record); }, complete: function complete(record, afterLoc) { if ("throw" === record.type) throw record.arg; return "break" === record.type || "continue" === record.type ? this.next = record.arg : "return" === record.type ? (this.rval = this.arg = record.arg, this.method = "return", this.next = "end") : "normal" === record.type && afterLoc && (this.next = afterLoc), ContinueSentinel; }, finish: function finish(finallyLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.finallyLoc === finallyLoc) return this.complete(entry.completion, entry.afterLoc), resetTryEntry(entry), ContinueSentinel; } }, catch: function _catch(tryLoc) { for (var i = this.tryEntries.length - 1; i >= 0; --i) { var entry = this.tryEntries[i]; if (entry.tryLoc === tryLoc) { var record = entry.completion; if ("throw" === record.type) { var thrown = record.arg; resetTryEntry(entry); } return thrown; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(iterable, resultName, nextLoc) { return this.delegate = { iterator: values(iterable), resultName: resultName, nextLoc: nextLoc }, "next" === this.method && (this.arg = undefined), ContinueSentinel; } }, exports; }
71
+
58
72
  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
73
 
60
74
  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); }); }; }
@@ -67,7 +81,7 @@ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _d
67
81
 
68
82
  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
83
 
70
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
84
+ function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
71
85
 
72
86
  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
87
 
@@ -77,7 +91,7 @@ function _assertThisInitialized(self) { if (self === void 0) { throw new Referen
77
91
 
78
92
  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
93
 
80
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
94
+ function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
81
95
 
82
96
  // FIXME: copied from Typography.Link. Code is duplicated to
83
97
  // avoid emotion dependency which breaks React 15.x back-compat
@@ -115,10 +129,10 @@ var LinkTo = /*#__PURE__*/function (_PureComponent) {
115
129
  _this.state = {
116
130
  href: '/'
117
131
  };
118
- _this.updateHref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
132
+ _this.updateHref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
119
133
  var _this$props, kind, story, href;
120
134
 
121
- return regeneratorRuntime.wrap(function _callee$(_context) {
135
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
122
136
  while (1) {
123
137
  switch (_context.prev = _context.next) {
124
138
  case 0:
package/dist/cjs/utils.js CHANGED
@@ -23,17 +23,25 @@ Object.defineProperty(exports, "__esModule", {
23
23
  });
24
24
  exports.withLinks = exports.navigate = exports.linkTo = exports.hrefTo = void 0;
25
25
 
26
- require("core-js/modules/es.object.to-string.js");
26
+ require("core-js/modules/es.array.filter.js");
27
27
 
28
- require("core-js/modules/es.promise.js");
28
+ require("core-js/modules/es.object.to-string.js");
29
29
 
30
30
  require("core-js/modules/es.regexp.exec.js");
31
31
 
32
+ require("core-js/modules/es.string.split.js");
33
+
34
+ require("core-js/modules/es.promise.js");
35
+
32
36
  require("core-js/modules/es.string.search.js");
33
37
 
34
38
  require("core-js/modules/es.array.concat.js");
35
39
 
36
- require("core-js/modules/es.string.split.js");
40
+ require("core-js/modules/es.array.join.js");
41
+
42
+ require("core-js/modules/es.array.map.js");
43
+
44
+ require("core-js/modules/es.object.entries.js");
37
45
 
38
46
  require("core-js/modules/es.object.assign.js");
39
47
 
@@ -41,8 +49,6 @@ require("core-js/modules/es.string.match.js");
41
49
 
42
50
  var _global = _interopRequireDefault(require("global"));
43
51
 
44
- var _qs = _interopRequireDefault(require("qs"));
45
-
46
52
  var _addons = require("@storybook/addons");
47
53
 
48
54
  var _coreEvents = require("@storybook/core-events");
@@ -68,6 +74,18 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
68
74
  var document = _global.default.document,
69
75
  HTMLElement = _global.default.HTMLElement;
70
76
 
77
+ function parseQuery(queryString) {
78
+ var query = {};
79
+ var pairs = (queryString[0] === '?' ? queryString.substring(1) : queryString).split('&').filter(Boolean); // eslint-disable-next-line no-plusplus
80
+
81
+ for (var i = 0; i < pairs.length; i++) {
82
+ var pair = pairs[i].split('=');
83
+ query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
84
+ }
85
+
86
+ return query;
87
+ }
88
+
71
89
  var navigate = function navigate(params) {
72
90
  return _addons.addons.getChannel().emit(_coreEvents.SELECT_STORY, params);
73
91
  };
@@ -77,19 +95,15 @@ exports.navigate = navigate;
77
95
  var hrefTo = function hrefTo(title, name) {
78
96
  return new Promise(function (resolve) {
79
97
  var location = document.location;
80
-
81
- var query = _qs.default.parse(location.search, {
82
- ignoreQueryPrefix: true
83
- });
84
-
98
+ var query = parseQuery(location.search);
85
99
  var existingId = [].concat(query.id)[0];
86
100
  var titleToLink = title || existingId.split('--', 2)[0];
87
101
  var id = (0, _csf.toId)(titleToLink, name);
88
- var url = "".concat(location.origin + location.pathname, "?").concat(_qs.default.stringify(Object.assign({}, query, {
102
+ var url = "".concat(location.origin + location.pathname, "?").concat(Object.entries(Object.assign({}, query, {
89
103
  id: id
90
- }), {
91
- encode: false
92
- }));
104
+ })).map(function (item) {
105
+ return "".concat(item[0], "=").concat(item[1]);
106
+ }).join('&'));
93
107
  resolve(url);
94
108
  });
95
109
  };
@@ -1,7 +1,7 @@
1
- export var ADDON_ID = 'storybook/links';
2
- export var PARAM_KEY = "links";
1
+ export const ADDON_ID = 'storybook/links';
2
+ export const PARAM_KEY = `links`;
3
3
  export default {
4
- NAVIGATE: "".concat(ADDON_ID, "/navigate"),
5
- REQUEST: "".concat(ADDON_ID, "/request"),
6
- RECEIVE: "".concat(ADDON_ID, "/receive")
4
+ NAVIGATE: `${ADDON_ID}/navigate`,
5
+ REQUEST: `${ADDON_ID}/request`,
6
+ RECEIVE: `${ADDON_ID}/receive`
7
7
  };
package/dist/esm/index.js CHANGED
@@ -1,16 +1,12 @@
1
- import "core-js/modules/es.array.slice.js";
2
- import "core-js/modules/es.object.freeze.js";
3
-
4
- var _templateObject;
5
-
6
- function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
7
-
8
1
  import dedent from 'ts-dedent';
9
- var hasWarned = false;
2
+ let hasWarned = false;
10
3
  export function LinkTo() {
11
4
  if (!hasWarned) {
12
5
  // eslint-disable-next-line no-console
13
- console.error(dedent(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n LinkTo has moved to addon-links/react:\n import LinkTo from '@storybook/addon-links/react';\n "]))));
6
+ console.error(dedent`
7
+ LinkTo has moved to addon-links/react:
8
+ import LinkTo from '@storybook/addon-links/react';
9
+ `);
14
10
  hasWarned = true;
15
11
  }
16
12
 
@@ -1,12 +1,12 @@
1
- import "core-js/modules/es.function.name.js";
2
1
  import { addons } from '@storybook/addons';
3
2
  import EVENTS, { ADDON_ID } from './constants';
4
- addons.register(ADDON_ID, function (api) {
5
- var channel = addons.getChannel();
6
- channel.on(EVENTS.REQUEST, function (_ref) {
7
- var kind = _ref.kind,
8
- name = _ref.name;
9
- var id = api.storyId(kind, name);
3
+ addons.register(ADDON_ID, api => {
4
+ const channel = addons.getChannel();
5
+ channel.on(EVENTS.REQUEST, ({
6
+ kind,
7
+ name
8
+ }) => {
9
+ const id = api.storyId(kind, name);
10
10
  api.emit(EVENTS.RECEIVE, id);
11
11
  });
12
12
  });
@@ -1,2 +1,2 @@
1
1
  import { withLinks } from './index';
2
- export var decorators = [withLinks];
2
+ export const decorators = [withLinks];
@@ -5,36 +5,33 @@ import React from 'react'; // NOTE: this is a copy of `lib/components/src/naviga
5
5
  // on a specific react version. However, that's a heavy-handed solution for
6
6
  // one trivial file.
7
7
 
8
- var LEFT_BUTTON = 0; // Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
8
+ const LEFT_BUTTON = 0; // Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
9
9
 
10
- var isPlainLeftClick = function isPlainLeftClick(e) {
11
- return e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
12
- };
13
-
14
- var RoutedLink = function RoutedLink(_ref) {
15
- var _ref$href = _ref.href,
16
- href = _ref$href === void 0 ? '#' : _ref$href,
17
- children = _ref.children,
18
- onClick = _ref.onClick,
19
- className = _ref.className,
20
- style = _ref.style;
10
+ const isPlainLeftClick = e => e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
21
11
 
22
- var handleClick = function handleClick(e) {
12
+ const RoutedLink = ({
13
+ href = '#',
14
+ children,
15
+ onClick,
16
+ className,
17
+ style
18
+ }) => {
19
+ const handleClick = e => {
23
20
  if (isPlainLeftClick(e)) {
24
21
  e.preventDefault();
25
22
  onClick(e);
26
23
  }
27
24
  };
28
25
 
29
- var props = onClick ? {
30
- href: href,
31
- className: className,
32
- style: style,
26
+ const props = onClick ? {
27
+ href,
28
+ className,
29
+ style,
33
30
  onClick: handleClick
34
31
  } : {
35
- href: href,
36
- className: className,
37
- style: style
32
+ href,
33
+ className,
34
+ style
38
35
  };
39
36
  return /*#__PURE__*/React.createElement("a", props, children);
40
37
  };
@@ -1,167 +1,82 @@
1
- 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); }
1
+ const _excluded = ["kind", "story", "children"];
2
2
 
3
- import "core-js/modules/es.object.to-string.js";
4
- import "core-js/modules/es.reflect.construct.js";
5
- import "core-js/modules/es.promise.js";
6
- import "core-js/modules/es.object.keys.js";
7
- import "core-js/modules/es.symbol.js";
8
- import "core-js/modules/es.object.assign.js";
9
- import "core-js/modules/es.symbol.description.js";
10
- import "core-js/modules/es.symbol.iterator.js";
11
- import "core-js/modules/es.array.iterator.js";
12
- import "core-js/modules/es.string.iterator.js";
13
- import "core-js/modules/web.dom-collections.iterator.js";
14
- var _excluded = ["kind", "story", "children"];
15
-
16
- 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); }
17
-
18
- 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; }
3
+ function _extends() { _extends = Object.assign ? Object.assign.bind() : 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); }
19
4
 
20
5
  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; }
21
6
 
22
- import "regenerator-runtime/runtime.js";
23
-
24
- 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); } }
25
-
26
- 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); }); }; }
27
-
28
- import "core-js/modules/es.array.concat.js";
29
- import "core-js/modules/es.object.get-prototype-of.js";
30
-
31
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
32
-
33
- 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); } }
34
-
35
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
36
-
37
- 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); }
38
-
39
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
40
-
41
- 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); }; }
42
-
43
- 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); }
44
-
45
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
46
-
47
- 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; } }
48
-
49
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
50
-
51
7
  import React, { PureComponent } from 'react';
52
8
  import { navigate, hrefTo } from '../../utils'; // FIXME: copied from Typography.Link. Code is duplicated to
53
9
  // avoid emotion dependency which breaks React 15.x back-compat
54
10
  // Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
55
11
 
56
- var LEFT_BUTTON = 0;
57
-
58
- var isPlainLeftClick = function isPlainLeftClick(e) {
59
- return e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
60
- };
12
+ const LEFT_BUTTON = 0;
61
13
 
62
- var cancelled = function cancelled(e) {
63
- var cb = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function (_e) {};
14
+ const isPlainLeftClick = e => e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
64
15
 
16
+ const cancelled = (e, cb = _e => {}) => {
65
17
  if (isPlainLeftClick(e)) {
66
18
  e.preventDefault();
67
19
  cb(e);
68
20
  }
69
21
  };
70
22
 
71
- var LinkTo = /*#__PURE__*/function (_PureComponent) {
72
- _inherits(LinkTo, _PureComponent);
73
-
74
- var _super = _createSuper(LinkTo);
75
-
76
- function LinkTo() {
77
- var _this;
78
-
79
- _classCallCheck(this, LinkTo);
80
-
81
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
82
- args[_key] = arguments[_key];
83
- }
84
-
85
- _this = _super.call.apply(_super, [this].concat(args));
86
- _this.state = {
23
+ export default class LinkTo extends PureComponent {
24
+ constructor(...args) {
25
+ super(...args);
26
+ this.state = {
87
27
  href: '/'
88
28
  };
89
- _this.updateHref = /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/regeneratorRuntime.mark(function _callee() {
90
- var _this$props, kind, story, href;
91
29
 
92
- return regeneratorRuntime.wrap(function _callee$(_context) {
93
- while (1) {
94
- switch (_context.prev = _context.next) {
95
- case 0:
96
- _this$props = _this.props, kind = _this$props.kind, story = _this$props.story;
97
- _context.next = 3;
98
- return hrefTo(kind, story);
99
-
100
- case 3:
101
- href = _context.sent;
102
-
103
- _this.setState({
104
- href: href
105
- });
106
-
107
- case 5:
108
- case "end":
109
- return _context.stop();
110
- }
111
- }
112
- }, _callee);
113
- }));
114
-
115
- _this.handleClick = function () {
116
- navigate(_this.props);
30
+ this.updateHref = async () => {
31
+ const {
32
+ kind,
33
+ story
34
+ } = this.props;
35
+ const href = await hrefTo(kind, story);
36
+ this.setState({
37
+ href
38
+ });
117
39
  };
118
40
 
119
- return _this;
41
+ this.handleClick = () => {
42
+ navigate(this.props);
43
+ };
120
44
  }
121
45
 
122
- _createClass(LinkTo, [{
123
- key: "componentDidMount",
124
- value: function componentDidMount() {
125
- this.updateHref();
126
- }
127
- }, {
128
- key: "componentDidUpdate",
129
- value: function componentDidUpdate(prevProps) {
130
- var _this$props2 = this.props,
131
- kind = _this$props2.kind,
132
- story = _this$props2.story;
133
-
134
- if (prevProps.kind !== kind || prevProps.story !== story) {
135
- this.updateHref();
136
- }
137
- }
138
- }, {
139
- key: "render",
140
- value: function render() {
141
- var _this2 = this;
46
+ componentDidMount() {
47
+ this.updateHref();
48
+ }
142
49
 
143
- var _this$props3 = this.props,
144
- kind = _this$props3.kind,
145
- story = _this$props3.story,
146
- children = _this$props3.children,
147
- rest = _objectWithoutProperties(_this$props3, _excluded);
50
+ componentDidUpdate(prevProps) {
51
+ const {
52
+ kind,
53
+ story
54
+ } = this.props;
148
55
 
149
- var href = this.state.href;
150
- return /*#__PURE__*/React.createElement("a", _extends({
151
- href: href,
152
- onClick: function onClick(e) {
153
- return cancelled(e, _this2.handleClick);
154
- }
155
- }, rest), children);
56
+ if (prevProps.kind !== kind || prevProps.story !== story) {
57
+ this.updateHref();
156
58
  }
157
- }]);
59
+ }
158
60
 
159
- return LinkTo;
160
- }(PureComponent);
61
+ render() {
62
+ const _this$props = this.props,
63
+ {
64
+ children
65
+ } = _this$props,
66
+ rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
67
+
68
+ const {
69
+ href
70
+ } = this.state;
71
+ return /*#__PURE__*/React.createElement("a", _extends({
72
+ href: href,
73
+ onClick: e => cancelled(e, this.handleClick)
74
+ }, rest), children);
75
+ }
161
76
 
77
+ }
162
78
  LinkTo.defaultProps = {
163
79
  kind: null,
164
80
  story: null,
165
81
  children: undefined
166
- };
167
- export { LinkTo as default };
82
+ };
package/dist/esm/utils.js CHANGED
@@ -1,131 +1,105 @@
1
- function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
-
3
- function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
4
-
5
- function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
6
-
7
- function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
8
-
9
- function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
10
-
11
- function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
12
-
13
- import "core-js/modules/es.object.to-string.js";
14
- import "core-js/modules/es.promise.js";
15
- import "core-js/modules/es.regexp.exec.js";
16
- import "core-js/modules/es.string.search.js";
17
- import "core-js/modules/es.array.concat.js";
18
- import "core-js/modules/es.string.split.js";
19
- import "core-js/modules/es.object.assign.js";
20
- import "core-js/modules/es.string.match.js";
21
- import "core-js/modules/es.symbol.js";
22
- import "core-js/modules/es.symbol.description.js";
23
- import "core-js/modules/es.symbol.iterator.js";
24
- import "core-js/modules/es.array.iterator.js";
25
- import "core-js/modules/es.string.iterator.js";
26
- import "core-js/modules/web.dom-collections.iterator.js";
27
- import "core-js/modules/es.array.from.js";
28
- import "core-js/modules/es.array.slice.js";
29
- import "core-js/modules/es.function.name.js";
30
1
  import global from 'global';
31
- import qs from 'qs';
32
2
  import { addons, makeDecorator } from '@storybook/addons';
33
3
  import { STORY_CHANGED, SELECT_STORY } from '@storybook/core-events';
34
4
  import { toId } from '@storybook/csf';
35
5
  import { PARAM_KEY } from './constants';
36
- var document = global.document,
37
- HTMLElement = global.HTMLElement;
38
- export var navigate = function navigate(params) {
39
- return addons.getChannel().emit(SELECT_STORY, params);
40
- };
41
- export var hrefTo = function hrefTo(title, name) {
42
- return new Promise(function (resolve) {
43
- var location = document.location;
44
- var query = qs.parse(location.search, {
45
- ignoreQueryPrefix: true
46
- });
47
- var existingId = [].concat(query.id)[0];
48
- var titleToLink = title || existingId.split('--', 2)[0];
49
- var id = toId(titleToLink, name);
50
- var url = "".concat(location.origin + location.pathname, "?").concat(qs.stringify(Object.assign({}, query, {
51
- id: id
52
- }), {
53
- encode: false
54
- }));
6
+ const {
7
+ document,
8
+ HTMLElement
9
+ } = global;
10
+
11
+ function parseQuery(queryString) {
12
+ const query = {};
13
+ const pairs = (queryString[0] === '?' ? queryString.substring(1) : queryString).split('&').filter(Boolean); // eslint-disable-next-line no-plusplus
14
+
15
+ for (let i = 0; i < pairs.length; i++) {
16
+ const pair = pairs[i].split('=');
17
+ query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || '');
18
+ }
19
+
20
+ return query;
21
+ }
22
+
23
+ export const navigate = params => addons.getChannel().emit(SELECT_STORY, params);
24
+ export const hrefTo = (title, name) => {
25
+ return new Promise(resolve => {
26
+ const {
27
+ location
28
+ } = document;
29
+ const query = parseQuery(location.search);
30
+ const existingId = [].concat(query.id)[0];
31
+ const titleToLink = title || existingId.split('--', 2)[0];
32
+ const id = toId(titleToLink, name);
33
+ const url = `${location.origin + location.pathname}?${Object.entries(Object.assign({}, query, {
34
+ id
35
+ })).map(item => `${item[0]}=${item[1]}`).join('&')}`;
55
36
  resolve(url);
56
37
  });
57
38
  };
58
39
 
59
- var valueOrCall = function valueOrCall(args) {
60
- return function (value) {
61
- return typeof value === 'function' ? value.apply(void 0, _toConsumableArray(args)) : value;
62
- };
63
- };
64
-
65
- export var linkTo = function linkTo(idOrTitle, nameInput) {
66
- return function () {
67
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
68
- args[_key] = arguments[_key];
69
- }
40
+ const valueOrCall = args => value => typeof value === 'function' ? value(...args) : value;
70
41
 
71
- var resolver = valueOrCall(args);
72
- var title = resolver(idOrTitle);
73
- var name = resolver(nameInput);
42
+ export const linkTo = (idOrTitle, nameInput) => (...args) => {
43
+ const resolver = valueOrCall(args);
44
+ const title = resolver(idOrTitle);
45
+ const name = resolver(nameInput);
74
46
 
75
- if (title !== null && title !== void 0 && title.match(/--/) && !name) {
76
- navigate({
77
- storyId: title
78
- });
79
- } else {
80
- navigate({
81
- kind: title,
82
- story: name
83
- });
84
- }
85
- };
47
+ if (title?.match(/--/) && !name) {
48
+ navigate({
49
+ storyId: title
50
+ });
51
+ } else {
52
+ navigate({
53
+ kind: title,
54
+ story: name
55
+ });
56
+ }
86
57
  };
87
58
 
88
- var linksListener = function linksListener(e) {
89
- var target = e.target;
59
+ const linksListener = e => {
60
+ const {
61
+ target
62
+ } = e;
90
63
 
91
64
  if (!(target instanceof HTMLElement)) {
92
65
  return;
93
66
  }
94
67
 
95
- var element = target;
96
- var _element$dataset = element.dataset,
97
- kind = _element$dataset.sbKind,
98
- story = _element$dataset.sbStory;
68
+ const element = target;
69
+ const {
70
+ sbKind: kind,
71
+ sbStory: story
72
+ } = element.dataset;
99
73
 
100
74
  if (kind || story) {
101
75
  e.preventDefault();
102
76
  navigate({
103
- kind: kind,
104
- story: story
77
+ kind,
78
+ story
105
79
  });
106
80
  }
107
81
  };
108
82
 
109
- var hasListener = false;
83
+ let hasListener = false;
110
84
 
111
- var on = function on() {
85
+ const on = () => {
112
86
  if (!hasListener) {
113
87
  hasListener = true;
114
88
  document.addEventListener('click', linksListener);
115
89
  }
116
90
  };
117
91
 
118
- var off = function off() {
92
+ const off = () => {
119
93
  if (hasListener) {
120
94
  hasListener = false;
121
95
  document.removeEventListener('click', linksListener);
122
96
  }
123
97
  };
124
98
 
125
- export var withLinks = makeDecorator({
99
+ export const withLinks = makeDecorator({
126
100
  name: 'withLinks',
127
101
  parameterName: PARAM_KEY,
128
- wrapper: function wrapper(getStory, context) {
102
+ wrapper: (getStory, context) => {
129
103
  on();
130
104
  addons.getChannel().once(STORY_CHANGED, off);
131
105
  return getStory(context);
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@storybook/addon-links",
3
- "version": "6.5.7",
3
+ "version": "7.0.0-alpha.0",
4
4
  "description": "Link stories together to build demos and prototypes with your UI components",
5
5
  "keywords": [
6
6
  "addon",
@@ -23,14 +23,7 @@
23
23
  "license": "MIT",
24
24
  "main": "dist/cjs/index.js",
25
25
  "module": "dist/esm/index.js",
26
- "types": "dist/ts3.9/index.d.ts",
27
- "typesVersions": {
28
- "<3.8": {
29
- "dist/ts3.9/*": [
30
- "dist/ts3.4/*"
31
- ]
32
- }
33
- },
26
+ "types": "dist/types/index.d.ts",
34
27
  "files": [
35
28
  "dist/**/*",
36
29
  "README.md",
@@ -41,22 +34,17 @@
41
34
  "prepare": "node ../../scripts/prepare.js"
42
35
  },
43
36
  "dependencies": {
44
- "@storybook/addons": "6.5.7",
45
- "@storybook/client-logger": "6.5.7",
46
- "@storybook/core-events": "6.5.7",
37
+ "@storybook/addons": "7.0.0-alpha.0",
38
+ "@storybook/client-logger": "7.0.0-alpha.0",
39
+ "@storybook/core-events": "7.0.0-alpha.0",
47
40
  "@storybook/csf": "0.0.2--canary.4566f4d.1",
48
- "@storybook/router": "6.5.7",
49
- "@types/qs": "^6.9.5",
41
+ "@storybook/router": "7.0.0-alpha.0",
50
42
  "core-js": "^3.8.2",
51
43
  "global": "^4.4.0",
52
44
  "prop-types": "^15.7.2",
53
- "qs": "^6.10.0",
54
45
  "regenerator-runtime": "^0.13.7",
55
46
  "ts-dedent": "^2.0.0"
56
47
  },
57
- "devDependencies": {
58
- "@types/webpack-env": "^1.16.0"
59
- },
60
48
  "peerDependencies": {
61
49
  "react": "^16.8.0 || ^17.0.0 || ^18.0.0",
62
50
  "react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
@@ -72,8 +60,7 @@
72
60
  "publishConfig": {
73
61
  "access": "public"
74
62
  },
75
- "gitHead": "7e19d3e734efa14e7cffba146295ca0d3467a8c6",
76
- "sbmodern": "dist/modern/index.js",
63
+ "gitHead": "c82d897ea765da8cf4fbbcc2af1f28c808a93e23",
77
64
  "storybook": {
78
65
  "displayName": "Links",
79
66
  "icon": "https://user-images.githubusercontent.com/263385/101991673-48355c80-3c7c-11eb-9b6e-b627c96a75f6.png",
package/react.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- export * from './dist/ts3.9/react';
2
- export { default } from './dist/ts3.9/react';
1
+ export * from './dist/types/react';
2
+ export { default } from './dist/types/react';
@@ -1,7 +0,0 @@
1
- export const ADDON_ID = 'storybook/links';
2
- export const PARAM_KEY = `links`;
3
- export default {
4
- NAVIGATE: `${ADDON_ID}/navigate`,
5
- REQUEST: `${ADDON_ID}/request`,
6
- RECEIVE: `${ADDON_ID}/receive`
7
- };
@@ -1,19 +0,0 @@
1
- import dedent from 'ts-dedent';
2
- let hasWarned = false;
3
- export function LinkTo() {
4
- if (!hasWarned) {
5
- // eslint-disable-next-line no-console
6
- console.error(dedent`
7
- LinkTo has moved to addon-links/react:
8
- import LinkTo from '@storybook/addon-links/react';
9
- `);
10
- hasWarned = true;
11
- }
12
-
13
- return null;
14
- }
15
- export { linkTo, hrefTo, withLinks, navigate } from './utils';
16
-
17
- if (module && module.hot && module.hot.decline) {
18
- module.hot.decline();
19
- }
@@ -1,12 +0,0 @@
1
- import { addons } from '@storybook/addons';
2
- import EVENTS, { ADDON_ID } from './constants';
3
- addons.register(ADDON_ID, api => {
4
- const channel = addons.getChannel();
5
- channel.on(EVENTS.REQUEST, ({
6
- kind,
7
- name
8
- }) => {
9
- const id = api.storyId(kind, name);
10
- api.emit(EVENTS.RECEIVE, id);
11
- });
12
- });
@@ -1,2 +0,0 @@
1
- import { withLinks } from './index';
2
- export const decorators = [withLinks];
@@ -1,39 +0,0 @@
1
- import React from 'react'; // NOTE: this is a copy of `lib/components/src/navigation/RoutedLink.tsx`.
2
- // It's duplicated here because that copy has an explicit dependency on
3
- // React 16.3+, which breaks older versions of React running in the preview.
4
- // The proper DRY solution is to create a new package that doesn't depend
5
- // on a specific react version. However, that's a heavy-handed solution for
6
- // one trivial file.
7
-
8
- const LEFT_BUTTON = 0; // Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
9
-
10
- const isPlainLeftClick = e => e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
11
-
12
- const RoutedLink = ({
13
- href = '#',
14
- children,
15
- onClick,
16
- className,
17
- style
18
- }) => {
19
- const handleClick = e => {
20
- if (isPlainLeftClick(e)) {
21
- e.preventDefault();
22
- onClick(e);
23
- }
24
- };
25
-
26
- const props = onClick ? {
27
- href,
28
- className,
29
- style,
30
- onClick: handleClick
31
- } : {
32
- href,
33
- className,
34
- style
35
- };
36
- return /*#__PURE__*/React.createElement("a", props, children);
37
- };
38
-
39
- export default RoutedLink;
@@ -1,82 +0,0 @@
1
- const _excluded = ["kind", "story", "children"];
2
-
3
- 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); }
4
-
5
- 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; }
6
-
7
- import React, { PureComponent } from 'react';
8
- import { navigate, hrefTo } from '../../utils'; // FIXME: copied from Typography.Link. Code is duplicated to
9
- // avoid emotion dependency which breaks React 15.x back-compat
10
- // Cmd/Ctrl/Shift/Alt + Click should trigger default browser behaviour. Same applies to non-left clicks
11
-
12
- const LEFT_BUTTON = 0;
13
-
14
- const isPlainLeftClick = e => e.button === LEFT_BUTTON && !e.altKey && !e.ctrlKey && !e.metaKey && !e.shiftKey;
15
-
16
- const cancelled = (e, cb = _e => {}) => {
17
- if (isPlainLeftClick(e)) {
18
- e.preventDefault();
19
- cb(e);
20
- }
21
- };
22
-
23
- export default class LinkTo extends PureComponent {
24
- constructor(...args) {
25
- super(...args);
26
- this.state = {
27
- href: '/'
28
- };
29
-
30
- this.updateHref = async () => {
31
- const {
32
- kind,
33
- story
34
- } = this.props;
35
- const href = await hrefTo(kind, story);
36
- this.setState({
37
- href
38
- });
39
- };
40
-
41
- this.handleClick = () => {
42
- navigate(this.props);
43
- };
44
- }
45
-
46
- componentDidMount() {
47
- this.updateHref();
48
- }
49
-
50
- componentDidUpdate(prevProps) {
51
- const {
52
- kind,
53
- story
54
- } = this.props;
55
-
56
- if (prevProps.kind !== kind || prevProps.story !== story) {
57
- this.updateHref();
58
- }
59
- }
60
-
61
- render() {
62
- const _this$props = this.props,
63
- {
64
- children
65
- } = _this$props,
66
- rest = _objectWithoutPropertiesLoose(_this$props, _excluded);
67
-
68
- const {
69
- href
70
- } = this.state;
71
- return /*#__PURE__*/React.createElement("a", _extends({
72
- href: href,
73
- onClick: e => cancelled(e, this.handleClick)
74
- }, rest), children);
75
- }
76
-
77
- }
78
- LinkTo.defaultProps = {
79
- kind: null,
80
- story: null,
81
- children: undefined
82
- };
@@ -1,2 +0,0 @@
1
- import LinkTo from './components/link';
2
- export default LinkTo;
@@ -1,99 +0,0 @@
1
- import global from 'global';
2
- import qs from 'qs';
3
- import { addons, makeDecorator } from '@storybook/addons';
4
- import { STORY_CHANGED, SELECT_STORY } from '@storybook/core-events';
5
- import { toId } from '@storybook/csf';
6
- import { PARAM_KEY } from './constants';
7
- const {
8
- document,
9
- HTMLElement
10
- } = global;
11
- export const navigate = params => addons.getChannel().emit(SELECT_STORY, params);
12
- export const hrefTo = (title, name) => {
13
- return new Promise(resolve => {
14
- const {
15
- location
16
- } = document;
17
- const query = qs.parse(location.search, {
18
- ignoreQueryPrefix: true
19
- });
20
- const existingId = [].concat(query.id)[0];
21
- const titleToLink = title || existingId.split('--', 2)[0];
22
- const id = toId(titleToLink, name);
23
- const url = `${location.origin + location.pathname}?${qs.stringify(Object.assign({}, query, {
24
- id
25
- }), {
26
- encode: false
27
- })}`;
28
- resolve(url);
29
- });
30
- };
31
-
32
- const valueOrCall = args => value => typeof value === 'function' ? value(...args) : value;
33
-
34
- export const linkTo = (idOrTitle, nameInput) => (...args) => {
35
- const resolver = valueOrCall(args);
36
- const title = resolver(idOrTitle);
37
- const name = resolver(nameInput);
38
-
39
- if (title !== null && title !== void 0 && title.match(/--/) && !name) {
40
- navigate({
41
- storyId: title
42
- });
43
- } else {
44
- navigate({
45
- kind: title,
46
- story: name
47
- });
48
- }
49
- };
50
-
51
- const linksListener = e => {
52
- const {
53
- target
54
- } = e;
55
-
56
- if (!(target instanceof HTMLElement)) {
57
- return;
58
- }
59
-
60
- const element = target;
61
- const {
62
- sbKind: kind,
63
- sbStory: story
64
- } = element.dataset;
65
-
66
- if (kind || story) {
67
- e.preventDefault();
68
- navigate({
69
- kind,
70
- story
71
- });
72
- }
73
- };
74
-
75
- let hasListener = false;
76
-
77
- const on = () => {
78
- if (!hasListener) {
79
- hasListener = true;
80
- document.addEventListener('click', linksListener);
81
- }
82
- };
83
-
84
- const off = () => {
85
- if (hasListener) {
86
- hasListener = false;
87
- document.removeEventListener('click', linksListener);
88
- }
89
- };
90
-
91
- export const withLinks = makeDecorator({
92
- name: 'withLinks',
93
- parameterName: PARAM_KEY,
94
- wrapper: (getStory, context) => {
95
- on();
96
- addons.getChannel().once(STORY_CHANGED, off);
97
- return getStory(context);
98
- }
99
- });
@@ -1,8 +0,0 @@
1
- export declare const ADDON_ID = "storybook/links";
2
- export declare const PARAM_KEY = "links";
3
- declare const _default: {
4
- NAVIGATE: string;
5
- REQUEST: string;
6
- RECEIVE: string;
7
- };
8
- export default _default;
@@ -1,2 +0,0 @@
1
- export declare function LinkTo(): null;
2
- export { linkTo, hrefTo, withLinks, navigate } from './utils';
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export declare const decorators: ((...args: any) => any)[];
@@ -1,3 +0,0 @@
1
- import React from 'react';
2
- declare const RoutedLink: React.FC<React.DetailedHTMLProps<React.AnchorHTMLAttributes<HTMLAnchorElement>, HTMLAnchorElement>>;
3
- export default RoutedLink;
@@ -1,19 +0,0 @@
1
- import { PureComponent, ReactNode } from 'react';
2
- interface Props {
3
- kind: string;
4
- story: string;
5
- children: ReactNode;
6
- }
7
- interface State {
8
- href: string;
9
- }
10
- export default class LinkTo extends PureComponent<Props, State> {
11
- static defaultProps: Props;
12
- state: State;
13
- componentDidMount(): void;
14
- componentDidUpdate(prevProps: Props): void;
15
- updateHref: () => Promise<void>;
16
- handleClick: () => void;
17
- render(): JSX.Element;
18
- }
19
- export {};
@@ -1,2 +0,0 @@
1
- import LinkTo from './components/link';
2
- export default LinkTo;
@@ -1,13 +0,0 @@
1
- import { StoryId, StoryName, ComponentTitle } from '@storybook/csf';
2
- interface ParamsId {
3
- storyId: StoryId;
4
- }
5
- interface ParamsCombo {
6
- kind?: ComponentTitle;
7
- story?: StoryName;
8
- }
9
- export declare const navigate: (params: ParamsId | ParamsCombo) => void;
10
- export declare const hrefTo: (title: ComponentTitle, name: StoryName) => Promise<string>;
11
- export declare const linkTo: (idOrTitle: string, nameInput?: string | ((...args: any[]) => string)) => (...args: any[]) => void;
12
- export declare const withLinks: (...args: any) => any;
13
- export {};