@lexriver/dome 2.0.0 → 2.0.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.
package/README.md CHANGED
@@ -1350,7 +1350,7 @@ DomeManipulator.scrollToY({
1350
1350
  Use DomeRouter for navigation in single page app.
1351
1351
 
1352
1352
  ```typescript
1353
- DomeRouter.onRoute('/about', true, async (params, url) => {
1353
+ DomeRouter.onRoute('/about', true, async (params, url, scrollTo, query) => {
1354
1354
  const { PageAbout } = await import('./pages/PageAbout') // dynamic import component
1355
1355
  DomeManipulator.replaceAllChildrenAsync(divContainer, <PageAbout />, animationHide, animationShow) // replace current page with new page
1356
1356
  })
@@ -1507,12 +1507,18 @@ Parameters:
1507
1507
  Where `RouteAction` type is:
1508
1508
  ```typescript
1509
1509
  export type RouteAction = (
1510
- params:{[key:string]:string}, // parameters from url
1511
- url:string,
1512
- scrollToPreviousPositionAsync:()=>Promise<void> // this function can be called to scroll to previous page position
1510
+ params:{[key:string]:string|number}, // parameters from url path
1511
+ url:string, // url path without query string
1512
+ scrollToPreviousPositionAsync:()=>Promise<void>, // this function can be called to scroll to previous page position
1513
+ query:{[key:string]:string} // query parameters from window.location.search
1513
1514
  ) => void|Promise<void>
1514
1515
  ```
1515
1516
 
1517
+ For example, for URL `/search?category=books&sort=price`, the `query` parameter will be:
1518
+ ```typescript
1519
+ {category: 'books', sort: 'price'}
1520
+ ```
1521
+
1516
1522
  example:
1517
1523
  ```typescript
1518
1524
  DomeRouter.onRoute('/login', true, (params, url) => changePage(<PageLogin />))
@@ -1,6 +1,8 @@
1
1
  export type RouteAction = (params: {
2
+ [key: string]: string | number;
3
+ }, url: string, scrollToPreviousPositionAsync: () => Promise<void>, query: {
2
4
  [key: string]: string;
3
- }, url: string, scrollToPreviousPositionAsync: () => Promise<void>) => void | Promise<void>;
5
+ }) => void | Promise<void>;
4
6
  export declare namespace DomeRouter {
5
7
  let maxHistoryUrlsCount: number;
6
8
  function navigate(url: string): void;
@@ -182,7 +182,20 @@ export var DomeRouter;
182
182
  return [name.substring(1), value];
183
183
  }
184
184
  }
185
+ function parseQueryString(search) {
186
+ const query = {};
187
+ if (!search || search[0] !== '?')
188
+ return query;
189
+ const params = new URLSearchParams(search.substring(1));
190
+ for (const [key, value] of params.entries()) {
191
+ query[key] = value;
192
+ }
193
+ return query;
194
+ }
185
195
  async function executeAsync(url = window.location.pathname, scrollToPosition) {
196
+ const queryString = window.location.search;
197
+ const query = parseQueryString(queryString);
198
+ url = url.split('?')[0]; // Strip query params
186
199
  //const url = window.location.pathname
187
200
  const urlSlices = getRouteSlices(url);
188
201
  // urlSlices = show, category, 345
@@ -225,7 +238,7 @@ export var DomeRouter;
225
238
  await DomeManipulator.scrollToAsync({
226
239
  pxFromTop: scrollToPosition
227
240
  });
228
- });
241
+ }, query);
229
242
  }
230
243
  }
231
244
  if (countOfFoundRoutes == 0 && onNotFoundAction) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "sideEffects": false,
3
3
  "name": "@lexriver/dome",
4
- "version": "2.0.0",
4
+ "version": "2.0.1",
5
5
  "description": "DOM manipulator",
6
6
  "type": "module",
7
7
  "exports": "./out/src/index.mjs",
File without changes
File without changes
File without changes
package/src/Animation.mts CHANGED
File without changes
package/src/Dome.mts CHANGED
File without changes
File without changes
File without changes
File without changes
@@ -3,9 +3,10 @@ import { DomeManipulator } from "./DomeManipulator.mjs"
3
3
  // const filename = '[DomeRouter]'
4
4
 
5
5
  export type RouteAction = (
6
- params:{[key:string]:string},
6
+ params:{[key:string]:string|number},
7
7
  url:string,
8
- scrollToPreviousPositionAsync:()=>Promise<void>
8
+ scrollToPreviousPositionAsync:()=>Promise<void>,
9
+ query:{[key:string]:string}
9
10
  ) => void|Promise<void>
10
11
 
11
12
  interface Route{
@@ -215,7 +216,20 @@ export namespace DomeRouter {
215
216
 
216
217
  }
217
218
 
219
+ function parseQueryString(search:string):{[key:string]:string}{
220
+ const query:{[key:string]:string} = {}
221
+ if(!search || search[0] !== '?') return query
222
+ const params = new URLSearchParams(search.substring(1))
223
+ for(const [key, value] of params.entries()){
224
+ query[key] = value
225
+ }
226
+ return query
227
+ }
228
+
218
229
  async function executeAsync(url:string = window.location.pathname, scrollToPosition:number){
230
+ const queryString = window.location.search
231
+ const query = parseQueryString(queryString)
232
+ url = url.split('?')[0] // Strip query params
219
233
  //const url = window.location.pathname
220
234
  const urlSlices = getRouteSlices(url)
221
235
  // urlSlices = show, category, 345
@@ -259,7 +273,7 @@ export namespace DomeRouter {
259
273
  await DomeManipulator.scrollToAsync({
260
274
  pxFromTop: scrollToPosition
261
275
  })
262
- })
276
+ }, query)
263
277
  }
264
278
  }
265
279
  if(countOfFoundRoutes==0 && onNotFoundAction){
File without changes
package/src/index.mts CHANGED
File without changes
package/src/temp-test.mts CHANGED
File without changes
package/tsconfig.json CHANGED
File without changes
package/vitest.config.ts CHANGED
File without changes