frutjam 0.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
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
# Welcome to Frutjam
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "frutjam",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "Frutjam includes prebuilt UI components and plugins that are completely open-source",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.mjs",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "github",
|
|
10
|
+
"url": "git+https://github.com/nezanuha/frutjam.git"
|
|
11
|
+
},
|
|
12
|
+
"scripts": {
|
|
13
|
+
"build": "tsup",
|
|
14
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
15
|
+
},
|
|
16
|
+
"keywords": [
|
|
17
|
+
"frutjam",
|
|
18
|
+
"Nezanuha"
|
|
19
|
+
],
|
|
20
|
+
"author": "Nezanuha",
|
|
21
|
+
"license": "MIT",
|
|
22
|
+
"homepage": "https://frutjam.com",
|
|
23
|
+
"bugs": {
|
|
24
|
+
"url": "https://github.com/nezanuha/frutjam/issues"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"src/**/*"
|
|
28
|
+
],
|
|
29
|
+
"devDependencies": {
|
|
30
|
+
"esbuild": "^0.20.2",
|
|
31
|
+
"tsup": "^8.0.2",
|
|
32
|
+
"typescript": "^5.4.5"
|
|
33
|
+
}
|
|
34
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default as Notification } from './plugins/notification'
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { NotificationOptions } from './interfaces';
|
|
2
|
+
import { TimeoutId } from './types';
|
|
3
|
+
|
|
4
|
+
export default class Notification {
|
|
5
|
+
effect: string;
|
|
6
|
+
escapeTime: number;
|
|
7
|
+
arriveTime: number;
|
|
8
|
+
autoClose: boolean;
|
|
9
|
+
element: HTMLElement | null;
|
|
10
|
+
timeoutId: TimeoutId;
|
|
11
|
+
|
|
12
|
+
constructor({ effect = 'fade', escapeTime = 3000, arriveTime = 200, autoClose = true, element = null }: NotificationOptions = {}) {
|
|
13
|
+
this.effect = effect;
|
|
14
|
+
this.arriveTime = arriveTime;
|
|
15
|
+
this.autoClose = autoClose;
|
|
16
|
+
this.escapeTime = escapeTime;
|
|
17
|
+
this.element = element;
|
|
18
|
+
this.timeoutId = null; // Initialize timeout ID as null
|
|
19
|
+
this.render();
|
|
20
|
+
this.action();
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
render() {
|
|
24
|
+
if (this.element) {
|
|
25
|
+
document.querySelector("body")?.insertAdjacentElement('beforeend', this.element);
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
action() {
|
|
30
|
+
document.querySelectorAll("[data-fj='toggle-btn']").forEach((event) => {
|
|
31
|
+
event.addEventListener("click", (e) => {
|
|
32
|
+
const self = e.target as HTMLElement;
|
|
33
|
+
const container = self.closest<HTMLElement>("[data-fj='notification']");
|
|
34
|
+
if (container) {
|
|
35
|
+
this.toggleNotification(container);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Clear the timeout when the click event occurs
|
|
39
|
+
if (this.timeoutId !== null) {
|
|
40
|
+
clearTimeout(this.timeoutId);
|
|
41
|
+
this.timeoutId = null;
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Set the timeout to toggle the class after arriveTime
|
|
47
|
+
this.timeoutId = setTimeout(() => {
|
|
48
|
+
const notificationsContainer = document.querySelectorAll<HTMLElement>("[data-fj='notification']");
|
|
49
|
+
notificationsContainer.forEach((container) => {
|
|
50
|
+
this.toggleNotification(container);
|
|
51
|
+
});
|
|
52
|
+
this.timeoutId = null; // Reset timeout ID after it's triggered
|
|
53
|
+
}, this.arriveTime);
|
|
54
|
+
|
|
55
|
+
if (this.autoClose === true) {
|
|
56
|
+
this.timeoutId = setTimeout(() => {
|
|
57
|
+
const notificationsContainer = document.querySelectorAll<HTMLElement>("[data-fj='notification']");
|
|
58
|
+
notificationsContainer.forEach((container) => {
|
|
59
|
+
this.toggleNotification(container);
|
|
60
|
+
});
|
|
61
|
+
this.timeoutId = null; // Reset timeout ID after it's triggered
|
|
62
|
+
}, this.escapeTime);
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
toggleNotification(container: HTMLElement) {
|
|
67
|
+
if (this.effect == 'slide') {
|
|
68
|
+
container.classList.toggle("translate-x-0");
|
|
69
|
+
} else {
|
|
70
|
+
container.classList.toggle("opacity-100");
|
|
71
|
+
}
|
|
72
|
+
// Add other toggle logic here if needed
|
|
73
|
+
}
|
|
74
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type TimeoutId = ReturnType<typeof setTimeout> | null;
|