@silexlabs/grapesjs-notifications 0.1.0 → 0.1.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/README.md +95 -20
- package/dist/Notification.d.ts +38 -0
- package/dist/Notification.d.ts.map +1 -0
- package/dist/NotificationManager.d.ts +48 -0
- package/dist/NotificationManager.d.ts.map +1 -0
- package/dist/Storage.d.ts +12 -0
- package/dist/Storage.d.ts.map +1 -0
- package/dist/index.d.ts +15 -80
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +2 -2
- package/dist/index.js.map +1 -1
- package/dist/locale/en.d.ts +10 -0
- package/dist/locale/en.d.ts.map +1 -0
- package/dist/view.d.ts +5 -0
- package/dist/view.d.ts.map +1 -0
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -28,6 +28,8 @@ Features
|
|
|
28
28
|
* [x] Group notifications
|
|
29
29
|
* [x] Support pages
|
|
30
30
|
|
|
31
|
+
## Usage
|
|
32
|
+
|
|
31
33
|
### HTML
|
|
32
34
|
```html
|
|
33
35
|
<link href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" rel="stylesheet">
|
|
@@ -46,6 +48,17 @@ const editor = grapesjs.init({
|
|
|
46
48
|
storageManager: false,
|
|
47
49
|
plugins: ['@silexlabs/grapesjs-notifications'],
|
|
48
50
|
});
|
|
51
|
+
|
|
52
|
+
// Add notifications using commands
|
|
53
|
+
editor.runCommand('notifications:add', {
|
|
54
|
+
type: 'info',
|
|
55
|
+
message: 'Hello world!',
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
// Listen to events
|
|
59
|
+
editor.on('notifications:changed', (notifications) => {
|
|
60
|
+
console.log('Notifications have changed', notifications)
|
|
61
|
+
})
|
|
49
62
|
```
|
|
50
63
|
|
|
51
64
|
### CSS
|
|
@@ -60,26 +73,87 @@ body, html {
|
|
|
60
73
|
|
|
61
74
|
Plugin name: `@silexlabs/grapesjs-notifications`
|
|
62
75
|
|
|
63
|
-
API
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
76
|
+
## API
|
|
77
|
+
|
|
78
|
+
### Commands
|
|
79
|
+
|
|
80
|
+
```js
|
|
81
|
+
// Add a notification
|
|
82
|
+
editor.runCommand('notifications:add', {
|
|
83
|
+
type: 'error' | 'warning' | 'success' | 'info',
|
|
84
|
+
message: 'string',
|
|
85
|
+
timeout: 5000, // optional timeout in ms
|
|
86
|
+
componentId: 'comp-123', // optional component to select
|
|
87
|
+
group: 'validation' // optional group name
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
// Remove a notification
|
|
91
|
+
editor.runCommand('notifications:remove', notification)
|
|
92
|
+
|
|
93
|
+
// Clear all notifications
|
|
94
|
+
editor.runCommand('notifications:clear')
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Events
|
|
98
|
+
|
|
99
|
+
Listen to notification events:
|
|
100
|
+
|
|
101
|
+
```js
|
|
102
|
+
editor.on('notifications:changed', (notifications) => {
|
|
103
|
+
// Triggered when any notification change occurs
|
|
104
|
+
// notifications parameter contains all current notifications
|
|
105
|
+
})
|
|
106
|
+
|
|
107
|
+
editor.on('notifications:added', (notification) => {
|
|
108
|
+
// Triggered when a notification is added
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
editor.on('notifications:removed', (notification) => {
|
|
112
|
+
// Triggered when a notification is removed
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
editor.on('notifications:cleared', () => {
|
|
116
|
+
// Triggered when all notifications are cleared
|
|
117
|
+
})
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Constants
|
|
121
|
+
|
|
122
|
+
```js
|
|
123
|
+
import {
|
|
124
|
+
NOTIFICATION_ADD,
|
|
125
|
+
NOTIFICATION_REMOVE,
|
|
126
|
+
NOTIFICATION_CLEAR,
|
|
127
|
+
NOTIFICATION_CHANGED,
|
|
128
|
+
NOTIFICATION_ADDED,
|
|
129
|
+
NOTIFICATION_REMOVED,
|
|
130
|
+
NOTIFICATION_CLEARED
|
|
131
|
+
} from '@silexlabs/grapesjs-notifications'
|
|
132
|
+
|
|
133
|
+
// Use with commands
|
|
134
|
+
editor.runCommand(NOTIFICATION_ADD, { /* ... */ })
|
|
135
|
+
|
|
136
|
+
// Use with events
|
|
137
|
+
editor.on(NOTIFICATION_CHANGED, () => { /* ... */ })
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
### NotificationOptions Interface
|
|
141
|
+
|
|
142
|
+
```ts
|
|
143
|
+
export interface NotificationOptions {
|
|
144
|
+
message: string
|
|
145
|
+
group?: string
|
|
146
|
+
timeout?: number
|
|
147
|
+
componentId?: string
|
|
148
|
+
type: 'info' | 'warning' | 'error' | 'success'
|
|
149
|
+
icons?: {
|
|
150
|
+
info?: string
|
|
151
|
+
warning?: string
|
|
152
|
+
error?: string
|
|
153
|
+
success?: string
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
```
|
|
83
157
|
|
|
84
158
|
## Options
|
|
85
159
|
|
|
@@ -92,6 +166,7 @@ API:
|
|
|
92
166
|
| `i18n` | Internationalization | `object` | Check the values in locale/en.js |
|
|
93
167
|
| `maxNotifications` | Maximum number of notifications to display | `number` | 50 |
|
|
94
168
|
| `reverse` | Reverse the order of the notifications | `boolean` | `false` |
|
|
169
|
+
| `style` | Optional styles to add to the component | `string` | `''` |
|
|
95
170
|
|
|
96
171
|
## Styling
|
|
97
172
|
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Editor } from 'grapesjs';
|
|
2
|
+
export interface NotificationOptions {
|
|
3
|
+
message: string;
|
|
4
|
+
group?: string;
|
|
5
|
+
timeout?: number;
|
|
6
|
+
componentId?: string;
|
|
7
|
+
type: 'info' | 'warning' | 'error' | 'success';
|
|
8
|
+
icons: {
|
|
9
|
+
info: string;
|
|
10
|
+
warning: string;
|
|
11
|
+
error: string;
|
|
12
|
+
success: string;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export declare class Notification {
|
|
16
|
+
protected editor: Editor;
|
|
17
|
+
componentId: string | null;
|
|
18
|
+
group: string | null;
|
|
19
|
+
timeoutRef: NodeJS.Timeout | undefined;
|
|
20
|
+
message: string;
|
|
21
|
+
type: 'info' | 'warning' | 'error' | 'success';
|
|
22
|
+
options: NotificationOptions;
|
|
23
|
+
model: any;
|
|
24
|
+
private removeCallback?;
|
|
25
|
+
constructor(editor: Editor, options: NotificationOptions | any, removeCallback?: (notification: Notification) => void);
|
|
26
|
+
select(): void;
|
|
27
|
+
remove(): void;
|
|
28
|
+
getSvgIcon(type: string): string;
|
|
29
|
+
private getDefaultOptions;
|
|
30
|
+
/**
|
|
31
|
+
* Get all components in the editor
|
|
32
|
+
* This is a heavy operation
|
|
33
|
+
*/
|
|
34
|
+
private getAllComponents;
|
|
35
|
+
private getAllComponentInPage;
|
|
36
|
+
private getAllChildrenComponent;
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=Notification.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Notification.d.ts","sourceRoot":"","sources":["../src/Notification.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,MAAM,EAAE,MAAM,UAAU,CAAA;AAElD,MAAM,WAAW,mBAAmB;IAClC,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAA;IAC9C,KAAK,EAAE;QACL,IAAI,EAAE,MAAM,CAAA;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,KAAK,EAAE,MAAM,CAAA;QACb,OAAO,EAAE,MAAM,CAAA;KAChB,CAAA;CACF;AAED,qBAAa,YAAY;IAUX,SAAS,CAAC,MAAM,EAAE,MAAM;IATpC,WAAW,EAAE,MAAM,GAAG,IAAI,CAAO;IACjC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAO;IAC3B,UAAU,6BAAA;IACV,OAAO,EAAE,MAAM,CAAA;IACf,IAAI,EAAE,MAAM,GAAG,SAAS,GAAG,OAAO,GAAG,SAAS,CAAA;IAC9C,OAAO,EAAE,mBAAmB,CAAA;IACrB,KAAK,EAAE,GAAG,CAAA;IACjB,OAAO,CAAC,cAAc,CAAC,CAAsC;gBAEvC,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,mBAAmB,GAAG,GAAG,EAAE,cAAc,CAAC,EAAE,CAAC,YAAY,EAAE,YAAY,KAAK,IAAI;IAa/H,MAAM;IAoBN,MAAM;IAYN,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAIhC,OAAO,CAAC,iBAAiB;IAezB;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IAIxB,OAAO,CAAC,qBAAqB;IAW7B,OAAO,CAAC,uBAAuB;CAIhC"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Editor } from "grapesjs";
|
|
2
|
+
import { Notification, NotificationOptions } from "./Notification";
|
|
3
|
+
import { StyleInfo } from "lit/directives/style-map";
|
|
4
|
+
export declare const NOTIFICATION_CHANGED = "notifications:changed";
|
|
5
|
+
export declare const NOTIFICATION_ADDED = "notifications:added";
|
|
6
|
+
export declare const NOTIFICATION_REMOVED = "notifications:removed";
|
|
7
|
+
export declare const NOTIFICATION_CLEARED = "notifications:cleared";
|
|
8
|
+
export interface NotificationManagerOptions {
|
|
9
|
+
style?: Readonly<StyleInfo>;
|
|
10
|
+
container: HTMLElement;
|
|
11
|
+
maxNotifications?: number;
|
|
12
|
+
reverse?: boolean;
|
|
13
|
+
timeout?: number;
|
|
14
|
+
storeKey?: string;
|
|
15
|
+
i18n?: any;
|
|
16
|
+
icons?: {
|
|
17
|
+
info?: string;
|
|
18
|
+
warning?: string;
|
|
19
|
+
error?: string;
|
|
20
|
+
success?: string;
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* GrapesJs plugin to manage notifications
|
|
25
|
+
*/
|
|
26
|
+
export declare class NotificationManager {
|
|
27
|
+
protected editor: Editor;
|
|
28
|
+
protected options: NotificationManagerOptions;
|
|
29
|
+
private notifications;
|
|
30
|
+
constructor(initialNotifications: any[], editor: Editor, options: NotificationManagerOptions);
|
|
31
|
+
/**
|
|
32
|
+
* Get all notifications
|
|
33
|
+
*/
|
|
34
|
+
getAll(): Notification[];
|
|
35
|
+
/**
|
|
36
|
+
* Add a notification
|
|
37
|
+
*/
|
|
38
|
+
add(options: NotificationOptions): void;
|
|
39
|
+
/**
|
|
40
|
+
* Remove a notification
|
|
41
|
+
*/
|
|
42
|
+
remove(notification: Notification | any): void;
|
|
43
|
+
/**
|
|
44
|
+
* Clear all notifications
|
|
45
|
+
*/
|
|
46
|
+
reset(): void;
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=NotificationManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NotificationManager.d.ts","sourceRoot":"","sources":["../src/NotificationManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AACjC,OAAO,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAA;AAGpD,eAAO,MAAM,oBAAoB,0BAA0B,CAAA;AAC3D,eAAO,MAAM,kBAAkB,wBAAwB,CAAA;AACvD,eAAO,MAAM,oBAAoB,0BAA0B,CAAA;AAC3D,eAAO,MAAM,oBAAoB,0BAA0B,CAAA;AAE3D,MAAM,WAAW,0BAA0B;IACzC,KAAK,CAAC,EAAE,QAAQ,CAAC,SAAS,CAAC,CAAA;IAC3B,SAAS,EAAE,WAAW,CAAA;IACtB,gBAAgB,CAAC,EAAE,MAAM,CAAA;IACzB,OAAO,CAAC,EAAE,OAAO,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,IAAI,CAAC,EAAE,GAAG,CAAA;IACV,KAAK,CAAC,EAAE;QACN,IAAI,CAAC,EAAE,MAAM,CAAA;QACb,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,OAAO,CAAC,EAAE,MAAM,CAAA;KACjB,CAAA;CACF;AAED;;GAEG;AACH,qBAAa,mBAAmB;IAGW,SAAS,CAAC,MAAM,EAAE,MAAM;IAAE,SAAS,CAAC,OAAO,EAAE,0BAA0B;IAFhH,OAAO,CAAC,aAAa,CAAqB;gBAE9B,oBAAoB,EAAE,GAAG,EAAE,EAAY,MAAM,EAAE,MAAM,EAAY,OAAO,EAAE,0BAA0B;IAWhH;;OAEG;IACH,MAAM,IAAI,YAAY,EAAE;IAIxB;;OAEG;IACH,GAAG,CAAC,OAAO,EAAE,mBAAmB,GAAG,IAAI;IAQvC;;OAEG;IACH,MAAM,CAAC,YAAY,EAAE,YAAY,GAAG,GAAG,GAAG,IAAI;IAS9C;;OAEG;IACH,KAAK,IAAI,IAAI;CAKd"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Notification } from './Notification';
|
|
2
|
+
/**
|
|
3
|
+
* @fileoverview Storage class
|
|
4
|
+
* Stores the notifications in the local storage
|
|
5
|
+
*/
|
|
6
|
+
export declare class Storage {
|
|
7
|
+
private storeKey?;
|
|
8
|
+
constructor(storeKey?: string | undefined);
|
|
9
|
+
getAll(): any[];
|
|
10
|
+
save(data: Notification[]): void;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=Storage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Storage.d.ts","sourceRoot":"","sources":["../src/Storage.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;AAE7C;;;GAGG;AAEH,qBAAa,OAAO;IACN,OAAO,CAAC,QAAQ,CAAC;gBAAT,QAAQ,CAAC,EAAE,MAAM,YAAA;IAErC,MAAM,IAAI,GAAG,EAAE;IAKf,IAAI,CAAC,IAAI,EAAE,YAAY,EAAE;CAU1B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,82 +1,17 @@
|
|
|
1
|
-
import Backbone from 'backbone';
|
|
2
1
|
import { Editor } from 'grapesjs';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
export
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
declare class NotificationModel extends Backbone.Model<any, Backbone.ModelSetOptions, any> {
|
|
19
|
-
}
|
|
20
|
-
declare class Notification {
|
|
21
|
-
protected editor: NotificationEditor;
|
|
22
|
-
protected model: NotificationModel;
|
|
23
|
-
componentId: string | null;
|
|
24
|
-
group: string | null;
|
|
25
|
-
timeoutRef: NodeJS.Timeout | undefined;
|
|
26
|
-
message: string;
|
|
27
|
-
type: "info" | "warning" | "error" | "success";
|
|
28
|
-
protected options: NotificationOptions;
|
|
29
|
-
constructor(editor: NotificationEditor, model: NotificationModel);
|
|
30
|
-
select(): void;
|
|
31
|
-
remove(): void;
|
|
32
|
-
getSvgIcon(type: string): string;
|
|
33
|
-
private getDefaultOptions;
|
|
34
|
-
/**
|
|
35
|
-
* Get all components in the editor
|
|
36
|
-
* This is a heavy operation
|
|
37
|
-
*/
|
|
38
|
-
private getAllComponents;
|
|
39
|
-
private getAllComponentInPage;
|
|
40
|
-
private getAllChildrenComponent;
|
|
41
|
-
}
|
|
42
|
-
export interface NotificationEditor extends Editor {
|
|
43
|
-
NotificationManager: NotificationManager;
|
|
44
|
-
}
|
|
45
|
-
export interface NotificationManagerOptions {
|
|
46
|
-
style: Readonly<StyleInfo>;
|
|
47
|
-
container: HTMLElement;
|
|
48
|
-
maxNotifications?: number;
|
|
49
|
-
reverse?: boolean;
|
|
50
|
-
timeout?: number;
|
|
51
|
-
storeKey?: string;
|
|
52
|
-
icons?: {
|
|
53
|
-
info?: string;
|
|
54
|
-
warning?: string;
|
|
55
|
-
error?: string;
|
|
56
|
-
success?: string;
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
|
-
declare class NotificationManager extends Backbone.Collection<NotificationModel> {
|
|
60
|
-
protected editor: NotificationEditor;
|
|
61
|
-
protected options: NotificationManagerOptions;
|
|
62
|
-
constructor(models: Notification[], editor: NotificationEditor, options: NotificationManagerOptions);
|
|
63
|
-
/**
|
|
64
|
-
* Get all models
|
|
65
|
-
*/
|
|
66
|
-
getAll(): Notification[];
|
|
67
|
-
/**
|
|
68
|
-
* Listen to model changes
|
|
69
|
-
*/
|
|
70
|
-
modelChanged(e?: CustomEvent): void;
|
|
71
|
-
/**
|
|
72
|
-
* Listen to model individual changes
|
|
73
|
-
*/
|
|
74
|
-
modelInit(): void;
|
|
75
|
-
}
|
|
76
|
-
declare const _default: (editor: NotificationEditor, opts?: Partial<NotificationManagerOptions>) => void;
|
|
77
|
-
|
|
78
|
-
export {
|
|
79
|
-
_default as default,
|
|
2
|
+
import { NotificationManagerOptions, NOTIFICATION_CHANGED, NOTIFICATION_ADDED, NOTIFICATION_REMOVED, NOTIFICATION_CLEARED } from './NotificationManager';
|
|
3
|
+
export declare const NOTIFICATION_ADD = "notifications:add";
|
|
4
|
+
export declare const NOTIFICATION_REMOVE = "notifications:remove";
|
|
5
|
+
export declare const NOTIFICATION_CLEAR = "notifications:clear";
|
|
6
|
+
export { NOTIFICATION_CHANGED, NOTIFICATION_ADDED, NOTIFICATION_REMOVED, NOTIFICATION_CLEARED };
|
|
7
|
+
export type { NotificationManagerOptions } from './NotificationManager';
|
|
8
|
+
export type { NotificationOptions } from './Notification';
|
|
9
|
+
export { Notification } from './Notification';
|
|
10
|
+
declare const _default: (editor: Editor, opts?: Partial<NotificationManagerOptions>) => {
|
|
11
|
+
getAll: () => import("./Notification").Notification[];
|
|
12
|
+
add: (notification: any) => any;
|
|
13
|
+
remove: (notification: any) => any;
|
|
14
|
+
clear: () => any;
|
|
80
15
|
};
|
|
81
|
-
|
|
82
|
-
|
|
16
|
+
export default _default;
|
|
17
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,UAAU,CAAA;AAEjC,OAAO,EAEL,0BAA0B,EAC1B,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACrB,MAAM,uBAAuB,CAAA;AAK9B,eAAO,MAAM,gBAAgB,sBAAsB,CAAA;AACnD,eAAO,MAAM,mBAAmB,yBAAyB,CAAA;AACzD,eAAO,MAAM,kBAAkB,wBAAwB,CAAA;AAGvD,OAAO,EACL,oBAAoB,EACpB,kBAAkB,EAClB,oBAAoB,EACpB,oBAAoB,EACrB,CAAA;AAGD,YAAY,EAAE,0BAA0B,EAAE,MAAM,uBAAuB,CAAA;AACvE,YAAY,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAA;AACzD,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAA;yBAiB7B,QAAQ,MAAM,EAAE,OAAM,OAAO,CAAC,0BAA0B,CAAM;;wBAwDtD,GAAG;2BACA,GAAG;;;AAzD9B,wBA4DC"}
|