1 | 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); }
|
2 |
|
3 | 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; }
|
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 "core-js/modules/es.string.starts-with.js";
|
8 | import "core-js/modules/es.array.concat.js";
|
9 | import "core-js/modules/es.string.search.js";
|
10 | import "core-js/modules/es.regexp.exec.js";
|
11 | import "core-js/modules/es.object.assign.js";
|
12 | import "core-js/modules/es.string.match.js";
|
13 | import "core-js/modules/es.object.keys.js";
|
14 | import "core-js/modules/es.symbol.js";
|
15 | import global from 'global';
|
16 | import React, { useCallback } from 'react';
|
17 | import { Link, BrowserRouter, useNavigate, useLocation, Router } from 'react-router-dom';
|
18 | import { ToggleVisibility } from './visibility';
|
19 | import { queryFromString, parsePath, getMatch } from './utils';
|
20 | var document = global.document;
|
21 |
|
22 | var getBase = function getBase() {
|
23 | return "".concat(document.location.pathname, "?");
|
24 | };
|
25 |
|
26 |
|
27 |
|
28 | var useQueryNavigate = function useQueryNavigate() {
|
29 | var navigate = useNavigate();
|
30 | return useCallback(function (to, options) {
|
31 | if (typeof to === 'string' && to.startsWith('#')) {
|
32 | document.location.hash = to;
|
33 | return undefined;
|
34 | }
|
35 |
|
36 | if (typeof to === 'string') {
|
37 | var target = options !== null && options !== void 0 && options.plain ? to : "?path=".concat(to);
|
38 | return navigate(target, options);
|
39 | }
|
40 |
|
41 | if (typeof to === 'number') {
|
42 | return navigate(to);
|
43 | }
|
44 |
|
45 | return undefined;
|
46 | }, []);
|
47 | };
|
48 |
|
49 |
|
50 | var QueryLink = function QueryLink(_ref) {
|
51 | var to = _ref.to,
|
52 | children = _ref.children,
|
53 | rest = _objectWithoutProperties(_ref, ["to", "children"]);
|
54 |
|
55 | return React.createElement(Link, _extends({
|
56 | to: "".concat(getBase(), "path=").concat(to)
|
57 | }, rest), children);
|
58 | };
|
59 |
|
60 | QueryLink.displayName = "QueryLink";
|
61 | QueryLink.displayName = 'QueryLink';
|
62 |
|
63 |
|
64 | var QueryLocation = function QueryLocation(_ref2) {
|
65 | var children = _ref2.children;
|
66 | var location = useLocation();
|
67 |
|
68 | var _queryFromString = queryFromString(location.search),
|
69 | path = _queryFromString.path,
|
70 | singleStory = _queryFromString.singleStory;
|
71 |
|
72 | var _parsePath = parsePath(path),
|
73 | viewMode = _parsePath.viewMode,
|
74 | storyId = _parsePath.storyId,
|
75 | refId = _parsePath.refId;
|
76 |
|
77 | return React.createElement(React.Fragment, null, children({
|
78 | path: path,
|
79 | location: location,
|
80 | viewMode: viewMode,
|
81 | storyId: storyId,
|
82 | refId: refId,
|
83 | singleStory: singleStory === 'true'
|
84 | }));
|
85 | };
|
86 |
|
87 | QueryLocation.displayName = 'QueryLocation';
|
88 |
|
89 |
|
90 |
|
91 | var QueryMatch = function QueryMatch(_ref3) {
|
92 | var children = _ref3.children,
|
93 | targetPath = _ref3.path,
|
94 | _ref3$startsWith = _ref3.startsWith,
|
95 | startsWith = _ref3$startsWith === void 0 ? false : _ref3$startsWith;
|
96 | return React.createElement(QueryLocation, null, function (_ref4) {
|
97 | var urlPath = _ref4.path,
|
98 | rest = _objectWithoutProperties(_ref4, ["path"]);
|
99 |
|
100 | return children(Object.assign({
|
101 | match: getMatch(urlPath, targetPath, startsWith)
|
102 | }, rest));
|
103 | });
|
104 | };
|
105 |
|
106 | QueryMatch.displayName = "QueryMatch";
|
107 | QueryMatch.displayName = 'QueryMatch';
|
108 |
|
109 | var Route = function Route(_ref5) {
|
110 | var path = _ref5.path,
|
111 | children = _ref5.children,
|
112 | _ref5$startsWith = _ref5.startsWith,
|
113 | startsWith = _ref5$startsWith === void 0 ? false : _ref5$startsWith,
|
114 | _ref5$hideOnly = _ref5.hideOnly,
|
115 | hideOnly = _ref5$hideOnly === void 0 ? false : _ref5$hideOnly;
|
116 | return React.createElement(QueryMatch, {
|
117 | path: path,
|
118 | startsWith: startsWith
|
119 | }, function (_ref6) {
|
120 | var match = _ref6.match;
|
121 |
|
122 | if (hideOnly) {
|
123 | return React.createElement(ToggleVisibility, {
|
124 | hidden: !match
|
125 | }, children);
|
126 | }
|
127 |
|
128 | return match ? children : null;
|
129 | });
|
130 | };
|
131 |
|
132 | Route.displayName = "Route";
|
133 | Route.displayName = 'Route';
|
134 | export { QueryLink as Link };
|
135 | export { QueryMatch as Match };
|
136 | export { QueryLocation as Location };
|
137 | export { Route };
|
138 | export { useQueryNavigate as useNavigate };
|
139 | export { BrowserRouter as LocationProvider };
|
140 | export { Router as BaseLocationProvider };
|
141 | export { useNavigate as usePlainNavigate }; |
\ | No newline at end of file |