@sonic-equipment/ui 223.0.0 → 225.0.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.
Files changed (27) hide show
  1. package/dist/buttons/reorder-button/connected-reorder-button.js +1 -0
  2. package/dist/buttons/reorder-button/reorder-button.js +1 -0
  3. package/dist/country-select/hooks/use-countries.js +1 -1
  4. package/dist/country-selector/use-countries-languages.js +1 -1
  5. package/dist/exports.d.ts +7 -1
  6. package/dist/index.d.ts +0 -1
  7. package/dist/index.js +6 -2
  8. package/dist/notifications/announcements/connected-announcement-list.js +1 -1
  9. package/dist/pages/my-sonic/pages/order-details/order-details-content.js +1 -0
  10. package/dist/shared/api/bff/hooks/use-fetch-favorites.js +1 -0
  11. package/dist/shared/local-storage/local-storage-context.d.ts +2 -0
  12. package/dist/shared/local-storage/local-storage-context.js +6 -0
  13. package/dist/shared/local-storage/local-storage-provider.d.ts +5 -0
  14. package/dist/shared/local-storage/local-storage-provider.js +14 -0
  15. package/dist/shared/local-storage/storage-mock.d.ts +10 -0
  16. package/dist/shared/local-storage/storage-mock.js +34 -0
  17. package/dist/shared/local-storage/types.d.ts +4 -0
  18. package/dist/shared/{hooks → local-storage}/use-local-storage.js +5 -1
  19. package/dist/shared/{hooks → local-storage}/use-session-storage.js +5 -1
  20. package/dist/shared/utils/url.d.ts +5 -0
  21. package/dist/shared/utils/url.js +20 -0
  22. package/dist/text/status-text/status-text.js +1 -0
  23. package/package.json +1 -1
  24. package/dist/shared/utils/local-storage.js +0 -107
  25. /package/dist/shared/{hooks → local-storage}/use-local-storage.d.ts +0 -0
  26. /package/dist/shared/{hooks → local-storage}/use-session-storage.d.ts +0 -0
  27. /package/dist/shared/utils/{local-storage.d.ts → url.test.d.ts} +0 -0
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { jsx } from 'react/jsx-runtime';
2
3
  import { useFormattedMessage } from '../../intl/use-formatted-message.js';
3
4
  import { useAddBulkProductsToCurrentCart } from '../../shared/api/storefront/hooks/cart/use-add-bulk-products-to-current-cart.js';
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { jsx } from 'react/jsx-runtime';
2
3
  import { FormattedMessage } from '../../intl/formatted-message.js';
3
4
  import { useFormattedMessage } from '../../intl/use-formatted-message.js';
@@ -3,7 +3,7 @@ import { useMemo } from 'react';
3
3
  import { useCookie } from '../../cookies/use-cookie.js';
4
4
  import { isCountryCode, isCultureCode, isLanguageCode } from '../../intl/types.js';
5
5
  import { useFetchCountriesWithLanguages } from '../../shared/api/storefront/hooks/website/use-fetch-countries-with-languages.js';
6
- import { useSessionStorage } from '../../shared/hooks/use-session-storage.js';
6
+ import { useSessionStorage } from '../../shared/local-storage/use-session-storage.js';
7
7
 
8
8
  function useCountries({ enabled = true, } = {}) {
9
9
  const [sessionCountries, setSessionCountries] = useSessionStorage('countries-v1');
@@ -3,7 +3,7 @@ import { useEffect } from 'react';
3
3
  import { useCookie } from '../cookies/use-cookie.js';
4
4
  import { useFetchCountriesWithLanguages } from '../shared/api/storefront/hooks/website/use-fetch-countries-with-languages.js';
5
5
  import { updateLocale } from '../shared/api/storefront/services/website-service.js';
6
- import { useSessionStorage } from '../shared/hooks/use-session-storage.js';
6
+ import { useSessionStorage } from '../shared/local-storage/use-session-storage.js';
7
7
  import { isCountry } from '../shared/model/countries-languages.js';
8
8
 
9
9
  function useCountriesLanguages({ defaultCountryCode, defaultLanguageCode, }) {
package/dist/exports.d.ts CHANGED
@@ -414,8 +414,13 @@ export * from './shared/hooks/use-mutation-observer';
414
414
  export * from './shared/hooks/use-resize-observer';
415
415
  export * from './shared/hooks/use-script';
416
416
  export * from './shared/hooks/use-scroll-lock';
417
- export * from './shared/hooks/use-session-storage';
418
417
  export * from './shared/hooks/use-watch-css-property';
418
+ export * from './shared/local-storage/local-storage-context';
419
+ export * from './shared/local-storage/local-storage-provider';
420
+ export * from './shared/local-storage/storage-mock';
421
+ export * from './shared/local-storage/types';
422
+ export * from './shared/local-storage/use-local-storage';
423
+ export * from './shared/local-storage/use-session-storage';
419
424
  export * from './shared/model/account';
420
425
  export * from './shared/model/address';
421
426
  export * from './shared/model/announcement';
@@ -461,6 +466,7 @@ export * from './shared/utils/scrolling';
461
466
  export * from './shared/utils/string';
462
467
  export * from './shared/utils/time';
463
468
  export * from './shared/utils/types';
469
+ export * from './shared/utils/url';
464
470
  export * from './shared/utils/uuid';
465
471
  export * from './sidebar/sidebar';
466
472
  export * from './sidebar/sidebar-provider';
package/dist/index.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import './shared/utils/local-storage';
2
1
  import './tokens/index.css';
3
2
  export * as BffModel from './shared/api/bff/model/bff.model';
4
3
  export * as StorefrontModel from './shared/api/storefront/model/storefront.model';
package/dist/index.js CHANGED
@@ -1,4 +1,3 @@
1
- import './shared/utils/local-storage.js';
2
1
  import * as bff_model from './shared/api/bff/model/bff.model.js';
3
2
  export { bff_model as BffModel };
4
3
  import * as storefront_model from './shared/api/storefront/model/storefront.model.js';
@@ -415,8 +414,12 @@ export { useMutationObserver } from './shared/hooks/use-mutation-observer.js';
415
414
  export { useResizeObserver } from './shared/hooks/use-resize-observer.js';
416
415
  export { useScript } from './shared/hooks/use-script.js';
417
416
  export { useScrollLock } from './shared/hooks/use-scroll-lock.js';
418
- export { useSessionStorage } from './shared/hooks/use-session-storage.js';
419
417
  export { useWatchCssProperty } from './shared/hooks/use-watch-css-property.js';
418
+ export { LocalStorageContext } from './shared/local-storage/local-storage-context.js';
419
+ export { LocalStorageProvider } from './shared/local-storage/local-storage-provider.js';
420
+ export { MockStorage } from './shared/local-storage/storage-mock.js';
421
+ export { useLocalStorage } from './shared/local-storage/use-local-storage.js';
422
+ export { useSessionStorage } from './shared/local-storage/use-session-storage.js';
420
423
  export { validatePassword } from './shared/model/account.js';
421
424
  export { validateEmail, validatePhone } from './shared/model/address.js';
422
425
  export { announcementSubTypes, announcementTypes, isAnnouncementSubtype, isAnnouncementType } from './shared/model/announcement.js';
@@ -460,6 +463,7 @@ export { scrollIntoViewRef, scrollToTop } from './shared/utils/scrolling.js';
460
463
  export { camelCase } from './shared/utils/string.js';
461
464
  export { TIME } from './shared/utils/time.js';
462
465
  export { has, hasNo, isObject } from './shared/utils/types.js';
466
+ export { join } from './shared/utils/url.js';
463
467
  export { createUUID, isUUID } from './shared/utils/uuid.js';
464
468
  export { Sidebar } from './sidebar/sidebar.js';
465
469
  export { SidebarDetectBreakpoint, SidebarProvider } from './sidebar/sidebar-provider.js';
@@ -3,7 +3,7 @@ import { jsx } from 'react/jsx-runtime';
3
3
  import { useCultureCode } from '../../intl/use-culture-code.js';
4
4
  import { useLogError } from '../../logging/use-log-error.js';
5
5
  import { useFetchAnnouncements } from '../../shared/api/bff/hooks/use-fetch-announcements.js';
6
- import { useLocalStorage } from '../../shared/hooks/use-local-storage.js';
6
+ import { useLocalStorage } from '../../shared/local-storage/use-local-storage.js';
7
7
  import { AnnouncementList } from './announcement-list.js';
8
8
 
9
9
  function ConnectedAnnouncementList({ className, }) {
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { jsxs, jsx } from 'react/jsx-runtime';
2
3
  import { Button } from '../../../../buttons/button/button.js';
3
4
  import { PrintButton } from '../../../../buttons/print-button/print-button.js';
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useQuery } from '@tanstack/react-query';
2
3
  import { useAlgoliaSearch } from '../../../../algolia/use-algolia-search.js';
3
4
  import { transformAlgoliaProductHitToProductHit } from '../../../model/hit.js';
@@ -0,0 +1,2 @@
1
+ import { LocalStorageContextValue } from './types';
2
+ export declare const LocalStorageContext: React.Context<LocalStorageContextValue | undefined>;
@@ -0,0 +1,6 @@
1
+ "use client";
2
+ import { createContext } from 'react';
3
+
4
+ const LocalStorageContext = createContext(undefined);
5
+
6
+ export { LocalStorageContext };
@@ -0,0 +1,5 @@
1
+ export declare function LocalStorageProvider({ children, localStorage, sessionStorage, }: {
2
+ children: React.ReactNode;
3
+ localStorage: Storage;
4
+ sessionStorage: Storage;
5
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { useMemo } from 'react';
4
+ import { LocalStorageContext } from './local-storage-context.js';
5
+
6
+ function LocalStorageProvider({ children, localStorage, sessionStorage, }) {
7
+ const value = useMemo(() => ({
8
+ localStorage,
9
+ sessionStorage,
10
+ }), [localStorage, sessionStorage]);
11
+ return (jsx(LocalStorageContext.Provider, { value: value, children: children }));
12
+ }
13
+
14
+ export { LocalStorageProvider };
@@ -0,0 +1,10 @@
1
+ export declare class MockStorage implements Storage {
2
+ private _state;
3
+ constructor();
4
+ get length(): number;
5
+ clear(): void;
6
+ getItem(key: string): string | null;
7
+ key(index: number): string | null;
8
+ removeItem(key: string): void;
9
+ setItem(key: string, value: string): void;
10
+ }
@@ -0,0 +1,34 @@
1
+ class MockStorage {
2
+ constructor() {
3
+ Object.defineProperty(this, "_state", {
4
+ enumerable: true,
5
+ configurable: true,
6
+ writable: true,
7
+ value: {}
8
+ });
9
+ }
10
+ get length() {
11
+ return Object.keys(this._state).length;
12
+ }
13
+ clear() {
14
+ this._state = {};
15
+ }
16
+ getItem(key) {
17
+ return Object.prototype.hasOwnProperty.call(this._state, key)
18
+ ? this._state[key] || null
19
+ : null;
20
+ }
21
+ key(index) {
22
+ const keys = Object.keys(this._state);
23
+ return index >= 0 && index < keys.length ? keys[index] || null : null;
24
+ }
25
+ removeItem(key) {
26
+ if (Object.prototype.hasOwnProperty.call(this._state, key))
27
+ delete this._state[key];
28
+ }
29
+ setItem(key, value) {
30
+ this._state[key] = value;
31
+ }
32
+ }
33
+
34
+ export { MockStorage };
@@ -0,0 +1,4 @@
1
+ export interface LocalStorageContextValue {
2
+ localStorage: Storage;
3
+ sessionStorage: Storage;
4
+ }
@@ -1,7 +1,11 @@
1
1
  "use client";
2
- import { useState } from 'react';
2
+ import { useContext, useState } from 'react';
3
+ import { LocalStorageContext } from './local-storage-context.js';
3
4
 
4
5
  function useLocalStorage(key, initialState) {
6
+ const { localStorage } = useContext(LocalStorageContext) ?? {
7
+ localStorage: typeof window === 'undefined' ? undefined : window.localStorage,
8
+ };
5
9
  const storedValue = localStorage?.getItem(key);
6
10
  const [internalValue, setInternalValue] = useState(storedValue ? JSON.parse(storedValue) : initialState);
7
11
  function setValue(value) {
@@ -1,7 +1,11 @@
1
1
  "use client";
2
- import { useState } from 'react';
2
+ import { useContext, useState } from 'react';
3
+ import { LocalStorageContext } from './local-storage-context.js';
3
4
 
4
5
  function useSessionStorage(key, initialState) {
6
+ const { sessionStorage } = useContext(LocalStorageContext) ?? {
7
+ sessionStorage: typeof window === 'undefined' ? undefined : window.sessionStorage,
8
+ };
5
9
  const storedValue = sessionStorage?.getItem(key);
6
10
  const [internalValue, setInternalValue] = useState(storedValue ? JSON.parse(storedValue) : initialState);
7
11
  function setValue(value) {
@@ -0,0 +1,5 @@
1
+ export declare function join(..._paths: string[]): string;
2
+ declare const _default: {
3
+ join: typeof join;
4
+ };
5
+ export default _default;
@@ -0,0 +1,20 @@
1
+ function join(..._paths) {
2
+ const paths = _paths.map(path => path.trim()).filter(Boolean);
3
+ let result = '';
4
+ for (const path of paths) {
5
+ if (result) {
6
+ result += `${result.endsWith('/') ? '' : '/'}${path.replaceAll(/^\/+|\/+$/g, '')}`;
7
+ }
8
+ else {
9
+ result =
10
+ path.length > 1 && path.endsWith('/')
11
+ ? path.replaceAll(/\/+$/g, '')
12
+ : path;
13
+ }
14
+ }
15
+ if (paths.at(-1)?.endsWith('/') && !result.endsWith('/'))
16
+ result += '/';
17
+ return result;
18
+ }
19
+
20
+ export { join };
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { jsx } from 'react/jsx-runtime';
2
3
  import styles from './status-text.module.css.js';
3
4
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sonic-equipment/ui",
3
- "version": "223.0.0",
3
+ "version": "225.0.0",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "engines": {
@@ -1,107 +0,0 @@
1
- "use client";
2
- import { voidFunction } from '../model/defaults.js';
3
-
4
- /** Mocks the localStorage and sessionStorage API in Node.js
5
- * @see https://gitlab.com/kaictl/node/mock-local-storage */
6
- const HAS_LOCAL_STORAGE_SUPPORT = typeof localStorage !== 'undefined';
7
- function mockStorage() {
8
- if (HAS_LOCAL_STORAGE_SUPPORT)
9
- return;
10
- // const global = require('global')
11
- // const window = require('global/window')
12
- let win;
13
- if (typeof global !== 'undefined') {
14
- win = global;
15
- }
16
- else if (typeof self === 'undefined') {
17
- win = {};
18
- }
19
- else {
20
- win = self;
21
- }
22
- Object.defineProperty(global, 'Storage', {
23
- value: createStorage,
24
- });
25
- Object.defineProperty(win, 'Storage', {
26
- value: createStorage,
27
- });
28
- Object.defineProperty(global, 'localStorage', {
29
- value: createStorage(),
30
- });
31
- Object.defineProperty(win, 'localStorage', {
32
- value: global.localStorage,
33
- });
34
- Object.defineProperty(global, 'sessionStorage', {
35
- value: createStorage(),
36
- });
37
- Object.defineProperty(win, 'sessionStorage', {
38
- value: global.sessionStorage,
39
- });
40
- }
41
- function createStorage() {
42
- const UNSET = Symbol();
43
- const s = {};
44
- let _itemInsertionCallback = voidFunction;
45
- Object.defineProperty(s, 'setItem', {
46
- get: () => {
47
- return (k, v = UNSET) => {
48
- if (v === UNSET) {
49
- throw new TypeError(`Failed to execute 'setItem' on 'Storage': 2 arguments required, but only 1 present.`);
50
- }
51
- if (!s.hasOwnProperty(String(k))) {
52
- _itemInsertionCallback();
53
- }
54
- s[String(k)] = String(v);
55
- };
56
- },
57
- });
58
- Object.defineProperty(s, 'getItem', {
59
- get: () => {
60
- return (k) => {
61
- return s.hasOwnProperty(String(k)) ? s[String(k)] : null;
62
- };
63
- },
64
- });
65
- Object.defineProperty(s, 'removeItem', {
66
- get: () => {
67
- return (k) => {
68
- if (s.hasOwnProperty(String(k))) {
69
- delete s[String(k)];
70
- }
71
- };
72
- },
73
- });
74
- Object.defineProperty(s, 'clear', {
75
- get: () => {
76
- return () => {
77
- for (const k in s) {
78
- delete s[String(k)];
79
- }
80
- };
81
- },
82
- });
83
- Object.defineProperty(s, 'length', {
84
- get: () => {
85
- return Object.keys(s).length;
86
- },
87
- });
88
- Object.defineProperty(s, 'key', {
89
- value: (k) => {
90
- return Object.keys(s)[k] || null;
91
- },
92
- });
93
- Object.defineProperty(s, 'itemInsertionCallback', {
94
- get: () => {
95
- return _itemInsertionCallback;
96
- },
97
- set: v => {
98
- if (!v || typeof v != 'function') {
99
- v = voidFunction;
100
- }
101
- _itemInsertionCallback = v;
102
- },
103
- });
104
- return s;
105
- }
106
- // Mock localStorage
107
- mockStorage();