@kaena1/mm-ui-shared-utils 1.25.0-f-poc-EC-3301.2 → 1.25.0-f-poc-EC-3301.4
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/components/ImportMapScripts.js +2 -1
- package/dist/hooks/useRemoteComponent.js +2 -0
- package/dist/index.d.ts +49 -3
- package/dist/index.js +6 -1
- package/dist/package.json.js +11 -0
- package/dist/services/ImportMapScript.js +26 -0
- package/dist/services/ImportMapService.js +61 -0
- package/package.json +5 -1
- package/dist/services/generateImportMap.js +0 -14
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { jsxs, Fragment, jsx } from "react/jsx-runtime";
|
|
2
2
|
import "react";
|
|
3
3
|
import "react-dom";
|
|
4
|
-
import { generateImportMapJson } from "../services/
|
|
4
|
+
import { generateImportMapJson } from "../services/ImportMapService.js";
|
|
5
|
+
import "next/script";
|
|
5
6
|
const ImportMapScripts = () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
6
7
|
/* @__PURE__ */ jsx(
|
|
7
8
|
"script",
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
|
|
1
3
|
import { default as default_2 } from 'react';
|
|
2
4
|
|
|
3
5
|
export declare interface ComponentManifest {
|
|
@@ -8,13 +10,57 @@ export declare interface ComponentManifest {
|
|
|
8
10
|
export declare function fetchManifest(manifestUrl: string): Promise<RemoteManifest>;
|
|
9
11
|
|
|
10
12
|
/**
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
+
* Generate complete import map object for remote components
|
|
14
|
+
*
|
|
15
|
+
* @param config - Optional configuration to override default settings
|
|
16
|
+
* @returns Import map object ready for browser consumption
|
|
17
|
+
*/
|
|
18
|
+
export declare const generateImportMap: (config?: ImportMapConfig) => object;
|
|
19
|
+
|
|
20
|
+
export declare const generateImportMapJson: (config?: ImportMapConfig) => string;
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get import map script props for Next.js Script component
|
|
24
|
+
*
|
|
25
|
+
* @param config - Optional configuration to override default settings
|
|
26
|
+
* @returns Props object with type and dangerouslySetInnerHTML for Script component
|
|
27
|
+
* @example
|
|
28
|
+
* ```tsx
|
|
29
|
+
* <Script {...getImportMapScriptProps()} strategy="beforeInteractive" />
|
|
30
|
+
* ```
|
|
13
31
|
*/
|
|
14
|
-
export declare
|
|
32
|
+
export declare const getImportMapScriptProps: (config?: ImportMapConfig) => {
|
|
33
|
+
type: "importmap-shim";
|
|
34
|
+
dangerouslySetInnerHTML: {
|
|
35
|
+
__html: string;
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export declare interface ImportMapConfig {
|
|
40
|
+
reactVersion?: string;
|
|
41
|
+
reactDomVersion?: string;
|
|
42
|
+
customImports?: Record<string, string>;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export declare const ImportMapScript: React.FC<ImportMapScriptProps>;
|
|
46
|
+
|
|
47
|
+
declare interface ImportMapScriptProps {
|
|
48
|
+
reactVersion?: string;
|
|
49
|
+
reactDomVersion?: string;
|
|
50
|
+
customImports?: Record<string, string>;
|
|
51
|
+
strategy?: 'beforeInteractive' | 'afterInteractive' | 'lazyOnload';
|
|
52
|
+
}
|
|
15
53
|
|
|
16
54
|
export declare const ImportMapScripts: default_2.FC;
|
|
17
55
|
|
|
56
|
+
/**
|
|
57
|
+
* Validate browser support for import maps
|
|
58
|
+
*
|
|
59
|
+
* @returns true if the browser supports import maps, false otherwise
|
|
60
|
+
* @see https://caniuse.com/import-maps
|
|
61
|
+
*/
|
|
62
|
+
export declare const isImportMapSupported: () => boolean;
|
|
63
|
+
|
|
18
64
|
export declare class ModuleLoader {
|
|
19
65
|
private loadedModules;
|
|
20
66
|
private importMapInjected;
|
package/dist/index.js
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
import { fetchManifest } from "./services/fetchManifest.js";
|
|
2
2
|
import { ModuleLoader, moduleLoader } from "./services/moduleLoader.js";
|
|
3
|
-
import { generateImportMapJson } from "./services/
|
|
3
|
+
import { generateImportMap, generateImportMapJson, getImportMapScriptProps, isImportMapSupported } from "./services/ImportMapService.js";
|
|
4
|
+
import { ImportMapScript } from "./services/ImportMapScript.js";
|
|
4
5
|
import { useRemoteComponent } from "./hooks/useRemoteComponent.js";
|
|
5
6
|
import { RemoteRenderer } from "./components/RemoteRenderer.js";
|
|
6
7
|
import { RemoteLinks } from "./components/RemoteLinks.js";
|
|
7
8
|
import { ImportMapScripts } from "./components/ImportMapScripts.js";
|
|
8
9
|
export {
|
|
10
|
+
ImportMapScript,
|
|
9
11
|
ImportMapScripts,
|
|
10
12
|
ModuleLoader,
|
|
11
13
|
RemoteLinks,
|
|
12
14
|
RemoteRenderer,
|
|
13
15
|
fetchManifest,
|
|
16
|
+
generateImportMap,
|
|
14
17
|
generateImportMapJson,
|
|
18
|
+
getImportMapScriptProps,
|
|
19
|
+
isImportMapSupported,
|
|
15
20
|
moduleLoader,
|
|
16
21
|
useRemoteComponent
|
|
17
22
|
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import Script from "next/script";
|
|
3
|
+
import { getImportMapScriptProps } from "./ImportMapService.js";
|
|
4
|
+
const ImportMapScript = ({
|
|
5
|
+
reactVersion,
|
|
6
|
+
reactDomVersion,
|
|
7
|
+
customImports,
|
|
8
|
+
strategy = "beforeInteractive"
|
|
9
|
+
}) => {
|
|
10
|
+
const scriptProps = getImportMapScriptProps({
|
|
11
|
+
reactVersion,
|
|
12
|
+
reactDomVersion,
|
|
13
|
+
customImports
|
|
14
|
+
});
|
|
15
|
+
return /* @__PURE__ */ jsx(
|
|
16
|
+
Script,
|
|
17
|
+
{
|
|
18
|
+
id: "remote-components-import-map",
|
|
19
|
+
strategy,
|
|
20
|
+
...scriptProps
|
|
21
|
+
}
|
|
22
|
+
);
|
|
23
|
+
};
|
|
24
|
+
export {
|
|
25
|
+
ImportMapScript
|
|
26
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import packageJson from "../package.json.js";
|
|
2
|
+
const cleanVersion = (version) => {
|
|
3
|
+
return version.replace(/^[\^~]/, "");
|
|
4
|
+
};
|
|
5
|
+
const DEFAULT_CONFIG = {
|
|
6
|
+
reactVersion: cleanVersion(packageJson.dependencies.react),
|
|
7
|
+
reactDomVersion: cleanVersion(packageJson.dependencies["react-dom"])
|
|
8
|
+
};
|
|
9
|
+
const generateReactDataUrl = () => {
|
|
10
|
+
return `data:text/javascript;charset=utf-8,
|
|
11
|
+
const React = window.React;
|
|
12
|
+
export default React;
|
|
13
|
+
export const {
|
|
14
|
+
Component, PureComponent, createContext, useContext, useState, useEffect,
|
|
15
|
+
useCallback, useMemo, useRef, forwardRef, createElement, Fragment, memo, lazy, Suspense,
|
|
16
|
+
useLayoutEffect, useId
|
|
17
|
+
} = React;`;
|
|
18
|
+
};
|
|
19
|
+
const generateJsxRuntimeDataUrl = () => {
|
|
20
|
+
return `data:text/javascript;charset=utf-8,
|
|
21
|
+
import * as ReactJSXRuntime from 'https://esm.sh/react@18.3.1/jsx-runtime';
|
|
22
|
+
export const jsx = ReactJSXRuntime.jsx;
|
|
23
|
+
export const jsxs = ReactJSXRuntime.jsxs;
|
|
24
|
+
export const Fragment = ReactJSXRuntime.Fragment;`;
|
|
25
|
+
};
|
|
26
|
+
const generateImportMap = (config = {}) => {
|
|
27
|
+
const finalConfig = { ...DEFAULT_CONFIG, ...config };
|
|
28
|
+
return {
|
|
29
|
+
imports: {
|
|
30
|
+
react: generateReactDataUrl(),
|
|
31
|
+
"react/jsx-runtime": generateJsxRuntimeDataUrl(),
|
|
32
|
+
"react/jsx-dev-runtime": generateJsxRuntimeDataUrl(),
|
|
33
|
+
// Some bundlers emit ".js" suffixed bare specifiers; map those too
|
|
34
|
+
"react/jsx-runtime.js": generateJsxRuntimeDataUrl(),
|
|
35
|
+
"react/jsx-dev-runtime.js": generateJsxRuntimeDataUrl(),
|
|
36
|
+
"react-dom": `https://esm.sh/react-dom@${finalConfig.reactDomVersion}`,
|
|
37
|
+
"react-dom/client": `https://esm.sh/react-dom@${finalConfig.reactDomVersion}/client`
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
};
|
|
41
|
+
const generateImportMapJson = (config) => {
|
|
42
|
+
return JSON.stringify(generateImportMap(config));
|
|
43
|
+
};
|
|
44
|
+
const isImportMapSupported = () => {
|
|
45
|
+
if (typeof window === "undefined") return false;
|
|
46
|
+
return "importmap" in document.createElement("script");
|
|
47
|
+
};
|
|
48
|
+
const getImportMapScriptProps = (config) => {
|
|
49
|
+
return {
|
|
50
|
+
type: "importmap-shim",
|
|
51
|
+
dangerouslySetInnerHTML: {
|
|
52
|
+
__html: generateImportMapJson(config)
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
};
|
|
56
|
+
export {
|
|
57
|
+
generateImportMap,
|
|
58
|
+
generateImportMapJson,
|
|
59
|
+
getImportMapScriptProps,
|
|
60
|
+
isImportMapSupported
|
|
61
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kaena1/mm-ui-shared-utils",
|
|
3
|
-
"version": "1.25.0-f-poc-EC-3301.
|
|
3
|
+
"version": "1.25.0-f-poc-EC-3301.4",
|
|
4
4
|
"description": "Shared utilities for loading remote React components in Mint Mobile microfrontends",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -35,6 +35,10 @@
|
|
|
35
35
|
],
|
|
36
36
|
"author": "",
|
|
37
37
|
"license": "ISC",
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"react": "^18.3.1",
|
|
40
|
+
"react-dom": "^18.3.1"
|
|
41
|
+
},
|
|
38
42
|
"peerDependencies": {
|
|
39
43
|
"react": "^18.3.1",
|
|
40
44
|
"react-dom": "^18.3.1"
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
function generateImportMapJson() {
|
|
2
|
-
const importMap = {
|
|
3
|
-
imports: {
|
|
4
|
-
react: "react",
|
|
5
|
-
"react-dom": "react-dom",
|
|
6
|
-
"react/jsx-runtime": "react/jsx-runtime",
|
|
7
|
-
"react/jsx-dev-runtime": "react/jsx-dev-runtime"
|
|
8
|
-
}
|
|
9
|
-
};
|
|
10
|
-
return JSON.stringify(importMap);
|
|
11
|
-
}
|
|
12
|
-
export {
|
|
13
|
-
generateImportMapJson
|
|
14
|
-
};
|