@elementor/session 3.32.0-75 → 3.32.0-76
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/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +3 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/use-session-storage.ts +3 -2
package/dist/index.d.mts
CHANGED
|
@@ -5,7 +5,7 @@ declare const getSessionStorageItem: <T>(key: string) => T | undefined;
|
|
|
5
5
|
declare const setSessionStorageItem: (key: string, item: unknown) => void;
|
|
6
6
|
declare const removeSessionStorageItem: (key: string) => void;
|
|
7
7
|
|
|
8
|
-
declare const useSessionStorage: <T>(key: string) => readonly [T | null | undefined, (newValue: T) => void, () => void];
|
|
8
|
+
declare const useSessionStorage: <T>(key: string, customPrefix?: string) => readonly [T | null | undefined, (newValue: T) => void, () => void];
|
|
9
9
|
|
|
10
10
|
type ContextValue = {
|
|
11
11
|
prefix: string;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ declare const getSessionStorageItem: <T>(key: string) => T | undefined;
|
|
|
5
5
|
declare const setSessionStorageItem: (key: string, item: unknown) => void;
|
|
6
6
|
declare const removeSessionStorageItem: (key: string) => void;
|
|
7
7
|
|
|
8
|
-
declare const useSessionStorage: <T>(key: string) => readonly [T | null | undefined, (newValue: T) => void, () => void];
|
|
8
|
+
declare const useSessionStorage: <T>(key: string, customPrefix?: string) => readonly [T | null | undefined, (newValue: T) => void, () => void];
|
|
9
9
|
|
|
10
10
|
type ContextValue = {
|
|
11
11
|
prefix: string;
|
package/dist/index.js
CHANGED
|
@@ -76,8 +76,9 @@ function SessionStorageProvider({ children, prefix }) {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
// src/use-session-storage.ts
|
|
79
|
-
var useSessionStorage = (key) => {
|
|
80
|
-
const
|
|
79
|
+
var useSessionStorage = (key, customPrefix) => {
|
|
80
|
+
const contextPrefix = (0, import_react2.useContext)(Context)?.prefix ?? "";
|
|
81
|
+
const prefix = customPrefix ? customPrefix : contextPrefix;
|
|
81
82
|
const prefixedKey = `${prefix}/${key}`;
|
|
82
83
|
const [value, setValue] = (0, import_react2.useState)();
|
|
83
84
|
(0, import_react2.useEffect)(() => {
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/session-storage.ts","../src/use-session-storage.ts","../src/session-storage-context.tsx"],"sourcesContent":["export * from './session-storage';\nexport * from './use-session-storage';\nexport * from './session-storage-context';\n","export const getSessionStorageItem = < T >( key: string ): T | undefined => {\n\treturn JSON.parse( sessionStorage.getItem( key ) || '{}' )?.item;\n};\n\nexport const setSessionStorageItem = ( key: string, item: unknown ) => {\n\tsessionStorage.setItem( key, JSON.stringify( { item } ) );\n\n\t// The browser doesn't dispatch the `storage` event for the current tab,\n\t// so we need to dispatch it manually.\n\t//\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event\n\twindow.dispatchEvent(\n\t\tnew StorageEvent( 'storage', {\n\t\t\tkey,\n\t\t\tstorageArea: sessionStorage,\n\t\t} )\n\t);\n};\n\nexport const removeSessionStorageItem = ( key: string ) => {\n\tsessionStorage.removeItem( key );\n\n\t// The browser doesn't dispatch the `storage` event for the current tab,\n\t// so we need to dispatch it manually.\n\t//\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event\n\twindow.dispatchEvent(\n\t\tnew StorageEvent( 'storage', {\n\t\t\tkey,\n\t\t\tstorageArea: sessionStorage,\n\t\t} )\n\t);\n};\n","import { useContext, useEffect, useState } from 'react';\n\nimport { getSessionStorageItem, removeSessionStorageItem, setSessionStorageItem } from './session-storage';\nimport { Context } from './session-storage-context';\n\nexport const useSessionStorage = < T >( key: string ) => {\n\tconst
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/session-storage.ts","../src/use-session-storage.ts","../src/session-storage-context.tsx"],"sourcesContent":["export * from './session-storage';\nexport * from './use-session-storage';\nexport * from './session-storage-context';\n","export const getSessionStorageItem = < T >( key: string ): T | undefined => {\n\treturn JSON.parse( sessionStorage.getItem( key ) || '{}' )?.item;\n};\n\nexport const setSessionStorageItem = ( key: string, item: unknown ) => {\n\tsessionStorage.setItem( key, JSON.stringify( { item } ) );\n\n\t// The browser doesn't dispatch the `storage` event for the current tab,\n\t// so we need to dispatch it manually.\n\t//\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event\n\twindow.dispatchEvent(\n\t\tnew StorageEvent( 'storage', {\n\t\t\tkey,\n\t\t\tstorageArea: sessionStorage,\n\t\t} )\n\t);\n};\n\nexport const removeSessionStorageItem = ( key: string ) => {\n\tsessionStorage.removeItem( key );\n\n\t// The browser doesn't dispatch the `storage` event for the current tab,\n\t// so we need to dispatch it manually.\n\t//\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event\n\twindow.dispatchEvent(\n\t\tnew StorageEvent( 'storage', {\n\t\t\tkey,\n\t\t\tstorageArea: sessionStorage,\n\t\t} )\n\t);\n};\n","import { useContext, useEffect, useState } from 'react';\n\nimport { getSessionStorageItem, removeSessionStorageItem, setSessionStorageItem } from './session-storage';\nimport { Context } from './session-storage-context';\n\nexport const useSessionStorage = < T >( key: string, customPrefix?: string ) => {\n\tconst contextPrefix = useContext( Context )?.prefix ?? '';\n\tconst prefix = customPrefix ? customPrefix : contextPrefix;\n\tconst prefixedKey = `${ prefix }/${ key }`;\n\n\tconst [ value, setValue ] = useState< T | null >();\n\n\tuseEffect( () => {\n\t\treturn subscribeToSessionStorage< T | null >( prefixedKey, ( newValue ) => {\n\t\t\tsetValue( newValue ?? null );\n\t\t} );\n\t}, [ prefixedKey ] );\n\n\tconst saveValue = ( newValue: T ) => {\n\t\tsetSessionStorageItem( prefixedKey, newValue );\n\t};\n\n\tconst removeValue = () => {\n\t\tremoveSessionStorageItem( prefixedKey );\n\t};\n\n\treturn [ value, saveValue, removeValue ] as const;\n};\n\nconst subscribeToSessionStorage = < T >( key: string, subscriber: ( value: T ) => void ) => {\n\tsubscriber( getSessionStorageItem( key ) as T );\n\n\tconst abortController = new AbortController();\n\n\twindow.addEventListener(\n\t\t'storage',\n\t\t( e ) => {\n\t\t\tif ( e.key !== key || e.storageArea !== sessionStorage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsubscriber( getSessionStorageItem( key ) as T );\n\t\t},\n\t\t{ signal: abortController.signal }\n\t);\n\n\treturn () => {\n\t\tabortController.abort();\n\t};\n};\n","import * as React from 'react';\nimport { createContext, type PropsWithChildren, useContext } from 'react';\n\ntype ContextValue = {\n\tprefix: string;\n};\n\nexport const Context = createContext< ContextValue | null >( null );\n\ntype Props = PropsWithChildren< ContextValue >;\n\nexport function SessionStorageProvider( { children, prefix }: Props ) {\n\tconst contextPrefix = useContext( Context )?.prefix ?? '';\n\tconst chainedPrefix = contextPrefix ? `${ contextPrefix }/${ prefix }` : prefix;\n\n\treturn <Context.Provider value={ { prefix: chainedPrefix } }>{ children }</Context.Provider>;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAO,IAAM,wBAAwB,CAAO,QAAgC;AAC3E,SAAO,KAAK,MAAO,eAAe,QAAS,GAAI,KAAK,IAAK,GAAG;AAC7D;AAEO,IAAM,wBAAwB,CAAE,KAAa,SAAmB;AACtE,iBAAe,QAAS,KAAK,KAAK,UAAW,EAAE,KAAK,CAAE,CAAE;AAMxD,SAAO;AAAA,IACN,IAAI,aAAc,WAAW;AAAA,MAC5B;AAAA,MACA,aAAa;AAAA,IACd,CAAE;AAAA,EACH;AACD;AAEO,IAAM,2BAA2B,CAAE,QAAiB;AAC1D,iBAAe,WAAY,GAAI;AAM/B,SAAO;AAAA,IACN,IAAI,aAAc,WAAW;AAAA,MAC5B;AAAA,M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Z,oBAAgB,MAAM;AAAA,EACvB;AACD;","names":["import_react"]}
|
package/dist/index.mjs
CHANGED
|
@@ -35,8 +35,9 @@ function SessionStorageProvider({ children, prefix }) {
|
|
|
35
35
|
}
|
|
36
36
|
|
|
37
37
|
// src/use-session-storage.ts
|
|
38
|
-
var useSessionStorage = (key) => {
|
|
39
|
-
const
|
|
38
|
+
var useSessionStorage = (key, customPrefix) => {
|
|
39
|
+
const contextPrefix = useContext2(Context)?.prefix ?? "";
|
|
40
|
+
const prefix = customPrefix ? customPrefix : contextPrefix;
|
|
40
41
|
const prefixedKey = `${prefix}/${key}`;
|
|
41
42
|
const [value, setValue] = useState();
|
|
42
43
|
useEffect(() => {
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/session-storage.ts","../src/use-session-storage.ts","../src/session-storage-context.tsx"],"sourcesContent":["export const getSessionStorageItem = < T >( key: string ): T | undefined => {\n\treturn JSON.parse( sessionStorage.getItem( key ) || '{}' )?.item;\n};\n\nexport const setSessionStorageItem = ( key: string, item: unknown ) => {\n\tsessionStorage.setItem( key, JSON.stringify( { item } ) );\n\n\t// The browser doesn't dispatch the `storage` event for the current tab,\n\t// so we need to dispatch it manually.\n\t//\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event\n\twindow.dispatchEvent(\n\t\tnew StorageEvent( 'storage', {\n\t\t\tkey,\n\t\t\tstorageArea: sessionStorage,\n\t\t} )\n\t);\n};\n\nexport const removeSessionStorageItem = ( key: string ) => {\n\tsessionStorage.removeItem( key );\n\n\t// The browser doesn't dispatch the `storage` event for the current tab,\n\t// so we need to dispatch it manually.\n\t//\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event\n\twindow.dispatchEvent(\n\t\tnew StorageEvent( 'storage', {\n\t\t\tkey,\n\t\t\tstorageArea: sessionStorage,\n\t\t} )\n\t);\n};\n","import { useContext, useEffect, useState } from 'react';\n\nimport { getSessionStorageItem, removeSessionStorageItem, setSessionStorageItem } from './session-storage';\nimport { Context } from './session-storage-context';\n\nexport const useSessionStorage = < T >( key: string ) => {\n\tconst
|
|
1
|
+
{"version":3,"sources":["../src/session-storage.ts","../src/use-session-storage.ts","../src/session-storage-context.tsx"],"sourcesContent":["export const getSessionStorageItem = < T >( key: string ): T | undefined => {\n\treturn JSON.parse( sessionStorage.getItem( key ) || '{}' )?.item;\n};\n\nexport const setSessionStorageItem = ( key: string, item: unknown ) => {\n\tsessionStorage.setItem( key, JSON.stringify( { item } ) );\n\n\t// The browser doesn't dispatch the `storage` event for the current tab,\n\t// so we need to dispatch it manually.\n\t//\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event\n\twindow.dispatchEvent(\n\t\tnew StorageEvent( 'storage', {\n\t\t\tkey,\n\t\t\tstorageArea: sessionStorage,\n\t\t} )\n\t);\n};\n\nexport const removeSessionStorageItem = ( key: string ) => {\n\tsessionStorage.removeItem( key );\n\n\t// The browser doesn't dispatch the `storage` event for the current tab,\n\t// so we need to dispatch it manually.\n\t//\n\t// https://developer.mozilla.org/en-US/docs/Web/API/Window/storage_event\n\twindow.dispatchEvent(\n\t\tnew StorageEvent( 'storage', {\n\t\t\tkey,\n\t\t\tstorageArea: sessionStorage,\n\t\t} )\n\t);\n};\n","import { useContext, useEffect, useState } from 'react';\n\nimport { getSessionStorageItem, removeSessionStorageItem, setSessionStorageItem } from './session-storage';\nimport { Context } from './session-storage-context';\n\nexport const useSessionStorage = < T >( key: string, customPrefix?: string ) => {\n\tconst contextPrefix = useContext( Context )?.prefix ?? '';\n\tconst prefix = customPrefix ? customPrefix : contextPrefix;\n\tconst prefixedKey = `${ prefix }/${ key }`;\n\n\tconst [ value, setValue ] = useState< T | null >();\n\n\tuseEffect( () => {\n\t\treturn subscribeToSessionStorage< T | null >( prefixedKey, ( newValue ) => {\n\t\t\tsetValue( newValue ?? null );\n\t\t} );\n\t}, [ prefixedKey ] );\n\n\tconst saveValue = ( newValue: T ) => {\n\t\tsetSessionStorageItem( prefixedKey, newValue );\n\t};\n\n\tconst removeValue = () => {\n\t\tremoveSessionStorageItem( prefixedKey );\n\t};\n\n\treturn [ value, saveValue, removeValue ] as const;\n};\n\nconst subscribeToSessionStorage = < T >( key: string, subscriber: ( value: T ) => void ) => {\n\tsubscriber( getSessionStorageItem( key ) as T );\n\n\tconst abortController = new AbortController();\n\n\twindow.addEventListener(\n\t\t'storage',\n\t\t( e ) => {\n\t\t\tif ( e.key !== key || e.storageArea !== sessionStorage ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tsubscriber( getSessionStorageItem( key ) as T );\n\t\t},\n\t\t{ signal: abortController.signal }\n\t);\n\n\treturn () => {\n\t\tabortController.abort();\n\t};\n};\n","import * as React from 'react';\nimport { createContext, type PropsWithChildren, useContext } from 'react';\n\ntype ContextValue = {\n\tprefix: string;\n};\n\nexport const Context = createContext< ContextValue | null >( null );\n\ntype Props = PropsWithChildren< ContextValue >;\n\nexport function SessionStorageProvider( { children, prefix }: Props ) {\n\tconst contextPrefix = useContext( Context )?.prefix ?? '';\n\tconst chainedPrefix = contextPrefix ? `${ contextPrefix }/${ prefix }` : prefix;\n\n\treturn <Context.Provider value={ { prefix: chainedPrefix } }>{ children }</Context.Provider>;\n}\n"],"mappings":";AAAO,IAAM,wBAAwB,CAAO,QAAgC;AAC3E,SAAO,KAAK,MAAO,eAAe,QAAS,GAAI,KAAK,IAAK,GAAG;AAC7D;AAEO,IAAM,wBAAwB,CAAE,KAAa,SAAmB;AACtE,iBAAe,QAAS,KAAK,KAAK,UAAW,EAAE,KAAK,CAAE,CAAE;AAMxD,SAAO;AAAA,IACN,IAAI,aAAc,WAAW;AAAA,MAC5B;AAAA,MACA,aAAa;AAAA,IACd,CAAE;AAAA,EACH;AACD;AAEO,IAAM,2BAA2B,CAAE,QAAiB;AAC1D,iBAAe,WAAY,GAAI;AAM/B,SAAO;AAAA,IACN,IAAI,aAAc,WAAW;AAAA,MAC5B;AAAA,MAC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AA,EAClC;AAEA,SAAO,MAAM;AACZ,oBAAgB,MAAM;AAAA,EACvB;AACD;","names":["useContext","useContext"]}
|
package/package.json
CHANGED
|
@@ -3,8 +3,9 @@ import { useContext, useEffect, useState } from 'react';
|
|
|
3
3
|
import { getSessionStorageItem, removeSessionStorageItem, setSessionStorageItem } from './session-storage';
|
|
4
4
|
import { Context } from './session-storage-context';
|
|
5
5
|
|
|
6
|
-
export const useSessionStorage = < T >( key: string ) => {
|
|
7
|
-
const
|
|
6
|
+
export const useSessionStorage = < T >( key: string, customPrefix?: string ) => {
|
|
7
|
+
const contextPrefix = useContext( Context )?.prefix ?? '';
|
|
8
|
+
const prefix = customPrefix ? customPrefix : contextPrefix;
|
|
8
9
|
const prefixedKey = `${ prefix }/${ key }`;
|
|
9
10
|
|
|
10
11
|
const [ value, setValue ] = useState< T | null >();
|