@depup/sanity 5.17.1-depup.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/LICENSE +21 -0
- package/README.md +57 -0
- package/bin/sanity +209 -0
- package/changes.json +114 -0
- package/lib/_chunks-dts/ActiveWorkspaceMatcherContext.d.ts +16164 -0
- package/lib/_chunks-dts/index.d.ts +780 -0
- package/lib/_chunks-dts/types.d.ts +2765 -0
- package/lib/_chunks-dts/types2.d.ts +656 -0
- package/lib/_chunks-dts/types3.d.ts +303 -0
- package/lib/_chunks-es/BroadcastDisplayedDocument.js +20 -0
- package/lib/_chunks-es/BroadcastDisplayedDocument.js.map +1 -0
- package/lib/_chunks-es/DisplayedDocumentBroadcaster.js +32 -0
- package/lib/_chunks-es/DisplayedDocumentBroadcaster.js.map +1 -0
- package/lib/_chunks-es/LiveQueries.js +339 -0
- package/lib/_chunks-es/LiveQueries.js.map +1 -0
- package/lib/_chunks-es/MenuGroup.js +106 -0
- package/lib/_chunks-es/MenuGroup.js.map +1 -0
- package/lib/_chunks-es/PostMessageDocuments.js +72 -0
- package/lib/_chunks-es/PostMessageDocuments.js.map +1 -0
- package/lib/_chunks-es/PostMessagePerspective.js +23 -0
- package/lib/_chunks-es/PostMessagePerspective.js.map +1 -0
- package/lib/_chunks-es/PostMessagePreviewSnapshots.js +69 -0
- package/lib/_chunks-es/PostMessagePreviewSnapshots.js.map +1 -0
- package/lib/_chunks-es/PostMessageRefreshMutations.js +74 -0
- package/lib/_chunks-es/PostMessageRefreshMutations.js.map +1 -0
- package/lib/_chunks-es/PostMessageSchema.js +502 -0
- package/lib/_chunks-es/PostMessageSchema.js.map +1 -0
- package/lib/_chunks-es/PostMessageTelemetry.js +21 -0
- package/lib/_chunks-es/PostMessageTelemetry.js.map +1 -0
- package/lib/_chunks-es/PresentationToolGrantsCheck.js +3848 -0
- package/lib/_chunks-es/PresentationToolGrantsCheck.js.map +1 -0
- package/lib/_chunks-es/QRCodeSVG.js +692 -0
- package/lib/_chunks-es/QRCodeSVG.js.map +1 -0
- package/lib/_chunks-es/StructureToolProvider.js +2360 -0
- package/lib/_chunks-es/StructureToolProvider.js.map +1 -0
- package/lib/_chunks-es/VideoPlayer.js +22 -0
- package/lib/_chunks-es/VideoPlayer.js.map +1 -0
- package/lib/_chunks-es/ViteDevServerStopped.js +52 -0
- package/lib/_chunks-es/ViteDevServerStopped.js.map +1 -0
- package/lib/_chunks-es/index.js +285 -0
- package/lib/_chunks-es/index.js.map +1 -0
- package/lib/_chunks-es/index2.js +105 -0
- package/lib/_chunks-es/index2.js.map +1 -0
- package/lib/_chunks-es/index3.js +139 -0
- package/lib/_chunks-es/index3.js.map +1 -0
- package/lib/_chunks-es/index4.js +1020 -0
- package/lib/_chunks-es/index4.js.map +1 -0
- package/lib/_chunks-es/pane.js +5 -0
- package/lib/_chunks-es/pane.js.map +1 -0
- package/lib/_chunks-es/pane2.js +5 -0
- package/lib/_chunks-es/pane2.js.map +1 -0
- package/lib/_chunks-es/presentation.js +549 -0
- package/lib/_chunks-es/presentation.js.map +1 -0
- package/lib/_chunks-es/resources.js +303 -0
- package/lib/_chunks-es/resources.js.map +1 -0
- package/lib/_chunks-es/resources2.js +459 -0
- package/lib/_chunks-es/resources2.js.map +1 -0
- package/lib/_chunks-es/resources3.js +281 -0
- package/lib/_chunks-es/resources3.js.map +1 -0
- package/lib/_chunks-es/resources4.js +184 -0
- package/lib/_chunks-es/resources4.js.map +1 -0
- package/lib/_chunks-es/resources5.js +161 -0
- package/lib/_chunks-es/resources5.js.map +1 -0
- package/lib/_chunks-es/resources6.js +141 -0
- package/lib/_chunks-es/resources6.js.map +1 -0
- package/lib/_chunks-es/resources7.js +24 -0
- package/lib/_chunks-es/resources7.js.map +1 -0
- package/lib/_chunks-es/resources8.js +603 -0
- package/lib/_chunks-es/resources8.js.map +1 -0
- package/lib/_chunks-es/resources9.js +126 -0
- package/lib/_chunks-es/resources9.js.map +1 -0
- package/lib/_chunks-es/structureTool.js +13673 -0
- package/lib/_chunks-es/structureTool.js.map +1 -0
- package/lib/_chunks-es/version.js +17 -0
- package/lib/_chunks-es/version.js.map +1 -0
- package/lib/_createContext.d.ts +12 -0
- package/lib/_createContext.js +38 -0
- package/lib/_createContext.js.map +1 -0
- package/lib/_internal.d.ts +9 -0
- package/lib/_internal.js +12 -0
- package/lib/_internal.js.map +1 -0
- package/lib/_singletons.d.ts +951 -0
- package/lib/_singletons.js +284 -0
- package/lib/_singletons.js.map +1 -0
- package/lib/cli.d.ts +3 -0
- package/lib/cli.js +9 -0
- package/lib/cli.js.map +1 -0
- package/lib/desk.d.ts +910 -0
- package/lib/desk.js +71 -0
- package/lib/desk.js.map +1 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +92934 -0
- package/lib/index.js.map +1 -0
- package/lib/media-library.d.ts +85 -0
- package/lib/media-library.js +11 -0
- package/lib/media-library.js.map +1 -0
- package/lib/migrate.d.ts +1 -0
- package/lib/migrate.js +2 -0
- package/lib/migrate.js.map +1 -0
- package/lib/presentation.d.ts +28 -0
- package/lib/presentation.js +10 -0
- package/lib/presentation.js.map +1 -0
- package/lib/router.d.ts +560 -0
- package/lib/router.js +777 -0
- package/lib/router.js.map +1 -0
- package/lib/structure.d.ts +3 -0
- package/lib/structure.js +639 -0
- package/lib/structure.js.map +1 -0
- package/mock-browser-env-stub-loader.mjs +27 -0
- package/package.json +383 -0
- package/static/favicons/apple-touch-icon.png +0 -0
- package/static/favicons/favicon-192.png +0 -0
- package/static/favicons/favicon-512.png +0 -0
- package/static/favicons/favicon-96.png +0 -0
- package/static/favicons/favicon.ico +0 -0
- package/static/favicons/favicon.svg +12 -0
package/lib/router.js
ADDED
|
@@ -0,0 +1,777 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { c } from "react/compiler-runtime";
|
|
3
|
+
import { useContext, forwardRef, useRef, useEffect } from "react";
|
|
4
|
+
import { RouterContext } from "sanity/_singletons";
|
|
5
|
+
import { RouterContext as RouterContext2 } from "sanity/_singletons";
|
|
6
|
+
import difference from "lodash-es/difference.js";
|
|
7
|
+
import intersection from "lodash-es/intersection.js";
|
|
8
|
+
import isPlainObject from "lodash-es/isPlainObject.js";
|
|
9
|
+
import pick from "lodash-es/pick.js";
|
|
10
|
+
import debug$1 from "debug";
|
|
11
|
+
import fromPairs from "lodash-es/fromPairs.js";
|
|
12
|
+
import partition from "lodash-es/partition.js";
|
|
13
|
+
import toPairs from "lodash-es/toPairs.js";
|
|
14
|
+
import identity from "lodash-es/identity.js";
|
|
15
|
+
function useRouter() {
|
|
16
|
+
const router = useContext(RouterContext);
|
|
17
|
+
if (!router)
|
|
18
|
+
throw new Error("Router: missing context value");
|
|
19
|
+
return router;
|
|
20
|
+
}
|
|
21
|
+
function isLeftClickEvent(event) {
|
|
22
|
+
return event.button === 0;
|
|
23
|
+
}
|
|
24
|
+
function isModifiedEvent(event) {
|
|
25
|
+
return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
|
|
26
|
+
}
|
|
27
|
+
function useLink(options) {
|
|
28
|
+
const $ = c(8), {
|
|
29
|
+
onClick: onClickProp,
|
|
30
|
+
href,
|
|
31
|
+
target,
|
|
32
|
+
replace: t0
|
|
33
|
+
} = options, replace = t0 === void 0 ? !1 : t0, {
|
|
34
|
+
navigateUrl
|
|
35
|
+
} = useRouter();
|
|
36
|
+
let t1;
|
|
37
|
+
$[0] !== href || $[1] !== navigateUrl || $[2] !== onClickProp || $[3] !== replace || $[4] !== target ? (t1 = (event) => {
|
|
38
|
+
event.isDefaultPrevented() || href && (onClickProp && onClickProp(event), !(isModifiedEvent(event) || !isLeftClickEvent(event)) && (target || (event.preventDefault(), navigateUrl({
|
|
39
|
+
path: href,
|
|
40
|
+
replace
|
|
41
|
+
}))));
|
|
42
|
+
}, $[0] = href, $[1] = navigateUrl, $[2] = onClickProp, $[3] = replace, $[4] = target, $[5] = t1) : t1 = $[5];
|
|
43
|
+
const onClick = t1;
|
|
44
|
+
let t2;
|
|
45
|
+
return $[6] !== onClick ? (t2 = {
|
|
46
|
+
onClick
|
|
47
|
+
}, $[6] = onClick, $[7] = t2) : t2 = $[7], t2;
|
|
48
|
+
}
|
|
49
|
+
function useIntentLink(options) {
|
|
50
|
+
const $ = c(13), {
|
|
51
|
+
intent,
|
|
52
|
+
onClick: onClickProp,
|
|
53
|
+
params,
|
|
54
|
+
replace,
|
|
55
|
+
target,
|
|
56
|
+
searchParams
|
|
57
|
+
} = options, {
|
|
58
|
+
resolveIntentLink
|
|
59
|
+
} = useRouter();
|
|
60
|
+
let t0;
|
|
61
|
+
$[0] !== intent || $[1] !== params || $[2] !== resolveIntentLink || $[3] !== searchParams ? (t0 = resolveIntentLink(intent, params, searchParams), $[0] = intent, $[1] = params, $[2] = resolveIntentLink, $[3] = searchParams, $[4] = t0) : t0 = $[4];
|
|
62
|
+
const href = t0;
|
|
63
|
+
let t1;
|
|
64
|
+
$[5] !== href || $[6] !== onClickProp || $[7] !== replace || $[8] !== target ? (t1 = {
|
|
65
|
+
href,
|
|
66
|
+
onClick: onClickProp,
|
|
67
|
+
replace,
|
|
68
|
+
target
|
|
69
|
+
}, $[5] = href, $[6] = onClickProp, $[7] = replace, $[8] = target, $[9] = t1) : t1 = $[9];
|
|
70
|
+
const {
|
|
71
|
+
onClick
|
|
72
|
+
} = useLink(t1);
|
|
73
|
+
let t2;
|
|
74
|
+
return $[10] !== href || $[11] !== onClick ? (t2 = {
|
|
75
|
+
onClick,
|
|
76
|
+
href
|
|
77
|
+
}, $[10] = href, $[11] = onClick, $[12] = t2) : t2 = $[12], t2;
|
|
78
|
+
}
|
|
79
|
+
const IntentLink = forwardRef(function(props, ref) {
|
|
80
|
+
const $ = c(18);
|
|
81
|
+
let intent, params, restProps, searchParams, target;
|
|
82
|
+
$[0] !== props ? ({
|
|
83
|
+
intent,
|
|
84
|
+
params,
|
|
85
|
+
target,
|
|
86
|
+
searchParams,
|
|
87
|
+
...restProps
|
|
88
|
+
} = props, $[0] = props, $[1] = intent, $[2] = params, $[3] = restProps, $[4] = searchParams, $[5] = target) : (intent = $[1], params = $[2], restProps = $[3], searchParams = $[4], target = $[5]);
|
|
89
|
+
let t0;
|
|
90
|
+
$[6] !== intent || $[7] !== params || $[8] !== props.onClick || $[9] !== searchParams || $[10] !== target ? (t0 = {
|
|
91
|
+
intent,
|
|
92
|
+
params,
|
|
93
|
+
target,
|
|
94
|
+
onClick: props.onClick,
|
|
95
|
+
searchParams
|
|
96
|
+
}, $[6] = intent, $[7] = params, $[8] = props.onClick, $[9] = searchParams, $[10] = target, $[11] = t0) : t0 = $[11];
|
|
97
|
+
const {
|
|
98
|
+
onClick,
|
|
99
|
+
href
|
|
100
|
+
} = useIntentLink(t0);
|
|
101
|
+
let t1;
|
|
102
|
+
return $[12] !== href || $[13] !== onClick || $[14] !== ref || $[15] !== restProps || $[16] !== target ? (t1 = /* @__PURE__ */ jsx("a", { ...restProps, href, onClick, ref, target }), $[12] = href, $[13] = onClick, $[14] = ref, $[15] = restProps, $[16] = target, $[17] = t1) : t1 = $[17], t1;
|
|
103
|
+
}), Link = forwardRef(function(props, ref) {
|
|
104
|
+
const $ = c(17);
|
|
105
|
+
let href, onClickProp, replace, restProps, target;
|
|
106
|
+
$[0] !== props ? ({
|
|
107
|
+
onClick: onClickProp,
|
|
108
|
+
href,
|
|
109
|
+
target,
|
|
110
|
+
replace,
|
|
111
|
+
...restProps
|
|
112
|
+
} = props, $[0] = props, $[1] = href, $[2] = onClickProp, $[3] = replace, $[4] = restProps, $[5] = target) : (href = $[1], onClickProp = $[2], replace = $[3], restProps = $[4], target = $[5]);
|
|
113
|
+
let t0;
|
|
114
|
+
$[6] !== href || $[7] !== onClickProp || $[8] !== replace || $[9] !== target ? (t0 = {
|
|
115
|
+
onClick: onClickProp,
|
|
116
|
+
href,
|
|
117
|
+
target,
|
|
118
|
+
replace
|
|
119
|
+
}, $[6] = href, $[7] = onClickProp, $[8] = replace, $[9] = target, $[10] = t0) : t0 = $[10];
|
|
120
|
+
const {
|
|
121
|
+
onClick
|
|
122
|
+
} = useLink(t0);
|
|
123
|
+
let t1;
|
|
124
|
+
return $[11] !== href || $[12] !== onClick || $[13] !== ref || $[14] !== restProps || $[15] !== target ? (t1 = /* @__PURE__ */ jsx("a", { ...restProps, onClick, href, target, ref }), $[11] = href, $[12] = onClick, $[13] = ref, $[14] = restProps, $[15] = target, $[16] = t1) : t1 = $[16], t1;
|
|
125
|
+
}), VALID_PARAM_SEGMENT = /^[a-zA-Z0-9_-]+$/;
|
|
126
|
+
function createSegment(segment) {
|
|
127
|
+
if (!segment)
|
|
128
|
+
return null;
|
|
129
|
+
if (segment.startsWith(":")) {
|
|
130
|
+
const paramName = segment.slice(1);
|
|
131
|
+
if (!VALID_PARAM_SEGMENT.test(paramName)) {
|
|
132
|
+
const addendum = segment.includes("*") ? " Splats are not supported. Consider using child routes instead" : "";
|
|
133
|
+
console.error(new Error(`Warning: Param segments "${segment}" includes invalid characters.${addendum}`));
|
|
134
|
+
}
|
|
135
|
+
return {
|
|
136
|
+
type: "param",
|
|
137
|
+
name: paramName
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
return {
|
|
141
|
+
type: "dir",
|
|
142
|
+
name: segment
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
function _parseRoute(route2) {
|
|
146
|
+
const [pathname] = route2.split("?"), segments = pathname.split("/").map(createSegment).filter(Boolean);
|
|
147
|
+
return {
|
|
148
|
+
raw: route2,
|
|
149
|
+
segments
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function arrayify(val) {
|
|
153
|
+
return Array.isArray(val) ? val : val ? [val] : [];
|
|
154
|
+
}
|
|
155
|
+
function isRecord(value) {
|
|
156
|
+
return isPlainObject(value);
|
|
157
|
+
}
|
|
158
|
+
function createMatchError(node, missingKeys, unmappableStateKeys) {
|
|
159
|
+
return {
|
|
160
|
+
type: "error",
|
|
161
|
+
node,
|
|
162
|
+
missingKeys,
|
|
163
|
+
unmappableStateKeys
|
|
164
|
+
};
|
|
165
|
+
}
|
|
166
|
+
function createMatchOk(node, matchedState, searchParams, child) {
|
|
167
|
+
return {
|
|
168
|
+
type: "ok",
|
|
169
|
+
node,
|
|
170
|
+
matchedState,
|
|
171
|
+
searchParams,
|
|
172
|
+
child
|
|
173
|
+
};
|
|
174
|
+
}
|
|
175
|
+
function _findMatchingRoutes(node, _state) {
|
|
176
|
+
if (!_state)
|
|
177
|
+
return createMatchOk(node, {}, []);
|
|
178
|
+
const scopedState = node.scope ? _state[node.scope] : _state, {
|
|
179
|
+
_searchParams: searchParams = [],
|
|
180
|
+
...state
|
|
181
|
+
} = scopedState || {}, requiredParams = node.route.segments.filter((seg) => seg.type === "param").map((seg) => seg.name), stateKeys = isRecord(state) ? Object.keys(state) : [], consumedParams = intersection(stateKeys, requiredParams), missingParams = difference(requiredParams, consumedParams), remainingParams = difference(stateKeys, consumedParams);
|
|
182
|
+
if (missingParams.length > 0)
|
|
183
|
+
return createMatchError(node, missingParams, []);
|
|
184
|
+
const scopedParams = searchParams.map(([key, value]) => [[key], value]), consumedState = pick(state, consumedParams);
|
|
185
|
+
if (remainingParams.length === 0)
|
|
186
|
+
return createMatchOk(node, consumedState, scopedParams);
|
|
187
|
+
const children = arrayify((typeof node.children == "function" ? node.children(isRecord(state) ? state : {}) : node.children) || []);
|
|
188
|
+
if (remainingParams.length > 0 && children.length === 0)
|
|
189
|
+
return createMatchError(node, [], remainingParams);
|
|
190
|
+
const remainingState = pick(state, remainingParams), found = children.map((childNode) => _findMatchingRoutes(childNode, remainingState)).find((res) => res.type === "ok");
|
|
191
|
+
return found ? createMatchOk(node, consumedState, scopedParams, found) : createMatchError(node, [], remainingParams);
|
|
192
|
+
}
|
|
193
|
+
function encodeURIComponentExcept(uriComponent, unescaped) {
|
|
194
|
+
const chars = [...String(uriComponent)];
|
|
195
|
+
let res = "";
|
|
196
|
+
for (let i = 0; i < chars.length; i++) {
|
|
197
|
+
const char = chars[i];
|
|
198
|
+
unescaped.includes(char) ? res += char : res += encodeURIComponent(char);
|
|
199
|
+
}
|
|
200
|
+
return res;
|
|
201
|
+
}
|
|
202
|
+
const debug = debug$1("state-router");
|
|
203
|
+
function _resolvePathFromState(node, _state) {
|
|
204
|
+
debug("Resolving path from state %o", _state);
|
|
205
|
+
const match = _findMatchingRoutes(node, _state);
|
|
206
|
+
if (match.type === "error") {
|
|
207
|
+
const unmappable = match.unmappableStateKeys;
|
|
208
|
+
if (unmappable.length > 0)
|
|
209
|
+
throw new Error(`Unable to find matching route for state. Could not map the following state key${unmappable.length == 1 ? "" : "s"} to a valid url: ${unmappable.map(quote).join(", ")}`);
|
|
210
|
+
const missingKeys = match.missingKeys;
|
|
211
|
+
throw new Error(`Unable to find matching route for state. State object is missing the following key${missingKeys.length == 1 ? "" : "s"} defined in route: ${missingKeys.map(quote).join(", ")}`);
|
|
212
|
+
}
|
|
213
|
+
const {
|
|
214
|
+
path,
|
|
215
|
+
searchParams
|
|
216
|
+
} = pathFromMatchResult(match), search = searchParams.length > 0 ? encodeParams$1(searchParams) : "";
|
|
217
|
+
return `/${path.join("/")}${search ? `?${search}` : ""}`;
|
|
218
|
+
}
|
|
219
|
+
function bracketify(value) {
|
|
220
|
+
return `[${value}]`;
|
|
221
|
+
}
|
|
222
|
+
function encodeParams$1(params) {
|
|
223
|
+
return params.flatMap(([key, value]) => value === void 0 ? [] : [encodeSearchParamKey(serializeScopedPath(key)), encodeSearchParamValue(value)].join("=")).join("&");
|
|
224
|
+
}
|
|
225
|
+
function serializeScopedPath(scopedPath) {
|
|
226
|
+
const [head, ...tail] = scopedPath;
|
|
227
|
+
return tail.length > 0 ? [head, ...tail.map(bracketify)].join("") : head;
|
|
228
|
+
}
|
|
229
|
+
function encodeSearchParamValue(value) {
|
|
230
|
+
return encodeURIComponentExcept(value, "/");
|
|
231
|
+
}
|
|
232
|
+
function encodeSearchParamKey(value) {
|
|
233
|
+
return encodeURIComponentExcept(value, "[]");
|
|
234
|
+
}
|
|
235
|
+
function pathFromMatchResult(match) {
|
|
236
|
+
const matchedState = match.matchedState, base = match.node.route.segments.map((segment) => {
|
|
237
|
+
if (segment.type === "dir")
|
|
238
|
+
return segment.name;
|
|
239
|
+
const transform = match.node.transform && match.node.transform[segment.name];
|
|
240
|
+
return transform ? transform.toPath(matchedState[segment.name]) : matchedState[segment.name];
|
|
241
|
+
}), childMatch = match.child ? pathFromMatchResult(match.child) : void 0, searchParams = childMatch?.searchParams ? [...match.searchParams, ...childMatch.searchParams] : match.searchParams;
|
|
242
|
+
return {
|
|
243
|
+
searchParams: addNodeScope(match.node, searchParams),
|
|
244
|
+
path: [...base || [], ...childMatch?.path || []]
|
|
245
|
+
};
|
|
246
|
+
}
|
|
247
|
+
function addNodeScope(node, searchParams) {
|
|
248
|
+
const scope = node.scope;
|
|
249
|
+
return scope && !node.__unsafe_disableScopedSearchParams ? searchParams.map(([namespaces, value]) => [[scope, ...namespaces], value]) : searchParams;
|
|
250
|
+
}
|
|
251
|
+
function quote(value) {
|
|
252
|
+
return `"${value}"`;
|
|
253
|
+
}
|
|
254
|
+
function parseScopedParams(params) {
|
|
255
|
+
return params.map(([key, value]) => [parse(key), value]);
|
|
256
|
+
}
|
|
257
|
+
const OPEN = 1, CLOSED = 0;
|
|
258
|
+
function parse(str) {
|
|
259
|
+
const result = [];
|
|
260
|
+
let i = 0, state = CLOSED;
|
|
261
|
+
for (; i < str.length; ) {
|
|
262
|
+
const nextBracketIdx = str.indexOf("[", i);
|
|
263
|
+
if (nextBracketIdx === -1) {
|
|
264
|
+
result.push(str.slice(i, str.length));
|
|
265
|
+
break;
|
|
266
|
+
}
|
|
267
|
+
if (state === OPEN)
|
|
268
|
+
throw new Error("Nested brackets not supported");
|
|
269
|
+
state = OPEN, nextBracketIdx > i && (result.push(str.slice(i, nextBracketIdx)), i = nextBracketIdx);
|
|
270
|
+
const nextClosing = str.indexOf("]", nextBracketIdx);
|
|
271
|
+
if (nextClosing === -1) {
|
|
272
|
+
if (state === OPEN)
|
|
273
|
+
throw new Error("Unclosed bracket");
|
|
274
|
+
break;
|
|
275
|
+
}
|
|
276
|
+
state = CLOSED, result.push(str.slice(i + 1, nextClosing)), i = nextClosing + 1;
|
|
277
|
+
}
|
|
278
|
+
return result;
|
|
279
|
+
}
|
|
280
|
+
function matchPath(node, path, searchParams) {
|
|
281
|
+
const parts = path.split("/").filter(Boolean), segmentsLength = node.route.segments.length;
|
|
282
|
+
if (parts.length < segmentsLength)
|
|
283
|
+
return null;
|
|
284
|
+
const state = {};
|
|
285
|
+
if (!node.route.segments.every((segment, i) => {
|
|
286
|
+
if (segment.type === "dir")
|
|
287
|
+
return segment.name === parts[i];
|
|
288
|
+
const transform = node.transform && node.transform[segment.name];
|
|
289
|
+
return state[segment.name] = transform ? transform.toState(parts[i]) : parts[i], !0;
|
|
290
|
+
}))
|
|
291
|
+
return null;
|
|
292
|
+
const rest = parts.slice(segmentsLength);
|
|
293
|
+
let childState = null;
|
|
294
|
+
const children = typeof node.children == "function" ? arrayify(node.children(state)) : node.children, unscopedParams = removeScope(node.scope, searchParams);
|
|
295
|
+
if (children.some((childNode) => {
|
|
296
|
+
if (childNode) {
|
|
297
|
+
const childParams = childNode.scope ? unscopedParams.filter(([namespaces]) => childNode.scope === namespaces[0]) : unscopedParams;
|
|
298
|
+
return childState = matchPath(childNode, rest.join("/"), childParams), childState;
|
|
299
|
+
}
|
|
300
|
+
}), rest.length > 0 && !childState)
|
|
301
|
+
return null;
|
|
302
|
+
const selfParams = unscopedParams.flatMap(([namespace, value]) => namespace.length === 1 ? [[namespace[0], value]] : []), mergedState = {
|
|
303
|
+
...state,
|
|
304
|
+
...childState === null ? {} : childState,
|
|
305
|
+
...selfParams.length > 0 ? {
|
|
306
|
+
_searchParams: selfParams
|
|
307
|
+
} : {}
|
|
308
|
+
};
|
|
309
|
+
return node.scope ? {
|
|
310
|
+
[node.scope]: mergedState
|
|
311
|
+
} : mergedState;
|
|
312
|
+
}
|
|
313
|
+
function _resolveStateFromPath(node, path) {
|
|
314
|
+
debug("resolving state from path %s", path);
|
|
315
|
+
const [pathname, search] = path.split("?"), urlSearchParams = Array.from(new URLSearchParams(search).entries()), pathMatch = matchPath(node, pathname, parseScopedParams(urlSearchParams));
|
|
316
|
+
return debug("resolved: %o", pathMatch || null), pathMatch || null;
|
|
317
|
+
}
|
|
318
|
+
function removeScope(scope, searchParams) {
|
|
319
|
+
return scope ? searchParams.map(([namespaces, value]) => [namespaces[0] === scope ? namespaces.slice(1) : namespaces, value]) : searchParams;
|
|
320
|
+
}
|
|
321
|
+
function encodeBase64Url(str) {
|
|
322
|
+
return encodeBase64(str).replace(/\//g, "_").replace(/\+/g, "-").replace(/[=]+$/, "");
|
|
323
|
+
}
|
|
324
|
+
function decodeBase64Url(str) {
|
|
325
|
+
return decodeBase64(str.replace(/-/g, "+").replace(/_/g, "/"));
|
|
326
|
+
}
|
|
327
|
+
function percentToByte(p) {
|
|
328
|
+
return String.fromCharCode(parseInt(p.slice(1), 16));
|
|
329
|
+
}
|
|
330
|
+
function encodeBase64(str) {
|
|
331
|
+
return btoa(encodeURIComponent(str).replace(/%[0-9A-F]{2}/g, percentToByte));
|
|
332
|
+
}
|
|
333
|
+
function byteToPercent(b) {
|
|
334
|
+
return `%${`00${b.charCodeAt(0).toString(16)}`.slice(-2)}`;
|
|
335
|
+
}
|
|
336
|
+
function decodeBase64(str) {
|
|
337
|
+
return decodeURIComponent(Array.from(atob(str), byteToPercent).join(""));
|
|
338
|
+
}
|
|
339
|
+
function decodeJsonParams(pathSegment = "") {
|
|
340
|
+
const segment = decodeURIComponent(pathSegment);
|
|
341
|
+
if (!segment)
|
|
342
|
+
return {};
|
|
343
|
+
try {
|
|
344
|
+
return JSON.parse(decodeBase64Url(segment));
|
|
345
|
+
} catch {
|
|
346
|
+
}
|
|
347
|
+
try {
|
|
348
|
+
return JSON.parse(atob(segment));
|
|
349
|
+
} catch {
|
|
350
|
+
}
|
|
351
|
+
try {
|
|
352
|
+
return JSON.parse(segment);
|
|
353
|
+
} catch {
|
|
354
|
+
console.warn("Failed to parse JSON parameters");
|
|
355
|
+
}
|
|
356
|
+
return {};
|
|
357
|
+
}
|
|
358
|
+
function encodeJsonParams(params) {
|
|
359
|
+
return params ? encodeBase64Url(JSON.stringify(params)) : "";
|
|
360
|
+
}
|
|
361
|
+
function decodeParams(pathSegment) {
|
|
362
|
+
return pathSegment.split(";").reduce((params, pair) => {
|
|
363
|
+
const [key, value] = pair.split("=");
|
|
364
|
+
return params[decodeURIComponent(key)] = decodeURIComponent(value), params;
|
|
365
|
+
}, {});
|
|
366
|
+
}
|
|
367
|
+
function encodeParams(params) {
|
|
368
|
+
return Object.entries(params).filter(([, value]) => value != null).map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`).join(";");
|
|
369
|
+
}
|
|
370
|
+
const route = {
|
|
371
|
+
create: (routeOrOpts, childrenOrOpts, children) => _createNode(normalizeArgs(routeOrOpts, childrenOrOpts, children)),
|
|
372
|
+
intents: (base) => {
|
|
373
|
+
const basePath = normalize(base).join("/");
|
|
374
|
+
return route.create(`${basePath}/:intent`, [route.create(":params", {
|
|
375
|
+
transform: {
|
|
376
|
+
params: {
|
|
377
|
+
toState: decodeParams,
|
|
378
|
+
toPath: encodeParams
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}, [route.create(":payload", {
|
|
382
|
+
transform: {
|
|
383
|
+
payload: {
|
|
384
|
+
toState: decodeJsonParams,
|
|
385
|
+
toPath: encodeJsonParams
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
})])]);
|
|
389
|
+
},
|
|
390
|
+
scope(scopeName, routeOrOpts, childrenOrOpts, children) {
|
|
391
|
+
const options = normalizeArgs(routeOrOpts, childrenOrOpts, children);
|
|
392
|
+
return _createNode({
|
|
393
|
+
...options,
|
|
394
|
+
scope: scopeName
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
};
|
|
398
|
+
function normalizeChildren(children) {
|
|
399
|
+
return Array.isArray(children) || typeof children == "function" ? children : children ? [children] : [];
|
|
400
|
+
}
|
|
401
|
+
function isRoute(val) {
|
|
402
|
+
return val && "_isRoute" in val;
|
|
403
|
+
}
|
|
404
|
+
function normalizeArgs(path, childrenOrOpts, children) {
|
|
405
|
+
return typeof path == "object" ? path : Array.isArray(childrenOrOpts) || typeof childrenOrOpts == "function" || isRoute(childrenOrOpts) ? {
|
|
406
|
+
path,
|
|
407
|
+
children: normalizeChildren(childrenOrOpts)
|
|
408
|
+
} : children ? {
|
|
409
|
+
path,
|
|
410
|
+
...childrenOrOpts,
|
|
411
|
+
children: normalizeChildren(children)
|
|
412
|
+
} : {
|
|
413
|
+
path,
|
|
414
|
+
...childrenOrOpts
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
function normalize(...paths) {
|
|
418
|
+
return paths.reduce((acc, path) => acc.concat(path.split("/")), []).filter(Boolean);
|
|
419
|
+
}
|
|
420
|
+
const EMPTY_STATE$1 = {};
|
|
421
|
+
function isRoot(pathname) {
|
|
422
|
+
return pathname.split("/").every((segment) => !segment);
|
|
423
|
+
}
|
|
424
|
+
function _createNode(options) {
|
|
425
|
+
const {
|
|
426
|
+
path,
|
|
427
|
+
scope,
|
|
428
|
+
transform,
|
|
429
|
+
children,
|
|
430
|
+
__unsafe_disableScopedSearchParams
|
|
431
|
+
} = options;
|
|
432
|
+
if (!path)
|
|
433
|
+
throw new TypeError("Missing path");
|
|
434
|
+
const parsedRoute = _parseRoute(path);
|
|
435
|
+
return {
|
|
436
|
+
_isRoute: !0,
|
|
437
|
+
// todo: make a Router class instead
|
|
438
|
+
scope,
|
|
439
|
+
// eslint-disable-next-line camelcase
|
|
440
|
+
__unsafe_disableScopedSearchParams,
|
|
441
|
+
route: parsedRoute,
|
|
442
|
+
children: children || [],
|
|
443
|
+
transform,
|
|
444
|
+
encode(state) {
|
|
445
|
+
return _resolvePathFromState(this, state);
|
|
446
|
+
},
|
|
447
|
+
decode(_path) {
|
|
448
|
+
return _resolveStateFromPath(this, _path);
|
|
449
|
+
},
|
|
450
|
+
isRoot,
|
|
451
|
+
isNotFound(pathname) {
|
|
452
|
+
return this.decode(pathname) === null;
|
|
453
|
+
},
|
|
454
|
+
getBasePath() {
|
|
455
|
+
return this.encode(EMPTY_STATE$1);
|
|
456
|
+
},
|
|
457
|
+
getRedirectBase(pathname) {
|
|
458
|
+
if (isRoot(pathname)) {
|
|
459
|
+
const basePath = this.getBasePath();
|
|
460
|
+
if (pathname !== basePath)
|
|
461
|
+
return basePath;
|
|
462
|
+
}
|
|
463
|
+
return null;
|
|
464
|
+
}
|
|
465
|
+
};
|
|
466
|
+
}
|
|
467
|
+
const STICKY_PARAMS = ["perspective", "excludedPerspectives", "displayInlineChanges", "sidebar", "selectedTask", "viewMode"], isNavigateOptions = (maybeNavigateOptions) => {
|
|
468
|
+
if (typeof maybeNavigateOptions != "object" || maybeNavigateOptions === null || Array.isArray(maybeNavigateOptions) || !("replace" in maybeNavigateOptions || "stickyParams" in maybeNavigateOptions || "state" in maybeNavigateOptions))
|
|
469
|
+
return !1;
|
|
470
|
+
if ("state" in maybeNavigateOptions) {
|
|
471
|
+
const {
|
|
472
|
+
state
|
|
473
|
+
} = maybeNavigateOptions;
|
|
474
|
+
return state == null || typeof state == "object";
|
|
475
|
+
}
|
|
476
|
+
return !0;
|
|
477
|
+
};
|
|
478
|
+
function RouterProvider(props) {
|
|
479
|
+
const $ = c(44), {
|
|
480
|
+
onNavigate,
|
|
481
|
+
router: routerProp,
|
|
482
|
+
state
|
|
483
|
+
} = props;
|
|
484
|
+
let t0;
|
|
485
|
+
$[0] !== routerProp || $[1] !== state._searchParams ? (t0 = (intentName, parameters, _searchParams) => {
|
|
486
|
+
const [params, payload] = Array.isArray(parameters) ? parameters : [parameters];
|
|
487
|
+
return routerProp.encode({
|
|
488
|
+
intent: intentName,
|
|
489
|
+
params,
|
|
490
|
+
payload,
|
|
491
|
+
_searchParams: toPairs({
|
|
492
|
+
...fromPairs((state._searchParams ?? []).filter(_temp)),
|
|
493
|
+
...fromPairs(_searchParams ?? [])
|
|
494
|
+
})
|
|
495
|
+
});
|
|
496
|
+
}, $[0] = routerProp, $[1] = state._searchParams, $[2] = t0) : t0 = $[2];
|
|
497
|
+
const resolveIntentLink = t0;
|
|
498
|
+
let t1;
|
|
499
|
+
$[3] !== routerProp || $[4] !== state._searchParams ? (t1 = (nextState) => {
|
|
500
|
+
const currentStateParams = state._searchParams || [], nextStateParams = nextState?._searchParams || [], nextParams = STICKY_PARAMS.reduce((acc, param) => replaceStickyParam(acc, param, findParam(nextStateParams, param) ?? findParam(currentStateParams, param)), nextStateParams || []);
|
|
501
|
+
return routerProp.encode({
|
|
502
|
+
...nextState,
|
|
503
|
+
_searchParams: nextParams
|
|
504
|
+
});
|
|
505
|
+
}, $[3] = routerProp, $[4] = state._searchParams, $[5] = t1) : t1 = $[5];
|
|
506
|
+
const resolvePathFromState = t1;
|
|
507
|
+
let t2;
|
|
508
|
+
$[6] !== onNavigate || $[7] !== resolvePathFromState || $[8] !== state ? (t2 = (nextStateOrOptions, maybeOptions) => {
|
|
509
|
+
const options = isNavigateOptions(nextStateOrOptions) && !maybeOptions ? nextStateOrOptions : maybeOptions || {}, baseState = isNavigateOptions(nextStateOrOptions) ? getStateFromOptions(nextStateOrOptions, state) ?? state : nextStateOrOptions, currentParams = state._searchParams || [], nextStickyParams = options.stickyParams ?? Object.fromEntries(currentParams.filter(_temp2));
|
|
510
|
+
validateStickyParams(nextStickyParams);
|
|
511
|
+
const nextParams_0 = baseState._searchParams || [], mergedParams = mergeStickyParams(nextParams_0, nextStickyParams);
|
|
512
|
+
onNavigate({
|
|
513
|
+
path: resolvePathFromState({
|
|
514
|
+
...baseState,
|
|
515
|
+
_searchParams: mergedParams
|
|
516
|
+
}),
|
|
517
|
+
replace: options.replace
|
|
518
|
+
});
|
|
519
|
+
}, $[6] = onNavigate, $[7] = resolvePathFromState, $[8] = state, $[9] = t2) : t2 = $[9];
|
|
520
|
+
const navigate = t2;
|
|
521
|
+
let t3;
|
|
522
|
+
$[10] !== navigate ? (t3 = (params_0, t42) => navigate({
|
|
523
|
+
stickyParams: params_0,
|
|
524
|
+
...t42 === void 0 ? {} : t42,
|
|
525
|
+
state: void 0
|
|
526
|
+
}), $[10] = navigate, $[11] = t3) : t3 = $[11];
|
|
527
|
+
const handleNavigateStickyParams = t3;
|
|
528
|
+
let t4;
|
|
529
|
+
$[12] !== onNavigate || $[13] !== resolveIntentLink ? (t4 = (intentName_0, params_1, t52) => {
|
|
530
|
+
const options_1 = t52 === void 0 ? {} : t52;
|
|
531
|
+
onNavigate({
|
|
532
|
+
path: resolveIntentLink(intentName_0, params_1),
|
|
533
|
+
replace: options_1.replace
|
|
534
|
+
});
|
|
535
|
+
}, $[12] = onNavigate, $[13] = resolveIntentLink, $[14] = t4) : t4 = $[14];
|
|
536
|
+
const navigateIntent = t4;
|
|
537
|
+
let t5;
|
|
538
|
+
bb0: {
|
|
539
|
+
if (!state._searchParams) {
|
|
540
|
+
let t63;
|
|
541
|
+
$[15] !== state ? (t63 = [state, null], $[15] = state, $[16] = t63) : t63 = $[16], t5 = t63;
|
|
542
|
+
break bb0;
|
|
543
|
+
}
|
|
544
|
+
let _searchParams_0, rest;
|
|
545
|
+
$[17] !== state ? ({
|
|
546
|
+
_searchParams: _searchParams_0,
|
|
547
|
+
...rest
|
|
548
|
+
} = state, $[17] = state, $[18] = _searchParams_0, $[19] = rest) : (_searchParams_0 = $[18], rest = $[19]);
|
|
549
|
+
let t62;
|
|
550
|
+
$[20] !== _searchParams_0 ? (t62 = partition(_searchParams_0, _temp3), $[20] = _searchParams_0, $[21] = t62) : t62 = $[21];
|
|
551
|
+
const [sticky, restParams] = t62;
|
|
552
|
+
if (sticky.length === 0) {
|
|
553
|
+
let t73;
|
|
554
|
+
$[22] !== state ? (t73 = [state, null], $[22] = state, $[23] = t73) : t73 = $[23], t5 = t73;
|
|
555
|
+
break bb0;
|
|
556
|
+
}
|
|
557
|
+
let t72;
|
|
558
|
+
$[24] !== rest || $[25] !== restParams ? (t72 = {
|
|
559
|
+
...rest,
|
|
560
|
+
_searchParams: restParams
|
|
561
|
+
}, $[24] = rest, $[25] = restParams, $[26] = t72) : t72 = $[26];
|
|
562
|
+
let t82;
|
|
563
|
+
$[27] !== sticky || $[28] !== t72 ? (t82 = [t72, sticky], $[27] = sticky, $[28] = t72, $[29] = t82) : t82 = $[29], t5 = t82;
|
|
564
|
+
}
|
|
565
|
+
const [routerState, stickyParams] = t5;
|
|
566
|
+
let t6;
|
|
567
|
+
$[30] !== stickyParams ? (t6 = Object.fromEntries(stickyParams || []), $[30] = stickyParams, $[31] = t6) : t6 = $[31];
|
|
568
|
+
const stickyParamsByName = t6;
|
|
569
|
+
let t7;
|
|
570
|
+
$[32] !== handleNavigateStickyParams || $[33] !== navigate || $[34] !== navigateIntent || $[35] !== onNavigate || $[36] !== resolveIntentLink || $[37] !== resolvePathFromState || $[38] !== routerState || $[39] !== stickyParamsByName ? (t7 = {
|
|
571
|
+
navigate,
|
|
572
|
+
navigateIntent,
|
|
573
|
+
navigateStickyParams: handleNavigateStickyParams,
|
|
574
|
+
navigateUrl: onNavigate,
|
|
575
|
+
resolveIntentLink,
|
|
576
|
+
resolvePathFromState,
|
|
577
|
+
state: routerState,
|
|
578
|
+
stickyParams: stickyParamsByName
|
|
579
|
+
}, $[32] = handleNavigateStickyParams, $[33] = navigate, $[34] = navigateIntent, $[35] = onNavigate, $[36] = resolveIntentLink, $[37] = resolvePathFromState, $[38] = routerState, $[39] = stickyParamsByName, $[40] = t7) : t7 = $[40];
|
|
580
|
+
const router = t7;
|
|
581
|
+
let t8;
|
|
582
|
+
return $[41] !== props.children || $[42] !== router ? (t8 = /* @__PURE__ */ jsx(RouterContext.Provider, { value: router, children: props.children }), $[41] = props.children, $[42] = router, $[43] = t8) : t8 = $[43], t8;
|
|
583
|
+
}
|
|
584
|
+
function _temp3(t0) {
|
|
585
|
+
const [key_1] = t0;
|
|
586
|
+
return STICKY_PARAMS.includes(key_1);
|
|
587
|
+
}
|
|
588
|
+
function _temp2(t0) {
|
|
589
|
+
const [key_0] = t0;
|
|
590
|
+
return STICKY_PARAMS.includes(key_0);
|
|
591
|
+
}
|
|
592
|
+
function _temp(t0) {
|
|
593
|
+
const [key] = t0;
|
|
594
|
+
return STICKY_PARAMS.includes(key);
|
|
595
|
+
}
|
|
596
|
+
function replaceStickyParam(current, param, value) {
|
|
597
|
+
const filtered = current.filter(([key]) => key !== param);
|
|
598
|
+
return value === void 0 || value == "" ? filtered : [...filtered, [param, value]];
|
|
599
|
+
}
|
|
600
|
+
function mergeStickyParams(currentParams, newParams) {
|
|
601
|
+
if (!newParams) return currentParams;
|
|
602
|
+
const filteredParams = currentParams.filter(([key]) => !Object.hasOwn(newParams, key)), isValidSearchParam = (entry) => entry[1] !== void 0, convertNullSearchParam = (entry) => [entry[0], entry[1] === null ? "" : entry[1]], newEntries = Object.entries(newParams).filter(isValidSearchParam).map(convertNullSearchParam);
|
|
603
|
+
return [...filteredParams, ...newEntries];
|
|
604
|
+
}
|
|
605
|
+
function findParam(searchParams, key) {
|
|
606
|
+
const entry = searchParams.find(([k]) => k === key);
|
|
607
|
+
return entry ? entry[1] : void 0;
|
|
608
|
+
}
|
|
609
|
+
function getStateFromOptions(nextStateOrOptions, state) {
|
|
610
|
+
return isNavigateOptions(nextStateOrOptions) ? nextStateOrOptions.state === null ? {} : nextStateOrOptions.state ?? state : null;
|
|
611
|
+
}
|
|
612
|
+
function validateStickyParams(nextStickyParams) {
|
|
613
|
+
if (Object.keys(nextStickyParams).some((param) => !STICKY_PARAMS.includes(param))) throw new Error("One or more parameters are not sticky");
|
|
614
|
+
}
|
|
615
|
+
function addScope(routerState, scope, scopedState) {
|
|
616
|
+
return scopedState && {
|
|
617
|
+
...routerState,
|
|
618
|
+
[scope]: scopedState
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
const RouteScope = function(props) {
|
|
622
|
+
const $ = c(24), {
|
|
623
|
+
children,
|
|
624
|
+
scope,
|
|
625
|
+
__unsafe_disableScopedSearchParams
|
|
626
|
+
} = props, parentRouter = useRouter(), {
|
|
627
|
+
resolvePathFromState: parent_resolvePathFromState,
|
|
628
|
+
navigate: parent_navigate
|
|
629
|
+
} = parentRouter, parentStateRef = useRef(parentRouter.state);
|
|
630
|
+
let t0, t1;
|
|
631
|
+
$[0] !== parentRouter.state ? (t0 = () => {
|
|
632
|
+
parentStateRef.current = parentRouter.state;
|
|
633
|
+
}, t1 = [parentRouter.state], $[0] = parentRouter.state, $[1] = t0, $[2] = t1) : (t0 = $[1], t1 = $[2]), useEffect(t0, t1);
|
|
634
|
+
let t2;
|
|
635
|
+
$[3] !== __unsafe_disableScopedSearchParams || $[4] !== scope ? (t2 = (_nextState) => {
|
|
636
|
+
if (_nextState === null)
|
|
637
|
+
return null;
|
|
638
|
+
const {
|
|
639
|
+
_searchParams,
|
|
640
|
+
...nextState
|
|
641
|
+
} = _nextState || {}, nextParentState = addScope(parentStateRef.current, scope, nextState);
|
|
642
|
+
return __unsafe_disableScopedSearchParams ? nextParentState._searchParams = _searchParams : nextParentState[scope]._searchParams = _searchParams, nextParentState;
|
|
643
|
+
}, $[3] = __unsafe_disableScopedSearchParams, $[4] = scope, $[5] = t2) : t2 = $[5];
|
|
644
|
+
const resolveNextParentState = t2;
|
|
645
|
+
let t3;
|
|
646
|
+
$[6] !== parent_resolvePathFromState || $[7] !== resolveNextParentState ? (t3 = (nextState_0) => parent_resolvePathFromState(resolveNextParentState(nextState_0)), $[6] = parent_resolvePathFromState, $[7] = resolveNextParentState, $[8] = t3) : t3 = $[8];
|
|
647
|
+
const resolvePathFromState = t3;
|
|
648
|
+
let t4;
|
|
649
|
+
$[9] !== parent_navigate || $[10] !== resolveNextParentState ? (t4 = (nextStateOrOptions, maybeOptions) => {
|
|
650
|
+
if (isNavigateOptions(nextStateOrOptions) && !maybeOptions) {
|
|
651
|
+
const options = nextStateOrOptions, {
|
|
652
|
+
state
|
|
653
|
+
} = options;
|
|
654
|
+
if (state) {
|
|
655
|
+
const nextState_1 = resolveNextParentState(state);
|
|
656
|
+
return parent_navigate(nextState_1 === null ? {} : nextState_1, options);
|
|
657
|
+
}
|
|
658
|
+
return parent_navigate(options);
|
|
659
|
+
}
|
|
660
|
+
const nextState_2 = isNavigateOptions(nextStateOrOptions) ? resolveNextParentState(null) : resolveNextParentState(nextStateOrOptions);
|
|
661
|
+
return parent_navigate(nextState_2 === null ? {} : nextState_2, maybeOptions || {});
|
|
662
|
+
}, $[9] = parent_navigate, $[10] = resolveNextParentState, $[11] = t4) : t4 = $[11];
|
|
663
|
+
const navigate = t4, parentState = parentRouter.state;
|
|
664
|
+
let childState;
|
|
665
|
+
$[12] !== __unsafe_disableScopedSearchParams || $[13] !== parentState || $[14] !== scope ? (childState = typeof parentState[scope] == "object" ? {
|
|
666
|
+
...parentState[scope]
|
|
667
|
+
} : {}, __unsafe_disableScopedSearchParams && (childState._searchParams = parentState._searchParams), $[12] = __unsafe_disableScopedSearchParams, $[13] = parentState, $[14] = scope, $[15] = childState) : childState = $[15];
|
|
668
|
+
let t5;
|
|
669
|
+
$[16] !== childState || $[17] !== navigate || $[18] !== parentRouter || $[19] !== resolvePathFromState ? (t5 = {
|
|
670
|
+
...parentRouter,
|
|
671
|
+
navigate,
|
|
672
|
+
resolvePathFromState,
|
|
673
|
+
state: childState
|
|
674
|
+
}, $[16] = childState, $[17] = navigate, $[18] = parentRouter, $[19] = resolvePathFromState, $[20] = t5) : t5 = $[20];
|
|
675
|
+
const childRouter = t5;
|
|
676
|
+
let t6;
|
|
677
|
+
return $[21] !== childRouter || $[22] !== children ? (t6 = /* @__PURE__ */ jsx(RouterContext.Provider, { value: childRouter, children }), $[21] = childRouter, $[22] = children, $[23] = t6) : t6 = $[23], t6;
|
|
678
|
+
};
|
|
679
|
+
RouteScope.displayName = "RouteScope";
|
|
680
|
+
const EMPTY_STATE = {};
|
|
681
|
+
function useStateLink(options) {
|
|
682
|
+
const $ = c(11), {
|
|
683
|
+
onClick: onClickProp,
|
|
684
|
+
replace,
|
|
685
|
+
state,
|
|
686
|
+
target,
|
|
687
|
+
toIndex: t0
|
|
688
|
+
} = options, toIndex = t0 === void 0 ? !1 : t0;
|
|
689
|
+
if (state && toIndex)
|
|
690
|
+
throw new Error("Passing both `state` and `toIndex={true}` as props to StateLink is invalid");
|
|
691
|
+
!state && !toIndex && console.error(new Error("No state passed to StateLink. If you want to link to an empty state, its better to use the the `toIndex` property"));
|
|
692
|
+
const {
|
|
693
|
+
resolvePathFromState
|
|
694
|
+
} = useRouter(), t1 = toIndex ? EMPTY_STATE : state || EMPTY_STATE;
|
|
695
|
+
let t2;
|
|
696
|
+
$[0] !== resolvePathFromState || $[1] !== t1 ? (t2 = resolvePathFromState(t1), $[0] = resolvePathFromState, $[1] = t1, $[2] = t2) : t2 = $[2];
|
|
697
|
+
const href = t2;
|
|
698
|
+
let t3;
|
|
699
|
+
$[3] !== href || $[4] !== onClickProp || $[5] !== replace || $[6] !== target ? (t3 = {
|
|
700
|
+
href,
|
|
701
|
+
onClick: onClickProp,
|
|
702
|
+
replace,
|
|
703
|
+
target
|
|
704
|
+
}, $[3] = href, $[4] = onClickProp, $[5] = replace, $[6] = target, $[7] = t3) : t3 = $[7];
|
|
705
|
+
const {
|
|
706
|
+
onClick
|
|
707
|
+
} = useLink(t3);
|
|
708
|
+
let t4;
|
|
709
|
+
return $[8] !== href || $[9] !== onClick ? (t4 = {
|
|
710
|
+
onClick,
|
|
711
|
+
href
|
|
712
|
+
}, $[8] = href, $[9] = onClick, $[10] = t4) : t4 = $[10], t4;
|
|
713
|
+
}
|
|
714
|
+
const StateLink = forwardRef(function(props, ref) {
|
|
715
|
+
const $ = c(18);
|
|
716
|
+
let onClickProp, replace, restProps, state, t0, target;
|
|
717
|
+
$[0] !== props ? ({
|
|
718
|
+
onClick: onClickProp,
|
|
719
|
+
replace,
|
|
720
|
+
state,
|
|
721
|
+
target,
|
|
722
|
+
toIndex: t0,
|
|
723
|
+
...restProps
|
|
724
|
+
} = props, $[0] = props, $[1] = onClickProp, $[2] = replace, $[3] = restProps, $[4] = state, $[5] = t0, $[6] = target) : (onClickProp = $[1], replace = $[2], restProps = $[3], state = $[4], t0 = $[5], target = $[6]);
|
|
725
|
+
const toIndex = t0 === void 0 ? !1 : t0;
|
|
726
|
+
let t1;
|
|
727
|
+
$[7] !== onClickProp || $[8] !== replace || $[9] !== state || $[10] !== target || $[11] !== toIndex ? (t1 = {
|
|
728
|
+
onClick: onClickProp,
|
|
729
|
+
replace,
|
|
730
|
+
state,
|
|
731
|
+
target,
|
|
732
|
+
toIndex
|
|
733
|
+
}, $[7] = onClickProp, $[8] = replace, $[9] = state, $[10] = target, $[11] = toIndex, $[12] = t1) : t1 = $[12];
|
|
734
|
+
const {
|
|
735
|
+
onClick,
|
|
736
|
+
href
|
|
737
|
+
} = useStateLink(t1);
|
|
738
|
+
let t2;
|
|
739
|
+
return $[13] !== href || $[14] !== onClick || $[15] !== ref || $[16] !== restProps ? (t2 = /* @__PURE__ */ jsx("a", { ...restProps, href, onClick, ref }), $[13] = href, $[14] = onClick, $[15] = ref, $[16] = restProps, $[17] = t2) : t2 = $[17], t2;
|
|
740
|
+
});
|
|
741
|
+
function useRouterState(t0) {
|
|
742
|
+
const $ = c(3), selector = t0 === void 0 ? identity : t0, {
|
|
743
|
+
state
|
|
744
|
+
} = useRouter();
|
|
745
|
+
let t1;
|
|
746
|
+
return $[0] !== selector || $[1] !== state ? (t1 = selector(state), $[0] = selector, $[1] = state, $[2] = t1) : t1 = $[2], t1;
|
|
747
|
+
}
|
|
748
|
+
function withRouter(Component) {
|
|
749
|
+
function WithRouter2(props) {
|
|
750
|
+
const $ = c(3), router = useRouter(), t0 = props;
|
|
751
|
+
let t1;
|
|
752
|
+
return $[0] !== router || $[1] !== t0 ? (t1 = /* @__PURE__ */ jsx(Component, { ...t0, router }), $[0] = router, $[1] = t0, $[2] = t1) : t1 = $[2], t1;
|
|
753
|
+
}
|
|
754
|
+
return WithRouter2.displayName = `withRouter(${Component.displayName || Component.name})`, WithRouter2;
|
|
755
|
+
}
|
|
756
|
+
const WithRouter = withRouter((props) => props.children(props.router));
|
|
757
|
+
export {
|
|
758
|
+
IntentLink,
|
|
759
|
+
Link,
|
|
760
|
+
RouteScope,
|
|
761
|
+
RouterContext2 as RouterContext,
|
|
762
|
+
RouterProvider,
|
|
763
|
+
STICKY_PARAMS,
|
|
764
|
+
StateLink,
|
|
765
|
+
WithRouter,
|
|
766
|
+
_createNode,
|
|
767
|
+
decodeJsonParams,
|
|
768
|
+
encodeJsonParams,
|
|
769
|
+
route,
|
|
770
|
+
useIntentLink,
|
|
771
|
+
useLink,
|
|
772
|
+
useRouter,
|
|
773
|
+
useRouterState,
|
|
774
|
+
useStateLink,
|
|
775
|
+
withRouter
|
|
776
|
+
};
|
|
777
|
+
//# sourceMappingURL=router.js.map
|