@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
package/src/hot/log.ts
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
|
|
3
|
+
export const makeLogger = (options: Options) => {
|
|
4
|
+
return {
|
|
5
|
+
log: makeLog(options),
|
|
6
|
+
error: makeError(options),
|
|
7
|
+
warn: makeWarn(options),
|
|
8
|
+
info: makeInfo(options),
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let lastLog: string = null
|
|
13
|
+
export const makeLog = options => {
|
|
14
|
+
return (...args) => {
|
|
15
|
+
if (options.log) {
|
|
16
|
+
if (lastLog === args.join(``)) return
|
|
17
|
+
lastLog = args.join(``)
|
|
18
|
+
|
|
19
|
+
console.log(`[${options.name}]`, ...args)
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export const makeInfo = options => {
|
|
25
|
+
return (...args) => {
|
|
26
|
+
if (options.log) {
|
|
27
|
+
console.info(`[${options.name}]`, ...args)
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export const makeError = options => {
|
|
33
|
+
return (...args) => {
|
|
34
|
+
console.error(`[${options.name}]`, ...args)
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export const makeWarn = options => {
|
|
39
|
+
return (...args) => {
|
|
40
|
+
console.warn(`[${options.name}]`, ...args)
|
|
41
|
+
}
|
|
42
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Client options
|
|
3
|
+
* @public
|
|
4
|
+
*/
|
|
5
|
+
let data: Options = {
|
|
6
|
+
timeout: 2000,
|
|
7
|
+
reload: true,
|
|
8
|
+
name: `@roots/bud-client`,
|
|
9
|
+
debug: true,
|
|
10
|
+
log: true,
|
|
11
|
+
indicator: true,
|
|
12
|
+
overlay: true,
|
|
13
|
+
path: `/bud/hot`,
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Get client option
|
|
18
|
+
* @public
|
|
19
|
+
*/
|
|
20
|
+
const get = (name?: string, key?: string) =>
|
|
21
|
+
key ? data[name][key] : data[name]
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Set client data based on URL parameters
|
|
25
|
+
* @public
|
|
26
|
+
*/
|
|
27
|
+
const setFromParameters = (query: string): Options => {
|
|
28
|
+
let parsedParams: Partial<Options> = {}
|
|
29
|
+
|
|
30
|
+
new window.URLSearchParams(query).forEach((value, key) => {
|
|
31
|
+
parsedParams[key] =
|
|
32
|
+
value === `true` ? true : value === `false` ? false : value
|
|
33
|
+
})
|
|
34
|
+
|
|
35
|
+
data[parsedParams.name] = {...data, ...parsedParams}
|
|
36
|
+
|
|
37
|
+
return data[parsedParams.name]
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export {data, get, setFromParameters}
|
package/src/index.cts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright © Roots Software Foundation LLC
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `@roots/bud` client scripts
|
|
6
|
+
*
|
|
7
|
+
* You should not import this root module.
|
|
8
|
+
* Import the components from the submodules instead.
|
|
9
|
+
*
|
|
10
|
+
* @see https://bud.js.org
|
|
11
|
+
* @see https://github.com/roots/bud
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export {}
|
package/src/index.mts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
// Copyright © Roots Software Foundation LLC
|
|
2
|
+
// Licensed under the MIT license.
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* `@roots/bud` client scripts
|
|
6
|
+
*
|
|
7
|
+
* You should not import this root module.
|
|
8
|
+
* Import the components from the submodules instead.
|
|
9
|
+
*
|
|
10
|
+
* @see https://bud.js.org
|
|
11
|
+
* @see https://github.com/roots/bud
|
|
12
|
+
*
|
|
13
|
+
* @packageDocumentation
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
export {}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
type Target = HTMLAnchorElement | HTMLLinkElement | HTMLFormElement
|
|
2
|
+
type ElementTuple = [HTMLCollectionOf<Target>, any]
|
|
3
|
+
|
|
4
|
+
const intercept = (...args: [string, string]) => {
|
|
5
|
+
args.every(arg => typeof arg === `string`) &&
|
|
6
|
+
setInterval(
|
|
7
|
+
() =>
|
|
8
|
+
[
|
|
9
|
+
[document.getElementsByTagName(`a`), `href`],
|
|
10
|
+
[document.getElementsByTagName(`link`), `href`],
|
|
11
|
+
]
|
|
12
|
+
.map(
|
|
13
|
+
([elements, attribute]: ElementTuple): [
|
|
14
|
+
Array<Target>,
|
|
15
|
+
any,
|
|
16
|
+
] => [Array.from(elements), attribute],
|
|
17
|
+
)
|
|
18
|
+
.forEach(([elements, attribute]: [Array<Target>, any]) =>
|
|
19
|
+
elements
|
|
20
|
+
.filter(el => el.hasAttribute(attribute))
|
|
21
|
+
.filter(el => !el.hasAttribute(`__bud_processed`))
|
|
22
|
+
.filter(el => el.getAttribute(attribute).startsWith(args[0]))
|
|
23
|
+
.map(el => {
|
|
24
|
+
const value = el.getAttribute(attribute).replace(...args)
|
|
25
|
+
el.setAttribute(attribute, value)
|
|
26
|
+
el.toggleAttribute(`__bud_processed`)
|
|
27
|
+
}),
|
|
28
|
+
),
|
|
29
|
+
1000,
|
|
30
|
+
)
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default intercept
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/* eslint-disable no-console */
|
|
2
|
+
/* global __resourceQuery */
|
|
3
|
+
|
|
4
|
+
import intercept from './index.js'
|
|
5
|
+
|
|
6
|
+
window.requestAnimationFrame(async function ready() {
|
|
7
|
+
if (!__resourceQuery) return
|
|
8
|
+
|
|
9
|
+
const params = new URLSearchParams(__resourceQuery)
|
|
10
|
+
if (!params || !params.has(`search`) || !params.has(`replace`)) return
|
|
11
|
+
|
|
12
|
+
const search = decodeURI(params.get(`search`))
|
|
13
|
+
const replace = decodeURI(params.get(`replace`))
|
|
14
|
+
|
|
15
|
+
return document.body
|
|
16
|
+
? intercept(search, replace)
|
|
17
|
+
: window.requestAnimationFrame(ready)
|
|
18
|
+
})
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
declare var __resourceQuery: string
|
|
2
|
+
declare var __webpack_hash__: string
|
|
3
|
+
|
|
4
|
+
interface Listener {
|
|
5
|
+
(event: Payload): void
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
declare interface Events {
|
|
9
|
+
options: Partial<Options> & {name: string; path: string}
|
|
10
|
+
listeners: Set<Listener>
|
|
11
|
+
addListener(fn: Listener): this
|
|
12
|
+
onopen: (ev?: Event) => void
|
|
13
|
+
onmessage: (ev?: MessageEvent) => void
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
declare interface Payload {
|
|
17
|
+
name: string
|
|
18
|
+
type: `middleware` | __WebpackModuleApi.HotNotifierInfo[`type`]
|
|
19
|
+
action: 'reload' | 'sync' | 'building' | 'built'
|
|
20
|
+
hash?: string
|
|
21
|
+
time?: number
|
|
22
|
+
errors?: Array<Record<string, any>>
|
|
23
|
+
warnings?: Array<string>
|
|
24
|
+
message?: string
|
|
25
|
+
modules?: Record<string, Array<string>>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
declare interface Controller {
|
|
29
|
+
update: (payload: Partial<Payload>) => void
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
declare interface Options {
|
|
33
|
+
timeout: number
|
|
34
|
+
reload: boolean
|
|
35
|
+
debug: boolean
|
|
36
|
+
log: boolean
|
|
37
|
+
name: string
|
|
38
|
+
path: string
|
|
39
|
+
indicator: boolean
|
|
40
|
+
overlay: boolean
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
declare var bud: {
|
|
44
|
+
current?: Record<string, string>
|
|
45
|
+
controllers?: Array<Controller>
|
|
46
|
+
hmr?: Record<string, Events & EventSource>
|
|
47
|
+
listeners?: Record<string, Listener>
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare module global {
|
|
51
|
+
interface Window {
|
|
52
|
+
bud: typeof bud
|
|
53
|
+
}
|
|
54
|
+
}
|