@servicetitan/web-components 23.0.0 → 23.1.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/dist/contexts/tests/mfe-data-context.test.js +1 -1
- package/dist/contexts/tests/mfe-data-context.test.js.map +1 -1
- package/dist/contexts/tests/mfe-metadata-context.test.js +1 -1
- package/dist/contexts/tests/mfe-metadata-context.test.js.map +1 -1
- package/dist/loader.d.ts +7 -17
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +74 -224
- package/dist/loader.js.map +1 -1
- package/dist/register.d.ts.map +1 -1
- package/dist/register.js +1 -0
- package/dist/register.js.map +1 -1
- package/dist/utils/get-bundle-info.d.ts +24 -0
- package/dist/utils/get-bundle-info.d.ts.map +1 -0
- package/dist/utils/get-bundle-info.js +98 -0
- package/dist/utils/get-bundle-info.js.map +1 -0
- package/dist/utils/get-entry-points.d.ts +6 -0
- package/dist/utils/get-entry-points.d.ts.map +1 -0
- package/dist/utils/get-entry-points.js +24 -0
- package/dist/utils/get-entry-points.js.map +1 -0
- package/dist/{get-mfe-supports-rerendering.d.ts → utils/get-mfe-supports-rerendering.d.ts} +1 -1
- package/dist/utils/get-mfe-supports-rerendering.d.ts.map +1 -0
- package/dist/utils/get-mfe-supports-rerendering.js.map +1 -0
- package/dist/{utils.d.ts → utils/get-version-mismatches.d.ts} +2 -3
- package/dist/utils/get-version-mismatches.d.ts.map +1 -0
- package/dist/{utils.js → utils/get-version-mismatches.js} +2 -10
- package/dist/utils/get-version-mismatches.js.map +1 -0
- package/dist/utils/index.d.ts +9 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +9 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/is-versioned-url.d.ts +2 -0
- package/dist/utils/is-versioned-url.d.ts.map +1 -0
- package/dist/utils/is-versioned-url.js +9 -0
- package/dist/utils/is-versioned-url.js.map +1 -0
- package/dist/utils/load-scripts.d.ts +3 -0
- package/dist/utils/load-scripts.d.ts.map +1 -0
- package/dist/utils/load-scripts.js +31 -0
- package/dist/utils/load-scripts.js.map +1 -0
- package/dist/utils/validate-bundle-info.d.ts +7 -0
- package/dist/utils/validate-bundle-info.d.ts.map +1 -0
- package/dist/utils/validate-bundle-info.js +10 -0
- package/dist/utils/validate-bundle-info.js.map +1 -0
- package/dist/utils/web-component.d.ts +17 -0
- package/dist/utils/web-component.d.ts.map +1 -0
- package/dist/utils/web-component.js +54 -0
- package/dist/utils/web-component.js.map +1 -0
- package/package.json +16 -17
- package/src/__tests__/event-bus.test.ts +3 -2
- package/src/__tests__/loader.test.tsx +17 -11
- package/src/contexts/tests/mfe-data-context.test.tsx +4 -4
- package/src/contexts/tests/mfe-metadata-context.test.tsx +4 -4
- package/src/loader.tsx +129 -374
- package/src/register.tsx +1 -0
- package/src/{__tests__ → utils/__tests__}/get-mfe-supports-rerendering.test.ts +1 -1
- package/src/utils/__tests__/get-version-mismatches.test.ts +76 -0
- package/src/utils/__tests__/is-versioned-url.test.ts +18 -0
- package/src/utils/get-bundle-info.ts +121 -0
- package/src/utils/get-entry-points.ts +23 -0
- package/src/{get-mfe-supports-rerendering.ts → utils/get-mfe-supports-rerendering.ts} +1 -1
- package/src/{utils.ts → utils/get-version-mismatches.ts} +1 -12
- package/src/utils/index.ts +8 -0
- package/src/utils/is-versioned-url.ts +11 -0
- package/src/utils/load-scripts.ts +38 -0
- package/src/utils/validate-bundle-info.ts +15 -0
- package/src/utils/web-component.tsx +96 -0
- package/dist/get-mfe-supports-rerendering.d.ts.map +0 -1
- package/dist/get-mfe-supports-rerendering.js.map +0 -1
- package/dist/utils.d.ts.map +0 -1
- package/dist/utils.js.map +0 -1
- package/src/__tests__/utils.test.ts +0 -95
- /package/dist/{get-mfe-supports-rerendering.js → utils/get-mfe-supports-rerendering.js} +0 -0
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { getJson } from '../common';
|
|
11
|
+
export function getEntrypoints(url, cache, signal) {
|
|
12
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
13
|
+
try {
|
|
14
|
+
return (yield getJson(url, {
|
|
15
|
+
cache,
|
|
16
|
+
signal,
|
|
17
|
+
})).data;
|
|
18
|
+
}
|
|
19
|
+
catch (_a) {
|
|
20
|
+
return { css: ['index.css'], js: ['index.js'] };
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=get-entry-points.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-entry-points.js","sourceRoot":"","sources":["../../src/utils/get-entry-points.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAOpC,MAAM,UAAgB,cAAc,CAChC,GAAW,EACX,KAA6B,EAC7B,MAAoB;;QAEpB,IAAI;YACA,OAAO,CACH,MAAM,OAAO,CAAC,GAAG,EAAE;gBACf,KAAK;gBACL,MAAM;aACT,CAAC,CACL,CAAC,IAAI,CAAC;SACV;QAAC,WAAM;YACJ,OAAO,EAAE,GAAG,EAAE,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,CAAC,UAAU,CAAC,EAAE,CAAC;SACnD;IACL,CAAC;CAAA"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
import { Metadata } from './
|
|
1
|
+
import { Metadata } from './get-bundle-info';
|
|
2
2
|
export declare function getMFESupportsRerendering(bundledWith: Metadata['bundledWith'], dependencies: Metadata['dependencies']): boolean;
|
|
3
3
|
//# sourceMappingURL=get-mfe-supports-rerendering.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-mfe-supports-rerendering.d.ts","sourceRoot":"","sources":["../../src/utils/get-mfe-supports-rerendering.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAY7C,wBAAgB,yBAAyB,CACrC,WAAW,EAAE,QAAQ,CAAC,aAAa,CAAC,EACpC,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,WAOzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-mfe-supports-rerendering.js","sourceRoot":"","sources":["../../src/utils/get-mfe-supports-rerendering.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAG5B;;;;;;;;;GASG;AACH,MAAM,UAAU,yBAAyB,CACrC,WAAoC,EACpC,YAAsC;;IAEtC,OAAO,CAAC,CAAC,CACL,MAAA,MAAA,kBAAkB,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,8BAA8B,CAAC,CAAC,mCACjE,kBAAkB,CAAC,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAG,8BAA8B,CAAC,CAAC,mCAClE,kBAAkB,CAAC,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAG,uBAAuB,CAAC,CAAC,CAC7D,CAAC;AACN,CAAC;AAED,SAAS,kBAAkB,CAAC,OAAgB;IACxC,MAAM,UAAU,GAAG,OAAO,IAAI,MAAM,CAAC,UAAU,CAAC,OAAO,CAAC,CAAC;IACzD,IAAI,UAAU,EAAE;QACZ,OAAO,MAAM,CAAC,GAAG,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC;KAC5C;AACL,CAAC"}
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { ExposedDependencies } from '
|
|
1
|
+
import { ExposedDependencies } from '../common';
|
|
2
2
|
export declare const getVersionMismatches: (exposedDependencies: ExposedDependencies, dependencies: Record<string, string>, sharedDependencies: Record<string, string>) => Record<string, {
|
|
3
3
|
host: string;
|
|
4
4
|
package: string;
|
|
5
5
|
}>;
|
|
6
|
-
|
|
7
|
-
//# sourceMappingURL=utils.d.ts.map
|
|
6
|
+
//# sourceMappingURL=get-version-mismatches.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-version-mismatches.d.ts","sourceRoot":"","sources":["../../src/utils/get-version-mismatches.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAgB,MAAM,WAAW,CAAC;AAE9D,eAAO,MAAM,oBAAoB,wBACR,mBAAmB,gBAC1B,OAAO,MAAM,EAAE,MAAM,CAAC,sBAChB,OAAO,MAAM,EAAE,MAAM,CAAC;UAYT,MAAM;aAAW,MAAM;EAc3D,CAAC"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { isCompatible } from './common';
|
|
1
|
+
import { isCompatible } from '../common';
|
|
3
2
|
export const getVersionMismatches = (exposedDependencies, dependencies, sharedDependencies) => {
|
|
4
3
|
const mismatch = Object.entries(exposedDependencies).reduce((result, [dependency, { version: hostVersion }]) => {
|
|
5
4
|
const packageVersion = dependencies[dependency];
|
|
@@ -19,11 +18,4 @@ export const getVersionMismatches = (exposedDependencies, dependencies, sharedDe
|
|
|
19
18
|
}
|
|
20
19
|
return mismatch;
|
|
21
20
|
};
|
|
22
|
-
|
|
23
|
-
if (!url.includes('unpkg.')) {
|
|
24
|
-
return false;
|
|
25
|
-
}
|
|
26
|
-
const parts = url.split('@');
|
|
27
|
-
return !!semver.clean(parts[parts.length - 1]);
|
|
28
|
-
};
|
|
29
|
-
//# sourceMappingURL=utils.js.map
|
|
21
|
+
//# sourceMappingURL=get-version-mismatches.js.map
|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AACpB,CAAC,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './get-bundle-info';
|
|
2
|
+
export * from './get-entry-points';
|
|
3
|
+
export * from './get-mfe-supports-rerendering';
|
|
4
|
+
export * from './get-version-mismatches';
|
|
5
|
+
export * from './is-versioned-url';
|
|
6
|
+
export * from './load-scripts';
|
|
7
|
+
export * from './validate-bundle-info';
|
|
8
|
+
export * from './web-component';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export * from './get-bundle-info';
|
|
2
|
+
export * from './get-entry-points';
|
|
3
|
+
export * from './get-mfe-supports-rerendering';
|
|
4
|
+
export * from './get-version-mismatches';
|
|
5
|
+
export * from './is-versioned-url';
|
|
6
|
+
export * from './load-scripts';
|
|
7
|
+
export * from './validate-bundle-info';
|
|
8
|
+
export * from './web-component';
|
|
9
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,mBAAmB,CAAC;AAClC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gCAAgC,CAAC;AAC/C,cAAc,0BAA0B,CAAC;AACzC,cAAc,oBAAoB,CAAC;AACnC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,wBAAwB,CAAC;AACvC,cAAc,iBAAiB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-versioned-url.d.ts","sourceRoot":"","sources":["../../src/utils/is-versioned-url.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,cAAc,QAAS,MAAM,KAAG,OAQ5C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"is-versioned-url.js","sourceRoot":"","sources":["../../src/utils/is-versioned-url.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,QAAQ,CAAC;AAE5B,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,GAAW,EAAW,EAAE;IACnD,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAE;QACzB,OAAO,KAAK,CAAC;KAChB;IAED,MAAM,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IAE7B,OAAO,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC;AACnD,CAAC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-scripts.d.ts","sourceRoot":"","sources":["../../src/utils/load-scripts.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,wBAAgB,WAAW,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,UAAU,mBAmC7D"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export function loadScripts({ urls, WebComponent }) {
|
|
2
|
+
return Promise.all(urls.js.map(url => {
|
|
3
|
+
const script = Array.from(document.scripts).find(({ src }) => src === url);
|
|
4
|
+
if (!script) {
|
|
5
|
+
return new Promise(resolve => {
|
|
6
|
+
const script = document.createElement('script');
|
|
7
|
+
script.crossOrigin = 'anonymous';
|
|
8
|
+
script.onload = () => {
|
|
9
|
+
script.dataset.webComponent = WebComponent;
|
|
10
|
+
script.onload = null;
|
|
11
|
+
resolve();
|
|
12
|
+
};
|
|
13
|
+
script.async = true;
|
|
14
|
+
script.src = url;
|
|
15
|
+
document.body.append(script);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
if (!script.dataset.webComponent) {
|
|
19
|
+
return new Promise(resolve => {
|
|
20
|
+
const originalOnload = script.onload;
|
|
21
|
+
script.onload = (...args) => {
|
|
22
|
+
originalOnload === null || originalOnload === void 0 ? void 0 : originalOnload.call(script, ...args);
|
|
23
|
+
script.onload = null;
|
|
24
|
+
resolve();
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
return Promise.resolve();
|
|
29
|
+
}));
|
|
30
|
+
}
|
|
31
|
+
//# sourceMappingURL=load-scripts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-scripts.js","sourceRoot":"","sources":["../../src/utils/load-scripts.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CAAC,EAAE,IAAI,EAAE,YAAY,EAAc;IAC1D,OAAO,OAAO,CAAC,GAAG,CACd,IAAI,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QACd,MAAM,MAAM,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,GAAG,EAAE,EAAE,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;QAC3E,IAAI,CAAC,MAAM,EAAE;YACT,OAAO,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE;gBAC/B,MAAM,MAAM,GAAG,QAAQ,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;gBAEhD,MAAM,CAAC,WAAW,GAAG,WAAW,CAAC;gBACjC,MAAM,CAAC,MAAM,GAAG,GAAG,EAAE;oBACjB,MAAM,CAAC,OAAO,CAAC,YAAY,GAAG,YAAY,CAAC;oBAC3C,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;oBACrB,OAAO,EAAE,CAAC;gBACd,CAAC,CAAC;gBACF,MAAM,CAAC,KAAK,GAAG,IAAI,CAAC;gBACpB,MAAM,CAAC,GAAG,GAAG,GAAG,CAAC;gBAEjB,QAAQ,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;YACjC,CAAC,CAAC,CAAC;SACN;QAED,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,YAAY,EAAE;YAC9B,OAAO,IAAI,OAAO,CAAO,OAAO,CAAC,EAAE;gBAC/B,MAAM,cAAc,GAAG,MAAM,CAAC,MAAM,CAAC;gBACrC,MAAM,CAAC,MAAM,GAAG,CAAC,GAAG,IAAI,EAAE,EAAE;oBACxB,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,IAAI,CAAC,MAAM,EAAE,GAAG,IAAI,CAAC,CAAC;oBACtC,MAAM,CAAC,MAAM,GAAG,IAAI,CAAC;oBACrB,OAAO,EAAE,CAAC;gBACd,CAAC,CAAC;YACN,CAAC,CAAC,CAAC;SACN;QAED,OAAO,OAAO,CAAC,OAAO,EAAE,CAAC;IAC7B,CAAC,CAAC,CACL,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Log } from '@servicetitan/log-service';
|
|
2
|
+
import { BundleInfo } from './get-bundle-info';
|
|
3
|
+
export declare function validateBundleInfo({ mismatch }: BundleInfo, { logService, packageName }: {
|
|
4
|
+
logService?: Log;
|
|
5
|
+
packageName: string;
|
|
6
|
+
}): void;
|
|
7
|
+
//# sourceMappingURL=validate-bundle-info.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-bundle-info.d.ts","sourceRoot":"","sources":["../../src/utils/validate-bundle-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAChD,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,wBAAgB,kBAAkB,CAC9B,EAAE,QAAQ,EAAE,EAAE,UAAU,EACxB,EAAE,UAAU,EAAE,WAAW,EAAE,EAAE;IAAE,UAAU,CAAC,EAAE,GAAG,CAAC;IAAC,WAAW,EAAE,MAAM,CAAA;CAAE,QASzE"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function validateBundleInfo({ mismatch }, { logService, packageName }) {
|
|
2
|
+
if (mismatch) {
|
|
3
|
+
logService === null || logService === void 0 ? void 0 : logService.warning({
|
|
4
|
+
category: 'MicroFrontends.DependenciesMismatch',
|
|
5
|
+
message: 'Some of the package dependencies have incompatible versions.',
|
|
6
|
+
data: { package: packageName, dependencies: JSON.stringify(mismatch) },
|
|
7
|
+
});
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
//# sourceMappingURL=validate-bundle-info.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validate-bundle-info.js","sourceRoot":"","sources":["../../src/utils/validate-bundle-info.ts"],"names":[],"mappings":"AAGA,MAAM,UAAU,kBAAkB,CAC9B,EAAE,QAAQ,EAAc,EACxB,EAAE,UAAU,EAAE,WAAW,EAA6C;IAEtE,IAAI,QAAQ,EAAE;QACV,UAAU,aAAV,UAAU,uBAAV,UAAU,CAAE,OAAO,CAAC;YAChB,QAAQ,EAAE,qCAAqC;YAC/C,OAAO,EAAE,8DAA8D;YACvE,IAAI,EAAE,EAAE,OAAO,EAAE,WAAW,EAAE,YAAY,EAAE,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE;SACzE,CAAC,CAAC;KACN;AACL,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
import { Log } from '@servicetitan/log-service';
|
|
3
|
+
import { ExposedDependencies } from '../common';
|
|
4
|
+
import { EventBus } from '../event-bus';
|
|
5
|
+
import { BundleInfo } from './get-bundle-info';
|
|
6
|
+
import { LoaderDataProps } from '../loader';
|
|
7
|
+
interface WebComponentProps {
|
|
8
|
+
basename?: string;
|
|
9
|
+
bundleInfo: BundleInfo;
|
|
10
|
+
eventBus: EventBus;
|
|
11
|
+
exposedDependencies?: ExposedDependencies;
|
|
12
|
+
logService?: Log;
|
|
13
|
+
LoadingFallback: () => JSX.Element;
|
|
14
|
+
}
|
|
15
|
+
export declare function webComponent(props: WebComponentProps): (props: LoaderDataProps) => import("react/jsx-runtime").JSX.Element;
|
|
16
|
+
export {};
|
|
17
|
+
//# sourceMappingURL=web-component.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-component.d.ts","sourceRoot":"","sources":["../../src/utils/web-component.tsx"],"names":[],"mappings":";AACA,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAGhD,OAAO,EAAE,mBAAmB,EAAiB,MAAM,WAAW,CAAC;AAE/D,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,UAAU,iBAAiB;IACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,UAAU,EAAE,UAAU,CAAC;IACvB,QAAQ,EAAE,QAAQ,CAAC;IACnB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,eAAe,EAAE,MAAM,GAAG,CAAC,OAAO,CAAC;CACtC;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,WAKlC,eAAe,6CAmDjC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Fragment, useMemo, useState } from 'react';
|
|
3
|
+
import { useOptionalDependencies } from '@servicetitan/react-ioc';
|
|
4
|
+
import { HistoryManager } from '../history-manager';
|
|
5
|
+
export function webComponent(props) {
|
|
6
|
+
const { basename, bundleInfo, eventBus, exposedDependencies, logService, LoadingFallback } = props;
|
|
7
|
+
const { WebComponent, disposer, mfeSupportsRerendering } = bundleInfo;
|
|
8
|
+
return (props) => {
|
|
9
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
10
|
+
const [historyManager] = useOptionalDependencies(HistoryManager);
|
|
11
|
+
const handleRef = (webComponent) => {
|
|
12
|
+
webComponent === null || webComponent === void 0 ? void 0 : webComponent.provide({
|
|
13
|
+
logService,
|
|
14
|
+
historyManager,
|
|
15
|
+
exposedDependencies,
|
|
16
|
+
eventBus,
|
|
17
|
+
basename,
|
|
18
|
+
onReady: () => {
|
|
19
|
+
setIsLoading(false);
|
|
20
|
+
},
|
|
21
|
+
onDispose: () => {
|
|
22
|
+
disposer();
|
|
23
|
+
},
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
const stringifiedData = useMemo(() => JSON.stringify(props.data), [props.data]);
|
|
27
|
+
/*
|
|
28
|
+
* Set key for rendering the web component so that if the data from the Host change,
|
|
29
|
+
* and the MFE's version of startup doesn't support watching for data changes, then
|
|
30
|
+
* the web component will be re-mounted whenever the data changes.
|
|
31
|
+
* This is only used as a fallback when the MFE's version is older.
|
|
32
|
+
*/
|
|
33
|
+
const key = mfeSupportsRerendering ? undefined : stringifiedData;
|
|
34
|
+
const dataAttrs = useMemo(() => composeDataAttributes(props.data), [props.data]);
|
|
35
|
+
const styleUrls = getStyleUrls(bundleInfo);
|
|
36
|
+
return (_jsxs(Fragment, { children: [isLoading && _jsx(LoadingFallback, {}), _jsx(WebComponent, Object.assign({ ref: handleRef, class: props.className }, (styleUrls && { 'style-urls': styleUrls }), dataAttrs, { "data-mfe-data": stringifiedData }), key)] }));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/*
|
|
40
|
+
* Convert camelCase data props to kebab-case data attributes, prepended with data-
|
|
41
|
+
* Ex: fooBar -> data-foo-bar
|
|
42
|
+
*/
|
|
43
|
+
function composeDataAttributes(data = {}) {
|
|
44
|
+
return Object.fromEntries(Object.entries(data).map(([key, value]) => [
|
|
45
|
+
'data-' + key.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase()),
|
|
46
|
+
value,
|
|
47
|
+
]));
|
|
48
|
+
}
|
|
49
|
+
function getStyleUrls({ urls }) {
|
|
50
|
+
if (urls.css.length) {
|
|
51
|
+
return encodeURIComponent(JSON.stringify(urls.css));
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=web-component.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"web-component.js","sourceRoot":"","sources":["../../src/utils/web-component.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAEpD,OAAO,EAAE,uBAAuB,EAAE,MAAM,yBAAyB,CAAC;AAMlE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AAYpD,MAAM,UAAU,YAAY,CAAC,KAAwB;IACjD,MAAM,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE,mBAAmB,EAAE,UAAU,EAAE,eAAe,EAAE,GACtF,KAAK,CAAC;IACV,MAAM,EAAE,YAAY,EAAE,QAAQ,EAAE,sBAAsB,EAAE,GAAG,UAAU,CAAC;IAEtE,OAAO,CAAC,KAAsB,EAAE,EAAE;QAC9B,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC;QACjD,MAAM,CAAC,cAAc,CAAC,GAAG,uBAAuB,CAAC,cAAc,CAAC,CAAC;QAEjE,MAAM,SAAS,GAAG,CAAC,YAAkC,EAAE,EAAE;YACrD,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,OAAO,CAAC;gBAClB,UAAU;gBACV,cAAc;gBACd,mBAAmB;gBACnB,QAAQ;gBACR,QAAQ;gBACR,OAAO,EAAE,GAAG,EAAE;oBACV,YAAY,CAAC,KA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AAC;AAED,SAAS,YAAY,CAAC,EAAE,IAAI,EAA4B;IACpD,IAAI,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE;QACjB,OAAO,kBAAkB,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;KACvD;AACL,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@servicetitan/web-components",
|
|
3
|
-
"version": "23.
|
|
3
|
+
"version": "23.1.0",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -15,36 +15,35 @@
|
|
|
15
15
|
"src"
|
|
16
16
|
],
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@servicetitan/error-boundary": "23.
|
|
18
|
+
"@servicetitan/error-boundary": "23.1.0",
|
|
19
19
|
"lodash.get": "~4.4.2",
|
|
20
20
|
"mitt": "~3.0.1",
|
|
21
21
|
"semver": "~7.5.4"
|
|
22
22
|
},
|
|
23
23
|
"devDependencies": {
|
|
24
|
-
"@servicetitan/design-system": "~
|
|
25
|
-
"@servicetitan/log-service": "23.
|
|
26
|
-
"@servicetitan/react-ioc": "23.
|
|
24
|
+
"@servicetitan/design-system": "~14.0.0",
|
|
25
|
+
"@servicetitan/log-service": "23.1.0",
|
|
26
|
+
"@servicetitan/react-ioc": "23.1.0",
|
|
27
27
|
"@testing-library/dom": "^8.20.1",
|
|
28
28
|
"@testing-library/jest-dom": "^6.4.2",
|
|
29
|
-
"@testing-library/react": "^
|
|
30
|
-
"@testing-library/react-hooks": "^8.0.1",
|
|
29
|
+
"@testing-library/react": "^14.2.1",
|
|
31
30
|
"@types/history": "~4.7.10",
|
|
32
31
|
"@types/lodash.get": "~4.4.6",
|
|
33
|
-
"@types/react": "~
|
|
34
|
-
"@types/react-dom": "~
|
|
32
|
+
"@types/react": "~18.2.55",
|
|
33
|
+
"@types/react-dom": "~18.2.19",
|
|
35
34
|
"@types/semver": "~7.5.0",
|
|
36
35
|
"history": "~4.10.1",
|
|
37
|
-
"react": "~
|
|
38
|
-
"react-dom": "~
|
|
36
|
+
"react": "~18.2.0",
|
|
37
|
+
"react-dom": "~18.2.0",
|
|
39
38
|
"shadow-dom-testing-library": "^1.11.0"
|
|
40
39
|
},
|
|
41
40
|
"peerDependencies": {
|
|
42
|
-
"@servicetitan/design-system": "
|
|
43
|
-
"@servicetitan/log-service": "23.
|
|
44
|
-
"@servicetitan/react-ioc": "23.
|
|
41
|
+
"@servicetitan/design-system": ">=12.6.2",
|
|
42
|
+
"@servicetitan/log-service": "23.1.0",
|
|
43
|
+
"@servicetitan/react-ioc": "23.1.0",
|
|
45
44
|
"history": "~4.10.1",
|
|
46
|
-
"react": "
|
|
47
|
-
"react-dom": "
|
|
45
|
+
"react": ">=17.0.2",
|
|
46
|
+
"react-dom": ">=17.0.2"
|
|
48
47
|
},
|
|
49
48
|
"publishConfig": {
|
|
50
49
|
"access": "public"
|
|
@@ -52,5 +51,5 @@
|
|
|
52
51
|
"cli": {
|
|
53
52
|
"webpack": false
|
|
54
53
|
},
|
|
55
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "7267270e54cdb3a2926f61feb4939d057e82adb3"
|
|
56
55
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as mitt from 'mitt';
|
|
2
|
-
import { renderHook } from '@testing-library/react
|
|
2
|
+
import { renderHook } from '@testing-library/react';
|
|
3
3
|
import { useEventBus, EventBus } from '../event-bus';
|
|
4
4
|
|
|
5
5
|
jest.mock('mitt', () => jest.fn());
|
|
@@ -138,9 +138,10 @@ describe(`[web-components] ${useEventBus.name}`, () => {
|
|
|
138
138
|
test('when the component using useEventBus is re-rendered, useEventBus provides the same event bus instance', () => {
|
|
139
139
|
const { result, rerender } = subject();
|
|
140
140
|
|
|
141
|
+
const firstInstance = result.current;
|
|
141
142
|
rerender();
|
|
142
143
|
|
|
143
|
-
const
|
|
144
|
+
const secondInstance = result.current;
|
|
144
145
|
expect(firstInstance).toBe(secondInstance);
|
|
145
146
|
});
|
|
146
147
|
});
|
|
@@ -1,14 +1,20 @@
|
|
|
1
|
-
import { Metadata, Loader, LoaderProps } from '../loader';
|
|
2
|
-
import { act, render, screen, waitFor } from '@testing-library/react';
|
|
3
1
|
import '@testing-library/jest-dom';
|
|
4
|
-
import {
|
|
5
|
-
import * as common from '../common';
|
|
6
|
-
import * as utils from '../utils';
|
|
7
|
-
import { FC } from 'react';
|
|
8
|
-
import { Provider, ProviderProps } from '@servicetitan/react-ioc';
|
|
2
|
+
import { act, render, screen, waitFor } from '@testing-library/react';
|
|
9
3
|
import { Log } from '@servicetitan/log-service';
|
|
10
|
-
import {
|
|
4
|
+
import { Provider, ProviderProps } from '@servicetitan/react-ioc';
|
|
5
|
+
import { FC } from 'react';
|
|
6
|
+
|
|
7
|
+
import * as common from '../common';
|
|
8
|
+
import { Entries, EXPOSED_DEPENDENCIES_TOKEN } from '../common';
|
|
11
9
|
import { EVENT_BUS_TOKEN } from '../event-bus';
|
|
10
|
+
import { HistoryManager } from '../history-manager';
|
|
11
|
+
import { Loader, LoaderProps } from '../loader';
|
|
12
|
+
import { Metadata } from '../utils/get-bundle-info';
|
|
13
|
+
import { getVersionMismatches } from '../utils/get-version-mismatches';
|
|
14
|
+
|
|
15
|
+
jest.mock('../utils/get-version-mismatches', () => ({
|
|
16
|
+
getVersionMismatches: jest.fn(),
|
|
17
|
+
}));
|
|
12
18
|
|
|
13
19
|
describe('[web-components] Loader', () => {
|
|
14
20
|
const baseUrl = 'http://localhost/mfe';
|
|
@@ -108,7 +114,7 @@ describe('[web-components] Loader', () => {
|
|
|
108
114
|
}
|
|
109
115
|
return getJsonMockFns[url]();
|
|
110
116
|
});
|
|
111
|
-
jest.
|
|
117
|
+
jest.mocked(getVersionMismatches).mockReturnValue({});
|
|
112
118
|
});
|
|
113
119
|
|
|
114
120
|
function subject() {
|
|
@@ -249,7 +255,7 @@ describe('[web-components] Loader', () => {
|
|
|
249
255
|
|
|
250
256
|
test('dependencies are pulled from package.json', async () => {
|
|
251
257
|
await scriptLoadedSetup();
|
|
252
|
-
expect(
|
|
258
|
+
expect(getVersionMismatches).toHaveBeenCalledWith(
|
|
253
259
|
expect.anything(),
|
|
254
260
|
dependencies,
|
|
255
261
|
expect.anything()
|
|
@@ -586,7 +592,7 @@ describe('[web-components] Loader', () => {
|
|
|
586
592
|
};
|
|
587
593
|
|
|
588
594
|
beforeEach(() => {
|
|
589
|
-
jest.
|
|
595
|
+
jest.mocked(getVersionMismatches).mockReturnValue(mismatchedDeps);
|
|
590
596
|
});
|
|
591
597
|
|
|
592
598
|
itAddsJsEntrypointToWebComponent(
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import { renderHook } from '@testing-library/react
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { renderHook } from '@testing-library/react';
|
|
3
3
|
import { MFEDataContext, useMFEDataContext } from '../mfe-data-context';
|
|
4
4
|
|
|
5
5
|
describe(`[web-components] ${useMFEDataContext.name}`, () => {
|
|
@@ -7,7 +7,7 @@ describe(`[web-components] ${useMFEDataContext.name}`, () => {
|
|
|
7
7
|
|
|
8
8
|
describe('when the MFEDataContext is provided by a parent', () => {
|
|
9
9
|
const data = { foo: 'bar' };
|
|
10
|
-
const Wrapper: FC = ({ children }) => {
|
|
10
|
+
const Wrapper: FC<PropsWithChildren<{}>> = ({ children }) => {
|
|
11
11
|
return <MFEDataContext.Provider value={data}>{children}</MFEDataContext.Provider>;
|
|
12
12
|
};
|
|
13
13
|
|
|
@@ -17,7 +17,7 @@ describe(`[web-components] ${useMFEDataContext.name}`, () => {
|
|
|
17
17
|
});
|
|
18
18
|
|
|
19
19
|
describe('when the MFEDataContext is not provided by a parent', () => {
|
|
20
|
-
const Wrapper: FC = ({ children }) => {
|
|
20
|
+
const Wrapper: FC<PropsWithChildren<{}>> = ({ children }) => {
|
|
21
21
|
return <div>{children}</div>;
|
|
22
22
|
};
|
|
23
23
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { FC } from 'react';
|
|
2
|
-
import { renderHook } from '@testing-library/react
|
|
1
|
+
import { FC, PropsWithChildren } from 'react';
|
|
2
|
+
import { renderHook } from '@testing-library/react';
|
|
3
3
|
import { MFEMetadataContext, useMFEMetadataContext } from '../mfe-metadata-context';
|
|
4
4
|
|
|
5
5
|
describe(`[web-components] ${useMFEMetadataContext.name}`, () => {
|
|
@@ -9,7 +9,7 @@ describe(`[web-components] ${useMFEMetadataContext.name}`, () => {
|
|
|
9
9
|
const shadowRoot = document.createElement('div').attachShadow({ mode: 'open' });
|
|
10
10
|
const portalShadowRoot = document.createElement('span').attachShadow({ mode: 'open' });
|
|
11
11
|
const metadata = { shadowRoot, portalShadowRoot };
|
|
12
|
-
const Wrapper: FC = ({ children }) => {
|
|
12
|
+
const Wrapper: FC<PropsWithChildren<{}>> = ({ children }) => {
|
|
13
13
|
return (
|
|
14
14
|
<MFEMetadataContext.Provider value={metadata}>
|
|
15
15
|
{children}
|
|
@@ -23,7 +23,7 @@ describe(`[web-components] ${useMFEMetadataContext.name}`, () => {
|
|
|
23
23
|
});
|
|
24
24
|
|
|
25
25
|
describe('when the MFEMetadataContext is not provided by a parent', () => {
|
|
26
|
-
const Wrapper: FC = ({ children }) => {
|
|
26
|
+
const Wrapper: FC<PropsWithChildren<{}>> = ({ children }) => {
|
|
27
27
|
return <div>{children}</div>;
|
|
28
28
|
};
|
|
29
29
|
|