jotai-location
Advanced tools
Comparing version 0.5.2 to 0.5.3
@@ -1,2 +0,2 @@ | ||
import{atom as n}from"jotai/vanilla";import{RESET as o}from"jotai/vanilla/utils";const e=()=>"undefined"!=typeof window&&window.location?{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}:{},t=(n,o)=>{const e=new URL(window.location.href);n.pathname&&(e.pathname=n.pathname),n.searchParams&&(e.search=n.searchParams.toString()),null!=o&&o.replace?window.history.replaceState(null,"",e):window.history.pushState(null,"",e)},a=n=>(window.addEventListener("popstate",n),()=>window.removeEventListener("popstate",n));function i(o){var i;const r=(null==o?void 0:o.getLocation)||e,l=(null==o?void 0:o.applyLocation)||t,s=(null==o?void 0:o.subscribe)||a,c=n(null!=(i=null==o?void 0:o.preloaded)?i:r());return"production"!==process.env.NODE_ENV&&(c.debugPrivate=!0),c.onMount=n=>{const o=()=>n(r()),e=s(o);return o(),e},n(n=>n(c),(n,e,t)=>{e(c,t),l(n(c),o)})}function r(e,t,a){const i=(null==a?void 0:a.serialize)||JSON.stringify,r=(null==a?void 0:a.deserialize)||(n=>o=>{try{return JSON.parse(o)}catch(o){return n}})(t),l=(null==a?void 0:a.subscribe)||(n=>(window.addEventListener("hashchange",n),()=>{window.removeEventListener("hashchange",n)})),s=null==a?void 0:a.setHash;let c=n=>{window.location.hash=n};"replaceState"===s&&(c=n=>{window.history.replaceState(window.history.state,"",`${window.location.pathname}${window.location.search}#${n}`)}),"function"==typeof s&&(c=s);const w=n(null);w.onMount=n=>{if("undefined"==typeof window||!window.location)return;const o=()=>{const o=new URLSearchParams(window.location.hash.slice(1)).get(e);n(o)},t=l(o);return o(),t};const d=n(n=>{const o=n(w);return null===o?t:r(o)});return n(n=>n(d),(n,t,a)=>{const r="function"==typeof a?a(n(d)):a,l=new URLSearchParams(window.location.hash.slice(1));if(r===o)t(w,null),l.delete(e);else{const n=i(r);t(w,n),l.set(e,n)}c(l.toString())})}export{r as atomWithHash,i as atomWithLocation}; | ||
import{atom as n}from"jotai/vanilla";import{RESET as t}from"jotai/vanilla/utils";function e(){return e=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var e=arguments[t];for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&(n[o]=e[o])}return n},e.apply(this,arguments)}const o=()=>"undefined"!=typeof window&&window.location?{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}:{},a=(n,t)=>{const e=new URL(window.location.href);n.pathname&&(e.pathname=n.pathname),n.searchParams&&(e.search=n.searchParams.toString()),null!=t&&t.replace?window.history.replaceState(null,"",e):window.history.pushState(null,"",e)},i=n=>(window.addEventListener("popstate",n),()=>window.removeEventListener("popstate",n));function r(t){var r;const s=(null==t?void 0:t.getLocation)||o,l=(null==t?void 0:t.applyLocation)||a,c=(null==t?void 0:t.subscribe)||i,w=n(null!=(r=null==t?void 0:t.preloaded)?r:s());return"production"!==process.env.NODE_ENV&&(w.debugPrivate=!0),w.onMount=n=>{const t=()=>n(s()),e=c(t);return t(),e},n(n=>n(w),(n,o,a,i={})=>{o(w,a),l(n(w),e({},t,i))})}function s(e,o,a){const i=(null==a?void 0:a.serialize)||JSON.stringify,r=(null==a?void 0:a.deserialize)||(n=>t=>{try{return JSON.parse(t)}catch(t){return n}})(o),s=(null==a?void 0:a.subscribe)||(n=>(window.addEventListener("hashchange",n),()=>{window.removeEventListener("hashchange",n)})),l=null==a?void 0:a.setHash;let c=n=>{window.location.hash=n};"replaceState"===l&&(c=n=>{window.history.replaceState(window.history.state,"",`${window.location.pathname}${window.location.search}#${n}`)}),"function"==typeof l&&(c=l);const w=n(null);w.onMount=n=>{if("undefined"==typeof window||!window.location)return;const t=()=>{const t=new URLSearchParams(window.location.hash.slice(1)).get(e);n(t)},o=s(t);return t(),o};const d=n(n=>{const t=n(w);return null===t?o:r(t)});return n(n=>n(d),(n,o,a)=>{const r="function"==typeof a?a(n(d)):a,s=new URLSearchParams(window.location.hash.slice(1));if(r===t)o(w,null),s.delete(e);else{const n=i(r);o(w,n),s.set(e,n)}c(s.toString())})}export{s as atomWithHash,r as atomWithLocation}; | ||
//# sourceMappingURL=index.modern.mjs.map |
@@ -1,2 +0,2 @@ | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("jotai/vanilla"),require("jotai/vanilla/utils")):"function"==typeof define&&define.amd?define(["exports","jotai/vanilla","jotai/vanilla/utils"],t):t((n||self).jotaiLocation={},n.vanilla,n.utils)}(this,function(n,t,o){var e=function(){return"undefined"!=typeof window&&window.location?{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}:{}},i=function(n,t){var o=new URL(window.location.href);n.pathname&&(o.pathname=n.pathname),n.searchParams&&(o.search=n.searchParams.toString()),null!=t&&t.replace?window.history.replaceState(null,"",o):window.history.pushState(null,"",o)},a=function(n){return window.addEventListener("popstate",n),function(){return window.removeEventListener("popstate",n)}};n.atomWithHash=function(n,e,i){var a=(null==i?void 0:i.serialize)||JSON.stringify,r=(null==i?void 0:i.deserialize)||function(n){return function(t){try{return JSON.parse(t)}catch(t){return n}}}(e),u=(null==i?void 0:i.subscribe)||function(n){return window.addEventListener("hashchange",n),function(){window.removeEventListener("hashchange",n)}},l=null==i?void 0:i.setHash,c=function(n){window.location.hash=n};"replaceState"===l&&(c=function(n){window.history.replaceState(window.history.state,"",""+window.location.pathname+window.location.search+"#"+n)}),"function"==typeof l&&(c=l);var s=t.atom(null);s.onMount=function(t){if("undefined"!=typeof window&&window.location){var o=function(){var o=new URLSearchParams(window.location.hash.slice(1)).get(n);t(o)},e=u(o);return o(),e}};var d=t.atom(function(n){var t=n(s);return null===t?e:r(t)});return t.atom(function(n){return n(d)},function(t,e,i){var r="function"==typeof i?i(t(d)):i,u=new URLSearchParams(window.location.hash.slice(1));if(r===o.RESET)e(s,null),u.delete(n);else{var l=a(r);e(s,l),u.set(n,l)}c(u.toString())})},n.atomWithLocation=function(n){var o,r=(null==n?void 0:n.getLocation)||e,u=(null==n?void 0:n.applyLocation)||i,l=(null==n?void 0:n.subscribe)||a,c=t.atom(null!=(o=null==n?void 0:n.preloaded)?o:r());return"production"!==process.env.NODE_ENV&&(c.debugPrivate=!0),c.onMount=function(n){var t=function(){return n(r())},o=l(t);return t(),o},t.atom(function(n){return n(c)},function(t,o,e){o(c,e),u(t(c),n)})}}); | ||
!function(n,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("jotai/vanilla"),require("jotai/vanilla/utils")):"function"==typeof define&&define.amd?define(["exports","jotai/vanilla","jotai/vanilla/utils"],t):t((n||self).jotaiLocation={},n.vanilla,n.utils)}(this,function(n,t,o){function e(){return e=Object.assign?Object.assign.bind():function(n){for(var t=1;t<arguments.length;t++){var o=arguments[t];for(var e in o)Object.prototype.hasOwnProperty.call(o,e)&&(n[e]=o[e])}return n},e.apply(this,arguments)}var i=function(){return"undefined"!=typeof window&&window.location?{pathname:window.location.pathname,searchParams:new URLSearchParams(window.location.search)}:{}},a=function(n,t){var o=new URL(window.location.href);n.pathname&&(o.pathname=n.pathname),n.searchParams&&(o.search=n.searchParams.toString()),null!=t&&t.replace?window.history.replaceState(null,"",o):window.history.pushState(null,"",o)},r=function(n){return window.addEventListener("popstate",n),function(){return window.removeEventListener("popstate",n)}};n.atomWithHash=function(n,e,i){var a=(null==i?void 0:i.serialize)||JSON.stringify,r=(null==i?void 0:i.deserialize)||function(n){return function(t){try{return JSON.parse(t)}catch(t){return n}}}(e),u=(null==i?void 0:i.subscribe)||function(n){return window.addEventListener("hashchange",n),function(){window.removeEventListener("hashchange",n)}},l=null==i?void 0:i.setHash,c=function(n){window.location.hash=n};"replaceState"===l&&(c=function(n){window.history.replaceState(window.history.state,"",""+window.location.pathname+window.location.search+"#"+n)}),"function"==typeof l&&(c=l);var s=t.atom(null);s.onMount=function(t){if("undefined"!=typeof window&&window.location){var o=function(){var o=new URLSearchParams(window.location.hash.slice(1)).get(n);t(o)},e=u(o);return o(),e}};var d=t.atom(function(n){var t=n(s);return null===t?e:r(t)});return t.atom(function(n){return n(d)},function(t,e,i){var r="function"==typeof i?i(t(d)):i,u=new URLSearchParams(window.location.hash.slice(1));if(r===o.RESET)e(s,null),u.delete(n);else{var l=a(r);e(s,l),u.set(n,l)}c(u.toString())})},n.atomWithLocation=function(n){var o,u=(null==n?void 0:n.getLocation)||i,l=(null==n?void 0:n.applyLocation)||a,c=(null==n?void 0:n.subscribe)||r,s=t.atom(null!=(o=null==n?void 0:n.preloaded)?o:u());return"production"!==process.env.NODE_ENV&&(s.debugPrivate=!0),s.onMount=function(n){var t=function(){return n(u())},o=c(t);return t(),o},t.atom(function(n){return n(s)},function(t,o,i,a){void 0===a&&(a={}),o(s,i),l(t(s),e({},n,a))})}}); | ||
//# sourceMappingURL=index.umd.js.map |
@@ -1,2 +0,2 @@ | ||
import type { PrimitiveAtom } from 'jotai/vanilla'; | ||
import type { SetStateAction, WritableAtom } from 'jotai/vanilla'; | ||
type Location = { | ||
@@ -16,4 +16,8 @@ pathname?: string; | ||
type RequiredOptions<T> = Omit<Options<T>, 'getLocation' | 'applyLocation'> & Required<Pick<Options<T>, 'getLocation' | 'applyLocation'>>; | ||
export declare function atomWithLocation(options?: Options<Location>): PrimitiveAtom<Location>; | ||
export declare function atomWithLocation<T>(options: RequiredOptions<T>): PrimitiveAtom<T>; | ||
type AtomOptions<T> = Pick<Options<T>, 'replace'>; | ||
export declare function atomWithLocation(options?: Options<Location>): WritableAtom<Location, [ | ||
SetStateAction<Location>, | ||
AtomOptions<Location>? | ||
], void>; | ||
export declare function atomWithLocation<T>(options: RequiredOptions<T>): WritableAtom<T, [SetStateAction<T>, AtomOptions<T>?], void>; | ||
export {}; |
{ | ||
"name": "jotai-location", | ||
"description": "👻🔗", | ||
"version": "0.5.2", | ||
"version": "0.5.3", | ||
"author": "Daishi Kato", | ||
@@ -37,3 +37,4 @@ "repository": { | ||
"examples:02_typescript": "DIR=02_typescript EXT=tsx webpack serve", | ||
"examples:03_hash": "DIR=03_hash EXT=tsx webpack serve" | ||
"examples:03_hash": "DIR=03_hash EXT=tsx webpack serve", | ||
"examples:04_react_router": "DIR=04_react_router EXT=tsx webpack serve" | ||
}, | ||
@@ -51,34 +52,36 @@ "jest": { | ||
"devDependencies": { | ||
"@testing-library/dom": "^9.3.3", | ||
"@testing-library/react": "^14.0.0", | ||
"@testing-library/user-event": "^14.5.1", | ||
"@types/jest": "^29.5.5", | ||
"@types/node": "^20.8.6", | ||
"@types/react": "^18.2.28", | ||
"@types/react-dom": "^18.2.13", | ||
"@typescript-eslint/eslint-plugin": "^6.7.5", | ||
"@typescript-eslint/parser": "^6.7.5", | ||
"eslint": "^8.51.0", | ||
"@testing-library/dom": "^9.3.4", | ||
"@testing-library/react": "^14.2.1", | ||
"@testing-library/user-event": "^14.5.2", | ||
"@types/jest": "^29.5.12", | ||
"@types/node": "^20.11.19", | ||
"@types/react": "^18.2.56", | ||
"@types/react-dom": "^18.2.19", | ||
"@typescript-eslint/eslint-plugin": "^7.0.1", | ||
"@typescript-eslint/parser": "^7.0.1", | ||
"eslint": "^8.56.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-prettier": "^9.0.0", | ||
"eslint-plugin-import": "^2.28.1", | ||
"eslint-plugin-jsx-a11y": "^6.7.1", | ||
"eslint-plugin-prettier": "^5.0.1", | ||
"eslint-config-prettier": "^9.1.0", | ||
"eslint-plugin-import": "^2.29.1", | ||
"eslint-plugin-jsx-a11y": "^6.8.0", | ||
"eslint-plugin-prettier": "^5.1.3", | ||
"eslint-plugin-react": "^7.33.2", | ||
"html-webpack-plugin": "^5.5.3", | ||
"history": "5.3.0", | ||
"html-webpack-plugin": "^5.6.0", | ||
"jest": "^29.7.0", | ||
"jest-environment-jsdom": "^29.7.0", | ||
"jotai": "^2.4.3", | ||
"jotai": "^2.6.4", | ||
"microbundle": "^0.15.1", | ||
"npm-run-all": "^4.1.5", | ||
"prettier": "^3.0.3", | ||
"prettier": "^3.2.5", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"react-error-boundary": "^4.0.11", | ||
"ts-jest": "^29.1.1", | ||
"ts-loader": "^9.5.0", | ||
"typescript": "^5.2.2", | ||
"webpack": "^5.89.0", | ||
"react-error-boundary": "^4.0.12", | ||
"react-router-dom": "6.22.1", | ||
"ts-jest": "^29.1.2", | ||
"ts-loader": "^9.5.1", | ||
"typescript": "^5.3.3", | ||
"webpack": "^5.90.2", | ||
"webpack-cli": "^5.1.4", | ||
"webpack-dev-server": "^4.15.1" | ||
"webpack-dev-server": "^5.0.2" | ||
}, | ||
@@ -85,0 +88,0 @@ "peerDependencies": { |
import { atom } from 'jotai/vanilla'; | ||
import type { PrimitiveAtom, SetStateAction } from 'jotai/vanilla'; | ||
import type { SetStateAction, WritableAtom } from 'jotai/vanilla'; | ||
@@ -53,9 +53,15 @@ type Location = { | ||
type AtomOptions<T> = Pick<Options<T>, 'replace'>; | ||
export function atomWithLocation( | ||
options?: Options<Location>, | ||
): PrimitiveAtom<Location>; | ||
): WritableAtom< | ||
Location, | ||
[SetStateAction<Location>, AtomOptions<Location>?], | ||
void | ||
>; | ||
export function atomWithLocation<T>( | ||
options: RequiredOptions<T>, | ||
): PrimitiveAtom<T>; | ||
): WritableAtom<T, [SetStateAction<T>, AtomOptions<T>?], void>; | ||
@@ -84,5 +90,5 @@ export function atomWithLocation<T>(options?: Options<T>) { | ||
(get) => get(baseAtom), | ||
(get, set, arg: SetStateAction<T>) => { | ||
(get, set, arg: SetStateAction<T>, atomOptions: AtomOptions<T> = {}) => { | ||
set(baseAtom, arg); | ||
appL(get(baseAtom), options); | ||
appL(get(baseAtom), { ...options, ...atomOptions }); | ||
}, | ||
@@ -89,0 +95,0 @@ ); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
43953
238
34