@plentymarkets/shop-core 1.25.1 → 1.26.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/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
3
  "configKey": "shopCore",
4
- "version": "1.25.1",
4
+ "version": "1.26.1",
5
5
  "builder": {
6
6
  "@nuxt/module-builder": "1.0.2",
7
7
  "unbuild": "unknown"
@@ -0,0 +1,7 @@
1
+ import type { Ref } from 'vue';
2
+ import type { UseNotificationState, UseNotificationDeps, Notification } from '../types/index.js';
3
+ export declare const createNotificationLogic: (defaultDismissTimeout: number, state: Ref<UseNotificationState>, deps: UseNotificationDeps) => {
4
+ data: Ref<Notification[], Notification[]>;
5
+ send: (notification: Notification) => void;
6
+ clear: () => void;
7
+ };
@@ -0,0 +1,41 @@
1
+ import { toRefs } from "vue";
2
+ const maxVisibleNotifications = 5;
3
+ export const createNotificationLogic = (defaultDismissTimeout, state, deps) => {
4
+ const { onScopeDispose } = deps;
5
+ const timeoutIds = /* @__PURE__ */ new Map();
6
+ const clearTimeouts = () => {
7
+ for (const timeoutId of timeoutIds.values()) {
8
+ clearTimeout(timeoutId);
9
+ }
10
+ timeoutIds.clear();
11
+ };
12
+ const send = (notification) => {
13
+ if (deps.isServer) return;
14
+ const id = Symbol();
15
+ const dismiss = () => {
16
+ const index = state.value.data.findIndex((n) => n.id === id);
17
+ if (index !== -1) state.value.data.splice(index, 1);
18
+ if (timeoutIds.has(id)) {
19
+ clearTimeout(timeoutIds.get(id));
20
+ timeoutIds.delete(id);
21
+ }
22
+ };
23
+ const dismissibleNotification = { ...notification, id, dismiss };
24
+ state.value.data.push(dismissibleNotification);
25
+ if (state.value.data.length > maxVisibleNotifications) state.value.data.shift();
26
+ if (!notification.persist && notification.type !== "negative") {
27
+ const timeoutId = setTimeout(dismiss, notification.dismissTimeout || defaultDismissTimeout);
28
+ timeoutIds.set(id, timeoutId);
29
+ }
30
+ };
31
+ const clear = () => {
32
+ clearTimeouts();
33
+ state.value.data = [];
34
+ };
35
+ onScopeDispose(clearTimeouts);
36
+ return {
37
+ send,
38
+ clear,
39
+ ...toRefs(state.value)
40
+ };
41
+ };
@@ -1,10 +1,2 @@
1
1
  import type { UseNotificationReturn } from '../types/index.js';
2
- /**
3
- * @description Composable to display ui notifications
4
- * @return UseNotificationReturn
5
- * @example
6
- * ``` ts
7
- * const { data, send } = useNotification();
8
- * ```
9
- */
10
2
  export declare const useNotification: UseNotificationReturn;
@@ -1,51 +1,13 @@
1
1
  import { useState } from "nuxt/app";
2
- import { toRefs } from "vue";
3
2
  import { tryOnScopeDispose } from "@vueuse/core";
4
- const maxVisibleNotifications = 5;
3
+ import { createNotificationLogic } from "./createNotificationLogic.js";
4
+ import { isServer } from "../utils/runtime.js";
5
5
  export const useNotification = (defaultDismissTimeout = 5e3) => {
6
6
  const state = useState(`useNotification`, () => ({
7
7
  data: []
8
8
  }));
9
- const timeoutIds = /* @__PURE__ */ new Map();
10
- const send = (notification) => {
11
- if (import.meta.server) return;
12
- const id = Symbol();
13
- const dismiss = () => {
14
- const index = state.value.data.findIndex((notification2) => notification2.id === id);
15
- if (index !== -1) state.value.data.splice(index, 1);
16
- if (timeoutIds.has(id)) {
17
- clearTimeout(timeoutIds.get(id));
18
- timeoutIds.delete(id);
19
- }
20
- };
21
- const dismissibleNotification = {
22
- ...notification,
23
- id,
24
- dismiss
25
- };
26
- state.value.data.push(dismissibleNotification);
27
- if (state.value.data.length > maxVisibleNotifications) state.value.data.shift();
28
- if (!notification.persist && notification.type !== "negative") {
29
- const timeoutId = setTimeout(dismiss, notification.dismissTimeout || defaultDismissTimeout);
30
- timeoutIds.set(id, timeoutId);
31
- }
32
- };
33
- const clearTimeouts = () => {
34
- for (const timeoutId of timeoutIds.values()) {
35
- clearTimeout(timeoutId);
36
- }
37
- timeoutIds.clear();
38
- };
39
- const clear = () => {
40
- clearTimeouts();
41
- state.value.data = [];
42
- };
43
- tryOnScopeDispose(() => {
44
- clearTimeouts();
9
+ return createNotificationLogic(defaultDismissTimeout, state, {
10
+ onScopeDispose: tryOnScopeDispose,
11
+ isServer: isServer()
45
12
  });
46
- return {
47
- send,
48
- clear,
49
- ...toRefs(state.value)
50
- };
51
13
  };
@@ -33,3 +33,7 @@ export interface UseNotification {
33
33
  clear: ClearNotification;
34
34
  }
35
35
  export type UseNotificationReturn = (defaultDismissTimeout?: number) => UseNotification;
36
+ export interface UseNotificationDeps {
37
+ onScopeDispose: (fn: () => void) => void;
38
+ isServer: boolean;
39
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@plentymarkets/shop-core",
3
- "version": "1.25.1",
3
+ "version": "1.26.1",
4
4
  "description": "Core module for PlentyONE Shop",
5
5
  "repository": {
6
6
  "type": "git",
@@ -42,6 +42,7 @@
42
42
  "format": "prettier --check \"**/*.{ts,vue,css,scss,md}\"",
43
43
  "format:fix": "prettier --write \"**/*.{ts,vue,css,scss,md}\"",
44
44
  "test": "vitest run",
45
+ "test:unit": "vitest run \\.unit\\.spec",
45
46
  "test:coverage": "vitest run --coverage",
46
47
  "test:watch": "vitest watch",
47
48
  "test:types": "vue-tsc --noEmit",
@@ -50,22 +51,19 @@
50
51
  },
51
52
  "dependencies": {
52
53
  "@noble/hashes": "^2.0.1",
53
- "@plentymarkets/shop-api": "^0.170.1",
54
+ "@plentymarkets/shop-api": "^0.171.0",
54
55
  "@vue-storefront/sdk": "^3.4.1",
55
56
  "cookie-es": "^2.0.0",
56
57
  "knitwork": "^1.3.0",
57
58
  "ofetch": "^1.5.1",
58
59
  "resolve": "^1.22.10"
59
60
  },
60
- "overrides": {
61
- "prettier": "^3.6.2"
62
- },
63
61
  "devDependencies": {
64
62
  "@nuxt/devtools": "^3.1.0",
65
63
  "@nuxt/eslint-config": "^0.7.6",
66
- "@nuxt/kit": "4.4.2",
64
+ "@nuxt/kit": "4.4.6",
67
65
  "@nuxt/module-builder": "^1.0.2",
68
- "@nuxt/schema": "4.4.2",
66
+ "@nuxt/schema": "4.4.6",
69
67
  "@nuxt/test-utils": "^3.19.0",
70
68
  "@nuxtjs/i18n": "9.5.4",
71
69
  "@playwright/test": "^1.57.0",
@@ -83,10 +81,10 @@
83
81
  "eslint-config-prettier": "^9.1.0",
84
82
  "eslint-plugin-ceviz": "^0.0.6",
85
83
  "eslint-plugin-vuejs-accessibility": "^2.4.1",
86
- "happy-dom": "^20.0.2",
84
+ "happy-dom": "^20.9.0",
87
85
  "js-sha256": "^0.11.0",
88
- "nuxi": "3.32.0",
89
- "nuxt": "4.4.2",
86
+ "nuxi": "3.35.2",
87
+ "nuxt": "4.4.6",
90
88
  "prettier": "^3.6.2",
91
89
  "tsx": "^4.21.0",
92
90
  "typescript": "~5.9.2",