@gohanfromgoku/ui-kit 1.0.1 → 1.1.1

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.
@@ -9,8 +9,8 @@ const createBrowserRouter = (routes, { page404 } = { page404: () => _jsx(_Fragme
9
9
  const { hash, href, origin, pathname, port, protocol, search } = window.location;
10
10
  return { hash, href, origin, pathname, port, protocol, search };
11
11
  };
12
- const { locationDetails, useLocationDetailsState } = createStore("locationDetails", { params: {}, queryParams: {}, ...getLatestLocationDetails() });
13
- const { activeRoute, useActiveRouteState } = createStore("activeRoute", routes.find(r => isRouteMatching(r.pathname)) || { pathname: window.location.pathname, component: page404 });
12
+ const { locationDetails, useLocationDetailsStoreValues } = createStore("locationDetails", { params: {}, queryParams: {}, ...getLatestLocationDetails() });
13
+ const { activeRoute, useActiveRouteStoreValues } = createStore("activeRoute", routes.find(r => isRouteMatching(r.pathname)) || { pathname: window.location.pathname, component: page404 });
14
14
  const navigate = (to, { queryParams, replace } = {}) => {
15
15
  if (typeof to === "number") {
16
16
  window.history.go(to);
@@ -31,10 +31,10 @@ const createBrowserRouter = (routes, { page404 } = { page404: () => _jsx(_Fragme
31
31
  if (routes.length === 0) {
32
32
  throw new Error("useLocationDetails cannot be used without initializing routes. Use createBrowserRouter with routes.");
33
33
  }
34
- return useLocationDetailsState();
34
+ return useLocationDetailsStoreValues();
35
35
  };
36
36
  const Outlet = () => {
37
- const { component } = useActiveRouteState();
37
+ const { component } = useActiveRouteStoreValues();
38
38
  useEffect(() => {
39
39
  const updateLocation = () => {
40
40
  const active = routes.find(r => isRouteMatching(r.pathname)) || { pathname: window.location.pathname, component: page404 };
@@ -13,8 +13,8 @@ const createMemoryRouter = (routes, { page404 } = { page404: () => _jsx(_Fragmen
13
13
  throw "Atleast one route should present";
14
14
  }
15
15
  ;
16
- const { activeRoute, useActiveRouteState } = createStore("activeRoute", routes.find(() => isRouteMatching("/")) || { pathname: "/", component: page404 });
17
- const { locationDetails, useLocationDetailsState } = createStore("locationDetails", { params: {}, queryParams: {}, ...getLatestLocationDetails(), pathname: activeRoute.pathname });
16
+ const { activeRoute, useActiveRouteStoreValues } = createStore("activeRoute", routes.find(() => isRouteMatching("/")) || { pathname: "/", component: page404 });
17
+ const { locationDetails, useLocationDetailsStoreValues } = createStore("locationDetails", { params: {}, queryParams: {}, ...getLatestLocationDetails(), pathname: activeRoute.pathname });
18
18
  const { entries } = createStore("entries", { value: ["/"] });
19
19
  const { currentIndex } = createStore("currentIndex", { value: 0 });
20
20
  const navigate = (to, { queryParams } = {}) => {
@@ -44,12 +44,12 @@ const createMemoryRouter = (routes, { page404 } = { page404: () => _jsx(_Fragmen
44
44
  currentIndex.setState({ value: currentIndex.value + 1 });
45
45
  };
46
46
  const Outlet = () => {
47
- const { component: Component } = useActiveRouteState();
47
+ const { component: Component } = useActiveRouteStoreValues();
48
48
  return _jsx(Component, {});
49
49
  };
50
50
  return {
51
51
  navigate,
52
- useLocationDetails: useLocationDetailsState,
52
+ useLocationDetails: useLocationDetailsStoreValues,
53
53
  Outlet
54
54
  };
55
55
  };
@@ -7,7 +7,10 @@ export const createQueryParamsSearchString = (queryParams) => {
7
7
  let search = "?";
8
8
  for (let index = 0; index < keys.length; index++) {
9
9
  const key = keys[index];
10
- search = `${search}${key}=${queryParams[key]}`;
10
+ const encodedKey = encodeURIComponent(key);
11
+ const value = queryParams[key];
12
+ const encodedValue = encodeURIComponent(value == null ? "" : String(value));
13
+ search = `${search}${encodedKey}=${encodedValue}`;
11
14
  if (index !== keys.length - 1) {
12
15
  search = search + "&";
13
16
  }
@@ -20,20 +23,18 @@ export const extractQueryParamsFromURL = (url) => {
20
23
  const queryObj = {};
21
24
  const parts = url.split("?");
22
25
  if (parts.length > 2) {
23
- throw "Invalid URL";
26
+ throw new Error("Invalid URL");
24
27
  }
25
- ;
26
28
  if (parts.length === 1) {
27
29
  return queryObj;
28
30
  }
29
- ;
30
31
  const search = parts[1];
31
32
  if (search && search.length > 0) {
32
33
  const queries = search.split("&");
33
34
  for (const query of queries) {
34
35
  const queryParts = query.split("=");
35
36
  if (queryParts.length > 2) {
36
- throw "Invalid URL";
37
+ throw new Error("Invalid URL");
37
38
  }
38
39
  const [key, value] = queryParts;
39
40
  queryObj[decodeURIComponent(key)] = decodeURIComponent(value ?? "");
@@ -1,7 +1,8 @@
1
1
  import "../prototypes";
2
2
  import { useSyncExternalStore } from "react";
3
3
  export default function createStore(name, initialState) {
4
- let state = initialState;
4
+ const originalState = JSON.parse(JSON.stringify(initialState));
5
+ let state = JSON.parse(JSON.stringify(originalState));
5
6
  const listeners = new Set();
6
7
  const subscribe = (listener) => {
7
8
  listeners.add(listener);
@@ -13,11 +14,11 @@ export default function createStore(name, initialState) {
13
14
  listeners.forEach(l => l());
14
15
  };
15
16
  const resetState = () => {
16
- state = initialState;
17
+ state = JSON.parse(JSON.stringify(originalState));
17
18
  listeners.forEach(l => l());
18
19
  };
19
20
  const useStore = () => useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
20
- const capName = name.capitalize();
21
+ const capName = (name.charAt(0).toUpperCase() + name.slice(1));
21
22
  const exposedState = {};
22
23
  Object.keys(initialState).forEach(key => {
23
24
  Object.defineProperty(exposedState, key, {
@@ -31,6 +32,6 @@ export default function createStore(name, initialState) {
31
32
  setState,
32
33
  resetState
33
34
  },
34
- [`use${capName}State`]: useStore
35
+ [`use${capName}StoreValues`]: useStore
35
36
  };
36
37
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gohanfromgoku/ui-kit",
3
- "version": "1.0.1",
3
+ "version": "1.1.1",
4
4
  "description": "ui-kit is a TypeScript based UI component library designed for building modern web applications with ease and efficiency.",
5
5
  "sideEffects": false,
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  },
31
31
  "devDependencies": {
32
32
  "@types/react": ">=18",
33
- "react": "^19.2.3",
33
+ "react": ">=18",
34
34
  "tsc-alias": "^1.8.16",
35
35
  "typescript": "^5.9.3"
36
36
  },
@@ -2,4 +2,4 @@ import "../prototypes";
2
2
  export default function createStore<Name extends string, T extends Record<string, any>>(name: Name, initialState: T): { [K in Name]: T & {
3
3
  setState: (partial: Partial<T>) => void;
4
4
  resetState: () => void;
5
- }; } & { [K in `use${Capitalize<Name>}State`]: () => T; };
5
+ }; } & { [K in `use${Capitalize<Name>}StoreValues`]: () => T; };