inviton-powerduck 0.0.208 → 0.0.210

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.
@@ -1,6 +1,6 @@
1
- export const SKILIFT_SVG: string = `
2
- <svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000" preserveAspectRatio="xMidYMid meet">
3
- <g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)" fill="currentColor" stroke="none">
4
- <path d="M3911 4254 l-1153 -354 -40 34 c-77 66 -211 76 -290 20 -57 -40 -107 -107 -114 -153 l-6 -38 -1127 -345 -1126 -345 -3 -103 c-2 -94 -1 -102 15 -98 10 3 529 161 1154 353 l1135 347 43 -28 42 -29 -5 -55 c-2 -30 -21 -279 -42 -552 l-38 -498 -360 0 c-200 0 -390 -5 -426 -11 -173 -27 -319 -153 -371 -320 -18 -56 -19 -99 -19 -594 0 -495 1 -538 19 -594 50 -161 183 -281 350 -317 98 -20 1924 -20 2022 0 167 36 300 156 350 317 18 56 19 99 19 588 0 444 -2 536 -16 586 -44 170 -197 307 -374 335 -36 5 -227 10 -426 10 l-360 0 -38 498 c-21 273 -40 522 -43 552 -5 53 -4 56 25 73 40 23 72 69 93 131 l17 49 153 48 c85 26 309 95 499 153 852 260 1595 488 1598 490 1 2 1 48 0 103 l-3 100 -1154 -353z m-1913 -2666 l2 -358 -260 0 -260 0 0 353 c0 195 3 357 7 361 4 3 119 5 257 4 l251 -3 3 -357z m820 0 l2 -358 -260 0 -260 0 0 353 c0 195 3 357 7 361 4 3 119 5 257 4 l251 -3 3 -357z m820 0 l2 -358 -260 0 -260 0 0 353 c0 195 3 357 7 361 4 3 119 5 257 4 l251 -3 3 -357z"/>
5
- </g>
6
- </svg>`;
1
+ export const SKILIFT_SVG: string = `
2
+ <svg version="1.0" xmlns="http://www.w3.org/2000/svg" width="512.000000pt" height="512.000000pt" viewBox="0 0 512.000000 512.000000" preserveAspectRatio="xMidYMid meet">
3
+ <g transform="translate(0.000000,512.000000) scale(0.100000,-0.100000)" fill="currentColor" stroke="none">
4
+ <path d="M3911 4254 l-1153 -354 -40 34 c-77 66 -211 76 -290 20 -57 -40 -107 -107 -114 -153 l-6 -38 -1127 -345 -1126 -345 -3 -103 c-2 -94 -1 -102 15 -98 10 3 529 161 1154 353 l1135 347 43 -28 42 -29 -5 -55 c-2 -30 -21 -279 -42 -552 l-38 -498 -360 0 c-200 0 -390 -5 -426 -11 -173 -27 -319 -153 -371 -320 -18 -56 -19 -99 -19 -594 0 -495 1 -538 19 -594 50 -161 183 -281 350 -317 98 -20 1924 -20 2022 0 167 36 300 156 350 317 18 56 19 99 19 588 0 444 -2 536 -16 586 -44 170 -197 307 -374 335 -36 5 -227 10 -426 10 l-360 0 -38 498 c-21 273 -40 522 -43 552 -5 53 -4 56 25 73 40 23 72 69 93 131 l17 49 153 48 c85 26 309 95 499 153 852 260 1595 488 1598 490 1 2 1 48 0 103 l-3 100 -1154 -353z m-1913 -2666 l2 -358 -260 0 -260 0 0 353 c0 195 3 357 7 361 4 3 119 5 257 4 l251 -3 3 -357z m820 0 l2 -358 -260 0 -260 0 0 353 c0 195 3 357 7 361 4 3 119 5 257 4 l251 -3 3 -357z m820 0 l2 -358 -260 0 -260 0 0 353 c0 195 3 357 7 361 4 3 119 5 257 4 l251 -3 3 -357z"/>
5
+ </g>
6
+ </svg>`;
@@ -11,7 +11,6 @@ export enum NotificationType {
11
11
  Success = 'success',
12
12
  Warning = 'warning',
13
13
  Danger = 'danger',
14
- Error = 'danger',
15
14
  }
16
15
 
17
16
  export enum NotificationIcon {
@@ -119,14 +118,30 @@ interface NotificationDisplayArgs {
119
118
  */
120
119
  containerClass?: string;
121
120
  };
121
+
122
+ /**
123
+ * Optional custom template passed directly to bootstrap-notify.
124
+ * When not provided, a default template is used.
125
+ */
126
+ template?: string | ((containerClass: string) => string);
127
+
122
128
  }
123
129
 
124
- const NotificationUtils = (function () {
125
- function getArgs(
130
+ const isMobileViewport = (): boolean => typeof window !== 'undefined' && window.innerWidth < 768;
131
+
132
+ const applyMobileCenterOffset = (element: any, offsetX: number): void => {
133
+ element?.css({
134
+ left: `${offsetX}px`,
135
+ right: `${offsetX}px`,
136
+ });
137
+ };
138
+
139
+ const NotificationUtils = (() => {
140
+ const getArgs = (
126
141
  messageOrArgs: string | NotificationDisplayArgs,
127
142
  icon?: string,
128
143
  title?: string,
129
- ): NotificationDisplayArgs {
144
+ ): NotificationDisplayArgs => {
130
145
  const args = messageOrArgs as NotificationDisplayArgs;
131
146
  if (args.messageHtml != null) {
132
147
  return args;
@@ -137,13 +152,13 @@ const NotificationUtils = (function () {
137
152
  icon,
138
153
  title,
139
154
  };
140
- }
155
+ };
141
156
 
142
- function getPlacement(args: NotificationDisplayArgs): any {
143
- const placement = args.placement || NotificationPlacement.TopCenter;
157
+ const getPlacement = (args: NotificationDisplayArgs): any => {
158
+ const placement = typeof args.placement === 'number' ? args.placement : NotificationPlacement.TopCenter;
144
159
  const placementEnd = (<number>placement).toString();
145
160
  const lastNumber = Number(placementEnd.substring(placementEnd.length - 1));
146
- const from = placement < 10 ? 'top' : 'bottom';
161
+ const from = placement >= NotificationPlacement.BottomLeft ? 'bottom' : 'top';
147
162
  let align;
148
163
 
149
164
  if (lastNumber == 0) {
@@ -154,41 +169,91 @@ const NotificationUtils = (function () {
154
169
  align = 'right';
155
170
  }
156
171
 
172
+ if (isMobileViewport() && (from === 'bottom' || from === 'top')) {
173
+ align = 'center';
174
+ }
175
+
157
176
  return {
158
177
  from,
159
178
  align,
160
179
  };
161
- }
180
+ };
181
+
182
+ const buildTemplate = (containerClass: string): string => `<div data-notify="container" class="${containerClass} alert alert-{0}" role="alert" style="z-index:999999">
183
+ <button type="button" class="btn-close" data-notify="dismiss" aria-label="Close"></button>
184
+ <span data-notify="icon"></span>
185
+ <span data-notify="title">{1}</span>
186
+ <span data-notify="message">{2}</span>
187
+ <div class="progress" data-notify="progressbar">
188
+ <div class="progress-bar progress-bar-{0}" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width:0%;"></div>
189
+ </div>
190
+ <a href="{3}" target="{4}" data-notify="url"></a>
191
+ </div>`.replace(/\s{2,}/g, ' ').trim();
192
+
193
+ const resolveTemplate = (args: NotificationDisplayArgs, containerClass: string): string => {
194
+ if (typeof args.template === 'string') {
195
+ return args.template;
196
+ }
197
+
198
+ if (typeof args.template === 'function') {
199
+ return args.template(containerClass);
200
+ }
162
201
 
163
- function show(
202
+ return buildTemplate(containerClass);
203
+ };
204
+
205
+ const show = (
164
206
  messageOrArgs: string | NotificationDisplayArgs,
165
207
  icon?: string,
166
208
  title?: string,
167
- ): void {
209
+ ): void => {
168
210
  const args = getArgs(
169
211
  messageOrArgs,
170
212
  icon,
171
213
  title,
172
214
  );
173
215
 
216
+ const containerClass = args.cssClasses?.containerClass || 'col-xs-11 col-sm-4';
217
+ const timerValue = typeof args.timeout === 'number' ? args.timeout : NotificationProviderConfig.defaultTimeout;
218
+ const delayValue = typeof args.delay === 'number' ? args.delay : NotificationProviderConfig.defaultDelay;
219
+ const placementOptions = getPlacement(args);
220
+ const defaultEnterAnimation = placementOptions.from === 'bottom' ? NotificationAnimation.FadeInUp : NotificationAnimation.FadeInDown;
221
+ const defaultExitAnimation = placementOptions.from === 'bottom' ? NotificationAnimation.FadeOutDown : NotificationAnimation.FadeOutUp;
222
+ const offsetOptions = {
223
+ x: 20,
224
+ y: 20,
225
+ };
226
+
227
+ const shouldForceMobileCenter = isMobileViewport() && placementOptions.align === 'center';
228
+ const onShowHandler = shouldForceMobileCenter
229
+ ? function (this: any) {
230
+ applyMobileCenterOffset(this, offsetOptions.x);
231
+ }
232
+ : undefined;
233
+
234
+ const template = resolveTemplate(args, containerClass);
235
+
174
236
  (jQuery as any).notify({
175
237
  icon: args.icon,
176
238
  message: args.messageHtml,
177
239
  title: args.title,
178
240
  }, {
179
- type: args.type || 'primary',
180
- timer: args.timeout > -1 ? args.timeout : NotificationProviderConfig.defaultTimeout,
181
- delay: args.delay > -1 ? args.delay : NotificationProviderConfig.defaultDelay,
182
- placement: getPlacement(args),
241
+ type: args.type || NotificationType.Primary,
242
+ timer: timerValue,
243
+ delay: delayValue,
244
+ placement: placementOptions,
183
245
  z_index: 99999,
184
- newest_on_top: (args.newestTop || false),
246
+ newest_on_top: args.newestTop ?? false,
247
+ icon_type: 'class',
185
248
  animate: {
186
- enter: (args.animation?.enter || 'animate__animated animate__fadeInDown'),
187
- exit: (args.animation?.exit || 'animate__animated animate__fadeOutUp'),
249
+ enter: args.animation?.enter || defaultEnterAnimation,
250
+ exit: args.animation?.exit || defaultExitAnimation,
188
251
  },
189
- template: `<div data-notify="container" class="${args.cssClasses?.containerClass ? args.cssClasses.containerClass : 'col-xs-11 col-sm-4'} alert alert-{0}" role="alert" style="z-index:999999"><div type="button" aria-hidden="true" class="btn-close close" data-notify="dismiss"></div><span data-notify="icon"></span> <span data-notify="title">{1}</span> <span data-notify="message">{2}</span><div class="progress" data-notify="progressbar"><div class="progress-bar progress-bar-{0}" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%;"></div></div><a href="{3}" target="{4}" data-notify="url"></a></div>`,
252
+ offset: offsetOptions,
253
+ template,
254
+ onShow: onShowHandler,
190
255
  });
191
- }
256
+ };
192
257
 
193
258
  return {
194
259
  show,
@@ -236,24 +301,33 @@ export default class NotificationProvider {
236
301
  }
237
302
 
238
303
  /**
239
- * Displays error message
304
+ * Displays danger\error message
240
305
  *
241
- * @param message Error message
306
+ * @param message Danger\Error message
242
307
  */
243
- static showErrorMessage(message: string): void;
308
+ static showErrorMessage(message: string, placement?: NotificationPlacement): void;
309
+ static showErrorMessage(message: string, title?: string, placement?: NotificationPlacement): void;
244
310
 
245
311
  /**
246
- * Displays error message
312
+ * Displays danger\error message
247
313
  *
248
- * @param messageHtml Error message
314
+ * @param messageHtml Danger\Error message
249
315
  * @param title Title of the message
250
316
  */
251
- static showErrorMessage(messageHtml: string, title?: string): void {
317
+ static showErrorMessage(
318
+ messageHtml: string,
319
+ titleOrPlacement?: string | NotificationPlacement,
320
+ placement?: NotificationPlacement,
321
+ ): void {
322
+ const resolvedTitle = typeof titleOrPlacement === 'string' ? titleOrPlacement : undefined;
323
+ const resolvedPlacement = typeof titleOrPlacement === 'number' ? titleOrPlacement : placement;
324
+
252
325
  NotificationUtils.show({
253
326
  messageHtml,
254
- title,
327
+ title: resolvedTitle,
255
328
  icon: NotificationIcon.Exclamation,
256
- type: NotificationType.Error,
329
+ type: NotificationType.Danger,
330
+ placement: resolvedPlacement ?? NotificationPlacement.TopCenter,
257
331
  });
258
332
  }
259
333
 
@@ -261,8 +335,10 @@ export default class NotificationProvider {
261
335
  * Displays success message
262
336
  *
263
337
  * @param message Success message
338
+ //
264
339
  */
265
- static showSuccessMessage(message: string): void;
340
+ static showSuccessMessage(message: string, placement?: NotificationPlacement): void;
341
+ static showSuccessMessage(message: string, title?: string, placement?: NotificationPlacement): void;
266
342
 
267
343
  /**
268
344
  * Displays success message
@@ -270,12 +346,45 @@ export default class NotificationProvider {
270
346
  * @param messageHtml Success message
271
347
  * @param title Title of the message
272
348
  */
273
- static showSuccessMessage(messageHtml: string, title?: string): void {
349
+ static showSuccessMessage(
350
+ messageHtml: string,
351
+ titleOrPlacement?: string | NotificationPlacement,
352
+ placement?: NotificationPlacement,
353
+ ): void {
354
+ const resolvedTitle = typeof titleOrPlacement === 'string' ? titleOrPlacement : undefined;
355
+ const resolvedPlacement = typeof titleOrPlacement === 'number' ? titleOrPlacement : placement;
356
+
274
357
  NotificationUtils.show({
275
358
  messageHtml,
276
- title,
359
+ title: resolvedTitle,
277
360
  icon: NotificationIcon.Checkmark,
278
361
  type: NotificationType.Success,
362
+ placement: resolvedPlacement ?? NotificationPlacement.TopCenter,
363
+ });
364
+ }
365
+
366
+ /**
367
+ * Displays warning message
368
+ *
369
+ * @param messageHtml Success message
370
+ * @param title Title of the message
371
+ */
372
+ static showWarningMessage(message: string, placement?: NotificationPlacement): void;
373
+ static showWarningMessage(message: string, title?: string, placement?: NotificationPlacement): void;
374
+ static showWarningMessage(
375
+ messageHtml: string,
376
+ titleOrPlacement?: string | NotificationPlacement,
377
+ placement?: NotificationPlacement,
378
+ ): void {
379
+ const resolvedTitle = typeof titleOrPlacement === 'string' ? titleOrPlacement : undefined;
380
+ const resolvedPlacement = typeof titleOrPlacement === 'number' ? titleOrPlacement : placement;
381
+
382
+ NotificationUtils.show({
383
+ messageHtml,
384
+ title: resolvedTitle,
385
+ icon: NotificationIcon.Exclamation,
386
+ type: NotificationType.Warning,
387
+ placement: resolvedPlacement ?? NotificationPlacement.TopRight,
279
388
  });
280
389
  }
281
390
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "inviton-powerduck",
3
3
  "type": "module",
4
- "version": "0.0.208",
4
+ "version": "0.0.210",
5
5
  "files": [
6
6
  "app/",
7
7
  "common/",