@kaena1/mm-ui-shared-utils 1.25.0-f-poc-EC-3301.1 → 1.25.0-f-poc-EC-3301.3

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.
@@ -0,0 +1,6 @@
1
+ function getDefaultExportFromCjs(x) {
2
+ return x && x.__esModule && Object.prototype.hasOwnProperty.call(x, "default") ? x["default"] : x;
3
+ }
4
+ export {
5
+ getDefaultExportFromCjs
6
+ };
@@ -0,0 +1,4 @@
1
+ var _interop_require_default = {};
2
+ export {
3
+ _interop_require_default as __exports
4
+ };
@@ -0,0 +1,4 @@
1
+ var _interop_require_wildcard = {};
2
+ export {
3
+ _interop_require_wildcard as __exports
4
+ };
@@ -0,0 +1,4 @@
1
+ var headManagerContext_sharedRuntime = {};
2
+ export {
3
+ headManagerContext_sharedRuntime as __exports
4
+ };
@@ -0,0 +1,4 @@
1
+ var headManager = { exports: {} };
2
+ export {
3
+ headManager as __module
4
+ };
@@ -0,0 +1,4 @@
1
+ var requestIdleCallback = { exports: {} };
2
+ export {
3
+ requestIdleCallback as __module
4
+ };
@@ -0,0 +1,4 @@
1
+ var script = { exports: {} };
2
+ export {
3
+ script as __module
4
+ };
@@ -0,0 +1,36 @@
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import "react-dom";
4
+ import { generateImportMapJson } from "../services/ImportMapService.js";
5
+ import "../node_modules/next/dist/client/script.js";
6
+ const ImportMapScripts = () => /* @__PURE__ */ jsxs(Fragment, { children: [
7
+ /* @__PURE__ */ jsx(
8
+ "script",
9
+ {
10
+ defer: true,
11
+ src: "https://ga.jspm.io/npm:es-module-shims@1.10.0/dist/es-module-shims.js",
12
+ crossOrigin: "anonymous"
13
+ }
14
+ ),
15
+ /* @__PURE__ */ jsx(
16
+ "link",
17
+ {
18
+ rel: "preconnect",
19
+ href: "https://assets-qa.mintmobile.com",
20
+ crossOrigin: "anonymous"
21
+ }
22
+ ),
23
+ /* @__PURE__ */ jsx("link", { rel: "dns-prefetch", href: "https://assets-qa.mintmobile.com" }),
24
+ /* @__PURE__ */ jsx("link", { rel: "preconnect", href: "https://esm.sh", crossOrigin: "anonymous" }),
25
+ /* @__PURE__ */ jsx("link", { rel: "dns-prefetch", href: "https://esm.sh" }),
26
+ /* @__PURE__ */ jsx(
27
+ "script",
28
+ {
29
+ type: "importmap-shim",
30
+ dangerouslySetInnerHTML: { __html: generateImportMapJson() }
31
+ }
32
+ )
33
+ ] });
34
+ export {
35
+ ImportMapScripts
36
+ };
@@ -0,0 +1,10 @@
1
+ import { jsxs, Fragment, jsx } from "react/jsx-runtime";
2
+ const RemoteLinks = ({ manifest }) => {
3
+ return /* @__PURE__ */ jsxs(Fragment, { children: [
4
+ manifest.styleUrl && /* @__PURE__ */ jsx("link", { rel: "stylesheet", href: manifest.styleUrl }),
5
+ /* @__PURE__ */ jsx("link", { rel: "modulepreload", href: manifest.bundleUrl })
6
+ ] });
7
+ };
8
+ export {
9
+ RemoteLinks
10
+ };
@@ -0,0 +1,27 @@
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { useRemoteComponent } from "../hooks/useRemoteComponent.js";
3
+ const RemoteRenderer = ({
4
+ manifest,
5
+ componentName,
6
+ componentProps,
7
+ autoLoad = true,
8
+ placeholder = null,
9
+ children,
10
+ errorFallback
11
+ }) => {
12
+ const {
13
+ component: Comp,
14
+ error,
15
+ loaded
16
+ } = useRemoteComponent({
17
+ manifest,
18
+ componentName,
19
+ autoLoad
20
+ });
21
+ if (error) return errorFallback ? errorFallback(error) : null;
22
+ if (!loaded || !Comp) return /* @__PURE__ */ jsx(Fragment, { children: placeholder });
23
+ return /* @__PURE__ */ jsx(Comp, { ...componentProps, children });
24
+ };
25
+ export {
26
+ RemoteRenderer
27
+ };
@@ -0,0 +1,69 @@
1
+ import { useState, useCallback, useEffect } from "react";
2
+ import { moduleLoader } from "../services/moduleLoader.js";
3
+ import "react/jsx-runtime";
4
+ import "../node_modules/next/dist/client/script.js";
5
+ function useRemoteComponent(options) {
6
+ const {
7
+ manifest: manifestFromProps,
8
+ componentName,
9
+ autoLoad = true
10
+ } = options;
11
+ const [state, setState] = useState({
12
+ component: null,
13
+ manifest: null,
14
+ loading: false,
15
+ error: null,
16
+ loaded: false
17
+ });
18
+ const loadComponent = useCallback(async () => {
19
+ try {
20
+ setState((prev) => ({
21
+ ...prev,
22
+ loading: true,
23
+ error: null,
24
+ manifest: manifestFromProps
25
+ }));
26
+ const loadOptions = {
27
+ bundleUrl: manifestFromProps.bundleUrl,
28
+ componentName
29
+ };
30
+ const component = await moduleLoader.loadComponent(loadOptions);
31
+ setState((prev) => ({
32
+ ...prev,
33
+ component,
34
+ loading: false,
35
+ loaded: true
36
+ }));
37
+ } catch (err) {
38
+ console.error("Error loading remote component:", err);
39
+ setState((prev) => ({
40
+ ...prev,
41
+ error: err.message,
42
+ loading: false,
43
+ loaded: false
44
+ }));
45
+ }
46
+ }, [manifestFromProps, componentName]);
47
+ const reload = useCallback(async () => {
48
+ await loadComponent();
49
+ }, [loadComponent]);
50
+ const clearError = useCallback(() => {
51
+ setState((prev) => ({ ...prev, error: null }));
52
+ }, []);
53
+ useEffect(() => {
54
+ if (autoLoad) {
55
+ loadComponent().then(() => {
56
+ setState((prev) => ({ ...prev, loaded: true }));
57
+ });
58
+ }
59
+ }, [autoLoad, loadComponent]);
60
+ return {
61
+ ...state,
62
+ loadComponent,
63
+ reload,
64
+ clearError
65
+ };
66
+ }
67
+ export {
68
+ useRemoteComponent
69
+ };
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,20 +10,61 @@ export declare interface ComponentManifest {
8
10
  export declare function fetchManifest(manifestUrl: string): Promise<RemoteManifest>;
9
11
 
10
12
  /**
11
- * Generates an import map JSON string for ES module dependency resolution
12
- * This allows remote modules to use bare specifiers like 'react' instead of full CDN URLs
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
13
17
  */
14
- export declare function generateImportMapJson(): string;
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
+ * ```
31
+ */
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;
21
- /**
22
- * Ensure React and ReactDOM are available globally
23
- * Remote components may expect these to be on window object.
24
- */
67
+ private prepareGlobalDependencies;
25
68
  /**
26
69
  * Ensure import map is injected before loading any modules
27
70
  * Import maps MUST be added before any module scripts
package/dist/index.js CHANGED
@@ -1,299 +1,22 @@
1
- var M = Object.defineProperty;
2
- var y = (n, e, t) => e in n ? M(n, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : n[e] = t;
3
- var u = (n, e, t) => y(n, typeof e != "symbol" ? e + "" : e, t);
4
- import { useState as x, useEffect as w, useCallback as f } from "react";
5
- import { jsx as l, Fragment as h, jsxs as g } from "react/jsx-runtime";
6
- async function $(n) {
7
- try {
8
- const e = await fetch(n, {
9
- headers: {
10
- "Content-Type": "application/json"
11
- }
12
- });
13
- if (!e.ok)
14
- throw new Error(
15
- `Failed to fetch manifest: ${e.status} ${e.statusText}`
16
- );
17
- const t = await e.json();
18
- if (!t || typeof t != "object" || !t.components || typeof t.components != "object")
19
- throw new Error("Invalid manifest: missing 'components' object");
20
- return t;
21
- } catch (e) {
22
- throw e instanceof Error ? new Error(
23
- `Manifest loading failed from ${n}: ${e.message}`
24
- ) : new Error(
25
- `Manifest loading failed from ${n}: Unknown error`
26
- );
27
- }
28
- }
29
- class R {
30
- constructor() {
31
- u(this, "loadedModules", /* @__PURE__ */ new Map());
32
- u(this, "importMapInjected", !1);
33
- }
34
- /**
35
- * Ensure React and ReactDOM are available globally
36
- * Remote components may expect these to be on window object.
37
- */
38
- // private prepareGlobalDependencies(): void {
39
- // if (typeof window === 'undefined') return;
40
- // if (!(window as any).React) {
41
- // (window as any).React = require('react');
42
- // }
43
- // if (!(window as any).ReactDOM) {
44
- // (window as any).ReactDOM = require('react-dom');
45
- // }
46
- // }
47
- /**
48
- * Ensure import map is injected before loading any modules
49
- * Import maps MUST be added before any module scripts
50
- */
51
- ensureImportMap() {
52
- if (typeof window > "u" || this.importMapInjected) return;
53
- if (document.querySelector(
54
- 'script[type="importmap"], script[type="importmap-shim"]'
55
- )) {
56
- this.importMapInjected = !0;
57
- return;
58
- }
59
- console.warn(
60
- `Import map not found. Ensure an import map is included early in:
61
-
62
- - pages router: the document head (e.g. in pages/_document.tsx).
63
-
64
- - app router: the root layout head (e.g. in app/layout.tsx).`
65
- ), this.importMapInjected = !0;
66
- }
67
- /**
68
- * Load remote React component from ES module URL
69
- *
70
- * @param options - Configuration object with bundleUrl and componentName
71
- * @returns Promise that resolves to the loaded React component
72
- * @throws Error if component loading fails or times out (10s)
73
- */
74
- async loadComponent(e) {
75
- const { bundleUrl: t, componentName: a } = e;
76
- if (this.loadedModules.has(t)) {
77
- console.log(
78
- `%c📦 LOADER: Returning module from INTERNAL cache for ${t}`,
79
- "color: green; font-weight: bold;"
80
- );
81
- const o = this.loadedModules.get(t), s = (o == null ? void 0 : o[a]) || (o == null ? void 0 : o.default);
82
- if (s) return s;
83
- }
84
- this.ensureImportMap();
85
- try {
86
- const o = await this.loadModuleViaScript(t), s = o[a] || o.default;
87
- if (!s)
88
- throw new Error(`Component ${a} not found in module`);
89
- return this.loadedModules.set(t, o), s;
90
- } catch (o) {
91
- throw console.error("🔍 LOADER: Failed to load component:", o), o;
92
- }
93
- }
94
- /**
95
- * Load ES module from external URL using dynamic script injection
96
- * This bypasses Webpack's module resolution and works with import maps
97
- */
98
- loadModuleViaScript(e) {
99
- return new Promise((t, a) => {
100
- const o = `__moduleCallback_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`, s = 50, i = 200;
101
- let c = 0;
102
- const m = `
103
- import * as loadedModule from '${e}';
104
- window.${o} = loadedModule;
105
- `, r = document.createElement("script");
106
- r.type = "module-shim", r.textContent = m;
107
- const d = setInterval(() => {
108
- if (c++, window[o]) {
109
- clearInterval(d);
110
- const p = window[o];
111
- delete window[o], r.parentNode && document.head.removeChild(r), t(p);
112
- } else c >= i && (clearInterval(d), delete window[o], r.parentNode && document.head.removeChild(r), a(new Error(`Timeout loading module from ${e}`)));
113
- }, s);
114
- r.onerror = (p) => {
115
- clearInterval(d), delete window[o], r.parentNode && document.head.removeChild(r), a(new Error(`Failed to load module from ${e}`));
116
- }, document.head.appendChild(r);
117
- });
118
- }
119
- /**
120
- * Preload a module without extracting components
121
- * Useful for warming up cache
122
- *
123
- * @param bundleUrl - URL of the module to preload
124
- */
125
- async preloadModule(e) {
126
- if (!this.loadedModules.has(e)) {
127
- this.ensureImportMap();
128
- try {
129
- const t = await this.loadModuleViaScript(e);
130
- this.loadedModules.set(e, t);
131
- } catch (t) {
132
- console.error(`Failed to preload module ${e}:`, t);
133
- }
134
- }
135
- }
136
- /**
137
- * Check if a module has already been loaded
138
- *
139
- * @param bundleUrl - URL of the module to check
140
- * @returns true if module is already loaded, false otherwise
141
- */
142
- isLoaded(e) {
143
- return this.loadedModules.has(e);
144
- }
145
- /**
146
- * Clear all loaded modules from cache
147
- * Useful for development/testing
148
- */
149
- clearCache() {
150
- this.loadedModules.clear();
151
- }
152
- }
153
- const j = new R();
154
- function I() {
155
- const n = `data:text/javascript;charset=utf-8,
156
- const React = window.React;
157
- export default React;
158
- export const {
159
- Component, PureComponent, createContext, useContext, useState, useEffect,
160
- useCallback, useMemo, useRef, forwardRef, createElement, Fragment, memo, lazy, Suspense,
161
- useLayoutEffect, useId, useReducer, useImperativeHandle
162
- } = React;`, e = `data:text/javascript;charset=utf-8,
163
- const React = window.React;
164
- export const jsx = React.createElement;
165
- export const jsxs = React.createElement;
166
- export const Fragment = React.Fragment;`;
167
- return JSON.stringify({
168
- imports: {
169
- react: n,
170
- "react/jsx-runtime": e,
171
- "react/jsx-dev-runtime": e,
172
- "react/jsx-runtime.js": e,
173
- "react/jsx-dev-runtime.js": e,
174
- "react-dom": "https://esm.sh/react-dom@18.3.1",
175
- "react-dom/client": "https://esm.sh/react-dom@18.3.1/client"
176
- }
177
- });
178
- }
179
- function C(n) {
180
- const {
181
- manifest: e,
182
- componentName: t,
183
- autoLoad: a = !0
184
- } = n, [o, s] = x({
185
- component: null,
186
- manifest: null,
187
- loading: !1,
188
- error: null,
189
- loaded: !1
190
- });
191
- w(() => {
192
- var r;
193
- typeof window < "u" && console.log("🧩 Remote sees React:", {
194
- react: window.React,
195
- useState: (r = window.React) == null ? void 0 : r.useState
196
- });
197
- }, []);
198
- const i = f(async () => {
199
- try {
200
- s((p) => ({
201
- ...p,
202
- loading: !0,
203
- error: null,
204
- manifest: e
205
- }));
206
- const r = {
207
- bundleUrl: e.bundleUrl,
208
- componentName: t
209
- }, d = await j.loadComponent(r);
210
- s((p) => ({
211
- ...p,
212
- component: d,
213
- loading: !1,
214
- loaded: !0
215
- }));
216
- } catch (r) {
217
- console.error("Error loading remote component:", r), s((d) => ({
218
- ...d,
219
- error: r.message,
220
- loading: !1,
221
- loaded: !1
222
- }));
223
- }
224
- }, [e, t]), c = f(async () => {
225
- await i();
226
- }, [i]), m = f(() => {
227
- s((r) => ({ ...r, error: null }));
228
- }, []);
229
- return w(() => {
230
- a && i().then(() => {
231
- s((r) => ({ ...r, loaded: !0 }));
232
- });
233
- }, [a, i]), {
234
- ...o,
235
- loadComponent: i,
236
- reload: c,
237
- clearError: m
238
- };
239
- }
240
- const k = ({
241
- manifest: n,
242
- componentName: e,
243
- componentProps: t,
244
- autoLoad: a = !0,
245
- placeholder: o = null,
246
- children: s,
247
- errorFallback: i
248
- }) => {
249
- const {
250
- component: c,
251
- error: m,
252
- loaded: r
253
- } = C({
254
- manifest: n,
255
- componentName: e,
256
- autoLoad: a
257
- });
258
- return m ? i ? i(m) : null : !r || !c ? /* @__PURE__ */ l(h, { children: o }) : /* @__PURE__ */ l(c, { ...t, children: s });
259
- }, b = ({ manifest: n }) => /* @__PURE__ */ g(h, { children: [
260
- n.styleUrl && /* @__PURE__ */ l("link", { rel: "stylesheet", href: n.styleUrl }),
261
- /* @__PURE__ */ l("link", { rel: "modulepreload", href: n.bundleUrl })
262
- ] }), L = () => /* @__PURE__ */ g(h, { children: [
263
- /* @__PURE__ */ l(
264
- "script",
265
- {
266
- defer: !0,
267
- src: "https://ga.jspm.io/npm:es-module-shims@1.10.0/dist/es-module-shims.js",
268
- crossOrigin: "anonymous"
269
- }
270
- ),
271
- /* @__PURE__ */ l(
272
- "link",
273
- {
274
- rel: "preconnect",
275
- href: "https://assets-qa.mintmobile.com",
276
- crossOrigin: "anonymous"
277
- }
278
- ),
279
- /* @__PURE__ */ l("link", { rel: "dns-prefetch", href: "https://assets-qa.mintmobile.com" }),
280
- /* @__PURE__ */ l("link", { rel: "preconnect", href: "https://esm.sh", crossOrigin: "anonymous" }),
281
- /* @__PURE__ */ l("link", { rel: "dns-prefetch", href: "https://esm.sh" }),
282
- /* @__PURE__ */ l(
283
- "script",
284
- {
285
- type: "importmap-shim",
286
- dangerouslySetInnerHTML: { __html: I() }
287
- }
288
- )
289
- ] });
1
+ import { fetchManifest } from "./services/fetchManifest.js";
2
+ import { ModuleLoader, moduleLoader } from "./services/moduleLoader.js";
3
+ import { generateImportMap, generateImportMapJson, getImportMapScriptProps, isImportMapSupported } from "./services/ImportMapService.js";
4
+ import { ImportMapScript } from "./services/ImportMapScript.js";
5
+ import { useRemoteComponent } from "./hooks/useRemoteComponent.js";
6
+ import { RemoteRenderer } from "./components/RemoteRenderer.js";
7
+ import { RemoteLinks } from "./components/RemoteLinks.js";
8
+ import { ImportMapScripts } from "./components/ImportMapScripts.js";
290
9
  export {
291
- L as ImportMapScripts,
292
- R as ModuleLoader,
293
- b as RemoteLinks,
294
- k as RemoteRenderer,
295
- $ as fetchManifest,
296
- I as generateImportMapJson,
297
- j as moduleLoader,
298
- C as useRemoteComponent
10
+ ImportMapScript,
11
+ ImportMapScripts,
12
+ ModuleLoader,
13
+ RemoteLinks,
14
+ RemoteRenderer,
15
+ fetchManifest,
16
+ generateImportMap,
17
+ generateImportMapJson,
18
+ getImportMapScriptProps,
19
+ isImportMapSupported,
20
+ moduleLoader,
21
+ useRemoteComponent
299
22
  };
@@ -0,0 +1,8 @@
1
+ import { __exports as _interop_require_default$1 } from "../../../../_virtual/_interop_require_default.js";
2
+ _interop_require_default$1._ = _interop_require_default$1._interop_require_default = _interop_require_default;
3
+ function _interop_require_default(obj) {
4
+ return obj && obj.__esModule ? obj : { default: obj };
5
+ }
6
+ export {
7
+ _interop_require_default$1 as default
8
+ };
@@ -0,0 +1,31 @@
1
+ import { __exports as _interop_require_wildcard$1 } from "../../../../_virtual/_interop_require_wildcard.js";
2
+ function _getRequireWildcardCache(nodeInterop) {
3
+ if (typeof WeakMap !== "function") return null;
4
+ var cacheBabelInterop = /* @__PURE__ */ new WeakMap();
5
+ var cacheNodeInterop = /* @__PURE__ */ new WeakMap();
6
+ return (_getRequireWildcardCache = function(nodeInterop2) {
7
+ return nodeInterop2 ? cacheNodeInterop : cacheBabelInterop;
8
+ })(nodeInterop);
9
+ }
10
+ _interop_require_wildcard$1._ = _interop_require_wildcard$1._interop_require_wildcard = _interop_require_wildcard;
11
+ function _interop_require_wildcard(obj, nodeInterop) {
12
+ if (!nodeInterop && obj && obj.__esModule) return obj;
13
+ if (obj === null || typeof obj !== "object" && typeof obj !== "function") return { default: obj };
14
+ var cache = _getRequireWildcardCache(nodeInterop);
15
+ if (cache && cache.has(obj)) return cache.get(obj);
16
+ var newObj = { __proto__: null };
17
+ var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor;
18
+ for (var key in obj) {
19
+ if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) {
20
+ var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null;
21
+ if (desc && (desc.get || desc.set)) Object.defineProperty(newObj, key, desc);
22
+ else newObj[key] = obj[key];
23
+ }
24
+ }
25
+ newObj.default = obj;
26
+ if (cache) cache.set(obj, newObj);
27
+ return newObj;
28
+ }
29
+ export {
30
+ _interop_require_wildcard$1 as default
31
+ };