@inventreedb/ui 0.11.0 → 0.11.2

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.
@@ -1,560 +0,0 @@
1
- import { useLocation, useNavigate, UNSAFE_NavigationContext as NavigationContext, useHref, useResolvedPath, UNSAFE_DataRouterStateContext as DataRouterStateContext, UNSAFE_useRouteId as useRouteId, UNSAFE_RouteContext as RouteContext, UNSAFE_DataRouterContext as DataRouterContext } from "../../react-router/dist/index.js";
2
- import { UNSAFE_LocationContext, useInRouterContext } from "../../react-router/dist/index.js";
3
- import { UNSAFE_warning as warning, stripBasename, createPath, UNSAFE_invariant as invariant, matchPath, joinPaths } from "../../@remix-run/router/dist/router.js";
4
- import { AbortedDeferredError, Action, parsePath, resolvePath } from "../../@remix-run/router/dist/router.js";
5
- const React = window["React"];
6
- const ReactDOM = window["ReactDOM"];
7
- function _extends() {
8
- _extends = Object.assign ? Object.assign.bind() : function(target) {
9
- for (var i = 1; i < arguments.length; i++) {
10
- var source = arguments[i];
11
- for (var key in source) {
12
- if (Object.prototype.hasOwnProperty.call(source, key)) {
13
- target[key] = source[key];
14
- }
15
- }
16
- }
17
- return target;
18
- };
19
- return _extends.apply(this, arguments);
20
- }
21
- function _objectWithoutPropertiesLoose(source, excluded) {
22
- if (source == null) return {};
23
- var target = {};
24
- var sourceKeys = Object.keys(source);
25
- var key, i;
26
- for (i = 0; i < sourceKeys.length; i++) {
27
- key = sourceKeys[i];
28
- if (excluded.indexOf(key) >= 0) continue;
29
- target[key] = source[key];
30
- }
31
- return target;
32
- }
33
- const defaultMethod = "get";
34
- const defaultEncType = "application/x-www-form-urlencoded";
35
- function isHtmlElement(object) {
36
- return object != null && typeof object.tagName === "string";
37
- }
38
- function isButtonElement(object) {
39
- return isHtmlElement(object) && object.tagName.toLowerCase() === "button";
40
- }
41
- function isFormElement(object) {
42
- return isHtmlElement(object) && object.tagName.toLowerCase() === "form";
43
- }
44
- function isInputElement(object) {
45
- return isHtmlElement(object) && object.tagName.toLowerCase() === "input";
46
- }
47
- function isModifiedEvent(event) {
48
- return !!(event.metaKey || event.altKey || event.ctrlKey || event.shiftKey);
49
- }
50
- function shouldProcessLinkClick(event, target) {
51
- return event.button === 0 && // Ignore everything but left clicks
52
- (!target || target === "_self") && // Let browser handle "target=_blank" etc.
53
- !isModifiedEvent(event);
54
- }
55
- function createSearchParams(init) {
56
- if (init === void 0) {
57
- init = "";
58
- }
59
- return new URLSearchParams(typeof init === "string" || Array.isArray(init) || init instanceof URLSearchParams ? init : Object.keys(init).reduce((memo, key) => {
60
- let value = init[key];
61
- return memo.concat(Array.isArray(value) ? value.map((v) => [key, v]) : [[key, value]]);
62
- }, []));
63
- }
64
- function getSearchParamsForLocation(locationSearch, defaultSearchParams) {
65
- let searchParams = createSearchParams(locationSearch);
66
- if (defaultSearchParams) {
67
- defaultSearchParams.forEach((_, key) => {
68
- if (!searchParams.has(key)) {
69
- defaultSearchParams.getAll(key).forEach((value) => {
70
- searchParams.append(key, value);
71
- });
72
- }
73
- });
74
- }
75
- return searchParams;
76
- }
77
- let _formDataSupportsSubmitter = null;
78
- function isFormDataSubmitterSupported() {
79
- if (_formDataSupportsSubmitter === null) {
80
- try {
81
- new FormData(
82
- document.createElement("form"),
83
- // @ts-expect-error if FormData supports the submitter parameter, this will throw
84
- 0
85
- );
86
- _formDataSupportsSubmitter = false;
87
- } catch (e) {
88
- _formDataSupportsSubmitter = true;
89
- }
90
- }
91
- return _formDataSupportsSubmitter;
92
- }
93
- const supportedFormEncTypes = /* @__PURE__ */ new Set(["application/x-www-form-urlencoded", "multipart/form-data", "text/plain"]);
94
- function getFormEncType(encType) {
95
- if (encType != null && !supportedFormEncTypes.has(encType)) {
96
- process.env.NODE_ENV !== "production" ? warning(false, '"' + encType + '" is not a valid `encType` for `<Form>`/`<fetcher.Form>` ' + ('and will default to "' + defaultEncType + '"')) : void 0;
97
- return null;
98
- }
99
- return encType;
100
- }
101
- function getFormSubmissionInfo(target, basename) {
102
- let method;
103
- let action;
104
- let encType;
105
- let formData;
106
- let body;
107
- if (isFormElement(target)) {
108
- let attr = target.getAttribute("action");
109
- action = attr ? stripBasename(attr, basename) : null;
110
- method = target.getAttribute("method") || defaultMethod;
111
- encType = getFormEncType(target.getAttribute("enctype")) || defaultEncType;
112
- formData = new FormData(target);
113
- } else if (isButtonElement(target) || isInputElement(target) && (target.type === "submit" || target.type === "image")) {
114
- let form = target.form;
115
- if (form == null) {
116
- throw new Error('Cannot submit a <button> or <input type="submit"> without a <form>');
117
- }
118
- let attr = target.getAttribute("formaction") || form.getAttribute("action");
119
- action = attr ? stripBasename(attr, basename) : null;
120
- method = target.getAttribute("formmethod") || form.getAttribute("method") || defaultMethod;
121
- encType = getFormEncType(target.getAttribute("formenctype")) || getFormEncType(form.getAttribute("enctype")) || defaultEncType;
122
- formData = new FormData(form, target);
123
- if (!isFormDataSubmitterSupported()) {
124
- let {
125
- name,
126
- type,
127
- value
128
- } = target;
129
- if (type === "image") {
130
- let prefix = name ? name + "." : "";
131
- formData.append(prefix + "x", "0");
132
- formData.append(prefix + "y", "0");
133
- } else if (name) {
134
- formData.append(name, value);
135
- }
136
- }
137
- } else if (isHtmlElement(target)) {
138
- throw new Error('Cannot submit element that is not <form>, <button>, or <input type="submit|image">');
139
- } else {
140
- method = defaultMethod;
141
- action = null;
142
- encType = defaultEncType;
143
- body = target;
144
- }
145
- if (formData && encType === "text/plain") {
146
- body = formData;
147
- formData = void 0;
148
- }
149
- return {
150
- action,
151
- method: method.toLowerCase(),
152
- encType,
153
- formData,
154
- body
155
- };
156
- }
157
- const _excluded = ["onClick", "relative", "reloadDocument", "replace", "state", "target", "to", "preventScrollReset", "viewTransition"], _excluded2 = ["aria-current", "caseSensitive", "className", "end", "style", "to", "viewTransition", "children"], _excluded3 = ["fetcherKey", "navigate", "reloadDocument", "replace", "state", "method", "action", "onSubmit", "relative", "preventScrollReset", "viewTransition"];
158
- const REACT_ROUTER_VERSION = "6";
159
- try {
160
- window.__reactRouterVersion = REACT_ROUTER_VERSION;
161
- } catch (e) {
162
- }
163
- const ViewTransitionContext = /* @__PURE__ */ React.createContext({
164
- isTransitioning: false
165
- });
166
- if (process.env.NODE_ENV !== "production") {
167
- ViewTransitionContext.displayName = "ViewTransition";
168
- }
169
- const FetchersContext = /* @__PURE__ */ React.createContext(/* @__PURE__ */ new Map());
170
- if (process.env.NODE_ENV !== "production") {
171
- FetchersContext.displayName = "Fetchers";
172
- }
173
- const START_TRANSITION = "startTransition";
174
- React[START_TRANSITION];
175
- const FLUSH_SYNC = "flushSync";
176
- ReactDOM[FLUSH_SYNC];
177
- const USE_ID = "useId";
178
- React[USE_ID];
179
- if (process.env.NODE_ENV !== "production") ;
180
- const isBrowser = typeof window !== "undefined" && typeof window.document !== "undefined" && typeof window.document.createElement !== "undefined";
181
- const ABSOLUTE_URL_REGEX = /^(?:[a-z][a-z0-9+.-]*:|\/\/)/i;
182
- const Link = /* @__PURE__ */ React.forwardRef(function LinkWithRef(_ref7, ref) {
183
- let {
184
- onClick,
185
- relative,
186
- reloadDocument,
187
- replace,
188
- state,
189
- target,
190
- to,
191
- preventScrollReset,
192
- viewTransition
193
- } = _ref7, rest = _objectWithoutPropertiesLoose(_ref7, _excluded);
194
- let {
195
- basename
196
- } = React.useContext(NavigationContext);
197
- let absoluteHref;
198
- let isExternal = false;
199
- if (typeof to === "string" && ABSOLUTE_URL_REGEX.test(to)) {
200
- absoluteHref = to;
201
- if (isBrowser) {
202
- try {
203
- let currentUrl = new URL(window.location.href);
204
- let targetUrl = to.startsWith("//") ? new URL(currentUrl.protocol + to) : new URL(to);
205
- let path = stripBasename(targetUrl.pathname, basename);
206
- if (targetUrl.origin === currentUrl.origin && path != null) {
207
- to = path + targetUrl.search + targetUrl.hash;
208
- } else {
209
- isExternal = true;
210
- }
211
- } catch (e) {
212
- process.env.NODE_ENV !== "production" ? warning(false, '<Link to="' + to + '"> contains an invalid URL which will probably break when clicked - please update to a valid URL path.') : void 0;
213
- }
214
- }
215
- }
216
- let href = useHref(to, {
217
- relative
218
- });
219
- let internalOnClick = useLinkClickHandler(to, {
220
- replace,
221
- state,
222
- target,
223
- preventScrollReset,
224
- relative,
225
- viewTransition
226
- });
227
- function handleClick(event) {
228
- if (onClick) onClick(event);
229
- if (!event.defaultPrevented) {
230
- internalOnClick(event);
231
- }
232
- }
233
- return (
234
- // eslint-disable-next-line jsx-a11y/anchor-has-content
235
- /* @__PURE__ */ React.createElement("a", _extends({}, rest, {
236
- href: absoluteHref || href,
237
- onClick: isExternal || reloadDocument ? onClick : handleClick,
238
- ref,
239
- target
240
- }))
241
- );
242
- });
243
- if (process.env.NODE_ENV !== "production") {
244
- Link.displayName = "Link";
245
- }
246
- const NavLink = /* @__PURE__ */ React.forwardRef(function NavLinkWithRef(_ref8, ref) {
247
- let {
248
- "aria-current": ariaCurrentProp = "page",
249
- caseSensitive = false,
250
- className: classNameProp = "",
251
- end = false,
252
- style: styleProp,
253
- to,
254
- viewTransition,
255
- children
256
- } = _ref8, rest = _objectWithoutPropertiesLoose(_ref8, _excluded2);
257
- let path = useResolvedPath(to, {
258
- relative: rest.relative
259
- });
260
- let location = useLocation();
261
- let routerState = React.useContext(DataRouterStateContext);
262
- let {
263
- navigator,
264
- basename
265
- } = React.useContext(NavigationContext);
266
- let isTransitioning = routerState != null && // Conditional usage is OK here because the usage of a data router is static
267
- // eslint-disable-next-line react-hooks/rules-of-hooks
268
- useViewTransitionState(path) && viewTransition === true;
269
- let toPathname = navigator.encodeLocation ? navigator.encodeLocation(path).pathname : path.pathname;
270
- let locationPathname = location.pathname;
271
- let nextLocationPathname = routerState && routerState.navigation && routerState.navigation.location ? routerState.navigation.location.pathname : null;
272
- if (!caseSensitive) {
273
- locationPathname = locationPathname.toLowerCase();
274
- nextLocationPathname = nextLocationPathname ? nextLocationPathname.toLowerCase() : null;
275
- toPathname = toPathname.toLowerCase();
276
- }
277
- if (nextLocationPathname && basename) {
278
- nextLocationPathname = stripBasename(nextLocationPathname, basename) || nextLocationPathname;
279
- }
280
- const endSlashPosition = toPathname !== "/" && toPathname.endsWith("/") ? toPathname.length - 1 : toPathname.length;
281
- let isActive = locationPathname === toPathname || !end && locationPathname.startsWith(toPathname) && locationPathname.charAt(endSlashPosition) === "/";
282
- let isPending = nextLocationPathname != null && (nextLocationPathname === toPathname || !end && nextLocationPathname.startsWith(toPathname) && nextLocationPathname.charAt(toPathname.length) === "/");
283
- let renderProps = {
284
- isActive,
285
- isPending,
286
- isTransitioning
287
- };
288
- let ariaCurrent = isActive ? ariaCurrentProp : void 0;
289
- let className;
290
- if (typeof classNameProp === "function") {
291
- className = classNameProp(renderProps);
292
- } else {
293
- className = [classNameProp, isActive ? "active" : null, isPending ? "pending" : null, isTransitioning ? "transitioning" : null].filter(Boolean).join(" ");
294
- }
295
- let style = typeof styleProp === "function" ? styleProp(renderProps) : styleProp;
296
- return /* @__PURE__ */ React.createElement(Link, _extends({}, rest, {
297
- "aria-current": ariaCurrent,
298
- className,
299
- ref,
300
- style,
301
- to,
302
- viewTransition
303
- }), typeof children === "function" ? children(renderProps) : children);
304
- });
305
- if (process.env.NODE_ENV !== "production") {
306
- NavLink.displayName = "NavLink";
307
- }
308
- const Form = /* @__PURE__ */ React.forwardRef((_ref9, forwardedRef) => {
309
- let {
310
- fetcherKey,
311
- navigate,
312
- reloadDocument,
313
- replace,
314
- state,
315
- method = defaultMethod,
316
- action,
317
- onSubmit,
318
- relative,
319
- preventScrollReset,
320
- viewTransition
321
- } = _ref9, props = _objectWithoutPropertiesLoose(_ref9, _excluded3);
322
- let submit = useSubmit();
323
- let formAction = useFormAction(action, {
324
- relative
325
- });
326
- let formMethod = method.toLowerCase() === "get" ? "get" : "post";
327
- let submitHandler = (event) => {
328
- onSubmit && onSubmit(event);
329
- if (event.defaultPrevented) return;
330
- event.preventDefault();
331
- let submitter = event.nativeEvent.submitter;
332
- let submitMethod = (submitter == null ? void 0 : submitter.getAttribute("formmethod")) || method;
333
- submit(submitter || event.currentTarget, {
334
- fetcherKey,
335
- method: submitMethod,
336
- navigate,
337
- replace,
338
- state,
339
- relative,
340
- preventScrollReset,
341
- viewTransition
342
- });
343
- };
344
- return /* @__PURE__ */ React.createElement("form", _extends({
345
- ref: forwardedRef,
346
- method: formMethod,
347
- action: formAction,
348
- onSubmit: reloadDocument ? onSubmit : submitHandler
349
- }, props));
350
- });
351
- if (process.env.NODE_ENV !== "production") {
352
- Form.displayName = "Form";
353
- }
354
- if (process.env.NODE_ENV !== "production") ;
355
- var DataRouterHook;
356
- (function(DataRouterHook2) {
357
- DataRouterHook2["UseScrollRestoration"] = "useScrollRestoration";
358
- DataRouterHook2["UseSubmit"] = "useSubmit";
359
- DataRouterHook2["UseSubmitFetcher"] = "useSubmitFetcher";
360
- DataRouterHook2["UseFetcher"] = "useFetcher";
361
- DataRouterHook2["useViewTransitionState"] = "useViewTransitionState";
362
- })(DataRouterHook || (DataRouterHook = {}));
363
- var DataRouterStateHook;
364
- (function(DataRouterStateHook2) {
365
- DataRouterStateHook2["UseFetcher"] = "useFetcher";
366
- DataRouterStateHook2["UseFetchers"] = "useFetchers";
367
- DataRouterStateHook2["UseScrollRestoration"] = "useScrollRestoration";
368
- })(DataRouterStateHook || (DataRouterStateHook = {}));
369
- function getDataRouterConsoleError(hookName) {
370
- return hookName + " must be used within a data router. See https://reactrouter.com/v6/routers/picking-a-router.";
371
- }
372
- function useDataRouterContext(hookName) {
373
- let ctx = React.useContext(DataRouterContext);
374
- !ctx ? process.env.NODE_ENV !== "production" ? invariant(false, getDataRouterConsoleError(hookName)) : invariant(false) : void 0;
375
- return ctx;
376
- }
377
- function useLinkClickHandler(to, _temp) {
378
- let {
379
- target,
380
- replace: replaceProp,
381
- state,
382
- preventScrollReset,
383
- relative,
384
- viewTransition
385
- } = _temp === void 0 ? {} : _temp;
386
- let navigate = useNavigate();
387
- let location = useLocation();
388
- let path = useResolvedPath(to, {
389
- relative
390
- });
391
- return React.useCallback((event) => {
392
- if (shouldProcessLinkClick(event, target)) {
393
- event.preventDefault();
394
- let replace = replaceProp !== void 0 ? replaceProp : createPath(location) === createPath(path);
395
- navigate(to, {
396
- replace,
397
- state,
398
- preventScrollReset,
399
- relative,
400
- viewTransition
401
- });
402
- }
403
- }, [location, navigate, path, replaceProp, state, target, to, preventScrollReset, relative, viewTransition]);
404
- }
405
- function useSearchParams(defaultInit) {
406
- process.env.NODE_ENV !== "production" ? warning(typeof URLSearchParams !== "undefined", "You cannot use the `useSearchParams` hook in a browser that does not support the URLSearchParams API. If you need to support Internet Explorer 11, we recommend you load a polyfill such as https://github.com/ungap/url-search-params.") : void 0;
407
- let defaultSearchParamsRef = React.useRef(createSearchParams(defaultInit));
408
- let hasSetSearchParamsRef = React.useRef(false);
409
- let location = useLocation();
410
- let searchParams = React.useMemo(() => (
411
- // Only merge in the defaults if we haven't yet called setSearchParams.
412
- // Once we call that we want those to take precedence, otherwise you can't
413
- // remove a param with setSearchParams({}) if it has an initial value
414
- getSearchParamsForLocation(location.search, hasSetSearchParamsRef.current ? null : defaultSearchParamsRef.current)
415
- ), [location.search]);
416
- let navigate = useNavigate();
417
- let setSearchParams = React.useCallback((nextInit, navigateOptions) => {
418
- const newSearchParams = createSearchParams(typeof nextInit === "function" ? nextInit(searchParams) : nextInit);
419
- hasSetSearchParamsRef.current = true;
420
- navigate("?" + newSearchParams, navigateOptions);
421
- }, [navigate, searchParams]);
422
- return [searchParams, setSearchParams];
423
- }
424
- function validateClientSideSubmission() {
425
- if (typeof document === "undefined") {
426
- throw new Error("You are calling submit during the server render. Try calling submit within a `useEffect` or callback instead.");
427
- }
428
- }
429
- let fetcherId = 0;
430
- let getUniqueFetcherId = () => "__" + String(++fetcherId) + "__";
431
- function useSubmit() {
432
- let {
433
- router
434
- } = useDataRouterContext(DataRouterHook.UseSubmit);
435
- let {
436
- basename
437
- } = React.useContext(NavigationContext);
438
- let currentRouteId = useRouteId();
439
- return React.useCallback(function(target, options) {
440
- if (options === void 0) {
441
- options = {};
442
- }
443
- validateClientSideSubmission();
444
- let {
445
- action,
446
- method,
447
- encType,
448
- formData,
449
- body
450
- } = getFormSubmissionInfo(target, basename);
451
- if (options.navigate === false) {
452
- let key = options.fetcherKey || getUniqueFetcherId();
453
- router.fetch(key, currentRouteId, options.action || action, {
454
- preventScrollReset: options.preventScrollReset,
455
- formData,
456
- body,
457
- formMethod: options.method || method,
458
- formEncType: options.encType || encType,
459
- flushSync: options.flushSync
460
- });
461
- } else {
462
- router.navigate(options.action || action, {
463
- preventScrollReset: options.preventScrollReset,
464
- formData,
465
- body,
466
- formMethod: options.method || method,
467
- formEncType: options.encType || encType,
468
- replace: options.replace,
469
- state: options.state,
470
- fromRouteId: currentRouteId,
471
- flushSync: options.flushSync,
472
- viewTransition: options.viewTransition
473
- });
474
- }
475
- }, [router, basename, currentRouteId]);
476
- }
477
- function useFormAction(action, _temp2) {
478
- let {
479
- relative
480
- } = _temp2 === void 0 ? {} : _temp2;
481
- let {
482
- basename
483
- } = React.useContext(NavigationContext);
484
- let routeContext = React.useContext(RouteContext);
485
- !routeContext ? process.env.NODE_ENV !== "production" ? invariant(false, "useFormAction must be used inside a RouteContext") : invariant(false) : void 0;
486
- let [match] = routeContext.matches.slice(-1);
487
- let path = _extends({}, useResolvedPath(action ? action : ".", {
488
- relative
489
- }));
490
- let location = useLocation();
491
- if (action == null) {
492
- path.search = location.search;
493
- let params = new URLSearchParams(path.search);
494
- let indexValues = params.getAll("index");
495
- let hasNakedIndexParam = indexValues.some((v) => v === "");
496
- if (hasNakedIndexParam) {
497
- params.delete("index");
498
- indexValues.filter((v) => v).forEach((v) => params.append("index", v));
499
- let qs = params.toString();
500
- path.search = qs ? "?" + qs : "";
501
- }
502
- }
503
- if ((!action || action === ".") && match.route.index) {
504
- path.search = path.search ? path.search.replace(/^\?/, "?index&") : "?index";
505
- }
506
- if (basename !== "/") {
507
- path.pathname = path.pathname === "/" ? basename : joinPaths([basename, path.pathname]);
508
- }
509
- return createPath(path);
510
- }
511
- function useViewTransitionState(to, opts) {
512
- if (opts === void 0) {
513
- opts = {};
514
- }
515
- let vtContext = React.useContext(ViewTransitionContext);
516
- !(vtContext != null) ? process.env.NODE_ENV !== "production" ? invariant(false, "`useViewTransitionState` must be used within `react-router-dom`'s `RouterProvider`. Did you accidentally import `RouterProvider` from `react-router`?") : invariant(false) : void 0;
517
- let {
518
- basename
519
- } = useDataRouterContext(DataRouterHook.useViewTransitionState);
520
- let path = useResolvedPath(to, {
521
- relative: opts.relative
522
- });
523
- if (!vtContext.isTransitioning) {
524
- return false;
525
- }
526
- let currentPath = stripBasename(vtContext.currentLocation.pathname, basename) || vtContext.currentLocation.pathname;
527
- let nextPath = stripBasename(vtContext.nextLocation.pathname, basename) || vtContext.nextLocation.pathname;
528
- return matchPath(path.pathname, nextPath) != null || matchPath(path.pathname, currentPath) != null;
529
- }
530
- export {
531
- AbortedDeferredError,
532
- Form,
533
- Link,
534
- NavLink,
535
- Action as NavigationType,
536
- DataRouterContext as UNSAFE_DataRouterContext,
537
- DataRouterStateContext as UNSAFE_DataRouterStateContext,
538
- FetchersContext as UNSAFE_FetchersContext,
539
- UNSAFE_LocationContext,
540
- NavigationContext as UNSAFE_NavigationContext,
541
- RouteContext as UNSAFE_RouteContext,
542
- ViewTransitionContext as UNSAFE_ViewTransitionContext,
543
- useRouteId as UNSAFE_useRouteId,
544
- createPath,
545
- createSearchParams,
546
- matchPath,
547
- parsePath,
548
- resolvePath,
549
- useFormAction,
550
- useHref,
551
- useInRouterContext,
552
- useLinkClickHandler,
553
- useLocation,
554
- useNavigate,
555
- useResolvedPath,
556
- useSearchParams,
557
- useSubmit,
558
- useViewTransitionState
559
- };
560
- //# sourceMappingURL=index.js.map