@roots/bud-client 6.12.3 → 6.13.1
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 +31 -40
- package/lib/hot/components/index.js +7 -16
- package/lib/hot/components/indicator/index.js +2 -11
- package/lib/hot/components/indicator/indicator.component.d.ts +29 -29
- package/lib/hot/components/indicator/indicator.component.js +86 -86
- package/lib/hot/components/indicator/indicator.controller.d.ts +1 -1
- package/lib/hot/components/indicator/indicator.controller.js +4 -7
- package/lib/hot/components/overlay/index.js +2 -11
- package/lib/hot/components/overlay/overlay.component.d.ts +3 -3
- package/lib/hot/components/overlay/overlay.component.js +25 -27
- package/lib/hot/components/overlay/overlay.controller.d.ts +4 -4
- package/lib/hot/components/overlay/overlay.controller.js +19 -24
- package/lib/hot/events.d.ts +22 -22
- package/lib/hot/events.js +17 -28
- package/lib/hot/index.js +16 -0
- package/lib/hot/log.d.ts +2 -2
- package/lib/hot/log.js +2 -2
- package/lib/hot/options.js +5 -5
- package/{src/index.mts → lib/index.js} +1 -3
- package/lib/intercept/proxy-click-interceptor.js +11 -22
- package/package.json +9 -9
- package/src/hot/client.ts +7 -5
- package/src/hot/components/indicator/indicator.component.ts +104 -104
- 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 +27 -27
- package/src/hot/index.ts +17 -0
- package/src/hot/log.ts +2 -2
- package/src/hot/options.ts +4 -4
- package/src/intercept/index.ts +1 -1
- package/lib/hot/index.cjs +0 -5
- package/lib/hot/index.d.mts +0 -1
- package/lib/hot/index.mjs +0 -17
- package/lib/index.cjs +0 -3
- package/lib/index.d.mts +0 -12
- package/lib/index.mjs +0 -3
- package/src/hot/client.test.ts +0 -78
- package/src/hot/index.cts +0 -7
- package/src/hot/index.mts +0 -9
- /package/lib/hot/{index.d.cts → index.d.ts} +0 -0
- /package/lib/{index.d.cts → index.d.ts} +0 -0
- /package/src/{index.cts → index.ts} +0 -0
|
@@ -2,27 +2,11 @@ const ansiPattern = [
|
|
|
2
2
|
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)`,
|
|
3
3
|
`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))`,
|
|
4
4
|
].join(`|`);
|
|
5
|
-
const stripAnsi = (body) =>
|
|
5
|
+
const stripAnsi = (body) => body?.replace?.(new RegExp(ansiPattern, `g`), ``) ?? body;
|
|
6
6
|
/**
|
|
7
7
|
* Overlay controller
|
|
8
8
|
*/
|
|
9
9
|
export class Controller {
|
|
10
|
-
/**
|
|
11
|
-
* Formatted error message
|
|
12
|
-
*/
|
|
13
|
-
get message() {
|
|
14
|
-
var _a;
|
|
15
|
-
return (_a = this.payload.errors) === null || _a === void 0 ? void 0 : _a.reduce((a, c) => {
|
|
16
|
-
var _a, _b;
|
|
17
|
-
const msg = (_b = (_a = c === null || c === void 0 ? void 0 : c.message) !== null && _a !== void 0 ? _a : c === null || c === void 0 ? void 0 : c.error) !== null && _b !== void 0 ? _b : c;
|
|
18
|
-
if (!msg)
|
|
19
|
-
return a;
|
|
20
|
-
return `${a}
|
|
21
|
-
<div>
|
|
22
|
-
<pre>${stripAnsi(msg)}</pre>
|
|
23
|
-
</div>`;
|
|
24
|
-
}, ``);
|
|
25
|
-
}
|
|
26
10
|
/**
|
|
27
11
|
* Class constructor
|
|
28
12
|
*/
|
|
@@ -34,25 +18,36 @@ export class Controller {
|
|
|
34
18
|
* Append `bud-error` element to the DOM
|
|
35
19
|
*/
|
|
36
20
|
createError() {
|
|
37
|
-
var _a;
|
|
38
21
|
!document.body.querySelector(`bud-error`) &&
|
|
39
|
-
|
|
22
|
+
document.body?.appendChild(this.element);
|
|
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
|
+
}, ``);
|
|
40
37
|
}
|
|
41
38
|
/**
|
|
42
39
|
* Remove `bud-error` element from the DOM (if present)
|
|
43
40
|
*/
|
|
44
41
|
removeError() {
|
|
45
|
-
|
|
46
|
-
(_a = document.body.querySelector(`bud-error`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
42
|
+
document.body.querySelector(`bud-error`)?.remove();
|
|
47
43
|
}
|
|
48
44
|
/**
|
|
49
45
|
* Update DOM
|
|
50
46
|
*/
|
|
51
47
|
update(payload) {
|
|
52
|
-
var _a, _b;
|
|
53
48
|
this.payload = payload;
|
|
54
|
-
this.element.setAttribute(`message`,
|
|
55
|
-
if (
|
|
49
|
+
this.element.setAttribute(`message`, this.message ?? ``);
|
|
50
|
+
if (this.payload.errors?.length > 0) {
|
|
56
51
|
return this.createError();
|
|
57
52
|
}
|
|
58
53
|
this.removeError();
|
package/lib/hot/events.d.ts
CHANGED
|
@@ -9,20 +9,20 @@ export declare const injectEvents: (eventSource: new (path: string) => EventSour
|
|
|
9
9
|
* @public
|
|
10
10
|
*/
|
|
11
11
|
listeners: Set<Listener>;
|
|
12
|
-
options: Partial<Options> & {
|
|
13
|
-
name: string;
|
|
14
|
-
path: string;
|
|
15
|
-
};
|
|
16
12
|
/**
|
|
17
|
-
* EventSource `
|
|
13
|
+
* EventSource `onmessage` handler
|
|
18
14
|
* @public
|
|
19
15
|
*/
|
|
20
|
-
|
|
16
|
+
onmessage: (payload: MessageEvent) => Promise<void>;
|
|
21
17
|
/**
|
|
22
|
-
* EventSource `
|
|
18
|
+
* EventSource `onopen` handler
|
|
23
19
|
* @public
|
|
24
20
|
*/
|
|
25
|
-
|
|
21
|
+
onopen: () => void;
|
|
22
|
+
options: Partial<Options> & {
|
|
23
|
+
name: string;
|
|
24
|
+
path: string;
|
|
25
|
+
};
|
|
26
26
|
/**
|
|
27
27
|
* EventSource `addMessageListener` handler
|
|
28
28
|
* @public
|
|
@@ -33,9 +33,9 @@ export declare const injectEvents: (eventSource: new (path: string) => EventSour
|
|
|
33
33
|
readonly url: string;
|
|
34
34
|
readonly withCredentials: boolean;
|
|
35
35
|
close(): void;
|
|
36
|
-
readonly
|
|
37
|
-
readonly
|
|
38
|
-
readonly
|
|
36
|
+
readonly CONNECTING: 0;
|
|
37
|
+
readonly OPEN: 1;
|
|
38
|
+
readonly CLOSED: 2;
|
|
39
39
|
addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
40
40
|
addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;
|
|
41
41
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
@@ -59,20 +59,20 @@ export declare const injectEvents: (eventSource: new (path: string) => EventSour
|
|
|
59
59
|
* @public
|
|
60
60
|
*/
|
|
61
61
|
listeners: Set<Listener>;
|
|
62
|
-
options: Partial<Options> & {
|
|
63
|
-
name: string;
|
|
64
|
-
path: string;
|
|
65
|
-
};
|
|
66
62
|
/**
|
|
67
|
-
* EventSource `
|
|
63
|
+
* EventSource `onmessage` handler
|
|
68
64
|
* @public
|
|
69
65
|
*/
|
|
70
|
-
|
|
66
|
+
onmessage: (payload: MessageEvent) => Promise<void>;
|
|
71
67
|
/**
|
|
72
|
-
* EventSource `
|
|
68
|
+
* EventSource `onopen` handler
|
|
73
69
|
* @public
|
|
74
70
|
*/
|
|
75
|
-
|
|
71
|
+
onopen: () => void;
|
|
72
|
+
options: Partial<Options> & {
|
|
73
|
+
name: string;
|
|
74
|
+
path: string;
|
|
75
|
+
};
|
|
76
76
|
/**
|
|
77
77
|
* EventSource `addMessageListener` handler
|
|
78
78
|
* @public
|
|
@@ -83,9 +83,9 @@ export declare const injectEvents: (eventSource: new (path: string) => EventSour
|
|
|
83
83
|
readonly url: string;
|
|
84
84
|
readonly withCredentials: boolean;
|
|
85
85
|
close(): void;
|
|
86
|
-
readonly
|
|
87
|
-
readonly
|
|
88
|
-
readonly
|
|
86
|
+
readonly CONNECTING: 0;
|
|
87
|
+
readonly OPEN: 1;
|
|
88
|
+
readonly CLOSED: 2;
|
|
89
89
|
addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
90
90
|
addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;
|
|
91
91
|
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
package/lib/hot/events.js
CHANGED
|
@@ -1,13 +1,4 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
-
});
|
|
10
|
-
};
|
|
11
2
|
export const injectEvents = (eventSource) => {
|
|
12
3
|
/**
|
|
13
4
|
* EventSource wrapper
|
|
@@ -34,31 +25,29 @@ export const injectEvents = (eventSource) => {
|
|
|
34
25
|
* @public
|
|
35
26
|
*/
|
|
36
27
|
this.listeners = new Set();
|
|
37
|
-
/**
|
|
38
|
-
* EventSource `onopen` handler
|
|
39
|
-
* @public
|
|
40
|
-
*/
|
|
41
|
-
this.onopen = function () { };
|
|
42
28
|
/**
|
|
43
29
|
* EventSource `onmessage` handler
|
|
44
30
|
* @public
|
|
45
31
|
*/
|
|
46
|
-
this.onmessage = function (payload) {
|
|
47
|
-
|
|
48
|
-
|
|
32
|
+
this.onmessage = async function (payload) {
|
|
33
|
+
if (!payload?.data || payload.data == `\uD83D\uDC93`) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const data = JSON.parse(payload.data);
|
|
38
|
+
if (!data)
|
|
49
39
|
return;
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
yield Promise.all([...this.listeners].map((listener) => __awaiter(this, void 0, void 0, function* () {
|
|
56
|
-
return yield listener(data);
|
|
57
|
-
})));
|
|
58
|
-
}
|
|
59
|
-
catch (ex) { }
|
|
60
|
-
});
|
|
40
|
+
await Promise.all([...this.listeners].map(async (listener) => {
|
|
41
|
+
return await listener(data);
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
catch (ex) { }
|
|
61
45
|
};
|
|
46
|
+
/**
|
|
47
|
+
* EventSource `onopen` handler
|
|
48
|
+
* @public
|
|
49
|
+
*/
|
|
50
|
+
this.onopen = function () { };
|
|
62
51
|
this.onopen = this.onopen.bind(this);
|
|
63
52
|
this.onmessage = this.onmessage.bind(this);
|
|
64
53
|
this.addListener = this.addListener.bind(this);
|
package/lib/hot/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* global __resourceQuery */
|
|
3
|
+
/* global module */
|
|
4
|
+
import { client } from './client.js';
|
|
5
|
+
try {
|
|
6
|
+
client(__resourceQuery, import.meta.webpackHot);
|
|
7
|
+
}
|
|
8
|
+
catch (err) {
|
|
9
|
+
console.error(err);
|
|
10
|
+
try {
|
|
11
|
+
client(__resourceQuery, module.hot);
|
|
12
|
+
}
|
|
13
|
+
catch (error) {
|
|
14
|
+
console.error(error);
|
|
15
|
+
}
|
|
16
|
+
}
|
package/lib/hot/log.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
export declare const makeLogger: (options: Options) => {
|
|
2
|
-
log: (...args: any[]) => void;
|
|
3
2
|
error: (...args: any[]) => void;
|
|
4
|
-
warn: (...args: any[]) => void;
|
|
5
3
|
info: (...args: any[]) => void;
|
|
4
|
+
log: (...args: any[]) => void;
|
|
5
|
+
warn: (...args: any[]) => void;
|
|
6
6
|
};
|
|
7
7
|
export declare const makeLog: (options: any) => (...args: any[]) => void;
|
|
8
8
|
export declare const makeInfo: (options: any) => (...args: any[]) => void;
|
package/lib/hot/log.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
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
10
|
let lastLog = null;
|
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
|
|
@@ -24,7 +24,7 @@ const setFromParameters = (query) => {
|
|
|
24
24
|
parsedParams[key] =
|
|
25
25
|
value === `true` ? true : value === `false` ? false : value;
|
|
26
26
|
});
|
|
27
|
-
data[parsedParams.name] =
|
|
27
|
+
data[parsedParams.name] = { ...data, ...parsedParams };
|
|
28
28
|
return data[parsedParams.name];
|
|
29
29
|
};
|
|
30
30
|
export { data, get, setFromParameters };
|
|
@@ -1,26 +1,15 @@
|
|
|
1
1
|
/* eslint-disable no-console */
|
|
2
2
|
/* global __resourceQuery */
|
|
3
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
-
});
|
|
11
|
-
};
|
|
12
3
|
import intercept from './index.js';
|
|
13
|
-
window.requestAnimationFrame(function ready() {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
: window.requestAnimationFrame(ready);
|
|
25
|
-
});
|
|
4
|
+
window.requestAnimationFrame(async function ready() {
|
|
5
|
+
if (!__resourceQuery)
|
|
6
|
+
return;
|
|
7
|
+
const params = new URLSearchParams(__resourceQuery);
|
|
8
|
+
if (!params || !params.has(`search`) || !params.has(`replace`))
|
|
9
|
+
return;
|
|
10
|
+
const search = decodeURI(params.get(`search`));
|
|
11
|
+
const replace = decodeURI(params.get(`replace`));
|
|
12
|
+
return document.body
|
|
13
|
+
? intercept(search, replace)
|
|
14
|
+
: window.requestAnimationFrame(ready);
|
|
26
15
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@roots/bud-client",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.13.1",
|
|
4
4
|
"description": "Client scripts for @roots/bud",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=16"
|
|
@@ -43,13 +43,14 @@
|
|
|
43
43
|
"lib",
|
|
44
44
|
"src"
|
|
45
45
|
],
|
|
46
|
+
"type": "module",
|
|
46
47
|
"exports": {
|
|
47
48
|
".": {
|
|
48
|
-
"
|
|
49
|
-
"default": "./lib/index.
|
|
49
|
+
"import": "./lib/index.js",
|
|
50
|
+
"default": "./lib/index.js"
|
|
50
51
|
},
|
|
51
52
|
"./lib/*": {
|
|
52
|
-
"
|
|
53
|
+
"import": "./lib/*",
|
|
53
54
|
"default": "./lib/*"
|
|
54
55
|
}
|
|
55
56
|
},
|
|
@@ -64,16 +65,15 @@
|
|
|
64
65
|
}
|
|
65
66
|
},
|
|
66
67
|
"types": "./lib/index.d.ts",
|
|
67
|
-
"main": "./lib/index.cjs",
|
|
68
68
|
"module": "./lib/index.mjs",
|
|
69
69
|
"devDependencies": {
|
|
70
|
-
"@roots/bud": "6.
|
|
70
|
+
"@roots/bud": "6.13.1",
|
|
71
71
|
"@skypack/package-check": "0.2.2",
|
|
72
|
-
"@types/node": "18.16.
|
|
73
|
-
"@types/webpack-env": "1.18.
|
|
72
|
+
"@types/node": "18.16.16",
|
|
73
|
+
"@types/webpack-env": "1.18.1"
|
|
74
74
|
},
|
|
75
75
|
"dependencies": {
|
|
76
|
-
"tslib": "2.5.
|
|
76
|
+
"tslib": "2.5.3"
|
|
77
77
|
},
|
|
78
78
|
"volta": {
|
|
79
79
|
"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()
|
|
@@ -111,12 +111,14 @@ export const client = async (
|
|
|
111
111
|
}
|
|
112
112
|
|
|
113
113
|
/* Instantiate indicator, overlay */
|
|
114
|
-
|
|
114
|
+
try {
|
|
115
|
+
await components.make(options)
|
|
116
|
+
} catch (error) {}
|
|
115
117
|
|
|
116
118
|
/* Instantiate eventSource */
|
|
117
119
|
const events = injectEvents(EventSource).make(options)
|
|
118
120
|
|
|
119
|
-
if (!window.bud.listeners[options.name]) {
|
|
121
|
+
if (!window.bud.listeners?.[options.name]) {
|
|
120
122
|
window.bud.listeners[options.name] = async payload => {
|
|
121
123
|
if (!payload) return
|
|
122
124
|
|
|
@@ -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
|
}
|