@silexlabs/grapesjs-notifications 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/LICENSE ADDED
@@ -0,0 +1,9 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024-current @silexlabs/grapesjs-notifications
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
6
+
7
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
8
+
9
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,175 @@
1
+ # GrapesJs Notifications Plugin
2
+
3
+ This GrapesJs plugin is designed to enhance the user experience within the editor by providing a robust notification system. This plugin captures and displays various types of notifications including errors, warnings, and activities, thereby facilitating a more interactive and responsive interface.
4
+
5
+ > This code is part of a larger project: [about Silex v3](https://www.silexlabs.org/silex-v3-kickoff/)
6
+
7
+ [DEMO](https://codepen.io/lexoyo/full/mdgzKQb)
8
+
9
+ Features
10
+
11
+ * [x] Notification types with corresponding icons
12
+ * [x] Select component attached to the notification
13
+ * [x] Customizable notification style
14
+ * [x] Internationalization
15
+ * [x] Local storage for persistent notifications
16
+ * [x] Maximum number of notifications to display
17
+ * [x] Notification timeout
18
+ * [x] Custom notification container
19
+ * [x] Notification events
20
+ * [x] Notification commands
21
+ * [x] editor.NotificationManager API
22
+ * [ ] Group notifications
23
+
24
+ ### HTML
25
+ ```html
26
+ <link href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" rel="stylesheet">
27
+ <script src="https://unpkg.com/grapesjs"></script>
28
+ <script src="https://unpkg.com/@silexlabs/grapesjs-notifications"></script>
29
+
30
+ <div id="gjs"></div>
31
+ ```
32
+
33
+ ### JS
34
+ ```js
35
+ const editor = grapesjs.init({
36
+ container: '#gjs',
37
+ height: '100%',
38
+ fromElement: true,
39
+ storageManager: false,
40
+ plugins: ['@silexlabs/grapesjs-notifications'],
41
+ });
42
+ ```
43
+
44
+ ### CSS
45
+ ```css
46
+ body, html {
47
+ margin: 0;
48
+ height: 100%;
49
+ }
50
+ ```
51
+
52
+ ## Summary
53
+
54
+ Plugin name: `@silexlabs/grapesjs-notifications`
55
+
56
+ API:
57
+
58
+ * Notification object:
59
+ * `type`: `error`, `warning`, `success`, `info`
60
+ * `message`: `string`
61
+ * `timeout`: `number` (ms)
62
+ * `component`: `string` or GrapesJs `Component` (optional)
63
+ * `editor.Notifications` methods:
64
+ * `add(notification)`
65
+ * `remove(notification)`
66
+ * `clear()`
67
+ * Commands: `editor.runCommand('notifications:add', notification)`
68
+ * `notifications:add` - Add a notification
69
+ * `notifications:remove` - Remove a notification
70
+ * `notifications:clear` - Clear all notifications
71
+ * Events:
72
+ * `notifications:changed` - When any change to the notifications occurs
73
+ * `notifications:added` - When a notification is added
74
+ * `notifications:removed` - When a notification is removed
75
+ * `notifications:cleared` - When all notifications are cleared
76
+
77
+ ## Options
78
+
79
+ | Option | Description | Type | Default |
80
+ |-|-|-|-
81
+ | `style` | Custom style for the notification | `object` | `{}` |
82
+ | `timeout` | Default timeout for the notification in ms | `number` | No timeout |
83
+ | `container` | Container for the notifications | `HTMLElement` | `document.body` |
84
+ | `storeKey` | Store notifications in local storage under this key | `string` | No storage |
85
+ | `icons` | Icons for the notification types | `object` | `{error: '\u2716', warning: '\u26A0', success: '\u2714', info: '\u2139'}` |
86
+ | `i18n` | Internationalization | `object` | Check the values in locale/en.js |
87
+ | `maxNotifications` | Maximum number of notifications to display | `number` | `5` |
88
+
89
+ ## Download
90
+
91
+ * CDN
92
+ * `https://unpkg.com/@silexlabs/grapesjs-notifications`
93
+ * NPM
94
+ * `npm i @silexlabs/grapesjs-notifications`
95
+ * GIT
96
+ * `git clone https://github.com/silexlabs/grapesjs-notifications.git`
97
+
98
+
99
+
100
+ ## Usage
101
+
102
+ Directly in the browser
103
+ ```html
104
+ <link href="https://unpkg.com/grapesjs/dist/css/grapes.min.css" rel="stylesheet"/>
105
+ <script src="https://unpkg.com/grapesjs"></script>
106
+ <script src="path/to/grapesjs-notifications.min.js"></script>
107
+
108
+ <div id="gjs"></div>
109
+
110
+ <script type="text/javascript">
111
+ var editor = grapesjs.init({
112
+ container: '#gjs',
113
+ // ...
114
+ plugins: ['@silexlabs/grapesjs-notifications'],
115
+ pluginsOpts: {
116
+ '@silexlabs/grapesjs-notifications': { /* options */ }
117
+ }
118
+ });
119
+ </script>
120
+ ```
121
+
122
+ Modern javascript
123
+ ```js
124
+ import grapesjs from 'grapesjs';
125
+ import plugin from '@silexlabs/grapesjs-notifications';
126
+ import 'grapesjs/dist/css/grapes.min.css';
127
+
128
+ const editor = grapesjs.init({
129
+ container : '#gjs',
130
+ // ...
131
+ plugins: [plugin],
132
+ pluginsOpts: {
133
+ [plugin]: { /* options */ }
134
+ }
135
+ // or
136
+ plugins: [
137
+ editor => plugin(editor, { /* options */ }),
138
+ ],
139
+ });
140
+ ```
141
+
142
+
143
+
144
+ ## Development
145
+
146
+ Clone the repository
147
+
148
+ ```sh
149
+ $ git clone https://github.com/silexlabs/grapesjs-notifications.git
150
+ $ cd @silexlabs/grapesjs-notifications
151
+ ```
152
+
153
+ Install dependencies
154
+
155
+ ```sh
156
+ $ npm i
157
+ ```
158
+
159
+ Start the dev server
160
+
161
+ ```sh
162
+ $ npm start
163
+ ```
164
+
165
+ Build the source
166
+
167
+ ```sh
168
+ $ npm run build
169
+ ```
170
+
171
+
172
+
173
+ ## License
174
+
175
+ MIT
@@ -0,0 +1,71 @@
1
+ import Backbone from 'backbone';
2
+ import { Component, Editor } from 'grapesjs';
3
+ import { StyleInfo } from 'lit/directives/style-map';
4
+
5
+ export interface NotificationOptions {
6
+ message: string;
7
+ timeout?: number;
8
+ component?: string | Component;
9
+ type: "info" | "warning" | "error" | "success";
10
+ icons: {
11
+ info: string;
12
+ warning: string;
13
+ error: string;
14
+ success: string;
15
+ };
16
+ }
17
+ export interface NotificationModel extends Backbone.Model<NotificationOptions> {
18
+ }
19
+ declare class Notification {
20
+ protected editor: NotificationEditor;
21
+ protected model: NotificationModel;
22
+ component: Component | null;
23
+ timeoutRef: NodeJS.Timeout | undefined;
24
+ message: string;
25
+ type: "info" | "warning" | "error" | "success";
26
+ protected options: NotificationOptions;
27
+ constructor(editor: NotificationEditor, model: NotificationModel);
28
+ select(): void;
29
+ remove(): void;
30
+ getSvgIcon(type: string): string;
31
+ }
32
+ export interface NotificationEditor extends Editor {
33
+ NotificationManager: NotificationManager;
34
+ }
35
+ export interface NotificationManagerOptions {
36
+ style: Readonly<StyleInfo>;
37
+ container: HTMLElement;
38
+ maxNotifications?: number;
39
+ timeout?: number;
40
+ storeKey?: string;
41
+ icons?: {
42
+ info?: string;
43
+ warning?: string;
44
+ error?: string;
45
+ success?: string;
46
+ };
47
+ }
48
+ declare class NotificationManager extends Backbone.Collection<NotificationModel> {
49
+ protected editor: NotificationEditor;
50
+ protected options: NotificationManagerOptions;
51
+ constructor(models: Notification[], editor: NotificationEditor, options: NotificationManagerOptions);
52
+ /**
53
+ * Get all models
54
+ */
55
+ getAll(): Notification[];
56
+ /**
57
+ * Listen to model changes
58
+ */
59
+ modelChanged(e?: CustomEvent): void;
60
+ /**
61
+ * Listen to model individual changes
62
+ */
63
+ modelInit(): void;
64
+ }
65
+ declare const _default: (editor: NotificationEditor, opts?: Partial<NotificationManagerOptions>) => void;
66
+
67
+ export {
68
+ _default as default,
69
+ };
70
+
71
+ export {};
package/locale/en.js ADDED
@@ -0,0 +1,12 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _default = exports.default = {
8
+ '@silexlabs/grapesjs-notifications': {
9
+ 'Close': 'Dismiss',
10
+ 'Select': 'Select component {componentName}'
11
+ }
12
+ };
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ Object.defineProperty(exports, "en", {
8
+ enumerable: true,
9
+ get: function () {
10
+ return _en.default;
11
+ }
12
+ });
13
+ var _en = _interopRequireDefault(require("./en"));
package/package.json ADDED
@@ -0,0 +1,47 @@
1
+ {
2
+ "name": "@silexlabs/grapesjs-notifications",
3
+ "version": "0.0.1",
4
+ "description": "This GrapesJs plugin is designed to enhance the user experience within the editor by providing a robust notification system. This plugin captures and displays various types of notifications including errors, warnings, and activities, thereby facilitating a more interactive and responsive interface.",
5
+ "main": "dist/index.js",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/silexlabs/grapesjs-notifications.git"
9
+ },
10
+ "scripts": {
11
+ "start": "grapesjs-cli serve",
12
+ "build": "grapesjs-cli build --patch=false"
13
+ },
14
+ "devDependencies": {
15
+ "grapesjs-cli": "^4.1.3"
16
+ },
17
+ "peerDependencies": {
18
+ "grapesjs": "^0.21.10",
19
+ "lit": "^3.1.2"
20
+ },
21
+ "author": "@lexoyo",
22
+ "license": "MIT",
23
+ "bugs": {
24
+ "url": "https://github.com/silexlabs/Silex/issues"
25
+ },
26
+ "homepage": "https://github.com/silexlabs/grapesjs-notifications#readme",
27
+ "keywords": [
28
+ "grapesjs",
29
+ "plugin",
30
+ "grapesjs-plugin",
31
+ "notifications",
32
+ "web-design",
33
+ "web-development",
34
+ "UI",
35
+ "UX",
36
+ "error-handling",
37
+ "warning-system",
38
+ "activity-tracker",
39
+ "silex",
40
+ "silexlabs",
41
+ "no-code",
42
+ "editor",
43
+ "web-editor",
44
+ "frontend",
45
+ "website-builder"
46
+ ]
47
+ }