@roots/bud-client 2024.7.2-8 → 2024.7.4-7

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,3 @@
1
- /// <reference types="webpack-env" />
2
1
  /**
3
2
  * Initializes bud.js HMR handling
4
3
  */
package/lib/hot/client.js CHANGED
@@ -111,7 +111,7 @@ export const client = async (queryString, webpackHot) => {
111
111
  if (payload.name !== options.name)
112
112
  return;
113
113
  window.bud.controllers.map(controller => controller?.update(payload));
114
- if (payload.errors?.length > 0)
114
+ if (payload.errors?.length)
115
115
  return;
116
116
  if (payload.action === `built` || payload.action === `sync`) {
117
117
  if (isStale(payload.hash))
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  /**
3
2
  * Indicator web component
4
3
  */
@@ -11,7 +10,7 @@ export declare class Component extends HTMLElement {
11
10
  /**
12
11
  * Timer
13
12
  */
14
- timeout: NodeJS.Timeout;
13
+ timeout?: NodeJS.Timeout;
15
14
  /**
16
15
  * Component name
17
16
  */
@@ -24,6 +24,10 @@ export class Component extends HTMLElement {
24
24
  * Component name
25
25
  */
26
26
  this.name = `bud-activity-indicator`;
27
+ /**
28
+ * Has component rendered
29
+ */
30
+ this.rendered = false;
27
31
  this.renderShadow();
28
32
  }
29
33
  /**
@@ -32,9 +36,9 @@ export class Component extends HTMLElement {
32
36
  onError() {
33
37
  this.show();
34
38
  this.shadowRoot
35
- .querySelector(this.selector)
36
- .classList.remove(`warning`, `success`, `pending`);
37
- this.shadowRoot.querySelector(this.selector).classList.add(`error`);
39
+ ?.querySelector(this.selector)
40
+ ?.classList.remove(`warning`, `success`, `pending`);
41
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`error`);
38
42
  this.hide();
39
43
  }
40
44
  /**
@@ -43,9 +47,9 @@ export class Component extends HTMLElement {
43
47
  onPending() {
44
48
  this.show();
45
49
  this.shadowRoot
46
- .querySelector(this.selector)
47
- .classList.remove(`error`, `warning`, `success`);
48
- this.shadowRoot.querySelector(this.selector).classList.add(`pending`);
50
+ ?.querySelector(this.selector)
51
+ ?.classList.remove(`error`, `warning`, `success`);
52
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`pending`);
49
53
  this.hide();
50
54
  }
51
55
  /**
@@ -54,9 +58,9 @@ export class Component extends HTMLElement {
54
58
  onSuccess() {
55
59
  this.show();
56
60
  this.shadowRoot
57
- .querySelector(this.selector)
58
- .classList.remove(`error`, `warning`, `pending`);
59
- this.shadowRoot.querySelector(this.selector).classList.add(`success`);
61
+ ?.querySelector(this.selector)
62
+ ?.classList.remove(`error`, `warning`, `pending`);
63
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`success`);
60
64
  this.hide();
61
65
  }
62
66
  /**
@@ -65,9 +69,9 @@ export class Component extends HTMLElement {
65
69
  onWarning() {
66
70
  this.show();
67
71
  this.shadowRoot
68
- .querySelector(this.selector)
69
- .classList.remove(`error`, `success`, `pending`);
70
- this.shadowRoot.querySelector(this.selector).classList.add(`warning`);
72
+ ?.querySelector(this.selector)
73
+ ?.classList.remove(`error`, `success`, `pending`);
74
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`warning`);
71
75
  this.hide();
72
76
  }
73
77
  attributeChangedCallback() {
@@ -97,7 +101,9 @@ export class Component extends HTMLElement {
97
101
  */
98
102
  hide() {
99
103
  this.timeout = setTimeout(() => {
100
- this.shadowRoot.querySelector(this.selector).classList.remove(`show`);
104
+ this.shadowRoot
105
+ ?.querySelector(this.selector)
106
+ ?.classList.remove(`show`);
101
107
  }, 2000);
102
108
  }
103
109
  /**
@@ -156,6 +162,6 @@ export class Component extends HTMLElement {
156
162
  */
157
163
  show() {
158
164
  this.timeout && clearTimeout(this.timeout);
159
- this.shadowRoot.querySelector(this.selector).classList.add(`show`);
165
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`show`);
160
166
  }
161
167
  }
@@ -1,4 +1,3 @@
1
- /// <reference types="node" resolution-mode="require"/>
2
1
  /**
3
2
  * Activity indicator controller
4
3
  */
@@ -14,7 +13,7 @@ export declare class Controller {
14
13
  /**
15
14
  * Timer handler
16
15
  */
17
- timer: NodeJS.Timeout;
16
+ timer?: NodeJS.Timeout;
18
17
  /**
19
18
  * Initialization
20
19
  */
@@ -35,9 +35,13 @@ export class Controller {
35
35
  * Update activity indicator
36
36
  */
37
37
  update(payload) {
38
- this.node.toggleAttribute(`has-errors`, payload.errors?.length > 0);
39
- this.node.toggleAttribute(`has-warnings`, payload.warnings?.length > 0);
38
+ if (!payload.action)
39
+ return;
40
40
  this.node.setAttribute(`action`, payload.action);
41
+ this.node.toggleAttribute(`has-errors`, payload?.errors?.length && payload.errors.length > 0 ? true : false);
42
+ this.node.toggleAttribute(`has-warnings`, payload?.warnings?.length && payload.warnings?.length > 0
43
+ ? true
44
+ : false);
41
45
  this.addNode();
42
46
  }
43
47
  }
@@ -25,7 +25,7 @@ export declare const injectEvents: (eventSource: EventSourceFactory) => {
25
25
  /**
26
26
  * EventSource `addMessageListener` handler
27
27
  */
28
- addListener(listener: Listener): this;
28
+ addListener(listener: Listener): any;
29
29
  onerror: (this: EventSource, ev: Event) => any;
30
30
  readonly readyState: number;
31
31
  readonly url: string;
@@ -35,10 +35,10 @@ export declare const injectEvents: (eventSource: EventSourceFactory) => {
35
35
  readonly OPEN: 1;
36
36
  readonly CLOSED: 2;
37
37
  addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
38
- addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;
38
+ addEventListener(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | AddEventListenerOptions): void;
39
39
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
40
- removeEventListener<K_1 extends keyof EventSourceEventMap>(type: K_1, listener: (this: EventSource, ev: EventSourceEventMap[K_1]) => any, options?: boolean | EventListenerOptions): void;
41
- removeEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | EventListenerOptions): void;
40
+ removeEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
41
+ removeEventListener(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | EventListenerOptions): void;
42
42
  removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
43
43
  dispatchEvent(event: Event): boolean;
44
44
  };
@@ -69,7 +69,7 @@ export declare const injectEvents: (eventSource: EventSourceFactory) => {
69
69
  /**
70
70
  * EventSource `addMessageListener` handler
71
71
  */
72
- addListener(listener: Listener): this;
72
+ addListener(listener: Listener): any;
73
73
  onerror: (this: EventSource, ev: Event) => any;
74
74
  readonly readyState: number;
75
75
  readonly url: string;
@@ -79,10 +79,10 @@ export declare const injectEvents: (eventSource: EventSourceFactory) => {
79
79
  readonly OPEN: 1;
80
80
  readonly CLOSED: 2;
81
81
  addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
82
- addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;
82
+ addEventListener(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | AddEventListenerOptions): void;
83
83
  addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
84
- removeEventListener<K_1 extends keyof EventSourceEventMap>(type: K_1, listener: (this: EventSource, ev: EventSourceEventMap[K_1]) => any, options?: boolean | EventListenerOptions): void;
85
- removeEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | EventListenerOptions): void;
84
+ removeEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | EventListenerOptions): void;
85
+ removeEventListener(type: string, listener: (this: EventSource, event: MessageEvent) => any, options?: boolean | EventListenerOptions): void;
86
86
  removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
87
87
  dispatchEvent(event: Event): boolean;
88
88
  };
package/lib/index.d.ts CHANGED
@@ -9,6 +9,5 @@
9
9
  *
10
10
  * @packageDocumentation
11
11
  */
12
- import domReady from '@roots/bud-client/dom-ready';
13
- import lazy from '@roots/bud-client/lazy';
14
- export { domReady, lazy };
12
+ export { default as domReady } from '@roots/bud-client/dom-ready';
13
+ export { default as lazy } from '@roots/bud-client/lazy';
package/lib/index.js CHANGED
@@ -11,6 +11,5 @@
11
11
  *
12
12
  * @packageDocumentation
13
13
  */
14
- import domReady from '@roots/bud-client/dom-ready';
15
- import lazy from '@roots/bud-client/lazy';
16
- export { domReady, lazy };
14
+ export { default as domReady } from '@roots/bud-client/dom-ready';
15
+ export { default as lazy } from '@roots/bud-client/lazy';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-client",
3
- "version": "2024.7.2-8",
3
+ "version": "2024.7.4-7",
4
4
  "description": "Client scripts for @roots/bud",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -44,11 +44,13 @@
44
44
  "src"
45
45
  ],
46
46
  "type": "module",
47
+ "module": "./lib/index.js",
48
+ "types": "./lib/index.d.ts",
47
49
  "exports": {
48
50
  ".": "./lib/index.js",
49
51
  "./dom-ready": "./lib/dom-ready.js",
50
52
  "./lazy": "./lib/lazy.js",
51
- "./lib/*": "./lib/*"
53
+ "./lib/*": "./lib/*.js"
52
54
  },
53
55
  "typesVersions": {
54
56
  "*": {
@@ -62,20 +64,18 @@
62
64
  "./lib/lazy.d.ts"
63
65
  ],
64
66
  "lib/*": [
65
- "./lib/*"
67
+ "./lib/*.d.ts"
66
68
  ]
67
69
  }
68
70
  },
69
- "types": "./lib/index.d.ts",
70
- "module": "./lib/index.mjs",
71
71
  "devDependencies": {
72
- "@roots/bud": "2024.7.2-8",
72
+ "@roots/bud": "2024.7.4-7",
73
73
  "@skypack/package-check": "0.2.2",
74
- "@types/node": "20.12.8",
75
- "@types/webpack-env": "1.18.4"
74
+ "@types/node": "20.14.9",
75
+ "@types/webpack-env": "1.18.5"
76
76
  },
77
77
  "dependencies": {
78
- "tslib": "2.6.2"
78
+ "tslib": "2.6.3"
79
79
  },
80
80
  "volta": {
81
81
  "extends": "../../../package.json"
package/src/hot/client.ts CHANGED
@@ -137,7 +137,7 @@ export const client = async (
137
137
  if (payload.name !== options.name) return
138
138
  window.bud.controllers.map(controller => controller?.update(payload))
139
139
 
140
- if (payload.errors?.length > 0) return
140
+ if (payload.errors?.length) return
141
141
 
142
142
  if (payload.action === `built` || payload.action === `sync`) {
143
143
  if (isStale(payload.hash)) return
@@ -20,7 +20,7 @@ export class Component extends HTMLElement {
20
20
  /**
21
21
  * Timer
22
22
  */
23
- public timeout: NodeJS.Timeout
23
+ public timeout?: NodeJS.Timeout
24
24
 
25
25
  /**
26
26
  * Component name
@@ -30,7 +30,7 @@ export class Component extends HTMLElement {
30
30
  /**
31
31
  * Has component rendered
32
32
  */
33
- public rendered: boolean
33
+ public rendered: boolean = false
34
34
 
35
35
  /**
36
36
  * Class constructor
@@ -47,9 +47,9 @@ export class Component extends HTMLElement {
47
47
  this.show()
48
48
 
49
49
  this.shadowRoot
50
- .querySelector(this.selector)
51
- .classList.remove(`warning`, `success`, `pending`)
52
- this.shadowRoot.querySelector(this.selector).classList.add(`error`)
50
+ ?.querySelector(this.selector)
51
+ ?.classList.remove(`warning`, `success`, `pending`)
52
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`error`)
53
53
 
54
54
  this.hide()
55
55
  }
@@ -60,10 +60,10 @@ export class Component extends HTMLElement {
60
60
  this.show()
61
61
 
62
62
  this.shadowRoot
63
- .querySelector(this.selector)
64
- .classList.remove(`error`, `warning`, `success`)
63
+ ?.querySelector(this.selector)
64
+ ?.classList.remove(`error`, `warning`, `success`)
65
65
 
66
- this.shadowRoot.querySelector(this.selector).classList.add(`pending`)
66
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`pending`)
67
67
 
68
68
  this.hide()
69
69
  }
@@ -74,10 +74,10 @@ export class Component extends HTMLElement {
74
74
  this.show()
75
75
 
76
76
  this.shadowRoot
77
- .querySelector(this.selector)
78
- .classList.remove(`error`, `warning`, `pending`)
77
+ ?.querySelector(this.selector)
78
+ ?.classList.remove(`error`, `warning`, `pending`)
79
79
 
80
- this.shadowRoot.querySelector(this.selector).classList.add(`success`)
80
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`success`)
81
81
 
82
82
  this.hide()
83
83
  }
@@ -88,10 +88,10 @@ export class Component extends HTMLElement {
88
88
  this.show()
89
89
 
90
90
  this.shadowRoot
91
- .querySelector(this.selector)
92
- .classList.remove(`error`, `success`, `pending`)
91
+ ?.querySelector(this.selector)
92
+ ?.classList.remove(`error`, `success`, `pending`)
93
93
 
94
- this.shadowRoot.querySelector(this.selector).classList.add(`warning`)
94
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`warning`)
95
95
 
96
96
  this.hide()
97
97
  }
@@ -127,7 +127,9 @@ export class Component extends HTMLElement {
127
127
  */
128
128
  public hide() {
129
129
  this.timeout = setTimeout(() => {
130
- this.shadowRoot.querySelector(this.selector).classList.remove(`show`)
130
+ this.shadowRoot
131
+ ?.querySelector(this.selector)
132
+ ?.classList.remove(`show`)
131
133
  }, 2000)
132
134
  }
133
135
 
@@ -190,6 +192,6 @@ export class Component extends HTMLElement {
190
192
  */
191
193
  public show() {
192
194
  this.timeout && clearTimeout(this.timeout)
193
- this.shadowRoot.querySelector(this.selector).classList.add(`show`)
195
+ this.shadowRoot?.querySelector(this.selector)?.classList.add(`show`)
194
196
  }
195
197
  }
@@ -15,7 +15,7 @@ export class Controller {
15
15
  /**
16
16
  * Timer handler
17
17
  */
18
- public timer: NodeJS.Timeout
18
+ public timer?: NodeJS.Timeout
19
19
 
20
20
  /**
21
21
  * Initialization
@@ -49,12 +49,22 @@ export class Controller {
49
49
  * Update activity indicator
50
50
  */
51
51
  public update(payload: Payload) {
52
- this.node.toggleAttribute(`has-errors`, payload.errors?.length > 0)
53
-
54
- this.node.toggleAttribute(`has-warnings`, payload.warnings?.length > 0)
52
+ if (!payload.action) return
55
53
 
56
54
  this.node.setAttribute(`action`, payload.action)
57
55
 
56
+ this.node.toggleAttribute(
57
+ `has-errors`,
58
+ payload?.errors?.length && payload.errors.length > 0 ? true : false,
59
+ )
60
+
61
+ this.node.toggleAttribute(
62
+ `has-warnings`,
63
+ payload?.warnings?.length && payload.warnings?.length > 0
64
+ ? true
65
+ : false,
66
+ )
67
+
58
68
  this.addNode()
59
69
  }
60
70
  }
package/src/index.ts CHANGED
@@ -13,7 +13,5 @@
13
13
  * @packageDocumentation
14
14
  */
15
15
 
16
- import domReady from '@roots/bud-client/dom-ready'
17
- import lazy from '@roots/bud-client/lazy'
18
-
19
- export {domReady, lazy}
16
+ export {default as domReady} from '@roots/bud-client/dom-ready'
17
+ export {default as lazy} from '@roots/bud-client/lazy'