@servicetitan/web-components 36.1.1-beta.1 → 36.2.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/globals.d.ts +3 -3
- package/dist/globals.d.ts.map +1 -1
- package/dist/globals.js +4 -19
- package/dist/globals.js.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/dist/register-headless.d.ts.map +1 -1
- package/dist/register-headless.js +0 -1
- package/dist/register-headless.js.map +1 -1
- package/dist/register.d.ts.map +1 -1
- package/dist/register.js +36 -38
- package/dist/register.js.map +1 -1
- package/dist/render.d.ts.map +1 -1
- package/dist/render.js +11 -3
- package/dist/render.js.map +1 -1
- package/dist/utils/get-bundle-info.d.ts.map +1 -1
- package/dist/utils/get-bundle-info.js +4 -10
- package/dist/utils/get-bundle-info.js.map +1 -1
- package/dist/utils/get-entry-points.d.ts +0 -1
- package/dist/utils/get-entry-points.d.ts.map +1 -1
- package/dist/utils/get-entry-points.js.map +1 -1
- package/dist/utils/get-ld-service-token.d.ts +3 -2
- package/dist/utils/get-ld-service-token.d.ts.map +1 -1
- package/dist/utils/get-ld-service-token.js +7 -2
- package/dist/utils/get-ld-service-token.js.map +1 -1
- package/package.json +12 -21
- package/src/__mocks__/test-component.tsx +2 -9
- package/src/__tests__/event-bus-types.test.ts +2 -1
- package/src/__tests__/register-anvil2.test.tsx +64 -11
- package/src/globals.ts +10 -30
- package/src/index.ts +0 -1
- package/src/register-headless.ts +0 -1
- package/src/register.tsx +42 -48
- package/src/render.ts +14 -3
- package/src/utils/get-bundle-info.ts +5 -11
- package/src/utils/get-entry-points.ts +0 -1
- package/src/utils/get-ld-service-token.ts +10 -2
- package/dist/with-css-injector.d.ts +0 -3
- package/dist/with-css-injector.d.ts.map +0 -1
- package/dist/with-css-injector.js +0 -52
- package/dist/with-css-injector.js.map +0 -1
- package/src/__mocks__/register-anvil2-harness.tsx +0 -49
- package/src/__tests__/register-anvil2-optional.test.tsx +0 -32
- package/src/__tests__/with-css-injector.test.tsx +0 -152
- package/src/with-css-injector.tsx +0 -45
package/dist/globals.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ declare global {
|
|
|
5
5
|
export const EXPOSED_INSTANCE_DEPENDENCIES: ExposedInstanceDependencies | undefined;
|
|
6
6
|
export const WEB_COMPONENT_NAME: string | undefined;
|
|
7
7
|
}
|
|
8
|
-
declare const _EXPOSED_DEPENDENCIES:
|
|
9
|
-
declare const _WEB_COMPONENT_NAME:
|
|
10
|
-
declare const _EXPOSED_INSTANCE_DEPENDENCIES:
|
|
8
|
+
declare const _EXPOSED_DEPENDENCIES: ExposedDependencies | undefined;
|
|
9
|
+
declare const _WEB_COMPONENT_NAME: string | undefined;
|
|
10
|
+
declare const _EXPOSED_INSTANCE_DEPENDENCIES: ExposedInstanceDependencies | undefined;
|
|
11
11
|
export { _EXPOSED_DEPENDENCIES as EXPOSED_DEPENDENCIES, _EXPOSED_INSTANCE_DEPENDENCIES as EXPOSED_INSTANCE_DEPENDENCIES, _WEB_COMPONENT_NAME as WEB_COMPONENT_NAME, };
|
|
12
12
|
//# sourceMappingURL=globals.d.ts.map
|
package/dist/globals.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"globals.d.ts","sourceRoot":"","sources":["../src/globals.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAClE,OAAO,EAAE,2BAA2B,EAAE,MAAM,UAAU,CAAC;AAEvD,OAAO,CAAC,MAAM,CAAC;IACX,MAAM,CAAC,MAAM,oBAAoB,EAAE,mBAAmB,GAAG,SAAS,CAAC;IACnE,MAAM,CAAC,MAAM,6BAA6B,EAAE,2BAA2B,GAAG,SAAS,CAAC;IACpF,MAAM,CAAC,MAAM,kBAAkB,EAAE,MAAM,GAAG,SAAS,CAAC;CACvD;AAUD,QAAA,MAAM,qBAAqB,iCAEzB,CAAC;AAEH,QAAA,MAAM,mBAAmB,oBAEvB,CAAC;AAEH,QAAA,MAAM,8BAA8B,yCAElC,CAAC;AAEH,OAAO,EACH,qBAAqB,IAAI,oBAAoB,EAC7C,8BAA8B,IAAI,6BAA6B,EAC/D,mBAAmB,IAAI,kBAAkB,GAC5C,CAAC"}
|
package/dist/globals.js
CHANGED
|
@@ -1,33 +1,18 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/naming-convention */
|
|
2
|
-
/// <reference types="vite/client" /> — provides types for import.meta.env
|
|
3
|
-
var _get, _get1, _get2;
|
|
4
|
-
/*
|
|
5
|
-
* Safely access a value that may not exist. Returns undefined instead of
|
|
6
|
-
* throwing a ReferenceError. Used below to try global constants first
|
|
7
|
-
* (set by webpack DefinePlugin), then fall back to import.meta.env
|
|
8
|
-
* (set by Vite's define config). One of these will always be defined
|
|
9
|
-
* depending on which bundler built the code.
|
|
10
|
-
*/ function get(fetch) {
|
|
1
|
+
/* eslint-disable @typescript-eslint/naming-convention */ function get(fetch) {
|
|
11
2
|
try {
|
|
12
3
|
return fetch();
|
|
13
4
|
} catch (unused) {
|
|
14
5
|
return undefined;
|
|
15
6
|
}
|
|
16
7
|
}
|
|
17
|
-
const _EXPOSED_DEPENDENCIES =
|
|
8
|
+
const _EXPOSED_DEPENDENCIES = get(()=>{
|
|
18
9
|
return EXPOSED_DEPENDENCIES;
|
|
19
|
-
})) !== null && _get !== void 0 ? _get : get(()=>{
|
|
20
|
-
return import.meta.env.EXPOSED_DEPENDENCIES;
|
|
21
10
|
});
|
|
22
|
-
const _WEB_COMPONENT_NAME =
|
|
11
|
+
const _WEB_COMPONENT_NAME = get(()=>{
|
|
23
12
|
return WEB_COMPONENT_NAME;
|
|
24
|
-
})) !== null && _get1 !== void 0 ? _get1 : get(()=>{
|
|
25
|
-
return import.meta.env.WEB_COMPONENT_NAME;
|
|
26
13
|
});
|
|
27
|
-
const _EXPOSED_INSTANCE_DEPENDENCIES =
|
|
14
|
+
const _EXPOSED_INSTANCE_DEPENDENCIES = get(()=>{
|
|
28
15
|
return EXPOSED_INSTANCE_DEPENDENCIES;
|
|
29
|
-
})) !== null && _get2 !== void 0 ? _get2 : get(()=>{
|
|
30
|
-
return import.meta.env.EXPOSED_INSTANCE_DEPENDENCIES;
|
|
31
16
|
});
|
|
32
17
|
export { _EXPOSED_DEPENDENCIES as EXPOSED_DEPENDENCIES, _EXPOSED_INSTANCE_DEPENDENCIES as EXPOSED_INSTANCE_DEPENDENCIES, _WEB_COMPONENT_NAME as WEB_COMPONENT_NAME };
|
|
33
18
|
|
package/dist/globals.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/globals.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\
|
|
1
|
+
{"version":3,"sources":["../src/globals.ts"],"sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport { ExposedInstanceDependencies } from './common';\n\ndeclare global {\n export const EXPOSED_DEPENDENCIES: ExposedDependencies | undefined;\n export const EXPOSED_INSTANCE_DEPENDENCIES: ExposedInstanceDependencies | undefined;\n export const WEB_COMPONENT_NAME: string | undefined;\n}\n\nfunction get<T>(fetch: () => T) {\n try {\n return fetch();\n } catch {\n return undefined;\n }\n}\n\nconst _EXPOSED_DEPENDENCIES = get(() => {\n return EXPOSED_DEPENDENCIES;\n});\n\nconst _WEB_COMPONENT_NAME = get(() => {\n return WEB_COMPONENT_NAME;\n});\n\nconst _EXPOSED_INSTANCE_DEPENDENCIES = get(() => {\n return EXPOSED_INSTANCE_DEPENDENCIES;\n});\n\nexport {\n _EXPOSED_DEPENDENCIES as EXPOSED_DEPENDENCIES,\n _EXPOSED_INSTANCE_DEPENDENCIES as EXPOSED_INSTANCE_DEPENDENCIES,\n _WEB_COMPONENT_NAME as WEB_COMPONENT_NAME,\n};\n"],"names":["get","fetch","undefined","_EXPOSED_DEPENDENCIES","EXPOSED_DEPENDENCIES","_WEB_COMPONENT_NAME","WEB_COMPONENT_NAME","_EXPOSED_INSTANCE_DEPENDENCIES","EXPOSED_INSTANCE_DEPENDENCIES"],"mappings":"AAAA,uDAAuD,GAUvD,SAASA,IAAOC,KAAc;IAC1B,IAAI;QACA,OAAOA;IACX,EAAE,eAAM;QACJ,OAAOC;IACX;AACJ;AAEA,MAAMC,wBAAwBH,IAAI;IAC9B,OAAOI;AACX;AAEA,MAAMC,sBAAsBL,IAAI;IAC5B,OAAOM;AACX;AAEA,MAAMC,iCAAiCP,IAAI;IACvC,OAAOQ;AACX;AAEA,SACIL,yBAAyBC,oBAAoB,EAC7CG,kCAAkCC,6BAA6B,EAC/DH,uBAAuBC,kBAAkB,GAC3C"}
|
package/dist/index.d.ts
CHANGED
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAE/B,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,aAAa,CAAC;AAC5B,cAAc,6BAA6B,CAAC;AAC5C,cAAc,mBAAmB,CAAC;AAClC,cAAc,mBAAmB,CAAC;AAClC,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,qBAAqB,CAAC;AACpC,cAAc,gBAAgB,CAAC;AAE/B,YAAY,EAAE,IAAI,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC"}
|
package/dist/index.js
CHANGED
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './common';\nexport * from './contexts';\nexport * from './event-bus';\nexport * from './get-value-for-environment';\nexport * from './headless-loader';\nexport * from './history-manager';\nexport * from './loader';\nexport * from './register';\nexport * from './register-headless';\nexport * from './use-prefetch';\n\nexport type { JSON, JSONPrimitive, Serializable } from './types';\
|
|
1
|
+
{"version":3,"sources":["../src/index.ts"],"sourcesContent":["export * from './common';\nexport * from './contexts';\nexport * from './event-bus';\nexport * from './get-value-for-environment';\nexport * from './headless-loader';\nexport * from './history-manager';\nexport * from './loader';\nexport * from './register';\nexport * from './register-headless';\nexport * from './use-prefetch';\n\nexport type { JSON, JSONPrimitive, Serializable } from './types';\n"],"names":[],"mappings":"AAAA,cAAc,WAAW;AACzB,cAAc,aAAa;AAC3B,cAAc,cAAc;AAC5B,cAAc,8BAA8B;AAC5C,cAAc,oBAAoB;AAClC,cAAc,oBAAoB;AAClC,cAAc,WAAW;AACzB,cAAc,aAAa;AAC3B,cAAc,sBAAsB;AACpC,cAAc,iBAAiB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register-headless.d.ts","sourceRoot":"","sources":["../src/register-headless.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAiB,MAAM,UAAU,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"register-headless.d.ts","sourceRoot":"","sources":["../src/register-headless.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,OAAO,EAAiB,MAAM,UAAU,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEvC,KAAK,oBAAoB,CAAC,QAAQ,EAAE,SAAS,SAAS,QAAQ,GAAG,QAAQ,IAAI,IAAI,CAC7E,OAAO,EACP,WAAW,GAAG,YAAY,CAC7B,GAAG;IACA,QAAQ,CAAC,EAAE,SAAS,CAAC;IACrB,OAAO,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;CACpC,CAAC;AACF,MAAM,MAAM,gBAAgB,CAAC,QAAQ,GAAG,GAAG,EAAE,SAAS,SAAS,QAAQ,GAAG,QAAQ,IAAI,CAClF,MAAM,EAAE,oBAAoB,CAAC,QAAQ,EAAE,SAAS,CAAC,KAChD,IAAI,CAAC;AAEV,wBAAgB,gBAAgB,CAC5B,iBAAiB,CAAC,EAAE,gBAAgB,EACpC,oBAAoB,CAAC,EAAE,gBAAgB,QAmE1C"}
|
|
@@ -11,7 +11,6 @@ function _define_property(obj, key, value) {
|
|
|
11
11
|
}
|
|
12
12
|
return obj;
|
|
13
13
|
}
|
|
14
|
-
import { WEB_COMPONENT_NAME } from './globals';
|
|
15
14
|
export function registerHeadless(connectedCallback, disconnectedCallback) {
|
|
16
15
|
class Headless extends HTMLElement {
|
|
17
16
|
async connectedCallback() {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/register-headless.ts"],"sourcesContent":["import type { LDService } from '@servicetitan/launchdarkly-service';\nimport type { Log } from '@servicetitan/log-service';\nimport type { Entries, IWebComponent } from './common';\nimport type { EventBus } from './event-bus';\nimport {
|
|
1
|
+
{"version":3,"sources":["../src/register-headless.ts"],"sourcesContent":["import type { LDService } from '@servicetitan/launchdarkly-service';\nimport type { Log } from '@servicetitan/log-service';\nimport type { Entries, IWebComponent } from './common';\nimport type { EventBus } from './event-bus';\nimport { Serializable } from './types';\n\ntype HeadlessCallbackArgs<TMfeData, TEventBus extends EventBus = EventBus> = Pick<\n Entries,\n 'ldService' | 'logService'\n> & {\n eventBus?: TEventBus;\n mfeData?: Serializable<TMfeData>;\n};\nexport type HeadlessCallback<TMfeData = any, TEventBus extends EventBus = EventBus> = (\n params: HeadlessCallbackArgs<TMfeData, TEventBus>\n) => void;\n\nexport function registerHeadless(\n connectedCallback?: HeadlessCallback,\n disconnectedCallback?: HeadlessCallback\n) {\n class Headless extends HTMLElement implements IWebComponent {\n private ldService?: LDService;\n private logService?: Log;\n private eventBus?: EventBus;\n private readonly readyPromise: Promise<void>;\n private resolveReadyPromise!: () => void;\n\n constructor() {\n super();\n this.readyPromise = new Promise(resolve => {\n this.resolveReadyPromise = resolve;\n });\n }\n\n provide = (entries: Entries) => {\n this.ldService = entries.ldService;\n this.logService = entries.logService;\n this.eventBus = entries.eventBus;\n this.resolveReadyPromise();\n };\n\n async connectedCallback() {\n await this.readyPromise;\n connectedCallback?.({\n ...this.services,\n mfeData: this.mfeData,\n });\n }\n\n async disconnectedCallback() {\n await this.readyPromise;\n disconnectedCallback?.({\n ...this.services,\n mfeData: this.mfeData,\n });\n }\n\n connectedMoveCallback() {\n /*\n * Defining connectedMoveCallback prevents connectedCallback or disconnectedCallback\n * from running when the element is moved in the DOM\n * https://developer.mozilla.org/en-US/docs/Web/API/Web_components/Using_custom_elements#custom_element_lifecycle_callbacks\n */\n }\n\n private get services() {\n return {\n ldService: this.ldService,\n logService: this.logService,\n eventBus: this.eventBus,\n };\n }\n\n private get mfeData() {\n return JSON.parse(this.dataset.mfeData ?? '{}');\n }\n }\n\n if (!WEB_COMPONENT_NAME) {\n // eslint-disable-next-line no-console\n console.error('\"WEB_COMPONENT_NAME\" is not defined!');\n return;\n }\n\n window.customElements.define(`headless-${WEB_COMPONENT_NAME}`, Headless);\n}\n"],"names":["registerHeadless","connectedCallback","disconnectedCallback","Headless","HTMLElement","readyPromise","services","mfeData","connectedMoveCallback","ldService","logService","eventBus","JSON","parse","dataset","resolveReadyPromise","provide","entries","Promise","resolve","WEB_COMPONENT_NAME","console","error","window","customElements","define"],"mappings":";;;;;;;;;;;;;AAiBA,OAAO,SAASA,iBACZC,iBAAoC,EACpCC,oBAAuC;IAEvC,MAAMC,iBAAiBC;QAqBnB,MAAMH,oBAAoB;YACtB,MAAM,IAAI,CAACI,YAAY;YACvBJ,8BAAAA,wCAAAA,kBAAoB;gBAChB,GAAG,IAAI,CAACK,QAAQ;gBAChBC,SAAS,IAAI,CAACA,OAAO;YACzB;QACJ;QAEA,MAAML,uBAAuB;YACzB,MAAM,IAAI,CAACG,YAAY;YACvBH,iCAAAA,2CAAAA,qBAAuB;gBACnB,GAAG,IAAI,CAACI,QAAQ;gBAChBC,SAAS,IAAI,CAACA,OAAO;YACzB;QACJ;QAEAC,wBAAwB;QACpB;;;;aAIC,GACL;QAEA,IAAYF,WAAW;YACnB,OAAO;gBACHG,WAAW,IAAI,CAACA,SAAS;gBACzBC,YAAY,IAAI,CAACA,UAAU;gBAC3BC,UAAU,IAAI,CAACA,QAAQ;YAC3B;QACJ;QAEA,IAAYJ,UAAU;gBACA;YAAlB,OAAOK,KAAKC,KAAK,EAAC,wBAAA,IAAI,CAACC,OAAO,CAACP,OAAO,cAApB,mCAAA,wBAAwB;QAC9C;QAhDA,aAAc;YACV,KAAK,IAPT,uBAAQE,aAAR,KAAA,IACA,uBAAQC,cAAR,KAAA,IACA,uBAAQC,YAAR,KAAA,IACA,uBAAiBN,gBAAjB,KAAA,IACA,uBAAQU,uBAAR,KAAA,IASAC,uBAAAA,WAAU,CAACC;gBACP,IAAI,CAACR,SAAS,GAAGQ,QAAQR,SAAS;gBAClC,IAAI,CAACC,UAAU,GAAGO,QAAQP,UAAU;gBACpC,IAAI,CAACC,QAAQ,GAAGM,QAAQN,QAAQ;gBAChC,IAAI,CAACI,mBAAmB;YAC5B;YAVI,IAAI,CAACV,YAAY,GAAG,IAAIa,QAAQC,CAAAA;gBAC5B,IAAI,CAACJ,mBAAmB,GAAGI;YAC/B;QACJ;IA4CJ;IAEA,IAAI,CAACC,oBAAoB;QACrB,sCAAsC;QACtCC,QAAQC,KAAK,CAAC;QACd;IACJ;IAEAC,OAAOC,cAAc,CAACC,MAAM,CAAC,CAAC,SAAS,EAAEL,oBAAoB,EAAEjB;AACnE"}
|
package/dist/register.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"register.d.ts","sourceRoot":"","sources":["../src/register.tsx"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAA+B,MAAM,OAAO,CAAC;AAiCnE,MAAM,WAAW,eAAe;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,uBAAuB,CAAC,EAAE,MAAM,EAAE,CAAC;CACtC;AAED,wBAAgB,QAAQ,CAAC,SAAS,EAAE,aAAa,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,eAAe,QAkP3F"}
|
package/dist/register.js
CHANGED
|
@@ -12,11 +12,9 @@ function _define_property(obj, key, value) {
|
|
|
12
12
|
return obj;
|
|
13
13
|
}
|
|
14
14
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
15
|
-
import * as Anvil2 from '@servicetitan/anvil2';
|
|
16
|
-
import * as Anvil1 from '@servicetitan/design-system';
|
|
17
15
|
import { Log } from '@servicetitan/log-service';
|
|
18
16
|
import { Provider } from '@servicetitan/react-ioc';
|
|
19
|
-
import {
|
|
17
|
+
import { useEffect } from 'react';
|
|
20
18
|
import { BASENAME_TOKEN, EXPOSED_DEPENDENCIES_TOKEN, EXPOSED_INSTANCE_DEPENDENCIES_TOKEN, IS_WEB_COMPONENT_TOKEN, RENDER_ROOT_TOKEN } from './common';
|
|
21
19
|
import { MFEDataContext } from './contexts/mfe-data-context';
|
|
22
20
|
import { MFEMetadataContext } from './contexts/mfe-metadata-context';
|
|
@@ -39,33 +37,6 @@ const Placeholder = ()=>/*#__PURE__*/ _jsx("div", {
|
|
|
39
37
|
display: 'none'
|
|
40
38
|
}
|
|
41
39
|
});
|
|
42
|
-
const Anvil1Providers = ({ root, portal, children })=>{
|
|
43
|
-
const getTablePopupProps = useCallback((props)=>({
|
|
44
|
-
...props,
|
|
45
|
-
appendTo: root
|
|
46
|
-
}), [
|
|
47
|
-
root
|
|
48
|
-
]);
|
|
49
|
-
if (Anvil1.DefaultPortalContext === undefined || Anvil1.TablePopupPropsContext === undefined) {
|
|
50
|
-
return children;
|
|
51
|
-
}
|
|
52
|
-
return /*#__PURE__*/ _jsx(Anvil1.DefaultPortalContext.Provider, {
|
|
53
|
-
value: portal,
|
|
54
|
-
children: /*#__PURE__*/ _jsx(Anvil1.TablePopupPropsContext.Provider, {
|
|
55
|
-
value: getTablePopupProps,
|
|
56
|
-
children: children
|
|
57
|
-
})
|
|
58
|
-
});
|
|
59
|
-
};
|
|
60
|
-
const Anvil2Providers = ({ portalAnvilContainer, children })=>{
|
|
61
|
-
if (Anvil2.PortalProvider === undefined) {
|
|
62
|
-
return children;
|
|
63
|
-
}
|
|
64
|
-
return /*#__PURE__*/ _jsx(Anvil2.PortalProvider, {
|
|
65
|
-
root: portalAnvilContainer,
|
|
66
|
-
children: children
|
|
67
|
-
});
|
|
68
|
-
};
|
|
69
40
|
export function register(Component, light, options) {
|
|
70
41
|
class WebComponent extends HTMLElement {
|
|
71
42
|
connectedCallback() {
|
|
@@ -132,15 +103,42 @@ export function register(Component, light, options) {
|
|
|
132
103
|
attributeChangedCallback() {
|
|
133
104
|
this.render();
|
|
134
105
|
}
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
106
|
+
withAnvil1Providers(children) {
|
|
107
|
+
try {
|
|
108
|
+
/**
|
|
109
|
+
* Note, the webpack.IgnorePlugin must be configured to ignore this dependency.
|
|
110
|
+
* @see {@link file://./../../startup/src/webpack/configs/plugins/ignore-plugin/ignore-plugin.ts}
|
|
111
|
+
*/ const { DefaultPortalContext, TablePopupPropsContext } = require('@servicetitan/design-system');
|
|
112
|
+
return /*#__PURE__*/ _jsx(DefaultPortalContext.Provider, {
|
|
113
|
+
value: this.portal,
|
|
114
|
+
children: /*#__PURE__*/ _jsx(TablePopupPropsContext.Provider, {
|
|
115
|
+
value: (props)=>({
|
|
116
|
+
...props,
|
|
117
|
+
appendTo: this.root
|
|
118
|
+
}),
|
|
119
|
+
children: children
|
|
120
|
+
})
|
|
121
|
+
});
|
|
122
|
+
} catch (unused) {
|
|
123
|
+
return children;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
withAnvil2Providers(children) {
|
|
127
|
+
try {
|
|
128
|
+
/**
|
|
129
|
+
* Note, the webpack.IgnorePlugin must be configured to ignore this dependency.
|
|
130
|
+
* @see {@link file://./../../startup/src/webpack/configs/plugins/ignore-plugin/ignore-plugin.ts}
|
|
131
|
+
*/ const { PortalProvider } = require('@servicetitan/anvil2');
|
|
132
|
+
return /*#__PURE__*/ _jsx(PortalProvider, {
|
|
133
|
+
root: this.portalAnvilContainer,
|
|
141
134
|
children: children
|
|
142
|
-
})
|
|
143
|
-
})
|
|
135
|
+
});
|
|
136
|
+
} catch (unused) {
|
|
137
|
+
return children;
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
withProviders(children) {
|
|
141
|
+
return this.withAnvil2Providers(this.withAnvil1Providers(children));
|
|
144
142
|
}
|
|
145
143
|
constructor(...args){
|
|
146
144
|
super(...args), _define_property(this, "root", void 0), _define_property(this, "portal", void 0), _define_property(this, "portalAnvilContainer", void 0), _define_property(this, "styles", {
|
package/dist/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/register.tsx"],"sourcesContent":["import * as Anvil2 from '@servicetitan/anvil2';\nimport * as Anvil1 from '@servicetitan/design-system';\nimport { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { Provider } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport { ComponentType, FC, PropsWithChildren, ReactElement, useCallback, useEffect } from 'react';\nimport {\n BASENAME_TOKEN,\n Entries,\n EXPOSED_DEPENDENCIES_TOKEN,\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,\n ExposedInstanceDependencies,\n IS_WEB_COMPONENT_TOKEN,\n IWebComponent,\n RENDER_ROOT_TOKEN,\n} from './common';\nimport { MFEDataContext } from './contexts/mfe-data-context';\nimport { MFEMetadataContext } from './contexts/mfe-metadata-context';\nimport { EVENT_BUS_TOKEN, EventBus } from './event-bus';\nimport { WEB_COMPONENT_NAME } from './globals';\nimport { HistoryManager } from './history-manager';\nimport { render } from './render';\nimport { getElementName, getLDServiceToken } from './utils';\n\nfunction createLink(url: string, onLoad: () => void) {\n const element = document.createElement('link');\n\n element.href = url;\n element.rel = 'stylesheet';\n element.crossOrigin = 'anonymous';\n element.onload = onLoad;\n element.onerror = onLoad;\n\n return element;\n}\n\nconst Placeholder: FC = () => <div style={{ display: 'none' }} />;\n\nexport interface RegisterOptions {\n legacyRoot?: boolean;\n sharedDependenciesNames?: string[];\n}\n\nconst Anvil1Providers: FC<{ root: ShadowRoot; portal: ShadowRoot } & PropsWithChildren> = ({\n root,\n portal,\n children,\n}) => {\n const getTablePopupProps = useCallback(\n (props: object) => ({\n ...props,\n appendTo: root as unknown as HTMLElement,\n }),\n [root]\n );\n\n if (Anvil1.DefaultPortalContext === undefined || Anvil1.TablePopupPropsContext === undefined) {\n return children;\n }\n\n return (\n <Anvil1.DefaultPortalContext.Provider value={portal as unknown as HTMLElement}>\n <Anvil1.TablePopupPropsContext.Provider value={getTablePopupProps}>\n {children}\n </Anvil1.TablePopupPropsContext.Provider>\n </Anvil1.DefaultPortalContext.Provider>\n );\n};\n\nconst Anvil2Providers: FC<{ portalAnvilContainer: HTMLDivElement } & PropsWithChildren> = ({\n portalAnvilContainer,\n children,\n}) => {\n if (Anvil2.PortalProvider === undefined) {\n return children;\n }\n\n return <Anvil2.PortalProvider root={portalAnvilContainer}>{children}</Anvil2.PortalProvider>;\n};\n\nexport function register(Component: ComponentType, light: boolean, options?: RegisterOptions) {\n class WebComponent extends HTMLElement implements IWebComponent {\n private root?: ShadowRoot;\n private portal?: ShadowRoot;\n private portalAnvilContainer?: HTMLDivElement;\n\n private styles: {\n total: number;\n loaded: number;\n elements: HTMLElement[];\n } = { total: 0, loaded: 0, elements: [] };\n\n private ldService?: LDService;\n private logService?: Log;\n private historyManager?: HistoryManager;\n private exposedDependencies?: ExposedDependencies;\n private exposedInstanceDependencies?: ExposedInstanceDependencies;\n private eventBus?: EventBus;\n private basename?: string;\n private onReady?: () => void;\n private onDispose?: () => void;\n private view?: ReturnType<typeof render>;\n\n connectedCallback() {\n /*\n * connectedCallback can be called when DOM element has moved\n * check that root is still connected to the DOM\n * if that's the case we don't need to reconnect MFE\n */\n if (this.root?.isConnected) {\n return;\n }\n const sharedDependenciesNames = options?.sharedDependenciesNames ?? [];\n const styleUrls = getStyleUrls(light, sharedDependenciesNames, this);\n\n this.styles = {\n total: styleUrls.length * 2,\n loaded: 0,\n elements: [],\n };\n\n this.root = this.shadowRoot ?? this.attachShadow({ mode: 'open' });\n /*\n * Portal shadow dom is created at the bottom of the body in order to be used as\n * the element for the design system components to attach modals and popups to.\n * This element is passed down the tree through context, and used within\n * the design system components.\n */\n const portalElement = document.createElement('div');\n portalElement.setAttribute(\n 'data-mfe-portal-name',\n getElementName({ WebComponent: WEB_COMPONENT_NAME! })\n );\n this.portal = document.body.appendChild(portalElement).attachShadow({ mode: 'open' });\n /*\n * Add element inside of portal so that Anvil 2 can attach modals and popups to it\n * since floating-ui does not support attaching straight to shadow dom\n */\n this.portalAnvilContainer = document.createElement('div');\n this.portal.appendChild(this.portalAnvilContainer);\n\n this.view = render(<Placeholder />, this.root, options);\n\n this.styles.elements.push(\n ...this.attachStyles(this.root, styleUrls),\n ...this.attachStyles(this.portal, styleUrls)\n );\n }\n\n disconnectedCallback() {\n if (!this.root || this.root.isConnected) {\n return;\n }\n for (const element of this.styles.elements) {\n element.remove();\n }\n\n this.view?.unmount();\n document.body?.removeChild(this.portal!.host);\n this.root = undefined;\n this.portal = undefined;\n this.portalAnvilContainer = undefined;\n\n this.onDispose?.();\n }\n\n // Observe changes to the data-mfe-data attribute so that we can re-render when it changes\n static get observedAttributes() {\n return ['data-mfe-data'];\n }\n\n attributeChangedCallback() {\n this.render();\n }\n\n provide = (entries: Entries) => {\n for (const [key, value] of Object.entries(entries)) {\n this[key as keyof IWebComponent] = value;\n }\n\n if (this.styles.loaded === this.styles.total) {\n this.render();\n }\n };\n\n private handleLoad = () => {\n this.styles.loaded++;\n\n if (this.styles.loaded === this.styles.total) {\n this.render();\n }\n };\n\n private attachStyles = (node: ShadowRoot, urls: string[]) => {\n const elements: HTMLElement[] = [];\n\n for (const url of urls) {\n const element = createLink(url, this.handleLoad);\n node.appendChild(element);\n elements.push(element);\n }\n\n return elements;\n };\n\n private withProviders(children: ReactElement) {\n return (\n <Anvil2Providers portalAnvilContainer={this.portalAnvilContainer!}>\n <Anvil1Providers root={this.root!} portal={this.portal!}>\n {children}\n </Anvil1Providers>\n </Anvil2Providers>\n );\n }\n\n private render = () => {\n /*\n * Check for this.root first, otherwise we get error when\n * attributeChangedCallback happens on load\n */\n if (this.root) {\n const mfeData = this.dataset.mfeData\n ? /*\n * Data was stringified in order to come through the data-mfe-data attribute\n * So we must JSON.parse it here to get an object back\n */\n JSON.parse(this.dataset.mfeData)\n : /*\n * If mfeData isn't there, then the Host may not be up to date with web-components\n * and is instead passing data through separate data-attributes, so we want to\n * spread all of those instead\n */\n { ...this.dataset };\n\n const metadata = {\n shadowRoot: this.root,\n portalShadowRoot: this.portal!,\n };\n\n this.view?.rerender(\n <Provider\n singletons={[\n { provide: IS_WEB_COMPONENT_TOKEN, useValue: true },\n { provide: RENDER_ROOT_TOKEN, useValue: this.root },\n ]}\n >\n <Provider\n singletons={[\n { provide: Log, useValue: this.logService },\n {\n provide: HistoryManager,\n useValue: this.historyManager,\n },\n {\n provide: EXPOSED_DEPENDENCIES_TOKEN,\n useValue: this.exposedDependencies,\n },\n {\n provide: EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,\n useValue: this.exposedInstanceDependencies,\n },\n { provide: BASENAME_TOKEN, useValue: this.basename },\n { provide: EVENT_BUS_TOKEN, useValue: this.eventBus },\n { provide: getLDServiceToken(), useValue: this.ldService },\n ].filter(\n ({ provide, useValue }) =>\n useValue !== undefined && provide !== undefined\n )}\n >\n <MFEDataContext.Provider value={{ ...mfeData }}>\n <MFEMetadataContext.Provider value={metadata}>\n {this.withProviders(<Component {...mfeData} />)}\n {this.onReady && <RenderCallback callback={this.onReady} />}\n </MFEMetadataContext.Provider>\n </MFEDataContext.Provider>\n </Provider>\n </Provider>\n );\n }\n };\n }\n\n if (!WEB_COMPONENT_NAME) {\n // eslint-disable-next-line no-console\n console.error('\"WEB_COMPONENT_NAME\" is not defined!');\n return;\n }\n\n window.customElements.define(WEB_COMPONENT_NAME, WebComponent);\n}\n\nfunction getStyleUrls(light: boolean, sharedDependenciesNames: string[], el: HTMLElement) {\n function getCssUrl(dependencyName: string, cssFileRegEx: RegExp) {\n if (light && sharedDependenciesNames.includes(dependencyName)) {\n return Array.from(document.getElementsByTagName('link')).find(\n ({ href }) => href && cssFileRegEx.test(href)\n )?.href;\n }\n }\n\n const designSystemUrl = getCssUrl(\n '@servicetitan/design-system',\n /design-system(\\..+)?\\.bundle\\.css/\n );\n const anvil2CssUrl = getCssUrl('@servicetitan/anvil2', /anvil2(\\..+)?\\.bundle\\.css/);\n\n return [\n ...(designSystemUrl ? [designSystemUrl] : []),\n ...(anvil2CssUrl ? [anvil2CssUrl] : []),\n ...(el.hasAttribute('style-urls')\n ? JSON.parse(decodeURIComponent(el.getAttribute('style-urls')!))\n : []),\n ];\n}\n\nfunction RenderCallback({ callback }: { callback: () => void }) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => callback(), []);\n return null;\n}\n"],"names":["Anvil2","Anvil1","Log","Provider","useCallback","useEffect","BASENAME_TOKEN","EXPOSED_DEPENDENCIES_TOKEN","EXPOSED_INSTANCE_DEPENDENCIES_TOKEN","IS_WEB_COMPONENT_TOKEN","RENDER_ROOT_TOKEN","MFEDataContext","MFEMetadataContext","EVENT_BUS_TOKEN","WEB_COMPONENT_NAME","HistoryManager","render","getElementName","getLDServiceToken","createLink","url","onLoad","element","document","createElement","href","rel","crossOrigin","onload","onerror","Placeholder","div","style","display","Anvil1Providers","root","portal","children","getTablePopupProps","props","appendTo","DefaultPortalContext","undefined","TablePopupPropsContext","value","Anvil2Providers","portalAnvilContainer","PortalProvider","register","Component","light","options","WebComponent","HTMLElement","connectedCallback","isConnected","sharedDependenciesNames","styleUrls","getStyleUrls","styles","total","length","loaded","elements","shadowRoot","attachShadow","mode","portalElement","setAttribute","body","appendChild","view","push","attachStyles","disconnectedCallback","remove","unmount","removeChild","host","onDispose","observedAttributes","attributeChangedCallback","withProviders","ldService","logService","historyManager","exposedDependencies","exposedInstanceDependencies","eventBus","basename","onReady","provide","entries","key","Object","handleLoad","node","urls","mfeData","dataset","JSON","parse","metadata","portalShadowRoot","rerender","singletons","useValue","filter","RenderCallback","callback","console","error","window","customElements","define","el","getCssUrl","dependencyName","cssFileRegEx","includes","Array","from","getElementsByTagName","find","test","designSystemUrl","anvil2CssUrl","hasAttribute","decodeURIComponent","getAttribute"],"mappings":";;;;;;;;;;;;;;AAAA,YAAYA,YAAY,uBAAuB;AAC/C,YAAYC,YAAY,8BAA8B;AAEtD,SAASC,GAAG,QAAQ,4BAA4B;AAChD,SAASC,QAAQ,QAAQ,0BAA0B;AAEnD,SAA6DC,WAAW,EAAEC,SAAS,QAAQ,QAAQ;AACnG,SACIC,cAAc,EAEdC,0BAA0B,EAC1BC,mCAAmC,EAEnCC,sBAAsB,EA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QAAOA,mBAAAA,MAAMC,IAAI,CAAClG,SAASmG,oBAAoB,CAAC,SAASC,IAAI,CACzD,CAAC,EAAElG,IAAI,EAAE,GAAKA,QAAQ6F,aAAaM,IAAI,CAACnG,oBADrC+F,uCAAAA,iBAEJ/F,IAAI;QACX;IACJ;IAEA,MAAMoG,kBAAkBT,UACpB,+BACA;IAEJ,MAAMU,eAAeV,UAAU,wBAAwB;IAEvD,OAAO;WACCS,kBAAkB;YAACA;SAAgB,GAAG,EAAE;WACxCC,eAAe;YAACA;SAAa,GAAG,EAAE;WAClCX,GAAGY,YAAY,CAAC,gBACd3B,KAAKC,KAAK,CAAC2B,mBAAmBb,GAAGc,YAAY,CAAC,kBAC9C,EAAE;KACX;AACL;AAEA,SAASrB,eAAe,EAAEC,QAAQ,EAA4B;IAC1D,uDAAuD;IACvDxG,UAAU,IAAMwG,YAAY,EAAE;IAC9B,OAAO;AACX"}
|
|
1
|
+
{"version":3,"sources":["../src/register.tsx"],"sourcesContent":["import { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { Provider } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport { ComponentType, FC, ReactElement, useEffect } from 'react';\nimport {\n BASENAME_TOKEN,\n Entries,\n EXPOSED_DEPENDENCIES_TOKEN,\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,\n ExposedInstanceDependencies,\n IS_WEB_COMPONENT_TOKEN,\n IWebComponent,\n RENDER_ROOT_TOKEN,\n} from './common';\nimport { MFEDataContext } from './contexts/mfe-data-context';\nimport { MFEMetadataContext } from './contexts/mfe-metadata-context';\nimport { EVENT_BUS_TOKEN, EventBus } from './event-bus';\nimport { WEB_COMPONENT_NAME } from './globals';\nimport { HistoryManager } from './history-manager';\nimport { render } from './render';\nimport { getElementName, getLDServiceToken } from './utils';\n\nfunction createLink(url: string, onLoad: () => void) {\n const element = document.createElement('link');\n\n element.href = url;\n element.rel = 'stylesheet';\n element.crossOrigin = 'anonymous';\n element.onload = onLoad;\n element.onerror = onLoad;\n\n return element;\n}\n\nconst Placeholder: FC = () => <div style={{ display: 'none' }} />;\n\nexport interface RegisterOptions {\n legacyRoot?: boolean;\n sharedDependenciesNames?: string[];\n}\n\nexport function register(Component: ComponentType, light: boolean, options?: RegisterOptions) {\n class WebComponent extends HTMLElement implements IWebComponent {\n private root?: ShadowRoot;\n private portal?: ShadowRoot;\n private portalAnvilContainer?: HTMLDivElement;\n\n private styles: {\n total: number;\n loaded: number;\n elements: HTMLElement[];\n } = { total: 0, loaded: 0, elements: [] };\n\n private ldService?: LDService;\n private logService?: Log;\n private historyManager?: HistoryManager;\n private exposedDependencies?: ExposedDependencies;\n private exposedInstanceDependencies?: ExposedInstanceDependencies;\n private eventBus?: EventBus;\n private basename?: string;\n private onReady?: () => void;\n private onDispose?: () => void;\n private view?: ReturnType<typeof render>;\n\n connectedCallback() {\n /*\n * connectedCallback can be called when DOM element has moved\n * check that root is still connected to the DOM\n * if that's the case we don't need to reconnect MFE\n */\n if (this.root?.isConnected) {\n return;\n }\n const sharedDependenciesNames = options?.sharedDependenciesNames ?? [];\n const styleUrls = getStyleUrls(light, sharedDependenciesNames, this);\n\n this.styles = {\n total: styleUrls.length * 2,\n loaded: 0,\n elements: [],\n };\n\n this.root = this.shadowRoot ?? this.attachShadow({ mode: 'open' });\n /*\n * Portal shadow dom is created at the bottom of the body in order to be used as\n * the element for the design system components to attach modals and popups to.\n * This element is passed down the tree through context, and used within\n * the design system components.\n */\n const portalElement = document.createElement('div');\n portalElement.setAttribute(\n 'data-mfe-portal-name',\n getElementName({ WebComponent: WEB_COMPONENT_NAME! })\n );\n this.portal = document.body.appendChild(portalElement).attachShadow({ mode: 'open' });\n /*\n * Add element inside of portal so that Anvil 2 can attach modals and popups to it\n * since floating-ui does not support attaching straight to shadow dom\n */\n this.portalAnvilContainer = document.createElement('div');\n this.portal.appendChild(this.portalAnvilContainer);\n\n this.view = render(<Placeholder />, this.root, options);\n\n this.styles.elements.push(\n ...this.attachStyles(this.root, styleUrls),\n ...this.attachStyles(this.portal, styleUrls)\n );\n }\n\n disconnectedCallback() {\n if (!this.root || this.root.isConnected) {\n return;\n }\n for (const element of this.styles.elements) {\n element.remove();\n }\n\n this.view?.unmount();\n document.body?.removeChild(this.portal!.host);\n this.root = undefined;\n this.portal = undefined;\n this.portalAnvilContainer = undefined;\n\n this.onDispose?.();\n }\n\n // Observe changes to the data-mfe-data attribute so that we can re-render when it changes\n static get observedAttributes() {\n return ['data-mfe-data'];\n }\n\n attributeChangedCallback() {\n this.render();\n }\n\n provide = (entries: Entries) => {\n for (const [key, value] of Object.entries(entries)) {\n this[key as keyof IWebComponent] = value;\n }\n\n if (this.styles.loaded === this.styles.total) {\n this.render();\n }\n };\n\n private handleLoad = () => {\n this.styles.loaded++;\n\n if (this.styles.loaded === this.styles.total) {\n this.render();\n }\n };\n\n private attachStyles = (node: ShadowRoot, urls: string[]) => {\n const elements: HTMLElement[] = [];\n\n for (const url of urls) {\n const element = createLink(url, this.handleLoad);\n node.appendChild(element);\n elements.push(element);\n }\n\n return elements;\n };\n\n private withAnvil1Providers(children: ReactElement): ReactElement {\n try {\n /**\n * Note, the webpack.IgnorePlugin must be configured to ignore this dependency.\n * @see {@link file://./../../startup/src/webpack/configs/plugins/ignore-plugin/ignore-plugin.ts}\n */\n const { DefaultPortalContext, TablePopupPropsContext } =\n require('@servicetitan/design-system') as typeof import('@servicetitan/design-system');\n return (\n <DefaultPortalContext.Provider value={this.portal as unknown as HTMLElement}>\n <TablePopupPropsContext.Provider\n value={props => ({\n ...props,\n appendTo: this.root as unknown as HTMLElement,\n })}\n >\n {children}\n </TablePopupPropsContext.Provider>\n </DefaultPortalContext.Provider>\n );\n } catch {\n return children;\n }\n }\n\n private withAnvil2Providers(children: ReactElement): ReactElement {\n try {\n /**\n * Note, the webpack.IgnorePlugin must be configured to ignore this dependency.\n * @see {@link file://./../../startup/src/webpack/configs/plugins/ignore-plugin/ignore-plugin.ts}\n */\n const { PortalProvider } =\n require('@servicetitan/anvil2') as typeof import('@servicetitan/anvil2');\n return <PortalProvider root={this.portalAnvilContainer}>{children}</PortalProvider>;\n } catch {\n return children;\n }\n }\n\n private withProviders(children: ReactElement): ReactElement {\n return this.withAnvil2Providers(this.withAnvil1Providers(children));\n }\n\n private render = () => {\n /*\n * Check for this.root first, otherwise we get error when\n * attributeChangedCallback happens on load\n */\n if (this.root) {\n const mfeData = this.dataset.mfeData\n ? /*\n * Data was stringified in order to come through the data-mfe-data attribute\n * So we must JSON.parse it here to get an object back\n */\n JSON.parse(this.dataset.mfeData)\n : /*\n * If mfeData isn't there, then the Host may not be up to date with web-components\n * and is instead passing data through separate data-attributes, so we want to\n * spread all of those instead\n */\n { ...this.dataset };\n\n const metadata = {\n shadowRoot: this.root,\n portalShadowRoot: this.portal!,\n };\n\n this.view?.rerender(\n <Provider\n singletons={[\n { provide: IS_WEB_COMPONENT_TOKEN, useValue: true },\n { provide: RENDER_ROOT_TOKEN, useValue: this.root },\n ]}\n >\n <Provider\n singletons={[\n { provide: Log, useValue: this.logService },\n {\n provide: HistoryManager,\n useValue: this.historyManager,\n },\n {\n provide: EXPOSED_DEPENDENCIES_TOKEN,\n useValue: this.exposedDependencies,\n },\n {\n provide: EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,\n useValue: this.exposedInstanceDependencies,\n },\n { provide: BASENAME_TOKEN, useValue: this.basename },\n { provide: EVENT_BUS_TOKEN, useValue: this.eventBus },\n { provide: getLDServiceToken(), useValue: this.ldService },\n ].filter(\n ({ provide, useValue }) =>\n useValue !== undefined && provide !== undefined\n )}\n >\n <MFEDataContext.Provider value={{ ...mfeData }}>\n <MFEMetadataContext.Provider value={metadata}>\n {this.withProviders(<Component {...mfeData} />)}\n {this.onReady && <RenderCallback callback={this.onReady} />}\n </MFEMetadataContext.Provider>\n </MFEDataContext.Provider>\n </Provider>\n </Provider>\n );\n }\n };\n }\n\n if (!WEB_COMPONENT_NAME) {\n // eslint-disable-next-line no-console\n console.error('\"WEB_COMPONENT_NAME\" is not defined!');\n return;\n }\n\n window.customElements.define(WEB_COMPONENT_NAME, WebComponent);\n}\n\nfunction getStyleUrls(light: boolean, sharedDependenciesNames: string[], el: HTMLElement) {\n function getCssUrl(dependencyName: string, cssFileRegEx: RegExp) {\n if (light && sharedDependenciesNames.includes(dependencyName)) {\n return Array.from(document.getElementsByTagName('link')).find(\n ({ href }) => href && cssFileRegEx.test(href)\n )?.href;\n }\n }\n\n const designSystemUrl = getCssUrl(\n '@servicetitan/design-system',\n /design-system(\\..+)?\\.bundle\\.css/\n );\n const anvil2CssUrl = getCssUrl('@servicetitan/anvil2', /anvil2(\\..+)?\\.bundle\\.css/);\n\n return [\n ...(designSystemUrl ? [designSystemUrl] : []),\n ...(anvil2CssUrl ? [anvil2CssUrl] : []),\n ...(el.hasAttribute('style-urls')\n ? JSON.parse(decodeURIComponent(el.getAttribute('style-urls')!))\n : []),\n ];\n}\n\nfunction RenderCallback({ callback }: { callback: () => void }) {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n useEffect(() => callback(), []);\n return null;\n}\n"],"names":["Log","Provider","useEffect","BASENAME_TOKEN","EXPOSED_DEPENDENCIES_TOKEN","EXPOSED_INSTANCE_DEPENDENCIES_TOKEN","IS_WEB_COMPONENT_TOKEN","RENDER_ROOT_TOKEN","MFEDataContext","MFEMetadataContext","EVENT_BUS_TOKEN","WEB_COMPONENT_NAME","HistoryManager","render","getElementName","getLDServiceToken","createLink","url","onLoad","element","document","createElement","href","rel","crossOrigin","onload","onerror","Placeholder","div","style","display","register","Component","light","options","WebComponent","HTMLElement","connectedCallback","root","isConnected","sharedDependenciesNames","styleUrls","getStyleUrls","styles","total","length","loaded","elements","shadowRoot","attachShadow","mode","portalElement","setAttribute","portal","body","appendChild","portalAnvilContainer","view","push","attachStyles","disconnectedCallback","remove","unmount","removeChild","host","undefined","onDispose","observedAttributes","attributeChangedCallback","withAnvil1Providers","children","DefaultPortalContext","TablePopupPropsContext","require","value","props","appendTo","withAnvil2Providers","PortalProvider","withProviders","ldService","logService","historyManager","exposedDependencies","exposedInstanceDependencies","eventBus","basename","onReady","provide","entries","key","Object","handleLoad","node","urls","mfeData","dataset","JSON","parse","metadata","portalShadowRoot","rerender","singletons","useValue","filter","RenderCallback","callback","console","error","window","customElements","define","el","getCssUrl","dependencyName","cssFileRegEx","includes","Array","from","getElementsByTagName","find","test","designSystemUrl","anvil2CssUrl","hasAttribute","decodeURIComponent","getAttribute"],"mappings":";;;;;;;;;;;;;;AACA,SAASA,GAAG,QAAQ,4BAA4B;AAChD,SAASC,QAAQ,QAAQ,0BAA0B;AAEnD,SAA0CC,SAAS,QAAQ,QAAQ;AACnE,SACIC,cAAc,EAEdC,0BAA0B,EAC1BC,mCAAmC,EAEnCC,sBAAsB,EAEtBC,iBAAiB,QACd,WAAW;AAClB,SAASC,cAAc,QAAQ,8BAA8B;AAC7D,SAASC,kBAAkB,QAAQ,kCAAkC;AACrE,SAASC,eAAe,QAAkB,cAAc;AACxD,SAASC,kBAAkB,QAAQ,YAAY;AAC/C,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,MAAM,QAAQ,WAAW;AAClC,SAASC,cAAc,EAAEC,iBAAiB,QAAQ,UAAU;AAE5D,SAASC,WAAWC,GAAW,EAAEC,MAAkB;IAC/C,MAAMC,UAAUC,SAASC,aAAa,CAAC;IAEvCF,QAAQG,IAAI,GAAGL;IACfE,QAAQI,GAAG,GAAG;IACdJ,QAAQK,WAAW,GAAG;IACtBL,QAAQM,MAAM,GAAGP;IACjBC,QAAQO,OAAO,GAAGR;IAElB,OAAOC;AACX;AAEA,MAAMQ,cAAkB,kBAAM,KAACC;QAAIC,OAAO;YAAEC,SAAS;QAAO;;AAO5D,OAAO,SAASC,SAASC,SAAwB,EAAEC,KAAc,EAAEC,OAAyB;IACxF,MAAMC,qBAAqBC;QAsBvBC,oBAAoB;sBAkBJ;gBAZR;YALJ;;;;aAIC,GACD,K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wCACzC,IAAI,CAACR,OAAO,kBAAI,KAACkB;4CAAeC,UAAU,IAAI,CAACnB,OAAO;;;;;;;gBAM/E;YACJ;;IACJ;IAEA,IAAI,CAAC5E,oBAAoB;QACrB,sCAAsC;QACtCgG,QAAQC,KAAK,CAAC;QACd;IACJ;IAEAC,OAAOC,cAAc,CAACC,MAAM,CAACpG,oBAAoBwB;AACrD;AAEA,SAASO,aAAaT,KAAc,EAAEO,uBAAiC,EAAEwE,EAAe;IACpF,SAASC,UAAUC,cAAsB,EAAEC,YAAoB;QAC3D,IAAIlF,SAASO,wBAAwB4E,QAAQ,CAACF,iBAAiB;gBACpDG;YAAP,QAAOA,mBAAAA,MAAMC,IAAI,CAAClG,SAASmG,oBAAoB,CAAC,SAASC,IAAI,CACzD,CAAC,EAAElG,IAAI,EAAE,GAAKA,QAAQ6F,aAAaM,IAAI,CAACnG,oBADrC+F,uCAAAA,iBAEJ/F,IAAI;QACX;IACJ;IAEA,MAAMoG,kBAAkBT,UACpB,+BACA;IAEJ,MAAMU,eAAeV,UAAU,wBAAwB;IAEvD,OAAO;WACCS,kBAAkB;YAACA;SAAgB,GAAG,EAAE;WACxCC,eAAe;YAACA;SAAa,GAAG,EAAE;WAClCX,GAAGY,YAAY,CAAC,gBACd3B,KAAKC,KAAK,CAAC2B,mBAAmBb,GAAGc,YAAY,CAAC,kBAC9C,EAAE;KACX;AACL;AAEA,SAASrB,eAAe,EAAEC,QAAQ,EAA4B;IAC1D,uDAAuD;IACvDxG,UAAU,IAAMwG,YAAY,EAAE;IAC9B,OAAO;AACX"}
|
package/dist/render.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../src/render.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAerC,UAAU,aAAa;IACnB,UAAU,CAAC,EAAE,OAAO,CAAC;CACxB;AAED,UAAU,YAAY;IAClB,QAAQ,CAAC,OAAO,EAAE,YAAY,GAAG,IAAI,CAAC;IACtC,OAAO,IAAI,IAAI,CAAC;CACnB;AAED,wBAAgB,MAAM,CAClB,OAAO,EAAE,YAAY,EACrB,SAAS,EAAE,OAAO,GAAG,gBAAgB,EACrC,OAAO,CAAC,EAAE,aAAa,GACxB,YAAY,CAgBd"}
|
package/dist/render.js
CHANGED
|
@@ -1,10 +1,18 @@
|
|
|
1
1
|
/* eslint-disable react/no-deprecated */ import ReactDOM from 'react-dom';
|
|
2
|
-
|
|
2
|
+
let createRoot;
|
|
3
|
+
try {
|
|
4
|
+
/**
|
|
5
|
+
* Note, the webpack.IgnorePlugin must be configured to ignore this dependency.
|
|
6
|
+
* @see {@link file://./../../startup/src/webpack/configs/plugins/ignore-plugin/ignore-plugin.ts}
|
|
7
|
+
*/ createRoot = require('react-dom/client').createRoot;
|
|
8
|
+
} catch (unused) {
|
|
9
|
+
// ignore
|
|
10
|
+
}
|
|
3
11
|
export function render(element, container, options) {
|
|
4
|
-
if (typeof
|
|
12
|
+
if (typeof createRoot !== 'function' || (options === null || options === void 0 ? void 0 : options.legacyRoot)) {
|
|
5
13
|
return renderLegacyRoot(element, container);
|
|
6
14
|
}
|
|
7
|
-
const root =
|
|
15
|
+
const root = createRoot(container);
|
|
8
16
|
root.render(element);
|
|
9
17
|
return {
|
|
10
18
|
rerender (element) {
|
package/dist/render.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/render.ts"],"sourcesContent":["/* eslint-disable react/no-deprecated */\nimport { ReactElement } from 'react';\nimport ReactDOM from 'react-dom';\nimport
|
|
1
|
+
{"version":3,"sources":["../src/render.ts"],"sourcesContent":["/* eslint-disable react/no-deprecated */\nimport { ReactElement } from 'react';\nimport ReactDOM from 'react-dom';\nimport type ReactDOMClient from 'react-dom/client';\n\nlet createRoot: typeof ReactDOMClient.createRoot;\ntry {\n /**\n * Note, the webpack.IgnorePlugin must be configured to ignore this dependency.\n * @see {@link file://./../../startup/src/webpack/configs/plugins/ignore-plugin/ignore-plugin.ts}\n */\n createRoot = require('react-dom/client').createRoot;\n} catch {\n // ignore\n}\n\ninterface RenderOptions {\n legacyRoot?: boolean;\n}\n\ninterface RenderResult {\n rerender(element: ReactElement): void;\n unmount(): void;\n}\n\nexport function render(\n element: ReactElement,\n container: Element | DocumentFragment,\n options?: RenderOptions\n): RenderResult {\n if (typeof createRoot !== 'function' || options?.legacyRoot) {\n return renderLegacyRoot(element, container);\n }\n\n const root = createRoot(container);\n root.render(element);\n\n return {\n rerender(element: ReactElement) {\n root.render(element);\n },\n unmount() {\n root.unmount();\n },\n };\n}\n\nfunction renderLegacyRoot(\n element: ReactElement,\n container: Element | DocumentFragment\n): RenderResult {\n ReactDOM.render(element, container);\n\n return {\n rerender(element: ReactElement) {\n ReactDOM.render(element, container);\n },\n unmount() {\n ReactDOM.unmountComponentAtNode(container);\n },\n };\n}\n"],"names":["ReactDOM","createRoot","require","render","element","container","options","legacyRoot","renderLegacyRoot","root","rerender","unmount","unmountComponentAtNode"],"mappings":"AAAA,sCAAsC,GAEtC,OAAOA,cAAc,YAAY;AAGjC,IAAIC;AACJ,IAAI;IACA;;;KAGC,GACDA,aAAaC,QAAQ,oBAAoBD,UAAU;AACvD,EAAE,eAAM;AACJ,SAAS;AACb;AAWA,OAAO,SAASE,OACZC,OAAqB,EACrBC,SAAqC,EACrCC,OAAuB;IAEvB,IAAI,OAAOL,eAAe,eAAcK,oBAAAA,8BAAAA,QAASC,UAAU,GAAE;QACzD,OAAOC,iBAAiBJ,SAASC;IACrC;IAEA,MAAMI,OAAOR,WAAWI;IACxBI,KAAKN,MAAM,CAACC;IAEZ,OAAO;QACHM,UAASN,OAAqB;YAC1BK,KAAKN,MAAM,CAACC;QAChB;QACAO;YACIF,KAAKE,OAAO;QAChB;IACJ;AACJ;AAEA,SAASH,iBACLJ,OAAqB,EACrBC,SAAqC;IAErCL,SAASG,MAAM,CAACC,SAASC;IAEzB,OAAO;QACHK,UAASN,OAAqB;YAC1BJ,SAASG,MAAM,CAACC,SAASC;QAC7B;QACAM;YACIX,SAASY,sBAAsB,CAACP;QACpC;IACJ;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-bundle-info.d.ts","sourceRoot":"","sources":["../../src/utils/get-bundle-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAwB,MAAM,6BAA6B,CAAC;AAGxF,OAAO,EAAE,2BAA2B,EAAW,YAAY,EAAE,MAAM,WAAW,CAAC;AAI/E,OAAO,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAKjE,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC;AAEnE,UAAU,kBAAkB;IACxB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;IAC1D,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;CACxB;AAED,wBAAsB,aAAa,CAAC,EAChC,KAAK,EACL,cAAc,EACd,kBAAkB,EAClB,mBAAwB,EACxB,2BAAgC,EAChC,UAAU,EACV,MAAM,EACN,OAAO,EACP,cAAc,GACjB,EAAE,kBAAkB;;;;;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"get-bundle-info.d.ts","sourceRoot":"","sources":["../../src/utils/get-bundle-info.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAwB,MAAM,6BAA6B,CAAC;AAGxF,OAAO,EAAE,2BAA2B,EAAW,YAAY,EAAE,MAAM,WAAW,CAAC;AAI/E,OAAO,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAKjE,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,UAAU,CAAC,OAAO,aAAa,CAAC,CAAC,CAAC;AAEnE,UAAU,kBAAkB;IACxB,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC;IACxB,mBAAmB,CAAC,EAAE,mBAAmB,CAAC;IAC1C,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;IAC1D,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,UAAU,CAAC,EAAE,OAAO,CAAC;IACrB,cAAc,EAAE,MAAM,CAAC;IACvB,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,YAAY,KAAK,IAAI,CAAC;IAC/C,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,WAAW,CAAC;CACxB;AAED,wBAAsB,aAAa,CAAC,EAChC,KAAK,EACL,cAAc,EACd,kBAAkB,EAClB,mBAAwB,EACxB,2BAAgC,EAChC,UAAU,EACV,MAAM,EACN,OAAO,EACP,cAAc,GACjB,EAAE,kBAAkB;;;;;;;;;;;;;;;;GAuFpB"}
|
|
@@ -43,12 +43,12 @@ export async function getBundleInfo({ cache, mainPackageUrl, fallbackPackageUrl,
|
|
|
43
43
|
const embed = !mismatch && supportLightBundles;
|
|
44
44
|
resolvedBundleType = embed ? 'light' : 'full';
|
|
45
45
|
}
|
|
46
|
-
const
|
|
46
|
+
const withBaseUrl = (path)=>`${exactPackageUrl}/dist/bundle/${resolvedBundleType}/${path}`;
|
|
47
47
|
let entrypoints;
|
|
48
48
|
if ((_metadata_entrypoints = metadata.entrypoints) === null || _metadata_entrypoints === void 0 ? void 0 : _metadata_entrypoints[resolvedBundleType]) {
|
|
49
49
|
entrypoints = metadata.entrypoints[resolvedBundleType];
|
|
50
50
|
} else {
|
|
51
|
-
entrypoints = await getEntrypoints(
|
|
51
|
+
entrypoints = await getEntrypoints(withBaseUrl('entrypoints.json'), requestCache);
|
|
52
52
|
}
|
|
53
53
|
const disposer = ()=>{
|
|
54
54
|
if (resolvedBundleType === 'light') {
|
|
@@ -58,15 +58,9 @@ export async function getBundleInfo({ cache, mainPackageUrl, fallbackPackageUrl,
|
|
|
58
58
|
}
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
-
let baseUrl = bundleBaseUrl;
|
|
62
|
-
if (entrypoints.port) {
|
|
63
|
-
const url = new URL(baseUrl);
|
|
64
|
-
url.port = String(entrypoints.port);
|
|
65
|
-
baseUrl = url.toString();
|
|
66
|
-
}
|
|
67
61
|
const urls = {
|
|
68
|
-
css: entrypoints.css.map(
|
|
69
|
-
js: entrypoints.js.map(
|
|
62
|
+
css: entrypoints.css.map(withBaseUrl),
|
|
63
|
+
js: entrypoints.js.map(withBaseUrl)
|
|
70
64
|
};
|
|
71
65
|
const elementName = resolvedBundleType === 'headless' ? `headless-${name}` : name;
|
|
72
66
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/get-bundle-info.ts"],"sourcesContent":["import { ExposedDependencies, getVersionMismatches } from '@servicetitan/startup-utils';\nimport get from 'lodash.get';\nimport semver from 'semver';\nimport { ExposedInstanceDependencies, getJson, GetJsonError } from '../common';\nimport type { Metadata } from '../types';\nimport { getCacheSetting } from './get-cache-setting';\nimport { getCachedMetadata } from './get-cached-metadata';\nimport { EntryPoints, getEntrypoints } from './get-entry-points';\nimport { getMFEHasCompatibleLaunchDarklyVersion } from './get-mfe-has-compatible-launchdarkly-version';\nimport { getMFEHasUniqueChunkNamespace } from './get-mfe-has-unique-chunk-namespace';\nimport { getMFESupportsRerendering } from './get-mfe-supports-rerendering';\n\nexport type BundleInfo = Awaited<ReturnType<typeof getBundleInfo>>;\n\ninterface GetBundleInfoProps {\n cache: boolean | number;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n fallbackPackageUrl?: string;\n isHeadless?: boolean;\n mainPackageUrl: string;\n onRequestError?: (error: GetJsonError) => void;\n retries?: number;\n signal?: AbortSignal;\n}\n\nexport async function getBundleInfo({\n cache,\n mainPackageUrl,\n fallbackPackageUrl,\n exposedDependencies = {},\n exposedInstanceDependencies = {},\n isHeadless,\n signal,\n retries,\n onRequestError,\n}: GetBundleInfoProps) {\n const {\n cacheHit,\n data: metadata,\n url: packageUrl,\n } = await getCachedMetadata({\n cache,\n fallbackPackageUrl,\n mainPackageUrl,\n onRequestError,\n retries,\n signal,\n });\n\n const { bundledWith, name, sharedDependencies } = metadata;\n const exactPackageUrl = packageUrl.replace('/dist/metadata.json', '');\n const requestCache = getCacheSetting(exactPackageUrl);\n\n let dependencies: NonNullable<Metadata['dependencies']>;\n if (metadata.dependencies) {\n dependencies = metadata.dependencies;\n } else {\n const { data: packageJson } = await getJson(`${exactPackageUrl}/package.json`, {\n cache: requestCache,\n retries,\n signal,\n });\n\n dependencies = packageJson.dependencies;\n }\n\n let mismatch: ReturnType<typeof getVersionMismatches>;\n let resolvedBundleType: 'headless' | 'light' | 'full';\n\n if (isHeadless) {\n resolvedBundleType = 'headless';\n } else {\n mismatch = getVersionMismatches(exposedDependencies, dependencies, sharedDependencies);\n const startupVersion = bundledWith?.['@servicetitan/startup'];\n const supportLightBundles = !!startupVersion && semver.gte(startupVersion, '17.0.0');\n const embed = !mismatch && supportLightBundles;\n resolvedBundleType = embed ? 'light' : 'full';\n }\n\n const
|
|
1
|
+
{"version":3,"sources":["../../src/utils/get-bundle-info.ts"],"sourcesContent":["import { ExposedDependencies, getVersionMismatches } from '@servicetitan/startup-utils';\nimport get from 'lodash.get';\nimport semver from 'semver';\nimport { ExposedInstanceDependencies, getJson, GetJsonError } from '../common';\nimport type { Metadata } from '../types';\nimport { getCacheSetting } from './get-cache-setting';\nimport { getCachedMetadata } from './get-cached-metadata';\nimport { EntryPoints, getEntrypoints } from './get-entry-points';\nimport { getMFEHasCompatibleLaunchDarklyVersion } from './get-mfe-has-compatible-launchdarkly-version';\nimport { getMFEHasUniqueChunkNamespace } from './get-mfe-has-unique-chunk-namespace';\nimport { getMFESupportsRerendering } from './get-mfe-supports-rerendering';\n\nexport type BundleInfo = Awaited<ReturnType<typeof getBundleInfo>>;\n\ninterface GetBundleInfoProps {\n cache: boolean | number;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n fallbackPackageUrl?: string;\n isHeadless?: boolean;\n mainPackageUrl: string;\n onRequestError?: (error: GetJsonError) => void;\n retries?: number;\n signal?: AbortSignal;\n}\n\nexport async function getBundleInfo({\n cache,\n mainPackageUrl,\n fallbackPackageUrl,\n exposedDependencies = {},\n exposedInstanceDependencies = {},\n isHeadless,\n signal,\n retries,\n onRequestError,\n}: GetBundleInfoProps) {\n const {\n cacheHit,\n data: metadata,\n url: packageUrl,\n } = await getCachedMetadata({\n cache,\n fallbackPackageUrl,\n mainPackageUrl,\n onRequestError,\n retries,\n signal,\n });\n\n const { bundledWith, name, sharedDependencies } = metadata;\n const exactPackageUrl = packageUrl.replace('/dist/metadata.json', '');\n const requestCache = getCacheSetting(exactPackageUrl);\n\n let dependencies: NonNullable<Metadata['dependencies']>;\n if (metadata.dependencies) {\n dependencies = metadata.dependencies;\n } else {\n const { data: packageJson } = await getJson(`${exactPackageUrl}/package.json`, {\n cache: requestCache,\n retries,\n signal,\n });\n\n dependencies = packageJson.dependencies;\n }\n\n let mismatch: ReturnType<typeof getVersionMismatches>;\n let resolvedBundleType: 'headless' | 'light' | 'full';\n\n if (isHeadless) {\n resolvedBundleType = 'headless';\n } else {\n mismatch = getVersionMismatches(exposedDependencies, dependencies, sharedDependencies);\n const startupVersion = bundledWith?.['@servicetitan/startup'];\n const supportLightBundles = !!startupVersion && semver.gte(startupVersion, '17.0.0');\n const embed = !mismatch && supportLightBundles;\n resolvedBundleType = embed ? 'light' : 'full';\n }\n\n const withBaseUrl = (path: string) =>\n `${exactPackageUrl}/dist/bundle/${resolvedBundleType}/${path}`;\n\n let entrypoints: EntryPoints;\n if (metadata.entrypoints?.[resolvedBundleType]) {\n entrypoints = metadata.entrypoints[resolvedBundleType];\n } else {\n entrypoints = await getEntrypoints(withBaseUrl('entrypoints.json'), requestCache);\n }\n\n const disposer = () => {\n if (resolvedBundleType === 'light') {\n const path = Object.values<string>(sharedDependencies).shift();\n if (path) {\n get(window, path).getStorage().clear(name);\n }\n }\n };\n\n const urls: EntryPoints = {\n css: entrypoints.css.map(withBaseUrl),\n js: entrypoints.js.map(withBaseUrl),\n };\n\n const elementName = resolvedBundleType === 'headless' ? `headless-${name}` : name;\n\n return {\n bundledWith,\n cacheHit,\n disposer,\n mfeSupportsRerendering: getMFESupportsRerendering(bundledWith, dependencies),\n mfeHasUniqueChunkNamespace: getMFEHasUniqueChunkNamespace(bundledWith),\n mfeHasCompatibleLaunchDarklyVersion: getMFEHasCompatibleLaunchDarklyVersion(\n bundledWith,\n exposedInstanceDependencies\n ),\n mismatch,\n resolvedBundleType,\n urls,\n WebComponent: elementName,\n version: metadata.version,\n module: entrypoints.module,\n };\n}\n"],"names":["getVersionMismatches","get","semver","getJson","getCacheSetting","getCachedMetadata","getEntrypoints","getMFEHasCompatibleLaunchDarklyVersion","getMFEHasUniqueChunkNamespace","getMFESupportsRerendering","getBundleInfo","cache","mainPackageUrl","fallbackPackageUrl","exposedDependencies","exposedInstanceDependencies","isHeadless","signal","retries","onRequestError","metadata","cacheHit","data","url","packageUrl","bundledWith","name","sharedDependencies","exactPackageUrl","replace","requestCache","dependencies","packageJson","mismatch","resolvedBundleType","startupVersion","supportLightBundles","gte","embed","withBaseUrl","path","entrypoints","disposer","Object","values","shift","window","getStorage","clear","urls","css","map","js","elementName","mfeSupportsRerendering","mfeHasUniqueChunkNamespace","mfeHasCompatibleLaunchDarklyVersion","Web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
5
|
}
|
|
7
6
|
export declare function getEntrypoints(url: string, cache: 'no-store' | undefined, signal?: AbortSignal): Promise<EntryPoints>;
|
|
8
7
|
//# sourceMappingURL=get-entry-points.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-entry-points.d.ts","sourceRoot":"","sources":["../../src/utils/get-entry-points.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC;
|
|
1
|
+
{"version":3,"file":"get-entry-points.d.ts","sourceRoot":"","sources":["../../src/utils/get-entry-points.ts"],"names":[],"mappings":"AAEA,MAAM,WAAW,WAAW;IACxB,GAAG,EAAE,MAAM,EAAE,CAAC;IACd,EAAE,EAAE,MAAM,EAAE,CAAC;IACb,MAAM,CAAC,EAAE,IAAI,CAAC;CACjB;AAED,wBAAsB,cAAc,CAChC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,UAAU,GAAG,SAAS,EAC7B,MAAM,CAAC,EAAE,WAAW,GACrB,OAAO,CAAC,WAAW,CAAC,CAWtB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/get-entry-points.ts"],"sourcesContent":["import { getJson } from '../common';\n\nexport interface EntryPoints {\n css: string[];\n js: string[];\n module?: true;\n
|
|
1
|
+
{"version":3,"sources":["../../src/utils/get-entry-points.ts"],"sourcesContent":["import { getJson } from '../common';\n\nexport interface EntryPoints {\n css: string[];\n js: string[];\n module?: true;\n}\n\nexport async function getEntrypoints(\n url: string,\n cache: 'no-store' | undefined,\n signal?: AbortSignal\n): Promise<EntryPoints> {\n try {\n return (\n await getJson(url, {\n cache,\n signal,\n })\n ).data;\n } catch {\n return { css: ['index.css'], js: ['index.js'] };\n }\n}\n"],"names":["getJson","getEntrypoints","url","cache","signal","data","css","js"],"mappings":"AAAA,SAASA,OAAO,QAAQ,YAAY;AAQpC,OAAO,eAAeC,eAClBC,GAAW,EACXC,KAA6B,EAC7BC,MAAoB;IAEpB,IAAI;QACA,OAAO,AACH,CAAA,MAAMJ,QAAQE,KAAK;YACfC;YACAC;QACJ,EAAC,EACHC,IAAI;IACV,EAAE,eAAM;QACJ,OAAO;YAAEC,KAAK;gBAAC;aAAY;YAAEC,IAAI;gBAAC;aAAW;QAAC;IAClD;AACJ"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import { type LDService } from '@servicetitan/launchdarkly-service';
|
|
2
|
+
import { SymbolToken } from '@servicetitan/react-ioc';
|
|
3
|
+
export declare function getLDServiceToken(): SymbolToken<LDService>;
|
|
3
4
|
//# sourceMappingURL=get-ld-service-token.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"get-ld-service-token.d.ts","sourceRoot":"","sources":["../../src/utils/get-ld-service-token.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,SAAS,MAAM,oCAAoC,CAAC;
|
|
1
|
+
{"version":3,"file":"get-ld-service-token.d.ts","sourceRoot":"","sources":["../../src/utils/get-ld-service-token.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAStD,wBAAgB,iBAAiB,2BAEhC"}
|
|
@@ -1,6 +1,11 @@
|
|
|
1
|
-
|
|
1
|
+
let token;
|
|
2
|
+
try {
|
|
3
|
+
token = require('@servicetitan/launchdarkly-service').LD_SERVICE_TOKEN;
|
|
4
|
+
} catch (unused) {
|
|
5
|
+
// ignore
|
|
6
|
+
}
|
|
2
7
|
export function getLDServiceToken() {
|
|
3
|
-
return
|
|
8
|
+
return token;
|
|
4
9
|
}
|
|
5
10
|
|
|
6
11
|
//# sourceMappingURL=get-ld-service-token.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/get-ld-service-token.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"sources":["../../src/utils/get-ld-service-token.ts"],"sourcesContent":["import { type LDService } from '@servicetitan/launchdarkly-service';\nimport { SymbolToken } from '@servicetitan/react-ioc';\n\nlet token: SymbolToken<LDService>;\ntry {\n token = require('@servicetitan/launchdarkly-service').LD_SERVICE_TOKEN;\n} catch {\n // ignore\n}\n\nexport function getLDServiceToken() {\n return token;\n}\n"],"names":["token","require","LD_SERVICE_TOKEN","getLDServiceToken"],"mappings":"AAGA,IAAIA;AACJ,IAAI;IACAA,QAAQC,QAAQ,sCAAsCC,gBAAgB;AAC1E,EAAE,eAAM;AACJ,SAAS;AACb;AAEA,OAAO,SAASC;IACZ,OAAOH;AACX"}
|