@wf-financing/ui 3.9.2 → 3.10.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wf-financing/ui",
3
- "version": "3.9.2",
3
+ "version": "3.10.0",
4
4
  "exports": {
5
5
  ".": {
6
6
  "import": "./dist/index.es.js",
package/src/main.tsx CHANGED
@@ -5,7 +5,7 @@ import { StyleSheetManager } from 'styled-components';
5
5
  import { MotionGlobalConfig } from 'framer-motion';
6
6
  import { App } from './App';
7
7
  import { PartnerTheme } from './config';
8
- import { applyFont, createRoots } from './utils';
8
+ import { applyFont, applyStyles, createRoots } from './utils';
9
9
 
10
10
  let root: ReactDOM.Root | undefined;
11
11
  let savedTargetId: string | undefined;
@@ -26,9 +26,10 @@ export const mountToTarget = async (
26
26
  const hostEl = document.getElementById(savedTargetId as string);
27
27
  if (!hostEl) throw new Error(`Target element with id "${savedTargetId}" not found.`);
28
28
 
29
- const shadow = hostEl.shadowRoot ?? hostEl.attachShadow({ mode: 'open' });
29
+ const shadow = hostEl.shadowRoot ?? (hostEl.attachShadow({ mode: 'open' }) as ShadowRoot);
30
30
 
31
31
  try {
32
+ applyStyles({ shadow });
32
33
  await applyFont(shadow, partnerTheme);
33
34
  } catch (error) {
34
35
  console.error(error);
@@ -0,0 +1,41 @@
1
+ import assetsManifest from '@wayflyer/flyui/manifest.json';
2
+
3
+ const LINK_TAG_ID = 'wf-flyui-styles';
4
+
5
+ type ApplyFontsType = ({
6
+ shadow,
7
+ onStylesLoad,
8
+ onStylesLoadError,
9
+ }: {
10
+ shadow: ShadowRoot;
11
+ onStylesLoad?: () => void;
12
+ onStylesLoadError?: (error: unknown) => void;
13
+ }) => void;
14
+
15
+ export const applyStyles: ApplyFontsType = async ({ shadow, onStylesLoad, onStylesLoadError }) => {
16
+ if (!assetsManifest || !('styles' in assetsManifest)) {
17
+ return onStylesLoadError?.('Style manifest not found');
18
+ }
19
+
20
+ const stylesUrl = assetsManifest.styles as string;
21
+
22
+ const linkTag = document.createElement('link');
23
+ linkTag.href = stylesUrl;
24
+ linkTag.rel = 'stylesheet';
25
+ linkTag.id = LINK_TAG_ID;
26
+
27
+ linkTag.onload = () => {
28
+ onStylesLoad?.();
29
+ };
30
+
31
+ linkTag.onerror = (error) => {
32
+ onStylesLoadError?.(error);
33
+ };
34
+
35
+ const existingLinkTag = document.getElementById(LINK_TAG_ID);
36
+ if (existingLinkTag) {
37
+ existingLinkTag.replaceWith(linkTag);
38
+ } else {
39
+ shadow.prepend(linkTag);
40
+ }
41
+ };
@@ -1,4 +1,5 @@
1
1
  export { applyFont } from './applyFont';
2
+ export { applyStyles } from './applyStyles';
2
3
  export { createRoots } from './createRoots';
3
4
  export { getPartnerIdFromToken } from './getPartnerIdFromToken';
4
5
  export { getPartnerThemeById } from './getPartnerThemeById';