@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,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
|
*/
|
package/src/hot/events.ts
CHANGED
|
@@ -18,6 +18,33 @@ export const injectEvents = (
|
|
|
18
18
|
*/
|
|
19
19
|
public listeners: Set<Listener> = new Set<Listener>()
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* EventSource `onmessage` handler
|
|
23
|
+
* @public
|
|
24
|
+
*/
|
|
25
|
+
public override onmessage = async function (payload: MessageEvent) {
|
|
26
|
+
if (!payload?.data || payload.data == `\uD83D\uDC93`) {
|
|
27
|
+
return
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
const data = JSON.parse(payload.data)
|
|
32
|
+
if (!data) return
|
|
33
|
+
|
|
34
|
+
await Promise.all(
|
|
35
|
+
[...this.listeners].map(async listener => {
|
|
36
|
+
return await listener(data)
|
|
37
|
+
}),
|
|
38
|
+
)
|
|
39
|
+
} catch (ex) {}
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* EventSource `onopen` handler
|
|
44
|
+
* @public
|
|
45
|
+
*/
|
|
46
|
+
public override onopen = function () {}
|
|
47
|
+
|
|
21
48
|
/**
|
|
22
49
|
* Class constructor
|
|
23
50
|
*
|
|
@@ -52,33 +79,6 @@ export const injectEvents = (
|
|
|
52
79
|
return window.bud.hmr[options.name]
|
|
53
80
|
}
|
|
54
81
|
|
|
55
|
-
/**
|
|
56
|
-
* EventSource `onopen` handler
|
|
57
|
-
* @public
|
|
58
|
-
*/
|
|
59
|
-
public override onopen = function () {}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* EventSource `onmessage` handler
|
|
63
|
-
* @public
|
|
64
|
-
*/
|
|
65
|
-
public override onmessage = async function (payload: MessageEvent) {
|
|
66
|
-
if (!payload?.data || payload.data == `\uD83D\uDC93`) {
|
|
67
|
-
return
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const data = JSON.parse(payload.data)
|
|
72
|
-
if (!data) return
|
|
73
|
-
|
|
74
|
-
await Promise.all(
|
|
75
|
-
[...this.listeners].map(async listener => {
|
|
76
|
-
return await listener(data)
|
|
77
|
-
}),
|
|
78
|
-
)
|
|
79
|
-
} catch (ex) {}
|
|
80
|
-
}
|
|
81
|
-
|
|
82
82
|
/**
|
|
83
83
|
* EventSource `addMessageListener` handler
|
|
84
84
|
* @public
|
package/src/hot/index.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* global __resourceQuery */
|
|
3
|
+
/* global module */
|
|
4
|
+
|
|
5
|
+
import {client} from './client.js'
|
|
6
|
+
|
|
7
|
+
try {
|
|
8
|
+
client(__resourceQuery, import.meta.webpackHot)
|
|
9
|
+
} catch (err) {
|
|
10
|
+
console.error(err)
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
client(__resourceQuery, module.hot)
|
|
14
|
+
} catch (error) {
|
|
15
|
+
console.error(error)
|
|
16
|
+
}
|
|
17
|
+
}
|
package/src/hot/log.ts
CHANGED
package/src/hot/options.ts
CHANGED
|
@@ -2,14 +2,14 @@
|
|
|
2
2
|
* Client options
|
|
3
3
|
*/
|
|
4
4
|
let data: Options = {
|
|
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
|
/**
|
package/src/intercept/index.ts
CHANGED
package/lib/hot/index.cjs
DELETED
package/lib/hot/index.d.mts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export {};
|
package/lib/hot/index.mjs
DELETED
|
@@ -1,17 +0,0 @@
|
|
|
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/index.cjs
DELETED
package/lib/index.d.mts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `@roots/bud` client scripts
|
|
3
|
-
*
|
|
4
|
-
* You should not import this root module.
|
|
5
|
-
* Import the components from the submodules instead.
|
|
6
|
-
*
|
|
7
|
-
* @see https://bud.js.org
|
|
8
|
-
* @see https://github.com/roots/bud
|
|
9
|
-
*
|
|
10
|
-
* @packageDocumentation
|
|
11
|
-
*/
|
|
12
|
-
export {};
|
package/lib/index.mjs
DELETED
package/src/hot/client.test.ts
DELETED
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-console */
|
|
2
|
-
/**
|
|
3
|
-
* @vitest-environment jsdom
|
|
4
|
-
*/
|
|
5
|
-
import {describe, expect, it, vi} from 'vitest'
|
|
6
|
-
|
|
7
|
-
import {client} from './client.js'
|
|
8
|
-
import {injectEvents} from './events.js'
|
|
9
|
-
import * as options from './options.js'
|
|
10
|
-
|
|
11
|
-
// @ts-ignore
|
|
12
|
-
global.EventSource = class Events {
|
|
13
|
-
public constructor() {}
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
window.EventSource = global.EventSource
|
|
17
|
-
|
|
18
|
-
const Events = injectEvents(global.EventSource)
|
|
19
|
-
|
|
20
|
-
// @ts-ignore
|
|
21
|
-
const webpackHotMock = {
|
|
22
|
-
hot: vi.fn(),
|
|
23
|
-
status: vi.fn(),
|
|
24
|
-
} as __WebpackModuleApi.Hot
|
|
25
|
-
|
|
26
|
-
describe(`@roots/bud-client`, () => {
|
|
27
|
-
it(`should be a fn module`, () => {
|
|
28
|
-
expect(client).toBeInstanceOf(Function)
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
it(`should add window.bud`, async () => {
|
|
32
|
-
await client(`?name=test`, webpackHotMock)
|
|
33
|
-
expect(window.bud).toBeDefined()
|
|
34
|
-
})
|
|
35
|
-
|
|
36
|
-
it(`should add window.bud.hmr as an instance of EventSource`, async () => {
|
|
37
|
-
await client(`?name=test`, webpackHotMock)
|
|
38
|
-
expect(window.bud?.hmr?.test).toBeInstanceOf(EventSource)
|
|
39
|
-
})
|
|
40
|
-
|
|
41
|
-
it(`should set clientOptions`, async () => {
|
|
42
|
-
await client(`?name=test`, webpackHotMock)
|
|
43
|
-
expect(options.data).toEqual(
|
|
44
|
-
expect.objectContaining({
|
|
45
|
-
debug: true,
|
|
46
|
-
indicator: true,
|
|
47
|
-
log: true,
|
|
48
|
-
name: `@roots/bud-client`,
|
|
49
|
-
overlay: true,
|
|
50
|
-
path: `/bud/hot`,
|
|
51
|
-
reload: true,
|
|
52
|
-
timeout: 2000,
|
|
53
|
-
}),
|
|
54
|
-
)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
it(`should call listener from onmessage`, async () => {
|
|
58
|
-
await client(`?name=test`, webpackHotMock)
|
|
59
|
-
const events = Events.make(options.data)
|
|
60
|
-
|
|
61
|
-
const listenerMock = vi.fn(async () => {})
|
|
62
|
-
events.addListener(listenerMock)
|
|
63
|
-
|
|
64
|
-
await events.onmessage(
|
|
65
|
-
// @ts-ignore
|
|
66
|
-
{
|
|
67
|
-
data: `{
|
|
68
|
-
"data": {
|
|
69
|
-
"hash": "test",
|
|
70
|
-
"action": "update"
|
|
71
|
-
}
|
|
72
|
-
}`,
|
|
73
|
-
},
|
|
74
|
-
)
|
|
75
|
-
|
|
76
|
-
expect(listenerMock).toHaveBeenCalled()
|
|
77
|
-
})
|
|
78
|
-
})
|
package/src/hot/index.cts
DELETED
package/src/hot/index.mts
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|