@roots/bud-client 6.13.0 → 6.14.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/lib/hot/client.js CHANGED
@@ -25,9 +25,9 @@ export const client = async (queryString, webpackHot) => {
25
25
  const logger = makeLogger(options);
26
26
  if (typeof window.bud === `undefined`) {
27
27
  window.bud = {
28
+ controllers: [],
28
29
  current: {},
29
30
  hmr: {},
30
- controllers: [],
31
31
  listeners: {},
32
32
  };
33
33
  }
@@ -76,12 +76,12 @@ export const client = async (queryString, webpackHot) => {
76
76
  const update = async () => {
77
77
  try {
78
78
  await webpackHot.apply({
79
- ignoreUnaccepted: true,
80
79
  ignoreDeclined: true,
81
80
  ignoreErrored: true,
81
+ ignoreUnaccepted: true,
82
+ onDeclined: onUnacceptedOrDeclined,
82
83
  onErrored,
83
84
  onUnaccepted: onUnacceptedOrDeclined,
84
- onDeclined: onUnacceptedOrDeclined,
85
85
  });
86
86
  if (!isStale())
87
87
  await check();
@@ -1,21 +1,14 @@
1
+ import * as Indicator from './indicator/index.js';
2
+ import * as Overlay from './overlay/index.js';
1
3
  export const make = async (options) => {
2
4
  if (options.indicator && !customElements.get(`bud-activity-indicator`)) {
3
- await import(`./indicator/index.js`)
4
- .then(makeController)
5
- .then(maybePushController);
5
+ maybePushController(Indicator.make());
6
6
  }
7
7
  if (options.overlay && !customElements.get(`bud-error`)) {
8
- await import(`./overlay/index.js`)
9
- .then(makeController)
10
- .then(maybePushController);
8
+ maybePushController(Overlay.make());
11
9
  }
12
10
  return window.bud.controllers;
13
11
  };
14
- const makeController = async (module) => {
15
- if (!module)
16
- return;
17
- return await module.make();
18
- };
19
12
  const maybePushController = (controller) => {
20
13
  if (!controller)
21
14
  return;
@@ -1,3 +1,2 @@
1
- export declare const make: () => Promise<{
2
- update: (data: Payload) => void;
3
- }>;
1
+ import { Controller } from './indicator.controller.js';
2
+ export declare const make: () => Controller;
@@ -1,6 +1,6 @@
1
1
  import { Component } from './indicator.component.js';
2
2
  import { Controller } from './indicator.controller.js';
3
- export const make = async () => {
3
+ export const make = () => {
4
4
  if (customElements.get(`bud-activity-indicator`))
5
5
  return;
6
6
  customElements.define(`bud-activity-indicator`, Component);
@@ -4,49 +4,43 @@
4
4
  */
5
5
  export declare class Component extends HTMLElement {
6
6
  /**
7
- * Has component rendered
8
- */
9
- rendered: boolean;
10
- /**
11
- * Component name
12
- */
13
- name: string;
14
- /**
15
- * Root div querySelector selector
7
+ * Status indicator colors
16
8
  */
17
- get selector(): string;
9
+ colors: Record<string, [number, number, number, number]>;
18
10
  /**
19
11
  * Timer
20
12
  */
21
13
  hideTimeout: NodeJS.Timer;
22
14
  /**
23
- * Get accessor: has errors
24
- */
25
- get hasErrors(): boolean;
26
- /**
27
- * Get accessor: has warnings
15
+ * Component name
28
16
  */
29
- get hasWarnings(): boolean;
17
+ name: string;
30
18
  /**
31
- * Status indicator colors
19
+ * Has component rendered
32
20
  */
33
- colors: Record<string, [number, number, number, number]>;
21
+ rendered: boolean;
34
22
  /**
35
23
  * Class constructor
36
24
  */
37
25
  constructor();
26
+ static get observedAttributes(): string[];
27
+ attributeChangedCallback(): void;
38
28
  /**
39
- * Render status indicator
29
+ * Get accessor: has errors
40
30
  */
41
- renderShadow(): void;
31
+ get hasErrors(): boolean;
42
32
  /**
43
- * Show status indicator
33
+ * Get accessor: has warnings
44
34
  */
45
- show(): void;
35
+ get hasWarnings(): boolean;
46
36
  /**
47
37
  * Hide status indicator
48
38
  */
49
39
  hide(): void;
40
+ /**
41
+ * Status is error
42
+ */
43
+ onError(): void;
50
44
  /**
51
45
  * Status is pending
52
46
  */
@@ -55,14 +49,20 @@ export declare class Component extends HTMLElement {
55
49
  * Status is success
56
50
  */
57
51
  onSuccess(): void;
58
- /**
59
- * Status is error
60
- */
61
- onError(): void;
62
52
  /**
63
53
  * Status is warning
64
54
  */
65
55
  onWarning(): void;
66
- static get observedAttributes(): string[];
67
- attributeChangedCallback(): void;
56
+ /**
57
+ * Render status indicator
58
+ */
59
+ renderShadow(): void;
60
+ /**
61
+ * Root div querySelector selector
62
+ */
63
+ get selector(): string;
64
+ /**
65
+ * Show status indicator
66
+ */
67
+ show(): void;
68
68
  }
@@ -4,10 +4,40 @@ import { pulse } from './indicator.pulse.js';
4
4
  */
5
5
  export class Component extends HTMLElement {
6
6
  /**
7
- * Root div querySelector selector
7
+ * Class constructor
8
8
  */
9
- get selector() {
10
- return `.${this.name}`;
9
+ constructor() {
10
+ super();
11
+ /**
12
+ * Status indicator colors
13
+ */
14
+ this.colors = {
15
+ error: [220, 38, 38, 1],
16
+ pending: [59, 130, 246, 1],
17
+ success: [4, 120, 87, 1],
18
+ warn: [252, 211, 77, 1],
19
+ };
20
+ /**
21
+ * Component name
22
+ */
23
+ this.name = `bud-activity-indicator`;
24
+ this.renderShadow();
25
+ }
26
+ static get observedAttributes() {
27
+ return [`has-errors`, `has-warnings`, `action`];
28
+ }
29
+ attributeChangedCallback() {
30
+ if (this.hasAttribute(`has-errors`))
31
+ return this.onError();
32
+ if (this.hasAttribute(`has-warnings`))
33
+ return this.onWarning();
34
+ if (!this.hasAttribute(`has-errors`) &&
35
+ !this.hasAttribute(`has-warnings`) &&
36
+ this.getAttribute(`action`) === `built`)
37
+ return this.onSuccess();
38
+ if (this.getAttribute(`action`) == `building` ||
39
+ this.getAttribute(`action`) == `sync`)
40
+ return this.onPending();
11
41
  }
12
42
  /**
13
43
  * Get accessor: has errors
@@ -22,24 +52,54 @@ export class Component extends HTMLElement {
22
52
  return this.getAttribute(`has-warnings`) == `true`;
23
53
  }
24
54
  /**
25
- * Class constructor
55
+ * Hide status indicator
26
56
  */
27
- constructor() {
28
- super();
29
- /**
30
- * Component name
31
- */
32
- this.name = `bud-activity-indicator`;
33
- /**
34
- * Status indicator colors
35
- */
36
- this.colors = {
37
- success: [4, 120, 87, 1],
38
- error: [220, 38, 38, 1],
39
- warn: [252, 211, 77, 1],
40
- pending: [59, 130, 246, 1],
41
- };
42
- this.renderShadow();
57
+ hide() {
58
+ this.hideTimeout = setTimeout(() => {
59
+ this.shadowRoot.querySelector(this.selector).classList.remove(`show`);
60
+ }, 2000);
61
+ }
62
+ /**
63
+ * Status is error
64
+ */
65
+ onError() {
66
+ this.show();
67
+ this.shadowRoot
68
+ .querySelector(this.selector)
69
+ .classList.remove(`warning`, `success`, `pending`);
70
+ this.shadowRoot.querySelector(this.selector).classList.add(`error`);
71
+ }
72
+ /**
73
+ * Status is pending
74
+ */
75
+ onPending() {
76
+ this.show();
77
+ this.shadowRoot
78
+ .querySelector(this.selector)
79
+ .classList.remove(`error`, `warning`, `success`);
80
+ this.shadowRoot.querySelector(this.selector).classList.add(`pending`);
81
+ this.hide();
82
+ }
83
+ /**
84
+ * Status is success
85
+ */
86
+ onSuccess() {
87
+ this.show();
88
+ this.shadowRoot
89
+ .querySelector(this.selector)
90
+ .classList.remove(`error`, `warning`, `pending`);
91
+ this.shadowRoot.querySelector(this.selector).classList.add(`success`);
92
+ this.hide();
93
+ }
94
+ /**
95
+ * Status is warning
96
+ */
97
+ onWarning() {
98
+ this.show();
99
+ this.shadowRoot
100
+ .querySelector(this.selector)
101
+ .classList.remove(`error`, `success`, `pending`);
102
+ this.shadowRoot.querySelector(this.selector).classList.add(`warning`);
43
103
  }
44
104
  /**
45
105
  * Render status indicator
@@ -86,6 +146,12 @@ export class Component extends HTMLElement {
86
146
  `;
87
147
  this.attachShadow({ mode: `open` }).appendChild(container);
88
148
  }
149
+ /**
150
+ * Root div querySelector selector
151
+ */
152
+ get selector() {
153
+ return `.${this.name}`;
154
+ }
89
155
  /**
90
156
  * Show status indicator
91
157
  */
@@ -93,70 +159,4 @@ export class Component extends HTMLElement {
93
159
  this.hideTimeout && clearTimeout(this.hideTimeout);
94
160
  this.shadowRoot.querySelector(this.selector).classList.add(`show`);
95
161
  }
96
- /**
97
- * Hide status indicator
98
- */
99
- hide() {
100
- this.hideTimeout = setTimeout(() => {
101
- this.shadowRoot.querySelector(this.selector).classList.remove(`show`);
102
- }, 2000);
103
- }
104
- /**
105
- * Status is pending
106
- */
107
- onPending() {
108
- this.show();
109
- this.shadowRoot
110
- .querySelector(this.selector)
111
- .classList.remove(`error`, `warning`, `success`);
112
- this.shadowRoot.querySelector(this.selector).classList.add(`pending`);
113
- this.hide();
114
- }
115
- /**
116
- * Status is success
117
- */
118
- onSuccess() {
119
- this.show();
120
- this.shadowRoot
121
- .querySelector(this.selector)
122
- .classList.remove(`error`, `warning`, `pending`);
123
- this.shadowRoot.querySelector(this.selector).classList.add(`success`);
124
- this.hide();
125
- }
126
- /**
127
- * Status is error
128
- */
129
- onError() {
130
- this.show();
131
- this.shadowRoot
132
- .querySelector(this.selector)
133
- .classList.remove(`warning`, `success`, `pending`);
134
- this.shadowRoot.querySelector(this.selector).classList.add(`error`);
135
- }
136
- /**
137
- * Status is warning
138
- */
139
- onWarning() {
140
- this.show();
141
- this.shadowRoot
142
- .querySelector(this.selector)
143
- .classList.remove(`error`, `success`, `pending`);
144
- this.shadowRoot.querySelector(this.selector).classList.add(`warning`);
145
- }
146
- static get observedAttributes() {
147
- return [`has-errors`, `has-warnings`, `action`];
148
- }
149
- attributeChangedCallback() {
150
- if (this.hasAttribute(`has-errors`))
151
- return this.onError();
152
- if (this.hasAttribute(`has-warnings`))
153
- return this.onWarning();
154
- if (!this.hasAttribute(`has-errors`) &&
155
- !this.hasAttribute(`has-warnings`) &&
156
- this.getAttribute(`action`) === `built`)
157
- return this.onSuccess();
158
- if (this.getAttribute(`action`) == `building` ||
159
- this.getAttribute(`action`) == `sync`)
160
- return this.onPending();
161
- }
162
162
  }
@@ -1,3 +1,3 @@
1
- export declare const make: () => Promise<{
1
+ export declare const make: () => {
2
2
  update: (data: Payload) => void;
3
- }>;
3
+ };
@@ -1,6 +1,6 @@
1
1
  import { Component } from './overlay.component.js';
2
2
  import { Controller } from './overlay.controller.js';
3
- export const make = async () => {
3
+ export const make = () => {
4
4
  if (customElements.get(`bud-error`))
5
5
  return;
6
6
  customElements.define(`bud-error`, Component);
@@ -2,16 +2,16 @@
2
2
  * Component container
3
3
  */
4
4
  export declare class Component extends HTMLElement {
5
+ documentBodyStyle: any;
5
6
  name: string;
6
7
  /**
7
8
  * WHM payload
8
9
  */
9
10
  payload: any;
10
- documentBodyStyle: any;
11
- get message(): string;
12
11
  constructor();
13
- renderShadow(): void;
14
12
  static get observedAttributes(): string[];
15
13
  attributeChangedCallback(): void;
16
14
  connectedCallback(): void;
15
+ get message(): string;
16
+ renderShadow(): void;
17
17
  }
@@ -2,14 +2,36 @@
2
2
  * Component container
3
3
  */
4
4
  export class Component extends HTMLElement {
5
- get message() {
6
- return this.getAttribute(`message`);
7
- }
8
5
  constructor() {
9
6
  super();
10
7
  this.name = `bud-overlay`;
11
8
  this.renderShadow();
12
9
  }
10
+ static get observedAttributes() {
11
+ return [`message`];
12
+ }
13
+ attributeChangedCallback() {
14
+ if (!this.documentBodyStyle)
15
+ this.documentBodyStyle = document.body?.style;
16
+ if (this.getAttribute(`message`)) {
17
+ document.body.style.overflow = `hidden`;
18
+ this.shadowRoot.querySelector(`.overlay`).classList.add(`visible`);
19
+ this.shadowRoot.querySelector(`.messages`).innerHTML =
20
+ this.getAttribute(`message`);
21
+ return;
22
+ }
23
+ if (this.documentBodyStyle?.overflow && document?.body?.style) {
24
+ document.body.style.overflow = this.documentBodyStyle.overflow;
25
+ }
26
+ this.shadowRoot.querySelector(`.overlay`).classList.remove(`visible`);
27
+ }
28
+ connectedCallback() {
29
+ if (document.body?.style)
30
+ this.documentBodyStyle = document.body.style;
31
+ }
32
+ get message() {
33
+ return this.getAttribute(`message`);
34
+ }
13
35
  renderShadow() {
14
36
  const container = document.createElement(`div`);
15
37
  container.classList.add(`overlay`);
@@ -119,26 +141,4 @@ export class Component extends HTMLElement {
119
141
  `;
120
142
  this.attachShadow({ mode: `open` }).appendChild(container);
121
143
  }
122
- static get observedAttributes() {
123
- return [`message`];
124
- }
125
- attributeChangedCallback() {
126
- if (!this.documentBodyStyle)
127
- this.documentBodyStyle = document.body?.style;
128
- if (this.getAttribute(`message`)) {
129
- document.body.style.overflow = `hidden`;
130
- this.shadowRoot.querySelector(`.overlay`).classList.add(`visible`);
131
- this.shadowRoot.querySelector(`.messages`).innerHTML =
132
- this.getAttribute(`message`);
133
- return;
134
- }
135
- if (this.documentBodyStyle?.overflow && document?.body?.style) {
136
- document.body.style.overflow = this.documentBodyStyle.overflow;
137
- }
138
- this.shadowRoot.querySelector(`.overlay`).classList.remove(`visible`);
139
- }
140
- connectedCallback() {
141
- if (document.body?.style)
142
- this.documentBodyStyle = document.body.style;
143
- }
144
144
  }
@@ -10,10 +10,6 @@ export declare class Controller {
10
10
  * HMR update
11
11
  */
12
12
  payload: Payload;
13
- /**
14
- * Formatted error message
15
- */
16
- get message(): string;
17
13
  /**
18
14
  * Class constructor
19
15
  */
@@ -22,6 +18,10 @@ export declare class Controller {
22
18
  * Append `bud-error` element to the DOM
23
19
  */
24
20
  createError(): void;
21
+ /**
22
+ * Formatted error message
23
+ */
24
+ get message(): string;
25
25
  /**
26
26
  * Remove `bud-error` element from the DOM (if present)
27
27
  */
@@ -7,20 +7,6 @@ const stripAnsi = (body) => body?.replace?.(new RegExp(ansiPattern, `g`), ``) ??
7
7
  * Overlay controller
8
8
  */
9
9
  export class Controller {
10
- /**
11
- * Formatted error message
12
- */
13
- get message() {
14
- return this.payload.errors?.reduce((a, c) => {
15
- const msg = c?.message ?? c?.error ?? c;
16
- if (!msg)
17
- return a;
18
- return `${a}
19
- <div>
20
- <pre>${stripAnsi(msg)}</pre>
21
- </div>`;
22
- }, ``);
23
- }
24
10
  /**
25
11
  * Class constructor
26
12
  */
@@ -35,6 +21,20 @@ export class Controller {
35
21
  !document.body.querySelector(`bud-error`) &&
36
22
  document.body?.appendChild(this.element);
37
23
  }
24
+ /**
25
+ * Formatted error message
26
+ */
27
+ get message() {
28
+ return this.payload.errors?.reduce((a, c) => {
29
+ const msg = c?.message ?? c?.error ?? c;
30
+ if (!msg)
31
+ return a;
32
+ return `${a}
33
+ <div>
34
+ <pre>${stripAnsi(msg)}</pre>
35
+ </div>`;
36
+ }, ``);
37
+ }
38
38
  /**
39
39
  * Remove `bud-error` element from the DOM (if present)
40
40
  */
@@ -1,31 +1,29 @@
1
- export declare const injectEvents: (eventSource: new (path: string) => EventSource) => {
1
+ interface EventSourceFactory {
2
+ new (path: string): EventSource;
3
+ }
4
+ export declare const injectEvents: (eventSource: EventSourceFactory) => {
2
5
  new (options: Partial<Options> & {
3
6
  name: string;
4
7
  path: string;
5
8
  }): {
6
9
  /**
7
10
  * Registered listeners
8
- *
9
- * @public
10
11
  */
11
12
  listeners: Set<Listener>;
12
- options: Partial<Options> & {
13
- name: string;
14
- path: string;
15
- };
16
- /**
17
- * EventSource `onopen` handler
18
- * @public
19
- */
20
- onopen: () => void;
21
13
  /**
22
14
  * EventSource `onmessage` handler
23
- * @public
24
15
  */
25
16
  onmessage: (payload: MessageEvent) => Promise<void>;
17
+ /**
18
+ * EventSource `onopen` handler
19
+ */
20
+ onopen: () => void;
21
+ options: Partial<Options> & {
22
+ name: string;
23
+ path: string;
24
+ };
26
25
  /**
27
26
  * EventSource `addMessageListener` handler
28
- * @public
29
27
  */
30
28
  addListener(listener: Listener): this;
31
29
  onerror: (this: EventSource, ev: Event) => any;
@@ -47,7 +45,6 @@ export declare const injectEvents: (eventSource: new (path: string) => EventSour
47
45
  /**
48
46
  * Singleton constructor
49
47
  *
50
- * @public
51
48
  */
52
49
  make(options: Partial<Options> & {
53
50
  name: string;
@@ -55,27 +52,22 @@ export declare const injectEvents: (eventSource: new (path: string) => EventSour
55
52
  }): {
56
53
  /**
57
54
  * Registered listeners
58
- *
59
- * @public
60
55
  */
61
56
  listeners: Set<Listener>;
62
- options: Partial<Options> & {
63
- name: string;
64
- path: string;
65
- };
66
- /**
67
- * EventSource `onopen` handler
68
- * @public
69
- */
70
- onopen: () => void;
71
57
  /**
72
58
  * EventSource `onmessage` handler
73
- * @public
74
59
  */
75
60
  onmessage: (payload: MessageEvent) => Promise<void>;
61
+ /**
62
+ * EventSource `onopen` handler
63
+ */
64
+ onopen: () => void;
65
+ options: Partial<Options> & {
66
+ name: string;
67
+ path: string;
68
+ };
76
69
  /**
77
70
  * EventSource `addMessageListener` handler
78
- * @public
79
71
  */
80
72
  addListener(listener: Listener): this;
81
73
  onerror: (this: EventSource, ev: Event) => any;
@@ -95,3 +87,4 @@ export declare const injectEvents: (eventSource: new (path: string) => EventSour
95
87
  dispatchEvent(event: Event): boolean;
96
88
  };
97
89
  };
90
+ export {};
package/lib/hot/events.js CHANGED
@@ -1,4 +1,3 @@
1
- /* eslint-disable no-console */
2
1
  export const injectEvents = (eventSource) => {
3
2
  /**
4
3
  * EventSource wrapper
@@ -14,25 +13,16 @@ export const injectEvents = (eventSource) => {
14
13
  * @remarks
15
14
  * Singleton interface, so this is private.
16
15
  *
17
- * @public
18
16
  */
19
17
  constructor(options) {
20
18
  super(options.path);
21
19
  this.options = options;
22
20
  /**
23
21
  * Registered listeners
24
- *
25
- * @public
26
22
  */
27
23
  this.listeners = new Set();
28
- /**
29
- * EventSource `onopen` handler
30
- * @public
31
- */
32
- this.onopen = function () { };
33
24
  /**
34
25
  * EventSource `onmessage` handler
35
- * @public
36
26
  */
37
27
  this.onmessage = async function (payload) {
38
28
  if (!payload?.data || payload.data == `\uD83D\uDC93`) {
@@ -48,6 +38,10 @@ export const injectEvents = (eventSource) => {
48
38
  }
49
39
  catch (ex) { }
50
40
  };
41
+ /**
42
+ * EventSource `onopen` handler
43
+ */
44
+ this.onopen = function () { };
51
45
  this.onopen = this.onopen.bind(this);
52
46
  this.onmessage = this.onmessage.bind(this);
53
47
  this.addListener = this.addListener.bind(this);
@@ -55,7 +49,6 @@ export const injectEvents = (eventSource) => {
55
49
  /**
56
50
  * Singleton constructor
57
51
  *
58
- * @public
59
52
  */
60
53
  static make(options) {
61
54
  if (typeof window.bud.hmr[options.name] === `undefined`)
@@ -66,7 +59,6 @@ export const injectEvents = (eventSource) => {
66
59
  }
67
60
  /**
68
61
  * EventSource `addMessageListener` handler
69
- * @public
70
62
  */
71
63
  addListener(listener) {
72
64
  this.listeners.add(listener);