@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 +3 -3
- package/lib/hot/components/index.js +4 -11
- package/lib/hot/components/indicator/index.d.ts +2 -3
- package/lib/hot/components/indicator/index.js +1 -1
- package/lib/hot/components/indicator/indicator.component.d.ts +28 -28
- package/lib/hot/components/indicator/indicator.component.js +86 -86
- package/lib/hot/components/overlay/index.d.ts +2 -2
- package/lib/hot/components/overlay/index.js +1 -1
- package/lib/hot/components/overlay/overlay.component.d.ts +3 -3
- package/lib/hot/components/overlay/overlay.component.js +25 -25
- package/lib/hot/components/overlay/overlay.controller.d.ts +4 -4
- package/lib/hot/components/overlay/overlay.controller.js +14 -14
- package/lib/hot/events.d.ts +21 -28
- package/lib/hot/events.js +4 -12
- package/lib/hot/index.js +5 -9
- package/lib/hot/log.d.ts +8 -8
- package/lib/hot/log.js +6 -10
- package/lib/hot/options.js +4 -4
- package/package.json +10 -16
- package/src/hot/client.ts +3 -3
- package/src/hot/components/index.ts +4 -16
- package/src/hot/components/indicator/index.ts +1 -3
- package/src/hot/components/indicator/indicator.component.ts +104 -104
- package/src/hot/components/overlay/index.ts +2 -2
- package/src/hot/components/overlay/overlay.component.ts +36 -36
- package/src/hot/components/overlay/overlay.controller.ts +14 -14
- package/src/hot/events.ts +29 -36
- package/src/hot/index.ts +8 -9
- package/src/hot/log.ts +10 -14
- package/src/hot/options.ts +4 -4
- package/src/intercept/index.ts +1 -1
package/lib/hot/index.js
CHANGED
|
@@ -2,15 +2,11 @@
|
|
|
2
2
|
/* global __resourceQuery */
|
|
3
3
|
/* global module */
|
|
4
4
|
import { client } from './client.js';
|
|
5
|
-
|
|
6
|
-
client(__resourceQuery, import.meta.webpackHot);
|
|
7
|
-
}
|
|
8
|
-
catch (err) {
|
|
9
|
-
console.error(err);
|
|
5
|
+
(async function () {
|
|
10
6
|
try {
|
|
11
|
-
client(__resourceQuery,
|
|
7
|
+
await client(__resourceQuery, import.meta.webpackHot);
|
|
12
8
|
}
|
|
13
|
-
catch (
|
|
14
|
-
console.error(
|
|
9
|
+
catch (err) {
|
|
10
|
+
console.error(err);
|
|
15
11
|
}
|
|
16
|
-
}
|
|
12
|
+
})();
|
package/lib/hot/log.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
export declare const makeLogger: (options: Options) => {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
error: (...args: Array<unknown>) => void;
|
|
3
|
+
info: (...args: Array<unknown>) => void;
|
|
4
|
+
log: (...args: Array<unknown>) => void;
|
|
5
|
+
warn: (...args: Array<unknown>) => void;
|
|
6
6
|
};
|
|
7
|
-
export declare const makeLog: (options:
|
|
8
|
-
export declare const makeInfo: (options:
|
|
9
|
-
export declare const makeError: (options:
|
|
10
|
-
export declare const makeWarn: (options:
|
|
7
|
+
export declare const makeLog: (options: Options) => (...args: Array<unknown>) => void;
|
|
8
|
+
export declare const makeInfo: (options: Options) => (...args: Array<unknown>) => void;
|
|
9
|
+
export declare const makeError: (options: Options) => (...args: Array<unknown>) => void;
|
|
10
|
+
export declare const makeWarn: (options: Options) => (...args: Array<unknown>) => void;
|
package/lib/hot/log.js
CHANGED
|
@@ -1,36 +1,32 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
export const makeLogger = (options) => {
|
|
3
3
|
return {
|
|
4
|
-
log: makeLog(options),
|
|
5
4
|
error: makeError(options),
|
|
6
|
-
warn: makeWarn(options),
|
|
7
5
|
info: makeInfo(options),
|
|
6
|
+
log: makeLog(options),
|
|
7
|
+
warn: makeWarn(options),
|
|
8
8
|
};
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
export const makeLog = options => {
|
|
10
|
+
export const makeLog = (options) => {
|
|
12
11
|
return (...args) => {
|
|
13
12
|
if (options.log) {
|
|
14
|
-
if (lastLog === args.join(``))
|
|
15
|
-
return;
|
|
16
|
-
lastLog = args.join(``);
|
|
17
13
|
console.log(`[${options.name}]`, ...args);
|
|
18
14
|
}
|
|
19
15
|
};
|
|
20
16
|
};
|
|
21
|
-
export const makeInfo = options => {
|
|
17
|
+
export const makeInfo = (options) => {
|
|
22
18
|
return (...args) => {
|
|
23
19
|
if (options.log) {
|
|
24
20
|
console.info(`[${options.name}]`, ...args);
|
|
25
21
|
}
|
|
26
22
|
};
|
|
27
23
|
};
|
|
28
|
-
export const makeError = options => {
|
|
24
|
+
export const makeError = (options) => {
|
|
29
25
|
return (...args) => {
|
|
30
26
|
console.error(`[${options.name}]`, ...args);
|
|
31
27
|
};
|
|
32
28
|
};
|
|
33
|
-
export const makeWarn = options => {
|
|
29
|
+
export const makeWarn = (options) => {
|
|
34
30
|
return (...args) => {
|
|
35
31
|
console.warn(`[${options.name}]`, ...args);
|
|
36
32
|
};
|
package/lib/hot/options.js
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Client options
|
|
3
3
|
*/
|
|
4
4
|
let data = {
|
|
5
|
-
timeout: 2000,
|
|
6
|
-
reload: true,
|
|
7
|
-
name: `@roots/bud-client`,
|
|
8
5
|
debug: true,
|
|
9
|
-
log: true,
|
|
10
6
|
indicator: true,
|
|
7
|
+
log: true,
|
|
8
|
+
name: `@roots/bud-client`,
|
|
11
9
|
overlay: true,
|
|
12
10
|
path: `/bud/hot`,
|
|
11
|
+
reload: true,
|
|
12
|
+
timeout: 2000,
|
|
13
13
|
};
|
|
14
14
|
/**
|
|
15
15
|
* Get client option
|
package/package.json
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roots/bud-client",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.14.0",
|
|
4
4
|
"description": "Client scripts for @roots/bud",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
7
7
|
},
|
|
8
8
|
"contributors": [
|
|
9
9
|
{
|
|
10
|
-
"name": "Kelly Mears",
|
|
11
10
|
"email": "developers@tinypixel.dev",
|
|
11
|
+
"name": "Kelly Mears",
|
|
12
12
|
"url": "https://github.com/kellymears"
|
|
13
13
|
},
|
|
14
14
|
{
|
|
15
|
-
"name": "Ben Word",
|
|
16
15
|
"email": "ben@benword.com",
|
|
16
|
+
"name": "Ben Word",
|
|
17
17
|
"url": "https://github.com/retlehs"
|
|
18
18
|
},
|
|
19
19
|
{
|
|
20
|
-
"name": "Brandon",
|
|
21
20
|
"email": "brandon@tendency.me",
|
|
21
|
+
"name": "Brandon",
|
|
22
22
|
"url": "https://github.com/Log1x"
|
|
23
23
|
}
|
|
24
24
|
],
|
|
@@ -45,14 +45,8 @@
|
|
|
45
45
|
],
|
|
46
46
|
"type": "module",
|
|
47
47
|
"exports": {
|
|
48
|
-
".":
|
|
49
|
-
|
|
50
|
-
"default": "./lib/index.js"
|
|
51
|
-
},
|
|
52
|
-
"./lib/*": {
|
|
53
|
-
"import": "./lib/*",
|
|
54
|
-
"default": "./lib/*"
|
|
55
|
-
}
|
|
48
|
+
".": "./lib/index.js",
|
|
49
|
+
"./lib/*": "./lib/*"
|
|
56
50
|
},
|
|
57
51
|
"typesVersions": {
|
|
58
52
|
"*": {
|
|
@@ -67,13 +61,13 @@
|
|
|
67
61
|
"types": "./lib/index.d.ts",
|
|
68
62
|
"module": "./lib/index.mjs",
|
|
69
63
|
"devDependencies": {
|
|
70
|
-
"@roots/bud": "6.
|
|
64
|
+
"@roots/bud": "6.14.0",
|
|
71
65
|
"@skypack/package-check": "0.2.2",
|
|
72
|
-
"@types/node": "18.16.
|
|
73
|
-
"@types/webpack-env": "1.18.
|
|
66
|
+
"@types/node": "18.16.18",
|
|
67
|
+
"@types/webpack-env": "1.18.1"
|
|
74
68
|
},
|
|
75
69
|
"dependencies": {
|
|
76
|
-
"tslib": "2.
|
|
70
|
+
"tslib": "2.6.0"
|
|
77
71
|
},
|
|
78
72
|
"volta": {
|
|
79
73
|
"extends": "../../../package.json"
|
package/src/hot/client.ts
CHANGED
|
@@ -36,9 +36,9 @@ export const client = async (
|
|
|
36
36
|
|
|
37
37
|
if (typeof window.bud === `undefined`) {
|
|
38
38
|
window.bud = {
|
|
39
|
+
controllers: [],
|
|
39
40
|
current: {},
|
|
40
41
|
hmr: {},
|
|
41
|
-
controllers: [],
|
|
42
42
|
listeners: {},
|
|
43
43
|
}
|
|
44
44
|
}
|
|
@@ -96,12 +96,12 @@ export const client = async (
|
|
|
96
96
|
const update = async () => {
|
|
97
97
|
try {
|
|
98
98
|
await webpackHot.apply({
|
|
99
|
-
ignoreUnaccepted: true,
|
|
100
99
|
ignoreDeclined: true,
|
|
101
100
|
ignoreErrored: true,
|
|
101
|
+
ignoreUnaccepted: true,
|
|
102
|
+
onDeclined: onUnacceptedOrDeclined,
|
|
102
103
|
onErrored,
|
|
103
104
|
onUnaccepted: onUnacceptedOrDeclined,
|
|
104
|
-
onDeclined: onUnacceptedOrDeclined,
|
|
105
105
|
})
|
|
106
106
|
|
|
107
107
|
if (!isStale()) await check()
|
|
@@ -1,32 +1,20 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
}
|
|
1
|
+
import * as Indicator from './indicator/index.js'
|
|
2
|
+
import * as Overlay from './overlay/index.js'
|
|
4
3
|
|
|
5
4
|
export const make: (
|
|
6
5
|
options: Options,
|
|
7
6
|
) => Promise<Array<Controller>> = async options => {
|
|
8
7
|
if (options.indicator && !customElements.get(`bud-activity-indicator`)) {
|
|
9
|
-
|
|
10
|
-
.then(makeController)
|
|
11
|
-
.then(maybePushController)
|
|
8
|
+
maybePushController(Indicator.make())
|
|
12
9
|
}
|
|
13
10
|
|
|
14
11
|
if (options.overlay && !customElements.get(`bud-error`)) {
|
|
15
|
-
|
|
16
|
-
.then(makeController)
|
|
17
|
-
.then(maybePushController)
|
|
12
|
+
maybePushController(Overlay.make())
|
|
18
13
|
}
|
|
19
14
|
|
|
20
15
|
return window.bud.controllers
|
|
21
16
|
}
|
|
22
17
|
|
|
23
|
-
const makeController = async (
|
|
24
|
-
module: ControllerModule,
|
|
25
|
-
): Promise<Controller | undefined> => {
|
|
26
|
-
if (!module) return
|
|
27
|
-
return await module.make()
|
|
28
|
-
}
|
|
29
|
-
|
|
30
18
|
const maybePushController = (controller: Controller | undefined) => {
|
|
31
19
|
if (!controller) return
|
|
32
20
|
window.bud.controllers.push(controller)
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import {Component} from './indicator.component.js'
|
|
2
2
|
import {Controller} from './indicator.controller.js'
|
|
3
3
|
|
|
4
|
-
export const make =
|
|
5
|
-
update: (data: Payload) => void
|
|
6
|
-
}> => {
|
|
4
|
+
export const make = () => {
|
|
7
5
|
if (customElements.get(`bud-activity-indicator`)) return
|
|
8
6
|
customElements.define(`bud-activity-indicator`, Component)
|
|
9
7
|
|
|
@@ -5,9 +5,19 @@ import {pulse} from './indicator.pulse.js'
|
|
|
5
5
|
*/
|
|
6
6
|
export class Component extends HTMLElement {
|
|
7
7
|
/**
|
|
8
|
-
*
|
|
8
|
+
* Status indicator colors
|
|
9
9
|
*/
|
|
10
|
-
public
|
|
10
|
+
public colors: Record<string, [number, number, number, number]> = {
|
|
11
|
+
error: [220, 38, 38, 1],
|
|
12
|
+
pending: [59, 130, 246, 1],
|
|
13
|
+
success: [4, 120, 87, 1],
|
|
14
|
+
warn: [252, 211, 77, 1],
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Timer
|
|
19
|
+
*/
|
|
20
|
+
public hideTimeout: NodeJS.Timer
|
|
11
21
|
|
|
12
22
|
/**
|
|
13
23
|
* Component name
|
|
@@ -15,16 +25,39 @@ export class Component extends HTMLElement {
|
|
|
15
25
|
public name: string = `bud-activity-indicator`
|
|
16
26
|
|
|
17
27
|
/**
|
|
18
|
-
*
|
|
28
|
+
* Has component rendered
|
|
19
29
|
*/
|
|
20
|
-
public
|
|
21
|
-
return `.${this.name}`
|
|
22
|
-
}
|
|
30
|
+
public rendered: boolean
|
|
23
31
|
|
|
24
32
|
/**
|
|
25
|
-
*
|
|
33
|
+
* Class constructor
|
|
26
34
|
*/
|
|
27
|
-
public
|
|
35
|
+
public constructor() {
|
|
36
|
+
super()
|
|
37
|
+
this.renderShadow()
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
public static get observedAttributes() {
|
|
41
|
+
return [`has-errors`, `has-warnings`, `action`]
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
public attributeChangedCallback() {
|
|
45
|
+
if (this.hasAttribute(`has-errors`)) return this.onError()
|
|
46
|
+
if (this.hasAttribute(`has-warnings`)) return this.onWarning()
|
|
47
|
+
|
|
48
|
+
if (
|
|
49
|
+
!this.hasAttribute(`has-errors`) &&
|
|
50
|
+
!this.hasAttribute(`has-warnings`) &&
|
|
51
|
+
this.getAttribute(`action`) === `built`
|
|
52
|
+
)
|
|
53
|
+
return this.onSuccess()
|
|
54
|
+
|
|
55
|
+
if (
|
|
56
|
+
this.getAttribute(`action`) == `building` ||
|
|
57
|
+
this.getAttribute(`action`) == `sync`
|
|
58
|
+
)
|
|
59
|
+
return this.onPending()
|
|
60
|
+
}
|
|
28
61
|
|
|
29
62
|
/**
|
|
30
63
|
* Get accessor: has errors
|
|
@@ -41,21 +74,67 @@ export class Component extends HTMLElement {
|
|
|
41
74
|
}
|
|
42
75
|
|
|
43
76
|
/**
|
|
44
|
-
*
|
|
77
|
+
* Hide status indicator
|
|
45
78
|
*/
|
|
46
|
-
public
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
pending: [59, 130, 246, 1],
|
|
79
|
+
public hide() {
|
|
80
|
+
this.hideTimeout = setTimeout(() => {
|
|
81
|
+
this.shadowRoot.querySelector(this.selector).classList.remove(`show`)
|
|
82
|
+
}, 2000)
|
|
51
83
|
}
|
|
52
84
|
|
|
53
85
|
/**
|
|
54
|
-
*
|
|
86
|
+
* Status is error
|
|
55
87
|
*/
|
|
56
|
-
public
|
|
57
|
-
|
|
58
|
-
|
|
88
|
+
public onError() {
|
|
89
|
+
this.show()
|
|
90
|
+
|
|
91
|
+
this.shadowRoot
|
|
92
|
+
.querySelector(this.selector)
|
|
93
|
+
.classList.remove(`warning`, `success`, `pending`)
|
|
94
|
+
this.shadowRoot.querySelector(this.selector).classList.add(`error`)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Status is pending
|
|
99
|
+
*/
|
|
100
|
+
public onPending() {
|
|
101
|
+
this.show()
|
|
102
|
+
|
|
103
|
+
this.shadowRoot
|
|
104
|
+
.querySelector(this.selector)
|
|
105
|
+
.classList.remove(`error`, `warning`, `success`)
|
|
106
|
+
|
|
107
|
+
this.shadowRoot.querySelector(this.selector).classList.add(`pending`)
|
|
108
|
+
|
|
109
|
+
this.hide()
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Status is success
|
|
114
|
+
*/
|
|
115
|
+
public onSuccess() {
|
|
116
|
+
this.show()
|
|
117
|
+
|
|
118
|
+
this.shadowRoot
|
|
119
|
+
.querySelector(this.selector)
|
|
120
|
+
.classList.remove(`error`, `warning`, `pending`)
|
|
121
|
+
|
|
122
|
+
this.shadowRoot.querySelector(this.selector).classList.add(`success`)
|
|
123
|
+
|
|
124
|
+
this.hide()
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Status is warning
|
|
129
|
+
*/
|
|
130
|
+
public onWarning() {
|
|
131
|
+
this.show()
|
|
132
|
+
|
|
133
|
+
this.shadowRoot
|
|
134
|
+
.querySelector(this.selector)
|
|
135
|
+
.classList.remove(`error`, `success`, `pending`)
|
|
136
|
+
|
|
137
|
+
this.shadowRoot.querySelector(this.selector).classList.add(`warning`)
|
|
59
138
|
}
|
|
60
139
|
|
|
61
140
|
/**
|
|
@@ -106,96 +185,17 @@ export class Component extends HTMLElement {
|
|
|
106
185
|
}
|
|
107
186
|
|
|
108
187
|
/**
|
|
109
|
-
*
|
|
110
|
-
*/
|
|
111
|
-
public show() {
|
|
112
|
-
this.hideTimeout && clearTimeout(this.hideTimeout)
|
|
113
|
-
this.shadowRoot.querySelector(this.selector).classList.add(`show`)
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
/**
|
|
117
|
-
* Hide status indicator
|
|
118
|
-
*/
|
|
119
|
-
public hide() {
|
|
120
|
-
this.hideTimeout = setTimeout(() => {
|
|
121
|
-
this.shadowRoot.querySelector(this.selector).classList.remove(`show`)
|
|
122
|
-
}, 2000)
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
* Status is pending
|
|
127
|
-
*/
|
|
128
|
-
public onPending() {
|
|
129
|
-
this.show()
|
|
130
|
-
|
|
131
|
-
this.shadowRoot
|
|
132
|
-
.querySelector(this.selector)
|
|
133
|
-
.classList.remove(`error`, `warning`, `success`)
|
|
134
|
-
|
|
135
|
-
this.shadowRoot.querySelector(this.selector).classList.add(`pending`)
|
|
136
|
-
|
|
137
|
-
this.hide()
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* Status is success
|
|
142
|
-
*/
|
|
143
|
-
public onSuccess() {
|
|
144
|
-
this.show()
|
|
145
|
-
|
|
146
|
-
this.shadowRoot
|
|
147
|
-
.querySelector(this.selector)
|
|
148
|
-
.classList.remove(`error`, `warning`, `pending`)
|
|
149
|
-
|
|
150
|
-
this.shadowRoot.querySelector(this.selector).classList.add(`success`)
|
|
151
|
-
|
|
152
|
-
this.hide()
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* Status is error
|
|
188
|
+
* Root div querySelector selector
|
|
157
189
|
*/
|
|
158
|
-
public
|
|
159
|
-
this.
|
|
160
|
-
|
|
161
|
-
this.shadowRoot
|
|
162
|
-
.querySelector(this.selector)
|
|
163
|
-
.classList.remove(`warning`, `success`, `pending`)
|
|
164
|
-
this.shadowRoot.querySelector(this.selector).classList.add(`error`)
|
|
190
|
+
public get selector() {
|
|
191
|
+
return `.${this.name}`
|
|
165
192
|
}
|
|
166
193
|
|
|
167
194
|
/**
|
|
168
|
-
*
|
|
195
|
+
* Show status indicator
|
|
169
196
|
*/
|
|
170
|
-
public
|
|
171
|
-
this.
|
|
172
|
-
|
|
173
|
-
this.shadowRoot
|
|
174
|
-
.querySelector(this.selector)
|
|
175
|
-
.classList.remove(`error`, `success`, `pending`)
|
|
176
|
-
|
|
177
|
-
this.shadowRoot.querySelector(this.selector).classList.add(`warning`)
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
public static get observedAttributes() {
|
|
181
|
-
return [`has-errors`, `has-warnings`, `action`]
|
|
182
|
-
}
|
|
183
|
-
|
|
184
|
-
public attributeChangedCallback() {
|
|
185
|
-
if (this.hasAttribute(`has-errors`)) return this.onError()
|
|
186
|
-
if (this.hasAttribute(`has-warnings`)) return this.onWarning()
|
|
187
|
-
|
|
188
|
-
if (
|
|
189
|
-
!this.hasAttribute(`has-errors`) &&
|
|
190
|
-
!this.hasAttribute(`has-warnings`) &&
|
|
191
|
-
this.getAttribute(`action`) === `built`
|
|
192
|
-
)
|
|
193
|
-
return this.onSuccess()
|
|
194
|
-
|
|
195
|
-
if (
|
|
196
|
-
this.getAttribute(`action`) == `building` ||
|
|
197
|
-
this.getAttribute(`action`) == `sync`
|
|
198
|
-
)
|
|
199
|
-
return this.onPending()
|
|
197
|
+
public show() {
|
|
198
|
+
this.hideTimeout && clearTimeout(this.hideTimeout)
|
|
199
|
+
this.shadowRoot.querySelector(this.selector).classList.add(`show`)
|
|
200
200
|
}
|
|
201
201
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {Component} from './overlay.component.js'
|
|
2
2
|
import {Controller} from './overlay.controller.js'
|
|
3
3
|
|
|
4
|
-
export const make =
|
|
4
|
+
export const make = (): {
|
|
5
5
|
update: (data: Payload) => void
|
|
6
|
-
}
|
|
6
|
+
} => {
|
|
7
7
|
if (customElements.get(`bud-error`)) return
|
|
8
8
|
|
|
9
9
|
customElements.define(`bud-error`, Component)
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
* Component container
|
|
3
3
|
*/
|
|
4
4
|
export class Component extends HTMLElement {
|
|
5
|
+
public documentBodyStyle: any
|
|
6
|
+
|
|
5
7
|
public name: string = `bud-overlay`
|
|
6
8
|
|
|
7
9
|
/**
|
|
@@ -9,17 +11,45 @@ export class Component extends HTMLElement {
|
|
|
9
11
|
*/
|
|
10
12
|
public payload: any
|
|
11
13
|
|
|
12
|
-
public documentBodyStyle: any
|
|
13
|
-
|
|
14
|
-
public get message() {
|
|
15
|
-
return this.getAttribute(`message`)
|
|
16
|
-
}
|
|
17
|
-
|
|
18
14
|
public constructor() {
|
|
19
15
|
super()
|
|
20
16
|
this.renderShadow()
|
|
21
17
|
}
|
|
22
18
|
|
|
19
|
+
public static get observedAttributes() {
|
|
20
|
+
return [`message`]
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public attributeChangedCallback() {
|
|
24
|
+
if (!this.documentBodyStyle)
|
|
25
|
+
this.documentBodyStyle = document.body?.style
|
|
26
|
+
|
|
27
|
+
if (this.getAttribute(`message`)) {
|
|
28
|
+
document.body.style.overflow = `hidden`
|
|
29
|
+
|
|
30
|
+
this.shadowRoot.querySelector(`.overlay`).classList.add(`visible`)
|
|
31
|
+
|
|
32
|
+
this.shadowRoot.querySelector(`.messages`).innerHTML =
|
|
33
|
+
this.getAttribute(`message`)
|
|
34
|
+
|
|
35
|
+
return
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
if (this.documentBodyStyle?.overflow && document?.body?.style) {
|
|
39
|
+
document.body.style.overflow = this.documentBodyStyle.overflow
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
this.shadowRoot.querySelector(`.overlay`).classList.remove(`visible`)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
public connectedCallback() {
|
|
46
|
+
if (document.body?.style) this.documentBodyStyle = document.body.style
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
public get message() {
|
|
50
|
+
return this.getAttribute(`message`)
|
|
51
|
+
}
|
|
52
|
+
|
|
23
53
|
public renderShadow(): void {
|
|
24
54
|
const container = document.createElement(`div`)
|
|
25
55
|
container.classList.add(`overlay`)
|
|
@@ -130,34 +160,4 @@ export class Component extends HTMLElement {
|
|
|
130
160
|
|
|
131
161
|
this.attachShadow({mode: `open`}).appendChild(container)
|
|
132
162
|
}
|
|
133
|
-
|
|
134
|
-
public static get observedAttributes() {
|
|
135
|
-
return [`message`]
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
public attributeChangedCallback() {
|
|
139
|
-
if (!this.documentBodyStyle)
|
|
140
|
-
this.documentBodyStyle = document.body?.style
|
|
141
|
-
|
|
142
|
-
if (this.getAttribute(`message`)) {
|
|
143
|
-
document.body.style.overflow = `hidden`
|
|
144
|
-
|
|
145
|
-
this.shadowRoot.querySelector(`.overlay`).classList.add(`visible`)
|
|
146
|
-
|
|
147
|
-
this.shadowRoot.querySelector(`.messages`).innerHTML =
|
|
148
|
-
this.getAttribute(`message`)
|
|
149
|
-
|
|
150
|
-
return
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if (this.documentBodyStyle?.overflow && document?.body?.style) {
|
|
154
|
-
document.body.style.overflow = this.documentBodyStyle.overflow
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
this.shadowRoot.querySelector(`.overlay`).classList.remove(`visible`)
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
public connectedCallback() {
|
|
161
|
-
if (document.body?.style) this.documentBodyStyle = document.body.style
|
|
162
|
-
}
|
|
163
163
|
}
|
|
@@ -20,20 +20,6 @@ export class Controller {
|
|
|
20
20
|
*/
|
|
21
21
|
public payload: Payload
|
|
22
22
|
|
|
23
|
-
/**
|
|
24
|
-
* Formatted error message
|
|
25
|
-
*/
|
|
26
|
-
public get message(): string {
|
|
27
|
-
return this.payload.errors?.reduce((a, c) => {
|
|
28
|
-
const msg = c?.message ?? c?.error ?? c
|
|
29
|
-
if (!msg) return a
|
|
30
|
-
return `${a}
|
|
31
|
-
<div>
|
|
32
|
-
<pre>${stripAnsi(msg)}</pre>
|
|
33
|
-
</div>`
|
|
34
|
-
}, ``)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
23
|
/**
|
|
38
24
|
* Class constructor
|
|
39
25
|
*/
|
|
@@ -50,6 +36,20 @@ export class Controller {
|
|
|
50
36
|
document.body?.appendChild(this.element)
|
|
51
37
|
}
|
|
52
38
|
|
|
39
|
+
/**
|
|
40
|
+
* Formatted error message
|
|
41
|
+
*/
|
|
42
|
+
public get message(): string {
|
|
43
|
+
return this.payload.errors?.reduce((a, c) => {
|
|
44
|
+
const msg = c?.message ?? c?.error ?? c
|
|
45
|
+
if (!msg) return a
|
|
46
|
+
return `${a}
|
|
47
|
+
<div>
|
|
48
|
+
<pre>${stripAnsi(msg)}</pre>
|
|
49
|
+
</div>`
|
|
50
|
+
}, ``)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
53
|
/**
|
|
54
54
|
* Remove `bud-error` element from the DOM (if present)
|
|
55
55
|
*/
|