@nemigo/layout 1.5.0 → 2.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.
@@ -0,0 +1,13 @@
1
+ import type { IState } from "@nemigo/helpers/types";
2
+ import type { ISvelteState } from "@nemigo/svelte";
3
+ export interface NavigationHandler {
4
+ ignore?: (from: URL, to: URL) => boolean;
5
+ equal?: boolean;
6
+ }
7
+ export declare class Navigation<State extends IState<boolean> = ISvelteState<boolean>> {
8
+ state: State;
9
+ __handler: NavigationHandler;
10
+ static default(handler?: NavigationHandler): Navigation;
11
+ constructor(state: State, handler?: NavigationHandler);
12
+ hydrate(): this;
13
+ }
@@ -0,0 +1,32 @@
1
+ import { afterNavigate, beforeNavigate } from "$app/navigation";
2
+ import { page } from "$app/state";
3
+ import { createSvelteState } from "@nemigo/svelte";
4
+ export class Navigation {
5
+ state;
6
+ __handler;
7
+ static default(handler) {
8
+ return new Navigation(createSvelteState(false), handler);
9
+ }
10
+ constructor(state, handler = {}) {
11
+ this.state = state;
12
+ this.__handler = handler;
13
+ }
14
+ hydrate() {
15
+ afterNavigate(() => this.state.set(false));
16
+ beforeNavigate((navigation) => {
17
+ if (!navigation.to)
18
+ return;
19
+ const form_url = page.url;
20
+ const to_url = navigation.to.url;
21
+ if (!this.__handler.equal && form_url.toString() === to_url.toString())
22
+ return;
23
+ if (this.__handler.ignore && this.__handler.ignore(form_url, to_url))
24
+ return;
25
+ if (this.state.get())
26
+ navigation.cancel();
27
+ else
28
+ this.state.set(true);
29
+ });
30
+ return this;
31
+ }
32
+ }
package/package.json CHANGED
@@ -1,20 +1,17 @@
1
1
  {
2
2
  "name": "@nemigo/layout",
3
- "version": "1.5.0",
3
+ "version": "2.0.0",
4
4
  "private": false,
5
5
  "author": {
6
6
  "name": "Vlad Logvin",
7
7
  "email": "vlad.logvin84@gmail.com"
8
8
  },
9
9
  "type": "module",
10
- "engines": {
11
- "node": ">=22",
12
- "pnpm": ">=10.9.0"
13
- },
14
10
  "scripts": {
15
11
  "build": "svelte-package && rimraf .svelte-kit",
16
12
  "check": "svelte-check --tsconfig ./tsconfig.json",
17
- "lint": "eslint ./",
13
+ "eslint": "eslint ./",
14
+ "eslint:fix": "eslint --fix ./",
18
15
  "format": "prettier --write ./"
19
16
  },
20
17
  "exports": {
@@ -30,19 +27,29 @@
30
27
  "types": "./dist/blocks/LazyBlock.svelte.d.ts",
31
28
  "svelte": "./dist/blocks/LazyBlock.svelte"
32
29
  },
30
+ "./navigation": {
31
+ "types": "./dist/navigation.d.ts",
32
+ "svelte": "./dist/navigation.js"
33
+ },
33
34
  "./stores/LoaderCursor": {
34
35
  "types": "./dist/stores/LoaderCursor.svelte.d.ts",
35
36
  "svelte": "./dist/stores/LoaderCursor.svelte"
36
37
  }
37
38
  },
38
39
  "peerDependencies": {
39
- "@nemigo/helpers": ">=1.5.0",
40
- "@nemigo/svelte": ">=1.5.0",
40
+ "@nemigo/helpers": ">=2.0.0",
41
+ "@nemigo/svelte": ">=2.0.0",
42
+ "@sveltejs/kit": ">=2.12.0",
41
43
  "svelte": ">=5.0.0"
42
44
  },
45
+ "peerDependenciesMeta": {
46
+ "@sveltejs/kit": {
47
+ "optional": true
48
+ }
49
+ },
43
50
  "devDependencies": {
44
- "@nemigo/configs": "workspace:*",
45
- "@nemigo/helpers": "workspace:*",
46
- "@nemigo/svelte": "workspace:*"
51
+ "@nemigo/configs": "2.0.0",
52
+ "@nemigo/helpers": "2.0.0",
53
+ "@nemigo/svelte": "2.0.0"
47
54
  }
48
55
  }