@plentymarkets/shop-core 1.26.0 → 1.26.2
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 +1 -1
- package/dist/runtime/composables/createNotificationLogic.d.ts +7 -0
- package/dist/runtime/composables/createNotificationLogic.js +41 -0
- package/dist/runtime/composables/useNotification.d.ts +0 -8
- package/dist/runtime/composables/useNotification.js +5 -43
- package/dist/runtime/types/notification.d.ts +4 -0
- package/package.json +3 -2
package/dist/module.json
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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.26.
|
|
3
|
+
"version": "1.26.2",
|
|
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,7 +51,7 @@
|
|
|
50
51
|
},
|
|
51
52
|
"dependencies": {
|
|
52
53
|
"@noble/hashes": "^2.0.1",
|
|
53
|
-
"@plentymarkets/shop-api": "^0.
|
|
54
|
+
"@plentymarkets/shop-api": "^0.172.0",
|
|
54
55
|
"@vue-storefront/sdk": "^3.4.1",
|
|
55
56
|
"cookie-es": "^2.0.0",
|
|
56
57
|
"knitwork": "^1.3.0",
|