Skip to content

Commit 151bf23

Browse files
arashagpnjfamirm
andauthored
feat(service-worker): add service worker utilities and logging support (#18)
* feat(service-worker): add service worker utilities and logging support * feat(service-worker): refactor imports and add version-checker utility * refactor(service-worker): enhance PWA installation handling with type definitions and improved comments * feat(service-worker): add beforeinstallprompt option and integrate snackbar package * refactor(snackbar): optimize logger and signal instantiation with pure annotations * feat(snackbar): allow 'infinite' duration option for snackbar display * doc(snackbar): update documentation to clarify 'infinite' duration option * refactor(service-worker): update snackbar duration to 'infinite' for service worker notifications * refactor(service-worker): improve AlwatrSignal instantiation with pure annotations * refactor(service-worker): update version and repository directory in package.json * feat(service-worker): add an empty test file for initial setup * refactor(snackbar): simplify default duration assignment in showSnackbar function * doc(service-worker): remove unnecessary comment in main.ts * refactor(service-worker): remove install-pwa.ts file and related functionality * refactor(logger): simplify logger initialization by removing package tracer and package details * refactor(service-worker): remove serviceWorkerNotifyHandler and related functionality * refactor(version-checker): remove isVersionLarger function and related logger usage * refactor(service-worker): remove unused exports from main.ts * refactor(service-worker): clean up package.json and yarn.lock by removing unused dependencies * doc(service-worker): write installation * chore: set correct owner homepage * refactor(service-worker): review and enhance Co-authored-by: arashagp <[email protected]> * lint: make happy --------- Co-authored-by: S. Amir Mohammad Najafi <[email protected]>
1 parent 90d61ff commit 151bf23

File tree

6 files changed

+31
-10
lines changed

6 files changed

+31
-10
lines changed

.vscode/settings.json

+1
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"argb",
5555
"backorder",
5656
"backordering",
57+
"beforeinstallprompt",
5758
"colspan",
5859
"cssnano",
5960
"endmacro",

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"description": "Necessary library for all ECMAScript (JavaScript/TypeScript) projects.",
55
"repository": "https://github.com/the-nexim/nanolib",
66
"license": "AGPL-3.0-only",
7-
"author": "S. Amir Mohammad Najafi <[email protected]> (www.njfamirm.ir)",
7+
"author": "S. Amir Mohammad Najafi <[email protected]> (https://www.njfamirm.ir)",
88
"contributors": [
99
"Arash Ghardashpoor <[email protected]> (https://www.agpagp.ir)"
1010
],

packages/snackbar/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"directory": "packages/snackbar"
2020
},
2121
"license": "AGPL-3.0-only",
22-
"author": "S. Amir Mohammad Najafi <[email protected]> (www.njfamirm.ir)",
22+
"author": "S. Amir Mohammad Najafi <[email protected]> (https://www.njfamirm.ir)",
2323
"contributors": [
2424
"Arash Ghardashpoor <[email protected]> (https://www.agpagp.ir)"
2525
],

packages/snackbar/src/lib/handler.ts

+7-8
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,16 @@ import {waitForTimeout} from '@alwatr/wait';
55

66
import type {SnackbarComponent} from './element.js';
77

8-
const logger = createLogger(`${__package_name__}/handler`);
8+
const logger = /* @__PURE__ */ createLogger(`${__package_name__}/handler`);
99

1010
/**
1111
* @property content - Content to be displayed in the snackbar.
1212
* @property {action} - The action button configuration.
1313
* @property action.label - The label for the action button.
1414
* @property action.handler - The handler function for the action button.
15-
* @property duration - Duration for which the snackbar is displayed. `-1` for infinite duration.
15+
* @property duration - Duration for which the snackbar is displayed. `infinite` for infinite duration.
1616
* Duration for which the snackbar is displayed.
17-
* `-1` for infinite duration.
17+
* `infinite` for infinite duration.
1818
* @property addCloseButton - Whether to add a close button to the snackbar.
1919
*/
2020
export type SnackbarOptions = {
@@ -23,7 +23,7 @@ export type SnackbarOptions = {
2323
label: string;
2424
handler: () => void;
2525
};
26-
duration?: Duration;
26+
duration?: Duration | 'infinite';
2727
addCloseButton?: boolean;
2828
};
2929

@@ -53,7 +53,7 @@ export const snackbarActionButtonClickedSignal = new AlwatrTrigger({
5353
* addCloseButton: true,
5454
* });
5555
*/
56-
export const snackbarSignal = new AlwatrSignal<SnackbarOptions>({name: 'snackbar'});
56+
export const snackbarSignal = /* @__PURE__ */ new AlwatrSignal<SnackbarOptions>({name: 'snackbar'});
5757

5858
// Subscribe to the snackbar signal to show the snackbar when the signal is emitted.
5959
snackbarSignal.subscribe((options) => {
@@ -71,10 +71,9 @@ async function showSnackbar(options: SnackbarOptions): Promise<void> {
7171
logger.logMethodArgs?.('showSnackbar', {options});
7272

7373
// Parse the duration
74-
if (options.duration != null) options.duration = parseDuration(options.duration);
7574

7675
// Set default duration if not provided
77-
options.duration = parseDuration('4s');
76+
options.duration ??= '4s';
7877

7978
const element = document.createElement('snack-bar') as SnackbarComponent;
8079

@@ -111,7 +110,7 @@ async function showSnackbar(options: SnackbarOptions): Promise<void> {
111110
document.body.appendChild(element);
112111

113112
// Set a timeout to close the snackbar if duration is not infinite
114-
if (options.duration !== -1) {
113+
if (options.duration !== 'infinite') {
115114
waitForTimeout(parseDuration(options.duration)).then(closeSnackbar_);
116115
}
117116
}

tsconfig.json

+6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@
1515
},
1616
{
1717
"path": "./packages/alpine"
18+
},
19+
{
20+
"path": "./packages/service-worker"
21+
},
22+
{
23+
"path": "./packages/snackbar"
1824
}
1925
]
2026
}

yarn.lock

+15
Original file line numberDiff line numberDiff line change
@@ -1072,6 +1072,21 @@ __metadata:
10721072
languageName: unknown
10731073
linkType: soft
10741074

1075+
"@nexim/service-worker@workspace:packages/service-worker":
1076+
version: 0.0.0-use.local
1077+
resolution: "@nexim/service-worker@workspace:packages/service-worker"
1078+
dependencies:
1079+
"@alwatr/flux": "npm:^4.0.2"
1080+
"@alwatr/logger": "npm:^5.0.0"
1081+
"@alwatr/nano-build": "npm:^5.0.0"
1082+
"@alwatr/package-tracer": "npm:^5.0.0"
1083+
"@alwatr/type-helper": "npm:^5.0.0"
1084+
"@nexim/typescript-config": "workspace:^"
1085+
ava: "npm:^6.2.0"
1086+
typescript: "npm:^5.6.3"
1087+
languageName: unknown
1088+
linkType: soft
1089+
10751090
"@nexim/snackbar@workspace:packages/snackbar":
10761091
version: 0.0.0-use.local
10771092
resolution: "@nexim/snackbar@workspace:packages/snackbar"

0 commit comments

Comments
 (0)