1 | !function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e=e||self).CuriReactDOM={},e.React)}(this,function(e,v){"use strict";var t=(v=v&&v.hasOwnProperty("default")?v.default:v).createContext({router:null,response:null,navigation:null}),i=t.Provider,r=t.Consumer;function c(){return v.useContext(t)}function n(t){var e=c().router;return{pathname:v.useMemo(function(){return t.name?e.route.pathname(t.name,t.params):""},[t.name].concat(Object.keys(t.params||{}).map(function(e){return t.params[e]}))),hash:t.hash,query:t.query,state:t.state}}function p(e){var t=n(e);return c().router.history.toHref(t)}function f(){return!0}function h(n,o,u){void 0===u&&(u=f);var i=c().router,a=v.useRef(void 0);return{handler:function(e){if(n.onNav&&n.onNav(e),u(e,n.forward)){e.preventDefault();var t=void 0,r=void 0;"function"==typeof n.children&&(t=r=function(){a.current=void 0,o(!1)},o(!0)),a.current=i.navigate({method:n.method||"ANCHOR",name:n.name,params:n.params,query:n.query,state:n.state,hash:n.hash,cancelled:t,finished:r})}},cancel:a}}var m=function(){return(m=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e}).apply(this,arguments)};function y(e,t){return!(e.defaultPrevented||0!==e.button||e.metaKey||e.altKey||e.ctrlKey||e.shiftKey||t&&t.target)}var o=v.forwardRef(function(e,t){var r=v.useState(!1),n=r[0],o=r[1],u=p(e),i=h(e,o,y),a=i.handler,c=i.cancel;v.useEffect(function(){return function(){c.current&&c.current()}},[]);var f=e.anchor,s=void 0===f?"a":f,d=e.children,l=e.forward;return v.createElement(s,m({onClick:a,href:u,ref:t},l),"function"==typeof d?d(n):d)});e.Link=o,e.useNavigationFocus=function(o,u){void 0===u&&(u={});var e=c().response;v.useEffect(function(){var e=o.current;if(null!==e){if(!u.preserve||!e.contains(document.activeElement)){"production"!==production&&(e.hasAttribute("tabIndex")||-1!==e.tabIndex||console.warn('The component that is passed the ref must have a "tabIndex" prop or be focusable by default in order to be focused. Otherwise, the document\'s <body> will be focused instead.'));var t=u.preventScroll,r=void 0!==t&&t,n=setTimeout(function(){e.focus({preventScroll:r})});return function(){clearTimeout(n)}}}else"production"!==production&&console.warn("There is no element to focus. Did you forget to add the ref to an element?")},[e])},e.curiProvider=function(o){function u(){var e=o.current(),t=e.response,r=e.navigation;return{router:o,response:t,navigation:r}}return function(e){var t=v.useState(u),r=t[0],n=t[1];return v.useEffect(function(){var t=!1,e=o.observe(function(e){t||n(e)},{initial:!1});return function(){t=!0,e()}},[]),v.createElement(i,{value:r},e.children)}},e.Curious=r,e.useCuri=c,e.useActive=function(e){var t=c(),r=t.router,n=t.response;if("production"!==production&&!r.route.active)throw new Error('You are attempting to use the "active" route interaction, but have not included it in your Curi router.\n\nimport curi from "@curi/router";\nimport active from "@curi/route-active";\n\nconst router = curi(history, routes, {\n route: [active()]\n});');return r.route.active(e.name,n,{params:e.params,partial:e.partial,locationCheck:e.locationCheck})},e.useBlock=function(e,t){var r=c().router;v.useEffect(function(){if(e)return r.history.confirmWith(t),function(){r.history.removeConfirmation()}},[e,t])},e.useLocation=n,e.useHref=p,e.useNavigating=function(){var e=c().router,t=v.useState(void 0),r=t[0],n=t[1],o=v.useState(!1),u=o[0],i=o[1];return v.useEffect(function(){return function(){i(!0)}},[]),v.useEffect(function(){return e.cancel(function(e){u||n(function(){return e})})},[]),r},e.useNavigationHandler=h,Object.defineProperty(e,"__esModule",{value:!0})});
|