inviton-powerduck 0.0.71 → 0.0.72

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.
@@ -10,6 +10,7 @@ import { isNullOrEmpty } from "./utils/is-null-or-empty";
10
10
  import NotificationProvider from './../components/ui/notification';
11
11
  import PowerduckState from "../app/powerduck-state";
12
12
  import { IValidation, ValidationState } from './static-wrappers/interfaces/validation-interface';
13
+ import ScrollUtils from "./scroll-utils";
13
14
 
14
15
  export abstract class PowerduckViewModelBase extends Vue {
15
16
  blockRoot: boolean = true;
@@ -19,8 +20,8 @@ export abstract class PowerduckViewModelBase extends Vue {
19
20
  constructor(optionBuilder: OptionBuilder, vueInstance: any) {
20
21
  super(optionBuilder, vueInstance);
21
22
  this.v$ = useVuelidate({
22
- $scope: vueInstance
23
- }) as any as Validation;
23
+ $scope: vueInstance
24
+ }) as any as Validation;
24
25
  }
25
26
 
26
27
  /**
@@ -228,25 +229,7 @@ export abstract class PowerduckViewModelBase extends Vue {
228
229
  }
229
230
 
230
231
  scrollToFirstPossibleError(context: JQuery) {
231
- setTimeout(() => {
232
- var scrollContext = context.find(".form-group.has-danger, .input-group.has-danger").first();
233
- if (scrollContext.length == 0) {
234
- scrollContext = $(".modal.show .form-group.has-danger, .modal.show .input-group.has-danger").first();
235
- }
236
-
237
- if (scrollContext.length > 0) {
238
- //Prevents multiple scrolling in one run
239
- let lastScroll = (PowerduckState as any)._lastValidationScroll || 0;
240
- let now = new Date().getTime();
241
- if (now - lastScroll < 800) {
242
- return;
243
- } else {
244
- (PowerduckState as any)._lastValidationScroll = now;
245
- }
246
-
247
- this.scrollToElem(scrollContext.first()[0]);
248
- }
249
- }, 10);
232
+ ScrollUtils.scrollToFirstPossibleError(context);
250
233
  }
251
234
 
252
235
  /**
@@ -254,40 +237,7 @@ export abstract class PowerduckViewModelBase extends Vue {
254
237
  * @param elem
255
238
  */
256
239
  scrollToElem(elem: typeof Vue | Element | typeof Vue[] | Element[], mobileOffset?: boolean | number, mobileOffsetSmoothing?: boolean, animated?: boolean, instant?: boolean): void {
257
- if (elem == null) {
258
- return;
259
- }
260
-
261
- let offset = 0;
262
- let otherHeaderHeight = $("nav.navbar.fixed-top").height();
263
- if (otherHeaderHeight == null) {
264
- otherHeaderHeight = $("header").height();
265
- }
266
-
267
- if (($(window).width() as number < 768 && mobileOffset != false) || otherHeaderHeight > 0) {
268
- if ((mobileOffset as number) > 1) {
269
- offset = mobileOffset as number;
270
- } else {
271
- offset = $(".topnavbar-wrap").height();
272
- if (offset == 0 || offset == null || isNaN(offset)) {
273
- offset = otherHeaderHeight;
274
- }
275
- }
276
- }
277
-
278
- let itemTop = $(elem).first().offset()?.top;
279
- let modalParent = $(elem as HTMLElement).closest(".modal");
280
- if (modalParent.length == 0) {
281
- modalParent = null;
282
- } else {
283
- itemTop = modalParent.scrollTop() + itemTop - 95;
284
- }
285
-
286
- if (isNaN(offset)) {
287
- offset = 0;
288
- }
289
-
290
- this.scrollToPos(itemTop - offset, modalParent, animated, instant);
240
+ ScrollUtils.scrollToElem(elem, mobileOffset, mobileOffsetSmoothing, animated, instant);
291
241
  }
292
242
 
293
243
  /**
@@ -295,19 +245,7 @@ export abstract class PowerduckViewModelBase extends Vue {
295
245
  * @param elem
296
246
  */
297
247
  scrollToPos(position: number, context?: JQuery, animated?: boolean, instant?: boolean): void {
298
- if (instant != true) {
299
- setTimeout(() => {
300
- (context?.length > 0 ? context[0] : window).scrollTo({
301
- top: position,
302
- behavior: (animated != false ? 'smooth' : 'instant') as any
303
- });
304
- });
305
- } else {
306
- (context?.length > 0 ? context[0] : window).scrollTo({
307
- top: position,
308
- behavior: (animated != false ? 'smooth' : 'instant') as any
309
- });
310
- }
248
+ ScrollUtils.scrollToPos(position, context, animated, instant);
311
249
  }
312
250
 
313
251
  /**
@@ -0,0 +1,87 @@
1
+ import { Vue } from "vue-facing-decorator";
2
+ import PowerduckState from "../app/powerduck-state";
3
+
4
+ export default class ScrollUtils {
5
+ static scrollToFirstPossibleError(context: JQuery) {
6
+ setTimeout(() => {
7
+ var scrollContext = context.find(".form-group.has-danger, .input-group.has-danger").first();
8
+ if (scrollContext.length == 0) {
9
+ scrollContext = $(".modal.show .form-group.has-danger, .modal.show .input-group.has-danger").first();
10
+ }
11
+
12
+ if (scrollContext.length > 0) {
13
+ //Prevents multiple scrolling in one run
14
+ let lastScroll = (PowerduckState as any)._lastValidationScroll || 0;
15
+ let now = new Date().getTime();
16
+ if (now - lastScroll < 800) {
17
+ return;
18
+ } else {
19
+ (PowerduckState as any)._lastValidationScroll = now;
20
+ }
21
+
22
+ this.scrollToElem(scrollContext.first()[0]);
23
+ }
24
+ }, 10);
25
+ }
26
+
27
+ /**
28
+ * Scrolls to element
29
+ * @param elem
30
+ */
31
+ static scrollToElem(elem: typeof Vue | Element | typeof Vue[] | Element[], mobileOffset?: boolean | number, mobileOffsetSmoothing?: boolean, animated?: boolean, instant?: boolean): void {
32
+ if (elem == null) {
33
+ return;
34
+ }
35
+
36
+ let offset = 0;
37
+ let otherHeaderHeight = $("nav.navbar.fixed-top").height();
38
+ if (otherHeaderHeight == null) {
39
+ otherHeaderHeight = $("header").height();
40
+ }
41
+
42
+ if (($(window).width() as number < 768 && mobileOffset != false) || otherHeaderHeight > 0) {
43
+ if ((mobileOffset as number) > 1) {
44
+ offset = mobileOffset as number;
45
+ } else {
46
+ offset = $(".topnavbar-wrap").height();
47
+ if (offset == 0 || offset == null || isNaN(offset)) {
48
+ offset = otherHeaderHeight;
49
+ }
50
+ }
51
+ }
52
+
53
+ let itemTop = $(elem).first().offset()?.top;
54
+ let modalParent = $(elem as HTMLElement).closest(".modal");
55
+ if (modalParent.length == 0) {
56
+ modalParent = null;
57
+ } else {
58
+ itemTop = modalParent.scrollTop() + itemTop - 95;
59
+ }
60
+
61
+ if (isNaN(offset)) {
62
+ offset = 0;
63
+ }
64
+
65
+ this.scrollToPos(itemTop - offset, modalParent, animated, instant);
66
+ }
67
+
68
+ /**
69
+ * Scrolls to position
70
+ * @param elem
71
+ */
72
+ static scrollToPos(position: number, context?: JQuery, animated?: boolean, instant?: boolean): void {
73
+ if (instant != true) {
74
+ setTimeout(() => {
75
+ (context?.length > 0 ? context[0] : window).scrollTo({
76
+ top: position,
77
+ behavior: (animated != false ? 'smooth' : 'instant') as any
78
+ });
79
+ });
80
+ } else {
81
+ (context?.length > 0 ? context[0] : window).scrollTo({
82
+ top: position,
83
+ behavior: (animated != false ? 'smooth' : 'instant') as any
84
+ });
85
+ }
86
+ }
87
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "inviton-powerduck",
3
- "version": "0.0.71",
3
+ "version": "0.0.72",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "build": " vite build && vue-tsc --declaration --emitDeclarationOnly",