@roots/bud-client 0.0.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/LICENSE.md +19 -0
- package/README.md +77 -0
- package/lib/hot/client.d.ts +6 -0
- package/lib/hot/client.d.ts.map +1 -0
- package/lib/hot/client.js +143 -0
- package/lib/hot/components/index.d.ts +2 -0
- package/lib/hot/components/index.d.ts.map +1 -0
- package/lib/hot/components/index.js +32 -0
- package/lib/hot/components/indicator/index.d.ts +4 -0
- package/lib/hot/components/indicator/index.d.ts.map +1 -0
- package/lib/hot/components/indicator/index.js +17 -0
- package/lib/hot/components/indicator/indicator.component.d.ts +84 -0
- package/lib/hot/components/indicator/indicator.component.d.ts.map +1 -0
- package/lib/hot/components/indicator/indicator.component.js +175 -0
- package/lib/hot/components/indicator/indicator.controller.d.ts +45 -0
- package/lib/hot/components/indicator/indicator.controller.d.ts.map +1 -0
- package/lib/hot/components/indicator/indicator.controller.js +54 -0
- package/lib/hot/components/indicator/indicator.pulse.d.ts +9 -0
- package/lib/hot/components/indicator/indicator.pulse.d.ts.map +1 -0
- package/lib/hot/components/indicator/indicator.pulse.js +36 -0
- package/lib/hot/components/overlay/index.d.ts +4 -0
- package/lib/hot/components/overlay/index.d.ts.map +1 -0
- package/lib/hot/components/overlay/index.js +17 -0
- package/lib/hot/components/overlay/overlay.component.d.ts +20 -0
- package/lib/hot/components/overlay/overlay.component.d.ts.map +1 -0
- package/lib/hot/components/overlay/overlay.component.js +146 -0
- package/lib/hot/components/overlay/overlay.controller.d.ts +46 -0
- package/lib/hot/components/overlay/overlay.controller.d.ts.map +1 -0
- package/lib/hot/components/overlay/overlay.controller.js +70 -0
- package/lib/hot/events.d.ts +98 -0
- package/lib/hot/events.d.ts.map +1 -0
- package/lib/hot/events.js +89 -0
- package/lib/hot/index.cjs +5 -0
- package/lib/hot/index.d.cts +2 -0
- package/lib/hot/index.d.cts.map +1 -0
- package/lib/hot/index.d.mts +2 -0
- package/lib/hot/index.d.mts.map +1 -0
- package/lib/hot/index.mjs +17 -0
- package/lib/hot/log.d.ts +11 -0
- package/lib/hot/log.d.ts.map +1 -0
- package/lib/hot/log.js +37 -0
- package/lib/hot/options.d.ts +17 -0
- package/lib/hot/options.d.ts.map +1 -0
- package/lib/hot/options.js +33 -0
- package/lib/index.cjs +3 -0
- package/lib/index.d.cts +13 -0
- package/lib/index.d.cts.map +1 -0
- package/lib/index.d.mts +13 -0
- package/lib/index.d.mts.map +1 -0
- package/lib/index.mjs +3 -0
- package/lib/intercept/index.d.ts +3 -0
- package/lib/intercept/index.d.ts.map +1 -0
- package/lib/intercept/index.js +18 -0
- package/lib/intercept/proxy-click-interceptor.d.ts +2 -0
- package/lib/intercept/proxy-click-interceptor.d.ts.map +1 -0
- package/lib/intercept/proxy-click-interceptor.js +26 -0
- package/package.json +79 -0
- package/src/hot/client.test.ts +78 -0
- package/src/hot/client.ts +156 -0
- package/src/hot/components/index.ts +33 -0
- package/src/hot/components/indicator/index.ts +11 -0
- package/src/hot/components/indicator/indicator.component.ts +216 -0
- package/src/hot/components/indicator/indicator.controller.ts +76 -0
- package/src/hot/components/indicator/indicator.pulse.ts +43 -0
- package/src/hot/components/overlay/index.ts +12 -0
- package/src/hot/components/overlay/overlay.component.ts +165 -0
- package/src/hot/components/overlay/overlay.controller.ts +86 -0
- package/src/hot/events.ts +93 -0
- package/src/hot/index.cts +7 -0
- package/src/hot/index.mts +9 -0
- package/src/hot/log.ts +42 -0
- package/src/hot/options.ts +40 -0
- package/src/index.cts +16 -0
- package/src/index.mts +16 -0
- package/src/intercept/index.ts +33 -0
- package/src/intercept/proxy-click-interceptor.ts +18 -0
- package/src/types/index.d.ts +54 -0
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export interface pulse {
|
|
2
|
+
(name: string, color: [number, number, number]): string;
|
|
3
|
+
}
|
|
4
|
+
/**
|
|
5
|
+
* CSS animation for reload indicator
|
|
6
|
+
* @public
|
|
7
|
+
*/
|
|
8
|
+
export declare const pulse: (name: string, color: [number, number, number, number]) => string;
|
|
9
|
+
//# sourceMappingURL=indicator.pulse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"indicator.pulse.d.ts","sourceRoot":"","sources":["../../../../src/hot/components/indicator/indicator.pulse.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,KAAK;IACpB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,GAAG,MAAM,CAAA;CACxD;AAED;;;GAGG;AACH,eAAO,MAAM,KAAK,SACV,MAAM,SACL,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,KACtC,MA+BF,CAAA"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS animation for reload indicator
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export const pulse = (name, color) => `
|
|
6
|
+
.${name} {
|
|
7
|
+
box-shadow: 0 0 0 0 rgba(${color[0]}, ${color[1]}, ${color[2]}, ${color[3]});
|
|
8
|
+
animation: ${name}__pulse 2s infinite;
|
|
9
|
+
transition: all 0.4s ease-in-out;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.${name}:not(.show) {
|
|
13
|
+
background-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, 0);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.${name}.show {
|
|
17
|
+
background-color: rgba(${color[0]}, ${color[1]}, ${color[2]}, ${color[3]});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
@keyframes ${name}__pulse {
|
|
21
|
+
0% {
|
|
22
|
+
transform: scale(0.95);
|
|
23
|
+
box-shadow: 0 0 0 0 rgba(${color[0]}, ${color[1]}, ${color[2]}, 0.7);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
70% {
|
|
27
|
+
transform: scale(1);
|
|
28
|
+
box-shadow: 0 0 0 10px rgba(${color[0]}, ${color[1]}, ${color[2]}, 0);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
100% {
|
|
32
|
+
transform: scale(0.95);
|
|
33
|
+
box-shadow: 0 0 0 0 rgba(${color[0]}, ${color[1]}, ${color[2]}, 0);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
`;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hot/components/overlay/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI;mBACA,OAAO,KAAK,IAAI;EAOhC,CAAA"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { Component } from './overlay.component.js';
|
|
11
|
+
import { Controller } from './overlay.controller.js';
|
|
12
|
+
export const make = () => __awaiter(void 0, void 0, void 0, function* () {
|
|
13
|
+
if (customElements.get(`bud-error`))
|
|
14
|
+
return;
|
|
15
|
+
customElements.define(`bud-error`, Component);
|
|
16
|
+
return new Controller();
|
|
17
|
+
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component container
|
|
3
|
+
*/
|
|
4
|
+
export declare class Component extends HTMLElement {
|
|
5
|
+
name: string;
|
|
6
|
+
/**
|
|
7
|
+
* WHM payload
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
payload: any;
|
|
12
|
+
documentBodyStyle: any;
|
|
13
|
+
get message(): string;
|
|
14
|
+
constructor();
|
|
15
|
+
renderShadow(): void;
|
|
16
|
+
static get observedAttributes(): string[];
|
|
17
|
+
attributeChangedCallback(): void;
|
|
18
|
+
connectedCallback(): void;
|
|
19
|
+
}
|
|
20
|
+
//# sourceMappingURL=overlay.component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay.component.d.ts","sourceRoot":"","sources":["../../../../src/hot/components/overlay/overlay.component.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,qBAAa,SAAU,SAAQ,WAAW;IACjC,IAAI,EAAE,MAAM,CAAgB;IAEnC;;;;OAIG;IACI,OAAO,EAAE,GAAG,CAAA;IAEZ,iBAAiB,EAAE,GAAG,CAAA;IAE7B,IAAW,OAAO,WAEjB;;IAOM,YAAY,IAAI,IAAI;IA+G3B,WAAkB,kBAAkB,aAEnC;IAEM,wBAAwB;IAsBxB,iBAAiB;CAGzB"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Component container
|
|
3
|
+
*/
|
|
4
|
+
export class Component extends HTMLElement {
|
|
5
|
+
get message() {
|
|
6
|
+
return this.getAttribute(`message`);
|
|
7
|
+
}
|
|
8
|
+
constructor() {
|
|
9
|
+
super();
|
|
10
|
+
this.name = `bud-overlay`;
|
|
11
|
+
this.renderShadow();
|
|
12
|
+
}
|
|
13
|
+
renderShadow() {
|
|
14
|
+
const container = document.createElement(`div`);
|
|
15
|
+
container.classList.add(`overlay`);
|
|
16
|
+
container.innerHTML = `
|
|
17
|
+
<style>
|
|
18
|
+
.overlay {
|
|
19
|
+
width: 100vw;
|
|
20
|
+
backdrop-filter: blur(10px);
|
|
21
|
+
display: flex;
|
|
22
|
+
height: 100vh;
|
|
23
|
+
border-top: 2px solid transparent;
|
|
24
|
+
overflow-x: hidden;
|
|
25
|
+
overflow-y: scroll;
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: -1000px;
|
|
28
|
+
left: 0;
|
|
29
|
+
right: 0;
|
|
30
|
+
bottom: 0;
|
|
31
|
+
opacity: 0;
|
|
32
|
+
transition: opacity 0.2s ease-in-out, border 0.4s ease-in-out;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.visible {
|
|
37
|
+
position: fixed;
|
|
38
|
+
top: 0;
|
|
39
|
+
z-index: 9998;
|
|
40
|
+
opacity: 1;
|
|
41
|
+
border-top: 5px solid red;
|
|
42
|
+
transition: opacity 0.2s ease-in-out, border 0.4s ease-in-out;
|
|
43
|
+
max-width: 100vw;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.messages {
|
|
47
|
+
background-color: white;
|
|
48
|
+
border-radius: 5px;
|
|
49
|
+
filter: drop-shadow(0 1px 2px rgb(0 0 0 / 0.1)) drop-shadow(0 1px 1px rgb(0 0 0 / 0.06));
|
|
50
|
+
display: flex;
|
|
51
|
+
align-self: center;
|
|
52
|
+
width: 800px;
|
|
53
|
+
max-width: 90vw;
|
|
54
|
+
margin-left: auto;
|
|
55
|
+
margin-right: auto;
|
|
56
|
+
flex-direction: column;
|
|
57
|
+
flex-wrap: wrap;
|
|
58
|
+
align-items: center;
|
|
59
|
+
align-content: center;
|
|
60
|
+
padding: 2rem 2rem 0rem 2rem;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
.visible .messages > div {
|
|
64
|
+
position: relative;
|
|
65
|
+
top: 0;
|
|
66
|
+
opacity: 1;
|
|
67
|
+
transition: all: 0.2s ease-in-out;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.messages > div {
|
|
71
|
+
position: relative;
|
|
72
|
+
top: 20px;
|
|
73
|
+
opacity: 0;
|
|
74
|
+
transition: all: 0.2s ease-in-out;
|
|
75
|
+
align-items: center;
|
|
76
|
+
align-content: center;
|
|
77
|
+
color: rgba(0, 0, 0, 0.87);
|
|
78
|
+
flex-direction: column;
|
|
79
|
+
font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol";
|
|
80
|
+
padding: 0rem 2rem 2rem 2rem;
|
|
81
|
+
width: 100%;
|
|
82
|
+
max-width:95vw;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
.messages > div > pre {
|
|
86
|
+
font-weight: 300;
|
|
87
|
+
font-size: 0.8rem;
|
|
88
|
+
overflow-x: scroll;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
pre {
|
|
92
|
+
background: #303030;
|
|
93
|
+
color: #f1f1f1;
|
|
94
|
+
padding: 10px 16px;
|
|
95
|
+
border-radius: 2px;
|
|
96
|
+
border-top: 4px solid #dd0303;
|
|
97
|
+
-moz-box-shadow: inset 0 0 10px #000;
|
|
98
|
+
box-shadow: inset 0 0 10px #000;
|
|
99
|
+
counter-reset: line;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
pre span {
|
|
103
|
+
display: block;
|
|
104
|
+
line-height: 1.5rem;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
pre span:before {
|
|
108
|
+
counter-increment: line;
|
|
109
|
+
content: counter(line);
|
|
110
|
+
display: inline-block;
|
|
111
|
+
border-right: 1px solid #ddd;
|
|
112
|
+
padding: 0 .5em;
|
|
113
|
+
margin-right: .5em;
|
|
114
|
+
color: #888;
|
|
115
|
+
width: 30px;
|
|
116
|
+
}
|
|
117
|
+
</style>
|
|
118
|
+
<div class="messages"></div>
|
|
119
|
+
`;
|
|
120
|
+
this.attachShadow({ mode: `open` }).appendChild(container);
|
|
121
|
+
}
|
|
122
|
+
static get observedAttributes() {
|
|
123
|
+
return [`message`];
|
|
124
|
+
}
|
|
125
|
+
attributeChangedCallback() {
|
|
126
|
+
var _a, _b, _c;
|
|
127
|
+
if (!this.documentBodyStyle)
|
|
128
|
+
this.documentBodyStyle = (_a = document.body) === null || _a === void 0 ? void 0 : _a.style;
|
|
129
|
+
if (this.getAttribute(`message`)) {
|
|
130
|
+
document.body.style.overflow = `hidden`;
|
|
131
|
+
this.shadowRoot.querySelector(`.overlay`).classList.add(`visible`);
|
|
132
|
+
this.shadowRoot.querySelector(`.messages`).innerHTML =
|
|
133
|
+
this.getAttribute(`message`);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (((_b = this.documentBodyStyle) === null || _b === void 0 ? void 0 : _b.overflow) && ((_c = document === null || document === void 0 ? void 0 : document.body) === null || _c === void 0 ? void 0 : _c.style)) {
|
|
137
|
+
document.body.style.overflow = this.documentBodyStyle.overflow;
|
|
138
|
+
}
|
|
139
|
+
this.shadowRoot.querySelector(`.overlay`).classList.remove(`visible`);
|
|
140
|
+
}
|
|
141
|
+
connectedCallback() {
|
|
142
|
+
var _a;
|
|
143
|
+
if ((_a = document.body) === null || _a === void 0 ? void 0 : _a.style)
|
|
144
|
+
this.documentBodyStyle = document.body.style;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Overlay controller
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
export declare class Controller {
|
|
6
|
+
/**
|
|
7
|
+
* Element
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
element: HTMLElement;
|
|
11
|
+
/**
|
|
12
|
+
* HMR update
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
payload: Payload;
|
|
16
|
+
/**
|
|
17
|
+
* Formatted error message
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
get message(): string;
|
|
21
|
+
/**
|
|
22
|
+
* Class constructor
|
|
23
|
+
*
|
|
24
|
+
* @public
|
|
25
|
+
*/
|
|
26
|
+
constructor();
|
|
27
|
+
/**
|
|
28
|
+
* Append `bud-error` element to the DOM
|
|
29
|
+
*
|
|
30
|
+
* @public
|
|
31
|
+
*/
|
|
32
|
+
createError(): void;
|
|
33
|
+
/**
|
|
34
|
+
* Remove `bud-error` element from the DOM (if present)
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
removeError(): void;
|
|
39
|
+
/**
|
|
40
|
+
* Update DOM
|
|
41
|
+
*
|
|
42
|
+
* @public
|
|
43
|
+
*/
|
|
44
|
+
update(payload: Payload): void;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=overlay.controller.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"overlay.controller.d.ts","sourceRoot":"","sources":["../../../../src/hot/components/overlay/overlay.controller.ts"],"names":[],"mappings":"AAQA;;;GAGG;AACH,qBAAa,UAAU;IACrB;;;OAGG;IACI,OAAO,EAAE,WAAW,CAAA;IAE3B;;;OAGG;IACI,OAAO,EAAE,OAAO,CAAA;IAEvB;;;OAGG;IACH,IAAW,OAAO,IAAI,MAAM,CAS3B;IAED;;;;OAIG;;IAMH;;;;OAIG;IACI,WAAW;IAKlB;;;;OAIG;IACI,WAAW;IAIlB;;;;OAIG;IACI,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,IAAI;CAWtC"}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
const ansiPattern = [
|
|
2
|
+
`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)`,
|
|
3
|
+
`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))`,
|
|
4
|
+
].join(`|`);
|
|
5
|
+
const stripAnsi = (body) => { var _a, _b; return (_b = (_a = body === null || body === void 0 ? void 0 : body.replace) === null || _a === void 0 ? void 0 : _a.call(body, new RegExp(ansiPattern, `g`), ``)) !== null && _b !== void 0 ? _b : body; };
|
|
6
|
+
/**
|
|
7
|
+
* Overlay controller
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
export class Controller {
|
|
11
|
+
/**
|
|
12
|
+
* Formatted error message
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
get message() {
|
|
16
|
+
var _a;
|
|
17
|
+
return (_a = this.payload.errors) === null || _a === void 0 ? void 0 : _a.reduce((a, c) => {
|
|
18
|
+
var _a, _b;
|
|
19
|
+
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;
|
|
20
|
+
if (!msg)
|
|
21
|
+
return a;
|
|
22
|
+
return `${a}
|
|
23
|
+
<div>
|
|
24
|
+
<pre>${stripAnsi(msg)}</pre>
|
|
25
|
+
</div>`;
|
|
26
|
+
}, ``);
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Class constructor
|
|
30
|
+
*
|
|
31
|
+
* @public
|
|
32
|
+
*/
|
|
33
|
+
constructor() {
|
|
34
|
+
this.update = this.update.bind(this);
|
|
35
|
+
this.element = document.createElement(`bud-error`);
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Append `bud-error` element to the DOM
|
|
39
|
+
*
|
|
40
|
+
* @public
|
|
41
|
+
*/
|
|
42
|
+
createError() {
|
|
43
|
+
var _a;
|
|
44
|
+
!document.body.querySelector(`bud-error`) &&
|
|
45
|
+
((_a = document.body) === null || _a === void 0 ? void 0 : _a.appendChild(this.element));
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Remove `bud-error` element from the DOM (if present)
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
removeError() {
|
|
53
|
+
var _a;
|
|
54
|
+
(_a = document.body.querySelector(`bud-error`)) === null || _a === void 0 ? void 0 : _a.remove();
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Update DOM
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
update(payload) {
|
|
62
|
+
var _a, _b;
|
|
63
|
+
this.payload = payload;
|
|
64
|
+
this.element.setAttribute(`message`, (_a = this.message) !== null && _a !== void 0 ? _a : ``);
|
|
65
|
+
if (((_b = this.payload.errors) === null || _b === void 0 ? void 0 : _b.length) > 0) {
|
|
66
|
+
return this.createError();
|
|
67
|
+
}
|
|
68
|
+
this.removeError();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
export declare const injectEvents: (eventSource: new (path: string) => EventSource) => {
|
|
2
|
+
new (options: Partial<Options> & {
|
|
3
|
+
name: string;
|
|
4
|
+
path: string;
|
|
5
|
+
}): {
|
|
6
|
+
/**
|
|
7
|
+
* Registered listeners
|
|
8
|
+
*
|
|
9
|
+
* @public
|
|
10
|
+
*/
|
|
11
|
+
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
|
+
/**
|
|
22
|
+
* EventSource `onmessage` handler
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
onmessage: (payload: MessageEvent) => Promise<void>;
|
|
26
|
+
/**
|
|
27
|
+
* EventSource `addMessageListener` handler
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
addListener(listener: Listener): this;
|
|
31
|
+
onerror: (this: EventSource, ev: Event) => any;
|
|
32
|
+
readonly readyState: number;
|
|
33
|
+
readonly url: string;
|
|
34
|
+
readonly withCredentials: boolean;
|
|
35
|
+
close(): void;
|
|
36
|
+
readonly CLOSED: number;
|
|
37
|
+
readonly CONNECTING: number;
|
|
38
|
+
readonly OPEN: number;
|
|
39
|
+
addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
40
|
+
addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;
|
|
41
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
42
|
+
removeEventListener<K_1 extends keyof EventSourceEventMap>(type: K_1, listener: (this: EventSource, ev: EventSourceEventMap[K_1]) => any, options?: boolean | EventListenerOptions): void;
|
|
43
|
+
removeEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | EventListenerOptions): void;
|
|
44
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
45
|
+
dispatchEvent(event: Event): boolean;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Singleton constructor
|
|
49
|
+
*
|
|
50
|
+
* @public
|
|
51
|
+
*/
|
|
52
|
+
make(options: Partial<Options> & {
|
|
53
|
+
name: string;
|
|
54
|
+
path: string;
|
|
55
|
+
}): {
|
|
56
|
+
/**
|
|
57
|
+
* Registered listeners
|
|
58
|
+
*
|
|
59
|
+
* @public
|
|
60
|
+
*/
|
|
61
|
+
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
|
+
/**
|
|
72
|
+
* EventSource `onmessage` handler
|
|
73
|
+
* @public
|
|
74
|
+
*/
|
|
75
|
+
onmessage: (payload: MessageEvent) => Promise<void>;
|
|
76
|
+
/**
|
|
77
|
+
* EventSource `addMessageListener` handler
|
|
78
|
+
* @public
|
|
79
|
+
*/
|
|
80
|
+
addListener(listener: Listener): this;
|
|
81
|
+
onerror: (this: EventSource, ev: Event) => any;
|
|
82
|
+
readonly readyState: number;
|
|
83
|
+
readonly url: string;
|
|
84
|
+
readonly withCredentials: boolean;
|
|
85
|
+
close(): void;
|
|
86
|
+
readonly CLOSED: number;
|
|
87
|
+
readonly CONNECTING: number;
|
|
88
|
+
readonly OPEN: number;
|
|
89
|
+
addEventListener<K extends keyof EventSourceEventMap>(type: K, listener: (this: EventSource, ev: EventSourceEventMap[K]) => any, options?: boolean | AddEventListenerOptions): void;
|
|
90
|
+
addEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | AddEventListenerOptions): void;
|
|
91
|
+
addEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void;
|
|
92
|
+
removeEventListener<K_1 extends keyof EventSourceEventMap>(type: K_1, listener: (this: EventSource, ev: EventSourceEventMap[K_1]) => any, options?: boolean | EventListenerOptions): void;
|
|
93
|
+
removeEventListener(type: string, listener: (this: EventSource, event: MessageEvent<any>) => any, options?: boolean | EventListenerOptions): void;
|
|
94
|
+
removeEventListener(type: string, listener: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void;
|
|
95
|
+
dispatchEvent(event: Event): boolean;
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
//# sourceMappingURL=events.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events.d.ts","sourceRoot":"","sources":["../../src/hot/events.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,YAAY,2BACC,MAAM,KAAK,WAAW;kBA4B1B,QAAQ,OAAO,CAAC,GAAG;QAAC,MAAM,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC;QAhBjE;;;;WAIG;mBACe,IAAI,QAAQ,CAAC;iBAWb,QAAQ,OAAO,CAAC,GAAG;YAAC,MAAM,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAC;QAyBjE;;;WAGG;;QAGH;;;WAGG;6BACkD,YAAY;QAiBjE;;;WAGG;8BAC0B,QAAQ,GAAG,IAAI;;;;;;;;;;;;;;;;;IA/C5C;;;;OAIG;kBAEQ,QAAQ,OAAO,CAAC,GAAG;QAAC,MAAM,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAC;QA/B1D;;;;WAIG;mBACe,IAAI,QAAQ,CAAC;iBAWb,QAAQ,OAAO,CAAC,GAAG;YAAC,MAAM,MAAM,CAAC;YAAC,IAAI,EAAE,MAAM,CAAA;SAAC;QAyBjE;;;WAGG;;QAGH;;;WAGG;6BACkD,YAAY;QAiBjE;;;WAGG;8BAC0B,QAAQ,GAAG,IAAI;;;;;;;;;;;;;;;;;CAK/C,CAAA"}
|
|
@@ -0,0 +1,89 @@
|
|
|
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
|
+
export const injectEvents = (eventSource) => {
|
|
12
|
+
/**
|
|
13
|
+
* EventSource wrapper
|
|
14
|
+
*
|
|
15
|
+
* @remarks
|
|
16
|
+
* wraps EventSource in a function to allow for
|
|
17
|
+
* mocking in tests
|
|
18
|
+
*
|
|
19
|
+
* @public
|
|
20
|
+
*/
|
|
21
|
+
return class Events extends eventSource {
|
|
22
|
+
/**
|
|
23
|
+
* Class constructor
|
|
24
|
+
*
|
|
25
|
+
* @remarks
|
|
26
|
+
* Singleton interface, so this is private.
|
|
27
|
+
*
|
|
28
|
+
* @public
|
|
29
|
+
*/
|
|
30
|
+
constructor(options) {
|
|
31
|
+
super(options.path);
|
|
32
|
+
this.options = options;
|
|
33
|
+
/**
|
|
34
|
+
* Registered listeners
|
|
35
|
+
*
|
|
36
|
+
* @public
|
|
37
|
+
*/
|
|
38
|
+
this.listeners = new Set();
|
|
39
|
+
/**
|
|
40
|
+
* EventSource `onopen` handler
|
|
41
|
+
* @public
|
|
42
|
+
*/
|
|
43
|
+
this.onopen = function () { };
|
|
44
|
+
/**
|
|
45
|
+
* EventSource `onmessage` handler
|
|
46
|
+
* @public
|
|
47
|
+
*/
|
|
48
|
+
this.onmessage = function (payload) {
|
|
49
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
50
|
+
if (!(payload === null || payload === void 0 ? void 0 : payload.data) || payload.data == `\uD83D\uDC93`) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
const data = JSON.parse(payload.data);
|
|
55
|
+
if (!data)
|
|
56
|
+
return;
|
|
57
|
+
yield Promise.all([...this.listeners].map((listener) => __awaiter(this, void 0, void 0, function* () {
|
|
58
|
+
return yield listener(data);
|
|
59
|
+
})));
|
|
60
|
+
}
|
|
61
|
+
catch (ex) { }
|
|
62
|
+
});
|
|
63
|
+
};
|
|
64
|
+
this.onopen = this.onopen.bind(this);
|
|
65
|
+
this.onmessage = this.onmessage.bind(this);
|
|
66
|
+
this.addListener = this.addListener.bind(this);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Singleton constructor
|
|
70
|
+
*
|
|
71
|
+
* @public
|
|
72
|
+
*/
|
|
73
|
+
static make(options) {
|
|
74
|
+
if (typeof window.bud.hmr[options.name] === `undefined`)
|
|
75
|
+
Object.assign(window.bud.hmr, {
|
|
76
|
+
[options.name]: new Events(options),
|
|
77
|
+
});
|
|
78
|
+
return window.bud.hmr[options.name];
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* EventSource `addMessageListener` handler
|
|
82
|
+
* @public
|
|
83
|
+
*/
|
|
84
|
+
addListener(listener) {
|
|
85
|
+
this.listeners.add(listener);
|
|
86
|
+
return this;
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.cts","sourceRoot":"","sources":["../../src/hot/index.cts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","sourceRoot":"","sources":["../../src/hot/index.mts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* global __resourceQuery */
|
|
3
|
+
/* global module */
|
|
4
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
5
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
6
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
7
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
8
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
9
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
10
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
11
|
+
});
|
|
12
|
+
};
|
|
13
|
+
;
|
|
14
|
+
(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
15
|
+
return yield import(`./client.js`).then((module) => __awaiter(void 0, void 0, void 0, function* () { return yield module.client(__resourceQuery, import.meta.webpackHot); }));
|
|
16
|
+
}))();
|
|
17
|
+
export {};
|
package/lib/hot/log.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export declare const makeLogger: (options: Options) => {
|
|
2
|
+
log: (...args: any[]) => void;
|
|
3
|
+
error: (...args: any[]) => void;
|
|
4
|
+
warn: (...args: any[]) => void;
|
|
5
|
+
info: (...args: any[]) => void;
|
|
6
|
+
};
|
|
7
|
+
export declare const makeLog: (options: any) => (...args: any[]) => void;
|
|
8
|
+
export declare const makeInfo: (options: any) => (...args: any[]) => void;
|
|
9
|
+
export declare const makeError: (options: any) => (...args: any[]) => void;
|
|
10
|
+
export declare const makeWarn: (options: any) => (...args: any[]) => void;
|
|
11
|
+
//# sourceMappingURL=log.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.d.ts","sourceRoot":"","sources":["../../src/hot/log.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,UAAU,YAAa,OAAO;;;;;CAO1C,CAAA;AAGD,eAAO,MAAM,OAAO,4CASnB,CAAA;AAED,eAAO,MAAM,QAAQ,4CAMpB,CAAA;AAED,eAAO,MAAM,SAAS,4CAIrB,CAAA;AAED,eAAO,MAAM,QAAQ,4CAIpB,CAAA"}
|
package/lib/hot/log.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
export const makeLogger = (options) => {
|
|
3
|
+
return {
|
|
4
|
+
log: makeLog(options),
|
|
5
|
+
error: makeError(options),
|
|
6
|
+
warn: makeWarn(options),
|
|
7
|
+
info: makeInfo(options),
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
let lastLog = null;
|
|
11
|
+
export const makeLog = options => {
|
|
12
|
+
return (...args) => {
|
|
13
|
+
if (options.log) {
|
|
14
|
+
if (lastLog === args.join(``))
|
|
15
|
+
return;
|
|
16
|
+
lastLog = args.join(``);
|
|
17
|
+
console.log(`[${options.name}]`, ...args);
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
};
|
|
21
|
+
export const makeInfo = options => {
|
|
22
|
+
return (...args) => {
|
|
23
|
+
if (options.log) {
|
|
24
|
+
console.info(`[${options.name}]`, ...args);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
};
|
|
28
|
+
export const makeError = options => {
|
|
29
|
+
return (...args) => {
|
|
30
|
+
console.error(`[${options.name}]`, ...args);
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
export const makeWarn = options => {
|
|
34
|
+
return (...args) => {
|
|
35
|
+
console.warn(`[${options.name}]`, ...args);
|
|
36
|
+
};
|
|
37
|
+
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client options
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
declare let data: Options;
|
|
6
|
+
/**
|
|
7
|
+
* Get client option
|
|
8
|
+
* @public
|
|
9
|
+
*/
|
|
10
|
+
declare const get: (name?: string, key?: string) => any;
|
|
11
|
+
/**
|
|
12
|
+
* Set client data based on URL parameters
|
|
13
|
+
* @public
|
|
14
|
+
*/
|
|
15
|
+
declare const setFromParameters: (query: string) => Options;
|
|
16
|
+
export { data, get, setFromParameters };
|
|
17
|
+
//# sourceMappingURL=options.d.ts.map
|