@servicetitan/web-components 40.2.1 → 40.3.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/loader.js +4 -1
- package/dist/loader.js.map +1 -1
- package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.d.ts +3 -0
- package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.d.ts.map +1 -0
- package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.js +12 -0
- package/dist/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.js.map +1 -0
- package/dist/patches/kendo-scrollbar-width/index.d.ts +3 -0
- package/dist/patches/kendo-scrollbar-width/index.d.ts.map +1 -0
- package/dist/patches/kendo-scrollbar-width/index.js +4 -0
- package/dist/patches/kendo-scrollbar-width/index.js.map +1 -0
- package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.d.ts +2 -0
- package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.d.ts.map +1 -0
- package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.js +26 -0
- package/dist/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.js.map +1 -0
- package/dist/register.js +2 -2
- package/dist/register.js.map +1 -1
- package/dist/use-prefetch.d.ts +2 -3
- package/dist/use-prefetch.d.ts.map +1 -1
- package/dist/use-prefetch.js +14 -7
- package/dist/use-prefetch.js.map +1 -1
- package/dist/utils/get-bundle-info.d.ts +1 -0
- package/dist/utils/get-bundle-info.d.ts.map +1 -1
- package/dist/utils/get-bundle-info.js +2 -0
- package/dist/utils/get-bundle-info.js.map +1 -1
- package/dist/utils/web-component.d.ts.map +1 -1
- package/dist/utils/web-component.js +13 -2
- package/dist/utils/web-component.js.map +1 -1
- package/package.json +18 -14
- package/src/loader.tsx +5 -1
- package/src/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.ts +11 -0
- package/src/patches/kendo-scrollbar-width/index.ts +2 -0
- package/src/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.ts +27 -0
- package/src/register.tsx +1 -1
- package/src/use-prefetch.ts +36 -32
- package/src/utils/get-bundle-info.ts +2 -0
- package/src/utils/web-component.tsx +20 -3
- package/dist/contexts/tests/mfe-data-context.test.d.ts +0 -2
- package/dist/contexts/tests/mfe-data-context.test.d.ts.map +0 -1
- package/dist/contexts/tests/mfe-data-context.test.js +0 -60
- package/dist/contexts/tests/mfe-data-context.test.js.map +0 -1
- package/dist/contexts/tests/mfe-metadata-context.test.d.ts +0 -2
- package/dist/contexts/tests/mfe-metadata-context.test.d.ts.map +0 -1
- package/dist/contexts/tests/mfe-metadata-context.test.js +0 -41
- package/dist/contexts/tests/mfe-metadata-context.test.js.map +0 -1
- package/src/__mocks__/expect-styles-in-dom.ts +0 -11
- package/src/__mocks__/index.ts +0 -3
- package/src/__mocks__/register-anvil2-harness.tsx +0 -49
- package/src/__mocks__/register-component.tsx +0 -20
- package/src/__mocks__/test-component.tsx +0 -41
- package/src/__tests__/common.test.ts +0 -204
- package/src/__tests__/delayed.test.tsx +0 -49
- package/src/__tests__/event-bus-types.test.ts +0 -620
- package/src/__tests__/event-bus.test.ts +0 -240
- package/src/__tests__/get-value-for-environment.test.ts +0 -95
- package/src/__tests__/globals.test.ts +0 -16
- package/src/__tests__/headless-loader.test.tsx +0 -123
- package/src/__tests__/history-manager.test.ts +0 -111
- package/src/__tests__/loader.test.tsx +0 -1178
- package/src/__tests__/register-anvil2-optional.test.tsx +0 -32
- package/src/__tests__/register-anvil2.test.tsx +0 -80
- package/src/__tests__/register-headless.test.tsx +0 -97
- package/src/__tests__/register-legacy-root.test.tsx +0 -38
- package/src/__tests__/register.test.tsx +0 -247
- package/src/__tests__/use-prefetch.test.tsx +0 -235
- package/src/contexts/tests/mfe-data-context.test.tsx +0 -64
- package/src/contexts/tests/mfe-metadata-context.test.tsx +0 -34
- package/src/css-injector/__tests__/mfe-style-registry.test.ts +0 -163
- package/src/css-injector/__tests__/with-css-injector.test.tsx +0 -128
- package/src/utils/__tests__/get-cached-metadata.test.ts +0 -94
- package/src/utils/__tests__/get-mfe-has-compatible-launchdarkly-version.test.ts +0 -54
- package/src/utils/__tests__/get-mfe-supports-rerendering.test.ts +0 -99
- package/src/utils/__tests__/get-mfe-supports-versioned-ld-client.test.ts +0 -38
- package/src/utils/__tests__/is-versioned-url.test.ts +0 -18
- package/src/utils/__tests__/load-scripts.test.ts +0 -171
- package/src/utils/__tests__/supports-prefetch.test.ts +0 -27
- package/src/utils/__tests__/ttl-cache.test.ts +0 -98
package/dist/loader.js
CHANGED
|
@@ -83,6 +83,9 @@ function lazyWebComponent(props) {
|
|
|
83
83
|
const { basename, cache, exposedDependencies, exposedInstanceDependencies, eventBus, fallbackSrc, isHeadless, logService, onRequestError, retries, src } = props;
|
|
84
84
|
return /*#__PURE__*/ lazy(async ()=>{
|
|
85
85
|
var _exposedInstanceDependencies_launchDarkly;
|
|
86
|
+
if (!src) {
|
|
87
|
+
throw new Error('Loader src is empty');
|
|
88
|
+
}
|
|
86
89
|
const bundleInfo = await getBundleInfo({
|
|
87
90
|
cache,
|
|
88
91
|
mainPackageUrl: src,
|
|
@@ -125,7 +128,7 @@ function getFallback(node, message, { delayed = false } = {}) {
|
|
|
125
128
|
}) : ()=>fallbackNode;
|
|
126
129
|
}
|
|
127
130
|
function isLocalHost(source) {
|
|
128
|
-
return [
|
|
131
|
+
return !!source && [
|
|
129
132
|
'localhost',
|
|
130
133
|
'127.0.0.1'
|
|
131
134
|
].some((host)=>source.indexOf(host) >= 0);
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/loader.tsx"],"sourcesContent":["import { ErrorBoundary } from '@servicetitan/error-boundary';\nimport { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport {\n ReactElement,\n ReactNode,\n Ref,\n Suspense,\n forwardRef,\n lazy,\n useImperativeHandle,\n useMemo,\n useRef,\n} from 'react';\nimport {\n EXPOSED_DEPENDENCIES_TOKEN,\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,\n ExposedInstanceDependencies,\n GetJsonError,\n} from './common';\nimport { MFEContextData } from './contexts/mfe-data-context';\nimport { Delayed } from './delayed';\nimport { EVENT_BUS_TOKEN, EventBus } from './event-bus';\nimport { EXPOSED_DEPENDENCIES, EXPOSED_INSTANCE_DEPENDENCIES } from './globals';\nimport {\n getBundleInfo,\n getLDServiceToken,\n loadScripts,\n validateBundleInfo,\n webComponent,\n} from './utils';\n\nexport type LoaderRef = EventBus;\n\nexport type FallbackNode = NonNullable<ReactNode> | null;\n\nexport interface UnrestrictedLoaderProps<T = {}> {\n src: string;\n fallbackSrc?: string;\n /** Values in the object will be stringified and then parsed before being delivered to the MFE via props or context. */\n data?: MFEContextData<T>;\n basename?: string;\n loadingFallback?: FallbackNode;\n loadingFallbackDelayed?: boolean;\n errorFallback?: FallbackNode;\n className?: string;\n retries?: number;\n isHeadless?: boolean;\n cache?: boolean | number;\n onRequestError?(error: GetJsonError): boolean;\n}\n\nexport type LoaderProps<T> = Pick<\n UnrestrictedLoaderProps<T>,\n | 'src'\n | 'fallbackSrc'\n | 'data'\n | 'basename'\n | 'loadingFallback'\n | 'loadingFallbackDelayed'\n | 'errorFallback'\n | 'className'\n | 'retries'\n | 'cache'\n | 'onRequestError'\n>;\n\nexport type LoaderDataProps = Pick<UnrestrictedLoaderProps, 'data' | 'className'> & {\n LoadingFallback: () => JSX.Element;\n};\n\nconst UnrestrictedLoader = <T,>(props: UnrestrictedLoaderProps<T>, ref: Ref<LoaderRef>) => {\n const { cache = -1, basename, fallbackSrc, isHeadless, onRequestError, retries, src } = props;\n const { loadingFallback, loadingFallbackDelayed = true } = props;\n\n const bus = useEventBus();\n const [logService, exposedDependencies = EXPOSED_DEPENDENCIES, eventBus = bus] =\n useOptionalDependencies(Log, EXPOSED_DEPENDENCIES_TOKEN, EVENT_BUS_TOKEN);\n let [exposedInstanceDependencies = EXPOSED_INSTANCE_DEPENDENCIES] = useOptionalDependencies(\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN\n );\n const [ldService] = useOptionalDependencies(getLDServiceToken() ?? Symbol());\n\n const LoadingFallback = useMemo(() => {\n const message = `Loading${isLocalHost(src) ? ` ${src}` : ''}...`;\n return getFallback(loadingFallback, message, { delayed: loadingFallbackDelayed });\n }, [loadingFallback, loadingFallbackDelayed, src]);\n\n const ErrorFallback = useMemo(() => {\n const message = `Something went wrong${isLocalHost(src) ? ` loading ${src}` : ''}`;\n return getFallback(props.errorFallback, message);\n }, [props.errorFallback, src]);\n\n exposedInstanceDependencies = useMemo(\n () => ensureLDService(exposedInstanceDependencies, ldService),\n [exposedInstanceDependencies, ldService]\n );\n\n const Loader = useMemo(\n () =>\n lazyWebComponent({\n basename,\n cache,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n }),\n [\n basename,\n cache,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n ]\n );\n\n useImperativeHandle(ref, () => eventBus, [eventBus]);\n\n return (\n <ErrorBoundary moduleName={src} fallback={ErrorFallback}>\n <Suspense fallback={<LoadingFallback />}>\n <Loader\n data={props.data ?? {}}\n className={props.className}\n LoadingFallback={LoadingFallback}\n />\n </Suspense>\n </ErrorBoundary>\n );\n};\n\nexport const Loader = forwardRef(UnrestrictedLoader) as <T = {}>(\n props: LoaderProps<NoInfer<T>> & { ref?: Ref<LoaderRef> }\n) => ReturnType<typeof UnrestrictedLoader>;\n\ntype LazyLoaderProps = UnrestrictedLoaderProps<any> & {\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n eventBus: EventBus;\n logService?: Log;\n cache: Required<UnrestrictedLoaderProps<any>>['cache'];\n};\n\nfunction lazyWebComponent(props: LazyLoaderProps) {\n const {\n basename,\n cache,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n } = props;\n\n return lazy<(_: LoaderDataProps) => JSX.Element | null>(async () => {\n const bundleInfo = await getBundleInfo({\n cache,\n mainPackageUrl: src,\n fallbackPackageUrl: fallbackSrc,\n isHeadless,\n exposedDependencies,\n exposedInstanceDependencies,\n retries,\n onRequestError,\n });\n\n validateBundleInfo(bundleInfo, {\n exposedDependencies,\n exposedInstanceDependencies,\n logService,\n packageUrl: src,\n });\n\n await loadScripts(bundleInfo);\n\n const hostLDService = exposedInstanceDependencies?.launchDarkly?.ldService;\n const hostSupportsVersionedLDClient = typeof hostLDService?.getVersionClient === 'function';\n const ldService =\n bundleInfo.mfeHasCompatibleLaunchDarklyVersion ||\n (bundleInfo.mfeSupportsVersionedLDClient && hostSupportsVersionedLDClient)\n ? hostLDService\n : undefined;\n\n return {\n default: webComponent({\n basename,\n bundleInfo,\n eventBus,\n exposedDependencies,\n exposedInstanceDependencies,\n ldService,\n logService,\n }),\n };\n });\n}\n\nfunction getFallback(\n node: FallbackNode | undefined,\n message: string,\n { delayed = false }: { delayed?: boolean } = {}\n) {\n const fallbackNode = node !== undefined ? (node as ReactElement) : <h2>{message}</h2>;\n return delayed ? () => <Delayed>{fallbackNode}</Delayed> : () => fallbackNode;\n}\n\nfunction isLocalHost(source: string) {\n return ['localhost', '127.0.0.1'].some(host => source.indexOf(host) >= 0);\n}\n\nfunction ensureLDService(\n exposedInstanceDependencies?: ExposedInstanceDependencies,\n ldService?: LDService\n) {\n const launchDarkly = exposedInstanceDependencies?.launchDarkly;\n if (launchDarkly?.version && !launchDarkly.ldService && ldService) {\n return { ...exposedInstanceDependencies, launchDarkly: { ...launchDarkly, ldService } };\n }\n return exposedInstanceDependencies;\n}\n\nfunction useEventBus() {\n return useRef(new EventBus()).current;\n}\n"],"names":["ErrorBoundary","Log","useOptionalDependencies","Suspense","forwardRef","lazy","useImperativeHandle","useMemo","useRef","EXPOSED_DEPENDENCIES_TOKEN","EXPOSED_INSTANCE_DEPENDENCIES_TOKEN","Delayed","EVENT_BUS_TOKEN","EventBus","EXPOSED_DEPENDENCIES","EXPOSED_INSTANCE_DEPENDENCIES","getBundleInfo","getLDServiceToken","loadScripts","validateBundleInfo","webComponent","UnrestrictedLoader","props","ref","cache","basename","fallbackSrc","isHeadless","onRequestError","retries","src","loadingFallback","loadingFallbackDelayed","bus","useEventBus","logService","exposedDependencies","eventBus","exposedInstanceDependencies","ldService","Symbol","LoadingFallback","message","isLocalHost","getFallback","delayed","ErrorFallback","errorFallback","ensureLDService","Loader","lazyWebComponent","moduleName","fallback","data","className","bundleInfo","mainPackageUrl","fallbackPackageUrl","packageUrl","hostLDService","launchDarkly","hostSupportsVersionedLDClient","getVersionClient","mfeHasCompatibleLaunchDarklyVersion","mfeSupportsVersionedLDClient","undefined","default","node","fallbackNode","h2","source","some","host","indexOf","version","current"],"mappings":";AAAA,SAASA,aAAa,QAAQ,+BAA+B;AAE7D,SAASC,GAAG,QAAQ,4BAA4B;AAChD,SAASC,uBAAuB,QAAQ,0BAA0B;AAElE,SAIIC,QAAQ,EACRC,UAAU,EACVC,IAAI,EACJC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,QACH,QAAQ;AACf,SACIC,0BAA0B,EAC1BC,mCAAmC,QAGhC,WAAW;AAElB,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,eAAe,EAAEC,QAAQ,QAAQ,cAAc;AACxD,SAASC,oBAAoB,EAAEC,6BAA6B,QAAQ,YAAY;AAChF,SACIC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,kBAAkB,EAClBC,YAAY,QACT,UAAU;AAyCjB,MAAMC,qBAAqB,CAAKC,OAAmCC;QAUnBN,oBAqDtBK;IA9Dt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B,eAAeD,SAASF,YAAaE,qBAAwB,KAACE;kBAAI3B;;IACxE,OAAOG,UAAU,kBAAM,KAAClC;sBAASyD;aAA0B,IAAMA;AACrE;AAEA,SAASzB,YAAY2B,MAAc;IAC/B,OAAO;QAAC;QAAa;KAAY,CAACC,IAAI,CAACC,CAAAA,OAAQF,OAAOG,OAAO,CAACD,SAAS;AAC3E;AAEA,SAASxB,gBACLV,2BAAyD,EACzDC,SAAqB;IAErB,MAAMqB,eAAetB,wCAAAA,kDAAAA,4BAA6BsB,YAAY;IAC9D,IAAIA,CAAAA,yBAAAA,mCAAAA,aAAcc,OAAO,KAAI,CAACd,aAAarB,SAAS,IAAIA,WAAW;QAC/D,OAAO;YAAE,GAAGD,2BAA2B;YAAEsB,cAAc;gBAAE,GAAGA,YAAY;gBAAErB;YAAU;QAAE;IAC1F;IACA,OAAOD;AACX;AAEA,SAASJ;IACL,OAAO1B,OAAO,IAAIK,YAAY8D,OAAO;AACzC"}
|
|
1
|
+
{"version":3,"sources":["../src/loader.tsx"],"sourcesContent":["import { ErrorBoundary } from '@servicetitan/error-boundary';\nimport { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport {\n ReactElement,\n ReactNode,\n Ref,\n Suspense,\n forwardRef,\n lazy,\n useImperativeHandle,\n useMemo,\n useRef,\n} from 'react';\nimport {\n EXPOSED_DEPENDENCIES_TOKEN,\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN,\n ExposedInstanceDependencies,\n GetJsonError,\n} from './common';\nimport { MFEContextData } from './contexts/mfe-data-context';\nimport { Delayed } from './delayed';\nimport { EVENT_BUS_TOKEN, EventBus } from './event-bus';\nimport { EXPOSED_DEPENDENCIES, EXPOSED_INSTANCE_DEPENDENCIES } from './globals';\nimport {\n getBundleInfo,\n getLDServiceToken,\n loadScripts,\n validateBundleInfo,\n webComponent,\n} from './utils';\n\nexport type LoaderRef = EventBus;\n\nexport type FallbackNode = NonNullable<ReactNode> | null;\n\nexport interface UnrestrictedLoaderProps<T = {}> {\n src: string;\n fallbackSrc?: string;\n /** Values in the object will be stringified and then parsed before being delivered to the MFE via props or context. */\n data?: MFEContextData<T>;\n basename?: string;\n loadingFallback?: FallbackNode;\n loadingFallbackDelayed?: boolean;\n errorFallback?: FallbackNode;\n className?: string;\n retries?: number;\n isHeadless?: boolean;\n cache?: boolean | number;\n onRequestError?(error: GetJsonError): boolean;\n}\n\nexport type LoaderProps<T> = Pick<\n UnrestrictedLoaderProps<T>,\n | 'src'\n | 'fallbackSrc'\n | 'data'\n | 'basename'\n | 'loadingFallback'\n | 'loadingFallbackDelayed'\n | 'errorFallback'\n | 'className'\n | 'retries'\n | 'cache'\n | 'onRequestError'\n>;\n\nexport type LoaderDataProps = Pick<UnrestrictedLoaderProps, 'data' | 'className'> & {\n LoadingFallback: () => JSX.Element;\n};\n\nconst UnrestrictedLoader = <T,>(props: UnrestrictedLoaderProps<T>, ref: Ref<LoaderRef>) => {\n const { cache = -1, basename, fallbackSrc, isHeadless, onRequestError, retries, src } = props;\n const { loadingFallback, loadingFallbackDelayed = true } = props;\n\n const bus = useEventBus();\n const [logService, exposedDependencies = EXPOSED_DEPENDENCIES, eventBus = bus] =\n useOptionalDependencies(Log, EXPOSED_DEPENDENCIES_TOKEN, EVENT_BUS_TOKEN);\n let [exposedInstanceDependencies = EXPOSED_INSTANCE_DEPENDENCIES] = useOptionalDependencies(\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN\n );\n const [ldService] = useOptionalDependencies(getLDServiceToken() ?? Symbol());\n\n const LoadingFallback = useMemo(() => {\n const message = `Loading${isLocalHost(src) ? ` ${src}` : ''}...`;\n return getFallback(loadingFallback, message, { delayed: loadingFallbackDelayed });\n }, [loadingFallback, loadingFallbackDelayed, src]);\n\n const ErrorFallback = useMemo(() => {\n const message = `Something went wrong${isLocalHost(src) ? ` loading ${src}` : ''}`;\n return getFallback(props.errorFallback, message);\n }, [props.errorFallback, src]);\n\n exposedInstanceDependencies = useMemo(\n () => ensureLDService(exposedInstanceDependencies, ldService),\n [exposedInstanceDependencies, ldService]\n );\n\n const Loader = useMemo(\n () =>\n lazyWebComponent({\n basename,\n cache,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n }),\n [\n basename,\n cache,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n ]\n );\n\n useImperativeHandle(ref, () => eventBus, [eventBus]);\n\n return (\n <ErrorBoundary moduleName={src} fallback={ErrorFallback}>\n <Suspense fallback={<LoadingFallback />}>\n <Loader\n data={props.data ?? {}}\n className={props.className}\n LoadingFallback={LoadingFallback}\n />\n </Suspense>\n </ErrorBoundary>\n );\n};\n\nexport const Loader = forwardRef(UnrestrictedLoader) as <T = {}>(\n props: LoaderProps<NoInfer<T>> & { ref?: Ref<LoaderRef> }\n) => ReturnType<typeof UnrestrictedLoader>;\n\ntype LazyLoaderProps = UnrestrictedLoaderProps<any> & {\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n eventBus: EventBus;\n logService?: Log;\n cache: Required<UnrestrictedLoaderProps<any>>['cache'];\n};\n\nfunction lazyWebComponent(props: LazyLoaderProps) {\n const {\n basename,\n cache,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n fallbackSrc,\n isHeadless,\n logService,\n onRequestError,\n retries,\n src,\n } = props;\n\n return lazy<(_: LoaderDataProps) => JSX.Element | null>(async () => {\n if (!src) {\n throw new Error('Loader src is empty');\n }\n\n const bundleInfo = await getBundleInfo({\n cache,\n mainPackageUrl: src,\n fallbackPackageUrl: fallbackSrc,\n isHeadless,\n exposedDependencies,\n exposedInstanceDependencies,\n retries,\n onRequestError,\n });\n\n validateBundleInfo(bundleInfo, {\n exposedDependencies,\n exposedInstanceDependencies,\n logService,\n packageUrl: src,\n });\n\n await loadScripts(bundleInfo);\n\n const hostLDService = exposedInstanceDependencies?.launchDarkly?.ldService;\n const hostSupportsVersionedLDClient = typeof hostLDService?.getVersionClient === 'function';\n const ldService =\n bundleInfo.mfeHasCompatibleLaunchDarklyVersion ||\n (bundleInfo.mfeSupportsVersionedLDClient && hostSupportsVersionedLDClient)\n ? hostLDService\n : undefined;\n\n return {\n default: webComponent({\n basename,\n bundleInfo,\n eventBus,\n exposedDependencies,\n exposedInstanceDependencies,\n ldService,\n logService,\n }),\n };\n });\n}\n\nfunction getFallback(\n node: FallbackNode | undefined,\n message: string,\n { delayed = false }: { delayed?: boolean } = {}\n) {\n const fallbackNode = node !== undefined ? (node as ReactElement) : <h2>{message}</h2>;\n return delayed ? () => <Delayed>{fallbackNode}</Delayed> : () => fallbackNode;\n}\n\nfunction isLocalHost(source: string) {\n return !!source && ['localhost', '127.0.0.1'].some(host => source.indexOf(host) >= 0);\n}\n\nfunction ensureLDService(\n exposedInstanceDependencies?: ExposedInstanceDependencies,\n ldService?: LDService\n) {\n const launchDarkly = exposedInstanceDependencies?.launchDarkly;\n if (launchDarkly?.version && !launchDarkly.ldService && ldService) {\n return { ...exposedInstanceDependencies, launchDarkly: { ...launchDarkly, ldService } };\n }\n return exposedInstanceDependencies;\n}\n\nfunction useEventBus() {\n return useRef(new EventBus()).current;\n}\n"],"names":["ErrorBoundary","Log","useOptionalDependencies","Suspense","forwardRef","lazy","useImperativeHandle","useMemo","useRef","EXPOSED_DEPENDENCIES_TOKEN","EXPOSED_INSTANCE_DEPENDENCIES_TOKEN","Delayed","EVENT_BUS_TOKEN","EventBus","EXPOSED_DEPENDENCIES","EXPOSED_INSTANCE_DEPENDENCIES","getBundleInfo","getLDServiceToken","loadScripts","validateBundleInfo","webComponent","UnrestrictedLoader","props","ref","cache","basename","fallbackSrc","isHeadless","onRequestError","retries","src","loadingFallback","loadingFallbackDelayed","bus","useEventBus","logService","exposedDependencies","eventBus","exposedInstanceDependencies","ldService","Symbol","LoadingFallback","message","isLocalHost","getFallback","delayed","ErrorFallback","errorFallback","ensureLDService","Loader","lazyWebComponent","moduleName","fallback","data","className","Error","bundleInfo","mainPackageUrl","fallbackPackageUrl","packageUrl","hostLDService","launchDarkly","hostSupportsVersionedLDClient","getVersionClient","mfeHasCompatibleLaunchDarklyVersion","mfeSupportsVersionedLDClient","undefined","default","node","fallbackNode","h2","source","some","host","indexOf","version","current"],"mappings":";AAAA,SAASA,aAAa,QAAQ,+BAA+B;AAE7D,SAASC,GAAG,QAAQ,4BAA4B;AAChD,SAASC,uBAAuB,QAAQ,0BAA0B;AAElE,SAIIC,QAAQ,EACRC,UAAU,EACVC,IAAI,EACJC,mBAAmB,EACnBC,OAAO,EACPC,MAAM,QACH,QAAQ;AACf,SACIC,0BAA0B,EAC1BC,mCAAmC,QAGhC,WAAW;AAElB,SAASC,OAAO,QAAQ,YAAY;AACpC,SAASC,eAAe,EAAEC,QAAQ,QAAQ,cAAc;AACxD,SAASC,oBAAoB,EAAEC,6BAA6B,QAAQ,YAAY;AAChF,SACIC,aAAa,EACbC,iBAAiB,EACjBC,WAAW,EACXC,kBAAkB,EAClBC,YAAY,QACT,UAAU;AAyCjB,MAAMC,qBAAqB,CAAKC,OAAmCC;QAUnBN,oBAqDtBK;IA9DtB,MAAM,EAAEE,QAAQ,CAAC,CAAC,EAAEC,QAAQ,EAAEC,WAAW,EAAEC,UAAU,EAAEC,cAAc,EAAEC,OAAO,EAAEC,GAAG,EAAE,GAAGR;IACxF,MAAM,EAAES,eAAe,EAAEC,yBAAyB,IAAI,EAAE,GAAGV;IAE3D,MAAMW,MAAMC;IACZ,MAAM,CAACC,YAAYC,sBAAsBtB,oBAAoB,EAAEuB,WAAWJ,GAAG,CAAC,GAC1E/B,wBAAwBD,KAAKQ,4BAA4BG;IAC7D,IAAI,CAAC0B,8BAA8BvB,6BAA6B,CAAC,GAAGb,wBAChEQ;IAE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AA,4BAA6BuB,YAAY;IAC9D,IAAIA,CAAAA,yBAAAA,mCAAAA,aAAcc,OAAO,KAAI,CAACd,aAAatB,SAAS,IAAIA,WAAW;QAC/D,OAAO;YAAE,GAAGD,2BAA2B;YAAEuB,cAAc;gBAAE,GAAGA,YAAY;gBAAEtB;YAAU;QAAE;IAC1F;IACA,OAAOD;AACX;AAEA,SAASJ;IACL,OAAO1B,OAAO,IAAIK,YAAY+D,OAAO;AACzC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"get-mfe-maybe-uses-kendo-grid.d.ts","sourceRoot":"","sources":["../../../src/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAQ5C,wBAAgB,wBAAwB,CAAC,YAAY,EAAE,QAAQ,CAAC,cAAc,CAAC,WAE9E"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* Design system's Table bundles the Kendo grid as its own dependency, so MFEs that use it
|
|
3
|
+
* don't list the grid themselves.
|
|
4
|
+
*/ const KENDO_GRID_PACKAGES = [
|
|
5
|
+
'@progress/kendo-react-grid',
|
|
6
|
+
'@servicetitan/design-system'
|
|
7
|
+
];
|
|
8
|
+
export function getMFEMaybeUsesKendoGrid(dependencies) {
|
|
9
|
+
return KENDO_GRID_PACKAGES.some((name)=>!!(dependencies === null || dependencies === void 0 ? void 0 : dependencies[name]));
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=get-mfe-maybe-uses-kendo-grid.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/patches/kendo-scrollbar-width/get-mfe-maybe-uses-kendo-grid.ts"],"sourcesContent":["import type { Metadata } from '../../types';\n\n/*\n * Design system's Table bundles the Kendo grid as its own dependency, so MFEs that use it\n * don't list the grid themselves.\n */\nconst KENDO_GRID_PACKAGES = ['@progress/kendo-react-grid', '@servicetitan/design-system'];\n\nexport function getMFEMaybeUsesKendoGrid(dependencies: Metadata['dependencies']) {\n return KENDO_GRID_PACKAGES.some(name => !!dependencies?.[name]);\n}\n"],"names":["KENDO_GRID_PACKAGES","getMFEMaybeUsesKendoGrid","dependencies","some","name"],"mappings":"AAEA;;;CAGC,GACD,MAAMA,sBAAsB;IAAC;IAA8B;CAA8B;AAEzF,OAAO,SAASC,yBAAyBC,YAAsC;IAC3E,OAAOF,oBAAoBG,IAAI,CAACC,CAAAA,OAAQ,CAAC,EAACF,yBAAAA,mCAAAA,YAAc,CAACE,KAAK;AAClE"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/patches/kendo-scrollbar-width/index.ts"],"names":[],"mappings":"AAAA,cAAc,iCAAiC,CAAC;AAChD,cAAc,6BAA6B,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/patches/kendo-scrollbar-width/index.ts"],"sourcesContent":["export * from './get-mfe-maybe-uses-kendo-grid';\nexport * from './set-kendo-scrollbar-width';\n"],"names":[],"mappings":"AAAA,cAAc,kCAAkC;AAChD,cAAc,8BAA8B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"set-kendo-scrollbar-width.d.ts","sourceRoot":"","sources":["../../../src/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.ts"],"names":[],"mappings":"AAOA,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,QAmB/E"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const KENDO_SCROLLBAR_WIDTH = '--kendo-scrollbar-width';
|
|
2
|
+
/*
|
|
3
|
+
* Kendo measures the scrollbar on document.body, where host scrollbar styles apply but MFE
|
|
4
|
+
* styles don't. Measure inside the MFE's shadow root instead, and set the result on the MFE
|
|
5
|
+
* element and its portals so it overrides the value they inherit from the body.
|
|
6
|
+
*/ export function setKendoScrollbarWidth(element, elementName) {
|
|
7
|
+
const root = element.shadowRoot;
|
|
8
|
+
if (!root) {
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const probe = document.createElement('div');
|
|
12
|
+
probe.style.cssText = 'overflow:scroll;overflow-x:hidden;zoom:1;clear:both;display:block';
|
|
13
|
+
probe.innerHTML = ' ';
|
|
14
|
+
root.appendChild(probe);
|
|
15
|
+
const width = `${probe.offsetWidth - probe.scrollWidth}px`;
|
|
16
|
+
probe.remove();
|
|
17
|
+
const portals = document.querySelectorAll(`[data-mfe-portal-name="${elementName}"]`);
|
|
18
|
+
for (const target of [
|
|
19
|
+
element,
|
|
20
|
+
...portals
|
|
21
|
+
]){
|
|
22
|
+
target.style.setProperty(KENDO_SCROLLBAR_WIDTH, width);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
//# sourceMappingURL=set-kendo-scrollbar-width.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../../src/patches/kendo-scrollbar-width/set-kendo-scrollbar-width.ts"],"sourcesContent":["const KENDO_SCROLLBAR_WIDTH = '--kendo-scrollbar-width';\n\n/*\n * Kendo measures the scrollbar on document.body, where host scrollbar styles apply but MFE\n * styles don't. Measure inside the MFE's shadow root instead, and set the result on the MFE\n * element and its portals so it overrides the value they inherit from the body.\n */\nexport function setKendoScrollbarWidth(element: HTMLElement, elementName: string) {\n const root = element.shadowRoot;\n if (!root) {\n return;\n }\n\n const probe = document.createElement('div');\n probe.style.cssText = 'overflow:scroll;overflow-x:hidden;zoom:1;clear:both;display:block';\n probe.innerHTML = ' ';\n root.appendChild(probe);\n const width = `${probe.offsetWidth - probe.scrollWidth}px`;\n probe.remove();\n\n const portals = document.querySelectorAll<HTMLElement>(\n `[data-mfe-portal-name=\"${elementName}\"]`\n );\n for (const target of [element, ...portals]) {\n target.style.setProperty(KENDO_SCROLLBAR_WIDTH, width);\n }\n}\n"],"names":["KENDO_SCROLLBAR_WIDTH","setKendoScrollbarWidth","element","elementName","root","shadowRoot","probe","document","createElement","style","cssText","innerHTML","appendChild","width","offsetWidth","scrollWidth","remove","portals","querySelectorAll","target","setProperty"],"mappings":"AAAA,MAAMA,wBAAwB;AAE9B;;;;CAIC,GACD,OAAO,SAASC,uBAAuBC,OAAoB,EAAEC,WAAmB;IAC5E,MAAMC,OAAOF,QAAQG,UAAU;IAC/B,IAAI,CAACD,MAAM;QACP;IACJ;IAEA,MAAME,QAAQC,SAASC,aAAa,CAAC;IACrCF,MAAMG,KAAK,CAACC,OAAO,GAAG;IACtBJ,MAAMK,SAAS,GAAG;IAClBP,KAAKQ,WAAW,CAACN;IACjB,MAAMO,QAAQ,GAAGP,MAAMQ,WAAW,GAAGR,MAAMS,WAAW,CAAC,EAAE,CAAC;IAC1DT,MAAMU,MAAM;IAEZ,MAAMC,UAAUV,SAASW,gBAAgB,CACrC,CAAC,uBAAuB,EAAEf,YAAY,EAAE,CAAC;IAE7C,KAAK,MAAMgB,UAAU;QAACjB;WAAYe;KAAQ,CAAE;QACxCE,OAAOV,KAAK,CAACW,WAAW,CAACpB,uBAAuBa;IACpD;AACJ"}
|
package/dist/register.js
CHANGED
|
@@ -87,7 +87,7 @@ export function register(Component, light, options) {
|
|
|
87
87
|
this.styles.elements.push(...this.attachStyles(this.root, styleUrls), ...this.attachStyles(this.portal, styleUrls));
|
|
88
88
|
}
|
|
89
89
|
disconnectedCallback() {
|
|
90
|
-
var _this_view,
|
|
90
|
+
var _this_view, _this_onDispose, _this;
|
|
91
91
|
if (!this.root || this.root.isConnected) {
|
|
92
92
|
return;
|
|
93
93
|
}
|
|
@@ -95,7 +95,7 @@ export function register(Component, light, options) {
|
|
|
95
95
|
element.remove();
|
|
96
96
|
}
|
|
97
97
|
(_this_view = this.view) === null || _this_view === void 0 ? void 0 : _this_view.unmount();
|
|
98
|
-
|
|
98
|
+
this.portal.host.remove();
|
|
99
99
|
this.root = undefined;
|
|
100
100
|
this.portal = undefined;
|
|
101
101
|
this.portalAnvilContainer = undefined;
|
package/dist/register.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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 { Anvil1Providers } from './anvil1-providers';\nimport { Anvil2Providers } from './anvil2-providers';\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 { withCssInjector } from './css-injector';\nimport { EVENT_BUS_TOKEN, EventBus } from './event-bus';\nimport { getStyleUrls } from './get-style-urls';\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 const WrappedComponent = withCssInjector(Component);\n\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 const version = this.getAttribute('data-mfe-version');\n if (version) {\n portalElement.setAttribute('data-mfe-version', version);\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(<WrappedComponent {...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 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","Anvil1Providers","Anvil2Providers","BASENAME_TOKEN","EXPOSED_DEPENDENCIES_TOKEN","EXPOSED_INSTANCE_DEPENDENCIES_TOKEN","IS_WEB_COMPONENT_TOKEN","RENDER_ROOT_TOKEN","MFEDataContext","MFEMetadataContext","withCssInjector","EVENT_BUS_TOKEN","getStyleUrls","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","WrappedComponent","WebComponent","HTMLElement","connectedCallback","root","isConnected","sharedDependenciesNames","styleUrls","styles","total","length","loaded","elements","shadowRoot","attachShadow","mode","portalElement","setAttribute","version","getAttribute","portal","body","appendChild","portalAnvilContainer","view","push","attachStyles","disconnectedCallback","remove","unmount","removeChild","host","undefined","onDispose","observedAttributes","attributeChangedCallback","withProviders","children","ldService","logService","historyManager","exposedDependencies","exposedInstanceDependencies","eventBus","basename","onReady","provide","entries","key","value","Object","handleLoad","node","urls","mfeData","dataset","JSON","parse","metadata","portalShadowRoot","rerender","singletons","useValue","filter","RenderCallback","callback","console","error","window","customElements","define"],"mappings":";;;;;;;;;;;;AACA,SAASA,GAAG,QAAQ,4BAA4B;AAChD,SAASC,QAAQ,QAAQ,0BAA0B;AAEnD,SAA0CC,SAAS,QAAQ,QAAQ;AACnE,SAASC,eAAe,QAAQ,qBAAqB;AACrD,SAASC,eAAe,QAAQ,qBAAqB;AACrD,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,QAAQ,iBAAiB;AACjD,SAASC,eAAe,QAAkB,cAAc;AACxD,SAASC,YAAY,QAAQ,mBAAmB;AAChD,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,mBAAmB3B,gBAAgBwB;IAEzC,MAAMI,qBAAqBC;QAsBvBC,oBAAoB;sBAkBJ;gBAZR;YALJ;;;;aAIC,GACD,KAAI,aAAA,IAAI,CAACC,IAAI,cAAT,iCAAA,WAAWC,WAA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1C;4BACGmG,YAAY;gCACR;oCAAEf,SAASrF;oCAAKqG,UAAU,IAAI,CAACvB,UAAU;gCAAC;gCAC1C;oCACIO,SAASrE;oCACTqF,UAAU,IAAI,CAACtB,cAAc;gCACjC;gCACA;oCACIM,SAAS/E;oCACT+F,UAAU,IAAI,CAACrB,mBAAmB;gCACtC;gCACA;oCACIK,SAAS9E;oCACT8F,UAAU,IAAI,CAACpB,2BAA2B;gCAC9C;gCACA;oCAAEI,SAAShF;oCAAgBgG,UAAU,IAAI,CAAClB,QAAQ;gCAAC;gCACnD;oCAAEE,SAASxE;oCAAiBwF,UAAU,IAAI,CAACnB,QAAQ;gCAAC;gCACpD;oCAAEG,SAASlE;oCAAqBkF,UAAU,IAAI,CAACxB,SAAS;gCAAC;6BAC5D,CAACyB,MAAM,CACJ,CAAC,EAAEjB,OAAO,EAAEgB,QAAQ,EAAE,GAClBA,aAAa9B,aAAac,YAAYd;sCAG9C,cAAA,KAAC7D,eAAeT,QAAQ;gCAACuF,OAAO;oCAAE,GAAGK,OAAO;gCAAC;0CACzC,cAAA,MAAClF,mBAAmBV,QAAQ;oCAACuF,OAAOS;;wCAC/B,IAAI,CAACtB,aAAa,eAAC,KAACpC;4CAAkB,GAAGsD,OAAO;;wCAChD,IAAI,CAACT,OAAO,kBAAI,KAACmB;4CAAeC,UAAU,IAAI,CAACpB,OAAO;;;;;;;gBAM/E;YACJ;;IACJ;IAEA,IAAI,CAACrE,oBAAoB;QACrB,sCAAsC;QACtC0F,QAAQC,KAAK,CAAC;QACd;IACJ;IAEAC,OAAOC,cAAc,CAACC,MAAM,CAAC9F,oBAAoByB;AACrD;AAEA,SAAS+D,eAAe,EAAEC,QAAQ,EAA4B;IAC1D,uDAAuD;IACvDtG,UAAU,IAAMsG,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 { Anvil1Providers } from './anvil1-providers';\nimport { Anvil2Providers } from './anvil2-providers';\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 { withCssInjector } from './css-injector';\nimport { EVENT_BUS_TOKEN, EventBus } from './event-bus';\nimport { getStyleUrls } from './get-style-urls';\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 const WrappedComponent = withCssInjector(Component);\n\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 const version = this.getAttribute('data-mfe-version');\n if (version) {\n portalElement.setAttribute('data-mfe-version', version);\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 this.portal!.host.remove();\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(<WrappedComponent {...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 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","Anvil1Providers","Anvil2Providers","BASENAME_TOKEN","EXPOSED_DEPENDENCIES_TOKEN","EXPOSED_INSTANCE_DEPENDENCIES_TOKEN","IS_WEB_COMPONENT_TOKEN","RENDER_ROOT_TOKEN","MFEDataContext","MFEMetadataContext","withCssInjector","EVENT_BUS_TOKEN","getStyleUrls","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","WrappedComponent","WebComponent","HTMLElement","connectedCallback","root","isConnected","sharedDependenciesNames","styleUrls","styles","total","length","loaded","elements","shadowRoot","attachShadow","mode","portalElement","setAttribute","version","getAttribute","portal","body","appendChild","portalAnvilContainer","view","push","attachStyles","disconnectedCallback","remove","unmount","host","undefined","onDispose","observedAttributes","attributeChangedCallback","withProviders","children","ldService","logService","historyManager","exposedDependencies","exposedInstanceDependencies","eventBus","basename","onReady","provide","entries","key","value","Object","handleLoad","node","urls","mfeData","dataset","JSON","parse","metadata","portalShadowRoot","rerender","singletons","useValue","filter","RenderCallback","callback","console","error","window","customElements","define"],"mappings":";;;;;;;;;;;;AACA,SAASA,GAAG,QAAQ,4BAA4B;AAChD,SAASC,QAAQ,QAAQ,0BAA0B;AAEnD,SAA0CC,SAAS,QAAQ,QAAQ;AACnE,SAASC,eAAe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gB+F,UAAU,IAAI,CAAClB,QAAQ;gCAAC;gCACnD;oCAAEE,SAASvE;oCAAiBuF,UAAU,IAAI,CAACnB,QAAQ;gCAAC;gCACpD;oCAAEG,SAASjE;oCAAqBiF,UAAU,IAAI,CAACxB,SAAS;gCAAC;6BAC5D,CAACyB,MAAM,CACJ,CAAC,EAAEjB,OAAO,EAAEgB,QAAQ,EAAE,GAClBA,aAAa9B,aAAac,YAAYd;sCAG9C,cAAA,KAAC5D,eAAeT,QAAQ;gCAACsF,OAAO;oCAAE,GAAGK,OAAO;gCAAC;0CACzC,cAAA,MAACjF,mBAAmBV,QAAQ;oCAACsF,OAAOS;;wCAC/B,IAAI,CAACtB,aAAa,eAAC,KAACnC;4CAAkB,GAAGqD,OAAO;;wCAChD,IAAI,CAACT,OAAO,kBAAI,KAACmB;4CAAeC,UAAU,IAAI,CAACpB,OAAO;;;;;;;gBAM/E;YACJ;;IACJ;IAEA,IAAI,CAACpE,oBAAoB;QACrB,sCAAsC;QACtCyF,QAAQC,KAAK,CAAC;QACd;IACJ;IAEAC,OAAOC,cAAc,CAACC,MAAM,CAAC7F,oBAAoByB;AACrD;AAEA,SAAS8D,eAAe,EAAEC,QAAQ,EAA4B;IAC1D,uDAAuD;IACvDrG,UAAU,IAAMqG,YAAY,EAAE;IAC9B,OAAO;AACX"}
|
package/dist/use-prefetch.d.ts
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { LoaderProps } from './loader';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* @returns Promise resolving to the BundleInfo
|
|
3
|
+
* Returns a stable `prefetch` function that prefetches and caches an MFE's bundle,
|
|
4
|
+
* so that Loader can load it faster later.
|
|
6
5
|
*/
|
|
7
6
|
export declare function usePrefetch(): {
|
|
8
7
|
prefetch: (src: string, { cache }?: Pick<LoaderProps<any>, "cache">) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-prefetch.d.ts","sourceRoot":"","sources":["../src/use-prefetch.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-prefetch.d.ts","sourceRoot":"","sources":["../src/use-prefetch.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAGvC;;;GAGG;AACH,wBAAgB,WAAW;oBASP,MAAM,cAAkB,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC;EAmC1E"}
|
package/dist/use-prefetch.js
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
import { Log } from '@servicetitan/log-service';
|
|
2
2
|
import { useOptionalDependencies } from '@servicetitan/react-ioc';
|
|
3
|
+
import { useCallback, useMemo } from 'react';
|
|
3
4
|
import { EXPOSED_DEPENDENCIES_TOKEN, EXPOSED_INSTANCE_DEPENDENCIES_TOKEN } from './common';
|
|
5
|
+
import { EXPOSED_DEPENDENCIES, EXPOSED_INSTANCE_DEPENDENCIES } from './globals';
|
|
4
6
|
import { getBundleInfo, supportsPrefetch } from './utils';
|
|
5
7
|
/**
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* @returns Promise resolving to the BundleInfo
|
|
8
|
+
* Returns a stable `prefetch` function that prefetches and caches an MFE's bundle,
|
|
9
|
+
* so that Loader can load it faster later.
|
|
9
10
|
*/ export function usePrefetch() {
|
|
10
11
|
const [logService, exposedDependencies = EXPOSED_DEPENDENCIES] = useOptionalDependencies(Log, EXPOSED_DEPENDENCIES_TOKEN);
|
|
11
12
|
const [exposedInstanceDependencies = EXPOSED_INSTANCE_DEPENDENCIES] = useOptionalDependencies(EXPOSED_INSTANCE_DEPENDENCIES_TOKEN);
|
|
12
|
-
const prefetch = async (src, { cache = -1 } = {})=>{
|
|
13
|
+
const prefetch = useCallback(async (src, { cache = -1 } = {})=>{
|
|
13
14
|
try {
|
|
14
15
|
const bundleInfo = await getBundleInfo({
|
|
15
16
|
exposedDependencies,
|
|
@@ -48,10 +49,16 @@ import { getBundleInfo, supportsPrefetch } from './utils';
|
|
|
48
49
|
data: e
|
|
49
50
|
});
|
|
50
51
|
}
|
|
51
|
-
}
|
|
52
|
-
|
|
52
|
+
}, [
|
|
53
|
+
logService,
|
|
54
|
+
exposedDependencies,
|
|
55
|
+
exposedInstanceDependencies
|
|
56
|
+
]);
|
|
57
|
+
return useMemo(()=>({
|
|
58
|
+
prefetch
|
|
59
|
+
}), [
|
|
53
60
|
prefetch
|
|
54
|
-
|
|
61
|
+
]);
|
|
55
62
|
}
|
|
56
63
|
function addLinks(links) {
|
|
57
64
|
const existingLinks = document.head.getElementsByTagName('link');
|
package/dist/use-prefetch.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/use-prefetch.ts"],"sourcesContent":["import { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { EXPOSED_DEPENDENCIES_TOKEN, EXPOSED_INSTANCE_DEPENDENCIES_TOKEN } from './common';\nimport { LoaderProps } from './loader';\nimport { getBundleInfo, supportsPrefetch } from './utils';\n\n/**\n *
|
|
1
|
+
{"version":3,"sources":["../src/use-prefetch.ts"],"sourcesContent":["import { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { useCallback, useMemo } from 'react';\nimport { EXPOSED_DEPENDENCIES_TOKEN, EXPOSED_INSTANCE_DEPENDENCIES_TOKEN } from './common';\nimport { EXPOSED_DEPENDENCIES, EXPOSED_INSTANCE_DEPENDENCIES } from './globals';\nimport { LoaderProps } from './loader';\nimport { getBundleInfo, supportsPrefetch } from './utils';\n\n/**\n * Returns a stable `prefetch` function that prefetches and caches an MFE's bundle,\n * so that Loader can load it faster later.\n */\nexport function usePrefetch() {\n const [logService, exposedDependencies = EXPOSED_DEPENDENCIES] = useOptionalDependencies(\n Log,\n EXPOSED_DEPENDENCIES_TOKEN\n );\n const [exposedInstanceDependencies = EXPOSED_INSTANCE_DEPENDENCIES] = useOptionalDependencies(\n EXPOSED_INSTANCE_DEPENDENCIES_TOKEN\n );\n const prefetch = useCallback(\n async (src: string, { cache = -1 }: Pick<LoaderProps<any>, 'cache'> = {}) => {\n try {\n const bundleInfo = await getBundleInfo({\n exposedDependencies,\n exposedInstanceDependencies,\n mainPackageUrl: src,\n cache,\n retries: 0,\n });\n\n if (bundleInfo.cacheHit) {\n return;\n }\n\n const { css, js } = bundleInfo.urls;\n if (supportsPrefetch()) {\n addLinks([\n ...css.map(href => ({ href, as: 'style' })),\n ...js.map(href => ({ href, as: 'script' })),\n ]);\n } else {\n await Promise.all([...css, ...js].map(url => fetch(url, { priority: 'low' })));\n }\n } catch (e: any) {\n logService?.warning({\n category: 'Microfrontends.Prefetch',\n message: `Failed to prefetch ${src}`,\n data: e,\n });\n }\n },\n [logService, exposedDependencies, exposedInstanceDependencies]\n );\n\n return useMemo(() => ({ prefetch }), [prefetch]);\n}\n\ninterface Link {\n as: string;\n href: string;\n}\n\nfunction addLinks(links: Link[]) {\n const existingLinks = document.head.getElementsByTagName('link');\n const existingHrefs = new Set(Array.from(existingLinks).map(({ href }) => href));\n\n links.forEach(({ as, href }) => {\n if (!existingHrefs.has(href)) {\n const link = document.createElement('link');\n link.as = as;\n link.crossOrigin = 'anonymous';\n link.href = href;\n link.rel = 'prefetch';\n document.head.append(link);\n }\n });\n}\n"],"names":["Log","useOptionalDependencies","useCallback","useMemo","EXPOSED_DEPENDENCIES_TOKEN","EXPOSED_INSTANCE_DEPENDENCIES_TOKEN","EXPOSED_DEPENDENCIES","EXPOSED_INSTANCE_DEPENDENCIES","getBundleInfo","supportsPrefetch","usePrefetch","logService","exposedDependencies","exposedInstanceDependencies","prefetch","src","cache","bundleInfo","mainPackageUrl","retries","cacheHit","css","js","urls","addLinks","map","href","as","Promise","all","url","fetch","priority","e","warning","category","message","data","links","existingLinks","document","head","getElementsByTagName","existingHrefs","Set","Array","from","forEach","has","link","createElement","crossOrigin","rel","append"],"mappings":"AAA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ACJ;IACJ,GACA;QAACtB;QAAYC;QAAqBC;KAA4B;IAGlE,OAAOV,QAAQ,IAAO,CAAA;YAAEW;QAAS,CAAA,GAAI;QAACA;KAAS;AACnD;AAOA,SAASU,SAASc,KAAa;IAC3B,MAAMC,gBAAgBC,SAASC,IAAI,CAACC,oBAAoB,CAAC;IACzD,MAAMC,gBAAgB,IAAIC,IAAIC,MAAMC,IAAI,CAACP,eAAed,GAAG,CAAC,CAAC,EAAEC,IAAI,EAAE,GAAKA;IAE1EY,MAAMS,OAAO,CAAC,CAAC,EAAEpB,EAAE,EAAED,IAAI,EAAE;QACvB,IAAI,CAACiB,cAAcK,GAAG,CAACtB,OAAO;YAC1B,MAAMuB,OAAOT,SAASU,aAAa,CAAC;YACpCD,KAAKtB,EAAE,GAAGA;YACVsB,KAAKE,WAAW,GAAG;YACnBF,KAAKvB,IAAI,GAAGA;YACZuB,KAAKG,GAAG,GAAG;YACXZ,SAASC,IAAI,CAACY,MAAM,CAACJ;QACzB;IACJ;AACJ"}
|
|
@@ -19,6 +19,7 @@ export declare function getBundleInfo({ cache, mainPackageUrl, fallbackPackageUr
|
|
|
19
19
|
mfeHasUniqueChunkNamespace: boolean;
|
|
20
20
|
mfeHasCompatibleLaunchDarklyVersion: boolean | undefined;
|
|
21
21
|
mfeSupportsVersionedLDClient: boolean;
|
|
22
|
+
mfeMaybeUsesKendoGrid: boolean;
|
|
22
23
|
mismatch: Record<string, {
|
|
23
24
|
host: string;
|
|
24
25
|
package: string;
|
|
@@ -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;AAExF,OAAO,EAAE,2BAA2B,EAAW,YAAY,EAAE,MAAM,WAAW,CAAC;
|
|
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;AAExF,OAAO,EAAE,2BAA2B,EAAW,YAAY,EAAE,MAAM,WAAW,CAAC;AAK/E,OAAO,EAAE,WAAW,EAAkB,MAAM,oBAAoB,CAAC;AAMjE,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;CACpB;AAED,wBAAsB,aAAa,CAAC,EAChC,KAAK,EACL,cAAc,EACd,kBAAkB,EAClB,mBAAwB,EACxB,2BAAgC,EAChC,UAAU,EACV,OAAO,EACP,cAAc,GACjB,EAAE,kBAAkB;;;;;;;;;;;;;;;;;GAoFpB"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { getVersionMismatches } from '@servicetitan/startup-utils';
|
|
2
2
|
import semver from 'semver';
|
|
3
3
|
import { getJson } from '../common';
|
|
4
|
+
import { getMFEMaybeUsesKendoGrid } from '../patches/kendo-scrollbar-width';
|
|
4
5
|
import { getCacheSetting } from './get-cache-setting';
|
|
5
6
|
import { getCachedMetadata } from './get-cached-metadata';
|
|
6
7
|
import { getEntrypoints } from './get-entry-points';
|
|
@@ -67,6 +68,7 @@ export async function getBundleInfo({ cache, mainPackageUrl, fallbackPackageUrl,
|
|
|
67
68
|
mfeHasUniqueChunkNamespace: getMFEHasUniqueChunkNamespace(bundledWith),
|
|
68
69
|
mfeHasCompatibleLaunchDarklyVersion: getMFEHasCompatibleLaunchDarklyVersion(bundledWith, exposedInstanceDependencies),
|
|
69
70
|
mfeSupportsVersionedLDClient: getMFESupportsVersionedLDClient(bundledWith),
|
|
71
|
+
mfeMaybeUsesKendoGrid: getMFEMaybeUsesKendoGrid(dependencies),
|
|
70
72
|
mismatch,
|
|
71
73
|
resolvedBundleType,
|
|
72
74
|
urls,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/get-bundle-info.ts"],"sourcesContent":["import { ExposedDependencies, getVersionMismatches } from '@servicetitan/startup-utils';\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';\nimport { getMFESupportsVersionedLDClient } from './get-mfe-supports-versioned-ld-client';\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}\n\nexport async function getBundleInfo({\n cache,\n mainPackageUrl,\n fallbackPackageUrl,\n exposedDependencies = {},\n exposedInstanceDependencies = {},\n isHeadless,\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 });\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 });\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 bundleBaseUrl = `${exactPackageUrl}/dist/bundle/${resolvedBundleType}`;\n\n let entrypoints: EntryPoints;\n if (metadata.entrypoints?.[resolvedBundleType]) {\n entrypoints = metadata.entrypoints[resolvedBundleType];\n } else {\n entrypoints = await getEntrypoints(`${bundleBaseUrl}/entrypoints.json`, requestCache);\n }\n\n let baseUrl = bundleBaseUrl;\n // Per-MFE dev-server port only happens during local development\n if (process.env.NODE_ENV !== 'production' && entrypoints.port) {\n const url = new URL(baseUrl);\n url.port = String(entrypoints.port);\n baseUrl = url.toString();\n }\n\n const urls: EntryPoints = {\n css: entrypoints.css.map(path => `${baseUrl}/${path}`),\n js: entrypoints.js.map(path => `${baseUrl}/${path}`),\n };\n\n const elementName = resolvedBundleType === 'headless' ? `headless-${name}` : name;\n\n return {\n bundledWith,\n cacheHit,\n mfeSupportsRerendering: getMFESupportsRerendering(bundledWith, dependencies),\n mfeHasUniqueChunkNamespace: getMFEHasUniqueChunkNamespace(bundledWith),\n mfeHasCompatibleLaunchDarklyVersion: getMFEHasCompatibleLaunchDarklyVersion(\n bundledWith,\n exposedInstanceDependencies\n ),\n mfeSupportsVersionedLDClient: getMFESupportsVersionedLDClient(bundledWith),\n mismatch,\n resolvedBundleType,\n urls,\n WebComponent: elementName,\n version: metadata.version,\n module: entrypoints.module,\n };\n}\n"],"names":["getVersionMismatches","semver","getJson","getCacheSetting","getCachedMetadata","getEntrypoints","getMFEHasCompatibleLaunchDarklyVersion","getMFEHasUniqueChunkNamespace","getMFESupportsRerendering","getMFESupportsVersionedLDClient","getBundleInfo","cache","mainPackageUrl","fallbackPackageUrl","exposedDependencies","exposedInstanceDependencies","isHeadless","retries","onRequestError","metadata","cacheHit","data","url","packageUrl","bundledWith","name","sharedDependencies","exactPackageUrl","replace","requestCache","dependencies","packageJson","mismatch","resolvedBundleType","startupVersion","supportLightBundles","gte","embed","bundleBaseUrl","entrypoints","baseUrl","process","env","NODE_ENV","port","URL","String","toString","urls","css","map","path","js","elementName","mfeSupportsRerendering","mfeHasUniqueChunkNamespace","mfeHasCompatibleLaunchDarklyVersion","mfeSupportsVersionedLDClient","WebComponent","version","module"],"mappings":"AAAA,SAA8BA,oBAAoB,QAAQ,8BAA8B;AACxF,OAAOC,YAAY,SAAS;AAC5B,SAAsCC,OAAO,QAAsB,YAAY;
|
|
1
|
+
{"version":3,"sources":["../../src/utils/get-bundle-info.ts"],"sourcesContent":["import { ExposedDependencies, getVersionMismatches } from '@servicetitan/startup-utils';\nimport semver from 'semver';\nimport { ExposedInstanceDependencies, getJson, GetJsonError } from '../common';\nimport { getMFEMaybeUsesKendoGrid } from '../patches/kendo-scrollbar-width';\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';\nimport { getMFESupportsVersionedLDClient } from './get-mfe-supports-versioned-ld-client';\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}\n\nexport async function getBundleInfo({\n cache,\n mainPackageUrl,\n fallbackPackageUrl,\n exposedDependencies = {},\n exposedInstanceDependencies = {},\n isHeadless,\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 });\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 });\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 bundleBaseUrl = `${exactPackageUrl}/dist/bundle/${resolvedBundleType}`;\n\n let entrypoints: EntryPoints;\n if (metadata.entrypoints?.[resolvedBundleType]) {\n entrypoints = metadata.entrypoints[resolvedBundleType];\n } else {\n entrypoints = await getEntrypoints(`${bundleBaseUrl}/entrypoints.json`, requestCache);\n }\n\n let baseUrl = bundleBaseUrl;\n // Per-MFE dev-server port only happens during local development\n if (process.env.NODE_ENV !== 'production' && entrypoints.port) {\n const url = new URL(baseUrl);\n url.port = String(entrypoints.port);\n baseUrl = url.toString();\n }\n\n const urls: EntryPoints = {\n css: entrypoints.css.map(path => `${baseUrl}/${path}`),\n js: entrypoints.js.map(path => `${baseUrl}/${path}`),\n };\n\n const elementName = resolvedBundleType === 'headless' ? `headless-${name}` : name;\n\n return {\n bundledWith,\n cacheHit,\n mfeSupportsRerendering: getMFESupportsRerendering(bundledWith, dependencies),\n mfeHasUniqueChunkNamespace: getMFEHasUniqueChunkNamespace(bundledWith),\n mfeHasCompatibleLaunchDarklyVersion: getMFEHasCompatibleLaunchDarklyVersion(\n bundledWith,\n exposedInstanceDependencies\n ),\n mfeSupportsVersionedLDClient: getMFESupportsVersionedLDClient(bundledWith),\n mfeMaybeUsesKendoGrid: getMFEMaybeUsesKendoGrid(dependencies),\n mismatch,\n resolvedBundleType,\n urls,\n WebComponent: elementName,\n version: metadata.version,\n module: entrypoints.module,\n };\n}\n"],"names":["getVersionMismatches","semver","getJson","getMFEMaybeUsesKendoGrid","getCacheSetting","getCachedMetadata","getEntrypoints","getMFEHasCompatibleLaunchDarklyVersion","getMFEHasUniqueChunkNamespace","getMFESupportsRerendering","getMFESupportsVersionedLDClient","getBundleInfo","cache","mainPackageUrl","fallbackPackageUrl","exposedDependencies","exposedInstanceDependencies","isHeadless","retries","onRequestError","metadata","cacheHit","data","url","packageUrl","bundledWith","name","sharedDependencies","exactPackageUrl","replace","requestCache","dependencies","packageJson","mismatch","resolvedBundleType","startupVersion","supportLightBundles","gte","embed","bundleBaseUrl","entrypoints","baseUrl","process","env","NODE_ENV","port","URL","String","toString","urls","css","map","path","js","elementName","mfeSupportsRerendering","mfeHasUniqueChunkNamespace","mfeHasCompatibleLaunchDarklyVersion","mfeSupportsVersionedLDClient","mfeMaybeUses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cN;QACdO,SAASzC,SAASyC,OAAO;QACzBC,QAAQtB,YAAYsB,MAAM;IAC9B;AACJ"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web-component.d.ts","sourceRoot":"","sources":["../../src/utils/web-component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,2BAA2B,EAAiB,MAAM,WAAW,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"web-component.d.ts","sourceRoot":"","sources":["../../src/utils/web-component.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,oCAAoC,CAAC;AACpE,OAAO,EAAE,GAAG,EAAE,MAAM,2BAA2B,CAAC;AAEhD,OAAO,EAAE,mBAAmB,EAAE,MAAM,6BAA6B,CAAC;AAElE,OAAO,EAAE,2BAA2B,EAAiB,MAAM,WAAW,CAAC;AAEvE,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAE5C,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAG/C,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,2BAA2B,CAAC,EAAE,2BAA2B,CAAC;IAC1D,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,UAAU,CAAC,EAAE,GAAG,CAAC;CACpB;AAED,wBAAgB,YAAY,CAAC,KAAK,EAAE,iBAAiB,IAgBzC,oCAAoC,eAAe,6CAoE9D"}
|
|
@@ -1,18 +1,21 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useOptionalDependencies } from '@servicetitan/react-ioc';
|
|
3
|
-
import { Fragment, useMemo, useState } from 'react';
|
|
3
|
+
import { Fragment, useLayoutEffect, useMemo, useRef, useState } from 'react';
|
|
4
4
|
import { HistoryManager } from '../history-manager';
|
|
5
|
+
import { setKendoScrollbarWidth } from '../patches/kendo-scrollbar-width';
|
|
5
6
|
import { getElementName } from './get-element-name';
|
|
6
7
|
export function webComponent(props) {
|
|
7
8
|
var _bundleInfo_bundledWith;
|
|
8
9
|
const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;
|
|
9
|
-
const { WebComponent, resolvedBundleType, mfeSupportsRerendering, version } = bundleInfo;
|
|
10
|
+
const { WebComponent, resolvedBundleType, mfeSupportsRerendering, mfeMaybeUsesKendoGrid, version } = bundleInfo;
|
|
10
11
|
const elementName = getElementName(bundleInfo);
|
|
11
12
|
const exposedInstanceDependencies = ensureLDVersion(props.exposedInstanceDependencies, (_bundleInfo_bundledWith = bundleInfo.bundledWith) === null || _bundleInfo_bundledWith === void 0 ? void 0 : _bundleInfo_bundledWith['launchdarkly-js-client-sdk']);
|
|
12
13
|
return ({ LoadingFallback, ...innerProps })=>{
|
|
13
14
|
const [isLoading, setIsLoading] = useState(true);
|
|
14
15
|
const [historyManager] = useOptionalDependencies(HistoryManager);
|
|
16
|
+
const elementRef = useRef(null);
|
|
15
17
|
const handleRef = (webComponent)=>{
|
|
18
|
+
elementRef.current = webComponent;
|
|
16
19
|
webComponent === null || webComponent === void 0 ? void 0 : webComponent.provide({
|
|
17
20
|
ldService,
|
|
18
21
|
logService,
|
|
@@ -36,6 +39,14 @@ export function webComponent(props) {
|
|
|
36
39
|
* the web component will be re-mounted whenever the data changes.
|
|
37
40
|
* This is only used as a fallback when the MFE's version is older.
|
|
38
41
|
*/ const key = mfeSupportsRerendering ? undefined : stringifiedData;
|
|
42
|
+
// Measure after the element is visible, since a hidden element has no scrollbar.
|
|
43
|
+
useLayoutEffect(()=>{
|
|
44
|
+
if (mfeMaybeUsesKendoGrid && !isLoading && elementRef.current) {
|
|
45
|
+
setKendoScrollbarWidth(elementRef.current, elementName);
|
|
46
|
+
}
|
|
47
|
+
}, [
|
|
48
|
+
isLoading
|
|
49
|
+
]);
|
|
39
50
|
const dataAttrs = useMemo(()=>composeDataAttributes(innerProps.data), [
|
|
40
51
|
innerProps.data
|
|
41
52
|
]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/utils/web-component.tsx"],"sourcesContent":["import { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport { Fragment, useMemo, useState } from 'react';\nimport { ExposedInstanceDependencies, IWebComponent } from '../common';\nimport { MFEContextData } from '../contexts/mfe-data-context';\nimport { EventBus } from '../event-bus';\nimport { HistoryManager } from '../history-manager';\nimport { LoaderDataProps } from '../loader';\nimport { BundleInfo } from './get-bundle-info';\nimport { getElementName } from './get-element-name';\n\ninterface WebComponentProps {\n basename?: string;\n bundleInfo: BundleInfo;\n eventBus: EventBus;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n ldService?: LDService;\n logService?: Log;\n}\n\nexport function webComponent(props: WebComponentProps) {\n const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;\n const {
|
|
1
|
+
{"version":3,"sources":["../../src/utils/web-component.tsx"],"sourcesContent":["import { type LDService } from '@servicetitan/launchdarkly-service';\nimport { Log } from '@servicetitan/log-service';\nimport { useOptionalDependencies } from '@servicetitan/react-ioc';\nimport { ExposedDependencies } from '@servicetitan/startup-utils';\nimport { Fragment, useLayoutEffect, useMemo, useRef, useState } from 'react';\nimport { ExposedInstanceDependencies, IWebComponent } from '../common';\nimport { MFEContextData } from '../contexts/mfe-data-context';\nimport { EventBus } from '../event-bus';\nimport { HistoryManager } from '../history-manager';\nimport { LoaderDataProps } from '../loader';\nimport { setKendoScrollbarWidth } from '../patches/kendo-scrollbar-width';\nimport { BundleInfo } from './get-bundle-info';\nimport { getElementName } from './get-element-name';\n\ninterface WebComponentProps {\n basename?: string;\n bundleInfo: BundleInfo;\n eventBus: EventBus;\n exposedDependencies?: ExposedDependencies;\n exposedInstanceDependencies?: ExposedInstanceDependencies;\n ldService?: LDService;\n logService?: Log;\n}\n\nexport function webComponent(props: WebComponentProps) {\n const { basename, bundleInfo, eventBus, exposedDependencies, ldService, logService } = props;\n const {\n WebComponent,\n resolvedBundleType,\n mfeSupportsRerendering,\n mfeMaybeUsesKendoGrid,\n version,\n } = bundleInfo;\n const elementName = getElementName(bundleInfo);\n\n const exposedInstanceDependencies = ensureLDVersion(\n props.exposedInstanceDependencies,\n bundleInfo.bundledWith?.['launchdarkly-js-client-sdk']\n );\n\n return ({ LoadingFallback, ...innerProps }: LoaderDataProps) => {\n const [isLoading, setIsLoading] = useState(true);\n const [historyManager] = useOptionalDependencies(HistoryManager);\n const elementRef = useRef<(IWebComponent & HTMLElement) | null>(null);\n\n const handleRef = (webComponent: (IWebComponent & HTMLElement) | null) => {\n elementRef.current = webComponent;\n webComponent?.provide({\n ldService,\n logService,\n historyManager,\n exposedDependencies,\n exposedInstanceDependencies,\n eventBus,\n basename,\n onReady: () => {\n setIsLoading(false);\n },\n });\n };\n\n // Stringify data object so that it can be passed as a data-attribute\n const stringifiedData = useMemo(() => JSON.stringify(innerProps.data), [innerProps.data]);\n\n /*\n * Set key for rendering the web component so that if the data from the Host change,\n * and the MFE's version of startup doesn't support watching for data changes, then\n * the web component will be re-mounted whenever the data changes.\n * This is only used as a fallback when the MFE's version is older.\n */\n const key = mfeSupportsRerendering ? undefined : stringifiedData;\n\n // Measure after the element is visible, since a hidden element has no scrollbar.\n useLayoutEffect(() => {\n if (mfeMaybeUsesKendoGrid && !isLoading && elementRef.current) {\n setKendoScrollbarWidth(elementRef.current, elementName);\n }\n }, [isLoading]);\n\n const dataAttrs = useMemo(() => composeDataAttributes(innerProps.data), [innerProps.data]);\n const styleUrls = getStyleUrls(bundleInfo);\n\n return (\n <Fragment>\n {isLoading && <LoadingFallback />}\n <WebComponent\n key={key}\n ref={handleRef}\n class={innerProps.className}\n {...(styleUrls && { 'style-urls': styleUrls })}\n /*\n * Continue to spread data as separate data attributes for backwards compatibility,\n * in case the Host has updated web-components, but the MFE has not\n */\n {...dataAttrs}\n data-mfe-data={stringifiedData}\n data-mfe-name={elementName}\n {...(version && { 'data-mfe-version': version })}\n // @ts-expect-error style exists on HTMLElement\n style={\n isLoading || resolvedBundleType === 'headless'\n ? { display: 'none' }\n : undefined\n }\n />\n </Fragment>\n );\n };\n}\n\n/*\n * Convert camelCase data props to kebab-case data attributes, prepended with data-\n * Ex: fooBar -> data-foo-bar\n */\nfunction composeDataAttributes(data: MFEContextData<{}> | undefined = {}) {\n return Object.fromEntries(\n Object.entries(data).map(([key, value]) => [\n 'data-' + key.replace(/[A-Z]/g, letter => '-' + letter.toLowerCase()),\n value,\n ])\n );\n}\n\nfunction ensureLDVersion(\n exposedInstanceDependencies: ExposedInstanceDependencies = {},\n version?: string\n) {\n if (version && !exposedInstanceDependencies.launchDarkly?.ldService) {\n return { ...exposedInstanceDependencies, launchDarkly: { version } };\n }\n return exposedInstanceDependencies;\n}\n\nfunction getStyleUrls({ urls }: Pick<BundleInfo, 'urls'>) {\n if (urls.css.length) {\n return encodeURIComponent(JSON.stringify(urls.css));\n }\n}\n"],"names":["useOptionalDependencies","Fragment","useLayoutEffect","useMemo","useRef","useState","HistoryManager","setKendoScrollbarWidth","getElementName","webComponent","props","bundleInfo","basename","eventBus","exposedDependencies","ldService","logService","WebComponent","resolvedBundleType","mfeSupportsRerendering","mfeMaybeUsesKendoGrid","version","elementName","exposedInstanceDependencies","ensureLDVersion","bundledWith","LoadingFallback","innerProps","isLoading","setIsLoading","historyManager","elementRef","handleRef","current","provide","onReady","stringifiedData","JSON","stringify","data","key","undefined","dataAttrs","composeDataAttributes","styleUrls","getStyleUrls","ref","class","className","data-mfe-data","data-mfe-name","style","display","Object","fromEntries","entries","map","value","replace","letter","toLowerCase","launchDarkly","urls","css","length","encodeURIComponent"],"mappings":";AAEA,SAASA,uBAAuB,QAAQ,0BAA0B;AAElE,SAASC,QAAQ,EAAEC,eAAe,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAI7E,SAASC,cAAc,QAAQ,qBAAqB;AAEpD,SAASC,sBAAsB,QAAQ,mCAAmC;AAE1E,SAASC,cAAc,QAAQ,qBAAqB;AAYpD,OAAO,SAASC,aAAaC,KAAwB;QAa7CC;IAZJ,MAAM,EAAEC,QAAQ,EAAED,UAAU,EAAEE,QAAQ,EAAEC,mBAAmB,EAAEC,SAAS,EAAEC,UAAU,EAAE,GAAGN;IACvF,MAAM,EACFO,YAAY,EACZC,kBAAkB,EAClBC,sBAAsB,EACtBC,qBAAqB,EACrBC,OAAO,EACV,GAAGV;IACJ,MAAMW,cAAcd,eAAeG;IAEnC,MAAMY,8BAA8BC,gBAChCd,MAAMa,2BAA2B,GACjCZ,0BAAAA,WAAWc,WAAW,cAAtBd,8CAAAA,uBAAwB,CAAC,6BAA6B;IAG1D,OAAO,CAAC,EAAEe,eAAe,EAAE,GAAGC,YAA6B;QACvD,MAAM,CAACC,WAAWC,aAAa,GAAGxB,SAAS;QAC3C,MAAM,CAACyB,eAAe,GAAG9B,wBAAwBM;QACjD,MAAMyB,aAAa3B,OAA6C;QAEhE,MAAM4B,YAAY,CAACvB;YACfsB,WAAWE,OAAO,GAAGxB;YACrBA,yBAAAA,mCAAAA,aAAcyB,OAAO,CAAC;gBAClBnB;gBACAC;gBACAc;gBACAhB;gBACAS;gBACAV;gBACAD;g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