@prezly/theme-kit-core 10.15.1 → 10.16.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.
- package/build/content-delivery/ContentDelivery.cjs +100 -14
- package/build/content-delivery/ContentDelivery.d.ts +50 -1
- package/build/content-delivery/ContentDelivery.mjs +96 -13
- package/build/content-delivery/ContentDelivery.test.cjs +85 -1
- package/build/content-delivery/ContentDelivery.test.mjs +85 -1
- package/build/content-delivery/RequestCoalescer.cjs +1 -1
- package/build/content-delivery/RequestCoalescer.mjs +1 -1
- package/build/content-delivery/metrics.cjs +1 -1
- package/build/content-delivery/metrics.mjs +1 -1
- package/build/content-delivery/telemetry.cjs +1 -1
- package/build/content-delivery/telemetry.mjs +1 -1
- package/build/environment.cjs +1 -1
- package/build/environment.mjs +1 -1
- package/build/http/HttpClient.cjs +1 -1
- package/build/http/HttpClient.mjs +1 -1
- package/build/http/index.cjs +2 -1
- package/build/index.cjs +2 -1
- package/build/metadata/getAlternateLanguageLinks.cjs +1 -1
- package/build/metadata/getAlternateLanguageLinks.mjs +1 -1
- package/build/routing/Route.cjs +27 -8
- package/build/routing/Route.mjs +27 -8
- package/build/routing/Route.test.cjs +46 -0
- package/build/routing/Route.test.mjs +46 -0
- package/build/routing/index.cjs +2 -1
- package/build/routing/types.d.ts +2 -0
- package/build/routing/utils/generateUrlFromPattern.cjs +19 -10
- package/build/routing/utils/generateUrlFromPattern.mjs +19 -10
- package/build/routing/utils/generateUrlFromPattern.test.cjs +15 -0
- package/build/routing/utils/generateUrlFromPattern.test.mjs +15 -0
- package/build/routing/utils/wildcard.cjs +76 -0
- package/build/routing/utils/wildcard.d.ts +25 -0
- package/build/routing/utils/wildcard.mjs +66 -0
- package/build/sitemap/build.cjs +1 -1
- package/build/sitemap/build.mjs +1 -1
- package/build/sitemap/generate.cjs +5 -1
- package/build/sitemap/generate.mjs +5 -1
- package/package.json +2 -2
|
@@ -12,7 +12,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
12
12
|
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; }
|
|
13
13
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
14
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
15
|
-
function _toPrimitive(t,
|
|
15
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
16
16
|
var CONTENT_OPERATIONS = exports.CONTENT_OPERATIONS = ['newsroom', 'theme', 'languages', 'categories', 'featuredContacts', 'galleries', 'gallery', 'stories', 'allStories', 'story', 'other'];
|
|
17
17
|
var UPSTREAM_ROUTES = exports.UPSTREAM_ROUTES = ['newsroom', 'theme', 'languages', 'categories', 'contacts', 'galleries', 'gallery', 'stories', 'story', 'story_by_slug', 'other'];
|
|
18
18
|
|
|
@@ -2,7 +2,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
2
2
|
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; }
|
|
3
3
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
|
-
function _toPrimitive(t,
|
|
5
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
6
6
|
export var CONTENT_OPERATIONS = ['newsroom', 'theme', 'languages', 'categories', 'featuredContacts', 'galleries', 'gallery', 'stories', 'allStories', 'story', 'other'];
|
|
7
7
|
export var UPSTREAM_ROUTES = ['newsroom', 'theme', 'languages', 'categories', 'contacts', 'galleries', 'gallery', 'stories', 'story', 'story_by_slug', 'other'];
|
|
8
8
|
|
package/build/environment.cjs
CHANGED
|
@@ -10,7 +10,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
10
10
|
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; }
|
|
11
11
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
12
12
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
13
|
-
function _toPrimitive(t,
|
|
13
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
14
14
|
function combine(vars, httpEnvHeader) {
|
|
15
15
|
if (httpEnvHeader) {
|
|
16
16
|
var httpEnv = decodeHttpEnvHeader(httpEnvHeader);
|
package/build/environment.mjs
CHANGED
|
@@ -2,7 +2,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
2
2
|
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; }
|
|
3
3
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
|
-
function _toPrimitive(t,
|
|
5
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
6
6
|
import parseDataUrl from 'parse-data-url';
|
|
7
7
|
export function combine(vars, httpEnvHeader) {
|
|
8
8
|
if (httpEnvHeader) {
|
|
@@ -10,7 +10,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
10
10
|
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; }
|
|
11
11
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
12
12
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
13
|
-
function _toPrimitive(t,
|
|
13
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
14
14
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
15
15
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
16
16
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
@@ -4,7 +4,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
4
4
|
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; }
|
|
5
5
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
6
6
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
7
|
-
function _toPrimitive(t,
|
|
7
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
8
8
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
9
9
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
10
10
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
package/build/http/index.cjs
CHANGED
|
@@ -6,4 +6,5 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.HttpClient = void 0;
|
|
7
7
|
var _HttpClient = _interopRequireWildcard(require("./HttpClient.cjs"));
|
|
8
8
|
exports.HttpClient = _HttpClient;
|
|
9
|
-
|
|
9
|
+
var cache;
|
|
10
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
package/build/index.cjs
CHANGED
|
@@ -84,4 +84,5 @@ var _Sitemap = _interopRequireWildcard(require("./sitemap/index.cjs"));
|
|
|
84
84
|
exports.Sitemap = _Sitemap;
|
|
85
85
|
var _Uploads = _interopRequireWildcard(require("./uploads.cjs"));
|
|
86
86
|
exports.Uploads = _Uploads;
|
|
87
|
-
|
|
87
|
+
var cache;
|
|
88
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
|
@@ -16,7 +16,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
16
16
|
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; }
|
|
17
17
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
18
18
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
19
|
-
function _toPrimitive(t,
|
|
19
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
20
20
|
// We use english locale as fallback since English is the most common language
|
|
21
21
|
var EN = 'en';
|
|
22
22
|
var X_DEFAULT = 'x-default';
|
|
@@ -8,7 +8,7 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
8
8
|
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; }
|
|
9
9
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
10
10
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
11
|
-
function _toPrimitive(t,
|
|
11
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
12
12
|
import { Locale } from '@prezly/theme-kit-intl';
|
|
13
13
|
import { isNotUndefined } from '@technically/is-not-undefined';
|
|
14
14
|
// We use english locale as fallback since English is the most common language
|
package/build/routing/Route.cjs
CHANGED
|
@@ -7,6 +7,7 @@ exports.Route = void 0;
|
|
|
7
7
|
var _urlPattern = _interopRequireDefault(require("url-pattern"));
|
|
8
8
|
var _constants = require("./constants.cjs");
|
|
9
9
|
var _index = require("./utils/index.cjs");
|
|
10
|
+
var _wildcard = require("./utils/wildcard.cjs");
|
|
10
11
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
12
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
12
13
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
@@ -21,17 +22,35 @@ var Route;
|
|
|
21
22
|
check = _ref.check,
|
|
22
23
|
generate = _ref.generate,
|
|
23
24
|
resolveLocale = _ref.resolveLocale;
|
|
24
|
-
|
|
25
|
+
// A pattern can end in a named wildcard (`/category/*path`), which takes several segments.
|
|
26
|
+
var wildcard = (0, _wildcard.parseWildcard)(pattern);
|
|
27
|
+
var rewriteWildcard = (0, _wildcard.parseWildcard)(rewrite);
|
|
28
|
+
var urlPattern = new _urlPattern.default(wildcard.pattern, {
|
|
25
29
|
segmentValueCharset: _constants.URL_PATTERN_SEGMENT_CHARSET
|
|
26
30
|
});
|
|
27
|
-
var rewritePattern = new _urlPattern.default(
|
|
31
|
+
var rewritePattern = new _urlPattern.default(rewriteWildcard.pattern, {
|
|
28
32
|
segmentValueCharset: _constants.URL_PATTERN_SEGMENT_CHARSET
|
|
29
33
|
});
|
|
34
|
+
|
|
35
|
+
// A custom `generate` gets the pattern to stringify its params with. On a wildcard route
|
|
36
|
+
// it gets one that takes the wildcard by its name, like the params it is given.
|
|
37
|
+
var generatePattern = wildcard.name ? Object.assign(Object.create(urlPattern), {
|
|
38
|
+
stringify: params => (0, _wildcard.stringify)(urlPattern, params !== null && params !== void 0 ? params : {}, wildcard.name)
|
|
39
|
+
}) : urlPattern;
|
|
40
|
+
function encode(key, value) {
|
|
41
|
+
return key === wildcard.name ? (0, _wildcard.encodeWildcard)(value) : encodeURIComponent(value);
|
|
42
|
+
}
|
|
30
43
|
return {
|
|
31
44
|
pattern,
|
|
32
45
|
match(path, searchParams) {
|
|
33
|
-
var
|
|
34
|
-
if (!
|
|
46
|
+
var match = urlPattern.match(path);
|
|
47
|
+
if (!match) {
|
|
48
|
+
return undefined;
|
|
49
|
+
}
|
|
50
|
+
var matched = (0, _wildcard.fromMatch)(match, wildcard.name);
|
|
51
|
+
|
|
52
|
+
// `/category/` is not a category: a wildcard has to have something in it.
|
|
53
|
+
if (wildcard.name && !matched[wildcard.name]) {
|
|
35
54
|
return undefined;
|
|
36
55
|
}
|
|
37
56
|
if ((check === null || check === void 0 ? void 0 : check(matched, searchParams)) === false) {
|
|
@@ -44,15 +63,15 @@ var Route;
|
|
|
44
63
|
var _ref3 = _slicedToArray(_ref2, 2),
|
|
45
64
|
key = _ref3[0],
|
|
46
65
|
value = _ref3[1];
|
|
47
|
-
return [key, typeof value === 'string' ?
|
|
66
|
+
return [key, typeof value === 'string' ? encode(key, value) : value];
|
|
48
67
|
}));
|
|
49
68
|
if (generate) {
|
|
50
|
-
return (0, _index.normalizeUrl)(generate(
|
|
69
|
+
return (0, _index.normalizeUrl)(generate(generatePattern, encoded));
|
|
51
70
|
}
|
|
52
|
-
return (0, _index.normalizeUrl)(
|
|
71
|
+
return (0, _index.normalizeUrl)((0, _wildcard.stringify)(urlPattern, encoded, wildcard.name));
|
|
53
72
|
},
|
|
54
73
|
rewrite(params) {
|
|
55
|
-
return
|
|
74
|
+
return (0, _wildcard.stringify)(rewritePattern, params !== null && params !== void 0 ? params : {}, rewriteWildcard.name);
|
|
56
75
|
},
|
|
57
76
|
resolveLocale
|
|
58
77
|
};
|
package/build/routing/Route.mjs
CHANGED
|
@@ -7,6 +7,7 @@ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
|
7
7
|
import UrlPattern from 'url-pattern';
|
|
8
8
|
import { URL_PATTERN_SEGMENT_CHARSET } from "./constants.mjs";
|
|
9
9
|
import { normalizeUrl } from "./utils/index.mjs";
|
|
10
|
+
import { encodeWildcard, fromMatch, parseWildcard, stringify as _stringify } from "./utils/wildcard.mjs";
|
|
10
11
|
export var Route;
|
|
11
12
|
(function (_Route) {
|
|
12
13
|
function create(pattern, rewrite) {
|
|
@@ -14,17 +15,35 @@ export var Route;
|
|
|
14
15
|
check = _ref.check,
|
|
15
16
|
generate = _ref.generate,
|
|
16
17
|
resolveLocale = _ref.resolveLocale;
|
|
17
|
-
|
|
18
|
+
// A pattern can end in a named wildcard (`/category/*path`), which takes several segments.
|
|
19
|
+
var wildcard = parseWildcard(pattern);
|
|
20
|
+
var rewriteWildcard = parseWildcard(rewrite);
|
|
21
|
+
var urlPattern = new UrlPattern(wildcard.pattern, {
|
|
18
22
|
segmentValueCharset: URL_PATTERN_SEGMENT_CHARSET
|
|
19
23
|
});
|
|
20
|
-
var rewritePattern = new UrlPattern(
|
|
24
|
+
var rewritePattern = new UrlPattern(rewriteWildcard.pattern, {
|
|
21
25
|
segmentValueCharset: URL_PATTERN_SEGMENT_CHARSET
|
|
22
26
|
});
|
|
27
|
+
|
|
28
|
+
// A custom `generate` gets the pattern to stringify its params with. On a wildcard route
|
|
29
|
+
// it gets one that takes the wildcard by its name, like the params it is given.
|
|
30
|
+
var generatePattern = wildcard.name ? Object.assign(Object.create(urlPattern), {
|
|
31
|
+
stringify: params => _stringify(urlPattern, params !== null && params !== void 0 ? params : {}, wildcard.name)
|
|
32
|
+
}) : urlPattern;
|
|
33
|
+
function encode(key, value) {
|
|
34
|
+
return key === wildcard.name ? encodeWildcard(value) : encodeURIComponent(value);
|
|
35
|
+
}
|
|
23
36
|
return {
|
|
24
37
|
pattern,
|
|
25
38
|
match(path, searchParams) {
|
|
26
|
-
var
|
|
27
|
-
if (!
|
|
39
|
+
var match = urlPattern.match(path);
|
|
40
|
+
if (!match) {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
var matched = fromMatch(match, wildcard.name);
|
|
44
|
+
|
|
45
|
+
// `/category/` is not a category: a wildcard has to have something in it.
|
|
46
|
+
if (wildcard.name && !matched[wildcard.name]) {
|
|
28
47
|
return undefined;
|
|
29
48
|
}
|
|
30
49
|
if ((check === null || check === void 0 ? void 0 : check(matched, searchParams)) === false) {
|
|
@@ -37,15 +56,15 @@ export var Route;
|
|
|
37
56
|
var _ref3 = _slicedToArray(_ref2, 2),
|
|
38
57
|
key = _ref3[0],
|
|
39
58
|
value = _ref3[1];
|
|
40
|
-
return [key, typeof value === 'string' ?
|
|
59
|
+
return [key, typeof value === 'string' ? encode(key, value) : value];
|
|
41
60
|
}));
|
|
42
61
|
if (generate) {
|
|
43
|
-
return normalizeUrl(generate(
|
|
62
|
+
return normalizeUrl(generate(generatePattern, encoded));
|
|
44
63
|
}
|
|
45
|
-
return normalizeUrl(urlPattern.
|
|
64
|
+
return normalizeUrl(_stringify(urlPattern, encoded, wildcard.name));
|
|
46
65
|
},
|
|
47
66
|
rewrite(params) {
|
|
48
|
-
return rewritePattern.
|
|
67
|
+
return _stringify(rewritePattern, params !== null && params !== void 0 ? params : {}, rewriteWildcard.name);
|
|
49
68
|
},
|
|
50
69
|
resolveLocale
|
|
51
70
|
};
|
|
@@ -8,4 +8,50 @@ describe('generate()', () => {
|
|
|
8
8
|
slug: '年春夏コレクション'
|
|
9
9
|
})).toBe('/%E5%B9%B4%E6%98%A5%E5%A4%8F%E3%82%B3%E3%83%AC%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3');
|
|
10
10
|
});
|
|
11
|
+
});
|
|
12
|
+
describe('a named wildcard', () => {
|
|
13
|
+
var route = _Route.Route.create('(/:localeSlug)/category/*path', '/:localeCode/category/*path');
|
|
14
|
+
it('should match every segment that is left', () => {
|
|
15
|
+
var search = new URLSearchParams();
|
|
16
|
+
expect(route.match('/category/cars', search)).toEqual({
|
|
17
|
+
path: 'cars'
|
|
18
|
+
});
|
|
19
|
+
expect(route.match('/category/cars/models/eqs', search)).toEqual({
|
|
20
|
+
path: 'cars/models/eqs'
|
|
21
|
+
});
|
|
22
|
+
expect(route.match('/fr/category/cars/models', search)).toEqual({
|
|
23
|
+
localeSlug: 'fr',
|
|
24
|
+
path: 'cars/models'
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
it('should not match without anything in the wildcard', () => {
|
|
28
|
+
var search = new URLSearchParams();
|
|
29
|
+
expect(route.match('/category', search)).toBeUndefined();
|
|
30
|
+
expect(route.match('/category/', search)).toBeUndefined();
|
|
31
|
+
});
|
|
32
|
+
it('should generate URLs keeping the slashes between segments', () => {
|
|
33
|
+
expect(route.generate({
|
|
34
|
+
path: 'cars/models/eqs'
|
|
35
|
+
})).toBe('/category/cars/models/eqs');
|
|
36
|
+
expect(route.generate({
|
|
37
|
+
localeSlug: 'fr',
|
|
38
|
+
path: 'voitures/événements'
|
|
39
|
+
})).toBe('/fr/category/voitures/%C3%A9v%C3%A9nements');
|
|
40
|
+
});
|
|
41
|
+
it('should let a custom generate() stringify the wildcard by its name', () => {
|
|
42
|
+
var custom = _Route.Route.create('/category/*path', '/:localeCode/category/*path', {
|
|
43
|
+
generate(pattern, params) {
|
|
44
|
+
return "".concat(pattern.stringify(params), "?preview");
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
expect(custom.generate({
|
|
48
|
+
path: 'cars/models/eqs'
|
|
49
|
+
})).toBe('/category/cars/models/eqs?preview');
|
|
50
|
+
});
|
|
51
|
+
it('should rewrite to the internal URL', () => {
|
|
52
|
+
expect(route.rewrite({
|
|
53
|
+
localeCode: 'en',
|
|
54
|
+
path: 'cars/models/eqs'
|
|
55
|
+
})).toBe('/en/category/cars/models/eqs');
|
|
56
|
+
});
|
|
11
57
|
});
|
|
@@ -6,4 +6,50 @@ describe('generate()', () => {
|
|
|
6
6
|
slug: '年春夏コレクション'
|
|
7
7
|
})).toBe('/%E5%B9%B4%E6%98%A5%E5%A4%8F%E3%82%B3%E3%83%AC%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3');
|
|
8
8
|
});
|
|
9
|
+
});
|
|
10
|
+
describe('a named wildcard', () => {
|
|
11
|
+
var route = Route.create('(/:localeSlug)/category/*path', '/:localeCode/category/*path');
|
|
12
|
+
it('should match every segment that is left', () => {
|
|
13
|
+
var search = new URLSearchParams();
|
|
14
|
+
expect(route.match('/category/cars', search)).toEqual({
|
|
15
|
+
path: 'cars'
|
|
16
|
+
});
|
|
17
|
+
expect(route.match('/category/cars/models/eqs', search)).toEqual({
|
|
18
|
+
path: 'cars/models/eqs'
|
|
19
|
+
});
|
|
20
|
+
expect(route.match('/fr/category/cars/models', search)).toEqual({
|
|
21
|
+
localeSlug: 'fr',
|
|
22
|
+
path: 'cars/models'
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
it('should not match without anything in the wildcard', () => {
|
|
26
|
+
var search = new URLSearchParams();
|
|
27
|
+
expect(route.match('/category', search)).toBeUndefined();
|
|
28
|
+
expect(route.match('/category/', search)).toBeUndefined();
|
|
29
|
+
});
|
|
30
|
+
it('should generate URLs keeping the slashes between segments', () => {
|
|
31
|
+
expect(route.generate({
|
|
32
|
+
path: 'cars/models/eqs'
|
|
33
|
+
})).toBe('/category/cars/models/eqs');
|
|
34
|
+
expect(route.generate({
|
|
35
|
+
localeSlug: 'fr',
|
|
36
|
+
path: 'voitures/événements'
|
|
37
|
+
})).toBe('/fr/category/voitures/%C3%A9v%C3%A9nements');
|
|
38
|
+
});
|
|
39
|
+
it('should let a custom generate() stringify the wildcard by its name', () => {
|
|
40
|
+
var custom = Route.create('/category/*path', '/:localeCode/category/*path', {
|
|
41
|
+
generate(pattern, params) {
|
|
42
|
+
return "".concat(pattern.stringify(params), "?preview");
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
expect(custom.generate({
|
|
46
|
+
path: 'cars/models/eqs'
|
|
47
|
+
})).toBe('/category/cars/models/eqs?preview');
|
|
48
|
+
});
|
|
49
|
+
it('should rewrite to the internal URL', () => {
|
|
50
|
+
expect(route.rewrite({
|
|
51
|
+
localeCode: 'en',
|
|
52
|
+
path: 'cars/models/eqs'
|
|
53
|
+
})).toBe('/en/category/cars/models/eqs');
|
|
54
|
+
});
|
|
9
55
|
});
|
package/build/routing/index.cjs
CHANGED
|
@@ -20,4 +20,5 @@ var _Route = require("./Route.cjs");
|
|
|
20
20
|
var _Router = require("./Router.cjs");
|
|
21
21
|
var _Routing = _interopRequireWildcard(require("./Routing.cjs"));
|
|
22
22
|
exports.Routing = _Routing;
|
|
23
|
-
|
|
23
|
+
var cache;
|
|
24
|
+
function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var r, c, a = Object.defineProperty, n = { __proto__: null, default: e }; if (Object(e) !== e) return n; if (cache || "function" != typeof WeakMap || (cache = new WeakMap()), cache) { if (cache.has(e)) return cache.get(e); cache.set(e, n); } for (c in e) "default" !== c && {}.hasOwnProperty.call(e, c) && ((r = a && Object.getOwnPropertyDescriptor(e, c)) && (r.get || r.set) ? a(n, c, r) : n[c] = e[c]); return n; }
|
package/build/routing/types.d.ts
CHANGED
|
@@ -11,4 +11,6 @@ export type ExtractPathParams<T extends string> = T extends `${infer _Start}(/:$
|
|
|
11
11
|
[k in Param]?: string;
|
|
12
12
|
} : T extends `${infer _Start}:${infer Param}` ? {
|
|
13
13
|
[k in Param]: string;
|
|
14
|
+
} : T extends `${infer _Start}*${infer Param}` ? {
|
|
15
|
+
[k in Param]: string;
|
|
14
16
|
} : {};
|
|
@@ -9,35 +9,44 @@ var _urlPattern = _interopRequireDefault(require("url-pattern"));
|
|
|
9
9
|
var _constants = require("../constants.cjs");
|
|
10
10
|
var _getShortestLocaleSlug = require("./getShortestLocaleSlug.cjs");
|
|
11
11
|
var _normalizeUrl = require("./normalizeUrl.cjs");
|
|
12
|
+
var _wildcard = require("./wildcard.cjs");
|
|
12
13
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
14
|
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; }
|
|
14
15
|
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; }
|
|
15
16
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
16
17
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
17
|
-
function _toPrimitive(t,
|
|
18
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
18
19
|
var CACHE = new Map();
|
|
19
20
|
function toUrlPattern(pattern) {
|
|
20
21
|
var cached = CACHE.get(pattern);
|
|
21
22
|
if (cached) return cached;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
|
|
24
|
+
// A pattern can end in a named wildcard (`/category/*path`), which takes several segments.
|
|
25
|
+
var wildcard = (0, _wildcard.parseWildcard)(pattern);
|
|
26
|
+
var parsed = {
|
|
27
|
+
urlPattern: new _urlPattern.default(wildcard.pattern, {
|
|
28
|
+
segmentValueCharset: _constants.URL_PATTERN_SEGMENT_CHARSET
|
|
29
|
+
}),
|
|
30
|
+
wildcard: wildcard.name
|
|
31
|
+
};
|
|
32
|
+
CACHE.set(pattern, parsed);
|
|
33
|
+
return parsed;
|
|
27
34
|
}
|
|
28
35
|
function generateUrlFromPattern(pattern) {
|
|
29
36
|
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
30
37
|
var context = arguments.length > 2 ? arguments[2] : undefined;
|
|
31
|
-
var
|
|
38
|
+
var _toUrlPattern = toUrlPattern(pattern),
|
|
39
|
+
urlPattern = _toUrlPattern.urlPattern,
|
|
40
|
+
wildcard = _toUrlPattern.wildcard;
|
|
32
41
|
if (context) {
|
|
33
42
|
var localeCode = params.localeCode;
|
|
34
43
|
var localeSlug = getLocaleSlug(params, context);
|
|
35
|
-
return (0, _normalizeUrl.normalizeUrl)(
|
|
44
|
+
return (0, _normalizeUrl.normalizeUrl)((0, _wildcard.stringify)(urlPattern, (0, _omitUndefined.omitUndefined)(_objectSpread(_objectSpread({}, params), {}, {
|
|
36
45
|
localeCode,
|
|
37
46
|
localeSlug
|
|
38
|
-
}))));
|
|
47
|
+
})), wildcard));
|
|
39
48
|
}
|
|
40
|
-
return (0, _normalizeUrl.normalizeUrl)(
|
|
49
|
+
return (0, _normalizeUrl.normalizeUrl)((0, _wildcard.stringify)(urlPattern, (0, _omitUndefined.omitUndefined)(params), wildcard));
|
|
41
50
|
}
|
|
42
51
|
function getLocaleSlug(params, context) {
|
|
43
52
|
if (params.localeSlug) {
|
|
@@ -2,35 +2,44 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
|
|
|
2
2
|
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; }
|
|
3
3
|
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
4
4
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
5
|
-
function _toPrimitive(t,
|
|
5
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
6
6
|
import { omitUndefined } from '@technically/omit-undefined';
|
|
7
7
|
import UrlPattern from 'url-pattern';
|
|
8
8
|
import { URL_PATTERN_SEGMENT_CHARSET } from "../constants.mjs";
|
|
9
9
|
import { getShortestLocaleSlug } from "./getShortestLocaleSlug.mjs";
|
|
10
10
|
import { normalizeUrl } from "./normalizeUrl.mjs";
|
|
11
|
+
import { parseWildcard, stringify } from "./wildcard.mjs";
|
|
11
12
|
var CACHE = new Map();
|
|
12
13
|
function toUrlPattern(pattern) {
|
|
13
14
|
var cached = CACHE.get(pattern);
|
|
14
15
|
if (cached) return cached;
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
|
|
17
|
+
// A pattern can end in a named wildcard (`/category/*path`), which takes several segments.
|
|
18
|
+
var wildcard = parseWildcard(pattern);
|
|
19
|
+
var parsed = {
|
|
20
|
+
urlPattern: new UrlPattern(wildcard.pattern, {
|
|
21
|
+
segmentValueCharset: URL_PATTERN_SEGMENT_CHARSET
|
|
22
|
+
}),
|
|
23
|
+
wildcard: wildcard.name
|
|
24
|
+
};
|
|
25
|
+
CACHE.set(pattern, parsed);
|
|
26
|
+
return parsed;
|
|
20
27
|
}
|
|
21
28
|
export function generateUrlFromPattern(pattern) {
|
|
22
29
|
var params = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
|
|
23
30
|
var context = arguments.length > 2 ? arguments[2] : undefined;
|
|
24
|
-
var
|
|
31
|
+
var _toUrlPattern = toUrlPattern(pattern),
|
|
32
|
+
urlPattern = _toUrlPattern.urlPattern,
|
|
33
|
+
wildcard = _toUrlPattern.wildcard;
|
|
25
34
|
if (context) {
|
|
26
35
|
var localeCode = params.localeCode;
|
|
27
36
|
var localeSlug = getLocaleSlug(params, context);
|
|
28
|
-
return normalizeUrl(
|
|
37
|
+
return normalizeUrl(stringify(urlPattern, omitUndefined(_objectSpread(_objectSpread({}, params), {}, {
|
|
29
38
|
localeCode,
|
|
30
39
|
localeSlug
|
|
31
|
-
}))));
|
|
40
|
+
})), wildcard));
|
|
32
41
|
}
|
|
33
|
-
return normalizeUrl(
|
|
42
|
+
return normalizeUrl(stringify(urlPattern, omitUndefined(params), wildcard));
|
|
34
43
|
}
|
|
35
44
|
function getLocaleSlug(params, context) {
|
|
36
45
|
if (params.localeSlug) {
|
|
@@ -41,4 +41,19 @@ describe('generateUrlFromPattern', () => {
|
|
|
41
41
|
});
|
|
42
42
|
expect(href).toBe('/nl/media');
|
|
43
43
|
});
|
|
44
|
+
it('should generate a URL with a named wildcard', () => {
|
|
45
|
+
var pattern = '/(:localeSlug/)category/*path';
|
|
46
|
+
var context = {
|
|
47
|
+
defaultLocale: 'en',
|
|
48
|
+
locales: ['en', 'fr']
|
|
49
|
+
};
|
|
50
|
+
expect((0, _generateUrlFromPattern.generateUrlFromPattern)(pattern, {
|
|
51
|
+
localeCode: 'en',
|
|
52
|
+
path: 'cars'
|
|
53
|
+
}, context)).toBe('/category/cars');
|
|
54
|
+
expect((0, _generateUrlFromPattern.generateUrlFromPattern)(pattern, {
|
|
55
|
+
localeCode: 'fr',
|
|
56
|
+
path: 'cars/models/eqs'
|
|
57
|
+
}, context)).toBe('/fr/category/cars/models/eqs');
|
|
58
|
+
});
|
|
44
59
|
});
|
|
@@ -39,4 +39,19 @@ describe('generateUrlFromPattern', () => {
|
|
|
39
39
|
});
|
|
40
40
|
expect(href).toBe('/nl/media');
|
|
41
41
|
});
|
|
42
|
+
it('should generate a URL with a named wildcard', () => {
|
|
43
|
+
var pattern = '/(:localeSlug/)category/*path';
|
|
44
|
+
var context = {
|
|
45
|
+
defaultLocale: 'en',
|
|
46
|
+
locales: ['en', 'fr']
|
|
47
|
+
};
|
|
48
|
+
expect(generateUrlFromPattern(pattern, {
|
|
49
|
+
localeCode: 'en',
|
|
50
|
+
path: 'cars'
|
|
51
|
+
}, context)).toBe('/category/cars');
|
|
52
|
+
expect(generateUrlFromPattern(pattern, {
|
|
53
|
+
localeCode: 'fr',
|
|
54
|
+
path: 'cars/models/eqs'
|
|
55
|
+
}, context)).toBe('/fr/category/cars/models/eqs');
|
|
56
|
+
});
|
|
42
57
|
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.encodeWildcard = encodeWildcard;
|
|
7
|
+
exports.fromMatch = fromMatch;
|
|
8
|
+
exports.parseWildcard = parseWildcard;
|
|
9
|
+
exports.stringify = stringify;
|
|
10
|
+
exports.toStringifyParams = toStringifyParams;
|
|
11
|
+
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; }
|
|
12
|
+
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; }
|
|
13
|
+
function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
|
|
14
|
+
function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var n = Object.getOwnPropertySymbols(e); for (r = 0; r < n.length; r++) o = n[r], -1 === t.indexOf(o) && {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
|
|
15
|
+
function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (-1 !== e.indexOf(n)) continue; t[n] = r[n]; } return t; }
|
|
16
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == typeof i ? i : i + ""; }
|
|
17
|
+
function _toPrimitive(t, e) { if ("object" != typeof t || !t) return t; var r; if ("undefined" != typeof Symbol && void 0 !== (r = t[Symbol.toPrimitive])) { var i = r.call(t, e || "default"); if ("object" != typeof i) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === e ? String : Number)(t); }
|
|
18
|
+
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
19
|
+
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
20
|
+
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
21
|
+
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
22
|
+
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
23
|
+
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
24
|
+
/**
|
|
25
|
+
* A route pattern can end in one named wildcard: `/category/*path`. Unlike a `:param`, which is
|
|
26
|
+
* one segment of the URL, a wildcard takes every segment that is left: `cars/models/eqs`.
|
|
27
|
+
*
|
|
28
|
+
* `url-pattern` only knows unnamed wildcards (`*`), which it reports as `_`. These helpers
|
|
29
|
+
* translate between the two, so routes and their params only ever see the name.
|
|
30
|
+
*/
|
|
31
|
+
var NAMED_WILDCARD = /\*([A-Za-z][A-Za-z0-9]*)/;
|
|
32
|
+
var UNNAMED = '_';
|
|
33
|
+
function parseWildcard(pattern) {
|
|
34
|
+
var _pattern$match;
|
|
35
|
+
var _ref = (_pattern$match = pattern.match(NAMED_WILDCARD)) !== null && _pattern$match !== void 0 ? _pattern$match : [],
|
|
36
|
+
_ref2 = _slicedToArray(_ref, 2),
|
|
37
|
+
name = _ref2[1];
|
|
38
|
+
return {
|
|
39
|
+
pattern: name ? pattern.replace(NAMED_WILDCARD, '*') : pattern,
|
|
40
|
+
name
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Params as a route sees them, from what `url-pattern` matched.
|
|
46
|
+
*/
|
|
47
|
+
function fromMatch(matched, name) {
|
|
48
|
+
if (!name || !(UNNAMED in matched)) return matched;
|
|
49
|
+
var value = matched[UNNAMED],
|
|
50
|
+
params = _objectWithoutProperties(matched, [UNNAMED].map(_toPropertyKey));
|
|
51
|
+
return _objectSpread(_objectSpread({}, params), {}, {
|
|
52
|
+
[name]: value
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Params as `url-pattern` wants them to build a URL.
|
|
58
|
+
*/
|
|
59
|
+
function toStringifyParams(params, name) {
|
|
60
|
+
if (!name || !(name in params)) return params;
|
|
61
|
+
var value = params[name],
|
|
62
|
+
rest = _objectWithoutProperties(params, [name].map(_toPropertyKey));
|
|
63
|
+
return _objectSpread(_objectSpread({}, rest), {}, {
|
|
64
|
+
[UNNAMED]: value
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Encodes a wildcard value for a URL, keeping the slashes between its segments.
|
|
70
|
+
*/
|
|
71
|
+
function encodeWildcard(value) {
|
|
72
|
+
return value.split('/').map(encodeURIComponent).join('/');
|
|
73
|
+
}
|
|
74
|
+
function stringify(urlPattern, params, name) {
|
|
75
|
+
return urlPattern.stringify(toStringifyParams(params, name));
|
|
76
|
+
}
|