@roots/bud-client 6.5.2 → 6.6.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.
Files changed (75) hide show
  1. package/lib/hot/client.d.ts +9 -0
  2. package/lib/hot/client.d.ts.map +1 -0
  3. package/lib/hot/client.js +170 -0
  4. package/lib/hot/components/index.d.ts +2 -0
  5. package/lib/hot/components/index.d.ts.map +1 -0
  6. package/lib/hot/components/index.js +28 -0
  7. package/lib/hot/components/indicator/index.d.ts +4 -0
  8. package/lib/hot/components/indicator/index.d.ts.map +1 -0
  9. package/lib/{components → hot/components}/indicator/index.js +0 -0
  10. package/lib/{components → hot/components}/indicator/indicator.component.d.ts +0 -0
  11. package/lib/hot/components/indicator/indicator.component.d.ts.map +1 -0
  12. package/lib/{components → hot/components}/indicator/indicator.component.js +0 -0
  13. package/lib/{components → hot/components}/indicator/indicator.controller.d.ts +0 -0
  14. package/lib/hot/components/indicator/indicator.controller.d.ts.map +1 -0
  15. package/lib/{components → hot/components}/indicator/indicator.controller.js +0 -0
  16. package/lib/{components → hot/components}/indicator/indicator.pulse.d.ts +0 -0
  17. package/lib/hot/components/indicator/indicator.pulse.d.ts.map +1 -0
  18. package/lib/{components → hot/components}/indicator/indicator.pulse.js +0 -0
  19. package/lib/hot/components/overlay/index.d.ts +4 -0
  20. package/lib/hot/components/overlay/index.d.ts.map +1 -0
  21. package/lib/{components → hot/components}/overlay/index.js +0 -0
  22. package/lib/{components → hot/components}/overlay/overlay.component.d.ts +0 -0
  23. package/lib/hot/components/overlay/overlay.component.d.ts.map +1 -0
  24. package/lib/{components → hot/components}/overlay/overlay.component.js +0 -0
  25. package/lib/{components → hot/components}/overlay/overlay.controller.d.ts +0 -0
  26. package/lib/hot/components/overlay/overlay.controller.d.ts.map +1 -0
  27. package/lib/{components → hot/components}/overlay/overlay.controller.js +10 -6
  28. package/lib/hot/events.d.ts +98 -0
  29. package/lib/hot/events.d.ts.map +1 -0
  30. package/lib/hot/events.js +95 -0
  31. package/lib/hot/index.d.ts +2 -0
  32. package/lib/hot/index.d.ts.map +1 -0
  33. package/lib/hot/index.js +23 -0
  34. package/lib/hot/log.d.ts +11 -0
  35. package/lib/hot/log.d.ts.map +1 -0
  36. package/lib/hot/log.js +45 -0
  37. package/lib/{options.d.ts → hot/options.d.ts} +2 -1
  38. package/lib/hot/options.d.ts.map +1 -0
  39. package/lib/{options.js → hot/options.js} +10 -11
  40. package/lib/index.d.mts +12 -1
  41. package/lib/index.d.mts.map +1 -1
  42. package/lib/index.d.ts +12 -1
  43. package/lib/index.d.ts.map +1 -1
  44. package/lib/index.js +2 -115
  45. package/lib/index.mjs +2 -1
  46. package/lib/{intercept.d.ts → intercept/index.d.ts} +1 -1
  47. package/lib/intercept/index.d.ts.map +1 -0
  48. package/lib/{intercept.js → intercept/index.js} +0 -0
  49. package/lib/{proxy-click-interceptor.d.ts → intercept/proxy-click-interceptor.d.ts} +0 -0
  50. package/lib/intercept/proxy-click-interceptor.d.ts.map +1 -0
  51. package/lib/{proxy-click-interceptor.js → intercept/proxy-click-interceptor.js} +2 -2
  52. package/lib/{interface.d.ts → types/index.d.ts} +27 -28
  53. package/lib/types/index.d.ts.map +1 -0
  54. package/lib/types/index.js +0 -0
  55. package/package.json +5 -13
  56. package/lib/components/index.d.ts +0 -4
  57. package/lib/components/index.d.ts.map +0 -1
  58. package/lib/components/index.js +0 -49
  59. package/lib/components/indicator/index.d.ts +0 -4
  60. package/lib/components/indicator/index.d.ts.map +0 -1
  61. package/lib/components/indicator/indicator.component.d.ts.map +0 -1
  62. package/lib/components/indicator/indicator.controller.d.ts.map +0 -1
  63. package/lib/components/indicator/indicator.pulse.d.ts.map +0 -1
  64. package/lib/components/overlay/index.d.ts +0 -4
  65. package/lib/components/overlay/index.d.ts.map +0 -1
  66. package/lib/components/overlay/overlay.component.d.ts.map +0 -1
  67. package/lib/components/overlay/overlay.controller.d.ts.map +0 -1
  68. package/lib/hmr/events.d.ts +0 -52
  69. package/lib/hmr/events.d.ts.map +0 -1
  70. package/lib/hmr/events.js +0 -100
  71. package/lib/intercept.d.ts.map +0 -1
  72. package/lib/interface.d.ts.map +0 -1
  73. package/lib/interface.js +0 -4
  74. package/lib/options.d.ts.map +0 -1
  75. package/lib/proxy-click-interceptor.d.ts.map +0 -1
@@ -0,0 +1,9 @@
1
+ /// <reference types="webpack-env" />
2
+ /**
3
+ * Initializes bud.js HMR handling
4
+ *
5
+ * @public
6
+ */
7
+ declare const _default: (queryString: string, webpackHot: __WebpackModuleApi.Hot) => Promise<boolean>;
8
+ export default _default;
9
+ //# sourceMappingURL=client.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../../src/hot/client.ts"],"names":[],"mappings":";AASA;;;;GAIG;sCAEY,MAAM,cACP,mBAAmB,GAAG;AAFpC,wBA+IC"}
@@ -0,0 +1,170 @@
1
+ "use strict";
2
+ /* eslint-disable no-console */
3
+ /* global __resourceQuery */
4
+ /* global __webpack_hash__ */
5
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ var desc = Object.getOwnPropertyDescriptor(m, k);
8
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
9
+ desc = { enumerable: true, get: function() { return m[k]; } };
10
+ }
11
+ Object.defineProperty(o, k2, desc);
12
+ }) : (function(o, m, k, k2) {
13
+ if (k2 === undefined) k2 = k;
14
+ o[k2] = m[k];
15
+ }));
16
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
17
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
18
+ }) : function(o, v) {
19
+ o["default"] = v;
20
+ });
21
+ var __importStar = (this && this.__importStar) || function (mod) {
22
+ if (mod && mod.__esModule) return mod;
23
+ var result = {};
24
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
25
+ __setModuleDefault(result, mod);
26
+ return result;
27
+ };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const components = __importStar(require("./components/index.js"));
39
+ const events_js_1 = require("./events.js");
40
+ const log_js_1 = require("./log.js");
41
+ const clientOptions = __importStar(require("./options.js"));
42
+ /**
43
+ * Initializes bud.js HMR handling
44
+ *
45
+ * @public
46
+ */
47
+ exports.default = (queryString, webpackHot) => __awaiter(void 0, void 0, void 0, function* () {
48
+ /* Guard: EventSource browser support */
49
+ if (typeof (window === null || window === void 0 ? void 0 : window.EventSource) === `undefined`) {
50
+ console.error(`[bud] hot module reload requires EventSource to work. https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events#Tools`);
51
+ return false;
52
+ }
53
+ /* Guard: webpackHot api availability */
54
+ if (!webpackHot) {
55
+ console.error(`[bud] hot module reload requires the webpack hot api to be available`);
56
+ return false;
57
+ }
58
+ /* Set client options from URL params */
59
+ const options = clientOptions.setFromParameters(queryString);
60
+ /* Setup logger */
61
+ const logger = (0, log_js_1.makeLogger)(options);
62
+ if (typeof window.bud === `undefined`) {
63
+ window.bud = {
64
+ current: {},
65
+ hmr: {},
66
+ controllers: [],
67
+ listeners: {},
68
+ };
69
+ }
70
+ if (!window.bud.current[options.name]) {
71
+ window.bud.current[options.name] = null;
72
+ }
73
+ const isStale = (hash) => {
74
+ if (hash)
75
+ window.bud.current[options.name] = hash;
76
+ return __webpack_hash__ === window.bud.current[options.name];
77
+ };
78
+ /**
79
+ * Webpack HMR check handler
80
+ *
81
+ * @internal
82
+ */
83
+ const check = () => __awaiter(void 0, void 0, void 0, function* () {
84
+ if (webpackHot.status() === `idle`) {
85
+ yield webpackHot.check(false);
86
+ requestAnimationFrame(function whenReady() {
87
+ return __awaiter(this, void 0, void 0, function* () {
88
+ if (webpackHot.status() === `ready`) {
89
+ yield update();
90
+ }
91
+ else {
92
+ requestAnimationFrame(whenReady);
93
+ }
94
+ });
95
+ });
96
+ }
97
+ });
98
+ /**
99
+ * Webpack HMR unaccepted module handler
100
+ *
101
+ * @internal
102
+ */
103
+ const onUnacceptedOrDeclined = (info) => {
104
+ console.warn(`[${options.name}] ${info.type}`, info);
105
+ options.reload && window.location.reload();
106
+ };
107
+ /**
108
+ * Webpack HMR error handler
109
+ *
110
+ * @internal
111
+ */
112
+ const onErrored = (error) => {
113
+ window.bud.controllers.map(controller => controller === null || controller === void 0 ? void 0 : controller.update({
114
+ errors: [error],
115
+ }));
116
+ };
117
+ /**
118
+ * Webpack HMR update handler
119
+ *
120
+ * @internal
121
+ */
122
+ const update = () => __awaiter(void 0, void 0, void 0, function* () {
123
+ try {
124
+ yield webpackHot.apply({
125
+ ignoreUnaccepted: true,
126
+ ignoreDeclined: true,
127
+ ignoreErrored: true,
128
+ onErrored,
129
+ onUnaccepted: onUnacceptedOrDeclined,
130
+ onDeclined: onUnacceptedOrDeclined,
131
+ });
132
+ if (!isStale())
133
+ yield check();
134
+ }
135
+ catch (error) {
136
+ logger.error(error);
137
+ }
138
+ });
139
+ /* Instantiate indicator, overlay */
140
+ yield components.make(options);
141
+ /* Instantiate eventSource */
142
+ const events = (0, events_js_1.injectEvents)(EventSource).make(options);
143
+ if (!window.bud.listeners[options.name]) {
144
+ window.bud.listeners[options.name] = (payload) => __awaiter(void 0, void 0, void 0, function* () {
145
+ var _a;
146
+ if (!payload)
147
+ return;
148
+ if (options.reload && payload.action === `reload`)
149
+ return window.location.reload();
150
+ if (payload.name !== options.name)
151
+ return;
152
+ window.bud.controllers.map(controller => controller === null || controller === void 0 ? void 0 : controller.update(payload));
153
+ if (((_a = payload.errors) === null || _a === void 0 ? void 0 : _a.length) > 0)
154
+ return;
155
+ if (payload.action === `built` || payload.action === `sync`) {
156
+ if (isStale(payload.hash))
157
+ return;
158
+ if (payload.action === `built`) {
159
+ logger.log(`built in ${payload.time}ms`);
160
+ }
161
+ yield check();
162
+ }
163
+ });
164
+ /*
165
+ * Instantiate HMR event source
166
+ * and register client listeners
167
+ */
168
+ events.addListener(window.bud.listeners[options.name]);
169
+ }
170
+ });
@@ -0,0 +1,2 @@
1
+ export declare const make: (options: Options) => Promise<Array<Controller>>;
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hot/components/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,IAAI,EAAE,CACjB,OAAO,EAAE,OAAO,KACb,OAAO,CAAC,KAAK,CAAC,UAAU,CAAC,CAgB7B,CAAA"}
@@ -0,0 +1,28 @@
1
+ "use strict";
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ exports.make = void 0;
13
+ const make = (options) => __awaiter(void 0, void 0, void 0, function* () {
14
+ if (window.bud.controllers.length > 0)
15
+ return window.bud.controllers;
16
+ if (options.indicator && !customElements.get(`bud-activity-indicator`)) {
17
+ yield import(`./indicator/index.js`)
18
+ .then((controller) => __awaiter(void 0, void 0, void 0, function* () { return yield controller.make(); }))
19
+ .then(controller => window.bud.controllers.push(controller));
20
+ }
21
+ if (options.overlay && !customElements.get(`bud-error`)) {
22
+ yield import(`./overlay/index.js`)
23
+ .then((controller) => __awaiter(void 0, void 0, void 0, function* () { return yield controller.make(); }))
24
+ .then(controller => window.bud.controllers.push(controller));
25
+ }
26
+ return window.bud.controllers;
27
+ });
28
+ exports.make = make;
@@ -0,0 +1,4 @@
1
+ export declare const make: () => Promise<{
2
+ update: (data: Payload) => void;
3
+ }>;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hot/components/indicator/index.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,IAAI;mBACA,OAAO,KAAK,IAAI;EAOhC,CAAA"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indicator.component.d.ts","sourceRoot":"","sources":["../../../../src/hot/components/indicator/indicator.component.ts"],"names":[],"mappings":";AAEA;;;GAGG;AACH,qBAAa,SAAU,SAAQ,WAAW;IACxC;;;OAGG;IACI,QAAQ,EAAE,OAAO,CAAA;IAExB;;;OAGG;IACI,IAAI,EAAE,MAAM,CAA2B;IAE9C;;;OAGG;IACH,IAAW,QAAQ,WAElB;IAED;;;OAGG;IACI,WAAW,EAAE,MAAM,CAAC,KAAK,CAAA;IAEhC;;;OAGG;IACH,IAAW,SAAS,IAAI,OAAO,CAE9B;IAED;;;OAGG;IACH,IAAW,WAAW,IAAI,OAAO,CAEhC;IAED;;;OAGG;IACI,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC,CAK9D;IAED;;;OAGG;;IAMH;;;OAGG;IACI,YAAY;IA4CnB;;;OAGG;IACI,IAAI;IAKX;;OAEG;IACI,IAAI;IAMX;;;OAGG;IACI,SAAS;IAYhB;;;OAGG;IACI,SAAS;IAYhB;;;OAGG;IACI,OAAO;IASd;;;OAGG;IACI,SAAS;IAUhB,WAAkB,kBAAkB,aAEnC;IAEM,wBAAwB;CAiBhC"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"indicator.controller.d.ts","sourceRoot":"","sources":["../../../../src/hot/components/indicator/indicator.controller.ts"],"names":[],"mappings":";AAAA;;;GAGG;AACH,qBAAa,UAAU;IACrB;;;OAGG;IACI,IAAI,EAAE,WAAW,CAAA;IAExB;;;OAGG;IACI,OAAO,MAAO;IAErB;;;OAGG;IACI,KAAK,EAAE,MAAM,CAAC,OAAO,CAAA;IAE5B;;;OAGG;;IAMH;;;;OAIG;IACI,OAAO;IAUd;;;;OAIG;IACI,UAAU;IAIjB;;;OAGG;IACI,MAAM,CAAC,OAAO,EAAE,OAAO;CAe/B"}
@@ -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,4 @@
1
+ export declare const make: () => Promise<{
2
+ update: (data: Payload) => void;
3
+ }>;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -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 @@
1
+ {"version":3,"file":"overlay.component.d.ts","sourceRoot":"","sources":["../../../../src/hot/components/overlay/overlay.component.ts"],"names":[],"mappings":"AAAA;;;;GAIG;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 @@
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"}
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Controller = void 0;
7
- const strip_ansi_1 = __importDefault(require("strip-ansi"));
4
+ const ansiPattern = [
5
+ `[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)`,
6
+ `(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))`,
7
+ ].join(`|`);
8
+ 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; };
8
9
  /**
9
10
  * Overlay controller
10
11
  * @public
@@ -26,10 +27,13 @@ class Controller {
26
27
  get message() {
27
28
  var _a;
28
29
  return (_a = this.payload.errors) === null || _a === void 0 ? void 0 : _a.reduce((a, c) => {
29
- var _a;
30
+ var _a, _b;
31
+ 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;
32
+ if (!msg)
33
+ return a;
30
34
  return `${a}
31
35
  <div>
32
- <pre>${(_a = (0, strip_ansi_1.default)(c === null || c === void 0 ? void 0 : c.message)) !== null && _a !== void 0 ? _a : ``}</pre>
36
+ <pre>${stripAnsi(msg)}</pre>
33
37
  </div>`;
34
38
  }, ``);
35
39
  }
@@ -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;QAmBjE;;;WAGG;8BAC0B,QAAQ,GAAG,IAAI;;;;;;;;;;;;;;;;;IAjD5C;;;;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;QAmBjE;;;WAGG;8BAC0B,QAAQ,GAAG,IAAI;;;;;;;;;;;;;;;;;CAK/C,CAAA"}
@@ -0,0 +1,95 @@
1
+ "use strict";
2
+ /* eslint-disable no-console */
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
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.injectEvents = void 0;
14
+ const injectEvents = (eventSource) => {
15
+ /**
16
+ * EventSource wrapper
17
+ *
18
+ * @remarks
19
+ * wraps EventSource in a function to allow for
20
+ * mocking in tests
21
+ *
22
+ * @public
23
+ */
24
+ return class Events extends eventSource {
25
+ /**
26
+ * Class constructor
27
+ *
28
+ * @remarks
29
+ * Singleton interface, so this is private.
30
+ *
31
+ * @public
32
+ */
33
+ constructor(options) {
34
+ super(options.path);
35
+ this.options = options;
36
+ /**
37
+ * Registered listeners
38
+ *
39
+ * @public
40
+ */
41
+ this.listeners = new Set();
42
+ /**
43
+ * EventSource `onopen` handler
44
+ * @public
45
+ */
46
+ this.onopen = function () { };
47
+ /**
48
+ * EventSource `onmessage` handler
49
+ * @public
50
+ */
51
+ this.onmessage = function (payload) {
52
+ return __awaiter(this, void 0, void 0, function* () {
53
+ if (!(payload === null || payload === void 0 ? void 0 : payload.data) || payload.data == `\uD83D\uDC93`) {
54
+ return;
55
+ }
56
+ try {
57
+ const data = JSON.parse(payload.data);
58
+ if (!data)
59
+ return;
60
+ yield Promise.all([...this.listeners].map((listener) => __awaiter(this, void 0, void 0, function* () {
61
+ return yield listener(data);
62
+ })));
63
+ }
64
+ catch (ex) {
65
+ console.warn(`Invalid HMR message: ${payload.data} \n ${ex}`);
66
+ }
67
+ });
68
+ };
69
+ this.onopen = this.onopen.bind(this);
70
+ this.onmessage = this.onmessage.bind(this);
71
+ this.addListener = this.addListener.bind(this);
72
+ }
73
+ /**
74
+ * Singleton constructor
75
+ *
76
+ * @public
77
+ */
78
+ static make(options) {
79
+ if (typeof window.bud.hmr[options.name] === `undefined`)
80
+ Object.assign(window.bud.hmr, {
81
+ [options.name]: new Events(options),
82
+ });
83
+ return window.bud.hmr[options.name];
84
+ }
85
+ /**
86
+ * EventSource `addMessageListener` handler
87
+ * @public
88
+ */
89
+ addListener(listener) {
90
+ this.listeners.add(listener);
91
+ return this;
92
+ }
93
+ };
94
+ };
95
+ exports.injectEvents = injectEvents;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hot/index.ts"],"names":[],"mappings":""}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ /* eslint-disable no-console */
3
+ /* global __resourceQuery */
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const client_js_1 = __importDefault(require("./client.js"));
18
+ // @ts-ignore
19
+ const webpackHot = import.meta
20
+ ? // @ts-ignore
21
+ import.meta.webpackHot
22
+ : module.hot;
23
+ (() => __awaiter(void 0, void 0, void 0, function* () { return yield (0, client_js_1.default)(__resourceQuery, webpackHot); }))();
@@ -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,45 @@
1
+ "use strict";
2
+ /* eslint-disable no-console */
3
+ Object.defineProperty(exports, "__esModule", { value: true });
4
+ exports.makeWarn = exports.makeError = exports.makeInfo = exports.makeLog = exports.makeLogger = void 0;
5
+ const makeLogger = (options) => {
6
+ return {
7
+ log: (0, exports.makeLog)(options),
8
+ error: (0, exports.makeError)(options),
9
+ warn: (0, exports.makeWarn)(options),
10
+ info: (0, exports.makeInfo)(options),
11
+ };
12
+ };
13
+ exports.makeLogger = makeLogger;
14
+ let lastLog = null;
15
+ const makeLog = options => {
16
+ return (...args) => {
17
+ if (options.log) {
18
+ if (lastLog === args.join(``))
19
+ return;
20
+ lastLog = args.join(``);
21
+ console.log(`[${options.name}]`, ...args);
22
+ }
23
+ };
24
+ };
25
+ exports.makeLog = makeLog;
26
+ const makeInfo = options => {
27
+ return (...args) => {
28
+ if (options.log) {
29
+ console.info(`[${options.name}]`, ...args);
30
+ }
31
+ };
32
+ };
33
+ exports.makeInfo = makeInfo;
34
+ const makeError = options => {
35
+ return (...args) => {
36
+ console.error(`[${options.name}]`, ...args);
37
+ };
38
+ };
39
+ exports.makeError = makeError;
40
+ const makeWarn = options => {
41
+ return (...args) => {
42
+ console.warn(`[${options.name}]`, ...args);
43
+ };
44
+ };
45
+ exports.makeWarn = makeWarn;
@@ -2,7 +2,7 @@
2
2
  * Client options
3
3
  * @public
4
4
  */
5
- declare let data: Record<string, Options>;
5
+ declare let data: Options;
6
6
  /**
7
7
  * Get client option
8
8
  * @public
@@ -10,6 +10,7 @@ declare let data: Record<string, Options>;
10
10
  declare const get: (name?: string, key?: string) => any;
11
11
  /**
12
12
  * Set client data based on URL parameters
13
+ * @public
13
14
  */
14
15
  declare const setFromParameters: (query: string) => Options;
15
16
  export { data, get, setFromParameters };
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/hot/options.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,QAAA,IAAI,IAAI,EAAE,OAST,CAAA;AAED;;;GAGG;AACH,QAAA,MAAM,GAAG,UAAW,MAAM,QAAQ,MAAM,QACJ,CAAA;AAEpC;;;GAGG;AACH,QAAA,MAAM,iBAAiB,UAAW,MAAM,KAAG,OAW1C,CAAA;AAED,OAAO,EAAC,IAAI,EAAE,GAAG,EAAE,iBAAiB,EAAC,CAAA"}