@samline/notify 0.1.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.
- package/CHANGELOG.md +9 -0
- package/README.md +128 -0
- package/dist/core/index.d.ts +47 -0
- package/dist/core/index.test.d.ts +1 -0
- package/dist/index.cjs.js +1131 -0
- package/dist/index.esm.js +1124 -0
- package/dist/notifications.umd.js +1133 -0
- package/dist/notify.umd.js +1137 -0
- package/dist/react/Toaster.d.ts +6 -0
- package/dist/react/index.d.ts +10 -0
- package/dist/samline.notifications.umd.js +1131 -0
- package/dist/styles.css +49 -0
- package/dist/svelte/store.d.ts +3 -0
- package/dist/vanilla/index.d.ts +13 -0
- package/dist/vanilla/toasterManager.d.ts +6 -0
- package/dist/vue/index.d.ts +20 -0
- package/docs/browser.md +44 -0
- package/docs/react.md +64 -0
- package/docs/svelte.md +50 -0
- package/docs/vanilla.md +79 -0
- package/docs/vue.md +41 -0
- package/examples/no-bundler/index.html +25 -0
- package/package.json +55 -0
- package/rollup.config.js +39 -0
- package/src/core/index.test.ts +26 -0
- package/src/core/index.ts +122 -0
- package/src/react/Toaster.tsx +67 -0
- package/src/react/index.ts +13 -0
- package/src/styles/sileo.css +49 -0
- package/src/svelte/Toaster.svelte +69 -0
- package/src/svelte/store.ts +9 -0
- package/src/vanilla/index.ts +22 -0
- package/src/vanilla/toasterManager.ts +132 -0
- package/src/vue/index.ts +61 -0
- package/test/smoke/no-bundler.test.ts +10 -0
- package/test/smoke/svelte.test.ts +12 -0
- package/tsconfig.json +16 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0 - Initial rename and multi-adapter release
|
|
4
|
+
|
|
5
|
+
- Renamed internal controller `sileo` -> `notify` (kept `sileo` alias for compatibility).
|
|
6
|
+
- Package renamed to `@samline/notify`.
|
|
7
|
+
- UMD build changed to `dist/notify.umd.js` and exposes `window.notify` (compat `window.notifications`).
|
|
8
|
+
- Updated docs, examples and tests to reflect the rename.
|
|
9
|
+
- Copied styles to `dist/styles.css` as part of build.
|
package/README.md
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
## @samline/notify
|
|
2
|
+
A Sileo-inspired notifications engine with a framework-agnostic core and adapters for Vanilla, React, Vue and Svelte.
|
|
3
|
+
|
|
4
|
+
Table of Contents
|
|
5
|
+
|
|
6
|
+
- Installation
|
|
7
|
+
- Entry Points
|
|
8
|
+
- Quick Start
|
|
9
|
+
- Documentation Guides
|
|
10
|
+
- Shared API Summary
|
|
11
|
+
- Shared Options
|
|
12
|
+
- Notes
|
|
13
|
+
- License
|
|
14
|
+
|
|
15
|
+
Installation
|
|
16
|
+
|
|
17
|
+
Choose the installer that matches your environment.
|
|
18
|
+
|
|
19
|
+
npm
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install @samline/notify
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
pnpm
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pnpm add @samline/notify
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
yarn
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
yarn add @samline/notify
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
bun
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
bun add @samline/notify
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
CDN / Browser
|
|
44
|
+
|
|
45
|
+
Use the browser build when your project loads scripts directly and cannot compile npm modules (Shopify, WordPress, plain HTML). Example CDN usage (replace version):
|
|
46
|
+
|
|
47
|
+
```html
|
|
48
|
+
<script src="/path/to/dist/notify.umd.js"></script>
|
|
49
|
+
<link rel="stylesheet" href="/path/to/dist/styles.css">
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Entry Points
|
|
53
|
+
|
|
54
|
+
Choose the entrypoint matching your stack so you only import what you need.
|
|
55
|
+
|
|
56
|
+
| Use case | Import | Guide |
|
|
57
|
+
| --- | --- | --- |
|
|
58
|
+
| Vanilla JS | `import { default as notifications } from '@samline/notify'` | [docs/vanilla.md](docs/vanilla.md) |
|
|
59
|
+
| Vanilla explicit subpath | `import { sileo } from '@samline/notify/vanilla'` | [docs/vanilla.md](docs/vanilla.md) |
|
|
60
|
+
| Browser / CDN | `<script src="/path/to/dist/notify.umd.js"></script>` | [docs/browser.md](docs/browser.md) |
|
|
61
|
+
| React | `import { Toaster } from '@samline/notify/react'` | [docs/react.md](docs/react.md) |
|
|
62
|
+
| Vue | `import Notifications from '@samline/notify/vue'` | [docs/vue.md](docs/vue.md) |
|
|
63
|
+
| Svelte | `import Toaster from '@samline/notify/svelte'` | [docs/svelte.md](docs/svelte.md) |
|
|
64
|
+
|
|
65
|
+
Quick Start
|
|
66
|
+
|
|
67
|
+
Vanilla example (UMD / modules):
|
|
68
|
+
|
|
69
|
+
```html
|
|
70
|
+
<script src="/path/to/dist/notify.umd.js"></script>
|
|
71
|
+
<link rel="stylesheet" href="/path/to/dist/styles.css">
|
|
72
|
+
<script>
|
|
73
|
+
const api = window.notify || window.notifications;
|
|
74
|
+
api.initToasters(document.body, ['top-right']);
|
|
75
|
+
api.notify({ title: 'Guardado', description: 'Cambios guardados', type: 'success' });
|
|
76
|
+
</script>
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
Documentation Guides
|
|
80
|
+
|
|
81
|
+
- Vanilla: [docs/vanilla.md](docs/vanilla.md)
|
|
82
|
+
- Browser/CDN: [docs/browser.md](docs/browser.md)
|
|
83
|
+
- React: [docs/react.md](docs/react.md)
|
|
84
|
+
- Vue: [docs/vue.md](docs/vue.md)
|
|
85
|
+
- Svelte: [docs/svelte.md](docs/svelte.md)
|
|
86
|
+
|
|
87
|
+
Shared API Summary
|
|
88
|
+
|
|
89
|
+
The package exposes a framework-agnostic core controller (`notify`) with the following shape (a `sileo` alias is provided for compatibility). Use `notify` as the primary API in examples and code.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
// core controller
|
|
93
|
+
notify.show(options)
|
|
94
|
+
notify.success(options)
|
|
95
|
+
notify.error(options)
|
|
96
|
+
notify.info(options)
|
|
97
|
+
notify.warning(options)
|
|
98
|
+
notify.action(options)
|
|
99
|
+
notify.promise(promise, messages)
|
|
100
|
+
notify.dismiss(id)
|
|
101
|
+
notify.clear()
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
When using the UMD/browser bundle the global is exposed as `window.notify` (preferred). For compatibility the API object also exposes `window.notifications` which maintains the previous shape.
|
|
105
|
+
|
|
106
|
+
Shared Options
|
|
107
|
+
|
|
108
|
+
Common `options` across entrypoints:
|
|
109
|
+
|
|
110
|
+
| Property | Type | Default | Description |
|
|
111
|
+
| --- | --- | --- | --- |
|
|
112
|
+
| `title` | string | — | Toast title |
|
|
113
|
+
| `description` | string | — | Optional body text |
|
|
114
|
+
| `type` | `info\|success\|error\|warning` | `info` | Visual intent |
|
|
115
|
+
| `position` | string | `top-right` | One of toast positions |
|
|
116
|
+
| `duration` | number | `4000` | Auto-dismiss timeout in ms (0 = persistent) |
|
|
117
|
+
| `button` | { title: string, onClick: () => void } | — | Optional action button |
|
|
118
|
+
|
|
119
|
+
Notes
|
|
120
|
+
|
|
121
|
+
- Accessibility: toasters use `role="status"` and `aria-live="polite"` by default. Respect `prefers-reduced-motion` in your UI.
|
|
122
|
+
- The package includes a UMD browser bundle for projects without a build step.
|
|
123
|
+
- Motion runtime is optional for module builds; UMD consumers should include the provided `dist/styles.css` for visuals.
|
|
124
|
+
|
|
125
|
+
License
|
|
126
|
+
|
|
127
|
+
MIT
|
|
128
|
+
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type Position = 'top-left' | 'top-center' | 'top-right' | 'bottom-left' | 'bottom-center' | 'bottom-right';
|
|
2
|
+
export type ToastType = 'success' | 'error' | 'info' | 'warning' | 'loading' | 'action';
|
|
3
|
+
export interface ToastButton {
|
|
4
|
+
title: string;
|
|
5
|
+
onClick: () => void;
|
|
6
|
+
}
|
|
7
|
+
export interface ToastOptions {
|
|
8
|
+
title?: string;
|
|
9
|
+
description?: string;
|
|
10
|
+
position?: Position;
|
|
11
|
+
duration?: number | null;
|
|
12
|
+
type?: ToastType;
|
|
13
|
+
button?: ToastButton;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
16
|
+
export interface ToastItem {
|
|
17
|
+
id: string;
|
|
18
|
+
options: ToastOptions;
|
|
19
|
+
createdAt: number;
|
|
20
|
+
}
|
|
21
|
+
type Listener = (items: ToastItem[]) => void;
|
|
22
|
+
declare class NotifyController {
|
|
23
|
+
private toasts;
|
|
24
|
+
private listeners;
|
|
25
|
+
private idCounter;
|
|
26
|
+
private nextId;
|
|
27
|
+
subscribe(fn: Listener): () => boolean;
|
|
28
|
+
private notify;
|
|
29
|
+
getToasts(): ToastItem[];
|
|
30
|
+
show(opts: ToastOptions): string;
|
|
31
|
+
success(opts: ToastOptions): string;
|
|
32
|
+
error(opts: ToastOptions): string;
|
|
33
|
+
info(opts: ToastOptions): string;
|
|
34
|
+
warning(opts: ToastOptions): string;
|
|
35
|
+
action(opts: ToastOptions): string;
|
|
36
|
+
dismiss(id: string): void;
|
|
37
|
+
clear(position?: Position): void;
|
|
38
|
+
promise<T = any>(p: Promise<T>, opts: {
|
|
39
|
+
loading: ToastOptions;
|
|
40
|
+
success?: ToastOptions | ((r: T) => ToastOptions);
|
|
41
|
+
error?: ToastOptions | ((e: any) => ToastOptions);
|
|
42
|
+
position?: Position;
|
|
43
|
+
}): Promise<T>;
|
|
44
|
+
}
|
|
45
|
+
export declare const notify: NotifyController;
|
|
46
|
+
export declare const sileo: NotifyController;
|
|
47
|
+
export default notify;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|