@roots/bud-client 6.17.0 → 6.19.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 CHANGED
@@ -66,9 +66,6 @@ However, the amount of effort needed to maintain and develop new features and pr
66
66
  <a href="https://wordpress.com/">
67
67
  <img src="https://cdn.roots.io/app/uploads/wordpress.svg" alt="WordPress.com" width="200" height="150"/>
68
68
  </a>
69
- <a href="https://pantheon.io/">
70
- <img src="https://cdn.roots.io/app/uploads/pantheon.svg" alt="Pantheon" width="200" height="150"/>
71
- </a>
72
69
  <a href="https://worksitesafety.ca/careers/">
73
70
  <img src="https://cdn.roots.io/app/uploads/worksite-safety.svg" alt="Worksite Safety" width="200" height="150"/>
74
71
  </a>
package/lib/hot/client.js CHANGED
@@ -65,13 +65,14 @@ export const client = async (queryString, webpackHot) => {
65
65
  console.warn(`[${options.name}] ${info.type}`, info);
66
66
  options.reload && window.location.reload();
67
67
  };
68
+ const onAccepted = (info) => {
69
+ window.bud.controllers.map(controller => controller?.update({ action: `sync`, errors: [] }));
70
+ };
68
71
  /**
69
72
  * Webpack HMR error handler
70
73
  */
71
74
  const onErrored = (error) => {
72
- window.bud.controllers.map(controller => controller?.update({
73
- errors: [error],
74
- }));
75
+ window.bud.controllers.map(controller => controller?.update({ errors: [error] }));
75
76
  };
76
77
  /**
77
78
  * Webpack HMR update handler
@@ -82,6 +83,7 @@ export const client = async (queryString, webpackHot) => {
82
83
  ignoreDeclined: true,
83
84
  ignoreErrored: true,
84
85
  ignoreUnaccepted: true,
86
+ onAccepted,
85
87
  onDeclined: onUnacceptedOrDeclined,
86
88
  onErrored,
87
89
  onUnaccepted: onUnacceptedOrDeclined,
@@ -11,7 +11,7 @@ export declare class Component extends HTMLElement {
11
11
  /**
12
12
  * Timer
13
13
  */
14
- hideTimeout: NodeJS.Timer;
14
+ timeout: NodeJS.Timeout;
15
15
  /**
16
16
  * Component name
17
17
  */
@@ -35,6 +35,7 @@ export class Component extends HTMLElement {
35
35
  .querySelector(this.selector)
36
36
  .classList.remove(`warning`, `success`, `pending`);
37
37
  this.shadowRoot.querySelector(this.selector).classList.add(`error`);
38
+ this.hide();
38
39
  }
39
40
  /**
40
41
  * Status is pending
@@ -67,19 +68,17 @@ export class Component extends HTMLElement {
67
68
  .querySelector(this.selector)
68
69
  .classList.remove(`error`, `success`, `pending`);
69
70
  this.shadowRoot.querySelector(this.selector).classList.add(`warning`);
71
+ this.hide();
70
72
  }
71
73
  attributeChangedCallback() {
72
74
  if (this.hasAttribute(`has-errors`))
73
75
  return this.onError();
74
76
  if (this.hasAttribute(`has-warnings`))
75
77
  return this.onWarning();
76
- if (!this.hasAttribute(`has-errors`) &&
77
- !this.hasAttribute(`has-warnings`) &&
78
- this.getAttribute(`action`) === `built`)
79
- return this.onSuccess();
80
78
  if (this.getAttribute(`action`) == `building` ||
81
79
  this.getAttribute(`action`) == `sync`)
82
- return this.onPending();
80
+ return this.onSuccess();
81
+ this.onPending();
83
82
  }
84
83
  /**
85
84
  * Get accessor: has errors
@@ -97,7 +96,7 @@ export class Component extends HTMLElement {
97
96
  * Hide status indicator
98
97
  */
99
98
  hide() {
100
- this.hideTimeout = setTimeout(() => {
99
+ this.timeout = setTimeout(() => {
101
100
  this.shadowRoot.querySelector(this.selector).classList.remove(`show`);
102
101
  }, 2000);
103
102
  }
@@ -156,7 +155,7 @@ export class Component extends HTMLElement {
156
155
  * Show status indicator
157
156
  */
158
157
  show() {
159
- this.hideTimeout && clearTimeout(this.hideTimeout);
158
+ this.timeout && clearTimeout(this.timeout);
160
159
  this.shadowRoot.querySelector(this.selector).classList.add(`show`);
161
160
  }
162
161
  }
@@ -35,8 +35,8 @@ export class Controller {
35
35
  * Update activity indicator
36
36
  */
37
37
  update(payload) {
38
- this.node.toggleAttribute(`has-errors`, payload.errors?.length ? true : false);
39
- this.node.toggleAttribute(`has-warnings`, payload.warnings?.length ? true : false);
38
+ this.node.toggleAttribute(`has-errors`, payload.errors?.length > 0);
39
+ this.node.toggleAttribute(`has-warnings`, payload.warnings?.length > 0);
40
40
  this.node.setAttribute(`action`, payload.action);
41
41
  this.addNode();
42
42
  }
package/lib/lazy.js CHANGED
@@ -12,7 +12,7 @@ const lazy = async function lazy(module, handler, errorHandler) {
12
12
  return await handler(request);
13
13
  }
14
14
  catch (error) {
15
- const handle = errorHandler ? errorHandler : defaultErrorHandler;
15
+ const handle = errorHandler ?? defaultErrorHandler;
16
16
  handle(error);
17
17
  }
18
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@roots/bud-client",
3
- "version": "6.17.0",
3
+ "version": "6.19.0",
4
4
  "description": "Client scripts for @roots/bud",
5
5
  "engines": {
6
6
  "node": ">=16"
@@ -69,10 +69,10 @@
69
69
  "types": "./lib/index.d.ts",
70
70
  "module": "./lib/index.mjs",
71
71
  "devDependencies": {
72
- "@roots/bud": "6.17.0",
72
+ "@roots/bud": "6.19.0",
73
73
  "@skypack/package-check": "0.2.2",
74
- "@types/node": "18.17.19",
75
- "@types/webpack-env": "1.18.1"
74
+ "@types/node": "20.10.4",
75
+ "@types/webpack-env": "1.18.4"
76
76
  },
77
77
  "dependencies": {
78
78
  "tslib": "2.6.2"
package/src/hot/client.ts CHANGED
@@ -83,15 +83,18 @@ export const client = async (
83
83
  options.reload && window.location.reload()
84
84
  }
85
85
 
86
+ const onAccepted = (info: __WebpackModuleApi.HotNotifierInfo) => {
87
+ window.bud.controllers.map(
88
+ controller => controller?.update({action: `sync`, errors: []}),
89
+ )
90
+ }
91
+
86
92
  /**
87
93
  * Webpack HMR error handler
88
94
  */
89
95
  const onErrored = (error: any) => {
90
96
  window.bud.controllers.map(
91
- controller =>
92
- controller?.update({
93
- errors: [error],
94
- }),
97
+ controller => controller?.update({errors: [error]}),
95
98
  )
96
99
  }
97
100
 
@@ -104,6 +107,7 @@ export const client = async (
104
107
  ignoreDeclined: true,
105
108
  ignoreErrored: true,
106
109
  ignoreUnaccepted: true,
110
+ onAccepted,
107
111
  onDeclined: onUnacceptedOrDeclined,
108
112
  onErrored,
109
113
  onUnaccepted: onUnacceptedOrDeclined,
@@ -20,7 +20,7 @@ export class Component extends HTMLElement {
20
20
  /**
21
21
  * Timer
22
22
  */
23
- public hideTimeout: NodeJS.Timer
23
+ public timeout: NodeJS.Timeout
24
24
 
25
25
  /**
26
26
  * Component name
@@ -50,6 +50,8 @@ export class Component extends HTMLElement {
50
50
  .querySelector(this.selector)
51
51
  .classList.remove(`warning`, `success`, `pending`)
52
52
  this.shadowRoot.querySelector(this.selector).classList.add(`error`)
53
+
54
+ this.hide()
53
55
  }
54
56
  /**
55
57
  * Status is pending
@@ -90,23 +92,20 @@ export class Component extends HTMLElement {
90
92
  .classList.remove(`error`, `success`, `pending`)
91
93
 
92
94
  this.shadowRoot.querySelector(this.selector).classList.add(`warning`)
95
+
96
+ this.hide()
93
97
  }
94
98
  public attributeChangedCallback() {
95
99
  if (this.hasAttribute(`has-errors`)) return this.onError()
96
100
  if (this.hasAttribute(`has-warnings`)) return this.onWarning()
97
101
 
98
- if (
99
- !this.hasAttribute(`has-errors`) &&
100
- !this.hasAttribute(`has-warnings`) &&
101
- this.getAttribute(`action`) === `built`
102
- )
103
- return this.onSuccess()
104
-
105
102
  if (
106
103
  this.getAttribute(`action`) == `building` ||
107
104
  this.getAttribute(`action`) == `sync`
108
105
  )
109
- return this.onPending()
106
+ return this.onSuccess()
107
+
108
+ this.onPending()
110
109
  }
111
110
 
112
111
  /**
@@ -127,7 +126,7 @@ export class Component extends HTMLElement {
127
126
  * Hide status indicator
128
127
  */
129
128
  public hide() {
130
- this.hideTimeout = setTimeout(() => {
129
+ this.timeout = setTimeout(() => {
131
130
  this.shadowRoot.querySelector(this.selector).classList.remove(`show`)
132
131
  }, 2000)
133
132
  }
@@ -190,7 +189,7 @@ export class Component extends HTMLElement {
190
189
  * Show status indicator
191
190
  */
192
191
  public show() {
193
- this.hideTimeout && clearTimeout(this.hideTimeout)
192
+ this.timeout && clearTimeout(this.timeout)
194
193
  this.shadowRoot.querySelector(this.selector).classList.add(`show`)
195
194
  }
196
195
  }
@@ -49,15 +49,9 @@ export class Controller {
49
49
  * Update activity indicator
50
50
  */
51
51
  public update(payload: Payload) {
52
- this.node.toggleAttribute(
53
- `has-errors`,
54
- payload.errors?.length ? true : false,
55
- )
52
+ this.node.toggleAttribute(`has-errors`, payload.errors?.length > 0)
56
53
 
57
- this.node.toggleAttribute(
58
- `has-warnings`,
59
- payload.warnings?.length ? true : false,
60
- )
54
+ this.node.toggleAttribute(`has-warnings`, payload.warnings?.length > 0)
61
55
 
62
56
  this.node.setAttribute(`action`, payload.action)
63
57
 
package/src/lazy.ts CHANGED
@@ -33,7 +33,7 @@ const lazy: lazy = async function lazy<T = any>(
33
33
  const {default: request} = await module
34
34
  return await handler(request)
35
35
  } catch (error: unknown) {
36
- const handle = errorHandler ? errorHandler : defaultErrorHandler
36
+ const handle = errorHandler ?? defaultErrorHandler
37
37
  handle(error)
38
38
  }
39
39
  }
@@ -16,7 +16,7 @@ declare interface Events {
16
16
  declare interface Payload {
17
17
  name: string
18
18
  type: `middleware` | __WebpackModuleApi.HotNotifierInfo[`type`]
19
- action: 'reload' | 'sync' | 'building' | 'built'
19
+ action?: 'reload' | 'sync' | 'building' | 'built'
20
20
  hash?: string
21
21
  time?: number
22
22
  errors?: Array<Record<string, any>>