@servicetitan/web-components 19.2.0 → 20.0.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/dist/common.js +17 -26
- package/dist/common.js.map +1 -1
- package/dist/event-bus.js +6 -14
- package/dist/event-bus.js.map +1 -1
- package/dist/globals.js +2 -5
- package/dist/globals.js.map +1 -1
- package/dist/history-manager.js +3 -6
- package/dist/history-manager.js.map +1 -1
- package/dist/index.js +5 -17
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +89 -65
- package/dist/loader.js.map +1 -1
- package/dist/register.d.ts.map +1 -1
- package/dist/register.js +51 -49
- package/dist/register.js.map +1 -1
- package/package.json +12 -11
- package/src/loader.tsx +67 -28
- package/src/register.tsx +38 -22
package/dist/common.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -19,19 +18,14 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
18
|
}
|
|
20
19
|
return t;
|
|
21
20
|
};
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
const
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
exports.BASENAME_TOKEN = (0, react_ioc_1.symbolToken)('BASENAME_TOKEN');
|
|
31
|
-
exports.EXPOSED_DEPENDENCIES_TOKEN = (0, react_ioc_1.symbolToken)('EXPOSED_DEPENDENCIES_TOKEN');
|
|
32
|
-
exports.IS_WEB_COMPONENT_TOKEN = (0, react_ioc_1.symbolToken)('IS_WEB_COMPONENT_TOKEN');
|
|
33
|
-
exports.RENDER_ROOT_TOKEN = (0, react_ioc_1.symbolToken)('RENDER_ROOT_TOKEN');
|
|
34
|
-
function isCompatible(hostVersion, packageVersion) {
|
|
21
|
+
import semver from 'semver';
|
|
22
|
+
import { useRef } from 'react';
|
|
23
|
+
import { symbolToken } from '@servicetitan/react-ioc';
|
|
24
|
+
export const BASENAME_TOKEN = symbolToken('BASENAME_TOKEN');
|
|
25
|
+
export const EXPOSED_DEPENDENCIES_TOKEN = symbolToken('EXPOSED_DEPENDENCIES_TOKEN');
|
|
26
|
+
export const IS_WEB_COMPONENT_TOKEN = symbolToken('IS_WEB_COMPONENT_TOKEN');
|
|
27
|
+
export const RENDER_ROOT_TOKEN = symbolToken('RENDER_ROOT_TOKEN');
|
|
28
|
+
export function isCompatible(hostVersion, packageVersion) {
|
|
35
29
|
if (hostVersion === packageVersion) {
|
|
36
30
|
return true;
|
|
37
31
|
}
|
|
@@ -42,25 +36,24 @@ function isCompatible(hostVersion, packageVersion) {
|
|
|
42
36
|
return true;
|
|
43
37
|
}
|
|
44
38
|
// host and package have exact non-equal versions
|
|
45
|
-
if (
|
|
39
|
+
if (semver.valid(hostVersion) && semver.valid(packageVersion)) {
|
|
46
40
|
return false;
|
|
47
41
|
}
|
|
48
42
|
// exact package version couldn't be compatible with host range
|
|
49
|
-
if (
|
|
43
|
+
if (semver.validRange(hostVersion) && semver.valid(packageVersion)) {
|
|
50
44
|
return false;
|
|
51
45
|
}
|
|
52
46
|
// exact host version must be in package range
|
|
53
|
-
if (
|
|
54
|
-
return
|
|
47
|
+
if (semver.valid(hostVersion) && semver.validRange(packageVersion)) {
|
|
48
|
+
return semver.satisfies(hostVersion, packageVersion);
|
|
55
49
|
}
|
|
56
50
|
// host range must be fully included in package range
|
|
57
|
-
if (
|
|
58
|
-
return
|
|
51
|
+
if (semver.validRange(hostVersion) && semver.validRange(packageVersion)) {
|
|
52
|
+
return semver.subset(hostVersion, packageVersion);
|
|
59
53
|
}
|
|
60
54
|
return false;
|
|
61
55
|
}
|
|
62
|
-
|
|
63
|
-
function getJson(url, _a = {}) {
|
|
56
|
+
export function getJson(url, _a = {}) {
|
|
64
57
|
var { retries = 5, retryDelay = 1000 } = _a, config = __rest(_a, ["retries", "retryDelay"]);
|
|
65
58
|
return __awaiter(this, void 0, void 0, function* () {
|
|
66
59
|
let response;
|
|
@@ -90,9 +83,7 @@ function getJson(url, _a = {}) {
|
|
|
90
83
|
return { data: yield response.json(), headers: response.headers };
|
|
91
84
|
});
|
|
92
85
|
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
return (0, react_1.useRef)(new AbortController()).current;
|
|
86
|
+
export function useCancelation() {
|
|
87
|
+
return useRef(new AbortController()).current;
|
|
96
88
|
}
|
|
97
|
-
exports.useCancelation = useCancelation;
|
|
98
89
|
//# sourceMappingURL=common.js.map
|
package/dist/common.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"common.js","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AActD,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAS,gBAAgB,CAAC,CAAC;AACpE,MAAM,CAAC,MAAM,0BAA0B,GAAG,WAAW,CACjD,4BAA4B,CAC/B,CAAC;AACF,MAAM,CAAC,MAAM,sBAAsB,GAAG,WAAW,CAAU,wBAAwB,CAAC,CAAC;AACrF,MAAM,CAAC,MAAM,iBAAiB,GAAG,WAAW,CAAa,mBAAmB,CAAC,CAAC;AAgB9E,MAAM,UAAU,YAAY,CAAC,WAAmB,EAAE,cAAsB;IACpE,IAAI,WAAW,KAAK,cAAc,EAAE;QAChC,OAAO,IAAI,CAAC;KACf;IAED,IAAI,WAAW,KAAK,GAA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GAAG,MAAM,CAAC,UAAU,CAAC,GAAG,EAAE;wBACrC,OAAO,CAAC,GAAG,kCACJ,MAAM,KACT,OAAO,EAAE,OAAO,GAAG,CAAC,EACpB,UAAU,EAAE,UAAU,GAAG,CAAC,IAC5B,CAAC,IAAI,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;oBAC7B,CAAC,EAAE,UAAU,CAAC,CAAC;oBAEf,MAAM,aAAN,MAAM,uBAAN,MAAM,CAAE,gBAAgB,CAAC,OAAO,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,SAAS,CAAC,CAAC,CAAC;gBAC5E,CAAC,CAAC,CAAC;aACN;YAED,MAAM,IAAI,KAAK,CAAC,qBAAqB,GAAG,IAAI,CAAC,CAAC;SACjD;QAED,IAAI,CAAC,QAAQ,CAAC,EAAE,EAAE;YACd,IAAI,OAAO,GAAG,eAAe,GAAG,6BAA6B,QAAQ,CAAC,MAAM,GAAG,CAAC;YAEhF,IAAI;gBACA,OAAO,IAAI,aAAa,MAAM,QAAQ,CAAC,IAAI,EAAE,GAAG,CAAC;aACpD;YAAC,WAAM,GAAE,CAAC,+BAA+B;YAE1C,MAAM,IAAI,KAAK,CAAC,OAAO,CAAC,CAAC;SAC5B;QAED,OAAO,EAAE,IAAI,EAAE,MAAM,QAAQ,CAAC,IAAI,EAAE,EAAE,OAAO,EAAE,QAAQ,CAAC,OAAO,EAAE,CAAC;;CACrE;AAED,MAAM,UAAU,cAAc;IAC1B,OAAO,MAAM,CAAC,IAAI,eAAe,EAAE,CAAC,CAAC,OAAO,CAAC;AACjD,CAAC"}
|
package/dist/event-bus.js
CHANGED
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.useEventBus = exports.EventBus = void 0;
|
|
7
|
-
const mitt_1 = __importDefault(require("mitt"));
|
|
8
|
-
const react_1 = require("react");
|
|
9
|
-
class EventBus {
|
|
1
|
+
import mitt from 'mitt';
|
|
2
|
+
import { useRef } from 'react';
|
|
3
|
+
export class EventBus {
|
|
10
4
|
constructor() {
|
|
11
5
|
Object.defineProperty(this, "job", {
|
|
12
6
|
enumerable: true,
|
|
@@ -40,7 +34,7 @@ class EventBus {
|
|
|
40
34
|
enumerable: true,
|
|
41
35
|
configurable: true,
|
|
42
36
|
writable: true,
|
|
43
|
-
value: (
|
|
37
|
+
value: mitt()
|
|
44
38
|
});
|
|
45
39
|
Object.defineProperty(this, "on", {
|
|
46
40
|
enumerable: true,
|
|
@@ -68,9 +62,7 @@ class EventBus {
|
|
|
68
62
|
});
|
|
69
63
|
}
|
|
70
64
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
return (0, react_1.useRef)(new EventBus()).current;
|
|
65
|
+
export function useEventBus() {
|
|
66
|
+
return useRef(new EventBus()).current;
|
|
74
67
|
}
|
|
75
|
-
exports.useEventBus = useEventBus;
|
|
76
68
|
//# sourceMappingURL=event-bus.js.map
|
package/dist/event-bus.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"event-bus.js","sourceRoot":"","sources":["../src/event-bus.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,MAAM,CAAC;AAExB,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAQ/B,MAAM,OAAO,QAAQ;IAArB;QACI;;;;mBAAM;gBACF,EAAE,EAAE,CAAC,IAAY,EAAE,OAAwB,EAAE,EAAE;oBAC3C,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;gBACnC,CAAC;gBACD,GAAG,EAAE,CAAC,IAAY,EAAE,OAAwB,EAAE,EAAE;oBAC5C,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,IAAI,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ENT_NAME = exports.EXPOSED_DEPENDENCIES = void 0;
|
|
4
1
|
function get(fetch) {
|
|
5
2
|
try {
|
|
6
3
|
return fetch();
|
|
@@ -12,9 +9,9 @@ function get(fetch) {
|
|
|
12
9
|
const _EXPOSED_DEPENDENCIES = get(() => {
|
|
13
10
|
return EXPOSED_DEPENDENCIES;
|
|
14
11
|
});
|
|
15
|
-
|
|
12
|
+
export { _EXPOSED_DEPENDENCIES as EXPOSED_DEPENDENCIES };
|
|
16
13
|
const _WEB_COMPONENT_NAME = get(() => {
|
|
17
14
|
return WEB_COMPONENT_NAME;
|
|
18
15
|
});
|
|
19
|
-
|
|
16
|
+
export { _WEB_COMPONENT_NAME as WEB_COMPONENT_NAME };
|
|
20
17
|
//# sourceMappingURL=globals.js.map
|
package/dist/globals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globals.js","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"globals.js","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AAQA,SAAS,GAAG,CAAI,KAAc;IAC1B,IAAI;QACA,OAAO,KAAK,EAAE,CAAC;KAClB;IAAC,WAAM;QACJ,OAAO,SAAS,CAAC;KACpB;AACL,CAAC;AAED,MAAM,qBAAqB,GAAG,GAAG,CAAC,GAAG,EAAE;IACnC,OAAO,oBAAoB,CAAC;AAChC,CAAC,CAAC,CAAC;AACH,OAAO,EAAE,qBAAqB,IAAI,oBAAoB,EAAE,CAAC;AAEzD,MAAM,mBAAmB,GAAG,GAAG,CAAC,GAAG,EAAE;IACjC,OAAO,kBAAkB,CAAC;AAC9B,CAAC,CAAC,CAAC;AACH,OAAO,EAAE,mBAAmB,IAAI,kBAAkB,EAAE,CAAC"}
|
package/dist/history-manager.js
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
2
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
3
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
4
|
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
5
|
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
6
|
};
|
|
8
|
-
|
|
9
|
-
exports.HistoryManager = void 0;
|
|
10
|
-
const react_ioc_1 = require("@servicetitan/react-ioc");
|
|
7
|
+
import { injectable } from '@servicetitan/react-ioc';
|
|
11
8
|
let HistoryManager = class HistoryManager {
|
|
12
9
|
constructor() {
|
|
13
10
|
// Initiator of action, used for filtering redirections
|
|
@@ -82,7 +79,7 @@ let HistoryManager = class HistoryManager {
|
|
|
82
79
|
}
|
|
83
80
|
};
|
|
84
81
|
HistoryManager = __decorate([
|
|
85
|
-
|
|
82
|
+
injectable()
|
|
86
83
|
], HistoryManager);
|
|
87
|
-
|
|
84
|
+
export { HistoryManager };
|
|
88
85
|
//# sourceMappingURL=history-manager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"history-manager.js","sourceRoot":"","sources":["../src/history-manager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"history-manager.js","sourceRoot":"","sources":["../src/history-manager.ts"],"names":[],"mappings":";;;;;;AAEA,OAAO,EAAE,UAAU,EAAE,MAAM,yBAAyB,CAAC;AAGrD,IAAa,cAAc,GAA3B,MAAa,cAAc;IAA3B;QACI,uDAAuD;QACvD;;;;;WAAoD;QAEpD;;;;mBAAU,IAAI,GAAG,EAA+B;WAAC;QAEjD;;;;mBAAW,CAAC,OAAgB,EAAE,EAAE;gBAC5B,IAAI,CAAC,OAAO,CAAC,GAAG,CACZ,OAAO,EACP,OAAO,CAAC,MAAM,CAAC,QAAQ,CA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AA,MAAA,IAAI,CAAC,QAAQ,0CAAE,QAAQ,MAAK,QAAQ,EACtC;4BACE,IAAI,CAAC,QAAQ,GAAG,SAAS,CAAC;yBAC7B;oBACL,CAAC,CAAC,CAAC;gBACP,CAAC,CAAC,CACL,CAAC;YACN,CAAC;WAAC;QAEF;;;;mBAAa,CAAC,SAAkB,EAAE,EAAE;gBAChC,IAAI,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAC,EAAE;oBAC7B,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,SAAS,CAAE,EAAE,CAAC;oBAC/B,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;iBAClC;YACL,CAAC;WAAC;IACN,CAAC;CAAA,CAAA;AArEY,cAAc;IAD1B,UAAU,EAAE;GACA,cAAc,CAqE1B;SArEY,cAAc"}
|
package/dist/index.js
CHANGED
|
@@ -1,18 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (k2 === undefined) k2 = k;
|
|
7
|
-
o[k2] = m[k];
|
|
8
|
-
}));
|
|
9
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
10
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
11
|
-
};
|
|
12
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
-
__exportStar(require("./common"), exports);
|
|
14
|
-
__exportStar(require("./event-bus"), exports);
|
|
15
|
-
__exportStar(require("./history-manager"), exports);
|
|
16
|
-
__exportStar(require("./register"), exports);
|
|
17
|
-
__exportStar(require("./loader"), exports);
|
|
1
|
+
export * from './common';
|
|
2
|
+
export * from './event-bus';
|
|
3
|
+
export * from './history-manager';
|
|
4
|
+
export * from './register';
|
|
5
|
+
export * from './loader';
|
|
18
6
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,CAAC;AAC5B,cAAc,mBAAmB,CAAC;AAClC,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC"}
|
package/dist/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.tsx"],"names":[],"mappings":"AAAA,OAAO,EASH,SAAS,EACZ,MAAM,OAAO,CAAC;AAkBf,OAAO,EAAE,QAAQ,EAAe,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.tsx"],"names":[],"mappings":"AAAA,OAAO,EASH,SAAS,EACZ,MAAM,OAAO,CAAC;AAkBf,OAAO,EAAE,QAAQ,EAAe,MAAM,aAAa,CAAC;AAmGpD,oBAAY,SAAS,GAAG,QAAQ,CAAC;AAEjC,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;IAChD,aAAa,CAAC,EAAE,WAAW,CAAC,SAAS,CAAC,GAAG,IAAI,CAAC;IAC9C,SAAS,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,MAAM,kGAiLlB,CAAC"}
|
package/dist/loader.js
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
2
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
3
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -8,22 +7,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
8
|
});
|
|
10
9
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const react_ioc_1 = require("@servicetitan/react-ioc");
|
|
23
|
-
const common_1 = require("./common");
|
|
24
|
-
const event_bus_1 = require("./event-bus");
|
|
25
|
-
const history_manager_1 = require("./history-manager");
|
|
26
|
-
const globals_1 = require("./globals");
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { lazy, Suspense, useEffect, useMemo, useState, forwardRef, useImperativeHandle, } from 'react';
|
|
12
|
+
import semver from 'semver';
|
|
13
|
+
import get from 'lodash.get';
|
|
14
|
+
import { ErrorBoundary } from '@servicetitan/error-boundary';
|
|
15
|
+
import { Log } from '@servicetitan/log-service';
|
|
16
|
+
import { useOptionalDependencies } from '@servicetitan/react-ioc';
|
|
17
|
+
import { EXPOSED_DEPENDENCIES_TOKEN, useCancelation, getJson, isCompatible, } from './common';
|
|
18
|
+
import { useEventBus } from './event-bus';
|
|
19
|
+
import { HistoryManager } from './history-manager';
|
|
20
|
+
import { EXPOSED_DEPENDENCIES } from './globals';
|
|
27
21
|
function omitPackageVersion(packageUrl) {
|
|
28
22
|
const chunks = packageUrl.split('@');
|
|
29
23
|
if (chunks.length > 2) {
|
|
@@ -31,17 +25,33 @@ function omitPackageVersion(packageUrl) {
|
|
|
31
25
|
}
|
|
32
26
|
return packageUrl;
|
|
33
27
|
}
|
|
28
|
+
function getEntrypoints(url, signal) {
|
|
29
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
30
|
+
try {
|
|
31
|
+
return (yield getJson(url, {
|
|
32
|
+
cache: 'no-store',
|
|
33
|
+
signal,
|
|
34
|
+
})).data;
|
|
35
|
+
}
|
|
36
|
+
catch (_a) {
|
|
37
|
+
return { css: ['index.css'], js: ['index.js'] };
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
}
|
|
34
41
|
function getBundleInfo(packageUrl, exposedDependencies = {}, signal) {
|
|
35
42
|
var _a;
|
|
36
43
|
return __awaiter(this, void 0, void 0, function* () {
|
|
37
|
-
const { data: { dependencies, version }, headers, } = yield
|
|
44
|
+
const { data: { dependencies, version }, headers, } = yield getJson(`${packageUrl}/package.json`, { cache: 'no-store', signal });
|
|
38
45
|
const exactPackageUrl = headers.get('X-Delivered-By') === 'unpkg'
|
|
39
46
|
? `${omitPackageVersion(packageUrl)}@${version}`
|
|
40
47
|
: packageUrl;
|
|
41
|
-
const { data: metadata } = yield
|
|
48
|
+
const { data: metadata } = yield getJson(`${exactPackageUrl}/dist/metadata.json`, {
|
|
49
|
+
cache: 'no-store',
|
|
50
|
+
signal,
|
|
51
|
+
});
|
|
42
52
|
const mismatch = Object.entries(exposedDependencies).reduce((result, [dependency, { version: hostVersion }]) => {
|
|
43
53
|
const packageVersion = dependencies[dependency];
|
|
44
|
-
if (packageVersion && !
|
|
54
|
+
if (packageVersion && !isCompatible(hostVersion, packageVersion)) {
|
|
45
55
|
result[dependency] = { host: hostVersion, package: packageVersion };
|
|
46
56
|
}
|
|
47
57
|
return result;
|
|
@@ -57,16 +67,23 @@ function getBundleInfo(packageUrl, exposedDependencies = {}, signal) {
|
|
|
57
67
|
}
|
|
58
68
|
const hasMismatch = !!Object.keys(mismatch).length;
|
|
59
69
|
const startupVersion = (_a = metadata.bundledWith) === null || _a === void 0 ? void 0 : _a['@servicetitan/startup'];
|
|
60
|
-
const supportLightBundles = startupVersion &&
|
|
70
|
+
const supportLightBundles = startupVersion && semver.gte(startupVersion, '17.0.0');
|
|
61
71
|
const embed = !hasMismatch && supportLightBundles;
|
|
72
|
+
const withBaseUrl = (path) => {
|
|
73
|
+
return `${exactPackageUrl}/dist/bundle/${embed ? 'light' : 'full'}/${path}`;
|
|
74
|
+
};
|
|
75
|
+
const entrypoints = yield getEntrypoints(withBaseUrl('entrypoints.json'));
|
|
62
76
|
return {
|
|
63
|
-
|
|
77
|
+
urls: {
|
|
78
|
+
css: entrypoints.css.map(withBaseUrl),
|
|
79
|
+
js: entrypoints.js.map(withBaseUrl),
|
|
80
|
+
},
|
|
64
81
|
WebComponent: metadata.name,
|
|
65
82
|
disposer: () => {
|
|
66
83
|
if (embed) {
|
|
67
84
|
const path = Object.values(metadata.sharedDependencies).shift();
|
|
68
85
|
if (path) {
|
|
69
|
-
(
|
|
86
|
+
get(window, path).getStorage().clear(metadata.name);
|
|
70
87
|
}
|
|
71
88
|
}
|
|
72
89
|
},
|
|
@@ -74,27 +91,27 @@ function getBundleInfo(packageUrl, exposedDependencies = {}, signal) {
|
|
|
74
91
|
};
|
|
75
92
|
});
|
|
76
93
|
}
|
|
77
|
-
|
|
78
|
-
const [isLoading, setIsLoading] =
|
|
79
|
-
const [logService, historyManager, exposedDependencies =
|
|
80
|
-
const dataAttrs =
|
|
94
|
+
export const Loader = forwardRef(({ src, data = {}, basename, loadingFallback, errorFallback, className }, ref) => {
|
|
95
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
96
|
+
const [logService, historyManager, exposedDependencies = EXPOSED_DEPENDENCIES] = useOptionalDependencies(Log, HistoryManager, EXPOSED_DEPENDENCIES_TOKEN);
|
|
97
|
+
const dataAttrs = useMemo(() => Object.fromEntries(Object.entries(data).map(([key, value]) => [
|
|
81
98
|
'data-' + key.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase()),
|
|
82
99
|
value,
|
|
83
100
|
])), [...Object.entries(data).map(v => v.join())] // eslint-disable-line react-hooks/exhaustive-deps
|
|
84
101
|
);
|
|
85
|
-
const Loader =
|
|
86
|
-
const Component =
|
|
87
|
-
const cancelation =
|
|
88
|
-
const eventBus =
|
|
89
|
-
|
|
102
|
+
const Loader = useMemo(() => {
|
|
103
|
+
const Component = forwardRef((_0, ref) => {
|
|
104
|
+
const cancelation = useCancelation();
|
|
105
|
+
const eventBus = useEventBus();
|
|
106
|
+
useImperativeHandle(ref, () => eventBus, [] // eslint-disable-line react-hooks/exhaustive-deps
|
|
90
107
|
);
|
|
91
|
-
|
|
108
|
+
useEffect(() => {
|
|
92
109
|
setIsLoading(true);
|
|
93
110
|
return () => {
|
|
94
111
|
cancelation.abort();
|
|
95
112
|
};
|
|
96
113
|
}, []); // eslint-disable-line react-hooks/exhaustive-deps
|
|
97
|
-
const Lazy =
|
|
114
|
+
const Lazy = useMemo(() => lazy(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
98
115
|
let bundleInfo;
|
|
99
116
|
try {
|
|
100
117
|
bundleInfo = yield getBundleInfo(src, exposedDependencies, cancelation.signal);
|
|
@@ -107,7 +124,7 @@ exports.Loader = (0, react_1.forwardRef)(({ src, data = {}, basename, loadingFal
|
|
|
107
124
|
}
|
|
108
125
|
throw e;
|
|
109
126
|
}
|
|
110
|
-
const {
|
|
127
|
+
const { urls, WebComponent, disposer, mismatch } = bundleInfo;
|
|
111
128
|
if (mismatch) {
|
|
112
129
|
logService === null || logService === void 0 ? void 0 : logService.warning({
|
|
113
130
|
category: 'MicroFrontends.DependenciesMismatch',
|
|
@@ -118,29 +135,32 @@ exports.Loader = (0, react_1.forwardRef)(({ src, data = {}, basename, loadingFal
|
|
|
118
135
|
},
|
|
119
136
|
});
|
|
120
137
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
script.
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
138
|
+
yield Promise.all(urls.js.map(url => {
|
|
139
|
+
const script = Array.from(document.scripts).find(({ src }) => src === url);
|
|
140
|
+
if (!script) {
|
|
141
|
+
return new Promise(resolve => {
|
|
142
|
+
const script = document.createElement('script');
|
|
143
|
+
script.crossOrigin = 'anonymous';
|
|
144
|
+
script.onload = () => {
|
|
145
|
+
script.dataset.webComponent = WebComponent;
|
|
146
|
+
resolve();
|
|
147
|
+
};
|
|
148
|
+
script.async = true;
|
|
149
|
+
script.src = url;
|
|
150
|
+
document.body.append(script);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
else if (!script.dataset.webComponent) {
|
|
154
|
+
return new Promise(resolve => {
|
|
155
|
+
const originalOnload = script.onload;
|
|
156
|
+
script.onload = (...args) => {
|
|
157
|
+
originalOnload === null || originalOnload === void 0 ? void 0 : originalOnload.call(script, ...args);
|
|
158
|
+
resolve();
|
|
159
|
+
};
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
return Promise.resolve();
|
|
163
|
+
}));
|
|
144
164
|
const handleRef = (webComponent) => {
|
|
145
165
|
webComponent === null || webComponent === void 0 ? void 0 : webComponent.provide({
|
|
146
166
|
logService,
|
|
@@ -157,26 +177,30 @@ exports.Loader = (0, react_1.forwardRef)(({ src, data = {}, basename, loadingFal
|
|
|
157
177
|
});
|
|
158
178
|
};
|
|
159
179
|
return {
|
|
160
|
-
default: () => ((
|
|
180
|
+
default: () => (_jsx(WebComponent, Object.assign({ ref: handleRef, class: className }, (urls.css.length
|
|
181
|
+
? {
|
|
182
|
+
'style-urls': encodeURIComponent(JSON.stringify(urls.css)),
|
|
183
|
+
}
|
|
184
|
+
: {}), dataAttrs), void 0)),
|
|
161
185
|
};
|
|
162
186
|
})), [] // eslint-disable-line react-hooks/exhaustive-deps
|
|
163
187
|
);
|
|
164
|
-
return (
|
|
188
|
+
return _jsx(Lazy, {}, void 0);
|
|
165
189
|
});
|
|
166
190
|
return Component;
|
|
167
191
|
}, [src, className, logService, historyManager, exposedDependencies, basename, dataAttrs]);
|
|
168
|
-
const LoadingFallback =
|
|
192
|
+
const LoadingFallback = useMemo(() => () => {
|
|
169
193
|
if (loadingFallback !== undefined) {
|
|
170
194
|
return loadingFallback;
|
|
171
195
|
}
|
|
172
|
-
return (
|
|
196
|
+
return _jsx("h2", { children: "Loading..." }, void 0);
|
|
173
197
|
}, [loadingFallback]);
|
|
174
|
-
const ErrorFallback =
|
|
198
|
+
const ErrorFallback = useMemo(() => () => {
|
|
175
199
|
if (errorFallback !== undefined) {
|
|
176
200
|
return errorFallback;
|
|
177
201
|
}
|
|
178
|
-
return (
|
|
202
|
+
return _jsx("h2", { children: "Something went wrong" }, void 0);
|
|
179
203
|
}, [errorFallback]);
|
|
180
|
-
return ((
|
|
204
|
+
return (_jsxs(ErrorBoundary, Object.assign({ moduleName: src, fallback: ErrorFallback }, { children: [isLoading && _jsx(LoadingFallback, {}, void 0), _jsx(Suspense, Object.assign({ fallback: null }, { children: _jsx(Loader, { ref: ref }, void 0) }), void 0)] }), void 0));
|
|
181
205
|
});
|
|
182
206
|
//# sourceMappingURL=loader.js.map
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.tsx"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EACH,IAAI,EACJ,QAAQ,EACR,SAAS,EACT,OAAO,EACP,QAAQ,EACR,UAAU,EACV,mBAAmB,GAGtB,MAAM,OAAO,CAAC;AAEf,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,aAAa,EAAE,MAAM,8BAA8B,CAAC;AAC7D,OAAO,EAAE,GAAG,EAAE,MA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C,CACJ,CAAC"}
|
package/dist/register.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAM,aAAa,EAAE,MAAM,OAAO,CAAC;AAkC1C,wBAAgB,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAM,aAAa,EAAE,MAAM,OAAO,CAAC;AAkC1C,wBAAgB,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,QAyIhE"}
|
package/dist/register.js
CHANGED
|
@@ -1,15 +1,12 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
const event_bus_1 = require("./event-bus");
|
|
11
|
-
const history_manager_1 = require("./history-manager");
|
|
12
|
-
const globals_1 = require("./globals");
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { render, unmountComponentAtNode } from 'react-dom';
|
|
3
|
+
import { Log } from '@servicetitan/log-service';
|
|
4
|
+
import { DefaultPortalContext, TablePopupPropsContext } from '@servicetitan/design-system';
|
|
5
|
+
import { Provider } from '@servicetitan/react-ioc';
|
|
6
|
+
import { EXPOSED_DEPENDENCIES_TOKEN, BASENAME_TOKEN, IS_WEB_COMPONENT_TOKEN, RENDER_ROOT_TOKEN, } from './common';
|
|
7
|
+
import { EventBus } from './event-bus';
|
|
8
|
+
import { HistoryManager } from './history-manager';
|
|
9
|
+
import { WEB_COMPONENT_NAME } from './globals';
|
|
13
10
|
function createLink(url, onLoad) {
|
|
14
11
|
const element = document.createElement('link');
|
|
15
12
|
element.href = url;
|
|
@@ -19,17 +16,8 @@ function createLink(url, onLoad) {
|
|
|
19
16
|
element.onerror = onLoad;
|
|
20
17
|
return element;
|
|
21
18
|
}
|
|
22
|
-
const Placeholder = () => (
|
|
23
|
-
function register(Component, light) {
|
|
24
|
-
var _a;
|
|
25
|
-
const currentDir = document.currentScript.src
|
|
26
|
-
.split('/')
|
|
27
|
-
.slice(0, -1)
|
|
28
|
-
.join('/');
|
|
29
|
-
const stylesUrl = `${currentDir}/index.css`;
|
|
30
|
-
const designSystemUrl = light
|
|
31
|
-
? (_a = Array.from(document.getElementsByTagName('link')).find(({ href }) => href && /design-system(\..+)?\.bundle\.css/.test(href))) === null || _a === void 0 ? void 0 : _a.href
|
|
32
|
-
: undefined;
|
|
19
|
+
const Placeholder = () => _jsx("div", { style: { display: 'none' } }, void 0);
|
|
20
|
+
export function register(Component, light) {
|
|
33
21
|
class WebComponent extends HTMLElement {
|
|
34
22
|
constructor() {
|
|
35
23
|
super(...arguments);
|
|
@@ -49,10 +37,7 @@ function register(Component, light) {
|
|
|
49
37
|
enumerable: true,
|
|
50
38
|
configurable: true,
|
|
51
39
|
writable: true,
|
|
52
|
-
value: {
|
|
53
|
-
total: 2 + (designSystemUrl ? 2 : 0),
|
|
54
|
-
loaded: 0,
|
|
55
|
-
}
|
|
40
|
+
value: { total: 0, loaded: 0, elements: [] }
|
|
56
41
|
});
|
|
57
42
|
Object.defineProperty(this, "logService", {
|
|
58
43
|
enumerable: true,
|
|
@@ -122,15 +107,18 @@ function register(Component, light) {
|
|
|
122
107
|
}
|
|
123
108
|
}
|
|
124
109
|
});
|
|
125
|
-
Object.defineProperty(this, "
|
|
110
|
+
Object.defineProperty(this, "attachStyles", {
|
|
126
111
|
enumerable: true,
|
|
127
112
|
configurable: true,
|
|
128
113
|
writable: true,
|
|
129
|
-
value: (node) => {
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
114
|
+
value: (node, urls) => {
|
|
115
|
+
const elements = [];
|
|
116
|
+
for (const url of urls) {
|
|
117
|
+
const element = createLink(url, this.handleLoad);
|
|
118
|
+
node.appendChild(element);
|
|
119
|
+
elements.push(element);
|
|
133
120
|
}
|
|
121
|
+
return elements;
|
|
134
122
|
}
|
|
135
123
|
});
|
|
136
124
|
Object.defineProperty(this, "render", {
|
|
@@ -138,44 +126,58 @@ function register(Component, light) {
|
|
|
138
126
|
configurable: true,
|
|
139
127
|
writable: true,
|
|
140
128
|
value: () => {
|
|
141
|
-
|
|
142
|
-
{ provide:
|
|
143
|
-
{ provide:
|
|
144
|
-
] }, { children: (
|
|
145
|
-
{ provide:
|
|
146
|
-
{ provide:
|
|
129
|
+
render(_jsx(Provider, Object.assign({ singletons: [
|
|
130
|
+
{ provide: IS_WEB_COMPONENT_TOKEN, useValue: true },
|
|
131
|
+
{ provide: RENDER_ROOT_TOKEN, useValue: this.root },
|
|
132
|
+
] }, { children: _jsx(DefaultPortalContext.Provider, Object.assign({ value: this.portal }, { children: _jsx(TablePopupPropsContext.Provider, Object.assign({ value: props => (Object.assign(Object.assign({}, props), { appendTo: this.root })) }, { children: _jsx(Provider, Object.assign({ singletons: [
|
|
133
|
+
{ provide: Log, useValue: this.logService },
|
|
134
|
+
{ provide: HistoryManager, useValue: this.historyManager },
|
|
147
135
|
{
|
|
148
|
-
provide:
|
|
136
|
+
provide: EXPOSED_DEPENDENCIES_TOKEN,
|
|
149
137
|
useValue: this.exposedDependencies,
|
|
150
138
|
},
|
|
151
|
-
{ provide:
|
|
152
|
-
{ provide:
|
|
153
|
-
].filter(({ useValue }) => useValue !== undefined) }, { children: (
|
|
139
|
+
{ provide: EventBus, useValue: this.eventBus },
|
|
140
|
+
{ provide: BASENAME_TOKEN, useValue: this.basename },
|
|
141
|
+
].filter(({ useValue }) => useValue !== undefined) }, { children: _jsx(Component, Object.assign({}, this.dataset), void 0) }), void 0) }), void 0) }), void 0) }), void 0), this.root, this.onReady);
|
|
154
142
|
}
|
|
155
143
|
});
|
|
156
144
|
}
|
|
157
145
|
connectedCallback() {
|
|
146
|
+
var _a;
|
|
147
|
+
const designSystemUrl = light
|
|
148
|
+
? (_a = Array.from(document.getElementsByTagName('link')).find(({ href }) => href && /design-system(\..+)?\.bundle\.css/.test(href))) === null || _a === void 0 ? void 0 : _a.href
|
|
149
|
+
: undefined;
|
|
150
|
+
const styleUrls = (this.hasAttribute('style-urls')
|
|
151
|
+
? JSON.parse(decodeURIComponent(this.getAttribute('style-urls')))
|
|
152
|
+
: []).concat(designSystemUrl !== null && designSystemUrl !== void 0 ? designSystemUrl : []);
|
|
153
|
+
this.styles = {
|
|
154
|
+
total: styleUrls.length * 2,
|
|
155
|
+
loaded: 0,
|
|
156
|
+
elements: [],
|
|
157
|
+
};
|
|
158
158
|
this.root = this.attachShadow({ mode: 'open' });
|
|
159
159
|
this.portal = document.body
|
|
160
160
|
.appendChild(document.createElement('div'))
|
|
161
161
|
.attachShadow({ mode: 'open' });
|
|
162
|
-
|
|
163
|
-
this.
|
|
164
|
-
this.
|
|
162
|
+
render(_jsx(Placeholder, {}, void 0), this.root);
|
|
163
|
+
this.styles.elements.push(...this.attachStyles(this.root, styleUrls));
|
|
164
|
+
this.styles.elements.push(...this.attachStyles(this.portal, styleUrls));
|
|
165
165
|
}
|
|
166
166
|
disconnectedCallback() {
|
|
167
167
|
var _a;
|
|
168
|
-
(
|
|
168
|
+
for (const element of this.styles.elements) {
|
|
169
|
+
element.remove();
|
|
170
|
+
}
|
|
171
|
+
unmountComponentAtNode(this.root);
|
|
169
172
|
document.body.removeChild(this.portal.host);
|
|
170
173
|
(_a = this.onDispose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
171
174
|
}
|
|
172
175
|
}
|
|
173
|
-
if (!
|
|
176
|
+
if (!WEB_COMPONENT_NAME) {
|
|
174
177
|
// eslint-disable-next-line no-console
|
|
175
178
|
console.error('"WEB_COMPONENT_NAME" is not defined!');
|
|
176
179
|
return;
|
|
177
180
|
}
|
|
178
|
-
window.customElements.define(
|
|
181
|
+
window.customElements.define(WEB_COMPONENT_NAME, WebComponent);
|
|
179
182
|
}
|
|
180
|
-
exports.register = register;
|
|
181
183
|
//# sourceMappingURL=register.js.map
|
package/dist/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.js","sourceRoot":"","sources":["../src/register.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,WAAW,CAAC;AAE3D,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAE,oBAAoB,EAAE,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAC3F,OAAO,EAAE,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAEnD,OAAO,EAEH,0BAA0B,EAG1B,cAAc,EACd,sBAAsB,EACtB,iBAAiB,GACpB,MAAM,UAAU,CAAC;AAClB,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,MAAM,mBAAmB,CAAC;AACnD,OAAO,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAE/C,SAAS,UAAU,CAAC,GAAW,EAAE,MAAkB;IAC/C,MAAM,OAAO,GAAG,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAE/C,OAAO,CAAC,IAAI,GAAG,GAAG,CAAC;IACnB,OAAO,CAAC,GAAG,GAAG,YAAY,CAAC;IAC3B,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC;IAClC,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC;IACxB,OAAO,CAAC,OAAO,GAAG,MAAM,CAAC;IAEzB,OAAO,OAAO,CAAC;AACnB,CAAC;AAED,MAAM,WAAW,GAAO,GAAG,EAAE,CAAC,cAAK,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,EAAE,WAAI,CAAC;AAElE,MAAM,UAAU,QAAQ,CAAC,SAAwB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AAC,CAAC,CAAC;YACtE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;QAC5E,CAAC;QAED,oBAAoB;;YAChB,KAAK,MAAM,OAAO,IAAI,IAAI,CAAC,MAAM,CAAC,QAAQ,EAAE;gBACxC,OAAO,CAAC,MAAM,EAAE,CAAC;aACpB;YAED,sBAAsB,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAClC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAE5C,MAAA,IAAI,CAAC,SAAS,+CAAd,IAAI,CAAc,CAAC;QACvB,CAAC;KAsEJ;IAED,IAAI,CAAC,kBAAkB,EAAE;QACrB,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC,sCAAsC,CAAC,CAAC;QACtD,OAAO;KACV;IAED,MAAM,CAAC,cAAc,CAAC,MAAM,CAAC,kBAAkB,EAAE,YAAY,CAAC,CAAC;AACnE,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/web-components",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "20.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -9,23 +9,24 @@
|
|
|
9
9
|
},
|
|
10
10
|
"main": "./dist/index.js",
|
|
11
11
|
"typings": "./dist/index.d.ts",
|
|
12
|
+
"sideEffects": false,
|
|
12
13
|
"files": [
|
|
13
14
|
"dist",
|
|
14
15
|
"src"
|
|
15
16
|
],
|
|
16
17
|
"dependencies": {
|
|
17
|
-
"@servicetitan/error-boundary": "^
|
|
18
|
+
"@servicetitan/error-boundary": "^20.0.1",
|
|
18
19
|
"lodash.get": "~4.4.2",
|
|
19
20
|
"mitt": "~3.0.0",
|
|
20
21
|
"semver": "~7.3.5"
|
|
21
22
|
},
|
|
22
23
|
"devDependencies": {
|
|
23
|
-
"@servicetitan/design-system": "~
|
|
24
|
-
"@servicetitan/log-service": "^
|
|
25
|
-
"@servicetitan/react-ioc": "^
|
|
26
|
-
"@types/history": "~4.7.
|
|
24
|
+
"@servicetitan/design-system": "~11.1.0",
|
|
25
|
+
"@servicetitan/log-service": "^20.0.1",
|
|
26
|
+
"@servicetitan/react-ioc": "^20.0.1",
|
|
27
|
+
"@types/history": "~4.7.10",
|
|
27
28
|
"@types/lodash.get": "~4.4.6",
|
|
28
|
-
"@types/react": "~17.0.
|
|
29
|
+
"@types/react": "~17.0.38",
|
|
29
30
|
"@types/react-dom": "~17.0.11",
|
|
30
31
|
"@types/semver": "~7.3.9",
|
|
31
32
|
"history": "~4.10.1",
|
|
@@ -33,9 +34,9 @@
|
|
|
33
34
|
"react-dom": "~17.0.2"
|
|
34
35
|
},
|
|
35
36
|
"peerDependencies": {
|
|
36
|
-
"@servicetitan/design-system": "~
|
|
37
|
-
"@servicetitan/log-service": "^
|
|
38
|
-
"@servicetitan/react-ioc": "^
|
|
37
|
+
"@servicetitan/design-system": "~11.1.0",
|
|
38
|
+
"@servicetitan/log-service": "^20.0.0",
|
|
39
|
+
"@servicetitan/react-ioc": "^20.0.0",
|
|
39
40
|
"history": "~4.10.1",
|
|
40
41
|
"react": "~17.0.2",
|
|
41
42
|
"react-dom": "~17.0.2"
|
|
@@ -46,5 +47,5 @@
|
|
|
46
47
|
"cli": {
|
|
47
48
|
"webpack": false
|
|
48
49
|
},
|
|
49
|
-
"gitHead": "
|
|
50
|
+
"gitHead": "0c0dc470ff92789389bbb96a8e867ecd439a1509"
|
|
50
51
|
}
|
package/src/loader.tsx
CHANGED
|
@@ -40,6 +40,22 @@ function omitPackageVersion(packageUrl: string) {
|
|
|
40
40
|
return packageUrl;
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
async function getEntrypoints(
|
|
44
|
+
url: string,
|
|
45
|
+
signal?: AbortSignal
|
|
46
|
+
): Promise<{ css: string[]; js: string[] }> {
|
|
47
|
+
try {
|
|
48
|
+
return (
|
|
49
|
+
await getJson(url, {
|
|
50
|
+
cache: 'no-store',
|
|
51
|
+
signal,
|
|
52
|
+
})
|
|
53
|
+
).data;
|
|
54
|
+
} catch {
|
|
55
|
+
return { css: ['index.css'], js: ['index.js'] };
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
43
59
|
async function getBundleInfo(
|
|
44
60
|
packageUrl: string,
|
|
45
61
|
exposedDependencies: ExposedDependencies = {},
|
|
@@ -55,7 +71,10 @@ async function getBundleInfo(
|
|
|
55
71
|
? `${omitPackageVersion(packageUrl)}@${version}`
|
|
56
72
|
: packageUrl;
|
|
57
73
|
|
|
58
|
-
const { data: metadata } = await getJson(`${exactPackageUrl}/dist/metadata.json`, {
|
|
74
|
+
const { data: metadata } = await getJson(`${exactPackageUrl}/dist/metadata.json`, {
|
|
75
|
+
cache: 'no-store',
|
|
76
|
+
signal,
|
|
77
|
+
});
|
|
59
78
|
|
|
60
79
|
const mismatch = Object.entries(exposedDependencies).reduce(
|
|
61
80
|
(result, [dependency, { version: hostVersion }]) => {
|
|
@@ -84,8 +103,15 @@ async function getBundleInfo(
|
|
|
84
103
|
const startupVersion = metadata.bundledWith?.['@servicetitan/startup'];
|
|
85
104
|
const supportLightBundles = startupVersion && semver.gte(startupVersion, '17.0.0');
|
|
86
105
|
const embed = !hasMismatch && supportLightBundles;
|
|
106
|
+
const withBaseUrl = (path: string) => {
|
|
107
|
+
return `${exactPackageUrl}/dist/bundle/${embed ? 'light' : 'full'}/${path}`;
|
|
108
|
+
};
|
|
109
|
+
const entrypoints = await getEntrypoints(withBaseUrl('entrypoints.json'));
|
|
87
110
|
return {
|
|
88
|
-
|
|
111
|
+
urls: {
|
|
112
|
+
css: entrypoints.css.map(withBaseUrl),
|
|
113
|
+
js: entrypoints.js.map(withBaseUrl),
|
|
114
|
+
},
|
|
89
115
|
WebComponent: metadata.name,
|
|
90
116
|
disposer: () => {
|
|
91
117
|
if (embed) {
|
|
@@ -167,7 +193,7 @@ export const Loader = forwardRef<LoaderRef, LoaderProps>(
|
|
|
167
193
|
throw e;
|
|
168
194
|
}
|
|
169
195
|
|
|
170
|
-
const {
|
|
196
|
+
const { urls, WebComponent, disposer, mismatch } = bundleInfo;
|
|
171
197
|
|
|
172
198
|
if (mismatch) {
|
|
173
199
|
logService?.warning({
|
|
@@ -181,32 +207,38 @@ export const Loader = forwardRef<LoaderRef, LoaderProps>(
|
|
|
181
207
|
});
|
|
182
208
|
}
|
|
183
209
|
|
|
184
|
-
|
|
185
|
-
(
|
|
210
|
+
await Promise.all(
|
|
211
|
+
urls.js.map(url => {
|
|
212
|
+
const script = Array.from(document.scripts).find(
|
|
213
|
+
({ src }) => src === url
|
|
214
|
+
);
|
|
215
|
+
if (!script) {
|
|
216
|
+
return new Promise<void>(resolve => {
|
|
217
|
+
const script = document.createElement('script');
|
|
218
|
+
|
|
219
|
+
script.crossOrigin = 'anonymous';
|
|
220
|
+
script.onload = () => {
|
|
221
|
+
script.dataset.webComponent = WebComponent;
|
|
222
|
+
resolve();
|
|
223
|
+
};
|
|
224
|
+
script.async = true;
|
|
225
|
+
script.src = url;
|
|
226
|
+
|
|
227
|
+
document.body.append(script);
|
|
228
|
+
});
|
|
229
|
+
} else if (!script.dataset.webComponent) {
|
|
230
|
+
return new Promise<void>(resolve => {
|
|
231
|
+
const originalOnload = script.onload;
|
|
232
|
+
script.onload = (...args) => {
|
|
233
|
+
originalOnload?.call(script, ...args);
|
|
234
|
+
resolve();
|
|
235
|
+
};
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return Promise.resolve();
|
|
240
|
+
})
|
|
186
241
|
);
|
|
187
|
-
if (!script) {
|
|
188
|
-
await new Promise<void>(resolve => {
|
|
189
|
-
const script = document.createElement('script');
|
|
190
|
-
|
|
191
|
-
script.crossOrigin = 'anonymous';
|
|
192
|
-
script.onload = () => {
|
|
193
|
-
script.dataset.webComponent = WebComponent;
|
|
194
|
-
resolve();
|
|
195
|
-
};
|
|
196
|
-
script.async = true;
|
|
197
|
-
script.src = url;
|
|
198
|
-
|
|
199
|
-
document.body.append(script);
|
|
200
|
-
});
|
|
201
|
-
} else if (!script.dataset.webComponent) {
|
|
202
|
-
await new Promise<void>(resolve => {
|
|
203
|
-
const originalOnload = script.onload;
|
|
204
|
-
script.onload = (...args) => {
|
|
205
|
-
originalOnload?.call(script, ...args);
|
|
206
|
-
resolve();
|
|
207
|
-
};
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
242
|
|
|
211
243
|
const handleRef = (webComponent: IWebComponent | null) => {
|
|
212
244
|
webComponent?.provide({
|
|
@@ -229,6 +261,13 @@ export const Loader = forwardRef<LoaderRef, LoaderProps>(
|
|
|
229
261
|
<WebComponent
|
|
230
262
|
ref={handleRef}
|
|
231
263
|
class={className}
|
|
264
|
+
{...(urls.css.length
|
|
265
|
+
? {
|
|
266
|
+
'style-urls': encodeURIComponent(
|
|
267
|
+
JSON.stringify(urls.css)
|
|
268
|
+
),
|
|
269
|
+
}
|
|
270
|
+
: {})}
|
|
232
271
|
{...dataAttrs}
|
|
233
272
|
/>
|
|
234
273
|
),
|
package/src/register.tsx
CHANGED
|
@@ -33,26 +33,15 @@ function createLink(url: string, onLoad: () => void) {
|
|
|
33
33
|
const Placeholder: FC = () => <div style={{ display: 'none' }} />;
|
|
34
34
|
|
|
35
35
|
export function register(Component: ComponentType, light: boolean) {
|
|
36
|
-
const currentDir = (document.currentScript as HTMLScriptElement).src
|
|
37
|
-
.split('/')
|
|
38
|
-
.slice(0, -1)
|
|
39
|
-
.join('/');
|
|
40
|
-
|
|
41
|
-
const stylesUrl = `${currentDir}/index.css`;
|
|
42
|
-
const designSystemUrl = light
|
|
43
|
-
? Array.from(document.getElementsByTagName('link')).find(
|
|
44
|
-
({ href }) => href && /design-system(\..+)?\.bundle\.css/.test(href)
|
|
45
|
-
)?.href
|
|
46
|
-
: undefined;
|
|
47
|
-
|
|
48
36
|
class WebComponent extends HTMLElement implements IWebComponent {
|
|
49
37
|
private root!: ShadowRoot;
|
|
50
38
|
private portal!: ShadowRoot;
|
|
51
39
|
|
|
52
|
-
private styles
|
|
53
|
-
total:
|
|
54
|
-
loaded:
|
|
55
|
-
|
|
40
|
+
private styles: {
|
|
41
|
+
total: number;
|
|
42
|
+
loaded: number;
|
|
43
|
+
elements: HTMLElement[];
|
|
44
|
+
} = { total: 0, loaded: 0, elements: [] };
|
|
56
45
|
|
|
57
46
|
private logService?: Log;
|
|
58
47
|
private historyManager?: HistoryManager;
|
|
@@ -63,6 +52,24 @@ export function register(Component: ComponentType, light: boolean) {
|
|
|
63
52
|
private onDispose?: () => void;
|
|
64
53
|
|
|
65
54
|
connectedCallback() {
|
|
55
|
+
const designSystemUrl = light
|
|
56
|
+
? Array.from(document.getElementsByTagName('link')).find(
|
|
57
|
+
({ href }) => href && /design-system(\..+)?\.bundle\.css/.test(href)
|
|
58
|
+
)?.href
|
|
59
|
+
: undefined;
|
|
60
|
+
|
|
61
|
+
const styleUrls = (
|
|
62
|
+
this.hasAttribute('style-urls')
|
|
63
|
+
? JSON.parse(decodeURIComponent(this.getAttribute('style-urls')!))
|
|
64
|
+
: []
|
|
65
|
+
).concat(designSystemUrl ?? []);
|
|
66
|
+
|
|
67
|
+
this.styles = {
|
|
68
|
+
total: styleUrls.length * 2,
|
|
69
|
+
loaded: 0,
|
|
70
|
+
elements: [],
|
|
71
|
+
};
|
|
72
|
+
|
|
66
73
|
this.root = this.attachShadow({ mode: 'open' });
|
|
67
74
|
this.portal = document.body
|
|
68
75
|
.appendChild(document.createElement('div'))
|
|
@@ -70,13 +77,18 @@ export function register(Component: ComponentType, light: boolean) {
|
|
|
70
77
|
|
|
71
78
|
render(<Placeholder />, this.root);
|
|
72
79
|
|
|
73
|
-
this.
|
|
74
|
-
this.
|
|
80
|
+
this.styles.elements.push(...this.attachStyles(this.root, styleUrls));
|
|
81
|
+
this.styles.elements.push(...this.attachStyles(this.portal, styleUrls));
|
|
75
82
|
}
|
|
76
83
|
|
|
77
84
|
disconnectedCallback() {
|
|
85
|
+
for (const element of this.styles.elements) {
|
|
86
|
+
element.remove();
|
|
87
|
+
}
|
|
88
|
+
|
|
78
89
|
unmountComponentAtNode(this.root);
|
|
79
90
|
document.body.removeChild(this.portal.host);
|
|
91
|
+
|
|
80
92
|
this.onDispose?.();
|
|
81
93
|
}
|
|
82
94
|
|
|
@@ -100,12 +112,16 @@ export function register(Component: ComponentType, light: boolean) {
|
|
|
100
112
|
}
|
|
101
113
|
};
|
|
102
114
|
|
|
103
|
-
private
|
|
104
|
-
|
|
115
|
+
private attachStyles = (node: ShadowRoot, urls: string[]) => {
|
|
116
|
+
const elements: HTMLElement[] = [];
|
|
105
117
|
|
|
106
|
-
|
|
107
|
-
|
|
118
|
+
for (const url of urls) {
|
|
119
|
+
const element = createLink(url, this.handleLoad);
|
|
120
|
+
node.appendChild(element);
|
|
121
|
+
elements.push(element);
|
|
108
122
|
}
|
|
123
|
+
|
|
124
|
+
return elements;
|
|
109
125
|
};
|
|
110
126
|
|
|
111
127
|
private render = () => {
|